LLVM IR插入

时间:2014-10-31 17:47:17

标签: llvm

我试图通过代码

在我的基本块中插入一条非常简单的指令
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);

当我在一个非常小的文件上运行时,它给出了堆栈转储:

   While deleting: i32 %

在Def被销毁后仍然坚持使用:%twenty = add i32 10, 10

我对LLVM很新,所以如果这段代码毫无意义,我会接受任何建议。

1 个答案:

答案 0 :(得分:1)

LLVM指令构造函数和Create工厂接受Instruction插入后,或BasicBlock插入结尾。请勿使用getInstList执行此操作。

AllocaInst

Here are samples

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