MLIR  19.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | 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 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...
 

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

Member Typedef Documentation

◆ LibraryDestroyFn

Function type for destroy functions of shared libraries.

Definition at line 135 of file ExecutionEngine.h.

◆ LibraryInitFn

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.

Constructor & Destructor Documentation

◆ ExecutionEngine()

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

Definition at line 203 of file ExecutionEngine.cpp.

◆ ~ExecutionEngine()

ExecutionEngine::~ExecutionEngine ( )

Definition at line 221 of file ExecutionEngine.cpp.

Member Function Documentation

◆ create()

Expected< std::unique_ptr< ExecutionEngine > > ExecutionEngine::create ( Operation op,
const ExecutionEngineOptions options = {},
std::unique_ptr< llvm::TargetMachine >  tm = nullptr 
)
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.

References mlir::Region::getOps(), mlir::Operation::getRegion(), kLibraryDestroyFnName, kLibraryInitFnName, makeStringError(), options, packFunctionArguments(), setupTargetTripleAndDataLayout(), and mlir::translateModuleToLLVMIR().

Referenced by compileAndExecute().

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

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

◆ invokePacked()

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, 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 421 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 414 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 182 of file ExecutionEngine.h.

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

◆ setupTargetTripleAndDataLayout()

void ExecutionEngine::setupTargetTripleAndDataLayout ( llvm::Module *  llvmModule,
llvm::TargetMachine *  tm 
)
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.

Referenced by create().

Member Data Documentation

◆ kLibraryDestroyFnName

constexpr const char* const mlir::ExecutionEngine::kLibraryDestroyFnName
staticconstexpr
Initial value:
=
"__mlir_execution_engine_destroy"

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.

Referenced by create().

◆ kLibraryInitFnName

constexpr const char* const mlir::ExecutionEngine::kLibraryInitFnName
staticconstexpr
Initial value:
=
"__mlir_execution_engine_init"

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.

Referenced by create().


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