0% found this document useful (0 votes)
31 views

Unit 5

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Unit 5

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

-V

(cole Cielealuen and de phnalal


5 A Simple loole Geuna loet
A Code genenator genenales larget to de for
hor
SequenCe eKtree- adduss tat enena aud ehfc
cevely
fhe staunen
es regteu to sove operanols
fo exayple Cousi olen e 8 aoloes Sta lGnonl
CodA
a: btC, Cau hare dtue ollooing Seguentus
ADD R. R
toR)
Cost1//A R: Contau b Covn
andtauvy C

Aeld C, Rr Cost 2 f mevy loalu


c
cu u a

(ov)
Mov C, R Cost3 more e fo m memoy
A DD anel ad d
Rj, Ri
Kegis Terand dddus Desttplarns
he Code qenenaluon algontum uses deaciptors
eep rack egiuker Contents and Addresse
nan es

A teauler Des cip lor wsed o Keep tvack


what u COoen tly in each Heainters. The
gis ten odescripbions Show a k fnitially all the
egist ers emply As e
ane Cocle qenerabion or
the blotk oeo progeaces The reiukers oill hole
the vValues o Computalion
An
An aloluss oles tuiplor slores e lotation uwhwre
he luvunt value o the name Can be -found at
9un tume The ineomm allien about lotetions Can
be stoveod n dhe Symbotable and w ed oo
used
acCeAs ke Vaables.
E x p t . No. **********'** ****** .--*****************

Page No.

A Coole genenatuon lgot hum s


he al oi thoatakes as Lput_o Seguente
dhee ooleless stateMent ansluluin a basrc
e
BxK. LoY eacda dhee addnss stalementu
fomX=y op z perfom he{ollouunq ailio
JaYoke a unLLicn qete o aletermine
the lakim here te u l t f the
Coraputahen yop z sheuldbe &lnreel
oault Haeadslasdesoiplnn. o r y o_deleuwe
he CuMenk lotakiom Y Borfen tlue egulz
i tu alue c i Curentu both
m aud aegi te
MCMOM I_ha alue of
inslutlims
is nok alea.oly in l4euenale te
MOV o pkatea lepu_af y
is a
3 ceneate fhe inatutlionOP z' L coherez
LIenklotatm zRelen a megLslen_o a mema
latalion i z_u in both Upade the addzess desuuipti
lotatin-
ex_do indicate thatx is inlotahio nL H x is
in update 1 elesCHiplor Qnd emeve X o m a l
ohen_oleaoiplona
4 h e CuntenE values O y or z_hae no next
eLSes ove_not_ie on exit fom ttue block_andaxe uinl|
Le4 iake alle dhe 9eqislenoles(nuptos toneuiai
Hataslen exeuuon_X'a 0p z,these registers
coill no Jonaten enkounu_o z.
3signmevt Slalomnt
Cjernealunq lode for
(a- 6) + (a- c) + (a-c)
The assianment stalement ol

has the hree adduss Coole seguente


u
Coole Sequente o he exanmple
E:= a-b
U: a C
V t +u
o V u wtth dlve ot e encl
The genwiated Code alonq with e te3iy Rn and
aoldess destip tor updation u qiren es folbw0s
stalemena Code geneuld Regi tex Adoliss
alos ciplbr
oles oup tor

a-b Mov a, Ro Ro Conlaiu inRo


SUB , Ro

u -a-c Mov a Ri Ro Contaiut tin Ro


Alin P
SUB,R, R Contains u
Adol R Ro Ro Contauis V u in R
V: t+u
Conta tauni s u V in Ro
d:- V4u ADD Ri,Ro Ro Contains d o in Ro
Mov Ro, d i n Ro and
namor
yeneTating Code orndexed Assignnern
The Table shocas dhe Coole Sepuences generated
qenenated
tnclexed aASLgnment a:= b[i] ano aC:]:= b
hor
tor the
the

Mov b(R), R.
a: b Mov b a (R).
Expt. No. ********e Page N0.

ELaling Cocle or poule 2csiguweu


Shows bol o
he lalle Code Seuentes qenraloo
e poLlen AsSLgmmet a: p and P
Statee Cocke
Mov Rp, a
P-a Moy a,RP_

TOh Enatiag_(ode or Condihual Slalemeus


statenueuk Lade
CMP X ump a z if ondtip
lode +5-ngare

Mov y Ro
Ann z Ro
ifxsogaloz-
Noy RD, x
CAz.

Bai Blacka auo Loc raphs


ahit
basic Block is_a set o statesaena
alnayaexetuf sCu aften oihen u aSqLenLe
he Ax st lask i to pailom a SaqLusnce thee
addbuss Code ua hati bleka.
A ubaaic blotk beacu wit feirst inubuctio
mot
and insbuutiau_aa aoldle.o udil a Jump a lalel|u
r
fothor
Jn dhe ahsenle_ojump mtolmors
tOnsetulwely pom 0w
raple basthlak
t3:ba-s

ttr
Emologues d U Ba3e Plock
statementa'b+C4

ene and use he Ihvee aoldwss


C
Said to olefie a and to e b and
basic Loce
Live and dtad: Te Marme in
Saio to be ve ak a qiven pornt t Ualue
Lued
alter at poinl in the progom
The name
viahle n t e basic hlocle||
Sad tobe oleadl at a guen pout i il Volule
4 e v e L e d allen a t poutin te prDgrm
pTDgYu
Algoitkm fov patliluovinulo Blorks
A gven pogam Counbe parhtioneol into basic
blot ks by
blet ks b wi that an
follotoung algornttm, Assume hat
inteimeoiale Coole du albready gevales o 7 e n
A Sequnte ob iivee adldres tatimunM
peoqtam pu
1Frrst deteamune h Jeaders by usuny follbroug stule
Ca)The first stalumnt i a Leaden.
(L) Any angek state ment o Covolilional or
untonolilova! goto Leader.a
Ce) Any satiment tat inmeoliakely folow a golo
golo ov
n Conditianal
qoto s a Jhaolen
The basit block fomeol stailing at the laaolerr
6takement and ending ust behore the nent leadun
stalemewt appeatu
onsiden the lode
to Compúlug dot vduek o two leetirs a ad 4
lenth to and paxtton t |
wo basit lotks
do
proolprod t aliJ+ b[iJ;

aule (ic=1o)
* * * * * * * * * * * * * * * * * * * * * * * *

Page No. .
Expt. No...
***** ***.
*****

AcCenalivng o algoilkd
mol::0
Slatenaeui u a laale

3 4tiL hy n b la)
4 t 2 allaLonuputaluu alJ) ktatemant 3 uOat
h yu l e i l h )

