0% found this document useful (0 votes)
39 views10 pages

Local Opt Part 1

1. The document discusses local optimizations that can be performed during compiler design including common subexpression elimination, dead code elimination, and reordering statements. 2. Basic blocks are defined as sequences of code with a single entry and exit, and control flow graphs are used to represent the flow between blocks. 3. Local optimizations like common subexpression elimination and dead code elimination can be applied to the directed acyclic graph (DAG) representation of the control flow graph.

Uploaded by

Dilip TheLip
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views10 pages

Local Opt Part 1

1. The document discusses local optimizations that can be performed during compiler design including common subexpression elimination, dead code elimination, and reordering statements. 2. Basic blocks are defined as sequences of code with a single entry and exit, and control flow graphs are used to represent the flow between blocks. 3. Local optimizations like common subexpression elimination and dead code elimination can be applied to the directed acyclic graph (DAG) representation of the control flow graph.

Uploaded by

Dilip TheLip
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Local Optimizations - Part 1

Y.N. Srikant
Department of Computer Science Indian Institute of Science Bangalore 560 012

NPTEL Course on Compiler Design

Y.N. Srikant

Local Optimizations

Outline of the Lecture

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 and Flow Graphs

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

Example of a Control Flow Graph

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

Algorithm for Partitioning into Basic Blocks

Determine the set of leaders, the rst statements of basic blocks


The rst statement is a leader Any statement which is the target of a conditional or unconditional goto is a leader Any statement which immediately follows a conditional goto is a leader

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

Example of a Control Flow Graph

Y.N. Srikant

Local Optimizations

Control Flow Graph

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

Basic Block Representation

A basic block is represented as a record consisting of


1 2 3 4

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

Example of a Control Flow Graph

Y.N. Srikant

Local Optimizations

You might also like