0% found this document useful (0 votes)
16 views20 pages

Assign CD

.
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)
16 views20 pages

Assign CD

.
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

produces Code 4.8.1 4.

8
The
iv) iil) i ) i)
truction selection
rderingInstruction
/ Target Code
Intermediate Code
primary program 8 generator
Register Source Introduction
an Code
generator generator
program equivalent
tasks takes
allocation Representation Generator
Front
of usesshould produces end an
code target
the Figure intermediate
codeBiC
and preserve Intermediate
generatoravailable the
Tgtreion sictr program
assignment 4.6
(IR) target
the Position representation
as
are:resources is oaan,
program
semantic given Symbol
table
optimizer Code the
as of
output.
effectively.
meaning input as code
output. to Intermediate of
along generator code
gniuaieno the
and source
with
quality generator
symbol aldst Code
program
in
the table nasti
program Target
target as
information. A the
program. input
and
e.g In program
different 4.8.2.2
TheTarget A8.2.1 achieveTo resourcesheof
generating / / The
based
Stack semantic
generation Intermediate eTOrs.and The Thesymbol Target
design Issues4.82 in eftic ent
a
The Codetriea s
i ) i) i) table. Input program.
Instruction
allocation.
Register Target Input
following code
Java Use CISC RISC Some
types Graphical o o o o codesource Evaluation
order,) to
the th
It Three-address
Virtual
Linear
outpuutsecodteoptargeitmmoizrere
is - program to
generator. code
of the to the primary targetthe
notVirtual push of generator the
Complex
Reduced thetarget of program challenges
architecture representation representation
machine selectíon.) code the must can
widely and target code
target representations 1s tasks be to
Machine pop program. generated generator.} Design machine.produced. be
used Instruction
Instruction program code assumesshould generator and correcttransform
operat io ns machine representation may
ecause(UVM) in such
terms such takes that be based occur produce of The . and
1s properly the
is Set Set
architectures dependent such as ose a code
many of of as
quadruple, different the of
itof
swapandtoo used Computer Computer address, postfix on while correct Code intermediate
high
as such intermediate the generator
syntax scanned,
as forms, input
designing Generator quality,
are, on notation. bytetriple code
instruction the 5ibooniuggem ioiiortOS1
trees
viz., parsed of itself i.e., code
target code andrepresentation
the the with
and
moves.
copy indirect
and and code code there
high should into
and DAGs. should
machine
register stack translatedgenerator generator. quality, a run form
from
triple. is
machine free efficiently. make
architectures
makes
from thein along effective
code. is which
challenge a syntactic front with
as need
end. the
the
levelIR data Nature
If selection
targetnstruction
The 4.8.2.3 358
Quality
The codeof the
SomeTherefore,
e-g., type IRofcomplexity
LevelNature languageTo
uality Instruction
/ speed. instruction Desired . machine
Complier
of make
Generates
eficient
more Redundant Typeidioms.
Machine of in
instruction
of sequences
code
Floating
the a of the
of uniform
code important exception
requires
each qualityinstruction is
Design
code.ba set determined of Instruction Instruction
code Addressing type
modes Registers
is load point is mnapping Features
of manner. not set generation
ined 2e
and operations
features set
uniform generated intermediate
level
Low by
store.staess architecture.
factors easier,
by 8 in and code.
its slg the wil incomplete, Relatively Simple
Three-address Many
handling.
special such itsimple RISC
eed, Check IR instruction be representation produces
level ogebaspok
done as
size,
separate
using the an
time selection
level
High target into assembly
and Two-address
Complex Few
machine code a
Variable
length CISC
ost. olos are:
into
TranslatesIR registers
some in
Needs
optimizationsfurther instructions
using
codestatements onioso
seqences a sequence
template asbo
iw generator
code by does
statement
Poor
of program
machine isaniN lodva
olds not executed
on support
as
a machines. output.
hv.
each
gete. plays The 4.8.2.5 Registers
generation allocation
Register
4,8.2.4
Hence,generated allocation
RegisterRegister The
a
vital register
Evaluation is are
the role assignment selecting the
order target usage fastest
in
in the code order can what
rformance
which theof -computational
should difficult
allocating process values be
the bieluo classified
ations be
and of to
executed dold hold Run-Time
andstoring
challenging as: unit
s finding in
target
code. ot
in
oldensy a which on
the value the Environment
are the
ormed target task registers.target
optimal ina
svissslooole even
machine. register.bo machine.
with
assignment and
can
affect single Code
The The
Generation
thesequence adi register of issue
ciency (aioubas register
in
ofmachines. 30 the
execution is
the code 359
of
the
Register
variable.botsioozzsOL
Principal the value must
of hold. consecutive
Register collectionofCode
assignment. 4.10
/They performanceNumber
ThevRegisters generator
stack). They andevaluated.
assignmentallocation Design
used can uses
hold help of
in are ofavailable is
the inother also of used
runtime register
used
operands be program.ibs of
Register Register
blocks. used registers three-address to a
to generate
storage to hold
Simple
of
an hold assignmentallocation
temporaries is
operation
management global limited code
statements, Code
gs is for
values, is the
based siosliSs and the single
generated
(maintenance hence process processof Generator
on 1.e., it
keeps basic
machine Values toatoefficient
while of
picking deciding
what trackblock.
of
chitecture stackcomputed larger usage
eb of As
up register
pointers, expression of a the
in register register register
one values a basic
concered. allocation
elements basic block
is promotes to
block being store
of a
and is
a
getReg()
Processofstatement s.
getReg()
getReg(s)
Function locations Address descriptor mentioned
Addresslocations.
the
descriptor. registers descriptor
Register
4.10.2registers Register locationWhen 4.10.1 364
getReg) This The These The descriptor.
Address
descriptor.
Register r Instruction
ordering.
allocation.
Register
/selection.
Code VCode
0
3. 2. 1. function is during values
ordescriptor number descriptor to generatingof generation Complier
costsfunction.
If holdingY. If If Code
used combination locations the values.Register
both the function
a
nimum needed execution. of code
decides to of Design
(1) variable Generation identifiers
select maintain For the
works may generator.
registers maintains
and thitarget
s and issuesokt
variable the register of include 2e
umber (2) is aforementioned it
are as status The memory uses code,
Address
not follows: are needed the
not in Y Algorithm memory stored bns
of of for CPU values two the
loadlikely a is available location for tsesorlo
register, already each registers, descriptors. code
locations as
and to the generating stored Desriptorsocle
memory locations. generator
happen,
store registers which gei
then stored values heaps, slaok
in
may
ns. then any location oiglis are code registers.
in and of
stacks, must
either names used
etReg) available register, load bo
also is keep
opioe gole
associated olelga be in determined
the might the
memory It
picks register elelgerlocation heap, informs track
it program. giah
uses stack, be of
up or
a
with oilosols
stored a by the the
gister is that osu o of
used three-address
name memory, combinationconsulting
availability availability
register bioden at
by
lsqloni
whicn values. otigo various o2
the CPU
k of this of a3
bioos
a=d o os instruction
For a.
a-csiisO
9TU=907 o /refers Let
d=v+u V=t+u t=a-b / location / location The / L
vb Once descriptors The
is instruction, The not ThegetReg). be
tperhrefe-oramddred.es
LD ADD SUBcDR3,LD SUB LD LD in
AD R2, R2, R2, R1, location currently address a.
R3, R1, ak
b there L value location
R1, d
R3, R1, respectively.
R3, R2, to of
R3 R2 y.
R1 R1ISC is of of op of the desScriptor
in L
y no y The (or
Lop
another, copied Where
T further and L.o2980qa instruction
R1
e z L. register) a
a which
z Here, of
to value of the the
use operand one
indicate is output
gets
a a,d t R2 z' toformRun-Time
of of MOV of
y
stored refers
y. store
and z the z
R3 that is the
z in to
found operands , =
is it L the saved y
found, contains has Lis output Environment op
R2 a R1
a,
copied by used z,
R2 a to is the
be the y
isdetermined of
they to
b b the
assigned value same consulted following
given
C
R3
c, copy
C tdC can value and
R2
d, be process
of instruction.
R1 the Code
stored of to z. by actions
R2 R2 R2 z z. value to
and as find functionthe Generation
R1
Hence,
R1 R1 in that
the ofout are
R3 V
memory. y
R3 R3 of
value
update tothe
y present L
by i fy call
ofthe the 365
t is of
where assembly
common
way. 366
e.g., Loops
a,
b, Complier
Design 2e
c,d and
are
conditional
live
bles
a-cU=
a=d U=t u
t=a6 statements
and
t,
u,
V
can
are also
ries
be
transformed
local
to into
the
lock. assembly

