[LLVMdev] Instruction insertion By Module Pass

John Criswell criswell at illinois.edu
Thu Aug 1 06:55:47 PDT 2013


On 7/31/13 7:20 AM, Rasha Omar wrote:
> Thank you for your help
> I tried
>     Instruction* p=&( Bb->front());
>     Type * Int32Type = IntegerType::getInt32Ty(getGlobalContext());
>     AllocaInst* newInst = new AllocaInst(Int32Type,"flag", p);
> that works well
> but I need to store the value of the variable too.
> What's the method that could be used to store specific value??

Create a store instruction (StoreInst) that stores the desired value 
into the memory created by the alloca instruction.

-- John T.

>
>
>
>
> On 30 July 2013 16:01, John Criswell <criswell at illinois.edu 
> <mailto:criswell at illinois.edu>> wrote:
>
>     On 7/30/13 7:44 AM, Rasha Omar wrote:
>>     Hi,
>>     I need to insert new instruction into every basic block like x=1
>>     or while loop
>>     I tried this code, but it doesn't work
>>
>>     Type * Int32Type = IntegerType::getInt32Ty(getGlobalContext());
>>      AllocaInst* newInst = new AllocaInst(Int32Type,"flag", Bb);
>>      Bb->getInstList().push_back(newInst);
>
>     The problem is that you've inserted the AllocaInst into the basic
>     block via the AllocaInst constructor (note the Bb at the end of
>     the line with new AllocaInst).  You then attempt to insert the
>     AllocaInst into the BasicBlock Bb a second time with the last
>     line.  Note that the assertion is telling you that you're
>     inserting the alloca instruction twice.
>
>     Remove the last line, and it should fix your problem.
>
>     -- John T.
>
>>
>>     the error:
>>     void llvm::SymbolTableListTraits<llvm::Instruction,
>>     llvm::BasicBlock>::addNodeToList(ValueSubClass *) [ValueSubClass
>>     = llvm::Instruction, ItemParentClass = llvm::BasicBlock]:
>>     Assertion `V->getParent() == 0 && "Value already in a
>>     container!!"' failed.
>>
>>      Is there a class I could use to insert while loop in Module Pass?
>>
>>     Thank you in advance
>>
>>     -- 
>>     *Rasha Salah Omar
>>     Msc Student at E-JUST
>>     Demonestrator  at Faculty of Computers and Informatics
>>     Benha University*
>>
>>     *e-mail: rasha.omar at ejust.edu.eg <mailto:rasha.omar at ejust.edu.eg>*
>>
>>     P* Please consider the environment before printing this email.*
>>
>>
>>
>>     _______________________________________________
>>     LLVM Developers mailing list
>>     LLVMdev at cs.uiuc.edu  <mailto:LLVMdev at cs.uiuc.edu>          http://llvm.cs.uiuc.edu
>>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
>
> -- 
> *Rasha Salah Omar
> Msc Student at E-JUST
> Demonestrator  at Faculty of Computers and Informatics
> Benha University*
>
> *e-mail: rasha.omar at ejust.edu.eg <mailto:rasha.omar at ejust.edu.eg>*
>
> P* Please consider the environment before printing this email.*
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130801/625dad5e/attachment.html>


More information about the llvm-dev mailing list