Skip to content

Commit fc0fdd1

Browse files
committed
[mlir] fix AsmPrinter after c1eab57
The change in c1eab57 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.
1 parent 03e29a4 commit fc0fdd1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,8 +3542,9 @@ void OperationPrinter::printGenericOp(Operation *op, bool printOpName) {
35423542
os << ')';
35433543
}
35443544

3545-
auto attrs = op->getDiscardableAttrs();
3546-
printOptionalAttrDict(llvm::to_vector(attrs));
3545+
printOptionalAttrDict(op->getPropertiesStorage()
3546+
? llvm::to_vector(op->getDiscardableAttrs())
3547+
: op->getAttrs());
35473548

35483549
// Print the type signature of the operation.
35493550
os << " : ";

mlir/unittests/IR/OpPropertiesTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ TEST(OpPropertiesTest, withoutPropertiesDiscardableAttrs) {
395395
EXPECT_EQ(op->getAttrs().size(), 2u);
396396
EXPECT_TRUE(op->getInherentAttr("inherent_attr") != std::nullopt);
397397
EXPECT_TRUE(op->getDiscardableAttr("other_attr") != Attribute());
398+
399+
std::string output;
400+
llvm::raw_string_ostream os(output);
401+
op->print(os);
402+
EXPECT_TRUE(StringRef(os.str()).contains("inherent_attr = 42"));
403+
EXPECT_TRUE(StringRef(os.str()).contains("other_attr = 56"));
398404
}
399405

400406
} // namespace

0 commit comments

Comments
 (0)