include "mlir/IR/OpBase.td" def Test_Dialect : Dialect { let name = "test"; } class NS_Op<string mnemonic, list<OpTrait> traits> : Op<Test_Dialect, mnemonic, traits>; def EOp : NS_Op<"e_op", []> { let arguments = (ins AnyInteger: $any_integer, Optional<AnyInteger>: $optioanl_integer ); } def FOp : NS_Op<"f_op", []> { let arguments = (ins AnyInteger: $any_integer, Optional<AnyInteger>: $optioanl_integer ); } // CHECK: if (auto tmpOperand = (*arg0.begin())) { // CHECK: if (auto tmpOperand = (arg1.size() > 0? (*arg1.begin()): nullptr)) { def test5 : Pat<(EOp $arg0, $arg1), (FOp $arg0, $arg1)>;
Without the patch, tblgen would generate cpp code like
arg1 = castedOp0.getODSOperands(1); tblgen_values.push_back(arg1)
and cause compilation error. Here arg1 is type ValueRange and tblgen_values is type SmallVector.
I don't know if this will work: if you have two optional args next to each other, the caller would not be able to differentiate which is specified. It would seem that passing in nullptr for those and handling it in the builder would work instead and keep ordering.