alloca & store generation

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:

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:

Why isn't llvm giving a name to the value returned by the allocas and
using it in the store instructions?

Because you pass in an empty string for the name in the new AllocaInst
calls below. Replace the empty strings with "argc_addr" or whatever
you want.

It seems as though, when the bytecode is disassebled, the result of the allocas should be given as a parameter to the stores. If the disassembler doesn't give the allocas a name, then that dependency is not conveyed.

Andreas Eriksson wrote:

Hello, Ryan.

It seems as though, when the bytecode is disassebled, the result of the
allocas should be given as a parameter to the stores.

It's given.

If the disassembler doesn't give the allocas a name, then that dependency is
not conveyed.

Both disassembly & bytecode is correct. Please carefully read LLVM
Language reference about %"num" names.

Ryan M. Lefever wrote:

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 )
  
I believe the above bytecode is correct. When an instruction is not
given a name, the compiler assigns it a numeric name. Names are unique
to type (for versions of LLVM <= 1.9), so your first two alloca
instructions are named %0 and could be re-written as follows:

%0 = alloca int
%0 = alloca sbyte **

Hence, the store and call instruction are using the alloca'ed pointers
as intended.

It would probably be nice if the disassembler listed those default
assigned names explicitly. There might be a good motivation for why it
doesn't, but if there is, I don't know the reason.

-- John T.

Thanks for the help. I apparently missed the part in the documentation about %"num" names.

Anton Korobeynikov wrote: