Passing an undefined attribute using Declarative Rewrite Rule

I have the following 1-to-1 declarative rewrite rule:

def : Pat<(op1 (op2 $a,$b,$c,$d,$e,$f,$g)),
          (op3 $a,$b,$c,$d,$e,$f,$g)>;

However, there is a string attribute in the op2 that I would like to have in op3 but the problem is that this attribute hasn’t been defined in the definition of any of op2 and op3 (cannot be set using builder). Is there any way to set that attribute in a declarative way in the td file or should we apply this on the native side?
Is there a similar example that uses NativeCodeCall that I can take a look at?

@pifon2a

I would just write a custom pattern. I don’t know if it can be done in td. @River707

Is the goal here to inject a discardable attribute as part of rewrite? What is the higher level goal?

Thank you for your replies.

I have dialect1_to_dialect2.td which has so many 1-to-1 pattern matching-and-rewriting like the following example using declarative rewrite rules.

def : Pat<(Dialect1_ConvolutionOp $input,$weight,$bias,$stride,$padding,$dilation,$transposed,$output_padding,$groups),
           (Dialect2_ConvolutionOp $input,$weight,$bias,$stride,$padding,$dilation,$groups)

This is what we already have:

dialect1.mlir -----> dialect1_to_dialect2 pass ----> dialect2.mlir

However, none of the operations of these two dialects have any attribute arguments in their td file. There is another pass X which is dialect1 specific and adds bunch of attributes to the operations of dialect1 on the fly. I want to adapt dialect1_to_dialect2 pass in a way that it clones all these attributes of the source operation to the target operation with minimum amount of changes in the code. I am looking for a way to use some native c++ code that I can call in the td file to clone the attributes from source operation to target operation after the source op is replaced by the target op. This is the goal:

dialect1.mlir ----> pass X -----> dialect1_with_attrs.mlir -----> dialect1_to_dialect2 pass ----> dialect2_with_attrs.mlir