[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
Sun Aug 14 20:16:00 PDT 2022


jloser created this revision.
jloser added a reviewer: paulkirth.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Use `std::clamp` directly from the standard library now that LLVM is built with
C++17 standards mode.


Repository:
  rG LLVM Github Monorepo

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>
@@ -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, 0, 99);
 
   // 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.452582.patch
Type: text/x-patch
Size: 1243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220815/62898da1/attachment.bin>


More information about the llvm-commits mailing list