13#ifndef MLIR_IR_REMARKS_H
14#define MLIR_IR_REMARKS_H
16#include "llvm/ADT/DenseSet.h"
17#include "llvm/ADT/StringExtras.h"
18#include "llvm/IR/DiagnosticInfo.h"
19#include "llvm/Remarks/Remark.h"
20#include "llvm/Support/FormatVariadic.h"
21#include "llvm/Support/Regex.h"
45 explicit operator bool()
const {
return id != 0; }
54 void print(llvm::raw_ostream &os)
const { os <<
"remark-" << id; }
117 copy.categoryName = v;
123 copy.subCategoryName = v;
129 copy.functionName = v;
161 (llvm::Twine(categoryName) +
":" + subCategoryName)
162 .toVector(fullCategoryName);
182 Arg(llvm::StringRef k, llvm::StringRef v) :
key(k),
val(v) {}
183 Arg(llvm::StringRef k, std::string v) :
key(k),
val(std::move(v)) {}
184 Arg(llvm::StringRef k,
const char *v) :
Arg(k,
llvm::StringRef(v)) {}
186 Arg(llvm::StringRef k,
Type t);
188 Arg(llvm::StringRef k,
bool b) :
key(k),
val(
b ?
"true" :
"false") {}
197 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T> &&
198 !std::is_same_v<T,
bool>>>
200 if constexpr (std::is_floating_point_v<T>) {
201 llvm::raw_string_ostream os(
val);
203 }
else if constexpr (std::is_signed_v<T>) {
204 val = llvm::itostr(
static_cast<long long>(v));
206 val = llvm::utostr(
static_cast<unsigned long long>(v));
211 void insert(llvm::StringRef s);
214 void print(llvm::raw_ostream &os,
bool printLocation =
false)
const;
223 return "<unknown function>";
240 return "<unknown remark name>";
244 std::string
getMsg()
const;
262 args.emplace_back(
"RemarkId", llvm::utostr(
id.getValue()));
277 args.emplace_back(
"RelatedTo", llvm::utostr(relatedId.
getValue()));
324 static llvm::DiagnosticSeverity
328 return llvm::DiagnosticSeverity::DS_Note;
330 return llvm::DiagnosticSeverity::DS_Warning;
332 return llvm::DiagnosticSeverity::DS_Error;
334 return llvm::DiagnosticSeverity::DS_Remark;
336 llvm_unreachable(
"Unknown diagnostic severity");
342 return llvm::DiagnosticKind::DK_Generic;
344 return llvm::DiagnosticKind::DK_OptimizationRemark;
346 return llvm::DiagnosticKind::DK_OptimizationRemarkMissed;
348 return llvm::DiagnosticKind::DK_OptimizationFailure;
350 return llvm::DiagnosticKind::DK_OptimizationRemarkAnalysis;
352 llvm_unreachable(
"Unknown diagnostic kind");
373template <RemarkKind K, DiagnosticSeverity S>
415 : remark(std::move(
diag)) {}
418 : owner(&eng), remark(std::move(
diag)) {}
429 template <
typename T,
typename = std::enable_if_t<
433 *remark << std::forward<T>(arg);
437 explicit operator bool()
const {
return remark !=
nullptr; }
451 std::unique_ptr<Remark>
remark;
499 std::optional<RemarkKind> kind = std::nullopt)
const {
512 std::optional<llvm::Regex> missFilter;
514 std::optional<llvm::Regex> passedFilter;
516 std::optional<llvm::Regex> analysisFilter;
518 std::optional<llvm::Regex> failedFilter;
520 std::unique_ptr<MLIRRemarkStreamerBase> remarkStreamer;
522 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy;
524 bool printAsEmitRemarks =
false;
526 std::atomic<uint64_t> nextRemarkId{1};
531 template <
typename RemarkT>
534 template <
typename RemarkT>
556 initialize(std::unique_ptr<MLIRRemarkStreamerBase> streamer,
557 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy,
558 std::string *errMsg);
562 return remarkEmittingPolicy.get();
567 return RemarkId(nextRemarkId.fetch_add(1, std::memory_order_relaxed));
605 return missFilter.has_value() || passedFilter.has_value() ||
606 analysisFilter.has_value() || failedFilter.has_value();
618 std::optional<RemarkKind> kind = std::nullopt)
const;
640template <
typename Fn,
typename... Args>
646 if (LLVM_UNLIKELY(enginePtr))
647 return (enginePtr->*fn)(loc, std::forward<Args>(args)...);
672 assert(
reportImpl &&
"reportImpl is not set");
702template <
class... Ts>
704 return {
"Reason", [=] {
return llvm::formatv(fmt, ts...).str(); }};
708template <
class... Ts>
710 return {
"Suggestion", [=] {
return llvm::formatv(fmt, ts...).str(); }};
714template <
class... Ts>
716 return {
"Remark", [=] {
return llvm::formatv(fmt, ts...).str(); }};
721 using DV = std::decay_t<V>;
722 return {key, [key, vv = DV(std::forward<V>(v))]()
mutable {
768 std::unique_ptr<remark::detail::MLIRRemarkStreamerBase> streamer,
769 std::unique_ptr<remark::detail::RemarkEmittingPolicyBase>
770 remarkEmittingPolicy,
781 return llvm::hash_combine(
790 return lhs.getLocation() == rhs.getLocation() &&
791 lhs.getRemarkName() == rhs.getRemarkName() &&
792 lhs.getCombinedCategoryName() == rhs.getCombinedCategoryName() &&
793 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.
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.