ABCD: Eliminating Array-Bounds Checks on Demand Rastislav Bodík Rajiv Gupta Vivek Sarkar U of Wisconsin U of Arizona IBM TJ Watson recent experiments.

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science
Advertisements

DATAFLOW TESTING DONE BY A.PRIYA, 08CSEE17, II- M.s.c [C.S].
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Satisfiability Modulo Theories (An introduction)
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
Stanford University CS243 Winter 2006 Wei Li 1 Register Allocation.
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
Enforcing Sequential Consistency in SPMD Programs with Arrays Wei Chen Arvind Krishnamurthy Katherine Yelick.
Program Representations. Representing programs Goals.
Program Slicing Mark Weiser and Precise Dynamic Slicing Algorithms Xiangyu Zhang, Rajiv Gupta & Youtao Zhang Presented by Harini Ramaprasad.
Presented By: Krishna Balasubramanian
ABCD: Eliminating Array-Bounds Checks on Demand Rastislav Bodík Rajiv Gupta Vivek Sarkar U of Wisconsin U of Arizona IBM TJ Watson recent experiments.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION TESTING II Autumn 2011.
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Recap from last time Saw several examples of optimizations –Constant folding –Constant Prop –Copy Prop –Common Sub-expression Elim –Partial Redundancy.
Administrative info Subscribe to the class mailing list –instructions are on the class web page, click on “Course Syllabus” –if you don’t subscribe by.
Administrative info Subscribe to the class mailing list –instructions are on the class web page, which is accessible from my home page, which is accessible.
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
Previous finals up on the web page use them as practice problems look at them early.
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; ???
1 Refinement-Based Context-Sensitive Points-To Analysis for Java Manu Sridharan, Rastislav Bodík UC Berkeley PLDI 2006.
Validating High-Level Synthesis Sudipta Kundu, Sorin Lerner, Rajesh Gupta Department of Computer Science and Engineering, University of California, San.
Incremental Path Profiling Kevin Bierhoff and Laura Hiatt Path ProfilingIncremental ApproachExperimental Results Path profiling counts how often each path.
Java Alias Analysis for Online Environments Manu Sridharan 2004 OSQ Retreat Joint work with Rastislav Bodik, Denis Gopan, Jong-Deok Choi.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Load-Reuse Analysis design and evaluation Rastislav Bodík Rajiv Gupta Mary Lou Soffa.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
PSUCS322 HM 1 Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
Recap from last time We saw various different issues related to program analysis and program transformations You were not expected to know all of these.
Eliminating Memory References Joshua Dunfield Alina Oprea.
Adaptive Optimization in the Jalapeño JVM M. Arnold, S. Fink, D. Grove, M. Hind, P. Sweeney Presented by Andrew Cove Spring 2006.
Precision Going back to constant prop, in what cases would we lose precision?
CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
P ARALLEL P ROCESSING I NSTITUTE · F UDAN U NIVERSITY 1.
White-Box Testing Eshcar Hillel Michael Beder. White Box Testing 2 Tutorial Outline What is White Box Testing? Flow Graph and Coverage Types Symbolic.
Toward Efficient Flow-Sensitive Induction Variable Analysis and Dependence Testing for Loop Optimization Yixin Shou, Robert A. van Engelen, Johnnie Birch,
CSc 453 Final Code Generation Saumya Debray The University of Arizona Tucson.
Extended Static Checking for Java  ESC/Java finds common errors in Java programs: null dereferences, array index bounds errors, type cast errors, race.
Static Program Analysis of Embedded Software Ramakrishnan Venkitaraman Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Targeted Path Profiling : Lower Overhead Path Profiling for Staged Dynamic Optimization Systems Rahul Joshi, UIUC Michael Bond*, UT Austin Craig Zilles,
Static Program Analysis of Embedded Software Ramakrishnan Venkitaraman Graduate Student, Computer Science Advisor: Dr. Gopal Gupta
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John.
A System to Generate Test Data and Symbolically Execute Programs Lori A. Clarke Presented by: Xia Cheng.
Targeted Path Profiling : Lower Overhead Path Profiling for Staged Dynamic Optimization Systems Rahul Joshi, UIUC Michael Bond*, UT Austin Craig Zilles,
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
CUTE: A Concolic Unit Testing Engine for C Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
Loops Simone Campanoni
Memory Protection through Dynamic Access Control Kun Zhang, Tao Zhang and Santosh Pande College of Computing Georgia Institute of Technology.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Introduction toData structures and Algorithms
Static Single Assignment
Machine-Independent Optimization
Factored Use-Def Chains and Static Single Assignment Forms
CS 201 Compiler Construction
Register Allocation Hal Perkins Autumn 2005
Amir Kamil and Katherine Yelick
CUTE: A Concolic Unit Testing Engine for C
Complete Removal of Redundant Expressions
CSE 373: Data Structures and Algorithms
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Practical Assignment Sinking for Dynamic Compilers
CS 201 Compiler Construction
Presentation transcript:

ABCD: Eliminating Array-Bounds Checks on Demand Rastislav Bodík Rajiv Gupta Vivek Sarkar U of Wisconsin U of Arizona IBM TJ Watson recent experiments by Denis Gopan, U of Wisconsin

2 Motivation: type safety Pro: type-safe programs don’t “crash” Con: some violations checked at run time Direct cost: executing the checks checks are frequent, expensive Indirect cost: preventing optimization checks block code motion of side-effect instructions Our goal: safety without performance penalty How? remove redundant checks

3 Talk outline Why remove bounds checks? safety without performance penalty The need for dynamic optimization existing optimizers not suitable an ideal dynamic optimizer ABCD Experiments Summary

4 When to optimize the checks?

5

6 Existing check optimizers Emphasis: precision all checks removed = statically type-safe theorem prover: [Necula, Lee], [Xu, Miller, Reps] range propagation: [Harrison, Patterson] types: [Xi, Phenning] Properties too heavy-weight limited notion of control flow: how to add profile feedback?

7 An ideal dynamic optimizer? A balance between power and economy powerful just enough  only common cases minimize analysis work  efficient IR reduce analysis overhead  reuse the IR Scalable optimize only hot checks  profile-directed  demand-driven not fully inter-procedural  use “local” info + insert (cold) checks

8 Why optimize on demand?  optimize only the few hot checks number of static checks % of dynamic checks

9 Talk outline Motivation An ideal dynamic optimizer ABCD “tutorial” 1. Simple... standard SSA 2. Full... extended SSA 3. PRE... profile-directed 4. Poor... when do we fail? ( future work) Experiments Summary

10 Keep in mind array access A[i] requires two checks: lower-bounds check: 0  i è upper-bounds check: i < A.length these two checks are analyzed separately

11 1. Simple ABCD i  A.length while ( ) --i..A[i].. Simple ABCD = SSA + shortest path

12 1. Simple ABCD 1.build SSA connect SSA definitions with edges 2.label edges with constraints weight(x  y) = c  y  x – c 3.analyze A[i k ]: input: a bounds check i k < A.length algorithm: find shortest path p from A.length to i k output: check is redundant if |p| > 0

13 Simple ABCD A.length i2i2 i0i0 i 1 :=ø(i 0,i 2 ) i 0  A.length – 0 i 2  i 1 – 1 i 1  i 0 – 0 i 1  ø(i 0,i 2 ) i 2  i 1 –1.. A[i 2 ].. i 0  A.length |A.length  i 2 | = 1  i 2  A.length – 1

14 2. Full ABCD for (i=0; i < A.length; i++)..A[i].. Real ABCD = SSA ++ + “shortest” path

15 2. Full ABCD 1.build extended SSA 2.label edges with constraints 3.analyze A[i k ]: input: a bounds check i k < A.length algorithm: find optimal hyper-path p from A.length to i k output: check is redundant if |p| > 0

16 Full ABCD for (i=0; i < A.length; i++).. A[i 2 ].. A.length i2i2 i0i0 i 1 :=ø(i 0,i 2 ) 0 0 –1 0 shortest path length = –  SSA misses constraints from conditionals 0 – 

17 Extending the SSA form 0 i2i2 i0i0 i 1  ø(i 0,i 3 ) 0 0 –1 0 0 i3i3 i 1  ø(i 0,i 3 ).. A[i 2 ].. i 3  i 2 +1 i 0  0 exit T F i 1  A.length–1 A.length 1 i 4  (i 1 ) i 2  (i 1 )

18 3. ABCD with PRE f(int A[], int n) { for (i=0; i < n; i++)..A[i].. } if (n <= A.length) unoptimized loop false ABCD with PRE = Full ABCD + profile feedback

19 3. ABCD with PRE 1.build extended SSA 2.label edges with constraints 3.analyze A[i k ]: algorithm: i) find paths with “bad” length ii) fix their length by inserting run-time checks Issues: What check to insert? Where to insert the check? When is insertion profitable?

20 ABCD with PRE 0 i2i2 i0i0 i 1  ø(i 0,i 3 ) 0 0 –1 0 0 i3i3 1 nA.length f(int A[], int n) { for (i=0; i<n; i++).. A[i].. } 0 if (n <= A.length – 0) DONE! constraint edges can be added by inserting run-time checks

21 4. Poor ABCD f(int A[], int n, i, j) { for ( ; i < n; i++, j++).. A[j].. } if ( n <= A.length–(j-i)) unoptimized loop When does ABCD fail?

22 Poor ABCD i2i2 i0i0 i1i1 0 –1 0 0 i3i3 1 n A.length j2j2 j0j0 j1j1 0 –1 0 0 j3j3 0 for (i=j=0 ; i<n; i++,j++) {.. A[j].. } c = j 2 -i 2 if (n <= A.length-( j 2 -i 2 )) c = j 0 -i 0 if (n <= A.length-( j 0 -i 0 ))

23 How powerful is ABCD? % of all checks removed (dynamic count) SPECjvm Symantec Misc. Java

24 Lower-bounds checks “JIT” ABCD ABCDE examined AVG % of all checks removed (dynamic count)

25 Upper-bounds checks “JIT” ABCD ABCDE examined AVG % of all checks removed (dynamic count)

26 Performance Speedup about 5% not many optimizations implemented Analysis time 4 ms / check = visit about 10 SSA nodes 20 static checks to get 80% coverage  80ms to analyze a (large) benchmark !

27 Summary of ABCD local constraints constraint format useful statements global constraint system extended SSA inequality graph solving the constraint system traversing the graph partially redundant checks

28 Summary optimize only hot statements demand-driven reduce analysis work sparse IR profile-driven powerful just enough tuned simplicity minimize IR overhead via IR reuse use SSA not interprocedural PRE