code generation and virtual machines · analysis 3 the analysis an instance of a forward monotone...

31
Shape Analysis CS 502 Lecture 12 11/06/08 Slides adapted from Nielson, Nielson, Hankin Principles of Program Analysis

Upload: others

Post on 01-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Shape Analysis

CS 502Lecture 1211/06/08

Slides adapted from Nielson, Nielson, HankinPrinciples of Program Analysis

Page 2: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Lattice

2

The complete lattice of shape graphs

A shape graph is a triple (S,H,is) where

S ! AState = P(Var! "ALoc)

H ! AHeap = P(ALoc" Sel"ALoc)

is ! IsShared = P(ALoc)

and ALoc = {nZ | Z # Var!}.

A shape graph (S,H, is) is compatible if it fulfils the five invariants.

The analysis computes over sets of compatible shape graphs

SG = {(S,H, is) | (S,H, is) is compatible}

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 123

Page 3: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Analysis

3

The analysis

An instance of a forward Monotone Framework with the complete latticeof interest being P(SG)

A may analysis: each of the sets of shape graphs computed by theanalysis may contain shape graphs that cannot really arrise

Aspects of a must analysis: each of the individual shape graphs (in aset of shape graphs computed by the analysis) will be the best possibledescription of some (!,H)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 124

Page 4: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Formulation

4

The analysis

Equations:

Shape!(!) =

!" if ! = init(S#)"{Shape•(!") | (!", !) # flow(S#)} otherwise

Shape•(!) = fSA! (Shape!(!))

Example: The extremal value " for the list reversal program

x ! n{x} !cdr n$

! "#"cdr

– x points to a non-cyclic list with at least three elements

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 125

Page 5: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

5

Shape•(1) for [y:=nil]1

x ! n{x} !cdr n!

!"#"cdr

Note: we do not record nil-values in the analysis

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 126

Page 6: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

6

Shape•(2) for [not is-nil(x)]2

x ! n{x} !cdr n!

!"#"cdr

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}

x ! n{x} !cdr n!

y ! n{y}

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}

"cdrz ! n{z}

x ! n{x} !cdr n!

y ! n{y}

"cdrz ! n{z}

x ! n{x} n!

y ! n{y}

"cdrz ! n{z}

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}

"cdrz ! n{z}

#

cdr

x ! n{x} !cdr n!

y ! n{y}

"cdrz ! n{z}

#

cdr

x ! n{x}

n!

y ! n{y}

"cdrz ! n{z} !cdr

n!

y ! n{y}

"cdrz ! n{z} !cdr n!

!"#"cdr

y ! n{y}

"cdrz ! n{z} !cdr n!

!"#"cdr

z ! n{z} !cdr n!

!"#"cdr

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 127

Page 7: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

7

Shape•(3) for [z:=y]3

x ! n{x} !cdr n!

!"#"cdr

x ! n{x} !cdr n!

!"#"cdr

y"

z ! n{y,z}

x ! n{x} !cdr n!

y"

z ! n{y,z}

x ! n{x} !cdr n!

!"#"cdr

y"

z ! n{y,z}

#

cdr

x ! n{x} !cdr n!

y"

z ! n{y,z}

#

cdr

x ! n{x}

n!

y"

z ! n{y,z} !cdr

x ! n{x}

n!

!"#"cdr

y"

z ! n{y,z} !cdr n!

!"#"cdr

y"

z ! n{y,z} !cdr n!

!"#"cdr

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 128

Page 8: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

8

Shape•(4) for [y:=x]4

x ! n{x,y} !cdr n!

!"#"cdr

y#

x ! n{x,y} !cdr n!

!"#"cdr

y#

z ! n{z}

x ! n{x,y} !cdr n!

y#

z ! n{z}

x ! n{x,y} !cdr n!

!"#"cdr

y#

z ! n{z}

#

cdr

x ! n{x,y} !cdr n!

y#

z ! n{z}

#

cdr

x ! n{x,y}

n!

y#

z ! n{z} !cdr

x ! n{x,y}

n!

!"#"cdr

