[BOLT] Sort BranchData in DataAggregator
authorAmir Ayupov <aaupov@fb.com>
Thu, 15 Jun 2023 19:08:07 +0000 (12:08 -0700)
committerAmir Ayupov <aaupov@fb.com>
Thu, 15 Jun 2023 19:08:57 +0000 (12:08 -0700)
Align perf reader to fdata behavior by sorting BranchData after reading samples,
in the same way as DataReader:
https://github.com/llvm/llvm-project/blob/20c66a0c66340f44f04b6526e45bcc5d872d480a/bolt/lib/Profile/DataReader.cpp#L1239

Namely, that order affects CallSiteInfo annotations which determine the
construction order of CallGraph, which in turn affects function reordering.

Reviewed By: #bolt, rafauler

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

bolt/lib/Profile/DataAggregator.cpp
bolt/test/runtime/X86/fdata-escape-chars.ll

index fd91756..24dbe34 100644 (file)
@@ -624,6 +624,12 @@ void DataAggregator::processProfile(BinaryContext &BC) {
       BF.markProfiled(Flags);
   }
 
+  for (auto &FuncBranches : NamesToBranches)
+    llvm::stable_sort(FuncBranches.second.Data);
+
+  for (auto &MemEvents : NamesToMemEvents)
+    llvm::stable_sort(MemEvents.second.Data);
+
   // Release intermediate storage.
   clear(BranchLBRs);
   clear(FallthroughLBRs);
index a5be4e4..4ea781a 100644 (file)
@@ -88,8 +88,8 @@ define internal void @static_symb_backslash_b() #0 {
 ; INSTR_CHECK: {{([[:xdigit:]]+)}}:   callq   "symb whitespace" # Count: 1
 
 ; PREAGR_FDATA_CHECK: 1 main 0 1 static\ symb\ backslash\\/1 0 0 1
-; PREAGR_FDATA_CHECK: 1 main 0 1 symb\ whitespace 0 0 1
 ; PREAGR_FDATA_CHECK: 1 main 0 1 symb\ backslash\\ 0 0 2
+; PREAGR_FDATA_CHECK: 1 main 0 1 symb\ whitespace 0 0 1
 ; PREAGR_FDATA_CHECK: 1 static\ symb\ backslash\\/1 0 1 symb\ whitespace 0 0 1
 ; PREAGR_FDATA_CHECK: 1 symb\ backslash\\ 0 1 symb\ whitespace 0 0 2