/
Register Allocation Register Allocation

Register Allocation - PowerPoint Presentation

natalia-silvester
natalia-silvester . @natalia-silvester
Follow
395 views
Uploaded On 2015-10-16

Register Allocation - PPT Presentation

Zach Ma Memory Model Register Classes Local Register Allocation Global Register Allocation Overview The choice of memory model fundamentally determines the allocators task In a registertoregister model ID: 162948

registers register values memory register registers memory values allocation graph model virtual allocate bottom general coloring purpose compiler called

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Register Allocation" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Register Allocation

Zach MaSlide2

Memory Model

Register Classes

Local Register AllocationGlobal Register Allocation

OverviewSlide3

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.

Memory modelSlide4

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.

Register ClassesSlide5

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.

Local Register

AllocationSlide6

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

I

t

dedicates a physical register to one virtual register for the entire basic block.

Top-down ApproachSlide7

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.Bottom-up ApproachSlide8
Slide9

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

Bottom-up ContinueSlide10

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

Two Examples of SpillSlide11

A closed set of related definitions and uses

that serves

as the base name spaceLive RangesSlide12

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.

Global Register AllocationSlide13

Variations

on Graph-Coloring

AllocationGlobal Register Allocation over SSA Form

Advanced TopicsSlide14

Thank you