Register Allocation Zach Ma.

Slides:



Advertisements
Similar presentations
Register Allocation Consists of two parts: Goal : minimize spills
Advertisements

Register Usage Keep as many values in registers as possible Register assignment Register allocation Popular techniques – Local vs. global – Graph coloring.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
CPU Review and Programming Models CT101 – Computing Systems.
Coalescing Register Allocation CS153: Compilers Greg Morrisett.
COMPILERS Register Allocation hussein suleman uct csc305w 2004.
1 CS 201 Compiler Construction Machine Code Generation.
Stanford University CS243 Winter 2006 Wei Li 1 Register Allocation.
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
Operating Systems Lecture 10 Issues in Paging and Virtual Memory Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing.
Program Representations. Representing programs Goals.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
1 CS 201 Compiler Construction Lecture 12 Global Register Allocation.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
November 29, 2005Christopher Tuttle1 Linear Scan Register Allocation Massimiliano Poletto (MIT) and Vivek Sarkar (IBM Watson)
1 Register Allocation Consists of two parts: –register allocation What will be stored in registers –Only unambiguous values –register assignment Which.
Prof. Bodik CS 164 Lecture 171 Register Allocation Lecture 19.
1 Computer System Overview OS-1 Course AA
Register Allocation (via graph coloring)
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Register Allocation (via graph coloring). Lecture Outline Memory Hierarchy Management Register Allocation –Register interference graph –Graph coloring.
1 Liveness analysis and Register Allocation Cheng-Chia Chen.
Improving Code Generation Honors Compilers April 16 th 2002.
4/29/09Prof. Hilfinger CS164 Lecture 381 Register Allocation Lecture 28 (from notes by G. Necula and R. Bodik)
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Register Allocation and Spilling via Graph Coloring G. J. Chaitin IBM Research, 1982.
Part II: Addressing Modes
Linear Scan Register Allocation POLETTO ET AL. PRESENTED BY MUHAMMAD HUZAIFA (MOST) SLIDES BORROWED FROM CHRISTOPHER TUTTLE 1.
1.A file is organized logically as a sequence of records. 2. These records are mapped onto disk blocks. 3. Files are provided as a basic construct in operating.
Supplementary Lecture – Register Allocation EECS 483 University of Michigan.
Memory Management Chapter 7.
Spring 2014Jim Hogg - UW - CSE - P501P-1 CSE P501 – Compiler Construction Register allocation constraints Local allocation Fast, but poorer code Global.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
1 October 18, October 18, 2015October 18, 2015October 18, 2015 Azusa, CA Sheldon X. Liang Ph. D. Azusa Pacific University, Azusa, CA 91702, Tel:
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Register Allocation John Cavazos University.
VIRTUAL MEMORY By Thi Nguyen. Motivation  In early time, the main memory was not large enough to store and execute complex program as higher level languages.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Operand Addressing And Instruction Representation Cs355-Chapter 6.
Radix Sort and Hash-Join for Vector Computers Ripal Nathuji 6.893: Advanced VLSI Computer Architecture 10/12/00.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Register Usage Keep as many values in registers as possible Keep as many values in registers as possible Register assignment Register assignment Register.
Register Allocation CS 471 November 12, CS 471 – Fall 2007 Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
2/22/2016© Hal Perkins & UW CSEP-1 CSE P 501 – Compilers Register Allocation Hal Perkins Winter 2008.
1 Liveness analysis and Register Allocation Cheng-Chia Chen.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Memory Management Chapter 3
ITEC 202 Operating Systems
The compilation process
Register Allocation Hal Perkins Autumn 2009
Data Structures Interview / VIVA Questions and Answers
Local Register Allocation & Lab Exercise 1
Register Allocation Hal Perkins Autumn 2011
Instruction Scheduling Hal Perkins Summer 2004
Instruction Scheduling Hal Perkins Winter 2008
CS 201 Compiler Construction
Register Allocation Hal Perkins Summer 2004
Register Allocation Hal Perkins Autumn 2005
Local Register Allocation & Lab Exercise 1
Memory management Explain how memory is managed in a typical modern computer system (virtual memory, paging and segmentation should be described.
Lecture 16: Register Allocation
Instruction Scheduling Hal Perkins Autumn 2005
Compiler Construction
Lecture 17: Register Allocation via Graph Colouring
COMP755 Advanced Operating Systems
Instruction Scheduling Hal Perkins Autumn 2011
(via graph coloring and spilling)
CS 201 Compiler Construction
Presentation transcript:

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. 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.

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.

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.

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.

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.

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

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

Live Ranges A closed set of related definitions and uses that serves as the base name space

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.

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

Thank you