techcomp
techcomp

Reputation: 400

LLVM IR insertion

i am trying to insert a very simple instruction into my basic block by the code

Value *ten=ConstantInt::get(Type::getInt32Ty(con),10,true);
Instruction *newinst=new AllocaInst(Type::getInt32Ty(con),ten,"jst");
b->getInstList().push_back(newinst);
Instruction *add=BinaryOperator::Create(Instruction :: Add,ten,ten,"twenty");
b->getInstList().push_back(add);

it giving stack dump while i am running it on a very small file:

   While deleting: i32 %

use still stuck around after Def is Destroyed : %twenty = add i32 10, 10

I'm rather new to LLVM, so I'll take any advice if this code makes no sense.

Upvotes: 0

Views: 273

Answers (1)

Eli Bendersky
Eli Bendersky

Reputation: 273716

LLVM instruction constructors and Create factories accept either an Instruction to insert after, or a BasicBlock to insert at the end of. Do not use getInstList to do this.

Here are samples for AllocaInst:

AllocaInst (Type *Ty, Value *ArraySize=nullptr,
            const Twine &Name="", Instruction *InsertBefore=nullptr)
AllocaInst (Type *Ty, Value *ArraySize,
            const Twine &Name, BasicBlock *InsertAtEnd)

Upvotes: 1

Related Questions