Compiler Construction: Code Optimizations - Dead Code Elimination - Prof. Rajiv Gupta, Study notes of Computer Science

Code optimizations in compiler construction, specifically dead code elimination. Dead code refers to code that is never executed or whose result is never used. Techniques such as partial dead code elimination, dead code examples, code motion, and second order effects. It also explains how to perform dead and faint variable analysis to identify and eliminate dead and faint code.

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-yn5
koofers-user-yn5 🇺🇸

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
4/13/09
1
1
CS 201
Compiler Construction
Lecture 8
Code Optimizations:
Partial Dead Code Elimination
Dead Code Elimination
Dead Code is code that is either never executed or,
if it is executed, its result is never used by the
program. Therefore dead code can be eliminated
from the program.
2
dead
code
dead
code
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Compiler Construction: Code Optimizations - Dead Code Elimination - Prof. Rajiv Gupta and more Study notes Computer Science in PDF only on Docsity!

1

CS 201

Compiler Construction

Lecture 8

Code Optimizations:

Partial Dead Code Elimination

Dead Code Elimination

Dead Code is code that is either never executed or, if it is executed, its result is never used by the program. Therefore dead code can be eliminated from the program. 2 dead code dead code

Dead Code: More Examples

3

Values used only by dead statements.

Partially Dead Code

Value computed by partially dead statement

is sometimes used and sometimes not used.

4

Removal of Code From Loops

7 = x = x

Critical Edges

8

= X X =

X =

Second Order Effects

9 a=c+d cannot be moved till x=a+b is moved

Algorithm

Repeat

Perform dead/faint variable analysis to

identify sinking candidates

Perform delayability analysis for

sinking candidates

Place statements in new positions

Until Program Stabilizes

10

Dead Variable Analysis

Bit vector analysis for all variables.

13

Faint Variable Analysis

Not bit vector analysis.

14

Analysis of Equation

15 N-FAINTS(x) is false if any of the following conditions is true:

  1. the statement s uses x and s cannot ever be marked faint, i.e.
  2. the statement s does not modify x and x is not faint on exit, i.e.
  3. x is used by statement s and lhs of s is not faint, i.e.

Elimination

Following dead/faint variable analysis we can eliminate dead/faint code  Eliminate n: x= .. assignment x = .. If x is dead/faint at exit of n. The above elimination rule eliminates fully dead/faint code. To eliminate partially dead code, we develop delayability analysis  using this analysis partially dead statement is moved to program points where it is fully dead or fully live. Iterative application of dead/faint code elimination and delaying partially dead assignments leads to optimization. 16

Contd..

19 Placing at its new positions. If N-INSERTn( )/X-INSERTn( ) is true then place at n’s entry/exit point. Essentially we are moving to the latest points to which it can be delayed.