We want to enable commutative matching of operands via PDL. Any suggestions on the desired functionality and implementation to accomplish the said goal are sought here!
I think there are broadly two ways to achieve commutativity in PDL:
- PDL pattern marked commutative → One PDLInterp “matcher” function using specialized ops represents commutativity → ByteCode executes multiple permutations of matching based on the PDLInterp pattern. This has been partly (PDL to PDLInterp is missing) done here: ⚙ D118683 [MLIR][PDL] Add optional attribute to enable commutativity in PDL, ⚙ D118684 [MLIR][PDLInterp] Define new ops in PDLInterp to support commutativity, and ⚙ D118689 [MLIR][PDL] Execute nondeterministic bytecode & lower some PDLInterp ops.
- PDL pattern marked commutative → Multiple PDL patterns are created within the same module, each representing a permutation of the matching and the PDL pattern with the commutative marker is removed → No other changes are required in PDLInterp or ByteCode. This has been suggested here.
Note that the changes required in approach 2 are less compared to the ones required in approach 1, which is why I am more inclined towards implementing approach 2, even though approach 1 is partly done.