[PATCH] D144211: [BOLT] computing raw branch count for yaml profiles

Sergey Pupyrev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 14:05:58 PDT 2023


spupyrev updated this revision to Diff 507878.
spupyrev added a comment.

- re-enabled test in branch-data.test
- added a check to the test verifying the new flag


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144211

Files:
  bolt/include/bolt/Core/BinaryFunction.h
  bolt/lib/Core/BinaryFunction.cpp
  bolt/lib/Profile/YAMLProfileReader.cpp
  bolt/test/X86/branch-data.test


Index: bolt/test/X86/branch-data.test
===================================================================
--- bolt/test/X86/branch-data.test
+++ bolt/test/X86/branch-data.test
@@ -3,18 +3,19 @@
 # Also checks that llvm-bolt disassembler and CFG builder is working properly.
 
 RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
-RUN: llvm-bolt %t.exe -o /dev/null --data %p/Inputs/blarge.fdata --print-cfg
+RUN: llvm-bolt %t.exe -o /dev/null --data %p/Inputs/blarge.fdata --print-cfg | FileCheck %s
 
 CHECK:    Binary Function "usqrt"
 CHECK:      State       : CFG constructed
 CHECK:      Address     : 0x401170
 CHECK:      Size        : 0x43
-CHECK:      MaxSize     : 0x50
-CHECK:      Offset      : 0x1170
+CHECK:      MaxSize     : 0x43
+CHECK:      Offset      : 0xcb0
 CHECK:      Section     : .text
 CHECK:      IsSimple    : 1
 CHECK:      BB Count    : 5
 CHECK:      Exec Count  : 199
+CHECK:      RawBranchCount  : 7689
 CHECK:    }
 CHECK:    .LBB{{.*}}
 CHECK:      Exec Count : 199
Index: bolt/lib/Profile/YAMLProfileReader.cpp
===================================================================
--- bolt/lib/Profile/YAMLProfileReader.cpp
+++ bolt/lib/Profile/YAMLProfileReader.cpp
@@ -83,6 +83,14 @@
 
   BF.setExecutionCount(YamlBF.ExecCount);
 
+  uint64_t FuncRawBranchCount = 0;
+  for (const yaml::bolt::BinaryBasicBlockProfile &YamlBB : YamlBF.Blocks) {
+    for (const yaml::bolt::SuccessorInfo &YamlSI : YamlBB.Successors) {
+      FuncRawBranchCount += YamlSI.Count;
+    }
+  }
+  BF.setRawBranchCount(FuncRawBranchCount);
+
   if (!opts::IgnoreHash && YamlBF.Hash != BF.computeHash(/*UseDFS=*/true)) {
     if (opts::Verbosity >= 1)
       errs() << "BOLT-WARNING: function hash mismatch\n";
Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -471,6 +471,7 @@
   if (ExecutionCount != COUNT_NO_PROFILE) {
     OS << "\n  Exec Count  : " << ExecutionCount;
     OS << "\n  Profile Acc : " << format("%.1f%%", ProfileMatchRatio * 100.0f);
+    OS << "\n  RawBranchCount : " << RawBranchCount;
   }
 
   if (opts::PrintDynoStats && !getLayout().block_empty()) {
Index: bolt/include/bolt/Core/BinaryFunction.h
===================================================================
--- bolt/include/bolt/Core/BinaryFunction.h
+++ bolt/include/bolt/Core/BinaryFunction.h
@@ -1868,6 +1868,10 @@
   /// executions corresponding to this function.
   uint64_t getRawBranchCount() const { return RawBranchCount; }
 
+  /// Set the profile data about the number of branch executions corresponding
+  /// to this function.
+  void setRawBranchCount(uint64_t Count) { RawBranchCount = Count; }
+
   /// Return the execution count for functions with known profile.
   /// Return 0 if the function has no profile.
   uint64_t getKnownExecutionCount() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144211.507878.patch
Type: text/x-patch
Size: 2900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230323/1bf6b12c/attachment.bin>


More information about the llvm-commits mailing list