[LLVMdev] Splitting a basic block, replacing it's terminator

Nick Johnson nicholas.paul.johnson at gmail.com
Fri May 8 16:19:29 PDT 2009


Thanks John.

The problem was that I used bb->getTerminator()->removeFromParent(),
but I should have used bb->getTerminator()->eraseFromParent().

Nick


On Fri, May 8, 2009 at 7:10 PM, John McCall <rjmccall at apple.com> wrote:
> On May 8, 2009, at 4:02 PM, Nick Johnson wrote:
>> I want to insert a conditional branch in the middle of a basic block.
>> To that end, I am doing these steps:
>>
>> (1) Split the basic block:
>> bb->splitBasicBlock()
>>
>> (2) Remove the old terminator:
>> succ->removePredecessor(bb)
>> bb->getTerminator()->getParent()
>
> Assuming that the new block will still be a successor of the old block
> (just not the unique successor), all you really need to do is:
>
>   BasicBlock* succ = bb->splitBasicBlock();
>   bb->getTerminator()->eraseFromParent();
>   BranchInst::Create(<ifTrue>, <ifFalse>, <cond>, bb);
>
> John.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



-- 
Nick Johnson



More information about the llvm-dev mailing list