diff --git a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h --- a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h +++ b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h @@ -63,21 +63,28 @@ ExecutionEngine(bool enableObjectCache, bool enableGDBNotificationListener, bool enablePerfNotificationListener); - /// Creates an execution engine for the given module. If `transformer` is - /// provided, it will be called on the LLVM module during JIT-compilation and - /// can be used, e.g., for reporting or optimization. `jitCodeGenOptLevel`, - /// when provided, is used as the optimization level for target code - /// generation. If `sharedLibPaths` are provided, the underlying - /// JIT-compilation will open and link the shared libraries for symbol - /// resolution. If `enableObjectCache` is set, the JIT compiler will create - /// one to store the object generated for the given module. If enable - /// `enableGDBNotificationListener` is set, the JIT compiler will notify - /// the llvm's global GDB notification listener. If - /// `enablePerfNotificationListener` is set, the JIT compiler will notify + /// Creates an execution engine for the given module. + /// + /// If `transformer` is provided, it will be called on the LLVM module during + /// JIT-compilation and can be used, e.g., for reporting or optimization. + /// + /// `jitCodeGenOptLevel`, when provided, is used as the optimization level for + /// target code generation. + /// + /// If `sharedLibPaths` are provided, the underlying JIT-compilation will + /// open and link the shared libraries for symbol resolution. + /// + /// If `enableObjectCache` is set, the JIT compiler will create one to store + /// the object generated for the given module. + /// + /// If enable `enableGDBNotificationListener` is set, the JIT compiler will + /// notify the llvm's global GDB notification listener. + /// + /// If `enablePerfNotificationListener` is set, the JIT compiler will notify /// the llvm's global Perf notification listener. static llvm::Expected> create(ModuleOp m, - std::function transformer = {}, + llvm::function_ref transformer = {}, Optional jitCodeGenOptLevel = llvm::None, ArrayRef sharedLibPaths = {}, bool enableObjectCache = true, bool enableGDBNotificationListener = true, @@ -105,6 +112,11 @@ /// Dump object code to output file `filename`. void dumpToObjectFile(StringRef filename); + /// Register symbols with an underlying JIT-compilation engine. + void registerSymbols( + llvm::function_ref + symbolMap); + private: /// Ordering of llvmContext and jit is important for destruction purposes: the /// jit must be destroyed before the context. diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp --- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp @@ -51,7 +51,9 @@ using llvm::orc::ExecutionSession; using llvm::orc::IRCompileLayer; using llvm::orc::JITTargetMachineBuilder; +using llvm::orc::MangleAndInterner; using llvm::orc::RTDyldObjectLinkingLayer; +using llvm::orc::SymbolMap; using llvm::orc::ThreadSafeModule; using llvm::orc::TMOwningSimpleCompiler; @@ -99,6 +101,14 @@ cache->dumpToObjectFile(filename); } +void ExecutionEngine::registerSymbols( + llvm::function_ref symbolMap) { + auto &mainJitDylib = jit->getMainJITDylib(); + cantFail(mainJitDylib.define( + absoluteSymbols(symbolMap(llvm::orc::MangleAndInterner( + mainJitDylib.getExecutionSession(), jit->getDataLayout()))))); +} + // Setup LLVM target triple from the current machine. bool ExecutionEngine::setupTargetTriple(Module *llvmModule) { // Setup the machine properties from the current architecture. @@ -194,7 +204,7 @@ : nullptr) {} Expected> ExecutionEngine::create( - ModuleOp m, std::function transformer, + ModuleOp m, llvm::function_ref transformer, Optional jitCodeGenOptLevel, ArrayRef sharedLibPaths, bool enableObjectCache, bool enableGDBNotificationListener, bool enablePerfNotificationListener) {