Sunteți pe pagina 1din 2

In compiler optimization, register allocation is the process of assigning a large number of target

program variables onto a small number of CPU registers.

Register allocation can happen over a basic block (local register allocation), over a whole
function/procedure (global register allocation), or across function boundaries traversed via call-
graph (interprocedural register allocation). When done per function/procedure the calling
convention may require insertion of save/restore around each call-site.

Register allocation techniques


Register allocation can happen over a basic block of code: it is said to be "local", and was first
mentioned by Horwitz et al. .[14] As basic blocks do not contain branches, the allocation process
is thought to be fast, because the management of control flow graph merge points in register
allocation reveals itself a time-consuming operation .[15] However, this approach is thought not to
produce as optimized code as the "global" approach, which operates over the whole compilation
unit (a method or procedure for instance).[16]

Graph-coloring allocation

See also: Graph coloring

Graph-coloring allocation is the predominant approach to solve register allocation [17] · .[18] It
was first proposed by Chaitin et al., [19] In this approach, nodes in the graph represent live ranges
(variables, temporaries, virtual/symbolic registers) that are candidates for register allocation.
Edges connect live ranges that interfere , i.e., live ranges that are simultaneously live at at least
one program point. Register allocation then reduces to the graph coloring problem in which
colors (registers) are assigned to the nodes such that two nodes connected by an edge do not
receive the same color.[20]

Using liveness analysis, an interference graph can be built. The interference graph which is
an undirected graph where the nodes are the program's variables is used to model which
variables canLinear Scan

Linear scan is another global register allocation approach. It was first proposed by Poletto et. al
in 1999 .[27] In this approach, the code is not turned into a graph. Instead, all the variables are
linearly scanned to determine their live range, represented as an interval. Once the live ranges of
all variables have been figured out, the intervals are traversed chronologically. Although this
traversal could help identifying variables whose live ranges interfere, no interference graph is
being built and the variables are allocated in a greedy way. [25]

The motivation for this approach is speed; not in terms of execution time of the generated code,
but in terms of time spent in code generation. Typically, the standard graph coloring approaches
produces quality code, but has a significant overhead, [28] [29] the used graph coloring algorithm
having a quadratic cost.[30] Owing to this feature, linear scan is the approach currently used in
several JIT compilers, like the Hotspot compiler, V8 and Jikes RVM.
.

S-ar putea să vă placă și