[PATCH] D78310: [ProfileSummary] Add partial profile annotation on IR.

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 11:08:56 PDT 2020


wmi created this revision.
wmi added reviewers: davidxl, yamauchi, wenlei.
Herald added subscribers: dexonsmith, hiraditya, eraman.

Profile and profile summary are usually read only once and then annotated on IR. The profile summary information on IR should include the value of the newly added partial profile flag, so that compilation phase like thinlto postlink can get the full set of profile information.


Repository:
  rL LLVM

https://reviews.llvm.org/D78310

Files:
  llvm/include/llvm/IR/ProfileSummary.h
  llvm/lib/IR/ProfileSummary.cpp
  llvm/test/Transforms/SampleProfile/summary.ll


Index: llvm/test/Transforms/SampleProfile/summary.ll
===================================================================
--- llvm/test/Transforms/SampleProfile/summary.ll
+++ llvm/test/Transforms/SampleProfile/summary.ll
@@ -1,6 +1,10 @@
 ; Test that we annotate entire program's summary to IR.
 ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | FileCheck %s
 ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | opt -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | FileCheck %s
+; Test that we annotate partial profile flag to IR correctly.
+; RUN: llvm-profdata merge --sample --extbinary --partial-profile %S/Inputs/summary.prof --output=%t.prof
+; RUN: opt < %s -sample-profile -sample-profile-file=%t.prof -S | FileCheck %s -check-prefix=PARTIAL
+; RUN: opt < %s -sample-profile -sample-profile-file=%t.prof -S | opt -sample-profile -sample-profile-file=%t.prof -S | FileCheck %s -check-prefix=PARTIAL
 
 define i32 @bar() #0 !dbg !1 {
 entry:
@@ -18,6 +22,8 @@
 ; CHECK-DAG: {{![0-9]+}} = !{!"NumCounts", i64 5}
 ; CHECK-DAG: {{![0-9]+}} = !{!"NumFunctions", i64 3}
 ; CHECK-DAG: {{![0-9]+}} = !{!"MaxFunctionCount", i64 3}
+; CHECK-DAG: {{![0-9]+}} = !{!"IsPartialProfile", i64 0}
+; PARTIAL: {{![0-9]+}} = !{!"IsPartialProfile", i64 1}
 
 !1 = distinct !DISubprogram(name: "bar")
 !2 = !DILocation(line: 2, scope: !2)
Index: llvm/lib/IR/ProfileSummary.cpp
===================================================================
--- llvm/lib/IR/ProfileSummary.cpp
+++ llvm/lib/IR/ProfileSummary.cpp
@@ -68,14 +68,15 @@
 Metadata *ProfileSummary::getMD(LLVMContext &Context) {
   const char *KindStr[3] = {"InstrProf", "CSInstrProf", "SampleProfile"};
   Metadata *Components[] = {
-    getKeyValMD(Context, "ProfileFormat", KindStr[PSK]),
-    getKeyValMD(Context, "TotalCount", getTotalCount()),
-    getKeyValMD(Context, "MaxCount", getMaxCount()),
-    getKeyValMD(Context, "MaxInternalCount", getMaxInternalCount()),
-    getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()),
-    getKeyValMD(Context, "NumCounts", getNumCounts()),
-    getKeyValMD(Context, "NumFunctions", getNumFunctions()),
-    getDetailedSummaryMD(Context),
+      getKeyValMD(Context, "ProfileFormat", KindStr[PSK]),
+      getKeyValMD(Context, "TotalCount", getTotalCount()),
+      getKeyValMD(Context, "MaxCount", getMaxCount()),
+      getKeyValMD(Context, "MaxInternalCount", getMaxInternalCount()),
+      getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()),
+      getKeyValMD(Context, "NumCounts", getNumCounts()),
+      getKeyValMD(Context, "NumFunctions", getNumFunctions()),
+      getKeyValMD(Context, "IsPartialProfile", isPartialProfile()),
+      getDetailedSummaryMD(Context),
   };
   return MDTuple::get(Context, Components);
 }
@@ -159,7 +160,7 @@
     return nullptr;
 
   uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount,
-      MaxInternalCount;
+      MaxInternalCount, IsPartialProfile;
   if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(1)), "TotalCount",
               TotalCount))
     return nullptr;
@@ -176,11 +177,14 @@
   if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(6)), "NumFunctions",
               NumFunctions))
     return nullptr;
+  if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(6)), "IsPartialProfile",
+              IsPartialProfile))
+    return nullptr;
 
   SummaryEntryVector Summary;
   if (!getSummaryFromMD(dyn_cast<MDTuple>(Tuple->getOperand(7)), Summary))
     return nullptr;
   return new ProfileSummary(SummaryKind, std::move(Summary), TotalCount,
                             MaxCount, MaxInternalCount, MaxFunctionCount,
-                            NumCounts, NumFunctions);
+                            NumCounts, NumFunctions, IsPartialProfile);
 }
Index: llvm/include/llvm/IR/ProfileSummary.h
===================================================================
--- llvm/include/llvm/IR/ProfileSummary.h
+++ llvm/include/llvm/IR/ProfileSummary.h
@@ -64,11 +64,12 @@
   ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
                  uint64_t TotalCount, uint64_t MaxCount,
                  uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
-                 uint32_t NumCounts, uint32_t NumFunctions)
+                 uint32_t NumCounts, uint32_t NumFunctions,
+                 bool Partial = false)
       : PSK(K), DetailedSummary(std::move(DetailedSummary)),
         TotalCount(TotalCount), MaxCount(MaxCount),
         MaxInternalCount(MaxInternalCount), MaxFunctionCount(MaxFunctionCount),
-        NumCounts(NumCounts), NumFunctions(NumFunctions) {}
+        NumCounts(NumCounts), NumFunctions(NumFunctions), Partial(Partial) {}
 
   Kind getKind() const { return PSK; }
   /// Return summary information as metadata.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78310.258090.patch
Type: text/x-patch
Size: 4815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200416/e8411ede/attachment-0001.bin>


More information about the llvm-commits mailing list