Advanced Compiler Design

Slides:



Advertisements
Similar presentations
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Advertisements

Advanced Compiler Design CSE 231 Instructor: Sorin Lerner.
Object Oriented Programming in Java George Mason University Fall 2011
Program Representations. Representing programs Goals.
Automated Soundness Proofs for Dataflow Analyses and Transformations via Local Rules Sorin Lerner* Todd Millstein** Erika Rice* Craig Chambers* * University.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
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.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
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.
Cpeg421-08S/final-review1 Course Review Tom St. John.
Automatically Proving the Correctness of Compiler Optimizations Sorin Lerner Todd Millstein Craig Chambers University of Washington.
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.
From last time: live variables Set D = 2 Vars Lattice: (D, v, ?, >, t, u ) = (2 Vars, µ, ;,Vars, [, Å ) x := y op z in out F x := y op z (out) = out –
Advanced Compilers CSE 231 Instructor: Sorin Lerner.
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.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
Chair of Software Engineering Fundamentals of Program Analysis Dr. Manuel Oriol.
Advanced Compilers CSE 231 Instructor: Sorin Lerner.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
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; ???
UMass Lowell Computer Science Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2004 Project.
Advanced Compilers CSE 231 Instructor: Sorin Lerner.
From last time S1: l := new Cons p := l S2: t := new Cons *p := t p := t l p S1 l p tS2 l p S1 t S2 l t S1 p S2 l t S1 p S2 l t S1 p L2 l t S1 p S2 l t.
Compiler Construction
From last lecture x := y op z in out F x := y op z (in) = in [ x ! in(y) op in(z) ] where a op b =
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
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.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 1: Getting Started by George Lamperti & BU Faculty.
Projects. Dataflow analysis Dataflow analysis: what is it? A common framework for expressing algorithms that compute information about a program Why.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
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)
Precision Going back to constant prop, in what cases would we lose precision?
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Course Overview John Cavazos University.
CSCA48 Course Summary.
Guiding Principles. Goals First we must agree on the goals. Several (non-exclusive) choices – Want every CS major to be educated in performance including.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Advanced Compilers CMPSCI 710 Spring 2004 Lecture 1 Emery Berger University of Massachusetts,
Principles of Computer Science I Honors Section Note Set 1 CSE 1341 – H 1.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 1.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
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.
An Undergraduate Course on Software Bug Detection Tools and Techniques Eric Larson Seattle University March 3, 2006.
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2003 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
CS 161 Introduction to Computer Science I Winter, 2014: 112 Spring, 2014: 131 Summer, 2014: 132.
Course topics Representing programs Analyzing and transforming programs Applications of these techniques.
Welcome! Simone Campanoni
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
CSC207 Fall 2016.
Topic: Programming Languages and their Evolution + Intro to Scratch
Advanced Compiler Design
Introduction to Compiler Construction
CSE 662 – Languages and Databases Class Overview
Compiler Construction (CS-636)
Dataflow analysis.
Optimization Code Optimization ©SoftMoore Consulting.
Advanced Compilers CMPSCI 710 Spring 2003 Lecture 1
Topic 10: Dataflow Analysis
Week # 1: Overview & Review
Exam Topics Hal Perkins Autumn 2009
CMSC201 Computer Science I for Majors Final Exam Information
Compiler Construction
Optimizing Compilers CISC 673 Spring 2009 Course Overview
IS 135 Business Programming
Advanced Compiler Design
Presentation transcript:

Advanced Compiler Design CSE 231 Instructor: Sorin Lerner

Let’s look at a compiler Parser Code Gen Compiler Optimizer if (…) { x := …; } else { y := …; } …; Exec Compiler

Let’s look at a compiler Parser Code Gen Compiler Parser Code Gen Compiler Optimizer

Advanced Optimizer Design CSE 231 Instructor: Sorin Lerner

What does an optimizer do? Parser Code Gen Compiler Optimizer Compute information about a program Use that information to perform program transformations (with the goal of improving some metric, e.g. performance)

What do these tools have in common? Bug finders Program verifiers Code refactoring tools Garbage collectors Runtime monitoring system And… optimizers

What do these tools have in common? Bug finders Program verifiers Code refactoring tools Garbage collectors Runtime monitoring system And… optimizers They all analyze and transform programs We will learn about the techniques underlying all these tools

Program Analyses, Transformations, and Applications CSE 231 Instructor: Sorin Lerner

Course goals Understand basic techniques cornerstone of a variety of program analysis tools useful no matter what your future path Get a feel for compiler research/implementation useful if you don’t have a research area picked also useful if you have a research area picked

Course topics Representing programs Analyzing and transforming programs Applications of these techniques

Course topics (more details) Representations Abstract Syntax Tree Control Flow Graph Dataflow Graph Static Single Assignment Control Dependence Graph Program Dependence Graph Call Graph

Course topics (more details) Analysis/Transformation Algorithms Dataflow Analysis Interprocedural analysis Pointer analysis Rule-based analyses and transformations Constraint-based analysis

Course topics (more details) Applications Scalar optimizations Loop optimizations Object oriented optimizations Program verification Bug finding

Course pre-requisites No compilers background necessary No familiarity with lattices I will review what is necessary in class Familiarity with functional/OO programming Optimization techniques for these kinds of languages Standard ugrad cs curriculum likely enough Talk to me if you’re concerned

Course work In-class midterm (30%) Take-home final (30%) Course project (35%) Class readings (5%)

Course project Get some hands on experience with compilers Use LLVM infrastructure to implement Dynamic instrumentation DFA engine Groups of 3 Make groups by next Tuesday

Course project Week 1: Make groups Weeks 2-4: Part 1 Implement dynamic instrumentation Write a one page report Weeks 5-10: Part 2 Design and Implement DFA engine Visualize DFA results Implement Const Prop, CSE, Ptr Analysis, Live Vars Write a 10 page report

Readings Paper readings throughout the quarter One or two papers per week Seminal papers and state of the art Will give you a feel for what research looks like

Administrative info Class web page is up Piazza link on web page http://cseweb.ucsd.edu/classes/sp14/cse231-a/ (or Google “Sorin Lerner”, follow “Teaching Now”) Will post lectures, readings, project info, etc. Piazza link on web page Use for questions, answers Especially LLVM/project Q&A

Questions?

Program Analyzer Issues (discuss) Input Output Program Analyzer

Program Analyzer Issues (discuss) Input Output Program Analyzer

Program Analyzer Issues (discuss) Input Output Program Analyzer

Input issues Input is a program, but… Instructor’s discussion notes Input issues Program Analyzer Input Output 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?

Input issues How much of the program do we see? Any additional inputs? Instructor’s discussion notes Input issues Program Analyzer Input Output 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?

Analysis issues Analysis/compilation model Instructor’s discussion notes Analysis issues Program Analyzer Input Output 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

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

Output issues Form of output varies widely, depending on analysis Instructor’s discussion notes Output issues Program Analyzer Input Output 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 algorithms for solving undecidable problems? notion of approximation statistical output

Program Transformation Issues (discuss) Input Output Program Transformer

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

Transformation issues Instructor’s discussion notes Transformation issues Program Transformer Input Output 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?

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