1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999-2014 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
30 #include "insn-config.h"
34 #include "alloc-pool.h"
36 #include "hard-reg-set.h"
37 #include "basic-block.h"
43 #include "target-def.h"
45 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
48 typedef struct df_mw_hardreg
*df_mw_hardreg_ptr
;
52 #define HAVE_epilogue 0
55 #define HAVE_prologue 0
57 #ifndef HAVE_sibcall_epilogue
58 #define HAVE_sibcall_epilogue 0
62 #define EPILOGUE_USES(REGNO) 0
65 /* The 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
, unsigned int);
114 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
, rtx
, bool);
115 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
116 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
117 static void df_install_ref (df_ref
, struct df_reg_info
*,
118 struct df_ref_info
*, bool);
120 static int df_ref_compare (df_ref
, df_ref
);
121 static int df_ref_ptr_compare (const void *, const void *);
122 static int df_mw_compare (const df_mw_hardreg
*, const df_mw_hardreg
*);
123 static int df_mw_ptr_compare (const void *, const void *);
125 static void df_insn_info_delete (unsigned int);
127 /* Indexed by hardware reg number, is true if that register is ever
128 used in the current function.
130 In df-scan.c, this is set up to record the hard regs used
131 explicitly. Reload adds in the hard regs used for holding pseudo
132 regs. Final uses it to generate the code in the function prologue
133 and epilogue to save and restore registers as needed. */
135 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
137 /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
138 static const unsigned int copy_defs
= 0x1;
139 static const unsigned int copy_uses
= 0x2;
140 static const unsigned int copy_eq_uses
= 0x4;
141 static const unsigned int copy_mw
= 0x8;
142 static const unsigned int copy_all
= copy_defs
| copy_uses
| copy_eq_uses
145 /*----------------------------------------------------------------------------
146 SCANNING DATAFLOW PROBLEM
148 There are several ways in which scanning looks just like the other
149 dataflow problems. It shares the all the mechanisms for local info
150 as well as basic block info. Where it differs is when and how often
151 it gets run. It also has no need for the iterative solver.
152 ----------------------------------------------------------------------------*/
154 /* Problem data for the scanning dataflow function. */
155 struct df_scan_problem_data
157 alloc_pool ref_base_pool
;
158 alloc_pool ref_artificial_pool
;
159 alloc_pool ref_regular_pool
;
160 alloc_pool insn_pool
;
162 alloc_pool mw_reg_pool
;
163 bitmap_obstack reg_bitmaps
;
164 bitmap_obstack insn_bitmaps
;
167 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
170 /* Internal function to shut down the scanning problem. */
172 df_scan_free_internal (void)
174 struct df_scan_problem_data
*problem_data
175 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
177 free (df
->def_info
.refs
);
178 free (df
->def_info
.begin
);
179 free (df
->def_info
.count
);
180 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
182 free (df
->use_info
.refs
);
183 free (df
->use_info
.begin
);
184 free (df
->use_info
.count
);
185 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
191 free (df
->eq_use_regs
);
192 df
->eq_use_regs
= NULL
;
194 DF_REG_SIZE (df
) = 0;
200 free (df_scan
->block_info
);
201 df_scan
->block_info
= NULL
;
202 df_scan
->block_info_size
= 0;
204 bitmap_clear (&df
->hardware_regs_used
);
205 bitmap_clear (&df
->regular_block_artificial_uses
);
206 bitmap_clear (&df
->eh_block_artificial_uses
);
207 BITMAP_FREE (df
->entry_block_defs
);
208 BITMAP_FREE (df
->exit_block_uses
);
209 bitmap_clear (&df
->insns_to_delete
);
210 bitmap_clear (&df
->insns_to_rescan
);
211 bitmap_clear (&df
->insns_to_notes_rescan
);
213 free_alloc_pool (problem_data
->ref_base_pool
);
214 free_alloc_pool (problem_data
->ref_artificial_pool
);
215 free_alloc_pool (problem_data
->ref_regular_pool
);
216 free_alloc_pool (problem_data
->insn_pool
);
217 free_alloc_pool (problem_data
->reg_pool
);
218 free_alloc_pool (problem_data
->mw_reg_pool
);
219 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
220 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
221 free (df_scan
->problem_data
);
225 /* Free basic block info. */
228 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
230 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
231 unsigned int bb_index
= bb
->index
;
234 FOR_BB_INSNS (bb
, insn
)
236 df_insn_info_delete (INSN_UID (insn
));
238 if (bb_index
< df_scan
->block_info_size
)
239 bb_info
= df_scan_get_bb_info (bb_index
);
241 /* Get rid of any artificial uses or defs. */
242 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
243 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
244 df_ref_chain_delete (bb_info
->artificial_defs
);
245 df_ref_chain_delete (bb_info
->artificial_uses
);
246 bb_info
->artificial_defs
= NULL
;
247 bb_info
->artificial_uses
= NULL
;
251 /* Allocate the problem data for the scanning problem. This should be
252 called when the problem is created or when the entire function is to
255 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
257 struct df_scan_problem_data
*problem_data
;
258 unsigned int insn_num
= get_max_uid () + 1;
259 unsigned int block_size
= 512;
262 /* Given the number of pools, this is really faster than tearing
264 if (df_scan
->problem_data
)
265 df_scan_free_internal ();
267 problem_data
= XNEW (struct df_scan_problem_data
);
268 df_scan
->problem_data
= problem_data
;
269 df_scan
->computed
= true;
271 problem_data
->ref_base_pool
272 = create_alloc_pool ("df_scan ref base",
273 sizeof (struct df_base_ref
), block_size
);
274 problem_data
->ref_artificial_pool
275 = create_alloc_pool ("df_scan ref artificial",
276 sizeof (struct df_artificial_ref
), block_size
);
277 problem_data
->ref_regular_pool
278 = create_alloc_pool ("df_scan ref regular",
279 sizeof (struct df_regular_ref
), block_size
);
280 problem_data
->insn_pool
281 = create_alloc_pool ("df_scan insn",
282 sizeof (struct df_insn_info
), block_size
);
283 problem_data
->reg_pool
284 = create_alloc_pool ("df_scan reg",
285 sizeof (struct df_reg_info
), block_size
);
286 problem_data
->mw_reg_pool
287 = create_alloc_pool ("df_scan mw_reg",
288 sizeof (struct df_mw_hardreg
), block_size
/ 16);
290 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
291 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
293 insn_num
+= insn_num
/ 4;
296 df_grow_insn_info ();
297 df_grow_bb_info (df_scan
);
299 FOR_ALL_BB_FN (bb
, cfun
)
301 unsigned int bb_index
= bb
->index
;
302 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
303 bb_info
->artificial_defs
= NULL
;
304 bb_info
->artificial_uses
= NULL
;
307 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
308 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
309 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
310 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
311 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
312 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
313 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
314 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
315 df_scan
->optional_p
= false;
319 /* Free all of the data associated with the scan problem. */
324 if (df_scan
->problem_data
)
325 df_scan_free_internal ();
327 if (df
->blocks_to_analyze
)
329 BITMAP_FREE (df
->blocks_to_analyze
);
330 df
->blocks_to_analyze
= NULL
;
336 /* Dump the preamble for DF_SCAN dump. */
338 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
349 fprintf (file
, ";; invalidated by call \t");
350 df_print_regset (file
, regs_invalidated_by_call_regset
);
351 fprintf (file
, ";; hardware regs used \t");
352 df_print_regset (file
, &df
->hardware_regs_used
);
353 fprintf (file
, ";; regular block artificial uses \t");
354 df_print_regset (file
, &df
->regular_block_artificial_uses
);
355 fprintf (file
, ";; eh block artificial uses \t");
356 df_print_regset (file
, &df
->eh_block_artificial_uses
);
357 fprintf (file
, ";; entry block defs \t");
358 df_print_regset (file
, df
->entry_block_defs
);
359 fprintf (file
, ";; exit block uses \t");
360 df_print_regset (file
, df
->exit_block_uses
);
361 fprintf (file
, ";; regs ever live \t");
362 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
363 if (df_regs_ever_live_p (i
))
364 fprintf (file
, " %d[%s]", i
, reg_names
[i
]);
365 fprintf (file
, "\n;; ref usage \t");
367 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
368 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
370 const char * sep
= "";
372 fprintf (file
, "r%d={", i
);
373 if (DF_REG_DEF_COUNT (i
))
375 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
377 dcount
+= DF_REG_DEF_COUNT (i
);
379 if (DF_REG_USE_COUNT (i
))
381 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
383 ucount
+= DF_REG_USE_COUNT (i
);
385 if (DF_REG_EQ_USE_COUNT (i
))
387 fprintf (file
, "%s%de", sep
, DF_REG_EQ_USE_COUNT (i
));
388 ecount
+= DF_REG_EQ_USE_COUNT (i
);
390 fprintf (file
, "} ");
393 FOR_EACH_BB_FN (bb
, cfun
)
394 FOR_BB_INSNS (bb
, insn
)
403 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de}"
404 " in %d{%d regular + %d call} insns.\n",
405 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
,
406 icount
+ ccount
, icount
, ccount
);
409 /* Dump the bb_info for a given basic block. */
411 df_scan_start_block (basic_block bb
, FILE *file
)
413 struct df_scan_bb_info
*bb_info
414 = df_scan_get_bb_info (bb
->index
);
418 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
419 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
420 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
421 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
422 fprintf (file
, "\n");
427 FOR_BB_INSNS (bb
, insn
)
429 df_insn_debug (insn
, false, file
);
434 static struct df_problem problem_SCAN
=
436 DF_SCAN
, /* Problem id. */
437 DF_NONE
, /* Direction. */
438 df_scan_alloc
, /* Allocate the problem specific data. */
439 NULL
, /* Reset global information. */
440 df_scan_free_bb_info
, /* Free basic block info. */
441 NULL
, /* Local compute function. */
442 NULL
, /* Init the solution specific data. */
443 NULL
, /* Iterative solver. */
444 NULL
, /* Confluence operator 0. */
445 NULL
, /* Confluence operator n. */
446 NULL
, /* Transfer function. */
447 NULL
, /* Finalize function. */
448 df_scan_free
, /* Free all of the problem information. */
449 NULL
, /* Remove this problem from the stack of dataflow problems. */
450 df_scan_start_dump
, /* Debugging. */
451 df_scan_start_block
, /* Debugging start block. */
452 NULL
, /* Debugging end block. */
453 NULL
, /* Debugging start insn. */
454 NULL
, /* Debugging end insn. */
455 NULL
, /* Incremental solution verify start. */
456 NULL
, /* Incremental solution verify end. */
457 NULL
, /* Dependent problem. */
458 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
459 TV_DF_SCAN
, /* Timing variable. */
460 false /* Reset blocks on dropping out of blocks_to_analyze. */
464 /* Create a new DATAFLOW instance and add it to an existing instance
465 of DF. The returned structure is what is used to get at the
469 df_scan_add_problem (void)
471 df_add_problem (&problem_SCAN
);
475 /*----------------------------------------------------------------------------
476 Storage Allocation Utilities
477 ----------------------------------------------------------------------------*/
480 /* First, grow the reg_info information. If the current size is less than
481 the number of pseudos, grow to 25% more than the number of
484 Second, assure that all of the slots up to max_reg_num have been
485 filled with reg_info structures. */
488 df_grow_reg_info (void)
490 unsigned int max_reg
= max_reg_num ();
491 unsigned int new_size
= max_reg
;
492 struct df_scan_problem_data
*problem_data
493 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
496 if (df
->regs_size
< new_size
)
498 new_size
+= new_size
/ 4;
499 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
500 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
501 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
503 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
504 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
505 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
506 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
507 df
->regs_size
= new_size
;
510 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
512 struct df_reg_info
*reg_info
;
514 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
515 memset (reg_info
, 0, sizeof (struct df_reg_info
));
516 df
->def_regs
[i
] = reg_info
;
517 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
518 memset (reg_info
, 0, sizeof (struct df_reg_info
));
519 df
->use_regs
[i
] = reg_info
;
520 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
521 memset (reg_info
, 0, sizeof (struct df_reg_info
));
522 df
->eq_use_regs
[i
] = reg_info
;
523 df
->def_info
.begin
[i
] = 0;
524 df
->def_info
.count
[i
] = 0;
525 df
->use_info
.begin
[i
] = 0;
526 df
->use_info
.count
[i
] = 0;
529 df
->regs_inited
= max_reg
;
533 /* Grow the ref information. */
536 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
538 if (ref_info
->refs_size
< new_size
)
540 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
541 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
542 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
543 ref_info
->refs_size
= new_size
;
548 /* Check and grow the ref information if necessary. This routine
549 guarantees total_size + BITMAP_ADDEND amount of entries in refs
550 array. It updates ref_info->refs_size only and does not change
551 ref_info->total_size. */
554 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
555 unsigned bitmap_addend
)
557 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
559 int new_size
= ref_info
->total_size
+ bitmap_addend
;
560 new_size
+= ref_info
->total_size
/ 4;
561 df_grow_ref_info (ref_info
, new_size
);
566 /* Grow the ref information. If the current size is less than the
567 number of instructions, grow to 25% more than the number of
571 df_grow_insn_info (void)
573 unsigned int new_size
= get_max_uid () + 1;
574 if (DF_INSN_SIZE () < new_size
)
576 new_size
+= new_size
/ 4;
577 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
578 memset (df
->insns
+ df
->insns_size
, 0,
579 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
580 DF_INSN_SIZE () = new_size
;
587 /*----------------------------------------------------------------------------
588 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
589 ----------------------------------------------------------------------------*/
591 /* Rescan all of the block_to_analyze or all of the blocks in the
592 function if df_set_blocks if blocks_to_analyze is NULL; */
595 df_scan_blocks (void)
599 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
600 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
602 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
603 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
605 bitmap_ior_into (&df
->eh_block_artificial_uses
,
606 &df
->regular_block_artificial_uses
);
608 /* ENTRY and EXIT blocks have special defs/uses. */
609 df_get_entry_block_def_set (df
->entry_block_defs
);
610 df_record_entry_block_defs (df
->entry_block_defs
);
611 df_get_exit_block_use_set (df
->exit_block_uses
);
612 df_record_exit_block_uses (df
->exit_block_uses
);
613 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
614 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
617 FOR_EACH_BB_FN (bb
, cfun
)
619 unsigned int bb_index
= bb
->index
;
620 df_bb_refs_record (bb_index
, true);
624 /* Create new refs under address LOC within INSN. This function is
625 only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
626 depending on whether LOC is inside PATTERN (INSN) or a note. */
629 df_uses_create (rtx
*loc
, rtx insn
, int ref_flags
)
631 gcc_assert (!(ref_flags
& ~DF_REF_IN_NOTE
));
632 df_uses_record (NULL
, loc
, DF_REF_REG_USE
,
633 BLOCK_FOR_INSN (insn
),
634 DF_INSN_INFO_GET (insn
),
639 df_install_ref_incremental (df_ref ref
)
641 struct df_reg_info
**reg_info
;
642 struct df_ref_info
*ref_info
;
646 rtx_insn
*insn
= DF_REF_INSN (ref
);
647 basic_block bb
= BLOCK_FOR_INSN (insn
);
649 if (DF_REF_REG_DEF_P (ref
))
651 reg_info
= df
->def_regs
;
652 ref_info
= &df
->def_info
;
653 ref_ptr
= &DF_INSN_DEFS (insn
);
654 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
656 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
658 reg_info
= df
->eq_use_regs
;
659 ref_info
= &df
->use_info
;
660 ref_ptr
= &DF_INSN_EQ_USES (insn
);
661 switch (ref_info
->ref_order
)
663 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
664 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
665 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
669 add_to_table
= false;
675 reg_info
= df
->use_regs
;
676 ref_info
= &df
->use_info
;
677 ref_ptr
= &DF_INSN_USES (insn
);
678 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
681 /* Do not add if ref is not in the right blocks. */
682 if (add_to_table
&& df
->analyze_subset
)
683 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
685 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
688 switch (ref_info
->ref_order
)
690 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
691 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
692 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
693 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
696 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
700 while (*ref_ptr
&& df_ref_compare (*ref_ptr
, ref
) < 0)
701 ref_ptr
= &DF_REF_NEXT_LOC (*ref_ptr
);
703 DF_REF_NEXT_LOC (ref
) = *ref_ptr
;
709 fprintf (dump_file
, "adding ref ");
710 df_ref_debug (ref
, dump_file
);
713 /* By adding the ref directly, df_insn_rescan my not find any
714 differences even though the block will have changed. So we need
715 to mark the block dirty ourselves. */
716 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
717 df_set_bb_dirty (bb
);
722 /*----------------------------------------------------------------------------
723 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
724 ----------------------------------------------------------------------------*/
727 df_free_ref (df_ref ref
)
729 struct df_scan_problem_data
*problem_data
730 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
732 switch (DF_REF_CLASS (ref
))
735 pool_free (problem_data
->ref_base_pool
, ref
);
738 case DF_REF_ARTIFICIAL
:
739 pool_free (problem_data
->ref_artificial_pool
, ref
);
743 pool_free (problem_data
->ref_regular_pool
, 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
)
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
= (struct df_insn_info
*) pool_alloc (problem_data
->insn_pool
);
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 pool_free (problem_data
->mw_reg_pool
, 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 pool_free (problem_data
->insn_pool
, 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
)
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 pool_free (problem_data
->mw_reg_pool
, 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
)
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
)
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
, 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 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 all refs that contained LOC from OLD_REGNO to
1900 NEW_REGNO. Refs that do not match LOC are not changed which means
1901 that artificial refs are not changed since they have no loc. This
1902 call is to support the SET_REGNO macro. */
1905 df_ref_change_reg_with_loc (int old_regno
, int new_regno
, rtx loc
)
1907 if ((!df
) || (old_regno
== -1) || (old_regno
== new_regno
))
1910 df_grow_reg_info ();
1912 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
1913 DF_REG_DEF_GET (new_regno
), new_regno
, loc
);
1914 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
1915 DF_REG_USE_GET (new_regno
), new_regno
, loc
);
1916 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
1917 DF_REG_EQ_USE_GET (new_regno
), new_regno
, loc
);
1921 /* Delete the mw_hardregs that point into the eq_notes. */
1924 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
1926 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
;
1927 struct df_scan_problem_data
*problem_data
1928 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1932 df_mw_hardreg
*mw
= *mw_ptr
;
1933 if (mw
->flags
& DF_REF_IN_NOTE
)
1935 *mw_ptr
= DF_MWS_NEXT (mw
);
1936 pool_free (problem_data
->mw_reg_pool
, mw
);
1939 mw_ptr
= &DF_MWS_NEXT (mw
);
1944 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
1947 df_notes_rescan (rtx insn
)
1949 struct df_insn_info
*insn_info
;
1950 unsigned int uid
= INSN_UID (insn
);
1955 /* The client has disabled rescanning and plans to do it itself. */
1956 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1959 /* Do nothing if the insn hasn't been emitted yet. */
1960 if (!BLOCK_FOR_INSN (insn
))
1963 df_grow_bb_info (df_scan
);
1964 df_grow_reg_info ();
1966 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1968 /* The client has deferred rescanning. */
1969 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1973 insn_info
= df_insn_create_insn_record (insn
);
1974 insn_info
->defs
= 0;
1975 insn_info
->uses
= 0;
1976 insn_info
->eq_uses
= 0;
1977 insn_info
->mw_hardregs
= 0;
1980 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1981 /* If the insn is set to be rescanned, it does not need to also
1982 be notes rescanned. */
1983 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
1984 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
1988 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1989 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1993 basic_block bb
= BLOCK_FOR_INSN (insn
);
1995 struct df_collection_rec collection_rec
;
1998 df_mw_hardreg_chain_delete_eq_uses (insn_info
);
1999 df_ref_chain_delete (insn_info
->eq_uses
);
2000 insn_info
->eq_uses
= NULL
;
2002 /* Process REG_EQUIV/REG_EQUAL notes */
2003 for (note
= REG_NOTES (insn
); note
;
2004 note
= XEXP (note
, 1))
2006 switch (REG_NOTE_KIND (note
))
2010 df_uses_record (&collection_rec
,
2011 &XEXP (note
, 0), DF_REF_REG_USE
,
2012 bb
, insn_info
, DF_REF_IN_NOTE
);
2018 /* Find some place to put any new mw_hardregs. */
2019 df_canonize_collection_rec (&collection_rec
);
2020 struct df_mw_hardreg
**mw_ptr
= &insn_info
->mw_hardregs
, *mw
;
2021 FOR_EACH_VEC_ELT (collection_rec
.mw_vec
, i
, mw
)
2023 while (*mw_ptr
&& df_mw_compare (*mw_ptr
, mw
) < 0)
2024 mw_ptr
= &DF_MWS_NEXT (*mw_ptr
);
2025 DF_MWS_NEXT (mw
) = *mw_ptr
;
2027 mw_ptr
= &DF_MWS_NEXT (mw
);
2029 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_eq_uses
);
2032 df_insn_rescan (insn
);
2037 /*----------------------------------------------------------------------------
2038 Hard core instruction scanning code. No external interfaces here,
2039 just a lot of routines that look inside insns.
2040 ----------------------------------------------------------------------------*/
2043 /* Return true if the contents of two df_ref's are identical.
2044 It ignores DF_REF_MARKER. */
2047 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2055 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2056 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2057 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2058 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2059 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2060 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2061 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2062 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2065 switch (DF_REF_CLASS (ref1
))
2067 case DF_REF_ARTIFICIAL
:
2071 case DF_REF_REGULAR
:
2072 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2081 /* Compare REF1 and REF2 for sorting. This is only called from places
2082 where all of the refs are of the same type, in the same insn, and
2083 have the same bb. So these fields are not checked. */
2086 df_ref_compare (df_ref ref1
, df_ref ref2
)
2088 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2089 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2091 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2092 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2094 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2095 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2097 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2098 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2100 /* Cannot look at the LOC field on artificial refs. */
2101 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2102 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2103 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2105 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2107 /* If two refs are identical except that one of them has is from
2108 a mw and one is not, we need to have the one with the mw
2110 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2111 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2112 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2113 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2119 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2122 /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2. */
2125 df_ref_ptr_compare (const void *r1
, const void *r2
)
2127 return df_ref_compare (*(const df_ref
*) r1
, *(const df_ref
*) r2
);
2131 df_swap_refs (vec
<df_ref
, va_heap
> *ref_vec
, int i
, int j
)
2133 df_ref tmp
= (*ref_vec
)[i
];
2134 (*ref_vec
)[i
] = (*ref_vec
)[j
];
2135 (*ref_vec
)[j
] = tmp
;
2138 /* Sort and compress a set of refs. */
2141 df_sort_and_compress_refs (vec
<df_ref
, va_heap
> *ref_vec
)
2145 unsigned int dist
= 0;
2147 count
= ref_vec
->length ();
2149 /* If there are 1 or 0 elements, there is nothing to do. */
2152 else if (count
== 2)
2154 df_ref r0
= (*ref_vec
)[0];
2155 df_ref r1
= (*ref_vec
)[1];
2156 if (df_ref_compare (r0
, r1
) > 0)
2157 df_swap_refs (ref_vec
, 0, 1);
2161 for (i
= 0; i
< count
- 1; i
++)
2163 df_ref r0
= (*ref_vec
)[i
];
2164 df_ref r1
= (*ref_vec
)[i
+ 1];
2165 if (df_ref_compare (r0
, r1
) >= 0)
2168 /* If the array is already strictly ordered,
2169 which is the most common case for large COUNT case
2170 (which happens for CALL INSNs),
2171 no need to sort and filter out duplicate.
2172 Simply return the count.
2173 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2174 of DF_REF_COMPARE. */
2177 ref_vec
->qsort (df_ref_ptr_compare
);
2180 for (i
=0; i
<count
-dist
; i
++)
2182 /* Find the next ref that is not equal to the current ref. */
2183 while (i
+ dist
+ 1 < count
2184 && df_ref_equal_p ((*ref_vec
)[i
],
2185 (*ref_vec
)[i
+ dist
+ 1]))
2187 df_free_ref ((*ref_vec
)[i
+ dist
+ 1]);
2190 /* Copy it down to the next position. */
2191 if (dist
&& i
+ dist
+ 1 < count
)
2192 (*ref_vec
)[i
+ 1] = (*ref_vec
)[i
+ dist
+ 1];
2196 ref_vec
->truncate (count
);
2200 /* Return true if the contents of two df_ref's are identical.
2201 It ignores DF_REF_MARKER. */
2204 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2208 return (mw1
== mw2
) ||
2209 (mw1
->mw_reg
== mw2
->mw_reg
2210 && mw1
->type
== mw2
->type
2211 && mw1
->flags
== mw2
->flags
2212 && mw1
->start_regno
== mw2
->start_regno
2213 && mw1
->end_regno
== mw2
->end_regno
);
2217 /* Compare MW1 and MW2 for sorting. */
2220 df_mw_compare (const df_mw_hardreg
*mw1
, const df_mw_hardreg
*mw2
)
2222 if (mw1
->type
!= mw2
->type
)
2223 return mw1
->type
- mw2
->type
;
2225 if (mw1
->flags
!= mw2
->flags
)
2226 return mw1
->flags
- mw2
->flags
;
2228 if (mw1
->start_regno
!= mw2
->start_regno
)
2229 return mw1
->start_regno
- mw2
->start_regno
;
2231 if (mw1
->end_regno
!= mw2
->end_regno
)
2232 return mw1
->end_regno
- mw2
->end_regno
;
2234 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2235 return mw1
->mw_order
- mw2
->mw_order
;
2240 /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2. */
2243 df_mw_ptr_compare (const void *m1
, const void *m2
)
2245 return df_mw_compare (*(const df_mw_hardreg
*const *) m1
,
2246 *(const df_mw_hardreg
*const *) m2
);
2249 /* Sort and compress a set of refs. */
2252 df_sort_and_compress_mws (vec
<df_mw_hardreg_ptr
, va_heap
> *mw_vec
)
2255 struct df_scan_problem_data
*problem_data
2256 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2258 unsigned int dist
= 0;
2260 count
= mw_vec
->length ();
2263 else if (count
== 2)
2265 struct df_mw_hardreg
*m0
= (*mw_vec
)[0];
2266 struct df_mw_hardreg
*m1
= (*mw_vec
)[1];
2267 if (df_mw_compare (m0
, m1
) > 0)
2269 struct df_mw_hardreg
*tmp
= (*mw_vec
)[0];
2270 (*mw_vec
)[0] = (*mw_vec
)[1];
2275 mw_vec
->qsort (df_mw_ptr_compare
);
2277 for (i
=0; i
<count
-dist
; i
++)
2279 /* Find the next ref that is not equal to the current ref. */
2280 while (i
+ dist
+ 1 < count
2281 && df_mw_equal_p ((*mw_vec
)[i
], (*mw_vec
)[i
+ dist
+ 1]))
2283 pool_free (problem_data
->mw_reg_pool
,
2284 (*mw_vec
)[i
+ dist
+ 1]);
2287 /* Copy it down to the next position. */
2288 if (dist
&& i
+ dist
+ 1 < count
)
2289 (*mw_vec
)[i
+ 1] = (*mw_vec
)[i
+ dist
+ 1];
2293 mw_vec
->truncate (count
);
2297 /* Sort and remove duplicates from the COLLECTION_REC. */
2300 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2302 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2303 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2304 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2305 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2309 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2312 df_install_ref (df_ref this_ref
,
2313 struct df_reg_info
*reg_info
,
2314 struct df_ref_info
*ref_info
,
2317 unsigned int regno
= DF_REF_REGNO (this_ref
);
2318 /* Add the ref to the reg_{def,use,eq_use} chain. */
2319 df_ref head
= reg_info
->reg_chain
;
2321 reg_info
->reg_chain
= this_ref
;
2324 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2326 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2327 df
->hard_regs_live_count
[regno
]++;
2330 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2331 && DF_REF_PREV_REG (this_ref
) == NULL
);
2333 DF_REF_NEXT_REG (this_ref
) = head
;
2335 /* We cannot actually link to the head of the chain. */
2336 DF_REF_PREV_REG (this_ref
) = NULL
;
2339 DF_REF_PREV_REG (head
) = this_ref
;
2343 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2344 df_check_and_grow_ref_info (ref_info
, 1);
2345 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2346 /* Add the ref to the big array of defs. */
2347 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2348 ref_info
->table_size
++;
2351 DF_REF_ID (this_ref
) = -1;
2353 ref_info
->total_size
++;
2357 /* This function takes one of the groups of refs (defs, uses or
2358 eq_uses) and installs the entire group into the insn. It also adds
2359 each of these refs into the appropriate chains. */
2362 df_install_refs (basic_block bb
,
2363 const vec
<df_ref
, va_heap
> *old_vec
,
2364 struct df_reg_info
**reg_info
,
2365 struct df_ref_info
*ref_info
,
2368 unsigned int count
= old_vec
->length ();
2375 switch (ref_info
->ref_order
)
2377 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2378 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2379 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2380 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2381 add_to_table
= true;
2383 case DF_REF_ORDER_UNORDERED
:
2384 case DF_REF_ORDER_BY_REG
:
2385 case DF_REF_ORDER_BY_INSN
:
2386 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2387 add_to_table
= !is_notes
;
2390 add_to_table
= false;
2394 /* Do not add if ref is not in the right blocks. */
2395 if (add_to_table
&& df
->analyze_subset
)
2396 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2398 FOR_EACH_VEC_ELT (*old_vec
, ix
, this_ref
)
2400 DF_REF_NEXT_LOC (this_ref
) = (ix
+ 1 < old_vec
->length ()
2401 ? (*old_vec
)[ix
+ 1]
2403 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2404 ref_info
, add_to_table
);
2406 return (*old_vec
)[0];
2413 /* This function takes the mws installs the entire group into the
2416 static struct df_mw_hardreg
*
2417 df_install_mws (const vec
<df_mw_hardreg_ptr
, va_heap
> *old_vec
)
2419 unsigned int count
= old_vec
->length ();
2422 for (unsigned int i
= 0; i
< count
- 1; i
++)
2423 DF_MWS_NEXT ((*old_vec
)[i
]) = (*old_vec
)[i
+ 1];
2424 DF_MWS_NEXT ((*old_vec
)[count
- 1]) = 0;
2425 return (*old_vec
)[0];
2432 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2433 chains and update other necessary information. */
2436 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2437 basic_block bb
, rtx insn
, unsigned int flags
)
2441 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2442 /* If there is a vector in the collection rec, add it to the
2443 insn. A null rec is a signal that the caller will handle the
2445 if (flags
& copy_defs
)
2447 gcc_checking_assert (!insn_rec
->defs
);
2449 = df_install_refs (bb
, &collection_rec
->def_vec
,
2451 &df
->def_info
, false);
2453 if (flags
& copy_uses
)
2455 gcc_checking_assert (!insn_rec
->uses
);
2457 = df_install_refs (bb
, &collection_rec
->use_vec
,
2459 &df
->use_info
, false);
2461 if (flags
& copy_eq_uses
)
2463 gcc_checking_assert (!insn_rec
->eq_uses
);
2465 = df_install_refs (bb
, &collection_rec
->eq_use_vec
,
2467 &df
->use_info
, true);
2469 if (flags
& copy_mw
)
2471 gcc_checking_assert (!insn_rec
->mw_hardregs
);
2472 insn_rec
->mw_hardregs
2473 = df_install_mws (&collection_rec
->mw_vec
);
2478 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2480 gcc_checking_assert (!bb_info
->artificial_defs
);
2481 bb_info
->artificial_defs
2482 = df_install_refs (bb
, &collection_rec
->def_vec
,
2484 &df
->def_info
, false);
2485 gcc_checking_assert (!bb_info
->artificial_uses
);
2486 bb_info
->artificial_uses
2487 = df_install_refs (bb
, &collection_rec
->use_vec
,
2489 &df
->use_info
, false);
2494 /* Allocate a ref and initialize its fields. */
2497 df_ref_create_structure (enum df_ref_class cl
,
2498 struct df_collection_rec
*collection_rec
,
2500 basic_block bb
, struct df_insn_info
*info
,
2501 enum df_ref_type ref_type
,
2504 df_ref this_ref
= NULL
;
2505 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2506 struct df_scan_problem_data
*problem_data
2507 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2512 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_base_pool
);
2513 gcc_checking_assert (loc
== NULL
);
2516 case DF_REF_ARTIFICIAL
:
2517 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_artificial_pool
);
2518 this_ref
->artificial_ref
.bb
= bb
;
2519 gcc_checking_assert (loc
== NULL
);
2522 case DF_REF_REGULAR
:
2523 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_regular_pool
);
2524 this_ref
->regular_ref
.loc
= loc
;
2525 gcc_checking_assert (loc
);
2529 DF_REF_CLASS (this_ref
) = cl
;
2530 DF_REF_ID (this_ref
) = -1;
2531 DF_REF_REG (this_ref
) = reg
;
2532 DF_REF_REGNO (this_ref
) = regno
;
2533 DF_REF_TYPE (this_ref
) = ref_type
;
2534 DF_REF_INSN_INFO (this_ref
) = info
;
2535 DF_REF_CHAIN (this_ref
) = NULL
;
2536 DF_REF_FLAGS (this_ref
) = ref_flags
;
2537 DF_REF_NEXT_REG (this_ref
) = NULL
;
2538 DF_REF_PREV_REG (this_ref
) = NULL
;
2539 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2541 /* We need to clear this bit because fwprop, and in the future
2542 possibly other optimizations sometimes create new refs using ond
2543 refs as the model. */
2544 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2546 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2547 if (regno
< FIRST_PSEUDO_REGISTER
2548 && !DF_REF_IS_ARTIFICIAL (this_ref
)
2549 && !DEBUG_INSN_P (DF_REF_INSN (this_ref
)))
2551 if (DF_REF_REG_DEF_P (this_ref
))
2553 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2554 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2556 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2557 && (regno
== FRAME_POINTER_REGNUM
2558 || regno
== ARG_POINTER_REGNUM
)))
2559 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2564 if (DF_REF_REG_DEF_P (this_ref
))
2565 collection_rec
->def_vec
.safe_push (this_ref
);
2566 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2567 collection_rec
->eq_use_vec
.safe_push (this_ref
);
2569 collection_rec
->use_vec
.safe_push (this_ref
);
2572 df_install_ref_incremental (this_ref
);
2578 /* Create new references of type DF_REF_TYPE for each part of register REG
2579 at address LOC within INSN of BB. */
2583 df_ref_record (enum df_ref_class cl
,
2584 struct df_collection_rec
*collection_rec
,
2586 basic_block bb
, struct df_insn_info
*insn_info
,
2587 enum df_ref_type ref_type
,
2592 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2594 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2595 if (regno
< FIRST_PSEUDO_REGISTER
)
2597 struct df_mw_hardreg
*hardreg
= NULL
;
2598 struct df_scan_problem_data
*problem_data
2599 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2601 unsigned int endregno
;
2604 if (GET_CODE (reg
) == SUBREG
)
2606 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2607 SUBREG_BYTE (reg
), GET_MODE (reg
));
2608 endregno
= regno
+ subreg_nregs (reg
);
2611 endregno
= END_HARD_REGNO (reg
);
2613 /* If this is a multiword hardreg, we create some extra
2614 datastructures that will enable us to easily build REG_DEAD
2615 and REG_UNUSED notes. */
2617 && (endregno
!= regno
+ 1) && insn_info
)
2619 /* Sets to a subreg of a multiword register are partial.
2620 Sets to a non-subreg of a multiword register are not. */
2621 if (GET_CODE (reg
) == SUBREG
)
2622 ref_flags
|= DF_REF_PARTIAL
;
2623 ref_flags
|= DF_REF_MW_HARDREG
;
2625 hardreg
= (struct df_mw_hardreg
*) pool_alloc (problem_data
->mw_reg_pool
);
2626 hardreg
->type
= ref_type
;
2627 hardreg
->flags
= ref_flags
;
2628 hardreg
->mw_reg
= reg
;
2629 hardreg
->start_regno
= regno
;
2630 hardreg
->end_regno
= endregno
- 1;
2631 hardreg
->mw_order
= df
->ref_order
++;
2632 collection_rec
->mw_vec
.safe_push (hardreg
);
2635 for (i
= regno
; i
< endregno
; i
++)
2637 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2638 bb
, insn_info
, ref_type
, ref_flags
);
2640 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2645 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2646 ref_type
, ref_flags
);
2651 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2652 covered by the outer mode is smaller than that covered by the inner mode,
2653 is a read-modify-write operation.
2654 This function returns true iff the SUBREG X is such a SUBREG. */
2657 df_read_modify_subreg_p (rtx x
)
2659 unsigned int isize
, osize
;
2660 if (GET_CODE (x
) != SUBREG
)
2662 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2663 osize
= GET_MODE_SIZE (GET_MODE (x
));
2664 return isize
> osize
2665 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2669 /* Process all the registers defined in the rtx pointed by LOC.
2670 Autoincrement/decrement definitions will be picked up by df_uses_record.
2671 Any change here has to be matched in df_find_hard_reg_defs_1. */
2674 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2675 rtx
*loc
, basic_block bb
, struct df_insn_info
*insn_info
,
2680 /* It is legal to have a set destination be a parallel. */
2681 if (GET_CODE (dst
) == PARALLEL
)
2684 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2686 rtx temp
= XVECEXP (dst
, 0, i
);
2687 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2688 df_def_record_1 (collection_rec
, &XEXP (temp
, 0),
2689 bb
, insn_info
, flags
);
2694 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2696 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2698 loc
= &XEXP (dst
, 0);
2702 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2704 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2706 loc
= &XEXP (dst
, 0);
2710 /* At this point if we do not have a reg or a subreg, just return. */
2713 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2714 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2716 /* We want to keep sp alive everywhere - by making all
2717 writes to sp also use of sp. */
2718 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2719 df_ref_record (DF_REF_BASE
, collection_rec
,
2720 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
2722 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2724 if (df_read_modify_subreg_p (dst
))
2725 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2727 flags
|= DF_REF_SUBREG
;
2729 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2730 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2735 /* Process all the registers defined in the pattern rtx, X. Any change
2736 here has to be matched in df_find_hard_reg_defs. */
2739 df_defs_record (struct df_collection_rec
*collection_rec
,
2740 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2743 RTX_CODE code
= GET_CODE (x
);
2749 df_def_record_1 (collection_rec
, &SET_DEST (x
), bb
, insn_info
, flags
);
2753 flags
|= DF_REF_MUST_CLOBBER
;
2754 df_def_record_1 (collection_rec
, &XEXP (x
, 0), bb
, insn_info
, flags
);
2758 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
2759 bb
, insn_info
, DF_REF_CONDITIONAL
);
2763 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2764 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
),
2765 bb
, insn_info
, flags
);
2768 /* No DEFs to record in other cases */
2773 /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
2774 destination of a set or clobber. This has to match the logic in
2775 df_defs_record_1. */
2778 df_find_hard_reg_defs_1 (rtx dst
, HARD_REG_SET
*defs
)
2780 /* It is legal to have a set destination be a parallel. */
2781 if (GET_CODE (dst
) == PARALLEL
)
2784 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2786 rtx temp
= XVECEXP (dst
, 0, i
);
2787 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2788 df_find_hard_reg_defs_1 (XEXP (temp
, 0), defs
);
2793 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2794 dst
= XEXP (dst
, 0);
2796 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2797 dst
= XEXP (dst
, 0);
2799 /* At this point if we do not have a reg or a subreg, just return. */
2800 if (REG_P (dst
) && HARD_REGISTER_P (dst
))
2801 SET_HARD_REG_BIT (*defs
, REGNO (dst
));
2802 else if (GET_CODE (dst
) == SUBREG
2803 && REG_P (SUBREG_REG (dst
)) && HARD_REGISTER_P (dst
))
2804 SET_HARD_REG_BIT (*defs
, REGNO (SUBREG_REG (dst
)));
2807 /* Set bits in *DEFS for hard registers defined in the pattern X. This
2808 has to match the logic in df_defs_record. */
2811 df_find_hard_reg_defs (rtx x
, HARD_REG_SET
*defs
)
2813 RTX_CODE code
= GET_CODE (x
);
2819 df_find_hard_reg_defs_1 (SET_DEST (x
), defs
);
2823 df_find_hard_reg_defs_1 (XEXP (x
, 0), defs
);
2827 df_find_hard_reg_defs (COND_EXEC_CODE (x
), defs
);
2831 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2832 df_find_hard_reg_defs (XVECEXP (x
, 0, i
), defs
);
2835 /* No DEFs to record in other cases */
2841 /* Process all the registers used in the rtx at address LOC. */
2844 df_uses_record (struct df_collection_rec
*collection_rec
,
2845 rtx
*loc
, enum df_ref_type ref_type
,
2846 basic_block bb
, struct df_insn_info
*insn_info
,
2856 code
= GET_CODE (x
);
2870 /* If we are clobbering a MEM, mark any registers inside the address
2872 if (MEM_P (XEXP (x
, 0)))
2873 df_uses_record (collection_rec
,
2874 &XEXP (XEXP (x
, 0), 0),
2875 DF_REF_REG_MEM_STORE
,
2879 /* If we're clobbering a REG then we have a def so ignore. */
2883 df_uses_record (collection_rec
,
2884 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
2885 bb
, insn_info
, flags
& DF_REF_IN_NOTE
);
2889 /* While we're here, optimize this case. */
2890 flags
|= DF_REF_PARTIAL
;
2891 /* In case the SUBREG is not of a REG, do not optimize. */
2892 if (!REG_P (SUBREG_REG (x
)))
2894 loc
= &SUBREG_REG (x
);
2895 df_uses_record (collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
);
2898 /* ... Fall through ... */
2901 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2902 x
, loc
, bb
, insn_info
,
2909 df_uses_record (collection_rec
,
2910 &XEXP (x
, 1), ref_type
, bb
, insn_info
, flags
);
2911 df_uses_record (collection_rec
,
2912 &XEXP (x
, 2), ref_type
, bb
, insn_info
, flags
);
2914 /* If the parameters to the zero or sign extract are
2915 constants, strip them off and recurse, otherwise there is
2916 no information that we can gain from this operation. */
2917 if (code
== ZERO_EXTRACT
)
2918 flags
|= DF_REF_ZERO_EXTRACT
;
2920 flags
|= DF_REF_SIGN_EXTRACT
;
2922 df_uses_record (collection_rec
,
2923 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
);
2930 rtx dst
= SET_DEST (x
);
2931 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
2932 df_uses_record (collection_rec
,
2933 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
);
2935 switch (GET_CODE (dst
))
2938 if (df_read_modify_subreg_p (dst
))
2940 df_uses_record (collection_rec
, &SUBREG_REG (dst
),
2941 DF_REF_REG_USE
, bb
, insn_info
,
2942 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
);
2953 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2954 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
);
2956 case STRICT_LOW_PART
:
2958 rtx
*temp
= &XEXP (dst
, 0);
2959 /* A strict_low_part uses the whole REG and not just the
2961 dst
= XEXP (dst
, 0);
2962 df_uses_record (collection_rec
,
2963 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
2964 DF_REF_REG_USE
, bb
, insn_info
,
2965 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
);
2970 df_uses_record (collection_rec
, &XEXP (dst
, 1),
2971 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2972 df_uses_record (collection_rec
, &XEXP (dst
, 2),
2973 DF_REF_REG_USE
, bb
, insn_info
, flags
);
2974 if (GET_CODE (XEXP (dst
,0)) == MEM
)
2975 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2976 DF_REF_REG_USE
, bb
, insn_info
,
2979 df_uses_record (collection_rec
, &XEXP (dst
, 0),
2980 DF_REF_REG_USE
, bb
, insn_info
,
2981 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
);
2996 case UNSPEC_VOLATILE
:
3000 /* Traditional and volatile asm instructions must be
3001 considered to use and clobber all hard registers, all
3002 pseudo-registers and all of memory. So must TRAP_IF and
3003 UNSPEC_VOLATILE operations.
3005 Consider for instance a volatile asm that changes the fpu
3006 rounding mode. An insn should not be moved across this
3007 even if it only uses pseudo-regs because it might give an
3008 incorrectly rounded result.
3010 However, flow.c's liveness computation did *not* do this,
3011 giving the reasoning as " ?!? Unfortunately, marking all
3012 hard registers as live causes massive problems for the
3013 register allocator and marking all pseudos as live creates
3014 mountains of uninitialized variable warnings."
3016 In order to maintain the status quo with regard to liveness
3017 and uses, we do what flow.c did and just mark any regs we
3018 can find in ASM_OPERANDS as used. In global asm insns are
3019 scanned and regs_asm_clobbered is filled out.
3021 For all ASM_OPERANDS, we must traverse the vector of input
3022 operands. We can not just fall through here since then we
3023 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3024 which do not indicate traditional asms unlike their normal
3026 if (code
== ASM_OPERANDS
)
3030 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3031 df_uses_record (collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3032 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3039 df_uses_record (collection_rec
,
3040 &PAT_VAR_LOCATION_LOC (x
),
3041 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3050 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3051 /* Catch the def of the register being modified. */
3052 df_ref_record (DF_REF_REGULAR
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3055 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
);
3057 /* ... Fall through to handle uses ... */
3063 /* Recursively scan the operands of this expression. */
3065 const char *fmt
= GET_RTX_FORMAT (code
);
3068 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3072 /* Tail recursive case: save a function call level. */
3078 df_uses_record (collection_rec
, &XEXP (x
, i
), ref_type
,
3079 bb
, insn_info
, flags
);
3081 else if (fmt
[i
] == 'E')
3084 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3085 df_uses_record (collection_rec
,
3086 &XVECEXP (x
, i
, j
), ref_type
,
3087 bb
, insn_info
, flags
);
3096 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3099 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3104 FOR_EACH_VEC_ELT (collection_rec
->def_vec
, ix
, ref
)
3106 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3110 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3111 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3112 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3113 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
);
3114 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3120 /* Get call's extra defs and uses (track caller-saved registers). */
3123 df_get_call_refs (struct df_collection_rec
*collection_rec
,
3125 struct df_insn_info
*insn_info
,
3129 bool is_sibling_call
;
3131 HARD_REG_SET defs_generated
;
3132 HARD_REG_SET fn_reg_set_usage
;
3134 CLEAR_HARD_REG_SET (defs_generated
);
3135 df_find_hard_reg_defs (PATTERN (insn_info
->insn
), &defs_generated
);
3136 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3137 get_call_reg_set_usage (insn_info
->insn
, &fn_reg_set_usage
,
3138 regs_invalidated_by_call
);
3140 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3142 if (i
== STACK_POINTER_REGNUM
)
3143 /* The stack ptr is used (honorarily) by a CALL insn. */
3144 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3145 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3146 DF_REF_CALL_STACK_USAGE
| flags
);
3147 else if (global_regs
[i
])
3149 /* Calls to const functions cannot access any global registers and
3150 calls to pure functions cannot set them. All other calls may
3151 reference any of the global registers, so they are recorded as
3153 if (!RTL_CONST_CALL_P (insn_info
->insn
))
3155 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3156 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
3157 if (!RTL_PURE_CALL_P (insn_info
->insn
))
3158 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3159 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3162 else if (TEST_HARD_REG_BIT (fn_reg_set_usage
, i
)
3163 /* no clobbers for regs that are the result of the call */
3164 && !TEST_HARD_REG_BIT (defs_generated
, i
)
3165 && (!is_sibling_call
3166 || !bitmap_bit_p (df
->exit_block_uses
, i
)
3167 || refers_to_regno_p (i
, i
+1,
3168 crtl
->return_rtx
, NULL
)))
3169 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3170 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3171 DF_REF_MAY_CLOBBER
| flags
);
3174 /* Record the registers used to pass arguments, and explicitly
3175 noted as clobbered. */
3176 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3177 note
= XEXP (note
, 1))
3179 if (GET_CODE (XEXP (note
, 0)) == USE
)
3180 df_uses_record (collection_rec
, &XEXP (XEXP (note
, 0), 0),
3181 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3182 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3184 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3186 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3187 if (!TEST_HARD_REG_BIT (defs_generated
, regno
))
3188 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3192 df_uses_record (collection_rec
, &XEXP (note
, 0),
3193 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3200 /* Collect all refs in the INSN. This function is free of any
3201 side-effect - it will create and return a lists of df_ref's in the
3202 COLLECTION_REC without putting those refs into existing ref chains
3206 df_insn_refs_collect (struct df_collection_rec
*collection_rec
,
3207 basic_block bb
, struct df_insn_info
*insn_info
)
3210 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3212 /* Clear out the collection record. */
3213 collection_rec
->def_vec
.truncate (0);
3214 collection_rec
->use_vec
.truncate (0);
3215 collection_rec
->eq_use_vec
.truncate (0);
3216 collection_rec
->mw_vec
.truncate (0);
3218 /* Process REG_EQUIV/REG_EQUAL notes. */
3219 for (note
= REG_NOTES (insn_info
->insn
); note
;
3220 note
= XEXP (note
, 1))
3222 switch (REG_NOTE_KIND (note
))
3226 df_uses_record (collection_rec
,
3227 &XEXP (note
, 0), DF_REF_REG_USE
,
3228 bb
, insn_info
, DF_REF_IN_NOTE
);
3230 case REG_NON_LOCAL_GOTO
:
3231 /* The frame ptr is used by a non-local goto. */
3232 df_ref_record (DF_REF_BASE
, collection_rec
,
3233 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3234 NULL
, bb
, insn_info
,
3236 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3237 df_ref_record (DF_REF_BASE
, collection_rec
,
3238 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3239 NULL
, bb
, insn_info
,
3248 /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
3249 uses from CALL_INSN_FUNCTION_USAGE. */
3250 if (CALL_P (insn_info
->insn
))
3251 df_get_call_refs (collection_rec
, bb
, insn_info
,
3252 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3254 /* Record other defs. These should be mostly for DF_REF_REGULAR, so
3255 that a qsort on the defs is unnecessary in most cases. */
3256 df_defs_record (collection_rec
,
3257 PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3259 /* Record the register uses. */
3260 df_uses_record (collection_rec
,
3261 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0);
3263 /* DF_REF_CONDITIONAL needs corresponding USES. */
3265 df_get_conditional_uses (collection_rec
);
3267 df_canonize_collection_rec (collection_rec
);
3270 /* Recompute the luids for the insns in BB. */
3273 df_recompute_luids (basic_block bb
)
3278 df_grow_insn_info ();
3280 /* Scan the block an insn at a time from beginning to end. */
3281 FOR_BB_INSNS (bb
, insn
)
3283 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3284 /* Inserting labels does not always trigger the incremental
3288 gcc_assert (!INSN_P (insn
));
3289 insn_info
= df_insn_create_insn_record (insn
);
3292 DF_INSN_INFO_LUID (insn_info
) = luid
;
3299 /* Collect all artificial refs at the block level for BB and add them
3300 to COLLECTION_REC. */
3303 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3305 collection_rec
->def_vec
.truncate (0);
3306 collection_rec
->use_vec
.truncate (0);
3307 collection_rec
->eq_use_vec
.truncate (0);
3308 collection_rec
->mw_vec
.truncate (0);
3310 if (bb
->index
== ENTRY_BLOCK
)
3312 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3315 else if (bb
->index
== EXIT_BLOCK
)
3317 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3321 #ifdef EH_RETURN_DATA_REGNO
3322 if (bb_has_eh_pred (bb
))
3325 /* Mark the registers that will contain data for the handler. */
3328 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3329 if (regno
== INVALID_REGNUM
)
3331 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3332 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3337 /* Add the hard_frame_pointer if this block is the target of a
3339 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3340 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3341 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3343 /* Add the artificial uses. */
3344 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3348 bitmap au
= bb_has_eh_pred (bb
)
3349 ? &df
->eh_block_artificial_uses
3350 : &df
->regular_block_artificial_uses
;
3352 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3354 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3355 bb
, NULL
, DF_REF_REG_USE
, 0);
3359 df_canonize_collection_rec (collection_rec
);
3363 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3366 df_bb_refs_record (int bb_index
, bool scan_insns
)
3368 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3375 df_collection_rec collection_rec
;
3376 df_grow_bb_info (df_scan
);
3378 /* Scan the block an insn at a time from beginning to end. */
3379 FOR_BB_INSNS (bb
, insn
)
3381 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3382 gcc_assert (!insn_info
);
3384 insn_info
= df_insn_create_insn_record (insn
);
3387 /* Record refs within INSN. */
3388 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3389 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3390 df_refs_add_to_chains (&collection_rec
, bb
, insn
, copy_all
);
3392 DF_INSN_INFO_LUID (insn_info
) = luid
;
3395 /* Other block level artificial refs */
3396 df_bb_refs_collect (&collection_rec
, bb
);
3397 df_refs_add_to_chains (&collection_rec
, bb
, NULL
, copy_all
);
3399 /* Now that the block has been processed, set the block as dirty so
3400 LR and LIVE will get it processed. */
3401 df_set_bb_dirty (bb
);
3405 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3409 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3415 bitmap_clear (regular_block_artificial_uses
);
3417 if (reload_completed
)
3419 if (frame_pointer_needed
)
3420 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3423 /* Before reload, there are a few registers that must be forced
3424 live everywhere -- which might not already be the case for
3425 blocks within infinite loops. */
3427 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3429 /* Any reference to any pseudo before reload is a potential
3430 reference of the frame pointer. */
3431 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3433 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3434 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3437 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3438 /* Pseudos with argument area equivalences may require
3439 reloading via the argument pointer. */
3440 if (fixed_regs
[ARG_POINTER_REGNUM
])
3441 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3444 /* Any constant, or pseudo with constant equivalences, may
3445 require reloading from memory using the pic register. */
3446 if (picreg
!= INVALID_REGNUM
3447 && fixed_regs
[picreg
])
3448 bitmap_set_bit (regular_block_artificial_uses
, picreg
);
3450 /* The all-important stack pointer must always be live. */
3451 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3454 /* EH_USES registers are used:
3455 1) at all insns that might throw (calls or with -fnon-call-exceptions
3458 3) to support backtraces and/or debugging, anywhere between their
3459 initialization and where they the saved registers are restored
3460 from them, including the cases where we don't reach the epilogue
3461 (noreturn call or infinite loop). */
3462 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3464 bitmap_set_bit (regular_block_artificial_uses
, i
);
3469 /* Get the artificial use set for an eh block. */
3472 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3474 bitmap_clear (eh_block_artificial_uses
);
3476 /* The following code (down through the arg_pointer setting APPEARS
3477 to be necessary because there is nothing that actually
3478 describes what the exception handling code may actually need
3480 if (reload_completed
)
3482 if (frame_pointer_needed
)
3484 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3485 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3486 bitmap_set_bit (eh_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3489 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3490 if (fixed_regs
[ARG_POINTER_REGNUM
])
3491 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3498 /*----------------------------------------------------------------------------
3499 Specialized hard register scanning functions.
3500 ----------------------------------------------------------------------------*/
3503 /* Mark a register in SET. Hard registers in large modes get all
3504 of their component registers set as well. */
3507 df_mark_reg (rtx reg
, void *vset
)
3509 bitmap set
= (bitmap
) vset
;
3510 int regno
= REGNO (reg
);
3512 gcc_assert (GET_MODE (reg
) != BLKmode
);
3514 if (regno
< FIRST_PSEUDO_REGISTER
)
3516 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3517 bitmap_set_range (set
, regno
, n
);
3520 bitmap_set_bit (set
, regno
);
3524 /* Set the bit for regs that are considered being defined at the entry. */
3527 df_get_entry_block_def_set (bitmap entry_block_defs
)
3532 bitmap_clear (entry_block_defs
);
3534 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3537 bitmap_set_bit (entry_block_defs
, i
);
3538 if (FUNCTION_ARG_REGNO_P (i
))
3539 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3542 /* The always important stack pointer. */
3543 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3545 /* Once the prologue has been generated, all of these registers
3546 should just show up in the first regular block. */
3547 if (HAVE_prologue
&& epilogue_completed
)
3549 /* Defs for the callee saved registers are inserted so that the
3550 pushes have some defining location. */
3551 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3552 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3553 bitmap_set_bit (entry_block_defs
, i
);
3556 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3558 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3560 /* If the function has an incoming STATIC_CHAIN, it has to show up
3561 in the entry def set. */
3562 r
= targetm
.calls
.static_chain (current_function_decl
, true);
3564 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3566 if ((!reload_completed
) || frame_pointer_needed
)
3568 /* Any reference to any pseudo before reload is a potential
3569 reference of the frame pointer. */
3570 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3571 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3572 /* If they are different, also mark the hard frame pointer as live. */
3573 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3574 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3578 /* These registers are live everywhere. */
3579 if (!reload_completed
)
3581 #ifdef PIC_OFFSET_TABLE_REGNUM
3582 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3585 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3586 /* Pseudos with argument area equivalences may require
3587 reloading via the argument pointer. */
3588 if (fixed_regs
[ARG_POINTER_REGNUM
])
3589 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3592 #ifdef PIC_OFFSET_TABLE_REGNUM
3593 /* Any constant, or pseudo with constant equivalences, may
3594 require reloading from memory using the pic register. */
3595 if (picreg
!= INVALID_REGNUM
3596 && fixed_regs
[picreg
])
3597 bitmap_set_bit (entry_block_defs
, picreg
);
3601 #ifdef INCOMING_RETURN_ADDR_RTX
3602 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3603 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3606 targetm
.extra_live_on_entry (entry_block_defs
);
3610 /* Return the (conservative) set of hard registers that are defined on
3611 entry to the function.
3612 It uses df->entry_block_defs to determine which register
3613 reference to include. */
3616 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3617 bitmap entry_block_defs
)
3622 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3624 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3625 ENTRY_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_DEF
, 0);
3628 df_canonize_collection_rec (collection_rec
);
3632 /* Record the (conservative) set of hard registers that are defined on
3633 entry to the function. */
3636 df_record_entry_block_defs (bitmap entry_block_defs
)
3638 struct df_collection_rec collection_rec
;
3639 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3641 /* Process bb_refs chain */
3642 df_refs_add_to_chains (&collection_rec
,
3643 BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
),
3649 /* Update the defs in the entry block. */
3652 df_update_entry_block_defs (void)
3655 bool changed
= false;
3657 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3658 df_get_entry_block_def_set (&refs
);
3659 if (df
->entry_block_defs
)
3661 if (!bitmap_equal_p (df
->entry_block_defs
, &refs
))
3663 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3664 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3665 df_ref_chain_delete (bb_info
->artificial_defs
);
3666 bb_info
->artificial_defs
= NULL
;
3672 struct df_scan_problem_data
*problem_data
3673 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3675 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3681 df_record_entry_block_defs (&refs
);
3682 bitmap_copy (df
->entry_block_defs
, &refs
);
3683 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, ENTRY_BLOCK
));
3685 bitmap_clear (&refs
);
3689 /* Set the bit for regs that are considered being used at the exit. */
3692 df_get_exit_block_use_set (bitmap exit_block_uses
)
3695 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3697 bitmap_clear (exit_block_uses
);
3699 /* Stack pointer is always live at the exit. */
3700 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3702 /* Mark the frame pointer if needed at the end of the function.
3703 If we end up eliminating it, it will be removed from the live
3704 list of each basic block by reload. */
3706 if ((!reload_completed
) || frame_pointer_needed
)
3708 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3709 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3710 /* If they are different, also mark the hard frame pointer as live. */
3711 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3712 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3716 /* Many architectures have a GP register even without flag_pic.
3717 Assume the pic register is not in use, or will be handled by
3718 other means, if it is not fixed. */
3719 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3720 && picreg
!= INVALID_REGNUM
3721 && fixed_regs
[picreg
])
3722 bitmap_set_bit (exit_block_uses
, picreg
);
3724 /* Mark all global registers, and all registers used by the
3725 epilogue as being live at the end of the function since they
3726 may be referenced by our caller. */
3727 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3728 if (global_regs
[i
] || EPILOGUE_USES (i
))
3729 bitmap_set_bit (exit_block_uses
, i
);
3731 if (HAVE_epilogue
&& epilogue_completed
)
3733 /* Mark all call-saved registers that we actually used. */
3734 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3735 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
3736 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3737 bitmap_set_bit (exit_block_uses
, i
);
3740 #ifdef EH_RETURN_DATA_REGNO
3741 /* Mark the registers that will contain data for the handler. */
3742 if (reload_completed
&& crtl
->calls_eh_return
)
3745 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3746 if (regno
== INVALID_REGNUM
)
3748 bitmap_set_bit (exit_block_uses
, regno
);
3752 #ifdef EH_RETURN_STACKADJ_RTX
3753 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3754 && crtl
->calls_eh_return
)
3756 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
3757 if (tmp
&& REG_P (tmp
))
3758 df_mark_reg (tmp
, exit_block_uses
);
3762 #ifdef EH_RETURN_HANDLER_RTX
3763 if ((!HAVE_epilogue
|| ! epilogue_completed
)
3764 && crtl
->calls_eh_return
)
3766 rtx tmp
= EH_RETURN_HANDLER_RTX
;
3767 if (tmp
&& REG_P (tmp
))
3768 df_mark_reg (tmp
, exit_block_uses
);
3772 /* Mark function return value. */
3773 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
3777 /* Return the refs of hard registers that are used in the exit block.
3778 It uses df->exit_block_uses to determine register to include. */
3781 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
3786 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
3787 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3788 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3790 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3791 /* It is deliberate that this is not put in the exit block uses but
3792 I do not know why. */
3793 if (reload_completed
3794 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
3795 && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun
))
3796 && fixed_regs
[ARG_POINTER_REGNUM
])
3797 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
3798 EXIT_BLOCK_PTR_FOR_FN (cfun
), NULL
, DF_REF_REG_USE
, 0);
3801 df_canonize_collection_rec (collection_rec
);
3805 /* Record the set of hard registers that are used in the exit block.
3806 It uses df->exit_block_uses to determine which bit to include. */
3809 df_record_exit_block_uses (bitmap exit_block_uses
)
3811 struct df_collection_rec collection_rec
;
3812 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
3814 /* Process bb_refs chain */
3815 df_refs_add_to_chains (&collection_rec
,
3816 BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
),
3822 /* Update the uses in the exit block. */
3825 df_update_exit_block_uses (void)
3828 bool changed
= false;
3830 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3831 df_get_exit_block_use_set (&refs
);
3832 if (df
->exit_block_uses
)
3834 if (!bitmap_equal_p (df
->exit_block_uses
, &refs
))
3836 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
3837 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
3838 df_ref_chain_delete (bb_info
->artificial_uses
);
3839 bb_info
->artificial_uses
= NULL
;
3845 struct df_scan_problem_data
*problem_data
3846 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3848 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3854 df_record_exit_block_uses (&refs
);
3855 bitmap_copy (df
->exit_block_uses
,& refs
);
3856 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun
, EXIT_BLOCK
));
3858 bitmap_clear (&refs
);
3861 static bool initialized
= false;
3864 /* Initialize some platform specific structures. */
3867 df_hard_reg_init (void)
3869 #ifdef ELIMINABLE_REGS
3871 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
3876 /* Record which registers will be eliminated. We use this in
3878 CLEAR_HARD_REG_SET (elim_reg_set
);
3880 #ifdef ELIMINABLE_REGS
3881 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
3882 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
3884 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
3891 /* Recompute the parts of scanning that are based on regs_ever_live
3892 because something changed in that array. */
3895 df_update_entry_exit_and_calls (void)
3899 df_update_entry_block_defs ();
3900 df_update_exit_block_uses ();
3902 /* The call insns need to be rescanned because there may be changes
3903 in the set of registers clobbered across the call. */
3904 FOR_EACH_BB_FN (bb
, cfun
)
3907 FOR_BB_INSNS (bb
, insn
)
3909 if (INSN_P (insn
) && CALL_P (insn
))
3910 df_insn_rescan (insn
);
3916 /* Return true if hard REG is actually used in the some instruction.
3917 There are a fair number of conditions that affect the setting of
3918 this array. See the comment in df.h for df->hard_regs_live_count
3919 for the conditions that this array is set. */
3922 df_hard_reg_used_p (unsigned int reg
)
3924 return df
->hard_regs_live_count
[reg
] != 0;
3928 /* A count of the number of times REG is actually used in the some
3929 instruction. There are a fair number of conditions that affect the
3930 setting of this array. See the comment in df.h for
3931 df->hard_regs_live_count for the conditions that this array is
3936 df_hard_reg_used_count (unsigned int reg
)
3938 return df
->hard_regs_live_count
[reg
];
3942 /* Get the value of regs_ever_live[REGNO]. */
3945 df_regs_ever_live_p (unsigned int regno
)
3947 return regs_ever_live
[regno
];
3951 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
3952 to change, schedule that change for the next update. */
3955 df_set_regs_ever_live (unsigned int regno
, bool value
)
3957 if (regs_ever_live
[regno
] == value
)
3960 regs_ever_live
[regno
] = value
;
3962 df
->redo_entry_and_exit
= true;
3966 /* Compute "regs_ever_live" information from the underlying df
3967 information. Set the vector to all false if RESET. */
3970 df_compute_regs_ever_live (bool reset
)
3973 bool changed
= df
->redo_entry_and_exit
;
3976 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
3978 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3979 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
3981 regs_ever_live
[i
] = true;
3985 df_update_entry_exit_and_calls ();
3986 df
->redo_entry_and_exit
= false;
3990 /*----------------------------------------------------------------------------
3991 Dataflow ref information verification functions.
3993 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
3994 df_reg_chain_verify_unmarked (refs)
3995 df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
3996 df_mws_verify (mw*, mw*, bool)
3997 df_insn_refs_verify (collection_rec, bb, insn, bool)
3998 df_bb_refs_verify (bb, refs, bool)
4000 df_exit_block_bitmap_verify (bool)
4001 df_entry_block_bitmap_verify (bool)
4003 ----------------------------------------------------------------------------*/
4006 /* Mark all refs in the reg chain. Verify that all of the registers
4007 are in the correct chain. */
4010 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
4011 bool is_def
, bool is_eq_use
)
4013 unsigned int count
= 0;
4015 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4017 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4019 /* If there are no def-use or use-def chains, make sure that all
4020 of the chains are clear. */
4022 gcc_assert (!DF_REF_CHAIN (ref
));
4024 /* Check to make sure the ref is in the correct chain. */
4025 gcc_assert (DF_REF_REGNO (ref
) == regno
);
4027 gcc_assert (DF_REF_REG_DEF_P (ref
));
4029 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4032 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4034 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4036 if (DF_REF_NEXT_REG (ref
))
4037 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4039 DF_REF_REG_MARK (ref
);
4045 /* Verify that all of the registers in the chain are unmarked. */
4048 df_reg_chain_verify_unmarked (df_ref refs
)
4051 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4052 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4056 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4059 df_refs_verify (const vec
<df_ref
, va_heap
> *new_rec
, df_ref old_rec
,
4065 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_ref
)
4067 if (old_rec
== NULL
|| !df_ref_equal_p (new_ref
, old_rec
))
4075 /* Abort if fail is called from the function level verifier. If
4076 that is the context, mark this reg as being seem. */
4079 gcc_assert (DF_REF_IS_REG_MARKED (old_rec
));
4080 DF_REF_REG_UNMARK (old_rec
);
4083 old_rec
= DF_REF_NEXT_LOC (old_rec
);
4087 gcc_assert (old_rec
== NULL
);
4089 return old_rec
== NULL
;
4094 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4097 df_mws_verify (const vec
<df_mw_hardreg_ptr
, va_heap
> *new_rec
,
4098 struct df_mw_hardreg
*old_rec
,
4102 struct df_mw_hardreg
*new_reg
;
4104 FOR_EACH_VEC_ELT (*new_rec
, ix
, new_reg
)
4106 if (old_rec
== NULL
|| !df_mw_equal_p (new_reg
, old_rec
))
4113 old_rec
= DF_MWS_NEXT (old_rec
);
4117 gcc_assert (old_rec
== NULL
);
4119 return old_rec
== NULL
;
4124 /* Return true if the existing insn refs information is complete and
4125 correct. Otherwise (i.e. if there's any missing or extra refs),
4126 return the correct df_ref chain in REFS_RETURN.
4128 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4129 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4130 verification mode instead of the whole function, so unmark
4133 If ABORT_IF_FAIL is set, this function never returns false. */
4136 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4141 bool ret1
, ret2
, ret3
, ret4
;
4142 unsigned int uid
= INSN_UID (insn
);
4143 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4145 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4147 /* Unfortunately we cannot opt out early if one of these is not
4148 right because the marks will not get cleared. */
4149 ret1
= df_refs_verify (&collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4151 ret2
= df_refs_verify (&collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4153 ret3
= df_refs_verify (&collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4155 ret4
= df_mws_verify (&collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4157 return (ret1
&& ret2
&& ret3
&& ret4
);
4161 /* Return true if all refs in the basic block are correct and complete.
4162 Due to df_ref_chain_verify, it will cause all refs
4163 that are verified to have DF_REF_MARK bit set. */
4166 df_bb_verify (basic_block bb
)
4169 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4170 struct df_collection_rec collection_rec
;
4172 gcc_assert (bb_info
);
4174 /* Scan the block, one insn at a time, from beginning to end. */
4175 FOR_BB_INSNS_REVERSE (bb
, insn
)
4179 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4180 df_free_collection_rec (&collection_rec
);
4183 /* Do the artificial defs and uses. */
4184 df_bb_refs_collect (&collection_rec
, bb
);
4185 df_refs_verify (&collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4186 df_refs_verify (&collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4187 df_free_collection_rec (&collection_rec
);
4193 /* Returns true if the entry block has correct and complete df_ref set.
4194 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4197 df_entry_block_bitmap_verify (bool abort_if_fail
)
4199 bitmap_head entry_block_defs
;
4202 bitmap_initialize (&entry_block_defs
, &df_bitmap_obstack
);
4203 df_get_entry_block_def_set (&entry_block_defs
);
4205 is_eq
= bitmap_equal_p (&entry_block_defs
, df
->entry_block_defs
);
4207 if (!is_eq
&& abort_if_fail
)
4209 fprintf (stderr
, "entry_block_defs = ");
4210 df_print_regset (stderr
, &entry_block_defs
);
4211 fprintf (stderr
, "df->entry_block_defs = ");
4212 df_print_regset (stderr
, df
->entry_block_defs
);
4216 bitmap_clear (&entry_block_defs
);
4222 /* Returns true if the exit block has correct and complete df_ref set.
4223 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4226 df_exit_block_bitmap_verify (bool abort_if_fail
)
4228 bitmap_head exit_block_uses
;
4231 bitmap_initialize (&exit_block_uses
, &df_bitmap_obstack
);
4232 df_get_exit_block_use_set (&exit_block_uses
);
4234 is_eq
= bitmap_equal_p (&exit_block_uses
, df
->exit_block_uses
);
4236 if (!is_eq
&& abort_if_fail
)
4238 fprintf (stderr
, "exit_block_uses = ");
4239 df_print_regset (stderr
, &exit_block_uses
);
4240 fprintf (stderr
, "df->exit_block_uses = ");
4241 df_print_regset (stderr
, df
->exit_block_uses
);
4245 bitmap_clear (&exit_block_uses
);
4251 /* Return true if df_ref information for all insns in all blocks are
4252 correct and complete. */
4255 df_scan_verify (void)
4259 bitmap_head regular_block_artificial_uses
;
4260 bitmap_head eh_block_artificial_uses
;
4265 /* Verification is a 4 step process. */
4267 /* (1) All of the refs are marked by going through the reg chains. */
4268 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4270 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4271 == DF_REG_DEF_COUNT (i
));
4272 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4273 == DF_REG_USE_COUNT (i
));
4274 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4275 == DF_REG_EQ_USE_COUNT (i
));
4278 /* (2) There are various bitmaps whose value may change over the
4279 course of the compilation. This step recomputes them to make
4280 sure that they have not slipped out of date. */
4281 bitmap_initialize (®ular_block_artificial_uses
, &df_bitmap_obstack
);
4282 bitmap_initialize (&eh_block_artificial_uses
, &df_bitmap_obstack
);
4284 df_get_regular_block_artificial_uses (®ular_block_artificial_uses
);
4285 df_get_eh_block_artificial_uses (&eh_block_artificial_uses
);
4287 bitmap_ior_into (&eh_block_artificial_uses
,
4288 ®ular_block_artificial_uses
);
4290 /* Check artificial_uses bitmaps didn't change. */
4291 gcc_assert (bitmap_equal_p (®ular_block_artificial_uses
,
4292 &df
->regular_block_artificial_uses
));
4293 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses
,
4294 &df
->eh_block_artificial_uses
));
4296 bitmap_clear (®ular_block_artificial_uses
);
4297 bitmap_clear (&eh_block_artificial_uses
);
4299 /* Verify entry block and exit block. These only verify the bitmaps,
4300 the refs are verified in df_bb_verify. */
4301 df_entry_block_bitmap_verify (true);
4302 df_exit_block_bitmap_verify (true);
4304 /* (3) All of the insns in all of the blocks are traversed and the
4305 marks are cleared both in the artificial refs attached to the
4306 blocks and the real refs inside the insns. It is a failure to
4307 clear a mark that has not been set as this means that the ref in
4308 the block or insn was not in the reg chain. */
4310 FOR_ALL_BB_FN (bb
, cfun
)
4313 /* (4) See if all reg chains are traversed a second time. This time
4314 a check is made that the marks are clear. A set mark would be a
4315 from a reg that is not in any insn or basic block. */
4317 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4319 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4320 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4321 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));