3 COMP 1 5 9 3 Algorithmic Verification Abstract - - PowerPoint PPT Presentation

3 comp 1 5 9 3 algorithmic verification
SMART_READER_LITE
LIVE PREVIEW

3 COMP 1 5 9 3 Algorithmic Verification Abstract - - PowerPoint PPT Presentation

<latexit


slide-1
SLIDE 1

Static Analysis Interval Analysis Data-flow Analysis

COMP 3 9 1 5 3 Algorithmic Verification

<latexit sha1_base64="P4jUJHo6g1yopyZBD74hiv3LdI=">AIZHicjVRb9NIFD6kXEKW6l4QEhoCBalIa4JYJqVcTSF14QRaIFqanQ2D5xRpnYZjxpG6L8Cn7d/oH9EfvEmWPnRgy7juw5/ubMd75zif1Uq8w2m39fqKxcvHT5SvVq7Y9r12/cvLV6+yhLBibAwyDRifnsywy1ivHQKqvxc2pQ9n2Nn/zevtv/dIomU0n80Q5TPOnLKFYdFUhL0JfVyve2j5GKR1b1vqUqsAOD41o7TkI8zqy0WO8orfd8PcAH2826ULGySuoTsfHV2xSjtsVz63fyNeuM9t+/OxiPx38uMxgMmUD6ySkKo6KuFUln76tHVHqnhGqnOdUJRotU/mok7OfqXZLqHbLqSKDGJeJ0ruOqSw/r5xpiJqkMNWMhOW0Skha5STBUMZzeTmKVl0GAaZWxRGX6fzXdQqNPMubgmGEXIgydGeGuqoXqDeH7paiM4bWHNqa8Z5vFikJacWGV9/yGtNWkMq/dJQYZbt9FYgjNMJZO0Yhwvz9+XWerPR5EsG15hrENxHSrlTa0IYQEAhAHxBisGRrkJDR7xg8aEJK2AmMCDNkKd5HGEONzg7IC8lDEtqjZ0RvxwUa07vjzPh0QFE03YZOCnhc+IRkdxjNVxdfzPn+KsaIuZ3GIa1+wdkn1EKX0P86N/H8v+dcTpYUvuRcFOlMGXFZBgsZdWjV9G5Jv3sOyRPJCumUISsgTBOaIy6GoTWvq8u8y3W7Idk/S4Xd6oH3zj+xGeCaVp9ZjIUzeU9YE15rhLqdCal96yI7mrv8op4x50yhJ3Rvu0zBhzqOMyGsLXrH3K9gj1OmVFNdV8gnj+l28Xo8BYJ3cIFdMCKpFm7f5767majRvfyLaT+cVjPjPFz9keJ70IAW2f1p5IwrH5Bnh+5FBX3OVdHq5n6Zz2lxWZ7R0/VYsJ3MacgonoB97lfM/RAcyXkgc7jpzKvfWMoI4ZS7O2SdlnuC8Iw8M54ZzTmNWK/intf5H6JoR9NOxJ0dwgPKuUkdmuXsVM9nmnKlU45mp3WY/OeQJ6oLQtyd6SB7vtaLyvO6WZ7dfM4Rzum5B4/o7dFvlEw8c0SyJUlZyioM+yZFrfMTuSJTeM5mpgbuW+f9/GVbNo62G97zxvMP2+uv3xRfvSrcg4ewQfPyAl7DWziAQwgq/6Ilc2Vp1f+qV6rlXv5K6VC8WZNVi4qvd/AB3w9Tw=</latexit>

Abstract Interpretation and Static Analysis

  • Dr. Liam O’Connor

CSE, UNSW (for now) Term 1 2020

1

slide-2
SLIDE 2

Static Analysis Interval Analysis Data-flow Analysis

Static Analysis

Static analysis is the automatic analysis of code without executing

  • it. It has a variety of applications from security to performance
  • ptimisations.

2

slide-3
SLIDE 3

Static Analysis Interval Analysis Data-flow Analysis

Static Analysis

Static analysis is the automatic analysis of code without executing

  • it. It has a variety of applications from security to performance
  • ptimisations.

Rice’s Theorem Any non-trivial property about the language recognized by a Turing machine is undecidable.

3

slide-4
SLIDE 4

Static Analysis Interval Analysis Data-flow Analysis

Static Analysis

Static analysis is the automatic analysis of code without executing

  • it. It has a variety of applications from security to performance
  • ptimisations.

Rice’s Theorem Any non-trivial property about the language recognized by a Turing machine is undecidable. Our trick: Abstract away from the non-computable or intractable bits by approximating.

4

slide-5
SLIDE 5

Static Analysis Interval Analysis Data-flow Analysis

Static Analysis

Static analysis is the automatic analysis of code without executing

  • it. It has a variety of applications from security to performance
  • ptimisations.

Rice’s Theorem Any non-trivial property about the language recognized by a Turing machine is undecidable. Our trick: Abstract away from the non-computable or intractable bits by approximating. Caution If we overapproximate, we may produce a lot of false positives (spurious errors), but our analysis will be sound.

5

slide-6
SLIDE 6

Static Analysis Interval Analysis Data-flow Analysis

Static Analysis

Static analysis is the automatic analysis of code without executing

  • it. It has a variety of applications from security to performance
  • ptimisations.

