LLVM 19.0.0git
Remark.h
Go to the documentation of this file.
1//===-- llvm/Remarks/Remark.h - The remark type -----------------*- C++/-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines an abstraction for handling remarks.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_REMARKS_REMARK_H
14#define LLVM_REMARKS_REMARK_H
15
16#include "llvm-c/Remarks.h"
18#include "llvm/ADT/StringRef.h"
21#include <optional>
22#include <string>
23
24namespace llvm {
25namespace remarks {
26
27/// The current version of the remark entry.
29
30/// The debug location used to track a remark back to the source file.
32 /// Absolute path of the source file corresponding to this remark.
34 unsigned SourceLine = 0;
35 unsigned SourceColumn = 0;
36
37 /// Implement operator<< on RemarkLocation.
38 void print(raw_ostream &OS) const;
39};
40
41// Create wrappers for C Binding types (see CBindingWrapping.h).
43
44/// A key-value pair with a debug location that is used to display the remarks
45/// at the right place in the source.
46struct Argument {
48 // FIXME: We might want to be able to store other types than strings here.
50 // If set, the debug location corresponding to the value.
51 std::optional<RemarkLocation> Loc;
52
53 /// Implement operator<< on Argument.
54 void print(raw_ostream &OS) const;
55 /// Return the value of argument as int.
56 std::optional<int> getValAsInt() const;
57 /// Check if the argument value can be parsed as int.
58 bool isValInt() const;
59};
60
61// Create wrappers for C Binding types (see CBindingWrapping.h).
63
64/// The type of the remark.
65enum class Type {
66 Unknown,
67 Passed,
68 Missed,
72 Failure,
73 First = Unknown,
75};
76
78 switch (Ty) {
79 case Type::Unknown:
80 return "Unknown";
81 case Type::Missed:
82 return "Missed";
83 case Type::Passed:
84 return "Passed";
85 case Type::Analysis:
86 return "Analysis";
88 return "AnalysisFPCommute";
90 return "AnalysisAliasing";
91 default:
92 return "Failure";
93 }
94}
95
96/// A remark type used for both emission and parsing.
97struct Remark {
98 /// The type of the remark.
100
101 /// Name of the pass that triggers the emission of this remark.
103
104 /// Textual identifier for the remark (single-word, camel-case). Can be used
105 /// by external tools reading the output file for remarks to identify the
106 /// remark.
108
109 /// Mangled name of the function that triggers the emssion of this remark.
111
112 /// The location in the source file of the remark.
113 std::optional<RemarkLocation> Loc;
114
115 /// If profile information is available, this is the number of times the
116 /// corresponding code was executed in a profile instrumentation run.
117 std::optional<uint64_t> Hotness;
118
119 /// Arguments collected via the streaming interface.
121
122 Remark() = default;
123 Remark(Remark &&) = default;
124 Remark &operator=(Remark &&) = default;
125
126 /// Return a message composed from the arguments as a string.
127 std::string getArgsAsMsg() const;
128
129 /// Clone this remark to explicitly ask for a copy.
130 Remark clone() const { return *this; }
131
132 /// Implement operator<< on Remark.
133 void print(raw_ostream &OS) const;
134
135private:
136 /// In order to avoid unwanted copies, "delete" the copy constructor.
137 /// If a copy is needed, it should be done through `Remark::clone()`.
138 Remark(const Remark &) = default;
139 Remark& operator=(const Remark &) = default;
140};
141
142// Create wrappers for C Binding types (see CBindingWrapping.h).
144
145/// Comparison operators for Remark objects and dependent objects.
146
147template <typename T>
148bool operator<(const std::optional<T> &LHS, const std::optional<T> &RHS) {
149 // Sorting based on optionals should result in all `None` entries to appear
150 // before the valid entries. For example, remarks with no debug location will
151 // appear first.
152 if (!LHS && !RHS)
153 return false;
154 if (!LHS && RHS)
155 return true;
156 if (LHS && !RHS)
157 return false;
158 return *LHS < *RHS;
159}
160
161inline bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS) {
162 return LHS.SourceFilePath == RHS.SourceFilePath &&
163 LHS.SourceLine == RHS.SourceLine &&
164 LHS.SourceColumn == RHS.SourceColumn;
165}
166
167inline bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS) {
168 return !(LHS == RHS);
169}
170
171inline bool operator<(const RemarkLocation &LHS, const RemarkLocation &RHS) {
172 return std::make_tuple(LHS.SourceFilePath, LHS.SourceLine, LHS.SourceColumn) <
173 std::make_tuple(RHS.SourceFilePath, RHS.SourceLine, RHS.SourceColumn);
174}
175
176inline bool operator==(const Argument &LHS, const Argument &RHS) {
177 return LHS.Key == RHS.Key && LHS.Val == RHS.Val && LHS.Loc == RHS.Loc;
178}
179
180inline bool operator!=(const Argument &LHS, const Argument &RHS) {
181 return !(LHS == RHS);
182}
183
184inline bool operator<(const Argument &LHS, const Argument &RHS) {
185 return std::make_tuple(LHS.Key, LHS.Val, LHS.Loc) <
186 std::make_tuple(RHS.Key, RHS.Val, RHS.Loc);
187}
188
189inline bool operator==(const Remark &LHS, const Remark &RHS) {
190 return LHS.RemarkType == RHS.RemarkType && LHS.PassName == RHS.PassName &&
191 LHS.RemarkName == RHS.RemarkName &&
192 LHS.FunctionName == RHS.FunctionName && LHS.Loc == RHS.Loc &&
193 LHS.Hotness == RHS.Hotness && LHS.Args == RHS.Args;
194}
195
196inline bool operator!=(const Remark &LHS, const Remark &RHS) {
197 return !(LHS == RHS);
198}
199
200inline bool operator<(const Remark &LHS, const Remark &RHS) {
201 return std::make_tuple(LHS.RemarkType, LHS.PassName, LHS.RemarkName,
202 LHS.FunctionName, LHS.Loc, LHS.Hotness, LHS.Args) <
203 std::make_tuple(RHS.RemarkType, RHS.PassName, RHS.RemarkName,
204 RHS.FunctionName, RHS.Loc, RHS.Hotness, RHS.Args);
205}
206
208 RLoc.print(OS);
209 return OS;
210}
211
213 Arg.print(OS);
214 return OS;
215}
216
218 Remark.print(OS);
219 return OS;
220}
221
222} // end namespace remarks
223} // end namespace llvm
224
225#endif /* LLVM_REMARKS_REMARK_H */
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
raw_pwrite_stream & OS
This file defines the SmallVector class.
Value * RHS
Value * LHS
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
struct LLVMRemarkOpaqueEntry * LLVMRemarkEntryRef
A remark emitted by the compiler.
Definition: Remarks.h:140
struct LLVMRemarkOpaqueArg * LLVMRemarkArgRef
Element of the "Args" list.
Definition: Remarks.h:109
struct LLVMRemarkOpaqueDebugLoc * LLVMRemarkDebugLocRef
DebugLoc containing File, Line and Column.
Definition: Remarks.h:78
raw_ostream & operator<<(raw_ostream &OS, const RemarkLocation &RLoc)
Definition: Remark.h:207
bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS)
Definition: Remark.h:161
StringRef typeToStr(Type Ty)
Definition: Remark.h:77
bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS)
Definition: Remark.h:167
constexpr uint64_t CurrentRemarkVersion
The current version of the remark entry.
Definition: Remark.h:28
bool operator<(const std::optional< T > &LHS, const std::optional< T > &RHS)
Comparison operators for Remark objects and dependent objects.
Definition: Remark.h:148
Type
The type of the remark.
Definition: Remark.h:65
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
A key-value pair with a debug location that is used to display the remarks at the right place in the ...
Definition: Remark.h:46
void print(raw_ostream &OS) const
Implement operator<< on Argument.
Definition: Remark.cpp:45
std::optional< RemarkLocation > Loc
Definition: Remark.h:51
The debug location used to track a remark back to the source file.
Definition: Remark.h:31
void print(raw_ostream &OS) const
Implement operator<< on RemarkLocation.
Definition: Remark.cpp:39
StringRef SourceFilePath
Absolute path of the source file corresponding to this remark.
Definition: Remark.h:33
A remark type used for both emission and parsing.
Definition: Remark.h:97
void print(raw_ostream &OS) const
Implement operator<< on Remark.
Definition: Remark.cpp:49
Type RemarkType
The type of the remark.
Definition: Remark.h:99
StringRef PassName
Name of the pass that triggers the emission of this remark.
Definition: Remark.h:102
std::optional< RemarkLocation > Loc
The location in the source file of the remark.
Definition: Remark.h:113
std::optional< uint64_t > Hotness
If profile information is available, this is the number of times the corresponding code was executed ...
Definition: Remark.h:117
Remark(Remark &&)=default
StringRef RemarkName
Textual identifier for the remark (single-word, camel-case).
Definition: Remark.h:107
Remark clone() const
Clone this remark to explicitly ask for a copy.
Definition: Remark.h:130
std::string getArgsAsMsg() const
Return a message composed from the arguments as a string.
Definition: Remark.cpp:21
StringRef FunctionName
Mangled name of the function that triggers the emssion of this remark.
Definition: Remark.h:110
Remark & operator=(Remark &&)=default
SmallVector< Argument, 5 > Args
Arguments collected via the streaming interface.
Definition: Remark.h:120