[Mlir-commits] [mlir] [mlir] Add emitRemark overload taking ArrayRef<Twine> (PR #217804)

lonely eagle llvmlistbot at llvm.org
Sat Aug 29 01:05:31 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/4] 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/4] 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 db782e9432f79adf1fe535377a202605d2ed4a86 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/4] make emitRemark return vector<InFlightDiagnostic>c>.

---
 mlir/include/mlir/IR/OpDefinition.h |  2 +-
 mlir/include/mlir/IR/Operation.h    |  2 +-
 mlir/lib/IR/Operation.cpp           | 15 ++++++++-------
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 057f17222fe68..3aceb7e288ef1 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -152,7 +152,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);
 }
 

>From 74dc4f376261ed3e92c7890c04367160bb2a8de7 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Sat, 29 Aug 2026 07:55:39 +0000
Subject: [PATCH 4/4] fix comment.

---
 mlir/include/mlir/IR/OpDefinition.h | 4 ++--
 mlir/include/mlir/IR/Operation.h    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 3aceb7e288ef1..6d1f206bfdd28 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -150,8 +150,8 @@ 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.
+  /// Emit a remark about this operation for each message, reporting up to any
+  /// diagnostic handlers that may be listening.
   std::vector<InFlightDiagnostic> emitRemark(const ArrayRef<Twine> messages);
 
   /// Walk the operation by calling the callback for each nested operation
diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index 07a473254b8cd..5068b0eb21f67 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -917,8 +917,8 @@ 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.
+  /// Emit a remark about this operation for each message, reporting up to any
+  /// diagnostic handlers that may be listening.
   std::vector<InFlightDiagnostic> emitRemark(const ArrayRef<Twine> messages);
 
   /// Returns the properties storage size.



More information about the Mlir-commits mailing list