[Mlir-commits] [mlir] [mlir] Make `printAlias` hooks public (NFC) (PR #78833)

Jeff Niu llvmlistbot at llvm.org
Fri Jan 19 23:17:11 PST 2024


https://github.com/Mogball created https://github.com/llvm/llvm-project/pull/78833

These are very useful when writing custom parsers and printers for aggregate types or attributes that might want to print aliases.

>From 9875d470d643f2c9fb46120c7a231ce92e8471d1 Mon Sep 17 00:00:00 2001
From: Mogball <jeff at modular.com>
Date: Fri, 19 Jan 2024 23:13:14 -0800
Subject: [PATCH] [mlir] Make `printAlias` hooks public (NFC)

These are very useful when writing custom parsers and printers for
aggregate types or attributes that might want to print aliases.
---
 mlir/include/mlir/IR/OpImplementation.h | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index 86ed14e7ca8439..5333d7446df5ca 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -180,6 +180,14 @@ class AsmPrinter {
   /// provide a valid type for the attribute.
   virtual void printAttributeWithoutType(Attribute attr);
 
+  /// Print the alias for the given attribute, return failure if no alias could
+  /// be printed.
+  virtual LogicalResult printAlias(Attribute attr);
+
+  /// Print the alias for the given type, return failure if no alias could
+  /// be printed.
+  virtual LogicalResult printAlias(Type type);
+
   /// Print the given string as a keyword, or a quoted and escaped string if it
   /// has any special or non-printable characters in it.
   virtual void printKeywordOrString(StringRef keyword);
@@ -295,14 +303,6 @@ class AsmPrinter {
   AsmPrinter(const AsmPrinter &) = delete;
   void operator=(const AsmPrinter &) = delete;
 
-  /// Print the alias for the given attribute, return failure if no alias could
-  /// be printed.
-  virtual LogicalResult printAlias(Attribute attr);
-
-  /// Print the alias for the given type, return failure if no alias could
-  /// be printed.
-  virtual LogicalResult printAlias(Type type);
-
   /// The internal implementation of the printer.
   Impl *impl{nullptr};
 };
@@ -1597,9 +1597,9 @@ class OpAsmParser : public AsmParser {
   //===--------------------------------------------------------------------===//
 
   struct Argument {
-    UnresolvedOperand ssaName;    // SourceLoc, SSA name, result #.
-    Type type;                    // Type.
-    DictionaryAttr attrs;         // Attributes if present.
+    UnresolvedOperand ssaName;         // SourceLoc, SSA name, result #.
+    Type type;                         // Type.
+    DictionaryAttr attrs;              // Attributes if present.
     std::optional<Location> sourceLoc; // Source location specifier if present.
   };
 



More information about the Mlir-commits mailing list