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
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
x = y + z<br />
a = x + 10<br />
p = y + z<br />
b = p + 20<br />
Both x and p computes same sub-expression hence generate code for x only once and p uses value of<br />
x instead of re-computing from x & y.<br />
After intermediate code generation it may so happen that there can be a jump statement whose target<br />
statement is next statement itself. In this case jump statement should be avoided, which reduces code<br />
generating time.<br />
Constant Folding : If the assignment statement consists of only constants to the right hand side of<br />
assignment statement. Then the value of the expression can be pre-computed.<br />
Example: y = 2 * 5 + 6<br />
The value of y can be computed as 16 and stored. Then the three address code generated would by<br />
y=16 instead of<br />
t1 = 2 * 5<br />
t2 = t1 + 6<br />
y = t2<br />
This helps in constant propagation i.e, from the above example if y is used in any other expression,<br />
instead of substituting y = 2 * 5+6 it can be substituted with y = 16.<br />
Example:<br />
y = 2 * 5 + 16<br />
x = y + z<br />
without optimization<br />
x = 2 * 5 + 6 + z<br />
with optimization<br />
y = 16<br />
x = 16 + z<br />
Some of the operations like procedure call are very expensive, especially recursive procedure calls. In<br />
order to reduce this, recursive procedures may be converted to iterative by providing lables. Issues<br />
regarding procedure call it that before transferring the control to procedure. The status of procedure<br />
has to be stored in registers. It has to be restored after procedure returns. Hence increases load and<br />
store instructions.<br />
Predicting program behavior<br />
10