@@ -148,27 +148,24 @@ class SelectInstToUnfold {
148
148
149
149
class DFAJumpThreading {
150
150
public:
151
- DFAJumpThreading (AssumptionCache *AC, DominatorTree *DT , LoopInfo *LI,
151
+ DFAJumpThreading (AssumptionCache *AC, DomTreeUpdater *DTU , LoopInfo *LI,
152
152
TargetTransformInfo *TTI, OptimizationRemarkEmitter *ORE)
153
- : AC(AC), DT(DT ), LI(LI), TTI(TTI), ORE(ORE) {}
153
+ : AC(AC), DTU(DTU ), LI(LI), TTI(TTI), ORE(ORE) {}
154
154
155
155
bool run (Function &F);
156
156
bool LoopInfoBroken;
157
157
158
158
private:
159
159
void
160
- unfoldSelectInstrs (DominatorTree *DT,
161
- const SmallVector<SelectInstToUnfold, 4 > &SelectInsts) {
162
- // TODO: Have everything use a single lazy DTU
163
- DomTreeUpdater DTU (DT, DomTreeUpdater::UpdateStrategy::Lazy);
160
+ unfoldSelectInstrs (const SmallVector<SelectInstToUnfold, 4 > &SelectInsts) {
164
161
SmallVector<SelectInstToUnfold, 4 > Stack (SelectInsts);
165
162
166
163
while (!Stack.empty ()) {
167
164
SelectInstToUnfold SIToUnfold = Stack.pop_back_val ();
168
165
169
166
std::vector<SelectInstToUnfold> NewSIsToUnfold;
170
167
std::vector<BasicBlock *> NewBBs;
171
- unfold (& DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);
168
+ unfold (DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);
172
169
173
170
// Put newly discovered select instructions into the work list.
174
171
llvm::append_range (Stack, NewSIsToUnfold);
@@ -181,7 +178,7 @@ class DFAJumpThreading {
181
178
std::vector<BasicBlock *> *NewBBs);
182
179
183
180
AssumptionCache *AC;
184
- DominatorTree *DT ;
181
+ DomTreeUpdater *DTU ;
185
182
LoopInfo *LI;
186
183
TargetTransformInfo *TTI;
187
184
OptimizationRemarkEmitter *ORE;
@@ -869,11 +866,11 @@ struct AllSwitchPaths {
869
866
};
870
867
871
868
struct TransformDFA {
872
- TransformDFA (AllSwitchPaths *SwitchPaths, DominatorTree *DT ,
869
+ TransformDFA (AllSwitchPaths *SwitchPaths, DomTreeUpdater *DTU ,
873
870
AssumptionCache *AC, TargetTransformInfo *TTI,
874
871
OptimizationRemarkEmitter *ORE,
875
872
SmallPtrSet<const Value *, 32 > EphValues)
876
- : SwitchPaths(SwitchPaths), DT(DT ), AC(AC), TTI(TTI), ORE(ORE),
873
+ : SwitchPaths(SwitchPaths), DTU(DTU ), AC(AC), TTI(TTI), ORE(ORE),
877
874
EphValues (EphValues) {}
878
875
879
876
bool run () {
@@ -1049,19 +1046,16 @@ struct TransformDFA {
1049
1046
SmallPtrSet<BasicBlock *, 16 > BlocksToClean;
1050
1047
BlocksToClean.insert_range (successors (SwitchBlock));
1051
1048
1052
- {
1053
- DomTreeUpdater DTU (*DT, DomTreeUpdater::UpdateStrategy::Lazy);
1054
- for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths ()) {
1055
- createExitPath (NewDefs, TPath, DuplicateMap, BlocksToClean, &DTU);
1056
- NumPaths++;
1057
- }
1058
-
1059
- // After all paths are cloned, now update the last successor of the cloned
1060
- // path so it skips over the switch statement
1061
- for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths ())
1062
- updateLastSuccessor (TPath, DuplicateMap, &DTU);
1049
+ for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths ()) {
1050
+ createExitPath (NewDefs, TPath, DuplicateMap, BlocksToClean, DTU);
1051
+ NumPaths++;
1063
1052
}
1064
1053
1054
+ // After all paths are cloned, now update the last successor of the cloned
1055
+ // path so it skips over the switch statement
1056
+ for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths ())
1057
+ updateLastSuccessor (TPath, DuplicateMap, DTU);
1058
+
1065
1059
// For each instruction that was cloned and used outside, update its uses
1066
1060
updateSSA (NewDefs);
1067
1061
@@ -1165,7 +1159,7 @@ struct TransformDFA {
1165
1159
}
1166
1160
// SSAUpdater handles phi placement and renaming uses with the appropriate
1167
1161
// value.
1168
- SSAUpdate.RewriteAllUses (DT );
1162
+ SSAUpdate.RewriteAllUses (&DTU-> getDomTree () );
1169
1163
}
1170
1164
1171
1165
// / Clones a basic block, and adds it to the CFG.
@@ -1388,7 +1382,7 @@ struct TransformDFA {
1388
1382
}
1389
1383
1390
1384
AllSwitchPaths *SwitchPaths;
1391
- DominatorTree *DT ;
1385
+ DomTreeUpdater *DTU ;
1392
1386
AssumptionCache *AC;
1393
1387
TargetTransformInfo *TTI;
1394
1388
OptimizationRemarkEmitter *ORE;
@@ -1431,7 +1425,7 @@ bool DFAJumpThreading::run(Function &F) {
1431
1425
<< " candidate for jump threading\n " );
1432
1426
LLVM_DEBUG (SI->dump ());
1433
1427
1434
- unfoldSelectInstrs (DT, Switch.getSelectInsts ());
1428
+ unfoldSelectInstrs (Switch.getSelectInsts ());
1435
1429
if (!Switch.getSelectInsts ().empty ())
1436
1430
MadeChanges = true ;
1437
1431
@@ -1453,21 +1447,23 @@ bool DFAJumpThreading::run(Function &F) {
1453
1447
}
1454
1448
1455
1449
#ifdef NDEBUG
1456
- LI->verify (*DT );
1450
+ LI->verify (DTU-> getDomTree () );
1457
1451
#endif
1458
1452
1459
1453
SmallPtrSet<const Value *, 32 > EphValues;
1460
1454
if (ThreadableLoops.size () > 0 )
1461
1455
CodeMetrics::collectEphemeralValues (&F, AC, EphValues);
1462
1456
1463
1457
for (AllSwitchPaths SwitchPaths : ThreadableLoops) {
1464
- TransformDFA Transform (&SwitchPaths, DT , AC, TTI, ORE, EphValues);
1458
+ TransformDFA Transform (&SwitchPaths, DTU , AC, TTI, ORE, EphValues);
1465
1459
if (Transform.run ())
1466
1460
MadeChanges = LoopInfoBroken = true ;
1467
1461
}
1468
1462
1463
+ DTU->flush ();
1464
+
1469
1465
#ifdef EXPENSIVE_CHECKS
1470
- assert (DT-> verify (DominatorTree::VerificationLevel::Full));
1466
+ assert (DTU-> getDomTree (). verify (DominatorTree::VerificationLevel::Full));
1471
1467
verifyFunction (F, &dbgs ());
1472
1468
#endif
1473
1469
@@ -1482,7 +1478,9 @@ PreservedAnalyses DFAJumpThreadingPass::run(Function &F,
1482
1478
LoopInfo &LI = AM.getResult <LoopAnalysis>(F);
1483
1479
TargetTransformInfo &TTI = AM.getResult <TargetIRAnalysis>(F);
1484
1480
OptimizationRemarkEmitter ORE (&F);
1485
- DFAJumpThreading ThreadImpl (&AC, &DT, &LI, &TTI, &ORE);
1481
+
1482
+ DomTreeUpdater DTU (DT, DomTreeUpdater::UpdateStrategy::Lazy);
1483
+ DFAJumpThreading ThreadImpl (&AC, &DTU, &LI, &TTI, &ORE);
1486
1484
if (!ThreadImpl.run (F))
1487
1485
return PreservedAnalyses::all ();
1488
1486
0 commit comments