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"
35 #include "hard-reg-set.h"
39 #include "alloc-pool.h"
42 #include "dominance.h"
44 #include "basic-block.h"
50 #include "target-def.h"
52 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
55 typedef struct df_mw_hardreg
*df_mw_hardreg_ptr
;
59 #define HAVE_prologue 0
61 #ifndef HAVE_sibcall_epilogue
62 #define HAVE_sibcall_epilogue 0
65 /* The set of hard registers in eliminables[i].from. */
67 static HARD_REG_SET elim_reg_set
;
69 /* Initialize ur_in and ur_out as if all hard registers were partially
72 struct df_collection_rec
74 auto_vec
<df_ref
, 128> def_vec
;
75 auto_vec
<df_ref
, 32> use_vec
;
76 auto_vec
<df_ref
, 32> eq_use_vec
;
77 auto_vec
<df_mw_hardreg_ptr
, 32> mw_vec
;
80 static void df_ref_record (enum df_ref_class
, struct df_collection_rec
*,
82 basic_block
, struct df_insn_info
*,
83 enum df_ref_type
, int ref_flags
);
84 static void df_def_record_1 (struct df_collection_rec
*, rtx
*,
85 basic_block
, struct df_insn_info
*,
87 static void df_defs_record (struct df_collection_rec
*, rtx
,
88 basic_block
, struct df_insn_info
*,
90 static void df_uses_record (struct df_collection_rec
*,
91 rtx
*, enum df_ref_type
,
92 basic_block
, struct df_insn_info
*,
95 static void df_install_ref_incremental (df_ref
);
96 static void df_insn_refs_collect (struct df_collection_rec
*,
97 basic_block
, struct df_insn_info
*);
98 static void df_canonize_collection_rec (struct df_collection_rec
*);
100 static void df_get_regular_block_artificial_uses (bitmap
);
101 static void df_get_eh_block_artificial_uses (bitmap
);
103 static void df_record_entry_block_defs (bitmap
);
104 static void df_record_exit_block_uses (bitmap
);
105 static void df_get_exit_block_use_set (bitmap
);
106 static void df_get_entry_block_def_set (bitmap
);
107 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
108 static void df_ref_chain_delete_du_chain (df_ref
);
109 static void df_ref_chain_delete (df_ref
);
111 static void df_refs_add_to_chains (struct df_collection_rec
*,
112 basic_block
, rtx_insn
*, unsigned int);
114 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
,
116 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
117 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
118 static void df_install_ref (df_ref
, struct df_reg_info
*,
119 struct df_ref_info
*, bool);
121 static int df_ref_compare (df_ref
, df_ref
);
122 static int df_ref_ptr_compare (const void *, const void *);
123 static int df_mw_compare (const df_mw_hardreg
*, const df_mw_hardreg
*);
124 static int df_mw_ptr_compare (const void *, const void *);
126 static void df_insn_info_delete (unsigned int);
128 /* Indexed by hardware reg number, is true if that register is ever
129 used in the current function.
131 In df-scan.c, this is set up to record the hard regs used
132 explicitly. Reload adds in the hard regs used for holding pseudo
133 regs. Final uses it to generate the code in the function prologue
134 and epilogue to save and restore registers as needed. */
136 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
138 /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
139 static const unsigned int copy_defs
= 0x1;
140 static const unsigned int copy_uses
= 0x2;
141 static const unsigned int copy_eq_uses
= 0x4;
142 static const unsigned int copy_mw
= 0x8;
143 static const unsigned int copy_all
= copy_defs
| copy_uses
| copy_eq_uses
146 /*----------------------------------------------------------------------------
147 SCANNING DATAFLOW PROBLEM
149 There are several ways in which scanning looks just like the other
150 dataflow problems. It shares the all the mechanisms for local info
151 as well as basic block info. Where it differs is when and how often
152 it gets run. It also has no need for the iterative solver.
153 ----------------------------------------------------------------------------*/
155 #define SCAN_PROBLEM_DATA_BLOCK_SIZE 512
157 /* Problem data for the scanning dataflow function. */
158 struct df_scan_problem_data
160 pool_allocator
<df_base_ref
> *ref_base_pool
;
161 pool_allocator
<df_artificial_ref
> *ref_artificial_pool
;
162 pool_allocator
<df_regular_ref
> *ref_regular_pool
;
163 pool_allocator
<df_insn_info
> *insn_pool
;
164 pool_allocator
<df_reg_info
> *reg_pool
;
165 pool_allocator
<df_mw_hardreg
> *mw_reg_pool
;
167 bitmap_obstack reg_bitmaps
;
168 bitmap_obstack insn_bitmaps
;
171 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
174 /* Internal function to shut down the scanning problem. */
176 df_scan_free_internal (void)
178 struct df_scan_problem_data
*problem_data
179 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
181 free (df
->def_info
.refs
);
182 free (df
->def_info
.begin
);
183 free (df
->def_info
.count
);
184 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
186 free (df
->use_info
.refs
);
187 free (df
->use_info
.begin
);
188 free (df
->use_info
.count
);
189 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
195 free (df
->eq_use_regs
);
196 df
->eq_use_regs
= NULL
;
198 DF_REG_SIZE (df
) = 0;
204 free (df_scan
->block_info
);
205 df_scan
->block_info
= NULL
;
206 df_scan
->block_info_size
= 0;
208 bitmap_clear (&df
->hardware_regs_used
);
209 bitmap_clear (&df
->regular_block_artificial_uses
);
210 bitmap_clear (&df
->eh_block_artificial_uses
);
211 BITMAP_FREE (df
->entry_block_defs
);
212 BITMAP_FREE (df
->exit_block_uses
);
213 bitmap_clear (&df
->insns_to_delete
);
214 bitmap_clear (&df
->insns_to_rescan
);
215 bitmap_clear (&df
->insns_to_notes_rescan
);
217 delete problem_data
->ref_base_pool
;
218 delete problem_data
->ref_artificial_pool
;
219 delete problem_data
->ref_regular_pool
;
220 delete problem_data
->insn_pool
;
221 delete problem_data
->reg_pool
;
222 delete problem_data
->mw_reg_pool
;
223 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
224 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
225 free (df_scan
->problem_data
);
229 /* Free basic block info. */
232 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
234 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
235 unsigned int bb_index
= bb
->index
;
238 FOR_BB_INSNS (bb
, insn
)
240 df_insn_info_delete (INSN_UID (insn
));
242 if (bb_index
< df_scan
->block_info_size
)
243 bb_info
= df_scan_get_bb_info (bb_index
);
245 /* Get rid of any artificial uses or defs. */
246 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
247 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
248 df_ref_chain_delete (bb_info
->artificial_defs
);
249 df_ref_chain_delete (bb_info
->artificial_uses
);
250 bb_info
->artificial_defs
= NULL
;
251 bb_info
->artificial_uses
= NULL
;
255 /* Allocate the problem data for the scanning problem. This should be
256 called when the problem is created or when the entire function is to
259 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
261 struct df_scan_problem_data
*problem_data
;
262 unsigned int insn_num
= get_max_uid () + 1;
265 /* Given the number of pools, this is really faster than tearing
267 if (df_scan
->problem_data
)
268 df_scan_free_internal ();
270 problem_data
= XNEW (struct df_scan_problem_data
);
271 df_scan
->problem_data
= problem_data
;
272 df_scan
->computed
= true;
274 problem_data
->ref_base_pool
= new pool_allocator
<df_base_ref
>
275 ("df_scan ref base", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
276 problem_data
->ref_artificial_pool
= new pool_allocator
<df_artificial_ref
>
277 ("df_scan ref artificial", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
278 problem_data
->ref_regular_pool
= new pool_allocator
<df_regular_ref
>
279 ("df_scan ref regular", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
280 problem_data
->insn_pool
= new pool_allocator
<df_insn_info
>
281 ("df_scan insn", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
282 problem_data
->reg_pool
= new pool_allocator
<df_reg_info
>
283 ("df_scan reg", SCAN_PROBLEM_DATA_BLOCK_SIZE
);
284 problem_data
->mw_reg_pool
= new pool_allocator
<df_mw_hardreg
>
285 ("df_scan mw_reg", SCAN_PROBLEM_DATA_BLOCK_SIZE
/ 16);
287 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
288 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
290 insn_num
+= insn_num
/ 4;
293 df_grow_insn_info ();
294 df_grow_bb_info (df_scan
);
296 FOR_ALL_BB_FN (bb
, cfun
)
298 unsigned int bb_index
= bb
->index
;
299 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
300 bb_info
->artificial_defs
= NULL
;
301 bb_info
->artificial_uses
= NULL
;
304 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
305 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
306 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
307 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
308 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
309 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
310 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
311 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
312 df_scan
->optional_p
= false;
316 /* Free all of the data associated with the scan problem. */
321 if (df_scan
->problem_data
)
322 df_scan_free_internal ();
324 if (df
->blocks_to_analyze
)
326 BITMAP_FREE (df
->blocks_to_analyze
);
327 df
->blocks_to_analyze
= NULL
;
333 /* Dump the preamble for DF_SCAN dump. */
335 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
346 fprintf (file
, ";; invalidated by call \t");
347 df_print_regset (file
, regs_invalidated_by_call_regset
);
348 fprintf (file
, ";; hardware regs used \t");
349 df_print_regset (file
, &df
->hardware_regs_used
);
350 fprintf (file
, ";; regular block artificial uses \t");
351 df_print_regset (file
, &df
->regular_block_artificial_uses
);
352 fprintf (file
, ";; eh block artificial uses \t");
353 df_print_regset (file
, &df
->eh_block_artificial_uses
);
354 fprintf (file
, ";; entry block defs \t");
355 df_print_regset (file
, df
->entry_block_defs
);
356 fprintf (file
, ";; exit block uses \t");
357 df_print_regset (file
, df
->exit_block_uses
);
358 fprintf (file
, ";; regs ever live \t");
359 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
360 if (df_regs_ever_live_p (i
))
361 fprintf (file
, " %d [%s]", i
, reg_names
[i
]);
362 fprintf (file
, "\n;; ref usage \t");
364 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
365 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
367 const char * sep
= "";
369 fprintf (file
, "r%d={", i
);
370 if (DF_REG_DEF_COUNT (i
))
372 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
374 dcount
+= DF_REG_DEF_COUNT (i
);
376 if (DF_REG_USE_COUNT (i
))
378 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
380 ucount
+= DF_REG_USE_COUNT (i
);
382 if (DF_REG_EQ_USE_COUNT (i
))
384 fprintf (file
, "%s%de", sep
, DF_REG_EQ_USE_COUNT (i
));
385 ecount
+= DF_REG_EQ_USE_COUNT (i
);
387 fprintf (file
, "} ");
390 FOR_EACH_BB_FN (bb
, cfun
)
391 FOR_BB_INSNS (bb
, insn
)
400 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de}"
401 " in %d{%d regular + %d call} insns.\n",
402 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
,
403 icount
+ ccount
, icount
, ccount
);
406 /* Dump the bb_info for a given basic block. */
408 df_scan_start_block (basic_block bb
, FILE *file
)
410 struct df_scan_bb_info
*bb_info
411 = df_scan_get_bb_info (bb
->index
);
415 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
416 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
417 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
418 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
419 fprintf (file
, "\n");
424 FOR_BB_INSNS (bb
, insn
)
426 df_insn_debug (insn
, false, file
);
431 static struct df_problem problem_SCAN
=
433 DF_SCAN
, /* Problem id. */
434 DF_NONE
, /* Direction. */
435 df_scan_alloc
, /* Allocate the problem specific data. */
436 NULL
, /* Reset global information. */
437 df_scan_free_bb_info
, /* Free basic block info. */
438 NULL
, /* Local compute function. */
439 NULL
, /* Init the solution specific data. */
440 NULL
, /* Iterative solver. */
441 NULL
, /* Confluence operator 0. */
442 NULL
, /* Confluence operator n. */
443 NULL
, /* Transfer function. */
444 NULL
, /* Finalize function. */
445 df_scan_free
, /* Free all of the problem information. */
446 NULL
, /* Remove this problem from the stack of dataflow problems. */
447 df_scan_start_dump
, /* Debugging. */
448 df_scan_start_block
, /* Debugging start block. */
449 NULL
, /* Debugging end block. */
450 NULL
, /* Debugging start insn. */
451 NULL
, /* Debugging end insn. */
452 NULL
, /* Incremental solution verify start. */
453 NULL
, /* Incremental solution verify end. */
454 NULL
, /* Dependent problem. */
455 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
456 TV_DF_SCAN
, /* Timing variable. */
457 false /* Reset blocks on dropping out of blocks_to_analyze. */
461 /* Create a new DATAFLOW instance and add it to an existing instance
462 of DF. The returned structure is what is used to get at the
466 df_scan_add_problem (void)
468 df_add_problem (&problem_SCAN
);
472 /*----------------------------------------------------------------------------
473 Storage Allocation Utilities
474 ----------------------------------------------------------------------------*/
477 /* First, grow the reg_info information. If the current size is less than
478 the number of pseudos, grow to 25% more than the number of
481 Second, assure that all of the slots up to max_reg_num have been
482 filled with reg_info structures. */
485 df_grow_reg_info (void)
487 unsigned int max_reg
= max_reg_num ();
488 unsigned int new_size
= max_reg
;
489 struct df_scan_problem_data
*problem_data
490 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
493 if (df
->regs_size
< new_size
)
495 new_size
+= new_size
/ 4;
496 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
497 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
498 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
500 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
501 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
502 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
503 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
504 df
->regs_size
= new_size
;
507 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
509 struct df_reg_info
*reg_info
;
512 reg_info
= problem_data
->reg_pool
->allocate ();
513 memset (reg_info
, 0, sizeof (struct df_reg_info
));
514 df
->def_regs
[i
] = reg_info
;
515 reg_info
= problem_data
->reg_pool
->allocate ();
516 memset (reg_info
, 0, sizeof (struct df_reg_info
));
517 df
->use_regs
[i
] = reg_info
;
518 reg_info
= problem_data
->reg_pool
->allocate ();
519 memset (reg_info
, 0, sizeof (struct df_reg_info
));
520 df
->eq_use_regs
[i
] = reg_info
;
521 df
->def_info
.begin
[i
] = 0;
522 df
->def_info
.count
[i
] = 0;
523 df
->use_info
.begin
[i
] = 0;
524 df
->use_info
.count
[i
] = 0;
527 df
->regs_inited
= max_reg
;
531 /* Grow the ref information. */
534 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
536 if (ref_info
->refs_size
< new_size
)
538 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
539 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
540 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
541 ref_info
->refs_size
= new_size
;
546 /* Check and grow the ref information if necessary. This routine
547 guarantees total_size + BITMAP_ADDEND amount of entries in refs
548 array. It updates ref_info->refs_size only and does not change
549 ref_info->total_size. */
552 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
553 unsigned bitmap_addend
)
555 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
557 int new_size
= ref_info
->total_size
+ bitmap_addend
;
558 new_size
+= ref_info
->total_size
/ 4;
559 df_grow_ref_info (ref_info
, new_size
);
564 /* Grow the ref information. If the current size is less than the
565 number of instructions, grow to 25% more than the number of
569 df_grow_insn_info (void)
571 unsigned int new_size
= get_max_uid () + 1;
572 if (DF_INSN_SIZE () < new_size
)
574 new_size
+= new_size
/ 4;
575 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
576 memset (df
->insns
+ df
->insns_size
, 0,
577 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
578 DF_INSN_SIZE () = new_size
;
585 /*----------------------------------------------------------------------------
586 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
587 ----------------------------------------------------------------------------*/
589 /* Rescan all of the block_to_analyze or all of the blocks in the
590 function if df_set_blocks if blocks_to_analyze is NULL; */
593 df_scan_blocks (void)
597 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
598 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
600 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
601 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
603 bitmap_ior_into (&df
->eh_block_artificial_uses
,
604 &df
->regular_block_artificial_uses
);
606 /* ENTRY and EXIT blocks have special defs/uses. */
607 df_get_entry_block_def_set (df
->entry_block_defs
);
608 df_record_entry_block_defs (df
->entry_block_defs
);
609 df_get_exit_block_use_set (df
->exit_block_uses
);
610 df_record_exit_block_uses (df
->exit_block_uses
);
611 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
612 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
615 FOR_EACH_BB_FN (bb
, cfun
)
617 unsigned int bb_index
= bb
->index
;
618 df_bb_refs_record (bb_index
, true);
622 /* Create new refs under address LOC within INSN. This function is
623 only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
624 depending on whether LOC is inside PATTERN (INSN) or a note. */
627 df_uses_create (rtx
*loc
, rtx_insn
*insn
, int ref_flags
)
629 gcc_assert (!(ref_flags
& ~DF_REF_IN_NOTE
));
630 df_uses_record (NULL
, loc
, DF_REF_REG_USE
,
631 BLOCK_FOR_INSN (insn
),
632 DF_INSN_INFO_GET (insn
),
637 df_install_ref_incremental (df_ref ref
)
639 struct df_reg_info
**reg_info
;
640 struct df_ref_info
*ref_info
;
644 rtx_insn
*insn
= DF_REF_INSN (ref
);
645 basic_block bb
= BLOCK_FOR_INSN (insn
);
647 if (DF_REF_REG_DEF_P (ref
))
649 reg_info
= df
->def_regs
;
650 ref_info
= &df
->def_info
;
651 ref_ptr
= &DF_INSN_DEFS (insn
);
652 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
654 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
656 reg_info
= df
->eq_use_regs
;
657 ref_info
= &df
->use_info
;
658 ref_ptr
= &DF_INSN_EQ_USES (insn
);
659 switch (ref_info
->ref_order
)
661 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
662 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
663 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
667 add_to_table
= false;
673 reg_info
= df
->use_regs
;
674 ref_info
= &df
->use_info
;
675 ref_ptr
= &DF_INSN_USES (insn
);
676 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
679 /* Do not add if ref is not in the right blocks. */
680 if (add_to_table
&& df
->analyze_subset
)
681 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
683 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
686 switch (ref_info
->ref_order
)
688 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
689 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
690 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
691 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
694 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
698 while (*ref_ptr
&& df_ref_compare (*ref_ptr
, ref
) < 0)
699 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
701 DF_REF_NEXT_LOC (ref
) = *ref_ptr
;
707 fprintf (dump_file
, "adding ref ");
708 df_ref_debug (ref
, dump_file
);
711 /* By adding the ref directly, df_insn_rescan my not find any
712 differences even though the block will have changed. So we need
713 to mark the block dirty ourselves. */
714 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
715 df_set_bb_dirty (bb
);
720 /*----------------------------------------------------------------------------
721 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
722 ----------------------------------------------------------------------------*/
725 df_free_ref (df_ref ref
)
727 struct df_scan_problem_data
*problem_data
728 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
730 switch (DF_REF_CLASS (ref
))
733 problem_data
->ref_base_pool
->remove ((df_base_ref
*) (ref
));
736 case DF_REF_ARTIFICIAL
:
737 problem_data
->ref_artificial_pool
->remove
738 ((df_artificial_ref
*) (ref
));
742 problem_data
->ref_regular_pool
->remove
743 ((df_regular_ref
*) (ref
));
749 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
750 Also delete the def-use or use-def chain if it exists. */
753 df_reg_chain_unlink (df_ref ref
)
755 df_ref next
= DF_REF_NEXT_REG (ref
);
756 df_ref prev
= DF_REF_PREV_REG (ref
);
757 int id
= DF_REF_ID (ref
);
758 struct df_reg_info
*reg_info
;
761 if (DF_REF_REG_DEF_P (ref
))
763 int regno
= DF_REF_REGNO (ref
);
764 reg_info
= DF_REG_DEF_GET (regno
);
765 refs
= df
->def_info
.refs
;
769 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
771 reg_info
= DF_REG_EQ_USE_GET (DF_REF_REGNO (ref
));
772 switch (df
->use_info
.ref_order
)
774 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
775 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
776 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
777 refs
= df
->use_info
.refs
;
785 reg_info
= DF_REG_USE_GET (DF_REF_REGNO (ref
));
786 refs
= df
->use_info
.refs
;
792 if (df
->analyze_subset
)
794 if (bitmap_bit_p (df
->blocks_to_analyze
, DF_REF_BBNO (ref
)))
801 /* Delete any def-use or use-def chains that start here. It is
802 possible that there is trash in this field. This happens for
803 insns that have been deleted when rescanning has been deferred
804 and the chain problem has also been deleted. The chain tear down
805 code skips deleted insns. */
806 if (df_chain
&& DF_REF_CHAIN (ref
))
807 df_chain_unlink (ref
);
810 if (DF_REF_FLAGS_IS_SET (ref
, DF_HARD_REG_LIVE
))
812 gcc_assert (DF_REF_REGNO (ref
) < FIRST_PSEUDO_REGISTER
);
813 df
->hard_regs_live_count
[DF_REF_REGNO (ref
)]--;
816 /* Unlink from the reg chain. If there is no prev, this is the
817 first of the list. If not, just join the next and prev. */
819 DF_REF_NEXT_REG (prev
) = next
;
822 gcc_assert (reg_info
->reg_chain
== ref
);
823 reg_info
->reg_chain
= next
;
826 DF_REF_PREV_REG (next
) = prev
;
832 /* Create the insn record for INSN. If there was one there, zero it
835 struct df_insn_info
*
836 df_insn_create_insn_record (rtx_insn
*insn
)
838 struct df_scan_problem_data
*problem_data
839 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
840 struct df_insn_info
*insn_rec
;
842 df_grow_insn_info ();
843 insn_rec
= DF_INSN_INFO_GET (insn
);
846 insn_rec
= problem_data
->insn_pool
->allocate ();
847 DF_INSN_INFO_SET (insn
, insn_rec
);
849 memset (insn_rec
, 0, sizeof (struct df_insn_info
));
850 insn_rec
->insn
= insn
;
855 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
858 df_ref_chain_delete_du_chain (df_ref ref
)
860 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
861 /* CHAIN is allocated by DF_CHAIN. So make sure to
862 pass df_scan instance for the problem. */
863 if (DF_REF_CHAIN (ref
))
864 df_chain_unlink (ref
);
868 /* Delete all refs in the ref chain. */
871 df_ref_chain_delete (df_ref ref
)
874 for (; ref
; ref
= next
)
876 next
= DF_REF_NEXT_LOC (ref
);
877 df_reg_chain_unlink (ref
);
882 /* Delete the hardreg chain. */
885 df_mw_hardreg_chain_delete (struct df_mw_hardreg
*hardregs
)
887 struct df_scan_problem_data
*problem_data
888 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
891 for (; hardregs
; hardregs
= next
)
893 next
= DF_MWS_NEXT (hardregs
);
894 problem_data
->mw_reg_pool
->remove (hardregs
);
899 /* Delete all of the refs information from the insn with UID.
900 Internal helper for df_insn_delete, df_insn_rescan, and other
901 df-scan routines that don't have to work in deferred mode
902 and do not have to mark basic blocks for re-processing. */
905 df_insn_info_delete (unsigned int uid
)
907 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
909 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
910 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
911 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
914 struct df_scan_problem_data
*problem_data
915 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
917 /* In general, notes do not have the insn_info fields
918 initialized. However, combine deletes insns by changing them
919 to notes. How clever. So we cannot just check if it is a
920 valid insn before short circuiting this code, we need to see
921 if we actually initialized it. */
922 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
926 df_ref_chain_delete_du_chain (insn_info
->defs
);
927 df_ref_chain_delete_du_chain (insn_info
->uses
);
928 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
931 df_ref_chain_delete (insn_info
->defs
);
932 df_ref_chain_delete (insn_info
->uses
);
933 df_ref_chain_delete (insn_info
->eq_uses
);
935 problem_data
->insn_pool
->remove (insn_info
);
936 DF_INSN_UID_SET (uid
, NULL
);
940 /* Delete all of the refs information from INSN, either right now
941 or marked for later in deferred mode. */
944 df_insn_delete (rtx_insn
*insn
)
949 gcc_checking_assert (INSN_P (insn
));
954 uid
= INSN_UID (insn
);
955 bb
= BLOCK_FOR_INSN (insn
);
957 /* ??? bb can be NULL after pass_free_cfg. At that point, DF should
958 not exist anymore (as mentioned in df-core.c: "The only requirement
959 [for DF] is that there be a correct control flow graph." Clearly
960 that isn't the case after pass_free_cfg. But DF is freed much later
961 because some back-ends want to use DF info even though the CFG is
962 already gone. It's not clear to me whether that is safe, actually.
963 In any case, we expect BB to be non-NULL at least up to register
964 allocation, so disallow a non-NULL BB up to there. Not perfect
965 but better than nothing... */
966 gcc_checking_assert (bb
!= NULL
|| reload_completed
);
968 df_grow_bb_info (df_scan
);
971 /* The block must be marked as dirty now, rather than later as in
972 df_insn_rescan and df_notes_rescan because it may not be there at
973 rescanning time and the mark would blow up.
974 DEBUG_INSNs do not make a block's data flow solution dirty (at
975 worst the LUIDs are no longer contiguous). */
976 if (bb
!= NULL
&& NONDEBUG_INSN_P (insn
))
977 df_set_bb_dirty (bb
);
979 /* The client has deferred rescanning. */
980 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
982 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
985 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
986 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
987 bitmap_set_bit (&df
->insns_to_delete
, uid
);
990 fprintf (dump_file
, "deferring deletion of insn with uid = %d.\n", uid
);
995 fprintf (dump_file
, "deleting insn with uid = %d.\n", uid
);
997 df_insn_info_delete (uid
);
1001 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1004 df_free_collection_rec (struct df_collection_rec
*collection_rec
)
1007 struct df_scan_problem_data
*problem_data
1008 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1010 struct df_mw_hardreg
*mw
;
1012 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
1014 FOR_EACH_VEC_ELT (collection_rec
->use_vec
, ix
, ref
)
1016 FOR_EACH_VEC_ELT (collection_rec
->eq_use_vec
, ix
, ref
)
1018 FOR_EACH_VEC_ELT (collection_rec
->mw_vec
, ix
, mw
)
1019 problem_data
->mw_reg_pool
->remove (mw
);
1021 collection_rec
->def_vec
.release ();
1022 collection_rec
->use_vec
.release ();
1023 collection_rec
->eq_use_vec
.release ();
1024 collection_rec
->mw_vec
.release ();
1027 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1030 df_insn_rescan (rtx_insn
*insn
)
1032 unsigned int uid
= INSN_UID (insn
);
1033 struct df_insn_info
*insn_info
= NULL
;
1034 basic_block bb
= BLOCK_FOR_INSN (insn
);
1035 struct df_collection_rec collection_rec
;
1037 if ((!df
) || (!INSN_P (insn
)))
1043 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1047 /* The client has disabled rescanning and plans to do it itself. */
1048 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1051 df_grow_bb_info (df_scan
);
1052 df_grow_reg_info ();
1054 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1056 /* The client has deferred rescanning. */
1057 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1061 insn_info
= df_insn_create_insn_record (insn
);
1062 insn_info
->defs
= 0;
1063 insn_info
->uses
= 0;
1064 insn_info
->eq_uses
= 0;
1065 insn_info
->mw_hardregs
= 0;
1068 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1070 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1071 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1072 bitmap_set_bit (&df
->insns_to_rescan
, INSN_UID (insn
));
1076 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1077 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1078 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1082 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1083 /* If there's no change, return false. */
1086 df_free_collection_rec (&collection_rec
);
1088 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1092 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1094 /* There's change - we need to delete the existing info.
1095 Since the insn isn't moved, we can salvage its LUID. */
1096 luid
= DF_INSN_LUID (insn
);
1097 df_insn_info_delete (uid
);
1098 df_insn_create_insn_record (insn
);
1099 DF_INSN_LUID (insn
) = luid
;
1103 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1104 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1106 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1109 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
1110 if (!DEBUG_INSN_P (insn
))
1111 df_set_bb_dirty (bb
);
1116 /* Same as df_insn_rescan, but don't mark the basic block as
1120 df_insn_rescan_debug_internal (rtx_insn
*insn
)
1122 unsigned int uid
= INSN_UID (insn
);
1123 struct df_insn_info
*insn_info
;
1125 gcc_assert (DEBUG_INSN_P (insn
)
1126 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn
)));
1131 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1136 fprintf (dump_file
, "deleting debug_insn with uid = %d.\n", uid
);
1138 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1139 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1140 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1142 if (insn_info
->defs
== 0
1143 && insn_info
->uses
== 0
1144 && insn_info
->eq_uses
== 0
1145 && insn_info
->mw_hardregs
== 0)
1148 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1152 df_ref_chain_delete_du_chain (insn_info
->defs
);
1153 df_ref_chain_delete_du_chain (insn_info
->uses
);
1154 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1157 df_ref_chain_delete (insn_info
->defs
);
1158 df_ref_chain_delete (insn_info
->uses
);
1159 df_ref_chain_delete (insn_info
->eq_uses
);
1161 insn_info
->defs
= 0;
1162 insn_info
->uses
= 0;
1163 insn_info
->eq_uses
= 0;
1164 insn_info
->mw_hardregs
= 0;
1170 /* Rescan all of the insns in the function. Note that the artificial
1171 uses and defs are not touched. This function will destroy def-use
1172 or use-def chains. */
1175 df_insn_rescan_all (void)
1177 bool no_insn_rescan
= false;
1178 bool defer_insn_rescan
= false;
1184 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1186 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1188 df_clear_flags (DF_NO_INSN_RESCAN
);
1189 no_insn_rescan
= true;
1192 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1194 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1195 defer_insn_rescan
= true;
1198 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1199 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1201 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1203 df_insn_info_delete (uid
);
1206 bitmap_clear (&tmp
);
1207 bitmap_clear (&df
->insns_to_delete
);
1208 bitmap_clear (&df
->insns_to_rescan
);
1209 bitmap_clear (&df
->insns_to_notes_rescan
);
1211 FOR_EACH_BB_FN (bb
, cfun
)
1214 FOR_BB_INSNS (bb
, insn
)
1216 df_insn_rescan (insn
);
1221 df_set_flags (DF_NO_INSN_RESCAN
);
1222 if (defer_insn_rescan
)
1223 df_set_flags (DF_DEFER_INSN_RESCAN
);
1227 /* Process all of the deferred rescans or deletions. */
1230 df_process_deferred_rescans (void)
1232 bool no_insn_rescan
= false;
1233 bool defer_insn_rescan
= false;
1238 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1240 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1242 df_clear_flags (DF_NO_INSN_RESCAN
);
1243 no_insn_rescan
= true;
1246 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1248 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1249 defer_insn_rescan
= true;
1253 fprintf (dump_file
, "starting the processing of deferred insns\n");
1255 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1256 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1258 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1260 df_insn_info_delete (uid
);
1263 bitmap_copy (&tmp
, &df
->insns_to_rescan
);
1264 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1266 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1268 df_insn_rescan (insn_info
->insn
);
1271 bitmap_copy (&tmp
, &df
->insns_to_notes_rescan
);
1272 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1274 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1276 df_notes_rescan (insn_info
->insn
);
1280 fprintf (dump_file
, "ending the processing of deferred insns\n");
1282 bitmap_clear (&tmp
);
1283 bitmap_clear (&df
->insns_to_delete
);
1284 bitmap_clear (&df
->insns_to_rescan
);
1285 bitmap_clear (&df
->insns_to_notes_rescan
);
1288 df_set_flags (DF_NO_INSN_RESCAN
);
1289 if (defer_insn_rescan
)
1290 df_set_flags (DF_DEFER_INSN_RESCAN
);
1292 /* If someone changed regs_ever_live during this pass, fix up the
1293 entry and exit blocks. */
1294 if (df
->redo_entry_and_exit
)
1296 df_update_entry_exit_and_calls ();
1297 df
->redo_entry_and_exit
= false;
1302 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1303 the uses if INCLUDE_USES. Include the eq_uses if
1307 df_count_refs (bool include_defs
, bool include_uses
,
1308 bool include_eq_uses
)
1312 unsigned int m
= df
->regs_inited
;
1314 for (regno
= 0; regno
< m
; regno
++)
1317 size
+= DF_REG_DEF_COUNT (regno
);
1319 size
+= DF_REG_USE_COUNT (regno
);
1320 if (include_eq_uses
)
1321 size
+= DF_REG_EQ_USE_COUNT (regno
);
1327 /* Take build ref table for either the uses or defs from the reg-use
1328 or reg-def chains. This version processes the refs in reg order
1329 which is likely to be best if processing the whole function. */
1332 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1335 bool include_eq_uses
)
1337 unsigned int m
= df
->regs_inited
;
1339 unsigned int offset
= 0;
1342 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1344 start
= FIRST_PSEUDO_REGISTER
;
1345 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1346 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1351 ref_info
->total_size
1352 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1354 df_check_and_grow_ref_info (ref_info
, 1);
1356 for (regno
= start
; regno
< m
; regno
++)
1359 ref_info
->begin
[regno
] = offset
;
1362 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1365 ref_info
->refs
[offset
] = ref
;
1366 DF_REF_ID (ref
) = offset
++;
1368 ref
= DF_REF_NEXT_REG (ref
);
1369 gcc_checking_assert (offset
< ref_info
->refs_size
);
1374 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1377 ref_info
->refs
[offset
] = ref
;
1378 DF_REF_ID (ref
) = offset
++;
1380 ref
= DF_REF_NEXT_REG (ref
);
1381 gcc_checking_assert (offset
< ref_info
->refs_size
);
1384 if (include_eq_uses
)
1386 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1389 ref_info
->refs
[offset
] = ref
;
1390 DF_REF_ID (ref
) = offset
++;
1392 ref
= DF_REF_NEXT_REG (ref
);
1393 gcc_checking_assert (offset
< ref_info
->refs_size
);
1396 ref_info
->count
[regno
] = count
;
1399 /* The bitmap size is not decremented when refs are deleted. So
1400 reset it now that we have squished out all of the empty
1402 ref_info
->table_size
= offset
;
1406 /* Take build ref table for either the uses or defs from the reg-use
1407 or reg-def chains. This version processes the refs in insn order
1408 which is likely to be best if processing some segment of the
1412 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1415 bool include_eq_uses
)
1418 unsigned int bb_index
;
1419 unsigned int m
= df
->regs_inited
;
1420 unsigned int offset
= 0;
1423 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1425 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1426 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1428 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1429 df_check_and_grow_ref_info (ref_info
, 1);
1431 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1433 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1438 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1440 unsigned int regno
= DF_REF_REGNO (def
);
1441 ref_info
->count
[regno
]++;
1444 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1446 unsigned int regno
= DF_REF_REGNO (use
);
1447 ref_info
->count
[regno
]++;
1450 FOR_BB_INSNS (bb
, insn
)
1454 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1457 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1459 unsigned int regno
= DF_REF_REGNO (def
);
1460 ref_info
->count
[regno
]++;
1463 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1465 unsigned int regno
= DF_REF_REGNO (use
);
1466 ref_info
->count
[regno
]++;
1468 if (include_eq_uses
)
1469 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1471 unsigned int regno
= DF_REF_REGNO (use
);
1472 ref_info
->count
[regno
]++;
1478 for (r
= start
; r
< m
; r
++)
1480 ref_info
->begin
[r
] = offset
;
1481 offset
+= ref_info
->count
[r
];
1482 ref_info
->count
[r
] = 0;
1485 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1487 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1492 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1494 unsigned int regno
= DF_REF_REGNO (def
);
1498 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1499 DF_REF_ID (def
) = id
;
1500 ref_info
->refs
[id
] = def
;
1504 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1506 unsigned int regno
= DF_REF_REGNO (def
);
1510 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1511 DF_REF_ID (use
) = id
;
1512 ref_info
->refs
[id
] = use
;
1516 FOR_BB_INSNS (bb
, insn
)
1520 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1523 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1525 unsigned int regno
= DF_REF_REGNO (def
);
1529 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1530 DF_REF_ID (def
) = id
;
1531 ref_info
->refs
[id
] = def
;
1535 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1537 unsigned int regno
= DF_REF_REGNO (use
);
1541 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1542 DF_REF_ID (use
) = id
;
1543 ref_info
->refs
[id
] = use
;
1546 if (include_eq_uses
)
1547 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1549 unsigned int regno
= DF_REF_REGNO (use
);
1553 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1554 DF_REF_ID (use
) = id
;
1555 ref_info
->refs
[id
] = use
;
1562 /* The bitmap size is not decremented when refs are deleted. So
1563 reset it now that we have squished out all of the empty
1566 ref_info
->table_size
= offset
;
1569 /* Take build ref table for either the uses or defs from the reg-use
1570 or reg-def chains. */
1573 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1576 bool include_eq_uses
)
1578 if (df
->analyze_subset
)
1579 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1580 include_uses
, include_eq_uses
);
1582 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1583 include_uses
, include_eq_uses
);
1587 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1589 df_add_refs_to_table (unsigned int offset
,
1590 struct df_ref_info
*ref_info
,
1593 for (; ref
; ref
= DF_REF_NEXT_LOC (ref
))
1594 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
)
1595 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1597 ref_info
->refs
[offset
] = ref
;
1598 DF_REF_ID (ref
) = offset
++;
1604 /* Count the number of refs in all of the insns of BB. Include the
1605 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1606 eq_uses if INCLUDE_EQ_USES. */
1609 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1610 struct df_ref_info
*ref_info
,
1611 bool include_defs
, bool include_uses
,
1612 bool include_eq_uses
)
1617 offset
= df_add_refs_to_table (offset
, ref_info
,
1618 df_get_artificial_defs (bb
->index
));
1620 offset
= df_add_refs_to_table (offset
, ref_info
,
1621 df_get_artificial_uses (bb
->index
));
1623 FOR_BB_INSNS (bb
, insn
)
1626 unsigned int uid
= INSN_UID (insn
);
1628 offset
= df_add_refs_to_table (offset
, ref_info
,
1629 DF_INSN_UID_DEFS (uid
));
1631 offset
= df_add_refs_to_table (offset
, ref_info
,
1632 DF_INSN_UID_USES (uid
));
1633 if (include_eq_uses
)
1634 offset
= df_add_refs_to_table (offset
, ref_info
,
1635 DF_INSN_UID_EQ_USES (uid
));
1641 /* Organize the refs by insn into the table in REF_INFO. If
1642 blocks_to_analyze is defined, use that set, otherwise the entire
1643 program. Include the defs if INCLUDE_DEFS. Include the uses if
1644 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1647 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1648 bool include_defs
, bool include_uses
,
1649 bool include_eq_uses
)
1652 unsigned int offset
= 0;
1654 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1655 df_check_and_grow_ref_info (ref_info
, 1);
1656 if (df
->blocks_to_analyze
)
1661 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1663 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun
,
1666 include_defs
, include_uses
,
1670 ref_info
->table_size
= offset
;
1674 FOR_ALL_BB_FN (bb
, cfun
)
1675 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1676 include_defs
, include_uses
,
1678 ref_info
->table_size
= offset
;
1683 /* If the use refs in DF are not organized, reorganize them. */
1686 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1688 if (order
== df
->use_info
.ref_order
)
1693 case DF_REF_ORDER_BY_REG
:
1694 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1697 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1698 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1701 case DF_REF_ORDER_BY_INSN
:
1702 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1705 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1706 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1709 case DF_REF_ORDER_NO_TABLE
:
1710 free (df
->use_info
.refs
);
1711 df
->use_info
.refs
= NULL
;
1712 df
->use_info
.refs_size
= 0;
1715 case DF_REF_ORDER_UNORDERED
:
1716 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1721 df
->use_info
.ref_order
= order
;
1725 /* If the def refs in DF are not organized, reorganize them. */
1728 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1730 if (order
== df
->def_info
.ref_order
)
1735 case DF_REF_ORDER_BY_REG
:
1736 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1739 case DF_REF_ORDER_BY_INSN
:
1740 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1743 case DF_REF_ORDER_NO_TABLE
:
1744 free (df
->def_info
.refs
);
1745 df
->def_info
.refs
= NULL
;
1746 df
->def_info
.refs_size
= 0;
1749 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1750 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1751 case DF_REF_ORDER_UNORDERED
:
1752 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1757 df
->def_info
.ref_order
= order
;
1761 /* Change all of the basic block references in INSN to use the insn's
1762 current basic block. This function is called from routines that move
1763 instructions from one block to another. */
1766 df_insn_change_bb (rtx_insn
*insn
, basic_block new_bb
)
1768 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1769 struct df_insn_info
*insn_info
;
1770 unsigned int uid
= INSN_UID (insn
);
1772 if (old_bb
== new_bb
)
1775 set_block_for_insn (insn
, new_bb
);
1781 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1783 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1784 if (insn_info
== NULL
)
1787 fprintf (dump_file
, " unscanned insn\n");
1788 df_insn_rescan (insn
);
1795 df_set_bb_dirty (new_bb
);
1799 fprintf (dump_file
, " from %d to %d\n",
1800 old_bb
->index
, new_bb
->index
);
1801 df_set_bb_dirty (old_bb
);
1805 fprintf (dump_file
, " to %d\n", new_bb
->index
);
1809 /* Helper function for df_ref_change_reg_with_loc. */
1812 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
1813 struct df_reg_info
*new_df
,
1814 unsigned int new_regno
, rtx loc
)
1816 df_ref the_ref
= old_df
->reg_chain
;
1820 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
1821 && DF_REF_LOC (the_ref
)
1822 && (*DF_REF_LOC (the_ref
) == loc
))
1824 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
1825 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
1827 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
1829 DF_REF_REGNO (the_ref
) = new_regno
;
1830 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
1832 /* Pull the_ref out of the old regno chain. */
1834 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
1836 old_df
->reg_chain
= next_ref
;
1838 DF_REF_PREV_REG (next_ref
) = prev_ref
;
1841 /* Put the ref into the new regno chain. */
1842 DF_REF_PREV_REG (the_ref
) = NULL
;
1843 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
1844 if (new_df
->reg_chain
)
1845 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
1846 new_df
->reg_chain
= the_ref
;
1848 if (DF_REF_BB (the_ref
))
1849 df_set_bb_dirty (DF_REF_BB (the_ref
));
1851 /* Need to sort the record again that the ref was in because
1852 the regno is a sorting key. First, find the right
1854 if (DF_REF_REG_DEF_P (the_ref
))
1855 ref_ptr
= &insn_info
->defs
;
1856 else if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
1857 ref_ptr
= &insn_info
->eq_uses
;
1859 ref_ptr
= &insn_info
->uses
;
1861 fprintf (dump_file
, "changing reg in insn %d\n",
1862 DF_REF_INSN_UID (the_ref
));
1864 /* Stop if we find the current reference or where the reference
1866 while (*ref_ptr
!= the_ref
&& df_ref_compare (*ref_ptr
, the_ref
) < 0)
1867 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1868 if (*ref_ptr
!= the_ref
)
1870 /* The reference needs to be promoted up the list. */
1871 df_ref next
= DF_REF_NEXT_LOC (the_ref
);
1872 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1875 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1876 while (*ref_ptr
!= the_ref
);
1879 else if (DF_REF_NEXT_LOC (the_ref
)
1880 && df_ref_compare (the_ref
, DF_REF_NEXT_LOC (the_ref
)) > 0)
1882 /* The reference needs to be demoted down the list. */
1883 *ref_ptr
= DF_REF_NEXT_LOC (the_ref
);
1885 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
1886 while (*ref_ptr
&& df_ref_compare (the_ref
, *ref_ptr
) > 0);
1887 DF_REF_NEXT_LOC (the_ref
) = *ref_ptr
;
1894 the_ref
= DF_REF_NEXT_REG (the_ref
);
1899 /* Change the regno of register LOC to NEW_REGNO and update the df
1900 information accordingly. Refs that do not match LOC are not changed
1901 which means that artificial refs are not changed since they have no loc.
1902 This call is to support the SET_REGNO macro. */
1905 df_ref_change_reg_with_loc (rtx loc
, unsigned int new_regno
)
1907 unsigned int old_regno
= REGNO (loc
);
1908 if (old_regno
== new_regno
)
1913 df_grow_reg_info ();
1915 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
1916 DF_REG_DEF_GET (new_regno
),
1918 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
1919 DF_REG_USE_GET (new_regno
),
1921 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
1922 DF_REG_EQ_USE_GET (new_regno
),
1925 set_mode_and_regno (loc
, GET_MODE (loc
), new_regno
);
1929 /* Delete the mw_hardregs that point into the eq_notes. */
1932 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
1934 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
;
1935 struct df_scan_problem_data
*problem_data
1936 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1940 df_mw_hardreg
*mw
= *mw_ptr
;
1941 if (mw
->flags
& DF_REF_IN_NOTE
)
1943 *mw_ptr
= DF_MWS_NEXT (mw
);
1944 problem_data
->mw_reg_pool
->remove (mw
);
1947 mw_ptr
= &DF_MWS_NEXT (mw
);
1952 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
1955 df_notes_rescan (rtx_insn
*insn
)
1957 struct df_insn_info
*insn_info
;
1958 unsigned int uid
= INSN_UID (insn
);
1963 /* The client has disabled rescanning and plans to do it itself. */
1964 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1967 /* Do nothing if the insn hasn't been emitted yet. */
1968 if (!BLOCK_FOR_INSN (insn
))
1971 df_grow_bb_info (df_scan
);
1972 df_grow_reg_info ();
1974 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1976 /* The client has deferred rescanning. */
1977 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1981 insn_info
= df_insn_create_insn_record (insn
);
1982 insn_info
->defs
= 0;
1983 insn_info
->uses
= 0;
1984 insn_info
->eq_uses
= 0;
1985 insn_info
->mw_hardregs
= 0;
1988 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1989 /* If the insn is set to be rescanned, it does not need to also
1990 be notes rescanned. */
1991 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
1992 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
1996 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1997 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
2001 basic_block bb
= BLOCK_FOR_INSN (insn
);
2003 struct df_collection_rec collection_rec
;
2006 df_mw_hardreg_chain_delete_eq_uses (insn_info
);
2007 df_ref_chain_delete (insn_info
->eq_uses
);
2008 insn_info
->eq_uses
= NULL
;
2010 /* Process REG_EQUIV/REG_EQUAL notes */
2011 for (note
= REG_NOTES (insn
); note
;
2012 note
= XEXP (note
, 1))
2014 switch (REG_NOTE_KIND (note
))
2018 df_uses_record (&collection_rec
,
2019 &XEXP (note
, 0), DF_REF_REG_USE
,
2020 bb
, insn_info
, DF_REF_IN_NOTE
);
2026 /* Find some place to put any new mw_hardregs. */
2027 df_canonize_collection_rec (&collection_rec
);
2028 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
, *mw
;
2029 FOR_EACH_VEC_ELT (collection_rec
.mw_vec
, i
, mw
)
2031 while (*mw_ptr
&& df_mw_compare (*mw_ptr
, mw
) < 0)
2032 mw_ptr
= &DF_MWS_NEXT (*mw_ptr
);
2033 DF_MWS_NEXT (mw
) = *mw_ptr
;
2035 mw_ptr
= &DF_MWS_NEXT (mw
);
2037 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_eq_uses
);
2040 df_insn_rescan (insn
);
2045 /*----------------------------------------------------------------------------
2046 Hard core instruction scanning code. No external interfaces here,
2047 just a lot of routines that look inside insns.
2048 ----------------------------------------------------------------------------*/
2051 /* Return true if the contents of two df_ref's are identical.
2052 It ignores DF_REF_MARKER. */
2055 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2063 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2064 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2065 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2066 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2067 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2068 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2069 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2070 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2073 switch (DF_REF_CLASS (ref1
))
2075 case DF_REF_ARTIFICIAL
:
2079 case DF_REF_REGULAR
:
2080 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2089 /* Compare REF1 and REF2 for sorting. This is only called from places
2090 where all of the refs are of the same type, in the same insn, and
2091 have the same bb. So these fields are not checked. */
2094 df_ref_compare (df_ref ref1
, df_ref ref2
)
2096 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2097 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2099 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2100 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2102 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2103 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2105 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2106 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2108 /* Cannot look at the LOC field on artificial refs. */
2109 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2110 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2111 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2113 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2115 /* If two refs are identical except that one of them has is from
2116 a mw and one is not, we need to have the one with the mw
2118 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2119 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2120 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2121 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2127 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2130 /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2. */
2133 df_ref_ptr_compare (const void *r1
, const void *r2
)
2135 return df_ref_compare (*(const df_ref
*) r1
, *(const df_ref
*) r2
);
2139 df_swap_refs (vec
<df_ref
, va_heap
> *ref_vec
, int i
, int j
)
2141 df_ref tmp
= (*ref_vec
)[i
];
2142 (*ref_vec
)[i
] = (*ref_vec
)[j
];
2143 (*ref_vec
)[j
] = tmp
;
2146 /* Sort and compress a set of refs. */
2149 df_sort_and_compress_refs (vec
<df_ref
, va_heap
> *ref_vec
)
2153 unsigned int dist
= 0;
2155 count
= ref_vec
->length ();
2157 /* If there are 1 or 0 elements, there is nothing to do. */
2160 else if (count
== 2)
2162 df_ref r0
= (*ref_vec
)[0];
2163 df_ref r1
= (*ref_vec
)[1];
2164 if (df_ref_compare (r0
, r1
) > 0)
2165 df_swap_refs (ref_vec
, 0, 1);
2169 for (i
= 0; i
< count
- 1; i
++)
2171 df_ref r0
= (*ref_vec
)[i
];
2172 df_ref r1
= (*ref_vec
)[i
+ 1];
2173 if (df_ref_compare (r0
, r1
) >= 0)
2176 /* If the array is already strictly ordered,
2177 which is the most common case for large COUNT case
2178 (which happens for CALL INSNs),
2179 no need to sort and filter out duplicate.
2180 Simply return the count.
2181 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2182 of DF_REF_COMPARE. */
2185 ref_vec
->qsort (df_ref_ptr_compare
);
2188 for (i
=0; i
<count
-dist
; i
++)
2190 /* Find the next ref that is not equal to the current ref. */
2191 while (i
+ dist
+ 1 < count
2192 && df_ref_equal_p ((*ref_vec
)[i
],
2193 (*ref_vec
)[i
+ dist
+ 1]))
2195 df_free_ref ((*ref_vec
)[i
+ dist
+ 1]);
2198 /* Copy it down to the next position. */
2199 if (dist
&& i
+ dist
+ 1 < count
)
2200 (*ref_vec
)[i
+ 1] = (*ref_vec
)[i
+ dist
+ 1];
2204 ref_vec
->truncate (count
);
2208 /* Return true if the contents of two df_ref's are identical.
2209 It ignores DF_REF_MARKER. */
2212 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2216 return (mw1
== mw2
) ||
2217 (mw1
->mw_reg
== mw2
->mw_reg
2218 && mw1
->type
== mw2
->type
2219 && mw1
->flags
== mw2
->flags
2220 && mw1
->start_regno
== mw2
->start_regno
2221 && mw1
->end_regno
== mw2
->end_regno
);
2225 /* Compare MW1 and MW2 for sorting. */
2228 df_mw_compare (const df_mw_hardreg
*mw1
, const df_mw_hardreg
*mw2
)
2230 if (mw1
->type
!= mw2
->type
)
2231 return mw1
->type
- mw2
->type
;
2233 if (mw1
->flags
!= mw2
->flags
)
2234 return mw1
->flags
- mw2
->flags
;
2236 if (mw1
->start_regno
!= mw2
->start_regno
)
2237 return mw1
->start_regno
- mw2
->start_regno
;
2239 if (mw1
->end_regno
!= mw2
->end_regno
)
2240 return mw1
->end_regno
- mw2
->end_regno
;
2242 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2243 return mw1
->mw_order
- mw2
->mw_order
;
2248 /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2. */
2251 df_mw_ptr_compare (const void *m1
, const void *m2
)
2253 return df_mw_compare (*(const df_mw_hardreg
*const *) m1
,
2254 *(const df_mw_hardreg
*const *) m2
);
2257 /* Sort and compress a set of refs. */
2260 df_sort_and_compress_mws (vec
<df_mw_hardreg_ptr
, va_heap
> *mw_vec
)
2263 struct df_scan_problem_data
*problem_data
2264 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2266 unsigned int dist
= 0;
2268 count
= mw_vec
->length ();
2271 else if (count
== 2)
2273 struct df_mw_hardreg
*m0
= (*mw_vec
)[0];
2274 struct df_mw_hardreg
*m1
= (*mw_vec
)[1];
2275 if (df_mw_compare (m0
, m1
) > 0)
2277 struct df_mw_hardreg
*tmp
= (*mw_vec
)[0];
2278 (*mw_vec
)[0] = (*mw_vec
)[1];
2283 mw_vec
->qsort (df_mw_ptr_compare
);
2285 for (i
=0; i
<count
-dist
; i
++)
2287 /* Find the next ref that is not equal to the current ref. */
2288 while (i
+ dist
+ 1 < count
2289 && df_mw_equal_p ((*mw_vec
)[i
], (*mw_vec
)[i
+ dist
+ 1]))
2291 problem_data
->mw_reg_pool
->remove ((*mw_vec
)[i
+ dist
+ 1]);
2294 /* Copy it down to the next position. */
2295 if (dist
&& i
+ dist
+ 1 < count
)
2296 (*mw_vec
)[i
+ 1] = (*mw_vec
)[i
+ dist
+ 1];
2300 mw_vec
->truncate (count
);
2304 /* Sort and remove duplicates from the COLLECTION_REC. */
2307 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2309 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2310 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2311 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2312 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2316 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2319 df_install_ref (df_ref this_ref
,
2320 struct df_reg_info
*reg_info
,
2321 struct df_ref_info
*ref_info
,
2324 unsigned int regno
= DF_REF_REGNO (this_ref
);
2325 /* Add the ref to the reg_{def,use,eq_use} chain. */
2326 df_ref head
= reg_info
->reg_chain
;
2328 reg_info
->reg_chain
= this_ref
;
2331 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2333 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2334 df
->hard_regs_live_count
[regno
]++;
2337 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2338 && DF_REF_PREV_REG (this_ref
) == NULL
);
2340 DF_REF_NEXT_REG (this_ref
) = head
;
2342 /* We cannot actually link to the head of the chain. */
2343 DF_REF_PREV_REG (this_ref
) = NULL
;
2346 DF_REF_PREV_REG (head
) = this_ref
;
2350 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2351 df_check_and_grow_ref_info (ref_info
, 1);
2352 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2353 /* Add the ref to the big array of defs. */
2354 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2355 ref_info
->table_size
++;
2358 DF_REF_ID (this_ref
) = -1;
2360 ref_info
->total_size
++;
2364 /* This function takes one of the groups of refs (defs, uses or
2365 eq_uses) and installs the entire group into the insn. It also adds
2366 each of these refs into the appropriate chains. */
2369 df_install_refs (basic_block bb
,
2370 const vec
<df_ref
, va_heap
> *old_vec
,
2371 struct df_reg_info
**reg_info
,
2372 struct df_ref_info
*ref_info
,
2375 unsigned int count
= old_vec
->length ();
2382 switch (ref_info
->ref_order
)
2384 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2385 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2386 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2387 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2388 add_to_table
= true;
2390 case DF_REF_ORDER_UNORDERED
:
2391 case DF_REF_ORDER_BY_REG
:
2392 case DF_REF_ORDER_BY_INSN
:
2393 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2394 add_to_table
= !is_notes
;
2397 add_to_table
= false;
2401 /* Do not add if ref is not in the right blocks. */
2402 if (add_to_table
&& df
->analyze_subset
)
2403 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2405 FOR_EACH_VEC_ELT (*old_vec
, ix
, this_ref
)
2407 DF_REF_NEXT_LOC (this_ref
) = (ix
+ 1 < old_vec
->length ()
2408 ? (*old_vec
)[ix
+ 1]
2410 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2411 ref_info
, add_to_table
);
2413 return (*old_vec
)[0];
2420 /* This function takes the mws installs the entire group into the
2423 static struct df_mw_hardreg
*
2424 df_install_mws (const vec
<df_mw_hardreg_ptr
, va_heap
> *old_vec
)
2426 unsigned int count
= old_vec
->length ();
2429 for (unsigned int i
= 0; i
< count
- 1; i
++)
2430 DF_MWS_NEXT ((*old_vec
)[i
]) = (*old_vec
)[i
+ 1];
2431 DF_MWS_NEXT ((*old_vec
)[count
- 1]) = 0;
2432 return (*old_vec
)[0];
2439 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2440 chains and update other necessary information. */
2443 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2444 basic_block bb
, rtx_insn
*insn
, unsigned int flags
)
2448 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2449 /* If there is a vector in the collection rec, add it to the
2450 insn. A null rec is a signal that the caller will handle the
2452 if (flags
& copy_defs
)
2454 gcc_checking_assert (!insn_rec
->defs
);
2456 = df_install_refs (bb
, &collection_rec
->def_vec
,
2458 &df
->def_info
, false);
2460 if (flags
& copy_uses
)
2462 gcc_checking_assert (!insn_rec
->uses
);
2464 = df_install_refs (bb
, &collection_rec
->use_vec
,
2466 &df
->use_info
, false);
2468 if (flags
& copy_eq_uses
)
2470 gcc_checking_assert (!insn_rec
->eq_uses
);
2472 = df_install_refs (bb
, &collection_rec
->eq_use_vec
,
2474 &df
->use_info
, true);
2476 if (flags
& copy_mw
)
2478 gcc_checking_assert (!insn_rec
->mw_hardregs
);
2479 insn_rec
->mw_hardregs
2480 = df_install_mws (&collection_rec
->mw_vec
);
2485 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2487 gcc_checking_assert (!bb_info
->artificial_defs
);
2488 bb_info
->artificial_defs
2489 = df_install_refs (bb
, &collection_rec
->def_vec
,
2491 &df
->def_info
, false);
2492 gcc_checking_assert (!bb_info
->artificial_uses
);
2493 bb_info
->artificial_uses
2494 = df_install_refs (bb
, &collection_rec
->use_vec
,
2496 &df
->use_info
, false);
2501 /* Allocate a ref and initialize its fields. */
2504 df_ref_create_structure (enum df_ref_class cl
,
2505 struct df_collection_rec
*collection_rec
,
2507 basic_block bb
, struct df_insn_info
*info
,
2508 enum df_ref_type ref_type
,
2511 df_ref this_ref
= NULL
;
2512 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2513 struct df_scan_problem_data
*problem_data
2514 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2519 this_ref
= (df_ref
) (problem_data
->ref_base_pool
->allocate ());
2520 gcc_checking_assert (loc
== NULL
);
2523 case DF_REF_ARTIFICIAL
:
2524 this_ref
= (df_ref
) (problem_data
->ref_artificial_pool
->allocate ());
2525 this_ref
->artificial_ref
.bb
= bb
;
2526 gcc_checking_assert (loc
== NULL
);
2529 case DF_REF_REGULAR
:
2530 this_ref
= (df_ref
) (problem_data
->ref_regular_pool
->allocate ());
2531 this_ref
->regular_ref
.loc
= loc
;
2532 gcc_checking_assert (loc
);
2536 DF_REF_CLASS (this_ref
) = cl
;
2537 DF_REF_ID (this_ref
) = -1;
2538 DF_REF_REG (this_ref
) = reg
;
2539 DF_REF_REGNO (this_ref
) = regno
;
2540 DF_REF_TYPE (this_ref
) = ref_type
;
2541 DF_REF_INSN_INFO (this_ref
) = info
;
2542 DF_REF_CHAIN (this_ref
) = NULL
;
2543 DF_REF_FLAGS (this_ref
) = ref_flags
;
2544 DF_REF_NEXT_REG (this_ref
) = NULL
;
2545 DF_REF_PREV_REG (this_ref
) = NULL
;
2546 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2548 /* We need to clear this bit because fwprop, and in the future
2549 possibly other optimizations sometimes create new refs using ond
2550 refs as the model. */
2551 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2553 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2554 if (regno
< FIRST_PSEUDO_REGISTER
2555 && !DF_REF_IS_ARTIFICIAL (this_ref
)
2556 && !DEBUG_INSN_P (DF_REF_INSN (this_ref
)))
2558 if (DF_REF_REG_DEF_P (this_ref
))
2560 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2561 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2563 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2564 && (regno
== FRAME_POINTER_REGNUM
2565 || regno
== ARG_POINTER_REGNUM
)))
2566 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2571 if (DF_REF_REG_DEF_P (this_ref
))
2572 collection_rec
->def_vec
.safe_push (this_ref
);
2573 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2574 collection_rec
->eq_use_vec
.safe_push (this_ref
);
2576 collection_rec
->use_vec
.safe_push (this_ref
);
2579 df_install_ref_incremental (this_ref
);
2585 /* Create new references of type DF_REF_TYPE for each part of register REG
2586 at address LOC within INSN of BB. */
2590 df_ref_record (enum df_ref_class cl
,
2591 struct df_collection_rec
*collection_rec
,
2593 basic_block bb
, struct df_insn_info
*insn_info
,
2594 enum df_ref_type ref_type
,
2599 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2601 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2602 if (regno
< FIRST_PSEUDO_REGISTER
)
2604 struct df_mw_hardreg
*hardreg
= NULL
;
2605 struct df_scan_problem_data
*problem_data
2606 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2608 unsigned int endregno
;
2611 if (GET_CODE (reg
) == SUBREG
)
2613 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2614 SUBREG_BYTE (reg
), GET_MODE (reg
));
2615 endregno
= regno
+ subreg_nregs (reg
);
2618 endregno
= END_REGNO (reg
);
2620 /* If this is a multiword hardreg, we create some extra
2621 datastructures that will enable us to easily build REG_DEAD
2622 and REG_UNUSED notes. */
2624 && (endregno
!= regno
+ 1) && insn_info
)
2626 /* Sets to a subreg of a multiword register are partial.
2627 Sets to a non-subreg of a multiword register are not. */
2628 if (GET_CODE (reg
) == SUBREG
)
2629 ref_flags
|= DF_REF_PARTIAL
;
2630 ref_flags
|= DF_REF_MW_HARDREG
;
2632 hardreg
= problem_data
->mw_reg_pool
->allocate ();
2633 hardreg
->type
= ref_type
;
2634 hardreg
->flags
= ref_flags
;
2635 hardreg
->mw_reg
= reg
;
2636 hardreg
->start_regno
= regno
;
2637 hardreg
->end_regno
= endregno
- 1;
2638 hardreg
->mw_order
= df
->ref_order
++;
2639 collection_rec
->mw_vec
.safe_push (hardreg
);
2642 for (i
= regno
; i
< endregno
; i
++)
2644 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2645 bb
, insn_info
, ref_type
, ref_flags
);
2647 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2652 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2653 ref_type
, ref_flags
);
2658 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2659 covered by the outer mode is smaller than that covered by the inner mode,
2660 is a read-modify-write operation.
2661 This function returns true iff the SUBREG X is such a SUBREG. */
2664 df_read_modify_subreg_p (rtx x
)
2666 unsigned int isize
, osize
;
2667 if (GET_CODE (x
) != SUBREG
)
2669 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2670 osize
= GET_MODE_SIZE (GET_MODE (x
));
2671 return isize
> osize
2672 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2676 /* Process all the registers defined in the rtx pointed by LOC.
2677 Autoincrement/decrement definitions will be picked up by df_uses_record.
2678 Any change here has to be matched in df_find_hard_reg_defs_1. */
2681 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2682 rtx
*loc
, basic_block bb
, struct df_insn_info
*insn_info
,
2687 /* It is legal to have a set destination be a parallel. */
2688 if (GET_CODE (dst
) == PARALLEL
)
2691 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2693 rtx temp
= XVECEXP (dst
, 0, i
);
2694 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2695 df_def_record_1 (collection_rec
, &XEXP (temp
, 0),
2696 bb
, insn_info
, flags
);
2701 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2703 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2705 loc
= &XEXP (dst
, 0);
2709 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2711 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2713 loc
= &XEXP (dst
, 0);
2717 /* At this point if we do not have a reg or a subreg, just return. */
2720 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2721 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2723 /* We want to keep sp alive everywhere - by making all
2724 writes to sp also use of sp. */
2725 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2726 df_ref_record (DF_REF_BASE
, collection_rec
,
2727 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
2729 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2731 if (df_read_modify_subreg_p (dst
))
2732 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2734 flags
|= DF_REF_SUBREG
;
2736 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2737 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2742 /* Process all the registers defined in the pattern rtx, X. Any change
2743 here has to be matched in df_find_hard_reg_defs. */
2746 df_defs_record (struct df_collection_rec
*collection_rec
,
2747 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2750 RTX_CODE code
= GET_CODE (x
);
2756 df_def_record_1 (collection_rec
, &SET_DEST (x
), bb
, insn_info
, flags
);
2760 flags
|= DF_REF_MUST_CLOBBER
;
2761 df_def_record_1 (collection_rec
, &XEXP (x
, 0), bb
, insn_info
, flags
);
2765 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
2766 bb
, insn_info
, DF_REF_CONDITIONAL
);
2770 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2771 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
),
2772 bb
, insn_info
, flags
);
2775 /* No DEFs to record in other cases */
2780 /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
2781 destination of a set or clobber. This has to match the logic in
2782 df_defs_record_1. */
2785 df_find_hard_reg_defs_1 (rtx dst
, HARD_REG_SET
*defs
)
2787 /* It is legal to have a set destination be a parallel. */
2788 if (GET_CODE (dst
) == PARALLEL
)
2791 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2793 rtx temp
= XVECEXP (dst
, 0, i
);
2794 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2795 df_find_hard_reg_defs_1 (XEXP (temp
, 0), defs
);
2800 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2801 dst
= XEXP (dst
, 0);
2803 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2804 dst
= XEXP (dst
, 0);
2806 /* At this point if we do not have a reg or a subreg, just return. */
2807 if (REG_P (dst
) && HARD_REGISTER_P (dst
))
2808 SET_HARD_REG_BIT (*defs
, REGNO (dst
));
2809 else if (GET_CODE (dst
) == SUBREG
2810 && REG_P (SUBREG_REG (dst
)) && HARD_REGISTER_P (dst
))
2811 SET_HARD_REG_BIT (*defs
, REGNO (SUBREG_REG (dst
)));
2814 /* Set bits in *DEFS for hard registers defined in the pattern X. This
2815 has to match the logic in df_defs_record. */
2818 df_find_hard_reg_defs (rtx x
, HARD_REG_SET
*defs
)
2820 RTX_CODE code
= GET_CODE (x
);
2826 df_find_hard_reg_defs_1 (SET_DEST (x
), defs
);
2830 df_find_hard_reg_defs_1 (XEXP (x
, 0), defs
);
2834 df_find_hard_reg_defs (COND_EXEC_CODE (x
), defs
);
2838 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2839 df_find_hard_reg_defs (XVECEXP (x
, 0, i
), defs
);
2842 /* No DEFs to record in other cases */
2848 /* Process all the registers used in the rtx at address LOC. */
2851 df_uses_record (struct df_collection_rec
*collection_rec
,
2852 rtx
*loc
, enum df_ref_type ref_type
,
2853 basic_block bb
, struct df_insn_info
*insn_info
,
2863 code
= GET_CODE (x
);
2877 /* If we are clobbering a MEM, mark any registers inside the address
2879 if (MEM_P (XEXP (x
, 0)))
2880 df_uses_record (collection_rec
,
2881 &XEXP (XEXP (x
, 0), 0),
2882 DF_REF_REG_MEM_STORE
,
2886 /* If we're clobbering a REG then we have a def so ignore. */
2890 df_uses_record (collection_rec
,
2891 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
2892 bb
, insn_info
, flags
& DF_REF_IN_NOTE
);
2896 /* While we're here, optimize this case. */
2897 flags
|= DF_REF_PARTIAL
;
2898 /* In case the SUBREG is not of a REG, do not optimize. */
2899 if (!REG_P (SUBREG_REG (x
)))
2901 loc
= &SUBREG_REG (x
);
2902 df_uses_record (collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
);
2905 /* ... Fall through ... */
2908 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2909 x
, loc
, bb
, insn_info
,
2916 df_uses_record (collection_rec
,
2917 &XEXP (x
, 1), ref_type
, bb
, insn_info
, flags
);
2918 df_uses_record (collection_rec
,
2919 &XEXP (x
, 2), ref_type
, bb
, insn_info
, flags
);
2921 /* If the parameters to the zero or sign extract are
2922 constants, strip them off and recurse, otherwise there is
2923 no information that we can gain from this operation. */
2924 if (code
== ZERO_EXTRACT
)
2925 flags
|= DF_REF_ZERO_EXTRACT
;
2927 flags
|= DF_REF_SIGN_EXTRACT
;
2929 df_uses_record (collection_rec
,
2930 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
);
2937 rtx dst
= SET_DEST (x
);
2938 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
2939 df_uses_record (collection_rec
,
2940 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
);
2942 switch (GET_CODE (dst
))
2945 if (df_read_modify_subreg_p (dst
))
2947 df_uses_record (collection_rec
, &SUBREG_REG (dst
),
2948 DF_REF_REG_USE
, bb
, insn_info
,
2949 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
);
2960 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2961 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
);
2963 case STRICT_LOW_PART
:
2965 rtx
*temp
= &XEXP (dst
, 0);
2966 /* A strict_low_part uses the whole REG and not just the
2968 dst
= XEXP (dst
, 0);
2969 df_uses_record (collection_rec
,
2970 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
2971 DF_REF_REG_USE
, bb
, insn_info
,
2972 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
);
2977 df_uses_record (collection_rec
, &XEXP (dst
, 1),
2978 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2979 df_uses_record (collection_rec
, &XEXP (dst
, 2),
2980 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2981 if (GET_CODE (XEXP (dst
,0)) == MEM
)
2982 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2983 DF_REF_REG_USE
, bb
, insn_info
,
2986 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2987 DF_REF_REG_USE
, bb
, insn_info
,
2988 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
);
3003 case UNSPEC_VOLATILE
:
3007 /* Traditional and volatile asm instructions must be
3008 considered to use and clobber all hard registers, all
3009 pseudo-registers and all of memory. So must TRAP_IF and
3010 UNSPEC_VOLATILE operations.
3012 Consider for instance a volatile asm that changes the fpu
3013 rounding mode. An insn should not be moved across this
3014 even if it only uses pseudo-regs because it might give an
3015 incorrectly rounded result.
3017 However, flow.c's liveness computation did *not* do this,
3018 giving the reasoning as " ?!? Unfortunately, marking all
3019 hard registers as live causes massive problems for the
3020 register allocator and marking all pseudos as live creates
3021 mountains of uninitialized variable warnings."
3023 In order to maintain the status quo with regard to liveness
3024 and uses, we do what flow.c did and just mark any regs we
3025 can find in ASM_OPERANDS as used. In global asm insns are
3026 scanned and regs_asm_clobbered is filled out.
3028 For all ASM_OPERANDS, we must traverse the vector of input
3029 operands. We can not just fall through here since then we
3030 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3031 which do not indicate traditional asms unlike their normal
3033 if (code
== ASM_OPERANDS
)
3037 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3038 df_uses_record (collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3039 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3046 df_uses_record (collection_rec
,
3047 &PAT_VAR_LOCATION_LOC (x
),
3048 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3057 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3058 /* Catch the def of the register being modified. */
3059 df_ref_record (DF_REF_REGULAR
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3062 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
);
3064 /* ... Fall through to handle uses ... */
3070 /* Recursively scan the operands of this expression. */
3072 const char *fmt
= GET_RTX_FORMAT (code
);
3075 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3079 /* Tail recursive case: save a function call level. */
3085 df_uses_record (collection_rec
, &XEXP (x
, i
), ref_type
,
3086 bb
, insn_info
, flags
);
3088 else if (fmt
[i
] == 'E')
3091 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3092 df_uses_record (collection_rec
,
3093 &XVECEXP (x
, i
, j
), ref_type
,
3094 bb
, insn_info
, flags
);
3103 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3106 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3111 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
3113 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3117 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3118 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3119 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3120 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
);
3121 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3127 /* Get call's extra defs and uses (track caller-saved registers). */
3130 df_get_call_refs (struct df_collection_rec
*collection_rec
,
3132 struct df_insn_info
*insn_info
,
3136 bool is_sibling_call
;
3138 HARD_REG_SET defs_generated
;
3139 HARD_REG_SET fn_reg_set_usage
;
3141 CLEAR_HARD_REG_SET (defs_generated
);
3142 df_find_hard_reg_defs (PATTERN (insn_info
->insn
), &defs_generated
);
3143 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3144 get_call_reg_set_usage (insn_info
->insn
, &fn_reg_set_usage
,
3145 regs_invalidated_by_call
);
3147 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3149 if (i
== STACK_POINTER_REGNUM
)
3150 /* The stack ptr is used (honorarily) by a CALL insn. */
3151 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3152 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3153 DF_REF_CALL_STACK_USAGE
| flags
);
3154 else if (global_regs
[i
])
3156 /* Calls to const functions cannot access any global registers and
3157 calls to pure functions cannot set them. All other calls may
3158 reference any of the global registers, so they are recorded as
3160 if (!RTL_CONST_CALL_P (insn_info
->insn
))
3162 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3163 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
3164 if (!RTL_PURE_CALL_P (insn_info
->insn
))
3165 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3166 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3169 else if (TEST_HARD_REG_BIT (fn_reg_set_usage
, i
)
3170 /* no clobbers for regs that are the result of the call */
3171 && !TEST_HARD_REG_BIT (defs_generated
, i
)
3172 && (!is_sibling_call
3173 || !bitmap_bit_p (df
->exit_block_uses
, i
)
3174 || refers_to_regno_p (i
, crtl
->return_rtx
)))
3175 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3176 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3177 DF_REF_MAY_CLOBBER
| flags
);
3180 /* Record the registers used to pass arguments, and explicitly
3181 noted as clobbered. */
3182 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3183 note
= XEXP (note
, 1))
3185 if (GET_CODE (XEXP (note
, 0)) == USE
)
3186 df_uses_record (collection_rec
, &XEXP (XEXP (note
, 0), 0),
3187 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3188 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3190 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3192 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3193 if (!TEST_HARD_REG_BIT (defs_generated
, regno
))
3194 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3198 df_uses_record (collection_rec
, &XEXP (note
, 0),
3199 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3206 /* Collect all refs in the INSN. This function is free of any
3207 side-effect - it will create and return a lists of df_ref's in the
3208 COLLECTION_REC without putting those refs into existing ref chains
3212 df_insn_refs_collect (struct df_collection_rec
*collection_rec
,
3213 basic_block bb
, struct df_insn_info
*insn_info
)
3216 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3218 /* Clear out the collection record. */
3219 collection_rec
->def_vec
.truncate (0);
3220 collection_rec
->use_vec
.truncate (0);
3221 collection_rec
->eq_use_vec
.truncate (0);
3222 collection_rec
->mw_vec
.truncate (0);
3224 /* Process REG_EQUIV/REG_EQUAL notes. */
3225 for (note
= REG_NOTES (insn_info
->insn
); note
;
3226 note
= XEXP (note
, 1))
3228 switch (REG_NOTE_KIND (note
))
3232 df_uses_record (collection_rec
,
3233 &XEXP (note
, 0), DF_REF_REG_USE
,
3234 bb
, insn_info
, DF_REF_IN_NOTE
);
3236 case REG_NON_LOCAL_GOTO
:
3237 /* The frame ptr is used by a non-local goto. */
3238 df_ref_record (DF_REF_BASE
, collection_rec
,
3239 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3240 NULL
, bb
, insn_info
,
3242 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3243 df_ref_record (DF_REF_BASE
, collection_rec
,
3244 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3245 NULL
, bb
, insn_info
,
3253 /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
3254 uses from CALL_INSN_FUNCTION_USAGE. */
3255 if (CALL_P (insn_info
->insn
))
3256 df_get_call_refs (collection_rec
, bb
, insn_info
,
3257 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3259 /* Record other defs. These should be mostly for DF_REF_REGULAR, so
3260 that a qsort on the defs is unnecessary in most cases. */
3261 df_defs_record (collection_rec
,
3262 PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3264 /* Record the register uses. */
3265 df_uses_record (collection_rec
,
3266 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0);
3268 /* DF_REF_CONDITIONAL needs corresponding USES. */
3270 df_get_conditional_uses (collection_rec
);
3272 df_canonize_collection_rec (collection_rec
);
3275 /* Recompute the luids for the insns in BB. */
3278 df_recompute_luids (basic_block bb
)
3283 df_grow_insn_info ();
3285 /* Scan the block an insn at a time from beginning to end. */
3286 FOR_BB_INSNS (bb
, insn
)
3288 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3289 /* Inserting labels does not always trigger the incremental
3293 gcc_assert (!INSN_P (insn
));
3294 insn_info
= df_insn_create_insn_record (insn
);
3297 DF_INSN_INFO_LUID (insn_info
) = luid
;
3304 /* Collect all artificial refs at the block level for BB and add them
3305 to COLLECTION_REC. */
3308 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3310 collection_rec
->def_vec
.truncate (0);
3311 collection_rec
->use_vec
.truncate (0);
3312 collection_rec
->eq_use_vec
.truncate (0);
3313 collection_rec
->mw_vec
.truncate (0);
3315 if (bb
->index
== ENTRY_BLOCK
)
3317 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3320 else if (bb
->index
== EXIT_BLOCK
)
3322 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3326 if (bb_has_eh_pred (bb
))
3329 /* Mark the registers that will contain data for the handler. */
3332 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3333 if (regno
== INVALID_REGNUM
)
3335 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3336 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3340 /* Add the hard_frame_pointer if this block is the target of a
3342 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3343 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3344 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3346 /* Add the artificial uses. */
3347 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3351 bitmap au
= bb_has_eh_pred (bb
)
3352 ? &df
->eh_block_artificial_uses
3353 : &df
->regular_block_artificial_uses
;
3355 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3357 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3358 bb
, NULL
, DF_REF_REG_USE
, 0);
3362 df_canonize_collection_rec (collection_rec
);
3366 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3369 df_bb_refs_record (int bb_index
, bool scan_insns
)
3371 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3378 df_collection_rec collection_rec
;
3379 df_grow_bb_info (df_scan
);
3381 /* Scan the block an insn at a time from beginning to end. */
3382 FOR_BB_INSNS (bb
, insn
)
3384 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3385 gcc_assert (!insn_info
);
3387 insn_info
= df_insn_create_insn_record (insn
);
3390 /* Record refs within INSN. */
3391 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3392 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3393 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
3395 DF_INSN_INFO_LUID (insn_info
) = luid
;
3398 /* Other block level artificial refs */
3399 df_bb_refs_collect (&collection_rec
, bb
);
3400 df_refs_add_to_chains (&collection_rec
, bb
, NULL
, copy_all
);
3402 /* Now that the block has been processed, set the block as dirty so
3403 LR and LIVE will get it processed. */
3404 df_set_bb_dirty (bb
);
3408 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3412 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3418 bitmap_clear (regular_block_artificial_uses
);
3420 if (reload_completed
)
3422 if (frame_pointer_needed
)
3423 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3426 /* Before reload, there are a few registers that must be forced
3427 live everywhere -- which might not already be the case for
3428 blocks within infinite loops. */
3430 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3432 /* Any reference to any pseudo before reload is a potential
3433 reference of the frame pointer. */
3434 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3436 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3437 bitmap_set_bit (regular_block_artificial_uses
,
3438 HARD_FRAME_POINTER_REGNUM
);
3440 /* Pseudos with argument area equivalences may require
3441 reloading via the argument pointer. */
3442 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3443 && fixed_regs
[ARG_POINTER_REGNUM
])
3444 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3446 /* Any constant, or pseudo with constant equivalences, may
3447 require reloading from memory using the pic register. */
3448 if (picreg
!= INVALID_REGNUM
3449 && fixed_regs
[picreg
])
3450 bitmap_set_bit (regular_block_artificial_uses
, picreg
);
3452 /* The all-important stack pointer must always be live. */
3453 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3456 /* EH_USES registers are used:
3457 1) at all insns that might throw (calls or with -fnon-call-exceptions
3460 3) to support backtraces and/or debugging, anywhere between their
3461 initialization and where they the saved registers are restored
3462 from them, including the cases where we don't reach the epilogue
3463 (noreturn call or infinite loop). */
3464 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3466 bitmap_set_bit (regular_block_artificial_uses
, i
);
3471 /* Get the artificial use set for an eh block. */
3474 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3476 bitmap_clear (eh_block_artificial_uses
);
3478 /* The following code (down through the arg_pointer setting APPEARS
3479 to be necessary because there is nothing that actually
3480 describes what the exception handling code may actually need
3482 if (reload_completed
)
3484 if (frame_pointer_needed
)
3486 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3487 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
)
3488 bitmap_set_bit (eh_block_artificial_uses
,
3489 HARD_FRAME_POINTER_REGNUM
);
3491 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3492 && fixed_regs
[ARG_POINTER_REGNUM
])
3493 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3499 /*----------------------------------------------------------------------------
3500 Specialized hard register scanning functions.
3501 ----------------------------------------------------------------------------*/
3504 /* Mark a register in SET. Hard registers in large modes get all
3505 of their component registers set as well. */
3508 df_mark_reg (rtx reg
, void *vset
)
3510 bitmap_set_range ((bitmap
) vset
, REGNO (reg
), REG_NREGS (reg
));
3514 /* Set the bit for regs that are considered being defined at the entry. */
3517 df_get_entry_block_def_set (bitmap entry_block_defs
)
3522 bitmap_clear (entry_block_defs
);
3524 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3527 bitmap_set_bit (entry_block_defs
, i
);
3528 if (FUNCTION_ARG_REGNO_P (i
))
3529 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3532 /* The always important stack pointer. */
3533 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3535 /* Once the prologue has been generated, all of these registers
3536 should just show up in the first regular block. */
3537 if (HAVE_prologue
&& epilogue_completed
)
3539 /* Defs for the callee saved registers are inserted so that the
3540 pushes have some defining location. */
3541 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3542 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3543 bitmap_set_bit (entry_block_defs
, i
);
3546 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3548 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3550 /* If the function has an incoming STATIC_CHAIN, it has to show up
3551 in the entry def set. */
3552 r
= targetm
.calls
.static_chain (current_function_decl
, true);
3554 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3556 if ((!reload_completed
) || frame_pointer_needed
)
3558 /* Any reference to any pseudo before reload is a potential
3559 reference of the frame pointer. */
3560 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3562 /* If they are different, also mark the hard frame pointer as live. */
3563 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3564 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3565 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3568 /* These registers are live everywhere. */
3569 if (!reload_completed
)
3571 /* Pseudos with argument area equivalences may require
3572 reloading via the argument pointer. */
3573 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3574 && fixed_regs
[ARG_POINTER_REGNUM
])
3575 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3577 /* Any constant, or pseudo with constant equivalences, may
3578 require reloading from memory using the pic register. */
3579 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3580 if (picreg
!= INVALID_REGNUM
3581 && fixed_regs
[picreg
])
3582 bitmap_set_bit (entry_block_defs
, picreg
);
3585 #ifdef INCOMING_RETURN_ADDR_RTX
3586 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3587 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3590 targetm
.extra_live_on_entry (entry_block_defs
);
3594 /* Return the (conservative) set of hard registers that are defined on
3595 entry to the function.
3596 It uses df->entry_block_defs to determine which register
3597 reference to include. */
3600 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3601 bitmap entry_block_defs
)
3606 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3608 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3609 ENTRY_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_DEF
, 0);
3612 df_canonize_collection_rec (collection_rec
);
3616 /* Record the (conservative) set of hard registers that are defined on
3617 entry to the function. */
3620 df_record_entry_block_defs (bitmap entry_block_defs
)
3622 struct df_collection_rec collection_rec
;
3623 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3625 /* Process bb_refs chain */
3626 df_refs_add_to_chains (&collection_rec
,
3627 BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
),
3633 /* Update the defs in the entry block. */
3636 df_update_entry_block_defs (void)
3639 bool changed
= false;
3641 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3642 df_get_entry_block_def_set (&refs
);
3643 if (df
->entry_block_defs
)
3645 if (!bitmap_equal_p (df
->entry_block_defs
, &refs
))
3647 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3648 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3649 df_ref_chain_delete (bb_info
->artificial_defs
);
3650 bb_info
->artificial_defs
= NULL
;
3656 struct df_scan_problem_data
*problem_data
3657 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3659 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3665 df_record_entry_block_defs (&refs
);
3666 bitmap_copy (df
->entry_block_defs
, &refs
);
3667 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
3669 bitmap_clear (&refs
);
3673 /* Set the bit for regs that are considered being used at the exit. */
3676 df_get_exit_block_use_set (bitmap exit_block_uses
)
3679 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3681 bitmap_clear (exit_block_uses
);
3683 /* Stack pointer is always live at the exit. */
3684 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3686 /* Mark the frame pointer if needed at the end of the function.
3687 If we end up eliminating it, it will be removed from the live
3688 list of each basic block by reload. */
3690 if ((!reload_completed
) || frame_pointer_needed
)
3692 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3694 /* If they are different, also mark the hard frame pointer as live. */
3695 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
3696 && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3697 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3700 /* Many architectures have a GP register even without flag_pic.
3701 Assume the pic register is not in use, or will be handled by
3702 other means, if it is not fixed. */
3703 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3704 && picreg
!= INVALID_REGNUM
3705 && fixed_regs
[picreg
])
3706 bitmap_set_bit (exit_block_uses
, picreg
);
3708 /* Mark all global registers, and all registers used by the
3709 epilogue as being live at the end of the function since they
3710 may be referenced by our caller. */
3711 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3712 if (global_regs
[i
] || EPILOGUE_USES (i
))
3713 bitmap_set_bit (exit_block_uses
, i
);
3715 if (HAVE_epilogue
&& epilogue_completed
)
3717 /* Mark all call-saved registers that we actually used. */
3718 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3719 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
3720 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3721 bitmap_set_bit (exit_block_uses
, i
);
3724 /* Mark the registers that will contain data for the handler. */
3725 if (reload_completed
&& crtl
->calls_eh_return
)
3728 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3729 if (regno
== INVALID_REGNUM
)
3731 bitmap_set_bit (exit_block_uses
, regno
);
3734 #ifdef EH_RETURN_STACKADJ_RTX
3735 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3736 && crtl
->calls_eh_return
)
3738 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
3739 if (tmp
&& REG_P (tmp
))
3740 df_mark_reg (tmp
, exit_block_uses
);
3744 #ifdef EH_RETURN_HANDLER_RTX
3745 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3746 && crtl
->calls_eh_return
)
3748 rtx tmp
= EH_RETURN_HANDLER_RTX
;
3749 if (tmp
&& REG_P (tmp
))
3750 df_mark_reg (tmp
, exit_block_uses
);
3754 /* Mark function return value. */
3755 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
3759 /* Return the refs of hard registers that are used in the exit block.
3760 It uses df->exit_block_uses to determine register to include. */
3763 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
3768 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
3769 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3770 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3772 /* It is deliberate that this is not put in the exit block uses but
3773 I do not know why. */
3774 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
3776 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
3777 && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun
))
3778 && fixed_regs
[ARG_POINTER_REGNUM
])
3779 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
3780 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3782 df_canonize_collection_rec (collection_rec
);
3786 /* Record the set of hard registers that are used in the exit block.
3787 It uses df->exit_block_uses to determine which bit to include. */
3790 df_record_exit_block_uses (bitmap exit_block_uses
)
3792 struct df_collection_rec collection_rec
;
3793 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
3795 /* Process bb_refs chain */
3796 df_refs_add_to_chains (&collection_rec
,
3797 BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
),
3803 /* Update the uses in the exit block. */
3806 df_update_exit_block_uses (void)
3809 bool changed
= false;
3811 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3812 df_get_exit_block_use_set (&refs
);
3813 if (df
->exit_block_uses
)
3815 if (!bitmap_equal_p (df
->exit_block_uses
, &refs
))
3817 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
3818 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
3819 df_ref_chain_delete (bb_info
->artificial_uses
);
3820 bb_info
->artificial_uses
= NULL
;
3826 struct df_scan_problem_data
*problem_data
3827 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3829 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3835 df_record_exit_block_uses (&refs
);
3836 bitmap_copy (df
->exit_block_uses
,& refs
);
3837 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
3839 bitmap_clear (&refs
);
3842 static bool initialized
= false;
3845 /* Initialize some platform specific structures. */
3848 df_hard_reg_init (void)
3850 #ifdef ELIMINABLE_REGS
3852 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
3857 /* Record which registers will be eliminated. We use this in
3859 CLEAR_HARD_REG_SET (elim_reg_set
);
3861 #ifdef ELIMINABLE_REGS
3862 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
3863 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
3865 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
3872 /* Recompute the parts of scanning that are based on regs_ever_live
3873 because something changed in that array. */
3876 df_update_entry_exit_and_calls (void)
3880 df_update_entry_block_defs ();
3881 df_update_exit_block_uses ();
3883 /* The call insns need to be rescanned because there may be changes
3884 in the set of registers clobbered across the call. */
3885 FOR_EACH_BB_FN (bb
, cfun
)
3888 FOR_BB_INSNS (bb
, insn
)
3890 if (INSN_P (insn
) && CALL_P (insn
))
3891 df_insn_rescan (insn
);
3897 /* Return true if hard REG is actually used in the some instruction.
3898 There are a fair number of conditions that affect the setting of
3899 this array. See the comment in df.h for df->hard_regs_live_count
3900 for the conditions that this array is set. */
3903 df_hard_reg_used_p (unsigned int reg
)
3905 return df
->hard_regs_live_count
[reg
] != 0;
3909 /* A count of the number of times REG is actually used in the some
3910 instruction. There are a fair number of conditions that affect the
3911 setting of this array. See the comment in df.h for
3912 df->hard_regs_live_count for the conditions that this array is
3917 df_hard_reg_used_count (unsigned int reg
)
3919 return df
->hard_regs_live_count
[reg
];
3923 /* Get the value of regs_ever_live[REGNO]. */
3926 df_regs_ever_live_p (unsigned int regno
)
3928 return regs_ever_live
[regno
];
3932 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
3933 to change, schedule that change for the next update. */
3936 df_set_regs_ever_live (unsigned int regno
, bool value
)
3938 if (regs_ever_live
[regno
] == value
)
3941 regs_ever_live
[regno
] = value
;
3943 df
->redo_entry_and_exit
= true;
3947 /* Compute "regs_ever_live" information from the underlying df
3948 information. Set the vector to all false if RESET. */
3951 df_compute_regs_ever_live (bool reset
)
3954 bool changed
= df
->redo_entry_and_exit
;
3957 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
3959 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3960 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
3962 regs_ever_live
[i
] = true;
3966 df_update_entry_exit_and_calls ();
3967 df
->redo_entry_and_exit
= false;
3971 /*----------------------------------------------------------------------------
3972 Dataflow ref information verification functions.
3974 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
3975 df_reg_chain_verify_unmarked (refs)
3976 df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
3977 df_mws_verify (mw*, mw*, bool)
3978 df_insn_refs_verify (collection_rec, bb, insn, bool)
3979 df_bb_refs_verify (bb, refs, bool)
3981 df_exit_block_bitmap_verify (bool)
3982 df_entry_block_bitmap_verify (bool)
3984 ----------------------------------------------------------------------------*/
3987 /* Mark all refs in the reg chain. Verify that all of the registers
3988 are in the correct chain. */
3991 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
3992 bool is_def
, bool is_eq_use
)
3994 unsigned int count
= 0;
3996 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
3998 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4000 /* If there are no def-use or use-def chains, make sure that all
4001 of the chains are clear. */
4003 gcc_assert (!DF_REF_CHAIN (ref
));
4005 /* Check to make sure the ref is in the correct chain. */
4006 gcc_assert (DF_REF_REGNO (ref
) == regno
);
4008 gcc_assert (DF_REF_REG_DEF_P (ref
));
4010 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4013 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4015 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4017 if (DF_REF_NEXT_REG (ref
))
4018 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4020 DF_REF_REG_MARK (ref
);
4026 /* Verify that all of the registers in the chain are unmarked. */
4029 df_reg_chain_verify_unmarked (df_ref refs
)
4032 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4033 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4037 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4040 df_refs_verify (const vec
<df_ref
, va_heap
> *new_rec
, df_ref old_rec
,
4046 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_ref
)
4048 if (old_rec
== NULL
|| !df_ref_equal_p (new_ref
, old_rec
))
4056 /* Abort if fail is called from the function level verifier. If
4057 that is the context, mark this reg as being seem. */
4060 gcc_assert (DF_REF_IS_REG_MARKED (old_rec
));
4061 DF_REF_REG_UNMARK (old_rec
);
4064 old_rec
= DF_REF_NEXT_LOC (old_rec
);
4068 gcc_assert (old_rec
== NULL
);
4070 return old_rec
== NULL
;
4075 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4078 df_mws_verify (const vec
<df_mw_hardreg_ptr
, va_heap
> *new_rec
,
4079 struct df_mw_hardreg
*old_rec
,
4083 struct df_mw_hardreg
*new_reg
;
4085 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_reg
)
4087 if (old_rec
== NULL
|| !df_mw_equal_p (new_reg
, old_rec
))
4094 old_rec
= DF_MWS_NEXT (old_rec
);
4098 gcc_assert (old_rec
== NULL
);
4100 return old_rec
== NULL
;
4105 /* Return true if the existing insn refs information is complete and
4106 correct. Otherwise (i.e. if there's any missing or extra refs),
4107 return the correct df_ref chain in REFS_RETURN.
4109 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4110 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4111 verification mode instead of the whole function, so unmark
4114 If ABORT_IF_FAIL is set, this function never returns false. */
4117 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4122 bool ret1
, ret2
, ret3
, ret4
;
4123 unsigned int uid
= INSN_UID (insn
);
4124 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4126 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4128 /* Unfortunately we cannot opt out early if one of these is not
4129 right because the marks will not get cleared. */
4130 ret1
= df_refs_verify (&collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4132 ret2
= df_refs_verify (&collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4134 ret3
= df_refs_verify (&collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4136 ret4
= df_mws_verify (&collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4138 return (ret1
&& ret2
&& ret3
&& ret4
);
4142 /* Return true if all refs in the basic block are correct and complete.
4143 Due to df_ref_chain_verify, it will cause all refs
4144 that are verified to have DF_REF_MARK bit set. */
4147 df_bb_verify (basic_block bb
)
4150 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4151 struct df_collection_rec collection_rec
;
4153 gcc_assert (bb_info
);
4155 /* Scan the block, one insn at a time, from beginning to end. */
4156 FOR_BB_INSNS_REVERSE (bb
, insn
)
4160 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4161 df_free_collection_rec (&collection_rec
);
4164 /* Do the artificial defs and uses. */
4165 df_bb_refs_collect (&collection_rec
, bb
);
4166 df_refs_verify (&collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4167 df_refs_verify (&collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4168 df_free_collection_rec (&collection_rec
);
4174 /* Returns true if the entry block has correct and complete df_ref set.
4175 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4178 df_entry_block_bitmap_verify (bool abort_if_fail
)
4180 bitmap_head entry_block_defs
;
4183 bitmap_initialize (&entry_block_defs
, &df_bitmap_obstack
);
4184 df_get_entry_block_def_set (&entry_block_defs
);
4186 is_eq
= bitmap_equal_p (&entry_block_defs
, df
->entry_block_defs
);
4188 if (!is_eq
&& abort_if_fail
)
4190 fprintf (stderr
, "entry_block_defs = ");
4191 df_print_regset (stderr
, &entry_block_defs
);
4192 fprintf (stderr
, "df->entry_block_defs = ");
4193 df_print_regset (stderr
, df
->entry_block_defs
);
4197 bitmap_clear (&entry_block_defs
);
4203 /* Returns true if the exit block has correct and complete df_ref set.
4204 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4207 df_exit_block_bitmap_verify (bool abort_if_fail
)
4209 bitmap_head exit_block_uses
;
4212 bitmap_initialize (&exit_block_uses
, &df_bitmap_obstack
);
4213 df_get_exit_block_use_set (&exit_block_uses
);
4215 is_eq
= bitmap_equal_p (&exit_block_uses
, df
->exit_block_uses
);
4217 if (!is_eq
&& abort_if_fail
)
4219 fprintf (stderr
, "exit_block_uses = ");
4220 df_print_regset (stderr
, &exit_block_uses
);
4221 fprintf (stderr
, "df->exit_block_uses = ");
4222 df_print_regset (stderr
, df
->exit_block_uses
);
4226 bitmap_clear (&exit_block_uses
);
4232 /* Return true if df_ref information for all insns in all blocks are
4233 correct and complete. */
4236 df_scan_verify (void)
4240 bitmap_head regular_block_artificial_uses
;
4241 bitmap_head eh_block_artificial_uses
;
4246 /* Verification is a 4 step process. */
4248 /* (1) All of the refs are marked by going through the reg chains. */
4249 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4251 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4252 == DF_REG_DEF_COUNT (i
));
4253 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4254 == DF_REG_USE_COUNT (i
));
4255 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4256 == DF_REG_EQ_USE_COUNT (i
));
4259 /* (2) There are various bitmaps whose value may change over the
4260 course of the compilation. This step recomputes them to make
4261 sure that they have not slipped out of date. */
4262 bitmap_initialize (®ular_block_artificial_uses
, &df_bitmap_obstack
);
4263 bitmap_initialize (&eh_block_artificial_uses
, &df_bitmap_obstack
);
4265 df_get_regular_block_artificial_uses (®ular_block_artificial_uses
);
4266 df_get_eh_block_artificial_uses (&eh_block_artificial_uses
);
4268 bitmap_ior_into (&eh_block_artificial_uses
,
4269 ®ular_block_artificial_uses
);
4271 /* Check artificial_uses bitmaps didn't change. */
4272 gcc_assert (bitmap_equal_p (®ular_block_artificial_uses
,
4273 &df
->regular_block_artificial_uses
));
4274 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses
,
4275 &df
->eh_block_artificial_uses
));
4277 bitmap_clear (®ular_block_artificial_uses
);
4278 bitmap_clear (&eh_block_artificial_uses
);
4280 /* Verify entry block and exit block. These only verify the bitmaps,
4281 the refs are verified in df_bb_verify. */
4282 df_entry_block_bitmap_verify (true);
4283 df_exit_block_bitmap_verify (true);
4285 /* (3) All of the insns in all of the blocks are traversed and the
4286 marks are cleared both in the artificial refs attached to the
4287 blocks and the real refs inside the insns. It is a failure to
4288 clear a mark that has not been set as this means that the ref in
4289 the block or insn was not in the reg chain. */
4291 FOR_ALL_BB_FN (bb
, cfun
)
4294 /* (4) See if all reg chains are traversed a second time. This time
4295 a check is made that the marks are clear. A set mark would be a
4296 from a reg that is not in any insn or basic block. */
4298 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4300 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4301 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4302 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));