Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.

Slides:



Advertisements
Similar presentations
1 Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Advertisements

The Last Lecture Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission.
Introduction to Code Optimization Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Instruction Selection Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
The Procedure Abstraction Part I: Basics Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
Introduction to Optimization Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Introduction to Code Generation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Instruction Scheduling II: Beyond Basic Blocks Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp.
Instruction Selection Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Introduction & Overview CS4533 from Cooper & Torczon.
The Procedure Abstraction Part I: Basics Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
Overview of the Course Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Overview of the Course Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Introduction to Optimization, II Value Numbering & Larger Scopes Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
Local Register Allocation & Lab Exercise 1 Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp.
1 EECS 6083 Compiler Theory Based on slides from text web site: Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Cleaning up the CFG Eliminating useless nodes & edges C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Local Instruction Scheduling — A Primer for Lab 3 — Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled.
Introduction to Code Generation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
Compiler Construction Dr. Naveed Ejaz Lecture 4. 2 The Back End Register Allocation:  Have each value in a register when it is used. Instruction selection.
Parsing — Part II (Top-down parsing, left-recursion removal) Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Cleaning up the CFG Eliminating useless nodes & edges This lecture describes the algorithm Clean, presented in Chapter 10 of EaC2e. The algorithm is due.
Instruction Scheduling Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Instruction Scheduling: Beyond Basic Blocks Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Advanced Computer Systems
Introduction to Optimization
Compiler Design (40-414) Main Text Book:
Code Optimization.
Chapter 1 Introduction.
Parsing — Part II (Top-down parsing, left-recursion removal)
Chapter 1 Introduction.
Local Register Allocation & Lab Exercise 1
Compiler Lecture 1 CS510.
Overview of the Course Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Finding Global Redundancies with Hopcroft’s DFA Minimization Algorithm
Local Instruction Scheduling
Context-sensitive Analysis
Lexical Analysis - An Introduction
Introduction to Optimization
Intermediate Representations
Introduction to Code Generation
Lecture 02: Compiler Overview
Instruction Scheduling: Beyond Basic Blocks
Local Instruction Scheduling — A Primer for Lab 3 —
The Procedure Abstraction Part I: Basics
Intermediate Representations
Optimizing Transformations Hal Perkins Winter 2008
The Last Lecture COMP 512 Rice University Houston, Texas Fall 2003
Parsing — Part II (Top-down parsing, left-recursion removal)
Overview of the Course Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Local Register Allocation & Lab Exercise 1
Introduction to Optimization
Lecture 16: Register Allocation
Instruction Scheduling: Beyond Basic Blocks
Compiler Construction
Instruction Scheduling Hal Perkins Autumn 2005
Lexical Analysis - An Introduction
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Compiler Construction
The Partitioning Algorithm for Detecting Congruent Expressions COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper.
Compiler Construction
Presentation transcript:

Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies of these materials for their personal use.

High-level View Definitions Compiler consumes code & produces code Interpreter consumes executable & produces results Source code Machine Compiler Errors The Last Lecture

High-level View Front end consumes source code & produces IR Determines code shape for rest of compiler Middle reads & writes IR Analyzes & transforms IR to “improve” it Myriad techniques at several distinct scopes Back end consumes optimizes IR & produces target code Maps code to target ISA & handles resource issues Errors Source Code Middle Front End Machine code Back IR The Last Lecture

Solved Problems Front End Scanner Applies DFA technology to classify words Use RE-based tools to generate fast scanners Parser Takes stream of classified words & computes structure Many techniques (TDRD, LL(1), LR(1) + others) Context-sensitive Analysis Type-checking & IR generation (AGs & Ad-hoc SDT) Problems are harder & tools not as well developed Errors Source Code Middle Front End Machine code Back IR Solved Problems The Last Lecture

Most compilers need better optimization … Middle (Optimizer) Typically structured as a series of passes Allows for separation of concerns Simplifies development & debugging Rewrites IR to improve running time, code space, … We studied redundancy elimination Other optimizations include code motion, dead-code elimination, constant propagation, strength reduction, … (see Ch 10) Errors Source Code Middle Front End Machine code Back IR Most compilers need better optimization … The Last Lecture

Back End Three Problems Instruction Selection Instruction Scheduling Mapping optimized IR to target machine’s ISA Instruction Scheduling Reordering operations to hide latencies & speed execution Register Allocation Mapping name space of optimized IR to target’s register set Errors Source Code Middle Front End Machine code Back IR The Last Lecture

Back End Instruction Selection This is a pattern-matching problem We looked at tree pattern matching, peephole optimization Other ideas: string matching, ad-hoc matching, parsing, … Criterion is “local optimality” Map immediate context to ISA in an efficient way Leave “global optimality” to optimizer My algorithm of choice: peephole matching Errors Source Code Middle Front End Machine code Back IR The Last Lecture

Back End Instruction Scheduling Fixed set of operations, can vary the order Must preserve inter-operation dependences May change demand for registers List scheduling is dominant paradigm Applied to blocks, extended blocks, regions in code My algorithm of choice: Schielke’s RBF algorithm on EBBs Errors Source Code Middle Front End Machine code Back IR The Last Lecture

Back End Register Allocation Handle disconnect between optimizer’s assumption of unlimited registers and chip’s limited set Insert loads and stores to reconcile the two models (spills) Minimize the slowdown Global allocation via graph coloring is the dominant paradigm Build interference graph and color it Many minor variations, but one strong theme Errors Source Code Middle Front End Machine code Back IR The Last Lecture

Perspective Different concerns in each phase Front end worries about shaping code for optimization Expose facts that can be improved & tailored Middle worries about global issues that affect speed, space Redundancy, constants, code motion, locality, ... Back end worries about using the target’s resources Address modes, functional units, registers, issue slots, … Errors Source Code Middle Front End Machine code Back IR These concerns “bleed” from one phase to another The Last Lecture

Perspective Different complexities in each phase Front end is mostly linear time DFAs, parsers take time proportional to size of input stream Middle is low-order polynomial time Analysis & optimization are O(n) to O(n2 ), in general Back end solves hard problems with approximations Heuristics that typically take O(n) to (n2) Underlying problems are seriously hard Errors Source Code Middle Front End Machine code Back IR The Last Lecture

Perspective Remaining work Front end is solved No more theses on parsing, I hope Middle has some room for work (not a wide open frontier) New machines, new languages present new problems Back end has room for work Complications from new machines Longer latencies, wider processors Errors Source Code Middle Front End Machine code Back IR The Last Lecture