Lecture 1 Introduction
Lecture 1 Introduction
Compilers
What
• Bringing things together – Compile
• Hope we shall make it.
Why compilers
• 1% improvement means billions of dollars in a data
center.
• Code optimization at programming, deployment,
and configuration require
– Language skills
– Compilers
– Runtime implementation
• the best boys behind google are compiler engineers
– Jeff Dean, Sanjay Ghemawat, Urs Hoelzle
• Jobs, better programming, computer scientist
Why compilers
How to talk to
different hardware
How are these
various
languages
executed
Where compiler engineers work
Companies developing compilers
• Intel - icc
• Mozilla - jaegerMonkey, IonMonkay,
TraceMonkey
• Apple – LLVM Hardware
• Google – ART, V8 companies need
• Codeplay compilation
• Coverity technology
• Pathscale, etc
Motivation
To understand;
• language processing: HLL to LLL translation
• Appreciate programming language features
• Implementation challenges
• Intersection between H/W and system S/W
Interested in writing a new compiler
“ the quality of the kitchen influences the quality of
cooking too ”
Other reason for learning compiler design
Source Machine
Frontend IR Optimizer IR Backend code
• Frontend
– Dependent on source language
– Lexical analysis
– Parsing
– Semantic analysis (e.g., type checking)
Structure cont’
Source Machine
Frontend IR Optimizer IR Backend code
• Optimizer
– Independent part of target processor
– Effort to realize efficiency
– Can be very computationally intensive
Structure cont’
Source Machine
Frontend IR Optimizer IR Backend code
• Backend
– Dependent on target processor
– Code selection
– Code scheduling
– Register allocation
– Processor (target) dependant optimization
Thanks to Andy D. Pimentel
Thanks to Frank Pfenning
Front end
• scanning: a scanner groups input characters into tokens;
• parsing: a parser recognizes sequences of tokens
according to some grammar and generates Abstract
Syntax Trees (ASTs);
• Semantic analysis: performs type checking (ie, checking
whether the variables, functions etc in the source
program are used consistently with their definitions and
with the language semantics) and translates ASTs into IRs;
• optimization: optimizes IRs.
Back end
• instruction selection: maps IRs into assembly
code;
• code optimization: optimizes the assembly
code using control-flow and data-flow
analyses, register allocation, etc;
• code emission: generates machine code from
assembly code.
Object file
• This file is not executable since it may refer to external symbols
(such as system calls). The OS uses Linker and loader to execute
the code:
• linking: A linker takes several object files and libraries as input and
produces one executable object file. It retrieves from the input
files (and puts them together in the executable object file) the
code of all the referenced functions/procedures and it resolves all
external references to real addresses. The libraries include the
operating sytem libraries, the language-specific libraries, and,
maybe, user-created libraries.
• loading: A loader loads an executable object file into memory,
initializes the registers, heap, data, etc and starts the execution of
the program.
Interesting Question on Languages
• Why many programming languages?
• Why new programming languages?
• What is a good programming language?