[PATCH] D131869: [llvm] Remove std::clamp equivalent in `Transforms/Utils/MisExpect.cpp`

Joe Loser via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 14:12:26 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGf3a55a1ddfe3: [llvm] Remove std::clamp equivalent in `Transforms/Utils/MisExpect.cpp` (authored by joe_loser).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131869

Files:
  llvm/lib/Transforms/Utils/MisExpect.cpp


Index: llvm/lib/Transforms/Utils/MisExpect.cpp
===================================================================
--- llvm/lib/Transforms/Utils/MisExpect.cpp
+++ llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FormatVariadic.h"
+#include <algorithm>
 #include <cstdint>
 #include <functional>
 #include <numeric>
@@ -71,7 +72,7 @@
   return PGOWarnMisExpect || Ctx.getMisExpectWarningRequested();
 }
 
-uint64_t getMisExpectTolerance(LLVMContext &Ctx) {
+uint32_t getMisExpectTolerance(LLVMContext &Ctx) {
   return std::max(static_cast<uint32_t>(MisExpectTolerance),
                   Ctx.getDiagnosticsMisExpectTolerance());
 }
@@ -119,15 +120,6 @@
 namespace llvm {
 namespace misexpect {
 
-// TODO: when clang allows c++17, use std::clamp instead
-uint32_t clamp(uint64_t value, uint32_t low, uint32_t hi) {
-  if (value > hi)
-    return hi;
-  if (value < low)
-    return low;
-  return value;
-}
-
 void verifyMisExpect(Instruction &I, ArrayRef<uint32_t> RealWeights,
                      ArrayRef<uint32_t> ExpectedWeights) {
   // To determine if we emit a diagnostic, we need to compare the branch weights
@@ -176,7 +168,7 @@
 
   // clamp tolerance range to [0, 100)
   auto Tolerance = getMisExpectTolerance(I.getContext());
-  Tolerance = clamp(Tolerance, 0, 99);
+  Tolerance = std::clamp(Tolerance, 0u, 99u);
 
   // Allow users to relax checking by N%  i.e., if they use a 5% tolerance,
   // then we check against 0.95*ScaledThreshold


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131869.453781.patch
Type: text/x-patch
Size: 1563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220818/982a1532/attachment.bin>


More information about the llvm-commits mailing list