Approach #1 to context-sensitivity Keep information for different call sites separate In this case: context is the call site from which the procedure is.

Slides:



Advertisements
Similar presentations
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Pointer Analysis.
Advertisements

Sorting Really Big Files Sorting Part 3. Using K Temporary Files Given  N records in file F  M records will fit into internal memory  Use K temp files,
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.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
1 Practical Object-sensitive Points-to Analysis for Java Ana Milanova Atanas Rountev Barbara Ryder Rutgers University.
Parameterized Object Sensitivity for Points-to Analysis for Java Presented By: - Anand Bahety Dan Bucatanschi.
Eliminating Stack Overflow by Abstract Interpretation John Regehr Alastair Reid Kirk Webb University of Utah.
Context-Free Parsing. 2/37 Basic issues Top-down vs. bottom-up Handling ambiguity –Lexical ambiguity –Structural ambiguity Breadth first vs. depth first.
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.
Feedback: Keep, Quit, Start
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.
CS 536 Spring Run-time organization Lecture 19.
Approach #1 to context-sensitivity Keep information for different call sites separate In this case: context is the call site from which the procedure is.
Inlining pros and cons (discussion). Inlining pros and cons Pros –eliminate overhead of call/return sequence –eliminate overhead of passing args & returning.
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.
Honors Compilers Addressing of Local Variables Mar 19 th, 2002.
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.
X := 11; if (x == 11) { DoSomething(); } else { DoSomethingElse(); x := x + 1; } y := x; // value of y? Phase ordering problem Optimizations can interact.
Scaling CFL-Reachability-Based Points- To Analysis Using Context-Sensitive Must-Not-Alias Analysis Guoqing Xu, Atanas Rountev, Manu Sridharan Ohio State.
Another example p := &x; *p := 5 y := x + 1;. Another example p := &x; *p := 5 y := x + 1; x := 5; *p := 3 y := x + 1; ???
Range Analysis. Intraprocedural Points-to Analysis Want to compute may-points-to information Lattice:
Run time vs. Compile time
Intraprocedural Points-to Analysis Flow functions:
Recap from last time g() { lock; } h() { unlock; } f() { h(); if (...) { main(); } } main() { g(); f(); lock; unlock; } mainfgh ;;;;;;; u u ” ”””” ” ”
ESP [Das et al PLDI 2002] Interface usage rules in documentation –Order of operations, data access –Resource management –Incomplete, wordy, not checked.
A simple approach Given call graph and CFGs of procedures, create a single CFG (control flow super-graph) by: –connecting call sites to entry nodes of.
From last time: Inlining pros and cons Pros –eliminate overhead of call/return sequence –eliminate overhead of passing args & returning results –can optimize.
Another lock protocol example g() { if(isLocked()) { unlock; } else { lock; } } mainfg ;;;;; u ” ”””” ” ””” ” ” ”” ” ” ” ”””” u l l ” ””” ” ” ” ” ” {u,l}
Comparison Caller precisionCallee precisionCode bloat Inlining context-insensitive interproc Context sensitive interproc Specialization.
Course project presentations Midterm project presentation Originally scheduled for Tuesday Nov 4 th Can move to Th Nov 6 th or Th Nov 13 th.
Reps Horwitz and Sagiv 95 (RHS) Another approach to context-sensitive interprocedural analysis Express the problem as a graph reachability query Works.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
Schedule Midterm out tomorrow, due by next Monday Final during finals week Project updates next week.
Code Generation CS 480. Can be complex To do a good job of teaching about code generation I could easily spend ten weeks But, don’t have ten weeks, so.
Prof. Aiken CS 294 Lecture 11 Program Analysis. Prof. Aiken CS 294 Lecture 12 The Purpose of this Course How are the following related? –Program analysis.
Transfer functions Our pairs of summaries look like functions from input information to output information We call these transfer functions Complete transfer.
Examples of summaries. Issues with summaries Level of “context” sensitivity: –For example, one summary that summarizes the entire procedure for all call.
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
From last class. The above is Click’s solution (PLDI 95)
Symbolic Path Simulation in Path-Sensitive Dataflow Analysis Hari Hampapuram Jason Yue Yang Manuvir Das Center for Software Excellence (CSE) Microsoft.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Impact Analysis of Database Schema Changes Andy Maule, Wolfgang Emmerich and David S. Rosenblum London Software Systems Dept. of Computer Science, University.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University STATIC ANALYSES FOR JAVA IN THE PRESENCE OF DISTRIBUTED COMPONENTS AND.
PRESTO Research Group, Ohio State University Interprocedural Dataflow Analysis in the Presence of Large Libraries Atanas (Nasko) Rountev Scott Kagan Ohio.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Prolog Program Style (ch. 8) Many style issues are applicable to any program in any language. Many style issues are applicable to any program in any language.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
CS 343 presentation Concrete Type Inference Department of Computer Science Stanford University.
Escape Analysis for Java Will von Rosenberg Noah Wallace.
Pointer Analysis – Part I CS Pointer Analysis Answers which pointers can point to which memory locations at run-time Central to many program optimization.
Interprocedural analyses and optimizations. Costs of procedure calls Up until now, we treated calls conservatively: –make the flow function for call nodes.
D A C U C P Speculative Alias Analysis for Executable Code Manel Fernández and Roger Espasa Computer Architecture Department Universitat Politècnica de.
Interprocedural analyses and optimizations. Costs of procedure calls Up until now, we treated calls conservatively: –make the flow function for call nodes.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Sorting and Runtime Complexity CS255. Sorting Different ways to sort: –Bubble –Exchange –Insertion –Merge –Quick –more…
Inter-procedural analysis
Ravi Mangal Mayur Naik Hongseok Yang
Another example: constant prop
Inlining and Devirtualization Hal Perkins Autumn 2011
Inlining and Devirtualization Hal Perkins Autumn 2009
Pointer analysis.
Interprocedural analyses and optimizations
Presentation transcript:

