PDL example for working with a range

I have a PDL rewrite pattern like the following:

module @patterns {
  pdl.pattern : benefit(1) {

     %TRANSPOSE_OP = pdl.operation "some_dialect.transpose" (%ARG0, %ARG1 : !pdl.value, !pdl.value) -> (%TRANSPOSE_TYPE : !pdl.type)

     pdl.rewrite {
        %custom_op = pdl.apply_native_rewrite "createCustomOp" (%TRANSPOSE_OP : !pdl.operation) : !pdl.operation

and the native rewriter:

static Operation *createCustomOp(PatternRewriter &rewriter, Operation *op) {

I wonder if there is an example or a way to change createCustomOp to accept a list of Operations (Range). How would the PDL rewrite pattern change? @pifon2a

Found the answer in the slide and recorded video and PatternMatch.h.

Here is how I did it:

static void createCustomOp(PatternRewriter &rewriter, PDLResultList &results,ArrayRef<PDLValue> args) {
  Operation *op1= args[0].cast<Operation *>();
  Operation *op2= args[1].cast<Operation *>();
%RESULT = pdl.apply_native_rewrite "createCustomOp" (%OP1, %OP2 : !pdl.operation, !pdl.operation) : !pdl.operation
1 Like