[llvm] [Analysis] Use std::clamp in getHeatColor (NFC) (PR #165394)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 28 07:10:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch uses std::clamp to simplify manual clamping in
getHeatColor.
---
Full diff: https://github.com/llvm/llvm-project/pull/165394.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/HeatUtils.cpp (+1-4)
``````````diff
diff --git a/llvm/lib/Analysis/HeatUtils.cpp b/llvm/lib/Analysis/HeatUtils.cpp
index a1cc7071f0e22..08e9428059e7e 100644
--- a/llvm/lib/Analysis/HeatUtils.cpp
+++ b/llvm/lib/Analysis/HeatUtils.cpp
@@ -64,10 +64,7 @@ std::string llvm::getHeatColor(uint64_t Freq, uint64_t MaxFreq) {
}
std::string llvm::getHeatColor(double Percent) {
- if (Percent > 1.0)
- Percent = 1.0;
- if (Percent < 0.0)
- Percent = 0.0;
+ Percent = std::clamp(Percent, 0.0, 1.0);
unsigned ColorID = unsigned(round(Percent * (HeatSize - 1.0)));
return HeatPalette[ColorID];
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/165394
More information about the llvm-commits
mailing list