Calculating Graph Algorithms for Dominance and Shortest Path Ilya - - PowerPoint PPT Presentation

calculating graph algorithms for dominance and shortest
SMART_READER_LITE
LIVE PREVIEW

Calculating Graph Algorithms for Dominance and Shortest Path Ilya - - PowerPoint PPT Presentation

Calculating Graph Algorithms for Dominance and Shortest Path Ilya Sergey Jan Midtgaard Dave Clarke MPC 2012 How to derive two graph algorithms by means of Abstract Interpretation ? Abstract Interpretation Abstract Interpretation


slide-1
SLIDE 1

Calculating Graph Algorithms for Dominance and Shortest Path

Ilya Sergey Jan Midtgaard Dave Clarke

MPC 2012

slide-2
SLIDE 2

two graph algorithms How to derive by means of Abstract Interpretation

slide-3
SLIDE 3

?

slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8

Abstract Interpretation

slide-9
SLIDE 9

Abstract Interpretation

(a brief history)

P . Cousot, R. Cousot, Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Construction or Approximation of Fixpoints. POPL’77 P . Cousot, R. Cousot, Systematic Design of Program Analysis Frameworks. POPL’79

... ... ... ... ... ... ... ... ...

slide-10
SLIDE 10

Abstract Interpretation

(a brief list of applications in PL)

  • strictness analysis
  • type system design
  • state reachability
  • control-flow analysis
  • information flow properties
  • static error detection
  • constant propagation
  • escape analysis
  • points-to analysis
  • state reachability
  • model checking
  • data-flow optimizations
  • loop detection
  • CPR analysis
slide-11
SLIDE 11

Abstract Interpretation

(an essence)

Not Interpretation as We Know It

slide-12
SLIDE 12

Abstract Interpretation

(an essence)

  • Partial orders and lattices
  • Monotone functions and fixed points
  • Galois connections
slide-13
SLIDE 13

Partial Orders and Lattices

Complete lattice

hC; v, ?, >, t, ui

Partial order

hC; vi

Least upper bound Greatest lower bound Bottom Top

t u > = tC ? = uC

slide-14
SLIDE 14

Monotone Functions

hC, vi hA, i f : C → A [ x v y = ) f(x)  f(y) ]

slide-15
SLIDE 15

Least Fixed Points

lfpvf = u{x | f(x) v x} f : hC, vi ! hC, vi

slide-16
SLIDE 16

Least Fixed Points

Kleene iteration

? v f(?) v f 2(?) v f 3(?) v . . .

lfpvf = G

n0

f n(⊥)

slide-17
SLIDE 17

Semantics: Interpretation:

hC, vi, f : C ! C f is monotone

lfpvf

slide-18
SLIDE 18

Concrete Interpretation

(an example)*

* P . Cousot, R. Cousot, Basic concepts of abstract interpretation

Partial trace collecting semantics

slide-19
SLIDE 19

Partial trace collecting semantics

System states Transition relation Initial states

t ⊆ Σ × Σ

Σ0 ⊆ Σ

Partial trace

σ = s0s1 . . . sn, si ∈ Σ

s ∈ Σ

slide-20
SLIDE 20

Partial trace collecting semantics

Semantic functional

F : ℘(Σ+) → ℘(Σ+)

F is monotone

