Skip to main content

Module spill

Module spill 

Source
Expand description

Which values go to memory before any register is handed out.

Design: spec/optimizer/39-register-allocation.md section 39.7, and tamnd/rucc#1177.

crate::pressure finds the points where more values are live than there are registers. At each of those some of the values live there have to be in memory, and this picks which: the lightest first, by the weight crate::backtrack places values by. That is how often a value is read or written, each time counted by how often its block runs, over how much of the function it is live across. A value read in a loop is heavy for the loop’s sake, so what goes is one read outside it, and a value live over a long stretch and rarely read is light, since sending it to memory frees a register over the most points for the fewest loads.

The points are taken in order along the line, and at each one values go until no more are over the room. A value that goes is taken off every point it was live at, so one long light value can settle several points at once, and a later point may already be settled by the time it is reached.

§What it promises

It takes off each point no more values than the pressure model says have to go, and that number is a floor, so every value picked here is standing in for one that some value at that point had to be. It does not promise that the rest then fit. A register a fixed operand claims for one value, the answer of a two address instruction live where its source is read, and a value wanted across a call in one of the registers the call keeps are all left to the assignment, which can still evict and spill after this the way it did before.

Functions§

choose
The values to send to memory before any register is handed out, lightest first at each point where more are live than there is room for.