language

in
Function
putation. Optimization
Function
5.3.1process
Principal5.3
eachFor

preserving
and
tion,
every
local
nsformation
Preserving must
Optimization
Sources of
preserve

improves
sformations the
semantics
ions
lobaland
a
program
of
the
program.
original
without

changing
will
place.
take
the
function

for
tion.
uces sub-expression. Ihe D3.1.1
hencepreviously
It Thatis,
expressions peloot
helps
Common
an
comput
replacing
ined
vd oiterirllonoso
l
Occurrence which
sub-expression
and compute
the the of Figure =
9=4*j
x10at] a[t8] 7=4*i
t9 t8
=X=al6] =4* t6i
common values an gotoa•tB10]=4*j=

expression the 5.6


-dut same
in elimination
Flow Bnrbaio ifi>=jgoto B 3<vgoto B
if 1=4*n 0=m-1
=4
*j
t4
at4] t5=j=j-1 2=4*i
a[2]
3= i=i+1 V=at] j=n
xpression E value 6>
have
isE graph golo v
not said that B,
B,osooT
B B B
neoo changed to has for
by be
already a[t15] 14=a[13]
= =4*i
xat12]= 14 =4*13n12
t11=4*Ë
its a
quicksort i5 x=
common =4
alt1|Bsot
leoc
previously since *nal
been Optimization
Code
the
sub-expression
8.previous computed
computed
9upR
is g
computation. the islin znoizeg
value ifcommon
E 387
and was
in noono14=al13] occurrences
expressions 388
ompare the In
Similarly
transformedFigures Figure Compiler
Bs:
Design 2e
B
B5 5.7 Figure =4
at15] x= t*n
15 a[t12]t14 = =4*nt13 B6 with for 5.7 Figure
4*i 12
=a1] X= t11 gotoB,
a[io] = t8 at6]X=4*i t6
=a[t8](9=7=4*i
x 10a[7] 19 =
with and =4 t6 = =
B;
can t6 block 4 4
5.8 5.8 * *j *j
B2 and i be and and 5.7
and
depict locally t8 t8Bs,
B6, Local respectively. Local
B3 local respectively the
common optimised
and common sub-expression
common
Local common sub-expression
common
Local
assignments
the common
xpressions
ns and
sub-expression eliminationinils
nol as, elimination
b-expression hence sub-expression
to
t7
both and
can 4 are t
*
elimination
be and i elimination eliminated re elimination
one Bs
4 B: tound
* a[t13] =
x a[13]
t14= X=at11] t11 *Ë
t6
=a[t8} t9= t8a(6]X= =4
as i 3=4*n goto Ba[t8] =xa[t6]19 =
S. are = to for 4
for for 4* by be *j
availabe B6 i
Bs replacing
common B
and
Bo.
ther suh.
Now
two
sub-expressions
Similarly, In
B2,
t2 Figure eile
computes
B;
Eieure
Global
5.10 19
= X=a[t6] t6=4 *j
can rnolaeeg6-due gotoB;at8] x= alt6]19
=alt8]B=4aj
t11=4*i
X=ati1] 5.9
a[t13]a[11]=
=x 14 a[t13]
14= =4*13n
be are 4
optimized
eliminated * Global
i
and sub-expression
common
Global
sub-expression
common
Global in common
mmon
as inB3, SoRoloiakotigo ommoo elimination
B;
elimination
t4
and
sub-expression
computes
replacement ghub
sion

