[LLVMdev] Preservance of function variables in the bytecode

Patrick Meredith pmeredit at uiuc.edu
Fri Apr 27 09:29:25 PDT 2007


This is what the llvm assembly looks like when I compile your example:

int %sum(int %i, int %j) {
entry:
         %i_addr = alloca int            ; <int*> [#uses=2]
         %j_addr = alloca int            ; <int*> [#uses=2]
         %retval = alloca int, align 4           ; <int*> [#uses=2]
         %tmp = alloca int, align 4              ; <int*> [#uses=2]
         %k = alloca int, align 4                ; <int*> [#uses=2]
         "alloca point" = cast int 0 to int              ; <int>  
[#uses=0]
         store int %i, int* %i_addr
         store int %j, int* %j_addr
         %tmp = load int* %i_addr                ; <int> [#uses=1]
         %tmp1 = load int* %j_addr               ; <int> [#uses=1]
         %tmp2 = add int %tmp, %tmp1             ; <int> [#uses=1]
         store int %tmp2, int* %k
         %tmp3 = load int* %k            ; <int> [#uses=1]
         store int %tmp3, int* %tmp
         %tmp4 = load int* %tmp          ; <int> [#uses=1]
         store int %tmp4, int* %retval
         br label %return

return:         ; preds = %entry
         %retval = load int* %retval             ; <int> [#uses=1]
         ret int %retval
}

You can see that the names i, j, and k are preserved... but this is  
an artifact
of whatever front-end you use (in this case llvm-gcc 4.0.1).  A front  
end is not
required to keep source level variable names, it is just a  
convenience.  This is actually
a little out of date, a more recent output would have i32 instead of  
int.

(Note the reason this looks so much longer than your C-backend code  
is that this has not
been optimized)

Why are you trying to recover variable names?

On Apr 27, 2007, at 10:44 AM, Seung Jae Lee wrote:

> Hello, LLVM-Dev guys.
> I just wonder if function variables are preserved in the bytecode.
>
> For example, are i and j in the following function preserved in .bc?
>
> int sum(int i, int j){
>     int k;
>     k = i + j;
>     return k;
> }
>
> I tested this with "llc -march=c" and found this was converted to
>
> int sum(int ltmp_0_1, int ltmp_1_1) {
>   return (ltmp_1_1 + ltmp_0_1);
> }
>
> Therefore, it seems that they are not preserved in the bytecode,  
> right?
> If it is not, (i.e., they are kept) how can I extract the variables  
> from the bytecode?
> I got really become to enjoy LLVM's magic.
> Thank you very much.
>
> Seung Jae Lee
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list