Split a block and insert optional then/else blocks around the split point.
Synopsis
Declared in <llvm/Transforms/Utils/BasicBlockUtils.h>
void
SplitBlockAndInsertIfThenElse(
Value* Cond,
BasicBlock::iterator SplitBefore,
BasicBlock** ThenBlock,
BasicBlock** ElseBlock,
bool UnreachableThen = false,
bool UnreachableElse = false,
MDNode* BranchWeights = nullptr,
DomTreeUpdater* DTU = nullptr,
LoopInfo* LI = nullptr);
Description
Split the containing block at the specified instruction ‐ everything before SplitBefore stays in the old basic block, and the rest of the instructions in the BB are moved to a new block. The two blocks are connected by a conditional branch (with value of Cmp being the condition). Before: Head SplitBefore Tail After: Head if (Cond) TrueBlock else/ FalseBlock SplitBefore Tail
If ThenBlock is null, the resulting CFG won't contain the TrueBlock. If ThenBlock is non‐null and points to non‐null BasicBlock pointer, that block will be inserted as the TrueBlock. Otherwise a new block will be created. Likewise for the ElseBlock parameter. If UnreachableThen or UnreachableElse is true, the corresponding newly created blocks will end with UnreachableInst, otherwise with branches to Tail. The function will not modify existing basic blocks passed to it. The caller must ensure that Tail is reachable from Head. Returns the newly created blocks in ThenBlock and ElseBlock. Updates DTU and LI if given.
Parameters
Name |
Description |
Cond |
Condition controlling the inserted branch. |
SplitBefore |
Instruction at which the block is split. |
ThenBlock |
In/out then‐block pointer as described above. |
ElseBlock |
In/out else‐block pointer as described above. |
UnreachableThen |
Whether a newly created then‐block ends with unreachable. |
UnreachableElse |
Whether a newly created else‐block ends with unreachable. |
BranchWeights |
Optional branch‐weight metadata for the new branch. |
DTU |
Optional dominator‐tree updater for CFG changes. |
LI |
Optional loop info to update. |
Created with MrDocs