Entertainment & Humor

11/11/2010. b = a + 2. c = b * b. return b * a

Description
Rgistr Allotion CS SJAlln Rgistr Allotion 1 Introution Rgistr ss is fstr thn mmory ss Rgistrs r sr rsour Assign spifi vlus to rtin rgistrs Bs rgistrs Stk pointr Currnt frm pointr Glol t pointr CS
Published
of 27
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
Rgistr Allotion CS SJAlln Rgistr Allotion 1 Introution Rgistr ss is fstr thn mmory ss Rgistrs r sr rsour Assign spifi vlus to rtin rgistrs Bs rgistrs Stk pointr Currnt frm pointr Glol t pointr CS SJAlln Rgistr Allotion 2 1 Glol Rgistr Allotion Kp vlus tht r frquntly us in rgistrs, vn ross si lok ounris Kp loop vlus (spilly innr loops) in rgistrs, if possil Avntg simpl to implmnt CS SJAlln Rgistr Allotion 3 Usg Counts Dvis mtho to lult th svings for kping vlu in rgistr A formul might us x, B) loks B in L ( 2 liv x, B Whr us(x,b) is th numr of tims x is us in B prior to ny finition of x, liv(x,b) is 1 if X is liv on xit from B n is ssign vlu in B,, n is 0 othrwis CS SJAlln Rgistr Allotion 4 2 Min I Wnt to rpl tmporry vrils with som fix st of rgistrs First: n to know whih vrils r liv ftr h instrution Two simultnously liv vrils nnot llot to th sm rgistr 5 Rgistr Allotion For vry no n in CFG, w hv out[n] St of tmporris liv out of n Two vrils intrfr if: Both r initilly liv (i.., funtion rgs), or Both ppr in out[n] for ny n, or On is fin n th othr is in out[n] x = - whr x is & is liv intrfr How to ssign rgistrs to vrils? 6 3 Intrfrn Grph Nos of th grph r vrils Egs onnt vrils tht intrfr with on nothr Nos r ssign olor This orrspons to th rgistr ssign to th vril Nos with th sm olor n t jnt in th grph 7 Intrfrn Grph Instrutions Liv vrs = + 2 = * = + 1 rturn * 8 4 Intrfrn Grph Instrutions Liv vrs = + 2 = * = + 1 rturn *, 9 Intrfrn Grph Instrutions Liv vrs = + 2 = * = + 1 rturn *,, 10 5 Intrfrn Grph Instrutions = + 2 = * = + 1 rturn * Liv vrs,,, 11 Intrfrn Grph Instrutions = + 2 = * = + 1 rturn * Liv Vrils,,, 12 6 Intrfrn Grph olor rgistr Instrutions = + 2 = * = + 1 rturn * Liv vrs,,, x x 13 Intrfrn Grph olor rgistr Instrutions = + 2 = * = + 1 rturn * Liv vrs,,, x x 14 7 Rfrns for Grph Chitin, G. J., t.l. Rgistr Allotion Vi. Computr Lngugs 6(1981):47-57 Chiting, G. J. Rgistr Allotion n Spilling Vi Grph. ACM SIGPLAN Notis 17(6): (Jun 1982) CS SJAlln Rgistr Allotion 15 Qustions: Grph Cn w ffiintly fin oloring of th grph whnvr possil? Cn w ffiintly fin th optimum oloring of th grph? How o w hoos rgistrs to voi mov instrutions? Wht o w o whn thr rn t nough olors (rgistrs) to olor th grph? 16 8 Grph Kmp s lgorithm [1879] for fining K- oloring of grph Stp 1 (simplify): Fin no with t most K-1 gs n ut it out of th grph Sv this no on stk for ltr stgs On oloring is foun for th simplr grph, w n lwys olor th no w sv 17 grph On oloring is foun for th simplr grph, w n lwys olor th no w sv on th stk Stp 2 (olor): Whn th simplifi sugrph hs n olor, k th no on th top of th stk n ssign it olor not tkn y on of th jnt nos In th xmpl tht follows, K=2 18 9 olor rgistr x x stk: 19 olor rgistr x x stk: 20 10 olor rgistr x x stk: 21 olor rgistr x x stk: 22 11 olor rgistr x x stk: 23 olor rgistr x x stk: 24 12 olor rgistr x x stk: 25 olor rgistr x x stk: 26 13 olor rgistr x x stk: 27 olor rgistr x x stk: 28 14 olor rgistr x x stk: 29 Filur If th grph nnot olor, it will vntully simplifi to grph in whih vry no hs t lst K nighors Somtims, th grph is still K-olorl! Fining K-oloring in ll situtions is n NP-omplt prolm W will hv to pproximt to mk rgistr llotors fst nough 30 15 olor rgistr x x stk: 31 olor rgistr x x stk: ll nos hv 2 nighours! 32 16 olor rgistr x x stk: 33 olor rgistr x x stk: 34 17 olor rgistr x x stk: 35 olor rgistr x x stk: 36 18 olor rgistr x x stk: 37 olor rgistr x x stk: 38 19 olor rgistr x x stk: W got luky! 39 olor rgistr x x Som grphs n t olor in K olors: stk: 40 20 olor rgistr x x Som grphs n t olor in K olors: stk: 41 olor rgistr x x Som grphs n t olor in K olors: stk: 42 21 olor rgistr x x Som grphs n t olor in K olors: stk: no olors lft for! 43 Stp 3 (spilling): Spilling On ll nos hv K or mor nighors, pik no for spilling Storg on th stk Thr r mny huristis tht n us to pik no No not in n innr loop 44 22 Spilling o W n to gnrt xtr instrutions to lo vrils from stk n stor thm Ths instrutions us rgistrs thmslvs Wht to o? Stupi pproh: lwys kp xtr rgistrs hny for shuffling t in n out: A wst! Bttr pproh:? 45 Spilling o W n to gnrt xtr instrutions to lo vrils from stk n stor thm Ths instrutions us rgistrs thmslvs. Wht to o? Stupi pproh: Alwys kp xtr rgistrs hny for shuffling t in n out: wht wst! Bttr pproh: Rwrit o introuing nw tmporry; rrun livnss nlysis n rgistr llotion 46 23 Consir: t1 t2 Rwriting o Suppos t2 is slt for spilling n ssign to stk lotion [SP-24] Crts nw tmporry t35 for just this instrution n rwrit: mov t35, [SP 24]; t1, t35 Avntg: t35 hs vry short liv rng n is muh lss likly to intrfr Rrun th lgorithm; fwr vrils will spill 47 Prolor Nos Som vrils r pr-ssign to rgistrs Eg: mul on x86/pntium uss x; fins x, x Eg: ll on x86/pntium Dfins (trshs) llr-sv rgistrs x, x, x Trt ths rgistrs s spil tmporris; for ginning, thm to th grph with thir olors 48 24 Prolor Nos Cn t simplify grph y rmoving prolor no Prolor nos r th strting point of th oloring pross On simplifi own to olor nos strt ing k th othr nos s for 49 Optimizing Movs Co gnrtion prous lot of xtr mov instrutions mov t1, t2 If w n ssign t1 n t2 to th sm rgistr, w o not hv to xut th mov I: if t1 n t2 r not onnt in th intrfrn grph, w ols into singl vril 50 25 Colsing Prolm: olsing n inrs th numr of intrfrn gs n mk grph unolorl ols t1 t2 t1/t2 Solution 1 (Briggs): voi rtion of high-gr ( = K) nos Solution 2 (Gorg): n n ols if vry nighor t of : lry intrfrs with, or hs low-gr ( K) 51 Simplify & Cols Stp 1 (simplify): simplify s muh s possil without t rmoving nos tht t r th sour or stintion of mov (mov-rlt nos) Stp 2 (ols): ols mov-rlt nos provi low-gr no rsults Stp 3 (frz): if nithr stps 1 or 2 pply, frz mov instrution: ti rgistrs involv r mrk not mov-rlt n try stp 1 gin 52 26 Ovrll Algorithm Simplify, frz n ols Livnss Mrk possil spills Color & tt tul spills Rwrit o to implmnt tul spills 53 Summry Rgistr llotion hs thr mjor prts Livnss nlysis Grph oloring Progrm trnsformtion (mov olsing n spilling) Stuy hptr in Appl Assignmnts this wk: livnss nlysis + intrfrn grph onstrution nxt wk: grph oloring + rgistr llotion 54 27
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks