CS553 Lecture Register Allocation I 3

Similar documents
CS553 Lecture Register Allocation 1

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

Graphs and Graph Searches

Solutions to Homework 5

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

CS 241 Analysis of Algorithms

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

Chapter Finding Small Vertex Covers. Extending the Limits of Tractability. Coping With NP-Completeness. Vertex Cover

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

Computational Biology, Phylogenetic Trees. Consensus methods

Examples and applications on SSSP and MST

Steinberg s Conjecture is false

N1.1 Homework Answers

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

Analysis of Algorithms - Elementary graphs algorithms -

Junction Tree Algorithm 1. David Barber

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

COMP108 Algorithmic Foundations

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

Register Allocation. How to assign variables to finitely many registers? What to do when it can t be done? How to do so efficiently?

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

Exam 1. It is important that you clearly show your work and mark the final answer clearly, closed book, closed notes, no calculator.

The second condition says that a node α of the tree has exactly n children if the arity of its label is n.

10. EXTENDING TRACTABILITY

Case Study Vancomycin Answers Provided by Jeffrey Stark, Graduate Student

Addition of angular momentum

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

AP Calculus BC Problem Drill 16: Indeterminate Forms, L Hopital s Rule, & Improper Intergals

Evans, Lipson, Wallace, Greenwood

Minimum Spanning Trees

Digital Signal Processing, Fall 2006

CS 461, Lecture 17. Today s Outline. Example Run

Announcements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

CS 6353 Compiler Construction, Homework #1. 1. Write regular expressions for the following informally described languages:

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

Analysis of Algorithms - Elementary graphs algorithms -

Multiple Short Term Infusion Homework # 5 PHA 5127

First order differential equation Linear equation; Method of integrating factors

L I R M M O N T P E L L I E R

Chapter 6 Folding. Folding

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

EEO 401 Digital Signal Processing Prof. Mark Fowler

Kernels. ffl A kernel K is a function of two objects, for example, two sentence/tree pairs (x1; y1) and (x2; y2)

A Propagating Wave Packet Group Velocity Dispersion

Addition of angular momentum

Final Exam Solutions

Edge-Triggered D Flip-flop. Formal Analysis. Fundamental-Mode Sequential Circuits. D latch: How do flip-flops work?

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

5/1/2018. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees

RAM Model. I/O Model. Real Machine Example: Nehalem : Algorithms in the Real World 4/9/13

PHYS ,Fall 05, Term Exam #1, Oct., 12, 2005

Constructive Geometric Constraint Solving

12. Traffic engineering

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

Aquauno Video 6 Plus Page 1

Instruction Scheduling

Numbering Boundary Nodes

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

MA1506 Tutorial 2 Solutions. Question 1. (1a) 1 ) y x. e x. 1 exp (in general, Integrating factor is. ye dx. So ) (1b) e e. e c.

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

Searching Linked Lists. Perfect Skip List. Building a Skip List. Skip List Analysis (1) Assume the list is sorted, but is stored in a linked list.

From Elimination to Belief Propagation

