Optimization - Machine Independent Code Optimizations Useless Code and Redundant Expression Elimination cs5363 1 Code Optimization Source program

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
cs5363 1 Machine Independent Code Optimizations Useless Code and Redundant Expression Elimination
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 2 Code Optimization The goal of code optimization is to Discover program run-time behavior at compile time Use the information to improve generated code Speed up runtime execution of compiled code Reduce the size of compiled code Correctness (safety) Optimizations must preserve the meaning of the input code Profitability Optimizations must improve code quality Front end Back end optimizer (Mid end) Source program IR IR Target program compiler
Background image of page 2
cs5363 3 Applying Optimizations Most optimizations are separated into two phases Program analysis: discover opportunity and prove safety Program transformation: rewrite code to improve quality The input code may benefit from many optimizations Every optimization acts as a filtering pass that translate one IR into another IR for further optimization Compilers Select a set of optimizations to implement Decide orders of applying implemented optimizations The safety of optimizations depends on results of program analysis Optimizations often interact with each other and need to be combined in specific ways Some optimizations may need to applied multiple times E.g., dead code elimination, redundancy elimination, copy folding Implement predetermined passes of optimizations
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 4 Scalar Compiler Optimizations Machine independent optimizations Enable other transformations Procedure inlining, cloning, loop unrolling Eliminate redundancy Redundant expression elimination Eliminate useless and unreachable code Dead code elimination Specialization and strength reduction Constant propagation, peephole optimization Move operations to less-frequently executed places Loop invariant code motion Machine dependent (scheduling) transformations Take advantage of special hardware features Instruction selection, prefetching Manage or hide latency, introduce parallelism Instruction scheduling, prefetching Manage bounded machine resources Register allocation
Background image of page 4
cs5363 5 Scope Of Optimization Local methods Applicable only to basic blocks Superlocal methods Operate on extended basic blocks (EBB) B1,B2,B3,…,Bm, where Bi is the single predecessor of B(i+1) Regional methods Operate beyond EBBs, e.g. loops, conditionals Global (intraprocedural) methods Operate on entire procedure (subroutine) Whole-program (interprocedural) methods Operate on entire program S0: if i< 50 goto s1 goto s2 s1: t1 := b * 2 a := a + t1 goto s0 S2: …… i :=0 EBB
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs5363 6 Loop Unrolling An enabling transformation to expose opportunities for other optimizations Reduce the number of branches by a factor 4 Provide a bigger basic block (loop body) for local optimization Better instruction scheduling and register allocation do i = 1 to n by 1 a(i) = a(i) + b(i)
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/29/2012 for the course CS 5363 taught by Professor Staff during the Spring '08 term at The University of Texas at San Antonio- San Antonio.

Page1 / 34

Optimization - Machine Independent Code Optimizations Useless Code and Redundant Expression Elimination cs5363 1 Code Optimization Source program

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online