[LLVMdev] Module management questions

Nicolas Capens nicolas.capens at gmail.com
Mon Aug 23 07:25:23 PDT 2010

Hi Larry,

I faced the same issue and solved it by writing my own JITMemoryManager.
This is the class that is responsible for allocating memory for the JITed
functions. So your derived implementation can let the application take
ownership of this memory before destructing the entire execution engine.
createJIT takes a JITMemoryManager as parameter, so it's straightforward to
make it use your derived class.

Good luck!


-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
Behalf Of Larry Gritz
Sent: Tuesday, August 17, 2010 0:47
To: llvmdev at cs.uiuc.edu
Subject: [LLVMdev] Module management questions

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)

LLVM Developers mailing list
LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu

More information about the llvm-dev mailing list