Docsity

two and three pass compiler architecture, Slides of Compiler Construction

Partial preview of the text

Download two and three pass compiler architecture and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 4

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

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

The Back End

Register Allocation:  Optimal register allocation is NP-Complete. Instruction selection IR (^) machine code errors Register allocation Instruction scheduling

IR IR

The Back End

Instruction Scheduling:  Use all functional units productively. Instruction selection IR (^) machine code errors Register allocation Instruction scheduling

IR IR

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

Three-pass Compiler

 Analyzes IR and rewrites (or transforms ) IR 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 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 Front End Source code machine code errors Middle End Back End

IR IR

Optimizer

 Modern optimizers are structured as a series of passes Opt 1

IR IR

errors Opt 2 Opt n

IR

IR Opt 3

IR

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

Optimizer

Typical transformations

Specialize some computation based on context Opt 1

IR IR

errors Opt 2 Opt n

IR

IR Opt 3

IR

Optimizer

Typical transformations  Remove useless or unreachable code Opt 1

IR IR

errors Opt 2 Opt n

IR

IR Opt 3

IR

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