Skip to content

Commit 7e5fbe8

Browse files
committed
[mlir] Fix TableGen emission for ops without properties
The current condition to emit `setPropertiesFromParsedAttr` is not strict enough since we emit the method even when we do not have properties at all. Similarly we should not emit `parseProperties` and `printProperties` if we don't have properties.
1 parent 9d0616c commit 7e5fbe8

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

mlir/test/IR/properties.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ test.with_nice_properties "foo bar" is -3
1919
// GENERIC-SAME: <{prop = "content for properties"}> : () -> ()
2020
test.with_wrapped_properties <{prop = "content for properties"}>
2121

22+
// CHECK: test.empty_properties
23+
// GENERIC: "test.empty_properties"()
24+
test.empty_properties
25+
2226
// CHECK: test.using_property_in_custom
2327
// CHECK-SAME: [1, 4, 20]{{$}}
2428
// GENERIC: "test.using_property_in_custom"()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,11 @@ def TestOpWithWrappedProperties : TEST_Op<"with_wrapped_properties"> {
30063006
);
30073007
}
30083008

3009+
def TestOpWithEmptyProperties : TEST_Op<"empty_properties"> {
3010+
let assemblyFormat = "prop-dict attr-dict";
3011+
let arguments = (ins);
3012+
}
3013+
30093014
def TestOpUsingPropertyInCustom : TEST_Op<"using_property_in_custom"> {
30103015
let assemblyFormat = "custom<UsingPropertyInCustom>($prop) attr-dict";
30113016
let arguments = (ins IntArrayProperty<"int64_t">:$prop);

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,8 +1275,9 @@ static void genAttrParser(AttributeVariable *attr, MethodBody &body,
12751275
// 'prop-dict' dictionary attr.
12761276
static void genParsedAttrPropertiesSetter(OperationFormat &fmt, Operator &op,
12771277
OpClass &opClass) {
1278-
// Not required unless 'prop-dict' is present.
1279-
if (!fmt.hasPropDict)
1278+
// Not required unless 'prop-dict' is present or we
1279+
// are not using properties.
1280+
if (!fmt.hasPropDict || !fmt.useProperties)
12801281
return;
12811282

12821283
SmallVector<MethodParameter> paramList;
@@ -1621,8 +1622,10 @@ void OperationFormat::genElementParser(FormatElement *element, MethodBody &body,
16211622
body.unindent() << "}\n";
16221623
body.unindent();
16231624
} else if (isa<PropDictDirective>(element)) {
1624-
body << " if (parseProperties(parser, result))\n"
1625-
<< " return ::mlir::failure();\n";
1625+
if (useProperties) {
1626+
body << " if (parseProperties(parser, result))\n"
1627+
<< " return ::mlir::failure();\n";
1628+
}
16261629
} else if (auto *customDir = dyn_cast<CustomDirective>(element)) {
16271630
genCustomDirectiveParser(customDir, body, useProperties, opCppClassName);
16281631
} else if (isa<OperandsDirective>(element)) {
@@ -2047,9 +2050,11 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
20472050
}
20482051
}
20492052

2050-
body << " _odsPrinter << \" \";\n"
2051-
<< " printProperties(this->getContext(), _odsPrinter, "
2052-
"getProperties(), elidedProps);\n";
2053+
if (fmt.useProperties) {
2054+
body << " _odsPrinter << \" \";\n"
2055+
<< " printProperties(this->getContext(), _odsPrinter, "
2056+
"getProperties(), elidedProps);\n";
2057+
}
20532058
}
20542059

20552060
/// Generate the printer for the 'attr-dict' directive.

0 commit comments

Comments
 (0)