[LLVMdev] two questions about JIT compilation

Eric Christopher echristo at apple.com
Mon Aug 8 13:56:49 PDT 2011


On Jul 26, 2011, at 6:22 PM, Nicholas Lester wrote:

> hi all,
> 
> I've written a small language implementation that JIT-compiles code prior to execution.  At the moment, i execute the function through ExecutionEngine::runFunction.  However, this requires me to keep all of the code generation artifacts (instructions, constants, etc) around during execution.  Given that execution compiles the program down to machine code, is there a reasonably straight-forward way to discard the contents of my generated Module, and simply call the JITted function through a pointer obtained through ExecutionEngine::getPointerToFunction?  I tried creating an independent JITMemoryManager and keeping that around, but the execution engine takes ownership of it (maybe to prevent this behaviour?).
> 
> My second question is about how to embed a reference to a c/c++ function into LLVM-generated code.  I'm only interested in the JIT case, so this code doesn't have to outlive the generating executable's lifetime.  The way i think this can be achieved is to cast a pointer to this function to an int, insert it into the generated code via ConstantInt, then use inttoptr to cast it back to the correct function type and call it.  Is there a more direct way of doing this?

You could delete the body of the function that's being jitted after you call getPointerToFunction.

-eric



More information about the llvm-dev mailing list