Abstract

Register allocation by coloring an interference graph is a common technique. We introduce the weighted interference graph (WIG) which improves upon previous approaches in the following ways: (i) the cost of a coloring accurately models the cost of the register assignment, (ii) arbitrary register spills are handled naturally, as the coloring implicitly determines when and what registers to spill, and (iii) the allocation granularity is freely scalable from an instruction level to a per variable level. In particular, at any granularity, a WIG models the degree of interference between two vertices, which improves upon the traditional interference graph. The weights in a WIG incorporate usage counts to reflect the relative cost for spilling a quantity. We model the savings from keeping a variable in a register via negative edge weights. Our method is ideal when near-optimal register allocation is desired and spill code is unavoidable, such as for large frequently-executed basic blocks, as might be produced by inlining and loop unrolling. We show that a WIG gives better allocations than a traditional interference graph when it matters most, namely when there are not enough registers.

Date of this Version

June 1993

Share

COinS