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