A Generic Framework for Interprocedural Analysis of Numerical - - PowerPoint PPT Presentation

a generic framework for interprocedural analysis of
SMART_READER_LITE
LIVE PREVIEW

A Generic Framework for Interprocedural Analysis of Numerical - - PowerPoint PPT Presentation

A Generic Framework for Interprocedural Analysis of Numerical Properties + Markus Mller-Olm Helmut Seidl + Mnster Mnchen PUMA Ringvorlesung, 2009 1 Outline: Background The framework for affine relations Grangers


slide-1
SLIDE 1

A Generic Framework for Interprocedural Analysis of Numerical Properties

Markus Müller-Olm + Helmut Seidl Münster + München PUMA Ringvorlesung, 2009

1

slide-2
SLIDE 2

Outline:

  • Background
  • The framework for affine relations
  • Granger’s analysis
  • Procedures
  • Guards
  • Conclusion

2

slide-3
SLIDE 3

Outline:

  • Background
  • The framework for affine relations
  • Granger’s analysis
  • Procedures
  • Guards
  • Conclusion

3

slide-4
SLIDE 4

Dream:

Check

  • everything
  • in every program
  • in no time

:-)

4

slide-5
SLIDE 5

Dream:

Check

  • everything
  • in many programs
  • in no time

;-)

5

slide-6
SLIDE 6

Dream:

Check

  • certain properties
  • in many programs
  • in no time

;-}

6

slide-7
SLIDE 7

Dream:

Check

  • certain properties
  • in many programs
  • in acceptable time ...

7

slide-8
SLIDE 8

Dream:

Check

  • affine properties
  • in affine programs
  • in polynomial time

;-}

8

slide-9
SLIDE 9

An Affine Program:

2 1

x2 := 4 x1 := 2 x1 := x1 + x2 x2 := x2 − 2x1

9

slide-10
SLIDE 10

More Generally:

Affine programs consist of

  • affine assignments:

x1 := x1 + x2 − 7;

  • non-deterministic instead of conditional choice ...

extended with

  • nondeterministic assignments:

x3 := ?;

  • recursive procedures;
  • equality guards

;-)

10

slide-11
SLIDE 11

More Generally:

Affine programs consist of

  • affine assignments:

x1 := x1 + x2 − 7;

  • non-deterministic instead of conditional choice ...

extended with

  • nondeterministic assignments:

x3 := ?;

  • recursive procedures;
  • equality guards

;-)

11

slide-12
SLIDE 12

Questions:

Karr, 1976

→ What is the value of x1 at program exit? → Where is 5 + 2x1 − x2 = 0 ? → Which of the variables x1, x2 and x3 are equal at program point 2 ? = = ⇒

affine relations

12

slide-13
SLIDE 13

Questions:

Karr, 1976

→ What is the value of x1 at program exit? → Where is 5 + 2x1 − x2 = 0 ? → Which of the variables x1, x2 and x3 are equal at program point 2 ? = = ⇒

affine relations

13

slide-14
SLIDE 14

Applications:

  • constant propagation;
  • data alignment properties;
  • induction variable detection;
  • loop transformations;
  • program verification

:-))

Goal:

Determine all valid affine relations between variables ... in polynomial time :-)

14

slide-15
SLIDE 15

Applications:

  • constant propagation;
  • data alignment properties;
  • induction variable detection;
  • loop transformations;
  • program verification

:-))

Goal:

Determine all valid affine relations between variables ... in polynomial time :-)

15

slide-16
SLIDE 16

Applications:

  • constant propagation;
  • data alignment properties;
  • induction variable detection;
  • loop transformations;
  • program verification

:-))

Goal:

Determine all valid affine relations between variables ... in polynomial time :-)

16

slide-17
SLIDE 17

Results for Intraprocedural Analysis:

Karr fields 1976 Gulwani, Necula random Zp 2003 MMO., S. fields 2004 MMO., S. Zm, m = 2w 2005

Why not ...

  • Re-use algorithm !
  • Just exchange ring

:-)

17

slide-18
SLIDE 18

Results for Intraprocedural Analysis:

Karr fields 1976 Gulwani, Necula random Zp 2003 MMO., S. fields 2004 MMO., S. Zm, m = 2w 2005

