Selecting a register allocator


Linear scan remains the default. To select an allocator for a compilation or measurement, dynamically bind register-allocator:
USING: compiler.cfg.metrics compiler.cfg.register-allocation math namespaces prettyprint ; linear-scan-allocator register-allocator [ [ + ] measure-compilation . ] with-variable

Allocator implementations receive the CFG before SSA destruction so that SSA-based algorithms can use their required invariants. Each implementation must produce a fully allocated CFG.

Three experimental alternatives are available:
compiler.cfg.register-allocation.greedy: LLVM-inspired priority allocation with eviction, CFG region placement, local splitting and bounded last-chance recoloring.
compiler.cfg.register-allocation.backtracking: regalloc2-inspired SSA affinity bundles with eviction, conflict-directed splitting, shared spill homes and second-chance allocation.
compiler.cfg.register-allocation.chordal: SSA pressure reduction with explicit spills and reloads before certified interference-graph coloring and affinity-guided assignment.

These are Factor implementations of the approaches, with different engineering tradeoffs from their reference compilers. Compare generated code and execution as well as compilation cost before choosing a default.
USING: compiler.cfg.metrics compiler.cfg.register-allocation compiler.cfg.register-allocation.greedy compiler.cfg.register-allocation.backtracking compiler.cfg.register-allocation.chordal kernel.private math prettyprint ; [ { fixnum fixnum } declare + ] { linear-scan-allocator greedy-allocator backtracking-allocator chordal-allocator } compare-allocators .