Docsity

COP5621 Exam 4 - Spring 2005: Program Optimization and Analysis - Prof. Robert A. Van Enge, Exams of Computer Science

Toggle sidebar
bg1
COP5621 Exam 4 - Spring 2005
Name: (Please print)
Put the answers on these sheets. Use additional sheets when necessary. Show how you derived
your answer when applicable (this is required for full credit and helpful for partial credit). You can
collect 100 points in total for this exam. A bonus question for an additional 15 points is included.
If the total number of points for this exam exceed 100, the excess points are carried over to the next
exams.
1. Match the terms below with the given sentences so as to best complete each sentence. Use
no term more than once. Some terms will go unused. (10 points)
(1) static link (7) stack pointer
(2) access link (8) control link
(3) state (9) environment
(4) local (10) global
(5) live (11) dead
(6) code motion (12) reduction in strength
(a) A transformation on a program is called if it can be performed by looking only at
the statements in a basic block rather than an entire region of code.
(b) An implementation of lexical scope for nested procedures is obtained by adding a pointer
called to each activation record.
(c) In liveness analysis, a variable is said to be if it has no next use.
(d) The loop optimization called moves loop-invariant statements to the loop header.
(e) In programming language semantics, the term refers to a function that maps a name
to a storage location (i.e. to an `-value) and the term refers to a function that maps
a storage location to the value held (i.e. to an r-value).
2. Name three peephole optimizations.(10 points)
1
pf3
pf4
pf5

Partial preview of the text

Download COP5621 Exam 4 - Spring 2005: Program Optimization and Analysis - Prof. Robert A. Van Enge and more Exams Computer Science in PDF only on Docsity!

COP5621 Exam 4 - Spring 2005

Name: (Please print)

Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full credit and helpful for partial credit). You can collect 100 points in total for this exam. A bonus question for an additional 15 points is included. If the total number of points for this exam exceed 100, the excess points are carried over to the next exams.

  1. Match the terms below with the given sentences so as to best complete each sentence. Use no term more than once. Some terms will go unused. (10 points)

(1) static link (7) stack pointer (2) access link (8) control link (3) state (9) environment (4) local (10) global (5) live (11) dead (6) code motion (12) reduction in strength

(a) A transformation on a program is called if it can be performed by looking only at the statements in a basic block rather than an entire region of code. (b) An implementation of lexical scope for nested procedures is obtained by adding a pointer called to each activation record. (c) In liveness analysis, a variable is said to be if it has no next use. (d) The loop optimization called moves loop-invariant statements to the loop header. (e) In programming language semantics, the term refers to a function that maps a name to a storage location (i.e. to an `-value) and the term refers to a function that maps a storage location to the value held (i.e. to an r-value).

  1. Name three peephole optimizations. (10 points)
  1. Describe a typical calling sequence to invoke a function. (10 points)
  2. Apply register allocation and assignment using graph coloring to the following CFG:

a := read() b := read() if a>0 goto L

L1: b := 1

a := 1 goto L

L2: c := a * b c := c + b

To determine a coloring, show the live ranges of the variables a, b, and c in the CFG, assuming that the variables are dead at the exit from the CFG Then draw the register-interference graph (conflict graph) for the variables and determine the minimum number of colors necessary to color the graph. (15 points)

  1. (a) Organize the following fragment of three-address code into basic blocks and construct the CFG. (10 points) L0: i := 0 L1: i := i+ if i>m goto L n := n<< if n<k goto L L2: k := k- if k<=0 goto L goto L L3: goto L L4: halt (b) Apply branch chaining optimization followed by dead-code elimination. After these optimizations, draw the modified CFG with its three-address code. (10 points)
  1. Consider the following program:

program P(input, output) var n : integer; procedure Q(k : integer) procedure S(i : integer) begin ... (* body of S *) end; begin S(k) end procedure R(j : integer); var m : integer begin Q(n + m) end; begin R(n) end

(a) Program P calls R, R in turn calls Q, and Q in turn calls S. Draw the resulting stack layout with activation records. Show the arguments and local variables in each record and draw the access links. (10 points)

(b) Which variables are visible (in scope) in the body of S and how many access links must be traversed to reach the nonlocal data? (5 points) Var visible (Y/N) #links i j k n m