Skip to content

Commit

Permalink
Fix ODS verifier emission for DerivedAttr when Properties are enabled
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D158679
  • Loading branch information
joker-eph committed Aug 24, 2023
1 parent ad7e6e9 commit aa33561
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mlir/test/lib/Dialect/Test/TestOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ def DerivedTypeAttrOp : TEST_Op<"derived_type_attr", []> {
"$_builder.getI32IntegerAttr($_self)">;
}

def TestPropOp : TEST_Op<"prop">,
Arguments<(ins Variadic<Index>:$upperInits,
I32ElementsAttr:$transforms)>,
Results<(outs Variadic<AnyType>:$results)> {
DerivedAttr upperLen = DerivedAttr<"uint32_t", [{
return getUpperInits().size() / getTransforms().size();
}], [{ $_builder.getI32IntegerAttr($_self) }]>;
}


def StringElementsAttrOp : TEST_Op<"string_elements_attr"> {
let arguments = (ins
StringElementsAttr:$scalar_string_attr
Expand Down
4 changes: 3 additions & 1 deletion mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,12 @@ while (true) {{
if (useProperties) {
for (const std::pair<StringRef, AttributeMetadata> &it :
emitHelper.getAttrMetadata()) {
const AttributeMetadata &metadata = it.second;
if (metadata.constraint && metadata.constraint->isDerivedAttr())
continue;
body << formatv(
"auto tblgen_{0} = getProperties().{0}; (void)tblgen_{0};\n",
it.first);
const AttributeMetadata &metadata = it.second;
if (metadata.isRequired)
body << formatv(
"if (!tblgen_{0}) return {1}\"requires attribute '{0}'\");\n",
Expand Down

0 comments on commit aa33561

Please sign in to comment.