[LLVMdev] alloca & store generation
Ryan M. Lefever
lefever at crhc.uiuc.edu
Mon Mar 5 23:24:20 PST 2007
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
More information about the llvm-dev
mailing list