Hea te basic bosk


Similanl taleme
8 t a pmd +ts
pmd- Eh_ 8 o 12
Qualh balitblak|

12 i u slo qolb (3)


Bloc.k 1

Blatk

ta[L_
t3(A
6 6 tublta

8- prdtts

12 iAslo gatel3)
Flow aph
in uch the
dlörecled graph
A Fou graph a a
basibbcks

flow Contol ntomation aoldedto the


y
Jhe nodes t h e flow graph ae Aeprexenleol by
basic blot ke.
The block wtase -leader s he frst statement s
Calles inittal Blotk.
*here ts a blot k Bi Block
oli'vecteol
edge from Ba|
ifBa im meoliately folloos 81 in Aiven segtiance
Be Can that B i s a predetesSor B .
r erample
* oFor Consoler -

3 addess Code as
T
prod:0 Block Br: the
inital Block
3 E 4+1
4. ta a l t . ti:4*
5 t3: 4* .
E3 4 * i
6 Ey blts
y: b[J
7. ts = ta * t4 Es t2 *t4
8 tb prod t E'pmd +t5
Prod t 6
E7:i+

A E1
:-E7
if isalo gotol3)
2 i = lo golo (38)
F.loo aph
Loop Loop
Lo op is a Colleduon nodes in the feo qvap
Suth tht ()All Suh nodes ame sbrongly Connecled. Tus
Mens always there is a palh 3om any ode a
othen node oitin hat '
Expt. No. Page No...

h e ollecdion_f dnolesha unique tuliu Thar meaA


olAiole izo_
ihereis onlyOne_path dom a nolo
oop 6he aade iskicle e lep
leep-
LIm) ihe_eop tatContaisno ollhiz leop ísLalleal
Lenp
ocinciple Sotoice Optimiratov
Roguieo to prwou te
Pooly te aukuen ent
ocle
Op timiration -

