1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Declarative Rewrite DSL for algebraic simplifications.
//!
//! This module provides the `rewrite_rules!` macro, which allows passes to define
//! algebraic rewrites and peephole optimizations in a declarative, readable format
//! rather than writing massive imperative match statements.
//!
//! # Example
//!
//! ```rust,ignore
//! use crate::ir::{BinOp, Expr};
//! use crate::optimizer::dsl::rewrite_rules;
//!
//! let mut rules = rewrite_rules! {
//! // Eliminate `X + 0`
//! add_zero: Expr::BinOp { op: BinOp::Add, left, right } if matches!(**right, Expr::LitU32(0)) => {
//! left.as_ref().clone()
//! },
//!
//! // Eliminate `X * 1`
//! mul_one: Expr::BinOp { op: BinOp::Mul, left, right } if matches!(**right, Expr::LitU32(1)) => {
//! left.as_ref().clone()
//! },
//! };
//!
//! // Pass the closure directly into `rewrite_program` or `rewrite_expr`
//! // let (program, changed) = rewrite_program(program, &mut rules);
//! ```
/// Defines a set of declarative rewrite rules that compile into a `|&Expr| -> Option<Expr>` closure.
}
}