[llvm-dev] ORC JIT - Can modules independently managed with one LLJIT instance?

Lang Hames via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 22 22:54:05 PDT 2020


Hi Bjoern,

Sounds like you want the removable code feature that's under development in
the orcv1-removal branch of https://github.com/lhames/llvm-project.git. I
will be aiming to merge this work back into the mainline some time in the
next couple of weeks.

I have not added a "removeJITDylib" method to ExecutionSession with this
feature yet, but will try to design and publish that tomorrow. Then you
should be able to do exactly what you want.

In the new system you can also perform fine grained removal: It is possible
to track and remove individual modules from within a JITDylib. For an
example of this see:
https://github.com/lhames/llvm-project/blob/7ec9f8930f68760953a483157e010d0ff88285cd/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp#L1148,
from lines 1148 to line 1161.

Also a related but different question:
> When using llvm::parseIRFile I need to pass it a LLVMContext - should this
> be a unique one for every module I pass or can I use a global one?


It depends on whether you want to be able to compile concurrently in the
JIT process. If you do want to compile concurrently then each module should
get its own context. If you are happy to stick to single threaded
compilation you can load all modules on the same context, potentially
saving some memory.

-- Lang.

On Thu, Sep 17, 2020 at 11:59 PM Gaier, Bjoern <Bjoern.Gaier at horiba.com>
wrote:

> Hello everyone and Lang,
>
>
>
> I have another design or "how-to" question about the ORC JIT. Sorry for
> having so many about them, to me this is a really complicated yet
> fascinating subject...
>
>
>
> How would I design an ORC JIT with the following requirements?
>
> At any time it should be possible to load a LLVM Module, every Module is
> independent and is not allowed to be linked with the other modules, every
> module can be removed at any time.
>
>
>
> My first idea was to have an ORC JIT for every module I load, but then I
> wondered if I could use a single ORC JIT for it.
>
>
>
> So, I would create an ORC JIT:
>
> - using llvm::orc::LLJITBuilder
>
> - configurating it
>
> - adding a custom memory manager that requests the entire memory size
>
>
>
> Then I would call "getMainJITDylib" and fill it with symbols that are
> valid for every module:
>
> - adding printf, strlen, usw.
>
>
>
> Now when I get a request to load a module:
>
> - load module
>
> - get symbols I want to look up
>
> - create new DyLib and add module to that
>
>
>
> Now I would do a lookup on that module, plus the main module to get symbol
> addresses and stuff
>
>
>
> If a new module is added, it goes to a new DyLib as well and so on.
>
>
>
> -----
>
>
>
> However, now I want to delete a module again. Killing the memory is fairly
> easy with my custom memory manager, but I still have my DyLib of the now
> dead code... Can I get rid of it without dumping the others or the entire
> ORC JIT?
>
> Or is there a different approach to do this? My goal with this is to speed
> up the setup phase for a module and also to reduce dynamic memory usage.
>
>
>
> Also a related but different question:
>
> When using llvm::parseIRFile I need to pass it a LLVMContext - should this
> be a unique one for every module I pass or can I use a global one?
>
>
>
> Kind greetings and thank you all again,
>
> Björn
> Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816,
> USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert
> Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Junichi Tajika, Ergin
> Cansiz.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200922/3f22a541/attachment.html>


More information about the llvm-dev mailing list