140 likes | 171 Views
Advanced Compilers CMPSCI 710 Spring 2003 Pointer Analysis. Emery Berger University of Massachusetts, Amherst. Pointer Analysis. (= alias analysis, = points-to analysis) Goal: statically determine possible runtime values of a pointer Necessary for optimizations, error detection
E N D
Advanced CompilersCMPSCI 710Spring 2003Pointer Analysis Emery Berger University of Massachusetts, Amherst
Pointer Analysis (= alias analysis, = points-to analysis) • Goal: statically determine possible runtime values of a pointer • Necessary for optimizations, error detection • Vital for C, C++ but: • Undecidable • Luckily: good approximations • Trade-off efficiency & precision • Result: points-to sets
Points-to sets if () p = &a; else p = &b; *p = 3; { a , b }
Analysis Sensitivity • Flow-insensitive • What may happen (on at least one path) • Linear-time • Flow-sensitive • Consider control flow (what must happen) • Iterative data-flow: possibly exponential • Context-insensitive • Call treated the same regardless of caller • “Monovariant” analysis • Context-sensitive • Reanalyze callee for each caller • “Polyvariant” analysis • More sensitivity ) more accuracy, but more expense
Flow-Sensitive Pointer Analysis • Too bad it’s exponential…
Flow-Insensitivity: Dimensions • Address-taken • Any object whose address is taken = potential alias • Brain-dead, widely used in practice • Equality-based • Treat assignments as bidirectional • Steensgaard’s • Almost linear • Subset-based • Assignment is unidirectional • Andersen’s • Polynomial complexity • Up to 30 times slower, but more precise
p q p p q q Steensgaard’s Algorithm p = q;
r1 p = &q; p q r2 p = q; r1 p = *q; q p r2 *p = q; r3 Andersen’s Algorithm p = &q; p = q;
s1 r1 p s2 q r2 s3 r1 s1 q p r2 s2 Andersen’s Algorithm p = *q; *p = q;
Analysis Examples Compare points-to sets at S5: • Address-taken • One set of objects for whole program • {heapS1, heapS4, heapS6, heapS8, local, p, q} • Steensgaard’s • Union two objects pointed to by same pointer into one • {heapS1, heapS4, heapS6, local} • Andersen’s • Don’t merge objects • {heapS1, heapS4, local}
More Dimensions • Heap modeling • Objects can be named by allocation site • Source line, n-levels in call stack • More sophisticated shape analysis • Aggregate modeling • Elements (of arrays structs, unions) distinct • Or collapsed into one object
Haven’t We Solved This Problem Yet? From [Hind, 2001]: • Past 21 years: at least 75 papers and nine Ph.D. theses published on pointer analysis
So Which Pointer Analysis is Best? • Comparisons between algorithms difficult • Size of points-to sets inadequate • Model heap as one blob = one object for all heap pointers! • Trade-offs unclear • Faster pointer analysis can mean more objects= more time for client analysis • More precise analysis can reduce client analysis time! • Idea: use client to drive pointer analyzer…