Hacker News·5 min read·hard

Rat's Register Allocator

M
mpweiher
✦AI Summary

The author describes the development of a register allocator for a compiler backend, detailing the transition from a scan-based allocator to a more efficient priority bin-packing approach. The post explains the technical constraints of register allocation, including live ranges and calling conventions.

Why it matters

Efficient register allocation is a fundamental component of compiler optimization, directly impacting the performance of generated machine code.

✦Dive DeeperCreate a free account to unlock

rat is my smallish compiler backend (with a semi-working

representation (IR) into x86-64 instructions. These use an unlimited number of virtual

registers (vregs). The register allocator maps each vreg to a physical register: a general-purpose register (12 can

be used) or an xmm register (14 on Linux 1 ). When no register is free,

scan allocator, which visits live ranges in program order. It worked, but it grew one fix at a time, to

1392 lines. So I measured which of its parts helped, threw the rest away and wrote a priority bin-packing

allocator in 584 lines. It visits live ranges by importance and puts each one in the first register where it

allocator , minus most of the hard parts, and it makes

A value is live from where it is written to where it is last read. Two values can share a register

Continue reading on Headlinne

Create a free account to read the full article.

Read full article →
technologyscience
✦

Get smarter about the news

Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.

Create free account

Already have an account? Sign in