Skip to content

Commit 6f3aa37

Browse files
committed
Use getExecutionEngine to obtain the JIT for Cling > LLVM16
1 parent 57d09bd commit 6f3aa37

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

lib/Interpreter/Compatibility.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,34 @@ inline void maybeMangleDeclName(const clang::GlobalDecl& GD,
8585
cling::utils::Analyze::maybeMangleDeclName(GD, mangledName);
8686
}
8787

88-
inline llvm::orc::LLJIT* getExecutionEngine(const cling::Interpreter& I) {
89-
// FIXME: This is a horrible hack finding the llvm::orc::LLJIT by computing
90-
// the object offsets in Cling. We should add getExecutionEngine interface
91-
// to directly.
88+
/// For Cling <= LLVM 16, this is a horrible hack obtaining the *private* llvm::orc::LLJIT by computing
89+
/// the object offsets in the cling::Interpreter instance(IncrementalExecutor):
90+
/// sizeof (m_Opts) + sizeof(m_LLVMContext)
91+
/// The IncrementalJIT and JIT itself have an offset of 0 as the first datamember.
92+
///
93+
/// The getExecutionEngine() interface has been added for Cling >=18 and should be used in future releases.
94+
inline llvm::orc::LLJIT* getExecutionEngine(cling::Interpreter& I) {
95+
#if CLANG_VERSION_MAJOR >= 18
96+
return I.getExecutionEngine();
97+
#endif
9298

93-
// sizeof (m_Opts) + sizeof(m_LLVMContext)
99+
#if CLANG_VERSION_MAJOR == 13
100+
#ifdef __APPLE__
101+
const unsigned m_ExecutorOffset = 62;
102+
#else
103+
const unsigned m_ExecutorOffset = 72;
104+
#endif // __APPLE__
105+
#endif
106+
107+
// Note: The offsets changed in LLVM 16 with the introduction of
108+
#if CLANG_VERSION_MAJOR == 16
94109
#ifdef __APPLE__
95110
const unsigned m_ExecutorOffset = 62;
96111
#else
97112
const unsigned m_ExecutorOffset = 72;
98113
#endif // __APPLE__
114+
#endif
115+
99116
int* IncrementalExecutor =
100117
((int*)(const_cast<cling::Interpreter*>(&I))) + m_ExecutorOffset;
101118
int* IncrementalJit = *(int**)IncrementalExecutor + 0;
@@ -104,7 +121,7 @@ inline llvm::orc::LLJIT* getExecutionEngine(const cling::Interpreter& I) {
104121
}
105122

106123
inline llvm::Expected<llvm::JITTargetAddress>
107-
getSymbolAddress(const cling::Interpreter& I, llvm::StringRef IRName) {
124+
getSymbolAddress(cling::Interpreter& I, llvm::StringRef IRName) {
108125
if (void* Addr = I.getAddressOfGlobal(IRName))
109126
return (llvm::JITTargetAddress)Addr;
110127

0 commit comments

Comments
 (0)