3+<6,&6([DP. September 29, SID (last 5 digits): --

Organization. Dominators. Control-flow graphs 8/30/2010. Dominators, control-dependence. Dominator relation of CFGs

Trigonometry. Contents. Syllabus subject matter

LR(0) Analysis. LR(0) Analysis

First derivative analysis

3) Use the average steady-state equation to determine the dose. Note that only 100 mg tablets of aminophylline are available here.

priority queue ADT heaps 1

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

CS 491 G Combinatorial Optimization

Section 10.4 Connectivity (up to paths and isomorphism, not including)

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

Codes on Planar Graphs

Unit 6: Solving Exponential Equations and More

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Calculus II (MAC )

Present state Next state Q + M N

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

Alpha and beta decay equation practice

Hydrogen Atom and One Electron Ions

Higher order derivatives

QUESTIONS BEGIN HERE!

EEO 401 Digital Signal Processing Prof. Mark Fowler

Coupled Pendulums. Two normal modes.

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

The Matrix Exponential

On the Hamiltonian of a Multi-Electron Atom

Transcription:

Low-Lvl Issus Last ltur Intrproural analysis Toay Start low-lvl issus Rgistr alloation Latr Mor rgistr alloation Instrution shuling CS553 Ltur Rgistr Alloation I 2 Rgistr Alloation Prolm Assign an unoun numr of symoli rgistrs to a fix numr of arhittural rgistrs (whih might gt rnam y th harwar to som numr of physial rgistrs) Simultanously liv ata must assign to iffrnt arhittural rgistrs Goal Minimiz ovrha of assing ata Mmory oprations (loas & stors) Rgistr movs CS553 Ltur Rgistr Alloation I 3 1

Sop of Rgistr Alloation Exprssion Loal Loop Gloal Intrproural CS553 Ltur Rgistr Alloation I 4 Granularity of Alloation What is alloat to rgistrs? Varials Liv rangs/ws (i.., u-hains with ommon uss) Valus (i.., finitions; sam as varials with SSA & opy propagation) t 1 : x := 5 2 t 2 : y := x 3 t 3 : x := y+1 4 1 t 6 :... x... t 4 :... x... t 5 : x := 3 Varials: 2 (x & y) Liv Rangs/W: 3 (t 1 t 2,t 4 ; t 2 t 3 ; t 3,t 5 t 6 ) Valus: 4 (t 1, t 2, t 3, t 5, φ (t 3,t 5 )) What ar th traoffs? Eah alloation unit is givn a symoli rgistr nam (.g., s1, s2, t.) CS553 Ltur Rgistr Alloation I 5 2

Gloal Rgistr Alloation y Graph Coloring Ia [Cok 71], First alloator [Chaitin 81] 1. Construt intrfrn graph G=(N,E) Rprsnts notion of simultanously liv Nos ar units of alloation (.g., varials, liv rangs/ws) g (n 1,n 2 ) E if n 1 an n 2 ar simultanously liv Symmtri (not rflxiv nor transitiv) 2. Fin k-oloring of G (for k rgistrs) Ajant nos an t hav sam olor 3. Alloat th sam rgistr to all alloation units of th sam olor Ajant nos must alloat to istint rgistrs s2 s1 s3 CS553 Ltur Rgistr Alloation I 6 Intrfrn Graph Exampl (Varials) a :=... :=... :=...... a... :=... a...... a :=......... a :=............... :=...... a............... :=... CS553 Ltur Rgistr Alloation I 7 3

Intrfrn Graph Exampl (Ws) :=... :=... :=......... :=... Consir ws (u-hains w/ ommon uss) insta of varials...... :=......... :=............... :=..................... :=... CS553 Ltur Rgistr Alloation I 8 Computing th Intrfrn Graph Us rsults of liv varial analysis for ah symoli-rgistr s i o for ah symoli-rgistr s j (j < i) o for ah f {finitions of s i } o if (s j is liv at f) thn E E (s i,s j ) CS553 Ltur Rgistr Alloation I 9 4

Coalsing Mov instrutions Co gnration an prou unnssary mov instrutions mov t1, t2 If w an assign t1 an t2 to th sam rgistr, w an liminat th mov Ia If t1 an t2 ar not onnt in th intrfrn graph, oals thm into a singl varial Prolm Coalsing an inras th numr of gs an mak a graph unoloral Limit oalsing to avoi unoloral graphs oals t1 t2 t1 t2 CS553 Ltur Rgistr Alloation I 10 Alloating Rgistrs Using th Intrfrn Graph K-oloring Color graph nos using up to k olors Ajant nos must hav iffrnt olors Alloating to k rgistrs fining a k-oloring of th intrfrn graph Ajant nos must alloat to istint rgistrs But... Optimal graph oloring is NP-omplt Rgistr alloation is NP-omplt, too (must approximat) What if w an t k-olor a graph? (must spill) CS553 Ltur Rgistr Alloation I 11 5

Spilling If w an t fin a k-oloring of th intrfrn graph Spill varials (nos) until th graph is oloral Choosing varials to spill Choos last frquntly ass varials Brak tis y hoosing nos with th most onflits in th intrfrn graph Ys, ths ar huristis! CS553 Ltur Rgistr Alloation I 12 Wight Intrfrn Graph Goal Wight(s) =! f ( r) f(r) is xution frquny of r " rfrns r of s Stati approximation Us som rasonal shm to rank varials On possiility Wight(s) = 1 Nos aftr ranh: ½ wight of ranh Nos in loop: 10 wight of nos outsi loop CS553 Ltur Rgistr Alloation I 13 6

Simpl Gry Algorithm for Rgistr Alloation for ah n N o { slt n in rasing orr of wight } if n an olor thn o it { rsrv a rgistr for n } ls Rmov n (an its gs) from graph { alloat n to stak (spill) } CS553 Ltur Rgistr Alloation I 14 Exampl Attmpt to 3-olor this graph (,, ) Wight orr: What if you us a iffrnt wighting? CS553 Ltur Rgistr Alloation I 15 7

Exampl Attmpt to 2-olor this graph (, ) Wight orr: a a CS553 Ltur Rgistr Alloation I 16 Improvmnt #1: Simplifiation Phas [Chaitin 81] Ia Nos with < k nighors ar guarant oloral Rmov thm from th graph first Rus th gr of th rmaining nos Must spill only whn all rmaining nos hav gr k CS553 Ltur Rgistr Alloation I 17 8

Algorithm [Chaitin81] whil intrfrn graph not mpty o whil a no n with < k nighors o Rmov n from th graph simplify Push n on a stak if any nos rmain in th graph thn { lok with >= k gs } Pik a no n to spill { lowst spill-ost or } spill A n to spill st { highst gr } Rmov n from th graph if spill st not mpty thn Insrt spill o for all spill nos { stor aftr f; loa for us } Ronstrut intrfrn graph & start ovr whil stak not mpty o Pop no n from stak olor Alloat n to a rgistr CS553 Ltur Rgistr Alloation I 18 Mor on Spilling Chaitin s algorithm rstarts th whol pross on spill Nssary, aus spill o (loas/stors) uss rgistrs Okay, aus it usually only happns a oupl tims Altrnativ Rsrv 2-3 rgistrs for spilling Don t n to start ovr But hav fwr rgistrs to work with CS553 Ltur Rgistr Alloation I 19 9

Exampl Attmpt to 3-olor this graph (,, ) Stak: Wight orr: CS553 Ltur Rgistr Alloation I 20 Exampl Attmpt to 2-olor this graph (, ) Spill St: Stak: Wight orr: Many nos rmain unolor vn though w oul larly o ttr CS553 Ltur Rgistr Alloation I 21 10

Th Prolm: Worst Cas Assumptions Is th following graph 2-oloral? s1 s4 s2 s3 Clarly 2-oloral But Chaitin s algorithm las to an immiat lok an spill Th algorithm assums th worst as, namly, that all nighors will assign a iffrnt olor CS553 Ltur Rgistr Alloation I 22 Improvmnt #2: Optimisti Spilling [Briggs 89] s1 s4 s2 s3 Ia Som nighors might gt th sam olor Nos with k nighors might oloral Bloking os not imply that spilling is nssary Push lok nos on stak (rathr than pla in spill st) Chk oloraility upon popping th stak, whn mor information is availal Dfr ision CS553 Ltur Rgistr Alloation I 23 11

Algorithm [Briggs t al. 89] whil intrfrn graph not mpty o whil a no n with < k nighors o Rmov n from th graph simplify Push n on a stak if any nos rmain in th graph thn { lok with >= k gs } Pik a no n to spill { lowst spill-ost/highst gr } Push n on stak fr ision Rmov n from th graph whil stak not mpty o Pop no n from stak mak ision if n is oloral thn Alloat n to a rgistr ls Insrt spill o for n { Stor aftr f; loa for us } Ronstrut intrfrn graph & start ovr CS553 Ltur Rgistr Alloation I 24 Exampl Attmpt to 2-olor this graph (, ) Stak: * * * * * lok no Wight orr: CS553 Ltur Rgistr Alloation I 25 12

Improvmnt #3: Liv Rang Splitting [Chow & Hnnssy 84] Ia Start with varials as our alloation unit Whn a varial an t alloat, split it into multipl surangs for sparat alloation Sltiv spilling: put som surangs in rgistrs, som in mmory Insrt mmory oprations at ounaris Why is this a goo ia? CS553 Ltur Rgistr Alloation I 26 Improvmnt #4: Rmatrialization [Chaitin 82]&[Briggs 84] Ia Sltivly r-omput valus rathr than loaing from mmory Rvrs CSE Easy as Valu an omput in singl instrution, an All oprans ar availal Exampls Constants Arsss of gloal varials Arsss of loal varials (on stak) CS553 Ltur Rgistr Alloation I 27 13

Nxt Tim Ltur Mor rgistr alloation Alloation aross prour alls CS553 Ltur Rgistr Alloation I 28 14