[PATCH] D75787: [mlir] [ExecutionEngine] add option to enable/disable GDB notification listener

Aart Bik via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 17:08:54 PST 2020


aartbik created this revision.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.

This way, clients can opt-out of the GDB notification listener. Also, this
changes the semantics of enabling the object cache, which seemed the wrong
way around.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75787

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
@@ -182,15 +182,20 @@
   }
 }
 
-ExecutionEngine::ExecutionEngine(bool enableObjectCache)
-    : cache(enableObjectCache ? nullptr : new SimpleObjectCache()),
-      gdbListener(llvm::JITEventListener::createGDBRegistrationListener()) {}
+ExecutionEngine::ExecutionEngine(bool enableObjectCache,
+                                 bool enableGDBNotificationListener)
+    : cache(enableObjectCache ? new SimpleObjectCache() : nullptr),
+      gdbListener(enableGDBNotificationListener
+                      ? llvm::JITEventListener::createGDBRegistrationListener()
+                      : nullptr) {}
 
 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) {
-  auto engine = std::make_unique<ExecutionEngine>(enableObjectCache);
+    ArrayRef<StringRef> sharedLibPaths, bool enableObjectCache,
+    bool enableGDBNotificationListener) {
+  auto engine = std::make_unique<ExecutionEngine>(
+      enableObjectCache, enableGDBNotificationListener);
 
   std::unique_ptr<llvm::LLVMContext> ctx(new llvm::LLVMContext);
   auto llvmModule = translateModuleToLLVMIR(m);
@@ -228,9 +233,11 @@
         [engine = engine.get()](
             llvm::orc::VModuleKey, const llvm::object::ObjectFile &object,
             const llvm::RuntimeDyld::LoadedObjectInfo &objectInfo) {
-          uint64_t key = static_cast<uint64_t>(
-              reinterpret_cast<uintptr_t>(object.getData().data()));
-          engine->gdbListener->notifyObjectLoaded(key, object, objectInfo);
+          if (engine->gdbListener) {
+            uint64_t key = static_cast<uint64_t>(
+                reinterpret_cast<uintptr_t>(object.getData().data()));
+            engine->gdbListener->notifyObjectLoaded(key, object, objectInfo);
+          }
         });
 
     // Resolve symbols from shared libraries.
Index: mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
===================================================================
--- mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
+++ mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
@@ -60,7 +60,7 @@
 /// be used to invoke the JIT-compiled function.
 class ExecutionEngine {
 public:
-  ExecutionEngine(bool enableObjectCache);
+  ExecutionEngine(bool enableObjectCache, bool enableGDBNotificationListener);
 
   /// Creates an execution engine for the given module.  If `transformer` is
   /// provided, it will be called on the LLVM module during JIT-compilation and
@@ -68,12 +68,16 @@
   /// 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 `objectCache` is provided, JIT compiler will use it to
-  /// store the object generated for the given module.
-  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 = false);
+  /// 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.
+  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);
 
   /// 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: D75787.248863.patch
Type: text/x-patch
Size: 4281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200307/8f85d3f6/attachment.bin>


More information about the llvm-commits mailing list