[mlir] fix AsmPrinter after c1eab57673

The change in c1eab57673 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.
This commit is contained in:
Alex Zinenko
2024-01-03 17:31:16 +00:00
parent 03e29a49d9
commit fc0fdd1ae2
2 changed files with 9 additions and 2 deletions

View File

@@ -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 << " : ";

View File

@@ -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