Skip to content

Commit

Permalink
Add interfaces that expose JIT
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aaronj0 authored and jenkins committed Sep 30, 2024
1 parent c30873f commit 6217270
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/cling/Interpreter/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace llvm {
template <typename T> class SmallVectorImpl;
namespace orc {
class DefinitionGenerator;
class LLJIT;
}
}

Expand Down Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions lib/Interpreter/IncrementalExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<IncrementalExecutor*>(this)->m_DyLibManager;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Interpreter/IncrementalJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
7 changes: 7 additions & 0 deletions lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6217270

Please sign in to comment.