https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/139193

>From 0d16d90e829f7ce753abb5e50eca8e46a80872dc Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aau...@fb.com>
Date: Fri, 9 May 2025 14:48:04 -0700
Subject: [PATCH] update

Created using spr 1.3.4
---
 bolt/lib/Profile/Heatmap.cpp      | 35 ++++++++++++++-----------------
 bolt/test/X86/heatmap-preagg.test | 24 ++++++++++-----------
 2 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/bolt/lib/Profile/Heatmap.cpp b/bolt/lib/Profile/Heatmap.cpp
index dd73f3a13a9d3..7b74c44427cb8 100644
--- a/bolt/lib/Profile/Heatmap.cpp
+++ b/bolt/lib/Profile/Heatmap.cpp
@@ -297,7 +297,7 @@ void Heatmap::printSectionHotness(StringRef FileName) const 
{
 void Heatmap::printSectionHotness(raw_ostream &OS) const {
   uint64_t NumTotalCounts = 0;
   StringMap<uint64_t> SectionHotness;
-  StringMap<uint64_t> SectionUtilization;
+  StringMap<uint64_t> BucketUtilization;
   unsigned TextSectionIndex = 0;
 
   if (TextSections.empty())
@@ -312,42 +312,39 @@ void Heatmap::printSectionHotness(raw_ostream &OS) const {
     UnmappedHotness += Frequency;
   };
 
-  for (const auto [Bucket, Count] : Map) {
-    NumTotalCounts += Count;
+  for (const std::pair<const uint64_t, uint64_t> &KV : Map) {
+    NumTotalCounts += KV.second;
     // We map an address bucket to the first section (lowest address)
     // overlapping with that bucket.
-    auto Address = Bucket * BucketSize;
+    auto Address = KV.first * BucketSize;
     while (TextSectionIndex < TextSections.size() &&
            Address >= TextSections[TextSectionIndex].EndAddress)
       TextSectionIndex++;
     if (TextSectionIndex >= TextSections.size() ||
         Address + BucketSize < TextSections[TextSectionIndex].BeginAddress) {
-      RecordUnmappedBucket(Address, Count);
+      RecordUnmappedBucket(Address, KV.second);
       continue;
     }
-    StringRef Name = TextSections[TextSectionIndex].Name;
-    SectionHotness[Name] += Count;
-    ++SectionUtilization[Name];
+    SectionHotness[TextSections[TextSectionIndex].Name] += KV.second;
+    ++BucketUtilization[TextSections[TextSectionIndex].Name];
   }
 
-  auto getNumBuckets = [&](uint64_t Begin, uint64_t End) {
-    return End / BucketSize + !!(End % BucketSize) - Begin / BucketSize;
-  };
-
   assert(NumTotalCounts > 0 &&
          "total number of heatmap buckets should be greater than 0");
 
   OS << "Section Name, Begin Address, End Address, Percentage Hotness, "
-     << "Utilization Pct\n";
+     << "Utilization Pct, Partition Score\n";
   for (const auto [Name, Begin, End] : TextSections) {
-    const float RelHotness = 100. * SectionHotness[Name] / NumTotalCounts;
-    const float BucketUtilization =
-        100. * SectionUtilization[Name] / getNumBuckets(Begin, End);
-    OS << formatv("{0}, {1:x}, {2:x}, {3:f4}, {4:f4}\n", Name, Begin, End,
-                  RelHotness, BucketUtilization);
+    const float Hotness = 1. * SectionHotness[Name] / NumTotalCounts;
+    const uint64_t NumBuckets =
+        End / BucketSize + !!(End % BucketSize) - Begin / BucketSize;
+    const float Utilization = 1. * BucketUtilization[Name] / NumBuckets;
+    const float PartitionScore = Hotness * Utilization;
+    OS << formatv("{0}, {1:x}, {2:x}, {3:f4}, {4:f4}, {5:f4}\n", Name, Begin,
+                  End, 100. * Hotness, 100. * Utilization, PartitionScore);
   }
   if (UnmappedHotness > 0)
-    OS << formatv("[unmapped], 0x0, 0x0, {0:f4}, 0\n",
+    OS << formatv("[unmapped], 0x0, 0x0, {0:f4}, 0, 0\n",
                   100.0 * UnmappedHotness / NumTotalCounts);
 }
 } // namespace bolt
diff --git a/bolt/test/X86/heatmap-preagg.test 
b/bolt/test/X86/heatmap-preagg.test
index 660d37fd03cbe..48f1683892881 100644
--- a/bolt/test/X86/heatmap-preagg.test
+++ b/bolt/test/X86/heatmap-preagg.test
@@ -17,19 +17,19 @@ RUN: FileCheck %s --check-prefix CHECK-SEC-HOT-BAT 
--input-file %t2-section-hotn
 CHECK-HEATMAP: PERF2BOLT: read 81 aggregated LBR entries
 CHECK-HEATMAP: HEATMAP: invalid traces: 1
 
-CHECK-SEC-HOT: Section Name, Begin Address, End Address, Percentage Hotness, 
Utilization Pct
-CHECK-SEC-HOT-NEXT: .init, 0x401000, 0x40101b, 16.8545, 100.0000
-CHECK-SEC-HOT-NEXT: .plt, 0x401020, 0x4010b0, 4.7583, 66.6667
-CHECK-SEC-HOT-NEXT: .text, 0x4010b0, 0x401c25, 78.3872, 85.1064
-CHECK-SEC-HOT-NEXT: .fini, 0x401c28, 0x401c35, 0.0000, 0.0000
+CHECK-SEC-HOT: Section Name, Begin Address, End Address, Percentage Hotness, 
Utilization Pct, Partition Score
+CHECK-SEC-HOT-NEXT: .init, 0x401000, 0x40101b, 16.8545, 100.0000, 0.1685
+CHECK-SEC-HOT-NEXT: .plt, 0x401020, 0x4010b0, 4.7583, 66.6667, 0.0317
+CHECK-SEC-HOT-NEXT: .text, 0x4010b0, 0x401c25, 78.3872, 85.1064, 0.6671
+CHECK-SEC-HOT-NEXT: .fini, 0x401c28, 0x401c35, 0.0000, 0.0000, 0.0000
 
 CHECK-HEATMAP-BAT: PERF2BOLT: read 79 aggregated LBR entries
 CHECK-HEATMAP-BAT: HEATMAP: invalid traces: 2
 
-CHECK-SEC-HOT-BAT: Section Name, Begin Address, End Address, Percentage 
Hotness, Utilization Pct
-CHECK-SEC-HOT-BAT-NEXT: .init, 0x401000, 0x40101b, 17.2888, 100.0000
-CHECK-SEC-HOT-BAT-NEXT: .plt, 0x401020, 0x4010b0, 5.6132, 66.6667
-CHECK-SEC-HOT-BAT-NEXT: .bolt.org.text, 0x4010b0, 0x401c25, 38.3385
-CHECK-SEC-HOT-BAT-NEXT: .fini, 0x401c28, 0x401c35, 0.0000, 0.0000
-CHECK-SEC-HOT-BAT-NEXT: .text, 0x800000, 0x8002cc, 38.7595, 91.6667
-CHECK-SEC-HOT-BAT-NEXT: .text.cold, 0x800300, 0x800415, 0.0000, 0.0000
+CHECK-SEC-HOT-BAT: Section Name, Begin Address, End Address, Percentage 
Hotness, Utilization Pct, Partition Score
+CHECK-SEC-HOT-BAT-NEXT: .init, 0x401000, 0x40101b, 17.2888, 100.0000, 0.1729
+CHECK-SEC-HOT-BAT-NEXT: .plt, 0x401020, 0x4010b0, 5.6132, 66.6667, 0.0374
+CHECK-SEC-HOT-BAT-NEXT: .bolt.org.text, 0x4010b0, 0x401c25, 38.3385, 0.1958
+CHECK-SEC-HOT-BAT-NEXT: .fini, 0x401c28, 0x401c35, 0.0000, 0.0000, 0.0000
+CHECK-SEC-HOT-BAT-NEXT: .text, 0x800000, 0x8002cc, 38.7595, 91.6667, 0.3553
+CHECK-SEC-HOT-BAT-NEXT: .text.cold, 0x800300, 0x800415, 0.0000, 0.0000, 0.0000

_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to