dead code elimination
TRANSCRIPT
![Page 1: Dead Code Elimination](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/1.jpg)
Compiler Design Dead Code Elimination
![Page 2: Dead Code Elimination](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/4.jpg)
Benefits of Dead Code Elimination
› Two benefits :1. It shrinks program size.2. Reduces its running time.
![Page 5: Dead Code Elimination](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/6.jpg)
Dead Code Elimination› The code fragment after dead code elimination.
int global;void function() {
global=2;return;
}
![Page 7: Dead Code Elimination](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/9.jpg)
Partially Dead Code› Value computed by partially dead statement is
sometimes used and sometimes not used.
![Page 10: Dead Code Elimination](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/10.jpg)
Another Example of Partial Dead Code
![Page 11: Dead Code Elimination](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022083021/58a3254e1a28ab71398b5753/html5/thumbnails/12.jpg)
THANK YOU