Why not ...

  • Re-use algorithm !
  • Just exchange the ring

:-)

18

slide-19
SLIDE 19

Principal Ideal Rings

Ideal: I ⊆ R such that: a + b ∈ I if a, b ∈ I r · a ∈ I if r ∈ R, a ∈ I PIR: R such that I = aR = {r · a | r ∈ R} for every ideal I ⊆ R.

19

slide-20
SLIDE 20

Examples:

  • All fields such as

Q , Zp (p prime) , R

  • integral domains such as

Z , Q[t] :-)

  • the modular ring

Z2w;

  • the modular rings

Zm for arbitrary m

  • ...

20

slide-21
SLIDE 21

Examples:

  • All fields such as

Q , Zp (p prime) , R

  • integral domains such as

Z , Q[t] :-)

  • the modular ring

Z2w;

  • the modular rings

Zm for arbitrary m

  • ...

21

slide-22
SLIDE 22

Properties of PIRs:

The homogeneous equation a · x = 0 can be solved ... = = ⇒ Find all annihilators !

Example:

has the solutions {0, 5, 10, 15, 20, 25} :-)

22

slide-23
SLIDE 23

Properties of PIRs:

The homogeneous equation a · x = 0 can be solved ... = = ⇒ Find all annihilators !

Example: R = Z32

12 · x = 0 has the solutions {0, 8, 16, 24} :-)

23

slide-24
SLIDE 24

Properties of PIRs:

The homogeneous equation a · x = 0 can be solved ... = = ⇒ Find all annihilators !

Example: R = Z30

6 · x = 0 has the solutions {0, 5, 10, 15, 20, 25} :-)

24

slide-25
SLIDE 25

Properties of PIRs (2):

The inhomogeneous equation a · x = b can be solved ... = = ⇒ Check for ideal membership !

Example:

has the solutions 5 + {10, 20} :-)

25

slide-26
SLIDE 26

Properties of PIRs (2):

The inhomogeneous equation a · x = b can be solved ... = = ⇒ Check for ideal membership !

Example: R = Z32

12 · x = 4 has the solutions 11 + {0, 8, 16, 24} :-)

26

slide-27
SLIDE 27

Properties of PIRs (2):

The inhomogeneous equation a · x = b can be solved ... = = ⇒ Check for ideal membership !

Example: R = Z30

3 · x = 15 has the solutions 5 + {10, 20} :-)

27

slide-28
SLIDE 28

Properties of PIRs (3):

For every a, b ∈ R, there is a gcd: a, bR = dR. Even more:

  • t11

t12 t21 t22

  • ·
  • a

b

  • =
  • d
  • for some tij with

t11t22 − t12t21 = 1 ... fill!

28

slide-29
SLIDE 29

Consequence:

Hafner, McCurley, 1991 Storjohann, 2000 Any linear equation system over a PIR can be solved using modified Gaussian elimination :-)

29

slide-30
SLIDE 30

Outline:

  • Background
  • The framework for affine relations
  • Granger’s analysis
  • Procedures
  • Guards
  • Conclusion

30

slide-31
SLIDE 31

General Setting:

1 x := 1 y := q

2

x := 4q − 1 x := q + 1 y := x − 2q

semantics collecting property

31

slide-32
SLIDE 32

General Setting:

1

?

2

x := 1 y := q x := 4q − 1 y := x − 2q x := q + 1

semantics collecting property

32

slide-33
SLIDE 33

Abstract Interpretation:

Cousot/Cousot, 1977

1

?

2

x := 1 y := q x := q + 1 y := x − 2q x := 4q − 1

semantics abstract semantics collecting property

33

slide-34
SLIDE 34

Precise Abstract Interpretation:

1

?

2

x := 1 y := q x := q + 1 y := x − 2q x := 4q − 1

semantics collecting property semantics abstract lossless

34

slide-35
SLIDE 35

The Collecting Semantics

  • For every program point determine the set of reachable

states [x1, . . . , xk]t.

  • Every assignment

xj := t induces a affine transformation of the state: [ [x1 := x1 + x2 + 1] ]

  • x1

x2

  • =
  • 1

1 1

  • ·
  • x1

