@@ -170,7 +170,6 @@ namespace {
170
170
bool simplifyProgramTerminationBlock (SILBasicBlock *BB);
171
171
bool simplifyArgument (SILBasicBlock *BB, unsigned i);
172
172
bool simplifyArgs (SILBasicBlock *BB);
173
- bool trySimplifyCheckedCastBr (TermInst *Term, DominanceInfo *DT);
174
173
void findLoopHeaders ();
175
174
};
176
175
@@ -239,28 +238,6 @@ void swift::updateSSAAfterCloning(BaseThreadingCloner &Cloner,
239
238
}
240
239
}
241
240
242
- // / Perform a dominator-based jump-threading for checked_cast_br [exact]
243
- // / instructions if they use the same condition (modulo upcasts and downcasts).
244
- // / This is very beneficial for code that:
245
- // / - references the same object multiple times (e.g. x.f1() + x.f2())
246
- // / - and for method invocation chaining (e.g. x.f3().f4().f5())
247
- bool
248
- SimplifyCFG::trySimplifyCheckedCastBr (TermInst *Term, DominanceInfo *DT) {
249
- // Ignore unreachable blocks.
250
- if (!DT->getNode (Term->getParent ()))
251
- return false ;
252
-
253
- SmallVector<SILBasicBlock *, 16 > BBs;
254
- auto Result = tryCheckedCastBrJumpThreading (Term, DT, BBs);
255
-
256
- if (Result) {
257
- for (auto BB: BBs)
258
- addToWorklist (BB);
259
- }
260
-
261
- return Result;
262
- }
263
-
264
241
static SILValue getTerminatorCondition (TermInst *Term) {
265
242
if (auto *CondBr = dyn_cast<CondBranchInst>(Term))
266
243
return stripExpectIntrinsic (CondBr->getCondition ());
@@ -670,6 +647,7 @@ bool SimplifyCFG::dominatorBasedSimplify(DominanceAnalysis *DA) {
670
647
EnableJumpThread ? splitAllCriticalEdges (Fn, false , DT, nullptr ) : false ;
671
648
672
649
unsigned MaxIter = MaxIterationsOfDominatorBasedSimplify;
650
+ SmallVector<SILBasicBlock *, 16 > BlocksForWorklist;
673
651
674
652
bool HasChangedInCurrentIter;
675
653
do {
@@ -678,26 +656,14 @@ bool SimplifyCFG::dominatorBasedSimplify(DominanceAnalysis *DA) {
678
656
// Do dominator based simplification of terminator condition. This does not
679
657
// and MUST NOT change the CFG without updating the dominator tree to
680
658
// reflect such change.
681
- for (auto &BB : Fn) {
682
- // Any method called from this loop should update
683
- // the DT if it changes anything related to dominators.
684
- TermInst *Term = BB.getTerminator ();
685
- switch (Term->getKind ()) {
686
- case ValueKind::SwitchValueInst:
687
- // TODO: handle switch_value
688
- break ;
689
- case ValueKind::CheckedCastBranchInst:
690
- if (trySimplifyCheckedCastBr (BB.getTerminator (), DT)) {
691
- HasChangedInCurrentIter = true ;
692
- // FIXME: trySimplifyCheckedCastBr function should preserve the
693
- // dominator tree but its code to do so is buggy.
694
- DT->recalculate (Fn);
695
- }
696
- break ;
697
- default :
698
- break ;
699
- }
659
+ if (tryCheckedCastBrJumpThreading (&Fn, DT, BlocksForWorklist)) {
660
+ for (auto BB: BlocksForWorklist)
661
+ addToWorklist (BB);
662
+
663
+ HasChangedInCurrentIter = true ;
664
+ DT->recalculate (Fn);
700
665
}
666
+ BlocksForWorklist.clear ();
701
667
702
668
if (ShouldVerify)
703
669
DT->verify ();
0 commit comments