dead code elimination

12
Compiler Design Dead Code Elimination

Upload: samiul-ehsan

Post on 14-Feb-2017

277 views

Category:

Education


3 download

TRANSCRIPT

Page 1: Dead Code Elimination

Compiler Design Dead Code Elimination

Page 2: Dead Code Elimination

Dead Code Elimination

› Also known as DCE, dead code removal, dead code stripping, or dead code strip.

›  Compiler optimization process to remove code.

Page 3: Dead Code Elimination

What Is Dead Code?!!!› Dead code is one or more than one code

statements, which are:• Code that can never be executed (unreachable code).• Or if executed, their output is never used.• Code that only affects dead variables (written to, but never read

again).

Page 4: Dead Code Elimination

Benefits of Dead Code Elimination

› Two benefits :1.  It shrinks program size.2.  Reduces its running time.

Page 5: Dead Code Elimination

Example of Dead Codeint global;Void function() {

int i;i=1; //dead store//global=1; //dead store//global=2;return;global=3; //unreachable//

}

Page 6: Dead Code Elimination

Dead Code Elimination› The code fragment after dead code elimination.

int global;void function() {

global=2;return;

}

Page 7: Dead Code Elimination

Dead Code Elimination via Preprocessorint main(void) {

int a = 5; int b = 6;

int c; c = a * (b >> 1); if (0) { /* DEBUG */ printf("%d\n", c);

} return c; }

Page 8: Dead Code Elimination

Dynamic Dead Code Elimination› The techniques used to dynamically detect

demand, identify and resolve dependencies, remove conditionally dead code, and recombine the remaining code at load or runtime.

› Remove dead code through dead code elimination at compile time.

› Very rare with languages compiled ahead-of-time.› language implementations doing just-in-time

compilation.

Page 9: Dead Code Elimination

Partially Dead Code› Value computed by partially dead statement is

sometimes used and sometimes not used.

Page 10: Dead Code Elimination

Another Example of Partial Dead Code

Page 11: Dead Code Elimination

REFERENCE› http://

www.tutorialspoint.com/compiler_design/compiler_design_code_optimization.htm

› https://en.wikipedia.org/wiki/Dead_code_elimination› http://www.compileroptimizations.com/category/

dead_code_elimination.htm

Page 12: Dead Code Elimination

THANK YOU