Compiler Construction - Lecture 03
Compiler Construction - Lecture 03
Compiler Construction - Lecture 03
Construction
Lecture 3
Syntax Tree
goal
x+2-y expr
expr op term
3
Abstract Syntax Trees
+ <id,y>
<id,x> <number,2>
4
Abstract Syntax Trees
–
+ <id,y>
<id,x> <number,2>
5
Abstract Syntax Trees
–
+ <id,y>
<id,x> <number,2>
errors
7
The Back End
8
The Back End
9
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Selection:
Produce fast, compact code.
10
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Selection:
Take advantage of target features such as addressing modes.
11
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Selection:
Usually viewed as a pattern matching problem – dynamic programming.
12
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Selection:
Spurred by PDP-11 to VAX-11
- CISC. 13
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Selection:
RISC architecture simplified
this problem. 14
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Register Allocation:
Have each value in a register
when it is used. 15
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Register Allocation:
Manage a limited set of
resources – register file. 16
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Register Allocation:
Can change instruction choices and insert LOADs and STOREs.
17
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Register Allocation:
Optimal register allocation is
NP-Complete. 18
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Scheduling:
Avoid hardware stalls and
interlocks. 19
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Scheduling:
Use all functional units
productively. 20
The Back End
IR Instruction IR Register IR Instruction machine
selection allocation scheduling code
errors
Instruction Scheduling:
Optimal scheduling is
NP-Complete in nearly all cases.
21