x2

  • +
  • 1
  • 35
slide-36
SLIDE 36

Simplified Collecting Semantics

  • For every program point determine the set of reachable

extended states [1, x1, . . . , xk]t.

  • Every assignment

xj := t induces a linear transformation of the state: [ [x1 := x1 + x2 + 1] ]     x0 x1 x2     =     1 1 1 1 1     ·     x0 x1 x2    

36

slide-37
SLIDE 37

Constraint System:

C[start] ⊇ {1} × Rk C[v] ⊇ [ [xj := t] ] (C[u]) (u, xj := t, v) control-flow edge

37

slide-38
SLIDE 38

The Abstraction:

αR(X) = {r1x(1) + . . . + rmx(m) | ri ∈ R, x(i) ∈ X} the R-module generated by X :-)

38

slide-39
SLIDE 39

The Abstraction:

αR(X) = {r1x(1) + . . . + rmx(m) | ri ∈ R, x(i) ∈ X} =: XR the R-module generated by X :-)

39

slide-40
SLIDE 40

Properties:

  • αR

maps sets of extended states into R-modules.

  • The R-modules

M ⊆ Rk+1 form a complete lattice: least element: ∅R = {0} least upper bound: M1 ⊔ M2 = {m1 + m2 | mi ∈ Mi}

40

slide-41
SLIDE 41

Properties (2):

  • If

R is a PIR, then every ascending chain: M0 ⊑ . . . ⊑ Mi ⊑ . . . ⊑ Rk+1 is ultimately stable :-))

Examples:

41

slide-42
SLIDE 42

Properties (2):

  • If

R is a PIR, then every ascending chain: M0 ⊑ . . . ⊑ Mi ⊑ . . . ⊑ Rk+1 is ultimately stable :-))

Examples:

R height field k + 1 Zm log(m) · (k + 1) Z unbounded

42

slide-43
SLIDE 43

Idea:

Apply αR to constraint system ...

43

slide-44
SLIDE 44

Idea:

Apply αR to constraint system ...

C♯

R[start]

⊒ Rk+1 C♯

R[v]

⊒ [ [xj := t] ] (C♯

R[u])

(u, xj := t, v) control-flow edge

44

slide-45
SLIDE 45

Our Example:

R = Q

1 1 1 1 1

2 1

x2 := 4 x1 := 2 x1 := x1 + x2 x2 := x2 − 2x1

45

slide-46
SLIDE 46

Our Example:

R = Q

4 1 2 4 1 6 1 1 1 1 1

2 1

x2 := 4 x1 := 2 x1 := x1 + x2 x2 := x2 − 2x1

46

slide-47
SLIDE 47

Our Example:

R = Q

4 1 2 1 6 −8 4 1 6 1 −2 −8 1 1 1 1 1

2 1

x2 := 4 x1 := 2 x1 := x1 + x2 x2 := x2 − 2x1

47

slide-48
SLIDE 48

Our Example:

R = Q

4 1 6 1 −2 −8 1 −6 −4 4 1 2 1 6 −8 1 −2 −4 1 1 1 1 1

2 1

x2 := 4 x1 := 2 x1 := x1 + x2 x2 := x2 − 2x1

48

slide-49
SLIDE 49

Fact:

. . .R commutes with “⊔” and “·”:

X1 ∪ X2R = X1R ⊔ X2R {A · x | x ∈ X}R = {A · x | x ∈ XR}R for matrix A and sets X, X1, X2 of vectors :-)

49

slide-50
SLIDE 50

Theorem 1:

  • C♯

R

precisely yields the linear closure of C :-)

  • If R is a PIR, the values

C♯

R[u]

are computable :-)

50

slide-51
SLIDE 51

Theorem 1:

  • C♯

R

precisely yields the linear closure of C :-)

  • If R is a PIR, the values

C♯

R[u]

are computable :-)

R Complexity field n · k3 Zm n · k3 · log(m)

51

slide-52
SLIDE 52

Exploiting the Abstraction:

  • 5 + 2x1 − 13x2 = 0

⇐ = ⇒ [5, 2, −13]

  • An affine relation

