Rgistr Allotion
Rgistr Allotion How to ssign vrils to initly mny rgistrs? Wht to o whn it n t on? How to o so iintly? Mony, Jun 3, 13
Mmory Wll Disprity twn CPU sp n mmory ss sp improvmnt Mony, Jun 3, 13
Mony, Jun 3, 13
Th Mmory Hirrhy I: Try to gt th st o ll worls y using multipl typs o mmory. Rgistrs L1 Ch L2 Ch Min Mmory Hr Disk Ntwork 256B - 8KB 16KB 64KB 1MB - 4MB 4GB 256GB 500GB+ HUGE 0.25 1ns 1ns 5ns 5ns 25ns 25ns 100ns 3 10ms 10 2000ms
On hllng o o gnrtion Almost ll progrmming lngugs xpos ors viw o th mmory hirrhy: All vrils liv in mmory. Disk n ntwork xpliitly hnl sprtly. Chllngs in o gnrtion: Position ojts in wy tht tks mximum vntg o th mmory hirrhy. Do so utomtilly Mony, Jun 3, 13
Rgistrs Most mhins hv st o rgistrs, it mmory lotions tht n ss quikly, n hv omputtions prorm on thm, n xist in smll quntity. Using rgistrs intlligntly is ritil stp in ny ompilr. A goo rgistr llotor n gnrt o orrs o mgnitu ttr thn rgistr llotor.
Rgistr Allotion In TAC, thr r n unlimit numr o vrils. On physil mhin thr r smll numr o rgistrs: x86 hs our gnrl-purpos rgistrs n numr o spiliz rgistrs. MIPS hs twnty-our gnrl-purpos rgistrs n ight spil-purpos rgistrs. Rgistr llotion is th pross o ssigning vrils to rgistrs n mnging t trnsr in n out o rgistrs.
Rgistr Allotion Diing whih vlus to stor in limit numr o rgistrs Rgistr llotion hs irt impt on prormn Ats lmost vry sttmnt o th progrm Elimints xpnsiv mmory instrutions # o instrutions gos own u to irt mnipultion o rgistrs Limit mm-to-mm ALU ops, my n two instrutions Proly is th optimiztion with th most impt! Smn Amrsingh & Armno Solr-Lzm 4 6.035 MIT
Chllngs in Rgistr Allotion Rgistrs r sr. Otn sustntilly mor IR vrils thn rgistrs. N to in wy to rus rgistrs whnvr possil. Rgistrs r omplit. x86: Eh rgistr m o svrl smllr rgistrs; n't us rgistr n its onstitunt rgistrs t th sm tim. x86: Crtin instrutions must stor thir rsults in spii rgistrs; n't stor vlus thr i you wnt to us thos instrutions. MIPS: Som rgistrs rsrv or th ssmlr or oprting systm. Most rhitturs: Som rgistrs must prsrv ross untion lls.
Builing Bttr Allotor Gol: Try to hol s mny vrils in rgistrs s possil. Rus mmory rs/writs. Rus totl mmory usg. W will n to rss ths qustions: Whih rgistrs o w put vrils in? Wht o w o whn w run out o rgistrs?
Liv Rngs n Liv Intrvls Rll: A vril is liv t prtiulr progrm point i its vlu my r ltr or it is writtn. Cn in this using glol livnss nlysis. Th liv rng or vril is th st o progrm points t whih tht vril is liv. Th liv intrvl or vril is th smllst surng o th IR o ontining ll vril's liv rngs. A proprty o th IR o, not th CFG. Lss pris thn liv rngs, ut simplr to work with.
Liv Rngs n Liv Intrvls
Liv Rngs n Liv Intrvls = + = + = + IZ Goto _L0 = + Goto _L1; _L0: = - _L1: g =
Liv Rngs n Liv Intrvls = + = + = + = + = + IZ Goto _L0 = + Goto _L1; = + _L0: = - _L1: g = = + = g =
Liv Rngs n Liv Intrvls = + = + = + IZ Goto _L0 = + Goto _L1; _L0: {,,, } = + {,, } {,, } = + {,, } {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + = + = + IZ Goto _L0 = + Goto _L1; _L0: {,,, } = + {,, } {,, } = + {,, } {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + = + = + IZ Goto _L0 = + Goto _L1; _L0: {,,, } = + {,, } {,, } = + {,, } {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + {,,, } = + {,, } = + = + IZ Goto _L0 {,, } = + {,, } = + Goto _L1; _L0: {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + {,,, } = + {,, } = + = + IZ Goto _L0 {,, } = + {,, } = + Goto _L1; _L0: {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + {,,, } = + {,, } = + = + IZ Goto _L0 {,, } = + {,, } = + Goto _L1; _L0: {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + {,,, } = + {,, } = + = + IZ Goto _L0 {,, } = + {,, } = + Goto _L1; _L0: {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + {,,, } = + {,, } = + = + IZ Goto _L0 {,, } = + {,, } = + Goto _L1; _L0: {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Liv Rngs n Liv Intrvls = + g {,,, } = + {,, } = + = + IZ Goto _L0 {,, } = + {,, } = + Goto _L1; _L0: {,, } = + {, } _L1: = - g = {, } = + { } {, } = { } { } g = { g }
Rgistr Allotion with Liv Intrvls Givn th liv intrvls or ll th vrils in th progrm, w n llot rgistrs using simpl gry lgorithm. g I: Trk whih rgistrs r r t h point. Whn liv intrvl gins, giv tht vril r rgistr. Whn liv intrvl ns, th rgistr is on gin r. W n't lwys it vrything into rgistr; w'll s wht o to in minut.
Rgistr Allotion with Liv Intrvls g
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 23
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 23
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 23
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 23
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 23
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 32
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 0 R 1 R 2 R 32
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 32
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 0 R 1 R 2 R 32
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 0 R 1 R 2 R 32
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 0 R 1 R 2 R 23
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 0 R 1 R 2 R 23
Rgistr Allotion with Liv Intrvls g Fr Rgistrs R 0 R 1 R 2 R 23
Anothr Exmpl
Anothr Exmpl g
Anothr Exmpl g Fr Rgistrs
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2 Wht o w o now?
Rgistr Spilling I rgistr nnot oun or vril v, w my n to spill vril. Whn vril is spill, it is stor in mmory rthr thn rgistr. Whn w n rgistr or th spill vril: Evit som xisting rgistr to mmory. Lo th vril into th rgistr. Whn on, writ th rgistr k to mmory n rlo th rgistr with its originl vlu. Spilling is slow, ut somtims nssry.
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2 Wht o w o now?
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Anothr Exmpl g Fr Rgistrs R 0 R 1 R 2
Linr Sn Rgistr Allotion This lgorithm is ll linr sn rgistr llotion n is omprtivly nw lgorithm. Avntgs: Vry iint (tr omputing liv intrvls, runs in linr tim) Prous goo o in mny instns. Allotion stp works in on pss; n gnrt o uring itrtion. Otn us in JIT ompilrs lik Jv HotSpot. Disvntgs: Impris u to us o liv intrvls rthr thn liv rngs. Othr thniqus known to suprior in mny ss.
An Entirly Dirnt Approh
An Entirly Dirnt Approh {,,, } = + {,, } {,, } = + {,, } {,, } = + {, } {, } = + { } {, } = { } { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } {,, } = + {,, } {, } = + { } {,, } = + {, } {, } = { } Wht n w inr rom ll ths vrils ing liv t this point? { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } {,, } = + {,, } {,, } = + {, } {, } = + { } {, } = { } { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } {,, } = + {,, } {, } = + { } {,, } = + {, } {, } = { } g { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } {,, } = + {,, } {, } = + { } {,, } = + {, } {, } = { } g { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } {,, } = + {,, } {, } = + { } {,, } = + {, } {, } = { } g { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } {,, } = + {,, } {, } = + { } {,, } = + {, } {, } = { } g { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } Rgistrs R 3 {,, } = + {,, } {, } = + { } {,, } = + {, } {, } = { } g { } g = { g }
An Entirly Dirnt Approh {,,, } = + {,, } Rgistrs R 3 {,, } = + {,, } {, } = + { } {,, } = + {, } {, } = { } g { } g = { g }
Th Rgistr Intrrn Grph Th rgistr intrrn grph (RIG) o ontrol-low grph is n unirt grph whr Eh no is vril. Thr is n g twn two vrils tht r liv t th sm progrm point. Prorm rgistr llotion y ssigning h vril irnt rgistr rom ll o its nighors. Thr's just on th...
Th On Cth This prolm is quivlnt to grpholoring, whih is NP-hr i thr r t lst thr rgistrs. No goo polynomil-tim lgorithms (or vn goo pproximtions!) r known or this prolm. W hv to ontnt with huristi tht is goo nough or RIGs tht ris in prti.
Th On Cth to Th On Cth
Th On Cth to Th On Cth I you n igur out wy to ssign rgistrs to ritrry RIGs, you'v just provn P = NP n will gt $1,000,000 hk rom th Cly Mthmtis Institut.
Th On Cth to Th On Cth I you n igur out wy to ssign rgistrs to ritrry RIGs, you'v just provn P = NP n will gt $1,000,000 hk rom th Cly Mthmtis Institut.
Bttling NP-Hrnss
Chitin's Algorithm Intuition: Suppos w r trying to k-olor grph n in no with wr thn k gs. I w lt this no rom th grph n olor wht rmins, w n in olor or this no i w it k in. Rson: With wr thn k nighors, som olor must lt ovr. Algorithm: Fin no with wr thn k outgoing gs. Rmov it rom th grph. Rursivly olor th rst o th grph. A th no k in. Assign it vli olor.
Chitin's Algorithm
Chitin's Algorithm g
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g g Rgistrs R 3
Chitin's Algorithm g g Rgistrs R 3
Chitin's Algorithm g g Rgistrs R 3
Chitin's Algorithm g g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
Chitin's Algorithm g Rgistrs R 3
On Prolm Wht i w n't in no with wr thn k nighors? Choos n rmov n ritrry no, mrking it troulsom. Us huristis to hoos whih on. Whn ing no k in, it my possil to in vli olor. Othrwis, w hv to spill tht no.
Chitin's Algorithm Rlo g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo g g Rgistrs
Chitin's Algorithm Rlo (spill) g g Rgistrs
Chitin's Algorithm Rlo (spill) g g Rgistrs
Chitin's Algorithm Rlo (spill) g g Rgistrs
Chitin's Algorithm Rlo (spill) g g Rgistrs
Chitin's Algorithm Rlo (spill) g g Rgistrs
Chitin's Algorithm Rlo (spill) g Rgistrs
Chitin's Algorithm Rlo (spill) g Rgistrs
Anothr Exmpl
Anothr Exmpl
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl Rgistrs
Anothr Exmpl (spill) Rgistrs
Anothr Exmpl (spill) Rgistrs
Anothr Exmpl (spill) (spill) Rgistrs
Chitin's Algorithm Avntgs: For mny ontrol-low grphs, ins n xllnt ssignmnt o vrils to rgistrs. Whn istinguishing vrils y us, prous pris RIG. Otn us in proution ompilrs lik GCC. Disvntgs: Cor pproh s on th NP-hr grph oloring prolm. Huristi my prou pthologilly worst-s ssignmnts.
Improvmnts to th Algorithm Choos wht to spill intlligntly. Us huristis (lst-ommonly us, grtst improvmnt, t.) to trmin wht to spill. Hnl spilling intlligntly. Whn spilling vril, romput th RIG s on th spill n us nw oloring to in rgistr.
Summry o Rgistr Allotion Critil stp in ll optimizing ompilrs. Th linr sn lgorithm uss liv intrvls to grily ssign vrils to rgistrs. Otn us in JIT ompilrs u to iiny. Chitin's lgorithm uss th rgistr intrrn grph (s on liv rngs) n grph oloring to ssign rgistrs. Th sis or th thniqu us in GCC.