Context-Sensitive Interprocedural Points-To Analysis in the Presence of Function Pointers

Context-Sensitive Interprocedural Points-To Analysis in the Presence of Function Pointers

Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Maryam Emami Rakesh Ghiya Laurie J. Hendren School of Computer Science McGill University, Montreal, Quebec Canada H3A 2A7 {emami ,ghiya,hendren}@cs .mcgill. ca Abstract This paper reports on the design, implementation, and results of a new method for dealing with the alias- This paper reports on the design, implementation, ing problem in C. Our method, called points-to analy- and empirical results of a new method for dealing with sis, estimates the relationships between abstract stack the aliasing problem in C. The method is based on ap- locations. This method has been developed over the proximating the points-to relationships between acces- last two years within the framework of the McCAT sible stack locations, and can be used to generate alias optimizing/p arallelizing C compiler, and is currently pairs, or used directly for other analyses and transfor- operational. The import ant facets of our approach in- mations. clude: Our method provides context-sensitive interproce- The points-to abstraction: Rather than compute dural information based on analysis over invocation sets of alias pairs, our method computes a different ab- graphs that capture all calling contexts including re- straction: the points-to relationships between stack lo- cursive and mutually-recursive calling contexts. Fur- cations. We say that a stack location x points-to stack thermore, the method allows the smooth integration location y at program point p if x contains the ad- for handling general function pointers in C. dress of y. 1 In addition to providing a more compact We illustrate the effectiveness of the method with abstraction as compared to alias pairs, the points-to empirical results from an implementation in the Mc- information is well suited for immediate use by other CAT optimizing/p araHelizing C compiler. analyses. Unlike most approaches that compute may aliases, 1 Introduction and Motivation our analysis computes both possible and definite points- Alias and dependence analysis are fundamental com- to relationships. Using the points-to abstraction, the ponents of optimizing and parallelizing compilers. Al- additional overhead of providing the definite informa- though traditionally studied in the context of For- tion is minimal, while at the same time providing tran or block-structured languages [1, 2, 8, 9], there several advantages. The first advantage is that defi- has been increasing interest in providing accurate alias nite points-to information can be used to sharpen the and side-effect analysis for C programs [7, 31]. Solv- points-to analysis itself, by providing accurate killing ing these problems for C rather than Fortran leads to information. For example, given the statement *p = many interesting and difficult problems including the x, and the information that p definitely points to y, treatment of the address-of operator (i.e. &a) which we can kill all points-to relationships from y. The sec- can create new pointer relationships at any program ond major advantage is that definite relationships can point, multi-level pointer references (i.e. **a) which en- be used to direct transformations like pointer replace- able the called function to modify alias relationships in ment. For example, given the statement x = *q, and the calling function, the integration of pointer analysis the information that q definitely points-to y, we can for stack-allocated variables and dynamically-allocated replace the statement x = *q with x = y. This trans- variables, and the proper interprocedural handling of formation can then lead to better results in later phases recursion and function point ers. of the compiler such as reducing the number of loads and stores [12]. Permission to cc y vvithout fee all or part of this material is We present the points-to abstraction and the basic granted providJ that the copies are not made or distributed for flow analysis rules in Section 3 and we compare our direct commercial advantage, the ACM copyright notice and the approach to similar approaches in Section 7. title of the publication and its date appear, and notice is given that copying is by permission of the Association of Computing A context-sensitive interprocedural analysis: Machinery. To copy otherwise, or to republish, requires a fee anct/or specific permission. 1In more conventional alias analysis, the notion that x points- to y would be captured by an alias pair (*x, y). SIGPIAN 94-6/94 Orlando, Florida USA @ 1994 ACM 0-89791 -662-xKWO006..$3.5O 242 The points-to abstraction and basic flow analysis rules a structured intermediate representation called SIM- could be implemented in many different analysis frame- PLE [22, 43]. On one hand, we need to analyze real C works. However, our particular approach is a struc- programs (not just programs written in a toy subset of tured or compositional analysis that uses invocation C), and therefore our SIMPLE representation faithfully graphs to provide a context-sensitive analysis. This ap- represents these programs. On the other hand, we re- proach allows us to get accurate results and to correctly quire as compact and clean a representation as possible, handle recursion. so that new and powerful analyses can be implemented Function pointers provide a big challenge for inter- in a straightforward and compositional fashion. procedural analysis of C programs. In this paper we In designing the SIMPLE intermediate representa- give a natural extension of the points-to analysis that tion there were three major design criteria: (1) basing gracefully includes the general problem of single and our analysis framework on structured (compositional) multi-level pointers to functions. In fact, as we demon- analyses, and thus using a structured intermediate rep- strate, the problem of instantiating function pointers resent ation, (2) retaining high-level variable references in C must be done at the same time as points-to anal- and type casting information, and (3) designing a com- ysis in order to get a reasonably general and accurate pact representation for statements and expressions that solution. includes 15 basic statements, plus explicit simplified We discuss the basic interprocedural strategy in Sec- representations of the while, do, for, if, switch, tion 4 and then we show how to extend this to handle break, continue and return statements.2 Typical function pointers in Section 5. Related interprocedural simplifications include: compiling complex statements approaches are compared in Sections 4 and 7. into a series of basic statements, simplifying all condi- Experimental results and applications: It is our tional expressions in if and while statements to sim- viewpoint that any alias analysis must be implemented ple expressions with no side-effects, simplifying proce- and tested in order to measure the actual costs and ben- dure arguments to either constants or variable names, efits of the analysis. We have completely implemented and moving variable initializations from declarations the analysis described in this paper, and in Section 6 we to statements in the body of the appropriate proce- provide empirical evidence that our approach gives ac- dure. After simplification, points-to analysis rules need curate and useful results. We also provide a summary to be developed only for the 15 basic statements and of how the results of points-to analysis are used as a the compositional control statements. The design of building block for other analyses and transformations. these rules is further simplified by the fact that each of Separating stack-based aliasing from array and the basic statements can have only one level of pointer heap-based aliasing: The problem of aliasing really indirection for a variable reference. Further details are comes in three varieties: (1) aliases between variable given in [13, 22]. references to the stack, (2) aliases between references 3 Abstract Stack Locations and Basic to dynamically-allocated storage on the heap, and (3) Analysis Rules aliases between two references to the same array. It has become accepted that the last problem, aliases be- Traditionally, alias analysis methods have approxi- tween references to the same array, requires special de- mated aliases by sets of alias pairs. With this approxi- pendence testing methods based on analyzing the index mation, two variable references are said to be aliased if expressions. We claim that one must also consider to- they refer to the same location. Typical alias pairs are tally different analysis methods for stack-based aliases of the form (*x, y), (**p, **q), (*u, *v) and so on. and heap-based aliases, and that the two problems can 3.1 Points-to Abstraction safely be decoupled. In the case of stack-based aliases We have chosen a different abstraction that approxi- a name exists for each stack location of interest, and mates the points-to relationships between stack loca- one may compute some approximation of the relation- tions at each program point. The basic idea is to ships between these locations. In the case of heap- abstract the set of all accessible stack locations with based aliases, there are no natural names for each lo- a finite set of named abstract stack locations. Based cation. In fact, one does not know statically how many on this abstraction, the approximation of interest con- locations will be allocated. Thus, a completely differ- sists of a set of points-to relationships between the ab- ent approach is likely to be required. For example, stract stack locations. For example, after the statement Deutsch argues that a store~ess model is more appro- p = &y, we would say that abstract stack location p priate for the heap-based problems [11]. We discuss points-to abstract stack location y. this issue further in Section 7. The key to our approach is to guarantee that each 2 Setting - the McCAT compiler real stack location involved in a points-to relationship Our points-to analysis is implemented in the Mc- 2 It should be noted that the unrestricted use ~f got.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    15 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us