Do Exercise 2.4 on page 133, defining a modification of live variable analysis: Strongly Live Variable Analysis (SLVA). SLVA requires that you initialize the set of strongly live variables at the end of the program. When we implement SLVA in Homework #6, we will use the program output variables for this purpose. For this Homework, assume the existence of a special ``return'' variable r to initialize the SLVA set. In all places other than the end of the program/statement, r should be treated the same as any other variable.
Here are some examples of SLVA:
r is strongly live before the assignment.
z and a are all
to faint variables.
b is strongly live until the loop is done; a is faint
everywhere and r is strongly live after its first assignment.
Here's how you should do Exercise 2.4:
The book's Live Variable Analysis (p. 47-50) requires isolated exits.
In Homework #3, several students initialized reaching definitions with the empty set (rather than with the set ). Then whenever a use of a variable was found without any reaching definition, the definition was inferred. So, for example in the following code
y = 1; x = y + zThe analysis would infer a reaching definition of for the use of z. This result is correct. Nevertheless, this approach does not work in general:
Several students, when implementing reaching definitions analysis, did not iterate to a fixed point and instead just ran the loop twice. The textbook does say that GEN-KILL analyses only require the loop to be analyzed twice, but there are some pitfalls which is why it was required to do fixed-point iteration.
Implement two additional worklists that make use of reverse postorder ordering:
Within each SCC, the nodes are processed round-robin: in order from the first to the last in reverse post-order. Then, if any nodes in this SCC were ``added'', the SCC is processed again (all nodes in RPO). The ``add'' method doesn't actually add the node to some data structure. It merely means we will need to process the SCC again.
Once all the SCCs are processed and the last time the last SCC was processed, ``add'' was never called, then (and only then) the worklist's ``hasNext'' method should return false.
As with all homeworks, please turn in your homework on paper at the beginning of lecture.