Jajoo, Malhar via llvm-dev
2017-Jun-12 15:59 UTC
[llvm-dev] deleting a range of instructions
Hi, I am trying to delete a range of instructions ( specified as between [startIns , endIns) ) . the endIns may not be in the same basic block as the start. I keep getting the following error when trying to delete the last instruction in - reference llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>::operator*() const [OptionsT = llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, IsReverse = false, IsConst = false]: Assertion `!NodePtr->isKnownSentinel()' failed. Following is my C++ code - // delete all instructions between [start,end) void deleteAllInstructionsInRange(Instruction* startInst,Instruction* endInst) { BasicBlock::iterator it(startInst); BasicBlock::iterator it_end(endInst); Instruction* currentInst ; Instruction* lastInst ; while(it != it_end) { currentInst = &*it; ++it; if (!currentInst->use_empty()) { currentInst->replaceAllUsesWith(UndefValue::get(currentInst->getType())); } currentInst->eraseFromParent(); } } Following is my IR - define i32 @test2() { entry: %calltmp = call i32 @UInt() %datasize = alloca i32 switch i32 %calltmp, label %sw.bb.0 [ i32 1, label %sw.bb.1 i32 2, label %sw.bb.2 i32 3, label %sw.bb.3 ] ; %res = alloca i8 ------> deleted this ; store i8 0, i8* %res ------> deleted this ;%datasize1 = load i32, i32* %datasize ------> deleted this ;ret i32 %datasize1 ------> deleted this ret i32 undef ------> Unable to delete this sw.bb.0: ; preds = %entry %resclone0 = alloca i10 store i10 0, i10* %resclone0 %datasize1clone0 = load i32, i32* %datasize ret i32 %datasize1clone0 Any help will be appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170612/2514e75d/attachment.html>