0% found this document useful (0 votes)
2 views15 pages

Intermediate Code Generation

Uploaded by

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

Intermediate Code Generation

Uploaded by

ishu57881
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tnlet mediale code Genovatiow

E:(a+b) *(a+ b tt)


TMc
ee-foem

Linea fozm M a s tP o p u l a s

DAG
Three Addveuu
Postfx Coode SyrkaxTkee
t atb
Ob+ab+C+%
EX: -x
t 4 t*t3

*
lc Tzee -
IE u a ind f pane Tee mwhitk is

Cowden&ed (Shorle vesion fade Tee)


Tree Addre code
Twee addu ode is a fom an 'lamediale
code
E
isaemevated by the omfilet et
lt wes macimum thee addveuts o
implemeutig cooe eptimizatin
ebeleu am Stalameut
eneva o 3-Add. code
n jene/ak, Three addreL wstruetiuns are vepresedl as
abopc
.Hene, ab,and ave
è epeands operands may
names, t
Comlet generated. rempo vasies.
be
Coustars
Ppesents the evaló
Ex L(a+b) AdtE) *

t a+b
Binay op 3-Add. code
ta C+d
Binauy opP
t2+e naf
t tz *tj Gant P
T 4 Aipmne op.
pes 3- Adldyeu code,
gructien
O Bingty opeatov

Heve, ,3,z ave opevand


p Pevalor

UnaDat eperalo

3 are porand
P pevator

Assiynmeudopenlor
Relatioa operntor oih Condition Jols (Rel"op a
==,\4,7<7:)
, 4:)
e ol Level (L)
Unconditioual olo
oto L

Armfauy ndaing
ACiJ-; ACJ
Pone
Heve, Addven f a vaiakle is
ethel variable auiqned k Seme
uee, au
Peinted by a
polaq
Ex:-(a +b) * (c +d) + (a +b+¢)
a+b
Quadruples Evey insmetim can be
Yepvieleutes uing 4 elemaul
t C+dd opr P ves u l l
b
tA = t2*t3
t r a +b
t t + t3
a
t tq-+t6 ts
6 t
Note t
eve ofe
Hotmatg to Aote Advanlase: stalemds can be moved
hre add vw code mto alouud.
compndeis
memoTY' Mese e . pis ad To mua space is nasled
O quadruples Ta~ple
Rndirett iple
(it) Tiple -

Euey iust. ca« be


preauted stoved ing 3 eleme
cpY opi 2-
a
Advaua Space is not waslel
-

(4) sad w e annet moe


C
he
Selemet alouwd
) (3)
+ a b
6) + (S)
(c)
Cii) Sudirect iple
b
Evey ine (3)
apoinMe to tinyA
the intruchon(ivy () Poinlex
( i'C6 A talemen a n be mouec

Dis. w o memon
acceuas qe

equve ) ACceAhe adt


Hfelk
fo Loop ( n c r e m ] D e r

toEt E2, E3)


E Tni tializadin
Coudi tion

Es Exit

HCrem Ea T
deamcn
atio
taleneu

E: foie o tcio; i+*))


on Loop
b tc,.
L O initializatiun
L FCiao) gola L it coud iu tue

ZotloaE+it
Caud is fals e

L tbt
lb+C
a

t =i+l?
Lucremeuf
3i-t2
Jots
Aersim Soiteh-cale stalameul- iuls [Link]

Suoiuch (itJ) / ti+j


goo t e g
Coe C):
(Gzb+l L:ptsb+
a-t t i CeLre )
eal
Caje Ca tLastL.
P-+R La: t- Q+R
break
P-t Cage
defat: gololastE

83
brenk
L3
t defausl ode
3ot las
test:t-=!) jotLL

las:Ei
Bacl
leauinq toe labels au enply cmo flli hem latet
Patebing >

s called back, pathi

(ac) hen t =
1) else t o
ab) Jol6_4
t
t
Eit Endu
Conveysim Loopinq salameul- mts Turae Adveu cade
O ohile leep
while ( conditim) Ale E doS
Stalevul

Exampe hile (acb) do


ohile lotP

L:CE:0) gos L1
S
3o L t - 9+* )
Li: ExitK

Last: Evt
Thyee Addve cade -for couditieva) Salene
f-else qalaneut
Cacb)then zdte else -f+
Tvee Add. Code

O(acb) zs
t de

o41t
oast
lasteit

(2) mree Addiunce f Asimneuf Gafenneul


oPK. here Dp is biwaty asithmetic ot lqicad
opevation
Afinmeu

A= -a +b
3- dd. Ccole

t+b
Thvee Ad code foe Aay
e A L,33 ven Alox20 f*ao + ) 4
t 0
tt*3
t 4
t4=baie addreu A

aud
baae
Take he
Peld Oidn offsel-

Code ptimization Reducmg the tie e paivaw otlhoul


caing+he astun affectinq Ahe outaul-
ebjetve code ptimization
O me dmizadin must be Cotfect it sheuld mot chau
he meaniu h e pyofa)

a t h o uld increale the peed and performauee chk #he


Poam.

