mlirSynth: Automatic, Retargetable Program Raising in Multi-Level IR using Program Synthesis

Alexander Brauckmann, Elizabeth Polgreen, Tobias Grosser, Michael F. P. O'Boyle · DOI

As Moore’s Law and Dennard scaling reach their limits, the computing landscape has shifted toward specialized hardware accelerators like Tensor Processing Units (TPUs). To leverage these devices, compilers must understand high-level program semantics—such as matrix operations—rather than just low-level instruction sequences. The Multi-Level Intermediate Representation (MLIR) framework addresses this by using "dialects" to capture high-level intent. However, most legacy code is written in low-level languages like C, creating a significant "raising" gap.

The Challenge of Program Raising

Traditionally, "raising" code from low-level representations (like LLVM IR) to high-level dialects (like Linalg or HLO) has relied on manually authored pattern-matching rules. These rules are brittle, difficult to maintain, and fail to scale as new hardware and dialects emerge. Without effective raising, legacy applications cannot take advantage of the massive performance potential offered by modern accelerators.

The MLIR ecosystem and the concept of "raising" low-level code to high-level dialects.

The mlirSynth Framework

The authors present mlirSynth, a framework that automates the raising process using program synthesis. Instead of hardcoded rules, mlirSynth searches for a high-level program that is behaviorally equivalent to the low-level source.

The framework is uniquely "retargetable." By ingesting MLIR’s TableGen files, it automatically generates a search grammar for any dialect. The synthesis engine employs a bottom-up enumerative search, building candidate programs from simple operations. To manage the search space, it uses several pruning techniques:

  • Type Constraints: Only exploring programs that are syntactically and type-correct.
  • Observational Equivalence: Discarding redundant candidate programs that produce identical outputs for the same inputs.
  • Polyhedral-Guided Heuristics: Using mathematical loop analysis to distribute complex nests into smaller, manageable sub-problems.

Finally, it verifies correctness using a multi-staged approach, starting with random testing and culminating in formal proof via the CBMC bounded model checker.

Overview of the mlirSynth workflow, transforming a C program into high-level IRs for CPU and TPU execution.

Evaluation and Results

Evaluated on the Polybench 4.2.1 suite, mlirSynth demonstrated superior coverage and performance compared to existing rule-based systems. It successfully raised 13 out of 14 benchmarks, whereas the previous state-of-the-art (MLT) handled only 6.

On standard CPUs, the synthesized programs achieved geomean speedups of 2.5x (Intel) and 3.4x (AMD) over LLVM -O3. Most impressively, by raising C code to the HLO dialect, mlirSynth enabled execution on Google TPUs, yielding a geomean speedup of 21.6x, with specific kernels like doitgen reaching an 806x improvement. Synthesis is also efficient, with many kernels processed in under two seconds, though more complex cases can take up to two minutes.

Conclusion

mlirSynth proves that program synthesis can replace manual compiler engineering for complex raising tasks. By automating the bridge between legacy C code and modern high-level dialects, it unlocks the full potential of specialized hardware without requiring manual code rewrites. Future work aims to scale this approach to larger, general-purpose applications and multi-dialect targets.

Summary updated

BibTeX
@inproceedings{brauckmann2023mlirsynth,
  author = {Alexander Brauckmann and Elizabeth Polgreen and Tobias Grosser and Michael F. P. O'Boyle},
  title = {{mlirSynth: Automatic, Retargetable Program Raising in Multi-Level IR using Program Synthesis}},
  booktitle = {PACT},
  year = {2023},
  url = {https://openreview.net/forum?id=0sVTcmnnnS},
}
Figure