[Mlir-commits] [mlir] fc0fdd1 - [mlir] fix AsmPrinter after c1eab57673ef3e

Alex Zinenko llvmlistbot at llvm.org
Wed Jan 3 09:37:46 PST 2024


Author: Alex Zinenko
Date: 2024-01-03T17:37:41Z
New Revision: fc0fdd1ae20062e4d77c1b7ffc5b06773c752815

URL: https://github.com/llvm/llvm-project/commit/fc0fdd1ae20062e4d77c1b7ffc5b06773c752815
DIFF: https://github.com/llvm/llvm-project/commit/fc0fdd1ae20062e4d77c1b7ffc5b06773c752815.diff

LOG: [mlir] fix AsmPrinter after c1eab57673ef3e

The change in c1eab57673ef3eb2842c0fbe454d7878854cf54c fixed the
behavior of `getDiscardableAttrDictionary` for ops that are not using
properties to only return discardable attributes. AsmPrinter was relying
on the wrong behavior when printing such ops in the generic form,
assuming all attributes are discardable.

Added: 
    

Modified: 
    mlir/lib/IR/AsmPrinter.cpp
    mlir/unittests/IR/OpPropertiesTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 0cc6d11ddc576c..8fe8c78efecf9f 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -3542,8 +3542,9 @@ void OperationPrinter::printGenericOp(Operation *op, bool printOpName) {
     os << ')';
   }
 
-  auto attrs = op->getDiscardableAttrs();
-  printOptionalAttrDict(llvm::to_vector(attrs));
+  printOptionalAttrDict(op->getPropertiesStorage()
+                            ? llvm::to_vector(op->getDiscardableAttrs())
+                            : op->getAttrs());
 
   // Print the type signature of the operation.
   os << " : ";

diff  --git a/mlir/unittests/IR/OpPropertiesTest.cpp b/mlir/unittests/IR/OpPropertiesTest.cpp
index 6dcba16e656b33..bb1b741d1cc223 100644
--- a/mlir/unittests/IR/OpPropertiesTest.cpp
+++ b/mlir/unittests/IR/OpPropertiesTest.cpp
@@ -395,6 +395,12 @@ TEST(OpPropertiesTest, withoutPropertiesDiscardableAttrs) {
   EXPECT_EQ(op->getAttrs().size(), 2u);
   EXPECT_TRUE(op->getInherentAttr("inherent_attr") != std::nullopt);
   EXPECT_TRUE(op->getDiscardableAttr("other_attr") != Attribute());
+
+  std::string output;
+  llvm::raw_string_ostream os(output);
+  op->print(os);
+  EXPECT_TRUE(StringRef(os.str()).contains("inherent_attr = 42"));
+  EXPECT_TRUE(StringRef(os.str()).contains("other_attr = 56"));
 }
 
 } // namespace


        


More information about the Mlir-commits mailing list