Practical Techniques For Interprocedural Heap Analysis

Accurate alias analysis is critical for optimizing/parallelizing compilers that support languages with pointers. E cient techniques have been developed to calculate aliases introduced by pointers to named memory locations (typically on the stack). However, practical and e ective techniques for detection of aliases induced by heap-based dynamic data structures, have yet to be developed. Existing approaches are either e cient but overly conservative, or sophisticated but expensive. In this thesis, we present a new and practical approach for analyzing the alias properties of heap data structures. The important features of our approach include: (i) we analyze heap-directed pointers after resolving the points-to relationships of stack-directed pointers, (ii) we use a storeless model and estimate the heap structure by abstracting the relationships between heap-directed pointers, and not by explicitly abstracting the heap as a graph, and (iii) we employ a hierarchical approach and design di erent abstractions to solve the problem at di erent levels of complexity. We present a hierarchy of three practical abstractions for analyzing heap data structures, namely connection, direction and interference matrix abstractions. These abstractions respectively capture the following boolean relationships between any two given heap-directed pointers: (i) if they can point to the same heap data structure, (ii) if an access path exists between the heap objects they point to, and (iii) if they can access a common heap object. Connection matrix information helps detect pointer accesses to completely disjoint data structures. The other two abstractions work together to identify if the given program builds tree-like or dag-like structures. We have implemented context-sensitive interprocedural analyses for these abstractions in the framework of the McCAT C compiler. For each abstraction, we rst present basic analysis rules applicable to any language that supports pointers. We then describe C speci c features of the analyses. We demonstrate the e ectiveness of the analyses by providing examples as well as empirical results for real C programs. ii R esum e L'analyse pr ecise d'alias est critique pour les compilateurs optimisateurs/ parallelisateurs, supportant des langages qui utilisent des pointeurs. Des techniques e caces ont et e d evelopp ees pour calculer les alias introduits par des pointeurs qui pointent sur des locations m emoires nomm ees (typiquement sur la pile). Pourtant des techniques e caces et pratiques pour d etecter les alias introduits par les structures de donn ees dynamiques bas ees sur le heap, sont encore a être d evelopp ees. Les approches qui existent maintenant sont: ou e caces mais tr es conservatives, ou compliqu ees mais ch eres. Dans cette th ese, nous pr esentons une nouvelle m ethode qui est pratique pour analyser les propri et es des structures de donn ees de type 'heap'. Les principales caract eristiques de notre m ethode sont: (i) nous analysons les pointeurs pointant sur le heap apr es avoir r esolu les relations 'pointe-sur' des pointeurs pointant sur la pile, (ii) nous utilisons un mod ele qui ne requiert aucune m emoire et nous estimons les structures du heap en faisant abstraction des relations entre les pointeurs qui pointent sur le heap, et non pas en faisant abstraction du heap comme un graphe, et (iii) nous employons une approche de type hierarchique et nous avons con cu di erentes abstractions pour r esoudre le probl eme a plusieurs niveaux de complexit e. Nous pr esentons une hi erarchie de trois abstractions pratiques pour analyser les structures de donn ees de heap: abstractions de matrices de connection, de direction, et d'interf erence. Chacune de ces abstractions reconnâit une relation bool eenne entre deux pointeurs qui pointent sur un heap. Respectivement: (i) si ces pointeurs peuvent pointer sur la même structure de donn ee du heap, (ii) s'il existe un chemin d'acc es entre les objets du heap qu'ils pointent, et (iii) s'ils peuvent acc eder a un objet commun du heap. La matrice de connection aide a d etecter l'acc es des pointeurs a des structures de donn ees compl etement disjointes. Les deux autres abstractions iii identi ent ensemble si le programme consid er e construit des structures de donn ees de type arbre ou 'dag' (graphe dirig e sans cycle). Nous avons impl ement e des analyses inter-procedurales qui tiennent compte du contexte pour ces abstractions dans l'environnement du compilateur C McCAT. Pour chacune de ces abstractions, nous pr esentons d'abord les r egles d'analyse de base appplicable a n'importe quel langage supportant des pointeurs. Puis, nous d ecrivons les caract eristiques qui sont sp eci ques pour C. Nous d emontrons aussi l'e cacit e de ces analyses en pr esentant des exemples ainsi que le r esultat d' experiences r ealis ees avec de v eritables programmes ecrits en C. iv Acknowledgments Many thanks to: Laurie Hendren for being a very caring and cheerful advisor. She has provided constant encouragement and kept me in good spirits all through. The numerous discussions I had with her, greatly helped me in making my fuzzy ideas concrete and in maintaining my focus. She has also supported my studies and saved me from the worldly worries. It has been fun sharing the penchant for pointers with her. Professor Guang Gao for providing clear insights into the compiler-architecture relationship through his foundational courses. He always greeted me with a smile and boosted my morale with words of encouragement. I must also add that his keen sense of humor has given me many light moments during his lectures and seminars. My mentors at TRDDC at Pune in India, for the rst lessons. Professor Kesav Nori initiated me into the realm of compilers and Hemant Pande inducted me into pointer research. Maryam Emami for making things tractable. She solved the rst half of the problem and provided me a framework to attack the second part. She patiently answered all my questions, and many a times took pains to explain intricate details with elegant examples. I owe her a debt of gratitude. The multi-cultural melange of people in the ACAPS lab, for adding much color to life. Chris Donawa showed me the ropes around in Montr eal and provoked me into many interesting discussions of all kinds. Ana Erosa made us jealous with really long holiday trips to Europe, and kept us happy with her parties. Luis Lozano always cheered me with a warm hello, and has been a considerate friend. Bhama, Cecile, Maryam and Justiani arranged some wonderful get-togethers, which will always remind me of the good old days. This pack however remains incomplete without including Ian and Helga, who have always been great fun. v The fun friends in Montr eal, for always having time for me. Nasser Elmasri provided company during the late night hacking sessions. He consistently humbled me on the squash courts, but invariably consoled me with a dinner invitation. Alain Turki and Herve Avril always invented attractive alternatives to work, and never said no to a snooker game. And Dhrubajyoti Goswami has been a good-natured friend since the rst days in Montr eal. The very helpful people in the administrative o ce: Lorraine Harper, Franca Cianci and Lise Minogue, for making life a lot easier. People at home: my parents for their quiet support, uncle S. N. for always coming to rescue, and everyone else for being so much fun. This work was partly supported by the EPPP project, nanced by Industry Canada, Alex Parallel Computers, Digital Equipment Canada, IBM Canada and the Centre de recherche informatique de Montr eal (CRIM). vi In the memory of my grandfather Jagdish Prasad Ghiya vii