CS553 Lecture Register Allocation 1

Similar documents
CS553 Lecture Register Allocation I 3

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

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

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

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

CS 241 Analysis of Algorithms

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

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)}

Constructive Geometric Constraint Solving

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

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

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

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

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

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

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

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

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

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

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

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

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

COMP108 Algorithmic Foundations

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

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

Present state Next state Q + M N

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

1 Introduction to Modulo 7 Arithmetic

Problem solving by search

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

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

CSCI Compiler Design

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?

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

Seven-Segment Display Driver

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

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

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

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

CS September 2018

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

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

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

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

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

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

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

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

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

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

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

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

Planar Upward Drawings

Aquauno Video 6 Plus Page 1

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

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

Minimum Spanning Trees

EE1000 Project 4 Digital Volt Meter

12. Traffic engineering

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

Outline. Binary Tree

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

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

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

Jonathan Turner Exam 2-10/28/03

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

A 4-state solution to the Firing Squad Synchronization Problem based on hybrid rule 60 and 102 cellular automata

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

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

Module 2 Motion Instructions

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

QUESTIONS BEGIN HERE!

Computational Biology, Phylogenetic Trees. Consensus methods

Instruction Scheduling

CS 103 BFS Alorithm. Mark Redekopp

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

ECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.

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

10. EXTENDING TRACTABILITY

QUESTIONS BEGIN HERE!

Chapter 9. Graphs. 9.1 Graphs

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

Last time: introduced our first computational model the DFA.

Graph Contraction and Connectivity

Trees as operads. Lecture A formalism of trees

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

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

Decimals DECIMALS.

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

WORKSHOP 6 BRIDGE TRUSS

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

b.) v d =? Example 2 l = 50 m, D = 1.0 mm, E = 6 V, " = 1.72 #10 $8 % & m, and r = 0.5 % a.) R =? c.) V ab =? a.) R eq =?

Fundamental Algorithms for System Modeling, Analysis, and Optimization

Solutions to Homework 5

COMP 250. Lecture 29. graph traversal. Nov. 15/16, 2017

Transcription:

Low-Lvl Issus Lst ltur Livnss nlysis Rgistr llotion Toy Mor rgistr llotion Wnsy Common suxprssion limintion or PA2 Logistis PA1 is u PA2 hs n post Mony th 15 th, no lss u to LCPC in Orgon CS553 Ltur Rgistr Allotion 1 Rgistr Allotion Prolm Assign n unoun numr o symoli rgistrs to ix numr o rhitturl rgistrs Simultnously liv t must ssign to irnt rhitturl rgistrs Gol Minimiz ovrh o ssing t Mmory oprtions (los & stors) Rgistr movs CS553 Ltur Rgistr Allotion 2

Grph Coloring Approh to Rgistr Allotion Min Stps Crt n intrrn grph Us huristi to olor th intrrn grph Eh olor rprsnts rgistr CS553 Ltur Rgistr Allotion 3 Intrrn Grph Exmpl (Vrils) :=... :=... :=......... :=......... :=......... :=............... :=..................... :=... CS553 Ltur Rgistr Allotion I 4

Computing th Intrrn Grph Us rsults o liv vril nlysis or h symoli-rgistr/tmporry t i o or h symoli-rgistr/tmporry t j (j < i) o or h {initions o t i } o i (t j is liv out t ) thn E E (t i,t j ) Options trt ll instrutions th sm trt MOVE instrutions spil whih is ttr? CS553 Ltur Rgistr Allotion I 5 Alloting Rgistrs Using th Intrrn Grph K-oloring Color grph nos using up to k olors Ajnt nos must hv irnt olors Alloting to k rgistrs ining k-oloring o th intrrn grph Ajnt nos must llot to istint rgistrs But... Optiml grph oloring is NP-omplt Optiml rgistr llotion is NP-omplt, too (must pproximt) Wht i w n t k-olor grph? (must spill) CS553 Ltur Rgistr Allotion I 6

Rgistr Allotion: Spilling I w n t in k-oloring o th intrrn grph Spill vrils (nos) until th grph is olorl Choosing vrils to spill Choos ritrrily or Choos lst rquntly ss vrils Brk tis y hoosing nos with th most onlits in th intrrn grph Ys, ths r huristis! CS553 Ltur Rgistr Allotion I 7 Spilling (Originl CFG n Intrrn Grph) :=... :=... :=......... :=......... :=......... :=............... :=..................... :=... CS553 Ltur Rgistr Allotion I 8

Spilling (Atr spilling ) :=... 1 :=... M[p+4] := 1 :=......... :=......... :=......... :=......... 1 2...... :=............... 2 = M[p+4]... 2... :=... CS553 Ltur Rgistr Allotion I 9 Simpl Gry Algorithm or Rgistr Allotion or h n N o { slt n in rsing orr o wight } i n n olor thn o it { rsrv rgistr or n } ls Rmov n (n its gs) rom grph { llot n to stk (spill) } :=... r1 :=... M[p+4] := r1 :=......... :=... (Atr spilling )...... :=............... r2 = M[p+4]... r2... CS553 Ltur Rgistr Allotion I 10

