diff options
author | Vedant Kumar <vsk@apple.com> | 2019-01-22 22:49:08 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2019-01-22 22:49:08 +0000 |
commit | 38874c8f7b1d73fbd9b6843e706602dbb6c7495d (patch) | |
tree | 18add610c292ec4c51be46f1a26d573425b65351 /llvm/lib/Transforms/IPO/HotColdSplitting.cpp | |
parent | 27f8b4c7e85e58477833bd403085951b769c45ef (diff) | |
download | bcm5719-llvm-38874c8f7b1d73fbd9b6843e706602dbb6c7495d.tar.gz bcm5719-llvm-38874c8f7b1d73fbd9b6843e706602dbb6c7495d.zip |
[HotColdSplit] Calculate domtrees lazily to reduce compile-time, NFC
The splitting pass does not need (post)domtrees until after it's found a
cold block. Defer domtree calculation until a cold block is found.
For the sqlite3 amalgamation, this reduces time spent in the splitting
pass from 0.8% of the total to 0.4%.
llvm-svn: 351892
Diffstat (limited to 'llvm/lib/Transforms/IPO/HotColdSplitting.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/HotColdSplitting.cpp | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp index 14758f430ed..eda96710b95 100644 --- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -74,10 +74,6 @@ static cl::opt<int> namespace { -struct PostDomTree : PostDomTreeBase<BasicBlock> { - PostDomTree(Function &F) { recalculate(F); } -}; - /// A sequence of basic blocks. /// /// A 0-sized SmallVector is slightly cheaper to move than a std::vector. @@ -180,10 +176,7 @@ public: private: bool isFunctionCold(const Function &F) const; bool shouldOutlineFrom(const Function &F) const; - bool outlineColdRegions(Function &F, ProfileSummaryInfo &PSI, - BlockFrequencyInfo *BFI, TargetTransformInfo &TTI, - DominatorTree &DT, PostDomTree &PDT, - OptimizationRemarkEmitter &ORE); + bool outlineColdRegions(Function &F); Function *extractColdRegion(const BlockSequence &Region, DominatorTree &DT, BlockFrequencyInfo *BFI, TargetTransformInfo &TTI, OptimizationRemarkEmitter &ORE, unsigned Count); @@ -327,7 +320,7 @@ public: OutliningRegion &operator=(OutliningRegion &&) = default; static OutliningRegion create(BasicBlock &SinkBB, const DominatorTree &DT, - const PostDomTree &PDT) { + const PostDominatorTree &PDT) { OutliningRegion ColdRegion; SmallPtrSet<BasicBlock *, 4> RegionBlocks; @@ -455,11 +448,7 @@ public: }; } // namespace -bool HotColdSplitting::outlineColdRegions(Function &F, ProfileSummaryInfo &PSI, - BlockFrequencyInfo *BFI, - TargetTransformInfo &TTI, - DominatorTree &DT, PostDomTree &PDT, - OptimizationRemarkEmitter &ORE) { +bool HotColdSplitting::outlineColdRegions(Function &F) { bool Changed = false; // The set of cold blocks. @@ -473,13 +462,21 @@ bool HotColdSplitting::outlineColdRegions(Function &F, ProfileSummaryInfo &PSI, // the first region to contain a block. ReversePostOrderTraversal<Function *> RPOT(&F); + // Calculate domtrees lazily. This reduces compile-time significantly. + std::unique_ptr<DominatorTree> DT; + std::unique_ptr<PostDominatorTree> PDT; + + BlockFrequencyInfo *BFI = GetBFI(F); + TargetTransformInfo &TTI = GetTTI(F); + OptimizationRemarkEmitter &ORE = (*GetORE)(F); + // Find all cold regions. for (BasicBlock *BB : RPOT) { // This block is already part of some outlining region. if (ColdBlocks.count(BB)) continue; - bool Cold = PSI.isColdBlock(BB, BFI) || + bool Cold = PSI->isColdBlock(BB, BFI) || (EnableStaticAnalyis && unlikelyExecuted(*BB)); if (!Cold) continue; @@ -489,7 +486,12 @@ bool HotColdSplitting::outlineColdRegions(Function &F, ProfileSummaryInfo &PSI, BB->dump(); }); - auto Region = OutliningRegion::create(*BB, DT, PDT); + if (!DT) + DT = make_unique<DominatorTree>(F); + if (!PDT) + PDT = make_unique<PostDominatorTree>(F); + + auto Region = OutliningRegion::create(*BB, *DT, *PDT); if (Region.empty()) continue; @@ -519,7 +521,7 @@ bool HotColdSplitting::outlineColdRegions(Function &F, ProfileSummaryInfo &PSI, OutliningRegion Region = OutliningWorklist.pop_back_val(); assert(!Region.empty() && "Empty outlining region in worklist"); do { - BlockSequence SubRegion = Region.takeSingleEntrySubRegion(DT); + BlockSequence SubRegion = Region.takeSingleEntrySubRegion(*DT); if (!isProfitableToOutline(SubRegion, TTI)) { LLVM_DEBUG({ dbgs() << "Skipping outlining; not profitable to outline\n"; @@ -535,7 +537,7 @@ bool HotColdSplitting::outlineColdRegions(Function &F, ProfileSummaryInfo &PSI, }); Function *Outlined = - extractColdRegion(SubRegion, DT, BFI, TTI, ORE, OutlinedFunctionID); + extractColdRegion(SubRegion, *DT, BFI, TTI, ORE, OutlinedFunctionID); if (Outlined) { ++OutlinedFunctionID; Changed = true; @@ -571,13 +573,7 @@ bool HotColdSplitting::run(Module &M) { } LLVM_DEBUG(llvm::dbgs() << "Outlining in " << F.getName() << "\n"); - DominatorTree DT(F); - PostDomTree PDT(F); - PDT.recalculate(F); - BlockFrequencyInfo *BFI = GetBFI(F); - TargetTransformInfo &TTI = GetTTI(F); - OptimizationRemarkEmitter &ORE = (*GetORE)(F); - Changed |= outlineColdRegions(F, *PSI, BFI, TTI, DT, PDT, ORE); + Changed |= outlineColdRegions(F); } return Changed; } |