Skip to content

Commit c8e4d2b

Browse files
committed
SILGen KeyPath: Create a basic block to split the critical edge.
This is the one place in SILGen where we need to explicitly split the critical edge. createBasicBlockAndBranch is a simply utility for that.
1 parent 1c701b2 commit c8e4d2b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3346,9 +3346,11 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
33463346
C.getBoolDecl()->getStoredProperties().front(), i1Ty);
33473347

33483348
auto isTrueBB = subSGF.createBasicBlock();
3349-
3350-
subSGF.B.createCondBranch(loc, isEqualI1, isTrueBB, isFalseBB);
3351-
3349+
// Each false condition needs its own block to avoid critical edges.
3350+
auto falseEdgeBB = subSGF.createBasicBlockAndBranch(loc, isFalseBB);
3351+
3352+
subSGF.B.createCondBranch(loc, isEqualI1, isTrueBB, falseEdgeBB);
3353+
33523354
subSGF.B.emitBlock(isTrueBB);
33533355
}
33543356

lib/SILGen/SILGenStmt.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ SILBasicBlock *SILGenFunction::createBasicBlock(FunctionSection section) {
7979
llvm_unreachable("bad function section");
8080
}
8181

82+
SILBasicBlock *
83+
SILGenFunction::createBasicBlockAndBranch(SILLocation loc,
84+
SILBasicBlock *destBB) {
85+
auto *newBB = createBasicBlock();
86+
SILGenBuilder(B, newBB).createBranch(loc, destBB);
87+
return newBB;
88+
}
89+
8290
void SILGenFunction::eraseBasicBlock(SILBasicBlock *block) {
8391
assert(block->pred_empty() && "erasing block with predecessors");
8492
assert(block->empty() && "erasing block with content");

0 commit comments

Comments
 (0)