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

Similar documents
CS553 Lecture Register Allocation 1

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

CS553 Lecture Register Allocation I 3

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

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

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

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

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

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

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

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

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

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

Planar Upward Drawings

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

COMP108 Algorithmic Foundations

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

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

12. Traffic engineering

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

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

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

1 Introduction to Modulo 7 Arithmetic

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

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

CS 241 Analysis of Algorithms

Present state Next state Q + M N

Constructive Geometric Constraint Solving

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

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

The University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

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

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

0.1. Exercise 1: the distances between four points in a graph

Aquauno Video 6 Plus Page 1

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

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

Seven-Segment Display Driver

Section 3: Antiderivatives of Formulas

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

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

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

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

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

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

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

Chapter 9. Graphs. 9.1 Graphs

Announcements. Programming Project 4 due Saturday, August 18 at 11:30AM

Garnir Polynomial and their Properties

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

Nefertiti. Echoes of. Regal components evoke visions of the past MULTIPLE STITCHES. designed by Helena Tang-Lim

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

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

Problem solving by search

QUESTIONS BEGIN HERE!

EE1000 Project 4 Digital Volt Meter

Numbering Boundary Nodes

Instructions for Section 1

Minimum Spanning Trees

CS September 2018

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?

Construction 11: Book I, Proposition 42

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

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

Designing A Concrete Arch Bridge

Multipoint Alternate Marking method for passive and hybrid performance monitoring

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

a b c cat CAT A B C Aa Bb Cc cat cat Lesson 1 (Part 1) Verbal lesson: Capital Letters Make The Same Sound Lesson 1 (Part 1) continued...

Chapter 16. 1) is a particular point on the graph of the function. 1. y, where x y 1

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

d e c b a d c b a d e c b a a c a d c c e b

QUESTIONS BEGIN HERE!

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

Jonathan Turner Exam 2-10/28/03

Last time: introduced our first computational model the DFA.

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

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

This chapter covers special properties of planar graphs.

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

Graph Contraction and Connectivity

Improving Union. Implementation. Union-by-size Code. Union-by-Size Find Analysis. Path Compression! Improving Find find(e)

Decimals DECIMALS.

Fundamental Algorithms for System Modeling, Analysis, and Optimization

Chem 104A, Fall 2016, Midterm 1 Key

MULTIPLE-LEVEL LOGIC OPTIMIZATION II

Ch 1.2: Solutions of Some Differential Equations

CSCI Compiler Design

XML and Databases. Outline. Recall: Top-Down Evaluation of Simple Paths. Recall: Top-Down Evaluation of Simple Paths. Sebastian Maneth NICTA and UNSW

Winter 2016 COMP-250: Introduction to Computer Science. Lecture 23, April 5, 2016

Weighted Graphs. Weighted graphs may be either directed or undirected.

SOLVED EXAMPLES. be the foci of an ellipse with eccentricity e. For any point P on the ellipse, prove that. tan

(a) v 1. v a. v i. v s. (b)

Formal Concept Analysis

Transcription:

Rgistr Allotion W now r l to o rgistr llotion on our intrfrn grph. W wnt to l with two typs of onstrints: 1. Two vlus r liv t ovrlpping points (intrfrn grph) 2. A vlu must or must not in prtiulr rhitturl rgistr Rgistr Allotion is ompris of two prts: Rgistr llotion in whih w fin st of virtul rgistrs tht oul pl in th sm physil lotion Rgistr ssignmnt in whih w tully i whih rhitturl rgistr to put st of non-intrfring vlus Rgistr Allotion Rgistr Allotion rus to prolm known s Grph Coloring, whr w try to olor grph without using th sm olor on two nighoring trritoris. If w onsir th st of olors to our rgistrs n our trritoris th virtul rgistrs, it s lrly th prolm w wish to solv. Howvr, it is NP-omplt, whih mns it is (likly) intrtl without numrtion of ll possil omintions. Or t lst, w on t know how to o it othrwis. Th goo nws is tht w n us huristis (inform ruls of gussing) to mk th prolm prtilly solvl in rsonl tim with goo nough nswr. Prinipl Phss Buil Buil th intrfrn grph from th liv rngs of our virtul rgistr st Simplify Us huristi to ttmpt to olor th grph W ll us th huristi tht if our intrfrn grph hs no m of gr (mount of nighors) < K (our rgistr st siz), w n rmov tht no from th grph. If th rsulting grph n K olor, so n th originl grph, sin som olor n foun to olor no m. This rsults in rursiv lgorithm. Eh simplifition stp mks th prolm smllr n sir to solv. Prinipl Phss Spill Unfortuntly, ll of th rmining nos my hv K nighors vn ftr simplifition. Ths nos r of signifint gr Th ision might n to tht w mov n itm to mmory n kp it thr. W ll this spill. Any spill vlu os not intrfr with ny of th nos in th grph, n so it my rmov n th prour ontinus simplifying Slt Assign olors to nos in th grph y strting with n mpty grph n ing nos from our simplify stk. Thr must lwys olor to ssign u to our huristi. W now trmin potntil spills from tul spills. W might luky n gt no tht hs 2 or mor nighors tht r th sm olor, n thus w n olor th no. This is optimisti oloring. Spills Exmpl: Buil If th slt phs is unl to fin olor for potntil spill, it oms n tul spill. Atul spills must stor in mmory. This mns tht w r hnging th progrm o to lo th vlu from mmory into rgistr for w us it. Sin w n rgistr to lo th mmory vlu into, our liv rngs hv hng: W now hv nw rgistrs with tiny liv rngs whih potntilly intrfr with our oloring. W must strt ll ovr with th rwrittn (spills inorport) progrm o. := 0 := mm[] := * 2 := + := := * := + := + 1 Th sh lin inits opy, not n intrfrn. 1

