Skip to content

Commit 871518c

Browse files
committed
SimplifyCFG; add jump-threading successors to the worklist.
This is required for SimplifyCFG to iterate over simplified blocks when it does critical edge splitting.
1 parent 7d88d72 commit 871518c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ namespace {
180180
bool tryJumpThreading(BranchInst *BI);
181181
bool tailDuplicateObjCMethodCallSuccessorBlocks();
182182
bool simplifyAfterDroppingPredecessor(SILBasicBlock *BB);
183+
bool addToWorklistAfterSplittingEdges(SILBasicBlock *BB);
183184

184185
bool simplifyBranchOperands(OperandValueArrayRef Operands);
185186
bool simplifyBranchBlock(BranchInst *BI);
@@ -715,6 +716,18 @@ bool SimplifyCFG::simplifyAfterDroppingPredecessor(SILBasicBlock *BB) {
715716
return false;
716717
}
717718

719+
/// This is called after \p BB has been cloned during jump-threading
720+
/// (tail-duplication) and the new critical edge on its successor has been
721+
/// split. This is necessary to continue jump-threading through the split
722+
/// critical edge (since we only jump-thread one block at a time).
723+
bool SimplifyCFG::addToWorklistAfterSplittingEdges(SILBasicBlock *BB) {
724+
addToWorklist(BB);
725+
for (auto *succBB : BB->getSuccessorBlocks()) {
726+
addToWorklist(succBB);
727+
}
728+
return false;
729+
}
730+
718731
static NullablePtr<EnumElementDecl>
719732
getEnumCaseRecursive(SILValue Val, SILBasicBlock *UsedInBB, int RecursionDepth,
720733
llvm::SmallPtrSetImpl<SILArgument *> &HandledArgs) {
@@ -1075,7 +1088,10 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
10751088
// the threaded and edge block to the worklist now that they (likely) can be
10761089
// simplified.
10771090
addToWorklist(SrcBB);
1078-
addToWorklist(Cloner.getNewBB());
1091+
1092+
// Simplify the cloned block and continue jump-threading through its new
1093+
// successors edges.
1094+
addToWorklistAfterSplittingEdges(Cloner.getNewBB());
10791095

10801096
// We may be able to simplify DestBB now that it has one fewer predecessor.
10811097
simplifyAfterDroppingPredecessor(DestBB);
@@ -2816,7 +2832,9 @@ bool SimplifyCFG::tailDuplicateObjCMethodCallSuccessorBlocks() {
28162832
Cloner.updateSSAAfterCloning();
28172833

28182834
Changed = true;
2819-
addToWorklist(Cloner.getNewBB());
2835+
// Simplify the cloned block and continue tail duplicating through its new
2836+
// successors edges.
2837+
addToWorklistAfterSplittingEdges(Cloner.getNewBB());
28202838
}
28212839
return Changed;
28222840
}

0 commit comments

Comments
 (0)