1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999-2022 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"
35 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
38 #include "function-abi.h"
40 /* The set of hard registers in eliminables[i].from. */
42 static HARD_REG_SET elim_reg_set
;
44 /* Initialize ur_in and ur_out as if all hard registers were partially
47 class df_collection_rec
50 auto_vec
<df_ref
, 128> def_vec
;
51 auto_vec
<df_ref
, 32> use_vec
;
52 auto_vec
<df_ref
, 32> eq_use_vec
;
53 auto_vec
<df_mw_hardreg
*, 32> mw_vec
;
56 static void df_ref_record (enum df_ref_class
, class df_collection_rec
*,
58 basic_block
, struct df_insn_info
*,
59 enum df_ref_type
, int ref_flags
);
60 static void df_def_record_1 (class df_collection_rec
*, rtx
*,
61 basic_block
, struct df_insn_info
*,
63 static void df_defs_record (class df_collection_rec
*, rtx
,
64 basic_block
, struct df_insn_info
*,
66 static void df_uses_record (class df_collection_rec
*,
67 rtx
*, enum df_ref_type
,
68 basic_block
, struct df_insn_info
*,
71 static void df_install_ref_incremental (df_ref
);
72 static void df_insn_refs_collect (class df_collection_rec
*,
73 basic_block
, struct df_insn_info
*);
74 static void df_canonize_collection_rec (class df_collection_rec
*);
76 static void df_get_regular_block_artificial_uses (bitmap
);
77 static void df_get_eh_block_artificial_uses (bitmap
);
79 static void df_record_entry_block_defs (bitmap
);
80 static void df_record_exit_block_uses (bitmap
);
81 static void df_get_exit_block_use_set (bitmap
);
82 static void df_get_entry_block_def_set (bitmap
);
83 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
84 static void df_ref_chain_delete_du_chain (df_ref
);
85 static void df_ref_chain_delete (df_ref
);
87 static void df_refs_add_to_chains (class df_collection_rec
*,
88 basic_block
, rtx_insn
*, unsigned int);
90 static bool df_insn_refs_verify (class df_collection_rec
*, basic_block
,
92 static void df_entry_block_defs_collect (class df_collection_rec
*, bitmap
);
93 static void df_exit_block_uses_collect (class df_collection_rec
*, bitmap
);
94 static void df_install_ref (df_ref
, struct df_reg_info
*,
95 struct df_ref_info
*, bool);
97 static int df_ref_compare (df_ref
, df_ref
);
98 static int df_ref_ptr_compare (const void *, const void *);
99 static int df_mw_compare (const df_mw_hardreg
*, const df_mw_hardreg
*);
100 static int df_mw_ptr_compare (const void *, const void *);
102 static void df_insn_info_delete (unsigned int);
104 /* Indexed by hardware reg number, is true if that register is ever
105 used in the current function.
107 In df-scan.cc, this is set up to record the hard regs used
108 explicitly. Reload adds in the hard regs used for holding pseudo
109 regs. Final uses it to generate the code in the function prologue
110 and epilogue to save and restore registers as needed. */
112 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
114 /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
115 static const unsigned int copy_defs
= 0x1;
116 static const unsigned int copy_uses
= 0x2;
117 static const unsigned int copy_eq_uses
= 0x4;
118 static const unsigned int copy_mw
= 0x8;
119 static const unsigned int copy_all
= copy_defs
| copy_uses
| copy_eq_uses
122 /*----------------------------------------------------------------------------
123 SCANNING DATAFLOW PROBLEM
125 There are several ways in which scanning looks just like the other
126 dataflow problems. It shares the all the mechanisms for local info
127 as well as basic block info. Where it differs is when and how often
128 it gets run. It also has no need for the iterative solver.
129 ----------------------------------------------------------------------------*/
131 /* Problem data for the scanning dataflow function. */
132 struct df_scan_problem_data
134 object_allocator
<df_base_ref
> *ref_base_pool
;
135 object_allocator
<df_artificial_ref
> *ref_artificial_pool
;
136 object_allocator
<df_regular_ref
> *ref_regular_pool
;
137 object_allocator
<df_insn_info
> *insn_pool
;
138 object_allocator
<df_reg_info
> *reg_pool
;
139 object_allocator
<df_mw_hardreg
> *mw_reg_pool
;
141 bitmap_obstack reg_bitmaps
;
142 bitmap_obstack insn_bitmaps
;
145 /* Internal function to shut down the scanning problem. */
147 df_scan_free_internal (void)
149 struct df_scan_problem_data
*problem_data
150 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
152 free (df
->def_info
.refs
);
153 free (df
->def_info
.begin
);
154 free (df
->def_info
.count
);
155 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
157 free (df
->use_info
.refs
);
158 free (df
->use_info
.begin
);
159 free (df
->use_info
.count
);
160 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
166 free (df
->eq_use_regs
);
167 df
->eq_use_regs
= NULL
;
169 DF_REG_SIZE (df
) = 0;
175 free (df_scan
->block_info
);
176 df_scan
->block_info
= NULL
;
177 df_scan
->block_info_size
= 0;
179 bitmap_clear (&df
->hardware_regs_used
);
180 bitmap_clear (&df
->regular_block_artificial_uses
);
181 bitmap_clear (&df
->eh_block_artificial_uses
);
182 BITMAP_FREE (df
->entry_block_defs
);
183 BITMAP_FREE (df
->exit_block_uses
);
184 bitmap_clear (&df
->insns_to_delete
);
185 bitmap_clear (&df
->insns_to_rescan
);
186 bitmap_clear (&df
->insns_to_notes_rescan
);
188 delete problem_data
->ref_base_pool
;
189 delete problem_data
->ref_artificial_pool
;
190 delete problem_data
->ref_regular_pool
;
191 delete problem_data
->insn_pool
;
192 delete problem_data
->reg_pool
;
193 delete problem_data
->mw_reg_pool
;
194 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
195 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
196 free (df_scan
->problem_data
);
200 /* Free basic block info. */
203 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
205 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
206 unsigned int bb_index
= bb
->index
;
209 FOR_BB_INSNS (bb
, insn
)
211 df_insn_info_delete (INSN_UID (insn
));
213 if (bb_index
< df_scan
->block_info_size
)
214 bb_info
= df_scan_get_bb_info (bb_index
);
216 /* Get rid of any artificial uses or defs. */
217 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
218 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
219 df_ref_chain_delete (bb_info
->artificial_defs
);
220 df_ref_chain_delete (bb_info
->artificial_uses
);
221 bb_info
->artificial_defs
= NULL
;
222 bb_info
->artificial_uses
= NULL
;
226 /* Allocate the problem data for the scanning problem. This should be
227 called when the problem is created or when the entire function is to
230 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
232 struct df_scan_problem_data
*problem_data
;
235 /* Given the number of pools, this is really faster than tearing
237 if (df_scan
->problem_data
)
238 df_scan_free_internal ();
240 problem_data
= XNEW (struct df_scan_problem_data
);
241 df_scan
->problem_data
= problem_data
;
242 df_scan
->computed
= true;
244 problem_data
->ref_base_pool
= new object_allocator
<df_base_ref
>
245 ("df_scan ref base");
246 problem_data
->ref_artificial_pool
= new object_allocator
<df_artificial_ref
>
247 ("df_scan ref artificial");
248 problem_data
->ref_regular_pool
= new object_allocator
<df_regular_ref
>
249 ("df_scan ref regular");
250 problem_data
->insn_pool
= new object_allocator
<df_insn_info
>
252 problem_data
->reg_pool
= new object_allocator
<df_reg_info
>
254 problem_data
->mw_reg_pool
= new object_allocator
<df_mw_hardreg
>
257 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
258 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
262 df_grow_insn_info ();
263 df_grow_bb_info (df_scan
);
265 FOR_ALL_BB_FN (bb
, cfun
)
267 unsigned int bb_index
= bb
->index
;
268 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
269 bb_info
->artificial_defs
= NULL
;
270 bb_info
->artificial_uses
= NULL
;
273 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
274 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
275 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
276 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
277 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
278 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
279 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
280 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
281 df_scan
->optional_p
= false;
285 /* Free all of the data associated with the scan problem. */
290 if (df_scan
->problem_data
)
291 df_scan_free_internal ();
293 if (df
->blocks_to_analyze
)
295 BITMAP_FREE (df
->blocks_to_analyze
);
296 df
->blocks_to_analyze
= NULL
;
302 /* Dump the preamble for DF_SCAN dump. */
304 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
315 fprintf (file
, ";; fully invalidated by EH \t");
317 (file
, bitmap_view
<HARD_REG_SET
> (eh_edge_abi
.full_reg_clobbers ()));
318 fprintf (file
, ";; hardware regs used \t");
319 df_print_regset (file
, &df
->hardware_regs_used
);
320 fprintf (file
, ";; regular block artificial uses \t");
321 df_print_regset (file
, &df
->regular_block_artificial_uses
);
322 fprintf (file
, ";; eh block artificial uses \t");
323 df_print_regset (file
, &df
->eh_block_artificial_uses
);
324 fprintf (file
, ";; entry block defs \t");
325 df_print_regset (file
, df
->entry_block_defs
);
326 fprintf (file
, ";; exit block uses \t");
327 df_print_regset (file
, df
->exit_block_uses
);
328 fprintf (file
, ";; regs ever live \t");
329 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
330 if (df_regs_ever_live_p (i
))
331 fprintf (file
, " %d [%s]", i
, reg_names
[i
]);
332 fprintf (file
, "\n;; ref usage \t");
334 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
335 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
337 const char * sep
= "";
339 fprintf (file
, "r%d={", i
);
340 if (DF_REG_DEF_COUNT (i
))
342 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
344 dcount
+= DF_REG_DEF_COUNT (i
);
346 if (DF_REG_USE_COUNT (i
))
348 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
350 ucount
+= DF_REG_USE_COUNT (i
);
352 if (DF_REG_EQ_USE_COUNT (i
))
354 fprintf (file
, "%s%de", sep
, DF_REG_EQ_USE_COUNT (i
));
355 ecount
+= DF_REG_EQ_USE_COUNT (i
);
357 fprintf (file
, "} ");
360 FOR_EACH_BB_FN (bb
, cfun
)
361 FOR_BB_INSNS (bb
, insn
)
370 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de}"
371 " in %d{%d regular + %d call} insns.\n",
372 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
,
373 icount
+ ccount
, icount
, ccount
);
376 /* Dump the bb_info for a given basic block. */
378 df_scan_start_block (basic_block bb
, FILE *file
)
380 struct df_scan_bb_info
*bb_info
381 = df_scan_get_bb_info (bb
->index
);
385 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
386 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
387 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
388 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
389 fprintf (file
, "\n");
394 FOR_BB_INSNS (bb
, insn
)
396 df_insn_debug (insn
, false, file
);
401 static const struct df_problem problem_SCAN
=
403 DF_SCAN
, /* Problem id. */
404 DF_NONE
, /* Direction. */
405 df_scan_alloc
, /* Allocate the problem specific data. */
406 NULL
, /* Reset global information. */
407 df_scan_free_bb_info
, /* Free basic block info. */
408 NULL
, /* Local compute function. */
409 NULL
, /* Init the solution specific data. */
410 NULL
, /* Iterative solver. */
411 NULL
, /* Confluence operator 0. */
412 NULL
, /* Confluence operator n. */
413 NULL
, /* Transfer function. */
414 NULL
, /* Finalize function. */
415 df_scan_free
, /* Free all of the problem information. */
416 NULL
, /* Remove this problem from the stack of dataflow problems. */
417 df_scan_start_dump
, /* Debugging. */
418 df_scan_start_block
, /* Debugging start block. */
419 NULL
, /* Debugging end block. */
420 NULL
, /* Debugging start insn. */
421 NULL
, /* Debugging end insn. */
422 NULL
, /* Incremental solution verify start. */
423 NULL
, /* Incremental solution verify end. */
424 NULL
, /* Dependent problem. */
425 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
426 TV_DF_SCAN
, /* Timing variable. */
427 false /* Reset blocks on dropping out of blocks_to_analyze. */
431 /* Create a new DATAFLOW instance and add it to an existing instance
432 of DF. The returned structure is what is used to get at the
436 df_scan_add_problem (void)
438 df_add_problem (&problem_SCAN
);
442 /*----------------------------------------------------------------------------
443 Storage Allocation Utilities
444 ----------------------------------------------------------------------------*/
447 /* First, grow the reg_info information. If the current size is less than
448 the number of pseudos, grow to 25% more than the number of
451 Second, assure that all of the slots up to max_reg_num have been
452 filled with reg_info structures. */
455 df_grow_reg_info (void)
457 unsigned int max_reg
= max_reg_num ();
458 unsigned int new_size
= max_reg
;
459 struct df_scan_problem_data
*problem_data
460 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
463 if (df
->regs_size
< new_size
)
465 new_size
+= new_size
/ 4;
466 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
467 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
468 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
470 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
471 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
472 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
473 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
474 df
->regs_size
= new_size
;
477 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
479 struct df_reg_info
*reg_info
;
482 reg_info
= problem_data
->reg_pool
->allocate ();
483 memset (reg_info
, 0, sizeof (struct df_reg_info
));
484 df
->def_regs
[i
] = reg_info
;
485 reg_info
= problem_data
->reg_pool
->allocate ();
486 memset (reg_info
, 0, sizeof (struct df_reg_info
));
487 df
->use_regs
[i
] = reg_info
;
488 reg_info
= problem_data
->reg_pool
->allocate ();
489 memset (reg_info
, 0, sizeof (struct df_reg_info
));
490 df
->eq_use_regs
[i
] = reg_info
;
491 df
->def_info
.begin
[i
] = 0;
492 df
->def_info
.count
[i
] = 0;
493 df
->use_info
.begin
[i
] = 0;
494 df
->use_info
.count
[i
] = 0;
497 df
->regs_inited
= max_reg
;
501 /* Grow the ref information. */
504 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
506 if (ref_info
->refs_size
< new_size
)
508 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
509 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
510 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
511 ref_info
->refs_size
= new_size
;
516 /* Check and grow the ref information if necessary. This routine
517 guarantees total_size + BITMAP_ADDEND amount of entries in refs
518 array. It updates ref_info->refs_size only and does not change
519 ref_info->total_size. */
522 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
523 unsigned bitmap_addend
)
525 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
527 int new_size
= ref_info
->total_size
+ bitmap_addend
;
528 new_size
+= ref_info
->total_size
/ 4;
529 df_grow_ref_info (ref_info
, new_size
);
534 /* Grow the ref information. If the current size is less than the
535 number of instructions, grow to 25% more than the number of
539 df_grow_insn_info (void)
541 unsigned int new_size
= get_max_uid () + 1;
542 if (DF_INSN_SIZE () < new_size
)
544 new_size
+= new_size
/ 4;
545 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
546 memset (df
->insns
+ df
->insns_size
, 0,
547 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
548 DF_INSN_SIZE () = new_size
;
555 /*----------------------------------------------------------------------------
556 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
557 ----------------------------------------------------------------------------*/
559 /* Rescan all of the block_to_analyze or all of the blocks in the
560 function if df_set_blocks if blocks_to_analyze is NULL; */
563 df_scan_blocks (void)
567 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
568 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
570 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
571 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
573 bitmap_ior_into (&df
->eh_block_artificial_uses
,
574 &df
->regular_block_artificial_uses
);
576 /* ENTRY and EXIT blocks have special defs/uses. */
577 df_get_entry_block_def_set (df
->entry_block_defs
);
578 df_record_entry_block_defs (df
->entry_block_defs
);
579 df_get_exit_block_use_set (df
->exit_block_uses
);
580 df_record_exit_block_uses (df
->exit_block_uses
);
581 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
582 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
585 FOR_EACH_BB_FN (bb
, cfun
)
587 unsigned int bb_index
= bb
->index
;
588 df_bb_refs_record (bb_index
, true);
592 /* Create new refs under address LOC within INSN. This function is
593 only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
594 depending on whether LOC is inside PATTERN (INSN) or a note. */
597 df_uses_create (rtx
*loc
, rtx_insn
*insn
, int ref_flags
)
599 gcc_assert (!(ref_flags
& ~DF_REF_IN_NOTE
));
600 df_uses_record (NULL
, loc
, DF_REF_REG_USE
,
601 BLOCK_FOR_INSN (insn
),
602 DF_INSN_INFO_GET (insn
),
607 df_install_ref_incremental (df_ref ref
)
609 struct df_reg_info
**reg_info
;
610 struct df_ref_info
*ref_info
;
614 rtx_insn
*insn
= DF_REF_INSN (ref
);
615 basic_block bb
= BLOCK_FOR_INSN (insn
);
617 if (DF_REF_REG_DEF_P (ref
))
619 reg_info
= df
->def_regs
;
620 ref_info
= &df
->def_info
;
621 ref_ptr
= &DF_INSN_DEFS (insn
);
622 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
624 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
626 reg_info
= df
->eq_use_regs
;
627 ref_info
= &df
->use_info
;
628 ref_ptr
= &DF_INSN_EQ_USES (insn
);
629 switch (ref_info
->ref_order
)
631 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
632 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
633 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
637 add_to_table
= false;
643 reg_info
= df
->use_regs
;
644 ref_info
= &df
->use_info
;
645 ref_ptr
= &DF_INSN_USES (insn
);
646 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
649 /* Do not add if ref is not in the right blocks. */
650 if (add_to_table
&& df
->analyze_subset
)
651 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
653 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
656 switch (ref_info
->ref_order
)
658 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
659 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
660 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
661 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
664 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
668 while (*ref_ptr
&& df_ref_compare (*ref_ptr
, ref
) < 0)
669 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
671 DF_REF_NEXT_LOC (ref
) = *ref_ptr
;
677 fprintf (dump_file
, "adding ref ");
678 df_ref_debug (ref
, dump_file
);
681 /* By adding the ref directly, df_insn_rescan my not find any
682 differences even though the block will have changed. So we need
683 to mark the block dirty ourselves. */
684 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
685 df_set_bb_dirty (bb
);
690 /*----------------------------------------------------------------------------
691 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
692 ----------------------------------------------------------------------------*/
695 df_free_ref (df_ref ref
)
697 struct df_scan_problem_data
*problem_data
698 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
700 switch (DF_REF_CLASS (ref
))
703 problem_data
->ref_base_pool
->remove ((df_base_ref
*) (ref
));
706 case DF_REF_ARTIFICIAL
:
707 problem_data
->ref_artificial_pool
->remove
708 ((df_artificial_ref
*) (ref
));
712 problem_data
->ref_regular_pool
->remove
713 ((df_regular_ref
*) (ref
));
719 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
720 Also delete the def-use or use-def chain if it exists. */
723 df_reg_chain_unlink (df_ref ref
)
725 df_ref next
= DF_REF_NEXT_REG (ref
);
726 df_ref prev
= DF_REF_PREV_REG (ref
);
727 int id
= DF_REF_ID (ref
);
728 struct df_reg_info
*reg_info
;
731 if (DF_REF_REG_DEF_P (ref
))
733 int regno
= DF_REF_REGNO (ref
);
734 reg_info
= DF_REG_DEF_GET (regno
);
735 refs
= df
->def_info
.refs
;
739 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
741 reg_info
= DF_REG_EQ_USE_GET (DF_REF_REGNO (ref
));
742 switch (df
->use_info
.ref_order
)
744 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
745 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
746 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
747 refs
= df
->use_info
.refs
;
755 reg_info
= DF_REG_USE_GET (DF_REF_REGNO (ref
));
756 refs
= df
->use_info
.refs
;
762 if (df
->analyze_subset
)
764 if (bitmap_bit_p (df
->blocks_to_analyze
, DF_REF_BBNO (ref
)))
771 /* Delete any def-use or use-def chains that start here. It is
772 possible that there is trash in this field. This happens for
773 insns that have been deleted when rescanning has been deferred
774 and the chain problem has also been deleted. The chain tear down
775 code skips deleted insns. */
776 if (df_chain
&& DF_REF_CHAIN (ref
))
777 df_chain_unlink (ref
);
780 if (DF_REF_FLAGS_IS_SET (ref
, DF_HARD_REG_LIVE
))
782 gcc_assert (DF_REF_REGNO (ref
) < FIRST_PSEUDO_REGISTER
);
783 df
->hard_regs_live_count
[DF_REF_REGNO (ref
)]--;
786 /* Unlink from the reg chain. If there is no prev, this is the
787 first of the list. If not, just join the next and prev. */
789 DF_REF_NEXT_REG (prev
) = next
;
792 gcc_assert (reg_info
->reg_chain
== ref
);
793 reg_info
->reg_chain
= next
;
796 DF_REF_PREV_REG (next
) = prev
;
801 /* Initialize INSN_INFO to describe INSN. */
804 df_insn_info_init_fields (df_insn_info
*insn_info
, rtx_insn
*insn
)
806 memset (insn_info
, 0, sizeof (struct df_insn_info
));
807 insn_info
->insn
= insn
;
810 /* Create the insn record for INSN. If there was one there, zero it
813 struct df_insn_info
*
814 df_insn_create_insn_record (rtx_insn
*insn
)
816 struct df_scan_problem_data
*problem_data
817 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
818 struct df_insn_info
*insn_rec
;
820 df_grow_insn_info ();
821 insn_rec
= DF_INSN_INFO_GET (insn
);
824 insn_rec
= problem_data
->insn_pool
->allocate ();
825 DF_INSN_INFO_SET (insn
, insn_rec
);
827 df_insn_info_init_fields (insn_rec
, insn
);
832 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
835 df_ref_chain_delete_du_chain (df_ref ref
)
837 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
838 /* CHAIN is allocated by DF_CHAIN. So make sure to
839 pass df_scan instance for the problem. */
840 if (DF_REF_CHAIN (ref
))
841 df_chain_unlink (ref
);
845 /* Delete all refs in the ref chain. */
848 df_ref_chain_delete (df_ref ref
)
851 for (; ref
; ref
= next
)
853 next
= DF_REF_NEXT_LOC (ref
);
854 df_reg_chain_unlink (ref
);
859 /* Delete the hardreg chain. */
862 df_mw_hardreg_chain_delete (struct df_mw_hardreg
*hardregs
)
864 struct df_scan_problem_data
*problem_data
865 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
868 for (; hardregs
; hardregs
= next
)
870 next
= DF_MWS_NEXT (hardregs
);
871 problem_data
->mw_reg_pool
->remove (hardregs
);
875 /* Remove the contents of INSN_INFO (but don't free INSN_INFO itself). */
878 df_insn_info_free_fields (df_insn_info
*insn_info
)
880 /* In general, notes do not have the insn_info fields
881 initialized. However, combine deletes insns by changing them
882 to notes. How clever. So we cannot just check if it is a
883 valid insn before short circuiting this code, we need to see
884 if we actually initialized it. */
885 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
889 df_ref_chain_delete_du_chain (insn_info
->defs
);
890 df_ref_chain_delete_du_chain (insn_info
->uses
);
891 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
894 df_ref_chain_delete (insn_info
->defs
);
895 df_ref_chain_delete (insn_info
->uses
);
896 df_ref_chain_delete (insn_info
->eq_uses
);
899 /* Delete all of the refs information from the insn with UID.
900 Internal helper for df_insn_delete, df_insn_rescan, and other
901 df-scan routines that don't have to work in deferred mode
902 and do not have to mark basic blocks for re-processing. */
905 df_insn_info_delete (unsigned int uid
)
907 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
909 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
910 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
911 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
914 struct df_scan_problem_data
*problem_data
915 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
917 df_insn_info_free_fields (insn_info
);
918 problem_data
->insn_pool
->remove (insn_info
);
919 DF_INSN_UID_SET (uid
, NULL
);
923 /* Delete all of the refs information from INSN, either right now
924 or marked for later in deferred mode. */
927 df_insn_delete (rtx_insn
*insn
)
932 gcc_checking_assert (INSN_P (insn
));
937 uid
= INSN_UID (insn
);
938 bb
= BLOCK_FOR_INSN (insn
);
940 /* ??? bb can be NULL after pass_free_cfg. At that point, DF should
941 not exist anymore (as mentioned in df-core.cc: "The only requirement
942 [for DF] is that there be a correct control flow graph." Clearly
943 that isn't the case after pass_free_cfg. But DF is freed much later
944 because some back-ends want to use DF info even though the CFG is
945 already gone. It's not clear to me whether that is safe, actually.
946 In any case, we expect BB to be non-NULL at least up to register
947 allocation, so disallow a non-NULL BB up to there. Not perfect
948 but better than nothing... */
949 gcc_checking_assert (bb
!= NULL
|| reload_completed
);
951 df_grow_bb_info (df_scan
);
954 /* The block must be marked as dirty now, rather than later as in
955 df_insn_rescan and df_notes_rescan because it may not be there at
956 rescanning time and the mark would blow up.
957 DEBUG_INSNs do not make a block's data flow solution dirty (at
958 worst the LUIDs are no longer contiguous). */
959 if (bb
!= NULL
&& NONDEBUG_INSN_P (insn
))
960 df_set_bb_dirty (bb
);
962 /* The client has deferred rescanning. */
963 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
965 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
968 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
969 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
970 bitmap_set_bit (&df
->insns_to_delete
, uid
);
973 fprintf (dump_file
, "deferring deletion of insn with uid = %d.\n", uid
);
978 fprintf (dump_file
, "deleting insn with uid = %d.\n", uid
);
980 df_insn_info_delete (uid
);
984 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
987 df_free_collection_rec (class df_collection_rec
*collection_rec
)
990 struct df_scan_problem_data
*problem_data
991 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
993 struct df_mw_hardreg
*mw
;
995 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
997 FOR_EACH_VEC_ELT (collection_rec
->use_vec
, ix
, ref
)
999 FOR_EACH_VEC_ELT (collection_rec
->eq_use_vec
, ix
, ref
)
1001 FOR_EACH_VEC_ELT (collection_rec
->mw_vec
, ix
, mw
)
1002 problem_data
->mw_reg_pool
->remove (mw
);
1004 collection_rec
->def_vec
.release ();
1005 collection_rec
->use_vec
.release ();
1006 collection_rec
->eq_use_vec
.release ();
1007 collection_rec
->mw_vec
.release ();
1010 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1013 df_insn_rescan (rtx_insn
*insn
)
1015 unsigned int uid
= INSN_UID (insn
);
1016 struct df_insn_info
*insn_info
= NULL
;
1017 basic_block bb
= BLOCK_FOR_INSN (insn
);
1018 class df_collection_rec collection_rec
;
1020 if ((!df
) || (!INSN_P (insn
)))
1026 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1030 /* The client has disabled rescanning and plans to do it itself. */
1031 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1034 df_grow_bb_info (df_scan
);
1035 df_grow_reg_info ();
1037 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1039 /* The client has deferred rescanning. */
1040 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1044 insn_info
= df_insn_create_insn_record (insn
);
1045 insn_info
->defs
= 0;
1046 insn_info
->uses
= 0;
1047 insn_info
->eq_uses
= 0;
1048 insn_info
->mw_hardregs
= 0;
1051 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1053 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1054 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1055 bitmap_set_bit (&df
->insns_to_rescan
, INSN_UID (insn
));
1059 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1060 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1061 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1065 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1066 /* If there's no change, return false. */
1069 df_free_collection_rec (&collection_rec
);
1071 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1075 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1077 /* There's change - we need to delete the existing info.
1078 Since the insn isn't moved, we can salvage its LUID. */
1079 luid
= DF_INSN_LUID (insn
);
1080 df_insn_info_free_fields (insn_info
);
1081 df_insn_info_init_fields (insn_info
, insn
);
1082 DF_INSN_LUID (insn
) = luid
;
1086 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1087 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1089 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1092 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
1093 if (!DEBUG_INSN_P (insn
))
1094 df_set_bb_dirty (bb
);
1099 /* Same as df_insn_rescan, but don't mark the basic block as
1103 df_insn_rescan_debug_internal (rtx_insn
*insn
)
1105 unsigned int uid
= INSN_UID (insn
);
1106 struct df_insn_info
*insn_info
;
1108 gcc_assert (DEBUG_INSN_P (insn
)
1109 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn
)));
1114 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1119 fprintf (dump_file
, "deleting debug_insn with uid = %d.\n", uid
);
1121 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1122 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1123 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1125 if (insn_info
->defs
== 0
1126 && insn_info
->uses
== 0
1127 && insn_info
->eq_uses
== 0
1128 && insn_info
->mw_hardregs
== 0)
1131 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1135 df_ref_chain_delete_du_chain (insn_info
->defs
);
1136 df_ref_chain_delete_du_chain (insn_info
->uses
);
1137 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1140 df_ref_chain_delete (insn_info
->defs
);
1141 df_ref_chain_delete (insn_info
->uses
);
1142 df_ref_chain_delete (insn_info
->eq_uses
);
1144 insn_info
->defs
= 0;
1145 insn_info
->uses
= 0;
1146 insn_info
->eq_uses
= 0;
1147 insn_info
->mw_hardregs
= 0;
1153 /* Rescan all of the insns in the function. Note that the artificial
1154 uses and defs are not touched. This function will destroy def-use
1155 or use-def chains. */
1158 df_insn_rescan_all (void)
1160 bool no_insn_rescan
= false;
1161 bool defer_insn_rescan
= false;
1166 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1168 df_clear_flags (DF_NO_INSN_RESCAN
);
1169 no_insn_rescan
= true;
1172 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1174 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1175 defer_insn_rescan
= true;
1178 auto_bitmap
tmp (&df_bitmap_obstack
);
1179 bitmap_copy (tmp
, &df
->insns_to_delete
);
1180 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1182 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1184 df_insn_info_delete (uid
);
1187 bitmap_clear (&df
->insns_to_delete
);
1188 bitmap_clear (&df
->insns_to_rescan
);
1189 bitmap_clear (&df
->insns_to_notes_rescan
);
1191 FOR_EACH_BB_FN (bb
, cfun
)
1194 FOR_BB_INSNS (bb
, insn
)
1196 df_insn_rescan (insn
);
1201 df_set_flags (DF_NO_INSN_RESCAN
);
1202 if (defer_insn_rescan
)
1203 df_set_flags (DF_DEFER_INSN_RESCAN
);
1207 /* Process all of the deferred rescans or deletions. */
1210 df_process_deferred_rescans (void)
1212 bool no_insn_rescan
= false;
1213 bool defer_insn_rescan
= false;
1217 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1219 df_clear_flags (DF_NO_INSN_RESCAN
);
1220 no_insn_rescan
= true;
1223 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1225 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1226 defer_insn_rescan
= true;
1230 fprintf (dump_file
, "starting the processing of deferred insns\n");
1232 auto_bitmap
tmp (&df_bitmap_obstack
);
1233 bitmap_copy (tmp
, &df
->insns_to_delete
);
1234 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1236 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1238 df_insn_info_delete (uid
);
1241 bitmap_copy (tmp
, &df
->insns_to_rescan
);
1242 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1244 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1246 df_insn_rescan (insn_info
->insn
);
1249 bitmap_copy (tmp
, &df
->insns_to_notes_rescan
);
1250 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1252 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1254 df_notes_rescan (insn_info
->insn
);
1258 fprintf (dump_file
, "ending the processing of deferred insns\n");
1260 bitmap_clear (&df
->insns_to_delete
);
1261 bitmap_clear (&df
->insns_to_rescan
);
1262 bitmap_clear (&df
->insns_to_notes_rescan
);
1265 df_set_flags (DF_NO_INSN_RESCAN
);
1266 if (defer_insn_rescan
)
1267 df_set_flags (DF_DEFER_INSN_RESCAN
);
1269 /* If someone changed regs_ever_live during this pass, fix up the
1270 entry and exit blocks. */
1271 if (df
->redo_entry_and_exit
)
1273 df_update_entry_exit_and_calls ();
1274 df
->redo_entry_and_exit
= false;
1279 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1280 the uses if INCLUDE_USES. Include the eq_uses if
1284 df_count_refs (bool include_defs
, bool include_uses
,
1285 bool include_eq_uses
)
1289 unsigned int m
= df
->regs_inited
;
1291 for (regno
= 0; regno
< m
; regno
++)
1294 size
+= DF_REG_DEF_COUNT (regno
);
1296 size
+= DF_REG_USE_COUNT (regno
);
1297 if (include_eq_uses
)
1298 size
+= DF_REG_EQ_USE_COUNT (regno
);
1304 /* Take build ref table for either the uses or defs from the reg-use
1305 or reg-def chains. This version processes the refs in reg order
1306 which is likely to be best if processing the whole function. */
1309 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1312 bool include_eq_uses
)
1314 unsigned int m
= df
->regs_inited
;
1316 unsigned int offset
= 0;
1319 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1321 start
= FIRST_PSEUDO_REGISTER
;
1322 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1323 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1328 ref_info
->total_size
1329 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1331 df_check_and_grow_ref_info (ref_info
, 1);
1333 for (regno
= start
; regno
< m
; regno
++)
1336 ref_info
->begin
[regno
] = offset
;
1339 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1342 ref_info
->refs
[offset
] = ref
;
1343 DF_REF_ID (ref
) = offset
++;
1345 ref
= DF_REF_NEXT_REG (ref
);
1346 gcc_checking_assert (offset
< ref_info
->refs_size
);
1351 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1354 ref_info
->refs
[offset
] = ref
;
1355 DF_REF_ID (ref
) = offset
++;
1357 ref
= DF_REF_NEXT_REG (ref
);
1358 gcc_checking_assert (offset
< ref_info
->refs_size
);
1361 if (include_eq_uses
)
1363 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1366 ref_info
->refs
[offset
] = ref
;
1367 DF_REF_ID (ref
) = offset
++;
1369 ref
= DF_REF_NEXT_REG (ref
);
1370 gcc_checking_assert (offset
< ref_info
->refs_size
);
1373 ref_info
->count
[regno
] = count
;
1376 /* The bitmap size is not decremented when refs are deleted. So
1377 reset it now that we have squished out all of the empty
1379 ref_info
->table_size
= offset
;
1383 /* Take build ref table for either the uses or defs from the reg-use
1384 or reg-def chains. This version processes the refs in insn order
1385 which is likely to be best if processing some segment of the
1389 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1392 bool include_eq_uses
)
1395 unsigned int bb_index
;
1396 unsigned int m
= df
->regs_inited
;
1397 unsigned int offset
= 0;
1400 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1402 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1403 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1405 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1406 df_check_and_grow_ref_info (ref_info
, 1);
1408 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1410 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1415 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1417 unsigned int regno
= DF_REF_REGNO (def
);
1418 ref_info
->count
[regno
]++;
1421 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1423 unsigned int regno
= DF_REF_REGNO (use
);
1424 ref_info
->count
[regno
]++;
1427 FOR_BB_INSNS (bb
, insn
)
1431 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1434 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1436 unsigned int regno
= DF_REF_REGNO (def
);
1437 ref_info
->count
[regno
]++;
1440 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1442 unsigned int regno
= DF_REF_REGNO (use
);
1443 ref_info
->count
[regno
]++;
1445 if (include_eq_uses
)
1446 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1448 unsigned int regno
= DF_REF_REGNO (use
);
1449 ref_info
->count
[regno
]++;
1455 for (r
= start
; r
< m
; r
++)
1457 ref_info
->begin
[r
] = offset
;
1458 offset
+= ref_info
->count
[r
];
1459 ref_info
->count
[r
] = 0;
1462 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1464 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1469 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1471 unsigned int regno
= DF_REF_REGNO (def
);
1475 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1476 DF_REF_ID (def
) = id
;
1477 ref_info
->refs
[id
] = def
;
1481 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1483 unsigned int regno
= DF_REF_REGNO (def
);
1487 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1488 DF_REF_ID (use
) = id
;
1489 ref_info
->refs
[id
] = use
;
1493 FOR_BB_INSNS (bb
, insn
)
1497 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1500 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1502 unsigned int regno
= DF_REF_REGNO (def
);
1506 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1507 DF_REF_ID (def
) = id
;
1508 ref_info
->refs
[id
] = def
;
1512 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1514 unsigned int regno
= DF_REF_REGNO (use
);
1518 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1519 DF_REF_ID (use
) = id
;
1520 ref_info
->refs
[id
] = use
;
1523 if (include_eq_uses
)
1524 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1526 unsigned int regno
= DF_REF_REGNO (use
);
1530 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1531 DF_REF_ID (use
) = id
;
1532 ref_info
->refs
[id
] = use
;
1539 /* The bitmap size is not decremented when refs are deleted. So
1540 reset it now that we have squished out all of the empty
1543 ref_info
->table_size
= offset
;
1546 /* Take build ref table for either the uses or defs from the reg-use
1547 or reg-def chains. */
1550 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1553 bool include_eq_uses
)
1555 if (df
->analyze_subset
)
1556 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1557 include_uses
, include_eq_uses
);
1559 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1560 include_uses
, include_eq_uses
);
1564 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1566 df_add_refs_to_table (unsigned int offset
,
1567 struct df_ref_info
*ref_info
,
1570 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
1571 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
)
1572 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1574 ref_info
->refs
[offset
] = ref
;
1575 DF_REF_ID (ref
) = offset
++;
1581 /* Count the number of refs in all of the insns of BB. Include the
1582 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1583 eq_uses if INCLUDE_EQ_USES. */
1586 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1587 struct df_ref_info
*ref_info
,
1588 bool include_defs
, bool include_uses
,
1589 bool include_eq_uses
)
1594 offset
= df_add_refs_to_table (offset
, ref_info
,
1595 df_get_artificial_defs (bb
->index
));
1597 offset
= df_add_refs_to_table (offset
, ref_info
,
1598 df_get_artificial_uses (bb
->index
));
1600 FOR_BB_INSNS (bb
, insn
)
1603 unsigned int uid
= INSN_UID (insn
);
1605 offset
= df_add_refs_to_table (offset
, ref_info
,
1606 DF_INSN_UID_DEFS (uid
));
1608 offset
= df_add_refs_to_table (offset
, ref_info
,
1609 DF_INSN_UID_USES (uid
));
1610 if (include_eq_uses
)
1611 offset
= df_add_refs_to_table (offset
, ref_info
,
1612 DF_INSN_UID_EQ_USES (uid
));
1618 /* Organize the refs by insn into the table in REF_INFO. If
1619 blocks_to_analyze is defined, use that set, otherwise the entire
1620 program. Include the defs if INCLUDE_DEFS. Include the uses if
1621 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1624 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1625 bool include_defs
, bool include_uses
,
1626 bool include_eq_uses
)
1629 unsigned int offset
= 0;
1631 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1632 df_check_and_grow_ref_info (ref_info
, 1);
1633 if (df
->blocks_to_analyze
)
1638 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1640 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun
,
1643 include_defs
, include_uses
,
1647 ref_info
->table_size
= offset
;
1651 FOR_ALL_BB_FN (bb
, cfun
)
1652 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1653 include_defs
, include_uses
,
1655 ref_info
->table_size
= offset
;
1660 /* If the use refs in DF are not organized, reorganize them. */
1663 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1665 if (order
== df
->use_info
.ref_order
)
1670 case DF_REF_ORDER_BY_REG
:
1671 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1674 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1675 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1678 case DF_REF_ORDER_BY_INSN
:
1679 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1682 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1683 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1686 case DF_REF_ORDER_NO_TABLE
:
1687 free (df
->use_info
.refs
);
1688 df
->use_info
.refs
= NULL
;
1689 df
->use_info
.refs_size
= 0;
1692 case DF_REF_ORDER_UNORDERED
:
1693 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1698 df
->use_info
.ref_order
= order
;
1702 /* If the def refs in DF are not organized, reorganize them. */
1705 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1707 if (order
== df
->def_info
.ref_order
)
1712 case DF_REF_ORDER_BY_REG
:
1713 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1716 case DF_REF_ORDER_BY_INSN
:
1717 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1720 case DF_REF_ORDER_NO_TABLE
:
1721 free (df
->def_info
.refs
);
1722 df
->def_info
.refs
= NULL
;
1723 df
->def_info
.refs_size
= 0;
1726 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1727 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1728 case DF_REF_ORDER_UNORDERED
:
1729 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1734 df
->def_info
.ref_order
= order
;
1738 /* Change all of the basic block references in INSN to use the insn's
1739 current basic block. This function is called from routines that move
1740 instructions from one block to another. */
1743 df_insn_change_bb (rtx_insn
*insn
, basic_block new_bb
)
1745 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1746 struct df_insn_info
*insn_info
;
1747 unsigned int uid
= INSN_UID (insn
);
1749 if (old_bb
== new_bb
)
1752 set_block_for_insn (insn
, new_bb
);
1758 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1760 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1761 if (insn_info
== NULL
)
1764 fprintf (dump_file
, " unscanned insn\n");
1765 df_insn_rescan (insn
);
1772 if (!DEBUG_INSN_P (insn
))
1773 df_set_bb_dirty (new_bb
);
1777 fprintf (dump_file
, " from %d to %d\n",
1778 old_bb
->index
, new_bb
->index
);
1779 if (!DEBUG_INSN_P (insn
))
1780 df_set_bb_dirty (old_bb
);
1784 fprintf (dump_file
, " to %d\n", new_bb
->index
);
1788 /* Helper function for df_ref_change_reg_with_loc. */
1791 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
1792 struct df_reg_info
*new_df
,
1793 unsigned int new_regno
, rtx loc
)
1795 df_ref the_ref
= old_df
->reg_chain
;
1799 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
1800 && DF_REF_LOC (the_ref
)
1801 && (*DF_REF_LOC (the_ref
) == loc
))
1803 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
1804 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
1806 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
1808 DF_REF_REGNO (the_ref
) = new_regno
;
1809 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
1811 /* Pull the_ref out of the old regno chain. */
1813 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
1815 old_df
->reg_chain
= next_ref
;
1817 DF_REF_PREV_REG (next_ref
) = prev_ref
;
1820 /* Put the ref into the new regno chain. */
1821 DF_REF_PREV_REG (the_ref
) = NULL
;
1822 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
1823 if (new_df
->reg_chain
)
1824 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
1825 new_df
->reg_chain
= the_ref
;
1827 if (DF_REF_BB (the_ref
))
1828 df_set_bb_dirty (DF_REF_BB (the_ref
));
1830 /* Need to sort the record again that the ref was in because
1831 the regno is a sorting key. First, find the right
1833 if (DF_REF_REG_DEF_P (the_ref
))
1834 ref_ptr
= &insn_info
->defs
;
1835 else if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
1836 ref_ptr
= &insn_info
->eq_uses
;
1838 ref_ptr
= &insn_info
->uses
;
1840 fprintf (dump_file
, "changing reg in insn %d\n",
1841 DF_REF_INSN_UID (the_ref
));
1843 /* Stop if we find the current reference or where the reference
1845 while (*ref_ptr
!= the_ref
&& df_ref_compare (*ref_ptr
, the_ref
) < 0)
1846 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1847 if (*ref_ptr
!= the_ref
)
1849 /* The reference needs to be promoted up the list. */
1850 df_ref next
= DF_REF_NEXT_LOC (the_ref
);
1851 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1854 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1855 while (*ref_ptr
!= the_ref
);
1858 else if (DF_REF_NEXT_LOC (the_ref
)
1859 && df_ref_compare (the_ref
, DF_REF_NEXT_LOC (the_ref
)) > 0)
1861 /* The reference needs to be demoted down the list. */
1862 *ref_ptr
= DF_REF_NEXT_LOC (the_ref
);
1864 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1865 while (*ref_ptr
&& df_ref_compare (the_ref
, *ref_ptr
) > 0);
1866 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1873 the_ref
= DF_REF_NEXT_REG (the_ref
);
1878 /* Change the regno of register LOC to NEW_REGNO and update the df
1879 information accordingly. Refs that do not match LOC are not changed
1880 which means that artificial refs are not changed since they have no loc.
1881 This call is to support the SET_REGNO macro. */
1884 df_ref_change_reg_with_loc (rtx loc
, unsigned int new_regno
)
1886 unsigned int old_regno
= REGNO (loc
);
1887 if (old_regno
== new_regno
)
1892 df_grow_reg_info ();
1894 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
1895 DF_REG_DEF_GET (new_regno
),
1897 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
1898 DF_REG_USE_GET (new_regno
),
1900 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
1901 DF_REG_EQ_USE_GET (new_regno
),
1904 set_mode_and_regno (loc
, GET_MODE (loc
), new_regno
);
1908 /* Delete the mw_hardregs that point into the eq_notes. */
1911 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
1913 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
;
1914 struct df_scan_problem_data
*problem_data
1915 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1919 df_mw_hardreg
*mw
= *mw_ptr
;
1920 if (mw
->flags
& DF_REF_IN_NOTE
)
1922 *mw_ptr
= DF_MWS_NEXT (mw
);
1923 problem_data
->mw_reg_pool
->remove (mw
);
1926 mw_ptr
= &DF_MWS_NEXT (mw
);
1931 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
1934 df_notes_rescan (rtx_insn
*insn
)
1936 struct df_insn_info
*insn_info
;
1937 unsigned int uid
= INSN_UID (insn
);
1942 /* The client has disabled rescanning and plans to do it itself. */
1943 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1946 /* Do nothing if the insn hasn't been emitted yet. */
1947 if (!BLOCK_FOR_INSN (insn
))
1950 df_grow_bb_info (df_scan
);
1951 df_grow_reg_info ();
1953 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1955 /* The client has deferred rescanning. */
1956 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1960 insn_info
= df_insn_create_insn_record (insn
);
1961 insn_info
->defs
= 0;
1962 insn_info
->uses
= 0;
1963 insn_info
->eq_uses
= 0;
1964 insn_info
->mw_hardregs
= 0;
1967 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1968 /* If the insn is set to be rescanned, it does not need to also
1969 be notes rescanned. */
1970 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
1971 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
1975 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1976 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1980 basic_block bb
= BLOCK_FOR_INSN (insn
);
1982 class df_collection_rec collection_rec
;
1985 df_mw_hardreg_chain_delete_eq_uses (insn_info
);
1986 df_ref_chain_delete (insn_info
->eq_uses
);
1987 insn_info
->eq_uses
= NULL
;
1989 /* Process REG_EQUIV/REG_EQUAL notes */
1990 for (note
= REG_NOTES (insn
); note
;
1991 note
= XEXP (note
, 1))
1993 switch (REG_NOTE_KIND (note
))
1997 df_uses_record (&collection_rec
,
1998 &XEXP (note
, 0), DF_REF_REG_USE
,
1999 bb
, insn_info
, DF_REF_IN_NOTE
);
2005 /* Find some place to put any new mw_hardregs. */
2006 df_canonize_collection_rec (&collection_rec
);
2007 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
, *mw
;
2008 FOR_EACH_VEC_ELT (collection_rec
.mw_vec
, i
, mw
)
2010 while (*mw_ptr
&& df_mw_compare (*mw_ptr
, mw
) < 0)
2011 mw_ptr
= &DF_MWS_NEXT (*mw_ptr
);
2012 DF_MWS_NEXT (mw
) = *mw_ptr
;
2014 mw_ptr
= &DF_MWS_NEXT (mw
);
2016 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_eq_uses
);
2019 df_insn_rescan (insn
);
2024 /*----------------------------------------------------------------------------
2025 Hard core instruction scanning code. No external interfaces here,
2026 just a lot of routines that look inside insns.
2027 ----------------------------------------------------------------------------*/
2030 /* Return true if the contents of two df_ref's are identical.
2031 It ignores DF_REF_MARKER. */
2034 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2042 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2043 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2044 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2045 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2046 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2047 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2048 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2049 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2052 switch (DF_REF_CLASS (ref1
))
2054 case DF_REF_ARTIFICIAL
:
2058 case DF_REF_REGULAR
:
2059 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2067 /* Compare REF1 and REF2 for sorting. This is only called from places
2068 where all of the refs are of the same type, in the same insn, and
2069 have the same bb. So these fields are not checked. */
2072 df_ref_compare (df_ref ref1
, df_ref ref2
)
2074 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2075 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2077 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2078 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2080 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2081 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2083 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2084 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2086 /* Cannot look at the LOC field on artificial refs. */
2087 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2088 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2089 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2091 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2093 /* If two refs are identical except that one of them has is from
2094 a mw and one is not, we need to have the one with the mw
2096 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2097 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2098 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2099 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2105 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2108 /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2. */
2111 df_ref_ptr_compare (const void *r1
, const void *r2
)
2113 return df_ref_compare (*(const df_ref
*) r1
, *(const df_ref
*) r2
);
2116 /* Sort and compress a set of refs. */
2119 df_sort_and_compress_refs (vec
<df_ref
, va_heap
> *ref_vec
)
2123 unsigned int dist
= 0;
2125 count
= ref_vec
->length ();
2127 /* If there are 1 or 0 elements, there is nothing to do. */
2130 else if (count
== 2)
2132 df_ref r0
= (*ref_vec
)[0];
2133 df_ref r1
= (*ref_vec
)[1];
2134 if (df_ref_compare (r0
, r1
) > 0)
2135 std::swap ((*ref_vec
)[0], (*ref_vec
)[1]);
2139 for (i
= 0; i
< count
- 1; i
++)
2141 df_ref r0
= (*ref_vec
)[i
];
2142 df_ref r1
= (*ref_vec
)[i
+ 1];
2143 if (df_ref_compare (r0
, r1
) >= 0)
2146 /* If the array is already strictly ordered,
2147 which is the most common case for large COUNT case
2148 (which happens for CALL INSNs),
2149 no need to sort and filter out duplicate.
2150 Simply return the count.
2151 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2152 of DF_REF_COMPARE. */
2155 ref_vec
->qsort (df_ref_ptr_compare
);
2158 for (i
=0; i
<count
-dist
; i
++)
2160 /* Find the next ref that is not equal to the current ref. */
2161 while (i
+ dist
+ 1 < count
2162 && df_ref_equal_p ((*ref_vec
)[i
],
2163 (*ref_vec
)[i
+ dist
+ 1]))
2165 df_free_ref ((*ref_vec
)[i
+ dist
+ 1]);
2168 /* Copy it down to the next position. */
2169 if (dist
&& i
+ dist
+ 1 < count
)
2170 (*ref_vec
)[i
+ 1] = (*ref_vec
)[i
+ dist
+ 1];
2174 ref_vec
->truncate (count
);
2178 /* Return true if the contents of two df_ref's are identical.
2179 It ignores DF_REF_MARKER. */
2182 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2186 return (mw1
== mw2
) ||
2187 (mw1
->mw_reg
== mw2
->mw_reg
2188 && mw1
->type
== mw2
->type
2189 && mw1
->flags
== mw2
->flags
2190 && mw1
->start_regno
== mw2
->start_regno
2191 && mw1
->end_regno
== mw2
->end_regno
);
2195 /* Compare MW1 and MW2 for sorting. */
2198 df_mw_compare (const df_mw_hardreg
*mw1
, const df_mw_hardreg
*mw2
)
2200 if (mw1
->type
!= mw2
->type
)
2201 return mw1
->type
- mw2
->type
;
2203 if (mw1
->flags
!= mw2
->flags
)
2204 return mw1
->flags
- mw2
->flags
;
2206 if (mw1
->start_regno
!= mw2
->start_regno
)
2207 return mw1
->start_regno
- mw2
->start_regno
;
2209 if (mw1
->end_regno
!= mw2
->end_regno
)
2210 return mw1
->end_regno
- mw2
->end_regno
;
2212 return mw1
->mw_order
- mw2
->mw_order
;
2215 /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2. */
2218 df_mw_ptr_compare (const void *m1
, const void *m2
)
2220 return df_mw_compare (*(const df_mw_hardreg
*const *) m1
,
2221 *(const df_mw_hardreg
*const *) m2
);
2224 /* Sort and compress a set of refs. */
2227 df_sort_and_compress_mws (vec
<df_mw_hardreg
*, va_heap
> *mw_vec
)
2230 struct df_scan_problem_data
*problem_data
2231 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2233 unsigned int dist
= 0;
2235 count
= mw_vec
->length ();
2238 else if (count
== 2)
2240 struct df_mw_hardreg
*m0
= (*mw_vec
)[0];
2241 struct df_mw_hardreg
*m1
= (*mw_vec
)[1];
2242 if (df_mw_compare (m0
, m1
) > 0)
2244 struct df_mw_hardreg
*tmp
= (*mw_vec
)[0];
2245 (*mw_vec
)[0] = (*mw_vec
)[1];
2250 mw_vec
->qsort (df_mw_ptr_compare
);
2252 for (i
=0; i
<count
-dist
; i
++)
2254 /* Find the next ref that is not equal to the current ref. */
2255 while (i
+ dist
+ 1 < count
2256 && df_mw_equal_p ((*mw_vec
)[i
], (*mw_vec
)[i
+ dist
+ 1]))
2258 problem_data
->mw_reg_pool
->remove ((*mw_vec
)[i
+ dist
+ 1]);
2261 /* Copy it down to the next position. */
2262 if (dist
&& i
+ dist
+ 1 < count
)
2263 (*mw_vec
)[i
+ 1] = (*mw_vec
)[i
+ dist
+ 1];
2267 mw_vec
->truncate (count
);
2271 /* Sort and remove duplicates from the COLLECTION_REC. */
2274 df_canonize_collection_rec (class df_collection_rec
*collection_rec
)
2276 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2277 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2278 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2279 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2283 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2286 df_install_ref (df_ref this_ref
,
2287 struct df_reg_info
*reg_info
,
2288 struct df_ref_info
*ref_info
,
2291 unsigned int regno
= DF_REF_REGNO (this_ref
);
2292 /* Add the ref to the reg_{def,use,eq_use} chain. */
2293 df_ref head
= reg_info
->reg_chain
;
2295 reg_info
->reg_chain
= this_ref
;
2298 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2300 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2301 df
->hard_regs_live_count
[regno
]++;
2304 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2305 && DF_REF_PREV_REG (this_ref
) == NULL
);
2307 DF_REF_NEXT_REG (this_ref
) = head
;
2309 /* We cannot actually link to the head of the chain. */
2310 DF_REF_PREV_REG (this_ref
) = NULL
;
2313 DF_REF_PREV_REG (head
) = this_ref
;
2317 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2318 df_check_and_grow_ref_info (ref_info
, 1);
2319 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2320 /* Add the ref to the big array of defs. */
2321 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2322 ref_info
->table_size
++;
2325 DF_REF_ID (this_ref
) = -1;
2327 ref_info
->total_size
++;
2331 /* This function takes one of the groups of refs (defs, uses or
2332 eq_uses) and installs the entire group into the insn. It also adds
2333 each of these refs into the appropriate chains. */
2336 df_install_refs (basic_block bb
,
2337 const vec
<df_ref
, va_heap
> *old_vec
,
2338 struct df_reg_info
**reg_info
,
2339 struct df_ref_info
*ref_info
,
2342 unsigned int count
= old_vec
->length ();
2349 switch (ref_info
->ref_order
)
2351 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2352 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2353 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2354 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2355 add_to_table
= true;
2357 case DF_REF_ORDER_UNORDERED
:
2358 case DF_REF_ORDER_BY_REG
:
2359 case DF_REF_ORDER_BY_INSN
:
2360 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2361 add_to_table
= !is_notes
;
2364 add_to_table
= false;
2368 /* Do not add if ref is not in the right blocks. */
2369 if (add_to_table
&& df
->analyze_subset
)
2370 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2372 FOR_EACH_VEC_ELT (*old_vec
, ix
, this_ref
)
2374 DF_REF_NEXT_LOC (this_ref
) = (ix
+ 1 < old_vec
->length ()
2375 ? (*old_vec
)[ix
+ 1]
2377 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2378 ref_info
, add_to_table
);
2380 return (*old_vec
)[0];
2387 /* This function takes the mws installs the entire group into the
2390 static struct df_mw_hardreg
*
2391 df_install_mws (const vec
<df_mw_hardreg
*, va_heap
> *old_vec
)
2393 unsigned int count
= old_vec
->length ();
2396 for (unsigned int i
= 0; i
< count
- 1; i
++)
2397 DF_MWS_NEXT ((*old_vec
)[i
]) = (*old_vec
)[i
+ 1];
2398 DF_MWS_NEXT ((*old_vec
)[count
- 1]) = 0;
2399 return (*old_vec
)[0];
2406 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2407 chains and update other necessary information. */
2410 df_refs_add_to_chains (class df_collection_rec
*collection_rec
,
2411 basic_block bb
, rtx_insn
*insn
, unsigned int flags
)
2415 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2416 /* If there is a vector in the collection rec, add it to the
2417 insn. A null rec is a signal that the caller will handle the
2419 if (flags
& copy_defs
)
2421 gcc_checking_assert (!insn_rec
->defs
);
2423 = df_install_refs (bb
, &collection_rec
->def_vec
,
2425 &df
->def_info
, false);
2427 if (flags
& copy_uses
)
2429 gcc_checking_assert (!insn_rec
->uses
);
2431 = df_install_refs (bb
, &collection_rec
->use_vec
,
2433 &df
->use_info
, false);
2435 if (flags
& copy_eq_uses
)
2437 gcc_checking_assert (!insn_rec
->eq_uses
);
2439 = df_install_refs (bb
, &collection_rec
->eq_use_vec
,
2441 &df
->use_info
, true);
2443 if (flags
& copy_mw
)
2445 gcc_checking_assert (!insn_rec
->mw_hardregs
);
2446 insn_rec
->mw_hardregs
2447 = df_install_mws (&collection_rec
->mw_vec
);
2452 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2454 gcc_checking_assert (!bb_info
->artificial_defs
);
2455 bb_info
->artificial_defs
2456 = df_install_refs (bb
, &collection_rec
->def_vec
,
2458 &df
->def_info
, false);
2459 gcc_checking_assert (!bb_info
->artificial_uses
);
2460 bb_info
->artificial_uses
2461 = df_install_refs (bb
, &collection_rec
->use_vec
,
2463 &df
->use_info
, false);
2468 /* Allocate a ref and initialize its fields. */
2471 df_ref_create_structure (enum df_ref_class cl
,
2472 class df_collection_rec
*collection_rec
,
2474 basic_block bb
, struct df_insn_info
*info
,
2475 enum df_ref_type ref_type
,
2478 df_ref this_ref
= NULL
;
2479 unsigned int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2480 struct df_scan_problem_data
*problem_data
2481 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2486 this_ref
= (df_ref
) (problem_data
->ref_base_pool
->allocate ());
2487 gcc_checking_assert (loc
== NULL
);
2490 case DF_REF_ARTIFICIAL
:
2491 this_ref
= (df_ref
) (problem_data
->ref_artificial_pool
->allocate ());
2492 this_ref
->artificial_ref
.bb
= bb
;
2493 gcc_checking_assert (loc
== NULL
);
2496 case DF_REF_REGULAR
:
2497 this_ref
= (df_ref
) (problem_data
->ref_regular_pool
->allocate ());
2498 this_ref
->regular_ref
.loc
= loc
;
2499 gcc_checking_assert (loc
);
2503 DF_REF_CLASS (this_ref
) = cl
;
2504 DF_REF_ID (this_ref
) = -1;
2505 DF_REF_REG (this_ref
) = reg
;
2506 DF_REF_REGNO (this_ref
) = regno
;
2507 DF_REF_TYPE (this_ref
) = ref_type
;
2508 DF_REF_INSN_INFO (this_ref
) = info
;
2509 DF_REF_CHAIN (this_ref
) = NULL
;
2510 DF_REF_FLAGS (this_ref
) = ref_flags
;
2511 DF_REF_NEXT_REG (this_ref
) = NULL
;
2512 DF_REF_PREV_REG (this_ref
) = NULL
;
2513 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2515 /* We need to clear this bit because fwprop, and in the future
2516 possibly other optimizations sometimes create new refs using ond
2517 refs as the model. */
2518 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2520 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2521 if (regno
< FIRST_PSEUDO_REGISTER
2522 && !DF_REF_IS_ARTIFICIAL (this_ref
)
2523 && !DEBUG_INSN_P (DF_REF_INSN (this_ref
)))
2525 if (DF_REF_REG_DEF_P (this_ref
))
2527 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2528 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2530 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2531 && (regno
== FRAME_POINTER_REGNUM
2532 || regno
== ARG_POINTER_REGNUM
)))
2533 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2538 if (DF_REF_REG_DEF_P (this_ref
))
2539 collection_rec
->def_vec
.safe_push (this_ref
);
2540 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2541 collection_rec
->eq_use_vec
.safe_push (this_ref
);
2543 collection_rec
->use_vec
.safe_push (this_ref
);
2546 df_install_ref_incremental (this_ref
);
2552 /* Create new references of type DF_REF_TYPE for each part of register REG
2553 at address LOC within INSN of BB. */
2557 df_ref_record (enum df_ref_class cl
,
2558 class df_collection_rec
*collection_rec
,
2560 basic_block bb
, struct df_insn_info
*insn_info
,
2561 enum df_ref_type ref_type
,
2566 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2568 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2569 if (regno
< FIRST_PSEUDO_REGISTER
)
2571 struct df_mw_hardreg
*hardreg
= NULL
;
2572 struct df_scan_problem_data
*problem_data
2573 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2575 unsigned int endregno
;
2578 if (GET_CODE (reg
) == SUBREG
)
2580 int off
= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2581 SUBREG_BYTE (reg
), GET_MODE (reg
));
2582 unsigned int nregno
= regno
+ off
;
2583 endregno
= nregno
+ subreg_nregs (reg
);
2584 if (off
< 0 && regno
< (unsigned) -off
)
2585 /* Deal with paradoxical SUBREGs on big endian where
2586 in debug insns the hard reg number might be smaller
2587 than -off, such as (subreg:DI (reg:SI 0 [+4 ]) 0));
2588 RA decisions shouldn't be affected by debug insns
2589 and so RA can decide to put pseudo into a hard reg
2590 with small REGNO, even when it is referenced in
2591 a paradoxical SUBREG in a debug insn. */
2597 endregno
= END_REGNO (reg
);
2599 /* If this is a multiword hardreg, we create some extra
2600 datastructures that will enable us to easily build REG_DEAD
2601 and REG_UNUSED notes. */
2603 && (endregno
!= regno
+ 1) && insn_info
)
2605 /* Sets to a subreg of a multiword register are partial.
2606 Sets to a non-subreg of a multiword register are not. */
2607 if (GET_CODE (reg
) == SUBREG
)
2608 ref_flags
|= DF_REF_PARTIAL
;
2609 ref_flags
|= DF_REF_MW_HARDREG
;
2611 gcc_assert (regno
< endregno
);
2613 hardreg
= problem_data
->mw_reg_pool
->allocate ();
2614 hardreg
->type
= ref_type
;
2615 hardreg
->flags
= ref_flags
;
2616 hardreg
->mw_reg
= reg
;
2617 hardreg
->start_regno
= regno
;
2618 hardreg
->end_regno
= endregno
- 1;
2619 hardreg
->mw_order
= df
->ref_order
++;
2620 collection_rec
->mw_vec
.safe_push (hardreg
);
2623 for (i
= regno
; i
< endregno
; i
++)
2625 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2626 bb
, insn_info
, ref_type
, ref_flags
);
2628 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2633 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2634 ref_type
, ref_flags
);
2639 /* Process all the registers defined in the rtx pointed by LOC.
2640 Autoincrement/decrement definitions will be picked up by df_uses_record.
2641 Any change here has to be matched in df_find_hard_reg_defs_1. */
2644 df_def_record_1 (class df_collection_rec
*collection_rec
,
2645 rtx
*loc
, basic_block bb
, struct df_insn_info
*insn_info
,
2650 /* It is legal to have a set destination be a parallel. */
2651 if (GET_CODE (dst
) == PARALLEL
)
2654 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2656 rtx temp
= XVECEXP (dst
, 0, i
);
2657 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2658 df_def_record_1 (collection_rec
, &XEXP (temp
, 0),
2659 bb
, insn_info
, flags
);
2664 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2666 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2668 loc
= &XEXP (dst
, 0);
2672 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2674 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2676 loc
= &XEXP (dst
, 0);
2680 /* At this point if we do not have a reg or a subreg, just return. */
2683 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2684 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2686 /* We want to keep sp alive everywhere - by making all
2687 writes to sp also use of sp. */
2688 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2689 df_ref_record (DF_REF_BASE
, collection_rec
,
2690 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
2692 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2694 if (read_modify_subreg_p (dst
))
2695 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2697 flags
|= DF_REF_SUBREG
;
2699 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2700 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2705 /* Process all the registers defined in the pattern rtx, X. Any change
2706 here has to be matched in df_find_hard_reg_defs. */
2709 df_defs_record (class df_collection_rec
*collection_rec
,
2710 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2713 RTX_CODE code
= GET_CODE (x
);
2719 df_def_record_1 (collection_rec
, &SET_DEST (x
), bb
, insn_info
, flags
);
2723 flags
|= DF_REF_MUST_CLOBBER
;
2724 df_def_record_1 (collection_rec
, &XEXP (x
, 0), bb
, insn_info
, flags
);
2728 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
2729 bb
, insn_info
, DF_REF_CONDITIONAL
);
2733 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2734 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
),
2735 bb
, insn_info
, flags
);
2738 /* No DEFs to record in other cases */
2743 /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
2744 destination of a set or clobber. This has to match the logic in
2745 df_defs_record_1. */
2748 df_find_hard_reg_defs_1 (rtx dst
, HARD_REG_SET
*defs
)
2750 /* It is legal to have a set destination be a parallel. */
2751 if (GET_CODE (dst
) == PARALLEL
)
2754 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2756 rtx temp
= XVECEXP (dst
, 0, i
);
2757 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2758 df_find_hard_reg_defs_1 (XEXP (temp
, 0), defs
);
2763 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2764 dst
= XEXP (dst
, 0);
2766 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2767 dst
= XEXP (dst
, 0);
2769 /* At this point if we do not have a reg or a subreg, just return. */
2770 if (REG_P (dst
) && HARD_REGISTER_P (dst
))
2771 SET_HARD_REG_BIT (*defs
, REGNO (dst
));
2772 else if (GET_CODE (dst
) == SUBREG
2773 && REG_P (SUBREG_REG (dst
)) && HARD_REGISTER_P (dst
))
2774 SET_HARD_REG_BIT (*defs
, REGNO (SUBREG_REG (dst
)));
2777 /* Set bits in *DEFS for hard registers defined in the pattern X. This
2778 has to match the logic in df_defs_record. */
2781 df_find_hard_reg_defs (rtx x
, HARD_REG_SET
*defs
)
2783 RTX_CODE code
= GET_CODE (x
);
2789 df_find_hard_reg_defs_1 (SET_DEST (x
), defs
);
2793 df_find_hard_reg_defs_1 (XEXP (x
, 0), defs
);
2797 df_find_hard_reg_defs (COND_EXEC_CODE (x
), defs
);
2801 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2802 df_find_hard_reg_defs (XVECEXP (x
, 0, i
), defs
);
2805 /* No DEFs to record in other cases */
2811 /* Process all the registers used in the rtx at address LOC. */
2814 df_uses_record (class df_collection_rec
*collection_rec
,
2815 rtx
*loc
, enum df_ref_type ref_type
,
2816 basic_block bb
, struct df_insn_info
*insn_info
,
2826 code
= GET_CODE (x
);
2839 /* If we are clobbering a MEM, mark any registers inside the address
2841 if (MEM_P (XEXP (x
, 0)))
2842 df_uses_record (collection_rec
,
2843 &XEXP (XEXP (x
, 0), 0),
2844 DF_REF_REG_MEM_STORE
,
2848 /* If we're clobbering a REG then we have a def so ignore. */
2852 df_uses_record (collection_rec
,
2853 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
2854 bb
, insn_info
, flags
& DF_REF_IN_NOTE
);
2858 /* While we're here, optimize this case. */
2859 flags
|= DF_REF_PARTIAL
;
2860 /* In case the SUBREG is not of a REG, do not optimize. */
2861 if (!REG_P (SUBREG_REG (x
)))
2863 loc
= &SUBREG_REG (x
);
2864 df_uses_record (collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
);
2870 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2871 x
, loc
, bb
, insn_info
,
2878 df_uses_record (collection_rec
,
2879 &XEXP (x
, 1), ref_type
, bb
, insn_info
, flags
);
2880 df_uses_record (collection_rec
,
2881 &XEXP (x
, 2), ref_type
, bb
, insn_info
, flags
);
2883 /* If the parameters to the zero or sign extract are
2884 constants, strip them off and recurse, otherwise there is
2885 no information that we can gain from this operation. */
2886 if (code
== ZERO_EXTRACT
)
2887 flags
|= DF_REF_ZERO_EXTRACT
;
2889 flags
|= DF_REF_SIGN_EXTRACT
;
2891 df_uses_record (collection_rec
,
2892 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
);
2899 rtx dst
= SET_DEST (x
);
2900 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
2901 df_uses_record (collection_rec
,
2902 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
);
2904 switch (GET_CODE (dst
))
2907 if (read_modify_subreg_p (dst
))
2909 df_uses_record (collection_rec
, &SUBREG_REG (dst
),
2910 DF_REF_REG_USE
, bb
, insn_info
,
2911 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
);
2921 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2922 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
);
2924 case STRICT_LOW_PART
:
2926 rtx
*temp
= &XEXP (dst
, 0);
2927 /* A strict_low_part uses the whole REG and not just the
2929 dst
= XEXP (dst
, 0);
2930 df_uses_record (collection_rec
,
2931 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
2932 DF_REF_REG_USE
, bb
, insn_info
,
2933 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
);
2938 df_uses_record (collection_rec
, &XEXP (dst
, 1),
2939 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2940 df_uses_record (collection_rec
, &XEXP (dst
, 2),
2941 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2942 if (GET_CODE (XEXP (dst
,0)) == MEM
)
2943 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2944 DF_REF_REG_USE
, bb
, insn_info
,
2947 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2948 DF_REF_REG_USE
, bb
, insn_info
,
2949 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
);
2964 case UNSPEC_VOLATILE
:
2968 /* Traditional and volatile asm instructions must be
2969 considered to use and clobber all hard registers, all
2970 pseudo-registers and all of memory. So must TRAP_IF and
2971 UNSPEC_VOLATILE operations.
2973 Consider for instance a volatile asm that changes the fpu
2974 rounding mode. An insn should not be moved across this
2975 even if it only uses pseudo-regs because it might give an
2976 incorrectly rounded result.
2978 However, flow.c's liveness computation did *not* do this,
2979 giving the reasoning as " ?!? Unfortunately, marking all
2980 hard registers as live causes massive problems for the
2981 register allocator and marking all pseudos as live creates
2982 mountains of uninitialized variable warnings."
2984 In order to maintain the status quo with regard to liveness
2985 and uses, we do what flow.c did and just mark any regs we
2986 can find in ASM_OPERANDS as used. In global asm insns are
2987 scanned and regs_asm_clobbered is filled out.
2989 For all ASM_OPERANDS, we must traverse the vector of input
2990 operands. We cannot just fall through here since then we
2991 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
2992 which do not indicate traditional asms unlike their normal
2994 if (code
== ASM_OPERANDS
)
2998 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
2999 df_uses_record (collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3000 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3007 df_uses_record (collection_rec
,
3008 &PAT_VAR_LOCATION_LOC (x
),
3009 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3018 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3019 /* Catch the def of the register being modified. */
3020 df_ref_record (DF_REF_REGULAR
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3023 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
);
3025 /* ... Fall through to handle uses ... */
3031 /* Recursively scan the operands of this expression. */
3033 const char *fmt
= GET_RTX_FORMAT (code
);
3036 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3040 /* Tail recursive case: save a function call level. */
3046 df_uses_record (collection_rec
, &XEXP (x
, i
), ref_type
,
3047 bb
, insn_info
, flags
);
3049 else if (fmt
[i
] == 'E')
3052 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3053 df_uses_record (collection_rec
,
3054 &XVECEXP (x
, i
, j
), ref_type
,
3055 bb
, insn_info
, flags
);
3064 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3067 df_get_conditional_uses (class df_collection_rec
*collection_rec
)
3072 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
3074 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3078 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3079 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3080 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3081 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
);
3082 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3088 /* Get call's extra defs and uses (track caller-saved registers). */
3091 df_get_call_refs (class df_collection_rec
*collection_rec
,
3093 struct df_insn_info
*insn_info
,
3097 bool is_sibling_call
;
3099 HARD_REG_SET defs_generated
;
3101 CLEAR_HARD_REG_SET (defs_generated
);
3102 df_find_hard_reg_defs (PATTERN (insn_info
->insn
), &defs_generated
);
3103 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3104 function_abi callee_abi
= insn_callee_abi (insn_info
->insn
);
3106 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3108 if (i
== STACK_POINTER_REGNUM
3109 && !FAKE_CALL_P (insn_info
->insn
))
3110 /* The stack ptr is used (honorarily) by a CALL insn. */
3111 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3112 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3113 DF_REF_CALL_STACK_USAGE
| flags
);
3114 else if (global_regs
[i
])
3116 /* Calls to const functions cannot access any global registers and
3117 calls to pure functions cannot set them. All other calls may
3118 reference any of the global registers, so they are recorded as
3120 if (!RTL_CONST_CALL_P (insn_info
->insn
))
3122 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3123 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
3124 if (!RTL_PURE_CALL_P (insn_info
->insn
))
3125 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3126 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3129 else if (callee_abi
.clobbers_full_reg_p (i
)
3130 /* no clobbers for regs that are the result of the call */
3131 && !TEST_HARD_REG_BIT (defs_generated
, i
)
3132 && (!is_sibling_call
3133 || !bitmap_bit_p (df
->exit_block_uses
, i
)
3134 || refers_to_regno_p (i
, crtl
->return_rtx
)))
3135 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3136 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3137 DF_REF_MAY_CLOBBER
| flags
);
3140 /* Record the registers used to pass arguments, and explicitly
3141 noted as clobbered. */
3142 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3143 note
= XEXP (note
, 1))
3145 if (GET_CODE (XEXP (note
, 0)) == USE
)
3146 df_uses_record (collection_rec
, &XEXP (XEXP (note
, 0), 0),
3147 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3148 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3150 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3152 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3153 if (!TEST_HARD_REG_BIT (defs_generated
, regno
))
3154 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3158 df_uses_record (collection_rec
, &XEXP (note
, 0),
3159 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3166 /* Collect all refs in the INSN. This function is free of any
3167 side-effect - it will create and return a lists of df_ref's in the
3168 COLLECTION_REC without putting those refs into existing ref chains
3172 df_insn_refs_collect (class df_collection_rec
*collection_rec
,
3173 basic_block bb
, struct df_insn_info
*insn_info
)
3176 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3178 /* Clear out the collection record. */
3179 collection_rec
->def_vec
.truncate (0);
3180 collection_rec
->use_vec
.truncate (0);
3181 collection_rec
->eq_use_vec
.truncate (0);
3182 collection_rec
->mw_vec
.truncate (0);
3184 /* Process REG_EQUIV/REG_EQUAL notes. */
3185 for (note
= REG_NOTES (insn_info
->insn
); note
;
3186 note
= XEXP (note
, 1))
3188 switch (REG_NOTE_KIND (note
))
3192 df_uses_record (collection_rec
,
3193 &XEXP (note
, 0), DF_REF_REG_USE
,
3194 bb
, insn_info
, DF_REF_IN_NOTE
);
3196 case REG_NON_LOCAL_GOTO
:
3197 /* The frame ptr is used by a non-local goto. */
3198 df_ref_record (DF_REF_BASE
, collection_rec
,
3199 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3200 NULL
, bb
, insn_info
,
3202 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3203 df_ref_record (DF_REF_BASE
, collection_rec
,
3204 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3205 NULL
, bb
, insn_info
,
3213 int flags
= (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0;
3214 /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
3215 uses from CALL_INSN_FUNCTION_USAGE. */
3216 if (CALL_P (insn_info
->insn
))
3217 df_get_call_refs (collection_rec
, bb
, insn_info
, flags
);
3219 /* Record other defs. These should be mostly for DF_REF_REGULAR, so
3220 that a qsort on the defs is unnecessary in most cases. */
3221 df_defs_record (collection_rec
,
3222 PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3224 /* Record the register uses. */
3225 df_uses_record (collection_rec
,
3226 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0);
3228 /* DF_REF_CONDITIONAL needs corresponding USES. */
3230 df_get_conditional_uses (collection_rec
);
3232 df_canonize_collection_rec (collection_rec
);
3235 /* Recompute the luids for the insns in BB. */
3238 df_recompute_luids (basic_block bb
)
3243 df_grow_insn_info ();
3245 /* Scan the block an insn at a time from beginning to end. */
3246 FOR_BB_INSNS (bb
, insn
)
3248 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3249 /* Inserting labels does not always trigger the incremental
3253 gcc_assert (!INSN_P (insn
));
3254 insn_info
= df_insn_create_insn_record (insn
);
3257 DF_INSN_INFO_LUID (insn_info
) = luid
;
3264 /* Collect all artificial refs at the block level for BB and add them
3265 to COLLECTION_REC. */
3268 df_bb_refs_collect (class df_collection_rec
*collection_rec
, basic_block bb
)
3270 collection_rec
->def_vec
.truncate (0);
3271 collection_rec
->use_vec
.truncate (0);
3272 collection_rec
->eq_use_vec
.truncate (0);
3273 collection_rec
->mw_vec
.truncate (0);
3275 if (bb
->index
== ENTRY_BLOCK
)
3277 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3280 else if (bb
->index
== EXIT_BLOCK
)
3282 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3286 if (bb_has_eh_pred (bb
))
3289 /* Mark the registers that will contain data for the handler. */
3292 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3293 if (regno
== INVALID_REGNUM
)
3295 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3296 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3300 /* Add the hard_frame_pointer if this block is the target of a
3302 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3303 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3304 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3306 /* Add the artificial uses. */
3307 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3311 bitmap au
= bb_has_eh_pred (bb
)
3312 ? &df
->eh_block_artificial_uses
3313 : &df
->regular_block_artificial_uses
;
3315 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3317 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3318 bb
, NULL
, DF_REF_REG_USE
, 0);
3322 df_canonize_collection_rec (collection_rec
);
3326 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3329 df_bb_refs_record (int bb_index
, bool scan_insns
)
3331 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3338 df_collection_rec collection_rec
;
3339 df_grow_bb_info (df_scan
);
3341 /* Scan the block an insn at a time from beginning to end. */
3342 FOR_BB_INSNS (bb
, insn
)
3344 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3345 gcc_assert (!insn_info
);
3347 insn_info
= df_insn_create_insn_record (insn
);
3350 /* Record refs within INSN. */
3351 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3352 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3353 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
3355 DF_INSN_INFO_LUID (insn_info
) = luid
;
3358 /* Other block level artificial refs */
3359 df_bb_refs_collect (&collection_rec
, bb
);
3360 df_refs_add_to_chains (&collection_rec
, bb
, NULL
, copy_all
);
3362 /* Now that the block has been processed, set the block as dirty so
3363 LR and LIVE will get it processed. */
3364 df_set_bb_dirty (bb
);
3368 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3372 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3378 bitmap_clear (regular_block_artificial_uses
);
3380 if (reload_completed
)
3382 if (frame_pointer_needed
)
3383 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3386 /* Before reload, there are a few registers that must be forced
3387 live everywhere -- which might not already be the case for
3388 blocks within infinite loops. */
3390 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3392 /* Any reference to any pseudo before reload is a potential
3393 reference of the frame pointer. */
3394 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3396 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3397 bitmap_set_bit (regular_block_artificial_uses
,
3398 HARD_FRAME_POINTER_REGNUM
);
3400 /* Pseudos with argument area equivalences may require
3401 reloading via the argument pointer. */
3402 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3403 && fixed_regs
[ARG_POINTER_REGNUM
])
3404 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3406 /* Any constant, or pseudo with constant equivalences, may
3407 require reloading from memory using the pic register. */
3408 if (picreg
!= INVALID_REGNUM
3409 && fixed_regs
[picreg
])
3410 bitmap_set_bit (regular_block_artificial_uses
, picreg
);
3412 /* The all-important stack pointer must always be live. */
3413 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3416 /* EH_USES registers are used:
3417 1) at all insns that might throw (calls or with -fnon-call-exceptions
3420 3) to support backtraces and/or debugging, anywhere between their
3421 initialization and where they the saved registers are restored
3422 from them, including the cases where we don't reach the epilogue
3423 (noreturn call or infinite loop). */
3424 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3426 bitmap_set_bit (regular_block_artificial_uses
, i
);
3431 /* Get the artificial use set for an eh block. */
3434 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3436 bitmap_clear (eh_block_artificial_uses
);
3438 /* The following code (down through the arg_pointer setting APPEARS
3439 to be necessary because there is nothing that actually
3440 describes what the exception handling code may actually need
3442 if (reload_completed
)
3444 if (frame_pointer_needed
)
3446 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3447 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3448 bitmap_set_bit (eh_block_artificial_uses
,
3449 HARD_FRAME_POINTER_REGNUM
);
3451 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3452 && fixed_regs
[ARG_POINTER_REGNUM
])
3453 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3459 /*----------------------------------------------------------------------------
3460 Specialized hard register scanning functions.
3461 ----------------------------------------------------------------------------*/
3464 /* Mark a register in SET. Hard registers in large modes get all
3465 of their component registers set as well. */
3468 df_mark_reg (rtx reg
, void *vset
)
3470 bitmap_set_range ((bitmap
) vset
, REGNO (reg
), REG_NREGS (reg
));
3474 /* Set the bit for regs that are considered being defined at the entry. */
3477 df_get_entry_block_def_set (bitmap entry_block_defs
)
3482 bitmap_clear (entry_block_defs
);
3484 /* For separate shrink-wrapping we use LIVE to analyze which basic blocks
3485 need a prologue for some component to be executed before that block,
3486 and we do not care about any other registers. Hence, we do not want
3487 any register for any component defined in the entry block, and we can
3488 just leave all registers undefined. */
3489 if (df_scan
->local_flags
& DF_SCAN_EMPTY_ENTRY_EXIT
)
3492 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3495 bitmap_set_bit (entry_block_defs
, i
);
3496 if (FUNCTION_ARG_REGNO_P (i
))
3497 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3500 /* The always important stack pointer. */
3501 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3503 /* Once the prologue has been generated, all of these registers
3504 should just show up in the first regular block. */
3505 if (targetm
.have_prologue () && epilogue_completed
)
3507 /* Defs for the callee saved registers are inserted so that the
3508 pushes have some defining location. */
3509 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3510 if (!crtl
->abi
->clobbers_full_reg_p (i
)
3512 && df_regs_ever_live_p (i
))
3513 bitmap_set_bit (entry_block_defs
, i
);
3516 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3518 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3520 /* If the function has an incoming STATIC_CHAIN, it has to show up
3521 in the entry def set. */
3522 r
= rtx_for_static_chain (current_function_decl
, true);
3524 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3526 if ((!reload_completed
) || frame_pointer_needed
)
3528 /* Any reference to any pseudo before reload is a potential
3529 reference of the frame pointer. */
3530 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3532 /* If they are different, also mark the hard frame pointer as live. */
3533 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3534 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3535 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3538 /* These registers are live everywhere. */
3539 if (!reload_completed
)
3541 /* Pseudos with argument area equivalences may require
3542 reloading via the argument pointer. */
3543 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3544 && fixed_regs
[ARG_POINTER_REGNUM
])
3545 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3547 /* Any constant, or pseudo with constant equivalences, may
3548 require reloading from memory using the pic register. */
3549 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3550 if (picreg
!= INVALID_REGNUM
3551 && fixed_regs
[picreg
])
3552 bitmap_set_bit (entry_block_defs
, picreg
);
3555 #ifdef INCOMING_RETURN_ADDR_RTX
3556 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3557 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3560 targetm
.extra_live_on_entry (entry_block_defs
);
3564 /* Return the (conservative) set of hard registers that are defined on
3565 entry to the function.
3566 It uses df->entry_block_defs to determine which register
3567 reference to include. */
3570 df_entry_block_defs_collect (class df_collection_rec
*collection_rec
,
3571 bitmap entry_block_defs
)
3576 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3578 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3579 ENTRY_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_DEF
, 0);
3582 df_canonize_collection_rec (collection_rec
);
3586 /* Record the (conservative) set of hard registers that are defined on
3587 entry to the function. */
3590 df_record_entry_block_defs (bitmap entry_block_defs
)
3592 class df_collection_rec collection_rec
;
3593 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3595 /* Process bb_refs chain */
3596 df_refs_add_to_chains (&collection_rec
,
3597 BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
),
3603 /* Update the defs in the entry block. */
3606 df_update_entry_block_defs (void)
3608 bool changed
= false;
3610 auto_bitmap
refs (&df_bitmap_obstack
);
3611 df_get_entry_block_def_set (refs
);
3612 gcc_assert (df
->entry_block_defs
);
3613 if (!bitmap_equal_p (df
->entry_block_defs
, refs
))
3615 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3616 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3617 df_ref_chain_delete (bb_info
->artificial_defs
);
3618 bb_info
->artificial_defs
= NULL
;
3624 df_record_entry_block_defs (refs
);
3625 bitmap_copy (df
->entry_block_defs
, refs
);
3626 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
3631 /* Return true if REGNO is used by the epilogue. */
3633 df_epilogue_uses_p (unsigned int regno
)
3635 return (EPILOGUE_USES (regno
)
3636 || TEST_HARD_REG_BIT (crtl
->must_be_zero_on_return
, regno
));
3639 /* Set the bit for regs that are considered being used at the exit. */
3642 df_get_exit_block_use_set (bitmap exit_block_uses
)
3645 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3647 bitmap_clear (exit_block_uses
);
3649 /* For separate shrink-wrapping we use LIVE to analyze which basic blocks
3650 need an epilogue for some component to be executed after that block,
3651 and we do not care about any other registers. Hence, we do not want
3652 any register for any component seen as used in the exit block, and we
3653 can just say no registers at all are used. */
3654 if (df_scan
->local_flags
& DF_SCAN_EMPTY_ENTRY_EXIT
)
3657 /* Stack pointer is always live at the exit. */
3658 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3660 /* Mark the frame pointer if needed at the end of the function.
3661 If we end up eliminating it, it will be removed from the live
3662 list of each basic block by reload. */
3664 if ((!reload_completed
) || frame_pointer_needed
)
3666 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3668 /* If they are different, also mark the hard frame pointer as live. */
3669 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3670 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3671 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3674 /* Many architectures have a GP register even without flag_pic.
3675 Assume the pic register is not in use, or will be handled by
3676 other means, if it is not fixed. */
3677 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3678 && picreg
!= INVALID_REGNUM
3679 && fixed_regs
[picreg
])
3680 bitmap_set_bit (exit_block_uses
, picreg
);
3682 /* Mark all global registers, and all registers used by the
3683 epilogue as being live at the end of the function since they
3684 may be referenced by our caller. */
3685 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3686 if (global_regs
[i
] || df_epilogue_uses_p (i
))
3687 bitmap_set_bit (exit_block_uses
, i
);
3689 if (targetm
.have_epilogue () && epilogue_completed
)
3691 /* Mark all call-saved registers that we actually used. */
3692 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3693 if (df_regs_ever_live_p (i
)
3695 && !crtl
->abi
->clobbers_full_reg_p (i
))
3696 bitmap_set_bit (exit_block_uses
, i
);
3699 /* Mark the registers that will contain data for the handler. */
3700 if (reload_completed
&& crtl
->calls_eh_return
)
3703 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3704 if (regno
== INVALID_REGNUM
)
3706 bitmap_set_bit (exit_block_uses
, regno
);
3709 #ifdef EH_RETURN_STACKADJ_RTX
3710 if ((!targetm
.have_epilogue () || ! epilogue_completed
)
3711 && crtl
->calls_eh_return
)
3713 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
3714 if (tmp
&& REG_P (tmp
))
3715 df_mark_reg (tmp
, exit_block_uses
);
3719 if ((!targetm
.have_epilogue () || ! epilogue_completed
)
3720 && crtl
->calls_eh_return
)
3722 rtx tmp
= EH_RETURN_HANDLER_RTX
;
3723 if (tmp
&& REG_P (tmp
))
3724 df_mark_reg (tmp
, exit_block_uses
);
3727 /* Mark function return value. */
3728 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
3732 /* Return the refs of hard registers that are used in the exit block.
3733 It uses df->exit_block_uses to determine register to include. */
3736 df_exit_block_uses_collect (class df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
3741 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
3742 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3743 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3745 /* It is deliberate that this is not put in the exit block uses but
3746 I do not know why. */
3747 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3749 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
3750 && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun
))
3751 && fixed_regs
[ARG_POINTER_REGNUM
])
3752 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
3753 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3755 df_canonize_collection_rec (collection_rec
);
3759 /* Record the set of hard registers that are used in the exit block.
3760 It uses df->exit_block_uses to determine which bit to include. */
3763 df_record_exit_block_uses (bitmap exit_block_uses
)
3765 class df_collection_rec collection_rec
;
3766 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
3768 /* Process bb_refs chain */
3769 df_refs_add_to_chains (&collection_rec
,
3770 BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
),
3776 /* Update the uses in the exit block. */
3779 df_update_exit_block_uses (void)
3781 bool changed
= false;
3783 auto_bitmap
refs (&df_bitmap_obstack
);
3784 df_get_exit_block_use_set (refs
);
3785 gcc_assert (df
->exit_block_uses
);
3786 if (!bitmap_equal_p (df
->exit_block_uses
, refs
))
3788 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
3789 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
3790 df_ref_chain_delete (bb_info
->artificial_uses
);
3791 bb_info
->artificial_uses
= NULL
;
3797 df_record_exit_block_uses (refs
);
3798 bitmap_copy (df
->exit_block_uses
, refs
);
3799 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
3803 static bool initialized
= false;
3806 /* Initialize some platform specific structures. */
3809 df_hard_reg_init (void)
3812 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
3817 /* Record which registers will be eliminated. We use this in
3819 CLEAR_HARD_REG_SET (elim_reg_set
);
3821 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
3822 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
3827 /* Recompute the parts of scanning that are based on regs_ever_live
3828 because something changed in that array. */
3831 df_update_entry_exit_and_calls (void)
3835 df_update_entry_block_defs ();
3836 df_update_exit_block_uses ();
3838 /* The call insns need to be rescanned because there may be changes
3839 in the set of registers clobbered across the call. */
3840 FOR_EACH_BB_FN (bb
, cfun
)
3843 FOR_BB_INSNS (bb
, insn
)
3845 if (INSN_P (insn
) && CALL_P (insn
))
3846 df_insn_rescan (insn
);
3852 /* Return true if hard REG is actually used in the some instruction.
3853 There are a fair number of conditions that affect the setting of
3854 this array. See the comment in df.h for df->hard_regs_live_count
3855 for the conditions that this array is set. */
3858 df_hard_reg_used_p (unsigned int reg
)
3860 return df
->hard_regs_live_count
[reg
] != 0;
3864 /* A count of the number of times REG is actually used in the some
3865 instruction. There are a fair number of conditions that affect the
3866 setting of this array. See the comment in df.h for
3867 df->hard_regs_live_count for the conditions that this array is
3872 df_hard_reg_used_count (unsigned int reg
)
3874 return df
->hard_regs_live_count
[reg
];
3878 /* Get the value of regs_ever_live[REGNO]. */
3881 df_regs_ever_live_p (unsigned int regno
)
3883 return regs_ever_live
[regno
];
3886 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
3887 to change, schedule that change for the next update. */
3890 df_set_regs_ever_live (unsigned int regno
, bool value
)
3892 if (regs_ever_live
[regno
] == value
)
3895 regs_ever_live
[regno
] = value
;
3897 df
->redo_entry_and_exit
= true;
3901 /* Compute "regs_ever_live" information from the underlying df
3902 information. Set the vector to all false if RESET. */
3905 df_compute_regs_ever_live (bool reset
)
3908 bool changed
= df
->redo_entry_and_exit
;
3911 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
3913 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3914 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
3916 regs_ever_live
[i
] = true;
3920 df_update_entry_exit_and_calls ();
3921 df
->redo_entry_and_exit
= false;
3925 /*----------------------------------------------------------------------------
3926 Dataflow ref information verification functions.
3928 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
3929 df_reg_chain_verify_unmarked (refs)
3930 df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
3931 df_mws_verify (mw*, mw*, bool)
3932 df_insn_refs_verify (collection_rec, bb, insn, bool)
3933 df_bb_refs_verify (bb, refs, bool)
3935 df_exit_block_bitmap_verify (bool)
3936 df_entry_block_bitmap_verify (bool)
3938 ----------------------------------------------------------------------------*/
3941 /* Mark all refs in the reg chain. Verify that all of the registers
3942 are in the correct chain. */
3945 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
3946 bool is_def
, bool is_eq_use
)
3948 unsigned int count
= 0;
3950 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
3952 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
3954 /* If there are no def-use or use-def chains, make sure that all
3955 of the chains are clear. */
3957 gcc_assert (!DF_REF_CHAIN (ref
));
3959 /* Check to make sure the ref is in the correct chain. */
3960 gcc_assert (DF_REF_REGNO (ref
) == regno
);
3962 gcc_assert (DF_REF_REG_DEF_P (ref
));
3964 gcc_assert (!DF_REF_REG_DEF_P (ref
));
3967 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
3969 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
3971 if (DF_REF_NEXT_REG (ref
))
3972 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
3974 DF_REF_REG_MARK (ref
);
3980 /* Verify that all of the registers in the chain are unmarked. */
3983 df_reg_chain_verify_unmarked (df_ref refs
)
3986 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
3987 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
3991 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
3994 df_refs_verify (const vec
<df_ref
, va_heap
> *new_rec
, df_ref old_rec
,
4000 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_ref
)
4002 if (old_rec
== NULL
|| !df_ref_equal_p (new_ref
, old_rec
))
4010 /* Abort if fail is called from the function level verifier. If
4011 that is the context, mark this reg as being seem. */
4014 gcc_assert (DF_REF_IS_REG_MARKED (old_rec
));
4015 DF_REF_REG_UNMARK (old_rec
);
4018 old_rec
= DF_REF_NEXT_LOC (old_rec
);
4022 gcc_assert (old_rec
== NULL
);
4024 return old_rec
== NULL
;
4029 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4032 df_mws_verify (const vec
<df_mw_hardreg
*, va_heap
> *new_rec
,
4033 struct df_mw_hardreg
*old_rec
,
4037 struct df_mw_hardreg
*new_reg
;
4039 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_reg
)
4041 if (old_rec
== NULL
|| !df_mw_equal_p (new_reg
, old_rec
))
4048 old_rec
= DF_MWS_NEXT (old_rec
);
4052 gcc_assert (old_rec
== NULL
);
4054 return old_rec
== NULL
;
4059 /* Return true if the existing insn refs information is complete and
4060 correct. Otherwise (i.e. if there's any missing or extra refs),
4061 return the correct df_ref chain in REFS_RETURN.
4063 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4064 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4065 verification mode instead of the whole function, so unmark
4068 If ABORT_IF_FAIL is set, this function never returns false. */
4071 df_insn_refs_verify (class df_collection_rec
*collection_rec
,
4076 bool ret1
, ret2
, ret3
;
4077 unsigned int uid
= INSN_UID (insn
);
4078 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4080 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4082 /* Unfortunately we cannot opt out early if one of these is not
4083 right and abort_if_fail is set because the marks will not get cleared. */
4084 ret1
= df_refs_verify (&collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4086 if (!ret1
&& !abort_if_fail
)
4088 ret2
= df_refs_verify (&collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4090 if (!ret2
&& !abort_if_fail
)
4092 ret3
= df_refs_verify (&collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4094 if (!ret3
&& !abort_if_fail
)
4096 if (! df_mws_verify (&collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4099 return (ret1
&& ret2
&& ret3
);
4103 /* Return true if all refs in the basic block are correct and complete.
4104 Due to df_ref_chain_verify, it will cause all refs
4105 that are verified to have DF_REF_MARK bit set. */
4108 df_bb_verify (basic_block bb
)
4111 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4112 class df_collection_rec collection_rec
;
4114 gcc_assert (bb_info
);
4116 /* Scan the block, one insn at a time, from beginning to end. */
4117 FOR_BB_INSNS_REVERSE (bb
, insn
)
4121 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4122 df_free_collection_rec (&collection_rec
);
4125 /* Do the artificial defs and uses. */
4126 df_bb_refs_collect (&collection_rec
, bb
);
4127 df_refs_verify (&collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4128 df_refs_verify (&collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4129 df_free_collection_rec (&collection_rec
);
4135 /* Returns true if the entry block has correct and complete df_ref set.
4136 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4139 df_entry_block_bitmap_verify (bool abort_if_fail
)
4143 auto_bitmap
entry_block_defs (&df_bitmap_obstack
);
4144 df_get_entry_block_def_set (entry_block_defs
);
4146 is_eq
= bitmap_equal_p (entry_block_defs
, df
->entry_block_defs
);
4148 if (!is_eq
&& abort_if_fail
)
4150 fprintf (stderr
, "entry_block_defs = ");
4151 df_print_regset (stderr
, entry_block_defs
);
4152 fprintf (stderr
, "df->entry_block_defs = ");
4153 df_print_regset (stderr
, df
->entry_block_defs
);
4161 /* Returns true if the exit block has correct and complete df_ref set.
4162 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4165 df_exit_block_bitmap_verify (bool abort_if_fail
)
4169 auto_bitmap
exit_block_uses (&df_bitmap_obstack
);
4170 df_get_exit_block_use_set (exit_block_uses
);
4172 is_eq
= bitmap_equal_p (exit_block_uses
, df
->exit_block_uses
);
4174 if (!is_eq
&& abort_if_fail
)
4176 fprintf (stderr
, "exit_block_uses = ");
4177 df_print_regset (stderr
, exit_block_uses
);
4178 fprintf (stderr
, "df->exit_block_uses = ");
4179 df_print_regset (stderr
, df
->exit_block_uses
);
4187 /* Return true if df_ref information for all insns in all blocks are
4188 correct and complete. */
4191 df_scan_verify (void)
4199 /* Verification is a 4 step process. */
4201 /* (1) All of the refs are marked by going through the reg chains. */
4202 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4204 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4205 == DF_REG_DEF_COUNT (i
));
4206 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4207 == DF_REG_USE_COUNT (i
));
4208 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4209 == DF_REG_EQ_USE_COUNT (i
));
4212 /* (2) There are various bitmaps whose value may change over the
4213 course of the compilation. This step recomputes them to make
4214 sure that they have not slipped out of date. */
4215 auto_bitmap
regular_block_artificial_uses (&df_bitmap_obstack
);
4216 auto_bitmap
eh_block_artificial_uses (&df_bitmap_obstack
);
4218 df_get_regular_block_artificial_uses (regular_block_artificial_uses
);
4219 df_get_eh_block_artificial_uses (eh_block_artificial_uses
);
4221 bitmap_ior_into (eh_block_artificial_uses
,
4222 regular_block_artificial_uses
);
4224 /* Check artificial_uses bitmaps didn't change. */
4225 gcc_assert (bitmap_equal_p (regular_block_artificial_uses
,
4226 &df
->regular_block_artificial_uses
));
4227 gcc_assert (bitmap_equal_p (eh_block_artificial_uses
,
4228 &df
->eh_block_artificial_uses
));
4230 /* Verify entry block and exit block. These only verify the bitmaps,
4231 the refs are verified in df_bb_verify. */
4232 df_entry_block_bitmap_verify (true);
4233 df_exit_block_bitmap_verify (true);
4235 /* (3) All of the insns in all of the blocks are traversed and the
4236 marks are cleared both in the artificial refs attached to the
4237 blocks and the real refs inside the insns. It is a failure to
4238 clear a mark that has not been set as this means that the ref in
4239 the block or insn was not in the reg chain. */
4241 FOR_ALL_BB_FN (bb
, cfun
)
4244 /* (4) See if all reg chains are traversed a second time. This time
4245 a check is made that the marks are clear. A set mark would be a
4246 from a reg that is not in any insn or basic block. */
4248 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4250 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4251 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4252 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));