4 beouhotfiieoio
*j.
occursHence, elimination
x=
gotoB, at4]a(2]=(9 a2] X= Code
a(t4)t9=Optimization
ation a[t4] x=
gotoB, at2] 19 t5=
= 19
X=3 at1] = 14= X=at2]
xa[2]=14 at1] X=(3aa
at1]14
=
bythe
the
computation
computed for
for Bs
avl
itibe value.
bse sdo
of 389
those
conditional
not holds, is 5.3.1.3
A
achable said
InDead variable Hence, by 390
Figure to B6: B5:
g.fpropagation
5.3.1.2
Copy
Copy
(i.e.,
be Dead
From Figure
code B; They
statementtrue).
(never live is Figures statements Compiler
Design 2
said and are
5.14, refers code 5.11
variable. a[t1]=x
a[2]14
14== X=3
to goto a[t4] =
Ba[t2]
X19
t5sa
t=
9= X=3 B, also
So, the be
toelimination are
a[t1]
gets the can 5.9 Copies
when print the dead a=d+e termed of
ted).
condition Figure further and
statement Figure the
statement or 5.10 C=d+e as
the introduced formf=g.
useless be it copies.
variable 5.13 5.12 b=d+e
never optimizedclearlyis
which It
is if Copy is
satisfiesexecuted the propagation
Copy Copy propagation
Copy during
s
getcomputes visible done
value as
assigned propagation propagation follows: thatcommon by
which of replacing
if z t=d+e
and value variable a=t
=
inwith t3 the
tun only that for for sub-expression
and C=t
false, never B6 occurrence
makes if is t9=tT t=d+e
B;Oes-dua b=t
thenever t3
a[t1] 3= 14= X= t9=
=X=3t5
gets a[t214
]= goto a[tB4] a[t2]
t3
=t5
then
the value a[t1] are
used. used. of
prt for copy
eliminatien either
of
all ð OtherwiSe
staterma. g
Siat cases cold by
f
of o or
loop.the S.3.2.1
Code Constant
folding
cOmputesConstant 5.3.1.4
Optimizations
Codemotion
S 5.3.2 Bg: o Bs'
spent Loop Loop o14 alti] = Hence,
This sgoto B, dt int
ifprdebug)
motion optimizatioinns a
folding become
bodythe
aims executing The
constant conditional
X=
3 a[t4] a[2]=
3 t5 t9=
t5
= X=3
to refers a[ti] a[t=
32t1]4 =
computation is ba
duce to value the
aare Figure Figure
the loop. process statement Figure
the eneeded by
proOcess a=2*3.14 its 5.16 5.15
tation to valuewhich 5.14
of improve elimination
Dead
code and if(debug)FALSE
print.. debug =
Dead elimination
Dead
code Dead
moving of its Dead
verheadin replaces
constant. code
the can code
code
code be
performance the elimination elimination
segments replaced elimination
ps.s
rolianicsite
computational
by dead
from of a for for
loop eldsiev and
=6.26.ody Be a[l]= a[2]
1314 t14=
a[t1]
= B; =2] 15
=
od inside goto a[t4]
B a[tt3 are
as statement FALSE
debug =
the mordsbiasuo
e qoolbs eliminated.
noiioubnl
loop execution
that
to sotsl
outside always Ss6
time
implies outside implies e.g,
Inductive Note: that An e.g" Steps:
5.3.2.2thereby gets 392
Similarly,B3,in Hence, That
forinduction Hence, (1) ()
that the that B2, In executedFigureIn concerned.
ltohopat Move on
variablecanbe reducing
each is, Induction
the Find CompiDesilegrn 2e
enever they
loopwhenever a the
assignment
variablevariable limit 5.17,
though the
number loop
and can the while(i loop
variable - the
preserving be t2= 2 the < of
the i=i+1 z computation
is limit ant
4*j t4= optimized the of is of condition
is
value invariantintivari
mes
value j=j-1 value 4 computed inductive the
-2)
* a,elimination found
i its form, a
of the of value
of Figure
inside loop
j by time. to limit variable/vari
codeable/code
ases semantics increases i
eliminatingi=i+land with if z gets
increases there = be
t2 while
- 5.17 motion
Code
=
increment
single T+c loop 2 executed.
is
by
t2 of by a
never loop
Code
+ B2 constant
(or Or invariant outside Variable -
1, 4 1, gets is
the by the decreases) z=T motion
the value evaluated
changed the
alue c and or
statement, decrement)(or (either loop code
C.
of moving of by is each so
t4 t2 by limit
while(i t)
<t= -2
gets positive
c. moved the that whose
gets and
the it
d increased executionevery independent
wil
value
per or outside
computation be
loop negative), is
time the
by the of
by iteration. loop. the entry
* 4.
such loon loon
4
*1 of
e-g
Figure It It
can
focuses on of532.3 outside Hence,
2 a also the
ContolBo
of * **
exponentiatioReprnduoccesstiReduction
5.18 in loop they
a
can can 2 on bestrength slodqo
oding shows reducing called by and can
be cheaper
replaced be in preserving be
0] a<tt3
gota[to 1B =] =5 the replaced as strength
is loboooptimized
19
optimized the
strength
computation the
Figure by
computational
by the
ata. by
areduction. semantics
5.18 Bs flow * eliminating
if if a t44 t4=
iff>=jgoto B t5 t4-4 t4= 2=12+4 m-1 i= such
alt4]
> t5= 3< a[2] t3=
t4
t2=4*
V=a[t1]i j=n graph
imized vgoto vgoto =4*j
1=4nitauienk
insbnube b replacing
cost as of
Ba B for multiplication.oU
of B3 j
Figure statements. by =
flow an the
j-
Ba B, B
1
graph 5.6. expensive statement, and
moving
Optimization
the Code
a[i] a[2]
3=t14a[t]
14==

