exam4-2005

exam4-2005 - COP5621 Exam 4 - Spring 2005 (Please print)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COP5621 Exam 4 - Spring 2005 (Please print) Name: 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) (2) (3) (4) (5) (6) static link access link state local live code motion (7) (8) (9) (10) (11) (12) stack pointer control link environment global dead 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 (d) The loop optimization called if it has no next use. moves loop-invariant statements to the loop header. refers to a function that maps a name (e) In programming language semantics, the term 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 3. Describe a typical calling sequence to invoke a function. (10 points) 4. Apply register allocation and assignment using graph coloring to the following CFG: a := read() b := read() if a>0 goto L1 a := 1 goto L2 L1: b := 1 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) 2 5. Consider the following CFG: 1 2 3 4 5 6 (a) Draw the dominator tree of the CFG. (10 points) (b) Identify the natural loops. (5 points) (c) Is the CFG reducible? Explain why or why not. (5 points) 3 6. (a) Organize the following fragment of three-address code into basic blocks and construct the CFG. (10 points) L0: L1: L2: L3: L4: i := 0 i := i+1 if i>m goto L2 n := n<<1 if n<k goto L1 k := k-1 if k<=0 goto L3 goto L0 goto 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) 4 7. 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 i j k n m visible (Y/N) 5 #links 8. (Bonus question). (a) Give the data-flow equations for reaching definitions as described in the book and illustrated in class for the four example programming constructs (assignment, statement composition, if-then-else, and do-while). (8 points) (b) Consider the following program: d1 : d2 : d3 : d4 : d5 : i := 0; do i := i + 1; n := n << 1 while i<m and n<k; if n<k then i := i - 1 else i := -1 Annotate the syntax tree of the above program with in, gen, kill, and out bit-vectors: in = 00000 gen = ; kill = out = d1 in = 00000 gen = 10000 kill = 01011 out = in = gen = ; kill = out = do in = gen = ; kill = out = d2 in = gen = kill = out = in = gen = kill = out = if i<m and n<k d3 n<k d4 in = gen = kill = out = in = gen = kill = out = d5 in = gen = kill = out = in = gen = kill = out = Note: compute the gen and kill vectors bottom-up first, i.e. start at the leaves. For example, gen=01000 and kill=10011 of d2 , because d2 kills all other definitions of variable i (i.e. d1 , d4 , and d5 ). Then, go up by applying the equations for reaching definitions. When the gen and kill sets are determined, compute the in and out vectors in a top-down, left-to-right traversal. (in is inherited, while out is synthesized.) (7 points) 6 ...
View Full Document

This note was uploaded on 02/01/2012 for the course COP 5621 taught by Professor Vanengelen during the Spring '11 term at FSU.

Ask a homework question - tutors are online