Presentation on theme: "Zach Ma. Memory Model Register Classes Local Register Allocation Global Register Allocation."— Presentation transcript:
Memory Model Register Classes Local Register Allocation Global Register Allocation
The choice of memory model fundamentally determines the allocator’s task. In a register-to-register model, the allocator tries to minimize the inserts of the load and store. In contrast, in a compiler with a memory-to-memory model, the allocator tries to remove as many loads and stores as possible, since this can significantly improve the overall performance.
Most processors have distinct classes of registers for different kinds of values. E.g. The early IBM 360 machines had 16 general-purpose registers and four floating-point registers. On most processors, general-purpose registers and floating- point registers are not used to hold the same kinds of values. If different register classes overlap, the compiler must allocate them together. A similar problem arises on architectures that allow values of different length to be stored in general-purpose registers.
Top-Down Simple principle: the most heavily used values should reside in registers. Bottom-up Keep list of available registers for each register class, and allocate them when needed.
Implementing Algorithm 1.Compute a priority for each virtual register 2.Sort the virtual registers into priority order 3.Assign registers in priority order 4.Rewrite the code Primary weakness It dedicates a physical register to one virtual register for the entire basic block.
Begin with all the registers unoccupied. Most of the complications in the algorithm occur in the routines Ensure, Allocate, and Free. ◦ Ensure just make sure a virtual register is or will occupy a physical register. ◦ Allocate returns a physical register from the free list of a register class. ◦ Free simply needs to push the freed register onto the stack and reset its fields to their initial values.
Advantage In some sense, it maximizes the benefit obtained for the cost of the spill. Clean and Dirty Value A value that need not be stored is called clean, while a value that needs a store is called dirty. E.g. constant, value created by a load from memory
Assume that x1 is clean and x2 is dirty, and the remainder of the block is x3 x1 x2, on a two-register machine Same with the first example, but the remainder of the block is x3 x1 x3 x1 x2
A closed set of related definitions and uses that serves as the base name space
Graph-coloring allocators build a graph, called the interference graph, to model the conflicts between live ranges. If the compiler cannot directly construct a k-coloring for the graph, it modifies the underlying code by spilling some values to memory and tries again.
Variations on Graph-Coloring Allocation Global Register Allocation over SSA Form