






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!







Program analysis and optimization can be speeded up through the use of the dependence flow graph (DFG), a represen- tation of program dependences which generalizes def-use chains and static single assignment (SSA) form. In this pa- per, we give a simple graph-theoretic description of the DFG and show how the DFG for a program can be constructed in O E V time. We then show how forward and back- ward dataflow analyses can be performed efficiently on the DFG, using constant propagation and elimination of partial redundancies as examples. These analyses can be framed as solutions of dataflow equations in the DFG. Our construction algorithm is of independent interest because it can be used to construct a program’s control dependence graph in O E time and its SSA representation in O E V time, which are improvements over existing algorithms.
A number of recent papers have focused attention on the prob- lem of speeding up program optimization [FOW87, BMO90, CCF91, PBJ ^ 91, CFR ^ 91, DRZ92]. Most optimization al- gorithms are based on dataflow analysis. Classic examples are Kildall’s constant propagation algorithm [Kil73], and Morel and Renvoise’s algorithm for elimination of partial redundancies [MR79]. These algorithms are usually imple- mented using vectors of boolean, integer or real values to represent sets of assertions, such as x is 5 here, or y+z is available here. One vector is associated with each point in the control flow graph and initialized appropriately. Vector values are computed iteratively by propagating information
(^1) This research was supported by an NSF Presidential Young Investigator award CCR-8958543, NSF grant CCR-9008526, ONR grant N00014-93-1- 0103, and a grant from Hewlett-Packard Corporation.
(^0) *** To appear in ACM SIGPLAN’93 PLDI, June 1993 ***
from the inputs of statements to their outputs in the case of forward analysis, and from outputs to inputs in the case of backward analysis. The analysis terminates when all state- ments have a consistent set of input and output assertions. Although easy to implement, this approach has a number of disadvantages. Information is propagated throughout the control flow graph, not just to where it is needed for optimization. For example, in constant propagation it suffices to prop- agate information from definitions of variables to their uses. In common subexpression elimination, it is un- necessary to propagate availability of an expression to points where the variables of the expression are dead. When the vector at some point in the program is updated, the entire control flow graph below that point (or above it, in backward analysis) may be re-analyzed, even if there are few points in that region affected by the update. Many optimizations benefit from analysis performed in stages, but this is difficult to do in the standard approach. Consider redundancy elimination in the following pro- gram. To deduce that the computation of y is redun- dant, we must first deduce that the computation of w is redundant. This kind of analysis in stages is contrary to the standard approach, which considers all assertions simultaneously. ... z = a + b w = a + b ... x = z + 1 y = w + 1 ... Def-use chains provide a partial solution to these prob- lems. They permit information to flow directly between defi- nitions and uses without going through unrelated statements. However, def-use chains suffer from three drawbacks. First, def-use chains cannot be used for backward dataflow prob- lems, such as the elimination of redundant computations, because they do not incorporate sufficient information about the control structure of the program. Second, this lack of control flow information in def-use chains affects the preci- sion of analysis even in forward dataflow problems such as
constant propagation [WZ85, PBJ ^ 91]. Finally, the worst- case size of def-use chains is O E 2 V where E is the number of edges in the control flow graph and V is the number of variables [RT81]. The size problem can be overcome by using a “factored” representation of def-use chains called static single assign- ment (SSA) form, which has worst-case asymptotic size O E V [CFR ^ 89, CFR ^ 91]. However, SSA form cannot be used for backward dataflow problems. A generalization of the SSA approach, called the sparse data flow evaluation graph , has been proposed to address this problem, but sparse graphs take O N 3 time to construct, where N is the number of nodes in the control flow graph [CCF91, DRZ92]. In this paper, we show how these problems can be solved using the dependence flow graph (DFG), which can be viewed as a generalization of def-use chains and SSA form. The DFG was suggested to us by the work of Cartwright and Felleison who showed the advantages of an executable representation of program dependences [CF89]. We previously introduced the DFG using a dataflow machine style operational seman- tics [PBJ ^ 91, Bec92]. Dataflow machine graphs are also the basis of the program dependence web (PDW) of Ballance, McCabe and Ottenstein [BMO90], as well as the original SSA graphs due to Shapiro and Saint [SS70]. However, our experience in implementing and using a representation based on these ideas is that a full-blown dataflow graph representa- tion is neither necessary nor desirable. The main contribution of this paper is the distillation and incorporation of the essence of the dataflow graph represen- tation into a traditional optimizing compiler framework. We accomplish this as follows. In Section 2, we give a simple graph-theoretic charac- terization of dependence flow graphs. This characterization permits the exorcism of the dataflow execution model from the description of DFGs. It also brings out key connections between our work and prior work on representing control and data dependences. In Section 3, we describe how to construct DFGs. An important step in this construction is determining when two nodes in a control flow graph have the same control depen- dences. We describe how to do this in O E time. This algorithm is of independent interest since it can be used to build a program’s control dependence graph in O E time and its SSA representation in O E V time, which are im- provements over existing algorithms [CFS90, CFR ^ 89]. In Section 4, we show how to use the DFG in a forward dataflow problem: constant propagation with dead code elim- ination. This algorithm is faster than the standard control flow graph algorithm, yet it does as good a job of optimizing programs. In Section 5, we show how to solve a backward dataflow problem: anticipatability of expressions, which is an impor- tant step in the elimination of partial redundancies [MR79]. Finally, in Section 6, we describe what we have learned so far in our implementation.
We give a graph-theoretic characterization of def-use chains, static single assignment form, and the dependence flow graph. This characterization formalizes the relationship be- tween these program representations, permits the design of an efficient construction algorithm for DFGs, and aids in proving optimization algorithms correct.
Definition 1 A control flow graph (CFG) is a directed graph with distinguished nodes start and end such that all nodes are reachable from start and all nodes have a path to end_._ start is the only node with no predecessors, and end is the only node with no successors.
For convenience in describing algorithms that operate on CFGs, we introduce explicit switch and merge nodes to sepa- rate branching and merging of control flow from computation. A switch node is essentially a conditional jump that redirects control flow to one of multiple outgoing edges based on the value of an expression computed within the node. A merge node performs no computation but simply serves as the target of multiple control flow edges. An assignment statement node performs any general, non-branching computation. It is useful to extend the standard notions of dominance, postdominance and control dependence so that they apply to edges as well as to nodes in the CFG.
Definition 2 A node or edge x is said to dominate node or edge y in a directed graph if every path from start to y includes x_. A node or edge_ x is said to postdominate node or edge y in a directed graph if every path from y to end includes x_. A node or edge_ x is said to be control dependent on node n if x postdominates all edges on some path from n to x , but x does not postdominate n_. (Intuitively,_ n is a conditional branch that determines if control will pass through x .)
We begin by recalling the standard definition of def-use chains.
Definition 3 A definition of variable x is said to reach a use of x if there is a control flow path from the definition to the use that does not pass through any other definition of x_. A_ def-use chain for variable x is a node pair n 1 n 2 such that n 1 defines x , n 2 uses x , and the definition of x at n 1 reaches the use of x at n 2_._
For our purpose, it is convenient to recast this in terms of control flow edges rather than nodes.
of x reached by that definition. Conditions 3 and 4 ensure that the only definitions that reach e 2 are those that reach e 1 ; otherwise there would be -functions between e 1 and e 2 and there would be no SSA edge from e 1 directly to e 2. The worst-case size of the SSA representation is O E V . This solves the size problem of def-use chains, but the SSA form cannot be used directly in backward dataflow analysis problems.
Figure 1(c) shows the dependence flow graph for the running example. Unlike def-use chains, which go directly from definitions to uses, a DFG edge for a variable x can bypass a region of the control flow graph only if this region is a single- entry single-exit region that does not contain an assignment to x, since such a region has neither data nor control information that is of interest to program analysis. The following theorem defines single-entry single-exit regions formally, and states an important connection between control dependences and DFGs.
Theorem 1 The following are equivalent. e 1 and e 2 enclose a single-entry single-exit region. e 1 dominates e 2 , e 2 postdominates e 1 , and every cycle containing e 1 also contains e 2 and vice versa. e 1 and e 2 have the same control dependences.
For lack of space, we omit the proof of this theorem. A related structure called a hammock has been discussed in the literature [Kas75]. Hammocks are not the same as single- entry single-exit regions since the exit node in a hammock can be the target of edges outside the hammock; besides, the algorithm for finding hammocks is O E N . Just as def-use chains are “intercepted” by -functions in the SSA representation, they are intercepted by switch and merge operators in the DFG. DFG edges can be character- ized as follows:
Definition 6 A DFG edge for variable x corresponds to an edge pair e 1 e 2 such that
1. there exists a definition of x that reaches e 1 _,
Conditions 1 through 4 are the same as in the SSA rep- resentation. In the DFG, the merge operator plays the same role as -functions do in SSA form. Conditions 4 through 6 formally specify that the region of the control flow graph be- tween e 1 and e 2 must be a single-entry single-exit region. For example, in Figure 1(c) the region of the control flow graph
between the assignment to x and the use of x is a single-entry single-exit region containing no definition of x. Thus there is a dependence edge from the definition of x directly to the use of x. However, this region contains a definition of y, so dependence edges for y cannot bypass this region; they are intercepted by a switch operator at the conditional branch. In this way, dependences in the DFG are intercepted by merges and switches at merge points and branches respectively in the control flow graph.
We now describe the construction algorithm for depen- dence flow graphs. We first outline our algorithm for identi- fying single-entry single-exit regions and then show how this information is used to build the DFG.
Abstractly, decomposing a control flow graph into single- entry single-exit regions can be viewed as providing a “parse tree” of the control flow structure. In structured pro- grams, syntactic constructs such as if-then-else and while loops provide information for determining single- entry single-exit regions. For general control flow graphs, however, we need an efficient algorithm for discovering this information. Consider any two single-entry single-exit regions. It is easy to show that if they overlap, then either one is nested within the other, or the intersection is itself a single-entry single-exit region. If we only consider regions that are not formed by sequentially composing smaller regions, then we can show that single-entry single-exit regions are pairwise either nested, disjoint, or sequentially ordered. Thus these regions give a hierarchical decomposition of a control flow graph’s structure. For lack of space, we sketch our O E algorithm for find- ing single-entry single-exit regions. A longer paper giving the details of this algorithm can be obtained from the au- thors. Given a control flow graph, we want to find sets of edges having the same control dependences. Such edges are totally ordered, and each pair of consecutive edges are the entry/exit of a single-entry single-exit region. To find sets of edges having the same control dependences, note that we can insert a dummy node on each edge and then compute the property for nodes 3. We then reduce the problem to one of finding sets of cycle equivalent nodes in a related graph.
Definition 7 Control flow nodes a and b are said to be cycle equivalent if every cycle containing a also contains b and vice versa. (^3) Adding E nodes does not change the O E time complexity of our algorithm.
control flow dependence for x dependence for y
.. y ..
.. x ..
if x=
y := 2
x := 1
start
y := y+
.. y ..
.. x ..
if x=
start
x := 1
y := 2
y := y+
.. y ..
.. x ..
if x=
y := 2
x := 1
start
y := y+
(a) example CFG (b) base-level DFG (c) after region bypassing and dead edge removal
Figure 2: An Illustration of DFG Construction
Claim 1 Nodes a and b have the same control dependences if and only if a and b are cycle equivalent in the strongly connected component formed by adding the edge end start to the CFG.
The proof is straightforward using Theorem 1. Comput- ing cycle equivalence in directed graphs appears difficult, but we further reduce the problem to that of finding cycle equivalence in a related undirected graph.
Claim 2 Nodes a and b are cycle equivalent in a strongly connected component S if and only if the corresponding nodes a ^ and b ^ are cycle equivalent in the undirected graph G formed from S as follows: expand S into S ^ by splitting each node n into nodes ni n ^ and n (^) o such that inedges to n connect to n (^) i , out- edges from n originate from n (^) o , and there are directed edges ni n ^ and n ^ no_._ undirect all edges in S ^ to form G_._
Note that any cycle in S has a corresponding cycle in G, and although G contains cycles not in S , these cycles do not affect the cycle equivalence relation on nodes in G that correspond to nodes in S. Our algorithm for finding undi- rected cycle equivalence is based on depth-first search and runs in O E time; the details are omitted. In a companion paper, we show that this algorithm can be used to construct the factored control dependence graph of a program in O E time. A surprising aspect of this algorithm is that it does not
require the computation of the dominator or postdominator relations.
Suppose single-entry single-exit regions are discovered by the algorithm sketched above. The following steps outline the DFG construction algorithm and are illustrated in Fig- ures 2(b)-(c). In the example, each assignment statement is a single-entry single-exit region, as is the if-then-else construct.
start assignment multiedge switch merge
start
A V i
Vx
Vi x := e
A
B
V
1 2 k V V ... V
if (p)
A
B C Vt Vf
V Vp if (p)
C
A V1 B V
V