File indexing completed on 2026-05-10 08:44:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_REMARKS_REMARK_H
0014 #define LLVM_REMARKS_REMARK_H
0015
0016 #include "llvm-c/Remarks.h"
0017 #include "llvm/ADT/SmallVector.h"
0018 #include "llvm/ADT/StringRef.h"
0019 #include "llvm/Support/CBindingWrapping.h"
0020 #include "llvm/Support/raw_ostream.h"
0021 #include <optional>
0022 #include <string>
0023
0024 namespace llvm {
0025 namespace remarks {
0026
0027
0028 constexpr uint64_t CurrentRemarkVersion = 0;
0029
0030
0031 struct RemarkLocation {
0032
0033 StringRef SourceFilePath;
0034 unsigned SourceLine = 0;
0035 unsigned SourceColumn = 0;
0036
0037
0038 void print(raw_ostream &OS) const;
0039 };
0040
0041
0042 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkLocation, LLVMRemarkDebugLocRef)
0043
0044
0045
0046 struct Argument {
0047 StringRef Key;
0048
0049 StringRef Val;
0050
0051 std::optional<RemarkLocation> Loc;
0052
0053
0054 void print(raw_ostream &OS) const;
0055
0056 std::optional<int> getValAsInt() const;
0057
0058 bool isValInt() const;
0059 };
0060
0061
0062 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Argument, LLVMRemarkArgRef)
0063
0064
0065 enum class Type {
0066 Unknown,
0067 Passed,
0068 Missed,
0069 Analysis,
0070 AnalysisFPCommute,
0071 AnalysisAliasing,
0072 Failure,
0073 First = Unknown,
0074 Last = Failure
0075 };
0076
0077 inline StringRef typeToStr(Type Ty) {
0078 switch (Ty) {
0079 case Type::Unknown:
0080 return "Unknown";
0081 case Type::Missed:
0082 return "Missed";
0083 case Type::Passed:
0084 return "Passed";
0085 case Type::Analysis:
0086 return "Analysis";
0087 case Type::AnalysisFPCommute:
0088 return "AnalysisFPCommute";
0089 case Type::AnalysisAliasing:
0090 return "AnalysisAliasing";
0091 default:
0092 return "Failure";
0093 }
0094 }
0095
0096
0097 struct Remark {
0098
0099 Type RemarkType = Type::Unknown;
0100
0101
0102 StringRef PassName;
0103
0104
0105
0106
0107 StringRef RemarkName;
0108
0109
0110 StringRef FunctionName;
0111
0112
0113 std::optional<RemarkLocation> Loc;
0114
0115
0116
0117 std::optional<uint64_t> Hotness;
0118
0119
0120 SmallVector<Argument, 5> Args;
0121
0122 Remark() = default;
0123 Remark(Remark &&) = default;
0124 Remark &operator=(Remark &&) = default;
0125
0126
0127 std::string getArgsAsMsg() const;
0128
0129
0130 Remark clone() const { return *this; }
0131
0132
0133 void print(raw_ostream &OS) const;
0134
0135 private:
0136
0137
0138 Remark(const Remark &) = default;
0139 Remark& operator=(const Remark &) = default;
0140 };
0141
0142
0143 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Remark, LLVMRemarkEntryRef)
0144
0145
0146
0147 template <typename T>
0148 bool operator<(const std::optional<T> &LHS, const std::optional<T> &RHS) {
0149
0150
0151
0152 if (!LHS && !RHS)
0153 return false;
0154 if (!LHS && RHS)
0155 return true;
0156 if (LHS && !RHS)
0157 return false;
0158 return *LHS < *RHS;
0159 }
0160
0161 inline bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS) {
0162 return LHS.SourceFilePath == RHS.SourceFilePath &&
0163 LHS.SourceLine == RHS.SourceLine &&
0164 LHS.SourceColumn == RHS.SourceColumn;
0165 }
0166
0167 inline bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS) {
0168 return !(LHS == RHS);
0169 }
0170
0171 inline bool operator<(const RemarkLocation &LHS, const RemarkLocation &RHS) {
0172 return std::make_tuple(LHS.SourceFilePath, LHS.SourceLine, LHS.SourceColumn) <
0173 std::make_tuple(RHS.SourceFilePath, RHS.SourceLine, RHS.SourceColumn);
0174 }
0175
0176 inline bool operator==(const Argument &LHS, const Argument &RHS) {
0177 return LHS.Key == RHS.Key && LHS.Val == RHS.Val && LHS.Loc == RHS.Loc;
0178 }
0179
0180 inline bool operator!=(const Argument &LHS, const Argument &RHS) {
0181 return !(LHS == RHS);
0182 }
0183
0184 inline bool operator<(const Argument &LHS, const Argument &RHS) {
0185 return std::make_tuple(LHS.Key, LHS.Val, LHS.Loc) <
0186 std::make_tuple(RHS.Key, RHS.Val, RHS.Loc);
0187 }
0188
0189 inline bool operator==(const Remark &LHS, const Remark &RHS) {
0190 return LHS.RemarkType == RHS.RemarkType && LHS.PassName == RHS.PassName &&
0191 LHS.RemarkName == RHS.RemarkName &&
0192 LHS.FunctionName == RHS.FunctionName && LHS.Loc == RHS.Loc &&
0193 LHS.Hotness == RHS.Hotness && LHS.Args == RHS.Args;
0194 }
0195
0196 inline bool operator!=(const Remark &LHS, const Remark &RHS) {
0197 return !(LHS == RHS);
0198 }
0199
0200 inline bool operator<(const Remark &LHS, const Remark &RHS) {
0201 return std::make_tuple(LHS.RemarkType, LHS.PassName, LHS.RemarkName,
0202 LHS.FunctionName, LHS.Loc, LHS.Hotness, LHS.Args) <
0203 std::make_tuple(RHS.RemarkType, RHS.PassName, RHS.RemarkName,
0204 RHS.FunctionName, RHS.Loc, RHS.Hotness, RHS.Args);
0205 }
0206
0207 inline raw_ostream &operator<<(raw_ostream &OS, const RemarkLocation &RLoc) {
0208 RLoc.print(OS);
0209 return OS;
0210 }
0211
0212 inline raw_ostream &operator<<(raw_ostream &OS, const Argument &Arg) {
0213 Arg.print(OS);
0214 return OS;
0215 }
0216
0217 inline raw_ostream &operator<<(raw_ostream &OS, const Remark &Remark) {
0218 Remark.print(OS);
0219 return OS;
0220 }
0221
0222 }
0223 }
0224
0225 #endif