tu iaternoolialh. Code
tanget odde. Used t Improve
Could sun faster
aslen
hat the output ef ue pYogvam
and take se less spa te or ba
Can be Lotally
oleue lotally basie
lhe optimizáuon Same ba
is appliee) ou
h e
the S ame
tthe tranfomakion is olone lbcally
is done loca
C.
Transfomation
block fhen h a t Kind e
unCuon presenving uomallov
wich Canpilo
Compileen
a
in
ihee ae a numben e waus the function it t
The funion
a o tBrout changing
Can Tmpove
Can proqam
paqalion
sub expression diminatien, opi POP
Computes. lommo n ane
ane
ommen
(om

elimintion and Costant fololing


oeacd ode trnspomatien.
presetvig
etamples Such
funtin .

Elminaluem

Lommevm SubeXpress?on expvesi> appeaxing


oppexing
expvessidn
-

an
en
8ub expression
The Commen
eol
Cenmputeol previousy
previousy
w ih
wuith uu lomput
n he program olo not get changed
Tepeateolly Sul expresstou
ott used
sed inateaol
nsteaol
the opeanos is
hen i
Then
Suth sub
expesion
at
a t all then result o
relomputing
eath ume
eaul E1:=b *C

t2 a-Ei
t= bc Coole
Optimi'zoo
t 3 = t 2 +E)
t a-ti
t3 btC Ase on
O ne
mean
se
' e a t3 propagauon

pagatiovm:
Vaniable 2A
(t) Lopy Ao br e
tor xampe:
exampe
anolher.
anothor.
ulead ok OYA X* Y¥ T
Vaiable

Natiale popagalon
optimizaien usin
e
a oleuS amea =pit r*"
Ceun be olove
Mexe Vaualsle x s eli'i nated
tDead Coode Eliminetion
A Vaiable sad be ve iu a
pog
PTo Tam

be wed Sulseguenty, othewi'se it is dead at


al Value Can

Bhat point Some


Smn
resulE
The oleao oole may be Vwuable or the not
net have
have
that moy
mau
The p r o g o m m n e
epYeAsion Compuleol by
pYeLSio n

Hhue
Hhese ueless
weless ugs roma
rom«
Hungs
eliminalinq
Quy wthen usesS. By
ue Cbole wilqet optimi zed.
Gocle,
Ca-b)
a=b

bC
Tetwn
Tttwtn b;
C O,

Conatant Folding the value


value o a
me hat inteaol
at Cornpile
Dedutin
Deduting
Coatout--and
tuinq the
Cutant
tan-be
Smplpied
aa tcnt
prej sion
Totng he Coale
CooLe
S oon as ConalovWe

b en self. 2*3.
X
Fov examp le
Iuial Cocle
X6
Opbimized o ole :
Zend
(Loop qplimizatin the
The n
nnne
ent lotps, pro9ram
loops, p rgrama

Unnin Time ob
n
linme
oops, espeially
nIn bop l u m e . he unning
ime.
bulk o tuein t l e nwmben O
h e numbe
o Spend te
be tmpro ved eveu
a pmgram may es deuveas eo,
intuttions
an Ane leop outsi de t t a t
outside
amownt e Code
lode
nureae te.
we

Code Htuen or Fregtenty Radueier


Rodluelib
Co
s olecveajed. A statement
The Qmeunt 8 Coole n eop
moved eukside the doop body
Can be
6T epression, wich eue progam,
i t o u t alhectin h S emanlyo o
oved culsiole fe doop
toY etample 2
ptiized T Sinc)/ Ces (x)
while Crki0o) Ccle l e (i <icc)
x)+1
A StnC) /cos Att;
it

Vavfalle elimualuon
innereop,
fom tie
)Lnouttien tie Loop
Vauables Leopp L f
t Yeplate Fnducten Variable Vaxiable
Appiod Called an
a n
Fnducten
T+
I t sis eitrer
etex
is me.
linme.
AYaia ble x
Vcoiable gets thanged
b Some
eveu
evey
nstaut
tnstaunE

the
The Yale of by
Some
incremented
values and
or Te
detremented
B (ode,
Ttu
lotked sta hat iu,
Exomple:-|:= i+ E a n e in
incremenled
i gel
shen value o
aCt intemenlad hy 4.
t a 4 i o g0to Bi k I t e n E gets
atlo induitiow Vari
Hence t4 are

Cc) Redudion n shenglh


Cexlain cpetators hTqhe tLan
ktghe HLan
The tngth e *i
iss highey 1hon
hghey han tt+

for example, ebrength


otuet oplato vs. st reng th
ta kes more aime for highey
tsually. Compilen ment
Replatement
i dess. Replate
Speedexeuutiovn p e t alor 1s

