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