llvm pass

I want to insert new alloca Instruction after existing alloca Instruction in llvm pass so what attribute to be passed at last in following
newallocaI = new AllocaInst(llvm::Type::getInt32PtrTy(context,0), //type
0, // ArraySize

8, // Alignment

“p”, // const Twine Name
allocaI); // InsertBefore

Dear Varun,

First, the order of the allocas is likely not important. Due to the way LLVM IR works, the ordering doesn't matter. I typically only need to insert instructions in a particular order for cosmetic reasons (e.g., making the LLVM IR easier to read for debugging).

That said, if you want your new alloca to appear after an original alloca, you should create a BasicBlock::iterator with the original alloca as an argument. You then advance this iterator by 1 element and assign it to an Instruction *. This instruction is the one following the alloca and is the argument you want to use for the insertion point. I think the following is what you would want:

AllocaInst * AI = .... ;
Instruction *InsertionPoint = ++(BasicBlock::iterator(AI));


John Criswell