0% found this document useful (0 votes)
59 views34 pages

Compiler Design - Unit 5

Uploaded by

White chillies
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
59 views34 pages

Compiler Design - Unit 5

Uploaded by

White chillies
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 34
Lo COMPILER DESIGN Code Ophimizations- brnit-5 We quality a a ebyect Program bs gevelly meoourea) by ats Alge or LB unnirg time, I -for Longe computection , sunning “He 24 part cularly imporbrt cfoy emai computation size is move \mbortent - // Code obtimraston ved on to techmquss a ambi ae employ in On atlembt to produce a beter object } language program than -the mast obvious for a given BOUT program - the Criferia or She aclection 4 offen iain rans feretin — ® Doo he olhimigection cabture most e she, golential ‘mbrovernan} coitheut an untearonabh, amount 2 alert ? QB Dow opr apkimisgtion pronewe. —the wean of the Avura pregorn 4 6 bea pkirsgption aodua +h dime and Zpaca 0 foken by dhe ebjecl praghaen. A ‘ \ st) ed Coda. obhimigetion Jeckmqan an gnrally after ayntox avalysis , usvolllyy los bhov e and dui todle gerwertion. \B/) Constraints for obi migatton s— @ mol ervure shat -the Fars ter meal procram J Zemontically equivalent +o “He ccatint Fosioae. QO ™ improverrant- aj Presa edbicrency must be achieved verthoud changing, tha alspaithrs wohich one wad wn he Progam, foe fT ages dine ee Gade] trae! program cole ebtimirzer | tod ee aa Cotagery = t Socol optimization 2 Global optimization t (sh) Aocol. optimisation :— C pasbhole oft mization) “he foage! cocle gensrad ecl Astelmont by swtobemend Gerwelly cortains redhecbnt jnshvctions« we Can improve, He quality — such code ‘4 aud optimgations Aocalls examining a shor} vend el code inshuchons an replacing tem desler ox chorley seat re acing by Anis Jechhique We known as hole © Himizat on Gohera He perbhole is a emall wie ‘eitloe en tha program | “Tie foophola ip a small, slicling usindl gus e& on @ prosam. The tec, in Je posphole reel net bo cong uous although ABnt implawerdedrens do poquire Ans ' Mt fs chonacknrt'c, ft peebhole obtimigedion ~\nert O° ‘Vmbrovermant ray, create ofporgtan che. Por add i-torod, (prove mand ’ channckenishic,

