Top Banner
CS738: Advanced Compiler Optimizations Foundations of Data Flow Analysis Amey Karkare [email protected] http://www.cse.iitk.ac.in/~karkare/cs738 Department of CSE, IIT Kanpur
128

Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Jun 05, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

CS738: Advanced Compiler Optimizations

Foundations of Data Flow Analysis

Amey Karkare

[email protected]

http://www.cse.iitk.ac.in/~karkare/cs738

Department of CSE, IIT Kanpur

Page 2: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Agenda

◮ Intraprocedural Data Flow Analysis◮ We looked at 4 classic examples◮ Today: Mathematical foundations

Page 3: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

◮ Categorized along several dimensions

Page 4: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

◮ Categorized along several dimensions◮ the information they are designed to provide

Page 5: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

◮ Categorized along several dimensions◮ the information they are designed to provide◮ the direction of flow

Page 6: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

◮ Categorized along several dimensions◮ the information they are designed to provide◮ the direction of flow◮ confluence operator

Page 7: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

◮ Categorized along several dimensions◮ the information they are designed to provide◮ the direction of flow◮ confluence operator

◮ Four kinds of dataflow problems, distinguished by

Page 8: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

◮ Categorized along several dimensions◮ the information they are designed to provide◮ the direction of flow◮ confluence operator

◮ Four kinds of dataflow problems, distinguished by◮ the operator used for confluence or divergence

Page 9: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

◮ Categorized along several dimensions◮ the information they are designed to provide◮ the direction of flow◮ confluence operator

◮ Four kinds of dataflow problems, distinguished by◮ the operator used for confluence or divergence◮ data flows backward or forward

Page 10: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

Confluence →⋃ ⋂

Direction ↓

Forward

Backward

Page 11: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

Confluence →⋃ ⋂

Direction ↓

Forward R D

Backward

Page 12: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

Confluence →⋃ ⋂

Direction ↓

Forward R D Av E

Backward

Page 13: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

Confluence →⋃ ⋂

Direction ↓

Forward R D Av E

Backward L V

Page 14: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Taxonomy of Dataflow Problems

Confluence →⋃ ⋂

Direction ↓

Forward R D Av E

Backward L V V B E

Page 15: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Why Data Flow Analysis Works?

◮ Suitable initial values and boundary conditions

◮ Suitable domain of values◮ Bounded, Finite

◮ Suitable meet operator

◮ Suitable flow functions◮ monotonic, closed under composition

◮ But what is SUITABLE ?

Page 16: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice Theory

Page 17: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Partially Ordered Sets

◮ Posets

Page 18: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Partially Ordered Sets

◮ Posets

S: a set

Page 19: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Partially Ordered Sets

◮ Posets

S: a set

≤: a relation

Page 20: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Partially Ordered Sets

◮ Posets

S: a set

≤: a relation

(S,≤) is a poset if for x , y , z ∈ S

Page 21: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Partially Ordered Sets

◮ Posets

S: a set

≤: a relation

(S,≤) is a poset if for x , y , z ∈ S◮ x ≤ x (reflexive)

Page 22: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Partially Ordered Sets

◮ Posets

S: a set

≤: a relation

(S,≤) is a poset if for x , y , z ∈ S◮ x ≤ x (reflexive)◮ x ≤ y and y ≤ x ⇒ x = y (antisymmetric)

Page 23: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Partially Ordered Sets

◮ Posets

S: a set

≤: a relation

(S,≤) is a poset if for x , y , z ∈ S◮ x ≤ x (reflexive)◮ x ≤ y and y ≤ x ⇒ x = y (antisymmetric)◮ x ≤ y and y ≤ z ⇒ x ≤ z (transitive)

Page 24: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Chain

◮ Linear Ordering

Page 25: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Chain

◮ Linear Ordering

◮ Poset where every pair of elements is comparable

Page 26: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Chain

◮ Linear Ordering

