[llvm] [BFI] Compute the minimum frequency only when dumping. NFC (PR #212957)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 01:34:18 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/212957
None
>From 92cceacb61db44a20163634760e2685d1a2684b3 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 29 Jul 2026 23:52:41 -0700
Subject: [PATCH] [BFI] Compute the minimum frequency only when dumping. NFC
---
llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp | 29 +++++++++-----------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
index 1e7d7c9ce8d51..4680af8f50c2b 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
@@ -479,8 +479,11 @@ void BlockFrequencyInfoImplBase::distributeMass(const BlockNode &Source,
}
}
-static void convertFloatingToInteger(BlockFrequencyInfoImplBase &BFI,
- const Scaled64 &Min, const Scaled64 &Max) {
+static void convertFloatingToInteger(BlockFrequencyInfoImplBase &BFI) {
+ auto Max = Scaled64::getZero();
+ for (const FrequencyData &F : BFI.Freqs)
+ Max = std::max(Max, F.Scaled);
+
// Scale the Factor to a size that creates integers. If possible scale
// integers so that Max == UINT64_MAX so that they can be best differentiated.
// It is possible that the range between min and max cannot be accurately
@@ -496,9 +499,13 @@ static void convertFloatingToInteger(BlockFrequencyInfoImplBase &BFI,
Scaled64 ScalingFactor = Scaled64(1, MaxBits - Slack) / Max;
// Translate the floats to integers.
- LLVM_DEBUG(dbgs() << "float-to-int: min = " << Min << ", max = " << Max
- << ", factor = " << ScalingFactor << "\n");
- (void)Min;
+ LLVM_DEBUG({
+ auto Min = Scaled64::getLargest();
+ for (const FrequencyData &F : BFI.Freqs)
+ Min = std::min(Min, F.Scaled);
+ dbgs() << "float-to-int: min = " << Min << ", max = " << Max
+ << ", factor = " << ScalingFactor << "\n";
+ });
for (size_t Index = 0; Index < BFI.Freqs.size(); ++Index) {
Scaled64 Scaled = BFI.Freqs[Index].Scaled * ScalingFactor;
BFI.Freqs[Index].Integer = std::max(UINT64_C(1), Scaled.toInt<uint64_t>());
@@ -544,18 +551,8 @@ void BlockFrequencyInfoImplBase::unwrapLoops() {
}
void BlockFrequencyInfoImplBase::finalizeMetrics() {
- // Unwrap loop packages in reverse post-order, tracking min and max
- // frequencies.
- auto Min = Scaled64::getLargest();
- auto Max = Scaled64::getZero();
- for (size_t Index = 0; Index < Working.size(); ++Index) {
- // Update min/max scale.
- Min = std::min(Min, Freqs[Index].Scaled);
- Max = std::max(Max, Freqs[Index].Scaled);
- }
-
// Convert to integers.
- convertFloatingToInteger(*this, Min, Max);
+ convertFloatingToInteger(*this);
// Clean up data structures.
cleanup(*this);
More information about the llvm-commits
mailing list