Early Program Optimizations Chapter 12 - PowerPoint PPT Presentation

About This Presentation
Title:

Early Program Optimizations Chapter 12

Description:

var a:array[lo1..hi1, lo2..hi2] of eltype; i, j: integer; for j :=lo2 ... Removal of type coercions can be done. eps:=1.0 ; while eps 1.0 1.0 do. oldeps := eps; ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 18
Provided by: thoma423
Category:

less

Transcript and Presenter's Notes

Title: Early Program Optimizations Chapter 12


1
Early Program Optimizations Chapter 12
  • Mooly Sagiv

2
Outline
  • Constant Folding
  • Scalar Replacement of Aggregates
  • Algebraic Simplification and Reassociation
  • Value Numbering
  • Basic blocks
  • Procedure based data flow analysis
  • Sparse conditional constant propagation

3
Constant Folding
  • Evaluate expressions with constant value inside
    basic blocks
  • Invoked at all levels
  • Computations need to be conducted according to
    target machine
  • Need to take care of overflow exceptions
  • Very problematic in floating point arithmetic

4
Scalar replacement of aggregates
  • Replace structure elements by scalars
  • Very simple but not common
  • Depends on aliasingMakes other optimizations
    applicable

5
typedef enum APPLE, BANANA, ORANGE
VARIETY typedef enum LONG, ROUND
SHAPE typedef struct fruit
VARIETY variety SHAPE shape
FRUIT
6
char Red red char Yellow
yellow char Orange orange char
color(FRUIT CurrentFruit) switch
(currentFruit-gtvariety) case
APPLE return Red
break case BANANA
return Yellow
break case ORANGE
return Orange main() FRUIT snack
snack.variety APPLE snack.shape ROUND
printf(s\n, color(snack))
char Red red char Yellow
yellow char Orange orange main()
FRUIT snack VARIETY t1 SHAPE t2 COLOR
t3 t1 APPLE t2 ROUND switch (t1)
case APPLE t3 Red
break
case BANANA t3Yellow
break case
ORANGE t3Orange printf(s\n, t3)
7
char Red red char Yellow
yellow char Orange orange main()
FRUIT snack VARIETY t1 SHAPE t2 COLOR
t3 t1 APPLE t2 ROUND switch (t1)
case APPLE t3 Red
break
case BANANA t3Yellow
break case
ORANGE t3Orange printf(s\n, t3)
main() printf(s\n, red)
8
Algebraic Simplification and Reassociations
  • Use algebraic properties of operators in basic
    block
  • Invoked at all levels
  • Convert (HIR, MIR, LIR) in a basic block into a
    tree ? rewrite trees according to rules (in an
    efficient way)
  • Mainly for integer and address arithmetic

9
0/1/false/true Simplification
10
Simplifying Unary Operators
11
Simplifying Shift Operators
12
Strength Reduction in Operators
t?i shl 2 t ? t i
t?i 5
t?i shl 3 t ? t - i
t?i 7
13
Commutativity and Associativity
14
Algebraic Simplifications of Addressing
Expressions
  • Cannot raise overflow
  • Important for array references
  • Use canonizations
  • Integrate with other optimizations

15
var aarraylo1..hi1, lo2..hi2 of eltype
i, j integer ... for j lo2 to
hi2 do ai,j bai, j end

16
Algebraic Simplifications of Floating Point
Expressions
  • Almost always impossible
  • Removal of type coercions can be done

eps1.0 while eps1.0gt1.0 do oldeps
eps eps 0.5eps od
17
Summary
  • Algebraic association and constant folding are
    useful
  • Compiler need to take into account the exact
    semantics
  • Example Floating point
  • IEEE Standards, C, Fortran77, Ada, Java
Write a Comment
User Comments (0)
About PowerShow.com