1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
31 #include "insn-config.h"
36 #include "alloc-pool.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
45 #include "target-def.h"
47 #include "tree-pass.h"
50 #define HAVE_epilogue 0
53 #define HAVE_prologue 0
55 #ifndef HAVE_sibcall_epilogue
56 #define HAVE_sibcall_epilogue 0
60 #define EPILOGUE_USES(REGNO) 0
63 /* The following two macros free the vecs that hold either the refs or
64 the mw refs. They are a little tricky because the vec has 0
65 elements is special and is not to be freed. */
66 #define df_scan_free_ref_vec(V) \
72 #define df_scan_free_mws_vec(V) \
78 /* The set of hard registers in eliminables[i].from. */
80 static HARD_REG_SET elim_reg_set
;
82 /* Initialize ur_in and ur_out as if all hard registers were partially
85 struct df_collection_rec
89 unsigned int next_def
;
90 unsigned int next_use
;
92 struct df_mw_hardreg
**mw_vec
;
93 unsigned int next_eq_use
;
97 static df_ref df_null_ref_rec
[1];
98 static struct df_mw_hardreg
* df_null_mw_rec
[1];
100 static void df_ref_record (enum df_ref_class
, struct df_collection_rec
*,
102 basic_block
, struct df_insn_info
*,
103 enum df_ref_type
, int ref_flags
,
104 int, int, enum machine_mode
);
105 static void df_def_record_1 (struct df_collection_rec
*, rtx
,
106 basic_block
, struct df_insn_info
*,
108 static void df_defs_record (struct df_collection_rec
*, rtx
,
109 basic_block
, struct df_insn_info
*,
111 static void df_uses_record (enum df_ref_class
, struct df_collection_rec
*,
112 rtx
*, enum df_ref_type
,
113 basic_block
, struct df_insn_info
*,
115 int, int, enum machine_mode
);
117 static df_ref
df_ref_create_structure (enum df_ref_class
,
118 struct df_collection_rec
*, rtx
, rtx
*,
119 basic_block
, struct df_insn_info
*,
120 enum df_ref_type
, int ref_flags
,
121 int, int, enum machine_mode
);
123 static void df_insn_refs_collect (struct df_collection_rec
*,
124 basic_block
, struct df_insn_info
*);
125 static void df_canonize_collection_rec (struct df_collection_rec
*);
127 static void df_get_regular_block_artificial_uses (bitmap
);
128 static void df_get_eh_block_artificial_uses (bitmap
);
130 static void df_record_entry_block_defs (bitmap
);
131 static void df_record_exit_block_uses (bitmap
);
132 static void df_get_exit_block_use_set (bitmap
);
133 static void df_get_entry_block_def_set (bitmap
);
134 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
135 static void df_ref_chain_delete_du_chain (df_ref
*);
136 static void df_ref_chain_delete (df_ref
*);
138 static void df_refs_add_to_chains (struct df_collection_rec
*,
141 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
, rtx
, bool);
142 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
143 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
144 static void df_install_ref (df_ref
, struct df_reg_info
*,
145 struct df_ref_info
*, bool);
147 static int df_ref_compare (const void *, const void *);
148 static int df_mw_compare (const void *, const void *);
150 /* Indexed by hardware reg number, is true if that register is ever
151 used in the current function.
153 In df-scan.c, this is set up to record the hard regs used
154 explicitly. Reload adds in the hard regs used for holding pseudo
155 regs. Final uses it to generate the code in the function prologue
156 and epilogue to save and restore registers as needed. */
158 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
160 /*----------------------------------------------------------------------------
161 SCANNING DATAFLOW PROBLEM
163 There are several ways in which scanning looks just like the other
164 dataflow problems. It shares the all the mechanisms for local info
165 as well as basic block info. Where it differs is when and how often
166 it gets run. It also has no need for the iterative solver.
167 ----------------------------------------------------------------------------*/
169 /* Problem data for the scanning dataflow function. */
170 struct df_scan_problem_data
172 alloc_pool ref_base_pool
;
173 alloc_pool ref_artificial_pool
;
174 alloc_pool ref_regular_pool
;
175 alloc_pool ref_extract_pool
;
176 alloc_pool insn_pool
;
178 alloc_pool mw_reg_pool
;
179 bitmap_obstack reg_bitmaps
;
180 bitmap_obstack insn_bitmaps
;
183 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
186 /* Internal function to shut down the scanning problem. */
188 df_scan_free_internal (void)
190 struct df_scan_problem_data
*problem_data
191 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
195 /* The vectors that hold the refs are not pool allocated because
196 they come in many sizes. This makes them impossible to delete
198 for (i
= 0; i
< DF_INSN_SIZE(); i
++)
200 struct df_insn_info
*insn_info
= DF_INSN_UID_GET(i
);
201 /* Skip the insns that have no insn_info or have been
205 df_scan_free_ref_vec (insn_info
->defs
);
206 df_scan_free_ref_vec (insn_info
->uses
);
207 df_scan_free_ref_vec (insn_info
->eq_uses
);
208 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
214 unsigned int bb_index
= bb
->index
;
215 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
218 df_scan_free_ref_vec (bb_info
->artificial_defs
);
219 df_scan_free_ref_vec (bb_info
->artificial_uses
);
223 free (df
->def_info
.refs
);
224 free (df
->def_info
.begin
);
225 free (df
->def_info
.count
);
226 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
228 free (df
->use_info
.refs
);
229 free (df
->use_info
.begin
);
230 free (df
->use_info
.count
);
231 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
237 free (df
->eq_use_regs
);
238 df
->eq_use_regs
= NULL
;
246 free (df_scan
->block_info
);
247 df_scan
->block_info
= NULL
;
248 df_scan
->block_info_size
= 0;
250 BITMAP_FREE (df
->hardware_regs_used
);
251 BITMAP_FREE (df
->regular_block_artificial_uses
);
252 BITMAP_FREE (df
->eh_block_artificial_uses
);
253 BITMAP_FREE (df
->entry_block_defs
);
254 BITMAP_FREE (df
->exit_block_uses
);
255 BITMAP_FREE (df
->insns_to_delete
);
256 BITMAP_FREE (df
->insns_to_rescan
);
257 BITMAP_FREE (df
->insns_to_notes_rescan
);
259 free_alloc_pool (df_scan
->block_pool
);
260 free_alloc_pool (problem_data
->ref_base_pool
);
261 free_alloc_pool (problem_data
->ref_artificial_pool
);
262 free_alloc_pool (problem_data
->ref_regular_pool
);
263 free_alloc_pool (problem_data
->ref_extract_pool
);
264 free_alloc_pool (problem_data
->insn_pool
);
265 free_alloc_pool (problem_data
->reg_pool
);
266 free_alloc_pool (problem_data
->mw_reg_pool
);
267 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
268 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
269 free (df_scan
->problem_data
);
273 /* Set basic block info. */
276 df_scan_set_bb_info (unsigned int index
,
277 struct df_scan_bb_info
*bb_info
)
279 gcc_assert (df_scan
);
280 df_grow_bb_info (df_scan
);
281 df_scan
->block_info
[index
] = (void *) bb_info
;
285 /* Free basic block info. */
288 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
290 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
291 unsigned int bb_index
= bb
->index
;
295 FOR_BB_INSNS (bb
, insn
)
298 /* Record defs within INSN. */
299 df_insn_delete (bb
, INSN_UID (insn
));
302 if (bb_index
< df_scan
->block_info_size
)
303 bb_info
= df_scan_get_bb_info (bb_index
);
305 /* Get rid of any artificial uses or defs. */
306 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
307 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
308 df_ref_chain_delete (bb_info
->artificial_defs
);
309 df_ref_chain_delete (bb_info
->artificial_uses
);
310 bb_info
->artificial_defs
= NULL
;
311 bb_info
->artificial_uses
= NULL
;
312 pool_free (df_scan
->block_pool
, bb_info
);
317 /* Allocate the problem data for the scanning problem. This should be
318 called when the problem is created or when the entire function is to
321 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
323 struct df_scan_problem_data
*problem_data
;
324 unsigned int insn_num
= get_max_uid () + 1;
325 unsigned int block_size
= 400;
328 /* Given the number of pools, this is really faster than tearing
330 if (df_scan
->problem_data
)
331 df_scan_free_internal ();
334 = create_alloc_pool ("df_scan_block pool",
335 sizeof (struct df_scan_bb_info
),
338 problem_data
= XNEW (struct df_scan_problem_data
);
339 df_scan
->problem_data
= problem_data
;
340 df_scan
->computed
= true;
342 problem_data
->ref_base_pool
343 = create_alloc_pool ("df_scan ref base",
344 sizeof (struct df_base_ref
), block_size
);
345 problem_data
->ref_artificial_pool
346 = create_alloc_pool ("df_scan ref artificial",
347 sizeof (struct df_artificial_ref
), block_size
);
348 problem_data
->ref_regular_pool
349 = create_alloc_pool ("df_scan ref regular",
350 sizeof (struct df_regular_ref
), block_size
);
351 problem_data
->ref_extract_pool
352 = create_alloc_pool ("df_scan ref extract",
353 sizeof (struct df_extract_ref
), block_size
);
354 problem_data
->insn_pool
355 = create_alloc_pool ("df_scan insn",
356 sizeof (struct df_insn_info
), block_size
);
357 problem_data
->reg_pool
358 = create_alloc_pool ("df_scan reg",
359 sizeof (struct df_reg_info
), block_size
);
360 problem_data
->mw_reg_pool
361 = create_alloc_pool ("df_scan mw_reg",
362 sizeof (struct df_mw_hardreg
), block_size
);
364 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
365 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
367 insn_num
+= insn_num
/ 4;
370 df_grow_insn_info ();
371 df_grow_bb_info (df_scan
);
375 unsigned int bb_index
= bb
->index
;
376 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
379 bb_info
= (struct df_scan_bb_info
*) pool_alloc (df_scan
->block_pool
);
380 df_scan_set_bb_info (bb_index
, bb_info
);
382 bb_info
->artificial_defs
= NULL
;
383 bb_info
->artificial_uses
= NULL
;
386 df
->hardware_regs_used
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
387 df
->regular_block_artificial_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
388 df
->eh_block_artificial_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
389 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
390 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
391 df
->insns_to_delete
= BITMAP_ALLOC (&problem_data
->insn_bitmaps
);
392 df
->insns_to_rescan
= BITMAP_ALLOC (&problem_data
->insn_bitmaps
);
393 df
->insns_to_notes_rescan
= BITMAP_ALLOC (&problem_data
->insn_bitmaps
);
394 df_scan
->optional_p
= false;
398 /* Free all of the data associated with the scan problem. */
403 if (df_scan
->problem_data
)
404 df_scan_free_internal ();
406 if (df
->blocks_to_analyze
)
408 BITMAP_FREE (df
->blocks_to_analyze
);
409 df
->blocks_to_analyze
= NULL
;
415 /* Dump the preamble for DF_SCAN dump. */
417 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
428 fprintf (file
, ";; invalidated by call \t");
429 df_print_regset (file
, regs_invalidated_by_call_regset
);
430 fprintf (file
, ";; hardware regs used \t");
431 df_print_regset (file
, df
->hardware_regs_used
);
432 fprintf (file
, ";; regular block artificial uses \t");
433 df_print_regset (file
, df
->regular_block_artificial_uses
);
434 fprintf (file
, ";; eh block artificial uses \t");
435 df_print_regset (file
, df
->eh_block_artificial_uses
);
436 fprintf (file
, ";; entry block defs \t");
437 df_print_regset (file
, df
->entry_block_defs
);
438 fprintf (file
, ";; exit block uses \t");
439 df_print_regset (file
, df
->exit_block_uses
);
440 fprintf (file
, ";; regs ever live \t");
441 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
442 if (df_regs_ever_live_p (i
))
443 fprintf (file
, " %d[%s]", i
, reg_names
[i
]);
444 fprintf (file
, "\n;; ref usage \t");
446 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
447 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
449 const char * sep
= "";
451 fprintf (file
, "r%d={", i
);
452 if (DF_REG_DEF_COUNT (i
))
454 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
456 dcount
+= DF_REG_DEF_COUNT (i
);
458 if (DF_REG_USE_COUNT (i
))
460 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
462 ucount
+= DF_REG_USE_COUNT (i
);
464 if (DF_REG_EQ_USE_COUNT (i
))
466 fprintf (file
, "%s%dd", sep
, DF_REG_EQ_USE_COUNT (i
));
467 ecount
+= DF_REG_EQ_USE_COUNT (i
);
469 fprintf (file
, "} ");
473 FOR_BB_INSNS (bb
, insn
)
482 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de} in %d{%d regular + %d call} insns.\n",
483 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
, icount
+ ccount
, icount
, ccount
);
486 /* Dump the bb_info for a given basic block. */
488 df_scan_start_block (basic_block bb
, FILE *file
)
490 struct df_scan_bb_info
*bb_info
491 = df_scan_get_bb_info (bb
->index
);
495 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
496 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
497 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
498 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
499 fprintf (file
, "\n");
504 FOR_BB_INSNS (bb
, insn
)
506 df_insn_debug (insn
, false, file
);
511 static struct df_problem problem_SCAN
=
513 DF_SCAN
, /* Problem id. */
514 DF_NONE
, /* Direction. */
515 df_scan_alloc
, /* Allocate the problem specific data. */
516 NULL
, /* Reset global information. */
517 df_scan_free_bb_info
, /* Free basic block info. */
518 NULL
, /* Local compute function. */
519 NULL
, /* Init the solution specific data. */
520 NULL
, /* Iterative solver. */
521 NULL
, /* Confluence operator 0. */
522 NULL
, /* Confluence operator n. */
523 NULL
, /* Transfer function. */
524 NULL
, /* Finalize function. */
525 df_scan_free
, /* Free all of the problem information. */
526 NULL
, /* Remove this problem from the stack of dataflow problems. */
527 df_scan_start_dump
, /* Debugging. */
528 df_scan_start_block
, /* Debugging start block. */
529 NULL
, /* Debugging end block. */
530 NULL
, /* Incremental solution verify start. */
531 NULL
, /* Incremental solution verify end. */
532 NULL
, /* Dependent problem. */
533 TV_DF_SCAN
, /* Timing variable. */
534 false /* Reset blocks on dropping out of blocks_to_analyze. */
538 /* Create a new DATAFLOW instance and add it to an existing instance
539 of DF. The returned structure is what is used to get at the
543 df_scan_add_problem (void)
545 df_add_problem (&problem_SCAN
);
549 /*----------------------------------------------------------------------------
550 Storage Allocation Utilities
551 ----------------------------------------------------------------------------*/
554 /* First, grow the reg_info information. If the current size is less than
555 the number of pseudos, grow to 25% more than the number of
558 Second, assure that all of the slots up to max_reg_num have been
559 filled with reg_info structures. */
562 df_grow_reg_info (void)
564 unsigned int max_reg
= max_reg_num ();
565 unsigned int new_size
= max_reg
;
566 struct df_scan_problem_data
*problem_data
567 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
570 if (df
->regs_size
< new_size
)
572 new_size
+= new_size
/ 4;
573 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
574 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
575 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
577 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
578 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
579 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
580 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
581 df
->regs_size
= new_size
;
584 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
586 struct df_reg_info
*reg_info
;
588 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
589 memset (reg_info
, 0, sizeof (struct df_reg_info
));
590 df
->def_regs
[i
] = reg_info
;
591 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
592 memset (reg_info
, 0, sizeof (struct df_reg_info
));
593 df
->use_regs
[i
] = reg_info
;
594 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
595 memset (reg_info
, 0, sizeof (struct df_reg_info
));
596 df
->eq_use_regs
[i
] = reg_info
;
597 df
->def_info
.begin
[i
] = 0;
598 df
->def_info
.count
[i
] = 0;
599 df
->use_info
.begin
[i
] = 0;
600 df
->use_info
.count
[i
] = 0;
603 df
->regs_inited
= max_reg
;
607 /* Grow the ref information. */
610 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
612 if (ref_info
->refs_size
< new_size
)
614 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
615 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
616 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
617 ref_info
->refs_size
= new_size
;
622 /* Check and grow the ref information if necessary. This routine
623 guarantees total_size + BITMAP_ADDEND amount of entries in refs
624 array. It updates ref_info->refs_size only and does not change
625 ref_info->total_size. */
628 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
629 unsigned bitmap_addend
)
631 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
633 int new_size
= ref_info
->total_size
+ bitmap_addend
;
634 new_size
+= ref_info
->total_size
/ 4;
635 df_grow_ref_info (ref_info
, new_size
);
640 /* Grow the ref information. If the current size is less than the
641 number of instructions, grow to 25% more than the number of
645 df_grow_insn_info (void)
647 unsigned int new_size
= get_max_uid () + 1;
648 if (DF_INSN_SIZE () < new_size
)
650 new_size
+= new_size
/ 4;
651 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
652 memset (df
->insns
+ df
->insns_size
, 0,
653 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
654 DF_INSN_SIZE () = new_size
;
661 /*----------------------------------------------------------------------------
662 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
663 ----------------------------------------------------------------------------*/
665 /* Rescan all of the block_to_analyze or all of the blocks in the
666 function if df_set_blocks if blocks_to_analyze is NULL; */
669 df_scan_blocks (void)
673 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
674 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
676 df_get_regular_block_artificial_uses (df
->regular_block_artificial_uses
);
677 df_get_eh_block_artificial_uses (df
->eh_block_artificial_uses
);
679 bitmap_ior_into (df
->eh_block_artificial_uses
,
680 df
->regular_block_artificial_uses
);
682 /* ENTRY and EXIT blocks have special defs/uses. */
683 df_get_entry_block_def_set (df
->entry_block_defs
);
684 df_record_entry_block_defs (df
->entry_block_defs
);
685 df_get_exit_block_use_set (df
->exit_block_uses
);
686 df_record_exit_block_uses (df
->exit_block_uses
);
687 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
688 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
693 unsigned int bb_index
= bb
->index
;
694 df_bb_refs_record (bb_index
, true);
699 /* Create a new ref of type DF_REF_TYPE for register REG at address
700 LOC within INSN of BB. This function is only used externally.
702 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
703 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
704 fields if they were constants. Otherwise they should be -1 if
705 those flags were set. */
708 df_ref_create (rtx reg
, rtx
*loc
, rtx insn
,
710 enum df_ref_type ref_type
,
712 int width
, int offset
, enum machine_mode mode
)
715 struct df_reg_info
**reg_info
;
716 struct df_ref_info
*ref_info
;
718 df_ref
**ref_rec_ptr
;
719 unsigned int count
= 0;
721 enum df_ref_class cl
;
725 /* You cannot hack artificial refs. */
728 if (width
!= -1 || offset
!= -1)
734 ref
= df_ref_create_structure (cl
, NULL
, reg
, loc
, bb
, DF_INSN_INFO_GET (insn
),
736 width
, offset
, mode
);
738 if (DF_REF_REG_DEF_P (ref
))
740 reg_info
= df
->def_regs
;
741 ref_info
= &df
->def_info
;
742 ref_rec_ptr
= &DF_INSN_DEFS (insn
);
743 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
745 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
747 reg_info
= df
->eq_use_regs
;
748 ref_info
= &df
->use_info
;
749 ref_rec_ptr
= &DF_INSN_EQ_USES (insn
);
750 switch (ref_info
->ref_order
)
752 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
753 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
754 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
758 add_to_table
= false;
764 reg_info
= df
->use_regs
;
765 ref_info
= &df
->use_info
;
766 ref_rec_ptr
= &DF_INSN_USES (insn
);
767 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
770 /* Do not add if ref is not in the right blocks. */
771 if (add_to_table
&& df
->analyze_subset
)
772 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
774 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
777 switch (ref_info
->ref_order
)
779 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
780 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
781 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
782 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
785 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
789 ref_rec
= *ref_rec_ptr
;
796 ref_rec
= *ref_rec_ptr
;
799 ref_rec
= XRESIZEVEC (df_ref
, ref_rec
, count
+2);
800 *ref_rec_ptr
= ref_rec
;
801 ref_rec
[count
] = ref
;
802 ref_rec
[count
+1] = NULL
;
803 qsort (ref_rec
, count
+ 1, sizeof (df_ref
), df_ref_compare
);
807 df_ref
*ref_rec
= XNEWVEC (df_ref
, 2);
810 *ref_rec_ptr
= ref_rec
;
816 fprintf (dump_file
, "adding ref ");
817 df_ref_debug (ref
, dump_file
);
820 /* By adding the ref directly, df_insn_rescan my not find any
821 differences even though the block will have changed. So we need
822 to mark the block dirty ourselves. */
823 df_set_bb_dirty (bb
);
830 /*----------------------------------------------------------------------------
831 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
832 ----------------------------------------------------------------------------*/
835 df_free_ref (df_ref ref
)
837 struct df_scan_problem_data
*problem_data
838 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
840 switch (DF_REF_CLASS (ref
))
843 pool_free (problem_data
->ref_base_pool
, ref
);
846 case DF_REF_ARTIFICIAL
:
847 pool_free (problem_data
->ref_artificial_pool
, ref
);
851 pool_free (problem_data
->ref_regular_pool
, ref
);
855 pool_free (problem_data
->ref_extract_pool
, ref
);
861 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
862 Also delete the def-use or use-def chain if it exists. */
865 df_reg_chain_unlink (df_ref ref
)
867 df_ref next
= DF_REF_NEXT_REG (ref
);
868 df_ref prev
= DF_REF_PREV_REG (ref
);
869 int id
= DF_REF_ID (ref
);
870 struct df_reg_info
*reg_info
;
873 if (DF_REF_REG_DEF_P (ref
))
875 int regno
= DF_REF_REGNO (ref
);
876 reg_info
= DF_REG_DEF_GET (regno
);
877 refs
= df
->def_info
.refs
;
881 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
883 reg_info
= DF_REG_EQ_USE_GET (DF_REF_REGNO (ref
));
884 switch (df
->use_info
.ref_order
)
886 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
887 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
888 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
889 refs
= df
->use_info
.refs
;
897 reg_info
= DF_REG_USE_GET (DF_REF_REGNO (ref
));
898 refs
= df
->use_info
.refs
;
904 if (df
->analyze_subset
)
906 if (bitmap_bit_p (df
->blocks_to_analyze
, DF_REF_BBNO (ref
)))
913 /* Delete any def-use or use-def chains that start here. It is
914 possible that there is trash in this field. This happens for
915 insns that have been deleted when rescanning has been deferred
916 and the chain problem has also been deleted. The chain tear down
917 code skips deleted insns. */
918 if (df_chain
&& DF_REF_CHAIN (ref
))
919 df_chain_unlink (ref
);
922 if (DF_REF_FLAGS_IS_SET (ref
, DF_HARD_REG_LIVE
))
924 gcc_assert (DF_REF_REGNO (ref
) < FIRST_PSEUDO_REGISTER
);
925 df
->hard_regs_live_count
[DF_REF_REGNO (ref
)]--;
928 /* Unlink from the reg chain. If there is no prev, this is the
929 first of the list. If not, just join the next and prev. */
931 DF_REF_NEXT_REG (prev
) = next
;
934 gcc_assert (reg_info
->reg_chain
== ref
);
935 reg_info
->reg_chain
= next
;
938 DF_REF_PREV_REG (next
) = prev
;
944 /* Remove REF from VEC. */
947 df_ref_compress_rec (df_ref
**vec_ptr
, df_ref ref
)
949 df_ref
*vec
= *vec_ptr
;
953 while (*vec
&& *vec
!= ref
)
965 *vec_ptr
= df_null_ref_rec
;
970 /* Unlink REF from all def-use/use-def chains, etc. */
973 df_ref_remove (df_ref ref
)
978 fprintf (dump_file
, "removing ref ");
979 df_ref_debug (ref
, dump_file
);
983 if (DF_REF_REG_DEF_P (ref
))
985 if (DF_REF_IS_ARTIFICIAL (ref
))
987 struct df_scan_bb_info
*bb_info
988 = df_scan_get_bb_info (DF_REF_BBNO (ref
));
989 df_ref_compress_rec (&bb_info
->artificial_defs
, ref
);
993 unsigned int uid
= DF_REF_INSN_UID (ref
);
994 struct df_insn_info
*insn_rec
= DF_INSN_UID_GET (uid
);
995 df_ref_compress_rec (&insn_rec
->defs
, ref
);
1000 if (DF_REF_IS_ARTIFICIAL (ref
))
1002 struct df_scan_bb_info
*bb_info
1003 = df_scan_get_bb_info (DF_REF_BBNO (ref
));
1004 df_ref_compress_rec (&bb_info
->artificial_uses
, ref
);
1008 unsigned int uid
= DF_REF_INSN_UID (ref
);
1009 struct df_insn_info
*insn_rec
= DF_INSN_UID_GET (uid
);
1011 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
1012 df_ref_compress_rec (&insn_rec
->eq_uses
, ref
);
1014 df_ref_compress_rec (&insn_rec
->uses
, ref
);
1018 /* By deleting the ref directly, df_insn_rescan my not find any
1019 differences even though the block will have changed. So we need
1020 to mark the block dirty ourselves. */
1021 df_set_bb_dirty (DF_REF_BB (ref
));
1022 df_reg_chain_unlink (ref
);
1026 /* Create the insn record for INSN. If there was one there, zero it
1029 struct df_insn_info
*
1030 df_insn_create_insn_record (rtx insn
)
1032 struct df_scan_problem_data
*problem_data
1033 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1034 struct df_insn_info
*insn_rec
;
1036 df_grow_insn_info ();
1037 insn_rec
= DF_INSN_INFO_GET (insn
);
1040 insn_rec
= (struct df_insn_info
*) pool_alloc (problem_data
->insn_pool
);
1041 DF_INSN_INFO_SET (insn
, insn_rec
);
1043 memset (insn_rec
, 0, sizeof (struct df_insn_info
));
1044 insn_rec
->insn
= insn
;
1049 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
1052 df_ref_chain_delete_du_chain (df_ref
*ref_rec
)
1056 df_ref ref
= *ref_rec
;
1057 /* CHAIN is allocated by DF_CHAIN. So make sure to
1058 pass df_scan instance for the problem. */
1059 if (DF_REF_CHAIN (ref
))
1060 df_chain_unlink (ref
);
1066 /* Delete all refs in the ref chain. */
1069 df_ref_chain_delete (df_ref
*ref_rec
)
1071 df_ref
*start
= ref_rec
;
1074 df_reg_chain_unlink (*ref_rec
);
1078 /* If the list is empty, it has a special shared element that is not
1085 /* Delete the hardreg chain. */
1088 df_mw_hardreg_chain_delete (struct df_mw_hardreg
**hardregs
)
1090 struct df_scan_problem_data
*problem_data
;
1095 problem_data
= (struct df_scan_problem_data
*) df_scan
->problem_data
;
1099 pool_free (problem_data
->mw_reg_pool
, *hardregs
);
1105 /* Delete all of the refs information from INSN. BB must be passed in
1106 except when called from df_process_deferred_rescans to mark the block
1110 df_insn_delete (basic_block bb
, unsigned int uid
)
1112 struct df_insn_info
*insn_info
= NULL
;
1116 df_grow_bb_info (df_scan
);
1117 df_grow_reg_info ();
1119 /* The block must be marked as dirty now, rather than later as in
1120 df_insn_rescan and df_notes_rescan because it may not be there at
1121 rescanning time and the mark would blow up. */
1123 df_set_bb_dirty (bb
);
1125 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1127 /* The client has deferred rescanning. */
1128 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1132 bitmap_clear_bit (df
->insns_to_rescan
, uid
);
1133 bitmap_clear_bit (df
->insns_to_notes_rescan
, uid
);
1134 bitmap_set_bit (df
->insns_to_delete
, uid
);
1137 fprintf (dump_file
, "deferring deletion of insn with uid = %d.\n", uid
);
1142 fprintf (dump_file
, "deleting insn with uid = %d.\n", uid
);
1144 bitmap_clear_bit (df
->insns_to_delete
, uid
);
1145 bitmap_clear_bit (df
->insns_to_rescan
, uid
);
1146 bitmap_clear_bit (df
->insns_to_notes_rescan
, uid
);
1149 struct df_scan_problem_data
*problem_data
1150 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1152 /* In general, notes do not have the insn_info fields
1153 initialized. However, combine deletes insns by changing them
1154 to notes. How clever. So we cannot just check if it is a
1155 valid insn before short circuiting this code, we need to see
1156 if we actually initialized it. */
1157 if (insn_info
->defs
)
1159 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1163 df_ref_chain_delete_du_chain (insn_info
->defs
);
1164 df_ref_chain_delete_du_chain (insn_info
->uses
);
1165 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1168 df_ref_chain_delete (insn_info
->defs
);
1169 df_ref_chain_delete (insn_info
->uses
);
1170 df_ref_chain_delete (insn_info
->eq_uses
);
1172 pool_free (problem_data
->insn_pool
, insn_info
);
1173 DF_INSN_UID_SET (uid
, NULL
);
1178 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1181 df_free_collection_rec (struct df_collection_rec
*collection_rec
)
1183 struct df_scan_problem_data
*problem_data
1184 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1186 struct df_mw_hardreg
**mw
;
1188 if (collection_rec
->def_vec
)
1189 for (ref
= collection_rec
->def_vec
; *ref
; ref
++)
1191 if (collection_rec
->use_vec
)
1192 for (ref
= collection_rec
->use_vec
; *ref
; ref
++)
1194 if (collection_rec
->eq_use_vec
)
1195 for (ref
= collection_rec
->eq_use_vec
; *ref
; ref
++)
1197 if (collection_rec
->mw_vec
)
1198 for (mw
= collection_rec
->mw_vec
; *mw
; mw
++)
1199 pool_free (problem_data
->mw_reg_pool
, *mw
);
1203 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1206 df_insn_rescan (rtx insn
)
1208 unsigned int uid
= INSN_UID (insn
);
1209 struct df_insn_info
*insn_info
= NULL
;
1210 basic_block bb
= BLOCK_FOR_INSN (insn
);
1211 struct df_collection_rec collection_rec
;
1212 collection_rec
.def_vec
= XALLOCAVEC (df_ref
, 1000);
1213 collection_rec
.use_vec
= XALLOCAVEC (df_ref
, 1000);
1214 collection_rec
.eq_use_vec
= XALLOCAVEC (df_ref
, 1000);
1215 collection_rec
.mw_vec
= XALLOCAVEC (struct df_mw_hardreg
*, 100);
1217 if ((!df
) || (!INSN_P (insn
)))
1223 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1227 /* The client has disabled rescanning and plans to do it itself. */
1228 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1231 df_grow_bb_info (df_scan
);
1232 df_grow_reg_info ();
1234 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1236 /* The client has deferred rescanning. */
1237 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1241 insn_info
= df_insn_create_insn_record (insn
);
1242 insn_info
->defs
= df_null_ref_rec
;
1243 insn_info
->uses
= df_null_ref_rec
;
1244 insn_info
->eq_uses
= df_null_ref_rec
;
1245 insn_info
->mw_hardregs
= df_null_mw_rec
;
1248 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1250 bitmap_clear_bit (df
->insns_to_delete
, uid
);
1251 bitmap_clear_bit (df
->insns_to_notes_rescan
, uid
);
1252 bitmap_set_bit (df
->insns_to_rescan
, INSN_UID (insn
));
1256 bitmap_clear_bit (df
->insns_to_delete
, uid
);
1257 bitmap_clear_bit (df
->insns_to_rescan
, uid
);
1258 bitmap_clear_bit (df
->insns_to_notes_rescan
, uid
);
1262 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1263 /* If there's no change, return false. */
1266 df_free_collection_rec (&collection_rec
);
1268 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1272 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1274 /* There's change - we need to delete the existing info.
1275 Since the insn isn't moved, we can salvage its LUID. */
1276 luid
= DF_INSN_LUID (insn
);
1277 df_insn_delete (NULL
, uid
);
1278 df_insn_create_insn_record (insn
);
1279 DF_INSN_LUID (insn
) = luid
;
1283 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1284 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1286 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1289 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
1290 df_set_bb_dirty (bb
);
1295 /* Rescan all of the insns in the function. Note that the artificial
1296 uses and defs are not touched. This function will destroy def-se
1297 or use-def chains. */
1300 df_insn_rescan_all (void)
1302 bool no_insn_rescan
= false;
1303 bool defer_insn_rescan
= false;
1307 bitmap tmp
= BITMAP_ALLOC (&df_bitmap_obstack
);
1309 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1311 df_clear_flags (DF_NO_INSN_RESCAN
);
1312 no_insn_rescan
= true;
1315 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1317 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1318 defer_insn_rescan
= true;
1321 bitmap_copy (tmp
, df
->insns_to_delete
);
1322 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1324 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1326 df_insn_delete (NULL
, uid
);
1330 bitmap_clear (df
->insns_to_delete
);
1331 bitmap_clear (df
->insns_to_rescan
);
1332 bitmap_clear (df
->insns_to_notes_rescan
);
1337 FOR_BB_INSNS (bb
, insn
)
1339 df_insn_rescan (insn
);
1344 df_set_flags (DF_NO_INSN_RESCAN
);
1345 if (defer_insn_rescan
)
1346 df_set_flags (DF_DEFER_INSN_RESCAN
);
1350 /* Process all of the deferred rescans or deletions. */
1353 df_process_deferred_rescans (void)
1355 bool no_insn_rescan
= false;
1356 bool defer_insn_rescan
= false;
1359 bitmap tmp
= BITMAP_ALLOC (&df_bitmap_obstack
);
1361 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1363 df_clear_flags (DF_NO_INSN_RESCAN
);
1364 no_insn_rescan
= true;
1367 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1369 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1370 defer_insn_rescan
= true;
1374 fprintf (dump_file
, "starting the processing of deferred insns\n");
1376 bitmap_copy (tmp
, df
->insns_to_delete
);
1377 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1379 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1381 df_insn_delete (NULL
, uid
);
1384 bitmap_copy (tmp
, df
->insns_to_rescan
);
1385 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1387 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1389 df_insn_rescan (insn_info
->insn
);
1392 bitmap_copy (tmp
, df
->insns_to_notes_rescan
);
1393 EXECUTE_IF_SET_IN_BITMAP (tmp
, 0, uid
, bi
)
1395 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1397 df_notes_rescan (insn_info
->insn
);
1401 fprintf (dump_file
, "ending the processing of deferred insns\n");
1404 bitmap_clear (df
->insns_to_delete
);
1405 bitmap_clear (df
->insns_to_rescan
);
1406 bitmap_clear (df
->insns_to_notes_rescan
);
1409 df_set_flags (DF_NO_INSN_RESCAN
);
1410 if (defer_insn_rescan
)
1411 df_set_flags (DF_DEFER_INSN_RESCAN
);
1413 /* If someone changed regs_ever_live during this pass, fix up the
1414 entry and exit blocks. */
1415 if (df
->redo_entry_and_exit
)
1417 df_update_entry_exit_and_calls ();
1418 df
->redo_entry_and_exit
= false;
1423 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1424 the uses if INCLUDE_USES. Include the eq_uses if
1428 df_count_refs (bool include_defs
, bool include_uses
,
1429 bool include_eq_uses
)
1433 unsigned int m
= df
->regs_inited
;
1435 for (regno
= 0; regno
< m
; regno
++)
1438 size
+= DF_REG_DEF_COUNT (regno
);
1440 size
+= DF_REG_USE_COUNT (regno
);
1441 if (include_eq_uses
)
1442 size
+= DF_REG_EQ_USE_COUNT (regno
);
1448 /* Take build ref table for either the uses or defs from the reg-use
1449 or reg-def chains. This version processes the refs in reg order
1450 which is likely to be best if processing the whole function. */
1453 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1456 bool include_eq_uses
)
1458 unsigned int m
= df
->regs_inited
;
1460 unsigned int offset
= 0;
1463 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1465 start
= FIRST_PSEUDO_REGISTER
;
1466 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1467 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1472 ref_info
->total_size
1473 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1475 df_check_and_grow_ref_info (ref_info
, 1);
1477 for (regno
= start
; regno
< m
; regno
++)
1480 ref_info
->begin
[regno
] = offset
;
1483 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1486 ref_info
->refs
[offset
] = ref
;
1487 DF_REF_ID (ref
) = offset
++;
1489 ref
= DF_REF_NEXT_REG (ref
);
1490 gcc_assert (offset
< ref_info
->refs_size
);
1495 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1498 ref_info
->refs
[offset
] = ref
;
1499 DF_REF_ID (ref
) = offset
++;
1501 ref
= DF_REF_NEXT_REG (ref
);
1502 gcc_assert (offset
< ref_info
->refs_size
);
1505 if (include_eq_uses
)
1507 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1510 ref_info
->refs
[offset
] = ref
;
1511 DF_REF_ID (ref
) = offset
++;
1513 ref
= DF_REF_NEXT_REG (ref
);
1514 gcc_assert (offset
< ref_info
->refs_size
);
1517 ref_info
->count
[regno
] = count
;
1520 /* The bitmap size is not decremented when refs are deleted. So
1521 reset it now that we have squished out all of the empty
1523 ref_info
->table_size
= offset
;
1527 /* Take build ref table for either the uses or defs from the reg-use
1528 or reg-def chains. This version processes the refs in insn order
1529 which is likely to be best if processing some segment of the
1533 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1536 bool include_eq_uses
)
1539 unsigned int bb_index
;
1540 unsigned int m
= df
->regs_inited
;
1541 unsigned int offset
= 0;
1544 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1546 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1547 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1549 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1550 df_check_and_grow_ref_info (ref_info
, 1);
1552 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1554 basic_block bb
= BASIC_BLOCK (bb_index
);
1559 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1561 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1562 ref_info
->count
[regno
]++;
1565 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1567 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1568 ref_info
->count
[regno
]++;
1571 FOR_BB_INSNS (bb
, insn
)
1575 unsigned int uid
= INSN_UID (insn
);
1578 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1580 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1581 ref_info
->count
[regno
]++;
1584 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1586 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1587 ref_info
->count
[regno
]++;
1589 if (include_eq_uses
)
1590 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1592 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1593 ref_info
->count
[regno
]++;
1599 for (r
= start
; r
< m
; r
++)
1601 ref_info
->begin
[r
] = offset
;
1602 offset
+= ref_info
->count
[r
];
1603 ref_info
->count
[r
] = 0;
1606 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1608 basic_block bb
= BASIC_BLOCK (bb_index
);
1613 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1615 df_ref ref
= *ref_rec
;
1616 unsigned int regno
= DF_REF_REGNO (ref
);
1620 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1621 DF_REF_ID (ref
) = id
;
1622 ref_info
->refs
[id
] = ref
;
1626 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1628 df_ref ref
= *ref_rec
;
1629 unsigned int regno
= DF_REF_REGNO (ref
);
1633 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1634 DF_REF_ID (ref
) = id
;
1635 ref_info
->refs
[id
] = ref
;
1639 FOR_BB_INSNS (bb
, insn
)
1643 unsigned int uid
= INSN_UID (insn
);
1646 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1648 df_ref ref
= *ref_rec
;
1649 unsigned int regno
= DF_REF_REGNO (ref
);
1653 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1654 DF_REF_ID (ref
) = id
;
1655 ref_info
->refs
[id
] = ref
;
1659 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1661 df_ref ref
= *ref_rec
;
1662 unsigned int regno
= DF_REF_REGNO (ref
);
1666 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1667 DF_REF_ID (ref
) = id
;
1668 ref_info
->refs
[id
] = ref
;
1671 if (include_eq_uses
)
1672 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1674 df_ref ref
= *ref_rec
;
1675 unsigned int regno
= DF_REF_REGNO (ref
);
1679 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1680 DF_REF_ID (ref
) = id
;
1681 ref_info
->refs
[id
] = ref
;
1688 /* The bitmap size is not decremented when refs are deleted. So
1689 reset it now that we have squished out all of the empty
1692 ref_info
->table_size
= offset
;
1695 /* Take build ref table for either the uses or defs from the reg-use
1696 or reg-def chains. */
1699 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1702 bool include_eq_uses
)
1704 if (df
->analyze_subset
)
1705 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1706 include_uses
, include_eq_uses
);
1708 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1709 include_uses
, include_eq_uses
);
1713 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1715 df_add_refs_to_table (unsigned int offset
,
1716 struct df_ref_info
*ref_info
,
1721 df_ref ref
= *ref_vec
;
1722 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
1723 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1725 ref_info
->refs
[offset
] = ref
;
1726 DF_REF_ID (*ref_vec
) = offset
++;
1734 /* Count the number of refs in all of the insns of BB. Include the
1735 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1736 eq_uses if INCLUDE_EQ_USES. */
1739 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1740 struct df_ref_info
*ref_info
,
1741 bool include_defs
, bool include_uses
,
1742 bool include_eq_uses
)
1747 offset
= df_add_refs_to_table (offset
, ref_info
,
1748 df_get_artificial_defs (bb
->index
));
1750 offset
= df_add_refs_to_table (offset
, ref_info
,
1751 df_get_artificial_uses (bb
->index
));
1753 FOR_BB_INSNS (bb
, insn
)
1756 unsigned int uid
= INSN_UID (insn
);
1758 offset
= df_add_refs_to_table (offset
, ref_info
,
1759 DF_INSN_UID_DEFS (uid
));
1761 offset
= df_add_refs_to_table (offset
, ref_info
,
1762 DF_INSN_UID_USES (uid
));
1763 if (include_eq_uses
)
1764 offset
= df_add_refs_to_table (offset
, ref_info
,
1765 DF_INSN_UID_EQ_USES (uid
));
1771 /* Organize the refs by insn into the table in REF_INFO. If
1772 blocks_to_analyze is defined, use that set, otherwise the entire
1773 program. Include the defs if INCLUDE_DEFS. Include the uses if
1774 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1777 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1778 bool include_defs
, bool include_uses
,
1779 bool include_eq_uses
)
1782 unsigned int offset
= 0;
1784 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1785 df_check_and_grow_ref_info (ref_info
, 1);
1786 if (df
->blocks_to_analyze
)
1791 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1793 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index
), offset
, ref_info
,
1794 include_defs
, include_uses
,
1798 ref_info
->table_size
= offset
;
1803 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1804 include_defs
, include_uses
,
1806 ref_info
->table_size
= offset
;
1811 /* If the use refs in DF are not organized, reorganize them. */
1814 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1816 if (order
== df
->use_info
.ref_order
)
1821 case DF_REF_ORDER_BY_REG
:
1822 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1825 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1826 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1829 case DF_REF_ORDER_BY_INSN
:
1830 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1833 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1834 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1837 case DF_REF_ORDER_NO_TABLE
:
1838 free (df
->use_info
.refs
);
1839 df
->use_info
.refs
= NULL
;
1840 df
->use_info
.refs_size
= 0;
1843 case DF_REF_ORDER_UNORDERED
:
1844 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1849 df
->use_info
.ref_order
= order
;
1853 /* If the def refs in DF are not organized, reorganize them. */
1856 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1858 if (order
== df
->def_info
.ref_order
)
1863 case DF_REF_ORDER_BY_REG
:
1864 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1867 case DF_REF_ORDER_BY_INSN
:
1868 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1871 case DF_REF_ORDER_NO_TABLE
:
1872 free (df
->def_info
.refs
);
1873 df
->def_info
.refs
= NULL
;
1874 df
->def_info
.refs_size
= 0;
1877 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1878 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1879 case DF_REF_ORDER_UNORDERED
:
1880 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1885 df
->def_info
.ref_order
= order
;
1889 /* Change all of the basic block references in INSN to use the insn's
1890 current basic block. This function is called from routines that move
1891 instructions from one block to another. */
1894 df_insn_change_bb (rtx insn
, basic_block new_bb
)
1896 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1897 struct df_insn_info
*insn_info
;
1898 unsigned int uid
= INSN_UID (insn
);
1900 if (old_bb
== new_bb
)
1903 set_block_for_insn (insn
, new_bb
);
1909 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1911 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1912 if (insn_info
== NULL
)
1915 fprintf (dump_file
, " unscanned insn\n");
1916 df_insn_rescan (insn
);
1923 df_set_bb_dirty (new_bb
);
1927 fprintf (dump_file
, " from %d to %d\n",
1928 old_bb
->index
, new_bb
->index
);
1929 df_set_bb_dirty (old_bb
);
1933 fprintf (dump_file
, " to %d\n", new_bb
->index
);
1937 /* Helper function for df_ref_change_reg_with_loc. */
1940 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
1941 struct df_reg_info
*new_df
,
1942 int new_regno
, rtx loc
)
1944 df_ref the_ref
= old_df
->reg_chain
;
1948 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
1949 && (DF_REF_LOC (the_ref
))
1950 && (*DF_REF_LOC (the_ref
) == loc
))
1952 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
1953 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
1954 df_ref
*ref_vec
, *ref_vec_t
;
1955 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
1956 unsigned int count
= 0;
1958 DF_REF_REGNO (the_ref
) = new_regno
;
1959 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
1961 /* Pull the_ref out of the old regno chain. */
1963 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
1965 old_df
->reg_chain
= next_ref
;
1967 DF_REF_PREV_REG (next_ref
) = prev_ref
;
1970 /* Put the ref into the new regno chain. */
1971 DF_REF_PREV_REG (the_ref
) = NULL
;
1972 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
1973 if (new_df
->reg_chain
)
1974 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
1975 new_df
->reg_chain
= the_ref
;
1977 if (DF_REF_BB (the_ref
))
1978 df_set_bb_dirty (DF_REF_BB (the_ref
));
1980 /* Need to sort the record again that the ref was in because
1981 the regno is a sorting key. First, find the right
1983 if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
1984 ref_vec
= insn_info
->eq_uses
;
1986 ref_vec
= insn_info
->uses
;
1988 fprintf (dump_file
, "changing reg in insn %d\n",
1989 DF_REF_INSN_UID (the_ref
));
1991 ref_vec_t
= ref_vec
;
1993 /* Find the length. */
1999 qsort (ref_vec
, count
, sizeof (df_ref
), df_ref_compare
);
2004 the_ref
= DF_REF_NEXT_REG (the_ref
);
2009 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2010 NEW_REGNO. Refs that do not match LOC are not changed which means
2011 that artificial refs are not changed since they have no loc. This
2012 call is to support the SET_REGNO macro. */
2015 df_ref_change_reg_with_loc (int old_regno
, int new_regno
, rtx loc
)
2017 if ((!df
) || (old_regno
== -1) || (old_regno
== new_regno
))
2020 df_grow_reg_info ();
2022 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
2023 DF_REG_DEF_GET (new_regno
), new_regno
, loc
);
2024 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
2025 DF_REG_USE_GET (new_regno
), new_regno
, loc
);
2026 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
2027 DF_REG_EQ_USE_GET (new_regno
), new_regno
, loc
);
2031 /* Delete the mw_hardregs that point into the eq_notes. */
2034 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
2036 struct df_mw_hardreg
**mw_vec
= insn_info
->mw_hardregs
;
2037 unsigned int deleted
= 0;
2038 unsigned int count
= 0;
2039 struct df_scan_problem_data
*problem_data
2040 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2047 if ((*mw_vec
)->flags
& DF_REF_IN_NOTE
)
2049 struct df_mw_hardreg
**temp_vec
= mw_vec
;
2051 pool_free (problem_data
->mw_reg_pool
, *mw_vec
);
2053 /* Shove the remaining ones down one to fill the gap. While
2054 this looks n**2, it is highly unusual to have any mw regs
2055 in eq_notes and the chances of more than one are almost
2059 *temp_vec
= *(temp_vec
+ 1);
2073 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
2074 insn_info
->mw_hardregs
= df_null_mw_rec
;
2081 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2084 df_notes_rescan (rtx insn
)
2086 struct df_insn_info
*insn_info
;
2087 unsigned int uid
= INSN_UID (insn
);
2092 /* The client has disabled rescanning and plans to do it itself. */
2093 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
2096 /* Do nothing if the insn hasn't been emitted yet. */
2097 if (!BLOCK_FOR_INSN (insn
))
2100 df_grow_bb_info (df_scan
);
2101 df_grow_reg_info ();
2103 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID(insn
));
2105 /* The client has deferred rescanning. */
2106 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
2110 insn_info
= df_insn_create_insn_record (insn
);
2111 insn_info
->defs
= df_null_ref_rec
;
2112 insn_info
->uses
= df_null_ref_rec
;
2113 insn_info
->eq_uses
= df_null_ref_rec
;
2114 insn_info
->mw_hardregs
= df_null_mw_rec
;
2117 bitmap_clear_bit (df
->insns_to_delete
, uid
);
2118 /* If the insn is set to be rescanned, it does not need to also
2119 be notes rescanned. */
2120 if (!bitmap_bit_p (df
->insns_to_rescan
, uid
))
2121 bitmap_set_bit (df
->insns_to_notes_rescan
, INSN_UID (insn
));
2125 bitmap_clear_bit (df
->insns_to_delete
, uid
);
2126 bitmap_clear_bit (df
->insns_to_notes_rescan
, uid
);
2130 basic_block bb
= BLOCK_FOR_INSN (insn
);
2132 struct df_collection_rec collection_rec
;
2133 unsigned int num_deleted
;
2135 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
2136 collection_rec
.eq_use_vec
= XALLOCAVEC (df_ref
, 1000);
2137 collection_rec
.mw_vec
= XALLOCAVEC (struct df_mw_hardreg
*, 1000);
2139 num_deleted
= df_mw_hardreg_chain_delete_eq_uses (insn_info
);
2140 df_ref_chain_delete (insn_info
->eq_uses
);
2141 insn_info
->eq_uses
= NULL
;
2143 /* Process REG_EQUIV/REG_EQUAL notes */
2144 for (note
= REG_NOTES (insn
); note
;
2145 note
= XEXP (note
, 1))
2147 switch (REG_NOTE_KIND (note
))
2151 df_uses_record (DF_REF_REGULAR
, &collection_rec
,
2152 &XEXP (note
, 0), DF_REF_REG_USE
,
2153 bb
, insn_info
, DF_REF_IN_NOTE
, -1, -1, VOIDmode
);
2159 /* Find some place to put any new mw_hardregs. */
2160 df_canonize_collection_rec (&collection_rec
);
2161 if (collection_rec
.next_mw
)
2163 unsigned int count
= 0;
2164 struct df_mw_hardreg
**mw_rec
= insn_info
->mw_hardregs
;
2173 /* Append to the end of the existing record after
2174 expanding it if necessary. */
2175 if (collection_rec
.next_mw
> num_deleted
)
2177 insn_info
->mw_hardregs
=
2178 XRESIZEVEC (struct df_mw_hardreg
*,
2179 insn_info
->mw_hardregs
,
2180 count
+ 1 + collection_rec
.next_mw
);
2182 memcpy (&insn_info
->mw_hardregs
[count
], collection_rec
.mw_vec
,
2183 (collection_rec
.next_mw
+ 1) * sizeof (struct df_mw_hardreg
*));
2184 qsort (insn_info
->mw_hardregs
, count
+ collection_rec
.next_mw
,
2185 sizeof (struct df_mw_hardreg
*), df_mw_compare
);
2189 /* No vector there. */
2190 insn_info
->mw_hardregs
2191 = XNEWVEC (struct df_mw_hardreg
*,
2192 count
+ 1 + collection_rec
.next_mw
);
2193 memcpy (insn_info
->mw_hardregs
, collection_rec
.mw_vec
,
2194 (collection_rec
.next_mw
+ 1) * sizeof (struct df_mw_hardreg
*));
2197 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2199 collection_rec
.mw_vec
= NULL
;
2200 collection_rec
.next_mw
= 0;
2201 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
2204 df_insn_rescan (insn
);
2209 /*----------------------------------------------------------------------------
2210 Hard core instruction scanning code. No external interfaces here,
2211 just a lot of routines that look inside insns.
2212 ----------------------------------------------------------------------------*/
2215 /* Return true if the contents of two df_ref's are identical.
2216 It ignores DF_REF_MARKER. */
2219 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2227 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2228 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2229 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2230 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2231 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2232 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2233 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2234 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2237 switch (DF_REF_CLASS (ref1
))
2239 case DF_REF_ARTIFICIAL
:
2243 case DF_REF_EXTRACT
:
2244 if ((DF_REF_EXTRACT_OFFSET (ref1
) != DF_REF_EXTRACT_OFFSET (ref2
))
2245 || (DF_REF_EXTRACT_WIDTH (ref1
) != DF_REF_EXTRACT_WIDTH (ref2
))
2246 || (DF_REF_EXTRACT_MODE (ref1
) != DF_REF_EXTRACT_MODE (ref2
)))
2250 case DF_REF_REGULAR
:
2251 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2260 /* Compare REF1 and REF2 for sorting. This is only called from places
2261 where all of the refs are of the same type, in the same insn, and
2262 have the same bb. So these fields are not checked. */
2265 df_ref_compare (const void *r1
, const void *r2
)
2267 const df_ref ref1
= *(const df_ref
*)r1
;
2268 const df_ref ref2
= *(const df_ref
*)r2
;
2273 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2274 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2276 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2277 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2279 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2280 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2282 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2283 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2285 /* Cannot look at the LOC field on artificial refs. */
2286 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2287 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2288 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2290 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2292 /* If two refs are identical except that one of them has is from
2293 a mw and one is not, we need to have the one with the mw
2295 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2296 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2297 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2298 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2304 /* The classes are the same at this point so it is safe to only look
2306 if (DF_REF_CLASS (ref1
) == DF_REF_EXTRACT
)
2308 if (DF_REF_EXTRACT_OFFSET (ref1
) != DF_REF_EXTRACT_OFFSET (ref2
))
2309 return DF_REF_EXTRACT_OFFSET (ref1
) - DF_REF_EXTRACT_OFFSET (ref2
);
2310 if (DF_REF_EXTRACT_WIDTH (ref1
) != DF_REF_EXTRACT_WIDTH (ref2
))
2311 return DF_REF_EXTRACT_WIDTH (ref1
) - DF_REF_EXTRACT_WIDTH (ref2
);
2312 if (DF_REF_EXTRACT_MODE (ref1
) != DF_REF_EXTRACT_MODE (ref2
))
2313 return DF_REF_EXTRACT_MODE (ref1
) - DF_REF_EXTRACT_MODE (ref2
);
2319 df_swap_refs (df_ref
*ref_vec
, int i
, int j
)
2321 df_ref tmp
= ref_vec
[i
];
2322 ref_vec
[i
] = ref_vec
[j
];
2326 /* Sort and compress a set of refs. */
2329 df_sort_and_compress_refs (df_ref
*ref_vec
, unsigned int count
)
2332 unsigned int dist
= 0;
2334 ref_vec
[count
] = NULL
;
2335 /* If there are 1 or 0 elements, there is nothing to do. */
2338 else if (count
== 2)
2340 if (df_ref_compare (&ref_vec
[0], &ref_vec
[1]) > 0)
2341 df_swap_refs (ref_vec
, 0, 1);
2345 for (i
= 0; i
< count
- 1; i
++)
2346 if (df_ref_compare (&ref_vec
[i
], &ref_vec
[i
+1]) >= 0)
2348 /* If the array is already strictly ordered,
2349 which is the most common case for large COUNT case
2350 (which happens for CALL INSNs),
2351 no need to sort and filter out duplicate.
2352 Simply return the count.
2353 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2354 of DF_REF_COMPARE. */
2357 qsort (ref_vec
, count
, sizeof (df_ref
), df_ref_compare
);
2360 for (i
=0; i
<count
-dist
; i
++)
2362 /* Find the next ref that is not equal to the current ref. */
2363 while (df_ref_equal_p (ref_vec
[i
], ref_vec
[i
+ dist
+ 1]))
2365 df_free_ref (ref_vec
[i
+ dist
+ 1]);
2368 /* Copy it down to the next position. */
2370 ref_vec
[i
+1] = ref_vec
[i
+ dist
+ 1];
2374 ref_vec
[count
] = NULL
;
2379 /* Return true if the contents of two df_ref's are identical.
2380 It ignores DF_REF_MARKER. */
2383 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2387 return (mw1
== mw2
) ||
2388 (mw1
->mw_reg
== mw2
->mw_reg
2389 && mw1
->type
== mw2
->type
2390 && mw1
->flags
== mw2
->flags
2391 && mw1
->start_regno
== mw2
->start_regno
2392 && mw1
->end_regno
== mw2
->end_regno
);
2396 /* Compare MW1 and MW2 for sorting. */
2399 df_mw_compare (const void *m1
, const void *m2
)
2401 const struct df_mw_hardreg
*const mw1
= *(const struct df_mw_hardreg
*const*)m1
;
2402 const struct df_mw_hardreg
*const mw2
= *(const struct df_mw_hardreg
*const*)m2
;
2407 if (mw1
->type
!= mw2
->type
)
2408 return mw1
->type
- mw2
->type
;
2410 if (mw1
->flags
!= mw2
->flags
)
2411 return mw1
->flags
- mw2
->flags
;
2413 if (mw1
->start_regno
!= mw2
->start_regno
)
2414 return mw1
->start_regno
- mw2
->start_regno
;
2416 if (mw1
->end_regno
!= mw2
->end_regno
)
2417 return mw1
->end_regno
- mw2
->end_regno
;
2419 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2420 return mw1
->mw_order
- mw2
->mw_order
;
2426 /* Sort and compress a set of refs. */
2429 df_sort_and_compress_mws (struct df_mw_hardreg
**mw_vec
, unsigned int count
)
2431 struct df_scan_problem_data
*problem_data
2432 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2434 unsigned int dist
= 0;
2435 mw_vec
[count
] = NULL
;
2439 else if (count
== 2)
2441 if (df_mw_compare (&mw_vec
[0], &mw_vec
[1]) > 0)
2443 struct df_mw_hardreg
*tmp
= mw_vec
[0];
2444 mw_vec
[0] = mw_vec
[1];
2449 qsort (mw_vec
, count
, sizeof (struct df_mw_hardreg
*), df_mw_compare
);
2451 for (i
=0; i
<count
-dist
; i
++)
2453 /* Find the next ref that is not equal to the current ref. */
2454 while (df_mw_equal_p (mw_vec
[i
], mw_vec
[i
+ dist
+ 1]))
2456 pool_free (problem_data
->mw_reg_pool
, mw_vec
[i
+ dist
+ 1]);
2459 /* Copy it down to the next position. */
2461 mw_vec
[i
+1] = mw_vec
[i
+ dist
+ 1];
2465 mw_vec
[count
] = NULL
;
2470 /* Sort and remove duplicates from the COLLECTION_REC. */
2473 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2475 if (collection_rec
->def_vec
)
2476 collection_rec
->next_def
2477 = df_sort_and_compress_refs (collection_rec
->def_vec
,
2478 collection_rec
->next_def
);
2479 if (collection_rec
->use_vec
)
2480 collection_rec
->next_use
2481 = df_sort_and_compress_refs (collection_rec
->use_vec
,
2482 collection_rec
->next_use
);
2483 if (collection_rec
->eq_use_vec
)
2484 collection_rec
->next_eq_use
2485 = df_sort_and_compress_refs (collection_rec
->eq_use_vec
,
2486 collection_rec
->next_eq_use
);
2487 if (collection_rec
->mw_vec
)
2488 collection_rec
->next_mw
2489 = df_sort_and_compress_mws (collection_rec
->mw_vec
,
2490 collection_rec
->next_mw
);
2494 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2497 df_install_ref (df_ref this_ref
,
2498 struct df_reg_info
*reg_info
,
2499 struct df_ref_info
*ref_info
,
2502 unsigned int regno
= DF_REF_REGNO (this_ref
);
2503 /* Add the ref to the reg_{def,use,eq_use} chain. */
2504 df_ref head
= reg_info
->reg_chain
;
2506 reg_info
->reg_chain
= this_ref
;
2509 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2511 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2512 df
->hard_regs_live_count
[regno
]++;
2515 gcc_assert (DF_REF_NEXT_REG (this_ref
) == NULL
);
2516 gcc_assert (DF_REF_PREV_REG (this_ref
) == NULL
);
2518 DF_REF_NEXT_REG (this_ref
) = head
;
2520 /* We cannot actually link to the head of the chain. */
2521 DF_REF_PREV_REG (this_ref
) = NULL
;
2524 DF_REF_PREV_REG (head
) = this_ref
;
2528 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2529 df_check_and_grow_ref_info (ref_info
, 1);
2530 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2531 /* Add the ref to the big array of defs. */
2532 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2533 ref_info
->table_size
++;
2536 DF_REF_ID (this_ref
) = -1;
2538 ref_info
->total_size
++;
2542 /* This function takes one of the groups of refs (defs, uses or
2543 eq_uses) and installs the entire group into the insn. It also adds
2544 each of these refs into the appropriate chains. */
2547 df_install_refs (basic_block bb
,
2548 df_ref
*old_vec
, unsigned int count
,
2549 struct df_reg_info
**reg_info
,
2550 struct df_ref_info
*ref_info
,
2556 df_ref
*new_vec
= XNEWVEC (df_ref
, count
+ 1);
2559 switch (ref_info
->ref_order
)
2561 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2562 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2563 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2564 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2565 add_to_table
= true;
2567 case DF_REF_ORDER_UNORDERED
:
2568 case DF_REF_ORDER_BY_REG
:
2569 case DF_REF_ORDER_BY_INSN
:
2570 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2571 add_to_table
= !is_notes
;
2574 add_to_table
= false;
2578 /* Do not add if ref is not in the right blocks. */
2579 if (add_to_table
&& df
->analyze_subset
)
2580 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2582 for (i
= 0; i
< count
; i
++)
2584 df_ref this_ref
= old_vec
[i
];
2585 new_vec
[i
] = this_ref
;
2586 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2587 ref_info
, add_to_table
);
2590 new_vec
[count
] = NULL
;
2594 return df_null_ref_rec
;
2598 /* This function takes the mws installs the entire group into the
2601 static struct df_mw_hardreg
**
2602 df_install_mws (struct df_mw_hardreg
**old_vec
, unsigned int count
)
2606 struct df_mw_hardreg
**new_vec
2607 = XNEWVEC (struct df_mw_hardreg
*, count
+ 1);
2608 memcpy (new_vec
, old_vec
,
2609 sizeof (struct df_mw_hardreg
*) * (count
+ 1));
2613 return df_null_mw_rec
;
2617 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2618 chains and update other necessary information. */
2621 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2622 basic_block bb
, rtx insn
)
2626 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2627 /* If there is a vector in the collection rec, add it to the
2628 insn. A null rec is a signal that the caller will handle the
2630 if (collection_rec
->def_vec
)
2632 df_scan_free_ref_vec (insn_rec
->defs
);
2634 = df_install_refs (bb
, collection_rec
->def_vec
,
2635 collection_rec
->next_def
,
2637 &df
->def_info
, false);
2639 if (collection_rec
->use_vec
)
2641 df_scan_free_ref_vec (insn_rec
->uses
);
2643 = df_install_refs (bb
, collection_rec
->use_vec
,
2644 collection_rec
->next_use
,
2646 &df
->use_info
, false);
2648 if (collection_rec
->eq_use_vec
)
2650 df_scan_free_ref_vec (insn_rec
->eq_uses
);
2652 = df_install_refs (bb
, collection_rec
->eq_use_vec
,
2653 collection_rec
->next_eq_use
,
2655 &df
->use_info
, true);
2657 if (collection_rec
->mw_vec
)
2659 df_scan_free_mws_vec (insn_rec
->mw_hardregs
);
2660 insn_rec
->mw_hardregs
2661 = df_install_mws (collection_rec
->mw_vec
,
2662 collection_rec
->next_mw
);
2667 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2669 df_scan_free_ref_vec (bb_info
->artificial_defs
);
2670 bb_info
->artificial_defs
2671 = df_install_refs (bb
, collection_rec
->def_vec
,
2672 collection_rec
->next_def
,
2674 &df
->def_info
, false);
2675 df_scan_free_ref_vec (bb_info
->artificial_uses
);
2676 bb_info
->artificial_uses
2677 = df_install_refs (bb
, collection_rec
->use_vec
,
2678 collection_rec
->next_use
,
2680 &df
->use_info
, false);
2685 /* Allocate a ref and initialize its fields.
2687 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2688 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the fields
2689 if they were constants. Otherwise they should be -1 if those flags
2693 df_ref_create_structure (enum df_ref_class cl
,
2694 struct df_collection_rec
*collection_rec
,
2696 basic_block bb
, struct df_insn_info
*info
,
2697 enum df_ref_type ref_type
,
2699 int width
, int offset
, enum machine_mode mode
)
2701 df_ref this_ref
= NULL
;
2702 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2703 struct df_scan_problem_data
*problem_data
2704 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2709 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_base_pool
);
2710 gcc_assert (loc
== NULL
);
2713 case DF_REF_ARTIFICIAL
:
2714 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_artificial_pool
);
2715 this_ref
->artificial_ref
.bb
= bb
;
2716 gcc_assert (loc
== NULL
);
2719 case DF_REF_REGULAR
:
2720 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_regular_pool
);
2721 this_ref
->regular_ref
.loc
= loc
;
2725 case DF_REF_EXTRACT
:
2726 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_extract_pool
);
2727 DF_REF_EXTRACT_WIDTH (this_ref
) = width
;
2728 DF_REF_EXTRACT_OFFSET (this_ref
) = offset
;
2729 DF_REF_EXTRACT_MODE (this_ref
) = mode
;
2730 this_ref
->regular_ref
.loc
= loc
;
2735 DF_REF_CLASS (this_ref
) = cl
;
2736 DF_REF_ID (this_ref
) = -1;
2737 DF_REF_REG (this_ref
) = reg
;
2738 DF_REF_REGNO (this_ref
) = regno
;
2739 DF_REF_TYPE (this_ref
) = ref_type
;
2740 DF_REF_INSN_INFO (this_ref
) = info
;
2741 DF_REF_CHAIN (this_ref
) = NULL
;
2742 DF_REF_FLAGS (this_ref
) = ref_flags
;
2743 DF_REF_NEXT_REG (this_ref
) = NULL
;
2744 DF_REF_PREV_REG (this_ref
) = NULL
;
2745 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2747 /* We need to clear this bit because fwprop, and in the future
2748 possibly other optimizations sometimes create new refs using ond
2749 refs as the model. */
2750 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2752 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2753 if ((regno
< FIRST_PSEUDO_REGISTER
)
2754 && (!DF_REF_IS_ARTIFICIAL (this_ref
)))
2756 if (DF_REF_REG_DEF_P (this_ref
))
2758 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2759 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2761 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2762 && (regno
== FRAME_POINTER_REGNUM
2763 || regno
== ARG_POINTER_REGNUM
)))
2764 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2769 if (DF_REF_REG_DEF_P (this_ref
))
2770 collection_rec
->def_vec
[collection_rec
->next_def
++] = this_ref
;
2771 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2772 collection_rec
->eq_use_vec
[collection_rec
->next_eq_use
++] = this_ref
;
2774 collection_rec
->use_vec
[collection_rec
->next_use
++] = this_ref
;
2781 /* Create new references of type DF_REF_TYPE for each part of register REG
2782 at address LOC within INSN of BB.
2784 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2785 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
2786 fields if they were constants. Otherwise they should be -1 if
2787 those flags were set. */
2791 df_ref_record (enum df_ref_class cl
,
2792 struct df_collection_rec
*collection_rec
,
2794 basic_block bb
, struct df_insn_info
*insn_info
,
2795 enum df_ref_type ref_type
,
2797 int width
, int offset
, enum machine_mode mode
)
2801 gcc_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2803 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2804 if (regno
< FIRST_PSEUDO_REGISTER
)
2806 struct df_mw_hardreg
*hardreg
= NULL
;
2807 struct df_scan_problem_data
*problem_data
2808 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2810 unsigned int endregno
;
2813 if (GET_CODE (reg
) == SUBREG
)
2815 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2816 SUBREG_BYTE (reg
), GET_MODE (reg
));
2817 endregno
= regno
+ subreg_nregs (reg
);
2820 endregno
= END_HARD_REGNO (reg
);
2822 /* If this is a multiword hardreg, we create some extra
2823 datastructures that will enable us to easily build REG_DEAD
2824 and REG_UNUSED notes. */
2825 if ((endregno
!= regno
+ 1) && insn_info
)
2827 /* Sets to a subreg of a multiword register are partial.
2828 Sets to a non-subreg of a multiword register are not. */
2829 if (GET_CODE (reg
) == SUBREG
)
2830 ref_flags
|= DF_REF_PARTIAL
;
2831 ref_flags
|= DF_REF_MW_HARDREG
;
2833 hardreg
= (struct df_mw_hardreg
*) pool_alloc (problem_data
->mw_reg_pool
);
2834 hardreg
->type
= ref_type
;
2835 hardreg
->flags
= ref_flags
;
2836 hardreg
->mw_reg
= reg
;
2837 hardreg
->start_regno
= regno
;
2838 hardreg
->end_regno
= endregno
- 1;
2839 hardreg
->mw_order
= df
->ref_order
++;
2840 collection_rec
->mw_vec
[collection_rec
->next_mw
++] = hardreg
;
2843 for (i
= regno
; i
< endregno
; i
++)
2845 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2846 bb
, insn_info
, ref_type
, ref_flags
,
2847 width
, offset
, mode
);
2849 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2854 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2855 ref_type
, ref_flags
, width
, offset
, mode
);
2860 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2861 covered by the outer mode is smaller than that covered by the inner mode,
2862 is a read-modify-write operation.
2863 This function returns true iff the SUBREG X is such a SUBREG. */
2866 df_read_modify_subreg_p (rtx x
)
2868 unsigned int isize
, osize
;
2869 if (GET_CODE (x
) != SUBREG
)
2871 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2872 osize
= GET_MODE_SIZE (GET_MODE (x
));
2873 return isize
> osize
2874 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2878 /* Process all the registers defined in the rtx, X.
2879 Autoincrement/decrement definitions will be picked up by
2883 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2884 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2891 enum machine_mode mode
= VOIDmode
;
2892 enum df_ref_class cl
= DF_REF_REGULAR
;
2894 /* We may recursively call ourselves on EXPR_LIST when dealing with PARALLEL
2896 if (GET_CODE (x
) == EXPR_LIST
|| GET_CODE (x
) == CLOBBER
)
2899 loc
= &SET_DEST (x
);
2902 /* It is legal to have a set destination be a parallel. */
2903 if (GET_CODE (dst
) == PARALLEL
)
2907 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2909 rtx temp
= XVECEXP (dst
, 0, i
);
2910 if (GET_CODE (temp
) == EXPR_LIST
|| GET_CODE (temp
) == CLOBBER
2911 || GET_CODE (temp
) == SET
)
2912 df_def_record_1 (collection_rec
,
2913 temp
, bb
, insn_info
,
2914 GET_CODE (temp
) == CLOBBER
2915 ? flags
| DF_REF_MUST_CLOBBER
: flags
);
2920 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2922 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2924 loc
= &XEXP (dst
, 0);
2928 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2930 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2932 if (GET_CODE (XEXP (dst
, 1)) == CONST_INT
2933 && GET_CODE (XEXP (dst
, 2)) == CONST_INT
)
2935 width
= INTVAL (XEXP (dst
, 1));
2936 offset
= INTVAL (XEXP (dst
, 2));
2937 mode
= GET_MODE (dst
);
2938 cl
= DF_REF_EXTRACT
;
2941 loc
= &XEXP (dst
, 0);
2945 /* At this point if we do not have a reg or a subreg, just return. */
2948 df_ref_record (cl
, collection_rec
,
2949 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
,
2950 width
, offset
, mode
);
2952 /* We want to keep sp alive everywhere - by making all
2953 writes to sp also use of sp. */
2954 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2955 df_ref_record (DF_REF_BASE
, collection_rec
,
2956 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
,
2957 width
, offset
, mode
);
2959 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2961 if (df_read_modify_subreg_p (dst
))
2962 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2964 flags
|= DF_REF_SUBREG
;
2966 df_ref_record (cl
, collection_rec
,
2967 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
,
2968 width
, offset
, mode
);
2973 /* Process all the registers defined in the pattern rtx, X. */
2976 df_defs_record (struct df_collection_rec
*collection_rec
,
2977 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2980 RTX_CODE code
= GET_CODE (x
);
2982 if (code
== SET
|| code
== CLOBBER
)
2984 /* Mark the single def within the pattern. */
2985 int clobber_flags
= flags
;
2986 clobber_flags
|= (code
== CLOBBER
) ? DF_REF_MUST_CLOBBER
: 0;
2987 df_def_record_1 (collection_rec
, x
, bb
, insn_info
, clobber_flags
);
2989 else if (code
== COND_EXEC
)
2991 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
2992 bb
, insn_info
, DF_REF_CONDITIONAL
);
2994 else if (code
== PARALLEL
)
2998 /* Mark the multiple defs within the pattern. */
2999 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
3000 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
), bb
, insn_info
, flags
);
3005 /* Process all the registers used in the rtx at address LOC.
3007 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
3008 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
3009 fields if they were constants. Otherwise they should be -1 if
3010 those flags were set. */
3013 df_uses_record (enum df_ref_class cl
, struct df_collection_rec
*collection_rec
,
3014 rtx
*loc
, enum df_ref_type ref_type
,
3015 basic_block bb
, struct df_insn_info
*insn_info
,
3017 int width
, int offset
, enum machine_mode mode
)
3026 code
= GET_CODE (x
);
3043 /* If we are clobbering a MEM, mark any registers inside the address
3045 if (MEM_P (XEXP (x
, 0)))
3046 df_uses_record (cl
, collection_rec
,
3047 &XEXP (XEXP (x
, 0), 0),
3048 DF_REF_REG_MEM_STORE
,
3050 flags
, width
, offset
, mode
);
3052 /* If we're clobbering a REG then we have a def so ignore. */
3056 df_uses_record (cl
, collection_rec
,
3057 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
3058 bb
, insn_info
, flags
& DF_REF_IN_NOTE
,
3059 width
, offset
, mode
);
3063 /* While we're here, optimize this case. */
3064 flags
|= DF_REF_PARTIAL
;
3065 /* In case the SUBREG is not of a REG, do not optimize. */
3066 if (!REG_P (SUBREG_REG (x
)))
3068 loc
= &SUBREG_REG (x
);
3069 df_uses_record (cl
, collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
,
3070 width
, offset
, mode
);
3073 /* ... Fall through ... */
3076 df_ref_record (cl
, collection_rec
,
3077 x
, loc
, bb
, insn_info
,
3079 width
, offset
, mode
);
3085 /* If the parameters to the zero or sign extract are
3086 constants, strip them off and recurse, otherwise there is
3087 no information that we can gain from this operation. */
3088 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
3089 && GET_CODE (XEXP (x
, 2)) == CONST_INT
)
3091 width
= INTVAL (XEXP (x
, 1));
3092 offset
= INTVAL (XEXP (x
, 2));
3093 mode
= GET_MODE (x
);
3095 if (code
== ZERO_EXTRACT
)
3096 flags
|= DF_REF_ZERO_EXTRACT
;
3098 flags
|= DF_REF_SIGN_EXTRACT
;
3100 df_uses_record (DF_REF_EXTRACT
, collection_rec
,
3101 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
,
3102 width
, offset
, mode
);
3110 rtx dst
= SET_DEST (x
);
3111 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
3112 df_uses_record (cl
, collection_rec
,
3113 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
,
3114 width
, offset
, mode
);
3116 switch (GET_CODE (dst
))
3119 if (df_read_modify_subreg_p (dst
))
3121 df_uses_record (cl
, collection_rec
, &SUBREG_REG (dst
),
3122 DF_REF_REG_USE
, bb
, insn_info
,
3123 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
,
3124 width
, offset
, mode
);
3135 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 0),
3136 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
,
3137 width
, offset
, mode
);
3139 case STRICT_LOW_PART
:
3141 rtx
*temp
= &XEXP (dst
, 0);
3142 /* A strict_low_part uses the whole REG and not just the
3144 dst
= XEXP (dst
, 0);
3145 df_uses_record (cl
, collection_rec
,
3146 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
3147 DF_REF_REG_USE
, bb
, insn_info
,
3148 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
,
3149 width
, offset
, mode
);
3154 if (GET_CODE (XEXP (dst
, 1)) == CONST_INT
3155 && GET_CODE (XEXP (dst
, 2)) == CONST_INT
)
3157 width
= INTVAL (XEXP (dst
, 1));
3158 offset
= INTVAL (XEXP (dst
, 2));
3159 mode
= GET_MODE (dst
);
3160 df_uses_record (DF_REF_EXTRACT
, collection_rec
, &XEXP (dst
, 0),
3161 DF_REF_REG_USE
, bb
, insn_info
,
3162 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
,
3163 width
, offset
, mode
);
3167 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 1),
3168 DF_REF_REG_USE
, bb
, insn_info
, flags
,
3169 width
, offset
, mode
);
3170 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 2),
3171 DF_REF_REG_USE
, bb
, insn_info
, flags
,
3172 width
, offset
, mode
);
3173 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 0),
3174 DF_REF_REG_USE
, bb
, insn_info
,
3175 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
,
3176 width
, offset
, mode
);
3192 case UNSPEC_VOLATILE
:
3196 /* Traditional and volatile asm instructions must be
3197 considered to use and clobber all hard registers, all
3198 pseudo-registers and all of memory. So must TRAP_IF and
3199 UNSPEC_VOLATILE operations.
3201 Consider for instance a volatile asm that changes the fpu
3202 rounding mode. An insn should not be moved across this
3203 even if it only uses pseudo-regs because it might give an
3204 incorrectly rounded result.
3206 However, flow.c's liveness computation did *not* do this,
3207 giving the reasoning as " ?!? Unfortunately, marking all
3208 hard registers as live causes massive problems for the
3209 register allocator and marking all pseudos as live creates
3210 mountains of uninitialized variable warnings."
3212 In order to maintain the status quo with regard to liveness
3213 and uses, we do what flow.c did and just mark any regs we
3214 can find in ASM_OPERANDS as used. In global asm insns are
3215 scanned and regs_asm_clobbered is filled out.
3217 For all ASM_OPERANDS, we must traverse the vector of input
3218 operands. We can not just fall through here since then we
3219 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3220 which do not indicate traditional asms unlike their normal
3222 if (code
== ASM_OPERANDS
)
3226 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3227 df_uses_record (cl
, collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3228 DF_REF_REG_USE
, bb
, insn_info
, flags
,
3229 width
, offset
, mode
);
3241 /* Catch the def of the register being modified. */
3242 df_ref_record (cl
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3245 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
,
3246 width
, offset
, mode
);
3248 /* ... Fall through to handle uses ... */
3254 /* Recursively scan the operands of this expression. */
3256 const char *fmt
= GET_RTX_FORMAT (code
);
3259 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3263 /* Tail recursive case: save a function call level. */
3269 df_uses_record (cl
, collection_rec
, &XEXP (x
, i
), ref_type
,
3270 bb
, insn_info
, flags
,
3271 width
, offset
, mode
);
3273 else if (fmt
[i
] == 'E')
3276 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3277 df_uses_record (cl
, collection_rec
,
3278 &XVECEXP (x
, i
, j
), ref_type
,
3279 bb
, insn_info
, flags
,
3280 width
, offset
, mode
);
3289 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3292 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3295 for (i
= 0; i
< collection_rec
->next_def
; i
++)
3297 df_ref ref
= collection_rec
->def_vec
[i
];
3298 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3302 enum machine_mode mode
= VOIDmode
;
3305 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_SIGN_EXTRACT
| DF_REF_ZERO_EXTRACT
))
3307 width
= DF_REF_EXTRACT_WIDTH (ref
);
3308 offset
= DF_REF_EXTRACT_OFFSET (ref
);
3309 mode
= DF_REF_EXTRACT_MODE (ref
);
3312 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3313 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3314 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3315 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
,
3316 width
, offset
, mode
);
3317 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3323 /* Get call's extra defs and uses. */
3326 df_get_call_refs (struct df_collection_rec
* collection_rec
,
3328 struct df_insn_info
*insn_info
,
3334 bool is_sibling_call
;
3336 bitmap defs_generated
= BITMAP_ALLOC (&df_bitmap_obstack
);
3338 /* Do not generate clobbers for registers that are the result of the
3339 call. This causes ordering problems in the chain building code
3340 depending on which def is seen first. */
3341 for (i
=0; i
<collection_rec
->next_def
; i
++)
3343 df_ref def
= collection_rec
->def_vec
[i
];
3344 bitmap_set_bit (defs_generated
, DF_REF_REGNO (def
));
3347 /* Record the registers used to pass arguments, and explicitly
3348 noted as clobbered. */
3349 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3350 note
= XEXP (note
, 1))
3352 if (GET_CODE (XEXP (note
, 0)) == USE
)
3353 df_uses_record (DF_REF_REGULAR
, collection_rec
, &XEXP (XEXP (note
, 0), 0),
3354 DF_REF_REG_USE
, bb
, insn_info
, flags
, -1, -1,
3356 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3358 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3360 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3361 if (!bitmap_bit_p (defs_generated
, regno
))
3362 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3366 df_uses_record (DF_REF_REGULAR
, collection_rec
, &XEXP (note
, 0),
3367 DF_REF_REG_USE
, bb
, insn_info
, flags
, -1, -1,
3372 /* The stack ptr is used (honorarily) by a CALL insn. */
3373 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[STACK_POINTER_REGNUM
],
3374 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3375 DF_REF_CALL_STACK_USAGE
| flags
,
3378 /* Calls may also reference any of the global registers,
3379 so they are recorded as used. */
3380 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3383 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3384 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
, -1, -1,
3386 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3387 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
, -1, -1,
3391 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3392 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset
, 0, ui
, bi
)
3394 if (!global_regs
[ui
]
3395 && (!bitmap_bit_p (defs_generated
, ui
))
3396 && (!is_sibling_call
3397 || !bitmap_bit_p (df
->exit_block_uses
, ui
)
3398 || refers_to_regno_p (ui
, ui
+1,
3399 crtl
->return_rtx
, NULL
)))
3400 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[ui
],
3401 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3402 DF_REF_MAY_CLOBBER
| flags
,
3406 BITMAP_FREE (defs_generated
);
3410 /* Collect all refs in the INSN. This function is free of any
3411 side-effect - it will create and return a lists of df_ref's in the
3412 COLLECTION_REC without putting those refs into existing ref chains
3416 df_insn_refs_collect (struct df_collection_rec
* collection_rec
,
3417 basic_block bb
, struct df_insn_info
*insn_info
)
3420 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3422 /* Clear out the collection record. */
3423 collection_rec
->next_def
= 0;
3424 collection_rec
->next_use
= 0;
3425 collection_rec
->next_eq_use
= 0;
3426 collection_rec
->next_mw
= 0;
3428 /* Record register defs. */
3429 df_defs_record (collection_rec
, PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3431 /* Process REG_EQUIV/REG_EQUAL notes. */
3432 for (note
= REG_NOTES (insn_info
->insn
); note
;
3433 note
= XEXP (note
, 1))
3435 switch (REG_NOTE_KIND (note
))
3439 df_uses_record (DF_REF_REGULAR
, collection_rec
,
3440 &XEXP (note
, 0), DF_REF_REG_USE
,
3441 bb
, insn_info
, DF_REF_IN_NOTE
, -1, -1, VOIDmode
);
3443 case REG_NON_LOCAL_GOTO
:
3444 /* The frame ptr is used by a non-local goto. */
3445 df_ref_record (DF_REF_BASE
, collection_rec
,
3446 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3447 NULL
, bb
, insn_info
,
3448 DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
3449 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3450 df_ref_record (DF_REF_BASE
, collection_rec
,
3451 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3452 NULL
, bb
, insn_info
,
3453 DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
3461 if (CALL_P (insn_info
->insn
))
3462 df_get_call_refs (collection_rec
, bb
, insn_info
,
3463 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3465 /* Record the register uses. */
3466 df_uses_record (DF_REF_REGULAR
, collection_rec
,
3467 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0,
3470 /* DF_REF_CONDITIONAL needs corresponding USES. */
3472 df_get_conditional_uses (collection_rec
);
3474 df_canonize_collection_rec (collection_rec
);
3477 /* Recompute the luids for the insns in BB. */
3480 df_recompute_luids (basic_block bb
)
3485 df_grow_insn_info ();
3487 /* Scan the block an insn at a time from beginning to end. */
3488 FOR_BB_INSNS (bb
, insn
)
3490 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3491 /* Inserting labels does not always trigger the incremental
3495 gcc_assert (!INSN_P (insn
));
3496 insn_info
= df_insn_create_insn_record (insn
);
3499 DF_INSN_INFO_LUID (insn_info
) = luid
;
3506 /* Returns true if the function entry needs to
3507 define the static chain register. */
3510 df_need_static_chain_reg (struct function
*fun
)
3512 tree fun_context
= decl_function_context (fun
->decl
);
3514 && DECL_NO_STATIC_CHAIN (fun_context
) == false;
3518 /* Collect all artificial refs at the block level for BB and add them
3519 to COLLECTION_REC. */
3522 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3524 collection_rec
->next_def
= 0;
3525 collection_rec
->next_use
= 0;
3526 collection_rec
->next_eq_use
= 0;
3527 collection_rec
->next_mw
= 0;
3529 if (bb
->index
== ENTRY_BLOCK
)
3531 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3534 else if (bb
->index
== EXIT_BLOCK
)
3536 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3540 #ifdef EH_RETURN_DATA_REGNO
3541 if (bb_has_eh_pred (bb
))
3544 /* Mark the registers that will contain data for the handler. */
3547 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3548 if (regno
== INVALID_REGNUM
)
3550 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3551 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
, -1, -1,
3557 /* Add the hard_frame_pointer if this block is the target of a
3559 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3560 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3561 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
, -1, -1, VOIDmode
);
3563 /* Add the artificial uses. */
3564 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3568 bitmap au
= bb_has_eh_pred (bb
)
3569 ? df
->eh_block_artificial_uses
3570 : df
->regular_block_artificial_uses
;
3572 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3574 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3575 bb
, NULL
, DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
3579 df_canonize_collection_rec (collection_rec
);
3583 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3586 df_bb_refs_record (int bb_index
, bool scan_insns
)
3588 basic_block bb
= BASIC_BLOCK (bb_index
);
3591 struct df_scan_bb_info
*bb_info
;
3592 struct df_collection_rec collection_rec
;
3593 collection_rec
.def_vec
= XALLOCAVEC (df_ref
, 1000);
3594 collection_rec
.use_vec
= XALLOCAVEC (df_ref
, 1000);
3595 collection_rec
.eq_use_vec
= XALLOCAVEC (df_ref
, 1000);
3596 collection_rec
.mw_vec
= XALLOCAVEC (struct df_mw_hardreg
*, 100);
3601 bb_info
= df_scan_get_bb_info (bb_index
);
3603 /* Need to make sure that there is a record in the basic block info. */
3606 bb_info
= (struct df_scan_bb_info
*) pool_alloc (df_scan
->block_pool
);
3607 df_scan_set_bb_info (bb_index
, bb_info
);
3608 bb_info
->artificial_defs
= NULL
;
3609 bb_info
->artificial_uses
= NULL
;
3613 /* Scan the block an insn at a time from beginning to end. */
3614 FOR_BB_INSNS (bb
, insn
)
3616 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3617 gcc_assert (!insn_info
);
3619 insn_info
= df_insn_create_insn_record (insn
);
3622 /* Record refs within INSN. */
3623 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3624 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3625 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
3627 DF_INSN_INFO_LUID (insn_info
) = luid
;
3630 /* Other block level artificial refs */
3631 df_bb_refs_collect (&collection_rec
, bb
);
3632 df_refs_add_to_chains (&collection_rec
, bb
, NULL
);
3634 /* Now that the block has been processed, set the block as dirty so
3635 LR and LIVE will get it processed. */
3636 df_set_bb_dirty (bb
);
3640 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3644 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3650 bitmap_clear (regular_block_artificial_uses
);
3652 if (reload_completed
)
3654 if (frame_pointer_needed
)
3655 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3658 /* Before reload, there are a few registers that must be forced
3659 live everywhere -- which might not already be the case for
3660 blocks within infinite loops. */
3662 /* Any reference to any pseudo before reload is a potential
3663 reference of the frame pointer. */
3664 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3666 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3667 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3670 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3671 /* Pseudos with argument area equivalences may require
3672 reloading via the argument pointer. */
3673 if (fixed_regs
[ARG_POINTER_REGNUM
])
3674 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3677 /* Any constant, or pseudo with constant equivalences, may
3678 require reloading from memory using the pic register. */
3679 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
3680 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
3681 bitmap_set_bit (regular_block_artificial_uses
, PIC_OFFSET_TABLE_REGNUM
);
3683 /* The all-important stack pointer must always be live. */
3684 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3687 /* EH_USES registers are used:
3688 1) at all insns that might throw (calls or with -fnon-call-exceptions
3691 3) to support backtraces and/or debugging, anywhere between their
3692 initialization and where they the saved registers are restored
3693 from them, including the cases where we don't reach the epilogue
3694 (noreturn call or infinite loop). */
3695 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3697 bitmap_set_bit (regular_block_artificial_uses
, i
);
3702 /* Get the artificial use set for an eh block. */
3705 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3707 bitmap_clear (eh_block_artificial_uses
);
3709 /* The following code (down thru the arg_pointer setting APPEARS
3710 to be necessary because there is nothing that actually
3711 describes what the exception handling code may actually need
3713 if (reload_completed
)
3715 if (frame_pointer_needed
)
3717 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3718 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3719 bitmap_set_bit (eh_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3722 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3723 if (fixed_regs
[ARG_POINTER_REGNUM
])
3724 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3731 /*----------------------------------------------------------------------------
3732 Specialized hard register scanning functions.
3733 ----------------------------------------------------------------------------*/
3736 /* Mark a register in SET. Hard registers in large modes get all
3737 of their component registers set as well. */
3740 df_mark_reg (rtx reg
, void *vset
)
3742 bitmap set
= (bitmap
) vset
;
3743 int regno
= REGNO (reg
);
3745 gcc_assert (GET_MODE (reg
) != BLKmode
);
3747 bitmap_set_bit (set
, regno
);
3748 if (regno
< FIRST_PSEUDO_REGISTER
)
3750 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3752 bitmap_set_bit (set
, regno
+ n
);
3757 /* Set the bit for regs that are considered being defined at the entry. */
3760 df_get_entry_block_def_set (bitmap entry_block_defs
)
3765 bitmap_clear (entry_block_defs
);
3767 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3769 if (FUNCTION_ARG_REGNO_P (i
))
3770 #ifdef INCOMING_REGNO
3771 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3773 bitmap_set_bit (entry_block_defs
, i
);
3777 /* The always important stack pointer. */
3778 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3780 /* Once the prologue has been generated, all of these registers
3781 should just show up in the first regular block. */
3782 if (HAVE_prologue
&& epilogue_completed
)
3784 /* Defs for the callee saved registers are inserted so that the
3785 pushes have some defining location. */
3786 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3787 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3788 bitmap_set_bit (entry_block_defs
, i
);
3792 /* If STATIC_CHAIN_INCOMING_REGNUM == STATIC_CHAIN_REGNUM
3793 only STATIC_CHAIN_REGNUM is defined. If they are different,
3794 we only care about the STATIC_CHAIN_INCOMING_REGNUM. */
3795 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3796 bitmap_set_bit (entry_block_defs
, STATIC_CHAIN_INCOMING_REGNUM
);
3798 #ifdef STATIC_CHAIN_REGNUM
3799 bitmap_set_bit (entry_block_defs
, STATIC_CHAIN_REGNUM
);
3804 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3806 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3808 if ((!reload_completed
) || frame_pointer_needed
)
3810 /* Any reference to any pseudo before reload is a potential
3811 reference of the frame pointer. */
3812 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3813 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3814 /* If they are different, also mark the hard frame pointer as live. */
3815 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3816 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3820 /* These registers are live everywhere. */
3821 if (!reload_completed
)
3823 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3824 /* Pseudos with argument area equivalences may require
3825 reloading via the argument pointer. */
3826 if (fixed_regs
[ARG_POINTER_REGNUM
])
3827 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3830 #ifdef PIC_OFFSET_TABLE_REGNUM
3831 /* Any constant, or pseudo with constant equivalences, may
3832 require reloading from memory using the pic register. */
3833 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
3834 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
3835 bitmap_set_bit (entry_block_defs
, PIC_OFFSET_TABLE_REGNUM
);
3839 #ifdef INCOMING_RETURN_ADDR_RTX
3840 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3841 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3844 targetm
.live_on_entry (entry_block_defs
);
3846 /* If the function has an incoming STATIC_CHAIN,
3847 it has to show up in the entry def set. */
3848 if (df_need_static_chain_reg (cfun
))
3850 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3851 bitmap_set_bit (entry_block_defs
, STATIC_CHAIN_INCOMING_REGNUM
);
3853 #ifdef STATIC_CHAIN_REGNUM
3854 bitmap_set_bit (entry_block_defs
, STATIC_CHAIN_REGNUM
);
3861 /* Return the (conservative) set of hard registers that are defined on
3862 entry to the function.
3863 It uses df->entry_block_defs to determine which register
3864 reference to include. */
3867 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3868 bitmap entry_block_defs
)
3873 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3875 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3876 ENTRY_BLOCK_PTR
, NULL
, DF_REF_REG_DEF
, 0, -1, -1,
3880 df_canonize_collection_rec (collection_rec
);
3884 /* Record the (conservative) set of hard registers that are defined on
3885 entry to the function. */
3888 df_record_entry_block_defs (bitmap entry_block_defs
)
3890 struct df_collection_rec collection_rec
;
3891 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
3892 collection_rec
.def_vec
= XALLOCAVEC (df_ref
, FIRST_PSEUDO_REGISTER
);
3894 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3896 /* Process bb_refs chain */
3897 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (ENTRY_BLOCK
), NULL
);
3901 /* Update the defs in the entry block. */
3904 df_update_entry_block_defs (void)
3906 bitmap refs
= BITMAP_ALLOC (&df_bitmap_obstack
);
3907 bool changed
= false;
3909 df_get_entry_block_def_set (refs
);
3910 if (df
->entry_block_defs
)
3912 if (!bitmap_equal_p (df
->entry_block_defs
, refs
))
3914 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3915 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3916 df_ref_chain_delete (bb_info
->artificial_defs
);
3917 bb_info
->artificial_defs
= NULL
;
3923 struct df_scan_problem_data
*problem_data
3924 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3925 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3931 df_record_entry_block_defs (refs
);
3932 bitmap_copy (df
->entry_block_defs
, refs
);
3933 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
3939 /* Set the bit for regs that are considered being used at the exit. */
3942 df_get_exit_block_use_set (bitmap exit_block_uses
)
3946 bitmap_clear (exit_block_uses
);
3948 /* Stack pointer is always live at the exit. */
3949 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3951 /* Mark the frame pointer if needed at the end of the function.
3952 If we end up eliminating it, it will be removed from the live
3953 list of each basic block by reload. */
3955 if ((!reload_completed
) || frame_pointer_needed
)
3957 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3958 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3959 /* If they are different, also mark the hard frame pointer as live. */
3960 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3961 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3965 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3966 /* Many architectures have a GP register even without flag_pic.
3967 Assume the pic register is not in use, or will be handled by
3968 other means, if it is not fixed. */
3969 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
3970 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
3971 bitmap_set_bit (exit_block_uses
, PIC_OFFSET_TABLE_REGNUM
);
3974 /* Mark all global registers, and all registers used by the
3975 epilogue as being live at the end of the function since they
3976 may be referenced by our caller. */
3977 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3978 if (global_regs
[i
] || EPILOGUE_USES (i
))
3979 bitmap_set_bit (exit_block_uses
, i
);
3981 if (HAVE_epilogue
&& epilogue_completed
)
3983 /* Mark all call-saved registers that we actually used. */
3984 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3985 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
3986 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3987 bitmap_set_bit (exit_block_uses
, i
);
3990 #ifdef EH_RETURN_DATA_REGNO
3991 /* Mark the registers that will contain data for the handler. */
3992 if (reload_completed
&& crtl
->calls_eh_return
)
3995 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3996 if (regno
== INVALID_REGNUM
)
3998 bitmap_set_bit (exit_block_uses
, regno
);
4002 #ifdef EH_RETURN_STACKADJ_RTX
4003 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4004 && crtl
->calls_eh_return
)
4006 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
4007 if (tmp
&& REG_P (tmp
))
4008 df_mark_reg (tmp
, exit_block_uses
);
4012 #ifdef EH_RETURN_HANDLER_RTX
4013 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4014 && crtl
->calls_eh_return
)
4016 rtx tmp
= EH_RETURN_HANDLER_RTX
;
4017 if (tmp
&& REG_P (tmp
))
4018 df_mark_reg (tmp
, exit_block_uses
);
4022 /* Mark function return value. */
4023 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
4027 /* Return the refs of hard registers that are used in the exit block.
4028 It uses df->exit_block_uses to determine register to include. */
4031 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
4036 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
4037 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
4038 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
4040 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4041 /* It is deliberate that this is not put in the exit block uses but
4042 I do not know why. */
4043 if (reload_completed
4044 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
4045 && bb_has_eh_pred (EXIT_BLOCK_PTR
)
4046 && fixed_regs
[ARG_POINTER_REGNUM
])
4047 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
4048 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
4051 df_canonize_collection_rec (collection_rec
);
4055 /* Record the set of hard registers that are used in the exit block.
4056 It uses df->exit_block_uses to determine which bit to include. */
4059 df_record_exit_block_uses (bitmap exit_block_uses
)
4061 struct df_collection_rec collection_rec
;
4062 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4063 collection_rec
.use_vec
= XALLOCAVEC (df_ref
, FIRST_PSEUDO_REGISTER
);
4065 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
4067 /* Process bb_refs chain */
4068 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (EXIT_BLOCK
), NULL
);
4072 /* Update the uses in the exit block. */
4075 df_update_exit_block_uses (void)
4077 bitmap refs
= BITMAP_ALLOC (&df_bitmap_obstack
);
4078 bool changed
= false;
4080 df_get_exit_block_use_set (refs
);
4081 if (df
->exit_block_uses
)
4083 if (!bitmap_equal_p (df
->exit_block_uses
, refs
))
4085 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
4086 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
4087 df_ref_chain_delete (bb_info
->artificial_uses
);
4088 bb_info
->artificial_uses
= NULL
;
4094 struct df_scan_problem_data
*problem_data
4095 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
4096 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
4102 df_record_exit_block_uses (refs
);
4103 bitmap_copy (df
->exit_block_uses
, refs
);
4104 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
4109 static bool initialized
= false;
4112 /* Initialize some platform specific structures. */
4115 df_hard_reg_init (void)
4117 #ifdef ELIMINABLE_REGS
4119 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
4124 /* Record which registers will be eliminated. We use this in
4126 CLEAR_HARD_REG_SET (elim_reg_set
);
4128 #ifdef ELIMINABLE_REGS
4129 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
4130 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
4132 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
4139 /* Recompute the parts of scanning that are based on regs_ever_live
4140 because something changed in that array. */
4143 df_update_entry_exit_and_calls (void)
4147 df_update_entry_block_defs ();
4148 df_update_exit_block_uses ();
4150 /* The call insns need to be rescanned because there may be changes
4151 in the set of registers clobbered across the call. */
4155 FOR_BB_INSNS (bb
, insn
)
4157 if (INSN_P (insn
) && CALL_P (insn
))
4158 df_insn_rescan (insn
);
4164 /* Return true if hard REG is actually used in the some instruction.
4165 There are a fair number of conditions that affect the setting of
4166 this array. See the comment in df.h for df->hard_regs_live_count
4167 for the conditions that this array is set. */
4170 df_hard_reg_used_p (unsigned int reg
)
4173 return df
->hard_regs_live_count
[reg
] != 0;
4177 /* A count of the number of times REG is actually used in the some
4178 instruction. There are a fair number of conditions that affect the
4179 setting of this array. See the comment in df.h for
4180 df->hard_regs_live_count for the conditions that this array is
4185 df_hard_reg_used_count (unsigned int reg
)
4188 return df
->hard_regs_live_count
[reg
];
4192 /* Get the value of regs_ever_live[REGNO]. */
4195 df_regs_ever_live_p (unsigned int regno
)
4197 return regs_ever_live
[regno
];
4201 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
4202 to change, schedule that change for the next update. */
4205 df_set_regs_ever_live (unsigned int regno
, bool value
)
4207 if (regs_ever_live
[regno
] == value
)
4210 regs_ever_live
[regno
] = value
;
4212 df
->redo_entry_and_exit
= true;
4216 /* Compute "regs_ever_live" information from the underlying df
4217 information. Set the vector to all false if RESET. */
4220 df_compute_regs_ever_live (bool reset
)
4223 bool changed
= df
->redo_entry_and_exit
;
4226 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
4228 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4229 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
4231 regs_ever_live
[i
] = true;
4235 df_update_entry_exit_and_calls ();
4236 df
->redo_entry_and_exit
= false;
4240 /*----------------------------------------------------------------------------
4241 Dataflow ref information verification functions.
4243 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4244 df_reg_chain_verify_unmarked (refs)
4245 df_refs_verify (ref*, ref*, bool)
4246 df_mws_verify (mw*, mw*, bool)
4247 df_insn_refs_verify (collection_rec, bb, insn, bool)
4248 df_bb_refs_verify (bb, refs, bool)
4250 df_exit_block_bitmap_verify (bool)
4251 df_entry_block_bitmap_verify (bool)
4253 ----------------------------------------------------------------------------*/
4256 /* Mark all refs in the reg chain. Verify that all of the registers
4257 are in the correct chain. */
4260 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
4261 bool is_def
, bool is_eq_use
)
4263 unsigned int count
= 0;
4265 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4267 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4269 /* If there are no def-use or use-def chains, make sure that all
4270 of the chains are clear. */
4272 gcc_assert (!DF_REF_CHAIN (ref
));
4274 /* Check to make sure the ref is in the correct chain. */
4275 gcc_assert (DF_REF_REGNO (ref
) == regno
);
4277 gcc_assert (DF_REF_REG_DEF_P (ref
));
4279 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4282 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4284 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4286 if (DF_REF_NEXT_REG (ref
))
4287 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4289 DF_REF_REG_MARK (ref
);
4295 /* Verify that all of the registers in the chain are unmarked. */
4298 df_reg_chain_verify_unmarked (df_ref refs
)
4301 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4302 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4306 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4309 df_refs_verify (df_ref
*new_rec
, df_ref
*old_rec
,
4312 while ((*new_rec
) && (*old_rec
))
4314 if (!df_ref_equal_p (*new_rec
, *old_rec
))
4322 /* Abort if fail is called from the function level verifier. If
4323 that is the context, mark this reg as being seem. */
4326 gcc_assert (DF_REF_IS_REG_MARKED (*old_rec
));
4327 DF_REF_REG_UNMARK (*old_rec
);
4335 gcc_assert ((*new_rec
== NULL
) && (*old_rec
== NULL
));
4337 return ((*new_rec
== NULL
) && (*old_rec
== NULL
));
4342 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4345 df_mws_verify (struct df_mw_hardreg
**new_rec
, struct df_mw_hardreg
**old_rec
,
4348 while ((*new_rec
) && (*old_rec
))
4350 if (!df_mw_equal_p (*new_rec
, *old_rec
))
4362 gcc_assert ((*new_rec
== NULL
) && (*old_rec
== NULL
));
4364 return ((*new_rec
== NULL
) && (*old_rec
== NULL
));
4369 /* Return true if the existing insn refs information is complete and
4370 correct. Otherwise (i.e. if there's any missing or extra refs),
4371 return the correct df_ref chain in REFS_RETURN.
4373 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4374 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4375 verification mode instead of the whole function, so unmark
4378 If ABORT_IF_FAIL is set, this function never returns false. */
4381 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4386 bool ret1
, ret2
, ret3
, ret4
;
4387 unsigned int uid
= INSN_UID (insn
);
4388 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4390 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4392 if (!DF_INSN_UID_DEFS (uid
))
4394 /* The insn_rec was created but it was never filled out. */
4401 /* Unfortunately we cannot opt out early if one of these is not
4402 right because the marks will not get cleared. */
4403 ret1
= df_refs_verify (collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4405 ret2
= df_refs_verify (collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4407 ret3
= df_refs_verify (collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4409 ret4
= df_mws_verify (collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4411 return (ret1
&& ret2
&& ret3
&& ret4
);
4415 /* Return true if all refs in the basic block are correct and complete.
4416 Due to df_ref_chain_verify, it will cause all refs
4417 that are verified to have DF_REF_MARK bit set. */
4420 df_bb_verify (basic_block bb
)
4423 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4424 struct df_collection_rec collection_rec
;
4426 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4427 collection_rec
.def_vec
= XALLOCAVEC (df_ref
, 1000);
4428 collection_rec
.use_vec
= XALLOCAVEC (df_ref
, 1000);
4429 collection_rec
.eq_use_vec
= XALLOCAVEC (df_ref
, 1000);
4430 collection_rec
.mw_vec
= XALLOCAVEC (struct df_mw_hardreg
*, 100);
4432 gcc_assert (bb_info
);
4434 /* Scan the block, one insn at a time, from beginning to end. */
4435 FOR_BB_INSNS_REVERSE (bb
, insn
)
4439 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4440 df_free_collection_rec (&collection_rec
);
4443 /* Do the artificial defs and uses. */
4444 df_bb_refs_collect (&collection_rec
, bb
);
4445 df_refs_verify (collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4446 df_refs_verify (collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4447 df_free_collection_rec (&collection_rec
);
4453 /* Returns true if the entry block has correct and complete df_ref set.
4454 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4457 df_entry_block_bitmap_verify (bool abort_if_fail
)
4459 bitmap entry_block_defs
= BITMAP_ALLOC (&df_bitmap_obstack
);
4462 df_get_entry_block_def_set (entry_block_defs
);
4464 is_eq
= bitmap_equal_p (entry_block_defs
, df
->entry_block_defs
);
4466 if (!is_eq
&& abort_if_fail
)
4468 print_current_pass (stderr
);
4469 fprintf (stderr
, "entry_block_defs = ");
4470 df_print_regset (stderr
, entry_block_defs
);
4471 fprintf (stderr
, "df->entry_block_defs = ");
4472 df_print_regset (stderr
, df
->entry_block_defs
);
4476 BITMAP_FREE (entry_block_defs
);
4482 /* Returns true if the exit block has correct and complete df_ref set.
4483 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4486 df_exit_block_bitmap_verify (bool abort_if_fail
)
4488 bitmap exit_block_uses
= BITMAP_ALLOC (&df_bitmap_obstack
);
4491 df_get_exit_block_use_set (exit_block_uses
);
4493 is_eq
= bitmap_equal_p (exit_block_uses
, df
->exit_block_uses
);
4495 if (!is_eq
&& abort_if_fail
)
4497 print_current_pass (stderr
);
4498 fprintf (stderr
, "exit_block_uses = ");
4499 df_print_regset (stderr
, exit_block_uses
);
4500 fprintf (stderr
, "df->exit_block_uses = ");
4501 df_print_regset (stderr
, df
->exit_block_uses
);
4505 BITMAP_FREE (exit_block_uses
);
4511 /* Return true if df_ref information for all insns in all blocks are
4512 correct and complete. */
4515 df_scan_verify (void)
4519 bitmap regular_block_artificial_uses
;
4520 bitmap eh_block_artificial_uses
;
4525 /* Verification is a 4 step process. */
4527 /* (1) All of the refs are marked by going thru the reg chains. */
4528 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4530 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4531 == DF_REG_DEF_COUNT(i
));
4532 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4533 == DF_REG_USE_COUNT(i
));
4534 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4535 == DF_REG_EQ_USE_COUNT(i
));
4538 /* (2) There are various bitmaps whose value may change over the
4539 course of the compilation. This step recomputes them to make
4540 sure that they have not slipped out of date. */
4541 regular_block_artificial_uses
= BITMAP_ALLOC (&df_bitmap_obstack
);
4542 eh_block_artificial_uses
= BITMAP_ALLOC (&df_bitmap_obstack
);
4544 df_get_regular_block_artificial_uses (regular_block_artificial_uses
);
4545 df_get_eh_block_artificial_uses (eh_block_artificial_uses
);
4547 bitmap_ior_into (eh_block_artificial_uses
,
4548 regular_block_artificial_uses
);
4550 /* Check artificial_uses bitmaps didn't change. */
4551 gcc_assert (bitmap_equal_p (regular_block_artificial_uses
,
4552 df
->regular_block_artificial_uses
));
4553 gcc_assert (bitmap_equal_p (eh_block_artificial_uses
,
4554 df
->eh_block_artificial_uses
));
4556 BITMAP_FREE (regular_block_artificial_uses
);
4557 BITMAP_FREE (eh_block_artificial_uses
);
4559 /* Verify entry block and exit block. These only verify the bitmaps,
4560 the refs are verified in df_bb_verify. */
4561 df_entry_block_bitmap_verify (true);
4562 df_exit_block_bitmap_verify (true);
4564 /* (3) All of the insns in all of the blocks are traversed and the
4565 marks are cleared both in the artificial refs attached to the
4566 blocks and the real refs inside the insns. It is a failure to
4567 clear a mark that has not been set as this means that the ref in
4568 the block or insn was not in the reg chain. */
4573 /* (4) See if all reg chains are traversed a second time. This time
4574 a check is made that the marks are clear. A set mark would be a
4575 from a reg that is not in any insn or basic block. */
4577 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4579 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4580 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4581 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));