xref: /dragonfly/contrib/gcc-8.0/gcc/df-core.c (revision 38fd1498)
1*38fd1498Szrj /* Allocation for dataflow support routines.
2*38fd1498Szrj    Copyright (C) 1999-2018 Free Software Foundation, Inc.
3*38fd1498Szrj    Originally contributed by Michael P. Hayes
4*38fd1498Szrj              (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5*38fd1498Szrj    Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6*38fd1498Szrj              and Kenneth Zadeck (zadeck@naturalbridge.com).
7*38fd1498Szrj 
8*38fd1498Szrj This file is part of GCC.
9*38fd1498Szrj 
10*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
11*38fd1498Szrj the terms of the GNU General Public License as published by the Free
12*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
13*38fd1498Szrj version.
14*38fd1498Szrj 
15*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
17*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18*38fd1498Szrj for more details.
19*38fd1498Szrj 
20*38fd1498Szrj You should have received a copy of the GNU General Public License
21*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
22*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
23*38fd1498Szrj 
24*38fd1498Szrj /*
25*38fd1498Szrj OVERVIEW:
26*38fd1498Szrj 
27*38fd1498Szrj The files in this collection (df*.c,df.h) provide a general framework
28*38fd1498Szrj for solving dataflow problems.  The global dataflow is performed using
29*38fd1498Szrj a good implementation of iterative dataflow analysis.
30*38fd1498Szrj 
31*38fd1498Szrj The file df-problems.c provides problem instance for the most common
32*38fd1498Szrj dataflow problems: reaching defs, upward exposed uses, live variables,
33*38fd1498Szrj uninitialized variables, def-use chains, and use-def chains.  However,
34*38fd1498Szrj the interface allows other dataflow problems to be defined as well.
35*38fd1498Szrj 
36*38fd1498Szrj Dataflow analysis is available in most of the rtl backend (the parts
37*38fd1498Szrj between pass_df_initialize and pass_df_finish).  It is quite likely
38*38fd1498Szrj that these boundaries will be expanded in the future.  The only
39*38fd1498Szrj requirement is that there be a correct control flow graph.
40*38fd1498Szrj 
41*38fd1498Szrj There are three variations of the live variable problem that are
42*38fd1498Szrj available whenever dataflow is available.  The LR problem finds the
43*38fd1498Szrj areas that can reach a use of a variable, the UR problems finds the
44*38fd1498Szrj areas that can be reached from a definition of a variable.  The LIVE
45*38fd1498Szrj problem finds the intersection of these two areas.
46*38fd1498Szrj 
47*38fd1498Szrj There are several optional problems.  These can be enabled when they
48*38fd1498Szrj are needed and disabled when they are not needed.
49*38fd1498Szrj 
50*38fd1498Szrj Dataflow problems are generally solved in three layers.  The bottom
51*38fd1498Szrj layer is called scanning where a data structure is built for each rtl
52*38fd1498Szrj insn that describes the set of defs and uses of that insn.  Scanning
53*38fd1498Szrj is generally kept up to date, i.e. as the insns changes, the scanned
54*38fd1498Szrj version of that insn changes also.  There are various mechanisms for
55*38fd1498Szrj making this happen and are described in the INCREMENTAL SCANNING
56*38fd1498Szrj section.
57*38fd1498Szrj 
58*38fd1498Szrj In the middle layer, basic blocks are scanned to produce transfer
59*38fd1498Szrj functions which describe the effects of that block on the global
60*38fd1498Szrj dataflow solution.  The transfer functions are only rebuilt if the
61*38fd1498Szrj some instruction within the block has changed.
62*38fd1498Szrj 
63*38fd1498Szrj The top layer is the dataflow solution itself.  The dataflow solution
64*38fd1498Szrj is computed by using an efficient iterative solver and the transfer
65*38fd1498Szrj functions.  The dataflow solution must be recomputed whenever the
66*38fd1498Szrj control changes or if one of the transfer function changes.
67*38fd1498Szrj 
68*38fd1498Szrj 
69*38fd1498Szrj USAGE:
70*38fd1498Szrj 
71*38fd1498Szrj Here is an example of using the dataflow routines.
72*38fd1498Szrj 
73*38fd1498Szrj       df_[chain,live,note,rd]_add_problem (flags);
74*38fd1498Szrj 
75*38fd1498Szrj       df_set_blocks (blocks);
76*38fd1498Szrj 
77*38fd1498Szrj       df_analyze ();
78*38fd1498Szrj 
79*38fd1498Szrj       df_dump (stderr);
80*38fd1498Szrj 
81*38fd1498Szrj       df_finish_pass (false);
82*38fd1498Szrj 
83*38fd1498Szrj DF_[chain,live,note,rd]_ADD_PROBLEM adds a problem, defined by an
84*38fd1498Szrj instance to struct df_problem, to the set of problems solved in this
85*38fd1498Szrj instance of df.  All calls to add a problem for a given instance of df
86*38fd1498Szrj must occur before the first call to DF_ANALYZE.
87*38fd1498Szrj 
88*38fd1498Szrj Problems can be dependent on other problems.  For instance, solving
89*38fd1498Szrj def-use or use-def chains is dependent on solving reaching
90*38fd1498Szrj definitions. As long as these dependencies are listed in the problem
91*38fd1498Szrj definition, the order of adding the problems is not material.
92*38fd1498Szrj Otherwise, the problems will be solved in the order of calls to
93*38fd1498Szrj df_add_problem.  Note that it is not necessary to have a problem.  In
94*38fd1498Szrj that case, df will just be used to do the scanning.
95*38fd1498Szrj 
96*38fd1498Szrj 
97*38fd1498Szrj 
98*38fd1498Szrj DF_SET_BLOCKS is an optional call used to define a region of the
99*38fd1498Szrj function on which the analysis will be performed.  The normal case is
100*38fd1498Szrj to analyze the entire function and no call to df_set_blocks is made.
101*38fd1498Szrj DF_SET_BLOCKS only effects the blocks that are effected when computing
102*38fd1498Szrj the transfer functions and final solution.  The insn level information
103*38fd1498Szrj is always kept up to date.
104*38fd1498Szrj 
105*38fd1498Szrj When a subset is given, the analysis behaves as if the function only
106*38fd1498Szrj contains those blocks and any edges that occur directly between the
107*38fd1498Szrj blocks in the set.  Care should be taken to call df_set_blocks right
108*38fd1498Szrj before the call to analyze in order to eliminate the possibility that
109*38fd1498Szrj optimizations that reorder blocks invalidate the bitvector.
110*38fd1498Szrj 
111*38fd1498Szrj DF_ANALYZE causes all of the defined problems to be (re)solved.  When
112*38fd1498Szrj DF_ANALYZE is completes, the IN and OUT sets for each basic block
113*38fd1498Szrj contain the computer information.  The DF_*_BB_INFO macros can be used
114*38fd1498Szrj to access these bitvectors.  All deferred rescannings are down before
115*38fd1498Szrj the transfer functions are recomputed.
116*38fd1498Szrj 
117*38fd1498Szrj DF_DUMP can then be called to dump the information produce to some
118*38fd1498Szrj file.  This calls DF_DUMP_START, to print the information that is not
119*38fd1498Szrj basic block specific, and then calls DF_DUMP_TOP and DF_DUMP_BOTTOM
120*38fd1498Szrj for each block to print the basic specific information.  These parts
121*38fd1498Szrj can all be called separately as part of a larger dump function.
122*38fd1498Szrj 
123*38fd1498Szrj 
124*38fd1498Szrj DF_FINISH_PASS causes df_remove_problem to be called on all of the
125*38fd1498Szrj optional problems.  It also causes any insns whose scanning has been
126*38fd1498Szrj deferred to be rescanned as well as clears all of the changeable flags.
127*38fd1498Szrj Setting the pass manager TODO_df_finish flag causes this function to
128*38fd1498Szrj be run.  However, the pass manager will call df_finish_pass AFTER the
129*38fd1498Szrj pass dumping has been done, so if you want to see the results of the
130*38fd1498Szrj optional problems in the pass dumps, use the TODO flag rather than
131*38fd1498Szrj calling the function yourself.
132*38fd1498Szrj 
133*38fd1498Szrj INCREMENTAL SCANNING
134*38fd1498Szrj 
135*38fd1498Szrj There are four ways of doing the incremental scanning:
136*38fd1498Szrj 
137*38fd1498Szrj 1) Immediate rescanning - Calls to df_insn_rescan, df_notes_rescan,
138*38fd1498Szrj    df_bb_delete, df_insn_change_bb have been added to most of
139*38fd1498Szrj    the low level service functions that maintain the cfg and change
140*38fd1498Szrj    rtl.  Calling and of these routines many cause some number of insns
141*38fd1498Szrj    to be rescanned.
142*38fd1498Szrj 
143*38fd1498Szrj    For most modern rtl passes, this is certainly the easiest way to
144*38fd1498Szrj    manage rescanning the insns.  This technique also has the advantage
145*38fd1498Szrj    that the scanning information is always correct and can be relied
146*38fd1498Szrj    upon even after changes have been made to the instructions.  This
147*38fd1498Szrj    technique is contra indicated in several cases:
148*38fd1498Szrj 
149*38fd1498Szrj    a) If def-use chains OR use-def chains (but not both) are built,
150*38fd1498Szrj       using this is SIMPLY WRONG.  The problem is that when a ref is
151*38fd1498Szrj       deleted that is the target of an edge, there is not enough
152*38fd1498Szrj       information to efficiently find the source of the edge and
153*38fd1498Szrj       delete the edge.  This leaves a dangling reference that may
154*38fd1498Szrj       cause problems.
155*38fd1498Szrj 
156*38fd1498Szrj    b) If def-use chains AND use-def chains are built, this may
157*38fd1498Szrj       produce unexpected results.  The problem is that the incremental
158*38fd1498Szrj       scanning of an insn does not know how to repair the chains that
159*38fd1498Szrj       point into an insn when the insn changes.  So the incremental
160*38fd1498Szrj       scanning just deletes the chains that enter and exit the insn
161*38fd1498Szrj       being changed.  The dangling reference issue in (a) is not a
162*38fd1498Szrj       problem here, but if the pass is depending on the chains being
163*38fd1498Szrj       maintained after insns have been modified, this technique will
164*38fd1498Szrj       not do the correct thing.
165*38fd1498Szrj 
166*38fd1498Szrj    c) If the pass modifies insns several times, this incremental
167*38fd1498Szrj       updating may be expensive.
168*38fd1498Szrj 
169*38fd1498Szrj    d) If the pass modifies all of the insns, as does register
170*38fd1498Szrj       allocation, it is simply better to rescan the entire function.
171*38fd1498Szrj 
172*38fd1498Szrj 2) Deferred rescanning - Calls to df_insn_rescan, df_notes_rescan, and
173*38fd1498Szrj    df_insn_delete do not immediately change the insn but instead make
174*38fd1498Szrj    a note that the insn needs to be rescanned.  The next call to
175*38fd1498Szrj    df_analyze, df_finish_pass, or df_process_deferred_rescans will
176*38fd1498Szrj    cause all of the pending rescans to be processed.
177*38fd1498Szrj 
178*38fd1498Szrj    This is the technique of choice if either 1a, 1b, or 1c are issues
179*38fd1498Szrj    in the pass.  In the case of 1a or 1b, a call to df_finish_pass
180*38fd1498Szrj    (either manually or via TODO_df_finish) should be made before the
181*38fd1498Szrj    next call to df_analyze or df_process_deferred_rescans.
182*38fd1498Szrj 
183*38fd1498Szrj    This mode is also used by a few passes that still rely on note_uses,
184*38fd1498Szrj    note_stores and rtx iterators instead of using the DF data.  This
185*38fd1498Szrj    can be said to fall under case 1c.
186*38fd1498Szrj 
187*38fd1498Szrj    To enable this mode, call df_set_flags (DF_DEFER_INSN_RESCAN).
188*38fd1498Szrj    (This mode can be cleared by calling df_clear_flags
189*38fd1498Szrj    (DF_DEFER_INSN_RESCAN) but this does not cause the deferred insns to
190*38fd1498Szrj    be rescanned.
191*38fd1498Szrj 
192*38fd1498Szrj 3) Total rescanning - In this mode the rescanning is disabled.
193*38fd1498Szrj    Only when insns are deleted is the df information associated with
194*38fd1498Szrj    it also deleted.  At the end of the pass, a call must be made to
195*38fd1498Szrj    df_insn_rescan_all.  This method is used by the register allocator
196*38fd1498Szrj    since it generally changes each insn multiple times (once for each ref)
197*38fd1498Szrj    and does not need to make use of the updated scanning information.
198*38fd1498Szrj 
199*38fd1498Szrj 4) Do it yourself - In this mechanism, the pass updates the insns
200*38fd1498Szrj    itself using the low level df primitives.  Currently no pass does
201*38fd1498Szrj    this, but it has the advantage that it is quite efficient given
202*38fd1498Szrj    that the pass generally has exact knowledge of what it is changing.
203*38fd1498Szrj 
204*38fd1498Szrj DATA STRUCTURES
205*38fd1498Szrj 
206*38fd1498Szrj Scanning produces a `struct df_ref' data structure (ref) is allocated
207*38fd1498Szrj for every register reference (def or use) and this records the insn
208*38fd1498Szrj and bb the ref is found within.  The refs are linked together in
209*38fd1498Szrj chains of uses and defs for each insn and for each register.  Each ref
210*38fd1498Szrj also has a chain field that links all the use refs for a def or all
211*38fd1498Szrj the def refs for a use.  This is used to create use-def or def-use
212*38fd1498Szrj chains.
213*38fd1498Szrj 
214*38fd1498Szrj Different optimizations have different needs.  Ultimately, only
215*38fd1498Szrj register allocation and schedulers should be using the bitmaps
216*38fd1498Szrj produced for the live register and uninitialized register problems.
217*38fd1498Szrj The rest of the backend should be upgraded to using and maintaining
218*38fd1498Szrj the linked information such as def use or use def chains.
219*38fd1498Szrj 
220*38fd1498Szrj 
221*38fd1498Szrj PHILOSOPHY:
222*38fd1498Szrj 
223*38fd1498Szrj While incremental bitmaps are not worthwhile to maintain, incremental
224*38fd1498Szrj chains may be perfectly reasonable.  The fastest way to build chains
225*38fd1498Szrj from scratch or after significant modifications is to build reaching
226*38fd1498Szrj definitions (RD) and build the chains from this.
227*38fd1498Szrj 
228*38fd1498Szrj However, general algorithms for maintaining use-def or def-use chains
229*38fd1498Szrj are not practical.  The amount of work to recompute the chain any
230*38fd1498Szrj chain after an arbitrary change is large.  However, with a modest
231*38fd1498Szrj amount of work it is generally possible to have the application that
232*38fd1498Szrj uses the chains keep them up to date.  The high level knowledge of
233*38fd1498Szrj what is really happening is essential to crafting efficient
234*38fd1498Szrj incremental algorithms.
235*38fd1498Szrj 
236*38fd1498Szrj As for the bit vector problems, there is no interface to give a set of
237*38fd1498Szrj blocks over with to resolve the iteration.  In general, restarting a
238*38fd1498Szrj dataflow iteration is difficult and expensive.  Again, the best way to
239*38fd1498Szrj keep the dataflow information up to data (if this is really what is
240*38fd1498Szrj needed) it to formulate a problem specific solution.
241*38fd1498Szrj 
242*38fd1498Szrj There are fine grained calls for creating and deleting references from
243*38fd1498Szrj instructions in df-scan.c.  However, these are not currently connected
244*38fd1498Szrj to the engine that resolves the dataflow equations.
245*38fd1498Szrj 
246*38fd1498Szrj 
247*38fd1498Szrj DATA STRUCTURES:
248*38fd1498Szrj 
249*38fd1498Szrj The basic object is a DF_REF (reference) and this may either be a
250*38fd1498Szrj DEF (definition) or a USE of a register.
251*38fd1498Szrj 
252*38fd1498Szrj These are linked into a variety of lists; namely reg-def, reg-use,
253*38fd1498Szrj insn-def, insn-use, def-use, and use-def lists.  For example, the
254*38fd1498Szrj reg-def lists contain all the locations that define a given register
255*38fd1498Szrj while the insn-use lists contain all the locations that use a
256*38fd1498Szrj register.
257*38fd1498Szrj 
258*38fd1498Szrj Note that the reg-def and reg-use chains are generally short for
259*38fd1498Szrj pseudos and long for the hard registers.
260*38fd1498Szrj 
261*38fd1498Szrj ACCESSING INSNS:
262*38fd1498Szrj 
263*38fd1498Szrj 1) The df insn information is kept in an array of DF_INSN_INFO objects.
264*38fd1498Szrj    The array is indexed by insn uid, and every DF_REF points to the
265*38fd1498Szrj    DF_INSN_INFO object of the insn that contains the reference.
266*38fd1498Szrj 
267*38fd1498Szrj 2) Each insn has three sets of refs, which are linked into one of three
268*38fd1498Szrj    lists: The insn's defs list (accessed by the DF_INSN_INFO_DEFS,
269*38fd1498Szrj    DF_INSN_DEFS, or DF_INSN_UID_DEFS macros), the insn's uses list
270*38fd1498Szrj    (accessed by the DF_INSN_INFO_USES, DF_INSN_USES, or
271*38fd1498Szrj    DF_INSN_UID_USES macros) or the insn's eq_uses list (accessed by the
272*38fd1498Szrj    DF_INSN_INFO_EQ_USES, DF_INSN_EQ_USES or DF_INSN_UID_EQ_USES macros).
273*38fd1498Szrj    The latter list are the list of references in REG_EQUAL or REG_EQUIV
274*38fd1498Szrj    notes.  These macros produce a ref (or NULL), the rest of the list
275*38fd1498Szrj    can be obtained by traversal of the NEXT_REF field (accessed by the
276*38fd1498Szrj    DF_REF_NEXT_REF macro.)  There is no significance to the ordering of
277*38fd1498Szrj    the uses or refs in an instruction.
278*38fd1498Szrj 
279*38fd1498Szrj 3) Each insn has a logical uid field (LUID) which is stored in the
280*38fd1498Szrj    DF_INSN_INFO object for the insn.  The LUID field is accessed by
281*38fd1498Szrj    the DF_INSN_INFO_LUID, DF_INSN_LUID, and DF_INSN_UID_LUID macros.
282*38fd1498Szrj    When properly set, the LUID is an integer that numbers each insn in
283*38fd1498Szrj    the basic block, in order from the start of the block.
284*38fd1498Szrj    The numbers are only correct after a call to df_analyze.  They will
285*38fd1498Szrj    rot after insns are added deleted or moved round.
286*38fd1498Szrj 
287*38fd1498Szrj ACCESSING REFS:
288*38fd1498Szrj 
289*38fd1498Szrj There are 4 ways to obtain access to refs:
290*38fd1498Szrj 
291*38fd1498Szrj 1) References are divided into two categories, REAL and ARTIFICIAL.
292*38fd1498Szrj 
293*38fd1498Szrj    REAL refs are associated with instructions.
294*38fd1498Szrj 
295*38fd1498Szrj    ARTIFICIAL refs are associated with basic blocks.  The heads of
296*38fd1498Szrj    these lists can be accessed by calling df_get_artificial_defs or
297*38fd1498Szrj    df_get_artificial_uses for the particular basic block.
298*38fd1498Szrj 
299*38fd1498Szrj    Artificial defs and uses occur both at the beginning and ends of blocks.
300*38fd1498Szrj 
301*38fd1498Szrj      For blocks that area at the destination of eh edges, the
302*38fd1498Szrj      artificial uses and defs occur at the beginning.  The defs relate
303*38fd1498Szrj      to the registers specified in EH_RETURN_DATA_REGNO and the uses
304*38fd1498Szrj      relate to the registers specified in ED_USES.  Logically these
305*38fd1498Szrj      defs and uses should really occur along the eh edge, but there is
306*38fd1498Szrj      no convenient way to do this.  Artificial edges that occur at the
307*38fd1498Szrj      beginning of the block have the DF_REF_AT_TOP flag set.
308*38fd1498Szrj 
309*38fd1498Szrj      Artificial uses occur at the end of all blocks.  These arise from
310*38fd1498Szrj      the hard registers that are always live, such as the stack
311*38fd1498Szrj      register and are put there to keep the code from forgetting about
312*38fd1498Szrj      them.
313*38fd1498Szrj 
314*38fd1498Szrj      Artificial defs occur at the end of the entry block.  These arise
315*38fd1498Szrj      from registers that are live at entry to the function.
316*38fd1498Szrj 
317*38fd1498Szrj 2) There are three types of refs: defs, uses and eq_uses.  (Eq_uses are
318*38fd1498Szrj    uses that appear inside a REG_EQUAL or REG_EQUIV note.)
319*38fd1498Szrj 
320*38fd1498Szrj    All of the eq_uses, uses and defs associated with each pseudo or
321*38fd1498Szrj    hard register may be linked in a bidirectional chain.  These are
322*38fd1498Szrj    called reg-use or reg_def chains.  If the changeable flag
323*38fd1498Szrj    DF_EQ_NOTES is set when the chains are built, the eq_uses will be
324*38fd1498Szrj    treated like uses.  If it is not set they are ignored.
325*38fd1498Szrj 
326*38fd1498Szrj    The first use, eq_use or def for a register can be obtained using
327*38fd1498Szrj    the DF_REG_USE_CHAIN, DF_REG_EQ_USE_CHAIN or DF_REG_DEF_CHAIN
328*38fd1498Szrj    macros.  Subsequent uses for the same regno can be obtained by
329*38fd1498Szrj    following the next_reg field of the ref.  The number of elements in
330*38fd1498Szrj    each of the chains can be found by using the DF_REG_USE_COUNT,
331*38fd1498Szrj    DF_REG_EQ_USE_COUNT or DF_REG_DEF_COUNT macros.
332*38fd1498Szrj 
333*38fd1498Szrj    In previous versions of this code, these chains were ordered.  It
334*38fd1498Szrj    has not been practical to continue this practice.
335*38fd1498Szrj 
336*38fd1498Szrj 3) If def-use or use-def chains are built, these can be traversed to
337*38fd1498Szrj    get to other refs.  If the flag DF_EQ_NOTES has been set, the chains
338*38fd1498Szrj    include the eq_uses.  Otherwise these are ignored when building the
339*38fd1498Szrj    chains.
340*38fd1498Szrj 
341*38fd1498Szrj 4) An array of all of the uses (and an array of all of the defs) can
342*38fd1498Szrj    be built.  These arrays are indexed by the value in the id
343*38fd1498Szrj    structure.  These arrays are only lazily kept up to date, and that
344*38fd1498Szrj    process can be expensive.  To have these arrays built, call
345*38fd1498Szrj    df_reorganize_defs or df_reorganize_uses.  If the flag DF_EQ_NOTES
346*38fd1498Szrj    has been set the array will contain the eq_uses.  Otherwise these
347*38fd1498Szrj    are ignored when building the array and assigning the ids.  Note
348*38fd1498Szrj    that the values in the id field of a ref may change across calls to
349*38fd1498Szrj    df_analyze or df_reorganize_defs or df_reorganize_uses.
350*38fd1498Szrj 
351*38fd1498Szrj    If the only use of this array is to find all of the refs, it is
352*38fd1498Szrj    better to traverse all of the registers and then traverse all of
353*38fd1498Szrj    reg-use or reg-def chains.
354*38fd1498Szrj 
355*38fd1498Szrj NOTES:
356*38fd1498Szrj 
357*38fd1498Szrj Embedded addressing side-effects, such as POST_INC or PRE_INC, generate
358*38fd1498Szrj both a use and a def.  These are both marked read/write to show that they
359*38fd1498Szrj are dependent. For example, (set (reg 40) (mem (post_inc (reg 42))))
360*38fd1498Szrj will generate a use of reg 42 followed by a def of reg 42 (both marked
361*38fd1498Szrj read/write).  Similarly, (set (reg 40) (mem (pre_dec (reg 41))))
362*38fd1498Szrj generates a use of reg 41 then a def of reg 41 (both marked read/write),
363*38fd1498Szrj even though reg 41 is decremented before it is used for the memory
364*38fd1498Szrj address in this second example.
365*38fd1498Szrj 
366*38fd1498Szrj A set to a REG inside a ZERO_EXTRACT, or a set to a non-paradoxical SUBREG
367*38fd1498Szrj for which the number of word_mode units covered by the outer mode is
368*38fd1498Szrj smaller than that covered by the inner mode, invokes a read-modify-write
369*38fd1498Szrj operation.  We generate both a use and a def and again mark them
370*38fd1498Szrj read/write.
371*38fd1498Szrj 
372*38fd1498Szrj Paradoxical subreg writes do not leave a trace of the old content, so they
373*38fd1498Szrj are write-only operations.
374*38fd1498Szrj */
375*38fd1498Szrj 
376*38fd1498Szrj 
377*38fd1498Szrj #include "config.h"
378*38fd1498Szrj #include "system.h"
379*38fd1498Szrj #include "coretypes.h"
380*38fd1498Szrj #include "backend.h"
381*38fd1498Szrj #include "rtl.h"
382*38fd1498Szrj #include "df.h"
383*38fd1498Szrj #include "memmodel.h"
384*38fd1498Szrj #include "emit-rtl.h"
385*38fd1498Szrj #include "cfganal.h"
386*38fd1498Szrj #include "tree-pass.h"
387*38fd1498Szrj #include "cfgloop.h"
388*38fd1498Szrj 
389*38fd1498Szrj static void *df_get_bb_info (struct dataflow *, unsigned int);
390*38fd1498Szrj static void df_set_bb_info (struct dataflow *, unsigned int, void *);
391*38fd1498Szrj static void df_clear_bb_info (struct dataflow *, unsigned int);
392*38fd1498Szrj #ifdef DF_DEBUG_CFG
393*38fd1498Szrj static void df_set_clean_cfg (void);
394*38fd1498Szrj #endif
395*38fd1498Szrj 
396*38fd1498Szrj /* The obstack on which regsets are allocated.  */
397*38fd1498Szrj struct bitmap_obstack reg_obstack;
398*38fd1498Szrj 
399*38fd1498Szrj /* An obstack for bitmap not related to specific dataflow problems.
400*38fd1498Szrj    This obstack should e.g. be used for bitmaps with a short life time
401*38fd1498Szrj    such as temporary bitmaps.  */
402*38fd1498Szrj 
403*38fd1498Szrj bitmap_obstack df_bitmap_obstack;
404*38fd1498Szrj 
405*38fd1498Szrj 
406*38fd1498Szrj /*----------------------------------------------------------------------------
407*38fd1498Szrj   Functions to create, destroy and manipulate an instance of df.
408*38fd1498Szrj ----------------------------------------------------------------------------*/
409*38fd1498Szrj 
410*38fd1498Szrj struct df_d *df;
411*38fd1498Szrj 
412*38fd1498Szrj /* Add PROBLEM (and any dependent problems) to the DF instance.  */
413*38fd1498Szrj 
414*38fd1498Szrj void
df_add_problem(const struct df_problem * problem)415*38fd1498Szrj df_add_problem (const struct df_problem *problem)
416*38fd1498Szrj {
417*38fd1498Szrj   struct dataflow *dflow;
418*38fd1498Szrj   int i;
419*38fd1498Szrj 
420*38fd1498Szrj   /* First try to add the dependent problem. */
421*38fd1498Szrj   if (problem->dependent_problem)
422*38fd1498Szrj     df_add_problem (problem->dependent_problem);
423*38fd1498Szrj 
424*38fd1498Szrj   /* Check to see if this problem has already been defined.  If it
425*38fd1498Szrj      has, just return that instance, if not, add it to the end of the
426*38fd1498Szrj      vector.  */
427*38fd1498Szrj   dflow = df->problems_by_index[problem->id];
428*38fd1498Szrj   if (dflow)
429*38fd1498Szrj     return;
430*38fd1498Szrj 
431*38fd1498Szrj   /* Make a new one and add it to the end.  */
432*38fd1498Szrj   dflow = XCNEW (struct dataflow);
433*38fd1498Szrj   dflow->problem = problem;
434*38fd1498Szrj   dflow->computed = false;
435*38fd1498Szrj   dflow->solutions_dirty = true;
436*38fd1498Szrj   df->problems_by_index[dflow->problem->id] = dflow;
437*38fd1498Szrj 
438*38fd1498Szrj   /* Keep the defined problems ordered by index.  This solves the
439*38fd1498Szrj      problem that RI will use the information from UREC if UREC has
440*38fd1498Szrj      been defined, or from LIVE if LIVE is defined and otherwise LR.
441*38fd1498Szrj      However for this to work, the computation of RI must be pushed
442*38fd1498Szrj      after which ever of those problems is defined, but we do not
443*38fd1498Szrj      require any of those except for LR to have actually been
444*38fd1498Szrj      defined.  */
445*38fd1498Szrj   df->num_problems_defined++;
446*38fd1498Szrj   for (i = df->num_problems_defined - 2; i >= 0; i--)
447*38fd1498Szrj     {
448*38fd1498Szrj       if (problem->id < df->problems_in_order[i]->problem->id)
449*38fd1498Szrj 	df->problems_in_order[i+1] = df->problems_in_order[i];
450*38fd1498Szrj       else
451*38fd1498Szrj 	{
452*38fd1498Szrj 	  df->problems_in_order[i+1] = dflow;
453*38fd1498Szrj 	  return;
454*38fd1498Szrj 	}
455*38fd1498Szrj     }
456*38fd1498Szrj   df->problems_in_order[0] = dflow;
457*38fd1498Szrj }
458*38fd1498Szrj 
459*38fd1498Szrj 
460*38fd1498Szrj /* Set the MASK flags in the DFLOW problem.  The old flags are
461*38fd1498Szrj    returned.  If a flag is not allowed to be changed this will fail if
462*38fd1498Szrj    checking is enabled.  */
463*38fd1498Szrj int
df_set_flags(int changeable_flags)464*38fd1498Szrj df_set_flags (int changeable_flags)
465*38fd1498Szrj {
466*38fd1498Szrj   int old_flags = df->changeable_flags;
467*38fd1498Szrj   df->changeable_flags |= changeable_flags;
468*38fd1498Szrj   return old_flags;
469*38fd1498Szrj }
470*38fd1498Szrj 
471*38fd1498Szrj 
472*38fd1498Szrj /* Clear the MASK flags in the DFLOW problem.  The old flags are
473*38fd1498Szrj    returned.  If a flag is not allowed to be changed this will fail if
474*38fd1498Szrj    checking is enabled.  */
475*38fd1498Szrj int
df_clear_flags(int changeable_flags)476*38fd1498Szrj df_clear_flags (int changeable_flags)
477*38fd1498Szrj {
478*38fd1498Szrj   int old_flags = df->changeable_flags;
479*38fd1498Szrj   df->changeable_flags &= ~changeable_flags;
480*38fd1498Szrj   return old_flags;
481*38fd1498Szrj }
482*38fd1498Szrj 
483*38fd1498Szrj 
484*38fd1498Szrj /* Set the blocks that are to be considered for analysis.  If this is
485*38fd1498Szrj    not called or is called with null, the entire function in
486*38fd1498Szrj    analyzed.  */
487*38fd1498Szrj 
488*38fd1498Szrj void
df_set_blocks(bitmap blocks)489*38fd1498Szrj df_set_blocks (bitmap blocks)
490*38fd1498Szrj {
491*38fd1498Szrj   if (blocks)
492*38fd1498Szrj     {
493*38fd1498Szrj       if (dump_file)
494*38fd1498Szrj 	bitmap_print (dump_file, blocks, "setting blocks to analyze ", "\n");
495*38fd1498Szrj       if (df->blocks_to_analyze)
496*38fd1498Szrj 	{
497*38fd1498Szrj 	  /* This block is called to change the focus from one subset
498*38fd1498Szrj 	     to another.  */
499*38fd1498Szrj 	  int p;
500*38fd1498Szrj 	  auto_bitmap diff (&df_bitmap_obstack);
501*38fd1498Szrj 	  bitmap_and_compl (diff, df->blocks_to_analyze, blocks);
502*38fd1498Szrj 	  for (p = 0; p < df->num_problems_defined; p++)
503*38fd1498Szrj 	    {
504*38fd1498Szrj 	      struct dataflow *dflow = df->problems_in_order[p];
505*38fd1498Szrj 	      if (dflow->optional_p && dflow->problem->reset_fun)
506*38fd1498Szrj 		dflow->problem->reset_fun (df->blocks_to_analyze);
507*38fd1498Szrj 	      else if (dflow->problem->free_blocks_on_set_blocks)
508*38fd1498Szrj 		{
509*38fd1498Szrj 		  bitmap_iterator bi;
510*38fd1498Szrj 		  unsigned int bb_index;
511*38fd1498Szrj 
512*38fd1498Szrj 		  EXECUTE_IF_SET_IN_BITMAP (diff, 0, bb_index, bi)
513*38fd1498Szrj 		    {
514*38fd1498Szrj 		      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
515*38fd1498Szrj 		      if (bb)
516*38fd1498Szrj 			{
517*38fd1498Szrj 			  void *bb_info = df_get_bb_info (dflow, bb_index);
518*38fd1498Szrj 			  dflow->problem->free_bb_fun (bb, bb_info);
519*38fd1498Szrj 			  df_clear_bb_info (dflow, bb_index);
520*38fd1498Szrj 			}
521*38fd1498Szrj 		    }
522*38fd1498Szrj 		}
523*38fd1498Szrj 	    }
524*38fd1498Szrj 	}
525*38fd1498Szrj       else
526*38fd1498Szrj 	{
527*38fd1498Szrj 	  /* This block of code is executed to change the focus from
528*38fd1498Szrj 	     the entire function to a subset.  */
529*38fd1498Szrj 	  bitmap_head blocks_to_reset;
530*38fd1498Szrj 	  bool initialized = false;
531*38fd1498Szrj 	  int p;
532*38fd1498Szrj 	  for (p = 0; p < df->num_problems_defined; p++)
533*38fd1498Szrj 	    {
534*38fd1498Szrj 	      struct dataflow *dflow = df->problems_in_order[p];
535*38fd1498Szrj 	      if (dflow->optional_p && dflow->problem->reset_fun)
536*38fd1498Szrj 		{
537*38fd1498Szrj 		  if (!initialized)
538*38fd1498Szrj 		    {
539*38fd1498Szrj 		      basic_block bb;
540*38fd1498Szrj 		      bitmap_initialize (&blocks_to_reset, &df_bitmap_obstack);
541*38fd1498Szrj 		      FOR_ALL_BB_FN (bb, cfun)
542*38fd1498Szrj 			{
543*38fd1498Szrj 			  bitmap_set_bit (&blocks_to_reset, bb->index);
544*38fd1498Szrj 			}
545*38fd1498Szrj 		    }
546*38fd1498Szrj 		  dflow->problem->reset_fun (&blocks_to_reset);
547*38fd1498Szrj 		}
548*38fd1498Szrj 	    }
549*38fd1498Szrj 	  if (initialized)
550*38fd1498Szrj 	    bitmap_clear (&blocks_to_reset);
551*38fd1498Szrj 
552*38fd1498Szrj 	  df->blocks_to_analyze = BITMAP_ALLOC (&df_bitmap_obstack);
553*38fd1498Szrj 	}
554*38fd1498Szrj       bitmap_copy (df->blocks_to_analyze, blocks);
555*38fd1498Szrj       df->analyze_subset = true;
556*38fd1498Szrj     }
557*38fd1498Szrj   else
558*38fd1498Szrj     {
559*38fd1498Szrj       /* This block is executed to reset the focus to the entire
560*38fd1498Szrj 	 function.  */
561*38fd1498Szrj       if (dump_file)
562*38fd1498Szrj 	fprintf (dump_file, "clearing blocks_to_analyze\n");
563*38fd1498Szrj       if (df->blocks_to_analyze)
564*38fd1498Szrj 	{
565*38fd1498Szrj 	  BITMAP_FREE (df->blocks_to_analyze);
566*38fd1498Szrj 	  df->blocks_to_analyze = NULL;
567*38fd1498Szrj 	}
568*38fd1498Szrj       df->analyze_subset = false;
569*38fd1498Szrj     }
570*38fd1498Szrj 
571*38fd1498Szrj   /* Setting the blocks causes the refs to be unorganized since only
572*38fd1498Szrj      the refs in the blocks are seen.  */
573*38fd1498Szrj   df_maybe_reorganize_def_refs (DF_REF_ORDER_NO_TABLE);
574*38fd1498Szrj   df_maybe_reorganize_use_refs (DF_REF_ORDER_NO_TABLE);
575*38fd1498Szrj   df_mark_solutions_dirty ();
576*38fd1498Szrj }
577*38fd1498Szrj 
578*38fd1498Szrj 
579*38fd1498Szrj /* Delete a DFLOW problem (and any problems that depend on this
580*38fd1498Szrj    problem).  */
581*38fd1498Szrj 
582*38fd1498Szrj void
df_remove_problem(struct dataflow * dflow)583*38fd1498Szrj df_remove_problem (struct dataflow *dflow)
584*38fd1498Szrj {
585*38fd1498Szrj   const struct df_problem *problem;
586*38fd1498Szrj   int i;
587*38fd1498Szrj 
588*38fd1498Szrj   if (!dflow)
589*38fd1498Szrj     return;
590*38fd1498Szrj 
591*38fd1498Szrj   problem = dflow->problem;
592*38fd1498Szrj   gcc_assert (problem->remove_problem_fun);
593*38fd1498Szrj 
594*38fd1498Szrj   /* Delete any problems that depended on this problem first.  */
595*38fd1498Szrj   for (i = 0; i < df->num_problems_defined; i++)
596*38fd1498Szrj     if (df->problems_in_order[i]->problem->dependent_problem == problem)
597*38fd1498Szrj       df_remove_problem (df->problems_in_order[i]);
598*38fd1498Szrj 
599*38fd1498Szrj   /* Now remove this problem.  */
600*38fd1498Szrj   for (i = 0; i < df->num_problems_defined; i++)
601*38fd1498Szrj     if (df->problems_in_order[i] == dflow)
602*38fd1498Szrj       {
603*38fd1498Szrj 	int j;
604*38fd1498Szrj 	for (j = i + 1; j < df->num_problems_defined; j++)
605*38fd1498Szrj 	  df->problems_in_order[j-1] = df->problems_in_order[j];
606*38fd1498Szrj 	df->problems_in_order[j-1] = NULL;
607*38fd1498Szrj 	df->num_problems_defined--;
608*38fd1498Szrj 	break;
609*38fd1498Szrj       }
610*38fd1498Szrj 
611*38fd1498Szrj   (problem->remove_problem_fun) ();
612*38fd1498Szrj   df->problems_by_index[problem->id] = NULL;
613*38fd1498Szrj }
614*38fd1498Szrj 
615*38fd1498Szrj 
616*38fd1498Szrj /* Remove all of the problems that are not permanent.  Scanning, LR
617*38fd1498Szrj    and (at -O2 or higher) LIVE are permanent, the rest are removable.
618*38fd1498Szrj    Also clear all of the changeable_flags.  */
619*38fd1498Szrj 
620*38fd1498Szrj void
df_finish_pass(bool verify ATTRIBUTE_UNUSED)621*38fd1498Szrj df_finish_pass (bool verify ATTRIBUTE_UNUSED)
622*38fd1498Szrj {
623*38fd1498Szrj   int i;
624*38fd1498Szrj 
625*38fd1498Szrj #ifdef ENABLE_DF_CHECKING
626*38fd1498Szrj   int saved_flags;
627*38fd1498Szrj #endif
628*38fd1498Szrj 
629*38fd1498Szrj   if (!df)
630*38fd1498Szrj     return;
631*38fd1498Szrj 
632*38fd1498Szrj   df_maybe_reorganize_def_refs (DF_REF_ORDER_NO_TABLE);
633*38fd1498Szrj   df_maybe_reorganize_use_refs (DF_REF_ORDER_NO_TABLE);
634*38fd1498Szrj 
635*38fd1498Szrj #ifdef ENABLE_DF_CHECKING
636*38fd1498Szrj   saved_flags = df->changeable_flags;
637*38fd1498Szrj #endif
638*38fd1498Szrj 
639*38fd1498Szrj   /* We iterate over problems by index as each problem removed will
640*38fd1498Szrj      lead to problems_in_order to be reordered.  */
641*38fd1498Szrj   for (i = 0; i < DF_LAST_PROBLEM_PLUS1; i++)
642*38fd1498Szrj     {
643*38fd1498Szrj       struct dataflow *dflow = df->problems_by_index[i];
644*38fd1498Szrj 
645*38fd1498Szrj       if (dflow && dflow->optional_p)
646*38fd1498Szrj 	df_remove_problem (dflow);
647*38fd1498Szrj     }
648*38fd1498Szrj 
649*38fd1498Szrj   /* Clear all of the flags.  */
650*38fd1498Szrj   df->changeable_flags = 0;
651*38fd1498Szrj   df_process_deferred_rescans ();
652*38fd1498Szrj 
653*38fd1498Szrj   /* Set the focus back to the whole function.  */
654*38fd1498Szrj   if (df->blocks_to_analyze)
655*38fd1498Szrj     {
656*38fd1498Szrj       BITMAP_FREE (df->blocks_to_analyze);
657*38fd1498Szrj       df->blocks_to_analyze = NULL;
658*38fd1498Szrj       df_mark_solutions_dirty ();
659*38fd1498Szrj       df->analyze_subset = false;
660*38fd1498Szrj     }
661*38fd1498Szrj 
662*38fd1498Szrj #ifdef ENABLE_DF_CHECKING
663*38fd1498Szrj   /* Verification will fail in DF_NO_INSN_RESCAN.  */
664*38fd1498Szrj   if (!(saved_flags & DF_NO_INSN_RESCAN))
665*38fd1498Szrj     {
666*38fd1498Szrj       df_lr_verify_transfer_functions ();
667*38fd1498Szrj       if (df_live)
668*38fd1498Szrj 	df_live_verify_transfer_functions ();
669*38fd1498Szrj     }
670*38fd1498Szrj 
671*38fd1498Szrj #ifdef DF_DEBUG_CFG
672*38fd1498Szrj   df_set_clean_cfg ();
673*38fd1498Szrj #endif
674*38fd1498Szrj #endif
675*38fd1498Szrj 
676*38fd1498Szrj   if (flag_checking && verify)
677*38fd1498Szrj     df->changeable_flags |= DF_VERIFY_SCHEDULED;
678*38fd1498Szrj }
679*38fd1498Szrj 
680*38fd1498Szrj 
681*38fd1498Szrj /* Set up the dataflow instance for the entire back end.  */
682*38fd1498Szrj 
683*38fd1498Szrj static unsigned int
rest_of_handle_df_initialize(void)684*38fd1498Szrj rest_of_handle_df_initialize (void)
685*38fd1498Szrj {
686*38fd1498Szrj   gcc_assert (!df);
687*38fd1498Szrj   df = XCNEW (struct df_d);
688*38fd1498Szrj   df->changeable_flags = 0;
689*38fd1498Szrj 
690*38fd1498Szrj   bitmap_obstack_initialize (&df_bitmap_obstack);
691*38fd1498Szrj 
692*38fd1498Szrj   /* Set this to a conservative value.  Stack_ptr_mod will compute it
693*38fd1498Szrj      correctly later.  */
694*38fd1498Szrj   crtl->sp_is_unchanging = 0;
695*38fd1498Szrj 
696*38fd1498Szrj   df_scan_add_problem ();
697*38fd1498Szrj   df_scan_alloc (NULL);
698*38fd1498Szrj 
699*38fd1498Szrj   /* These three problems are permanent.  */
700*38fd1498Szrj   df_lr_add_problem ();
701*38fd1498Szrj   if (optimize > 1)
702*38fd1498Szrj     df_live_add_problem ();
703*38fd1498Szrj 
704*38fd1498Szrj   df->postorder = XNEWVEC (int, last_basic_block_for_fn (cfun));
705*38fd1498Szrj   df->n_blocks = post_order_compute (df->postorder, true, true);
706*38fd1498Szrj   inverted_post_order_compute (&df->postorder_inverted);
707*38fd1498Szrj   gcc_assert ((unsigned) df->n_blocks == df->postorder_inverted.length ());
708*38fd1498Szrj 
709*38fd1498Szrj   df->hard_regs_live_count = XCNEWVEC (unsigned int, FIRST_PSEUDO_REGISTER);
710*38fd1498Szrj 
711*38fd1498Szrj   df_hard_reg_init ();
712*38fd1498Szrj   /* After reload, some ports add certain bits to regs_ever_live so
713*38fd1498Szrj      this cannot be reset.  */
714*38fd1498Szrj   df_compute_regs_ever_live (true);
715*38fd1498Szrj   df_scan_blocks ();
716*38fd1498Szrj   df_compute_regs_ever_live (false);
717*38fd1498Szrj   return 0;
718*38fd1498Szrj }
719*38fd1498Szrj 
720*38fd1498Szrj 
721*38fd1498Szrj namespace {
722*38fd1498Szrj 
723*38fd1498Szrj const pass_data pass_data_df_initialize_opt =
724*38fd1498Szrj {
725*38fd1498Szrj   RTL_PASS, /* type */
726*38fd1498Szrj   "dfinit", /* name */
727*38fd1498Szrj   OPTGROUP_NONE, /* optinfo_flags */
728*38fd1498Szrj   TV_DF_SCAN, /* tv_id */
729*38fd1498Szrj   0, /* properties_required */
730*38fd1498Szrj   0, /* properties_provided */
731*38fd1498Szrj   0, /* properties_destroyed */
732*38fd1498Szrj   0, /* todo_flags_start */
733*38fd1498Szrj   0, /* todo_flags_finish */
734*38fd1498Szrj };
735*38fd1498Szrj 
736*38fd1498Szrj class pass_df_initialize_opt : public rtl_opt_pass
737*38fd1498Szrj {
738*38fd1498Szrj public:
pass_df_initialize_opt(gcc::context * ctxt)739*38fd1498Szrj   pass_df_initialize_opt (gcc::context *ctxt)
740*38fd1498Szrj     : rtl_opt_pass (pass_data_df_initialize_opt, ctxt)
741*38fd1498Szrj   {}
742*38fd1498Szrj 
743*38fd1498Szrj   /* opt_pass methods: */
gate(function *)744*38fd1498Szrj   virtual bool gate (function *) { return optimize > 0; }
execute(function *)745*38fd1498Szrj   virtual unsigned int execute (function *)
746*38fd1498Szrj     {
747*38fd1498Szrj       return rest_of_handle_df_initialize ();
748*38fd1498Szrj     }
749*38fd1498Szrj 
750*38fd1498Szrj }; // class pass_df_initialize_opt
751*38fd1498Szrj 
752*38fd1498Szrj } // anon namespace
753*38fd1498Szrj 
754*38fd1498Szrj rtl_opt_pass *
make_pass_df_initialize_opt(gcc::context * ctxt)755*38fd1498Szrj make_pass_df_initialize_opt (gcc::context *ctxt)
756*38fd1498Szrj {
757*38fd1498Szrj   return new pass_df_initialize_opt (ctxt);
758*38fd1498Szrj }
759*38fd1498Szrj 
760*38fd1498Szrj 
761*38fd1498Szrj namespace {
762*38fd1498Szrj 
763*38fd1498Szrj const pass_data pass_data_df_initialize_no_opt =
764*38fd1498Szrj {
765*38fd1498Szrj   RTL_PASS, /* type */
766*38fd1498Szrj   "no-opt dfinit", /* name */
767*38fd1498Szrj   OPTGROUP_NONE, /* optinfo_flags */
768*38fd1498Szrj   TV_DF_SCAN, /* tv_id */
769*38fd1498Szrj   0, /* properties_required */
770*38fd1498Szrj   0, /* properties_provided */
771*38fd1498Szrj   0, /* properties_destroyed */
772*38fd1498Szrj   0, /* todo_flags_start */
773*38fd1498Szrj   0, /* todo_flags_finish */
774*38fd1498Szrj };
775*38fd1498Szrj 
776*38fd1498Szrj class pass_df_initialize_no_opt : public rtl_opt_pass
777*38fd1498Szrj {
778*38fd1498Szrj public:
pass_df_initialize_no_opt(gcc::context * ctxt)779*38fd1498Szrj   pass_df_initialize_no_opt (gcc::context *ctxt)
780*38fd1498Szrj     : rtl_opt_pass (pass_data_df_initialize_no_opt, ctxt)
781*38fd1498Szrj   {}
782*38fd1498Szrj 
783*38fd1498Szrj   /* opt_pass methods: */
gate(function *)784*38fd1498Szrj   virtual bool gate (function *) { return optimize == 0; }
execute(function *)785*38fd1498Szrj   virtual unsigned int execute (function *)
786*38fd1498Szrj     {
787*38fd1498Szrj       return rest_of_handle_df_initialize ();
788*38fd1498Szrj     }
789*38fd1498Szrj 
790*38fd1498Szrj }; // class pass_df_initialize_no_opt
791*38fd1498Szrj 
792*38fd1498Szrj } // anon namespace
793*38fd1498Szrj 
794*38fd1498Szrj rtl_opt_pass *
make_pass_df_initialize_no_opt(gcc::context * ctxt)795*38fd1498Szrj make_pass_df_initialize_no_opt (gcc::context *ctxt)
796*38fd1498Szrj {
797*38fd1498Szrj   return new pass_df_initialize_no_opt (ctxt);
798*38fd1498Szrj }
799*38fd1498Szrj 
800*38fd1498Szrj 
801*38fd1498Szrj /* Free all the dataflow info and the DF structure.  This should be
802*38fd1498Szrj    called from the df_finish macro which also NULLs the parm.  */
803*38fd1498Szrj 
804*38fd1498Szrj static unsigned int
rest_of_handle_df_finish(void)805*38fd1498Szrj rest_of_handle_df_finish (void)
806*38fd1498Szrj {
807*38fd1498Szrj   int i;
808*38fd1498Szrj 
809*38fd1498Szrj   gcc_assert (df);
810*38fd1498Szrj 
811*38fd1498Szrj   for (i = 0; i < df->num_problems_defined; i++)
812*38fd1498Szrj     {
813*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[i];
814*38fd1498Szrj       dflow->problem->free_fun ();
815*38fd1498Szrj     }
816*38fd1498Szrj 
817*38fd1498Szrj   free (df->postorder);
818*38fd1498Szrj   df->postorder_inverted.release ();
819*38fd1498Szrj   free (df->hard_regs_live_count);
820*38fd1498Szrj   free (df);
821*38fd1498Szrj   df = NULL;
822*38fd1498Szrj 
823*38fd1498Szrj   bitmap_obstack_release (&df_bitmap_obstack);
824*38fd1498Szrj   return 0;
825*38fd1498Szrj }
826*38fd1498Szrj 
827*38fd1498Szrj 
828*38fd1498Szrj namespace {
829*38fd1498Szrj 
830*38fd1498Szrj const pass_data pass_data_df_finish =
831*38fd1498Szrj {
832*38fd1498Szrj   RTL_PASS, /* type */
833*38fd1498Szrj   "dfinish", /* name */
834*38fd1498Szrj   OPTGROUP_NONE, /* optinfo_flags */
835*38fd1498Szrj   TV_NONE, /* tv_id */
836*38fd1498Szrj   0, /* properties_required */
837*38fd1498Szrj   0, /* properties_provided */
838*38fd1498Szrj   0, /* properties_destroyed */
839*38fd1498Szrj   0, /* todo_flags_start */
840*38fd1498Szrj   0, /* todo_flags_finish */
841*38fd1498Szrj };
842*38fd1498Szrj 
843*38fd1498Szrj class pass_df_finish : public rtl_opt_pass
844*38fd1498Szrj {
845*38fd1498Szrj public:
pass_df_finish(gcc::context * ctxt)846*38fd1498Szrj   pass_df_finish (gcc::context *ctxt)
847*38fd1498Szrj     : rtl_opt_pass (pass_data_df_finish, ctxt)
848*38fd1498Szrj   {}
849*38fd1498Szrj 
850*38fd1498Szrj   /* opt_pass methods: */
execute(function *)851*38fd1498Szrj   virtual unsigned int execute (function *)
852*38fd1498Szrj     {
853*38fd1498Szrj       return rest_of_handle_df_finish ();
854*38fd1498Szrj     }
855*38fd1498Szrj 
856*38fd1498Szrj }; // class pass_df_finish
857*38fd1498Szrj 
858*38fd1498Szrj } // anon namespace
859*38fd1498Szrj 
860*38fd1498Szrj rtl_opt_pass *
make_pass_df_finish(gcc::context * ctxt)861*38fd1498Szrj make_pass_df_finish (gcc::context *ctxt)
862*38fd1498Szrj {
863*38fd1498Szrj   return new pass_df_finish (ctxt);
864*38fd1498Szrj }
865*38fd1498Szrj 
866*38fd1498Szrj 
867*38fd1498Szrj 
868*38fd1498Szrj 
869*38fd1498Szrj 
870*38fd1498Szrj /*----------------------------------------------------------------------------
871*38fd1498Szrj    The general data flow analysis engine.
872*38fd1498Szrj ----------------------------------------------------------------------------*/
873*38fd1498Szrj 
874*38fd1498Szrj /* Return time BB when it was visited for last time.  */
875*38fd1498Szrj #define BB_LAST_CHANGE_AGE(bb) ((ptrdiff_t)(bb)->aux)
876*38fd1498Szrj 
877*38fd1498Szrj /* Helper function for df_worklist_dataflow.
878*38fd1498Szrj    Propagate the dataflow forward.
879*38fd1498Szrj    Given a BB_INDEX, do the dataflow propagation
880*38fd1498Szrj    and set bits on for successors in PENDING
881*38fd1498Szrj    if the out set of the dataflow has changed.
882*38fd1498Szrj 
883*38fd1498Szrj    AGE specify time when BB was visited last time.
884*38fd1498Szrj    AGE of 0 means we are visiting for first time and need to
885*38fd1498Szrj    compute transfer function to initialize datastructures.
886*38fd1498Szrj    Otherwise we re-do transfer function only if something change
887*38fd1498Szrj    while computing confluence functions.
888*38fd1498Szrj    We need to compute confluence only of basic block that are younger
889*38fd1498Szrj    then last visit of the BB.
890*38fd1498Szrj 
891*38fd1498Szrj    Return true if BB info has changed.  This is always the case
892*38fd1498Szrj    in the first visit.  */
893*38fd1498Szrj 
894*38fd1498Szrj static bool
df_worklist_propagate_forward(struct dataflow * dataflow,unsigned bb_index,unsigned * bbindex_to_postorder,bitmap pending,sbitmap considered,ptrdiff_t age)895*38fd1498Szrj df_worklist_propagate_forward (struct dataflow *dataflow,
896*38fd1498Szrj                                unsigned bb_index,
897*38fd1498Szrj                                unsigned *bbindex_to_postorder,
898*38fd1498Szrj                                bitmap pending,
899*38fd1498Szrj                                sbitmap considered,
900*38fd1498Szrj 			       ptrdiff_t age)
901*38fd1498Szrj {
902*38fd1498Szrj   edge e;
903*38fd1498Szrj   edge_iterator ei;
904*38fd1498Szrj   basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
905*38fd1498Szrj   bool changed = !age;
906*38fd1498Szrj 
907*38fd1498Szrj   /*  Calculate <conf_op> of incoming edges.  */
908*38fd1498Szrj   if (EDGE_COUNT (bb->preds) > 0)
909*38fd1498Szrj     FOR_EACH_EDGE (e, ei, bb->preds)
910*38fd1498Szrj       {
911*38fd1498Szrj         if (age <= BB_LAST_CHANGE_AGE (e->src)
912*38fd1498Szrj 	    && bitmap_bit_p (considered, e->src->index))
913*38fd1498Szrj           changed |= dataflow->problem->con_fun_n (e);
914*38fd1498Szrj       }
915*38fd1498Szrj   else if (dataflow->problem->con_fun_0)
916*38fd1498Szrj     dataflow->problem->con_fun_0 (bb);
917*38fd1498Szrj 
918*38fd1498Szrj   if (changed
919*38fd1498Szrj       && dataflow->problem->trans_fun (bb_index))
920*38fd1498Szrj     {
921*38fd1498Szrj       /* The out set of this block has changed.
922*38fd1498Szrj          Propagate to the outgoing blocks.  */
923*38fd1498Szrj       FOR_EACH_EDGE (e, ei, bb->succs)
924*38fd1498Szrj         {
925*38fd1498Szrj           unsigned ob_index = e->dest->index;
926*38fd1498Szrj 
927*38fd1498Szrj           if (bitmap_bit_p (considered, ob_index))
928*38fd1498Szrj             bitmap_set_bit (pending, bbindex_to_postorder[ob_index]);
929*38fd1498Szrj         }
930*38fd1498Szrj       return true;
931*38fd1498Szrj     }
932*38fd1498Szrj   return false;
933*38fd1498Szrj }
934*38fd1498Szrj 
935*38fd1498Szrj 
936*38fd1498Szrj /* Helper function for df_worklist_dataflow.
937*38fd1498Szrj    Propagate the dataflow backward.  */
938*38fd1498Szrj 
939*38fd1498Szrj static bool
df_worklist_propagate_backward(struct dataflow * dataflow,unsigned bb_index,unsigned * bbindex_to_postorder,bitmap pending,sbitmap considered,ptrdiff_t age)940*38fd1498Szrj df_worklist_propagate_backward (struct dataflow *dataflow,
941*38fd1498Szrj                                 unsigned bb_index,
942*38fd1498Szrj                                 unsigned *bbindex_to_postorder,
943*38fd1498Szrj                                 bitmap pending,
944*38fd1498Szrj                                 sbitmap considered,
945*38fd1498Szrj 			        ptrdiff_t age)
946*38fd1498Szrj {
947*38fd1498Szrj   edge e;
948*38fd1498Szrj   edge_iterator ei;
949*38fd1498Szrj   basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
950*38fd1498Szrj   bool changed = !age;
951*38fd1498Szrj 
952*38fd1498Szrj   /*  Calculate <conf_op> of incoming edges.  */
953*38fd1498Szrj   if (EDGE_COUNT (bb->succs) > 0)
954*38fd1498Szrj     FOR_EACH_EDGE (e, ei, bb->succs)
955*38fd1498Szrj       {
956*38fd1498Szrj         if (age <= BB_LAST_CHANGE_AGE (e->dest)
957*38fd1498Szrj 	    && bitmap_bit_p (considered, e->dest->index))
958*38fd1498Szrj           changed |= dataflow->problem->con_fun_n (e);
959*38fd1498Szrj       }
960*38fd1498Szrj   else if (dataflow->problem->con_fun_0)
961*38fd1498Szrj     dataflow->problem->con_fun_0 (bb);
962*38fd1498Szrj 
963*38fd1498Szrj   if (changed
964*38fd1498Szrj       && dataflow->problem->trans_fun (bb_index))
965*38fd1498Szrj     {
966*38fd1498Szrj       /* The out set of this block has changed.
967*38fd1498Szrj          Propagate to the outgoing blocks.  */
968*38fd1498Szrj       FOR_EACH_EDGE (e, ei, bb->preds)
969*38fd1498Szrj         {
970*38fd1498Szrj           unsigned ob_index = e->src->index;
971*38fd1498Szrj 
972*38fd1498Szrj           if (bitmap_bit_p (considered, ob_index))
973*38fd1498Szrj             bitmap_set_bit (pending, bbindex_to_postorder[ob_index]);
974*38fd1498Szrj         }
975*38fd1498Szrj       return true;
976*38fd1498Szrj     }
977*38fd1498Szrj   return false;
978*38fd1498Szrj }
979*38fd1498Szrj 
980*38fd1498Szrj /* Main dataflow solver loop.
981*38fd1498Szrj 
982*38fd1498Szrj    DATAFLOW is problem we are solving, PENDING is worklist of basic blocks we
983*38fd1498Szrj    need to visit.
984*38fd1498Szrj    BLOCK_IN_POSTORDER is array of size N_BLOCKS specifying postorder in BBs and
985*38fd1498Szrj    BBINDEX_TO_POSTORDER is array mapping back BB->index to postorder position.
986*38fd1498Szrj    PENDING will be freed.
987*38fd1498Szrj 
988*38fd1498Szrj    The worklists are bitmaps indexed by postorder positions.
989*38fd1498Szrj 
990*38fd1498Szrj    The function implements standard algorithm for dataflow solving with two
991*38fd1498Szrj    worklists (we are processing WORKLIST and storing new BBs to visit in
992*38fd1498Szrj    PENDING).
993*38fd1498Szrj 
994*38fd1498Szrj    As an optimization we maintain ages when BB was changed (stored in bb->aux)
995*38fd1498Szrj    and when it was last visited (stored in last_visit_age).  This avoids need
996*38fd1498Szrj    to re-do confluence function for edges to basic blocks whose source
997*38fd1498Szrj    did not change since destination was visited last time.  */
998*38fd1498Szrj 
999*38fd1498Szrj static void
df_worklist_dataflow_doublequeue(struct dataflow * dataflow,bitmap pending,sbitmap considered,int * blocks_in_postorder,unsigned * bbindex_to_postorder,int n_blocks)1000*38fd1498Szrj df_worklist_dataflow_doublequeue (struct dataflow *dataflow,
1001*38fd1498Szrj 			  	  bitmap pending,
1002*38fd1498Szrj                                   sbitmap considered,
1003*38fd1498Szrj                                   int *blocks_in_postorder,
1004*38fd1498Szrj 				  unsigned *bbindex_to_postorder,
1005*38fd1498Szrj 				  int n_blocks)
1006*38fd1498Szrj {
1007*38fd1498Szrj   enum df_flow_dir dir = dataflow->problem->dir;
1008*38fd1498Szrj   int dcount = 0;
1009*38fd1498Szrj   bitmap worklist = BITMAP_ALLOC (&df_bitmap_obstack);
1010*38fd1498Szrj   int age = 0;
1011*38fd1498Szrj   bool changed;
1012*38fd1498Szrj   vec<int> last_visit_age = vNULL;
1013*38fd1498Szrj   int prev_age;
1014*38fd1498Szrj   basic_block bb;
1015*38fd1498Szrj   int i;
1016*38fd1498Szrj 
1017*38fd1498Szrj   last_visit_age.safe_grow_cleared (n_blocks);
1018*38fd1498Szrj 
1019*38fd1498Szrj   /* Double-queueing. Worklist is for the current iteration,
1020*38fd1498Szrj      and pending is for the next. */
1021*38fd1498Szrj   while (!bitmap_empty_p (pending))
1022*38fd1498Szrj     {
1023*38fd1498Szrj       bitmap_iterator bi;
1024*38fd1498Szrj       unsigned int index;
1025*38fd1498Szrj 
1026*38fd1498Szrj       std::swap (pending, worklist);
1027*38fd1498Szrj 
1028*38fd1498Szrj       EXECUTE_IF_SET_IN_BITMAP (worklist, 0, index, bi)
1029*38fd1498Szrj 	{
1030*38fd1498Szrj 	  unsigned bb_index;
1031*38fd1498Szrj 	  dcount++;
1032*38fd1498Szrj 
1033*38fd1498Szrj 	  bitmap_clear_bit (pending, index);
1034*38fd1498Szrj 	  bb_index = blocks_in_postorder[index];
1035*38fd1498Szrj 	  bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1036*38fd1498Szrj 	  prev_age = last_visit_age[index];
1037*38fd1498Szrj 	  if (dir == DF_FORWARD)
1038*38fd1498Szrj 	    changed = df_worklist_propagate_forward (dataflow, bb_index,
1039*38fd1498Szrj 						     bbindex_to_postorder,
1040*38fd1498Szrj 						     pending, considered,
1041*38fd1498Szrj 						     prev_age);
1042*38fd1498Szrj 	  else
1043*38fd1498Szrj 	    changed = df_worklist_propagate_backward (dataflow, bb_index,
1044*38fd1498Szrj 						      bbindex_to_postorder,
1045*38fd1498Szrj 						      pending, considered,
1046*38fd1498Szrj 						      prev_age);
1047*38fd1498Szrj 	  last_visit_age[index] = ++age;
1048*38fd1498Szrj 	  if (changed)
1049*38fd1498Szrj 	    bb->aux = (void *)(ptrdiff_t)age;
1050*38fd1498Szrj 	}
1051*38fd1498Szrj       bitmap_clear (worklist);
1052*38fd1498Szrj     }
1053*38fd1498Szrj   for (i = 0; i < n_blocks; i++)
1054*38fd1498Szrj     BASIC_BLOCK_FOR_FN (cfun, blocks_in_postorder[i])->aux = NULL;
1055*38fd1498Szrj 
1056*38fd1498Szrj   BITMAP_FREE (worklist);
1057*38fd1498Szrj   BITMAP_FREE (pending);
1058*38fd1498Szrj   last_visit_age.release ();
1059*38fd1498Szrj 
1060*38fd1498Szrj   /* Dump statistics. */
1061*38fd1498Szrj   if (dump_file)
1062*38fd1498Szrj     fprintf (dump_file, "df_worklist_dataflow_doublequeue:"
1063*38fd1498Szrj 	     " n_basic_blocks %d n_edges %d"
1064*38fd1498Szrj 	     " count %d (%5.2g)\n",
1065*38fd1498Szrj 	     n_basic_blocks_for_fn (cfun), n_edges_for_fn (cfun),
1066*38fd1498Szrj 	     dcount, dcount / (float)n_basic_blocks_for_fn (cfun));
1067*38fd1498Szrj }
1068*38fd1498Szrj 
1069*38fd1498Szrj /* Worklist-based dataflow solver. It uses sbitmap as a worklist,
1070*38fd1498Szrj    with "n"-th bit representing the n-th block in the reverse-postorder order.
1071*38fd1498Szrj    The solver is a double-queue algorithm similar to the "double stack" solver
1072*38fd1498Szrj    from Cooper, Harvey and Kennedy, "Iterative data-flow analysis, Revisited".
1073*38fd1498Szrj    The only significant difference is that the worklist in this implementation
1074*38fd1498Szrj    is always sorted in RPO of the CFG visiting direction.  */
1075*38fd1498Szrj 
1076*38fd1498Szrj void
df_worklist_dataflow(struct dataflow * dataflow,bitmap blocks_to_consider,int * blocks_in_postorder,int n_blocks)1077*38fd1498Szrj df_worklist_dataflow (struct dataflow *dataflow,
1078*38fd1498Szrj                       bitmap blocks_to_consider,
1079*38fd1498Szrj                       int *blocks_in_postorder,
1080*38fd1498Szrj                       int n_blocks)
1081*38fd1498Szrj {
1082*38fd1498Szrj   bitmap pending = BITMAP_ALLOC (&df_bitmap_obstack);
1083*38fd1498Szrj   bitmap_iterator bi;
1084*38fd1498Szrj   unsigned int *bbindex_to_postorder;
1085*38fd1498Szrj   int i;
1086*38fd1498Szrj   unsigned int index;
1087*38fd1498Szrj   enum df_flow_dir dir = dataflow->problem->dir;
1088*38fd1498Szrj 
1089*38fd1498Szrj   gcc_assert (dir != DF_NONE);
1090*38fd1498Szrj 
1091*38fd1498Szrj   /* BBINDEX_TO_POSTORDER maps the bb->index to the reverse postorder.  */
1092*38fd1498Szrj   bbindex_to_postorder = XNEWVEC (unsigned int,
1093*38fd1498Szrj 				  last_basic_block_for_fn (cfun));
1094*38fd1498Szrj 
1095*38fd1498Szrj   /* Initialize the array to an out-of-bound value.  */
1096*38fd1498Szrj   for (i = 0; i < last_basic_block_for_fn (cfun); i++)
1097*38fd1498Szrj     bbindex_to_postorder[i] = last_basic_block_for_fn (cfun);
1098*38fd1498Szrj 
1099*38fd1498Szrj   /* Initialize the considered map.  */
1100*38fd1498Szrj   auto_sbitmap considered (last_basic_block_for_fn (cfun));
1101*38fd1498Szrj   bitmap_clear (considered);
1102*38fd1498Szrj   EXECUTE_IF_SET_IN_BITMAP (blocks_to_consider, 0, index, bi)
1103*38fd1498Szrj     {
1104*38fd1498Szrj       bitmap_set_bit (considered, index);
1105*38fd1498Szrj     }
1106*38fd1498Szrj 
1107*38fd1498Szrj   /* Initialize the mapping of block index to postorder.  */
1108*38fd1498Szrj   for (i = 0; i < n_blocks; i++)
1109*38fd1498Szrj     {
1110*38fd1498Szrj       bbindex_to_postorder[blocks_in_postorder[i]] = i;
1111*38fd1498Szrj       /* Add all blocks to the worklist.  */
1112*38fd1498Szrj       bitmap_set_bit (pending, i);
1113*38fd1498Szrj     }
1114*38fd1498Szrj 
1115*38fd1498Szrj   /* Initialize the problem. */
1116*38fd1498Szrj   if (dataflow->problem->init_fun)
1117*38fd1498Szrj     dataflow->problem->init_fun (blocks_to_consider);
1118*38fd1498Szrj 
1119*38fd1498Szrj   /* Solve it.  */
1120*38fd1498Szrj   df_worklist_dataflow_doublequeue (dataflow, pending, considered,
1121*38fd1498Szrj 				    blocks_in_postorder,
1122*38fd1498Szrj 				    bbindex_to_postorder,
1123*38fd1498Szrj 				    n_blocks);
1124*38fd1498Szrj   free (bbindex_to_postorder);
1125*38fd1498Szrj }
1126*38fd1498Szrj 
1127*38fd1498Szrj 
1128*38fd1498Szrj /* Remove the entries not in BLOCKS from the LIST of length LEN, preserving
1129*38fd1498Szrj    the order of the remaining entries.  Returns the length of the resulting
1130*38fd1498Szrj    list.  */
1131*38fd1498Szrj 
1132*38fd1498Szrj static unsigned
df_prune_to_subcfg(int list[],unsigned len,bitmap blocks)1133*38fd1498Szrj df_prune_to_subcfg (int list[], unsigned len, bitmap blocks)
1134*38fd1498Szrj {
1135*38fd1498Szrj   unsigned act, last;
1136*38fd1498Szrj 
1137*38fd1498Szrj   for (act = 0, last = 0; act < len; act++)
1138*38fd1498Szrj     if (bitmap_bit_p (blocks, list[act]))
1139*38fd1498Szrj       list[last++] = list[act];
1140*38fd1498Szrj 
1141*38fd1498Szrj   return last;
1142*38fd1498Szrj }
1143*38fd1498Szrj 
1144*38fd1498Szrj 
1145*38fd1498Szrj /* Execute dataflow analysis on a single dataflow problem.
1146*38fd1498Szrj 
1147*38fd1498Szrj    BLOCKS_TO_CONSIDER are the blocks whose solution can either be
1148*38fd1498Szrj    examined or will be computed.  For calls from DF_ANALYZE, this is
1149*38fd1498Szrj    the set of blocks that has been passed to DF_SET_BLOCKS.
1150*38fd1498Szrj */
1151*38fd1498Szrj 
1152*38fd1498Szrj void
df_analyze_problem(struct dataflow * dflow,bitmap blocks_to_consider,int * postorder,int n_blocks)1153*38fd1498Szrj df_analyze_problem (struct dataflow *dflow,
1154*38fd1498Szrj 		    bitmap blocks_to_consider,
1155*38fd1498Szrj 		    int *postorder, int n_blocks)
1156*38fd1498Szrj {
1157*38fd1498Szrj   timevar_push (dflow->problem->tv_id);
1158*38fd1498Szrj 
1159*38fd1498Szrj   /* (Re)Allocate the datastructures necessary to solve the problem.  */
1160*38fd1498Szrj   if (dflow->problem->alloc_fun)
1161*38fd1498Szrj     dflow->problem->alloc_fun (blocks_to_consider);
1162*38fd1498Szrj 
1163*38fd1498Szrj #ifdef ENABLE_DF_CHECKING
1164*38fd1498Szrj   if (dflow->problem->verify_start_fun)
1165*38fd1498Szrj     dflow->problem->verify_start_fun ();
1166*38fd1498Szrj #endif
1167*38fd1498Szrj 
1168*38fd1498Szrj   /* Set up the problem and compute the local information.  */
1169*38fd1498Szrj   if (dflow->problem->local_compute_fun)
1170*38fd1498Szrj     dflow->problem->local_compute_fun (blocks_to_consider);
1171*38fd1498Szrj 
1172*38fd1498Szrj   /* Solve the equations.  */
1173*38fd1498Szrj   if (dflow->problem->dataflow_fun)
1174*38fd1498Szrj     dflow->problem->dataflow_fun (dflow, blocks_to_consider,
1175*38fd1498Szrj 				  postorder, n_blocks);
1176*38fd1498Szrj 
1177*38fd1498Szrj   /* Massage the solution.  */
1178*38fd1498Szrj   if (dflow->problem->finalize_fun)
1179*38fd1498Szrj     dflow->problem->finalize_fun (blocks_to_consider);
1180*38fd1498Szrj 
1181*38fd1498Szrj #ifdef ENABLE_DF_CHECKING
1182*38fd1498Szrj   if (dflow->problem->verify_end_fun)
1183*38fd1498Szrj     dflow->problem->verify_end_fun ();
1184*38fd1498Szrj #endif
1185*38fd1498Szrj 
1186*38fd1498Szrj   timevar_pop (dflow->problem->tv_id);
1187*38fd1498Szrj 
1188*38fd1498Szrj   dflow->computed = true;
1189*38fd1498Szrj }
1190*38fd1498Szrj 
1191*38fd1498Szrj 
1192*38fd1498Szrj /* Analyze dataflow info.  */
1193*38fd1498Szrj 
1194*38fd1498Szrj static void
df_analyze_1(void)1195*38fd1498Szrj df_analyze_1 (void)
1196*38fd1498Szrj {
1197*38fd1498Szrj   int i;
1198*38fd1498Szrj 
1199*38fd1498Szrj   /* These should be the same.  */
1200*38fd1498Szrj   gcc_assert ((unsigned) df->n_blocks == df->postorder_inverted.length ());
1201*38fd1498Szrj 
1202*38fd1498Szrj   /* We need to do this before the df_verify_all because this is
1203*38fd1498Szrj      not kept incrementally up to date.  */
1204*38fd1498Szrj   df_compute_regs_ever_live (false);
1205*38fd1498Szrj   df_process_deferred_rescans ();
1206*38fd1498Szrj 
1207*38fd1498Szrj   if (dump_file)
1208*38fd1498Szrj     fprintf (dump_file, "df_analyze called\n");
1209*38fd1498Szrj 
1210*38fd1498Szrj #ifndef ENABLE_DF_CHECKING
1211*38fd1498Szrj   if (df->changeable_flags & DF_VERIFY_SCHEDULED)
1212*38fd1498Szrj #endif
1213*38fd1498Szrj     df_verify ();
1214*38fd1498Szrj 
1215*38fd1498Szrj   /* Skip over the DF_SCAN problem. */
1216*38fd1498Szrj   for (i = 1; i < df->num_problems_defined; i++)
1217*38fd1498Szrj     {
1218*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[i];
1219*38fd1498Szrj       if (dflow->solutions_dirty)
1220*38fd1498Szrj         {
1221*38fd1498Szrj           if (dflow->problem->dir == DF_FORWARD)
1222*38fd1498Szrj             df_analyze_problem (dflow,
1223*38fd1498Szrj                                 df->blocks_to_analyze,
1224*38fd1498Szrj 				df->postorder_inverted.address (),
1225*38fd1498Szrj 				df->postorder_inverted.length ());
1226*38fd1498Szrj           else
1227*38fd1498Szrj             df_analyze_problem (dflow,
1228*38fd1498Szrj                                 df->blocks_to_analyze,
1229*38fd1498Szrj                                 df->postorder,
1230*38fd1498Szrj                                 df->n_blocks);
1231*38fd1498Szrj         }
1232*38fd1498Szrj     }
1233*38fd1498Szrj 
1234*38fd1498Szrj   if (!df->analyze_subset)
1235*38fd1498Szrj     {
1236*38fd1498Szrj       BITMAP_FREE (df->blocks_to_analyze);
1237*38fd1498Szrj       df->blocks_to_analyze = NULL;
1238*38fd1498Szrj     }
1239*38fd1498Szrj 
1240*38fd1498Szrj #ifdef DF_DEBUG_CFG
1241*38fd1498Szrj   df_set_clean_cfg ();
1242*38fd1498Szrj #endif
1243*38fd1498Szrj }
1244*38fd1498Szrj 
1245*38fd1498Szrj /* Analyze dataflow info.  */
1246*38fd1498Szrj 
1247*38fd1498Szrj void
df_analyze(void)1248*38fd1498Szrj df_analyze (void)
1249*38fd1498Szrj {
1250*38fd1498Szrj   bitmap current_all_blocks = BITMAP_ALLOC (&df_bitmap_obstack);
1251*38fd1498Szrj 
1252*38fd1498Szrj   free (df->postorder);
1253*38fd1498Szrj   df->postorder = XNEWVEC (int, last_basic_block_for_fn (cfun));
1254*38fd1498Szrj   df->n_blocks = post_order_compute (df->postorder, true, true);
1255*38fd1498Szrj   df->postorder_inverted.truncate (0);
1256*38fd1498Szrj   inverted_post_order_compute (&df->postorder_inverted);
1257*38fd1498Szrj 
1258*38fd1498Szrj   for (int i = 0; i < df->n_blocks; i++)
1259*38fd1498Szrj     bitmap_set_bit (current_all_blocks, df->postorder[i]);
1260*38fd1498Szrj 
1261*38fd1498Szrj   if (flag_checking)
1262*38fd1498Szrj     {
1263*38fd1498Szrj       /* Verify that POSTORDER_INVERTED only contains blocks reachable from
1264*38fd1498Szrj 	 the ENTRY block.  */
1265*38fd1498Szrj       for (unsigned int i = 0; i < df->postorder_inverted.length (); i++)
1266*38fd1498Szrj 	gcc_assert (bitmap_bit_p (current_all_blocks,
1267*38fd1498Szrj 				  df->postorder_inverted[i]));
1268*38fd1498Szrj     }
1269*38fd1498Szrj 
1270*38fd1498Szrj   /* Make sure that we have pruned any unreachable blocks from these
1271*38fd1498Szrj      sets.  */
1272*38fd1498Szrj   if (df->analyze_subset)
1273*38fd1498Szrj     {
1274*38fd1498Szrj       bitmap_and_into (df->blocks_to_analyze, current_all_blocks);
1275*38fd1498Szrj       df->n_blocks = df_prune_to_subcfg (df->postorder,
1276*38fd1498Szrj 					 df->n_blocks, df->blocks_to_analyze);
1277*38fd1498Szrj       unsigned int newlen = df_prune_to_subcfg (df->postorder_inverted.address (),
1278*38fd1498Szrj 						df->postorder_inverted.length (),
1279*38fd1498Szrj 						  df->blocks_to_analyze);
1280*38fd1498Szrj       df->postorder_inverted.truncate (newlen);
1281*38fd1498Szrj       BITMAP_FREE (current_all_blocks);
1282*38fd1498Szrj     }
1283*38fd1498Szrj   else
1284*38fd1498Szrj     {
1285*38fd1498Szrj       df->blocks_to_analyze = current_all_blocks;
1286*38fd1498Szrj       current_all_blocks = NULL;
1287*38fd1498Szrj     }
1288*38fd1498Szrj 
1289*38fd1498Szrj   df_analyze_1 ();
1290*38fd1498Szrj }
1291*38fd1498Szrj 
1292*38fd1498Szrj /* Compute the reverse top sort order of the sub-CFG specified by LOOP.
1293*38fd1498Szrj    Returns the number of blocks which is always loop->num_nodes.  */
1294*38fd1498Szrj 
1295*38fd1498Szrj static int
loop_post_order_compute(int * post_order,struct loop * loop)1296*38fd1498Szrj loop_post_order_compute (int *post_order, struct loop *loop)
1297*38fd1498Szrj {
1298*38fd1498Szrj   edge_iterator *stack;
1299*38fd1498Szrj   int sp;
1300*38fd1498Szrj   int post_order_num = 0;
1301*38fd1498Szrj 
1302*38fd1498Szrj   /* Allocate stack for back-tracking up CFG.  */
1303*38fd1498Szrj   stack = XNEWVEC (edge_iterator, loop->num_nodes + 1);
1304*38fd1498Szrj   sp = 0;
1305*38fd1498Szrj 
1306*38fd1498Szrj   /* Allocate bitmap to track nodes that have been visited.  */
1307*38fd1498Szrj   auto_bitmap visited;
1308*38fd1498Szrj 
1309*38fd1498Szrj   /* Push the first edge on to the stack.  */
1310*38fd1498Szrj   stack[sp++] = ei_start (loop_preheader_edge (loop)->src->succs);
1311*38fd1498Szrj 
1312*38fd1498Szrj   while (sp)
1313*38fd1498Szrj     {
1314*38fd1498Szrj       edge_iterator ei;
1315*38fd1498Szrj       basic_block src;
1316*38fd1498Szrj       basic_block dest;
1317*38fd1498Szrj 
1318*38fd1498Szrj       /* Look at the edge on the top of the stack.  */
1319*38fd1498Szrj       ei = stack[sp - 1];
1320*38fd1498Szrj       src = ei_edge (ei)->src;
1321*38fd1498Szrj       dest = ei_edge (ei)->dest;
1322*38fd1498Szrj 
1323*38fd1498Szrj       /* Check if the edge destination has been visited yet and mark it
1324*38fd1498Szrj          if not so.  */
1325*38fd1498Szrj       if (flow_bb_inside_loop_p (loop, dest)
1326*38fd1498Szrj 	  && bitmap_set_bit (visited, dest->index))
1327*38fd1498Szrj 	{
1328*38fd1498Szrj 	  if (EDGE_COUNT (dest->succs) > 0)
1329*38fd1498Szrj 	    /* Since the DEST node has been visited for the first
1330*38fd1498Szrj 	       time, check its successors.  */
1331*38fd1498Szrj 	    stack[sp++] = ei_start (dest->succs);
1332*38fd1498Szrj 	  else
1333*38fd1498Szrj 	    post_order[post_order_num++] = dest->index;
1334*38fd1498Szrj 	}
1335*38fd1498Szrj       else
1336*38fd1498Szrj 	{
1337*38fd1498Szrj 	  if (ei_one_before_end_p (ei)
1338*38fd1498Szrj 	      && src != loop_preheader_edge (loop)->src)
1339*38fd1498Szrj 	    post_order[post_order_num++] = src->index;
1340*38fd1498Szrj 
1341*38fd1498Szrj 	  if (!ei_one_before_end_p (ei))
1342*38fd1498Szrj 	    ei_next (&stack[sp - 1]);
1343*38fd1498Szrj 	  else
1344*38fd1498Szrj 	    sp--;
1345*38fd1498Szrj 	}
1346*38fd1498Szrj     }
1347*38fd1498Szrj 
1348*38fd1498Szrj   free (stack);
1349*38fd1498Szrj 
1350*38fd1498Szrj   return post_order_num;
1351*38fd1498Szrj }
1352*38fd1498Szrj 
1353*38fd1498Szrj /* Compute the reverse top sort order of the inverted sub-CFG specified
1354*38fd1498Szrj    by LOOP.  Returns the number of blocks which is always loop->num_nodes.  */
1355*38fd1498Szrj 
1356*38fd1498Szrj static void
loop_inverted_post_order_compute(vec<int> * post_order,struct loop * loop)1357*38fd1498Szrj loop_inverted_post_order_compute (vec<int> *post_order, struct loop *loop)
1358*38fd1498Szrj {
1359*38fd1498Szrj   basic_block bb;
1360*38fd1498Szrj   edge_iterator *stack;
1361*38fd1498Szrj   int sp;
1362*38fd1498Szrj 
1363*38fd1498Szrj   post_order->reserve_exact (loop->num_nodes);
1364*38fd1498Szrj 
1365*38fd1498Szrj   /* Allocate stack for back-tracking up CFG.  */
1366*38fd1498Szrj   stack = XNEWVEC (edge_iterator, loop->num_nodes + 1);
1367*38fd1498Szrj   sp = 0;
1368*38fd1498Szrj 
1369*38fd1498Szrj   /* Allocate bitmap to track nodes that have been visited.  */
1370*38fd1498Szrj   auto_bitmap visited;
1371*38fd1498Szrj 
1372*38fd1498Szrj   /* Put all latches into the initial work list.  In theory we'd want
1373*38fd1498Szrj      to start from loop exits but then we'd have the special case of
1374*38fd1498Szrj      endless loops.  It doesn't really matter for DF iteration order and
1375*38fd1498Szrj      handling latches last is probably even better.  */
1376*38fd1498Szrj   stack[sp++] = ei_start (loop->header->preds);
1377*38fd1498Szrj   bitmap_set_bit (visited, loop->header->index);
1378*38fd1498Szrj 
1379*38fd1498Szrj   /* The inverted traversal loop. */
1380*38fd1498Szrj   while (sp)
1381*38fd1498Szrj     {
1382*38fd1498Szrj       edge_iterator ei;
1383*38fd1498Szrj       basic_block pred;
1384*38fd1498Szrj 
1385*38fd1498Szrj       /* Look at the edge on the top of the stack.  */
1386*38fd1498Szrj       ei = stack[sp - 1];
1387*38fd1498Szrj       bb = ei_edge (ei)->dest;
1388*38fd1498Szrj       pred = ei_edge (ei)->src;
1389*38fd1498Szrj 
1390*38fd1498Szrj       /* Check if the predecessor has been visited yet and mark it
1391*38fd1498Szrj 	 if not so.  */
1392*38fd1498Szrj       if (flow_bb_inside_loop_p (loop, pred)
1393*38fd1498Szrj 	  && bitmap_set_bit (visited, pred->index))
1394*38fd1498Szrj 	{
1395*38fd1498Szrj 	  if (EDGE_COUNT (pred->preds) > 0)
1396*38fd1498Szrj 	    /* Since the predecessor node has been visited for the first
1397*38fd1498Szrj 	       time, check its predecessors.  */
1398*38fd1498Szrj 	    stack[sp++] = ei_start (pred->preds);
1399*38fd1498Szrj 	  else
1400*38fd1498Szrj 	    post_order->quick_push (pred->index);
1401*38fd1498Szrj 	}
1402*38fd1498Szrj       else
1403*38fd1498Szrj 	{
1404*38fd1498Szrj 	  if (flow_bb_inside_loop_p (loop, bb)
1405*38fd1498Szrj 	      && ei_one_before_end_p (ei))
1406*38fd1498Szrj 	    post_order->quick_push (bb->index);
1407*38fd1498Szrj 
1408*38fd1498Szrj 	  if (!ei_one_before_end_p (ei))
1409*38fd1498Szrj 	    ei_next (&stack[sp - 1]);
1410*38fd1498Szrj 	  else
1411*38fd1498Szrj 	    sp--;
1412*38fd1498Szrj 	}
1413*38fd1498Szrj     }
1414*38fd1498Szrj 
1415*38fd1498Szrj   free (stack);
1416*38fd1498Szrj }
1417*38fd1498Szrj 
1418*38fd1498Szrj 
1419*38fd1498Szrj /* Analyze dataflow info for the basic blocks contained in LOOP.  */
1420*38fd1498Szrj 
1421*38fd1498Szrj void
df_analyze_loop(struct loop * loop)1422*38fd1498Szrj df_analyze_loop (struct loop *loop)
1423*38fd1498Szrj {
1424*38fd1498Szrj   free (df->postorder);
1425*38fd1498Szrj 
1426*38fd1498Szrj   df->postorder = XNEWVEC (int, loop->num_nodes);
1427*38fd1498Szrj   df->postorder_inverted.truncate (0);
1428*38fd1498Szrj   df->n_blocks = loop_post_order_compute (df->postorder, loop);
1429*38fd1498Szrj     loop_inverted_post_order_compute (&df->postorder_inverted, loop);
1430*38fd1498Szrj   gcc_assert ((unsigned) df->n_blocks == loop->num_nodes);
1431*38fd1498Szrj   gcc_assert (df->postorder_inverted.length () == loop->num_nodes);
1432*38fd1498Szrj 
1433*38fd1498Szrj   bitmap blocks = BITMAP_ALLOC (&df_bitmap_obstack);
1434*38fd1498Szrj   for (int i = 0; i < df->n_blocks; ++i)
1435*38fd1498Szrj     bitmap_set_bit (blocks, df->postorder[i]);
1436*38fd1498Szrj   df_set_blocks (blocks);
1437*38fd1498Szrj   BITMAP_FREE (blocks);
1438*38fd1498Szrj 
1439*38fd1498Szrj   df_analyze_1 ();
1440*38fd1498Szrj }
1441*38fd1498Szrj 
1442*38fd1498Szrj 
1443*38fd1498Szrj /* Return the number of basic blocks from the last call to df_analyze.  */
1444*38fd1498Szrj 
1445*38fd1498Szrj int
df_get_n_blocks(enum df_flow_dir dir)1446*38fd1498Szrj df_get_n_blocks (enum df_flow_dir dir)
1447*38fd1498Szrj {
1448*38fd1498Szrj   gcc_assert (dir != DF_NONE);
1449*38fd1498Szrj 
1450*38fd1498Szrj   if (dir == DF_FORWARD)
1451*38fd1498Szrj     {
1452*38fd1498Szrj       gcc_assert (df->postorder_inverted.length ());
1453*38fd1498Szrj       return df->postorder_inverted.length ();
1454*38fd1498Szrj     }
1455*38fd1498Szrj 
1456*38fd1498Szrj   gcc_assert (df->postorder);
1457*38fd1498Szrj   return df->n_blocks;
1458*38fd1498Szrj }
1459*38fd1498Szrj 
1460*38fd1498Szrj 
1461*38fd1498Szrj /* Return a pointer to the array of basic blocks in the reverse postorder.
1462*38fd1498Szrj    Depending on the direction of the dataflow problem,
1463*38fd1498Szrj    it returns either the usual reverse postorder array
1464*38fd1498Szrj    or the reverse postorder of inverted traversal. */
1465*38fd1498Szrj int *
df_get_postorder(enum df_flow_dir dir)1466*38fd1498Szrj df_get_postorder (enum df_flow_dir dir)
1467*38fd1498Szrj {
1468*38fd1498Szrj   gcc_assert (dir != DF_NONE);
1469*38fd1498Szrj 
1470*38fd1498Szrj   if (dir == DF_FORWARD)
1471*38fd1498Szrj     {
1472*38fd1498Szrj       gcc_assert (df->postorder_inverted.length ());
1473*38fd1498Szrj       return df->postorder_inverted.address ();
1474*38fd1498Szrj     }
1475*38fd1498Szrj   gcc_assert (df->postorder);
1476*38fd1498Szrj   return df->postorder;
1477*38fd1498Szrj }
1478*38fd1498Szrj 
1479*38fd1498Szrj static struct df_problem user_problem;
1480*38fd1498Szrj static struct dataflow user_dflow;
1481*38fd1498Szrj 
1482*38fd1498Szrj /* Interface for calling iterative dataflow with user defined
1483*38fd1498Szrj    confluence and transfer functions.  All that is necessary is to
1484*38fd1498Szrj    supply DIR, a direction, CONF_FUN_0, a confluence function for
1485*38fd1498Szrj    blocks with no logical preds (or NULL), CONF_FUN_N, the normal
1486*38fd1498Szrj    confluence function, TRANS_FUN, the basic block transfer function,
1487*38fd1498Szrj    and BLOCKS, the set of blocks to examine, POSTORDER the blocks in
1488*38fd1498Szrj    postorder, and N_BLOCKS, the number of blocks in POSTORDER. */
1489*38fd1498Szrj 
1490*38fd1498Szrj void
df_simple_dataflow(enum df_flow_dir dir,df_init_function init_fun,df_confluence_function_0 con_fun_0,df_confluence_function_n con_fun_n,df_transfer_function trans_fun,bitmap blocks,int * postorder,int n_blocks)1491*38fd1498Szrj df_simple_dataflow (enum df_flow_dir dir,
1492*38fd1498Szrj 		    df_init_function init_fun,
1493*38fd1498Szrj 		    df_confluence_function_0 con_fun_0,
1494*38fd1498Szrj 		    df_confluence_function_n con_fun_n,
1495*38fd1498Szrj 		    df_transfer_function trans_fun,
1496*38fd1498Szrj 		    bitmap blocks, int * postorder, int n_blocks)
1497*38fd1498Szrj {
1498*38fd1498Szrj   memset (&user_problem, 0, sizeof (struct df_problem));
1499*38fd1498Szrj   user_problem.dir = dir;
1500*38fd1498Szrj   user_problem.init_fun = init_fun;
1501*38fd1498Szrj   user_problem.con_fun_0 = con_fun_0;
1502*38fd1498Szrj   user_problem.con_fun_n = con_fun_n;
1503*38fd1498Szrj   user_problem.trans_fun = trans_fun;
1504*38fd1498Szrj   user_dflow.problem = &user_problem;
1505*38fd1498Szrj   df_worklist_dataflow (&user_dflow, blocks, postorder, n_blocks);
1506*38fd1498Szrj }
1507*38fd1498Szrj 
1508*38fd1498Szrj 
1509*38fd1498Szrj 
1510*38fd1498Szrj /*----------------------------------------------------------------------------
1511*38fd1498Szrj    Functions to support limited incremental change.
1512*38fd1498Szrj ----------------------------------------------------------------------------*/
1513*38fd1498Szrj 
1514*38fd1498Szrj 
1515*38fd1498Szrj /* Get basic block info.  */
1516*38fd1498Szrj 
1517*38fd1498Szrj static void *
df_get_bb_info(struct dataflow * dflow,unsigned int index)1518*38fd1498Szrj df_get_bb_info (struct dataflow *dflow, unsigned int index)
1519*38fd1498Szrj {
1520*38fd1498Szrj   if (dflow->block_info == NULL)
1521*38fd1498Szrj     return NULL;
1522*38fd1498Szrj   if (index >= dflow->block_info_size)
1523*38fd1498Szrj     return NULL;
1524*38fd1498Szrj   return (void *)((char *)dflow->block_info
1525*38fd1498Szrj 		  + index * dflow->problem->block_info_elt_size);
1526*38fd1498Szrj }
1527*38fd1498Szrj 
1528*38fd1498Szrj 
1529*38fd1498Szrj /* Set basic block info.  */
1530*38fd1498Szrj 
1531*38fd1498Szrj static void
df_set_bb_info(struct dataflow * dflow,unsigned int index,void * bb_info)1532*38fd1498Szrj df_set_bb_info (struct dataflow *dflow, unsigned int index,
1533*38fd1498Szrj 		void *bb_info)
1534*38fd1498Szrj {
1535*38fd1498Szrj   gcc_assert (dflow->block_info);
1536*38fd1498Szrj   memcpy ((char *)dflow->block_info
1537*38fd1498Szrj 	  + index * dflow->problem->block_info_elt_size,
1538*38fd1498Szrj 	  bb_info, dflow->problem->block_info_elt_size);
1539*38fd1498Szrj }
1540*38fd1498Szrj 
1541*38fd1498Szrj 
1542*38fd1498Szrj /* Clear basic block info.  */
1543*38fd1498Szrj 
1544*38fd1498Szrj static void
df_clear_bb_info(struct dataflow * dflow,unsigned int index)1545*38fd1498Szrj df_clear_bb_info (struct dataflow *dflow, unsigned int index)
1546*38fd1498Szrj {
1547*38fd1498Szrj   gcc_assert (dflow->block_info);
1548*38fd1498Szrj   gcc_assert (dflow->block_info_size > index);
1549*38fd1498Szrj   memset ((char *)dflow->block_info
1550*38fd1498Szrj 	  + index * dflow->problem->block_info_elt_size,
1551*38fd1498Szrj 	  0, dflow->problem->block_info_elt_size);
1552*38fd1498Szrj }
1553*38fd1498Szrj 
1554*38fd1498Szrj 
1555*38fd1498Szrj /* Mark the solutions as being out of date.  */
1556*38fd1498Szrj 
1557*38fd1498Szrj void
df_mark_solutions_dirty(void)1558*38fd1498Szrj df_mark_solutions_dirty (void)
1559*38fd1498Szrj {
1560*38fd1498Szrj   if (df)
1561*38fd1498Szrj     {
1562*38fd1498Szrj       int p;
1563*38fd1498Szrj       for (p = 1; p < df->num_problems_defined; p++)
1564*38fd1498Szrj 	df->problems_in_order[p]->solutions_dirty = true;
1565*38fd1498Szrj     }
1566*38fd1498Szrj }
1567*38fd1498Szrj 
1568*38fd1498Szrj 
1569*38fd1498Szrj /* Return true if BB needs it's transfer functions recomputed.  */
1570*38fd1498Szrj 
1571*38fd1498Szrj bool
df_get_bb_dirty(basic_block bb)1572*38fd1498Szrj df_get_bb_dirty (basic_block bb)
1573*38fd1498Szrj {
1574*38fd1498Szrj   return bitmap_bit_p ((df_live
1575*38fd1498Szrj 			? df_live : df_lr)->out_of_date_transfer_functions,
1576*38fd1498Szrj 		       bb->index);
1577*38fd1498Szrj }
1578*38fd1498Szrj 
1579*38fd1498Szrj 
1580*38fd1498Szrj /* Mark BB as needing it's transfer functions as being out of
1581*38fd1498Szrj    date.  */
1582*38fd1498Szrj 
1583*38fd1498Szrj void
df_set_bb_dirty(basic_block bb)1584*38fd1498Szrj df_set_bb_dirty (basic_block bb)
1585*38fd1498Szrj {
1586*38fd1498Szrj   bb->flags |= BB_MODIFIED;
1587*38fd1498Szrj   if (df)
1588*38fd1498Szrj     {
1589*38fd1498Szrj       int p;
1590*38fd1498Szrj       for (p = 1; p < df->num_problems_defined; p++)
1591*38fd1498Szrj 	{
1592*38fd1498Szrj 	  struct dataflow *dflow = df->problems_in_order[p];
1593*38fd1498Szrj 	  if (dflow->out_of_date_transfer_functions)
1594*38fd1498Szrj 	    bitmap_set_bit (dflow->out_of_date_transfer_functions, bb->index);
1595*38fd1498Szrj 	}
1596*38fd1498Szrj       df_mark_solutions_dirty ();
1597*38fd1498Szrj     }
1598*38fd1498Szrj }
1599*38fd1498Szrj 
1600*38fd1498Szrj 
1601*38fd1498Szrj /* Grow the bb_info array.  */
1602*38fd1498Szrj 
1603*38fd1498Szrj void
df_grow_bb_info(struct dataflow * dflow)1604*38fd1498Szrj df_grow_bb_info (struct dataflow *dflow)
1605*38fd1498Szrj {
1606*38fd1498Szrj   unsigned int new_size = last_basic_block_for_fn (cfun) + 1;
1607*38fd1498Szrj   if (dflow->block_info_size < new_size)
1608*38fd1498Szrj     {
1609*38fd1498Szrj       new_size += new_size / 4;
1610*38fd1498Szrj       dflow->block_info
1611*38fd1498Szrj          = (void *)XRESIZEVEC (char, (char *)dflow->block_info,
1612*38fd1498Szrj 			       new_size
1613*38fd1498Szrj 			       * dflow->problem->block_info_elt_size);
1614*38fd1498Szrj       memset ((char *)dflow->block_info
1615*38fd1498Szrj 	      + dflow->block_info_size
1616*38fd1498Szrj 	      * dflow->problem->block_info_elt_size,
1617*38fd1498Szrj 	      0,
1618*38fd1498Szrj 	      (new_size - dflow->block_info_size)
1619*38fd1498Szrj 	      * dflow->problem->block_info_elt_size);
1620*38fd1498Szrj       dflow->block_info_size = new_size;
1621*38fd1498Szrj     }
1622*38fd1498Szrj }
1623*38fd1498Szrj 
1624*38fd1498Szrj 
1625*38fd1498Szrj /* Clear the dirty bits.  This is called from places that delete
1626*38fd1498Szrj    blocks.  */
1627*38fd1498Szrj static void
df_clear_bb_dirty(basic_block bb)1628*38fd1498Szrj df_clear_bb_dirty (basic_block bb)
1629*38fd1498Szrj {
1630*38fd1498Szrj   int p;
1631*38fd1498Szrj   for (p = 1; p < df->num_problems_defined; p++)
1632*38fd1498Szrj     {
1633*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[p];
1634*38fd1498Szrj       if (dflow->out_of_date_transfer_functions)
1635*38fd1498Szrj 	bitmap_clear_bit (dflow->out_of_date_transfer_functions, bb->index);
1636*38fd1498Szrj     }
1637*38fd1498Szrj }
1638*38fd1498Szrj 
1639*38fd1498Szrj /* Called from the rtl_compact_blocks to reorganize the problems basic
1640*38fd1498Szrj    block info.  */
1641*38fd1498Szrj 
1642*38fd1498Szrj void
df_compact_blocks(void)1643*38fd1498Szrj df_compact_blocks (void)
1644*38fd1498Szrj {
1645*38fd1498Szrj   int i, p;
1646*38fd1498Szrj   basic_block bb;
1647*38fd1498Szrj   void *problem_temps;
1648*38fd1498Szrj 
1649*38fd1498Szrj   auto_bitmap tmp (&df_bitmap_obstack);
1650*38fd1498Szrj   for (p = 0; p < df->num_problems_defined; p++)
1651*38fd1498Szrj     {
1652*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[p];
1653*38fd1498Szrj 
1654*38fd1498Szrj       /* Need to reorganize the out_of_date_transfer_functions for the
1655*38fd1498Szrj 	 dflow problem.  */
1656*38fd1498Szrj       if (dflow->out_of_date_transfer_functions)
1657*38fd1498Szrj 	{
1658*38fd1498Szrj 	  bitmap_copy (tmp, dflow->out_of_date_transfer_functions);
1659*38fd1498Szrj 	  bitmap_clear (dflow->out_of_date_transfer_functions);
1660*38fd1498Szrj 	  if (bitmap_bit_p (tmp, ENTRY_BLOCK))
1661*38fd1498Szrj 	    bitmap_set_bit (dflow->out_of_date_transfer_functions, ENTRY_BLOCK);
1662*38fd1498Szrj 	  if (bitmap_bit_p (tmp, EXIT_BLOCK))
1663*38fd1498Szrj 	    bitmap_set_bit (dflow->out_of_date_transfer_functions, EXIT_BLOCK);
1664*38fd1498Szrj 
1665*38fd1498Szrj 	  i = NUM_FIXED_BLOCKS;
1666*38fd1498Szrj 	  FOR_EACH_BB_FN (bb, cfun)
1667*38fd1498Szrj 	    {
1668*38fd1498Szrj 	      if (bitmap_bit_p (tmp, bb->index))
1669*38fd1498Szrj 		bitmap_set_bit (dflow->out_of_date_transfer_functions, i);
1670*38fd1498Szrj 	      i++;
1671*38fd1498Szrj 	    }
1672*38fd1498Szrj 	}
1673*38fd1498Szrj 
1674*38fd1498Szrj       /* Now shuffle the block info for the problem.  */
1675*38fd1498Szrj       if (dflow->problem->free_bb_fun)
1676*38fd1498Szrj 	{
1677*38fd1498Szrj 	  int size = (last_basic_block_for_fn (cfun)
1678*38fd1498Szrj 		      * dflow->problem->block_info_elt_size);
1679*38fd1498Szrj 	  problem_temps = XNEWVAR (char, size);
1680*38fd1498Szrj 	  df_grow_bb_info (dflow);
1681*38fd1498Szrj 	  memcpy (problem_temps, dflow->block_info, size);
1682*38fd1498Szrj 
1683*38fd1498Szrj 	  /* Copy the bb info from the problem tmps to the proper
1684*38fd1498Szrj 	     place in the block_info vector.  Null out the copied
1685*38fd1498Szrj 	     item.  The entry and exit blocks never move.  */
1686*38fd1498Szrj 	  i = NUM_FIXED_BLOCKS;
1687*38fd1498Szrj 	  FOR_EACH_BB_FN (bb, cfun)
1688*38fd1498Szrj 	    {
1689*38fd1498Szrj 	      df_set_bb_info (dflow, i,
1690*38fd1498Szrj 			      (char *)problem_temps
1691*38fd1498Szrj 			      + bb->index * dflow->problem->block_info_elt_size);
1692*38fd1498Szrj 	      i++;
1693*38fd1498Szrj 	    }
1694*38fd1498Szrj 	  memset ((char *)dflow->block_info
1695*38fd1498Szrj 		  + i * dflow->problem->block_info_elt_size, 0,
1696*38fd1498Szrj 		  (last_basic_block_for_fn (cfun) - i)
1697*38fd1498Szrj 		  * dflow->problem->block_info_elt_size);
1698*38fd1498Szrj 	  free (problem_temps);
1699*38fd1498Szrj 	}
1700*38fd1498Szrj     }
1701*38fd1498Szrj 
1702*38fd1498Szrj   /* Shuffle the bits in the basic_block indexed arrays.  */
1703*38fd1498Szrj 
1704*38fd1498Szrj   if (df->blocks_to_analyze)
1705*38fd1498Szrj     {
1706*38fd1498Szrj       if (bitmap_bit_p (tmp, ENTRY_BLOCK))
1707*38fd1498Szrj 	bitmap_set_bit (df->blocks_to_analyze, ENTRY_BLOCK);
1708*38fd1498Szrj       if (bitmap_bit_p (tmp, EXIT_BLOCK))
1709*38fd1498Szrj 	bitmap_set_bit (df->blocks_to_analyze, EXIT_BLOCK);
1710*38fd1498Szrj       bitmap_copy (tmp, df->blocks_to_analyze);
1711*38fd1498Szrj       bitmap_clear (df->blocks_to_analyze);
1712*38fd1498Szrj       i = NUM_FIXED_BLOCKS;
1713*38fd1498Szrj       FOR_EACH_BB_FN (bb, cfun)
1714*38fd1498Szrj 	{
1715*38fd1498Szrj 	  if (bitmap_bit_p (tmp, bb->index))
1716*38fd1498Szrj 	    bitmap_set_bit (df->blocks_to_analyze, i);
1717*38fd1498Szrj 	  i++;
1718*38fd1498Szrj 	}
1719*38fd1498Szrj     }
1720*38fd1498Szrj 
1721*38fd1498Szrj   i = NUM_FIXED_BLOCKS;
1722*38fd1498Szrj   FOR_EACH_BB_FN (bb, cfun)
1723*38fd1498Szrj     {
1724*38fd1498Szrj       SET_BASIC_BLOCK_FOR_FN (cfun, i, bb);
1725*38fd1498Szrj       bb->index = i;
1726*38fd1498Szrj       i++;
1727*38fd1498Szrj     }
1728*38fd1498Szrj 
1729*38fd1498Szrj   gcc_assert (i == n_basic_blocks_for_fn (cfun));
1730*38fd1498Szrj 
1731*38fd1498Szrj   for (; i < last_basic_block_for_fn (cfun); i++)
1732*38fd1498Szrj     SET_BASIC_BLOCK_FOR_FN (cfun, i, NULL);
1733*38fd1498Szrj 
1734*38fd1498Szrj #ifdef DF_DEBUG_CFG
1735*38fd1498Szrj   if (!df_lr->solutions_dirty)
1736*38fd1498Szrj     df_set_clean_cfg ();
1737*38fd1498Szrj #endif
1738*38fd1498Szrj }
1739*38fd1498Szrj 
1740*38fd1498Szrj 
1741*38fd1498Szrj /* Shove NEW_BLOCK in at OLD_INDEX.  Called from ifcvt to hack a
1742*38fd1498Szrj    block.  There is no excuse for people to do this kind of thing.  */
1743*38fd1498Szrj 
1744*38fd1498Szrj void
df_bb_replace(int old_index,basic_block new_block)1745*38fd1498Szrj df_bb_replace (int old_index, basic_block new_block)
1746*38fd1498Szrj {
1747*38fd1498Szrj   int new_block_index = new_block->index;
1748*38fd1498Szrj   int p;
1749*38fd1498Szrj 
1750*38fd1498Szrj   if (dump_file)
1751*38fd1498Szrj     fprintf (dump_file, "shoving block %d into %d\n", new_block_index, old_index);
1752*38fd1498Szrj 
1753*38fd1498Szrj   gcc_assert (df);
1754*38fd1498Szrj   gcc_assert (BASIC_BLOCK_FOR_FN (cfun, old_index) == NULL);
1755*38fd1498Szrj 
1756*38fd1498Szrj   for (p = 0; p < df->num_problems_defined; p++)
1757*38fd1498Szrj     {
1758*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[p];
1759*38fd1498Szrj       if (dflow->block_info)
1760*38fd1498Szrj 	{
1761*38fd1498Szrj 	  df_grow_bb_info (dflow);
1762*38fd1498Szrj 	  df_set_bb_info (dflow, old_index,
1763*38fd1498Szrj 			  df_get_bb_info (dflow, new_block_index));
1764*38fd1498Szrj 	}
1765*38fd1498Szrj     }
1766*38fd1498Szrj 
1767*38fd1498Szrj   df_clear_bb_dirty (new_block);
1768*38fd1498Szrj   SET_BASIC_BLOCK_FOR_FN (cfun, old_index, new_block);
1769*38fd1498Szrj   new_block->index = old_index;
1770*38fd1498Szrj   df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, old_index));
1771*38fd1498Szrj   SET_BASIC_BLOCK_FOR_FN (cfun, new_block_index, NULL);
1772*38fd1498Szrj }
1773*38fd1498Szrj 
1774*38fd1498Szrj 
1775*38fd1498Szrj /* Free all of the per basic block dataflow from all of the problems.
1776*38fd1498Szrj    This is typically called before a basic block is deleted and the
1777*38fd1498Szrj    problem will be reanalyzed.  */
1778*38fd1498Szrj 
1779*38fd1498Szrj void
df_bb_delete(int bb_index)1780*38fd1498Szrj df_bb_delete (int bb_index)
1781*38fd1498Szrj {
1782*38fd1498Szrj   basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1783*38fd1498Szrj   int i;
1784*38fd1498Szrj 
1785*38fd1498Szrj   if (!df)
1786*38fd1498Szrj     return;
1787*38fd1498Szrj 
1788*38fd1498Szrj   for (i = 0; i < df->num_problems_defined; i++)
1789*38fd1498Szrj     {
1790*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[i];
1791*38fd1498Szrj       if (dflow->problem->free_bb_fun)
1792*38fd1498Szrj 	{
1793*38fd1498Szrj 	  void *bb_info = df_get_bb_info (dflow, bb_index);
1794*38fd1498Szrj 	  if (bb_info)
1795*38fd1498Szrj 	    {
1796*38fd1498Szrj 	      dflow->problem->free_bb_fun (bb, bb_info);
1797*38fd1498Szrj 	      df_clear_bb_info (dflow, bb_index);
1798*38fd1498Szrj 	    }
1799*38fd1498Szrj 	}
1800*38fd1498Szrj     }
1801*38fd1498Szrj   df_clear_bb_dirty (bb);
1802*38fd1498Szrj   df_mark_solutions_dirty ();
1803*38fd1498Szrj }
1804*38fd1498Szrj 
1805*38fd1498Szrj 
1806*38fd1498Szrj /* Verify that there is a place for everything and everything is in
1807*38fd1498Szrj    its place.  This is too expensive to run after every pass in the
1808*38fd1498Szrj    mainline.  However this is an excellent debugging tool if the
1809*38fd1498Szrj    dataflow information is not being updated properly.  You can just
1810*38fd1498Szrj    sprinkle calls in until you find the place that is changing an
1811*38fd1498Szrj    underlying structure without calling the proper updating
1812*38fd1498Szrj    routine.  */
1813*38fd1498Szrj 
1814*38fd1498Szrj void
df_verify(void)1815*38fd1498Szrj df_verify (void)
1816*38fd1498Szrj {
1817*38fd1498Szrj   df_scan_verify ();
1818*38fd1498Szrj #ifdef ENABLE_DF_CHECKING
1819*38fd1498Szrj   df_lr_verify_transfer_functions ();
1820*38fd1498Szrj   if (df_live)
1821*38fd1498Szrj     df_live_verify_transfer_functions ();
1822*38fd1498Szrj #endif
1823*38fd1498Szrj   df->changeable_flags &= ~DF_VERIFY_SCHEDULED;
1824*38fd1498Szrj }
1825*38fd1498Szrj 
1826*38fd1498Szrj #ifdef DF_DEBUG_CFG
1827*38fd1498Szrj 
1828*38fd1498Szrj /* Compute an array of ints that describes the cfg.  This can be used
1829*38fd1498Szrj    to discover places where the cfg is modified by the appropriate
1830*38fd1498Szrj    calls have not been made to the keep df informed.  The internals of
1831*38fd1498Szrj    this are unexciting, the key is that two instances of this can be
1832*38fd1498Szrj    compared to see if any changes have been made to the cfg.  */
1833*38fd1498Szrj 
1834*38fd1498Szrj static int *
df_compute_cfg_image(void)1835*38fd1498Szrj df_compute_cfg_image (void)
1836*38fd1498Szrj {
1837*38fd1498Szrj   basic_block bb;
1838*38fd1498Szrj   int size = 2 + (2 * n_basic_blocks_for_fn (cfun));
1839*38fd1498Szrj   int i;
1840*38fd1498Szrj   int * map;
1841*38fd1498Szrj 
1842*38fd1498Szrj   FOR_ALL_BB_FN (bb, cfun)
1843*38fd1498Szrj     {
1844*38fd1498Szrj       size += EDGE_COUNT (bb->succs);
1845*38fd1498Szrj     }
1846*38fd1498Szrj 
1847*38fd1498Szrj   map = XNEWVEC (int, size);
1848*38fd1498Szrj   map[0] = size;
1849*38fd1498Szrj   i = 1;
1850*38fd1498Szrj   FOR_ALL_BB_FN (bb, cfun)
1851*38fd1498Szrj     {
1852*38fd1498Szrj       edge_iterator ei;
1853*38fd1498Szrj       edge e;
1854*38fd1498Szrj 
1855*38fd1498Szrj       map[i++] = bb->index;
1856*38fd1498Szrj       FOR_EACH_EDGE (e, ei, bb->succs)
1857*38fd1498Szrj 	map[i++] = e->dest->index;
1858*38fd1498Szrj       map[i++] = -1;
1859*38fd1498Szrj     }
1860*38fd1498Szrj   map[i] = -1;
1861*38fd1498Szrj   return map;
1862*38fd1498Szrj }
1863*38fd1498Szrj 
1864*38fd1498Szrj static int *saved_cfg = NULL;
1865*38fd1498Szrj 
1866*38fd1498Szrj 
1867*38fd1498Szrj /* This function compares the saved version of the cfg with the
1868*38fd1498Szrj    current cfg and aborts if the two are identical.  The function
1869*38fd1498Szrj    silently returns if the cfg has been marked as dirty or the two are
1870*38fd1498Szrj    the same.  */
1871*38fd1498Szrj 
1872*38fd1498Szrj void
df_check_cfg_clean(void)1873*38fd1498Szrj df_check_cfg_clean (void)
1874*38fd1498Szrj {
1875*38fd1498Szrj   int *new_map;
1876*38fd1498Szrj 
1877*38fd1498Szrj   if (!df)
1878*38fd1498Szrj     return;
1879*38fd1498Szrj 
1880*38fd1498Szrj   if (df_lr->solutions_dirty)
1881*38fd1498Szrj     return;
1882*38fd1498Szrj 
1883*38fd1498Szrj   if (saved_cfg == NULL)
1884*38fd1498Szrj     return;
1885*38fd1498Szrj 
1886*38fd1498Szrj   new_map = df_compute_cfg_image ();
1887*38fd1498Szrj   gcc_assert (memcmp (saved_cfg, new_map, saved_cfg[0] * sizeof (int)) == 0);
1888*38fd1498Szrj   free (new_map);
1889*38fd1498Szrj }
1890*38fd1498Szrj 
1891*38fd1498Szrj 
1892*38fd1498Szrj /* This function builds a cfg fingerprint and squirrels it away in
1893*38fd1498Szrj    saved_cfg.  */
1894*38fd1498Szrj 
1895*38fd1498Szrj static void
df_set_clean_cfg(void)1896*38fd1498Szrj df_set_clean_cfg (void)
1897*38fd1498Szrj {
1898*38fd1498Szrj   free (saved_cfg);
1899*38fd1498Szrj   saved_cfg = df_compute_cfg_image ();
1900*38fd1498Szrj }
1901*38fd1498Szrj 
1902*38fd1498Szrj #endif /* DF_DEBUG_CFG  */
1903*38fd1498Szrj /*----------------------------------------------------------------------------
1904*38fd1498Szrj    PUBLIC INTERFACES TO QUERY INFORMATION.
1905*38fd1498Szrj ----------------------------------------------------------------------------*/
1906*38fd1498Szrj 
1907*38fd1498Szrj 
1908*38fd1498Szrj /* Return first def of REGNO within BB.  */
1909*38fd1498Szrj 
1910*38fd1498Szrj df_ref
df_bb_regno_first_def_find(basic_block bb,unsigned int regno)1911*38fd1498Szrj df_bb_regno_first_def_find (basic_block bb, unsigned int regno)
1912*38fd1498Szrj {
1913*38fd1498Szrj   rtx_insn *insn;
1914*38fd1498Szrj   df_ref def;
1915*38fd1498Szrj 
1916*38fd1498Szrj   FOR_BB_INSNS (bb, insn)
1917*38fd1498Szrj     {
1918*38fd1498Szrj       if (!INSN_P (insn))
1919*38fd1498Szrj 	continue;
1920*38fd1498Szrj 
1921*38fd1498Szrj       FOR_EACH_INSN_DEF (def, insn)
1922*38fd1498Szrj 	if (DF_REF_REGNO (def) == regno)
1923*38fd1498Szrj 	  return def;
1924*38fd1498Szrj     }
1925*38fd1498Szrj   return NULL;
1926*38fd1498Szrj }
1927*38fd1498Szrj 
1928*38fd1498Szrj 
1929*38fd1498Szrj /* Return last def of REGNO within BB.  */
1930*38fd1498Szrj 
1931*38fd1498Szrj df_ref
df_bb_regno_last_def_find(basic_block bb,unsigned int regno)1932*38fd1498Szrj df_bb_regno_last_def_find (basic_block bb, unsigned int regno)
1933*38fd1498Szrj {
1934*38fd1498Szrj   rtx_insn *insn;
1935*38fd1498Szrj   df_ref def;
1936*38fd1498Szrj 
1937*38fd1498Szrj   FOR_BB_INSNS_REVERSE (bb, insn)
1938*38fd1498Szrj     {
1939*38fd1498Szrj       if (!INSN_P (insn))
1940*38fd1498Szrj 	continue;
1941*38fd1498Szrj 
1942*38fd1498Szrj       FOR_EACH_INSN_DEF (def, insn)
1943*38fd1498Szrj 	if (DF_REF_REGNO (def) == regno)
1944*38fd1498Szrj 	  return def;
1945*38fd1498Szrj     }
1946*38fd1498Szrj 
1947*38fd1498Szrj   return NULL;
1948*38fd1498Szrj }
1949*38fd1498Szrj 
1950*38fd1498Szrj /* Finds the reference corresponding to the definition of REG in INSN.
1951*38fd1498Szrj    DF is the dataflow object.  */
1952*38fd1498Szrj 
1953*38fd1498Szrj df_ref
df_find_def(rtx_insn * insn,rtx reg)1954*38fd1498Szrj df_find_def (rtx_insn *insn, rtx reg)
1955*38fd1498Szrj {
1956*38fd1498Szrj   df_ref def;
1957*38fd1498Szrj 
1958*38fd1498Szrj   if (GET_CODE (reg) == SUBREG)
1959*38fd1498Szrj     reg = SUBREG_REG (reg);
1960*38fd1498Szrj   gcc_assert (REG_P (reg));
1961*38fd1498Szrj 
1962*38fd1498Szrj   FOR_EACH_INSN_DEF (def, insn)
1963*38fd1498Szrj     if (DF_REF_REGNO (def) == REGNO (reg))
1964*38fd1498Szrj       return def;
1965*38fd1498Szrj 
1966*38fd1498Szrj   return NULL;
1967*38fd1498Szrj }
1968*38fd1498Szrj 
1969*38fd1498Szrj 
1970*38fd1498Szrj /* Return true if REG is defined in INSN, zero otherwise.  */
1971*38fd1498Szrj 
1972*38fd1498Szrj bool
df_reg_defined(rtx_insn * insn,rtx reg)1973*38fd1498Szrj df_reg_defined (rtx_insn *insn, rtx reg)
1974*38fd1498Szrj {
1975*38fd1498Szrj   return df_find_def (insn, reg) != NULL;
1976*38fd1498Szrj }
1977*38fd1498Szrj 
1978*38fd1498Szrj 
1979*38fd1498Szrj /* Finds the reference corresponding to the use of REG in INSN.
1980*38fd1498Szrj    DF is the dataflow object.  */
1981*38fd1498Szrj 
1982*38fd1498Szrj df_ref
df_find_use(rtx_insn * insn,rtx reg)1983*38fd1498Szrj df_find_use (rtx_insn *insn, rtx reg)
1984*38fd1498Szrj {
1985*38fd1498Szrj   df_ref use;
1986*38fd1498Szrj 
1987*38fd1498Szrj   if (GET_CODE (reg) == SUBREG)
1988*38fd1498Szrj     reg = SUBREG_REG (reg);
1989*38fd1498Szrj   gcc_assert (REG_P (reg));
1990*38fd1498Szrj 
1991*38fd1498Szrj   df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
1992*38fd1498Szrj   FOR_EACH_INSN_INFO_USE (use, insn_info)
1993*38fd1498Szrj     if (DF_REF_REGNO (use) == REGNO (reg))
1994*38fd1498Szrj       return use;
1995*38fd1498Szrj   if (df->changeable_flags & DF_EQ_NOTES)
1996*38fd1498Szrj     FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
1997*38fd1498Szrj       if (DF_REF_REGNO (use) == REGNO (reg))
1998*38fd1498Szrj 	return use;
1999*38fd1498Szrj   return NULL;
2000*38fd1498Szrj }
2001*38fd1498Szrj 
2002*38fd1498Szrj 
2003*38fd1498Szrj /* Return true if REG is referenced in INSN, zero otherwise.  */
2004*38fd1498Szrj 
2005*38fd1498Szrj bool
df_reg_used(rtx_insn * insn,rtx reg)2006*38fd1498Szrj df_reg_used (rtx_insn *insn, rtx reg)
2007*38fd1498Szrj {
2008*38fd1498Szrj   return df_find_use (insn, reg) != NULL;
2009*38fd1498Szrj }
2010*38fd1498Szrj 
2011*38fd1498Szrj 
2012*38fd1498Szrj /*----------------------------------------------------------------------------
2013*38fd1498Szrj    Debugging and printing functions.
2014*38fd1498Szrj ----------------------------------------------------------------------------*/
2015*38fd1498Szrj 
2016*38fd1498Szrj /* Write information about registers and basic blocks into FILE.
2017*38fd1498Szrj    This is part of making a debugging dump.  */
2018*38fd1498Szrj 
2019*38fd1498Szrj void
dump_regset(regset r,FILE * outf)2020*38fd1498Szrj dump_regset (regset r, FILE *outf)
2021*38fd1498Szrj {
2022*38fd1498Szrj   unsigned i;
2023*38fd1498Szrj   reg_set_iterator rsi;
2024*38fd1498Szrj 
2025*38fd1498Szrj   if (r == NULL)
2026*38fd1498Szrj     {
2027*38fd1498Szrj       fputs (" (nil)", outf);
2028*38fd1498Szrj       return;
2029*38fd1498Szrj     }
2030*38fd1498Szrj 
2031*38fd1498Szrj   EXECUTE_IF_SET_IN_REG_SET (r, 0, i, rsi)
2032*38fd1498Szrj     {
2033*38fd1498Szrj       fprintf (outf, " %d", i);
2034*38fd1498Szrj       if (i < FIRST_PSEUDO_REGISTER)
2035*38fd1498Szrj 	fprintf (outf, " [%s]",
2036*38fd1498Szrj 		 reg_names[i]);
2037*38fd1498Szrj     }
2038*38fd1498Szrj }
2039*38fd1498Szrj 
2040*38fd1498Szrj /* Print a human-readable representation of R on the standard error
2041*38fd1498Szrj    stream.  This function is designed to be used from within the
2042*38fd1498Szrj    debugger.  */
2043*38fd1498Szrj extern void debug_regset (regset);
2044*38fd1498Szrj DEBUG_FUNCTION void
debug_regset(regset r)2045*38fd1498Szrj debug_regset (regset r)
2046*38fd1498Szrj {
2047*38fd1498Szrj   dump_regset (r, stderr);
2048*38fd1498Szrj   putc ('\n', stderr);
2049*38fd1498Szrj }
2050*38fd1498Szrj 
2051*38fd1498Szrj /* Write information about registers and basic blocks into FILE.
2052*38fd1498Szrj    This is part of making a debugging dump.  */
2053*38fd1498Szrj 
2054*38fd1498Szrj void
df_print_regset(FILE * file,bitmap r)2055*38fd1498Szrj df_print_regset (FILE *file, bitmap r)
2056*38fd1498Szrj {
2057*38fd1498Szrj   unsigned int i;
2058*38fd1498Szrj   bitmap_iterator bi;
2059*38fd1498Szrj 
2060*38fd1498Szrj   if (r == NULL)
2061*38fd1498Szrj     fputs (" (nil)", file);
2062*38fd1498Szrj   else
2063*38fd1498Szrj     {
2064*38fd1498Szrj       EXECUTE_IF_SET_IN_BITMAP (r, 0, i, bi)
2065*38fd1498Szrj 	{
2066*38fd1498Szrj 	  fprintf (file, " %d", i);
2067*38fd1498Szrj 	  if (i < FIRST_PSEUDO_REGISTER)
2068*38fd1498Szrj 	    fprintf (file, " [%s]", reg_names[i]);
2069*38fd1498Szrj 	}
2070*38fd1498Szrj     }
2071*38fd1498Szrj   fprintf (file, "\n");
2072*38fd1498Szrj }
2073*38fd1498Szrj 
2074*38fd1498Szrj 
2075*38fd1498Szrj /* Write information about registers and basic blocks into FILE.  The
2076*38fd1498Szrj    bitmap is in the form used by df_byte_lr.  This is part of making a
2077*38fd1498Szrj    debugging dump.  */
2078*38fd1498Szrj 
2079*38fd1498Szrj void
df_print_word_regset(FILE * file,bitmap r)2080*38fd1498Szrj df_print_word_regset (FILE *file, bitmap r)
2081*38fd1498Szrj {
2082*38fd1498Szrj   unsigned int max_reg = max_reg_num ();
2083*38fd1498Szrj 
2084*38fd1498Szrj   if (r == NULL)
2085*38fd1498Szrj     fputs (" (nil)", file);
2086*38fd1498Szrj   else
2087*38fd1498Szrj     {
2088*38fd1498Szrj       unsigned int i;
2089*38fd1498Szrj       for (i = FIRST_PSEUDO_REGISTER; i < max_reg; i++)
2090*38fd1498Szrj 	{
2091*38fd1498Szrj 	  bool found = (bitmap_bit_p (r, 2 * i)
2092*38fd1498Szrj 			|| bitmap_bit_p (r, 2 * i + 1));
2093*38fd1498Szrj 	  if (found)
2094*38fd1498Szrj 	    {
2095*38fd1498Szrj 	      int word;
2096*38fd1498Szrj 	      const char * sep = "";
2097*38fd1498Szrj 	      fprintf (file, " %d", i);
2098*38fd1498Szrj 	      fprintf (file, "(");
2099*38fd1498Szrj 	      for (word = 0; word < 2; word++)
2100*38fd1498Szrj 		if (bitmap_bit_p (r, 2 * i + word))
2101*38fd1498Szrj 		  {
2102*38fd1498Szrj 		    fprintf (file, "%s%d", sep, word);
2103*38fd1498Szrj 		    sep = ", ";
2104*38fd1498Szrj 		  }
2105*38fd1498Szrj 	      fprintf (file, ")");
2106*38fd1498Szrj 	    }
2107*38fd1498Szrj 	}
2108*38fd1498Szrj     }
2109*38fd1498Szrj   fprintf (file, "\n");
2110*38fd1498Szrj }
2111*38fd1498Szrj 
2112*38fd1498Szrj 
2113*38fd1498Szrj /* Dump dataflow info.  */
2114*38fd1498Szrj 
2115*38fd1498Szrj void
df_dump(FILE * file)2116*38fd1498Szrj df_dump (FILE *file)
2117*38fd1498Szrj {
2118*38fd1498Szrj   basic_block bb;
2119*38fd1498Szrj   df_dump_start (file);
2120*38fd1498Szrj 
2121*38fd1498Szrj   FOR_ALL_BB_FN (bb, cfun)
2122*38fd1498Szrj     {
2123*38fd1498Szrj       df_print_bb_index (bb, file);
2124*38fd1498Szrj       df_dump_top (bb, file);
2125*38fd1498Szrj       df_dump_bottom (bb, file);
2126*38fd1498Szrj     }
2127*38fd1498Szrj 
2128*38fd1498Szrj   fprintf (file, "\n");
2129*38fd1498Szrj }
2130*38fd1498Szrj 
2131*38fd1498Szrj 
2132*38fd1498Szrj /* Dump dataflow info for df->blocks_to_analyze.  */
2133*38fd1498Szrj 
2134*38fd1498Szrj void
df_dump_region(FILE * file)2135*38fd1498Szrj df_dump_region (FILE *file)
2136*38fd1498Szrj {
2137*38fd1498Szrj   if (df->blocks_to_analyze)
2138*38fd1498Szrj     {
2139*38fd1498Szrj       bitmap_iterator bi;
2140*38fd1498Szrj       unsigned int bb_index;
2141*38fd1498Szrj 
2142*38fd1498Szrj       fprintf (file, "\n\nstarting region dump\n");
2143*38fd1498Szrj       df_dump_start (file);
2144*38fd1498Szrj 
2145*38fd1498Szrj       EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
2146*38fd1498Szrj 	{
2147*38fd1498Szrj 	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2148*38fd1498Szrj 	  dump_bb (file, bb, 0, TDF_DETAILS);
2149*38fd1498Szrj 	}
2150*38fd1498Szrj       fprintf (file, "\n");
2151*38fd1498Szrj     }
2152*38fd1498Szrj   else
2153*38fd1498Szrj     df_dump (file);
2154*38fd1498Szrj }
2155*38fd1498Szrj 
2156*38fd1498Szrj 
2157*38fd1498Szrj /* Dump the introductory information for each problem defined.  */
2158*38fd1498Szrj 
2159*38fd1498Szrj void
df_dump_start(FILE * file)2160*38fd1498Szrj df_dump_start (FILE *file)
2161*38fd1498Szrj {
2162*38fd1498Szrj   int i;
2163*38fd1498Szrj 
2164*38fd1498Szrj   if (!df || !file)
2165*38fd1498Szrj     return;
2166*38fd1498Szrj 
2167*38fd1498Szrj   fprintf (file, "\n\n%s\n", current_function_name ());
2168*38fd1498Szrj   fprintf (file, "\nDataflow summary:\n");
2169*38fd1498Szrj   if (df->blocks_to_analyze)
2170*38fd1498Szrj     fprintf (file, "def_info->table_size = %d, use_info->table_size = %d\n",
2171*38fd1498Szrj 	     DF_DEFS_TABLE_SIZE (), DF_USES_TABLE_SIZE ());
2172*38fd1498Szrj 
2173*38fd1498Szrj   for (i = 0; i < df->num_problems_defined; i++)
2174*38fd1498Szrj     {
2175*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[i];
2176*38fd1498Szrj       if (dflow->computed)
2177*38fd1498Szrj 	{
2178*38fd1498Szrj 	  df_dump_problem_function fun = dflow->problem->dump_start_fun;
2179*38fd1498Szrj 	  if (fun)
2180*38fd1498Szrj 	    fun (file);
2181*38fd1498Szrj 	}
2182*38fd1498Szrj     }
2183*38fd1498Szrj }
2184*38fd1498Szrj 
2185*38fd1498Szrj 
2186*38fd1498Szrj /* Dump the top or bottom of the block information for BB.  */
2187*38fd1498Szrj static void
df_dump_bb_problem_data(basic_block bb,FILE * file,bool top)2188*38fd1498Szrj df_dump_bb_problem_data (basic_block bb, FILE *file, bool top)
2189*38fd1498Szrj {
2190*38fd1498Szrj   int i;
2191*38fd1498Szrj 
2192*38fd1498Szrj   if (!df || !file)
2193*38fd1498Szrj     return;
2194*38fd1498Szrj 
2195*38fd1498Szrj   for (i = 0; i < df->num_problems_defined; i++)
2196*38fd1498Szrj     {
2197*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[i];
2198*38fd1498Szrj       if (dflow->computed)
2199*38fd1498Szrj 	{
2200*38fd1498Szrj 	  df_dump_bb_problem_function bbfun;
2201*38fd1498Szrj 
2202*38fd1498Szrj 	  if (top)
2203*38fd1498Szrj 	    bbfun = dflow->problem->dump_top_fun;
2204*38fd1498Szrj 	  else
2205*38fd1498Szrj 	    bbfun = dflow->problem->dump_bottom_fun;
2206*38fd1498Szrj 
2207*38fd1498Szrj 	  if (bbfun)
2208*38fd1498Szrj 	    bbfun (bb, file);
2209*38fd1498Szrj 	}
2210*38fd1498Szrj     }
2211*38fd1498Szrj }
2212*38fd1498Szrj 
2213*38fd1498Szrj /* Dump the top of the block information for BB.  */
2214*38fd1498Szrj 
2215*38fd1498Szrj void
df_dump_top(basic_block bb,FILE * file)2216*38fd1498Szrj df_dump_top (basic_block bb, FILE *file)
2217*38fd1498Szrj {
2218*38fd1498Szrj   df_dump_bb_problem_data (bb, file, /*top=*/true);
2219*38fd1498Szrj }
2220*38fd1498Szrj 
2221*38fd1498Szrj /* Dump the bottom of the block information for BB.  */
2222*38fd1498Szrj 
2223*38fd1498Szrj void
df_dump_bottom(basic_block bb,FILE * file)2224*38fd1498Szrj df_dump_bottom (basic_block bb, FILE *file)
2225*38fd1498Szrj {
2226*38fd1498Szrj   df_dump_bb_problem_data (bb, file, /*top=*/false);
2227*38fd1498Szrj }
2228*38fd1498Szrj 
2229*38fd1498Szrj 
2230*38fd1498Szrj /* Dump information about INSN just before or after dumping INSN itself.  */
2231*38fd1498Szrj static void
df_dump_insn_problem_data(const rtx_insn * insn,FILE * file,bool top)2232*38fd1498Szrj df_dump_insn_problem_data (const rtx_insn *insn, FILE *file, bool top)
2233*38fd1498Szrj {
2234*38fd1498Szrj   int i;
2235*38fd1498Szrj 
2236*38fd1498Szrj   if (!df || !file)
2237*38fd1498Szrj     return;
2238*38fd1498Szrj 
2239*38fd1498Szrj   for (i = 0; i < df->num_problems_defined; i++)
2240*38fd1498Szrj     {
2241*38fd1498Szrj       struct dataflow *dflow = df->problems_in_order[i];
2242*38fd1498Szrj       if (dflow->computed)
2243*38fd1498Szrj 	{
2244*38fd1498Szrj 	  df_dump_insn_problem_function insnfun;
2245*38fd1498Szrj 
2246*38fd1498Szrj 	  if (top)
2247*38fd1498Szrj 	    insnfun = dflow->problem->dump_insn_top_fun;
2248*38fd1498Szrj 	  else
2249*38fd1498Szrj 	    insnfun = dflow->problem->dump_insn_bottom_fun;
2250*38fd1498Szrj 
2251*38fd1498Szrj 	  if (insnfun)
2252*38fd1498Szrj 	    insnfun (insn, file);
2253*38fd1498Szrj 	}
2254*38fd1498Szrj     }
2255*38fd1498Szrj }
2256*38fd1498Szrj 
2257*38fd1498Szrj /* Dump information about INSN before dumping INSN itself.  */
2258*38fd1498Szrj 
2259*38fd1498Szrj void
df_dump_insn_top(const rtx_insn * insn,FILE * file)2260*38fd1498Szrj df_dump_insn_top (const rtx_insn *insn, FILE *file)
2261*38fd1498Szrj {
2262*38fd1498Szrj   df_dump_insn_problem_data (insn,  file, /*top=*/true);
2263*38fd1498Szrj }
2264*38fd1498Szrj 
2265*38fd1498Szrj /* Dump information about INSN after dumping INSN itself.  */
2266*38fd1498Szrj 
2267*38fd1498Szrj void
df_dump_insn_bottom(const rtx_insn * insn,FILE * file)2268*38fd1498Szrj df_dump_insn_bottom (const rtx_insn *insn, FILE *file)
2269*38fd1498Szrj {
2270*38fd1498Szrj   df_dump_insn_problem_data (insn,  file, /*top=*/false);
2271*38fd1498Szrj }
2272*38fd1498Szrj 
2273*38fd1498Szrj 
2274*38fd1498Szrj static void
df_ref_dump(df_ref ref,FILE * file)2275*38fd1498Szrj df_ref_dump (df_ref ref, FILE *file)
2276*38fd1498Szrj {
2277*38fd1498Szrj   fprintf (file, "%c%d(%d)",
2278*38fd1498Szrj 	   DF_REF_REG_DEF_P (ref)
2279*38fd1498Szrj 	   ? 'd'
2280*38fd1498Szrj 	   : (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
2281*38fd1498Szrj 	   DF_REF_ID (ref),
2282*38fd1498Szrj 	   DF_REF_REGNO (ref));
2283*38fd1498Szrj }
2284*38fd1498Szrj 
2285*38fd1498Szrj void
df_refs_chain_dump(df_ref ref,bool follow_chain,FILE * file)2286*38fd1498Szrj df_refs_chain_dump (df_ref ref, bool follow_chain, FILE *file)
2287*38fd1498Szrj {
2288*38fd1498Szrj   fprintf (file, "{ ");
2289*38fd1498Szrj   for (; ref; ref = DF_REF_NEXT_LOC (ref))
2290*38fd1498Szrj     {
2291*38fd1498Szrj       df_ref_dump (ref, file);
2292*38fd1498Szrj       if (follow_chain)
2293*38fd1498Szrj 	df_chain_dump (DF_REF_CHAIN (ref), file);
2294*38fd1498Szrj     }
2295*38fd1498Szrj   fprintf (file, "}");
2296*38fd1498Szrj }
2297*38fd1498Szrj 
2298*38fd1498Szrj 
2299*38fd1498Szrj /* Dump either a ref-def or reg-use chain.  */
2300*38fd1498Szrj 
2301*38fd1498Szrj void
df_regs_chain_dump(df_ref ref,FILE * file)2302*38fd1498Szrj df_regs_chain_dump (df_ref ref,  FILE *file)
2303*38fd1498Szrj {
2304*38fd1498Szrj   fprintf (file, "{ ");
2305*38fd1498Szrj   while (ref)
2306*38fd1498Szrj     {
2307*38fd1498Szrj       df_ref_dump (ref, file);
2308*38fd1498Szrj       ref = DF_REF_NEXT_REG (ref);
2309*38fd1498Szrj     }
2310*38fd1498Szrj   fprintf (file, "}");
2311*38fd1498Szrj }
2312*38fd1498Szrj 
2313*38fd1498Szrj 
2314*38fd1498Szrj static void
df_mws_dump(struct df_mw_hardreg * mws,FILE * file)2315*38fd1498Szrj df_mws_dump (struct df_mw_hardreg *mws, FILE *file)
2316*38fd1498Szrj {
2317*38fd1498Szrj   for (; mws; mws = DF_MWS_NEXT (mws))
2318*38fd1498Szrj     fprintf (file, "mw %c r[%d..%d]\n",
2319*38fd1498Szrj 	     DF_MWS_REG_DEF_P (mws) ? 'd' : 'u',
2320*38fd1498Szrj 	     mws->start_regno, mws->end_regno);
2321*38fd1498Szrj }
2322*38fd1498Szrj 
2323*38fd1498Szrj 
2324*38fd1498Szrj static void
df_insn_uid_debug(unsigned int uid,bool follow_chain,FILE * file)2325*38fd1498Szrj df_insn_uid_debug (unsigned int uid,
2326*38fd1498Szrj 		   bool follow_chain, FILE *file)
2327*38fd1498Szrj {
2328*38fd1498Szrj   fprintf (file, "insn %d luid %d",
2329*38fd1498Szrj 	   uid, DF_INSN_UID_LUID (uid));
2330*38fd1498Szrj 
2331*38fd1498Szrj   if (DF_INSN_UID_DEFS (uid))
2332*38fd1498Szrj     {
2333*38fd1498Szrj       fprintf (file, " defs ");
2334*38fd1498Szrj       df_refs_chain_dump (DF_INSN_UID_DEFS (uid), follow_chain, file);
2335*38fd1498Szrj     }
2336*38fd1498Szrj 
2337*38fd1498Szrj   if (DF_INSN_UID_USES (uid))
2338*38fd1498Szrj     {
2339*38fd1498Szrj       fprintf (file, " uses ");
2340*38fd1498Szrj       df_refs_chain_dump (DF_INSN_UID_USES (uid), follow_chain, file);
2341*38fd1498Szrj     }
2342*38fd1498Szrj 
2343*38fd1498Szrj   if (DF_INSN_UID_EQ_USES (uid))
2344*38fd1498Szrj     {
2345*38fd1498Szrj       fprintf (file, " eq uses ");
2346*38fd1498Szrj       df_refs_chain_dump (DF_INSN_UID_EQ_USES (uid), follow_chain, file);
2347*38fd1498Szrj     }
2348*38fd1498Szrj 
2349*38fd1498Szrj   if (DF_INSN_UID_MWS (uid))
2350*38fd1498Szrj     {
2351*38fd1498Szrj       fprintf (file, " mws ");
2352*38fd1498Szrj       df_mws_dump (DF_INSN_UID_MWS (uid), file);
2353*38fd1498Szrj     }
2354*38fd1498Szrj   fprintf (file, "\n");
2355*38fd1498Szrj }
2356*38fd1498Szrj 
2357*38fd1498Szrj 
2358*38fd1498Szrj DEBUG_FUNCTION void
df_insn_debug(rtx_insn * insn,bool follow_chain,FILE * file)2359*38fd1498Szrj df_insn_debug (rtx_insn *insn, bool follow_chain, FILE *file)
2360*38fd1498Szrj {
2361*38fd1498Szrj   df_insn_uid_debug (INSN_UID (insn), follow_chain, file);
2362*38fd1498Szrj }
2363*38fd1498Szrj 
2364*38fd1498Szrj DEBUG_FUNCTION void
df_insn_debug_regno(rtx_insn * insn,FILE * file)2365*38fd1498Szrj df_insn_debug_regno (rtx_insn *insn, FILE *file)
2366*38fd1498Szrj {
2367*38fd1498Szrj   struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2368*38fd1498Szrj 
2369*38fd1498Szrj   fprintf (file, "insn %d bb %d luid %d defs ",
2370*38fd1498Szrj 	   INSN_UID (insn), BLOCK_FOR_INSN (insn)->index,
2371*38fd1498Szrj 	   DF_INSN_INFO_LUID (insn_info));
2372*38fd1498Szrj   df_refs_chain_dump (DF_INSN_INFO_DEFS (insn_info), false, file);
2373*38fd1498Szrj 
2374*38fd1498Szrj   fprintf (file, " uses ");
2375*38fd1498Szrj   df_refs_chain_dump (DF_INSN_INFO_USES (insn_info), false, file);
2376*38fd1498Szrj 
2377*38fd1498Szrj   fprintf (file, " eq_uses ");
2378*38fd1498Szrj   df_refs_chain_dump (DF_INSN_INFO_EQ_USES (insn_info), false, file);
2379*38fd1498Szrj   fprintf (file, "\n");
2380*38fd1498Szrj }
2381*38fd1498Szrj 
2382*38fd1498Szrj DEBUG_FUNCTION void
df_regno_debug(unsigned int regno,FILE * file)2383*38fd1498Szrj df_regno_debug (unsigned int regno, FILE *file)
2384*38fd1498Szrj {
2385*38fd1498Szrj   fprintf (file, "reg %d defs ", regno);
2386*38fd1498Szrj   df_regs_chain_dump (DF_REG_DEF_CHAIN (regno), file);
2387*38fd1498Szrj   fprintf (file, " uses ");
2388*38fd1498Szrj   df_regs_chain_dump (DF_REG_USE_CHAIN (regno), file);
2389*38fd1498Szrj   fprintf (file, " eq_uses ");
2390*38fd1498Szrj   df_regs_chain_dump (DF_REG_EQ_USE_CHAIN (regno), file);
2391*38fd1498Szrj   fprintf (file, "\n");
2392*38fd1498Szrj }
2393*38fd1498Szrj 
2394*38fd1498Szrj 
2395*38fd1498Szrj DEBUG_FUNCTION void
df_ref_debug(df_ref ref,FILE * file)2396*38fd1498Szrj df_ref_debug (df_ref ref, FILE *file)
2397*38fd1498Szrj {
2398*38fd1498Szrj   fprintf (file, "%c%d ",
2399*38fd1498Szrj 	   DF_REF_REG_DEF_P (ref) ? 'd' : 'u',
2400*38fd1498Szrj 	   DF_REF_ID (ref));
2401*38fd1498Szrj   fprintf (file, "reg %d bb %d insn %d flag %#x type %#x ",
2402*38fd1498Szrj 	   DF_REF_REGNO (ref),
2403*38fd1498Szrj 	   DF_REF_BBNO (ref),
2404*38fd1498Szrj 	   DF_REF_IS_ARTIFICIAL (ref) ? -1 : DF_REF_INSN_UID (ref),
2405*38fd1498Szrj 	   DF_REF_FLAGS (ref),
2406*38fd1498Szrj 	   DF_REF_TYPE (ref));
2407*38fd1498Szrj   if (DF_REF_LOC (ref))
2408*38fd1498Szrj     {
2409*38fd1498Szrj       if (flag_dump_noaddr)
2410*38fd1498Szrj 	fprintf (file, "loc #(#) chain ");
2411*38fd1498Szrj       else
2412*38fd1498Szrj 	fprintf (file, "loc %p(%p) chain ", (void *)DF_REF_LOC (ref),
2413*38fd1498Szrj 		 (void *)*DF_REF_LOC (ref));
2414*38fd1498Szrj     }
2415*38fd1498Szrj   else
2416*38fd1498Szrj     fprintf (file, "chain ");
2417*38fd1498Szrj   df_chain_dump (DF_REF_CHAIN (ref), file);
2418*38fd1498Szrj   fprintf (file, "\n");
2419*38fd1498Szrj }
2420*38fd1498Szrj 
2421*38fd1498Szrj /* Functions for debugging from GDB.  */
2422*38fd1498Szrj 
2423*38fd1498Szrj DEBUG_FUNCTION void
debug_df_insn(rtx_insn * insn)2424*38fd1498Szrj debug_df_insn (rtx_insn *insn)
2425*38fd1498Szrj {
2426*38fd1498Szrj   df_insn_debug (insn, true, stderr);
2427*38fd1498Szrj   debug_rtx (insn);
2428*38fd1498Szrj }
2429*38fd1498Szrj 
2430*38fd1498Szrj 
2431*38fd1498Szrj DEBUG_FUNCTION void
debug_df_reg(rtx reg)2432*38fd1498Szrj debug_df_reg (rtx reg)
2433*38fd1498Szrj {
2434*38fd1498Szrj   df_regno_debug (REGNO (reg), stderr);
2435*38fd1498Szrj }
2436*38fd1498Szrj 
2437*38fd1498Szrj 
2438*38fd1498Szrj DEBUG_FUNCTION void
debug_df_regno(unsigned int regno)2439*38fd1498Szrj debug_df_regno (unsigned int regno)
2440*38fd1498Szrj {
2441*38fd1498Szrj   df_regno_debug (regno, stderr);
2442*38fd1498Szrj }
2443*38fd1498Szrj 
2444*38fd1498Szrj 
2445*38fd1498Szrj DEBUG_FUNCTION void
debug_df_ref(df_ref ref)2446*38fd1498Szrj debug_df_ref (df_ref ref)
2447*38fd1498Szrj {
2448*38fd1498Szrj   df_ref_debug (ref, stderr);
2449*38fd1498Szrj }
2450*38fd1498Szrj 
2451*38fd1498Szrj 
2452*38fd1498Szrj DEBUG_FUNCTION void
debug_df_defno(unsigned int defno)2453*38fd1498Szrj debug_df_defno (unsigned int defno)
2454*38fd1498Szrj {
2455*38fd1498Szrj   df_ref_debug (DF_DEFS_GET (defno), stderr);
2456*38fd1498Szrj }
2457*38fd1498Szrj 
2458*38fd1498Szrj 
2459*38fd1498Szrj DEBUG_FUNCTION void
debug_df_useno(unsigned int defno)2460*38fd1498Szrj debug_df_useno (unsigned int defno)
2461*38fd1498Szrj {
2462*38fd1498Szrj   df_ref_debug (DF_USES_GET (defno), stderr);
2463*38fd1498Szrj }
2464*38fd1498Szrj 
2465*38fd1498Szrj 
2466*38fd1498Szrj DEBUG_FUNCTION void
debug_df_chain(struct df_link * link)2467*38fd1498Szrj debug_df_chain (struct df_link *link)
2468*38fd1498Szrj {
2469*38fd1498Szrj   df_chain_dump (link, stderr);
2470*38fd1498Szrj   fputc ('\n', stderr);
2471*38fd1498Szrj }
2472