[llvm] [BOLT][merge-fdata] Fix basic sample profile aggregation without LBR info (PR #118481)

Tibor Dusnoki via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 6 06:15:51 PST 2024


https://github.com/tdusnoki updated https://github.com/llvm/llvm-project/pull/118481

>From b8ebec170289330ebfe4f613e18b0f3892cb0959 Mon Sep 17 00:00:00 2001
From: Tibor <tdusnoki at inf.u-szeged.hu>
Date: Thu, 28 Nov 2024 16:20:03 +0100
Subject: [PATCH] [BOLT][merge-fdata] Fix basic sample profile aggregation
 without LBR info

When a basic sample profile is gathered without LBR info, the generated profile contains a "no-lbr" tag in the first line of the fdata file. This PR fixes merge-fdata to recognize and save this tag to the output file.
---
 bolt/test/Inputs/lbr_profile.fdata      | 20 ++++++++++++++++++++
 bolt/test/Inputs/no-lbr_profile_1.fdata | 20 ++++++++++++++++++++
 bolt/test/Inputs/no-lbr_profile_2.fdata | 20 ++++++++++++++++++++
 bolt/test/merge-fdata-lbr-mode.test     |  6 ++++++
 bolt/test/merge-fdata-mixed-mode.test   |  7 +++++++
 bolt/test/merge-fdata-no-lbr-mode.test  |  8 ++++++++
 bolt/tools/merge-fdata/merge-fdata.cpp  | 19 ++++++++++++++++++-
 7 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 bolt/test/Inputs/lbr_profile.fdata
 create mode 100644 bolt/test/Inputs/no-lbr_profile_1.fdata
 create mode 100644 bolt/test/Inputs/no-lbr_profile_2.fdata
 create mode 100644 bolt/test/merge-fdata-lbr-mode.test
 create mode 100644 bolt/test/merge-fdata-mixed-mode.test
 create mode 100644 bolt/test/merge-fdata-no-lbr-mode.test

diff --git a/bolt/test/Inputs/lbr_profile.fdata b/bolt/test/Inputs/lbr_profile.fdata
new file mode 100644
index 00000000000000..18dd9d5071a1f5
--- /dev/null
+++ b/bolt/test/Inputs/lbr_profile.fdata
@@ -0,0 +1,20 @@
+1 __aarch64_cas4_acq/1 c 2
+1 __aarch64_cas4_acq/1 0 20
+1 __aarch64_cas4_acq/1 14 954
+1 __aarch64_swp4_rel/1 14 657
+1 __ieee754_fmod 54 1
+1 __ieee754_fmod 14 1
+1 __ieee754_fmod c8 59
+1 __ieee754_fmod 74 2
+1 __ieee754_fmod 8c 119
+1 __ieee754_fmod b4 55
+1 __ieee754_fmod 78 95
+1 __ieee754_fmod a0 93
+1 __ieee754_fmod 94 33
+1 __ieee754_fmod c4 96
+1 __ieee754_fmod 84 31
+1 __ieee754_fmod 80 9
+1 __ieee754_fmod c0 38
+1 __ieee754_fmod 1c 12
+1 __ieee754_fmod 88 111
+1 __ieee754_fmod 18 14
diff --git a/bolt/test/Inputs/no-lbr_profile_1.fdata b/bolt/test/Inputs/no-lbr_profile_1.fdata
new file mode 100644
index 00000000000000..8c6955e05d6547
--- /dev/null
+++ b/bolt/test/Inputs/no-lbr_profile_1.fdata
@@ -0,0 +1,20 @@
+no_lbr cycles:HG:
+1 __aarch64_cas4_acq/1 c 2
+1 __aarch64_cas4_acq/1 0 20
+1 __aarch64_cas4_acq/1 14 954
+1 __aarch64_swp4_rel/1 14 657
+1 __ieee754_fmod 54 1
+1 __ieee754_fmod 14 1
+1 __ieee754_fmod c8 59
+1 __ieee754_fmod 74 2
+1 __ieee754_fmod 8c 119
+1 __ieee754_fmod b4 55
+1 __ieee754_fmod 78 95
+1 __ieee754_fmod a0 93
+1 __ieee754_fmod 94 33
+1 __ieee754_fmod c4 96
+1 __ieee754_fmod 84 31
+1 __ieee754_fmod 80 9
+1 __ieee754_fmod c0 38
+1 __ieee754_fmod 1c 12
+1 __ieee754_fmod 88 111
diff --git a/bolt/test/Inputs/no-lbr_profile_2.fdata b/bolt/test/Inputs/no-lbr_profile_2.fdata
new file mode 100644
index 00000000000000..16605d64cb1b4a
--- /dev/null
+++ b/bolt/test/Inputs/no-lbr_profile_2.fdata
@@ -0,0 +1,20 @@
+no_lbr cycles:HG:
+1 __aarch64_cas4_acq/1 14 981
+1 __aarch64_cas4_acq/1 0 23
+1 __aarch64_swp4_rel/1 c 2
+1 __aarch64_swp4_rel/1 14 663
+1 __ieee754_fmod 80 17
+1 __ieee754_fmod bc 4
+1 __ieee754_fmod b4 56
+1 __ieee754_fmod 58 12
+1 __ieee754_fmod b0 49
+1 __ieee754_fmod c0 44
+1 __ieee754_fmod 18 12
+1 __ieee754_fmod 88 98
+1 __ieee754_fmod 38 12
+1 __ieee754_fmod c4 73
+1 __ieee754_fmod 1c 11
+1 __ieee754_fmod 98 85
+1 __ieee754_fmod a0 85
+1 __ieee754_fmod c8 65
+1 __ieee754_fmod ac 15
diff --git a/bolt/test/merge-fdata-lbr-mode.test b/bolt/test/merge-fdata-lbr-mode.test
new file mode 100644
index 00000000000000..d32c9caec90e6a
--- /dev/null
+++ b/bolt/test/merge-fdata-lbr-mode.test
@@ -0,0 +1,6 @@
+## Check that merge-fdata tool doesn't falsely print no_lbr when not in no-lbr mode
+
+RUN: merge-fdata %S/Inputs/blarge.fdata %S/Inputs/blarge.fdata \
+RUN:                   | FileCheck %s --check-prefix=CHECK-FDATA
+
+CHECK-FDATA-NOT: no_lbr
diff --git a/bolt/test/merge-fdata-mixed-mode.test b/bolt/test/merge-fdata-mixed-mode.test
new file mode 100644
index 00000000000000..befee06e5e535f
--- /dev/null
+++ b/bolt/test/merge-fdata-mixed-mode.test
@@ -0,0 +1,7 @@
+## Check that merge-fdata tool correctly reports error message
+## when trying to merge 'no-lbr' and 'lbr' profiles
+# RUN: not merge-fdata %S/Inputs/no-lbr_profile_1.fdata \
+# RUN:                      %S/Inputs/lbr_profile.fdata \
+# RUN:                                     | FileCheck %s
+
+# CHECK: error: cannot mix 'no_lbr' and 'lbr' profiles
diff --git a/bolt/test/merge-fdata-no-lbr-mode.test b/bolt/test/merge-fdata-no-lbr-mode.test
new file mode 100644
index 00000000000000..d63f98e096927d
--- /dev/null
+++ b/bolt/test/merge-fdata-no-lbr-mode.test
@@ -0,0 +1,8 @@
+## Check that merge-fdata tool correctly processes fdata files with header
+## string produced by no-lbr mode (no_lbr)
+RUN: merge-fdata %S/Inputs/no-lbr_profile_1.fdata \
+RUN:             %S/Inputs/no-lbr_profile_2.fdata \
+RUN:      | FileCheck %s --check-prefix=CHECK-FDATA
+
+CHECK-FDATA: no_lbr
+CHECK-FDATA: 1 tan 234 1
diff --git a/bolt/tools/merge-fdata/merge-fdata.cpp b/bolt/tools/merge-fdata/merge-fdata.cpp
index 89ca46c1c0a8fa..6877fb17c6264e 100644
--- a/bolt/tools/merge-fdata/merge-fdata.cpp
+++ b/bolt/tools/merge-fdata/merge-fdata.cpp
@@ -265,6 +265,7 @@ bool isYAML(const StringRef Filename) {
 void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
   errs() << "Using legacy profile format.\n";
   std::optional<bool> BoltedCollection;
+  std::optional<bool> NoLBRCollection;
   std::mutex BoltedCollectionMutex;
   typedef StringMap<uint64_t> ProfileTy;
 
@@ -297,7 +298,21 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
               "cannot mix profile collected in BOLT and non-BOLT deployments");
         BoltedCollection = false;
       }
-
+      // Check if the string "no_lbr" is in the first line
+      size_t FirstNewline = Buf.find('\n');
+      if (FirstNewline != StringRef::npos) {
+        StringRef FirstLine = Buf.substr(0, FirstNewline);
+        if (FirstLine.contains("no_lbr")) {
+          if (!NoLBRCollection.value_or(true))
+            report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
+          NoLBRCollection = true;
+          Buf = Buf.drop_front(FirstNewline + 1);
+        } else {
+          if (NoLBRCollection.value_or(false))
+            report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
+          NoLBRCollection = false;
+        }
+      }
       Profile = &Profiles[tid];
     }
 
@@ -336,6 +351,8 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
 
   if (BoltedCollection.value_or(false))
     output() << "boltedcollection\n";
+  if (NoLBRCollection.value_or(false))
+    output() << "no_lbr\n";
   for (const auto &[Key, Value] : MergedProfile)
     output() << Key << " " << Value << "\n";
 



More information about the llvm-commits mailing list