MLIR 22.0.0git
Remarks.h
Go to the documentation of this file.
1//===- Remarks.h - MLIR Optimization Remark ----------------------*- 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 utilities for emitting optimization remarks.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_IR_REMARKS_H
14#define MLIR_IR_REMARKS_H
15
16#include "llvm/ADT/StringExtras.h"
17#include "llvm/IR/DiagnosticInfo.h"
18#include "llvm/Remarks/Remark.h"
19#include "llvm/Support/FormatVariadic.h"
20#include "llvm/Support/Regex.h"
21
22#include "mlir/IR/Diagnostics.h"
23#include "mlir/IR/MLIRContext.h"
24#include "mlir/IR/Value.h"
25
26namespace mlir::remark {
27
28/// Define an the set of categories to accept. By default none are, the provided
29/// regex matches against the category names for each kind of remark.
31 std::optional<std::string> all, passed, missed, analysis, failed;
32};
33
34/// Categories describe the outcome of an transformation, not the mechanics of
35/// emitting/serializing remarks.
36enum class RemarkKind {
38
39 /// An optimization was applied.
41
42 /// A profitable optimization opportunity was found but not applied.
44
45 /// The compiler attempted the optimization but failed (e.g., legality
46 /// checks, or better opportunites).
48
49 /// Informational context (e.g., analysis numbers) without a pass/fail
50 /// outcome.
52};
53
54using namespace llvm;
55
56/// Options to create a Remark
57struct RemarkOpts {
58 StringRef remarkName; // Identifiable name
59 StringRef categoryName; // Category name (subject to regex filtering)
60 StringRef subCategoryName; // Subcategory name
61 StringRef functionName; // Function name if available
62
63 // Construct RemarkOpts from a remark name.
64 static constexpr RemarkOpts name(StringRef n) {
65 return RemarkOpts{n, {}, {}, {}};
66 }
67 /// Return a copy with the category set.
68 constexpr RemarkOpts category(StringRef v) const {
70 }
71 /// Return a copy with the subcategory set.
72 constexpr RemarkOpts subCategory(StringRef v) const {
74 }
75 /// Return a copy with the function name set.
76 constexpr RemarkOpts function(StringRef v) const {
78 }
79};
80
81} // namespace mlir::remark
82
83namespace mlir::remark::detail {
84//===----------------------------------------------------------------------===//
85// Remark Base Class
86//===----------------------------------------------------------------------===//
87class Remark {
88
89public:
91 RemarkOpts opts)
95 if (!categoryName.empty() && !subCategoryName.empty()) {
96 (llvm::Twine(categoryName) + ":" + subCategoryName)
97 .toStringRef(fullCategoryName);
98 }
99 }
100
101 // Remark argument that is a key-value pair that can be printed as machine
102 // parsable args.
103 struct Arg {
104 std::string key;
105 std::string val;
106 Arg(llvm::StringRef m) : key("Remark"), val(m) {}
107 Arg(llvm::StringRef k, llvm::StringRef v) : key(k), val(v) {}
108 Arg(llvm::StringRef k, std::string v) : key(k), val(std::move(v)) {}
109 Arg(llvm::StringRef k, const char *v) : Arg(k, llvm::StringRef(v)) {}
110 Arg(llvm::StringRef k, Value v);
111 Arg(llvm::StringRef k, Type t);
112 Arg(llvm::StringRef k, bool b) : key(k), val(b ? "true" : "false") {}
113
114 // One constructor for all arithmetic types except bool.
115 template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T> &&
116 !std::is_same_v<T, bool>>>
117 Arg(llvm::StringRef k, T v) : key(k) {
118 if constexpr (std::is_floating_point_v<T>) {
119 llvm::raw_string_ostream os(val);
120 os << v;
121 } else if constexpr (std::is_signed_v<T>) {
122 val = llvm::itostr(static_cast<long long>(v));
123 } else {
124 val = llvm::utostr(static_cast<unsigned long long>(v));
125 }
126 }
127 };
128
129 void insert(llvm::StringRef s);
130 void insert(Arg a);
131
132 void print(llvm::raw_ostream &os, bool printLocation = false) const;
133
134 Location getLocation() const { return loc; }
135 /// Diagnostic -> Remark
136 llvm::remarks::Remark generateRemark() const;
137
138 StringRef getFunction() const {
139 if (!functionName.empty())
140 return functionName;
141 return "<unknown function>";
142 }
143
144 llvm::StringRef getCategoryName() const { return categoryName; }
145
146 llvm::StringRef getCombinedCategoryName() const {
147 if (categoryName.empty() && subCategoryName.empty())
148 return {};
149 if (subCategoryName.empty())
150 return categoryName;
151 if (categoryName.empty())
152 return subCategoryName;
153 return fullCategoryName;
154 }
155
156 StringRef getRemarkName() const {
157 if (remarkName.empty())
158 return "<unknown remark name>";
159 return remarkName;
160 }
161
162 std::string getMsg() const;
163
164 ArrayRef<Arg> getArgs() const { return args; }
165
166 llvm::remarks::Type getRemarkType() const;
167
168 StringRef getRemarkTypeString() const;
169
170protected:
171 /// Keeps the MLIR diagnostic kind, which is used to determine the
172 /// diagnostic kind in the LLVM remark streamer.
174 /// Name of the convering function like interface
175 StringRef functionName;
176
178 /// Sub category passname e.g., "Unroll" or "UnrollAndJam"
179 StringRef categoryName;
180
181 /// Sub category name "Loop Optimizer"
183
184 /// Combined name for category and sub-category
186
187 /// Remark identifier
188 StringRef remarkName;
189
190 /// Args collected via the streaming interface.
192
193private:
194 /// Convert the MLIR diagnostic severity to LLVM diagnostic severity.
195 static llvm::DiagnosticSeverity
196 makeLLVMSeverity(DiagnosticSeverity severity) {
197 switch (severity) {
199 return llvm::DiagnosticSeverity::DS_Note;
201 return llvm::DiagnosticSeverity::DS_Warning;
203 return llvm::DiagnosticSeverity::DS_Error;
205 return llvm::DiagnosticSeverity::DS_Remark;
206 }
207 llvm_unreachable("Unknown diagnostic severity");
208 }
209 /// Convert the MLIR remark kind to LLVM diagnostic kind.
210 static llvm::DiagnosticKind makeLLVMKind(RemarkKind remarkKind) {
211 switch (remarkKind) {
213 return llvm::DiagnosticKind::DK_Generic;
215 return llvm::DiagnosticKind::DK_OptimizationRemark;
217 return llvm::DiagnosticKind::DK_OptimizationRemarkMissed;
219 return llvm::DiagnosticKind::DK_OptimizationFailure;
221 return llvm::DiagnosticKind::DK_OptimizationRemarkAnalysis;
222 }
223 llvm_unreachable("Unknown diagnostic kind");
224 }
225};
226
227inline Remark &operator<<(Remark &r, StringRef s) {
228 r.insert(s);
229 return r;
230}
231inline Remark &&operator<<(Remark &&r, StringRef s) {
232 r.insert(s);
233 return std::move(r);
234}
235inline Remark &operator<<(Remark &r, const Remark::Arg &kv) {
236 r.insert(kv);
237 return r;
238}
239
240//===----------------------------------------------------------------------===//
241// Shorthand aliases for different kinds of remarks.
242//===----------------------------------------------------------------------===//
243
244template <RemarkKind K, DiagnosticSeverity S>
245class OptRemarkBase final : public Remark {
246public:
248 : Remark(K, S, loc, opts) {}
249};
250
253
256
259
262
263class RemarkEngine;
264
265//===----------------------------------------------------------------------===//
266// InFlightRemark
267//===----------------------------------------------------------------------===//
268
269/// Lazy text building for zero cost string formatting.
271 llvm::StringRef key;
272 std::function<std::string()> thunk;
273};
274
275/// InFlightRemark is a RAII class that holds a reference to a Remark
276/// instance and allows to build the remark using the << operator. The remark
277/// is emitted when the InFlightRemark instance is destroyed, which happens
278/// when the scope ends or when the InFlightRemark instance is moved.
279/// Similar to InFlightDiagnostic, but for remarks.
281public:
282 explicit InFlightRemark(std::unique_ptr<Remark> diag)
283 : remark(std::move(diag)) {}
284
285 InFlightRemark(RemarkEngine &eng, std::unique_ptr<Remark> diag)
286 : owner(&eng), remark(std::move(diag)) {}
287
288 InFlightRemark() = default; // empty ctor
289
291 if (remark)
292 *remark << Remark::Arg(l.key, l.thunk());
293 return *this;
294 }
295
296 // Generic path, but *not* for Lazy
297 template <typename T, typename = std::enable_if_t<
298 !std::is_same_v<std::decay_t<T>, LazyTextBuild>>>
300 if (remark)
301 *remark << std::forward<T>(arg);
302 return *this;
303 }
304
305 explicit operator bool() const { return remark != nullptr; }
306
308
313
314private:
315 RemarkEngine *owner{nullptr};
316 std::unique_ptr<Remark> remark;
317};
318
319//===----------------------------------------------------------------------===//
320// Pluggable Remark Utilities
321//===----------------------------------------------------------------------===//
322
323/// Base class for MLIR remark streamers that is used to stream
324/// optimization remarks to the underlying remark streamer. The derived classes
325/// should implement the `streamOptimizationRemark` method to provide the
326/// actual streaming implementation.
328public:
329 virtual ~MLIRRemarkStreamerBase() = default;
330 /// Stream an optimization remark to the underlying remark streamer. It is
331 /// called by the RemarkEngine to stream the optimization remarks.
332 ///
333 /// It must be overridden by the derived classes to provide
334 /// the actual streaming implementation.
335 virtual void streamOptimizationRemark(const Remark &remark) = 0;
336
337 virtual void finalize() {} // optional
338};
339
340using ReportFn = llvm::unique_function<void(const Remark &)>;
341
342/// Base class for MLIR remark emitting policies that is used to emit
343/// optimization remarks to the underlying remark streamer. The derived classes
344/// should implement the `reportRemark` method to provide the actual emitting
345/// implementation.
347protected:
349
350public:
352 virtual ~RemarkEmittingPolicyBase() = default;
353
354 void initialize(ReportFn fn) { reportImpl = std::move(fn); }
355
356 virtual void reportRemark(const Remark &remark) = 0;
357 virtual void finalize() = 0;
358};
359
360//===----------------------------------------------------------------------===//
361// Remark Engine (MLIR Context will own this class)
362//===----------------------------------------------------------------------===//
363
365private:
366 /// Regex that filters missed optimization remarks: only matching one are
367 /// reported.
368 std::optional<llvm::Regex> missFilter;
369 /// The category for passed optimization remarks.
370 std::optional<llvm::Regex> passedFilter;
371 /// The category for analysis remarks.
372 std::optional<llvm::Regex> analysisFilter;
373 /// The category for failed optimization remarks.
374 std::optional<llvm::Regex> failedFilter;
375 /// The MLIR remark streamer that will be used to emit the remarks.
376 std::unique_ptr<MLIRRemarkStreamerBase> remarkStreamer;
377 /// The MLIR remark policy that will be used to emit the remarks.
378 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy;
379 /// When is enabled, engine also prints remarks as mlir::emitRemarks.
380 bool printAsEmitRemarks = false;
381
382 /// Return true if missed optimization remarks are enabled, override
383 /// to provide different implementation.
384 bool isMissedOptRemarkEnabled(StringRef categoryName) const;
385
386 /// Return true if passed optimization remarks are enabled, override
387 /// to provide different implementation.
388 bool isPassedOptRemarkEnabled(StringRef categoryName) const;
389
390 /// Return true if analysis optimization remarks are enabled, override
391 /// to provide different implementation.
392 bool isAnalysisOptRemarkEnabled(StringRef categoryName) const;
393
394 /// Return true if analysis optimization remarks are enabled, override
395 /// to provide different implementation.
396 bool isFailedOptRemarkEnabled(StringRef categoryName) const;
397
398 /// Return true if any type of remarks are enabled for this pass.
399 bool isAnyRemarkEnabled(StringRef categoryName) const {
400 return isMissedOptRemarkEnabled(categoryName) ||
401 isPassedOptRemarkEnabled(categoryName) ||
402 isFailedOptRemarkEnabled(categoryName) ||
403 isAnalysisOptRemarkEnabled(categoryName);
404 }
405
406 /// Emit a remark using the given maker function, which should return
407 /// a Remark instance. The remark will be emitted using the main
408 /// remark streamer.
409 template <typename RemarkT, typename... Args>
410 InFlightRemark makeRemark(Args &&...args);
411
412 template <typename RemarkT>
413 InFlightRemark emitIfEnabled(Location loc, RemarkOpts opts,
414 bool (RemarkEngine::*isEnabled)(StringRef)
415 const);
416 /// Report a remark.
417 void reportImpl(const Remark &remark);
418
419public:
420 /// Default constructor is deleted, use the other constructor.
421 RemarkEngine() = delete;
422
423 /// Constructs Remark engine with optional category names. If a category
424 /// name is not provided, it is not enabled. The category names are used to
425 /// filter the remarks that are emitted.
426 RemarkEngine(bool printAsEmitRemarks, const RemarkCategories &cats);
427
428 /// Destructor that will close the output file and reset the
429 /// main remark streamer.
431
432 /// Setup the remark engine with the given output path and format.
433 LogicalResult
434 initialize(std::unique_ptr<MLIRRemarkStreamerBase> streamer,
435 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy,
436 std::string *errMsg);
437
438 /// Get the remark emitting policy.
440 return remarkEmittingPolicy.get();
441 }
442
443 /// Report a remark.
444 void report(const Remark &&remark);
445
446 /// Report a successful remark, this will create an InFlightRemark
447 /// that can be used to build the remark using the << operator.
449
450 /// Report a missed optimization remark
451 /// that can be used to build the remark using the << operator.
453
454 /// Report a failed optimization remark, this will create an InFlightRemark
455 /// that can be used to build the remark using the << operator.
457
458 /// Report an analysis remark, this will create an InFlightRemark
459 /// that can be used to build the remark using the << operator.
461};
462
463template <typename Fn, typename... Args>
464inline InFlightRemark withEngine(Fn fn, Location loc, Args &&...args) {
465 MLIRContext *ctx = loc->getContext();
466
467 RemarkEngine *enginePtr = ctx->getRemarkEngine();
468
469 if (LLVM_UNLIKELY(enginePtr))
470 return (enginePtr->*fn)(loc, std::forward<Args>(args)...);
471
472 return {};
473}
474
475} // namespace mlir::remark::detail
476
477namespace mlir::remark {
478
479//===----------------------------------------------------------------------===//
480// Remark Emitting Policies
481//===----------------------------------------------------------------------===//
482
483/// Policy that emits all remarks.
485public:
487
488 void reportRemark(const detail::Remark &remark) override {
489 assert(reportImpl && "reportImpl is not set");
491 }
492 void finalize() override {}
493};
494
495/// Policy that emits final remarks.
497private:
498 /// user can intercept them for custom processing via a registered callback,
499 /// otherwise they will be reported on engine destruction.
500 llvm::DenseSet<detail::Remark> postponedRemarks;
501
502public:
504
505 void reportRemark(const detail::Remark &remark) override {
506 postponedRemarks.erase(remark);
507 postponedRemarks.insert(remark);
508 }
509
510 void finalize() override {
511 assert(reportImpl && "reportImpl is not set");
512 for (auto &remark : postponedRemarks) {
513 if (reportImpl)
515 }
516 }
517};
518
519/// Create a Reason with llvm::formatv formatting.
520template <class... Ts>
521inline detail::LazyTextBuild reason(const char *fmt, Ts &&...ts) {
522 return {"Reason", [=] { return llvm::formatv(fmt, ts...).str(); }};
523}
524
525/// Create a Suggestion with llvm::formatv formatting.
526template <class... Ts>
527inline detail::LazyTextBuild suggest(const char *fmt, Ts &&...ts) {
528 return {"Suggestion", [=] { return llvm::formatv(fmt, ts...).str(); }};
529}
530
531/// Create a Remark with llvm::formatv formatting.
532template <class... Ts>
533inline detail::LazyTextBuild add(const char *fmt, Ts &&...ts) {
534 return {"Remark", [=] { return llvm::formatv(fmt, ts...).str(); }};
535}
536
537template <class V>
538inline detail::LazyTextBuild metric(StringRef key, V &&v) {
539 using DV = std::decay_t<V>;
540 return {key, [key, vv = DV(std::forward<V>(v))]() mutable {
541 // Reuse Arg's formatting logic and return just the value string.
542 return detail::Remark::Arg(key, std::move(vv)).val;
543 }};
544}
545//===----------------------------------------------------------------------===//
546// Emitters
547//===----------------------------------------------------------------------===//
548
549/// Report an optimization remark that was passed.
551 return withEngine(&detail::RemarkEngine::emitOptimizationRemark, loc, opts);
552}
553
554/// Report an optimization remark that was missed.
557 opts);
558}
559
560/// Report an optimization remark that failed.
563 opts);
564}
565
566/// Report an optimization analysis remark.
569 opts);
570}
571
572//===----------------------------------------------------------------------===//
573// Setup
574//===----------------------------------------------------------------------===//
575
576/// Setup remarks for the context. This function will enable the remark engine
577/// and set the streamer to be used for optimization remarks. The remark
578/// categories are used to filter the remarks that will be emitted by the
579/// remark engine. If a category is not specified, it will not be emitted. If
580/// `printAsEmitRemarks` is true, the remarks will be printed as
581/// mlir::emitRemarks. 'streamer' must inherit from MLIRRemarkStreamerBase and
582/// will be used to stream the remarks.
584 MLIRContext &ctx,
585 std::unique_ptr<remark::detail::MLIRRemarkStreamerBase> streamer,
586 std::unique_ptr<remark::detail::RemarkEmittingPolicyBase>
587 remarkEmittingPolicy,
588 const remark::RemarkCategories &cats, bool printAsEmitRemarks = false);
589
590} // namespace mlir::remark
591
592// DenseMapInfo specialization for Remark
593namespace llvm {
594template <>
595struct DenseMapInfo<mlir::remark::detail::Remark> {
596 static constexpr StringRef kEmptyKey = "<EMPTY_KEY>";
597 static constexpr StringRef kTombstoneKey = "<TOMBSTONE_KEY>";
598
599 /// Helper to provide a static dummy context for sentinel keys.
601 static mlir::MLIRContext dummyContext;
602 return &dummyContext;
603 }
604
605 /// Create an empty remark
612
613 /// Create a dead remark
620
621 /// Compute the hash value of the remark
622 static unsigned getHashValue(const mlir::remark::detail::Remark &remark) {
623 return llvm::hash_combine(
625 llvm::hash_value(remark.getRemarkName()),
626 llvm::hash_value(remark.getCombinedCategoryName()));
627 }
628
631 // Check for empty/tombstone keys first
632 if (lhs.getRemarkName() == kEmptyKey ||
633 lhs.getRemarkName() == kTombstoneKey ||
634 rhs.getRemarkName() == kEmptyKey ||
635 rhs.getRemarkName() == kTombstoneKey) {
636 return lhs.getRemarkName() == rhs.getRemarkName();
637 }
638
639 // For regular remarks, compare key identifying fields
640 return lhs.getLocation() == rhs.getLocation() &&
641 lhs.getRemarkName() == rhs.getRemarkName() &&
642 lhs.getCombinedCategoryName() == rhs.getCombinedCategoryName();
643 }
644};
645} // namespace llvm
646#endif // MLIR_IR_REMARKS_H
lhs
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
static std::string diag(const llvm::Value &value)
#define add(a, b)
MLIRContext * getContext() const
Return the context this attribute belongs to.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
const void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
Definition Location.h:103
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
remark::detail::RemarkEngine * getRemarkEngine()
Returns the remark engine for this context, or nullptr if none has been set.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
void reportRemark(const detail::Remark &remark) override
Definition Remarks.h:488
void reportRemark(const detail::Remark &remark) override
Definition Remarks.h:505
InFlightRemark is a RAII class that holds a reference to a Remark instance and allows to build the re...
Definition Remarks.h:280
InFlightRemark(RemarkEngine &eng, std::unique_ptr< Remark > diag)
Definition Remarks.h:285
InFlightRemark(std::unique_ptr< Remark > diag)
Definition Remarks.h:282
InFlightRemark(const InFlightRemark &)=delete
InFlightRemark & operator<<(const LazyTextBuild &l)
Definition Remarks.h:290
InFlightRemark(InFlightRemark &&)=default
InFlightRemark & operator=(InFlightRemark &&)=default
InFlightRemark & operator<<(T &&arg)
Definition Remarks.h:299
InFlightRemark & operator=(const InFlightRemark &)=delete
Base class for MLIR remark streamers that is used to stream optimization remarks to the underlying re...
Definition Remarks.h:327
virtual void streamOptimizationRemark(const Remark &remark)=0
Stream an optimization remark to the underlying remark streamer.
OptRemarkBase(Location loc, RemarkOpts opts)
Definition Remarks.h:247
Base class for MLIR remark emitting policies that is used to emit optimization remarks to the underly...
Definition Remarks.h:346
virtual void reportRemark(const Remark &remark)=0
InFlightRemark emitOptimizationRemarkFailure(Location loc, RemarkOpts opts)
Report a failed optimization remark, this will create an InFlightRemark that can be used to build the...
Definition Remarks.cpp:213
void report(const Remark &&remark)
Report a remark.
Definition Remarks.cpp:240
InFlightRemark emitOptimizationRemark(Location loc, RemarkOpts opts)
Report a successful remark, this will create an InFlightRemark that can be used to build the remark u...
Definition Remarks.cpp:201
RemarkEmittingPolicyBase * getRemarkEmittingPolicy() const
Get the remark emitting policy.
Definition Remarks.h:439
LogicalResult initialize(std::unique_ptr< MLIRRemarkStreamerBase > streamer, std::unique_ptr< RemarkEmittingPolicyBase > remarkEmittingPolicy, std::string *errMsg)
Setup the remark engine with the given output path and format.
Definition Remarks.cpp:253
RemarkEngine()=delete
Default constructor is deleted, use the other constructor.
InFlightRemark emitOptimizationRemarkMiss(Location loc, RemarkOpts opts)
Report a missed optimization remark that can be used to build the remark using the << operator.
Definition Remarks.cpp:207
~RemarkEngine()
Destructor that will close the output file and reset the main remark streamer.
Definition Remarks.cpp:245
InFlightRemark emitOptimizationRemarkAnalysis(Location loc, RemarkOpts opts)
Report an analysis remark, this will create an InFlightRemark that can be used to build the remark us...
Definition Remarks.cpp:219
void print(llvm::raw_ostream &os, bool printLocation=false) const
Print the remark to the given output stream.
Definition Remarks.cpp:70
ArrayRef< Arg > getArgs() const
Definition Remarks.h:164
StringRef categoryName
Sub category passname e.g., "Unroll" or "UnrollAndJam".
Definition Remarks.h:179
SmallVector< Arg, 4 > args
Args collected via the streaming interface.
Definition Remarks.h:191
llvm::StringRef getCategoryName() const
Definition Remarks.h:144
StringRef getFunction() const
Definition Remarks.h:138
Remark(RemarkKind remarkKind, DiagnosticSeverity severity, Location loc, RemarkOpts opts)
Definition Remarks.h:90
llvm::remarks::Type getRemarkType() const
Definition Remarks.cpp:117
StringRef getRemarkTypeString() const
Definition Remarks.cpp:101
StringRef subCategoryName
Sub category name "Loop Optimizer".
Definition Remarks.h:182
Location getLocation() const
Definition Remarks.h:134
StringRef remarkName
Remark identifier.
Definition Remarks.h:188
llvm::StringRef getCombinedCategoryName() const
Definition Remarks.h:146
RemarkKind remarkKind
Keeps the MLIR diagnostic kind, which is used to determine the diagnostic kind in the LLVM remark str...
Definition Remarks.h:173
StringRef getRemarkName() const
Definition Remarks.h:156
SmallString< 64 > fullCategoryName
Combined name for category and sub-category.
Definition Remarks.h:185
void insert(llvm::StringRef s)
Definition Remarks.cpp:34
StringRef functionName
Name of the convering function like interface.
Definition Remarks.h:175
llvm::remarks::Remark generateRemark() const
Diagnostic -> Remark.
Definition Remarks.cpp:133
std::string getMsg() const
Definition Remarks.cpp:93
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
OptRemarkBase< RemarkKind::RemarkMissed, DiagnosticSeverity::Remark > OptRemarkMissed
Definition Remarks.h:257
llvm::unique_function< void(const Remark &)> ReportFn
Definition Remarks.h:340
OptRemarkBase< RemarkKind::RemarkPassed, DiagnosticSeverity::Remark > OptRemarkPass
Definition Remarks.h:254
OptRemarkBase< RemarkKind::RemarkFailure, DiagnosticSeverity::Remark > OptRemarkFailure
Definition Remarks.h:260
OptRemarkBase< RemarkKind::RemarkAnalysis, DiagnosticSeverity::Remark > OptRemarkAnalysis
Definition Remarks.h:251
InFlightRemark withEngine(Fn fn, Location loc, Args &&...args)
Definition Remarks.h:464
Remark & operator<<(Remark &r, StringRef s)
Definition Remarks.h:227
detail::LazyTextBuild suggest(const char *fmt, Ts &&...ts)
Create a Suggestion with llvm::formatv formatting.
Definition Remarks.h:527
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:561
detail::InFlightRemark missed(Location loc, RemarkOpts opts)
Report an optimization remark that was missed.
Definition Remarks.h:555
detail::InFlightRemark analysis(Location loc, RemarkOpts opts)
Report an optimization analysis remark.
Definition Remarks.h:567
LogicalResult enableOptimizationRemarks(MLIRContext &ctx, std::unique_ptr< remark::detail::MLIRRemarkStreamerBase > streamer, std::unique_ptr< remark::detail::RemarkEmittingPolicyBase > remarkEmittingPolicy, const remark::RemarkCategories &cats, bool printAsEmitRemarks=false)
Setup remarks for the context.
detail::InFlightRemark passed(Location loc, RemarkOpts opts)
Report an optimization remark that was passed.
Definition Remarks.h:550
detail::LazyTextBuild metric(StringRef key, V &&v)
Definition Remarks.h:538
detail::LazyTextBuild reason(const char *fmt, Ts &&...ts)
Create a Reason with llvm::formatv formatting.
Definition Remarks.h:521
RemarkKind
Categories describe the outcome of an transformation, not the mechanics of emitting/serializing remar...
Definition Remarks.h:36
@ RemarkPassed
An optimization was applied.
Definition Remarks.h:40
@ RemarkAnalysis
Informational context (e.g., analysis numbers) without a pass/fail outcome.
Definition Remarks.h:51
@ RemarkMissed
A profitable optimization opportunity was found but not applied.
Definition Remarks.h:43
@ RemarkFailure
The compiler attempted the optimization but failed (e.g., legality checks, or better opportunites).
Definition Remarks.h:47
Include the generated interface declarations.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition Diagnostics.h:41
static mlir::remark::detail::Remark getEmptyKey()
Create an empty remark.
Definition Remarks.h:606
static bool isEqual(const mlir::remark::detail::Remark &lhs, const mlir::remark::detail::Remark &rhs)
Definition Remarks.h:629
static mlir::MLIRContext * getStaticDummyContext()
Helper to provide a static dummy context for sentinel keys.
Definition Remarks.h:600
static unsigned getHashValue(const mlir::remark::detail::Remark &remark)
Compute the hash value of the remark.
Definition Remarks.h:622
static mlir::remark::detail::Remark getTombstoneKey()
Create a dead remark.
Definition Remarks.h:614
Define an the set of categories to accept.
Definition Remarks.h:30
std::optional< std::string > missed
Definition Remarks.h:31
std::optional< std::string > all
Definition Remarks.h:31
std::optional< std::string > passed
Definition Remarks.h:31
std::optional< std::string > analysis
Definition Remarks.h:31
std::optional< std::string > failed
Definition Remarks.h:31
Options to create a Remark.
Definition Remarks.h:57
constexpr RemarkOpts function(StringRef v) const
Return a copy with the function name set.
Definition Remarks.h:76
StringRef subCategoryName
Definition Remarks.h:60
static constexpr RemarkOpts name(StringRef n)
Definition Remarks.h:64
constexpr RemarkOpts category(StringRef v) const
Return a copy with the category set.
Definition Remarks.h:68
constexpr RemarkOpts subCategory(StringRef v) const
Return a copy with the subcategory set.
Definition Remarks.h:72
Lazy text building for zero cost string formatting.
Definition Remarks.h:270
std::function< std::string()> thunk
Definition Remarks.h:272
Arg(llvm::StringRef k, T v)
Definition Remarks.h:117
Arg(llvm::StringRef k, llvm::StringRef v)
Definition Remarks.h:107
Arg(llvm::StringRef k, std::string v)
Definition Remarks.h:108
Arg(llvm::StringRef k, const char *v)
Definition Remarks.h:109
Arg(llvm::StringRef k, bool b)
Definition Remarks.h:112