diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp b/llvm/lib/Transforms/Utils/MisExpect.cpp --- 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 #include #include #include @@ -71,7 +72,7 @@ return PGOWarnMisExpect || Ctx.getMisExpectWarningRequested(); } -uint64_t getMisExpectTolerance(LLVMContext &Ctx) { +uint32_t getMisExpectTolerance(LLVMContext &Ctx) { return std::max(static_cast(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 RealWeights, ArrayRef 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