◮ Poset where every pair of elements is comparable

◮ x1 ≤ x2 ≤ . . . ≤ xk is a chain of length k

Page 27: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Chain

◮ Linear Ordering

◮ Poset where every pair of elements is comparable

◮ x1 ≤ x2 ≤ . . . ≤ xk is a chain of length k

◮ We are interested in chains of finite length

Page 28: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Observation

◮ Any finite nonempty subset of a poset has minimal and

maximal elements

Page 29: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Observation

◮ Any finite nonempty subset of a poset has minimal and

maximal elements

◮ Any finite nonempty chain has unique minimum and

maximum elements

Page 30: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

Page 31: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

◮ x , y , z ∈ S

Page 32: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

◮ x , y , z ∈ S◮ x

∧x = x (idempotent)

Page 33: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

◮ x , y , z ∈ S◮ x

∧x = x (idempotent)

◮ x∧

y = y∧

x (commutative)

Page 34: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

◮ x , y , z ∈ S◮ x

∧x = x (idempotent)

◮ x∧

y = y∧

x (commutative)◮ x

∧(y

∧z) = (x

∧y)

∧z (associative)

Page 35: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

◮ x , y , z ∈ S◮ x

∧x = x (idempotent)

◮ x∧

y = y∧

x (commutative)◮ x

∧(y

∧z) = (x

∧y)

∧z (associative)

◮ Partial order for semilattice

Page 36: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

◮ x , y , z ∈ S◮ x

∧x = x (idempotent)

◮ x∧

y = y∧

x (commutative)◮ x

∧(y

∧z) = (x

∧y)

∧z (associative)

◮ Partial order for semilattice◮ x ≤ y if and only if x

∧y = x

Page 37: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semilattice

◮ Set S and meet∧

◮ x , y , z ∈ S◮ x

∧x = x (idempotent)

◮ x∧

y = y∧

x (commutative)◮ x

∧(y

∧z) = (x

∧y)

∧z (associative)

◮ Partial order for semilattice◮ x ≤ y if and only if x

∧y = x

◮ Reflexive, antisymmetric, transitive

Page 38: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Border Elements

◮ Top Element (⊤)

Page 39: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Border Elements

◮ Top Element (⊤)◮ ∀x ∈ S, x

∧⊤ = ⊤

∧x = x

Page 40: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Border Elements

◮ Top Element (⊤)◮ ∀x ∈ S, x

∧⊤ = ⊤

∧x = x

◮ (Optional) Bottom Element (⊥)

Page 41: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Border Elements

◮ Top Element (⊤)◮ ∀x ∈ S, x

∧⊤ = ⊤

∧x = x

◮ (Optional) Bottom Element (⊥)◮ ∀x ∈ S, x

∧⊥ = ⊥

∧x = ⊥

Page 42: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

Page 43: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∩

Page 44: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∩

◮ Partial Order is ⊆

Page 45: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∩

◮ Partial Order is ⊆

◮ Top element is S

Page 46: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∩

◮ Partial Order is ⊆

◮ Top element is S

◮ Bottom element is ∅

Page 47: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

Page 48: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∪

Page 49: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∪

◮ Partial Order is ⊇

Page 50: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∪

◮ Partial Order is ⊇

◮ Top element is ∅

Page 51: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Familiar (Semi)Lattices

◮ Powerset for a set S, 2S

◮ Meet∧

is ∪

◮ Partial Order is ⊇

◮ Top element is ∅

◮ Bottom element is S

Page 52: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Greatest Lower Bound (glb)

◮ x , y , z ∈ S

Page 53: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Greatest Lower Bound (glb)

◮ x , y , z ∈ S

◮ glb of x and y is an element g such that

Page 54: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Greatest Lower Bound (glb)

◮ x , y , z ∈ S

◮ glb of x and y is an element g such that◮ g ≤ x

Page 55: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Greatest Lower Bound (glb)

◮ x , y , z ∈ S

