How Rewriting works in MLIR
An in-depth look at the rewriting mechanisms in MLIR and how they enable powerful optimizations. Table of Contents TL;DR Part 1: The moving pieces RewritePatternSet and PatternRewriter Greedy vs. Conversion Greedy (Canonicalization and Local Rewrites) Conversion (Dialect Conversion) Part 2: Your first greedy rewrite pattern. Pattern Definition Part 3 : Running it: Tiny IR + Command Build and run Result Part 4: Dialect Conversion in a nutshell Core ingredients Example: Convert toy.addi to arith.addi Key differences from greedy patterns: Part 5 : Folding vs. Patterns Part 6: Match helpers, benefits, and ordering Part 7: Debugging and guardrails Part 8: Mini LIT Test Example Conclusion Further Reading If you only remember one thing from this post: rewriting in MLIR is “find a pattern, make a change, repeat until more changes can’t be made”, with two key components: ...