05.10.2013 Views

1 Code Generation Code generator phase ... - VTU e-Learning

1 Code Generation Code generator phase ... - VTU e-Learning

1 Code Generation Code generator phase ... - VTU e-Learning

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In order to generate more optimized code, <strong>Code</strong> optimization <strong>phase</strong> has to find out number of<br />

variables used, their value set, those expressions which are used many times. It should also perform<br />

some statistical analysis like-part of the code never reached, part of code which will executed many<br />

times, procedures likely to be called. This information helps in adjusting loop structure and procedure<br />

code to minimize execution speed.<br />

Other Methods of Optimizations<br />

Some of the optimization techniques are used to improve the loop statements. These are code motion<br />

and reduction in strength of expression.<br />

<strong>Code</strong> Motion:<br />

Optimization is done for those statements which are executed frequently. Hence the statements whose<br />

values do not change with respect to loop invariants should be removed from the loop.<br />

Example:<br />

a = 1;<br />

while (a! = 10)<br />

{<br />

}<br />

b = x + 100;<br />

a = a + 1 ;<br />

printf(“%d”,a);<br />

In the above example, variable b with in while loop, is independent of loop invariant a and the value<br />

of x do not change inside loop, hence b = x + 100 can be executed before while loop or after while<br />

loop.<br />

b = x + 100;<br />

a = 1;<br />

while (a ! = 0 )<br />

{ a = a + 1;<br />

}<br />

printf (“%d”,a);<br />

Reduce the strength of expression: If the intermediate code consists of multiplication or division, it<br />

can be replaced by addition or subtraction, this reduces the strength of expression.<br />

Example:<br />

while ( i > 10)<br />

{ i = i + 1;<br />

11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!