[LLVMdev] Question in LLVM IR

bhavani krishnan bhavi63 at yahoo.com
Sun Nov 30 19:38:15 PST 2008

Hi all,

I observed the nature of the LLVM IR and because of the SSA form, it does not preserve function local variable names (like it preserves function argument names). Is there any way to track these local variables?

Basically what I am doing is interpreting the IR against an abstract machien where I need to store the value of each program variable at any instance. Here I would get values for registers but how do I map them back to original program variables?

For eg: the sample program given below converts to the following IR: How do I track the variables x & y in this case? As you can see in the IR, x does not appear in any of the register names?
int foo(int a, int b)
        int x=0,y=0;

translates to 
        %tmp11 = add i32 %a.0, %b.0             
        %tmp12 = icmp sgt i32 %tmp11, 10     
        br i1 %tmp12, label %bb15, label %bb32
bb15:           ; preds = %entry
        %tmp29.pn38 = shl i32 %b.0, 1           
        %tmp18 = sub i32 %i, %a.0               
        %y.039 = add i32 %tmp18, %b.0        
        %tmp3540 = sub i32 %y.039, %tmp29.pn38          
        ret i32 %tmp3540
bb32:           ; preds = %entry
        %tmp25 = shl i32 %a.0, 1                
        %tmp29.pn = shl i32 %i, 1               
        %y.0 = shl i32 %b.0, 1          
        %tmp27 = sub i32 %y.0, %tmp29.pn                
        %tmp35 = add i32 %tmp27, %tmp25         
        ret i32 %tmp35

Please help me out here.....


More information about the llvm-dev mailing list