{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture-14-6up

lecture-14-6up - Simple example x:= 5 ptr:[email protected]*ptr:= 9 y:= x...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Analysis of programs with pointers Wednesday, November 30, 2011 Simple example What are the dependences in this program? Problem: just looking at variable names will not give you the correct information After statement S2, program names “x” and “*ptr” are both expressions that refer to the same memory location. We say that ptr points-to x after statement S2. In a C-like language that has pointers, we must know the points-to relation to be able to determine dependences correctly x := 5 ptr := @x *ptr := 9 y := x S1 S2 S3 S4 dependences program Wednesday, November 30, 2011 Program model For now, only types are int and int* No heap – All pointers point to only to stack variables No procedure or function calls Statements involving pointer variables: – address: x := &y – copy: x := y – load: x := *y – store: *x := y Arbitrary computations involving ints Wednesday, November 30, 2011 Points-to relation Directed graph: – nodes are program variables – edge (a,b): variable a points-to variable b Can use a special node to represent NULL Points-to relation is different at different program points x ptr y Wednesday, November 30, 2011 Out-degree of node may be more than one – if points-to graph has edges (a,b) and (a,c), it means that variable a may point to either b or c – depending on how we got to that point, one or the other will be true – path-sensitive analyses: track how you got to a program point (we will not do this) Points-to graph if (p) then x := &y else x := &z ….. p x := &y x := &z What does x point to here? Wednesday, November 30, 2011 Ordering on points-to relation Subset ordering: for a given set of variables – Least element is graph with no edges – G1 <= G2 if G2 has all the edges G1 has and maybe some more Given two points-to relations G1 and G2 – G1 U G2: least graph that contains all the edges in G1 and in G2 Wednesday, November 30, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Overview We will look at three different points-to analyses. Flow-sensitive points-to analysis Dataflow analysis Computes a different points-to relation at each point in program Flow-insensitive points-to analysis Computes a single points-to graph for entire program Andersen’s algorithm Natural simplification of flow-sensitive algorithm Steensgard’s algorithm Nodes in tree are equivalence classes of variables if x may point-to either y or z, put y and z in the same equivalence class Points-to relation is a tree with edges from children to parents rather than a general graph Less precise than Andersen’s algorithm but faster Wednesday, November 30, 2011 Example x := &z ptr := @x y := @w ptr := @y ptr x z y w ptr x z y w ptr x,y z,w Flow-sensitive algorithm Andersen’s algorithm Steensgard’s algorithm Wednesday, November 30, 2011 Notation Suppose S and S1 are set-valued variables.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}