lecture14

lecture14 - Lecture Outline Intermediate code Intermediate...

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

View Full Document Right Arrow Icon
1 Prof. Aiken CS 143 Lecture 14 1 Lecture 14 Prof. Aiken CS 143 Lecture 14 2 Lecture Outline • Intermediate code • Local optimizations • Next time: global optimizations Prof. Aiken CS 143 Lecture 14 3 Code Generation Summary • We have discussed – Runtime organization – Simple stack machine code generation – Improvements to stack machine code generation • Our compiler maps AST to assembly language – And does not perform optimizations Prof. Aiken CS 143 Lecture 14 4 Optimization • Optimization is our last compiler phase • Most complexity in modern compilers is in the optimizer – Also by far the largest phase • First, we need to discuss intermediate languages Prof. Aiken CS 143 Lecture 14 5 Why Intermediate Languages? • When should we perform optimizations? – On AST • Pro : Machine independent • Con : Too high level – On assembly language • Pro : Exposes optimization opportunities • Con : Machine dependent • Con : Must reimplement optimizations when retargetting – On an intermediate language • Pro : Machine independent • Pro : Exposes optimization opportunities Prof. Aiken CS 143 Lecture 14 6 Intermediate Languages • Intermediate language = high-level assembly – Uses register names, but has an unlimited number – Uses control structures like assembly language – Uses opcodes but some are higher level • E.g., push translates to several assembly instructions • Most opcodes correspond directly to assembly opcodes
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Prof. Aiken CS 143 Lecture 14 7 Three-Address Intermediate Code • Each instruction is of the form x := y op z x := op y – y and z are registers or constants – Common form of intermediate code • The expression x + y * z is translated t 1 := y * z t 2 := x + t 1 – Each subexpression has a “name” Prof. Aiken CS 143 Lecture 14 8 Generating Intermediate Code • Similar to assembly code generation • But use any number of IL registers to hold intermediate results Prof. Aiken CS 143 Lecture 14 9 Generating Intermediate Code (Cont.) • igen(e, t) function generates code to compute the value of e in register t • Example: igen(e 1 + e 2 , t) = igen(e 1 , t 1 ) (t 1 is a fresh register) igen(e 2 , t 2 ) (t 2 is a fresh register) t := t 1 + t 2 • Unlimited number of registers simple code generation Prof. Aiken CS 143 Lecture 14 10 Intermediate Code Notes • You should be able to use intermediate code – At the level discussed in lecture • You are not expected to know how to generate intermediate code – Because we won’t discuss it – But really just a variation on code generation . . .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

lecture14 - Lecture Outline Intermediate code Intermediate...

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

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