LLVM: include/llvm/Remarks/Remark.h Source File

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"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/CBindingWrapping.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/Support/raw_ostream.h"
22#include <optional>
23#include <string>
24
25namespace llvm {
26namespace remarks {
27
28/// The current version of the remark entry.
29 constexpr uint64_t CurrentRemarkVersion = 0;
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).
43DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkLocation, LLVMRemarkDebugLocRef)
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.
47 struct 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 Argument() = default;
56
57 /// Implement operator<< on Argument.
58 LLVM_ABI void print(raw_ostream &OS) const;
59
60 /// Return the value of argument as an integer of type T.
61 template <typename T>
62 std::optional<T> getValAsInt(unsigned Radix = 10) const {
63 StringRef Str = Val;
64 T Res;
65 if (Str.consumeInteger<T>(Radix, Res) || !Str.empty())
66 return std::nullopt;
67 return Res;
68 }
69};
70
71// Create wrappers for C Binding types (see CBindingWrapping.h).
72DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Argument, LLVMRemarkArgRef)
73
74/// The type of the remark.
86
88 switch (Ty) {
89 case Type::Unknown:
90 return "Unknown";
91 case Type::Missed:
92 return "Missed";
93 case Type::Passed:
94 return "Passed";
95 case Type::Analysis:
96 return "Analysis";
98 return "AnalysisFPCommute";
100 return "AnalysisAliasing";
101 default:
102 return "Failure";
103 }
104}
105
106/// A remark type used for both emission and parsing.
107 struct Remark {
108 /// The type of the remark.
110
111 /// Name of the pass that triggers the emission of this remark.
113
114 /// Textual identifier for the remark (single-word, camel-case). Can be used
115 /// by external tools reading the output file for remarks to identify the
116 /// remark.
118
119 /// Mangled name of the function that triggers the emssion of this remark.
121
122 /// The location in the source file of the remark.
123 std::optional<RemarkLocation> Loc;
124
125 /// If profile information is available, this is the number of times the
126 /// corresponding code was executed in a profile instrumentation run.
127 std::optional<uint64_t> Hotness;
128
129 /// Arguments collected via the streaming interface.
131
132 Remark() = default;
133 Remark(Remark &&) = default;
134 Remark &operator=(Remark &&) = default;
135
136 /// Return a message composed from the arguments as a string.
137 LLVM_ABI std::string getArgsAsMsg() const;
138
139 /// Return the first argument with the specified key or nullptr if no such
140 /// argument was found.
142
143 /// Clone this remark to explicitly ask for a copy.
144 Remark clone() const { return *this; }
145
146 /// Implement operator<< on Remark.
147 LLVM_ABI void print(raw_ostream &OS) const;
148
149private:
150 /// In order to avoid unwanted copies, "delete" the copy constructor.
151 /// If a copy is needed, it should be done through `Remark::clone()`.
152 Remark(const Remark &) = default;
153 Remark& operator=(const Remark &) = default;
154};
155
156// Create wrappers for C Binding types (see CBindingWrapping.h).
157DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Remark, LLVMRemarkEntryRef)
158
159/// Comparison operators for Remark objects and dependent objects.
160
161template <typename T>
162 bool operator<(const std::optional<T> &LHS, const std::optional<T> &RHS) {
163 // Sorting based on optionals should result in all `None` entries to appear
164 // before the valid entries. For example, remarks with no debug location will
165 // appear first.
166 if (!LHS && !RHS)
167 return false;
168 if (!LHS && RHS)
169 return true;
170 if (LHS && !RHS)
171 return false;
172 return *LHS < *RHS;
173}
174
175 inline bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS) {
176 return LHS.SourceFilePath == RHS.SourceFilePath &&
177 LHS.SourceLine == RHS.SourceLine &&
178 LHS.SourceColumn == RHS.SourceColumn;
179}
180
181 inline bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS) {
182 return !(LHS == RHS);
183}
184
185 inline bool operator<(const RemarkLocation &LHS, const RemarkLocation &RHS) {
186 return std::make_tuple(LHS.SourceFilePath, LHS.SourceLine, LHS.SourceColumn) <
187 std::make_tuple(RHS.SourceFilePath, RHS.SourceLine, RHS.SourceColumn);
188}
189
190 inline bool operator==(const Argument &LHS, const Argument &RHS) {
191 return LHS.Key == RHS.Key && LHS.Val == RHS.Val && LHS.Loc == RHS.Loc;
192}
193
194 inline bool operator!=(const Argument &LHS, const Argument &RHS) {
195 return !(LHS == RHS);
196}
197
198 inline bool operator<(const Argument &LHS, const Argument &RHS) {
199 return std::make_tuple(LHS.Key, LHS.Val, LHS.Loc) <
200 std::make_tuple(RHS.Key, RHS.Val, RHS.Loc);
201}
202
203 inline bool operator==(const Remark &LHS, const Remark &RHS) {
204 return LHS.RemarkType == RHS.RemarkType && LHS.PassName == RHS.PassName &&
205 LHS.RemarkName == RHS.RemarkName &&
206 LHS.FunctionName == RHS.FunctionName && LHS.Loc == RHS.Loc &&
207 LHS.Hotness == RHS.Hotness && LHS.Args == RHS.Args;
208}
209
210 inline bool operator!=(const Remark &LHS, const Remark &RHS) {
211 return !(LHS == RHS);
212}
213
214 inline bool operator<(const Remark &LHS, const Remark &RHS) {
215 return std::make_tuple(LHS.RemarkType, LHS.PassName, LHS.RemarkName,
216 LHS.FunctionName, LHS.Loc, LHS.Hotness, LHS.Args) <
217 std::make_tuple(RHS.RemarkType, RHS.PassName, RHS.RemarkName,
218 RHS.FunctionName, RHS.Loc, RHS.Hotness, RHS.Args);
219}
220
222 RLoc.print(OS);
223 return OS;
224}
225
226 inline raw_ostream &operator<<(raw_ostream &OS, const Argument &Arg) {
227 Arg.print(OS);
228 return OS;
229}
230
232 Remark.print(OS);
233 return OS;
234}
235
236} // end namespace remarks
237} // end namespace llvm
238
239#endif /* LLVM_REMARKS_REMARK_H */
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
#define LLVM_ABI
Definition Compiler.h:213
T
#define T
This file defines the SmallVector class.
Value * RHS
Value * LHS
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition SmallVector.h:1203
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:221
bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS)
Definition Remark.h:175
StringRef typeToStr(Type Ty)
Definition Remark.h:87
bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS)
Definition Remark.h:181
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:162
Type
The type of the remark.
Definition Remark.h:75
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)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Definition PassManager.h:668
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
Argument(StringRef Key, StringRef Val)
Definition Remark.h:55
StringRef Key
Definition Remark.h:48
LLVM_ABI void print(raw_ostream &OS) const
Implement operator<< on Argument.
Definition Remark.cpp:43
StringRef Val
Definition Remark.h:50
std::optional< RemarkLocation > Loc
Definition Remark.h:52
std::optional< T > getValAsInt(unsigned Radix=10) const
Return the value of argument as an integer of type T.
Definition Remark.h:62
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:37
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:107
LLVM_ABI void print(raw_ostream &OS) const
Implement operator<< on Remark.
Definition Remark.cpp:47
Type RemarkType
The type of the remark.
Definition Remark.h:109
StringRef PassName
Name of the pass that triggers the emission of this remark.
Definition Remark.h:112
std::optional< RemarkLocation > Loc
The location in the source file of the remark.
Definition Remark.h:123
std::optional< uint64_t > Hotness
If profile information is available, this is the number of times the corresponding code was executed ...
Definition Remark.h:127
Remark(Remark &&)=default
StringRef RemarkName
Textual identifier for the remark (single-word, camel-case).
Definition Remark.h:117
Remark clone() const
Clone this remark to explicitly ask for a copy.
Definition Remark.h:144
LLVM_ABI std::string getArgsAsMsg() const
Return a message composed from the arguments as a string.
Definition Remark.cpp:22
StringRef FunctionName
Mangled name of the function that triggers the emssion of this remark.
Definition Remark.h:120
LLVM_ABI Argument * getArgByKey(StringRef Key)
Return the first argument with the specified key or nullptr if no such argument was found.
Definition Remark.cpp:30
Remark & operator=(Remark &&)=default
SmallVector< Argument, 5 > Args
Arguments collected via the streaming interface.
Definition Remark.h:130

Generated on for LLVM by doxygen 1.14.0

AltStyle によって変換されたページ (->オリジナル) /