

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


(a) How can compiler transformations improve a pro- gram? (b) What does the compiler need to consider when ap- plying optimizations? (c) What are the different scopes of compiler optimiza- tions? What are the tradeoffs when considering what scope of optimizations to use?
Consider the following code.
(1) a := 1 (2) b := f + a (3) c := a (4) d := f + a (5) e := f + c (6) f := b (7) g := f + a
(a) Build a DAG for the code.
For the following problems, consider this code:
(a) What are the basic blocks? (b) What is the control flow graph? (c) Depth-first order selects nodes in the order they are visited (start by visiting the root node) and then recursively visiting every child of each node (if the child has not been visited before). Note that the order in which children are visited is random. What are all the possible results of depth-first traver- sal on the control flow graph?
(d) Using depth-first order, is it possible to visit a child before its parent? For which depth-first ordering(s) of the control flow graph does this occur? (e) Postorder selects nodes (starting from root) after visiting every child of that node (if the child has not been visited before). Note that the order in which children are visited is random. What are all the possible results of Postorder traver- sal for the control flow graph? (f) Reverse Postorder simply reverses the node order- ing found by a Postorder traversal of the graph. What are the possible Reverse Postorder traver- sals of the control flow graph? (g) Using Reverse Postorder, is it possible to visit a child before its parent? Why or why not?
(a) What is the dataflow equation for RD? (b) In what direction is RD calculated? I.e., does in- formation flow forwards or backwards in the CFG? (c) Calculate GEN, KILL for each basic block. (d) What is a good initial value for RD for each basic block? (e) Solve the data-flow equations in reverse Postorder. Show your work.
(a) We define LV(b) for a basic block b to be the set of live variables at the end of b. What is the dataflow equation for LV? (b) In what direction is LV calculated? I.e., does in- formation flow forwards or backwards in the CFG? (c) Show GEN, KILL for each basic block. (d) What is a good initial value for LV for each basic block? (e) Solve the data-flow equations in rPostorder. Show your work.
Available expressions is a data-flow analysis problem whose solution is used to guide global common subex- pression. It calculates AVAIL, the expressions available at the beginning of each basic block. Consider the following code. Assume that b+c is the only expression of interest:
B
B
B2 B
a := b+c
d := b+c (^) b := 2e := b+c
(a) What is the data-flow equation for AVAIL? (b) Give GEN and KILL (needed by AVAIL) for each basic block. (c) What is a good initial value for AVAIL for each basic block? (d) Calculate AVAIL. Show all steps, including values for AVAIL and the order basic blocks are analyzed.
Prove the following properties of lattices:
(a) Show that a ≤ b and b ≤ c implies a ≤ c
(b) Show that a ≤ (b ∧ c) implies a ≤ b
(a) When estimating each of the following sets, tell whether too-large or too-small estimates are con- servative. Explain your answer in terms of the in- tended use of information. i. Available expressions ii. Reaching definitions iii. Live variables (b) What properties are necessary to ensure an itera- tive data-flow analysis framework terminates? (c) What properties are necessary to ensure an itera- tive data-flow analysis framework terminates with the meet-over-all-paths solution?