[LLVMdev] Preservance of function variables in the bytecode
Seung Jae Lee
lee225 at uiuc.edu
Fri Apr 27 10:05:55 PDT 2007
Thank you, Patrick.
What I want to do is just to write those source level variable names in my assembly code for a virtual machine because it is instructed in its instructions manual.
I registered the VM as a target for LLC and want to emit the assembly. For this reason, I asked how to get the variables themselves which are not mangled from the bytecode.
Thanks to your help, now I see they can be found in the LLVM assembly but still don't know how to use them in my assembly from the bytecode.
Can you help me to this point?
Thanks a lot.
Seung Jae Lee
---- Original message ----
>Date: Fri, 27 Apr 2007 11:29:25 -0500
>From: Patrick Meredith <pmeredit at uiuc.edu>
>Subject: Re: [LLVMdev] Preservance of function variables in the bytecode
>To: LLVM Developers Mailing List <llvmdev at cs.uiuc.edu>
>
>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
>
>_______________________________________________
>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