F(X) = {s | s 2 Σ0} [ {σss0 | σs 2 X ^ hs, s0i 2 t}

slide-21
SLIDE 21

Partial trace collecting semantics

Lattice

lfp⊆F = [

n≥0

Fn(∅)

Interpretation

h℘(Σ+), ✓, ;, Σ+, [, \i

slide-22
SLIDE 22

Partial trace collecting semantics

(an example)

Σ0 = {s0}

t = {hs0, s1i, hs1, s1i, hs1, s2i}

Σ = {s0, s1, s2}

F0(∅) = ∅ F1(∅) = {s0} F2(∅) = {s0, s0s1} F3(∅) = {s0, s0s1, s0s1s2, s0s1s1} . . . F4(∅) = {s0, s0s1, s0s1s2, s0s1s1, s0s1s1s1, s0s1s1s2}

slide-23
SLIDE 23

is decidable

lfp⊆F

un

slide-24
SLIDE 24

lfp⊆F

α( )

α - property, “abstraction”

is decidable un

lfpv b F

b F is defined byα andF

slide-25
SLIDE 25

α : hC, vi ! hA, i

Abstraction

α is monotone

slide-26
SLIDE 26

Abstraction

hC, vi

hA, i

c1 c2 c3 a1 a2

α α α

slide-27
SLIDE 27

Concretization

γ : hA, i ! hC, vi

γ is monotone

slide-28
SLIDE 28

Concretization

hC, vi

hA, i

c1 c2 c3 a1 a2

γ γ

slide-29
SLIDE 29

Galois Connections

hC, vi

  • !
  • α

γ

hA, i

iff

[ α(c)  a ( ) c v γ(a) ]

slide-30
SLIDE 30

Galois Connection Properties

Compositional construction

hC, vi

  • !
  • α1

γ1

hA1, 1i hA1, 1i

  • !
  • α2

γ2

hA2, 2i hC, vi

  • !
  • α2α1

γ1γ2

hA2, 2i

slide-31
SLIDE 31

Galois Connection Properties

Fixed point fusion

α Fc ˙ ≤ Fa α = ⇒ α(lfp Fc) ≤ lfp Fa

Fc, Fa are monotone

α Fc = Fa α = ⇒ α(lfp Fc) = lfp Fa

Fa : hA, i ! hA, i

Fc : hC, vi ! hC, vi

| {z }

usually finite

slide-32
SLIDE 32

α(lfp Fc) = lfp Fa

| {z }

decidable

slide-33
SLIDE 33

How to find an abstract functional

(a recipe)

α Fc

= . . .

v . . .

= Fa α

= . . .

slide-34
SLIDE 34

A property of trace-based interpretation

slide-35
SLIDE 35

Partial trace collecting semantics

(abstracted)

α(X) = last states of all traces in X

α(X) = {s | σs ∈ X for some σ}

h℘(Σ+), ✓, ;, Σ+, [, \i

| {z }

| {z }

Partial traces Reachable states

h℘(Σ), ✓, ;, Σ, [, \i − − − → ← − − −

α γ

slide-36
SLIDE 36

Partial trace collecting semantics

(abstracted)

h℘(Σ+), ✓, ;, Σ+, [, \i

  • !
  • α

γ

h℘(Σ), ✓, ;, Σ, [, \i

| {z }

| {z }

Partial traces

| {z }

Reachable states

F(X) = {s | s 2 Σ0} [ {σss0 | σs 2 X ^ hs, s0i 2 t} b F(X) = {s | s 2 Σ0} [ {s0 | s 2 X ^ hs, s0i 2 t}

α F = b F α

* Proof: P . Cousot, R. Cousot, Basic concepts of abstract interpretation

* =

⇒ α(lfp⊆F) = lfp⊆ b F

slide-37
SLIDE 37

Reachable states semantics

(an example)

Σ0 = {s0}

t = {hs0, s1i, hs1, s1i, hs1, s2i}

Σ = {s0, s1, s2}

b F0(∅) = ∅

b F1(∅) = {s0} b F2(∅) = {s0, s1}

b F3(∅) = {s0, s1, s2}

b F4(∅) = {s0, s1, s2} = b

F3(∅) = lfp⊆( b F)

slide-38
SLIDE 38

Graphs

slide-39
SLIDE 39

Directed Rooted Graph

G = hV, E, v0i

E ⊆ V × V

Edges: Root node:

v0 ∈ V

slide-40
SLIDE 40

Paths in Rooted Graphs

(u ! v) ( ) hu, vi 2 E

σ ∈ V +

Finite non-empty paths

σ = u0 . . . un

∀i ∈ 1 . . . n, (ui−1 → ui)

slide-41
SLIDE 41

Enumerating All Paths

pG : ℘(V +) → ℘(V +)

A finite path functional

pG(X) = {σ, v : σ ∈ X ∧ (last(σ) → v) : σv} last : V + → V

last(σu) = u

slide-42
SLIDE 42

All Paths in a Fixpoint Form

A lattice

h℘(V +), ✓i

PG = lfp(λX.{v0} ∪ pG(X))

slide-43
SLIDE 43

Dominance

slide-44
SLIDE 44

A node u dominates node v if u belongs to every path from the initial node v0 to v.

slide-45
SLIDE 45
  • Dominance is a property of all paths in a

graph

  • Dominance is a relation on graph nodes
  • Dominance is a finite (i.e., computable) property

Preliminary Ideas

slide-46
SLIDE 46

Goal

Compute a dominance algorithm from the definition of dominance

slide-47
SLIDE 47

Formal Definition of Dominance

dom : ℘(V +) → ℘(V × V ) [ u dom(X) v = h8σ : σ 2 X ^ last(σ) = v : u in σi ]

where

in ⊆ V × V + in = lfp(λX.last ∪ X pre)

and

pre ⊆ V + × V + pre = {σ, v : σ 2 V + ^ σv 2 V + : hσ, σvi}

slide-48
SLIDE 48

| {z }

for every σ∈X

v is a last node of σ

z }| {

X is a set of paths

z}|{

| {z }

u∈σ

[ u dom(X) v = h8σ : σ 2 X ^ last(σ) = v : u in σi ]

Formal Definition of Dominance

slide-49
SLIDE 49

v0 a b c d

Dominance in a Graph

p0

G(∅) = ∅

dom

  • p0

G(;)

  • = {hv0, v0i, hv0, ai, hv0, bi, hv0, ci, hv0, di,

ha, v0i, ha, ai, ha, bi, ha, ci, ha, di, hb, v0i, hb, ai, hb, bi, hb, ci, hb, di, hc, v0i, hc, ai, hc, bi, hc, ci, hc, di, hd, v0i, hd, ai, hd, bi, hd, ci, hd, di}

slide-50
SLIDE 50

v0 a b c d

Dominance in a Graph

p1

G(∅) = {v0}

dom

  • p1

G(;)

  • = {hv0, v0i, hv0, ai, hv0, bi, hv0, ci, hv0, di,

ha, ai, ha, bi, ha, ci, ha, di, hb, ai, hb, bi, hb, ci, hb, di, hc, ai, hc, bi, hc, ci, hc, di, hd, ai, hd, bi, hd, ci, hd, di}

slide-51
SLIDE 51

v0 a b c d

Dominance in a Graph

p2

G(∅) = {v0, v0a, v0d}

dom

  • p2

G(;)

  • = {hv0, v0i, hv0, ai, hv0, bi, hv0, ci, hv0, di,

ha, ai, ha, bi, ha, ci, hb, bi, hb, ci, hc, bi, hc, ci, hd, bi, hd, ci, hd, di}

slide-52
SLIDE 52

v0 a b c d

Dominance in a Graph

p3

G(∅) = {v0, v0a, v0d, v0ab, v0dc}

dom

  • p3

G(;)

  • = {hv0, v0i, hv0, ai, hv0, bi, hv0, ci, hv0, di,

ha, ai, ha, bi, hb, bi, hc, ci, hd, ci, hd, di}

slide-53
SLIDE 53

v0 a b c d

Dominance in a Graph

A fixed point for dominance is reached

dom

  • p4

G(;)

  • = {hv0, v0i, hv0, ai, hv0, bi, hv0, ci, hv0, di,

ha, ai, ha, bi, hb, bi, hc, ci, hd, di}

p4

G(∅) = {v0, v0a, v0d, v0ab, v0dc, v0abc, v0dca}

slide-54
SLIDE 54
  • As a set of paths increases, a dominance

can only decrease

  • A possible case to establish a Galois

Connection

Idea

slide-55
SLIDE 55

A Galois Connection for Dominance

| {z }

Finite paths

| {z }

Dominance relations

What is α?

h℘(V +), ✓i

  • !
  • α

γ

h℘(V ⇥ V ), ◆i

slide-56
SLIDE 56

What about dom?

Recall:

dom : ℘(V +) → ℘(V × V ) [ u dom(X) v = h8σ : σ 2 X ^ last(σ) = v : u in σi ]

slide-57
SLIDE 57

Goals

  • 1. Prove a Galois Connection
  • 2. Find

such that

FD

dom pG = FD dom

then

dom(PG) = lfp⊇(λX.dom({v0}) ∩ FD(X))

h℘(V +), ✓i

  • !
  • dom

dom

h℘(V ⇥ V ), ◆i

To do

slide-58
SLIDE 58
  • 1. A Galois Connection

for Dominance

slide-59
SLIDE 59

Decomposing Dominance

dom = g f

Establish a connection compositionally

slide-60
SLIDE 60

Intermezzo: Compositions and Factors

* With gratitude to Reviewer #1

*

slide-61
SLIDE 61

Compositions

R S ⌘ {x, y, z : hx, yi 2 R ^ hy, zi 2 S : hx, zi}

R ⊆ A × B S ⊆ B × C

slide-62
SLIDE 62

Factors

R ⊆ A × B S ⊆ B × C T ⊆ A × C

Left factor: Right factor:

[ x T/S y ⌘ h8z : y S z : x T zi ]

[ x R\T y ⌘ h8z : z R x : z T yi ]

slide-63
SLIDE 63

A Nice Thing about Factors

R ⊆ A × B S ⊆ B × C T ⊆ A × C

[ T/S ⊇ R ⇐ ⇒ S ⊆ R\T ]

≤ α(S)

R ⇐

[

S v γ(R) ]

α(X) = T/X

γ(X) = X\T

slide-64
SLIDE 64

A Nice Thing about Factors

R ⊆ A × B S ⊆ B × C T ⊆ A × C

h℘(B ⇥ C), ✓i

  • !
  • (T/)

(\T )

h℘(A ⇥ B), ◆i

(T/) = λX.T/X (\T) = λX.X\T

[ T/S ⊇ R ⇐ ⇒ S ⊆ R\T ]

≤ α(S)

R ⇐

[

S v γ(R) ]

α(X) = T/X

γ(X) = X\T

slide-65
SLIDE 65

Back to Dominance

slide-66
SLIDE 66

Decomposing Dominance

[u dom(X) v = h8σ : σ ∈ X ∧ last(σ) = v : u in σi] f(X) = {σ : σ 2 X : hlast(σ), σi} v f(X) σ | {z }

in/f(X)

slide-67
SLIDE 67

Decomposing Dominance

f(X) = {σ : σ 2 X : hlast(σ), σi} dom = (in/) f [u dom(X) v = h8σ : : u in σi] v f(X) σ | {z }

in/f(X)

slide-68
SLIDE 68

Decomposing Dominance

dom = (in/) f

Factors In the paper

h℘(V +), ✓i

  • !
  • dom

dom

h℘(V ⇥ V ), ◆i

f(X) = {σ : σ 2 X : hlast(σ), σi}

h℘(last), ✓i

  • !
  • (in/)

(\in)

h℘(V ⇥ V ), ◆i

h℘(V +) ✓i

  • !
  • f

f

h℘(last), ✓i

slide-69
SLIDE 69

Goals

  • 1. Prove a Galois Connection
  • 2. Find

such that

FD

dom pG = FD dom

Done

h℘(V +), ✓i

  • !
  • dom

dom

h℘(V ⇥ V ), ◆i

To do

slide-70
SLIDE 70
  • 2. Computing a

Dominance Functional

slide-71
SLIDE 71

dom pG = (in/) f pG f pG = k f

k(X) = {σ, u, v : hu, σi 2 X ^ (u ! v) : hv, σvi}

slide-72
SLIDE 72

dom pG = (in/) f pG = k f

k(X) = {σ, u, v : hu, σi 2 X ^ (u ! v) : hv, σvi}

(in/) k f

Details in the paper

f pG

slide-73
SLIDE 73

dom pG = (in/) k f (in/) k = FD (in/) FD(X) = id ∪ X/pred [ v pred u ≡ u → v ] f pG = k f

k(X) = {σ, u, v : hu, σi 2 X ^ (u ! v) : hv, σvi}

Details in the paper

slide-74
SLIDE 74

dom pG = FD(X) = id ∪ X/pred [ v pred u ≡ u → v ]

Details in the paper

FD (in/) f

(in/) k = FD (in/) (in/) k f

slide-75
SLIDE 75

dom pG = FD(X) = id ∪ X/pred [ v pred u ≡ u → v ]

FD dom FD (in/) f

(in/) k = FD (in/)

Details in the paper

slide-76
SLIDE 76

dom pG =

dom(PG) = lfp⊇(λX.dom({v0}) ∩ FD(X))

FD dom

FD(X) = id ∪ X/pred [ v pred u ≡ u → v ] (in/) k = FD (in/)

slide-77
SLIDE 77

Goals

  • 1. Prove a Galois Connection
  • 2. Find

such that

FD

dom pG = FD dom

Done

h℘(V +), ✓i

  • !
  • dom

dom

h℘(V ⇥ V ), ◆i

Done

slide-78
SLIDE 78

dom(PG) = lfp⊇(λX.dom({v0}) ∩ FD(X))

slide-79
SLIDE 79

Algorithm

slide-80
SLIDE 80

Dom(v) = {u : u dom(PG) v : u}

slide-81
SLIDE 81

A Straightforward Algorithm

{

⊥ 

 

for v 2 V do Dom[v] V Dom’ dom({v0}) \ FD(Dom) while Dom 6= Dom’ do Dom Dom’ Dom’ dom({v0}) \ FD(Dom)

dom({v0}) t lfp(. . .)

slide-82
SLIDE 82

Can we do better?

slide-83
SLIDE 83

Dominance Equivalences

[ u dom(PG) v ( ) u = v _ h8w : w ! v : u dom(PG) wi ]

[ u dom(PG) v0 ⇐ ⇒ u = v0 ]

slide-84
SLIDE 84

Dominance Equations

Dom(v0) = {v0} Dom(v) = \

w∈pred(v)

Dom(w) ∪ {v}

slide-85
SLIDE 85

An Optimized Algorithm*

for v 2 V do Dom[v] V Dom[v0] {v0} Changed true while Changed do Changed false for v 2 V do newSet ⇣T

w∈pred(v) Dom[w]

⌘ [ {v} if newSet 6= Dom[v] then Dom[v] newSet Changed true

* K. D. Cooper, T. J. Harvey, and K. Kennedy. A simple, fast dominance algorithm.

slide-86
SLIDE 86

Complexity

slide-87
SLIDE 87

for v 2 V do Dom[v] V Dom[v0] {v0} Changed true while Changed do Changed false for v 2 V do newSet ⇣T

w∈pred(v) Dom[w]

⌘ [ {v} if newSet 6= Dom[v] then Dom[v] newSet Changed true

{

O(|V |2)

slide-88
SLIDE 88

for v 2 V do Dom[v] V Dom[v0] {v0} Changed true while Changed do Changed false for v 2 V do newSet ⇣T

w∈pred(v) Dom[w]

⌘ [ {v} if newSet 6= Dom[v] then Dom[v] newSet Changed true

{

      

O(|V | × |E|)

O(|V |2)

slide-89
SLIDE 89

for v 2 V do Dom[v] V Dom[v0] {v0} Changed true while Changed do Changed false for v 2 V do newSet ⇣T

w∈pred(v) Dom[w]

⌘ [ {v} if newSet 6= Dom[v] then Dom[v] newSet Changed true

{

              

O(|V |3 × |E|) O(|V |2)

slide-90
SLIDE 90

O(|V |3 × |E|)

slide-91
SLIDE 91

Bottleneck: naïve iteration

slide-92
SLIDE 92

for v 2 V do Dom[v] V Dom[v0] {v0} Changed true while Changed do Changed false for v 2 V do newSet ⇣T

w∈pred(v) Dom[w]

⌘ [ {v} if newSet 6= Dom[v] then Dom[v] newSet Changed true

slide-93
SLIDE 93

Usual Hacks for Performance*

Reverse postorder

O(|V | × |E|)

Using priority queue

O(|V |2)

* K. D. Cooper, T. J. Harvey, and K. Kennedy. A simple, fast dominance algorithm.

slide-94
SLIDE 94

The Pattern Summarized

slide-95
SLIDE 95
  • 1. A concrete domain
  • 3. An abstract domain
  • 4. An abstraction
  • 2. A concrete functional
  • 5. A Galois connection
  • 6. “Pushing alphas”
  • 7. An iterative algorithm

h℘(V ⇥ V ), ◆i h℘(V +), ✓i

pG : ℘(V +) → ℘(V +)

dom pG = FD dom

lfp⊇FD

dom = (in/) f

h℘(V +), ✓i

  • !
  • dom

dom

h℘(V ⇥ V ), ◆i

slide-96
SLIDE 96

Shortest Path Algorithm (an overview)

slide-97
SLIDE 97
  • 1. A concrete domain
  • 3. An abstract domain
  • 4. An abstraction
  • 2. A concrete functional
  • 5. A Galois connection
  • 6. “Pushing alphas”
  • 7. An iterative algorithm

pGw : ℘(V +

w ) → ℘(V + w )

h℘(V +

w ), ✓i

dist(X) = λv. min{τ : τ 2 X ^ last(τ) = v : kτk}

dist pGw = Fδ dist

lfp ˙

≥Fδ

hV ! (N [ {1}), ˙ i

Details in the paper

h℘(V +

w ), ✓i

  • !
  • dist

dist

hV ! (N [ {1}), ˙ i

slide-98
SLIDE 98

An algorithm*

for u ∈ V do δ[u] ← ∞ δ[v0] ← 0 Changed ← true while Changed do Changed ← false for v ∈ V do for u ∈ pred(v) do if δ[u] + W[u, v] < δ[v] then δ[v] ← δ[u] + W[u, v] Changed ← true

* R. Bellman. On a routing problem. 1958

slide-99
SLIDE 99

Conclusion

slide-100
SLIDE 100
  • Various graph problems can be formulated as

properties of sets of finite paths

  • Sets of paths can be taken as a concrete domain
  • A property can be taken as an abstract domain
  • A mapping from paths to a property can be proved

to be a lower adjoint in a Galois connection

  • Fixpoint fusion law to obtain an algorithm
  • Correctness is by construction
slide-101
SLIDE 101

− − − → ← − − −

α γ

¡Gracias!