a holds for [x1, . . . , xk]t iff a · x = 0 for x = [1, x1, . . . , xk]t. Thus, affine relation of the state ⇐ = ⇒ linear relation of the extended state :-)

52

slide-53
SLIDE 53

Exploiting the Abstraction:

  • 5 + 2x1 − 13x2 = 0

⇐ = ⇒ [5, 2, −13]

  • An affine relation

a holds for [x1, . . . , xk]t iff a · x = 0 for x = [1, x1, . . . , xk]t. Thus, affine relation of the state ⇐ = ⇒ linear relation of the extended state :-)

53

slide-54
SLIDE 54

Observation:

The following statements are equivalent for X ⊆ Rk+1: a · x = for all x ∈ X (1) a · x = for all x ∈ XR (2) = = ⇒ The abstraction αR is lossless :-)

54

slide-55
SLIDE 55

Observation:

The following statements are equivalent for X ⊆ Rk+1: a · x = for all x ∈ X (1) a · x = for all x ∈ XR (2) = = ⇒ The abstraction αR is lossless :-)

55

slide-56
SLIDE 56

Our Example:

R = Q

A relation is valid at point 2 iff it satisfies: a0 + 2a1 + 4a2 = a0 + 6a1 − 8a2 = a0 − 2a1 − 4a2 = = = ⇒ No affine relation holds :-)

56

slide-57
SLIDE 57

Our Example:

R = Q

A relation is valid at point 2 iff it satisfies: a0 + 2a1 + 4a2 = a0 + 6a1 − 8a2 = a0 − 2a1 − 4a2 = = = ⇒ No affine relation holds :-)

57

slide-58
SLIDE 58

Corollary:

For every PIR R, the set of all affine relations which are valid at a program point can be computed.

R Complexity field n · k3 Zm n · k3 · log(m)

58

slide-59
SLIDE 59

Outline:

  • Background
  • The framework for affine relations
  • Granger’s analysis
  • Procedures
  • Guards
  • Conclusion

59

slide-60
SLIDE 60

The Particular Case R = Z:

The following statements are equivalent for X ⊆ Zk+1: a · x = for all x ∈ X (1) a · x = for all x ∈ XZ (2) = = ⇒ The abstraction αQ is good enough !!!

60

slide-61
SLIDE 61

The Particular Case R = Z:

The following statements are equivalent for X ⊆ Zk+1: a · x = for all x ∈ X (1) a · x = for all x ∈ XZ (2) a · x = for all x ∈ XQ (3) = = ⇒ The abstraction αQ is good enough !!!

61

slide-62
SLIDE 62

Observation:

Granger 1991

The Z-linear closure allows to derive ...

  • all valid linear relations;

and furthermore,

  • all valid linear relations modulo any

m such as 10 + 3x1 + x2 = 0 [20] = = ⇒

linear congruence relations

62

slide-63
SLIDE 63

Observation:

Granger 1991

The Z-linear closure allows to derive ...

  • all valid linear relations;
  • all valid linear relations modulo any

m such as 10 + 3x1 + x2 = 0 [20] = = ⇒

linear congruence relations

63

slide-64
SLIDE 64

Our Example:

R = Z16

A relation is valid at point 2 iff it satisfies: a0 + 2a1 + 4a2 = [16] a0 + 6a1 − 8a2 = [16] a0 − 2a1 − 4a2 = [16] Valid affine relations: [0, 0, 4] , [8, 4, 0] :-)

64

slide-65
SLIDE 65

Our Example:

R = Z16

A relation is valid at point 2 iff it satisfies: a0 + 2a1 + 4a2 = [16] a0 + 6a1 − 8a2 = [16] a0 − 2a1 − 4a2 = [16] Valid affine relations: [0, 0, 4] , [8, 4, 0] :-)

65

slide-66
SLIDE 66

Observation:

MMO, Seidl 2005 (1) Every Z-module M ⊆ Zk+1 can be characterized by:

  • all valid linear equalities; together with
  • all valid linear equalities modulo one suitable

m :-) (2) Every other valid congruence relation can be deduced :-)

66

slide-67
SLIDE 67

Observation:

MMO, Seidl 2005 (1) Every Z-module M ⊆ Zk+1 can be characterized by:

  • all valid linear equalities; together with
  • all valid linear equalities modulo one suitable

