Skip to content

[MLIR][ODS] Check hasProperties when generating populateDefaultAttrs #78525

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

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

zyx-billy
Copy link
Contributor

@zyx-billy zyx-billy commented Jan 18, 2024

Currently ODS generates populateDefaultAttrs or populateDefaultProperties based on whether the dialect opted into usePropertiesForAttributes. But since individual ops might get opted into using properties (as long as it has one property), it should actually just check whether the op itself uses properties. Otherwise populateDefaultAttrs will overwrite existing attrs inside properties when creating an op. Understandably this becomes moot once everything switches over to using properties, but this fixes it for now.

This PR makes ODS generate populateDefaultProperties as long as the op itself uses properties.

@zyx-billy zyx-billy force-pushed the mlir/default_attr_and_properties branch from 491c094 to 729bcd2 Compare January 18, 2024 01:19
@zyx-billy zyx-billy changed the title [MLIR] Consider properties when populating default attrs [MLIR][ODS] Check hasProperties when generating populateDefaultAttrs Jan 18, 2024
@zyx-billy zyx-billy force-pushed the mlir/default_attr_and_properties branch from 729bcd2 to 2035ce5 Compare January 18, 2024 18:11
@zyx-billy zyx-billy marked this pull request as ready for review January 18, 2024 19:23
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Jan 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 18, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Billy Zhu (zyx-billy)

Changes

Currently ODS generates populateDefaultAttrs or populateDefaultProperties based on whether the dialect opted into usePropertiesForAttributes. But since individual ops might get opted into using properties (as long as it has one property), it should actually just check whether the op itself uses properties. Otherwise populateDefaultAttrs will overwrite existing attrs inside properties when creating an op. Understandably this becomes moot once everything switches over to using properties, but this fixes it for now.

This PR makes ODS generate populateDefaultProperties as long as the op itself uses properties.


Full diff: https://github.com/llvm/llvm-project/pull/78525.diff

2 Files Affected:

  • (modified) mlir/test/mlir-tblgen/op-attribute.td (+13)
  • (modified) mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp (+1-1)
diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td
index 07636f53c1e15c..b5b8619e7c9bea 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -173,6 +173,8 @@ def AOp : NS_Op<"a_op", []> {
 // DEF:        ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
 // DEF:      odsState.addAttributes(attributes);
 
+// DEF:      void AOp::populateDefaultAttrs
+
 // Test the above but with prefix.
 
 def Test2_Dialect : Dialect {
@@ -287,6 +289,17 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
 // DEF:        ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
 // DEF:      odsState.addAttributes(attributes);
 
+// Test the above but using properties.
+def ApropOp : NS_Op<"a_prop_op", []> {
+  let arguments = (ins
+      Property<"unsigned">:$aAttr,
+      DefaultValuedAttr<SomeAttr, "4.2">:$bAttr
+  );
+}
+
+// DEF-LABEL: ApropOp definitions
+// DEF:       void ApropOp::populateDefaultProperties
+
 def SomeTypeAttr : TypeAttrBase<"SomeType", "some type attribute">;
 
 def BOp : NS_Op<"b_op", []> {
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index cd37c8dcd3d5e0..71326049af0579 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2506,7 +2506,7 @@ void OpEmitter::genPopulateDefaultAttributes() {
       }))
     return;
 
-  if (op.getDialect().usePropertiesForAttributes()) {
+  if (emitHelper.hasProperties()) {
     SmallVector<MethodParameter> paramList;
     paramList.emplace_back("::mlir::OperationName", "opName");
     paramList.emplace_back("Properties &", "properties");

@zyx-billy zyx-billy requested a review from joker-eph January 18, 2024 19:24
@zyx-billy zyx-billy merged commit 595d780 into llvm:main Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants