编程代写|PLT-4115 Final Review

本次美国作业是一个编程语言相关的编程代写限时测试

Q1. Consider the basic block:

y := 3
x := y
z := 4 * x

Now consider the local optimizations:

– constant propagation
– copy propagation,
– constant folding.

– For this example, what is the best order in which to apply the three
optimizations, if each can be applied only once?

Q2. Consider the basic block:

y := 3
x := y
z := 4 * x

Now consider the local optimizations:

– constant propagation
– copy propagation,
– constant folding.

– For this example, What is the worst possible order (i.e., requires
the most passes) for the basic block?

Q3. Consider the following intermediate code:

1. x := 5
2. if y >1 goto Label3
3. Label1:
4. w := w + 1
5. if y > 2 goto Label3
6. Label2:
7. q := 3
8. if z < 1 goto Label1
9. Label3:
10.w := 2
11.if z > 1 goto Label2
12. q := y + w

a. Draw the CFG where each node is a BB.

b. Which variables are live immediately
before the execution of statement 7?
Assume only variable q is live after the
statement in line 12.

Q3. Consider the following intermediate code:

1. x := 5
2. if y >1 goto Label3
3. Label1:
4. w := w + 1
5. if y > 2 goto Label3
6. Label2:
7. q := 3
8. if z < 1 goto Label1
9. Label3:
10.w := 2
11.if z > 1 goto Label2
12.12: q := y + w

c. Assume the constant propagation algorithm has
completed. Which of the following statements is true?
– L_N is the statement at line N
– C(L,v,in) = C means that at the “in” of statement L
variable v is some constant
– C(L,v,in) = ⊤ means v is not a constant.