OSDN Git Service

2010-12-09 Martin Jambor <mjambor@suse.cz>
[pf3gnuchains/gcc-fork.git] / gcc / df-scan.c
1 /* Scanning of rtl for dataflow analysis.
2    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3    2008, 2009, 2010 Free Software Foundation, Inc.
4    Originally contributed by Michael P. Hayes
5              (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6    Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7              and Kenneth Zadeck (zadeck@naturalbridge.com).
8
9 This file is part of GCC.
10
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
15
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3.  If not see
23 <http://www.gnu.org/licenses/>.  */
24
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "recog.h"
33 #include "function.h"
34 #include "regs.h"
35 #include "output.h"
36 #include "alloc-pool.h"
37 #include "flags.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "sbitmap.h"
41 #include "bitmap.h"
42 #include "timevar.h"
43 #include "tree.h"
44 #include "target.h"
45 #include "target-def.h"
46 #include "df.h"
47 #include "tree-pass.h"
48 #include "emit-rtl.h"  /* FIXME: Can go away once crtl is moved to rtl.h.  */
49
50 DEF_VEC_P(df_ref);
51 DEF_VEC_ALLOC_P_STACK(df_ref);
52
53 #define VEC_df_ref_stack_alloc(alloc) VEC_stack_alloc (df_ref, alloc)
54
55 typedef struct df_mw_hardreg *df_mw_hardreg_ptr;
56
57 DEF_VEC_P(df_mw_hardreg_ptr);
58 DEF_VEC_ALLOC_P_STACK(df_mw_hardreg_ptr);
59
60 #define VEC_df_mw_hardreg_ptr_stack_alloc(alloc) \
61   VEC_stack_alloc (df_mw_hardreg_ptr, alloc)
62
63 #ifndef HAVE_epilogue
64 #define HAVE_epilogue 0
65 #endif
66 #ifndef HAVE_prologue
67 #define HAVE_prologue 0
68 #endif
69 #ifndef HAVE_sibcall_epilogue
70 #define HAVE_sibcall_epilogue 0
71 #endif
72
73 #ifndef EPILOGUE_USES
74 #define EPILOGUE_USES(REGNO)  0
75 #endif
76
77 /* The following two macros free the vecs that hold either the refs or
78    the mw refs.  They are a little tricky because the vec has 0
79    elements is special and is not to be freed.  */
80 #define df_scan_free_ref_vec(V) \
81   do { \
82     if (V && *V) \
83       free (V);  \
84   } while (0)
85
86 #define df_scan_free_mws_vec(V) \
87   do { \
88     if (V && *V) \
89       free (V);  \
90   } while (0)
91
92 /* The set of hard registers in eliminables[i].from. */
93
94 static HARD_REG_SET elim_reg_set;
95
96 /* Initialize ur_in and ur_out as if all hard registers were partially
97    available.  */
98
99 struct df_collection_rec
100 {
101   VEC(df_ref,stack) *def_vec;
102   VEC(df_ref,stack) *use_vec;
103   VEC(df_ref,stack) *eq_use_vec;
104   VEC(df_mw_hardreg_ptr,stack) *mw_vec;
105 };
106
107 static df_ref df_null_ref_rec[1];
108 static struct df_mw_hardreg * df_null_mw_rec[1];
109
110 static void df_ref_record (enum df_ref_class, struct df_collection_rec *,
111                            rtx, rtx *,
112                            basic_block, struct df_insn_info *,
113                            enum df_ref_type, int ref_flags);
114 static void df_def_record_1 (struct df_collection_rec *, rtx,
115                              basic_block, struct df_insn_info *,
116                              int ref_flags);
117 static void df_defs_record (struct df_collection_rec *, rtx,
118                             basic_block, struct df_insn_info *,
119                             int ref_flags);
120 static void df_uses_record (struct df_collection_rec *,
121                             rtx *, enum df_ref_type,
122                             basic_block, struct df_insn_info *,
123                             int ref_flags);
124
125 static void df_install_ref_incremental (df_ref);
126 static df_ref df_ref_create_structure (enum df_ref_class,
127                                        struct df_collection_rec *, rtx, rtx *,
128                                        basic_block, struct df_insn_info *,
129                                        enum df_ref_type, int ref_flags);
130 static void df_insn_refs_collect (struct df_collection_rec*,
131                                   basic_block, struct df_insn_info *);
132 static void df_canonize_collection_rec (struct df_collection_rec *);
133
134 static void df_get_regular_block_artificial_uses (bitmap);
135 static void df_get_eh_block_artificial_uses (bitmap);
136
137 static void df_record_entry_block_defs (bitmap);
138 static void df_record_exit_block_uses (bitmap);
139 static void df_get_exit_block_use_set (bitmap);
140 static void df_get_entry_block_def_set (bitmap);
141 static void df_grow_ref_info (struct df_ref_info *, unsigned int);
142 static void df_ref_chain_delete_du_chain (df_ref *);
143 static void df_ref_chain_delete (df_ref *);
144
145 static void df_refs_add_to_chains (struct df_collection_rec *,
146                                    basic_block, rtx);
147
148 static bool df_insn_refs_verify (struct df_collection_rec *, basic_block, rtx, bool);
149 static void df_entry_block_defs_collect (struct df_collection_rec *, bitmap);
150 static void df_exit_block_uses_collect (struct df_collection_rec *, bitmap);
151 static void df_install_ref (df_ref, struct df_reg_info *,
152                             struct df_ref_info *, bool);
153
154 static int df_ref_compare (const void *, const void *);
155 static int df_mw_compare (const void *, const void *);
156
157 /* Indexed by hardware reg number, is true if that register is ever
158    used in the current function.
159
160    In df-scan.c, this is set up to record the hard regs used
161    explicitly.  Reload adds in the hard regs used for holding pseudo
162    regs.  Final uses it to generate the code in the function prologue
163    and epilogue to save and restore registers as needed.  */
164
165 static bool regs_ever_live[FIRST_PSEUDO_REGISTER];
166 \f
167 /*----------------------------------------------------------------------------
168    SCANNING DATAFLOW PROBLEM
169
170    There are several ways in which scanning looks just like the other
171    dataflow problems.  It shares the all the mechanisms for local info
172    as well as basic block info.  Where it differs is when and how often
173    it gets run.  It also has no need for the iterative solver.
174 ----------------------------------------------------------------------------*/
175
176 /* Problem data for the scanning dataflow function.  */
177 struct df_scan_problem_data
178 {
179   alloc_pool ref_base_pool;
180   alloc_pool ref_artificial_pool;
181   alloc_pool ref_regular_pool;
182   alloc_pool insn_pool;
183   alloc_pool reg_pool;
184   alloc_pool mw_reg_pool;
185   bitmap_obstack reg_bitmaps;
186   bitmap_obstack insn_bitmaps;
187 };
188
189 typedef struct df_scan_bb_info *df_scan_bb_info_t;
190
191
192 /* Internal function to shut down the scanning problem.  */
193 static void
194 df_scan_free_internal (void)
195 {
196   struct df_scan_problem_data *problem_data
197     = (struct df_scan_problem_data *) df_scan->problem_data;
198   unsigned int i;
199   basic_block bb;
200
201   /* The vectors that hold the refs are not pool allocated because
202      they come in many sizes.  This makes them impossible to delete
203      all at once.  */
204   for (i = 0; i < DF_INSN_SIZE(); i++)
205     {
206       struct df_insn_info *insn_info = DF_INSN_UID_GET(i);
207       /* Skip the insns that have no insn_info or have been
208          deleted.  */
209       if (insn_info)
210         {
211           df_scan_free_ref_vec (insn_info->defs);
212           df_scan_free_ref_vec (insn_info->uses);
213           df_scan_free_ref_vec (insn_info->eq_uses);
214           df_scan_free_mws_vec (insn_info->mw_hardregs);
215         }
216     }
217
218   FOR_ALL_BB (bb)
219     {
220       unsigned int bb_index = bb->index;
221       struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
222       if (bb_info)
223         {
224           df_scan_free_ref_vec (bb_info->artificial_defs);
225           df_scan_free_ref_vec (bb_info->artificial_uses);
226         }
227     }
228
229   free (df->def_info.refs);
230   free (df->def_info.begin);
231   free (df->def_info.count);
232   memset (&df->def_info, 0, (sizeof (struct df_ref_info)));
233
234   free (df->use_info.refs);
235   free (df->use_info.begin);
236   free (df->use_info.count);
237   memset (&df->use_info, 0, (sizeof (struct df_ref_info)));
238
239   free (df->def_regs);
240   df->def_regs = NULL;
241   free (df->use_regs);
242   df->use_regs = NULL;
243   free (df->eq_use_regs);
244   df->eq_use_regs = NULL;
245   df->regs_size = 0;
246   DF_REG_SIZE(df) = 0;
247
248   free (df->insns);
249   df->insns = NULL;
250   DF_INSN_SIZE () = 0;
251
252   free (df_scan->block_info);
253   df_scan->block_info = NULL;
254   df_scan->block_info_size = 0;
255
256   bitmap_clear (&df->hardware_regs_used);
257   bitmap_clear (&df->regular_block_artificial_uses);
258   bitmap_clear (&df->eh_block_artificial_uses);
259   BITMAP_FREE (df->entry_block_defs);
260   BITMAP_FREE (df->exit_block_uses);
261   bitmap_clear (&df->insns_to_delete);
262   bitmap_clear (&df->insns_to_rescan);
263   bitmap_clear (&df->insns_to_notes_rescan);
264
265   free_alloc_pool (problem_data->ref_base_pool);
266   free_alloc_pool (problem_data->ref_artificial_pool);
267   free_alloc_pool (problem_data->ref_regular_pool);
268   free_alloc_pool (problem_data->insn_pool);
269   free_alloc_pool (problem_data->reg_pool);
270   free_alloc_pool (problem_data->mw_reg_pool);
271   bitmap_obstack_release (&problem_data->reg_bitmaps);
272   bitmap_obstack_release (&problem_data->insn_bitmaps);
273   free (df_scan->problem_data);
274 }
275
276
277 /* Free basic block info.  */
278
279 static void
280 df_scan_free_bb_info (basic_block bb, void *vbb_info)
281 {
282   struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
283   unsigned int bb_index = bb->index;
284
285   /* See if bb_info is initialized.  */
286   if (bb_info->artificial_defs)
287     {
288       rtx insn;
289       FOR_BB_INSNS (bb, insn)
290         {
291           if (INSN_P (insn))
292             /* Record defs within INSN.  */
293             df_insn_delete (bb, INSN_UID (insn));
294         }
295
296       if (bb_index < df_scan->block_info_size)
297         bb_info = df_scan_get_bb_info (bb_index);
298
299       /* Get rid of any artificial uses or defs.  */
300       if (bb_info->artificial_defs)
301         {
302           df_ref_chain_delete_du_chain (bb_info->artificial_defs);
303           df_ref_chain_delete_du_chain (bb_info->artificial_uses);
304           df_ref_chain_delete (bb_info->artificial_defs);
305           df_ref_chain_delete (bb_info->artificial_uses);
306           bb_info->artificial_defs = NULL;
307           bb_info->artificial_uses = NULL;
308         }
309     }
310 }
311
312
313 /* Allocate the problem data for the scanning problem.  This should be
314    called when the problem is created or when the entire function is to
315    be rescanned.  */
316 void
317 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
318 {
319   struct df_scan_problem_data *problem_data;
320   unsigned int insn_num = get_max_uid () + 1;
321   unsigned int block_size = 400;
322   basic_block bb;
323
324   /* Given the number of pools, this is really faster than tearing
325      everything apart.  */
326   if (df_scan->problem_data)
327     df_scan_free_internal ();
328
329   problem_data = XNEW (struct df_scan_problem_data);
330   df_scan->problem_data = problem_data;
331   df_scan->computed = true;
332
333   problem_data->ref_base_pool
334     = create_alloc_pool ("df_scan ref base",
335                          sizeof (struct df_base_ref), block_size);
336   problem_data->ref_artificial_pool
337     = create_alloc_pool ("df_scan ref artificial",
338                          sizeof (struct df_artificial_ref), block_size);
339   problem_data->ref_regular_pool
340     = create_alloc_pool ("df_scan ref regular",
341                          sizeof (struct df_regular_ref), block_size);
342   problem_data->insn_pool
343     = create_alloc_pool ("df_scan insn",
344                          sizeof (struct df_insn_info), block_size);
345   problem_data->reg_pool
346     = create_alloc_pool ("df_scan reg",
347                          sizeof (struct df_reg_info), block_size);
348   problem_data->mw_reg_pool
349     = create_alloc_pool ("df_scan mw_reg",
350                          sizeof (struct df_mw_hardreg), block_size);
351
352   bitmap_obstack_initialize (&problem_data->reg_bitmaps);
353   bitmap_obstack_initialize (&problem_data->insn_bitmaps);
354
355   insn_num += insn_num / 4;
356   df_grow_reg_info ();
357
358   df_grow_insn_info ();
359   df_grow_bb_info (df_scan);
360
361   FOR_ALL_BB (bb)
362     {
363       unsigned int bb_index = bb->index;
364       struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
365       bb_info->artificial_defs = NULL;
366       bb_info->artificial_uses = NULL;
367     }
368
369   bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps);
370   bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps);
371   bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps);
372   df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
373   df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
374   bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps);
375   bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps);
376   bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps);
377   df_scan->optional_p = false;
378 }
379
380
381 /* Free all of the data associated with the scan problem.  */
382
383 static void
384 df_scan_free (void)
385 {
386   if (df_scan->problem_data)
387     df_scan_free_internal ();
388
389   if (df->blocks_to_analyze)
390     {
391       BITMAP_FREE (df->blocks_to_analyze);
392       df->blocks_to_analyze = NULL;
393     }
394
395   free (df_scan);
396 }
397
398 /* Dump the preamble for DF_SCAN dump. */
399 static void
400 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
401 {
402   int i;
403   int dcount = 0;
404   int ucount = 0;
405   int ecount = 0;
406   int icount = 0;
407   int ccount = 0;
408   basic_block bb;
409   rtx insn;
410
411   fprintf (file, ";;  invalidated by call \t");
412   df_print_regset (file, regs_invalidated_by_call_regset);
413   fprintf (file, ";;  hardware regs used \t");
414   df_print_regset (file, &df->hardware_regs_used);
415   fprintf (file, ";;  regular block artificial uses \t");
416   df_print_regset (file, &df->regular_block_artificial_uses);
417   fprintf (file, ";;  eh block artificial uses \t");
418   df_print_regset (file, &df->eh_block_artificial_uses);
419   fprintf (file, ";;  entry block defs \t");
420   df_print_regset (file, df->entry_block_defs);
421   fprintf (file, ";;  exit block uses \t");
422   df_print_regset (file, df->exit_block_uses);
423   fprintf (file, ";;  regs ever live \t");
424   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
425     if (df_regs_ever_live_p (i))
426       fprintf (file, " %d[%s]", i, reg_names[i]);
427   fprintf (file, "\n;;  ref usage \t");
428
429   for (i = 0; i < (int)df->regs_inited; i++)
430     if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i))
431       {
432         const char * sep = "";
433
434         fprintf (file, "r%d={", i);
435         if (DF_REG_DEF_COUNT (i))
436           {
437             fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
438             sep = ",";
439             dcount += DF_REG_DEF_COUNT (i);
440           }
441         if (DF_REG_USE_COUNT (i))
442           {
443             fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
444             sep = ",";
445             ucount += DF_REG_USE_COUNT (i);
446           }
447         if (DF_REG_EQ_USE_COUNT (i))
448           {
449             fprintf (file, "%s%de", sep, DF_REG_EQ_USE_COUNT (i));
450             ecount += DF_REG_EQ_USE_COUNT (i);
451           }
452         fprintf (file, "} ");
453       }
454
455   FOR_EACH_BB (bb)
456     FOR_BB_INSNS (bb, insn)
457       if (INSN_P (insn))
458         {
459           if (CALL_P (insn))
460             ccount++;
461           else
462             icount++;
463         }
464
465   fprintf (file, "\n;;    total ref usage %d{%dd,%du,%de}"
466                  " in %d{%d regular + %d call} insns.\n",
467                  dcount + ucount + ecount, dcount, ucount, ecount,
468                  icount + ccount, icount, ccount);
469 }
470
471 /* Dump the bb_info for a given basic block. */
472 static void
473 df_scan_start_block (basic_block bb, FILE *file)
474 {
475   struct df_scan_bb_info *bb_info
476     = df_scan_get_bb_info (bb->index);
477
478   if (bb_info)
479     {
480       fprintf (file, ";; bb %d artificial_defs: ", bb->index);
481       df_refs_chain_dump (bb_info->artificial_defs, true, file);
482       fprintf (file, "\n;; bb %d artificial_uses: ", bb->index);
483       df_refs_chain_dump (bb_info->artificial_uses, true, file);
484       fprintf (file, "\n");
485     }
486 #if 0
487   {
488     rtx insn;
489     FOR_BB_INSNS (bb, insn)
490       if (INSN_P (insn))
491         df_insn_debug (insn, false, file);
492   }
493 #endif
494 }
495
496 static struct df_problem problem_SCAN =
497 {
498   DF_SCAN,                    /* Problem id.  */
499   DF_NONE,                    /* Direction.  */
500   df_scan_alloc,              /* Allocate the problem specific data.  */
501   NULL,                       /* Reset global information.  */
502   df_scan_free_bb_info,       /* Free basic block info.  */
503   NULL,                       /* Local compute function.  */
504   NULL,                       /* Init the solution specific data.  */
505   NULL,                       /* Iterative solver.  */
506   NULL,                       /* Confluence operator 0.  */
507   NULL,                       /* Confluence operator n.  */
508   NULL,                       /* Transfer function.  */
509   NULL,                       /* Finalize function.  */
510   df_scan_free,               /* Free all of the problem information.  */
511   NULL,                       /* Remove this problem from the stack of dataflow problems.  */
512   df_scan_start_dump,         /* Debugging.  */
513   df_scan_start_block,        /* Debugging start block.  */
514   NULL,                       /* Debugging end block.  */
515   NULL,                       /* Incremental solution verify start.  */
516   NULL,                       /* Incremental solution verify end.  */
517   NULL,                       /* Dependent problem.  */
518   sizeof (struct df_scan_bb_info),/* Size of entry of block_info array.  */
519   TV_DF_SCAN,                 /* Timing variable.  */
520   false                       /* Reset blocks on dropping out of blocks_to_analyze.  */
521 };
522
523
524 /* Create a new DATAFLOW instance and add it to an existing instance
525    of DF.  The returned structure is what is used to get at the
526    solution.  */
527
528 void
529 df_scan_add_problem (void)
530 {
531   df_add_problem (&problem_SCAN);
532 }
533
534 \f
535 /*----------------------------------------------------------------------------
536    Storage Allocation Utilities
537 ----------------------------------------------------------------------------*/
538
539
540 /* First, grow the reg_info information.  If the current size is less than
541    the number of pseudos, grow to 25% more than the number of
542    pseudos.
543
544    Second, assure that all of the slots up to max_reg_num have been
545    filled with reg_info structures.  */
546
547 void
548 df_grow_reg_info (void)
549 {
550   unsigned int max_reg = max_reg_num ();
551   unsigned int new_size = max_reg;
552   struct df_scan_problem_data *problem_data
553     = (struct df_scan_problem_data *) df_scan->problem_data;
554   unsigned int i;
555
556   if (df->regs_size < new_size)
557     {
558       new_size += new_size / 4;
559       df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
560       df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
561       df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
562                                     new_size);
563       df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
564       df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
565       df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
566       df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
567       df->regs_size = new_size;
568     }
569
570   for (i = df->regs_inited; i < max_reg; i++)
571     {
572       struct df_reg_info *reg_info;
573
574       reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
575       memset (reg_info, 0, sizeof (struct df_reg_info));
576       df->def_regs[i] = reg_info;
577       reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
578       memset (reg_info, 0, sizeof (struct df_reg_info));
579       df->use_regs[i] = reg_info;
580       reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
581       memset (reg_info, 0, sizeof (struct df_reg_info));
582       df->eq_use_regs[i] = reg_info;
583       df->def_info.begin[i] = 0;
584       df->def_info.count[i] = 0;
585       df->use_info.begin[i] = 0;
586       df->use_info.count[i] = 0;
587     }
588
589   df->regs_inited = max_reg;
590 }
591
592
593 /* Grow the ref information.  */
594
595 static void
596 df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
597 {
598   if (ref_info->refs_size < new_size)
599     {
600       ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
601       memset (ref_info->refs + ref_info->refs_size, 0,
602               (new_size - ref_info->refs_size) *sizeof (df_ref));
603       ref_info->refs_size = new_size;
604     }
605 }
606
607
608 /* Check and grow the ref information if necessary.  This routine
609    guarantees total_size + BITMAP_ADDEND amount of entries in refs
610    array.  It updates ref_info->refs_size only and does not change
611    ref_info->total_size.  */
612
613 static void
614 df_check_and_grow_ref_info (struct df_ref_info *ref_info,
615                             unsigned bitmap_addend)
616 {
617   if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
618     {
619       int new_size = ref_info->total_size + bitmap_addend;
620       new_size += ref_info->total_size / 4;
621       df_grow_ref_info (ref_info, new_size);
622     }
623 }
624
625
626 /* Grow the ref information.  If the current size is less than the
627    number of instructions, grow to 25% more than the number of
628    instructions.  */
629
630 void
631 df_grow_insn_info (void)
632 {
633   unsigned int new_size = get_max_uid () + 1;
634   if (DF_INSN_SIZE () < new_size)
635     {
636       new_size += new_size / 4;
637       df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
638       memset (df->insns + df->insns_size, 0,
639               (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
640       DF_INSN_SIZE () = new_size;
641     }
642 }
643
644
645
646 \f
647 /*----------------------------------------------------------------------------
648    PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
649 ----------------------------------------------------------------------------*/
650
651 /* Rescan all of the block_to_analyze or all of the blocks in the
652    function if df_set_blocks if blocks_to_analyze is NULL;  */
653
654 void
655 df_scan_blocks (void)
656 {
657   basic_block bb;
658
659   df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
660   df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
661
662   df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses);
663   df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses);
664
665   bitmap_ior_into (&df->eh_block_artificial_uses,
666                    &df->regular_block_artificial_uses);
667
668   /* ENTRY and EXIT blocks have special defs/uses.  */
669   df_get_entry_block_def_set (df->entry_block_defs);
670   df_record_entry_block_defs (df->entry_block_defs);
671   df_get_exit_block_use_set (df->exit_block_uses);
672   df_record_exit_block_uses (df->exit_block_uses);
673   df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
674   df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
675
676   /* Regular blocks */
677   FOR_EACH_BB (bb)
678     {
679       unsigned int bb_index = bb->index;
680       df_bb_refs_record (bb_index, true);
681     }
682 }
683
684 /* Create new refs under address LOC within INSN.  This function is
685    only used externally.  REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
686    depending on whether LOC is inside PATTERN (INSN) or a note.  */
687
688 void
689 df_uses_create (rtx *loc, rtx insn, int ref_flags)
690 {
691   gcc_assert (!(ref_flags & ~DF_REF_IN_NOTE));
692   df_uses_record (NULL, loc, DF_REF_REG_USE,
693                   BLOCK_FOR_INSN (insn),
694                   DF_INSN_INFO_GET (insn),
695                   ref_flags);
696 }
697
698 /* Create a new ref of type DF_REF_TYPE for register REG at address
699    LOC within INSN of BB.  This function is only used externally.  */
700
701 df_ref
702 df_ref_create (rtx reg, rtx *loc, rtx insn,
703                basic_block bb,
704                enum df_ref_type ref_type,
705                int ref_flags)
706 {
707   enum df_ref_class cl;
708
709   df_grow_reg_info ();
710
711   /* You cannot hack artificial refs.  */
712   gcc_assert (insn);
713
714   if (loc)
715     cl = DF_REF_REGULAR;
716   else
717     cl = DF_REF_BASE;
718
719   return df_ref_create_structure (cl, NULL, reg, loc, bb,
720                                   DF_INSN_INFO_GET (insn),
721                                   ref_type, ref_flags);
722 }
723
724 static void
725 df_install_ref_incremental (df_ref ref)
726 {
727   struct df_reg_info **reg_info;
728   struct df_ref_info *ref_info;
729   df_ref *ref_rec;
730   df_ref **ref_rec_ptr;
731   unsigned int count = 0;
732   bool add_to_table;
733
734   rtx insn = DF_REF_INSN (ref);
735   basic_block bb = BLOCK_FOR_INSN (insn);
736
737   if (DF_REF_REG_DEF_P (ref))
738     {
739       reg_info = df->def_regs;
740       ref_info = &df->def_info;
741       ref_rec_ptr = &DF_INSN_DEFS (insn);
742       add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
743     }
744   else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
745     {
746       reg_info = df->eq_use_regs;
747       ref_info = &df->use_info;
748       ref_rec_ptr = &DF_INSN_EQ_USES (insn);
749       switch (ref_info->ref_order)
750         {
751         case DF_REF_ORDER_UNORDERED_WITH_NOTES:
752         case DF_REF_ORDER_BY_REG_WITH_NOTES:
753         case DF_REF_ORDER_BY_INSN_WITH_NOTES:
754           add_to_table = true;
755           break;
756         default:
757           add_to_table = false;
758           break;
759         }
760     }
761   else
762     {
763       reg_info = df->use_regs;
764       ref_info = &df->use_info;
765       ref_rec_ptr = &DF_INSN_USES (insn);
766       add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
767     }
768
769   /* Do not add if ref is not in the right blocks.  */
770   if (add_to_table && df->analyze_subset)
771     add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
772
773   df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
774
775   if (add_to_table)
776     switch (ref_info->ref_order)
777       {
778       case DF_REF_ORDER_UNORDERED_WITH_NOTES:
779       case DF_REF_ORDER_BY_REG_WITH_NOTES:
780       case DF_REF_ORDER_BY_INSN_WITH_NOTES:
781         ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
782         break;
783       default:
784         ref_info->ref_order = DF_REF_ORDER_UNORDERED;
785         break;
786       }
787
788   ref_rec = *ref_rec_ptr;
789   while (*ref_rec)
790     {
791       count++;
792       ref_rec++;
793     }
794
795   ref_rec = *ref_rec_ptr;
796   if (count)
797     {
798       ref_rec = XRESIZEVEC (df_ref, ref_rec, count+2);
799       *ref_rec_ptr = ref_rec;
800       ref_rec[count] = ref;
801       ref_rec[count+1] = NULL;
802       qsort (ref_rec, count + 1, sizeof (df_ref), df_ref_compare);
803     }
804   else
805     {
806       df_ref *ref_rec = XNEWVEC (df_ref, 2);
807       ref_rec[0] = ref;
808       ref_rec[1] = NULL;
809       *ref_rec_ptr = ref_rec;
810     }
811
812 #if 0
813   if (dump_file)
814     {
815       fprintf (dump_file, "adding ref ");
816       df_ref_debug (ref, dump_file);
817     }
818 #endif
819   /* By adding the ref directly, df_insn_rescan my not find any
820      differences even though the block will have changed.  So we need
821      to mark the block dirty ourselves.  */
822   if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
823     df_set_bb_dirty (bb);
824 }
825
826
827 \f
828 /*----------------------------------------------------------------------------
829    UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
830 ----------------------------------------------------------------------------*/
831
832 static void
833 df_free_ref (df_ref ref)
834 {
835   struct df_scan_problem_data *problem_data
836     = (struct df_scan_problem_data *) df_scan->problem_data;
837
838   switch (DF_REF_CLASS (ref))
839     {
840     case DF_REF_BASE:
841       pool_free (problem_data->ref_base_pool, ref);
842       break;
843
844     case DF_REF_ARTIFICIAL:
845       pool_free (problem_data->ref_artificial_pool, ref);
846       break;
847
848     case DF_REF_REGULAR:
849       pool_free (problem_data->ref_regular_pool, ref);
850       break;
851     }
852 }
853
854
855 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
856    Also delete the def-use or use-def chain if it exists.  */
857
858 static void
859 df_reg_chain_unlink (df_ref ref)
860 {
861   df_ref next = DF_REF_NEXT_REG (ref);
862   df_ref prev = DF_REF_PREV_REG (ref);
863   int id = DF_REF_ID (ref);
864   struct df_reg_info *reg_info;
865   df_ref *refs = NULL;
866
867   if (DF_REF_REG_DEF_P (ref))
868     {
869       int regno = DF_REF_REGNO (ref);
870       reg_info = DF_REG_DEF_GET (regno);
871       refs = df->def_info.refs;
872     }
873   else
874     {
875       if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
876         {
877           reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
878           switch (df->use_info.ref_order)
879             {
880             case DF_REF_ORDER_UNORDERED_WITH_NOTES:
881             case DF_REF_ORDER_BY_REG_WITH_NOTES:
882             case DF_REF_ORDER_BY_INSN_WITH_NOTES:
883               refs = df->use_info.refs;
884               break;
885             default:
886               break;
887             }
888         }
889       else
890         {
891           reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
892           refs = df->use_info.refs;
893         }
894     }
895
896   if (refs)
897     {
898       if (df->analyze_subset)
899         {
900           if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
901             refs[id] = NULL;
902         }
903       else
904         refs[id] = NULL;
905     }
906
907   /* Delete any def-use or use-def chains that start here. It is
908      possible that there is trash in this field.  This happens for
909      insns that have been deleted when rescanning has been deferred
910      and the chain problem has also been deleted.  The chain tear down
911      code skips deleted insns.  */
912   if (df_chain && DF_REF_CHAIN (ref))
913     df_chain_unlink (ref);
914
915   reg_info->n_refs--;
916   if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
917     {
918       gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
919       df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
920     }
921
922   /* Unlink from the reg chain.  If there is no prev, this is the
923      first of the list.  If not, just join the next and prev.  */
924   if (prev)
925     DF_REF_NEXT_REG (prev) = next;
926   else
927     {
928       gcc_assert (reg_info->reg_chain == ref);
929       reg_info->reg_chain = next;
930     }
931   if (next)
932     DF_REF_PREV_REG (next) = prev;
933
934   df_free_ref (ref);
935 }
936
937
938 /* Remove REF from VEC.  */
939
940 static void
941 df_ref_compress_rec (df_ref **vec_ptr, df_ref ref)
942 {
943   df_ref *vec = *vec_ptr;
944
945   if (vec[1])
946     {
947       while (*vec && *vec != ref)
948         vec++;
949
950       while (*vec)
951         {
952           *vec = *(vec+1);
953           vec++;
954         }
955     }
956   else
957     {
958       free (vec);
959       *vec_ptr = df_null_ref_rec;
960     }
961 }
962
963
964 /* Unlink REF from all def-use/use-def chains, etc.  */
965
966 void
967 df_ref_remove (df_ref ref)
968 {
969 #if 0
970   if (dump_file)
971     {
972       fprintf (dump_file, "removing ref ");
973       df_ref_debug (ref, dump_file);
974     }
975 #endif
976
977   if (DF_REF_REG_DEF_P (ref))
978     {
979       if (DF_REF_IS_ARTIFICIAL (ref))
980         {
981           struct df_scan_bb_info *bb_info
982             = df_scan_get_bb_info (DF_REF_BBNO (ref));
983           df_ref_compress_rec (&bb_info->artificial_defs, ref);
984         }
985       else
986         {
987           unsigned int uid = DF_REF_INSN_UID (ref);
988           struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
989           df_ref_compress_rec (&insn_rec->defs, ref);
990         }
991     }
992   else
993     {
994       if (DF_REF_IS_ARTIFICIAL (ref))
995         {
996           struct df_scan_bb_info *bb_info
997             = df_scan_get_bb_info (DF_REF_BBNO (ref));
998           df_ref_compress_rec (&bb_info->artificial_uses, ref);
999         }
1000       else
1001         {
1002           unsigned int uid = DF_REF_INSN_UID (ref);
1003           struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
1004
1005           if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
1006             df_ref_compress_rec (&insn_rec->eq_uses, ref);
1007           else
1008             df_ref_compress_rec (&insn_rec->uses, ref);
1009         }
1010     }
1011
1012   /* By deleting the ref directly, df_insn_rescan my not find any
1013      differences even though the block will have changed.  So we need
1014      to mark the block dirty ourselves.  */
1015   if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
1016     df_set_bb_dirty (DF_REF_BB (ref));
1017   df_reg_chain_unlink (ref);
1018 }
1019
1020
1021 /* Create the insn record for INSN.  If there was one there, zero it
1022    out.  */
1023
1024 struct df_insn_info *
1025 df_insn_create_insn_record (rtx insn)
1026 {
1027   struct df_scan_problem_data *problem_data
1028     = (struct df_scan_problem_data *) df_scan->problem_data;
1029   struct df_insn_info *insn_rec;
1030
1031   df_grow_insn_info ();
1032   insn_rec = DF_INSN_INFO_GET (insn);
1033   if (!insn_rec)
1034     {
1035       insn_rec = (struct df_insn_info *) pool_alloc (problem_data->insn_pool);
1036       DF_INSN_INFO_SET (insn, insn_rec);
1037     }
1038   memset (insn_rec, 0, sizeof (struct df_insn_info));
1039   insn_rec->insn = insn;
1040   return insn_rec;
1041 }
1042
1043
1044 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain.  */
1045
1046 static void
1047 df_ref_chain_delete_du_chain (df_ref *ref_rec)
1048 {
1049   while (*ref_rec)
1050     {
1051       df_ref ref = *ref_rec;
1052       /* CHAIN is allocated by DF_CHAIN. So make sure to
1053          pass df_scan instance for the problem.  */
1054       if (DF_REF_CHAIN (ref))
1055         df_chain_unlink (ref);
1056       ref_rec++;
1057     }
1058 }
1059
1060
1061 /* Delete all refs in the ref chain.  */
1062
1063 static void
1064 df_ref_chain_delete (df_ref *ref_rec)
1065 {
1066   df_ref *start = ref_rec;
1067   while (*ref_rec)
1068     {
1069       df_reg_chain_unlink (*ref_rec);
1070       ref_rec++;
1071     }
1072
1073   /* If the list is empty, it has a special shared element that is not
1074      to be deleted.  */
1075   if (*start)
1076     free (start);
1077 }
1078
1079
1080 /* Delete the hardreg chain.  */
1081
1082 static void
1083 df_mw_hardreg_chain_delete (struct df_mw_hardreg **hardregs)
1084 {
1085   struct df_scan_problem_data *problem_data;
1086
1087   if (!hardregs)
1088     return;
1089
1090   problem_data = (struct df_scan_problem_data *) df_scan->problem_data;
1091
1092   while (*hardregs)
1093     {
1094       pool_free (problem_data->mw_reg_pool, *hardregs);
1095       hardregs++;
1096     }
1097 }
1098
1099
1100 /* Delete all of the refs information from INSN.  BB must be passed in
1101    except when called from df_process_deferred_rescans to mark the block
1102    as dirty.  */
1103
1104 void
1105 df_insn_delete (basic_block bb, unsigned int uid)
1106 {
1107   struct df_insn_info *insn_info = NULL;
1108   if (!df)
1109     return;
1110
1111   df_grow_bb_info (df_scan);
1112   df_grow_reg_info ();
1113
1114   /* The block must be marked as dirty now, rather than later as in
1115      df_insn_rescan and df_notes_rescan because it may not be there at
1116      rescanning time and the mark would blow up.  */
1117   if (bb)
1118     df_set_bb_dirty (bb);
1119
1120   insn_info = DF_INSN_UID_SAFE_GET (uid);
1121
1122   /* The client has deferred rescanning.  */
1123   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1124     {
1125       if (insn_info)
1126         {
1127           bitmap_clear_bit (&df->insns_to_rescan, uid);
1128           bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1129           bitmap_set_bit (&df->insns_to_delete, uid);
1130         }
1131       if (dump_file)
1132         fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
1133       return;
1134     }
1135
1136   if (dump_file)
1137     fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
1138
1139   bitmap_clear_bit (&df->insns_to_delete, uid);
1140   bitmap_clear_bit (&df->insns_to_rescan, uid);
1141   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1142   if (insn_info)
1143     {
1144       struct df_scan_problem_data *problem_data
1145         = (struct df_scan_problem_data *) df_scan->problem_data;
1146
1147       /* In general, notes do not have the insn_info fields
1148          initialized.  However, combine deletes insns by changing them
1149          to notes.  How clever.  So we cannot just check if it is a
1150          valid insn before short circuiting this code, we need to see
1151          if we actually initialized it.  */
1152       if (insn_info->defs)
1153         {
1154           df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1155
1156           if (df_chain)
1157             {
1158               df_ref_chain_delete_du_chain (insn_info->defs);
1159               df_ref_chain_delete_du_chain (insn_info->uses);
1160               df_ref_chain_delete_du_chain (insn_info->eq_uses);
1161             }
1162
1163           df_ref_chain_delete (insn_info->defs);
1164           df_ref_chain_delete (insn_info->uses);
1165           df_ref_chain_delete (insn_info->eq_uses);
1166         }
1167       pool_free (problem_data->insn_pool, insn_info);
1168       DF_INSN_UID_SET (uid, NULL);
1169     }
1170 }
1171
1172
1173 /* Free all of the refs and the mw_hardregs in COLLECTION_REC.  */
1174
1175 static void
1176 df_free_collection_rec (struct df_collection_rec *collection_rec)
1177 {
1178   unsigned int ix;
1179   struct df_scan_problem_data *problem_data
1180     = (struct df_scan_problem_data *) df_scan->problem_data;
1181   df_ref ref;
1182   struct df_mw_hardreg *mw;
1183
1184   FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
1185     df_free_ref (ref);
1186   FOR_EACH_VEC_ELT (df_ref, collection_rec->use_vec, ix, ref)
1187     df_free_ref (ref);
1188   FOR_EACH_VEC_ELT (df_ref, collection_rec->eq_use_vec, ix, ref)
1189     df_free_ref (ref);
1190   FOR_EACH_VEC_ELT (df_mw_hardreg_ptr, collection_rec->mw_vec, ix, mw)
1191     pool_free (problem_data->mw_reg_pool, mw);
1192
1193   VEC_free (df_ref, stack, collection_rec->def_vec);
1194   VEC_free (df_ref, stack, collection_rec->use_vec);
1195   VEC_free (df_ref, stack, collection_rec->eq_use_vec);
1196   VEC_free (df_mw_hardreg_ptr, stack, collection_rec->mw_vec);
1197 }
1198
1199 /* Rescan INSN.  Return TRUE if the rescanning produced any changes.  */
1200
1201 bool
1202 df_insn_rescan (rtx insn)
1203 {
1204   unsigned int uid = INSN_UID (insn);
1205   struct df_insn_info *insn_info = NULL;
1206   basic_block bb = BLOCK_FOR_INSN (insn);
1207   struct df_collection_rec collection_rec;
1208
1209   if ((!df) || (!INSN_P (insn)))
1210     return false;
1211
1212   if (!bb)
1213     {
1214       if (dump_file)
1215         fprintf (dump_file, "no bb for insn with uid = %d.\n", uid);
1216       return false;
1217     }
1218
1219   /* The client has disabled rescanning and plans to do it itself.  */
1220   if (df->changeable_flags & DF_NO_INSN_RESCAN)
1221     return false;
1222
1223   df_grow_bb_info (df_scan);
1224   df_grow_reg_info ();
1225
1226   insn_info = DF_INSN_UID_SAFE_GET (uid);
1227
1228   /* The client has deferred rescanning.  */
1229   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1230     {
1231       if (!insn_info)
1232         {
1233           insn_info = df_insn_create_insn_record (insn);
1234           insn_info->defs = df_null_ref_rec;
1235           insn_info->uses = df_null_ref_rec;
1236           insn_info->eq_uses = df_null_ref_rec;
1237           insn_info->mw_hardregs = df_null_mw_rec;
1238         }
1239       if (dump_file)
1240         fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid);
1241
1242       bitmap_clear_bit (&df->insns_to_delete, uid);
1243       bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1244       bitmap_set_bit (&df->insns_to_rescan, INSN_UID (insn));
1245       return false;
1246     }
1247
1248   collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
1249   collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
1250   collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
1251   collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
1252
1253   bitmap_clear_bit (&df->insns_to_delete, uid);
1254   bitmap_clear_bit (&df->insns_to_rescan, uid);
1255   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1256   if (insn_info)
1257     {
1258       int luid;
1259       bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false);
1260       /* If there's no change, return false. */
1261       if (the_same)
1262         {
1263           df_free_collection_rec (&collection_rec);
1264           if (dump_file)
1265             fprintf (dump_file, "verify found no changes in insn with uid = %d.\n", uid);
1266           return false;
1267         }
1268       if (dump_file)
1269         fprintf (dump_file, "rescanning insn with uid = %d.\n", uid);
1270
1271       /* There's change - we need to delete the existing info.
1272          Since the insn isn't moved, we can salvage its LUID.  */
1273       luid = DF_INSN_LUID (insn);
1274       df_insn_delete (NULL, uid);
1275       df_insn_create_insn_record (insn);
1276       DF_INSN_LUID (insn) = luid;
1277     }
1278   else
1279     {
1280       struct df_insn_info *insn_info = df_insn_create_insn_record (insn);
1281       df_insn_refs_collect (&collection_rec, bb, insn_info);
1282       if (dump_file)
1283         fprintf (dump_file, "scanning new insn with uid = %d.\n", uid);
1284     }
1285
1286   df_refs_add_to_chains (&collection_rec, bb, insn);
1287   if (!DEBUG_INSN_P (insn))
1288     df_set_bb_dirty (bb);
1289
1290   VEC_free (df_ref, stack, collection_rec.def_vec);
1291   VEC_free (df_ref, stack, collection_rec.use_vec);
1292   VEC_free (df_ref, stack, collection_rec.eq_use_vec);
1293   VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
1294
1295   return true;
1296 }
1297
1298 /* Same as df_insn_rescan, but don't mark the basic block as
1299    dirty.  */
1300
1301 bool
1302 df_insn_rescan_debug_internal (rtx insn)
1303 {
1304   unsigned int uid = INSN_UID (insn);
1305   struct df_insn_info *insn_info;
1306
1307   gcc_assert (DEBUG_INSN_P (insn)
1308               && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)));
1309
1310   if (!df)
1311     return false;
1312
1313   insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
1314   if (!insn_info)
1315     return false;
1316
1317   if (dump_file)
1318     fprintf (dump_file, "deleting debug_insn with uid = %d.\n", uid);
1319
1320   bitmap_clear_bit (&df->insns_to_delete, uid);
1321   bitmap_clear_bit (&df->insns_to_rescan, uid);
1322   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1323
1324   if (!insn_info->defs)
1325     return false;
1326
1327   if (insn_info->defs == df_null_ref_rec
1328       && insn_info->uses == df_null_ref_rec
1329       && insn_info->eq_uses == df_null_ref_rec
1330       && insn_info->mw_hardregs == df_null_mw_rec)
1331     return false;
1332
1333   df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1334
1335   if (df_chain)
1336     {
1337       df_ref_chain_delete_du_chain (insn_info->defs);
1338       df_ref_chain_delete_du_chain (insn_info->uses);
1339       df_ref_chain_delete_du_chain (insn_info->eq_uses);
1340     }
1341
1342   df_ref_chain_delete (insn_info->defs);
1343   df_ref_chain_delete (insn_info->uses);
1344   df_ref_chain_delete (insn_info->eq_uses);
1345
1346   insn_info->defs = df_null_ref_rec;
1347   insn_info->uses = df_null_ref_rec;
1348   insn_info->eq_uses = df_null_ref_rec;
1349   insn_info->mw_hardregs = df_null_mw_rec;
1350
1351   return true;
1352 }
1353
1354
1355 /* Rescan all of the insns in the function.  Note that the artificial
1356    uses and defs are not touched.  This function will destroy def-se
1357    or use-def chains.  */
1358
1359 void
1360 df_insn_rescan_all (void)
1361 {
1362   bool no_insn_rescan = false;
1363   bool defer_insn_rescan = false;
1364   basic_block bb;
1365   bitmap_iterator bi;
1366   unsigned int uid;
1367   bitmap_head tmp;
1368
1369   bitmap_initialize (&tmp, &df_bitmap_obstack);
1370
1371   if (df->changeable_flags & DF_NO_INSN_RESCAN)
1372     {
1373       df_clear_flags (DF_NO_INSN_RESCAN);
1374       no_insn_rescan = true;
1375     }
1376
1377   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1378     {
1379       df_clear_flags (DF_DEFER_INSN_RESCAN);
1380       defer_insn_rescan = true;
1381     }
1382
1383   bitmap_copy (&tmp, &df->insns_to_delete);
1384   EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1385     {
1386       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1387       if (insn_info)
1388         df_insn_delete (NULL, uid);
1389     }
1390
1391   bitmap_clear (&tmp);
1392   bitmap_clear (&df->insns_to_delete);
1393   bitmap_clear (&df->insns_to_rescan);
1394   bitmap_clear (&df->insns_to_notes_rescan);
1395
1396   FOR_EACH_BB (bb)
1397     {
1398       rtx insn;
1399       FOR_BB_INSNS (bb, insn)
1400         {
1401           df_insn_rescan (insn);
1402         }
1403     }
1404
1405   if (no_insn_rescan)
1406     df_set_flags (DF_NO_INSN_RESCAN);
1407   if (defer_insn_rescan)
1408     df_set_flags (DF_DEFER_INSN_RESCAN);
1409 }
1410
1411
1412 /* Process all of the deferred rescans or deletions.  */
1413
1414 void
1415 df_process_deferred_rescans (void)
1416 {
1417   bool no_insn_rescan = false;
1418   bool defer_insn_rescan = false;
1419   bitmap_iterator bi;
1420   unsigned int uid;
1421   bitmap_head tmp;
1422
1423   bitmap_initialize (&tmp, &df_bitmap_obstack);
1424
1425   if (df->changeable_flags & DF_NO_INSN_RESCAN)
1426     {
1427       df_clear_flags (DF_NO_INSN_RESCAN);
1428       no_insn_rescan = true;
1429     }
1430
1431   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1432     {
1433       df_clear_flags (DF_DEFER_INSN_RESCAN);
1434       defer_insn_rescan = true;
1435     }
1436
1437   if (dump_file)
1438     fprintf (dump_file, "starting the processing of deferred insns\n");
1439
1440   bitmap_copy (&tmp, &df->insns_to_delete);
1441   EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1442     {
1443       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1444       if (insn_info)
1445         df_insn_delete (NULL, uid);
1446     }
1447
1448   bitmap_copy (&tmp, &df->insns_to_rescan);
1449   EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1450     {
1451       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1452       if (insn_info)
1453         df_insn_rescan (insn_info->insn);
1454     }
1455
1456   bitmap_copy (&tmp, &df->insns_to_notes_rescan);
1457   EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1458     {
1459       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1460       if (insn_info)
1461         df_notes_rescan (insn_info->insn);
1462     }
1463
1464   if (dump_file)
1465     fprintf (dump_file, "ending the processing of deferred insns\n");
1466
1467   bitmap_clear (&tmp);
1468   bitmap_clear (&df->insns_to_delete);
1469   bitmap_clear (&df->insns_to_rescan);
1470   bitmap_clear (&df->insns_to_notes_rescan);
1471
1472   if (no_insn_rescan)
1473     df_set_flags (DF_NO_INSN_RESCAN);
1474   if (defer_insn_rescan)
1475     df_set_flags (DF_DEFER_INSN_RESCAN);
1476
1477   /* If someone changed regs_ever_live during this pass, fix up the
1478      entry and exit blocks.  */
1479   if (df->redo_entry_and_exit)
1480     {
1481       df_update_entry_exit_and_calls ();
1482       df->redo_entry_and_exit = false;
1483     }
1484 }
1485
1486
1487 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1488    the uses if INCLUDE_USES. Include the eq_uses if
1489    INCLUDE_EQ_USES.  */
1490
1491 static unsigned int
1492 df_count_refs (bool include_defs, bool include_uses,
1493                bool include_eq_uses)
1494 {
1495   unsigned int regno;
1496   int size = 0;
1497   unsigned int m = df->regs_inited;
1498
1499   for (regno = 0; regno < m; regno++)
1500     {
1501       if (include_defs)
1502         size += DF_REG_DEF_COUNT (regno);
1503       if (include_uses)
1504         size += DF_REG_USE_COUNT (regno);
1505       if (include_eq_uses)
1506         size += DF_REG_EQ_USE_COUNT (regno);
1507     }
1508   return size;
1509 }
1510
1511
1512 /* Take build ref table for either the uses or defs from the reg-use
1513    or reg-def chains.  This version processes the refs in reg order
1514    which is likely to be best if processing the whole function.  */
1515
1516 static void
1517 df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info,
1518                                   bool include_defs,
1519                                   bool include_uses,
1520                                   bool include_eq_uses)
1521 {
1522   unsigned int m = df->regs_inited;
1523   unsigned int regno;
1524   unsigned int offset = 0;
1525   unsigned int start;
1526
1527   if (df->changeable_flags & DF_NO_HARD_REGS)
1528     {
1529       start = FIRST_PSEUDO_REGISTER;
1530       memset (ref_info->begin, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1531       memset (ref_info->count, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1532     }
1533   else
1534     start = 0;
1535
1536   ref_info->total_size
1537     = df_count_refs (include_defs, include_uses, include_eq_uses);
1538
1539   df_check_and_grow_ref_info (ref_info, 1);
1540
1541   for (regno = start; regno < m; regno++)
1542     {
1543       int count = 0;
1544       ref_info->begin[regno] = offset;
1545       if (include_defs)
1546         {
1547           df_ref ref = DF_REG_DEF_CHAIN (regno);
1548           while (ref)
1549             {
1550               ref_info->refs[offset] = ref;
1551               DF_REF_ID (ref) = offset++;
1552               count++;
1553               ref = DF_REF_NEXT_REG (ref);
1554               gcc_checking_assert (offset < ref_info->refs_size);
1555             }
1556         }
1557       if (include_uses)
1558         {
1559           df_ref ref = DF_REG_USE_CHAIN (regno);
1560           while (ref)
1561             {
1562               ref_info->refs[offset] = ref;
1563               DF_REF_ID (ref) = offset++;
1564               count++;
1565               ref = DF_REF_NEXT_REG (ref);
1566               gcc_checking_assert (offset < ref_info->refs_size);
1567             }
1568         }
1569       if (include_eq_uses)
1570         {
1571           df_ref ref = DF_REG_EQ_USE_CHAIN (regno);
1572           while (ref)
1573             {
1574               ref_info->refs[offset] = ref;
1575               DF_REF_ID (ref) = offset++;
1576               count++;
1577               ref = DF_REF_NEXT_REG (ref);
1578               gcc_checking_assert (offset < ref_info->refs_size);
1579             }
1580         }
1581       ref_info->count[regno] = count;
1582     }
1583
1584   /* The bitmap size is not decremented when refs are deleted.  So
1585      reset it now that we have squished out all of the empty
1586      slots.  */
1587   ref_info->table_size = offset;
1588 }
1589
1590
1591 /* Take build ref table for either the uses or defs from the reg-use
1592    or reg-def chains.  This version processes the refs in insn order
1593    which is likely to be best if processing some segment of the
1594    function.  */
1595
1596 static void
1597 df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
1598                                    bool include_defs,
1599                                    bool include_uses,
1600                                    bool include_eq_uses)
1601 {
1602   bitmap_iterator bi;
1603   unsigned int bb_index;
1604   unsigned int m = df->regs_inited;
1605   unsigned int offset = 0;
1606   unsigned int r;
1607   unsigned int start
1608     = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
1609
1610   memset (ref_info->begin, 0, sizeof (int) * df->regs_inited);
1611   memset (ref_info->count, 0, sizeof (int) * df->regs_inited);
1612
1613   ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1614   df_check_and_grow_ref_info (ref_info, 1);
1615
1616   EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1617     {
1618       basic_block bb = BASIC_BLOCK (bb_index);
1619       rtx insn;
1620       df_ref *ref_rec;
1621
1622       if (include_defs)
1623         for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1624           {
1625             unsigned int regno = DF_REF_REGNO (*ref_rec);
1626             ref_info->count[regno]++;
1627           }
1628       if (include_uses)
1629         for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1630           {
1631             unsigned int regno = DF_REF_REGNO (*ref_rec);
1632             ref_info->count[regno]++;
1633           }
1634
1635       FOR_BB_INSNS (bb, insn)
1636         {
1637           if (INSN_P (insn))
1638             {
1639               unsigned int uid = INSN_UID (insn);
1640
1641               if (include_defs)
1642                 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1643                   {
1644                     unsigned int regno = DF_REF_REGNO (*ref_rec);
1645                     ref_info->count[regno]++;
1646                   }
1647               if (include_uses)
1648                 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1649                   {
1650                     unsigned int regno = DF_REF_REGNO (*ref_rec);
1651                     ref_info->count[regno]++;
1652                   }
1653               if (include_eq_uses)
1654                 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1655                   {
1656                     unsigned int regno = DF_REF_REGNO (*ref_rec);
1657                     ref_info->count[regno]++;
1658                   }
1659             }
1660         }
1661     }
1662
1663   for (r = start; r < m; r++)
1664     {
1665       ref_info->begin[r] = offset;
1666       offset += ref_info->count[r];
1667       ref_info->count[r] = 0;
1668     }
1669
1670   EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1671     {
1672       basic_block bb = BASIC_BLOCK (bb_index);
1673       rtx insn;
1674       df_ref *ref_rec;
1675
1676       if (include_defs)
1677         for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1678           {
1679             df_ref ref = *ref_rec;
1680             unsigned int regno = DF_REF_REGNO (ref);
1681             if (regno >= start)
1682               {
1683                 unsigned int id
1684                   = ref_info->begin[regno] + ref_info->count[regno]++;
1685                 DF_REF_ID (ref) = id;
1686                 ref_info->refs[id] = ref;
1687               }
1688           }
1689       if (include_uses)
1690         for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1691           {
1692             df_ref ref = *ref_rec;
1693             unsigned int regno = DF_REF_REGNO (ref);
1694             if (regno >= start)
1695               {
1696                 unsigned int id
1697                   = ref_info->begin[regno] + ref_info->count[regno]++;
1698                 DF_REF_ID (ref) = id;
1699                 ref_info->refs[id] = ref;
1700               }
1701           }
1702
1703       FOR_BB_INSNS (bb, insn)
1704         {
1705           if (INSN_P (insn))
1706             {
1707               unsigned int uid = INSN_UID (insn);
1708
1709               if (include_defs)
1710                 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1711                   {
1712                     df_ref ref = *ref_rec;
1713                     unsigned int regno = DF_REF_REGNO (ref);
1714                     if (regno >= start)
1715                       {
1716                         unsigned int id
1717                           = ref_info->begin[regno] + ref_info->count[regno]++;
1718                         DF_REF_ID (ref) = id;
1719                         ref_info->refs[id] = ref;
1720                       }
1721                   }
1722               if (include_uses)
1723                 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1724                   {
1725                     df_ref ref = *ref_rec;
1726                     unsigned int regno = DF_REF_REGNO (ref);
1727                     if (regno >= start)
1728                       {
1729                         unsigned int id
1730                           = ref_info->begin[regno] + ref_info->count[regno]++;
1731                         DF_REF_ID (ref) = id;
1732                         ref_info->refs[id] = ref;
1733                       }
1734                   }
1735               if (include_eq_uses)
1736                 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1737                   {
1738                     df_ref ref = *ref_rec;
1739                     unsigned int regno = DF_REF_REGNO (ref);
1740                     if (regno >= start)
1741                       {
1742                         unsigned int id
1743                           = ref_info->begin[regno] + ref_info->count[regno]++;
1744                         DF_REF_ID (ref) = id;
1745                         ref_info->refs[id] = ref;
1746                       }
1747                   }
1748             }
1749         }
1750     }
1751
1752   /* The bitmap size is not decremented when refs are deleted.  So
1753      reset it now that we have squished out all of the empty
1754      slots.  */
1755
1756   ref_info->table_size = offset;
1757 }
1758
1759 /* Take build ref table for either the uses or defs from the reg-use
1760    or reg-def chains.  */
1761
1762 static void
1763 df_reorganize_refs_by_reg (struct df_ref_info *ref_info,
1764                            bool include_defs,
1765                            bool include_uses,
1766                            bool include_eq_uses)
1767 {
1768   if (df->analyze_subset)
1769     df_reorganize_refs_by_reg_by_insn (ref_info, include_defs,
1770                                        include_uses, include_eq_uses);
1771   else
1772     df_reorganize_refs_by_reg_by_reg (ref_info, include_defs,
1773                                        include_uses, include_eq_uses);
1774 }
1775
1776
1777 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET.  */
1778 static unsigned int
1779 df_add_refs_to_table (unsigned int offset,
1780                       struct df_ref_info *ref_info,
1781                       df_ref *ref_vec)
1782 {
1783   while (*ref_vec)
1784     {
1785       df_ref ref = *ref_vec;
1786       if ((!(df->changeable_flags & DF_NO_HARD_REGS))
1787           || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER))
1788         {
1789           ref_info->refs[offset] = ref;
1790           DF_REF_ID (*ref_vec) = offset++;
1791         }
1792       ref_vec++;
1793     }
1794   return offset;
1795 }
1796
1797
1798 /* Count the number of refs in all of the insns of BB. Include the
1799    defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1800    eq_uses if INCLUDE_EQ_USES.  */
1801
1802 static unsigned int
1803 df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset,
1804                                struct df_ref_info *ref_info,
1805                                bool include_defs, bool include_uses,
1806                                bool include_eq_uses)
1807 {
1808   rtx insn;
1809
1810   if (include_defs)
1811     offset = df_add_refs_to_table (offset, ref_info,
1812                                    df_get_artificial_defs (bb->index));
1813   if (include_uses)
1814     offset = df_add_refs_to_table (offset, ref_info,
1815                                    df_get_artificial_uses (bb->index));
1816
1817   FOR_BB_INSNS (bb, insn)
1818     if (INSN_P (insn))
1819       {
1820         unsigned int uid = INSN_UID (insn);
1821         if (include_defs)
1822           offset = df_add_refs_to_table (offset, ref_info,
1823                                          DF_INSN_UID_DEFS (uid));
1824         if (include_uses)
1825           offset = df_add_refs_to_table (offset, ref_info,
1826                                          DF_INSN_UID_USES (uid));
1827         if (include_eq_uses)
1828           offset = df_add_refs_to_table (offset, ref_info,
1829                                          DF_INSN_UID_EQ_USES (uid));
1830       }
1831   return offset;
1832 }
1833
1834
1835 /* Organize the refs by insn into the table in REF_INFO.  If
1836    blocks_to_analyze is defined, use that set, otherwise the entire
1837    program.  Include the defs if INCLUDE_DEFS. Include the uses if
1838    INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES.  */
1839
1840 static void
1841 df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
1842                             bool include_defs, bool include_uses,
1843                             bool include_eq_uses)
1844 {
1845   basic_block bb;
1846   unsigned int offset = 0;
1847
1848   ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1849   df_check_and_grow_ref_info (ref_info, 1);
1850   if (df->blocks_to_analyze)
1851     {
1852       bitmap_iterator bi;
1853       unsigned int index;
1854
1855       EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
1856         {
1857           offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index), offset, ref_info,
1858                                                   include_defs, include_uses,
1859                                                   include_eq_uses);
1860         }
1861
1862       ref_info->table_size = offset;
1863     }
1864   else
1865     {
1866       FOR_ALL_BB (bb)
1867         offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info,
1868                                                 include_defs, include_uses,
1869                                                 include_eq_uses);
1870       ref_info->table_size = offset;
1871     }
1872 }
1873
1874
1875 /* If the use refs in DF are not organized, reorganize them.  */
1876
1877 void
1878 df_maybe_reorganize_use_refs (enum df_ref_order order)
1879 {
1880   if (order == df->use_info.ref_order)
1881     return;
1882
1883   switch (order)
1884     {
1885     case DF_REF_ORDER_BY_REG:
1886       df_reorganize_refs_by_reg (&df->use_info, false, true, false);
1887       break;
1888
1889     case DF_REF_ORDER_BY_REG_WITH_NOTES:
1890       df_reorganize_refs_by_reg (&df->use_info, false, true, true);
1891       break;
1892
1893     case DF_REF_ORDER_BY_INSN:
1894       df_reorganize_refs_by_insn (&df->use_info, false, true, false);
1895       break;
1896
1897     case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1898       df_reorganize_refs_by_insn (&df->use_info, false, true, true);
1899       break;
1900
1901     case DF_REF_ORDER_NO_TABLE:
1902       free (df->use_info.refs);
1903       df->use_info.refs = NULL;
1904       df->use_info.refs_size = 0;
1905       break;
1906
1907     case DF_REF_ORDER_UNORDERED:
1908     case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1909       gcc_unreachable ();
1910       break;
1911     }
1912
1913   df->use_info.ref_order = order;
1914 }
1915
1916
1917 /* If the def refs in DF are not organized, reorganize them.  */
1918
1919 void
1920 df_maybe_reorganize_def_refs (enum df_ref_order order)
1921 {
1922   if (order == df->def_info.ref_order)
1923     return;
1924
1925   switch (order)
1926     {
1927     case DF_REF_ORDER_BY_REG:
1928       df_reorganize_refs_by_reg (&df->def_info, true, false, false);
1929       break;
1930
1931     case DF_REF_ORDER_BY_INSN:
1932       df_reorganize_refs_by_insn (&df->def_info, true, false, false);
1933       break;
1934
1935     case DF_REF_ORDER_NO_TABLE:
1936       free (df->def_info.refs);
1937       df->def_info.refs = NULL;
1938       df->def_info.refs_size = 0;
1939       break;
1940
1941     case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1942     case DF_REF_ORDER_BY_REG_WITH_NOTES:
1943     case DF_REF_ORDER_UNORDERED:
1944     case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1945       gcc_unreachable ();
1946       break;
1947     }
1948
1949   df->def_info.ref_order = order;
1950 }
1951
1952
1953 /* Change all of the basic block references in INSN to use the insn's
1954    current basic block.  This function is called from routines that move
1955    instructions from one block to another.  */
1956
1957 void
1958 df_insn_change_bb (rtx insn, basic_block new_bb)
1959 {
1960   basic_block old_bb = BLOCK_FOR_INSN (insn);
1961   struct df_insn_info *insn_info;
1962   unsigned int uid = INSN_UID (insn);
1963
1964   if (old_bb == new_bb)
1965     return;
1966
1967   set_block_for_insn (insn, new_bb);
1968
1969   if (!df)
1970     return;
1971
1972   if (dump_file)
1973     fprintf (dump_file, "changing bb of uid %d\n", uid);
1974
1975   insn_info = DF_INSN_UID_SAFE_GET (uid);
1976   if (insn_info == NULL)
1977     {
1978       if (dump_file)
1979         fprintf (dump_file, "  unscanned insn\n");
1980       df_insn_rescan (insn);
1981       return;
1982     }
1983
1984   if (!INSN_P (insn))
1985     return;
1986
1987   df_set_bb_dirty (new_bb);
1988   if (old_bb)
1989     {
1990       if (dump_file)
1991         fprintf (dump_file, "  from %d to %d\n",
1992                  old_bb->index, new_bb->index);
1993       df_set_bb_dirty (old_bb);
1994     }
1995   else
1996     if (dump_file)
1997       fprintf (dump_file, "  to %d\n", new_bb->index);
1998 }
1999
2000
2001 /* Helper function for df_ref_change_reg_with_loc.  */
2002
2003 static void
2004 df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df,
2005                               struct df_reg_info *new_df,
2006                               int new_regno, rtx loc)
2007 {
2008   df_ref the_ref = old_df->reg_chain;
2009
2010   while (the_ref)
2011     {
2012       if ((!DF_REF_IS_ARTIFICIAL (the_ref))
2013           && DF_REF_LOC (the_ref)
2014           && (*DF_REF_LOC (the_ref) == loc))
2015         {
2016           df_ref next_ref = DF_REF_NEXT_REG (the_ref);
2017           df_ref prev_ref = DF_REF_PREV_REG (the_ref);
2018           df_ref *ref_vec, *ref_vec_t;
2019           struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref);
2020           unsigned int count = 0;
2021
2022           DF_REF_REGNO (the_ref) = new_regno;
2023           DF_REF_REG (the_ref) = regno_reg_rtx[new_regno];
2024
2025           /* Pull the_ref out of the old regno chain.  */
2026           if (prev_ref)
2027             DF_REF_NEXT_REG (prev_ref) = next_ref;
2028           else
2029             old_df->reg_chain = next_ref;
2030           if (next_ref)
2031             DF_REF_PREV_REG (next_ref) = prev_ref;
2032           old_df->n_refs--;
2033
2034           /* Put the ref into the new regno chain.  */
2035           DF_REF_PREV_REG (the_ref) = NULL;
2036           DF_REF_NEXT_REG (the_ref) = new_df->reg_chain;
2037           if (new_df->reg_chain)
2038             DF_REF_PREV_REG (new_df->reg_chain) = the_ref;
2039           new_df->reg_chain = the_ref;
2040           new_df->n_refs++;
2041           if (DF_REF_BB (the_ref))
2042             df_set_bb_dirty (DF_REF_BB (the_ref));
2043
2044           /* Need to sort the record again that the ref was in because
2045              the regno is a sorting key.  First, find the right
2046              record.  */
2047           if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE)
2048             ref_vec = insn_info->eq_uses;
2049           else
2050             ref_vec = insn_info->uses;
2051           if (dump_file)
2052             fprintf (dump_file, "changing reg in insn %d\n",
2053                      DF_REF_INSN_UID (the_ref));
2054
2055           ref_vec_t = ref_vec;
2056
2057           /* Find the length.  */
2058           while (*ref_vec_t)
2059             {
2060               count++;
2061               ref_vec_t++;
2062             }
2063           qsort (ref_vec, count, sizeof (df_ref ), df_ref_compare);
2064
2065           the_ref = next_ref;
2066         }
2067       else
2068         the_ref = DF_REF_NEXT_REG (the_ref);
2069     }
2070 }
2071
2072
2073 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2074    NEW_REGNO.  Refs that do not match LOC are not changed which means
2075    that artificial refs are not changed since they have no loc.  This
2076    call is to support the SET_REGNO macro. */
2077
2078 void
2079 df_ref_change_reg_with_loc (int old_regno, int new_regno, rtx loc)
2080 {
2081   if ((!df) || (old_regno == -1) || (old_regno == new_regno))
2082     return;
2083
2084   df_grow_reg_info ();
2085
2086   df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno),
2087                                 DF_REG_DEF_GET (new_regno), new_regno, loc);
2088   df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno),
2089                                 DF_REG_USE_GET (new_regno), new_regno, loc);
2090   df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno),
2091                                 DF_REG_EQ_USE_GET (new_regno), new_regno, loc);
2092 }
2093
2094
2095 /* Delete the mw_hardregs that point into the eq_notes.  */
2096
2097 static unsigned int
2098 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info)
2099 {
2100   struct df_mw_hardreg **mw_vec = insn_info->mw_hardregs;
2101   unsigned int deleted = 0;
2102   unsigned int count = 0;
2103   struct df_scan_problem_data *problem_data
2104     = (struct df_scan_problem_data *) df_scan->problem_data;
2105
2106   if (!*mw_vec)
2107     return 0;
2108
2109   while (*mw_vec)
2110     {
2111       if ((*mw_vec)->flags & DF_REF_IN_NOTE)
2112         {
2113           struct df_mw_hardreg **temp_vec = mw_vec;
2114
2115           pool_free (problem_data->mw_reg_pool, *mw_vec);
2116           temp_vec = mw_vec;
2117           /* Shove the remaining ones down one to fill the gap.  While
2118              this looks n**2, it is highly unusual to have any mw regs
2119              in eq_notes and the chances of more than one are almost
2120              non existent.  */
2121           while (*temp_vec)
2122             {
2123               *temp_vec = *(temp_vec + 1);
2124               temp_vec++;
2125             }
2126           deleted++;
2127         }
2128       else
2129         {
2130           mw_vec++;
2131           count++;
2132         }
2133     }
2134
2135   if (count == 0)
2136     {
2137       df_scan_free_mws_vec (insn_info->mw_hardregs);
2138       insn_info->mw_hardregs = df_null_mw_rec;
2139       return 0;
2140     }
2141   return deleted;
2142 }
2143
2144
2145 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN.  */
2146
2147 void
2148 df_notes_rescan (rtx insn)
2149 {
2150   struct df_insn_info *insn_info;
2151   unsigned int uid = INSN_UID (insn);
2152
2153   if (!df)
2154     return;
2155
2156   /* The client has disabled rescanning and plans to do it itself.  */
2157   if (df->changeable_flags & DF_NO_INSN_RESCAN)
2158     return;
2159
2160   /* Do nothing if the insn hasn't been emitted yet.  */
2161   if (!BLOCK_FOR_INSN (insn))
2162     return;
2163
2164   df_grow_bb_info (df_scan);
2165   df_grow_reg_info ();
2166
2167   insn_info = DF_INSN_UID_SAFE_GET (INSN_UID(insn));
2168
2169   /* The client has deferred rescanning.  */
2170   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
2171     {
2172       if (!insn_info)
2173         {
2174           insn_info = df_insn_create_insn_record (insn);
2175           insn_info->defs = df_null_ref_rec;
2176           insn_info->uses = df_null_ref_rec;
2177           insn_info->eq_uses = df_null_ref_rec;
2178           insn_info->mw_hardregs = df_null_mw_rec;
2179         }
2180
2181       bitmap_clear_bit (&df->insns_to_delete, uid);
2182       /* If the insn is set to be rescanned, it does not need to also
2183          be notes rescanned.  */
2184       if (!bitmap_bit_p (&df->insns_to_rescan, uid))
2185         bitmap_set_bit (&df->insns_to_notes_rescan, INSN_UID (insn));
2186       return;
2187     }
2188
2189   bitmap_clear_bit (&df->insns_to_delete, uid);
2190   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
2191
2192   if (insn_info)
2193     {
2194       basic_block bb = BLOCK_FOR_INSN (insn);
2195       rtx note;
2196       struct df_collection_rec collection_rec;
2197       unsigned int num_deleted;
2198       unsigned int mw_len;
2199
2200       memset (&collection_rec, 0, sizeof (struct df_collection_rec));
2201       collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
2202       collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
2203
2204       num_deleted = df_mw_hardreg_chain_delete_eq_uses (insn_info);
2205       df_ref_chain_delete (insn_info->eq_uses);
2206       insn_info->eq_uses = NULL;
2207
2208       /* Process REG_EQUIV/REG_EQUAL notes */
2209       for (note = REG_NOTES (insn); note;
2210            note = XEXP (note, 1))
2211         {
2212           switch (REG_NOTE_KIND (note))
2213             {
2214             case REG_EQUIV:
2215             case REG_EQUAL:
2216               df_uses_record (&collection_rec,
2217                               &XEXP (note, 0), DF_REF_REG_USE,
2218                               bb, insn_info, DF_REF_IN_NOTE);
2219             default:
2220               break;
2221             }
2222         }
2223
2224       /* Find some place to put any new mw_hardregs.  */
2225       df_canonize_collection_rec (&collection_rec);
2226       mw_len = VEC_length (df_mw_hardreg_ptr, collection_rec.mw_vec);
2227       if (mw_len)
2228         {
2229           unsigned int count = 0;
2230           struct df_mw_hardreg **mw_rec = insn_info->mw_hardregs;
2231           while (*mw_rec)
2232             {
2233               count++;
2234               mw_rec++;
2235             }
2236
2237           if (count)
2238             {
2239               /* Append to the end of the existing record after
2240                  expanding it if necessary.  */
2241               if (mw_len > num_deleted)
2242                 {
2243                   insn_info->mw_hardregs =
2244                     XRESIZEVEC (struct df_mw_hardreg *,
2245                                 insn_info->mw_hardregs,
2246                                 count + 1 + mw_len);
2247                 }
2248               memcpy (&insn_info->mw_hardregs[count],
2249                       VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2250                       mw_len * sizeof (struct df_mw_hardreg *));
2251               insn_info->mw_hardregs[count + mw_len] = NULL;
2252               qsort (insn_info->mw_hardregs, count + mw_len,
2253                      sizeof (struct df_mw_hardreg *), df_mw_compare);
2254             }
2255           else
2256             {
2257               /* No vector there. */
2258               insn_info->mw_hardregs
2259                 = XNEWVEC (struct df_mw_hardreg*, 1 + mw_len);
2260               memcpy (insn_info->mw_hardregs,
2261                       VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2262                       mw_len * sizeof (struct df_mw_hardreg *));
2263               insn_info->mw_hardregs[mw_len] = NULL;
2264             }
2265         }
2266       /* Get rid of the mw_rec so that df_refs_add_to_chains will
2267          ignore it.  */
2268       VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
2269       df_refs_add_to_chains (&collection_rec, bb, insn);
2270       VEC_free (df_ref, stack, collection_rec.eq_use_vec);
2271     }
2272   else
2273     df_insn_rescan (insn);
2274
2275 }
2276
2277 \f
2278 /*----------------------------------------------------------------------------
2279    Hard core instruction scanning code.  No external interfaces here,
2280    just a lot of routines that look inside insns.
2281 ----------------------------------------------------------------------------*/
2282
2283
2284 /* Return true if the contents of two df_ref's are identical.
2285    It ignores DF_REF_MARKER.  */
2286
2287 static bool
2288 df_ref_equal_p (df_ref ref1, df_ref ref2)
2289 {
2290   if (!ref2)
2291     return false;
2292
2293   if (ref1 == ref2)
2294     return true;
2295
2296   if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)
2297       || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)
2298       || DF_REF_REG (ref1) != DF_REF_REG (ref2)
2299       || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)
2300       || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))
2301           != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)))
2302       || DF_REF_BB (ref1) != DF_REF_BB (ref2)
2303       || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2))
2304     return false;
2305
2306   switch (DF_REF_CLASS (ref1))
2307     {
2308     case DF_REF_ARTIFICIAL:
2309     case DF_REF_BASE:
2310       return true;
2311
2312     case DF_REF_REGULAR:
2313       return DF_REF_LOC (ref1) == DF_REF_LOC (ref2);
2314
2315     default:
2316       gcc_unreachable ();
2317     }
2318   return false;
2319 }
2320
2321
2322 /* Compare REF1 and REF2 for sorting.  This is only called from places
2323    where all of the refs are of the same type, in the same insn, and
2324    have the same bb.  So these fields are not checked.  */
2325
2326 static int
2327 df_ref_compare (const void *r1, const void *r2)
2328 {
2329   const df_ref ref1 = *(const df_ref *)r1;
2330   const df_ref ref2 = *(const df_ref *)r2;
2331
2332   if (ref1 == ref2)
2333     return 0;
2334
2335   if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
2336     return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
2337
2338   if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
2339     return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
2340
2341   if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
2342     return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
2343
2344   if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
2345     return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2346
2347   /* Cannot look at the LOC field on artificial refs.  */
2348   if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
2349       && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
2350     return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2351
2352   if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
2353     {
2354       /* If two refs are identical except that one of them has is from
2355          a mw and one is not, we need to have the one with the mw
2356          first.  */
2357       if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) ==
2358           DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG))
2359         return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2);
2360       else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG))
2361         return -1;
2362       else
2363         return 1;
2364     }
2365
2366   return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2367 }
2368
2369 static void
2370 df_swap_refs (VEC(df_ref,stack) **ref_vec, int i, int j)
2371 {
2372   df_ref tmp = VEC_index (df_ref, *ref_vec, i);
2373   VEC_replace (df_ref, *ref_vec, i, VEC_index (df_ref, *ref_vec, j));
2374   VEC_replace (df_ref, *ref_vec, j, tmp);
2375 }
2376
2377 /* Sort and compress a set of refs.  */
2378
2379 static void
2380 df_sort_and_compress_refs (VEC(df_ref,stack) **ref_vec)
2381 {
2382   unsigned int count;
2383   unsigned int i;
2384   unsigned int dist = 0;
2385
2386   count = VEC_length (df_ref, *ref_vec);
2387
2388   /* If there are 1 or 0 elements, there is nothing to do.  */
2389   if (count < 2)
2390     return;
2391   else if (count == 2)
2392     {
2393       df_ref r0 = VEC_index (df_ref, *ref_vec, 0);
2394       df_ref r1 = VEC_index (df_ref, *ref_vec, 1);
2395       if (df_ref_compare (&r0, &r1) > 0)
2396         df_swap_refs (ref_vec, 0, 1);
2397     }
2398   else
2399     {
2400       for (i = 0; i < count - 1; i++)
2401         {
2402           df_ref r0 = VEC_index (df_ref, *ref_vec, i);
2403           df_ref r1 = VEC_index (df_ref, *ref_vec, i + 1);
2404           if (df_ref_compare (&r0, &r1) >= 0)
2405             break;
2406         }
2407       /* If the array is already strictly ordered,
2408          which is the most common case for large COUNT case
2409          (which happens for CALL INSNs),
2410          no need to sort and filter out duplicate.
2411          Simply return the count.
2412          Make sure DF_GET_ADD_REFS adds refs in the increasing order
2413          of DF_REF_COMPARE.  */
2414       if (i == count - 1)
2415         return;
2416       VEC_qsort (df_ref, *ref_vec, df_ref_compare);
2417     }
2418
2419   for (i=0; i<count-dist; i++)
2420     {
2421       /* Find the next ref that is not equal to the current ref.  */
2422       while (i + dist + 1 < count
2423              && df_ref_equal_p (VEC_index (df_ref, *ref_vec, i),
2424                                 VEC_index (df_ref, *ref_vec, i + dist + 1)))
2425         {
2426           df_free_ref (VEC_index (df_ref, *ref_vec, i + dist + 1));
2427           dist++;
2428         }
2429       /* Copy it down to the next position.  */
2430       if (dist && i + dist + 1 < count)
2431         VEC_replace (df_ref, *ref_vec, i + 1,
2432                      VEC_index (df_ref, *ref_vec, i + dist + 1));
2433     }
2434
2435   count -= dist;
2436   VEC_truncate (df_ref, *ref_vec, count);
2437 }
2438
2439
2440 /* Return true if the contents of two df_ref's are identical.
2441    It ignores DF_REF_MARKER.  */
2442
2443 static bool
2444 df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2)
2445 {
2446   if (!mw2)
2447     return false;
2448   return (mw1 == mw2) ||
2449     (mw1->mw_reg == mw2->mw_reg
2450      && mw1->type == mw2->type
2451      && mw1->flags == mw2->flags
2452      && mw1->start_regno == mw2->start_regno
2453      && mw1->end_regno == mw2->end_regno);
2454 }
2455
2456
2457 /* Compare MW1 and MW2 for sorting.  */
2458
2459 static int
2460 df_mw_compare (const void *m1, const void *m2)
2461 {
2462   const struct df_mw_hardreg *const mw1 = *(const struct df_mw_hardreg *const*)m1;
2463   const struct df_mw_hardreg *const mw2 = *(const struct df_mw_hardreg *const*)m2;
2464
2465   if (mw1 == mw2)
2466     return 0;
2467
2468   if (mw1->type != mw2->type)
2469     return mw1->type - mw2->type;
2470
2471   if (mw1->flags != mw2->flags)
2472     return mw1->flags - mw2->flags;
2473
2474   if (mw1->start_regno != mw2->start_regno)
2475     return mw1->start_regno - mw2->start_regno;
2476
2477   if (mw1->end_regno != mw2->end_regno)
2478     return mw1->end_regno - mw2->end_regno;
2479
2480   if (mw1->mw_reg != mw2->mw_reg)
2481     return mw1->mw_order - mw2->mw_order;
2482
2483   return 0;
2484 }
2485
2486
2487 /* Sort and compress a set of refs.  */
2488
2489 static void
2490 df_sort_and_compress_mws (VEC(df_mw_hardreg_ptr,stack) **mw_vec)
2491 {
2492   unsigned int count;
2493   struct df_scan_problem_data *problem_data
2494     = (struct df_scan_problem_data *) df_scan->problem_data;
2495   unsigned int i;
2496   unsigned int dist = 0;
2497
2498   count = VEC_length (df_mw_hardreg_ptr, *mw_vec);
2499   if (count < 2)
2500     return;
2501   else if (count == 2)
2502     {
2503       struct df_mw_hardreg *m0 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 0);
2504       struct df_mw_hardreg *m1 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 1);
2505       if (df_mw_compare (&m0, &m1) > 0)
2506         {
2507           struct df_mw_hardreg *tmp = VEC_index (df_mw_hardreg_ptr,
2508                                                  *mw_vec, 0);
2509           VEC_replace (df_mw_hardreg_ptr, *mw_vec, 0,
2510                        VEC_index (df_mw_hardreg_ptr, *mw_vec, 1));
2511           VEC_replace (df_mw_hardreg_ptr, *mw_vec, 1, tmp);
2512         }
2513     }
2514   else
2515     VEC_qsort (df_mw_hardreg_ptr, *mw_vec, df_mw_compare);
2516
2517   for (i=0; i<count-dist; i++)
2518     {
2519       /* Find the next ref that is not equal to the current ref.  */
2520       while (i + dist + 1 < count
2521              && df_mw_equal_p (VEC_index (df_mw_hardreg_ptr, *mw_vec, i),
2522                                VEC_index (df_mw_hardreg_ptr, *mw_vec,
2523                                           i + dist + 1)))
2524         {
2525           pool_free (problem_data->mw_reg_pool,
2526                      VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2527           dist++;
2528         }
2529       /* Copy it down to the next position.  */
2530       if (dist && i + dist + 1 < count)
2531         VEC_replace (df_mw_hardreg_ptr, *mw_vec, i + 1,
2532                      VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2533     }
2534
2535   count -= dist;
2536   VEC_truncate (df_mw_hardreg_ptr, *mw_vec, count);
2537 }
2538
2539
2540 /* Sort and remove duplicates from the COLLECTION_REC.  */
2541
2542 static void
2543 df_canonize_collection_rec (struct df_collection_rec *collection_rec)
2544 {
2545   df_sort_and_compress_refs (&collection_rec->def_vec);
2546   df_sort_and_compress_refs (&collection_rec->use_vec);
2547   df_sort_and_compress_refs (&collection_rec->eq_use_vec);
2548   df_sort_and_compress_mws (&collection_rec->mw_vec);
2549 }
2550
2551
2552 /* Add the new df_ref to appropriate reg_info/ref_info chains.  */
2553
2554 static void
2555 df_install_ref (df_ref this_ref,
2556                 struct df_reg_info *reg_info,
2557                 struct df_ref_info *ref_info,
2558                 bool add_to_table)
2559 {
2560   unsigned int regno = DF_REF_REGNO (this_ref);
2561   /* Add the ref to the reg_{def,use,eq_use} chain.  */
2562   df_ref head = reg_info->reg_chain;
2563
2564   reg_info->reg_chain = this_ref;
2565   reg_info->n_refs++;
2566
2567   if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE))
2568     {
2569       gcc_assert (regno < FIRST_PSEUDO_REGISTER);
2570       df->hard_regs_live_count[regno]++;
2571     }
2572
2573   gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL
2574                        && DF_REF_PREV_REG (this_ref) == NULL);
2575
2576   DF_REF_NEXT_REG (this_ref) = head;
2577
2578   /* We cannot actually link to the head of the chain.  */
2579   DF_REF_PREV_REG (this_ref) = NULL;
2580
2581   if (head)
2582     DF_REF_PREV_REG (head) = this_ref;
2583
2584   if (add_to_table)
2585     {
2586       gcc_assert (ref_info->ref_order != DF_REF_ORDER_NO_TABLE);
2587       df_check_and_grow_ref_info (ref_info, 1);
2588       DF_REF_ID (this_ref) = ref_info->table_size;
2589       /* Add the ref to the big array of defs.  */
2590       ref_info->refs[ref_info->table_size] = this_ref;
2591       ref_info->table_size++;
2592     }
2593   else
2594     DF_REF_ID (this_ref) = -1;
2595
2596   ref_info->total_size++;
2597 }
2598
2599
2600 /* This function takes one of the groups of refs (defs, uses or
2601    eq_uses) and installs the entire group into the insn.  It also adds
2602    each of these refs into the appropriate chains.  */
2603
2604 static df_ref *
2605 df_install_refs (basic_block bb,
2606                  VEC(df_ref,stack)* old_vec,
2607                  struct df_reg_info **reg_info,
2608                  struct df_ref_info *ref_info,
2609                  bool is_notes)
2610 {
2611   unsigned int count;
2612
2613   count = VEC_length (df_ref, old_vec);
2614   if (count)
2615     {
2616       df_ref *new_vec = XNEWVEC (df_ref, count + 1);
2617       bool add_to_table;
2618       df_ref this_ref;
2619       unsigned int ix;
2620
2621       switch (ref_info->ref_order)
2622         {
2623         case DF_REF_ORDER_UNORDERED_WITH_NOTES:
2624         case DF_REF_ORDER_BY_REG_WITH_NOTES:
2625         case DF_REF_ORDER_BY_INSN_WITH_NOTES:
2626           ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
2627           add_to_table = true;
2628           break;
2629         case DF_REF_ORDER_UNORDERED:
2630         case DF_REF_ORDER_BY_REG:
2631         case DF_REF_ORDER_BY_INSN:
2632           ref_info->ref_order = DF_REF_ORDER_UNORDERED;
2633           add_to_table = !is_notes;
2634           break;
2635         default:
2636           add_to_table = false;
2637           break;
2638         }
2639
2640       /* Do not add if ref is not in the right blocks.  */
2641       if (add_to_table && df->analyze_subset)
2642         add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
2643
2644       FOR_EACH_VEC_ELT (df_ref, old_vec, ix, this_ref)
2645         {
2646           new_vec[ix] = this_ref;
2647           df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)],
2648                           ref_info, add_to_table);
2649         }
2650
2651       new_vec[count] = NULL;
2652       return new_vec;
2653     }
2654   else
2655     return df_null_ref_rec;
2656 }
2657
2658
2659 /* This function takes the mws installs the entire group into the
2660    insn.  */
2661
2662 static struct df_mw_hardreg **
2663 df_install_mws (VEC(df_mw_hardreg_ptr,stack) *old_vec)
2664 {
2665   unsigned int count;
2666
2667   count = VEC_length (df_mw_hardreg_ptr, old_vec);
2668   if (count)
2669     {
2670       struct df_mw_hardreg **new_vec
2671         = XNEWVEC (struct df_mw_hardreg*, count + 1);
2672       memcpy (new_vec, VEC_address (df_mw_hardreg_ptr, old_vec),
2673               sizeof (struct df_mw_hardreg*) * count);
2674       new_vec[count] = NULL;
2675       return new_vec;
2676     }
2677   else
2678     return df_null_mw_rec;
2679 }
2680
2681
2682 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2683    chains and update other necessary information.  */
2684
2685 static void
2686 df_refs_add_to_chains (struct df_collection_rec *collection_rec,
2687                        basic_block bb, rtx insn)
2688 {
2689   if (insn)
2690     {
2691       struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn);
2692       /* If there is a vector in the collection rec, add it to the
2693          insn.  A null rec is a signal that the caller will handle the
2694          chain specially.  */
2695       if (collection_rec->def_vec)
2696         {
2697           df_scan_free_ref_vec (insn_rec->defs);
2698           insn_rec->defs
2699             = df_install_refs (bb, collection_rec->def_vec,
2700                                df->def_regs,
2701                                &df->def_info, false);
2702         }
2703       if (collection_rec->use_vec)
2704         {
2705           df_scan_free_ref_vec (insn_rec->uses);
2706           insn_rec->uses
2707             = df_install_refs (bb, collection_rec->use_vec,
2708                                df->use_regs,
2709                                &df->use_info, false);
2710         }
2711       if (collection_rec->eq_use_vec)
2712         {
2713           df_scan_free_ref_vec (insn_rec->eq_uses);
2714           insn_rec->eq_uses
2715             = df_install_refs (bb, collection_rec->eq_use_vec,
2716                                df->eq_use_regs,
2717                                &df->use_info, true);
2718         }
2719       if (collection_rec->mw_vec)
2720         {
2721           df_scan_free_mws_vec (insn_rec->mw_hardregs);
2722           insn_rec->mw_hardregs
2723             = df_install_mws (collection_rec->mw_vec);
2724         }
2725     }
2726   else
2727     {
2728       struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
2729
2730       df_scan_free_ref_vec (bb_info->artificial_defs);
2731       bb_info->artificial_defs
2732         = df_install_refs (bb, collection_rec->def_vec,
2733                            df->def_regs,
2734                            &df->def_info, false);
2735       df_scan_free_ref_vec (bb_info->artificial_uses);
2736       bb_info->artificial_uses
2737         = df_install_refs (bb, collection_rec->use_vec,
2738                            df->use_regs,
2739                            &df->use_info, false);
2740     }
2741 }
2742
2743
2744 /* Allocate a ref and initialize its fields.  */
2745
2746 static df_ref
2747 df_ref_create_structure (enum df_ref_class cl,
2748                          struct df_collection_rec *collection_rec,
2749                          rtx reg, rtx *loc,
2750                          basic_block bb, struct df_insn_info *info,
2751                          enum df_ref_type ref_type,
2752                          int ref_flags)
2753 {
2754   df_ref this_ref = NULL;
2755   int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2756   struct df_scan_problem_data *problem_data
2757     = (struct df_scan_problem_data *) df_scan->problem_data;
2758
2759   switch (cl)
2760     {
2761     case DF_REF_BASE:
2762       this_ref = (df_ref) pool_alloc (problem_data->ref_base_pool);
2763       gcc_checking_assert (loc == NULL);
2764       break;
2765
2766     case DF_REF_ARTIFICIAL:
2767       this_ref = (df_ref) pool_alloc (problem_data->ref_artificial_pool);
2768       this_ref->artificial_ref.bb = bb;
2769       gcc_checking_assert (loc == NULL);
2770       break;
2771
2772     case DF_REF_REGULAR:
2773       this_ref = (df_ref) pool_alloc (problem_data->ref_regular_pool);
2774       this_ref->regular_ref.loc = loc;
2775       gcc_checking_assert (loc);
2776       break;
2777     }
2778
2779   DF_REF_CLASS (this_ref) = cl;
2780   DF_REF_ID (this_ref) = -1;
2781   DF_REF_REG (this_ref) = reg;
2782   DF_REF_REGNO (this_ref) =  regno;
2783   DF_REF_TYPE (this_ref) = ref_type;
2784   DF_REF_INSN_INFO (this_ref) = info;
2785   DF_REF_CHAIN (this_ref) = NULL;
2786   DF_REF_FLAGS (this_ref) = ref_flags;
2787   DF_REF_NEXT_REG (this_ref) = NULL;
2788   DF_REF_PREV_REG (this_ref) = NULL;
2789   DF_REF_ORDER (this_ref) = df->ref_order++;
2790
2791   /* We need to clear this bit because fwprop, and in the future
2792      possibly other optimizations sometimes create new refs using ond
2793      refs as the model.  */
2794   DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE);
2795
2796   /* See if this ref needs to have DF_HARD_REG_LIVE bit set.  */
2797   if ((regno < FIRST_PSEUDO_REGISTER)
2798       && (!DF_REF_IS_ARTIFICIAL (this_ref)))
2799     {
2800       if (DF_REF_REG_DEF_P (this_ref))
2801         {
2802           if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER))
2803             DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2804         }
2805       else if (!(TEST_HARD_REG_BIT (elim_reg_set, regno)
2806                  && (regno == FRAME_POINTER_REGNUM
2807                      || regno == ARG_POINTER_REGNUM)))
2808         DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2809     }
2810
2811   if (collection_rec)
2812     {
2813       if (DF_REF_REG_DEF_P (this_ref))
2814         VEC_safe_push (df_ref, stack, collection_rec->def_vec, this_ref);
2815       else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE)
2816         VEC_safe_push (df_ref, stack, collection_rec->eq_use_vec, this_ref);
2817       else
2818         VEC_safe_push (df_ref, stack, collection_rec->use_vec, this_ref);
2819     }
2820   else
2821     df_install_ref_incremental (this_ref);
2822
2823   return this_ref;
2824 }
2825
2826
2827 /* Create new references of type DF_REF_TYPE for each part of register REG
2828    at address LOC within INSN of BB.  */
2829
2830
2831 static void
2832 df_ref_record (enum df_ref_class cl,
2833                struct df_collection_rec *collection_rec,
2834                rtx reg, rtx *loc,
2835                basic_block bb, struct df_insn_info *insn_info,
2836                enum df_ref_type ref_type,
2837                int ref_flags)
2838 {
2839   unsigned int regno;
2840
2841   gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
2842
2843   regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2844   if (regno < FIRST_PSEUDO_REGISTER)
2845     {
2846       struct df_mw_hardreg *hardreg = NULL;
2847       struct df_scan_problem_data *problem_data
2848         = (struct df_scan_problem_data *) df_scan->problem_data;
2849       unsigned int i;
2850       unsigned int endregno;
2851       df_ref ref;
2852
2853       if (GET_CODE (reg) == SUBREG)
2854         {
2855           regno += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
2856                                         SUBREG_BYTE (reg), GET_MODE (reg));
2857           endregno = regno + subreg_nregs (reg);
2858         }
2859       else
2860         endregno = END_HARD_REGNO (reg);
2861
2862       /*  If this is a multiword hardreg, we create some extra
2863           datastructures that will enable us to easily build REG_DEAD
2864           and REG_UNUSED notes.  */
2865       if (collection_rec
2866           && (endregno != regno + 1) && insn_info)
2867         {
2868           /* Sets to a subreg of a multiword register are partial.
2869              Sets to a non-subreg of a multiword register are not.  */
2870           if (GET_CODE (reg) == SUBREG)
2871             ref_flags |= DF_REF_PARTIAL;
2872           ref_flags |= DF_REF_MW_HARDREG;
2873
2874           hardreg = (struct df_mw_hardreg *) pool_alloc (problem_data->mw_reg_pool);
2875           hardreg->type = ref_type;
2876           hardreg->flags = ref_flags;
2877           hardreg->mw_reg = reg;
2878           hardreg->start_regno = regno;
2879           hardreg->end_regno = endregno - 1;
2880           hardreg->mw_order = df->ref_order++;
2881           VEC_safe_push (df_mw_hardreg_ptr, stack, collection_rec->mw_vec,
2882                          hardreg);
2883         }
2884
2885       for (i = regno; i < endregno; i++)
2886         {
2887           ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc,
2888                                          bb, insn_info, ref_type, ref_flags);
2889
2890           gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i);
2891         }
2892     }
2893   else
2894     {
2895       df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info,
2896                                ref_type, ref_flags);
2897     }
2898 }
2899
2900
2901 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2902    covered by the outer mode is smaller than that covered by the inner mode,
2903    is a read-modify-write operation.
2904    This function returns true iff the SUBREG X is such a SUBREG.  */
2905
2906 bool
2907 df_read_modify_subreg_p (rtx x)
2908 {
2909   unsigned int isize, osize;
2910   if (GET_CODE (x) != SUBREG)
2911     return false;
2912   isize = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
2913   osize = GET_MODE_SIZE (GET_MODE (x));
2914   return isize > osize
2915          && isize > REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x)));
2916 }
2917
2918
2919 /* Process all the registers defined in the rtx, X.
2920    Autoincrement/decrement definitions will be picked up by
2921    df_uses_record.  */
2922
2923 static void
2924 df_def_record_1 (struct df_collection_rec *collection_rec,
2925                  rtx x, basic_block bb, struct df_insn_info *insn_info,
2926                  int flags)
2927 {
2928   rtx *loc;
2929   rtx dst;
2930
2931  /* We may recursively call ourselves on EXPR_LIST when dealing with PARALLEL
2932      construct.  */
2933   if (GET_CODE (x) == EXPR_LIST || GET_CODE (x) == CLOBBER)
2934     loc = &XEXP (x, 0);
2935   else
2936     loc = &SET_DEST (x);
2937   dst = *loc;
2938
2939   /* It is legal to have a set destination be a parallel. */
2940   if (GET_CODE (dst) == PARALLEL)
2941     {
2942       int i;
2943
2944       for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
2945         {
2946           rtx temp = XVECEXP (dst, 0, i);
2947           if (GET_CODE (temp) == EXPR_LIST || GET_CODE (temp) == CLOBBER
2948               || GET_CODE (temp) == SET)
2949             df_def_record_1 (collection_rec,
2950                              temp, bb, insn_info,
2951                              GET_CODE (temp) == CLOBBER
2952                              ? flags | DF_REF_MUST_CLOBBER : flags);
2953         }
2954       return;
2955     }
2956
2957   if (GET_CODE (dst) == STRICT_LOW_PART)
2958     {
2959       flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;
2960
2961       loc = &XEXP (dst, 0);
2962       dst = *loc;
2963     }
2964
2965   if (GET_CODE (dst) == ZERO_EXTRACT)
2966     {
2967       flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;
2968
2969       loc = &XEXP (dst, 0);
2970       dst = *loc;
2971     }
2972
2973   /* At this point if we do not have a reg or a subreg, just return.  */
2974   if (REG_P (dst))
2975     {
2976       df_ref_record (DF_REF_REGULAR, collection_rec,
2977                      dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
2978
2979       /* We want to keep sp alive everywhere - by making all
2980          writes to sp also use of sp. */
2981       if (REGNO (dst) == STACK_POINTER_REGNUM)
2982         df_ref_record (DF_REF_BASE, collection_rec,
2983                        dst, NULL, bb, insn_info, DF_REF_REG_USE, flags);
2984     }
2985   else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
2986     {
2987       if (df_read_modify_subreg_p (dst))
2988         flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;
2989
2990       flags |= DF_REF_SUBREG;
2991
2992       df_ref_record (DF_REF_REGULAR, collection_rec,
2993                      dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
2994     }
2995 }
2996
2997
2998 /* Process all the registers defined in the pattern rtx, X.  */
2999
3000 static void
3001 df_defs_record (struct df_collection_rec *collection_rec,
3002                 rtx x, basic_block bb, struct df_insn_info *insn_info,
3003                 int flags)
3004 {
3005   RTX_CODE code = GET_CODE (x);
3006
3007   if (code == SET || code == CLOBBER)
3008     {
3009       /* Mark the single def within the pattern.  */
3010       int clobber_flags = flags;
3011       clobber_flags |= (code == CLOBBER) ? DF_REF_MUST_CLOBBER : 0;
3012       df_def_record_1 (collection_rec, x, bb, insn_info, clobber_flags);
3013     }
3014   else if (code == COND_EXEC)
3015     {
3016       df_defs_record (collection_rec, COND_EXEC_CODE (x),
3017                       bb, insn_info, DF_REF_CONDITIONAL);
3018     }
3019   else if (code == PARALLEL)
3020     {
3021       int i;
3022
3023       /* Mark the multiple defs within the pattern.  */
3024       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
3025         df_defs_record (collection_rec, XVECEXP (x, 0, i), bb, insn_info, flags);
3026     }
3027 }
3028
3029
3030 /* Process all the registers used in the rtx at address LOC.  */
3031
3032 static void
3033 df_uses_record (struct df_collection_rec *collection_rec,
3034                 rtx *loc, enum df_ref_type ref_type,
3035                 basic_block bb, struct df_insn_info *insn_info,
3036                 int flags)
3037 {
3038   RTX_CODE code;
3039   rtx x;
3040
3041  retry:
3042   x = *loc;
3043   if (!x)
3044     return;
3045   code = GET_CODE (x);
3046   switch (code)
3047     {
3048     case LABEL_REF:
3049     case SYMBOL_REF:
3050     case CONST_INT:
3051     case CONST:
3052     case CONST_DOUBLE:
3053     case CONST_FIXED:
3054     case CONST_VECTOR:
3055     case PC:
3056     case CC0:
3057     case ADDR_VEC:
3058     case ADDR_DIFF_VEC:
3059       return;
3060
3061     case CLOBBER:
3062       /* If we are clobbering a MEM, mark any registers inside the address
3063          as being used.  */
3064       if (MEM_P (XEXP (x, 0)))
3065         df_uses_record (collection_rec,
3066                         &XEXP (XEXP (x, 0), 0),
3067                         DF_REF_REG_MEM_STORE,
3068                         bb, insn_info,
3069                         flags);
3070
3071       /* If we're clobbering a REG then we have a def so ignore.  */
3072       return;
3073
3074     case MEM:
3075       df_uses_record (collection_rec,
3076                       &XEXP (x, 0), DF_REF_REG_MEM_LOAD,
3077                       bb, insn_info, flags & DF_REF_IN_NOTE);
3078       return;
3079
3080     case SUBREG:
3081       /* While we're here, optimize this case.  */
3082       flags |= DF_REF_PARTIAL;
3083       /* In case the SUBREG is not of a REG, do not optimize.  */
3084       if (!REG_P (SUBREG_REG (x)))
3085         {
3086           loc = &SUBREG_REG (x);
3087           df_uses_record (collection_rec, loc, ref_type, bb, insn_info, flags);
3088           return;
3089         }
3090       /* ... Fall through ...  */
3091
3092     case REG:
3093       df_ref_record (DF_REF_REGULAR, collection_rec,
3094                      x, loc, bb, insn_info,
3095                      ref_type, flags);
3096       return;
3097
3098     case SIGN_EXTRACT:
3099     case ZERO_EXTRACT:
3100       {
3101         df_uses_record (collection_rec,
3102                         &XEXP (x, 1), ref_type, bb, insn_info, flags);
3103         df_uses_record (collection_rec,
3104                         &XEXP (x, 2), ref_type, bb, insn_info, flags);
3105
3106         /* If the parameters to the zero or sign extract are
3107            constants, strip them off and recurse, otherwise there is
3108            no information that we can gain from this operation.  */
3109         if (code == ZERO_EXTRACT)
3110           flags |= DF_REF_ZERO_EXTRACT;
3111         else
3112           flags |= DF_REF_SIGN_EXTRACT;
3113
3114         df_uses_record (collection_rec,
3115                         &XEXP (x, 0), ref_type, bb, insn_info, flags);
3116         return;
3117       }
3118       break;
3119
3120     case SET:
3121       {
3122         rtx dst = SET_DEST (x);
3123         gcc_assert (!(flags & DF_REF_IN_NOTE));
3124         df_uses_record (collection_rec,
3125                         &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags);
3126
3127         switch (GET_CODE (dst))
3128           {
3129             case SUBREG:
3130               if (df_read_modify_subreg_p (dst))
3131                 {
3132                   df_uses_record (collection_rec, &SUBREG_REG (dst),
3133                                   DF_REF_REG_USE, bb, insn_info,
3134                                   flags | DF_REF_READ_WRITE | DF_REF_SUBREG);
3135                   break;
3136                 }
3137               /* Fall through.  */
3138             case REG:
3139             case PARALLEL:
3140             case SCRATCH:
3141             case PC:
3142             case CC0:
3143                 break;
3144             case MEM:
3145               df_uses_record (collection_rec, &XEXP (dst, 0),
3146                               DF_REF_REG_MEM_STORE, bb, insn_info, flags);
3147               break;
3148             case STRICT_LOW_PART:
3149               {
3150                 rtx *temp = &XEXP (dst, 0);
3151                 /* A strict_low_part uses the whole REG and not just the
3152                  SUBREG.  */
3153                 dst = XEXP (dst, 0);
3154                 df_uses_record (collection_rec,
3155                                 (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
3156                                 DF_REF_REG_USE, bb, insn_info,
3157                                 DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART);
3158               }
3159               break;
3160             case ZERO_EXTRACT:
3161               {
3162                 df_uses_record (collection_rec, &XEXP (dst, 1),
3163                                 DF_REF_REG_USE, bb, insn_info, flags);
3164                 df_uses_record (collection_rec, &XEXP (dst, 2),
3165                                 DF_REF_REG_USE, bb, insn_info, flags);
3166                 if (GET_CODE (XEXP (dst,0)) == MEM)
3167                   df_uses_record (collection_rec, &XEXP (dst, 0),
3168                                   DF_REF_REG_USE, bb, insn_info,
3169                                   flags);
3170                 else
3171                   df_uses_record (collection_rec, &XEXP (dst, 0),
3172                                   DF_REF_REG_USE, bb, insn_info,
3173                                   DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT);
3174               }
3175               break;
3176
3177             default:
3178               gcc_unreachable ();
3179           }
3180         return;
3181       }
3182
3183     case RETURN:
3184       break;
3185
3186     case ASM_OPERANDS:
3187     case UNSPEC_VOLATILE:
3188     case TRAP_IF:
3189     case ASM_INPUT:
3190       {
3191         /* Traditional and volatile asm instructions must be
3192            considered to use and clobber all hard registers, all
3193            pseudo-registers and all of memory.  So must TRAP_IF and
3194            UNSPEC_VOLATILE operations.
3195
3196            Consider for instance a volatile asm that changes the fpu
3197            rounding mode.  An insn should not be moved across this
3198            even if it only uses pseudo-regs because it might give an
3199            incorrectly rounded result.
3200
3201            However, flow.c's liveness computation did *not* do this,
3202            giving the reasoning as " ?!? Unfortunately, marking all
3203            hard registers as live causes massive problems for the
3204            register allocator and marking all pseudos as live creates
3205            mountains of uninitialized variable warnings."
3206
3207            In order to maintain the status quo with regard to liveness
3208            and uses, we do what flow.c did and just mark any regs we
3209            can find in ASM_OPERANDS as used.  In global asm insns are
3210            scanned and regs_asm_clobbered is filled out.
3211
3212            For all ASM_OPERANDS, we must traverse the vector of input
3213            operands.  We can not just fall through here since then we
3214            would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3215            which do not indicate traditional asms unlike their normal
3216            usage.  */
3217         if (code == ASM_OPERANDS)
3218           {
3219             int j;
3220
3221             for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
3222               df_uses_record (collection_rec, &ASM_OPERANDS_INPUT (x, j),
3223                               DF_REF_REG_USE, bb, insn_info, flags);
3224             return;
3225           }
3226         break;
3227       }
3228
3229     case VAR_LOCATION:
3230       df_uses_record (collection_rec,
3231                       &PAT_VAR_LOCATION_LOC (x),
3232                       DF_REF_REG_USE, bb, insn_info, flags);
3233       return;
3234
3235     case PRE_DEC:
3236     case POST_DEC:
3237     case PRE_INC:
3238     case POST_INC:
3239     case PRE_MODIFY:
3240     case POST_MODIFY:
3241       gcc_assert (!DEBUG_INSN_P (insn_info->insn));
3242       /* Catch the def of the register being modified.  */
3243       df_ref_record (DF_REF_REGULAR, collection_rec, XEXP (x, 0), &XEXP (x, 0),
3244                      bb, insn_info,
3245                      DF_REF_REG_DEF,
3246                      flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY);
3247
3248       /* ... Fall through to handle uses ...  */
3249
3250     default:
3251       break;
3252     }
3253
3254   /* Recursively scan the operands of this expression.  */
3255   {
3256     const char *fmt = GET_RTX_FORMAT (code);
3257     int i;
3258
3259     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3260       {
3261         if (fmt[i] == 'e')
3262           {
3263             /* Tail recursive case: save a function call level.  */
3264             if (i == 0)
3265               {
3266                 loc = &XEXP (x, 0);
3267                 goto retry;
3268               }
3269             df_uses_record (collection_rec, &XEXP (x, i), ref_type,
3270                             bb, insn_info, flags);
3271           }
3272         else if (fmt[i] == 'E')
3273           {
3274             int j;
3275             for (j = 0; j < XVECLEN (x, i); j++)
3276               df_uses_record (collection_rec,
3277                               &XVECEXP (x, i, j), ref_type,
3278                               bb, insn_info, flags);
3279           }
3280       }
3281   }
3282
3283   return;
3284 }
3285
3286
3287 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses.  */
3288
3289 static void
3290 df_get_conditional_uses (struct df_collection_rec *collection_rec)
3291 {
3292   unsigned int ix;
3293   df_ref ref;
3294
3295   FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
3296     {
3297       if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL))
3298         {
3299           df_ref use;
3300
3301           use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref),
3302                                          DF_REF_LOC (ref), DF_REF_BB (ref),
3303                                          DF_REF_INSN_INFO (ref), DF_REF_REG_USE,
3304                                          DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL);
3305           DF_REF_REGNO (use) = DF_REF_REGNO (ref);
3306         }
3307     }
3308 }
3309
3310
3311 /* Get call's extra defs and uses. */
3312
3313 static void
3314 df_get_call_refs (struct df_collection_rec * collection_rec,
3315                   basic_block bb,
3316                   struct df_insn_info *insn_info,
3317                   int flags)
3318 {
3319   rtx note;
3320   bitmap_iterator bi;
3321   unsigned int ui;
3322   bool is_sibling_call;
3323   unsigned int i;
3324   df_ref def;
3325   bitmap_head defs_generated;
3326
3327   bitmap_initialize (&defs_generated, &df_bitmap_obstack);
3328
3329   /* Do not generate clobbers for registers that are the result of the
3330      call.  This causes ordering problems in the chain building code
3331      depending on which def is seen first.  */
3332   FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, i, def)
3333     bitmap_set_bit (&defs_generated, DF_REF_REGNO (def));
3334
3335   /* Record the registers used to pass arguments, and explicitly
3336      noted as clobbered.  */
3337   for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note;
3338        note = XEXP (note, 1))
3339     {
3340       if (GET_CODE (XEXP (note, 0)) == USE)
3341         df_uses_record (collection_rec, &XEXP (XEXP (note, 0), 0),
3342                         DF_REF_REG_USE, bb, insn_info, flags);
3343       else if (GET_CODE (XEXP (note, 0)) == CLOBBER)
3344         {
3345           if (REG_P (XEXP (XEXP (note, 0), 0)))
3346             {
3347               unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
3348               if (!bitmap_bit_p (&defs_generated, regno))
3349                 df_defs_record (collection_rec, XEXP (note, 0), bb,
3350                                 insn_info, flags);
3351             }
3352           else
3353             df_uses_record (collection_rec, &XEXP (note, 0),
3354                             DF_REF_REG_USE, bb, insn_info, flags);
3355         }
3356     }
3357
3358   /* The stack ptr is used (honorarily) by a CALL insn.  */
3359   df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[STACK_POINTER_REGNUM],
3360                  NULL, bb, insn_info, DF_REF_REG_USE,
3361                  DF_REF_CALL_STACK_USAGE | flags);
3362
3363   /* Calls may also reference any of the global registers,
3364      so they are recorded as used.  */
3365   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3366     if (global_regs[i])
3367       {
3368         df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3369                        NULL, bb, insn_info, DF_REF_REG_USE, flags);
3370         df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3371                        NULL, bb, insn_info, DF_REF_REG_DEF, flags);
3372       }
3373
3374   is_sibling_call = SIBLING_CALL_P (insn_info->insn);
3375   EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, ui, bi)
3376     {
3377       if (!global_regs[ui]
3378           && (!bitmap_bit_p (&defs_generated, ui))
3379           && (!is_sibling_call
3380               || !bitmap_bit_p (df->exit_block_uses, ui)
3381               || refers_to_regno_p (ui, ui+1,
3382                                     crtl->return_rtx, NULL)))
3383         df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[ui],
3384                        NULL, bb, insn_info, DF_REF_REG_DEF,
3385                        DF_REF_MAY_CLOBBER | flags);
3386     }
3387
3388   bitmap_clear (&defs_generated);
3389   return;
3390 }
3391
3392 /* Collect all refs in the INSN. This function is free of any
3393    side-effect - it will create and return a lists of df_ref's in the
3394    COLLECTION_REC without putting those refs into existing ref chains
3395    and reg chains. */
3396
3397 static void
3398 df_insn_refs_collect (struct df_collection_rec* collection_rec,
3399                       basic_block bb, struct df_insn_info *insn_info)
3400 {
3401   rtx note;
3402   bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC);
3403
3404   /* Clear out the collection record.  */
3405   VEC_truncate (df_ref, collection_rec->def_vec, 0);
3406   VEC_truncate (df_ref, collection_rec->use_vec, 0);
3407   VEC_truncate (df_ref, collection_rec->eq_use_vec, 0);
3408   VEC_truncate (df_mw_hardreg_ptr, collection_rec->mw_vec, 0);
3409
3410   /* Record register defs.  */
3411   df_defs_record (collection_rec, PATTERN (insn_info->insn), bb, insn_info, 0);
3412
3413   /* Process REG_EQUIV/REG_EQUAL notes.  */
3414   for (note = REG_NOTES (insn_info->insn); note;
3415        note = XEXP (note, 1))
3416     {
3417       switch (REG_NOTE_KIND (note))
3418         {
3419         case REG_EQUIV:
3420         case REG_EQUAL:
3421           df_uses_record (collection_rec,
3422                           &XEXP (note, 0), DF_REF_REG_USE,
3423                           bb, insn_info, DF_REF_IN_NOTE);
3424           break;
3425         case REG_NON_LOCAL_GOTO:
3426           /* The frame ptr is used by a non-local goto.  */
3427           df_ref_record (DF_REF_BASE, collection_rec,
3428                          regno_reg_rtx[FRAME_POINTER_REGNUM],
3429                          NULL, bb, insn_info,
3430                          DF_REF_REG_USE, 0);
3431 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3432           df_ref_record (DF_REF_BASE, collection_rec,
3433                          regno_reg_rtx[HARD_FRAME_POINTER_REGNUM],
3434                          NULL, bb, insn_info,
3435                          DF_REF_REG_USE, 0);
3436 #endif
3437           break;
3438         default:
3439           break;
3440         }
3441     }
3442
3443   if (CALL_P (insn_info->insn))
3444     df_get_call_refs (collection_rec, bb, insn_info,
3445                       (is_cond_exec) ? DF_REF_CONDITIONAL : 0);
3446
3447   /* Record the register uses.  */
3448   df_uses_record (collection_rec,
3449                   &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0);
3450
3451   /* DF_REF_CONDITIONAL needs corresponding USES. */
3452   if (is_cond_exec)
3453     df_get_conditional_uses (collection_rec);
3454
3455   df_canonize_collection_rec (collection_rec);
3456 }
3457
3458 /* Recompute the luids for the insns in BB.  */
3459
3460 void
3461 df_recompute_luids (basic_block bb)
3462 {
3463   rtx insn;
3464   int luid = 0;
3465
3466   df_grow_insn_info ();
3467
3468   /* Scan the block an insn at a time from beginning to end.  */
3469   FOR_BB_INSNS (bb, insn)
3470     {
3471       struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3472       /* Inserting labels does not always trigger the incremental
3473          rescanning.  */
3474       if (!insn_info)
3475         {
3476           gcc_assert (!INSN_P (insn));
3477           insn_info = df_insn_create_insn_record (insn);
3478         }
3479
3480       DF_INSN_INFO_LUID (insn_info) = luid;
3481       if (INSN_P (insn))
3482         luid++;
3483     }
3484 }
3485
3486
3487 /* Collect all artificial refs at the block level for BB and add them
3488    to COLLECTION_REC.  */
3489
3490 static void
3491 df_bb_refs_collect (struct df_collection_rec *collection_rec, basic_block bb)
3492 {
3493   VEC_truncate (df_ref, collection_rec->def_vec, 0);
3494   VEC_truncate (df_ref, collection_rec->use_vec, 0);
3495   VEC_truncate (df_ref, collection_rec->eq_use_vec, 0);
3496   VEC_truncate (df_mw_hardreg_ptr, collection_rec->mw_vec, 0);
3497
3498   if (bb->index == ENTRY_BLOCK)
3499     {
3500       df_entry_block_defs_collect (collection_rec, df->entry_block_defs);
3501       return;
3502     }
3503   else if (bb->index == EXIT_BLOCK)
3504     {
3505       df_exit_block_uses_collect (collection_rec, df->exit_block_uses);
3506       return;
3507     }
3508
3509 #ifdef EH_RETURN_DATA_REGNO
3510   if (bb_has_eh_pred (bb))
3511     {
3512       unsigned int i;
3513       /* Mark the registers that will contain data for the handler.  */
3514       for (i = 0; ; ++i)
3515         {
3516           unsigned regno = EH_RETURN_DATA_REGNO (i);
3517           if (regno == INVALID_REGNUM)
3518             break;
3519           df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3520                          bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
3521         }
3522     }
3523 #endif
3524
3525   /* Add the hard_frame_pointer if this block is the target of a
3526      non-local goto.  */
3527   if (bb->flags & BB_NON_LOCAL_GOTO_TARGET)
3528     df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL,
3529                    bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
3530
3531   /* Add the artificial uses.  */
3532   if (bb->index >= NUM_FIXED_BLOCKS)
3533     {
3534       bitmap_iterator bi;
3535       unsigned int regno;
3536       bitmap au = bb_has_eh_pred (bb)
3537         ? &df->eh_block_artificial_uses
3538         : &df->regular_block_artificial_uses;
3539
3540       EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi)
3541         {
3542           df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3543                          bb, NULL, DF_REF_REG_USE, 0);
3544         }
3545     }
3546
3547   df_canonize_collection_rec (collection_rec);
3548 }
3549
3550
3551 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS.  */
3552
3553 void
3554 df_bb_refs_record (int bb_index, bool scan_insns)
3555 {
3556   basic_block bb = BASIC_BLOCK (bb_index);
3557   rtx insn;
3558   int luid = 0;
3559   struct df_collection_rec collection_rec;
3560
3561   if (!df)
3562     return;
3563
3564   df_grow_bb_info (df_scan);
3565   collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
3566   collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
3567   collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
3568   collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
3569
3570   if (scan_insns)
3571     /* Scan the block an insn at a time from beginning to end.  */
3572     FOR_BB_INSNS (bb, insn)
3573       {
3574         struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3575         gcc_assert (!insn_info);
3576
3577         insn_info = df_insn_create_insn_record (insn);
3578         if (INSN_P (insn))
3579           {
3580             /* Record refs within INSN.  */
3581             DF_INSN_INFO_LUID (insn_info) = luid++;
3582             df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn));
3583             df_refs_add_to_chains (&collection_rec, bb, insn);
3584           }
3585         DF_INSN_INFO_LUID (insn_info) = luid;
3586       }
3587
3588   /* Other block level artificial refs */
3589   df_bb_refs_collect (&collection_rec, bb);
3590   df_refs_add_to_chains (&collection_rec, bb, NULL);
3591
3592   VEC_free (df_ref, stack, collection_rec.def_vec);
3593   VEC_free (df_ref, stack, collection_rec.use_vec);
3594   VEC_free (df_ref, stack, collection_rec.eq_use_vec);
3595   VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
3596
3597   /* Now that the block has been processed, set the block as dirty so
3598      LR and LIVE will get it processed.  */
3599   df_set_bb_dirty (bb);
3600 }
3601
3602
3603 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3604    block. */
3605
3606 static void
3607 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses)
3608 {
3609 #ifdef EH_USES
3610   unsigned int i;
3611 #endif
3612
3613   bitmap_clear (regular_block_artificial_uses);
3614
3615   if (reload_completed)
3616     {
3617       if (frame_pointer_needed)
3618         bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3619     }
3620   else
3621     /* Before reload, there are a few registers that must be forced
3622        live everywhere -- which might not already be the case for
3623        blocks within infinite loops.  */
3624     {
3625       /* Any reference to any pseudo before reload is a potential
3626          reference of the frame pointer.  */
3627       bitmap_set_bit (regular_block_artificial_uses, FRAME_POINTER_REGNUM);
3628
3629 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3630       bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3631 #endif
3632
3633 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3634       /* Pseudos with argument area equivalences may require
3635          reloading via the argument pointer.  */
3636       if (fixed_regs[ARG_POINTER_REGNUM])
3637         bitmap_set_bit (regular_block_artificial_uses, ARG_POINTER_REGNUM);
3638 #endif
3639
3640       /* Any constant, or pseudo with constant equivalences, may
3641          require reloading from memory using the pic register.  */
3642       if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3643           && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3644         bitmap_set_bit (regular_block_artificial_uses, PIC_OFFSET_TABLE_REGNUM);
3645     }
3646   /* The all-important stack pointer must always be live.  */
3647   bitmap_set_bit (regular_block_artificial_uses, STACK_POINTER_REGNUM);
3648
3649 #ifdef EH_USES
3650   /* EH_USES registers are used:
3651      1) at all insns that might throw (calls or with -fnon-call-exceptions
3652         trapping insns)
3653      2) in all EH edges
3654      3) to support backtraces and/or debugging, anywhere between their
3655         initialization and where they the saved registers are restored
3656         from them, including the cases where we don't reach the epilogue
3657         (noreturn call or infinite loop).  */
3658   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3659     if (EH_USES (i))
3660       bitmap_set_bit (regular_block_artificial_uses, i);
3661 #endif
3662 }
3663
3664
3665 /* Get the artificial use set for an eh block. */
3666
3667 static void
3668 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses)
3669 {
3670   bitmap_clear (eh_block_artificial_uses);
3671
3672   /* The following code (down thru the arg_pointer setting APPEARS
3673      to be necessary because there is nothing that actually
3674      describes what the exception handling code may actually need
3675      to keep alive.  */
3676   if (reload_completed)
3677     {
3678       if (frame_pointer_needed)
3679         {
3680           bitmap_set_bit (eh_block_artificial_uses, FRAME_POINTER_REGNUM);
3681 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3682           bitmap_set_bit (eh_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3683 #endif
3684         }
3685 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3686       if (fixed_regs[ARG_POINTER_REGNUM])
3687         bitmap_set_bit (eh_block_artificial_uses, ARG_POINTER_REGNUM);
3688 #endif
3689     }
3690 }
3691
3692
3693 \f
3694 /*----------------------------------------------------------------------------
3695    Specialized hard register scanning functions.
3696 ----------------------------------------------------------------------------*/
3697
3698
3699 /* Mark a register in SET.  Hard registers in large modes get all
3700    of their component registers set as well.  */
3701
3702 static void
3703 df_mark_reg (rtx reg, void *vset)
3704 {
3705   bitmap set = (bitmap) vset;
3706   int regno = REGNO (reg);
3707
3708   gcc_assert (GET_MODE (reg) != BLKmode);
3709
3710   if (regno < FIRST_PSEUDO_REGISTER)
3711     {
3712       int n = hard_regno_nregs[regno][GET_MODE (reg)];
3713       bitmap_set_range (set, regno, n);
3714     }
3715   else
3716     bitmap_set_bit (set, regno);
3717 }
3718
3719
3720 /* Set the bit for regs that are considered being defined at the entry. */
3721
3722 static void
3723 df_get_entry_block_def_set (bitmap entry_block_defs)
3724 {
3725   rtx r;
3726   int i;
3727
3728   bitmap_clear (entry_block_defs);
3729
3730   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3731     {
3732       if (FUNCTION_ARG_REGNO_P (i))
3733 #ifdef INCOMING_REGNO
3734         bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
3735 #else
3736         bitmap_set_bit (entry_block_defs, i);
3737 #endif
3738     }
3739
3740   /* The always important stack pointer.  */
3741   bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM);
3742
3743   /* Once the prologue has been generated, all of these registers
3744      should just show up in the first regular block.  */
3745   if (HAVE_prologue && epilogue_completed)
3746     {
3747       /* Defs for the callee saved registers are inserted so that the
3748          pushes have some defining location.  */
3749       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3750         if ((call_used_regs[i] == 0) && (df_regs_ever_live_p (i)))
3751           bitmap_set_bit (entry_block_defs, i);
3752     }
3753
3754   r = targetm.calls.struct_value_rtx (current_function_decl, true);
3755   if (r && REG_P (r))
3756     bitmap_set_bit (entry_block_defs, REGNO (r));
3757
3758   /* If the function has an incoming STATIC_CHAIN, it has to show up
3759      in the entry def set.  */
3760   r = targetm.calls.static_chain (current_function_decl, true);
3761   if (r && REG_P (r))
3762     bitmap_set_bit (entry_block_defs, REGNO (r));
3763
3764   if ((!reload_completed) || frame_pointer_needed)
3765     {
3766       /* Any reference to any pseudo before reload is a potential
3767          reference of the frame pointer.  */
3768       bitmap_set_bit (entry_block_defs, FRAME_POINTER_REGNUM);
3769 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3770       /* If they are different, also mark the hard frame pointer as live.  */
3771       if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
3772         bitmap_set_bit (entry_block_defs, HARD_FRAME_POINTER_REGNUM);
3773 #endif
3774     }
3775
3776   /* These registers are live everywhere.  */
3777   if (!reload_completed)
3778     {
3779 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3780       /* Pseudos with argument area equivalences may require
3781          reloading via the argument pointer.  */
3782       if (fixed_regs[ARG_POINTER_REGNUM])
3783         bitmap_set_bit (entry_block_defs, ARG_POINTER_REGNUM);
3784 #endif
3785
3786 #ifdef PIC_OFFSET_TABLE_REGNUM
3787       /* Any constant, or pseudo with constant equivalences, may
3788          require reloading from memory using the pic register.  */
3789       if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3790           && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3791         bitmap_set_bit (entry_block_defs, PIC_OFFSET_TABLE_REGNUM);
3792 #endif
3793     }
3794
3795 #ifdef INCOMING_RETURN_ADDR_RTX
3796   if (REG_P (INCOMING_RETURN_ADDR_RTX))
3797     bitmap_set_bit (entry_block_defs, REGNO (INCOMING_RETURN_ADDR_RTX));
3798 #endif
3799
3800   targetm.extra_live_on_entry (entry_block_defs);
3801 }
3802
3803
3804 /* Return the (conservative) set of hard registers that are defined on
3805    entry to the function.
3806    It uses df->entry_block_defs to determine which register
3807    reference to include.  */
3808
3809 static void
3810 df_entry_block_defs_collect (struct df_collection_rec *collection_rec,
3811                              bitmap entry_block_defs)
3812 {
3813   unsigned int i;
3814   bitmap_iterator bi;
3815
3816   EXECUTE_IF_SET_IN_BITMAP (entry_block_defs, 0, i, bi)
3817     {
3818       df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
3819                      ENTRY_BLOCK_PTR, NULL, DF_REF_REG_DEF, 0);
3820     }
3821
3822   df_canonize_collection_rec (collection_rec);
3823 }
3824
3825
3826 /* Record the (conservative) set of hard registers that are defined on
3827    entry to the function.  */
3828
3829 static void
3830 df_record_entry_block_defs (bitmap entry_block_defs)
3831 {
3832   struct df_collection_rec collection_rec;
3833   memset (&collection_rec, 0, sizeof (struct df_collection_rec));
3834   collection_rec.def_vec = VEC_alloc (df_ref, stack, FIRST_PSEUDO_REGISTER);
3835   df_entry_block_defs_collect (&collection_rec, entry_block_defs);
3836
3837   /* Process bb_refs chain */
3838   df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (ENTRY_BLOCK), NULL);
3839   VEC_free (df_ref, stack, collection_rec.def_vec);
3840 }
3841
3842
3843 /* Update the defs in the entry block.  */
3844
3845 void
3846 df_update_entry_block_defs (void)
3847 {
3848   bitmap_head refs;
3849   bool changed = false;
3850
3851   bitmap_initialize (&refs, &df_bitmap_obstack);
3852   df_get_entry_block_def_set (&refs);
3853   if (df->entry_block_defs)
3854     {
3855       if (!bitmap_equal_p (df->entry_block_defs, &refs))
3856         {
3857           struct df_scan_bb_info *bb_info = df_scan_get_bb_info (ENTRY_BLOCK);
3858           df_ref_chain_delete_du_chain (bb_info->artificial_defs);
3859           df_ref_chain_delete (bb_info->artificial_defs);
3860           bb_info->artificial_defs = NULL;
3861           changed = true;
3862         }
3863     }
3864   else
3865     {
3866       struct df_scan_problem_data *problem_data
3867         = (struct df_scan_problem_data *) df_scan->problem_data;
3868         gcc_unreachable ();
3869       df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
3870       changed = true;
3871     }
3872
3873   if (changed)
3874     {
3875       df_record_entry_block_defs (&refs);
3876       bitmap_copy (df->entry_block_defs, &refs);
3877       df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
3878     }
3879   bitmap_clear (&refs);
3880 }
3881
3882
3883 /* Set the bit for regs that are considered being used at the exit. */
3884
3885 static void
3886 df_get_exit_block_use_set (bitmap exit_block_uses)
3887 {
3888   unsigned int i;
3889
3890   bitmap_clear (exit_block_uses);
3891
3892   /* Stack pointer is always live at the exit.  */
3893   bitmap_set_bit (exit_block_uses, STACK_POINTER_REGNUM);
3894
3895   /* Mark the frame pointer if needed at the end of the function.
3896      If we end up eliminating it, it will be removed from the live
3897      list of each basic block by reload.  */
3898
3899   if ((!reload_completed) || frame_pointer_needed)
3900     {
3901       bitmap_set_bit (exit_block_uses, FRAME_POINTER_REGNUM);
3902 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3903       /* If they are different, also mark the hard frame pointer as live.  */
3904       if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
3905         bitmap_set_bit (exit_block_uses, HARD_FRAME_POINTER_REGNUM);
3906 #endif
3907     }
3908
3909   /* Many architectures have a GP register even without flag_pic.
3910      Assume the pic register is not in use, or will be handled by
3911      other means, if it is not fixed.  */
3912   if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3913       && (unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3914       && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3915     bitmap_set_bit (exit_block_uses, PIC_OFFSET_TABLE_REGNUM);
3916
3917   /* Mark all global registers, and all registers used by the
3918      epilogue as being live at the end of the function since they
3919      may be referenced by our caller.  */
3920   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3921     if (global_regs[i] || EPILOGUE_USES (i))
3922       bitmap_set_bit (exit_block_uses, i);
3923
3924   if (HAVE_epilogue && epilogue_completed)
3925     {
3926       /* Mark all call-saved registers that we actually used.  */
3927       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3928         if (df_regs_ever_live_p (i) && !LOCAL_REGNO (i)
3929             && !TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
3930           bitmap_set_bit (exit_block_uses, i);
3931     }
3932
3933 #ifdef EH_RETURN_DATA_REGNO
3934   /* Mark the registers that will contain data for the handler.  */
3935   if (reload_completed && crtl->calls_eh_return)
3936     for (i = 0; ; ++i)
3937       {
3938         unsigned regno = EH_RETURN_DATA_REGNO (i);
3939         if (regno == INVALID_REGNUM)
3940           break;
3941         bitmap_set_bit (exit_block_uses, regno);
3942       }
3943 #endif
3944
3945 #ifdef EH_RETURN_STACKADJ_RTX
3946   if ((!HAVE_epilogue || ! epilogue_completed)
3947       && crtl->calls_eh_return)
3948     {
3949       rtx tmp = EH_RETURN_STACKADJ_RTX;
3950       if (tmp && REG_P (tmp))
3951         df_mark_reg (tmp, exit_block_uses);
3952     }
3953 #endif
3954
3955 #ifdef EH_RETURN_HANDLER_RTX
3956   if ((!HAVE_epilogue || ! epilogue_completed)
3957       && crtl->calls_eh_return)
3958     {
3959       rtx tmp = EH_RETURN_HANDLER_RTX;
3960       if (tmp && REG_P (tmp))
3961         df_mark_reg (tmp, exit_block_uses);
3962     }
3963 #endif
3964
3965   /* Mark function return value.  */
3966   diddle_return_value (df_mark_reg, (void*) exit_block_uses);
3967 }
3968
3969
3970 /* Return the refs of hard registers that are used in the exit block.
3971    It uses df->exit_block_uses to determine register to include.  */
3972
3973 static void
3974 df_exit_block_uses_collect (struct df_collection_rec *collection_rec, bitmap exit_block_uses)
3975 {
3976   unsigned int i;
3977   bitmap_iterator bi;
3978
3979   EXECUTE_IF_SET_IN_BITMAP (exit_block_uses, 0, i, bi)
3980     df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
3981                    EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0);
3982
3983 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3984   /* It is deliberate that this is not put in the exit block uses but
3985      I do not know why.  */
3986   if (reload_completed
3987       && !bitmap_bit_p (exit_block_uses, ARG_POINTER_REGNUM)
3988       && bb_has_eh_pred (EXIT_BLOCK_PTR)
3989       && fixed_regs[ARG_POINTER_REGNUM])
3990     df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[ARG_POINTER_REGNUM], NULL,
3991                    EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0);
3992 #endif
3993
3994   df_canonize_collection_rec (collection_rec);
3995 }
3996
3997
3998 /* Record the set of hard registers that are used in the exit block.
3999    It uses df->exit_block_uses to determine which bit to include.  */
4000
4001 static void
4002 df_record_exit_block_uses (bitmap exit_block_uses)
4003 {
4004   struct df_collection_rec collection_rec;
4005   memset (&collection_rec, 0, sizeof (struct df_collection_rec));
4006   collection_rec.use_vec = VEC_alloc (df_ref, stack, FIRST_PSEUDO_REGISTER);
4007
4008   df_exit_block_uses_collect (&collection_rec, exit_block_uses);
4009
4010   /* Process bb_refs chain */
4011   df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (EXIT_BLOCK), NULL);
4012   VEC_free (df_ref, stack, collection_rec.use_vec);
4013 }
4014
4015
4016 /* Update the uses in the exit block.  */
4017
4018 void
4019 df_update_exit_block_uses (void)
4020 {
4021   bitmap_head refs;
4022   bool changed = false;
4023
4024   bitmap_initialize (&refs, &df_bitmap_obstack);
4025   df_get_exit_block_use_set (&refs);
4026   if (df->exit_block_uses)
4027     {
4028       if (!bitmap_equal_p (df->exit_block_uses, &refs))
4029         {
4030           struct df_scan_bb_info *bb_info = df_scan_get_bb_info (EXIT_BLOCK);
4031           df_ref_chain_delete_du_chain (bb_info->artificial_uses);
4032           df_ref_chain_delete (bb_info->artificial_uses);
4033           bb_info->artificial_uses = NULL;
4034           changed = true;
4035         }
4036     }
4037   else
4038     {
4039       struct df_scan_problem_data *problem_data
4040         = (struct df_scan_problem_data *) df_scan->problem_data;
4041         gcc_unreachable ();
4042       df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
4043       changed = true;
4044     }
4045
4046   if (changed)
4047     {
4048       df_record_exit_block_uses (&refs);
4049       bitmap_copy (df->exit_block_uses,& refs);
4050       df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
4051     }
4052   bitmap_clear (&refs);
4053 }
4054
4055 static bool initialized = false;
4056
4057
4058 /* Initialize some platform specific structures.  */
4059
4060 void
4061 df_hard_reg_init (void)
4062 {
4063 #ifdef ELIMINABLE_REGS
4064   int i;
4065   static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
4066 #endif
4067   if (initialized)
4068     return;
4069
4070   /* Record which registers will be eliminated.  We use this in
4071      mark_used_regs.  */
4072   CLEAR_HARD_REG_SET (elim_reg_set);
4073
4074 #ifdef ELIMINABLE_REGS
4075   for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
4076     SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
4077 #else
4078   SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
4079 #endif
4080
4081   initialized = true;
4082 }
4083
4084
4085 /* Recompute the parts of scanning that are based on regs_ever_live
4086    because something changed in that array.  */
4087
4088 void
4089 df_update_entry_exit_and_calls (void)
4090 {
4091   basic_block bb;
4092
4093   df_update_entry_block_defs ();
4094   df_update_exit_block_uses ();
4095
4096   /* The call insns need to be rescanned because there may be changes
4097      in the set of registers clobbered across the call.  */
4098   FOR_EACH_BB (bb)
4099     {
4100       rtx insn;
4101       FOR_BB_INSNS (bb, insn)
4102         {
4103           if (INSN_P (insn) && CALL_P (insn))
4104             df_insn_rescan (insn);
4105         }
4106     }
4107 }
4108
4109
4110 /* Return true if hard REG is actually used in the some instruction.
4111    There are a fair number of conditions that affect the setting of
4112    this array.  See the comment in df.h for df->hard_regs_live_count
4113    for the conditions that this array is set. */
4114
4115 bool
4116 df_hard_reg_used_p (unsigned int reg)
4117 {
4118   return df->hard_regs_live_count[reg] != 0;
4119 }
4120
4121
4122 /* A count of the number of times REG is actually used in the some
4123    instruction.  There are a fair number of conditions that affect the
4124    setting of this array.  See the comment in df.h for
4125    df->hard_regs_live_count for the conditions that this array is
4126    set. */
4127
4128
4129 unsigned int
4130 df_hard_reg_used_count (unsigned int reg)
4131 {
4132   return df->hard_regs_live_count[reg];
4133 }
4134
4135
4136 /* Get the value of regs_ever_live[REGNO].  */
4137
4138 bool
4139 df_regs_ever_live_p (unsigned int regno)
4140 {
4141   return regs_ever_live[regno];
4142 }
4143
4144
4145 /* Set regs_ever_live[REGNO] to VALUE.  If this cause regs_ever_live
4146    to change, schedule that change for the next update.  */
4147
4148 void
4149 df_set_regs_ever_live (unsigned int regno, bool value)
4150 {
4151   if (regs_ever_live[regno] == value)
4152     return;
4153
4154   regs_ever_live[regno] = value;
4155   if (df)
4156     df->redo_entry_and_exit = true;
4157 }
4158
4159
4160 /* Compute "regs_ever_live" information from the underlying df
4161    information.  Set the vector to all false if RESET.  */
4162
4163 void
4164 df_compute_regs_ever_live (bool reset)
4165 {
4166   unsigned int i;
4167   bool changed = df->redo_entry_and_exit;
4168
4169   if (reset)
4170     memset (regs_ever_live, 0, sizeof (regs_ever_live));
4171
4172   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4173     if ((!regs_ever_live[i]) && df_hard_reg_used_p (i))
4174       {
4175         regs_ever_live[i] = true;
4176         changed = true;
4177       }
4178   if (changed)
4179     df_update_entry_exit_and_calls ();
4180   df->redo_entry_and_exit = false;
4181 }
4182
4183 \f
4184 /*----------------------------------------------------------------------------
4185   Dataflow ref information verification functions.
4186
4187   df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4188   df_reg_chain_verify_unmarked (refs)
4189   df_refs_verify (VEC(stack,df_ref)*, ref*, bool)
4190   df_mws_verify (mw*, mw*, bool)
4191   df_insn_refs_verify (collection_rec, bb, insn, bool)
4192   df_bb_refs_verify (bb, refs, bool)
4193   df_bb_verify (bb)
4194   df_exit_block_bitmap_verify (bool)
4195   df_entry_block_bitmap_verify (bool)
4196   df_scan_verify ()
4197 ----------------------------------------------------------------------------*/
4198
4199
4200 /* Mark all refs in the reg chain.  Verify that all of the registers
4201 are in the correct chain.  */
4202
4203 static unsigned int
4204 df_reg_chain_mark (df_ref refs, unsigned int regno,
4205                    bool is_def, bool is_eq_use)
4206 {
4207   unsigned int count = 0;
4208   df_ref ref;
4209   for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4210     {
4211       gcc_assert (!DF_REF_IS_REG_MARKED (ref));
4212
4213       /* If there are no def-use or use-def chains, make sure that all
4214          of the chains are clear.  */
4215       if (!df_chain)
4216         gcc_assert (!DF_REF_CHAIN (ref));
4217
4218       /* Check to make sure the ref is in the correct chain.  */
4219       gcc_assert (DF_REF_REGNO (ref) == regno);
4220       if (is_def)
4221         gcc_assert (DF_REF_REG_DEF_P (ref));
4222       else
4223         gcc_assert (!DF_REF_REG_DEF_P (ref));
4224
4225       if (is_eq_use)
4226         gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE));
4227       else
4228         gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) == 0);
4229
4230       if (DF_REF_NEXT_REG (ref))
4231         gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref)) == ref);
4232       count++;
4233       DF_REF_REG_MARK (ref);
4234     }
4235   return count;
4236 }
4237
4238
4239 /* Verify that all of the registers in the chain are unmarked.  */
4240
4241 static void
4242 df_reg_chain_verify_unmarked (df_ref refs)
4243 {
4244   df_ref ref;
4245   for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4246     gcc_assert (!DF_REF_IS_REG_MARKED (ref));
4247 }
4248
4249
4250 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4251
4252 static bool
4253 df_refs_verify (VEC(df_ref,stack) *new_rec, df_ref *old_rec,
4254                 bool abort_if_fail)
4255 {
4256   unsigned int ix;
4257   df_ref new_ref;
4258
4259   FOR_EACH_VEC_ELT (df_ref, new_rec, ix, new_ref)
4260     {
4261       if (*old_rec == NULL || !df_ref_equal_p (new_ref, *old_rec))
4262         {
4263           if (abort_if_fail)
4264             gcc_assert (0);
4265           else
4266             return false;
4267         }
4268
4269       /* Abort if fail is called from the function level verifier.  If
4270          that is the context, mark this reg as being seem.  */
4271       if (abort_if_fail)
4272         {
4273           gcc_assert (DF_REF_IS_REG_MARKED (*old_rec));
4274           DF_REF_REG_UNMARK (*old_rec);
4275         }
4276
4277       old_rec++;
4278     }
4279
4280   if (abort_if_fail)
4281     gcc_assert (*old_rec == NULL);
4282   else
4283     return *old_rec == NULL;
4284   return false;
4285 }
4286
4287
4288 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4289
4290 static bool
4291 df_mws_verify (VEC(df_mw_hardreg_ptr,stack) *new_rec,
4292                struct df_mw_hardreg **old_rec,
4293                bool abort_if_fail)
4294 {
4295   unsigned int ix;
4296   struct df_mw_hardreg *new_reg;
4297
4298   FOR_EACH_VEC_ELT (df_mw_hardreg_ptr, new_rec, ix, new_reg)
4299     {
4300       if (*old_rec == NULL || !df_mw_equal_p (new_reg, *old_rec))
4301         {
4302           if (abort_if_fail)
4303             gcc_assert (0);
4304           else
4305             return false;
4306         }
4307       old_rec++;
4308     }
4309
4310   if (abort_if_fail)
4311     gcc_assert (*old_rec == NULL);
4312   else
4313     return *old_rec == NULL;
4314   return false;
4315 }
4316
4317
4318 /* Return true if the existing insn refs information is complete and
4319    correct. Otherwise (i.e. if there's any missing or extra refs),
4320    return the correct df_ref chain in REFS_RETURN.
4321
4322    If ABORT_IF_FAIL, leave the refs that are verified (already in the
4323    ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4324    verification mode instead of the whole function, so unmark
4325    everything.
4326
4327    If ABORT_IF_FAIL is set, this function never returns false.  */
4328
4329 static bool
4330 df_insn_refs_verify (struct df_collection_rec *collection_rec,
4331                      basic_block bb,
4332                      rtx insn,
4333                      bool abort_if_fail)
4334 {
4335   bool ret1, ret2, ret3, ret4;
4336   unsigned int uid = INSN_UID (insn);
4337   struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
4338
4339   df_insn_refs_collect (collection_rec, bb, insn_info);
4340
4341   if (!DF_INSN_UID_DEFS (uid))
4342     {
4343       /* The insn_rec was created but it was never filled out.  */
4344       if (abort_if_fail)
4345         gcc_assert (0);
4346       else
4347         return false;
4348     }
4349
4350   /* Unfortunately we cannot opt out early if one of these is not
4351      right because the marks will not get cleared.  */
4352   ret1 = df_refs_verify (collection_rec->def_vec, DF_INSN_UID_DEFS (uid),
4353                          abort_if_fail);
4354   ret2 = df_refs_verify (collection_rec->use_vec, DF_INSN_UID_USES (uid),
4355                          abort_if_fail);
4356   ret3 = df_refs_verify (collection_rec->eq_use_vec, DF_INSN_UID_EQ_USES (uid),
4357                          abort_if_fail);
4358   ret4 = df_mws_verify (collection_rec->mw_vec, DF_INSN_UID_MWS (uid),
4359                        abort_if_fail);
4360   return (ret1 && ret2 && ret3 && ret4);
4361 }
4362
4363
4364 /* Return true if all refs in the basic block are correct and complete.
4365    Due to df_ref_chain_verify, it will cause all refs
4366    that are verified to have DF_REF_MARK bit set.  */
4367
4368 static bool
4369 df_bb_verify (basic_block bb)
4370 {
4371   rtx insn;
4372   struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
4373   struct df_collection_rec collection_rec;
4374
4375   memset (&collection_rec, 0, sizeof (struct df_collection_rec));
4376   collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
4377   collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
4378   collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
4379   collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
4380
4381   gcc_assert (bb_info);
4382
4383   /* Scan the block, one insn at a time, from beginning to end.  */
4384   FOR_BB_INSNS_REVERSE (bb, insn)
4385     {
4386       if (!INSN_P (insn))
4387         continue;
4388       df_insn_refs_verify (&collection_rec, bb, insn, true);
4389       df_free_collection_rec (&collection_rec);
4390     }
4391
4392   /* Do the artificial defs and uses.  */
4393   df_bb_refs_collect (&collection_rec, bb);
4394   df_refs_verify (collection_rec.def_vec, df_get_artificial_defs (bb->index), true);
4395   df_refs_verify (collection_rec.use_vec, df_get_artificial_uses (bb->index), true);
4396   df_free_collection_rec (&collection_rec);
4397
4398   return true;
4399 }
4400
4401
4402 /* Returns true if the entry block has correct and complete df_ref set.
4403    If not it either aborts if ABORT_IF_FAIL is true or returns false.  */
4404
4405 static bool
4406 df_entry_block_bitmap_verify (bool abort_if_fail)
4407 {
4408   bitmap_head entry_block_defs;
4409   bool is_eq;
4410
4411   bitmap_initialize (&entry_block_defs, &df_bitmap_obstack);
4412   df_get_entry_block_def_set (&entry_block_defs);
4413
4414   is_eq = bitmap_equal_p (&entry_block_defs, df->entry_block_defs);
4415
4416   if (!is_eq && abort_if_fail)
4417     {
4418       print_current_pass (stderr);
4419       fprintf (stderr, "entry_block_defs = ");
4420       df_print_regset (stderr, &entry_block_defs);
4421       fprintf (stderr, "df->entry_block_defs = ");
4422       df_print_regset (stderr, df->entry_block_defs);
4423       gcc_assert (0);
4424     }
4425
4426   bitmap_clear (&entry_block_defs);
4427
4428   return is_eq;
4429 }
4430
4431
4432 /* Returns true if the exit block has correct and complete df_ref set.
4433    If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4434
4435 static bool
4436 df_exit_block_bitmap_verify (bool abort_if_fail)
4437 {
4438   bitmap_head exit_block_uses;
4439   bool is_eq;
4440
4441   bitmap_initialize (&exit_block_uses, &df_bitmap_obstack);
4442   df_get_exit_block_use_set (&exit_block_uses);
4443
4444   is_eq = bitmap_equal_p (&exit_block_uses, df->exit_block_uses);
4445
4446   if (!is_eq && abort_if_fail)
4447     {
4448       print_current_pass (stderr);
4449       fprintf (stderr, "exit_block_uses = ");
4450       df_print_regset (stderr, &exit_block_uses);
4451       fprintf (stderr, "df->exit_block_uses = ");
4452       df_print_regset (stderr, df->exit_block_uses);
4453       gcc_assert (0);
4454     }
4455
4456   bitmap_clear (&exit_block_uses);
4457
4458   return is_eq;
4459 }
4460
4461
4462 /* Return true if df_ref information for all insns in all blocks are
4463    correct and complete.  */
4464
4465 void
4466 df_scan_verify (void)
4467 {
4468   unsigned int i;
4469   basic_block bb;
4470   bitmap_head regular_block_artificial_uses;
4471   bitmap_head eh_block_artificial_uses;
4472
4473   if (!df)
4474     return;
4475
4476   /* Verification is a 4 step process. */
4477
4478   /* (1) All of the refs are marked by going thru the reg chains.  */
4479   for (i = 0; i < DF_REG_SIZE (df); i++)
4480     {
4481       gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false)
4482                   == DF_REG_DEF_COUNT(i));
4483       gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i), i, false, false)
4484                   == DF_REG_USE_COUNT(i));
4485       gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i), i, false, true)
4486                   == DF_REG_EQ_USE_COUNT(i));
4487     }
4488
4489   /* (2) There are various bitmaps whose value may change over the
4490      course of the compilation.  This step recomputes them to make
4491      sure that they have not slipped out of date.  */
4492   bitmap_initialize (&regular_block_artificial_uses, &df_bitmap_obstack);
4493   bitmap_initialize (&eh_block_artificial_uses, &df_bitmap_obstack);
4494
4495   df_get_regular_block_artificial_uses (&regular_block_artificial_uses);
4496   df_get_eh_block_artificial_uses (&eh_block_artificial_uses);
4497
4498   bitmap_ior_into (&eh_block_artificial_uses,
4499                    &regular_block_artificial_uses);
4500
4501   /* Check artificial_uses bitmaps didn't change. */
4502   gcc_assert (bitmap_equal_p (&regular_block_artificial_uses,
4503                               &df->regular_block_artificial_uses));
4504   gcc_assert (bitmap_equal_p (&eh_block_artificial_uses,
4505                               &df->eh_block_artificial_uses));
4506
4507   bitmap_clear (&regular_block_artificial_uses);
4508   bitmap_clear (&eh_block_artificial_uses);
4509
4510   /* Verify entry block and exit block. These only verify the bitmaps,
4511      the refs are verified in df_bb_verify.  */
4512   df_entry_block_bitmap_verify (true);
4513   df_exit_block_bitmap_verify (true);
4514
4515   /* (3) All of the insns in all of the blocks are traversed and the
4516      marks are cleared both in the artificial refs attached to the
4517      blocks and the real refs inside the insns.  It is a failure to
4518      clear a mark that has not been set as this means that the ref in
4519      the block or insn was not in the reg chain.  */
4520
4521   FOR_ALL_BB (bb)
4522     df_bb_verify (bb);
4523
4524   /* (4) See if all reg chains are traversed a second time.  This time
4525      a check is made that the marks are clear. A set mark would be a
4526      from a reg that is not in any insn or basic block.  */
4527
4528   for (i = 0; i < DF_REG_SIZE (df); i++)
4529     {
4530       df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i));
4531       df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i));
4532       df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i));
4533     }
4534 }