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.

}<br />

t1 = 4 * i;<br />

The statement with in while loop, will be executed until ‘i’ greater than 10. Initially if i = 0, for the<br />

first iteration i = 1 and t1 = 4, for the 2 nd instruction i = 2 and t1 = 4 * 2 = 8<br />

or t1 = 4 * (i + 1)<br />

t1 = 4 * i + 4 (∴ t1 = 4 * i )<br />

t1 = t1 + 4<br />

As the expression for evaluating t1 which requires multiplication is reduced to addition, its execution<br />

is faster.<br />

Local, Global & Inter-Procedural Optimization:<br />

In case of local optimization straight line codes with in basic block are optimized. The basic block<br />

consists of only assignment statements with no jumps or loops. Some of the optimization techniques<br />

that can be used for local optimization are constant folding, constant propagations and algebraic<br />

transformations.<br />

Optimization considering many basic blocks of single procedure is called global optimization. They<br />

use optimization techniques like code motion, elimination of induction variables and reduction in<br />

strength of expression. Global optimization requires data flow analysis to detect jump boundaries<br />

before optimization.<br />

Inter-procedural optimization deals with optimization of entire program as a whole. This is very<br />

difficult to achieve as it has to take care of different parameters passing mechanization and non local<br />

variable access. The advantage of inter procedural optimization is that each procedure can be<br />

optimized independently and linked together at the end with the help of linker which performs<br />

optimization later on.<br />

Machine dependent optimization<br />

Some of the optimizations are machine independent, like register allocation and cost of instruction.<br />

Register Allocation:<br />

Number of times variable in each block of program may vary, but there are fixed number at register in<br />

the system. Hence these registers are to be efficiently used. As far as possible the temporary variable<br />

or intermediate values should be present in register this reduces the load and store to memory.<br />

Example:<br />

x = y + z<br />

a = x + 10<br />

b = x + 20<br />

As the value of x is used after it has been assigned a value. Retain the value of x in the register, to<br />

avoid storing and reloading from memory.<br />

Cost of Instructions:<br />

12

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

Saved successfully!

Ooh no, something went wrong!