[llvm] f3a55a1 - [llvm] Remove std::clamp equivalent in `Transforms/Utils/MisExpect.cpp`
Joe Loser via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 18 14:12:17 PDT 2022
Author: Joe Loser
Date: 2022-08-18T15:11:25-06:00
New Revision: f3a55a1ddfe3ba2ae08d49a98405dadf44ebfd37
URL: https://github.com/llvm/llvm-project/commit/f3a55a1ddfe3ba2ae08d49a98405dadf44ebfd37
DIFF: https://github.com/llvm/llvm-project/commit/f3a55a1ddfe3ba2ae08d49a98405dadf44ebfd37.diff
LOG: [llvm] Remove std::clamp equivalent in `Transforms/Utils/MisExpect.cpp`
Use `std::clamp` directly from the standard library now that LLVM is built with
C++17 standards mode.
Differential Revision: https://reviews.llvm.org/D131869
Added:
Modified:
llvm/lib/Transforms/Utils/MisExpect.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp b/llvm/lib/Transforms/Utils/MisExpect.cpp
index 28649b083f3b3..6dbeaaad8d14e 100644
--- a/llvm/lib/Transforms/Utils/MisExpect.cpp
+++ b/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 @@ bool isMisExpectDiagEnabled(LLVMContext &Ctx) {
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 @@ void emitMisexpectDiagnostic(Instruction *I, LLVMContext &Ctx,
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 @@ void verifyMisExpect(Instruction &I, ArrayRef<uint32_t> RealWeights,
// 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
More information about the llvm-commits
mailing list