◮ glb of x and y is an element g such that◮ g ≤ x◮ g ≤ y

Page 56: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Greatest Lower Bound (glb)

◮ x , y , z ∈ S

◮ glb of x and y is an element g such that◮ g ≤ x◮ g ≤ y◮ if z ≤ x and z ≤ y then z ≤ g

Page 57: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

QQ

◮ x , y ∈ S

Page 58: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

QQ

◮ x , y ∈ S

◮ (S,∧) is a semilattice

Page 59: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

QQ

◮ x , y ∈ S

◮ (S,∧) is a semilattice

◮ Prove that x∧

y is glb of x and y .

Page 60: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semi(?)-Lattice

◮ We can define symmetric concepts

Page 61: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semi(?)-Lattice

◮ We can define symmetric concepts◮ ≥ order

Page 62: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semi(?)-Lattice

◮ We can define symmetric concepts◮ ≥ order◮ Join operation (

∨)

Page 63: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Semi(?)-Lattice

◮ We can define symmetric concepts◮ ≥ order◮ Join operation (

∨)

◮ Least upper bound (lub)

Page 64: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ (S,∧,∨) is a lattice

Page 65: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ (S,∧,∨) is a lattice

iff for each non-empty finite subset Y of S

Page 66: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ (S,∧,∨) is a lattice

iff for each non-empty finite subset Y of S

both∧

Y and∨

Y are in S.

Page 67: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ (S,∧,∨) is a lattice

iff for each non-empty finite subset Y of S

both∧

Y and∨

Y are in S.

◮ (S,∧,∨) is a complete lattice

Page 68: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ (S,∧,∨) is a lattice

iff for each non-empty finite subset Y of S

both∧

Y and∨

Y are in S.

◮ (S,∧,∨) is a complete lattice

iff for each subset Y of S

Page 69: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ (S,∧,∨) is a lattice

iff for each non-empty finite subset Y of S

both∧

Y and∨

Y are in S.

◮ (S,∧,∨) is a complete lattice

iff for each subset Y of S

both∧

Y and∨

Y are in S.

Page 70: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ Complete lattice (S,∧,∨)

Page 71: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ Complete lattice (S,∧,∨)

◮ For every pair of elements x and y , both x∧

y and x∨

y

should be in S

Page 72: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ Complete lattice (S,∧,∨)

◮ For every pair of elements x and y , both x∧

y and x∨

y

should be in S◮ Example : Powerset lattice

Page 73: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ Complete lattice (S,∧,∨)

◮ For every pair of elements x and y , both x∧

y and x∨

y

should be in S◮ Example : Powerset lattice

◮ We will talk about meet semi-lattices only

Page 74: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice

◮ Complete lattice (S,∧,∨)

◮ For every pair of elements x and y , both x∧

y and x∨

y

should be in S◮ Example : Powerset lattice

◮ We will talk about meet semi-lattices only◮ except for some proofs

Page 75: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice Diagram

◮ Graphical view of posets

Page 76: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice Diagram

◮ Graphical view of posets

◮ Elements = the nodes in the graph

Page 77: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice Diagram

◮ Graphical view of posets

◮ Elements = the nodes in the graph

◮ If x < y then x is depicted lower than y in the diagram

Page 78: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice Diagram

◮ Graphical view of posets

◮ Elements = the nodes in the graph

◮ If x < y then x is depicted lower than y in the diagram

◮ An edge between x and y (x lower than y ) implies x < y

and no other element z exists s.t. x < z < y (i.e.

transitivity is excluded)

Page 79: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice Diagram

{c}

{b}

{a}{b, c}

{a, b}

{c, a}

{a, b, c}

Lattice Diagram for ({a, b, c},∩)

Page 80: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Lattice Diagram

{c}

{b}

{a}{b, c}

{a, b}

{c, a}

{a, b, c}

Lattice Diagram for ({a, b, c},∩)

