Skip to content

Commit 63b5096

Browse files
committed
[mlir][docs] Add docs on canonicalizers being folders or patterns
1 parent a557861 commit 63b5096

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

mlir/docs/Canonicalization.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,26 @@ Operation *MyDialect::materializeConstant(OpBuilder &builder, Attribute value,
275275
...
276276
}
277277
```
278+
279+
### Choosing between implementing a Folder or a `RewritePattern`
280+
281+
When implementing a new canonicalization, an important thing to think about is
282+
if the canonicalization should be a folder or a `RewritePattern`. The generally
283+
accepted policy is:
284+
285+
* If a transformation should be a canonicalizer is a different question from
286+
if a transformation should be a folder or a `RewritePattern`. A
287+
transformation is promoted to a canonicalization as defined by the General
288+
Design of canonicalizations.
289+
290+
* If a transformation is a canonicalization, there are two ways to implement
291+
it: As a Folder or as a `RewritePattern`, both of which are implementation
292+
details of how a canonicalization exists, with the difference being folders
293+
have restrictions on what they can do. A `RewritePattern` can implement any
294+
transformation a folder can.
295+
296+
* A canonicalization should always be implemented as a Folder if it fits
297+
the "local" definition of a folder.
298+
299+
* If a canonicalization does not fit as a folder, it should be implemented
300+
as a `RewritePattern`.

0 commit comments

Comments
 (0)