[PATCH] D125591: [BOLT] Fix merge-fdata handling of BAT profiles

Rafael Auler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 15:59:18 PDT 2022


rafauler created this revision.
rafauler added reviewers: maksfb, Amir, yota9, kongyi.
Herald added a subscriber: ayermolo.
Herald added a project: All.
rafauler requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When a profile is collected in a BOLTed binary, the generated
profile is tagged with a header string "boltedcollection" in the first
line of the fdata file. Fix merge-fdata to recognize this header
string and preserve it into the output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125591

Files:
  bolt/test/X86/Inputs/bat_profile_1.fdata
  bolt/test/X86/Inputs/bat_profile_2.fdata
  bolt/test/X86/merge-fdata-bat-mode.test
  bolt/tools/merge-fdata/merge-fdata.cpp


Index: bolt/tools/merge-fdata/merge-fdata.cpp
===================================================================
--- bolt/tools/merge-fdata/merge-fdata.cpp
+++ bolt/tools/merge-fdata/merge-fdata.cpp
@@ -257,8 +257,7 @@
             Filename,
             "cannot mix profile collected in BOLT and non-BOLT deployments");
       BoltedCollection = true;
-      if (!First)
-        Buf = Buf.drop_front(17);
+      Buf = Buf.drop_front(17);
     } else {
       if (BoltedCollection)
         report_error(
@@ -282,6 +281,8 @@
     First = false;
   }
 
+  if (BoltedCollection)
+    outs() << "boltedcollection\n";
   for (const auto &Entry : Entries)
     outs() << Entry.getKey() << " " << Entry.getValue() << "\n";
 
Index: bolt/test/X86/merge-fdata-bat-mode.test
===================================================================
--- /dev/null
+++ bolt/test/X86/merge-fdata-bat-mode.test
@@ -0,0 +1,12 @@
+# Check merge-fdata tool correctly processes fdata files with header strings
+# such as the ones produced by BAT mode (bolted_collection)
+RUN: merge-fdata %S/Inputs/bat_profile_1.fdata \
+RUN:             %S/Inputs/bat_profile_2.fdata 2> %t.error \
+RUN:   | FileCheck %s --check-prefix=CHECK-FDATA
+RUN: cat %t.error |& FileCheck %s --check-prefix=CHECK-ERROR
+
+CHECK-ERROR-NOT:  malformed
+
+CHECK-FDATA: 1 main 451 1 SolveCubic 0 0 302
+
+
Index: bolt/test/X86/Inputs/bat_profile_2.fdata
===================================================================
--- /dev/null
+++ bolt/test/X86/Inputs/bat_profile_2.fdata
@@ -0,0 +1,20 @@
+boltedcollection
+1 main 451 1 SolveCubic 0 0 151
+1 main 489 1 main 46a 0 27
+1 main 4ad 1 main 428 0 135
+1 main 4cb 1 main 410 2 19
+1 main 4e9 1 main 3fa 0 1
+1 main 521 1 usqrt 0 0 168
+1 main 543 1 main 519 0 179
+1 main 55c 1 usqrt 0 0 31
+1 main 57f 1 main 554 0 34
+1 main 5d6 1 main 58f 0 1001
+1 main 62d 1 main 5e6 0 22
+1 SolveCubic 82 1 SolveCubic 130 2 4
+1 SolveCubic 107 1 SolveCubic 111 0 89
+1 SolveCubic 12c 1 main 456 0 87
+1 SolveCubic 2a6 1 main 456 0 5
+1 usqrt 30 1 usqrt 39 171 2886
+1 usqrt 3d 1 usqrt 10 33 4711
+1 usqrt 42 1 main 526 0 73
+1 usqrt 42 1 main 561 0 19
Index: bolt/test/X86/Inputs/bat_profile_1.fdata
===================================================================
--- /dev/null
+++ bolt/test/X86/Inputs/bat_profile_1.fdata
@@ -0,0 +1,20 @@
+boltedcollection
+1 main 451 1 SolveCubic 0 0 151
+1 main 489 1 main 46a 0 27
+1 main 4ad 1 main 428 0 135
+1 main 4cb 1 main 410 2 19
+1 main 4e9 1 main 3fa 0 1
+1 main 521 1 usqrt 0 0 168
+1 main 543 1 main 519 0 179
+1 main 55c 1 usqrt 0 0 31
+1 main 57f 1 main 554 0 34
+1 main 5d6 1 main 58f 0 1001
+1 main 62d 1 main 5e6 0 22
+1 SolveCubic 82 1 SolveCubic 130 2 4
+1 SolveCubic 107 1 SolveCubic 111 0 89
+1 SolveCubic 12c 1 main 456 0 87
+1 SolveCubic 2a6 1 main 456 0 5
+1 usqrt 30 1 usqrt 39 171 2886
+1 usqrt 3d 1 usqrt 10 33 4711
+1 usqrt 42 1 main 526 0 73
+1 usqrt 42 1 main 561 0 19


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125591.429378.patch
Type: text/x-patch
Size: 2935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/794f2f8f/attachment.bin>


More information about the llvm-commits mailing list