[LLVMdev] How to insert a basic block in an edge

Nick Lewycky nicholas at mxc.ca
Sat Jul 17 09:46:08 PDT 2010

Chayan Sarkar wrote:
> Hi all,
> Suppose in a CFG bb1 has two succesor bb3 and bb4, and bb3 has two
> predecessor bb1 and bb2. Now how can I insert a basic block between
> bb1 and bb3 that at the edge bb1-->bb3 .
> In general how can I insert a basic block on an edge?

Use llvm::SplitEdge in Transforms/Utils/BasicBlockUtils.h.

The technique is to create a new bb with a single branch to bb3, then 
modify bb1's use of bb3 to point to 'new bb' instead, then fix up any 
phi nodes in bb3 by replacing uses of bb1 with 'new bb'.


More information about the llvm-dev mailing list