[LLVMdev] alloca & store generation

Ryan M. Lefever lefever at crhc.uiuc.edu
Tue Mar 6 01:57:42 PST 2007


After looking at this problem longer, I believe that there is something 
wrong with the disassembler.  When I run my transformation and then 
disassemble the output, I get bytecode that looks like:

-----
int %main(int %argc, sbyte** %argv) {
entry:
         alloca int              ; <int*>:0 [#uses=3]
         alloca sbyte**          ; <sbyte***>:0 [#uses=3]
         store int %argc, int* %0
         store sbyte** %argv, sbyte*** %0
         call void %F( int* %0, sbyte*** %0, int 1, int 0 )
-----

However, if I use llc to generate C code from the bytecode that my 
transformation produces, it looks like:

-----
int main(int ltmp_75_3, signed char **ltmp_76_9) {
   int ltmp_3355_85;    /* Address-exposed local */
   signed char **ltmp_3356_105;    /* Address-exposed local */
   ...
   *(&ltmp_3355_85) = ltmp_75_3;
   *(&ltmp_3356_105) = ltmp_76_9;
   initLogging((&ltmp_3355_85), (&ltmp_3356_105), 1, 0);
-----

The C code is what I intended.  That leaves me to believe that my 
transformation produced the correct bytecode, but the dissassembler is 
not properly disassebling the bytecode.

Ryan


Ryan M. Lefever wrote:
> I am writing a transformation that needs to add a call to a function F() 
> at the beginning of main() with the addresses of argc and argv as 
> parameters to F().  However, the bytecode file I'm transforming has not 
> allocated space on the stack for argc and argv.  So, I developed my 
> transformation to change main() from:
> 
> -----
> int main(int %argc, sbyte** %argv){
> entry:
>    ...
>    // some use of %argc and %argv
>    ...
> }
> -----
> 
> to the following code:
> 
> -----
> int main(int %argc, sbyte** %argv){
> entry:
>    %argc_addr = alloca int
>    %argv_addr = alloca sbyte**
>    store int %argc, int* %argc_addr
>    store sbyte** %argv, sbyte*** %argv_addr
>    call void %F ( int %argc_addr, sbyte*** %argv_addr )
>    %tmp = load int* %argc_addr
>    %tmp1 = load int* %tmp
>    ...
>    // the use of %argc and %argv is transformed to use
>    // %tmp and %tmp1, respectively
>    ...
> }
> -----
> 
> However, after adding the alloca and stores, I print out main it looks like:
> 
> -----
> int %main(int %argc, sbyte** %argv) {
> entry:
>    alloca int              ; <int*>:0 [#uses=1]
>    alloca sbyte**          ; <sbyte***>:0 [#uses=1]
>    store int %argc, int* %0
>    store sbyte** %argv, sbyte*** %0
>    ...
> -----
> 
> I used the following code in my transformation:
> 
> -----
>    BasicBlock* eb = M.getMainFunction()->getEntryBlock();
>    Function::arg_iterator argc_it = mainfun->arg_begin();
>    Function::arg_iterator argv_it = argc_it;
>    ++argv_it;
>    Argument* argc = &*argc_it;
>    Argument* argv = &*argv_it;
>    Instruction* insertNewInstsBefore = &eb->front();
>    AllocaInst* argc_alloca = new AllocaInst(argc->getType(), "",
> 					   insertNewInstsBefore);
>    AllocaInst* argv_alloca = new AllocaInst(argv->getType(), "",
> 					   insertNewInstsBefore);
>    new StoreInst(argc, argc_alloca, false, insertNewInstsBefore);
>    new StoreInst(argv, argv_alloca, false, insertNewInstsBefore);
> -----
> 
> Why isn't llvm giving a name to the value returned by the allocas and 
> using it in the store instructions?
> 
> Regards,
> Ryan
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-- 
Ryan M. Lefever  [http://www.ews.uiuc.edu/~lefever]



More information about the llvm-dev mailing list