Putting Pointer Analysis to Work Rakesh Ghiya and Laurie J. Hendren Presented by Shey Liggett & Jason Bartkowiak.

Slides:



Advertisements
Similar presentations
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
Advertisements

Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Program Representations. Representing programs Goals.
Code Compaction of an Operating System Kernel Haifeng He, John Trimble, Somu Perianayagam, Saumya Debray, Gregory Andrews Computer Science Department.
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
1 S. Tallam, R. Gupta, and X. Zhang PACT 2005 Extended Whole Program Paths Sriraman Tallam Rajiv Gupta Xiangyu Zhang University of Arizona.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Software Group © 2005 IBM Corporation Compiler Technology October 17, 2005 Array privatization in IBM static compilers -- technical report CASCON 2005.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
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.
Vertically Integrated Analysis and Transformation for Embedded Software John Regehr University of Utah.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
ISBN Chapter 9 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Introduction Two fundamental abstraction facilities.
Previous finals up on the web page use them as practice problems look at them early.
Run-Time Storage Organization
Range Analysis. Intraprocedural Points-to Analysis Want to compute may-points-to information Lattice:
Run time vs. Compile time
Data Partitioning for Reconfigurable Architectures with Distributed Block RAM Wenrui Gong Gang Wang Ryan Kastner Department of Electrical and Computer.
Class canceled next Tuesday. Recap: Components of IR Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements.
Intraprocedural Points-to Analysis Flow functions:
Copy Propagation and Common Subexpression Elimination in Titanium Johnathon Jamison David Marin CS265 S. Graham.
Comparison Caller precisionCallee precisionCode bloat Inlining context-insensitive interproc Context sensitive interproc Specialization.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Schedule Midterm out tomorrow, due by next Monday Final during finals week Project updates next week.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
Compiler Code Optimizations. Introduction Introduction Optimized codeOptimized code Executes faster Executes faster efficient memory usage efficient memory.
5.3 Machine-Independent Compiler Features
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
P ARALLEL P ROCESSING I NSTITUTE · F UDAN U NIVERSITY 1.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University STATIC ANALYSES FOR JAVA IN THE PRESENCE OF DISTRIBUTED COMPONENTS AND.
Department of Computer Science A Static Program Analyzer to increase software reuse Ramakrishnan Venkitaraman and Gopal Gupta.
AN EXTENDED OPENMP TARGETING ON THE HYBRID ARCHITECTURE OF SMP-CLUSTER Author : Y. Zhao 、 C. Hu 、 S. Wang 、 S. Zhang Source : Proceedings of the 2nd IASTED.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
1 Advance Computer Architecture CSE 8383 Ranya Alawadhi.
Compiler Construction
Toward Efficient Flow-Sensitive Induction Variable Analysis and Dependence Testing for Loop Optimization Yixin Shou, Robert A. van Engelen, Johnnie Birch,
Predicated Static Single Assignment (PSSA) Presented by AbdulAziz Al-Shammari
Static Program Analyses of DSP Software Systems Ramakrishnan Venkitaraman and Gopal Gupta.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Assembly Code Optimization Techniques for the AMD64 Athlon and Opteron Architectures David Phillips Robert Duckles Cse 520 Spring 2007 Term Project Presentation.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Mark Marron IMDEA-Software (Madrid, Spain) 1.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Using Types to Analyze and Optimize Object-Oriented Programs By: Amer Diwan Presented By: Jess Martin, Noah Wallace, and Will von Rosenberg.
Pointer Analysis Survey. Rupesh Nasre. Aug 24, 2007.
OPTIMIZING DSP SCHEDULING VIA ADDRESS ASSIGNMENT WITH ARRAY AND LOOP TRANSFORMATION Chun Xue, Zili Shao, Ying Chen, Edwin H.-M. Sha Department of Computer.
Pointer Analysis for Multithreaded Programs Radu Rugina and Martin Rinard M I T Laboratory for Computer Science.
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
Data Flow Analysis for Software Prefetching Linked Data Structures in Java Brendon Cahoon Dept. of Computer Science University of Massachusetts Amherst,
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Power Analysis of Embedded Software : A Fast Step Towards Software Power Minimization 指導教授 : 陳少傑 教授 組員 : R 張馨怡 R 林秀萍.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
1 ”MCUDA: An efficient implementation of CUDA kernels for multi-core CPUs” John A. Stratton, Sam S. Stone and Wen-mei W. Hwu Presentation for class TDT24,
Compositional Pointer and Escape Analysis for Java Programs
Code Generation.
A Practical Stride Prefetching Implementation in Global Optimizer
Compiler Code Optimizations
Pointer analysis.
rePLay: A Hardware Framework for Dynamic Optimization
Presentation transcript:

