Skip to content

Commit 4d60be0

Browse files
bealwangBiao Wang
andauthored
[mlir] Do not print empty property (#93379)
Skip printing property as `<<<NULL ATTRIBUTE>>>` when operation has an empty property. Co-authored-by: Biao Wang <[email protected]>
1 parent f2a385c commit 4d60be0

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

mlir/lib/IR/Operation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@ ParseResult OpState::genericParseProperties(OpAsmParser &parser,
801801
/// 'elidedProps'
802802
void OpState::genericPrintProperties(OpAsmPrinter &p, Attribute properties,
803803
ArrayRef<StringRef> elidedProps) {
804+
if (!properties)
805+
return;
804806
auto dictAttr = dyn_cast_or_null<::mlir::DictionaryAttr>(properties);
805807
if (dictAttr && !elidedProps.empty()) {
806808
ArrayRef<NamedAttribute> attrs = dictAttr.getValue();

mlir/test/IR/properties.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ test.using_property_ref_in_custom 1 + 4 = 5
3838
// GENERIC: "test.with_default_valued_properties"()
3939
// GENERIC-SAME: <{a = 0 : i32}>
4040
test.with_default_valued_properties <{a = 0 : i32}>
41+
42+
// CHECK: test.with_optional_properties
43+
// CHECK-SAME: <{b = 0 : i32}>
44+
// GENERIC: "test.with_optional_properties"()
45+
// GENERIC-SAME: <{b = 0 : i32}>
46+
test.with_optional_properties <{b = 0 : i32}>
47+
48+
// CHECK: test.with_optional_properties {{$}}
49+
// GENERIC: "test.with_optional_properties"()
50+
// GENERIC-SAME: : () -> ()
51+
test.with_optional_properties

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,11 @@ def TestOpWithDefaultValuedProperties : TEST_Op<"with_default_valued_properties"
31133113
let arguments = (ins DefaultValuedAttr<I32Attr, "0">:$a);
31143114
}
31153115

3116+
def TestOpWithOptionalProperties : TEST_Op<"with_optional_properties"> {
3117+
let assemblyFormat = "prop-dict attr-dict";
3118+
let arguments = (ins OptionalAttr<I32Attr>:$a, OptionalAttr<I32Attr>:$b);
3119+
}
3120+
31163121
//===----------------------------------------------------------------------===//
31173122
// Test Dataflow
31183123
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)