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.

Slides:



Advertisements
Similar presentations
CSC 4181 Compiler Construction Code Generation & Optimization.
Advertisements

Code Optimization and Performance Chapter 5 CS 105 Tour of the Black Holes of Computing.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
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.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Advanced Compiler Design CSE 231 Instructor: Sorin Lerner.
Overview Motivations Basic static and dynamic optimization methods ADAPT Dynamo.
Program Representations. Representing programs Goals.
Optimization Compiler Baojian Hua
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
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.
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.
Recap from last time Saw several examples of optimizations –Constant folding –Constant Prop –Copy Prop –Common Sub-expression Elim –Partial Redundancy.
Telescoping Languages: A Compiler Strategy for Implementation of High-Level Domain-Specific Programming Systems Ken Kennedy Rice University.
Automatically Proving the Correctness of Compiler Optimizations Sorin Lerner Todd Millstein Craig Chambers University of Washington.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
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.
4/23/09Prof. Hilfinger CS 164 Lecture 261 IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula)
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.
Advanced Compilers CSE 231 Instructor: Sorin Lerner.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
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.
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; ???
Introduction to Program Optimizations Chapter 11 Mooly Sagiv.
Advanced Compilers CSE 231 Instructor: Sorin Lerner.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Intermediate Code. Local Optimizations
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Lecture 1CS 380C 1 380C Last Time –Course organization –Read Backus et al. Announcements –Hadi lab Q&A Wed 1-2 in Painter 5.38N –UT Texas Learning Center:
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Composing Dataflow Analyses and Transformations Sorin Lerner (University of Washington) David Grove (IBM T.J. Watson) Craig Chambers (University of Washington)
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.
From last class. The above is Click’s solution (PLDI 95)
Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Java Virtual Machine Case Study on the Design of JikesRVM.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
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.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
Programming for Performance CS 740 Oct. 4, 2000 Topics How architecture impacts your programs How (and how not) to tune your code.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
3/2/2016© Hal Perkins & UW CSES-1 CSE P 501 – Compilers Optimizing Transformations Hal Perkins Autumn 2009.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
Course topics Representing programs Analyzing and transforming programs Applications of these techniques.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
Code Optimization Overview and Examples
High-level optimization Jakub Yaghob
Code Optimization.
User-Written Functions
Advanced Compiler Design
Compiler Construction (CS-636)
Optimization Code Optimization ©SoftMoore Consulting.
Machine-Independent Optimization
Optimizing Transformations Hal Perkins Autumn 2011
Inlining and Devirtualization Hal Perkins Autumn 2011
Topic 1: Problem Solving
Optimizing Transformations Hal Perkins Winter 2008
Fall Compiler Principles Lecture 10: Loop Optimizations
Advanced Compiler Design
Tour of common optimizations
Tour of common optimizations
Tour of common optimizations
Presentation transcript:

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 things We will learn more about each one of the topics we touched upon last time

Program Analyzer Issues (discuss) Program Analyzer InputOutput

Input issues Input is a program, but… What language is the program written in? –imperative vs. functional vs. object-oriented? maybe even declarative? –what pointer model does the language use? –reflection, exceptions, continuations? –type system trusted or not? –one often analyzes an intermediate language... how does one design such a language? Instructor’s discussion notes Program Analyzer InputOutput

Input issues How much of the program do we see? –all? –one file at a time? –one library at a time? –reflection… Any additional inputs? –any human help? –profile info? Instructor’s discussion notes Program Analyzer InputOutput

Analysis issues Analysis/compilation model –Separate compilation/analysis quick, but no opportunities for interprocedural analysis –Link-time allows interprocedural and whole program analysis but what about shared precompiled libraries? and what about compile-time? –Run-time best optimization/analysis potential (can even use run-time state as additional information) can handle run-time extensions to the program but severe pressure to limit compilation time –Selective run-time compilation choose what part of compilation to delay until run-time can balance compile-time/benefit tradeoffs Instructor’s discussion notes Program Analyzer InputOutput

Analysis issues Does running-time matter? –for use in IDE? –or in overnight compile? Instructor’s discussion notes Program Analyzer InputOutput

Output issues Form of output varies widely, depending on analysis –alias information –constantness information –loop terminates/does not terminate Correctness of analysis results –depends on what the results are used for –are we attempting to design algorithsm for solving undecidable problems? –notion of approximation –statistical output Instructor’s discussion notes Program Analyzer InputOutput

Program Transformation Issues (discuss) Program Transformer InputOutput

Input issues A program, and … Program analysis results Profile info? Environment: # of CPUs, # of cores/CPU, cache size, etc. Anything else? Instructor’s discussion notes Program Transformer InputOutput

Transformation issues What is profitable? What order to perform transformations? What happens to the program representation? What happens to the computed information? For example alias information? Need to recompute? Instructor’s discussion notes Program Transformer InputOutput

Output issues Output in same IL as input? Should the output program behave the same way as the input program? Instructor’s discussion notes Program Transformer InputOutput

Tour of common optimizations

Simple example foo(z) { x := 3 + 6; y := x – 5 return z * y }

Simple example foo(z) { x := 3 + 6; y := x – 5 return z * y }

Another example x := a + b;... y := a + b;

Another example x := a + b;... y := a + b;

Another example if (...) { x := a + b; }... y := a + b;

Another example if (...) { x := a + b; }... y := a + b;

Another example x := y... z := z + x

Another example x := y... z := z + x

Another example x := y... z := z + y What if we run CSE now?

Another example x := y... z := z + y What if we run CSE now?

Another example x := y**z... x :=...

Another example Often used as a clean-up pass x := y**z... x :=... x := y z := z + x x := y z := z + y Copy propDAE x := y z := z + y

Another example if (false) {... }

Another example if (false) {... }

Another example In Java: a = new int [10]; for (index = 0; index < 10; index ++) { a[index] = 100; }

Another example In “lowered” Java: a = new int [10]; for (index = 0; index < 10; index ++) { if (index = a.length()) { throw OutOfBoundsException; } a[index] = 0; }

Another example In “lowered” Java: a = new int [10]; for (index = 0; index < 10; index ++) { if (index = a.length()) { throw OutOfBoundsException; } a[index] = 0; }

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; ???

Another example for j := 1 to N for i := 1 to M a[i] := a[i] + b[j]

Another example for j := 1 to N for i := 1 to M a[i] := a[i] + b[j]

Another example area(h,w) { return h * w } h :=...; w := 4; a := area(h,w)

Another example area(h,w) { return h * w } h :=...; w := 4; a := area(h,w)

Optimization themes Don’t compute if you don’t have to –unused assignment elimination Compute at compile-time if possible –constant folding, loop unrolling, inlining Compute it as few times as possible –CSE, PRE, PDE, loop invariant code motion Compute it as cheaply as possible –strength reduction Enable other optimizations –constant and copy prop, pointer analysis Compute it with as little code space as possible –unreachable code elimination