[llvm] 1831986 - [PGO][PGSO] Prep for enabling non-cold code size opts under non-partial-profile sample PGO.

Hiroshi Yamauchi via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 29 08:58:13 PDT 2020


Author: Hiroshi Yamauchi
Date: 2020-04-29T08:57:47-07:00
New Revision: 18319868267a898ba6559e50653330da0dcd7ed0

URL: https://github.com/llvm/llvm-project/commit/18319868267a898ba6559e50653330da0dcd7ed0
DIFF: https://github.com/llvm/llvm-project/commit/18319868267a898ba6559e50653330da0dcd7ed0.diff

LOG: [PGO][PGSO] Prep for enabling non-cold code size opts under non-partial-profile sample PGO.

Summary:
- Distinguish between partial-profile and non-partial-profile sample PGO.
- Add a flag for partial-profile sample PGO.
- Tune the sample PGO cutoff.
- No default behavior change (yet).

Reviewers: davidxl

Subscribers: eraman, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78949

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/ProfileSummaryInfo.h
    llvm/include/llvm/Transforms/Utils/SizeOpts.h
    llvm/lib/Transforms/Utils/SizeOpts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
index 615abe233ced..e293d069f1f1 100644
--- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
+++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
@@ -72,6 +72,13 @@ class ProfileSummaryInfo {
            Summary->getKind() == ProfileSummary::PSK_Sample;
   }
 
+  /// Returns true if module \c M has partial-profile sample profile.
+  bool hasPartialSampleProfile() {
+    return hasProfileSummary() &&
+           Summary->getKind() == ProfileSummary::PSK_Sample &&
+           Summary->isPartialProfile();
+  }
+
   /// Returns true if module \c M has instrumentation profile.
   bool hasInstrumentationProfile() {
     return hasProfileSummary() &&

diff  --git a/llvm/include/llvm/Transforms/Utils/SizeOpts.h b/llvm/include/llvm/Transforms/Utils/SizeOpts.h
index d4a2d8edb459..08d963475f23 100644
--- a/llvm/include/llvm/Transforms/Utils/SizeOpts.h
+++ b/llvm/include/llvm/Transforms/Utils/SizeOpts.h
@@ -23,6 +23,7 @@ extern llvm::cl::opt<bool> PGSOIRPassOrTestOnly;
 extern llvm::cl::opt<bool> PGSOColdCodeOnly;
 extern llvm::cl::opt<bool> PGSOColdCodeOnlyForInstrPGO;
 extern llvm::cl::opt<bool> PGSOColdCodeOnlyForSamplePGO;
+extern llvm::cl::opt<bool> PGSOColdCodeOnlyForPartialSamplePGO;
 extern llvm::cl::opt<bool> ForcePGSO;
 extern llvm::cl::opt<int> PgsoCutoffInstrProf;
 extern llvm::cl::opt<int> PgsoCutoffSampleProf;
@@ -39,6 +40,16 @@ enum class PGSOQueryType {
   Other,  // Others.
 };
 
+static inline bool isPGSOColdCodeOnly(ProfileSummaryInfo *PSI) {
+  return PGSOColdCodeOnly ||
+         (PSI->hasInstrumentationProfile() && PGSOColdCodeOnlyForInstrPGO) ||
+         (PSI->hasSampleProfile() &&
+          ((!PSI->hasPartialSampleProfile() && PGSOColdCodeOnlyForSamplePGO) ||
+           (PSI->hasPartialSampleProfile() &&
+            PGSOColdCodeOnlyForPartialSamplePGO))) ||
+         (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize());
+}
+
 template<typename AdapterT, typename FuncT, typename BFIT>
 bool shouldFuncOptimizeForSizeImpl(const FuncT *F, ProfileSummaryInfo *PSI,
                                    BFIT *BFI, PGSOQueryType QueryType) {
@@ -54,13 +65,8 @@ bool shouldFuncOptimizeForSizeImpl(const FuncT *F, ProfileSummaryInfo *PSI,
   if (PGSOIRPassOrTestOnly && !(QueryType == PGSOQueryType::IRPass ||
                                 QueryType == PGSOQueryType::Test))
     return false;
-  if (PGSOColdCodeOnly ||
-      (PSI->hasInstrumentationProfile() && PGSOColdCodeOnlyForInstrPGO) ||
-      (PSI->hasSampleProfile() && PGSOColdCodeOnlyForSamplePGO) ||
-      (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize())) {
-    // Even if the working set size isn't large, size-optimize cold code.
+  if (isPGSOColdCodeOnly(PSI))
     return AdapterT::isFunctionColdInCallGraph(F, PSI, *BFI);
-  }
   if (PSI->hasSampleProfile())
     // The "isCold" check seems to work better for Sample PGO as it could have
     // many profile-unannotated functions.
@@ -84,13 +90,8 @@ bool shouldOptimizeForSizeImpl(BlockTOrBlockFreq BBOrBlockFreq, ProfileSummaryIn
   if (PGSOIRPassOrTestOnly && !(QueryType == PGSOQueryType::IRPass ||
                                 QueryType == PGSOQueryType::Test))
     return false;
-  if (PGSOColdCodeOnly ||
-      (PSI->hasInstrumentationProfile() && PGSOColdCodeOnlyForInstrPGO) ||
-      (PSI->hasSampleProfile() && PGSOColdCodeOnlyForSamplePGO) ||
-      (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize())) {
-    // Even if the working set size isn't large, size-optimize cold code.
+  if (isPGSOColdCodeOnly(PSI))
     return AdapterT::isColdBlock(BBOrBlockFreq, PSI, BFI);
-  }
   if (PSI->hasSampleProfile())
     // The "isCold" check seems to work better for Sample PGO as it could have
     // many profile-unannotated functions.

diff  --git a/llvm/lib/Transforms/Utils/SizeOpts.cpp b/llvm/lib/Transforms/Utils/SizeOpts.cpp
index f299681ef779..b67d4a18ec43 100644
--- a/llvm/lib/Transforms/Utils/SizeOpts.cpp
+++ b/llvm/lib/Transforms/Utils/SizeOpts.cpp
@@ -38,6 +38,11 @@ cl::opt<bool> PGSOColdCodeOnlyForSamplePGO(
     cl::desc("Apply the profile guided size optimizations only "
              "to cold code under sample PGO."));
 
+cl::opt<bool> PGSOColdCodeOnlyForPartialSamplePGO(
+    "pgso-cold-code-only-for-partial-sample-pgo", cl::Hidden, cl::init(true),
+    cl::desc("Apply the profile guided size optimizations only "
+             "to cold code under partial-profile sample PGO."));
+
 cl::opt<bool> PGSOIRPassOrTestOnly(
     "pgso-ir-pass-or-test-only", cl::Hidden, cl::init(false),
     cl::desc("Apply the profile guided size optimizations only"
@@ -53,7 +58,7 @@ cl::opt<int> PgsoCutoffInstrProf(
              "for instrumentation profile."));
 
 cl::opt<int> PgsoCutoffSampleProf(
-    "pgso-cutoff-sample-prof", cl::Hidden, cl::init(800000), cl::ZeroOrMore,
+    "pgso-cutoff-sample-prof", cl::Hidden, cl::init(990000), cl::ZeroOrMore,
     cl::desc("The profile guided size optimization profile summary cutoff "
              "for sample profile."));
 


        


More information about the llvm-commits mailing list