Lecture_04.pptm,nm,nm,nmnnnnnnnnnnnnnmnnmnnm

HammadRajput20 6 views 22 slides Apr 29, 2024
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

Lecture_04.ppt


Slide Content

Compiler
Construction
Lecture 4

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
Tags