From 62172702a6885cf1e7e7f846ee1c707940a989d5 Mon Sep 17 00:00:00 2001 From: Aaron Jomy Date: Thu, 26 Sep 2024 14:53:39 +0200 Subject: [PATCH] Add interfaces that expose JIT This allows us to access the `llvm::orc::LLJIT` similar to the `getExecutionEngine` interface in clang-repl which is required for the functioning of libInterOp starting from LLVM 16 --- include/cling/Interpreter/Interpreter.h | 6 ++++++ lib/Interpreter/IncrementalExecutor.h | 3 +++ lib/Interpreter/IncrementalJIT.h | 3 +++ lib/Interpreter/Interpreter.cpp | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/include/cling/Interpreter/Interpreter.h b/include/cling/Interpreter/Interpreter.h index b2d3131e3e..9c0bac1a44 100644 --- a/include/cling/Interpreter/Interpreter.h +++ b/include/cling/Interpreter/Interpreter.h @@ -36,6 +36,7 @@ namespace llvm { template class SmallVectorImpl; namespace orc { class DefinitionGenerator; + class LLJIT; } } @@ -771,6 +772,11 @@ namespace cling { const InterpreterCallbacks* getCallbacks() const {return m_Callbacks.get();} InterpreterCallbacks* getCallbacks() { return m_Callbacks.get(); } + ///\brief Returns the JIT managed by the Interpreter. + /// Accesses and returns the JIT held in the IncrementalJIT instance + /// managed by m_Executor + llvm::orc::LLJIT* getExecutionEngine(); + const DynamicLibraryManager* getDynamicLibraryManager() const; DynamicLibraryManager* getDynamicLibraryManager(); diff --git a/lib/Interpreter/IncrementalExecutor.h b/lib/Interpreter/IncrementalExecutor.h index 428331c4a5..eeb89f2eab 100644 --- a/lib/Interpreter/IncrementalExecutor.h +++ b/lib/Interpreter/IncrementalExecutor.h @@ -154,6 +154,9 @@ namespace cling { void setCallbacks(InterpreterCallbacks* callbacks); + ///\brief Return the LLJIT held by the IncrementalJIT + llvm::orc::LLJIT* getLLJIT() { return m_JIT ? m_JIT->getLLJIT() : nullptr; } + const DynamicLibraryManager& getDynamicLibraryManager() const { return const_cast(this)->m_DyLibManager; } diff --git a/lib/Interpreter/IncrementalJIT.h b/lib/Interpreter/IncrementalJIT.h index e907d57046..6fefecb280 100644 --- a/lib/Interpreter/IncrementalJIT.h +++ b/lib/Interpreter/IncrementalJIT.h @@ -102,6 +102,9 @@ class IncrementalJIT { return Jit->initialize(Jit->getMainJITDylib()); } + /// @brief Return a pointer to the JIT held by IncrementalJIT object + llvm::orc::LLJIT* getLLJIT() { return Jit.get(); } + /// @brief Get the TargetMachine used by the JIT. /// Non-const because BackendPasses need to update OptLevel. llvm::TargetMachine &getTargetMachine() { return *m_TM; } diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index 44187b2d8d..6af9010850 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -1670,6 +1670,13 @@ namespace cling { ->addCallback(std::move(C)); } + llvm::orc::LLJIT* Interpreter::getExecutionEngine() { + if (!m_Executor) + return nullptr; + + return m_Executor->getLLJIT(); + } + const DynamicLibraryManager* Interpreter::getDynamicLibraryManager() const { assert(m_Executor.get() && "We must have an executor"); return &m_Executor->getDynamicLibraryManager();