Show the flow graph for the basic block code overlay.
Note that the only block following an unconditional goto is the target of the goto.
Blocks ending in a conditional goto are followed by both the target of a conditional goto and the block following.
Branches do not distinguish between conditional and unconditional branches.
Terminology
Block B is a predecessor of block C if there is an edge that flows from B to C.
B pred C
If B is the predecessor of C then C is a successor of B. C succ B
In the diagram, we can reach B4 from B2 but B2 is not a predecessor of B4 since there is no edge between the two.
Node B dominates node C if we must pass through B to get to C when starting at the beginning of the graph. B is an immediate dominator of node C if it is the last dominator we pass through before reaching C. Go through flow diagram to get the dominance.
Finding loops by finding back edges - an edge of the flow diagram whose head dominates its tail. B10 -> B2 and B7 -> B4 are back edges.
Data-Flow Equations
To optimize globally must keep track of the movement of information between basic blocks.
Example of the problem
j := j+1 in Block B7 where did the j come from?
Initialized in B3 not changed before B7 .
Things considered in data-flow analysis
What happens to variables and expression values within a block(used? or updated?)
How variables or values reach the beginning of a block.
Where they go from the end of a block.
Four forms of flow analysis
Forward
Backward
Any path to or from a block
All paths to and from a block
Day 2
Forward-Flow Analysis
An expression is available at a point p, it its value has been computed some place before p.
What's available coming into a block?
ina(Bi) = intersection of outa(Bj) where Bj pred Bi
Within a block an expression is killed if any of its operands are changed.
An expression is generated in a block if its value is computed and not killed in the block.
outa(Bi) = gen[Bi] »(ina(Bi) - kill(Bi)
ina(B1) = { }
Use-definition (ud-) chaining. The ud-chain for any use of a variable is the list of all definitions in a program that reach that use. (union of the outs from predecessor blocks.
Backward-Flow Analysis (use intersection and union of successor.