1 / 18

Introduction to Program Optimizations Chapter 11

This chapter provides an overview of program optimizations, including undecidability, optimization criteria, placement of optimizations, and early optimizations. It also covers specific optimization techniques such as constant-folding, scalar replacement of aggregates, algebraic simplification, and value numbering.

Télécharger la présentation

Introduction to Program Optimizations Chapter 11

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. Introduction to Program Optimizations Chapter 11 Mooly Sagiv

  2. Outline • Undecidability of optimizations • Optimization Criteria • Placement of optimizations • Early Optimizations • Constant-Folding • Scalar replacement of aggregates • Algebraic simplification • Value numbering

  3. Undecidability of Optimizations • “Optimization” = More efficient generated code • It is generally undecidable to determine: • If a given optimization always/sometimes leads to improvement on a given program • If a given optimization is applicable • Solutions: • Allow optimizations to slow some programs • Focus on improvements for “reasonable” programs • Apply optimization conservatively

  4. Example: Loop Invariant Code Motion t y/z L1: if … goto L2 … r r + t … goto L1 L2: L1: if … goto L2 … t y/z r r + t … goto L1 L2:

  5. Optimization Criteria • Execution-time • Code space • Data space

  6. Profiling • Instrument the code to measure certain “resource” consumption (profile information) • Optimize the next compile session with profile information

  7. More Dimensions for Data-Flow Analysis • Flow-sensitive • Context-sensitive • May vs. Must

  8. “Important” Optimizations • Loop optimizations • Memory hierarchy optimizations • Global register optimizations • Instruction and data cache • Virtual memory • Interprocedural optimizations (OO programs) • Tail call optimizations (recursive programs)

  9. Importance of Individual Optimizations • Group I: Operate on loops, important for all programs • constant folding • algebraic simplifications and reassociations • global value numbering • sparse conditional constant propagation • common-subexpression elimination, loop-invariant code motions, partial redundency elimination • strength reduction • induction variable elimination • dead code elimination • unreachable code elimination • graph coloring register allocation • software pipelining, loop unrolling, register renaming • branch and basic block scheduling

  10. Importance of Individual Optimizations • Group II: Operate on loops, important for many programs • Local and global copy propagation • leaf-routine optimization • machine idioms and instruction combining • branch optimization and loop inversion (while  repeat) • unnecessary bound-checking elimination • branch predication

  11. Importance of Individual Optimizations • Group III: apply to whole procedures, help other optimizations • procedure integration • tail-call elimination • in-line expansion • shrink wrapping (move/decrease prologue and epilogue) • scalar replacement of aggregates • additional control flow optimizations (straithening, if simplification, unswitching, conditional moves) • Group IV: Decrease code size • code hoisting • tail merging

  12. Order of Optimizations and Repetitions • Transformations are order-dependent • No “Optimal order” • May need to repeat certain transformations

  13. Scalar replacement of array references Data-cache optimizations A HIR Procedure integration … B HIR|MIR Global value numbering … In-line expansion … Interprocedural register allocation … C MIR|LIR D LIR E link-time Textbook Order constant-folding simplifications

  14. Early High Level Optimizations (B) HIR|MIR Procedure integration Tail-call elimination Scalar replacement of aggregates Sparse conditional constant propagation Interprocedural constant propagation Procedure specialization and cloning Sparse conditional constant propagation constant-folding simplifications

  15. MIR|LIR(C) Global value numbering Local and global copy propagation Sparse conditional constant propagation Dead code elimination constant-folding simplifications Common Subexpression Elimination Loop invariant code motion Partial redundency Elimination Dead code elimination code hoisting induction variable strength reduction linear function test replacement induction variable removal bound checking elimination, control flow optimizations

  16. LIR(D) Inline expansion Leaf-routine optimizations Shrink wrapping Machine idioms Tail merging Branch optimization and conditional moves Dead code elimination Software pipelining, … Instruction Scheduling 1 Register allocation Instruction Scheduling 2 Intraprocedural I-cache optimizations Instruction prefetching Data prefertching Branch predication constant-folding simplifications

  17. Link-time optimizations(E) Interprocedural register allocation Aggregation global references Interprcudural I-cache optimizations

  18. Scalar replacement of array references Data-cache optimizations Procedure integration Tail-call elimination Scalar replacement of aggregates Sparse constant propagation Interprocedural constant propagation Procedure specialization and cloning Sparse conditional constant propagation Inline expansion Leaf-routine optimizations Instruction Scheduling 1 Register allocation Instruction Scheduling 2 Intraprocedural I-cache optimizations Instruction prefetching Data prefertching Branch predication Global value numbering Local and global copy propagation Sparse conditional constant propagation Dead code elimination Common Subexpression Elimination Loop invariant code motion Partial redundency Elimination Interprocedural register allocation Interprocedural I-cache optimization

More Related