* config/sh/sh.c (push_regs): Emit movml for interrupt handler
[official-gcc.git] / gcc / df-scan.c
blobddd2387b2001e30fcc7d18f94e39e6f4d51ffc91
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
14 version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "recog.h"
33 #include "function.h"
34 #include "regs.h"
35 #include "output.h"
36 #include "alloc-pool.h"
37 #include "flags.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "sbitmap.h"
41 #include "bitmap.h"
42 #include "timevar.h"
43 #include "tree.h"
44 #include "target.h"
45 #include "target-def.h"
46 #include "df.h"
47 #include "tree-pass.h"
48 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
50 DEF_VEC_P(df_ref);
51 DEF_VEC_ALLOC_P_STACK(df_ref);
53 #define VEC_df_ref_stack_alloc(alloc) VEC_stack_alloc (df_ref, alloc)
55 typedef struct df_mw_hardreg *df_mw_hardreg_ptr;
57 DEF_VEC_P(df_mw_hardreg_ptr);
58 DEF_VEC_ALLOC_P_STACK(df_mw_hardreg_ptr);
60 #define VEC_df_mw_hardreg_ptr_stack_alloc(alloc) \
61 VEC_stack_alloc (df_mw_hardreg_ptr, alloc)
63 #ifndef HAVE_epilogue
64 #define HAVE_epilogue 0
65 #endif
66 #ifndef HAVE_prologue
67 #define HAVE_prologue 0
68 #endif
69 #ifndef HAVE_sibcall_epilogue
70 #define HAVE_sibcall_epilogue 0
71 #endif
73 #ifndef EPILOGUE_USES
74 #define EPILOGUE_USES(REGNO) 0
75 #endif
77 /* The following two macros free the vecs that hold either the refs or
78 the mw refs. They are a little tricky because the vec has 0
79 elements is special and is not to be freed. */
80 #define df_scan_free_ref_vec(V) \
81 do { \
82 if (V && *V) \
83 free (V); \
84 } while (0)
86 #define df_scan_free_mws_vec(V) \
87 do { \
88 if (V && *V) \
89 free (V); \
90 } while (0)
92 /* The set of hard registers in eliminables[i].from. */
94 static HARD_REG_SET elim_reg_set;
96 /* Initialize ur_in and ur_out as if all hard registers were partially
97 available. */
99 struct df_collection_rec
101 VEC(df_ref,stack) *def_vec;
102 VEC(df_ref,stack) *use_vec;
103 VEC(df_ref,stack) *eq_use_vec;
104 VEC(df_mw_hardreg_ptr,stack) *mw_vec;
107 static df_ref df_null_ref_rec[1];
108 static struct df_mw_hardreg * df_null_mw_rec[1];
110 static void df_ref_record (enum df_ref_class, struct df_collection_rec *,
111 rtx, rtx *,
112 basic_block, struct df_insn_info *,
113 enum df_ref_type, int ref_flags,
114 int, int, enum machine_mode);
115 static void df_def_record_1 (struct df_collection_rec *, rtx,
116 basic_block, struct df_insn_info *,
117 int ref_flags);
118 static void df_defs_record (struct df_collection_rec *, rtx,
119 basic_block, struct df_insn_info *,
120 int ref_flags);
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 *,
124 int ref_flags,
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, int 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 *,
149 basic_block, rtx);
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;
187 alloc_pool reg_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. */
197 static void
198 df_scan_free_internal (void)
200 struct df_scan_problem_data *problem_data
201 = (struct df_scan_problem_data *) df_scan->problem_data;
202 unsigned int i;
203 basic_block bb;
205 /* The vectors that hold the refs are not pool allocated because
206 they come in many sizes. This makes them impossible to delete
207 all at once. */
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
212 deleted. */
213 if (insn_info)
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);
222 FOR_ALL_BB (bb)
224 unsigned int bb_index = bb->index;
225 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
226 if (bb_info)
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)));
243 free (df->def_regs);
244 df->def_regs = NULL;
245 free (df->use_regs);
246 df->use_regs = NULL;
247 free (df->eq_use_regs);
248 df->eq_use_regs = NULL;
249 df->regs_size = 0;
250 DF_REG_SIZE(df) = 0;
252 free (df->insns);
253 df->insns = NULL;
254 DF_INSN_SIZE () = 0;
256 free (df_scan->block_info);
257 df_scan->block_info = NULL;
258 df_scan->block_info_size = 0;
260 bitmap_clear (&df->hardware_regs_used);
261 bitmap_clear (&df->regular_block_artificial_uses);
262 bitmap_clear (&df->eh_block_artificial_uses);
263 BITMAP_FREE (df->entry_block_defs);
264 BITMAP_FREE (df->exit_block_uses);
265 bitmap_clear (&df->insns_to_delete);
266 bitmap_clear (&df->insns_to_rescan);
267 bitmap_clear (&df->insns_to_notes_rescan);
269 free_alloc_pool (problem_data->ref_base_pool);
270 free_alloc_pool (problem_data->ref_artificial_pool);
271 free_alloc_pool (problem_data->ref_regular_pool);
272 free_alloc_pool (problem_data->ref_extract_pool);
273 free_alloc_pool (problem_data->insn_pool);
274 free_alloc_pool (problem_data->reg_pool);
275 free_alloc_pool (problem_data->mw_reg_pool);
276 bitmap_obstack_release (&problem_data->reg_bitmaps);
277 bitmap_obstack_release (&problem_data->insn_bitmaps);
278 free (df_scan->problem_data);
282 /* Free basic block info. */
284 static void
285 df_scan_free_bb_info (basic_block bb, void *vbb_info)
287 struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
288 unsigned int bb_index = bb->index;
290 /* See if bb_info is initialized. */
291 if (bb_info->artificial_defs)
293 rtx insn;
294 FOR_BB_INSNS (bb, insn)
296 if (INSN_P (insn))
297 /* Record defs within INSN. */
298 df_insn_delete (bb, INSN_UID (insn));
301 if (bb_index < df_scan->block_info_size)
302 bb_info = df_scan_get_bb_info (bb_index);
304 /* Get rid of any artificial uses or defs. */
305 if (bb_info->artificial_defs)
307 df_ref_chain_delete_du_chain (bb_info->artificial_defs);
308 df_ref_chain_delete_du_chain (bb_info->artificial_uses);
309 df_ref_chain_delete (bb_info->artificial_defs);
310 df_ref_chain_delete (bb_info->artificial_uses);
311 bb_info->artificial_defs = NULL;
312 bb_info->artificial_uses = NULL;
318 /* Allocate the problem data for the scanning problem. This should be
319 called when the problem is created or when the entire function is to
320 be rescanned. */
321 void
322 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
324 struct df_scan_problem_data *problem_data;
325 unsigned int insn_num = get_max_uid () + 1;
326 unsigned int block_size = 400;
327 basic_block bb;
329 /* Given the number of pools, this is really faster than tearing
330 everything apart. */
331 if (df_scan->problem_data)
332 df_scan_free_internal ();
334 problem_data = XNEW (struct df_scan_problem_data);
335 df_scan->problem_data = problem_data;
336 df_scan->computed = true;
338 problem_data->ref_base_pool
339 = create_alloc_pool ("df_scan ref base",
340 sizeof (struct df_base_ref), block_size);
341 problem_data->ref_artificial_pool
342 = create_alloc_pool ("df_scan ref artificial",
343 sizeof (struct df_artificial_ref), block_size);
344 problem_data->ref_regular_pool
345 = create_alloc_pool ("df_scan ref regular",
346 sizeof (struct df_regular_ref), block_size);
347 problem_data->ref_extract_pool
348 = create_alloc_pool ("df_scan ref extract",
349 sizeof (struct df_extract_ref), block_size);
350 problem_data->insn_pool
351 = create_alloc_pool ("df_scan insn",
352 sizeof (struct df_insn_info), block_size);
353 problem_data->reg_pool
354 = create_alloc_pool ("df_scan reg",
355 sizeof (struct df_reg_info), block_size);
356 problem_data->mw_reg_pool
357 = create_alloc_pool ("df_scan mw_reg",
358 sizeof (struct df_mw_hardreg), block_size);
360 bitmap_obstack_initialize (&problem_data->reg_bitmaps);
361 bitmap_obstack_initialize (&problem_data->insn_bitmaps);
363 insn_num += insn_num / 4;
364 df_grow_reg_info ();
366 df_grow_insn_info ();
367 df_grow_bb_info (df_scan);
369 FOR_ALL_BB (bb)
371 unsigned int bb_index = bb->index;
372 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
373 bb_info->artificial_defs = NULL;
374 bb_info->artificial_uses = NULL;
377 bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps);
378 bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps);
379 bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps);
380 df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
381 df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
382 bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps);
383 bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps);
384 bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps);
385 df_scan->optional_p = false;
389 /* Free all of the data associated with the scan problem. */
391 static void
392 df_scan_free (void)
394 if (df_scan->problem_data)
395 df_scan_free_internal ();
397 if (df->blocks_to_analyze)
399 BITMAP_FREE (df->blocks_to_analyze);
400 df->blocks_to_analyze = NULL;
403 free (df_scan);
406 /* Dump the preamble for DF_SCAN dump. */
407 static void
408 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
410 int i;
411 int dcount = 0;
412 int ucount = 0;
413 int ecount = 0;
414 int icount = 0;
415 int ccount = 0;
416 basic_block bb;
417 rtx insn;
419 fprintf (file, ";; invalidated by call \t");
420 df_print_regset (file, regs_invalidated_by_call_regset);
421 fprintf (file, ";; hardware regs used \t");
422 df_print_regset (file, &df->hardware_regs_used);
423 fprintf (file, ";; regular block artificial uses \t");
424 df_print_regset (file, &df->regular_block_artificial_uses);
425 fprintf (file, ";; eh block artificial uses \t");
426 df_print_regset (file, &df->eh_block_artificial_uses);
427 fprintf (file, ";; entry block defs \t");
428 df_print_regset (file, df->entry_block_defs);
429 fprintf (file, ";; exit block uses \t");
430 df_print_regset (file, df->exit_block_uses);
431 fprintf (file, ";; regs ever live \t");
432 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
433 if (df_regs_ever_live_p (i))
434 fprintf (file, " %d[%s]", i, reg_names[i]);
435 fprintf (file, "\n;; ref usage \t");
437 for (i = 0; i < (int)df->regs_inited; i++)
438 if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i))
440 const char * sep = "";
442 fprintf (file, "r%d={", i);
443 if (DF_REG_DEF_COUNT (i))
445 fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
446 sep = ",";
447 dcount += DF_REG_DEF_COUNT (i);
449 if (DF_REG_USE_COUNT (i))
451 fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
452 sep = ",";
453 ucount += DF_REG_USE_COUNT (i);
455 if (DF_REG_EQ_USE_COUNT (i))
457 fprintf (file, "%s%dd", sep, DF_REG_EQ_USE_COUNT (i));
458 ecount += DF_REG_EQ_USE_COUNT (i);
460 fprintf (file, "} ");
463 FOR_EACH_BB (bb)
464 FOR_BB_INSNS (bb, insn)
465 if (INSN_P (insn))
467 if (CALL_P (insn))
468 ccount++;
469 else
470 icount++;
473 fprintf (file, "\n;; total ref usage %d{%dd,%du,%de} in %d{%d regular + %d call} insns.\n",
474 dcount + ucount + ecount, dcount, ucount, ecount, icount + ccount, icount, ccount);
477 /* Dump the bb_info for a given basic block. */
478 static void
479 df_scan_start_block (basic_block bb, FILE *file)
481 struct df_scan_bb_info *bb_info
482 = df_scan_get_bb_info (bb->index);
484 if (bb_info)
486 fprintf (file, ";; bb %d artificial_defs: ", bb->index);
487 df_refs_chain_dump (bb_info->artificial_defs, true, file);
488 fprintf (file, "\n;; bb %d artificial_uses: ", bb->index);
489 df_refs_chain_dump (bb_info->artificial_uses, true, file);
490 fprintf (file, "\n");
492 #if 0
494 rtx insn;
495 FOR_BB_INSNS (bb, insn)
496 if (INSN_P (insn))
497 df_insn_debug (insn, false, file);
499 #endif
502 static struct df_problem problem_SCAN =
504 DF_SCAN, /* Problem id. */
505 DF_NONE, /* Direction. */
506 df_scan_alloc, /* Allocate the problem specific data. */
507 NULL, /* Reset global information. */
508 df_scan_free_bb_info, /* Free basic block info. */
509 NULL, /* Local compute function. */
510 NULL, /* Init the solution specific data. */
511 NULL, /* Iterative solver. */
512 NULL, /* Confluence operator 0. */
513 NULL, /* Confluence operator n. */
514 NULL, /* Transfer function. */
515 NULL, /* Finalize function. */
516 df_scan_free, /* Free all of the problem information. */
517 NULL, /* Remove this problem from the stack of dataflow problems. */
518 df_scan_start_dump, /* Debugging. */
519 df_scan_start_block, /* Debugging start block. */
520 NULL, /* Debugging end block. */
521 NULL, /* Incremental solution verify start. */
522 NULL, /* Incremental solution verify end. */
523 NULL, /* Dependent problem. */
524 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
525 TV_DF_SCAN, /* Timing variable. */
526 false /* Reset blocks on dropping out of blocks_to_analyze. */
530 /* Create a new DATAFLOW instance and add it to an existing instance
531 of DF. The returned structure is what is used to get at the
532 solution. */
534 void
535 df_scan_add_problem (void)
537 df_add_problem (&problem_SCAN);
541 /*----------------------------------------------------------------------------
542 Storage Allocation Utilities
543 ----------------------------------------------------------------------------*/
546 /* First, grow the reg_info information. If the current size is less than
547 the number of pseudos, grow to 25% more than the number of
548 pseudos.
550 Second, assure that all of the slots up to max_reg_num have been
551 filled with reg_info structures. */
553 void
554 df_grow_reg_info (void)
556 unsigned int max_reg = max_reg_num ();
557 unsigned int new_size = max_reg;
558 struct df_scan_problem_data *problem_data
559 = (struct df_scan_problem_data *) df_scan->problem_data;
560 unsigned int i;
562 if (df->regs_size < new_size)
564 new_size += new_size / 4;
565 df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
566 df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
567 df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
568 new_size);
569 df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
570 df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
571 df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
572 df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
573 df->regs_size = new_size;
576 for (i = df->regs_inited; i < max_reg; i++)
578 struct df_reg_info *reg_info;
580 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
581 memset (reg_info, 0, sizeof (struct df_reg_info));
582 df->def_regs[i] = reg_info;
583 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
584 memset (reg_info, 0, sizeof (struct df_reg_info));
585 df->use_regs[i] = reg_info;
586 reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
587 memset (reg_info, 0, sizeof (struct df_reg_info));
588 df->eq_use_regs[i] = reg_info;
589 df->def_info.begin[i] = 0;
590 df->def_info.count[i] = 0;
591 df->use_info.begin[i] = 0;
592 df->use_info.count[i] = 0;
595 df->regs_inited = max_reg;
599 /* Grow the ref information. */
601 static void
602 df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
604 if (ref_info->refs_size < new_size)
606 ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
607 memset (ref_info->refs + ref_info->refs_size, 0,
608 (new_size - ref_info->refs_size) *sizeof (df_ref));
609 ref_info->refs_size = new_size;
614 /* Check and grow the ref information if necessary. This routine
615 guarantees total_size + BITMAP_ADDEND amount of entries in refs
616 array. It updates ref_info->refs_size only and does not change
617 ref_info->total_size. */
619 static void
620 df_check_and_grow_ref_info (struct df_ref_info *ref_info,
621 unsigned bitmap_addend)
623 if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
625 int new_size = ref_info->total_size + bitmap_addend;
626 new_size += ref_info->total_size / 4;
627 df_grow_ref_info (ref_info, new_size);
632 /* Grow the ref information. If the current size is less than the
633 number of instructions, grow to 25% more than the number of
634 instructions. */
636 void
637 df_grow_insn_info (void)
639 unsigned int new_size = get_max_uid () + 1;
640 if (DF_INSN_SIZE () < new_size)
642 new_size += new_size / 4;
643 df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
644 memset (df->insns + df->insns_size, 0,
645 (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
646 DF_INSN_SIZE () = new_size;
653 /*----------------------------------------------------------------------------
654 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
655 ----------------------------------------------------------------------------*/
657 /* Rescan all of the block_to_analyze or all of the blocks in the
658 function if df_set_blocks if blocks_to_analyze is NULL; */
660 void
661 df_scan_blocks (void)
663 basic_block bb;
665 df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
666 df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
668 df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses);
669 df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses);
671 bitmap_ior_into (&df->eh_block_artificial_uses,
672 &df->regular_block_artificial_uses);
674 /* ENTRY and EXIT blocks have special defs/uses. */
675 df_get_entry_block_def_set (df->entry_block_defs);
676 df_record_entry_block_defs (df->entry_block_defs);
677 df_get_exit_block_use_set (df->exit_block_uses);
678 df_record_exit_block_uses (df->exit_block_uses);
679 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
680 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
682 /* Regular blocks */
683 FOR_EACH_BB (bb)
685 unsigned int bb_index = bb->index;
686 df_bb_refs_record (bb_index, true);
691 /* Create a new ref of type DF_REF_TYPE for register REG at address
692 LOC within INSN of BB. This function is only used externally.
694 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
695 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
696 fields if they were constants. Otherwise they should be -1 if
697 those flags were set. */
699 df_ref
700 df_ref_create (rtx reg, rtx *loc, rtx insn,
701 basic_block bb,
702 enum df_ref_type ref_type,
703 int ref_flags,
704 int width, int offset, enum machine_mode mode)
706 df_ref ref;
707 struct df_reg_info **reg_info;
708 struct df_ref_info *ref_info;
709 df_ref *ref_rec;
710 df_ref **ref_rec_ptr;
711 unsigned int count = 0;
712 bool add_to_table;
713 enum df_ref_class cl;
715 df_grow_reg_info ();
717 /* You cannot hack artificial refs. */
718 gcc_assert (insn);
720 if (width != -1 || offset != -1)
721 cl = DF_REF_EXTRACT;
722 else if (loc)
723 cl = DF_REF_REGULAR;
724 else
725 cl = DF_REF_BASE;
726 ref = df_ref_create_structure (cl, NULL, reg, loc, bb, DF_INSN_INFO_GET (insn),
727 ref_type, ref_flags,
728 width, offset, mode);
730 if (DF_REF_REG_DEF_P (ref))
732 reg_info = df->def_regs;
733 ref_info = &df->def_info;
734 ref_rec_ptr = &DF_INSN_DEFS (insn);
735 add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
737 else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
739 reg_info = df->eq_use_regs;
740 ref_info = &df->use_info;
741 ref_rec_ptr = &DF_INSN_EQ_USES (insn);
742 switch (ref_info->ref_order)
744 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
745 case DF_REF_ORDER_BY_REG_WITH_NOTES:
746 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
747 add_to_table = true;
748 break;
749 default:
750 add_to_table = false;
751 break;
754 else
756 reg_info = df->use_regs;
757 ref_info = &df->use_info;
758 ref_rec_ptr = &DF_INSN_USES (insn);
759 add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
762 /* Do not add if ref is not in the right blocks. */
763 if (add_to_table && df->analyze_subset)
764 add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
766 df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
768 if (add_to_table)
769 switch (ref_info->ref_order)
771 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
772 case DF_REF_ORDER_BY_REG_WITH_NOTES:
773 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
774 ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
775 break;
776 default:
777 ref_info->ref_order = DF_REF_ORDER_UNORDERED;
778 break;
781 ref_rec = *ref_rec_ptr;
782 while (*ref_rec)
784 count++;
785 ref_rec++;
788 ref_rec = *ref_rec_ptr;
789 if (count)
791 ref_rec = XRESIZEVEC (df_ref, ref_rec, count+2);
792 *ref_rec_ptr = ref_rec;
793 ref_rec[count] = ref;
794 ref_rec[count+1] = NULL;
795 qsort (ref_rec, count + 1, sizeof (df_ref), df_ref_compare);
797 else
799 df_ref *ref_rec = XNEWVEC (df_ref, 2);
800 ref_rec[0] = ref;
801 ref_rec[1] = NULL;
802 *ref_rec_ptr = ref_rec;
805 #if 0
806 if (dump_file)
808 fprintf (dump_file, "adding ref ");
809 df_ref_debug (ref, dump_file);
811 #endif
812 /* By adding the ref directly, df_insn_rescan my not find any
813 differences even though the block will have changed. So we need
814 to mark the block dirty ourselves. */
815 if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
816 df_set_bb_dirty (bb);
818 return ref;
823 /*----------------------------------------------------------------------------
824 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
825 ----------------------------------------------------------------------------*/
827 static void
828 df_free_ref (df_ref ref)
830 struct df_scan_problem_data *problem_data
831 = (struct df_scan_problem_data *) df_scan->problem_data;
833 switch (DF_REF_CLASS (ref))
835 case DF_REF_BASE:
836 pool_free (problem_data->ref_base_pool, ref);
837 break;
839 case DF_REF_ARTIFICIAL:
840 pool_free (problem_data->ref_artificial_pool, ref);
841 break;
843 case DF_REF_REGULAR:
844 pool_free (problem_data->ref_regular_pool, ref);
845 break;
847 case DF_REF_EXTRACT:
848 pool_free (problem_data->ref_extract_pool, ref);
849 break;
854 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
855 Also delete the def-use or use-def chain if it exists. */
857 static void
858 df_reg_chain_unlink (df_ref ref)
860 df_ref next = DF_REF_NEXT_REG (ref);
861 df_ref prev = DF_REF_PREV_REG (ref);
862 int id = DF_REF_ID (ref);
863 struct df_reg_info *reg_info;
864 df_ref *refs = NULL;
866 if (DF_REF_REG_DEF_P (ref))
868 int regno = DF_REF_REGNO (ref);
869 reg_info = DF_REG_DEF_GET (regno);
870 refs = df->def_info.refs;
872 else
874 if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
876 reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
877 switch (df->use_info.ref_order)
879 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
880 case DF_REF_ORDER_BY_REG_WITH_NOTES:
881 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
882 refs = df->use_info.refs;
883 break;
884 default:
885 break;
888 else
890 reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
891 refs = df->use_info.refs;
895 if (refs)
897 if (df->analyze_subset)
899 if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
900 refs[id] = NULL;
902 else
903 refs[id] = NULL;
906 /* Delete any def-use or use-def chains that start here. It is
907 possible that there is trash in this field. This happens for
908 insns that have been deleted when rescanning has been deferred
909 and the chain problem has also been deleted. The chain tear down
910 code skips deleted insns. */
911 if (df_chain && DF_REF_CHAIN (ref))
912 df_chain_unlink (ref);
914 reg_info->n_refs--;
915 if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
917 gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
918 df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
921 /* Unlink from the reg chain. If there is no prev, this is the
922 first of the list. If not, just join the next and prev. */
923 if (prev)
924 DF_REF_NEXT_REG (prev) = next;
925 else
927 gcc_assert (reg_info->reg_chain == ref);
928 reg_info->reg_chain = next;
930 if (next)
931 DF_REF_PREV_REG (next) = prev;
933 df_free_ref (ref);
937 /* Remove REF from VEC. */
939 static void
940 df_ref_compress_rec (df_ref **vec_ptr, df_ref ref)
942 df_ref *vec = *vec_ptr;
944 if (vec[1])
946 while (*vec && *vec != ref)
947 vec++;
949 while (*vec)
951 *vec = *(vec+1);
952 vec++;
955 else
957 free (vec);
958 *vec_ptr = df_null_ref_rec;
963 /* Unlink REF from all def-use/use-def chains, etc. */
965 void
966 df_ref_remove (df_ref ref)
968 #if 0
969 if (dump_file)
971 fprintf (dump_file, "removing ref ");
972 df_ref_debug (ref, dump_file);
974 #endif
976 if (DF_REF_REG_DEF_P (ref))
978 if (DF_REF_IS_ARTIFICIAL (ref))
980 struct df_scan_bb_info *bb_info
981 = df_scan_get_bb_info (DF_REF_BBNO (ref));
982 df_ref_compress_rec (&bb_info->artificial_defs, ref);
984 else
986 unsigned int uid = DF_REF_INSN_UID (ref);
987 struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
988 df_ref_compress_rec (&insn_rec->defs, ref);
991 else
993 if (DF_REF_IS_ARTIFICIAL (ref))
995 struct df_scan_bb_info *bb_info
996 = df_scan_get_bb_info (DF_REF_BBNO (ref));
997 df_ref_compress_rec (&bb_info->artificial_uses, ref);
999 else
1001 unsigned int uid = DF_REF_INSN_UID (ref);
1002 struct df_insn_info *insn_rec = DF_INSN_UID_GET (uid);
1004 if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
1005 df_ref_compress_rec (&insn_rec->eq_uses, ref);
1006 else
1007 df_ref_compress_rec (&insn_rec->uses, ref);
1011 /* By deleting the ref directly, df_insn_rescan my not find any
1012 differences even though the block will have changed. So we need
1013 to mark the block dirty ourselves. */
1014 if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
1015 df_set_bb_dirty (DF_REF_BB (ref));
1016 df_reg_chain_unlink (ref);
1020 /* Create the insn record for INSN. If there was one there, zero it
1021 out. */
1023 struct df_insn_info *
1024 df_insn_create_insn_record (rtx insn)
1026 struct df_scan_problem_data *problem_data
1027 = (struct df_scan_problem_data *) df_scan->problem_data;
1028 struct df_insn_info *insn_rec;
1030 df_grow_insn_info ();
1031 insn_rec = DF_INSN_INFO_GET (insn);
1032 if (!insn_rec)
1034 insn_rec = (struct df_insn_info *) pool_alloc (problem_data->insn_pool);
1035 DF_INSN_INFO_SET (insn, insn_rec);
1037 memset (insn_rec, 0, sizeof (struct df_insn_info));
1038 insn_rec->insn = insn;
1039 return insn_rec;
1043 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
1045 static void
1046 df_ref_chain_delete_du_chain (df_ref *ref_rec)
1048 while (*ref_rec)
1050 df_ref ref = *ref_rec;
1051 /* CHAIN is allocated by DF_CHAIN. So make sure to
1052 pass df_scan instance for the problem. */
1053 if (DF_REF_CHAIN (ref))
1054 df_chain_unlink (ref);
1055 ref_rec++;
1060 /* Delete all refs in the ref chain. */
1062 static void
1063 df_ref_chain_delete (df_ref *ref_rec)
1065 df_ref *start = ref_rec;
1066 while (*ref_rec)
1068 df_reg_chain_unlink (*ref_rec);
1069 ref_rec++;
1072 /* If the list is empty, it has a special shared element that is not
1073 to be deleted. */
1074 if (*start)
1075 free (start);
1079 /* Delete the hardreg chain. */
1081 static void
1082 df_mw_hardreg_chain_delete (struct df_mw_hardreg **hardregs)
1084 struct df_scan_problem_data *problem_data;
1086 if (!hardregs)
1087 return;
1089 problem_data = (struct df_scan_problem_data *) df_scan->problem_data;
1091 while (*hardregs)
1093 pool_free (problem_data->mw_reg_pool, *hardregs);
1094 hardregs++;
1099 /* Delete all of the refs information from INSN. BB must be passed in
1100 except when called from df_process_deferred_rescans to mark the block
1101 as dirty. */
1103 void
1104 df_insn_delete (basic_block bb, unsigned int uid)
1106 struct df_insn_info *insn_info = NULL;
1107 if (!df)
1108 return;
1110 df_grow_bb_info (df_scan);
1111 df_grow_reg_info ();
1113 /* The block must be marked as dirty now, rather than later as in
1114 df_insn_rescan and df_notes_rescan because it may not be there at
1115 rescanning time and the mark would blow up. */
1116 if (bb)
1117 df_set_bb_dirty (bb);
1119 insn_info = DF_INSN_UID_SAFE_GET (uid);
1121 /* The client has deferred rescanning. */
1122 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1124 if (insn_info)
1126 bitmap_clear_bit (&df->insns_to_rescan, uid);
1127 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1128 bitmap_set_bit (&df->insns_to_delete, uid);
1130 if (dump_file)
1131 fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
1132 return;
1135 if (dump_file)
1136 fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
1138 bitmap_clear_bit (&df->insns_to_delete, uid);
1139 bitmap_clear_bit (&df->insns_to_rescan, uid);
1140 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1141 if (insn_info)
1143 struct df_scan_problem_data *problem_data
1144 = (struct df_scan_problem_data *) df_scan->problem_data;
1146 /* In general, notes do not have the insn_info fields
1147 initialized. However, combine deletes insns by changing them
1148 to notes. How clever. So we cannot just check if it is a
1149 valid insn before short circuiting this code, we need to see
1150 if we actually initialized it. */
1151 if (insn_info->defs)
1153 df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1155 if (df_chain)
1157 df_ref_chain_delete_du_chain (insn_info->defs);
1158 df_ref_chain_delete_du_chain (insn_info->uses);
1159 df_ref_chain_delete_du_chain (insn_info->eq_uses);
1162 df_ref_chain_delete (insn_info->defs);
1163 df_ref_chain_delete (insn_info->uses);
1164 df_ref_chain_delete (insn_info->eq_uses);
1166 pool_free (problem_data->insn_pool, insn_info);
1167 DF_INSN_UID_SET (uid, NULL);
1172 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1174 static void
1175 df_free_collection_rec (struct df_collection_rec *collection_rec)
1177 unsigned int ix;
1178 struct df_scan_problem_data *problem_data
1179 = (struct df_scan_problem_data *) df_scan->problem_data;
1180 df_ref ref;
1181 struct df_mw_hardreg *mw;
1183 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
1184 df_free_ref (ref);
1185 FOR_EACH_VEC_ELT (df_ref, collection_rec->use_vec, ix, ref)
1186 df_free_ref (ref);
1187 FOR_EACH_VEC_ELT (df_ref, collection_rec->eq_use_vec, ix, ref)
1188 df_free_ref (ref);
1189 FOR_EACH_VEC_ELT (df_mw_hardreg_ptr, collection_rec->mw_vec, ix, mw)
1190 pool_free (problem_data->mw_reg_pool, mw);
1192 VEC_free (df_ref, stack, collection_rec->def_vec);
1193 VEC_free (df_ref, stack, collection_rec->use_vec);
1194 VEC_free (df_ref, stack, collection_rec->eq_use_vec);
1195 VEC_free (df_mw_hardreg_ptr, stack, collection_rec->mw_vec);
1198 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1200 bool
1201 df_insn_rescan (rtx insn)
1203 unsigned int uid = INSN_UID (insn);
1204 struct df_insn_info *insn_info = NULL;
1205 basic_block bb = BLOCK_FOR_INSN (insn);
1206 struct df_collection_rec collection_rec;
1208 if ((!df) || (!INSN_P (insn)))
1209 return false;
1211 if (!bb)
1213 if (dump_file)
1214 fprintf (dump_file, "no bb for insn with uid = %d.\n", uid);
1215 return false;
1218 /* The client has disabled rescanning and plans to do it itself. */
1219 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1220 return false;
1222 df_grow_bb_info (df_scan);
1223 df_grow_reg_info ();
1225 insn_info = DF_INSN_UID_SAFE_GET (uid);
1227 /* The client has deferred rescanning. */
1228 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1230 if (!insn_info)
1232 insn_info = df_insn_create_insn_record (insn);
1233 insn_info->defs = df_null_ref_rec;
1234 insn_info->uses = df_null_ref_rec;
1235 insn_info->eq_uses = df_null_ref_rec;
1236 insn_info->mw_hardregs = df_null_mw_rec;
1238 if (dump_file)
1239 fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid);
1241 bitmap_clear_bit (&df->insns_to_delete, uid);
1242 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1243 bitmap_set_bit (&df->insns_to_rescan, INSN_UID (insn));
1244 return false;
1247 collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
1248 collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
1249 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
1250 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
1252 bitmap_clear_bit (&df->insns_to_delete, uid);
1253 bitmap_clear_bit (&df->insns_to_rescan, uid);
1254 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1255 if (insn_info)
1257 int luid;
1258 bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false);
1259 /* If there's no change, return false. */
1260 if (the_same)
1262 df_free_collection_rec (&collection_rec);
1263 if (dump_file)
1264 fprintf (dump_file, "verify found no changes in insn with uid = %d.\n", uid);
1265 return false;
1267 if (dump_file)
1268 fprintf (dump_file, "rescanning insn with uid = %d.\n", uid);
1270 /* There's change - we need to delete the existing info.
1271 Since the insn isn't moved, we can salvage its LUID. */
1272 luid = DF_INSN_LUID (insn);
1273 df_insn_delete (NULL, uid);
1274 df_insn_create_insn_record (insn);
1275 DF_INSN_LUID (insn) = luid;
1277 else
1279 struct df_insn_info *insn_info = df_insn_create_insn_record (insn);
1280 df_insn_refs_collect (&collection_rec, bb, insn_info);
1281 if (dump_file)
1282 fprintf (dump_file, "scanning new insn with uid = %d.\n", uid);
1285 df_refs_add_to_chains (&collection_rec, bb, insn);
1286 if (DEBUG_INSN_P (insn))
1287 df_set_bb_dirty_nonlr (bb);
1288 else
1289 df_set_bb_dirty (bb);
1291 VEC_free (df_ref, stack, collection_rec.def_vec);
1292 VEC_free (df_ref, stack, collection_rec.use_vec);
1293 VEC_free (df_ref, stack, collection_rec.eq_use_vec);
1294 VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
1296 return true;
1299 /* Same as df_insn_rescan, but don't mark the basic block as
1300 dirty. */
1302 bool
1303 df_insn_rescan_debug_internal (rtx insn)
1305 unsigned int uid = INSN_UID (insn);
1306 struct df_insn_info *insn_info;
1308 gcc_assert (DEBUG_INSN_P (insn)
1309 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)));
1311 if (!df)
1312 return false;
1314 insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
1315 if (!insn_info)
1316 return false;
1318 if (dump_file)
1319 fprintf (dump_file, "deleting debug_insn with uid = %d.\n", uid);
1321 bitmap_clear_bit (&df->insns_to_delete, uid);
1322 bitmap_clear_bit (&df->insns_to_rescan, uid);
1323 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
1325 if (!insn_info->defs)
1326 return false;
1328 if (insn_info->defs == df_null_ref_rec
1329 && insn_info->uses == df_null_ref_rec
1330 && insn_info->eq_uses == df_null_ref_rec
1331 && insn_info->mw_hardregs == df_null_mw_rec)
1332 return false;
1334 df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
1336 if (df_chain)
1338 df_ref_chain_delete_du_chain (insn_info->defs);
1339 df_ref_chain_delete_du_chain (insn_info->uses);
1340 df_ref_chain_delete_du_chain (insn_info->eq_uses);
1343 df_ref_chain_delete (insn_info->defs);
1344 df_ref_chain_delete (insn_info->uses);
1345 df_ref_chain_delete (insn_info->eq_uses);
1347 insn_info->defs = df_null_ref_rec;
1348 insn_info->uses = df_null_ref_rec;
1349 insn_info->eq_uses = df_null_ref_rec;
1350 insn_info->mw_hardregs = df_null_mw_rec;
1352 return true;
1356 /* Rescan all of the insns in the function. Note that the artificial
1357 uses and defs are not touched. This function will destroy def-se
1358 or use-def chains. */
1360 void
1361 df_insn_rescan_all (void)
1363 bool no_insn_rescan = false;
1364 bool defer_insn_rescan = false;
1365 basic_block bb;
1366 bitmap_iterator bi;
1367 unsigned int uid;
1368 bitmap_head tmp;
1370 bitmap_initialize (&tmp, &df_bitmap_obstack);
1372 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1374 df_clear_flags (DF_NO_INSN_RESCAN);
1375 no_insn_rescan = true;
1378 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1380 df_clear_flags (DF_DEFER_INSN_RESCAN);
1381 defer_insn_rescan = true;
1384 bitmap_copy (&tmp, &df->insns_to_delete);
1385 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1387 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1388 if (insn_info)
1389 df_insn_delete (NULL, uid);
1392 bitmap_clear (&tmp);
1393 bitmap_clear (&df->insns_to_delete);
1394 bitmap_clear (&df->insns_to_rescan);
1395 bitmap_clear (&df->insns_to_notes_rescan);
1397 FOR_EACH_BB (bb)
1399 rtx insn;
1400 FOR_BB_INSNS (bb, insn)
1402 df_insn_rescan (insn);
1406 if (no_insn_rescan)
1407 df_set_flags (DF_NO_INSN_RESCAN);
1408 if (defer_insn_rescan)
1409 df_set_flags (DF_DEFER_INSN_RESCAN);
1413 /* Process all of the deferred rescans or deletions. */
1415 void
1416 df_process_deferred_rescans (void)
1418 bool no_insn_rescan = false;
1419 bool defer_insn_rescan = false;
1420 bitmap_iterator bi;
1421 unsigned int uid;
1422 bitmap_head tmp;
1424 bitmap_initialize (&tmp, &df_bitmap_obstack);
1426 if (df->changeable_flags & DF_NO_INSN_RESCAN)
1428 df_clear_flags (DF_NO_INSN_RESCAN);
1429 no_insn_rescan = true;
1432 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
1434 df_clear_flags (DF_DEFER_INSN_RESCAN);
1435 defer_insn_rescan = true;
1438 if (dump_file)
1439 fprintf (dump_file, "starting the processing of deferred insns\n");
1441 bitmap_copy (&tmp, &df->insns_to_delete);
1442 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1444 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1445 if (insn_info)
1446 df_insn_delete (NULL, uid);
1449 bitmap_copy (&tmp, &df->insns_to_rescan);
1450 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1452 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1453 if (insn_info)
1454 df_insn_rescan (insn_info->insn);
1457 bitmap_copy (&tmp, &df->insns_to_notes_rescan);
1458 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
1460 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
1461 if (insn_info)
1462 df_notes_rescan (insn_info->insn);
1465 if (dump_file)
1466 fprintf (dump_file, "ending the processing of deferred insns\n");
1468 bitmap_clear (&tmp);
1469 bitmap_clear (&df->insns_to_delete);
1470 bitmap_clear (&df->insns_to_rescan);
1471 bitmap_clear (&df->insns_to_notes_rescan);
1473 if (no_insn_rescan)
1474 df_set_flags (DF_NO_INSN_RESCAN);
1475 if (defer_insn_rescan)
1476 df_set_flags (DF_DEFER_INSN_RESCAN);
1478 /* If someone changed regs_ever_live during this pass, fix up the
1479 entry and exit blocks. */
1480 if (df->redo_entry_and_exit)
1482 df_update_entry_exit_and_calls ();
1483 df->redo_entry_and_exit = false;
1488 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1489 the uses if INCLUDE_USES. Include the eq_uses if
1490 INCLUDE_EQ_USES. */
1492 static unsigned int
1493 df_count_refs (bool include_defs, bool include_uses,
1494 bool include_eq_uses)
1496 unsigned int regno;
1497 int size = 0;
1498 unsigned int m = df->regs_inited;
1500 for (regno = 0; regno < m; regno++)
1502 if (include_defs)
1503 size += DF_REG_DEF_COUNT (regno);
1504 if (include_uses)
1505 size += DF_REG_USE_COUNT (regno);
1506 if (include_eq_uses)
1507 size += DF_REG_EQ_USE_COUNT (regno);
1509 return size;
1513 /* Take build ref table for either the uses or defs from the reg-use
1514 or reg-def chains. This version processes the refs in reg order
1515 which is likely to be best if processing the whole function. */
1517 static void
1518 df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info,
1519 bool include_defs,
1520 bool include_uses,
1521 bool include_eq_uses)
1523 unsigned int m = df->regs_inited;
1524 unsigned int regno;
1525 unsigned int offset = 0;
1526 unsigned int start;
1528 if (df->changeable_flags & DF_NO_HARD_REGS)
1530 start = FIRST_PSEUDO_REGISTER;
1531 memset (ref_info->begin, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1532 memset (ref_info->count, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
1534 else
1535 start = 0;
1537 ref_info->total_size
1538 = df_count_refs (include_defs, include_uses, include_eq_uses);
1540 df_check_and_grow_ref_info (ref_info, 1);
1542 for (regno = start; regno < m; regno++)
1544 int count = 0;
1545 ref_info->begin[regno] = offset;
1546 if (include_defs)
1548 df_ref ref = DF_REG_DEF_CHAIN (regno);
1549 while (ref)
1551 ref_info->refs[offset] = ref;
1552 DF_REF_ID (ref) = offset++;
1553 count++;
1554 ref = DF_REF_NEXT_REG (ref);
1555 gcc_checking_assert (offset < ref_info->refs_size);
1558 if (include_uses)
1560 df_ref ref = DF_REG_USE_CHAIN (regno);
1561 while (ref)
1563 ref_info->refs[offset] = ref;
1564 DF_REF_ID (ref) = offset++;
1565 count++;
1566 ref = DF_REF_NEXT_REG (ref);
1567 gcc_checking_assert (offset < ref_info->refs_size);
1570 if (include_eq_uses)
1572 df_ref ref = DF_REG_EQ_USE_CHAIN (regno);
1573 while (ref)
1575 ref_info->refs[offset] = ref;
1576 DF_REF_ID (ref) = offset++;
1577 count++;
1578 ref = DF_REF_NEXT_REG (ref);
1579 gcc_checking_assert (offset < ref_info->refs_size);
1582 ref_info->count[regno] = count;
1585 /* The bitmap size is not decremented when refs are deleted. So
1586 reset it now that we have squished out all of the empty
1587 slots. */
1588 ref_info->table_size = offset;
1592 /* Take build ref table for either the uses or defs from the reg-use
1593 or reg-def chains. This version processes the refs in insn order
1594 which is likely to be best if processing some segment of the
1595 function. */
1597 static void
1598 df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
1599 bool include_defs,
1600 bool include_uses,
1601 bool include_eq_uses)
1603 bitmap_iterator bi;
1604 unsigned int bb_index;
1605 unsigned int m = df->regs_inited;
1606 unsigned int offset = 0;
1607 unsigned int r;
1608 unsigned int start
1609 = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
1611 memset (ref_info->begin, 0, sizeof (int) * df->regs_inited);
1612 memset (ref_info->count, 0, sizeof (int) * df->regs_inited);
1614 ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1615 df_check_and_grow_ref_info (ref_info, 1);
1617 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1619 basic_block bb = BASIC_BLOCK (bb_index);
1620 rtx insn;
1621 df_ref *ref_rec;
1623 if (include_defs)
1624 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1626 unsigned int regno = DF_REF_REGNO (*ref_rec);
1627 ref_info->count[regno]++;
1629 if (include_uses)
1630 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1632 unsigned int regno = DF_REF_REGNO (*ref_rec);
1633 ref_info->count[regno]++;
1636 FOR_BB_INSNS (bb, insn)
1638 if (INSN_P (insn))
1640 unsigned int uid = INSN_UID (insn);
1642 if (include_defs)
1643 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1645 unsigned int regno = DF_REF_REGNO (*ref_rec);
1646 ref_info->count[regno]++;
1648 if (include_uses)
1649 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1651 unsigned int regno = DF_REF_REGNO (*ref_rec);
1652 ref_info->count[regno]++;
1654 if (include_eq_uses)
1655 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1657 unsigned int regno = DF_REF_REGNO (*ref_rec);
1658 ref_info->count[regno]++;
1664 for (r = start; r < m; r++)
1666 ref_info->begin[r] = offset;
1667 offset += ref_info->count[r];
1668 ref_info->count[r] = 0;
1671 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1673 basic_block bb = BASIC_BLOCK (bb_index);
1674 rtx insn;
1675 df_ref *ref_rec;
1677 if (include_defs)
1678 for (ref_rec = df_get_artificial_defs (bb_index); *ref_rec; ref_rec++)
1680 df_ref ref = *ref_rec;
1681 unsigned int regno = DF_REF_REGNO (ref);
1682 if (regno >= start)
1684 unsigned int id
1685 = ref_info->begin[regno] + ref_info->count[regno]++;
1686 DF_REF_ID (ref) = id;
1687 ref_info->refs[id] = ref;
1690 if (include_uses)
1691 for (ref_rec = df_get_artificial_uses (bb_index); *ref_rec; ref_rec++)
1693 df_ref ref = *ref_rec;
1694 unsigned int regno = DF_REF_REGNO (ref);
1695 if (regno >= start)
1697 unsigned int id
1698 = ref_info->begin[regno] + ref_info->count[regno]++;
1699 DF_REF_ID (ref) = id;
1700 ref_info->refs[id] = ref;
1704 FOR_BB_INSNS (bb, insn)
1706 if (INSN_P (insn))
1708 unsigned int uid = INSN_UID (insn);
1710 if (include_defs)
1711 for (ref_rec = DF_INSN_UID_DEFS (uid); *ref_rec; ref_rec++)
1713 df_ref ref = *ref_rec;
1714 unsigned int regno = DF_REF_REGNO (ref);
1715 if (regno >= start)
1717 unsigned int id
1718 = ref_info->begin[regno] + ref_info->count[regno]++;
1719 DF_REF_ID (ref) = id;
1720 ref_info->refs[id] = ref;
1723 if (include_uses)
1724 for (ref_rec = DF_INSN_UID_USES (uid); *ref_rec; ref_rec++)
1726 df_ref ref = *ref_rec;
1727 unsigned int regno = DF_REF_REGNO (ref);
1728 if (regno >= start)
1730 unsigned int id
1731 = ref_info->begin[regno] + ref_info->count[regno]++;
1732 DF_REF_ID (ref) = id;
1733 ref_info->refs[id] = ref;
1736 if (include_eq_uses)
1737 for (ref_rec = DF_INSN_UID_EQ_USES (uid); *ref_rec; ref_rec++)
1739 df_ref ref = *ref_rec;
1740 unsigned int regno = DF_REF_REGNO (ref);
1741 if (regno >= start)
1743 unsigned int id
1744 = ref_info->begin[regno] + ref_info->count[regno]++;
1745 DF_REF_ID (ref) = id;
1746 ref_info->refs[id] = ref;
1753 /* The bitmap size is not decremented when refs are deleted. So
1754 reset it now that we have squished out all of the empty
1755 slots. */
1757 ref_info->table_size = offset;
1760 /* Take build ref table for either the uses or defs from the reg-use
1761 or reg-def chains. */
1763 static void
1764 df_reorganize_refs_by_reg (struct df_ref_info *ref_info,
1765 bool include_defs,
1766 bool include_uses,
1767 bool include_eq_uses)
1769 if (df->analyze_subset)
1770 df_reorganize_refs_by_reg_by_insn (ref_info, include_defs,
1771 include_uses, include_eq_uses);
1772 else
1773 df_reorganize_refs_by_reg_by_reg (ref_info, include_defs,
1774 include_uses, include_eq_uses);
1778 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1779 static unsigned int
1780 df_add_refs_to_table (unsigned int offset,
1781 struct df_ref_info *ref_info,
1782 df_ref *ref_vec)
1784 while (*ref_vec)
1786 df_ref ref = *ref_vec;
1787 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
1788 || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER))
1790 ref_info->refs[offset] = ref;
1791 DF_REF_ID (*ref_vec) = offset++;
1793 ref_vec++;
1795 return offset;
1799 /* Count the number of refs in all of the insns of BB. Include the
1800 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1801 eq_uses if INCLUDE_EQ_USES. */
1803 static unsigned int
1804 df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset,
1805 struct df_ref_info *ref_info,
1806 bool include_defs, bool include_uses,
1807 bool include_eq_uses)
1809 rtx insn;
1811 if (include_defs)
1812 offset = df_add_refs_to_table (offset, ref_info,
1813 df_get_artificial_defs (bb->index));
1814 if (include_uses)
1815 offset = df_add_refs_to_table (offset, ref_info,
1816 df_get_artificial_uses (bb->index));
1818 FOR_BB_INSNS (bb, insn)
1819 if (INSN_P (insn))
1821 unsigned int uid = INSN_UID (insn);
1822 if (include_defs)
1823 offset = df_add_refs_to_table (offset, ref_info,
1824 DF_INSN_UID_DEFS (uid));
1825 if (include_uses)
1826 offset = df_add_refs_to_table (offset, ref_info,
1827 DF_INSN_UID_USES (uid));
1828 if (include_eq_uses)
1829 offset = df_add_refs_to_table (offset, ref_info,
1830 DF_INSN_UID_EQ_USES (uid));
1832 return offset;
1836 /* Organize the refs by insn into the table in REF_INFO. If
1837 blocks_to_analyze is defined, use that set, otherwise the entire
1838 program. Include the defs if INCLUDE_DEFS. Include the uses if
1839 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1841 static void
1842 df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
1843 bool include_defs, bool include_uses,
1844 bool include_eq_uses)
1846 basic_block bb;
1847 unsigned int offset = 0;
1849 ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
1850 df_check_and_grow_ref_info (ref_info, 1);
1851 if (df->blocks_to_analyze)
1853 bitmap_iterator bi;
1854 unsigned int index;
1856 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
1858 offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index), offset, ref_info,
1859 include_defs, include_uses,
1860 include_eq_uses);
1863 ref_info->table_size = offset;
1865 else
1867 FOR_ALL_BB (bb)
1868 offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info,
1869 include_defs, include_uses,
1870 include_eq_uses);
1871 ref_info->table_size = offset;
1876 /* If the use refs in DF are not organized, reorganize them. */
1878 void
1879 df_maybe_reorganize_use_refs (enum df_ref_order order)
1881 if (order == df->use_info.ref_order)
1882 return;
1884 switch (order)
1886 case DF_REF_ORDER_BY_REG:
1887 df_reorganize_refs_by_reg (&df->use_info, false, true, false);
1888 break;
1890 case DF_REF_ORDER_BY_REG_WITH_NOTES:
1891 df_reorganize_refs_by_reg (&df->use_info, false, true, true);
1892 break;
1894 case DF_REF_ORDER_BY_INSN:
1895 df_reorganize_refs_by_insn (&df->use_info, false, true, false);
1896 break;
1898 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1899 df_reorganize_refs_by_insn (&df->use_info, false, true, true);
1900 break;
1902 case DF_REF_ORDER_NO_TABLE:
1903 free (df->use_info.refs);
1904 df->use_info.refs = NULL;
1905 df->use_info.refs_size = 0;
1906 break;
1908 case DF_REF_ORDER_UNORDERED:
1909 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1910 gcc_unreachable ();
1911 break;
1914 df->use_info.ref_order = order;
1918 /* If the def refs in DF are not organized, reorganize them. */
1920 void
1921 df_maybe_reorganize_def_refs (enum df_ref_order order)
1923 if (order == df->def_info.ref_order)
1924 return;
1926 switch (order)
1928 case DF_REF_ORDER_BY_REG:
1929 df_reorganize_refs_by_reg (&df->def_info, true, false, false);
1930 break;
1932 case DF_REF_ORDER_BY_INSN:
1933 df_reorganize_refs_by_insn (&df->def_info, true, false, false);
1934 break;
1936 case DF_REF_ORDER_NO_TABLE:
1937 free (df->def_info.refs);
1938 df->def_info.refs = NULL;
1939 df->def_info.refs_size = 0;
1940 break;
1942 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
1943 case DF_REF_ORDER_BY_REG_WITH_NOTES:
1944 case DF_REF_ORDER_UNORDERED:
1945 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
1946 gcc_unreachable ();
1947 break;
1950 df->def_info.ref_order = order;
1954 /* Change all of the basic block references in INSN to use the insn's
1955 current basic block. This function is called from routines that move
1956 instructions from one block to another. */
1958 void
1959 df_insn_change_bb (rtx insn, basic_block new_bb)
1961 basic_block old_bb = BLOCK_FOR_INSN (insn);
1962 struct df_insn_info *insn_info;
1963 unsigned int uid = INSN_UID (insn);
1965 if (old_bb == new_bb)
1966 return;
1968 set_block_for_insn (insn, new_bb);
1970 if (!df)
1971 return;
1973 if (dump_file)
1974 fprintf (dump_file, "changing bb of uid %d\n", uid);
1976 insn_info = DF_INSN_UID_SAFE_GET (uid);
1977 if (insn_info == NULL)
1979 if (dump_file)
1980 fprintf (dump_file, " unscanned insn\n");
1981 df_insn_rescan (insn);
1982 return;
1985 if (!INSN_P (insn))
1986 return;
1988 df_set_bb_dirty (new_bb);
1989 if (old_bb)
1991 if (dump_file)
1992 fprintf (dump_file, " from %d to %d\n",
1993 old_bb->index, new_bb->index);
1994 df_set_bb_dirty (old_bb);
1996 else
1997 if (dump_file)
1998 fprintf (dump_file, " to %d\n", new_bb->index);
2002 /* Helper function for df_ref_change_reg_with_loc. */
2004 static void
2005 df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df,
2006 struct df_reg_info *new_df,
2007 int new_regno, rtx loc)
2009 df_ref the_ref = old_df->reg_chain;
2011 while (the_ref)
2013 if ((!DF_REF_IS_ARTIFICIAL (the_ref))
2014 && (DF_REF_LOC (the_ref))
2015 && (*DF_REF_LOC (the_ref) == loc))
2017 df_ref next_ref = DF_REF_NEXT_REG (the_ref);
2018 df_ref prev_ref = DF_REF_PREV_REG (the_ref);
2019 df_ref *ref_vec, *ref_vec_t;
2020 struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref);
2021 unsigned int count = 0;
2023 DF_REF_REGNO (the_ref) = new_regno;
2024 DF_REF_REG (the_ref) = regno_reg_rtx[new_regno];
2026 /* Pull the_ref out of the old regno chain. */
2027 if (prev_ref)
2028 DF_REF_NEXT_REG (prev_ref) = next_ref;
2029 else
2030 old_df->reg_chain = next_ref;
2031 if (next_ref)
2032 DF_REF_PREV_REG (next_ref) = prev_ref;
2033 old_df->n_refs--;
2035 /* Put the ref into the new regno chain. */
2036 DF_REF_PREV_REG (the_ref) = NULL;
2037 DF_REF_NEXT_REG (the_ref) = new_df->reg_chain;
2038 if (new_df->reg_chain)
2039 DF_REF_PREV_REG (new_df->reg_chain) = the_ref;
2040 new_df->reg_chain = the_ref;
2041 new_df->n_refs++;
2042 if (DF_REF_BB (the_ref))
2043 df_set_bb_dirty (DF_REF_BB (the_ref));
2045 /* Need to sort the record again that the ref was in because
2046 the regno is a sorting key. First, find the right
2047 record. */
2048 if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE)
2049 ref_vec = insn_info->eq_uses;
2050 else
2051 ref_vec = insn_info->uses;
2052 if (dump_file)
2053 fprintf (dump_file, "changing reg in insn %d\n",
2054 DF_REF_INSN_UID (the_ref));
2056 ref_vec_t = ref_vec;
2058 /* Find the length. */
2059 while (*ref_vec_t)
2061 count++;
2062 ref_vec_t++;
2064 qsort (ref_vec, count, sizeof (df_ref ), df_ref_compare);
2066 the_ref = next_ref;
2068 else
2069 the_ref = DF_REF_NEXT_REG (the_ref);
2074 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2075 NEW_REGNO. Refs that do not match LOC are not changed which means
2076 that artificial refs are not changed since they have no loc. This
2077 call is to support the SET_REGNO macro. */
2079 void
2080 df_ref_change_reg_with_loc (int old_regno, int new_regno, rtx loc)
2082 if ((!df) || (old_regno == -1) || (old_regno == new_regno))
2083 return;
2085 df_grow_reg_info ();
2087 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno),
2088 DF_REG_DEF_GET (new_regno), new_regno, loc);
2089 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno),
2090 DF_REG_USE_GET (new_regno), new_regno, loc);
2091 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno),
2092 DF_REG_EQ_USE_GET (new_regno), new_regno, loc);
2096 /* Delete the mw_hardregs that point into the eq_notes. */
2098 static unsigned int
2099 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info)
2101 struct df_mw_hardreg **mw_vec = insn_info->mw_hardregs;
2102 unsigned int deleted = 0;
2103 unsigned int count = 0;
2104 struct df_scan_problem_data *problem_data
2105 = (struct df_scan_problem_data *) df_scan->problem_data;
2107 if (!*mw_vec)
2108 return 0;
2110 while (*mw_vec)
2112 if ((*mw_vec)->flags & DF_REF_IN_NOTE)
2114 struct df_mw_hardreg **temp_vec = mw_vec;
2116 pool_free (problem_data->mw_reg_pool, *mw_vec);
2117 temp_vec = mw_vec;
2118 /* Shove the remaining ones down one to fill the gap. While
2119 this looks n**2, it is highly unusual to have any mw regs
2120 in eq_notes and the chances of more than one are almost
2121 non existent. */
2122 while (*temp_vec)
2124 *temp_vec = *(temp_vec + 1);
2125 temp_vec++;
2127 deleted++;
2129 else
2131 mw_vec++;
2132 count++;
2136 if (count == 0)
2138 df_scan_free_mws_vec (insn_info->mw_hardregs);
2139 insn_info->mw_hardregs = df_null_mw_rec;
2140 return 0;
2142 return deleted;
2146 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2148 void
2149 df_notes_rescan (rtx insn)
2151 struct df_insn_info *insn_info;
2152 unsigned int uid = INSN_UID (insn);
2154 if (!df)
2155 return;
2157 /* The client has disabled rescanning and plans to do it itself. */
2158 if (df->changeable_flags & DF_NO_INSN_RESCAN)
2159 return;
2161 /* Do nothing if the insn hasn't been emitted yet. */
2162 if (!BLOCK_FOR_INSN (insn))
2163 return;
2165 df_grow_bb_info (df_scan);
2166 df_grow_reg_info ();
2168 insn_info = DF_INSN_UID_SAFE_GET (INSN_UID(insn));
2170 /* The client has deferred rescanning. */
2171 if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
2173 if (!insn_info)
2175 insn_info = df_insn_create_insn_record (insn);
2176 insn_info->defs = df_null_ref_rec;
2177 insn_info->uses = df_null_ref_rec;
2178 insn_info->eq_uses = df_null_ref_rec;
2179 insn_info->mw_hardregs = df_null_mw_rec;
2182 bitmap_clear_bit (&df->insns_to_delete, uid);
2183 /* If the insn is set to be rescanned, it does not need to also
2184 be notes rescanned. */
2185 if (!bitmap_bit_p (&df->insns_to_rescan, uid))
2186 bitmap_set_bit (&df->insns_to_notes_rescan, INSN_UID (insn));
2187 return;
2190 bitmap_clear_bit (&df->insns_to_delete, uid);
2191 bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
2193 if (insn_info)
2195 basic_block bb = BLOCK_FOR_INSN (insn);
2196 rtx note;
2197 struct df_collection_rec collection_rec;
2198 unsigned int num_deleted;
2199 unsigned int mw_len;
2201 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
2202 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
2203 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
2205 num_deleted = df_mw_hardreg_chain_delete_eq_uses (insn_info);
2206 df_ref_chain_delete (insn_info->eq_uses);
2207 insn_info->eq_uses = NULL;
2209 /* Process REG_EQUIV/REG_EQUAL notes */
2210 for (note = REG_NOTES (insn); note;
2211 note = XEXP (note, 1))
2213 switch (REG_NOTE_KIND (note))
2215 case REG_EQUIV:
2216 case REG_EQUAL:
2217 df_uses_record (DF_REF_REGULAR, &collection_rec,
2218 &XEXP (note, 0), DF_REF_REG_USE,
2219 bb, insn_info, DF_REF_IN_NOTE, -1, -1, VOIDmode);
2220 default:
2221 break;
2225 /* Find some place to put any new mw_hardregs. */
2226 df_canonize_collection_rec (&collection_rec);
2227 mw_len = VEC_length (df_mw_hardreg_ptr, collection_rec.mw_vec);
2228 if (mw_len)
2230 unsigned int count = 0;
2231 struct df_mw_hardreg **mw_rec = insn_info->mw_hardregs;
2232 while (*mw_rec)
2234 count++;
2235 mw_rec++;
2238 if (count)
2240 /* Append to the end of the existing record after
2241 expanding it if necessary. */
2242 if (mw_len > num_deleted)
2244 insn_info->mw_hardregs =
2245 XRESIZEVEC (struct df_mw_hardreg *,
2246 insn_info->mw_hardregs,
2247 count + 1 + mw_len);
2249 memcpy (&insn_info->mw_hardregs[count],
2250 VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2251 mw_len * sizeof (struct df_mw_hardreg *));
2252 insn_info->mw_hardregs[count + mw_len] = NULL;
2253 qsort (insn_info->mw_hardregs, count + mw_len,
2254 sizeof (struct df_mw_hardreg *), df_mw_compare);
2256 else
2258 /* No vector there. */
2259 insn_info->mw_hardregs
2260 = XNEWVEC (struct df_mw_hardreg*, 1 + mw_len);
2261 memcpy (insn_info->mw_hardregs,
2262 VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec),
2263 mw_len * sizeof (struct df_mw_hardreg *));
2264 insn_info->mw_hardregs[mw_len] = NULL;
2267 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2268 ignore it. */
2269 VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
2270 df_refs_add_to_chains (&collection_rec, bb, insn);
2271 VEC_free (df_ref, stack, collection_rec.eq_use_vec);
2273 else
2274 df_insn_rescan (insn);
2279 /*----------------------------------------------------------------------------
2280 Hard core instruction scanning code. No external interfaces here,
2281 just a lot of routines that look inside insns.
2282 ----------------------------------------------------------------------------*/
2285 /* Return true if the contents of two df_ref's are identical.
2286 It ignores DF_REF_MARKER. */
2288 static bool
2289 df_ref_equal_p (df_ref ref1, df_ref ref2)
2291 if (!ref2)
2292 return false;
2294 if (ref1 == ref2)
2295 return true;
2297 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)
2298 || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)
2299 || DF_REF_REG (ref1) != DF_REF_REG (ref2)
2300 || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)
2301 || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))
2302 != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)))
2303 || DF_REF_BB (ref1) != DF_REF_BB (ref2)
2304 || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2))
2305 return false;
2307 switch (DF_REF_CLASS (ref1))
2309 case DF_REF_ARTIFICIAL:
2310 case DF_REF_BASE:
2311 return true;
2313 case DF_REF_EXTRACT:
2314 if ((DF_REF_EXTRACT_OFFSET (ref1) != DF_REF_EXTRACT_OFFSET (ref2))
2315 || (DF_REF_EXTRACT_WIDTH (ref1) != DF_REF_EXTRACT_WIDTH (ref2))
2316 || (DF_REF_EXTRACT_MODE (ref1) != DF_REF_EXTRACT_MODE (ref2)))
2317 return false;
2318 /* fallthru. */
2320 case DF_REF_REGULAR:
2321 return DF_REF_LOC (ref1) == DF_REF_LOC (ref2);
2323 default:
2324 gcc_unreachable ();
2326 return false;
2330 /* Compare REF1 and REF2 for sorting. This is only called from places
2331 where all of the refs are of the same type, in the same insn, and
2332 have the same bb. So these fields are not checked. */
2334 static int
2335 df_ref_compare (const void *r1, const void *r2)
2337 const df_ref ref1 = *(const df_ref *)r1;
2338 const df_ref ref2 = *(const df_ref *)r2;
2340 if (ref1 == ref2)
2341 return 0;
2343 if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
2344 return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
2346 if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
2347 return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
2349 if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
2350 return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
2352 if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
2353 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2355 /* Cannot look at the LOC field on artificial refs. */
2356 if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
2357 && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
2358 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2360 if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
2362 /* If two refs are identical except that one of them has is from
2363 a mw and one is not, we need to have the one with the mw
2364 first. */
2365 if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) ==
2366 DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG))
2367 return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2);
2368 else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG))
2369 return -1;
2370 else
2371 return 1;
2374 /* The classes are the same at this point so it is safe to only look
2375 at ref1. */
2376 if (DF_REF_CLASS (ref1) == DF_REF_EXTRACT)
2378 if (DF_REF_EXTRACT_OFFSET (ref1) != DF_REF_EXTRACT_OFFSET (ref2))
2379 return DF_REF_EXTRACT_OFFSET (ref1) - DF_REF_EXTRACT_OFFSET (ref2);
2380 if (DF_REF_EXTRACT_WIDTH (ref1) != DF_REF_EXTRACT_WIDTH (ref2))
2381 return DF_REF_EXTRACT_WIDTH (ref1) - DF_REF_EXTRACT_WIDTH (ref2);
2382 if (DF_REF_EXTRACT_MODE (ref1) != DF_REF_EXTRACT_MODE (ref2))
2383 return DF_REF_EXTRACT_MODE (ref1) - DF_REF_EXTRACT_MODE (ref2);
2385 return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
2388 static void
2389 df_swap_refs (VEC(df_ref,stack) **ref_vec, int i, int j)
2391 df_ref tmp = VEC_index (df_ref, *ref_vec, i);
2392 VEC_replace (df_ref, *ref_vec, i, VEC_index (df_ref, *ref_vec, j));
2393 VEC_replace (df_ref, *ref_vec, j, tmp);
2396 /* Sort and compress a set of refs. */
2398 static void
2399 df_sort_and_compress_refs (VEC(df_ref,stack) **ref_vec)
2401 unsigned int count;
2402 unsigned int i;
2403 unsigned int dist = 0;
2405 count = VEC_length (df_ref, *ref_vec);
2407 /* If there are 1 or 0 elements, there is nothing to do. */
2408 if (count < 2)
2409 return;
2410 else if (count == 2)
2412 df_ref r0 = VEC_index (df_ref, *ref_vec, 0);
2413 df_ref r1 = VEC_index (df_ref, *ref_vec, 1);
2414 if (df_ref_compare (&r0, &r1) > 0)
2415 df_swap_refs (ref_vec, 0, 1);
2417 else
2419 for (i = 0; i < count - 1; i++)
2421 df_ref r0 = VEC_index (df_ref, *ref_vec, i);
2422 df_ref r1 = VEC_index (df_ref, *ref_vec, i + 1);
2423 if (df_ref_compare (&r0, &r1) >= 0)
2424 break;
2426 /* If the array is already strictly ordered,
2427 which is the most common case for large COUNT case
2428 (which happens for CALL INSNs),
2429 no need to sort and filter out duplicate.
2430 Simply return the count.
2431 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2432 of DF_REF_COMPARE. */
2433 if (i == count - 1)
2434 return;
2435 qsort (VEC_address (df_ref, *ref_vec), count, sizeof (df_ref),
2436 df_ref_compare);
2439 for (i=0; i<count-dist; i++)
2441 /* Find the next ref that is not equal to the current ref. */
2442 while (i + dist + 1 < count
2443 && df_ref_equal_p (VEC_index (df_ref, *ref_vec, i),
2444 VEC_index (df_ref, *ref_vec, i + dist + 1)))
2446 df_free_ref (VEC_index (df_ref, *ref_vec, i + dist + 1));
2447 dist++;
2449 /* Copy it down to the next position. */
2450 if (dist && i + dist + 1 < count)
2451 VEC_replace (df_ref, *ref_vec, i + 1,
2452 VEC_index (df_ref, *ref_vec, i + dist + 1));
2455 count -= dist;
2456 VEC_truncate (df_ref, *ref_vec, count);
2460 /* Return true if the contents of two df_ref's are identical.
2461 It ignores DF_REF_MARKER. */
2463 static bool
2464 df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2)
2466 if (!mw2)
2467 return false;
2468 return (mw1 == mw2) ||
2469 (mw1->mw_reg == mw2->mw_reg
2470 && mw1->type == mw2->type
2471 && mw1->flags == mw2->flags
2472 && mw1->start_regno == mw2->start_regno
2473 && mw1->end_regno == mw2->end_regno);
2477 /* Compare MW1 and MW2 for sorting. */
2479 static int
2480 df_mw_compare (const void *m1, const void *m2)
2482 const struct df_mw_hardreg *const mw1 = *(const struct df_mw_hardreg *const*)m1;
2483 const struct df_mw_hardreg *const mw2 = *(const struct df_mw_hardreg *const*)m2;
2485 if (mw1 == mw2)
2486 return 0;
2488 if (mw1->type != mw2->type)
2489 return mw1->type - mw2->type;
2491 if (mw1->flags != mw2->flags)
2492 return mw1->flags - mw2->flags;
2494 if (mw1->start_regno != mw2->start_regno)
2495 return mw1->start_regno - mw2->start_regno;
2497 if (mw1->end_regno != mw2->end_regno)
2498 return mw1->end_regno - mw2->end_regno;
2500 if (mw1->mw_reg != mw2->mw_reg)
2501 return mw1->mw_order - mw2->mw_order;
2503 return 0;
2507 /* Sort and compress a set of refs. */
2509 static void
2510 df_sort_and_compress_mws (VEC(df_mw_hardreg_ptr,stack) **mw_vec)
2512 unsigned int count;
2513 struct df_scan_problem_data *problem_data
2514 = (struct df_scan_problem_data *) df_scan->problem_data;
2515 unsigned int i;
2516 unsigned int dist = 0;
2518 count = VEC_length (df_mw_hardreg_ptr, *mw_vec);
2519 if (count < 2)
2520 return;
2521 else if (count == 2)
2523 struct df_mw_hardreg *m0 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 0);
2524 struct df_mw_hardreg *m1 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 1);
2525 if (df_mw_compare (&m0, &m1) > 0)
2527 struct df_mw_hardreg *tmp = VEC_index (df_mw_hardreg_ptr,
2528 *mw_vec, 0);
2529 VEC_replace (df_mw_hardreg_ptr, *mw_vec, 0,
2530 VEC_index (df_mw_hardreg_ptr, *mw_vec, 1));
2531 VEC_replace (df_mw_hardreg_ptr, *mw_vec, 1, tmp);
2534 else
2535 qsort (VEC_address (df_mw_hardreg_ptr, *mw_vec), count,
2536 sizeof (struct df_mw_hardreg *), df_mw_compare);
2538 for (i=0; i<count-dist; i++)
2540 /* Find the next ref that is not equal to the current ref. */
2541 while (i + dist + 1 < count
2542 && df_mw_equal_p (VEC_index (df_mw_hardreg_ptr, *mw_vec, i),
2543 VEC_index (df_mw_hardreg_ptr, *mw_vec,
2544 i + dist + 1)))
2546 pool_free (problem_data->mw_reg_pool,
2547 VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2548 dist++;
2550 /* Copy it down to the next position. */
2551 if (dist && i + dist + 1 < count)
2552 VEC_replace (df_mw_hardreg_ptr, *mw_vec, i + 1,
2553 VEC_index (df_mw_hardreg_ptr, *mw_vec, i + dist + 1));
2556 count -= dist;
2557 VEC_truncate (df_mw_hardreg_ptr, *mw_vec, count);
2561 /* Sort and remove duplicates from the COLLECTION_REC. */
2563 static void
2564 df_canonize_collection_rec (struct df_collection_rec *collection_rec)
2566 df_sort_and_compress_refs (&collection_rec->def_vec);
2567 df_sort_and_compress_refs (&collection_rec->use_vec);
2568 df_sort_and_compress_refs (&collection_rec->eq_use_vec);
2569 df_sort_and_compress_mws (&collection_rec->mw_vec);
2573 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2575 static void
2576 df_install_ref (df_ref this_ref,
2577 struct df_reg_info *reg_info,
2578 struct df_ref_info *ref_info,
2579 bool add_to_table)
2581 unsigned int regno = DF_REF_REGNO (this_ref);
2582 /* Add the ref to the reg_{def,use,eq_use} chain. */
2583 df_ref head = reg_info->reg_chain;
2585 reg_info->reg_chain = this_ref;
2586 reg_info->n_refs++;
2588 if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE))
2590 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
2591 df->hard_regs_live_count[regno]++;
2594 gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL
2595 && DF_REF_PREV_REG (this_ref) == NULL);
2597 DF_REF_NEXT_REG (this_ref) = head;
2599 /* We cannot actually link to the head of the chain. */
2600 DF_REF_PREV_REG (this_ref) = NULL;
2602 if (head)
2603 DF_REF_PREV_REG (head) = this_ref;
2605 if (add_to_table)
2607 gcc_assert (ref_info->ref_order != DF_REF_ORDER_NO_TABLE);
2608 df_check_and_grow_ref_info (ref_info, 1);
2609 DF_REF_ID (this_ref) = ref_info->table_size;
2610 /* Add the ref to the big array of defs. */
2611 ref_info->refs[ref_info->table_size] = this_ref;
2612 ref_info->table_size++;
2614 else
2615 DF_REF_ID (this_ref) = -1;
2617 ref_info->total_size++;
2621 /* This function takes one of the groups of refs (defs, uses or
2622 eq_uses) and installs the entire group into the insn. It also adds
2623 each of these refs into the appropriate chains. */
2625 static df_ref *
2626 df_install_refs (basic_block bb,
2627 VEC(df_ref,stack)* old_vec,
2628 struct df_reg_info **reg_info,
2629 struct df_ref_info *ref_info,
2630 bool is_notes)
2632 unsigned int count;
2634 count = VEC_length (df_ref, old_vec);
2635 if (count)
2637 df_ref *new_vec = XNEWVEC (df_ref, count + 1);
2638 bool add_to_table;
2639 df_ref this_ref;
2640 unsigned int ix;
2642 switch (ref_info->ref_order)
2644 case DF_REF_ORDER_UNORDERED_WITH_NOTES:
2645 case DF_REF_ORDER_BY_REG_WITH_NOTES:
2646 case DF_REF_ORDER_BY_INSN_WITH_NOTES:
2647 ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
2648 add_to_table = true;
2649 break;
2650 case DF_REF_ORDER_UNORDERED:
2651 case DF_REF_ORDER_BY_REG:
2652 case DF_REF_ORDER_BY_INSN:
2653 ref_info->ref_order = DF_REF_ORDER_UNORDERED;
2654 add_to_table = !is_notes;
2655 break;
2656 default:
2657 add_to_table = false;
2658 break;
2661 /* Do not add if ref is not in the right blocks. */
2662 if (add_to_table && df->analyze_subset)
2663 add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
2665 FOR_EACH_VEC_ELT (df_ref, old_vec, ix, this_ref)
2667 new_vec[ix] = this_ref;
2668 df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)],
2669 ref_info, add_to_table);
2672 new_vec[count] = NULL;
2673 return new_vec;
2675 else
2676 return df_null_ref_rec;
2680 /* This function takes the mws installs the entire group into the
2681 insn. */
2683 static struct df_mw_hardreg **
2684 df_install_mws (VEC(df_mw_hardreg_ptr,stack) *old_vec)
2686 unsigned int count;
2688 count = VEC_length (df_mw_hardreg_ptr, old_vec);
2689 if (count)
2691 struct df_mw_hardreg **new_vec
2692 = XNEWVEC (struct df_mw_hardreg*, count + 1);
2693 memcpy (new_vec, VEC_address (df_mw_hardreg_ptr, old_vec),
2694 sizeof (struct df_mw_hardreg*) * count);
2695 new_vec[count] = NULL;
2696 return new_vec;
2698 else
2699 return df_null_mw_rec;
2703 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2704 chains and update other necessary information. */
2706 static void
2707 df_refs_add_to_chains (struct df_collection_rec *collection_rec,
2708 basic_block bb, rtx insn)
2710 if (insn)
2712 struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn);
2713 /* If there is a vector in the collection rec, add it to the
2714 insn. A null rec is a signal that the caller will handle the
2715 chain specially. */
2716 if (collection_rec->def_vec)
2718 df_scan_free_ref_vec (insn_rec->defs);
2719 insn_rec->defs
2720 = df_install_refs (bb, collection_rec->def_vec,
2721 df->def_regs,
2722 &df->def_info, false);
2724 if (collection_rec->use_vec)
2726 df_scan_free_ref_vec (insn_rec->uses);
2727 insn_rec->uses
2728 = df_install_refs (bb, collection_rec->use_vec,
2729 df->use_regs,
2730 &df->use_info, false);
2732 if (collection_rec->eq_use_vec)
2734 df_scan_free_ref_vec (insn_rec->eq_uses);
2735 insn_rec->eq_uses
2736 = df_install_refs (bb, collection_rec->eq_use_vec,
2737 df->eq_use_regs,
2738 &df->use_info, true);
2740 if (collection_rec->mw_vec)
2742 df_scan_free_mws_vec (insn_rec->mw_hardregs);
2743 insn_rec->mw_hardregs
2744 = df_install_mws (collection_rec->mw_vec);
2747 else
2749 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
2751 df_scan_free_ref_vec (bb_info->artificial_defs);
2752 bb_info->artificial_defs
2753 = df_install_refs (bb, collection_rec->def_vec,
2754 df->def_regs,
2755 &df->def_info, false);
2756 df_scan_free_ref_vec (bb_info->artificial_uses);
2757 bb_info->artificial_uses
2758 = df_install_refs (bb, collection_rec->use_vec,
2759 df->use_regs,
2760 &df->use_info, false);
2765 /* Allocate a ref and initialize its fields.
2767 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2768 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the fields
2769 if they were constants. Otherwise they should be -1 if those flags
2770 were set. */
2772 static df_ref
2773 df_ref_create_structure (enum df_ref_class cl,
2774 struct df_collection_rec *collection_rec,
2775 rtx reg, rtx *loc,
2776 basic_block bb, struct df_insn_info *info,
2777 enum df_ref_type ref_type,
2778 int ref_flags,
2779 int width, int offset, enum machine_mode mode)
2781 df_ref this_ref = NULL;
2782 int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2783 struct df_scan_problem_data *problem_data
2784 = (struct df_scan_problem_data *) df_scan->problem_data;
2786 switch (cl)
2788 case DF_REF_BASE:
2789 this_ref = (df_ref) pool_alloc (problem_data->ref_base_pool);
2790 gcc_checking_assert (loc == NULL);
2791 break;
2793 case DF_REF_ARTIFICIAL:
2794 this_ref = (df_ref) pool_alloc (problem_data->ref_artificial_pool);
2795 this_ref->artificial_ref.bb = bb;
2796 gcc_checking_assert (loc == NULL);
2797 break;
2799 case DF_REF_REGULAR:
2800 this_ref = (df_ref) pool_alloc (problem_data->ref_regular_pool);
2801 this_ref->regular_ref.loc = loc;
2802 gcc_checking_assert (loc);
2803 break;
2805 case DF_REF_EXTRACT:
2806 this_ref = (df_ref) pool_alloc (problem_data->ref_extract_pool);
2807 DF_REF_EXTRACT_WIDTH (this_ref) = width;
2808 DF_REF_EXTRACT_OFFSET (this_ref) = offset;
2809 DF_REF_EXTRACT_MODE (this_ref) = mode;
2810 this_ref->regular_ref.loc = loc;
2811 gcc_checking_assert (loc);
2812 break;
2815 DF_REF_CLASS (this_ref) = cl;
2816 DF_REF_ID (this_ref) = -1;
2817 DF_REF_REG (this_ref) = reg;
2818 DF_REF_REGNO (this_ref) = regno;
2819 DF_REF_TYPE (this_ref) = ref_type;
2820 DF_REF_INSN_INFO (this_ref) = info;
2821 DF_REF_CHAIN (this_ref) = NULL;
2822 DF_REF_FLAGS (this_ref) = ref_flags;
2823 DF_REF_NEXT_REG (this_ref) = NULL;
2824 DF_REF_PREV_REG (this_ref) = NULL;
2825 DF_REF_ORDER (this_ref) = df->ref_order++;
2827 /* We need to clear this bit because fwprop, and in the future
2828 possibly other optimizations sometimes create new refs using ond
2829 refs as the model. */
2830 DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE);
2832 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2833 if ((regno < FIRST_PSEUDO_REGISTER)
2834 && (!DF_REF_IS_ARTIFICIAL (this_ref)))
2836 if (DF_REF_REG_DEF_P (this_ref))
2838 if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER))
2839 DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2841 else if (!(TEST_HARD_REG_BIT (elim_reg_set, regno)
2842 && (regno == FRAME_POINTER_REGNUM
2843 || regno == ARG_POINTER_REGNUM)))
2844 DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
2847 if (collection_rec)
2849 if (DF_REF_REG_DEF_P (this_ref))
2850 VEC_safe_push (df_ref, stack, collection_rec->def_vec, this_ref);
2851 else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE)
2852 VEC_safe_push (df_ref, stack, collection_rec->eq_use_vec, this_ref);
2853 else
2854 VEC_safe_push (df_ref, stack, collection_rec->use_vec, this_ref);
2857 return this_ref;
2861 /* Create new references of type DF_REF_TYPE for each part of register REG
2862 at address LOC within INSN of BB.
2864 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2865 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
2866 fields if they were constants. Otherwise they should be -1 if
2867 those flags were set. */
2870 static void
2871 df_ref_record (enum df_ref_class cl,
2872 struct df_collection_rec *collection_rec,
2873 rtx reg, rtx *loc,
2874 basic_block bb, struct df_insn_info *insn_info,
2875 enum df_ref_type ref_type,
2876 int ref_flags,
2877 int width, int offset, enum machine_mode mode)
2879 unsigned int regno;
2881 gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
2883 regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
2884 if (regno < FIRST_PSEUDO_REGISTER)
2886 struct df_mw_hardreg *hardreg = NULL;
2887 struct df_scan_problem_data *problem_data
2888 = (struct df_scan_problem_data *) df_scan->problem_data;
2889 unsigned int i;
2890 unsigned int endregno;
2891 df_ref ref;
2893 if (GET_CODE (reg) == SUBREG)
2895 regno += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
2896 SUBREG_BYTE (reg), GET_MODE (reg));
2897 endregno = regno + subreg_nregs (reg);
2899 else
2900 endregno = END_HARD_REGNO (reg);
2902 /* If this is a multiword hardreg, we create some extra
2903 datastructures that will enable us to easily build REG_DEAD
2904 and REG_UNUSED notes. */
2905 if ((endregno != regno + 1) && insn_info)
2907 /* Sets to a subreg of a multiword register are partial.
2908 Sets to a non-subreg of a multiword register are not. */
2909 if (GET_CODE (reg) == SUBREG)
2910 ref_flags |= DF_REF_PARTIAL;
2911 ref_flags |= DF_REF_MW_HARDREG;
2913 hardreg = (struct df_mw_hardreg *) pool_alloc (problem_data->mw_reg_pool);
2914 hardreg->type = ref_type;
2915 hardreg->flags = ref_flags;
2916 hardreg->mw_reg = reg;
2917 hardreg->start_regno = regno;
2918 hardreg->end_regno = endregno - 1;
2919 hardreg->mw_order = df->ref_order++;
2920 VEC_safe_push (df_mw_hardreg_ptr, stack, collection_rec->mw_vec,
2921 hardreg);
2924 for (i = regno; i < endregno; i++)
2926 ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc,
2927 bb, insn_info, ref_type, ref_flags,
2928 width, offset, mode);
2930 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i);
2933 else
2935 df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info,
2936 ref_type, ref_flags, width, offset, mode);
2941 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2942 covered by the outer mode is smaller than that covered by the inner mode,
2943 is a read-modify-write operation.
2944 This function returns true iff the SUBREG X is such a SUBREG. */
2946 bool
2947 df_read_modify_subreg_p (rtx x)
2949 unsigned int isize, osize;
2950 if (GET_CODE (x) != SUBREG)
2951 return false;
2952 isize = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
2953 osize = GET_MODE_SIZE (GET_MODE (x));
2954 return isize > osize
2955 && isize > REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x)));
2959 /* Process all the registers defined in the rtx, X.
2960 Autoincrement/decrement definitions will be picked up by
2961 df_uses_record. */
2963 static void
2964 df_def_record_1 (struct df_collection_rec *collection_rec,
2965 rtx x, basic_block bb, struct df_insn_info *insn_info,
2966 int flags)
2968 rtx *loc;
2969 rtx dst;
2970 int offset = -1;
2971 int width = -1;
2972 enum machine_mode mode = VOIDmode;
2973 enum df_ref_class cl = DF_REF_REGULAR;
2975 /* We may recursively call ourselves on EXPR_LIST when dealing with PARALLEL
2976 construct. */
2977 if (GET_CODE (x) == EXPR_LIST || GET_CODE (x) == CLOBBER)
2978 loc = &XEXP (x, 0);
2979 else
2980 loc = &SET_DEST (x);
2981 dst = *loc;
2983 /* It is legal to have a set destination be a parallel. */
2984 if (GET_CODE (dst) == PARALLEL)
2986 int i;
2988 for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
2990 rtx temp = XVECEXP (dst, 0, i);
2991 if (GET_CODE (temp) == EXPR_LIST || GET_CODE (temp) == CLOBBER
2992 || GET_CODE (temp) == SET)
2993 df_def_record_1 (collection_rec,
2994 temp, bb, insn_info,
2995 GET_CODE (temp) == CLOBBER
2996 ? flags | DF_REF_MUST_CLOBBER : flags);
2998 return;
3001 if (GET_CODE (dst) == STRICT_LOW_PART)
3003 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;
3005 loc = &XEXP (dst, 0);
3006 dst = *loc;
3009 if (GET_CODE (dst) == ZERO_EXTRACT)
3011 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;
3013 if (CONST_INT_P (XEXP (dst, 1))
3014 && CONST_INT_P (XEXP (dst, 2)))
3016 width = INTVAL (XEXP (dst, 1));
3017 offset = INTVAL (XEXP (dst, 2));
3018 mode = GET_MODE (dst);
3019 cl = DF_REF_EXTRACT;
3022 loc = &XEXP (dst, 0);
3023 dst = *loc;
3026 /* At this point if we do not have a reg or a subreg, just return. */
3027 if (REG_P (dst))
3029 df_ref_record (cl, collection_rec,
3030 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags,
3031 width, offset, mode);
3033 /* We want to keep sp alive everywhere - by making all
3034 writes to sp also use of sp. */
3035 if (REGNO (dst) == STACK_POINTER_REGNUM)
3036 df_ref_record (DF_REF_BASE, collection_rec,
3037 dst, NULL, bb, insn_info, DF_REF_REG_USE, flags,
3038 width, offset, mode);
3040 else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
3042 if (df_read_modify_subreg_p (dst))
3043 flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;
3045 flags |= DF_REF_SUBREG;
3047 df_ref_record (cl, collection_rec,
3048 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags,
3049 width, offset, mode);
3054 /* Process all the registers defined in the pattern rtx, X. */
3056 static void
3057 df_defs_record (struct df_collection_rec *collection_rec,
3058 rtx x, basic_block bb, struct df_insn_info *insn_info,
3059 int flags)
3061 RTX_CODE code = GET_CODE (x);
3063 if (code == SET || code == CLOBBER)
3065 /* Mark the single def within the pattern. */
3066 int clobber_flags = flags;
3067 clobber_flags |= (code == CLOBBER) ? DF_REF_MUST_CLOBBER : 0;
3068 df_def_record_1 (collection_rec, x, bb, insn_info, clobber_flags);
3070 else if (code == COND_EXEC)
3072 df_defs_record (collection_rec, COND_EXEC_CODE (x),
3073 bb, insn_info, DF_REF_CONDITIONAL);
3075 else if (code == PARALLEL)
3077 int i;
3079 /* Mark the multiple defs within the pattern. */
3080 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
3081 df_defs_record (collection_rec, XVECEXP (x, 0, i), bb, insn_info, flags);
3086 /* Process all the registers used in the rtx at address LOC.
3088 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
3089 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
3090 fields if they were constants. Otherwise they should be -1 if
3091 those flags were set. */
3093 static void
3094 df_uses_record (enum df_ref_class cl, struct df_collection_rec *collection_rec,
3095 rtx *loc, enum df_ref_type ref_type,
3096 basic_block bb, struct df_insn_info *insn_info,
3097 int flags,
3098 int width, int offset, enum machine_mode mode)
3100 RTX_CODE code;
3101 rtx x;
3103 retry:
3104 x = *loc;
3105 if (!x)
3106 return;
3107 code = GET_CODE (x);
3108 switch (code)
3110 case LABEL_REF:
3111 case SYMBOL_REF:
3112 case CONST_INT:
3113 case CONST:
3114 case CONST_DOUBLE:
3115 case CONST_FIXED:
3116 case CONST_VECTOR:
3117 case PC:
3118 case CC0:
3119 case ADDR_VEC:
3120 case ADDR_DIFF_VEC:
3121 return;
3123 case CLOBBER:
3124 /* If we are clobbering a MEM, mark any registers inside the address
3125 as being used. */
3126 if (MEM_P (XEXP (x, 0)))
3127 df_uses_record (cl, collection_rec,
3128 &XEXP (XEXP (x, 0), 0),
3129 DF_REF_REG_MEM_STORE,
3130 bb, insn_info,
3131 flags, width, offset, mode);
3133 /* If we're clobbering a REG then we have a def so ignore. */
3134 return;
3136 case MEM:
3137 df_uses_record (cl, collection_rec,
3138 &XEXP (x, 0), DF_REF_REG_MEM_LOAD,
3139 bb, insn_info, flags & DF_REF_IN_NOTE,
3140 width, offset, mode);
3141 return;
3143 case SUBREG:
3144 /* While we're here, optimize this case. */
3145 flags |= DF_REF_PARTIAL;
3146 /* In case the SUBREG is not of a REG, do not optimize. */
3147 if (!REG_P (SUBREG_REG (x)))
3149 loc = &SUBREG_REG (x);
3150 df_uses_record (cl, collection_rec, loc, ref_type, bb, insn_info, flags,
3151 width, offset, mode);
3152 return;
3154 /* ... Fall through ... */
3156 case REG:
3157 df_ref_record (cl, collection_rec,
3158 x, loc, bb, insn_info,
3159 ref_type, flags,
3160 width, offset, mode);
3161 return;
3163 case SIGN_EXTRACT:
3164 case ZERO_EXTRACT:
3166 /* If the parameters to the zero or sign extract are
3167 constants, strip them off and recurse, otherwise there is
3168 no information that we can gain from this operation. */
3169 if (CONST_INT_P (XEXP (x, 1))
3170 && CONST_INT_P (XEXP (x, 2)))
3172 width = INTVAL (XEXP (x, 1));
3173 offset = INTVAL (XEXP (x, 2));
3174 mode = GET_MODE (x);
3176 if (code == ZERO_EXTRACT)
3177 flags |= DF_REF_ZERO_EXTRACT;
3178 else
3179 flags |= DF_REF_SIGN_EXTRACT;
3181 df_uses_record (DF_REF_EXTRACT, collection_rec,
3182 &XEXP (x, 0), ref_type, bb, insn_info, flags,
3183 width, offset, mode);
3184 return;
3187 break;
3189 case SET:
3191 rtx dst = SET_DEST (x);
3192 gcc_assert (!(flags & DF_REF_IN_NOTE));
3193 df_uses_record (cl, collection_rec,
3194 &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags,
3195 width, offset, mode);
3197 switch (GET_CODE (dst))
3199 case SUBREG:
3200 if (df_read_modify_subreg_p (dst))
3202 df_uses_record (cl, collection_rec, &SUBREG_REG (dst),
3203 DF_REF_REG_USE, bb, insn_info,
3204 flags | DF_REF_READ_WRITE | DF_REF_SUBREG,
3205 width, offset, mode);
3206 break;
3208 /* Fall through. */
3209 case REG:
3210 case PARALLEL:
3211 case SCRATCH:
3212 case PC:
3213 case CC0:
3214 break;
3215 case MEM:
3216 df_uses_record (cl, collection_rec, &XEXP (dst, 0),
3217 DF_REF_REG_MEM_STORE, bb, insn_info, flags,
3218 width, offset, mode);
3219 break;
3220 case STRICT_LOW_PART:
3222 rtx *temp = &XEXP (dst, 0);
3223 /* A strict_low_part uses the whole REG and not just the
3224 SUBREG. */
3225 dst = XEXP (dst, 0);
3226 df_uses_record (cl, collection_rec,
3227 (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
3228 DF_REF_REG_USE, bb, insn_info,
3229 DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART,
3230 width, offset, mode);
3232 break;
3233 case ZERO_EXTRACT:
3235 if (CONST_INT_P (XEXP (dst, 1))
3236 && CONST_INT_P (XEXP (dst, 2)))
3238 width = INTVAL (XEXP (dst, 1));
3239 offset = INTVAL (XEXP (dst, 2));
3240 mode = GET_MODE (dst);
3241 if (GET_CODE (XEXP (dst,0)) == MEM)
3243 /* Handle the case of zero_extract(mem(...)) in the set dest.
3244 This special case is allowed only if the mem is a single byte and
3245 is useful to set a bitfield in memory. */
3246 df_uses_record (DF_REF_EXTRACT, collection_rec, &XEXP (XEXP (dst,0), 0),
3247 DF_REF_REG_MEM_STORE, bb, insn_info,
3248 DF_REF_ZERO_EXTRACT,
3249 width, offset, mode);
3251 else
3253 df_uses_record (DF_REF_EXTRACT, collection_rec, &XEXP (dst, 0),
3254 DF_REF_REG_USE, bb, insn_info,
3255 DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT,
3256 width, offset, mode);
3259 else
3261 df_uses_record (cl, collection_rec, &XEXP (dst, 1),
3262 DF_REF_REG_USE, bb, insn_info, flags,
3263 width, offset, mode);
3264 df_uses_record (cl, collection_rec, &XEXP (dst, 2),
3265 DF_REF_REG_USE, bb, insn_info, flags,
3266 width, offset, mode);
3267 df_uses_record (cl, collection_rec, &XEXP (dst, 0),
3268 DF_REF_REG_USE, bb, insn_info,
3269 DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT,
3270 width, offset, mode);
3274 break;
3276 default:
3277 gcc_unreachable ();
3279 return;
3282 case RETURN:
3283 break;
3285 case ASM_OPERANDS:
3286 case UNSPEC_VOLATILE:
3287 case TRAP_IF:
3288 case ASM_INPUT:
3290 /* Traditional and volatile asm instructions must be
3291 considered to use and clobber all hard registers, all
3292 pseudo-registers and all of memory. So must TRAP_IF and
3293 UNSPEC_VOLATILE operations.
3295 Consider for instance a volatile asm that changes the fpu
3296 rounding mode. An insn should not be moved across this
3297 even if it only uses pseudo-regs because it might give an
3298 incorrectly rounded result.
3300 However, flow.c's liveness computation did *not* do this,
3301 giving the reasoning as " ?!? Unfortunately, marking all
3302 hard registers as live causes massive problems for the
3303 register allocator and marking all pseudos as live creates
3304 mountains of uninitialized variable warnings."
3306 In order to maintain the status quo with regard to liveness
3307 and uses, we do what flow.c did and just mark any regs we
3308 can find in ASM_OPERANDS as used. In global asm insns are
3309 scanned and regs_asm_clobbered is filled out.
3311 For all ASM_OPERANDS, we must traverse the vector of input
3312 operands. We can not just fall through here since then we
3313 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3314 which do not indicate traditional asms unlike their normal
3315 usage. */
3316 if (code == ASM_OPERANDS)
3318 int j;
3320 for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
3321 df_uses_record (cl, collection_rec, &ASM_OPERANDS_INPUT (x, j),
3322 DF_REF_REG_USE, bb, insn_info, flags,
3323 width, offset, mode);
3324 return;
3326 break;
3329 case VAR_LOCATION:
3330 df_uses_record (cl, collection_rec,
3331 &PAT_VAR_LOCATION_LOC (x),
3332 DF_REF_REG_USE, bb, insn_info,
3333 flags, width, offset, mode);
3334 return;
3336 case PRE_DEC:
3337 case POST_DEC:
3338 case PRE_INC:
3339 case POST_INC:
3340 case PRE_MODIFY:
3341 case POST_MODIFY:
3342 gcc_assert (!DEBUG_INSN_P (insn_info->insn));
3343 /* Catch the def of the register being modified. */
3344 df_ref_record (cl, collection_rec, XEXP (x, 0), &XEXP (x, 0),
3345 bb, insn_info,
3346 DF_REF_REG_DEF,
3347 flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY,
3348 width, offset, mode);
3350 /* ... Fall through to handle uses ... */
3352 default:
3353 break;
3356 /* Recursively scan the operands of this expression. */
3358 const char *fmt = GET_RTX_FORMAT (code);
3359 int i;
3361 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3363 if (fmt[i] == 'e')
3365 /* Tail recursive case: save a function call level. */
3366 if (i == 0)
3368 loc = &XEXP (x, 0);
3369 goto retry;
3371 df_uses_record (cl, collection_rec, &XEXP (x, i), ref_type,
3372 bb, insn_info, flags,
3373 width, offset, mode);
3375 else if (fmt[i] == 'E')
3377 int j;
3378 for (j = 0; j < XVECLEN (x, i); j++)
3379 df_uses_record (cl, collection_rec,
3380 &XVECEXP (x, i, j), ref_type,
3381 bb, insn_info, flags,
3382 width, offset, mode);
3387 return;
3391 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3393 static void
3394 df_get_conditional_uses (struct df_collection_rec *collection_rec)
3396 unsigned int ix;
3397 df_ref ref;
3399 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, ix, ref)
3401 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL))
3403 int width = -1;
3404 int offset = -1;
3405 enum machine_mode mode = VOIDmode;
3406 df_ref use;
3408 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_SIGN_EXTRACT | DF_REF_ZERO_EXTRACT))
3410 width = DF_REF_EXTRACT_WIDTH (ref);
3411 offset = DF_REF_EXTRACT_OFFSET (ref);
3412 mode = DF_REF_EXTRACT_MODE (ref);
3415 use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref),
3416 DF_REF_LOC (ref), DF_REF_BB (ref),
3417 DF_REF_INSN_INFO (ref), DF_REF_REG_USE,
3418 DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL,
3419 width, offset, mode);
3420 DF_REF_REGNO (use) = DF_REF_REGNO (ref);
3426 /* Get call's extra defs and uses. */
3428 static void
3429 df_get_call_refs (struct df_collection_rec * collection_rec,
3430 basic_block bb,
3431 struct df_insn_info *insn_info,
3432 int flags)
3434 rtx note;
3435 bitmap_iterator bi;
3436 unsigned int ui;
3437 bool is_sibling_call;
3438 unsigned int i;
3439 df_ref def;
3440 bitmap_head defs_generated;
3442 bitmap_initialize (&defs_generated, &df_bitmap_obstack);
3444 /* Do not generate clobbers for registers that are the result of the
3445 call. This causes ordering problems in the chain building code
3446 depending on which def is seen first. */
3447 FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, i, def)
3448 bitmap_set_bit (&defs_generated, DF_REF_REGNO (def));
3450 /* Record the registers used to pass arguments, and explicitly
3451 noted as clobbered. */
3452 for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note;
3453 note = XEXP (note, 1))
3455 if (GET_CODE (XEXP (note, 0)) == USE)
3456 df_uses_record (DF_REF_REGULAR, collection_rec, &XEXP (XEXP (note, 0), 0),
3457 DF_REF_REG_USE, bb, insn_info, flags, -1, -1,
3458 VOIDmode);
3459 else if (GET_CODE (XEXP (note, 0)) == CLOBBER)
3461 if (REG_P (XEXP (XEXP (note, 0), 0)))
3463 unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
3464 if (!bitmap_bit_p (&defs_generated, regno))
3465 df_defs_record (collection_rec, XEXP (note, 0), bb,
3466 insn_info, flags);
3468 else
3469 df_uses_record (DF_REF_REGULAR, collection_rec, &XEXP (note, 0),
3470 DF_REF_REG_USE, bb, insn_info, flags, -1, -1,
3471 VOIDmode);
3475 /* The stack ptr is used (honorarily) by a CALL insn. */
3476 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[STACK_POINTER_REGNUM],
3477 NULL, bb, insn_info, DF_REF_REG_USE,
3478 DF_REF_CALL_STACK_USAGE | flags,
3479 -1, -1, VOIDmode);
3481 /* Calls may also reference any of the global registers,
3482 so they are recorded as used. */
3483 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3484 if (global_regs[i])
3486 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3487 NULL, bb, insn_info, DF_REF_REG_USE, flags, -1, -1,
3488 VOIDmode);
3489 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
3490 NULL, bb, insn_info, DF_REF_REG_DEF, flags, -1, -1,
3491 VOIDmode);
3494 is_sibling_call = SIBLING_CALL_P (insn_info->insn);
3495 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, ui, bi)
3497 if (!global_regs[ui]
3498 && (!bitmap_bit_p (&defs_generated, ui))
3499 && (!is_sibling_call
3500 || !bitmap_bit_p (df->exit_block_uses, ui)
3501 || refers_to_regno_p (ui, ui+1,
3502 crtl->return_rtx, NULL)))
3503 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[ui],
3504 NULL, bb, insn_info, DF_REF_REG_DEF,
3505 DF_REF_MAY_CLOBBER | flags,
3506 -1, -1, VOIDmode);
3509 bitmap_clear (&defs_generated);
3510 return;
3513 /* Collect all refs in the INSN. This function is free of any
3514 side-effect - it will create and return a lists of df_ref's in the
3515 COLLECTION_REC without putting those refs into existing ref chains
3516 and reg chains. */
3518 static void
3519 df_insn_refs_collect (struct df_collection_rec* collection_rec,
3520 basic_block bb, struct df_insn_info *insn_info)
3522 rtx note;
3523 bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC);
3525 /* Clear out the collection record. */
3526 VEC_truncate (df_ref, collection_rec->def_vec, 0);
3527 VEC_truncate (df_ref, collection_rec->use_vec, 0);
3528 VEC_truncate (df_ref, collection_rec->eq_use_vec, 0);
3529 VEC_truncate (df_mw_hardreg_ptr, collection_rec->mw_vec, 0);
3531 /* Record register defs. */
3532 df_defs_record (collection_rec, PATTERN (insn_info->insn), bb, insn_info, 0);
3534 /* Process REG_EQUIV/REG_EQUAL notes. */
3535 for (note = REG_NOTES (insn_info->insn); note;
3536 note = XEXP (note, 1))
3538 switch (REG_NOTE_KIND (note))
3540 case REG_EQUIV:
3541 case REG_EQUAL:
3542 df_uses_record (DF_REF_REGULAR, collection_rec,
3543 &XEXP (note, 0), DF_REF_REG_USE,
3544 bb, insn_info, DF_REF_IN_NOTE, -1, -1, VOIDmode);
3545 break;
3546 case REG_NON_LOCAL_GOTO:
3547 /* The frame ptr is used by a non-local goto. */
3548 df_ref_record (DF_REF_BASE, collection_rec,
3549 regno_reg_rtx[FRAME_POINTER_REGNUM],
3550 NULL, bb, insn_info,
3551 DF_REF_REG_USE, 0, -1, -1, VOIDmode);
3552 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3553 df_ref_record (DF_REF_BASE, collection_rec,
3554 regno_reg_rtx[HARD_FRAME_POINTER_REGNUM],
3555 NULL, bb, insn_info,
3556 DF_REF_REG_USE, 0, -1, -1, VOIDmode);
3557 #endif
3558 break;
3559 default:
3560 break;
3564 if (CALL_P (insn_info->insn))
3565 df_get_call_refs (collection_rec, bb, insn_info,
3566 (is_cond_exec) ? DF_REF_CONDITIONAL : 0);
3568 /* Record the register uses. */
3569 df_uses_record (DF_REF_REGULAR, collection_rec,
3570 &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0,
3571 -1, -1, VOIDmode);
3573 /* DF_REF_CONDITIONAL needs corresponding USES. */
3574 if (is_cond_exec)
3575 df_get_conditional_uses (collection_rec);
3577 df_canonize_collection_rec (collection_rec);
3580 /* Recompute the luids for the insns in BB. */
3582 void
3583 df_recompute_luids (basic_block bb)
3585 rtx insn;
3586 int luid = 0;
3588 df_grow_insn_info ();
3590 /* Scan the block an insn at a time from beginning to end. */
3591 FOR_BB_INSNS (bb, insn)
3593 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3594 /* Inserting labels does not always trigger the incremental
3595 rescanning. */
3596 if (!insn_info)
3598 gcc_assert (!INSN_P (insn));
3599 insn_info = df_insn_create_insn_record (insn);
3602 DF_INSN_INFO_LUID (insn_info) = luid;
3603 if (INSN_P (insn))
3604 luid++;
3609 /* Collect all artificial refs at the block level for BB and add them
3610 to COLLECTION_REC. */
3612 static void
3613 df_bb_refs_collect (struct df_collection_rec *collection_rec, basic_block bb)
3615 VEC_truncate (df_ref, collection_rec->def_vec, 0);
3616 VEC_truncate (df_ref, collection_rec->use_vec, 0);
3617 VEC_truncate (df_ref, collection_rec->eq_use_vec, 0);
3618 VEC_truncate (df_mw_hardreg_ptr, collection_rec->mw_vec, 0);
3620 if (bb->index == ENTRY_BLOCK)
3622 df_entry_block_defs_collect (collection_rec, df->entry_block_defs);
3623 return;
3625 else if (bb->index == EXIT_BLOCK)
3627 df_exit_block_uses_collect (collection_rec, df->exit_block_uses);
3628 return;
3631 #ifdef EH_RETURN_DATA_REGNO
3632 if (bb_has_eh_pred (bb))
3634 unsigned int i;
3635 /* Mark the registers that will contain data for the handler. */
3636 for (i = 0; ; ++i)
3638 unsigned regno = EH_RETURN_DATA_REGNO (i);
3639 if (regno == INVALID_REGNUM)
3640 break;
3641 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3642 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP, -1, -1,
3643 VOIDmode);
3646 #endif
3648 /* Add the hard_frame_pointer if this block is the target of a
3649 non-local goto. */
3650 if (bb->flags & BB_NON_LOCAL_GOTO_TARGET)
3651 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL,
3652 bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP, -1, -1, VOIDmode);
3654 /* Add the artificial uses. */
3655 if (bb->index >= NUM_FIXED_BLOCKS)
3657 bitmap_iterator bi;
3658 unsigned int regno;
3659 bitmap au = bb_has_eh_pred (bb)
3660 ? &df->eh_block_artificial_uses
3661 : &df->regular_block_artificial_uses;
3663 EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi)
3665 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
3666 bb, NULL, DF_REF_REG_USE, 0, -1, -1, VOIDmode);
3670 df_canonize_collection_rec (collection_rec);
3674 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3676 void
3677 df_bb_refs_record (int bb_index, bool scan_insns)
3679 basic_block bb = BASIC_BLOCK (bb_index);
3680 rtx insn;
3681 int luid = 0;
3682 struct df_collection_rec collection_rec;
3684 if (!df)
3685 return;
3687 df_grow_bb_info (df_scan);
3688 collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
3689 collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
3690 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
3691 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
3693 if (scan_insns)
3694 /* Scan the block an insn at a time from beginning to end. */
3695 FOR_BB_INSNS (bb, insn)
3697 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3698 gcc_assert (!insn_info);
3700 insn_info = df_insn_create_insn_record (insn);
3701 if (INSN_P (insn))
3703 /* Record refs within INSN. */
3704 DF_INSN_INFO_LUID (insn_info) = luid++;
3705 df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn));
3706 df_refs_add_to_chains (&collection_rec, bb, insn);
3708 DF_INSN_INFO_LUID (insn_info) = luid;
3711 /* Other block level artificial refs */
3712 df_bb_refs_collect (&collection_rec, bb);
3713 df_refs_add_to_chains (&collection_rec, bb, NULL);
3715 VEC_free (df_ref, stack, collection_rec.def_vec);
3716 VEC_free (df_ref, stack, collection_rec.use_vec);
3717 VEC_free (df_ref, stack, collection_rec.eq_use_vec);
3718 VEC_free (df_mw_hardreg_ptr, stack, collection_rec.mw_vec);
3720 /* Now that the block has been processed, set the block as dirty so
3721 LR and LIVE will get it processed. */
3722 df_set_bb_dirty (bb);
3726 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3727 block. */
3729 static void
3730 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses)
3732 #ifdef EH_USES
3733 unsigned int i;
3734 #endif
3736 bitmap_clear (regular_block_artificial_uses);
3738 if (reload_completed)
3740 if (frame_pointer_needed)
3741 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3743 else
3744 /* Before reload, there are a few registers that must be forced
3745 live everywhere -- which might not already be the case for
3746 blocks within infinite loops. */
3748 /* Any reference to any pseudo before reload is a potential
3749 reference of the frame pointer. */
3750 bitmap_set_bit (regular_block_artificial_uses, FRAME_POINTER_REGNUM);
3752 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3753 bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3754 #endif
3756 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3757 /* Pseudos with argument area equivalences may require
3758 reloading via the argument pointer. */
3759 if (fixed_regs[ARG_POINTER_REGNUM])
3760 bitmap_set_bit (regular_block_artificial_uses, ARG_POINTER_REGNUM);
3761 #endif
3763 /* Any constant, or pseudo with constant equivalences, may
3764 require reloading from memory using the pic register. */
3765 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3766 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3767 bitmap_set_bit (regular_block_artificial_uses, PIC_OFFSET_TABLE_REGNUM);
3769 /* The all-important stack pointer must always be live. */
3770 bitmap_set_bit (regular_block_artificial_uses, STACK_POINTER_REGNUM);
3772 #ifdef EH_USES
3773 /* EH_USES registers are used:
3774 1) at all insns that might throw (calls or with -fnon-call-exceptions
3775 trapping insns)
3776 2) in all EH edges
3777 3) to support backtraces and/or debugging, anywhere between their
3778 initialization and where they the saved registers are restored
3779 from them, including the cases where we don't reach the epilogue
3780 (noreturn call or infinite loop). */
3781 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3782 if (EH_USES (i))
3783 bitmap_set_bit (regular_block_artificial_uses, i);
3784 #endif
3788 /* Get the artificial use set for an eh block. */
3790 static void
3791 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses)
3793 bitmap_clear (eh_block_artificial_uses);
3795 /* The following code (down thru the arg_pointer setting APPEARS
3796 to be necessary because there is nothing that actually
3797 describes what the exception handling code may actually need
3798 to keep alive. */
3799 if (reload_completed)
3801 if (frame_pointer_needed)
3803 bitmap_set_bit (eh_block_artificial_uses, FRAME_POINTER_REGNUM);
3804 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3805 bitmap_set_bit (eh_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
3806 #endif
3808 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3809 if (fixed_regs[ARG_POINTER_REGNUM])
3810 bitmap_set_bit (eh_block_artificial_uses, ARG_POINTER_REGNUM);
3811 #endif
3817 /*----------------------------------------------------------------------------
3818 Specialized hard register scanning functions.
3819 ----------------------------------------------------------------------------*/
3822 /* Mark a register in SET. Hard registers in large modes get all
3823 of their component registers set as well. */
3825 static void
3826 df_mark_reg (rtx reg, void *vset)
3828 bitmap set = (bitmap) vset;
3829 int regno = REGNO (reg);
3831 gcc_assert (GET_MODE (reg) != BLKmode);
3833 if (regno < FIRST_PSEUDO_REGISTER)
3835 int n = hard_regno_nregs[regno][GET_MODE (reg)];
3836 bitmap_set_range (set, regno, n);
3838 else
3839 bitmap_set_bit (set, regno);
3843 /* Set the bit for regs that are considered being defined at the entry. */
3845 static void
3846 df_get_entry_block_def_set (bitmap entry_block_defs)
3848 rtx r;
3849 int i;
3851 bitmap_clear (entry_block_defs);
3853 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3855 if (FUNCTION_ARG_REGNO_P (i))
3856 #ifdef INCOMING_REGNO
3857 bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
3858 #else
3859 bitmap_set_bit (entry_block_defs, i);
3860 #endif
3863 /* The always important stack pointer. */
3864 bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM);
3866 /* Once the prologue has been generated, all of these registers
3867 should just show up in the first regular block. */
3868 if (HAVE_prologue && epilogue_completed)
3870 /* Defs for the callee saved registers are inserted so that the
3871 pushes have some defining location. */
3872 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3873 if ((call_used_regs[i] == 0) && (df_regs_ever_live_p (i)))
3874 bitmap_set_bit (entry_block_defs, i);
3877 r = targetm.calls.struct_value_rtx (current_function_decl, true);
3878 if (r && REG_P (r))
3879 bitmap_set_bit (entry_block_defs, REGNO (r));
3881 /* If the function has an incoming STATIC_CHAIN, it has to show up
3882 in the entry def set. */
3883 r = targetm.calls.static_chain (current_function_decl, true);
3884 if (r && REG_P (r))
3885 bitmap_set_bit (entry_block_defs, REGNO (r));
3887 if ((!reload_completed) || frame_pointer_needed)
3889 /* Any reference to any pseudo before reload is a potential
3890 reference of the frame pointer. */
3891 bitmap_set_bit (entry_block_defs, FRAME_POINTER_REGNUM);
3892 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3893 /* If they are different, also mark the hard frame pointer as live. */
3894 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
3895 bitmap_set_bit (entry_block_defs, HARD_FRAME_POINTER_REGNUM);
3896 #endif
3899 /* These registers are live everywhere. */
3900 if (!reload_completed)
3902 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3903 /* Pseudos with argument area equivalences may require
3904 reloading via the argument pointer. */
3905 if (fixed_regs[ARG_POINTER_REGNUM])
3906 bitmap_set_bit (entry_block_defs, ARG_POINTER_REGNUM);
3907 #endif
3909 #ifdef PIC_OFFSET_TABLE_REGNUM
3910 /* Any constant, or pseudo with constant equivalences, may
3911 require reloading from memory using the pic register. */
3912 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3913 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
3914 bitmap_set_bit (entry_block_defs, PIC_OFFSET_TABLE_REGNUM);
3915 #endif
3918 #ifdef INCOMING_RETURN_ADDR_RTX
3919 if (REG_P (INCOMING_RETURN_ADDR_RTX))
3920 bitmap_set_bit (entry_block_defs, REGNO (INCOMING_RETURN_ADDR_RTX));
3921 #endif
3923 targetm.extra_live_on_entry (entry_block_defs);
3927 /* Return the (conservative) set of hard registers that are defined on
3928 entry to the function.
3929 It uses df->entry_block_defs to determine which register
3930 reference to include. */
3932 static void
3933 df_entry_block_defs_collect (struct df_collection_rec *collection_rec,
3934 bitmap entry_block_defs)
3936 unsigned int i;
3937 bitmap_iterator bi;
3939 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs, 0, i, bi)
3941 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
3942 ENTRY_BLOCK_PTR, NULL, DF_REF_REG_DEF, 0, -1, -1,
3943 VOIDmode);
3946 df_canonize_collection_rec (collection_rec);
3950 /* Record the (conservative) set of hard registers that are defined on
3951 entry to the function. */
3953 static void
3954 df_record_entry_block_defs (bitmap entry_block_defs)
3956 struct df_collection_rec collection_rec;
3957 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
3958 collection_rec.def_vec = VEC_alloc (df_ref, stack, FIRST_PSEUDO_REGISTER);
3959 df_entry_block_defs_collect (&collection_rec, entry_block_defs);
3961 /* Process bb_refs chain */
3962 df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (ENTRY_BLOCK), NULL);
3963 VEC_free (df_ref, stack, collection_rec.def_vec);
3967 /* Update the defs in the entry block. */
3969 void
3970 df_update_entry_block_defs (void)
3972 bitmap_head refs;
3973 bool changed = false;
3975 bitmap_initialize (&refs, &df_bitmap_obstack);
3976 df_get_entry_block_def_set (&refs);
3977 if (df->entry_block_defs)
3979 if (!bitmap_equal_p (df->entry_block_defs, &refs))
3981 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (ENTRY_BLOCK);
3982 df_ref_chain_delete_du_chain (bb_info->artificial_defs);
3983 df_ref_chain_delete (bb_info->artificial_defs);
3984 bb_info->artificial_defs = NULL;
3985 changed = true;
3988 else
3990 struct df_scan_problem_data *problem_data
3991 = (struct df_scan_problem_data *) df_scan->problem_data;
3992 gcc_unreachable ();
3993 df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
3994 changed = true;
3997 if (changed)
3999 df_record_entry_block_defs (&refs);
4000 bitmap_copy (df->entry_block_defs, &refs);
4001 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
4003 bitmap_clear (&refs);
4007 /* Set the bit for regs that are considered being used at the exit. */
4009 static void
4010 df_get_exit_block_use_set (bitmap exit_block_uses)
4012 unsigned int i;
4014 bitmap_clear (exit_block_uses);
4016 /* Stack pointer is always live at the exit. */
4017 bitmap_set_bit (exit_block_uses, STACK_POINTER_REGNUM);
4019 /* Mark the frame pointer if needed at the end of the function.
4020 If we end up eliminating it, it will be removed from the live
4021 list of each basic block by reload. */
4023 if ((!reload_completed) || frame_pointer_needed)
4025 bitmap_set_bit (exit_block_uses, FRAME_POINTER_REGNUM);
4026 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4027 /* If they are different, also mark the hard frame pointer as live. */
4028 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
4029 bitmap_set_bit (exit_block_uses, HARD_FRAME_POINTER_REGNUM);
4030 #endif
4033 /* Many architectures have a GP register even without flag_pic.
4034 Assume the pic register is not in use, or will be handled by
4035 other means, if it is not fixed. */
4036 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
4037 && (unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
4038 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
4039 bitmap_set_bit (exit_block_uses, PIC_OFFSET_TABLE_REGNUM);
4041 /* Mark all global registers, and all registers used by the
4042 epilogue as being live at the end of the function since they
4043 may be referenced by our caller. */
4044 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4045 if (global_regs[i] || EPILOGUE_USES (i))
4046 bitmap_set_bit (exit_block_uses, i);
4048 if (HAVE_epilogue && epilogue_completed)
4050 /* Mark all call-saved registers that we actually used. */
4051 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4052 if (df_regs_ever_live_p (i) && !LOCAL_REGNO (i)
4053 && !TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
4054 bitmap_set_bit (exit_block_uses, i);
4057 #ifdef EH_RETURN_DATA_REGNO
4058 /* Mark the registers that will contain data for the handler. */
4059 if (reload_completed && crtl->calls_eh_return)
4060 for (i = 0; ; ++i)
4062 unsigned regno = EH_RETURN_DATA_REGNO (i);
4063 if (regno == INVALID_REGNUM)
4064 break;
4065 bitmap_set_bit (exit_block_uses, regno);
4067 #endif
4069 #ifdef EH_RETURN_STACKADJ_RTX
4070 if ((!HAVE_epilogue || ! epilogue_completed)
4071 && crtl->calls_eh_return)
4073 rtx tmp = EH_RETURN_STACKADJ_RTX;
4074 if (tmp && REG_P (tmp))
4075 df_mark_reg (tmp, exit_block_uses);
4077 #endif
4079 #ifdef EH_RETURN_HANDLER_RTX
4080 if ((!HAVE_epilogue || ! epilogue_completed)
4081 && crtl->calls_eh_return)
4083 rtx tmp = EH_RETURN_HANDLER_RTX;
4084 if (tmp && REG_P (tmp))
4085 df_mark_reg (tmp, exit_block_uses);
4087 #endif
4089 /* Mark function return value. */
4090 diddle_return_value (df_mark_reg, (void*) exit_block_uses);
4094 /* Return the refs of hard registers that are used in the exit block.
4095 It uses df->exit_block_uses to determine register to include. */
4097 static void
4098 df_exit_block_uses_collect (struct df_collection_rec *collection_rec, bitmap exit_block_uses)
4100 unsigned int i;
4101 bitmap_iterator bi;
4103 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses, 0, i, bi)
4104 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
4105 EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0, -1, -1, VOIDmode);
4107 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4108 /* It is deliberate that this is not put in the exit block uses but
4109 I do not know why. */
4110 if (reload_completed
4111 && !bitmap_bit_p (exit_block_uses, ARG_POINTER_REGNUM)
4112 && bb_has_eh_pred (EXIT_BLOCK_PTR)
4113 && fixed_regs[ARG_POINTER_REGNUM])
4114 df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[ARG_POINTER_REGNUM], NULL,
4115 EXIT_BLOCK_PTR, NULL, DF_REF_REG_USE, 0, -1, -1, VOIDmode);
4116 #endif
4118 df_canonize_collection_rec (collection_rec);
4122 /* Record the set of hard registers that are used in the exit block.
4123 It uses df->exit_block_uses to determine which bit to include. */
4125 static void
4126 df_record_exit_block_uses (bitmap exit_block_uses)
4128 struct df_collection_rec collection_rec;
4129 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
4130 collection_rec.use_vec = VEC_alloc (df_ref, stack, FIRST_PSEUDO_REGISTER);
4132 df_exit_block_uses_collect (&collection_rec, exit_block_uses);
4134 /* Process bb_refs chain */
4135 df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (EXIT_BLOCK), NULL);
4136 VEC_free (df_ref, stack, collection_rec.use_vec);
4140 /* Update the uses in the exit block. */
4142 void
4143 df_update_exit_block_uses (void)
4145 bitmap_head refs;
4146 bool changed = false;
4148 bitmap_initialize (&refs, &df_bitmap_obstack);
4149 df_get_exit_block_use_set (&refs);
4150 if (df->exit_block_uses)
4152 if (!bitmap_equal_p (df->exit_block_uses, &refs))
4154 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (EXIT_BLOCK);
4155 df_ref_chain_delete_du_chain (bb_info->artificial_uses);
4156 df_ref_chain_delete (bb_info->artificial_uses);
4157 bb_info->artificial_uses = NULL;
4158 changed = true;
4161 else
4163 struct df_scan_problem_data *problem_data
4164 = (struct df_scan_problem_data *) df_scan->problem_data;
4165 gcc_unreachable ();
4166 df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
4167 changed = true;
4170 if (changed)
4172 df_record_exit_block_uses (&refs);
4173 bitmap_copy (df->exit_block_uses,& refs);
4174 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
4176 bitmap_clear (&refs);
4179 static bool initialized = false;
4182 /* Initialize some platform specific structures. */
4184 void
4185 df_hard_reg_init (void)
4187 #ifdef ELIMINABLE_REGS
4188 int i;
4189 static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
4190 #endif
4191 if (initialized)
4192 return;
4194 /* Record which registers will be eliminated. We use this in
4195 mark_used_regs. */
4196 CLEAR_HARD_REG_SET (elim_reg_set);
4198 #ifdef ELIMINABLE_REGS
4199 for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
4200 SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
4201 #else
4202 SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
4203 #endif
4205 initialized = true;
4209 /* Recompute the parts of scanning that are based on regs_ever_live
4210 because something changed in that array. */
4212 void
4213 df_update_entry_exit_and_calls (void)
4215 basic_block bb;
4217 df_update_entry_block_defs ();
4218 df_update_exit_block_uses ();
4220 /* The call insns need to be rescanned because there may be changes
4221 in the set of registers clobbered across the call. */
4222 FOR_EACH_BB (bb)
4224 rtx insn;
4225 FOR_BB_INSNS (bb, insn)
4227 if (INSN_P (insn) && CALL_P (insn))
4228 df_insn_rescan (insn);
4234 /* Return true if hard REG is actually used in the some instruction.
4235 There are a fair number of conditions that affect the setting of
4236 this array. See the comment in df.h for df->hard_regs_live_count
4237 for the conditions that this array is set. */
4239 bool
4240 df_hard_reg_used_p (unsigned int reg)
4242 return df->hard_regs_live_count[reg] != 0;
4246 /* A count of the number of times REG is actually used in the some
4247 instruction. There are a fair number of conditions that affect the
4248 setting of this array. See the comment in df.h for
4249 df->hard_regs_live_count for the conditions that this array is
4250 set. */
4253 unsigned int
4254 df_hard_reg_used_count (unsigned int reg)
4256 return df->hard_regs_live_count[reg];
4260 /* Get the value of regs_ever_live[REGNO]. */
4262 bool
4263 df_regs_ever_live_p (unsigned int regno)
4265 return regs_ever_live[regno];
4269 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
4270 to change, schedule that change for the next update. */
4272 void
4273 df_set_regs_ever_live (unsigned int regno, bool value)
4275 if (regs_ever_live[regno] == value)
4276 return;
4278 regs_ever_live[regno] = value;
4279 if (df)
4280 df->redo_entry_and_exit = true;
4284 /* Compute "regs_ever_live" information from the underlying df
4285 information. Set the vector to all false if RESET. */
4287 void
4288 df_compute_regs_ever_live (bool reset)
4290 unsigned int i;
4291 bool changed = df->redo_entry_and_exit;
4293 if (reset)
4294 memset (regs_ever_live, 0, sizeof (regs_ever_live));
4296 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4297 if ((!regs_ever_live[i]) && df_hard_reg_used_p (i))
4299 regs_ever_live[i] = true;
4300 changed = true;
4302 if (changed)
4303 df_update_entry_exit_and_calls ();
4304 df->redo_entry_and_exit = false;
4308 /*----------------------------------------------------------------------------
4309 Dataflow ref information verification functions.
4311 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4312 df_reg_chain_verify_unmarked (refs)
4313 df_refs_verify (VEC(stack,df_ref)*, ref*, bool)
4314 df_mws_verify (mw*, mw*, bool)
4315 df_insn_refs_verify (collection_rec, bb, insn, bool)
4316 df_bb_refs_verify (bb, refs, bool)
4317 df_bb_verify (bb)
4318 df_exit_block_bitmap_verify (bool)
4319 df_entry_block_bitmap_verify (bool)
4320 df_scan_verify ()
4321 ----------------------------------------------------------------------------*/
4324 /* Mark all refs in the reg chain. Verify that all of the registers
4325 are in the correct chain. */
4327 static unsigned int
4328 df_reg_chain_mark (df_ref refs, unsigned int regno,
4329 bool is_def, bool is_eq_use)
4331 unsigned int count = 0;
4332 df_ref ref;
4333 for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4335 gcc_assert (!DF_REF_IS_REG_MARKED (ref));
4337 /* If there are no def-use or use-def chains, make sure that all
4338 of the chains are clear. */
4339 if (!df_chain)
4340 gcc_assert (!DF_REF_CHAIN (ref));
4342 /* Check to make sure the ref is in the correct chain. */
4343 gcc_assert (DF_REF_REGNO (ref) == regno);
4344 if (is_def)
4345 gcc_assert (DF_REF_REG_DEF_P (ref));
4346 else
4347 gcc_assert (!DF_REF_REG_DEF_P (ref));
4349 if (is_eq_use)
4350 gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE));
4351 else
4352 gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) == 0);
4354 if (DF_REF_NEXT_REG (ref))
4355 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref)) == ref);
4356 count++;
4357 DF_REF_REG_MARK (ref);
4359 return count;
4363 /* Verify that all of the registers in the chain are unmarked. */
4365 static void
4366 df_reg_chain_verify_unmarked (df_ref refs)
4368 df_ref ref;
4369 for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
4370 gcc_assert (!DF_REF_IS_REG_MARKED (ref));
4374 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4376 static bool
4377 df_refs_verify (VEC(df_ref,stack) *new_rec, df_ref *old_rec,
4378 bool abort_if_fail)
4380 unsigned int ix;
4381 df_ref new_ref;
4383 FOR_EACH_VEC_ELT (df_ref, new_rec, ix, new_ref)
4385 if (*old_rec == NULL || !df_ref_equal_p (new_ref, *old_rec))
4387 if (abort_if_fail)
4388 gcc_assert (0);
4389 else
4390 return false;
4393 /* Abort if fail is called from the function level verifier. If
4394 that is the context, mark this reg as being seem. */
4395 if (abort_if_fail)
4397 gcc_assert (DF_REF_IS_REG_MARKED (*old_rec));
4398 DF_REF_REG_UNMARK (*old_rec);
4401 old_rec++;
4404 if (abort_if_fail)
4405 gcc_assert (*old_rec == NULL);
4406 else
4407 return *old_rec == NULL;
4408 return false;
4412 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4414 static bool
4415 df_mws_verify (VEC(df_mw_hardreg_ptr,stack) *new_rec,
4416 struct df_mw_hardreg **old_rec,
4417 bool abort_if_fail)
4419 unsigned int ix;
4420 struct df_mw_hardreg *new_reg;
4422 FOR_EACH_VEC_ELT (df_mw_hardreg_ptr, new_rec, ix, new_reg)
4424 if (*old_rec == NULL || !df_mw_equal_p (new_reg, *old_rec))
4426 if (abort_if_fail)
4427 gcc_assert (0);
4428 else
4429 return false;
4431 old_rec++;
4434 if (abort_if_fail)
4435 gcc_assert (*old_rec == NULL);
4436 else
4437 return *old_rec == NULL;
4438 return false;
4442 /* Return true if the existing insn refs information is complete and
4443 correct. Otherwise (i.e. if there's any missing or extra refs),
4444 return the correct df_ref chain in REFS_RETURN.
4446 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4447 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4448 verification mode instead of the whole function, so unmark
4449 everything.
4451 If ABORT_IF_FAIL is set, this function never returns false. */
4453 static bool
4454 df_insn_refs_verify (struct df_collection_rec *collection_rec,
4455 basic_block bb,
4456 rtx insn,
4457 bool abort_if_fail)
4459 bool ret1, ret2, ret3, ret4;
4460 unsigned int uid = INSN_UID (insn);
4461 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
4463 df_insn_refs_collect (collection_rec, bb, insn_info);
4465 if (!DF_INSN_UID_DEFS (uid))
4467 /* The insn_rec was created but it was never filled out. */
4468 if (abort_if_fail)
4469 gcc_assert (0);
4470 else
4471 return false;
4474 /* Unfortunately we cannot opt out early if one of these is not
4475 right because the marks will not get cleared. */
4476 ret1 = df_refs_verify (collection_rec->def_vec, DF_INSN_UID_DEFS (uid),
4477 abort_if_fail);
4478 ret2 = df_refs_verify (collection_rec->use_vec, DF_INSN_UID_USES (uid),
4479 abort_if_fail);
4480 ret3 = df_refs_verify (collection_rec->eq_use_vec, DF_INSN_UID_EQ_USES (uid),
4481 abort_if_fail);
4482 ret4 = df_mws_verify (collection_rec->mw_vec, DF_INSN_UID_MWS (uid),
4483 abort_if_fail);
4484 return (ret1 && ret2 && ret3 && ret4);
4488 /* Return true if all refs in the basic block are correct and complete.
4489 Due to df_ref_chain_verify, it will cause all refs
4490 that are verified to have DF_REF_MARK bit set. */
4492 static bool
4493 df_bb_verify (basic_block bb)
4495 rtx insn;
4496 struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
4497 struct df_collection_rec collection_rec;
4499 memset (&collection_rec, 0, sizeof (struct df_collection_rec));
4500 collection_rec.def_vec = VEC_alloc (df_ref, stack, 128);
4501 collection_rec.use_vec = VEC_alloc (df_ref, stack, 32);
4502 collection_rec.eq_use_vec = VEC_alloc (df_ref, stack, 32);
4503 collection_rec.mw_vec = VEC_alloc (df_mw_hardreg_ptr, stack, 32);
4505 gcc_assert (bb_info);
4507 /* Scan the block, one insn at a time, from beginning to end. */
4508 FOR_BB_INSNS_REVERSE (bb, insn)
4510 if (!INSN_P (insn))
4511 continue;
4512 df_insn_refs_verify (&collection_rec, bb, insn, true);
4513 df_free_collection_rec (&collection_rec);
4516 /* Do the artificial defs and uses. */
4517 df_bb_refs_collect (&collection_rec, bb);
4518 df_refs_verify (collection_rec.def_vec, df_get_artificial_defs (bb->index), true);
4519 df_refs_verify (collection_rec.use_vec, df_get_artificial_uses (bb->index), true);
4520 df_free_collection_rec (&collection_rec);
4522 return true;
4526 /* Returns true if the entry block has correct and complete df_ref set.
4527 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4529 static bool
4530 df_entry_block_bitmap_verify (bool abort_if_fail)
4532 bitmap_head entry_block_defs;
4533 bool is_eq;
4535 bitmap_initialize (&entry_block_defs, &df_bitmap_obstack);
4536 df_get_entry_block_def_set (&entry_block_defs);
4538 is_eq = bitmap_equal_p (&entry_block_defs, df->entry_block_defs);
4540 if (!is_eq && abort_if_fail)
4542 print_current_pass (stderr);
4543 fprintf (stderr, "entry_block_defs = ");
4544 df_print_regset (stderr, &entry_block_defs);
4545 fprintf (stderr, "df->entry_block_defs = ");
4546 df_print_regset (stderr, df->entry_block_defs);
4547 gcc_assert (0);
4550 bitmap_clear (&entry_block_defs);
4552 return is_eq;
4556 /* Returns true if the exit block has correct and complete df_ref set.
4557 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4559 static bool
4560 df_exit_block_bitmap_verify (bool abort_if_fail)
4562 bitmap_head exit_block_uses;
4563 bool is_eq;
4565 bitmap_initialize (&exit_block_uses, &df_bitmap_obstack);
4566 df_get_exit_block_use_set (&exit_block_uses);
4568 is_eq = bitmap_equal_p (&exit_block_uses, df->exit_block_uses);
4570 if (!is_eq && abort_if_fail)
4572 print_current_pass (stderr);
4573 fprintf (stderr, "exit_block_uses = ");
4574 df_print_regset (stderr, &exit_block_uses);
4575 fprintf (stderr, "df->exit_block_uses = ");
4576 df_print_regset (stderr, df->exit_block_uses);
4577 gcc_assert (0);
4580 bitmap_clear (&exit_block_uses);
4582 return is_eq;
4586 /* Return true if df_ref information for all insns in all blocks are
4587 correct and complete. */
4589 void
4590 df_scan_verify (void)
4592 unsigned int i;
4593 basic_block bb;
4594 bitmap_head regular_block_artificial_uses;
4595 bitmap_head eh_block_artificial_uses;
4597 if (!df)
4598 return;
4600 /* Verification is a 4 step process. */
4602 /* (1) All of the refs are marked by going thru the reg chains. */
4603 for (i = 0; i < DF_REG_SIZE (df); i++)
4605 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false)
4606 == DF_REG_DEF_COUNT(i));
4607 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i), i, false, false)
4608 == DF_REG_USE_COUNT(i));
4609 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i), i, false, true)
4610 == DF_REG_EQ_USE_COUNT(i));
4613 /* (2) There are various bitmaps whose value may change over the
4614 course of the compilation. This step recomputes them to make
4615 sure that they have not slipped out of date. */
4616 bitmap_initialize (&regular_block_artificial_uses, &df_bitmap_obstack);
4617 bitmap_initialize (&eh_block_artificial_uses, &df_bitmap_obstack);
4619 df_get_regular_block_artificial_uses (&regular_block_artificial_uses);
4620 df_get_eh_block_artificial_uses (&eh_block_artificial_uses);
4622 bitmap_ior_into (&eh_block_artificial_uses,
4623 &regular_block_artificial_uses);
4625 /* Check artificial_uses bitmaps didn't change. */
4626 gcc_assert (bitmap_equal_p (&regular_block_artificial_uses,
4627 &df->regular_block_artificial_uses));
4628 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses,
4629 &df->eh_block_artificial_uses));
4631 bitmap_clear (&regular_block_artificial_uses);
4632 bitmap_clear (&eh_block_artificial_uses);
4634 /* Verify entry block and exit block. These only verify the bitmaps,
4635 the refs are verified in df_bb_verify. */
4636 df_entry_block_bitmap_verify (true);
4637 df_exit_block_bitmap_verify (true);
4639 /* (3) All of the insns in all of the blocks are traversed and the
4640 marks are cleared both in the artificial refs attached to the
4641 blocks and the real refs inside the insns. It is a failure to
4642 clear a mark that has not been set as this means that the ref in
4643 the block or insn was not in the reg chain. */
4645 FOR_ALL_BB (bb)
4646 df_bb_verify (bb);
4648 /* (4) See if all reg chains are traversed a second time. This time
4649 a check is made that the marks are clear. A set mark would be a
4650 from a reg that is not in any insn or basic block. */
4652 for (i = 0; i < DF_REG_SIZE (df); i++)
4654 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i));
4655 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i));
4656 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i));