[llvm] r338950 - [ADCE] Remove the need of DomTree
Chijun Sima via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 3 19:50:12 PDT 2018
Author: sima
Date: Fri Aug 3 19:50:12 2018
New Revision: 338950
URL: http://llvm.org/viewvc/llvm-project?rev=338950&view=rev
Log:
[ADCE] Remove the need of DomTree
Summary: ADCE doesn't need to query domtree.
Reviewers: kuhar, brzycki, dmgreen, davide, grosser
Reviewed By: kuhar
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D49988
Modified:
llvm/trunk/lib/Transforms/Scalar/ADCE.cpp
llvm/trunk/test/Transforms/LoopRotate/pr35210.ll
Modified: llvm/trunk/lib/Transforms/Scalar/ADCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ADCE.cpp?rev=338950&r1=338949&r2=338950&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ADCE.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ADCE.cpp Fri Aug 3 19:50:12 2018
@@ -116,7 +116,7 @@ class AggressiveDeadCodeElimination {
// ADCE does not use DominatorTree per se, but it updates it to preserve the
// analysis.
- DominatorTree &DT;
+ DominatorTree *DT;
PostDominatorTree &PDT;
/// Mapping of blocks to associated information, an element in BlockInfoVec.
@@ -191,7 +191,7 @@ class AggressiveDeadCodeElimination {
void makeUnconditional(BasicBlock *BB, BasicBlock *Target);
public:
- AggressiveDeadCodeElimination(Function &F, DominatorTree &DT,
+ AggressiveDeadCodeElimination(Function &F, DominatorTree *DT,
PostDominatorTree &PDT)
: F(F), DT(DT), PDT(PDT) {}
@@ -615,7 +615,7 @@ void AggressiveDeadCodeElimination::upda
}
}
- DomTreeUpdater(DT, PDT, DomTreeUpdater::UpdateStrategy::Eager)
+ DomTreeUpdater(DT, &PDT, DomTreeUpdater::UpdateStrategy::Eager)
.applyUpdates(DeletedEdges);
NumBranchesRemoved += 1;
@@ -672,7 +672,9 @@ void AggressiveDeadCodeElimination::make
//
//===----------------------------------------------------------------------===//
PreservedAnalyses ADCEPass::run(Function &F, FunctionAnalysisManager &FAM) {
- auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
+ // ADCE does not need DominatorTree, but require DominatorTree here
+ // to update analysis if it is already available.
+ auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F);
auto &PDT = FAM.getResult<PostDominatorTreeAnalysis>(F);
if (!AggressiveDeadCodeElimination(F, DT, PDT).performDeadCodeElimination())
return PreservedAnalyses::all();
@@ -698,15 +700,16 @@ struct ADCELegacyPass : public FunctionP
if (skipFunction(F))
return false;
- auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ // ADCE does not need DominatorTree, but require DominatorTree here
+ // to update analysis if it is already available.
+ auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
+ auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
return AggressiveDeadCodeElimination(F, DT, PDT)
.performDeadCodeElimination();
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
- // We require DominatorTree here only to update and thus preserve it.
- AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<PostDominatorTreeWrapperPass>();
if (!RemoveControlFlowFlag)
AU.setPreservesCFG();
@@ -724,7 +727,6 @@ char ADCELegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(ADCELegacyPass, "adce",
"Aggressive Dead Code Elimination", false, false)
-INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
INITIALIZE_PASS_END(ADCELegacyPass, "adce", "Aggressive Dead Code Elimination",
false, false)
Modified: llvm/trunk/test/Transforms/LoopRotate/pr35210.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/pr35210.ll?rev=338950&r1=338949&r2=338950&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopRotate/pr35210.ll (original)
+++ llvm/trunk/test/Transforms/LoopRotate/pr35210.ll Fri Aug 3 19:50:12 2018
@@ -6,12 +6,12 @@
; CHECK: Starting llvm::Function pass manager run.
; CHECK-NEXT: Running pass: ADCEPass on f
-; CHECK-NEXT: Running analysis: DominatorTreeAnalysis on f
; CHECK-NEXT: Running analysis: PostDominatorTreeAnalysis on f
; CHECK-NEXT: Running pass: FunctionToLoopPassAdaptor{{.*}} on f
; CHECK-NEXT: Starting llvm::Function pass manager run.
; CHECK-NEXT: Running pass: LoopSimplifyPass on f
; CHECK-NEXT: Running analysis: LoopAnalysis on f
+; CHECK-NEXT: Running analysis: DominatorTreeAnalysis on f
; CHECK-NEXT: Running analysis: AssumptionAnalysis on f
; CHECK-NEXT: Running pass: LCSSAPass on f
; CHECK-NEXT: Finished llvm::Function pass manager run.
More information about the llvm-commits
mailing list