0% found this document useful (0 votes)
7 views9 pages

Optimization of Basic Blocks

The document discusses optimization techniques for basic blocks in code, focusing on local optimizations such as eliminating common subexpressions and dead code. It explains the construction and representation of Directed Acyclic Graphs (DAGs) for basic blocks, detailing how to identify and eliminate redundancies. Additionally, it covers the use of algebraic identities and constant folding to improve code efficiency and the reassembly of basic blocks from DAGs after optimization.
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)
7 views9 pages

Optimization of Basic Blocks

The document discusses optimization techniques for basic blocks in code, focusing on local optimizations such as eliminating common subexpressions and dead code. It explains the construction and representation of Directed Acyclic Graphs (DAGs) for basic blocks, detailing how to identify and eliminate redundancies. Additionally, it covers the use of algebraic identities and constant folding to improve code efficiency and the reassembly of basic blocks from DAGs after optimization.
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
You are on page 1/ 9

6Dtinitation Basic lpcks.

kle Can of ten Obtain a Substahtial improrement


in the Tunning Hme of Code merey by Peoformiry
local optmi tatton klictin each basie Biech by ittesy- d
* The DAG Representaton D Basic Bloch
* Anding Local Common Subexpressions
Dead code ELominatt on
* The use f Ale braic THenttHes
a Repyesen tation Referentes
Pointer Assignment andotedu Te Cals
x Re. assenbln Basic Blocks from DA 9
The AG
D Repretntation o Basic Blo chr
-Local optimitaton begin ansfovming
basic blocy into DAG.
kle Co nslruut a DAg for bagic bloch as
follows :
1. The re mode cù a DAY tor each of the.
tnitt a ratues of the Variabies ppearing in the blotfs.
. There 2 node a ssociated rlits pach s tatemen
the blok. The Childen taose
nades comespondin to Statemnen s tiat ase la

defini tion Prior to & of the Gperand used ys


3. Node is labelel by the applied a
Sand also attachad bo
for hith tast deginitton
o Certain nodes
designated Qutput noder
These te mod es Ohose Variableu lire on
erit föom te bloch.

ex! .
a6+c

bd

e
bo Co

-a

bo C
The DAG DepPresentaton bsic bloch lets y
pefom Sereral Code imprening transformattons
On tPre. code repesented by Ihe basie dof.
Elimnate Local Comron bub expeslon.
Eliminate. dead ode
e Rerder Btatement kiat do not depend
One ano ter

algebaai'c laws to reordes oferands

Finding kocal CommOn Sabexpresslon:


Commnon Subexpressions Can be detected by
node M is about to be added
no ticing as new

xlhettreta there s an node N klith the

Same chitdsen in tre Sane 0rday and klith tie


Same opera lor
Computee Ihe Bame, Ualue
M and may be used n the place Tis tahniquu
las inerod aled the Value metho
deteckt ing
ng Cam mon Bub expremon

dz.a-d
în abore. example are Common

Sub epression. So e Can emore One Statemnn


The blocs then becomes,

da-d

both b and d are Live.


I'en a fou sth Btatement must be.
the ralue fom Orre to anotber

Dead Code Eliminatton


kle detete -fRom DA
Cnode hit no anies to s) aat has no hve
Variables atached..
Repeated applitatrog tais brans formas
hrll remo re foom the Dag
DA that
corrspnds to dead tad
Ex:

la

bo Co
do
In abo re example and are t e .
C and nle Can

i mediateiy remored 00t labeleo e Vhen


Then the Mode labeled C becomes a

and Can be remore The 900t Labeled a and6


remacn i Sine each have live Variable

atfached

bo Co

The Use o4 Atzeboaic Ldentiier


- Represent another important class of
ptini taken basic blo h.
arithmetc identtties, Such a

eliminate Computaton from basic bla.


gAnother class algebre'e peimizatong
includes local s2ductt on in Strengh.
replace nq a more
expenire operato by a
cheapet one as
Expensive cheaper

* A tird ciass elated optimi a tion ts


constantt folding. Here. eraluate Constant
expression. a t Compile time and replae the
Constan t epressi on by thei r Value -
ex! x3-14 Cab be eplared by b-2g
constoutt on Proles can help us.
genenal bransfosmatton
assoiadiritu E a s S Y e o b
Commetatte Xy*x
ex: a btC
e =ct dto eebtctd

commorn Sube preisoo


8emoe t anq assigh
e a ttd.
Repre sentalton of Aray Refesenep.
Avray indezing Astruttton! Can be

breated uke ether ope vato -.

Ex'

aT:Y

The pzpes ay to represent array auess n

DAG is follow s-
t. An assi qnment from an Qrray, tihc xag
i's veprese ted by Coeating node iti
oßerator = CJ and tod chi td vern repsesen ttng
the inital -Value of the do in thscdl
the index i. Yariable becomes label o
and
this meus 20 de

to an aray ie aGIy
3. An assignmen t
is vepresented by
CIa and tree childoen representnthi node
an
4. These Vaoable labeting

yo
hhat clittesent L3 that tBe cea tion
node his al CuoDenty Constuted
nodes nhose raue depends On aO

éCDHled

Pointes Assi gn men t and rorcdure.calle.


klhen kle assign indi recty târaugh. a pointe
as in
the assiqn mens

kle do not Know hat


hab Por 9 Point to
- bperalor = must tahe al nodes that a
Carrenty
hich6
asou at ed
is elerant
/it tdenttfa ag agumant
for dead code. ktimminatton
Protedure Calle behave much ihe
libe assignmo
Peinte (f Protedu De. P r's in
VarieGle Call to p bot uses the node klits
attalhed rartable and ille t a t nos,
node

Reassembling Basic Blochs from DAG's


After Che Perfo m Ohatered optimixatta,
Possible Ohile Constueting the DA
by manipulatinq the DAG S e Constrctd
7ecos titute tiree addess iode
we tre
-for te. bastl block fom ohich e bult

the pA4.
The Tules to
4 . The oder instruction must eSpet
nodes in t e LDA G.
2-ASsignment ray.must fellaw
Porerions assignment to o evaluatoos
from the Same an aceording to te oe

these. instuettorn in the onginal bagic

3-Evaluateons of aDay element megt


to the
fo(louo Preriow zignment
Sam a vay
Of Vasiabe ust folae
Doero us Proteduae Catls indirect acsighmet
Deinte
Pro tetu de. Cal o) indi a t
assignment heufh a pointes mus t fallo
ad Prevjouy eraluatton

You might also like