1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010 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"
48 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
51 DEF_VEC_ALLOC_P_STACK(df_ref);
53 #define VEC_df_ref_stack_alloc(alloc) VEC_stack_alloc (df_ref, alloc)
55 typedef struct df_mw_hardreg *df_mw_hardreg_ptr;
57 DEF_VEC_P(df_mw_hardreg_ptr);
58 DEF_VEC_ALLOC_P_STACK(df_mw_hardreg_ptr);
60 #define VEC_df_mw_hardreg_ptr_stack_alloc(alloc) \
61 VEC_stack_alloc (df_mw_hardreg_ptr, alloc)
64 #define HAVE_epilogue 0
67 #define HAVE_prologue 0
69 #ifndef HAVE_sibcall_epilogue
70 #define HAVE_sibcall_epilogue 0
74 #define EPILOGUE_USES(REGNO) 0
77 /* The following two macros free the vecs that hold either the refs or
78 the mw refs. They are a little tricky because the vec has 0
79 elements is special and is not to be freed. */
80 #define df_scan_free_ref_vec(V) \
86 #define df_scan_free_mws_vec(V) \
92 /* The set of hard registers in eliminables[i].from. */
94 static HARD_REG_SET elim_reg_set;
96 /* Initialize ur_in and ur_out as if all hard registers were partially
99 struct df_collection_rec
101 VEC(df_ref,stack) *def_vec;
102 VEC(df_ref,stack) *use_vec;
103 VEC(df_ref,stack) *eq_use_vec;
104 VEC(df_mw_hardreg_ptr,stack) *mw_vec;
107 static df_ref df_null_ref_rec[1];
108 static struct df_mw_hardreg * df_null_mw_rec[1];
110 static void df_ref_record (enum df_ref_class, struct df_collection_rec *,
112 basic_block, struct df_insn_info *,
113 enum df_ref_type, int ref_flags);
114 static void df_def_record_1 (struct df_collection_rec *, rtx,
115 basic_block, struct df_insn_info *,
117 static void df_defs_record (struct df_collection_rec *, rtx,
118 basic_block, struct df_insn_info *,
120 static void df_uses_record (struct df_collection_rec *,
121 rtx *, enum df_ref_type,
122 basic_block, struct df_insn_info *,
125 static df_ref df_ref_create_structure (enum df_ref_class,
126 struct df_collection_rec *, rtx, rtx *,
127 basic_block, struct df_insn_info *,
128 enum df_ref_type, int ref_flags);
129 static void df_insn_refs_collect (struct df_collection_rec*,
130 basic_block, struct df_insn_info *);
131 static void df_canonize_collection_rec (struct df_collection_rec *);
133 static void df_get_regular_block_artificial_uses (bitmap);
134 static void df_get_eh_block_artificial_uses (bitmap);
136 static void df_record_entry_block_defs (bitmap);
137 static void df_record_exit_block_uses (bitmap);
138 static void df_get_exit_block_use_set (bitmap);
139 static void df_get_entry_block_def_set (bitmap);
140 static void df_grow_ref_info (struct df_ref_info *, unsigned int);
141 static void df_ref_chain_delete_du_chain (df_ref *);
142 static void df_ref_chain_delete (df_ref *);
144 static void df_refs_add_to_chains (struct df_collection_rec *,
147 static bool df_insn_refs_verify (struct df_collection_rec *, basic_block, rtx, bool);
148 static void df_entry_block_defs_collect (struct df_collection_rec *, bitmap);
149 static void df_exit_block_uses_collect (struct df_collection_rec *, bitmap);
150 static void df_install_ref (df_ref, struct df_reg_info *,
151 struct df_ref_info *, bool);
153 static int df_ref_compare (const void *, const void *);
154 static int df_mw_compare (const void *, const void *);
156 /* Indexed by hardware reg number, is true if that register is ever
157 used in the current function.
159 In df-scan.c, this is set up to record the hard regs used
160 explicitly. Reload adds in the hard regs used for holding pseudo
161 regs. Final uses it to generate the code in the function prologue
162 and epilogue to save and restore registers as needed. */
164 static bool regs_ever_live[FIRST_PSEUDO_REGISTER];
166 /*----------------------------------------------------------------------------
167 SCANNING DATAFLOW PROBLEM
169 There are several ways in which scanning looks just like the other
170 dataflow problems. It shares the all the mechanisms for local info
171 as well as basic block info. Where it differs is when and how often
172 it gets run. It also has no need for the iterative solver.
173 ----------------------------------------------------------------------------*/
175 /* Problem data for the scanning dataflow function. */
176 struct df_scan_problem_data
178 alloc_pool ref_base_pool;
179 alloc_pool ref_artificial_pool;
180 alloc_pool ref_regular_pool;
181 alloc_pool insn_pool;
183 alloc_pool mw_reg_pool;
184 bitmap_obstack reg_bitmaps;
185 bitmap_obstack insn_bitmaps;
188 typedef struct df_scan_bb_info *df_scan_bb_info_t;
191 /* Internal function to shut down the scanning problem. */
193 df_scan_free_internal (void)
195 struct df_scan_problem_data *problem_data
196 = (struct df_scan_problem_data *) df_scan->problem_data;
200 /* The vectors that hold the refs are not pool allocated because
201 they come in many sizes. This makes them impossible to delete
203 for (i = 0; i < DF_INSN_SIZE(); i++)
205 struct df_insn_info *insn_info = DF_INSN_UID_GET(i);
206 /* Skip the insns that have no insn_info or have been
210 df_scan_free_ref_vec (insn_info->defs);
211 df_scan_free_ref_vec (insn_info->uses);
212 df_scan_free_ref_vec (insn_info->eq_uses);
213 df_scan_free_mws_vec (insn_info->mw_hardregs);
219 unsigned int bb_index = bb->index;
220 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
223 df_scan_free_ref_vec (bb_info->artificial_defs);
224 df_scan_free_ref_vec (bb_info->artificial_uses);
228 free (df->def_info.refs);
229 free (df->def_info.begin);
230 free (df->def_info.count);
231 memset (&df->def_info, 0, (sizeof (struct df_ref_info)));
233 free (df->use_info.refs);
234 free (df->use_info.begin);
235 free (df->use_info.count);
236 memset (&df->use_info, 0, (sizeof (struct df_ref_info)));
242 free (df->eq_use_regs);
243 df->eq_use_regs = NULL;
251 free (df_scan->block_info);
252 df_scan->block_info = NULL;
253 df_scan->block_info_size = 0;
255 bitmap_clear (&df->hardware_regs_used);
256 bitmap_clear (&df->regular_block_artificial_uses);
257 bitmap_clear (&df->eh_block_artificial_uses);
258 BITMAP_FREE (df->entry_block_defs);
259 BITMAP_FREE (df->exit_block_uses);
260 bitmap_clear (&df->insns_to_delete);
261 bitmap_clear (&df->insns_to_rescan);
262 bitmap_clear (&df->insns_to_notes_rescan);
264 free_alloc_pool (problem_data->ref_base_pool);
265 free_alloc_pool (problem_data->ref_artificial_pool);
266 free_alloc_pool (problem_data->ref_regular_pool);
267 free_alloc_pool (problem_data->insn_pool);
268 free_alloc_pool (problem_data->reg_pool);
269 free_alloc_pool (problem_data->mw_reg_pool);
270 bitmap_obstack_release (&problem_data->reg_bitmaps);
271 bitmap_obstack_release (&problem_data->insn_bitmaps);
272 free (df_scan->problem_data);
276 /* Free basic block info. */
279 df_scan_free_bb_info (basic_block bb, void *vbb_info)
281 struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
282 unsigned int bb_index = bb->index;
284 /* See if bb_info is initialized. */
285 if (bb_info->artificial_defs)
288 FOR_BB_INSNS (bb, insn)
291 /* Record defs within INSN. */
292 df_insn_delete (bb, INSN_UID (insn));
295 if (bb_index < df_scan->block_info_size)
296 bb_info = df_scan_get_bb_info (bb_index);
298 /* Get rid of any artificial uses or defs. */
299 if (bb_info->artificial_defs)
301 df_ref_chain_delete_du_chain (bb_info->artificial_defs);
302 df_ref_chain_delete_du_chain (bb_info->artificial_uses);
303 df_ref_chain_delete (bb_info->artificial_defs);
304 df_ref_chain_delete (bb_info->artificial_uses);
305 bb_info->artificial_defs = NULL;
306 bb_info->artificial_uses = NULL;
312 /* Allocate the problem data for the scanning problem. This should be
313 called when the problem is created or when the entire function is to
316 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
318 struct df_scan_problem_data *problem_data;
319 unsigned int insn_num = get_max_uid () + 1;
320 unsigned int block_size = 400;
323 /* Given the number of pools, this is really faster than tearing
325 if (df_scan->problem_data)
326 df_scan_free_internal ();
328 problem_data = XNEW (struct df_scan_problem_data);
329 df_scan->problem_data = problem_data;
330 df_scan->computed = true;
332 problem_data->ref_base_pool
333 = create_alloc_pool ("df_scan ref base",
334 sizeof (struct df_base_ref), block_size);
335 problem_data->ref_artificial_pool
336 = create_alloc_pool ("df_scan ref artificial",
337 sizeof (struct df_artificial_ref), block_size);
338 problem_data->ref_regular_pool
339 = create_alloc_pool ("df_scan ref regular",
340 sizeof (struct df_regular_ref), block_size);
341 problem_data->insn_pool
342 = create_alloc_pool ("df_scan insn",
343 sizeof (struct df_insn_info), block_size);
344 problem_data->reg_pool
345 = create_alloc_pool ("df_scan reg",
346 sizeof (struct df_reg_info), block_size);
347 problem_data->mw_reg_pool
348 = create_alloc_pool ("df_scan mw_reg",
349 sizeof (struct df_mw_hardreg), block_size);
351 bitmap_obstack_initialize (&problem_data->reg_bitmaps);
352 bitmap_obstack_initialize (&problem_data->insn_bitmaps);
354 insn_num += insn_num / 4;
357 df_grow_insn_info ();
358 df_grow_bb_info (df_scan);
362 unsigned int bb_index = bb->index;
363 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
364 bb_info->artificial_defs = NULL;
365 bb_info->artificial_uses = NULL;
368 bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps);
369 bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps);
370 bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps);
371 df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
372 df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
373 bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps);
374 bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps);
375 bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps);
376 df_scan->optional_p = false;
380 /* Free all of the data associated with the scan problem. */
385 if (df_scan->problem_data)
386 df_scan_free_internal ();
388 if (df->blocks_to_analyze)
390 BITMAP_FREE (df->blocks_to_analyze);
391 df->blocks_to_analyze = NULL;
397 /* Dump the preamble for DF_SCAN dump. */
399 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
410 fprintf (file, ";; invalidated by call \t");
411 df_print_regset (file, regs_invalidated_by_call_regset);
412 fprintf (file, ";; hardware regs used \t");
413 df_print_regset (file, &df->hardware_regs_used);
414 fprintf (file, ";; regular block artificial uses \t");
415 df_print_regset (file, &df->regular_block_artificial_uses);
416 fprintf (file, ";; eh block artificial uses \t");
417 df_print_regset (file, &df->eh_block_artificial_uses);
418 fprintf (file, ";; entry block defs \t");
419 df_print_regset (file, df->entry_block_defs);
420 fprintf (file, ";; exit block uses \t");
421 df_print_regset (file, df->exit_block_uses);
422 fprintf (file, ";; regs ever live \t");
423 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
424 if (df_regs_ever_live_p (i))
425 fprintf (file, " %d[%s]", i, reg_names[i]);
426 fprintf (file, "\n;; ref usage \t");
428 for (i = 0; i < (int)df->regs_inited; i++)
429 if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i))
431 const char * sep = "";
433 fprintf (file, "r%d={", i);
434 if (DF_REG_DEF_COUNT (i))
436 fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
438 dcount += DF_REG_DEF_COUNT (i);
440 if (DF_REG_USE_COUNT (i))
442 fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
444 ucount += DF_REG_USE_COUNT (i);
446 if (DF_REG_EQ_USE_COUNT (i))
448 fprintf (file, "%s%dd", sep, DF_REG_EQ_USE_COUNT (i));
449 ecount += DF_REG_EQ_USE_COUNT (i);
451 fprintf (file, "} ");
455 FOR_BB_INSNS (bb, insn)
464 fprintf (file, "\n;; total ref usage %d{%dd,%du,%de} in %d{%d regular + %d call} insns.\n",
465 dcount + ucount + ecount, dcount, ucount, ecount, icount + ccount, icount, ccount);
468 /* Dump the bb_info for a given basic block. */
470 df_scan_start_block (basic_block bb, FILE *file)
472 struct df_scan_bb_info *bb_info
473 = df_scan_get_bb_info (bb->index);
477 fprintf (file, ";; bb %d artificial_defs: ", bb->index);
478 df_refs_chain_dump (bb_info->artificial_defs, true, file);
479 fprintf (file, "\n;; bb %d artificial_uses: ", bb->index);
480 df_refs_chain_dump (bb_info->artificial_uses, true, file);
481 fprintf (file, "\n");
486 FOR_BB_INSNS (bb, insn)
488 df_insn_debug (insn, false, file);
493 static struct df_problem problem_SCAN =
495 DF_SCAN, /* Problem id. */
496 DF_NONE, /* Direction. */
497 df_scan_alloc, /* Allocate the problem specific data. */
498 NULL, /* Reset global information. */
499 df_scan_free_bb_info, /* Free basic block info. */
500 NULL, /* Local compute function. */
501 NULL, /* Init the solution specific data. */
502 NULL, /* Iterative solver. */
503 NULL, /* Confluence operator 0. */
504 NULL, /* Confluence operator n. */
505 NULL, /* Transfer function. */
506 NULL, /* Finalize function. */
507 df_scan_free, /* Free all of the problem information. */
508 NULL, /* Remove this problem from the stack of dataflow problems. */
509 df_scan_start_dump, /* Debugging. */
510 df_scan_start_block, /* Debugging start block. */
511 NULL, /* Debugging end block. */
512 NULL, /* Incremental solution verify start. */
513 NULL, /* Incremental solution verify end. */
514 NULL, /* Dependent problem. */
515 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
516 TV_DF_SCAN, /* Timing variable. */
517 false /* Reset blocks on dropping out of blocks_to_analyze. */
521 /* Create a new DATAFLOW instance and add it to an existing instance
522 of DF. The returned structure is what is used to get at the
526 df_scan_add_problem (void)
528 df_add_problem (&problem_SCAN);
532 /*----------------------------------------------------------------------------
533 Storage Allocation Utilities
534 ----------------------------------------------------------------------------*/
537 /* First, grow the reg_info information. If the current size is less than
538 the number of pseudos, grow to 25% more than the number of
541 Second, assure that all of the slots up to max_reg_num have been
542 filled with reg_info structures. */
545 df_grow_reg_info (void)
547 unsigned int max_reg = max_reg_num ();
548 unsigned int new_size = max_reg;
549 struct df_scan_problem_data *problem_data
550 = (struct df_scan_problem_data *) df_scan->problem_data;
553 if (df->regs_size < new_size)
555 new_size += new_size / 4;
556 df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
557 df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
558 df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
560 df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
561 df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
562 df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
563 df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
564 df->regs_size = new_size;
567 for (i = df->regs_inited; i < max_reg; i++)
569 struct df_reg_info *reg_info;
571 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
572 memset (reg_info, 0, sizeof (struct df_reg_info));
573 df->def_regs[i] = reg_info;
574 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
575 memset (reg_info, 0, sizeof (struct df_reg_info));
576 df->use_regs[i] = reg_info;
577 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
578 memset (reg_info, 0, sizeof (struct df_reg_info));
579 df->eq_use_regs[i] = reg_info;
580 df->def_info.begin[i] = 0;
581 df->def_info.count[i] = 0;
582 df->use_info.begin[i] = 0;
583 df->use_info.count[i] = 0;
586 df->regs_inited = max_reg;
590 /* Grow the ref information. */
593 df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
595 if (ref_info->refs_size < new_size)
597 ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
598 memset (ref_info->refs + ref_info->refs_size, 0,
599 (new_size - ref_info->refs_size) *sizeof (df_ref));
600 ref_info->refs_size = new_size;
605 /* Check and grow the ref information if necessary. This routine
606 guarantees total_size + BITMAP_ADDEND amount of entries in refs
607 array. It updates ref_info->refs_size only and does not change
608 ref_info->total_size. */
611 df_check_and_grow_ref_info (struct df_ref_info *ref_info,
612 unsigned bitmap_addend)
614 if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
616 int new_size = ref_info->total_size + bitmap_addend;
617 new_size += ref_info->total_size / 4;
618 df_grow_ref_info (ref_info, new_size);
623 /* Grow the ref information. If the current size is less than the
624 number of instructions, grow to 25% more than the number of
628 df_grow_insn_info (void)
630 unsigned int new_size = get_max_uid () + 1;
631 if (DF_INSN_SIZE () < new_size)
633 new_size += new_size / 4;
634 df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
635 memset (df->insns + df->insns_size, 0,
636 (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
637 DF_INSN_SIZE () = new_size;
644 /*----------------------------------------------------------------------------
645 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
646 ----------------------------------------------------------------------------*/
648 /* Rescan all of the block_to_analyze or all of the blocks in the
649 function if df_set_blocks if blocks_to_analyze is NULL; */
652 df_scan_blocks (void)
656 df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
657 df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
659 df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses);
660 df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses);
662 bitmap_ior_into (&df->eh_block_artificial_uses,
663 &df->regular_block_artificial_uses);
665 /* ENTRY and EXIT blocks have special defs/uses. */
666 df_get_entry_block_def_set (df->entry_block_defs);
667 df_record_entry_block_defs (df->entry_block_defs);
668 df_get_exit_block_use_set (df->exit_block_uses);
669 df_record_exit_block_uses (df->exit_block_uses);
670 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
671 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
676 unsigned int bb_index = bb->index;
677 df_bb_refs_record (bb_index, true);
682 /* Create a new ref of type DF_REF_TYPE for register REG at address
683 LOC within INSN of BB. This function is only used externally. */
686 df_ref_create (rtx reg, rtx *loc, rtx insn,
688 enum df_ref_type ref_type,
692 struct df_reg_info **reg_info;
693 struct df_ref_info *ref_info;
695 df_ref **ref_rec_ptr;
696 unsigned int count = 0;
698 enum df_ref_class cl;
702 /* You cannot hack artificial refs. */
709 ref = df_ref_create_structure (cl, NULL, reg, loc, bb, DF_INSN_INFO_GET (insn),
710 ref_type, ref_flags);
712 if (DF_REF_REG_DEF_P (ref))
714 reg_info = df->def_regs;
715 ref_info = &df->def_info;
716 ref_rec_ptr = &DF_INSN_DEFS (insn);
717 add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
719 else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
721 reg_info = df->eq_use_regs;
722 ref_info = &df->use_info;
723 ref_rec_ptr = &DF_INSN_EQ_USES (insn);
724 switch (ref_info->ref_order)
726 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
727 case DF_REF_ORDER_BY_REG_WITH_NOTES:
728 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
732 add_to_table = false;
738 reg_info = df->use_regs;
739 ref_info = &df->use_info;
740 ref_rec_ptr = &DF_INSN_USES (insn);
741 add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
744 /* Do not add if ref is not in the right blocks. */
745 if (add_to_table && df->analyze_subset)
746 add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
748 df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
751 switch (ref_info->ref_order)
753 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
754 case DF_REF_ORDER_BY_REG_WITH_NOTES:
755 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
756 ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
759 ref_info->ref_order = DF_REF_ORDER_UNORDERED;
763 ref_rec = *ref_rec_ptr;
770 ref_rec = *ref_rec_ptr;
773 ref_rec = XRESIZEVEC (df_ref, ref_rec, count+2);
774 *ref_rec_ptr = ref_rec;
775 ref_rec[count] = ref;
776 ref_rec[count+1] = NULL;
777 qsort (ref_rec, count + 1, sizeof (df_ref), df_ref_compare);
781 df_ref *ref_rec = XNEWVEC (df_ref, 2);
784 *ref_rec_ptr = ref_rec;
790 fprintf (dump_file, "adding ref ");
791 df_ref_debug (ref, dump_file);
794 /* By adding the ref directly, df_insn_rescan my not find any
795 differences even though the block will have changed. So we need
796 to mark the block dirty ourselves. */
797 if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
798 df_set_bb_dirty (bb);
805 /*----------------------------------------------------------------------------
806 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
807 ----------------------------------------------------------------------------*/
810 df_free_ref (df_ref ref)
812 struct df_scan_problem_data *problem_data
813 = (struct df_scan_problem_data *) df_scan->problem_data;
815 switch (DF_REF_CLASS (ref))
818 pool_free (problem_data->ref_base_pool, ref);
821 case DF_REF_ARTIFICIAL:
822 pool_free (problem_data->ref_artificial_pool, ref);
826 pool_free (problem_data->ref_regular_pool, ref);
832 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
833 Also delete the def-use or use-def chain if it exists. */
836 df_reg_chain_unlink (df_ref ref)
838 df_ref next = DF_REF_NEXT_REG (ref);
839 df_ref prev = DF_REF_PREV_REG (ref);
840 int id = DF_REF_ID (ref);
841 struct df_reg_info *reg_info;
844 if (DF_REF_REG_DEF_P (ref))
846 int regno = DF_REF_REGNO (ref);
847 reg_info = DF_REG_DEF_GET (regno);
848 refs = df->def_info.refs;
852 if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
854 reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
855 switch (df->use_info.ref_order)
857 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
858 case DF_REF_ORDER_BY_REG_WITH_NOTES:
859 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
860 refs = df->use_info.refs;
868 reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
869 refs = df->use_info.refs;
875 if (df->analyze_subset)
877 if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
884 /* Delete any def-use or use-def chains that start here. It is
885 possible that there is trash in this field. This happens for
886 insns that have been deleted when rescanning has been deferred
887 and the chain problem has also been deleted. The chain tear down
888 code skips deleted insns. */
889 if (df_chain && DF_REF_CHAIN (ref))
890 df_chain_unlink (ref);
893 if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
895 gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
896 df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
899 /* Unlink from the reg chain. If there is no prev, this is the
900 first of the list. If not, just join the next and prev. */
902 DF_REF_NEXT_REG (prev) = next;
905 gcc_assert (reg_info->reg_chain == ref);
906 reg_info->reg_chain = next;
909 DF_REF_PREV_REG (next) = prev;
915 /* Remove REF from VEC. */
918 df_ref_compress_rec (df_ref **vec_ptr, df_ref ref)
920 df_ref *vec = *vec_ptr;
924 while (*vec && *vec != ref)
936 *vec_ptr = df_null_ref_rec;
941 /* Unlink REF from all def-use/use-def chains, etc. */
944 df_ref_remove (df_ref ref)
949 fprintf (dump_file, "removing ref ");
950 df_ref_debug (ref, dump_file);
954 if (DF_REF_REG_DEF_P (ref))
956 if (DF_REF_IS_ARTIFICIAL (ref))
958 struct df_scan_bb_info *bb_info
959 = df_scan_get_bb_info (DF_REF_BBNO (ref));
960 df_ref_compress_rec (&bb_info->artificial_defs, ref);
964 unsigned int uid = DF_REF_INSN_UID (ref);
965 struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
966 df_ref_compress_rec (&insn_rec->defs, ref);
971 if (DF_REF_IS_ARTIFICIAL (ref))
973 struct df_scan_bb_info *bb_info
974 = df_scan_get_bb_info (DF_REF_BBNO (ref));
975 df_ref_compress_rec (&bb_info->artificial_uses, ref);
979 unsigned int uid = DF_REF_INSN_UID (ref);
980 struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
982 if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
983 df_ref_compress_rec (&insn_rec->eq_uses, ref);
985 df_ref_compress_rec (&insn_rec->uses, ref);
989 /* By deleting the ref directly, df_insn_rescan my not find any
990 differences even though the block will have changed. So we need
991 to mark the block dirty ourselves. */
992 if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
993 df_set_bb_dirty (DF_REF_BB (ref));
994 df_reg_chain_unlink (ref);
998 /* Create the insn record for INSN. If there was one there, zero it
1001 struct df_insn_info *
1002 df_insn_create_insn_record (rtx insn)
1004 struct df_scan_problem_data *problem_data
1005 = (struct df_scan_problem_data *) df_scan->problem_data;
1006 struct df_insn_info *insn_rec;
1008 df_grow_insn_info ();
1009 insn_rec = DF_INSN_INFO_GET (insn);
1012 insn_rec = (struct df_insn_info *) pool_alloc (problem_data->insn_pool);
1013 DF_INSN_INFO_SET (insn, insn_rec);
1015 memset (insn_rec, 0, sizeof (struct df_insn_info));
1016 insn_rec->insn = insn;
1021 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
1024 df_ref_chain_delete_du_chain (df_ref *ref_rec)
1028 df_ref ref = *ref_rec;
1029 /* CHAIN is allocated by DF_CHAIN. So make sure to
1030 pass df_scan instance for the problem. */
1031 if (DF_REF_CHAIN (ref))
1032 df_chain_unlink (ref);
1038 /* Delete all refs in the ref chain. */
1041 df_ref_chain_delete (df_ref *ref_rec)
1043 df_ref *start = ref_rec;
1046 df_reg_chain_unlink (*ref_rec);
1050 /* If the list is empty, it has a special shared element that is not
1057 /* Delete the hardreg chain. */
1060 df_mw_hardreg_chain_delete (struct df_mw_hardreg **hardregs)
1062 struct df_scan_problem_data *problem_data;
1067 problem_data = (struct df_scan_problem_data *) df_scan->problem_data;
1071 pool_free (problem_data->mw_reg_pool, *hardregs);
1077 /* Delete all of the refs information from INSN. BB must be passed in
1078 except when called from df_process_deferred_rescans to mark the block
1082 df_insn_delete (basic_block bb, unsigned int uid)
1084 struct df_insn_info *insn_info = NULL;
1088 df_grow_bb_info (df_scan);
1089 df_grow_reg_info ();
1091 /* The block must be marked as dirty now, rather than later as in
1092 df_insn_rescan and df_notes_rescan because it may not be there at
1093 rescanning time and the mark would blow up. */
1095 df_set_bb_dirty (bb);
1097 insn_info = DF_INSN_UID_SAFE_GET (uid);
1099 /* The client has deferred rescanning. */
1100 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1104 bitmap_clear_bit (&df->insns_to_rescan, uid);
1105 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1106 bitmap_set_bit (&df->insns_to_delete, uid);
1109 fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
1114 fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
1116 bitmap_clear_bit (&df->insns_to_delete, uid);
1117 bitmap_clear_bit (&df->insns_to_rescan, uid);
1118 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1121 struct df_scan_problem_data *problem_data
1122 = (struct df_scan_problem_data *) df_scan->problem_data;
1124 /* In general, notes do not have the insn_info fields
1125 initialized. However, combine deletes insns by changing them
1126 to notes. How clever. So we cannot just check if it is a
1127 valid insn before short circuiting this code, we need to see
1128 if we actually initialized it. */
1129 if (insn_info->defs)
1131 df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1135 df_ref_chain_delete_du_chain (insn_info->defs);
1136 df_ref_chain_delete_du_chain (insn_info->uses);
1137 df_ref_chain_delete_du_chain (insn_info->eq_uses);
1140 df_ref_chain_delete (insn_info->defs);
1141 df_ref_chain_delete (insn_info->uses);
1142 df_ref_chain_delete (insn_info->eq_uses);
1144 pool_free (problem_data->insn_pool, insn_info);
1145 DF_INSN_UID_SET (uid, NULL);
1150 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1153 df_free_collection_rec (struct df_collection_rec *collection_rec)
1156 struct df_scan_problem_data *problem_data
1157 = (struct df_scan_problem_data *) df_scan->problem_data;
1159 struct df_mw_hardreg *mw;
1161 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
1163 FOR_EACH_VEC_ELT (df_ref, collection_rec->use_vec, ix, ref)
1165 FOR_EACH_VEC_ELT (df_ref, collection_rec->eq_use_vec, ix, ref)
1167 FOR_EACH_VEC_ELT (df_mw_hardreg_ptr, collection_rec->mw_vec, ix, mw)
1168 pool_free (problem_data->mw_reg_pool, mw);
1170 VEC_free (df_ref, stack, collection_rec->def_vec);
1171 VEC_free (df_ref, stack, collection_rec->use_vec);
1172 VEC_free (df_ref, stack, collection_rec->eq_use_vec);
1173 VEC_free (df_mw_hardreg_ptr, stack, collection_rec->mw_vec);
1176 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1179 df_insn_rescan (rtx insn)
1181 unsigned int uid = INSN_UID (insn);
1182 struct df_insn_info *insn_info = NULL;
1183 basic_block bb = BLOCK_FOR_INSN (insn);
1184 struct df_collection_rec collection_rec;
1186 if ((!df) || (!INSN_P (insn)))
1192 fprintf (dump_file, "no bb for insn with uid = %d.\n", uid);
1196 /* The client has disabled rescanning and plans to do it itself. */
1197 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1200 df_grow_bb_info (df_scan);
1201 df_grow_reg_info ();
1203 insn_info = DF_INSN_UID_SAFE_GET (uid);
1205 /* The client has deferred rescanning. */
1206 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1210 insn_info = df_insn_create_insn_record (insn);
1211 insn_info->defs = df_null_ref_rec;
1212 insn_info->uses = df_null_ref_rec;
1213 insn_info->eq_uses = df_null_ref_rec;
1214 insn_info->mw_hardregs = df_null_mw_rec;
1217 fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid);
1219 bitmap_clear_bit (&df->insns_to_delete, uid);
1220 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1221 bitmap_set_bit (&df->insns_to_rescan, INSN_UID (insn));
1225 collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
1226 collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
1227 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
1228 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
1230 bitmap_clear_bit (&df->insns_to_delete, uid);
1231 bitmap_clear_bit (&df->insns_to_rescan, uid);
1232 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1236 bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false);
1237 /* If there's no change, return false. */
1240 df_free_collection_rec (&collection_rec);
1242 fprintf (dump_file, "verify found no changes in insn with uid = %d.\n", uid);
1246 fprintf (dump_file, "rescanning insn with uid = %d.\n", uid);
1248 /* There's change - we need to delete the existing info.
1249 Since the insn isn't moved, we can salvage its LUID. */
1250 luid = DF_INSN_LUID (insn);
1251 df_insn_delete (NULL, uid);
1252 df_insn_create_insn_record (insn);
1253 DF_INSN_LUID (insn) = luid;
1257 struct df_insn_info *insn_info = df_insn_create_insn_record (insn);
1258 df_insn_refs_collect (&collection_rec, bb, insn_info);
1260 fprintf (dump_file, "scanning new insn with uid = %d.\n", uid);
1263 df_refs_add_to_chains (&collection_rec, bb, insn);
1264 if (!DEBUG_INSN_P (insn))
1265 df_set_bb_dirty (bb);
1267 VEC_free (df_ref, stack, collection_rec.def_vec);
1268 VEC_free (df_ref, stack, collection_rec.use_vec);
1269 VEC_free (df_ref, stack, collection_rec.eq_use_vec);
1270 VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
1275 /* Same as df_insn_rescan, but don't mark the basic block as
1279 df_insn_rescan_debug_internal (rtx insn)
1281 unsigned int uid = INSN_UID (insn);
1282 struct df_insn_info *insn_info;
1284 gcc_assert (DEBUG_INSN_P (insn)
1285 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)));
1290 insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
1295 fprintf (dump_file, "deleting debug_insn with uid = %d.\n", uid);
1297 bitmap_clear_bit (&df->insns_to_delete, uid);
1298 bitmap_clear_bit (&df->insns_to_rescan, uid);
1299 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1301 if (!insn_info->defs)
1304 if (insn_info->defs == df_null_ref_rec
1305 && insn_info->uses == df_null_ref_rec
1306 && insn_info->eq_uses == df_null_ref_rec
1307 && insn_info->mw_hardregs == df_null_mw_rec)
1310 df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1314 df_ref_chain_delete_du_chain (insn_info->defs);
1315 df_ref_chain_delete_du_chain (insn_info->uses);
1316 df_ref_chain_delete_du_chain (insn_info->eq_uses);
1319 df_ref_chain_delete (insn_info->defs);
1320 df_ref_chain_delete (insn_info->uses);
1321 df_ref_chain_delete (insn_info->eq_uses);
1323 insn_info->defs = df_null_ref_rec;
1324 insn_info->uses = df_null_ref_rec;
1325 insn_info->eq_uses = df_null_ref_rec;
1326 insn_info->mw_hardregs = df_null_mw_rec;
1332 /* Rescan all of the insns in the function. Note that the artificial
1333 uses and defs are not touched. This function will destroy def-se
1334 or use-def chains. */
1337 df_insn_rescan_all (void)
1339 bool no_insn_rescan = false;
1340 bool defer_insn_rescan = false;
1346 bitmap_initialize (&tmp, &df_bitmap_obstack);
1348 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1350 df_clear_flags (DF_NO_INSN_RESCAN);
1351 no_insn_rescan = true;
1354 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1356 df_clear_flags (DF_DEFER_INSN_RESCAN);
1357 defer_insn_rescan = true;
1360 bitmap_copy (&tmp, &df->insns_to_delete);
1361 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1363 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1365 df_insn_delete (NULL, uid);
1368 bitmap_clear (&tmp);
1369 bitmap_clear (&df->insns_to_delete);
1370 bitmap_clear (&df->insns_to_rescan);
1371 bitmap_clear (&df->insns_to_notes_rescan);
1376 FOR_BB_INSNS (bb, insn)
1378 df_insn_rescan (insn);
1383 df_set_flags (DF_NO_INSN_RESCAN);
1384 if (defer_insn_rescan)
1385 df_set_flags (DF_DEFER_INSN_RESCAN);
1389 /* Process all of the deferred rescans or deletions. */
1392 df_process_deferred_rescans (void)
1394 bool no_insn_rescan = false;
1395 bool defer_insn_rescan = false;
1400 bitmap_initialize (&tmp, &df_bitmap_obstack);
1402 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1404 df_clear_flags (DF_NO_INSN_RESCAN);
1405 no_insn_rescan = true;
1408 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1410 df_clear_flags (DF_DEFER_INSN_RESCAN);
1411 defer_insn_rescan = true;
1415 fprintf (dump_file, "starting the processing of deferred insns\n");
1417 bitmap_copy (&tmp, &df->insns_to_delete);
1418 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1420 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1422 df_insn_delete (NULL, uid);
1425 bitmap_copy (&tmp, &df->insns_to_rescan);
1426 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1428 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1430 df_insn_rescan (insn_info->insn);
1433 bitmap_copy (&tmp, &df->insns_to_notes_rescan);
1434 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1436 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1438 df_notes_rescan (insn_info->insn);
1442 fprintf (dump_file, "ending the processing of deferred insns\n");
1444 bitmap_clear (&tmp);
1445 bitmap_clear (&df->insns_to_delete);
1446 bitmap_clear (&df->insns_to_rescan);
1447 bitmap_clear (&df->insns_to_notes_rescan);
1450 df_set_flags (DF_NO_INSN_RESCAN);
1451 if (defer_insn_rescan)
1452 df_set_flags (DF_DEFER_INSN_RESCAN);
1454 /* If someone changed regs_ever_live during this pass, fix up the
1455 entry and exit blocks. */
1456 if (df->redo_entry_and_exit)
1458 df_update_entry_exit_and_calls ();
1459 df->redo_entry_and_exit = false;
1464 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1465 the uses if INCLUDE_USES. Include the eq_uses if
1469 df_count_refs (bool include_defs, bool include_uses,
1470 bool include_eq_uses)
1474 unsigned int m = df->regs_inited;
1476 for (regno = 0; regno < m; regno++)
1479 size += DF_REG_DEF_COUNT (regno);
1481 size += DF_REG_USE_COUNT (regno);
1482 if (include_eq_uses)
1483 size += DF_REG_EQ_USE_COUNT (regno);
1489 /* Take build ref table for either the uses or defs from the reg-use
1490 or reg-def chains. This version processes the refs in reg order
1491 which is likely to be best if processing the whole function. */
1494 df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info,
1497 bool include_eq_uses)
1499 unsigned int m = df->regs_inited;
1501 unsigned int offset = 0;
1504 if (df->changeable_flags & DF_NO_HARD_REGS)
1506 start = FIRST_PSEUDO_REGISTER;
1507 memset (ref_info->begin, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1508 memset (ref_info->count, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1513 ref_info->total_size
1514 = df_count_refs (include_defs, include_uses, include_eq_uses);
1516 df_check_and_grow_ref_info (ref_info, 1);
1518 for (regno = start; regno < m; regno++)
1521 ref_info->begin[regno] = offset;
1524 df_ref ref = DF_REG_DEF_CHAIN (regno);
1527 ref_info->refs[offset] = ref;
1528 DF_REF_ID (ref) = offset++;
1530 ref = DF_REF_NEXT_REG (ref);
1531 gcc_checking_assert (offset < ref_info->refs_size);
1536 df_ref ref = DF_REG_USE_CHAIN (regno);
1539 ref_info->refs[offset] = ref;
1540 DF_REF_ID (ref) = offset++;
1542 ref = DF_REF_NEXT_REG (ref);
1543 gcc_checking_assert (offset < ref_info->refs_size);
1546 if (include_eq_uses)
1548 df_ref ref = DF_REG_EQ_USE_CHAIN (regno);
1551 ref_info->refs[offset] = ref;
1552 DF_REF_ID (ref) = offset++;
1554 ref = DF_REF_NEXT_REG (ref);
1555 gcc_checking_assert (offset < ref_info->refs_size);
1558 ref_info->count[regno] = count;
1561 /* The bitmap size is not decremented when refs are deleted. So
1562 reset it now that we have squished out all of the empty
1564 ref_info->table_size = offset;
1568 /* Take build ref table for either the uses or defs from the reg-use
1569 or reg-def chains. This version processes the refs in insn order
1570 which is likely to be best if processing some segment of the
1574 df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
1577 bool include_eq_uses)
1580 unsigned int bb_index;
1581 unsigned int m = df->regs_inited;
1582 unsigned int offset = 0;
1585 = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
1587 memset (ref_info->begin, 0, sizeof (int) * df->regs_inited);
1588 memset (ref_info->count, 0, sizeof (int) * df->regs_inited);
1590 ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1591 df_check_and_grow_ref_info (ref_info, 1);
1593 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1595 basic_block bb = BASIC_BLOCK (bb_index);
1600 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1602 unsigned int regno = DF_REF_REGNO (*ref_rec);
1603 ref_info->count[regno]++;
1606 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1608 unsigned int regno = DF_REF_REGNO (*ref_rec);
1609 ref_info->count[regno]++;
1612 FOR_BB_INSNS (bb, insn)
1616 unsigned int uid = INSN_UID (insn);
1619 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1621 unsigned int regno = DF_REF_REGNO (*ref_rec);
1622 ref_info->count[regno]++;
1625 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1627 unsigned int regno = DF_REF_REGNO (*ref_rec);
1628 ref_info->count[regno]++;
1630 if (include_eq_uses)
1631 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1633 unsigned int regno = DF_REF_REGNO (*ref_rec);
1634 ref_info->count[regno]++;
1640 for (r = start; r < m; r++)
1642 ref_info->begin[r] = offset;
1643 offset += ref_info->count[r];
1644 ref_info->count[r] = 0;
1647 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1649 basic_block bb = BASIC_BLOCK (bb_index);
1654 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1656 df_ref ref = *ref_rec;
1657 unsigned int regno = DF_REF_REGNO (ref);
1661 = ref_info->begin[regno] + ref_info->count[regno]++;
1662 DF_REF_ID (ref) = id;
1663 ref_info->refs[id] = ref;
1667 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1669 df_ref ref = *ref_rec;
1670 unsigned int regno = DF_REF_REGNO (ref);
1674 = ref_info->begin[regno] + ref_info->count[regno]++;
1675 DF_REF_ID (ref) = id;
1676 ref_info->refs[id] = ref;
1680 FOR_BB_INSNS (bb, insn)
1684 unsigned int uid = INSN_UID (insn);
1687 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1689 df_ref ref = *ref_rec;
1690 unsigned int regno = DF_REF_REGNO (ref);
1694 = ref_info->begin[regno] + ref_info->count[regno]++;
1695 DF_REF_ID (ref) = id;
1696 ref_info->refs[id] = ref;
1700 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1702 df_ref ref = *ref_rec;
1703 unsigned int regno = DF_REF_REGNO (ref);
1707 = ref_info->begin[regno] + ref_info->count[regno]++;
1708 DF_REF_ID (ref) = id;
1709 ref_info->refs[id] = ref;
1712 if (include_eq_uses)
1713 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1715 df_ref ref = *ref_rec;
1716 unsigned int regno = DF_REF_REGNO (ref);
1720 = ref_info->begin[regno] + ref_info->count[regno]++;
1721 DF_REF_ID (ref) = id;
1722 ref_info->refs[id] = ref;
1729 /* The bitmap size is not decremented when refs are deleted. So
1730 reset it now that we have squished out all of the empty
1733 ref_info->table_size = offset;
1736 /* Take build ref table for either the uses or defs from the reg-use
1737 or reg-def chains. */
1740 df_reorganize_refs_by_reg (struct df_ref_info *ref_info,
1743 bool include_eq_uses)
1745 if (df->analyze_subset)
1746 df_reorganize_refs_by_reg_by_insn (ref_info, include_defs,
1747 include_uses, include_eq_uses);
1749 df_reorganize_refs_by_reg_by_reg (ref_info, include_defs,
1750 include_uses, include_eq_uses);
1754 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1756 df_add_refs_to_table (unsigned int offset,
1757 struct df_ref_info *ref_info,
1762 df_ref ref = *ref_vec;
1763 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
1764 || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER))
1766 ref_info->refs[offset] = ref;
1767 DF_REF_ID (*ref_vec) = offset++;
1775 /* Count the number of refs in all of the insns of BB. Include the
1776 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1777 eq_uses if INCLUDE_EQ_USES. */
1780 df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset,
1781 struct df_ref_info *ref_info,
1782 bool include_defs, bool include_uses,
1783 bool include_eq_uses)
1788 offset = df_add_refs_to_table (offset, ref_info,
1789 df_get_artificial_defs (bb->index));
1791 offset = df_add_refs_to_table (offset, ref_info,
1792 df_get_artificial_uses (bb->index));
1794 FOR_BB_INSNS (bb, insn)
1797 unsigned int uid = INSN_UID (insn);
1799 offset = df_add_refs_to_table (offset, ref_info,
1800 DF_INSN_UID_DEFS (uid));
1802 offset = df_add_refs_to_table (offset, ref_info,
1803 DF_INSN_UID_USES (uid));
1804 if (include_eq_uses)
1805 offset = df_add_refs_to_table (offset, ref_info,
1806 DF_INSN_UID_EQ_USES (uid));
1812 /* Organize the refs by insn into the table in REF_INFO. If
1813 blocks_to_analyze is defined, use that set, otherwise the entire
1814 program. Include the defs if INCLUDE_DEFS. Include the uses if
1815 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1818 df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
1819 bool include_defs, bool include_uses,
1820 bool include_eq_uses)
1823 unsigned int offset = 0;
1825 ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1826 df_check_and_grow_ref_info (ref_info, 1);
1827 if (df->blocks_to_analyze)
1832 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
1834 offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index), offset, ref_info,
1835 include_defs, include_uses,
1839 ref_info->table_size = offset;
1844 offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info,
1845 include_defs, include_uses,
1847 ref_info->table_size = offset;
1852 /* If the use refs in DF are not organized, reorganize them. */
1855 df_maybe_reorganize_use_refs (enum df_ref_order order)
1857 if (order == df->use_info.ref_order)
1862 case DF_REF_ORDER_BY_REG:
1863 df_reorganize_refs_by_reg (&df->use_info, false, true, false);
1866 case DF_REF_ORDER_BY_REG_WITH_NOTES:
1867 df_reorganize_refs_by_reg (&df->use_info, false, true, true);
1870 case DF_REF_ORDER_BY_INSN:
1871 df_reorganize_refs_by_insn (&df->use_info, false, true, false);
1874 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1875 df_reorganize_refs_by_insn (&df->use_info, false, true, true);
1878 case DF_REF_ORDER_NO_TABLE:
1879 free (df->use_info.refs);
1880 df->use_info.refs = NULL;
1881 df->use_info.refs_size = 0;
1884 case DF_REF_ORDER_UNORDERED:
1885 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1890 df->use_info.ref_order = order;
1894 /* If the def refs in DF are not organized, reorganize them. */
1897 df_maybe_reorganize_def_refs (enum df_ref_order order)
1899 if (order == df->def_info.ref_order)
1904 case DF_REF_ORDER_BY_REG:
1905 df_reorganize_refs_by_reg (&df->def_info, true, false, false);
1908 case DF_REF_ORDER_BY_INSN:
1909 df_reorganize_refs_by_insn (&df->def_info, true, false, false);
1912 case DF_REF_ORDER_NO_TABLE:
1913 free (df->def_info.refs);
1914 df->def_info.refs = NULL;
1915 df->def_info.refs_size = 0;
1918 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1919 case DF_REF_ORDER_BY_REG_WITH_NOTES:
1920 case DF_REF_ORDER_UNORDERED:
1921 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1926 df->def_info.ref_order = order;
1930 /* Change all of the basic block references in INSN to use the insn's
1931 current basic block. This function is called from routines that move
1932 instructions from one block to another. */
1935 df_insn_change_bb (rtx insn, basic_block new_bb)
1937 basic_block old_bb = BLOCK_FOR_INSN (insn);
1938 struct df_insn_info *insn_info;
1939 unsigned int uid = INSN_UID (insn);
1941 if (old_bb == new_bb)
1944 set_block_for_insn (insn, new_bb);
1950 fprintf (dump_file, "changing bb of uid %d\n", uid);
1952 insn_info = DF_INSN_UID_SAFE_GET (uid);
1953 if (insn_info == NULL)
1956 fprintf (dump_file, " unscanned insn\n");
1957 df_insn_rescan (insn);
1964 df_set_bb_dirty (new_bb);
1968 fprintf (dump_file, " from %d to %d\n",
1969 old_bb->index, new_bb->index);
1970 df_set_bb_dirty (old_bb);
1974 fprintf (dump_file, " to %d\n", new_bb->index);
1978 /* Helper function for df_ref_change_reg_with_loc. */
1981 df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df,
1982 struct df_reg_info *new_df,
1983 int new_regno, rtx loc)
1985 df_ref the_ref = old_df->reg_chain;
1989 if ((!DF_REF_IS_ARTIFICIAL (the_ref))
1990 && DF_REF_LOC (the_ref)
1991 && (*DF_REF_LOC (the_ref) == loc))
1993 df_ref next_ref = DF_REF_NEXT_REG (the_ref);
1994 df_ref prev_ref = DF_REF_PREV_REG (the_ref);
1995 df_ref *ref_vec, *ref_vec_t;
1996 struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref);
1997 unsigned int count = 0;
1999 DF_REF_REGNO (the_ref) = new_regno;
2000 DF_REF_REG (the_ref) = regno_reg_rtx[new_regno];
2002 /* Pull the_ref out of the old regno chain. */
2004 DF_REF_NEXT_REG (prev_ref) = next_ref;
2006 old_df->reg_chain = next_ref;
2008 DF_REF_PREV_REG (next_ref) = prev_ref;
2011 /* Put the ref into the new regno chain. */
2012 DF_REF_PREV_REG (the_ref) = NULL;
2013 DF_REF_NEXT_REG (the_ref) = new_df->reg_chain;
2014 if (new_df->reg_chain)
2015 DF_REF_PREV_REG (new_df->reg_chain) = the_ref;
2016 new_df->reg_chain = the_ref;
2018 if (DF_REF_BB (the_ref))
2019 df_set_bb_dirty (DF_REF_BB (the_ref));
2021 /* Need to sort the record again that the ref was in because
2022 the regno is a sorting key. First, find the right
2024 if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE)
2025 ref_vec = insn_info->eq_uses;
2027 ref_vec = insn_info->uses;
2029 fprintf (dump_file, "changing reg in insn %d\n",
2030 DF_REF_INSN_UID (the_ref));
2032 ref_vec_t = ref_vec;
2034 /* Find the length. */
2040 qsort (ref_vec, count, sizeof (df_ref ), df_ref_compare);
2045 the_ref = DF_REF_NEXT_REG (the_ref);
2050 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2051 NEW_REGNO. Refs that do not match LOC are not changed which means
2052 that artificial refs are not changed since they have no loc. This
2053 call is to support the SET_REGNO macro. */
2056 df_ref_change_reg_with_loc (int old_regno, int new_regno, rtx loc)
2058 if ((!df) || (old_regno == -1) || (old_regno == new_regno))
2061 df_grow_reg_info ();
2063 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno),
2064 DF_REG_DEF_GET (new_regno), new_regno, loc);
2065 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno),
2066 DF_REG_USE_GET (new_regno), new_regno, loc);
2067 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno),
2068 DF_REG_EQ_USE_GET (new_regno), new_regno, loc);
2072 /* Delete the mw_hardregs that point into the eq_notes. */
2075 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info)
2077 struct df_mw_hardreg **mw_vec = insn_info->mw_hardregs;
2078 unsigned int deleted = 0;
2079 unsigned int count = 0;
2080 struct df_scan_problem_data *problem_data
2081 = (struct df_scan_problem_data *) df_scan->problem_data;
2088 if ((*mw_vec)->flags & DF_REF_IN_NOTE)
2090 struct df_mw_hardreg **temp_vec = mw_vec;
2092 pool_free (problem_data->mw_reg_pool, *mw_vec);
2094 /* Shove the remaining ones down one to fill the gap. While
2095 this looks n**2, it is highly unusual to have any mw regs
2096 in eq_notes and the chances of more than one are almost
2100 *temp_vec = *(temp_vec + 1);
2114 df_scan_free_mws_vec (insn_info->mw_hardregs);
2115 insn_info->mw_hardregs = df_null_mw_rec;
2122 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2125 df_notes_rescan (rtx insn)
2127 struct df_insn_info *insn_info;
2128 unsigned int uid = INSN_UID (insn);
2133 /* The client has disabled rescanning and plans to do it itself. */
2134 if (df->changeable_flags & DF_NO_INSN_RESCAN)
2137 /* Do nothing if the insn hasn't been emitted yet. */
2138 if (!BLOCK_FOR_INSN (insn))
2141 df_grow_bb_info (df_scan);
2142 df_grow_reg_info ();
2144 insn_info = DF_INSN_UID_SAFE_GET (INSN_UID(insn));
2146 /* The client has deferred rescanning. */
2147 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
2151 insn_info = df_insn_create_insn_record (insn);
2152 insn_info->defs = df_null_ref_rec;
2153 insn_info->uses = df_null_ref_rec;
2154 insn_info->eq_uses = df_null_ref_rec;
2155 insn_info->mw_hardregs = df_null_mw_rec;
2158 bitmap_clear_bit (&df->insns_to_delete, uid);
2159 /* If the insn is set to be rescanned, it does not need to also
2160 be notes rescanned. */
2161 if (!bitmap_bit_p (&df->insns_to_rescan, uid))
2162 bitmap_set_bit (&df->insns_to_notes_rescan, INSN_UID (insn));
2166 bitmap_clear_bit (&df->insns_to_delete, uid);
2167 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
2171 basic_block bb = BLOCK_FOR_INSN (insn);
2173 struct df_collection_rec collection_rec;
2174 unsigned int num_deleted;
2175 unsigned int mw_len;
2177 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
2178 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
2179 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
2181 num_deleted = df_mw_hardreg_chain_delete_eq_uses (insn_info);
2182 df_ref_chain_delete (insn_info->eq_uses);
2183 insn_info->eq_uses = NULL;
2185 /* Process REG_EQUIV/REG_EQUAL notes */
2186 for (note = REG_NOTES (insn); note;
2187 note = XEXP (note, 1))
2189 switch (REG_NOTE_KIND (note))
2193 df_uses_record (&collection_rec,
2194 &XEXP (note, 0), DF_REF_REG_USE,
2195 bb, insn_info, DF_REF_IN_NOTE);
2201 /* Find some place to put any new mw_hardregs. */
2202 df_canonize_collection_rec (&collection_rec);
2203 mw_len = VEC_length (df_mw_hardreg_ptr, collection_rec.mw_vec);
2206 unsigned int count = 0;
2207 struct df_mw_hardreg **mw_rec = insn_info->mw_hardregs;
2216 /* Append to the end of the existing record after
2217 expanding it if necessary. */
2218 if (mw_len > num_deleted)
2220 insn_info->mw_hardregs =
2221 XRESIZEVEC (struct df_mw_hardreg *,
2222 insn_info->mw_hardregs,
2223 count + 1 + mw_len);
2225 memcpy (&insn_info->mw_hardregs[count],
2226 VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2227 mw_len * sizeof (struct df_mw_hardreg *));
2228 insn_info->mw_hardregs[count + mw_len] = NULL;
2229 qsort (insn_info->mw_hardregs, count + mw_len,
2230 sizeof (struct df_mw_hardreg *), df_mw_compare);
2234 /* No vector there. */
2235 insn_info->mw_hardregs
2236 = XNEWVEC (struct df_mw_hardreg*, 1 + mw_len);
2237 memcpy (insn_info->mw_hardregs,
2238 VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2239 mw_len * sizeof (struct df_mw_hardreg *));
2240 insn_info->mw_hardregs[mw_len] = NULL;
2243 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2245 VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
2246 df_refs_add_to_chains (&collection_rec, bb, insn);
2247 VEC_free (df_ref, stack, collection_rec.eq_use_vec);
2250 df_insn_rescan (insn);
2255 /*----------------------------------------------------------------------------
2256 Hard core instruction scanning code. No external interfaces here,
2257 just a lot of routines that look inside insns.
2258 ----------------------------------------------------------------------------*/
2261 /* Return true if the contents of two df_ref's are identical.
2262 It ignores DF_REF_MARKER. */
2265 df_ref_equal_p (df_ref ref1, df_ref ref2)
2273 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)
2274 || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)
2275 || DF_REF_REG (ref1) != DF_REF_REG (ref2)
2276 || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)
2277 || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))
2278 != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)))
2279 || DF_REF_BB (ref1) != DF_REF_BB (ref2)
2280 || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2))
2283 switch (DF_REF_CLASS (ref1))
2285 case DF_REF_ARTIFICIAL:
2289 case DF_REF_REGULAR:
2290 return DF_REF_LOC (ref1) == DF_REF_LOC (ref2);
2299 /* Compare REF1 and REF2 for sorting. This is only called from places
2300 where all of the refs are of the same type, in the same insn, and
2301 have the same bb. So these fields are not checked. */
2304 df_ref_compare (const void *r1, const void *r2)
2306 const df_ref ref1 = *(const df_ref *)r1;
2307 const df_ref ref2 = *(const df_ref *)r2;
2312 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
2313 return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
2315 if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
2316 return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
2318 if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
2319 return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
2321 if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
2322 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2324 /* Cannot look at the LOC field on artificial refs. */
2325 if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
2326 && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
2327 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2329 if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
2331 /* If two refs are identical except that one of them has is from
2332 a mw and one is not, we need to have the one with the mw
2334 if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) ==
2335 DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG))
2336 return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2);
2337 else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG))
2343 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2347 df_swap_refs (VEC(df_ref,stack) **ref_vec, int i, int j)
2349 df_ref tmp = VEC_index (df_ref, *ref_vec, i);
2350 VEC_replace (df_ref, *ref_vec, i, VEC_index (df_ref, *ref_vec, j));
2351 VEC_replace (df_ref, *ref_vec, j, tmp);
2354 /* Sort and compress a set of refs. */
2357 df_sort_and_compress_refs (VEC(df_ref,stack) **ref_vec)
2361 unsigned int dist = 0;
2363 count = VEC_length (df_ref, *ref_vec);
2365 /* If there are 1 or 0 elements, there is nothing to do. */
2368 else if (count == 2)
2370 df_ref r0 = VEC_index (df_ref, *ref_vec, 0);
2371 df_ref r1 = VEC_index (df_ref, *ref_vec, 1);
2372 if (df_ref_compare (&r0, &r1) > 0)
2373 df_swap_refs (ref_vec, 0, 1);
2377 for (i = 0; i < count - 1; i++)
2379 df_ref r0 = VEC_index (df_ref, *ref_vec, i);
2380 df_ref r1 = VEC_index (df_ref, *ref_vec, i + 1);
2381 if (df_ref_compare (&r0, &r1) >= 0)
2384 /* If the array is already strictly ordered,
2385 which is the most common case for large COUNT case
2386 (which happens for CALL INSNs),
2387 no need to sort and filter out duplicate.
2388 Simply return the count.
2389 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2390 of DF_REF_COMPARE. */
2393 VEC_qsort (df_ref, *ref_vec, df_ref_compare);
2396 for (i=0; i<count-dist; i++)
2398 /* Find the next ref that is not equal to the current ref. */
2399 while (i + dist + 1 < count
2400 && df_ref_equal_p (VEC_index (df_ref, *ref_vec, i),
2401 VEC_index (df_ref, *ref_vec, i + dist + 1)))
2403 df_free_ref (VEC_index (df_ref, *ref_vec, i + dist + 1));
2406 /* Copy it down to the next position. */
2407 if (dist && i + dist + 1 < count)
2408 VEC_replace (df_ref, *ref_vec, i + 1,
2409 VEC_index (df_ref, *ref_vec, i + dist + 1));
2413 VEC_truncate (df_ref, *ref_vec, count);
2417 /* Return true if the contents of two df_ref's are identical.
2418 It ignores DF_REF_MARKER. */
2421 df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2)
2425 return (mw1 == mw2) ||
2426 (mw1->mw_reg == mw2->mw_reg
2427 && mw1->type == mw2->type
2428 && mw1->flags == mw2->flags
2429 && mw1->start_regno == mw2->start_regno
2430 && mw1->end_regno == mw2->end_regno);
2434 /* Compare MW1 and MW2 for sorting. */
2437 df_mw_compare (const void *m1, const void *m2)
2439 const struct df_mw_hardreg *const mw1 = *(const struct df_mw_hardreg *const*)m1;
2440 const struct df_mw_hardreg *const mw2 = *(const struct df_mw_hardreg *const*)m2;
2445 if (mw1->type != mw2->type)
2446 return mw1->type - mw2->type;
2448 if (mw1->flags != mw2->flags)
2449 return mw1->flags - mw2->flags;
2451 if (mw1->start_regno != mw2->start_regno)
2452 return mw1->start_regno - mw2->start_regno;
2454 if (mw1->end_regno != mw2->end_regno)
2455 return mw1->end_regno - mw2->end_regno;
2457 if (mw1->mw_reg != mw2->mw_reg)
2458 return mw1->mw_order - mw2->mw_order;
2464 /* Sort and compress a set of refs. */
2467 df_sort_and_compress_mws (VEC(df_mw_hardreg_ptr,stack) **mw_vec)
2470 struct df_scan_problem_data *problem_data
2471 = (struct df_scan_problem_data *) df_scan->problem_data;
2473 unsigned int dist = 0;
2475 count = VEC_length (df_mw_hardreg_ptr, *mw_vec);
2478 else if (count == 2)
2480 struct df_mw_hardreg *m0 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 0);
2481 struct df_mw_hardreg *m1 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 1);
2482 if (df_mw_compare (&m0, &m1) > 0)
2484 struct df_mw_hardreg *tmp = VEC_index (df_mw_hardreg_ptr,
2486 VEC_replace (df_mw_hardreg_ptr, *mw_vec, 0,
2487 VEC_index (df_mw_hardreg_ptr, *mw_vec, 1));
2488 VEC_replace (df_mw_hardreg_ptr, *mw_vec, 1, tmp);
2492 VEC_qsort (df_mw_hardreg_ptr, *mw_vec, df_mw_compare);
2494 for (i=0; i<count-dist; i++)
2496 /* Find the next ref that is not equal to the current ref. */
2497 while (i + dist + 1 < count
2498 && df_mw_equal_p (VEC_index (df_mw_hardreg_ptr, *mw_vec, i),
2499 VEC_index (df_mw_hardreg_ptr, *mw_vec,
2502 pool_free (problem_data->mw_reg_pool,
2503 VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2506 /* Copy it down to the next position. */
2507 if (dist && i + dist + 1 < count)
2508 VEC_replace (df_mw_hardreg_ptr, *mw_vec, i + 1,
2509 VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2513 VEC_truncate (df_mw_hardreg_ptr, *mw_vec, count);
2517 /* Sort and remove duplicates from the COLLECTION_REC. */
2520 df_canonize_collection_rec (struct df_collection_rec *collection_rec)
2522 df_sort_and_compress_refs (&collection_rec->def_vec);
2523 df_sort_and_compress_refs (&collection_rec->use_vec);
2524 df_sort_and_compress_refs (&collection_rec->eq_use_vec);
2525 df_sort_and_compress_mws (&collection_rec->mw_vec);
2529 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2532 df_install_ref (df_ref this_ref,
2533 struct df_reg_info *reg_info,
2534 struct df_ref_info *ref_info,
2537 unsigned int regno = DF_REF_REGNO (this_ref);
2538 /* Add the ref to the reg_{def,use,eq_use} chain. */
2539 df_ref head = reg_info->reg_chain;
2541 reg_info->reg_chain = this_ref;
2544 if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE))
2546 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
2547 df->hard_regs_live_count[regno]++;
2550 gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL
2551 && DF_REF_PREV_REG (this_ref) == NULL);
2553 DF_REF_NEXT_REG (this_ref) = head;
2555 /* We cannot actually link to the head of the chain. */
2556 DF_REF_PREV_REG (this_ref) = NULL;
2559 DF_REF_PREV_REG (head) = this_ref;
2563 gcc_assert (ref_info->ref_order != DF_REF_ORDER_NO_TABLE);
2564 df_check_and_grow_ref_info (ref_info, 1);
2565 DF_REF_ID (this_ref) = ref_info->table_size;
2566 /* Add the ref to the big array of defs. */
2567 ref_info->refs[ref_info->table_size] = this_ref;
2568 ref_info->table_size++;
2571 DF_REF_ID (this_ref) = -1;
2573 ref_info->total_size++;
2577 /* This function takes one of the groups of refs (defs, uses or
2578 eq_uses) and installs the entire group into the insn. It also adds
2579 each of these refs into the appropriate chains. */
2582 df_install_refs (basic_block bb,
2583 VEC(df_ref,stack)* old_vec,
2584 struct df_reg_info **reg_info,
2585 struct df_ref_info *ref_info,
2590 count = VEC_length (df_ref, old_vec);
2593 df_ref *new_vec = XNEWVEC (df_ref, count + 1);
2598 switch (ref_info->ref_order)
2600 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
2601 case DF_REF_ORDER_BY_REG_WITH_NOTES:
2602 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
2603 ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
2604 add_to_table = true;
2606 case DF_REF_ORDER_UNORDERED:
2607 case DF_REF_ORDER_BY_REG:
2608 case DF_REF_ORDER_BY_INSN:
2609 ref_info->ref_order = DF_REF_ORDER_UNORDERED;
2610 add_to_table = !is_notes;
2613 add_to_table = false;
2617 /* Do not add if ref is not in the right blocks. */
2618 if (add_to_table && df->analyze_subset)
2619 add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
2621 FOR_EACH_VEC_ELT (df_ref, old_vec, ix, this_ref)
2623 new_vec[ix] = this_ref;
2624 df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)],
2625 ref_info, add_to_table);
2628 new_vec[count] = NULL;
2632 return df_null_ref_rec;
2636 /* This function takes the mws installs the entire group into the
2639 static struct df_mw_hardreg **
2640 df_install_mws (VEC(df_mw_hardreg_ptr,stack) *old_vec)
2644 count = VEC_length (df_mw_hardreg_ptr, old_vec);
2647 struct df_mw_hardreg **new_vec
2648 = XNEWVEC (struct df_mw_hardreg*, count + 1);
2649 memcpy (new_vec, VEC_address (df_mw_hardreg_ptr, old_vec),
2650 sizeof (struct df_mw_hardreg*) * count);
2651 new_vec[count] = NULL;
2655 return df_null_mw_rec;
2659 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2660 chains and update other necessary information. */
2663 df_refs_add_to_chains (struct df_collection_rec *collection_rec,
2664 basic_block bb, rtx insn)
2668 struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn);
2669 /* If there is a vector in the collection rec, add it to the
2670 insn. A null rec is a signal that the caller will handle the
2672 if (collection_rec->def_vec)
2674 df_scan_free_ref_vec (insn_rec->defs);
2676 = df_install_refs (bb, collection_rec->def_vec,
2678 &df->def_info, false);
2680 if (collection_rec->use_vec)
2682 df_scan_free_ref_vec (insn_rec->uses);
2684 = df_install_refs (bb, collection_rec->use_vec,
2686 &df->use_info, false);
2688 if (collection_rec->eq_use_vec)
2690 df_scan_free_ref_vec (insn_rec->eq_uses);
2692 = df_install_refs (bb, collection_rec->eq_use_vec,
2694 &df->use_info, true);
2696 if (collection_rec->mw_vec)
2698 df_scan_free_mws_vec (insn_rec->mw_hardregs);
2699 insn_rec->mw_hardregs
2700 = df_install_mws (collection_rec->mw_vec);
2705 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
2707 df_scan_free_ref_vec (bb_info->artificial_defs);
2708 bb_info->artificial_defs
2709 = df_install_refs (bb, collection_rec->def_vec,
2711 &df->def_info, false);
2712 df_scan_free_ref_vec (bb_info->artificial_uses);
2713 bb_info->artificial_uses
2714 = df_install_refs (bb, collection_rec->use_vec,
2716 &df->use_info, false);
2721 /* Allocate a ref and initialize its fields. */
2724 df_ref_create_structure (enum df_ref_class cl,
2725 struct df_collection_rec *collection_rec,
2727 basic_block bb, struct df_insn_info *info,
2728 enum df_ref_type ref_type,
2731 df_ref this_ref = NULL;
2732 int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2733 struct df_scan_problem_data *problem_data
2734 = (struct df_scan_problem_data *) df_scan->problem_data;
2739 this_ref = (df_ref) pool_alloc (problem_data->ref_base_pool);
2740 gcc_checking_assert (loc == NULL);
2743 case DF_REF_ARTIFICIAL:
2744 this_ref = (df_ref) pool_alloc (problem_data->ref_artificial_pool);
2745 this_ref->artificial_ref.bb = bb;
2746 gcc_checking_assert (loc == NULL);
2749 case DF_REF_REGULAR:
2750 this_ref = (df_ref) pool_alloc (problem_data->ref_regular_pool);
2751 this_ref->regular_ref.loc = loc;
2752 gcc_checking_assert (loc);
2756 DF_REF_CLASS (this_ref) = cl;
2757 DF_REF_ID (this_ref) = -1;
2758 DF_REF_REG (this_ref) = reg;
2759 DF_REF_REGNO (this_ref) = regno;
2760 DF_REF_TYPE (this_ref) = ref_type;
2761 DF_REF_INSN_INFO (this_ref) = info;
2762 DF_REF_CHAIN (this_ref) = NULL;
2763 DF_REF_FLAGS (this_ref) = ref_flags;
2764 DF_REF_NEXT_REG (this_ref) = NULL;
2765 DF_REF_PREV_REG (this_ref) = NULL;
2766 DF_REF_ORDER (this_ref) = df->ref_order++;
2768 /* We need to clear this bit because fwprop, and in the future
2769 possibly other optimizations sometimes create new refs using ond
2770 refs as the model. */
2771 DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE);
2773 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2774 if ((regno < FIRST_PSEUDO_REGISTER)
2775 && (!DF_REF_IS_ARTIFICIAL (this_ref)))
2777 if (DF_REF_REG_DEF_P (this_ref))
2779 if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER))
2780 DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2782 else if (!(TEST_HARD_REG_BIT (elim_reg_set, regno)
2783 && (regno == FRAME_POINTER_REGNUM
2784 || regno == ARG_POINTER_REGNUM)))
2785 DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2790 if (DF_REF_REG_DEF_P (this_ref))
2791 VEC_safe_push (df_ref, stack, collection_rec->def_vec, this_ref);
2792 else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE)
2793 VEC_safe_push (df_ref, stack, collection_rec->eq_use_vec, this_ref);
2795 VEC_safe_push (df_ref, stack, collection_rec->use_vec, this_ref);
2802 /* Create new references of type DF_REF_TYPE for each part of register REG
2803 at address LOC within INSN of BB. */
2807 df_ref_record (enum df_ref_class cl,
2808 struct df_collection_rec *collection_rec,
2810 basic_block bb, struct df_insn_info *insn_info,
2811 enum df_ref_type ref_type,
2816 gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
2818 regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2819 if (regno < FIRST_PSEUDO_REGISTER)
2821 struct df_mw_hardreg *hardreg = NULL;
2822 struct df_scan_problem_data *problem_data
2823 = (struct df_scan_problem_data *) df_scan->problem_data;
2825 unsigned int endregno;
2828 if (GET_CODE (reg) == SUBREG)
2830 regno += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
2831 SUBREG_BYTE (reg), GET_MODE (reg));
2832 endregno = regno + subreg_nregs (reg);
2835 endregno = END_HARD_REGNO (reg);
2837 /* If this is a multiword hardreg, we create some extra
2838 datastructures that will enable us to easily build REG_DEAD
2839 and REG_UNUSED notes. */
2840 if ((endregno != regno + 1) && insn_info)
2842 /* Sets to a subreg of a multiword register are partial.
2843 Sets to a non-subreg of a multiword register are not. */
2844 if (GET_CODE (reg) == SUBREG)
2845 ref_flags |= DF_REF_PARTIAL;
2846 ref_flags |= DF_REF_MW_HARDREG;
2848 hardreg = (struct df_mw_hardreg *) pool_alloc (problem_data->mw_reg_pool);
2849 hardreg->type = ref_type;
2850 hardreg->flags = ref_flags;
2851 hardreg->mw_reg = reg;
2852 hardreg->start_regno = regno;
2853 hardreg->end_regno = endregno - 1;
2854 hardreg->mw_order = df->ref_order++;
2855 VEC_safe_push (df_mw_hardreg_ptr, stack, collection_rec->mw_vec,
2859 for (i = regno; i < endregno; i++)
2861 ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc,
2862 bb, insn_info, ref_type, ref_flags);
2864 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i);
2869 df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info,
2870 ref_type, ref_flags);
2875 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2876 covered by the outer mode is smaller than that covered by the inner mode,
2877 is a read-modify-write operation.
2878 This function returns true iff the SUBREG X is such a SUBREG. */
2881 df_read_modify_subreg_p (rtx x)
2883 unsigned int isize, osize;
2884 if (GET_CODE (x) != SUBREG)
2886 isize = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
2887 osize = GET_MODE_SIZE (GET_MODE (x));
2888 return isize > osize
2889 && isize > REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x)));
2893 /* Process all the registers defined in the rtx, X.
2894 Autoincrement/decrement definitions will be picked up by
2898 df_def_record_1 (struct df_collection_rec *collection_rec,
2899 rtx x, basic_block bb, struct df_insn_info *insn_info,
2905 /* We may recursively call ourselves on EXPR_LIST when dealing with PARALLEL
2907 if (GET_CODE (x) == EXPR_LIST || GET_CODE (x) == CLOBBER)
2910 loc = &SET_DEST (x);
2913 /* It is legal to have a set destination be a parallel. */
2914 if (GET_CODE (dst) == PARALLEL)
2918 for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
2920 rtx temp = XVECEXP (dst, 0, i);
2921 if (GET_CODE (temp) == EXPR_LIST || GET_CODE (temp) == CLOBBER
2922 || GET_CODE (temp) == SET)
2923 df_def_record_1 (collection_rec,
2924 temp, bb, insn_info,
2925 GET_CODE (temp) == CLOBBER
2926 ? flags | DF_REF_MUST_CLOBBER : flags);
2931 if (GET_CODE (dst) == STRICT_LOW_PART)
2933 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;
2935 loc = &XEXP (dst, 0);
2939 if (GET_CODE (dst) == ZERO_EXTRACT)
2941 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;
2943 loc = &XEXP (dst, 0);
2947 /* At this point if we do not have a reg or a subreg, just return. */
2950 df_ref_record (DF_REF_REGULAR, collection_rec,
2951 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
2953 /* We want to keep sp alive everywhere - by making all
2954 writes to sp also use of sp. */
2955 if (REGNO (dst) == STACK_POINTER_REGNUM)
2956 df_ref_record (DF_REF_BASE, collection_rec,
2957 dst, NULL, bb, insn_info, DF_REF_REG_USE, flags);
2959 else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
2961 if (df_read_modify_subreg_p (dst))
2962 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;
2964 flags |= DF_REF_SUBREG;
2966 df_ref_record (DF_REF_REGULAR, collection_rec,
2967 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
2972 /* Process all the registers defined in the pattern rtx, X. */
2975 df_defs_record (struct df_collection_rec *collection_rec,
2976 rtx x, basic_block bb, struct df_insn_info *insn_info,
2979 RTX_CODE code = GET_CODE (x);
2981 if (code == SET || code == CLOBBER)
2983 /* Mark the single def within the pattern. */
2984 int clobber_flags = flags;
2985 clobber_flags |= (code == CLOBBER) ? DF_REF_MUST_CLOBBER : 0;
2986 df_def_record_1 (collection_rec, x, bb, insn_info, clobber_flags);
2988 else if (code == COND_EXEC)
2990 df_defs_record (collection_rec, COND_EXEC_CODE (x),
2991 bb, insn_info, DF_REF_CONDITIONAL);
2993 else if (code == PARALLEL)
2997 /* Mark the multiple defs within the pattern. */
2998 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2999 df_defs_record (collection_rec, XVECEXP (x, 0, i), bb, insn_info, flags);
3004 /* Process all the registers used in the rtx at address LOC. */
3007 df_uses_record (struct df_collection_rec *collection_rec,
3008 rtx *loc, enum df_ref_type ref_type,
3009 basic_block bb, struct df_insn_info *insn_info,
3019 code = GET_CODE (x);
3036 /* If we are clobbering a MEM, mark any registers inside the address
3038 if (MEM_P (XEXP (x, 0)))
3039 df_uses_record (collection_rec,
3040 &XEXP (XEXP (x, 0), 0),
3041 DF_REF_REG_MEM_STORE,
3045 /* If we're clobbering a REG then we have a def so ignore. */
3049 df_uses_record (collection_rec,
3050 &XEXP (x, 0), DF_REF_REG_MEM_LOAD,
3051 bb, insn_info, flags & DF_REF_IN_NOTE);
3055 /* While we're here, optimize this case. */
3056 flags |= DF_REF_PARTIAL;
3057 /* In case the SUBREG is not of a REG, do not optimize. */
3058 if (!REG_P (SUBREG_REG (x)))
3060 loc = &SUBREG_REG (x);
3061 df_uses_record (collection_rec, loc, ref_type, bb, insn_info, flags);
3064 /* ... Fall through ... */
3067 df_ref_record (DF_REF_REGULAR, collection_rec,
3068 x, loc, bb, insn_info,
3075 df_uses_record (collection_rec,
3076 &XEXP (x, 1), ref_type, bb, insn_info, flags);
3077 df_uses_record (collection_rec,
3078 &XEXP (x, 2), ref_type, bb, insn_info, flags);
3080 /* If the parameters to the zero or sign extract are
3081 constants, strip them off and recurse, otherwise there is
3082 no information that we can gain from this operation. */
3083 if (code == ZERO_EXTRACT)
3084 flags |= DF_REF_ZERO_EXTRACT;
3086 flags |= DF_REF_SIGN_EXTRACT;
3088 df_uses_record (collection_rec,
3089 &XEXP (x, 0), ref_type, bb, insn_info, flags);
3096 rtx dst = SET_DEST (x);
3097 gcc_assert (!(flags & DF_REF_IN_NOTE));
3098 df_uses_record (collection_rec,
3099 &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags);
3101 switch (GET_CODE (dst))
3104 if (df_read_modify_subreg_p (dst))
3106 df_uses_record (collection_rec, &SUBREG_REG (dst),
3107 DF_REF_REG_USE, bb, insn_info,
3108 flags | DF_REF_READ_WRITE | DF_REF_SUBREG);
3119 df_uses_record (collection_rec, &XEXP (dst, 0),
3120 DF_REF_REG_MEM_STORE, bb, insn_info, flags);
3122 case STRICT_LOW_PART:
3124 rtx *temp = &XEXP (dst, 0);
3125 /* A strict_low_part uses the whole REG and not just the
3127 dst = XEXP (dst, 0);
3128 df_uses_record (collection_rec,
3129 (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
3130 DF_REF_REG_USE, bb, insn_info,
3131 DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART);
3136 df_uses_record (collection_rec, &XEXP (dst, 1),
3137 DF_REF_REG_USE, bb, insn_info, flags);
3138 df_uses_record (collection_rec, &XEXP (dst, 2),
3139 DF_REF_REG_USE, bb, insn_info, flags);
3140 if (GET_CODE (XEXP (dst,0)) == MEM)
3141 df_uses_record (collection_rec, &XEXP (dst, 0),
3142 DF_REF_REG_USE, bb, insn_info,
3145 df_uses_record (collection_rec, &XEXP (dst, 0),
3146 DF_REF_REG_USE, bb, insn_info,
3147 DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT);
3161 case UNSPEC_VOLATILE:
3165 /* Traditional and volatile asm instructions must be
3166 considered to use and clobber all hard registers, all
3167 pseudo-registers and all of memory. So must TRAP_IF and
3168 UNSPEC_VOLATILE operations.
3170 Consider for instance a volatile asm that changes the fpu
3171 rounding mode. An insn should not be moved across this
3172 even if it only uses pseudo-regs because it might give an
3173 incorrectly rounded result.
3175 However, flow.c's liveness computation did *not* do this,
3176 giving the reasoning as " ?!? Unfortunately, marking all
3177 hard registers as live causes massive problems for the
3178 register allocator and marking all pseudos as live creates
3179 mountains of uninitialized variable warnings."
3181 In order to maintain the status quo with regard to liveness
3182 and uses, we do what flow.c did and just mark any regs we
3183 can find in ASM_OPERANDS as used. In global asm insns are
3184 scanned and regs_asm_clobbered is filled out.
3186 For all ASM_OPERANDS, we must traverse the vector of input
3187 operands. We can not just fall through here since then we
3188 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3189 which do not indicate traditional asms unlike their normal
3191 if (code == ASM_OPERANDS)
3195 for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
3196 df_uses_record (collection_rec, &ASM_OPERANDS_INPUT (x, j),
3197 DF_REF_REG_USE, bb, insn_info, flags);
3204 df_uses_record (collection_rec,
3205 &PAT_VAR_LOCATION_LOC (x),
3206 DF_REF_REG_USE, bb, insn_info, flags);
3215 gcc_assert (!DEBUG_INSN_P (insn_info->insn));
3216 /* Catch the def of the register being modified. */
3217 df_ref_record (DF_REF_REGULAR, collection_rec, XEXP (x, 0), &XEXP (x, 0),
3220 flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY);
3222 /* ... Fall through to handle uses ... */
3228 /* Recursively scan the operands of this expression. */
3230 const char *fmt = GET_RTX_FORMAT (code);
3233 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3237 /* Tail recursive case: save a function call level. */
3243 df_uses_record (collection_rec, &XEXP (x, i), ref_type,
3244 bb, insn_info, flags);
3246 else if (fmt[i] == 'E')
3249 for (j = 0; j < XVECLEN (x, i); j++)
3250 df_uses_record (collection_rec,
3251 &XVECEXP (x, i, j), ref_type,
3252 bb, insn_info, flags);
3261 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3264 df_get_conditional_uses (struct df_collection_rec *collection_rec)
3269 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
3271 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL))
3275 use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref),
3276 DF_REF_LOC (ref), DF_REF_BB (ref),
3277 DF_REF_INSN_INFO (ref), DF_REF_REG_USE,
3278 DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL);
3279 DF_REF_REGNO (use) = DF_REF_REGNO (ref);
3285 /* Get call's extra defs and uses. */
3288 df_get_call_refs (struct df_collection_rec * collection_rec,
3290 struct df_insn_info *insn_info,
3296 bool is_sibling_call;
3299 bitmap_head defs_generated;
3301 bitmap_initialize (&defs_generated, &df_bitmap_obstack);
3303 /* Do not generate clobbers for registers that are the result of the
3304 call. This causes ordering problems in the chain building code
3305 depending on which def is seen first. */
3306 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, i, def)
3307 bitmap_set_bit (&defs_generated, DF_REF_REGNO (def));
3309 /* Record the registers used to pass arguments, and explicitly
3310 noted as clobbered. */
3311 for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note;
3312 note = XEXP (note, 1))
3314 if (GET_CODE (XEXP (note, 0)) == USE)
3315 df_uses_record (collection_rec, &XEXP (XEXP (note, 0), 0),
3316 DF_REF_REG_USE, bb, insn_info, flags);
3317 else if (GET_CODE (XEXP (note, 0)) == CLOBBER)
3319 if (REG_P (XEXP (XEXP (note, 0), 0)))
3321 unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
3322 if (!bitmap_bit_p (&defs_generated, regno))
3323 df_defs_record (collection_rec, XEXP (note, 0), bb,
3327 df_uses_record (collection_rec, &XEXP (note, 0),
3328 DF_REF_REG_USE, bb, insn_info, flags);
3332 /* The stack ptr is used (honorarily) by a CALL insn. */
3333 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[STACK_POINTER_REGNUM],
3334 NULL, bb, insn_info, DF_REF_REG_USE,
3335 DF_REF_CALL_STACK_USAGE | flags);
3337 /* Calls may also reference any of the global registers,
3338 so they are recorded as used. */
3339 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3342 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3343 NULL, bb, insn_info, DF_REF_REG_USE, flags);
3344 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3345 NULL, bb, insn_info, DF_REF_REG_DEF, flags);
3348 is_sibling_call = SIBLING_CALL_P (insn_info->insn);
3349 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, ui, bi)
3351 if (!global_regs[ui]
3352 && (!bitmap_bit_p (&defs_generated, ui))
3353 && (!is_sibling_call
3354 || !bitmap_bit_p (df->exit_block_uses, ui)
3355 || refers_to_regno_p (ui, ui+1,
3356 crtl->return_rtx, NULL)))
3357 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[ui],
3358 NULL, bb, insn_info, DF_REF_REG_DEF,
3359 DF_REF_MAY_CLOBBER | flags);
3362 bitmap_clear (&defs_generated);
3366 /* Collect all refs in the INSN. This function is free of any
3367 side-effect - it will create and return a lists of df_ref's in the
3368 COLLECTION_REC without putting those refs into existing ref chains
3372 df_insn_refs_collect (struct df_collection_rec* collection_rec,
3373 basic_block bb, struct df_insn_info *insn_info)
3376 bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC);
3378 /* Clear out the collection record. */
3379 VEC_truncate (df_ref, collection_rec->def_vec, 0);
3380 VEC_truncate (df_ref, collection_rec->use_vec, 0);
3381 VEC_truncate (df_ref, collection_rec->eq_use_vec, 0);
3382 VEC_truncate (df_mw_hardreg_ptr, collection_rec->mw_vec, 0);
3384 /* Record register defs. */
3385 df_defs_record (collection_rec, PATTERN (insn_info->insn), bb, insn_info, 0);
3387 /* Process REG_EQUIV/REG_EQUAL notes. */
3388 for (note = REG_NOTES (insn_info->insn); note;
3389 note = XEXP (note, 1))
3391 switch (REG_NOTE_KIND (note))
3395 df_uses_record (collection_rec,
3396 &XEXP (note, 0), DF_REF_REG_USE,
3397 bb, insn_info, DF_REF_IN_NOTE);
3399 case REG_NON_LOCAL_GOTO:
3400 /* The frame ptr is used by a non-local goto. */
3401 df_ref_record (DF_REF_BASE, collection_rec,
3402 regno_reg_rtx[FRAME_POINTER_REGNUM],
3403 NULL, bb, insn_info,
3405 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3406 df_ref_record (DF_REF_BASE, collection_rec,
3407 regno_reg_rtx[HARD_FRAME_POINTER_REGNUM],
3408 NULL, bb, insn_info,
3417 if (CALL_P (insn_info->insn))
3418 df_get_call_refs (collection_rec, bb, insn_info,
3419 (is_cond_exec) ? DF_REF_CONDITIONAL : 0);
3421 /* Record the register uses. */
3422 df_uses_record (collection_rec,
3423 &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0);
3425 /* DF_REF_CONDITIONAL needs corresponding USES. */
3427 df_get_conditional_uses (collection_rec);
3429 df_canonize_collection_rec (collection_rec);
3432 /* Recompute the luids for the insns in BB. */
3435 df_recompute_luids (basic_block bb)
3440 df_grow_insn_info ();
3442 /* Scan the block an insn at a time from beginning to end. */
3443 FOR_BB_INSNS (bb, insn)
3445 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3446 /* Inserting labels does not always trigger the incremental
3450 gcc_assert (!INSN_P (insn));
3451 insn_info = df_insn_create_insn_record (insn);
3454 DF_INSN_INFO_LUID (insn_info) = luid;
3461 /* Collect all artificial refs at the block level for BB and add them
3462 to COLLECTION_REC. */
3465 df_bb_refs_collect (struct df_collection_rec *collection_rec, basic_block bb)
3467 VEC_truncate (df_ref, collection_rec->def_vec, 0);
3468 VEC_truncate (df_ref, collection_rec->use_vec, 0);
3469 VEC_truncate (df_ref, collection_rec->eq_use_vec, 0);
3470 VEC_truncate (df_mw_hardreg_ptr, collection_rec->mw_vec, 0);
3472 if (bb->index == ENTRY_BLOCK)
3474 df_entry_block_defs_collect (collection_rec, df->entry_block_defs);
3477 else if (bb->index == EXIT_BLOCK)
3479 df_exit_block_uses_collect (collection_rec, df->exit_block_uses);
3483 #ifdef EH_RETURN_DATA_REGNO
3484 if (bb_has_eh_pred (bb))
3487 /* Mark the registers that will contain data for the handler. */
3490 unsigned regno = EH_RETURN_DATA_REGNO (i);
3491 if (regno == INVALID_REGNUM)
3493 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3494 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
3499 /* Add the hard_frame_pointer if this block is the target of a
3501 if (bb->flags & BB_NON_LOCAL_GOTO_TARGET)
3502 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL,
3503 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
3505 /* Add the artificial uses. */
3506 if (bb->index >= NUM_FIXED_BLOCKS)
3510 bitmap au = bb_has_eh_pred (bb)
3511 ? &df->eh_block_artificial_uses
3512 : &df->regular_block_artificial_uses;
3514 EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi)
3516 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3517 bb, NULL, DF_REF_REG_USE, 0);
3521 df_canonize_collection_rec (collection_rec);
3525 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3528 df_bb_refs_record (int bb_index, bool scan_insns)
3530 basic_block bb = BASIC_BLOCK (bb_index);
3533 struct df_collection_rec collection_rec;
3538 df_grow_bb_info (df_scan);
3539 collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
3540 collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
3541 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
3542 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
3545 /* Scan the block an insn at a time from beginning to end. */
3546 FOR_BB_INSNS (bb, insn)
3548 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3549 gcc_assert (!insn_info);
3551 insn_info = df_insn_create_insn_record (insn);
3554 /* Record refs within INSN. */
3555 DF_INSN_INFO_LUID (insn_info) = luid++;
3556 df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn));
3557 df_refs_add_to_chains (&collection_rec, bb, insn);
3559 DF_INSN_INFO_LUID (insn_info) = luid;
3562 /* Other block level artificial refs */
3563 df_bb_refs_collect (&collection_rec, bb);
3564 df_refs_add_to_chains (&collection_rec, bb, NULL);
3566 VEC_free (df_ref, stack, collection_rec.def_vec);
3567 VEC_free (df_ref, stack, collection_rec.use_vec);
3568 VEC_free (df_ref, stack, collection_rec.eq_use_vec);
3569 VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
3571 /* Now that the block has been processed, set the block as dirty so
3572 LR and LIVE will get it processed. */
3573 df_set_bb_dirty (bb);
3577 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3581 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses)
3587 bitmap_clear (regular_block_artificial_uses);
3589 if (reload_completed)
3591 if (frame_pointer_needed)
3592 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3595 /* Before reload, there are a few registers that must be forced
3596 live everywhere -- which might not already be the case for
3597 blocks within infinite loops. */
3599 /* Any reference to any pseudo before reload is a potential
3600 reference of the frame pointer. */
3601 bitmap_set_bit (regular_block_artificial_uses, FRAME_POINTER_REGNUM);
3603 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3604 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3607 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3608 /* Pseudos with argument area equivalences may require
3609 reloading via the argument pointer. */
3610 if (fixed_regs[ARG_POINTER_REGNUM])
3611 bitmap_set_bit (regular_block_artificial_uses, ARG_POINTER_REGNUM);
3614 /* Any constant, or pseudo with constant equivalences, may
3615 require reloading from memory using the pic register. */
3616 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3617 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3618 bitmap_set_bit (regular_block_a