m :-) (2) Every other valid congruence relation can be deduced :-)

67

slide-68
SLIDE 68

Our Example:

M = GZ

where G =            1 2 4     ,     1 6 −8     ,     1 −2 −4           

Idea:

Choose m as the determinant :-) = = ⇒ m = 80

68

slide-69
SLIDE 69

Our Example:

M = GZ

The valid relations modulo m therefore must satisfy: a0 + 2a1 + 4a2 = [80] a0 + 6a1 − 8a2 = [80] a0 − 2a1 − 4a2 = [80] These are: [40, 20, 0] , [8, 68, 4]

69

slide-70
SLIDE 70

The Algorithm:

(1) Compute the least solution of C♯

Q;

(2) Determine for every u, all valid linear equalities; (3) Determine for every u, a suitable modulus m(u); (4) For m = m(u), determine C♯

Zm[u];

(5) Determine the valid Zm-linear equalities at u.

70

slide-71
SLIDE 71

The Algorithm:

(1) Compute the least solution of C♯

Q;

(2) Determine for every u, all valid linear equalities; (3) Determine for every u, a suitable modulus m(u); (4) For m = m(u), determine C♯

Zm[u];

(5) Determine the valid Zm-linear equalities at u.

71

slide-72
SLIDE 72

Theorem 2:

MMO., Seidl 2005

  • If

C♯

Q[u] = GQ

for some linearly independent G ⊆ C[u] , then m(u) can be chosen as the determinant of G.

  • The set of all valid linear congruence equations at

program point u can be computed in polynomial time :-)

72

slide-73
SLIDE 73

Theorem 2:

MMO., Seidl 2005

  • If

C♯

Q[u] = GQ

for some linearly independent G ⊆ C[u] , then m(u) can be chosen as the determinant of G.

  • The set of all valid linear congruence equations at

program point u can be computed in polynomial time :-)

73

slide-74
SLIDE 74

Outline:

  • Background
  • The framework for affine relations
  • Granger’s analysis
  • Procedures
  • Guards
  • Conclusion

74

slide-75
SLIDE 75

An Example Program:

1 2 3 4 5 6

Main : q()

x2 := 0 x1 := 2

q : q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

75

slide-76
SLIDE 76

Interprocedural Analysis for Affine Programs:

Horwitz et al. linear constants 1996 MMO., S. affine relations over fields 2003 Gulwani, Necula affine relations over random Zp 2005 MMO., S. affine relations over Zm 2005 MMO., S. affine relations over PIRs 2005

76

slide-77
SLIDE 77

Interprocedural Analysis for Affine Programs:

Horwitz et al. linear constants 1996 MMO., S. affine relations over fields 2003 Gulwani, Necula affine relations over random Zp 2005 MMO., S. affine relations over Zm 2005 MMO., S. affine relations over PIRs 2005

77

slide-78
SLIDE 78

The Collecting Semantics

  • A run through a procedure is a linear transformation of

the extended program state :-)

  • The effect of a procedure is a set of linear

transformations :-)

  • These sets can be described by a constraint system

...

78

slide-79
SLIDE 79

Constraint System:

E[startq] ⊇ {Id} E[q] ⊇ E[returnq] E[v] ⊇ [ [xj := t] ] · E[u] (u, xj := t, v) control-flow edge E[v] ⊇ E[q] · E[u] (u, q, v) control-flow edge

79

slide-80
SLIDE 80

Idea:

Apply αR to Sets of Matrices !!!

80

slide-81
SLIDE 81

Idea:

Apply αR to Sets of Matrices !!!

E♯

R[startq]

⊒ IdR E♯

R[q]

⊒ E♯

R[returnq]

E♯

R[v]

⊒ [ [xj := t] ] · E♯

R[u]

(u, xj := t, v) control-flow edge E♯

R[v]

⊒ E♯

R[q] · E♯ R[u]

(u, q, v) control-flow edge

81

slide-82
SLIDE 82

The Example:

1 1 1 0 0

1 2 3

q : q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

82

slide-83
SLIDE 83

The Example:

1 1 1 0 0 1 1 1 0 0

1 2 3

q : q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

83

slide-84
SLIDE 84

