[LLVMdev] Splitting a basic block, replacing it's terminator
John McCall
rjmccall at apple.com
Fri May 8 16:10:34 PDT 2009
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.
More information about the llvm-dev
mailing list