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 @@ -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> create( - ModuleOp m, std::function transformer = {}, - Optional jitCodeGenOptLevel = llvm::None, - ArrayRef 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> + create(ModuleOp m, + std::function transformer = {}, + Optional jitCodeGenOptLevel = llvm::None, + ArrayRef 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. 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 @@ -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> ExecutionEngine::create( ModuleOp m, std::function transformer, Optional jitCodeGenOptLevel, - ArrayRef sharedLibPaths, bool enableObjectCache) { - auto engine = std::make_unique(enableObjectCache); + ArrayRef sharedLibPaths, bool enableObjectCache, + bool enableGDBNotificationListener) { + auto engine = std::make_unique( + enableObjectCache, enableGDBNotificationListener); std::unique_ptr 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( - reinterpret_cast(object.getData().data())); - engine->gdbListener->notifyObjectLoaded(key, object, objectInfo); + if (engine->gdbListener) { + uint64_t key = static_cast( + reinterpret_cast(object.getData().data())); + engine->gdbListener->notifyObjectLoaded(key, object, objectInfo); + } }); // Resolve symbols from shared libraries.