(3 he tompilatium dme must be kept sealonalsle


() Me ph mizatim pvoten should not dolay e ovoml!
Compilua Peeu
ybe Code optimizaition

Macdine depeudeu aebine depeveen


D Lodp optimization Oiste Allocation
CecdeCoce motin o Ue Addvniy medes
requeucy eductim Peephole optimu2atro
Lotp uwyolinq 4Streuatth Redutien
LodPLoop Tarnming to corol eptimiaat
Foldina
coustant fadig
Reckuclanty elimivetir)

() Steath euctiom

Lovp obti mizatien

To aPPly loop obtimiztin de musr fstdetec luops.


r detecting 1ovps we usa cotoL ftod a
nalsk CFA) usi
Pvgam toa gap (pe 4)
To And PFG, we need t find baste blocke.
A Baic block ic a
&equene f 3-addreu Aatemetg
where contol eules at the
the end beinning and teaves dyal
ihou ay Jumps or hal

Loe
CCFA ÇPFD
findim the Baaie blocE
order ofiad he basie blecks,
the
need ts fAnd the leode
e

peamhen a baie blecte illaut fom one leade


tthe next leacder bu
not ineluding next leade
deuiinq leades a bast plock
U Fis t talermeu s elsay a leadei
Stateme Anal
dlae ik
touditena
o s lemen- i a leader
oR uncodeti
lemel tha follos wnediatal a CondHm) oA
UnconoliHenal aota stalenel sa leadel
Three addreul_ code
eptimizatin f leadu
at
Lsops
}i>s) aols glenda
CFA (PF t-f«i; -leade facta)
)f-t, feali2,ik=«^i++)
Boic Bloc =it1 ff*
7) iet2 Teluewf

Leaders
GLeacde s a kid el tin
Speciap Gtaleneut
t ) gots g

.O4-
Tae alye
Toue
Cycle
Cyele indieali l o p

it2

(
84 3ets eallinq Pegon
Loop optimiratior
Code Motion or frequeuey Reduetion
Moving the code fom higher frequeney regim to a tou

frequeet fgion. i 0 = to,J=SS


eq-) L= 0, ai0,j-,
while ( i<= Sooo)
Lohile Ci<=S0oo)

a
pivtfcha", A);
Bafore optumigation itfc-a", a)
Agl aptimization
() Teuwvollinq- Loop unvolling is a lop tafovnaluvn teclunqe
hd-helps t eptimige the execudiaM time ef a profam
n remo ve ov reduce h e no. *
Loop unwollin, we basically
9tevadiews
i l e ole (izto) )0-o
eue
A4signiq value
d

Ci-o,
Lt+
3- oomes

- O

while Ci1o )

Ci0

P Jamm: Lovp Jamnin is te pvoceu Colurg the


a o move weps us a vgle loop

Ex: in-i:o in o
fonio es it+)4 t ( i o i<s; i++)
a i +S
a=i+s
forlio i s; it4)
bi+10
Abl opimizaiom

fure ptimization
oldiFoldi Conatau-folding
Keplaeina a n ex pvesion ta coaw be
computed a Compi
ime bit values

C 03+4 +C +8 7+c+S
val PIe2)7 3.14
Keduudany eli mi nationn
Beere aptiniaat
atien

D 3+Btc +4 r»
A 6t
D-3+A+4 optimized de
D A+
Streut Reduetin
ne
Replacinq a Costt petim by cheaper

e A+2.
A

Agebaic smplifiation
A- 4 t D

eliminaion
Sub ecpkessiom
G) Common-
cdled a comwewSub ap
eepressieu(Eis

HM
0cCuYTenLe

and t h e
alues ef
Computed
was þreviously
expesi E Sinte h e p
have not chauged
e vaiailes in E
io
Sub eppfets
Computaton
common

Heve t s a

alveady compuksd i (1
a tt3 Since +
is
hae
TE P+d, i1) values f and y
Cwd the
empulalion
b +JtY{u) not chaedl Akte tte fMt
and it-i Rame i i)
Coniider te folleaisa blockf
Cde
a- +t3

4g-tt
a 2 bt4

e Coce akle Conmow sub-expressio) Eliminállon

a types
O Local Common Sub *[Link].
a-t Gloln
Co mmon 6ub-exp elimi
P+4
t4- t+
T-t3 AteeptmistyB«fore,
o t i n i s t S < f e a ec p i m i g a t i c u s

b=t4
a-bieC+ t bc
d-bc +e a-ti +& t g t i +e
d t+e d tz
DAG s ued ts epjenta
DAG Divceed Acyclic Gaph )-e
Stuchure basic blochs. tE s a aiaaramaticallypresedatiu
ban block
s a d ts visualize flod vaues beeew e a t
DAG the

bloces, ad pvouide epimigatin teehniques w the basic blc


I E demonsta tes ho the &tnleneuts computed value is wed
i 8ubsequeu 4lemeuts.

Erample O To= atb - Ex pD

TT+c -Ep®
d o+T-ExA

C
T
Eample 2
Tab
T T+c
Ta TT
T

DAG

Example T, a+b T4

4 - T3
Ts T+T3

You might also like