Download presentation
Presentation is loading. Please wait.
Published byKory Wheeler Modified over 9 years ago
1
Machine-Independent Optimizations Ⅱ CS308 Compiler Theory1
2
Foundations of Data-Flow Analysis CS308 Compiler Theory2
3
Semilattices CS308 Compiler Theory3
4
Semilattices The partial order for a semilattice (V, ∧ ) for all x and y in V, Greatest low bound of domain elements x and y is an element g such that The meet of x and y, g=x ∧ y, is their only greatest lower bound CS308 Compiler Theory4
5
Semilattices Lattice Diagrams for 3 definitions The set of data-flow values is the power set of the definitions, which contains 2 n elements if there are n definitions in the program. CS308 Compiler Theory5
6
Product Lattices for only one definition d, the lattice would have two element: {} and {d} Suppose (A, ∧ A ) and (B, ∧ B ) are lattices, the product lattice is: CS308 Compiler Theory6
7
Transfer Functions Closed under composition –For any two functions f and g in F, h(x)=g(f(x)) is in F Monotone frameworks –A data-flow framework (D, F, V, ∧ ) is monotone if for all x and y in V and f in F, x<=y implies f(x)<=f(y) Distributive frameworks –f(x ∧ y) = f(x) ∧ f(y) for all x and y in V and f in F. CS308 Compiler Theory7
8
The Iterative Algorithm for General Frameworks CS308 Compiler Theory8
9
The Iterative Algorithm for General Frameworks CS308 Compiler Theory9
10
Constant Propagation The set of data-flow values is a product lattice The lattice for a single variable consists of the following: –All constants appropriate for the type of the variable –The value NAC, which stands for not-a-constant. –The value UNDEF, which stands for undefined. CS308 Compiler Theory10 The semilattice for a typical integer- valued variable The semilattice of data-flow values is simply the product of the semilattices like the Figure.
11
Constant Propagation CS308 Compiler Theory11
12
Constant Propagation As long as there exists a path that defines a variable reaching a program point, the variable will not have an UNDEF value. If all the definitions reaching a program point have the same constant value, the variable is considered a constant even though it may not be defined along some program path. CS308 Compiler Theory12
13
Constant Propagation CS308 Compiler Theory13 The values of x are 10 and UNDEF at the exit of B2 and B3, respectively. UNDEF ∧ 10=10 The value of x is 10 on entry to B4. x in B5 can be replaced with10 What about B1-B3-B4-B5? Choosing 10 as the value of x cannot be worse than allowing x to assume random value.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.