Rice’s Theorem Any non-trivial property about the language recognized by a Turing machine is undecidable. Our trick: Abstract away from the non-computable or intractable bits by approximating. Caution If we overapproximate, we may produce a lot of false positives (spurious errors), but our analysis will be sound. If we underapproximate, we may report that the program is fine when it isn’t (false negatives), but our analysis will be complete.

6

slide-7
SLIDE 7

Static Analysis Interval Analysis Data-flow Analysis

Static Analysis

Static analysis is the automatic analysis of code without executing

  • it. It has a variety of applications from security to performance
  • ptimisations.

Rice’s Theorem Any non-trivial property about the language recognized by a Turing machine is undecidable. Our trick: Abstract away from the non-computable or intractable bits by approximating. Caution If we overapproximate, we may produce a lot of false positives (spurious errors), but our analysis will be sound. If we underapproximate, we may report that the program is fine when it isn’t (false negatives), but our analysis will be complete. Most tools aren’t sound nor complete, because they’re a mixture.

7

slide-8
SLIDE 8

Static Analysis Interval Analysis Data-flow Analysis

Math Recap: Lattices

Definition A lattice (L, ) is a set L and a partial order () ⊆ L × L where any set X ⊆ L has both a least upper bound sup X ∈ L and a greatest lower bound inf X ∈ L. We define ⊤ = sup L and ⊥ = inf L

8

slide-9
SLIDE 9

Static Analysis Interval Analysis Data-flow Analysis

Math Recap: Lattices

Definition A lattice (L, ) is a set L and a partial order () ⊆ L × L where any set X ⊆ L has both a least upper bound sup X ∈ L and a greatest lower bound inf X ∈ L. We define ⊤ = sup L and ⊥ = inf L If I define a function f : L → L that is monotone, i.e: x y ⇒ f (x) f (y)

9

slide-10
SLIDE 10

Static Analysis Interval Analysis Data-flow Analysis

Math Recap: Lattices

Definition A lattice (L, ) is a set L and a partial order () ⊆ L × L where any set X ⊆ L has both a least upper bound sup X ∈ L and a greatest lower bound inf X ∈ L. We define ⊤ = sup L and ⊥ = inf L If I define a function f : L → L that is monotone, i.e: x y ⇒ f (x) f (y) I can prove that f has both a least and greatest fixed point, i.e. Least The least fixed point µf of a function f : L → L is the smallest (wrt. ) element x ∈ L such that f (x) = x. Greatest The greatest fixed point νf of a function f : L → L is the largest (wrt. ) element x ∈ L s.t. f (x) = x.

10

slide-11
SLIDE 11

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}.

11

slide-12
SLIDE 12

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m,

12

slide-13
SLIDE 13

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,

13

slide-14
SLIDE 14

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc.

14

slide-15
SLIDE 15

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound.

15

slide-16
SLIDE 16

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u,

16

slide-17
SLIDE 17

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u).

17

slide-18
SLIDE 18

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D.

18

slide-19
SLIDE 19

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D. u is the least upper bound of D, so u f (u).

19

slide-20
SLIDE 20

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D. u is the least upper bound of D, so u f (u). Thus u ∈ D.

20

slide-21
SLIDE 21

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D. u is the least upper bound of D, so u f (u). Thus u ∈ D. By monotonicity, f (u) f (f (u)),

21

slide-22
SLIDE 22

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D. u is the least upper bound of D, so u f (u). Thus u ∈ D. By monotonicity, f (u) f (f (u)), so f (u) ∈ D

22

slide-23
SLIDE 23

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D. u is the least upper bound of D, so u f (u). Thus u ∈ D. By monotonicity, f (u) f (f (u)), so f (u) ∈ D Because u is the least upper bound of D, f (u) ≤ u.

23

slide-24
SLIDE 24

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D. u is the least upper bound of D, so u f (u). Thus u ∈ D. By monotonicity, f (u) f (f (u)), so f (u) ∈ D Because u is the least upper bound of D, f (u) ≤ u. Therefore f (u) = u, i.e. u is a fixed point.

24

slide-25
SLIDE 25

Static Analysis Interval Analysis Data-flow Analysis

Knaster-Tarski Theorem

Let’s prove it for greatest fixed points, given a lattice L and a monotone function f : Define D = {x ∈ L | x f (x)}. We know that ∀m. ⊥ m, so we know ⊥ ∈ D,and, by monotonicity, f (⊥) ∈ D, f (f (⊥)) ∈ D etc. Let u = sup D, the least upper bound. Hence for all x ∈ D, x u, and by monotonicity f (x) f (u). Thus x f (x) f (u). So f (u) is also an upper bound of D. u is the least upper bound of D, so u f (u). Thus u ∈ D. By monotonicity, f (u) f (f (u)), so f (u) ∈ D Because u is the least upper bound of D, f (u) ≤ u. Therefore f (u) = u, i.e. u is a fixed point. All fixed points are in D, therefore u is the greatest fixed point.

25

slide-26
SLIDE 26

Static Analysis Interval Analysis Data-flow Analysis

Fixed Point

How do we compute fixed points?

26

slide-27
SLIDE 27

Static Analysis Interval Analysis Data-flow Analysis

Fixed Point

How do we compute fixed points? For finite lattices, we can compute the least fixed point by iterating f from ⊥, and the greatest by iterating from ⊤: Let ι ∈ {⊤, ⊥} depending on which fixed point we want: prev := ι curr := f (prev) while curr = prev do prev := curr curr := f (curr)

  • d

