llvm address of

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)

thanks for any suggestions

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,

Thanks Edwin,
I got it


My favourite way is to use http://llvm.org/demo/ , which compiles this

void another_fn(int*);

int fn(int x, int y)
   int z = x + y;
   return z;

into this

define i32 @fn(i32 %x, i32 %y) nounwind {
  %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*)