Optimisation = Analysis + Transformation. Lecture 1: Introduction. Optimising Compilers. An optimising compiler. A non-optimising compiler

Lecture 1: Introduction Optimising Compilers Computer Science Tripos Part II - Lent 2007 Tom Stuart A non-optimising compiler An optimising compile...
Author: Leon Johnston
3 downloads 0 Views 3MB Size
Lecture 1: Introduction

Optimising Compilers Computer Science Tripos Part II - Lent 2007 Tom Stuart

A non-optimising compiler

An optimising compiler

character stream

character stream

lexing token stream

token stream

parsing parse tree

optimisation

parse tree

optimisation

intermediate code

optimisation

target code

translation intermediate code

decompilation

code generation target code

Optimisation (really “amelioration”!)

Good humans write simple, maintainable, general code. Compilers should then remove unused generality, and hence hopefully make the code:

• Smaller • Faster • Cheaper (e.g. lower power consumption)

Analysis + Transformation

Optimisation = Analysis + Transformation Analysis + Transformation • An analysis shows that your program has

• Transformation does something dangerous. • Analysis determines whether it’s safe.

some property...

• ...and the transformation is designed to be safe for all programs with that property...

• ...so it’s safe to do the transformation.

Analysis + Transformation

Analysis + Transformation

int main(void) { return 42; }

int main(void) { return 42; }

int f(int x) { return x * 2; }

int f(int x) { return x * 2; }

Analysis + Transformation

Analysis + Transformation

int main(void) { return f(21); }

int main(void) { return f(21); }

int f(int x) { return x * 2; }

int f(int x) { return x * 2; }

Analysis + Transformation

Analysis + Transformation

while (i