Get IR Module From ORC Jit (original) (raw)
Hey.
Is it possible to get an IR module that I’ve added to an ORC Jit execution session back temporarily? From the looks of it ThreadSafeModule has withModuleDo, but I can’t actually find a way to get to the ThreadSafeModule in the first place.
I want to do something like:
_compileLayer.add(
*getMain(),
std::move(_module));
// Things happen here
// Bit I can't figure out how to do
ThreadSafeModule threadSafeModule = getThreadSafeModuleReferenceFromCompileLayer();
threadSafeModule.withModuleDo([](Module& mod) {
// Do thing with the underlying module here
});
I don’t think you can retrieve a ThreadSafeModule from the compile layer after adding it, but I guess you can store a reference to it before adding it and then modify that instead.
lhames May 15, 2025, 1:37am 3
Hi @moff181.
Retaining a reference to modules added to the JIT is dangerous: In general the JIT may compile the module at any time, so you have no way of knowing (from outside the JIT) whether you’re about to access the module pre-compilation, post-compilation, or during compilation.
In general you can access / mutate the module prior to adding it to the JIT, or from inside the JIT pipeline by using an IRTransformLayer (see e.g. llvm-project/llvm/examples/OrcV2Examples/LLJITWithOptimizingIRTransform/LLJITWithOptimizingIRTransform.cpp at 34be80aa6edda60e240e4ea46f28b1b54ababf72 · llvm/llvm-project · GitHub).