Unformatted text preview:

413CS 701 Fall 2008©Data Flow FrameworksRevisitedRecall that a Data Flow problem ischaracterized as:(a) A Control Flow Graph(b) A Lattice of Data Flow values(c) A Meet operator to join solutions from Predecessors or Successors(d) A Transfer Function Out = fb(In) or In = fb(Out)414CS 701 Fall 2008©Value LatticeThe lattice of values is usually a meetsemilattice defined by:A: a set of valuesT and ⊥ (“top” and “bottom”):distinguished values in the lattice≤: A reflexive partial order relatingvalues in the lattice∧: An associative and commutativemeet operator on lattice values415CS 701 Fall 2008©Lattice AxiomsThe following axioms apply to thelattice defined by A, T, ⊥, ≤ and ∧: a ≤ b ⇔ a ∧ b = a a ∧ a = a (a ∧ b) ≤ a (a ∧ b) ≤ b (a ∧ T) = a (a ∧⊥) = ⊥416CS 701 Fall 2008©Monotone Transfer FunctionTransfer Functions, fb:L → L (where Lis the Data Flow Lattice) are normallyrequired to be monotone.That is x ≤ y ⇒ fb(x) ≤ fb(y).This rule states that a “worse” inputcan’t produce a “better” output.Monotone transfer functions allow usto guarantee that data flow solutionsare stable.If we had fb(T) = ⊥ and fb(⊥)=T,then solutions might oscillatebetween T and ⊥ indefinitely.Since ⊥≤ T, fb(⊥) should be ≤ fb(T).But fb(⊥) = T which is not ≤ fb(T) =⊥. Thus fb isn’t monotone.417CS 701 Fall 2008©Dominators fit the Data FlowFrameworkGiven a set of Basic Blocks, N, wehave:A is 2N (all subsets of Basic Blocks).T is N.⊥ is φ.a ≤ b ≡ a ⊆ b.fZ(in) = In ∪ {Z}∧ is ∩ (set intersection).418CS 701 Fall 2008©The required axioms are satisfied: a ⊆ b ⇔ a ∩ b = a a ∩ a = a (a ∩ b) ⊆ a (a ∩ b) ⊆ b (a ∩ N) = a (a ∩φ) = φAlso fZ is monotone sincea ⊆ b ⇒ a ∪ {Z} ⊆ b ∪ {Z} ⇒fZ(a) ⊆ fZ(b)419CS 701 Fall 2008©Constant PropagationWe can model Constant Propagationas a Data Flow Problem. For eachscalar integer variable, we willdetermine whether it is known tohold a particular constant value at aparticular basic block.The value lattice isT represents a variable holding aconstant, whose value is not yetknown.i represents a variable holding aknown constant value.T⊥..., −2, −1, 0, 1, 2, ...420CS 701 Fall 2008©⊥ represents a variable whose value isnon-constant.This analysis is complicated by thefact that variables interact, so wecan’t just do a series of independentone variable analyses.Instead, the solution lattice willcontain functions (or vectors) thatmap each variable in the program toits constant status (T, ⊥, or someinteger).Let V be the set of all variables in aprogram.421CS 701 Fall 2008©Let t : V → N U {T,⊥}t is the set of all total mappings fromV (the set of variables) to N U {T,⊥}(the lattice of “constant status”values).For example, t1=(T,6,⊥) is a mappingfor three variables (call them A, B andC) into their constant status. t1 saysA is considered a constant, with valueas yet undetermined. B holds thevalue 6, and C is non-constant.We can create a lattice composed of tfunctions:tT(V) = T (∀ V) (tT=(T,T,T, ...)t⊥(V) = ⊥ (∀ V) (t⊥=(⊥,⊥,⊥, ...)422CS 701 Fall 2008©ta≤ tb⇔∀v ta(v) ≤ tb(v)Thus (1,⊥) ≤ (T,3) since 1 ≤ T and ⊥≤ 3.The meet operator ∧ is appliedcomponentwise:ta∧tb = tc where ∀v tc(v) = ta(v) ∧ tb(b)Thus (1,⊥) ∧ (T,3) = (1,⊥) since 1 ∧ T = 1 and ⊥∧ 3 = ⊥.423CS 701 Fall 2008©The lattice axioms hold: ta≤ tb⇔ ta∧ tb = ta (since thisaxiom holds for each component) ta∧ ta = ta (trivially holds) (ta∧ tb) ≤ ta (per variable def of ∧) (ta∧ tb) ≤ tb (per variable def of ∧) (ta∧ tT) = ta (true for allcomponents) (ta∧ t⊥) = t⊥(true for allcomponents)424CS 701 Fall 2008©The Transfer FunctionConstant propagation is a forwardflow problem, so Cout = fb(Cin)Cin is a function, t(v), that mapsvariables to T,⊥, or an integer valuefb(t(v)) is defined as:(1) Initially, let t’(v)=t(v) (∀v)(2) For each assignment statement v = e(w1,w2,...,wn) in b, in order of execution, do: If any t’(wi) = ⊥ ( 1≤i≤n ) Then set t’(v) = ⊥ (strictness) Elsif any t’(wi) = T (1≤i≤n ) Then set t’(v) = T (delay eval of v) Else t’(v) = e(t’(w1),t’(w2),...)(3) Cout = t’(v)425CS 701 Fall 2008©Note that in valid programs, we don’tuse uninitialized variables, sovariables mapped to T should onlyoccur prior to initialization.Initially, all variables are mapped to T,indicating that initially their constantstatus is unknown.426CS 701 Fall 2008©Examplea=1b=2b=a+1b=a+2b=b-1T, T1,21,21,2 1,31,⊥1,⊥1,⊥427CS 701 Fall 2008©Distributive FunctionsFrom the properties of ∧ and f’smonotone property, we can show that f(a∧b) ≤ f(a) ∧ f(b)To see this note that a∧b ≤ a, a∧b ≤ b ⇒f(a∧b) ≤ f(a), f(a∧b) ≤ f(b) (*)Now we can establish that x≤y, x≤z ⇒ x ≤ y∧z (**)To see that (**) holds, note that x≤y ⇒ x∧y = x x≤z ⇒ x∧z = x (y∧z)∧x ≤ y∧z (y∧z)∧x = (y∧z)∧(x∧x) = (y∧x)∧(z∧x) = x∧x = x Thus x ≤ y∧z, establishing (**).428CS 701 Fall 2008©Now substituting f(a∧b) for x, f(a) for y and f(b) for z in (**) andusing (*) we get f(a∧b) ≤ f(a) ∧ f(b).Many Data Flow problems have flowequations that satisfy the distributiveproperty:f(a∧b) = f(a) ∧ f(b)For example, in our formulation ofdominators:Out = fb(In) = In U {b}whereIn =∩ Out(p)p ∈ Pred(b)429CS 701 Fall 2008©In this case, ∧ =∩.Now fb(S1∩S2) = (S1∩S2) U {b}Also, fb(S1)∩fb(S2) = (S1 U {b})∩(S2 U {b}) = (S1∩S2) U {b}So dominators are distributive.430CS 701 Fall 2008©Not all Data Flow Problemsare DistributiveConstant propagation is notdistributive.Consider the following (with variables(x,y,z)):Now f(t)=t’ wheret’(y) = t(y), t’(z) = t(z),t’(x) = if t(y)=⊥ or t(z) = ⊥ then ⊥ elseif t(y)=T or t(z) =T then T else t(y)+t(z)x=y+zt1 = (T,1,3) t2=(T,2,2)431CS 701 Fall 2008©Now f(t1∧t2) = f(T,⊥,⊥) = (⊥,⊥,⊥)f(t1) = (4,1,3)f(t2) = (4,2,2)f(t1)∧f(t2) = (4,⊥,⊥) ≥ (⊥,⊥,⊥)432CS 701 Fall 2008©Why does it Matter if a DataFlow Problem isn’tDistributive?Consider actual program executionpaths from b0 to (say) bk.One path might be b0,bi1,bi2,...,binwhere bin=bk.At bk the Data Flow information wewant isfin(...fi2(fi1(f0(T)))...) ≡ f(b0,b1,...,bin)On a different path to bk,


View Full Document

UW-Madison COMPSCI 701 - Lecture 20 Notes

Download Lecture 20 Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 20 Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 20 Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?