MLIR  16.0.0git
Classes | Public Member Functions | Static Public Member Functions | List of all members
mlir::ExecutionEngine Class Reference

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 Member Functions

 ExecutionEngine (bool enableObjectDump, bool enableGDBNotificationListener, bool enablePerfNotificationListener)
 
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=llvm::None)
 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={})
 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 bool setupTargetTriple (llvm::Module *llvmModule)
 Set the target triple on the module. More...
 

Detailed Description

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 105 of file ExecutionEngine.h.

Constructor & Destructor Documentation

◆ ExecutionEngine()

ExecutionEngine::ExecutionEngine ( bool  enableObjectDump,
bool  enableGDBNotificationListener,
bool  enablePerfNotificationListener 
)

Definition at line 232 of file ExecutionEngine.cpp.

Member Function Documentation

◆ create()

Expected< std::unique_ptr< ExecutionEngine > > ExecutionEngine::create ( Operation op,
const ExecutionEngineOptions options = {} 
)
static

◆ dumpToObjectFile()

void ExecutionEngine::dumpToObjectFile ( StringRef  filename)

Dump object code to output file filename.

Definition at line 101 of file ExecutionEngine.cpp.

References lookupPacked(), and result().

◆ invoke()

template<typename... Args>
llvm::Error mlir::ExecutionEngine::invoke ( StringRef  funcName,
Args...  args 
)
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 172 of file ExecutionEngine.h.

References invokePacked(), and mlir::ExecutionEngine::Argument< T >::pack().

◆ invokePacked()

Error ExecutionEngine::invokePacked ( StringRef  name,
MutableArrayRef< void * >  args = llvm::None 
)

Invokes the function with the given name passing it the list of opaque pointers to the actual arguments.

Definition at line 392 of file ExecutionEngine.cpp.

References Error, lookupPacked(), and mlir::success().

Referenced by invoke().

◆ lookup()

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 370 of file ExecutionEngine.cpp.

References makeStringError().

◆ lookupPacked()

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 363 of file ExecutionEngine.cpp.

References makePackedFunctionName().

Referenced by dumpToObjectFile(), and invokePacked().

◆ registerSymbols()

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.

◆ result()

template<typename T >
static Result<T> mlir::ExecutionEngine::result ( T &  t)
inlinestatic

Helper function to wrap an output operand when using ExecutionEngine::invoke.

Definition at line 147 of file ExecutionEngine.h.

Referenced by dumpToObjectFile(), and mlir::ExecutionEngine::Argument< Result< T > >::pack().

◆ setupTargetTriple()

bool ExecutionEngine::setupTargetTriple ( llvm::Module *  llvmModule)
static

Set the target triple on the module.

This is implicitly done when creating the engine.

Definition at line 132 of file ExecutionEngine.cpp.

Referenced by create().


The documentation for this class was generated from the following files: