13#ifndef MLIR_IR_REMARKS_H
14#define MLIR_IR_REMARKS_H
16#include "llvm/ADT/DenseSet.h"
17#include "llvm/ADT/STLFunctionalExtras.h"
18#include "llvm/ADT/StringExtras.h"
19#include "llvm/IR/DiagnosticInfo.h"
20#include "llvm/Remarks/Remark.h"
21#include "llvm/Support/FormatVariadic.h"
22#include "llvm/Support/Regex.h"
47 explicit operator bool()
const {
return id != 0; }
56 void print(llvm::raw_ostream &os)
const { os <<
"remark-" << id; }
120 copy.categoryName = v;
126 copy.subCategoryName = v;
132 copy.functionName = v;
163 remarkName = value.str();
164 return std::move(*
this);
171 categoryName = value.str();
172 return std::move(*
this);
178 subCategoryName = value.str();
179 return std::move(*
this);
185 functionName = value.str();
186 return std::move(*
this);
193 return std::move(*
this);
201 return std::move(*
this);
206 std::optional<std::string> remarkName, categoryName, subCategoryName,
208 std::optional<RemarkKind> remarkKind;
209 std::optional<Location> location;
227 (llvm::Twine(categoryName) +
":" + subCategoryName)
228 .toVector(fullCategoryName);
248 Arg(llvm::StringRef k, llvm::StringRef v) :
key(k),
val(v) {}
249 Arg(llvm::StringRef k, std::string v) :
key(k),
val(std::move(v)) {}
250 Arg(llvm::StringRef k,
const char *v) :
Arg(k,
llvm::StringRef(v)) {}
252 Arg(llvm::StringRef k,
Type t);
254 Arg(llvm::StringRef k,
bool b) :
key(k),
val(
b ?
"true" :
"false") {}
263 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T> &&
264 !std::is_same_v<T,
bool>>>
266 if constexpr (std::is_floating_point_v<T>) {
267 llvm::raw_string_ostream os(
val);
269 }
else if constexpr (std::is_signed_v<T>) {
270 val = llvm::itostr(
static_cast<long long>(v));
272 val = llvm::utostr(
static_cast<unsigned long long>(v));
277 void insert(llvm::StringRef s);
280 void print(llvm::raw_ostream &os,
bool printLocation =
false)
const;
289 return "<unknown function>";
311 return "<unknown remark name>";
318 std::string
getMsg()
const;
336 args.emplace_back(
"RemarkId", llvm::utostr(
id.getValue()));
351 args.emplace_back(
"RelatedTo", llvm::utostr(relatedId.
getValue()));
398 static llvm::DiagnosticSeverity
402 return llvm::DiagnosticSeverity::DS_Note;
404 return llvm::DiagnosticSeverity::DS_Warning;
406 return llvm::DiagnosticSeverity::DS_Error;
408 return llvm::DiagnosticSeverity::DS_Remark;
410 llvm_unreachable(
"Unknown diagnostic severity");
416 return llvm::DiagnosticKind::DK_Generic;
418 return llvm::DiagnosticKind::DK_OptimizationRemark;
420 return llvm::DiagnosticKind::DK_OptimizationRemarkMissed;
422 return llvm::DiagnosticKind::DK_OptimizationFailure;
424 return llvm::DiagnosticKind::DK_OptimizationRemarkAnalysis;
426 llvm_unreachable(
"Unknown diagnostic kind");
447template <RemarkKind K, DiagnosticSeverity S>
491 : remark(std::move(
diag)) {}
494 : owner(&eng), remark(std::move(
diag)) {}
507 template <
typename T,
508 typename = std::enable_if_t<
513 *remark << std::forward<T>(arg);
517 explicit operator bool()
const {
return remark !=
nullptr; }
531 std::unique_ptr<Remark>
remark;
585 if (
remark.getLocation() == loc)
599 std::optional<llvm::Regex> missFilter;
601 std::optional<llvm::Regex> passedFilter;
603 std::optional<llvm::Regex> analysisFilter;
605 std::optional<llvm::Regex> failedFilter;
611 std::unique_ptr<RemarkHistory> history;
612 std::atomic<bool> historyEnabled{
false};
614 std::unique_ptr<MLIRRemarkStreamerBase> remarkStreamer;
616 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy;
618 bool printAsEmitRemarks =
false;
620 std::atomic<uint64_t> nextRemarkId{1};
625 template <
typename RemarkT>
628 template <
typename RemarkT>
650 initialize(std::unique_ptr<MLIRRemarkStreamerBase> streamer,
651 std::unique_ptr<RemarkEmittingPolicyBase> remarkEmittingPolicy,
652 std::string *errMsg);
656 return remarkEmittingPolicy.get();
661 return RemarkId(nextRemarkId.fetch_add(1, std::memory_order_relaxed));
699 return missFilter.has_value() || passedFilter.has_value() ||
700 analysisFilter.has_value() || failedFilter.has_value();
728 std::optional<RemarkKind> kind = std::nullopt)
const;
750template <
typename Fn,
typename... Args>
756 if (LLVM_UNLIKELY(enginePtr))
757 return (enginePtr->*fn)(loc, std::forward<Args>(args)...);
775 return {std::move(
query)};
788 assert(
reportImpl &&
"reportImpl is not set");
818 struct RemarkPtrInfo {
820 getHashValue(
const std::unique_ptr<detail::Remark> &
remark) {
821 return getHashValue(*
remark);
824 static bool isEqual(
const std::unique_ptr<detail::Remark> &lhs,
825 const std::unique_ptr<detail::Remark> &rhs) {
826 return isEqual(*lhs, rhs);
828 static bool isEqual(
const detail::Remark &lhs,
829 const std::unique_ptr<detail::Remark> &rhs);
832 mutable std::mutex mutex;
835 using LocationIndex =
838 mutable std::unique_ptr<LocationIndex> pendingByLocation;
844template <
class... Ts>
846 return {
"Reason", [=] {
return llvm::formatv(fmt, ts...).str(); }};
850template <
class... Ts>
852 return {
"Suggestion", [=] {
return llvm::formatv(fmt, ts...).str(); }};
856template <
class... Ts>
858 return {
"Remark", [=] {
return llvm::formatv(fmt, ts...).str(); }};
863 using DV = std::decay_t<V>;
864 return {key, [key, vv = DV(std::forward<V>(v))]()
mutable {
910 std::unique_ptr<remark::detail::MLIRRemarkStreamerBase> streamer,
911 std::unique_ptr<remark::detail::RemarkEmittingPolicyBase>
912 remarkEmittingPolicy,
923 return llvm::hash_combine(
932 return lhs.getLocation() == rhs.getLocation() &&
933 lhs.getRemarkName() == rhs.getRemarkName() &&
934 lhs.getCombinedCategoryName() == rhs.getCombinedCategoryName() &&
935 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.