Rgistr Allotion W now r l to o rgistr llotion on our intrfrn grph. W wnt to l with two typs of onstrints: 1. Two vlus r liv t ovrlpping points (intrfrn grph) 2. A vlu must or must not in prtiulr rhitturl rgistr Rgistr Allotion is ompris of two prts: Rgistr llotion in whih w fin st of virtul rgistrs tht oul pl in th sm physil lotion Rgistr ssignmnt in whih w tully i whih rhitturl rgistr to put st of non-intrfring vlus Rgistr Allotion Rgistr Allotion rus to prolm known s Grph Coloring, whr w try to olor grph without using th sm olor on two nighoring trritoris. If w onsir th st of olors to our rgistrs n our trritoris th virtul rgistrs, it s lrly th prolm w wish to solv. Howvr, it is NP-omplt, whih mns it is (likly) intrtl without numrtion of ll possil omintions. Or t lst, w on t know how to o it othrwis. Th goo nws is tht w n us huristis (inform ruls of gussing) to mk th prolm prtilly solvl in rsonl tim with goo nough nswr. Prinipl Phss Buil Buil th intrfrn grph from th liv rngs of our virtul rgistr st Simplify Us huristi to ttmpt to olor th grph W ll us th huristi tht if our intrfrn grph hs no m of gr (mount of nighors) < K (our rgistr st siz), w n rmov tht no from th grph. If th rsulting grph n K olor, so n th originl grph, sin som olor n foun to olor no m. This rsults in rursiv lgorithm. Eh simplifition stp mks th prolm smllr n sir to solv. Prinipl Phss Spill Unfortuntly, ll of th rmining nos my hv K nighors vn ftr simplifition. Ths nos r of signifint gr Th ision might n to tht w mov n itm to mmory n kp it thr. W ll this spill. Any spill vlu os not intrfr with ny of th nos in th grph, n so it my rmov n th prour ontinus simplifying Slt Assign olors to nos in th grph y strting with n mpty grph n ing nos from our simplify stk. Thr must lwys olor to ssign u to our huristi. W now trmin potntil spills from tul spills. W might luky n gt no tht hs 2 or mor nighors tht r th sm olor, n thus w n olor th no. This is optimisti oloring. Spills Exmpl: Buil If th slt phs is unl to fin olor for potntil spill, it oms n tul spill. Atul spills must stor in mmory. This mns tht w r hnging th progrm o to lo th vlu from mmory into rgistr for w us it. Sin w n rgistr to lo th mmory vlu into, our liv rngs hv hng: W now hv nw rgistrs with tiny liv rngs whih potntilly intrfr with our oloring. W must strt ll ovr with th rwrittn (spills inorport) progrm o. := 0 := mm[] := * 2 := + := := * := + := + 1 Th sh lin inits opy, not n intrfrn. 1
Exmpl: Simplify Exmpl: Simplify Strt with our intrfrn grph, n mpty stk, n K=3 olors. Vril sms worrying sin it is of signifint gr (i.., it hs gr 3). Rmov no with gr < K n push it on th stk. Th rmov no s gs will rs th gr of th rmining nos. Exmpl: Simplify Exmpl: Simplify Exmpl: Simplify Exmpl: Simplify 2
Exmpl: Simplify Exmpl: Slt W foun no potntil spills, so w n skip tht stp n go stright to th slt phs. Strting from n mpty grph, pop off h no n giv it olor. Exmpl: Slt Exmpl: Slt Exmpl: Slt Exmpl: Slt 3
Exmpl: Slt Colsing W n rmov runnt movs if th sour n stintions hv no g twn thm in th intrfrn grph. W n thn simply tll th rgistr llotor to llot oth th sour n stintion into th sm rgistr y olsing oth nos into singl no in th grph. Howvr, sin this no is th union of th two nos ing ols, th possiility xists of prvnting th rsulting grph from ing K-olorl whn th prvious grph ws. Don. W hv 3-olor our intrfrn grph. Consrvtivly, w n o sf olsing lgorithm tht n gurnt w will nvr prou n unolorl grph from olorl on. Briggs Colsing Gorg Colsing Nos n n ols if th rsulting no,, will hv fwr thn K nos of signifint gr. This works us simplify rmov ll nos of insignifint gr. This mns tht will only jnt to th nos of signifint gr. If thr r lss thn K nighors of signifint gr, thn simplify n rmov this no n oloring n pro. Nos n n ols if, for vry nighor t of, ithr: t lry intrfrs with, or t is of insignifint gr Proof: Lt S th st of nighors of with insignifint gr. If olsing is not on, Simplify n rmov ll of S, lving grph G 1 If olsing is on, Simplify n still rmov ll of S, lving grph G 2 G 2 is sugrph of G 1 sin no orrspons to th no in G 1. Thus, G 2 must s sy to olor s G 1. Colsing Rgistr Coloring Algorithm Ths r sf, ut onsrvtiv olsing shms, so thy my miss opportunitis to ols movs. Strt Buil Howvr, n xtr mov is lss ostly thn ny itionl spills. A Cols phs will to our lgorithm from for, n our Simply routin will intrlv with it: w simplify n ols until our grph is mpty. This will limint most mov instrutions ut still olorl. Ro with rwrittn progrm Simplify Cols Frz Potntil Spill Slt Atul Spill Don 4
RgAllo with Colsing Buil Buil th intrfrn grph Clssify h no s mov-rlt or not Mov-rlt mns tht it is th stintion or sour of mov Simplify Rmov h non-mov rlt no of low gr (<K) on t tim Cols Prform on of th onsrvtiv lgorithms w hv shown on th rsulting simplifi grph Elimint th ssoit mov instrution If th rsulting no is no longr mov-rlt, it n simplifi in th nxt roun Simplify n Cols r rpt until only signifint-gr or mov-rlt nos rmin. RgAllo with Colsing Frz If w nnot simplify or ols, w look for mov-rlt no of low gr Wfrz suh no, tht is, w giv up trying to ols it Mrk it s non-mov-rlt n go k to oing Simplify n Cols Spill If w n t simplify, ols, or frz n only signifint gr nos rmin, slt signifint gr no to potntilly spill Push it on th stk Slt Pop h lmnt off th stk n ssign it olor Exmpl: Buil Exmpl: Simplify := 0 := mm[] := * 2 := + := := * := + := + 1 Thr r two mov-rlt nos, n. W will simplify only thos nos tht r of non-signifint gr n non-mov-rlt. For K=3, tht s only. Exmpl: Simplify Exmpl: Cols W will simplify only thos nos tht r of non-signifint gr n non-mov-rlt. n only hv two nighors of signifint gr n so thy my sfly ols. For K=3, tht s only. 5
Exmpl: Cols Exmpl: Cols n only hv two nighors of signifint gr n so thy my sfly ols. W rmov th mov instrution n mrk s non-mov-rlt. n only hv two nighors of signifint gr n so thy my sfly ols. W rmov th mov instrution n mrk s non-mov-rlt. Exmpl: Simplify Exmpl: Simplify W now hv nos tht hv non-signifint gr tht w n simplify. Exmpl: Simplify Exmpl: Simplify With n mpty grph, w hv no n for th Frz or Spill stps. W now ruil th grph ssigning olors s w go. 6
Exmpl: Slt Exmpl: Slt Exmpl: Slt Exmpl: Slt Exmpl: Rsult Constrin Movs := 0 := mm[] := * 2 := + := * := + := + 1 Somtims thr my multipl hois for olsing movs. For instn, w my hv thr vrils,,, n n two movs: := := If (, ) is n g in our intrfrn grph, olsing n into rsults in: := With th olsing of n, w hv rwrittn th o to rmov th mov n n will oth ssign to th sm rgistr. Whih hs n intrfrn g twn thm. This mov is onstrin n nnot ols. W trt it s non-mov-rlt n is no longr onsir for olsing. 7
Spilling Whn w hv to spill, Buil n Simplify must rrun on th progrm. With olsing, w throw wy work tht osn t inrs th numr of spills. A ttr lgorithm n kp ll olss on for th first potntil spill ws isovr. Howvr, vn mor n on. If w hv vry onstrin mhin, suh s x86 with its 6 gnrl purpos rgistrs, w my n up spilling mny tmporris into th stk frm. Movs of spill vlus involv loing th sour into rgistr, rting nw liv rng n furthr onstrining th rsults. Spill Colsing W n tully o grph oloring on th spill lotions us thy my not liv ithr. It s tully sir to o us w r not onstrin y th numr of tivtion ror lotions, so w n ols ggrssivly. Th lgorithm is: 1. Construt intrfrn for spill nos 2. Cols ll non-intrfring spill nos onnt vi mov 3. Us Simplify n Slt to olor th grph. Thr is no limit on th numr of olors, so Simplify n pik th lowst gr no n Slt n pik th first vill olor 4. Us th olors to ssign stk lotions to th spills Do this for gnrting spill instrutions to voi unnssry lo/stors for ols movs of spills. Proloring Somtims w hv onstrints on th mhin rgistrs tht hol spifi vlus. For instn, th stk pointr, th frm pointr, th rgumnt rgistrs, t. W n ssign ths rgistrs olor for w run our lgorithm so tht w n in vlu to tht rgistr. This is ll proloring n thr must t most on prolor no of givn olor. Slt n Cols n ssign nos th sm olor s prolor nos s long s thy o not intrfr. For instn, $3 in MIPS oul us to hol tmporry in funtion tht os not tk 4 prmtrs. Prolor Nos Th lgorithm now lls Simplify, Cols, n Spill until only th prolor nos rmin. Thn Slt will th othr nos k in whil oloring thm. Prolor nos o not spill n thus thir liv rngs shoul kpt short. This n on y gnrting movs for vlus into n out of prolor nos. Only if thr is onsirl rgistr prssur high mn for rgistrs will th mov rmin ftr olsing. Whn w hv K rgistrs, w n K prolor nos tht ll intrfr with h othr, n thus nnot ols. Thy shoul not spill, sin thy r, y finition, rgistrs. Thy lso nnot simplifi, w must trt thm s hving infinit gr. Cllr- n Cll-sv Rgistrs Th onstrints of llr-sv n ll-sv rgistrs n nfor y ugmnting th ll instrutions of our IR. A ll instrution n nnott to intrfr with ll of th llr-sv rgistrs. If vril is not liv ross th prour ll, it will most likly llot to llr-sv rgistr. If vril is liv ross ll, it must thn intrfr with ll of th llr-sv rgistrs n it will intrfr with th tmporris rt for ll-sv rgistrs. This will rsult in spill, sving th vlu to mmory. W n stimt spill ost to trmin whih vlu is st put in mmory. A si huristi woul spill no with high gr in th intrfrn grph ut fw uss. 8