Practice with Interval Analysis
Interval Analysis Pass 1
Recall that the first pass of interval analysis works as follows:
- Divide the current CFG into intervals.
- If this is the original CFG, then annotate each edge
n→m with the GEN and NOT-KILL sets of node n.
Otherwise, each node n represents one interval from the
previous CFG. In that case, annotate each edge
n→m with the GEN(n, m) and NOT-KILL(n, m) sets that
were computed for the previous CFG.
- For each interval, use the GEN and NOT-Kill sets to compute
DEF and PRE sets for each node in the interval, and for each
edge whose source is in the interval. The DEF sets are the
sets of definitions that reach the node or reach the end of
the edge along an acyclic path from the interval head.
The PRE sets are the sets of definitions that are not
killed along those paths. Compute DEF and PRE sets by traversing
the nodes in interval order.
- Use the DEF and PRE sets to compute GEN(I, H), NOT-KILL(I, H),
and R(head(I)) for each interval I and each successor interval H.
Use the CFG shown below to practice solving the reaching definitions
problem using interval analysis.
First, fill in the following table with the initial GEN and NOT-KILL sets
for the CFG's edges (the sets for those edges' source nodes).
EDGE
| GEN
| NOT-KILL
|
1→2 | |
|
1→4 | |
|
2→3 | |
|
2→5 | |
|
3→5 | |
|
4→1 | |
|
5→6 | |
|
5→7 | |
|
6→5 | |
|
Now divide the CFG into intervals and
fill in the following table with the DEF and PRE sets for the CFG's nodes
and edges (working on one interval at a time, and visiting the nodes in
each interval in interval order).
Remember that the DEF and PRE sets represent the compositions of the
dataflow functions (their GEN and NOT-KILL sets)
on all acyclic paths from the interval header
to the start of the current node or the end of the current edge.
NODE OR EDGE
| DEF
| PRE
|
1 | |
|
1→2 | |
|
1→4 | |
|
2 | |
|
2→3 | |
|
2→5 | |
|
3 | |
|
3→5 | |
|
4 | |
|
4→1 | |
|
5 | |
|
5→6 | |
|
5→7 | |
|
6 | |
|
6→5 | |
|
Now compute the GEN, NOT-KILL, and R sets for the intervals.
When that's done, collapse each interval into a single node
to form the next CFG.
Label the edges of that CFG with the GEN and NOT-KILL sets
computed for the previous CFG's intervals.
Continue the example until you have a CFG with just one interval.
Compute the R set for that interval, and you're done with
Interval Analysis Pass 1!
Interval Analysis Pass 2
Interval Analysis Pass 2 computes "before"
sets for each node, and "after" sets for each edge,
in each CFG.
It starts with the CFG that has just one interval, the R set
for that interval, and the GEN and NOT-KILL sets on the CFG
edges.
The "before" set for the whole interval is the initial
dataflow fact (the empty set for Reaching Definitions).
The "before" set for the interval's head node is the "before"
set for the whole interval unioned
with the interval's R set.
The "before" and "after" sets for the other nodes and for the
edges are computed by visiting nodes in interval order, using the
GEN and NOT-KILL sets on the edges.
Once "before" and "after" sets have been computed for all nodes
and edges in the current CFG,
Pass 2 of Interval Analysis continues with the previous CFG.
Each interval in the previous CFG was a node in the current
CFG, so each whole interval's "before" set is the "before"
set of the corresponding node.
Complete the analysis of our example CFG by computing
"before" and "after" sets for each CFG in the (reverse) sequence.