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