1 / 9

COMPILERS IR Optimisations

COMPILERS IR Optimisations. hussein suleman uct csc3005h 2006. 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 Folding.

mura
Download Presentation

COMPILERS IR Optimisations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMPILERSIR Optimisations hussein suleman uct csc3005h 2006

  2. 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

  3. Constant Folding • Convert calculations that result in a constant value into a pre-calculated constant. BINOP (PLUS, CONST 1, CONST 2) CONST 3

  4. Constant Propagation • Convert uses of a constant’s name to its value. a = 5; b = a; c = b; a = 5; b = 5; c = 5;

  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)

  6. Inlining • Replace subprogram calls with the body of each subprogram. sub incr { return $_+1; } c = incr(a) + incr(b); c = a+1 + b + 1;

  7. 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;

  8. 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;

  9. Strength Reduction • Convert multiplications within a loop into (possibly faster) additions. basically … for ( int i=0; i<10; i++ ) { print i*5; } for (int i=0; i<50; i+=5 ) { print i; }

More Related