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

lonely eagle llvmlistbot at llvm.org
Tue Sep 1 08:46:52 PDT 2026


https://github.com/linuxlonelyeagle updated https://github.com/llvm/llvm-project/pull/217804

>From e5740ace91d704cd1a3ca6499dfcc91c3a3602ae 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/5] 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 d262e844603a1..87a2dd67a9019 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 05f87df9de2b4b95e02e798716ae0b7c63dd4fd0 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/5] 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 d92a93746bf54..b2a56058b1af7 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 3ea9ad8ca0cfc..b580d35784f93 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -944,6 +944,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 87a2dd67a9019..f7396805887f0 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;
@@ -859,6 +869,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 60529ac05929a499dd68ad44c9cb2b26a7225e13 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/5] 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 b2a56058b1af7..0e10be7eac0b5 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 b580d35784f93..6c9d89d02587a 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -946,7 +946,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 f7396805887f0..2c072c6b70456 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() {
@@ -871,7 +871,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 58fd08b02847093f3a3a944e7b4e0a966bfcb394 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/5] 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 0e10be7eac0b5..5711c627ed311 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 6c9d89d02587a..e9e4c602f9969 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -944,8 +944,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.

>From 7d6456d0b88f5eb47aacca1576790c7815b401f6 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Tue, 1 Sep 2026 15:46:30 +0000
Subject: [PATCH 5/5] use SmallVector.

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

diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 5711c627ed311..92eb51e7148b6 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.
-  std::vector<InFlightDiagnostic> emitRemark(const ArrayRef<Twine> messages);
+  SmallVector<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 e9e4c602f9969..16cb76382eefd 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -946,7 +946,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.
-  std::vector<InFlightDiagnostic> emitRemark(const ArrayRef<Twine> messages);
+  SmallVector<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 2c072c6b70456..6b249a1d99a34 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -291,9 +291,9 @@ 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.
-std::vector<InFlightDiagnostic>
+SmallVector<InFlightDiagnostic>
 Operation::emitRemark(const ArrayRef<Twine> messages) {
-  std::vector<InFlightDiagnostic> diags;
+  SmallVector<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())
@@ -871,9 +871,11 @@ 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.
-std::vector<InFlightDiagnostic>
+SmallVector<InFlightDiagnostic>
 OpState::emitRemark(const ArrayRef<Twine> messages) {
-  return getOperation()->emitRemark(messages);
+  // Explicitly move to transfer ownership, preventing temporary diagnostics
+  // from destructing in reverse order and emitting early.
+  return std::move(getOperation()->emitRemark(messages));
 }
 
 //===----------------------------------------------------------------------===//



More information about the Mlir-commits mailing list