Local Opt Part 1
Local Opt Part 1
Y.N. Srikant
Department of Computer Science Indian Institute of Science Bangalore 560 012
Y.N. Srikant
Local Optimizations
Basic blocks and control ow graphs Local optimizations Building a control ow graph Directed acyclic graphs and value numbering DAGs and value-numbering will be covered in part 2 of the lecture.
Y.N. Srikant
Local Optimizations
Basic blocks are sequences of intermediate code with a single entry and a single exit We consider the quadruple version of intermediate code here, to make the explanations easier Flow graphs show control ow among basic blocks Basic blocks are represented as directed acyclic blocks(DAGs), which are in turn represented using the value-numbering method applied on quadruples Optimizations on basic blocks
Y.N. Srikant
Local Optimizations
Y.N. Srikant
Local Optimizations
Local Optimizations
Local common subexpression elimination Dead code (instructions that compute a value that is never used) elimination Reordering statements that do not depend on one another Reordering computations using algebraic laws The above two optimizations can be applied only on DAG or tree representation
Y.N. Srikant
Local Optimizations
A leader and all statements which follow it upto but not including the next leader (or the end of the procedure), is the basic block corresponding to that leader Any statements, not placed in a block, can never be executed, and may now be removed, if desired
Y.N. Srikant
Local Optimizations
Y.N. Srikant
Local Optimizations
The nodes of the CFG are basic blocks One node is distinguished as the initial node There is a directed edge B 1 B 2, if B2 can immediately follow B1 in some execution sequence; i.e.,
There is a conditional or unconditional jump from the last statement of B1 to the rst statement of B2, or B2 immediately follows B1 in the order of the program, and B1 does not end in an unconditional jump
Y.N. Srikant
Local Optimizations
a count of the number of quadruples in the block a pointer to the leader of the block pointers to the predecessors of the block pointers to the successors of the block
Note that jump statements point to basic blocks and not quadruples so as to make code movement easy
Y.N. Srikant
Local Optimizations
Y.N. Srikant
Local Optimizations