[LLVMdev] Module management questions

Larry Gritz lg at larrygritz.com
Mon Aug 16 15:47:25 PDT 2010

I have an app that's dynamically generating and JITing code, and will have many such cases in the course of its run.  They need to be JITed separately, because I need to execute the first batch before I know what the second one will be.  Of course, I *still* need to execute the first after the need for the second arises, so I need to retain the JITed machine code for all the functions I dynamically compile.

I think I just discovered the hard way that I can't keep adding to a single Module and ExecutionEngine, and re-optimizing -- certain combinations of optimization passes evidently are not happy doing this.  In particular, I seem to have special problems with templated (but not explicitly 'inline') C++ functions, when llvm inlining passes are used.  It seems to JIT fine, no errors, but I end up with my JITed code crashing upon execution (seg faults, and occasionally unknown opcodes).

First question: can anybody confirm my theory, that it is not in fact safe/proper to add more functions to an already-optimized Module/ExecutionEngine and then perform more passes on it again?

Assuming that is the case...  I'm very concerned about leaks and resource usage (including memory) if I need to create a new module and/or EE for every one of these sets of functions that I need to dynamically compile.

Second question: what's the best way to proceed?  What's the approved way to completely free a Module/EE?  And can I do so and still retain the JITed machine code to continue executing?

Larry Gritz
lg at larrygritz.com (a.k.a. lg at imageworks.com)

More information about the llvm-dev mailing list