Exmpl: Simplify Exmpl: Simplify Strt with our intrfrn grph, n mpty stk, n K=3 olors. Vril sms worrying sin it is of signifint gr (i.., it hs gr 3). Rmov no with gr < K n push it on th stk. Th rmov no s gs will rs th gr of th rmining nos. Exmpl: Simplify Exmpl: Simplify Exmpl: Simplify Exmpl: Simplify 2

Exmpl: Simplify Exmpl: Slt W foun no potntil spills, so w n skip tht stp n go stright to th slt phs. Strting from n mpty grph, pop off h no n giv it olor. Exmpl: Slt Exmpl: Slt Exmpl: Slt Exmpl: Slt 3

Exmpl: Slt Colsing W n rmov runnt movs if th sour n stintions hv no g twn thm in th intrfrn grph. W n thn simply tll th rgistr llotor to llot oth th sour n stintion into th sm rgistr y olsing oth nos into singl no in th grph. Howvr, sin this no is th union of th two nos ing ols, th possiility xists of prvnting th rsulting grph from ing K-olorl whn th prvious grph ws. Don. W hv 3-olor our intrfrn grph. Consrvtivly, w n o sf olsing lgorithm tht n gurnt w will nvr prou n unolorl grph from olorl on. Briggs Colsing Gorg Colsing Nos n n ols if th rsulting no,, will hv fwr thn K nos of signifint gr. This works us simplify rmov ll nos of insignifint gr. This mns tht will only jnt to th nos of signifint gr. If thr r lss thn K nighors of signifint gr, thn simplify n rmov this no n oloring n pro. Nos n n ols if, for vry nighor t of, ithr: t lry intrfrs with, or t is of insignifint gr Proof: Lt S th st of nighors of with insignifint gr. If olsing is not on, Simplify n rmov ll of S, lving grph G 1 If olsing is on, Simplify n still rmov ll of S, lving grph G 2 G 2 is sugrph of G 1 sin no orrspons to th no in G 1. Thus, G 2 must s sy to olor s G 1. Colsing Rgistr Coloring Algorithm Ths r sf, ut onsrvtiv olsing shms, so thy my miss opportunitis to ols movs. Strt Buil Howvr, n xtr mov is lss ostly thn ny itionl spills. A Cols phs will to our lgorithm from for, n our Simply routin will intrlv with it: w simplify n ols until our grph is mpty. This will limint most mov instrutions ut still olorl. Ro with rwrittn progrm Simplify Cols Frz Potntil Spill Slt Atul Spill Don 4

RgAllo with Colsing Buil Buil th intrfrn grph Clssify h no s mov-rlt or not Mov-rlt mns tht it is th stintion or sour of mov Simplify Rmov h non-mov rlt no of low gr (<K) on t tim Cols Prform on of th onsrvtiv lgorithms w hv shown on th rsulting simplifi grph Elimint th ssoit mov instrution If th rsulting no is no longr mov-rlt, it n simplifi in th nxt roun Simplify n Cols r rpt until only signifint-gr or mov-rlt nos rmin. RgAllo with Colsing Frz If w nnot simplify or ols, w look for mov-rlt no of low gr Wfrz suh no, tht is, w giv up trying to ols it Mrk it s non-mov-rlt n go k to oing Simplify n Cols Spill If w n t simplify, ols, or frz n only signifint gr nos rmin, slt signifint gr no to potntilly spill Push it on th stk Slt Pop h lmnt off th stk n ssign it olor Exmpl: Buil Exmpl: Simplify := 0 := mm[] := * 2 := + := := * := + := + 1 Thr r two mov-rlt nos, n. W will simplify only thos nos tht r of non-signifint gr n non-mov-rlt. For K=3, tht s only. Exmpl: Simplify Exmpl: Cols W will simplify only thos nos tht r of non-signifint gr n non-mov-rlt. n only hv two nighors of signifint gr n so thy my sfly ols. For K=3, tht s only. 5

