[LLVMdev] llvm address of

me22 me22.ca at gmail.com
Sun May 24 13:37:34 PDT 2009


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*)




More information about the llvm-dev mailing list