Skip to content

Commit bd04138

Browse files
authored
[mlir] Add non-attribute property predicates to adaptor verifiers (#150881)
When adding a predicated field to non-attribute properties / implemneting PropConstraint, a call to genPropertyVerifiers() wasn't added to the generation sequence for [Op]GenericAdaptor::verify. This commit fixes the issue.
1 parent 7abb519 commit bd04138

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mlir/test/mlir-tblgen/op-properties-predicates.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def OpWithPredicates : NS_Op<"op_with_predicates"> {
7070
// CHECK-NEXT: if (!(((!prop.has_value())) || ((::llvm::all_of((*(prop)), [](const int64_t& baseStore) -> bool { return [](int64_t baseIface) -> bool { return ((baseIface >= 0)); }(baseStore); })) && (!(((*(prop)).empty()))))))
7171
// CHECK: failed to satisfy constraint: optional non-empty array of non-negative int64_
7272

73+
// CHECK-LABEL: ::llvm::LogicalResult OpWithPredicatesAdaptor::verify
74+
// Note: comprehensive emission of verifiers is tested in verifyINvariantsImpl() below
75+
// CHECK: int64_t tblgen_scalar = this->getScalar();
76+
// CHECK: if (!((tblgen_scalar >= 0)))
77+
// CHECK: return emitError(loc, "'test.op_with_predicates' op ""property 'scalar' failed to satisfy constraint: non-negative int64_t");
78+
7379
// CHECK-LABEL: OpWithPredicates::verifyInvariantsImpl()
7480
// Note: for test readability, we capture [[maybe_unused]] into the variable maybe_unused
7581
// CHECK: [[maybe_unused:\[\[maybe_unused\]\]]] int64_t tblgen_scalar = this->getScalar();

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ static void genPropertyVerifier(
11271127
body << formatv(fetchProperty, varName, getterName,
11281128
prop.prop.getInterfaceType());
11291129
auto uniquedFn = staticVerifierEmitter.getPropConstraintFn(prop.prop);
1130-
if (uniquedFn.has_value())
1130+
if (uniquedFn.has_value() && emitHelper.isEmittingForOp())
11311131
body << formatv(verifyPropertyUniqued, *uniquedFn, varName, prop.name);
11321132
else
11331133
body << formatv(
@@ -4764,6 +4764,7 @@ void OpOperandAdaptorEmitter::addVerification() {
47644764

47654765
FmtContext verifyCtx;
47664766
populateSubstitutions(emitHelper, verifyCtx);
4767+
genPropertyVerifier(emitHelper, verifyCtx, body, staticVerifierEmitter);
47674768
genAttributeVerifier(emitHelper, verifyCtx, body, staticVerifierEmitter,
47684769
useProperties);
47694770

0 commit comments

Comments
 (0)