Docsity

ECE 3035 Final Exam Solutions - Computing Mechanisms (Fall 2006), Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035 12:00pm Computing Mechanisms Fall 2006
5 problems, 8 pages Final Exam Solutions 15 December 2006
1
Problem 1 (6 parts, 30 points) Register Allocation
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 S1,
S2, etc.
F
T
def a
def b
use a
use b
use c
use b
def c
use c
def b
def f
use b
use f
def g
use g
def c
use c
def d
def a
use d
use a
s1
s3
s2
s4
s5
s6
s7
pf3
pf4
pf5

Partial preview of the text

Download ECE 3035 Final Exam Solutions - Computing Mechanisms (Fall 2006) and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

5 problems, 8 pages Final Exam Solutions 15 December 2006

Problem 1 (6 parts, 30 points) Register Allocation

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.

T^ F

def a

def b

use a

use b

use c

use b

def c

use c

def b

def f

use b

use f

def g

use g

def c

use c

def d

def a

use d

use a

s

s

s

s

s

s

s

5 problems, 8 pages Final Exam Solutions 15 December 2006

Part C (5 points) Draw the interference graph using the nodes to represent the webs identified in part B.

s

P

s

B s

G

s

R

s

R

s

R

s

R

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

5 problems, 8 pages Final Exam Solutions 15 December 2006

Problem 3 (1 part, 30 points) Hash Tables

Consider an open hash table composed of a four-bucket table, with each bucket containing a

variable length list. Each list entry has three slots <key, value, next> corresponding to the three

word groupings in the entries section. The hash function is key mod four. Inserted entries

are appended to the end of a bucket list. Deallocated entries are maintained on a LIFO free list.

When the free list is empty, new entry objects are allocated from heap memory. Accesses are

listed as <op, key, [value]>. Simulate the access list below and draw the ending state. Assume

the hash table is initially empty, the heap pointer is initially 5016 and the free pointer is initially

Heap

Pointer

5016 5066 Free

List

Buckets

Entries

Hash Table Access Trace

# op key value # op key value

1 insert 1003 111 5 remove 1001 n/a

2 insert 1001 222 6 remove 1007 n/a

3 insert 1007 333 7 insert 1000 555

4 insert 1019 444 8 insert 1003 666

5 problems, 8 pages Final Exam Solutions 15 December 2006

Problem 4 (5 parts, 30 points) Heap Management

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.)

Reference Counting: 6100, 6080, 6004

Mark and Sweep: 6100, 6080, 6004, 6072, 6148, 6036

Old-New Space (copying): 6100, 6080, 6004, 6072, 6148, 6036