Compiler Optimization

Download Compiler Optimization

Post on 08-Jul-2015

617 views

Category:

Education

3 download

Embed Size (px)

TRANSCRIPT

<ul><li><p>TI U HA MCODE OPTIMZATIONSinh Vin : Trn Vn Bng. Bi Ngc Sn.Lp : Khoa hc my tnhGing Vin : Nguyn Thu Hng</p></li><li><p>1.Gii thiu v ti u ha mTi u ha mGii thiu ti u ha m c thc hin trong giai on no ca qu trnh dch? Ti saoNi thm rng: Ti u ha y dng cha chun, bi ton ti u ha thc s l bi ton NP-kh, chng ta ch c gng lm tt n mc no c thSlide ny ch bn n vn ti u ha chung nht, tc l machine-independent v language-independent</p></li><li><p>1.Gii thiu v ti u ha mCc yu cu khi ti u ha m</p></li><li><p>2.Cc ngun ti u haNi Dung:2.1Loi b biu thc con chung (Common subexpression elimination)2.2Lan truyn sao chp(Copy propagation)2.3Loi b m cht (Dead code elimination)2.4Rp hng (Constant Folding)2.5Ti u ha vng khuyn</p></li><li><p>2.1. Loi B Biu Thc Con Chungnh ngha: Biu thc con chung l </p></li><li><p>2.2. Lan Truyn Sao Chp</p></li><li><p>2.3. Loi B M Cht</p></li><li><p>2.4. Rp HngRp hng (constant folding) l k thut ti u ha m d hiu nht, tuy nhin, li t c hiu qu kh tt. tng ca Rp hng: thay vic tnh ton cc hng s bng kt qu tnh ca chng. V d: cu lnh gnx = 45 * 88;Vi trnh bin dch khng ti u ha, mi ln chy s thc hin php nhn 2 s.Ti u ha: ti thi im dch, s tnh 45 * 88 = 3960, gn lun x = 3960 vo m ch.</p></li><li><p>2.4 Hiu qu ca Rp hngV d khc: tnh a ch 1 phn t trong mngCho mng 2 chiu N x M s nguyn, mi s nguyn chim k byte, a ch c s ca mng l B. Ch s t 0.Tnh a ch ca phn t trn dng i, ct j:Address = B + j * k + i * k * MTrong nhiu trng hp, ch s dng hoc ch s ct l c nh. Gi s ch s ct j = const. Khi Address = B + X + i * Z (X = j * k, Z = k * M)Address = Y + i * Z (Y = B + X)Tit kim 2 php nhn v 1 php cng</p></li><li><p>2.4 Nhn xtRp hng ch thc hin c vi nhng bin c xc nh l hng s ngay t giai on dch.Mt trnh bin dch thc hin rp hng tt?Tnh ton biu thc A * x * B vi A, B l hng s, x l bin s</p><p>Cha tt: (A * x) * B hoc A * (x * B) =&gt; khng th rp hng</p><p>Tt: giao hon (A * B) * x =&gt; rp hng.</p></li><li><p>2.5. Ti u Ha Vng KhuynVng khuyn: hay cn gi l vng lp (loop).Thi gian chy ca chng trnh phn ln l dnh cho vic thc hin cc vng khuyn, c bit l cc vng khuyn trong (trong cc vng khuyn lng nhau)=&gt; Ti u ha vng khuyn rt quan trng.Cc phng php s dng trong ti u ha vng khuyn:Di chuyn m (Code Motion):Loi b bin quy np (Induction variable) v Thu gim lc (Reduce in strength)</p></li><li><p>2.5.1. Di chuyn m tng: chuyn m vng khuyn trong ra cc vng khuyn ngoi, lm gim s lng m trong vng khuynPhp bin i ny ly (cc) biu thc c kt qu c lp vi s ln vng khuyn c thc thi v t (cc) biu thc ra ngoi vng khuyn. Thng l t ln trc, cng c th t xung sau nu khng lm thay i kt qu chng trnh.Lm gim thi gian tnh ton cc biu thc, thi gian truy cp b nh, cp pht bin v.v</p></li><li><p>2.5.1. V dXt on m sau:while (j &lt; maximum 1){ j = j + (4 + array[k]) * pi + 5; }p dng 2 ci thin m:real maxval = maximum - 1; real calcval = (4 + array[k]) * pi + 5; while (j &lt; maxval) { j = j + calcval; }Lp trnh vin tt vs lp trnh vin ti</p></li><li><p>2.5.2. Bin quy np v thu gim lcThu gim lc: thay mt php bin i tn km bng mt php ton hiu qu hn: php * thay bng php + , dch bit.S dng li cc kt qu tnh ton trc .V dfor (i=0; i &lt; 10; i++) { j = 17 * i; }Thay bng j = 0; for (i=0; i &lt; 10; ++i) { j = j + 17; }</p></li><li><p>2.5.2. Bin quy np v thu gim lcBin quy np c nh ngha quy nh sau:l nhng bin c gi tr thay i mt lng c nh trong mi ln lp. V d for (i = 0; i &lt; n; i++) th i l bin quy np.Nhng bin l mt hm tuyn tnh ca mt bin quy np khc. V d, vi i l bin quy np; j = 17 * i th j l bin quy np</p><p>Induction Variable: Khi c 2 hay nhiu bin quy np trong 1 vng, ta c th b bt cc bin ny ra khi vng lp.</p><p>Loi b bin quy np v thu gim lc thng c kt hp vi nhau.</p></li><li>2.5.2. V dXt on code sau:global sum;int i, j = 5; for (i = 0; i &lt; n; i++) { j += 2; sum += j; }i, j l cc bin quy np. p dng vic loi b bin quy np:global sum;int i; for (i = 0; i &lt; n; i++) { sum += (5 + 2 * i); }Thu gim lc: biu thc sum += (5 + 2 * i);Chuyn thnh: sum += (5 + i </li><li><p>Cc Gii Thut Bin i Ci Thin MNi Dung:3.1Cc khi nim c lin quan3.2Loi b biu thc con chung(L Thuyt &amp; Gii Thut a ra v v d minh ha)3.3Lan truyn sao chp3.4Di chuyn m.3.5Loi b cc bin quy np &amp; thu gim lc</p></li><li><p>3.1Cc Khi Nim Lin Quan</p></li><li><p>3.2Loi B Biu Thc Con Chung</p></li><li><p>3.3Lan Truyn Sao Chp</p></li><li><p>3.4Di Chuyn M</p></li><li><p>3.5Loi B Cc Bin Quy Np &amp;Thu Gim Lc</p></li><li><p>4.Kt Lunim mnhim cn khc phcCc hng m rng</p></li><li><p>Li m uNgy nay a s cc chng trnh dch u h tr vic ti u ha m.Tuy nhin c nhng chng trnh dch khng h tr, v d nh TurboPascal 5.0Nghin cu v ti u ha m gip cho chng ta, nhng lp trnh vin, c bit l lp trnh vin h thng c khi nim v ti u ha m v vit c nhng on m ti u hn, chy nhanh hn.</p></li></ul>

Recommended

View more >