1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 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
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
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/>. */
27 #include "coretypes.h"
31 #include "insn-config.h"
36 #include "alloc-pool.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
45 #include "target-def.h"
47 #include "tree-pass.h"
50 #define HAVE_epilogue 0
53 #define HAVE_prologue 0
55 #ifndef HAVE_sibcall_epilogue
56 #define HAVE_sibcall_epilogue 0
60 #define EPILOGUE_USES(REGNO) 0
63 /* The following two macros free the vecs that hold either the refs or
64 the mw refs. They are a little tricky because the vec has 0
65 elements is special and is not to be freed. */
66 #define df_scan_free_ref_vec(V) \
72 #define df_scan_free_mws_vec(V) \
78 /* The bitmap_obstack is used to hold some static variables that
79 should not be reset after each function is compiled. */
81 static bitmap_obstack persistent_obstack;
83 /* The set of hard registers in eliminables[i].from. */
85 static HARD_REG_SET elim_reg_set;
87 /* This is a bitmap copy of regs_invalidated_by_call so that we can
88 easily add it into bitmaps, etc. */
90 bitmap df_invalidated_by_call = NULL;
92 /* Initialize ur_in and ur_out as if all hard registers were partially
95 struct df_collection_rec
98 unsigned int next_def;
100 unsigned int next_use;
102 unsigned int next_eq_use;
103 struct df_mw_hardreg **mw_vec;
104 unsigned int next_mw;
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 *,
112 basic_block, struct df_insn_info *,
113 enum df_ref_type, enum df_ref_flags,
114 int, int, enum machine_mode);
115 static void df_def_record_1 (struct df_collection_rec *, rtx,
116 basic_block, struct df_insn_info *,
118 static void df_defs_record (struct df_collection_rec *, rtx,
119 basic_block, struct df_insn_info *,
121 static void df_uses_record (enum df_ref_class, struct df_collection_rec *,
122 rtx *, enum df_ref_type,
123 basic_block, struct df_insn_info *,
125 int, int, enum machine_mode);
127 static df_ref df_ref_create_structure (enum df_ref_class,
128 struct df_collection_rec *, rtx, rtx *,
129 basic_block, struct df_insn_info *,
130 enum df_ref_type, enum df_ref_flags,
131 int, int, enum machine_mode);
133 static void df_insn_refs_collect (struct df_collection_rec*,
134 basic_block, struct df_insn_info *);
135 static void df_canonize_collection_rec (struct df_collection_rec *);
137 static void df_get_regular_block_artificial_uses (bitmap);
138 static void df_get_eh_block_artificial_uses (bitmap);
140 static void df_record_entry_block_defs (bitmap);
141 static void df_record_exit_block_uses (bitmap);
142 static void df_get_exit_block_use_set (bitmap);
143 static void df_get_entry_block_def_set (bitmap);
144 static void df_grow_ref_info (struct df_ref_info *, unsigned int);
145 static void df_ref_chain_delete_du_chain (df_ref *);
146 static void df_ref_chain_delete (df_ref *);
148 static void df_refs_add_to_chains (struct df_collection_rec *,
151 static bool df_insn_refs_verify (struct df_collection_rec *, basic_block, rtx, bool);
152 static void df_entry_block_defs_collect (struct df_collection_rec *, bitmap);
153 static void df_exit_block_uses_collect (struct df_collection_rec *, bitmap);
154 static void df_install_ref (df_ref, struct df_reg_info *,
155 struct df_ref_info *, bool);
157 static int df_ref_compare (const void *, const void *);
158 static int df_mw_compare (const void *, const void *);
160 /* Indexed by hardware reg number, is true if that register is ever
161 used in the current function.
163 In df-scan.c, this is set up to record the hard regs used
164 explicitly. Reload adds in the hard regs used for holding pseudo
165 regs. Final uses it to generate the code in the function prologue
166 and epilogue to save and restore registers as needed. */
168 static bool regs_ever_live[FIRST_PSEUDO_REGISTER];
170 /*----------------------------------------------------------------------------
171 SCANNING DATAFLOW PROBLEM
173 There are several ways in which scanning looks just like the other
174 dataflow problems. It shares the all the mechanisms for local info
175 as well as basic block info. Where it differs is when and how often
176 it gets run. It also has no need for the iterative solver.
177 ----------------------------------------------------------------------------*/
179 /* Problem data for the scanning dataflow function. */
180 struct df_scan_problem_data
182 alloc_pool ref_base_pool;
183 alloc_pool ref_artificial_pool;
184 alloc_pool ref_regular_pool;
185 alloc_pool ref_extract_pool;
186 alloc_pool insn_pool;
188 alloc_pool mw_reg_pool;
189 bitmap_obstack reg_bitmaps;
190 bitmap_obstack insn_bitmaps;
193 typedef struct df_scan_bb_info *df_scan_bb_info_t;
196 /* Internal function to shut down the scanning problem. */
198 df_scan_free_internal (void)
200 struct df_scan_problem_data *problem_data
201 = (struct df_scan_problem_data *) df_scan->problem_data;
205 /* The vectors that hold the refs are not pool allocated because
206 they come in many sizes. This makes them impossible to delete
208 for (i = 0; i < DF_INSN_SIZE(); i++)
210 struct df_insn_info *insn_info = DF_INSN_UID_GET(i);
211 /* Skip the insns that have no insn_info or have been
215 df_scan_free_ref_vec (insn_info->defs);
216 df_scan_free_ref_vec (insn_info->uses);
217 df_scan_free_ref_vec (insn_info->eq_uses);
218 df_scan_free_mws_vec (insn_info->mw_hardregs);
224 unsigned int bb_index = bb->index;
225 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
228 df_scan_free_ref_vec (bb_info->artificial_defs);
229 df_scan_free_ref_vec (bb_info->artificial_uses);
233 free (df->def_info.refs);
234 free (df->def_info.begin);
235 free (df->def_info.count);
236 memset (&df->def_info, 0, (sizeof (struct df_ref_info)));
238 free (df->use_info.refs);
239 free (df->use_info.begin);
240 free (df->use_info.count);
241 memset (&df->use_info, 0, (sizeof (struct df_ref_info)));
247 free (df->eq_use_regs);
248 df->eq_use_regs = NULL;
256 free (df_scan->block_info);
257 df_scan->block_info = NULL;
258 df_scan->block_info_size = 0;
260 BITMAP_FREE (df->hardware_regs_used);
261 BITMAP_FREE (df->regular_block_artificial_uses);
262 BITMAP_FREE (df->eh_block_artificial_uses);
263 BITMAP_FREE (df->entry_block_defs);
264 BITMAP_FREE (df->exit_block_uses);
265 BITMAP_FREE (df->insns_to_delete);
266 BITMAP_FREE (df->insns_to_rescan);
267 BITMAP_FREE (df->insns_to_notes_rescan);
269 free_alloc_pool (df_scan->block_pool);
270 free_alloc_pool (problem_data->ref_base_pool);
271 free_alloc_pool (problem_data->ref_artificial_pool);
272 free_alloc_pool (problem_data->ref_regular_pool);
273 free_alloc_pool (problem_data->ref_extract_pool);
274 free_alloc_pool (problem_data->insn_pool);
275 free_alloc_pool (problem_data->reg_pool);
276 free_alloc_pool (problem_data->mw_reg_pool);
277 bitmap_obstack_release (&problem_data->reg_bitmaps);
278 bitmap_obstack_release (&problem_data->insn_bitmaps);
279 free (df_scan->problem_data);
283 /* Set basic block info. */
286 df_scan_set_bb_info (unsigned int index,
287 struct df_scan_bb_info *bb_info)
289 gcc_assert (df_scan);
290 df_grow_bb_info (df_scan);
291 df_scan->block_info[index] = (void *) bb_info;
295 /* Free basic block info. */
298 df_scan_free_bb_info (basic_block bb, void *vbb_info)
300 struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
301 unsigned int bb_index = bb->index;
305 FOR_BB_INSNS (bb, insn)
308 /* Record defs within INSN. */
309 df_insn_delete (bb, INSN_UID (insn));
312 if (bb_index < df_scan->block_info_size)
313 bb_info = df_scan_get_bb_info (bb_index);
315 /* Get rid of any artificial uses or defs. */
316 df_ref_chain_delete_du_chain (bb_info->artificial_defs);
317 df_ref_chain_delete_du_chain (bb_info->artificial_uses);
318 df_ref_chain_delete (bb_info->artificial_defs);
319 df_ref_chain_delete (bb_info->artificial_uses);
320 bb_info->artificial_defs = NULL;
321 bb_info->artificial_uses = NULL;
322 pool_free (df_scan->block_pool, bb_info);
327 /* Allocate the problem data for the scanning problem. This should be
328 called when the problem is created or when the entire function is to
331 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
333 struct df_scan_problem_data *problem_data;
334 unsigned int insn_num = get_max_uid () + 1;
335 unsigned int block_size = 400;
338 /* Given the number of pools, this is really faster than tearing
340 if (df_scan->problem_data)
341 df_scan_free_internal ();
344 = create_alloc_pool ("df_scan_block pool",
345 sizeof (struct df_scan_bb_info),
348 problem_data = XNEW (struct df_scan_problem_data);
349 df_scan->problem_data = problem_data;
350 df_scan->computed = true;
352 problem_data->ref_base_pool
353 = create_alloc_pool ("df_scan ref base",
354 sizeof (struct df_base_ref), block_size);
355 problem_data->ref_artificial_pool
356 = create_alloc_pool ("df_scan ref artificial",
357 sizeof (struct df_artificial_ref), block_size);
358 problem_data->ref_regular_pool
359 = create_alloc_pool ("df_scan ref regular",
360 sizeof (struct df_regular_ref), block_size);
361 problem_data->ref_extract_pool
362 = create_alloc_pool ("df_scan ref extract",
363 sizeof (struct df_extract_ref), block_size);
364 problem_data->insn_pool
365 = create_alloc_pool ("df_scan insn",
366 sizeof (struct df_insn_info), block_size);
367 problem_data->reg_pool
368 = create_alloc_pool ("df_scan reg",
369 sizeof (struct df_reg_info), block_size);
370 problem_data->mw_reg_pool
371 = create_alloc_pool ("df_scan mw_reg",
372 sizeof (struct df_mw_hardreg), block_size);
374 bitmap_obstack_initialize (&problem_data->reg_bitmaps);
375 bitmap_obstack_initialize (&problem_data->insn_bitmaps);
377 insn_num += insn_num / 4;
380 df_grow_insn_info ();
381 df_grow_bb_info (df_scan);
385 unsigned int bb_index = bb->index;
386 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
389 bb_info = (struct df_scan_bb_info *) pool_alloc (df_scan->block_pool);
390 df_scan_set_bb_info (bb_index, bb_info);
392 bb_info->artificial_defs = NULL;
393 bb_info->artificial_uses = NULL;
396 df->hardware_regs_used = BITMAP_ALLOC (&problem_data->reg_bitmaps);
397 df->regular_block_artificial_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
398 df->eh_block_artificial_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
399 df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
400 df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
401 df->insns_to_delete = BITMAP_ALLOC (&problem_data->insn_bitmaps);
402 df->insns_to_rescan = BITMAP_ALLOC (&problem_data->insn_bitmaps);
403 df->insns_to_notes_rescan = BITMAP_ALLOC (&problem_data->insn_bitmaps);
404 df_scan->optional_p = false;
408 /* Free all of the data associated with the scan problem. */
413 if (df_scan->problem_data)
414 df_scan_free_internal ();
416 if (df->blocks_to_analyze)
418 BITMAP_FREE (df->blocks_to_analyze);
419 df->blocks_to_analyze = NULL;
425 /* Dump the preamble for DF_SCAN dump. */
427 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
438 fprintf (file, ";; invalidated by call \t");
439 df_print_regset (file, df_invalidated_by_call);
440 fprintf (file, ";; hardware regs used \t");
441 df_print_regset (file, df->hardware_regs_used);
442 fprintf (file, ";; regular block artificial uses \t");
443 df_print_regset (file, df->regular_block_artificial_uses);
444 fprintf (file, ";; eh block artificial uses \t");
445 df_print_regset (file, df->eh_block_artificial_uses);
446 fprintf (file, ";; entry block defs \t");
447 df_print_regset (file, df->entry_block_defs);
448 fprintf (file, ";; exit block uses \t");
449 df_print_regset (file, df->exit_block_uses);
450 fprintf (file, ";; regs ever live \t");
451 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
452 if (df_regs_ever_live_p (i))
453 fprintf (file, " %d[%s]", i, reg_names[i]);
454 fprintf (file, "\n;; ref usage \t");
456 for (i = 0; i < (int)df->regs_inited; i++)
457 if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i))
459 const char * sep = "";
461 fprintf (file, "r%d={", i);
462 if (DF_REG_DEF_COUNT (i))
464 fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
466 dcount += DF_REG_DEF_COUNT (i);
468 if (DF_REG_USE_COUNT (i))
470 fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
472 ucount += DF_REG_USE_COUNT (i);
474 if (DF_REG_EQ_USE_COUNT (i))
476 fprintf (file, "%s%dd", sep, DF_REG_EQ_USE_COUNT (i));
477 ecount += DF_REG_EQ_USE_COUNT (i);
479 fprintf (file, "} ");
483 FOR_BB_INSNS (bb, insn)
492 fprintf (file, "\n;; total ref usage %d{%dd,%du,%de} in %d{%d regular + %d call} insns.\n",
493 dcount + ucount + ecount, dcount, ucount, ecount, icount + ccount, icount, ccount);
496 /* Dump the bb_info for a given basic block. */
498 df_scan_start_block (basic_block bb, FILE *file)
500 struct df_scan_bb_info *bb_info
501 = df_scan_get_bb_info (bb->index);
505 fprintf (file, ";; bb %d artificial_defs: ", bb->index);
506 df_refs_chain_dump (bb_info->artificial_defs, true, file);
507 fprintf (file, "\n;; bb %d artificial_uses: ", bb->index);
508 df_refs_chain_dump (bb_info->artificial_uses, true, file);
509 fprintf (file, "\n");
514 FOR_BB_INSNS (bb, insn)
516 df_insn_debug (insn, false, file);
521 static struct df_problem problem_SCAN =
523 DF_SCAN, /* Problem id. */
524 DF_NONE, /* Direction. */
525 df_scan_alloc, /* Allocate the problem specific data. */
526 NULL, /* Reset global information. */
527 df_scan_free_bb_info, /* Free basic block info. */
528 NULL, /* Local compute function. */
529 NULL, /* Init the solution specific data. */
530 NULL, /* Iterative solver. */
531 NULL, /* Confluence operator 0. */
532 NULL, /* Confluence operator n. */
533 NULL, /* Transfer function. */
534 NULL, /* Finalize function. */
535 df_scan_free, /* Free all of the problem information. */
536 NULL, /* Remove this problem from the stack of dataflow problems. */
537 df_scan_start_dump, /* Debugging. */
538 df_scan_start_block, /* Debugging start block. */
539 NULL, /* Debugging end block. */
540 NULL, /* Incremental solution verify start. */
541 NULL, /* Incremental solution verify end. */
542 NULL, /* Dependent problem. */
543 TV_DF_SCAN, /* Timing variable. */
544 false /* Reset blocks on dropping out of blocks_to_analyze. */
548 /* Create a new DATAFLOW instance and add it to an existing instance
549 of DF. The returned structure is what is used to get at the
553 df_scan_add_problem (void)
555 df_add_problem (&problem_SCAN);
559 /*----------------------------------------------------------------------------
560 Storage Allocation Utilities
561 ----------------------------------------------------------------------------*/
564 /* First, grow the reg_info information. If the current size is less than
565 the number of pseudos, grow to 25% more than the number of
568 Second, assure that all of the slots up to max_reg_num have been
569 filled with reg_info structures. */
572 df_grow_reg_info (void)
574 unsigned int max_reg = max_reg_num ();
575 unsigned int new_size = max_reg;
576 struct df_scan_problem_data *problem_data
577 = (struct df_scan_problem_data *) df_scan->problem_data;
580 if (df->regs_size < new_size)
582 new_size += new_size / 4;
583 df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
584 df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
585 df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
587 df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
588 df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
589 df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
590 df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
591 df->regs_size = new_size;
594 for (i = df->regs_inited; i < max_reg; i++)
596 struct df_reg_info *reg_info;
598 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
599 memset (reg_info, 0, sizeof (struct df_reg_info));
600 df->def_regs[i] = reg_info;
601 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
602 memset (reg_info, 0, sizeof (struct df_reg_info));
603 df->use_regs[i] = reg_info;
604 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
605 memset (reg_info, 0, sizeof (struct df_reg_info));
606 df->eq_use_regs[i] = reg_info;
607 df->def_info.begin[i] = 0;
608 df->def_info.count[i] = 0;
609 df->use_info.begin[i] = 0;
610 df->use_info.count[i] = 0;
613 df->regs_inited = max_reg;
617 /* Grow the ref information. */
620 df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
622 if (ref_info->refs_size < new_size)
624 ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
625 memset (ref_info->refs + ref_info->refs_size, 0,
626 (new_size - ref_info->refs_size) *sizeof (df_ref));
627 ref_info->refs_size = new_size;
632 /* Check and grow the ref information if necessary. This routine
633 guarantees total_size + BITMAP_ADDEND amount of entries in refs
634 array. It updates ref_info->refs_size only and does not change
635 ref_info->total_size. */
638 df_check_and_grow_ref_info (struct df_ref_info *ref_info,
639 unsigned bitmap_addend)
641 if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
643 int new_size = ref_info->total_size + bitmap_addend;
644 new_size += ref_info->total_size / 4;
645 df_grow_ref_info (ref_info, new_size);
650 /* Grow the ref information. If the current size is less than the
651 number of instructions, grow to 25% more than the number of
655 df_grow_insn_info (void)
657 unsigned int new_size = get_max_uid () + 1;
658 if (DF_INSN_SIZE () < new_size)
660 new_size += new_size / 4;
661 df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
662 memset (df->insns + df->insns_size, 0,
663 (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
664 DF_INSN_SIZE () = new_size;
671 /*----------------------------------------------------------------------------
672 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
673 ----------------------------------------------------------------------------*/
675 /* Rescan all of the block_to_analyze or all of the blocks in the
676 function if df_set_blocks if blocks_to_analyze is NULL; */
679 df_scan_blocks (void)
683 df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
684 df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
686 df_get_regular_block_artificial_uses (df->regular_block_artificial_uses);
687 df_get_eh_block_artificial_uses (df->eh_block_artificial_uses);
689 bitmap_ior_into (df->eh_block_artificial_uses,
690 df->regular_block_artificial_uses);
692 /* ENTRY and EXIT blocks have special defs/uses. */
693 df_get_entry_block_def_set (df->entry_block_defs);
694 df_record_entry_block_defs (df->entry_block_defs);
695 df_get_exit_block_use_set (df->exit_block_uses);
696 df_record_exit_block_uses (df->exit_block_uses);
697 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
698 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
703 unsigned int bb_index = bb->index;
704 df_bb_refs_record (bb_index, true);
709 /* Create a new ref of type DF_REF_TYPE for register REG at address
710 LOC within INSN of BB. This function is only used externally.
712 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
713 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
714 fields if they were constants. Otherwise they should be -1 if
715 those flags were set. */
718 df_ref_create (rtx reg, rtx *loc, rtx insn,
720 enum df_ref_type ref_type,
721 enum df_ref_flags ref_flags,
722 int width, int offset, enum machine_mode mode)
725 struct df_reg_info **reg_info;
726 struct df_ref_info *ref_info;
728 df_ref **ref_rec_ptr;
729 unsigned int count = 0;
731 enum df_ref_class cl;
735 /* You cannot hack artificial refs. */
738 if (width != -1 || offset != -1)
744 ref = df_ref_create_structure (cl, NULL, reg, loc, bb, DF_INSN_INFO_GET (insn),
746 width, offset, mode);
748 if (DF_REF_REG_DEF_P (ref))
750 reg_info = df->def_regs;
751 ref_info = &df->def_info;
752 ref_rec_ptr = &DF_INSN_DEFS (insn);
753 add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
755 else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
757 reg_info = df->eq_use_regs;
758 ref_info = &df->use_info;
759 ref_rec_ptr = &DF_INSN_EQ_USES (insn);
760 switch (ref_info->ref_order)
762 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
763 case DF_REF_ORDER_BY_REG_WITH_NOTES:
764 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
768 add_to_table = false;
774 reg_info = df->use_regs;
775 ref_info = &df->use_info;
776 ref_rec_ptr = &DF_INSN_USES (insn);
777 add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
780 /* Do not add if ref is not in the right blocks. */
781 if (add_to_table && df->analyze_subset)
782 add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
784 df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
787 switch (ref_info->ref_order)
789 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
790 case DF_REF_ORDER_BY_REG_WITH_NOTES:
791 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
792 ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
795 ref_info->ref_order = DF_REF_ORDER_UNORDERED;
799 ref_rec = *ref_rec_ptr;
806 ref_rec = *ref_rec_ptr;
809 ref_rec = XRESIZEVEC (df_ref, ref_rec, count+2);
810 *ref_rec_ptr = ref_rec;
811 ref_rec[count] = ref;
812 ref_rec[count+1] = NULL;
813 qsort (ref_rec, count + 1, sizeof (df_ref), df_ref_compare);
817 df_ref *ref_rec = XNEWVEC (df_ref, 2);
820 *ref_rec_ptr = ref_rec;
826 fprintf (dump_file, "adding ref ");
827 df_ref_debug (ref, dump_file);
830 /* By adding the ref directly, df_insn_rescan my not find any
831 differences even though the block will have changed. So we need
832 to mark the block dirty ourselves. */
833 df_set_bb_dirty (bb);
840 /*----------------------------------------------------------------------------
841 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
842 ----------------------------------------------------------------------------*/
845 df_free_ref (df_ref ref)
847 struct df_scan_problem_data *problem_data
848 = (struct df_scan_problem_data *) df_scan->problem_data;
850 switch (DF_REF_CLASS (ref))
853 pool_free (problem_data->ref_base_pool, ref);
856 case DF_REF_ARTIFICIAL:
857 pool_free (problem_data->ref_artificial_pool, ref);
861 pool_free (problem_data->ref_regular_pool, ref);
865 pool_free (problem_data->ref_extract_pool, ref);
871 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
872 Also delete the def-use or use-def chain if it exists. */
875 df_reg_chain_unlink (df_ref ref)
877 df_ref next = DF_REF_NEXT_REG (ref);
878 df_ref prev = DF_REF_PREV_REG (ref);
879 int id = DF_REF_ID (ref);
880 struct df_reg_info *reg_info;
883 if (DF_REF_REG_DEF_P (ref))
885 int regno = DF_REF_REGNO (ref);
886 reg_info = DF_REG_DEF_GET (regno);
887 refs = df->def_info.refs;
891 if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
893 reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
894 switch (df->use_info.ref_order)
896 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
897 case DF_REF_ORDER_BY_REG_WITH_NOTES:
898 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
899 refs = df->use_info.refs;
907 reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
908 refs = df->use_info.refs;
914 if (df->analyze_subset)
916 if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
923 /* Delete any def-use or use-def chains that start here. It is
924 possible that there is trash in this field. This happens for
925 insns that have been deleted when rescanning has been deferred
926 and the chain problem has also been deleted. The chain tear down
927 code skips deleted insns. */
928 if (df_chain && DF_REF_CHAIN (ref))
929 df_chain_unlink (ref);
932 if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
934 gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
935 df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
938 /* Unlink from the reg chain. If there is no prev, this is the
939 first of the list. If not, just join the next and prev. */
941 DF_REF_NEXT_REG (prev) = next;
944 gcc_assert (reg_info->reg_chain == ref);
945 reg_info->reg_chain = next;
948 DF_REF_PREV_REG (next) = prev;
954 /* Remove REF from VEC. */
957 df_ref_compress_rec (df_ref **vec_ptr, df_ref ref)
959 df_ref *vec = *vec_ptr;
963 while (*vec && *vec != ref)
975 *vec_ptr = df_null_ref_rec;
980 /* Unlink REF from all def-use/use-def chains, etc. */
983 df_ref_remove (df_ref ref)
988 fprintf (dump_file, "removing ref ");
989 df_ref_debug (ref, dump_file);
993 if (DF_REF_REG_DEF_P (ref))
995 if (DF_REF_IS_ARTIFICIAL (ref))
997 struct df_scan_bb_info *bb_info
998 = df_scan_get_bb_info (DF_REF_BBNO (ref));
999 df_ref_compress_rec (&bb_info->artificial_defs, ref);
1003 unsigned int uid = DF_REF_INSN_UID (ref);
1004 struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
1005 df_ref_compress_rec (&insn_rec->defs, ref);
1010 if (DF_REF_IS_ARTIFICIAL (ref))
1012 struct df_scan_bb_info *bb_info
1013 = df_scan_get_bb_info (DF_REF_BBNO (ref));
1014 df_ref_compress_rec (&bb_info->artificial_uses, ref);
1018 unsigned int uid = DF_REF_INSN_UID (ref);
1019 struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
1021 if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
1022 df_ref_compress_rec (&insn_rec->eq_uses, ref);
1024 df_ref_compress_rec (&insn_rec->uses, ref);
1028 /* By deleting the ref directly, df_insn_rescan my not find any
1029 differences even though the block will have changed. So we need
1030 to mark the block dirty ourselves. */
1031 df_set_bb_dirty (DF_REF_BB (ref));
1032 df_reg_chain_unlink (ref);
1036 /* Create the insn record for INSN. If there was one there, zero it
1039 struct df_insn_info *
1040 df_insn_create_insn_record (rtx insn)
1042 struct df_scan_problem_data *problem_data
1043 = (struct df_scan_problem_data *) df_scan->problem_data;
1044 struct df_insn_info *insn_rec;
1046 df_grow_insn_info ();
1047 insn_rec = DF_INSN_INFO_GET (insn);
1050 insn_rec = (struct df_insn_info *) pool_alloc (problem_data->insn_pool);
1051 DF_INSN_INFO_SET (insn, insn_rec);
1053 memset (insn_rec, 0, sizeof (struct df_insn_info));
1054 insn_rec->insn = insn;
1059 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
1062 df_ref_chain_delete_du_chain (df_ref *ref_rec)
1066 df_ref ref = *ref_rec;
1067 /* CHAIN is allocated by DF_CHAIN. So make sure to
1068 pass df_scan instance for the problem. */
1069 if (DF_REF_CHAIN (ref))
1070 df_chain_unlink (ref);
1076 /* Delete all refs in the ref chain. */
1079 df_ref_chain_delete (df_ref *ref_rec)
1081 df_ref *start = ref_rec;
1084 df_reg_chain_unlink (*ref_rec);
1088 /* If the list is empty, it has a special shared element that is not
1095 /* Delete the hardreg chain. */
1098 df_mw_hardreg_chain_delete (struct df_mw_hardreg **hardregs)
1100 struct df_scan_problem_data *problem_data;
1105 problem_data = (struct df_scan_problem_data *) df_scan->problem_data;
1109 pool_free (problem_data->mw_reg_pool, *hardregs);
1115 /* Delete all of the refs information from INSN. BB must be passed in
1116 except when called from df_process_deferred_rescans to mark the block
1120 df_insn_delete (basic_block bb, unsigned int uid)
1122 struct df_insn_info *insn_info = NULL;
1126 df_grow_bb_info (df_scan);
1127 df_grow_reg_info ();
1129 /* The block must be marked as dirty now, rather than later as in
1130 df_insn_rescan and df_notes_rescan because it may not be there at
1131 rescanning time and the mark would blow up. */
1133 df_set_bb_dirty (bb);
1135 insn_info = DF_INSN_UID_SAFE_GET (uid);
1137 /* The client has deferred rescanning. */
1138 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1142 bitmap_clear_bit (df->insns_to_rescan, uid);
1143 bitmap_clear_bit (df->insns_to_notes_rescan, uid);
1144 bitmap_set_bit (df->insns_to_delete, uid);
1147 fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
1152 fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
1154 bitmap_clear_bit (df->insns_to_delete, uid);
1155 bitmap_clear_bit (df->insns_to_rescan, uid);
1156 bitmap_clear_bit (df->insns_to_notes_rescan, uid);
1159 struct df_scan_problem_data *problem_data
1160 = (struct df_scan_problem_data *) df_scan->problem_data;
1162 /* In general, notes do not have the insn_info fields
1163 initialized. However, combine deletes insns by changing them
1164 to notes. How clever. So we cannot just check if it is a
1165 valid insn before short circuiting this code, we need to see
1166 if we actually initialized it. */
1167 if (insn_info->defs)
1169 df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1173 df_ref_chain_delete_du_chain (insn_info->defs);
1174 df_ref_chain_delete_du_chain (insn_info->uses);
1175 df_ref_chain_delete_du_chain (insn_info->eq_uses);
1178 df_ref_chain_delete (insn_info->defs);
1179 df_ref_chain_delete (insn_info->uses);
1180 df_ref_chain_delete (insn_info->eq_uses);
1182 pool_free (problem_data->insn_pool, insn_info);
1183 DF_INSN_UID_SET (uid, NULL);
1188 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1191 df_free_collection_rec (struct df_collection_rec *collection_rec)
1193 struct df_scan_problem_data *problem_data
1194 = (struct df_scan_problem_data *) df_scan->problem_data;
1196 struct df_mw_hardreg **mw;
1198 if (collection_rec->def_vec)
1199 for (ref = collection_rec->def_vec; *ref; ref++)
1201 if (collection_rec->use_vec)
1202 for (ref = collection_rec->use_vec; *ref; ref++)
1204 if (collection_rec->eq_use_vec)
1205 for (ref = collection_rec->eq_use_vec; *ref; ref++)
1207 if (collection_rec->mw_vec)
1208 for (mw = collection_rec->mw_vec; *mw; mw++)
1209 pool_free (problem_data->mw_reg_pool, *mw);
1213 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1216 df_insn_rescan (rtx insn)
1218 unsigned int uid = INSN_UID (insn);
1219 struct df_insn_info *insn_info = NULL;
1220 basic_block bb = BLOCK_FOR_INSN (insn);
1221 struct df_collection_rec collection_rec;
1222 collection_rec.def_vec = XALLOCAVEC (df_ref, 1000);
1223 collection_rec.use_vec = XALLOCAVEC (df_ref, 1000);
1224 collection_rec.eq_use_vec = XALLOCAVEC (df_ref, 1000);
1225 collection_rec.mw_vec = XALLOCAVEC (struct df_mw_hardreg *, 100);
1227 if ((!df) || (!INSN_P (insn)))
1233 fprintf (dump_file, "no bb for insn with uid = %d.\n", uid);
1237 /* The client has disabled rescanning and plans to do it itself. */
1238 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1241 df_grow_bb_info (df_scan);
1242 df_grow_reg_info ();
1244 insn_info = DF_INSN_UID_SAFE_GET (uid);
1246 /* The client has deferred rescanning. */
1247 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1251 insn_info = df_insn_create_insn_record (insn);
1252 insn_info->defs = df_null_ref_rec;
1253 insn_info->uses = df_null_ref_rec;
1254 insn_info->eq_uses = df_null_ref_rec;
1255 insn_info->mw_hardregs = df_null_mw_rec;
1258 fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid);
1260 bitmap_clear_bit (df->insns_to_delete, uid);
1261 bitmap_clear_bit (df->insns_to_notes_rescan, uid);
1262 bitmap_set_bit (df->insns_to_rescan, INSN_UID (insn));
1266 bitmap_clear_bit (df->insns_to_delete, uid);
1267 bitmap_clear_bit (df->insns_to_rescan, uid);
1268 bitmap_clear_bit (df->insns_to_notes_rescan, uid);
1271 bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false);
1272 /* If there's no change, return false. */
1275 df_free_collection_rec (&collection_rec);
1277 fprintf (dump_file, "verify found no changes in insn with uid = %d.\n", uid);
1281 fprintf (dump_file, "rescanning insn with uid = %d.\n", uid);
1283 /* There's change - we need to delete the existing info. */
1284 df_insn_delete (NULL, uid);
1285 df_insn_create_insn_record (insn);
1289 struct df_insn_info *insn_info = df_insn_create_insn_record (insn);
1290 df_insn_refs_collect (&collection_rec, bb, insn_info);
1292 fprintf (dump_file, "scanning new insn with uid = %d.\n", uid);
1295 df_refs_add_to_chains (&collection_rec, bb, insn);
1296 df_set_bb_dirty (bb);
1301 /* Rescan all of the insns in the function. Note that the artificial
1302 uses and defs are not touched. This function will destroy def-se
1303 or use-def chains. */
1306 df_insn_rescan_all (void)
1308 bool no_insn_rescan = false;
1309 bool defer_insn_rescan = false;
1313 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
1315 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1317 df_clear_flags (DF_NO_INSN_RESCAN);
1318 no_insn_rescan = true;
1321 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1323 df_clear_flags (DF_DEFER_INSN_RESCAN);
1324 defer_insn_rescan = true;
1327 bitmap_copy (tmp, df->insns_to_delete);
1328 EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
1330 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1332 df_insn_delete (NULL, uid);
1336 bitmap_clear (df->insns_to_delete);
1337 bitmap_clear (df->insns_to_rescan);
1338 bitmap_clear (df->insns_to_notes_rescan);
1343 FOR_BB_INSNS (bb, insn)
1345 df_insn_rescan (insn);
1350 df_set_flags (DF_NO_INSN_RESCAN);
1351 if (defer_insn_rescan)
1352 df_set_flags (DF_DEFER_INSN_RESCAN);
1356 /* Process all of the deferred rescans or deletions. */
1359 df_process_deferred_rescans (void)
1361 bool no_insn_rescan = false;
1362 bool defer_insn_rescan = false;
1365 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
1367 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1369 df_clear_flags (DF_NO_INSN_RESCAN);
1370 no_insn_rescan = true;
1373 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1375 df_clear_flags (DF_DEFER_INSN_RESCAN);
1376 defer_insn_rescan = true;
1380 fprintf (dump_file, "starting the processing of deferred insns\n");
1382 bitmap_copy (tmp, df->insns_to_delete);
1383 EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
1385 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1387 df_insn_delete (NULL, uid);
1390 bitmap_copy (tmp, df->insns_to_rescan);
1391 EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
1393 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1395 df_insn_rescan (insn_info->insn);
1398 bitmap_copy (tmp, df->insns_to_notes_rescan);
1399 EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
1401 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1403 df_notes_rescan (insn_info->insn);
1407 fprintf (dump_file, "ending the processing of deferred insns\n");
1410 bitmap_clear (df->insns_to_delete);
1411 bitmap_clear (df->insns_to_rescan);
1412 bitmap_clear (df->insns_to_notes_rescan);
1415 df_set_flags (DF_NO_INSN_RESCAN);
1416 if (defer_insn_rescan)
1417 df_set_flags (DF_DEFER_INSN_RESCAN);
1419 /* If someone changed regs_ever_live during this pass, fix up the
1420 entry and exit blocks. */
1421 if (df->redo_entry_and_exit)
1423 df_update_entry_exit_and_calls ();
1424 df->redo_entry_and_exit = false;
1429 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1430 the uses if INCLUDE_USES. Include the eq_uses if
1434 df_count_refs (bool include_defs, bool include_uses,
1435 bool include_eq_uses)
1439 unsigned int m = df->regs_inited;
1441 for (regno = 0; regno < m; regno++)
1444 size += DF_REG_DEF_COUNT (regno);
1446 size += DF_REG_USE_COUNT (regno);
1447 if (include_eq_uses)
1448 size += DF_REG_EQ_USE_COUNT (regno);
1454 /* Take build ref table for either the uses or defs from the reg-use
1455 or reg-def chains. This version processes the refs in reg order
1456 which is likely to be best if processing the whole function. */
1459 df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info,
1462 bool include_eq_uses)
1464 unsigned int m = df->regs_inited;
1466 unsigned int offset = 0;
1469 if (df->changeable_flags & DF_NO_HARD_REGS)
1471 start = FIRST_PSEUDO_REGISTER;
1472 memset (ref_info->begin, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1473 memset (ref_info->count, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1478 ref_info->total_size
1479 = df_count_refs (include_defs, include_uses, include_eq_uses);
1481 df_check_and_grow_ref_info (ref_info, 1);
1483 for (regno = start; regno < m; regno++)
1486 ref_info->begin[regno] = offset;
1489 df_ref ref = DF_REG_DEF_CHAIN (regno);
1492 ref_info->refs[offset] = ref;
1493 DF_REF_ID (ref) = offset++;
1495 ref = DF_REF_NEXT_REG (ref);
1496 gcc_assert (offset < ref_info->refs_size);
1501 df_ref ref = DF_REG_USE_CHAIN (regno);
1504 ref_info->refs[offset] = ref;
1505 DF_REF_ID (ref) = offset++;
1507 ref = DF_REF_NEXT_REG (ref);
1508 gcc_assert (offset < ref_info->refs_size);
1511 if (include_eq_uses)
1513 df_ref ref = DF_REG_EQ_USE_CHAIN (regno);
1516 ref_info->refs[offset] = ref;
1517 DF_REF_ID (ref) = offset++;
1519 ref = DF_REF_NEXT_REG (ref);
1520 gcc_assert (offset < ref_info->refs_size);
1523 ref_info->count[regno] = count;
1526 /* The bitmap size is not decremented when refs are deleted. So
1527 reset it now that we have squished out all of the empty
1529 ref_info->table_size = offset;
1533 /* Take build ref table for either the uses or defs from the reg-use
1534 or reg-def chains. This version processes the refs in insn order
1535 which is likely to be best if processing some segment of the
1539 df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
1542 bool include_eq_uses)
1545 unsigned int bb_index;
1546 unsigned int m = df->regs_inited;
1547 unsigned int offset = 0;
1550 = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
1552 memset (ref_info->begin, 0, sizeof (int) * df->regs_inited);
1553 memset (ref_info->count, 0, sizeof (int) * df->regs_inited);
1555 ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1556 df_check_and_grow_ref_info (ref_info, 1);
1558 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1560 basic_block bb = BASIC_BLOCK (bb_index);
1565 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1567 unsigned int regno = DF_REF_REGNO (*ref_rec);
1568 ref_info->count[regno]++;
1571 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1573 unsigned int regno = DF_REF_REGNO (*ref_rec);
1574 ref_info->count[regno]++;
1577 FOR_BB_INSNS (bb, insn)
1581 unsigned int uid = INSN_UID (insn);
1584 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1586 unsigned int regno = DF_REF_REGNO (*ref_rec);
1587 ref_info->count[regno]++;
1590 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1592 unsigned int regno = DF_REF_REGNO (*ref_rec);
1593 ref_info->count[regno]++;
1595 if (include_eq_uses)
1596 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1598 unsigned int regno = DF_REF_REGNO (*ref_rec);
1599 ref_info->count[regno]++;
1605 for (r = start; r < m; r++)
1607 ref_info->begin[r] = offset;
1608 offset += ref_info->count[r];
1609 ref_info->count[r] = 0;
1612 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1614 basic_block bb = BASIC_BLOCK (bb_index);
1619 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1621 df_ref ref = *ref_rec;
1622 unsigned int regno = DF_REF_REGNO (ref);
1626 = ref_info->begin[regno] + ref_info->count[regno]++;
1627 DF_REF_ID (ref) = id;
1628 ref_info->refs[id] = ref;
1632 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1634 df_ref ref = *ref_rec;
1635 unsigned int regno = DF_REF_REGNO (ref);
1639 = ref_info->begin[regno] + ref_info->count[regno]++;
1640 DF_REF_ID (ref) = id;
1641 ref_info->refs[id] = ref;
1645 FOR_BB_INSNS (bb, insn)
1649 unsigned int uid = INSN_UID (insn);
1652 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1654 df_ref ref = *ref_rec;
1655 unsigned int regno = DF_REF_REGNO (ref);
1659 = ref_info->begin[regno] + ref_info->count[regno]++;
1660 DF_REF_ID (ref) = id;
1661 ref_info->refs[id] = ref;
1665 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1667 df_ref ref = *ref_rec;
1668 unsigned int regno = DF_REF_REGNO (ref);
1672 = ref_info->begin[regno] + ref_info->count[regno]++;
1673 DF_REF_ID (ref) = id;
1674 ref_info->refs[id] = ref;
1677 if (include_eq_uses)
1678 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1680 df_ref ref = *ref_rec;
1681 unsigned int regno = DF_REF_REGNO (ref);
1685 = ref_info->begin[regno] + ref_info->count[regno]++;
1686 DF_REF_ID (ref) = id;
1687 ref_info->refs[id] = ref;
1694 /* The bitmap size is not decremented when refs are deleted. So
1695 reset it now that we have squished out all of the empty
1698 ref_info->table_size = offset;
1701 /* Take build ref table for either the uses or defs from the reg-use
1702 or reg-def chains. */
1705 df_reorganize_refs_by_reg (struct df_ref_info *ref_info,
1708 bool include_eq_uses)
1710 if (df->analyze_subset)
1711 df_reorganize_refs_by_reg_by_insn (ref_info, include_defs,
1712 include_uses, include_eq_uses);
1714 df_reorganize_refs_by_reg_by_reg (ref_info, include_defs,
1715 include_uses, include_eq_uses);
1719 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1721 df_add_refs_to_table (unsigned int offset,
1722 struct df_ref_info *ref_info,
1727 df_ref ref = *ref_vec;
1728 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
1729 || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER))
1731 ref_info->refs[offset] = ref;
1732 DF_REF_ID (*ref_vec) = offset++;
1740 /* Count the number of refs in all of the insns of BB. Include the
1741 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1742 eq_uses if INCLUDE_EQ_USES. */
1745 df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset,
1746 struct df_ref_info *ref_info,
1747 bool include_defs, bool include_uses,
1748 bool include_eq_uses)
1753 offset = df_add_refs_to_table (offset, ref_info,
1754 df_get_artificial_defs (bb->index));
1756 offset = df_add_refs_to_table (offset, ref_info,
1757 df_get_artificial_uses (bb->index));
1759 FOR_BB_INSNS (bb, insn)
1762 unsigned int uid = INSN_UID (insn);
1764 offset = df_add_refs_to_table (offset, ref_info,
1765 DF_INSN_UID_DEFS (uid));
1767 offset = df_add_refs_to_table (offset, ref_info,
1768 DF_INSN_UID_USES (uid));
1769 if (include_eq_uses)
1770 offset = df_add_refs_to_table (offset, ref_info,
1771 DF_INSN_UID_EQ_USES (uid));
1777 /* Organize the refs by insn into the table in REF_INFO. If
1778 blocks_to_analyze is defined, use that set, otherwise the entire
1779 program. Include the defs if INCLUDE_DEFS. Include the uses if
1780 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1783 df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
1784 bool include_defs, bool include_uses,
1785 bool include_eq_uses)
1788 unsigned int offset = 0;
1790 ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1791 df_check_and_grow_ref_info (ref_info, 1);
1792 if (df->blocks_to_analyze)
1797 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
1799 offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index), offset, ref_info,
1800 include_defs, include_uses,
1804 ref_info->table_size = offset;
1809 offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info,
1810 include_defs, include_uses,
1812 ref_info->table_size = offset;
1817 /* If the use refs in DF are not organized, reorganize them. */
1820 df_maybe_reorganize_use_refs (enum df_ref_order order)
1822 if (order == df->use_info.ref_order)
1827 case DF_REF_ORDER_BY_REG:
1828 df_reorganize_refs_by_reg (&df->use_info, false, true, false);
1831 case DF_REF_ORDER_BY_REG_WITH_NOTES:
1832 df_reorganize_refs_by_reg (&df->use_info, false, true, true);
1835 case DF_REF_ORDER_BY_INSN:
1836 df_reorganize_refs_by_insn (&df->use_info, false, true, false);
1839 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1840 df_reorganize_refs_by_insn (&df->use_info, false, true, true);
1843 case DF_REF_ORDER_NO_TABLE:
1844 free (df->use_info.refs);
1845 df->use_info.refs = NULL;
1846 df->use_info.refs_size = 0;
1849 case DF_REF_ORDER_UNORDERED:
1850 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1855 df->use_info.ref_order = order;
1859 /* If the def refs in DF are not organized, reorganize them. */
1862 df_maybe_reorganize_def_refs (enum df_ref_order order)
1864 if (order == df->def_info.ref_order)
1869 case DF_REF_ORDER_BY_REG:
1870 df_reorganize_refs_by_reg (&df->def_info, true, false, false);
1873 case DF_REF_ORDER_BY_INSN:
1874 df_reorganize_refs_by_insn (&df->def_info, true, false, false);
1877 case DF_REF_ORDER_NO_TABLE:
1878 free (df->def_info.refs);
1879 df->def_info.refs = NULL;
1880 df->def_info.refs_size = 0;
1883 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1884 case DF_REF_ORDER_BY_REG_WITH_NOTES:
1885 case DF_REF_ORDER_UNORDERED:
1886 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1891 df->def_info.ref_order = order;
1895 /* Change all of the basic block references in INSN to use the insn's
1896 current basic block. This function is called from routines that move
1897 instructions from one block to another. */
1900 df_insn_change_bb (rtx insn, basic_block new_bb)
1902 basic_block old_bb = BLOCK_FOR_INSN (insn);
1903 struct df_insn_info *insn_info;
1904 unsigned int uid = INSN_UID (insn);
1906 if (old_bb == new_bb)
1909 set_block_for_insn (insn, new_bb);
1915 fprintf (dump_file, "changing bb of uid %d\n", uid);
1917 insn_info = DF_INSN_UID_SAFE_GET (uid);
1918 if (insn_info == NULL)
1921 fprintf (dump_file, " unscanned insn\n");
1922 df_insn_rescan (insn);
1929 df_set_bb_dirty (new_bb);
1933 fprintf (dump_file, " from %d to %d\n",
1934 old_bb->index, new_bb->index);
1935 df_set_bb_dirty (old_bb);
1939 fprintf (dump_file, " to %d\n", new_bb->index);
1943 /* Helper function for df_ref_change_reg_with_loc. */
1946 df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df,
1947 struct df_reg_info *new_df,
1948 int new_regno, rtx loc)
1950 df_ref the_ref = old_df->reg_chain;
1954 if ((!DF_REF_IS_ARTIFICIAL (the_ref))
1955 && (DF_REF_LOC (the_ref))
1956 && (*DF_REF_LOC (the_ref) == loc))
1958 df_ref next_ref = DF_REF_NEXT_REG (the_ref);
1959 df_ref prev_ref = DF_REF_PREV_REG (the_ref);
1960 df_ref *ref_vec, *ref_vec_t;
1961 struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref);
1962 unsigned int count = 0;
1964 DF_REF_REGNO (the_ref) = new_regno;
1965 DF_REF_REG (the_ref) = regno_reg_rtx[new_regno];
1967 /* Pull the_ref out of the old regno chain. */
1969 DF_REF_NEXT_REG (prev_ref) = next_ref;
1971 old_df->reg_chain = next_ref;
1973 DF_REF_PREV_REG (next_ref) = prev_ref;
1976 /* Put the ref into the new regno chain. */
1977 DF_REF_PREV_REG (the_ref) = NULL;
1978 DF_REF_NEXT_REG (the_ref) = new_df->reg_chain;
1979 if (new_df->reg_chain)
1980 DF_REF_PREV_REG (new_df->reg_chain) = the_ref;
1981 new_df->reg_chain = the_ref;
1983 df_set_bb_dirty (DF_REF_BB (the_ref));
1985 /* Need to sort the record again that the ref was in because
1986 the regno is a sorting key. First, find the right
1988 if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE)
1989 ref_vec = insn_info->eq_uses;
1991 ref_vec = insn_info->uses;
1993 fprintf (dump_file, "changing reg in insn %d\n",
1994 DF_REF_INSN_UID (the_ref));
1996 ref_vec_t = ref_vec;
1998 /* Find the length. */
2004 qsort (ref_vec, count, sizeof (df_ref ), df_ref_compare);
2009 the_ref = DF_REF_NEXT_REG (the_ref);
2014 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2015 NEW_REGNO. Refs that do not match LOC are not changed which means
2016 that artificial refs are not changed since they have no loc. This
2017 call is to support the SET_REGNO macro. */
2020 df_ref_change_reg_with_loc (int old_regno, int new_regno, rtx loc)
2022 if ((!df) || (old_regno == -1) || (old_regno == new_regno))
2025 df_grow_reg_info ();
2027 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno),
2028 DF_REG_DEF_GET (new_regno), new_regno, loc);
2029 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno),
2030 DF_REG_USE_GET (new_regno), new_regno, loc);
2031 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno),
2032 DF_REG_EQ_USE_GET (new_regno), new_regno, loc);
2036 /* Delete the mw_hardregs that point into the eq_notes. */
2039 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info)
2041 struct df_mw_hardreg **mw_vec = insn_info->mw_hardregs;
2042 unsigned int deleted = 0;
2043 unsigned int count = 0;
2044 struct df_scan_problem_data *problem_data
2045 = (struct df_scan_problem_data *) df_scan->problem_data;
2052 if ((*mw_vec)->flags & DF_REF_IN_NOTE)
2054 struct df_mw_hardreg **temp_vec = mw_vec;
2056 pool_free (problem_data->mw_reg_pool, *mw_vec);
2058 /* Shove the remaining ones down one to fill the gap. While
2059 this looks n**2, it is highly unusual to have any mw regs
2060 in eq_notes and the chances of more than one are almost
2064 *temp_vec = *(temp_vec + 1);
2078 df_scan_free_mws_vec (insn_info->mw_hardregs);
2079 insn_info->mw_hardregs = df_null_mw_rec;
2086 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2089 df_notes_rescan (rtx insn)
2091 struct df_insn_info *insn_info;
2092 unsigned int uid = INSN_UID (insn);
2097 /* The client has disabled rescanning and plans to do it itself. */
2098 if (df->changeable_flags & DF_NO_INSN_RESCAN)
2101 /* Do nothing if the insn hasn't been emitted yet. */
2102 if (!BLOCK_FOR_INSN (insn))
2105 df_grow_bb_info (df_scan);
2106 df_grow_reg_info ();
2108 insn_info = DF_INSN_UID_SAFE_GET (INSN_UID(insn));
2110 /* The client has deferred rescanning. */
2111 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
2115 insn_info = df_insn_create_insn_record (insn);
2116 insn_info->defs = df_null_ref_rec;
2117 insn_info->uses = df_null_ref_rec;
2118 insn_info->eq_uses = df_null_ref_rec;
2119 insn_info->mw_hardregs = df_null_mw_rec;
2122 bitmap_clear_bit (df->insns_to_delete, uid);
2123 /* If the insn is set to be rescanned, it does not need to also
2124 be notes rescanned. */
2125 if (!bitmap_bit_p (df->insns_to_rescan, uid))
2126 bitmap_set_bit (df->insns_to_notes_rescan, INSN_UID (insn));
2130 bitmap_clear_bit (df->insns_to_delete, uid);
2131 bitmap_clear_bit (df->insns_to_notes_rescan, uid);
2135 basic_block bb = BLOCK_FOR_INSN (insn);
2137 struct df_collection_rec collection_rec;
2138 unsigned int num_deleted;
2140 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
2141 collection_rec.eq_use_vec = XALLOCAVEC (df_ref, 1000);
2142 collection_rec.mw_vec = XALLOCAVEC (struct df_mw_hardreg *, 1000);
2144 num_deleted = df_mw_hardreg_chain_delete_eq_uses (insn_info);
2145 df_ref_chain_delete (insn_info->eq_uses);
2146 insn_info->eq_uses = NULL;
2148 /* Process REG_EQUIV/REG_EQUAL notes */
2149 for (note = REG_NOTES (insn); note;
2150 note = XEXP (note, 1))
2152 switch (REG_NOTE_KIND (note))
2156 df_uses_record (DF_REF_REGULAR, &collection_rec,
2157 &XEXP (note, 0), DF_REF_REG_USE,
2158 bb, insn_info, DF_REF_IN_NOTE, -1, -1, 0);
2164 /* Find some place to put any new mw_hardregs. */
2165 df_canonize_collection_rec (&collection_rec);
2166 if (collection_rec.next_mw)
2168 unsigned int count = 0;
2169 struct df_mw_hardreg **mw_rec = insn_info->mw_hardregs;
2178 /* Append to the end of the existing record after
2179 expanding it if necessary. */
2180 if (collection_rec.next_mw > num_deleted)
2182 insn_info->mw_hardregs =
2183 XRESIZEVEC (struct df_mw_hardreg *,
2184 insn_info->mw_hardregs,
2185 count + 1 + collection_rec.next_mw);
2187 memcpy (&insn_info->mw_hardregs[count], collection_rec.mw_vec,
2188 (collection_rec.next_mw + 1) * sizeof (struct df_mw_hardreg *));
2189 qsort (insn_info->mw_hardregs, count + collection_rec.next_mw,
2190 sizeof (struct df_mw_hardreg *), df_mw_compare);
2194 /* No vector there. */
2195 insn_info->mw_hardregs
2196 = XNEWVEC (struct df_mw_hardreg*,
2197 count + 1 + collection_rec.next_mw);
2198 memcpy (insn_info->mw_hardregs, collection_rec.mw_vec,
2199 (collection_rec.next_mw + 1) * sizeof (struct df_mw_hardreg *));
2202 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2204 collection_rec.mw_vec = NULL;
2205 collection_rec.next_mw = 0;
2206 df_refs_add_to_chains (&collection_rec, bb, insn);
2209 df_insn_rescan (insn);
2214 /*----------------------------------------------------------------------------
2215 Hard core instruction scanning code. No external interfaces here,
2216 just a lot of routines that look inside insns.
2217 ----------------------------------------------------------------------------*/
2220 /* Return true if the contents of two df_ref's are identical.
2221 It ignores DF_REF_MARKER. */
2224 df_ref_equal_p (df_ref ref1, df_ref ref2)
2232 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)
2233 || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)
2234 || DF_REF_REG (ref1) != DF_REF_REG (ref2)
2235 || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)
2236 || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))
2237 != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)))
2238 || DF_REF_BB (ref1) != DF_REF_BB (ref2)
2239 || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2))
2242 switch (DF_REF_CLASS (ref1))
2244 case DF_REF_ARTIFICIAL:
2248 case DF_REF_EXTRACT:
2249 if ((DF_REF_EXTRACT_OFFSET (ref1) != DF_REF_EXTRACT_OFFSET (ref2))
2250 || (DF_REF_EXTRACT_WIDTH (ref1) != DF_REF_EXTRACT_WIDTH (ref2))
2251 || (DF_REF_EXTRACT_MODE (ref1) != DF_REF_EXTRACT_MODE (ref2)))
2255 case DF_REF_REGULAR:
2256 return DF_REF_LOC (ref1) == DF_REF_LOC (ref2);
2265 /* Compare REF1 and REF2 for sorting. This is only called from places
2266 where all of the refs are of the same type, in the same insn, and
2267 have the same bb. So these fields are not checked. */
2270 df_ref_compare (const void *r1, const void *r2)
2272 const df_ref ref1 = *(const df_ref *)r1;
2273 const df_ref ref2 = *(const df_ref *)r2;
2278 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
2279 return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
2281 if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
2282 return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
2284 if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
2285 return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
2287 if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
2288 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2290 /* Cannot look at the LOC field on artificial refs. */
2291 if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
2292 && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
2293 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2295 if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
2297 /* If two refs are identical except that one of them has is from
2298 a mw and one is not, we need to have the one with the mw
2300 if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) ==
2301 DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG))
2302 return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2);
2303 else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG))
2309 /* The classes are the same at this point so it is safe to only look
2311 if (DF_REF_CLASS (ref1) == DF_REF_EXTRACT)
2313 if (DF_REF_EXTRACT_OFFSET (ref1) != DF_REF_EXTRACT_OFFSET (ref2))
2314 return DF_REF_EXTRACT_OFFSET (ref1) - DF_REF_EXTRACT_OFFSET (ref2);
2315 if (DF_REF_EXTRACT_WIDTH (ref1) != DF_REF_EXTRACT_WIDTH (ref2))
2316 return DF_REF_EXTRACT_WIDTH (ref1) - DF_REF_EXTRACT_WIDTH (ref2);
2317 if (DF_REF_EXTRACT_MODE (ref1) != DF_REF_EXTRACT_MODE (ref2))
2318 return DF_REF_EXTRACT_MODE (ref1) - DF_REF_EXTRACT_MODE (ref2);
2324 df_swap_refs (df_ref *ref_vec, int i, int j)
2326 df_ref tmp = ref_vec[i];
2327 ref_vec[i] = ref_vec[j];
2331 /* Sort and compress a set of refs. */
2334 df_sort_and_compress_refs (df_ref *ref_vec, unsigned int count)
2337 unsigned int dist = 0;
2339 ref_vec[count] = NULL;
2340 /* If there are 1 or 0 elements, there is nothing to do. */
2343 else if (count == 2)
2345 if (df_ref_compare (&ref_vec[0], &ref_vec[1]) > 0)
2346 df_swap_refs (ref_vec, 0, 1);
2350 for (i = 0; i < count - 1; i++)
2351 if (df_ref_compare (&ref_vec[i], &ref_vec[i+1]) >= 0)
2353 /* If the array is already strictly ordered,
2354 which is the most common case for large COUNT case
2355 (which happens for CALL INSNs),
2356 no need to sort and filter out duplicate.
2357 Simply return the count.
2358 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2359 of DF_REF_COMPARE. */
2362 qsort (ref_vec, count, sizeof (df_ref), df_ref_compare);
2365 for (i=0; i<count-dist; i++)
2367 /* Find the next ref that is not equal to the current ref. */
2368 while (df_ref_equal_p (ref_vec[i], ref_vec[i + dist + 1]))
2370 df_free_ref (ref_vec[i + dist + 1]);
2373 /* Copy it down to the next position. */
2375 ref_vec[i+1] = ref_vec[i + dist + 1];
2379 ref_vec[count] = NULL;
2384 /* Return true if the contents of two df_ref's are identical.
2385 It ignores DF_REF_MARKER. */
2388 df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2)
2392 return (mw1 == mw2) ||
2393 (mw1->mw_reg == mw2->mw_reg
2394 && mw1->type == mw2->type
2395 && mw1->flags == mw2->flags
2396 && mw1->start_regno == mw2->start_regno
2397 && mw1->end_regno == mw2->end_regno);
2401 /* Compare MW1 and MW2 for sorting. */
2404 df_mw_compare (const void *m1, const void *m2)
2406 const struct df_mw_hardreg *const mw1 = *(const struct df_mw_hardreg *const*)m1;
2407 const struct df_mw_hardreg *const mw2 = *(const struct df_mw_hardreg *const*)m2;
2412 if (mw1->type != mw2->type)
2413 return mw1->type - mw2->type;
2415 if (mw1->flags != mw2->flags)
2416 return mw1->flags - mw2->flags;
2418 if (mw1->start_regno != mw2->start_regno)
2419 return mw1->start_regno - mw2->start_regno;
2421 if (mw1->end_regno != mw2->end_regno)
2422 return mw1->end_regno - mw2->end_regno;
2424 if (mw1->mw_reg != mw2->mw_reg)
2425 return mw1->mw_order - mw2->mw_order;
2431 /* Sort and compress a set of refs. */
2434 df_sort_and_compress_mws (struct df_mw_hardreg **mw_vec, unsigned int count)
2436 struct df_scan_problem_data *problem_data
2437 = (struct df_scan_problem_data *) df_scan->problem_data;
2439 unsigned int dist = 0;
2440 mw_vec[count] = NULL;
2444 else if (count == 2)
2446 if (df_mw_compare (&mw_vec[0], &mw_vec[1]) > 0)
2448 struct df_mw_hardreg *tmp = mw_vec[0];
2449 mw_vec[0] = mw_vec[1];
2454 qsort (mw_vec, count, sizeof (struct df_mw_hardreg *), df_mw_compare);
2456 for (i=0; i<count-dist; i++)
2458 /* Find the next ref that is not equal to the current ref. */
2459 while (df_mw_equal_p (mw_vec[i], mw_vec[i + dist + 1]))
2461 pool_free (problem_data->mw_reg_pool, mw_vec[i + dist + 1]);
2464 /* Copy it down to the next position. */
2466 mw_vec[i+1] = mw_vec[i + dist + 1];
2470 mw_vec[count] = NULL;
2475 /* Sort and remove duplicates from the COLLECTION_REC. */
2478 df_canonize_collection_rec (struct df_collection_rec *collection_rec)
2480 if (collection_rec->def_vec)
2481 collection_rec->next_def
2482 = df_sort_and_compress_refs (collection_rec->def_vec,
2483 collection_rec->next_def);
2484 if (collection_rec->use_vec)
2485 collection_rec->next_use
2486 = df_sort_and_compress_refs (collection_rec->use_vec,
2487 collection_rec->next_use);
2488 if (collection_rec->eq_use_vec)
2489 collection_rec->next_eq_use
2490 = df_sort_and_compress_refs (collection_rec->eq_use_vec,
2491 collection_rec->next_eq_use);
2492 if (collection_rec->mw_vec)
2493 collection_rec->next_mw
2494 = df_sort_and_compress_mws (collection_rec->mw_vec,
2495 collection_rec->next_mw);
2499 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2502 df_install_ref (df_ref this_ref,
2503 struct df_reg_info *reg_info,
2504 struct df_ref_info *ref_info,
2507 unsigned int regno = DF_REF_REGNO (this_ref);
2508 /* Add the ref to the reg_{def,use,eq_use} chain. */
2509 df_ref head = reg_info->reg_chain;
2511 reg_info->reg_chain = this_ref;
2514 if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE))
2516 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
2517 df->hard_regs_live_count[regno]++;
2520 gcc_assert (DF_REF_NEXT_REG (this_ref) == NULL);
2521 gcc_assert (DF_REF_PREV_REG (this_ref) == NULL);
2523 DF_REF_NEXT_REG (this_ref) = head;
2525 /* We cannot actually link to the head of the chain. */
2526 DF_REF_PREV_REG (this_ref) = NULL;
2529 DF_REF_PREV_REG (head) = this_ref;
2533 gcc_assert (ref_info->ref_order != DF_REF_ORDER_NO_TABLE);
2534 df_check_and_grow_ref_info (ref_info, 1);
2535 DF_REF_ID (this_ref) = ref_info->table_size;
2536 /* Add the ref to the big array of defs. */
2537 ref_info->refs[ref_info->table_size] = this_ref;
2538 ref_info->table_size++;
2541 DF_REF_ID (this_ref) = -1;
2543 ref_info->total_size++;
2547 /* This function takes one of the groups of refs (defs, uses or
2548 eq_uses) and installs the entire group into the insn. It also adds
2549 each of these refs into the appropriate chains. */
2552 df_install_refs (basic_block bb,
2553 df_ref *old_vec, unsigned int count,
2554 struct df_reg_info **reg_info,
2555 struct df_ref_info *ref_info,
2561 df_ref *new_vec = XNEWVEC (df_ref, count + 1);
2564 switch (ref_info->ref_order)
2566 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
2567 case DF_REF_ORDER_BY_REG_WITH_NOTES:
2568 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
2569 ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
2570 add_to_table = true;
2572 case DF_REF_ORDER_UNORDERED:
2573 case DF_REF_ORDER_BY_REG:
2574 case DF_REF_ORDER_BY_INSN:
2575 ref_info->ref_order = DF_REF_ORDER_UNORDERED;
2576 add_to_table = !is_notes;
2579 add_to_table = false;
2583 /* Do not add if ref is not in the right blocks. */
2584 if (add_to_table && df->analyze_subset)
2585 add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
2587 for (i = 0; i < count; i++)
2589 df_ref this_ref = old_vec[i];
2590 new_vec[i] = this_ref;
2591 df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)],
2592 ref_info, add_to_table);
2595 new_vec[count] = NULL;
2599 return df_null_ref_rec;
2603 /* This function takes the mws installs the entire group into the
2606 static struct df_mw_hardreg **
2607 df_install_mws (struct df_mw_hardreg **old_vec, unsigned int count)
2611 struct df_mw_hardreg **new_vec
2612 = XNEWVEC (struct df_mw_hardreg*, count + 1);
2613 memcpy (new_vec, old_vec,
2614 sizeof (struct df_mw_hardreg*) * (count + 1));
2618 return df_null_mw_rec;
2622 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2623 chains and update other necessary information. */
2626 df_refs_add_to_chains (struct df_collection_rec *collection_rec,
2627 basic_block bb, rtx insn)
2631 struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn);
2632 /* If there is a vector in the collection rec, add it to the
2633 insn. A null rec is a signal that the caller will handle the
2635 if (collection_rec->def_vec)
2637 df_scan_free_ref_vec (insn_rec->defs);
2639 = df_install_refs (bb, collection_rec->def_vec,
2640 collection_rec->next_def,
2642 &df->def_info, false);
2644 if (collection_rec->use_vec)
2646 df_scan_free_ref_vec (insn_rec->uses);
2648 = df_install_refs (bb, collection_rec->use_vec,
2649 collection_rec->next_use,
2651 &df->use_info, false);
2653 if (collection_rec->eq_use_vec)
2655 df_scan_free_ref_vec (insn_rec->eq_uses);
2657 = df_install_refs (bb, collection_rec->eq_use_vec,
2658 collection_rec->next_eq_use,
2660 &df->use_info, true);
2662 if (collection_rec->mw_vec)
2664 df_scan_free_mws_vec (insn_rec->mw_hardregs);
2665 insn_rec->mw_hardregs
2666 = df_install_mws (collection_rec->mw_vec,
2667 collection_rec->next_mw);
2672 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
2674 df_scan_free_ref_vec (bb_info->artificial_defs);
2675 bb_info->artificial_defs
2676 = df_install_refs (bb, collection_rec->def_vec,
2677 collection_rec->next_def,
2679 &df->def_info, false);
2680 df_scan_free_ref_vec (bb_info->artificial_uses);
2681 bb_info->artificial_uses
2682 = df_install_refs (bb, collection_rec->use_vec,
2683 collection_rec->next_use,
2685 &df->use_info, false);
2690 /* Allocate a ref and initialize its fields.
2692 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2693 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the fields
2694 if they were constants. Otherwise they should be -1 if those flags
2698 df_ref_create_structure (enum df_ref_class cl,
2699 struct df_collection_rec *collection_rec,
2701 basic_block bb, struct df_insn_info *info,
2702 enum df_ref_type ref_type,
2703 enum df_ref_flags ref_flags,
2704 int width, int offset, enum machine_mode mode)
2706 df_ref this_ref = NULL;
2707 int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2708 struct df_scan_problem_data *problem_data
2709 = (struct df_scan_problem_data *) df_scan->problem_data;
2714 this_ref = (df_ref) pool_alloc (problem_data->ref_base_pool);
2715 gcc_assert (loc == NULL);
2718 case DF_REF_ARTIFICIAL:
2719 this_ref = (df_ref) pool_alloc (problem_data->ref_artificial_pool);
2720 this_ref->artificial_ref.bb = bb;
2721 gcc_assert (loc == NULL);
2724 case DF_REF_REGULAR:
2725 this_ref = (df_ref) pool_alloc (problem_data->ref_regular_pool);
2726 this_ref->regular_ref.loc = loc;
2730 case DF_REF_EXTRACT:
2731 this_ref = (df_ref) pool_alloc (problem_data->ref_extract_pool);
2732 DF_REF_EXTRACT_WIDTH (this_ref) = width;
2733 DF_REF_EXTRACT_OFFSET (this_ref) = offset;
2734 DF_REF_EXTRACT_MODE (this_ref) = mode;
2735 this_ref->regular_ref.loc = loc;
2740 DF_REF_CLASS (this_ref) = cl;
2741 DF_REF_ID (this_ref) = -1;
2742 DF_REF_REG (this_ref) = reg;
2743 DF_REF_REGNO (this_ref) = regno;
2744 DF_REF_TYPE (this_ref) = ref_type;
2745 DF_REF_INSN_INFO (this_ref) = info;
2746 DF_REF_CHAIN (this_ref) = NULL;
2747 DF_REF_FLAGS (this_ref) = ref_flags;
2748 DF_REF_NEXT_REG (this_ref) = NULL;
2749 DF_REF_PREV_REG (this_ref) = NULL;
2750 DF_REF_ORDER (this_ref) = df->ref_order++;
2752 /* We need to clear this bit because fwprop, and in the future
2753 possibly other optimizations sometimes create new refs using ond
2754 refs as the model. */
2755 DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE);
2757 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2758 if ((regno < FIRST_PSEUDO_REGISTER)
2759 && (!DF_REF_IS_ARTIFICIAL (this_ref)))
2761 if (DF_REF_REG_DEF_P (this_ref))
2763 if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER))
2764 DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2766 else if (!(TEST_HARD_REG_BIT (elim_reg_set, regno)
2767 && (regno == FRAME_POINTER_REGNUM
2768 || regno == ARG_POINTER_REGNUM)))
2769 DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2774 if (DF_REF_REG_DEF_P (this_ref))
2775 collection_rec->def_vec[collection_rec->next_def++] = this_ref;
2776 else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE)
2777 collection_rec->eq_use_vec[collection_rec->next_eq_use++] = this_ref;
2779 collection_rec->use_vec[collection_rec->next_use++] = this_ref;
2786 /* Create new references of type DF_REF_TYPE for each part of register REG
2787 at address LOC within INSN of BB.
2789 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2790 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
2791 fields if they were constants. Otherwise they should be -1 if
2792 those flags were set. */
2796 df_ref_record (enum df_ref_class cl,
2797 struct df_collection_rec *collection_rec,
2799 basic_block bb, struct df_insn_info *insn_info,
2800 enum df_ref_type ref_type,
2801 enum df_ref_flags ref_flags,
2802 int width, int offset, enum machine_mode mode)
2806 gcc_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
2808 regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2809 if (regno < FIRST_PSEUDO_REGISTER)
2811 struct df_mw_hardreg *hardreg = NULL;
2812 struct df_scan_problem_data *problem_data
2813 = (struct df_scan_problem_data *) df_scan->problem_data;
2815 unsigned int endregno;
2818 if (GET_CODE (reg) == SUBREG)
2820 regno += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
2821 SUBREG_BYTE (reg), GET_MODE (reg));
2822 endregno = regno + subreg_nregs (reg);
2825 endregno = END_HARD_REGNO (reg);
2827 /* If this is a multiword hardreg, we create some extra
2828 datastructures that will enable us to easily build REG_DEAD
2829 and REG_UNUSED notes. */
2830 if ((endregno != regno + 1) && insn_info)
2832 /* Sets to a subreg of a multiword register are partial.
2833 Sets to a non-subreg of a multiword register are not. */
2834 if (GET_CODE (reg) == SUBREG)
2835 ref_flags |= DF_REF_PARTIAL;
2836 ref_flags |= DF_REF_MW_HARDREG;
2838 hardreg = (struct df_mw_hardreg *) pool_alloc (problem_data->mw_reg_pool);
2839 hardreg->type = ref_type;
2840 hardreg->flags = ref_flags;
2841 hardreg->mw_reg = reg;
2842 hardreg->start_regno = regno;
2843 hardreg->end_regno = endregno - 1;
2844 hardreg->mw_order = df->ref_order++;
2845 collection_rec->mw_vec[collection_rec->next_mw++] = hardreg;
2848 for (i = regno; i < endregno; i++)
2850 ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc,
2851 bb, insn_info, ref_type, ref_flags,
2852 width, offset, mode);
2854 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i);
2859 df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info,
2860 ref_type, ref_flags, width, offset, mode);
2865 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2866 covered by the outer mode is smaller than that covered by the inner mode,
2867 is a read-modify-write operation.
2868 This function returns true iff the SUBREG X is such a SUBREG. */
2871 df_read_modify_subreg_p (rtx x)
2873 unsigned int isize, osize;
2874 if (GET_CODE (x) != SUBREG)
2876 isize = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
2877 osize = GET_MODE_SIZE (GET_MODE (x));
2878 return isize > osize
2879 && isize > REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x)));
2883 /* Process all the registers defined in the rtx, X.
2884 Autoincrement/decrement definitions will be picked up by
2888 df_def_record_1 (struct df_collection_rec *collection_rec,
2889 rtx x, basic_block bb, struct df_insn_info *insn_info,
2890 enum df_ref_flags flags)
2896 enum machine_mode mode = 0;
2897 enum df_ref_class cl = DF_REF_REGULAR;
2899 /* We may recursively call ourselves on EXPR_LIST when dealing with PARALLEL
2901 if (GET_CODE (x) == EXPR_LIST || GET_CODE (x) == CLOBBER)
2904 loc = &SET_DEST (x);
2907 /* It is legal to have a set destination be a parallel. */
2908 if (GET_CODE (dst) == PARALLEL)
2912 for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
2914 rtx temp = XVECEXP (dst, 0, i);
2915 if (GET_CODE (temp) == EXPR_LIST || GET_CODE (temp) == CLOBBER
2916 || GET_CODE (temp) == SET)
2917 df_def_record_1 (collection_rec,
2918 temp, bb, insn_info,
2919 GET_CODE (temp) == CLOBBER
2920 ? flags | DF_REF_MUST_CLOBBER : flags);
2925 if (GET_CODE (dst) == STRICT_LOW_PART)
2927 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;
2929 loc = &XEXP (dst, 0);
2933 if (GET_CODE (dst) == ZERO_EXTRACT)
2935 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;
2937 if (GET_CODE (XEXP (dst, 1)) == CONST_INT
2938 && GET_CODE (XEXP (dst, 2)) == CONST_INT)
2940 width = INTVAL (XEXP (dst, 1));
2941 offset = INTVAL (XEXP (dst, 2));
2942 mode = GET_MODE (dst);
2943 cl = DF_REF_EXTRACT;
2946 loc = &XEXP (dst, 0);
2950 /* At this point if we do not have a reg or a subreg, just return. */
2953 df_ref_record (cl, collection_rec,
2954 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags,
2955 width, offset, mode);
2957 /* We want to keep sp alive everywhere - by making all
2958 writes to sp also use of sp. */
2959 if (REGNO (dst) == STACK_POINTER_REGNUM)
2960 df_ref_record (DF_REF_BASE, collection_rec,
2961 dst, NULL, bb, insn_info, DF_REF_REG_USE, flags,
2962 width, offset, mode);
2964 else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
2966 if (df_read_modify_subreg_p (dst))
2967 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;
2969 flags |= DF_REF_SUBREG;
2971 df_ref_record (cl, collection_rec,
2972 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags,
2973 width, offset, mode);
2978 /* Process all the registers defined in the pattern rtx, X. */
2981 df_defs_record (struct df_collection_rec *collection_rec,
2982 rtx x, basic_block bb, struct df_insn_info *insn_info,
2983 enum df_ref_flags flags)
2985 RTX_CODE code = GET_CODE (x);
2987 if (code == SET || code == CLOBBER)
2989 /* Mark the single def within the pattern. */
2990 enum df_ref_flags clobber_flags = flags;
2991 clobber_flags |= (code == CLOBBER) ? DF_REF_MUST_CLOBBER : 0;
2992 df_def_record_1 (collection_rec, x, bb, insn_info, clobber_flags);
2994 else if (code == COND_EXEC)
2996 df_defs_record (collection_rec, COND_EXEC_CODE (x),
2997 bb, insn_info, DF_REF_CONDITIONAL);
2999 else if (code == PARALLEL)
3003 /* Mark the multiple defs within the pattern. */
3004 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
3005 df_defs_record (collection_rec, XVECEXP (x, 0, i), bb, insn_info, flags);
3010 /* Process all the registers used in the rtx at address LOC.
3012 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
3013 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
3014 fields if they were constants. Otherwise they should be -1 if
3015 those flags were set. */
3018 df_uses_record (enum df_ref_class cl, struct df_collection_rec *collection_rec,
3019 rtx *loc, enum df_ref_type ref_type,
3020 basic_block bb, struct df_insn_info *insn_info,
3021 enum df_ref_flags flags,
3022 int width, int offset, enum machine_mode mode)
3031 code = GET_CODE (x);
3048 /* If we are clobbering a MEM, mark any registers inside the address
3050 if (MEM_P (XEXP (x, 0)))
3051 df_uses_record (cl, collection_rec,
3052 &XEXP (XEXP (x, 0), 0),
3053 DF_REF_REG_MEM_STORE,
3055 flags, width, offset, mode);
3057 /* If we're clobbering a REG then we have a def so ignore. */
3061 df_uses_record (cl, collection_rec,
3062 &XEXP (x, 0), DF_REF_REG_MEM_LOAD,
3063 bb, insn_info, flags & DF_REF_IN_NOTE,
3064 width, offset, mode);
3068 /* While we're here, optimize this case. */
3069 flags |= DF_REF_PARTIAL;
3070 /* In case the SUBREG is not of a REG, do not optimize. */
3071 if (!REG_P (SUBREG_REG (x)))
3073 loc = &SUBREG_REG (x);
3074 df_uses_record (cl, collection_rec, loc, ref_type, bb, insn_info, flags,
3075 width, offset, mode);
3078 /* ... Fall through ... */
3081 df_ref_record (cl, collection_rec,
3082 x, loc, bb, insn_info,
3084 width, offset, mode);
3090 /* If the parameters to the zero or sign extract are
3091 constants, strip them off and recurse, otherwise there is
3092 no information that we can gain from this operation. */
3093 if (GET_CODE (XEXP (x, 1)) == CONST_INT
3094 && GET_CODE (XEXP (x, 2)) == CONST_INT)
3096 width = INTVAL (XEXP (x, 1));
3097 offset = INTVAL (XEXP (x, 2));
3098 mode = GET_MODE (x);
3100 if (code == ZERO_EXTRACT)
3101 flags |= DF_REF_ZERO_EXTRACT;
3103 flags |= DF_REF_SIGN_EXTRACT;
3105 df_uses_record (DF_REF_EXTRACT, collection_rec,
3106 &XEXP (x, 0), ref_type, bb, insn_info, flags,
3107 width, offset, mode);
3115 rtx dst = SET_DEST (x);
3116 gcc_assert (!(flags & DF_REF_IN_NOTE));
3117 df_uses_record (cl, collection_rec,
3118 &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags,
3119 width, offset, mode);
3121 switch (GET_CODE (dst))
3124 if (df_read_modify_subreg_p (dst))
3126 df_uses_record (cl, collection_rec, &SUBREG_REG (dst),
3127 DF_REF_REG_USE, bb, insn_info,
3128 flags | DF_REF_READ_WRITE | DF_REF_SUBREG,
3129 width, offset, mode);
3140 df_uses_record (cl, collection_rec, &XEXP (dst, 0),
3141 DF_REF_REG_MEM_STORE, bb, insn_info, flags,
3142 width, offset, mode);
3144 case STRICT_LOW_PART:
3146 rtx *temp = &XEXP (dst, 0);
3147 /* A strict_low_part uses the whole REG and not just the
3149 dst = XEXP (dst, 0);
3150 df_uses_record (cl, collection_rec,
3151 (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
3152 DF_REF_REG_USE, bb, insn_info,
3153 DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART,
3154 width, offset, mode);
3159 if (GET_CODE (XEXP (dst, 1)) == CONST_INT
3160 && GET_CODE (XEXP (dst, 2)) == CONST_INT)
3162 width = INTVAL (XEXP (dst, 1));
3163 offset = INTVAL (XEXP (dst, 2));
3164 mode = GET_MODE (dst);
3165 df_uses_record (DF_REF_EXTRACT, collection_rec, &XEXP (dst, 0),
3166 DF_REF_REG_USE, bb, insn_info,
3167 DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT,
3168 width, offset, mode);
3172 df_uses_record (cl, collection_rec, &XEXP (dst, 1),
3173 DF_REF_REG_USE, bb, insn_info, flags,
3174 width, offset, mode);
3175 df_uses_record (cl, collection_rec, &XEXP (dst, 2),
3176 DF_REF_REG_USE, bb, insn_info, flags,
3177 width, offset, mode);
3178 df_uses_record (cl, collection_rec, &XEXP (dst, 0),
3179 DF_REF_REG_USE, bb, insn_info,
3180 DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT,
3181 width, offset, mode);
3197 case UNSPEC_VOLATILE:
3201 /* Traditional and volatile asm instructions must be
3202 considered to use and clobber all hard registers, all
3203 pseudo-registers and all of memory. So must TRAP_IF and
3204 UNSPEC_VOLATILE operations.
3206 Consider for instance a volatile asm that changes the fpu
3207 rounding mode. An insn should not be moved across this
3208 even if it only uses pseudo-regs because it might give an
3209 incorrectly rounded result.
3211 However, flow.c's liveness computation did *not* do this,
3212 giving the reasoning as " ?!? Unfortunately, marking all
3213 hard registers as live causes massive problems for the
3214 register allocator and marking all pseudos as live creates
3215 mountains of uninitialized variable warnings."
3217 In order to maintain the status quo with regard to liveness
3218 and uses, we do what flow.c did and just mark any regs we
3219 can find in ASM_OPERANDS as used. In global asm insns are
3220 scanned and regs_asm_clobbered is filled out.
3222 For all ASM_OPERANDS, we must traverse the vector of input
3223 operands. We can not just fall through here since then we
3224 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3225 which do not indicate traditional asms unlike their normal
3227 if (code == ASM_OPERANDS)
3231 for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
3232 df_uses_record (cl, collection_rec, &ASM_OPERANDS_INPUT (x, j),
3233 DF_REF_REG_USE, bb, insn_info, flags,
3234 width, offset, mode);
3246 /* Catch the def of the register being modified. */
3247 df_ref_record (cl, collection_rec, XEXP (x, 0), &XEXP (x, 0),
3250 flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY,
3251 width, offset, mode);
3253 /* ... Fall through to handle uses ... */
3259 /* Recursively scan the operands of this expression. */
3261 const char *fmt = GET_RTX_FORMAT (code);
3264 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3268 /* Tail recursive case: save a function call level. */
3274 df_uses_record (cl, collection_rec, &XEXP (x, i), ref_type,
3275 bb, insn_info, flags,
3276 width, offset, mode);
3278 else if (fmt[i] == 'E')
3281 for (j = 0; j < XVECLEN (x, i); j++)
3282 df_uses_record (cl, collection_rec,
3283 &XVECEXP (x, i, j), ref_type,
3284 bb, insn_info, flags,
3285 width, offset, mode);
3294 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3297 df_get_conditional_uses (struct df_collection_rec *collection_rec)
3300 for (i = 0; i < collection_rec->next_def; i++)
3302 df_ref ref = collection_rec->def_vec[i];
3303 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL))
3307 enum machine_mode mode = 0;
3310 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_SIGN_EXTRACT | DF_REF_ZERO_EXTRACT))
3312 width = DF_REF_EXTRACT_WIDTH (ref);
3313 offset = DF_REF_EXTRACT_OFFSET (ref);
3314 mode = DF_REF_EXTRACT_MODE (ref);
3317 use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref),
3318 DF_REF_LOC (ref), DF_REF_BB (ref),
3319 DF_REF_INSN_INFO (ref), DF_REF_REG_USE,
3320 DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL,
3321 width, offset, mode);
3322 DF_REF_REGNO (use) = DF_REF_REGNO (ref);
3328 /* Get call's extra defs and uses. */
3331 df_get_call_refs (struct df_collection_rec * collection_rec,
3333 struct df_insn_info *insn_info,
3334 enum df_ref_flags flags)
3339 bool is_sibling_call;
3341 bitmap defs_generated = BITMAP_ALLOC (&df_bitmap_obstack);
3343 /* Do not generate clobbers for registers that are the result of the
3344 call. This causes ordering problems in the chain building code
3345 depending on which def is seen first. */
3346 for (i=0; i<collection_rec->next_def; i++)
3348 df_ref def = collection_rec->def_vec[i];
3349 bitmap_set_bit (defs_generated, DF_REF_REGNO (def));
3352 /* Record the registers used to pass arguments, and explicitly
3353 noted as clobbered. */
3354 for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note;
3355 note = XEXP (note, 1))
3357 if (GET_CODE (XEXP (note, 0)) == USE)
3358 df_uses_record (DF_REF_REGULAR, collection_rec, &XEXP (XEXP (note, 0), 0),
3359 DF_REF_REG_USE, bb, insn_info, flags, -1, -1, 0);
3360 else if (GET_CODE (XEXP (note, 0)) == CLOBBER)
3362 if (REG_P (XEXP (XEXP (note, 0), 0)))
3364 unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
3365 if (!bitmap_bit_p (defs_generated, regno))
3366 df_defs_record (collection_rec, XEXP (note, 0), bb,
3370 df_uses_record (DF_REF_REGULAR, collection_rec, &XEXP (note, 0),
3371 DF_REF_REG_USE, bb, insn_info, flags, -1, -1, 0);
3375 /* The stack ptr is used (honorarily) by a CALL insn. */
3376 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[STACK_POINTER_REGNUM],
3377 NULL, bb, insn_info, DF_REF_REG_USE,
3378 DF_REF_CALL_STACK_USAGE | flags,
3381 /* Calls may also reference any of the global registers,
3382 so they are recorded as used. */
3383 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3386 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3387 NULL, bb, insn_info, DF_REF_REG_USE, flags, -1, -1, 0);
3388 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3389 NULL, bb, insn_info, DF_REF_REG_DEF, flags, -1, -1, 0);
3392 is_sibling_call = SIBLING_CALL_P (insn_info->insn);
3393 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, ui, bi)
3395 if (!global_regs[ui]
3396 && (!bitmap_bit_p (defs_generated, ui))
3397 && (!is_sibling_call
3398 || !bitmap_bit_p (df->exit_block_uses, ui)
3399 || refers_to_regno_p (ui, ui+1,
3400 crtl->return_rtx, NULL)))
3401 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[ui],
3402 NULL, bb, insn_info, DF_REF_REG_DEF,
3403 DF_REF_MAY_CLOBBER | flags,
3407 BITMAP_FREE (defs_generated);
3411 /* Collect all refs in the INSN. This function is free of any
3412 side-effect - it will create and return a lists of df_ref's in the
3413 COLLECTION_REC without putting those refs into existing ref chains
3417 df_insn_refs_collect (struct df_collection_rec* collection_rec,
3418 basic_block bb, struct df_insn_info *insn_info)
3421 bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC);
3423 /* Clear out the collection record. */
3424 collection_rec->next_def = 0;
3425 collection_rec->next_use = 0;
3426 collection_rec->next_eq_use = 0;
3427 collection_rec->next_mw = 0;
3429 /* Record register defs. */
3430 df_defs_record (collection_rec, PATTERN (insn_info->insn), bb, insn_info, 0);
3432 /* Process REG_EQUIV/REG_EQUAL notes. */
3433 for (note = REG_NOTES (insn_info->insn); note;
3434 note = XEXP (note, 1))
3436 switch (REG_NOTE_KIND (note))
3440 df_uses_record (DF_REF_REGULAR, collection_rec,
3441 &XEXP (note, 0), DF_REF_REG_USE,
3442 bb, insn_info, DF_REF_IN_NOTE, -1, -1, 0);
3444 case REG_NON_LOCAL_GOTO:
3445 /* The frame ptr is used by a non-local goto. */
3446 df_ref_record (DF_REF_BASE, collection_rec,
3447 regno_reg_rtx[FRAME_POINTER_REGNUM],
3448 NULL, bb, insn_info,
3449 DF_REF_REG_USE, 0, -1, -1, 0);
3450 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3451 df_ref_record (DF_REF_BASE, collection_rec,
3452 regno_reg_rtx[HARD_FRAME_POINTER_REGNUM],
3453 NULL, bb, insn_info,
3454 DF_REF_REG_USE, 0, -1, -1, 0);
3462 if (CALL_P (insn_info->insn))
3463 df_get_call_refs (collection_rec, bb, insn_info,
3464 (is_cond_exec) ? DF_REF_CONDITIONAL : 0);
3466 /* Record the register uses. */
3467 df_uses_record (DF_REF_REGULAR, collection_rec,
3468 &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0,
3471 /* DF_REF_CONDITIONAL needs corresponding USES. */
3473 df_get_conditional_uses (collection_rec);
3475 df_canonize_collection_rec (collection_rec);
3478 /* Recompute the luids for the insns in BB. */
3481 df_recompute_luids (basic_block bb)
3486 df_grow_insn_info ();
3488 /* Scan the block an insn at a time from beginning to end. */
3489 FOR_BB_INSNS (bb, insn)
3491 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3492 /* Inserting labels does not always trigger the incremental
3496 gcc_assert (!INSN_P (insn));
3497 insn_info = df_insn_create_insn_record (insn);
3500 DF_INSN_INFO_LUID (insn_info) = luid;
3507 /* Returns true if the function entry needs to
3508 define the static chain register. */
3511 df_need_static_chain_reg (struct function *fun)
3513 tree fun_context = decl_function_context (fun->decl);
3515 && DECL_NO_STATIC_CHAIN (fun_context) == false;
3519 /* Collect all artificial refs at the block level for BB and add them
3520 to COLLECTION_REC. */
3523 df_bb_refs_collect (struct df_collection_rec *collection_rec, basic_block bb)
3525 collection_rec->next_def = 0;
3526 collection_rec->next_use = 0;
3527 collection_rec->next_eq_use = 0;
3528 collection_rec->next_mw = 0;
3530 if (bb->index == ENTRY_BLOCK)
3532 df_entry_block_defs_collect (collection_rec, df->entry_block_defs);
3535 else if (bb->index == EXIT_BLOCK)
3537 df_exit_block_uses_collect (collection_rec, df->exit_block_uses);
3541 #ifdef EH_RETURN_DATA_REGNO
3542 if (bb_has_eh_pred (bb))
3545 /* Mark the registers that will contain data for the handler. */
3548 unsigned regno = EH_RETURN_DATA_REGNO (i);
3549 if (regno == INVALID_REGNUM)
3551 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3552 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP, -1, -1, 0);
3559 if (bb_has_eh_pred (bb))
3562 /* This code is putting in an artificial ref for the use at the
3563 TOP of the block that receives the exception. It is too
3564 cumbersome to actually put the ref on the edge. We could
3565 either model this at the top of the receiver block or the
3566 bottom of the sender block.
3568 The bottom of the sender block is problematic because not all
3569 out-edges of a block are eh-edges. However, it is true
3570 that all edges into a block are either eh-edges or none of
3571 them are eh-edges. Thus, we can model this at the top of the
3572 eh-receiver for all of the edges at once. */
3573 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3575 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
3576 bb, NULL, DF_REF_REG_USE, DF_REF_AT_TOP, -1, -1, 0);
3580 /* Add the hard_frame_pointer if this block is the target of a
3582 if (bb->flags & BB_NON_LOCAL_GOTO_TARGET)
3583 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL,
3584 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP, -1, -1, 0);
3586 /* Add the artificial uses. */
3587 if (bb->index >= NUM_FIXED_BLOCKS)
3591 bitmap au = bb_has_eh_pred (bb)
3592 ? df->eh_block_artificial_uses
3593 : df->regular_block_artificial_uses;
3595 EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi)
3597 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3598 bb, NULL, DF_REF_REG_USE, 0, -1, -1, 0);
3602 df_canonize_collection_rec (collection_rec);
3606 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3609 df_bb_refs_record (int bb_index, bool scan_insns)
3611 basic_block bb = BASIC_BLOCK (bb_index);
3614 struct df_scan_bb_info *bb_info;
3615 struct df_collection_rec collection_rec;
3616 collection_rec.def_vec = XALLOCAVEC (df_ref, 1000);
3617 collection_rec.use_vec = XALLOCAVEC (df_ref, 1000);
3618 collection_rec.eq_use_vec = XALLOCAVEC (df_ref, 1000);
3619 collection_rec.mw_vec = XALLOCAVEC (struct df_mw_hardreg *, 100);
3624 bb_info = df_scan_get_bb_info (bb_index);
3626 /* Need to make sure that there is a record in the basic block info. */
3629 bb_info = (struct df_scan_bb_info *) pool_alloc (df_scan->block_pool);
3630 df_scan_set_bb_info (bb_index, bb_info);
3631 bb_info->artificial_defs = NULL;
3632 bb_info->artificial_uses = NULL;
3636 /* Scan the block an insn at a time from beginning to end. */
3637 FOR_BB_INSNS (bb, insn)
3639 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3640 gcc_assert (!insn_info);
3642 insn_info = df_insn_create_insn_record (insn);
3645 /* Record refs within INSN. */
3646 DF_INSN_INFO_LUID (insn_info) = luid++;
3647 df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn));
3648 df_refs_add_to_chains (&collection_rec, bb, insn);
3650 DF_INSN_INFO_LUID (insn_info) = luid;
3653 /* Other block level artificial refs */
3654 df_bb_refs_collect (&collection_rec, bb);
3655 df_refs_add_to_chains (&collection_rec, bb, NULL);
3657 /* Now that the block has been processed, set the block as dirty so
3658 LR and LIVE will get it processed. */
3659 df_set_bb_dirty (bb);
3663 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3667 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses)
3669 bitmap_clear (regular_block_artificial_uses);
3671 if (reload_completed)
3673 if (frame_pointer_needed)
3674 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3677 /* Before reload, there are a few registers that must be forced
3678 live everywhere -- which might not already be the case for
3679 blocks within infinite loops. */
3681 /* Any reference to any pseudo before reload is a potential
3682 reference of the frame pointer. */
3683 bitmap_set_bit (regular_block_artificial_uses, FRAME_POINTER_REGNUM);
3685 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3686 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3689 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3690 /* Pseudos with argument area equivalences may require
3691 reloading via the argument pointer. */
3692 if (fixed_regs[ARG_POINTER_REGNUM])
3693 bitmap_set_bit (regular_block_artificial_uses, ARG_POINTER_REGNUM);
3696 /* Any constant, or pseudo with constant equivalences, may
3697 require reloading from memory using the pic register. */
3698 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3699 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3700 bitmap_set_bit (regular_block_artificial_uses, PIC_OFFSET_TABLE_REGNUM);
3702 /* The all-important stack pointer must always be live. */
3703 bitmap_set_bit (regular_block_artificial_uses, STACK_POINTER_REGNUM);
3707 /* Get the artificial use set for an eh block. */
3710 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses)
3712 bitmap_clear (eh_block_artificial_uses);
3714 /* The following code (down thru the arg_pointer setting APPEARS
3715 to be necessary because there is nothing that actually
3716 describes what the exception handling code may actually need
3718 if (reload_completed)
3720 if (frame_pointer_needed)
3722 bitmap_set_bit (eh_block_artificial_uses, FRAME_POINTER_REGNUM);
3723 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3724 bitmap_set_bit (eh_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3727 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3728 if (fixed_regs[ARG_POINTER_REGNUM])
3729 bitmap_set_bit (eh_block_artificial_uses, ARG_POINTER_REGNUM);
3736 /*----------------------------------------------------------------------------
3737 Specialized hard register scanning functions.
3738 ----------------------------------------------------------------------------*/
3741 /* Mark a register in SET. Hard registers in large modes get all
3742 of their component registers set as well. */
3745 df_mark_reg (rtx reg, void *vset)
3747 bitmap set = (bitmap) vset;
3748 int regno = REGNO (reg);
3750 gcc_assert (GET_MODE (reg) != BLKmode);
3752 bitmap_set_bit (set, regno);
3753 if (regno < FIRST_PSEUDO_REGISTER)
3755 int n = hard_regno_nregs[regno][GET_MODE (reg)];
3757 bitmap_set_bit (set, regno + n);
3762 /* Set the bit for regs that are considered being defined at the entry. */
3765 df_get_entry_block_def_set (bitmap entry_block_defs)
3770 bitmap_clear (entry_block_defs);
3772 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3774 if (FUNCTION_ARG_REGNO_P (i))
3775 #ifdef INCOMING_REGNO
3776 bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
3778 bitmap_set_bit (entry_block_defs, i);
3782 /* The always important stack pointer. */
3783 bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM);
3785 /* Once the prologue has been generated, all of these registers
3786 should just show up in the first regular block. */
3787 if (HAVE_prologue && epilogue_completed)
3789 /* Defs for the callee saved registers are inserted so that the
3790 pushes have some defining location. */
3791 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3792 if ((call_used_regs[i] == 0) && (df_regs_ever_live_p (i)))
3793 bitmap_set_bit (entry_block_defs, i);
3797 /* If STATIC_CHAIN_INCOMING_REGNUM == STATIC_CHAIN_REGNUM
3798 only STATIC_CHAIN_REGNUM is defined. If they are different,
3799 we only care about the STATIC_CHAIN_INCOMING_REGNUM. */
3800 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3801 bitmap_set_bit (entry_block_defs, STATIC_CHAIN_INCOMING_REGNUM);
3803 #ifdef STATIC_CHAIN_REGNUM
3804 bitmap_set_bit (entry_block_defs, STATIC_CHAIN_REGNUM);
3809 r = targetm.calls.struct_value_rtx (current_function_decl, true);
3811 bitmap_set_bit (entry_block_defs, REGNO (r));
3813 if ((!reload_completed) || frame_pointer_needed)
3815 /* Any reference to any pseudo before reload is a potential
3816 reference of the frame pointer. */
3817 bitmap_set_bit (entry_block_defs, FRAME_POINTER_REGNUM);
3818 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3819 /* If they are different, also mark the hard frame pointer as live. */
3820 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
3821 bitmap_set_bit (entry_block_defs, HARD_FRAME_POINTER_REGNUM);
3825 /* These registers are live everywhere. */
3826 if (!reload_completed)
3829 /* The ia-64, the only machine that uses this, does not define these
3830 until after reload. */
3831 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3834 bitmap_set_bit (entry_block_defs, i);
3838 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3839 /* Pseudos with argument area equivalences may require
3840 reloading via the argument pointer. */
3841 if (fixed_regs[ARG_POINTER_REGNUM])
3842 bitmap_set_bit (entry_block_defs, ARG_POINTER_REGNUM);
3845 #ifdef PIC_OFFSET_TABLE_REGNUM
3846 /* Any constant, or pseudo with constant equivalences, may
3847 require reloading from memory using the pic register. */
3848 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3849 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3850 bitmap_set_bit (entry_block_defs, PIC_OFFSET_TABLE_REGNUM);
3854 #ifdef INCOMING_RETURN_ADDR_RTX
3855 if (REG_P (INCOMING_RETURN_ADDR_RTX))
3856 bitmap_set_bit (entry_block_defs, REGNO (INCOMING_RETURN_ADDR_RTX));
3859 targetm.live_on_entry (entry_block_defs);
3861 /* If the function has an incoming STATIC_CHAIN,
3862 it has to show up in the entry def set. */
3863 if (df_need_static_chain_reg (cfun))
3865 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3866 bitmap_set_bit (entry_block_defs, STATIC_CHAIN_INCOMING_REGNUM);
3868 #ifdef STATIC_CHAIN_REGNUM
3869 bitmap_set_bit (entry_block_defs, STATIC_CHAIN_REGNUM);
3876 /* Return the (conservative) set of hard registers that are defined on
3877 entry to the function.
3878 It uses df->entry_block_defs to determine which register
3879 reference to include. */
3882 df_entry_block_defs_collect (struct df_collection_rec *collection_rec,
3883 bitmap entry_block_defs)
3888 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs, 0, i, bi)
3890 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
3891 ENTRY_BLOCK_PTR, NULL, DF_REF_REG_DEF, 0, -1, -1, 0);
3894 df_canonize_collection_rec (collection_rec);
3898 /* Record the (conservative) set of hard registers that are defined on
3899 entry to the function. */
3902 df_record_entry_block_defs (bitmap entry_block_defs)
3904 struct df_collection_rec collection_rec;
3905 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
3906 collection_rec.def_vec = XALLOCAVEC (df_ref, FIRST_PSEUDO_REGISTER);
3908 df_entry_block_defs_collect (&collection_rec, entry_block_defs);
3910 /* Process bb_refs chain */
3911 df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (ENTRY_BLOCK), NULL);
3915 /* Update the defs in the entry block. */
3918 df_update_entry_block_defs (void)
3920 bitmap refs = BITMAP_ALLOC (&df_bitmap_obstack);
3921 bool changed = false;
3923 df_get_entry_block_def_set (refs);
3924 if (df->entry_block_defs)
3926 if (!bitmap_equal_p (df->entry_block_defs, refs))
3928 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (ENTRY_BLOCK);
3929 df_ref_chain_delete_du_chain (bb_info->artificial_defs);
3930 df_ref_chain_delete (bb_info->artificial_defs);
3931 bb_info->artificial_defs = NULL;
3937 struct df_scan_problem_data *problem_data
3938 = (struct df_scan_problem_data *) df_scan->problem_data;
3939 df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
3945 df_record_entry_block_defs (refs);
3946 bitmap_copy (df->entry_block_defs, refs);
3947 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
3953 /* Set the bit for regs that are considered being used at the exit. */
3956 df_get_exit_block_use_set (bitmap exit_block_uses)
3960 bitmap_clear (exit_block_uses);
3962 /* Stack pointer is always live at the exit. */
3963 bitmap_set_bit (exit_block_uses, STACK_POINTER_REGNUM);
3965 /* Mark the frame pointer if needed at the end of the function.
3966 If we end up eliminating it, it will be removed from the live
3967 list of each basic block by reload. */
3969 if ((!reload_completed) || frame_pointer_needed)
3971 bitmap_set_bit (exit_block_uses, FRAME_POINTER_REGNUM);
3972 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3973 /* If they are different, also mark the hard frame pointer as live. */
3974 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
3975 bitmap_set_bit (exit_block_uses, HARD_FRAME_POINTER_REGNUM);
3979 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3980 /* Many architectures have a GP register even without flag_pic.
3981 Assume the pic register is not in use, or will be handled by
3982 other means, if it is not fixed. */
3983 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3984 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3985 bitmap_set_bit (exit_block_uses, PIC_OFFSET_TABLE_REGNUM);
3988 /* Mark all global registers, and all registers used by the
3989 epilogue as being live at the end of the function since they
3990 may be referenced by our caller. */
3991 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3992 if (global_regs[i] || EPILOGUE_USES (i))
3993 bitmap_set_bit (exit_block_uses, i);
3995 if (HAVE_epilogue && epilogue_completed)
3997 /* Mark all call-saved registers that we actually used. */
3998 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3999 if (df_regs_ever_live_p (i) && !LOCAL_REGNO (i)
4000 && !TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
4001 bitmap_set_bit (exit_block_uses, i);
4004 #ifdef EH_RETURN_DATA_REGNO
4005 /* Mark the registers that will contain data for the handler. */
4006 if (reload_completed && crtl->calls_eh_return)
4009 unsigned regno = EH_RETURN_DATA_REGNO (i);
4010 if (regno == INVALID_REGNUM)
4012 bitmap_set_bit (exit_block_uses, regno);
4016 #ifdef EH_RETURN_STACKADJ_RTX
4017 if ((!HAVE_epilogue || ! epilogue_completed)
4018 && crtl->calls_eh_return)
4020 rtx tmp = EH_RETURN_STACKADJ_RTX;
4021 if (tmp && REG_P (tmp))
4022 df_mark_reg (tmp, exit_block_uses);
4026 #ifdef EH_RETURN_HANDLER_RTX
4027 if ((!HAVE_epilogue || ! epilogue_completed)
4028 && crtl->calls_eh_return)
4030 rtx tmp = EH_RETURN_HANDLER_RTX;
4031 if (tmp && REG_P (tmp))
4032 df_mark_reg (tmp, exit_block_uses);
4036 /* Mark function return value. */
4037 diddle_return_value (df_mark_reg, (void*) exit_block_uses);
4041 /* Return the refs of hard registers that are used in the exit block.
4042 It uses df->exit_block_uses to determine register to include. */
4045 df_exit_block_uses_collect (struct df_collection_rec *collection_rec, bitmap exit_block_uses)
4050 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses, 0, i, bi)
4051 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
4052 EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0, -1, -1, 0);
4054 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4055 /* It is deliberate that this is not put in the exit block uses but
4056 I do not know why. */
4057 if (reload_completed
4058 && !bitmap_bit_p (exit_block_uses, ARG_POINTER_REGNUM)
4059 && bb_has_eh_pred (EXIT_BLOCK_PTR)
4060 && fixed_regs[ARG_POINTER_REGNUM])
4061 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[ARG_POINTER_REGNUM], NULL,
4062 EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0, -1, -1, 0);
4065 df_canonize_collection_rec (collection_rec);
4069 /* Record the set of hard registers that are used in the exit block.
4070 It uses df->exit_block_uses to determine which bit to include. */
4073 df_record_exit_block_uses (bitmap exit_block_uses)
4075 struct df_collection_rec collection_rec;
4076 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
4077 collection_rec.use_vec = XALLOCAVEC (df_ref, FIRST_PSEUDO_REGISTER);
4079 df_exit_block_uses_collect (&collection_rec, exit_block_uses);
4081 /* Process bb_refs chain */
4082 df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (EXIT_BLOCK), NULL);
4086 /* Update the uses in the exit block. */
4089 df_update_exit_block_uses (void)
4091 bitmap refs = BITMAP_ALLOC (&df_bitmap_obstack);
4092 bool changed = false;
4094 df_get_exit_block_use_set (refs);
4095 if (df->exit_block_uses)
4097 if (!bitmap_equal_p (df->exit_block_uses, refs))
4099 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (EXIT_BLOCK);
4100 df_ref_chain_delete_du_chain (bb_info->artificial_uses);
4101 df_ref_chain_delete (bb_info->artificial_uses);
4102 bb_info->artificial_uses = NULL;
4108 struct df_scan_problem_data *problem_data
4109 = (struct df_scan_problem_data *) df_scan->problem_data;
4110 df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
4116 df_record_exit_block_uses (refs);
4117 bitmap_copy (df->exit_block_uses, refs);
4118 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
4123 static bool initialized = false;
4126 /* Initialize some platform specific structures. */
4129 df_hard_reg_init (void)
4132 #ifdef ELIMINABLE_REGS
4133 static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
4138 bitmap_obstack_initialize (&persistent_obstack);
4140 /* Record which registers will be eliminated. We use this in
4142 CLEAR_HARD_REG_SET (elim_reg_set);
4144 #ifdef ELIMINABLE_REGS
4145 for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
4146 SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
4148 SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
4151 df_invalidated_by_call = BITMAP_ALLOC (&persistent_obstack);
4153 /* Inconveniently, this is only readily available in hard reg set
4155 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
4156 if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
4157 bitmap_set_bit (df_invalidated_by_call, i);
4163 /* Recompute the parts of scanning that are based on regs_ever_live
4164 because something changed in that array. */
4167 df_update_entry_exit_and_calls (void)
4171 df_update_entry_block_defs ();
4172 df_update_exit_block_uses ();
4174 /* The call insns need to be rescanned because there may be changes
4175 in the set of registers clobbered across the call. */
4179 FOR_BB_INSNS (bb, insn)
4181 if (INSN_P (insn) && CALL_P (insn))
4182 df_insn_rescan (insn);
4188 /* Return true if hard REG is actually used in the some instruction.
4189 There are a fair number of conditions that affect the setting of
4190 this array. See the comment in df.h for df->hard_regs_live_count
4191 for the conditions that this array is set. */
4194 df_hard_reg_used_p (unsigned int reg)
4197 return df->hard_regs_live_count[reg] != 0;
4201 /* A count of the number of times REG is actually used in the some
4202 instruction. There are a fair number of conditions that affect the
4203 setting of this array. See the comment in df.h for
4204 df->hard_regs_live_count for the conditions that this array is
4209 df_hard_reg_used_count (unsigned int reg)
4212 return df->hard_regs_live_count[reg];
4216 /* Get the value of regs_ever_live[REGNO]. */
4219 df_regs_ever_live_p (unsigned int regno)
4221 return regs_ever_live[regno];
4225 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
4226 to change, schedule that change for the next update. */
4229 df_set_regs_ever_live (unsigned int regno, bool value)
4231 if (regs_ever_live[regno] == value)
4234 regs_ever_live[regno] = value;
4236 df->redo_entry_and_exit = true;
4240 /* Compute "regs_ever_live" information from the underlying df
4241 information. Set the vector to all false if RESET. */
4244 df_compute_regs_ever_live (bool reset)
4247 bool changed = df->redo_entry_and_exit;
4250 memset (regs_ever_live, 0, sizeof (regs_ever_live));
4252 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4253 if ((!regs_ever_live[i]) && df_hard_reg_used_p (i))
4255 regs_ever_live[i] = true;
4259 df_update_entry_exit_and_calls ();
4260 df->redo_entry_and_exit = false;
4264 /*----------------------------------------------------------------------------
4265 Dataflow ref information verification functions.
4267 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4268 df_reg_chain_verify_unmarked (refs)
4269 df_refs_verify (ref*, ref*, bool)
4270 df_mws_verify (mw*, mw*, bool)
4271 df_insn_refs_verify (collection_rec, bb, insn, bool)
4272 df_bb_refs_verify (bb, refs, bool)
4274 df_exit_block_bitmap_verify (bool)
4275 df_entry_block_bitmap_verify (bool)
4277 ----------------------------------------------------------------------------*/
4280 /* Mark all refs in the reg chain. Verify that all of the registers
4281 are in the correct chain. */
4284 df_reg_chain_mark (df_ref refs, unsigned int regno,
4285 bool is_def, bool is_eq_use)
4287 unsigned int count = 0;
4289 for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4291 gcc_assert (!DF_REF_IS_REG_MARKED (ref));
4293 /* If there are no def-use or use-def chains, make sure that all
4294 of the chains are clear. */
4296 gcc_assert (!DF_REF_CHAIN (ref));
4298 /* Check to make sure the ref is in the correct chain. */
4299 gcc_assert (DF_REF_REGNO (ref) == regno);
4301 gcc_assert (DF_REF_REG_DEF_P (ref));
4303 gcc_assert (!DF_REF_REG_DEF_P (ref));
4306 gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE));
4308 gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) == 0);
4310 if (DF_REF_NEXT_REG (ref))
4311 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref)) == ref);
4313 DF_REF_REG_MARK (ref);
4319 /* Verify that all of the registers in the chain are unmarked. */
4322 df_reg_chain_verify_unmarked (df_ref refs)
4325 for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4326 gcc_assert (!DF_REF_IS_REG_MARKED (ref));
4330 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4333 df_refs_verify (df_ref *new_rec, df_ref *old_rec,
4336 while ((*new_rec) && (*old_rec))
4338 if (!df_ref_equal_p (*new_rec, *old_rec))
4346 /* Abort if fail is called from the function level verifier. If
4347 that is the context, mark this reg as being seem. */
4350 gcc_assert (DF_REF_IS_REG_MARKED (*old_rec));
4351 DF_REF_REG_UNMARK (*old_rec);
4359 gcc_assert ((*new_rec == NULL) && (*old_rec == NULL));
4361 return ((*new_rec == NULL) && (*old_rec == NULL));
4366 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4369 df_mws_verify (struct df_mw_hardreg **new_rec, struct df_mw_hardreg **old_rec,
4372 while ((*new_rec) && (*old_rec))
4374 if (!df_mw_equal_p (*new_rec, *old_rec))
4386 gcc_assert ((*new_rec == NULL) && (*old_rec == NULL));
4388 return ((*new_rec == NULL) && (*old_rec == NULL));
4393 /* Return true if the existing insn refs information is complete and
4394 correct. Otherwise (i.e. if there's any missing or extra refs),
4395 return the correct df_ref chain in REFS_RETURN.
4397 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4398 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4399 verification mode instead of the whole function, so unmark
4402 If ABORT_IF_FAIL is set, this function never returns false. */
4405 df_insn_refs_verify (struct df_collection_rec *collection_rec,
4410 bool ret1, ret2, ret3, ret4;
4411 unsigned int uid = INSN_UID (insn);
4412 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
4414 df_insn_refs_collect (collection_rec, bb, insn_info);
4416 if (!DF_INSN_UID_DEFS (uid))
4418 /* The insn_rec was created but it was never filled out. */
4425 /* Unfortunately we cannot opt out early if one of these is not
4426 right because the marks will not get cleared. */
4427 ret1 = df_refs_verify (collection_rec->def_vec, DF_INSN_UID_DEFS (uid),
4429 ret2 = df_refs_verify (collection_rec->use_vec, DF_INSN_UID_USES (uid),
4431 ret3 = df_refs_verify (collection_rec->eq_use_vec, DF_INSN_UID_EQ_USES (uid),
4433 ret4 = df_mws_verify (collection_rec->mw_vec, DF_INSN_UID_MWS (uid),
4435 return (ret1 && ret2 && ret3 && ret4);
4439 /* Return true if all refs in the basic block are correct and complete.
4440 Due to df_ref_chain_verify, it will cause all refs
4441 that are verified to have DF_REF_MARK bit set. */
4444 df_bb_verify (basic_block bb)
4447 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
4448 struct df_collection_rec collection_rec;
4450 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
4451 collection_rec.def_vec = XALLOCAVEC (df_ref, 1000);
4452 collection_rec.use_vec = XALLOCAVEC (df_ref, 1000);
4453 collection_rec.eq_use_vec = XALLOCAVEC (df_ref, 1000);
4454 collection_rec.mw_vec = XALLOCAVEC (struct df_mw_hardreg *, 100);
4456 gcc_assert (bb_info);
4458 /* Scan the block, one insn at a time, from beginning to end. */
4459 FOR_BB_INSNS_REVERSE (bb, insn)
4463 df_insn_refs_verify (&collection_rec, bb, insn, true);
4464 df_free_collection_rec (&collection_rec);
4467 /* Do the artificial defs and uses. */
4468 df_bb_refs_collect (&collection_rec, bb);
4469 df_refs_verify (collection_rec.def_vec, df_get_artificial_defs (bb->index), true);
4470 df_refs_verify (collection_rec.use_vec, df_get_artificial_uses (bb->index), true);
4471 df_free_collection_rec (&collection_rec);
4477 /* Returns true if the entry block has correct and complete df_ref set.
4478 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4481 df_entry_block_bitmap_verify (bool abort_if_fail)
4483 bitmap entry_block_defs = BITMAP_ALLOC (&df_bitmap_obstack);
4486 df_get_entry_block_def_set (entry_block_defs);
4488 is_eq = bitmap_equal_p (entry_block_defs, df->entry_block_defs);
4490 if (!is_eq && abort_if_fail)
4492 print_current_pass (stderr);
4493 fprintf (stderr, "entry_block_defs = ");
4494 df_print_regset (stderr, entry_block_defs);
4495 fprintf (stderr, "df->entry_block_defs = ");
4496 df_print_regset (stderr, df->entry_block_defs);
4500 BITMAP_FREE (entry_block_defs);
4506 /* Returns true if the exit block has correct and complete df_ref set.
4507 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4510 df_exit_block_bitmap_verify (bool abort_if_fail)
4512 bitmap exit_block_uses = BITMAP_ALLOC (&df_bitmap_obstack);
4515 df_get_exit_block_use_set (exit_block_uses);
4517 is_eq = bitmap_equal_p (exit_block_uses, df->exit_block_uses);
4519 if (!is_eq && abort_if_fail)
4521 print_current_pass (stderr);
4522 fprintf (stderr, "exit_block_uses = ");
4523 df_print_regset (stderr, exit_block_uses);
4524 fprintf (stderr, "df->exit_block_uses = ");
4525 df_print_regset (stderr, df->exit_block_uses);
4529 BITMAP_FREE (exit_block_uses);
4535 /* Return true if df_ref information for all insns in all blocks are
4536 correct and complete. */
4539 df_scan_verify (void)
4543 bitmap regular_block_artificial_uses;
4544 bitmap eh_block_artificial_uses;
4549 /* Verification is a 4 step process. */
4551 /* (1) All of the refs are marked by going thru the reg chains. */
4552 for (i = 0; i < DF_REG_SIZE (df); i++)
4554 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false)
4555 == DF_REG_DEF_COUNT(i));
4556 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i), i, false, false)
4557 == DF_REG_USE_COUNT(i));
4558 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i), i, false, true)
4559 == DF_REG_EQ_USE_COUNT(i));
4562 /* (2) There are various bitmaps whose value may change over the
4563 course of the compilation. This step recomputes them to make
4564 sure that they have not slipped out of date. */
4565 regular_block_artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
4566 eh_block_artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
4568 df_get_regular_block_artificial_uses (regular_block_artificial_uses);
4569 df_get_eh_block_artificial_uses (eh_block_artificial_uses);
4571 bitmap_ior_into (eh_block_artificial_uses,
4572 regular_block_artificial_uses);
4574 /* Check artificial_uses bitmaps didn't change. */
4575 gcc_assert (bitmap_equal_p (regular_block_artificial_uses,
4576 df->regular_block_artificial_uses));
4577 gcc_assert (bitmap_equal_p (eh_block_artificial_uses,
4578 df->eh_block_artificial_uses));
4580 BITMAP_FREE (regular_block_artificial_uses);
4581 BITMAP_FREE (eh_block_artificial_uses);
4583 /* Verify entry block and exit block. These only verify the bitmaps,
4584 the refs are verified in df_bb_verify. */
4585 df_entry_block_bitmap_verify (true);
4586 df_exit_block_bitmap_verify (true);
4588 /* (3) All of the insns in all of the blocks are traversed and the
4589 marks are cleared both in the artificial refs attached to the
4590 blocks and the real refs inside the insns. It is a failure to
4591 clear a mark that has not been set as this means that the ref in
4592 the block or insn was not in the reg chain. */
4597 /* (4) See if all reg chains are traversed a second time. This time
4598 a check is made that the marks are clear. A set mark would be a
4599 from a reg that is not in any insn or basic block. */
4601 for (i = 0; i < DF_REG_SIZE (df); i++)
4603 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i));
4604 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i));
4605 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i));