mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
This refactoring commit restructures the compilation pipeline of
`zamacompiler`, such that it is possible to enter and exit the
pipeline at different points, effectively defining the level of
abstraction at the input and the required level of abstraction for the
output.
The entry point is specified using the `--entry-dialect`
argument. Valid choices are:
`--entry-dialect=hlfhe`: Source contains HLFHE operations
`--entry-dialect=midlfhe`: Source contains MidLFHE operations
`--entry-dialect=lowlfhe`: Source contains LowLFHE operations
`--entry-dialect=std`: Source does not contain any FHE Operations
`--entry-dialect=llvm`: Source is in LLVM dialect
The exit point is defined by an action, specified using --action.
`--action=roundtrip`:
Parse the source file to in-memory representation and immediately
dump as text without any processing
`--action=dump-midlfhe`:
Lower source to MidLFHE and dump result as text
`--action=dump-lowlfhe`:
Lower source to LowLFHE and dump result as text
`--action=dump-std`:
Lower source to only standard MLIR dialects (i.e., all FHE
operations have already been lowered)
`--action=dump-llvm-dialect`:
Lower source to MLIR's LLVM dialect (i.e., the LLVM dialect, not
LLVM IR)
`--action=dump-llvm-ir`:
Lower source to plain LLVM IR (i.e., not the LLVM dialect, but
actual LLVM IR)
`--action=dump-optimized-llvm-ir`:
Lower source to plain LLVM IR (i.e., not the LLVM dialect, but
actual LLVM IR), pass the result through the LLVM optimizer and
print the result.
`--action=dump-jit-invoke`:
Execute the full lowering pipeline to optimized LLVM IR, JIT
compile the result, invoke the function specified in
`--jit-funcname` with the parameters from `--jit-args` and print
the functions return value.
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#ifndef ZAMALANG_SUPPORT_COMPILER_ENGINE_H
|
|
#define ZAMALANG_SUPPORT_COMPILER_ENGINE_H
|
|
|
|
#include "Jit.h"
|
|
|
|
namespace mlir {
|
|
namespace zamalang {
|
|
|
|
/// CompilerEngine is an tools that provides tools to implements the compilation
|
|
/// flow and manage the compilation flow state.
|
|
class CompilerEngine {
|
|
public:
|
|
CompilerEngine() {
|
|
context = new mlir::MLIRContext();
|
|
loadDialects();
|
|
}
|
|
~CompilerEngine() {
|
|
if (context != nullptr)
|
|
delete context;
|
|
}
|
|
|
|
// Compile an mlir programs from it's textual representation.
|
|
llvm::Error compile(std::string mlirStr);
|
|
|
|
// Build the jit lambda argument.
|
|
llvm::Expected<std::unique_ptr<JITLambda::Argument>> buildArgument();
|
|
|
|
// Call the compiled function with and argument object.
|
|
llvm::Error invoke(JITLambda::Argument &arg);
|
|
|
|
// Call the compiled function with a list of integer arguments.
|
|
llvm::Expected<uint64_t> run(std::vector<uint64_t> args);
|
|
|
|
// Get a printable representation of the compiled module
|
|
std::string getCompiledModule();
|
|
|
|
private:
|
|
// Load the necessary dialects into the engine's context
|
|
void loadDialects();
|
|
|
|
mlir::OwningModuleRef module_ref;
|
|
mlir::MLIRContext *context;
|
|
std::unique_ptr<mlir::zamalang::KeySet> keySet;
|
|
};
|
|
} // namespace zamalang
|
|
} // namespace mlir
|
|
|
|
#endif
|