27

slide-28
SLIDE 28

Static Analysis Interval Analysis Data-flow Analysis

Fixed Point

How do we compute fixed points? For finite lattices, we can compute the least fixed point by iterating f from ⊥, and the greatest by iterating from ⊤: Let ι ∈ {⊤, ⊥} depending on which fixed point we want: prev := ι curr := f (prev) while curr = prev do prev := curr curr := f (curr)

  • d

Why does this terminate?

28

slide-29
SLIDE 29

Static Analysis Interval Analysis Data-flow Analysis

Abstract Interpretation

A very common use-case for fixed point computations is in abstract interpretation, a type of static analysis. Key Idea

1

Replace concrete variables with approximate abstractions in an abstract domain, which is a lattice.

29

slide-30
SLIDE 30

Static Analysis Interval Analysis Data-flow Analysis

Abstract Interpretation

A very common use-case for fixed point computations is in abstract interpretation, a type of static analysis. Key Idea

1

Replace concrete variables with approximate abstractions in an abstract domain, which is a lattice.

2

Approximate the program’s semantics using monotonic functions defined over that domain.

30

slide-31
SLIDE 31

Static Analysis Interval Analysis Data-flow Analysis

Abstract Interpretation

A very common use-case for fixed point computations is in abstract interpretation, a type of static analysis. Key Idea

1

Replace concrete variables with approximate abstractions in an abstract domain, which is a lattice.

2

Approximate the program’s semantics using monotonic functions defined over that domain.

3

Compute the least fixed point of these functions.

31

slide-32
SLIDE 32

Static Analysis Interval Analysis Data-flow Analysis

Abstract Interpretation

A very common use-case for fixed point computations is in abstract interpretation, a type of static analysis. Key Idea

1

Replace concrete variables with approximate abstractions in an abstract domain, which is a lattice.

2

Approximate the program’s semantics using monotonic functions defined over that domain.

3

Compute the least fixed point of these functions. We have seen this before. Predicate abstraction is an example of abstract interpretation.

32

slide-33
SLIDE 33

Static Analysis Interval Analysis Data-flow Analysis

The WHILE Language

To make things easier, we will define a simple imperative programming language as follows: A ::= arithmetic expressions B ::= boolean expressions S ::= [x := A]ℓ | [skip]ℓ | S1; S2 | if [B]ℓ then S else S | while [B]ℓ do S Note that we label all statements and conditions (usually with a number). These labelled terms correspond to nodes on the control flow graph.

33

slide-34
SLIDE 34

Static Analysis Interval Analysis Data-flow Analysis

Examples

if [x > 0]1 then [x := 2x + 1]2 else [x := 1 − 4x]3 [x := 8 ÷ x]4

slide-35
SLIDE 35

Static Analysis Interval Analysis Data-flow Analysis

Examples