Exmpl Attmpt to 3-olor this grph (,, ) Wight orr: Wht i you us irnt orr? CS553 Ltur Rgistr Allotion I 11 Exmpl Attmpt to 2-olor this grph (, ) Wight orr: CS553 Ltur Rgistr Allotion I 12

Conpts rom lst wk n toy so r Livnss Us in rgistr llotion Gnrting livnss Flow n irtion Dt-low qutions n nlysis Control low grph trminology Rgistr llotion sop o llotion grnulrity: wht is ing llot to rgistr orr tht llotion units r visit in mttrs in ll huristi lgorithms Glol pproh: gry oloring CS553 Ltur Introution to Dt-low Anlysis 13 Improvmnt #1: Simpliition Phs [Chitin 81] I Nos with < k nighors r gurnt olorl Rmov thm rom th grph irst Rus th gr o th rmining nos Must spill only whn ll rmining nos hv gr k Rrr to s pssimisti spilling CS553 Ltur Rgistr Allotion 14

Simpliying Grph Allotors Chitin Briggs CS553 Ltur Rgistr Allotion 15 Algorithm [Chitin81] whil intrrn grph not mpty o whil no n with < k nighors o Rmov n rom th grph simpliy Push n on stk i ny nos rmin in th grph thn { lok with >= k gs } Pik no n to spill { lowst spill-ost or } spill A n to spill st { highst gr } Rmov n rom th grph i spill st not mpty thn Insrt spill o or ll spill nos { stor tr ; lo or us } Ronstrut intrrn grph & strt ovr whil stk not mpty o Pop no n rom stk olor or slt Allot n to rgistr CS553 Ltur Rgistr Allotion 16

Exmpl Attmpt to 3-olor this grph (,, ) Stk: Possil orr: CS553 Ltur Rgistr Allotion 17 Th Prolm: Worst Cs Assumptions Is th ollowing grph 2-olorl? s1 s4 s2 s3 Clrly 2-olorl But Chitin s lgorithm ls to n immit lok n spill Th lgorithm ssums th worst s, nmly, tht ll nighors will ssign irnt olor CS553 Ltur Rgistr Allotion 18

Improvmnt #2: Optimisti Spilling [Briggs 89] s1 s4 s2 s3 I Som nighors might gt th sm olor Nos with k nighors might olorl Bloking os not imply tht spilling is nssry Push lok nos on stk (rthr thn pl in spill st) Chk olorility upon popping th stk, whn mor inormtion is vill Dr ision CS553 Ltur Rgistr Allotion 19 Algorithm [Briggs t l. 89] whil intrrn grph not mpty o whil no n with < k nighors o Rmov n rom th grph simpliy Push n on stk i ny nos rmin in th grph thn { lok with >= k gs } Pik no n to spill { lowst spill-ost/highst gr } Push n on stk Rmov n rom th grph r ision whil stk not mpty o Pop no n rom stk i n is olorl thn mk ision Allot n to rgistr ls Insrt spill o or n { Stor tr ; lo or us } Ronstrut intrrn grph & strt ovr CS553 Ltur Rgistr Allotion 20

Exmpl Attmpt to 2-olor this grph (, ) Stk: * * * * * lok no Inrsing Wight: CS553 Ltur Rgistr Allotion 21 Improvmnt #3: Colsing Mov instrutions Co gnrtion n prou unnssry mov instrutions mov t1, t2 I w n ssign t1 n t2 to th sm rgistr, w n limint th mov I I t1 n t2 r not onnt in th intrrn grph, ols thm into singl vril Prolm Colsing n inrs th numr o gs n mk grph unolorl Limit olsing ols to voi unolorl grphs t1 t2 t1 t2 CS553 Ltur Rgistr Allotion 22

Colsing Logistis Rul Whn uiling th intrrn grph, o NOT mk virtul rgistrs intrr u to opis. I th virtul rgistrs s1 n s2 o not intrr n thr is opy sttmnt s1 = s2 thn s1 n s2 n ols. Exmpl CS553 Ltur Rgistr Allotion 23 Rgistr Allotion: Spilling I w n t in k-oloring o th intrrn grph Spill vrils (nos) until th grph is olorl Choosing vrils to spill Choos lst rquntly ss vrils Brk tis y hoosing nos with th most onlits in th intrrn grph Ys, ths r huristis! CS553 Ltur Rgistr Allotion 24