Cperators
and
low
uen en strength opena lor
sbengh opetator by
by
h i g he redutuen Tee huque. s b e n g t h reduiuon
meclutlon
Stength t
Caled a
appying sben
be elone by
ptimizatuon
Can
Cau be epla cad b
streg th
kecnigue
where higke
Lowen 3bvength opetaloYs Aller cptinu zaueu
Beone optiu zalion lemp 7 ;
i14) f
For (i:1 i<1o ;
Sum i emp lemp+7
).a"; Sum)
point f (" Sum Temp;
Puint f ( 7 d " , Sum);
Basic Blotkhs
Bletks
Opumi alun
tle basie
Optimi zauon pYo
COsS Can be aPplieol cu
ang e
clavge
don't uead t s
Blocks. wi le optimi zation,
Ceptcd
Ttiu blot
byTtuu k
lotck
expresSiovs
Sek op imizaleis
ophimizaliou
basic Blotk
bloek

ane
usD y pes
heoa
Yelloos
These ae a
as m a

aufemnalwn
n e m n a l u w r n s

Presermn9
SOuttwe

Ci)
i ) Alaehrit vaudommalu

Imansomatona maton
a nsfo manidomaluon on

C) Stutture e senVig manufomaluon

presering
stmuelwre
he p
TheP
ima
as fotloos
blocks
bastc elimt n á l m
Sub- expression
Common
Dcad Coode ellminauon

Renamin tu
lempolu Vastialsles
Vaialles
slaleme
inolepenolent aodj a cent
Tuwo
Intenchonge
Coe Hovement

ompile Time Evaluallon

Strength leouuion

a
DAG
Ho

rans mmation
aion
pYesoing bra is Co
C ou
tu ee
tu te
tess
l
/he
h e
stmeture
a DAG is
DG tnansfomna
er me
m ea
anns
s
Tak tion
bions tnansfonma
fomalien. abore Saiol
Saiol
Based Tranu t
abore

Bock
Rhen
tRen
he
the Basic
for
tor
Cen e appued. oleatad by
b
olelerled

Sub expvessiom
Can be ea
ea
baate block
Cornmo
e omespemolung bas
ehseving he DAG fer
assum0 e 3
Consi de m'n-Y P Icoe
or example mt aues n=l,

P: n d* P P:2 and9 9 .

mt

belo mes

hen t e expesio mt
P
n m t *2
3

2 3
emmon
2
us
n:5 Contaiu
m 3 Fruuons

for t e
te
Sequen ce ee But fer
Thus, t e above
m+9.
p and
and m t
aas np qes
gels
expreasions
Suc value
Sub the
ommon Sub expressi nP
p
n*P
Mot a

Hente
eappeas,
hen it
Chougec in r epeine
repeuune
on YeAult
yelultE n
expressi
C a c h Uum
sub ives ue So
ame um
Cemmon ivesfue tent each
m+ C o u u tent
Conu
expreAsien t
he 9
and q e
exxp
prre
esss
S Io
'i on
n,
m Sub
Yalues
Vaues
and ke he
Cmmon

The DAG
DAG
P p e a a n C e

poied
to h eCoun
es Sup e
the
sa
S m
ar me
e
ho donths
mt
mt?
and
a
llee Coun
9
n
Oltimalely Hhe CemnCN p

Cntueted and ie
nethoo
bunluon
eicbne
eeEtne
Gou
DAG z a l u e n

he elinminalon,

for
optimi
deaol lode
for voole from h
h he
e
from
o sb o r s
node bo s
e
a
a n

Delete
a has
has
n
no o a o d Coole
Hnat
elemdalion

T
DA G,
DA G nesulu

DAG For Jlenkly


expyresk uon
Sub
rnoM
ebralcidutil 3
fdentiies aote
Csed peeplole oplumizolbio
eplmizauonn
Algebaic appued
Can be apphed
vausfommalucns
Can
Auo gimple
Aechni ues
oplumize eue Code
lode

A Orodlen Jo
Can
Con be
be
Todentifiers
idenufiers
omespending
hese a l g e b maic ekpYesSi
ekxpresioom
agebmie
oeapevoling
a applieol ov

be ob
o Lltaa
uuua
eeol
l
al1a a n
Can be
I ransfommalion
IYamufemmallen

e4 ue
Techmig w e
lecthmig
The
Ihe
algelbmauc

Strength
ye
y eo
ollu
udcllu
ioon
n

use ata
oe Can
e a
2*
using
- isteaol
sing
using
e Coun e a
rO:5

eample a 2
s stead esie
insteao) oo
insteao
opetator
dow e streug-h tte C
Coold
e rcden
e }trdent
CLse e makes
maKes
the
opvator e applel
Stren Can
ghe Jechnigue

