13#ifndef MLIR_IR_REMARKS_H
14#define MLIR_IR_REMARKS_H
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"
42 explicit operator bool()
const {
return id != 0; }
51 void print(llvm::raw_ostream &os)
const { os <<
"remark-" << id; }
114 copy.categoryName = v;
120 copy.subCategoryName = v;
126 copy.functionName = v;
158 (llvm::Twine(categoryName) +
":" + subCategoryName)
159 .toVector(fullCategoryName);
177 Arg(llvm::StringRef k, llvm::StringRef v) :
key(k),
val(v) {}
178 Arg(llvm::StringRef k, std::string v) :
key(k),
val(std::move(v)) {}
179 Arg(llvm::StringRef k,
const char *v) :
Arg(k,
llvm::StringRef(v)) {}
181 Arg(llvm::StringRef k,
Type t);
183 Arg(llvm::StringRef k,
bool b) :
key(k),
val(
b ?
"true" :
"false") {}
192 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T> &&
193 !std::is_same_v<T,
bool>>>
195 if constexpr (std::is_floating_point_v<T>) {
196 llvm::raw_string_ostream os(
val);
198 }
else if constexpr (std::is_signed_v<T>) {
199 val = llvm::itostr(
static_cast<long long>(v));
201 val = llvm::utostr(
static_cast<unsigned long long>(v));
206 void insert(llvm::StringRef s);
209 void print(llvm::raw_ostream &os,
bool printLocation =
false)
const;
218 return "<unknown function>";
235 return "<unknown remark name>";
239 std::string
getMsg()
const;
256 args.emplace_back(
"RemarkId", llvm::utostr(
id.getValue()));
267 args.emplace_back(
"RelatedTo", llvm::utostr(relatedId.
getValue()));
314 static llvm::DiagnosticSeverity
318 return llvm::DiagnosticSeverity::DS_Note;
320 return llvm::DiagnosticSeverity::DS_Warning;
322 return llvm::DiagnosticSeverity::DS_Error;
324 return llvm::DiagnosticSeverity::DS_Remark;
326 llvm_unreachable(
"Unknown diagnostic severity");
332 return llvm::DiagnosticKind::DK_Generic;
334 return llvm::DiagnosticKind::DK_OptimizationRemark;
336 return llvm::DiagnosticKind::DK_OptimizationRemarkMissed;
338 return llvm::DiagnosticKind::DK_OptimizationFailure;
340 return llvm::DiagnosticKind::DK_OptimizationRemarkAnalysis;
342 llvm_unreachable(
"Unknown diagnostic kind");
363template <RemarkKind K, DiagnosticSeverity S>
405 : remark(std::move(
diag)) {}
408 : owner(&eng), remark(std::move(
diag)) {}
419 template <
typename T,
typename = std::enable_if_t<
423 *remark << std::forward<T>(arg);
427 explicit operator bool()
const {
return remark !=
nullptr; }
441 std::unique_ptr<Remark>
remark;
489 std::optional<RemarkKind> kind = std::nullopt)
const {
502 std::optional<llvm::Regex> missFilter;
504 std::optional<llvm::Regex> passedFilter;
506 std::optional<llvm::Regex> analysisFilter;
508 std::optional<llvm::Regex> failedFilter;
510 std::unique_ptr<MLIRRemarkStreamerBase> remarkStreamer;
512 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy;
514 bool printAsEmitRemarks =
false;
516 std::atomic<uint64_t> nextRemarkId{1};
521 template <
typename RemarkT>
524 template <
typename RemarkT>
546 initialize(std::unique_ptr<MLIRRemarkStreamerBase> streamer,
547 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy,
548 std::string *errMsg);
552 return remarkEmittingPolicy.get();
557 return RemarkId(nextRemarkId.fetch_add(1, std::memory_order_relaxed));
595 return missFilter.has_value() || passedFilter.has_value() ||
596 analysisFilter.has_value() || failedFilter.has_value();
608 std::optional<RemarkKind> kind = std::nullopt)
const;
630template <
typename Fn,
typename... Args>
636 if (LLVM_UNLIKELY(enginePtr))
637 return (enginePtr->*fn)(loc, std::forward<Args>(args)...);
662 assert(
reportImpl &&
"reportImpl is not set");
680 postponedRemarks.erase(
remark);
681 postponedRemarks.insert(
remark);
690template <
class... Ts>
692 return {
"Reason", [=] {
return llvm::formatv(fmt, ts...).str(); }};
696template <
class... Ts>
698 return {
"Suggestion", [=] {
return llvm::formatv(fmt, ts...).str(); }};
702template <
class... Ts>
704 return {
"Remark", [=] {
return llvm::formatv(fmt, ts...).str(); }};
709 using DV = std::decay_t<V>;
710 return {key, [key, vv = DV(std::forward<V>(v))]()
mutable {
756 std::unique_ptr<remark::detail::MLIRRemarkStreamerBase> streamer,
757 std::unique_ptr<remark::detail::RemarkEmittingPolicyBase>
758 remarkEmittingPolicy,
772 return &dummyContext;
778 return llvm::hash_combine(
789 return lhs.getRemarkName() == rhs.getRemarkName();
793 return lhs.getLocation() == rhs.getLocation() &&
794 lhs.getRemarkName() == rhs.getRemarkName() &&
795 lhs.getCombinedCategoryName() == rhs.getCombinedCategoryName() &&
796 lhs.getRemarkKind() == rhs.getRemarkKind();
if(failed(verifyVectorMemoryOp(getOperation(), memrefType, getVectorType()))) return failure()
static void copy(Location loc, Value dst, Value src, Value size, OpBuilder &builder)
Copies the given number of bytes from src to dst pointers.
static std::string diag(const llvm::Value &value)
Attributes are known-constant values of operations.
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...
const void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
MLIRContext is the top-level object for a collection of MLIR operations.
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...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.