if [x > 0]1 then [x := 2x + 1]2 else [x := 1 − 4x]3 [x := 8 ÷ x]4 [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4

slide-36
SLIDE 36

Static Analysis Interval Analysis Data-flow Analysis

Examples

if [x > 0]1 then [x := 2x + 1]2 else [x := 1 − 4x]3 [x := 8 ÷ x]4 [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 What abstract domain should we use to detect divide by zero?

36

slide-37
SLIDE 37

Static Analysis Interval Analysis Data-flow Analysis

Intervals

Let’s define intervals n, m as either: ∅, the empty interval, or [n, m] where n, m ∈ Z ∪ {+∞, −∞}.

37

slide-38
SLIDE 38

Static Analysis Interval Analysis Data-flow Analysis

Intervals

Let’s define intervals n, m as either: ∅, the empty interval, or [n, m] where n, m ∈ Z ∪ {+∞, −∞}. We can define interval intersection n ∩ m as the interval where n and m overlap.

38

slide-39
SLIDE 39

Static Analysis Interval Analysis Data-flow Analysis

Intervals

Let’s define intervals n, m as either: ∅, the empty interval, or [n, m] where n, m ∈ Z ∪ {+∞, −∞}. We can define interval intersection n ∩ m as the interval where n and m overlap. Likewise, define union n ∪ m as the smallest interval containing both n and m.

39

slide-40
SLIDE 40

Static Analysis Interval Analysis Data-flow Analysis

Intervals

Let’s define intervals n, m as either: ∅, the empty interval, or [n, m] where n, m ∈ Z ∪ {+∞, −∞}. We can define interval intersection n ∩ m as the interval where n and m overlap. Likewise, define union n ∪ m as the smallest interval containing both n and m. Observation Define inf S = S and sup S = S, then intervals form a lattice: ⊥ = ∅ and ⊤ = [−∞, +∞]. The ordering here is interval inclusion.

40

slide-41
SLIDE 41

Static Analysis Interval Analysis Data-flow Analysis

Intervals

Let’s define intervals n, m as either: ∅, the empty interval, or [n, m] where n, m ∈ Z ∪ {+∞, −∞}. We can define interval intersection n ∩ m as the interval where n and m overlap. Likewise, define union n ∪ m as the smallest interval containing both n and m. Observation Define inf S = S and sup S = S, then intervals form a lattice: ⊥ = ∅ and ⊤ = [−∞, +∞]. The ordering here is interval inclusion. We can “lift” arithmetic operators to the interval level, where they apply to both bounds. Similarly define e.g. ˆ 3 = [3, 3].

41

slide-42
SLIDE 42

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 =

slide-43
SLIDE 43

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

=

slide-44
SLIDE 44

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 =

slide-45
SLIDE 45

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 = x′

1 ∩ [1, +∞]

x′

2

=

slide-46
SLIDE 46

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 = x′

1 ∩ [1, +∞]

x′

2

= ˆ 2 × x2 + ˆ 1 x3 =

slide-47
SLIDE 47

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 = x′

1 ∩ [1, +∞]

x′

2

= ˆ 2 × x2 + ˆ 1 x3 = x′

1 ∩ [−∞, 0]

x′

3

=

slide-48
SLIDE 48

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 = x′

1 ∩ [1, +∞]

x′

2

= ˆ 2 × x2 + ˆ 1 x3 = x′

1 ∩ [−∞, 0]

x′

3

= ˆ 1 − ˆ 4 × x3 x4 =

slide-49
SLIDE 49

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 = x′

1 ∩ [1, +∞]

x′

2

= ˆ 2 × x2 + ˆ 1 x3 = x′

1 ∩ [−∞, 0]

x′

3

= ˆ 1 − ˆ 4 × x3 x4 = x′

2 ∪ x′ 3

x′

4

=

slide-50
SLIDE 50

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 = x′

1 ∩ [1, +∞]

x′

2

= ˆ 2 × x2 + ˆ 1 x3 = x′

1 ∩ [−∞, 0]

x′

3

= ˆ 1 − ˆ 4 × x3 x4 = x′

2 ∪ x′ 3

x′

4

= ˆ 8 ÷ x4

slide-51
SLIDE 51

Static Analysis Interval Analysis Data-flow Analysis

Equation Systems

We define a series of entry interval equations xi, and a series of exit equations x′

i describing the possible values of x before and

after the statement i. [x > 0]1 [x := 2x + 1]2 [x := 1 − 4x]3 [x := 8 ÷ x]4 x1 = [−∞, +∞] x′

1

= x1 x2 = x′

1 ∩ [1, +∞]

x′

2

= ˆ 2 × x2 + ˆ 1 x3 = x′

1 ∩ [−∞, 0]

x′

3

= ˆ 1 − ˆ 4 × x3 x4 = x′

2 ∪ x′ 3

x′

4

= ˆ 8 ÷ x4 Observe that all operations used are monotone. How can we compute what the intervals are? Iterate to the least fixed point !

51

slide-52
SLIDE 52

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] x′

1

= ∅ = x1 x2 = ∅ = x′

1 ∩ [1, +∞]

x′

2

= ∅ = ˆ 2 × x2 + ˆ 1 x3 = ∅ = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = ˆ 1 − ˆ 4 × x3 x4 = ∅ = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

52

slide-53
SLIDE 53

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = x1 x2 = ∅ = x′

1 ∩ [1, +∞]

x′

2

= ∅ = ˆ 2 × x2 + ˆ 1 x3 = ∅ = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = ˆ 1 − ˆ 4 × x3 x4 = ∅ = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

53

slide-54
SLIDE 54

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = x′

1 ∩ [1, +∞]

x′

2

= ∅ = ˆ 2 × x2 + ˆ 1 x3 = ∅ = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = ˆ 1 − ˆ 4 × x3 x4 = ∅ = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

54

slide-55
SLIDE 55

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = [1, +∞] = x′

1 ∩ [1, +∞]

x′

2

= ∅ = ˆ 2 × x2 + ˆ 1 x3 = ∅ = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = ˆ 1 − ˆ 4 × x3 x4 = ∅ = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

55

slide-56
SLIDE 56

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = [1, +∞] = x′

1 ∩ [1, +∞]

x′

2

= ∅ = [3, +∞] = ˆ 2 × x2 + ˆ 1 x3 = ∅ = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = ˆ 1 − ˆ 4 × x3 x4 = ∅ = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

56

slide-57
SLIDE 57

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = [1, +∞] = x′

1 ∩ [1, +∞]

x′

2

= ∅ = [3, +∞] = ˆ 2 × x2 + ˆ 1 x3 = ∅ = [−∞, 0] = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = ˆ 1 − ˆ 4 × x3 x4 = ∅ = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

57

slide-58
SLIDE 58

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = [1, +∞] = x′

1 ∩ [1, +∞]

x′

2

= ∅ = [3, +∞] = ˆ 2 × x2 + ˆ 1 x3 = ∅ = [−∞, 0] = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = [1, +∞] = ˆ 1 − ˆ 4 × x3 x4 = ∅ = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

58

slide-59
SLIDE 59

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = [1, +∞] = x′

1 ∩ [1, +∞]

x′

2

= ∅ = [3, +∞] = ˆ 2 × x2 + ˆ 1 x3 = ∅ = [−∞, 0] = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = [1, +∞] = ˆ 1 − ˆ 4 × x3 x4 = ∅ = [1, +∞] = x′

2 ∪ x′ 3

x′

4

= ∅ = ˆ 8 ÷ x4

59

slide-60
SLIDE 60

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = [1, +∞] = x′

1 ∩ [1, +∞]

x′

2

= ∅ = [3, +∞] = ˆ 2 × x2 + ˆ 1 x3 = ∅ = [−∞, 0] = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = [1, +∞] = ˆ 1 − ˆ 4 × x3 x4 = ∅ = [1, +∞] = x′

2 ∪ x′ 3

x′

4

= ∅ = [0, 8] = ˆ 8 ÷ x4

60

slide-61
SLIDE 61

Static Analysis Interval Analysis Data-flow Analysis

Least Fixed Points for Equation Systems

We start initialising all equations to ⊥, and then iterate until the results stop changing. We can choose the equations in any (fair)

  • rder, and we will always reach a fixed point eventually. Some

ways are faster than others. x1 = ∅ = [−∞, +∞] = [−∞, +∞] x′

1

= ∅ = [−∞, +∞] = x1 x2 = ∅ = [1, +∞] = x′

1 ∩ [1, +∞]

x′

2

= ∅ = [3, +∞] = ˆ 2 × x2 + ˆ 1 x3 = ∅ = [−∞, 0] = x′

1 ∩ [−∞, 0]

x′

3

= ∅ = [1, +∞] = ˆ 1 − ˆ 4 × x3 x4 = ∅ = [1, +∞] = x′

2 ∪ x′ 3

x′

4

= ∅ = [0, 8] = ˆ 8 ÷ x4 Seeing as 0 / ∈ x4, we know divide by zero is impossible.

61

slide-62
SLIDE 62

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] n2 = ∅ = n′

