1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999-2013 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
30 #include "insn-config.h"
34 #include "alloc-pool.h"
36 #include "hard-reg-set.h"
37 #include "basic-block.h"
43 #include "target-def.h"
45 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
48 typedef struct df_mw_hardreg
*df_mw_hardreg_ptr
;
52 #define HAVE_epilogue 0
55 #define HAVE_prologue 0
57 #ifndef HAVE_sibcall_epilogue
58 #define HAVE_sibcall_epilogue 0
62 #define EPILOGUE_USES(REGNO) 0
65 /* The following two macros free the vecs that hold either the refs or
66 the mw refs. They are a little tricky because the vec has 0
67 elements is special and is not to be freed. */
68 #define df_scan_free_ref_vec(V) \
74 #define df_scan_free_mws_vec(V) \
80 /* The set of hard registers in eliminables[i].from. */
82 static HARD_REG_SET elim_reg_set
;
84 /* Initialize ur_in and ur_out as if all hard registers were partially
87 struct df_collection_rec
89 vec
<df_ref
, va_stack
> def_vec
;
90 vec
<df_ref
, va_stack
> use_vec
;
91 vec
<df_ref
, va_stack
> eq_use_vec
;
92 vec
<df_mw_hardreg_ptr
, va_stack
> mw_vec
;
95 static df_ref df_null_ref_rec
[1];
96 static struct df_mw_hardreg
* df_null_mw_rec
[1];
98 static void df_ref_record (enum df_ref_class
, struct df_collection_rec
*,
100 basic_block
, struct df_insn_info
*,
101 enum df_ref_type
, int ref_flags
);
102 static void df_def_record_1 (struct df_collection_rec
*, rtx
*,
103 basic_block
, struct df_insn_info
*,
105 static void df_defs_record (struct df_collection_rec
*, rtx
,
106 basic_block
, struct df_insn_info
*,
108 static void df_uses_record (struct df_collection_rec
*,
109 rtx
*, enum df_ref_type
,
110 basic_block
, struct df_insn_info
*,
113 static void df_install_ref_incremental (df_ref
);
114 static df_ref
df_ref_create_structure (enum df_ref_class
,
115 struct df_collection_rec
*, rtx
, rtx
*,
116 basic_block
, struct df_insn_info
*,
117 enum df_ref_type
, int ref_flags
);
118 static void df_insn_refs_collect (struct df_collection_rec
*,
119 basic_block
, struct df_insn_info
*);
120 static void df_canonize_collection_rec (struct df_collection_rec
*);
122 static void df_get_regular_block_artificial_uses (bitmap
);
123 static void df_get_eh_block_artificial_uses (bitmap
);
125 static void df_record_entry_block_defs (bitmap
);
126 static void df_record_exit_block_uses (bitmap
);
127 static void df_get_exit_block_use_set (bitmap
);
128 static void df_get_entry_block_def_set (bitmap
);
129 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
130 static void df_ref_chain_delete_du_chain (df_ref
*);
131 static void df_ref_chain_delete (df_ref
*);
133 static void df_refs_add_to_chains (struct df_collection_rec
*,
136 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
, rtx
, bool);
137 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
138 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
139 static void df_install_ref (df_ref
, struct df_reg_info
*,
140 struct df_ref_info
*, bool);
142 static int df_ref_compare (const void *, const void *);
143 static int df_mw_compare (const void *, const void *);
145 static void df_insn_info_delete (unsigned int);
147 /* Indexed by hardware reg number, is true if that register is ever
148 used in the current function.
150 In df-scan.c, this is set up to record the hard regs used
151 explicitly. Reload adds in the hard regs used for holding pseudo
152 regs. Final uses it to generate the code in the function prologue
153 and epilogue to save and restore registers as needed. */
155 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
157 /*----------------------------------------------------------------------------
158 SCANNING DATAFLOW PROBLEM
160 There are several ways in which scanning looks just like the other
161 dataflow problems. It shares the all the mechanisms for local info
162 as well as basic block info. Where it differs is when and how often
163 it gets run. It also has no need for the iterative solver.
164 ----------------------------------------------------------------------------*/
166 /* Problem data for the scanning dataflow function. */
167 struct df_scan_problem_data
169 alloc_pool ref_base_pool
;
170 alloc_pool ref_artificial_pool
;
171 alloc_pool ref_regular_pool
;
172 alloc_pool insn_pool
;
174 alloc_pool mw_reg_pool
;
175 bitmap_obstack reg_bitmaps
;
176 bitmap_obstack insn_bitmaps
;
179 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
182 /* Internal function to shut down the scanning problem. */
184 df_scan_free_internal (void)
186 struct df_scan_problem_data
*problem_data
187 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
191 /* The vectors that hold the refs are not pool allocated because
192 they come in many sizes. This makes them impossible to delete
194 for (i
= 0; i
< DF_INSN_SIZE(); i
++)
196 struct df_insn_info
*insn_info
= DF_INSN_UID_GET(i
);
197 /* Skip the insns that have no insn_info or have been
201 df_scan_free_ref_vec (insn_info
->defs
);
202 df_scan_free_ref_vec (insn_info
->uses
);
203 df_scan_free_ref_vec (insn_info
->eq_uses
);
204 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
210 unsigned int bb_index
= bb
->index
;
211 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
214 df_scan_free_ref_vec (bb_info
->artificial_defs
);
215 df_scan_free_ref_vec (bb_info
->artificial_uses
);
219 free (df
->def_info
.refs
);
220 free (df
->def_info
.begin
);
221 free (df
->def_info
.count
);
222 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
224 free (df
->use_info
.refs
);
225 free (df
->use_info
.begin
);
226 free (df
->use_info
.count
);
227 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
233 free (df
->eq_use_regs
);
234 df
->eq_use_regs
= NULL
;
242 free (df_scan
->block_info
);
243 df_scan
->block_info
= NULL
;
244 df_scan
->block_info_size
= 0;
246 bitmap_clear (&df
->hardware_regs_used
);
247 bitmap_clear (&df
->regular_block_artificial_uses
);
248 bitmap_clear (&df
->eh_block_artificial_uses
);
249 BITMAP_FREE (df
->entry_block_defs
);
250 BITMAP_FREE (df
->exit_block_uses
);
251 bitmap_clear (&df
->insns_to_delete
);
252 bitmap_clear (&df
->insns_to_rescan
);
253 bitmap_clear (&df
->insns_to_notes_rescan
);
255 free_alloc_pool (problem_data
->ref_base_pool
);
256 free_alloc_pool (problem_data
->ref_artificial_pool
);
257 free_alloc_pool (problem_data
->ref_regular_pool
);
258 free_alloc_pool (problem_data
->insn_pool
);
259 free_alloc_pool (problem_data
->reg_pool
);
260 free_alloc_pool (problem_data
->mw_reg_pool
);
261 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
262 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
263 free (df_scan
->problem_data
);
267 /* Free basic block info. */
270 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
272 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
273 unsigned int bb_index
= bb
->index
;
275 /* See if bb_info is initialized. */
276 if (bb_info
->artificial_defs
)
279 FOR_BB_INSNS (bb
, insn
)
282 df_insn_info_delete (INSN_UID (insn
));
285 if (bb_index
< df_scan
->block_info_size
)
286 bb_info
= df_scan_get_bb_info (bb_index
);
288 /* Get rid of any artificial uses or defs. */
289 if (bb_info
->artificial_defs
)
291 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
292 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
293 df_ref_chain_delete (bb_info
->artificial_defs
);
294 df_ref_chain_delete (bb_info
->artificial_uses
);
295 bb_info
->artificial_defs
= NULL
;
296 bb_info
->artificial_uses
= NULL
;
302 /* Allocate the problem data for the scanning problem. This should be
303 called when the problem is created or when the entire function is to
306 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
308 struct df_scan_problem_data
*problem_data
;
309 unsigned int insn_num
= get_max_uid () + 1;
310 unsigned int block_size
= 512;
313 /* Given the number of pools, this is really faster than tearing
315 if (df_scan
->problem_data
)
316 df_scan_free_internal ();
318 problem_data
= XNEW (struct df_scan_problem_data
);
319 df_scan
->problem_data
= problem_data
;
320 df_scan
->computed
= true;
322 problem_data
->ref_base_pool
323 = create_alloc_pool ("df_scan ref base",
324 sizeof (struct df_base_ref
), block_size
);
325 problem_data
->ref_artificial_pool
326 = create_alloc_pool ("df_scan ref artificial",
327 sizeof (struct df_artificial_ref
), block_size
);
328 problem_data
->ref_regular_pool
329 = create_alloc_pool ("df_scan ref regular",
330 sizeof (struct df_regular_ref
), block_size
);
331 problem_data
->insn_pool
332 = create_alloc_pool ("df_scan insn",
333 sizeof (struct df_insn_info
), block_size
);
334 problem_data
->reg_pool
335 = create_alloc_pool ("df_scan reg",
336 sizeof (struct df_reg_info
), block_size
);
337 problem_data
->mw_reg_pool
338 = create_alloc_pool ("df_scan mw_reg",
339 sizeof (struct df_mw_hardreg
), block_size
/ 16);
341 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
342 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
344 insn_num
+= insn_num
/ 4;
347 df_grow_insn_info ();
348 df_grow_bb_info (df_scan
);
352 unsigned int bb_index
= bb
->index
;
353 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
354 bb_info
->artificial_defs
= NULL
;
355 bb_info
->artificial_uses
= NULL
;
358 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
359 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
360 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
361 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
362 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
363 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
364 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
365 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
366 df_scan
->optional_p
= false;
370 /* Free all of the data associated with the scan problem. */
375 if (df_scan
->problem_data
)
376 df_scan_free_internal ();
378 if (df
->blocks_to_analyze
)
380 BITMAP_FREE (df
->blocks_to_analyze
);
381 df
->blocks_to_analyze
= NULL
;
387 /* Dump the preamble for DF_SCAN dump. */
389 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
400 fprintf (file
, ";; invalidated by call \t");
401 df_print_regset (file
, regs_invalidated_by_call_regset
);
402 fprintf (file
, ";; hardware regs used \t");
403 df_print_regset (file
, &df
->hardware_regs_used
);
404 fprintf (file
, ";; regular block artificial uses \t");
405 df_print_regset (file
, &df
->regular_block_artificial_uses
);
406 fprintf (file
, ";; eh block artificial uses \t");
407 df_print_regset (file
, &df
->eh_block_artificial_uses
);
408 fprintf (file
, ";; entry block defs \t");
409 df_print_regset (file
, df
->entry_block_defs
);
410 fprintf (file
, ";; exit block uses \t");
411 df_print_regset (file
, df
->exit_block_uses
);
412 fprintf (file
, ";; regs ever live \t");
413 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
414 if (df_regs_ever_live_p (i
))
415 fprintf (file
, " %d[%s]", i
, reg_names
[i
]);
416 fprintf (file
, "\n;; ref usage \t");
418 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
419 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
421 const char * sep
= "";
423 fprintf (file
, "r%d={", i
);
424 if (DF_REG_DEF_COUNT (i
))
426 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
428 dcount
+= DF_REG_DEF_COUNT (i
);
430 if (DF_REG_USE_COUNT (i
))
432 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
434 ucount
+= DF_REG_USE_COUNT (i
);
436 if (DF_REG_EQ_USE_COUNT (i
))
438 fprintf (file
, "%s%de", sep
, DF_REG_EQ_USE_COUNT (i
));
439 ecount
+= DF_REG_EQ_USE_COUNT (i
);
441 fprintf (file
, "} ");
445 FOR_BB_INSNS (bb
, insn
)
454 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de}"
455 " in %d{%d regular + %d call} insns.\n",
456 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
,
457 icount
+ ccount
, icount
, ccount
);
460 /* Dump the bb_info for a given basic block. */
462 df_scan_start_block (basic_block bb
, FILE *file
)
464 struct df_scan_bb_info
*bb_info
465 = df_scan_get_bb_info (bb
->index
);
469 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
470 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
471 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
472 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
473 fprintf (file
, "\n");
478 FOR_BB_INSNS (bb
, insn
)
480 df_insn_debug (insn
, false, file
);
485 static struct df_problem problem_SCAN
=
487 DF_SCAN
, /* Problem id. */
488 DF_NONE
, /* Direction. */
489 df_scan_alloc
, /* Allocate the problem specific data. */
490 NULL
, /* Reset global information. */
491 df_scan_free_bb_info
, /* Free basic block info. */
492 NULL
, /* Local compute function. */
493 NULL
, /* Init the solution specific data. */
494 NULL
, /* Iterative solver. */
495 NULL
, /* Confluence operator 0. */
496 NULL
, /* Confluence operator n. */
497 NULL
, /* Transfer function. */
498 NULL
, /* Finalize function. */
499 df_scan_free
, /* Free all of the problem information. */
500 NULL
, /* Remove this problem from the stack of dataflow problems. */
501 df_scan_start_dump
, /* Debugging. */
502 df_scan_start_block
, /* Debugging start block. */
503 NULL
, /* Debugging end block. */
504 NULL
, /* Debugging start insn. */
505 NULL
, /* Debugging end insn. */
506 NULL
, /* Incremental solution verify start. */
507 NULL
, /* Incremental solution verify end. */
508 NULL
, /* Dependent problem. */
509 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
510 TV_DF_SCAN
, /* Timing variable. */
511 false /* Reset blocks on dropping out of blocks_to_analyze. */
515 /* Create a new DATAFLOW instance and add it to an existing instance
516 of DF. The returned structure is what is used to get at the
520 df_scan_add_problem (void)
522 df_add_problem (&problem_SCAN
);
526 /*----------------------------------------------------------------------------
527 Storage Allocation Utilities
528 ----------------------------------------------------------------------------*/
531 /* First, grow the reg_info information. If the current size is less than
532 the number of pseudos, grow to 25% more than the number of
535 Second, assure that all of the slots up to max_reg_num have been
536 filled with reg_info structures. */
539 df_grow_reg_info (void)
541 unsigned int max_reg
= max_reg_num ();
542 unsigned int new_size
= max_reg
;
543 struct df_scan_problem_data
*problem_data
544 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
547 if (df
->regs_size
< new_size
)
549 new_size
+= new_size
/ 4;
550 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
551 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
552 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
554 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
555 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
556 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
557 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
558 df
->regs_size
= new_size
;
561 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
563 struct df_reg_info
*reg_info
;
565 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
566 memset (reg_info
, 0, sizeof (struct df_reg_info
));
567 df
->def_regs
[i
] = reg_info
;
568 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
569 memset (reg_info
, 0, sizeof (struct df_reg_info
));
570 df
->use_regs
[i
] = reg_info
;
571 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
572 memset (reg_info
, 0, sizeof (struct df_reg_info
));
573 df
->eq_use_regs
[i
] = reg_info
;
574 df
->def_info
.begin
[i
] = 0;
575 df
->def_info
.count
[i
] = 0;
576 df
->use_info
.begin
[i
] = 0;
577 df
->use_info
.count
[i
] = 0;
580 df
->regs_inited
= max_reg
;
584 /* Grow the ref information. */
587 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
589 if (ref_info
->refs_size
< new_size
)
591 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
592 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
593 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
594 ref_info
->refs_size
= new_size
;
599 /* Check and grow the ref information if necessary. This routine
600 guarantees total_size + BITMAP_ADDEND amount of entries in refs
601 array. It updates ref_info->refs_size only and does not change
602 ref_info->total_size. */
605 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
606 unsigned bitmap_addend
)
608 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
610 int new_size
= ref_info
->total_size
+ bitmap_addend
;
611 new_size
+= ref_info
->total_size
/ 4;
612 df_grow_ref_info (ref_info
, new_size
);
617 /* Grow the ref information. If the current size is less than the
618 number of instructions, grow to 25% more than the number of
622 df_grow_insn_info (void)
624 unsigned int new_size
= get_max_uid () + 1;
625 if (DF_INSN_SIZE () < new_size
)
627 new_size
+= new_size
/ 4;
628 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
629 memset (df
->insns
+ df
->insns_size
, 0,
630 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
631 DF_INSN_SIZE () = new_size
;
638 /*----------------------------------------------------------------------------
639 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
640 ----------------------------------------------------------------------------*/
642 /* Rescan all of the block_to_analyze or all of the blocks in the
643 function if df_set_blocks if blocks_to_analyze is NULL; */
646 df_scan_blocks (void)
650 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
651 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
653 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
654 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
656 bitmap_ior_into (&df
->eh_block_artificial_uses
,
657 &df
->regular_block_artificial_uses
);
659 /* ENTRY and EXIT blocks have special defs/uses. */
660 df_get_entry_block_def_set (df
->entry_block_defs
);
661 df_record_entry_block_defs (df
->entry_block_defs
);
662 df_get_exit_block_use_set (df
->exit_block_uses
);
663 df_record_exit_block_uses (df
->exit_block_uses
);
664 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
665 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
670 unsigned int bb_index
= bb
->index
;
671 df_bb_refs_record (bb_index
, true);
675 /* Create new refs under address LOC within INSN. This function is
676 only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
677 depending on whether LOC is inside PATTERN (INSN) or a note. */
680 df_uses_create (rtx
*loc
, rtx insn
, int ref_flags
)
682 gcc_assert (!(ref_flags
& ~DF_REF_IN_NOTE
));
683 df_uses_record (NULL
, loc
, DF_REF_REG_USE
,
684 BLOCK_FOR_INSN (insn
),
685 DF_INSN_INFO_GET (insn
),
689 /* Create a new ref of type DF_REF_TYPE for register REG at address
690 LOC within INSN of BB. This function is only used externally. */
693 df_ref_create (rtx reg
, rtx
*loc
, rtx insn
,
695 enum df_ref_type ref_type
,
698 enum df_ref_class cl
;
702 /* You cannot hack artificial refs. */
710 return df_ref_create_structure (cl
, NULL
, reg
, loc
, bb
,
711 DF_INSN_INFO_GET (insn
),
712 ref_type
, ref_flags
);
716 df_install_ref_incremental (df_ref ref
)
718 struct df_reg_info
**reg_info
;
719 struct df_ref_info
*ref_info
;
721 df_ref
**ref_rec_ptr
;
722 unsigned int count
= 0;
725 rtx insn
= DF_REF_INSN (ref
);
726 basic_block bb
= BLOCK_FOR_INSN (insn
);
728 if (DF_REF_REG_DEF_P (ref
))
730 reg_info
= df
->def_regs
;
731 ref_info
= &df
->def_info
;
732 ref_rec_ptr
= &DF_INSN_DEFS (insn
);
733 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
735 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
737 reg_info
= df
->eq_use_regs
;
738 ref_info
= &df
->use_info
;
739 ref_rec_ptr
= &DF_INSN_EQ_USES (insn
);
740 switch (ref_info
->ref_order
)
742 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
743 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
744 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
748 add_to_table
= false;
754 reg_info
= df
->use_regs
;
755 ref_info
= &df
->use_info
;
756 ref_rec_ptr
= &DF_INSN_USES (insn
);
757 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
760 /* Do not add if ref is not in the right blocks. */
761 if (add_to_table
&& df
->analyze_subset
)
762 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
764 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
767 switch (ref_info
->ref_order
)
769 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
770 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
771 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
772 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
775 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
779 ref_rec
= *ref_rec_ptr
;
786 ref_rec
= *ref_rec_ptr
;
789 ref_rec
= XRESIZEVEC (df_ref
, ref_rec
, count
+2);
790 *ref_rec_ptr
= ref_rec
;
791 ref_rec
[count
] = ref
;
792 ref_rec
[count
+1] = NULL
;
793 qsort (ref_rec
, count
+ 1, sizeof (df_ref
), df_ref_compare
);
797 df_ref
*ref_rec
= XNEWVEC (df_ref
, 2);
800 *ref_rec_ptr
= ref_rec
;
806 fprintf (dump_file
, "adding ref ");
807 df_ref_debug (ref
, dump_file
);
810 /* By adding the ref directly, df_insn_rescan my not find any
811 differences even though the block will have changed. So we need
812 to mark the block dirty ourselves. */
813 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
814 df_set_bb_dirty (bb
);
819 /*----------------------------------------------------------------------------
820 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
821 ----------------------------------------------------------------------------*/
824 df_free_ref (df_ref ref
)
826 struct df_scan_problem_data
*problem_data
827 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
829 switch (DF_REF_CLASS (ref
))
832 pool_free (problem_data
->ref_base_pool
, ref
);
835 case DF_REF_ARTIFICIAL
:
836 pool_free (problem_data
->ref_artificial_pool
, ref
);
840 pool_free (problem_data
->ref_regular_pool
, ref
);
846 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
847 Also delete the def-use or use-def chain if it exists. */
850 df_reg_chain_unlink (df_ref ref
)
852 df_ref next
= DF_REF_NEXT_REG (ref
);
853 df_ref prev
= DF_REF_PREV_REG (ref
);
854 int id
= DF_REF_ID (ref
);
855 struct df_reg_info
*reg_info
;
858 if (DF_REF_REG_DEF_P (ref
))
860 int regno
= DF_REF_REGNO (ref
);
861 reg_info
= DF_REG_DEF_GET (regno
);
862 refs
= df
->def_info
.refs
;
866 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
868 reg_info
= DF_REG_EQ_USE_GET (DF_REF_REGNO (ref
));
869 switch (df
->use_info
.ref_order
)
871 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
872 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
873 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
874 refs
= df
->use_info
.refs
;
882 reg_info
= DF_REG_USE_GET (DF_REF_REGNO (ref
));
883 refs
= df
->use_info
.refs
;
889 if (df
->analyze_subset
)
891 if (bitmap_bit_p (df
->blocks_to_analyze
, DF_REF_BBNO (ref
)))
898 /* Delete any def-use or use-def chains that start here. It is
899 possible that there is trash in this field. This happens for
900 insns that have been deleted when rescanning has been deferred
901 and the chain problem has also been deleted. The chain tear down
902 code skips deleted insns. */
903 if (df_chain
&& DF_REF_CHAIN (ref
))
904 df_chain_unlink (ref
);
907 if (DF_REF_FLAGS_IS_SET (ref
, DF_HARD_REG_LIVE
))
909 gcc_assert (DF_REF_REGNO (ref
) < FIRST_PSEUDO_REGISTER
);
910 df
->hard_regs_live_count
[DF_REF_REGNO (ref
)]--;
913 /* Unlink from the reg chain. If there is no prev, this is the
914 first of the list. If not, just join the next and prev. */
916 DF_REF_NEXT_REG (prev
) = next
;
919 gcc_assert (reg_info
->reg_chain
== ref
);
920 reg_info
->reg_chain
= next
;
923 DF_REF_PREV_REG (next
) = prev
;
929 /* Remove REF from VEC. */
932 df_ref_compress_rec (df_ref
**vec_ptr
, df_ref ref
)
934 df_ref
*vec
= *vec_ptr
;
938 while (*vec
&& *vec
!= ref
)
950 *vec_ptr
= df_null_ref_rec
;
955 /* Unlink REF from all def-use/use-def chains, etc. */
958 df_ref_remove (df_ref ref
)
963 fprintf (dump_file
, "removing ref ");
964 df_ref_debug (ref
, dump_file
);
968 if (DF_REF_REG_DEF_P (ref
))
970 if (DF_REF_IS_ARTIFICIAL (ref
))
972 struct df_scan_bb_info
*bb_info
973 = df_scan_get_bb_info (DF_REF_BBNO (ref
));
974 df_ref_compress_rec (&bb_info
->artificial_defs
, ref
);
978 unsigned int uid
= DF_REF_INSN_UID (ref
);
979 struct df_insn_info
*insn_rec
= DF_INSN_UID_GET (uid
);
980 df_ref_compress_rec (&insn_rec
->defs
, ref
);
985 if (DF_REF_IS_ARTIFICIAL (ref
))
987 struct df_scan_bb_info
*bb_info
988 = df_scan_get_bb_info (DF_REF_BBNO (ref
));
989 df_ref_compress_rec (&bb_info
->artificial_uses
, ref
);
993 unsigned int uid
= DF_REF_INSN_UID (ref
);
994 struct df_insn_info
*insn_rec
= DF_INSN_UID_GET (uid
);
996 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
997 df_ref_compress_rec (&insn_rec
->eq_uses
, ref
);
999 df_ref_compress_rec (&insn_rec
->uses
, ref
);
1003 /* By deleting the ref directly, df_insn_rescan my not find any
1004 differences even though the block will have changed. So we need
1005 to mark the block dirty ourselves. */
1006 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
1007 df_set_bb_dirty (DF_REF_BB (ref
));
1008 df_reg_chain_unlink (ref
);
1012 /* Create the insn record for INSN. If there was one there, zero it
1015 struct df_insn_info
*
1016 df_insn_create_insn_record (rtx insn
)
1018 struct df_scan_problem_data
*problem_data
1019 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1020 struct df_insn_info
*insn_rec
;
1022 df_grow_insn_info ();
1023 insn_rec
= DF_INSN_INFO_GET (insn
);
1026 insn_rec
= (struct df_insn_info
*) pool_alloc (problem_data
->insn_pool
);
1027 DF_INSN_INFO_SET (insn
, insn_rec
);
1029 memset (insn_rec
, 0, sizeof (struct df_insn_info
));
1030 insn_rec
->insn
= insn
;
1035 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
1038 df_ref_chain_delete_du_chain (df_ref
*ref_rec
)
1042 df_ref ref
= *ref_rec
;
1043 /* CHAIN is allocated by DF_CHAIN. So make sure to
1044 pass df_scan instance for the problem. */
1045 if (DF_REF_CHAIN (ref
))
1046 df_chain_unlink (ref
);
1052 /* Delete all refs in the ref chain. */
1055 df_ref_chain_delete (df_ref
*ref_rec
)
1057 df_ref
*start
= ref_rec
;
1060 df_reg_chain_unlink (*ref_rec
);
1064 /* If the list is empty, it has a special shared element that is not
1071 /* Delete the hardreg chain. */
1074 df_mw_hardreg_chain_delete (struct df_mw_hardreg
**hardregs
)
1076 struct df_scan_problem_data
*problem_data
;
1081 problem_data
= (struct df_scan_problem_data
*) df_scan
->problem_data
;
1085 pool_free (problem_data
->mw_reg_pool
, *hardregs
);
1091 /* Delete all of the refs information from the insn with UID.
1092 Internal helper for df_insn_delete, df_insn_rescan, and other
1093 df-scan routines that don't have to work in deferred mode
1094 and do not have to mark basic blocks for re-processing. */
1097 df_insn_info_delete (unsigned int uid
)
1099 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1101 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1102 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1103 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1106 struct df_scan_problem_data
*problem_data
1107 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1109 /* In general, notes do not have the insn_info fields
1110 initialized. However, combine deletes insns by changing them
1111 to notes. How clever. So we cannot just check if it is a
1112 valid insn before short circuiting this code, we need to see
1113 if we actually initialized it. */
1114 if (insn_info
->defs
)
1116 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1120 df_ref_chain_delete_du_chain (insn_info
->defs
);
1121 df_ref_chain_delete_du_chain (insn_info
->uses
);
1122 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1125 df_ref_chain_delete (insn_info
->defs
);
1126 df_ref_chain_delete (insn_info
->uses
);
1127 df_ref_chain_delete (insn_info
->eq_uses
);
1128 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
1130 pool_free (problem_data
->insn_pool
, insn_info
);
1131 DF_INSN_UID_SET (uid
, NULL
);
1135 /* Delete all of the refs information from INSN, either right now
1136 or marked for later in deferred mode. */
1139 df_insn_delete (rtx insn
)
1144 gcc_checking_assert (INSN_P (insn
));
1149 uid
= INSN_UID (insn
);
1150 bb
= BLOCK_FOR_INSN (insn
);
1152 /* ??? bb can be NULL after pass_free_cfg. At that point, DF should
1153 not exist anymore (as mentioned in df-core.c: "The only requirement
1154 [for DF] is that there be a correct control flow graph." Clearly
1155 that isn't the case after pass_free_cfg. But DF is freed much later
1156 because some back-ends want to use DF info even though the CFG is
1157 already gone. It's not clear to me whether that is safe, actually.
1158 In any case, we expect BB to be non-NULL at least up to register
1159 allocation, so disallow a non-NULL BB up to there. Not perfect
1160 but better than nothing... */
1161 gcc_checking_assert (bb
!= NULL
|| reload_completed
);
1163 df_grow_bb_info (df_scan
);
1164 df_grow_reg_info ();
1166 /* The block must be marked as dirty now, rather than later as in
1167 df_insn_rescan and df_notes_rescan because it may not be there at
1168 rescanning time and the mark would blow up.
1169 DEBUG_INSNs do not make a block's data flow solution dirty (at
1170 worst the LUIDs are no longer contiguous). */
1171 if (bb
!= NULL
&& NONDEBUG_INSN_P (insn
))
1172 df_set_bb_dirty (bb
);
1174 /* The client has deferred rescanning. */
1175 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1177 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1180 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1181 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1182 bitmap_set_bit (&df
->insns_to_delete
, uid
);
1185 fprintf (dump_file
, "deferring deletion of insn with uid = %d.\n", uid
);
1190 fprintf (dump_file
, "deleting insn with uid = %d.\n", uid
);
1192 df_insn_info_delete (uid
);
1196 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1199 df_free_collection_rec (struct df_collection_rec
*collection_rec
)
1202 struct df_scan_problem_data
*problem_data
1203 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1205 struct df_mw_hardreg
*mw
;
1207 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
1209 FOR_EACH_VEC_ELT (collection_rec
->use_vec
, ix
, ref
)
1211 FOR_EACH_VEC_ELT (collection_rec
->eq_use_vec
, ix
, ref
)
1213 FOR_EACH_VEC_ELT (collection_rec
->mw_vec
, ix
, mw
)
1214 pool_free (problem_data
->mw_reg_pool
, mw
);
1216 collection_rec
->def_vec
.release ();
1217 collection_rec
->use_vec
.release ();
1218 collection_rec
->eq_use_vec
.release ();
1219 collection_rec
->mw_vec
.release ();
1222 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1225 df_insn_rescan (rtx insn
)
1227 unsigned int uid
= INSN_UID (insn
);
1228 struct df_insn_info
*insn_info
= NULL
;
1229 basic_block bb
= BLOCK_FOR_INSN (insn
);
1230 struct df_collection_rec collection_rec
;
1232 if ((!df
) || (!INSN_P (insn
)))
1238 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1242 /* The client has disabled rescanning and plans to do it itself. */
1243 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1246 df_grow_bb_info (df_scan
);
1247 df_grow_reg_info ();
1249 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1251 /* The client has deferred rescanning. */
1252 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1256 insn_info
= df_insn_create_insn_record (insn
);
1257 insn_info
->defs
= df_null_ref_rec
;
1258 insn_info
->uses
= df_null_ref_rec
;
1259 insn_info
->eq_uses
= df_null_ref_rec
;
1260 insn_info
->mw_hardregs
= df_null_mw_rec
;
1263 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1265 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1266 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1267 bitmap_set_bit (&df
->insns_to_rescan
, INSN_UID (insn
));
1271 vec_stack_alloc (df_ref
, collection_rec
.def_vec
, 128);
1272 vec_stack_alloc (df_ref
, collection_rec
.use_vec
, 32);
1273 vec_stack_alloc (df_ref
, collection_rec
.eq_use_vec
, 32);
1274 vec_stack_alloc (df_mw_hardreg_ptr
, collection_rec
.mw_vec
, 32);
1276 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1277 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1278 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1282 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1283 /* If there's no change, return false. */
1286 df_free_collection_rec (&collection_rec
);
1288 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1292 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1294 /* There's change - we need to delete the existing info.
1295 Since the insn isn't moved, we can salvage its LUID. */
1296 luid
= DF_INSN_LUID (insn
);
1297 df_insn_info_delete (uid
);
1298 df_insn_create_insn_record (insn
);
1299 DF_INSN_LUID (insn
) = luid
;
1303 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1304 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1306 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1309 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
1310 if (!DEBUG_INSN_P (insn
))
1311 df_set_bb_dirty (bb
);
1313 collection_rec
.def_vec
.release ();
1314 collection_rec
.use_vec
.release ();
1315 collection_rec
.eq_use_vec
.release ();
1316 collection_rec
.mw_vec
.release ();
1321 /* Same as df_insn_rescan, but don't mark the basic block as
1325 df_insn_rescan_debug_internal (rtx insn
)
1327 unsigned int uid
= INSN_UID (insn
);
1328 struct df_insn_info
*insn_info
;
1330 gcc_assert (DEBUG_INSN_P (insn
)
1331 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn
)));
1336 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1341 fprintf (dump_file
, "deleting debug_insn with uid = %d.\n", uid
);
1343 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1344 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1345 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1347 if (!insn_info
->defs
)
1350 if (insn_info
->defs
== df_null_ref_rec
1351 && insn_info
->uses
== df_null_ref_rec
1352 && insn_info
->eq_uses
== df_null_ref_rec
1353 && insn_info
->mw_hardregs
== df_null_mw_rec
)
1356 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1360 df_ref_chain_delete_du_chain (insn_info
->defs
);
1361 df_ref_chain_delete_du_chain (insn_info
->uses
);
1362 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1365 df_ref_chain_delete (insn_info
->defs
);
1366 df_ref_chain_delete (insn_info
->uses
);
1367 df_ref_chain_delete (insn_info
->eq_uses
);
1368 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
1370 insn_info
->defs
= df_null_ref_rec
;
1371 insn_info
->uses
= df_null_ref_rec
;
1372 insn_info
->eq_uses
= df_null_ref_rec
;
1373 insn_info
->mw_hardregs
= df_null_mw_rec
;
1379 /* Rescan all of the insns in the function. Note that the artificial
1380 uses and defs are not touched. This function will destroy def-use
1381 or use-def chains. */
1384 df_insn_rescan_all (void)
1386 bool no_insn_rescan
= false;
1387 bool defer_insn_rescan
= false;
1393 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1395 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1397 df_clear_flags (DF_NO_INSN_RESCAN
);
1398 no_insn_rescan
= true;
1401 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1403 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1404 defer_insn_rescan
= true;
1407 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1408 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1410 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1412 df_insn_info_delete (uid
);
1415 bitmap_clear (&tmp
);
1416 bitmap_clear (&df
->insns_to_delete
);
1417 bitmap_clear (&df
->insns_to_rescan
);
1418 bitmap_clear (&df
->insns_to_notes_rescan
);
1423 FOR_BB_INSNS (bb
, insn
)
1425 df_insn_rescan (insn
);
1430 df_set_flags (DF_NO_INSN_RESCAN
);
1431 if (defer_insn_rescan
)
1432 df_set_flags (DF_DEFER_INSN_RESCAN
);
1436 /* Process all of the deferred rescans or deletions. */
1439 df_process_deferred_rescans (void)
1441 bool no_insn_rescan
= false;
1442 bool defer_insn_rescan
= false;
1447 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1449 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1451 df_clear_flags (DF_NO_INSN_RESCAN
);
1452 no_insn_rescan
= true;
1455 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1457 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1458 defer_insn_rescan
= true;
1462 fprintf (dump_file
, "starting the processing of deferred insns\n");
1464 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1465 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1467 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1469 df_insn_info_delete (uid
);
1472 bitmap_copy (&tmp
, &df
->insns_to_rescan
);
1473 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1475 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1477 df_insn_rescan (insn_info
->insn
);
1480 bitmap_copy (&tmp
, &df
->insns_to_notes_rescan
);
1481 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1483 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1485 df_notes_rescan (insn_info
->insn
);
1489 fprintf (dump_file
, "ending the processing of deferred insns\n");
1491 bitmap_clear (&tmp
);
1492 bitmap_clear (&df
->insns_to_delete
);
1493 bitmap_clear (&df
->insns_to_rescan
);
1494 bitmap_clear (&df
->insns_to_notes_rescan
);
1497 df_set_flags (DF_NO_INSN_RESCAN
);
1498 if (defer_insn_rescan
)
1499 df_set_flags (DF_DEFER_INSN_RESCAN
);
1501 /* If someone changed regs_ever_live during this pass, fix up the
1502 entry and exit blocks. */
1503 if (df
->redo_entry_and_exit
)
1505 df_update_entry_exit_and_calls ();
1506 df
->redo_entry_and_exit
= false;
1511 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1512 the uses if INCLUDE_USES. Include the eq_uses if
1516 df_count_refs (bool include_defs
, bool include_uses
,
1517 bool include_eq_uses
)
1521 unsigned int m
= df
->regs_inited
;
1523 for (regno
= 0; regno
< m
; regno
++)
1526 size
+= DF_REG_DEF_COUNT (regno
);
1528 size
+= DF_REG_USE_COUNT (regno
);
1529 if (include_eq_uses
)
1530 size
+= DF_REG_EQ_USE_COUNT (regno
);
1536 /* Take build ref table for either the uses or defs from the reg-use
1537 or reg-def chains. This version processes the refs in reg order
1538 which is likely to be best if processing the whole function. */
1541 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1544 bool include_eq_uses
)
1546 unsigned int m
= df
->regs_inited
;
1548 unsigned int offset
= 0;
1551 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1553 start
= FIRST_PSEUDO_REGISTER
;
1554 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1555 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1560 ref_info
->total_size
1561 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1563 df_check_and_grow_ref_info (ref_info
, 1);
1565 for (regno
= start
; regno
< m
; regno
++)
1568 ref_info
->begin
[regno
] = offset
;
1571 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1574 ref_info
->refs
[offset
] = ref
;
1575 DF_REF_ID (ref
) = offset
++;
1577 ref
= DF_REF_NEXT_REG (ref
);
1578 gcc_checking_assert (offset
< ref_info
->refs_size
);
1583 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1586 ref_info
->refs
[offset
] = ref
;
1587 DF_REF_ID (ref
) = offset
++;
1589 ref
= DF_REF_NEXT_REG (ref
);
1590 gcc_checking_assert (offset
< ref_info
->refs_size
);
1593 if (include_eq_uses
)
1595 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1598 ref_info
->refs
[offset
] = ref
;
1599 DF_REF_ID (ref
) = offset
++;
1601 ref
= DF_REF_NEXT_REG (ref
);
1602 gcc_checking_assert (offset
< ref_info
->refs_size
);
1605 ref_info
->count
[regno
] = count
;
1608 /* The bitmap size is not decremented when refs are deleted. So
1609 reset it now that we have squished out all of the empty
1611 ref_info
->table_size
= offset
;
1615 /* Take build ref table for either the uses or defs from the reg-use
1616 or reg-def chains. This version processes the refs in insn order
1617 which is likely to be best if processing some segment of the
1621 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1624 bool include_eq_uses
)
1627 unsigned int bb_index
;
1628 unsigned int m
= df
->regs_inited
;
1629 unsigned int offset
= 0;
1632 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1634 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1635 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1637 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1638 df_check_and_grow_ref_info (ref_info
, 1);
1640 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1642 basic_block bb
= BASIC_BLOCK (bb_index
);
1647 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1649 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1650 ref_info
->count
[regno
]++;
1653 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1655 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1656 ref_info
->count
[regno
]++;
1659 FOR_BB_INSNS (bb
, insn
)
1663 unsigned int uid
= INSN_UID (insn
);
1666 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1668 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1669 ref_info
->count
[regno
]++;
1672 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1674 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1675 ref_info
->count
[regno
]++;
1677 if (include_eq_uses
)
1678 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1680 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1681 ref_info
->count
[regno
]++;
1687 for (r
= start
; r
< m
; r
++)
1689 ref_info
->begin
[r
] = offset
;
1690 offset
+= ref_info
->count
[r
];
1691 ref_info
->count
[r
] = 0;
1694 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1696 basic_block bb
= BASIC_BLOCK (bb_index
);
1701 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1703 df_ref ref
= *ref_rec
;
1704 unsigned int regno
= DF_REF_REGNO (ref
);
1708 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1709 DF_REF_ID (ref
) = id
;
1710 ref_info
->refs
[id
] = ref
;
1714 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1716 df_ref ref
= *ref_rec
;
1717 unsigned int regno
= DF_REF_REGNO (ref
);
1721 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1722 DF_REF_ID (ref
) = id
;
1723 ref_info
->refs
[id
] = ref
;
1727 FOR_BB_INSNS (bb
, insn
)
1731 unsigned int uid
= INSN_UID (insn
);
1734 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1736 df_ref ref
= *ref_rec
;
1737 unsigned int regno
= DF_REF_REGNO (ref
);
1741 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1742 DF_REF_ID (ref
) = id
;
1743 ref_info
->refs
[id
] = ref
;
1747 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1749 df_ref ref
= *ref_rec
;
1750 unsigned int regno
= DF_REF_REGNO (ref
);
1754 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1755 DF_REF_ID (ref
) = id
;
1756 ref_info
->refs
[id
] = ref
;
1759 if (include_eq_uses
)
1760 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1762 df_ref ref
= *ref_rec
;
1763 unsigned int regno
= DF_REF_REGNO (ref
);
1767 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1768 DF_REF_ID (ref
) = id
;
1769 ref_info
->refs
[id
] = ref
;
1776 /* The bitmap size is not decremented when refs are deleted. So
1777 reset it now that we have squished out all of the empty
1780 ref_info
->table_size
= offset
;
1783 /* Take build ref table for either the uses or defs from the reg-use
1784 or reg-def chains. */
1787 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1790 bool include_eq_uses
)
1792 if (df
->analyze_subset
)
1793 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1794 include_uses
, include_eq_uses
);
1796 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1797 include_uses
, include_eq_uses
);
1801 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1803 df_add_refs_to_table (unsigned int offset
,
1804 struct df_ref_info
*ref_info
,
1809 df_ref ref
= *ref_vec
;
1810 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
1811 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1813 ref_info
->refs
[offset
] = ref
;
1814 DF_REF_ID (*ref_vec
) = offset
++;
1822 /* Count the number of refs in all of the insns of BB. Include the
1823 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1824 eq_uses if INCLUDE_EQ_USES. */
1827 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1828 struct df_ref_info
*ref_info
,
1829 bool include_defs
, bool include_uses
,
1830 bool include_eq_uses
)
1835 offset
= df_add_refs_to_table (offset
, ref_info
,
1836 df_get_artificial_defs (bb
->index
));
1838 offset
= df_add_refs_to_table (offset
, ref_info
,
1839 df_get_artificial_uses (bb
->index
));
1841 FOR_BB_INSNS (bb
, insn
)
1844 unsigned int uid
= INSN_UID (insn
);
1846 offset
= df_add_refs_to_table (offset
, ref_info
,
1847 DF_INSN_UID_DEFS (uid
));
1849 offset
= df_add_refs_to_table (offset
, ref_info
,
1850 DF_INSN_UID_USES (uid
));
1851 if (include_eq_uses
)
1852 offset
= df_add_refs_to_table (offset
, ref_info
,
1853 DF_INSN_UID_EQ_USES (uid
));
1859 /* Organize the refs by insn into the table in REF_INFO. If
1860 blocks_to_analyze is defined, use that set, otherwise the entire
1861 program. Include the defs if INCLUDE_DEFS. Include the uses if
1862 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1865 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1866 bool include_defs
, bool include_uses
,
1867 bool include_eq_uses
)
1870 unsigned int offset
= 0;
1872 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1873 df_check_and_grow_ref_info (ref_info
, 1);
1874 if (df
->blocks_to_analyze
)
1879 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1881 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index
), offset
, ref_info
,
1882 include_defs
, include_uses
,
1886 ref_info
->table_size
= offset
;
1891 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1892 include_defs
, include_uses
,
1894 ref_info
->table_size
= offset
;
1899 /* If the use refs in DF are not organized, reorganize them. */
1902 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1904 if (order
== df
->use_info
.ref_order
)
1909 case DF_REF_ORDER_BY_REG
:
1910 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1913 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1914 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1917 case DF_REF_ORDER_BY_INSN
:
1918 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1921 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1922 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1925 case DF_REF_ORDER_NO_TABLE
:
1926 free (df
->use_info
.refs
);
1927 df
->use_info
.refs
= NULL
;
1928 df
->use_info
.refs_size
= 0;
1931 case DF_REF_ORDER_UNORDERED
:
1932 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1937 df
->use_info
.ref_order
= order
;
1941 /* If the def refs in DF are not organized, reorganize them. */
1944 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1946 if (order
== df
->def_info
.ref_order
)
1951 case DF_REF_ORDER_BY_REG
:
1952 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1955 case DF_REF_ORDER_BY_INSN
:
1956 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1959 case DF_REF_ORDER_NO_TABLE
:
1960 free (df
->def_info
.refs
);
1961 df
->def_info
.refs
= NULL
;
1962 df
->def_info
.refs_size
= 0;
1965 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1966 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1967 case DF_REF_ORDER_UNORDERED
:
1968 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1973 df
->def_info
.ref_order
= order
;
1977 /* Change all of the basic block references in INSN to use the insn's
1978 current basic block. This function is called from routines that move
1979 instructions from one block to another. */
1982 df_insn_change_bb (rtx insn
, basic_block new_bb
)
1984 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1985 struct df_insn_info
*insn_info
;
1986 unsigned int uid
= INSN_UID (insn
);
1988 if (old_bb
== new_bb
)
1991 set_block_for_insn (insn
, new_bb
);
1997 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1999 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
2000 if (insn_info
== NULL
)
2003 fprintf (dump_file
, " unscanned insn\n");
2004 df_insn_rescan (insn
);
2011 df_set_bb_dirty (new_bb
);
2015 fprintf (dump_file
, " from %d to %d\n",
2016 old_bb
->index
, new_bb
->index
);
2017 df_set_bb_dirty (old_bb
);
2021 fprintf (dump_file
, " to %d\n", new_bb
->index
);
2025 /* Helper function for df_ref_change_reg_with_loc. */
2028 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
2029 struct df_reg_info
*new_df
,
2030 int new_regno
, rtx loc
)
2032 df_ref the_ref
= old_df
->reg_chain
;
2036 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
2037 && DF_REF_LOC (the_ref
)
2038 && (*DF_REF_LOC (the_ref
) == loc
))
2040 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
2041 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
2042 df_ref
*ref_vec
, *ref_vec_t
;
2043 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
2044 unsigned int count
= 0;
2046 DF_REF_REGNO (the_ref
) = new_regno
;
2047 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
2049 /* Pull the_ref out of the old regno chain. */
2051 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
2053 old_df
->reg_chain
= next_ref
;
2055 DF_REF_PREV_REG (next_ref
) = prev_ref
;
2058 /* Put the ref into the new regno chain. */
2059 DF_REF_PREV_REG (the_ref
) = NULL
;
2060 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
2061 if (new_df
->reg_chain
)
2062 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
2063 new_df
->reg_chain
= the_ref
;
2065 if (DF_REF_BB (the_ref
))
2066 df_set_bb_dirty (DF_REF_BB (the_ref
));
2068 /* Need to sort the record again that the ref was in because
2069 the regno is a sorting key. First, find the right
2071 if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
2072 ref_vec
= insn_info
->eq_uses
;
2074 ref_vec
= insn_info
->uses
;
2076 fprintf (dump_file
, "changing reg in insn %d\n",
2077 DF_REF_INSN_UID (the_ref
));
2079 ref_vec_t
= ref_vec
;
2081 /* Find the length. */
2087 qsort (ref_vec
, count
, sizeof (df_ref
), df_ref_compare
);
2092 the_ref
= DF_REF_NEXT_REG (the_ref
);
2097 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2098 NEW_REGNO. Refs that do not match LOC are not changed which means
2099 that artificial refs are not changed since they have no loc. This
2100 call is to support the SET_REGNO macro. */
2103 df_ref_change_reg_with_loc (int old_regno
, int new_regno
, rtx loc
)
2105 if ((!df
) || (old_regno
== -1) || (old_regno
== new_regno
))
2108 df_grow_reg_info ();
2110 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
2111 DF_REG_DEF_GET (new_regno
), new_regno
, loc
);
2112 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
2113 DF_REG_USE_GET (new_regno
), new_regno
, loc
);
2114 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
2115 DF_REG_EQ_USE_GET (new_regno
), new_regno
, loc
);
2119 /* Delete the mw_hardregs that point into the eq_notes. */
2122 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
2124 struct df_mw_hardreg
**mw_vec
= insn_info
->mw_hardregs
;
2125 unsigned int deleted
= 0;
2126 unsigned int count
= 0;
2127 struct df_scan_problem_data
*problem_data
2128 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2135 if ((*mw_vec
)->flags
& DF_REF_IN_NOTE
)
2137 struct df_mw_hardreg
**temp_vec
= mw_vec
;
2139 pool_free (problem_data
->mw_reg_pool
, *mw_vec
);
2141 /* Shove the remaining ones down one to fill the gap. While
2142 this looks n**2, it is highly unusual to have any mw regs
2143 in eq_notes and the chances of more than one are almost
2147 *temp_vec
= *(temp_vec
+ 1);
2161 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
2162 insn_info
->mw_hardregs
= df_null_mw_rec
;
2169 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2172 df_notes_rescan (rtx insn
)
2174 struct df_insn_info
*insn_info
;
2175 unsigned int uid
= INSN_UID (insn
);
2180 /* The client has disabled rescanning and plans to do it itself. */
2181 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
2184 /* Do nothing if the insn hasn't been emitted yet. */
2185 if (!BLOCK_FOR_INSN (insn
))
2188 df_grow_bb_info (df_scan
);
2189 df_grow_reg_info ();
2191 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID(insn
));
2193 /* The client has deferred rescanning. */
2194 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
2198 insn_info
= df_insn_create_insn_record (insn
);
2199 insn_info
->defs
= df_null_ref_rec
;
2200 insn_info
->uses
= df_null_ref_rec
;
2201 insn_info
->eq_uses
= df_null_ref_rec
;
2202 insn_info
->mw_hardregs
= df_null_mw_rec
;
2205 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
2206 /* If the insn is set to be rescanned, it does not need to also
2207 be notes rescanned. */
2208 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
2209 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
2213 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
2214 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
2218 basic_block bb
= BLOCK_FOR_INSN (insn
);
2220 struct df_collection_rec collection_rec
;
2221 unsigned int num_deleted
;
2222 unsigned int mw_len
;
2224 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
2225 vec_stack_alloc (df_ref
, collection_rec
.eq_use_vec
, 32);
2226 vec_stack_alloc (df_mw_hardreg_ptr
, collection_rec
.mw_vec
, 32);
2228 num_deleted
= df_mw_hardreg_chain_delete_eq_uses (insn_info
);
2229 df_ref_chain_delete (insn_info
->eq_uses
);
2230 insn_info
->eq_uses
= NULL
;
2232 /* Process REG_EQUIV/REG_EQUAL notes */
2233 for (note
= REG_NOTES (insn
); note
;
2234 note
= XEXP (note
, 1))
2236 switch (REG_NOTE_KIND (note
))
2240 df_uses_record (&collection_rec
,
2241 &XEXP (note
, 0), DF_REF_REG_USE
,
2242 bb
, insn_info
, DF_REF_IN_NOTE
);
2248 /* Find some place to put any new mw_hardregs. */
2249 df_canonize_collection_rec (&collection_rec
);
2250 mw_len
= collection_rec
.mw_vec
.length ();
2253 unsigned int count
= 0;
2254 struct df_mw_hardreg
**mw_rec
= insn_info
->mw_hardregs
;
2263 /* Append to the end of the existing record after
2264 expanding it if necessary. */
2265 if (mw_len
> num_deleted
)
2267 insn_info
->mw_hardregs
=
2268 XRESIZEVEC (struct df_mw_hardreg
*,
2269 insn_info
->mw_hardregs
,
2270 count
+ 1 + mw_len
);
2272 memcpy (&insn_info
->mw_hardregs
[count
],
2273 collection_rec
.mw_vec
.address (),
2274 mw_len
* sizeof (struct df_mw_hardreg
*));
2275 insn_info
->mw_hardregs
[count
+ mw_len
] = NULL
;
2276 qsort (insn_info
->mw_hardregs
, count
+ mw_len
,
2277 sizeof (struct df_mw_hardreg
*), df_mw_compare
);
2281 /* No vector there. */
2282 insn_info
->mw_hardregs
2283 = XNEWVEC (struct df_mw_hardreg
*, 1 + mw_len
);
2284 memcpy (insn_info
->mw_hardregs
,
2285 collection_rec
.mw_vec
.address (),
2286 mw_len
* sizeof (struct df_mw_hardreg
*));
2287 insn_info
->mw_hardregs
[mw_len
] = NULL
;
2290 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2292 collection_rec
.mw_vec
.release ();
2293 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
2294 collection_rec
.eq_use_vec
.release ();
2297 df_insn_rescan (insn
);
2302 /*----------------------------------------------------------------------------
2303 Hard core instruction scanning code. No external interfaces here,
2304 just a lot of routines that look inside insns.
2305 ----------------------------------------------------------------------------*/
2308 /* Return true if the contents of two df_ref's are identical.
2309 It ignores DF_REF_MARKER. */
2312 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2320 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2321 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2322 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2323 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2324 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2325 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2326 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2327 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2330 switch (DF_REF_CLASS (ref1
))
2332 case DF_REF_ARTIFICIAL
:
2336 case DF_REF_REGULAR
:
2337 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2346 /* Compare REF1 and REF2 for sorting. This is only called from places
2347 where all of the refs are of the same type, in the same insn, and
2348 have the same bb. So these fields are not checked. */
2351 df_ref_compare (const void *r1
, const void *r2
)
2353 const df_ref ref1
= *(const df_ref
*)r1
;
2354 const df_ref ref2
= *(const df_ref
*)r2
;
2359 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2360 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2362 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2363 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2365 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2366 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2368 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2369 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2371 /* Cannot look at the LOC field on artificial refs. */
2372 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2373 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2374 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2376 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2378 /* If two refs are identical except that one of them has is from
2379 a mw and one is not, we need to have the one with the mw
2381 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2382 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2383 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2384 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2390 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2394 df_swap_refs (vec
<df_ref
, va_stack
> *ref_vec
, int i
, int j
)
2396 df_ref tmp
= (*ref_vec
)[i
];
2397 (*ref_vec
)[i
] = (*ref_vec
)[j
];
2398 (*ref_vec
)[j
] = tmp
;
2401 /* Sort and compress a set of refs. */
2404 df_sort_and_compress_refs (vec
<df_ref
, va_stack
> *ref_vec
)
2408 unsigned int dist
= 0;
2410 count
= ref_vec
->length ();
2412 /* If there are 1 or 0 elements, there is nothing to do. */
2415 else if (count
== 2)
2417 df_ref r0
= (*ref_vec
)[0];
2418 df_ref r1
= (*ref_vec
)[1];
2419 if (df_ref_compare (&r0
, &r1
) > 0)
2420 df_swap_refs (ref_vec
, 0, 1);
2424 for (i
= 0; i
< count
- 1; i
++)
2426 df_ref r0
= (*ref_vec
)[i
];
2427 df_ref r1
= (*ref_vec
)[i
+ 1];
2428 if (df_ref_compare (&r0
, &r1
) >= 0)
2431 /* If the array is already strictly ordered,
2432 which is the most common case for large COUNT case
2433 (which happens for CALL INSNs),
2434 no need to sort and filter out duplicate.
2435 Simply return the count.
2436 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2437 of DF_REF_COMPARE. */
2440 ref_vec
->qsort (df_ref_compare
);
2443 for (i
=0; i
<count
-dist
; i
++)
2445 /* Find the next ref that is not equal to the current ref. */
2446 while (i
+ dist
+ 1 < count
2447 && df_ref_equal_p ((*ref_vec
)[i
],
2448 (*ref_vec
)[i
+ dist
+ 1]))
2450 df_free_ref ((*ref_vec
)[i
+ dist
+ 1]);
2453 /* Copy it down to the next position. */
2454 if (dist
&& i
+ dist
+ 1 < count
)
2455 (*ref_vec
)[i
+ 1] = (*ref_vec
)[i
+ dist
+ 1];
2459 ref_vec
->truncate (count
);
2463 /* Return true if the contents of two df_ref's are identical.
2464 It ignores DF_REF_MARKER. */
2467 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2471 return (mw1
== mw2
) ||
2472 (mw1
->mw_reg
== mw2
->mw_reg
2473 && mw1
->type
== mw2
->type
2474 && mw1
->flags
== mw2
->flags
2475 && mw1
->start_regno
== mw2
->start_regno
2476 && mw1
->end_regno
== mw2
->end_regno
);
2480 /* Compare MW1 and MW2 for sorting. */
2483 df_mw_compare (const void *m1
, const void *m2
)
2485 const struct df_mw_hardreg
*const mw1
= *(const struct df_mw_hardreg
*const*)m1
;
2486 const struct df_mw_hardreg
*const mw2
= *(const struct df_mw_hardreg
*const*)m2
;
2491 if (mw1
->type
!= mw2
->type
)
2492 return mw1
->type
- mw2
->type
;
2494 if (mw1
->flags
!= mw2
->flags
)
2495 return mw1
->flags
- mw2
->flags
;
2497 if (mw1
->start_regno
!= mw2
->start_regno
)
2498 return mw1
->start_regno
- mw2
->start_regno
;
2500 if (mw1
->end_regno
!= mw2
->end_regno
)
2501 return mw1
->end_regno
- mw2
->end_regno
;
2503 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2504 return mw1
->mw_order
- mw2
->mw_order
;
2510 /* Sort and compress a set of refs. */
2513 df_sort_and_compress_mws (vec
<df_mw_hardreg_ptr
, va_stack
> *mw_vec
)
2516 struct df_scan_problem_data
*problem_data
2517 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2519 unsigned int dist
= 0;
2521 count
= mw_vec
->length ();
2524 else if (count
== 2)
2526 struct df_mw_hardreg
*m0
= (*mw_vec
)[0];
2527 struct df_mw_hardreg
*m1
= (*mw_vec
)[1];
2528 if (df_mw_compare (&m0
, &m1
) > 0)
2530 struct df_mw_hardreg
*tmp
= (*mw_vec
)[0];
2531 (*mw_vec
)[0] = (*mw_vec
)[1];
2536 mw_vec
->qsort (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 ((*mw_vec
)[i
], (*mw_vec
)[i
+ dist
+ 1]))
2544 pool_free (problem_data
->mw_reg_pool
,
2545 (*mw_vec
)[i
+ dist
+ 1]);
2548 /* Copy it down to the next position. */
2549 if (dist
&& i
+ dist
+ 1 < count
)
2550 (*mw_vec
)[i
+ 1] = (*mw_vec
)[i
+ dist
+ 1];
2554 mw_vec
->truncate (count
);
2558 /* Sort and remove duplicates from the COLLECTION_REC. */
2561 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2563 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2564 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2565 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2566 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2570 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2573 df_install_ref (df_ref this_ref
,
2574 struct df_reg_info
*reg_info
,
2575 struct df_ref_info
*ref_info
,
2578 unsigned int regno
= DF_REF_REGNO (this_ref
);
2579 /* Add the ref to the reg_{def,use,eq_use} chain. */
2580 df_ref head
= reg_info
->reg_chain
;
2582 reg_info
->reg_chain
= this_ref
;
2585 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2587 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2588 df
->hard_regs_live_count
[regno
]++;
2591 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2592 && DF_REF_PREV_REG (this_ref
) == NULL
);
2594 DF_REF_NEXT_REG (this_ref
) = head
;
2596 /* We cannot actually link to the head of the chain. */
2597 DF_REF_PREV_REG (this_ref
) = NULL
;
2600 DF_REF_PREV_REG (head
) = this_ref
;
2604 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2605 df_check_and_grow_ref_info (ref_info
, 1);
2606 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2607 /* Add the ref to the big array of defs. */
2608 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2609 ref_info
->table_size
++;
2612 DF_REF_ID (this_ref
) = -1;
2614 ref_info
->total_size
++;
2618 /* This function takes one of the groups of refs (defs, uses or
2619 eq_uses) and installs the entire group into the insn. It also adds
2620 each of these refs into the appropriate chains. */
2623 df_install_refs (basic_block bb
,
2624 vec
<df_ref
, va_stack
> old_vec
,
2625 struct df_reg_info
**reg_info
,
2626 struct df_ref_info
*ref_info
,
2631 count
= old_vec
.length ();
2634 df_ref
*new_vec
= XNEWVEC (df_ref
, count
+ 1);
2639 switch (ref_info
->ref_order
)
2641 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2642 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2643 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2644 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2645 add_to_table
= true;
2647 case DF_REF_ORDER_UNORDERED
:
2648 case DF_REF_ORDER_BY_REG
:
2649 case DF_REF_ORDER_BY_INSN
:
2650 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2651 add_to_table
= !is_notes
;
2654 add_to_table
= false;
2658 /* Do not add if ref is not in the right blocks. */
2659 if (add_to_table
&& df
->analyze_subset
)
2660 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2662 FOR_EACH_VEC_ELT (old_vec
, ix
, this_ref
)
2664 new_vec
[ix
] = this_ref
;
2665 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2666 ref_info
, add_to_table
);
2669 new_vec
[count
] = NULL
;
2673 return df_null_ref_rec
;
2677 /* This function takes the mws installs the entire group into the
2680 static struct df_mw_hardreg
**
2681 df_install_mws (vec
<df_mw_hardreg_ptr
, va_stack
> old_vec
)
2685 count
= old_vec
.length ();
2688 struct df_mw_hardreg
**new_vec
2689 = XNEWVEC (struct df_mw_hardreg
*, count
+ 1);
2690 memcpy (new_vec
, old_vec
.address (),
2691 sizeof (struct df_mw_hardreg
*) * count
);
2692 new_vec
[count
] = NULL
;
2696 return df_null_mw_rec
;
2700 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2701 chains and update other necessary information. */
2704 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2705 basic_block bb
, rtx insn
)
2709 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2710 /* If there is a vector in the collection rec, add it to the
2711 insn. A null rec is a signal that the caller will handle the
2713 if (collection_rec
->def_vec
.exists ())
2715 df_scan_free_ref_vec (insn_rec
->defs
);
2717 = df_install_refs (bb
, collection_rec
->def_vec
,
2719 &df
->def_info
, false);
2721 if (collection_rec
->use_vec
.exists ())
2723 df_scan_free_ref_vec (insn_rec
->uses
);
2725 = df_install_refs (bb
, collection_rec
->use_vec
,
2727 &df
->use_info
, false);
2729 if (collection_rec
->eq_use_vec
.exists ())
2731 df_scan_free_ref_vec (insn_rec
->eq_uses
);
2733 = df_install_refs (bb
, collection_rec
->eq_use_vec
,
2735 &df
->use_info
, true);
2737 if (collection_rec
->mw_vec
.exists ())
2739 df_scan_free_mws_vec (insn_rec
->mw_hardregs
);
2740 insn_rec
->mw_hardregs
2741 = df_install_mws (collection_rec
->mw_vec
);
2746 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2748 df_scan_free_ref_vec (bb_info
->artificial_defs
);
2749 bb_info
->artificial_defs
2750 = df_install_refs (bb
, collection_rec
->def_vec
,
2752 &df
->def_info
, false);
2753 df_scan_free_ref_vec (bb_info
->artificial_uses
);
2754 bb_info
->artificial_uses
2755 = df_install_refs (bb
, collection_rec
->use_vec
,
2757 &df
->use_info
, false);
2762 /* Allocate a ref and initialize its fields. */
2765 df_ref_create_structure (enum df_ref_class cl
,
2766 struct df_collection_rec
*collection_rec
,
2768 basic_block bb
, struct df_insn_info
*info
,
2769 enum df_ref_type ref_type
,
2772 df_ref this_ref
= NULL
;
2773 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2774 struct df_scan_problem_data
*problem_data
2775 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2780 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_base_pool
);
2781 gcc_checking_assert (loc
== NULL
);
2784 case DF_REF_ARTIFICIAL
:
2785 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_artificial_pool
);
2786 this_ref
->artificial_ref
.bb
= bb
;
2787 gcc_checking_assert (loc
== NULL
);
2790 case DF_REF_REGULAR
:
2791 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_regular_pool
);
2792 this_ref
->regular_ref
.loc
= loc
;
2793 gcc_checking_assert (loc
);
2797 DF_REF_CLASS (this_ref
) = cl
;
2798 DF_REF_ID (this_ref
) = -1;
2799 DF_REF_REG (this_ref
) = reg
;
2800 DF_REF_REGNO (this_ref
) = regno
;
2801 DF_REF_TYPE (this_ref
) = ref_type
;
2802 DF_REF_INSN_INFO (this_ref
) = info
;
2803 DF_REF_CHAIN (this_ref
) = NULL
;
2804 DF_REF_FLAGS (this_ref
) = ref_flags
;
2805 DF_REF_NEXT_REG (this_ref
) = NULL
;
2806 DF_REF_PREV_REG (this_ref
) = NULL
;
2807 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2809 /* We need to clear this bit because fwprop, and in the future
2810 possibly other optimizations sometimes create new refs using ond
2811 refs as the model. */
2812 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2814 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2815 if (regno
< FIRST_PSEUDO_REGISTER
2816 && !DF_REF_IS_ARTIFICIAL (this_ref
)
2817 && !DEBUG_INSN_P (DF_REF_INSN (this_ref
)))
2819 if (DF_REF_REG_DEF_P (this_ref
))
2821 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2822 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2824 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2825 && (regno
== FRAME_POINTER_REGNUM
2826 || regno
== ARG_POINTER_REGNUM
)))
2827 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2832 if (DF_REF_REG_DEF_P (this_ref
))
2833 collection_rec
->def_vec
.safe_push (this_ref
);
2834 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2835 collection_rec
->eq_use_vec
.safe_push (this_ref
);
2837 collection_rec
->use_vec
.safe_push (this_ref
);
2840 df_install_ref_incremental (this_ref
);
2846 /* Create new references of type DF_REF_TYPE for each part of register REG
2847 at address LOC within INSN of BB. */
2851 df_ref_record (enum df_ref_class cl
,
2852 struct df_collection_rec
*collection_rec
,
2854 basic_block bb
, struct df_insn_info
*insn_info
,
2855 enum df_ref_type ref_type
,
2860 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2862 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2863 if (regno
< FIRST_PSEUDO_REGISTER
)
2865 struct df_mw_hardreg
*hardreg
= NULL
;
2866 struct df_scan_problem_data
*problem_data
2867 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2869 unsigned int endregno
;
2872 if (GET_CODE (reg
) == SUBREG
)
2874 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2875 SUBREG_BYTE (reg
), GET_MODE (reg
));
2876 endregno
= regno
+ subreg_nregs (reg
);
2879 endregno
= END_HARD_REGNO (reg
);
2881 /* If this is a multiword hardreg, we create some extra
2882 datastructures that will enable us to easily build REG_DEAD
2883 and REG_UNUSED notes. */
2885 && (endregno
!= regno
+ 1) && insn_info
)
2887 /* Sets to a subreg of a multiword register are partial.
2888 Sets to a non-subreg of a multiword register are not. */
2889 if (GET_CODE (reg
) == SUBREG
)
2890 ref_flags
|= DF_REF_PARTIAL
;
2891 ref_flags
|= DF_REF_MW_HARDREG
;
2893 hardreg
= (struct df_mw_hardreg
*) pool_alloc (problem_data
->mw_reg_pool
);
2894 hardreg
->type
= ref_type
;
2895 hardreg
->flags
= ref_flags
;
2896 hardreg
->mw_reg
= reg
;
2897 hardreg
->start_regno
= regno
;
2898 hardreg
->end_regno
= endregno
- 1;
2899 hardreg
->mw_order
= df
->ref_order
++;
2900 collection_rec
->mw_vec
.safe_push (hardreg
);
2903 for (i
= regno
; i
< endregno
; i
++)
2905 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2906 bb
, insn_info
, ref_type
, ref_flags
);
2908 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2913 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2914 ref_type
, ref_flags
);
2919 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2920 covered by the outer mode is smaller than that covered by the inner mode,
2921 is a read-modify-write operation.
2922 This function returns true iff the SUBREG X is such a SUBREG. */
2925 df_read_modify_subreg_p (rtx x
)
2927 unsigned int isize
, osize
;
2928 if (GET_CODE (x
) != SUBREG
)
2930 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2931 osize
= GET_MODE_SIZE (GET_MODE (x
));
2932 return isize
> osize
2933 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2937 /* Process all the registers defined in the rtx pointed by LOC.
2938 Autoincrement/decrement definitions will be picked up by df_uses_record.
2939 Any change here has to be matched in df_find_hard_reg_defs_1. */
2942 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2943 rtx
*loc
, basic_block bb
, struct df_insn_info
*insn_info
,
2948 /* It is legal to have a set destination be a parallel. */
2949 if (GET_CODE (dst
) == PARALLEL
)
2952 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2954 rtx temp
= XVECEXP (dst
, 0, i
);
2955 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2956 df_def_record_1 (collection_rec
, &XEXP (temp
, 0),
2957 bb
, insn_info
, flags
);
2962 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2964 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2966 loc
= &XEXP (dst
, 0);
2970 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2972 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2974 loc
= &XEXP (dst
, 0);
2978 /* At this point if we do not have a reg or a subreg, just return. */
2981 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2982 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2984 /* We want to keep sp alive everywhere - by making all
2985 writes to sp also use of sp. */
2986 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2987 df_ref_record (DF_REF_BASE
, collection_rec
,
2988 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
2990 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2992 if (df_read_modify_subreg_p (dst
))
2993 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2995 flags
|= DF_REF_SUBREG
;
2997 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2998 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3003 /* Process all the registers defined in the pattern rtx, X. Any change
3004 here has to be matched in df_find_hard_reg_defs. */
3007 df_defs_record (struct df_collection_rec
*collection_rec
,
3008 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
3011 RTX_CODE code
= GET_CODE (x
);
3017 df_def_record_1 (collection_rec
, &SET_DEST (x
), bb
, insn_info
, flags
);
3021 flags
|= DF_REF_MUST_CLOBBER
;
3022 df_def_record_1 (collection_rec
, &XEXP (x
, 0), bb
, insn_info
, flags
);
3026 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
3027 bb
, insn_info
, DF_REF_CONDITIONAL
);
3031 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
3032 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
),
3033 bb
, insn_info
, flags
);
3036 /* No DEFs to record in other cases */
3041 /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
3042 destination of a set or clobber. This has to match the logic in
3043 df_defs_record_1. */
3046 df_find_hard_reg_defs_1 (rtx dst
, HARD_REG_SET
*defs
)
3048 /* It is legal to have a set destination be a parallel. */
3049 if (GET_CODE (dst
) == PARALLEL
)
3052 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
3054 rtx temp
= XVECEXP (dst
, 0, i
);
3055 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
3056 df_find_hard_reg_defs_1 (XEXP (temp
, 0), defs
);
3061 if (GET_CODE (dst
) == STRICT_LOW_PART
)
3062 dst
= XEXP (dst
, 0);
3064 if (GET_CODE (dst
) == ZERO_EXTRACT
)
3065 dst
= XEXP (dst
, 0);
3067 /* At this point if we do not have a reg or a subreg, just return. */
3068 if (REG_P (dst
) && HARD_REGISTER_P (dst
))
3069 SET_HARD_REG_BIT (*defs
, REGNO (dst
));
3070 else if (GET_CODE (dst
) == SUBREG
3071 && REG_P (SUBREG_REG (dst
)) && HARD_REGISTER_P (dst
))
3072 SET_HARD_REG_BIT (*defs
, REGNO (SUBREG_REG (dst
)));
3075 /* Set bits in *DEFS for hard registers defined in the pattern X. This
3076 has to match the logic in df_defs_record. */
3079 df_find_hard_reg_defs (rtx x
, HARD_REG_SET
*defs
)
3081 RTX_CODE code
= GET_CODE (x
);
3087 df_find_hard_reg_defs_1 (SET_DEST (x
), defs
);
3091 df_find_hard_reg_defs_1 (XEXP (x
, 0), defs
);
3095 df_find_hard_reg_defs (COND_EXEC_CODE (x
), defs
);
3099 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
3100 df_find_hard_reg_defs (XVECEXP (x
, 0, i
), defs
);
3103 /* No DEFs to record in other cases */
3109 /* Process all the registers used in the rtx at address LOC. */
3112 df_uses_record (struct df_collection_rec
*collection_rec
,
3113 rtx
*loc
, enum df_ref_type ref_type
,
3114 basic_block bb
, struct df_insn_info
*insn_info
,
3124 code
= GET_CODE (x
);
3138 /* If we are clobbering a MEM, mark any registers inside the address
3140 if (MEM_P (XEXP (x
, 0)))
3141 df_uses_record (collection_rec
,
3142 &XEXP (XEXP (x
, 0), 0),
3143 DF_REF_REG_MEM_STORE
,
3147 /* If we're clobbering a REG then we have a def so ignore. */
3151 df_uses_record (collection_rec
,
3152 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
3153 bb
, insn_info
, flags
& DF_REF_IN_NOTE
);
3157 /* While we're here, optimize this case. */
3158 flags
|= DF_REF_PARTIAL
;
3159 /* In case the SUBREG is not of a REG, do not optimize. */
3160 if (!REG_P (SUBREG_REG (x
)))
3162 loc
= &SUBREG_REG (x
);
3163 df_uses_record (collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
);
3166 /* ... Fall through ... */
3169 df_ref_record (DF_REF_REGULAR
, collection_rec
,
3170 x
, loc
, bb
, insn_info
,
3177 df_uses_record (collection_rec
,
3178 &XEXP (x
, 1), ref_type
, bb
, insn_info
, flags
);
3179 df_uses_record (collection_rec
,
3180 &XEXP (x
, 2), ref_type
, bb
, insn_info
, flags
);
3182 /* If the parameters to the zero or sign extract are
3183 constants, strip them off and recurse, otherwise there is
3184 no information that we can gain from this operation. */
3185 if (code
== ZERO_EXTRACT
)
3186 flags
|= DF_REF_ZERO_EXTRACT
;
3188 flags
|= DF_REF_SIGN_EXTRACT
;
3190 df_uses_record (collection_rec
,
3191 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
);
3198 rtx dst
= SET_DEST (x
);
3199 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
3200 df_uses_record (collection_rec
,
3201 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
);
3203 switch (GET_CODE (dst
))
3206 if (df_read_modify_subreg_p (dst
))
3208 df_uses_record (collection_rec
, &SUBREG_REG (dst
),
3209 DF_REF_REG_USE
, bb
, insn_info
,
3210 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
);
3221 df_uses_record (collection_rec
, &XEXP (dst
, 0),
3222 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
);
3224 case STRICT_LOW_PART
:
3226 rtx
*temp
= &XEXP (dst
, 0);
3227 /* A strict_low_part uses the whole REG and not just the
3229 dst
= XEXP (dst
, 0);
3230 df_uses_record (collection_rec
,
3231 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
3232 DF_REF_REG_USE
, bb
, insn_info
,
3233 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
);
3238 df_uses_record (collection_rec
, &XEXP (dst
, 1),
3239 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3240 df_uses_record (collection_rec
, &XEXP (dst
, 2),
3241 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3242 if (GET_CODE (XEXP (dst
,0)) == MEM
)
3243 df_uses_record (collection_rec
, &XEXP (dst
, 0),
3244 DF_REF_REG_USE
, bb
, insn_info
,
3247 df_uses_record (collection_rec
, &XEXP (dst
, 0),
3248 DF_REF_REG_USE
, bb
, insn_info
,
3249 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
);
3264 case UNSPEC_VOLATILE
:
3268 /* Traditional and volatile asm instructions must be
3269 considered to use and clobber all hard registers, all
3270 pseudo-registers and all of memory. So must TRAP_IF and
3271 UNSPEC_VOLATILE operations.
3273 Consider for instance a volatile asm that changes the fpu
3274 rounding mode. An insn should not be moved across this
3275 even if it only uses pseudo-regs because it might give an
3276 incorrectly rounded result.
3278 However, flow.c's liveness computation did *not* do this,
3279 giving the reasoning as " ?!? Unfortunately, marking all
3280 hard registers as live causes massive problems for the
3281 register allocator and marking all pseudos as live creates
3282 mountains of uninitialized variable warnings."
3284 In order to maintain the status quo with regard to liveness
3285 and uses, we do what flow.c did and just mark any regs we
3286 can find in ASM_OPERANDS as used. In global asm insns are
3287 scanned and regs_asm_clobbered is filled out.
3289 For all ASM_OPERANDS, we must traverse the vector of input
3290 operands. We can not just fall through here since then we
3291 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3292 which do not indicate traditional asms unlike their normal
3294 if (code
== ASM_OPERANDS
)
3298 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3299 df_uses_record (collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3300 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3307 df_uses_record (collection_rec
,
3308 &PAT_VAR_LOCATION_LOC (x
),
3309 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3318 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3319 /* Catch the def of the register being modified. */
3320 df_ref_record (DF_REF_REGULAR
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3323 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
);
3325 /* ... Fall through to handle uses ... */
3331 /* Recursively scan the operands of this expression. */
3333 const char *fmt
= GET_RTX_FORMAT (code
);
3336 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3340 /* Tail recursive case: save a function call level. */
3346 df_uses_record (collection_rec
, &XEXP (x
, i
), ref_type
,
3347 bb
, insn_info
, flags
);
3349 else if (fmt
[i
] == 'E')
3352 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3353 df_uses_record (collection_rec
,
3354 &XVECEXP (x
, i
, j
), ref_type
,
3355 bb
, insn_info
, flags
);
3364 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3367 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3372 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
3374 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3378 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3379 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3380 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3381 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
);
3382 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3388 /* Get call's extra defs and uses (track caller-saved registers). */
3391 df_get_call_refs (struct df_collection_rec
*collection_rec
,
3393 struct df_insn_info
*insn_info
,
3397 bool is_sibling_call
;
3399 HARD_REG_SET defs_generated
;
3401 CLEAR_HARD_REG_SET (defs_generated
);
3402 df_find_hard_reg_defs (PATTERN (insn_info
->insn
), &defs_generated
);
3403 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3405 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3407 if (i
== STACK_POINTER_REGNUM
)
3408 /* The stack ptr is used (honorarily) by a CALL insn. */
3409 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3410 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3411 DF_REF_CALL_STACK_USAGE
| flags
);
3412 else if (global_regs
[i
])
3414 /* Calls to const functions cannot access any global registers and
3415 calls to pure functions cannot set them. All other calls may
3416 reference any of the global registers, so they are recorded as
3418 if (!RTL_CONST_CALL_P (insn_info
->insn
))
3420 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3421 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
3422 if (!RTL_PURE_CALL_P (insn_info
->insn
))
3423 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3424 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3427 else if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
)
3428 /* no clobbers for regs that are the result of the call */
3429 && !TEST_HARD_REG_BIT (defs_generated
, i
)
3430 && (!is_sibling_call
3431 || !bitmap_bit_p (df
->exit_block_uses
, i
)
3432 || refers_to_regno_p (i
, i
+1,
3433 crtl
->return_rtx
, NULL
)))
3434 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3435 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3436 DF_REF_MAY_CLOBBER
| flags
);
3439 /* Record the registers used to pass arguments, and explicitly
3440 noted as clobbered. */
3441 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3442 note
= XEXP (note
, 1))
3444 if (GET_CODE (XEXP (note
, 0)) == USE
)
3445 df_uses_record (collection_rec
, &XEXP (XEXP (note
, 0), 0),
3446 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3447 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3449 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3451 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3452 if (!TEST_HARD_REG_BIT (defs_generated
, regno
))
3453 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3457 df_uses_record (collection_rec
, &XEXP (note
, 0),
3458 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3465 /* Collect all refs in the INSN. This function is free of any
3466 side-effect - it will create and return a lists of df_ref's in the
3467 COLLECTION_REC without putting those refs into existing ref chains
3471 df_insn_refs_collect (struct df_collection_rec
*collection_rec
,
3472 basic_block bb
, struct df_insn_info
*insn_info
)
3475 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3477 /* Clear out the collection record. */
3478 collection_rec
->def_vec
.truncate (0);
3479 collection_rec
->use_vec
.truncate (0);
3480 collection_rec
->eq_use_vec
.truncate (0);
3481 collection_rec
->mw_vec
.truncate (0);
3483 /* Process REG_EQUIV/REG_EQUAL notes. */
3484 for (note
= REG_NOTES (insn_info
->insn
); note
;
3485 note
= XEXP (note
, 1))
3487 switch (REG_NOTE_KIND (note
))
3491 df_uses_record (collection_rec
,
3492 &XEXP (note
, 0), DF_REF_REG_USE
,
3493 bb
, insn_info
, DF_REF_IN_NOTE
);
3495 case REG_NON_LOCAL_GOTO
:
3496 /* The frame ptr is used by a non-local goto. */
3497 df_ref_record (DF_REF_BASE
, collection_rec
,
3498 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3499 NULL
, bb
, insn_info
,
3501 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3502 df_ref_record (DF_REF_BASE
, collection_rec
,
3503 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3504 NULL
, bb
, insn_info
,
3513 /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
3514 uses from CALL_INSN_FUNCTION_USAGE. */
3515 if (CALL_P (insn_info
->insn
))
3516 df_get_call_refs (collection_rec
, bb
, insn_info
,
3517 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3519 /* Record other defs. These should be mostly for DF_REF_REGULAR, so
3520 that a qsort on the defs is unnecessary in most cases. */
3521 df_defs_record (collection_rec
,
3522 PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3524 /* Record the register uses. */
3525 df_uses_record (collection_rec
,
3526 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0);
3528 /* DF_REF_CONDITIONAL needs corresponding USES. */
3530 df_get_conditional_uses (collection_rec
);
3532 df_canonize_collection_rec (collection_rec
);
3535 /* Recompute the luids for the insns in BB. */
3538 df_recompute_luids (basic_block bb
)
3543 df_grow_insn_info ();
3545 /* Scan the block an insn at a time from beginning to end. */
3546 FOR_BB_INSNS (bb
, insn
)
3548 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3549 /* Inserting labels does not always trigger the incremental
3553 gcc_assert (!INSN_P (insn
));
3554 insn_info
= df_insn_create_insn_record (insn
);
3557 DF_INSN_INFO_LUID (insn_info
) = luid
;
3564 /* Collect all artificial refs at the block level for BB and add them
3565 to COLLECTION_REC. */
3568 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3570 collection_rec
->def_vec
.truncate (0);
3571 collection_rec
->use_vec
.truncate (0);
3572 collection_rec
->eq_use_vec
.truncate (0);
3573 collection_rec
->mw_vec
.truncate (0);
3575 if (bb
->index
== ENTRY_BLOCK
)
3577 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3580 else if (bb
->index
== EXIT_BLOCK
)
3582 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3586 #ifdef EH_RETURN_DATA_REGNO
3587 if (bb_has_eh_pred (bb
))
3590 /* Mark the registers that will contain data for the handler. */
3593 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3594 if (regno
== INVALID_REGNUM
)
3596 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3597 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3602 /* Add the hard_frame_pointer if this block is the target of a
3604 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3605 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3606 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3608 /* Add the artificial uses. */
3609 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3613 bitmap au
= bb_has_eh_pred (bb
)
3614 ? &df
->eh_block_artificial_uses
3615 : &df
->regular_block_artificial_uses
;
3617 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3619 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3620 bb
, NULL
, DF_REF_REG_USE
, 0);
3624 df_canonize_collection_rec (collection_rec
);
3628 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3631 df_bb_refs_record (int bb_index
, bool scan_insns
)
3633 basic_block bb
= BASIC_BLOCK (bb_index
);
3636 struct df_collection_rec collection_rec
;
3641 df_grow_bb_info (df_scan
);
3642 vec_stack_alloc (df_ref
, collection_rec
.def_vec
, 128);
3643 vec_stack_alloc (df_ref
, collection_rec
.use_vec
, 32);
3644 vec_stack_alloc (df_ref
, collection_rec
.eq_use_vec
, 32);
3645 vec_stack_alloc (df_mw_hardreg_ptr
, collection_rec
.mw_vec
, 32);
3648 /* Scan the block an insn at a time from beginning to end. */
3649 FOR_BB_INSNS (bb
, insn
)
3651 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3652 gcc_assert (!insn_info
);
3654 insn_info
= df_insn_create_insn_record (insn
);
3657 /* Record refs within INSN. */
3658 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3659 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3660 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
3662 DF_INSN_INFO_LUID (insn_info
) = luid
;
3665 /* Other block level artificial refs */
3666 df_bb_refs_collect (&collection_rec
, bb
);
3667 df_refs_add_to_chains (&collection_rec
, bb
, NULL
);
3669 collection_rec
.def_vec
.release ();
3670 collection_rec
.use_vec
.release ();
3671 collection_rec
.eq_use_vec
.release ();
3672 collection_rec
.mw_vec
.release ();
3674 /* Now that the block has been processed, set the block as dirty so
3675 LR and LIVE will get it processed. */
3676 df_set_bb_dirty (bb
);
3680 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3684 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3690 bitmap_clear (regular_block_artificial_uses
);
3692 if (reload_completed
)
3694 if (frame_pointer_needed
)
3695 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3698 /* Before reload, there are a few registers that must be forced
3699 live everywhere -- which might not already be the case for
3700 blocks within infinite loops. */
3702 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3704 /* Any reference to any pseudo before reload is a potential
3705 reference of the frame pointer. */
3706 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3708 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3709 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3712 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3713 /* Pseudos with argument area equivalences may require
3714 reloading via the argument pointer. */
3715 if (fixed_regs
[ARG_POINTER_REGNUM
])
3716 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3719 /* Any constant, or pseudo with constant equivalences, may
3720 require reloading from memory using the pic register. */
3721 if (picreg
!= INVALID_REGNUM
3722 && fixed_regs
[picreg
])
3723 bitmap_set_bit (regular_block_artificial_uses
, picreg
);
3725 /* The all-important stack pointer must always be live. */
3726 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3729 /* EH_USES registers are used:
3730 1) at all insns that might throw (calls or with -fnon-call-exceptions
3733 3) to support backtraces and/or debugging, anywhere between their
3734 initialization and where they the saved registers are restored
3735 from them, including the cases where we don't reach the epilogue
3736 (noreturn call or infinite loop). */
3737 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3739 bitmap_set_bit (regular_block_artificial_uses
, i
);
3744 /* Get the artificial use set for an eh block. */
3747 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3749 bitmap_clear (eh_block_artificial_uses
);
3751 /* The following code (down through the arg_pointer setting APPEARS
3752 to be necessary because there is nothing that actually
3753 describes what the exception handling code may actually need
3755 if (reload_completed
)
3757 if (frame_pointer_needed
)
3759 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3760 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3761 bitmap_set_bit (eh_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3764 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3765 if (fixed_regs
[ARG_POINTER_REGNUM
])
3766 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3773 /*----------------------------------------------------------------------------
3774 Specialized hard register scanning functions.
3775 ----------------------------------------------------------------------------*/
3778 /* Mark a register in SET. Hard registers in large modes get all
3779 of their component registers set as well. */
3782 df_mark_reg (rtx reg
, void *vset
)
3784 bitmap set
= (bitmap
) vset
;
3785 int regno
= REGNO (reg
);
3787 gcc_assert (GET_MODE (reg
) != BLKmode
);
3789 if (regno
< FIRST_PSEUDO_REGISTER
)
3791 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3792 bitmap_set_range (set
, regno
, n
);
3795 bitmap_set_bit (set
, regno
);
3799 /* Set the bit for regs that are considered being defined at the entry. */
3802 df_get_entry_block_def_set (bitmap entry_block_defs
)
3807 bitmap_clear (entry_block_defs
);
3809 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3812 bitmap_set_bit (entry_block_defs
, i
);
3813 if (FUNCTION_ARG_REGNO_P (i
))
3814 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3817 /* The always important stack pointer. */
3818 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3820 /* Once the prologue has been generated, all of these registers
3821 should just show up in the first regular block. */
3822 if (HAVE_prologue
&& epilogue_completed
)
3824 /* Defs for the callee saved registers are inserted so that the
3825 pushes have some defining location. */
3826 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3827 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3828 bitmap_set_bit (entry_block_defs
, i
);
3831 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3833 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3835 /* If the function has an incoming STATIC_CHAIN, it has to show up
3836 in the entry def set. */
3837 r
= targetm
.calls
.static_chain (current_function_decl
, true);
3839 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3841 if ((!reload_completed
) || frame_pointer_needed
)
3843 /* Any reference to any pseudo before reload is a potential
3844 reference of the frame pointer. */
3845 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3846 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3847 /* If they are different, also mark the hard frame pointer as live. */
3848 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3849 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3853 /* These registers are live everywhere. */
3854 if (!reload_completed
)
3856 #ifdef PIC_OFFSET_TABLE_REGNUM
3857 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3860 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3861 /* Pseudos with argument area equivalences may require
3862 reloading via the argument pointer. */
3863 if (fixed_regs
[ARG_POINTER_REGNUM
])
3864 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3867 #ifdef PIC_OFFSET_TABLE_REGNUM
3868 /* Any constant, or pseudo with constant equivalences, may
3869 require reloading from memory using the pic register. */
3870 if (picreg
!= INVALID_REGNUM
3871 && fixed_regs
[picreg
])
3872 bitmap_set_bit (entry_block_defs
, picreg
);
3876 #ifdef INCOMING_RETURN_ADDR_RTX
3877 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3878 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3881 targetm
.extra_live_on_entry (entry_block_defs
);
3885 /* Return the (conservative) set of hard registers that are defined on
3886 entry to the function.
3887 It uses df->entry_block_defs to determine which register
3888 reference to include. */
3891 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3892 bitmap entry_block_defs
)
3897 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3899 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3900 ENTRY_BLOCK_PTR
, NULL
, DF_REF_REG_DEF
, 0);
3903 df_canonize_collection_rec (collection_rec
);
3907 /* Record the (conservative) set of hard registers that are defined on
3908 entry to the function. */
3911 df_record_entry_block_defs (bitmap entry_block_defs
)
3913 struct df_collection_rec collection_rec
;
3914 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
3915 vec_stack_alloc (df_ref
, collection_rec
.def_vec
, FIRST_PSEUDO_REGISTER
);
3916 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3918 /* Process bb_refs chain */
3919 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (ENTRY_BLOCK
), NULL
);
3920 collection_rec
.def_vec
.release ();
3924 /* Update the defs in the entry block. */
3927 df_update_entry_block_defs (void)
3930 bool changed
= false;
3932 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3933 df_get_entry_block_def_set (&refs
);
3934 if (df
->entry_block_defs
)
3936 if (!bitmap_equal_p (df
->entry_block_defs
, &refs
))
3938 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3939 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3940 df_ref_chain_delete (bb_info
->artificial_defs
);
3941 bb_info
->artificial_defs
= NULL
;
3947 struct df_scan_problem_data
*problem_data
3948 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3950 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3956 df_record_entry_block_defs (&refs
);
3957 bitmap_copy (df
->entry_block_defs
, &refs
);
3958 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
3960 bitmap_clear (&refs
);
3964 /* Set the bit for regs that are considered being used at the exit. */
3967 df_get_exit_block_use_set (bitmap exit_block_uses
)
3970 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3972 bitmap_clear (exit_block_uses
);
3974 /* Stack pointer is always live at the exit. */
3975 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3977 /* Mark the frame pointer if needed at the end of the function.
3978 If we end up eliminating it, it will be removed from the live
3979 list of each basic block by reload. */
3981 if ((!reload_completed
) || frame_pointer_needed
)
3983 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3984 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3985 /* If they are different, also mark the hard frame pointer as live. */
3986 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3987 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3991 /* Many architectures have a GP register even without flag_pic.
3992 Assume the pic register is not in use, or will be handled by
3993 other means, if it is not fixed. */
3994 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3995 && picreg
!= INVALID_REGNUM
3996 && fixed_regs
[picreg
])
3997 bitmap_set_bit (exit_block_uses
, picreg
);
3999 /* Mark all global registers, and all registers used by the
4000 epilogue as being live at the end of the function since they
4001 may be referenced by our caller. */
4002 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4003 if (global_regs
[i
] || EPILOGUE_USES (i
))
4004 bitmap_set_bit (exit_block_uses
, i
);
4006 if (HAVE_epilogue
&& epilogue_completed
)
4008 /* Mark all call-saved registers that we actually used. */
4009 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4010 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
4011 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
4012 bitmap_set_bit (exit_block_uses
, i
);
4015 #ifdef EH_RETURN_DATA_REGNO
4016 /* Mark the registers that will contain data for the handler. */
4017 if (reload_completed
&& crtl
->calls_eh_return
)
4020 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
4021 if (regno
== INVALID_REGNUM
)
4023 bitmap_set_bit (exit_block_uses
, regno
);
4027 #ifdef EH_RETURN_STACKADJ_RTX
4028 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4029 && crtl
->calls_eh_return
)
4031 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
4032 if (tmp
&& REG_P (tmp
))
4033 df_mark_reg (tmp
, exit_block_uses
);
4037 #ifdef EH_RETURN_HANDLER_RTX
4038 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4039 && crtl
->calls_eh_return
)
4041 rtx tmp
= EH_RETURN_HANDLER_RTX
;
4042 if (tmp
&& REG_P (tmp
))
4043 df_mark_reg (tmp
, exit_block_uses
);
4047 /* Mark function return value. */
4048 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
4052 /* Return the refs of hard registers that are used in the exit block.
4053 It uses df->exit_block_uses to determine register to include. */
4056 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
4061 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
4062 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
4063 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0);
4065 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4066 /* It is deliberate that this is not put in the exit block uses but
4067 I do not know why. */
4068 if (reload_completed
4069 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
4070 && bb_has_eh_pred (EXIT_BLOCK_PTR
)
4071 && fixed_regs
[ARG_POINTER_REGNUM
])
4072 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
4073 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0);
4076 df_canonize_collection_rec (collection_rec
);
4080 /* Record the set of hard registers that are used in the exit block.
4081 It uses df->exit_block_uses to determine which bit to include. */
4084 df_record_exit_block_uses (bitmap exit_block_uses
)
4086 struct df_collection_rec collection_rec
;
4087 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4088 vec_stack_alloc (df_ref
, collection_rec
.use_vec
, FIRST_PSEUDO_REGISTER
);
4089 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
4091 /* Process bb_refs chain */
4092 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (EXIT_BLOCK
), NULL
);
4093 collection_rec
.use_vec
.release ();
4097 /* Update the uses in the exit block. */
4100 df_update_exit_block_uses (void)
4103 bool changed
= false;
4105 bitmap_initialize (&refs
, &df_bitmap_obstack
);
4106 df_get_exit_block_use_set (&refs
);
4107 if (df
->exit_block_uses
)
4109 if (!bitmap_equal_p (df
->exit_block_uses
, &refs
))
4111 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
4112 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
4113 df_ref_chain_delete (bb_info
->artificial_uses
);
4114 bb_info
->artificial_uses
= NULL
;
4120 struct df_scan_problem_data
*problem_data
4121 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
4123 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
4129 df_record_exit_block_uses (&refs
);
4130 bitmap_copy (df
->exit_block_uses
,& refs
);
4131 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
4133 bitmap_clear (&refs
);
4136 static bool initialized
= false;
4139 /* Initialize some platform specific structures. */
4142 df_hard_reg_init (void)
4144 #ifdef ELIMINABLE_REGS
4146 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
4151 /* Record which registers will be eliminated. We use this in
4153 CLEAR_HARD_REG_SET (elim_reg_set
);
4155 #ifdef ELIMINABLE_REGS
4156 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
4157 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
4159 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
4166 /* Recompute the parts of scanning that are based on regs_ever_live
4167 because something changed in that array. */
4170 df_update_entry_exit_and_calls (void)
4174 df_update_entry_block_defs ();
4175 df_update_exit_block_uses ();
4177 /* The call insns need to be rescanned because there may be changes
4178 in the set of registers clobbered across the call. */
4182 FOR_BB_INSNS (bb
, insn
)
4184 if (INSN_P (insn
) && CALL_P (insn
))
4185 df_insn_rescan (insn
);
4191 /* Return true if hard REG is actually used in the some instruction.
4192 There are a fair number of conditions that affect the setting of
4193 this array. See the comment in df.h for df->hard_regs_live_count
4194 for the conditions that this array is set. */
4197 df_hard_reg_used_p (unsigned int reg
)
4199 return df
->hard_regs_live_count
[reg
] != 0;
4203 /* A count of the number of times REG is actually used in the some
4204 instruction. There are a fair number of conditions that affect the
4205 setting of this array. See the comment in df.h for
4206 df->hard_regs_live_count for the conditions that this array is
4211 df_hard_reg_used_count (unsigned int reg
)
4213 return df
->hard_regs_live_count
[reg
];
4217 /* Get the value of regs_ever_live[REGNO]. */
4220 df_regs_ever_live_p (unsigned int regno
)
4222 return regs_ever_live
[regno
];
4226 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
4227 to change, schedule that change for the next update. */
4230 df_set_regs_ever_live (unsigned int regno
, bool value
)
4232 if (regs_ever_live
[regno
] == value
)
4235 regs_ever_live
[regno
] = value
;
4237 df
->redo_entry_and_exit
= true;
4241 /* Compute "regs_ever_live" information from the underlying df
4242 information. Set the vector to all false if RESET. */
4245 df_compute_regs_ever_live (bool reset
)
4248 bool changed
= df
->redo_entry_and_exit
;
4251 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
4253 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4254 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
4256 regs_ever_live
[i
] = true;
4260 df_update_entry_exit_and_calls ();
4261 df
->redo_entry_and_exit
= false;
4265 /*----------------------------------------------------------------------------
4266 Dataflow ref information verification functions.
4268 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4269 df_reg_chain_verify_unmarked (refs)
4270 df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
4271 df_mws_verify (mw*, mw*, bool)
4272 df_insn_refs_verify (collection_rec, bb, insn, bool)
4273 df_bb_refs_verify (bb, refs, bool)
4275 df_exit_block_bitmap_verify (bool)
4276 df_entry_block_bitmap_verify (bool)
4278 ----------------------------------------------------------------------------*/
4281 /* Mark all refs in the reg chain. Verify that all of the registers
4282 are in the correct chain. */
4285 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
4286 bool is_def
, bool is_eq_use
)
4288 unsigned int count
= 0;
4290 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4292 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4294 /* If there are no def-use or use-def chains, make sure that all
4295 of the chains are clear. */
4297 gcc_assert (!DF_REF_CHAIN (ref
));
4299 /* Check to make sure the ref is in the correct chain. */
4300 gcc_assert (DF_REF_REGNO (ref
) == regno
);
4302 gcc_assert (DF_REF_REG_DEF_P (ref
));
4304 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4307 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4309 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4311 if (DF_REF_NEXT_REG (ref
))
4312 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4314 DF_REF_REG_MARK (ref
);
4320 /* Verify that all of the registers in the chain are unmarked. */
4323 df_reg_chain_verify_unmarked (df_ref refs
)
4326 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4327 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4331 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4334 df_refs_verify (vec
<df_ref
, va_stack
> new_rec
, df_ref
*old_rec
,
4340 FOR_EACH_VEC_ELT (new_rec
, ix
, new_ref
)
4342 if (*old_rec
== NULL
|| !df_ref_equal_p (new_ref
, *old_rec
))
4350 /* Abort if fail is called from the function level verifier. If
4351 that is the context, mark this reg as being seem. */
4354 gcc_assert (DF_REF_IS_REG_MARKED (*old_rec
));
4355 DF_REF_REG_UNMARK (*old_rec
);
4362 gcc_assert (*old_rec
== NULL
);
4364 return *old_rec
== NULL
;
4369 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4372 df_mws_verify (vec
<df_mw_hardreg_ptr
, va_stack
> new_rec
,
4373 struct df_mw_hardreg
**old_rec
,
4377 struct df_mw_hardreg
*new_reg
;
4379 FOR_EACH_VEC_ELT (new_rec
, ix
, new_reg
)
4381 if (*old_rec
== NULL
|| !df_mw_equal_p (new_reg
, *old_rec
))
4392 gcc_assert (*old_rec
== NULL
);
4394 return *old_rec
== NULL
;
4399 /* Return true if the existing insn refs information is complete and
4400 correct. Otherwise (i.e. if there's any missing or extra refs),
4401 return the correct df_ref chain in REFS_RETURN.
4403 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4404 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4405 verification mode instead of the whole function, so unmark
4408 If ABORT_IF_FAIL is set, this function never returns false. */
4411 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4416 bool ret1
, ret2
, ret3
, ret4
;
4417 unsigned int uid
= INSN_UID (insn
);
4418 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4420 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4422 if (!DF_INSN_UID_DEFS (uid
))
4424 /* The insn_rec was created but it was never filled out. */
4431 /* Unfortunately we cannot opt out early if one of these is not
4432 right because the marks will not get cleared. */
4433 ret1
= df_refs_verify (collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4435 ret2
= df_refs_verify (collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4437 ret3
= df_refs_verify (collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4439 ret4
= df_mws_verify (collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4441 return (ret1
&& ret2
&& ret3
&& ret4
);
4445 /* Return true if all refs in the basic block are correct and complete.
4446 Due to df_ref_chain_verify, it will cause all refs
4447 that are verified to have DF_REF_MARK bit set. */
4450 df_bb_verify (basic_block bb
)
4453 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4454 struct df_collection_rec collection_rec
;
4456 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4457 vec_stack_alloc (df_ref
, collection_rec
.def_vec
, 128);
4458 vec_stack_alloc (df_ref
, collection_rec
.use_vec
, 32);
4459 vec_stack_alloc (df_ref
, collection_rec
.eq_use_vec
, 32);
4460 vec_stack_alloc (df_mw_hardreg_ptr
, collection_rec
.mw_vec
, 32);
4462 gcc_assert (bb_info
);
4464 /* Scan the block, one insn at a time, from beginning to end. */
4465 FOR_BB_INSNS_REVERSE (bb
, insn
)
4469 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4470 df_free_collection_rec (&collection_rec
);
4473 /* Do the artificial defs and uses. */
4474 df_bb_refs_collect (&collection_rec
, bb
);
4475 df_refs_verify (collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4476 df_refs_verify (collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4477 df_free_collection_rec (&collection_rec
);
4483 /* Returns true if the entry block has correct and complete df_ref set.
4484 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4487 df_entry_block_bitmap_verify (bool abort_if_fail
)
4489 bitmap_head entry_block_defs
;
4492 bitmap_initialize (&entry_block_defs
, &df_bitmap_obstack
);
4493 df_get_entry_block_def_set (&entry_block_defs
);
4495 is_eq
= bitmap_equal_p (&entry_block_defs
, df
->entry_block_defs
);
4497 if (!is_eq
&& abort_if_fail
)
4499 fprintf (stderr
, "entry_block_defs = ");
4500 df_print_regset (stderr
, &entry_block_defs
);
4501 fprintf (stderr
, "df->entry_block_defs = ");
4502 df_print_regset (stderr
, df
->entry_block_defs
);
4506 bitmap_clear (&entry_block_defs
);
4512 /* Returns true if the exit block has correct and complete df_ref set.
4513 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4516 df_exit_block_bitmap_verify (bool abort_if_fail
)
4518 bitmap_head exit_block_uses
;
4521 bitmap_initialize (&exit_block_uses
, &df_bitmap_obstack
);
4522 df_get_exit_block_use_set (&exit_block_uses
);
4524 is_eq
= bitmap_equal_p (&exit_block_uses
, df
->exit_block_uses
);
4526 if (!is_eq
&& abort_if_fail
)
4528 fprintf (stderr
, "exit_block_uses = ");
4529 df_print_regset (stderr
, &exit_block_uses
);
4530 fprintf (stderr
, "df->exit_block_uses = ");
4531 df_print_regset (stderr
, df
->exit_block_uses
);
4535 bitmap_clear (&exit_block_uses
);
4541 /* Return true if df_ref information for all insns in all blocks are
4542 correct and complete. */
4545 df_scan_verify (void)
4549 bitmap_head regular_block_artificial_uses
;
4550 bitmap_head eh_block_artificial_uses
;
4555 /* Verification is a 4 step process. */
4557 /* (1) All of the refs are marked by going through the reg chains. */
4558 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4560 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4561 == DF_REG_DEF_COUNT(i
));
4562 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4563 == DF_REG_USE_COUNT(i
));
4564 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4565 == DF_REG_EQ_USE_COUNT(i
));
4568 /* (2) There are various bitmaps whose value may change over the
4569 course of the compilation. This step recomputes them to make
4570 sure that they have not slipped out of date. */
4571 bitmap_initialize (®ular_block_artificial_uses
, &df_bitmap_obstack
);
4572 bitmap_initialize (&eh_block_artificial_uses
, &df_bitmap_obstack
);
4574 df_get_regular_block_artificial_uses (®ular_block_artificial_uses
);
4575 df_get_eh_block_artificial_uses (&eh_block_artificial_uses
);
4577 bitmap_ior_into (&eh_block_artificial_uses
,
4578 ®ular_block_artificial_uses
);
4580 /* Check artificial_uses bitmaps didn't change. */
4581 gcc_assert (bitmap_equal_p (®ular_block_artificial_uses
,
4582 &df
->regular_block_artificial_uses
));
4583 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses
,
4584 &df
->eh_block_artificial_uses
));
4586 bitmap_clear (®ular_block_artificial_uses
);
4587 bitmap_clear (&eh_block_artificial_uses
);
4589 /* Verify entry block and exit block. These only verify the bitmaps,
4590 the refs are verified in df_bb_verify. */
4591 df_entry_block_bitmap_verify (true);
4592 df_exit_block_bitmap_verify (true);
4594 /* (3) All of the insns in all of the blocks are traversed and the
4595 marks are cleared both in the artificial refs attached to the
4596 blocks and the real refs inside the insns. It is a failure to
4597 clear a mark that has not been set as this means that the ref in
4598 the block or insn was not in the reg chain. */
4603 /* (4) See if all reg chains are traversed a second time. This time
4604 a check is made that the marks are clear. A set mark would be a
4605 from a reg that is not in any insn or basic block. */
4607 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4609 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4610 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4611 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));