Tobias Pankrath
2015-Jan-08 16:11 UTC
[LLVMdev] JIT simple module and accessing the value fails
I'm using the llvm-c API and want to use the JIT. I've created the following module ; ModuleID = '_tmp' @a = global i64 5 define i64 @__tempfunc() { entry: %a_val = load i64* @a ret i64 %a_val } This output is generated by LLVMDumpModule just before I call LLVMRunFunction. Which yields a LLVMGenericValueRef. However converting the result to a 64bit integer via LLVMGenericValueToInt(gv, true), it results in 360287970189639680 or something similar - not 5. Converting via LLVMGenericValueToInt(gv, false) didn't help either. How can I use global variables in a JIT situation? Is anything wrong with the IR?
Tobias Pankrath
2015-Jan-08 16:52 UTC
[LLVMdev] JIT simple module and accessing the value fails
On Thursday 08 January 2015 17:11:15 Tobias Pankrath wrote:> This output is generated by LLVMDumpModule just before I call > LLVMRunFunction. Which yields a LLVMGenericValueRef. However converting the > result to a 64bit integer via LLVMGenericValueToInt(gv, true), it results > in 360287970189639680 or something similar - not 5. Converting via > LLVMGenericValueToInt(gv, false) didn't help either. > > How can I use global variables in a JIT situation? Is anything wrong with > the IR? >Okay, I already figured out that it has to do with the datalayout. How do I set it correctly? I'm working on a linux x86_64 and I tried LLVMSetDataLayout(mod, "x86_64-pc-linux") which crashes the program with LLVM ERROR: not a number, or does not fit in an unsigned int Using just LLVMSetDataLayout(mod, "e") solves it for now, would still like to know what the correct setting is / why x86_64-pc-linux does not work.
Jonathan Roelofs
2015-Jan-08 17:10 UTC
[LLVMdev] JIT simple module and accessing the value fails
On 1/8/15 9:52 AM, Tobias Pankrath wrote:> On Thursday 08 January 2015 17:11:15 Tobias Pankrath wrote: >> This output is generated by LLVMDumpModule just before I call >> LLVMRunFunction. Which yields a LLVMGenericValueRef. However converting the >> result to a 64bit integer via LLVMGenericValueToInt(gv, true), it results >> in 360287970189639680 or something similar - not 5. Converting via >> LLVMGenericValueToInt(gv, false) didn't help either. >> >> How can I use global variables in a JIT situation? Is anything wrong with >> the IR? >> > > Okay, I already figured out that it has to do with the datalayout. How do I > set it correctly? I'm working on a linux x86_64 and I tried > LLVMSetDataLayout(mod, "x86_64-pc-linux") which crashes the program with > > LLVM ERROR: not a number, or does not fit in an unsigned int > > Using just LLVMSetDataLayout(mod, "e") solves it for now, would still like to > know what the correct setting is / why x86_64-pc-linux does not work."x86_64-pc-linux" is a Triple, not a Data Layout: http://llvm.org/docs/LangRef.html#data-layout. The name "Triple" here lies: http://llvm.org/docs/doxygen/html/group__LLVMCCoreModule.html#ga09bb21e82ee1df64fd387cd1498ceded Looks like a copy-pasta to me. Jon> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Jon Roelofs jonathan at codesourcery.com CodeSourcery / Mentor Embedded