A Context-Sensitive Pointer Analysis Phase in Open64 Compiler Tianwei Sheng, Wenguang Chen, Weimin Zheng Tsinghua University.

Slides:



Advertisements
Similar presentations
R O O T S Field-Sensitive Points-to-Analysis Eda GÜNGÖR
Advertisements

Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Pointer Analysis.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009.
Efficient Field-Sensitive Pointer Analysis for C David J. Pearce, Paul H.J. Kelly and Chris Hankin Imperial College, London, UK
Demand-driven Alias Analysis Implementation Based on Open64 Xiaomi An
Flow insensitive pointer analysis: fixed S1: l := new Cons p := l S2: t := new Cons *p := t p := t l p S1 l p tS2 l p S1 t S2 l t S1 p S2 l t S1 p S2 l.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Pointer Analysis.
1 Automatic Predicate Abstraction of C Programs Parts of the slides are from
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
University of Houston Extending Global Optimizations in the OpenUH Compiler for OpenMP Open64 Workshop, CGO ‘08.
Parameterized Object Sensitivity for Points-to Analysis for Java Presented By: - Anand Bahety Dan Bucatanschi.
The Ant and The Grasshopper Fast and Accurate Pointer Analysis for Millions of Lines of Code Ben Hardekopf and Calvin Lin PLDI 2007 (Best Paper & Best.
Semi-Sparse Flow-Sensitive Pointer Analysis Ben Hardekopf Calvin Lin The University of Texas at Austin POPL ’09 Simplified by Eric Villasenor.
Interprocedural analysis © Marcelo d’Amorim 2010.
Pointer and Shape Analysis Seminar Context-sensitive points-to analysis: is it worth it? Article by Ondřej Lhoták & Laurie Hendren from McGill University.
Feedback: Keep, Quit, Start
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
Interprocedural analyses and optimizations. Costs of procedure calls Up until now, we treated calls conservatively: –make the flow function for call nodes.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Context-Sensitive Flow Analysis Using Instantiation Constraints CS 343, Spring 01/02 John Whaley Based on a presentation by Chris Unkel.
Interprocedural pointer analysis for C We’ll look at Wilson & Lam PLDI 95, and focus on two problems solved by this paper: –how to represent pointer information.
KQS More exercises/practice What about research frontier? Reading material Meetings for project Post notes more promptly.
Previous finals up on the web page use them as practice problems look at them early.
Scaling CFL-Reachability-Based Points- To Analysis Using Context-Sensitive Must-Not-Alias Analysis Guoqing Xu, Atanas Rountev, Manu Sridharan Ohio State.
Range Analysis. Intraprocedural Points-to Analysis Want to compute may-points-to information Lattice:
1 Refinement-Based Context-Sensitive Points-To Analysis for Java Manu Sridharan, Rastislav Bodík UC Berkeley PLDI 2006.
Intraprocedural Points-to Analysis Flow functions:
Java Alias Analysis for Online Environments Manu Sridharan 2004 OSQ Retreat Joint work with Rastislav Bodik, Denis Gopan, Jong-Deok Choi.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Comparison Caller precisionCallee precisionCode bloat Inlining context-insensitive interproc Context sensitive interproc Specialization.
Reps Horwitz and Sagiv 95 (RHS) Another approach to context-sensitive interprocedural analysis Express the problem as a graph reachability query Works.
Schedule Midterm out tomorrow, due by next Monday Final during finals week Project updates next week.
An Efficient Inclusion-Based Points-To Analysis for Strictly-Typed Languages John Whaley Monica S. Lam Computer Systems Laboratory Stanford University.
Transfer functions Our pairs of summaries look like functions from input information to output information We call these transfer functions Complete transfer.
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
Symbolic Path Simulation in Path-Sensitive Dataflow Analysis Hari Hampapuram Jason Yue Yang Manuvir Das Center for Software Excellence (CSE) Microsoft.
Making Object-Based STM Practical in Unmanaged Environments Torvald Riegel and Diogo Becker de Brum ( Dresden University of Technology, Germany)
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University STATIC ANALYSES FOR JAVA IN THE PRESENCE OF DISTRIBUTED COMPONENTS AND.
Automatic Data Partitioning in Software Transactional Memories Torvald Riegel, Christof Fetzer, Pascal Felber (TU Dresden, Germany / Uni Neuchatel, Switzerland)
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Pointer Analysis Lecture 2 G. Ramalingam Microsoft Research, India.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Mark Marron 1, Deepak Kapur 2, Manuel Hermenegildo 1 1 Imdea-Software (Spain) 2 University of New Mexico 1.
© Copyright 2010 Hewlett-Packard Development Company, L.P. 1 Rick Hank, Loreena Lee, Rajiv Ravindran, Hui Shi Java, Compilers & Tools Lab, Hewlett Packard,
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
1 The System Dependence Graph and its use in Program Slicing.
Dataflow Analysis for Concurrent Programs using Datarace Detection Ravi Chugh, Jan W. Voung, Ranjit Jhala, Sorin Lerner LBA Reading Group Michelle Goodstein.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Pointer Analysis Survey. Rupesh Nasre. Aug 24, 2007.
Pointer Analysis for Multithreaded Programs Radu Rugina and Martin Rinard M I T Laboratory for Computer Science.
Data Flow Analysis for Software Prefetching Linked Data Structures in Java Brendon Cahoon Dept. of Computer Science University of Massachusetts Amherst,
CS 343 presentation Concrete Type Inference Department of Computer Science Stanford University.
Parameter Passing Mechanisms CS308 Compiler Theory.
Escape Analysis for Java Will von Rosenberg Noah Wallace.
Pointer Analysis. Rupesh Nasre. Advisor: Prof R Govindarajan. Apr 05, 2008.
Pointer Analysis – Part I CS Pointer Analysis Answers which pointers can point to which memory locations at run-time Central to many program optimization.
1PLDI 2000 Off-line Variable Substitution for Scaling Points-to Analysis Atanas (Nasko) Rountev PROLANGS Group Rutgers University Satish Chandra Bell Labs.
Pointer Analysis CS Alias Analysis  Aliases: two expressions that denote the same memory location.  Aliases are introduced by:  pointers  call-by-reference.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Inter-procedural analysis
Phoenix Based Dynamic Slicing Debugging Tool Eric Cheng Lin Xu Matt Gruskin Ravi Ramaseshan Microsoft Phoenix Intern Team (Summer '06)
Run-Time Environments Chapter 7
Compositional Pointer and Escape Analysis for Java Programs
Hongtao Yu Wei Huo ZhaoQing Zhang XiaoBing Feng
Demand-Driven Context-Sensitive Alias Analysis for Java
Pointer analysis.
UNIT V Run Time Environments.
Hongtao Yu Wei Huo ZhaoQing Zhang XiaoBing Feng
Presentation transcript:

A Context-Sensitive Pointer Analysis Phase in Open64 Compiler Tianwei Sheng, Wenguang Chen, Weimin Zheng Tsinghua University

outline Motivation Definitions & State of the Art Summary High Level Design Context-Sensitive Pointer Analysis Field-Sensitive Pointer Analysis Global Variable Graph Preliminary Experiment Results Future Work Conclusion 2

Motivation Very important for compiler and program analysis tools Many inter-procedural analysis phases need alias information  Lock-set Based Static Data Race Detection  Mod-Ref Analysis  Data Layout More precise information clients get, more accurate results the clients can produce In open64, still based on Steensgaard’95 algorithm

Examples (a)(b) void foo(int index,int *p, int *q) { int i; for(i = 0; i < index; i++) { *(p + i) = *q; } } pthread_mutex_t lock1; pthread_mutex_t lock2; int x, y; void foo(int*p, int *q) { pthread_mutex_lock(&lock1); *p = 1; pthread_mutex_unlock(&lock1); *q = 2; } void bar() { p = &x; q = &y; foo(p,q); }

Definitions & State of the Art Summary AlgorithmEq/Sub/ReachCS CG CS heap FS/FIlanuageShown to ScaleNotes LattnerEqXXFSC/C++XPLDI‘07 Steensgaard(CS)EqXXFSC/C++X Microsoft’ latest progress ScridharanReachXXFSJavaXPLDI‘06 BenSubFSC/C++XPLDI’07 ZhengReachFICXPOPL‘08 Zhu/WhaleySubFSJavaXPLDI’04 FahandrichEqC/C++XPLDI‘00 WilsonSubXFSC/C++PLDI’95 LiangEqXFSC/C++SAS‘01 GuyerSubXSAS‘03 Defintions:  Context-Sensitive: consider the calling context of each callsites  Field-Sensitive: distinguish the individual member of structure variables  Equality/Subset: methods to model the pointer assignments, also known as Steensgaard and Andersen methods  Heap cloning: be able to distinguish the memory location on the heap State of the Art:

High Level Design(1) (a): IPA framework (b): existing alias analysis framework Problem:  IPA phases can not make use of any pointer analysis results  The existing algorithm is context-insensitive, field-insensitive

High Level Design(2) The new phase : after Call Graph Construction and DFE(Dead Function Elimination)  Use IPA_Node to read all WHIRL tree  DFE can use simple address taken techniques to eliminate dead functions. Major components  Local Phase: apply a new local phase to read all WHIRL tree and create the local alias graph  Bottom-Up Phase: Major context-sensitive phase, use cloning to inline the pointer information of callee into caller  Top-Down Phase: Incorporate caller’s information into callee and eliminate the incomplete information in callee due to formal parameters

High Level Design(3) IPA IPO Intra-Procedural Phase Call Graph Construction and DFE New Context Sensitive Pointer Analysis Phase Other Analysis Phases The Inter-procedural Pointer Information will be passed into Intra Phase

Context-Sensitive Pointer Analysis int foo(int **p, int*q) { *p = q; *q = 1; } int main() { int b, y; int *a, *t; foo(&a,&b); foo(&t,&y); printf(“b = %d\n",b); printf("y = %d\n",y); return 0; } Context-sensitive: p1 = &a; p2 = &t; q1 = &b; q2 = &y; *p1 = q1 *p2 = q2 *q1 = 1; *q2 = 1; Solution: a->{b}, t->{y} Context-insensitive: p = &a; p = &t; q = &b; q = &y; *p = q *q = 1 Solution: s->{b,y}, t->{b,y}

Context-Sensitive (continued) We use the Cloning(Lattner,PLDI’07) methods to achieve context-sensitivity Basic Constructs:  Alias Node: denote the memory location for variables  Alias Rep: Unify several Alias Nodes into an Alias Rep (Unification Methods)  Alias Graph: The points-to relations set, where the edges denotes the points-to relations

Context-Sensitive (continued) typedef struct { int a; int *s; }STR; int x; STR str; extern STR* bar(STR*); STR* foo(int **q) { STR* str_p; int *p; p = &x; str_p = bar(&str); str_p->s = p; *q = p; return str_p; }

Context-Sensitive : detailed algorithm Local Phase  Traverse every PU,visit each statements in the PU and create the local alias graph(callsite, return value, formal param information). The only phase which inspects the IR Bottom-Up Phase  Inline Callee’s Alias Graph into Caller. Only copy reachable nodes into caller since the scope of local variable in callee does not include caller  Use a SCC (Strong Connect Component) detection algorithm to visit all functions, and for recursive functions that form a SCC, Merge all function inside the SCC into a single alias graph.  Treat function pointers as normal pointers, and resolve them during the SCC visit algorithm, update the caller graph on the fly  For global variables, create the global variables graph to hold all global variables in the program, update the local graph and global graph interactively.

Context-Sensitive (continued) int foo(int **p, int*q) { *p = q; *q = 1; } int main() { int b, y; int *a, *t; foo(&a,&b); foo(&t,&y); printf(“b = %d\n",b); printf("y = %d\n",y); return 0; } (a) :Local graph for main (b) :Local graph for foo (c) :BU graph for main

Why Top-Down Phase? 1.After Bottom-Up phase, foo’s alias graph is copied into the bar. 2.Without inlining, we still do not know the alias information for the formal parameter of foo, p and q 3.The top-down phase will copy the a and x into foo, and make p and q point-to respectively

Field-Sensitive Pointer Analysis an alias node for each member of structures variables, collapse if consistent access pattern disable/enable field-sensitive, field number threshold Problems: in C/C++, we can take the address of the field member, we solve this problem through matching the type information for ADD’s parent WHIRL node struct List{ struct List* forward; struct List* backward; }; struct Hosp{ int c; struct List waiting; struct List assess; }; struct Hosp* hosp_p = &hosp; addList(&hosp_p->assess); addList_2(&(hosp_p->assess.forward)); LOC 1 26 addList(&hosp_p->assess); U8U8LDID 0 T U8INTCONST 24 (0x18) U8ADD U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 27 addList_2(&(hosp_p->assess.forward)); U8U8LDID 0 T U8INTCONST 24 (0x18) U8ADD U8PARM 2 T # by_value VCALL 126 # flags 0x7e

Global Variable Graph(1) To overcome the bottleneck of copying all global variables during the bottom-up and top-down phase holds all information about global variable update the local graph and global variable graph interactively:  During the local phase, when Visiting a PU, create a global variable alias node in global graph if it is referenced in this PU  During the bottom-up phase, before inlining any callee, first update the local graph according to the global graph  During the bottom-up phase, after inlining all callees, update the global graph

Global Variable Graph(2) Steps: 1.Local phase: s->p, p->x, q->y, in global graph: s->p->x, q->y 2.Bottom-up phase, when inline bar’s information into bar_1, without global graph, we get p->y. With global graph, we know that p also points-to x, then we get p->{x,y}, finally update the global graph s->p p->x q->y s->p->x,q->y Before inline, what p points-to?

Experimental Results The preliminary results show that:  The bottom-up phase does not increase the alias node very much, this is consistent with the fact that we only do reachable cloning for non-local variables  Original Field-Sensitive will incurs very large overhead if the benchmarks contain large number of structure variables, such as 177.mesa and mysql alias node number Statistics :

Future Work Design the alias query interface How to pass the alias information into intra- procedural efficiently (do not store all alias graph) Design and Implement client optimizations, such as mod-ref, race detection Compare with other algorithm, both scalability and precision Combined with Subset methods to further improve the precision

Conclusion We design and implement a new cloning based context-sensitive pointer analysis phase in Open64 Compiler The algorithm is based on DSA algorithm in LLVM, we do several tradeoffs due to the IR and framework of Open64 For all the benchmarks we studied, the cloning phase does not increase the alias node very much

Thanks very much !