Skip to content

Commit 27db7af

Browse files
committed
[DFAJumpThreading] Use a single lazy DTU
1 parent 187a8e3 commit 27db7af

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,25 @@ class SelectInstToUnfold {
148148

149149
class DFAJumpThreading {
150150
public:
151-
DFAJumpThreading(AssumptionCache *AC, DominatorTree *DT, LoopInfo *LI,
151+
DFAJumpThreading(AssumptionCache *AC, DomTreeUpdater *DTU, LoopInfo *LI,
152152
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) {}
154154

155155
bool run(Function &F);
156156
bool LoopInfoBroken;
157157

158158
private:
159159
void
160-
unfoldSelectInstrs(DominatorTree *DT,
161-
const SmallVector<SelectInstToUnfold, 4> &SelectInsts) {
160+
unfoldSelectInstrs(const SmallVector<SelectInstToUnfold, 4> &SelectInsts) {
162161
// TODO: Have everything use a single lazy DTU
163-
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
164162
SmallVector<SelectInstToUnfold, 4> Stack(SelectInsts);
165163

166164
while (!Stack.empty()) {
167165
SelectInstToUnfold SIToUnfold = Stack.pop_back_val();
168166

169167
std::vector<SelectInstToUnfold> NewSIsToUnfold;
170168
std::vector<BasicBlock *> NewBBs;
171-
unfold(&DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);
169+
unfold(DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);
172170

173171
// Put newly discovered select instructions into the work list.
174172
llvm::append_range(Stack, NewSIsToUnfold);
@@ -181,7 +179,7 @@ class DFAJumpThreading {
181179
std::vector<BasicBlock *> *NewBBs);
182180

183181
AssumptionCache *AC;
184-
DominatorTree *DT;
182+
DomTreeUpdater *DTU;
185183
LoopInfo *LI;
186184
TargetTransformInfo *TTI;
187185
OptimizationRemarkEmitter *ORE;
@@ -869,11 +867,11 @@ struct AllSwitchPaths {
869867
};
870868

871869
struct TransformDFA {
872-
TransformDFA(AllSwitchPaths *SwitchPaths, DominatorTree *DT,
870+
TransformDFA(AllSwitchPaths *SwitchPaths, DomTreeUpdater *DTU,
873871
AssumptionCache *AC, TargetTransformInfo *TTI,
874872
OptimizationRemarkEmitter *ORE,
875873
SmallPtrSet<const Value *, 32> EphValues)
876-
: SwitchPaths(SwitchPaths), DT(DT), AC(AC), TTI(TTI), ORE(ORE),
874+
: SwitchPaths(SwitchPaths), DTU(DTU), AC(AC), TTI(TTI), ORE(ORE),
877875
EphValues(EphValues) {}
878876

879877
bool run() {
@@ -1049,19 +1047,16 @@ struct TransformDFA {
10491047
SmallPtrSet<BasicBlock *, 16> BlocksToClean;
10501048
BlocksToClean.insert_range(successors(SwitchBlock));
10511049

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);
1050+
for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
1051+
createExitPath(NewDefs, TPath, DuplicateMap, BlocksToClean, DTU);
1052+
NumPaths++;
10631053
}
10641054

1055+
// After all paths are cloned, now update the last successor of the cloned
1056+
// path so it skips over the switch statement
1057+
for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths())
1058+
updateLastSuccessor(TPath, DuplicateMap, DTU);
1059+
10651060
// For each instruction that was cloned and used outside, update its uses
10661061
updateSSA(NewDefs);
10671062

@@ -1165,7 +1160,7 @@ struct TransformDFA {
11651160
}
11661161
// SSAUpdater handles phi placement and renaming uses with the appropriate
11671162
// value.
1168-
SSAUpdate.RewriteAllUses(DT);
1163+
SSAUpdate.RewriteAllUses(&DTU->getDomTree());
11691164
}
11701165

11711166
/// Clones a basic block, and adds it to the CFG.
@@ -1388,7 +1383,7 @@ struct TransformDFA {
13881383
}
13891384

13901385
AllSwitchPaths *SwitchPaths;
1391-
DominatorTree *DT;
1386+
DomTreeUpdater *DTU;
13921387
AssumptionCache *AC;
13931388
TargetTransformInfo *TTI;
13941389
OptimizationRemarkEmitter *ORE;
@@ -1431,7 +1426,7 @@ bool DFAJumpThreading::run(Function &F) {
14311426
<< "candidate for jump threading\n");
14321427
LLVM_DEBUG(SI->dump());
14331428

1434-
unfoldSelectInstrs(DT, Switch.getSelectInsts());
1429+
unfoldSelectInstrs(Switch.getSelectInsts());
14351430
if (!Switch.getSelectInsts().empty())
14361431
MadeChanges = true;
14371432

@@ -1453,21 +1448,23 @@ bool DFAJumpThreading::run(Function &F) {
14531448
}
14541449

14551450
#ifdef NDEBUG
1456-
LI->verify(*DT);
1451+
LI->verify(DTU->getDomTree());
14571452
#endif
14581453

14591454
SmallPtrSet<const Value *, 32> EphValues;
14601455
if (ThreadableLoops.size() > 0)
14611456
CodeMetrics::collectEphemeralValues(&F, AC, EphValues);
14621457

14631458
for (AllSwitchPaths SwitchPaths : ThreadableLoops) {
1464-
TransformDFA Transform(&SwitchPaths, DT, AC, TTI, ORE, EphValues);
1459+
TransformDFA Transform(&SwitchPaths, DTU, AC, TTI, ORE, EphValues);
14651460
if (Transform.run())
14661461
MadeChanges = LoopInfoBroken = true;
14671462
}
14681463

1464+
DTU->flush();
1465+
14691466
#ifdef EXPENSIVE_CHECKS
1470-
assert(DT->verify(DominatorTree::VerificationLevel::Full));
1467+
assert(DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full));
14711468
verifyFunction(F, &dbgs());
14721469
#endif
14731470

@@ -1482,7 +1479,9 @@ PreservedAnalyses DFAJumpThreadingPass::run(Function &F,
14821479
LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
14831480
TargetTransformInfo &TTI = AM.getResult<TargetIRAnalysis>(F);
14841481
OptimizationRemarkEmitter ORE(&F);
1485-
DFAJumpThreading ThreadImpl(&AC, &DT, &LI, &TTI, &ORE);
1482+
1483+
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
1484+
DFAJumpThreading ThreadImpl(&AC, &DTU, &LI, &TTI, &ORE);
14861485
if (!ThreadImpl.run(F))
14871486
return PreservedAnalyses::all();
14881487

0 commit comments

Comments
 (0)