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