VeIR is a compiler infrastructure written in Lean that offers both an MLIR-style imperative design and (optional) ITP-level verification. VeIR connects with MLIR via the MLIR textual format, making it easy to combine MLIR and VeIR tooling.
| VeIR Features | Complete | Verified |
|---|---|---|
| MLIR core data structures (block, operation, region) | ✅ | 🔒 |
| define dialects | ✅ (basic) | |
| pass infrastructure | ✅ | |
| peephole rewriter | ✅ | |
| peephole rewriter (declarative) | ||
| interpreter framework | ✅ |
Our testing framework is split into two parts: unit tests written in Lean and
FileCheck tests for the
command line tool veir-opt.
Run the unit tests with:
lake testFileCheck tests require uv to be installed.
First, install dependencies:
uv syncThen run the tests:
uv run lit Test/ -vlake exe run-benchmarks add-fold-worklistThis section gives an example showing how to run code through a VeIR pass, starting from C code.
Prerequisite: An up-to-date MLIR bin directory in your PATH.
Start with a C function:
cat << _end_ > demorgan.c
unsigned d1(unsigned p, unsigned q) {
return ~(~p & ~q);
}
unsigned short d2(unsigned short p, unsigned short q) {
return ~(~p | ~q);
}
_end_Compile to LLVM IR:
clang -cc1 -O0 -disable-O0-optnone -emit-llvm demorgan.cOptimize it a little:
opt -passes=sroa demorgan.ll -S -o demorgan-opt.llTranslate to MLIR:
mlir-translate --import-llvm demorgan-opt.ll | mlir-opt --mlir-print-op-generic --mlir-print-local-scope > demorgan-opt.mlirOptimize using VeIR's InstCombine and DCE (dead code elimination) passes:
lake exec veir-opt -p=instcombine,dce demorgan-opt.mlir