lec19mod - CS415 Compilers Code Generation These slides are...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS415 Compilers Code Generation These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 19 2 cs415, spring 10 Code Generation: Structure of a Compiler (EaC Ch. 7) A compiler is a lot of fast stuff followed by some hard problems The hard stuff is mostly in code generation and optimization For superscalars, its allocation & scheduling that is particularly important Instruction Selection Register Allocation Instruction Scheduling Scanner Parser Analysis & Optimization O(n), O(n log n), … NP-Complete O(n) O(n) NP-Complete NP-Complete Either fast or NP-Complete words IR asm k regs
Background image of page 2
Lecture 19 3 cs415, spring 10 Review - The Big Picture Conventional wisdom says that we lose little by solving these problems independently Instruction selection Use some form of pattern matching Assume enough registers or target “important ” values Instruction scheduling Within a block, list scheduling is “close ” to optimal Across blocks, build framework to apply list scheduling Register allocation Start from virtual registers & map into k Focus on good priority heuristic Optimal for > 85% of blocks Note: many fuzzy terms here!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 19 4 cs415, spring 10 Code Shape Definition All those nebulous properties of the code that impact performance & code “quality” Includes code, approach for different constructs, cost, storage requirements & mapping, & choice of operations Code shape is the end product of many decisions (big & small) Impact Code shape influences algorithm choice & results Code shape can encode important facts, or hide them Rule of thumb: expose as much derived information as possible Example: explicit branch targets in I LOC simplify analysis
Background image of page 4
Lecture 19 5 cs415, spring 10 Code Shape An example What if x is 2 and z is 3? What if y+z is evaluated earlier? The “best” shape for x+y+z depends on contextual knowledge There may be several conflicting options x + y + z x + y t1 t1+ z t2 x + z t1 t1+ y t2 y + z t1 t1+ z t2 + z y x + + z y x + + y z x + + x z y Addition is commutative & associative for integers
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 19 6 cs415, spring 10 Code Shape Another example -- the case statement Implement it as cascaded if-then-else statements Cost depends on where your case actually occurs O(number of cases) Implement it as a binary search Uniform (log n) cost Implement it as a jump table Lookup address in a table & jump to it Uniform (constant) cost Compiler must choose best implementation strategy No amount of massaging or transforming will convert one into another
Background image of page 6
Lecture 19 7 cs415, spring 10 Generating Code for Expressions
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

lec19mod - CS415 Compilers Code Generation These slides are...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online