Approach #1 to context-sensitivity Keep information for different call sites separate In this case: context is the call site from which the procedure is called

Example again g() { if(isLocked()) { unlock; } else { lock; } } mainfg f() { g(); if (...) { main(); } } main() { g(); f(); lock; unlock; }

Example again g() { if(isLocked()) { unlock; } else { lock; } } mainfg f() { g(); if (...) { main(); } } main() { g(); f(); lock; unlock; }

How should we change the example? How should we change our example to break our context sensitivity strategy? g() { if(isLocked()) { unlock; } else { lock; } f() { g(); if (...) { main(); } main() { g(); f(); lock; unlock; }

Answer h() { g() } g() { if(isLocked()) { unlock; } else { lock; } f() { h(); if (...) { main(); } main() { h(); f(); lock; unlock; }

In general Our first attempt was to make the context be the immediate call site Previous example shows that we may need 2 levels of the stack –the context for an analysis of function f is: call site L 1 where f was called from AND call site L 2 where f’s caller was called from Can generalize to k levels –k-length call strings approach of Sharir and Pnueli –Shiver’s k-CFA

Approach #2 to context-sensitivity

Use dataflow information at call site as the context, not the call site itself

Using dataflow info as context g() { if(isLocked()) { unlock; } else { lock; } } f() { g(); if (...) { main(); } } main() { g(); f(); lock; unlock; } mainfg

Transfer functions Our two pairs of summaries look like functions from input information to output information We call these transfer functions Complete transfer functions –contain entries for all possible incoming dataflow information Partial transfer functions –contain only some entries, and continually refine during analysis

Top-down vs. bottom-up We’ve always run our interproc analysis top down: from main, down into procs For data-based context sensitivity, can also run the analysis bottom-up –analyze a proc in all possibly contexts –if domain is distributive, only need to analyze singleton sets and empty set

Top-down vs. bottom-up What are the tradeoffs?

Top-down vs. bottom-up What are the tradeoffs? –In top-down, only analyze procs in the context that occur during analysis, whereas in bottom-up, may do useless work analyzing proc in a data context never used during analysis –However, top-down requires analyzing a given function at several points in time that are far away from each other. If the entire program can’t fit in RAM, this will lead to unnecessary swapping. On the other hand, can do bottom-up as one pass over the call- graph, one SCC at a time. Once a proc is analyzed, it never needs to be reloaded in memory. –top-down better suited for finite domains

Bottom-up example g() { if(isLocked()) { unlock; } else { lock; } } f() { g(); if (...) { main(); } } main() { g(); f(); lock; unlock; } mainfg

Bottom-up example g() { if(isLocked()) { unlock; } else { lock; } } f() { g(); if (...) { main(); } } main() { g(); f(); lock; unlock; } mainfg ??? u ! l l ! u u ! l l ! u u ! u l ! e ”” ” ” ” ” u ! {l,e} l ! u ”” u ! u l ! e

RHS g() { if(isLocked()) { unlock; } else { lock; } f() { g(); if (...) { main(); } main() { g(); f(); lock; unlock; }

RHS

g() { if(isLocked()) { unlock; } else { lock; } f() { g(); if (...) { main(); } main() { g(); f(); lock; unlock; }

Procedure specialization Interprocedural analysis is great for callers But for the callee, information is still merged main() { x := new A(...); y := x.g(); y.f(); x := new A(...); y := x.g(); y.f(); x := new B(...); y:= x.g(); y.f(); } // g too large to inline g(x) { x.f(); // lots of code return x; } // but want to inline f {... } {... }

Procedure specialization Specialize g for each dataflow information “In between” inlining and context-sensitve interproc main() { x := new A(...); y := x.g 1 (); y.f(); x := new A(...); y := x.g 1 (); y.f(); x := new B(...); y:= x.g 2 (); y.f(); } g 1 (x) { x.f(); // can now inline // lots of code return x; } g 2 (x) { x.f(); // can now inline // lots of code return x; } // but want to inline f {... } {... }

A() { call D } B() { call D } C() { call D } D() {... } Recap using pictures

A() { } D’D’ B() { } D ’’ C() { } D ’’’ Inlining A() { call D } B() { call D } C() { call D } D() {... }

A() { call D } B() { call D } C() { call D } D() {... } caller summary callee summary Context-insensitive summary A() { call D } B() { call D } C() { call D } D() {... }

A() { call D } B() { call D } C() { call D } D() {... } context sensitive summary Context sensitive summary A() { call D } B() { call D } C() { call D } D() {... }

A() { call D } B() { call D } C() { call D } D() {... } D’() {... } Procedure Specialization A() { call D } B() { call D } C() { call D } D() {... }

Comparison Caller precisionCallee precisionCode bloat Inlining context-insensitive interproc Context sensitive interproc Specialization

Comparison Caller precisionCallee precisioncode bloat Inlining, because contexts are kept separate  may be large if we want to get the best precision context-insensitive interproc , because contexts are merged none Context sensitive interproc, because of context sensitive summaries , because contexts are still merged when optimizing callees none Specialization, contexts are kept separate  Some, less than inlining

Summary on how to optimize function calls Inlining Tail call optimizations Interprocedural analysis using summaries –context sensitive –context insensitive Specialization

Cutting edge research Making interprocedural analysis run fast –Many of the approaches as we have seen them do not scale to large programs (eg millions of lines of code) –Trade off precision for analysis speed (we’ll see an example later) Optimizing first order function calls Making inlining effective in the presence of dynamic dispatching and class loading (we’ll see some of this when we look at OO optimizations)