1 / 14

Register Allocation

Register Allocation. Zach Ma. Overview. Memory Model Register Classes Local Register Allocation Global Register Allocation. Memory model. The choice of memory model fundamentally determines the allocator’s task .

vidal
Download Presentation

Register Allocation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Register Allocation Zach Ma

  2. Overview • Memory Model • Register Classes • Local Register Allocation • Global Register Allocation

  3. Memory model • 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.

  4. Register Classes • 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.

  5. Local Register Allocation • 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.

  6. Top-down Approach • Implementing Algorithm • Compute a priority for each virtual register • Sort the virtual registers into priority order • Assign registers in priority order • Rewrite the code • Primary weakness It dedicates a physical register to one virtual register for the entire basic block.

  7. Bottom-up Approach • 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.

  8. Bottom-up Continue • 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

  9. Two Examples of Spill • 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

  10. Live Ranges • Aclosed set of related definitions and uses that serves as the base name space

  11. Global Register Allocation • 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.

  12. Advanced Topics • Variations on Graph-Coloring Allocation • Global Register Allocation over SSA Form

  13. Thank you

More Related