04-02regAlloc - 1 CSE 450: Compilers K. Stirewalt Code...

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CSE 450: Compilers K. Stirewalt Code generation Register allocation problem Topics: Administrivia and project questions Register allocation problem Control flow graphs Graph coloring strategy CSE 450: Compilers K. Stirewalt Administrivia Project 5 deadline extended by one week to Friday, April 18 th involves changes to scope of project #6, which will be due Friday, April 25 th there will be no Quiz #9 Quiz #8 rescheduled to Wednesday, April 16 th Final exam: Friday, May 2 nd from 10:00-12:00 noon in this room CSE 450: Compilers K. Stirewalt Project #6 Involves a hand translation of 3-address code generated by your compiler into target code We will provide two small SpartanAda programs as source You must use your compiler to generate the IR from these programs; then translate each statement in sequence into the target code Deliverable will be a written document and may include any explanatory text you deem appropriate Due Friday, April 25 th Look for project posting by this weekend CSE 450: Compilers K. Stirewalt Project 5 Q&A Questions??? CSE 450: Compilers K. Stirewalt Recall... If efficiency is not of concern, then we can translate 3-address instructions one by one, in isolation, to generate target code However, this strategy leads to terribly inefficient code More efficient strategies consider more context during translation Several key ideas and algorithms: Control flow graph representations Local vs. global optimizations Register-allocation strategies/algorithms CSE 450: Compilers K. Stirewalt Register Allocation Problem IR generator creates lots of temporaries Simplifies code generation and optimization But also potentially wasteful, as we never generate IR that reuses a temporary The register allocation problem: Rewrite the code to minimize compiler temporaries Method: pass up values and re-use temporaries (But without changing the program behavior!!) 2 CSE 450: Compilers K. Stirewalt How to reduce temporaries? 1. Re-use the same temporary variable after we would otherwise be finished with it Requires being able to know when you are finished with it! 2. Directly use constants when possible rather than saving them as temporaries. 3. Use an interpreter: Perform any math on constants at compile time. CSE 450: Compilers K. Stirewalt An Example Consider the program fragment a = 2 + 4 b = a * 5 c = b - 1 assume that a and b are not used later in the code Register used to hold the value of a can be reused after a * 5 Same with register for b after b - 1 Can allocate a , b , and c all to one register ( r 1 ): LD r1, #6 MUL r1, r1, 5 SUB r1, r1, 1 Notice: did not need to store values of a and b either...
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.

Page1 / 7

04-02regAlloc - 1 CSE 450: Compilers K. Stirewalt Code...

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