Mor on Spilling Chitin s lgorithm rstrts th whol pross on spill Nssry, us spill o (los/stors) uss rgistrs Oky, us it usully only hppns oupl tims Altrntiv Rsrv 2-3 rgistrs or spilling Don t n to strt ovr But hv wr rgistrs to work with CS553 Ltur Rgistr Allotion 25 Wight Intrrn Grph Gol Wight(s) = (r) (r) is xution rquny o r Stti pproximtion Us som rsonl shm to rnk vrils Som possiilitis rrns r o t Wight(t) = num o tims t is us in progrm Wight(t) = 10 (# uss in loops) + (# uss in strightlin o) Wight(t) = 20 (# uss in loops) + 2 (# uss in strightlin o) + (# uss in rnh sttmnt) CS553 Ltur Rgistr Allotion 26

Rgistr Allotion n Prour Clls Prolm Rgistr vlus my hng ross prour lls Th llotor must snsitiv to this Two pprohs Work within wll-in lling onvntion Us intrprourl llotion (not ovring this) CS553 Ltur Rgistr Allotion 27 Clling Convntions Gols Fst lls (pss rgumnts in rgistrs, miniml rgistr sving/rstoring) Lngug-inpnnt Support ugging, proiling, grg olltion, t. Compliting Issus Vrrgs Pssing/rturning ggrgts Exptions, non-lol rturns stjmp()/longjmp() CS553 Ltur Rgistr Allotion 28

Arhittur Rviw: Cllr- n Cll-Sv Rgistrs Prtition rgistrs into two tgoris Cllr-sv Cll-sv Cllr-sv rgistrs Cllr must sv/rstor ths rgistrs whn liv ross ll Cll is r to us thm Exmpl llr oo() { r llr = 4 sv r llr goo() rstor r llr r llr? } goo() { r llr = 99 } ll goo() is r to moiy r llr CS553 Ltur Rgistr Allotion 29 Arhittur Rviw: Cllr- n Cll-Sv Rgistrs Cll-sv rgistrs Cll must sv/rstor ths rgistrs whn it uss thm Cllr xpts ll to not hng thm Exmpl llr oo() { r ll = 4 } goo() r ll? ll goo() { sv r ll r ll = 99 rstor r ll } goo() promiss not to moiy r ll CS553 Ltur Rgistr Allotion 30

Arhitturs with Cll n Cllr Rgistrs SPARC hrwr-sv %i0-%i7, %o0-%o8 Alph 7 ll-sv out o 32 rgistrs MIPS llr-sv: $t0-$t9, $0-$3, $v0-$v1 ll-sv: $s0-$s7, $r, $p PPC 18 ll-sv 14 llr-sv StrCor EABI 4 ll-sv 28 llr-sv CS553 Ltur Rgistr Allotion 31 Rgistr Allotion n Clling Convntions Insnsitiv rgistr llotion Sv ll liv llr-sv rgistrs or ll; rstor tr Sv ll us ll-sv rgistrs t prour ntry; rstor t rturn Suoptiml oo() { t = = t s = () g() = s } Snsitiv rgistr llotion A vril tht is not liv ross lls shoul go in llr-sv rgistrs A vril tht is liv ross multipl lls shoul go in ll-sv rgistrs Eno lling onvntion onstrints in th IR n intrrn grph How? Us prolor nos CS553 Ltur Rgistr Allotion 32

Prolor Nos A rhitturl rgistrs to intrrn grph Prolor (mutully intrring) Not simpliil Not spilll Exprss llotion onstrints Intgrs usully n t stor in loting point rgistrs Som instrutions n only stor rsult in rtin rgistrs Cllr-sv n ll-sv rgistrs... s3 r1 s2 s4 r2 3 s1 loting point intgr loting point intgr CS553 Ltur Rgistr Allotion 33 Prolor Nos n Clling Convntions Cll-sv rgistrs Trt ntry s o ll ll-sv rgistrs Trt xit s us o thm ll Allotor must spill ll-sv rgistrs to us thm (rlly tmp) oo() { (r3) t1 = r3 } r3 = t1 us(r3) Liv rng o ll-sv rgistrs Cllr-sv rgistrs Vrils liv ross ll intrr with ll llr-sv rgistrs CS553 Ltur Rgistr Allotion 34

Exmpl oo(): (r3) t1 := r3 :=... :=......... ll goo...... r3 := t1 us(r3) rturn r3 r1, r2 llr-sv r3 ll-sv r1 r2 t1 CS553 Ltur Rgistr Allotion 35 Tros Cll-sv rgistrs + Drss o siz: on prour oy my hv multipl lls + Smll prours tn to n wr rgistrs thn lrg ons; ll-sv mks sns us prour sizs r shrinking My inrs xution tim: For long-liv vrils, my sv n rstor rgistrs multipl tims, on or h prour ll, inst o singl n-to-n sv/rstor Th lrgr prolm W r mking lol isions or poliis tht rquir glol inormtion CS553 Ltur Rgistr Allotion 36

Conpts Dision tr or rgistr llotion Glol pprohs ntr roun n intrrn grph gry oloring oloring with simpliition [Chitin] oloring with simpliition n optimisti spilling [Briggs] oloring with simpliition, olsing, n optimisti spilling Rgistr llotion ross prour lls prolor nos in th intrrn grph CS553 Ltur Rgistr Allotion 37