Skip to content

Commit 8e0a63d

Browse files
authored
[mlir][docs] Add docs on canonicalizers being folders or patterns (#129517)
If a transformation should be a canonicalization is an orthogonal question to if a transformation should be implemented as a `RewritePattern` or a `fold` method. The later is an implementation detail. This patch adds a suggestion to always implement a canonicalization as a `fold` pattern if possible, as they are a restricted subset of a `RewritePattern`. This has been a common source of confusion, as to when to implement a canonicalization as a fold method or a RewritePattern.
1 parent 6311e3f commit 8e0a63d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mlir/docs/Canonicalization.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,8 @@ Operation *MyDialect::materializeConstant(OpBuilder &builder, Attribute value,
275275
...
276276
}
277277
```
278+
279+
### When to use the `fold` method vs `RewriterPattern`s for canonicalizations
280+
281+
A canonicalization should always be implemented as a `fold` method if it can
282+
be, otherwise it should be implemented as a `RewritePattern`.

0 commit comments

Comments
 (0)