The Back End
Register Allocation:
•Have each value in a register
when it is used.
2
Instruction
selection
IR machine
code
errors
Register
allocation
Instruction
scheduling
IR IR
The Back End
Register Allocation:
•Manage a limited set of resources
–register file.
3
Instruction
selection
IR machine
code
errors
Register
allocation
Instruction
scheduling
IR IR
The Back End
Register Allocation:
•Can change instruction choices and insert LOADs and STOREs.
4
Instruction
selection
IR machine
code
errors
Register
allocation
Instruction
scheduling
IR IR
The Back End
Register Allocation:
•Optimal register allocation is NP-
Complete.
5
Instruction
selection
IR machine
code
errors
Register
allocation
Instruction
scheduling
IR IR
The Back End
Instruction Scheduling:
•Avoid hardware stalls and
interlocks.
6
Instruction
selection
IR machine
code
errors
Register
allocation
Instruction
scheduling
IR IR
The Back End
Instruction Scheduling:
•Use all functional units
productively.
7
Instruction
selection
IR machine
code
errors
Register
allocation
Instruction
scheduling
IR IR
The Back End
Instruction Scheduling:
•Optimal scheduling is
NP-Completein nearly all cases.
8
Instruction
selection
IR machine
code
errors
Register
allocation
Instruction
scheduling
IR IR
Three-pass Compiler
•Intermediate stage for code
improvement or optimization
9
Front
End
Source
code
machine
code
errors
Middle
End
Back
End
IR IR
Three-pass Compiler
•Analyzes IR and rewrites (or
transforms) IR
10
Front
End
Source
code
machine
code
errors
Middle
End
Back
End
IR IR
Three-pass Compiler
•Primary goal is to reduce running
time of the compiled code
11
Front
End
Source
code
machine
code
errors
Middle
End
Back
End
IR IR
Three-pass Compiler
•May also improve space usage,
power consumption, ...
12
Front
End
Source
code
machine
code
errors
Middle
End
Back
End
IR IR
Three-pass Compiler
•Must preserve “meaning” of the code.
•Measured by values of named variables
13
Front
End
Source
code
machine
code
errors
Middle
End
Back
End
IR IR
Optimizer
•Modern optimizers are structured
as a series of passes
14
Opt
1
IR IR
errors
Opt
2
Opt
n
IR IROpt
3
IR
Optimizer
Typical transformations
•Discover & propagate some
constant value
15
Opt
1
IR IR
errors
Opt
2
Opt
n
IR IROpt
3
IR
Optimizer
Typical transformations
•Move a computation to a less
frequently executed place
16
Opt
1
IR IR
errors
Opt
2
Opt
n
IR IROpt
3
IR
Optimizer
Typical transformations
•Specialize some computation
based on context
17
Opt
1
IR IR
errors
Opt
2
Opt
n
IR IROpt
3
IR
Optimizer
Typical transformations
•Discover a redundant
computation & remove it
18
Opt
1
IR IR
errors
Opt
2
Opt
n
IR IROpt
3
IR
Optimizer
Typical transformations
•Remove useless or unreachable
code
19
Opt
1
IR IR
errors
Opt
2
Opt
n
IR IROpt
3
IR
Optimizer
Typical transformations
•Encode an idiom in some
particularly efficient form
20
Opt
1
IR IR
errors
Opt
2
Opt
n
IR IROpt
3
IR
Role of Run-time System
•Memory management
•Allocate/deallocate
•Garbage collection
•Run-time type checking
•Error/exception processing
•Interface to OS –I/O
•Support for parallelism
•Parallel threads
•Communication and synchronization
21
Related to Compilers
•Interpreters (direct execution)
•Assemblers
•Preprocessors
•Text formatters (non-WYSIWYG)
•Analysis tools
22