computation
computation

Be
such
393
as *j4
with
sub-expression. The 5.6.1.1 may DAG 5.6.1
optimization Global optimlzation Local 398 5.6
e.g" theWhen expressions The beThe Optimization
/
Applying
Re-ordering Eliminating
Eliminating Each to
same Finding code usedblocks the
Each For for informationGlobal / They
a each basic DAG Optimization Compiler
node node node
children by statement are
is which localalgebraic
improving which
other variable block optimization Optimization of
is is
Representation easiest basic
to ofdead local labeledassociated from Design
with be compute blockscontain can done
common statements code. common in to blocks
added laws transformations the in be one
c=b+c
a-d d=b=a-d
=b+c a the by a performwithin 2e
inthe parent withconstructed basic basic
occurs is
same to the tothat the the of
sub-expressions
DAG, reduce
sub-expressions. live each of
same flow operator. node block
a block as two
operator are variables statement of
throughout they basic Basic
a independent graph.
in with Basic as to types.
check valuecomputation. which are
DAG follows: another.
and that ar e and initial carried block Blocks
is are Block the
in
made has representation called its by
the (on the value,
already children
last fiow out itself
same to one as
know outputdefinitions. node a graph exclusively is
order. been another)
of are called
whether the is by
computed basic nodes
or created.
nodes analyzing within local
a (of block and
node each that optimizo:.
is these the
are:
is the statement) corresponds the hacin
existing common variables
flow Ls
t
or Jabelled
WAth by A
5.6.1.2
other code Hence, From DAG
Dead
code variable isA
no
is for can
ancestors) blocks. dead Dead the Figure
the be
ifcode C=b+cval basic same given
can
Otherwise saidto it 5.21,
from be contains Figure
DAG
5.21
eliminationc=d+c a=b+tc a-dd= d=b a-d=b+tc
b= a block node. as,
eliminated the bo
the be
ctdb=b-d can common
a=b+cconstructed itlive the
is be +
dead. itsifvalue transformed
by [if [if
removing nodethe value of bis b sub-expressions
is representation
DAG. a not live
reachable isdead
live at as b,d Loopicot i
variable. the do
then
awel end]
ikcoie
are o C
at replace
avilatooaas containing for
the found
etigrieste basic
end the
of occurrence to Optimization
Code
blocko
the basic be
isslumno0 ni
dead oltoubef b
block and
variable of d 9au
or by b as
is
it they
8..a. d .a.a
(node used .tae 399
are
and 5.6.1.6 Constant
folding
Constant 5.6.1.5
Commutative computation
Reduction 5.6.1.4
node So e.g" e.g",
Algebraic 5.6.1.3labelledc
Ifa 400
when
Commutative
y folding Reduction
as Compiler
finding
left law by in identities Use becomes and b
strength of are
child. states is a algebraic
common the cheaper live
2*3.14=6.28 2 in are the Design
associative
that process a/2 strength
* is used root and
= = computation. a c 2e
node and bo
ssions, *yt T+
way to
identitiesstnoaoscot
of * e
=y*T. replacing 0.5 of simplify
T-0=T+0==0+ =0 and are
laws
optimizing *1=1*z itnot
T arithmetic removed.islive Go
a
a constant and then
node a =
basic T/l=T the
is expression expressions DAS node
ecked
block e
od do

nes S.d wil


with by by such be
replacing orug
its as removed.
node computed

as expensivean Then
right
values.
ciid
the
nod
Rules DAG.
computing
from a The 5.6.1.7 re-writtenas,be
/The variables If Then
V V no
signments
r. aAny When temporary it Associationcanbe
value bse bi the
Reassembling can
use an which be
of array of values
written
a or a are e=a+d =btc a variable
ariable from is node of explained
assigned nodes used basic as,
its can is
must to used,
evaluation be are holdblocks by
a
comnputed as
folow value, e then
the
given the a=b+c
=c+d+6 e
from
=c+d+b=c+b+d=a+ e=t+bt=c+ d following
all based the values by
importance
previous value only DAGsot9d associative
on of
DAGS
code:
the after
assigned
rocedure ordercomputing when and
node
of
must basic eools commutative
and Optimization
Code
calls
ctions.bs be the blocks the
or either value wo-sb12l order d
indirect snorioe law
from of are
its reconstructed of the
gnments its
children. instructions
woll-sisd code
previous
2ino beeh 401

You might also like