Glol Rgistr Allotion Xiokng Qiu Puru Univrsity ECE 468 Slis from Anrw Myrs Sptmr 23, 2016
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
Rgistr llotion For vry no n in CFG, w hv out[n] St of tmporris liv out of n Two vrils intrfr if oth initilly liv (i: funtion rgs), or oth ppr in out[n] for ny n How to ssign rgistrs to vrils?
Intrfrn grph Nos of th grph = vrils Egs onnt vrils tht intrfr with on nothr Nos will ssign olor orrsponing to th rgistr ssign to th vril Two olors n t nxt to on nothr in th grph
Intrfrn grph Instrutions Liv vrs = + 2 = * = + 1 rturn *
Intrfrn grph Instrutions Liv vrs = + 2 = * = + 1 rturn *,
Intrfrn grph Instrutions Liv vrs = + 2 = * = + 1 rturn *,,
Intrfrn grph Instrutions = + 2 = * = + 1 rturn * Liv vrs,,,
Intrfrn grph Instrutions = + 2 = * = + 1 rturn * Liv vrs,,,
Intrfrn grph olor rgistr Instrutions = + 2 = * = + 1 rturn * Liv vrs,,, x x
Intrfrn grph olor rgistr Instrutions = + 2 = * = + 1 rturn * Liv vrs,,, x x
Grph oloring Qustions: 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?
Coloring grph Kmp s lgorithm [1879] for fining K- oloring of grph Assum K=3 Stp 1 (simplify): fin no with t most K-1 gs n ut it out of th grph. (Rmmr this no on stk for ltr stgs.)
Coloring 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
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
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
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk: ll nos hv 2 nighours!
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk:
Coloring olor rgistr x x stk: W got luky!
Coloring olor rgistr x x Som grphs n t olor in K olors: stk:
Coloring olor rgistr x x Som grphs n t olor in K olors: stk:
Coloring olor rgistr x x Som grphs n t olor in K olors: stk:
Coloring olor rgistr x x Som grphs n t olor in K olors: stk: no olors lft for!
Spilling Stp 3 (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 not in n innr loop
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: wht wst! Bttr pproh: rwrit o introuing nw tmporry; rrun livnss nlysis n rgistr llotion Intuition: you wr not l to ssign singl rgistr to th vril tht ws spill ut thr my fr rgistr vill t h spot whr you n to us th vlu of tht vril
Rwriting o Consir: t1 t2 Suppos t2 is slt for spilling n ssign to stk lotion [p-24] Invnt nw tmporry t35 for just this instrution n rwrit: mov t35, [p 24]; t1, t35 Avntg: t35 hs vry short liv rng n is muh lss likly to intrfr. Rrun th lgorithm; fwr vrils will spill
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
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
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
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 ols with if vry nighour t of : lry intrfrs with, or hs low-gr (< K)
Simplify & Cols Stp 1 (simplify): simplify s muh s possil without rmoving nos tht 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: rgistrs involv r mrk not mov-rlt n try stp 1 gin
Ovrll Algorithm Simplify, frz n ols Livnss Mrk possil spills Color & tt tul spills Rwrit o to implmnt tul spills