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. For Attribute arguments, the original attribute is also
103 // stored to allow custom streamers to handle them specially.
104 struct Arg {
105 std::string key;
106 std::string val;
107 /// Optional attribute storage for Attribute-based args. Allows streamers
108 /// to access the original attribute for custom handling.
109 std::optional<Attribute> attr;
110
111 Arg(llvm::StringRef m) : key("Remark"), val(m) {}
112 Arg(llvm::StringRef k, llvm::StringRef v) : key(k), val(v) {}
113 Arg(llvm::StringRef k, std::string v) : key(k), val(std::move(v)) {}
114 Arg(llvm::StringRef k, const char *v) : Arg(k, llvm::StringRef(v)) {}
115 Arg(llvm::StringRef k, Value v);
116 Arg(llvm::StringRef k, Type t);
117 Arg(llvm::StringRef k, Attribute a);
118 Arg(llvm::StringRef k, bool b) : key(k), val(b ? "true" : "false") {}
119
120 /// Check if this arg has an associated attribute.
121 bool hasAttribute() const { return attr.has_value(); }
122
123 /// Get the attribute if present.
124 Attribute getAttribute() const { return attr.value_or(Attribute()); }
125
126 // One constructor for all arithmetic types except bool.
127 template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T> &&
128 !std::is_same_v<T, bool>>>
129 Arg(llvm::StringRef k, T v) : key(k) {
130 if constexpr (std::is_floating_point_v<T>) {
131 llvm::raw_string_ostream os(val);
132 os << v;
133 } else if constexpr (std::is_signed_v<T>) {
134 val = llvm::itostr(static_cast<long long>(v));
135 } else {
136 val = llvm::utostr(static_cast<unsigned long long>(v));
137 }
138 }
139 };
140
141 void insert(llvm::StringRef s);
142 void insert(Arg a);
143
144 void print(llvm::raw_ostream &os, bool printLocation = false) const;
145
146 Location getLocation() const { return loc; }
147 /// Diagnostic -> Remark
148 llvm::remarks::Remark generateRemark() const;
149
150 StringRef getFunction() const {
151 if (!functionName.empty())
152 return functionName;
153 return "<unknown function>";
154 }
155
156 llvm::StringRef getCategoryName() const { return categoryName; }
157
158 llvm::StringRef getCombinedCategoryName() const {
159 if (categoryName.empty() && subCategoryName.empty())
160 return {};
161 if (subCategoryName.empty())
162 return categoryName;
163 if (categoryName.empty())
164 return subCategoryName;
165 return fullCategoryName;
166 }
167
168 StringRef getRemarkName() const {
169 if (remarkName.empty())
170 return "<unknown remark name>";
171 return remarkName;
172 }
173
174 std::string getMsg() const;
175
176 ArrayRef<Arg> getArgs() const { return args; }
177
178 llvm::remarks::Type getRemarkType() const;
179
180 StringRef getRemarkTypeString() const;
181
182protected:
183 /// Keeps the MLIR diagnostic kind, which is used to determine the
184 /// diagnostic kind in the LLVM remark streamer.
186 /// Name of the convering function like interface
187 StringRef functionName;
188
190 /// Sub category passname e.g., "Unroll" or "UnrollAndJam"
191 StringRef categoryName;
192
193 /// Sub category name "Loop Optimizer"
195
196 /// Combined name for category and sub-category
198
199 /// Remark identifier
200 StringRef remarkName;
201
202 /// Args collected via the streaming interface.
204
205private:
206 /// Convert the MLIR diagnostic severity to LLVM diagnostic severity.
207 static llvm::DiagnosticSeverity
208 makeLLVMSeverity(DiagnosticSeverity severity) {
209 switch (severity) {
211 return llvm::DiagnosticSeverity::DS_Note;
213 return llvm::DiagnosticSeverity::DS_Warning;
215 return llvm::DiagnosticSeverity::DS_Error;
217 return llvm::DiagnosticSeverity::DS_Remark;
218 }
219 llvm_unreachable("Unknown diagnostic severity");
220 }
221 /// Convert the MLIR remark kind to LLVM diagnostic kind.
222 static llvm::DiagnosticKind makeLLVMKind(RemarkKind remarkKind) {
223 switch (remarkKind) {
225 return llvm::DiagnosticKind::DK_Generic;
227 return llvm::DiagnosticKind::DK_OptimizationRemark;
229 return llvm::DiagnosticKind::DK_OptimizationRemarkMissed;
231 return llvm::DiagnosticKind::DK_OptimizationFailure;
233 return llvm::DiagnosticKind::DK_OptimizationRemarkAnalysis;
234 }
235 llvm_unreachable("Unknown diagnostic kind");
236 }
237};
238
239inline Remark &operator<<(Remark &r, StringRef s) {
240 r.insert(s);
241 return r;
242}
243inline Remark &&operator<<(Remark &&r, StringRef s) {
244 r.insert(s);
245 return std::move(r);
246}
247inline Remark &operator<<(Remark &r, const Remark::Arg &kv) {
248 r.insert(kv);
249 return r;
250}
251
252//===----------------------------------------------------------------------===//
253// Shorthand aliases for different kinds of remarks.
254//===----------------------------------------------------------------------===//
255
256template <RemarkKind K, DiagnosticSeverity S>
257class OptRemarkBase final : public Remark {
258public:
260 : Remark(K, S, loc, opts) {}
261};
262
265
268
271
274
275class RemarkEngine;
276
277//===----------------------------------------------------------------------===//
278// InFlightRemark
279//===----------------------------------------------------------------------===//
280
281/// Lazy text building for zero cost string formatting.
283 llvm::StringRef key;
284 std::function<std::string()> thunk;
285};
286
287/// InFlightRemark is a RAII class that holds a reference to a Remark
288/// instance and allows to build the remark using the << operator. The remark
289/// is emitted when the InFlightRemark instance is destroyed, which happens
290/// when the scope ends or when the InFlightRemark instance is moved.
291/// Similar to InFlightDiagnostic, but for remarks.
293public:
294 explicit InFlightRemark(std::unique_ptr<Remark> diag)
295 : remark(std::move(diag)) {}
296
297 InFlightRemark(RemarkEngine &eng, std::unique_ptr<Remark> diag)
298 : owner(&eng), remark(std::move(diag)) {}
299
300 InFlightRemark() = default; // empty ctor
301
303 if (remark)
304 *remark << Remark::Arg(l.key, l.thunk());
305 return *this;
306 }
307
308 // Generic path, but *not* for Lazy
309 template <typename T, typename = std::enable_if_t<
310 !std::is_same_v<std::decay_t<T>, LazyTextBuild>>>
312 if (remark)
313 *remark << std::forward<T>(arg);
314 return *this;
315 }
316
317 explicit operator bool() const { return remark != nullptr; }
318
320
325
326private:
327 RemarkEngine *owner{nullptr};
328 std::unique_ptr<Remark> remark;
329};
330
331//===----------------------------------------------------------------------===//
332// Pluggable Remark Utilities
333//===----------------------------------------------------------------------===//
334
335/// Base class for MLIR remark streamers that is used to stream
336/// optimization remarks to the underlying remark streamer. The derived classes
337/// should implement the `streamOptimizationRemark` method to provide the
338/// actual streaming implementation.
340public:
341 virtual ~MLIRRemarkStreamerBase() = default;
342 /// Stream an optimization remark to the underlying remark streamer. It is
343 /// called by the RemarkEngine to stream the optimization remarks.
344 ///
345 /// It must be overridden by the derived classes to provide
346 /// the actual streaming implementation.
347 virtual void streamOptimizationRemark(const Remark &remark) = 0;
348
349 virtual void finalize() {} // optional
350};
351
352using ReportFn = llvm::unique_function<void(const Remark &)>;
353
354/// Base class for MLIR remark emitting policies that is used to emit
355/// optimization remarks to the underlying remark streamer. The derived classes
356/// should implement the `reportRemark` method to provide the actual emitting
357/// implementation.
359protected:
361
362public:
364 virtual ~RemarkEmittingPolicyBase() = default;
365
366 void initialize(ReportFn fn) { reportImpl = std::move(fn); }
367
368 virtual void reportRemark(const Remark &remark) = 0;
369 virtual void finalize() = 0;
370};
371
372//===----------------------------------------------------------------------===//
373// Remark Engine (MLIR Context will own this class)
374//===----------------------------------------------------------------------===//
375
377private:
378 /// Regex that filters missed optimization remarks: only matching one are
379 /// reported.
380 std::optional<llvm::Regex> missFilter;
381 /// The category for passed optimization remarks.
382 std::optional<llvm::Regex> passedFilter;
383 /// The category for analysis remarks.
384 std::optional<llvm::Regex> analysisFilter;
385 /// The category for failed optimization remarks.
386 std::optional<llvm::Regex> failedFilter;
387 /// The MLIR remark streamer that will be used to emit the remarks.
388 std::unique_ptr<MLIRRemarkStreamerBase> remarkStreamer;
389 /// The MLIR remark policy that will be used to emit the remarks.
390 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy;
391 /// When is enabled, engine also prints remarks as mlir::emitRemarks.
392 bool printAsEmitRemarks = false;
393
394 /// Return true if missed optimization remarks are enabled, override
395 /// to provide different implementation.
396 bool isMissedOptRemarkEnabled(StringRef categoryName) const;
397
398 /// Return true if passed optimization remarks are enabled, override
399 /// to provide different implementation.
400 bool isPassedOptRemarkEnabled(StringRef categoryName) const;
401
402 /// Return true if analysis optimization remarks are enabled, override
403 /// to provide different implementation.
404 bool isAnalysisOptRemarkEnabled(StringRef categoryName) const;
405
406 /// Return true if analysis optimization remarks are enabled, override
407 /// to provide different implementation.
408 bool isFailedOptRemarkEnabled(StringRef categoryName) const;
409
410 /// Return true if any type of remarks are enabled for this pass.
411 bool isAnyRemarkEnabled(StringRef categoryName) const {
412 return isMissedOptRemarkEnabled(categoryName) ||
413 isPassedOptRemarkEnabled(categoryName) ||
414 isFailedOptRemarkEnabled(categoryName) ||
415 isAnalysisOptRemarkEnabled(categoryName);
416 }
417
418 /// Emit a remark using the given maker function, which should return
419 /// a Remark instance. The remark will be emitted using the main
420 /// remark streamer.
421 template <typename RemarkT, typename... Args>
422 InFlightRemark makeRemark(Args &&...args);
423
424 template <typename RemarkT>
425 InFlightRemark emitIfEnabled(Location loc, RemarkOpts opts,
426 bool (RemarkEngine::*isEnabled)(StringRef)
427 const);
428 /// Report a remark.
429 void reportImpl(const Remark &remark);
430
431public:
432 /// Default constructor is deleted, use the other constructor.
433 RemarkEngine() = delete;
434
435 /// Constructs Remark engine with optional category names. If a category
436 /// name is not provided, it is not enabled. The category names are used to
437 /// filter the remarks that are emitted.
438 RemarkEngine(bool printAsEmitRemarks, const RemarkCategories &cats);
439
440 /// Destructor that will close the output file and reset the
441 /// main remark streamer.
443
444 /// Setup the remark engine with the given output path and format.
445 LogicalResult
446 initialize(std::unique_ptr<MLIRRemarkStreamerBase> streamer,
447 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy,
448 std::string *errMsg);
449
450 /// Get the remark emitting policy.
452 return remarkEmittingPolicy.get();
453 }
454
455 /// Report a remark.
456 void report(const Remark &&remark);
457
458 /// Report a successful remark, this will create an InFlightRemark
459 /// that can be used to build the remark using the << operator.
461
462 /// Report a missed optimization remark
463 /// that can be used to build the remark using the << operator.
465
466 /// Report a failed optimization remark, this will create an InFlightRemark
467 /// that can be used to build the remark using the << operator.
469
470 /// Report an analysis remark, this will create an InFlightRemark
471 /// that can be used to build the remark using the << operator.
473};
474
475template <typename Fn, typename... Args>
476inline InFlightRemark withEngine(Fn fn, Location loc, Args &&...args) {
477 MLIRContext *ctx = loc->getContext();
478
479 RemarkEngine *enginePtr = ctx->getRemarkEngine();
480
481 if (LLVM_UNLIKELY(enginePtr))
482 return (enginePtr->*fn)(loc, std::forward<Args>(args)...);
483
484 return {};
485}
486
487} // namespace mlir::remark::detail
488
489namespace mlir::remark {
490
491//===----------------------------------------------------------------------===//
492// Remark Emitting Policies
493//===----------------------------------------------------------------------===//
494
495/// Policy that emits all remarks.
497public:
499
500 void reportRemark(const detail::Remark &remark) override {
501 assert(reportImpl && "reportImpl is not set");
503 }
504 void finalize() override {}
505};
506
507/// Policy that emits final remarks.
509private:
510 /// user can intercept them for custom processing via a registered callback,
511 /// otherwise they will be reported on engine destruction.
512 llvm::DenseSet<detail::Remark> postponedRemarks;
513
514public:
516
517 void reportRemark(const detail::Remark &remark) override {
518 postponedRemarks.erase(remark);
519 postponedRemarks.insert(remark);
520 }
521
522 void finalize() override {
523 assert(reportImpl && "reportImpl is not set");
524 for (auto &remark : postponedRemarks) {
525 if (reportImpl)
527 }
528 }
529};
530
531/// Create a Reason with llvm::formatv formatting.
532template <class... Ts>
533inline detail::LazyTextBuild reason(const char *fmt, Ts &&...ts) {
534 return {"Reason", [=] { return llvm::formatv(fmt, ts...).str(); }};
535}
536
537/// Create a Suggestion with llvm::formatv formatting.
538template <class... Ts>
539inline detail::LazyTextBuild suggest(const char *fmt, Ts &&...ts) {
540 return {"Suggestion", [=] { return llvm::formatv(fmt, ts...).str(); }};
541}
542
543/// Create a Remark with llvm::formatv formatting.
544template <class... Ts>
545inline detail::LazyTextBuild add(const char *fmt, Ts &&...ts) {
546 return {"Remark", [=] { return llvm::formatv(fmt, ts...).str(); }};
547}
548
549template <class V>
550inline detail::LazyTextBuild metric(StringRef key, V &&v) {
551 using DV = std::decay_t<V>;
552 return {key, [key, vv = DV(std::forward<V>(v))]() mutable {
553 // Reuse Arg's formatting logic and return just the value string.
554 return detail::Remark::Arg(key, std::move(vv)).val;
555 }};
556}
557//===----------------------------------------------------------------------===//
558// Emitters
559//===----------------------------------------------------------------------===//
560
561/// Report an optimization remark that was passed.
563 return withEngine(&detail::RemarkEngine::emitOptimizationRemark, loc, opts);
564}
565
566/// Report an optimization remark that was missed.
569 opts);
570}
571
572/// Report an optimization remark that failed.
575 opts);
576}
577
578/// Report an optimization analysis remark.
581 opts);
582}
583
584//===----------------------------------------------------------------------===//
585// Setup
586//===----------------------------------------------------------------------===//
587
588/// Setup remarks for the context. This function will enable the remark engine
589/// and set the streamer to be used for optimization remarks. The remark
590/// categories are used to filter the remarks that will be emitted by the
591/// remark engine. If a category is not specified, it will not be emitted. If
592/// `printAsEmitRemarks` is true, the remarks will be printed as
593/// mlir::emitRemarks. 'streamer' must inherit from MLIRRemarkStreamerBase and
594/// will be used to stream the remarks.
596 MLIRContext &ctx,
597 std::unique_ptr<remark::detail::MLIRRemarkStreamerBase> streamer,
598 std::unique_ptr<remark::detail::RemarkEmittingPolicyBase>
599 remarkEmittingPolicy,
600 const remark::RemarkCategories &cats, bool printAsEmitRemarks = false);
601
602} // namespace mlir::remark
603
604// DenseMapInfo specialization for Remark
605namespace llvm {
606template <>
607struct DenseMapInfo<mlir::remark::detail::Remark> {
608 static constexpr StringRef kEmptyKey = "<EMPTY_KEY>";
609 static constexpr StringRef kTombstoneKey = "<TOMBSTONE_KEY>";
610
611 /// Helper to provide a static dummy context for sentinel keys.
613 static mlir::MLIRContext dummyContext;
614 return &dummyContext;
615 }
616
617 /// Create an empty remark
624
625 /// Create a dead remark
632
633 /// Compute the hash value of the remark
634 static unsigned getHashValue(const mlir::remark::detail::Remark &remark) {
635 return llvm::hash_combine(
637 llvm::hash_value(remark.getRemarkName()),
638 llvm::hash_value(remark.getCombinedCategoryName()));
639 }
640
643 // Check for empty/tombstone keys first
644 if (lhs.getRemarkName() == kEmptyKey ||
645 lhs.getRemarkName() == kTombstoneKey ||
646 rhs.getRemarkName() == kEmptyKey ||
647 rhs.getRemarkName() == kTombstoneKey) {
648 return lhs.getRemarkName() == rhs.getRemarkName();
649 }
650
651 // For regular remarks, compare key identifying fields
652 return lhs.getLocation() == rhs.getLocation() &&
653 lhs.getRemarkName() == rhs.getRemarkName() &&
654 lhs.getCombinedCategoryName() == rhs.getCombinedCategoryName();
655 }
656};
657} // namespace llvm
658#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)
Attributes are known-constant values of operations.
Definition Attributes.h:25
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:500
void reportRemark(const detail::Remark &remark) override
Definition Remarks.h:517
InFlightRemark is a RAII class that holds a reference to a Remark instance and allows to build the re...
Definition Remarks.h:292
InFlightRemark(RemarkEngine &eng, std::unique_ptr< Remark > diag)
Definition Remarks.h:297
InFlightRemark(std::unique_ptr< Remark > diag)
Definition Remarks.h:294
InFlightRemark(const InFlightRemark &)=delete
InFlightRemark & operator<<(const LazyTextBuild &l)
Definition Remarks.h:302
InFlightRemark(InFlightRemark &&)=default
InFlightRemark & operator=(InFlightRemark &&)=default
InFlightRemark & operator<<(T &&arg)
Definition Remarks.h:311
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:339
virtual void streamOptimizationRemark(const Remark &remark)=0
Stream an optimization remark to the underlying remark streamer.
OptRemarkBase(Location loc, RemarkOpts opts)
Definition Remarks.h:259
Base class for MLIR remark emitting policies that is used to emit optimization remarks to the underly...
Definition Remarks.h:358
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:218
void report(const Remark &&remark)
Report a remark.
Definition Remarks.cpp:245
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:206
RemarkEmittingPolicyBase * getRemarkEmittingPolicy() const
Get the remark emitting policy.
Definition Remarks.h:451
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:258
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:212
~RemarkEngine()
Destructor that will close the output file and reset the main remark streamer.
Definition Remarks.cpp:250
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:224
void print(llvm::raw_ostream &os, bool printLocation=false) const
Print the remark to the given output stream.
Definition Remarks.cpp:75
ArrayRef< Arg > getArgs() const
Definition Remarks.h:176
StringRef categoryName
Sub category passname e.g., "Unroll" or "UnrollAndJam".
Definition Remarks.h:191
SmallVector< Arg, 4 > args
Args collected via the streaming interface.
Definition Remarks.h:203
llvm::StringRef getCategoryName() const
Definition Remarks.h:156
StringRef getFunction() const
Definition Remarks.h:150
Remark(RemarkKind remarkKind, DiagnosticSeverity severity, Location loc, RemarkOpts opts)
Definition Remarks.h:90
llvm::remarks::Type getRemarkType() const
Definition Remarks.cpp:122
StringRef getRemarkTypeString() const
Definition Remarks.cpp:106
StringRef subCategoryName
Sub category name "Loop Optimizer".
Definition Remarks.h:194
Location getLocation() const
Definition Remarks.h:146
StringRef remarkName
Remark identifier.
Definition Remarks.h:200
llvm::StringRef getCombinedCategoryName() const
Definition Remarks.h:158
RemarkKind remarkKind
Keeps the MLIR diagnostic kind, which is used to determine the diagnostic kind in the LLVM remark str...
Definition Remarks.h:185
StringRef getRemarkName() const
Definition Remarks.h:168
SmallString< 64 > fullCategoryName
Combined name for category and sub-category.
Definition Remarks.h:197
void insert(llvm::StringRef s)
Definition Remarks.cpp:39
StringRef functionName
Name of the convering function like interface.
Definition Remarks.h:187
llvm::remarks::Remark generateRemark() const
Diagnostic -> Remark.
Definition Remarks.cpp:138
std::string getMsg() const
Definition Remarks.cpp:98
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
OptRemarkBase< RemarkKind::RemarkMissed, DiagnosticSeverity::Remark > OptRemarkMissed
Definition Remarks.h:269
llvm::unique_function< void(const Remark &)> ReportFn
Definition Remarks.h:352
OptRemarkBase< RemarkKind::RemarkPassed, DiagnosticSeverity::Remark > OptRemarkPass
Definition Remarks.h:266
OptRemarkBase< RemarkKind::RemarkFailure, DiagnosticSeverity::Remark > OptRemarkFailure
Definition Remarks.h:272
OptRemarkBase< RemarkKind::RemarkAnalysis, DiagnosticSeverity::Remark > OptRemarkAnalysis
Definition Remarks.h:263
InFlightRemark withEngine(Fn fn, Location loc, Args &&...args)
Definition Remarks.h:476
Remark & operator<<(Remark &r, StringRef s)
Definition Remarks.h:239
detail::LazyTextBuild suggest(const char *fmt, Ts &&...ts)
Create a Suggestion with llvm::formatv formatting.
Definition Remarks.h:539
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:573
detail::InFlightRemark missed(Location loc, RemarkOpts opts)
Report an optimization remark that was missed.
Definition Remarks.h:567
detail::InFlightRemark analysis(Location loc, RemarkOpts opts)
Report an optimization analysis remark.
Definition Remarks.h:579
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:562
detail::LazyTextBuild metric(StringRef key, V &&v)
Definition Remarks.h:550
detail::LazyTextBuild reason(const char *fmt, Ts &&...ts)
Create a Reason with llvm::formatv formatting.
Definition Remarks.h:533
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:618
static bool isEqual(const mlir::remark::detail::Remark &lhs, const mlir::remark::detail::Remark &rhs)
Definition Remarks.h:641
static mlir::MLIRContext * getStaticDummyContext()
Helper to provide a static dummy context for sentinel keys.
Definition Remarks.h:612
static unsigned getHashValue(const mlir::remark::detail::Remark &remark)
Compute the hash value of the remark.
Definition Remarks.h:634
static mlir::remark::detail::Remark getTombstoneKey()
Create a dead remark.
Definition Remarks.h:626
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:282
std::function< std::string()> thunk
Definition Remarks.h:284
Arg(llvm::StringRef k, T v)
Definition Remarks.h:129
Arg(llvm::StringRef k, llvm::StringRef v)
Definition Remarks.h:112
Arg(llvm::StringRef k, std::string v)
Definition Remarks.h:113
Arg(llvm::StringRef k, const char *v)
Definition Remarks.h:114
Attribute getAttribute() const
Get the attribute if present.
Definition Remarks.h:124
bool hasAttribute() const
Check if this arg has an associated attribute.
Definition Remarks.h:121
Arg(llvm::StringRef k, bool b)
Definition Remarks.h:118
std::optional< Attribute > attr
Optional attribute storage for Attribute-based args.
Definition Remarks.h:109