y#

z ! n{z} !cdr n!

!"#"cdr

z ! n{z} !cdr n!

!"#"cdr

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 129

Page 9: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

9

Shape•(5) for [x:=x.cdr]5

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}#cdr

x ! n{x} !cdr n!

y ! n{y}#cdr

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}#cdr

z ! n{z}

x ! n{x} !cdr n!

y ! n{y}#cdr

z ! n{z}

x ! n{x} n!

y ! n{y}#cdr

z ! n{z}

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}#cdr

z ! n{z}

#

cdr

x ! n{x} !cdr n!

y ! n{y}#cdr

z ! n{z}

#

cdr

x ! n{x}

n!

y ! n{y}#cdr

z ! n{z} !cdr n!

y ! n{y}

z ! n{z} !cdr

n!

!"#"cdr

y ! n{y}

z ! n{z} !cdr n!

!"#"cdr

z ! n{z} !cdr n!

!"#"cdr

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 130

Page 10: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

10

Shape•(6) for [y.cdr:=z]6

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}

x ! n{x} !cdr n!

y ! n{y}

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}

"cdrz ! n{z}

x ! n{x} !cdr n!

y ! n{y}

"cdrz ! n{z}

x ! n{x} n!

y ! n{y}

"cdrz ! n{z}

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}

"cdrz ! n{z}

#

cdr

x ! n{x} !cdr n!

y ! n{y}

"cdrz ! n{z}

#

cdr

x ! n{x}

n!

y ! n{y}

"cdrz ! n{z} !cdr n!

y ! n{y}

"cdrz ! n{z} !cdr

n!

!"#"cdr

y ! n{y}

"cdrz ! n{z} !cdr n!

!"#"cdr

z ! n{z} !cdr n!

!"#"cdr

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 131

Page 11: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

11

Shape•(7) for [z:=nil]7

x ! n{x} !cdr n!

!"#"cdr

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}

x ! n{x} !cdr n!

y ! n{y}

x ! n{x} !cdr n!

!"#"cdr

y ! n{y}#cdr

x ! n{x} !cdr n!

y ! n{y}#cdr

x ! n{x}

n!

!"#"cdr

y ! n{y} !cdr

x ! n{x}

n!y ! n{y} !cdr n!

!"#"cdr

y ! n{y} !cdr n!

!"#"cdr

– upon termination y points to a non-circular list

– a more precise analysis taking tests into account will know that x isnil upon termination

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 132

Page 12: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Transfer Functions

12

Transfer functions

fSA! : P(SG)! P(SG)

has the form:

fSA! (SG) =

