[PATCH] D147297: [AutoFDO]Merge called target in body samples

Mingming Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 31 12:10:27 PDT 2023


mingmingl updated this revision to Diff 510097.
mingmingl marked 4 inline comments as done.
mingmingl added a comment.

added tests and did a small refactor.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147297/new/

https://reviews.llvm.org/D147297

Files:
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext
  llvm/test/tools/llvm-profdata/sample-flatten-profile.test


Index: llvm/test/tools/llvm-profdata/sample-flatten-profile.test
===================================================================
--- llvm/test/tools/llvm-profdata/sample-flatten-profile.test
+++ llvm/test/tools/llvm-profdata/sample-flatten-profile.test
@@ -7,6 +7,8 @@
 ; CHECK:baz:169:10
 ; CHECK-NEXT: 1: 10
 ; CHECK-NEXT: 3: 20
+; CHECK-NEXT: 4: 36 corge:15 quux:13 qux:8
+; CHECK-NEXT: 4.1: 12 thud:5 grault:4 quux:3
 ; CHECK-NEXT: 5: 20 foo:20
 ; CHECK-NEXT: 6: 2 bar:2
 ; CHECK-NEXT: 10: 1
@@ -18,12 +20,12 @@
 ; CHECK-NEXT: 4: 1
 ; CHECK-NEXT: !CFGChecksum: 3
 ; CHECK-NEXT: !Attributes: 3
-; CHECK-NEXT:main:91:1
+; CHECK-NEXT:main:104:1
 ; CHECK-NEXT: 4: 1
 ; CHECK-NEXT: 4.2: 1
 ; CHECK-NEXT: 7: 1
 ; CHECK-NEXT: 9: 3 bar:2 foo:1
-; CHECK-NEXT: 10: 3 baz:2 foo:1
+; CHECK-NEXT: 10: 16 baz:15 foo:1
 ; CHECK-NEXT: !CFGChecksum: 2
 ; CHECK-NEXT: !Attributes: 2
 ; CHECK-NEXT:bar:15:14
Index: llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext
===================================================================
--- llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext
+++ llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext
@@ -1,6 +1,8 @@
 baz:160:10
  1: 10
  3: 20
+ 4: 21 qux:5 quux:6 corge:10
+ 4.1: 12 quux:3 grault:4 thud:5
  5: foo:30
   1: 20
   3: bar:10
@@ -25,6 +27,7 @@
   !CFGChecksum: 3
   !Attributes: 3
  10: baz:20
+  4: 15 qux:3 quux:7 corge:5
   10: 1
   6: bar:3
    1: 2
Index: llvm/include/llvm/ProfileData/SampleProf.h
===================================================================
--- llvm/include/llvm/ProfileData/SampleProf.h
+++ llvm/include/llvm/ProfileData/SampleProf.h
@@ -777,6 +777,11 @@
         FName, Num, Weight);
   }
 
+  sampleprof_error addSampleRecord(LineLocation Location,
+                                   const SampleRecord &SampleRecord) {
+    return BodySamples[Location].merge(SampleRecord);
+  }
+
   // Remove a call target and decrease the body sample correspondingly. Return
   // the number of body samples actually decreased.
   uint64_t removeCalledTargetAndBodySample(uint32_t LineOffset,
@@ -1342,7 +1347,7 @@
     // To retain the context, checksum, attributes of the original profile, make
     // a copy of it if no profile is found.
     SampleContext &Context = FS.getContext();
-    auto Ret = OutputProfiles.emplace(Context, FS);
+    auto Ret = OutputProfiles.try_emplace(Context, FS);
     FunctionSamples &Profile = Ret.first->second;
     if (Ret.second) {
       // When it's the copy of the old profile, just clear all the inlinees'
@@ -1351,9 +1356,8 @@
       // We recompute TotalSamples later, so here set to zero.
       Profile.setTotalSamples(0);
     } else {
-      for (const auto &Line : FS.getBodySamples()) {
-        Profile.addBodySamples(Line.first.LineOffset, Line.first.Discriminator,
-                               Line.second.getSamples());
+      for (const auto &[LineLocation, SampleRecord] : FS.getBodySamples()) {
+        Profile.addSampleRecord(LineLocation, SampleRecord);
       }
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147297.510097.patch
Type: text/x-patch
Size: 3062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230331/5937ca6a/attachment.bin>


More information about the llvm-commits mailing list