Ihe Cuustaut foleding


algebraic r ansfomalioy
raarfamalioY
10.8
R10- 8,
ui
U se
e

algebraic 2*
2 *
S
S .4
4,,
Hhe a a = C o n p u l a l + o n s

achiene using
Compilen i n
tead
ef Compilen
eliminolien, U
Uwse
e
eliminolion,
eamp
Saes
tla ekort o es a

Sus expYessien
e x p r e s s i b n

To app
Thes Sub
C o m m o n
C e m m o n

Cornrnuta t i v i o loes
bloetes

u
e e ba
b as
siic
c
a
The
Ihe
ss otialiviy ano
o
f o m i h o n s

block
block

exouple:Cousrde
t a n s

a
Covsider
a l g e b r a ie

Tox
z

be ppliea as y* z - z*y
be applieol b y hnce
Commutduwe
lau Can
Con
e p l a cee
Here veplate
Selend preasien,
and m beuomes,
* 2 .

block
optim zes
The DAG epresentaun basit blotks
e
basic blotk divetteol a tyclic gaph
A DAG o a
uodes
foLlowin abols on

elenufers, e{her
etuo
denufers,
ae labeled by cent gue
eaves
CemstaneE
Varuia ble name or an epetalor Symbol
Oakelod
abelod by
o dles
are
ntestior SeguenCe
also epuon.aly give Va
va lue s.
s
No oes e

stove te
ue Coputed
Computesd

Lolo els to
iolenkifexs for
iolenkfiers a2b+ C

b a -od
)b,d
C b+ C
do
a- d
Co
se DAG
DAG
Ceatutun
Alqendhm er
basfeblock
te
ConTaining de
k Conlaining
mpor basie
basie Llotk
Llot

DAG for the


the
Oulpul A a bed
bel a

tollowing omatuon Leaves,


te la
no ode
noode
Fov
For Smbol.
operalor Smbol
eath a
ann
cpEralor
label fer Loole S
nodes. held
hold
A ntetior

fiers
t
For ideutiA
ers
identiser attached
attached
ideriti
On
a n
lu
l ut
t
a
each node
for foY Va lues.
Va ues
Computed
the OP z

Ci) X: y
Case
ti)X
OP y
Case

Case
C) X -
Methoe Creae
Creale
noole lY)
noole
tdhen
en
Step ndek
ed
vode Cz) for
Cose Cr)
Tfyis Crtalu
u n dehned,
is
Ifz
Fove he Case C), Cveale a oole (oP) ohose lelt child
u e d e (z) Jat n be Tu wde
ode (y) and ight duld
oole
Modle (op)
daleinine whethen o e ts
Fo e Casei). Such aa noole
noole
o t Create
twith oue chilol node ty). Tf
will be uodeCY)
Mode n
fox dhe Case Crii),
idenifheu Cx)
node Cx).
identifieru fr node
fom du lu t e e
Deletex
atlached iodleilfiers fer
te lut
x to Cx) to o n .
uwole tx)
Append n d
Qnd Set uoole
set
2
n step
wode
uodle n ono
d
Example:
to= a+b
(*
E totC

Example 2

statemant C
8 3: 4*

5. bs: t2 *ty
6 t pred +ts stotementla)
7pTool t

esut
o ifiK:lo goto ti ce) (TT)E ole fo 4*fo
Hoabteaoly, hente allact
due
olantif ex s to

Io
(d) (3)E cat slalement (1)

O
7

Stalemert (s)

b 1,t3

stalement (6), a a h
Slalemmnt ()
() (+E6, pmd for
ikertfi er pd
Pmd o

a , t3

To
Ch) b, prool
nal DAG
pro d o

t2

(*) (t)E, 20

A Lo

4pplialuens DA6
Sub expressLons
oletemintng the Cemm.on
mere
than onte)
Cenp ressious Comp uiteol
ued insiole
siole the
the
which names ae
. dekemining
dekemintng $he block .

oulsole
blotk ad Campileol u ld
ould
statemat
he
h e bloe k
whh statemon utsiole the block
detemining
3 have the Compuleo Value

eath the i thmeue


and oukpulg
A Te inpus be rep
resenleo

oloue wtin ste Cocle Con


opealom tue lovpilen
Coapilen
is vepvesenlalien a |lows
by a DAG, Sulo epreAsionn
Subexpression
eliminauon

Commin
ekeule
t
ebfective

You might also like