MLIR Op operand constraints


Is there a way to specify that a particular operand (input) to an Op can only be the result of a specific set of Ops itself? Obviously we can impose type constraints in the td file, but we’re wondering if those constraints can be further hardened to specific Ops and hopefully prevent rewrites on the subgraphs that would violate those constraints.

Thanks in advance,

If this is really a constraint of the Operation itself, is it in scope for the verifier for this op?

Note that this may be fragile, as it limits the ability for these other ops to fold or rewrite themselves: in general we consider an SSA value for a given type to be “self-contained”: you can substitute the producer for any other op that produce the same value.

You might want to consider an op with a region that encodes the entire dependency within a single operation if that is possible.

Hard to say without knowing the exact situation, but I’d echo Mehdi that it sounds like really sounds like the solution to this would be to change the input type to something only produced by the ops in question. Non-local constraints in the verifier cause all kinds of issues. Also making this a verification failure would just cause verification to fail: it wouldn’t stop patterns that transform the ops you’re looking for.