[llvm] f91b0f2 - [AutoFDO]Merge called target in body samples when flattening profiles
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 31 13:27:07 PDT 2023
Author: Mingming Liu
Date: 2023-03-31T13:24:59-07:00
New Revision: f91b0f23c2f85361a9d20821ceadea770727425d
URL: https://github.com/llvm/llvm-project/commit/f91b0f23c2f85361a9d20821ceadea770727425d
DIFF: https://github.com/llvm/llvm-project/commit/f91b0f23c2f85361a9d20821ceadea770727425d.diff
LOG: [AutoFDO]Merge called target in body samples when flattening profiles
- Body samples could have call targets, merge them as well.
Differential Revision: https://reviews.llvm.org/D147297
Added:
Modified:
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
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 8e76af2316cea..cd376e3023129 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -777,6 +777,11 @@ class FunctionSamples {
FName, Num, Weight);
}
+ sampleprof_error addSampleRecord(LineLocation Location,
+ const SampleRecord &SampleRecord, uint64_t Weight = 1) {
+ return BodySamples[Location].merge(SampleRecord, Weight);
+ }
+
// 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 @@ class ProfileConverter {
// 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 @@ class ProfileConverter {
// 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);
}
}
diff --git a/llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext b/llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext
index bb0bf51c6a194..51be9e2b0074d 100644
--- a/llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext
+++ b/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 @@ main:110:1
!CFGChecksum: 3
!Attributes: 3
10: baz:20
+ 4: 15 qux:3 quux:7 corge:5
10: 1
6: bar:3
1: 2
diff --git a/llvm/test/tools/llvm-profdata/sample-flatten-profile.test b/llvm/test/tools/llvm-profdata/sample-flatten-profile.test
index 90effcb25190e..f99021bc6b723 100644
--- a/llvm/test/tools/llvm-profdata/sample-flatten-profile.test
+++ b/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
More information about the llvm-commits
mailing list