0% found this document useful (0 votes)
12 views17 pages

Lecture 05

Uploaded by

Kashmala Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views17 pages

Lecture 05

Uploaded by

Kashmala Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

COMPILER CONSTRUCTION

Instructor:
Mr. Sheraz Babar

1
Lecture 05

2
Three-pass Compiler
Source Front IR Middle IR Back machine
code End End End code

errors

 Intermediate stage for code


improvement or optimization
3
Three-pass Compiler
Source Front IR Middle IR Back machine
code End End End code

errors

 Analyzes IR and rewrites (or


transforms) IR
4
Three-pass Compiler
Source Front IR Middle IR Back machine
code End End End code

errors

 Primary goal is to reduce


running time of the compiled
code
5
Three-pass Compiler
Source Front IR Middle IR Back machine
code End End End code

errors

 May also improve space


usage, power consumption, ...
6
Three-pass Compiler
Source Front IR Middle IR Back machine
code End End End code

errors

 Must preserve “meaning” of the


code.
 Measured by values of named
variables
7
Optimizer
IR
IR Opt IR Opt IR Opt Opt IR
1 2 3 n

errors

 Modern optimizers are


structured as a series of
passes
8
Optimizer
IR
IR Opt IR Opt IR Opt Opt IR
1 2 3 n

errors

Typical transformations
 Discover & propagate some
constant value
9
Optimizer
IR
IR Opt IR Opt IR Opt Opt IR
1 2 3 n

errors

Typical transformations
 Move a computation to a less
frequently executed place
10
Optimizer
IR
IR Opt IR Opt IR Opt Opt IR
1 2 3 n

errors

Typical transformations
 Specialize some computation
based on context
11
Optimizer
IR
IR Opt IR Opt IR Opt Opt IR
1 2 3 n

errors

Typical transformations
 Discover a redundant
computation & remove it
12
Optimizer
IR
IR Opt IR Opt IR Opt Opt IR
1 2 3 n

errors

Typical transformations
 Remove useless or
unreachable code
13
Optimizer
IR
IR Opt IR Opt IR Opt Opt IR
1 2 3 n

errors

Typical transformations
 Encode an idiom in some
particularly efficient form
14
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
15
Related to Compilers
 Interpreters (direct execution)
 Assemblers
 Preprocessors
 Text formatters (non-
WYSIWYG)
 Analysis tools
16
The End

17

You might also like