lecture8

lecture8 - Code Optimization I: Machine Independent...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Code Optimization I: Machine Independent Optimizations Code Optimization I: Machine Independent Optimizations Topics Topics Machine-Independent Optimizations Code motion Reduction in strength Common subexpression sharing Tuning Identifying performance bottlenecks 2 Great Reality Great Reality Theres more to performance than asymptotic Theres more to performance than asymptotic complexity complexity Constant factors matter too! Constant factors matter too! Easily see 10:1 performance range depending on how code is written Must optimize at multiple levels: algorithm, data representations, procedures, and loops Must understand system to optimize performance Must understand system to optimize performance How programs are compiled and executed How to measure program performance and identify bottlenecks How to improve performance without destroying code modularity and generality 3 Optimizing Compilers Optimizing Compilers Provide efficient mapping of program to machine Provide efficient mapping of program to machine register allocation code selection and ordering eliminating minor inefficiencies Dont (usually) improve asymptotic efficiency Dont (usually) improve asymptotic efficiency up to programmer to select best overall algorithm big-O savings are (often) more important than constant factors but constant factors also matter Have difficulty overcoming optimization blockers Have difficulty overcoming optimization blockers potential memory aliasing potential procedure side-effects 4 Limitations of Optimizing Compilers Limitations of Optimizing Compilers Operate Under Fundamental Constraint Operate Under Fundamental Constraint Must not cause any change in program behavior under any possible condition Often prevents it from making optimizations when would only affect behavior under pathological conditions. Behavior that may be obvious to the programmer can be Behavior that may be obvious to the programmer can be obfuscated by languages and coding styles obfuscated by languages and coding styles e.g., data ranges may be more limited than variable types suggest Most analysis is performed only within procedures Most analysis is performed only within procedures whole-program analysis is too expensive in most cases Most analysis is based only on Most analysis is based only on static static information information compiler has difficulty anticipating run-time inputs When in doubt, the compiler must be conservative When in doubt, the compiler must be conservative 5 Machine-Independent Optimizations Machine-Independent Optimizations Optimizations you should do regardless of processor / compiler Code Motion Code Motion Reduce frequency with which computation performed If it will always produce same result Especially moving code out of loop for (i = 0; i < n; i++) for (j = 0; j < n; j++) a[n*i + j] = b[j]; for (i = 0; i < n; i++) { int ni = n*i; for (j = 0; j < n; j++) a[ni + j] = b[j]; } 6...
View Full Document

This note was uploaded on 04/13/2008 for the course CS 211 taught by Professor Chakraborty during the Spring '08 term at Rutgers.

Page1 / 34

lecture8 - Code Optimization I: Machine Independent...

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

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