x∧

y = the highest z for which there are paths downward from

both x and y .

Page 81: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

What if there is a large number of elements?

◮ Combine simple lattices to build a complex one

Page 82: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

What if there is a large number of elements?

◮ Combine simple lattices to build a complex one

◮ Superset lattices for singletons

∅ ∅ ∅

{a} {b} {c}

Page 83: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

What if there is a large number of elements?

◮ Combine simple lattices to build a complex one

◮ Superset lattices for singletons

∅ ∅ ∅

{a} {b} {c}

◮ Combine to form superset lattice for multi-element sets

Page 84: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

Page 85: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)

Page 86: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)For (a1,a2) and (b1,b2) ∈ S

Page 87: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)For (a1,a2) and (b1,b2) ∈ S

(a1, a2)∧(b1, b2) = (a1

∧1 b1, a2

∧2 b2)

Page 88: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)For (a1,a2) and (b1,b2) ∈ S

(a1, a2)∧(b1, b2) = (a1

∧1 b1, a2

∧2 b2)

(a1, a2) ≤ (b1, b2) iff a1 ≤1 b1 and a2 ≤2 b2

Page 89: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)For (a1,a2) and (b1,b2) ∈ S

(a1, a2)∧(b1, b2) = (a1

∧1 b1, a2

∧2 b2)

(a1, a2) ≤ (b1, b2) iff a1 ≤1 b1 and a2 ≤2 b2

≤ relation follows from∧

Page 90: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)For (a1,a2) and (b1,b2) ∈ S

(a1, a2)∧(b1, b2) = (a1

∧1 b1, a2

∧2 b2)

(a1, a2) ≤ (b1, b2) iff a1 ≤1 b1 and a2 ≤2 b2

≤ relation follows from∧

◮ Product of lattices is associative

Page 91: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)For (a1,a2) and (b1,b2) ∈ S

(a1, a2)∧(b1, b2) = (a1

∧1 b1, a2

∧2 b2)

(a1, a2) ≤ (b1, b2) iff a1 ≤1 b1 and a2 ≤2 b2

≤ relation follows from∧

◮ Product of lattices is associative

◮ Can be generalized to product of N > 2 lattices

Page 92: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice

◮ (S,∧) is product lattice of (S1,

∧1) and (S2,

∧2) when

S = S1 × S2 (domain)For (a1,a2) and (b1,b2) ∈ S

(a1, a2)∧(b1, b2) = (a1

∧1 b1, a2

∧2 b2)

(a1, a2) ≤ (b1, b2) iff a1 ≤1 b1 and a2 ≤2 b2

≤ relation follows from∧

◮ Product of lattices is associative

◮ Can be generalized to product of N > 2 lattices

◮ (S1,∧

1), (S2,∧

2), . . . are called component lattices

Page 93: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice: Example

∅ ∅ ∅

{a} {b} {c}

× ×

Page 94: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Product Lattice: Example

∅ ∅ ∅

{a} {b} {c}

× × =

{c}

{b}

{a}{b, c}

{a, b}

{c, a}

{a, b, c}

Page 95: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Height of a Semilattice

◮ Length of a chain x1 ≤ x2 ≤ . . . ≤ xk is k

Page 96: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Height of a Semilattice

◮ Length of a chain x1 ≤ x2 ≤ . . . ≤ xk is k

◮ Let K = max over lengths of all the chains in a semilattice

Page 97: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Height of a Semilattice

◮ Length of a chain x1 ≤ x2 ≤ . . . ≤ xk is k

◮ Let K = max over lengths of all the chains in a semilattice

◮ Height of the semilattice = K − 1

Page 98: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Data Flow Analysis Framework

◮ (D,S,

∧,F )

Page 99: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Data Flow Analysis Framework

◮ (D,S,

∧,F )

◮ D: direction – Forward or Backward

Page 100: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Data Flow Analysis Framework