1 ∪ n′ 3

n3 = ∅ = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

62

slide-63
SLIDE 63

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = n′

1 ∪ n′ 3

n3 = ∅ = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

63

slide-64
SLIDE 64

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = n′

1 ∪ n′ 3

n3 = ∅ = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

64

slide-65
SLIDE 65

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

65

slide-66
SLIDE 66

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

66

slide-67
SLIDE 67

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, 2] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

67

slide-68
SLIDE 68

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, 2] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 2] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

68

slide-69
SLIDE 69

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, 2] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 2] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 3] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

69

slide-70
SLIDE 70

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, 2] = [1, 3] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 2] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 3] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

70

slide-71
SLIDE 71

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, 2] = [1, 3] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 2] = [1, 3] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 3] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

71

slide-72
SLIDE 72

Static Analysis Interval Analysis Data-flow Analysis

Slow Convergence

Because the previous example had no loops, all equations converged after one step. Compare to this example: [n := 1]1 while [n < 1000]2 do [n := n + 1]3 [skip]4 Slightly simplified equations for presentation: n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, 2] = [1, 3] = · · · = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 2] = [1, 3] = · · · = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 3] = [2, 4] = · · · = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

This is going to take a long time to converge! (1000 steps)

72

slide-73
SLIDE 73

Static Analysis Interval Analysis Data-flow Analysis

Widening

Our interval abstraction is too detailed, making our loop iterations take ages.

73

slide-74
SLIDE 74

Static Analysis Interval Analysis Data-flow Analysis

Widening

Our interval abstraction is too detailed, making our loop iterations take ages. Solution Let n be the value we are updating and m be the result of the next

  • iteration. Then, we update with n ▽ m instead of m:

∅ ▽ m = m n ▽ ∅ = n [ℓ0, u0] ▽ [ℓ1, u1] = [ if ℓ1 < ℓ0 then − ∞ else ℓ1 , if u1 > u0 then + ∞ else u1] In other words, if we ever try to loosen a bound, we just extrapolate all the way to infinity.

74

slide-75
SLIDE 75

Static Analysis Interval Analysis Data-flow Analysis

Widening

Our interval abstraction is too detailed, making our loop iterations take ages. Solution Let n be the value we are updating and m be the result of the next

  • iteration. Then, we update with n ▽ m instead of m:

∅ ▽ m = m n ▽ ∅ = n [ℓ0, u0] ▽ [ℓ1, u1] = [ if ℓ1 < ℓ0 then − ∞ else ℓ1 , if u1 > u0 then + ∞ else u1] In other words, if we ever try to loosen a bound, we just extrapolate all the way to infinity. This is an overapproximation, but it converges much faster than the normal iterative sequence does.

75

slide-76
SLIDE 76

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] n2 = ∅ = n′

1 ∪ n′ 3

n3 = ∅ = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

76

slide-77
SLIDE 77

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = n′

1 ∪ n′ 3

n3 = ∅ = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

77

slide-78
SLIDE 78

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = n′

1 ∪ n′ 3

n3 = ∅ = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

78

slide-79
SLIDE 79

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = n2 ∩ [−∞, 999] n′

3

= ∅ = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

79

slide-80
SLIDE 80

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

80

slide-81
SLIDE 81

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, +∞] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

81

slide-82
SLIDE 82

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, +∞] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 999] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

82

slide-83
SLIDE 83

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, +∞] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 999] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 1000] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

83

slide-84
SLIDE 84

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, +∞] = [1, 1000] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 999] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 1000] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

84

slide-85
SLIDE 85

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, +∞] = [1, 1000] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 999] = [1, 999] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 1000] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

85

slide-86
SLIDE 86

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, +∞] = [1, 1000] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 999] = [1, 999] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 1000] = [2, 1000] = n3 + 1 n4 = ∅ = n′

3 ∩ [1000, +∞]

86

slide-87
SLIDE 87

Static Analysis Interval Analysis Data-flow Analysis

Loops with Widening

n′

1

= ∅ = [1, 1] = [1, 1] n2 = ∅ = [1, 1] = [1, +∞] = [1, 1000] = n′

1 ∪ n′ 3

n3 = ∅ = [1, 1] = [1, 999] = [1, 999] = n2 ∩ [−∞, 999] n′

