Toy Compiler for Python Expressions using MLIR and E-Graphs

2025-03-21
Toy Compiler for Python Expressions using MLIR and E-Graphs

This article details a toy compiler for Python expressions built using MLIR and the egglog library. The compiler leverages E-Graphs for equality saturation and term rewriting to optimize Python expressions before compiling them to MLIR. It features modules for expression modeling, built-in functions, Term IR, a transformation layer, an optimization layer, and MLIR code generation and an LLVM backend. By symbolically interpreting Python functions, converting them to an IR representation, applying optimization rules, and finally generating efficient MLIR code, the compiler achieves compilation and execution via LLVM.

Development