◮ (D,S,

∧,F )

◮ D: direction – Forward or Backward

◮ (S,∧): Semilattice – Domain and meet

Page 101: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Data Flow Analysis Framework

◮ (D,S,

∧,F )

◮ D: direction – Forward or Backward

◮ (S,∧): Semilattice – Domain and meet

◮ F : family of transfer functions of type S → S (see next

slide)

Page 102: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Transfer Functions

◮ F : family of functions S → S. Must Include

Page 103: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Transfer Functions

◮ F : family of functions S → S. Must Include◮ functions suitable for the boundary conditions (constant

transfer functions for Entry and Exit nodes)

Page 104: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Transfer Functions

◮ F : family of functions S → S. Must Include◮ functions suitable for the boundary conditions (constant

transfer functions for Entry and Exit nodes)◮ Identity function I:

I(x) = x ∀x ∈ S

Page 105: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Transfer Functions

◮ F : family of functions S → S. Must Include◮ functions suitable for the boundary conditions (constant

transfer functions for Entry and Exit nodes)◮ Identity function I:

I(x) = x ∀x ∈ S

◮ Closed under composition:

f ,g ∈ F , f ◦ g ⇒ h ∈ F

Page 106: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Monotonic Functions

◮ (S,≤): a poset

Page 107: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Monotonic Functions

◮ (S,≤): a poset

◮ f : S → S is monotonic iff

∀x , y ∈ S x ≤ y ⇒ f (x) ≤ f (y)

Page 108: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Monotonic Functions

◮ (S,≤): a poset

◮ f : S → S is monotonic iff

∀x , y ∈ S x ≤ y ⇒ f (x) ≤ f (y)

◮ Composition preserves monotonicity

Page 109: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Monotonic Functions

◮ (S,≤): a poset

◮ f : S → S is monotonic iff

∀x , y ∈ S x ≤ y ⇒ f (x) ≤ f (y)

◮ Composition preserves monotonicity◮ If f and g are monotonic, h = f ◦ g, then h is also monotonic

Page 110: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Monotone Frameworks

◮ (D,S,∧,F ) is monotone if the family F consists of

monotonic functions only

f ∈ F , ∀x , y ∈ S x ≤ y ⇒ f (x) ≤ f (y)

Page 111: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Monotone Frameworks

◮ (D,S,∧,F ) is monotone if the family F consists of

monotonic functions only

f ∈ F , ∀x , y ∈ S x ≤ y ⇒ f (x) ≤ f (y)

◮ Equivalently

f ∈ F , ∀x , y ∈ S f (x∧

y) ≤ f (x)∧

f (y)

Page 112: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Monotone Frameworks

◮ (D,S,∧,F ) is monotone if the family F consists of

monotonic functions only

f ∈ F , ∀x , y ∈ S x ≤ y ⇒ f (x) ≤ f (y)

◮ Equivalently

f ∈ F , ∀x , y ∈ S f (x∧

y) ≤ f (x)∧

f (y)

◮ Proof? : QQ in class

Page 113: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Knaster-Tarski Fixed Point Theorem

◮ Let f be a monotonic function on a complete lattice(S,

∧,∨). Define

Then,

Page 114: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Knaster-Tarski Fixed Point Theorem

◮ Let f be a monotonic function on a complete lattice(S,

∧,∨). Define

◮ red(f ) = {v | v ∈ S, f (v) ≤ v}, pre fix-points

Then,

Page 115: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Knaster-Tarski Fixed Point Theorem

◮ Let f be a monotonic function on a complete lattice(S,

∧,∨). Define

◮ red(f ) = {v | v ∈ S, f (v) ≤ v}, pre fix-points◮ ext(f ) = {v | v ∈ S, f (v) ≥ v}, post fix-points

Then,

Page 116: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Knaster-Tarski Fixed Point Theorem

◮ Let f be a monotonic function on a complete lattice(S,

∧,∨). Define

