[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
Wed Aug 17 08:40:06 PDT 2022
jloser updated this revision to Diff 453295.
jloser added a comment.
Rebase since D131869 <https://reviews.llvm.org/D131869> landed. Remove use of `static_cast` for the tolerance.
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,8 +72,8 @@
return PGOWarnMisExpect || Ctx.getMisExpectWarningRequested();
}
-uint64_t getMisExpectTolerance(LLVMContext &Ctx) {
- return std::max(static_cast<uint32_t>(MisExpectTolerance),
+uint32_t getMisExpectTolerance(LLVMContext &Ctx) {
+ return std::max(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.453295.patch
Type: text/x-patch
Size: 1604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220817/a84dc210/attachment.bin>
More information about the llvm-commits
mailing list