Putting Pointer Analysis to Work Rakesh Ghiya and Laurie J. Hendren Presented by Shey Liggett & Jason Bartkowiak

Introduction  Paper addresses the problem of how to apply pointer analysis to a wide variety of compiler applications.  Shows how to put points-to analysis and connection analysis to work  Compute read/write sets for indirections stack-directed pointers: points-to information heap directed pointers: connection analysis + anchor handles  Based on the read/write sets extend traditional optimizations.

Stack vs. Heap Directed Pointers  Stack directed pointers: pointer to stack objects. Objects on the stack have appropriate variable names int t, *pt1; pt1 = &t;  Heap directed pointers: pointers to heap objects Dynamically-allocated objects int *pt2; pt2 = malloc();

Approach  Resolve all pointer relationships on the stack using points-to analysis  Further analyze heap pointers using connection analysis  Examine how the combination of the above analyses can be used to compute applicable information

Pointer Analysis in General  Identify the set of locations read/written by a given statement or program region. x S: x = y + z; Read(S) = {y,z} Write(S) = {x} *q T: p = *q; Read(T) = {q,*q} Write(T) = {p} … *q U: *q = y; Read(U) = {y,q} Write(U) = {*q}  In order to relate read/write sets of statements: resolve indirect references into a set of static locations

Points-to Analysis (As explained by Emami)  Approximate relationships between named objects (stored-based).  Calculate pointer targets in terms of triplets of the form (x, y, D) / (x, y, P) Variable x definitely/possibly contains the address of the location corresponding to y.  Heap locations are abstracted as one symbolic stack location named heap

Points-to Analysis (cont.) C: (s, ptA, D), (t, ptB, D) mapping: U: (c, 1_c, D), (d, 1_d, D) Read(U) = {c, d, 1_c.x, 1_d.y} Write(U): {1_c.x} Read(V) = {c, d, 1_c.y, 1_d.x} Write(V): {1_c.y} Read(sum) = Read(U) + Read(V) Write(sum): Write(U) +Write(V)

Points-to Analysis (cont.) Read(sum) = {c, d, 1_c.x, 1_d.y, 1_c.y, 1_d.x} Write(sum): {1_c.x, 1_c.y} Unmapping: Read(C) = {s, t, ptA.x, ptB.y, ptA.y, ptB.x} Write(C): {ptA.x, ptA.y}

Points-to Analysis (cont.) D: (s, heap, P), (t, heap, P) mapping: flip:(a, heap, P), (b, heap, P) Read(S) = Read(T) = {b, a, heap) Write(S) = Write(T) = {heap} False dependence between S and T

Connection Analysis  Computing connection relationships between pointers (instead of explicitly computing potential targets of pointers)  Performed after point-to analysis  Focuses on heap-directed pointers  Two heap directed pointers are connected if they possibly point to heap objects belonging to the same data structure.  They are NOT connected if they definitely point to objects belonging to disjoint data structures

Connection Analysis (cont.)

 Problem: computing read/write sets based on connection analysis

Introducing Anchor Handles  Motivation: The same programmer defined name may refer to different objects at different program points  Solution: Invent enough new names: Anchor handles  Calculating read/write sets: anchor handle p is read/written each time any pointer connected to p is read/written.

HeapWrite(S) = HeapRead(T) = Detect flow dependence from S to T Introducing Anchor Handles (cont.)

Function level information: HeapWrite(t_flip) = HeapRead(t_flip) = Useful to prefetch a->x and b->y (but not a->y and b->x) No changes to the “listness” of the data structure

Introducing Anchor Handles (cont.)  Select the locations to be anchored  Generate anchor handles for each:  heap directed formal parameters  heap directed global pointer accessed in function  call site that can read/write a heap location  heap related indirect reference - *p if (p,heap,P)  Use SSA numbers to further reduce number of anchors anchor the same location (pointer a hasn’t been updated between them) same handle can be used to anchor all indirect references involving a given definition of a pointer.

Applications - extend several scalar compiler optimizations  Loop Invariant Removal (LIR) Variables that do not change in a loop (always evaluate the same value). Remove from the loop.  Location Invariant Removal (LcIR) Memory reference that accesses the same memory location in all iterations of a loop.  Common Sub-expression Elimination (CSE) Computations that are always performed at least twice on a given execution path. Eliminate second and later occurrences.

Example of LIR For(I= )temp = *a; {for(I=) Array[I] = *a;{ }Array[I] = temp; } (a)(b) Loop Invariants

Example of LcIR

Another Example of LcIR For(I= )temp = r->t; {for(I=) r->t = p->I;{ }temp=p->I; } r->t = temp; (a)(b) Location Invariants

Applications - LIR, LcIR

Example of CSE For(I= )temp = (a*b)/c; {for(I=) Array[I] = (a*b)/c;{ Array2[I] = (a*b)/c; Array[I] = temp; }Array2[I] = temp; } (a)(b) Common Sub-expression Elimination

Applications - CSE

Experimental Results Analysis Efficiency (UltraSparc) quite efficient for moderate size benchmarks average number of anchor handles per indirect reference is 0.50

Experimental Results (cont.) Optimization Opportunities expr invariants cannot always be identified without pointer analysis limited applications of LcIR. Numerous applications for CSE, LIR

Experimental Results (cont.) Benefits of using heap read/write sets LIR and CSE: number of optimizations increases moderately, for all benchmarks; stack analysis is able to detect most of them (heap read/write info doesn’t bring any added advantage in the case of address exposed variables, or if the code fragment doesn’t involve any write to heap) LcIR: increases in the two applications.

Experimental Results (cont.) Runtime Improvement Measure additional benefits of the analyses over a state-of-the-art optimizing compiler

Experimental Results (cont.) Runtime Improvement Optimized versions achieve significant reduction in the number of memory references (7% to 35.56%). There may not always be a direct correlation between the number of times optimizations are applied and the actual run time improvement. Percentage decrease is always equal or higher for Hopt compared to Sopt. Some of the applications show significant speedup over “gcc -O3”

More Applications  Improving array dependence tests. In C, arrays are mostly implemented using pointers to dynamically-allocated storage. Pointer based array references pose problems for array dependence tester. Pointer analyses can make it more effective.  Program Understanding/Debugging. Based on the summary of read/write sets can make observations about the effect of a function on data structures passed to it (which fields are/not updated by the function).  Guide data prefetching for recursive heap data structures

Contributions  Provided a new method for computing read/write sets for connection analysis, introducing the notion of anchor handles.  Demonstrated a variety of applications: extending standard scalar compiler optimizations, array dependence testers and program understanding.  Provided extensive measurements. Demonstrate up to 10% improvement over gcc -O3.

Conclusions  Pointer analysis is an important part of an optimizing C compiler, and one can achieve significant benefits from such an analysis.  Future work will be in three major directions:  Effect of stack and heap read/write sets on fine-grain parallelism and instruction scheduling  Benefits of context-sensitive, flow-sensitive analyses vs. flow-insensitive analyses  Continue to develop new transformations for pointer- intensive programs