The Example:

1 1 1 0 0 1 3 1 3 0 0 1 1 1 0 0 1 1 18 15 1 3 1 3 0 0

1 2 3

q : q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

84

slide-85
SLIDE 85

The Example:

1 1 1 0 0 1 3 1 3 0 0 1 1 1 0 0 1 1 18 15 1 1 225 282 1 3 1 3 0 0 1 1 57 45

1 2 3

q : q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

85

slide-86
SLIDE 86

The Example:

1 3 1 3 0 0 1 1 57 45 1 1 675 849 1 1 1 0 0 1 3 1 3 0 0 1 1 1 0 0 1 1 18 15 1 1 225 282

1 2 3

q : q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

86

slide-87
SLIDE 87

The abstract effects E♯

R[q]

can be used to determine the precise linear closure of the reachable extended states: C♯

R[Main]

⊒ Rk+1 C♯

R[startq]

⊒ C♯

R[q]

87

slide-88
SLIDE 88

The abstract effects E♯

R[q]

can be used to determine the precise linear closure of the reachable extended states: C♯

R[Main]

⊒ Rk+1 C♯

R[startq]

⊒ C♯

R[q]

C♯

R[v]

⊒ [ [xj := t] ] (C♯

R[u])

(u, xj := t, v) control-flow edge

88

slide-89
SLIDE 89

The abstract effects E♯

R[q]

can be used to determine the precise linear closure of the reachable extended states: C♯

R[Main]

⊒ Rk+1 C♯

R[startq]

⊒ C♯

R[q]

C♯

R[v]

⊒ [ [xj := t] ] (C♯

R[u])

(u, xj := t, v) control-flow edge C♯

R[v]

⊒ E♯

R[q] (C♯ R[u]) ,

and C♯

R[q]

⊒ C♯

R[u] ,

(u, q, v) control-flow edge

89

slide-90
SLIDE 90

Our Example:

1 1 1 0 0 1 1 225 282 1 1 18 15 1 1 1 1 1

1 2 3 4 5 6

Main : q()

x2 := 0 x1 := 2

q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

q :

90

slide-91
SLIDE 91

Our Example:

1 1 1 0 0 1 1 225 282 1 1 18 15 2 1 1 1 1 1 1

1 2 3 4 5 6

Main : q()

x2 := 0 x1 := 2

q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

q :

91

slide-92
SLIDE 92

Our Example:

1 1 1 0 0 1 1 225 282 1 1 18 15 2 1 1 1 1 1 1 2 1 564 450 1 36 30 1

1 2 3 4 5 6

Main : q()

x2 := 0 x1 := 2

q()

x2 := x1 + x2 x2 := x1 + x2 x1 := 3 ∗ x1 x1 := 5 ∗ x1

q :

92

slide-93
SLIDE 93

Theorem 3:

  • E♯

R

precisely yields the linear closure of E :-)

  • C♯

R

precisely yields the linear closure of C :-)

  • If R is a PIR, the values

E♯

R[p] , C♯ R[u]

are computable :-)

R Complexity field n · k8 Zm n · k8 · log(m)

93

slide-94
SLIDE 94

Corollary:

For every PIR R, the set of all affine relations which are valid at a program point can be computed.

R Complexity field n · k8 Zm n · k8 · log(m) Z n2 · k8 · ∆

94

slide-95
SLIDE 95

Local Variables, Parameters, Return Values

For simplicity assume,

  • All procedures have equally many locals;
  • All locals are passed as parameters;
  • Return values are are passed in global variables.

95

slide-96
SLIDE 96

Local Variables, Parameters, Return Values

For simplicity assume,

  • All procedures have equally many locals;
  • All locals are passed as parameters;
  • Return values are are passed in global variables.

Idea: Projections

96

slide-97
SLIDE 97

Example:

Globals: x1, x2 Locals: x3 Πglob =        1 1 1        Πlocs =        1       

97

slide-98
SLIDE 98

Example:

Globals: x1, x2 Locals: x3 Πglob =        1 1 1        Πlocs =        1        The effect of a call f() is obtained by the operator: H(A1, . . . , ArR) = Πlocs + ΠGlob · Ai | i = 1, . . . , rR

98

