[llvm-dev] Question about addModule in orc::IRCompileLayer (now orc::LegacyIRCompileLayer)

Riyaz Puthiyapurayil via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 26 14:48:48 PDT 2019

I am trying to convert some very old code based on LLVM 3.4.2 to LLVM 7. So I want to replace some old LLVM JIT code with OrcJIT. I am new to this stuff and when I study the Kaleidoscope example, I started wondering about this.

LLVMContext stores raw pointers to Module and will destroy the Module when the context is destroyed. But in the example, the module's ownership is transferred to IRCompileLayer (which in trunk seems to be now LegacyIRCompileLayer) which will destroy the module after eagerly compiling it using SimpleCompiler. Wouldn't that leave the pointer to the same Module held in LLVMContext's OwnedModules dangling?

AFAIK, LLVMContext always owns the modules with which it is constructed (it holds them as Module*) unless it is explicitly removed from the Context. So it is not clear how std::unique_ptr can be used on the same pointer.

Specifically, the problem is in this line:

  TheModule = llvm::make_unique<Module>("my cool jit", TheContext);

TheModule owns the new module but so does TheContext (though not explicitly via unique_ptr).

And then later we have:


The ownership is transferred but TheContext is still pointing to Module.

Note my question is not specifically about Kaleidoscope example but more about orc::LegacyIRCompileLayer::addModule expecting the caller to transfer ownership of a module.

Am I missing something here? TIA.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190626/64d8b2ab/attachment.html>

More information about the llvm-dev mailing list