[Mlir-commits] [mlir] [mlir] Add emitRemark overload taking ArrayRef<Twine> (PR #217804)
lonely eagle
llvmlistbot at llvm.org
Thu Aug 27 19:48:49 PDT 2026
https://github.com/linuxlonelyeagle updated https://github.com/llvm/llvm-project/pull/217804
>From f5b8f0888c02a5c8a9d2e9423740b5d96cd952ad Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Fri, 21 Aug 2026 02:27:45 +0000
Subject: [PATCH 1/3] make emitWarning/emitRemark use OpWithFlags.
---
mlir/lib/IR/Operation.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index b7227d0802ea8..937333b30e14c 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -276,7 +276,9 @@ InFlightDiagnostic Operation::emitError(const Twine &message) {
InFlightDiagnostic Operation::emitWarning(const Twine &message) {
InFlightDiagnostic diag = mlir::emitWarning(getLoc(), message);
if (getContext()->shouldPrintOpOnDiagnostic())
- diag.attachNote(getLoc()) << "see current operation: " << *this;
+ diag.attachNote(getLoc())
+ << "see current operation: "
+ << OpWithFlags(this, OpPrintingFlags().skipRegions());
return diag;
}
@@ -285,7 +287,9 @@ InFlightDiagnostic Operation::emitWarning(const Twine &message) {
InFlightDiagnostic Operation::emitRemark(const Twine &message) {
InFlightDiagnostic diag = mlir::emitRemark(getLoc(), message);
if (getContext()->shouldPrintOpOnDiagnostic())
- diag.attachNote(getLoc()) << "see current operation: " << *this;
+ diag.attachNote(getLoc())
+ << "see current operation: "
+ << OpWithFlags(this, OpPrintingFlags().skipRegions());
return diag;
}
>From 0cd6d215c90a52777224539c79b0df3b51bbbd32 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Thu, 27 Aug 2026 16:40:58 +0000
Subject: [PATCH 2/3] add new emitRemark method use ArrayRef<Twine> as
parameter.
---
mlir/include/mlir/IR/OpDefinition.h | 4 ++++
mlir/include/mlir/IR/Operation.h | 4 ++++
mlir/lib/IR/Operation.cpp | 28 ++++++++++++++++++++++------
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index fe2fa0a0ccd23..057f17222fe68 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -150,6 +150,10 @@ class OpState {
/// handlers that may be listening.
InFlightDiagnostic emitRemark(const Twine &message = {});
+ // Emit a remark about this operation for each message, reporting up to
+ /// any diagnostic handlers that may be listening.
+ InFlightDiagnostic emitRemark(const ArrayRef<Twine> messages);
+
/// Walk the operation by calling the callback for each nested operation
/// (including this one), block or region, depending on the callback provided.
/// The order in which regions, blocks and operations the same nesting level
diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index 793c046fbf2e5..404a4b0c50cae 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -917,6 +917,10 @@ class alignas(8) Operation final
/// handlers that may be listening.
InFlightDiagnostic emitRemark(const Twine &message = {});
+ // Emit a remark about this operation for each message, reporting up to
+ /// any diagnostic handlers that may be listening.
+ InFlightDiagnostic emitRemark(const ArrayRef<Twine> messages);
+
/// Returns the properties storage size.
int getPropertiesStorageSize() const {
return ((int)propertiesStorageSize) * 8;
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 937333b30e14c..6d6ff77206205 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -276,9 +276,7 @@ InFlightDiagnostic Operation::emitError(const Twine &message) {
InFlightDiagnostic Operation::emitWarning(const Twine &message) {
InFlightDiagnostic diag = mlir::emitWarning(getLoc(), message);
if (getContext()->shouldPrintOpOnDiagnostic())
- diag.attachNote(getLoc())
- << "see current operation: "
- << OpWithFlags(this, OpPrintingFlags().skipRegions());
+ diag.attachNote(getLoc()) << "see current operation: " << *this;
return diag;
}
@@ -287,12 +285,24 @@ InFlightDiagnostic Operation::emitWarning(const Twine &message) {
InFlightDiagnostic Operation::emitRemark(const Twine &message) {
InFlightDiagnostic diag = mlir::emitRemark(getLoc(), message);
if (getContext()->shouldPrintOpOnDiagnostic())
- diag.attachNote(getLoc())
- << "see current operation: "
- << OpWithFlags(this, OpPrintingFlags().skipRegions());
+ diag.attachNote(getLoc()) << "see current operation: " << *this;
return diag;
}
+/// Emit a remark about this operation for each message, reporting up to
+/// any diagnostic handlers that may be listening.
+InFlightDiagnostic Operation::emitRemark(const ArrayRef<Twine> messages) {
+ assert(!messages.empty() && "emitRemark messages is empty");
+ for (size_t i = 0, e = messages.size(); i < e; ++i) {
+ InFlightDiagnostic diag = mlir::emitRemark(getLoc(), messages[i]);
+ if (i == e - 1 && getContext()->shouldPrintOpOnDiagnostic()) {
+ diag.attachNote(getLoc()) << "see current operation: " << *this;
+ return diag;
+ }
+ }
+ return {};
+}
+
DictionaryAttr Operation::getAttrDictionary() {
if (getPropertiesStorageSize()) {
NamedAttrList attrsList = attrs;
@@ -858,6 +868,12 @@ InFlightDiagnostic OpState::emitRemark(const Twine &message) {
return getOperation()->emitRemark(message);
}
+/// Emit a remark about this operation for each message, reporting up to
+/// any diagnostic handlers that may be listening.
+InFlightDiagnostic OpState::emitRemark(const ArrayRef<Twine> messages) {
+ return getOperation()->emitRemark(messages);
+}
+
//===----------------------------------------------------------------------===//
// Op Trait implementations
//===----------------------------------------------------------------------===//
>From 3f8c0cbba924e2b8ce759a791c1510816ed75326 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Fri, 28 Aug 2026 02:48:33 +0000
Subject: [PATCH 3/3] make emitRemark return vector<InFlightDiagnostic>c>.
---
mlir/include/mlir/IR/OpDefinition.h | 4 +++-
mlir/include/mlir/IR/Operation.h | 2 +-
mlir/lib/IR/Operation.cpp | 15 ++++++++-------
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 057f17222fe68..e2bec838a25b4 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -22,10 +22,12 @@
#include "mlir/IR/Dialect.h"
#include "mlir/IR/ODSSupport.h"
#include "mlir/IR/Operation.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
#include <optional>
#include <type_traits>
+#include <vector>
namespace mlir {
class Builder;
@@ -152,7 +154,7 @@ class OpState {
// Emit a remark about this operation for each message, reporting up to
/// any diagnostic handlers that may be listening.
- InFlightDiagnostic emitRemark(const ArrayRef<Twine> messages);
+ std::vector<InFlightDiagnostic> emitRemark(const ArrayRef<Twine> messages);
/// Walk the operation by calling the callback for each nested operation
/// (including this one), block or region, depending on the callback provided.
diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index 404a4b0c50cae..07a473254b8cd 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -919,7 +919,7 @@ class alignas(8) Operation final
// Emit a remark about this operation for each message, reporting up to
/// any diagnostic handlers that may be listening.
- InFlightDiagnostic emitRemark(const ArrayRef<Twine> messages);
+ std::vector<InFlightDiagnostic> emitRemark(const ArrayRef<Twine> messages);
/// Returns the properties storage size.
int getPropertiesStorageSize() const {
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 6d6ff77206205..47e173957494d 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -291,16 +291,16 @@ InFlightDiagnostic Operation::emitRemark(const Twine &message) {
/// Emit a remark about this operation for each message, reporting up to
/// any diagnostic handlers that may be listening.
-InFlightDiagnostic Operation::emitRemark(const ArrayRef<Twine> messages) {
- assert(!messages.empty() && "emitRemark messages is empty");
+std::vector<InFlightDiagnostic>
+Operation::emitRemark(const ArrayRef<Twine> messages) {
+ std::vector<InFlightDiagnostic> diags;
for (size_t i = 0, e = messages.size(); i < e; ++i) {
InFlightDiagnostic diag = mlir::emitRemark(getLoc(), messages[i]);
- if (i == e - 1 && getContext()->shouldPrintOpOnDiagnostic()) {
+ if (i == e - 1 && getContext()->shouldPrintOpOnDiagnostic())
diag.attachNote(getLoc()) << "see current operation: " << *this;
- return diag;
- }
+ diags.push_back(std::move(diag));
}
- return {};
+ return diags;
}
DictionaryAttr Operation::getAttrDictionary() {
@@ -870,7 +870,8 @@ InFlightDiagnostic OpState::emitRemark(const Twine &message) {
/// Emit a remark about this operation for each message, reporting up to
/// any diagnostic handlers that may be listening.
-InFlightDiagnostic OpState::emitRemark(const ArrayRef<Twine> messages) {
+std::vector<InFlightDiagnostic>
+OpState::emitRemark(const ArrayRef<Twine> messages) {
return getOperation()->emitRemark(messages);
}
More information about the Mlir-commits
mailing list