3

= ∅ = [2, 2] = [2, 1000] = [2, 1000] = n3 + 1 n4 = ∅ = [1000, 1000] = n′

3 ∩ [1000, +∞]

87

slide-88
SLIDE 88

Static Analysis Interval Analysis Data-flow Analysis

Beyond Interval Anaylsis

Interval analysis is very effective but not very accurate, because it doesn’t express the relationships between variables.

88

slide-89
SLIDE 89

Static Analysis Interval Analysis Data-flow Analysis

Beyond Interval Anaylsis

Interval analysis is very effective but not very accurate, because it doesn’t express the relationships between variables. Predicate abstraction and polyhedral models do better in many cases, but are more complicated.

89

slide-90
SLIDE 90

Static Analysis Interval Analysis Data-flow Analysis

Beyond Interval Anaylsis

Interval analysis is very effective but not very accurate, because it doesn’t express the relationships between variables. Predicate abstraction and polyhedral models do better in many cases, but are more complicated. All are based on the same principle of least-fixed point of a system

  • f equations.

90

slide-91
SLIDE 91

Static Analysis Interval Analysis Data-flow Analysis

Data-flow Analysis

Data-flow analysis is a type of static analysis used extensively in compilers.

91

slide-92
SLIDE 92

Static Analysis Interval Analysis Data-flow Analysis

Data-flow Analysis

Data-flow analysis is a type of static analysis used extensively in compilers. Example Available Expressions Analysis – Compute what expressions must have already been computed (and don’t need to be recomputed).

92

slide-93
SLIDE 93

Static Analysis Interval Analysis Data-flow Analysis

Data-flow Analysis

Data-flow analysis is a type of static analysis used extensively in compilers. Example Available Expressions Analysis – Compute what expressions must have already been computed (and don’t need to be recomputed). Live Variables Analysis – Compute which variables may be read before next being written to (and thus hold important values).

93

slide-94
SLIDE 94

Static Analysis Interval Analysis Data-flow Analysis

Data-flow Analysis

Data-flow analysis is a type of static analysis used extensively in compilers. Example Available Expressions Analysis – Compute what expressions must have already been computed (and don’t need to be recomputed). Live Variables Analysis – Compute which variables may be read before next being written to (and thus hold important values). Data-flow analyses may be forwards or backwards, and may or must.

94

slide-95
SLIDE 95

Static Analysis Interval Analysis Data-flow Analysis

Data-flow Analysis

Data-flow analysis is a type of static analysis used extensively in compilers. Example Available Expressions Analysis – Compute what expressions must have already been computed (and don’t need to be recomputed). Live Variables Analysis – Compute which variables may be read before next being written to (and thus hold important values). Data-flow analyses may be forwards or backwards, and may or must. AEA is a forwards must analysis.

95

slide-96
SLIDE 96

Static Analysis Interval Analysis Data-flow Analysis

Data-flow Analysis

Data-flow analysis is a type of static analysis used extensively in compilers. Example Available Expressions Analysis – Compute what expressions must have already been computed (and don’t need to be recomputed). Live Variables Analysis – Compute which variables may be read before next being written to (and thus hold important values). Data-flow analyses may be forwards or backwards, and may or must. AEA is a forwards must analysis. LVA is a backwards may analysis.

96

slide-97
SLIDE 97

Static Analysis Interval Analysis Data-flow Analysis

Step 1: Gen and Kill

Each location in the CFG has an associated gen set, of generated information, and kill set, of information that is no longer accurate.

97

slide-98
SLIDE 98

Static Analysis Interval Analysis Data-flow Analysis

Step 1: Gen and Kill

Each location in the CFG has an associated gen set, of generated information, and kill set, of information that is no longer accurate. Example (AEA) In AEA, genAE(ℓ) is the expressions evaluated (and not updated) in ℓ and killAE(ℓ) is those expressions updated by ℓ.

98

slide-99
SLIDE 99

Static Analysis Interval Analysis Data-flow Analysis

Step 1: Gen and Kill

Each location in the CFG has an associated gen set, of generated information, and kill set, of information that is no longer accurate. Example (AEA) In AEA, genAE(ℓ) is the expressions evaluated (and not updated) in ℓ and killAE(ℓ) is those expressions updated by ℓ. For example, x := a + b would generate {a + b}, but kill any expression involving x.

99

slide-100
SLIDE 100

Static Analysis Interval Analysis Data-flow Analysis

Step 1: Gen and Kill

Each location in the CFG has an associated gen set, of generated information, and kill set, of information that is no longer accurate. Example (AEA) In AEA, genAE(ℓ) is the expressions evaluated (and not updated) in ℓ and killAE(ℓ) is those expressions updated by ℓ. For example, x := a + b would generate {a + b}, but kill any expression involving x. Note: a := a + 1 would kill a + 1, not generate it. Why? Example (LVA) In LVA

100

slide-101
SLIDE 101

Static Analysis Interval Analysis Data-flow Analysis

Step 1: Gen and Kill

Each location in the CFG has an associated gen set, of generated information, and kill set, of information that is no longer accurate. Example (AEA) In AEA, genAE(ℓ) is the expressions evaluated (and not updated) in ℓ and killAE(ℓ) is those expressions updated by ℓ. For example, x := a + b would generate {a + b}, but kill any expression involving x. Note: a := a + 1 would kill a + 1, not generate it. Why? Example (LVA) In LVA, genLV (ℓ) is the variables read (and not written to) in ℓ and killLV (ℓ) would be the variables written to in ℓ. For example, x := a + b would generate {a, b} and kill {x}.

