Notes:
-
Notes on the lab report, and
the 2-up version
- Look at the
Lectures page for more information.
- You should post questions to the class newsgroup
and check the newsgroup for clarifications, corrections, and insightful
comments.
- Last year's grading sheet can be found here.
You can expect this year's grading to be
based on similar if not identical factors.
Lab 1: Local Register Allocation
In the first lab, your task is to implement a pair of algorithms
for local register allocation -- a top-down algorithm and
a bottom-up algorithm.
Your program will take as input a file containing
a sequence of ILOC operations, and will produce an equivalent sequence
of ILOC operations as output. The desired difference between the
files is that the output file should use no more than k
registers, where k is an input parameter that your program
reads from the command line.
All register names in the input file will begin with an "r" followed by
a non-negative integer.
You should not worry about or implement symbolic registers.
The file produced as output by your register allocator should only
refer to registers numbered from
r0 to rk-1 where k is
the number of registers specified on the command line.
Your program should take three command line arguments.
They are, in order
- The number, k, of registers that the allocator will
assume for the target machine.
- A flag that indicates which allocation algorithm will be used
in the run.
Your program should recognize t for the top-down
allocator and b for the bottom-up allocator.
- The name of the input file.
The output file should be written to stdout.
The executable should be named 412alloc. For example, if
you are allocating the file block.i using 5 registers in a
top-down manner the command would be: 412alloc 5 t block.i
[These issues are specified in excruciating detail to simplify
the task of grading the labs. The laboratory assistants must
not only read your reports (see below), but also run enough test
blocks to verify the correct functioning of your lab. A standardized
interface allows them to automate much of this process.]
The input blocks and output blocks are written in a subset of the
ILOC representation. Limited information about ILOC appears in
Appendix A of the book.
The specific subset of ILOC instructions you need to support is the following:
|    |
load | :   |
retrieve a value from memory into a register |
| | loadI | :   |
retrieve a value from the instruction stream into a register |
| | store | :   |
store a value from a register into memory |
| | add | :   |
add the value from two registers & place the result in a
third register |
| | sub | :   |
subtract the value in the second register from the value in the first register & place the result in a
third register |
| | mult | :   |
multiply the value from two registers & place the result in a
third register |
| | lshift | :   |
shift the value in a register to the left by an amount specified
in a second register |
| | rshift | :   |
shift the value in a register to the right by an amount specified
in a second register |
| | output | :   |
write a value to the standard output stream |
These instructions are explained Appendix A of the book.
They are also listed in the lecture notes for Lab1 (Lecture 3 online).
A simulator for ILOC is available in comp412's
directory Lab1.
You may assume that memory locations 0 through 1023 are reserved for
the register allocator.
(The ILOC machine has separate program and data memory.
The examples will all assume that no programmer-stored
values should go into "low" memory.)
Thus, the allocator can spill values into those locations.
Due Date
This lab is formally due at
11:59 pm on Wednesday, September 16, 2009--that
is, one minute before midnight.
You must stop working on your code at that point.
The lab report is due the following Friday, at
11:59 pm on September 18 2009.
The lag between the due dates should allow you to sleep, if
necessary, before writing the lab report.
If you have specific, overriding,
personal reasons why these dates are unreasonable, you should discuss
them directly with the instructor before September 10, 2008.
Specific Details
- Implement a top-down local register allocator, based on
the algorithm in Section 13.3.1 and Exercise 2.a of
Section 13.3 (page 774 in the text).
Answer parts b & c of Exercise 2.a (Section 13.3)
in your lab report.
Propose a technique for solving b, but don't implement it.
- Implement a bottom-up local register allocator, based on
the algorithm in Section 13.3.2
- Test your allocators thoroughly.
Test blocks are available to help
in this process.
Invent at least 4 of your own test blocks and leave them
in your Lab 1 directory (explained below).
Use the simulator (in ~comp412/Lab1 on OwlNet) to ensure that
your allocated code is correct and to determine its execution
time.
- Run your allocator on each of the
Report blocks. Check their correctness and performance
using the ILOC simulator.
- Write up a brief (five to ten pages) report on the lab. It should
include:
- descriptions of the algorithms that you implemented, highlighting
differences between your implementations and the discussion in the
text;
- an explanation of how to invoke the allocator, including both
necessary and optional command line arguments;
- a table showing the results of running your allocator on each
report block for a machine with five (5) registers,
one with ten (10) registers, and one with twenty (20) registers; and
- a concise discussion of the experimental results and what conclusions
you draw about the performance of the two local allocators.
The report should be in either PostScript or PDF form with the name
report.*, where * is either ps or pdf respectively. When converting to
PostScript or PDF please make sure that
the document displays properly from an OwlNet computer.
-
Leave all the code and the documentation in a directory named
412/Lab1 on your OwlNet account.
Be sure to set the permissions
so that the professor and laboratory assistants can read the
directory and execute your code.
Thanks to the new campus-wide storage system, it may actually
be difficult to accomplish this situation. More on the subject
in class.
Grading Criteria
The grading criteria will be as follows:
Your lab should perform register allocation, not general optimization.
There is no bonus for linguistic virtuosity.
Writing the lab in an odd dialect of an irrelevant language
gets no more points than writing it in a mainline language
such as Scheme, C, C++, Java, or ML. However, don't forget that scripting
languages, specifically PERL and Python, are not allowed.