You are on page 1of 40

Efficiently Computing Static Single Assignment Form and the Control Dependence Graph


In optimizing compilers, data structure choices directly influence the power and efficiency of practical program optimization. A poor choice of data structure can inhibit optimization or slow compilation to the point that advanced optimization features become undesirable. Recently, static single assignment form and the control dependence graph have been proposed to represent data flow and control flow propertiee of programs. Each of these previously unrelated techniques lends efficiency and power to a useful class of program optimization. Although both of these structures are attractive, the difficulty of their construction and their potential size have discouraged their use. We present new algorithms that efficiently compute these data structures for arbitrary control flow graphs. The algorithms use dominance frontiers, a new concept that may have other applications. We also give analytical and experimental evidence that all of these data structures are usually linear in the size of the original program. This paper thus presents strong evidence that these structures can be of practical use in optimization. Categories and Subject Descriptors: D .3.3 [Programming Languages]: Language Constructs—control structures; data types and structures; procedures, functions and subroutines; Languages]: Processors—compilers; optimization; I. 1.2 [Algebraic D.3.4 [Programming Intelligence]: Automatic Manipulation]: Algorithms—analysis of algorithms; 1.2.2 [Artificial Programming-program transformation

A preliminary version of this paper, “An Efficient Method of Computing Static Single Assignment Form, ” appeared in the conference Record of the 16th ACM Symposium on principles of Programming Languages (Jan. 1989). F. K. Zadeck’s work on this paper was partially supported by the IBM Corporation, the office of Naval Research, and the Defense Advanced Research Projects Agency under contract NOCIO14-83K-0146 and ARPA order 6320, Amendment 1. Authors’ ac!drwses: R. i3yiru:I, J. Ferrante, and M. N. Wegman, Computer Sciences Department, IBM Research Division, P. O. Box 704, Yorktown Heights, NY 10598; B. K. Rosen, Mathematical Sciences Department, IBM Research Division, P. O. Box 218, Yorktown Heights, NY 10598; F. K. Zadeck, Computer Science Department, P.O. Box 1910, Brown University, Providence, RI 02912. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. @ 1991 ACM 0164-0925/91/1000-0451 $01.50
ACM Transact~ons on Programmmg Languages and Systems, VO1 13, NO 4, October, le91, Pages 451.490



Ron Cytron et al.
Languages Control dependence, control flow graph, clef-use chain,

Terms: Algorithms,

Additional dominator,

Key Words and Phrases: optimizing compilers

1. INTRODUCTION In optimizing and efficiency structure can advanced compilers, data structure choices directly influence the power of practical program optimization. A inhibit optimization or slow compilation features become undesirable. poor choice of data to the point where static single



assignment (SSA) form [5, 431 and the control dependence graph [241 have been proposed to represent data flow and control flow properties of programs. Each of these previously unrelated techniques lends efficiency and power to a useful class of program optimizations. Although both of these structures are attractive, the difficulty of their construction and their potential size have discouraged their use [4]. We present new algorithms that efficiently compute these data structures for arbitrary control flow graphs. The algorithms use
dominance frontiers,

a new


that linear


have that that




also give analytical the dominance This paper dependence Figure thus

and experimental is usually strong role presents the

evidence evidence

the sum of the sizes of all program. and control SSA form The


in the size of the original

can be of practical 1 illustrates

use in optimization. of SSA form in a compiler. intermediate

code is put into SSA form, optimized in various ways, and then translated back out of SSA form. Optimizations that can benefit from using SSA form include code motion [221 and elimination of partial redundancies [431, as well as the constant propagation discussed later in this section. Variants of SSA form have been used for detecting program equivalence [5, 521 and for increasing parallelism in imperative programs [211. The representation of simple data flow information (clef-use chains) may be made more compact through SSA form. If a variable has D definitions and U uses, then there can be D x U clef-use chains. When similar information is encoded in SSA form, there can be at most E def-use chains, where E is the number of edges in the control flow graph [40]. Moreover, the clef-use information encoded in SSA form can be updated easily when optimizations are applied. This is important for a constant propagation algorithm that deletes branches to code proven at compile time to be unexecutable [50]. Specifically, the def-use program information text that is just use that a list, for each variable, of the places in the variable. Every use of V is indeed a use of the to begin with straight-line

value provided by the (unique) assignment to V. To see the intuition behind SSA form, it is helpful

code. Each assignment to a variable is given a unique name (shown as a subscript in Figure 2), and all of the uses reached by that assignment are renamed to match the assignment’s new name. Most programs, however, have branch and join nodes. At the join nodes, we In Figure 3, the add a special form of assignment called a @-function.
ACM TransactIons on Programming Languages and Systems, Vol. 13, No, 4, October 1991

Static Single Assignment Form and the Control Dependence Graph
Orlgmal Intermediate Code Opt Imlzed Intermediate Code





Fig, 1. Vertical arrows represent arrows represent optimizations, translation to/from


form, Horizontal

static single assignment


VI-4 + V2*6 +-- V2 +7
Straight-line code and its single assignment version.

+-V+5 V+-6 --V+7
Fig. 2.




P then else V V +4 6 times. Fig.3. */ if-then-else anditssingle


P then else VI V2 + + 4 6 tines. */

v~ e- q5(vf, /* IJse V several
/* Use


V~ several version.


operands point. replaced just

to the by new

@-function variables to Vi.



assignments and is only each

to V reach old variable

thle join V is thus by

Subsequent one assignment

uses of V become Indeed,

uses of V3. The

Vl, Vz, V3, ..., there

use of Vi

is reached

one assignment

to Vi in the

entire program. This simplifies the record keeping An especially clear example is constant propagation the next subsection sketches this application. 1.1 Constant Propagation elaborate version of Figure true

for several optirnizations. based on SSA form [501;


4 is a more

3. The else branch to this use of Q tells

includes a compiler


test of Q, and propagating

the constant

that the else branch never falls through to the join point. If Q is the constant true, then all uses of V after the join point are really uses of the constant 4. Such possibilities is either can be taken into account without SSA form, but the processing costly [48] or difficult that to understand [49]. With SSA form, (i. e., never

the algorithm is fast and simple. Initially, the algorithm assumes

each edge is unexecutable

followed at run time) and that each variable is constant with an as-yet unknown value (denoted T). Worklists are initialized appropriately, and the assumptions are corrected until they stabilize. Suppose the algorithm finds that variable P is not constant (denoted _L) and, hence, that either branch of ACM
Transactions on Programming Languages and Systems, Vol. 13. No. 4, October 1991.

if then P


Ron Cytron et al
if P


V +-


then else return

do end



4 6 return

end else do end V3 . . . +V+5
Fig 4, Example ofconstant

V + if

6 Q then

do V2 if end + 4(V1,

Q then


. . . +- V3+S

the outer executable, processed,

conditional and the the

may betaken. statements about VI

The outedges they reach are is changed

of the test ofP processed. from When T to 4, and

are marked VI +4 all is uses of


VI are notified that they are uses of4. (Each use ofVl is indeed a use of this value, thanks to the single assignment property.) In particular, the @function combines 4with Vz. The second operand of the @function, however, isassociated uses with T for the inedge So long second the of thejoin as this operand, point that corresponds what to falling the asthrough algorithm the else branch. edge is considered no matter unexecutable, is currently

sumed about Vz. Combining 4 with T yields 4, so uses of V~ are still tentatively assumed to be uses of 4. Eventually, the assumption about Q may change from T to a known constant or to ~ . A change to either false or L would lead to the followed, and then discovery that the second the 6 at Vz combines with inedge of the join point can be the 4 at VI to yield L at V~. A

change to true would have no effect on the assumption at V3. Traditional constant propagation algorithms, on the other hand, would see that assignments of two different constants to V seem to “reach” all uses after the join point. They would thus decide The algorithm just sketched that V is not constant at these uses. is linear in the size of the SSA program it sees

[501, but this size might be nonlinear in the size of the original program. In particular, it would be safe but inefficient to place a +-function for every variable at every join point. This paper shows how to obtain SSA form efficiently. When ~-functions are placed possible but is unlikely in practice. The linear in essentially the size of the original linear in the SSA size. carefully, nonlinear behavior is still size of the SSA program is typically the time to do the work is




to Place

@-Functions placement might seem to require the enumeration of

At first



pairs of assignment statements for each variable. Checking whether there to V that reach a common point might seem to be are two assignments intrinsically nonlinear. In fact, however, it is enough to look at the domiof each node in the control flow graph. Leaving the technicalinance fi-ontier ties to later sections, we sketch the method here.
ACM Transactions on Programming Languages and Systems, Vol 13, No 4, October 1991

compares presents some conclusions. October 1991 . Then we show how to compute SSA form (Section Section 7 explains algorithms structures. CONTROL The basic statements blocks. along frontier of X and is no matter how many and no matter how Z not node on a path. No. 1. control may be able X. A control is a directed graph whose nodes are the basic blocks of a program jZow graph and two additional nodes. program optimization. This here. we can place ~-functions for V by finding the dominance frontier of every node that assigns to V. Suppose but Z is the may first such see V. any matter how far from to reach a node node strictly dominated X it may be. Section 8 shows that our are linear in the size of programs restricted to certain control We also give evidence of general linear behavior by reporting on Section 9 summarizes the algowith FORTRAN programs.3 Outline of the Rest of the Paper the representation of control flow by a directed graph. Then Z is said to be in the dominance clearly in need of a @-function for V. 13. our technique with other techniques. of dominance control frontiers dependence used for computing [20. program. In general. Basic blocks are indicated by the column of numbers in parentheses in Figure 5. FLOW GRAPHS are flow of a program where program organized enters into (not block necessarily at its first maximal) statement a basic and leaves the basic block at its last statement [1. to the any use of V will at entry program or a use of the value assignment to V. Let X be the will determine the value basic block Y. Indeed. experiments 5) and the control dependence graph (Section 6) efficiently. how to translate out of SSA form. then the dominance frontier of every node where a +-function has already been placed. There is an edge from Entry to ACM Transactions on Programming Languages and Systems. so that Z sees VI along one inedge another inedge. Our algorithm these variants. 24]. strictly dominated by by X will always see Vl. the branch SSA form identify can those to compute affecting statement execution. and rithms and time bounds. the code in see VI of V when along unaffected by V. 4. which Informally. 2. Entry and Exit. 36]. 455 in the original value V. no however. cause the statement to be of parallelism [2]. The same concept also be used conditions dependent statement skipped. Section 4 reviews the dominator tree dominance frontiers. on a branch if one edge from a statement is control definitely causes that to execute while another edge can Such information is vital for detection and program analysis [28]. assignments to V may appear in the original program complex the control flow may be. and so on. but all paths to Y must still go through dominate Y). Eventually.. so X control flows along any edge Y will X + 1{ to a and be X (in a [ways X + Y. section can be Section 2 reviews Section 3 explains SSA form and sketches how also considers variants of SSA form as defined adjusted concept to deal with and formalizes to construct it. When entered VI from the most recent execution of the basic block of code that assigns to V. If Y # X. Vol. then the code in Y will which case X is said to strictly see VI.Static Single Assignment Form and the Control Dependence Suppose so that that a variable V has just be either one assignment a use of the Graph .

to X. XJ) and a sequence of J edges sequence of J + 1 nodes (denoted (denoted e. CFG denotes control flow graph of the program under discussion. ) As is usual with occur several times. No 4.456 .. . . a path Xo. This assignment is treated just like the ones the that appear explicitly in the code. with 1991 J = O. one item eJ: X~_l ~ X~. . the representation also an edge from transfers of control node successor and there is an edge to For reasons related to in Section of control dependence and explained Entry to Exit. SZLCC( X) is the set of all successors of X. eJ) 1< j < J. . Vol 13. For Y with an edge X + Y in each node the graph. Exit from any basic block that can exit the program. each variable is considered to have an predecessor is a join assignment in Entry to represent whatever value the variable may have when the program is entered.K. (We write (node or edge) may such that e. The null path. A node node. for all j with sequences. of length J in CFG consists of a For any nonnegative integer J. is ACM Transactions on Programmmg Languages and Systems. Finally. KtK+2 J. with more than one successor is a branch similarly for predecessors. a node with more than one node. Throughout this paper. runs from XJ_. there is represent that each X. a and any basic block at which the program can be entered.. We assume is on a path from of X is any and on a path to Exit. The other (jumps) between the basic Entry node edges of the graph blocks. October . Ron Cytron et al. 1+1 J+ K+l L+-1 I (1) (1) (1) (1) if (P) then Jif repeat do I (Q) then else K-K+ end L L I t 2 3 (2) (2) (3) (3) (3) (4) (5) (6) (6) (7) (8) (9) (R) then L +L + 4 (S) else print repeat if until 1-1+6 until (T) (I. . L) (9) (10) (11) (12) (12) Fig 5 Simple pro~amand itscontrol @IEl--& flow graph 4 9 10 11 6.

already between other is assigned discussed. S. we still the but paths they p and -(j= q start Jork=K). R. STATIC SINGLE ASSIGNMENT FORM been expanded to an some expressions and This section intermediate initially assumes that programs have form in which each statement evaluates uses the results either to determine a branch or to assign to some variables.Static Single Assignment Form and the Control Dependence allowed.: XJ for an unrestricted path p. V and program (V). . No. XJ=Z=YK. join some nodes trivial in the o-functions program’s control flow is a two-step graph. ).) Intuitively. and uniform way to fold about the results of analysis the intermediate Practical concerns the size of the inte rmedi process.1 sketches (such is a tuple of expressions. Throughout an ordinary assignment this paper. # Yo. but X. and the jth operand of + is associated with the jth ACM Transactions on Programming Languages and Systems. 13. . The only novelty in our use of tuples is the fact that into they provide a simple text. In the examples tuples in expanding all tuples Section constructs is no need to distinguish use of longer as proce- dure calls) so as to make explicit the variables used and/or changed by the statements in the source program. . Translating a program into SSA form step. first of the new ate text are addressed in Section 3. (XJ=Y. at at the different end. 457 if X. but 3. an assignment or a @function. In V ~ @(V. node-disjoint.. .) An assignment statement A has the form LHS( A) . where a mention may be in a branch expression or on either side of an assignment may the be either result of statement. . are variables. .1. . . . The predecessors of X are listed in some arbitrary fixed order. X.) the same the and the right-hand length as the LHS value and the corresponding are l-tuples.1. . . .. (Other program constructs are considered in Section 3. S. The nodes and are (1) (2) (3) almost than come together the possibility use of or rather to be a cycle and in (3) is deliberate. is the number of control flow predecessors of X. Vol. . (for i = O.RHS( A). October 1991. The number of operands R. where V. Figure statement 6 displays translating a simple program to SSA form. . . 1. . ) are inserted at some variables V. 4. Nonnull if We write paths p: p: Graph p: . S. A +-function at entrance to a node X has the form V ~ +( R. A). need to consider One of the paths may happen of convergence. V. Z ~ Z.2. from there A) is a tuple RHS( Each RHS( A) target of distinct variable in target LHS( variables with A) (U. ) are generated. where the left-hand side LHS( side tuple. ~ XJ and q: YO ~ YK are said to converge at a node Z X. the second In the step. Each mention of a variable V in the program is replaced by a mention of one of the new variables V. “ XJ p is known to be nonnull. Such explicitness is a prerequisite for most optimization anyway. V. 3.

2 L +--.L~) print repeat (I.. predecessor. Ifcontrol supportl remembers @(R. L4) +K2+1 K4 +K2+2 #( J3. The value of of the jth operand. L6) +(R) then L8 -L7+4 @(L~. but which one depends on the flow of control just before entering X. the semantics of @ are only important when assessing the correctness of intermediate steps in a sequence of program transformations beginning and ending with code that has no +-functions. No 4. L) print(12. JI) l#J(K~. J2) @(K3.K~) 4(L9.11) J2 K2 L2 + +(P) then @(J4. L7) until 1+1+6 until (T) (S) until Fig. S. ACM Transactions on Programming Languages and Systems. Others [6. then the run-time the o-functions in X. J.3 K-K+ end else K+--K+2 I end else J4 K5 L6 + @(L3. L1) do J3 if (Q) then else L5 K3 L3 L4 t +2 3 12 if (P) then J+ if do I if (Q) then else L +-. For us.L~) J4. 13. K5. K4) ~(L2. there is no need actually to provide this support. Some variants of d-functions as defined here are useful for special purposes. repeat L7 if (R) then L+-L+4 if L9 + (S) @(L8.) qifunction is just uses only reaches Xfromits J“ while executing the value one ofthe jth predecessor. 521 have found it useful to give @ another parameter that incidentally encodes j..K.6 Simple program until 13-12+6 (T) anditsSSAform. under various restrictions on the control flow. 11. Any d-functions in X are executed before the ordinary statements in X.. 1-1 J+ Kti L+-1 repeat I 11-1 Jl +-1 Kl +-l L1tl repeat 12 #(13. October 1991 . For example. Vol. each @function can be tagged lWhen SSA form is used only as an intermediate form (Figure 1). Each execution of a operands.458 0 Ron Cytron et al.

For any variable V. then a trivial +-function V + q5(V. No.Static Single Assignment Form and the Control Dependence with the node X where it appears [5]. two paths assignments observe that A node Z needs a +-function for V if Z is a convergence nodes. they Thus.. 13. for V because a node Z is a convergence point for two nonnull paths X ~ Z and Y ~ Z that already containing assignments to V. (3) Along any control original program) Then V and to Vi have minimal Translation proviso that the number of @-functions inserted is as small as possible. Translation to SSA form replaces new program with the same control flow graph. V. V) has been inserted at Z (in the new program). This has been called pruned SSA form [16]. then the @function inserted at Z adds Z to the set of nodes that contain assignments to V. pruned SSA form can be obtained by a simple adjustment of our algorithm [16. and add unnecessary the optimization variant sometimes a @-function at a convergence more uses for V in or after any risk of losing Condition and it is sometimes However. If Z did start at nodes X and Y not already contain an assignment to V. consider and the corresponding the same value. (in the new program). 6. 11.1]. October 1991. . (2) Each mention of V in the original program or in an inserted +fulnction has been replaced by a mention of a new variable V. preferable to pruned form. Nonrecursively. 459 is flow of a language suitably restricted. . One form. so long +-functions overhead +-functions would as there can to only nre no to be lost. leaving the new program in SSA form. When desired. as Figure Z. . the nodes at which we should insert @-functions in the original program that to can be defined originate at V or needing Z needs recursively two different @-functions a @-function by Condition (1) in the definition point for containing we may of SSA form. form may be considered between two programs. With more nodes to consider as origins of paths. The algorithms in this paper apply variants SSA relation form as well. Vol. the following conditions are required of the new program: (1) If two nonnull paths X ~ Z and Y~ Z converge at a node Z. 4. flow path. . 52]. The @function could then be omitted without (3). is a target about to such as a property of a single program OY as a A single program is defined to be in SSA of exactly one assignment statement in the the original program by a For every original variable if each variable program text. However. both nodes for V. each @function can be tagged with information conditionals or loops [5. always of SSA point it is important extraneous to place form [52] Z. at all our convergence points. When the control Graph . subject to Condition (1) above. form is sometimes preferable to our placement 16 in Section 7 illustrates. SSA itself. we may observe more nodes appearing as convergence points of ACM Transactions on Programming Languages and Systems. . SSA form is translation to SSA form with the any use of a variable V (in the use of V. and nodes X and Y contain assignments to V (in the original program). Section 5. The optimizations that depend on SSA form are still valid if there are some extraneous +-functions beyond those that would cause where forego appear information they placing are in minimal process required.

taken value rather to awkward. Assigning a scalar value V to A(j) is equivalent to assigning an array value to the entire array A. Section 7. It will suffice to consider one-dimensional arrays here. paths Ron Cytron et al. October 1991 . where the new array value depends on the old one. Program found iterating presented Other the Constructs computes expressions using constants and scalar to (or source program variables to assign values to scalar variables. The entire array is treated like a single scalar variable. and some computations do not explicitly indicate which variables they use or change.1 Arrays. source programs commonly use other constructs as well: Some variables are not scalars. which may be one of the operands of Access or Update.O. in turn. 13. and reordering is then possible. even in typical cases 3This notation is similar to Select and Update [24]. For example. then it is straightforward derive an intermediate text that is ready to be put into SSA form otherwise analyzed and transformed by an optimizing compiler). Arrays of higher dimension involve more notation but no more concerns. This section sketches text how to map some important constructs to an explicit intermediate suitable for use in a compiler. 3. if allowed assignments program. of array references to SSA form removes some anti. The translation to SSA form is unconcerned with whether the values of variables As with scalars. After translation to SSA form. translation are large objects or what the operators mean. i) evaluates to the ith component of A. dependence analysis may prohibit reordering the use of A(i) by the first statement and the definition of A(j) by the second statement. However. If A and B are array variables. Vol.460 nonnull needing insertion in much 3. an will integer because by the source Many language. then array assignment statements like A + B or A +. 2 The less time. No. the two statements can execute concurrently. variable. 4. j. paths originating at @functions add nothing beyond the contributions from paths originating at ordinary assignments. of the for can be treated i. except for V as the value of the jth component. which not just may would change like be be the variables. ACM Transactions on Programming Languages and Systems. The straightforward iteration is still too slow. V) evaluates to an array value that is of the same size as A and has the same component values. the two references to A have been renamed. An easier approach is illustrated in Figure 7. The an the same set of nodes observation/ end results @functions cycle. be both to scalar however. as well as on the index j and on the new scalar value V. the expression Update(A. originating could algorithm at nodes thus with be assignments by here obtains to V.1 If . is similar to notation for referencing aggregate structures in a data flow language [23]. which. Where optimization does not reorder the two references.1.2 describes how transla - 2In typical cases. In the program in Figure 7a. 3 The expression Access(A. mentions A(i) may as of A in the a variable source be mentions an assignment of A(i) Treating some index or may to A(i) of A(j) and because the value of A(i) could be changed by assigning to i than to A(i).and output-dependences [32].

as an array. No. 32. Transformationto SSA form proceeds as usual (c). indirectly) terms the loop shown storage that would otherwise be necessary component to of in Figure 8a. 461 + A(i) A(j) + - V A(k) + 2 A t T - Access Access (A. If analysis or language semantics reveals a structure whose n fields are always accessed disjointly.w 1991. of A. the whole loop is like an assignment of the form ).). k) ++ + ACCeSS(A8. A simple solution to this formal problem is shown in Figure 8c. which assigns to every The value assigned to each component A(i) does not depend (even on any of the values previously assigned to components of A. Update(A8.k~~) -T+2 (a) (b) +T1+2 (c) Fig.1. 17) Llpdate(A. to elements of iIItO 3. 4. With or without SSA 8b makes A appear to be live at entry One reasonable accept it. which can sometimes accesses of A require the case for for each assignment problem scalars.Static Single Assignment Form and the Control Dependence Graph . Access of the structure. or for (like values execution can anyone code produced of the then some who by any other assignment uses Update results that as an be viewed of the is to communicate dead of dependence optimizations elimination) terms of “scalar” variables. Address response to the crudeness of the Update operator is to calculations and other genuine scalar calculations can still is to perform dependence analydetermine that no subsequent assignment to A(i) in initialization to make are usually arrays to A. 10. The actual code generated for an assignment from a HiddenUpdate expression is exactly the same as for an assignment from the corresponding the target Update expression. Another response sis [3. Dependence is translated an and a use of a structure field is translated into an In the prevalent case of simple structure field results in arrays whose elements are indexed by analysis can often determine independence i31111011g such accesses. j~. references. this treatment constants. Thus. the Update to the loop.. then the ACM Transactions on Programming Languages and Systems. 7. where the hidden operand is supplied by of the assignment. Such is Figure 8a. so that optimization may move an assignment to one field far from an assignment to another field. statement us. operator in of its A + (..2 Structures. V~) Access(A9. loolk analysis formulated The The like to in be optimized extensively. an assignment to a structure field Update of the structure. 51]. Vol. A structure can be generally regarded where references to structure fields are treated as references the array. that is not used before entering such should Figure be eliminated.. where the HiddenUpdate operator does not mention the assigned array operand. Octob. tion out of SSA form reclaims maintain distinct variables. where A is not used in (.. In effect on A. Consider array A.V) A9 T1 (A. i) j. Source code with array component references (a) is equivalent to code with explicit Access and Update operators that treat the array A just like a scalar (b). 13. . Any assignment to a component of A an initialization loop is dead code that form.

three types of references form: (1) (2) (3) MustMod(S) is the set of variables is the set of variables that that whose must translation into SSA be modified be modified prior by execution by execution to execution of of of S s. where all the variables on Programmmg Languages and Systems. The elements only for organizational in apparent SSA to form more of such reasons. iZ) until A2 13 until i > 100 (a) until -iz+i i3 > 100 (b) +-12+1 i3 > 100 (c) Fig. aliased we must account for implicit as well as explicit references. To obtain SSA form. 8. variables not mentioned by the statement itself. October . MayMod(S) may s. either by conservative assumptions or by analysis. 4. Heap storage can be conservatively modeled by representing the entire heap as a single variable that is both modified and used by any statement that may change the heap. construction used by a statement of SSA may form In or use knowing to those those variables variables explicitly modified a statement. but the conservative approach is already strong enough to support optimization of code that does not involve affect the heap but is interspersed with heap-dependent code. Using HiddenUpdate (c) is a purely formal way tosummarize some results of dependency analysis. A2) repeat i2 Al +-++- #(i~. Examples of such references are global variables modified or used by a procedure call. S by transformation to in MayMod(S) appear 1991 13. Ron Cytron et al. More refined modeling is also possible [15]. May Use(S) is the set of variables may be used by S.lz. 3. Source loop with array assignment (a) is equivalent to code with an Update operator that treats the array A just hke a scalar (b). if available. No.i~) f#(fio. For any statement S. Vol. and dereferenced pointer variables.1. i3) i2) ~(A0. structure structures and the the can be decomposed are united in the expression actual of the use into n distinct source program structure’s of the structure variables. variables.A2) HiddenUpdate(12. The and referenced. integer A(1:1OO) integer integer integer AO(I:lOO) A1(l:lOO) A2(I:IOO) integer integer integer il+--l repeat AO(I:lOO) A1(I:lOO) A2(1:100) i+l repeat il +--l i2 Al t + + ~(ii. makes decomposition program’s subsequent optimization. the eventual translation out of SSA form will leave just one array here. A(i) i+l+l t-- i A2 i3 update (Al.3 requires addition modify implicit Implicit References to Variables.462 . values We represent an assignment ACM Transactions implicit references for any statement statement A. As Section 72 explains.

15. When there Small often a sophisticated side analysis and technique the tuples directly.2) by replacing each mention of an original variable V by an appropriate mention of a new variable V. 4. The cal analyses of optimization techniques intuitive (with explanations and theoretior without SSA form) are compact representations conveniently formulated in terms of explicit can still be used in the implementations. 34]. A call might change any global variable by reference. see [7-9].2 introduces computation. the usual and analysis. Domination is both reflexive and transitive. are few tuples effects Many (both is applied. Both own transformations detailed aliasing.. If -X appears on every path from Entry to Y. compilers Consider a call to an external procedure that has not tuples for the call must contain all global variables. and [44].1 Dominator Trees the dominance frontier relation [47] between nodes in the control this relation in a dominator tree. it is customary sumptions. will be performed. mapping (2) Using the dominance frontiers. 33. for each (3) The variables are renamed (Section 5. Translation is done in three is constructed steps: from the contrcd flow (1) The dominance graph (Section frontier 4. been The on global Techniques parameter are available of procedures pointer ables. compilers do no interprocedural analysis analyzed. 4. X # Y. the extent to extract effects to make conservative asor any parameter passed variables that more local to the caller can variinformation: see [14. No. 4. is at all.2 Overview of the SSA Algorithm to minimal SSA form tuples. 3. DOMINANCE Section 4. [19]. 29. then X dominates Y. variable in the original program the locations of the @-functions are determined (Section 5. To determine but it is reasonable Such assumptions aliasing to assume limit and that not change. MustMod(S)) optimizing procedures of all If no or indirectly) or to summaries specific information is available. unavailable.1 reviews the dominance flow graph and how to summarize 4. LHS Sophisticated RHS) can be represented however. If X dominates Languages Y and and Systems.Static Single Assignment Form and the Control Dependence Graph in An LHS( A) and appear called all in compiler (directly the RHS( may variables A).2). to determine 27. then Vol. that few local (set to indicate The representation all globals that caln be a tuple are in the tuple) are in the variables because of parameter transmission. Section mapping and gives an algorithm for its Let X and Y be nodes in the control flow graph CFG of a program. or may not have access to the of their in May Use(S) u . 463 – ( ikfcz~illod(s) bodies effects. representation structure plus that a direct of the tuples includes a flag representation can still of the be compact. result are is that small. October . X strictly 1991 ACM Transactions on Programming 13.1). [37]. and [42].

For all practical purposes. Here. . and any node Y other than Entry has idom( Y) as its parent in the tree. the words parent.2.2) 9[-1 Exit. 13. 9 Control flow graph anddominator tree of the simple program Thesets ofnodes listed in ()and[] brackets summarize thedominance frontier calculation from Section 4. No 4. If X does dominator we write not X>> Y for strict is the domination Y. The of Y (denoted dominator of Y on any path from Entry to Y. p. The dominator tree of CFG has exactly the same set of nodes as CFG but a very different set of edges. 123]. the children of a node X are all immediately dominated by X.21Exit. N) = 2 when 16 < logz N < 216. October 1991 .2. descendant 4Under the definition of a ueed in analyzing the dominator tree algorithm [35.9] (’ E=’k w (Exit . strictly Y. ACM TransactIons on Programming Languages and Systems.I -] (-i 1 [.9] \ .2] I Fig. dominates for immediate Y. successor. The root of a dominator tree is Entry.464 . Let N and E be the numbers of nodes and edges in CFG._.]6] dominate Y)) idom( 6&\] (Exit.I -] I (Exit 2[-1 ) Exit..I Exit] Exit ‘(-) [. predecessor. N) = 1 when logz N < 16 and a(ll.2] (-l~xit2 3[-18] 7[8181 8[-1 Exi’t . and and path always always refer to CFG. The dominator tree for CFG from Figure 5 is shown in Figure 9. The dominator tree can be constructed in 0( Ea( E. N)) time [35] or (by a more difficult algorithm) in 0(E) time [26]. a( E. N) is a small constant.4 so this paper will consider the dominator tree to have been found in linear time.2) 12[Exit. The words refer to the dominator tree. Ron Cytron et al Entry [. Each node X is annotated with two sets [DFIOCaj (X) I DF’(X)] and a third set (DFUP(X)). N s E implies that a(17. In formulas.~2 10[111 11] li[91Exit:2. we write closest strict and X ~ X ~ Y domination. child. In a dominator tree. ancestor. Vol.2] (-) 4[616] P 5[.

DF(Z) frontier I idom(Z) ~ Y}. This then X Y e DFIOC. DFIOC~t(X) PRooF. X would the be quadratic. frontier we define dominance from the definition would require searching The total time to compute DF( X) for all nodes the sets themselves in time holds: U (J ZeChildren(X) even when mapping equation are small. hence. size Ex To compute I DF( X) I of linear in the the mapping. Because PROOF. 13. there such that X dominates and Z of X that strictly U but we are dominates dominate dcles not done. The dominance dominance equation (4) is correct. If U but Y. We assume that (X> Y ~ Succ( X) Y) and show that =X). DFIOC. is defined dominates to be a strict Y and. contribution DFIOC. 465 X is the set of all does not strictly CFG nodes Y such that a predecessor of Y but dominate Y)}. We must that everything in DF( X) has been accounted for. such that two intermediate sets DFIOC~l and DFUP for eaclh node the following DF(X) = DFIOC~l(X) DFUP(Z).Static Single Assignment Form and the Control Dependence 4. each child Z of X has DFUP(Z) G DF( X). . = {Y= SUCC(X) I idom(Y) # X}. strictly cannot implies The follows: LEMMA 2. intermediate sets because K can be computed with simple equality tests as For any node X. October 1991. No. some of the successors is defined of X may by contribute to DIF( X). The contribution DFUP(Z) that Z passes up to idom(Z) is defined by DFUP(Z)~f{Ye LEMMA 1. For the = part. on the other strictly dominate that Ye DFUP(Z). is transitive. If U = X. Suppose Y e let U ~ Y be an edge Y. dominance still show DF( X). Computing D1’( X) directly much of the dominator-tree. Because is reflexive. suppose that ACM Transactions on Programming dominator X strictly Languages and Systems. then Y hand. # (idom(Y) The = part is true because the immediate dominator.2 The Y: DF(X) = {Y[(~Pe Pred(Y))(X> Pand X? Dominance dominance Frontiers frontier X dominates DF( X) of a CFG node Graph . (4) Given This any local node X. some of the nodes in DF(Z) may contribute to DF( idom(Z)).Z( X).l( X) G DF( X). 4. is a child does not and dominate U # X. Vol.l( X) Given any node Z that is not the root Entry of the dominator tree.

so either V = Y. so V = Z and Z dominates Y. 4. hence. For any node X and DFUP(Z) = {Ye any child DF(Z) Z of X in the dominator # X}. We assume that (X> Y G DF(Z) Y)+ (idom(Y) The . To illustrate the dominator tree in Figure THEOREM PROOF. for Ron Cytron et al. then idom( Y) = idom( V ) = X. Choose a predecessor Y such that Z dominates U. Then V appears on any path from Entry V dominates that goes to U and then follows the edge U + Y. so path V = Y from and goes to = x. and uses it in (4) without needing to devote line is similar for DFUP( Z). October 1991 . The frontiers putes DFIOC./ id. We traverse the visiting each node X only after visiting each of its working of this algorithm. This the hypothesis results imply the given that Ye DF(Z). suppose is the transitive closure that X strictly dominates of Y U o!i to Y U or and. contradicts These dominance K algorithm /*local*/ for line computing effectively the com- correctness in Figure fly of the 10. that some child V of X dominates Y. each ~ each if end for each for if end end end Fig. The /*up*/ dominator tree bottom-up. one child of X can dominate U.Z( X) on the storage to it. The loop over Succ( X) in Figure examines each edge just once. that =X). because strict dominance For the + part. in Figure 10 is correct.part is true immediate dominance. X + Y. tree. that V dominates U) and derive a contradiction. children. Then then follows cannot V appears the edge dominate on any X. hence. Suppose V + Y (and. I idom(Y) and show PROOF. so either V = Y.466 . 13. Calculation of DF( X) for each CFG node X. 1. and we are done. Vol. K 10 are Let CFG have N nodes and E edges. we have annotated the 9 with the information [1 and () brackets. so all executions of the /*local*/ line ACM TransactIons on Programming Languages and Systems. Z each E Y Children(x) E LIF’(Z) # X do do then DF’(X) llF’(X) U {Y} in a bottom-up traversal do then llF(X) +IIF’(X) U {Y} of the dominator tree do DF(X) for + Y 0 E Succ(X) # X /*local. 10.m(Y) /*up*/ idorn(Y) that Entry V idom( some to Y) dominates child Y that X V of or X dominates X n and But V Y. = idom(v) LEMMA 3. The algorithm from Direct the preceding lemmas. If that Only V = Y. No.

line 467 are 8 We the O(size(DF)). then choose X’ = X to get all the claimed of X’. by the efficient worklist The actual computation of DF+ ( Y ) is performed algorithm iterated assignment in Section 5. DF. 4. No. the set J(Y) nodes is defined to be the set of all nodes Z such that there are two CFG paths that start at two distinct nodes in Y and converge at Z. if Y happens to be the set of assignment V. from nodes X) .) . then J+(Y) is the set of @function The join and iterated join operations extend natural the dominance way: frontier DF( As with increasing join.Static Single Assignment Form and the Control Dependence Graph complete complete which shows have standard 4. there is a node X’ e {X} U DF+ ({ X}) on p that dominates every node on p. . = J(YU J. For any nonnull path p: X ~ Z in CFG. some of the nodes 13. join J+ ( 5“ ) is the limit of the J(Y). the formulation dominance frontiers to iterated nodes for a variable V. If the set Y we will show that for relating is the set of J+(Y) =DF+(Y) (this equation depends on the fact that Entry is in Y) and. implemented to a worst-case this algorithm complexity size of the and have of 0( E + N2 ). Similarly. than amounts that. we just that unless X dominates on p. that it is faster in practice.+l In particular.3 in in time time 0(E). in DFf ({ X}). mapping observed is usually [21.1. DF+ ( Y ) is the limit to sets of nodes in the ~QJDF( frontier dominance of the sequence of sets of nodes DF1=DF(Y). then here is convenient joins. the iterated mapping S“ ) = nodes for V. a set Y of CFG nodes. the overall + size(DF)). The following lemmas do most of the work by relating dominance frontiers to joins: LEMMA 4. data-flow computations Frontiers formally in the PTRAN to Joins the nonrecursive Given Relating Dominance more We start of join nonnull The nodes by stating characterization of where the @-functions should be located. The all executions time of the is thus DF compiler /*up*/ O(E . the node X’ can be chosen PRooF. that the location of the @functions for V can be computed by the worklist algorithm for computing DF+ ( Y ) that is given in Section 5. ACM Transactions on Programming Vol. October 1991.). If X dominates properties every node Z.+l = DF(W DF. We may Languages assume and Systems. nodes for a variable We increasing sequence of sets of iterated J1= J. However. hence.1. Section linear. map sets of nodes to sets of nodes. Moreover.

Thus. with the sequence of XJ = Z. there are choices of ~“ with XJ e DF+ ({ X}). Then j < J. Z e DF’ ({ Y}). Two nodes cannot strictly dominate each other. 13. The predecessor Xh _ ~ is dominated by X’ and so puts X~ into DF( X’). X’ is on q and show that Z e DF+({ X}). and there is a first k with j < k s J such that X’ does not dominate Xh. Xh e DF( DF+ ({ X} )) = DF+ ({ X} ). and we continue inductively to show that X’ >> Y~ for all k. DF( Y ) G LEMMA 7. Then we show that the first two cases are (unobviously) exhaustive because the third case leads to a contradiction. We suppose that reasoning just as in Case 1.Y and any Ye DF( X). and q: Y$ Z in CFG converge p: X$ Z ~DF+({ DF+({ Y}). Thus. Xo. with the Y = YO. that D nonnull paths X}) U 5. In particular. YK = Z. We may now assume already of Z but that Z = X and X dominates every node on p. No. Let Y’ be from Lemma 4 for the path q. nodes. ACM Transactions on Programmmg Languages and Systems.468 on p . by similar reasoning from the supposition that Y >> Z but Y is not on p. Vol. LEMMA PROOF. . PROOF.. PROOF. We will show that X’ >> Z. are Ron Cytron et al not dominated by X. (3) in Section 2). q and Y is not on p. But X’ # YK_~.) Because X dominates the predecessor XJ_ ~ does not strictly dominate Y Z. On the other hand. contradicting LEMMA the choice and suppose at Z. Suppose not. . Lemma 4 asserts Z e DF+ ({ X}). The paths K therefore converge at Y. Then of j.. Z Let X + Y be two nodes in CFG. X’ >> YK_ ~. the predecessor X. 4. We suppose that definition of convergence (specifically.. we prove that Z e DF+ ({ X} ) U DF+ ({ Y} ). . For any set Y’ of CFG We apply Lemma 5. X’ >> Y’. There is a path from X to Y where all nodes before Y are dominated by X. Consider X’ = XJ for the largest j with XJ ~ DF+ ({ X}). dominates all predecessors of YK. By the Case 1. (Otherwise. In the first two cases. sequence of nodes X’ be from Lemma 4 for the path p. therefore. Case 2. we have is on p. 6._ ~ is dominated by X and so puts X. and that We derive a contradiction Case 3. . J(7) G DF’(J7 ). SO X’ >> Y&~. where Y is the set of nodes with assignments to V. The set of nodes that need ~-functions for any variable V is the iterated dominance frontier DF+ ( Y ). X’ = Z. There is also a path from Entry to Y where none of the nodes are dominated by X. We consider three cases that are obviously exhaustive. X’ X’ is not on >> YK = Z Z but and.. In particular. October 1991 . THEOREM 2.. Consider any Xc . Z c DF( X) show G DF+ ({ X}).. into DF’( X). . Because X’ from ~ the suppositions X’ is not that on q. . K nodes such that Entry e Y. Let nodes X= XO. XJ = Z. we can show that Y >> X’. For any set Y of CFG J(Y). so Case 3 is K impossible. For the smallest Let the sequence of nodes on p be X = i such that X does not dominate X. .

. counting assignments to variables is one of ACM Transactions on Programming Languages and Systems. array of flags. The outer loop of this Several data is performed are used: once for each variable V in the program. Vol. J+(Y)) need @-functions V is precisely J+(Y). J+(Y)) for =DF+(Y).~( x).. induction yield (6) 7 and another J+(Y). ments to DF( X) becomes — Work(*) indicates of CFG nodes being processed.) GJ(YU The set of nodes that prove the theorem.sAlready( of assigning V. No. is an of nodes that contain assignensures that each node Y in terminates each node. so (5) and (6) K OF MINIMAL SSA FORM 5. when the w orklist Work(X) iteration X) receives where whether loop. a @-function and for been inserted Work(X) the property a d-function Ha.Y)) The node Entry is in Y. 13.) GJ(SWDF+(Y)) GDF+(Y). SDF(J’W =J+(Y). 469 we can By Lemma 6 and induction on i in the definition of J+. . show that J+(Y) The induction step is as follows: Ji+l = J(YUJ.. for the current of the outer –HasAlready(*) indicates The flags because needing is an array whether one for each node. Each node X in the worklist a @function.~ (X) original each ordinary assignment statement LHS + RHS contributes the length of the tuple LHS to A o. The flags are independent.+l = DF(YUDF. (5) GDF+(!YUDF+(. In each iteration of this W is initialized to the set &(V) V.1 Using Dominance Frontiers to Find Where @-Functions Are Needed in Figure 11 inserts trivial @-functions. 4. The algorithm algorithm structures — W is the worklist algorithm. but this would to reset any true flags between iterations. where Let each node X have AO. is independent have We need two flags of the property with of just been implemented the values true and false.ber 1991. Each one iteration flag for empty.Static Single Assignment Form and the Control Dependence Graph PROOF. CONSTRUCTION 5. assignments to variables. so Lemma DF+(Y)G The induction step is as follows: DF. It is simpler to devote an integer to each flag and to test flags by comparing them with the current iteration count. Octc. X has ever been added to W during of flags. where V has already X) to V could HasAlready( at X. require additional record keeping without the expense of looping over all the nodes. .

several measures of program size. The 0(N) cost of 5The various measures relevant summarized in Section 9 1. = XX AtO.g(x) function placed at X contributes 1 to A.~(X) to size A. so there is an O(EX M*( X)) contribution to the running time from the work done when HasAlready( Y) < IterCount.~ = XX AO. at X Placing a ~-function at Y in Figure 11 has cost linear in the indegree of Y.470 . 4.T) < do IterCount V)) HasAlready(Y) place if (F’ @(V. .. Replacing mentions of variables will contribute at least 0( M~Ot) to the running time of any SSA translation algorithm. so the cost of placement can be ignored in analyzing the contribution of Figure 11 to the 0(. from Xx M~. where = A o.. = Xx Mto.g( X) to Mto. IterCount for each Work(X) end W’+o for each IterCount variable +V do --I 1 do + node O X do + 0 O HasAlready(X) IterCount for each X Work(X) ~ +- d(V) {x} IterCount W+wu end while take for if W X each then # @ do from Y W & do DF’(. ACM TransactIons on Programming here are reviewed when the whole SSA translation process is Languages and Systems. of X to MtOt( X) = MOrLg( X) + M+(X)... 13..O. October 1991 .( expands each @There Morlg is = contributes 1 plus the indegree where each @-function placed X). Placement +w IterCount IterCount +IterCount u {Y} of ~-functions. No. ) bound for the whole process. Ron Cytron et al.. a similar expansion in the number of mentions of variables. Vol..( X). + < at Y HasAlready(Y) Work(Y) then do Work(Y) Jv end end end end end Fig.(X) + A+(X). the program from size AO.. 5 By this measure... 11.

how many – WhichPred( X. In contrast with Figure 11. The jth of Y from —Each X. These tuples target tuple notation. Figure SEAFtCH that for at may only associated V.O. for each V. The contribution time of the whole process is therefore O(ZX( the output in the natural way where x as A tot. To minimize but the original branch is treated as an ordinary assignment to a special variable whose value indicates which edge the branch should follow. 5. The stacks can the value is used to construct countelc variable replace assignments a use of V. What W. A). 13. Vi that tells is an array of stacks. Y) is an integer telling which predecessor of Y in CFG is operand of a +-function in Y corresponds to the jth predecessor the listing of the inedges of Y. and Figure is effectively 0( A tOt). is effectively 0( AO. ACM Transactions on Programmmg Languages and Systems.Static Single Assignment Form and the Control Dependence initialization the dominance managing the performed because running Sizing can be similarly frontier worklist ignored because Graph . tree by calling the any statements @-functions requires work New variables V. This. A real implementation would recognize that a conditional branch involves a little less work The LHS part of the processing can be than a genuine assignment: omitted. 471 cost of it is subsumed by the calculation. all Ye DF( X) are polled. aurgDF~f (~ (A. we can contribution as 0( A ~Otx aurgDF). a conditional assignment where the right-hand side RHS( A) is a tuple left-hand side LHS( A) is a tuple of distinct target change is still as mentions remembered of variables as oldLILS( are renamed. describe the A. the dominance frontiers are small in practice.( X) times. we need a loop over all variables only when we initialize two arrays among the following data structures: –S(*) hold — C(*) C’(V) is an array integers. in turn. node in inserted. 4. No. for each variable to a node processes of a statement sequential those variables actually mentioned in the statement. processing starting with of variables.2 Renaming The algorithm denoted 12 begins the root with have the been in Figure 12 renames traversal The visit The all mentions are generated of the dominator order. of integers.i~).(X) the weighted 1))/(~ I DF(X) (7) As 11 emphasizes the dominance frontiers of nodes with many assignments. The to V have been processed. where a top-down node Entry. Section 8 shows. Vol. October 1991 . The statement and each time cannot be ignored is the cost of take X from W in Figure 11 is incurs a cost linear of Figure A ~Ot(X) x also average Aw(X)) in I DF( X) I 11 to the I DF( X) I )).. statement A has the form LHS(A) RHS(A) of expressions and the variables. i is an integer. The integer should one stack i at the One for top each variable of S(V) variable V.O.

12 Renaming mentions ofvariables.. variable V do c(v) S(V) end call + +- o Empty Stack SEARCH (Entry) SEARCH(X) : for each statement if A is an . where i = Top(S(V)) each ~ for end end for each call Y c Children(X) do V in do replace 1’ by use V. Ron Cytron et al. ina RHS Thelistofusesof V. By keeping acount C(V) ofthe number have already been processed. The simplest case is that of a target variable V inthetuple LHS(A).472 for each . Vol find an C(V). N0 4. October 1991 . where C(v) P’ by i onto i new tj in LHS(A) S(V) + 1 tt7hichPred(Y)X) each ~-function the j-th replace SEARCH(Y) A in oldLHS(A) end for each assignment for each pop end end end SEARCH V in X do do s(v) Fig. replacing ACM Transactions on Pro~amming Languages and Systems. i (which variables we also identify) push new 13. we can of assignments to V that appropriate new variable by using i = C(V) and then incrementing To facilitate renaming uses of V in the future. V by V. grows with each replacement of The processing ofan assignment statement A considers the mentions of variables in A. identifies V.4 in X do ordinary each variable use LHS(A) assignment V of used In RHS(A) of do i = Top(S(V)) then for end for each itreplace push C’(V) end end for /* + of Y first c loop SUCC(X) +/ do F’ in operand Y do t’ in RHS(F) by V.) onto a stack S(V) of (integers that V. Weneed anew variable V.

X does not new idom( variable X). then there is nothing more to show. Lemma 10. No. Let TopA/7er( V. assignment to V. if a node Z does not assign to a new to a variable derived from V.Static Single Assignment Form and the Control Dependence A subtler any variable expressions computation V used in in the tuple. 13. on the other onto hancl. If V. then from the i = Top(S(V)). U). because A maybe either an ordinary assignment or a but they later in 4 and of ~-function. o-function We may for assume X) that Z has = TopAfter( X # idom( Ye DF(Z). X) assigns to such a variable. We want for the right-hand that is. V. Both subcases get V.. loop A node original the value of a o-function V. there can be at most one assignment to V. and. Let U be the first node in idom( idom( . 473 side RHS( Vi. because at the time the algorithm renamed the old use of V to a use of Vi. we consider the two ways V. then it was i = Z’op(S( V )) was true pushed to vi. To show that there is at least one assignment to V. Because the counter C(V) is incremented after processing each PRooF. can be mentioned. to V in inherited TopAf3er( dominator not 9. X) denote the new variable in effect for V after statements in node X have been considered by the first loop in Figure Specifically. on results from Section it makes program. introduced this section. X) ~f V. thus. where X. . assign the Then sequence (9) TopAfter ACM Transactions = TopAfter Languages on Programming and Systems. derived from X)). . is needed RHS( A). V appears V by to replace Graph A). sense to speak Each new variable Vi in the transformed program is a target of exactly one assignment. At the earlier an assignment i was pushed been changed to V had just to an assignment K X may program contain or were assignments introduced to the variable to receive V that appeared in the for all 12. . V. We use this fact twice below. Y does not have (8) a Because V. We start by showing that “the” assignment to a variable in the transformed LEMMA 8. . By Lemma 2. 4. shows that The correctness proof V. is the target of the assignment that There are two subcases produces the value for V actually used in RHS( A). idom( Y). If the value of when time Vi when is used. then Y)). X) is to V. Ye DFIOC=l( X) G DF( X). on three more lemmas. inspect S(V) at different times in Figure 12. from the top of the stack S(V). is mentioned on the LHS on an assignment. PRooF. and define we consider the top of each stack S(V) at the end of this TopAfter If there that assigns LEMMA ( V. is correctly for renaming chosen depends in both subcases. that ( V. V and any CFG edge X ~ Y such that Y does TopAfter(V. ( V. where Consider one of the in at least V. October 1991. the top-down closest traversal of ensures X that are no assignments V. Vol.. For any variable have a rp-function for V. S(V).

V. 13. X).474 Because DF(U). No. V. Vol . 4. A) just statement path. but first from (9). executed is either TopBefore( the original before A. T) just program before and T. Therefore. X) when control flows along this edge. T) T. if A happens TopAfter( V. We consider to define the TopBefore( TopAfter V. A) = TopBefore( and 10. Case 2. Case of TopBefore( V. U) of U. By the induction hypothesis and the semantics of assignment. PRooF. let T be the last statement in X. For Z with U >> Z >> idom( Z >> Y and there an edge X * Y. then TopA/ler( V. V agrees with TopAfter(V. V agrees with TopAfter( V. October 1991 ACM Transactions on Programming Languages and Systems. We assume show that that the kth statement TopBefore( A is from V. Ron Cytron et al U assigns to a new variable Y). If A is from then the value of Vjust before executing A in the original as the value program. so U strictly Z >> X because implies Y. A) ( V. A) = TopAfler( V. program V and any statement B. T) ‘It could be a nominal Entry assignment or a @function. to be the last In particular. Thus. Consider any control flow the same path in the original program. U>> Z >> X from V. Let X + A is the followed Y be the claim V agrees with TopAfler( V. we get derived from V. basic that block Y. A. lemma we must of SSA so as to specify new variable There is one top of each corresponds to V just before and just after iteration of the first loop in Figure 12 for stack just before and just ~f ~f V. on the another LEMMA statement in block X. We consider the kth statement along the path and assume that. = TopAfler Z does not ( V. it follows dominates that that Y $ is But U dominates a predecessor of Y. then TopAfter( V. If X # Entry. for all j < k. hypothesis just after Let T be the statement just before A in Y. the jth statement T not from the original programG or has each variable V agreeing with V. path in the transformed Consider any variable occurrence of a statement A along the path. By the induction and the semantics of assignment. By the choice assign to a new variable derived 7’opAfter( and (8) follows The preceding form. Suppose that A is not the first original statement in its basic block Y. idom( Y)). If. K helps extend establish TopAfter Condition (3) in the definition which A. If X = Entry. V. then A is followed by other hand. Suppose V agrees that edge with TopBefore( first by the original control V. X) is VO and does hold the entry value of V. A) just V agrees with 1. program is the same A in the transformed We use induction along the path. A) Just before executing the original program. We before in its A. A) i = Top( S ( V ) ) before i = TOP( S( V ) ) after processing processing A. B). any . after this where where iteration each statement A.

. must knowing V. . TopAfter( A in Any = TopBefore( V. No. ? ~ + Y ... A) K can be put and then number into minimal SSA form by computin Figure of variables Let avr. Figure 11 places the @functions for V at the nodes in the iterated set of nodes dominance original frontier program. . thanks to the loop over successors of X in Figure 12..X). X) may not knowing ahead of that A TopAfter( TopBefore( may or program. As Figure 13 illustrates. DF+ ( Y ). Suppose that V has a ~-function Vi+- 4(.o. 13. Let A ~Ot be the total of assignments to variables of mentions resulting program. X). on Programming Languages the length of the tuple LHS to A. V agrees with TopBefore( V. TopAfter(V. By Lemma 9.. + T t . Vol. ~ Let MtOt be the total number the resulting program. V agrees just before Suppose with doing 3. October 1991. and and Systems. V does not have V. Then the running time of process O ( avrgDF) + M. x (7) of dominance frontier sizes. the node Y mayor may not have a +-function for V.Static Single Assignment Form and the Control Dependence Graph .. A) just before Case 2. 475 . just after T and.. 4. which doing is TopBefore( A in Y. still hence. that Y. In the proof of Lemma 10. Let E be the number of edges in CFG.gDF 11 in be in the THEOREM program frontiers ing the dominance applying the algorithms and Figure 12. idom(Y)) ‘1 Fig. ) . V. Thus.. This is the operand whose value is assigned to Vi.O. the weighted the whole average is E + ~ x I DF(X) I + (A.2. . . Case V.. A)..) Y /* No ~ for V */ V4K V 2 Z’opAfter(V..1. Y is the set of assignments DF+ ( Y ) is the 7Each ordinary assignment each @-function contributes ACM Transactions LHS + RHS contributes 1 to A ~Ot. 13...) in Y. The @ operand corresponding to X + Y is TopAfter ( V. @(. A) just doing Y. bridge along before with the X + TopAfter( gap Y between and A in for V V.. X) = TopAfter( a ~-function V. be a @-function transformed 2.... X) when control that V V in the flows agrees agrees along with with there x+ We Y. to V in the that need PROOF. idom( Y)) in Y. where By Theorem 2.

and subsumed frontiers.O. The dominator 12 runs in 0( N + E + Mtot) X ) I) Lemma 10. For any node V on r. (2) The node In other p: X ~ Y such that postdominate edge path from from Y postdominates the node X X that that X. Condition the definition We must (2) in of still the @-functions translation show that definition Let N edges. CONSTRUCTION In this section in we dominance Y be nodes postdominates OF CONTROL DEPENDENCE show in the that control graph dependence of the control [241 are flow essentially Let the X and X is reverse graph.1. Condition (3) follows from number of nodes in CFG. October 1991. Because Y postdominates Y must every postdominate then V as well. Figure 11 contributes cost of computing 0( M. then Like the dominator relation. ACM Transactions on Programming Languages and Systems. The postdominator If X postdominates Y but X # Y. Vol.a CFG. Ron Cytron et al. The by the 0( E + x ~ I DF( so Figure 12 contributes 5. . node after 8The postdominance relation in [24] is irreflexive. definitely avoids every node Y does not strictly there there is some words.476 . p be the path Then p: that starts with the edge X ~ Y and Y postdominates get from U to Exit by following to Exit. to execute. LEMMA 11. for V. 12. Section to SSA form renaming follows be the Figure is done from Lemma 8. Suppose that Y postdominates a successor U of X. No. Choose any path q from U to Exit. If X appears on every path from Y to Exit. q that reaches the first Then Y appears on q. We choose the reflexive defimtlon here to make postdominance the dual of the dominance relation. we can r to V and then by taking any path from V U but does not appear before the end of r. a Then Y postdominates path p: X ~ Y a successor of X if and nonnull such that Y postdominates PROOF. and with edge causes executing Y Y. We associate control flow is also some this control dependence from X to Y the from X that causes Y to execute. on a CFG node X if both of the (1) There is a nonnull after X on p. Let r be the initial segment of appearance of Y on q. 13. As explained 0( AfOt x czurgDF). then X strictly immediate postdominator of Y is the closest strict from Y to Exit. postdominates Y. along X + U and proceeds X on p. frontiers Y. X on p. K 6. Our here can easily be shown to be equivalent label on the definition of to the original control dependence definition [241.). of Y on any path the children of a node X are all immediately dependent A CFG node Y is control following hold: path postdominated by X. the postdominator relation reflexive and transitive. The two relations are identical on pairs of distinct elements. Let X and only every if (iff node ) Y be CFG there after is nodes. tree has O(N) N + E term is the dominance at the end of time. Let r. In a postdominator tree. so we have with obtained the fewest correctly by Condition possible Figure (1) in @functions. 4. whereas the definition we use here is reflexive.

10 9.8. Control dependences of theprogram in Figure5. Then reverse control U is a successor flow graph of X and Y postdominates same nodes RCFG has the control The on flow graph CFG.9. October .11. 14 applies this K result to the computation of control depenclences. Then Y is control dependent COROLLARY Let X and on X in CFG l?ROOF.6. No ACM TransactIons on Programming Languages and Systems. as the [] node X on p. 477 build build apply RCFG dominator the dominance tree frontier X Y E do do RDF(Y) CD(X) U for in RCFG Figure 10 to RDF 0 end find for the RCFG mapping t-- algorithm for for each each for node node X CD(X) each CD(X) do { Y } end end Fig. roles of Entry and Exit are also reversed. In RCFG this means that Y dominates a predecessor of X but does not strictly dominate X. The postdominator relation CFG is the dominator 1. 15.7 4.Static Single Assignment Form and the Control Dependence Graph .12 3. Algorithm for computing the set CD(X) of nodes that are contro 1dependent on X Node Entry 1 2 3 4 5 6 7 8 9 CD(Node) 1.8. we find that Y is control dependent on X iff Y postdomi - nates a successor of X but does not strictly postdominate X. 14.11.2.Vol. The total time is thus standard method [351 dominance frontiers for all 1991 0( E + size( RDF)) 13.5 Fig. Y be nodes in CFG. that Figure is. 4. After building the dominator tree for RCFG by the in time 0( Ea( E. after The given a path p with these properties. but has an edge Y + X for each edge X + Y in CFG.12 10 11 [ 12 Conversely. iff X~ DF( Y) in RCFG. relation on RCFG. X~DF(Y). control Using Lemma 11 to simplify the first condition in the definition of dependence.9. we spend O(size( RDF)) finding and then inverting them. N)).11 2. let U be the first U.

p. 431. but efficient code are applied: dead code section useful optimization by coloring. but sented in existing target machines. as in the equivalencing and redundancy elimination algorithms that are based on SSA form [5. however. If the naive replacement is preceded by dead code and then followed by coloring. however. purposes..then. steps in compilation With so many integration) dead code. X can be replaced by k flow predecessor of X. Suppose that V is assigned and then used along each branch of an if . October 1991 . 489]. 4. No. Code that sources for dead code. By applying to Exit the algorithm the control was added would in Figure so that 14 to the control in Figure the at Entry. Note control flow that in Figure 5. as a graph. TRANSLATING Many powerful FROM analysis SSA FORM and transformation techniques can be applied to programs in SSA form. sometimes perform a Naively.1 Dead Code Elimination program may may in the have dead code of useless work. The @-functions have precise semantics. Vol.. we obtain Entry viewed dependence to CFG be rooted edge from depend- ence relation. dead code eliminamany intermediate Translation to SSA form is one of the compilation steps that may introduce dead code.e. but these ordinary assignments good deal elimination efficient. Often.. subject removed. original assignments to V are live. to the correctness g A procedural condition of the that “dead” is can be safely version definition ‘The definition used here is broader variables [25. One such use is shown in Figure 16. 13. but that V is never used after the join point. ACM TransactIons on Programming than the usual one [1. Dead code is sometimes defined to be unreachable code and sometimes defined (as it is here) to be ineffectual code. code that has no effect (such once was possible on any program become output). it is natural to perform (or repeat) tion late in the optimization process. 7. Naive translation could can be generated elimination if two already allocation and storage @-function inefficient a program must be executed. it is desirable to use the broadest code really possible definition. each yield This out of SSA form by replacing ments. Eventually. p 595] and similar to that of “faint” Languages and Systems. Although others have avoided placement of dead @functions in translating to SSA form [16. 15. 52]. such dead +-functions are useful.. In both cases. a k-input @-function at entrance to a node ordinary assignments. There are many different definitions of dead code in the literature.. the resulting code is The original as procedure live may source (i. rather than burden steps with concerns about dead code. .. but the added assignment by the @ function is dead. dead Some of the intermediate also introduce course of optimization. 7..478 practical graph the G Ron Cytron et al. one at the end of each control This is always correct. The else. we prefer to include the dead O-functions to increase optimization opportunities. they are generally not repredescribes with object how to translate some ordinary assigncode.

statements dead. to a reference there call to a routine (2) The statement already marked is an assignment statement. holds: program parameter. statements. 479 if Pi then do Yltl of Y1 end else Y2 end use do Y2 of Y1 + xl use of use of 4( YI. . 16. eliminate dead code in the narrower sense branch to be marked live [30. Z2) use of Z3 use of Y3 Fig. or a iff at least should have one of the following to affect dead are truly A statement (1) The such statement as an 1/0 is one that statement. 381. 31. When the worklist eventually empties. 13. . more Initially. intuitive all need than a recursive are version. algorithms conditional Figure and there are statements already on this conditional branch. and live that use some of its outputs. The value numbering technique in [5] can determine that Y3 and Z3 have the same value. tentatively live so we prefer marked of the the procedural Some listed style. The dead ~-function is brought tolifebyusing Y3 inplaceof Z3. . are output. Paige (An unpublished ‘“The more readily accessible [31] contains a typographical should be consulted for the correct version. Y2) Y3+ do + xl Graph . . ACM TransactIons on Programmmg Languages error. October 1991. Vol. statements (3) The statement is a conditional branch. however. Thus. No.1° Our 17. below. any statements that are still marked dead and can be safely is marked live removed from the code. conditional given in branches.) algorithm by R. if Pi then else Z1 Z2 t ~ 1 Xl 4’(Y1.Static Single Assignment Form and the Control Dependence if Pi then do Yi+-1 use end else Y2 end Y3 . Y2) . Ontheleft isanunoptimized program containing a dead @function that assigns toY3. that may be assumed an assignment side effects. the earlier technical report [301 and Systems. 4. Marking natural to be marked because conditions these statements live may cause others to be marked live. Z3 and many of the computations that produce it can be eliminated. marked live that are control dependent Several published that requires every algorithm. . Y2 Z3 + 4( ZI. goes one step further in eliminating does this dead al so.

the current procedure — WorkList covered. 17 each statement = false delete B in CD-l = false - (B/ock(S)) do Liz~e(Last(B)) true U { t WorkList Last(B) } S do Live(S) then S from Block(S) Dead code ehmination The following —~ive(S) —PreLiue data structures that are used: S is live. No. —Definers(S) Statements that result in 1/0 scope are typically included. TransactIons on Programming Languages . whose execution is initially assumed to or side effects has been outside disstate- indicates is the statement set of statements affect program output. Ron Cytron et al for if each then else end iVorkList while take for if statement Live(S) Live(S) S do + true false S G Pre Live t(WorkList Pre Live # 0) do S from each then D 14To~kList c do Definers(S) = false ttrue \VorkList U { ~ } do Live(D) Live(l)) PVorkList end end for If each then block do Live(Last(B)) WorkList end end end for If end Fig. ment —Last( S. whose that Iiveness provide basic statement block S.480 . October block 1991 1?. is a list is the of statements set of statements that recently used by values B. 4. B) is the statement is the basic l?) terminates –Block(S) — ipdom( ACM block block containing that is the basic immediately and Systems. postdominates Vol 13.

to consider derived of the should most If the goal is to produce each original from variable readable source code. However. then to model the SSA variables coloring be considered assignments cases. Storage savings are especially noticeable for arrays.l(Block(S)). The of the new variables by the code motion to V twice by moving with the the introduced example invariant variables VI by translation in Figure assignment for and separate The SSA form out These to SSA form code 18b) loop. Such operations can be implemented inexpensively by llA conditional branch can be deleted by transforming it to an unconditional branch to any one of its prior targets. all of of the it is desirable the SSA variables changes V separately. (such not marked may leave optimizations motion) empty blocks. can share the same storage. to SSA form cannot always be eliminated. 18. that is. 13. Any graph coloring algorithm [12. (Figure of the 18. separate purposes (Figure live. assignment to V3 will where be eliminated. leave be yielding The all of the ~-functions.2 Allocation by the loop over a block with live by Coloring seem possible simply dead until marked live is crucial (transitively) on themselves are other live statement. both variables are required: The original variable V cannot substitute for both renamed variables. 4.V. Statements that depend never marked live unless required by some (3) is handled tion controls 7. ACM Transactions on Programming Languages and Systems. Vol. If optimization does not perturb the order of the first two statements in Figure 7. In both that were inserted code. 481 of the 14. . 211 can be used to reduce the number of variables needed and thereby can remove most of the associated assignment statements. The source persistence can be illustrated optimized a program dead a region in 18a) assigns and uses it twice. remove them. coloring V. If the goal is machine at once. These identity assignments can all be deleted. optimization program Vz are simultaneously Thus. The fact that statements are considered for condition (2). B. The array A ~ is then assigned an Update from an identically colored array. whose Condition termina- CD. 17. the process @functions into identity assignments. assignments of the form V . it might to map all occurrences the new variables of Vi back to V introduced by and to delete translation may have useful (Figure can 18c). predecessors B) in Figure still node corresponding After live the are algorithm deleted. 13.Static Single Assignment Form and the Control Dependence Graph – CD-1(B) is the set of nodes that to block discovers 11 Other are control is the dependence . This the live same as RDF( all those as code statements. At first. then ~arrays A ~ and A ~ can be assigned the same color and. because optimization capitalized on the storage independence of the new variables. The choice of coloring technique should be guided by the eventual then just use of the output. so there is already ample reason for a late The empty blocks left by dead code elimination optimization to can be removed along with any other empty blocks. No. October 1991. A basic block statements is itself live. hence.

Vol. program. ACM TransactIons on Programmmg Languages and Systems. . Program that (b)unoptimized - lj(v~.. Ron Cytron et al. For programs the can be described 19. . (c) result of code motion. V2G6 while (. . experimental the behavior THEOREM comprised dominance of frontier straight-line of any code. PROOF.) programs programs.) do while W3 (. we consider the associated frontiers of nodes. V2) read VI WI +V1+W3 WI +vi+w3 V2t6 W2 +V2+W1 end (b) really uses two instances for a variable SSA form. ure linear flow (We branching assume Such is restricted that expressions into account. flow graph a top-down we have parse of a program (program) using the grammar in the parse shown tree in and Figure a single node a control CFG with two nodes and one edge: to Entry - Exit.. October 1991 . Consider 19.) - do ~(w~. For each CFG and to the dominance a nonterminal parse tree node S. No. most two nodes.482 . (statement) symbol 13. since the actual assignments are not taken the size of the dominance frontiers control loops. In this new subgraph. 4. contains at and while-do constructs.. We will show that applying any of the productions preserves the following invariants: CFG node S corresponding to an unexpanded –Each has at most one node in its dominance frontier. When a production expands = @ = DF(Exit). V1 v~) read W3 + ~(w~. Program structure alone determines dominance frontiers and the number of control dependence. of this form. the operation by HiddenUpdate is always 8. Initially. w~) V3 + $+(VO. a new subgraph is inserted into CFG in place of S. each node corresponds to a symbol on the right-hand side of the production.) do V3 read V Wtv+w V+6 W+v+w end (a) Fig 18. In this section we prove that is linear in the size of the program when to if-then-else and results by the that constructs perform grammar that and no given while-do internal in Figis predicates suggest branching. It is possible that dominance frontiers may be larger than necessary for computing @function locations for some programs. (a) Source assigning actual to just one component performed if the array s share storage. W-J while (. after end W2 4- V2+W1 (c) code motion. CFG node if-then-else. The initial dominance frontiers are DF(Entry) changes production. We also give for actual 4. Inparticular. ANALYSIS AND MEASUREMENTS The number of nodes that contain d-functions for a variable V is a function of the program control flow structure and the assignments to V.

Edges are inserted S are now to Sd. T. IBy the argument for production (2).l.~. Edges leave Sz.e. by S. dominates all nodes that were by node S. inturn. of the allowed control constructs graph and its R(CFG is associated control ACM flow graph The reverse Languages flow Vol.~) = DF( S) = DF(T. All edges previously associated associated with node TUkil.~i~. Additionally. node to a terminal symbol has at most two nodes in its dominance We consider (l) the productions This production adds aCFG ing DF(S) = {Exit}. (3) When S is replaced s then? Sel. on at most two and while-do is control nodes.~~i ~]). 19. NOW nodes we obtain Sthen and Sel~e. if-then-else.n~. Consider a program P composed CFG.. Additionally. yield- (2) When is applied. 13. by nodes (4) When T whzle this production is applied.) a CFG = { T. 2.Static Single Assignment Form and the Control Dependence Graph <program> <statement> <statement> :: = <S. dominates SdO. Thus.m and dominateclby by nodes leaving additionally.~e.l. . = DF(S) (5) After phic application of this production. Node TWh.l. No. Although the consider Szdominate Sz. —Each CFG node T corresponding frontier.~~i ~ both dominate all nodes that were dominated made consider fr(mtier. Sisreplaced by twon odes SI and control S. Edges how this wehave node production DF(Sl) entering from affects were = DF(S) and all nodes that a CFG previously has changed.l. and dominated DF( TWhil. Ti ~ and T. edges are also inserted from St~~~ and S~l~~ to Te~~i~. tatenent> ::= ::= <statement><staternent> if <predicate> then else <statement> ::= while do <statement. Transactions on Programmmg and Systems. S now S~~. Ti ~ dominates S~~~~ and S. the new control flow graph COROLLARY For programs constructs. K to the old graph...l. we have DF( T. Sland Sldominates production Te. PROOF. previously entering and leaving S now enter edge is inserted from SI to Sz. TU~. A single flow graph tortree: Nodes this Sand aCF’G edges Entry node +S+Exit. every comprised node of straight-line dependent code. and SdO.~ and leave are inserted Ti~ to both s~l~~..~~z~.> ::= <statement> <statement> <predicate> <statement> <expression> for control structures (5) (4) (1) (2) (3) . we have U { TWhi~=) and DF(SdO) = { T~h.fl}. 483 <variable> Grammar Fig. Edges is applied. 4~October 1991.. node S is replaced with from node TW~.) is isomor- from S& to TU~. In the dominator tree. Ti~. Thus.}.. From the definition of a dominance DF(S. thedornina = DIF(SJ. this production SI and Sz. and enter T.l.) = DF(S.

We therefore wish to measure the nodes as a function of program size over a for constructing dominance frontiers and system. The ratio of these sizes close to the range of ratios for ratio avrgDF (defined by (7) in Section 5.3.2. No.034 2. All but one of the remaining procedures contained fewer than 60 statements. total For 4. Most of the dominance @functions.054 14. 5. For all Y in 1.484 . linearity the the results nest do not frontier whose hold of the loops.1) measures the cost of ~-functions relative to the number of assignments in the resulting on Programmmg Languages and Systems. 13.181 Summary Statistics of Our Experiment Statements per procedure Min 22 9 8 8 Median 89 54 43 55 Max 327 351 753 753 Description Dense matrix eigenvectors Flow past an airfoil Circuit simulation 221 FORTRAN procedures and values Package name EISPACK FL052 SPICE Totals itself RCFG. We ran these algorithms from on 61 [46] and 160 procedures two “Perfect” our algorithms in the PTRAN flow from EISPACK and control [391 benchmarks. For for all loops program illustrated to that strucin loop this each consider of repeat-until dominance mapping d-functions. Some summary statistics of these procedures are shown in Table I. these each loop. in placing might entrance n nested each of the entrances frontier 0(n) used needs at most is not actually of dominance to surrounding loops. Statements in all procedures 7. linear the plot in Figure 21 shows that program. The ratio of these sizes ranged from 0. 4. the size of the dominance frontier mapping appears to vary linearly with program size. the number The ratio of of in the size of the original these sizes ranged from 0. Figure includes leads variable mapping computation In particular. The placing ACM the size of the control dependence program.4. Table 1.6 (the Entry node has an empty dominance frontier) to 2. The largest ratio occurred for a procedure of only 12 statements.6 to 2. Y DF( Y) contains at most two nodes by Theorem K control dependent on at most two nodes.093 23. For the programs ~-functions is also we tested. the plot in Figure 22 shows that graph is linear in the size of the original ranged from O.5 to 5. These FORTRAN programs were chosen because they contain irreducible intervals and other unstructured constructs. October 1991 TransactIons . is then a structured control flow graph for some program P’. and 95 percent of the procedures had a ratio under 2. tures. Ron Cytron et al. As the plot in Figure 20 shows. We implemented placing ~-functions local library data flow procedures @functions. yet to a dominance size is 0( nz).1. Vol. which already offered the required analysis [2]. which is very dominance frontiers. Finally. so it seems take excessive time with frontier that the respect to frontiers the resulting number of actual number of dominance frontier diverse set of programs. By Corollary Unfortunately.

I 100 I 200 I 300 I 400 I 500 6~o of program ~~oo statements. .~ in the number of mentions (assignments ACM Transactions on Programming Languages and Systems. / A.8..Static Single Assignment Form and the Control Dependence Graph 16001500140k 1300120011oo1000-900 — 800 — 700 — 600 — 500 — 400 — 300 — 200 — *:*@*?:*:: * ‘** * ** ***** *** * * * * . we measured the expansion MtOt / MO. I 200 I 300 I 400 I 500 I 600 --&-Too Number of rj-functions versus number of program statements SSA form program. 13. There was We also measured the expansion A. 20. No.3 to 3. with median 1. in the number of assignments when translating to SSA form. * 485 * * * * * loo— 0 o Fig.. Size of dominance frontier mapping versus number 1300 1200 110 100 900 800 700 600 ! 500 — 400 — 300 — ** ****:* *** ** ‘e * * * *** * * * * * * * * * * * * * * * loo— 0 0 I 100 Fig. October 1991.. This ratio varied from 1..3.. no correlation with This ratio varied program size.. Vol. 21. 4. Fina”lly. from 1 to 2.

variable in the original program the total number of assignments where each ordinary assignment len~h A .6 size.O. be the total number of of variables in the resulting program. 22. The time the dominance frontiers in CFG (2) Using the dominance frontiers. parameters. or uses) to 9. are renamed (Section 5. dominance frontiers. Let A ~Ot be to variables in the resulting program. statement LHS * RHS contributes the time. No 4..2). Let M. and each ~-function contributes I to Placing @functions contributes 0( A.1). 6. This ratio with varied from 1. correlation program DISCUSSION and Time Bounds is done in three steps: the control flow E edges. in terms be the Languages (3) The variables mentions 0( M. there to SSA was no form.O.. of variables For both when of these translating ratios.486 160 150 1400 130 120 110 100 900 800 700 ! 600 500 400 300 1 200 — loo— 0 . 100 1 300 400 I 500 600 700 I 800 Size of control dependence graph versus number of program statements. Ron Cytron et al.) to the overall R To state the time bounds of the original program TransactIons on Programming of fewer maximum and Systems. x aurgDF) to the overall where aurgDF is the weighted average (7) of the sizes I DF( X) 1. * * * ** * * ******* * ** * * ** ** * **2** $* ?@%’” ‘**** I 200 0 Fig.2). Renaming contributes time. October 1991 ACM .1 Summary of Algorithms The conversion to SSA form (1) The graph dominance fi-ontier mapping is constructed from CFG (Section 4..2. Let CFG have N nodes and nodes to their tree and then be the mapping from compute the dominator O(E + Xx I DF(X)I). let the overall size of the relevant numbers: N Vol 13. Let DF to is 9. O. the locations of the @functions for each are determined (Section 5. of the tuple LffS to A ~ot.

whose sizes are not necessarily related to the depth of ACM Transactions on Programming Languages and Systems. has Thus. E edges for a program with Q variables. O(R). AOT. In the Graph . our approach can also take quadratic time. avrgDF lation reverse RDF Control be linear as is the is constant. = O(MO. 326]. The pseudoassignment nodes for V are exactly the nodes that need o-functions for V. Vol.~ original avrgDF = ~ ( IV) = 0(R). difficult to manage the new names or reason about the flow of values. and k insertions a c$function of qLfunctions. 487 of variables. 13. are (Section output read off of the and from M. they appear to be intrinsically quadratic. but the only quadratic behavior is caused by the output being fl( N2) in the worst case. our algorithm computes control dependence in linear time. N)) bit vector operations (where each vector algorithm is of [43] length for Q) to find all of the compseudoassignments. A simpler reducible programs putes SSA form in time 0( E x Q). In effect.O. A tOt = !J(R2) at worst. The data suggest that the control dependence calculation is effectively behavior in Section 0(R). if-then-else. Section 6 shows that control dependence can be determined by computing dominance frontiers in the reverse graph RCFG.Static Single Assignment Form and the Control Dependence nodes. The method presented here is 0( R3) at worst. The only quadratic caused by the output being fl( R2) in the worst case. The one-parameter worst-case time bounds are thus 0(122) for finding dominance frontiers and 0( R3) for translation to SSA form. This analysis is based on (post) dominator tree [24. In general. A closer precursor [221 of SSA form associated new from names for V with pseudoassignment Without nodes explicit and inserted assignments it was one new name to another. 4. and the simpler algorithm sometimes inserts extraneous o-functions. One algorithm [411 requires 0( Ea( E. 9. The earlier 0( R2 ) algorithms have no provision for running faster in typical cases. the data in Section 8 suggest that the entire translation to SSA form will is small. assignments to variables.~). and MO. For CFG with N nodes and E edges. but Section 8 gives evidence that it is 0(R) in practice. the dominance dependence The entire frontiers Since calculation. With lengths of bit vectors taken into account. p. The dominance frontier of each node in CFG number of ~-functions added for each variable. process graph is the dependence RCFG size of the in practice. and while-do constructs. Suppose the control flow graph CFG has N nodes and. No.Ot = 0( R3) at worst. !J( 1?) operands.. however.. Thus.2 Related Work SSA form is a refinement of Shapiro and Saint’s [45] notion of a Minimal pseudoassignment. previous general control dependence algorithms [24] can take quadratic the worst-case 0(N) depth of the time in (N + E). A ~Ot= 0( Ao.. October 1991. control the size of algorithm is linear in the size of the output. In particular. both of these algorithms are essentially 0( R2 ) on programs of size R. However. We obtain a better time bound for such programs because our algorithm is based on dominance frontiers. can require worst 0( I&) case. By Corollary 2. suppose a program is comprised only of straight-line code. . M.~ original assignments In the worst case. mentions ordinary E edges. @functions.~). transin the this is 8 is effectively 6) in time 0( E + size( RDF)).

Symposium Syst. Houston.. and that applying the early steps in the SSA translation to the reverse graph is an efficient way to compute control control dependence ACKNOWLEDGMENTS dependence. ALLEN. 1977) ACM. Detecting equality of values m programs on Principles of Programming Languages In Conference Record of the 15th ACM Symposium (Jan.. 4. For languages that offer only these constructs. Compzlers: Principles.3 Conclusions Previous powerful work has shown that SSA form and control that dependence efficient can support in terms of code optimization algorithms are highly time and space bounds based on the size of the program after translation to the forms. In Proceedings (ACM) 25. led to many paper. 10. 7. Comput. like Shaw whose to thank Julian for various thorough Fran Allen for early Tom encouragement Reps. Rice Univ. New 9. AND JOHNSON. helpful reports comments. BURKE.. SIGPLAN Not. that SSA form and We would Trina Jin-Fan referees. AHO. This is strong evidence form a practical basis for optimization. J. K.. Reading. that it leads to only a moderate increase in program size. M. 162-175. Ph. 7 (June Interprocedural dependence 1990).488 . J. It handles all cases in quadratic time and 9. AND ULLMAN. J. thesis. The program dependence web: A representation supporting control-. REFERENCES 1. R.. 257-271. S Compiling C for vectorization. 1988). R. parallelization and inline of the SIGPLAN ’88 Symposium on Compder Construction. A. An efficient way to find the side effects of procedure calls and the aliases of Record of the 6th ACM Syrnpoa~um on Principles of Programming variables. 241-249 ALPERN. An interval-based ACM of the Trans.. 29-41 8.. J. Construction SIGPLAN In Not 1986). 1986. 2. 3 (July Compiler on Principles of Programmmg Languages (Jan. typical cases in linear time. data-. Symposium 119-131. 341-395.D. (Oct. analysis. In Conference Record of the 4th York: flow ACM pp. New York. J. 7 (June 1988). R. Bob Paige. MACCABE. 6. CHARLES. New York. BURKE. An interprocedural data flow analysis algorithm. expansion. BURKE. 13. Proceedings (ACM) ACM 21. AND FERRAiYTE. and Tools. October 1991 Transactions on Programming . Apr. ACM. SIGPLAN approach Program 86 to exhaustive Lang. M. Tex. Department of Computer Science. J R .. pp. AND CYTRON. on and incremental interprocedural data 12. 5. 1988). E. D. PTRAN analysis system for multiprocessing. 1-11. J An overview of the Distrib. Ron Cytron et al. analysis and parallelization. grateful in this Allen. 1983. Vol. AND ZADECK. Techniques. CYTRON. In Proceedings SIGPLAN Not. AND OTTENSTEIN. pp. but our algorithm is more robust. M. M. In Conference Languages (Jan. B. SETHI. (ACM) 23. BARTH. Randy improvements We are especially and Fran Scarborough. B . F. R Dependence analysis for subscripted variables and its application to program transformations.. control dependence can also be computed from the parse tree [28] in linear time. B. We have shown that this translation can be performed efficiently. Languages and Systems. R. BALLANCE. K. J. 4 5. WEGMAN. Mass .. the dominator tree. ALLEN. N. 1979) ACM. and demand driven interpretation of languages. V. 6 of the SIGPLAN 90 Symposkum on Compiler Construction. A.. ALLEN. F. A. P. Parallel 617-640. No.. M. Padget. Addison-Wesley. (June 1990). and to the Avery. BANNING. 3.

K. JONES. D. 9. A. of California Berkeley. Stanford. D.. S. W. Register allocation via coloring. A portable machine-independent global optimizer—Design and measurements. Jones.D. J. N. 1986). Armonk. 30. 27. J. M. R. T. In Proceedings of the SIGPLAN 88 Symposium on Compiler Construction. 28. 29. Eds. 111. AND FELLEISEN.. In Conference ming Languages (Jan. 5. Memo 61). 1973. Lang. Tech. ACM GIEGERICH. Prentice-Hall. Rep. L.. Univ. New York. PRINS. An improved control dependence algorithm. J.. CHASE. Courant Institute of Mathematical Sciences.. AND FERRANTE. of Mathematical Sciences. AND FERRANTE. A. F. 4 (Oct. M.. Automatic construction of sparse data flow evaluaRecord of the 18th ACM Symposium on Principles of Programtion graphs. CHANDRA. Computer Systems Laboratory.. First version of a data flow procedure language. Jones. KENNEDY. R. J. J. tion. D. 319– 349. COOPER. A linear time algorithm for finding dominators in flow graphs and related of the 17th ACM Symposium on Theory of Computing (May 1985). of Computers and Computations. J. 21.. In Proceedings Conference on Parallel Processing CYTRON. R. S. Group Memo 93 (MAC Tech. 32. In Proceedings (ACM) of the SIGPLAN 90 Symposium on Compiler Construction. J.. FERRANTE. 19. 6 (1981). Houston.Static Single Assignment Form and the Control Dependence 11. N. 1983. M. HORWITZ.. (June 13291. 12.. SIGPLAN Not. KENNEDY. W. R.. S. C. 478-498. A formal framework for the derivation of machine-specific optimizers. 70-85. 7 (June 1988). Tex. New York. Flow Analysis. Tech. AND MARKSTEIN. AND FERRANTE. Calif. of the SIGPLAN 89 Symposium Graph . 3 (July 1987). In Program Flow Analysis. Flow analysis and optimization of lLISP-like structures. New York.. Not. D. 22. on Compiler Construction. Englewood Cliffs. P. R. K. Proceedings of the SIGPLAN 89 Symposium Dependence on analysis for pointer variables.. (ACM) 23. pp. S. 489 The semantics of program dependence. WEGMAN. Dec. 1990). AUSLANDER. Syst. R. New Yorkj pp. Program. N. The Structure LARUS. Strut. 25. May 1989. ACM Trans. Program. CHAITIN.. D. AND WARREN. problems. thesis. F. Analysis of pointers and structures. Rep. 31. 1978. J.. R. DENNIS. Integrating non-interfering versions of programs. CARTWRIGHT. N.. 1987). 1990). HORWITZ. 16. SIGPLAN Not. SIGPLf~N In Not. Stanford Univ. ACM. K. CYTRON. A survey of data flow analysis techniques. 12. AND MUCHNICK. (ACM) 24. AND ZADECK. Cambridge. IE.. Rep. UCB/CSD 89/502. K. Tech. CHOW. 26. ACM. C. Computer Science Dept. pp. J. CHASE. HAREL. KUCK. Trans. Program. J. HOPKINS. October 1991. S. 33.. Code motion of control structures in high-level on Principles of Programming languages. R. Vol. 1983. CYTRON. The program dependence gmph and ACM Trans. Comput. COCICE. 296-310. . Lang. SIGPLAN (ACM) In Proceedings 24. 345-387. K.. 14. K. SETL Newsl. Rice Univ. Syst. Program.. D. at Berkeley. CHAITIN. 55-66. 13. J. chap. New York Univ. 185-194. 102-131. J. No. Y. Rep... 1987. 13-27. Ph. MIT. PFEIFFER. 4. thesis and Tech. Calif. S. F. its use in optimization. CHOI. 7 (June 1989). Mass. Compiler Construction. LOWRY. J. Aug. J.. New York.... CHOW. Ph. Lang. J. May 1975. 18. 19-27. K. pp. 11. 4. D. RC 25. 13. IBM Corp. A. D. Muchnick and N. S. 1991). Safety considerations for storage allocation optimizations.. 15. Compiler Construction. 20. Comput. CYTRON. 1981. Lang. Syst. 23.. Not. Muchnick and N. 24.. Englewood In Program Cliffs. AND HENNESSY. ACM. G. Prentice-Hall. Wiley. Dept. 3 (July ACM Transactions on Proq-amming Languages and Systems. AND ZADECK. In Conference Record of the 13th ACM Symposium Languages (Jan. Interprocedural data flow analysis in a programming environment. 3 (July 1983). Syst. 1989). What’s in a name? In Proceedings of the 1987 International (Aug. The priority-based coloring approach to register allocaLang. W. Restructuring symbolic programs for concurrent execution on multiprocessors. J. 47-57. OTTENSTEIN. D. F. 501-536. Y. Global dead computation elimination. T. R.. SIGPLAN 1982). M. G. In Proceedings (ACM) 17. SIGPLAN 82 Register Symposium allocation on and spilling via graph coloring. D. 17.. AND REPS. 1981. P. 7 (July of the 6 (June 1989). AND REPS.. B. N. Eds. 83-254.. 98-105. ACM Trans. Rep. Tech. J. 1-10. S. pp.

T. MUCHNICK. Comput. REIF. R. 23. BOYLE. 44. KLEMA. 7 (July 1988). Softw. 322-344. 51 WOLFE. 21-34.. 1981). Tech. Global value numbers and redundant Record of the 15th ACM Symposui m on Przn ciples of Programcomputations. 12-27.. Rep. RUGGIERI. In Conference 8th ACM Symposium on Principles of Programming Languages (Jan.. 37 38. C. Eng. 1978. K. H. Tech Rep. Apr. P. 1 (July 1979). Ph. New York. Univ.490 34 .. IIIEBE. NJ. B. 285-293. K . A fast algorithm for finding dominators m a flowgraph. 1989 Received July 1989.. pp. S.. AND MOLER. R. J. J. 3. In Conference ming Languages. AND REPS. AND ZADECK. H. EngleProgram Flow Analysis. F. A precise interprocedural data flow algorithm. R. 32. Data flow analysis for procedural languages J. July 1989 REIF. Program. T. J. Ind. E. Tech. SMITH. revised March 1991. pp. thesis. October 1991 . 88 Sympostum on Compder Construction. 121-141 Prentice-Hall.D. 50. of Computer Science. OTTENSTEIN. M. Syst. POINTER.. 1 (1974). Perfect report: 1. J. D . AND SAINT. WEGMAN. 3 (June 1986). Urbana. IEEE Trans. B SE-1. J. Feb. M. K. F. Urbana 111. To be published. AND TARJAN. W. 39. Madison. Dept of Computer Science. J. ACM Trans. Univ. W. 1988). WEGMAN. 35.. R. R. 1981 Record of the MYEKS. New York. AND ZADECK. HORWITZ.. 270-285. ACM. K. Vol 13. 291-299. 62-89.. AND MURTAGH. B. N. 45. M . N of the ACM SIGPLAN Detecting conflicts between structure accesses SIGPLAN In Not. 1982). J. M. Syst. N.D. Efficient symbolic analysis of programs. In 1. 1982 52. 81-93 ROSEN. GARBOW. 36. Dept. New York. Constant propagation with conditional branches. 43. H. F. Lang. W. 111. 1 (Feb. Lafayette. T. L. LARUS. 40 41. 47 TARJAN. Optimizing supercompilers for supercomputers. Univ. 1975). Purdue Univ. of Illinois at Urbana-Champaign. Comput. P. of Illinois at Urbana-Champaign. pp. 11. 2 (Apr. Lang. E.. In Conference Record of the 12th ACM Symposium on Prlnczples of Programm mg Languages (Jan. M. K. CA-7002-1432. New York. S. SHAPIRO. Rep CSRD 896. AND TARJAN. SIAM J. J Proceedings Ron Cytron et al R. ROSEN. LENGAUER. AND HILFINGER.. (Jan. N . Syst. C B. DONGARRA. Comput Property extraction in well-founded property sets. Matrzx Eigensystem Routines – Eispack Guide. thesis. accepted March 1991 ACM TransactIons on Programming Languages and Systems. Finding dominators in directed graphs. Detecting program components with equivalent behaviors. 42... E Symbolic program analysis in almost linear time. pp. T. of Wisconsin at Madison. AND LEWIS. AND ZADECK. H Massachusetts Computer Associates. Lifetime analysis of dynamically allocated objects. 280-313. SIAM J. WEGBREIT. 1970.. Aug... B. Dept. ACM Trans. New York. EDS wood Cliffs. J. 219-230. Program. AND JONES.. ACM. 3 (Sept.. N. K. 1988).). Center for Supercomputing Research and Development. S. 1976. C. E. Constant propagation with conditional branches. 49.. 1979). ACM. 48. WEGMAN. The representation of algorithms. Y. No 4. Conference Record of the 15th ACM Symposzum on Principles of Programming Languages (Jan. YANG. of Computer Science. SCZ. 840. Data-flow graphs as an intermediate form. Ph.. 46. B. M. Springer-Verlag. V. S. ACM 26. ACM.