Docsity

Three pass Compiler, Optimizer - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Partial preview of the text

Download Three pass Compiler, Optimizer - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 4

2

The Back End

Register Allocation:

 Have each value in a register

when it is used.

Instruction selection

IR (^) machine code

errors

Register allocation

Instruction scheduling

IR IR

4

The Back End

Register Allocation:

 Can change instruction choices

and insert LOADs and STOREs.

Instruction selection

IR (^) machine code

errors

Register allocation

Instruction scheduling

IR IR

5

The Back End

Register Allocation:

 Optimal register allocation is

NP-Complete.

Instruction selection

IR (^) machine code

errors

Register allocation

Instruction scheduling

IR IR

7

The Back End

Instruction Scheduling:

 Use all functional units

productively.

Instruction selection

IR (^) machine code

errors

Register allocation

Instruction scheduling

IR IR

8

The Back End

Instruction Scheduling:

 Optimal scheduling is

NP-Complete in nearly all cases.

Instruction selection

IR (^) machine code

errors

Register allocation

Instruction scheduling

IR IR

10

Three-pass Compiler

 Analyzes IR and rewrites (or

transforms ) IR

Front End

Source code

machine code

errors

Middle End

Back End

IR IR

11

Three-pass Compiler

 Primary goal is to reduce

running time of the compiled

code

Front End

Source code

machine code

errors

Middle End

Back End

IR IR

13

Three-pass Compiler

 Must preserve “meaning” of the

code.

 Measured by values of named

variables

Front End

Source code

machine code

errors

Middle End

Back End

IR IR

14

Optimizer

 Modern optimizers are

structured as a series of

passes

Opt 1

IR IR

errors

Opt 2

Opt n

IR (^) IR Opt 3

IR

16

Optimizer

Typical transformations

 Move a computation to a less

frequently executed place

Opt 1

IR IR

errors

Opt 2

Opt n

IR (^) IR Opt 3

IR

17

Optimizer

Typical transformations

 Specialize some computation

based on context

Opt 1

IR IR

errors

Opt 2

Opt n

IR (^) IR Opt 3

IR

19

Optimizer

Typical transformations

 Remove useless or

unreachable code

Opt 1

IR IR

errors

Opt 2

Opt n

IR (^) IR Opt 3

IR

20

Optimizer

Typical transformations

 Encode an idiom in some

particularly efficient form

Opt 1

IR IR

errors

Opt 2

Opt n

IR (^) IR Opt 3

IR