
DemandDriven Constant Propagation Eric Stoltz Michael Wolfe and Michael P Gerlek Department of Computer Science and Engineering Oregon Graduate Institute of Science Technology PO Box Portland OR ext FAX stoltzcseogiedu Technical Rep ort Abstract Constant propagation is a wellknown static compiler technique in whichvalues of vari ables that are determined to b e constants can b e passed to expressions that use these constants Co de size reduction b ounds propagation and deadco de elimination are some of the optimizations which b enet from this analysis In this pap er we present a new metho d for detecting constants based up on an opti mistic demanddriven recursivesolver as opp osed to more traditional iterativesolvers The problem with iterativesolvers is that they mayevaluate an expression many times while our technique evaluates each expression only once To consider conditional co de we augment the standard Static Single Assignment SSA form with merge op erators called functions adapted from the interpretable Gated Single Assignment GSA mo del Wepresent pre liminary exp erimental results whichshow the number of intrapro cedural constants found in common highp erformance Fortran programs This research supp orted by NSF grant CCR ARPA grant FC and grants from Intel Corp oration and Matsushita Electric Industrial Intro duction Constant propagation is a static technique employed by the compiler to determine values which do not change regardless of the program path taken In fact it is a generalization of constant folding the deduction at compile time that the value of an expression is constant and is frequently used as a preliminary to other optimizations The results can often b e propagated to other expressions enabling further applications of the technique It is this recursive nature of the dataow problem which suggests using a demanddriven metho d instead of the more usual iterativetechniques In the following example the compiler substitutes the value of in S for x whichisa canonical instance of constant folding Since the value of x is now constant the compiler can propagate this value into S which after applying constant folding once again results in the determination that y is the constant It should b e noted that constant propagation for this work was applied only to scalar integer values Propagation of realvalued expressions can b e p erformed but sp ecial care is required since op erations on realvalued expressions are often architecturally dep endent The metho d outlined in this work also allows for arbitrary symb olic expression propagation S x S y x Although in general constant propagation is an undecidable problem it is nonetheless ex tremely useful and protable for a numb er of optimizations These include dead co de elimi nation array and lo opb ound propagation and pro cedure integration and inlining which we b elieve to b e a ma jor source of detectable constants Due to these b enets constant propagation is an integral comp onent of mo dern optimizing commercial compilers The pap er is organized as follows In Section we examine the standard framework em ployed to p erform constant propagation and relate it to previous metho ds and algorithms In Section we dene the structure used for this work with particular attention given to the necessary intermediate form based up on Static Single Assignment required to implementthe algorithms we present The basic propagation metho d used in our restructuring parallelizing compiler is also given in this section Section describ es the extension of the metho d to con ditional co de and a discussion of variables within lo ops whichwehave found is closely tied to induction variable recognition In Section we present the exp erimental results obtained thus far and we close with future directions and conclusions in Section Background and Other Work Framework Constant propagation op erates on a standard level lattice as shown in Figure Top is the initial state for all symbols When comparing two lattice elementvalues the meet op erator u is applied as given in Table These foundations are standard for many constant propagation metho ds originally intro duced by Kildall Eachsymb ol has its lattice value initialize d to which indicates that it has an as yet undetermined value After analysis is complete all symb ols will have lattice value equal to it cannot b e determined to b e constant a constantvalue or unexecutable co de We note that values can only move down in the lattice due to the meet op erator By initializin g lattice values to an optimistic ven approachistaken which assumes all symb ols can b e determined to b e constantuntil pro otherwise Previous metho ds p erform the analysis as an iterative dataow problem in which iterations continue until a xed p oint is reached We will see in the next section that an alternative demanddriven recursive algorithm oers advantages over the traditional approach u any any u any constant if i j i constant u constant i j otherwise Table Rules for meet u op erator . C iC i + 1C i + 2 . Figure Standard Constant Propagation Lattice S z S z S if P then S if z then S y S y S else S else S y z S y S endif S endif a b Figure Constant propagation with a simple and b conditional constants Previous Metho ds Classication As explained byWegman and Zadeck constant propagation algorithms can b e classied in twoways i using the entire graph or a sparse graph representation and ii detecting simple or conditional constants This naturally creates four classes of algorithms It is clear that propagating information ab out eachsymbol to every no de in a graph is inecient since not all no des contain references or denitions of the symb ol under consideration Sparse repre sentations on the other hand such as defuse or usedef chains Static Single Assignment SSA Dep endence Flow Graphs DFG or Program Dep endence Graphs PDG have all shown the virtue of op erating on a sparse graph for analysis The distinction b etween simple all paths constants and conditional constants can b e seen in Figure The simple value of y is determined to b e constant only if b oth branches whic h merge at S are constant with identical value as is the case in a However if the predicate whichcontrols branching can b e determined to b e constant then only one of the branches will b e executed allowing not only y to b e recognized as constant in b but also identifying the other path to b e dead co de The distinction b etween the four typ es of algorithms is explained well byWegman and Zadeck and the reader is referred to their pap er for more detail We will lo ok at the algo rithm that they present since it incorp orates b oth sparse graph representation and conditional co de The sparse graph employed is the SSA form describ ed in the next subsection Graph Preliminaries The algorithms to convert a program into SSA form are based up on the Control Flow Graph CFG which isagraphG VEEntryExit where V is a set of no des representing basic blo cks in the program E is a set of edges representing sequential control ow in the program and Entry and Exit are no des representing the unique entry p ointinto the program and the unique exit p oint from the program Switch no des have their outgoing edges determined bya predicate After a program has b een converted into SSA form it has twokey prop erties Every use of a variable in the program has exactly one reaching denition and At conuence p oints in the CFG merge functions called functions are intro duced A function for a variable merges the values of the variable from distinct incoming control ow paths in which a denition o ccurs along at least one of these paths and has one argument for eachcontrol ow predecessor The function is itself considered a new denition of the variable For details on SSA graph construction the reader is referred to the pap er by Cytron et al to SSA form is shown in Figure A sample program converted in A Closer Lo ok at One Algorithm The algorithm used byWegman and Zadeck op erates on CFG edges SSA defuse edges are added to the graph once the program has b een transformed into SSA form Their algorithm works bykeeping twoworklists a FlowWorkList and an SSAWorkList Flow edges are initially marked unexecutable Edges are examined from either worklist until empty x x x y y y z z z if P then if P then if P then y y y y y y endif endif endif y y y y P true y false y x y x y x y z y z y z y a b c Figure Program in a normal form b SSA form and c GSA form with those examined from the FlowWorkList b eing marked executable The destination no de for these edges also have their functions evaluated by taking the meet of all the arguments whose corresp onding CFG predecessors are marked executable Expressions are evaluated the rst time a no de is the destination of a ow edge and also when the expression is the target of an SSA edge and at least one incoming ow edge is executable More detail can b e found in the original pap er This algorithm nds all simple constants plus additional constants that can b e discovered when the predicate controlling a switch no de is determined to b e constant The time complexity is prop ortional to the size of the SSA graph and each SSA edge can b e pro cessed at most twice Since functions are reevaluated each time an edge with that no de as a destination is examined Wegman and Zadeck note that expressions which dep end on the value of a function
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages26 Page
-
File Size-