Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Slides:



Advertisements
Similar presentations
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Advertisements

P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Lecture 11: Code Optimization CS 540 George Mason University.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Carnegie Mellon Lecture 7 Instruction Scheduling I. Basic Block Scheduling II.Global Scheduling (for Non-Numeric Code) Reading: Chapter 10.3 – 10.4 M.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
Overview Motivations Basic static and dynamic optimization methods ADAPT Dynamo.
Whole-Program Linear-Constant Analysis with Applications to Link-Time Optimization Ludo Van Put – Dominique Chanet – Koen De Bosschere Ghent University.
Components of representation Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements occur in right order Data.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Dataflow Analysis Introduction Guo, Yao Part of the slides are adapted from.
Program Representations. Representing programs Goals.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
Example in SSA X := Y op Z in out F X := Y op Z (in) = in [ { X ! Y op Z } X :=  (Y,Z) in 0 out F X :=   (in 0, in 1 ) = (in 0 Å in 1 ) [ { X ! E |
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Feedback: Keep, Quit, Start
Recap from last time Saw several examples of optimizations –Constant folding –Constant Prop –Copy Prop –Common Sub-expression Elim –Partial Redundancy.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
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.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
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.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
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 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Class canceled next Tuesday. Recap: Components of IR Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements.
Parallelizing Compilers Presented by Yiwei Zhang.
1 CS 201 Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding.
Improving Code Generation Honors Compilers April 16 th 2002.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Introduction to Optimization Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Schedule Midterm out tomorrow, due by next Monday Final during finals week Project updates next week.
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.
Composing Dataflow Analyses and Transformations Sorin Lerner (University of Washington) David Grove (IBM T.J. Watson) Craig Chambers (University of Washington)
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
1 CS 201 Compiler Construction Data Flow Analysis.
Synchronization Transformations for Parallel Computing Pedro Diniz and Martin Rinard Department of Computer Science University of California, Santa Barbara.
Jeffrey D. Ullman Stanford University. 2 boolean x = true; while (x) {... // no change to x }  Doesn’t terminate.  Proof: only assignment to x is at.
Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud.
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.
High Performance Embedded Computing © 2007 Elsevier Lecture 10: Code Generation Embedded Computing Systems Michael Schulte Based on slides and textbook.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Code Optimization Data Flow Analysis. Data Flow Analysis (DFA)  General framework  Can be used for various optimization goals  Some terms  Basic block.
CS 412/413 Spring 2005Introduction to Compilers1 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 30: Loop Optimizations and Pointer Analysis.
Code Optimization Overview and Examples
Global Register Allocation Based on
Code Optimization.
Data Flow Analysis Suman Jana
An Evaluation of Staged Run-Time Optimizations in DyC
Machine-Independent Optimization
Topic 10: Dataflow Analysis
University Of Virginia
Calpa: A Tool for Automating Dynamic Compilation
Static Single Assignment
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
CMPE 152: Compiler Design April 30 Class Meeting
Code Optimization.
Presentation transcript:

Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ. of Washington Presented by Zhelong Pan April 12 th, 2002

Introduction Enable optimizations based on the invariant data computed at run-time: Enable optimizations based on the invariant data computed at run-time: –Eliminate memory loads –Perform constant propagation and folding –Remove branches –Fully unroll loops Overhead: the run-time cost of dynamic compilation. Overhead: the run-time cost of dynamic compilation. Goal: Fast compilation and high-quality code. Goal: Fast compilation and high-quality code.

Basic Ideas Step 1: The programmer annotates the dynamic regions. Step 3: Compute and patch the run-time constants to the template. Step 2: Generate pre- optimized templates. Step 4: Use the new code during the execution. Templates: pre-compiled optimized machine-code containing holes to be filled by the run-time data. Set-up code: calculating the values of derived run- time constants. Directives: instructing the dynamic compiler to produce executable code.

Annotation DynamicRegion delineates the section of code to be dynamically compiled. Its arguments indicate the variables are constant at the entry of the dynamic region and remain unchanged. The contents of arrays and pointer-based data are assumed to be run-time constants. Otherwise, the dereference operators should be used, e.g. x:=dynamic* p, x:=p dynamic->f, and x:=a dynamic[i] Unroll directs to completely unroll a loop. To produce several compiled versions, each optimized for a different set of run- time constants, key Variables are defined, e.g. dynamicRegion key(cache)

Static Compiler Identify the constant variables and expressions based on the annotated constants. Identify the constant variables and expressions based on the annotated constants. Split into set-up and template code subgraphs. Split into set-up and template code subgraphs. Apply the standard optimizations with few restrictions. Apply the standard optimizations with few restrictions. Generate machine code and stitcher directives. Generate machine code and stitcher directives.

Computing Derived Run-Time Constants Start with the initial set of constants through the control flow graph, updating the set after each instruction as follows: + x:=y iff y is a constant. + x:=y op z iff y and z are constants, op is an idempotent, side-effect-free, non-trapping operator. + x:=f(y1,…,yn) iff y’s are constants, f is an idempotent, side-effect-free, non-trapping function. + x:=*p iff p is a constant. – x:=dynamic* p: x is not a constant. – *p:=x Start with the initial set of constants through the control flow graph, updating the set after each instruction as follows: + x:=y iff y is a constant. + x:=y op z iff y and z are constants, op is an idempotent, side-effect-free, non-trapping operator. + x:=f(y1,…,yn) iff y’s are constants, f is an idempotent, side-effect-free, non-trapping function. + x:=*p iff p is a constant. – x:=dynamic* p: x is not a constant. – *p:=x

A forward dataflow analysis on control flow graph test is not a constant test is a constant After a control flow merge, if a variable has the same run-time constant reaching definition along all predecessors, it is considered a constant after the merge.

Reachability Analysis(1) A forward dataflow analysis to compute the branch conditions at each program point.

Reachability Analysis (2) If the reachability conditions for each merge predecessor are mutually exclusive, the merge is labeled as a constant merge. For a constant merge, the union is taken. For a non-constant merge, the intersection is taken. (The paper implies it, although it is not given explicitly.)

Reachability Analysis (3) The reachability conditions of the loop entry arc and loop back edge arc are not normally mutually- exclusive, the loop head is treated as a non-constant merge. For an unrolled loop, only one predecessor arc exists. So, its loop head is a constant merge.

Setup codes, templates, directives Static compiler divides each dynamic region into setup code and template code. Setup code computes the runtime constants. Templates contain all the remaining code with “holes” embedded for runtime constants. Stitcher directives are generated to inform the stitcher to patch the holes and unroll the loops.

Optimizations Optimizations (e.g. CSE) can be performed both before and after the dynamic region is divided into setup and template codes. Optimizations (e.g. CSE) can be performed both before and after the dynamic region is divided into setup and template codes. Optimizations performed afterwards must be modified slightly to deal with “holes”, marked as compile time constants with unknown values. Optimizations performed afterwards must be modified slightly to deal with “holes”, marked as compile time constants with unknown values.

Experimental Results

Discussion + Using the run time data to do optimization. + The idea of doing most work during static compilation is important for dynamic/adaptive compilers. – Run-time constant assumption limits its applicability. How much could the real application gain from it? – Annotation is not added automatically by the compiler, which may require inter-procedural analysis and pointer analysis.