



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Consider the following program fragment. a = 4; b = 0; if (p(a) > b) { c = 18; d = c + 7; a = 9; r(d, a); } else { c = 6; b = c * 4; f = 17; g = s(b, f); p(g);} s(c, b);
Part A (5 points) The control flow graph for this fragment is shown below. Fill in the definitions and uses of the variables (e.g., “def x” and “use w”) in the basic blocks of the graph.
Part B (10 points) Identify the webs (of def-use chains) in the control flow graph by drawing a region for each variable and labeling each web S 1 , S 2 , etc.
def c
use c
def b
def f
use b
use f
def g
use g
Part C (5 points) Draw the interference graph using the nodes to represent the webs identified in part B.
Part D (4 points) What is the minimum number of registers needed to cover all the variables in this code? Show work for maximum credit.
4 Registers
Part E (3 points) Which of the variables would you choose to spill to memory (i.e., don’t assign a register to it, but instead store it in memory)? Briefly explain why.
Spill variable b because it interferes with the most variables.
Part F (3 points) If you spill the variable you chose in part E, what is the minimum number of registers needed to cover the rest of the variables? Show work for maximum credit.
3 Registers
Below is a snapshot of heap storage. Values that are pointers are denoted with a “$”. The heap pointer is $6168. The heap has been allocated contiguously beginning at $6000, with no gaps between objects. addr value addr value addr value addr value addr value addr value 6000 16 6032 12 6064 0 6096 16 6128 12 6160 0 6004 33 6036 28 6068 4 6100 $6080 6132 8000 6164 0 6008 $6036 6040 24 6072 $6148 6104 16 6136 2525 6168 0 6012 16 6044 $6036 6076 8 6108 5 6140 0 6172 0 6016 3 6048 16 6080 $6072 6112 $6004 6144 20 6176 0 6020 8 6052 6 6084 0 6116 8 6148 $6072 6180 0 6024 25 6056 $6120 6088 4 6120 $6132 6152 8 6184 0 6028 52 6060 0 6092 $6052 6124 24 6156 26 6188 0
Part A (8 points) Suppose the stack holds a local variable whose value is the memory address $6100. No registers or static variables currently hold heap memory addresses. List the addresses of all objects in the heap that are not garbage.
Addresses of Non-Garbage Objects : 6100, 6080, 6072, 6148, 6004, 6036
Part B (8 points) Create a free list by scanning the memory for garbage, starting at address $6000 and pushing each reclaimed object on the front of the free list. List the addresses of the objects (in order) on the free list at the end of the scan.
Free List : 6132, 6120, 6092, 6052, 6024 (in that order)
Part C (3 points) Based on the free list created in part B, if an object of size 3 bytes is allocated, what address will be returned using a first-fit allocation strategy?
Address : 6132
Part D (3 points) Based on the free list created in part B, if an object of size 18 bytes is allocated, what address will be returned using a first-fit allocation strategy?
Address : 6172
Part E (8 points) If the local variable whose value is the address $6100 is popped from the stack, which addresses will be reclaimed by each of the following strategies? If none, write “none.” (You do not have to list addresses already on the free list from part B.)