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"
36 #include "double-int.h"
42 #include "hard-reg-set.h"
46 #include "alloc-pool.h"
49 #include "dominance.h"
51 #include "basic-block.h"
57 #include "target-def.h"
59 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
62 typedef struct df_mw_hardreg
*df_mw_hardreg_ptr
;
66 #define HAVE_epilogue 0
69 #define HAVE_prologue 0
71 #ifndef HAVE_sibcall_epilogue
72 #define HAVE_sibcall_epilogue 0
75 /* The set of hard registers in eliminables[i].from. */
77 static HARD_REG_SET elim_reg_set
;
79 /* Initialize ur_in and ur_out as if all hard registers were partially
82 struct df_collection_rec
84 auto_vec
<df_ref
, 128> def_vec
;
85 auto_vec
<df_ref
, 32> use_vec
;
86 auto_vec
<df_ref
, 32> eq_use_vec
;
87 auto_vec
<df_mw_hardreg_ptr
, 32> mw_vec
;
90 static void df_ref_record (enum df_ref_class
, struct df_collection_rec
*,
92 basic_block
, struct df_insn_info
*,
93 enum df_ref_type
, int ref_flags
);
94 static void df_def_record_1 (struct df_collection_rec
*, rtx
*,
95 basic_block
, struct df_insn_info
*,
97 static void df_defs_record (struct df_collection_rec
*, rtx
,
98 basic_block
, struct df_insn_info
*,
100 static void df_uses_record (struct df_collection_rec
*,
101 rtx
*, enum df_ref_type
,
102 basic_block
, struct df_insn_info
*,
105 static void df_install_ref_incremental (df_ref
);
106 static void df_insn_refs_collect (struct df_collection_rec
*,
107 basic_block
, struct df_insn_info
*);
108 static void df_canonize_collection_rec (struct df_collection_rec
*);
110 static void df_get_regular_block_artificial_uses (bitmap
);
111 static void df_get_eh_block_artificial_uses (bitmap
);
113 static void df_record_entry_block_defs (bitmap
);
114 static void df_record_exit_block_uses (bitmap
);
115 static void df_get_exit_block_use_set (bitmap
);
116 static void df_get_entry_block_def_set (bitmap
);
117 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
118 static void df_ref_chain_delete_du_chain (df_ref
);
119 static void df_ref_chain_delete (df_ref
);
121 static void df_refs_add_to_chains (struct df_collection_rec
*,
122 basic_block
, rtx_insn
*, unsigned int);
124 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
,
126 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
127 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
128 static void df_install_ref (df_ref
, struct df_reg_info
*,
129 struct df_ref_info
*, bool);
131 static int df_ref_compare (df_ref
, df_ref
);
132 static int df_ref_ptr_compare (const void *, const void *);
133 static int df_mw_compare (const df_mw_hardreg
*, const df_mw_hardreg
*);
134 static int df_mw_ptr_compare (const void *, const void *);
136 static void df_insn_info_delete (unsigned int);
138 /* Indexed by hardware reg number, is true if that register is ever
139 used in the current function.
141 In df-scan.c, this is set up to record the hard regs used
142 explicitly. Reload adds in the hard regs used for holding pseudo
143 regs. Final uses it to generate the code in the function prologue
144 and epilogue to save and restore registers as needed. */
146 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
148 /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
149 static const unsigned int copy_defs
= 0x1;
150 static const unsigned int copy_uses
= 0x2;
151 static const unsigned int copy_eq_uses
= 0x4;
152 static const unsigned int copy_mw
= 0x8;
153 static const unsigned int copy_all
= copy_defs
| copy_uses
| copy_eq_uses
156 /*----------------------------------------------------------------------------
157 SCANNING DATAFLOW PROBLEM
159 There are several ways in which scanning looks just like the other
160 dataflow problems. It shares the all the mechanisms for local info
161 as well as basic block info. Where it differs is when and how often
162 it gets run. It also has no need for the iterative solver.
163 ----------------------------------------------------------------------------*/
165 /* Problem data for the scanning dataflow function. */
166 struct df_scan_problem_data
168 alloc_pool ref_base_pool
;
169 alloc_pool ref_artificial_pool
;
170 alloc_pool ref_regular_pool
;
171 alloc_pool insn_pool
;
173 alloc_pool mw_reg_pool
;
174 bitmap_obstack reg_bitmaps
;
175 bitmap_obstack insn_bitmaps
;
178 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
181 /* Internal function to shut down the scanning problem. */
183 df_scan_free_internal (void)
185 struct df_scan_problem_data
*problem_data
186 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
188 free (df
->def_info
.refs
);
189 free (df
->def_info
.begin
);
190 free (df
->def_info
.count
);
191 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
193 free (df
->use_info
.refs
);
194 free (df
->use_info
.begin
);
195 free (df
->use_info
.count
);
196 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
202 free (df
->eq_use_regs
);
203 df
->eq_use_regs
= NULL
;
205 DF_REG_SIZE (df
) = 0;
211 free (df_scan
->block_info
);
212 df_scan
->block_info
= NULL
;
213 df_scan
->block_info_size
= 0;
215 bitmap_clear (&df
->hardware_regs_used
);
216 bitmap_clear (&df
->regular_block_artificial_uses
);
217 bitmap_clear (&df
->eh_block_artificial_uses
);
218 BITMAP_FREE (df
->entry_block_defs
);
219 BITMAP_FREE (df
->exit_block_uses
);
220 bitmap_clear (&df
->insns_to_delete
);
221 bitmap_clear (&df
->insns_to_rescan
);
222 bitmap_clear (&df
->insns_to_notes_rescan
);
224 free_alloc_pool (problem_data
->ref_base_pool
);
225 free_alloc_pool (problem_data
->ref_artificial_pool
);
226 free_alloc_pool (problem_data
->ref_regular_pool
);
227 free_alloc_pool (problem_data
->insn_pool
);
228 free_alloc_pool (problem_data
->reg_pool
);
229 free_alloc_pool (problem_data
->mw_reg_pool
);
230 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
231 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
232 free (df_scan
->problem_data
);
236 /* Free basic block info. */
239 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
241 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
242 unsigned int bb_index
= bb
->index
;
245 FOR_BB_INSNS (bb
, insn
)
247 df_insn_info_delete (INSN_UID (insn
));
249 if (bb_index
< df_scan
->block_info_size
)
250 bb_info
= df_scan_get_bb_info (bb_index
);
252 /* Get rid of any artificial uses or defs. */
253 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
254 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
255 df_ref_chain_delete (bb_info
->artificial_defs
);
256 df_ref_chain_delete (bb_info
->artificial_uses
);
257 bb_info
->artificial_defs
= NULL
;
258 bb_info
->artificial_uses
= NULL
;
262 /* Allocate the problem data for the scanning problem. This should be
263 called when the problem is created or when the entire function is to
266 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
268 struct df_scan_problem_data
*problem_data
;
269 unsigned int insn_num
= get_max_uid () + 1;
270 unsigned int block_size
= 512;
273 /* Given the number of pools, this is really faster than tearing
275 if (df_scan
->problem_data
)
276 df_scan_free_internal ();
278 problem_data
= XNEW (struct df_scan_problem_data
);
279 df_scan
->problem_data
= problem_data
;
280 df_scan
->computed
= true;
282 problem_data
->ref_base_pool
283 = create_alloc_pool ("df_scan ref base",
284 sizeof (struct df_base_ref
), block_size
);
285 problem_data
->ref_artificial_pool
286 = create_alloc_pool ("df_scan ref artificial",
287 sizeof (struct df_artificial_ref
), block_size
);
288 problem_data
->ref_regular_pool
289 = create_alloc_pool ("df_scan ref regular",
290 sizeof (struct df_regular_ref
), block_size
);
291 problem_data
->insn_pool
292 = create_alloc_pool ("df_scan insn",
293 sizeof (struct df_insn_info
), block_size
);
294 problem_data
->reg_pool
295 = create_alloc_pool ("df_scan reg",
296 sizeof (struct df_reg_info
), block_size
);
297 problem_data
->mw_reg_pool
298 = create_alloc_pool ("df_scan mw_reg",
299 sizeof (struct df_mw_hardreg
), block_size
/ 16);
301 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
302 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
304 insn_num
+= insn_num
/ 4;
307 df_grow_insn_info ();
308 df_grow_bb_info (df_scan
);
310 FOR_ALL_BB_FN (bb
, cfun
)
312 unsigned int bb_index
= bb
->index
;
313 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
314 bb_info
->artificial_defs
= NULL
;
315 bb_info
->artificial_uses
= NULL
;
318 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
319 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
320 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
321 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
322 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
323 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
324 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
325 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
326 df_scan
->optional_p
= false;
330 /* Free all of the data associated with the scan problem. */
335 if (df_scan
->problem_data
)
336 df_scan_free_internal ();
338 if (df
->blocks_to_analyze
)
340 BITMAP_FREE (df
->blocks_to_analyze
);
341 df
->blocks_to_analyze
= NULL
;
347 /* Dump the preamble for DF_SCAN dump. */
349 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
360 fprintf (file
, ";; invalidated by call \t");
361 df_print_regset (file
, regs_invalidated_by_call_regset
);
362 fprintf (file
, ";; hardware regs used \t");
363 df_print_regset (file
, &df
->hardware_regs_used
);
364 fprintf (file
, ";; regular block artificial uses \t");
365 df_print_regset (file
, &df
->regular_block_artificial_uses
);
366 fprintf (file
, ";; eh block artificial uses \t");
367 df_print_regset (file
, &df
->eh_block_artificial_uses
);
368 fprintf (file
, ";; entry block defs \t");
369 df_print_regset (file
, df
->entry_block_defs
);
370 fprintf (file
, ";; exit block uses \t");
371 df_print_regset (file
, df
->exit_block_uses
);
372 fprintf (file
, ";; regs ever live \t");
373 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
374 if (df_regs_ever_live_p (i
))
375 fprintf (file
, " %d[%s]", i
, reg_names
[i
]);
376 fprintf (file
, "\n;; ref usage \t");
378 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
379 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
381 const char * sep
= "";
383 fprintf (file
, "r%d={", i
);
384 if (DF_REG_DEF_COUNT (i
))
386 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
388 dcount
+= DF_REG_DEF_COUNT (i
);
390 if (DF_REG_USE_COUNT (i
))
392 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
394 ucount
+= DF_REG_USE_COUNT (i
);
396 if (DF_REG_EQ_USE_COUNT (i
))
398 fprintf (file
, "%s%de", sep
, DF_REG_EQ_USE_COUNT (i
));
399 ecount
+= DF_REG_EQ_USE_COUNT (i
);
401 fprintf (file
, "} ");
404 FOR_EACH_BB_FN (bb
, cfun
)
405 FOR_BB_INSNS (bb
, insn
)
414 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de}"
415 " in %d{%d regular + %d call} insns.\n",
416 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
,
417 icount
+ ccount
, icount
, ccount
);
420 /* Dump the bb_info for a given basic block. */
422 df_scan_start_block (basic_block bb
, FILE *file
)
424 struct df_scan_bb_info
*bb_info
425 = df_scan_get_bb_info (bb
->index
);
429 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
430 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
431 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
432 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
433 fprintf (file
, "\n");
438 FOR_BB_INSNS (bb
, insn
)
440 df_insn_debug (insn
, false, file
);
445 static struct df_problem problem_SCAN
=
447 DF_SCAN
, /* Problem id. */
448 DF_NONE
, /* Direction. */
449 df_scan_alloc
, /* Allocate the problem specific data. */
450 NULL
, /* Reset global information. */
451 df_scan_free_bb_info
, /* Free basic block info. */
452 NULL
, /* Local compute function. */
453 NULL
, /* Init the solution specific data. */
454 NULL
, /* Iterative solver. */
455 NULL
, /* Confluence operator 0. */
456 NULL
, /* Confluence operator n. */
457 NULL
, /* Transfer function. */
458 NULL
, /* Finalize function. */
459 df_scan_free
, /* Free all of the problem information. */
460 NULL
, /* Remove this problem from the stack of dataflow problems. */
461 df_scan_start_dump
, /* Debugging. */
462 df_scan_start_block
, /* Debugging start block. */
463 NULL
, /* Debugging end block. */
464 NULL
, /* Debugging start insn. */
465 NULL
, /* Debugging end insn. */
466 NULL
, /* Incremental solution verify start. */
467 NULL
, /* Incremental solution verify end. */
468 NULL
, /* Dependent problem. */
469 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
470 TV_DF_SCAN
, /* Timing variable. */
471 false /* Reset blocks on dropping out of blocks_to_analyze. */
475 /* Create a new DATAFLOW instance and add it to an existing instance
476 of DF. The returned structure is what is used to get at the
480 df_scan_add_problem (void)
482 df_add_problem (&problem_SCAN
);
486 /*----------------------------------------------------------------------------
487 Storage Allocation Utilities
488 ----------------------------------------------------------------------------*/
491 /* First, grow the reg_info information. If the current size is less than
492 the number of pseudos, grow to 25% more than the number of
495 Second, assure that all of the slots up to max_reg_num have been
496 filled with reg_info structures. */
499 df_grow_reg_info (void)
501 unsigned int max_reg
= max_reg_num ();
502 unsigned int new_size
= max_reg
;
503 struct df_scan_problem_data
*problem_data
504 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
507 if (df
->regs_size
< new_size
)
509 new_size
+= new_size
/ 4;
510 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
511 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
512 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
514 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
515 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
516 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
517 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
518 df
->regs_size
= new_size
;
521 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
523 struct df_reg_info
*reg_info
;
525 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
526 memset (reg_info
, 0, sizeof (struct df_reg_info
));
527 df
->def_regs
[i
] = reg_info
;
528 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
529 memset (reg_info
, 0, sizeof (struct df_reg_info
));
530 df
->use_regs
[i
] = reg_info
;
531 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
532 memset (reg_info
, 0, sizeof (struct df_reg_info
));
533 df
->eq_use_regs
[i
] = reg_info
;
534 df
->def_info
.begin
[i
] = 0;
535 df
->def_info
.count
[i
] = 0;
536 df
->use_info
.begin
[i
] = 0;
537 df
->use_info
.count
[i
] = 0;
540 df
->regs_inited
= max_reg
;
544 /* Grow the ref information. */
547 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
549 if (ref_info
->refs_size
< new_size
)
551 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
552 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
553 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
554 ref_info
->refs_size
= new_size
;
559 /* Check and grow the ref information if necessary. This routine
560 guarantees total_size + BITMAP_ADDEND amount of entries in refs
561 array. It updates ref_info->refs_size only and does not change
562 ref_info->total_size. */
565 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
566 unsigned bitmap_addend
)
568 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
570 int new_size
= ref_info
->total_size
+ bitmap_addend
;
571 new_size
+= ref_info
->total_size
/ 4;
572 df_grow_ref_info (ref_info
, new_size
);
577 /* Grow the ref information. If the current size is less than the
578 number of instructions, grow to 25% more than the number of
582 df_grow_insn_info (void)
584 unsigned int new_size
= get_max_uid () + 1;
585 if (DF_INSN_SIZE () < new_size
)
587 new_size
+= new_size
/ 4;
588 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
589 memset (df
->insns
+ df
->insns_size
, 0,
590 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
591 DF_INSN_SIZE () = new_size
;
598 /*----------------------------------------------------------------------------
599 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
600 ----------------------------------------------------------------------------*/
602 /* Rescan all of the block_to_analyze or all of the blocks in the
603 function if df_set_blocks if blocks_to_analyze is NULL; */
606 df_scan_blocks (void)
610 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
611 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
613 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
614 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
616 bitmap_ior_into (&df
->eh_block_artificial_uses
,
617 &df
->regular_block_artificial_uses
);
619 /* ENTRY and EXIT blocks have special defs/uses. */
620 df_get_entry_block_def_set (df
->entry_block_defs
);
621 df_record_entry_block_defs (df
->entry_block_defs
);
622 df_get_exit_block_use_set (df
->exit_block_uses
);
623 df_record_exit_block_uses (df
->exit_block_uses
);
624 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
625 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
628 FOR_EACH_BB_FN (bb
, cfun
)
630 unsigned int bb_index
= bb
->index
;
631 df_bb_refs_record (bb_index
, true);
635 /* Create new refs under address LOC within INSN. This function is
636 only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
637 depending on whether LOC is inside PATTERN (INSN) or a note. */
640 df_uses_create (rtx
*loc
, rtx_insn
*insn
, int ref_flags
)
642 gcc_assert (!(ref_flags
& ~DF_REF_IN_NOTE
));
643 df_uses_record (NULL
, loc
, DF_REF_REG_USE
,
644 BLOCK_FOR_INSN (insn
),
645 DF_INSN_INFO_GET (insn
),
650 df_install_ref_incremental (df_ref ref
)
652 struct df_reg_info
**reg_info
;
653 struct df_ref_info
*ref_info
;
657 rtx_insn
*insn
= DF_REF_INSN (ref
);
658 basic_block bb
= BLOCK_FOR_INSN (insn
);
660 if (DF_REF_REG_DEF_P (ref
))
662 reg_info
= df
->def_regs
;
663 ref_info
= &df
->def_info
;
664 ref_ptr
= &DF_INSN_DEFS (insn
);
665 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
667 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
669 reg_info
= df
->eq_use_regs
;
670 ref_info
= &df
->use_info
;
671 ref_ptr
= &DF_INSN_EQ_USES (insn
);
672 switch (ref_info
->ref_order
)
674 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
675 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
676 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
680 add_to_table
= false;
686 reg_info
= df
->use_regs
;
687 ref_info
= &df
->use_info
;
688 ref_ptr
= &DF_INSN_USES (insn
);
689 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
692 /* Do not add if ref is not in the right blocks. */
693 if (add_to_table
&& df
->analyze_subset
)
694 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
696 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
699 switch (ref_info
->ref_order
)
701 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
702 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
703 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
704 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
707 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
711 while (*ref_ptr
&& df_ref_compare (*ref_ptr
, ref
) < 0)
712 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
714 DF_REF_NEXT_LOC (ref
) = *ref_ptr
;
720 fprintf (dump_file
, "adding ref ");
721 df_ref_debug (ref
, dump_file
);
724 /* By adding the ref directly, df_insn_rescan my not find any
725 differences even though the block will have changed. So we need
726 to mark the block dirty ourselves. */
727 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
728 df_set_bb_dirty (bb
);
733 /*----------------------------------------------------------------------------
734 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
735 ----------------------------------------------------------------------------*/
738 df_free_ref (df_ref ref
)
740 struct df_scan_problem_data
*problem_data
741 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
743 switch (DF_REF_CLASS (ref
))
746 pool_free (problem_data
->ref_base_pool
, ref
);
749 case DF_REF_ARTIFICIAL
:
750 pool_free (problem_data
->ref_artificial_pool
, ref
);
754 pool_free (problem_data
->ref_regular_pool
, ref
);
760 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
761 Also delete the def-use or use-def chain if it exists. */
764 df_reg_chain_unlink (df_ref ref
)
766 df_ref next
= DF_REF_NEXT_REG (ref
);
767 df_ref prev
= DF_REF_PREV_REG (ref
);
768 int id
= DF_REF_ID (ref
);
769 struct df_reg_info
*reg_info
;
772 if (DF_REF_REG_DEF_P (ref
))
774 int regno
= DF_REF_REGNO (ref
);
775 reg_info
= DF_REG_DEF_GET (regno
);
776 refs
= df
->def_info
.refs
;
780 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
782 reg_info
= DF_REG_EQ_USE_GET (DF_REF_REGNO (ref
));
783 switch (df
->use_info
.ref_order
)
785 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
786 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
787 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
788 refs
= df
->use_info
.refs
;
796 reg_info
= DF_REG_USE_GET (DF_REF_REGNO (ref
));
797 refs
= df
->use_info
.refs
;
803 if (df
->analyze_subset
)
805 if (bitmap_bit_p (df
->blocks_to_analyze
, DF_REF_BBNO (ref
)))
812 /* Delete any def-use or use-def chains that start here. It is
813 possible that there is trash in this field. This happens for
814 insns that have been deleted when rescanning has been deferred
815 and the chain problem has also been deleted. The chain tear down
816 code skips deleted insns. */
817 if (df_chain
&& DF_REF_CHAIN (ref
))
818 df_chain_unlink (ref
);
821 if (DF_REF_FLAGS_IS_SET (ref
, DF_HARD_REG_LIVE
))
823 gcc_assert (DF_REF_REGNO (ref
) < FIRST_PSEUDO_REGISTER
);
824 df
->hard_regs_live_count
[DF_REF_REGNO (ref
)]--;
827 /* Unlink from the reg chain. If there is no prev, this is the
828 first of the list. If not, just join the next and prev. */
830 DF_REF_NEXT_REG (prev
) = next
;
833 gcc_assert (reg_info
->reg_chain
== ref
);
834 reg_info
->reg_chain
= next
;
837 DF_REF_PREV_REG (next
) = prev
;
843 /* Create the insn record for INSN. If there was one there, zero it
846 struct df_insn_info
*
847 df_insn_create_insn_record (rtx_insn
*insn
)
849 struct df_scan_problem_data
*problem_data
850 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
851 struct df_insn_info
*insn_rec
;
853 df_grow_insn_info ();
854 insn_rec
= DF_INSN_INFO_GET (insn
);
857 insn_rec
= (struct df_insn_info
*) pool_alloc (problem_data
->insn_pool
);
858 DF_INSN_INFO_SET (insn
, insn_rec
);
860 memset (insn_rec
, 0, sizeof (struct df_insn_info
));
861 insn_rec
->insn
= insn
;
866 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
869 df_ref_chain_delete_du_chain (df_ref ref
)
871 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
872 /* CHAIN is allocated by DF_CHAIN. So make sure to
873 pass df_scan instance for the problem. */
874 if (DF_REF_CHAIN (ref
))
875 df_chain_unlink (ref
);
879 /* Delete all refs in the ref chain. */
882 df_ref_chain_delete (df_ref ref
)
885 for (; ref
; ref
= next
)
887 next
= DF_REF_NEXT_LOC (ref
);
888 df_reg_chain_unlink (ref
);
893 /* Delete the hardreg chain. */
896 df_mw_hardreg_chain_delete (struct df_mw_hardreg
*hardregs
)
898 struct df_scan_problem_data
*problem_data
899 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
902 for (; hardregs
; hardregs
= next
)
904 next
= DF_MWS_NEXT (hardregs
);
905 pool_free (problem_data
->mw_reg_pool
, hardregs
);
910 /* Delete all of the refs information from the insn with UID.
911 Internal helper for df_insn_delete, df_insn_rescan, and other
912 df-scan routines that don't have to work in deferred mode
913 and do not have to mark basic blocks for re-processing. */
916 df_insn_info_delete (unsigned int uid
)
918 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
920 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
921 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
922 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
925 struct df_scan_problem_data
*problem_data
926 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
928 /* In general, notes do not have the insn_info fields
929 initialized. However, combine deletes insns by changing them
930 to notes. How clever. So we cannot just check if it is a
931 valid insn before short circuiting this code, we need to see
932 if we actually initialized it. */
933 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
937 df_ref_chain_delete_du_chain (insn_info
->defs
);
938 df_ref_chain_delete_du_chain (insn_info
->uses
);
939 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
942 df_ref_chain_delete (insn_info
->defs
);
943 df_ref_chain_delete (insn_info
->uses
);
944 df_ref_chain_delete (insn_info
->eq_uses
);
946 pool_free (problem_data
->insn_pool
, insn_info
);
947 DF_INSN_UID_SET (uid
, NULL
);
951 /* Delete all of the refs information from INSN, either right now
952 or marked for later in deferred mode. */
955 df_insn_delete (rtx_insn
*insn
)
960 gcc_checking_assert (INSN_P (insn
));
965 uid
= INSN_UID (insn
);
966 bb
= BLOCK_FOR_INSN (insn
);
968 /* ??? bb can be NULL after pass_free_cfg. At that point, DF should
969 not exist anymore (as mentioned in df-core.c: "The only requirement
970 [for DF] is that there be a correct control flow graph." Clearly
971 that isn't the case after pass_free_cfg. But DF is freed much later
972 because some back-ends want to use DF info even though the CFG is
973 already gone. It's not clear to me whether that is safe, actually.
974 In any case, we expect BB to be non-NULL at least up to register
975 allocation, so disallow a non-NULL BB up to there. Not perfect
976 but better than nothing... */
977 gcc_checking_assert (bb
!= NULL
|| reload_completed
);
979 df_grow_bb_info (df_scan
);
982 /* The block must be marked as dirty now, rather than later as in
983 df_insn_rescan and df_notes_rescan because it may not be there at
984 rescanning time and the mark would blow up.
985 DEBUG_INSNs do not make a block's data flow solution dirty (at
986 worst the LUIDs are no longer contiguous). */
987 if (bb
!= NULL
&& NONDEBUG_INSN_P (insn
))
988 df_set_bb_dirty (bb
);
990 /* The client has deferred rescanning. */
991 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
993 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
996 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
997 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
998 bitmap_set_bit (&df
->insns_to_delete
, uid
);
1001 fprintf (dump_file
, "deferring deletion of insn with uid = %d.\n", uid
);
1006 fprintf (dump_file
, "deleting insn with uid = %d.\n", uid
);
1008 df_insn_info_delete (uid
);
1012 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1015 df_free_collection_rec (struct df_collection_rec
*collection_rec
)
1018 struct df_scan_problem_data
*problem_data
1019 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1021 struct df_mw_hardreg
*mw
;
1023 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
1025 FOR_EACH_VEC_ELT (collection_rec
->use_vec
, ix
, ref
)
1027 FOR_EACH_VEC_ELT (collection_rec
->eq_use_vec
, ix
, ref
)
1029 FOR_EACH_VEC_ELT (collection_rec
->mw_vec
, ix
, mw
)
1030 pool_free (problem_data
->mw_reg_pool
, mw
);
1032 collection_rec
->def_vec
.release ();
1033 collection_rec
->use_vec
.release ();
1034 collection_rec
->eq_use_vec
.release ();
1035 collection_rec
->mw_vec
.release ();
1038 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1041 df_insn_rescan (rtx_insn
*insn
)
1043 unsigned int uid
= INSN_UID (insn
);
1044 struct df_insn_info
*insn_info
= NULL
;
1045 basic_block bb
= BLOCK_FOR_INSN (insn
);
1046 struct df_collection_rec collection_rec
;
1048 if ((!df
) || (!INSN_P (insn
)))
1054 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1058 /* The client has disabled rescanning and plans to do it itself. */
1059 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1062 df_grow_bb_info (df_scan
);
1063 df_grow_reg_info ();
1065 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1067 /* The client has deferred rescanning. */
1068 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1072 insn_info
= df_insn_create_insn_record (insn
);
1073 insn_info
->defs
= 0;
1074 insn_info
->uses
= 0;
1075 insn_info
->eq_uses
= 0;
1076 insn_info
->mw_hardregs
= 0;
1079 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1081 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1082 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1083 bitmap_set_bit (&df
->insns_to_rescan
, INSN_UID (insn
));
1087 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1088 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1089 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1093 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1094 /* If there's no change, return false. */
1097 df_free_collection_rec (&collection_rec
);
1099 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1103 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1105 /* There's change - we need to delete the existing info.
1106 Since the insn isn't moved, we can salvage its LUID. */
1107 luid
= DF_INSN_LUID (insn
);
1108 df_insn_info_delete (uid
);
1109 df_insn_create_insn_record (insn
);
1110 DF_INSN_LUID (insn
) = luid
;
1114 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1115 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1117 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1120 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
1121 if (!DEBUG_INSN_P (insn
))
1122 df_set_bb_dirty (bb
);
1127 /* Same as df_insn_rescan, but don't mark the basic block as
1131 df_insn_rescan_debug_internal (rtx_insn
*insn
)
1133 unsigned int uid
= INSN_UID (insn
);
1134 struct df_insn_info
*insn_info
;
1136 gcc_assert (DEBUG_INSN_P (insn
)
1137 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn
)));
1142 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1147 fprintf (dump_file
, "deleting debug_insn with uid = %d.\n", uid
);
1149 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1150 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1151 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1153 if (insn_info
->defs
== 0
1154 && insn_info
->uses
== 0
1155 && insn_info
->eq_uses
== 0
1156 && insn_info
->mw_hardregs
== 0)
1159 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1163 df_ref_chain_delete_du_chain (insn_info
->defs
);
1164 df_ref_chain_delete_du_chain (insn_info
->uses
);
1165 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1168 df_ref_chain_delete (insn_info
->defs
);
1169 df_ref_chain_delete (insn_info
->uses
);
1170 df_ref_chain_delete (insn_info
->eq_uses
);
1172 insn_info
->defs
= 0;
1173 insn_info
->uses
= 0;
1174 insn_info
->eq_uses
= 0;
1175 insn_info
->mw_hardregs
= 0;
1181 /* Rescan all of the insns in the function. Note that the artificial
1182 uses and defs are not touched. This function will destroy def-use
1183 or use-def chains. */
1186 df_insn_rescan_all (void)
1188 bool no_insn_rescan
= false;
1189 bool defer_insn_rescan
= false;
1195 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1197 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1199 df_clear_flags (DF_NO_INSN_RESCAN
);
1200 no_insn_rescan
= true;
1203 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1205 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1206 defer_insn_rescan
= true;
1209 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1210 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1212 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1214 df_insn_info_delete (uid
);
1217 bitmap_clear (&tmp
);
1218 bitmap_clear (&df
->insns_to_delete
);
1219 bitmap_clear (&df
->insns_to_rescan
);
1220 bitmap_clear (&df
->insns_to_notes_rescan
);
1222 FOR_EACH_BB_FN (bb
, cfun
)
1225 FOR_BB_INSNS (bb
, insn
)
1227 df_insn_rescan (insn
);
1232 df_set_flags (DF_NO_INSN_RESCAN
);
1233 if (defer_insn_rescan
)
1234 df_set_flags (DF_DEFER_INSN_RESCAN
);
1238 /* Process all of the deferred rescans or deletions. */
1241 df_process_deferred_rescans (void)
1243 bool no_insn_rescan
= false;
1244 bool defer_insn_rescan
= false;
1249 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1251 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1253 df_clear_flags (DF_NO_INSN_RESCAN
);
1254 no_insn_rescan
= true;
1257 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1259 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1260 defer_insn_rescan
= true;
1264 fprintf (dump_file
, "starting the processing of deferred insns\n");
1266 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1267 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1269 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1271 df_insn_info_delete (uid
);
1274 bitmap_copy (&tmp
, &df
->insns_to_rescan
);
1275 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1277 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1279 df_insn_rescan (insn_info
->insn
);
1282 bitmap_copy (&tmp
, &df
->insns_to_notes_rescan
);
1283 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1285 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1287 df_notes_rescan (insn_info
->insn
);
1291 fprintf (dump_file
, "ending the processing of deferred insns\n");
1293 bitmap_clear (&tmp
);
1294 bitmap_clear (&df
->insns_to_delete
);
1295 bitmap_clear (&df
->insns_to_rescan
);
1296 bitmap_clear (&df
->insns_to_notes_rescan
);
1299 df_set_flags (DF_NO_INSN_RESCAN
);
1300 if (defer_insn_rescan
)
1301 df_set_flags (DF_DEFER_INSN_RESCAN
);
1303 /* If someone changed regs_ever_live during this pass, fix up the
1304 entry and exit blocks. */
1305 if (df
->redo_entry_and_exit
)
1307 df_update_entry_exit_and_calls ();
1308 df
->redo_entry_and_exit
= false;
1313 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1314 the uses if INCLUDE_USES. Include the eq_uses if
1318 df_count_refs (bool include_defs
, bool include_uses
,
1319 bool include_eq_uses
)
1323 unsigned int m
= df
->regs_inited
;
1325 for (regno
= 0; regno
< m
; regno
++)
1328 size
+= DF_REG_DEF_COUNT (regno
);
1330 size
+= DF_REG_USE_COUNT (regno
);
1331 if (include_eq_uses
)
1332 size
+= DF_REG_EQ_USE_COUNT (regno
);
1338 /* Take build ref table for either the uses or defs from the reg-use
1339 or reg-def chains. This version processes the refs in reg order
1340 which is likely to be best if processing the whole function. */
1343 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1346 bool include_eq_uses
)
1348 unsigned int m
= df
->regs_inited
;
1350 unsigned int offset
= 0;
1353 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1355 start
= FIRST_PSEUDO_REGISTER
;
1356 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1357 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1362 ref_info
->total_size
1363 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1365 df_check_and_grow_ref_info (ref_info
, 1);
1367 for (regno
= start
; regno
< m
; regno
++)
1370 ref_info
->begin
[regno
] = offset
;
1373 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1376 ref_info
->refs
[offset
] = ref
;
1377 DF_REF_ID (ref
) = offset
++;
1379 ref
= DF_REF_NEXT_REG (ref
);
1380 gcc_checking_assert (offset
< ref_info
->refs_size
);
1385 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1388 ref_info
->refs
[offset
] = ref
;
1389 DF_REF_ID (ref
) = offset
++;
1391 ref
= DF_REF_NEXT_REG (ref
);
1392 gcc_checking_assert (offset
< ref_info
->refs_size
);
1395 if (include_eq_uses
)
1397 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1400 ref_info
->refs
[offset
] = ref
;
1401 DF_REF_ID (ref
) = offset
++;
1403 ref
= DF_REF_NEXT_REG (ref
);
1404 gcc_checking_assert (offset
< ref_info
->refs_size
);
1407 ref_info
->count
[regno
] = count
;
1410 /* The bitmap size is not decremented when refs are deleted. So
1411 reset it now that we have squished out all of the empty
1413 ref_info
->table_size
= offset
;
1417 /* Take build ref table for either the uses or defs from the reg-use
1418 or reg-def chains. This version processes the refs in insn order
1419 which is likely to be best if processing some segment of the
1423 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1426 bool include_eq_uses
)
1429 unsigned int bb_index
;
1430 unsigned int m
= df
->regs_inited
;
1431 unsigned int offset
= 0;
1434 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1436 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1437 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1439 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1440 df_check_and_grow_ref_info (ref_info
, 1);
1442 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1444 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1449 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1451 unsigned int regno
= DF_REF_REGNO (def
);
1452 ref_info
->count
[regno
]++;
1455 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1457 unsigned int regno
= DF_REF_REGNO (use
);
1458 ref_info
->count
[regno
]++;
1461 FOR_BB_INSNS (bb
, insn
)
1465 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1468 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1470 unsigned int regno
= DF_REF_REGNO (def
);
1471 ref_info
->count
[regno
]++;
1474 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1476 unsigned int regno
= DF_REF_REGNO (use
);
1477 ref_info
->count
[regno
]++;
1479 if (include_eq_uses
)
1480 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1482 unsigned int regno
= DF_REF_REGNO (use
);
1483 ref_info
->count
[regno
]++;
1489 for (r
= start
; r
< m
; r
++)
1491 ref_info
->begin
[r
] = offset
;
1492 offset
+= ref_info
->count
[r
];
1493 ref_info
->count
[r
] = 0;
1496 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1498 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1503 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1505 unsigned int regno
= DF_REF_REGNO (def
);
1509 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1510 DF_REF_ID (def
) = id
;
1511 ref_info
->refs
[id
] = def
;
1515 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1517 unsigned int regno
= DF_REF_REGNO (def
);
1521 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1522 DF_REF_ID (use
) = id
;
1523 ref_info
->refs
[id
] = use
;
1527 FOR_BB_INSNS (bb
, insn
)
1531 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1534 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1536 unsigned int regno
= DF_REF_REGNO (def
);
1540 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1541 DF_REF_ID (def
) = id
;
1542 ref_info
->refs
[id
] = def
;
1546 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1548 unsigned int regno
= DF_REF_REGNO (use
);
1552 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1553 DF_REF_ID (use
) = id
;
1554 ref_info
->refs
[id
] = use
;
1557 if (include_eq_uses
)
1558 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1560 unsigned int regno
= DF_REF_REGNO (use
);
1564 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1565 DF_REF_ID (use
) = id
;
1566 ref_info
->refs
[id
] = use
;
1573 /* The bitmap size is not decremented when refs are deleted. So
1574 reset it now that we have squished out all of the empty
1577 ref_info
->table_size
= offset
;
1580 /* Take build ref table for either the uses or defs from the reg-use
1581 or reg-def chains. */
1584 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1587 bool include_eq_uses
)
1589 if (df
->analyze_subset
)
1590 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1591 include_uses
, include_eq_uses
);
1593 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1594 include_uses
, include_eq_uses
);
1598 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1600 df_add_refs_to_table (unsigned int offset
,
1601 struct df_ref_info
*ref_info
,
1604 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
1605 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
)
1606 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1608 ref_info
->refs
[offset
] = ref
;
1609 DF_REF_ID (ref
) = offset
++;
1615 /* Count the number of refs in all of the insns of BB. Include the
1616 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1617 eq_uses if INCLUDE_EQ_USES. */
1620 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1621 struct df_ref_info
*ref_info
,
1622 bool include_defs
, bool include_uses
,
1623 bool include_eq_uses
)
1628 offset
= df_add_refs_to_table (offset
, ref_info
,
1629 df_get_artificial_defs (bb
->index
));
1631 offset
= df_add_refs_to_table (offset
, ref_info
,
1632 df_get_artificial_uses (bb
->index
));
1634 FOR_BB_INSNS (bb
, insn
)
1637 unsigned int uid
= INSN_UID (insn
);
1639 offset
= df_add_refs_to_table (offset
, ref_info
,
1640 DF_INSN_UID_DEFS (uid
));
1642 offset
= df_add_refs_to_table (offset
, ref_info
,
1643 DF_INSN_UID_USES (uid
));
1644 if (include_eq_uses
)
1645 offset
= df_add_refs_to_table (offset
, ref_info
,
1646 DF_INSN_UID_EQ_USES (uid
));
1652 /* Organize the refs by insn into the table in REF_INFO. If
1653 blocks_to_analyze is defined, use that set, otherwise the entire
1654 program. Include the defs if INCLUDE_DEFS. Include the uses if
1655 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1658 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1659 bool include_defs
, bool include_uses
,
1660 bool include_eq_uses
)
1663 unsigned int offset
= 0;
1665 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1666 df_check_and_grow_ref_info (ref_info
, 1);
1667 if (df
->blocks_to_analyze
)
1672 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1674 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun
,
1677 include_defs
, include_uses
,
1681 ref_info
->table_size
= offset
;
1685 FOR_ALL_BB_FN (bb
, cfun
)
1686 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1687 include_defs
, include_uses
,
1689 ref_info
->table_size
= offset
;
1694 /* If the use refs in DF are not organized, reorganize them. */
1697 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1699 if (order
== df
->use_info
.ref_order
)
1704 case DF_REF_ORDER_BY_REG
:
1705 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1708 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1709 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1712 case DF_REF_ORDER_BY_INSN
:
1713 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1716 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1717 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1720 case DF_REF_ORDER_NO_TABLE
:
1721 free (df
->use_info
.refs
);
1722 df
->use_info
.refs
= NULL
;
1723 df
->use_info
.refs_size
= 0;
1726 case DF_REF_ORDER_UNORDERED
:
1727 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1732 df
->use_info
.ref_order
= order
;
1736 /* If the def refs in DF are not organized, reorganize them. */
1739 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1741 if (order
== df
->def_info
.ref_order
)
1746 case DF_REF_ORDER_BY_REG
:
1747 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1750 case DF_REF_ORDER_BY_INSN
:
1751 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1754 case DF_REF_ORDER_NO_TABLE
:
1755 free (df
->def_info
.refs
);
1756 df
->def_info
.refs
= NULL
;
1757 df
->def_info
.refs_size
= 0;
1760 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1761 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1762 case DF_REF_ORDER_UNORDERED
:
1763 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1768 df
->def_info
.ref_order
= order
;
1772 /* Change all of the basic block references in INSN to use the insn's
1773 current basic block. This function is called from routines that move
1774 instructions from one block to another. */
1777 df_insn_change_bb (rtx_insn
*insn
, basic_block new_bb
)
1779 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1780 struct df_insn_info
*insn_info
;
1781 unsigned int uid
= INSN_UID (insn
);
1783 if (old_bb
== new_bb
)
1786 set_block_for_insn (insn
, new_bb
);
1792 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1794 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1795 if (insn_info
== NULL
)
1798 fprintf (dump_file
, " unscanned insn\n");
1799 df_insn_rescan (insn
);
1806 df_set_bb_dirty (new_bb
);
1810 fprintf (dump_file
, " from %d to %d\n",
1811 old_bb
->index
, new_bb
->index
);
1812 df_set_bb_dirty (old_bb
);
1816 fprintf (dump_file
, " to %d\n", new_bb
->index
);
1820 /* Helper function for df_ref_change_reg_with_loc. */
1823 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
1824 struct df_reg_info
*new_df
,
1825 int new_regno
, rtx loc
)
1827 df_ref the_ref
= old_df
->reg_chain
;
1831 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
1832 && DF_REF_LOC (the_ref
)
1833 && (*DF_REF_LOC (the_ref
) == loc
))
1835 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
1836 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
1838 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
1840 DF_REF_REGNO (the_ref
) = new_regno
;
1841 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
1843 /* Pull the_ref out of the old regno chain. */
1845 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
1847 old_df
->reg_chain
= next_ref
;
1849 DF_REF_PREV_REG (next_ref
) = prev_ref
;
1852 /* Put the ref into the new regno chain. */
1853 DF_REF_PREV_REG (the_ref
) = NULL
;
1854 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
1855 if (new_df
->reg_chain
)
1856 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
1857 new_df
->reg_chain
= the_ref
;
1859 if (DF_REF_BB (the_ref
))
1860 df_set_bb_dirty (DF_REF_BB (the_ref
));
1862 /* Need to sort the record again that the ref was in because
1863 the regno is a sorting key. First, find the right
1865 if (DF_REF_REG_DEF_P (the_ref
))
1866 ref_ptr
= &insn_info
->defs
;
1867 else if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
1868 ref_ptr
= &insn_info
->eq_uses
;
1870 ref_ptr
= &insn_info
->uses
;
1872 fprintf (dump_file
, "changing reg in insn %d\n",
1873 DF_REF_INSN_UID (the_ref
));
1875 /* Stop if we find the current reference or where the reference
1877 while (*ref_ptr
!= the_ref
&& df_ref_compare (*ref_ptr
, the_ref
) < 0)
1878 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1879 if (*ref_ptr
!= the_ref
)
1881 /* The reference needs to be promoted up the list. */
1882 df_ref next
= DF_REF_NEXT_LOC (the_ref
);
1883 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1886 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1887 while (*ref_ptr
!= the_ref
);
1890 else if (DF_REF_NEXT_LOC (the_ref
)
1891 && df_ref_compare (the_ref
, DF_REF_NEXT_LOC (the_ref
)) > 0)
1893 /* The reference needs to be demoted down the list. */
1894 *ref_ptr
= DF_REF_NEXT_LOC (the_ref
);
1896 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1897 while (*ref_ptr
&& df_ref_compare (the_ref
, *ref_ptr
) > 0);
1898 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1905 the_ref
= DF_REF_NEXT_REG (the_ref
);
1910 /* Change the regno of all refs that contained LOC from OLD_REGNO to
1911 NEW_REGNO. Refs that do not match LOC are not changed which means
1912 that artificial refs are not changed since they have no loc. This
1913 call is to support the SET_REGNO macro. */
1916 df_ref_change_reg_with_loc (int old_regno
, int new_regno
, rtx loc
)
1918 if ((!df
) || (old_regno
== -1) || (old_regno
== new_regno
))
1921 df_grow_reg_info ();
1923 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
1924 DF_REG_DEF_GET (new_regno
), new_regno
, loc
);
1925 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
1926 DF_REG_USE_GET (new_regno
), new_regno
, loc
);
1927 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
1928 DF_REG_EQ_USE_GET (new_regno
), new_regno
, loc
);
1932 /* Delete the mw_hardregs that point into the eq_notes. */
1935 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
1937 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
;
1938 struct df_scan_problem_data
*problem_data
1939 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1943 df_mw_hardreg
*mw
= *mw_ptr
;
1944 if (mw
->flags
& DF_REF_IN_NOTE
)
1946 *mw_ptr
= DF_MWS_NEXT (mw
);
1947 pool_free (problem_data
->mw_reg_pool
, mw
);
1950 mw_ptr
= &DF_MWS_NEXT (mw
);
1955 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
1958 df_notes_rescan (rtx_insn
*insn
)
1960 struct df_insn_info
*insn_info
;
1961 unsigned int uid
= INSN_UID (insn
);
1966 /* The client has disabled rescanning and plans to do it itself. */
1967 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1970 /* Do nothing if the insn hasn't been emitted yet. */
1971 if (!BLOCK_FOR_INSN (insn
))
1974 df_grow_bb_info (df_scan
);
1975 df_grow_reg_info ();
1977 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1979 /* The client has deferred rescanning. */
1980 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1984 insn_info
= df_insn_create_insn_record (insn
);
1985 insn_info
->defs
= 0;
1986 insn_info
->uses
= 0;
1987 insn_info
->eq_uses
= 0;
1988 insn_info
->mw_hardregs
= 0;
1991 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1992 /* If the insn is set to be rescanned, it does not need to also
1993 be notes rescanned. */
1994 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
1995 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
1999 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
2000 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
2004 basic_block bb
= BLOCK_FOR_INSN (insn
);
2006 struct df_collection_rec collection_rec
;
2009 df_mw_hardreg_chain_delete_eq_uses (insn_info
);
2010 df_ref_chain_delete (insn_info
->eq_uses
);
2011 insn_info
->eq_uses
= NULL
;
2013 /* Process REG_EQUIV/REG_EQUAL notes */
2014 for (note
= REG_NOTES (insn
); note
;
2015 note
= XEXP (note
, 1))
2017 switch (REG_NOTE_KIND (note
))
2021 df_uses_record (&collection_rec
,
2022 &XEXP (note
, 0), DF_REF_REG_USE
,
2023 bb
, insn_info
, DF_REF_IN_NOTE
);
2029 /* Find some place to put any new mw_hardregs. */
2030 df_canonize_collection_rec (&collection_rec
);
2031 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
, *mw
;
2032 FOR_EACH_VEC_ELT (collection_rec
.mw_vec
, i
, mw
)
2034 while (*mw_ptr
&& df_mw_compare (*mw_ptr
, mw
) < 0)
2035 mw_ptr
= &DF_MWS_NEXT (*mw_ptr
);
2036 DF_MWS_NEXT (mw
) = *mw_ptr
;
2038 mw_ptr
= &DF_MWS_NEXT (mw
);
2040 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_eq_uses
);
2043 df_insn_rescan (insn
);
2048 /*----------------------------------------------------------------------------
2049 Hard core instruction scanning code. No external interfaces here,
2050 just a lot of routines that look inside insns.
2051 ----------------------------------------------------------------------------*/
2054 /* Return true if the contents of two df_ref's are identical.
2055 It ignores DF_REF_MARKER. */
2058 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2066 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2067 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2068 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2069 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2070 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2071 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2072 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2073 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2076 switch (DF_REF_CLASS (ref1
))
2078 case DF_REF_ARTIFICIAL
:
2082 case DF_REF_REGULAR
:
2083 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2092 /* Compare REF1 and REF2 for sorting. This is only called from places
2093 where all of the refs are of the same type, in the same insn, and
2094 have the same bb. So these fields are not checked. */
2097 df_ref_compare (df_ref ref1
, df_ref ref2
)
2099 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2100 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2102 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2103 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2105 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2106 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2108 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2109 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2111 /* Cannot look at the LOC field on artificial refs. */
2112 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2113 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2114 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2116 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2118 /* If two refs are identical except that one of them has is from
2119 a mw and one is not, we need to have the one with the mw
2121 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2122 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2123 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2124 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2130 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2133 /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2. */
2136 df_ref_ptr_compare (const void *r1
, const void *r2
)
2138 return df_ref_compare (*(const df_ref
*) r1
, *(const df_ref
*) r2
);
2142 df_swap_refs (vec
<df_ref
, va_heap
> *ref_vec
, int i
, int j
)
2144 df_ref tmp
= (*ref_vec
)[i
];
2145 (*ref_vec
)[i
] = (*ref_vec
)[j
];
2146 (*ref_vec
)[j
] = tmp
;
2149 /* Sort and compress a set of refs. */
2152 df_sort_and_compress_refs (vec
<df_ref
, va_heap
> *ref_vec
)
2156 unsigned int dist
= 0;
2158 count
= ref_vec
->length ();
2160 /* If there are 1 or 0 elements, there is nothing to do. */
2163 else if (count
== 2)
2165 df_ref r0
= (*ref_vec
)[0];
2166 df_ref r1
= (*ref_vec
)[1];
2167 if (df_ref_compare (r0
, r1
) > 0)
2168 df_swap_refs (ref_vec
, 0, 1);
2172 for (i
= 0; i
< count
- 1; i
++)
2174 df_ref r0
= (*ref_vec
)[i
];
2175 df_ref r1
= (*ref_vec
)[i
+ 1];
2176 if (df_ref_compare (r0
, r1
) >= 0)
2179 /* If the array is already strictly ordered,
2180 which is the most common case for large COUNT case
2181 (which happens for CALL INSNs),
2182 no need to sort and filter out duplicate.
2183 Simply return the count.
2184 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2185 of DF_REF_COMPARE. */
2188 ref_vec
->qsort (df_ref_ptr_compare
);
2191 for (i
=0; i
<count
-dist
; i
++)
2193 /* Find the next ref that is not equal to the current ref. */
2194 while (i
+ dist
+ 1 < count
2195 && df_ref_equal_p ((*ref_vec
)[i
],
2196 (*ref_vec
)[i
+ dist
+ 1]))
2198 df_free_ref ((*ref_vec
)[i
+ dist
+ 1]);
2201 /* Copy it down to the next position. */
2202 if (dist
&& i
+ dist
+ 1 < count
)
2203 (*ref_vec
)[i
+ 1] = (*ref_vec
)[i
+ dist
+ 1];
2207 ref_vec
->truncate (count
);
2211 /* Return true if the contents of two df_ref's are identical.
2212 It ignores DF_REF_MARKER. */
2215 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2219 return (mw1
== mw2
) ||
2220 (mw1
->mw_reg
== mw2
->mw_reg
2221 && mw1
->type
== mw2
->type
2222 && mw1
->flags
== mw2
->flags
2223 && mw1
->start_regno
== mw2
->start_regno
2224 && mw1
->end_regno
== mw2
->end_regno
);
2228 /* Compare MW1 and MW2 for sorting. */
2231 df_mw_compare (const df_mw_hardreg
*mw1
, const df_mw_hardreg
*mw2
)
2233 if (mw1
->type
!= mw2
->type
)
2234 return mw1
->type
- mw2
->type
;
2236 if (mw1
->flags
!= mw2
->flags
)
2237 return mw1
->flags
- mw2
->flags
;
2239 if (mw1
->start_regno
!= mw2
->start_regno
)
2240 return mw1
->start_regno
- mw2
->start_regno
;
2242 if (mw1
->end_regno
!= mw2
->end_regno
)
2243 return mw1
->end_regno
- mw2
->end_regno
;
2245 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2246 return mw1
->mw_order
- mw2
->mw_order
;
2251 /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2. */
2254 df_mw_ptr_compare (const void *m1
, const void *m2
)
2256 return df_mw_compare (*(const df_mw_hardreg
*const *) m1
,
2257 *(const df_mw_hardreg
*const *) m2
);
2260 /* Sort and compress a set of refs. */
2263 df_sort_and_compress_mws (vec
<df_mw_hardreg_ptr
, va_heap
> *mw_vec
)
2266 struct df_scan_problem_data
*problem_data
2267 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2269 unsigned int dist
= 0;
2271 count
= mw_vec
->length ();
2274 else if (count
== 2)
2276 struct df_mw_hardreg
*m0
= (*mw_vec
)[0];
2277 struct df_mw_hardreg
*m1
= (*mw_vec
)[1];
2278 if (df_mw_compare (m0
, m1
) > 0)
2280 struct df_mw_hardreg
*tmp
= (*mw_vec
)[0];
2281 (*mw_vec
)[0] = (*mw_vec
)[1];
2286 mw_vec
->qsort (df_mw_ptr_compare
);
2288 for (i
=0; i
<count
-dist
; i
++)
2290 /* Find the next ref that is not equal to the current ref. */
2291 while (i
+ dist
+ 1 < count
2292 && df_mw_equal_p ((*mw_vec
)[i
], (*mw_vec
)[i
+ dist
+ 1]))
2294 pool_free (problem_data
->mw_reg_pool
,
2295 (*mw_vec
)[i
+ dist
+ 1]);
2298 /* Copy it down to the next position. */
2299 if (dist
&& i
+ dist
+ 1 < count
)
2300 (*mw_vec
)[i
+ 1] = (*mw_vec
)[i
+ dist
+ 1];
2304 mw_vec
->truncate (count
);
2308 /* Sort and remove duplicates from the COLLECTION_REC. */
2311 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2313 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2314 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2315 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2316 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2320 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2323 df_install_ref (df_ref this_ref
,
2324 struct df_reg_info
*reg_info
,
2325 struct df_ref_info
*ref_info
,
2328 unsigned int regno
= DF_REF_REGNO (this_ref
);
2329 /* Add the ref to the reg_{def,use,eq_use} chain. */
2330 df_ref head
= reg_info
->reg_chain
;
2332 reg_info
->reg_chain
= this_ref
;
2335 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2337 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2338 df
->hard_regs_live_count
[regno
]++;
2341 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2342 && DF_REF_PREV_REG (this_ref
) == NULL
);
2344 DF_REF_NEXT_REG (this_ref
) = head
;
2346 /* We cannot actually link to the head of the chain. */
2347 DF_REF_PREV_REG (this_ref
) = NULL
;
2350 DF_REF_PREV_REG (head
) = this_ref
;
2354 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2355 df_check_and_grow_ref_info (ref_info
, 1);
2356 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2357 /* Add the ref to the big array of defs. */
2358 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2359 ref_info
->table_size
++;
2362 DF_REF_ID (this_ref
) = -1;
2364 ref_info
->total_size
++;
2368 /* This function takes one of the groups of refs (defs, uses or
2369 eq_uses) and installs the entire group into the insn. It also adds
2370 each of these refs into the appropriate chains. */
2373 df_install_refs (basic_block bb
,
2374 const vec
<df_ref
, va_heap
> *old_vec
,
2375 struct df_reg_info
**reg_info
,
2376 struct df_ref_info
*ref_info
,
2379 unsigned int count
= old_vec
->length ();
2386 switch (ref_info
->ref_order
)
2388 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2389 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2390 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2391 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2392 add_to_table
= true;
2394 case DF_REF_ORDER_UNORDERED
:
2395 case DF_REF_ORDER_BY_REG
:
2396 case DF_REF_ORDER_BY_INSN
:
2397 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2398 add_to_table
= !is_notes
;
2401 add_to_table
= false;
2405 /* Do not add if ref is not in the right blocks. */
2406 if (add_to_table
&& df
->analyze_subset
)
2407 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2409 FOR_EACH_VEC_ELT (*old_vec
, ix
, this_ref
)
2411 DF_REF_NEXT_LOC (this_ref
) = (ix
+ 1 < old_vec
->length ()
2412 ? (*old_vec
)[ix
+ 1]
2414 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2415 ref_info
, add_to_table
);
2417 return (*old_vec
)[0];
2424 /* This function takes the mws installs the entire group into the
2427 static struct df_mw_hardreg
*
2428 df_install_mws (const vec
<df_mw_hardreg_ptr
, va_heap
> *old_vec
)
2430 unsigned int count
= old_vec
->length ();
2433 for (unsigned int i
= 0; i
< count
- 1; i
++)
2434 DF_MWS_NEXT ((*old_vec
)[i
]) = (*old_vec
)[i
+ 1];
2435 DF_MWS_NEXT ((*old_vec
)[count
- 1]) = 0;
2436 return (*old_vec
)[0];
2443 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2444 chains and update other necessary information. */
2447 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2448 basic_block bb
, rtx_insn
*insn
, unsigned int flags
)
2452 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2453 /* If there is a vector in the collection rec, add it to the
2454 insn. A null rec is a signal that the caller will handle the
2456 if (flags
& copy_defs
)
2458 gcc_checking_assert (!insn_rec
->defs
);
2460 = df_install_refs (bb
, &collection_rec
->def_vec
,
2462 &df
->def_info
, false);
2464 if (flags
& copy_uses
)
2466 gcc_checking_assert (!insn_rec
->uses
);
2468 = df_install_refs (bb
, &collection_rec
->use_vec
,
2470 &df
->use_info
, false);
2472 if (flags
& copy_eq_uses
)
2474 gcc_checking_assert (!insn_rec
->eq_uses
);
2476 = df_install_refs (bb
, &collection_rec
->eq_use_vec
,
2478 &df
->use_info
, true);
2480 if (flags
& copy_mw
)
2482 gcc_checking_assert (!insn_rec
->mw_hardregs
);
2483 insn_rec
->mw_hardregs
2484 = df_install_mws (&collection_rec
->mw_vec
);
2489 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2491 gcc_checking_assert (!bb_info
->artificial_defs
);
2492 bb_info
->artificial_defs
2493 = df_install_refs (bb
, &collection_rec
->def_vec
,
2495 &df
->def_info
, false);
2496 gcc_checking_assert (!bb_info
->artificial_uses
);
2497 bb_info
->artificial_uses
2498 = df_install_refs (bb
, &collection_rec
->use_vec
,
2500 &df
->use_info
, false);
2505 /* Allocate a ref and initialize its fields. */
2508 df_ref_create_structure (enum df_ref_class cl
,
2509 struct df_collection_rec
*collection_rec
,
2511 basic_block bb
, struct df_insn_info
*info
,
2512 enum df_ref_type ref_type
,
2515 df_ref this_ref
= NULL
;
2516 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2517 struct df_scan_problem_data
*problem_data
2518 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2523 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_base_pool
);
2524 gcc_checking_assert (loc
== NULL
);
2527 case DF_REF_ARTIFICIAL
:
2528 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_artificial_pool
);
2529 this_ref
->artificial_ref
.bb
= bb
;
2530 gcc_checking_assert (loc
== NULL
);
2533 case DF_REF_REGULAR
:
2534 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_regular_pool
);
2535 this_ref
->regular_ref
.loc
= loc
;
2536 gcc_checking_assert (loc
);
2540 DF_REF_CLASS (this_ref
) = cl
;
2541 DF_REF_ID (this_ref
) = -1;
2542 DF_REF_REG (this_ref
) = reg
;
2543 DF_REF_REGNO (this_ref
) = regno
;
2544 DF_REF_TYPE (this_ref
) = ref_type
;
2545 DF_REF_INSN_INFO (this_ref
) = info
;
2546 DF_REF_CHAIN (this_ref
) = NULL
;
2547 DF_REF_FLAGS (this_ref
) = ref_flags
;
2548 DF_REF_NEXT_REG (this_ref
) = NULL
;
2549 DF_REF_PREV_REG (this_ref
) = NULL
;
2550 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2552 /* We need to clear this bit because fwprop, and in the future
2553 possibly other optimizations sometimes create new refs using ond
2554 refs as the model. */
2555 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2557 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2558 if (regno
< FIRST_PSEUDO_REGISTER
2559 && !DF_REF_IS_ARTIFICIAL (this_ref
)
2560 && !DEBUG_INSN_P (DF_REF_INSN (this_ref
)))
2562 if (DF_REF_REG_DEF_P (this_ref
))
2564 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2565 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2567 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2568 && (regno
== FRAME_POINTER_REGNUM
2569 || regno
== ARG_POINTER_REGNUM
)))
2570 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2575 if (DF_REF_REG_DEF_P (this_ref
))
2576 collection_rec
->def_vec
.safe_push (this_ref
);
2577 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2578 collection_rec
->eq_use_vec
.safe_push (this_ref
);
2580 collection_rec
->use_vec
.safe_push (this_ref
);
2583 df_install_ref_incremental (this_ref
);
2589 /* Create new references of type DF_REF_TYPE for each part of register REG
2590 at address LOC within INSN of BB. */
2594 df_ref_record (enum df_ref_class cl
,
2595 struct df_collection_rec
*collection_rec
,
2597 basic_block bb
, struct df_insn_info
*insn_info
,
2598 enum df_ref_type ref_type
,
2603 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2605 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2606 if (regno
< FIRST_PSEUDO_REGISTER
)
2608 struct df_mw_hardreg
*hardreg
= NULL
;
2609 struct df_scan_problem_data
*problem_data
2610 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2612 unsigned int endregno
;
2615 if (GET_CODE (reg
) == SUBREG
)
2617 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2618 SUBREG_BYTE (reg
), GET_MODE (reg
));
2619 endregno
= regno
+ subreg_nregs (reg
);
2622 endregno
= END_HARD_REGNO (reg
);
2624 /* If this is a multiword hardreg, we create some extra
2625 datastructures that will enable us to easily build REG_DEAD
2626 and REG_UNUSED notes. */
2628 && (endregno
!= regno
+ 1) && insn_info
)
2630 /* Sets to a subreg of a multiword register are partial.
2631 Sets to a non-subreg of a multiword register are not. */
2632 if (GET_CODE (reg
) == SUBREG
)
2633 ref_flags
|= DF_REF_PARTIAL
;
2634 ref_flags
|= DF_REF_MW_HARDREG
;
2636 hardreg
= (struct df_mw_hardreg
*) pool_alloc (problem_data
->mw_reg_pool
);
2637 hardreg
->type
= ref_type
;
2638 hardreg
->flags
= ref_flags
;
2639 hardreg
->mw_reg
= reg
;
2640 hardreg
->start_regno
= regno
;
2641 hardreg
->end_regno
= endregno
- 1;
2642 hardreg
->mw_order
= df
->ref_order
++;
2643 collection_rec
->mw_vec
.safe_push (hardreg
);
2646 for (i
= regno
; i
< endregno
; i
++)
2648 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2649 bb
, insn_info
, ref_type
, ref_flags
);
2651 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2656 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2657 ref_type
, ref_flags
);
2662 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2663 covered by the outer mode is smaller than that covered by the inner mode,
2664 is a read-modify-write operation.
2665 This function returns true iff the SUBREG X is such a SUBREG. */
2668 df_read_modify_subreg_p (rtx x
)
2670 unsigned int isize
, osize
;
2671 if (GET_CODE (x
) != SUBREG
)
2673 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2674 osize
= GET_MODE_SIZE (GET_MODE (x
));
2675 return isize
> osize
2676 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2680 /* Process all the registers defined in the rtx pointed by LOC.
2681 Autoincrement/decrement definitions will be picked up by df_uses_record.
2682 Any change here has to be matched in df_find_hard_reg_defs_1. */
2685 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2686 rtx
*loc
, basic_block bb
, struct df_insn_info
*insn_info
,
2691 /* It is legal to have a set destination be a parallel. */
2692 if (GET_CODE (dst
) == PARALLEL
)
2695 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2697 rtx temp
= XVECEXP (dst
, 0, i
);
2698 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2699 df_def_record_1 (collection_rec
, &XEXP (temp
, 0),
2700 bb
, insn_info
, flags
);
2705 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2707 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2709 loc
= &XEXP (dst
, 0);
2713 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2715 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2717 loc
= &XEXP (dst
, 0);
2721 /* At this point if we do not have a reg or a subreg, just return. */
2724 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2725 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2727 /* We want to keep sp alive everywhere - by making all
2728 writes to sp also use of sp. */
2729 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2730 df_ref_record (DF_REF_BASE
, collection_rec
,
2731 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
2733 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2735 if (df_read_modify_subreg_p (dst
))
2736 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2738 flags
|= DF_REF_SUBREG
;
2740 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2741 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2746 /* Process all the registers defined in the pattern rtx, X. Any change
2747 here has to be matched in df_find_hard_reg_defs. */
2750 df_defs_record (struct df_collection_rec
*collection_rec
,
2751 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2754 RTX_CODE code
= GET_CODE (x
);
2760 df_def_record_1 (collection_rec
, &SET_DEST (x
), bb
, insn_info
, flags
);
2764 flags
|= DF_REF_MUST_CLOBBER
;
2765 df_def_record_1 (collection_rec
, &XEXP (x
, 0), bb
, insn_info
, flags
);
2769 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
2770 bb
, insn_info
, DF_REF_CONDITIONAL
);
2774 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2775 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
),
2776 bb
, insn_info
, flags
);
2779 /* No DEFs to record in other cases */
2784 /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
2785 destination of a set or clobber. This has to match the logic in
2786 df_defs_record_1. */
2789 df_find_hard_reg_defs_1 (rtx dst
, HARD_REG_SET
*defs
)
2791 /* It is legal to have a set destination be a parallel. */
2792 if (GET_CODE (dst
) == PARALLEL
)
2795 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2797 rtx temp
= XVECEXP (dst
, 0, i
);
2798 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2799 df_find_hard_reg_defs_1 (XEXP (temp
, 0), defs
);
2804 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2805 dst
= XEXP (dst
, 0);
2807 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2808 dst
= XEXP (dst
, 0);
2810 /* At this point if we do not have a reg or a subreg, just return. */
2811 if (REG_P (dst
) && HARD_REGISTER_P (dst
))
2812 SET_HARD_REG_BIT (*defs
, REGNO (dst
));
2813 else if (GET_CODE (dst
) == SUBREG
2814 && REG_P (SUBREG_REG (dst
)) && HARD_REGISTER_P (dst
))
2815 SET_HARD_REG_BIT (*defs
, REGNO (SUBREG_REG (dst
)));
2818 /* Set bits in *DEFS for hard registers defined in the pattern X. This
2819 has to match the logic in df_defs_record. */
2822 df_find_hard_reg_defs (rtx x
, HARD_REG_SET
*defs
)
2824 RTX_CODE code
= GET_CODE (x
);
2830 df_find_hard_reg_defs_1 (SET_DEST (x
), defs
);
2834 df_find_hard_reg_defs_1 (XEXP (x
, 0), defs
);
2838 df_find_hard_reg_defs (COND_EXEC_CODE (x
), defs
);
2842 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2843 df_find_hard_reg_defs (XVECEXP (x
, 0, i
), defs
);
2846 /* No DEFs to record in other cases */
2852 /* Process all the registers used in the rtx at address LOC. */
2855 df_uses_record (struct df_collection_rec
*collection_rec
,
2856 rtx
*loc
, enum df_ref_type ref_type
,
2857 basic_block bb
, struct df_insn_info
*insn_info
,
2867 code
= GET_CODE (x
);
2881 /* If we are clobbering a MEM, mark any registers inside the address
2883 if (MEM_P (XEXP (x
, 0)))
2884 df_uses_record (collection_rec
,
2885 &XEXP (XEXP (x
, 0), 0),
2886 DF_REF_REG_MEM_STORE
,
2890 /* If we're clobbering a REG then we have a def so ignore. */
2894 df_uses_record (collection_rec
,
2895 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
2896 bb
, insn_info
, flags
& DF_REF_IN_NOTE
);
2900 /* While we're here, optimize this case. */
2901 flags
|= DF_REF_PARTIAL
;
2902 /* In case the SUBREG is not of a REG, do not optimize. */
2903 if (!REG_P (SUBREG_REG (x
)))
2905 loc
= &SUBREG_REG (x
);
2906 df_uses_record (collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
);
2909 /* ... Fall through ... */
2912 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2913 x
, loc
, bb
, insn_info
,
2920 df_uses_record (collection_rec
,
2921 &XEXP (x
, 1), ref_type
, bb
, insn_info
, flags
);
2922 df_uses_record (collection_rec
,
2923 &XEXP (x
, 2), ref_type
, bb
, insn_info
, flags
);
2925 /* If the parameters to the zero or sign extract are
2926 constants, strip them off and recurse, otherwise there is
2927 no information that we can gain from this operation. */
2928 if (code
== ZERO_EXTRACT
)
2929 flags
|= DF_REF_ZERO_EXTRACT
;
2931 flags
|= DF_REF_SIGN_EXTRACT
;
2933 df_uses_record (collection_rec
,
2934 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
);
2941 rtx dst
= SET_DEST (x
);
2942 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
2943 df_uses_record (collection_rec
,
2944 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
);
2946 switch (GET_CODE (dst
))
2949 if (df_read_modify_subreg_p (dst
))
2951 df_uses_record (collection_rec
, &SUBREG_REG (dst
),
2952 DF_REF_REG_USE
, bb
, insn_info
,
2953 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
);
2964 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2965 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
);
2967 case STRICT_LOW_PART
:
2969 rtx
*temp
= &XEXP (dst
, 0);
2970 /* A strict_low_part uses the whole REG and not just the
2972 dst
= XEXP (dst
, 0);
2973 df_uses_record (collection_rec
,
2974 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
2975 DF_REF_REG_USE
, bb
, insn_info
,
2976 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
);
2981 df_uses_record (collection_rec
, &XEXP (dst
, 1),
2982 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2983 df_uses_record (collection_rec
, &XEXP (dst
, 2),
2984 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2985 if (GET_CODE (XEXP (dst
,0)) == MEM
)
2986 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2987 DF_REF_REG_USE
, bb
, insn_info
,
2990 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2991 DF_REF_REG_USE
, bb
, insn_info
,
2992 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
);
3007 case UNSPEC_VOLATILE
:
3011 /* Traditional and volatile asm instructions must be
3012 considered to use and clobber all hard registers, all
3013 pseudo-registers and all of memory. So must TRAP_IF and
3014 UNSPEC_VOLATILE operations.
3016 Consider for instance a volatile asm that changes the fpu
3017 rounding mode. An insn should not be moved across this
3018 even if it only uses pseudo-regs because it might give an
3019 incorrectly rounded result.
3021 However, flow.c's liveness computation did *not* do this,
3022 giving the reasoning as " ?!? Unfortunately, marking all
3023 hard registers as live causes massive problems for the
3024 register allocator and marking all pseudos as live creates
3025 mountains of uninitialized variable warnings."
3027 In order to maintain the status quo with regard to liveness
3028 and uses, we do what flow.c did and just mark any regs we
3029 can find in ASM_OPERANDS as used. In global asm insns are
3030 scanned and regs_asm_clobbered is filled out.
3032 For all ASM_OPERANDS, we must traverse the vector of input
3033 operands. We can not just fall through here since then we
3034 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3035 which do not indicate traditional asms unlike their normal
3037 if (code
== ASM_OPERANDS
)
3041 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3042 df_uses_record (collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3043 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3050 df_uses_record (collection_rec
,
3051 &PAT_VAR_LOCATION_LOC (x
),
3052 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3061 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3062 /* Catch the def of the register being modified. */
3063 df_ref_record (DF_REF_REGULAR
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3066 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
);
3068 /* ... Fall through to handle uses ... */
3074 /* Recursively scan the operands of this expression. */
3076 const char *fmt
= GET_RTX_FORMAT (code
);
3079 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3083 /* Tail recursive case: save a function call level. */
3089 df_uses_record (collection_rec
, &XEXP (x
, i
), ref_type
,
3090 bb
, insn_info
, flags
);
3092 else if (fmt
[i
] == 'E')
3095 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3096 df_uses_record (collection_rec
,
3097 &XVECEXP (x
, i
, j
), ref_type
,
3098 bb
, insn_info
, flags
);
3107 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3110 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3115 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
3117 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3121 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3122 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3123 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3124 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
);
3125 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3131 /* Get call's extra defs and uses (track caller-saved registers). */
3134 df_get_call_refs (struct df_collection_rec
*collection_rec
,
3136 struct df_insn_info
*insn_info
,
3140 bool is_sibling_call
;
3142 HARD_REG_SET defs_generated
;
3143 HARD_REG_SET fn_reg_set_usage
;
3145 CLEAR_HARD_REG_SET (defs_generated
);
3146 df_find_hard_reg_defs (PATTERN (insn_info
->insn
), &defs_generated
);
3147 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3148 get_call_reg_set_usage (insn_info
->insn
, &fn_reg_set_usage
,
3149 regs_invalidated_by_call
);
3151 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3153 if (i
== STACK_POINTER_REGNUM
)
3154 /* The stack ptr is used (honorarily) by a CALL insn. */
3155 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3156 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3157 DF_REF_CALL_STACK_USAGE
| flags
);
3158 else if (global_regs
[i
])
3160 /* Calls to const functions cannot access any global registers and
3161 calls to pure functions cannot set them. All other calls may
3162 reference any of the global registers, so they are recorded as
3164 if (!RTL_CONST_CALL_P (insn_info
->insn
))
3166 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3167 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
3168 if (!RTL_PURE_CALL_P (insn_info
->insn
))
3169 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3170 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3173 else if (TEST_HARD_REG_BIT (fn_reg_set_usage
, i
)
3174 /* no clobbers for regs that are the result of the call */
3175 && !TEST_HARD_REG_BIT (defs_generated
, i
)
3176 && (!is_sibling_call
3177 || !bitmap_bit_p (df
->exit_block_uses
, i
)
3178 || refers_to_regno_p (i
, crtl
->return_rtx
)))
3179 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3180 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3181 DF_REF_MAY_CLOBBER
| flags
);
3184 /* Record the registers used to pass arguments, and explicitly
3185 noted as clobbered. */
3186 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3187 note
= XEXP (note
, 1))
3189 if (GET_CODE (XEXP (note
, 0)) == USE
)
3190 df_uses_record (collection_rec
, &XEXP (XEXP (note
, 0), 0),
3191 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3192 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3194 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3196 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3197 if (!TEST_HARD_REG_BIT (defs_generated
, regno
))
3198 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3202 df_uses_record (collection_rec
, &XEXP (note
, 0),
3203 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3210 /* Collect all refs in the INSN. This function is free of any
3211 side-effect - it will create and return a lists of df_ref's in the
3212 COLLECTION_REC without putting those refs into existing ref chains
3216 df_insn_refs_collect (struct df_collection_rec
*collection_rec
,
3217 basic_block bb
, struct df_insn_info
*insn_info
)
3220 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3222 /* Clear out the collection record. */
3223 collection_rec
->def_vec
.truncate (0);
3224 collection_rec
->use_vec
.truncate (0);
3225 collection_rec
->eq_use_vec
.truncate (0);
3226 collection_rec
->mw_vec
.truncate (0);
3228 /* Process REG_EQUIV/REG_EQUAL notes. */
3229 for (note
= REG_NOTES (insn_info
->insn
); note
;
3230 note
= XEXP (note
, 1))
3232 switch (REG_NOTE_KIND (note
))
3236 df_uses_record (collection_rec
,
3237 &XEXP (note
, 0), DF_REF_REG_USE
,
3238 bb
, insn_info
, DF_REF_IN_NOTE
);
3240 case REG_NON_LOCAL_GOTO
:
3241 /* The frame ptr is used by a non-local goto. */
3242 df_ref_record (DF_REF_BASE
, collection_rec
,
3243 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3244 NULL
, bb
, insn_info
,
3246 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3247 df_ref_record (DF_REF_BASE
, collection_rec
,
3248 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3249 NULL
, bb
, insn_info
,
3257 /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
3258 uses from CALL_INSN_FUNCTION_USAGE. */
3259 if (CALL_P (insn_info
->insn
))
3260 df_get_call_refs (collection_rec
, bb
, insn_info
,
3261 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3263 /* Record other defs. These should be mostly for DF_REF_REGULAR, so
3264 that a qsort on the defs is unnecessary in most cases. */
3265 df_defs_record (collection_rec
,
3266 PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3268 /* Record the register uses. */
3269 df_uses_record (collection_rec
,
3270 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0);
3272 /* DF_REF_CONDITIONAL needs corresponding USES. */
3274 df_get_conditional_uses (collection_rec
);
3276 df_canonize_collection_rec (collection_rec
);
3279 /* Recompute the luids for the insns in BB. */
3282 df_recompute_luids (basic_block bb
)
3287 df_grow_insn_info ();
3289 /* Scan the block an insn at a time from beginning to end. */
3290 FOR_BB_INSNS (bb
, insn
)
3292 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3293 /* Inserting labels does not always trigger the incremental
3297 gcc_assert (!INSN_P (insn
));
3298 insn_info
= df_insn_create_insn_record (insn
);
3301 DF_INSN_INFO_LUID (insn_info
) = luid
;
3308 /* Collect all artificial refs at the block level for BB and add them
3309 to COLLECTION_REC. */
3312 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3314 collection_rec
->def_vec
.truncate (0);
3315 collection_rec
->use_vec
.truncate (0);
3316 collection_rec
->eq_use_vec
.truncate (0);
3317 collection_rec
->mw_vec
.truncate (0);
3319 if (bb
->index
== ENTRY_BLOCK
)
3321 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3324 else if (bb
->index
== EXIT_BLOCK
)
3326 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3330 if (bb_has_eh_pred (bb
))
3333 /* Mark the registers that will contain data for the handler. */
3336 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3337 if (regno
== INVALID_REGNUM
)
3339 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3340 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3344 /* Add the hard_frame_pointer if this block is the target of a
3346 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3347 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3348 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3350 /* Add the artificial uses. */
3351 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3355 bitmap au
= bb_has_eh_pred (bb
)
3356 ? &df
->eh_block_artificial_uses
3357 : &df
->regular_block_artificial_uses
;
3359 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3361 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3362 bb
, NULL
, DF_REF_REG_USE
, 0);
3366 df_canonize_collection_rec (collection_rec
);
3370 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3373 df_bb_refs_record (int bb_index
, bool scan_insns
)
3375 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3382 df_collection_rec collection_rec
;
3383 df_grow_bb_info (df_scan
);
3385 /* Scan the block an insn at a time from beginning to end. */
3386 FOR_BB_INSNS (bb
, insn
)
3388 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3389 gcc_assert (!insn_info
);
3391 insn_info
= df_insn_create_insn_record (insn
);
3394 /* Record refs within INSN. */
3395 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3396 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3397 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
3399 DF_INSN_INFO_LUID (insn_info
) = luid
;
3402 /* Other block level artificial refs */
3403 df_bb_refs_collect (&collection_rec
, bb
);
3404 df_refs_add_to_chains (&collection_rec
, bb
, NULL
, copy_all
);
3406 /* Now that the block has been processed, set the block as dirty so
3407 LR and LIVE will get it processed. */
3408 df_set_bb_dirty (bb
);
3412 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3416 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3422 bitmap_clear (regular_block_artificial_uses
);
3424 if (reload_completed
)
3426 if (frame_pointer_needed
)
3427 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3430 /* Before reload, there are a few registers that must be forced
3431 live everywhere -- which might not already be the case for
3432 blocks within infinite loops. */
3434 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3436 /* Any reference to any pseudo before reload is a potential
3437 reference of the frame pointer. */
3438 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3440 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3441 bitmap_set_bit (regular_block_artificial_uses
,
3442 HARD_FRAME_POINTER_REGNUM
);
3444 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3445 /* Pseudos with argument area equivalences may require
3446 reloading via the argument pointer. */
3447 if (fixed_regs
[ARG_POINTER_REGNUM
])
3448 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3451 /* Any constant, or pseudo with constant equivalences, may
3452 require reloading from memory using the pic register. */
3453 if (picreg
!= INVALID_REGNUM
3454 && fixed_regs
[picreg
])
3455 bitmap_set_bit (regular_block_artificial_uses
, picreg
);
3457 /* The all-important stack pointer must always be live. */
3458 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3461 /* EH_USES registers are used:
3462 1) at all insns that might throw (calls or with -fnon-call-exceptions
3465 3) to support backtraces and/or debugging, anywhere between their
3466 initialization and where they the saved registers are restored
3467 from them, including the cases where we don't reach the epilogue
3468 (noreturn call or infinite loop). */
3469 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3471 bitmap_set_bit (regular_block_artificial_uses
, i
);
3476 /* Get the artificial use set for an eh block. */
3479 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3481 bitmap_clear (eh_block_artificial_uses
);
3483 /* The following code (down through the arg_pointer setting APPEARS
3484 to be necessary because there is nothing that actually
3485 describes what the exception handling code may actually need
3487 if (reload_completed
)
3489 if (frame_pointer_needed
)
3491 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3492 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3493 bitmap_set_bit (eh_block_artificial_uses
,
3494 HARD_FRAME_POINTER_REGNUM
);
3496 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3497 if (fixed_regs
[ARG_POINTER_REGNUM
])
3498 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3505 /*----------------------------------------------------------------------------
3506 Specialized hard register scanning functions.
3507 ----------------------------------------------------------------------------*/
3510 /* Mark a register in SET. Hard registers in large modes get all
3511 of their component registers set as well. */
3514 df_mark_reg (rtx reg
, void *vset
)
3516 bitmap set
= (bitmap
) vset
;
3517 int regno
= REGNO (reg
);
3519 gcc_assert (GET_MODE (reg
) != BLKmode
);
3521 if (regno
< FIRST_PSEUDO_REGISTER
)
3523 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3524 bitmap_set_range (set
, regno
, n
);
3527 bitmap_set_bit (set
, regno
);
3531 /* Set the bit for regs that are considered being defined at the entry. */
3534 df_get_entry_block_def_set (bitmap entry_block_defs
)
3539 bitmap_clear (entry_block_defs
);
3541 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3544 bitmap_set_bit (entry_block_defs
, i
);
3545 if (FUNCTION_ARG_REGNO_P (i
))
3546 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3549 /* The always important stack pointer. */
3550 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3552 /* Once the prologue has been generated, all of these registers
3553 should just show up in the first regular block. */
3554 if (HAVE_prologue
&& epilogue_completed
)
3556 /* Defs for the callee saved registers are inserted so that the
3557 pushes have some defining location. */
3558 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3559 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3560 bitmap_set_bit (entry_block_defs
, i
);
3563 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3565 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3567 /* If the function has an incoming STATIC_CHAIN, it has to show up
3568 in the entry def set. */
3569 r
= targetm
.calls
.static_chain (current_function_decl
, true);
3571 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3573 if ((!reload_completed
) || frame_pointer_needed
)
3575 /* Any reference to any pseudo before reload is a potential
3576 reference of the frame pointer. */
3577 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3579 /* If they are different, also mark the hard frame pointer as live. */
3580 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3581 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3582 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3585 /* These registers are live everywhere. */
3586 if (!reload_completed
)
3588 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3589 /* Pseudos with argument area equivalences may require
3590 reloading via the argument pointer. */
3591 if (fixed_regs
[ARG_POINTER_REGNUM
])
3592 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3595 /* Any constant, or pseudo with constant equivalences, may
3596 require reloading from memory using the pic register. */
3597 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3598 if (picreg
!= INVALID_REGNUM
3599 && fixed_regs
[picreg
])
3600 bitmap_set_bit (entry_block_defs
, picreg
);
3603 #ifdef INCOMING_RETURN_ADDR_RTX
3604 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3605 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3608 targetm
.extra_live_on_entry (entry_block_defs
);
3612 /* Return the (conservative) set of hard registers that are defined on
3613 entry to the function.
3614 It uses df->entry_block_defs to determine which register
3615 reference to include. */
3618 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3619 bitmap entry_block_defs
)
3624 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3626 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3627 ENTRY_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_DEF
, 0);
3630 df_canonize_collection_rec (collection_rec
);
3634 /* Record the (conservative) set of hard registers that are defined on
3635 entry to the function. */
3638 df_record_entry_block_defs (bitmap entry_block_defs
)
3640 struct df_collection_rec collection_rec
;
3641 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3643 /* Process bb_refs chain */
3644 df_refs_add_to_chains (&collection_rec
,
3645 BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
),
3651 /* Update the defs in the entry block. */
3654 df_update_entry_block_defs (void)
3657 bool changed
= false;
3659 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3660 df_get_entry_block_def_set (&refs
);
3661 if (df
->entry_block_defs
)
3663 if (!bitmap_equal_p (df
->entry_block_defs
, &refs
))
3665 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3666 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3667 df_ref_chain_delete (bb_info
->artificial_defs
);
3668 bb_info
->artificial_defs
= NULL
;
3674 struct df_scan_problem_data
*problem_data
3675 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3677 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3683 df_record_entry_block_defs (&refs
);
3684 bitmap_copy (df
->entry_block_defs
, &refs
);
3685 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
3687 bitmap_clear (&refs
);
3691 /* Set the bit for regs that are considered being used at the exit. */
3694 df_get_exit_block_use_set (bitmap exit_block_uses
)
3697 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3699 bitmap_clear (exit_block_uses
);
3701 /* Stack pointer is always live at the exit. */
3702 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3704 /* Mark the frame pointer if needed at the end of the function.
3705 If we end up eliminating it, it will be removed from the live
3706 list of each basic block by reload. */
3708 if ((!reload_completed
) || frame_pointer_needed
)
3710 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3712 /* If they are different, also mark the hard frame pointer as live. */
3713 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3714 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3715 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3718 /* Many architectures have a GP register even without flag_pic.
3719 Assume the pic register is not in use, or will be handled by
3720 other means, if it is not fixed. */
3721 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3722 && picreg
!= INVALID_REGNUM
3723 && fixed_regs
[picreg
])
3724 bitmap_set_bit (exit_block_uses
, picreg
);
3726 /* Mark all global registers, and all registers used by the
3727 epilogue as being live at the end of the function since they
3728 may be referenced by our caller. */
3729 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3730 if (global_regs
[i
] || EPILOGUE_USES (i
))
3731 bitmap_set_bit (exit_block_uses
, i
);
3733 if (HAVE_epilogue
&& epilogue_completed
)
3735 /* Mark all call-saved registers that we actually used. */
3736 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3737 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
3738 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3739 bitmap_set_bit (exit_block_uses
, i
);
3742 /* Mark the registers that will contain data for the handler. */
3743 if (reload_completed
&& crtl
->calls_eh_return
)
3746 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3747 if (regno
== INVALID_REGNUM
)
3749 bitmap_set_bit (exit_block_uses
, regno
);
3752 #ifdef EH_RETURN_STACKADJ_RTX
3753 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3754 && crtl
->calls_eh_return
)
3756 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
3757 if (tmp
&& REG_P (tmp
))
3758 df_mark_reg (tmp
, exit_block_uses
);
3762 #ifdef EH_RETURN_HANDLER_RTX
3763 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3764 && crtl
->calls_eh_return
)
3766 rtx tmp
= EH_RETURN_HANDLER_RTX
;
3767 if (tmp
&& REG_P (tmp
))
3768 df_mark_reg (tmp
, exit_block_uses
);
3772 /* Mark function return value. */
3773 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
3777 /* Return the refs of hard registers that are used in the exit block.
3778 It uses df->exit_block_uses to determine register to include. */
3781 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
3786 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
3787 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3788 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3790 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3791 /* It is deliberate that this is not put in the exit block uses but
3792 I do not know why. */
3793 if (reload_completed
3794 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
3795 && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun
))
3796 && fixed_regs
[ARG_POINTER_REGNUM
])
3797 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
3798 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3801 df_canonize_collection_rec (collection_rec
);
3805 /* Record the set of hard registers that are used in the exit block.
3806 It uses df->exit_block_uses to determine which bit to include. */
3809 df_record_exit_block_uses (bitmap exit_block_uses
)
3811 struct df_collection_rec collection_rec
;
3812 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
3814 /* Process bb_refs chain */
3815 df_refs_add_to_chains (&collection_rec
,
3816 BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
),
3822 /* Update the uses in the exit block. */
3825 df_update_exit_block_uses (void)
3828 bool changed
= false;
3830 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3831 df_get_exit_block_use_set (&refs
);
3832 if (df
->exit_block_uses
)
3834 if (!bitmap_equal_p (df
->exit_block_uses
, &refs
))
3836 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
3837 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
3838 df_ref_chain_delete (bb_info
->artificial_uses
);
3839 bb_info
->artificial_uses
= NULL
;
3845 struct df_scan_problem_data
*problem_data
3846 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3848 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3854 df_record_exit_block_uses (&refs
);
3855 bitmap_copy (df
->exit_block_uses
,& refs
);
3856 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
3858 bitmap_clear (&refs
);
3861 static bool initialized
= false;
3864 /* Initialize some platform specific structures. */
3867 df_hard_reg_init (void)
3869 #ifdef ELIMINABLE_REGS
3871 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
3876 /* Record which registers will be eliminated. We use this in
3878 CLEAR_HARD_REG_SET (elim_reg_set
);
3880 #ifdef ELIMINABLE_REGS
3881 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
3882 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
3884 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
3891 /* Recompute the parts of scanning that are based on regs_ever_live
3892 because something changed in that array. */
3895 df_update_entry_exit_and_calls (void)
3899 df_update_entry_block_defs ();
3900 df_update_exit_block_uses ();
3902 /* The call insns need to be rescanned because there may be changes
3903 in the set of registers clobbered across the call. */
3904 FOR_EACH_BB_FN (bb
, cfun
)
3907 FOR_BB_INSNS (bb
, insn
)
3909 if (INSN_P (insn
) && CALL_P (insn
))
3910 df_insn_rescan (insn
);
3916 /* Return true if hard REG is actually used in the some instruction.
3917 There are a fair number of conditions that affect the setting of
3918 this array. See the comment in df.h for df->hard_regs_live_count
3919 for the conditions that this array is set. */
3922 df_hard_reg_used_p (unsigned int reg
)
3924 return df
->hard_regs_live_count
[reg
] != 0;
3928 /* A count of the number of times REG is actually used in the some
3929 instruction. There are a fair number of conditions that affect the
3930 setting of this array. See the comment in df.h for
3931 df->hard_regs_live_count for the conditions that this array is
3936 df_hard_reg_used_count (unsigned int reg
)
3938 return df
->hard_regs_live_count
[reg
];
3942 /* Get the value of regs_ever_live[REGNO]. */
3945 df_regs_ever_live_p (unsigned int regno
)
3947 return regs_ever_live
[regno
];
3951 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
3952 to change, schedule that change for the next update. */
3955 df_set_regs_ever_live (unsigned int regno
, bool value
)
3957 if (regs_ever_live
[regno
] == value
)
3960 regs_ever_live
[regno
] = value
;
3962 df
->redo_entry_and_exit
= true;
3966 /* Compute "regs_ever_live" information from the underlying df
3967 information. Set the vector to all false if RESET. */
3970 df_compute_regs_ever_live (bool reset
)
3973 bool changed
= df
->redo_entry_and_exit
;
3976 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
3978 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3979 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
3981 regs_ever_live
[i
] = true;
3985 df_update_entry_exit_and_calls ();
3986 df
->redo_entry_and_exit
= false;
3990 /*----------------------------------------------------------------------------
3991 Dataflow ref information verification functions.
3993 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
3994 df_reg_chain_verify_unmarked (refs)
3995 df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
3996 df_mws_verify (mw*, mw*, bool)
3997 df_insn_refs_verify (collection_rec, bb, insn, bool)
3998 df_bb_refs_verify (bb, refs, bool)
4000 df_exit_block_bitmap_verify (bool)
4001 df_entry_block_bitmap_verify (bool)
4003 ----------------------------------------------------------------------------*/
4006 /* Mark all refs in the reg chain. Verify that all of the registers
4007 are in the correct chain. */
4010 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
4011 bool is_def
, bool is_eq_use
)
4013 unsigned int count
= 0;
4015 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4017 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4019 /* If there are no def-use or use-def chains, make sure that all
4020 of the chains are clear. */
4022 gcc_assert (!DF_REF_CHAIN (ref
));
4024 /* Check to make sure the ref is in the correct chain. */
4025 gcc_assert (DF_REF_REGNO (ref
) == regno
);
4027 gcc_assert (DF_REF_REG_DEF_P (ref
));
4029 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4032 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4034 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4036 if (DF_REF_NEXT_REG (ref
))
4037 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4039 DF_REF_REG_MARK (ref
);
4045 /* Verify that all of the registers in the chain are unmarked. */
4048 df_reg_chain_verify_unmarked (df_ref refs
)
4051 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4052 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4056 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4059 df_refs_verify (const vec
<df_ref
, va_heap
> *new_rec
, df_ref old_rec
,
4065 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_ref
)
4067 if (old_rec
== NULL
|| !df_ref_equal_p (new_ref
, old_rec
))
4075 /* Abort if fail is called from the function level verifier. If
4076 that is the context, mark this reg as being seem. */
4079 gcc_assert (DF_REF_IS_REG_MARKED (old_rec
));
4080 DF_REF_REG_UNMARK (old_rec
);
4083 old_rec
= DF_REF_NEXT_LOC (old_rec
);
4087 gcc_assert (old_rec
== NULL
);
4089 return old_rec
== NULL
;
4094 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4097 df_mws_verify (const vec
<df_mw_hardreg_ptr
, va_heap
> *new_rec
,
4098 struct df_mw_hardreg
*old_rec
,
4102 struct df_mw_hardreg
*new_reg
;
4104 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_reg
)
4106 if (old_rec
== NULL
|| !df_mw_equal_p (new_reg
, old_rec
))
4113 old_rec
= DF_MWS_NEXT (old_rec
);
4117 gcc_assert (old_rec
== NULL
);
4119 return old_rec
== NULL
;
4124 /* Return true if the existing insn refs information is complete and
4125 correct. Otherwise (i.e. if there's any missing or extra refs),
4126 return the correct df_ref chain in REFS_RETURN.
4128 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4129 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4130 verification mode instead of the whole function, so unmark
4133 If ABORT_IF_FAIL is set, this function never returns false. */
4136 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4141 bool ret1
, ret2
, ret3
, ret4
;
4142 unsigned int uid
= INSN_UID (insn
);
4143 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4145 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4147 /* Unfortunately we cannot opt out early if one of these is not
4148 right because the marks will not get cleared. */
4149 ret1
= df_refs_verify (&collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4151 ret2
= df_refs_verify (&collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4153 ret3
= df_refs_verify (&collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4155 ret4
= df_mws_verify (&collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4157 return (ret1
&& ret2
&& ret3
&& ret4
);
4161 /* Return true if all refs in the basic block are correct and complete.
4162 Due to df_ref_chain_verify, it will cause all refs
4163 that are verified to have DF_REF_MARK bit set. */
4166 df_bb_verify (basic_block bb
)
4169 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4170 struct df_collection_rec collection_rec
;
4172 gcc_assert (bb_info
);
4174 /* Scan the block, one insn at a time, from beginning to end. */
4175 FOR_BB_INSNS_REVERSE (bb
, insn
)
4179 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4180 df_free_collection_rec (&collection_rec
);
4183 /* Do the artificial defs and uses. */
4184 df_bb_refs_collect (&collection_rec
, bb
);
4185 df_refs_verify (&collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4186 df_refs_verify (&collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4187 df_free_collection_rec (&collection_rec
);
4193 /* Returns true if the entry 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_entry_block_bitmap_verify (bool abort_if_fail
)
4199 bitmap_head entry_block_defs
;
4202 bitmap_initialize (&entry_block_defs
, &df_bitmap_obstack
);
4203 df_get_entry_block_def_set (&entry_block_defs
);
4205 is_eq
= bitmap_equal_p (&entry_block_defs
, df
->entry_block_defs
);
4207 if (!is_eq
&& abort_if_fail
)
4209 fprintf (stderr
, "entry_block_defs = ");
4210 df_print_regset (stderr
, &entry_block_defs
);
4211 fprintf (stderr
, "df->entry_block_defs = ");
4212 df_print_regset (stderr
, df
->entry_block_defs
);
4216 bitmap_clear (&entry_block_defs
);
4222 /* Returns true if the exit block has correct and complete df_ref set.
4223 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4226 df_exit_block_bitmap_verify (bool abort_if_fail
)
4228 bitmap_head exit_block_uses
;
4231 bitmap_initialize (&exit_block_uses
, &df_bitmap_obstack
);
4232 df_get_exit_block_use_set (&exit_block_uses
);
4234 is_eq
= bitmap_equal_p (&exit_block_uses
, df
->exit_block_uses
);
4236 if (!is_eq
&& abort_if_fail
)
4238 fprintf (stderr
, "exit_block_uses = ");
4239 df_print_regset (stderr
, &exit_block_uses
);
4240 fprintf (stderr
, "df->exit_block_uses = ");
4241 df_print_regset (stderr
, df
->exit_block_uses
);
4245 bitmap_clear (&exit_block_uses
);
4251 /* Return true if df_ref information for all insns in all blocks are
4252 correct and complete. */
4255 df_scan_verify (void)
4259 bitmap_head regular_block_artificial_uses
;
4260 bitmap_head eh_block_artificial_uses
;
4265 /* Verification is a 4 step process. */
4267 /* (1) All of the refs are marked by going through the reg chains. */
4268 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4270 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4271 == DF_REG_DEF_COUNT (i
));
4272 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4273 == DF_REG_USE_COUNT (i
));
4274 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4275 == DF_REG_EQ_USE_COUNT (i
));
4278 /* (2) There are various bitmaps whose value may change over the
4279 course of the compilation. This step recomputes them to make
4280 sure that they have not slipped out of date. */
4281 bitmap_initialize (®ular_block_artificial_uses
, &df_bitmap_obstack
);
4282 bitmap_initialize (&eh_block_artificial_uses
, &df_bitmap_obstack
);
4284 df_get_regular_block_artificial_uses (®ular_block_artificial_uses
);
4285 df_get_eh_block_artificial_uses (&eh_block_artificial_uses
);
4287 bitmap_ior_into (&eh_block_artificial_uses
,
4288 ®ular_block_artificial_uses
);
4290 /* Check artificial_uses bitmaps didn't change. */
4291 gcc_assert (bitmap_equal_p (®ular_block_artificial_uses
,
4292 &df
->regular_block_artificial_uses
));
4293 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses
,
4294 &df
->eh_block_artificial_uses
));
4296 bitmap_clear (®ular_block_artificial_uses
);
4297 bitmap_clear (&eh_block_artificial_uses
);
4299 /* Verify entry block and exit block. These only verify the bitmaps,
4300 the refs are verified in df_bb_verify. */
4301 df_entry_block_bitmap_verify (true);
4302 df_exit_block_bitmap_verify (true);
4304 /* (3) All of the insns in all of the blocks are traversed and the
4305 marks are cleared both in the artificial refs attached to the
4306 blocks and the real refs inside the insns. It is a failure to
4307 clear a mark that has not been set as this means that the ref in
4308 the block or insn was not in the reg chain. */
4310 FOR_ALL_BB_FN (bb
, cfun
)
4313 /* (4) See if all reg chains are traversed a second time. This time
4314 a check is made that the marks are clear. A set mark would be a
4315 from a reg that is not in any insn or basic block. */
4317 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4319 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4320 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4321 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));