(MLIR) Which one should I use among the following: [OpRewritePattern, RewritePattern, OpConversionPattern, ConversionPattern]?

Hello, I’m new to MLIR, and I’m writing a pass for dialect conversion.

I saw a few reference repositories such as torch-mlir, onnx-mlir, and toy-tutorial. One project uses OpRewritePattern to implement dialect conversion pass, another uses OpConversionPattern. Even, toy-tutorial is a mix of OpRewritePattern, OpConversionPattern, and ConversionPattern.

I have no idea that which one should I use among the following: [OpRewritePattern, RewritePattern, OpConversionPattern, ConversionPattern]. I would greatly appreciate any advice on when to use each pattern.

Thank you :slight_smile:

Use Op*Pattern when the pattern matches a root op of the specific kind, and *Pattern when it can match ops of multiple kinds (rare).
Use *ConversionPattern when the pattern involves type conversion and is used with applyFull/PartialConversion, and *RewritePattern when it does not and is used with applyPatternsGreedily.

1 Like

I really appreciated :slight_smile: