Docsity

CS415 Assignment 7: Local and Global Optimizations, Assignments of Programming Languages

Toggle sidebar
bg1
CS415 — Written Assignment 7
2007-04-01
This assignment asks you to prepare written answers to questions on local and
global optimizations. Each of the questions has a short answer. You may discuss this
assignment with other students and work on the problems together. However, your
write-up should be your own individual work.
Please print your name and email address on your homework!
We need this information so that we can give you credit for the assignment and so that
we can return it to you.
1. Consider the rules for the constant propagation algorithm discussed in class:
(1) Cin(x, s) = # ⇒Cout(x, s) = #
(2) Cin(x, x ←c)⇒Cout(x, x ←c) = c(cis a constant)
(3) Cout(x, x ←f(. . .)) = ∗
(4) E(x)6=E(y)⇒Cout(x, y ←. . .) = Cin(x, y ←. . .)
(5) Cin(x, s) = lub{Cout (x, p)|pis a predecessor of s}
Note that these rules are not necessarily applied in order—the numbers are just
there for ease of referencing. See slide 38 in the ‘Dataflow Analysis, Global
Optimizations’ lecture notes for the actual steps of the algorithm.
(a) Give a concise English description for each of rules 1–4.
(b) Note that rules 1–4 define Cout in terms of Cin. Rule 5, on the other hand,
defines Cin based on the Cout values of all predecessor statements. Give
two distinct examples that show some set of predecessor Cout’s and the
resulting Cin computation.
(c) Briefly explain why the algorithm (as described in the lecture notes) is
guaranteed to terminate.
(d) Note that, in rule 4, we set y←. . . (where “. . .” is some expression e).
Why is it safe to assume that the evaluation of edoes not change the value
of x?
1
pf2

Partial preview of the text

Download CS415 Assignment 7: Local and Global Optimizations and more Assignments Programming Languages in PDF only on Docsity!

CS415 — Written Assignment 7

This assignment asks you to prepare written answers to questions on local and global optimizations. Each of the questions has a short answer. You may discuss this assignment with other students and work on the problems together. However, your write-up should be your own individual work.

Please print your name and email address on your homework!

We need this information so that we can give you credit for the assignment and so that we can return it to you.

  1. Consider the rules for the constant propagation algorithm discussed in class:

(1) Cin(x, s) = # ⇒ Cout(x, s) = # (2) Cin(x, x ← c) ⇒ Cout(x, x ← c) = c (c is a constant) (3) Cout(x, x ← f (.. .)) = ∗ (4) E(x) 6 = E(y) ⇒ Cout(x, y ←.. .) = Cin(x, y ←.. .) (5) Cin(x, s) = lub{Cout(x, p) | p is a predecessor of s}

Note that these rules are not necessarily applied in order—the numbers are just there for ease of referencing. See slide 38 in the ‘Dataflow Analysis, Global Optimizations’ lecture notes for the actual steps of the algorithm.

(a) Give a concise English description for each of rules 1–4. (b) Note that rules 1–4 define Cout in terms of Cin. Rule 5, on the other hand, defines Cin based on the Cout values of all predecessor statements. Give two distinct examples that show some set of predecessor Cout’s and the resulting Cin computation. (c) Briefly explain why the algorithm (as described in the lecture notes) is guaranteed to terminate. (d) Note that, in rule 4, we set y ←... (where “.. .” is some expression e). Why is it safe to assume that the evaluation of e does not change the value of x?

  1. Consider the following fragment of intermediate code:

START if a = 2 goto L L0: b := 2 L1: d := a / 2 c := a % b if c = 0 goto L if b >= d goto L b := b + 1 goto L L2: a := a + 1 goto L L3: END

(a) Divide this code into basic blocks; there should be at least 6. Assume that START and END are placeholder instructions (i.e. they don’t do anything). (b) Draw a control-flow graph for this program, using your answer to (a). Place each basic block in a single node. (c) Annotate your control-flow graph with the set of variables that are live before and after each statement. Assume that only a is live at the entry to L. (d) Describe concisely what this program does if the value of a is the only output.