Compiler Construction Lecture 4 The Back End IR

Compiler Construction Lecture 4

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. 2

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. 3

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. 4

The Back End IR Instruction IR Register IR Instruction machine selection allocation scheduling code errors Register Allocation: § Optimal register allocation is NP-Complete. 5

The Back End IR Instruction IR Register IR Instruction machine selection allocation scheduling code errors Instruction Scheduling: § Avoid hardware stalls and interlocks. 6

The Back End IR Instruction IR Register IR Instruction machine selection allocation scheduling code errors Instruction Scheduling: § Use all functional units productively. 7

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. 8

Three-pass Compiler Source Front code End IR Middle End IR Back machine End code errors § Intermediate stage for code improvement or optimization 9

Three-pass Compiler Source Front code End IR Middle End IR Back machine End code errors § Analyzes IR and rewrites (or transforms) IR 10

Three-pass Compiler Source Front code End IR Middle End IR Back machine End code errors § Primary goal is to reduce running time of the compiled code 11

Three-pass Compiler Source Front code End IR Middle End IR Back machine End code errors § May also improve space usage, power consumption, . . . 12

Three-pass Compiler Source Front code End IR Middle End IR Back machine End code errors § Must preserve “meaning” of the code. § Measured by values of named variables 13

Optimizer IR Opt 2 3 1 IR Opt n IR errors § Modern optimizers are structured as a series of passes 14

Optimizer IR Opt 2 3 1 IR Opt n IR errors Typical transformations § Discover & propagate some constant value 15

Optimizer IR Opt 2 3 1 IR Opt n IR errors Typical transformations § Move a computation to a less frequently executed place 16

Optimizer IR Opt 2 3 1 IR Opt n IR errors Typical transformations § Specialize some computation based on context 17

Optimizer IR Opt 2 3 1 IR Opt n IR errors Typical transformations § Discover a redundant computation & remove it 18

Optimizer IR Opt 2 3 1 IR Opt n IR errors Typical transformations § Remove useless or unreachable code 19

Optimizer IR Opt 2 3 1 IR Opt n IR errors Typical transformations § Encode an idiom in some particularly efficient form 20

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
- Slides: 22