This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 1 CSE 450: Compilers K. Stirewalt Code generation Survey of global optimizations Topics: – Administrivia and project questions – Peephole optimization – Global optimizations CSE 450: Compilers K. Stirewalt Administrivia Final exam: Friday, May 2 nd from 10:00-12:00 noon in this room Graduating seniors may take the exam Wednesday, April 30th, from 9am - 11am in room 3105 Engineering CSE 450: Compilers K. Stirewalt Project #6 Involves a hand translation of 3-address code generated by your compiler into target code Subject program: test27.adb You must use your compiler to generate the IR from this program; then show how each statement translated into target code Deliverable will be a written document and may include any explanatory text you deem appropriate Due Friday, April 25 th CSE 450: Compilers K. Stirewalt Project 6 Q&A Questions??? CSE 450: Compilers K. Stirewalt Classification of optimizations High-level languages allow 3 optimization types: 1. Local optimizations : Apply to a basic block in isolation 2. Global optimizations : Apply to a control-flow graph (method body) in isolation 3. Inter-procedural optimizations : Apply across method boundaries Most compilers do (1), …many do (2) …and very few do (3) CSE 450: Compilers K. Stirewalt Local Optimizations The simplest form of optimizations are local to a basic block Examples: – Algebraic simplification – Constant folding – Common sub-expression elimination – Dead code elimination 2 CSE 450: Compilers K. Stirewalt Peephole optimization An alternative to careful instruction selection and register allocation Idea: – Generate naïve target code – Then iterate over the generated code, optimizing sequences of instructions within a sliding window or “peephole” Can also be applied to intermediate code prior to target instruction selection CSE 450: Compilers K. Stirewalt Peephole transformations Sliding window comprises small number of (usually contiguous) instructions Typical transformations: – Elimination of redundant loads/stores – Elimination of unreachable code – Flow of control optimizations – Algebraic simplification – Use of machine idioms CSE 450: Compilers K. Stirewalt Elimination of redundancy Naïve code-generation strategies may produce a store followed immediately by a load of the same address E.g.: ST a, R0 LD R0, a Here, the LD is clearly redundant and may be removed CSE 450: Compilers K. Stirewalt Eliminating unreachable code An unlabeled instruction that follows an unconditional jump may be removed E.g.: BR L50 LD R0, a L100: LD R1, z may be replaced with: BR L50 L100: LD R1, z CSE 450: Compilers K. Stirewalt Eliminating jumps over jumps Suppose program has code fragments executed only when a variable debug has value 1 Then might see the code: if debug == 1 goto L1 goto L2 L1: print debugging info L2: Could transform to: if debug != 1 goto L2 L1: print debugging info L2: CSE 450: Compilers K. Stirewalt Furthermore… Suppose we could determine debug == 0:...
View Full Document
This note was uploaded on 07/25/2008 for the course CSE 450 taught by Professor Stirewalt during the Spring '08 term at Michigan State University.
- Spring '08