code wiki / (root) / regalloc_evict_test.nx

regalloc_evict_test.nx

buildroot/runtime/regalloc_evict_test.nx

2965 B95 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind gate/prooftopic regalloc
docsdependenciesstructsconstsfunctions

about

regalloc_evict_test.nx -- proves the Poletto-Sarkar spill-at- interval eviction policy fires (added to linear_scan in nx_regalloc.nx). Construction: build 17 long-lived binop values (v0..v16) where v0 has the LATEST use (end ~ 34) and v16 has the EARLIEST use (end ~ 18). With 16 GPRs and 17 live values, exactly one must spill. Without eviction: v16 spills (arrival order -- the latest-arriving interval that finds the pool empty gets demoted). This wastes a spill slot on a short-lived value while a long-lived value (v0) happily keeps its register. With eviction (the new policy): when v16 arrives and pop_free returns -1, spill_furthest_gpr walks active[] (sorted by end ascending) and finds v0 at the back with end=34 > v16.end=18. Since v0.end > v16.end, v0 is evicted and v16 gets v0's register. The assertion: locs[ID_OF_V0].kind == VL_SPILLED. This is the proof the eviction fired -- v0 was the LATEST-end interval and got evicted by the new spill heuristic, not by arrival order.

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_types.nx nx_ir.nx nx_regalloc.nx regalloc_evict_test.nx

imports: nx_syscalls.nxnx_types.nxnx_ir.nxnx_regalloc.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap ir_function_new sys_mmap ↻ ir_type_i64 alloc_type sys_mmap ↻ ir_block_new nx_assert_ptr sys_write nx_puts_err sys_write ↻ nx_assert sys_write ↻ nx_puts_err ↻ nx_assert_lt sys_write ↻ nx_puti_err sys_mmap ↻ sys_write ↻ nx_puts_err ↻ ir_const_i64 nx_assert_ptr ↻ nx_assert ↻ alloc_value nx_assert_ptr ↻ nx_assert ↻ nx_assert_lt ↻ ir_type_i64 ↻ ir_emit_binop nx_assert_ptr ↻ nx_assert ↻ alloc_instr nx_assert_ptr ↻ nx_assert ↻ nx_assert_lt ↻ alloc_value ↻ append_instr ir_emit_return ir_bb_sealed

structs

none

consts

29const N_VALS: i64 = 17 // values v0..v16; one more than 16 GPRs

functions

31func main() -> i64