Docsity

Flow and Context Sensitive Pointer Analysis - Senior Research Project | ECE 497, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 497MF Multithreaded Computer Architecture
February 25, 2004
Lecture 11: Flow and Context Sensitive Pointer Analysis
Scribe: Kapil Sachdeva
1 Pointer Analysis
As explained in previously, the goal of static pointer analysis is a to determine
the set of possible locations in a program a pointer may hold. This procedure was
referred to as a “points-to analysis”. In th is analysis, pointers hold the location of static
allocation regions associated with global variables, malloc statements, and automatic
variables in the frame of a procedure.
1.1 Flow-and-Context Sensitive Pointer Analysis
In the last lecture this analysis was context and flow insensitive. In Foo(), for
example, because the analysis is insensitive to control flow, the integer pointer u could
point to p or q. Thus, copies of pointer variables translate into a union of their “po ints-to”
sets. That is, the control flow graph is disregarded in a flow insensitive analysis.
Similarly, because the analysis ignored context, in bar() and baz(), the integer pointers s
and r could point to the integer variables a, b, or c.
int* Foo( int *p, int *q )
{
if ( p == q ) {
r = 7;
u = p;
} else {
u = q;
}
return q;
}
void bar()
{
int a;
int *r;
. . .
r = Foo( &a, &a );
. . .
}
pf3
pf4
pf5

Partial preview of the text

Download Flow and Context Sensitive Pointer Analysis - Senior Research Project | ECE 497 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

ECE 497MF Multithreaded Computer Architecture

February 25, 2004 Lecture 11: Flow and Context Sensitive Pointer Analysis Scribe: Kapil Sachdeva

1 Pointer Analysis

As explained in previously, the goal of static pointer analysis is a to determine the set of possible locations in a program a pointer may hold. This procedure was referred to as a “ points to analysis”. In th is analysis, pointers hold the location of static allocation regions associated with global variables, malloc statements, and automatic variables in the frame of a procedure.

1.1 Flow and Context Sensitive Pointer Analysis

In the last lecture this analysis was context and flow insensitive. In Foo(), for example, because the analysis is insensitive to control flow, the integer pointer u could point to p or q. Thus, copies of pointer variables translate into a union of their “po intsto ” sets. That is, the control flow graph is disregarded in a flow insensitive analysis. Similarly, because the analysis ignored context, in bar() and baz(), the integer pointers s and r could point to the integer variables a, b, or c. int* Foo( int *p, int *q ) { if ( p == q ) { r = 7; u = p; } else { u = q; } return q; } void bar() { int a; int *r;

... r = Foo( &a, &a ); ... }

void baz() { int b; int c; int *s;

... s = Foo( &b, &c ); ... }

1.2 Flow Sensitive Pointer Analysis

In a flow sensitive analysis, copies of pointer variables translate into a simple copies of the assigned variable's pointsto set, and join points in the control flow graph correspond to unions of the variables' points to sets. Join points must be unions of the pointsto s ets because it is not known which of the paths between the join point and the branch point was executed. The function Foo() below shows that copy points are just copies of pointsto sets. In figure 1, p initially has the pointsto se t {A} and q points to {B}. At the join node, p can point to {A, B}. int Foo() {

... p = malloc( ... ); // p> { A } q = malloc( ... ); // q> { B } v = *p; // v> { A } p = q; // p> { B } ... }

Figure 2 This “ 2N^ way” of being context sensitive is slow. There are other techniques that might speed up context sensitive analysis, namely memoization and using a symbolic representation between function arguments. Memoization is a technique that attempts to use previouslyc omputed values before performing a computation. For example, in computing the Fibonacci sequence, a table of previously computed Fibonacci numbers would be kept around to speed up the computation of other Fibonacci numbers. In evaluating Fib4— the fifth Fibonacci number —on e might begin by evaluating Fib 2. Fib 2 is equal to the sum of Fib 1 and Fib 0 , which are in the memoization table. The result of the addition, Fib 2 , is then stored in the table. Then, to calculate Fib 3 , instead of expanding the computations of Fib 2 and Fib 1 , the values are simply read from the table. For pointer analysis, memoization does not help. The problem is that, often times, a procedure call is invoked with a set of parameters only once. It is not in the memoization table the first and only time it is called. Since there are no future invocations of the procedure with those specific parameters, memoization has not helped speed up points to analysis. begin begin end end void Foo( int *q) s = malloc( ... ) //{A} r = malloc( ... ) //{B} call Foo( s ) call Foo( r ) p=q if( cond1 ) if( cond2 ) E

Instead, one might want to represent a symbolic relationship between function arguments to speed up a contexts ensitive analysis. Here, if the arguments to a function are similar to those used in the past, then we use the results from that invocation. Here, the sets used represent a summary of what arguments were passed in. The context is the contents of the function arguments and the state of any global variables that the procedure might read. Consider the procedure Foo() below. The effect of Foo() depends on if p equals r. If p equals r, then p, q, and r point to the same location. Otherwise, they point to different locations. The function Foo() could depend on the equality of p and r. So one can memoize these two cases. If p, q, and r are different, let p point to { 1}, q point to {2}, and r point to { 3}. Otherwise if p equals r, then p and r point to {1} a nd q points to { 2}. If Foo() is called with p, q, and r different, the results of the procedure are memoized. Now if Foo() is called again with unequal parameters, the memoized results can be used. Usually, the number of contexts in which a procedure is called is small; thus, the memoization tables are small. void Foo( int *p, int *q, int *r ) {

... *p = *q; *q = *r; ... }

2 Dynamic Pointer Analysis

Renaming on a superscalar processor is done to avoid output and anti dependences. An output dependence is a dependence between two store instructions to the same memory location. An anti dependence is a dependence between a load and a store to the same memory location. This allows the outof order execution of instructions in the scoreboard. For loads and stores, it is often not possible to execute out of order because one cannot determine the address of a load or store until late in their execution. It is often desired, however, to execute them out of order. One may execute loads and stores out of order and check for conflicts before they are committed. A runtime memory dependence validation protocol based on timestamp ordering may also be used (Bernstein & Goodman, 1980). Every memory location is assigned a last read timestamp tL and a last written timestamp tS. If the timestamp t 1 associated with a load to memory is less than tS, then a future value of this location is being read out. Memory would return an incorrect value. If a store with timestamp t 1 attempts to write to a location whose tL is greater than t 1 , then a load that has already executed may have received a future value.