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