I'm trying to generate the equivalent of this function dynamically in llvm (a la http://llvm.org/docs/tutorial/JITTutorial1.html) but after half a day of searching I still haven't found how to create the equivalent of the & (address of) operator in the llvm API, more exactly how do I obtain the i8* from the i32 below void fn(int x) { another_fn(&x); } thanks for any suggestions Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090524/77da2175/attachment.html>
On 2009-05-24 19:42, Paul Martin wrote:> I'm trying to generate the equivalent of this function dynamically in > llvm (a la http://llvm.org/docs/tutorial/JITTutorial1.html) but after > half a day of searching I still haven't found how to create the > equivalent of the & (address of) operator in the llvm API, more > exactly how do I obtain the i8* from the i32 below > > void fn(int x) > { > another_fn(&x); > } >You should create a temporary variable on the stack, store the value of 'x' to it, and use the address of that variable as argument to another_fn. You can simply run your example on llvm-gcc/clang with -emit-llvm -S, and you'll see how it can be done. Best regards, --Edwin
Thanks Edwin, I got it Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090524/7d05f07a/attachment.html>
2009/5/24 Paul Martin <srucnoc at gmail.com>:> I'm trying to generate the equivalent of this function dynamically in llvm > (a la http://llvm.org/docs/tutorial/JITTutorial1.html) but after half a day > of searching I still haven't found how to create the equivalent of the & > (address of) operator in the llvm API, more exactly how do I obtain the i8* > from the i32 below > > void fn(int x) > { > another_fn(&x); > } >My favourite way is to use http://llvm.org/demo/ , which compiles this void another_fn(int*); int fn(int x, int y) { another_fn(&x); int z = x + y; return z; } into this define i32 @fn(i32 %x, i32 %y) nounwind { entry: %x_addr = alloca i32, align 4 ; <i32*> [#uses=3] store i32 %x, i32* %x_addr call void @another_fn(i32* %x_addr) nounwind %0 = load i32* %x_addr, align 4 ; <i32> [#uses=1] %1 = add i32 %0, %y ; <i32> [#uses=1] ret i32 %1 } declare void @another_fn(i32*)