When working with frontend dialects, we encounter optional attributes as well as input/output arguments. Optional attributes are easily handled in TableGen as of now. One example of optional input is the bias for Conv2D in Keras, we see the same optional input in ONNX’s CONV operation. There are many other examples.
We have identified a few ways to handle optional input/output:
Creating separate operation varients in the dialect itself, and steering the creation of the one or the other when encountering a frontend operation with optional arguments. Drawback is lower reuse of code among the different variants.
Creating a separate tensor type that accepts “no value” and possibly add an attributes that indicates the presence of an optional argument. This let us use a common operations for all combinations of optional arguments. The verifier does not know the correlation between the attribute and argument, so checking of consistency is left to the developper.
Adding support for optional arguments directly in TableGen, following the example of its handling of the optional attributes.
We currently use approach 1; I believe TF MLIR uses approach 2. Would the community be supportive of approach 3, to have a more standardized way to handle optional input/output arguments.