Skip to content

Commit a486f63

Browse files
author
git apple-llvm automerger
committed
Merge commit '881a57b99568' from llvm.org/main into next
2 parents 753953e + 881a57b commit a486f63

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,24 @@ 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) {
162-
// TODO: Have everything use a single lazy DTU
163-
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
160+
unfoldSelectInstrs(const SmallVector<SelectInstToUnfold, 4> &SelectInsts) {
164161
SmallVector<SelectInstToUnfold, 4> Stack(SelectInsts);
165162

166163
while (!Stack.empty()) {
167164
SelectInstToUnfold SIToUnfold = Stack.pop_back_val();
168165

169166
std::vector<SelectInstToUnfold> NewSIsToUnfold;
170167
std::vector<BasicBlock *> NewBBs;
171-
unfold(&DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);
168+
unfold(DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);
172169

173170
// Put newly discovered select instructions into the work list.
174171
llvm::append_range(Stack, NewSIsToUnfold);
@@ -181,7 +178,7 @@ class DFAJumpThreading {
181178
std::vector<BasicBlock *> *NewBBs);
182179

183180
AssumptionCache *AC;
184-
DominatorTree *DT;
181+
DomTreeUpdater *DTU;
185182
LoopInfo *LI;
186183
TargetTransformInfo *TTI;
187184
OptimizationRemarkEmitter *ORE;
@@ -869,11 +866,11 @@ struct AllSwitchPaths {
869866
};
870867

871868
struct TransformDFA {
872-
TransformDFA(AllSwitchPaths *SwitchPaths, DominatorTree *DT,
869+
TransformDFA(AllSwitchPaths *SwitchPaths, DomTreeUpdater *DTU,
873870
AssumptionCache *AC, TargetTransformInfo *TTI,
874871
OptimizationRemarkEmitter *ORE,
875872
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),
877874
EphValues(EphValues) {}
878875

879876
bool run() {
@@ -1049,19 +1046,16 @@ struct TransformDFA {
10491046
SmallPtrSet<BasicBlock *, 16> BlocksToClean;
10501047
BlocksToClean.insert_range(successors(SwitchBlock));
10511048

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++;
10631052
}
10641053

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+
10651059
// For each instruction that was cloned and used outside, update its uses
10661060
updateSSA(NewDefs);
10671061

@@ -1165,7 +1159,7 @@ struct TransformDFA {
11651159
}
11661160
// SSAUpdater handles phi placement and renaming uses with the appropriate
11671161
// value.
1168-
SSAUpdate.RewriteAllUses(DT);
1162+
SSAUpdate.RewriteAllUses(&DTU->getDomTree());
11691163
}
11701164

11711165
/// Clones a basic block, and adds it to the CFG.
@@ -1388,7 +1382,7 @@ struct TransformDFA {
13881382
}
13891383

13901384
AllSwitchPaths *SwitchPaths;
1391-
DominatorTree *DT;
1385+
DomTreeUpdater *DTU;
13921386
AssumptionCache *AC;
13931387
TargetTransformInfo *TTI;
13941388
OptimizationRemarkEmitter *ORE;
@@ -1431,7 +1425,7 @@ bool DFAJumpThreading::run(Function &F) {
14311425
<< "candidate for jump threading\n");
14321426
LLVM_DEBUG(SI->dump());
14331427

1434-
unfoldSelectInstrs(DT, Switch.getSelectInsts());
1428+
unfoldSelectInstrs(Switch.getSelectInsts());
14351429
if (!Switch.getSelectInsts().empty())
14361430
MadeChanges = true;
14371431

@@ -1453,21 +1447,23 @@ bool DFAJumpThreading::run(Function &F) {
14531447
}
14541448

14551449
#ifdef NDEBUG
1456-
LI->verify(*DT);
1450+
LI->verify(DTU->getDomTree());
14571451
#endif
14581452

14591453
SmallPtrSet<const Value *, 32> EphValues;
14601454
if (ThreadableLoops.size() > 0)
14611455
CodeMetrics::collectEphemeralValues(&F, AC, EphValues);
14621456

14631457
for (AllSwitchPaths SwitchPaths : ThreadableLoops) {
1464-
TransformDFA Transform(&SwitchPaths, DT, AC, TTI, ORE, EphValues);
1458+
TransformDFA Transform(&SwitchPaths, DTU, AC, TTI, ORE, EphValues);
14651459
if (Transform.run())
14661460
MadeChanges = LoopInfoBroken = true;
14671461
}
14681462

1463+
DTU->flush();
1464+
14691465
#ifdef EXPENSIVE_CHECKS
1470-
assert(DT->verify(DominatorTree::VerificationLevel::Full));
1466+
assert(DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full));
14711467
verifyFunction(F, &dbgs());
14721468
#endif
14731469

@@ -1482,7 +1478,9 @@ PreservedAnalyses DFAJumpThreadingPass::run(Function &F,
14821478
LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
14831479
TargetTransformInfo &TTI = AM.getResult<TargetIRAnalysis>(F);
14841480
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);
14861484
if (!ThreadImpl.run(F))
14871485
return PreservedAnalyses::all();
14881486

0 commit comments

Comments
 (0)