File indexing completed on 2026-05-10 08:44:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_REMARKS_HOTNESSTHRESHOLDPARSER_H
0016 #define LLVM_REMARKS_HOTNESSTHRESHOLDPARSER_H
0017
0018 #include "llvm/Support/CommandLine.h"
0019 #include "llvm/Support/Error.h"
0020 #include <optional>
0021
0022 namespace llvm {
0023 namespace remarks {
0024
0025
0026
0027
0028
0029
0030
0031
0032 inline Expected<std::optional<uint64_t>> parseHotnessThresholdOption(StringRef Arg) {
0033 if (Arg == "auto")
0034 return std::nullopt;
0035
0036 int64_t Val;
0037 if (Arg.getAsInteger(10, Val))
0038 return createStringError(llvm::inconvertibleErrorCode(),
0039 "Not an integer: %s", Arg.data());
0040
0041
0042 return Val < 0 ? 0 : Val;
0043 }
0044
0045
0046 class HotnessThresholdParser : public cl::parser<std::optional<uint64_t>> {
0047 public:
0048 HotnessThresholdParser(cl::Option &O) : cl::parser<std::optional<uint64_t>>(O) {}
0049
0050 bool parse(cl::Option &O, StringRef ArgName, StringRef Arg,
0051 std::optional<uint64_t> &V) {
0052 auto ResultOrErr = parseHotnessThresholdOption(Arg);
0053 if (!ResultOrErr)
0054 return O.error("Invalid argument '" + Arg +
0055 "', only integer or 'auto' is supported.");
0056
0057 V = *ResultOrErr;
0058 return false;
0059 }
0060 };
0061
0062 }
0063 }
0064 #endif