{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

04-02regAlloc - Administrivia Code generation Register...

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

View Full Document Right Arrow Icon
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!!)
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern