Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,24 @@ class SelectInstToUnfold {

class DFAJumpThreading {
public:
DFAJumpThreading(AssumptionCache *AC, DominatorTree *DT, LoopInfo *LI,
DFAJumpThreading(AssumptionCache *AC, DomTreeUpdater *DTU, LoopInfo *LI,
TargetTransformInfo *TTI, OptimizationRemarkEmitter *ORE)
: AC(AC), DT(DT), LI(LI), TTI(TTI), ORE(ORE) {}
: AC(AC), DTU(DTU), LI(LI), TTI(TTI), ORE(ORE) {}

bool run(Function &F);
bool LoopInfoBroken;

private:
void
unfoldSelectInstrs(DominatorTree *DT,
const SmallVector<SelectInstToUnfold, 4> &SelectInsts) {
// TODO: Have everything use a single lazy DTU
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
unfoldSelectInstrs(const SmallVector<SelectInstToUnfold, 4> &SelectInsts) {
SmallVector<SelectInstToUnfold, 4> Stack(SelectInsts);

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

std::vector<SelectInstToUnfold> NewSIsToUnfold;
std::vector<BasicBlock *> NewBBs;
unfold(&DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);
unfold(DTU, LI, SIToUnfold, &NewSIsToUnfold, &NewBBs);

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

AssumptionCache *AC;
DominatorTree *DT;
DomTreeUpdater *DTU;
LoopInfo *LI;
TargetTransformInfo *TTI;
OptimizationRemarkEmitter *ORE;
Expand Down Expand Up @@ -869,11 +866,11 @@ struct AllSwitchPaths {
};

struct TransformDFA {
TransformDFA(AllSwitchPaths *SwitchPaths, DominatorTree *DT,
TransformDFA(AllSwitchPaths *SwitchPaths, DomTreeUpdater *DTU,
AssumptionCache *AC, TargetTransformInfo *TTI,
OptimizationRemarkEmitter *ORE,
SmallPtrSet<const Value *, 32> EphValues)
: SwitchPaths(SwitchPaths), DT(DT), AC(AC), TTI(TTI), ORE(ORE),
: SwitchPaths(SwitchPaths), DTU(DTU), AC(AC), TTI(TTI), ORE(ORE),
EphValues(EphValues) {}

bool run() {
Expand Down Expand Up @@ -1049,19 +1046,16 @@ struct TransformDFA {
SmallPtrSet<BasicBlock *, 16> BlocksToClean;
BlocksToClean.insert_range(successors(SwitchBlock));

{
DomTreeUpdater DTU(*DT, DomTreeUpdater::UpdateStrategy::Lazy);
for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
createExitPath(NewDefs, TPath, DuplicateMap, BlocksToClean, &DTU);
NumPaths++;
}

// After all paths are cloned, now update the last successor of the cloned
// path so it skips over the switch statement
for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths())
updateLastSuccessor(TPath, DuplicateMap, &DTU);
for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
createExitPath(NewDefs, TPath, DuplicateMap, BlocksToClean, DTU);
NumPaths++;
}

// After all paths are cloned, now update the last successor of the cloned
// path so it skips over the switch statement
for (const ThreadingPath &TPath : SwitchPaths->getThreadingPaths())
updateLastSuccessor(TPath, DuplicateMap, DTU);

// For each instruction that was cloned and used outside, update its uses
updateSSA(NewDefs);

Expand Down Expand Up @@ -1165,7 +1159,7 @@ struct TransformDFA {
}
// SSAUpdater handles phi placement and renaming uses with the appropriate
// value.
SSAUpdate.RewriteAllUses(DT);
SSAUpdate.RewriteAllUses(&DTU->getDomTree());
}

/// Clones a basic block, and adds it to the CFG.
Expand Down Expand Up @@ -1388,7 +1382,7 @@ struct TransformDFA {
}

AllSwitchPaths *SwitchPaths;
DominatorTree *DT;
DomTreeUpdater *DTU;
AssumptionCache *AC;
TargetTransformInfo *TTI;
OptimizationRemarkEmitter *ORE;
Expand Down Expand Up @@ -1431,7 +1425,7 @@ bool DFAJumpThreading::run(Function &F) {
<< "candidate for jump threading\n");
LLVM_DEBUG(SI->dump());

unfoldSelectInstrs(DT, Switch.getSelectInsts());
unfoldSelectInstrs(Switch.getSelectInsts());
if (!Switch.getSelectInsts().empty())
MadeChanges = true;

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

#ifdef NDEBUG
LI->verify(*DT);
LI->verify(DTU->getDomTree());
#endif

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

for (AllSwitchPaths SwitchPaths : ThreadableLoops) {
TransformDFA Transform(&SwitchPaths, DT, AC, TTI, ORE, EphValues);
TransformDFA Transform(&SwitchPaths, DTU, AC, TTI, ORE, EphValues);
if (Transform.run())
MadeChanges = LoopInfoBroken = true;
}

DTU->flush();

#ifdef EXPENSIVE_CHECKS
assert(DT->verify(DominatorTree::VerificationLevel::Full));
assert(DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full));
verifyFunction(F, &dbgs());
#endif

Expand All @@ -1482,7 +1478,9 @@ PreservedAnalyses DFAJumpThreadingPass::run(Function &F,
LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
TargetTransformInfo &TTI = AM.getResult<TargetIRAnalysis>(F);
OptimizationRemarkEmitter ORE(&F);
DFAJumpThreading ThreadImpl(&AC, &DT, &LI, &TTI, &ORE);

DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
DFAJumpThreading ThreadImpl(&AC, &DTU, &LI, &TTI, &ORE);
if (!ThreadImpl.run(F))
return PreservedAnalyses::all();

Expand Down
Loading