U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Yet More Data flow analysis John Cavazos University of Delaware
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 2 Overview Additional Data Flow Problem Constant Propagation Generalization of Data Flow
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 3 Constant Propagation Along every path to point p, variable v has same “known” value
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 4 Constant Propagation Specialize computation at p based on v’s value
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 5 Constant Propagation Lattice Lattice is a poset with (V, ≤) V meet (or join) operator ≤ ordering operator … The Lattice of Constant Prop Hasse diagram
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 6 Two Special Elements in Lattice ⊤ (called top) Not a Constant ⊥ (called bottom) Unknown
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 7 Some Lattice Theory Generalized Meet Operator ⊔ Used at “merge” points
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 8 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
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 9 Iterative Data Flow Analysis Initialize non-entry nodes to identify element Identity element for meet function Remember last time: X ⋀ 1 = X
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 10 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
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 11 Top ⊤ versus Bottom ⊥ ⊤ means definitely NOT a constant Inputs are ⊤ ⊥ means Unknown or Undefined Could be constant but we do not know!
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 12 More Lattice Theory: Ordering Op ≤ ordering operator ⊥ ≤ anything ∀ x ⊥ ⊔ x = x anything ≤ ⊤ ∀ x x ⊔ ⊤ = ⊤ ∀ x x ⊔ x = x … The Lattice of Constant Prop
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 13 Relate to Constant Prop?! i and j are integer values i ⊔ i = i i ⊔ j = ⊤ if i ≠ j
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 14 What is X in Block 3?
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 15 What is X in Block 3? x is ⊤
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 16 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
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 17 Constant Prop Example Meet Operator = ⊔ Identity= ? X ⊔ ? = X
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 18 Constant Prop Example Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition?
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 19 Constant Prop Example Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition Boundary Condition? ⊥⊥⊥ XYZ
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 20 Constant Prop Example Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition Boundary Condition ⊥⊥⊥ XYZ
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 21 Constant Prop Example ⊥⊥⊥ out 1 = ??? ⊥⊥ ⊥ XYZ
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 22 Constant Prop Example ⊥⊥⊥ out 1 = 1 ⊥⊥ out 2 = ??? ⊥⊥ ⊥ 1 ⊥⊥ XYZ
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 23 Constant Prop Example ⊥⊥⊥ out 1 = 1 ⊥⊥ out 2 = 023 out 3 = ??? ⊥⊥ ⊥ 1 ⊥⊥ 023 XYZ
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 24 Constant Prop Example ⊥⊥⊥ out 1 = 1 ⊥⊥ out 2 = 023 out 3 = 12 ⊥ out 4 = ??? ⊥⊥ ⊥ 1 ⊥⊥ 023 XYZ 12 ⊥
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 25 Constant Prop Example ⊥⊥⊥ out 1 = 1 ⊥⊥ out 2 = 023 out 3 = 12 ⊥ out 4 = ⊤ 23 ⊥⊥ ⊥ 1 ⊥⊥ 023 XYZ 12 ⊥ ⊤ 23 Does this make sense?
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 26 Next Time Static-Single Assignment (SSA Form) Read Efficiently computing static single assignment form and the control dependence graph, Cytron et al.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 27 Next Time Intelligent Compilation