[llvm-dev] llvm pass
John Criswell via llvm-dev
llvm-dev at lists.llvm.org
Thu Dec 29 07:37:27 PST 2016
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));
Regards,
John Criswell
On 12/28/16 6:09 AM, Varun Patil via llvm-dev wrote:
> 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
> <http://llvm.org/docs/doxygen/html/AArch64PromoteConstant_8cpp.html#a90f8350fecae261c25be85d38b451bff>
> Twine <http://llvm.org/docs/doxygen/html/classllvm_1_1Twine.html> Name
> <http://llvm.org/docs/doxygen/html/SymbolizableObjectFile_8cpp.html#ab104eb44fb0574709f0ceb43b50bdb63>
> allocaI); //
> InsertBefore
> Presently I am passing previous allocaInstr Poiter as last argument as
> i shown above So New allocaInstr is inserting before previous
> allocaInstr in LLVM IR as follows output
>
> %p1 = alloca i32*, align 8 // New Alloca Instrctions
> %b = alloca i32, align 4 // previous Alloca Instrctions
>
> how can I get output like below
> %b = alloca i32, align 4 // previous Alloca Instrctions
> %p1 = alloca i32*, align 8 // New Alloca Instrctions
>
> Please help me to the needful Thank you
>
> Thanks and Regards
> Varun
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161229/95160147/attachment.html>
More information about the llvm-dev
mailing list