[PATCH] D79812: [MLIR] Add symbol map to mlir ExecutionEngine

Eugene Zhulenev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 12 21:32:57 PDT 2020


ezhulenev updated this revision to Diff 263600.
ezhulenev added a comment.

Pass symbolMap as a std::function callback.s


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79812/new/

https://reviews.llvm.org/D79812

Files:
  mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
  mlir/lib/ExecutionEngine/ExecutionEngine.cpp


Index: mlir/lib/ExecutionEngine/ExecutionEngine.cpp
===================================================================
--- mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -196,8 +196,10 @@
 Expected<std::unique_ptr<ExecutionEngine>> ExecutionEngine::create(
     ModuleOp m, std::function<Error(llvm::Module *)> transformer,
     Optional<llvm::CodeGenOpt::Level> jitCodeGenOptLevel,
-    ArrayRef<StringRef> sharedLibPaths, bool enableObjectCache,
-    bool enableGDBNotificationListener, bool enablePerfNotificationListener) {
+    ArrayRef<StringRef> sharedLibPaths,
+    std::function<llvm::orc::SymbolMap(llvm::orc::MangleAndInterner)> symbolMap,
+    bool enableObjectCache, bool enableGDBNotificationListener,
+    bool enablePerfNotificationListener) {
   auto engine = std::make_unique<ExecutionEngine>(
       enableObjectCache, enableGDBNotificationListener,
       enablePerfNotificationListener);
@@ -288,6 +290,13 @@
       cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
           dataLayout.getGlobalPrefix())));
 
+  // Add additional symbols provided via the symbol map.
+  if (symbolMap) {
+    auto symbols = symbolMap(
+        llvm::orc::MangleAndInterner(mainJD.getExecutionSession(), dataLayout));
+    cantFail(mainJD.define(absoluteSymbols(std::move(symbols))));
+  }
+
   return std::move(engine);
 }
 
Index: mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
===================================================================
--- mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
+++ mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
@@ -63,25 +63,37 @@
   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 `symbolMap` is provided, it will be called with a name mangler bound
+  /// to the underlying JIT-compilation engine. All symbols in the returned
+  /// symbol map will be added 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<std::unique_ptr<ExecutionEngine>>
-  create(ModuleOp m,
-         std::function<llvm::Error(llvm::Module *)> transformer = {},
-         Optional<llvm::CodeGenOpt::Level> jitCodeGenOptLevel = llvm::None,
-         ArrayRef<StringRef> sharedLibPaths = {}, bool enableObjectCache = true,
-         bool enableGDBNotificationListener = true,
-         bool enablePerfNotificationListener = true);
+  static llvm::Expected<std::unique_ptr<ExecutionEngine>> create(
+      ModuleOp m, std::function<llvm::Error(llvm::Module *)> transformer = {},
+      Optional<llvm::CodeGenOpt::Level> jitCodeGenOptLevel = llvm::None,
+      ArrayRef<StringRef> sharedLibPaths = {},
+      std::function<llvm::orc::SymbolMap(llvm::orc::MangleAndInterner)>
+          symbolMap = {},
+      bool enableObjectCache = true, bool enableGDBNotificationListener = true,
+      bool enablePerfNotificationListener = true);
 
   /// Looks up a packed-argument function with the given name and returns a
   /// pointer to it.  Propagates errors in case of failure.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79812.263600.patch
Type: text/x-patch
Size: 4797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200513/494289f2/attachment.bin>


More information about the llvm-commits mailing list