Exmpl: Cols Exmpl: Cols n only hv two nighors of signifint gr n so thy my sfly ols. W rmov th mov instrution n mrk s non-mov-rlt. n only hv two nighors of signifint gr n so thy my sfly ols. W rmov th mov instrution n mrk s non-mov-rlt. Exmpl: Simplify Exmpl: Simplify W now hv nos tht hv non-signifint gr tht w n simplify. Exmpl: Simplify Exmpl: Simplify With n mpty grph, w hv no n for th Frz or Spill stps. W now ruil th grph ssigning olors s w go. 6

Exmpl: Slt Exmpl: Slt Exmpl: Slt Exmpl: Slt Exmpl: Rsult Constrin Movs := 0 := mm[] := * 2 := + := * := + := + 1 Somtims thr my multipl hois for olsing movs. For instn, w my hv thr vrils,,, n n two movs: := := If (, ) is n g in our intrfrn grph, olsing n into rsults in: := With th olsing of n, w hv rwrittn th o to rmov th mov n n will oth ssign to th sm rgistr. Whih hs n intrfrn g twn thm. This mov is onstrin n nnot ols. W trt it s non-mov-rlt n is no longr onsir for olsing. 7

Spilling Whn w hv to spill, Buil n Simplify must rrun on th progrm. With olsing, w throw wy work tht osn t inrs th numr of spills. A ttr lgorithm n kp ll olss on for th first potntil spill ws isovr. Howvr, vn mor n on. If w hv vry onstrin mhin, suh s x86 with its 6 gnrl purpos rgistrs, w my n up spilling mny tmporris into th stk frm. Movs of spill vlus involv loing th sour into rgistr, rting nw liv rng n furthr onstrining th rsults. Spill Colsing W n tully o grph oloring on th spill lotions us thy my not liv ithr. It s tully sir to o us w r not onstrin y th numr of tivtion ror lotions, so w n ols ggrssivly. Th lgorithm is: 1. Construt intrfrn for spill nos 2. Cols ll non-intrfring spill nos onnt vi mov 3. Us Simplify n Slt to olor th grph. Thr is no limit on th numr of olors, so Simplify n pik th lowst gr no n Slt n pik th first vill olor 4. Us th olors to ssign stk lotions to th spills Do this for gnrting spill instrutions to voi unnssry lo/stors for ols movs of spills. Proloring Somtims w hv onstrints on th mhin rgistrs tht hol spifi vlus. For instn, th stk pointr, th frm pointr, th rgumnt rgistrs, t. W n ssign ths rgistrs olor for w run our lgorithm so tht w n in vlu to tht rgistr. This is ll proloring n thr must t most on prolor no of givn olor. Slt n Cols n ssign nos th sm olor s prolor nos s long s thy o not intrfr. For instn, $3 in MIPS oul us to hol tmporry in funtion tht os not tk 4 prmtrs. Prolor Nos Th lgorithm now lls Simplify, Cols, n Spill until only th prolor nos rmin. Thn Slt will th othr nos k in whil oloring thm. Prolor nos o not spill n thus thir liv rngs shoul kpt short. This n on y gnrting movs for vlus into n out of prolor nos. Only if thr is onsirl rgistr prssur high mn for rgistrs will th mov rmin ftr olsing. Whn w hv K rgistrs, w n K prolor nos tht ll intrfr with h othr, n thus nnot ols. Thy shoul not spill, sin thy r, y finition, rgistrs. Thy lso nnot simplifi, w must trt thm s hving infinit gr. Cllr- n Cll-sv Rgistrs Th onstrints of llr-sv n ll-sv rgistrs n nfor y ugmnting th ll instrutions of our IR. A ll instrution n nnott to intrfr with ll of th llr-sv rgistrs. If vril is not liv ross th prour ll, it will most likly llot to llr-sv rgistr. If vril is liv ross ll, it must thn intrfr with ll of th llr-sv rgistrs n it will intrfr with th tmporris rt for ll-sv rgistrs. This will rsult in spill, sving th vlu to mmory. W n stimt spill ost to trmin whih vlu is st put in mmory. A si huristi woul spill no with high gr in th intrfrn grph ut fw uss. 8