Relat T, fate = DAG Conshuchon > Gwshuction qf DAG -for a. basic bleek (sax follows © Trane ts @ node jn the BAG tor each of “the iniiad val. of tu vernabh appearing, wn Va basic block @ The is a pode NM axociated loith each steclmont- & wriin +ho block jhe childwen o N ae those nocles ‘ Cows ponchi fo atebmonts thot ano tho ox ddfinitions, Wor do a, ef the oferanols wycol by A. (2 Nece N is obelrel by Hr operertor appliool af 2 are| *adho crtnched -fo N ae Aik 4 vanables er tsbu'ch Gk ws the Lost chfinition toithin the block | Prey sehesences— | @ wo oxsignmrent gon an arerony [x= atid | Is veprenurl eg by creacivg % node UW orate Hy and too childyen rofrarertting ta wnibal value of ona {eo ) anal index > Venable x becomes the Aotoek co He's ® an conign mart to an avey [afr] -yJ% vopronented bey at naw ned woth opmats []= ancl three chilolren “epronetg , J ana y. Shyu th no aaxiobh Aabelivg Yer's dion > the — creston gf 4A nok Kilp olt currently constivcteal node who value dsbanca, OW Q, AGW py vrede Greco oor killeol can nok reCerve any more Sabels ’ rent GA - x= att] atji=¥ ze aft) Tiree oddios cocle qos Tlocls & &B> ® A407 » Ae addr (A) -4 9 t= #14 DAG y tye & 4h o jm odo [8] —4+ 9 t= Asta] 49; D teats ¥te 8) Ag = PRod+ 4p 2 fee ars > “OT = tq D ig T sro gle 8 ex— 2 Sum ied » L=O * Sum = Sum +9 i . Lately whuk ( lo t , ) 2 Adol ress Stetmant : (arrume 4 byte/ bord) ') Sum =0 2) t-0 ‘ her ati) ffm 1" saggte aalyos bill inca 9 4 = alt) . » » La 5) Sumge = Sumstr De ee e §) sa, i) da abel 2) Ae a4! ' yi ® if t c= losers . yp vel ) ky ets ee = Addy Cal ~ + By - xt4) e AL = alt) Sum = Sam4tan . Le= 441 y L cele Sobel) boat’ , a) ~Zyulelt: | 1 oi = consid, the cod fegmanh , Compute, He dot produc af seas vector A 4 Bq Jonth 20. Code Frogment 4 ba PRop t= 0 Viet do mn * PROD i= PROD + ALTIY B12) p= 2+) % ensl lolly BP $20 Biddiess Ahohrunty [ A byhe [mor t PRop =o a? =a rot = oe ei ® = Paddy (A) - 4 ‘s% - TIT) G Ta = Adar (G)- + tT = thi) ’ 9 Te = 72 ¥ Ts a PROD = PRD + Ts leo D =D+\ y ig 2 E26 soto (%) mL heat” exampl-}) Condtinurs T= 4#T Tr = Addr CA) - 4 % =-b(T) Ty = Adolr CB) + % = T4lh)J Tg = Ta¥ Ts Fro = PROP+ Te Q=PR+l dp 620 seto(@ J Plow , mph ofr Code rnotion : B T= AddyCa) - 4 Ta 2 nT Tg = Tal TJ Ty = BY TS = PROD* Te rey By @ _ PROD DAG. 7 re _ el) Ts it AY +) “T Dy odl(n) aololy(t) NZ) Dp pag. o 2% | 2) Plots graph of tex ebirinarhiog induchsa variable [prop =o] B, Ty '= Addy (A) - 4 Ba Ty t= hdd (8) - 4 TET, induchon ® verily ae ca beth daberct FR oon enchotnr T= 144 t% = PCT Ts = HL B. Gl = PRD ATE Ped = Te f Wo F446 sots Bo Vy. ace fox (i= 0; tele: let) sum =Sum + ay) 7 i Sums = a Wl=d ) ta> Alt) Adit 1 Lo Sobol bs) Sdyn = Sum + 3 4) goto (I) 1) get tO oy vs tl tes Fi 6) gob ® ry x oleh ie (18) Ay Ladolk (AY Ay ~ 4 (4) Sum ao Sam ts exampli- . Wate down “He & Addves ackedrwet -pe te Koliovowg brogram degrent, whe A,B ove away of size 20X20, anel tere are 4 byte { voove begin add + 0, ie ey do omy agin add = odd + ACI ¥ BCI) > Le LPL fre: fai eng Fee tere eb Ee! 1) odd = 0 iS) nA > odd + A), 2» L=l By 3) yl WwW aol da DY 4, = L¥20 ) Ai 9 Att ~) se43. 6) as z4Ar¥ 4 19) Aya? ut) 1) tg = Ady CA) - 34 oe) date 2!) 4 (0 0) gots 2% ) As 2 #4 bts] 8 Se) Y dy ~ $20 7 Mean goto i) ty’ = xetd a me. wee \) #8 = +, ys as am ) Aq = Adel (BD ~ 84 Leadsy- 1, 8 i) Ap - Alte) ) Av = Ae ¥ Ae (715) be J= ————_ tL =f 4) ty =p Ve ka = Aeble (8-84) ts = 44L42] te = Je 20 de = Fett to aay 4 ta = Aclolr( > — 84 typ = Aalto) dn =, As % Ap tn > Ade +4y Addl = ti Ais = E+! L~- 4 Aya = dH a4 , 4 4 Jor sot C4) @ (5/8) 8, Bs baa’ ‘or AD oway— ah consicl ADanray 0 Af2JL3] Jov “boxe adds t8 Crow major oveler) ~ adden of ALTILL] = bore +n (a= low) ) + (j- lew) coc given exarn ‘Ne ‘ i index don to bee ACI EA] = bore +Qn¢d-4i-) ¥ = bat (as) (nd HI) by “A tates) = Ueno bow =a | We + Jd . ’ ACL] = aarAerely+ = A oe - HD 43444 2(a- a4 Sit thus addres tod, tor mx 2 loxley W=P Yn) w= sg dz po gel | go? \ Ay = OK 5 d= fort dre Arty : Aue ai fae 8 Hy tae aed 4 ag = #2 -(88) tae o 0 , Mit e% atte | de> Azelts) (s/e Reg Nsidoy the Code dragon Ce wrtnel an idertrly matrix of rel ebrwnt take 9 | element - ancl vetting A Atpreal “Iy row rmaror oroley - Code tegen ¢- . dor L gm Jo lo do gor j tom | fo'lo obo ory loxlo, sur aChjlyJ =°; S feet from 1 lo do | alrifi}e ly, 2% fddror SBtectrunt o. N) c=) 2) jal 2) f= bowl 2 Ae Atl 4 da = vt %) Aq = £5.80 oP F) alta =o 8) j-d4 ® if bee 9 ater ae 0 Pas {dere goto 13) a5 = fel bt W) A= 99 ¥te ID aftsa=l \6) d= At BS Dif Lear gor uw “ PS | aft, -1 uals it TEEN, gototh — “OPH mizing ranadormation 3. { "tS & Gmmon Sub exp- eliminahon- r= Gals => aed we won “seat “he econ dm dey pvt fom nb wde if rene te Pacem tty ae gadis beh crerged Ths % Compile Hme evaluation » Can inprove the execution affeciency ct a program by ahiltig execstion ime achons to compile Tin - exe Folding ee) Ke a¥ (228/78) Wy Be Can perform he combrtion Combily in - : 2 Cretan peo Bagihiine a verte is aatisnasl a constant value “and tied in an exp” without my aaignnad other valug ih. we con ovalmote i da exp: sig Ye Constant parr . oe bev 4 *b » of 24 (220 | gaa) al & are i > ye ¥[2d we may cal evabaste x[23 a 12 4] 2.3 ok ombile Aime, Y Peas Code odivainaction: RY: ceavb oy Dead Code ohiminatont . > Nrenmalole prabagatiaa - ewx- 62 avb 2 a¥b Yea x=a : 2 a =x ote de arbte it a venabl is assignel ‘to ancthiy variable , we ere ue ore in place of oft. i dhe valun contained ino Veajahle at Yat point ts not red ENyowre in Ye rogram pubsegquontly 1 then tate yecrablh ik said to be ot het > place - af on cutighment 2 mode 40 2% oliaal” Uate'a ble, hee aignmen ip dace! eosignrenh Qn] tk con be dayely xermoved / Avorn Who program + exe wees carb @ x-9 yoann duacl perth ment i > : 5 ie WERE AF da avb +e Wy oer gz ab e ° as a¥b +4 (5/28) oo, 4 Code motion: Past of the program CEs a Q= 200) wWk Ca>2) b= Xt) PLEASE if Car evaluation \ on exp” is moveo| from he to ansth¥ in such a way tot ibis evaluated Qe ey freanemtly, 2-6) pag 2: WY Qs 200% b= x+4; while Ca >o) 4H Cake = tho wort th loop: bot com WA sun be execrteol only on . prank b= xtY ib executed wey tre iF ia loob invariant: | we, SA outsicle tre “Web f+ will =o) prints (7 Yd ne); we cm by sth loo invenanh Atadimunts oat =~ a tke ecb: e Anducisn Variable and Shrength Roduch'on : e- taty feu thik (i < Jo) oats 24) > L, \ . yal? 4) yd} fie te Law § (sx) #=tt4) a! Led Urvealling § - hoof unvvol lig ( dep —treavafor moction dechnigng thot all execuhon Abed at ‘les anaolling increas Une piggrams Apel by obiminatirg clexp conto! fyadaction anol Sop text \wshuchor, ; duce vlercttions) Nemeve or - ey AO ow Geo C6 ant, tells") yy loop anrolliny eC p20; L235 (+4) @ tes (veblet yrs (" Hello); & ys cron! BOR IN I ure eo ned to check the vetoed ge epok increnert- x over dime Yourc/ Bis she 2 bat (s/22) ° Lud 3 sing Jamin“ CPusion) . sop {wion ( Loop gammirg) ina @mbiby optima, ans| ool hramsformochon ich reflec rau less with a single one - Mt Ip poss i bl vahon Yeon lochs Posalis, str Jame "rg and do not xefevenca each ster dota. gt. Consichy a pasgram egret int Ly aQioc), bled]; dor (e045 UL doo 40H) a ati =15 by (te0, £21005 t+) eC) =) cn be equirelont to- int 4; alte], bilo}, es (leo; C —anitially 1" C8) <4 Block, TN out B $ Qi By b (3.4) Ba b s) by $ (6a) K7 8s o (9.9) fe 4 (ss) (160 Cxamblr - Considiy the flow srabh | ; ¥) Bc oot (B) = (INLB) -K/uuta))06" best # AR > Led of ements Wot orn Inf endl Gk Ss Wn & Can ®) a afnle) = VU oot CP) = a ovr [BJ = INCH - jute) Vv ‘gen cB) =( > - Gren Je ny 2 Ovreey}=Qi 2) a IN(BJ= v TCP) = %, B47 uTpag v ovTLety = U2) FEW =U 2,64 > 2 oot Bx} a(z on) -.8) ) v (34) \ . Way) 262) 2 WLS), colby DfBehow 3 #, O,4 2 ovr £831 es 94) ~ (4,9) ets -Gis.a). By IN CBA = B20 By 2 Bit, 50). 2 ovr Lea) =(34,56)- (24.n) (G9) = B.4,54 9) 7 oN CBS) = a 7 sn(e6) = Be ye = AG 7 ovr Bs) = oe (459 O99 | spor tbe) =(69) —W2.6) dC) ={09) ake | . ties After its! eration IN anol O07 Values ave |B Block, SN oot ; B, bo Qi2) B i262) (42,3,4,6,9) Bs (3.499) (35,4) Ba (3, 45,8) C3 4,6,6,4) Bs © @ & (6) ¢ 9,10, 1 ry ter Aecmd ther him - Block, IN Ser & b ("WD By (42, Bear SnGiy Ql 3 4,6, 9) B, aH 5,64) 8.5) 67.9) Be Wn 3.4 5, 6,9 a) 3, 415769) bs 59) | ’ (acs) Be 18) 6,9) (3,951) te) My Aine ~_$' ovT LB — o- Eile vy =Uh in Cd = (BV B+) OPT = (1,2) UGA S69) =f 1,2,3, 45164) oot CBr) = (42,3,4,5, 68) = (SO) v63,0 F=f 12,9, 4, 6,4 ) \w( 833 -do7[Br) o oor tps] 22,3, 46) bv (8) {1 2,3, + 5, 6% a) oof B83) = 23 4,8,6.49— 48) be = W2,3,5,67 9) AN LB4) = ovrtR2) L ont B39 ° Soney 46yu B59 = ) Mad, 4,8, 6,4,9) OPT CB4) (4,2, 3 4,5 6,4,4) -@a,N) DEY “U3, 4,56,9), SN CBS) =" ovT(B3) = (%,S,4) DoT LBs} =(3,5,4) 5,9) U9) {3.,8,9 IN(86) > corneas) =@ $1569) oot (26) = (34:5,63)-(.40) v¢ lo,1) (B55), , Jo, 11) Atte third iteroh'n: INL BJ = ovt C81} fe fete) v@,2) (1,2) & SNLB2) = owt(B) VovTcBt) \ ow = (42 vO,a%, 5, 6,9) } =(\,2,3,4,6,6,9) OvT C824 =(1,2, 3,4, 5,6,3)- G9) v3.4) ol) 2, 3,4, 6,4) (sj) rhe Infa3 and OvTfp] valne for blocks ane, inter Veahon 2 an Bimi br to tA vale | / afer Heration 2. dhs He vale of W anol ovr uncle Heredyoy 3 om (ovrect and Ainod ones: Combucting Ud chounk o Ud-choin > Use definition chain . we can Compute ud choins from the weaching 5 defini tons informations Sy a ue of 4 yemabls I is precoaleol tn ids dled by a definition @ T., Hhen only fhe Sool dalinition of Thin te block risk te Hi Wwe Yeaches He Ure « “Thws te. Uul- chotin fos this UAC consists a only 4p one linition . 6 id a * of 7 in precsoledl jnd Lt block B&B by nO ccfinrtion 4 T, shen the ud chouly for AW UNL consist of all dehinidun of 2 in ince). we fsstea \ @/29) Applications of Udl- chon 3— ° Af ~trome b ony ong definition eh Yom v Which veachs « point by ancl What clehini Bon ih QeD Ahn we can substihde > foe He Hons ty a we of A ot point p- del ermine. whether a partiowlor dafinition > We Can Nach anywhre at all, steak logi ol Vor! a a0 “ I's gro sw tha io, i hot Apecifically related <> another we of td -chou'n, to cock obtionigation {ye is ioe can dofesmina bald er a pot else weet diol, “shart 3: ta uncle ed eck hath pein - oe en (5/2) Considayanexample > \ diz TH? ary qye=Ttl Atter doost eratio’®— a po Block GEN KILL i obT, Br fied Hoe ABH), 023 Ro {3 cu D245) 123,43) 2 obs} Dad ale ae DEAS te EHS 8 ew Ce} Led rassd Lots) . Bn tke gyven flow graph thm ete 3 Una of Tomer (D uxe 2D, |) 40 Wes J. RT we of 7 at (2 in block Bl 1s prececld by a dofirition of T \n Bl @ aw het ud den for Tin © Consist & only (0 een \ (s20 Block, QI Qr Be Bs ~e ~~ -e 9 G2 Cen: ite 41, $2 63, 54,55 $3 a S4 sss ss g2, 84 , Ge oot s,S2 $2 S& ss ‘ fixgt devation ‘ we) = ite Ler) ¢ b- wiley VY aen(B1) ab- G35 59) vES9 = (1, $2) weed = ovrcey) v ores] = (Sh$2) 0 - = ($1, 82) : wi iA ) ! A ( Reduction tn Strength. “The replacamunt of an expensive. 0 peradéin a chines ow js ~Rerrse] yeduchon hp axrensth, An gpreen Anduchon yernadales of a love ane thode yomes, urhese only csisnmovt torthin the Joop oe of Ve form Pa dec i wh (s/2a) Ckample- r ) pte fold k ers) a2 ' 4» if Cele got & ye (ee \ 2) goto (D te cH % be lye 8 y>fi © by C4 ni2de Q goto »

You might also like