101

slide-102
SLIDE 102

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1

slide-103
SLIDE 103

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b}

slide-104
SLIDE 104

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2

slide-105
SLIDE 105

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3

slide-106
SLIDE 106

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4

slide-107
SLIDE 107

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅

slide-108
SLIDE 108

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5

slide-109
SLIDE 109

Static Analysis Interval Analysis Data-flow Analysis

Available Expressions Example

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ∅ What to do now? Specify an equation system that relates these, then find the fixed point!

109

slide-110
SLIDE 110

Static Analysis Interval Analysis Data-flow Analysis

Forwards Must Analysis

The set of available expressions as we enter a location ℓ is the intersection of all available expressions from the predecessors to ℓ: AEentry(ℓ) =

if ℓ ∈ ICFG {AEexit(ℓ′) | (ℓ′, ℓ) ∈ δCFG}

  • therwise

110

slide-111
SLIDE 111

Static Analysis Interval Analysis Data-flow Analysis

Forwards Must Analysis

The set of available expressions as we enter a location ℓ is the intersection of all available expressions from the predecessors to ℓ: AEentry(ℓ) =

if ℓ ∈ ICFG {AEexit(ℓ′) | (ℓ′, ℓ) ∈ δCFG}

  • therwise

We choose intersection because we want expressions that are definitely available no matter what route we took to get to ℓ (a must analysis).

111

slide-112
SLIDE 112

Static Analysis Interval Analysis Data-flow Analysis

Forwards Must Analysis

The set of available expressions as we enter a location ℓ is the intersection of all available expressions from the predecessors to ℓ: AEentry(ℓ) =

if ℓ ∈ ICFG {AEexit(ℓ′) | (ℓ′, ℓ) ∈ δCFG}

  • therwise

We choose intersection because we want expressions that are definitely available no matter what route we took to get to ℓ (a must analysis). The set of available expressions as we exit a location ℓ is the set that we entered with, minus anything we kill, plus anything we generate: AEexit(ℓ) = (AEentry(ℓ) \ killAE(ℓ)) ∪ genAE(ℓ)

112

slide-113
SLIDE 113

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅

slide-114
SLIDE 114

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b}

slide-115
SLIDE 115

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1)

slide-116
SLIDE 116

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1) AEentry(2) ∪ {a ∗ b}

slide-117
SLIDE 117

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1) AEentry(2) ∪ {a ∗ b} 3 AEexit(2) ∩ AEexit(5)

slide-118
SLIDE 118

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1) AEentry(2) ∪ {a ∗ b} 3 AEexit(2) ∩ AEexit(5) AEentry(3) ∪ {a + b}

slide-119
SLIDE 119

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1) AEentry(2) ∪ {a ∗ b} 3 AEexit(2) ∩ AEexit(5) AEentry(3) ∪ {a + b} 4 AEexit(3)

slide-120
SLIDE 120

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1) AEentry(2) ∪ {a ∗ b} 3 AEexit(2) ∩ AEexit(5) AEentry(3) ∪ {a + b} 4 AEexit(3) AEentry(4) \ killAE(4)

slide-121
SLIDE 121

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1) AEentry(2) ∪ {a ∗ b} 3 AEexit(2) ∩ AEexit(5) AEentry(3) ∪ {a + b} 4 AEexit(3) AEentry(4) \ killAE(4) 5 AEexit(4)

slide-122
SLIDE 122

Static Analysis Interval Analysis Data-flow Analysis

Example for AEA

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ AEentry(1) ∪ {a + b} 2 AEexit(1) AEentry(2) ∪ {a ∗ b} 3 AEexit(2) ∩ AEexit(5) AEentry(3) ∪ {a + b} 4 AEexit(3) AEentry(4) \ killAE(4) 5 AEexit(4) AEentry(5) ∪ {a + b}

Liam: Compute the LFP on the board 122

slide-123
SLIDE 123

Static Analysis Interval Analysis Data-flow Analysis

Results

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ {a + b} 2 {a + b} {a + b, a ∗ b} 3 {a + b} {a + b} 4 {a + b} ∅ 5 ∅ {a + b}

123

slide-124
SLIDE 124

Static Analysis Interval Analysis Data-flow Analysis

Results

[x := a + b]1 [y := a ∗ b]2 [y > a + b]3 [a := a + 1]4 [x := a + b]5 ℓ genAE killAE 1 {a + b} ∅ 2 {a ∗ b} ∅ 3 {a + b} ∅ 4 ∅ {a + b, a ∗ b, a + 1} 5 {a + b} ℓ AEentry(ℓ) AEexit(ℓ) 1 ∅ {a + b} 2 {a + b} {a + b, a ∗ b} 3 {a + b} {a + b} 4 {a + b} ∅ 5 ∅ {a + b} Note ℓ = 3 can be optimised, as a + b is already computed!

124

slide-125
SLIDE 125

Static Analysis Interval Analysis Data-flow Analysis

Backwards May Analysis

The set of live variables as we exit a location ℓ is the union of live variables from the successors to ℓ: LVexit(ℓ) =

if ℓ ∈ FCFG {LVexit(ℓ′) | (ℓ, ℓ′) ∈ δCFG}

  • therwise

125

slide-126
SLIDE 126

