13 #ifndef MLIR_EXECUTIONENGINE_EXECUTIONENGINE_H_
14 #define MLIR_EXECUTIONENGINE_EXECUTIONENGINE_H_
17 #include "llvm/ExecutionEngine/ObjectCache.h"
18 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
19 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
20 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/Support/Error.h"
31 class ExecutionEngine;
32 class JITEventListener;
44 llvm::MemoryBufferRef objBuffer)
override;
45 std::unique_ptr<llvm::MemoryBuffer>
getObject(
const llvm::Module *m)
override;
54 llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> cachedObjects;
120 "__mlir_execution_engine_init";
126 "__mlir_execution_engine_destroy";
137 ExecutionEngine(
bool enableObjectDump,
bool enableGDBNotificationListener,
138 bool enablePerfNotificationListener);
147 std::unique_ptr<llvm::TargetMachine> tm =
nullptr);
165 template <
typename T>
168 args.push_back(&val);
173 template <
typename T>
181 template <
typename T>
188 template <
typename T>
191 args.push_back(&
result.value);
206 template <
typename... Args>
207 llvm::Error
invoke(StringRef funcName, Args... args) {
208 const std::string adapterName =
209 std::string(
"_mlir_ciface_") + funcName.str();
221 llvm::TargetMachine *tm);
234 llvm::LLVMContext llvmContext;
237 std::unique_ptr<llvm::orc::LLJIT> jit;
240 std::unique_ptr<SimpleObjectCache> cache;
243 std::vector<std::string> functionNames;
246 llvm::JITEventListener *gdbListener;
249 llvm::JITEventListener *perfListener;
static llvm::ManagedStatic< PassManagerOptions > options
JIT-backed execution engine for MLIR.
llvm::Error invoke(StringRef funcName, Args... args)
Invokes the function with the given name passing it the list of arguments by value.
llvm::Expected< void(*)(void **)> lookupPacked(StringRef name) const
Looks up a packed-argument function wrapping the function with the given name and returns a pointer t...
void(*)(llvm::StringMap< void * > &) LibraryInitFn
Function type for init functions of shared libraries.
void(*)() LibraryDestroyFn
Function type for destroy functions of shared libraries.
void registerSymbols(llvm::function_ref< llvm::orc::SymbolMap(llvm::orc::MangleAndInterner)> symbolMap)
Register symbols with this ExecutionEngine.
llvm::Expected< void * > lookup(StringRef name) const
Looks up the original function with the given name and returns a pointer to it.
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.
void dumpToObjectFile(StringRef filename)
Dump object code to output file filename.
static constexpr const char *const kLibraryInitFnName
Name of init functions of shared libraries.
llvm::Error invokePacked(StringRef name, MutableArrayRef< void * > args=std::nullopt)
Invokes the function with the given name passing it the list of opaque pointers to the actual argumen...
static Result< T > result(T &t)
Helper function to wrap an output operand when using ExecutionEngine::invoke.
static constexpr const char *const kLibraryDestroyFnName
Name of destroy functions of shared libraries.
ExecutionEngine(bool enableObjectDump, bool enableGDBNotificationListener, bool enablePerfNotificationListener)
static void setupTargetTripleAndDataLayout(llvm::Module *llvmModule, llvm::TargetMachine *tm)
Set the target triple and the data layout for the input module based on the input TargetMachine.
Operation is the basic unit of execution within MLIR.
A simple object cache following Lang's LLJITWithObjectCache example.
bool isEmpty()
Returns true if cache hasn't been populated yet.
void notifyObjectCompiled(const llvm::Module *m, llvm::MemoryBufferRef objBuffer) override
void dumpToObjectFile(StringRef filename)
Dump cached object to output file filename.
std::unique_ptr< llvm::MemoryBuffer > getObject(const llvm::Module *m) override
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
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...
bool enablePerfNotificationListener
If enablePerfNotificationListener is set, the JIT compiler will notify the llvm's global Perf notific...
llvm::function_ref< std::unique_ptr< llvm::Module >Operation *, llvm::LLVMContext &)> llvmModuleBuilder
If llvmModuleBuilder is provided, it will be used to create an LLVM module from the given MLIR IR.
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...
llvm::SectionMemoryManager::MemoryMapper * sectionMemoryMapper
Specifies an existing sectionMemoryMapper to be associated with the compiled code.
bool enableGDBNotificationListener
If enable enableGDBNotificationListener is set, the JIT compiler will notify the llvm's global GDB no...
static void pack(SmallVectorImpl< void * > &args, Result< T > &result)
Trait that defines how a given type is passed to the JIT code.
static void pack(SmallVectorImpl< void * > &args, T &val)
Tag to wrap an output parameter when invoking a jitted function.