Introduction to Program Optimizations Chapter 11 - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Program Optimizations Chapter 11

Description:

Code space. Data space. Profiling. Instrument the code to measure ... dead code elimination. unreachable code elimination. graph coloring register allocation ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 19
Provided by: thoma423
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Program Optimizations Chapter 11


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
Textbook Order
constant-folding simplifications
14
Early High Level Optimizations (B) HIRMIR
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
MIRLIR(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 Interproced
ural constant propagation Procedure
specialization and cloning Sparse conditional
constant propagation
Inline expansion Leaf-routine optimizations Instru
ction 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 Interprocedura
l I-cache optimization
Write a Comment
User Comments (0)
About PowerShow.com