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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jan 19 23:17:40 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Jeff Niu (Mogball)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/78833.diff


1 Files Affected:

- (modified) mlir/include/mlir/IR/OpImplementation.h (+11-11) 


``````````diff
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.
   };
 

``````````

</details>


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


More information about the Mlir-commits mailing list