COP5621exam4 - A 145 Wed} COP5621 Compiler Construction...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A 145 Wed} COP5621 Compiler Construction Exam 4 — Spring 2007 Name: (Please print) Put the answers on these sheets. Use additional sheets when necessary. You can collect 100 points in total for this exam. 1. Which of the following optimizations is considered a peephole optimization? (mark one)(4 points) (a) Common-subexpression elimination (b) Code motion .___,..:; (c) Branch chaining a (d) Register assignment 2. Subroutine frames (activation records) manage a procedure’s local data. For a typical pro— gramming language implementation, Who deallocates the frame? (mark one)(4 points) V’é (a) Caller (b) Callee (c) Caller and callee (01) None of the above 3. List three local optimizations of your choice and describe What they optimize. (9 points) (I 5"“1’97‘ “fl't 752M»? (6”45174H 7L Ccmé/Ly/hfi S‘ffl/Zm/j 71A all/r c litre/1 ( 0m 474 t lady—J “9', aim/1 (gin/Vi M on 51/1 4’ “(ix/9 £6.91 1" £44 ’6 //‘W/ I “7“ Eflc We: 2‘: Iv] Key-"7 fp/é’u/I/I’ it; 4 "4 (CW’L 4. Consider the following program: program P() var p : integer; procedure Q(k : integer) begin R(k, p) end procedure R(i : integer, j : integer); var n : integer procedure T(i : integer) begin (* body of T *) end; procedure S() var m : integer begin T(n) end; begin S() end; begin Q(p) end (a) Program P calls Q, Q in turn calls R, R in turn calls S, and S in turn calls T. 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 T and how many access links must be traversed to reach the nonlocal data? (6 points) Var | visible (Y/Nu #lmks ' Y 0 5. Partition the following fragment of three—address code into basic blocks and construct the (DI?(}. (9 points) I.“ H H H d H ._. M p. II p. + H f := f * i if i<n goto L2 ‘IL- f -=o 6. Apply global constant propagation to the following CFG.(8 points) 7. Apply register allocation and assignment using graph coloring to the following CFG: x, y, t are not live Hint: Show the live ranges of the variables in the CFC}, assuming that x, y, and t are no longer live at the exit from the CFG. Draw the register—interference graph (conflict graph) for the variables and determine the minimum number of colors to color the graph. (12 points) f5 L S éde/P/i; X #7: k?!) 7 “MI E «9/5; F'—“>‘ 41 8. Consider the following CFG: (a) Draw the dominator tree of the CFG. (8 points) (b) Identify the natural loops. (5 points) (c) Is the CFG reducible? Explain why or Why not. (5 points) 1%; nodes r7 (4:) 9. Give the data—flow equations for reaching definitions (gen, kill, in and out sets) as described in the book and illustrated in class for the four programming constructs (assignment, statement composition, if—then—else, and do-while). (10 points) 5’26 (114/449? /o/c/ /u/ [6041“ mew/55’ // 7% N/ 10. Consider the following program: if n>0 then d1: 1 := 0; d2: f := 1; do d3: 1 := i + 1; d4: f := f * 1 while i < n; else d5: f := 0; end if Annotate the syntax tree of the program with in, gen, kill, and out bit-vectors: in: 00000 R gen: 00 i 1 i kill: 0 i 000 out= 00 in .. if /' in: 0 o 0 00 i 0, gen: 0 00 o; 5 kill: 0 , 0 {0 0L”: o 00 0 ( Ii n>O 7.x win: 00000 / gee/7:00 no l ; kill: // 00, out: o 0 ill? {Luf- in= 00000 gen: 10000 kill: 00100 I out: / 0 at) o e in: [000 e9 d gen: 0 /' 000 kill: 0001/ out: / Nico in: // 1/0 gen: (.3 0 ll 0 kill: 1 / 00/ out: 0 O [I D J x i l i , \l in: ill/ 0 //’ 3 gen: 00 [00 d4 gen: 000:0 kill: 1 0000 kill: 0 [new out: 0 {H0 .5? out: Do i/ 0 5”. “‘3‘in= 01/] C) ‘\ Hint: compute the gen and kill vectors bottom-up first, i.e. start at the leaves. Then compute the in, and out vectors in a top-down, left-to-right traversal. (in is inherited, while out is synthesized.) (10 points) ...
View Full Document

This document was uploaded on 12/04/2011.

Page1 / 8

COP5621exam4 - A 145 Wed} COP5621 Compiler Construction...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online