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? thanks Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110726/c5ec9108/attachment.html>
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
Possibly Parallel Threads
- [LLVMdev] JIT : Does it cache the compiled code of executed functions upon runFunction(..)?
- [LLVMdev] JIT : Does it cache the compiled code of executed functions upon runFunction(..)?
- [LLVMdev] Getting the start and end address of JITted code
- [LLVMdev] Unit testing with random input using JIT
- [LLVMdev] GSOC Adaptive Compilation Framework for LLVM JIT Compiler