Linear Scan Register Allocation POLETTO ET AL. PRESENTED BY MUHAMMAD HUZAIFA (MOST) SLIDES BORROWED FROM CHRISTOPHER TUTTLE 1.

Slides:



Advertisements
Similar presentations
Performance Evaluation of Cache Replacement Policies for the SPEC CPU2000 Benchmark Suite Hussein Al-Zoubi.
Advertisements

Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Register Allocation COS 320 David Walker (with thanks to Andrew Myers for many of these slides)
Compiler Support for Superscalar Processors. Loop Unrolling Assumption: Standard five stage pipeline Empty cycles between instructions before the result.
Comparison and Evaluation of Back Translation Algorithms for Static Single Assignment Form Masataka Sassa #, Masaki Kohama + and Yo Ito # # Dept. of Mathematical.
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.
Register allocation Morgensen, Torben. "Register Allocation." Basics of Compiler Design. pp from (
Register Allocation Zach Ma.
Register Allocation CS 320 David Walker (with thanks to Andrew Myers for most of the content of these slides)
Coalescing Register Allocation CS153: Compilers Greg Morrisett.
COMPILERS Register Allocation hussein suleman uct csc305w 2004.
1 CS 201 Compiler Construction Machine Code Generation.
Graph-Coloring Register Allocation CS153: Compilers Greg Morrisett.
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.
Carnegie Mellon Lecture 6 Register Allocation I. Introduction II. Abstraction and the Problem III. Algorithm Reading: Chapter Before next class:
School of Computer Science A Global Progressive Register Allocator David Ryan Koes Seth Copen Goldstein Carnegie Mellon University
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.
Register Allocation (Slides from Andrew Myers). Main idea Want to replace temporary variables with some fixed set of registers First: need to know which.
November 29, 2005Christopher Tuttle1 Linear Scan Register Allocation Massimiliano Poletto (MIT) and Vivek Sarkar (IBM Watson)
Prof. Bodik CS 164 Lecture 171 Register Allocation Lecture 19.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
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.
Introduction to Code Generation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
4/29/09Prof. Hilfinger CS164 Lecture 381 Register Allocation Lecture 28 (from notes by G. Necula and R. Bodik)
Register Allocation and Spilling via Graph Coloring G. J. Chaitin IBM Research, 1982.
CS745: Register Allocation© Seth Copen Goldstein & Todd C. Mowry Register Allocation.
Applying Data Copy To Improve Memory Performance of General Array Computations Qing Yi University of Texas at San Antonio.
Just-In-Time Java Compilation for the Itanium Processor Tatiana Shpeisman Guei-Yuan Lueh Ali-Reza Adl-Tabatabai Intel Labs.
Fast, Effective Code Generation in a Just-In-Time Java Compiler Rejin P. James & Roshan C. Subudhi CSE Department USC, Columbia.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
1 Advance Computer Architecture CSE 8383 Ranya Alawadhi.
1 Instruction Sets and Beyond Computers, Complexity, and Controversy Brian Blum, Darren Drewry Ben Hocking, Gus Scheidt.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Register Allocation John Cavazos University.
CMPE 511 Computer Architecture A Faster Optimal Register Allocator Betül Demiröz.
ANALYSIS AND IMPLEMENTATION OF GRAPH COLORING ALGORITHMS FOR REGISTER ALLOCATION By, Sumeeth K. C Vasanth K.
Interference Graphs for Programs in Static Single Information Form are Interval Graphs Philip Brisk Processor Architecture Laboratory (LAP) EPFL Lausanne,
Chapter 4 Memory Management Virtual Memory.
Introduction to Code Generation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
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.
Sunpyo Hong, Hyesoon Kim
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
More Code Generation and Optimization Pat Morin COMP 3002.
Optimizing Compilers Background
Register Allocation Hal Perkins Autumn 2009
Chapter 9 – Real Memory Organization and Management
Topic Register Allocation
Linear Scan Register Allocation Massimiliano Poletto, Vivek Sarkar A Fast, Memory-Efficient Register Allocation Framework for Embedded Systems Sathyanarayanan.
Optimization Code Optimization ©SoftMoore Consulting.
CSCI1600: Embedded and Real Time Software
Register Allocation Hal Perkins Autumn 2011
Register Allocation Hal Perkins Summer 2004
Register Allocation Hal Perkins Autumn 2005
Lecture 16: Register Allocation
Lecture 17: Register Allocation via Graph Colouring
CSCI1600: Embedded and Real Time Software
(via graph coloring and spilling)
CS 201 Compiler Construction
Presentation transcript:

Linear Scan Register Allocation POLETTO ET AL. PRESENTED BY MUHAMMAD HUZAIFA (MOST) SLIDES BORROWED FROM CHRISTOPHER TUTTLE 1

Introduction Register Allocation: The problem of mapping an unbounded number of virtual registers to physical ones Good register allocation is necessary for performance ◦Several SPEC benchmarks benefit an order of magnitude from good allocation ◦Core memory (and even caches) are slow relative to registers Register allocation is expensive ◦Most algorithms are variations on Graph Coloring ◦Non-trivial algorithms require liveness analysis ◦Allocators can be quadratic in the number of live intervals 2

Motivation On-line compilers need to generate code quickly ◦Just-In-Time compilation ◦Dynamic code generation in language extensions (‘C) ◦Interactive environments (IDEs, etc.) Sacrifice code speed for a quicker compile ◦Find a faster allocation algorithm ◦Compare it to the best allocation algorithms 3

Definitions Live interval: A sequence of instructions, outside of which a variable v is never live (For this paper, intervals are assumed to be contiguous) Spilling: Variables are spilled when they are stored on the stack Interference: Two live ranges interfere if they are simultaneously live in a program 4

Graph Coloring Model allocation as a graph coloring problem Nodes represent live ranges Edges represent interference Colorings are safe allocations Order V 2 in live variables 5

Linear Scan Algorithm Perform live variable analysis Keep list of live intervals sorted in order of increasing start point Keep list of active intervals sorted in order of increasing end point Walk through intervals once in order: ◦Throw away expired live intervals ◦If there is contention, spill the interval that ends furthest in the future (other heuristics can be used too) ◦Allocate new interval to any free register Complexity: O(V log R) for V variables and R registers 6

November 29, 2005CHRISTOPHER TUTTLE 7 Example With Two Registers 1. Active =

November 29, 2005CHRISTOPHER TUTTLE 8 Example With Two Registers 1. Active = 2. Active =

November 29, 2005CHRISTOPHER TUTTLE 9 Example With Two Registers 1. Active = 2. Active = 3. Active = ; Spill =

November 29, 2005CHRISTOPHER TUTTLE 10 Example With Two Registers 1. Active = 2. Active = 3. Active = ; Spill = 4. Active = ; Spill =

November 29, 2005CHRISTOPHER TUTTLE 11 Example With Two Registers 1. Active = 2. Active = 3. Active = ; Spill = 4. Active = ; Spill = 5. Active = ; Spill =

Evaluation Overview Evaluate both compile-time and run-time performance Two Implementations ◦ICODE dynamic ‘C compiler (optimized for fast compilation) ◦Small dynamic code kernels like matrix multiplication, sorting, etc. ◦Compare against tuned graph-coloring and usage counts ◦Also evaluate a few pathological program examples ◦Machine SUIF (optimized for high performance) ◦Various benchmarks from SPEC92 and SPEC95 ◦Compare against graph-coloring, usage counts, and second-chance binpacking Compare both metrics on both implementations 12

Compile-Time on ICODE ‘C Usage Counts, Linear Scan, and Graph Coloring Linear Scan allocation is always faster than Graph Coloring 13

Compile-Time on SUIF Linear Scan allocation is around twice as fast than Binpacking ◦(Binpacking is known to be slower than Graph Coloring) 14

Pathological Cases (1) N live variable ranges interfering over the entire program 15

Pathological Cases (2) K staggered sets of live intervals in which no more than M intervals overlap at a time 16 k m

Compile-Time Bottom Line Linear Scan ◦is faster than Binpacking and Graph Coloring ◦scales more gracefully than Graph Coloring … but can it play Crysis does it generate good code? 17

Run-Time on ICODE ‘C Usage Counts, Linear Scan, and Graph Coloring Dynamic kernels do not have enough register pressure to illustrate differences 18

Run-Time on SUIF / SPEC Usage Counts, Linear Scan, Graph Coloring and Binpacking shown Linear Scan makes a fair performance trade-off (5% - 10% slower than G.C.) 19

Variations Fast Live Variable Analysis Numbering Heuristics Spilling Heuristics 20

Conclusions Linear Scan is a faster alternative to Graph Coloring for register allocation Linear Scan generates faster code than similar algorithms (Binpacking, Usage Counts) Possible optimizations: ◦Reduce register interference with live range splitting ◦Use register move coalescing to free up extra registers 21

THANK YOU FOR YOUR TIME! QUESTIONS? 22

Backup Slides 23

SCC-Based Liveness Analysis 24

Flow Graph Numbering 25

Spilling Heuristics 26