<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69789>69789</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR][TableGen] Attribute constraints regression: predicates can no longer reference $_op
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shkoo
</td>
</tr>
</table>
<pre>
It looks like attribute constraints can no longer reference $_op as the documentation (`docs/DefiningDialects/Operations.md`) says they should be able to. mlir-tblgent substitutes "$_op" with a reference to a non-existent "op" variable, giving a compilation error.
This seems to be a regression in 5e118f933b6590cecd7f1afb30845a1594bc4a5d. This functionality is partially tested by `mlir/mlir/test/mlir-tblgen/constraint-unique.td`, but unfortunately that test doesn't verify that the generated code actually compiles. :(
The `constraint-unique.td` lit test contains this:
```tblgen
def AnAttrPred : CPred<"attrPred($_self, $_op)">;
```
which generates this code:
```c++
static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_constraint2Dunique0(
::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> getDiag) {
if (attr && !((attrPred(attr, *op))))
return getDiag() << "attribute '" << attrName
<< "' failed to satisfy constraint: an attribute";
return ::mlir::success();
}
static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_constraint2Dunique0(
::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) {
return __mlir_ods_local_attr_constraint_constraint2Dunique0(attr, attrName, [op]() {
return op->emitOpError();
});
}
```
Notice that the first of those two generated functions references "*op", but there is no "op" passed to that function so this gets a compilation error.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVk2P2zYT_jX0ZbCGTEm2dfDBu959ESBvUqS5GxQ1ktjQpEuONvW_L4aSbGez7aEo0AWxovkx88wzX1Qxms4h7kT5KMrDQg3U-7CL_TfvF7VvLrsPBNb7bxGs-Y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