I have a function in llvm ir as follows: def [2 x [3 x double]] @fun() { return [ ... ]; // a [2 x [3 x double]] constant } I would like to JIT this function in C. I first get the void pointer using: void *FPtr = TheExecutionEngine->getPointerToFunction( func ); Then I need to conver this void pointer to the corresponding C function pointer type, and then call the function pointer. double a[2][3]; CType *FP = (CType*) FPtr; a = FP(); My question is that: 1. Is this JIT work flow supported by LLVM? 2. If yes, what is correct CType for the JITted function? 3. If not, what are requirements on the LLVM function IRs such that they could be JIT and called in C? Thanks, -Peng -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120806/5751c4c9/attachment.html>
On Mon, Aug 6, 2012 at 9:35 AM, Peng Cheng <gm4cheng at gmail.com> wrote:> I have a function in llvm ir as follows: > > def [2 x [3 x double]] @fun() > { > return [ ... ]; // a [2 x [3 x double]] constant > } > > I would like to JIT this function in C. > > I first get the void pointer using: > > void *FPtr = TheExecutionEngine->getPointerToFunction( func ); > > Then I need to conver this void pointer to the corresponding C function > pointer > type, and then call the function pointer. > > double a[2][3]; > > CType *FP = (CType*) FPtr; > > a = FP(); > > My question is that: > > 1. Is this JIT work flow supported by LLVM?Sort of?> 2. If yes, what is correct CType for the JITted function?Probably "typedef void FPtr(double*);", but that's not guaranteed.> 3. If not, what are requirements on the LLVM function IRs such that they > could be JIT and called in C?If you want to generate functions which are easily callable from C, make sure the return type and all the parameters are pointers or simple values; otherwise, the correct rule for converting from C types to IR types is complicated and platform-specific. -Eli
Thanks! On Monday, August 6, 2012, Eli Friedman wrote:> On Mon, Aug 6, 2012 at 9:35 AM, Peng Cheng <gm4cheng at gmail.com<javascript:;>> > wrote: > > I have a function in llvm ir as follows: > > > > def [2 x [3 x double]] @fun() > > { > > return [ ... ]; // a [2 x [3 x double]] constant > > } > > > > I would like to JIT this function in C. > > > > I first get the void pointer using: > > > > void *FPtr = TheExecutionEngine->getPointerToFunction( func ); > > > > Then I need to conver this void pointer to the corresponding C function > > pointer > > type, and then call the function pointer. > > > > double a[2][3]; > > > > CType *FP = (CType*) FPtr; > > > > a = FP(); > > > > My question is that: > > > > 1. Is this JIT work flow supported by LLVM? > > Sort of? > > > 2. If yes, what is correct CType for the JITted function? > > Probably "typedef void FPtr(double*);", but that's not guaranteed. > > > 3. If not, what are requirements on the LLVM function IRs such that they > > could be JIT and called in C? > > If you want to generate functions which are easily callable from C, > make sure the return type and all the parameters are pointers or > simple values; otherwise, the correct rule for converting from C types > to IR types is complicated and platform-specific. > > -Eli >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120809/346c447e/attachment.html>
Maybe Matching Threads
- [LLVMdev] Question about llvm JIT
- [LLVMdev] JIT question: Inner workings of getPointerToFunction()
- [LLVMdev] Kaleidoscope toy4 failure seg fault on llvm::ExecutionEngine::getTargetData (this=0x0)
- [LLVMdev] Kaleidoscope toy4 failure seg fault on llvm::ExecutionEngine::getTargetData (this=0x0)
- [LLVMdev] JIT question: Inner workings of getPointerToFunction()