Assignment: | Register allocation for PowerPC processor |
Instructor: | Kathryn S. McKinley |
Assigned: | Monday, October 26, 2009 |
Due: | Friday, November 20, 2009, 5PM |
Objective
The goal of this assignment is to implement the register allocation algorithm for the PowerPC processor on Linux.
Project Description
You will implement a register allocation algorithm in your compiler. As in prior assigments, your compiler will call csc compiler on subset C files. Then, your register allocator will take the 3-address format program as the input, and perform register allocation for the PowerPC processor. It will generate an intermediate format called RA3 code (register allocated 3-address format code) as the output. Then, you will translate the code in RA3 from to PowerPC assembly code by calling a translator that we provide. You need to test your code on PowerPC machine, and generate an analysis report based on the results.
Getting Started On Lab1
"tar xvfz cs380c_lab4.tgz".This command will produce the following directory structure
cs380c_lab1 3addr_to_ppc examples lab4 srcThe source files of the 3-addr to PowerPC translator are in the 3addr_to_ppc directory. Here is an example call to the translator:
Implementation Specification
Perform register allocation from the source of your choice. You will generate the RA3 format code, which is an extension of the 3-address format.
instr 6: add res_base#32756 GP r19~instr 7: load res_base#32756You only need to allocate one register for the results of the 2nd instruction. Please notice the format of the 2nd instruction is different from the 3-address format. B: Store global variable:
instr 4: add res_base#32756 GP instr 5: store 18 res_base#32756This instruction stores a constant 18 in a global variable with the address 32756. If a register is stored, the instructions are:
instr 4: add res_base#32756 GP instr 5: store r18~ res_base#32756This instruction stores the contents of register r18 in a global variable with the address 32756.
The example of a 3-address format code and its RA3 format code are listed below:
long res; void main() { long x, y, z; res = 8; x =res; x =0; y =1; z =2; y = x *10; z = y + 1000; if (z<=2000) { z = z + 5; } res = z; WriteLong(z); //printf("%d \n", z); }3-address format code:
instr 1: nop instr 2: entrypc instr 3: enter 12 instr 4: add res_base#32764 GP instr 5: store 8 (4) instr 6: add res_base#32764 GP instr 7: load (6) instr 8: move (7) x#-4 instr 9: move 0 x#-4 instr 10: move 1 y#-8 instr 11: move 2 z#-12 instr 12: mul x#-4 10 instr 13: move (12) y#-8 instr 14: add y#-8 1000 instr 15: move (14) z#-12 instr 16: cmple z#-12 2000 instr 17: blbc (16) [20] instr 18: add z#-12 5 instr 19: move (18) z#-12 instr 20: add res_base#32764 GP instr 21: store z#-12 (20) instr 22: write z#-12 instr 23: ret 0 instr 24: nopRA3 format code:
instr 1: nop instr 2: entrypc instr 3: enter 12 instr 4: add res_base#32764 GP instr 5: store 8 res_base#32764 instr 6: add res_base#32764 GP r19~instr 7: load res_base#32764 instr 8: store r19~ x#-4 instr 9: store 0 x#-4 instr 10: store 1 y#-8 instr 11: store 2 z#-12 r20~instr 12: load x#-4 r21~instr 13: load y#-8 r22~instr 14: load z#-12 r23~instr 15: mul r20~ 10 instr 16: move r23~ r21~ r24~instr 17: add r21~ 1000 instr 19: move r24~ r22~ instr 20: store r21~ y#-8 instr 21: store r22~ z#-12 instr 23: cmplt r22~ 2000 instr 24: blbc (23) [27] r22~instr 25: add r22~ 5 instr 26: store r22~ z#-12 instr 27: add res_base#32764 GP instr 28: store r22~ res_base#32764 instr 29: write r22~ instr 30: ret 0 instr 31: nop
Register Name | Usage |
---|---|
r0 | Volatile register which may be modified during function linkage |
r1 | Stack frame pointer, always valid |
r2 | System-reserved register |
r3-r4 | Volatile registers used for parameter passing and return values |
r5-r10 | Volatile registers used for parameter passing |
r11-r12 | Volatile registers which may be modified during function linkage |
r13 | Small data area pointer register |
r14-r30 | Registers used for local variables Only these numbers are available to your register allocator. |
r31 | Used for local variables or "environment pointers" |
CR0-CR7 | Condition Register Fields, each 4 bits wide |
LR | Link Register |
<Graph coloring/Linear scan> Register number: 4, Number of Spills: 20Then, You will translate the ra3 code into ppc assembly code by calling the translator provided on a CS Linux machine. You will test your assebmly code on a PPC machine (we will send you account information shortly). You will report the compilation and execution time. Please report the execution time with variant number of registers as below, note, you need to generate this report manually, and write it into a file, named testcase1.ppc.rep. C File: testcase1.c
<Graph coloring/Linear scan> Compile time: .15s Register number: 4, Execution time: 0.12s Register number: 6, Execution time: 0.08s Register number: 8, Execution time: 0.04s ... ... Register number: 16, Execution time: 0.02s
Turning In Your Assignment
Your assignment should contain the following.
Turn in your assignment by running the following commands on a UTCS Linux machine.
$ # Go the parent directory of the lab1 directory. $ tgz lab4 lab4/ $ turnin --submit hadi cs380c-lab4 lab4.tgz $ turnin --list hadi cs380c-lab4Thanks & Acknowledgements
These assignments are derived from similar ones developed by Keshav Pingali. Martin Burtscher developed the csc compiler that the assignments use. Thank you Keshav and Martin.