[llvm] r351894 - [HotColdSplit] Calculate BFI lazily to reduce compile-time, NFC

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 14:49:22 PST 2019


Author: vedantk
Date: Tue Jan 22 14:49:22 2019
New Revision: 351894

URL: http://llvm.org/viewvc/llvm-project?rev=351894&view=rev
Log:
[HotColdSplit] Calculate BFI lazily to reduce compile-time, NFC

The splitting pass does not need BFI unless the Module actually has a profile
summary. Do not calcualte BFI unless the summary is present.

For the sqlite3 amalgamation, this reduces time spent in the splitting pass
from 0.4% of the total to under 0.1%.

Modified:
    llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp

Modified: llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp?rev=351894&r1=351893&r2=351894&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp Tue Jan 22 14:49:22 2019
@@ -176,7 +176,7 @@ public:
 private:
   bool isFunctionCold(const Function &F) const;
   bool shouldOutlineFrom(const Function &F) const;
-  bool outlineColdRegions(Function &F);
+  bool outlineColdRegions(Function &F, bool HasProfileSummary);
   Function *extractColdRegion(const BlockSequence &Region, DominatorTree &DT,
                               BlockFrequencyInfo *BFI, TargetTransformInfo &TTI,
                               OptimizationRemarkEmitter &ORE, unsigned Count);
@@ -448,7 +448,7 @@ public:
 };
 } // namespace
 
-bool HotColdSplitting::outlineColdRegions(Function &F) {
+bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) {
   bool Changed = false;
 
   // The set of cold blocks.
@@ -466,7 +466,13 @@ bool HotColdSplitting::outlineColdRegion
   std::unique_ptr<DominatorTree> DT;
   std::unique_ptr<PostDominatorTree> PDT;
 
-  BlockFrequencyInfo *BFI = GetBFI(F);
+  // Calculate BFI lazily (it's only used to query ProfileSummaryInfo). This
+  // reduces compile-time significantly. TODO: When we *do* use BFI, we should
+  // be able to salvage its domtrees instead of recomputing them.
+  BlockFrequencyInfo *BFI = nullptr;
+  if (HasProfileSummary)
+    BFI = GetBFI(F);
+
   TargetTransformInfo &TTI = GetTTI(F);
   OptimizationRemarkEmitter &ORE = (*GetORE)(F);
 
@@ -476,7 +482,7 @@ bool HotColdSplitting::outlineColdRegion
     if (ColdBlocks.count(BB))
       continue;
 
-    bool Cold = PSI->isColdBlock(BB, BFI) ||
+    bool Cold = (BFI && PSI->isColdBlock(BB, BFI)) ||
                 (EnableStaticAnalyis && unlikelyExecuted(*BB));
     if (!Cold)
       continue;
@@ -550,6 +556,7 @@ bool HotColdSplitting::outlineColdRegion
 
 bool HotColdSplitting::run(Module &M) {
   bool Changed = false;
+  bool HasProfileSummary = M.getProfileSummary();
   for (auto It = M.begin(), End = M.end(); It != End; ++It) {
     Function &F = *It;
 
@@ -573,7 +580,7 @@ bool HotColdSplitting::run(Module &M) {
     }
 
     LLVM_DEBUG(llvm::dbgs() << "Outlining in " << F.getName() << "\n");
-    Changed |= outlineColdRegions(F);
+    Changed |= outlineColdRegions(F, HasProfileSummary);
   }
   return Changed;
 }




More information about the llvm-commits mailing list