Question in LLVM IR

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;
        if(a+b>10){
         x=b-a;
         y=i-2*b;
        }else{
         x=2*a+b;
         y=b-2*i;
        }
        return(x+y);
}

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.....
Thanks,
Bhavani

Basically, the loads/stores are getting killed by optimization;
there's no real way to guarantee that the values are ever even
calculated. You could use debug information in theory, but LLVM
doesn't properly support optimization with debug info at the moment.
Another way would be to use clang, and add some sort of
instrumentation to every store; this would keep the values, but
interfere with optimizations. The other approach is to just disable
optimizations; then you can track the variables quite easily, but
you're not really instrumenting the same program. Overall, there
really isn't a good solution to what you're trying to do.

-Eli

Thanks! How do I disable the optimizations??

Bhavani

llvm-gcc -O0? How are you generating your code?

-Eli