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