diff options
author | Evgeniy Brevnov <evgueni.brevnov@gmail.com> | 2020-04-28 16:31:20 +0700 |
---|---|---|
committer | Evgeniy Brevnov <evgueni.brevnov@gmail.com> | 2020-04-30 11:31:03 +0700 |
commit | 3e68a667047d1541e445c8f47501d69f5b1a497d (patch) | |
tree | f0673f97733b16d3b9bf85ea598b33fe2b7615b2 /llvm/lib/Analysis/BranchProbabilityInfo.cpp | |
parent | fbdcfcd4c392c487c411632b951f4aada351154e (diff) | |
download | llvm-3e68a667047d1541e445c8f47501d69f5b1a497d.zip llvm-3e68a667047d1541e445c8f47501d69f5b1a497d.tar.gz llvm-3e68a667047d1541e445c8f47501d69f5b1a497d.tar.bz2 |
[BPI][NFC] Reuse post dominantor tree from analysis manager when available
Summary: Currenlty BPI unconditionally creates post dominator tree each time. While this is not incorrect we can save compile time by reusing existing post dominator tree (when it's valid) provided by analysis manager.
Reviewers: skatkov, taewookoh, yrouban
Reviewed By: skatkov
Subscribers: hiraditya, steven_wu, dexonsmith, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78987
Diffstat (limited to 'llvm/lib/Analysis/BranchProbabilityInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/BranchProbabilityInfo.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp index ae99d63..99f253c 100644 --- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp +++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp @@ -61,6 +61,7 @@ INITIALIZE_PASS_BEGIN(BranchProbabilityInfoWrapperPass, "branch-prob", "Branch Probability Analysis", false, true) INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_END(BranchProbabilityInfoWrapperPass, "branch-prob", "Branch Probability Analysis", false, true) @@ -980,7 +981,8 @@ void BranchProbabilityInfo::eraseBlock(const BasicBlock *BB) { } void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LI, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, + PostDominatorTree *PDT) { LLVM_DEBUG(dbgs() << "---- Branch Probability Info : " << F.getName() << " ----\n\n"); LastF = &F; // Store the last function we ran on for printing. @@ -1008,10 +1010,15 @@ void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LI, LLVM_DEBUG(dbgs() << "\n"); } - std::unique_ptr<PostDominatorTree> PDT = - std::make_unique<PostDominatorTree>(const_cast<Function &>(F)); - computePostDominatedByUnreachable(F, PDT.get()); - computePostDominatedByColdCall(F, PDT.get()); + std::unique_ptr<PostDominatorTree> PDTPtr; + + if (!PDT) { + PDTPtr = std::make_unique<PostDominatorTree>(const_cast<Function &>(F)); + PDT = PDTPtr.get(); + } + + computePostDominatedByUnreachable(F, PDT); + computePostDominatedByColdCall(F, PDT); // Walk the basic blocks in post-order so that we can build up state about // the successors of a block iteratively. @@ -1057,6 +1064,7 @@ void BranchProbabilityInfoWrapperPass::getAnalysisUsage( AU.addRequired<DominatorTreeWrapperPass>(); AU.addRequired<LoopInfoWrapperPass>(); AU.addRequired<TargetLibraryInfoWrapperPass>(); + AU.addRequired<PostDominatorTreeWrapperPass>(); AU.setPreservesAll(); } @@ -1064,7 +1072,9 @@ bool BranchProbabilityInfoWrapperPass::runOnFunction(Function &F) { const LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); const TargetLibraryInfo &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F); - BPI.calculate(F, LI, &TLI); + PostDominatorTree &PDT = + getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree(); + BPI.calculate(F, LI, &TLI, &PDT); return false; } @@ -1079,7 +1089,9 @@ AnalysisKey BranchProbabilityAnalysis::Key; BranchProbabilityInfo BranchProbabilityAnalysis::run(Function &F, FunctionAnalysisManager &AM) { BranchProbabilityInfo BPI; - BPI.calculate(F, AM.getResult<LoopAnalysis>(F), &AM.getResult<TargetLibraryAnalysis>(F)); + BPI.calculate(F, AM.getResult<LoopAnalysis>(F), + &AM.getResult<TargetLibraryAnalysis>(F), + &AM.getResult<PostDominatorTreeAnalysis>(F)); return BPI; } |