140 likes | 157 Views
Early Optimizations (Chapter 12). Constant-expression evaluation (constant folding), scalar replacement of aggregates, algebraic simplifications and reassociation, value numbering, copy propagation sparse conditional constant propagation
E N D
Constant-expression evaluation (constant folding), • scalar replacement of aggregates, • algebraic simplifications and reassociation, • value numbering, • copy propagation • sparse conditional constant propagation • First three are independent of Data flow analysis and last 3 are dependent of data flow analysis.
Constant-expression evaluation • It refers to the evaluation at compile time of expression whose, operands are known to be constant. • The function returns true if its argument is a constant and false otherwise. • Ex Boolean values.
Scalar replacement of aggregates • Makes other optimizations applicable to components of aggregates, such as C structures. • Use in very less compiler
As in the example, first do scalar replacement on the snack record in main(), • Then the body of procedure color() into the call in main(), • Transform the resulting &snack->variety in the switch stmt into the equivalent snack. • Main() after constant propagation and dead-code elimination for the program.
Algebraic simplifications and reassociation • Use algebraic properties of operators to simplify expressions. • Ex.
Value numbering • It is one of several methods for determining that two computations are equivalent and eliminating one of them.
Copy propagation • It is a transformation that, given an assignment xy for some variables x and y, replaces later uses of x with uses of y, as long as intervening instructions have not changed the value of either x or y
Sparse conditional constant propagation • It is a transformation that, given and assignment xc for a variable x and a constant c, replaces later uses of x with uses of c as long as intervening assignments have not changed the value of x.
Ex b3 in block B1 assigns the constant value 3 to b and no other assignment in the flow graph assigns to b Ex b3 in block B1 assigns the constant value 3 to b and no other assignment in the flowgraph assigns to b