◮ red(f ) = {v | v ∈ S, f (v) ≤ v}, pre fix-points◮ ext(f ) = {v | v ∈ S, f (v) ≥ v}, post fix-points◮ fix(f ) = {v | v ∈ S, f (v) = v}, fix-points

Then,

Page 117: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Knaster-Tarski Fixed Point Theorem

◮ Let f be a monotonic function on a complete lattice(S,

∧,∨). Define

◮ red(f ) = {v | v ∈ S, f (v) ≤ v}, pre fix-points◮ ext(f ) = {v | v ∈ S, f (v) ≥ v}, post fix-points◮ fix(f ) = {v | v ∈ S, f (v) = v}, fix-points

Then,◮

∧red(f ) ∈ fix(f ). Further,

∧red(f ) =

∧fix(f )

Page 118: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Knaster-Tarski Fixed Point Theorem

◮ Let f be a monotonic function on a complete lattice(S,

∧,∨). Define

◮ red(f ) = {v | v ∈ S, f (v) ≤ v}, pre fix-points◮ ext(f ) = {v | v ∈ S, f (v) ≥ v}, post fix-points◮ fix(f ) = {v | v ∈ S, f (v) = v}, fix-points

Then,◮

∧red(f ) ∈ fix(f ). Further,

∧red(f ) =

∧fix(f )

◮∨

ext(f ) ∈ fix(f ). Further,∨

ext(f ) =∨

fix(f )

Page 119: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Knaster-Tarski Fixed Point Theorem

◮ Let f be a monotonic function on a complete lattice(S,

∧,∨). Define

◮ red(f ) = {v | v ∈ S, f (v) ≤ v}, pre fix-points◮ ext(f ) = {v | v ∈ S, f (v) ≥ v}, post fix-points◮ fix(f ) = {v | v ∈ S, f (v) = v}, fix-points

Then,◮

∧red(f ) ∈ fix(f ). Further,

∧red(f ) =

∧fix(f )

◮∨

ext(f ) ∈ fix(f ). Further,∨

ext(f ) =∨

fix(f )◮ fix(f ) is a complete lattice

Page 120: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Application of Fixed Point Theorem

◮ f : S → S is a monotonic function

Page 121: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Application of Fixed Point Theorem

◮ f : S → S is a monotonic function

◮ (S,∧) is a finite height semilattice

Page 122: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Application of Fixed Point Theorem

◮ f : S → S is a monotonic function

◮ (S,∧) is a finite height semilattice

◮ ⊤ is the top element of (S,∧)

Page 123: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Application of Fixed Point Theorem

◮ f : S → S is a monotonic function

◮ (S,∧) is a finite height semilattice

◮ ⊤ is the top element of (S,∧)

◮ Notation: f 0(x) = x , f i+1(x) = f (f i(x)), ∀i ≥ 0

Page 124: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Application of Fixed Point Theorem

◮ f : S → S is a monotonic function

◮ (S,∧) is a finite height semilattice

◮ ⊤ is the top element of (S,∧)

◮ Notation: f 0(x) = x , f i+1(x) = f (f i(x)), ∀i ≥ 0

◮ The greatest fixed point of f is

f k (⊤), where f k+1(⊤) = f k (⊤)

Page 125: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Fixed Point Algorithm

// monotonic function f on a meet semilattice

Page 126: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Fixed Point Algorithm

// monotonic function f on a meet semilattice

x := ⊤;

Page 127: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Fixed Point Algorithm

// monotonic function f on a meet semilattice

x := ⊤;while (x 6= f(x)) x := f(x);

Page 128: Foundations of Data Flow Analysis...Why Data Flow Analysis Works? Suitable initial values and boundary conditions Suitable domain of values Bounded, Finite Suitable meet operator Suitable

Fixed Point Algorithm

// monotonic function f on a meet semilattice

x := ⊤;while (x 6= f(x)) x := f(x);

return x;