Static Analysis Interval Analysis Data-flow Analysis

Backwards May Analysis

The set of live variables as we exit a location ℓ is the union of live variables from the successors to ℓ: LVexit(ℓ) =

if ℓ ∈ FCFG {LVexit(ℓ′) | (ℓ, ℓ′) ∈ δCFG}

  • therwise

We choose union because we want any variables that might be used in a successor to be marked live in ℓ (a may analysis).

126

slide-127
SLIDE 127

Static Analysis Interval Analysis Data-flow Analysis

Backwards May Analysis

The set of live variables as we exit a location ℓ is the union of live variables from the successors to ℓ: LVexit(ℓ) =

if ℓ ∈ FCFG {LVexit(ℓ′) | (ℓ, ℓ′) ∈ δCFG}

  • therwise

We choose union because we want any variables that might be used in a successor to be marked live in ℓ (a may analysis). The set of live variables as we enter a location ℓ is the set of live variables at the exit, minus anything we kill (write to), plus anything we generate (read from): LVentry(ℓ) = (LVexit(ℓ) \ killLV(ℓ)) ∪ genLV(ℓ)

127

slide-128
SLIDE 128

Static Analysis Interval Analysis Data-flow Analysis

Backwards May Analysis

The set of live variables as we exit a location ℓ is the union of live variables from the successors to ℓ: LVexit(ℓ) =

if ℓ ∈ FCFG {LVexit(ℓ′) | (ℓ, ℓ′) ∈ δCFG}

  • therwise

We choose union because we want any variables that might be used in a successor to be marked live in ℓ (a may analysis). The set of live variables as we enter a location ℓ is the set of live variables at the exit, minus anything we kill (write to), plus anything we generate (read from): LVentry(ℓ) = (LVexit(ℓ) \ killLV(ℓ)) ∪ genLV(ℓ) The entry and exit equations are flipped because this is a backwards analysis.

128

slide-129
SLIDE 129

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1

slide-130
SLIDE 130

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅

slide-131
SLIDE 131

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2

slide-132
SLIDE 132

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a}

slide-133
SLIDE 133

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3

slide-134
SLIDE 134

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4

slide-135
SLIDE 135

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5

slide-136
SLIDE 136

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1

slide-137
SLIDE 137

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a}

slide-138
SLIDE 138

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2

slide-139
SLIDE 139

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a}

slide-140
SLIDE 140

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a} LVentry(3) 3

slide-141
SLIDE 141

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a} LVentry(3) 3 LVexit(3) \ {c} ∪ {b}

slide-142
SLIDE 142

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a} LVentry(3) 3 LVexit(3) \ {c} ∪ {b} LVentry(4) 4

slide-143
SLIDE 143

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a} LVentry(3) 3 LVexit(3) \ {c} ∪ {b} LVentry(4) 4 LVexit(4) \ {a} ∪ {b}

slide-144
SLIDE 144

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a} LVentry(3) 3 LVexit(3) \ {c} ∪ {b} LVentry(4) 4 LVexit(4) \ {a} ∪ {b} LVentry(5) 5

slide-145
SLIDE 145

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a} LVentry(3) 3 LVexit(3) \ {c} ∪ {b} LVentry(4) 4 LVexit(4) \ {a} ∪ {b} LVentry(5) 5 LVexit(5) ∪ {a}

slide-146
SLIDE 146

Static Analysis Interval Analysis Data-flow Analysis

Example for LVA

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 LVexit(1) \ {a} LVentry(2) 2 LVexit(2) \ {b} ∪ {a} LVentry(3) 3 LVexit(3) \ {c} ∪ {b} LVentry(4) 4 LVexit(4) \ {a} ∪ {b} LVentry(5) 5 LVexit(5) ∪ {a} LVentry(2) ∪ LVentry(6)

146

slide-147
SLIDE 147

Static Analysis Interval Analysis Data-flow Analysis

Results

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 ∅ {a} 2 {a} {b} 3 {b} {b, c} 4 {b, c} {a, c} 5 {a, c} {a, c}

147

slide-148
SLIDE 148

Static Analysis Interval Analysis Data-flow Analysis

Results

[a := 0]1 [b := a ∗ 1]2 [c := c + b]3 [a := b ∗ 2]4 [a < 9]5 [return c]6 ℓ genLV killLV 1 ∅ {a} 2 {a} {b} 3 {b} {c} 4 {b} {a} 5 {a} ∅ ℓ LVentry(ℓ) LVexit(ℓ) 1 ∅ {a} 2 {a} {b} 3 {b} {b, c} 4 {b, c} {a, c} 5 {a, c} {a, c} Note: b and a are never simultaneously live!

148

slide-149
SLIDE 149

Static Analysis Interval Analysis Data-flow Analysis

Existence of Solutions

Solutions always exist to our data flow equations. Why? Because (2A, ⊆) (for AEA) and (2Var, ⊆) (for LVA) are both lattices and all our functions are monotone. So the Knaster-Tarski theorem applies.

149

slide-150
SLIDE 150

Static Analysis Interval Analysis Data-flow Analysis

Bibliography

  • F. Neilson: Principles of Program Analysis, Chapters 2 and 4,

Springer 1999

  • P. Cousot, A Tutorial on Abstract Interpretation, VMCAI

2005. Aho, Lam, Sethi, Ullman: Compilers: Principles Techniques and Tools (the Dragon Book), Second Edition.

150