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.

320: MOV #340, *SP<br />

330: GOTO 200<br />

340: SUB # c_size, SP<br />

350: action 5<br />

360: ADD # C_Size_SP<br />

370: MOV # 390, * SP<br />

380: GOTO 300<br />

390: SUB # C_Size_SP<br />

400: Action 6<br />

410: ADD # C_Size_SP<br />

420: MOV # 440, * SP<br />

430: GOTO 300<br />

440: SUB # C_Size_SP<br />

450: GOTO *0(SP)<br />

600: Stack Starts here<br />

<strong>Code</strong> Optimization<br />

<strong>Code</strong> Optimization <strong>phase</strong> in mainly use to optimize the code for better utilization of memory and<br />

reduce the time taken for execution. <strong>Code</strong> optimization takes input from intermediate code <strong>generator</strong><br />

and performs machine independent optimization. <strong>Code</strong> optimizer may also take input from code<br />

<strong>generator</strong> and perform machine dependent code optimization. Compilers that use code optimization<br />

transformations are called as optimizing compilers. <strong>Code</strong> optimization does not consider target<br />

machine properties for optimization (like register allocation and memory management) if input is<br />

from intermediate code <strong>generator</strong>.<br />

<strong>Code</strong> optimization tries to optimize that part of the code which are executed more number of times,<br />

like statements within flow control block of for statement and while statement. This is because the<br />

most programs always spend maximum execution time on executing only few statements <strong>Code</strong><br />

optimization analysis programs in two levels control flow analysis and data flow analysis. In control<br />

flow analysis code optimization concentrates more on improving the code of inner loops than outer<br />

statements, as inner loops are executed more number of times than outer ones. A detailed data flow<br />

analysis is required for debugging the optimized code. Data flow analysis collects the information of<br />

statistics about statements being executed more number of times. This information is used in the<br />

process if optimization. <strong>Code</strong> optimization should be such that best results crop up with minimum<br />

effort.<br />

8

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

Saved successfully!

Ooh no, something went wrong!