!{"SA

! ((S,H, is)) | (S,H, is) " SG}

where

"SA! : SG ! P(SG)

specifies how a single shape graph (in Shape#(!)) may be transformedinto a set of shape graphs (in Shape•(!)) by the elementary block.

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 133

Page 13: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Guards and skip statements

13

Transfer function for [b]! and [skip]!

We are only interested in the shape of the heap – and it is not changedby these elementary blocks:

"SA! ((S,H, is)) = {(S,H, is)}

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 134

Page 14: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Assignments

14

Transfer function for [x:=a]!— where a is of the form n, a1 opa a2 or nil

"SA! ((S,H, is)) = {killx((S,H, is))}

where killx((S,H, is)) = (S!,H!, is!) is

S! = {(z, kx(nZ)) | (z, nZ) " S # z $= x}H! = {(kx(nV ), sel, kx(nW )) | (nV , sel, nW ) " H}is! = {kx(nX) | nX " is}

and

kx(nZ) = nZ\{x}

Idea: all abstract locations are renamed to not having x in their nameset

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 135

Page 15: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

15

The e!ect of [x:=nil]!

!nV

!sel1

n! "

x " n{x} "sel2 nW

(S,H, is)

!nV "sel1 n! "

nW

!sel2

(S",H", is")

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 136

Page 16: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Assignment (cont)

16

Transfer function for [x:=y]! when x != y

"SA! ((S,H, is)) = {(S"",H"", is"")}

where (S",H", is") = killx((S,H, is)) and

S"" = {(z, gyx(nZ)) | (z, nZ) # S"}

$ {(x, gyx(nY )) | (y", nY ) # S" % y" = y}

H"" = {(gyx(nV ), sel, gy

x(nW )) | (nV , sel, nW ) # H"}

is"" = {gyx(nZ) | nZ # is"}

and

gyx(nZ) =

!nZ${x} if y # Z

nZ otherwise

Idea: all abstract locations are renamed to also have x in their name setif they already have y

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 137

Page 17: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

17

The e!ect of [x:=y]! when x !=y

!

x " nX "

y " nY "sel2 nW

#sel1

nV

(S,H, is)

!

x!

nX\{x} "

y " nY "{x} "sel2 nW

#sel1

nV

(S##,H##, is##)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 138

Page 18: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Heap selection

18

Transfer function for [x:=y.sel]! when x != y

Remove the old binding for x: strong nullification

(S",H", is") = killx((S,H, is))

Establish the new binding for x:

1. There is no abstract location nY such that (y, nY ) # S" – or there isan abstract location nY such that (y, nY ) # S" but no nZ such that(nY , sel, nZ) # H"

2. There is an abstract location nY such that (y, nY ) # S" and there isan abstract location nU != n$ such that (nY , sel, nU) # H"

3. There is an abstract location nY such that (y, nY ) # S" and (nY , sel, n$)# H"

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 139

Transfer function for [x:=y.sel]! when x != y

Remove the old binding for x: strong nullification

(S",H", is") = killx((S,H, is))

Establish the new binding for x:

1. There is no abstract location nY such that (y, nY ) # S" – or there isan abstract location nY such that (y, nY ) # S" but no nZ such that(nY , sel, nZ) # H"

2. There is an abstract location nY such that (y, nY ) # S" and there isan abstract location nU != n$ such that (nY , sel, nU) # H"

3. There is an abstract location nY such that (y, nY ) # S" and (nY , sel, n$)# H"

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 139

Page 19: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Selection: Case (1)

19

Case 1 for [x:=y.sel]!

Assume there is no abstract location nY such that (y, nY ) ! S"

"SA! ((S,H, is)) = {(S",H", is")}

OBS: dereference of a nil-pointer

Assume there is an abstract location nY such that (y, nY ) ! S" but thereis no abstract location n such that (nY , sel, n) ! H"

"SA! ((S,H, is)) = {(S",H", is")}

OBS: dereference of a non-existing sel-field

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 140

Page 20: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Selection: Case (2)

20

Case 2 for [x:=y.sel]!

Assume there is an abstract location nY such that (y, nY ) ! S" and thereis an abstract location nU #= n$ such that (nY , sel, nU) ! H".

The abstract location nU will be renamed to include the variable x usingthe function:

hUx (nZ) =

!nU%{x} if Z = U

nZ otherwise

We take

"SA! ((S,H, is)) = {(S"",H"", is"")}

where (S",H", is") = killx((S,H, is)) and

S"" = {(z, hUx (nZ)) | (z, nZ) ! S"} % {(x, hU

x (nU))}

H"" = {(hUx (nV ), sel ", hU

x (nW )) | (nV , sel ", nW ) ! H"}

is"" = {hUx (nZ) | nZ ! is"}

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 141

Page 21: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

21

The e!ect of [x:=y.sel]! in Case 2

!

x " nX "

y " nY "sel nU "sel2 nW

nV

#sel1

(S,H, is)

!

xnX\{x} "

$y " nY "sel nU!{x} "sel2 nW

nV

#sel1

(S"",H"", is"")

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 142

Page 22: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Selection: Case (3)

22

Case 3 for [x:=y.sel]! (1)

Assume that there is an abstract location nY such that (y, nY ) ! S" andfurthermore (nY , sel, n#) ! H".

We have to materialise a new abstract location n{x} from n#.

[x:=nil]···; [x:=y.sel]!; [x:=nil]···

! ! ! !

(S,H, is)(S",H", is")

(S"",H"", is"")(S""",H""", is""")

Idea:

(S",H", is") = (S""",H""", is""") = killx((S"",H"", is""))

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 143

Page 23: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Materialization

23

Case 3 for [x:=y.sel]! (2)

Transfer function:

"SA! ((S,H, is)) = {(S!!,H!!, is!!) | (S!!,H!!, is!!) is compatible "

killx((S!!,H!!, is!!)) = (S!,H!, is!) "

(x, n{x}) # S!! " (nY , sel, n{x}) # H!! }

where (S!,H!, is!) = killx((S,H, is)).

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 144

Page 24: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

24

The e!ect of [x:=y.sel]! in Case 3 (1)

!

x " nX "

y " nY "sel n! "sel2 nW

nV

#sel1

! "#!sel3

(S,H, is)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 145

Page 25: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

25

The e!ect of [x:=y.sel]! in Case 3 (2)

!

xnX\{x} "

#y " nY "sel n{x}

nV "sel1 n! "sel2 nW!

sel3

(S""1,H""

1, is""1)

!

xnX\{x} "

#y " nY "sel n{x}

nV "sel1 n! "sel2 nW

!"#! sel3

(S""3,H""

3, is""3)

!

xnX\{x} "

#y " nY "sel n{x}

!"#! sel3nV "sel1 n! "sel2 nW

!sel3

(S""5,H""

5, is""5)

!

xnX\{x} "

#y " nY "sel n{x}

nV!

sel3"sel1 n! nW

!

sel2

(S""2,H""

2, is""2)

!

xnX\{x} "

#y " nY "sel n{x}

nV "sel1 n!!

sel2

nW

!"#! sel3

(S""4,H""

4, is""4)

!

xnX\{x} "

#y " nY "sel

n! nW!

sel2

"sel1!

sel3

n{x}

nV

!"#! sel3

(S""6,H""

6, is""6)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 146

Page 26: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Assignment

26

Transfer function for [x.sel:=y]! when x != y

If there is no nX such that (x, nX) " S then fSA! is the identity function.

If (x, nX) " S but there is no nY such that (y, nY ) " S then

"SA! ((S,H, is)) = {killx.sel((S,H, is))}

If there is (x, nX) " S and (y, nY ) " S then

"SA! ((S,H, is)) = {(S##,H##, is##)}

where (S#,H#, is#) = killx.sel((S,H, is)) and

S## = S# (= S)

H## = H# $ {(nX, sel, nY ) | (x, nX) " S# % (y, nY ) " S#}

is## =

!is# $ {nY } if #into(nY ,H#) & 1is# otherwise

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 149

Transfer function for [x.sel:=y]! when x != y

If there is no nX such that (x, nX) " S then fSA! is the identity function.

If (x, nX) " S but there is no nY such that (y, nY ) " S then

"SA! ((S,H, is)) = {killx.sel((S,H, is))}

If there is (x, nX) " S and (y, nY ) " S then

"SA! ((S,H, is)) = {(S##,H##, is##)}

where (S#,H#, is#) = killx.sel((S,H, is)) and

S## = S# (= S)

H## = H# $ {(nX, sel, nY ) | (x, nX) " S# % (y, nY ) " S#}

is## =

!is# $ {nY } if #into(nY ,H#) & 1is# otherwise

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 149

Page 27: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

27

Transfer function for [x.sel:=a]!— where a is of the form n, a1 opa a2 or nil.

If there is no nX such that (x, nX) ! S then fSA! is the identity.

If there is nX such that (x, nX) ! S but that there is no nU such that(nX, sel, nU) ! H then fSA

! is the identity.

If there are abstract locations nX and nU such that (x, nX) ! S and(nX, sel, nU) ! H then

"SA! ((S,H, is)) = {killx.sel((S,H, is))}

where killx.sel((S,H, is)) = (S",H", is") is given by

S" = S

H" = {(nV , sel ", nW ) | (nV , sel ", nW ) ! H # ¬(X = V # sel = sel ")}

is" =

!is\{nU} if nU ! is # #into(nU,H") $ 1 # ¬%(n&, sel ", nU) ! H"

is otherwise

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 147

Transfer function for [x.sel:=a]!— where a is of the form n, a1 opa a2 or nil.

If there is no nX such that (x, nX) ! S then fSA! is the identity.

If there is nX such that (x, nX) ! S but that there is no nU such that(nX, sel, nU) ! H then fSA

! is the identity.

If there are abstract locations nX and nU such that (x, nX) ! S and(nX, sel, nU) ! H then

"SA! ((S,H, is)) = {killx.sel((S,H, is))}

where killx.sel((S,H, is)) = (S",H", is") is given by

S" = S

H" = {(nV , sel ", nW ) | (nV , sel ", nW ) ! H # ¬(X = V # sel = sel ")}

is" =

!is\{nU} if nU ! is # #into(nU,H") $ 1 # ¬%(n&, sel ", nU) ! H"

is otherwise

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 147

Page 28: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

28

The e!ect of [x.sel:=nil]! when #into(nU,H!) "1

x ! nX !sel nU !

n#

"##

nV

$sel1

(S,H, is)

x ! nX nU !"

##

n#

nV

$sel1

(S!,H!, is!)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 148

The e!ect of [x.sel:=nil]! when #into(nU,H!) "1

x ! nX !sel nU !

n#

"##

nV

$sel1

(S,H, is)

x ! nX nU !"

##

n#

nV

$sel1

(S!,H!, is!)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 148

Page 29: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

29

Transfer function for [x.sel:=y]! when x != y

If there is no nX such that (x, nX) " S then fSA! is the identity function.

If (x, nX) " S but there is no nY such that (y, nY ) " S then

"SA! ((S,H, is)) = {killx.sel((S,H, is))}

If there is (x, nX) " S and (y, nY ) " S then

"SA! ((S,H, is)) = {(S##,H##, is##)}

where (S#,H#, is#) = killx.sel((S,H, is)) and

S## = S# (= S)

H## = H# $ {(nX, sel, nY ) | (x, nX) " S# % (y, nY ) " S#}

is## =

!is# $ {nY } if #into(nY ,H#) & 1is# otherwise

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 149

Transfer function for [x.sel:=y]! when x != y

If there is no nX such that (x, nX) " S then fSA! is the identity function.

If (x, nX) " S but there is no nY such that (y, nY ) " S then

"SA! ((S,H, is)) = {killx.sel((S,H, is))}

If there is (x, nX) " S and (y, nY ) " S then

"SA! ((S,H, is)) = {(S##,H##, is##)}

where (S#,H#, is#) = killx.sel((S,H, is)) and

S## = S# (= S)

H## = H# $ {(nX, sel, nY ) | (x, nX) " S# % (y, nY ) " S#}

is## =

!is# $ {nY } if #into(nY ,H#) & 1is# otherwise

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 149

Page 30: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Example

30

The e!ect of [x.sel:=y]! when #into(nY ,H!) "1

x ! nX !sel nU

y ! nY

"

##

(S,H, is)

x ! nX

$sel

nU

y ! nY

"

##

(S!,H!!, is!!)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 150

The e!ect of [x.sel:=y]! when #into(nY ,H!) "1

x ! nX !sel nU

y ! nY

"

##

(S,H, is)

x ! nX

$sel

nU

y ! nY

"

##

(S!,H!!, is!!)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 150

The e!ect of [x.sel:=nil]! when #into(nU,H!) "1

x ! nX !sel nU !

n#

"##

nV

$sel1

(S,H, is)

x ! nX nU !"

##

n#

nV

$sel1

(S!,H!, is!)

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 148

Page 31: Code Generation and Virtual Machines · Analysis 3 The analysis An instance of a forward Monotone Framework with the complete lattice of interest being P(SG) A may analysis: each

Allocation

31

Transfer function for [malloc x]!

"SA! ((S,H, is)) = {(S! " {(x, n{x})},H

!, is!)}

where (S!,H!, is!) = killx(S,H, is).

PPA Section 2.6 c! F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 151