[llvm] c460ef6 - [CSSPGO][llvm-profgen] Change sample count of dangling probe in llvm-profgen

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 8 14:36:59 PST 2021


Author: wlei
Date: 2021-03-08T14:36:02-08:00
New Revision: c460ef61d64f3ccb46f60d1b53f271f5b1c05b79

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

LOG: [CSSPGO][llvm-profgen] Change sample count of dangling probe in llvm-profgen

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

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/SampleProf.h
    llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test
    llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test
    llvm/tools/llvm-profgen/ProfileGenerator.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 7c7957779ff1..11b160fc3ac6 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -552,6 +552,13 @@ class FunctionSamples {
         FName, Num, Weight);
   }
 
+  sampleprof_error addBodySamplesForProbe(uint32_t Index, uint64_t Num,
+                                          uint64_t Weight = 1) {
+    SampleRecord S;
+    S.addSamples(Num, Weight);
+    return BodySamples[LineLocation(Index, 0)].merge(S, Weight);
+  }
+
   /// Return the number of samples collected at the given location.
   /// Each location is specified by \p LineOffset and \p Discriminator.
   /// If the location is not found in profile, return error.

diff  --git a/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test
index c7aa1dea21bb..cb414c2e6c06 100644
--- a/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test
+++ b/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test
@@ -9,10 +9,10 @@
 ; CHECK-NEXT: 6: 15
 ; CHECK-NEXT: 8: 14 bar:14
 ; CHECK-NEXT: !CFGChecksum: 138950591924
-; CHECK-NEXT:[main:2 @ foo:8 @ bar]:56:14
+; CHECK-NEXT:[main:2 @ foo:8 @ bar]:28:14
 ; CHECK-NEXT: 1: 14
-; CHECK-NEXT: 2: 14
-; CHECK-NEXT: 3: 14
+; CHECK-NEXT: 2: 18446744073709551615
+; CHECK-NEXT: 3: 18446744073709551615
 ; CHECK-NEXT: 4: 14
 ; CHECK-NEXT: !CFGChecksum: 72617220756
 

diff  --git a/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test b/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test
index a0e5507c70dd..64a8b052ab93 100644
--- a/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test
+++ b/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test
@@ -8,10 +8,10 @@
 ; CHECK-NEXT: 6: 15
 ; CHECK-NEXT: 8: 15 bar:15
 ; CHECK-NEXT: !CFGChecksum: 138950591924
-; CHECK-NEXT:[main:2 @ foo:8 @ bar]:60:15
+; CHECK-NEXT:[main:2 @ foo:8 @ bar]:30:15
 ; CHECK-NEXT: 1: 15
-; CHECK-NEXT: 2: 15
-; CHECK-NEXT: 3: 15
+; CHECK-NEXT: 2: 18446744073709551615
+; CHECK-NEXT: 3: 18446744073709551615
 ; CHECK-NEXT: 4: 15
 ; CHECK-NEXT: !CFGChecksum: 72617220756
 

diff  --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 4cfadffebb18..d4233a804e24 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -492,7 +492,17 @@ void PseudoProbeCSProfileGenerator::populateBodySamplesWithProbes(
     FunctionSamples &FunctionProfile =
         getFunctionProfileForLeafProbe(ContextStrStack, Probe, Binary);
 
-    FunctionProfile.addBodySamples(Probe->Index, 0, Count);
+    // Use InvalidProbeCount(UINT64_MAX) to mark sample count for a dangling
+    // probe. Dangling probes are the probes associated to an empty block. With
+    // this place holder, sample count on dangling probe will not be trusted by
+    // the compiler and it will rely on the counts inference algorithm to get
+    // the probe a reasonable count.
+    if (Probe->isDangling()) {
+      FunctionProfile.addBodySamplesForProbe(
+          Probe->Index, FunctionSamples::InvalidProbeCount);
+      continue;
+    }
+    FunctionProfile.addBodySamplesForProbe(Probe->Index, Count);
     FunctionProfile.addTotalSamples(Count);
     if (Probe->isEntry()) {
       FunctionProfile.addHeadSamples(Count);


        


More information about the llvm-commits mailing list