MLIR
20.0.0git
|
JIT-backed execution engine for MLIR. More...
#include "mlir/ExecutionEngine/ExecutionEngine.h"
Classes | |
struct | Argument |
Trait that defines how a given type is passed to the JIT code. More... | |
struct | Argument< Result< T > > |
struct | Result |
Tag to wrap an output parameter when invoking a jitted function. More... | |
Public Types | |
using | LibraryInitFn = void(*)(llvm::StringMap< void * > &) |
Function type for init functions of shared libraries. More... | |
using | LibraryDestroyFn = void(*)() |
Function type for destroy functions of shared libraries. More... | |
Public Member Functions | |
ExecutionEngine (bool enableObjectDump, bool enableGDBNotificationListener, bool enablePerfNotificationListener) | |
~ExecutionEngine () | |
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 to it. More... | |
llvm::Expected< void * > | lookup (StringRef name) const |
Looks up the original function with the given name and returns a pointer to it. More... | |
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 arguments. More... | |
template<typename... Args> | |
llvm::Error | invoke (StringRef funcName, Args... args) |
Invokes the function with the given name passing it the list of arguments by value. More... | |
void | dumpToObjectFile (StringRef filename) |
Dump object code to output file filename . More... | |
void | registerSymbols (llvm::function_ref< llvm::orc::SymbolMap(llvm::orc::MangleAndInterner)> symbolMap) |
Register symbols with this ExecutionEngine. More... | |
Static Public Member Functions | |
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. More... | |
template<typename T > | |
static Result< T > | result (T &t) |
Helper function to wrap an output operand when using ExecutionEngine::invoke. More... | |
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. More... | |
Static Public Attributes | |
static constexpr const char *const | kLibraryInitFnName |
Name of init functions of shared libraries. More... | |
static constexpr const char *const | kLibraryDestroyFnName |
Name of destroy functions of shared libraries. More... | |
JIT-backed execution engine for MLIR.
Assumes the IR can be converted to LLVM IR. For each function, creates a wrapper function with the fixed interface
void _mlir_funcName(void **)
where the only argument is interpreted as a list of pointers to the actual arguments of the function, followed by a pointer to the result. This allows the engine to provide the caller with a generic function pointer that can be used to invoke the JIT-compiled function.
Definition at line 114 of file ExecutionEngine.h.
using mlir::ExecutionEngine::LibraryDestroyFn = void (*)() |
Function type for destroy functions of shared libraries.
Definition at line 135 of file ExecutionEngine.h.
using mlir::ExecutionEngine::LibraryInitFn = void (*)(llvm::StringMap<void *> &) |
Function type for init functions of shared libraries.
The library may provide a list of symbols that it wants to make available to code run by the ExecutionEngine
. If the two functions are not defined, only symbols with public visibility are available to the executed code.
Definition at line 132 of file ExecutionEngine.h.
ExecutionEngine::ExecutionEngine | ( | bool | enableObjectDump, |
bool | enableGDBNotificationListener, | ||
bool | enablePerfNotificationListener | ||
) |
Definition at line 203 of file ExecutionEngine.cpp.
ExecutionEngine::~ExecutionEngine | ( | ) |
Definition at line 221 of file ExecutionEngine.cpp.
|
static |
Creates an execution engine for the given MLIR IR.
If TargetMachine is not provided, default TM is created (i.e. ignoring any command line flags that could affect the set-up).
Definition at line 233 of file ExecutionEngine.cpp.
Referenced by compileAndExecute(), and mlirExecutionEngineCreate().
void ExecutionEngine::dumpToObjectFile | ( | StringRef | filename | ) |
Dump object code to output file filename
.
Definition at line 101 of file ExecutionEngine.cpp.
References lookupPacked(), and result().
|
inline |
Invokes the function with the given name passing it the list of arguments by value.
Function result can be obtain through output parameter using the Result
wrapper defined above. For example:
func @foo(%arg0 : i32) -> i32 attributes { llvm.emit_c_interface }
can be invoked:
int32_t result = 0; llvm::Error error = jit->invoke("foo", 42, result(result));
Definition at line 207 of file ExecutionEngine.h.
References invokePacked(), and mlir::ExecutionEngine::Argument< T >::pack().
Error ExecutionEngine::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 arguments.
Definition at line 443 of file ExecutionEngine.cpp.
References Error, and lookupPacked().
Referenced by invoke().
Expected< void * > ExecutionEngine::lookup | ( | StringRef | name | ) | const |
Looks up the original function with the given name and returns a pointer to it.
This is not necesarily a packed function. Propagates errors in case of failure.
Definition at line 421 of file ExecutionEngine.cpp.
References makeStringError().
Expected< void(*)(void **)> ExecutionEngine::lookupPacked | ( | StringRef | name | ) | const |
Looks up a packed-argument function wrapping the function with the given name and returns a pointer to it.
Propagates errors in case of failure.
Definition at line 414 of file ExecutionEngine.cpp.
References makePackedFunctionName().
Referenced by dumpToObjectFile(), and invokePacked().
void ExecutionEngine::registerSymbols | ( | llvm::function_ref< llvm::orc::SymbolMap(llvm::orc::MangleAndInterner)> | symbolMap | ) |
Register symbols with this ExecutionEngine.
Definition at line 123 of file ExecutionEngine.cpp.
|
inlinestatic |
Helper function to wrap an output operand when using ExecutionEngine::invoke.
Definition at line 182 of file ExecutionEngine.h.
Referenced by dumpToObjectFile(), and mlir::ExecutionEngine::Argument< Result< T > >::pack().
|
static |
Set the target triple and the data layout for the input module based on the input TargetMachine.
This is implicitly done when creating the engine.
Definition at line 131 of file ExecutionEngine.cpp.
|
staticconstexpr |
Name of destroy functions of shared libraries.
If a library provides a function with this name and the one of the init function, this function is called upon destructing the ExecutionEngine
.
Definition at line 125 of file ExecutionEngine.h.
|
staticconstexpr |
Name of init functions of shared libraries.
If a library provides a function with this name and the one of the destroy function, this function is called upon loading the library.
Definition at line 119 of file ExecutionEngine.h.