slide-99
SLIDE 99

Outline:

  • Background
  • The framework for affine relations
  • Granger’s analysis
  • Procedures
  • Guards
  • Conclusion

99

slide-100
SLIDE 100

Example:

1 2

x1 := x1 + 1 x1 = 10? x1 := 0

100

slide-101
SLIDE 101

Remarks:

  • For a program with guards, it is undecidable whether

x1 = 0 holds at some u. = = ⇒ Abstraction is inevitable :-(

  • An abstract semantics over any

R can model guards g = 0? with intersections ... = = ⇒ through solving a linear system of equations. = = ⇒ sizes of numbers may explode !!!

101

slide-102
SLIDE 102

Remarks:

  • For a program with guards, it is undecidable whether

x1 = 0 holds at some u. = = ⇒ Abstraction is inevitable :-(

  • An abstract semantics over any

R can model guards g = 0? with intersections ... C♯

R[v]

⊒ {x | g · x = 0} ∩ C♯

R[u]

= = ⇒ through solving a linear system of equations. = = ⇒ sizes of numbers may explode !!!

102

slide-103
SLIDE 103

Remarks:

  • For a program with guards, it is undecidable whether

x1 = 0 holds at some u. = = ⇒ Abstraction is inevitable :-(

  • An abstract semantics over any

R can model guards g = 0? with intersections ... C♯

R[v]

⊒ {x | g · x = 0} ∩ C♯

R[u]

= = ⇒ through solving a linear system of equations = = ⇒ sizes of numbers may explode !!!

103

slide-104
SLIDE 104

Interprocedural Treatment:

How to do intersections for transformers ???

Idea:

  • Postpone intersections

:-)

  • Accumulate value of guard g in a variable xg.
  • Insist on

xg = 0 after each call !!!

104

slide-105
SLIDE 105

Interprocedural Treatment:

How to do intersections for transformers ???

Idea:

  • Postpone intersections

:-)

  • Accumulate value of guard g in a variable xg.
  • Insist on

xg = 0 after each call !!!

105

slide-106
SLIDE 106

Example:

1 2

x1 := x1 + 1 x1 = 10? x1 := 0

q()

106

slide-107
SLIDE 107

Example:

1 2

x1 := x1 + 1 x1 := 0

q()

x2 := x1 − 10

107

slide-108
SLIDE 108

Modified Call:

C♯

R[v]

⊒ {x | ∀ g : xg = 0} ∩ E♯

R[q] (C♯ R[u]) ,

(u, q, v) control-flow edge

108

slide-109
SLIDE 109

Outline:

  • Background
  • The framework for affine relations
  • Granger’s analysis
  • Procedures
  • Guards
  • Conclusion

109

slide-110
SLIDE 110

Summary:

  • We presented a framework for interprocedural analysis

which is parametric in the ring R.

  • The framework works whenever R is a PIR.
  • The framework covers the best known algorithms for

inferring affine equalities :-)

  • It provides a variant of Granger’s linear congruence

relation analysis which is polynomial.

  • It provides a uniform and interprocedural treatment of

equality guards.

110

slide-111
SLIDE 111

Extensions:

⇒ assignments xj :=? :-) ⇒ inferring all valid polynomial relations such as: x2x3 − x1 + x2 + x3 = 0 ... of degree at most d :-) ⇒ interprocedural negative equality guards ?! ⇒ interprocedural polynomial programs ?! ⇒ What, if we are interested in weaker invariants ???

111

slide-112
SLIDE 112

Extensions:

⇒ assignments xj :=? :-) ⇒ inferring all valid polynomial relations such as: x2x3 − x1 + x2 + x3 = 0 ... of degree at most d :-) ⇒ interprocedural negative equality guards ?! ⇒ interprocedural polynomial programs ?! ⇒ What, if we are interested in weaker invariants ???

112

slide-113
SLIDE 113

Extensions:

⇒ assignments xj :=? :-) ⇒ inferring all valid polynomial relations such as: x2x3 − x1 + x2 + x3 = 0 ... of degree at most d :-) ⇒ interprocedural negative equality guards ?! ⇒ interprocedural polynomial programs ?! ⇒ What, if we are interested in weaker invariants ???

113