CS980-01
Project Assignment 2
Fall 2007
Due Monday October 8


Modify the pcc3 code generator to change from using a memory-to-memory memory model to using a register-to-register memory model. (See Cooper and Torczon 5.6.2 for a discussion of memory models.)

In particular, change the code generator to use virtual registers for expression temporaries, and for parameters and local variables when feasible. Parameters and local variables may only be placed in virtual registers when they do not have their address taken in the body of the function. (See Cooper and Torcson 7.2.2 for a discussion of this issue.) You will need to write a routine to examine the function body, prior to generating code for the function, to identify which parameters and locals may be placed in virtual registers. For the parameters that can be placed in virtual registers, you should generate code at the beginning of the function to move the parameter values to the virtual registers. Likewise, when calling functions, code should be generated to move values from virtual registers containing the argument expressions to proper location (real register or stack) mandated by the EM64T calling conventions. And code should be generated after the call to move the function return value to a virtual register. Finally, at function exit, code should be generated to move the function return value from a virtual register to the real register mandated by the EM64T calling conventions.

You should assume a set of virtual registers for each major class of registers available on the EM64T architecture: integer, float/double and long double. Assume there are an infinite number of virtual registers available in each set. Allocate these virtual registers on a function-by-function basis. In the later assignments you will map these virtual registers to real registers.

I strongly recommend you annotate the code you generate with information about when virtual registers have their contents defined and used, as well as when the virtual register contents are dead (are no longer needed). However, this will not be required for grading purposes.

For full credit, perform some simple optimizations to improve the quality of the code. In particular, try to avoid placing constants in registers, if they can be directly incorporated into an instruction. And do the same with dereferences of variables that are stored in memory. This may require you to change the REG type defined in defs.h and used as the type of the reg field in the ExprTree struct. This will be worth 10% of the grade for this assignment.

Since the code generated by this assignment will not directly execute, I will not be able to run the test suite or do any other comprehensive testing. However, I will do spot checking of the code you generate as well as the code generator source code itself. Therefore, completeness of the code generator will be a factor in grading.

You should work independently on this assignment. We will talk in class about strategies for approaching this assignment, as well as the relevant EM64T architecture details. Talking to your classmates at this level is fine, but please write your code generator code yourself. Do not share source code on this assignment. My motivation in this regard is simply to get everyone fully involved, as I think I failed to fully involve everyone on the last assignment. Please let me know if you have any questions about this.

To submit this assignment you should tar and gzip up all the necessary modifications to pcc3 and e-mail me the resulting file.

This assignment is due at 1:30pm on Monday October 8. However, these is a two-day grace period that ends at 1:30pm on Wednesday October 10. No assignments may be submitted after this time without my prior approval.


Last modified on September 24, 2007.

Comments and questions should be directed to hatcher@unh.edu