Compiler Construction CS 606 Sohail Aslam Lecture 4 compiler: intro
The Back End Register Allocation: IR Instruction selection IR Register allocation IR Instruction scheduling machine code errors Register Allocation: Have each value in a register when it is used.
The Back End Register Allocation: IR Instruction selection IR Register allocation IR Instruction scheduling machine code errors Register Allocation: Manage a limited set of resources – register file.
The Back End Register Allocation: IR Instruction selection IR Register allocation IR Instruction scheduling machine code errors Register Allocation: Can change instruction choices and insert LOADs and STOREs.
The Back End Register Allocation: IR Instruction selection IR Register allocation IR Instruction scheduling machine code errors Register Allocation: Optimal register allocation is NP-Complete.
The Back End Instruction Scheduling: IR Instruction selection IR Register allocation IR Instruction scheduling machine code errors Instruction Scheduling: Avoid hardware stalls and interlocks.
The Back End Instruction Scheduling: IR Instruction selection IR Register allocation IR Instruction scheduling machine code errors Instruction Scheduling: Use all functional units productively.
The Back End Instruction Scheduling: IR Instruction selection IR Register allocation IR Instruction scheduling machine code errors Instruction Scheduling: Optimal scheduling is NP-Complete in nearly all cases.
Three-pass Compiler IR IR Front End Source code Middle End Back End machine code errors Intermediate stage for code improvement or optimization
Three-pass Compiler Analyzes IR and rewrites (or transforms) IR IR IR Front End Source code Middle End Back End machine code errors Analyzes IR and rewrites (or transforms) IR
Three-pass Compiler IR IR Front End Source code Middle End Back End machine code errors Primary goal is to reduce running time of the compiled code
Three-pass Compiler IR IR Front End Source code Middle End Back End machine code errors May also improve space usage, power consumption, ...
Three-pass Compiler Must preserve “meaning” of the code. IR IR Front End Source code Middle End Back End machine code errors Must preserve “meaning” of the code. Measured by values of named variables
Optimizer Modern optimizers are structured as a series of passes Opt 1 IR errors Opt 2 n 3 Modern optimizers are structured as a series of passes
Optimizer Typical transformations IR errors Opt 2 n 3 Typical transformations Discover & propagate some constant value
Optimizer Typical transformations IR errors Opt 2 n 3 Typical transformations Move a computation to a less frequently executed place
Optimizer Typical transformations IR errors Opt 2 n 3 Typical transformations Specialize some computation based on context
Optimizer Typical transformations IR errors Opt 2 n 3 Typical transformations Discover a redundant computation & remove it
Optimizer Typical transformations Remove useless or unreachable code IR errors Opt 2 n 3 Typical transformations Remove useless or unreachable code
Optimizer Typical transformations IR errors Opt 2 n 3 Typical transformations Encode an idiom in some particularly efficient form
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
Related to Compilers Interpreters (direct execution) Assemblers Preprocessors Text formatters (non-WYSIWYG) Analysis tools