



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!




1 Dataflow Analysis: A Review
Any operation we want a compiler to perform must of course be expressed formally. Very often, we will use the formal machinery of dataflow analysis. Dataflow analysis addresses the two main problems of consequence to compilers:
Actually, item 1 and item 2 are equivalent. By DeMorganās law, item 1 can be re-cast in the form of item 2 as follows: āP : C = ¬(āP : ¬C).
Control Flow Graphs The control flow graph is a directed graph wherein the nodes are either program statements or basic blocks and an edge A ā B exists if B can execute immediately after A. Special nodes S and E denote the start and exit points respectively. By convention, all CFGs include an edge S ā E although this edge is not always shown. It is generally simpler to let each node in the flowgraph be a single instruction, rather than a basic block. Using basic blocks has speed and memory advantages, but it isnāt worthwhile in a research compiler. Weāll assume each node is a single instruction.
Last weekās paper by Lam and Wall demonstrated the importance of control-dependence in parallelization. Ultimately, we need to define the control-dependence graph (CDG), but here weāll give only an informal explanation and then move on to do some other simple dataflow analysis problems before returning to the CDG problem in a later lecture. Intuitive definition of Control-dependence: Statement A is control-dependent on a branch B if the decision at B can affect the number of times A executes. In a block-structured programming language, each statement is control-dependent on its enclosing conditionals. For example, in Figure 1, statement 2 is dependent on statement 1, but neither 4, 6, 7, nor 8 are dependent on 1. In Figure 2, statements 1 and 2 are both control-dependent on the loop conditional 3, but E is not dependent on 3.
Each assignment statement creates a new definition of its left-hand-side. The reaching definitions analysis determines which definitions are visible to each statement in the program. Given an assignment statements A and another statement B, A reaches B iff there is a path from A to B where the left-hand-side of A is not overwritten. Using reaching definitions, one can build the def-use chains, which give information about how data is produced and consumed in the program. To perform the analysis, associate the sets gen(inst), pass(inst), and def s(inst) with each instruction in the CFG. For all assignment statements, let gen(inst) contain the current statement and let pass(inst) contain all assignment statements that do not define the same variable as the current statement. For all other statements, let gen(inst) be the empty set and let pass(inst) be the set of all assignment statements.
E
1
2 3
4
5
6 7
8
Figure 1: An acyclic flowgraph.
S
1
2
E
3
Figure 2: A flowgraph with a loop.
Given flowgraph nodes A and B, A dom B iff all paths from S to B flow through A. If we observe statement B execute in a program, we can say with certainty that A has executed at least once if A dom B. The dominator relation dom is a partial ordering of flowgraph nodes. In fact, that partial order is a tree called the ādominator treeā. Deriving the dominator tree is an intermediate step in many important transformations, including generating the control-dependence graph (CDG) and translating to single static assignment (SSA) form. Dominators find a simple application in detecting natural loops. An edge A ā B is a natural loop back edge iff B dom A. For example, Figure 5 contains a natural loop with back-edge 3 ā 1, while Figure 6 does not contain a natural loop (it results from unstructured code). The set of dominators dom(inst) for each instruction can be computed as follows. For each node except S, let dom(inst) initially be the set of all nodes. Let dom(S) = {S}. Iterate the following transfer function over each node until a fixed point is reached:
dom(inst) = 
iāpreds(inst)
doms(i) ⪠inst
Figure 4 shows a sample CFG where dges satisfying the natural loop edge criterion appear in bold. Table 2 shows the results of iterating the above equation to a fixed point (only one iteration). Again, more than one iteration will be necessary in the general case.
Node dom dom initial iter 1 S {S} {S} 1 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 } 2 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 2 } 3 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 } 4 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 } 5 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 , 5 } 6 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 , 6 } 7 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 , 7 } 8 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 , 7 , 8 } 9 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 , 7 , 9 } 10 {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 , 7 , 8 , 10 } E {S, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } {S, 1 , 3 , 4 , 7 , 9 , E}
Table 2: Propagating dominance sets through Figure 4 top-down.
2 Higher-Order Observations
(^1) This is open to debate, of course (^2) The Tao of Matt pp.207 (paraphrased)
Figure 4: A flowgraph with 5 natural loop back-edges (bold).