CS553 Colorado State University =============================================== Interprocedural Analysis =============================================== 12/8/09 -------------------- What is Datalog? -> slides 10-13 in John Whaley's PLDI Tutorial slides. http://suif.stanford.edu/~jwhaley/PLDITutorial.ppt -> graph example with bddbddb path.dtl and edge.tuples -> academic family tree example with bddbddb family.dtl and child.tuples -> then add rules from slide 14 family-extend.dtl -------------------- Reaching definitions in Datalog - how does the example in slide 15 match the book? It doesn't but I like the formulation in the slides better. -> have students construct the statementAt, assign, and follows tuples files for our typical data-flow example They need a mapping for each domain they are dealing with, which maps integers to names. They need a .tuples files that encodes the relationships in the program. -> work on checking the output -------------------- Relationship between datalog and BDDs -> slides 34-46 -------------------- How to specify Andersens and Steensgaard in Datalog ---------------- Andersens Program a = &b c = a a = &d e = a Constraints ptsto(a) = {b,d} ptsto(c) superseteq ptsto(a) ptsto(e) superseteq ptsto(a) Answer ptsto(c) = ptsto(a) = {b,d} ptsto(e) = ptsto(a) = {b,d} Specifying the analysis in datalog Different than book because we are encoding a stack-only pointer analysis. output ptsto(v,w) means stack variable v can point at stack variable w input addressof(a,b) means a contains the address of b, a=&b ptrassign(p,q) means that p has been assigned the pointer value q, p=q dereflhs(p,q) means *p=q derefrhs(p,q) means p=*q rules to solve with Andersens ptsto(a,b) :- addressof(a,b). ptsto(p,x) :- ptrassign(p,q), ptsto(q,x). ptsto(y,x) :- dereflhs(p,q), ptsto(q,x), ptsto(p,y). ptsto(p,y) :- derefrhs(p,q), ptsto(q,x), ptsto(x,y). # Goes with example on slide 12 of lecture22-aliasanalysis.ppt. # p is 1, q is 2, x is 3, a is 4, b is 5, d is 6, # f is 7, c is 8, e is 9, g is 10 # t1 is 11, t2 is 12 int g; int** foo(int **p, **q) { int **x; x = p; . . . x = q; return x; } int main() { int **a, *b, *d, *f, c, e, t1, t2; a = foo(&b, &f); t1 = &c; *a = t1; a = foo(&d, &g); t2 = &e; *a = t2; } Answer should be p -> {b,d} (1,5), (1,6) q -> {f,g} (2,7), (2,10) t1-> {c} (11,8) t2-> {e} (12,9) x -> {b,d,f,g} (3,5), (3,6), (3,7), (3,10) a -> {b,d,f,g} (4,5), (4,6), (4,7), (4,10) b -> {c,e} (5,8), (5,9) d -> {c,e} (6,8), (6,9) f -> {c,e} (7,8), (7,9) g -> {c,e} (10,8), (10,9) ---------------- Steensgaard More efficiently solved with a union/find data structure instead of using datalog and BDDs, but here is the datalog specification extending Andersen rules to solve for Steensgaard ptsto(a,b) :- addressof(a,b). ptsto(p,x) :- ptrassign(p,q), ptsto(q,x). ptsto(y,x) :- dereflhs(p,q), ptsto(q,x), ptsto(p,y). ptsto(p,y) :- derefrhs(p,q), ptsto(q,x), ptsto(x,y). # extension is modification of last three rules ablve ptsto(q,x) :- ptrassign(p,q), ptsto(p,x). ptsto(q,x) :- dereflhs(p,q), ptsto(p,y), ptsto(y,x). ptsto(q,y) :- derefrhs(p,q), ptsto(p,y), ptsto(q,x). # Goes with example on slide 12 of lecture22-aliasanalysis.ppt. # p is 1, q is 2, x is 3, a is 4, b is 5, d is 6, # f is 7, c is 8, e is 9, g is 10 Answer is p -> {b,d,f,g} (1,5), (1,6), (1,7), (1,10) q -> {f,g,b,d} (2,7), (2,10), (2,6), (2,5) t1-> {c} (11,8), (11,9) t2-> {e} (12,9), (12,8) x -> {b,d,f,g} (3,5), (3,6), (3,7), (3,10) a -> {b,d,f,g} (4,5), (4,6), (4,7), (4,10) b -> {c,e} (5,8), (5,9) d -> {c,e} (6,8), (6,9) f -> {c,e} (7,8), (7,9) g -> {c,e} (10,8), (10,9) -------------------- mstrout@cs.colostate.edu, 12/8/09