Show HN: Lamina – A compiler backend that is not LLVM or Cranelift
5 points
2 days ago
| 0 comments
| github.com
| HN
Recently, I've been working on Lamina, a compiler infrastructure that generates native assembly for multiple architectures without relying on LLVM or Cranelift. It's designed for building compilers for new languages, educational projects, and any projects that can utilize a custom syntax of code generation.

Instead of depending on external backends, Lamina provides a complete pipeline from a single SSA based IR directly to the supported target's assembly generation. The IR is readable, also provides a IRBuilder API that is easy to use via programmatic construction.

For better management of the code generation process, in the future, it will use a new pipeline IR -> MIR -> native assembly with the optimization passes.

Key features: - Direct code generation: IR -> assembly/machine code without LLVM/Cranelift - SSA based IR: single assignment form optimized for analysis and optimization passes - MIR based codegen(experimental): new intermediate representation with register allocation and advanced optimizations - IRBuilder API: fluent interface for building modules, functions, blocks, and control flow - Readable IR: easy to debug and lower than high level languages - Zero external backend dependencies: simplified builds and transparent pipeline while being faster to build

Optimization passes (experimental MIR flow only): - Control flow: CFG simplification, jump threading, branch optimization - Loop optimizations: loop fusion, loop invariant code motion, loop unrolling - Code motion: copy propagation, common subexpression elimination, constant folding - Function optimizations: inlining, tail call optimization - Arithmetic: strength reduction, peephole optimizations

Performance: On a 256×256 matrix multiplication benchmark (300 runs), Lamina's experimental MIR-based codegen (which includes all optimization passes) generates code comparable to C/C++/Rust (within 1.8x) and faster than Java, Go, JavaScript, and Python. The experimental MIR based flow's result is much faster than the IR-> Assembly based codegen.

Written in Rust (2024 edition), Current Version 0.0.7. Optional nightly features available for SIMD, atomic placeholders, and experimental targets.

No one has commented on this post.