cgraphunit.c (handle_alias_pairs): Also handle wekref with destination declared.
[official-gcc.git] / gcc / df-scan.c
blobdeaa9f96d5323aff8bde0369943ec0659ca243d1
1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "recog.h"
33 #include "function.h"
34 #include "regs.h"
35 #include "output.h"
36 #include "alloc-pool.h"
37 #include "flags.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "sbitmap.h"
41 #include "bitmap.h"
42 #include "timevar.h"
43 #include "tree.h"
44 #include "target.h"
45 #include "target-def.h"
46 #include "df.h"
47 #include "tree-pass.h"
48 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
50 DEF_VEC_P(df_ref);
51 DEF_VEC_ALLOC_P_STACK(df_ref);
53 #define VEC_df_ref_stack_alloc(alloc) VEC_stack_alloc (df_ref, alloc)
55 typedef struct df_mw_hardreg *df_mw_hardreg_ptr;
57 DEF_VEC_P(df_mw_hardreg_ptr);
58 DEF_VEC_ALLOC_P_STACK(df_mw_hardreg_ptr);
60 #define VEC_df_mw_hardreg_ptr_stack_alloc(alloc) \
61 VEC_stack_alloc (df_mw_hardreg_ptr, alloc)
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
73 #ifndef EPILOGUE_USES
74 #define EPILOGUE_USES(REGNO) 0
75 #endif
77 /* The following two macros free the vecs that hold either the refs or
78 the mw refs. They are a little tricky because the vec has 0
79 elements is special and is not to be freed. */
80 #define df_scan_free_ref_vec(V) \
81 do { \
82 if (V && *V) \
83 free (V); \
84 } while (0)
86 #define df_scan_free_mws_vec(V) \
87 do { \
88 if (V && *V) \
89 free (V); \
90 } while (0)
92 /* The set of hard registers in eliminables[i].from. */
94 static HARD_REG_SET elim_reg_set;
96 /* Initialize ur_in and ur_out as if all hard registers were partially
97 available. */
99 struct df_collection_rec
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;
107 static df_ref df_null_ref_rec[1];
108 static struct df_mw_hardreg * df_null_mw_rec[1];
110 static void df_ref_record (enum df_ref_class, struct df_collection_rec *,
111 rtx, rtx *,
112 basic_block, struct df_insn_info *,
113 enum df_ref_type, int ref_flags);
114 static void df_def_record_1 (struct df_collection_rec *, rtx,
115 basic_block, struct df_insn_info *,
116 int ref_flags);
117 static void df_defs_record (struct df_collection_rec *, rtx,
118 basic_block, struct df_insn_info *,
119 int ref_flags);
120 static void df_uses_record (struct df_collection_rec *,
121 rtx *, enum df_ref_type,
122 basic_block, struct df_insn_info *,
123 int ref_flags);
125 static void df_install_ref_incremental (df_ref);
126 static df_ref df_ref_create_structure (enum df_ref_class,
127 struct df_collection_rec *, rtx, rtx *,
128 basic_block, struct df_insn_info *,
129 enum df_ref_type, int ref_flags);
130 static void df_insn_refs_collect (struct df_collection_rec*,
131 basic_block, struct df_insn_info *);
132 static void df_canonize_collection_rec (struct df_collection_rec *);
134 static void df_get_regular_block_artificial_uses (bitmap);
135 static void df_get_eh_block_artificial_uses (bitmap);
137 static void df_record_entry_block_defs (bitmap);
138 static void df_record_exit_block_uses (bitmap);
139 static void df_get_exit_block_use_set (bitmap);
140 static void df_get_entry_block_def_set (bitmap);
141 static void df_grow_ref_info (struct df_ref_info *, unsigned int);
142 static void df_ref_chain_delete_du_chain (df_ref *);
143 static void df_ref_chain_delete (df_ref *);
145 static void df_refs_add_to_chains (struct df_collection_rec *,
146 basic_block, rtx);
148 static bool df_insn_refs_verify (struct df_collection_rec *, basic_block, rtx, bool);
149 static void df_entry_block_defs_collect (struct df_collection_rec *, bitmap);
150 static void df_exit_block_uses_collect (struct df_collection_rec *, bitmap);
151 static void df_install_ref (df_ref, struct df_reg_info *,
152 struct df_ref_info *, bool);
154 static int df_ref_compare (const void *, const void *);
155 static int df_mw_compare (const void *, const void *);
157 /* Indexed by hardware reg number, is true if that register is ever
158 used in the current function.
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. */
165 static bool regs_ever_live[FIRST_PSEUDO_REGISTER];
167 /*----------------------------------------------------------------------------
168 SCANNING DATAFLOW PROBLEM
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 ----------------------------------------------------------------------------*/
176 /* Problem data for the scanning dataflow function. */
177 struct df_scan_problem_data
179 alloc_pool ref_base_pool;
180 alloc_pool ref_artificial_pool;
181 alloc_pool ref_regular_pool;
182 alloc_pool insn_pool;
183 alloc_pool reg_pool;
184 alloc_pool mw_reg_pool;
185 bitmap_obstack reg_bitmaps;
186 bitmap_obstack insn_bitmaps;
189 typedef struct df_scan_bb_info *df_scan_bb_info_t;
192 /* Internal function to shut down the scanning problem. */
193 static void
194 df_scan_free_internal (void)
196 struct df_scan_problem_data *problem_data
197 = (struct df_scan_problem_data *) df_scan->problem_data;
198 unsigned int i;
199 basic_block bb;
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++)
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)
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);
218 FOR_ALL_BB (bb)
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)
224 df_scan_free_ref_vec (bb_info->artificial_defs);
225 df_scan_free_ref_vec (bb_info->artificial_uses);
229 free (df->def_info.refs);
230 free (df->def_info.begin);
231 free (df->def_info.count);
232 memset (&df->def_info, 0, (sizeof (struct df_ref_info)));
234 free (df->use_info.refs);
235 free (df->use_info.begin);
236 free (df->use_info.count);
237 memset (&df->use_info, 0, (sizeof (struct df_ref_info)));
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;
248 free (df->insns);
249 df->insns = NULL;
250 DF_INSN_SIZE () = 0;
252 free (df_scan->block_info);
253 df_scan->block_info = NULL;
254 df_scan->block_info_size = 0;
256 bitmap_clear (&df->hardware_regs_used);
257 bitmap_clear (&df->regular_block_artificial_uses);
258 bitmap_clear (&df->eh_block_artificial_uses);
259 BITMAP_FREE (df->entry_block_defs);
260 BITMAP_FREE (df->exit_block_uses);
261 bitmap_clear (&df->insns_to_delete);
262 bitmap_clear (&df->insns_to_rescan);
263 bitmap_clear (&df->insns_to_notes_rescan);
265 free_alloc_pool (problem_data->ref_base_pool);
266 free_alloc_pool (problem_data->ref_artificial_pool);
267 free_alloc_pool (problem_data->ref_regular_pool);
268 free_alloc_pool (problem_data->insn_pool);
269 free_alloc_pool (problem_data->reg_pool);
270 free_alloc_pool (problem_data->mw_reg_pool);
271 bitmap_obstack_release (&problem_data->reg_bitmaps);
272 bitmap_obstack_release (&problem_data->insn_bitmaps);
273 free (df_scan->problem_data);
277 /* Free basic block info. */
279 static void
280 df_scan_free_bb_info (basic_block bb, void *vbb_info)
282 struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
283 unsigned int bb_index = bb->index;
285 /* See if bb_info is initialized. */
286 if (bb_info->artificial_defs)
288 rtx insn;
289 FOR_BB_INSNS (bb, insn)
291 if (INSN_P (insn))
292 /* Record defs within INSN. */
293 df_insn_delete (bb, INSN_UID (insn));
296 if (bb_index < df_scan->block_info_size)
297 bb_info = df_scan_get_bb_info (bb_index);
299 /* Get rid of any artificial uses or defs. */
300 if (bb_info->artificial_defs)
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;
313 /* Allocate the problem data for the scanning problem. This should be
314 called when the problem is created or when the entire function is to
315 be rescanned. */
316 void
317 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
319 struct df_scan_problem_data *problem_data;
320 unsigned int insn_num = get_max_uid () + 1;
321 unsigned int block_size = 400;
322 basic_block bb;
324 /* Given the number of pools, this is really faster than tearing
325 everything apart. */
326 if (df_scan->problem_data)
327 df_scan_free_internal ();
329 problem_data = XNEW (struct df_scan_problem_data);
330 df_scan->problem_data = problem_data;
331 df_scan->computed = true;
333 problem_data->ref_base_pool
334 = create_alloc_pool ("df_scan ref base",
335 sizeof (struct df_base_ref), block_size);
336 problem_data->ref_artificial_pool
337 = create_alloc_pool ("df_scan ref artificial",
338 sizeof (struct df_artificial_ref), block_size);
339 problem_data->ref_regular_pool
340 = create_alloc_pool ("df_scan ref regular",
341 sizeof (struct df_regular_ref), block_size);
342 problem_data->insn_pool
343 = create_alloc_pool ("df_scan insn",
344 sizeof (struct df_insn_info), block_size);
345 problem_data->reg_pool
346 = create_alloc_pool ("df_scan reg",
347 sizeof (struct df_reg_info), block_size);
348 problem_data->mw_reg_pool
349 = create_alloc_pool ("df_scan mw_reg",
350 sizeof (struct df_mw_hardreg), block_size);
352 bitmap_obstack_initialize (&problem_data->reg_bitmaps);
353 bitmap_obstack_initialize (&problem_data->insn_bitmaps);
355 insn_num += insn_num / 4;
356 df_grow_reg_info ();
358 df_grow_insn_info ();
359 df_grow_bb_info (df_scan);
361 FOR_ALL_BB (bb)
363 unsigned int bb_index = bb->index;
364 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
365 bb_info->artificial_defs = NULL;
366 bb_info->artificial_uses = NULL;
369 bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps);
370 bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps);
371 bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps);
372 df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
373 df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
374 bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps);
375 bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps);
376 bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps);
377 df_scan->optional_p = false;
381 /* Free all of the data associated with the scan problem. */
383 static void
384 df_scan_free (void)
386 if (df_scan->problem_data)
387 df_scan_free_internal ();
389 if (df->blocks_to_analyze)
391 BITMAP_FREE (df->blocks_to_analyze);
392 df->blocks_to_analyze = NULL;
395 free (df_scan);
398 /* Dump the preamble for DF_SCAN dump. */
399 static void
400 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
402 int i;
403 int dcount = 0;
404 int ucount = 0;
405 int ecount = 0;
406 int icount = 0;
407 int ccount = 0;
408 basic_block bb;
409 rtx insn;
411 fprintf (file, ";; invalidated by call \t");
412 df_print_regset (file, regs_invalidated_by_call_regset);
413 fprintf (file, ";; hardware regs used \t");
414 df_print_regset (file, &df->hardware_regs_used);
415 fprintf (file, ";; regular block artificial uses \t");
416 df_print_regset (file, &df->regular_block_artificial_uses);
417 fprintf (file, ";; eh block artificial uses \t");
418 df_print_regset (file, &df->eh_block_artificial_uses);
419 fprintf (file, ";; entry block defs \t");
420 df_print_regset (file, df->entry_block_defs);
421 fprintf (file, ";; exit block uses \t");
422 df_print_regset (file, df->exit_block_uses);
423 fprintf (file, ";; regs ever live \t");
424 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
425 if (df_regs_ever_live_p (i))
426 fprintf (file, " %d[%s]", i, reg_names[i]);
427 fprintf (file, "\n;; ref usage \t");
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))
432 const char * sep = "";
434 fprintf (file, "r%d={", i);
435 if (DF_REG_DEF_COUNT (i))
437 fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
438 sep = ",";
439 dcount += DF_REG_DEF_COUNT (i);
441 if (DF_REG_USE_COUNT (i))
443 fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
444 sep = ",";
445 ucount += DF_REG_USE_COUNT (i);
447 if (DF_REG_EQ_USE_COUNT (i))
449 fprintf (file, "%s%de", sep, DF_REG_EQ_USE_COUNT (i));
450 ecount += DF_REG_EQ_USE_COUNT (i);
452 fprintf (file, "} ");
455 FOR_EACH_BB (bb)
456 FOR_BB_INSNS (bb, insn)
457 if (INSN_P (insn))
459 if (CALL_P (insn))
460 ccount++;
461 else
462 icount++;
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);
471 /* Dump the bb_info for a given basic block. */
472 static void
473 df_scan_start_block (basic_block bb, FILE *file)
475 struct df_scan_bb_info *bb_info
476 = df_scan_get_bb_info (bb->index);
478 if (bb_info)
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");
486 #if 0
488 rtx insn;
489 FOR_BB_INSNS (bb, insn)
490 if (INSN_P (insn))
491 df_insn_debug (insn, false, file);
493 #endif
496 static struct df_problem problem_SCAN =
498 DF_SCAN, /* Problem id. */
499 DF_NONE, /* Direction. */
500 df_scan_alloc, /* Allocate the problem specific data. */
501 NULL, /* Reset global information. */
502 df_scan_free_bb_info, /* Free basic block info. */
503 NULL, /* Local compute function. */
504 NULL, /* Init the solution specific data. */
505 NULL, /* Iterative solver. */
506 NULL, /* Confluence operator 0. */
507 NULL, /* Confluence operator n. */
508 NULL, /* Transfer function. */
509 NULL, /* Finalize function. */
510 df_scan_free, /* Free all of the problem information. */
511 NULL, /* Remove this problem from the stack of dataflow problems. */
512 df_scan_start_dump, /* Debugging. */
513 df_scan_start_block, /* Debugging start block. */
514 NULL, /* Debugging end block. */
515 NULL, /* Incremental solution verify start. */
516 NULL, /* Incremental solution verify end. */
517 NULL, /* Dependent problem. */
518 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
519 TV_DF_SCAN, /* Timing variable. */
520 false /* Reset blocks on dropping out of blocks_to_analyze. */
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. */
528 void
529 df_scan_add_problem (void)
531 df_add_problem (&problem_SCAN);
535 /*----------------------------------------------------------------------------
536 Storage Allocation Utilities
537 ----------------------------------------------------------------------------*/
540 /* First, grow the reg_info information. If the current size is less than
541 the number of pseudos, grow to 25% more than the number of
542 pseudos.
544 Second, assure that all of the slots up to max_reg_num have been
545 filled with reg_info structures. */
547 void
548 df_grow_reg_info (void)
550 unsigned int max_reg = max_reg_num ();
551 unsigned int new_size = max_reg;
552 struct df_scan_problem_data *problem_data
553 = (struct df_scan_problem_data *) df_scan->problem_data;
554 unsigned int i;
556 if (df->regs_size < new_size)
558 new_size += new_size / 4;
559 df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
560 df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
561 df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
562 new_size);
563 df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
564 df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
565 df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
566 df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
567 df->regs_size = new_size;
570 for (i = df->regs_inited; i < max_reg; i++)
572 struct df_reg_info *reg_info;
574 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
575 memset (reg_info, 0, sizeof (struct df_reg_info));
576 df->def_regs[i] = reg_info;
577 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
578 memset (reg_info, 0, sizeof (struct df_reg_info));
579 df->use_regs[i] = reg_info;
580 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
581 memset (reg_info, 0, sizeof (struct df_reg_info));
582 df->eq_use_regs[i] = reg_info;
583 df->def_info.begin[i] = 0;
584 df->def_info.count[i] = 0;
585 df->use_info.begin[i] = 0;
586 df->use_info.count[i] = 0;
589 df->regs_inited = max_reg;
593 /* Grow the ref information. */
595 static void
596 df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
598 if (ref_info->refs_size < new_size)
600 ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
601 memset (ref_info->refs + ref_info->refs_size, 0,
602 (new_size - ref_info->refs_size) *sizeof (df_ref));
603 ref_info->refs_size = new_size;
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. */
613 static void
614 df_check_and_grow_ref_info (struct df_ref_info *ref_info,
615 unsigned bitmap_addend)
617 if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
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);
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. */
630 void
631 df_grow_insn_info (void)
633 unsigned int new_size = get_max_uid () + 1;
634 if (DF_INSN_SIZE () < new_size)
636 new_size += new_size / 4;
637 df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
638 memset (df->insns + df->insns_size, 0,
639 (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
640 DF_INSN_SIZE () = new_size;
647 /*----------------------------------------------------------------------------
648 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
649 ----------------------------------------------------------------------------*/
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; */
654 void
655 df_scan_blocks (void)
657 basic_block bb;
659 df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
660 df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
662 df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses);
663 df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses);
665 bitmap_ior_into (&df->eh_block_artificial_uses,
666 &df->regular_block_artificial_uses);
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));
676 /* Regular blocks */
677 FOR_EACH_BB (bb)
679 unsigned int bb_index = bb->index;
680 df_bb_refs_record (bb_index, true);
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. */
688 void
689 df_uses_create (rtx *loc, rtx insn, int ref_flags)
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);
698 /* Create a new ref of type DF_REF_TYPE for register REG at address
699 LOC within INSN of BB. This function is only used externally. */
701 df_ref
702 df_ref_create (rtx reg, rtx *loc, rtx insn,
703 basic_block bb,
704 enum df_ref_type ref_type,
705 int ref_flags)
707 enum df_ref_class cl;
709 df_grow_reg_info ();
711 /* You cannot hack artificial refs. */
712 gcc_assert (insn);
714 if (loc)
715 cl = DF_REF_REGULAR;
716 else
717 cl = DF_REF_BASE;
719 return df_ref_create_structure (cl, NULL, reg, loc, bb,
720 DF_INSN_INFO_GET (insn),
721 ref_type, ref_flags);
724 static void
725 df_install_ref_incremental (df_ref ref)
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;
734 rtx insn = DF_REF_INSN (ref);
735 basic_block bb = BLOCK_FOR_INSN (insn);
737 if (DF_REF_REG_DEF_P (ref))
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;
744 else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
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)
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;
761 else
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;
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);
773 df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
775 if (add_to_table)
776 switch (ref_info->ref_order)
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;
788 ref_rec = *ref_rec_ptr;
789 while (*ref_rec)
791 count++;
792 ref_rec++;
795 ref_rec = *ref_rec_ptr;
796 if (count)
798 ref_rec = XRESIZEVEC (df_ref, ref_rec, count+2);
799 *ref_rec_ptr = ref_rec;
800 ref_rec[count] = ref;
801 ref_rec[count+1] = NULL;
802 qsort (ref_rec, count + 1, sizeof (df_ref), df_ref_compare);
804 else
806 df_ref *ref_rec = XNEWVEC (df_ref, 2);
807 ref_rec[0] = ref;
808 ref_rec[1] = NULL;
809 *ref_rec_ptr = ref_rec;
812 #if 0
813 if (dump_file)
815 fprintf (dump_file, "adding ref ");
816 df_ref_debug (ref, dump_file);
818 #endif
819 /* By adding the ref directly, df_insn_rescan my not find any
820 differences even though the block will have changed. So we need
821 to mark the block dirty ourselves. */
822 if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
823 df_set_bb_dirty (bb);
828 /*----------------------------------------------------------------------------
829 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
830 ----------------------------------------------------------------------------*/
832 static void
833 df_free_ref (df_ref ref)
835 struct df_scan_problem_data *problem_data
836 = (struct df_scan_problem_data *) df_scan->problem_data;
838 switch (DF_REF_CLASS (ref))
840 case DF_REF_BASE:
841 pool_free (problem_data->ref_base_pool, ref);
842 break;
844 case DF_REF_ARTIFICIAL:
845 pool_free (problem_data->ref_artificial_pool, ref);
846 break;
848 case DF_REF_REGULAR:
849 pool_free (problem_data->ref_regular_pool, ref);
850 break;
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. */
858 static void
859 df_reg_chain_unlink (df_ref ref)
861 df_ref next = DF_REF_NEXT_REG (ref);
862 df_ref prev = DF_REF_PREV_REG (ref);
863 int id = DF_REF_ID (ref);
864 struct df_reg_info *reg_info;
865 df_ref *refs = NULL;
867 if (DF_REF_REG_DEF_P (ref))
869 int regno = DF_REF_REGNO (ref);
870 reg_info = DF_REG_DEF_GET (regno);
871 refs = df->def_info.refs;
873 else
875 if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
877 reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
878 switch (df->use_info.ref_order)
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;
889 else
891 reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
892 refs = df->use_info.refs;
896 if (refs)
898 if (df->analyze_subset)
900 if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
901 refs[id] = NULL;
903 else
904 refs[id] = NULL;
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);
915 reg_info->n_refs--;
916 if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
918 gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
919 df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
922 /* Unlink from the reg chain. If there is no prev, this is the
923 first of the list. If not, just join the next and prev. */
924 if (prev)
925 DF_REF_NEXT_REG (prev) = next;
926 else
928 gcc_assert (reg_info->reg_chain == ref);
929 reg_info->reg_chain = next;
931 if (next)
932 DF_REF_PREV_REG (next) = prev;
934 df_free_ref (ref);
938 /* Remove REF from VEC. */
940 static void
941 df_ref_compress_rec (df_ref **vec_ptr, df_ref ref)
943 df_ref *vec = *vec_ptr;
945 if (vec[1])
947 while (*vec && *vec != ref)
948 vec++;
950 while (*vec)
952 *vec = *(vec+1);
953 vec++;
956 else
958 free (vec);
959 *vec_ptr = df_null_ref_rec;
964 /* Unlink REF from all def-use/use-def chains, etc. */
966 void
967 df_ref_remove (df_ref ref)
969 #if 0
970 if (dump_file)
972 fprintf (dump_file, "removing ref ");
973 df_ref_debug (ref, dump_file);
975 #endif
977 if (DF_REF_REG_DEF_P (ref))
979 if (DF_REF_IS_ARTIFICIAL (ref))
981 struct df_scan_bb_info *bb_info
982 = df_scan_get_bb_info (DF_REF_BBNO (ref));
983 df_ref_compress_rec (&bb_info->artificial_defs, ref);
985 else
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);
992 else
994 if (DF_REF_IS_ARTIFICIAL (ref))
996 struct df_scan_bb_info *bb_info
997 = df_scan_get_bb_info (DF_REF_BBNO (ref));
998 df_ref_compress_rec (&bb_info->artificial_uses, ref);
1000 else
1002 unsigned int uid = DF_REF_INSN_UID (ref);
1003 struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
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);
1012 /* By deleting the ref directly, df_insn_rescan my not find any
1013 differences even though the block will have changed. So we need
1014 to mark the block dirty ourselves. */
1015 if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
1016 df_set_bb_dirty (DF_REF_BB (ref));
1017 df_reg_chain_unlink (ref);
1021 /* Create the insn record for INSN. If there was one there, zero it
1022 out. */
1024 struct df_insn_info *
1025 df_insn_create_insn_record (rtx insn)
1027 struct df_scan_problem_data *problem_data
1028 = (struct df_scan_problem_data *) df_scan->problem_data;
1029 struct df_insn_info *insn_rec;
1031 df_grow_insn_info ();
1032 insn_rec = DF_INSN_INFO_GET (insn);
1033 if (!insn_rec)
1035 insn_rec = (struct df_insn_info *) pool_alloc (problem_data->insn_pool);
1036 DF_INSN_INFO_SET (insn, insn_rec);
1038 memset (insn_rec, 0, sizeof (struct df_insn_info));
1039 insn_rec->insn = insn;
1040 return insn_rec;
1044 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
1046 static void
1047 df_ref_chain_delete_du_chain (df_ref *ref_rec)
1049 while (*ref_rec)
1051 df_ref ref = *ref_rec;
1052 /* CHAIN is allocated by DF_CHAIN. So make sure to
1053 pass df_scan instance for the problem. */
1054 if (DF_REF_CHAIN (ref))
1055 df_chain_unlink (ref);
1056 ref_rec++;
1061 /* Delete all refs in the ref chain. */
1063 static void
1064 df_ref_chain_delete (df_ref *ref_rec)
1066 df_ref *start = ref_rec;
1067 while (*ref_rec)
1069 df_reg_chain_unlink (*ref_rec);
1070 ref_rec++;
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);
1080 /* Delete the hardreg chain. */
1082 static void
1083 df_mw_hardreg_chain_delete (struct df_mw_hardreg **hardregs)
1085 struct df_scan_problem_data *problem_data;
1087 if (!hardregs)
1088 return;
1090 problem_data = (struct df_scan_problem_data *) df_scan->problem_data;
1092 while (*hardregs)
1094 pool_free (problem_data->mw_reg_pool, *hardregs);
1095 hardregs++;
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. */
1104 void
1105 df_insn_delete (basic_block bb, unsigned int uid)
1107 struct df_insn_info *insn_info = NULL;
1108 if (!df)
1109 return;
1111 df_grow_bb_info (df_scan);
1112 df_grow_reg_info ();
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);
1120 insn_info = DF_INSN_UID_SAFE_GET (uid);
1122 /* The client has deferred rescanning. */
1123 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1125 if (insn_info)
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);
1131 if (dump_file)
1132 fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
1133 return;
1136 if (dump_file)
1137 fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
1139 bitmap_clear_bit (&df->insns_to_delete, uid);
1140 bitmap_clear_bit (&df->insns_to_rescan, uid);
1141 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1142 if (insn_info)
1144 struct df_scan_problem_data *problem_data
1145 = (struct df_scan_problem_data *) df_scan->problem_data;
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)
1154 df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1156 if (df_chain)
1158 df_ref_chain_delete_du_chain (insn_info->defs);
1159 df_ref_chain_delete_du_chain (insn_info->uses);
1160 df_ref_chain_delete_du_chain (insn_info->eq_uses);
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);
1167 pool_free (problem_data->insn_pool, insn_info);
1168 DF_INSN_UID_SET (uid, NULL);
1173 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1175 static void
1176 df_free_collection_rec (struct df_collection_rec *collection_rec)
1178 unsigned int ix;
1179 struct df_scan_problem_data *problem_data
1180 = (struct df_scan_problem_data *) df_scan->problem_data;
1181 df_ref ref;
1182 struct df_mw_hardreg *mw;
1184 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
1185 df_free_ref (ref);
1186 FOR_EACH_VEC_ELT (df_ref, collection_rec->use_vec, ix, ref)
1187 df_free_ref (ref);
1188 FOR_EACH_VEC_ELT (df_ref, collection_rec->eq_use_vec, ix, ref)
1189 df_free_ref (ref);
1190 FOR_EACH_VEC_ELT (df_mw_hardreg_ptr, collection_rec->mw_vec, ix, mw)
1191 pool_free (problem_data->mw_reg_pool, mw);
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);
1199 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1201 bool
1202 df_insn_rescan (rtx insn)
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;
1209 if ((!df) || (!INSN_P (insn)))
1210 return false;
1212 if (!bb)
1214 if (dump_file)
1215 fprintf (dump_file, "no bb for insn with uid = %d.\n", uid);
1216 return false;
1219 /* The client has disabled rescanning and plans to do it itself. */
1220 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1221 return false;
1223 df_grow_bb_info (df_scan);
1224 df_grow_reg_info ();
1226 insn_info = DF_INSN_UID_SAFE_GET (uid);
1228 /* The client has deferred rescanning. */
1229 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1231 if (!insn_info)
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;
1239 if (dump_file)
1240 fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid);
1242 bitmap_clear_bit (&df->insns_to_delete, uid);
1243 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1244 bitmap_set_bit (&df->insns_to_rescan, INSN_UID (insn));
1245 return false;
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);
1253 bitmap_clear_bit (&df->insns_to_delete, uid);
1254 bitmap_clear_bit (&df->insns_to_rescan, uid);
1255 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1256 if (insn_info)
1258 int luid;
1259 bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false);
1260 /* If there's no change, return false. */
1261 if (the_same)
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;
1268 if (dump_file)
1269 fprintf (dump_file, "rescanning insn with uid = %d.\n", uid);
1271 /* There's change - we need to delete the existing info.
1272 Since the insn isn't moved, we can salvage its LUID. */
1273 luid = DF_INSN_LUID (insn);
1274 df_insn_delete (NULL, uid);
1275 df_insn_create_insn_record (insn);
1276 DF_INSN_LUID (insn) = luid;
1278 else
1280 struct df_insn_info *insn_info = df_insn_create_insn_record (insn);
1281 df_insn_refs_collect (&collection_rec, bb, insn_info);
1282 if (dump_file)
1283 fprintf (dump_file, "scanning new insn with uid = %d.\n", uid);
1286 df_refs_add_to_chains (&collection_rec, bb, insn);
1287 if (!DEBUG_INSN_P (insn))
1288 df_set_bb_dirty (bb);
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);
1295 return true;
1298 /* Same as df_insn_rescan, but don't mark the basic block as
1299 dirty. */
1301 bool
1302 df_insn_rescan_debug_internal (rtx insn)
1304 unsigned int uid = INSN_UID (insn);
1305 struct df_insn_info *insn_info;
1307 gcc_assert (DEBUG_INSN_P (insn)
1308 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)));
1310 if (!df)
1311 return false;
1313 insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
1314 if (!insn_info)
1315 return false;
1317 if (dump_file)
1318 fprintf (dump_file, "deleting debug_insn with uid = %d.\n", uid);
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);
1324 if (!insn_info->defs)
1325 return false;
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;
1333 df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1335 if (df_chain)
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);
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);
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;
1351 return true;
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. */
1359 void
1360 df_insn_rescan_all (void)
1362 bool no_insn_rescan = false;
1363 bool defer_insn_rescan = false;
1364 basic_block bb;
1365 bitmap_iterator bi;
1366 unsigned int uid;
1367 bitmap_head tmp;
1369 bitmap_initialize (&tmp, &df_bitmap_obstack);
1371 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1373 df_clear_flags (DF_NO_INSN_RESCAN);
1374 no_insn_rescan = true;
1377 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1379 df_clear_flags (DF_DEFER_INSN_RESCAN);
1380 defer_insn_rescan = true;
1383 bitmap_copy (&tmp, &df->insns_to_delete);
1384 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1386 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1387 if (insn_info)
1388 df_insn_delete (NULL, uid);
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);
1396 FOR_EACH_BB (bb)
1398 rtx insn;
1399 FOR_BB_INSNS (bb, insn)
1401 df_insn_rescan (insn);
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);
1412 /* Process all of the deferred rescans or deletions. */
1414 void
1415 df_process_deferred_rescans (void)
1417 bool no_insn_rescan = false;
1418 bool defer_insn_rescan = false;
1419 bitmap_iterator bi;
1420 unsigned int uid;
1421 bitmap_head tmp;
1423 bitmap_initialize (&tmp, &df_bitmap_obstack);
1425 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1427 df_clear_flags (DF_NO_INSN_RESCAN);
1428 no_insn_rescan = true;
1431 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1433 df_clear_flags (DF_DEFER_INSN_RESCAN);
1434 defer_insn_rescan = true;
1437 if (dump_file)
1438 fprintf (dump_file, "starting the processing of deferred insns\n");
1440 bitmap_copy (&tmp, &df->insns_to_delete);
1441 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1443 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1444 if (insn_info)
1445 df_insn_delete (NULL, uid);
1448 bitmap_copy (&tmp, &df->insns_to_rescan);
1449 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1451 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1452 if (insn_info)
1453 df_insn_rescan (insn_info->insn);
1456 bitmap_copy (&tmp, &df->insns_to_notes_rescan);
1457 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1459 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1460 if (insn_info)
1461 df_notes_rescan (insn_info->insn);
1464 if (dump_file)
1465 fprintf (dump_file, "ending the processing of deferred insns\n");
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);
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);
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)
1481 df_update_entry_exit_and_calls ();
1482 df->redo_entry_and_exit = false;
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. */
1491 static unsigned int
1492 df_count_refs (bool include_defs, bool include_uses,
1493 bool include_eq_uses)
1495 unsigned int regno;
1496 int size = 0;
1497 unsigned int m = df->regs_inited;
1499 for (regno = 0; regno < m; regno++)
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);
1508 return size;
1512 /* Take build ref table for either the uses or defs from the reg-use
1513 or reg-def chains. This version processes the refs in reg order
1514 which is likely to be best if processing the whole function. */
1516 static void
1517 df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info,
1518 bool include_defs,
1519 bool include_uses,
1520 bool include_eq_uses)
1522 unsigned int m = df->regs_inited;
1523 unsigned int regno;
1524 unsigned int offset = 0;
1525 unsigned int start;
1527 if (df->changeable_flags & DF_NO_HARD_REGS)
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);
1533 else
1534 start = 0;
1536 ref_info->total_size
1537 = df_count_refs (include_defs, include_uses, include_eq_uses);
1539 df_check_and_grow_ref_info (ref_info, 1);
1541 for (regno = start; regno < m; regno++)
1543 int count = 0;
1544 ref_info->begin[regno] = offset;
1545 if (include_defs)
1547 df_ref ref = DF_REG_DEF_CHAIN (regno);
1548 while (ref)
1550 ref_info->refs[offset] = ref;
1551 DF_REF_ID (ref) = offset++;
1552 count++;
1553 ref = DF_REF_NEXT_REG (ref);
1554 gcc_checking_assert (offset < ref_info->refs_size);
1557 if (include_uses)
1559 df_ref ref = DF_REG_USE_CHAIN (regno);
1560 while (ref)
1562 ref_info->refs[offset] = ref;
1563 DF_REF_ID (ref) = offset++;
1564 count++;
1565 ref = DF_REF_NEXT_REG (ref);
1566 gcc_checking_assert (offset < ref_info->refs_size);
1569 if (include_eq_uses)
1571 df_ref ref = DF_REG_EQ_USE_CHAIN (regno);
1572 while (ref)
1574 ref_info->refs[offset] = ref;
1575 DF_REF_ID (ref) = offset++;
1576 count++;
1577 ref = DF_REF_NEXT_REG (ref);
1578 gcc_checking_assert (offset < ref_info->refs_size);
1581 ref_info->count[regno] = count;
1584 /* The bitmap size is not decremented when refs are deleted. So
1585 reset it now that we have squished out all of the empty
1586 slots. */
1587 ref_info->table_size = offset;
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. */
1596 static void
1597 df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
1598 bool include_defs,
1599 bool include_uses,
1600 bool include_eq_uses)
1602 bitmap_iterator bi;
1603 unsigned int bb_index;
1604 unsigned int m = df->regs_inited;
1605 unsigned int offset = 0;
1606 unsigned int r;
1607 unsigned int start
1608 = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
1610 memset (ref_info->begin, 0, sizeof (int) * df->regs_inited);
1611 memset (ref_info->count, 0, sizeof (int) * df->regs_inited);
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);
1616 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1618 basic_block bb = BASIC_BLOCK (bb_index);
1619 rtx insn;
1620 df_ref *ref_rec;
1622 if (include_defs)
1623 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1625 unsigned int regno = DF_REF_REGNO (*ref_rec);
1626 ref_info->count[regno]++;
1628 if (include_uses)
1629 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1631 unsigned int regno = DF_REF_REGNO (*ref_rec);
1632 ref_info->count[regno]++;
1635 FOR_BB_INSNS (bb, insn)
1637 if (INSN_P (insn))
1639 unsigned int uid = INSN_UID (insn);
1641 if (include_defs)
1642 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1644 unsigned int regno = DF_REF_REGNO (*ref_rec);
1645 ref_info->count[regno]++;
1647 if (include_uses)
1648 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1650 unsigned int regno = DF_REF_REGNO (*ref_rec);
1651 ref_info->count[regno]++;
1653 if (include_eq_uses)
1654 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1656 unsigned int regno = DF_REF_REGNO (*ref_rec);
1657 ref_info->count[regno]++;
1663 for (r = start; r < m; r++)
1665 ref_info->begin[r] = offset;
1666 offset += ref_info->count[r];
1667 ref_info->count[r] = 0;
1670 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1672 basic_block bb = BASIC_BLOCK (bb_index);
1673 rtx insn;
1674 df_ref *ref_rec;
1676 if (include_defs)
1677 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1679 df_ref ref = *ref_rec;
1680 unsigned int regno = DF_REF_REGNO (ref);
1681 if (regno >= start)
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;
1689 if (include_uses)
1690 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1692 df_ref ref = *ref_rec;
1693 unsigned int regno = DF_REF_REGNO (ref);
1694 if (regno >= start)
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;
1703 FOR_BB_INSNS (bb, insn)
1705 if (INSN_P (insn))
1707 unsigned int uid = INSN_UID (insn);
1709 if (include_defs)
1710 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1712 df_ref ref = *ref_rec;
1713 unsigned int regno = DF_REF_REGNO (ref);
1714 if (regno >= start)
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;
1722 if (include_uses)
1723 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1725 df_ref ref = *ref_rec;
1726 unsigned int regno = DF_REF_REGNO (ref);
1727 if (regno >= start)
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;
1735 if (include_eq_uses)
1736 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1738 df_ref ref = *ref_rec;
1739 unsigned int regno = DF_REF_REGNO (ref);
1740 if (regno >= start)
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;
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. */
1756 ref_info->table_size = offset;
1759 /* Take build ref table for either the uses or defs from the reg-use
1760 or reg-def chains. */
1762 static void
1763 df_reorganize_refs_by_reg (struct df_ref_info *ref_info,
1764 bool include_defs,
1765 bool include_uses,
1766 bool include_eq_uses)
1768 if (df->analyze_subset)
1769 df_reorganize_refs_by_reg_by_insn (ref_info, include_defs,
1770 include_uses, include_eq_uses);
1771 else
1772 df_reorganize_refs_by_reg_by_reg (ref_info, include_defs,
1773 include_uses, include_eq_uses);
1777 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1778 static unsigned int
1779 df_add_refs_to_table (unsigned int offset,
1780 struct df_ref_info *ref_info,
1781 df_ref *ref_vec)
1783 while (*ref_vec)
1785 df_ref ref = *ref_vec;
1786 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
1787 || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER))
1789 ref_info->refs[offset] = ref;
1790 DF_REF_ID (*ref_vec) = offset++;
1792 ref_vec++;
1794 return offset;
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. */
1802 static unsigned int
1803 df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset,
1804 struct df_ref_info *ref_info,
1805 bool include_defs, bool include_uses,
1806 bool include_eq_uses)
1808 rtx insn;
1810 if (include_defs)
1811 offset = df_add_refs_to_table (offset, ref_info,
1812 df_get_artificial_defs (bb->index));
1813 if (include_uses)
1814 offset = df_add_refs_to_table (offset, ref_info,
1815 df_get_artificial_uses (bb->index));
1817 FOR_BB_INSNS (bb, insn)
1818 if (INSN_P (insn))
1820 unsigned int uid = INSN_UID (insn);
1821 if (include_defs)
1822 offset = df_add_refs_to_table (offset, ref_info,
1823 DF_INSN_UID_DEFS (uid));
1824 if (include_uses)
1825 offset = df_add_refs_to_table (offset, ref_info,
1826 DF_INSN_UID_USES (uid));
1827 if (include_eq_uses)
1828 offset = df_add_refs_to_table (offset, ref_info,
1829 DF_INSN_UID_EQ_USES (uid));
1831 return offset;
1835 /* Organize the refs by insn into the table in REF_INFO. If
1836 blocks_to_analyze is defined, use that set, otherwise the entire
1837 program. Include the defs if INCLUDE_DEFS. Include the uses if
1838 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1840 static void
1841 df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
1842 bool include_defs, bool include_uses,
1843 bool include_eq_uses)
1845 basic_block bb;
1846 unsigned int offset = 0;
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)
1852 bitmap_iterator bi;
1853 unsigned int index;
1855 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
1857 offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index), offset, ref_info,
1858 include_defs, include_uses,
1859 include_eq_uses);
1862 ref_info->table_size = offset;
1864 else
1866 FOR_ALL_BB (bb)
1867 offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info,
1868 include_defs, include_uses,
1869 include_eq_uses);
1870 ref_info->table_size = offset;
1875 /* If the use refs in DF are not organized, reorganize them. */
1877 void
1878 df_maybe_reorganize_use_refs (enum df_ref_order order)
1880 if (order == df->use_info.ref_order)
1881 return;
1883 switch (order)
1885 case DF_REF_ORDER_BY_REG:
1886 df_reorganize_refs_by_reg (&df->use_info, false, true, false);
1887 break;
1889 case DF_REF_ORDER_BY_REG_WITH_NOTES:
1890 df_reorganize_refs_by_reg (&df->use_info, false, true, true);
1891 break;
1893 case DF_REF_ORDER_BY_INSN:
1894 df_reorganize_refs_by_insn (&df->use_info, false, true, false);
1895 break;
1897 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1898 df_reorganize_refs_by_insn (&df->use_info, false, true, true);
1899 break;
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;
1907 case DF_REF_ORDER_UNORDERED:
1908 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1909 gcc_unreachable ();
1910 break;
1913 df->use_info.ref_order = order;
1917 /* If the def refs in DF are not organized, reorganize them. */
1919 void
1920 df_maybe_reorganize_def_refs (enum df_ref_order order)
1922 if (order == df->def_info.ref_order)
1923 return;
1925 switch (order)
1927 case DF_REF_ORDER_BY_REG:
1928 df_reorganize_refs_by_reg (&df->def_info, true, false, false);
1929 break;
1931 case DF_REF_ORDER_BY_INSN:
1932 df_reorganize_refs_by_insn (&df->def_info, true, false, false);
1933 break;
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;
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;
1949 df->def_info.ref_order = order;
1953 /* Change all of the basic block references in INSN to use the insn's
1954 current basic block. This function is called from routines that move
1955 instructions from one block to another. */
1957 void
1958 df_insn_change_bb (rtx insn, basic_block new_bb)
1960 basic_block old_bb = BLOCK_FOR_INSN (insn);
1961 struct df_insn_info *insn_info;
1962 unsigned int uid = INSN_UID (insn);
1964 if (old_bb == new_bb)
1965 return;
1967 set_block_for_insn (insn, new_bb);
1969 if (!df)
1970 return;
1972 if (dump_file)
1973 fprintf (dump_file, "changing bb of uid %d\n", uid);
1975 insn_info = DF_INSN_UID_SAFE_GET (uid);
1976 if (insn_info == NULL)
1978 if (dump_file)
1979 fprintf (dump_file, " unscanned insn\n");
1980 df_insn_rescan (insn);
1981 return;
1984 if (!INSN_P (insn))
1985 return;
1987 df_set_bb_dirty (new_bb);
1988 if (old_bb)
1990 if (dump_file)
1991 fprintf (dump_file, " from %d to %d\n",
1992 old_bb->index, new_bb->index);
1993 df_set_bb_dirty (old_bb);
1995 else
1996 if (dump_file)
1997 fprintf (dump_file, " to %d\n", new_bb->index);
2001 /* Helper function for df_ref_change_reg_with_loc. */
2003 static void
2004 df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df,
2005 struct df_reg_info *new_df,
2006 int new_regno, rtx loc)
2008 df_ref the_ref = old_df->reg_chain;
2010 while (the_ref)
2012 if ((!DF_REF_IS_ARTIFICIAL (the_ref))
2013 && DF_REF_LOC (the_ref)
2014 && (*DF_REF_LOC (the_ref) == loc))
2016 df_ref next_ref = DF_REF_NEXT_REG (the_ref);
2017 df_ref prev_ref = DF_REF_PREV_REG (the_ref);
2018 df_ref *ref_vec, *ref_vec_t;
2019 struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref);
2020 unsigned int count = 0;
2022 DF_REF_REGNO (the_ref) = new_regno;
2023 DF_REF_REG (the_ref) = regno_reg_rtx[new_regno];
2025 /* Pull the_ref out of the old regno chain. */
2026 if (prev_ref)
2027 DF_REF_NEXT_REG (prev_ref) = next_ref;
2028 else
2029 old_df->reg_chain = next_ref;
2030 if (next_ref)
2031 DF_REF_PREV_REG (next_ref) = prev_ref;
2032 old_df->n_refs--;
2034 /* Put the ref into the new regno chain. */
2035 DF_REF_PREV_REG (the_ref) = NULL;
2036 DF_REF_NEXT_REG (the_ref) = new_df->reg_chain;
2037 if (new_df->reg_chain)
2038 DF_REF_PREV_REG (new_df->reg_chain) = the_ref;
2039 new_df->reg_chain = the_ref;
2040 new_df->n_refs++;
2041 if (DF_REF_BB (the_ref))
2042 df_set_bb_dirty (DF_REF_BB (the_ref));
2044 /* Need to sort the record again that the ref was in because
2045 the regno is a sorting key. First, find the right
2046 record. */
2047 if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE)
2048 ref_vec = insn_info->eq_uses;
2049 else
2050 ref_vec = insn_info->uses;
2051 if (dump_file)
2052 fprintf (dump_file, "changing reg in insn %d\n",
2053 DF_REF_INSN_UID (the_ref));
2055 ref_vec_t = ref_vec;
2057 /* Find the length. */
2058 while (*ref_vec_t)
2060 count++;
2061 ref_vec_t++;
2063 qsort (ref_vec, count, sizeof (df_ref ), df_ref_compare);
2065 the_ref = next_ref;
2067 else
2068 the_ref = DF_REF_NEXT_REG (the_ref);
2073 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2074 NEW_REGNO. Refs that do not match LOC are not changed which means
2075 that artificial refs are not changed since they have no loc. This
2076 call is to support the SET_REGNO macro. */
2078 void
2079 df_ref_change_reg_with_loc (int old_regno, int new_regno, rtx loc)
2081 if ((!df) || (old_regno == -1) || (old_regno == new_regno))
2082 return;
2084 df_grow_reg_info ();
2086 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno),
2087 DF_REG_DEF_GET (new_regno), new_regno, loc);
2088 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno),
2089 DF_REG_USE_GET (new_regno), new_regno, loc);
2090 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno),
2091 DF_REG_EQ_USE_GET (new_regno), new_regno, loc);
2095 /* Delete the mw_hardregs that point into the eq_notes. */
2097 static unsigned int
2098 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info)
2100 struct df_mw_hardreg **mw_vec = insn_info->mw_hardregs;
2101 unsigned int deleted = 0;
2102 unsigned int count = 0;
2103 struct df_scan_problem_data *problem_data
2104 = (struct df_scan_problem_data *) df_scan->problem_data;
2106 if (!*mw_vec)
2107 return 0;
2109 while (*mw_vec)
2111 if ((*mw_vec)->flags & DF_REF_IN_NOTE)
2113 struct df_mw_hardreg **temp_vec = mw_vec;
2115 pool_free (problem_data->mw_reg_pool, *mw_vec);
2116 temp_vec = mw_vec;
2117 /* Shove the remaining ones down one to fill the gap. While
2118 this looks n**2, it is highly unusual to have any mw regs
2119 in eq_notes and the chances of more than one are almost
2120 non existent. */
2121 while (*temp_vec)
2123 *temp_vec = *(temp_vec + 1);
2124 temp_vec++;
2126 deleted++;
2128 else
2130 mw_vec++;
2131 count++;
2135 if (count == 0)
2137 df_scan_free_mws_vec (insn_info->mw_hardregs);
2138 insn_info->mw_hardregs = df_null_mw_rec;
2139 return 0;
2141 return deleted;
2145 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2147 void
2148 df_notes_rescan (rtx insn)
2150 struct df_insn_info *insn_info;
2151 unsigned int uid = INSN_UID (insn);
2153 if (!df)
2154 return;
2156 /* The client has disabled rescanning and plans to do it itself. */
2157 if (df->changeable_flags & DF_NO_INSN_RESCAN)
2158 return;
2160 /* Do nothing if the insn hasn't been emitted yet. */
2161 if (!BLOCK_FOR_INSN (insn))
2162 return;
2164 df_grow_bb_info (df_scan);
2165 df_grow_reg_info ();
2167 insn_info = DF_INSN_UID_SAFE_GET (INSN_UID(insn));
2169 /* The client has deferred rescanning. */
2170 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
2172 if (!insn_info)
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;
2181 bitmap_clear_bit (&df->insns_to_delete, uid);
2182 /* If the insn is set to be rescanned, it does not need to also
2183 be notes rescanned. */
2184 if (!bitmap_bit_p (&df->insns_to_rescan, uid))
2185 bitmap_set_bit (&df->insns_to_notes_rescan, INSN_UID (insn));
2186 return;
2189 bitmap_clear_bit (&df->insns_to_delete, uid);
2190 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
2192 if (insn_info)
2194 basic_block bb = BLOCK_FOR_INSN (insn);
2195 rtx note;
2196 struct df_collection_rec collection_rec;
2197 unsigned int num_deleted;
2198 unsigned int mw_len;
2200 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
2201 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
2202 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
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;
2208 /* Process REG_EQUIV/REG_EQUAL notes */
2209 for (note = REG_NOTES (insn); note;
2210 note = XEXP (note, 1))
2212 switch (REG_NOTE_KIND (note))
2214 case REG_EQUIV:
2215 case REG_EQUAL:
2216 df_uses_record (&collection_rec,
2217 &XEXP (note, 0), DF_REF_REG_USE,
2218 bb, insn_info, DF_REF_IN_NOTE);
2219 default:
2220 break;
2224 /* Find some place to put any new mw_hardregs. */
2225 df_canonize_collection_rec (&collection_rec);
2226 mw_len = VEC_length (df_mw_hardreg_ptr, collection_rec.mw_vec);
2227 if (mw_len)
2229 unsigned int count = 0;
2230 struct df_mw_hardreg **mw_rec = insn_info->mw_hardregs;
2231 while (*mw_rec)
2233 count++;
2234 mw_rec++;
2237 if (count)
2239 /* Append to the end of the existing record after
2240 expanding it if necessary. */
2241 if (mw_len > num_deleted)
2243 insn_info->mw_hardregs =
2244 XRESIZEVEC (struct df_mw_hardreg *,
2245 insn_info->mw_hardregs,
2246 count + 1 + mw_len);
2248 memcpy (&insn_info->mw_hardregs[count],
2249 VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2250 mw_len * sizeof (struct df_mw_hardreg *));
2251 insn_info->mw_hardregs[count + mw_len] = NULL;
2252 qsort (insn_info->mw_hardregs, count + mw_len,
2253 sizeof (struct df_mw_hardreg *), df_mw_compare);
2255 else
2257 /* No vector there. */
2258 insn_info->mw_hardregs
2259 = XNEWVEC (struct df_mw_hardreg*, 1 + mw_len);
2260 memcpy (insn_info->mw_hardregs,
2261 VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2262 mw_len * sizeof (struct df_mw_hardreg *));
2263 insn_info->mw_hardregs[mw_len] = NULL;
2266 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2267 ignore it. */
2268 VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
2269 df_refs_add_to_chains (&collection_rec, bb, insn);
2270 VEC_free (df_ref, stack, collection_rec.eq_use_vec);
2272 else
2273 df_insn_rescan (insn);
2278 /*----------------------------------------------------------------------------
2279 Hard core instruction scanning code. No external interfaces here,
2280 just a lot of routines that look inside insns.
2281 ----------------------------------------------------------------------------*/
2284 /* Return true if the contents of two df_ref's are identical.
2285 It ignores DF_REF_MARKER. */
2287 static bool
2288 df_ref_equal_p (df_ref ref1, df_ref ref2)
2290 if (!ref2)
2291 return false;
2293 if (ref1 == ref2)
2294 return true;
2296 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)
2297 || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)
2298 || DF_REF_REG (ref1) != DF_REF_REG (ref2)
2299 || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)
2300 || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))
2301 != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)))
2302 || DF_REF_BB (ref1) != DF_REF_BB (ref2)
2303 || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2))
2304 return false;
2306 switch (DF_REF_CLASS (ref1))
2308 case DF_REF_ARTIFICIAL:
2309 case DF_REF_BASE:
2310 return true;
2312 case DF_REF_REGULAR:
2313 return DF_REF_LOC (ref1) == DF_REF_LOC (ref2);
2315 default:
2316 gcc_unreachable ();
2318 return false;
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. */
2326 static int
2327 df_ref_compare (const void *r1, const void *r2)
2329 const df_ref ref1 = *(const df_ref *)r1;
2330 const df_ref ref2 = *(const df_ref *)r2;
2332 if (ref1 == ref2)
2333 return 0;
2335 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
2336 return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
2338 if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
2339 return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
2341 if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
2342 return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
2344 if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
2345 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2347 /* Cannot look at the LOC field on artificial refs. */
2348 if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
2349 && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
2350 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2352 if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
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;
2366 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2369 static void
2370 df_swap_refs (VEC(df_ref,stack) **ref_vec, int i, int j)
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);
2377 /* Sort and compress a set of refs. */
2379 static void
2380 df_sort_and_compress_refs (VEC(df_ref,stack) **ref_vec)
2382 unsigned int count;
2383 unsigned int i;
2384 unsigned int dist = 0;
2386 count = VEC_length (df_ref, *ref_vec);
2388 /* If there are 1 or 0 elements, there is nothing to do. */
2389 if (count < 2)
2390 return;
2391 else if (count == 2)
2393 df_ref r0 = VEC_index (df_ref, *ref_vec, 0);
2394 df_ref r1 = VEC_index (df_ref, *ref_vec, 1);
2395 if (df_ref_compare (&r0, &r1) > 0)
2396 df_swap_refs (ref_vec, 0, 1);
2398 else
2400 for (i = 0; i < count - 1; i++)
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;
2407 /* If the array is already strictly ordered,
2408 which is the most common case for large COUNT case
2409 (which happens for CALL INSNs),
2410 no need to sort and filter out duplicate.
2411 Simply return the count.
2412 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2413 of DF_REF_COMPARE. */
2414 if (i == count - 1)
2415 return;
2416 VEC_qsort (df_ref, *ref_vec, df_ref_compare);
2419 for (i=0; i<count-dist; i++)
2421 /* Find the next ref that is not equal to the current ref. */
2422 while (i + dist + 1 < count
2423 && df_ref_equal_p (VEC_index (df_ref, *ref_vec, i),
2424 VEC_index (df_ref, *ref_vec, i + dist + 1)))
2426 df_free_ref (VEC_index (df_ref, *ref_vec, i + dist + 1));
2427 dist++;
2429 /* Copy it down to the next position. */
2430 if (dist && i + dist + 1 < count)
2431 VEC_replace (df_ref, *ref_vec, i + 1,
2432 VEC_index (df_ref, *ref_vec, i + dist + 1));
2435 count -= dist;
2436 VEC_truncate (df_ref, *ref_vec, count);
2440 /* Return true if the contents of two df_ref's are identical.
2441 It ignores DF_REF_MARKER. */
2443 static bool
2444 df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2)
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);
2457 /* Compare MW1 and MW2 for sorting. */
2459 static int
2460 df_mw_compare (const void *m1, const void *m2)
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;
2465 if (mw1 == mw2)
2466 return 0;
2468 if (mw1->type != mw2->type)
2469 return mw1->type - mw2->type;
2471 if (mw1->flags != mw2->flags)
2472 return mw1->flags - mw2->flags;
2474 if (mw1->start_regno != mw2->start_regno)
2475 return mw1->start_regno - mw2->start_regno;
2477 if (mw1->end_regno != mw2->end_regno)
2478 return mw1->end_regno - mw2->end_regno;
2480 if (mw1->mw_reg != mw2->mw_reg)
2481 return mw1->mw_order - mw2->mw_order;
2483 return 0;
2487 /* Sort and compress a set of refs. */
2489 static void
2490 df_sort_and_compress_mws (VEC(df_mw_hardreg_ptr,stack) **mw_vec)
2492 unsigned int count;
2493 struct df_scan_problem_data *problem_data
2494 = (struct df_scan_problem_data *) df_scan->problem_data;
2495 unsigned int i;
2496 unsigned int dist = 0;
2498 count = VEC_length (df_mw_hardreg_ptr, *mw_vec);
2499 if (count < 2)
2500 return;
2501 else if (count == 2)
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)
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);
2514 else
2515 VEC_qsort (df_mw_hardreg_ptr, *mw_vec, df_mw_compare);
2517 for (i=0; i<count-dist; i++)
2519 /* Find the next ref that is not equal to the current ref. */
2520 while (i + dist + 1 < count
2521 && df_mw_equal_p (VEC_index (df_mw_hardreg_ptr, *mw_vec, i),
2522 VEC_index (df_mw_hardreg_ptr, *mw_vec,
2523 i + dist + 1)))
2525 pool_free (problem_data->mw_reg_pool,
2526 VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2527 dist++;
2529 /* Copy it down to the next position. */
2530 if (dist && i + dist + 1 < count)
2531 VEC_replace (df_mw_hardreg_ptr, *mw_vec, i + 1,
2532 VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2535 count -= dist;
2536 VEC_truncate (df_mw_hardreg_ptr, *mw_vec, count);
2540 /* Sort and remove duplicates from the COLLECTION_REC. */
2542 static void
2543 df_canonize_collection_rec (struct df_collection_rec *collection_rec)
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);
2552 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2554 static void
2555 df_install_ref (df_ref this_ref,
2556 struct df_reg_info *reg_info,
2557 struct df_ref_info *ref_info,
2558 bool add_to_table)
2560 unsigned int regno = DF_REF_REGNO (this_ref);
2561 /* Add the ref to the reg_{def,use,eq_use} chain. */
2562 df_ref head = reg_info->reg_chain;
2564 reg_info->reg_chain = this_ref;
2565 reg_info->n_refs++;
2567 if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE))
2569 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
2570 df->hard_regs_live_count[regno]++;
2573 gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL
2574 && DF_REF_PREV_REG (this_ref) == NULL);
2576 DF_REF_NEXT_REG (this_ref) = head;
2578 /* We cannot actually link to the head of the chain. */
2579 DF_REF_PREV_REG (this_ref) = NULL;
2581 if (head)
2582 DF_REF_PREV_REG (head) = this_ref;
2584 if (add_to_table)
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++;
2593 else
2594 DF_REF_ID (this_ref) = -1;
2596 ref_info->total_size++;
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. */
2604 static df_ref *
2605 df_install_refs (basic_block bb,
2606 VEC(df_ref,stack)* old_vec,
2607 struct df_reg_info **reg_info,
2608 struct df_ref_info *ref_info,
2609 bool is_notes)
2611 unsigned int count;
2613 count = VEC_length (df_ref, old_vec);
2614 if (count)
2616 df_ref *new_vec = XNEWVEC (df_ref, count + 1);
2617 bool add_to_table;
2618 df_ref this_ref;
2619 unsigned int ix;
2621 switch (ref_info->ref_order)
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;
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);
2644 FOR_EACH_VEC_ELT (df_ref, old_vec, ix, this_ref)
2646 new_vec[ix] = this_ref;
2647 df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)],
2648 ref_info, add_to_table);
2651 new_vec[count] = NULL;
2652 return new_vec;
2654 else
2655 return df_null_ref_rec;
2659 /* This function takes the mws installs the entire group into the
2660 insn. */
2662 static struct df_mw_hardreg **
2663 df_install_mws (VEC(df_mw_hardreg_ptr,stack) *old_vec)
2665 unsigned int count;
2667 count = VEC_length (df_mw_hardreg_ptr, old_vec);
2668 if (count)
2670 struct df_mw_hardreg **new_vec
2671 = XNEWVEC (struct df_mw_hardreg*, count + 1);
2672 memcpy (new_vec, VEC_address (df_mw_hardreg_ptr, old_vec),
2673 sizeof (struct df_mw_hardreg*) * count);
2674 new_vec[count] = NULL;
2675 return new_vec;
2677 else
2678 return df_null_mw_rec;
2682 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2683 chains and update other necessary information. */
2685 static void
2686 df_refs_add_to_chains (struct df_collection_rec *collection_rec,
2687 basic_block bb, rtx insn)
2689 if (insn)
2691 struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn);
2692 /* If there is a vector in the collection rec, add it to the
2693 insn. A null rec is a signal that the caller will handle the
2694 chain specially. */
2695 if (collection_rec->def_vec)
2697 df_scan_free_ref_vec (insn_rec->defs);
2698 insn_rec->defs
2699 = df_install_refs (bb, collection_rec->def_vec,
2700 df->def_regs,
2701 &df->def_info, false);
2703 if (collection_rec->use_vec)
2705 df_scan_free_ref_vec (insn_rec->uses);
2706 insn_rec->uses
2707 = df_install_refs (bb, collection_rec->use_vec,
2708 df->use_regs,
2709 &df->use_info, false);
2711 if (collection_rec->eq_use_vec)
2713 df_scan_free_ref_vec (insn_rec->eq_uses);
2714 insn_rec->eq_uses
2715 = df_install_refs (bb, collection_rec->eq_use_vec,
2716 df->eq_use_regs,
2717 &df->use_info, true);
2719 if (collection_rec->mw_vec)
2721 df_scan_free_mws_vec (insn_rec->mw_hardregs);
2722 insn_rec->mw_hardregs
2723 = df_install_mws (collection_rec->mw_vec);
2726 else
2728 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
2730 df_scan_free_ref_vec (bb_info->artificial_defs);
2731 bb_info->artificial_defs
2732 = df_install_refs (bb, collection_rec->def_vec,
2733 df->def_regs,
2734 &df->def_info, false);
2735 df_scan_free_ref_vec (bb_info->artificial_uses);
2736 bb_info->artificial_uses
2737 = df_install_refs (bb, collection_rec->use_vec,
2738 df->use_regs,
2739 &df->use_info, false);
2744 /* Allocate a ref and initialize its fields. */
2746 static df_ref
2747 df_ref_create_structure (enum df_ref_class cl,
2748 struct df_collection_rec *collection_rec,
2749 rtx reg, rtx *loc,
2750 basic_block bb, struct df_insn_info *info,
2751 enum df_ref_type ref_type,
2752 int ref_flags)
2754 df_ref this_ref = NULL;
2755 int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2756 struct df_scan_problem_data *problem_data
2757 = (struct df_scan_problem_data *) df_scan->problem_data;
2759 switch (cl)
2761 case DF_REF_BASE:
2762 this_ref = (df_ref) pool_alloc (problem_data->ref_base_pool);
2763 gcc_checking_assert (loc == NULL);
2764 break;
2766 case DF_REF_ARTIFICIAL:
2767 this_ref = (df_ref) pool_alloc (problem_data->ref_artificial_pool);
2768 this_ref->artificial_ref.bb = bb;
2769 gcc_checking_assert (loc == NULL);
2770 break;
2772 case DF_REF_REGULAR:
2773 this_ref = (df_ref) pool_alloc (problem_data->ref_regular_pool);
2774 this_ref->regular_ref.loc = loc;
2775 gcc_checking_assert (loc);
2776 break;
2779 DF_REF_CLASS (this_ref) = cl;
2780 DF_REF_ID (this_ref) = -1;
2781 DF_REF_REG (this_ref) = reg;
2782 DF_REF_REGNO (this_ref) = regno;
2783 DF_REF_TYPE (this_ref) = ref_type;
2784 DF_REF_INSN_INFO (this_ref) = info;
2785 DF_REF_CHAIN (this_ref) = NULL;
2786 DF_REF_FLAGS (this_ref) = ref_flags;
2787 DF_REF_NEXT_REG (this_ref) = NULL;
2788 DF_REF_PREV_REG (this_ref) = NULL;
2789 DF_REF_ORDER (this_ref) = df->ref_order++;
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);
2796 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2797 if ((regno < FIRST_PSEUDO_REGISTER)
2798 && (!DF_REF_IS_ARTIFICIAL (this_ref)))
2800 if (DF_REF_REG_DEF_P (this_ref))
2802 if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER))
2803 DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
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);
2811 if (collection_rec)
2813 if (DF_REF_REG_DEF_P (this_ref))
2814 VEC_safe_push (df_ref, stack, collection_rec->def_vec, this_ref);
2815 else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE)
2816 VEC_safe_push (df_ref, stack, collection_rec->eq_use_vec, this_ref);
2817 else
2818 VEC_safe_push (df_ref, stack, collection_rec->use_vec, this_ref);
2820 else
2821 df_install_ref_incremental (this_ref);
2823 return this_ref;
2827 /* Create new references of type DF_REF_TYPE for each part of register REG
2828 at address LOC within INSN of BB. */
2831 static void
2832 df_ref_record (enum df_ref_class cl,
2833 struct df_collection_rec *collection_rec,
2834 rtx reg, rtx *loc,
2835 basic_block bb, struct df_insn_info *insn_info,
2836 enum df_ref_type ref_type,
2837 int ref_flags)
2839 unsigned int regno;
2841 gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
2843 regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2844 if (regno < FIRST_PSEUDO_REGISTER)
2846 struct df_mw_hardreg *hardreg = NULL;
2847 struct df_scan_problem_data *problem_data
2848 = (struct df_scan_problem_data *) df_scan->problem_data;
2849 unsigned int i;
2850 unsigned int endregno;
2851 df_ref ref;
2853 if (GET_CODE (reg) == SUBREG)
2855 regno += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
2856 SUBREG_BYTE (reg), GET_MODE (reg));
2857 endregno = regno + subreg_nregs (reg);
2859 else
2860 endregno = END_HARD_REGNO (reg);
2862 /* If this is a multiword hardreg, we create some extra
2863 datastructures that will enable us to easily build REG_DEAD
2864 and REG_UNUSED notes. */
2865 if (collection_rec
2866 && (endregno != regno + 1) && insn_info)
2868 /* Sets to a subreg of a multiword register are partial.
2869 Sets to a non-subreg of a multiword register are not. */
2870 if (GET_CODE (reg) == SUBREG)
2871 ref_flags |= DF_REF_PARTIAL;
2872 ref_flags |= DF_REF_MW_HARDREG;
2874 hardreg = (struct df_mw_hardreg *) pool_alloc (problem_data->mw_reg_pool);
2875 hardreg->type = ref_type;
2876 hardreg->flags = ref_flags;
2877 hardreg->mw_reg = reg;
2878 hardreg->start_regno = regno;
2879 hardreg->end_regno = endregno - 1;
2880 hardreg->mw_order = df->ref_order++;
2881 VEC_safe_push (df_mw_hardreg_ptr, stack, collection_rec->mw_vec,
2882 hardreg);
2885 for (i = regno; i < endregno; i++)
2887 ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc,
2888 bb, insn_info, ref_type, ref_flags);
2890 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i);
2893 else
2895 df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info,
2896 ref_type, ref_flags);
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. */
2906 bool
2907 df_read_modify_subreg_p (rtx x)
2909 unsigned int isize, osize;
2910 if (GET_CODE (x) != SUBREG)
2911 return false;
2912 isize = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
2913 osize = GET_MODE_SIZE (GET_MODE (x));
2914 return isize > osize
2915 && isize > REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x)));
2919 /* Process all the registers defined in the rtx, X.
2920 Autoincrement/decrement definitions will be picked up by
2921 df_uses_record. */
2923 static void
2924 df_def_record_1 (struct df_collection_rec *collection_rec,
2925 rtx x, basic_block bb, struct df_insn_info *insn_info,
2926 int flags)
2928 rtx *loc;
2929 rtx dst;
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;
2939 /* It is legal to have a set destination be a parallel. */
2940 if (GET_CODE (dst) == PARALLEL)
2942 int i;
2944 for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
2946 rtx temp = XVECEXP (dst, 0, i);
2947 if (GET_CODE (temp) == EXPR_LIST || GET_CODE (temp) == CLOBBER
2948 || GET_CODE (temp) == SET)
2949 df_def_record_1 (collection_rec,
2950 temp, bb, insn_info,
2951 GET_CODE (temp) == CLOBBER
2952 ? flags | DF_REF_MUST_CLOBBER : flags);
2954 return;
2957 if (GET_CODE (dst) == STRICT_LOW_PART)
2959 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;
2961 loc = &XEXP (dst, 0);
2962 dst = *loc;
2965 if (GET_CODE (dst) == ZERO_EXTRACT)
2967 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;
2969 loc = &XEXP (dst, 0);
2970 dst = *loc;
2973 /* At this point if we do not have a reg or a subreg, just return. */
2974 if (REG_P (dst))
2976 df_ref_record (DF_REF_REGULAR, collection_rec,
2977 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
2979 /* We want to keep sp alive everywhere - by making all
2980 writes to sp also use of sp. */
2981 if (REGNO (dst) == STACK_POINTER_REGNUM)
2982 df_ref_record (DF_REF_BASE, collection_rec,
2983 dst, NULL, bb, insn_info, DF_REF_REG_USE, flags);
2985 else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
2987 if (df_read_modify_subreg_p (dst))
2988 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;
2990 flags |= DF_REF_SUBREG;
2992 df_ref_record (DF_REF_REGULAR, collection_rec,
2993 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
2998 /* Process all the registers defined in the pattern rtx, X. */
3000 static void
3001 df_defs_record (struct df_collection_rec *collection_rec,
3002 rtx x, basic_block bb, struct df_insn_info *insn_info,
3003 int flags)
3005 RTX_CODE code = GET_CODE (x);
3007 if (code == SET || code == CLOBBER)
3009 /* Mark the single def within the pattern. */
3010 int clobber_flags = flags;
3011 clobber_flags |= (code == CLOBBER) ? DF_REF_MUST_CLOBBER : 0;
3012 df_def_record_1 (collection_rec, x, bb, insn_info, clobber_flags);
3014 else if (code == COND_EXEC)
3016 df_defs_record (collection_rec, COND_EXEC_CODE (x),
3017 bb, insn_info, DF_REF_CONDITIONAL);
3019 else if (code == PARALLEL)
3021 int i;
3023 /* Mark the multiple defs within the pattern. */
3024 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
3025 df_defs_record (collection_rec, XVECEXP (x, 0, i), bb, insn_info, flags);
3030 /* Process all the registers used in the rtx at address LOC. */
3032 static void
3033 df_uses_record (struct df_collection_rec *collection_rec,
3034 rtx *loc, enum df_ref_type ref_type,
3035 basic_block bb, struct df_insn_info *insn_info,
3036 int flags)
3038 RTX_CODE code;
3039 rtx x;
3041 retry:
3042 x = *loc;
3043 if (!x)
3044 return;
3045 code = GET_CODE (x);
3046 switch (code)
3048 case LABEL_REF:
3049 case SYMBOL_REF:
3050 case CONST_INT:
3051 case CONST:
3052 case CONST_DOUBLE:
3053 case CONST_FIXED:
3054 case CONST_VECTOR:
3055 case PC:
3056 case CC0:
3057 case ADDR_VEC:
3058 case ADDR_DIFF_VEC:
3059 return;
3061 case CLOBBER:
3062 /* If we are clobbering a MEM, mark any registers inside the address
3063 as being used. */
3064 if (MEM_P (XEXP (x, 0)))
3065 df_uses_record (collection_rec,
3066 &XEXP (XEXP (x, 0), 0),
3067 DF_REF_REG_MEM_STORE,
3068 bb, insn_info,
3069 flags);
3071 /* If we're clobbering a REG then we have a def so ignore. */
3072 return;
3074 case MEM:
3075 df_uses_record (collection_rec,
3076 &XEXP (x, 0), DF_REF_REG_MEM_LOAD,
3077 bb, insn_info, flags & DF_REF_IN_NOTE);
3078 return;
3080 case SUBREG:
3081 /* While we're here, optimize this case. */
3082 flags |= DF_REF_PARTIAL;
3083 /* In case the SUBREG is not of a REG, do not optimize. */
3084 if (!REG_P (SUBREG_REG (x)))
3086 loc = &SUBREG_REG (x);
3087 df_uses_record (collection_rec, loc, ref_type, bb, insn_info, flags);
3088 return;
3090 /* ... Fall through ... */
3092 case REG:
3093 df_ref_record (DF_REF_REGULAR, collection_rec,
3094 x, loc, bb, insn_info,
3095 ref_type, flags);
3096 return;
3098 case SIGN_EXTRACT:
3099 case ZERO_EXTRACT:
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);
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;
3114 df_uses_record (collection_rec,
3115 &XEXP (x, 0), ref_type, bb, insn_info, flags);
3116 return;
3118 break;
3120 case SET:
3122 rtx dst = SET_DEST (x);
3123 gcc_assert (!(flags & DF_REF_IN_NOTE));
3124 df_uses_record (collection_rec,
3125 &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags);
3127 switch (GET_CODE (dst))
3129 case SUBREG:
3130 if (df_read_modify_subreg_p (dst))
3132 df_uses_record (collection_rec, &SUBREG_REG (dst),
3133 DF_REF_REG_USE, bb, insn_info,
3134 flags | DF_REF_READ_WRITE | DF_REF_SUBREG);
3135 break;
3137 /* Fall through. */
3138 case REG:
3139 case PARALLEL:
3140 case SCRATCH:
3141 case PC:
3142 case CC0:
3143 break;
3144 case MEM:
3145 df_uses_record (collection_rec, &XEXP (dst, 0),
3146 DF_REF_REG_MEM_STORE, bb, insn_info, flags);
3147 break;
3148 case STRICT_LOW_PART:
3150 rtx *temp = &XEXP (dst, 0);
3151 /* A strict_low_part uses the whole REG and not just the
3152 SUBREG. */
3153 dst = XEXP (dst, 0);
3154 df_uses_record (collection_rec,
3155 (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
3156 DF_REF_REG_USE, bb, insn_info,
3157 DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART);
3159 break;
3160 case ZERO_EXTRACT:
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);
3175 break;
3177 default:
3178 gcc_unreachable ();
3180 return;
3183 case RETURN:
3184 case SIMPLE_RETURN:
3185 break;
3187 case ASM_OPERANDS:
3188 case UNSPEC_VOLATILE:
3189 case TRAP_IF:
3190 case ASM_INPUT:
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.
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.
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."
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
3210 can find in ASM_OPERANDS as used. In global asm insns are
3211 scanned and regs_asm_clobbered is filled out.
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)
3220 int j;
3222 for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
3223 df_uses_record (collection_rec, &ASM_OPERANDS_INPUT (x, j),
3224 DF_REF_REG_USE, bb, insn_info, flags);
3225 return;
3227 break;
3230 case VAR_LOCATION:
3231 df_uses_record (collection_rec,
3232 &PAT_VAR_LOCATION_LOC (x),
3233 DF_REF_REG_USE, bb, insn_info, flags);
3234 return;
3236 case PRE_DEC:
3237 case POST_DEC:
3238 case PRE_INC:
3239 case POST_INC:
3240 case PRE_MODIFY:
3241 case POST_MODIFY:
3242 gcc_assert (!DEBUG_INSN_P (insn_info->insn));
3243 /* Catch the def of the register being modified. */
3244 df_ref_record (DF_REF_REGULAR, collection_rec, XEXP (x, 0), &XEXP (x, 0),
3245 bb, insn_info,
3246 DF_REF_REG_DEF,
3247 flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY);
3249 /* ... Fall through to handle uses ... */
3251 default:
3252 break;
3255 /* Recursively scan the operands of this expression. */
3257 const char *fmt = GET_RTX_FORMAT (code);
3258 int i;
3260 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3262 if (fmt[i] == 'e')
3264 /* Tail recursive case: save a function call level. */
3265 if (i == 0)
3267 loc = &XEXP (x, 0);
3268 goto retry;
3270 df_uses_record (collection_rec, &XEXP (x, i), ref_type,
3271 bb, insn_info, flags);
3273 else if (fmt[i] == 'E')
3275 int j;
3276 for (j = 0; j < XVECLEN (x, i); j++)
3277 df_uses_record (collection_rec,
3278 &XVECEXP (x, i, j), ref_type,
3279 bb, insn_info, flags);
3284 return;
3288 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3290 static void
3291 df_get_conditional_uses (struct df_collection_rec *collection_rec)
3293 unsigned int ix;
3294 df_ref ref;
3296 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
3298 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL))
3300 df_ref use;
3302 use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref),
3303 DF_REF_LOC (ref), DF_REF_BB (ref),
3304 DF_REF_INSN_INFO (ref), DF_REF_REG_USE,
3305 DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL);
3306 DF_REF_REGNO (use) = DF_REF_REGNO (ref);
3312 /* Get call's extra defs and uses. */
3314 static void
3315 df_get_call_refs (struct df_collection_rec * collection_rec,
3316 basic_block bb,
3317 struct df_insn_info *insn_info,
3318 int flags)
3320 rtx note;
3321 bitmap_iterator bi;
3322 unsigned int ui;
3323 bool is_sibling_call;
3324 unsigned int i;
3325 df_ref def;
3326 bitmap_head defs_generated;
3328 bitmap_initialize (&defs_generated, &df_bitmap_obstack);
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. */
3333 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, i, def)
3334 bitmap_set_bit (&defs_generated, DF_REF_REGNO (def));
3336 /* Record the registers used to pass arguments, and explicitly
3337 noted as clobbered. */
3338 for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note;
3339 note = XEXP (note, 1))
3341 if (GET_CODE (XEXP (note, 0)) == USE)
3342 df_uses_record (collection_rec, &XEXP (XEXP (note, 0), 0),
3343 DF_REF_REG_USE, bb, insn_info, flags);
3344 else if (GET_CODE (XEXP (note, 0)) == CLOBBER)
3346 if (REG_P (XEXP (XEXP (note, 0), 0)))
3348 unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
3349 if (!bitmap_bit_p (&defs_generated, regno))
3350 df_defs_record (collection_rec, XEXP (note, 0), bb,
3351 insn_info, flags);
3353 else
3354 df_uses_record (collection_rec, &XEXP (note, 0),
3355 DF_REF_REG_USE, bb, insn_info, flags);
3359 /* The stack ptr is used (honorarily) by a CALL insn. */
3360 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[STACK_POINTER_REGNUM],
3361 NULL, bb, insn_info, DF_REF_REG_USE,
3362 DF_REF_CALL_STACK_USAGE | flags);
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])
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);
3378 is_sibling_call = SIBLING_CALL_P (insn_info->insn);
3379 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, ui, bi)
3381 if (!global_regs[ui]
3382 && (!bitmap_bit_p (&defs_generated, ui))
3383 && (!is_sibling_call
3384 || !bitmap_bit_p (df->exit_block_uses, ui)
3385 || refers_to_regno_p (ui, ui+1,
3386 crtl->return_rtx, NULL)))
3387 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[ui],
3388 NULL, bb, insn_info, DF_REF_REG_DEF,
3389 DF_REF_MAY_CLOBBER | flags);
3392 bitmap_clear (&defs_generated);
3393 return;
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. */
3401 static void
3402 df_insn_refs_collect (struct df_collection_rec* collection_rec,
3403 basic_block bb, struct df_insn_info *insn_info)
3405 rtx note;
3406 bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC);
3408 /* Clear out the collection record. */
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);
3414 /* Record register defs. */
3415 df_defs_record (collection_rec, PATTERN (insn_info->insn), bb, insn_info, 0);
3417 /* Process REG_EQUIV/REG_EQUAL notes. */
3418 for (note = REG_NOTES (insn_info->insn); note;
3419 note = XEXP (note, 1))
3421 switch (REG_NOTE_KIND (note))
3423 case REG_EQUIV:
3424 case REG_EQUAL:
3425 df_uses_record (collection_rec,
3426 &XEXP (note, 0), DF_REF_REG_USE,
3427 bb, insn_info, DF_REF_IN_NOTE);
3428 break;
3429 case REG_NON_LOCAL_GOTO:
3430 /* The frame ptr is used by a non-local goto. */
3431 df_ref_record (DF_REF_BASE, collection_rec,
3432 regno_reg_rtx[FRAME_POINTER_REGNUM],
3433 NULL, bb, insn_info,
3434 DF_REF_REG_USE, 0);
3435 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3436 df_ref_record (DF_REF_BASE, collection_rec,
3437 regno_reg_rtx[HARD_FRAME_POINTER_REGNUM],
3438 NULL, bb, insn_info,
3439 DF_REF_REG_USE, 0);
3440 #endif
3441 break;
3442 default:
3443 break;
3447 if (CALL_P (insn_info->insn))
3448 df_get_call_refs (collection_rec, bb, insn_info,
3449 (is_cond_exec) ? DF_REF_CONDITIONAL : 0);
3451 /* Record the register uses. */
3452 df_uses_record (collection_rec,
3453 &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0);
3455 /* DF_REF_CONDITIONAL needs corresponding USES. */
3456 if (is_cond_exec)
3457 df_get_conditional_uses (collection_rec);
3459 df_canonize_collection_rec (collection_rec);
3462 /* Recompute the luids for the insns in BB. */
3464 void
3465 df_recompute_luids (basic_block bb)
3467 rtx insn;
3468 int luid = 0;
3470 df_grow_insn_info ();
3472 /* Scan the block an insn at a time from beginning to end. */
3473 FOR_BB_INSNS (bb, insn)
3475 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3476 /* Inserting labels does not always trigger the incremental
3477 rescanning. */
3478 if (!insn_info)
3480 gcc_assert (!INSN_P (insn));
3481 insn_info = df_insn_create_insn_record (insn);
3484 DF_INSN_INFO_LUID (insn_info) = luid;
3485 if (INSN_P (insn))
3486 luid++;
3491 /* Collect all artificial refs at the block level for BB and add them
3492 to COLLECTION_REC. */
3494 static void
3495 df_bb_refs_collect (struct df_collection_rec *collection_rec, basic_block bb)
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);
3502 if (bb->index == ENTRY_BLOCK)
3504 df_entry_block_defs_collect (collection_rec, df->entry_block_defs);
3505 return;
3507 else if (bb->index == EXIT_BLOCK)
3509 df_exit_block_uses_collect (collection_rec, df->exit_block_uses);
3510 return;
3513 #ifdef EH_RETURN_DATA_REGNO
3514 if (bb_has_eh_pred (bb))
3516 unsigned int i;
3517 /* Mark the registers that will contain data for the handler. */
3518 for (i = 0; ; ++i)
3520 unsigned regno = EH_RETURN_DATA_REGNO (i);
3521 if (regno == INVALID_REGNUM)
3522 break;
3523 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3524 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
3527 #endif
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)
3532 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL,
3533 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
3535 /* Add the artificial uses. */
3536 if (bb->index >= NUM_FIXED_BLOCKS)
3538 bitmap_iterator bi;
3539 unsigned int regno;
3540 bitmap au = bb_has_eh_pred (bb)
3541 ? &df->eh_block_artificial_uses
3542 : &df->regular_block_artificial_uses;
3544 EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi)
3546 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3547 bb, NULL, DF_REF_REG_USE, 0);
3551 df_canonize_collection_rec (collection_rec);
3555 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3557 void
3558 df_bb_refs_record (int bb_index, bool scan_insns)
3560 basic_block bb = BASIC_BLOCK (bb_index);
3561 rtx insn;
3562 int luid = 0;
3563 struct df_collection_rec collection_rec;
3565 if (!df)
3566 return;
3568 df_grow_bb_info (df_scan);
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);
3574 if (scan_insns)
3575 /* Scan the block an insn at a time from beginning to end. */
3576 FOR_BB_INSNS (bb, insn)
3578 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3579 gcc_assert (!insn_info);
3581 insn_info = df_insn_create_insn_record (insn);
3582 if (INSN_P (insn))
3584 /* Record refs within INSN. */
3585 DF_INSN_INFO_LUID (insn_info) = luid++;
3586 df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn));
3587 df_refs_add_to_chains (&collection_rec, bb, insn);
3589 DF_INSN_INFO_LUID (insn_info) = luid;
3592 /* Other block level artificial refs */
3593 df_bb_refs_collect (&collection_rec, bb);
3594 df_refs_add_to_chains (&collection_rec, bb, NULL);
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);
3601 /* Now that the block has been processed, set the block as dirty so
3602 LR and LIVE will get it processed. */
3603 df_set_bb_dirty (bb);
3607 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3608 block. */
3610 static void
3611 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses)
3613 #ifdef EH_USES
3614 unsigned int i;
3615 #endif
3617 bitmap_clear (regular_block_artificial_uses);
3619 if (reload_completed)
3621 if (frame_pointer_needed)
3622 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
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. */
3629 unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
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);
3635 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3636 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3637 #endif
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
3646 /* Any constant, or pseudo with constant equivalences, may
3647 require reloading from memory using the pic register. */
3648 if (picreg != INVALID_REGNUM
3649 && fixed_regs[picreg])
3650 bitmap_set_bit (regular_block_artificial_uses, picreg);
3652 /* The all-important stack pointer must always be live. */
3653 bitmap_set_bit (regular_block_artificial_uses, STACK_POINTER_REGNUM);
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
3671 /* Get the artificial use set for an eh block. */
3673 static void
3674 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses)
3676 bitmap_clear (eh_block_artificial_uses);
3678 /* The following code (down thru the arg_pointer setting APPEARS
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)
3684 if (frame_pointer_needed)
3686 bitmap_set_bit (eh_block_artificial_uses, FRAME_POINTER_REGNUM);
3687 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3688 bitmap_set_bit (eh_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3689 #endif
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
3700 /*----------------------------------------------------------------------------
3701 Specialized hard register scanning functions.
3702 ----------------------------------------------------------------------------*/
3705 /* Mark a register in SET. Hard registers in large modes get all
3706 of their component registers set as well. */
3708 static void
3709 df_mark_reg (rtx reg, void *vset)
3711 bitmap set = (bitmap) vset;
3712 int regno = REGNO (reg);
3714 gcc_assert (GET_MODE (reg) != BLKmode);
3716 if (regno < FIRST_PSEUDO_REGISTER)
3718 int n = hard_regno_nregs[regno][GET_MODE (reg)];
3719 bitmap_set_range (set, regno, n);
3721 else
3722 bitmap_set_bit (set, regno);
3726 /* Set the bit for regs that are considered being defined at the entry. */
3728 static void
3729 df_get_entry_block_def_set (bitmap entry_block_defs)
3731 rtx r;
3732 int i;
3734 bitmap_clear (entry_block_defs);
3736 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3737 if (FUNCTION_ARG_REGNO_P (i))
3738 bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
3740 /* The always important stack pointer. */
3741 bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM);
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)
3747 /* Defs for the callee saved registers are inserted so that the
3748 pushes have some defining location. */
3749 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3750 if ((call_used_regs[i] == 0) && (df_regs_ever_live_p (i)))
3751 bitmap_set_bit (entry_block_defs, i);
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));
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));
3764 if ((!reload_completed) || frame_pointer_needed)
3766 /* Any reference to any pseudo before reload is a potential
3767 reference of the frame pointer. */
3768 bitmap_set_bit (entry_block_defs, FRAME_POINTER_REGNUM);
3769 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3770 /* If they are different, also mark the hard frame pointer as live. */
3771 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
3772 bitmap_set_bit (entry_block_defs, HARD_FRAME_POINTER_REGNUM);
3773 #endif
3776 /* These registers are live everywhere. */
3777 if (!reload_completed)
3779 #ifdef PIC_OFFSET_TABLE_REGNUM
3780 unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
3781 #endif
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])
3787 bitmap_set_bit (entry_block_defs, ARG_POINTER_REGNUM);
3788 #endif
3790 #ifdef PIC_OFFSET_TABLE_REGNUM
3791 /* Any constant, or pseudo with constant equivalences, may
3792 require reloading from memory using the pic register. */
3793 if (picreg != INVALID_REGNUM
3794 && fixed_regs[picreg])
3795 bitmap_set_bit (entry_block_defs, picreg);
3796 #endif
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
3804 targetm.extra_live_on_entry (entry_block_defs);
3808 /* Return the (conservative) set of hard registers that are defined on
3809 entry to the function.
3810 It uses df->entry_block_defs to determine which register
3811 reference to include. */
3813 static void
3814 df_entry_block_defs_collect (struct df_collection_rec *collection_rec,
3815 bitmap entry_block_defs)
3817 unsigned int i;
3818 bitmap_iterator bi;
3820 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs, 0, i, bi)
3822 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
3823 ENTRY_BLOCK_PTR, NULL, DF_REF_REG_DEF, 0);
3826 df_canonize_collection_rec (collection_rec);
3830 /* Record the (conservative) set of hard registers that are defined on
3831 entry to the function. */
3833 static void
3834 df_record_entry_block_defs (bitmap entry_block_defs)
3836 struct df_collection_rec collection_rec;
3837 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
3838 collection_rec.def_vec = VEC_alloc (df_ref, stack, FIRST_PSEUDO_REGISTER);
3839 df_entry_block_defs_collect (&collection_rec, entry_block_defs);
3841 /* Process bb_refs chain */
3842 df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (ENTRY_BLOCK), NULL);
3843 VEC_free (df_ref, stack, collection_rec.def_vec);
3847 /* Update the defs in the entry block. */
3849 void
3850 df_update_entry_block_defs (void)
3852 bitmap_head refs;
3853 bool changed = false;
3855 bitmap_initialize (&refs, &df_bitmap_obstack);
3856 df_get_entry_block_def_set (&refs);
3857 if (df->entry_block_defs)
3859 if (!bitmap_equal_p (df->entry_block_defs, &refs))
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;
3868 else
3870 struct df_scan_problem_data *problem_data
3871 = (struct df_scan_problem_data *) df_scan->problem_data;
3872 gcc_unreachable ();
3873 df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
3874 changed = true;
3877 if (changed)
3879 df_record_entry_block_defs (&refs);
3880 bitmap_copy (df->entry_block_defs, &refs);
3881 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
3883 bitmap_clear (&refs);
3887 /* Set the bit for regs that are considered being used at the exit. */
3889 static void
3890 df_get_exit_block_use_set (bitmap exit_block_uses)
3892 unsigned int i;
3893 unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
3895 bitmap_clear (exit_block_uses);
3897 /* Stack pointer is always live at the exit. */
3898 bitmap_set_bit (exit_block_uses, STACK_POINTER_REGNUM);
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. */
3904 if ((!reload_completed) || frame_pointer_needed)
3906 bitmap_set_bit (exit_block_uses, FRAME_POINTER_REGNUM);
3907 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3908 /* If they are different, also mark the hard frame pointer as live. */
3909 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
3910 bitmap_set_bit (exit_block_uses, HARD_FRAME_POINTER_REGNUM);
3911 #endif
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. */
3917 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3918 && picreg != INVALID_REGNUM
3919 && fixed_regs[picreg])
3920 bitmap_set_bit (exit_block_uses, picreg);
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))
3927 bitmap_set_bit (exit_block_uses, i);
3929 if (HAVE_epilogue && epilogue_completed)
3931 /* Mark all call-saved registers that we actually used. */
3932 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3933 if (df_regs_ever_live_p (i) && !LOCAL_REGNO (i)
3934 && !TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
3935 bitmap_set_bit (exit_block_uses, i);
3938 #ifdef EH_RETURN_DATA_REGNO
3939 /* Mark the registers that will contain data for the handler. */
3940 if (reload_completed && crtl->calls_eh_return)
3941 for (i = 0; ; ++i)
3943 unsigned regno = EH_RETURN_DATA_REGNO (i);
3944 if (regno == INVALID_REGNUM)
3945 break;
3946 bitmap_set_bit (exit_block_uses, regno);
3948 #endif
3950 #ifdef EH_RETURN_STACKADJ_RTX
3951 if ((!HAVE_epilogue || ! epilogue_completed)
3952 && crtl->calls_eh_return)
3954 rtx tmp = EH_RETURN_STACKADJ_RTX;
3955 if (tmp && REG_P (tmp))
3956 df_mark_reg (tmp, exit_block_uses);
3958 #endif
3960 #ifdef EH_RETURN_HANDLER_RTX
3961 if ((!HAVE_epilogue || ! epilogue_completed)
3962 && crtl->calls_eh_return)
3964 rtx tmp = EH_RETURN_HANDLER_RTX;
3965 if (tmp && REG_P (tmp))
3966 df_mark_reg (tmp, exit_block_uses);
3968 #endif
3970 /* Mark function return value. */
3971 diddle_return_value (df_mark_reg, (void*) exit_block_uses);
3975 /* Return the refs of hard registers that are used in the exit block.
3976 It uses df->exit_block_uses to determine register to include. */
3978 static void
3979 df_exit_block_uses_collect (struct df_collection_rec *collection_rec, bitmap exit_block_uses)
3981 unsigned int i;
3982 bitmap_iterator bi;
3984 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses, 0, i, bi)
3985 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
3986 EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0);
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. */
3991 if (reload_completed
3992 && !bitmap_bit_p (exit_block_uses, ARG_POINTER_REGNUM)
3993 && bb_has_eh_pred (EXIT_BLOCK_PTR)
3994 && fixed_regs[ARG_POINTER_REGNUM])
3995 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[ARG_POINTER_REGNUM], NULL,
3996 EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0);
3997 #endif
3999 df_canonize_collection_rec (collection_rec);
4003 /* Record the set of hard registers that are used in the exit block.
4004 It uses df->exit_block_uses to determine which bit to include. */
4006 static void
4007 df_record_exit_block_uses (bitmap exit_block_uses)
4009 struct df_collection_rec collection_rec;
4010 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
4011 collection_rec.use_vec = VEC_alloc (df_ref, stack, FIRST_PSEUDO_REGISTER);
4013 df_exit_block_uses_collect (&collection_rec, exit_block_uses);
4015 /* Process bb_refs chain */
4016 df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (EXIT_BLOCK), NULL);
4017 VEC_free (df_ref, stack, collection_rec.use_vec);
4021 /* Update the uses in the exit block. */
4023 void
4024 df_update_exit_block_uses (void)
4026 bitmap_head refs;
4027 bool changed = false;
4029 bitmap_initialize (&refs, &df_bitmap_obstack);
4030 df_get_exit_block_use_set (&refs);
4031 if (df->exit_block_uses)
4033 if (!bitmap_equal_p (df->exit_block_uses, &refs))
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;
4042 else
4044 struct df_scan_problem_data *problem_data
4045 = (struct df_scan_problem_data *) df_scan->problem_data;
4046 gcc_unreachable ();
4047 df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
4048 changed = true;
4051 if (changed)
4053 df_record_exit_block_uses (&refs);
4054 bitmap_copy (df->exit_block_uses,& refs);
4055 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
4057 bitmap_clear (&refs);
4060 static bool initialized = false;
4063 /* Initialize some platform specific structures. */
4065 void
4066 df_hard_reg_init (void)
4068 #ifdef ELIMINABLE_REGS
4069 int i;
4070 static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
4071 #endif
4072 if (initialized)
4073 return;
4075 /* Record which registers will be eliminated. We use this in
4076 mark_used_regs. */
4077 CLEAR_HARD_REG_SET (elim_reg_set);
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
4086 initialized = true;
4090 /* Recompute the parts of scanning that are based on regs_ever_live
4091 because something changed in that array. */
4093 void
4094 df_update_entry_exit_and_calls (void)
4096 basic_block bb;
4098 df_update_entry_block_defs ();
4099 df_update_exit_block_uses ();
4101 /* The call insns need to be rescanned because there may be changes
4102 in the set of registers clobbered across the call. */
4103 FOR_EACH_BB (bb)
4105 rtx insn;
4106 FOR_BB_INSNS (bb, insn)
4108 if (INSN_P (insn) && CALL_P (insn))
4109 df_insn_rescan (insn);
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. */
4120 bool
4121 df_hard_reg_used_p (unsigned int reg)
4123 return df->hard_regs_live_count[reg] != 0;
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. */
4134 unsigned int
4135 df_hard_reg_used_count (unsigned int reg)
4137 return df->hard_regs_live_count[reg];
4141 /* Get the value of regs_ever_live[REGNO]. */
4143 bool
4144 df_regs_ever_live_p (unsigned int regno)
4146 return regs_ever_live[regno];
4150 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
4151 to change, schedule that change for the next update. */
4153 void
4154 df_set_regs_ever_live (unsigned int regno, bool value)
4156 if (regs_ever_live[regno] == value)
4157 return;
4159 regs_ever_live[regno] = value;
4160 if (df)
4161 df->redo_entry_and_exit = true;
4165 /* Compute "regs_ever_live" information from the underlying df
4166 information. Set the vector to all false if RESET. */
4168 void
4169 df_compute_regs_ever_live (bool reset)
4171 unsigned int i;
4172 bool changed = df->redo_entry_and_exit;
4174 if (reset)
4175 memset (regs_ever_live, 0, sizeof (regs_ever_live));
4177 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4178 if ((!regs_ever_live[i]) && df_hard_reg_used_p (i))
4180 regs_ever_live[i] = true;
4181 changed = true;
4183 if (changed)
4184 df_update_entry_exit_and_calls ();
4185 df->redo_entry_and_exit = false;
4189 /*----------------------------------------------------------------------------
4190 Dataflow ref information verification functions.
4192 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4193 df_reg_chain_verify_unmarked (refs)
4194 df_refs_verify (VEC(stack,df_ref)*, ref*, bool)
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 ----------------------------------------------------------------------------*/
4205 /* Mark all refs in the reg chain. Verify that all of the registers
4206 are in the correct chain. */
4208 static unsigned int
4209 df_reg_chain_mark (df_ref refs, unsigned int regno,
4210 bool is_def, bool is_eq_use)
4212 unsigned int count = 0;
4213 df_ref ref;
4214 for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4216 gcc_assert (!DF_REF_IS_REG_MARKED (ref));
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));
4223 /* Check to make sure the ref is in the correct chain. */
4224 gcc_assert (DF_REF_REGNO (ref) == regno);
4225 if (is_def)
4226 gcc_assert (DF_REF_REG_DEF_P (ref));
4227 else
4228 gcc_assert (!DF_REF_REG_DEF_P (ref));
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);
4235 if (DF_REF_NEXT_REG (ref))
4236 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref)) == ref);
4237 count++;
4238 DF_REF_REG_MARK (ref);
4240 return count;
4244 /* Verify that all of the registers in the chain are unmarked. */
4246 static void
4247 df_reg_chain_verify_unmarked (df_ref refs)
4249 df_ref ref;
4250 for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4251 gcc_assert (!DF_REF_IS_REG_MARKED (ref));
4255 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4257 static bool
4258 df_refs_verify (VEC(df_ref,stack) *new_rec, df_ref *old_rec,
4259 bool abort_if_fail)
4261 unsigned int ix;
4262 df_ref new_ref;
4264 FOR_EACH_VEC_ELT (df_ref, new_rec, ix, new_ref)
4266 if (*old_rec == NULL || !df_ref_equal_p (new_ref, *old_rec))
4268 if (abort_if_fail)
4269 gcc_assert (0);
4270 else
4271 return false;
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)
4278 gcc_assert (DF_REF_IS_REG_MARKED (*old_rec));
4279 DF_REF_REG_UNMARK (*old_rec);
4282 old_rec++;
4285 if (abort_if_fail)
4286 gcc_assert (*old_rec == NULL);
4287 else
4288 return *old_rec == NULL;
4289 return false;
4293 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4295 static bool
4296 df_mws_verify (VEC(df_mw_hardreg_ptr,stack) *new_rec,
4297 struct df_mw_hardreg **old_rec,
4298 bool abort_if_fail)
4300 unsigned int ix;
4301 struct df_mw_hardreg *new_reg;
4303 FOR_EACH_VEC_ELT (df_mw_hardreg_ptr, new_rec, ix, new_reg)
4305 if (*old_rec == NULL || !df_mw_equal_p (new_reg, *old_rec))
4307 if (abort_if_fail)
4308 gcc_assert (0);
4309 else
4310 return false;
4312 old_rec++;
4315 if (abort_if_fail)
4316 gcc_assert (*old_rec == NULL);
4317 else
4318 return *old_rec == NULL;
4319 return false;
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),
4325 return the correct df_ref chain in REFS_RETURN.
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.
4332 If ABORT_IF_FAIL is set, this function never returns false. */
4334 static bool
4335 df_insn_refs_verify (struct df_collection_rec *collection_rec,
4336 basic_block bb,
4337 rtx insn,
4338 bool abort_if_fail)
4340 bool ret1, ret2, ret3, ret4;
4341 unsigned int uid = INSN_UID (insn);
4342 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
4344 df_insn_refs_collect (collection_rec, bb, insn_info);
4346 if (!DF_INSN_UID_DEFS (uid))
4348 /* The insn_rec was created but it was never filled out. */
4349 if (abort_if_fail)
4350 gcc_assert (0);
4351 else
4352 return false;
4355 /* Unfortunately we cannot opt out early if one of these is not
4356 right because the marks will not get cleared. */
4357 ret1 = df_refs_verify (collection_rec->def_vec, DF_INSN_UID_DEFS (uid),
4358 abort_if_fail);
4359 ret2 = df_refs_verify (collection_rec->use_vec, DF_INSN_UID_USES (uid),
4360 abort_if_fail);
4361 ret3 = df_refs_verify (collection_rec->eq_use_vec, DF_INSN_UID_EQ_USES (uid),
4362 abort_if_fail);
4363 ret4 = df_mws_verify (collection_rec->mw_vec, DF_INSN_UID_MWS (uid),
4364 abort_if_fail);
4365 return (ret1 && ret2 && ret3 && ret4);
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. */
4373 static bool
4374 df_bb_verify (basic_block bb)
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;
4380 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
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);
4386 gcc_assert (bb_info);
4388 /* Scan the block, one insn at a time, from beginning to end. */
4389 FOR_BB_INSNS_REVERSE (bb, insn)
4391 if (!INSN_P (insn))
4392 continue;
4393 df_insn_refs_verify (&collection_rec, bb, insn, true);
4394 df_free_collection_rec (&collection_rec);
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);
4403 return true;
4407 /* Returns true if the entry block has correct and complete df_ref set.
4408 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4410 static bool
4411 df_entry_block_bitmap_verify (bool abort_if_fail)
4413 bitmap_head entry_block_defs;
4414 bool is_eq;
4416 bitmap_initialize (&entry_block_defs, &df_bitmap_obstack);
4417 df_get_entry_block_def_set (&entry_block_defs);
4419 is_eq = bitmap_equal_p (&entry_block_defs, df->entry_block_defs);
4421 if (!is_eq && abort_if_fail)
4423 print_current_pass (stderr);
4424 fprintf (stderr, "entry_block_defs = ");
4425 df_print_regset (stderr, &entry_block_defs);
4426 fprintf (stderr, "df->entry_block_defs = ");
4427 df_print_regset (stderr, df->entry_block_defs);
4428 gcc_assert (0);
4431 bitmap_clear (&entry_block_defs);
4433 return is_eq;
4437 /* Returns true if the exit block has correct and complete df_ref set.
4438 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4440 static bool
4441 df_exit_block_bitmap_verify (bool abort_if_fail)
4443 bitmap_head exit_block_uses;
4444 bool is_eq;
4446 bitmap_initialize (&exit_block_uses, &df_bitmap_obstack);
4447 df_get_exit_block_use_set (&exit_block_uses);
4449 is_eq = bitmap_equal_p (&exit_block_uses, df->exit_block_uses);
4451 if (!is_eq && abort_if_fail)
4453 print_current_pass (stderr);
4454 fprintf (stderr, "exit_block_uses = ");
4455 df_print_regset (stderr, &exit_block_uses);
4456 fprintf (stderr, "df->exit_block_uses = ");
4457 df_print_regset (stderr, df->exit_block_uses);
4458 gcc_assert (0);
4461 bitmap_clear (&exit_block_uses);
4463 return is_eq;
4467 /* Return true if df_ref information for all insns in all blocks are
4468 correct and complete. */
4470 void
4471 df_scan_verify (void)
4473 unsigned int i;
4474 basic_block bb;
4475 bitmap_head regular_block_artificial_uses;
4476 bitmap_head eh_block_artificial_uses;
4478 if (!df)
4479 return;
4481 /* Verification is a 4 step process. */
4483 /* (1) All of the refs are marked by going thru the reg chains. */
4484 for (i = 0; i < DF_REG_SIZE (df); i++)
4486 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false)
4487 == DF_REG_DEF_COUNT(i));
4488 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i), i, false, false)
4489 == DF_REG_USE_COUNT(i));
4490 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i), i, false, true)
4491 == DF_REG_EQ_USE_COUNT(i));
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. */
4497 bitmap_initialize (&regular_block_artificial_uses, &df_bitmap_obstack);
4498 bitmap_initialize (&eh_block_artificial_uses, &df_bitmap_obstack);
4500 df_get_regular_block_artificial_uses (&regular_block_artificial_uses);
4501 df_get_eh_block_artificial_uses (&eh_block_artificial_uses);
4503 bitmap_ior_into (&eh_block_artificial_uses,
4504 &regular_block_artificial_uses);
4506 /* Check artificial_uses bitmaps didn't change. */
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));
4512 bitmap_clear (&regular_block_artificial_uses);
4513 bitmap_clear (&eh_block_artificial_uses);
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);
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. */
4526 FOR_ALL_BB (bb)
4527 df_bb_verify (bb);
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. */
4533 for (i = 0; i < DF_REG_SIZE (df); i++)
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));