Docsity

Optimizing IR: Peephole, Global, Modular, Constant Folding, Propagation, Unreachable Code , Slides of Compilers

Partial preview of the text

Download Optimizing IR: Peephole, Global, Modular, Constant Folding, Propagation, Unreachable Code and more Slides Compilers in PDF only on Docsity!

COMPILERS

IR Optimisations

Types of Optimisations

 Peephole Optimisation

 (^) Considers only a restricted subset of the IR tree

 Global Optimisation

 (^) Considers the entire program

 Modular Optimisation

 (^) Considers each module in its entirety

Constant Propagation

 Convert uses of a constant’s name to its

value.

a = 5; b = a; c = b;

a = 5; b = 5; c = 5;

Unreachable Code Elimination

 Remove code that will never be executed

because of the logic of the program.

SEQ (SEQ (CJUMP (LT, CONST 1, CONST 2,

LABEL T, LABEL F), LABEL F), MOVE (TEMP

a, TEMP b))

JUMP (NAME T)

Loop Unrolling

 (^) Convert short loops with a constant number of

iterations into multiple static statements.

for ( int i=0; i<=2; i++ ) { a[i] = 0; }

a[0] = 0; a[1] = 0; a[2] = 0;

Common Subexpression Elimination

 Eliminate identical sub-expressions that

are calculated multiple times.

a = b + c * d; e = b + c * d;

x = b + c * d; a = x; e = x;