1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
30 #include "insn-config.h"
34 #include "hard-reg-set.h"
37 #include "alloc-pool.h"
40 #include "dominance.h"
42 #include "basic-block.h"
48 #include "target-def.h"
50 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
53 typedef struct df_mw_hardreg
*df_mw_hardreg_ptr
;
57 #define HAVE_prologue 0
59 #ifndef HAVE_sibcall_epilogue
60 #define HAVE_sibcall_epilogue 0
63 /* The set of hard registers in eliminables[i].from. */
65 static HARD_REG_SET elim_reg_set
;
67 /* Initialize ur_in and ur_out as if all hard registers were partially
70 struct df_collection_rec
72 auto_vec
<df_ref
, 128> def_vec
;
73 auto_vec
<df_ref
, 32> use_vec
;
74 auto_vec
<df_ref
, 32> eq_use_vec
;
75 auto_vec
<df_mw_hardreg_ptr
, 32> mw_vec
;
78 static void df_ref_record (enum df_ref_class
, struct df_collection_rec
*,
80 basic_block
, struct df_insn_info
*,
81 enum df_ref_type
, int ref_flags
);
82 static void df_def_record_1 (struct df_collection_rec
*, rtx
*,
83 basic_block
, struct df_insn_info
*,
85 static void df_defs_record (struct df_collection_rec
*, rtx
,
86 basic_block
, struct df_insn_info
*,
88 static void df_uses_record (struct df_collection_rec
*,
89 rtx
*, enum df_ref_type
,
90 basic_block
, struct df_insn_info
*,
93 static void df_install_ref_incremental (df_ref
);
94 static void df_insn_refs_collect (struct df_collection_rec
*,
95 basic_block
, struct df_insn_info
*);
96 static void df_canonize_collection_rec (struct df_collection_rec
*);
98 static void df_get_regular_block_artificial_uses (bitmap
);
99 static void df_get_eh_block_artificial_uses (bitmap
);
101 static void df_record_entry_block_defs (bitmap
);
102 static void df_record_exit_block_uses (bitmap
);
103 static void df_get_exit_block_use_set (bitmap
);
104 static void df_get_entry_block_def_set (bitmap
);
105 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
106 static void df_ref_chain_delete_du_chain (df_ref
);
107 static void df_ref_chain_delete (df_ref
);
109 static void df_refs_add_to_chains (struct df_collection_rec
*,
110 basic_block
, rtx_insn
*, unsigned int);
112 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
,
114 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
115 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
116 static void df_install_ref (df_ref
, struct df_reg_info
*,
117 struct df_ref_info
*, bool);
119 static int df_ref_compare (df_ref
, df_ref
);
120 static int df_ref_ptr_compare (const void *, const void *);
121 static int df_mw_compare (const df_mw_hardreg
*, const df_mw_hardreg
*);
122 static int df_mw_ptr_compare (const void *, const void *);
124 static void df_insn_info_delete (unsigned int);
126 /* Indexed by hardware reg number, is true if that register is ever
127 used in the current function.
129 In df-scan.c, this is set up to record the hard regs used
130 explicitly. Reload adds in the hard regs used for holding pseudo
131 regs. Final uses it to generate the code in the function prologue
132 and epilogue to save and restore registers as needed. */
134 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
136 /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
137 static const unsigned int copy_defs
= 0x1;
138 static const unsigned int copy_uses
= 0x2;
139 static const unsigned int copy_eq_uses
= 0x4;
140 static const unsigned int copy_mw
= 0x8;
141 static const unsigned int copy_all
= copy_defs
| copy_uses
| copy_eq_uses
144 /*----------------------------------------------------------------------------
145 SCANNING DATAFLOW PROBLEM
147 There are several ways in which scanning looks just like the other
148 dataflow problems. It shares the all the mechanisms for local info
149 as well as basic block info. Where it differs is when and how often
150 it gets run. It also has no need for the iterative solver.
151 ----------------------------------------------------------------------------*/
153 #define SCAN_PROBLEM_DATA_BLOCK_SIZE 512
155 /* Problem data for the scanning dataflow function. */
156 struct df_scan_problem_data
158 pool_allocator
<df_base_ref
> *ref_base_pool
;
159 pool_allocator
<df_artificial_ref
> *ref_artificial_pool
;
160 pool_allocator
<df_regular_ref
> *ref_regular_pool
;
161 pool_allocator
<df_insn_info
> *insn_pool
;
162 pool_allocator
<df_reg_info
> *reg_pool
;
163 pool_allocator
<df_mw_hardreg
> *mw_reg_pool
;
165 bitmap_obstack reg_bitmaps
;
166 bitmap_obstack insn_bitmaps
;
169 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
172 /* Internal function to shut down the scanning problem. */
174 df_scan_free_internal (void)
176 struct df_scan_problem_data
*problem_data
177 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
179 free (df
->def_info
.refs
);
180 free (df
->def_info
.begin
);
181 free (df
->def_info
.count
);
182 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
184 free (df
->use_info
.refs
);
185 free (df
->use_info
.begin
);
186 free (df
->use_info
.count
);
187 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
193 free (df
->eq_use_regs
);
194 df
->eq_use_regs
= NULL
;
196 DF_REG_SIZE (df
) = 0;
202 free (df_scan
->block_info
);
203 df_scan
->block_info
= NULL
;
204 df_scan
->block_info_size
= 0;
206 bitmap_clear (&df
->hardware_regs_used
);
207 bitmap_clear (&df
->regular_block_artificial_uses
);
208 bitmap_clear (&df
->eh_block_artificial_uses
);
209 BITMAP_FREE (df
->entry_block_defs
);
210 BITMAP_FREE (df
->exit_block_uses
);
211 bitmap_clear (&df
->insns_to_delete
);
212 bitmap_clear (&df
->insns_to_rescan
);
213 bitmap_clear (&df
->insns_to_notes_rescan
);
215 delete problem_data
->ref_base_pool
;
216 delete problem_data
->ref_artificial_pool
;
217 delete problem_data
->ref_regular_pool
;
218 delete problem_data
->insn_pool
;
219 delete problem_data
->reg_pool
;
220 delete problem_data
->mw_reg_pool
;
221 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
222 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
223 free (df_scan
->problem_data
);
227 /* Free basic block info. */
230 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
232 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
233 unsigned int bb_index
= bb
->index
;
236 FOR_BB_INSNS (bb
, insn
)
238 df_insn_info_delete (INSN_UID (insn
));
240 if (bb_index
< df_scan
->block_info_size
)
241 bb_info
= df_scan_get_bb_info (bb_index
);
243 /* Get rid of any artificial uses or defs. */
244 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
245 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
246 df_ref_chain_delete (bb_info
->artificial_defs
);
247 df_ref_chain_delete (bb_info
->artificial_uses
);
248 bb_info
->artificial_defs
= NULL
;
249 bb_info
->artificial_uses
= NULL
;
253 /* Allocate the problem data for the scanning problem. This should be
254 called when the problem is created or when the entire function is to
257 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
259 struct df_scan_problem_data
*problem_data
;
260 unsigned int insn_num
= get_max_uid () + 1;
263 /* Given the number of pools, this is really faster than tearing
265 if (df_scan
->problem_data
)
266 df_scan_free_internal ();
268 problem_data
= XNEW (struct df_scan_problem_data
);
269 df_scan
->problem_data
= problem_data
;
270 df_scan
->computed
= true;
272 problem_data
->ref_base_pool
= new pool_allocator
<df_base_ref
>
273 ("df_scan ref base", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
274 problem_data
->ref_artificial_pool
= new pool_allocator
<df_artificial_ref
>
275 ("df_scan ref artificial", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
276 problem_data
->ref_regular_pool
= new pool_allocator
<df_regular_ref
>
277 ("df_scan ref regular", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
278 problem_data
->insn_pool
= new pool_allocator
<df_insn_info
>
279 ("df_scan insn", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
280 problem_data
->reg_pool
= new pool_allocator
<df_reg_info
>
281 ("df_scan reg", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
282 problem_data
->mw_reg_pool
= new pool_allocator
<df_mw_hardreg
>
283 ("df_scan mw_reg", SCAN_PROBLEM_DATA_BLOCK_SIZE
/ 16);
285 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
286 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
288 insn_num
+= insn_num
/ 4;
291 df_grow_insn_info ();
292 df_grow_bb_info (df_scan
);
294 FOR_ALL_BB_FN (bb
, cfun
)
296 unsigned int bb_index
= bb
->index
;
297 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
298 bb_info
->artificial_defs
= NULL
;
299 bb_info
->artificial_uses
= NULL
;
302 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
303 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
304 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
305 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
306 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
307 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
308 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
309 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
310 df_scan
->optional_p
= false;
314 /* Free all of the data associated with the scan problem. */
319 if (df_scan
->problem_data
)
320 df_scan_free_internal ();
322 if (df
->blocks_to_analyze
)
324 BITMAP_FREE (df
->blocks_to_analyze
);
325 df
->blocks_to_analyze
= NULL
;
331 /* Dump the preamble for DF_SCAN dump. */
333 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
344 fprintf (file
, ";; invalidated by call \t");
345 df_print_regset (file
, regs_invalidated_by_call_regset
);
346 fprintf (file
, ";; hardware regs used \t");
347 df_print_regset (file
, &df
->hardware_regs_used
);
348 fprintf (file
, ";; regular block artificial uses \t");
349 df_print_regset (file
, &df
->regular_block_artificial_uses
);
350 fprintf (file
, ";; eh block artificial uses \t");
351 df_print_regset (file
, &df
->eh_block_artificial_uses
);
352 fprintf (file
, ";; entry block defs \t");
353 df_print_regset (file
, df
->entry_block_defs
);
354 fprintf (file
, ";; exit block uses \t");
355 df_print_regset (file
, df
->exit_block_uses
);
356 fprintf (file
, ";; regs ever live \t");
357 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
358 if (df_regs_ever_live_p (i
))
359 fprintf (file
, " %d [%s]", i
, reg_names
[i
]);
360 fprintf (file
, "\n;; ref usage \t");
362 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
363 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
365 const char * sep
= "";
367 fprintf (file
, "r%d={", i
);
368 if (DF_REG_DEF_COUNT (i
))
370 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
372 dcount
+= DF_REG_DEF_COUNT (i
);
374 if (DF_REG_USE_COUNT (i
))
376 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
378 ucount
+= DF_REG_USE_COUNT (i
);
380 if (DF_REG_EQ_USE_COUNT (i
))
382 fprintf (file
, "%s%de", sep
, DF_REG_EQ_USE_COUNT (i
));
383 ecount
+= DF_REG_EQ_USE_COUNT (i
);
385 fprintf (file
, "} ");
388 FOR_EACH_BB_FN (bb
, cfun
)
389 FOR_BB_INSNS (bb
, insn
)
398 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de}"
399 " in %d{%d regular + %d call} insns.\n",
400 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
,
401 icount
+ ccount
, icount
, ccount
);
404 /* Dump the bb_info for a given basic block. */
406 df_scan_start_block (basic_block bb
, FILE *file
)
408 struct df_scan_bb_info
*bb_info
409 = df_scan_get_bb_info (bb
->index
);
413 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
414 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
415 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
416 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
417 fprintf (file
, "\n");
422 FOR_BB_INSNS (bb
, insn
)
424 df_insn_debug (insn
, false, file
);
429 static struct df_problem problem_SCAN
=
431 DF_SCAN
, /* Problem id. */
432 DF_NONE
, /* Direction. */
433 df_scan_alloc
, /* Allocate the problem specific data. */
434 NULL
, /* Reset global information. */
435 df_scan_free_bb_info
, /* Free basic block info. */
436 NULL
, /* Local compute function. */
437 NULL
, /* Init the solution specific data. */
438 NULL
, /* Iterative solver. */
439 NULL
, /* Confluence operator 0. */
440 NULL
, /* Confluence operator n. */
441 NULL
, /* Transfer function. */
442 NULL
, /* Finalize function. */
443 df_scan_free
, /* Free all of the problem information. */
444 NULL
, /* Remove this problem from the stack of dataflow problems. */
445 df_scan_start_dump
, /* Debugging. */
446 df_scan_start_block
, /* Debugging start block. */
447 NULL
, /* Debugging end block. */
448 NULL
, /* Debugging start insn. */
449 NULL
, /* Debugging end insn. */
450 NULL
, /* Incremental solution verify start. */
451 NULL
, /* Incremental solution verify end. */
452 NULL
, /* Dependent problem. */
453 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
454 TV_DF_SCAN
, /* Timing variable. */
455 false /* Reset blocks on dropping out of blocks_to_analyze. */
459 /* Create a new DATAFLOW instance and add it to an existing instance
460 of DF. The returned structure is what is used to get at the
464 df_scan_add_problem (void)
466 df_add_problem (&problem_SCAN
);
470 /*----------------------------------------------------------------------------
471 Storage Allocation Utilities
472 ----------------------------------------------------------------------------*/
475 /* First, grow the reg_info information. If the current size is less than
476 the number of pseudos, grow to 25% more than the number of
479 Second, assure that all of the slots up to max_reg_num have been
480 filled with reg_info structures. */
483 df_grow_reg_info (void)
485 unsigned int max_reg
= max_reg_num ();
486 unsigned int new_size
= max_reg
;
487 struct df_scan_problem_data
*problem_data
488 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
491 if (df
->regs_size
< new_size
)
493 new_size
+= new_size
/ 4;
494 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
495 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
496 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
498 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
499 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
500 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
501 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
502 df
->regs_size
= new_size
;
505 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
507 struct df_reg_info
*reg_info
;
510 reg_info
= problem_data
->reg_pool
->allocate ();
511 memset (reg_info
, 0, sizeof (struct df_reg_info
));
512 df
->def_regs
[i
] = reg_info
;
513 reg_info
= problem_data
->reg_pool
->allocate ();
514 memset (reg_info
, 0, sizeof (struct df_reg_info
));
515 df
->use_regs
[i
] = reg_info
;
516 reg_info
= problem_data
->reg_pool
->allocate ();
517 memset (reg_info
, 0, sizeof (struct df_reg_info
));
518 df
->eq_use_regs
[i
] = reg_info
;
519 df
->def_info
.begin
[i
] = 0;
520 df
->def_info
.count
[i
] = 0;
521 df
->use_info
.begin
[i
] = 0;
522 df
->use_info
.count
[i
] = 0;
525 df
->regs_inited
= max_reg
;
529 /* Grow the ref information. */
532 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
534 if (ref_info
->refs_size
< new_size
)
536 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
537 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
538 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
539 ref_info
->refs_size
= new_size
;
544 /* Check and grow the ref information if necessary. This routine
545 guarantees total_size + BITMAP_ADDEND amount of entries in refs
546 array. It updates ref_info->refs_size only and does not change
547 ref_info->total_size. */
550 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
551 unsigned bitmap_addend
)
553 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
555 int new_size
= ref_info
->total_size
+ bitmap_addend
;
556 new_size
+= ref_info
->total_size
/ 4;
557 df_grow_ref_info (ref_info
, new_size
);
562 /* Grow the ref information. If the current size is less than the
563 number of instructions, grow to 25% more than the number of
567 df_grow_insn_info (void)
569 unsigned int new_size
= get_max_uid () + 1;
570 if (DF_INSN_SIZE () < new_size
)
572 new_size
+= new_size
/ 4;
573 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
574 memset (df
->insns
+ df
->insns_size
, 0,
575 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
576 DF_INSN_SIZE () = new_size
;
583 /*----------------------------------------------------------------------------
584 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
585 ----------------------------------------------------------------------------*/
587 /* Rescan all of the block_to_analyze or all of the blocks in the
588 function if df_set_blocks if blocks_to_analyze is NULL; */
591 df_scan_blocks (void)
595 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
596 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
598 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
599 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
601 bitmap_ior_into (&df
->eh_block_artificial_uses
,
602 &df
->regular_block_artificial_uses
);
604 /* ENTRY and EXIT blocks have special defs/uses. */
605 df_get_entry_block_def_set (df
->entry_block_defs
);
606 df_record_entry_block_defs (df
->entry_block_defs
);
607 df_get_exit_block_use_set (df
->exit_block_uses
);
608 df_record_exit_block_uses (df
->exit_block_uses
);
609 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
610 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
613 FOR_EACH_BB_FN (bb
, cfun
)
615 unsigned int bb_index
= bb
->index
;
616 df_bb_refs_record (bb_index
, true);
620 /* Create new refs under address LOC within INSN. This function is
621 only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
622 depending on whether LOC is inside PATTERN (INSN) or a note. */
625 df_uses_create (rtx
*loc
, rtx_insn
*insn
, int ref_flags
)
627 gcc_assert (!(ref_flags
& ~DF_REF_IN_NOTE
));
628 df_uses_record (NULL
, loc
, DF_REF_REG_USE
,
629 BLOCK_FOR_INSN (insn
),
630 DF_INSN_INFO_GET (insn
),
635 df_install_ref_incremental (df_ref ref
)
637 struct df_reg_info
**reg_info
;
638 struct df_ref_info
*ref_info
;
642 rtx_insn
*insn
= DF_REF_INSN (ref
);
643 basic_block bb
= BLOCK_FOR_INSN (insn
);
645 if (DF_REF_REG_DEF_P (ref
))
647 reg_info
= df
->def_regs
;
648 ref_info
= &df
->def_info
;
649 ref_ptr
= &DF_INSN_DEFS (insn
);
650 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
652 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
654 reg_info
= df
->eq_use_regs
;
655 ref_info
= &df
->use_info
;
656 ref_ptr
= &DF_INSN_EQ_USES (insn
);
657 switch (ref_info
->ref_order
)
659 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
660 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
661 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
665 add_to_table
= false;
671 reg_info
= df
->use_regs
;
672 ref_info
= &df
->use_info
;
673 ref_ptr
= &DF_INSN_USES (insn
);
674 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
677 /* Do not add if ref is not in the right blocks. */
678 if (add_to_table
&& df
->analyze_subset
)
679 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
681 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
684 switch (ref_info
->ref_order
)
686 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
687 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
688 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
689 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
692 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
696 while (*ref_ptr
&& df_ref_compare (*ref_ptr
, ref
) < 0)
697 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
699 DF_REF_NEXT_LOC (ref
) = *ref_ptr
;
705 fprintf (dump_file
, "adding ref ");
706 df_ref_debug (ref
, dump_file
);
709 /* By adding the ref directly, df_insn_rescan my not find any
710 differences even though the block will have changed. So we need
711 to mark the block dirty ourselves. */
712 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
713 df_set_bb_dirty (bb
);
718 /*----------------------------------------------------------------------------
719 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
720 ----------------------------------------------------------------------------*/
723 df_free_ref (df_ref ref
)
725 struct df_scan_problem_data
*problem_data
726 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
728 switch (DF_REF_CLASS (ref
))
731 problem_data
->ref_base_pool
->remove ((df_base_ref
*) (ref
));
734 case DF_REF_ARTIFICIAL
:
735 problem_data
->ref_artificial_pool
->remove
736 ((df_artificial_ref
*) (ref
));
740 problem_data
->ref_regular_pool
->remove
741 ((df_regular_ref
*) (ref
));
747 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
748 Also delete the def-use or use-def chain if it exists. */
751 df_reg_chain_unlink (df_ref ref
)
753 df_ref next
= DF_REF_NEXT_REG (ref
);
754 df_ref prev
= DF_REF_PREV_REG (ref
);
755 int id
= DF_REF_ID (ref
);
756 struct df_reg_info
*reg_info
;
759 if (DF_REF_REG_DEF_P (ref
))
761 int regno
= DF_REF_REGNO (ref
);
762 reg_info
= DF_REG_DEF_GET (regno
);
763 refs
= df
->def_info
.refs
;
767 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
769 reg_info
= DF_REG_EQ_USE_GET (DF_REF_REGNO (ref
));
770 switch (df
->use_info
.ref_order
)
772 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
773 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
774 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
775 refs
= df
->use_info
.refs
;
783 reg_info
= DF_REG_USE_GET (DF_REF_REGNO (ref
));
784 refs
= df
->use_info
.refs
;
790 if (df
->analyze_subset
)
792 if (bitmap_bit_p (df
->blocks_to_analyze
, DF_REF_BBNO (ref
)))
799 /* Delete any def-use or use-def chains that start here. It is
800 possible that there is trash in this field. This happens for
801 insns that have been deleted when rescanning has been deferred
802 and the chain problem has also been deleted. The chain tear down
803 code skips deleted insns. */
804 if (df_chain
&& DF_REF_CHAIN (ref
))
805 df_chain_unlink (ref
);
808 if (DF_REF_FLAGS_IS_SET (ref
, DF_HARD_REG_LIVE
))
810 gcc_assert (DF_REF_REGNO (ref
) < FIRST_PSEUDO_REGISTER
);
811 df
->hard_regs_live_count
[DF_REF_REGNO (ref
)]--;
814 /* Unlink from the reg chain. If there is no prev, this is the
815 first of the list. If not, just join the next and prev. */
817 DF_REF_NEXT_REG (prev
) = next
;
820 gcc_assert (reg_info
->reg_chain
== ref
);
821 reg_info
->reg_chain
= next
;
824 DF_REF_PREV_REG (next
) = prev
;
830 /* Create the insn record for INSN. If there was one there, zero it
833 struct df_insn_info
*
834 df_insn_create_insn_record (rtx_insn
*insn
)
836 struct df_scan_problem_data
*problem_data
837 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
838 struct df_insn_info
*insn_rec
;
840 df_grow_insn_info ();
841 insn_rec
= DF_INSN_INFO_GET (insn
);
844 insn_rec
= problem_data
->insn_pool
->allocate ();
845 DF_INSN_INFO_SET (insn
, insn_rec
);
847 memset (insn_rec
, 0, sizeof (struct df_insn_info
));
848 insn_rec
->insn
= insn
;
853 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
856 df_ref_chain_delete_du_chain (df_ref ref
)
858 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
859 /* CHAIN is allocated by DF_CHAIN. So make sure to
860 pass df_scan instance for the problem. */
861 if (DF_REF_CHAIN (ref
))
862 df_chain_unlink (ref
);
866 /* Delete all refs in the ref chain. */
869 df_ref_chain_delete (df_ref ref
)
872 for (; ref
; ref
= next
)
874 next
= DF_REF_NEXT_LOC (ref
);
875 df_reg_chain_unlink (ref
);
880 /* Delete the hardreg chain. */
883 df_mw_hardreg_chain_delete (struct df_mw_hardreg
*hardregs
)
885 struct df_scan_problem_data
*problem_data
886 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
889 for (; hardregs
; hardregs
= next
)
891 next
= DF_MWS_NEXT (hardregs
);
892 problem_data
->mw_reg_pool
->remove (hardregs
);
897 /* Delete all of the refs information from the insn with UID.
898 Internal helper for df_insn_delete, df_insn_rescan, and other
899 df-scan routines that don't have to work in deferred mode
900 and do not have to mark basic blocks for re-processing. */
903 df_insn_info_delete (unsigned int uid
)
905 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
907 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
908 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
909 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
912 struct df_scan_problem_data
*problem_data
913 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
915 /* In general, notes do not have the insn_info fields
916 initialized. However, combine deletes insns by changing them
917 to notes. How clever. So we cannot just check if it is a
918 valid insn before short circuiting this code, we need to see
919 if we actually initialized it. */
920 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
924 df_ref_chain_delete_du_chain (insn_info
->defs
);
925 df_ref_chain_delete_du_chain (insn_info
->uses
);
926 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
929 df_ref_chain_delete (insn_info
->defs
);
930 df_ref_chain_delete (insn_info
->uses
);
931 df_ref_chain_delete (insn_info
->eq_uses
);
933 problem_data
->insn_pool
->remove (insn_info
);
934 DF_INSN_UID_SET (uid
, NULL
);
938 /* Delete all of the refs information from INSN, either right now
939 or marked for later in deferred mode. */
942 df_insn_delete (rtx_insn
*insn
)
947 gcc_checking_assert (INSN_P (insn
));
952 uid
= INSN_UID (insn
);
953 bb
= BLOCK_FOR_INSN (insn
);
955 /* ??? bb can be NULL after pass_free_cfg. At that point, DF should
956 not exist anymore (as mentioned in df-core.c: "The only requirement
957 [for DF] is that there be a correct control flow graph." Clearly
958 that isn't the case after pass_free_cfg. But DF is freed much later
959 because some back-ends want to use DF info even though the CFG is
960 already gone. It's not clear to me whether that is safe, actually.
961 In any case, we expect BB to be non-NULL at least up to register
962 allocation, so disallow a non-NULL BB up to there. Not perfect
963 but better than nothing... */
964 gcc_checking_assert (bb
!= NULL
|| reload_completed
);
966 df_grow_bb_info (df_scan
);
969 /* The block must be marked as dirty now, rather than later as in
970 df_insn_rescan and df_notes_rescan because it may not be there at
971 rescanning time and the mark would blow up.
972 DEBUG_INSNs do not make a block's data flow solution dirty (at
973 worst the LUIDs are no longer contiguous). */
974 if (bb
!= NULL
&& NONDEBUG_INSN_P (insn
))
975 df_set_bb_dirty (bb
);
977 /* The client has deferred rescanning. */
978 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
980 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
983 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
984 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
985 bitmap_set_bit (&df
->insns_to_delete
, uid
);
988 fprintf (dump_file
, "deferring deletion of insn with uid = %d.\n", uid
);
993 fprintf (dump_file
, "deleting insn with uid = %d.\n", uid
);
995 df_insn_info_delete (uid
);
999 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1002 df_free_collection_rec (struct df_collection_rec
*collection_rec
)
1005 struct df_scan_problem_data
*problem_data
1006 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1008 struct df_mw_hardreg
*mw
;
1010 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
1012 FOR_EACH_VEC_ELT (collection_rec
->use_vec
, ix
, ref
)
1014 FOR_EACH_VEC_ELT (collection_rec
->eq_use_vec
, ix
, ref
)
1016 FOR_EACH_VEC_ELT (collection_rec
->mw_vec
, ix
, mw
)
1017 problem_data
->mw_reg_pool
->remove (mw
);
1019 collection_rec
->def_vec
.release ();
1020 collection_rec
->use_vec
.release ();
1021 collection_rec
->eq_use_vec
.release ();
1022 collection_rec
->mw_vec
.release ();
1025 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1028 df_insn_rescan (rtx_insn
*insn
)
1030 unsigned int uid
= INSN_UID (insn
);
1031 struct df_insn_info
*insn_info
= NULL
;
1032 basic_block bb
= BLOCK_FOR_INSN (insn
);
1033 struct df_collection_rec collection_rec
;
1035 if ((!df
) || (!INSN_P (insn
)))
1041 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1045 /* The client has disabled rescanning and plans to do it itself. */
1046 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1049 df_grow_bb_info (df_scan
);
1050 df_grow_reg_info ();
1052 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1054 /* The client has deferred rescanning. */
1055 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1059 insn_info
= df_insn_create_insn_record (insn
);
1060 insn_info
->defs
= 0;
1061 insn_info
->uses
= 0;
1062 insn_info
->eq_uses
= 0;
1063 insn_info
->mw_hardregs
= 0;
1066 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1068 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1069 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1070 bitmap_set_bit (&df
->insns_to_rescan
, INSN_UID (insn
));
1074 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1075 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1076 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1080 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1081 /* If there's no change, return false. */
1084 df_free_collection_rec (&collection_rec
);
1086 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1090 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1092 /* There's change - we need to delete the existing info.
1093 Since the insn isn't moved, we can salvage its LUID. */
1094 luid
= DF_INSN_LUID (insn
);
1095 df_insn_info_delete (uid
);
1096 df_insn_create_insn_record (insn
);
1097 DF_INSN_LUID (insn
) = luid
;
1101 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1102 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1104 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1107 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
1108 if (!DEBUG_INSN_P (insn
))
1109 df_set_bb_dirty (bb
);
1114 /* Same as df_insn_rescan, but don't mark the basic block as
1118 df_insn_rescan_debug_internal (rtx_insn
*insn
)
1120 unsigned int uid
= INSN_UID (insn
);
1121 struct df_insn_info
*insn_info
;
1123 gcc_assert (DEBUG_INSN_P (insn
)
1124 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn
)));
1129 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1134 fprintf (dump_file
, "deleting debug_insn with uid = %d.\n", uid
);
1136 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1137 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1138 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1140 if (insn_info
->defs
== 0
1141 && insn_info
->uses
== 0
1142 && insn_info
->eq_uses
== 0
1143 && insn_info
->mw_hardregs
== 0)
1146 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1150 df_ref_chain_delete_du_chain (insn_info
->defs
);
1151 df_ref_chain_delete_du_chain (insn_info
->uses
);
1152 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1155 df_ref_chain_delete (insn_info
->defs
);
1156 df_ref_chain_delete (insn_info
->uses
);
1157 df_ref_chain_delete (insn_info
->eq_uses
);
1159 insn_info
->defs
= 0;
1160 insn_info
->uses
= 0;
1161 insn_info
->eq_uses
= 0;
1162 insn_info
->mw_hardregs
= 0;
1168 /* Rescan all of the insns in the function. Note that the artificial
1169 uses and defs are not touched. This function will destroy def-use
1170 or use-def chains. */
1173 df_insn_rescan_all (void)
1175 bool no_insn_rescan
= false;
1176 bool defer_insn_rescan
= false;
1182 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1184 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1186 df_clear_flags (DF_NO_INSN_RESCAN
);
1187 no_insn_rescan
= true;
1190 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1192 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1193 defer_insn_rescan
= true;
1196 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1197 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1199 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1201 df_insn_info_delete (uid
);
1204 bitmap_clear (&tmp
);
1205 bitmap_clear (&df
->insns_to_delete
);
1206 bitmap_clear (&df
->insns_to_rescan
);
1207 bitmap_clear (&df
->insns_to_notes_rescan
);
1209 FOR_EACH_BB_FN (bb
, cfun
)
1212 FOR_BB_INSNS (bb
, insn
)
1214 df_insn_rescan (insn
);
1219 df_set_flags (DF_NO_INSN_RESCAN
);
1220 if (defer_insn_rescan
)
1221 df_set_flags (DF_DEFER_INSN_RESCAN
);
1225 /* Process all of the deferred rescans or deletions. */
1228 df_process_deferred_rescans (void)
1230 bool no_insn_rescan
= false;
1231 bool defer_insn_rescan
= false;
1236 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1238 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1240 df_clear_flags (DF_NO_INSN_RESCAN
);
1241 no_insn_rescan
= true;
1244 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1246 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1247 defer_insn_rescan
= true;
1251 fprintf (dump_file
, "starting the processing of deferred insns\n");
1253 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1254 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1256 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1258 df_insn_info_delete (uid
);
1261 bitmap_copy (&tmp
, &df
->insns_to_rescan
);
1262 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1264 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1266 df_insn_rescan (insn_info
->insn
);
1269 bitmap_copy (&tmp
, &df
->insns_to_notes_rescan
);
1270 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1272 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1274 df_notes_rescan (insn_info
->insn
);
1278 fprintf (dump_file
, "ending the processing of deferred insns\n");
1280 bitmap_clear (&tmp
);
1281 bitmap_clear (&df
->insns_to_delete
);
1282 bitmap_clear (&df
->insns_to_rescan
);
1283 bitmap_clear (&df
->insns_to_notes_rescan
);
1286 df_set_flags (DF_NO_INSN_RESCAN
);
1287 if (defer_insn_rescan
)
1288 df_set_flags (DF_DEFER_INSN_RESCAN
);
1290 /* If someone changed regs_ever_live during this pass, fix up the
1291 entry and exit blocks. */
1292 if (df
->redo_entry_and_exit
)
1294 df_update_entry_exit_and_calls ();
1295 df
->redo_entry_and_exit
= false;
1300 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1301 the uses if INCLUDE_USES. Include the eq_uses if
1305 df_count_refs (bool include_defs
, bool include_uses
,
1306 bool include_eq_uses
)
1310 unsigned int m
= df
->regs_inited
;
1312 for (regno
= 0; regno
< m
; regno
++)
1315 size
+= DF_REG_DEF_COUNT (regno
);
1317 size
+= DF_REG_USE_COUNT (regno
);
1318 if (include_eq_uses
)
1319 size
+= DF_REG_EQ_USE_COUNT (regno
);
1325 /* Take build ref table for either the uses or defs from the reg-use
1326 or reg-def chains. This version processes the refs in reg order
1327 which is likely to be best if processing the whole function. */
1330 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1333 bool include_eq_uses
)
1335 unsigned int m
= df
->regs_inited
;
1337 unsigned int offset
= 0;
1340 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1342 start
= FIRST_PSEUDO_REGISTER
;
1343 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1344 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1349 ref_info
->total_size
1350 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1352 df_check_and_grow_ref_info (ref_info
, 1);
1354 for (regno
= start
; regno
< m
; regno
++)
1357 ref_info
->begin
[regno
] = offset
;
1360 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1363 ref_info
->refs
[offset
] = ref
;
1364 DF_REF_ID (ref
) = offset
++;
1366 ref
= DF_REF_NEXT_REG (ref
);
1367 gcc_checking_assert (offset
< ref_info
->refs_size
);
1372 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1375 ref_info
->refs
[offset
] = ref
;
1376 DF_REF_ID (ref
) = offset
++;
1378 ref
= DF_REF_NEXT_REG (ref
);
1379 gcc_checking_assert (offset
< ref_info
->refs_size
);
1382 if (include_eq_uses
)
1384 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1387 ref_info
->refs
[offset
] = ref
;
1388 DF_REF_ID (ref
) = offset
++;
1390 ref
= DF_REF_NEXT_REG (ref
);
1391 gcc_checking_assert (offset
< ref_info
->refs_size
);
1394 ref_info
->count
[regno
] = count
;
1397 /* The bitmap size is not decremented when refs are deleted. So
1398 reset it now that we have squished out all of the empty
1400 ref_info
->table_size
= offset
;
1404 /* Take build ref table for either the uses or defs from the reg-use
1405 or reg-def chains. This version processes the refs in insn order
1406 which is likely to be best if processing some segment of the
1410 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1413 bool include_eq_uses
)
1416 unsigned int bb_index
;
1417 unsigned int m
= df
->regs_inited
;
1418 unsigned int offset
= 0;
1421 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1423 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1424 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1426 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1427 df_check_and_grow_ref_info (ref_info
, 1);
1429 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1431 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1436 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1438 unsigned int regno
= DF_REF_REGNO (def
);
1439 ref_info
->count
[regno
]++;
1442 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1444 unsigned int regno
= DF_REF_REGNO (use
);
1445 ref_info
->count
[regno
]++;
1448 FOR_BB_INSNS (bb
, insn
)
1452 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1455 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1457 unsigned int regno
= DF_REF_REGNO (def
);
1458 ref_info
->count
[regno
]++;
1461 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1463 unsigned int regno
= DF_REF_REGNO (use
);
1464 ref_info
->count
[regno
]++;
1466 if (include_eq_uses
)
1467 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1469 unsigned int regno
= DF_REF_REGNO (use
);
1470 ref_info
->count
[regno
]++;
1476 for (r
= start
; r
< m
; r
++)
1478 ref_info
->begin
[r
] = offset
;
1479 offset
+= ref_info
->count
[r
];
1480 ref_info
->count
[r
] = 0;
1483 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1485 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1490 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1492 unsigned int regno
= DF_REF_REGNO (def
);
1496 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1497 DF_REF_ID (def
) = id
;
1498 ref_info
->refs
[id
] = def
;
1502 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1504 unsigned int regno
= DF_REF_REGNO (def
);
1508 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1509 DF_REF_ID (use
) = id
;
1510 ref_info
->refs
[id
] = use
;
1514 FOR_BB_INSNS (bb
, insn
)
1518 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1521 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1523 unsigned int regno
= DF_REF_REGNO (def
);
1527 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1528 DF_REF_ID (def
) = id
;
1529 ref_info
->refs
[id
] = def
;
1533 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1535 unsigned int regno
= DF_REF_REGNO (use
);
1539 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1540 DF_REF_ID (use
) = id
;
1541 ref_info
->refs
[id
] = use
;
1544 if (include_eq_uses
)
1545 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1547 unsigned int regno
= DF_REF_REGNO (use
);
1551 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1552 DF_REF_ID (use
) = id
;
1553 ref_info
->refs
[id
] = use
;
1560 /* The bitmap size is not decremented when refs are deleted. So
1561 reset it now that we have squished out all of the empty
1564 ref_info
->table_size
= offset
;
1567 /* Take build ref table for either the uses or defs from the reg-use
1568 or reg-def chains. */
1571 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1574 bool include_eq_uses
)
1576 if (df
->analyze_subset
)
1577 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1578 include_uses
, include_eq_uses
);
1580 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1581 include_uses
, include_eq_uses
);
1585 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1587 df_add_refs_to_table (unsigned int offset
,
1588 struct df_ref_info
*ref_info
,
1591 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
1592 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
)
1593 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1595 ref_info
->refs
[offset
] = ref
;
1596 DF_REF_ID (ref
) = offset
++;
1602 /* Count the number of refs in all of the insns of BB. Include the
1603 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1604 eq_uses if INCLUDE_EQ_USES. */
1607 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1608 struct df_ref_info
*ref_info
,
1609 bool include_defs
, bool include_uses
,
1610 bool include_eq_uses
)
1615 offset
= df_add_refs_to_table (offset
, ref_info
,
1616 df_get_artificial_defs (bb
->index
));
1618 offset
= df_add_refs_to_table (offset
, ref_info
,
1619 df_get_artificial_uses (bb
->index
));
1621 FOR_BB_INSNS (bb
, insn
)
1624 unsigned int uid
= INSN_UID (insn
);
1626 offset
= df_add_refs_to_table (offset
, ref_info
,
1627 DF_INSN_UID_DEFS (uid
));
1629 offset
= df_add_refs_to_table (offset
, ref_info
,
1630 DF_INSN_UID_USES (uid
));
1631 if (include_eq_uses
)
1632 offset
= df_add_refs_to_table (offset
, ref_info
,
1633 DF_INSN_UID_EQ_USES (uid
));
1639 /* Organize the refs by insn into the table in REF_INFO. If
1640 blocks_to_analyze is defined, use that set, otherwise the entire
1641 program. Include the defs if INCLUDE_DEFS. Include the uses if
1642 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1645 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1646 bool include_defs
, bool include_uses
,
1647 bool include_eq_uses
)
1650 unsigned int offset
= 0;
1652 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1653 df_check_and_grow_ref_info (ref_info
, 1);
1654 if (df
->blocks_to_analyze
)
1659 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1661 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun
,
1664 include_defs
, include_uses
,
1668 ref_info
->table_size
= offset
;
1672 FOR_ALL_BB_FN (bb
, cfun
)
1673 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1674 include_defs
, include_uses
,
1676 ref_info
->table_size
= offset
;
1681 /* If the use refs in DF are not organized, reorganize them. */
1684 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1686 if (order
== df
->use_info
.ref_order
)
1691 case DF_REF_ORDER_BY_REG
:
1692 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1695 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1696 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1699 case DF_REF_ORDER_BY_INSN
:
1700 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1703 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1704 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1707 case DF_REF_ORDER_NO_TABLE
:
1708 free (df
->use_info
.refs
);
1709 df
->use_info
.refs
= NULL
;
1710 df
->use_info
.refs_size
= 0;
1713 case DF_REF_ORDER_UNORDERED
:
1714 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1719 df
->use_info
.ref_order
= order
;
1723 /* If the def refs in DF are not organized, reorganize them. */
1726 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1728 if (order
== df
->def_info
.ref_order
)
1733 case DF_REF_ORDER_BY_REG
:
1734 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1737 case DF_REF_ORDER_BY_INSN
:
1738 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1741 case DF_REF_ORDER_NO_TABLE
:
1742 free (df
->def_info
.refs
);
1743 df
->def_info
.refs
= NULL
;
1744 df
->def_info
.refs_size
= 0;
1747 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1748 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1749 case DF_REF_ORDER_UNORDERED
:
1750 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1755 df
->def_info
.ref_order
= order
;
1759 /* Change all of the basic block references in INSN to use the insn's
1760 current basic block. This function is called from routines that move
1761 instructions from one block to another. */
1764 df_insn_change_bb (rtx_insn
*insn
, basic_block new_bb
)
1766 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1767 struct df_insn_info
*insn_info
;
1768 unsigned int uid
= INSN_UID (insn
);
1770 if (old_bb
== new_bb
)
1773 set_block_for_insn (insn
, new_bb
);
1779 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1781 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1782 if (insn_info
== NULL
)
1785 fprintf (dump_file
, " unscanned insn\n");
1786 df_insn_rescan (insn
);
1793 df_set_bb_dirty (new_bb
);
1797 fprintf (dump_file
, " from %d to %d\n",
1798 old_bb
->index
, new_bb
->index
);
1799 df_set_bb_dirty (old_bb
);
1803 fprintf (dump_file
, " to %d\n", new_bb
->index
);
1807 /* Helper function for df_ref_change_reg_with_loc. */
1810 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
1811 struct df_reg_info
*new_df
,
1812 unsigned int new_regno
, rtx loc
)
1814 df_ref the_ref
= old_df
->reg_chain
;
1818 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
1819 && DF_REF_LOC (the_ref
)
1820 && (*DF_REF_LOC (the_ref
) == loc
))
1822 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
1823 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
1825 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
1827 DF_REF_REGNO (the_ref
) = new_regno
;
1828 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
1830 /* Pull the_ref out of the old regno chain. */
1832 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
1834 old_df
->reg_chain
= next_ref
;
1836 DF_REF_PREV_REG (next_ref
) = prev_ref
;
1839 /* Put the ref into the new regno chain. */
1840 DF_REF_PREV_REG (the_ref
) = NULL
;
1841 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
1842 if (new_df
->reg_chain
)
1843 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
1844 new_df
->reg_chain
= the_ref
;
1846 if (DF_REF_BB (the_ref
))
1847 df_set_bb_dirty (DF_REF_BB (the_ref
));
1849 /* Need to sort the record again that the ref was in because
1850 the regno is a sorting key. First, find the right
1852 if (DF_REF_REG_DEF_P (the_ref
))
1853 ref_ptr
= &insn_info
->defs
;
1854 else if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
1855 ref_ptr
= &insn_info
->eq_uses
;
1857 ref_ptr
= &insn_info
->uses
;
1859 fprintf (dump_file
, "changing reg in insn %d\n",
1860 DF_REF_INSN_UID (the_ref
));
1862 /* Stop if we find the current reference or where the reference
1864 while (*ref_ptr
!= the_ref
&& df_ref_compare (*ref_ptr
, the_ref
) < 0)
1865 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1866 if (*ref_ptr
!= the_ref
)
1868 /* The reference needs to be promoted up the list. */
1869 df_ref next
= DF_REF_NEXT_LOC (the_ref
);
1870 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1873 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1874 while (*ref_ptr
!= the_ref
);
1877 else if (DF_REF_NEXT_LOC (the_ref
)
1878 && df_ref_compare (the_ref
, DF_REF_NEXT_LOC (the_ref
)) > 0)
1880 /* The reference needs to be demoted down the list. */
1881 *ref_ptr
= DF_REF_NEXT_LOC (the_ref
);
1883 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1884 while (*ref_ptr
&& df_ref_compare (the_ref
, *ref_ptr
) > 0);
1885 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1892 the_ref
= DF_REF_NEXT_REG (the_ref
);
1897 /* Change the regno of register LOC to NEW_REGNO and update the df
1898 information accordingly. Refs that do not match LOC are not changed
1899 which means that artificial refs are not changed since they have no loc.
1900 This call is to support the SET_REGNO macro. */
1903 df_ref_change_reg_with_loc (rtx loc
, unsigned int new_regno
)
1905 unsigned int old_regno
= REGNO (loc
);
1906 if (old_regno
== new_regno
)
1911 df_grow_reg_info ();
1913 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
1914 DF_REG_DEF_GET (new_regno
),
1916 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
1917 DF_REG_USE_GET (new_regno
),
1919 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
1920 DF_REG_EQ_USE_GET (new_regno
),
1923 set_mode_and_regno (loc
, GET_MODE (loc
), new_regno
);
1927 /* Delete the mw_hardregs that point into the eq_notes. */
1930 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
1932 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
;
1933 struct df_scan_problem_data
*problem_data
1934 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1938 df_mw_hardreg
*mw
= *mw_ptr
;
1939 if (mw
->flags
& DF_REF_IN_NOTE
)
1941 *mw_ptr
= DF_MWS_NEXT (mw
);
1942 problem_data
->mw_reg_pool
->remove (mw
);
1945 mw_ptr
= &DF_MWS_NEXT (mw
);
1950 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
1953 df_notes_rescan (rtx_insn
*insn
)
1955 struct df_insn_info
*insn_info
;
1956 unsigned int uid
= INSN_UID (insn
);
1961 /* The client has disabled rescanning and plans to do it itself. */
1962 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1965 /* Do nothing if the insn hasn't been emitted yet. */
1966 if (!BLOCK_FOR_INSN (insn
))
1969 df_grow_bb_info (df_scan
);
1970 df_grow_reg_info ();
1972 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1974 /* The client has deferred rescanning. */
1975 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1979 insn_info
= df_insn_create_insn_record (insn
);
1980 insn_info
->defs
= 0;
1981 insn_info
->uses
= 0;
1982 insn_info
->eq_uses
= 0;
1983 insn_info
->mw_hardregs
= 0;
1986 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1987 /* If the insn is set to be rescanned, it does not need to also
1988 be notes rescanned. */
1989 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
1990 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
1994 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1995 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1999 basic_block bb
= BLOCK_FOR_INSN (insn
);
2001 struct df_collection_rec collection_rec
;
2004 df_mw_hardreg_chain_delete_eq_uses (insn_info
);
2005 df_ref_chain_delete (insn_info
->eq_uses
);
2006 insn_info
->eq_uses
= NULL
;
2008 /* Process REG_EQUIV/REG_EQUAL notes */
2009 for (note
= REG_NOTES (insn
); note
;
2010 note
= XEXP (note
, 1))
2012 switch (REG_NOTE_KIND (note
))
2016 df_uses_record (&collection_rec
,
2017 &XEXP (note
, 0), DF_REF_REG_USE
,
2018 bb
, insn_info
, DF_REF_IN_NOTE
);
2024 /* Find some place to put any new mw_hardregs. */
2025 df_canonize_collection_rec (&collection_rec
);
2026 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
, *mw
;
2027 FOR_EACH_VEC_ELT (collection_rec
.mw_vec
, i
, mw
)
2029 while (*mw_ptr
&& df_mw_compare (*mw_ptr
, mw
) < 0)
2030 mw_ptr
= &DF_MWS_NEXT (*mw_ptr
);
2031 DF_MWS_NEXT (mw
) = *mw_ptr
;
2033 mw_ptr
= &DF_MWS_NEXT (mw
);
2035 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_eq_uses
);
2038 df_insn_rescan (insn
);
2043 /*----------------------------------------------------------------------------
2044 Hard core instruction scanning code. No external interfaces here,
2045 just a lot of routines that look inside insns.
2046 ----------------------------------------------------------------------------*/
2049 /* Return true if the contents of two df_ref's are identical.
2050 It ignores DF_REF_MARKER. */
2053 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2061 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2062 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2063 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2064 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2065 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2066 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2067 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2068 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2071 switch (DF_REF_CLASS (ref1
))
2073 case DF_REF_ARTIFICIAL
:
2077 case DF_REF_REGULAR
:
2078 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2087 /* Compare REF1 and REF2 for sorting. This is only called from places
2088 where all of the refs are of the same type, in the same insn, and
2089 have the same bb. So these fields are not checked. */
2092 df_ref_compare (df_ref ref1
, df_ref ref2
)
2094 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2095 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2097 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2098 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2100 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2101 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2103 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2104 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2106 /* Cannot look at the LOC field on artificial refs. */
2107 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2108 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2109 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2111 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2113 /* If two refs are identical except that one of them has is from
2114 a mw and one is not, we need to have the one with the mw
2116 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2117 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2118 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2119 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2125 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2128 /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2. */
2131 df_ref_ptr_compare (const void *r1
, const void *r2
)
2133 return df_ref_compare (*(const df_ref
*) r1
, *(const df_ref
*) r2
);
2136 /* Sort and compress a set of refs. */
2139 df_sort_and_compress_refs (vec
<df_ref
, va_heap
> *ref_vec
)
2143 unsigned int dist
= 0;
2145 count
= ref_vec
->length ();
2147 /* If there are 1 or 0 elements, there is nothing to do. */
2150 else if (count
== 2)
2152 df_ref r0
= (*ref_vec
)[0];
2153 df_ref r1
= (*ref_vec
)[1];
2154 if (df_ref_compare (r0
, r1
) > 0)
2155 std::swap ((*ref_vec
)[0], (*ref_vec
)[1]);
2159 for (i
= 0; i
< count
- 1; i
++)
2161 df_ref r0
= (*ref_vec
)[i
];
2162 df_ref r1
= (*ref_vec
)[i
+ 1];
2163 if (df_ref_compare (r0
, r1
) >= 0)
2166 /* If the array is already strictly ordered,
2167 which is the most common case for large COUNT case
2168 (which happens for CALL INSNs),
2169 no need to sort and filter out duplicate.
2170 Simply return the count.
2171 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2172 of DF_REF_COMPARE. */
2175 ref_vec
->qsort (df_ref_ptr_compare
);
2178 for (i
=0; i
<count
-dist
; i
++)
2180 /* Find the next ref that is not equal to the current ref. */
2181 while (i
+ dist
+ 1 < count
2182 && df_ref_equal_p ((*ref_vec
)[i
],
2183 (*ref_vec
)[i
+ dist
+ 1]))
2185 df_free_ref ((*ref_vec
)[i
+ dist
+ 1]);
2188 /* Copy it down to the next position. */
2189 if (dist
&& i
+ dist
+ 1 < count
)
2190 (*ref_vec
)[i
+ 1] = (*ref_vec
)[i
+ dist
+ 1];
2194 ref_vec
->truncate (count
);
2198 /* Return true if the contents of two df_ref's are identical.
2199 It ignores DF_REF_MARKER. */
2202 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2206 return (mw1
== mw2
) ||
2207 (mw1
->mw_reg
== mw2
->mw_reg
2208 && mw1
->type
== mw2
->type
2209 && mw1
->flags
== mw2
->flags
2210 && mw1
->start_regno
== mw2
->start_regno
2211 && mw1
->end_regno
== mw2
->end_regno
);
2215 /* Compare MW1 and MW2 for sorting. */
2218 df_mw_compare (const df_mw_hardreg
*mw1
, const df_mw_hardreg
*mw2
)
2220 if (mw1
->type
!= mw2
->type
)
2221 return mw1
->type
- mw2
->type
;
2223 if (mw1
->flags
!= mw2
->flags
)
2224 return mw1
->flags
- mw2
->flags
;
2226 if (mw1
->start_regno
!= mw2
->start_regno
)
2227 return mw1
->start_regno
- mw2
->start_regno
;
2229 if (mw1
->end_regno
!= mw2
->end_regno
)
2230 return mw1
->end_regno
- mw2
->end_regno
;
2232 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2233 return mw1
->mw_order
- mw2
->mw_order
;
2238 /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2. */
2241 df_mw_ptr_compare (const void *m1
, const void *m2
)
2243 return df_mw_compare (*(const df_mw_hardreg
*const *) m1
,
2244 *(const df_mw_hardreg
*const *) m2
);
2247 /* Sort and compress a set of refs. */
2250 df_sort_and_compress_mws (vec
<df_mw_hardreg_ptr
, va_heap
> *mw_vec
)
2253 struct df_scan_problem_data
*problem_data
2254 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2256 unsigned int dist
= 0;
2258 count
= mw_vec
->length ();
2261 else if (count
== 2)
2263 struct df_mw_hardreg
*m0
= (*mw_vec
)[0];
2264 struct df_mw_hardreg
*m1
= (*mw_vec
)[1];
2265 if (df_mw_compare (m0
, m1
) > 0)
2267 struct df_mw_hardreg
*tmp
= (*mw_vec
)[0];
2268 (*mw_vec
)[0] = (*mw_vec
)[1];
2273 mw_vec
->qsort (df_mw_ptr_compare
);
2275 for (i
=0; i
<count
-dist
; i
++)
2277 /* Find the next ref that is not equal to the current ref. */
2278 while (i
+ dist
+ 1 < count
2279 && df_mw_equal_p ((*mw_vec
)[i
], (*mw_vec
)[i
+ dist
+ 1]))
2281 problem_data
->mw_reg_pool
->remove ((*mw_vec
)[i
+ dist
+ 1]);
2284 /* Copy it down to the next position. */
2285 if (dist
&& i
+ dist
+ 1 < count
)
2286 (*mw_vec
)[i
+ 1] = (*mw_vec
)[i
+ dist
+ 1];
2290 mw_vec
->truncate (count
);
2294 /* Sort and remove duplicates from the COLLECTION_REC. */
2297 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2299 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2300 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2301 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2302 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2306 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2309 df_install_ref (df_ref this_ref
,
2310 struct df_reg_info
*reg_info
,
2311 struct df_ref_info
*ref_info
,
2314 unsigned int regno
= DF_REF_REGNO (this_ref
);
2315 /* Add the ref to the reg_{def,use,eq_use} chain. */
2316 df_ref head
= reg_info
->reg_chain
;
2318 reg_info
->reg_chain
= this_ref
;
2321 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2323 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2324 df
->hard_regs_live_count
[regno
]++;
2327 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2328 && DF_REF_PREV_REG (this_ref
) == NULL
);
2330 DF_REF_NEXT_REG (this_ref
) = head
;
2332 /* We cannot actually link to the head of the chain. */
2333 DF_REF_PREV_REG (this_ref
) = NULL
;
2336 DF_REF_PREV_REG (head
) = this_ref
;
2340 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2341 df_check_and_grow_ref_info (ref_info
, 1);
2342 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2343 /* Add the ref to the big array of defs. */
2344 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2345 ref_info
->table_size
++;
2348 DF_REF_ID (this_ref
) = -1;
2350 ref_info
->total_size
++;
2354 /* This function takes one of the groups of refs (defs, uses or
2355 eq_uses) and installs the entire group into the insn. It also adds
2356 each of these refs into the appropriate chains. */
2359 df_install_refs (basic_block bb
,
2360 const vec
<df_ref
, va_heap
> *old_vec
,
2361 struct df_reg_info
**reg_info
,
2362 struct df_ref_info
*ref_info
,
2365 unsigned int count
= old_vec
->length ();
2372 switch (ref_info
->ref_order
)
2374 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2375 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2376 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2377 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2378 add_to_table
= true;
2380 case DF_REF_ORDER_UNORDERED
:
2381 case DF_REF_ORDER_BY_REG
:
2382 case DF_REF_ORDER_BY_INSN
:
2383 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2384 add_to_table
= !is_notes
;
2387 add_to_table
= false;
2391 /* Do not add if ref is not in the right blocks. */
2392 if (add_to_table
&& df
->analyze_subset
)
2393 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2395 FOR_EACH_VEC_ELT (*old_vec
, ix
, this_ref
)
2397 DF_REF_NEXT_LOC (this_ref
) = (ix
+ 1 < old_vec
->length ()
2398 ? (*old_vec
)[ix
+ 1]
2400 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2401 ref_info
, add_to_table
);
2403 return (*old_vec
)[0];
2410 /* This function takes the mws installs the entire group into the
2413 static struct df_mw_hardreg
*
2414 df_install_mws (const vec
<df_mw_hardreg_ptr
, va_heap
> *old_vec
)
2416 unsigned int count
= old_vec
->length ();
2419 for (unsigned int i
= 0; i
< count
- 1; i
++)
2420 DF_MWS_NEXT ((*old_vec
)[i
]) = (*old_vec
)[i
+ 1];
2421 DF_MWS_NEXT ((*old_vec
)[count
- 1]) = 0;
2422 return (*old_vec
)[0];
2429 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2430 chains and update other necessary information. */
2433 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2434 basic_block bb
, rtx_insn
*insn
, unsigned int flags
)
2438 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2439 /* If there is a vector in the collection rec, add it to the
2440 insn. A null rec is a signal that the caller will handle the
2442 if (flags
& copy_defs
)
2444 gcc_checking_assert (!insn_rec
->defs
);
2446 = df_install_refs (bb
, &collection_rec
->def_vec
,
2448 &df
->def_info
, false);
2450 if (flags
& copy_uses
)
2452 gcc_checking_assert (!insn_rec
->uses
);
2454 = df_install_refs (bb
, &collection_rec
->use_vec
,
2456 &df
->use_info
, false);
2458 if (flags
& copy_eq_uses
)
2460 gcc_checking_assert (!insn_rec
->eq_uses
);
2462 = df_install_refs (bb
, &collection_rec
->eq_use_vec
,
2464 &df
->use_info
, true);
2466 if (flags
& copy_mw
)
2468 gcc_checking_assert (!insn_rec
->mw_hardregs
);
2469 insn_rec
->mw_hardregs
2470 = df_install_mws (&collection_rec
->mw_vec
);
2475 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2477 gcc_checking_assert (!bb_info
->artificial_defs
);
2478 bb_info
->artificial_defs
2479 = df_install_refs (bb
, &collection_rec
->def_vec
,
2481 &df
->def_info
, false);
2482 gcc_checking_assert (!bb_info
->artificial_uses
);
2483 bb_info
->artificial_uses
2484 = df_install_refs (bb
, &collection_rec
->use_vec
,
2486 &df
->use_info
, false);
2491 /* Allocate a ref and initialize its fields. */
2494 df_ref_create_structure (enum df_ref_class cl
,
2495 struct df_collection_rec
*collection_rec
,
2497 basic_block bb
, struct df_insn_info
*info
,
2498 enum df_ref_type ref_type
,
2501 df_ref this_ref
= NULL
;
2502 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2503 struct df_scan_problem_data
*problem_data
2504 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2509 this_ref
= (df_ref
) (problem_data
->ref_base_pool
->allocate ());
2510 gcc_checking_assert (loc
== NULL
);
2513 case DF_REF_ARTIFICIAL
:
2514 this_ref
= (df_ref
) (problem_data
->ref_artificial_pool
->allocate ());
2515 this_ref
->artificial_ref
.bb
= bb
;
2516 gcc_checking_assert (loc
== NULL
);
2519 case DF_REF_REGULAR
:
2520 this_ref
= (df_ref
) (problem_data
->ref_regular_pool
->allocate ());
2521 this_ref
->regular_ref
.loc
= loc
;
2522 gcc_checking_assert (loc
);
2526 DF_REF_CLASS (this_ref
) = cl
;
2527 DF_REF_ID (this_ref
) = -1;
2528 DF_REF_REG (this_ref
) = reg
;
2529 DF_REF_REGNO (this_ref
) = regno
;
2530 DF_REF_TYPE (this_ref
) = ref_type
;
2531 DF_REF_INSN_INFO (this_ref
) = info
;
2532 DF_REF_CHAIN (this_ref
) = NULL
;
2533 DF_REF_FLAGS (this_ref
) = ref_flags
;
2534 DF_REF_NEXT_REG (this_ref
) = NULL
;
2535 DF_REF_PREV_REG (this_ref
) = NULL
;
2536 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2538 /* We need to clear this bit because fwprop, and in the future
2539 possibly other optimizations sometimes create new refs using ond
2540 refs as the model. */
2541 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2543 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2544 if (regno
< FIRST_PSEUDO_REGISTER
2545 && !DF_REF_IS_ARTIFICIAL (this_ref
)
2546 && !DEBUG_INSN_P (DF_REF_INSN (this_ref
)))
2548 if (DF_REF_REG_DEF_P (this_ref
))
2550 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2551 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2553 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2554 && (regno
== FRAME_POINTER_REGNUM
2555 || regno
== ARG_POINTER_REGNUM
)))
2556 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2561 if (DF_REF_REG_DEF_P (this_ref
))
2562 collection_rec
->def_vec
.safe_push (this_ref
);
2563 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2564 collection_rec
->eq_use_vec
.safe_push (this_ref
);
2566 collection_rec
->use_vec
.safe_push (this_ref
);
2569 df_install_ref_incremental (this_ref
);
2575 /* Create new references of type DF_REF_TYPE for each part of register REG
2576 at address LOC within INSN of BB. */
2580 df_ref_record (enum df_ref_class cl
,
2581 struct df_collection_rec
*collection_rec
,
2583 basic_block bb
, struct df_insn_info
*insn_info
,
2584 enum df_ref_type ref_type
,
2589 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2591 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2592 if (regno
< FIRST_PSEUDO_REGISTER
)
2594 struct df_mw_hardreg
*hardreg
= NULL
;
2595 struct df_scan_problem_data
*problem_data
2596 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2598 unsigned int endregno
;
2601 if (GET_CODE (reg
) == SUBREG
)
2603 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2604 SUBREG_BYTE (reg
), GET_MODE (reg
));
2605 endregno
= regno
+ subreg_nregs (reg
);
2608 endregno
= END_REGNO (reg
);
2610 /* If this is a multiword hardreg, we create some extra
2611 datastructures that will enable us to easily build REG_DEAD
2612 and REG_UNUSED notes. */
2614 && (endregno
!= regno
+ 1) && insn_info
)
2616 /* Sets to a subreg of a multiword register are partial.
2617 Sets to a non-subreg of a multiword register are not. */
2618 if (GET_CODE (reg
) == SUBREG
)
2619 ref_flags
|= DF_REF_PARTIAL
;
2620 ref_flags
|= DF_REF_MW_HARDREG
;
2622 hardreg
= problem_data
->mw_reg_pool
->allocate ();
2623 hardreg
->type
= ref_type
;
2624 hardreg
->flags
= ref_flags
;
2625 hardreg
->mw_reg
= reg
;
2626 hardreg
->start_regno
= regno
;
2627 hardreg
->end_regno
= endregno
- 1;
2628 hardreg
->mw_order
= df
->ref_order
++;
2629 collection_rec
->mw_vec
.safe_push (hardreg
);
2632 for (i
= regno
; i
< endregno
; i
++)
2634 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2635 bb
, insn_info
, ref_type
, ref_flags
);
2637 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2642 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2643 ref_type
, ref_flags
);
2648 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2649 covered by the outer mode is smaller than that covered by the inner mode,
2650 is a read-modify-write operation.
2651 This function returns true iff the SUBREG X is such a SUBREG. */
2654 df_read_modify_subreg_p (rtx x
)
2656 unsigned int isize
, osize
;
2657 if (GET_CODE (x
) != SUBREG
)
2659 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2660 osize
= GET_MODE_SIZE (GET_MODE (x
));
2661 return isize
> osize
2662 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2666 /* Process all the registers defined in the rtx pointed by LOC.
2667 Autoincrement/decrement definitions will be picked up by df_uses_record.
2668 Any change here has to be matched in df_find_hard_reg_defs_1. */
2671 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2672 rtx
*loc
, basic_block bb
, struct df_insn_info
*insn_info
,
2677 /* It is legal to have a set destination be a parallel. */
2678 if (GET_CODE (dst
) == PARALLEL
)
2681 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2683 rtx temp
= XVECEXP (dst
, 0, i
);
2684 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2685 df_def_record_1 (collection_rec
, &XEXP (temp
, 0),
2686 bb
, insn_info
, flags
);
2691 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2693 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2695 loc
= &XEXP (dst
, 0);
2699 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2701 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2703 loc
= &XEXP (dst
, 0);
2707 /* At this point if we do not have a reg or a subreg, just return. */
2710 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2711 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2713 /* We want to keep sp alive everywhere - by making all
2714 writes to sp also use of sp. */
2715 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2716 df_ref_record (DF_REF_BASE
, collection_rec
,
2717 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
2719 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2721 if (df_read_modify_subreg_p (dst
))
2722 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2724 flags
|= DF_REF_SUBREG
;
2726 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2727 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2732 /* Process all the registers defined in the pattern rtx, X. Any change
2733 here has to be matched in df_find_hard_reg_defs. */
2736 df_defs_record (struct df_collection_rec
*collection_rec
,
2737 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2740 RTX_CODE code
= GET_CODE (x
);
2746 df_def_record_1 (collection_rec
, &SET_DEST (x
), bb
, insn_info
, flags
);
2750 flags
|= DF_REF_MUST_CLOBBER
;
2751 df_def_record_1 (collection_rec
, &XEXP (x
, 0), bb
, insn_info
, flags
);
2755 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
2756 bb
, insn_info
, DF_REF_CONDITIONAL
);
2760 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2761 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
),
2762 bb
, insn_info
, flags
);
2765 /* No DEFs to record in other cases */
2770 /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
2771 destination of a set or clobber. This has to match the logic in
2772 df_defs_record_1. */
2775 df_find_hard_reg_defs_1 (rtx dst
, HARD_REG_SET
*defs
)
2777 /* It is legal to have a set destination be a parallel. */
2778 if (GET_CODE (dst
) == PARALLEL
)
2781 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2783 rtx temp
= XVECEXP (dst
, 0, i
);
2784 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2785 df_find_hard_reg_defs_1 (XEXP (temp
, 0), defs
);
2790 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2791 dst
= XEXP (dst
, 0);
2793 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2794 dst
= XEXP (dst
, 0);
2796 /* At this point if we do not have a reg or a subreg, just return. */
2797 if (REG_P (dst
) && HARD_REGISTER_P (dst
))
2798 SET_HARD_REG_BIT (*defs
, REGNO (dst
));
2799 else if (GET_CODE (dst
) == SUBREG
2800 && REG_P (SUBREG_REG (dst
)) && HARD_REGISTER_P (dst
))
2801 SET_HARD_REG_BIT (*defs
, REGNO (SUBREG_REG (dst
)));
2804 /* Set bits in *DEFS for hard registers defined in the pattern X. This
2805 has to match the logic in df_defs_record. */
2808 df_find_hard_reg_defs (rtx x
, HARD_REG_SET
*defs
)
2810 RTX_CODE code
= GET_CODE (x
);
2816 df_find_hard_reg_defs_1 (SET_DEST (x
), defs
);
2820 df_find_hard_reg_defs_1 (XEXP (x
, 0), defs
);
2824 df_find_hard_reg_defs (COND_EXEC_CODE (x
), defs
);
2828 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2829 df_find_hard_reg_defs (XVECEXP (x
, 0, i
), defs
);
2832 /* No DEFs to record in other cases */
2838 /* Process all the registers used in the rtx at address LOC. */
2841 df_uses_record (struct df_collection_rec
*collection_rec
,
2842 rtx
*loc
, enum df_ref_type ref_type
,
2843 basic_block bb
, struct df_insn_info
*insn_info
,
2853 code
= GET_CODE (x
);
2867 /* If we are clobbering a MEM, mark any registers inside the address
2869 if (MEM_P (XEXP (x
, 0)))
2870 df_uses_record (collection_rec
,
2871 &XEXP (XEXP (x
, 0), 0),
2872 DF_REF_REG_MEM_STORE
,
2876 /* If we're clobbering a REG then we have a def so ignore. */
2880 df_uses_record (collection_rec
,
2881 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
2882 bb
, insn_info
, flags
& DF_REF_IN_NOTE
);
2886 /* While we're here, optimize this case. */
2887 flags
|= DF_REF_PARTIAL
;
2888 /* In case the SUBREG is not of a REG, do not optimize. */
2889 if (!REG_P (SUBREG_REG (x
)))
2891 loc
= &SUBREG_REG (x
);
2892 df_uses_record (collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
);
2895 /* ... Fall through ... */
2898 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2899 x
, loc
, bb
, insn_info
,
2906 df_uses_record (collection_rec
,
2907 &XEXP (x
, 1), ref_type
, bb
, insn_info
, flags
);
2908 df_uses_record (collection_rec
,
2909 &XEXP (x
, 2), ref_type
, bb
, insn_info
, flags
);
2911 /* If the parameters to the zero or sign extract are
2912 constants, strip them off and recurse, otherwise there is
2913 no information that we can gain from this operation. */
2914 if (code
== ZERO_EXTRACT
)
2915 flags
|= DF_REF_ZERO_EXTRACT
;
2917 flags
|= DF_REF_SIGN_EXTRACT
;
2919 df_uses_record (collection_rec
,
2920 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
);
2927 rtx dst
= SET_DEST (x
);
2928 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
2929 df_uses_record (collection_rec
,
2930 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
);
2932 switch (GET_CODE (dst
))
2935 if (df_read_modify_subreg_p (dst
))
2937 df_uses_record (collection_rec
, &SUBREG_REG (dst
),
2938 DF_REF_REG_USE
, bb
, insn_info
,
2939 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
);
2950 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2951 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
);
2953 case STRICT_LOW_PART
:
2955 rtx
*temp
= &XEXP (dst
, 0);
2956 /* A strict_low_part uses the whole REG and not just the
2958 dst
= XEXP (dst
, 0);
2959 df_uses_record (collection_rec
,
2960 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
2961 DF_REF_REG_USE
, bb
, insn_info
,
2962 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
);
2967 df_uses_record (collection_rec
, &XEXP (dst
, 1),
2968 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2969 df_uses_record (collection_rec
, &XEXP (dst
, 2),
2970 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2971 if (GET_CODE (XEXP (dst
,0)) == MEM
)
2972 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2973 DF_REF_REG_USE
, bb
, insn_info
,
2976 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2977 DF_REF_REG_USE
, bb
, insn_info
,
2978 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
);
2993 case UNSPEC_VOLATILE
:
2997 /* Traditional and volatile asm instructions must be
2998 considered to use and clobber all hard registers, all
2999 pseudo-registers and all of memory. So must TRAP_IF and
3000 UNSPEC_VOLATILE operations.
3002 Consider for instance a volatile asm that changes the fpu
3003 rounding mode. An insn should not be moved across this
3004 even if it only uses pseudo-regs because it might give an
3005 incorrectly rounded result.
3007 However, flow.c's liveness computation did *not* do this,
3008 giving the reasoning as " ?!? Unfortunately, marking all
3009 hard registers as live causes massive problems for the
3010 register allocator and marking all pseudos as live creates
3011 mountains of uninitialized variable warnings."
3013 In order to maintain the status quo with regard to liveness
3014 and uses, we do what flow.c did and just mark any regs we
3015 can find in ASM_OPERANDS as used. In global asm insns are
3016 scanned and regs_asm_clobbered is filled out.
3018 For all ASM_OPERANDS, we must traverse the vector of input
3019 operands. We can not just fall through here since then we
3020 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3021 which do not indicate traditional asms unlike their normal
3023 if (code
== ASM_OPERANDS
)
3027 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3028 df_uses_record (collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3029 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3036 df_uses_record (collection_rec
,
3037 &PAT_VAR_LOCATION_LOC (x
),
3038 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3047 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3048 /* Catch the def of the register being modified. */
3049 df_ref_record (DF_REF_REGULAR
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3052 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
);
3054 /* ... Fall through to handle uses ... */
3060 /* Recursively scan the operands of this expression. */
3062 const char *fmt
= GET_RTX_FORMAT (code
);
3065 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3069 /* Tail recursive case: save a function call level. */
3075 df_uses_record (collection_rec
, &XEXP (x
, i
), ref_type
,
3076 bb
, insn_info
, flags
);
3078 else if (fmt
[i
] == 'E')
3081 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3082 df_uses_record (collection_rec
,
3083 &XVECEXP (x
, i
, j
), ref_type
,
3084 bb
, insn_info
, flags
);
3093 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3096 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3101 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
3103 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3107 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3108 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3109 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3110 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
);
3111 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3117 /* Get call's extra defs and uses (track caller-saved registers). */
3120 df_get_call_refs (struct df_collection_rec
*collection_rec
,
3122 struct df_insn_info
*insn_info
,
3126 bool is_sibling_call
;
3128 HARD_REG_SET defs_generated
;
3129 HARD_REG_SET fn_reg_set_usage
;
3131 CLEAR_HARD_REG_SET (defs_generated
);
3132 df_find_hard_reg_defs (PATTERN (insn_info
->insn
), &defs_generated
);
3133 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3134 get_call_reg_set_usage (insn_info
->insn
, &fn_reg_set_usage
,
3135 regs_invalidated_by_call
);
3137 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3139 if (i
== STACK_POINTER_REGNUM
)
3140 /* The stack ptr is used (honorarily) by a CALL insn. */
3141 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3142 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3143 DF_REF_CALL_STACK_USAGE
| flags
);
3144 else if (global_regs
[i
])
3146 /* Calls to const functions cannot access any global registers and
3147 calls to pure functions cannot set them. All other calls may
3148 reference any of the global registers, so they are recorded as
3150 if (!RTL_CONST_CALL_P (insn_info
->insn
))
3152 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3153 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
3154 if (!RTL_PURE_CALL_P (insn_info
->insn
))
3155 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3156 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3159 else if (TEST_HARD_REG_BIT (fn_reg_set_usage
, i
)
3160 /* no clobbers for regs that are the result of the call */
3161 && !TEST_HARD_REG_BIT (defs_generated
, i
)
3162 && (!is_sibling_call
3163 || !bitmap_bit_p (df
->exit_block_uses
, i
)
3164 || refers_to_regno_p (i
, crtl
->return_rtx
)))
3165 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3166 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3167 DF_REF_MAY_CLOBBER
| flags
);
3170 /* Record the registers used to pass arguments, and explicitly
3171 noted as clobbered. */
3172 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3173 note
= XEXP (note
, 1))
3175 if (GET_CODE (XEXP (note
, 0)) == USE
)
3176 df_uses_record (collection_rec
, &XEXP (XEXP (note
, 0), 0),
3177 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3178 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3180 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3182 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3183 if (!TEST_HARD_REG_BIT (defs_generated
, regno
))
3184 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3188 df_uses_record (collection_rec
, &XEXP (note
, 0),
3189 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3196 /* Collect all refs in the INSN. This function is free of any
3197 side-effect - it will create and return a lists of df_ref's in the
3198 COLLECTION_REC without putting those refs into existing ref chains
3202 df_insn_refs_collect (struct df_collection_rec
*collection_rec
,
3203 basic_block bb
, struct df_insn_info
*insn_info
)
3206 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3208 /* Clear out the collection record. */
3209 collection_rec
->def_vec
.truncate (0);
3210 collection_rec
->use_vec
.truncate (0);
3211 collection_rec
->eq_use_vec
.truncate (0);
3212 collection_rec
->mw_vec
.truncate (0);
3214 /* Process REG_EQUIV/REG_EQUAL notes. */
3215 for (note
= REG_NOTES (insn_info
->insn
); note
;
3216 note
= XEXP (note
, 1))
3218 switch (REG_NOTE_KIND (note
))
3222 df_uses_record (collection_rec
,
3223 &XEXP (note
, 0), DF_REF_REG_USE
,
3224 bb
, insn_info
, DF_REF_IN_NOTE
);
3226 case REG_NON_LOCAL_GOTO
:
3227 /* The frame ptr is used by a non-local goto. */
3228 df_ref_record (DF_REF_BASE
, collection_rec
,
3229 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3230 NULL
, bb
, insn_info
,
3232 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3233 df_ref_record (DF_REF_BASE
, collection_rec
,
3234 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3235 NULL
, bb
, insn_info
,
3243 /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
3244 uses from CALL_INSN_FUNCTION_USAGE. */
3245 if (CALL_P (insn_info
->insn
))
3246 df_get_call_refs (collection_rec
, bb
, insn_info
,
3247 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3249 /* Record other defs. These should be mostly for DF_REF_REGULAR, so
3250 that a qsort on the defs is unnecessary in most cases. */
3251 df_defs_record (collection_rec
,
3252 PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3254 /* Record the register uses. */
3255 df_uses_record (collection_rec
,
3256 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0);
3258 /* DF_REF_CONDITIONAL needs corresponding USES. */
3260 df_get_conditional_uses (collection_rec
);
3262 df_canonize_collection_rec (collection_rec
);
3265 /* Recompute the luids for the insns in BB. */
3268 df_recompute_luids (basic_block bb
)
3273 df_grow_insn_info ();
3275 /* Scan the block an insn at a time from beginning to end. */
3276 FOR_BB_INSNS (bb
, insn
)
3278 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3279 /* Inserting labels does not always trigger the incremental
3283 gcc_assert (!INSN_P (insn
));
3284 insn_info
= df_insn_create_insn_record (insn
);
3287 DF_INSN_INFO_LUID (insn_info
) = luid
;
3294 /* Collect all artificial refs at the block level for BB and add them
3295 to COLLECTION_REC. */
3298 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3300 collection_rec
->def_vec
.truncate (0);
3301 collection_rec
->use_vec
.truncate (0);
3302 collection_rec
->eq_use_vec
.truncate (0);
3303 collection_rec
->mw_vec
.truncate (0);
3305 if (bb
->index
== ENTRY_BLOCK
)
3307 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3310 else if (bb
->index
== EXIT_BLOCK
)
3312 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3316 if (bb_has_eh_pred (bb
))
3319 /* Mark the registers that will contain data for the handler. */
3322 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3323 if (regno
== INVALID_REGNUM
)
3325 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3326 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3330 /* Add the hard_frame_pointer if this block is the target of a
3332 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3333 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3334 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3336 /* Add the artificial uses. */
3337 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3341 bitmap au
= bb_has_eh_pred (bb
)
3342 ? &df
->eh_block_artificial_uses
3343 : &df
->regular_block_artificial_uses
;
3345 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3347 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3348 bb
, NULL
, DF_REF_REG_USE
, 0);
3352 df_canonize_collection_rec (collection_rec
);
3356 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3359 df_bb_refs_record (int bb_index
, bool scan_insns
)
3361 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3368 df_collection_rec collection_rec
;
3369 df_grow_bb_info (df_scan
);
3371 /* Scan the block an insn at a time from beginning to end. */
3372 FOR_BB_INSNS (bb
, insn
)
3374 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3375 gcc_assert (!insn_info
);
3377 insn_info
= df_insn_create_insn_record (insn
);
3380 /* Record refs within INSN. */
3381 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3382 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3383 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
3385 DF_INSN_INFO_LUID (insn_info
) = luid
;
3388 /* Other block level artificial refs */
3389 df_bb_refs_collect (&collection_rec
, bb
);
3390 df_refs_add_to_chains (&collection_rec
, bb
, NULL
, copy_all
);
3392 /* Now that the block has been processed, set the block as dirty so
3393 LR and LIVE will get it processed. */
3394 df_set_bb_dirty (bb
);
3398 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3402 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3408 bitmap_clear (regular_block_artificial_uses
);
3410 if (reload_completed
)
3412 if (frame_pointer_needed
)
3413 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3416 /* Before reload, there are a few registers that must be forced
3417 live everywhere -- which might not already be the case for
3418 blocks within infinite loops. */
3420 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3422 /* Any reference to any pseudo before reload is a potential
3423 reference of the frame pointer. */
3424 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3426 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3427 bitmap_set_bit (regular_block_artificial_uses
,
3428 HARD_FRAME_POINTER_REGNUM
);
3430 /* Pseudos with argument area equivalences may require
3431 reloading via the argument pointer. */
3432 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3433 && fixed_regs
[ARG_POINTER_REGNUM
])
3434 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3436 /* Any constant, or pseudo with constant equivalences, may
3437 require reloading from memory using the pic register. */
3438 if (picreg
!= INVALID_REGNUM
3439 && fixed_regs
[picreg
])
3440 bitmap_set_bit (regular_block_artificial_uses
, picreg
);
3442 /* The all-important stack pointer must always be live. */
3443 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3446 /* EH_USES registers are used:
3447 1) at all insns that might throw (calls or with -fnon-call-exceptions
3450 3) to support backtraces and/or debugging, anywhere between their
3451 initialization and where they the saved registers are restored
3452 from them, including the cases where we don't reach the epilogue
3453 (noreturn call or infinite loop). */
3454 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3456 bitmap_set_bit (regular_block_artificial_uses
, i
);
3461 /* Get the artificial use set for an eh block. */
3464 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3466 bitmap_clear (eh_block_artificial_uses
);
3468 /* The following code (down through the arg_pointer setting APPEARS
3469 to be necessary because there is nothing that actually
3470 describes what the exception handling code may actually need
3472 if (reload_completed
)
3474 if (frame_pointer_needed
)
3476 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3477 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3478 bitmap_set_bit (eh_block_artificial_uses
,
3479 HARD_FRAME_POINTER_REGNUM
);
3481 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3482 && fixed_regs
[ARG_POINTER_REGNUM
])
3483 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3489 /*----------------------------------------------------------------------------
3490 Specialized hard register scanning functions.
3491 ----------------------------------------------------------------------------*/
3494 /* Mark a register in SET. Hard registers in large modes get all
3495 of their component registers set as well. */
3498 df_mark_reg (rtx reg
, void *vset
)
3500 bitmap_set_range ((bitmap
) vset
, REGNO (reg
), REG_NREGS (reg
));
3504 /* Set the bit for regs that are considered being defined at the entry. */
3507 df_get_entry_block_def_set (bitmap entry_block_defs
)
3512 bitmap_clear (entry_block_defs
);
3514 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3517 bitmap_set_bit (entry_block_defs
, i
);
3518 if (FUNCTION_ARG_REGNO_P (i
))
3519 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3522 /* The always important stack pointer. */
3523 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3525 /* Once the prologue has been generated, all of these registers
3526 should just show up in the first regular block. */
3527 if (HAVE_prologue
&& epilogue_completed
)
3529 /* Defs for the callee saved registers are inserted so that the
3530 pushes have some defining location. */
3531 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3532 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3533 bitmap_set_bit (entry_block_defs
, i
);
3536 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3538 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3540 /* If the function has an incoming STATIC_CHAIN, it has to show up
3541 in the entry def set. */
3542 r
= targetm
.calls
.static_chain (current_function_decl
, true);
3544 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3546 if ((!reload_completed
) || frame_pointer_needed
)
3548 /* Any reference to any pseudo before reload is a potential
3549 reference of the frame pointer. */
3550 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3552 /* If they are different, also mark the hard frame pointer as live. */
3553 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3554 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3555 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3558 /* These registers are live everywhere. */
3559 if (!reload_completed
)
3561 /* Pseudos with argument area equivalences may require
3562 reloading via the argument pointer. */
3563 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3564 && fixed_regs
[ARG_POINTER_REGNUM
])
3565 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3567 /* Any constant, or pseudo with constant equivalences, may
3568 require reloading from memory using the pic register. */
3569 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3570 if (picreg
!= INVALID_REGNUM
3571 && fixed_regs
[picreg
])
3572 bitmap_set_bit (entry_block_defs
, picreg
);
3575 #ifdef INCOMING_RETURN_ADDR_RTX
3576 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3577 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3580 targetm
.extra_live_on_entry (entry_block_defs
);
3584 /* Return the (conservative) set of hard registers that are defined on
3585 entry to the function.
3586 It uses df->entry_block_defs to determine which register
3587 reference to include. */
3590 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3591 bitmap entry_block_defs
)
3596 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3598 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3599 ENTRY_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_DEF
, 0);
3602 df_canonize_collection_rec (collection_rec
);
3606 /* Record the (conservative) set of hard registers that are defined on
3607 entry to the function. */
3610 df_record_entry_block_defs (bitmap entry_block_defs
)
3612 struct df_collection_rec collection_rec
;
3613 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3615 /* Process bb_refs chain */
3616 df_refs_add_to_chains (&collection_rec
,
3617 BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
),
3623 /* Update the defs in the entry block. */
3626 df_update_entry_block_defs (void)
3629 bool changed
= false;
3631 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3632 df_get_entry_block_def_set (&refs
);
3633 if (df
->entry_block_defs
)
3635 if (!bitmap_equal_p (df
->entry_block_defs
, &refs
))
3637 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3638 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3639 df_ref_chain_delete (bb_info
->artificial_defs
);
3640 bb_info
->artificial_defs
= NULL
;
3646 struct df_scan_problem_data
*problem_data
3647 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3649 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3655 df_record_entry_block_defs (&refs
);
3656 bitmap_copy (df
->entry_block_defs
, &refs
);
3657 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
3659 bitmap_clear (&refs
);
3663 /* Set the bit for regs that are considered being used at the exit. */
3666 df_get_exit_block_use_set (bitmap exit_block_uses
)
3669 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3671 bitmap_clear (exit_block_uses
);
3673 /* Stack pointer is always live at the exit. */
3674 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3676 /* Mark the frame pointer if needed at the end of the function.
3677 If we end up eliminating it, it will be removed from the live
3678 list of each basic block by reload. */
3680 if ((!reload_completed
) || frame_pointer_needed
)
3682 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3684 /* If they are different, also mark the hard frame pointer as live. */
3685 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3686 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3687 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3690 /* Many architectures have a GP register even without flag_pic.
3691 Assume the pic register is not in use, or will be handled by
3692 other means, if it is not fixed. */
3693 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3694 && picreg
!= INVALID_REGNUM
3695 && fixed_regs
[picreg
])
3696 bitmap_set_bit (exit_block_uses
, picreg
);
3698 /* Mark all global registers, and all registers used by the
3699 epilogue as being live at the end of the function since they
3700 may be referenced by our caller. */
3701 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3702 if (global_regs
[i
] || EPILOGUE_USES (i
))
3703 bitmap_set_bit (exit_block_uses
, i
);
3705 if (HAVE_epilogue
&& epilogue_completed
)
3707 /* Mark all call-saved registers that we actually used. */
3708 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3709 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
3710 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3711 bitmap_set_bit (exit_block_uses
, i
);
3714 /* Mark the registers that will contain data for the handler. */
3715 if (reload_completed
&& crtl
->calls_eh_return
)
3718 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3719 if (regno
== INVALID_REGNUM
)
3721 bitmap_set_bit (exit_block_uses
, regno
);
3724 #ifdef EH_RETURN_STACKADJ_RTX
3725 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3726 && crtl
->calls_eh_return
)
3728 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
3729 if (tmp
&& REG_P (tmp
))
3730 df_mark_reg (tmp
, exit_block_uses
);
3734 #ifdef EH_RETURN_HANDLER_RTX
3735 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3736 && crtl
->calls_eh_return
)
3738 rtx tmp
= EH_RETURN_HANDLER_RTX
;
3739 if (tmp
&& REG_P (tmp
))
3740 df_mark_reg (tmp
, exit_block_uses
);
3744 /* Mark function return value. */
3745 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
3749 /* Return the refs of hard registers that are used in the exit block.
3750 It uses df->exit_block_uses to determine register to include. */
3753 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
3758 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
3759 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3760 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3762 /* It is deliberate that this is not put in the exit block uses but
3763 I do not know why. */
3764 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3766 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
3767 && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun
))
3768 && fixed_regs
[ARG_POINTER_REGNUM
])
3769 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
3770 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3772 df_canonize_collection_rec (collection_rec
);
3776 /* Record the set of hard registers that are used in the exit block.
3777 It uses df->exit_block_uses to determine which bit to include. */
3780 df_record_exit_block_uses (bitmap exit_block_uses
)
3782 struct df_collection_rec collection_rec
;
3783 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
3785 /* Process bb_refs chain */
3786 df_refs_add_to_chains (&collection_rec
,
3787 BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
),
3793 /* Update the uses in the exit block. */
3796 df_update_exit_block_uses (void)
3799 bool changed
= false;
3801 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3802 df_get_exit_block_use_set (&refs
);
3803 if (df
->exit_block_uses
)
3805 if (!bitmap_equal_p (df
->exit_block_uses
, &refs
))
3807 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
3808 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
3809 df_ref_chain_delete (bb_info
->artificial_uses
);
3810 bb_info
->artificial_uses
= NULL
;
3816 struct df_scan_problem_data
*problem_data
3817 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3819 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3825 df_record_exit_block_uses (&refs
);
3826 bitmap_copy (df
->exit_block_uses
,& refs
);
3827 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
3829 bitmap_clear (&refs
);
3832 static bool initialized
= false;
3835 /* Initialize some platform specific structures. */
3838 df_hard_reg_init (void)
3840 #ifdef ELIMINABLE_REGS
3842 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
3847 /* Record which registers will be eliminated. We use this in
3849 CLEAR_HARD_REG_SET (elim_reg_set
);
3851 #ifdef ELIMINABLE_REGS
3852 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
3853 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
3855 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
3862 /* Recompute the parts of scanning that are based on regs_ever_live
3863 because something changed in that array. */
3866 df_update_entry_exit_and_calls (void)
3870 df_update_entry_block_defs ();
3871 df_update_exit_block_uses ();
3873 /* The call insns need to be rescanned because there may be changes
3874 in the set of registers clobbered across the call. */
3875 FOR_EACH_BB_FN (bb
, cfun
)
3878 FOR_BB_INSNS (bb
, insn
)
3880 if (INSN_P (insn
) && CALL_P (insn
))
3881 df_insn_rescan (insn
);
3887 /* Return true if hard REG is actually used in the some instruction.
3888 There are a fair number of conditions that affect the setting of
3889 this array. See the comment in df.h for df->hard_regs_live_count
3890 for the conditions that this array is set. */
3893 df_hard_reg_used_p (unsigned int reg
)
3895 return df
->hard_regs_live_count
[reg
] != 0;
3899 /* A count of the number of times REG is actually used in the some
3900 instruction. There are a fair number of conditions that affect the
3901 setting of this array. See the comment in df.h for
3902 df->hard_regs_live_count for the conditions that this array is
3907 df_hard_reg_used_count (unsigned int reg
)
3909 return df
->hard_regs_live_count
[reg
];
3913 /* Get the value of regs_ever_live[REGNO]. */
3916 df_regs_ever_live_p (unsigned int regno
)
3918 return regs_ever_live
[regno
];
3922 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
3923 to change, schedule that change for the next update. */
3926 df_set_regs_ever_live (unsigned int regno
, bool value
)
3928 if (regs_ever_live
[regno
] == value
)
3931 regs_ever_live
[regno
] = value
;
3933 df
->redo_entry_and_exit
= true;
3937 /* Compute "regs_ever_live" information from the underlying df
3938 information. Set the vector to all false if RESET. */
3941 df_compute_regs_ever_live (bool reset
)
3944 bool changed
= df
->redo_entry_and_exit
;
3947 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
3949 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3950 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
3952 regs_ever_live
[i
] = true;
3956 df_update_entry_exit_and_calls ();
3957 df
->redo_entry_and_exit
= false;
3961 /*----------------------------------------------------------------------------
3962 Dataflow ref information verification functions.
3964 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
3965 df_reg_chain_verify_unmarked (refs)
3966 df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
3967 df_mws_verify (mw*, mw*, bool)
3968 df_insn_refs_verify (collection_rec, bb, insn, bool)
3969 df_bb_refs_verify (bb, refs, bool)
3971 df_exit_block_bitmap_verify (bool)
3972 df_entry_block_bitmap_verify (bool)
3974 ----------------------------------------------------------------------------*/
3977 /* Mark all refs in the reg chain. Verify that all of the registers
3978 are in the correct chain. */
3981 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
3982 bool is_def
, bool is_eq_use
)
3984 unsigned int count
= 0;
3986 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
3988 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
3990 /* If there are no def-use or use-def chains, make sure that all
3991 of the chains are clear. */
3993 gcc_assert (!DF_REF_CHAIN (ref
));
3995 /* Check to make sure the ref is in the correct chain. */
3996 gcc_assert (DF_REF_REGNO (ref
) == regno
);
3998 gcc_assert (DF_REF_REG_DEF_P (ref
));
4000 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4003 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4005 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4007 if (DF_REF_NEXT_REG (ref
))
4008 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4010 DF_REF_REG_MARK (ref
);
4016 /* Verify that all of the registers in the chain are unmarked. */
4019 df_reg_chain_verify_unmarked (df_ref refs
)
4022 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4023 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4027 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4030 df_refs_verify (const vec
<df_ref
, va_heap
> *new_rec
, df_ref old_rec
,
4036 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_ref
)
4038 if (old_rec
== NULL
|| !df_ref_equal_p (new_ref
, old_rec
))
4046 /* Abort if fail is called from the function level verifier. If
4047 that is the context, mark this reg as being seem. */
4050 gcc_assert (DF_REF_IS_REG_MARKED (old_rec
));
4051 DF_REF_REG_UNMARK (old_rec
);
4054 old_rec
= DF_REF_NEXT_LOC (old_rec
);
4058 gcc_assert (old_rec
== NULL
);
4060 return old_rec
== NULL
;
4065 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4068 df_mws_verify (const vec
<df_mw_hardreg_ptr
, va_heap
> *new_rec
,
4069 struct df_mw_hardreg
*old_rec
,
4073 struct df_mw_hardreg
*new_reg
;
4075 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_reg
)
4077 if (old_rec
== NULL
|| !df_mw_equal_p (new_reg
, old_rec
))
4084 old_rec
= DF_MWS_NEXT (old_rec
);
4088 gcc_assert (old_rec
== NULL
);
4090 return old_rec
== NULL
;
4095 /* Return true if the existing insn refs information is complete and
4096 correct. Otherwise (i.e. if there's any missing or extra refs),
4097 return the correct df_ref chain in REFS_RETURN.
4099 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4100 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4101 verification mode instead of the whole function, so unmark
4104 If ABORT_IF_FAIL is set, this function never returns false. */
4107 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4112 bool ret1
, ret2
, ret3
, ret4
;
4113 unsigned int uid
= INSN_UID (insn
);
4114 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4116 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4118 /* Unfortunately we cannot opt out early if one of these is not
4119 right because the marks will not get cleared. */
4120 ret1
= df_refs_verify (&collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4122 ret2
= df_refs_verify (&collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4124 ret3
= df_refs_verify (&collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4126 ret4
= df_mws_verify (&collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4128 return (ret1
&& ret2
&& ret3
&& ret4
);
4132 /* Return true if all refs in the basic block are correct and complete.
4133 Due to df_ref_chain_verify, it will cause all refs
4134 that are verified to have DF_REF_MARK bit set. */
4137 df_bb_verify (basic_block bb
)
4140 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4141 struct df_collection_rec collection_rec
;
4143 gcc_assert (bb_info
);
4145 /* Scan the block, one insn at a time, from beginning to end. */
4146 FOR_BB_INSNS_REVERSE (bb
, insn
)
4150 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4151 df_free_collection_rec (&collection_rec
);
4154 /* Do the artificial defs and uses. */
4155 df_bb_refs_collect (&collection_rec
, bb
);
4156 df_refs_verify (&collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4157 df_refs_verify (&collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4158 df_free_collection_rec (&collection_rec
);
4164 /* Returns true if the entry block has correct and complete df_ref set.
4165 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4168 df_entry_block_bitmap_verify (bool abort_if_fail
)
4170 bitmap_head entry_block_defs
;
4173 bitmap_initialize (&entry_block_defs
, &df_bitmap_obstack
);
4174 df_get_entry_block_def_set (&entry_block_defs
);
4176 is_eq
= bitmap_equal_p (&entry_block_defs
, df
->entry_block_defs
);
4178 if (!is_eq
&& abort_if_fail
)
4180 fprintf (stderr
, "entry_block_defs = ");
4181 df_print_regset (stderr
, &entry_block_defs
);
4182 fprintf (stderr
, "df->entry_block_defs = ");
4183 df_print_regset (stderr
, df
->entry_block_defs
);
4187 bitmap_clear (&entry_block_defs
);
4193 /* Returns true if the exit block has correct and complete df_ref set.
4194 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4197 df_exit_block_bitmap_verify (bool abort_if_fail
)
4199 bitmap_head exit_block_uses
;
4202 bitmap_initialize (&exit_block_uses
, &df_bitmap_obstack
);
4203 df_get_exit_block_use_set (&exit_block_uses
);
4205 is_eq
= bitmap_equal_p (&exit_block_uses
, df
->exit_block_uses
);
4207 if (!is_eq
&& abort_if_fail
)
4209 fprintf (stderr
, "exit_block_uses = ");
4210 df_print_regset (stderr
, &exit_block_uses
);
4211 fprintf (stderr
, "df->exit_block_uses = ");
4212 df_print_regset (stderr
, df
->exit_block_uses
);
4216 bitmap_clear (&exit_block_uses
);
4222 /* Return true if df_ref information for all insns in all blocks are
4223 correct and complete. */
4226 df_scan_verify (void)
4230 bitmap_head regular_block_artificial_uses
;
4231 bitmap_head eh_block_artificial_uses
;
4236 /* Verification is a 4 step process. */
4238 /* (1) All of the refs are marked by going through the reg chains. */
4239 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4241 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4242 == DF_REG_DEF_COUNT (i
));
4243 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4244 == DF_REG_USE_COUNT (i
));
4245 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4246 == DF_REG_EQ_USE_COUNT (i
));
4249 /* (2) There are various bitmaps whose value may change over the
4250 course of the compilation. This step recomputes them to make
4251 sure that they have not slipped out of date. */
4252 bitmap_initialize (®ular_block_artificial_uses
, &df_bitmap_obstack
);
4253 bitmap_initialize (&eh_block_artificial_uses
, &df_bitmap_obstack
);
4255 df_get_regular_block_artificial_uses (®ular_block_artificial_uses
);
4256 df_get_eh_block_artificial_uses (&eh_block_artificial_uses
);
4258 bitmap_ior_into (&eh_block_artificial_uses
,
4259 ®ular_block_artificial_uses
);
4261 /* Check artificial_uses bitmaps didn't change. */
4262 gcc_assert (bitmap_equal_p (®ular_block_artificial_uses
,
4263 &df
->regular_block_artificial_uses
));
4264 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses
,
4265 &df
->eh_block_artificial_uses
));
4267 bitmap_clear (®ular_block_artificial_uses
);
4268 bitmap_clear (&eh_block_artificial_uses
);
4270 /* Verify entry block and exit block. These only verify the bitmaps,
4271 the refs are verified in df_bb_verify. */
4272 df_entry_block_bitmap_verify (true);
4273 df_exit_block_bitmap_verify (true);
4275 /* (3) All of the insns in all of the blocks are traversed and the
4276 marks are cleared both in the artificial refs attached to the
4277 blocks and the real refs inside the insns. It is a failure to
4278 clear a mark that has not been set as this means that the ref in
4279 the block or insn was not in the reg chain. */
4281 FOR_ALL_BB_FN (bb
, cfun
)
4284 /* (4) See if all reg chains are traversed a second time. This time
4285 a check is made that the marks are clear. A set mark would be a
4286 from a reg that is not in any insn or basic block. */
4288 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4290 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4291 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4292 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));