270 likes | 372 Views
Optimizing Compilers CISC 673 Spring 2011 Yet More Data flow analysis. John Cavazos University of Delaware. Overview. Additional Data Flow Problem Constant Propagation Generalization of Data Flow. Constant Propagation. Along every path to point p, variable v has same “known” value.
E N D
Optimizing CompilersCISC 673Spring 2011Yet More Data flow analysis John Cavazos University of Delaware
Overview • Additional Data Flow Problem • Constant Propagation • Generalization of Data Flow
Constant Propagation • Along every path to point p, variable v has same “known” value
Constant Propagation • Specialize computation at p based on v’s value
… -2 -1 0 1 2 ... The Lattice of Constant Prop Constant Propagation Lattice Hasse diagram • Lattice is a poset with (V, ≤) • V meet (or join) operator • ≤ ordering operator
Two Special Elements in Lattice • ⊤ (called top) • Not a Constant • ⊥ (called bottom) • Unknown
Some Lattice Theory • Generalized Meet Operator ⊔ • Used at “merge” points
Some Lattice Theory (cont’d) • Meet Operator (⊔) for Avail Expressions • Avail Expression (w/ sets): • Avail Expression (w/ Bit Vectors): ⋀ • Produces Least Upper Bound (LUB) • X ⊔ Y = least element Z s.t. • X ≤ Z and Y ≤ Z
Iterative Data Flow Analysis • Initialize non-entry nodes to identify element • Identity element for meet function • Remember last time: X ⋀ 1 = X
Iterative Data Flow Analysis (cont’d) • If node function is monotone: • Each re-evaluation of node moves up the lattice, if it moves at all • If height of lattice is finite, must terminate
Top ⊤ versus Bottom ⊥ • ⊤ means definitely NOT a constant • Inputs are ⊤ • ⊥ means Unknown or Undefined • Could be constant but we do not know!
… -2 -1 0 1 2 ... The Lattice of Constant Prop More Lattice Theory: Ordering Op • ≤ ordering operator • ⊥ ≤ anything • ∀x ⊥ ⊔ x = x • anything ≤ ⊤ • ∀x x ⊔ ⊤= ⊤ • ∀x x ⊔ x = x
Relate to Constant Prop?! • i and j are integer values • i ⊔ i = i • i ⊔ j = ⊤ if i ≠ j
What is X in Block 3? 1. 2. 3.
What is X in Block 3? 1. 2. 3. x is ⊤
Constant Propagation Problem • Variable v has constant value c at point p, iff ∀ paths from entry to p, the most recently assigned value for v is c
Constant Prop Example Meet Operator = ⊔ Identity= ? X ⊔ ? = X
Constant Prop Example Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition?
Constant Prop Example Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition Boundary Condition? XYZ ⊥⊥⊥ ⊥⊥⊥ ⊥⊥⊥ ⊥⊥⊥
Constant Prop Example ⊥⊥⊥ Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition Boundary Condition XYZ 1. ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 4. ⊥⊥⊥
Constant Prop Example ⊥⊥⊥ XYZ out1= ??? 1. ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 4. ⊥⊥⊥
Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= ??? 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 4. ⊥⊥⊥
Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= 023 out3= ??? 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 023 4. ⊥⊥⊥
Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= 023 out3= 12⊥ out4= ??? 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 12⊥ 023 4. ⊥⊥⊥
Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= 023 out3= 12⊥ out4= ⊤23 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ Does this make sense? 12⊥ 023 4. ⊥⊥⊥ ⊤23
Next Time • Static-Single Assignment (SSA Form) • Read Efficiently computing static single assignment form and the control dependence graph, Cytron et al. http://portal.acm.org/citation.cfm?id=115320
Next Time • Intelligent Compilation