regalloc2
More info
- Creator
- Chris Fallin
- Owner
- Bytecode Alliance
- Type
- Register allocator (library)
- Source
- github.com/bytecodealliance/regalloc2
The Rust register allocator behind Cranelift, built on ideas from Firefox's JavaScript JIT rather than on graph colouring.
Chris Fallin wrote it in 2021–2022 to replace Cranelift's earlier allocator, regalloc.rs. The model was the backtracking allocator in IonMonkey, Firefox's optimising JIT, which had itself borrowed from LLVM's greedy allocator. Instead of building a full interference graph, it works with live ranges grouped into bundles; each bundle is assigned a register, and on conflict it either evicts another bundle or gets split into smaller pieces.
The input is code with virtual registers and block parameters; the output is both the register assignment and the list of moves and spills needed to make it work. The switch gave Cranelift noticeably faster compilation and better code at the same time, which is an unusual combination. The library stands alone and could serve other code generators, but so far it has mostly done one job: WebAssembly in Wasmtime.