Skip to content

Commit 595d780

Browse files
authored
[MLIR][ODS] Check hasProperties when generating populateDefaultAttrs (#78525)
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.
1 parent dbc0955 commit 595d780

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mlir/test/mlir-tblgen/op-attribute.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def AOp : NS_Op<"a_op", []> {
173173
// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
174174
// DEF: odsState.addAttributes(attributes);
175175

176+
// DEF: void AOp::populateDefaultAttrs
177+
176178
// Test the above but with prefix.
177179

178180
def Test2_Dialect : Dialect {
@@ -287,6 +289,17 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
287289
// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
288290
// DEF: odsState.addAttributes(attributes);
289291

292+
// Test the above but using properties.
293+
def ApropOp : NS_Op<"a_prop_op", []> {
294+
let arguments = (ins
295+
Property<"unsigned">:$aAttr,
296+
DefaultValuedAttr<SomeAttr, "4.2">:$bAttr
297+
);
298+
}
299+
300+
// DEF-LABEL: ApropOp definitions
301+
// DEF: void ApropOp::populateDefaultProperties
302+
290303
def SomeTypeAttr : TypeAttrBase<"SomeType", "some type attribute">;
291304

292305
def BOp : NS_Op<"b_op", []> {

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,7 @@ void OpEmitter::genPopulateDefaultAttributes() {
25062506
}))
25072507
return;
25082508

2509-
if (op.getDialect().usePropertiesForAttributes()) {
2509+
if (emitHelper.hasProperties()) {
25102510
SmallVector<MethodParameter> paramList;
25112511
paramList.emplace_back("::mlir::OperationName", "opName");
25122512
paramList.emplace_back("Properties &", "properties");

0 commit comments

Comments
 (0)