Lecture9 - Instruction Selection CSE 501 Lecture 9 April...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Instruction Selection CSE 501 Lecture 9 April 27, 2009 Questions? About the last lecture? About the programming assignments? About the reading? Any critiques ready? An Optimizing Compiler FE SL TL BE IL IL optimizer Remember this picture? We've been focusing on optimization. Now we'll spend some time looking at the back end, aka the code generator . We'll focus on cases where the TL = assembly. Code Generation Pursuing our separation of concerns, we think of code generation as having three parts: Instruction selection Register allocation Instruction scheduling And, as usual, multiple phases implies a phase-ordering problem. For some machines, one part or another won't matter too much. In other tougher cases, we'll have to explore new ideas. Instruction Selection For best optimization, we like an IL that's very low level. Trying to expose every detail of the computation to optimization. Typically, target machines have instructions that do more than one thing at once. E.g., this bit of x64 assembly add %r8, $123(%r9, %r10, 2) which I'd write out as t1 = r10 << 2 t2 = t1 + r9 t3 = t2 + 123 t4 = *t3 t5 = t4 + r8 *t3 = t5 oh, and there's the condition codes too! An Example Typically, we'll be considering each basic block individually. Here's IL for a simple statement, i = c + 4, where c is a char and i is an int. t1 = &i t2 = &c t3 = *t2 t4 = cvci(t3) t5 = 4 t6 = t4 + t5 *t1 = t6 The details will vary depending on your IL and your optimizer. If we're in a hurry, or targeting a RISC machine, we could just choose 7 simple assembly instructions. We'll try to do better. Selection via Peephole Optimization An approach pursued by Chris Fraser and his students. Considers pairs of (not necessarily adjacent) instructions and tries to replace them with a single, cheaper instruction. For example, t2 = &c t3 = *t2 might be replaced by t3 = c Similarly, t5 = 4 t6 = t4 + t5 might become t5 = t3 + 4 Which Pairs of Instructions? In olden times, we looked at all pairs of adjacent instructions. Fraser noticed that most useful pairs were connected by UD chains! t2 = &c t3 = *t2 t5 = 4 t6 = t4 + t5 Suddenly we had a plan: Consider each instruction together with the instructions that feed it....
View Full Document

This note was uploaded on 02/09/2012 for the course CSE 403 taught by Professor Staff during the Spring '08 term at University of Washington.

Page1 / 36

Lecture9 - Instruction Selection CSE 501 Lecture 9 April...

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

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