27
Reps Horwitz and Sagiv 95 (RHS) Another approach to context- sensitive interprocedural analysis Express the problem as a graph reachability query Works for distributive problems

Reps Horwitz and Sagiv 95 (RHS) Another approach to context-sensitive interprocedural analysis Express the problem as a graph reachability query Works

  • View
    217

  • Download
    2

Embed Size (px)

Citation preview

Reps Horwitz and Sagiv 95 (RHS)

• Another approach to context-sensitive interprocedural analysis

• Express the problem as a graph reachability query

• Works for distributive problems

Reps Horwitz and Sagiv 95 (RHS)g() {

if(isLocked()) {

unlock;

} else {

lock;

}}

f() { g(); if (...) { main(); }}

main() {

g();

f();

lock;

unlock;

}

Reps Horwitz and Sagiv 95 (RHS)g() {

if(isLocked()) {

unlock;

} else {

lock;

}}

f() { g(); if (...) { main(); }}

main() {

g();

f();

lock;

unlock;

}

Reps Horwitz and Sagiv 95 (RHS)g() {

if(isLocked()) {

unlock;

} else {

lock;

}}

f() { g(); if (...) { main(); }}

main() {

g();

f();

lock;

unlock;

}

In class excersice

main() {

f()

}

f() {

if(Unlocked()) {

lock

f()

} else {

unlock

}

}

In class excersice

main() {

f()

}

f() {

if(Unlocked()) {

lock

f()

} else {

unlock

}

}

Procedure specialization

• Interprocedural analysis is great for callers

• But for the callee, information is still mergedmain() { x := new A(...); y := x.g(); y.f();

x := new A(...); y := x.g(); y.f();

x := new B(...); y:= x.g(); y.f();}

// g too large to inlineg(x) { x.f(); // lots of code return x;}

// but want to inline ff(x@A) { ... }f(x@B) { ... }

Procedure specialization

• Specialize g for each dataflow information

• “In between” inlining and context-sensitve interproc

main() { x := new A(...); y := x.g1(); y.f();

x := new A(...); y := x.g1(); y.f();

x := new B(...); y:= x.g2(); y.f();}

g1(x) { x.f(); // can now inline // lots of code return x;}g2(x) { x.f(); // can now inline // lots of code return x;}

// but want to inline ff(x@A) { ... }f(x@B) { ... }

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

Recap using pictures

A() {

}

D’

B() {

}

D’’

C() {

}

D’’’

Inlining

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

caller summary

callee summary

Context-insensitive summary

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

context sensitivesummary

Context sensitive summary

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

D’() { ...

}

Procedure Specialization

A() { call D }

B() { call D }

C() { call D }

D() { ...

}

Comparison

Caller precision Callee precision Code bloat

Inlining

context-insensitive interproc

Context sensitive interproc

Specialization

Comparison

Caller precision Callee precision code bloat

Inlining , because contexts are kept separate

, because contexts are kept separate

may be large if we want to get the best precision

context-insensitive interproc

, because contexts are merged

, because contexts are merged

none

Context sensitive interproc

, because of context sensitive summaries

, because contexts are still merged when optimizing callees

none

Specialization , contexts are kept separate

, contexts are kept separate

Some, less than inlining

Summary on how to optimize function calls

• Inlining

• Tail call optimizations

• Interprocedural analysis using summaries– context sensitive– context insensitive

• Specialization

Cutting edge research

• Making interprocedural analysis scalable

• Optimizing first order function calls

• Making inlining effective in the presence of dynamic dispatching and class loading

Pointer analysis

Pointer Analysis

• Outline:– What is pointer analysis– Intraprocedural pointer analysis– Interprocedural pointer analysis

• Andersen and Steensgaard

Pointer and Alias Analysis

• Aliases: two expressions that denote the same memory location.

• Aliases are introduced by:– pointers– call-by-reference– array indexing– C unions

Useful for what?

• Improve the precision of analyses that require knowing what is modified or referenced (eg const prop, CSE …)

• Eliminate redundant loads/stores and dead stores.

• Parallelization of code– can recursive calls to quick_sort be run in parallel? Yes,

provided that they reference distinct regions of the array.

• Identify objects to be tracked in error detection tools

x := *p;...y := *p; // replace with y := x?

*x := ...;// is *x dead?

x.lock();...y.unlock(); // same object as x?

Kinds of alias information

• Points-to information (must or may versions)– at program point, compute a set of pairs of the form p ! x, where p

points to x.– can represent this information

in a points-to graph

• Alias pairs– at each program point, compute the set of of all pairs (e1,e2) where

e1 and e2 must/may reference the same memory.

• Storage shape analysis– at each program point, compute an

abstract description of the pointer structure.

px

y

z

p

Intraprocedural Points-to Analysis

• Want to compute may-points-to information

• Lattice:

Flow functions

x := a + b

in

out

Fx := a+b(in) =

x := k

in

out

Fx := k(in) =

Flow functions

x := &y

in

out

Fx := &y(in) =

x := y

in

out

Fx := y(in) =

Flow functions

*x := y

in

out

F*x := y(in) =

x := *y

in

out

Fx := *y(in) =

Intraprocedural Points-to Analysis

• Flow functions: