-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir] Fix the emission of prop-dict
when operations have no properties
#112851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: lorenzo chelini (chelini) ChangesThe current condition to emit Full diff: https://github.com/llvm/llvm-project/pull/112851.diff 3 Files Affected:
diff --git a/mlir/test/IR/properties.mlir b/mlir/test/IR/properties.mlir
index 418b81dcbb034f..9a1c49cb7dabf3 100644
--- a/mlir/test/IR/properties.mlir
+++ b/mlir/test/IR/properties.mlir
@@ -19,6 +19,10 @@ test.with_nice_properties "foo bar" is -3
// GENERIC-SAME: <{prop = "content for properties"}> : () -> ()
test.with_wrapped_properties <{prop = "content for properties"}>
+// CHECK: test.empty_properties
+// GENERIC: "test.empty_properties"()
+test.empty_properties
+
// CHECK: test.using_property_in_custom
// CHECK-SAME: [1, 4, 20]{{$}}
// GENERIC: "test.using_property_in_custom"()
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 9e19966414d1d7..bc6c6cf213ea4b 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -3006,6 +3006,11 @@ def TestOpWithWrappedProperties : TEST_Op<"with_wrapped_properties"> {
);
}
+def TestOpWithEmptyProperties : TEST_Op<"empty_properties"> {
+ let assemblyFormat = "prop-dict attr-dict";
+ let arguments = (ins);
+}
+
def TestOpUsingPropertyInCustom : TEST_Op<"using_property_in_custom"> {
let assemblyFormat = "custom<UsingPropertyInCustom>($prop) attr-dict";
let arguments = (ins IntArrayProperty<"int64_t">:$prop);
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index c99c71572bec23..4703de67025ded 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -1275,8 +1275,9 @@ static void genAttrParser(AttributeVariable *attr, MethodBody &body,
// 'prop-dict' dictionary attr.
static void genParsedAttrPropertiesSetter(OperationFormat &fmt, Operator &op,
OpClass &opClass) {
- // Not required unless 'prop-dict' is present.
- if (!fmt.hasPropDict)
+ // Not required unless 'prop-dict' is present or we
+ // are not using properties.
+ if (!fmt.hasPropDict || !fmt.useProperties)
return;
SmallVector<MethodParameter> paramList;
@@ -1621,8 +1622,10 @@ void OperationFormat::genElementParser(FormatElement *element, MethodBody &body,
body.unindent() << "}\n";
body.unindent();
} else if (isa<PropDictDirective>(element)) {
- body << " if (parseProperties(parser, result))\n"
- << " return ::mlir::failure();\n";
+ if (useProperties) {
+ body << " if (parseProperties(parser, result))\n"
+ << " return ::mlir::failure();\n";
+ }
} else if (auto *customDir = dyn_cast<CustomDirective>(element)) {
genCustomDirectiveParser(customDir, body, useProperties, opCppClassName);
} else if (isa<OperandsDirective>(element)) {
@@ -2047,9 +2050,11 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
}
}
- body << " _odsPrinter << \" \";\n"
- << " printProperties(this->getContext(), _odsPrinter, "
- "getProperties(), elidedProps);\n";
+ if (fmt.useProperties) {
+ body << " _odsPrinter << \" \";\n"
+ << " printProperties(this->getContext(), _odsPrinter, "
+ "getProperties(), elidedProps);\n";
+ }
}
/// Generate the printer for the 'attr-dict' directive.
|
7e5fbe8
to
182119c
Compare
Curious about the motivation here: Is there a problem with always emitting these methods that this PR solves? |
yes, if we did not emit any property struct for the current operation we should not inject these method, otherwise you end up with a compilation error.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a second I wasn't sure what was broken from the description, but it seems like this PR fixes emission of prop-dict
when the operation doesn't have properties?
Thanks for the fix! Can you please edit the description to make it more clear what is the problem fixed here? |
yes, correct. Let me improve the commit msg. |
…roperties When an operation has no properties, no property struct is emitted. To avoid a compilation error, we should also skip emitting `setPropertiesFromParsedAttr`, `parseProperties` and `printProperties` in such cases. Compilation error: ``` error: ‘Properties’ has not been declared static ::llvm::LogicalResult setPropertiesFromParsedAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); ```
182119c
to
d5acba5
Compare
prop-dict
when the operation does not have properties
Thanks, updated. Hopefully it is more clear now! |
prop-dict
when the operation does not have propertiesprop-dict
when operations do not have properties
prop-dict
when operations do not have propertiesprop-dict
when operations have no properties
When an operation has no properties, no property struct is emitted. To avoid a
compilation error, we should also skip emitting
setPropertiesFromParsedAttr
,parseProperties
andprintProperties
in such cases.Compilation error: