MLIR DRR result pattern with constant StringAttr

Hi, everyone, I’d like to write a pass with DRR. I want to replace AOp with BOp with a constant StringAttr like “Function1”.:

def BOp: myDialectOp<"bop",[]>{
    let arguments = (ins Builtin_StringAttr: $SA, I32:%B)
def MyPattern :Pat<(AOp $in0), (BOp Builtin_StringAttr:"Function1",in0)>;

But Errors occurred when I built the project :

error: expected variable name in dag literal

I guess I should use a C++ helper to get a constant StringAttr instance. But I could not find a constructor of StringAttr with std::string as input. How should I do?

Remove Builtin_StringAttr on the target pattern/DAG: on the source it’s a constraint, on the target it’s not handled in useful way.

Although the Builtin_StringAttr is redundent in the example I showed above, are there some apporaches to realize a “constant Attribute” in DRR?

I think I solved this by

def Func1 : NativeCodeCall<"StringAttr::get($_builder.getContext(), \"Function1\")">;
def MyPattern :Pat<(AOp $in0), (BOp (Func1)",in0)>;

If you need constant attributes in patterns you can use instances of ConstantAttr as operands in the result pattern. For string-like atrtibutes in particular there is ConstantStrAttr which takes care of the quoting.
For the example you posted this would be:

def MyPattern :Pat<(AOp $in0), (BOp ConstantStrAttr<StrAttr, "Function1">, $in0)>;

It works. Thanks!