From: Vedant Kumar Date: Tue, 22 Jan 2019 22:49:08 +0000 (+0000) Subject: [HotColdSplit] Calculate domtrees lazily to reduce compile-time, NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4631696c9821c4fb35db28c3748e939853fa4c55;p=llvm [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%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351892 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/HotColdSplitting.cpp b/lib/Transforms/IPO/HotColdSplitting.cpp index 14758f430ed..eda96710b95 100644 --- a/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/lib/Transforms/IPO/HotColdSplitting.cpp @@ -74,10 +74,6 @@ static cl::opt namespace { -struct PostDomTree : PostDomTreeBase { - 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 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 RPOT(&F); + // Calculate domtrees lazily. This reduces compile-time significantly. + std::unique_ptr DT; + std::unique_ptr 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(F); + if (!PDT) + PDT = make_unique(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; }