[Mlir-commits] [mlir] [MLIR] Always emit setPropertiesFromParsedAttr() when hasCustomAssemblyFormat is set (PR #145973)

Mehdi Amini llvmlistbot at llvm.org
Thu Jun 26 14:04:25 PDT 2025


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/145973

This allows people writing custom C++ assembly functions to reuse the "prop-dict" parser.

Fix #145028

>From ebb1ac1227db58843d36e4aec04fd26d56c5aebb Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Thu, 26 Jun 2025 14:01:56 -0700
Subject: [PATCH] [MLIR] Always emit setPropertiesFromParsedAttr() when
 hasCustomAssemblyFormat is set

This allows people writing custom C++ assembly functions to reuse the
"prop-dict" parser.

Fix #145028
---
 mlir/test/mlir-tblgen/op-decl-and-defs.td | 1 +
 mlir/tools/mlir-tblgen/OpFormatGen.cpp    | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td
index a3dce9b31f8d2..3ccefd4d82366 100644
--- a/mlir/test/mlir-tblgen/op-decl-and-defs.td
+++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td
@@ -125,6 +125,7 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
 // CHECK:   ::llvm::LogicalResult verifyInvariants();
 // CHECK:   static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context);
 // CHECK:   ::llvm::LogicalResult fold(FoldAdaptor adaptor, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results);
+// CHECK:   static ::llvm::LogicalResult setPropertiesFromParsedAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
 // CHECK:   // Display a graph for debugging purposes.
 // CHECK:   void displayGraph();
 // CHECK: };
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 11edf2523f1aa..0c62e803ece8a 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -3848,8 +3848,14 @@ void mlir::tblgen::generateOpFormat(const Operator &constOp, OpClass &opClass,
   // TODO: Operator doesn't expose all necessary functionality via
   // the const interface.
   Operator &op = const_cast<Operator &>(constOp);
-  if (!op.hasAssemblyFormat())
+  if (!op.hasAssemblyFormat()) {
+    // We still need to generate the parsed attribute properties setter for
+    // allowing it to be reused in custom assembly implementations.
+    OperationFormat format(op, hasProperties);
+    format.hasPropDict = true;
+    genParsedAttrPropertiesSetter(format, op, opClass);
     return;
+  }
 
   // Parse the format description.
   llvm::SourceMgr mgr;



More information about the Mlir-commits mailing list