17 #include "llvm/ExecutionEngine/Orc/Mangling.h"
18 #include "llvm/Support/TargetSelect.h"
22 extern "C" MlirExecutionEngine
25 bool enableObjectDump) {
26 static bool initOnce = [] {
27 llvm::InitializeNativeTarget();
28 llvm::InitializeNativeTargetAsmParser();
29 llvm::InitializeNativeTargetAsmPrinter();
34 auto &ctx = *
unwrap(op)->getContext();
39 auto tmBuilderOrError = llvm::orc::JITTargetMachineBuilder::detectHost();
40 if (!tmBuilderOrError) {
41 llvm::errs() <<
"Failed to create a JITTargetMachineBuilder for the host\n";
42 return MlirExecutionEngine{
nullptr};
44 auto tmOrError = tmBuilderOrError->createTargetMachine();
46 llvm::errs() <<
"Failed to create a TargetMachine for the host\n";
47 return MlirExecutionEngine{
nullptr};
51 for (
unsigned i = 0; i < static_cast<unsigned>(numPaths); ++i)
52 libPaths.push_back(sharedLibPaths[i].
data);
57 optLevel, 0, tmOrError->get());
65 consumeError(jitOrError.takeError());
66 return MlirExecutionEngine{
nullptr};
68 return wrap(jitOrError->release());
78 const std::string ifaceName = (
"_mlir_ciface_" +
unwrap(name)).str();
79 llvm::Error error =
unwrap(jit)->invokePacked(
82 return wrap(failure());
83 return wrap(success());
88 auto expectedFPtr =
unwrap(jit)->lookupPacked(
unwrap(name));
91 return reinterpret_cast<void *
>(*expectedFPtr);
99 return reinterpret_cast<void *
>(*expectedFPtr);
105 unwrap(jit)->registerSymbols([&](llvm::orc::MangleAndInterner interner) {
106 llvm::orc::SymbolMap symbolMap;
107 symbolMap[interner(
unwrap(name))] =
108 { llvm::orc::ExecutorAddr::fromPtr(sym),
109 llvm::JITSymbolFlags::Exported };
void * mlirExecutionEngineLookupPacked(MlirExecutionEngine jit, MlirStringRef name)
Lookup the wrapper of the native function in the execution engine with the given name,...
void mlirExecutionEngineDumpToObjectFile(MlirExecutionEngine jit, MlirStringRef name)
Dump as an object in fileName.
MlirLogicalResult mlirExecutionEngineInvokePacked(MlirExecutionEngine jit, MlirStringRef name, void **arguments)
Invoke a native function in the execution engine by name with the arguments and result of the invoked...
MlirExecutionEngine mlirExecutionEngineCreate(MlirModule op, int optLevel, int numPaths, const MlirStringRef *sharedLibPaths, bool enableObjectDump)
Creates an ExecutionEngine for the provided ModuleOp.
void * mlirExecutionEngineLookup(MlirExecutionEngine jit, MlirStringRef name)
Lookup a native function in the execution engine by name, returns nullptr if the name can't be looked...
void mlirExecutionEngineDestroy(MlirExecutionEngine jit)
Destroy an ExecutionEngine instance.
void mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit, MlirStringRef name, void *sym)
Register a symbol with the jit: this symbol will be accessible to the jitted code.
static llvm::Expected< std::unique_ptr< ExecutionEngine > > create(Operation *op, const ExecutionEngineOptions &options={}, std::unique_ptr< llvm::TargetMachine > tm=nullptr)
Creates an execution engine for the given MLIR IR.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Include the generated interface declarations.
std::function< llvm::Error(llvm::Module *)> makeOptimizingTransformer(unsigned optLevel, unsigned sizeLevel, llvm::TargetMachine *targetMachine)
Create a module transformer function for MLIR ExecutionEngine that runs LLVM IR passes corresponding ...
void registerOpenMPDialectTranslation(DialectRegistry ®istry)
Register the OpenMP dialect and the translation from it to the LLVM IR in the given registry;.
void registerBuiltinDialectTranslation(DialectRegistry ®istry)
Register the translation from the builtin dialect to the LLVM IR in the given registry.
void registerLLVMDialectTranslation(DialectRegistry ®istry)
Register the LLVM dialect and the translation from it to the LLVM IR in the given registry;.
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.
const char * data
Pointer to the first symbol.
std::optional< llvm::CodeGenOptLevel > jitCodeGenOptLevel
jitCodeGenOptLevel, when provided, is used as the optimization level for target code generation.
ArrayRef< StringRef > sharedLibPaths
If sharedLibPaths are provided, the underlying JIT-compilation will open and link the shared librarie...
bool enableObjectDump
If enableObjectCache is set, the JIT compiler will create one to store the object generated for the g...
llvm::function_ref< llvm::Error(llvm::Module *)> transformer
If transformer is provided, it will be called on the LLVM module during JIT-compilation and can be us...