1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011, 2012 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"
35 #include "alloc-pool.h"
37 #include "hard-reg-set.h"
38 #include "basic-block.h"
44 #include "target-def.h"
46 #include "tree-pass.h"
47 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
50 DEF_VEC_ALLOC_P_STACK(df_ref
);
52 #define VEC_df_ref_stack_alloc(alloc) VEC_stack_alloc (df_ref, alloc)
54 typedef struct df_mw_hardreg
*df_mw_hardreg_ptr
;
56 DEF_VEC_P(df_mw_hardreg_ptr
);
57 DEF_VEC_ALLOC_P_STACK(df_mw_hardreg_ptr
);
59 #define VEC_df_mw_hardreg_ptr_stack_alloc(alloc) \
60 VEC_stack_alloc (df_mw_hardreg_ptr, alloc)
63 #define HAVE_epilogue 0
66 #define HAVE_prologue 0
68 #ifndef HAVE_sibcall_epilogue
69 #define HAVE_sibcall_epilogue 0
73 #define EPILOGUE_USES(REGNO) 0
76 /* The following two macros free the vecs that hold either the refs or
77 the mw refs. They are a little tricky because the vec has 0
78 elements is special and is not to be freed. */
79 #define df_scan_free_ref_vec(V) \
85 #define df_scan_free_mws_vec(V) \
91 /* The set of hard registers in eliminables[i].from. */
93 static HARD_REG_SET elim_reg_set
;
95 /* Initialize ur_in and ur_out as if all hard registers were partially
98 struct df_collection_rec
100 VEC(df_ref
,stack
) *def_vec
;
101 VEC(df_ref
,stack
) *use_vec
;
102 VEC(df_ref
,stack
) *eq_use_vec
;
103 VEC(df_mw_hardreg_ptr
,stack
) *mw_vec
;
106 static df_ref df_null_ref_rec
[1];
107 static struct df_mw_hardreg
* df_null_mw_rec
[1];
109 static void df_ref_record (enum df_ref_class
, struct df_collection_rec
*,
111 basic_block
, struct df_insn_info
*,
112 enum df_ref_type
, int ref_flags
);
113 static void df_def_record_1 (struct df_collection_rec
*, rtx
*,
114 basic_block
, struct df_insn_info
*,
116 static void df_defs_record (struct df_collection_rec
*, rtx
,
117 basic_block
, struct df_insn_info
*,
119 static void df_uses_record (struct df_collection_rec
*,
120 rtx
*, enum df_ref_type
,
121 basic_block
, struct df_insn_info
*,
124 static void df_install_ref_incremental (df_ref
);
125 static df_ref
df_ref_create_structure (enum df_ref_class
,
126 struct df_collection_rec
*, rtx
, rtx
*,
127 basic_block
, struct df_insn_info
*,
128 enum df_ref_type
, int ref_flags
);
129 static void df_insn_refs_collect (struct df_collection_rec
*,
130 basic_block
, struct df_insn_info
*);
131 static void df_canonize_collection_rec (struct df_collection_rec
*);
133 static void df_get_regular_block_artificial_uses (bitmap
);
134 static void df_get_eh_block_artificial_uses (bitmap
);
136 static void df_record_entry_block_defs (bitmap
);
137 static void df_record_exit_block_uses (bitmap
);
138 static void df_get_exit_block_use_set (bitmap
);
139 static void df_get_entry_block_def_set (bitmap
);
140 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
141 static void df_ref_chain_delete_du_chain (df_ref
*);
142 static void df_ref_chain_delete (df_ref
*);
144 static void df_refs_add_to_chains (struct df_collection_rec
*,
147 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
, rtx
, bool);
148 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
149 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
150 static void df_install_ref (df_ref
, struct df_reg_info
*,
151 struct df_ref_info
*, bool);
153 static int df_ref_compare (const void *, const void *);
154 static int df_mw_compare (const void *, const void *);
156 /* Indexed by hardware reg number, is true if that register is ever
157 used in the current function.
159 In df-scan.c, this is set up to record the hard regs used
160 explicitly. Reload adds in the hard regs used for holding pseudo
161 regs. Final uses it to generate the code in the function prologue
162 and epilogue to save and restore registers as needed. */
164 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
166 /*----------------------------------------------------------------------------
167 SCANNING DATAFLOW PROBLEM
169 There are several ways in which scanning looks just like the other
170 dataflow problems. It shares the all the mechanisms for local info
171 as well as basic block info. Where it differs is when and how often
172 it gets run. It also has no need for the iterative solver.
173 ----------------------------------------------------------------------------*/
175 /* Problem data for the scanning dataflow function. */
176 struct df_scan_problem_data
178 alloc_pool ref_base_pool
;
179 alloc_pool ref_artificial_pool
;
180 alloc_pool ref_regular_pool
;
181 alloc_pool insn_pool
;
183 alloc_pool mw_reg_pool
;
184 bitmap_obstack reg_bitmaps
;
185 bitmap_obstack insn_bitmaps
;
188 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
191 /* Internal function to shut down the scanning problem. */
193 df_scan_free_internal (void)
195 struct df_scan_problem_data
*problem_data
196 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
200 /* The vectors that hold the refs are not pool allocated because
201 they come in many sizes. This makes them impossible to delete
203 for (i
= 0; i
< DF_INSN_SIZE(); i
++)
205 struct df_insn_info
*insn_info
= DF_INSN_UID_GET(i
);
206 /* Skip the insns that have no insn_info or have been
210 df_scan_free_ref_vec (insn_info
->defs
);
211 df_scan_free_ref_vec (insn_info
->uses
);
212 df_scan_free_ref_vec (insn_info
->eq_uses
);
213 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
219 unsigned int bb_index
= bb
->index
;
220 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
223 df_scan_free_ref_vec (bb_info
->artificial_defs
);
224 df_scan_free_ref_vec (bb_info
->artificial_uses
);
228 free (df
->def_info
.refs
);
229 free (df
->def_info
.begin
);
230 free (df
->def_info
.count
);
231 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
233 free (df
->use_info
.refs
);
234 free (df
->use_info
.begin
);
235 free (df
->use_info
.count
);
236 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
242 free (df
->eq_use_regs
);
243 df
->eq_use_regs
= NULL
;
251 free (df_scan
->block_info
);
252 df_scan
->block_info
= NULL
;
253 df_scan
->block_info_size
= 0;
255 bitmap_clear (&df
->hardware_regs_used
);
256 bitmap_clear (&df
->regular_block_artificial_uses
);
257 bitmap_clear (&df
->eh_block_artificial_uses
);
258 BITMAP_FREE (df
->entry_block_defs
);
259 BITMAP_FREE (df
->exit_block_uses
);
260 bitmap_clear (&df
->insns_to_delete
);
261 bitmap_clear (&df
->insns_to_rescan
);
262 bitmap_clear (&df
->insns_to_notes_rescan
);
264 free_alloc_pool (problem_data
->ref_base_pool
);
265 free_alloc_pool (problem_data
->ref_artificial_pool
);
266 free_alloc_pool (problem_data
->ref_regular_pool
);
267 free_alloc_pool (problem_data
->insn_pool
);
268 free_alloc_pool (problem_data
->reg_pool
);
269 free_alloc_pool (problem_data
->mw_reg_pool
);
270 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
271 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
272 free (df_scan
->problem_data
);
276 /* Free basic block info. */
279 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
281 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
282 unsigned int bb_index
= bb
->index
;
284 /* See if bb_info is initialized. */
285 if (bb_info
->artificial_defs
)
288 FOR_BB_INSNS (bb
, insn
)
291 /* Record defs within INSN. */
292 df_insn_delete (bb
, INSN_UID (insn
));
295 if (bb_index
< df_scan
->block_info_size
)
296 bb_info
= df_scan_get_bb_info (bb_index
);
298 /* Get rid of any artificial uses or defs. */
299 if (bb_info
->artificial_defs
)
301 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
302 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
303 df_ref_chain_delete (bb_info
->artificial_defs
);
304 df_ref_chain_delete (bb_info
->artificial_uses
);
305 bb_info
->artificial_defs
= NULL
;
306 bb_info
->artificial_uses
= NULL
;
312 /* Allocate the problem data for the scanning problem. This should be
313 called when the problem is created or when the entire function is to
316 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
318 struct df_scan_problem_data
*problem_data
;
319 unsigned int insn_num
= get_max_uid () + 1;
320 unsigned int block_size
= 512;
323 /* Given the number of pools, this is really faster than tearing
325 if (df_scan
->problem_data
)
326 df_scan_free_internal ();
328 problem_data
= XNEW (struct df_scan_problem_data
);
329 df_scan
->problem_data
= problem_data
;
330 df_scan
->computed
= true;
332 problem_data
->ref_base_pool
333 = create_alloc_pool ("df_scan ref base",
334 sizeof (struct df_base_ref
), block_size
);
335 problem_data
->ref_artificial_pool
336 = create_alloc_pool ("df_scan ref artificial",
337 sizeof (struct df_artificial_ref
), block_size
);
338 problem_data
->ref_regular_pool
339 = create_alloc_pool ("df_scan ref regular",
340 sizeof (struct df_regular_ref
), block_size
);
341 problem_data
->insn_pool
342 = create_alloc_pool ("df_scan insn",
343 sizeof (struct df_insn_info
), block_size
);
344 problem_data
->reg_pool
345 = create_alloc_pool ("df_scan reg",
346 sizeof (struct df_reg_info
), block_size
);
347 problem_data
->mw_reg_pool
348 = create_alloc_pool ("df_scan mw_reg",
349 sizeof (struct df_mw_hardreg
), block_size
/ 16);
351 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
352 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
354 insn_num
+= insn_num
/ 4;
357 df_grow_insn_info ();
358 df_grow_bb_info (df_scan
);
362 unsigned int bb_index
= bb
->index
;
363 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
364 bb_info
->artificial_defs
= NULL
;
365 bb_info
->artificial_uses
= NULL
;
368 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
369 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
370 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
371 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
372 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
373 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
374 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
375 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
376 df_scan
->optional_p
= false;
380 /* Free all of the data associated with the scan problem. */
385 if (df_scan
->problem_data
)
386 df_scan_free_internal ();
388 if (df
->blocks_to_analyze
)
390 BITMAP_FREE (df
->blocks_to_analyze
);
391 df
->blocks_to_analyze
= NULL
;
397 /* Dump the preamble for DF_SCAN dump. */
399 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
410 fprintf (file
, ";; invalidated by call \t");
411 df_print_regset (file
, regs_invalidated_by_call_regset
);
412 fprintf (file
, ";; hardware regs used \t");
413 df_print_regset (file
, &df
->hardware_regs_used
);
414 fprintf (file
, ";; regular block artificial uses \t");
415 df_print_regset (file
, &df
->regular_block_artificial_uses
);
416 fprintf (file
, ";; eh block artificial uses \t");
417 df_print_regset (file
, &df
->eh_block_artificial_uses
);
418 fprintf (file
, ";; entry block defs \t");
419 df_print_regset (file
, df
->entry_block_defs
);
420 fprintf (file
, ";; exit block uses \t");
421 df_print_regset (file
, df
->exit_block_uses
);
422 fprintf (file
, ";; regs ever live \t");
423 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
424 if (df_regs_ever_live_p (i
))
425 fprintf (file
, " %d[%s]", i
, reg_names
[i
]);
426 fprintf (file
, "\n;; ref usage \t");
428 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
429 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
431 const char * sep
= "";
433 fprintf (file
, "r%d={", i
);
434 if (DF_REG_DEF_COUNT (i
))
436 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
438 dcount
+= DF_REG_DEF_COUNT (i
);
440 if (DF_REG_USE_COUNT (i
))
442 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
444 ucount
+= DF_REG_USE_COUNT (i
);
446 if (DF_REG_EQ_USE_COUNT (i
))
448 fprintf (file
, "%s%de", sep
, DF_REG_EQ_USE_COUNT (i
));
449 ecount
+= DF_REG_EQ_USE_COUNT (i
);
451 fprintf (file
, "} ");
455 FOR_BB_INSNS (bb
, insn
)
464 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de}"
465 " in %d{%d regular + %d call} insns.\n",
466 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
,
467 icount
+ ccount
, icount
, ccount
);
470 /* Dump the bb_info for a given basic block. */
472 df_scan_start_block (basic_block bb
, FILE *file
)
474 struct df_scan_bb_info
*bb_info
475 = df_scan_get_bb_info (bb
->index
);
479 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
480 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
481 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
482 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
483 fprintf (file
, "\n");
488 FOR_BB_INSNS (bb
, insn
)
490 df_insn_debug (insn
, false, file
);
495 static struct df_problem problem_SCAN
=
497 DF_SCAN
, /* Problem id. */
498 DF_NONE
, /* Direction. */
499 df_scan_alloc
, /* Allocate the problem specific data. */
500 NULL
, /* Reset global information. */
501 df_scan_free_bb_info
, /* Free basic block info. */
502 NULL
, /* Local compute function. */
503 NULL
, /* Init the solution specific data. */
504 NULL
, /* Iterative solver. */
505 NULL
, /* Confluence operator 0. */
506 NULL
, /* Confluence operator n. */
507 NULL
, /* Transfer function. */
508 NULL
, /* Finalize function. */
509 df_scan_free
, /* Free all of the problem information. */
510 NULL
, /* Remove this problem from the stack of dataflow problems. */
511 df_scan_start_dump
, /* Debugging. */
512 df_scan_start_block
, /* Debugging start block. */
513 NULL
, /* Debugging end block. */
514 NULL
, /* Incremental solution verify start. */
515 NULL
, /* Incremental solution verify end. */
516 NULL
, /* Dependent problem. */
517 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
518 TV_DF_SCAN
, /* Timing variable. */
519 false /* Reset blocks on dropping out of blocks_to_analyze. */
523 /* Create a new DATAFLOW instance and add it to an existing instance
524 of DF. The returned structure is what is used to get at the
528 df_scan_add_problem (void)
530 df_add_problem (&problem_SCAN
);
534 /*----------------------------------------------------------------------------
535 Storage Allocation Utilities
536 ----------------------------------------------------------------------------*/
539 /* First, grow the reg_info information. If the current size is less than
540 the number of pseudos, grow to 25% more than the number of
543 Second, assure that all of the slots up to max_reg_num have been
544 filled with reg_info structures. */
547 df_grow_reg_info (void)
549 unsigned int max_reg
= max_reg_num ();
550 unsigned int new_size
= max_reg
;
551 struct df_scan_problem_data
*problem_data
552 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
555 if (df
->regs_size
< new_size
)
557 new_size
+= new_size
/ 4;
558 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
559 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
560 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
562 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
563 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
564 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
565 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
566 df
->regs_size
= new_size
;
569 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
571 struct df_reg_info
*reg_info
;
573 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
574 memset (reg_info
, 0, sizeof (struct df_reg_info
));
575 df
->def_regs
[i
] = reg_info
;
576 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
577 memset (reg_info
, 0, sizeof (struct df_reg_info
));
578 df
->use_regs
[i
] = reg_info
;
579 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
580 memset (reg_info
, 0, sizeof (struct df_reg_info
));
581 df
->eq_use_regs
[i
] = reg_info
;
582 df
->def_info
.begin
[i
] = 0;
583 df
->def_info
.count
[i
] = 0;
584 df
->use_info
.begin
[i
] = 0;
585 df
->use_info
.count
[i
] = 0;
588 df
->regs_inited
= max_reg
;
592 /* Grow the ref information. */
595 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
597 if (ref_info
->refs_size
< new_size
)
599 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
600 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
601 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
602 ref_info
->refs_size
= new_size
;
607 /* Check and grow the ref information if necessary. This routine
608 guarantees total_size + BITMAP_ADDEND amount of entries in refs
609 array. It updates ref_info->refs_size only and does not change
610 ref_info->total_size. */
613 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
614 unsigned bitmap_addend
)
616 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
618 int new_size
= ref_info
->total_size
+ bitmap_addend
;
619 new_size
+= ref_info
->total_size
/ 4;
620 df_grow_ref_info (ref_info
, new_size
);
625 /* Grow the ref information. If the current size is less than the
626 number of instructions, grow to 25% more than the number of
630 df_grow_insn_info (void)
632 unsigned int new_size
= get_max_uid () + 1;
633 if (DF_INSN_SIZE () < new_size
)
635 new_size
+= new_size
/ 4;
636 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
637 memset (df
->insns
+ df
->insns_size
, 0,
638 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
639 DF_INSN_SIZE () = new_size
;
646 /*----------------------------------------------------------------------------
647 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
648 ----------------------------------------------------------------------------*/
650 /* Rescan all of the block_to_analyze or all of the blocks in the
651 function if df_set_blocks if blocks_to_analyze is NULL; */
654 df_scan_blocks (void)
658 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
659 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
661 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
662 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
664 bitmap_ior_into (&df
->eh_block_artificial_uses
,
665 &df
->regular_block_artificial_uses
);
667 /* ENTRY and EXIT blocks have special defs/uses. */
668 df_get_entry_block_def_set (df
->entry_block_defs
);
669 df_record_entry_block_defs (df
->entry_block_defs
);
670 df_get_exit_block_use_set (df
->exit_block_uses
);
671 df_record_exit_block_uses (df
->exit_block_uses
);
672 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
673 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
678 unsigned int bb_index
= bb
->index
;
679 df_bb_refs_record (bb_index
, true);
683 /* Create new refs under address LOC within INSN. This function is
684 only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
685 depending on whether LOC is inside PATTERN (INSN) or a note. */
688 df_uses_create (rtx
*loc
, rtx insn
, int ref_flags
)
690 gcc_assert (!(ref_flags
& ~DF_REF_IN_NOTE
));
691 df_uses_record (NULL
, loc
, DF_REF_REG_USE
,
692 BLOCK_FOR_INSN (insn
),
693 DF_INSN_INFO_GET (insn
),
697 /* Create a new ref of type DF_REF_TYPE for register REG at address
698 LOC within INSN of BB. This function is only used externally. */
701 df_ref_create (rtx reg
, rtx
*loc
, rtx insn
,
703 enum df_ref_type ref_type
,
706 enum df_ref_class cl
;
710 /* You cannot hack artificial refs. */
718 return df_ref_create_structure (cl
, NULL
, reg
, loc
, bb
,
719 DF_INSN_INFO_GET (insn
),
720 ref_type
, ref_flags
);
724 df_install_ref_incremental (df_ref ref
)
726 struct df_reg_info
**reg_info
;
727 struct df_ref_info
*ref_info
;
729 df_ref
**ref_rec_ptr
;
730 unsigned int count
= 0;
733 rtx insn
= DF_REF_INSN (ref
);
734 basic_block bb
= BLOCK_FOR_INSN (insn
);
736 if (DF_REF_REG_DEF_P (ref
))
738 reg_info
= df
->def_regs
;
739 ref_info
= &df
->def_info
;
740 ref_rec_ptr
= &DF_INSN_DEFS (insn
);
741 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
743 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
745 reg_info
= df
->eq_use_regs
;
746 ref_info
= &df
->use_info
;
747 ref_rec_ptr
= &DF_INSN_EQ_USES (insn
);
748 switch (ref_info
->ref_order
)
750 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
751 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
752 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
756 add_to_table
= false;
762 reg_info
= df
->use_regs
;
763 ref_info
= &df
->use_info
;
764 ref_rec_ptr
= &DF_INSN_USES (insn
);
765 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
768 /* Do not add if ref is not in the right blocks. */
769 if (add_to_table
&& df
->analyze_subset
)
770 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
772 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
775 switch (ref_info
->ref_order
)
777 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
778 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
779 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
780 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
783 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
787 ref_rec
= *ref_rec_ptr
;
794 ref_rec
= *ref_rec_ptr
;
797 ref_rec
= XRESIZEVEC (df_ref
, ref_rec
, count
+2);
798 *ref_rec_ptr
= ref_rec
;
799 ref_rec
[count
] = ref
;
800 ref_rec
[count
+1] = NULL
;
801 qsort (ref_rec
, count
+ 1, sizeof (df_ref
), df_ref_compare
);
805 df_ref
*ref_rec
= XNEWVEC (df_ref
, 2);
808 *ref_rec_ptr
= ref_rec
;
814 fprintf (dump_file
, "adding ref ");
815 df_ref_debug (ref
, dump_file
);
818 /* By adding the ref directly, df_insn_rescan my not find any
819 differences even though the block will have changed. So we need
820 to mark the block dirty ourselves. */
821 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
822 df_set_bb_dirty (bb
);
827 /*----------------------------------------------------------------------------
828 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
829 ----------------------------------------------------------------------------*/
832 df_free_ref (df_ref ref
)
834 struct df_scan_problem_data
*problem_data
835 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
837 switch (DF_REF_CLASS (ref
))
840 pool_free (problem_data
->ref_base_pool
, ref
);
843 case DF_REF_ARTIFICIAL
:
844 pool_free (problem_data
->ref_artificial_pool
, ref
);
848 pool_free (problem_data
->ref_regular_pool
, ref
);
854 /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
855 Also delete the def-use or use-def chain if it exists. */
858 df_reg_chain_unlink (df_ref ref
)
860 df_ref next
= DF_REF_NEXT_REG (ref
);
861 df_ref prev
= DF_REF_PREV_REG (ref
);
862 int id
= DF_REF_ID (ref
);
863 struct df_reg_info
*reg_info
;
866 if (DF_REF_REG_DEF_P (ref
))
868 int regno
= DF_REF_REGNO (ref
);
869 reg_info
= DF_REG_DEF_GET (regno
);
870 refs
= df
->def_info
.refs
;
874 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
876 reg_info
= DF_REG_EQ_USE_GET (DF_REF_REGNO (ref
));
877 switch (df
->use_info
.ref_order
)
879 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
880 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
881 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
882 refs
= df
->use_info
.refs
;
890 reg_info
= DF_REG_USE_GET (DF_REF_REGNO (ref
));
891 refs
= df
->use_info
.refs
;
897 if (df
->analyze_subset
)
899 if (bitmap_bit_p (df
->blocks_to_analyze
, DF_REF_BBNO (ref
)))
906 /* Delete any def-use or use-def chains that start here. It is
907 possible that there is trash in this field. This happens for
908 insns that have been deleted when rescanning has been deferred
909 and the chain problem has also been deleted. The chain tear down
910 code skips deleted insns. */
911 if (df_chain
&& DF_REF_CHAIN (ref
))
912 df_chain_unlink (ref
);
915 if (DF_REF_FLAGS_IS_SET (ref
, DF_HARD_REG_LIVE
))
917 gcc_assert (DF_REF_REGNO (ref
) < FIRST_PSEUDO_REGISTER
);
918 df
->hard_regs_live_count
[DF_REF_REGNO (ref
)]--;
921 /* Unlink from the reg chain. If there is no prev, this is the
922 first of the list. If not, just join the next and prev. */
924 DF_REF_NEXT_REG (prev
) = next
;
927 gcc_assert (reg_info
->reg_chain
== ref
);
928 reg_info
->reg_chain
= next
;
931 DF_REF_PREV_REG (next
) = prev
;
937 /* Remove REF from VEC. */
940 df_ref_compress_rec (df_ref
**vec_ptr
, df_ref ref
)
942 df_ref
*vec
= *vec_ptr
;
946 while (*vec
&& *vec
!= ref
)
958 *vec_ptr
= df_null_ref_rec
;
963 /* Unlink REF from all def-use/use-def chains, etc. */
966 df_ref_remove (df_ref ref
)
971 fprintf (dump_file
, "removing ref ");
972 df_ref_debug (ref
, dump_file
);
976 if (DF_REF_REG_DEF_P (ref
))
978 if (DF_REF_IS_ARTIFICIAL (ref
))
980 struct df_scan_bb_info
*bb_info
981 = df_scan_get_bb_info (DF_REF_BBNO (ref
));
982 df_ref_compress_rec (&bb_info
->artificial_defs
, ref
);
986 unsigned int uid
= DF_REF_INSN_UID (ref
);
987 struct df_insn_info
*insn_rec
= DF_INSN_UID_GET (uid
);
988 df_ref_compress_rec (&insn_rec
->defs
, ref
);
993 if (DF_REF_IS_ARTIFICIAL (ref
))
995 struct df_scan_bb_info
*bb_info
996 = df_scan_get_bb_info (DF_REF_BBNO (ref
));
997 df_ref_compress_rec (&bb_info
->artificial_uses
, ref
);
1001 unsigned int uid
= DF_REF_INSN_UID (ref
);
1002 struct df_insn_info
*insn_rec
= DF_INSN_UID_GET (uid
);
1004 if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
1005 df_ref_compress_rec (&insn_rec
->eq_uses
, ref
);
1007 df_ref_compress_rec (&insn_rec
->uses
, ref
);
1011 /* By deleting the ref directly, df_insn_rescan my not find any
1012 differences even though the block will have changed. So we need
1013 to mark the block dirty ourselves. */
1014 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
1015 df_set_bb_dirty (DF_REF_BB (ref
));
1016 df_reg_chain_unlink (ref
);
1020 /* Create the insn record for INSN. If there was one there, zero it
1023 struct df_insn_info
*
1024 df_insn_create_insn_record (rtx insn
)
1026 struct df_scan_problem_data
*problem_data
1027 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1028 struct df_insn_info
*insn_rec
;
1030 df_grow_insn_info ();
1031 insn_rec
= DF_INSN_INFO_GET (insn
);
1034 insn_rec
= (struct df_insn_info
*) pool_alloc (problem_data
->insn_pool
);
1035 DF_INSN_INFO_SET (insn
, insn_rec
);
1037 memset (insn_rec
, 0, sizeof (struct df_insn_info
));
1038 insn_rec
->insn
= insn
;
1043 /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
1046 df_ref_chain_delete_du_chain (df_ref
*ref_rec
)
1050 df_ref ref
= *ref_rec
;
1051 /* CHAIN is allocated by DF_CHAIN. So make sure to
1052 pass df_scan instance for the problem. */
1053 if (DF_REF_CHAIN (ref
))
1054 df_chain_unlink (ref
);
1060 /* Delete all refs in the ref chain. */
1063 df_ref_chain_delete (df_ref
*ref_rec
)
1065 df_ref
*start
= ref_rec
;
1068 df_reg_chain_unlink (*ref_rec
);
1072 /* If the list is empty, it has a special shared element that is not
1079 /* Delete the hardreg chain. */
1082 df_mw_hardreg_chain_delete (struct df_mw_hardreg
**hardregs
)
1084 struct df_scan_problem_data
*problem_data
;
1089 problem_data
= (struct df_scan_problem_data
*) df_scan
->problem_data
;
1093 pool_free (problem_data
->mw_reg_pool
, *hardregs
);
1099 /* Delete all of the refs information from INSN. BB must be passed in
1100 except when called from df_process_deferred_rescans to mark the block
1104 df_insn_delete (basic_block bb
, unsigned int uid
)
1106 struct df_insn_info
*insn_info
= NULL
;
1110 df_grow_bb_info (df_scan
);
1111 df_grow_reg_info ();
1113 /* The block must be marked as dirty now, rather than later as in
1114 df_insn_rescan and df_notes_rescan because it may not be there at
1115 rescanning time and the mark would blow up. */
1117 df_set_bb_dirty (bb
);
1119 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1121 /* The client has deferred rescanning. */
1122 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1126 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1127 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1128 bitmap_set_bit (&df
->insns_to_delete
, uid
);
1131 fprintf (dump_file
, "deferring deletion of insn with uid = %d.\n", uid
);
1136 fprintf (dump_file
, "deleting insn with uid = %d.\n", uid
);
1138 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1139 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1140 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1143 struct df_scan_problem_data
*problem_data
1144 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1146 /* In general, notes do not have the insn_info fields
1147 initialized. However, combine deletes insns by changing them
1148 to notes. How clever. So we cannot just check if it is a
1149 valid insn before short circuiting this code, we need to see
1150 if we actually initialized it. */
1151 if (insn_info
->defs
)
1153 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1157 df_ref_chain_delete_du_chain (insn_info
->defs
);
1158 df_ref_chain_delete_du_chain (insn_info
->uses
);
1159 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1162 df_ref_chain_delete (insn_info
->defs
);
1163 df_ref_chain_delete (insn_info
->uses
);
1164 df_ref_chain_delete (insn_info
->eq_uses
);
1166 pool_free (problem_data
->insn_pool
, insn_info
);
1167 DF_INSN_UID_SET (uid
, NULL
);
1172 /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
1175 df_free_collection_rec (struct df_collection_rec
*collection_rec
)
1178 struct df_scan_problem_data
*problem_data
1179 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
1181 struct df_mw_hardreg
*mw
;
1183 FOR_EACH_VEC_ELT (df_ref
, collection_rec
->def_vec
, ix
, ref
)
1185 FOR_EACH_VEC_ELT (df_ref
, collection_rec
->use_vec
, ix
, ref
)
1187 FOR_EACH_VEC_ELT (df_ref
, collection_rec
->eq_use_vec
, ix
, ref
)
1189 FOR_EACH_VEC_ELT (df_mw_hardreg_ptr
, collection_rec
->mw_vec
, ix
, mw
)
1190 pool_free (problem_data
->mw_reg_pool
, mw
);
1192 VEC_free (df_ref
, stack
, collection_rec
->def_vec
);
1193 VEC_free (df_ref
, stack
, collection_rec
->use_vec
);
1194 VEC_free (df_ref
, stack
, collection_rec
->eq_use_vec
);
1195 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
->mw_vec
);
1198 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1201 df_insn_rescan (rtx insn
)
1203 unsigned int uid
= INSN_UID (insn
);
1204 struct df_insn_info
*insn_info
= NULL
;
1205 basic_block bb
= BLOCK_FOR_INSN (insn
);
1206 struct df_collection_rec collection_rec
;
1208 if ((!df
) || (!INSN_P (insn
)))
1214 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1218 /* The client has disabled rescanning and plans to do it itself. */
1219 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1222 df_grow_bb_info (df_scan
);
1223 df_grow_reg_info ();
1225 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1227 /* The client has deferred rescanning. */
1228 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1232 insn_info
= df_insn_create_insn_record (insn
);
1233 insn_info
->defs
= df_null_ref_rec
;
1234 insn_info
->uses
= df_null_ref_rec
;
1235 insn_info
->eq_uses
= df_null_ref_rec
;
1236 insn_info
->mw_hardregs
= df_null_mw_rec
;
1239 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1241 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1242 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1243 bitmap_set_bit (&df
->insns_to_rescan
, INSN_UID (insn
));
1247 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, 128);
1248 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, 32);
1249 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
1250 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
1252 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1253 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1254 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1258 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1259 /* If there's no change, return false. */
1262 df_free_collection_rec (&collection_rec
);
1264 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1268 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1270 /* There's change - we need to delete the existing info.
1271 Since the insn isn't moved, we can salvage its LUID. */
1272 luid
= DF_INSN_LUID (insn
);
1273 df_insn_delete (NULL
, uid
);
1274 df_insn_create_insn_record (insn
);
1275 DF_INSN_LUID (insn
) = luid
;
1279 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1280 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1282 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1285 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
1286 if (!DEBUG_INSN_P (insn
))
1287 df_set_bb_dirty (bb
);
1289 VEC_free (df_ref
, stack
, collection_rec
.def_vec
);
1290 VEC_free (df_ref
, stack
, collection_rec
.use_vec
);
1291 VEC_free (df_ref
, stack
, collection_rec
.eq_use_vec
);
1292 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
.mw_vec
);
1297 /* Same as df_insn_rescan, but don't mark the basic block as
1301 df_insn_rescan_debug_internal (rtx insn
)
1303 unsigned int uid
= INSN_UID (insn
);
1304 struct df_insn_info
*insn_info
;
1306 gcc_assert (DEBUG_INSN_P (insn
)
1307 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn
)));
1312 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1317 fprintf (dump_file
, "deleting debug_insn with uid = %d.\n", uid
);
1319 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1320 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1321 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1323 if (!insn_info
->defs
)
1326 if (insn_info
->defs
== df_null_ref_rec
1327 && insn_info
->uses
== df_null_ref_rec
1328 && insn_info
->eq_uses
== df_null_ref_rec
1329 && insn_info
->mw_hardregs
== df_null_mw_rec
)
1332 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1336 df_ref_chain_delete_du_chain (insn_info
->defs
);
1337 df_ref_chain_delete_du_chain (insn_info
->uses
);
1338 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1341 df_ref_chain_delete (insn_info
->defs
);
1342 df_ref_chain_delete (insn_info
->uses
);
1343 df_ref_chain_delete (insn_info
->eq_uses
);
1345 insn_info
->defs
= df_null_ref_rec
;
1346 insn_info
->uses
= df_null_ref_rec
;
1347 insn_info
->eq_uses
= df_null_ref_rec
;
1348 insn_info
->mw_hardregs
= df_null_mw_rec
;
1354 /* Rescan all of the insns in the function. Note that the artificial
1355 uses and defs are not touched. This function will destroy def-se
1356 or use-def chains. */
1359 df_insn_rescan_all (void)
1361 bool no_insn_rescan
= false;
1362 bool defer_insn_rescan
= false;
1368 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1370 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1372 df_clear_flags (DF_NO_INSN_RESCAN
);
1373 no_insn_rescan
= true;
1376 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1378 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1379 defer_insn_rescan
= true;
1382 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1383 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1385 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1387 df_insn_delete (NULL
, uid
);
1390 bitmap_clear (&tmp
);
1391 bitmap_clear (&df
->insns_to_delete
);
1392 bitmap_clear (&df
->insns_to_rescan
);
1393 bitmap_clear (&df
->insns_to_notes_rescan
);
1398 FOR_BB_INSNS (bb
, insn
)
1400 df_insn_rescan (insn
);
1405 df_set_flags (DF_NO_INSN_RESCAN
);
1406 if (defer_insn_rescan
)
1407 df_set_flags (DF_DEFER_INSN_RESCAN
);
1411 /* Process all of the deferred rescans or deletions. */
1414 df_process_deferred_rescans (void)
1416 bool no_insn_rescan
= false;
1417 bool defer_insn_rescan
= false;
1422 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1424 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1426 df_clear_flags (DF_NO_INSN_RESCAN
);
1427 no_insn_rescan
= true;
1430 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1432 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1433 defer_insn_rescan
= true;
1437 fprintf (dump_file
, "starting the processing of deferred insns\n");
1439 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1440 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1442 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1444 df_insn_delete (NULL
, uid
);
1447 bitmap_copy (&tmp
, &df
->insns_to_rescan
);
1448 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1450 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1452 df_insn_rescan (insn_info
->insn
);
1455 bitmap_copy (&tmp
, &df
->insns_to_notes_rescan
);
1456 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1458 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1460 df_notes_rescan (insn_info
->insn
);
1464 fprintf (dump_file
, "ending the processing of deferred insns\n");
1466 bitmap_clear (&tmp
);
1467 bitmap_clear (&df
->insns_to_delete
);
1468 bitmap_clear (&df
->insns_to_rescan
);
1469 bitmap_clear (&df
->insns_to_notes_rescan
);
1472 df_set_flags (DF_NO_INSN_RESCAN
);
1473 if (defer_insn_rescan
)
1474 df_set_flags (DF_DEFER_INSN_RESCAN
);
1476 /* If someone changed regs_ever_live during this pass, fix up the
1477 entry and exit blocks. */
1478 if (df
->redo_entry_and_exit
)
1480 df_update_entry_exit_and_calls ();
1481 df
->redo_entry_and_exit
= false;
1486 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1487 the uses if INCLUDE_USES. Include the eq_uses if
1491 df_count_refs (bool include_defs
, bool include_uses
,
1492 bool include_eq_uses
)
1496 unsigned int m
= df
->regs_inited
;
1498 for (regno
= 0; regno
< m
; regno
++)
1501 size
+= DF_REG_DEF_COUNT (regno
);
1503 size
+= DF_REG_USE_COUNT (regno
);
1504 if (include_eq_uses
)
1505 size
+= DF_REG_EQ_USE_COUNT (regno
);
1511 /* Take build ref table for either the uses or defs from the reg-use
1512 or reg-def chains. This version processes the refs in reg order
1513 which is likely to be best if processing the whole function. */
1516 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1519 bool include_eq_uses
)
1521 unsigned int m
= df
->regs_inited
;
1523 unsigned int offset
= 0;
1526 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1528 start
= FIRST_PSEUDO_REGISTER
;
1529 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1530 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1535 ref_info
->total_size
1536 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1538 df_check_and_grow_ref_info (ref_info
, 1);
1540 for (regno
= start
; regno
< m
; regno
++)
1543 ref_info
->begin
[regno
] = offset
;
1546 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1549 ref_info
->refs
[offset
] = ref
;
1550 DF_REF_ID (ref
) = offset
++;
1552 ref
= DF_REF_NEXT_REG (ref
);
1553 gcc_checking_assert (offset
< ref_info
->refs_size
);
1558 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1561 ref_info
->refs
[offset
] = ref
;
1562 DF_REF_ID (ref
) = offset
++;
1564 ref
= DF_REF_NEXT_REG (ref
);
1565 gcc_checking_assert (offset
< ref_info
->refs_size
);
1568 if (include_eq_uses
)
1570 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1573 ref_info
->refs
[offset
] = ref
;
1574 DF_REF_ID (ref
) = offset
++;
1576 ref
= DF_REF_NEXT_REG (ref
);
1577 gcc_checking_assert (offset
< ref_info
->refs_size
);
1580 ref_info
->count
[regno
] = count
;
1583 /* The bitmap size is not decremented when refs are deleted. So
1584 reset it now that we have squished out all of the empty
1586 ref_info
->table_size
= offset
;
1590 /* Take build ref table for either the uses or defs from the reg-use
1591 or reg-def chains. This version processes the refs in insn order
1592 which is likely to be best if processing some segment of the
1596 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1599 bool include_eq_uses
)
1602 unsigned int bb_index
;
1603 unsigned int m
= df
->regs_inited
;
1604 unsigned int offset
= 0;
1607 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1609 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1610 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1612 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1613 df_check_and_grow_ref_info (ref_info
, 1);
1615 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1617 basic_block bb
= BASIC_BLOCK (bb_index
);
1622 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1624 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1625 ref_info
->count
[regno
]++;
1628 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1630 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1631 ref_info
->count
[regno
]++;
1634 FOR_BB_INSNS (bb
, insn
)
1638 unsigned int uid
= INSN_UID (insn
);
1641 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1643 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1644 ref_info
->count
[regno
]++;
1647 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1649 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1650 ref_info
->count
[regno
]++;
1652 if (include_eq_uses
)
1653 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1655 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1656 ref_info
->count
[regno
]++;
1662 for (r
= start
; r
< m
; r
++)
1664 ref_info
->begin
[r
] = offset
;
1665 offset
+= ref_info
->count
[r
];
1666 ref_info
->count
[r
] = 0;
1669 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1671 basic_block bb
= BASIC_BLOCK (bb_index
);
1676 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1678 df_ref ref
= *ref_rec
;
1679 unsigned int regno
= DF_REF_REGNO (ref
);
1683 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1684 DF_REF_ID (ref
) = id
;
1685 ref_info
->refs
[id
] = ref
;
1689 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1691 df_ref ref
= *ref_rec
;
1692 unsigned int regno
= DF_REF_REGNO (ref
);
1696 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1697 DF_REF_ID (ref
) = id
;
1698 ref_info
->refs
[id
] = ref
;
1702 FOR_BB_INSNS (bb
, insn
)
1706 unsigned int uid
= INSN_UID (insn
);
1709 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1711 df_ref ref
= *ref_rec
;
1712 unsigned int regno
= DF_REF_REGNO (ref
);
1716 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1717 DF_REF_ID (ref
) = id
;
1718 ref_info
->refs
[id
] = ref
;
1722 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1724 df_ref ref
= *ref_rec
;
1725 unsigned int regno
= DF_REF_REGNO (ref
);
1729 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1730 DF_REF_ID (ref
) = id
;
1731 ref_info
->refs
[id
] = ref
;
1734 if (include_eq_uses
)
1735 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1737 df_ref ref
= *ref_rec
;
1738 unsigned int regno
= DF_REF_REGNO (ref
);
1742 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1743 DF_REF_ID (ref
) = id
;
1744 ref_info
->refs
[id
] = ref
;
1751 /* The bitmap size is not decremented when refs are deleted. So
1752 reset it now that we have squished out all of the empty
1755 ref_info
->table_size
= offset
;
1758 /* Take build ref table for either the uses or defs from the reg-use
1759 or reg-def chains. */
1762 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1765 bool include_eq_uses
)
1767 if (df
->analyze_subset
)
1768 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1769 include_uses
, include_eq_uses
);
1771 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1772 include_uses
, include_eq_uses
);
1776 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1778 df_add_refs_to_table (unsigned int offset
,
1779 struct df_ref_info
*ref_info
,
1784 df_ref ref
= *ref_vec
;
1785 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
1786 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1788 ref_info
->refs
[offset
] = ref
;
1789 DF_REF_ID (*ref_vec
) = offset
++;
1797 /* Count the number of refs in all of the insns of BB. Include the
1798 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1799 eq_uses if INCLUDE_EQ_USES. */
1802 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1803 struct df_ref_info
*ref_info
,
1804 bool include_defs
, bool include_uses
,
1805 bool include_eq_uses
)
1810 offset
= df_add_refs_to_table (offset
, ref_info
,
1811 df_get_artificial_defs (bb
->index
));
1813 offset
= df_add_refs_to_table (offset
, ref_info
,
1814 df_get_artificial_uses (bb
->index
));
1816 FOR_BB_INSNS (bb
, insn
)
1819 unsigned int uid
= INSN_UID (insn
);
1821 offset
= df_add_refs_to_table (offset
, ref_info
,
1822 DF_INSN_UID_DEFS (uid
));
1824 offset
= df_add_refs_to_table (offset
, ref_info
,
1825 DF_INSN_UID_USES (uid
));
1826 if (include_eq_uses
)
1827 offset
= df_add_refs_to_table (offset
, ref_info
,
1828 DF_INSN_UID_EQ_USES (uid
));
1834 /* Organize the refs by insn into the table in REF_INFO. If
1835 blocks_to_analyze is defined, use that set, otherwise the entire
1836 program. Include the defs if INCLUDE_DEFS. Include the uses if
1837 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1840 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1841 bool include_defs
, bool include_uses
,
1842 bool include_eq_uses
)
1845 unsigned int offset
= 0;
1847 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1848 df_check_and_grow_ref_info (ref_info
, 1);
1849 if (df
->blocks_to_analyze
)
1854 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1856 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index
), offset
, ref_info
,
1857 include_defs
, include_uses
,
1861 ref_info
->table_size
= offset
;
1866 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1867 include_defs
, include_uses
,
1869 ref_info
->table_size
= offset
;
1874 /* If the use refs in DF are not organized, reorganize them. */
1877 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1879 if (order
== df
->use_info
.ref_order
)
1884 case DF_REF_ORDER_BY_REG
:
1885 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1888 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1889 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1892 case DF_REF_ORDER_BY_INSN
:
1893 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1896 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1897 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1900 case DF_REF_ORDER_NO_TABLE
:
1901 free (df
->use_info
.refs
);
1902 df
->use_info
.refs
= NULL
;
1903 df
->use_info
.refs_size
= 0;
1906 case DF_REF_ORDER_UNORDERED
:
1907 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1912 df
->use_info
.ref_order
= order
;
1916 /* If the def refs in DF are not organized, reorganize them. */
1919 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1921 if (order
== df
->def_info
.ref_order
)
1926 case DF_REF_ORDER_BY_REG
:
1927 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1930 case DF_REF_ORDER_BY_INSN
:
1931 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1934 case DF_REF_ORDER_NO_TABLE
:
1935 free (df
->def_info
.refs
);
1936 df
->def_info
.refs
= NULL
;
1937 df
->def_info
.refs_size
= 0;
1940 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1941 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1942 case DF_REF_ORDER_UNORDERED
:
1943 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1948 df
->def_info
.ref_order
= order
;
1952 /* Change all of the basic block references in INSN to use the insn's
1953 current basic block. This function is called from routines that move
1954 instructions from one block to another. */
1957 df_insn_change_bb (rtx insn
, basic_block new_bb
)
1959 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1960 struct df_insn_info
*insn_info
;
1961 unsigned int uid
= INSN_UID (insn
);
1963 if (old_bb
== new_bb
)
1966 set_block_for_insn (insn
, new_bb
);
1972 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1974 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1975 if (insn_info
== NULL
)
1978 fprintf (dump_file
, " unscanned insn\n");
1979 df_insn_rescan (insn
);
1986 df_set_bb_dirty (new_bb
);
1990 fprintf (dump_file
, " from %d to %d\n",
1991 old_bb
->index
, new_bb
->index
);
1992 df_set_bb_dirty (old_bb
);
1996 fprintf (dump_file
, " to %d\n", new_bb
->index
);
2000 /* Helper function for df_ref_change_reg_with_loc. */
2003 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
2004 struct df_reg_info
*new_df
,
2005 int new_regno
, rtx loc
)
2007 df_ref the_ref
= old_df
->reg_chain
;
2011 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
2012 && DF_REF_LOC (the_ref
)
2013 && (*DF_REF_LOC (the_ref
) == loc
))
2015 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
2016 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
2017 df_ref
*ref_vec
, *ref_vec_t
;
2018 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
2019 unsigned int count
= 0;
2021 DF_REF_REGNO (the_ref
) = new_regno
;
2022 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
2024 /* Pull the_ref out of the old regno chain. */
2026 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
2028 old_df
->reg_chain
= next_ref
;
2030 DF_REF_PREV_REG (next_ref
) = prev_ref
;
2033 /* Put the ref into the new regno chain. */
2034 DF_REF_PREV_REG (the_ref
) = NULL
;
2035 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
2036 if (new_df
->reg_chain
)
2037 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
2038 new_df
->reg_chain
= the_ref
;
2040 if (DF_REF_BB (the_ref
))
2041 df_set_bb_dirty (DF_REF_BB (the_ref
));
2043 /* Need to sort the record again that the ref was in because
2044 the regno is a sorting key. First, find the right
2046 if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
2047 ref_vec
= insn_info
->eq_uses
;
2049 ref_vec
= insn_info
->uses
;
2051 fprintf (dump_file
, "changing reg in insn %d\n",
2052 DF_REF_INSN_UID (the_ref
));
2054 ref_vec_t
= ref_vec
;
2056 /* Find the length. */
2062 qsort (ref_vec
, count
, sizeof (df_ref
), df_ref_compare
);
2067 the_ref
= DF_REF_NEXT_REG (the_ref
);
2072 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2073 NEW_REGNO. Refs that do not match LOC are not changed which means
2074 that artificial refs are not changed since they have no loc. This
2075 call is to support the SET_REGNO macro. */
2078 df_ref_change_reg_with_loc (int old_regno
, int new_regno
, rtx loc
)
2080 if ((!df
) || (old_regno
== -1) || (old_regno
== new_regno
))
2083 df_grow_reg_info ();
2085 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
2086 DF_REG_DEF_GET (new_regno
), new_regno
, loc
);
2087 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
2088 DF_REG_USE_GET (new_regno
), new_regno
, loc
);
2089 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
2090 DF_REG_EQ_USE_GET (new_regno
), new_regno
, loc
);
2094 /* Delete the mw_hardregs that point into the eq_notes. */
2097 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
2099 struct df_mw_hardreg
**mw_vec
= insn_info
->mw_hardregs
;
2100 unsigned int deleted
= 0;
2101 unsigned int count
= 0;
2102 struct df_scan_problem_data
*problem_data
2103 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2110 if ((*mw_vec
)->flags
& DF_REF_IN_NOTE
)
2112 struct df_mw_hardreg
**temp_vec
= mw_vec
;
2114 pool_free (problem_data
->mw_reg_pool
, *mw_vec
);
2116 /* Shove the remaining ones down one to fill the gap. While
2117 this looks n**2, it is highly unusual to have any mw regs
2118 in eq_notes and the chances of more than one are almost
2122 *temp_vec
= *(temp_vec
+ 1);
2136 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
2137 insn_info
->mw_hardregs
= df_null_mw_rec
;
2144 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2147 df_notes_rescan (rtx insn
)
2149 struct df_insn_info
*insn_info
;
2150 unsigned int uid
= INSN_UID (insn
);
2155 /* The client has disabled rescanning and plans to do it itself. */
2156 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
2159 /* Do nothing if the insn hasn't been emitted yet. */
2160 if (!BLOCK_FOR_INSN (insn
))
2163 df_grow_bb_info (df_scan
);
2164 df_grow_reg_info ();
2166 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID(insn
));
2168 /* The client has deferred rescanning. */
2169 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
2173 insn_info
= df_insn_create_insn_record (insn
);
2174 insn_info
->defs
= df_null_ref_rec
;
2175 insn_info
->uses
= df_null_ref_rec
;
2176 insn_info
->eq_uses
= df_null_ref_rec
;
2177 insn_info
->mw_hardregs
= df_null_mw_rec
;
2180 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
2181 /* If the insn is set to be rescanned, it does not need to also
2182 be notes rescanned. */
2183 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
2184 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
2188 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
2189 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
2193 basic_block bb
= BLOCK_FOR_INSN (insn
);
2195 struct df_collection_rec collection_rec
;
2196 unsigned int num_deleted
;
2197 unsigned int mw_len
;
2199 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
2200 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
2201 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
2203 num_deleted
= df_mw_hardreg_chain_delete_eq_uses (insn_info
);
2204 df_ref_chain_delete (insn_info
->eq_uses
);
2205 insn_info
->eq_uses
= NULL
;
2207 /* Process REG_EQUIV/REG_EQUAL notes */
2208 for (note
= REG_NOTES (insn
); note
;
2209 note
= XEXP (note
, 1))
2211 switch (REG_NOTE_KIND (note
))
2215 df_uses_record (&collection_rec
,
2216 &XEXP (note
, 0), DF_REF_REG_USE
,
2217 bb
, insn_info
, DF_REF_IN_NOTE
);
2223 /* Find some place to put any new mw_hardregs. */
2224 df_canonize_collection_rec (&collection_rec
);
2225 mw_len
= VEC_length (df_mw_hardreg_ptr
, collection_rec
.mw_vec
);
2228 unsigned int count
= 0;
2229 struct df_mw_hardreg
**mw_rec
= insn_info
->mw_hardregs
;
2238 /* Append to the end of the existing record after
2239 expanding it if necessary. */
2240 if (mw_len
> num_deleted
)
2242 insn_info
->mw_hardregs
=
2243 XRESIZEVEC (struct df_mw_hardreg
*,
2244 insn_info
->mw_hardregs
,
2245 count
+ 1 + mw_len
);
2247 memcpy (&insn_info
->mw_hardregs
[count
],
2248 VEC_address (df_mw_hardreg_ptr
, collection_rec
.mw_vec
),
2249 mw_len
* sizeof (struct df_mw_hardreg
*));
2250 insn_info
->mw_hardregs
[count
+ mw_len
] = NULL
;
2251 qsort (insn_info
->mw_hardregs
, count
+ mw_len
,
2252 sizeof (struct df_mw_hardreg
*), df_mw_compare
);
2256 /* No vector there. */
2257 insn_info
->mw_hardregs
2258 = XNEWVEC (struct df_mw_hardreg
*, 1 + mw_len
);
2259 memcpy (insn_info
->mw_hardregs
,
2260 VEC_address (df_mw_hardreg_ptr
, collection_rec
.mw_vec
),
2261 mw_len
* sizeof (struct df_mw_hardreg
*));
2262 insn_info
->mw_hardregs
[mw_len
] = NULL
;
2265 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2267 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
.mw_vec
);
2268 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
2269 VEC_free (df_ref
, stack
, collection_rec
.eq_use_vec
);
2272 df_insn_rescan (insn
);
2277 /*----------------------------------------------------------------------------
2278 Hard core instruction scanning code. No external interfaces here,
2279 just a lot of routines that look inside insns.
2280 ----------------------------------------------------------------------------*/
2283 /* Return true if the contents of two df_ref's are identical.
2284 It ignores DF_REF_MARKER. */
2287 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2295 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2296 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2297 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2298 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2299 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2300 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2301 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2302 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2305 switch (DF_REF_CLASS (ref1
))
2307 case DF_REF_ARTIFICIAL
:
2311 case DF_REF_REGULAR
:
2312 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2321 /* Compare REF1 and REF2 for sorting. This is only called from places
2322 where all of the refs are of the same type, in the same insn, and
2323 have the same bb. So these fields are not checked. */
2326 df_ref_compare (const void *r1
, const void *r2
)
2328 const df_ref ref1
= *(const df_ref
*)r1
;
2329 const df_ref ref2
= *(const df_ref
*)r2
;
2334 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2335 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2337 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2338 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2340 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2341 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2343 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2344 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2346 /* Cannot look at the LOC field on artificial refs. */
2347 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2348 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2349 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2351 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2353 /* If two refs are identical except that one of them has is from
2354 a mw and one is not, we need to have the one with the mw
2356 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2357 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2358 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2359 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2365 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2369 df_swap_refs (VEC(df_ref
,stack
) **ref_vec
, int i
, int j
)
2371 df_ref tmp
= VEC_index (df_ref
, *ref_vec
, i
);
2372 VEC_replace (df_ref
, *ref_vec
, i
, VEC_index (df_ref
, *ref_vec
, j
));
2373 VEC_replace (df_ref
, *ref_vec
, j
, tmp
);
2376 /* Sort and compress a set of refs. */
2379 df_sort_and_compress_refs (VEC(df_ref
,stack
) **ref_vec
)
2383 unsigned int dist
= 0;
2385 count
= VEC_length (df_ref
, *ref_vec
);
2387 /* If there are 1 or 0 elements, there is nothing to do. */
2390 else if (count
== 2)
2392 df_ref r0
= VEC_index (df_ref
, *ref_vec
, 0);
2393 df_ref r1
= VEC_index (df_ref
, *ref_vec
, 1);
2394 if (df_ref_compare (&r0
, &r1
) > 0)
2395 df_swap_refs (ref_vec
, 0, 1);
2399 for (i
= 0; i
< count
- 1; i
++)
2401 df_ref r0
= VEC_index (df_ref
, *ref_vec
, i
);
2402 df_ref r1
= VEC_index (df_ref
, *ref_vec
, i
+ 1);
2403 if (df_ref_compare (&r0
, &r1
) >= 0)
2406 /* If the array is already strictly ordered,
2407 which is the most common case for large COUNT case
2408 (which happens for CALL INSNs),
2409 no need to sort and filter out duplicate.
2410 Simply return the count.
2411 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2412 of DF_REF_COMPARE. */
2415 VEC_qsort (df_ref
, *ref_vec
, df_ref_compare
);
2418 for (i
=0; i
<count
-dist
; i
++)
2420 /* Find the next ref that is not equal to the current ref. */
2421 while (i
+ dist
+ 1 < count
2422 && df_ref_equal_p (VEC_index (df_ref
, *ref_vec
, i
),
2423 VEC_index (df_ref
, *ref_vec
, i
+ dist
+ 1)))
2425 df_free_ref (VEC_index (df_ref
, *ref_vec
, i
+ dist
+ 1));
2428 /* Copy it down to the next position. */
2429 if (dist
&& i
+ dist
+ 1 < count
)
2430 VEC_replace (df_ref
, *ref_vec
, i
+ 1,
2431 VEC_index (df_ref
, *ref_vec
, i
+ dist
+ 1));
2435 VEC_truncate (df_ref
, *ref_vec
, count
);
2439 /* Return true if the contents of two df_ref's are identical.
2440 It ignores DF_REF_MARKER. */
2443 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2447 return (mw1
== mw2
) ||
2448 (mw1
->mw_reg
== mw2
->mw_reg
2449 && mw1
->type
== mw2
->type
2450 && mw1
->flags
== mw2
->flags
2451 && mw1
->start_regno
== mw2
->start_regno
2452 && mw1
->end_regno
== mw2
->end_regno
);
2456 /* Compare MW1 and MW2 for sorting. */
2459 df_mw_compare (const void *m1
, const void *m2
)
2461 const struct df_mw_hardreg
*const mw1
= *(const struct df_mw_hardreg
*const*)m1
;
2462 const struct df_mw_hardreg
*const mw2
= *(const struct df_mw_hardreg
*const*)m2
;
2467 if (mw1
->type
!= mw2
->type
)
2468 return mw1
->type
- mw2
->type
;
2470 if (mw1
->flags
!= mw2
->flags
)
2471 return mw1
->flags
- mw2
->flags
;
2473 if (mw1
->start_regno
!= mw2
->start_regno
)
2474 return mw1
->start_regno
- mw2
->start_regno
;
2476 if (mw1
->end_regno
!= mw2
->end_regno
)
2477 return mw1
->end_regno
- mw2
->end_regno
;
2479 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2480 return mw1
->mw_order
- mw2
->mw_order
;
2486 /* Sort and compress a set of refs. */
2489 df_sort_and_compress_mws (VEC(df_mw_hardreg_ptr
,stack
) **mw_vec
)
2492 struct df_scan_problem_data
*problem_data
2493 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2495 unsigned int dist
= 0;
2497 count
= VEC_length (df_mw_hardreg_ptr
, *mw_vec
);
2500 else if (count
== 2)
2502 struct df_mw_hardreg
*m0
= VEC_index (df_mw_hardreg_ptr
, *mw_vec
, 0);
2503 struct df_mw_hardreg
*m1
= VEC_index (df_mw_hardreg_ptr
, *mw_vec
, 1);
2504 if (df_mw_compare (&m0
, &m1
) > 0)
2506 struct df_mw_hardreg
*tmp
= VEC_index (df_mw_hardreg_ptr
,
2508 VEC_replace (df_mw_hardreg_ptr
, *mw_vec
, 0,
2509 VEC_index (df_mw_hardreg_ptr
, *mw_vec
, 1));
2510 VEC_replace (df_mw_hardreg_ptr
, *mw_vec
, 1, tmp
);
2514 VEC_qsort (df_mw_hardreg_ptr
, *mw_vec
, df_mw_compare
);
2516 for (i
=0; i
<count
-dist
; i
++)
2518 /* Find the next ref that is not equal to the current ref. */
2519 while (i
+ dist
+ 1 < count
2520 && df_mw_equal_p (VEC_index (df_mw_hardreg_ptr
, *mw_vec
, i
),
2521 VEC_index (df_mw_hardreg_ptr
, *mw_vec
,
2524 pool_free (problem_data
->mw_reg_pool
,
2525 VEC_index (df_mw_hardreg_ptr
, *mw_vec
, i
+ dist
+ 1));
2528 /* Copy it down to the next position. */
2529 if (dist
&& i
+ dist
+ 1 < count
)
2530 VEC_replace (df_mw_hardreg_ptr
, *mw_vec
, i
+ 1,
2531 VEC_index (df_mw_hardreg_ptr
, *mw_vec
, i
+ dist
+ 1));
2535 VEC_truncate (df_mw_hardreg_ptr
, *mw_vec
, count
);
2539 /* Sort and remove duplicates from the COLLECTION_REC. */
2542 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2544 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2545 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2546 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2547 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2551 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2554 df_install_ref (df_ref this_ref
,
2555 struct df_reg_info
*reg_info
,
2556 struct df_ref_info
*ref_info
,
2559 unsigned int regno
= DF_REF_REGNO (this_ref
);
2560 /* Add the ref to the reg_{def,use,eq_use} chain. */
2561 df_ref head
= reg_info
->reg_chain
;
2563 reg_info
->reg_chain
= this_ref
;
2566 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2568 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2569 df
->hard_regs_live_count
[regno
]++;
2572 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2573 && DF_REF_PREV_REG (this_ref
) == NULL
);
2575 DF_REF_NEXT_REG (this_ref
) = head
;
2577 /* We cannot actually link to the head of the chain. */
2578 DF_REF_PREV_REG (this_ref
) = NULL
;
2581 DF_REF_PREV_REG (head
) = this_ref
;
2585 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2586 df_check_and_grow_ref_info (ref_info
, 1);
2587 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2588 /* Add the ref to the big array of defs. */
2589 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2590 ref_info
->table_size
++;
2593 DF_REF_ID (this_ref
) = -1;
2595 ref_info
->total_size
++;
2599 /* This function takes one of the groups of refs (defs, uses or
2600 eq_uses) and installs the entire group into the insn. It also adds
2601 each of these refs into the appropriate chains. */
2604 df_install_refs (basic_block bb
,
2605 VEC(df_ref
,stack
)* old_vec
,
2606 struct df_reg_info
**reg_info
,
2607 struct df_ref_info
*ref_info
,
2612 count
= VEC_length (df_ref
, old_vec
);
2615 df_ref
*new_vec
= XNEWVEC (df_ref
, count
+ 1);
2620 switch (ref_info
->ref_order
)
2622 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2623 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2624 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2625 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2626 add_to_table
= true;
2628 case DF_REF_ORDER_UNORDERED
:
2629 case DF_REF_ORDER_BY_REG
:
2630 case DF_REF_ORDER_BY_INSN
:
2631 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2632 add_to_table
= !is_notes
;
2635 add_to_table
= false;
2639 /* Do not add if ref is not in the right blocks. */
2640 if (add_to_table
&& df
->analyze_subset
)
2641 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2643 FOR_EACH_VEC_ELT (df_ref
, old_vec
, ix
, this_ref
)
2645 new_vec
[ix
] = this_ref
;
2646 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2647 ref_info
, add_to_table
);
2650 new_vec
[count
] = NULL
;
2654 return df_null_ref_rec
;
2658 /* This function takes the mws installs the entire group into the
2661 static struct df_mw_hardreg
**
2662 df_install_mws (VEC(df_mw_hardreg_ptr
,stack
) *old_vec
)
2666 count
= VEC_length (df_mw_hardreg_ptr
, old_vec
);
2669 struct df_mw_hardreg
**new_vec
2670 = XNEWVEC (struct df_mw_hardreg
*, count
+ 1);
2671 memcpy (new_vec
, VEC_address (df_mw_hardreg_ptr
, old_vec
),
2672 sizeof (struct df_mw_hardreg
*) * count
);
2673 new_vec
[count
] = NULL
;
2677 return df_null_mw_rec
;
2681 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2682 chains and update other necessary information. */
2685 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2686 basic_block bb
, rtx insn
)
2690 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2691 /* If there is a vector in the collection rec, add it to the
2692 insn. A null rec is a signal that the caller will handle the
2694 if (collection_rec
->def_vec
)
2696 df_scan_free_ref_vec (insn_rec
->defs
);
2698 = df_install_refs (bb
, collection_rec
->def_vec
,
2700 &df
->def_info
, false);
2702 if (collection_rec
->use_vec
)
2704 df_scan_free_ref_vec (insn_rec
->uses
);
2706 = df_install_refs (bb
, collection_rec
->use_vec
,
2708 &df
->use_info
, false);
2710 if (collection_rec
->eq_use_vec
)
2712 df_scan_free_ref_vec (insn_rec
->eq_uses
);
2714 = df_install_refs (bb
, collection_rec
->eq_use_vec
,
2716 &df
->use_info
, true);
2718 if (collection_rec
->mw_vec
)
2720 df_scan_free_mws_vec (insn_rec
->mw_hardregs
);
2721 insn_rec
->mw_hardregs
2722 = df_install_mws (collection_rec
->mw_vec
);
2727 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2729 df_scan_free_ref_vec (bb_info
->artificial_defs
);
2730 bb_info
->artificial_defs
2731 = df_install_refs (bb
, collection_rec
->def_vec
,
2733 &df
->def_info
, false);
2734 df_scan_free_ref_vec (bb_info
->artificial_uses
);
2735 bb_info
->artificial_uses
2736 = df_install_refs (bb
, collection_rec
->use_vec
,
2738 &df
->use_info
, false);
2743 /* Allocate a ref and initialize its fields. */
2746 df_ref_create_structure (enum df_ref_class cl
,
2747 struct df_collection_rec
*collection_rec
,
2749 basic_block bb
, struct df_insn_info
*info
,
2750 enum df_ref_type ref_type
,
2753 df_ref this_ref
= NULL
;
2754 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2755 struct df_scan_problem_data
*problem_data
2756 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2761 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_base_pool
);
2762 gcc_checking_assert (loc
== NULL
);
2765 case DF_REF_ARTIFICIAL
:
2766 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_artificial_pool
);
2767 this_ref
->artificial_ref
.bb
= bb
;
2768 gcc_checking_assert (loc
== NULL
);
2771 case DF_REF_REGULAR
:
2772 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_regular_pool
);
2773 this_ref
->regular_ref
.loc
= loc
;
2774 gcc_checking_assert (loc
);
2778 DF_REF_CLASS (this_ref
) = cl
;
2779 DF_REF_ID (this_ref
) = -1;
2780 DF_REF_REG (this_ref
) = reg
;
2781 DF_REF_REGNO (this_ref
) = regno
;
2782 DF_REF_TYPE (this_ref
) = ref_type
;
2783 DF_REF_INSN_INFO (this_ref
) = info
;
2784 DF_REF_CHAIN (this_ref
) = NULL
;
2785 DF_REF_FLAGS (this_ref
) = ref_flags
;
2786 DF_REF_NEXT_REG (this_ref
) = NULL
;
2787 DF_REF_PREV_REG (this_ref
) = NULL
;
2788 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2790 /* We need to clear this bit because fwprop, and in the future
2791 possibly other optimizations sometimes create new refs using ond
2792 refs as the model. */
2793 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2795 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2796 if (regno
< FIRST_PSEUDO_REGISTER
2797 && !DF_REF_IS_ARTIFICIAL (this_ref
)
2798 && !DEBUG_INSN_P (DF_REF_INSN (this_ref
)))
2800 if (DF_REF_REG_DEF_P (this_ref
))
2802 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2803 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2805 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2806 && (regno
== FRAME_POINTER_REGNUM
2807 || regno
== ARG_POINTER_REGNUM
)))
2808 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2813 if (DF_REF_REG_DEF_P (this_ref
))
2814 VEC_safe_push (df_ref
, stack
, collection_rec
->def_vec
, this_ref
);
2815 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2816 VEC_safe_push (df_ref
, stack
, collection_rec
->eq_use_vec
, this_ref
);
2818 VEC_safe_push (df_ref
, stack
, collection_rec
->use_vec
, this_ref
);
2821 df_install_ref_incremental (this_ref
);
2827 /* Create new references of type DF_REF_TYPE for each part of register REG
2828 at address LOC within INSN of BB. */
2832 df_ref_record (enum df_ref_class cl
,
2833 struct df_collection_rec
*collection_rec
,
2835 basic_block bb
, struct df_insn_info
*insn_info
,
2836 enum df_ref_type ref_type
,
2841 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2843 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2844 if (regno
< FIRST_PSEUDO_REGISTER
)
2846 struct df_mw_hardreg
*hardreg
= NULL
;
2847 struct df_scan_problem_data
*problem_data
2848 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2850 unsigned int endregno
;
2853 if (GET_CODE (reg
) == SUBREG
)
2855 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2856 SUBREG_BYTE (reg
), GET_MODE (reg
));
2857 endregno
= regno
+ subreg_nregs (reg
);
2860 endregno
= END_HARD_REGNO (reg
);
2862 /* If this is a multiword hardreg, we create some extra
2863 datastructures that will enable us to easily build REG_DEAD
2864 and REG_UNUSED notes. */
2866 && (endregno
!= regno
+ 1) && insn_info
)
2868 /* Sets to a subreg of a multiword register are partial.
2869 Sets to a non-subreg of a multiword register are not. */
2870 if (GET_CODE (reg
) == SUBREG
)
2871 ref_flags
|= DF_REF_PARTIAL
;
2872 ref_flags
|= DF_REF_MW_HARDREG
;
2874 hardreg
= (struct df_mw_hardreg
*) pool_alloc (problem_data
->mw_reg_pool
);
2875 hardreg
->type
= ref_type
;
2876 hardreg
->flags
= ref_flags
;
2877 hardreg
->mw_reg
= reg
;
2878 hardreg
->start_regno
= regno
;
2879 hardreg
->end_regno
= endregno
- 1;
2880 hardreg
->mw_order
= df
->ref_order
++;
2881 VEC_safe_push (df_mw_hardreg_ptr
, stack
, collection_rec
->mw_vec
,
2885 for (i
= regno
; i
< endregno
; i
++)
2887 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2888 bb
, insn_info
, ref_type
, ref_flags
);
2890 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2895 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2896 ref_type
, ref_flags
);
2901 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2902 covered by the outer mode is smaller than that covered by the inner mode,
2903 is a read-modify-write operation.
2904 This function returns true iff the SUBREG X is such a SUBREG. */
2907 df_read_modify_subreg_p (rtx x
)
2909 unsigned int isize
, osize
;
2910 if (GET_CODE (x
) != SUBREG
)
2912 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2913 osize
= GET_MODE_SIZE (GET_MODE (x
));
2914 return isize
> osize
2915 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2919 /* Process all the registers defined in the rtx pointed by LOC.
2920 Autoincrement/decrement definitions will be picked up by df_uses_record.
2921 Any change here has to be matched in df_find_hard_reg_defs_1. */
2924 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2925 rtx
*loc
, basic_block bb
, struct df_insn_info
*insn_info
,
2930 /* It is legal to have a set destination be a parallel. */
2931 if (GET_CODE (dst
) == PARALLEL
)
2934 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2936 rtx temp
= XVECEXP (dst
, 0, i
);
2937 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
2938 df_def_record_1 (collection_rec
, &XEXP (temp
, 0),
2939 bb
, insn_info
, flags
);
2944 if (GET_CODE (dst
) == STRICT_LOW_PART
)
2946 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
2948 loc
= &XEXP (dst
, 0);
2952 if (GET_CODE (dst
) == ZERO_EXTRACT
)
2954 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
2956 loc
= &XEXP (dst
, 0);
2960 /* At this point if we do not have a reg or a subreg, just return. */
2963 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2964 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2966 /* We want to keep sp alive everywhere - by making all
2967 writes to sp also use of sp. */
2968 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
2969 df_ref_record (DF_REF_BASE
, collection_rec
,
2970 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
2972 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
2974 if (df_read_modify_subreg_p (dst
))
2975 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
2977 flags
|= DF_REF_SUBREG
;
2979 df_ref_record (DF_REF_REGULAR
, collection_rec
,
2980 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
2985 /* Process all the registers defined in the pattern rtx, X. Any change
2986 here has to be matched in df_find_hard_reg_defs. */
2989 df_defs_record (struct df_collection_rec
*collection_rec
,
2990 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2993 RTX_CODE code
= GET_CODE (x
);
2999 df_def_record_1 (collection_rec
, &SET_DEST (x
), bb
, insn_info
, flags
);
3003 flags
|= DF_REF_MUST_CLOBBER
;
3004 df_def_record_1 (collection_rec
, &XEXP (x
, 0), bb
, insn_info
, flags
);
3008 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
3009 bb
, insn_info
, DF_REF_CONDITIONAL
);
3013 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
3014 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
),
3015 bb
, insn_info
, flags
);
3018 /* No DEFs to record in other cases */
3023 /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
3024 destination of a set or clobber. This has to match the logic in
3025 df_defs_record_1. */
3028 df_find_hard_reg_defs_1 (rtx dst
, HARD_REG_SET
*defs
)
3030 /* It is legal to have a set destination be a parallel. */
3031 if (GET_CODE (dst
) == PARALLEL
)
3034 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
3036 rtx temp
= XVECEXP (dst
, 0, i
);
3037 gcc_assert (GET_CODE (temp
) == EXPR_LIST
);
3038 df_find_hard_reg_defs_1 (XEXP (temp
, 0), defs
);
3043 if (GET_CODE (dst
) == STRICT_LOW_PART
)
3044 dst
= XEXP (dst
, 0);
3046 if (GET_CODE (dst
) == ZERO_EXTRACT
)
3047 dst
= XEXP (dst
, 0);
3049 /* At this point if we do not have a reg or a subreg, just return. */
3050 if (REG_P (dst
) && HARD_REGISTER_P (dst
))
3051 SET_HARD_REG_BIT (*defs
, REGNO (dst
));
3052 else if (GET_CODE (dst
) == SUBREG
3053 && REG_P (SUBREG_REG (dst
)) && HARD_REGISTER_P (dst
))
3054 SET_HARD_REG_BIT (*defs
, REGNO (SUBREG_REG (dst
)));
3057 /* Set bits in *DEFS for hard registers defined in the pattern X. This
3058 has to match the logic in df_defs_record. */
3061 df_find_hard_reg_defs (rtx x
, HARD_REG_SET
*defs
)
3063 RTX_CODE code
= GET_CODE (x
);
3069 df_find_hard_reg_defs_1 (SET_DEST (x
), defs
);
3073 df_find_hard_reg_defs_1 (XEXP (x
, 0), defs
);
3077 df_find_hard_reg_defs (COND_EXEC_CODE (x
), defs
);
3081 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
3082 df_find_hard_reg_defs (XVECEXP (x
, 0, i
), defs
);
3085 /* No DEFs to record in other cases */
3091 /* Process all the registers used in the rtx at address LOC. */
3094 df_uses_record (struct df_collection_rec
*collection_rec
,
3095 rtx
*loc
, enum df_ref_type ref_type
,
3096 basic_block bb
, struct df_insn_info
*insn_info
,
3106 code
= GET_CODE (x
);
3123 /* If we are clobbering a MEM, mark any registers inside the address
3125 if (MEM_P (XEXP (x
, 0)))
3126 df_uses_record (collection_rec
,
3127 &XEXP (XEXP (x
, 0), 0),
3128 DF_REF_REG_MEM_STORE
,
3132 /* If we're clobbering a REG then we have a def so ignore. */
3136 df_uses_record (collection_rec
,
3137 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
3138 bb
, insn_info
, flags
& DF_REF_IN_NOTE
);
3142 /* While we're here, optimize this case. */
3143 flags
|= DF_REF_PARTIAL
;
3144 /* In case the SUBREG is not of a REG, do not optimize. */
3145 if (!REG_P (SUBREG_REG (x
)))
3147 loc
= &SUBREG_REG (x
);
3148 df_uses_record (collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
);
3151 /* ... Fall through ... */
3154 df_ref_record (DF_REF_REGULAR
, collection_rec
,
3155 x
, loc
, bb
, insn_info
,
3162 df_uses_record (collection_rec
,
3163 &XEXP (x
, 1), ref_type
, bb
, insn_info
, flags
);
3164 df_uses_record (collection_rec
,
3165 &XEXP (x
, 2), ref_type
, bb
, insn_info
, flags
);
3167 /* If the parameters to the zero or sign extract are
3168 constants, strip them off and recurse, otherwise there is
3169 no information that we can gain from this operation. */
3170 if (code
== ZERO_EXTRACT
)
3171 flags
|= DF_REF_ZERO_EXTRACT
;
3173 flags
|= DF_REF_SIGN_EXTRACT
;
3175 df_uses_record (collection_rec
,
3176 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
);
3183 rtx dst
= SET_DEST (x
);
3184 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
3185 df_uses_record (collection_rec
,
3186 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
);
3188 switch (GET_CODE (dst
))
3191 if (df_read_modify_subreg_p (dst
))
3193 df_uses_record (collection_rec
, &SUBREG_REG (dst
),
3194 DF_REF_REG_USE
, bb
, insn_info
,
3195 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
);
3206 df_uses_record (collection_rec
, &XEXP (dst
, 0),
3207 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
);
3209 case STRICT_LOW_PART
:
3211 rtx
*temp
= &XEXP (dst
, 0);
3212 /* A strict_low_part uses the whole REG and not just the
3214 dst
= XEXP (dst
, 0);
3215 df_uses_record (collection_rec
,
3216 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
3217 DF_REF_REG_USE
, bb
, insn_info
,
3218 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
);
3223 df_uses_record (collection_rec
, &XEXP (dst
, 1),
3224 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3225 df_uses_record (collection_rec
, &XEXP (dst
, 2),
3226 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3227 if (GET_CODE (XEXP (dst
,0)) == MEM
)
3228 df_uses_record (collection_rec
, &XEXP (dst
, 0),
3229 DF_REF_REG_USE
, bb
, insn_info
,
3232 df_uses_record (collection_rec
, &XEXP (dst
, 0),
3233 DF_REF_REG_USE
, bb
, insn_info
,
3234 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
);
3249 case UNSPEC_VOLATILE
:
3253 /* Traditional and volatile asm instructions must be
3254 considered to use and clobber all hard registers, all
3255 pseudo-registers and all of memory. So must TRAP_IF and
3256 UNSPEC_VOLATILE operations.
3258 Consider for instance a volatile asm that changes the fpu
3259 rounding mode. An insn should not be moved across this
3260 even if it only uses pseudo-regs because it might give an
3261 incorrectly rounded result.
3263 However, flow.c's liveness computation did *not* do this,
3264 giving the reasoning as " ?!? Unfortunately, marking all
3265 hard registers as live causes massive problems for the
3266 register allocator and marking all pseudos as live creates
3267 mountains of uninitialized variable warnings."
3269 In order to maintain the status quo with regard to liveness
3270 and uses, we do what flow.c did and just mark any regs we
3271 can find in ASM_OPERANDS as used. In global asm insns are
3272 scanned and regs_asm_clobbered is filled out.
3274 For all ASM_OPERANDS, we must traverse the vector of input
3275 operands. We can not just fall through here since then we
3276 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3277 which do not indicate traditional asms unlike their normal
3279 if (code
== ASM_OPERANDS
)
3283 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3284 df_uses_record (collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3285 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3292 df_uses_record (collection_rec
,
3293 &PAT_VAR_LOCATION_LOC (x
),
3294 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3303 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3304 /* Catch the def of the register being modified. */
3305 df_ref_record (DF_REF_REGULAR
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3308 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
);
3310 /* ... Fall through to handle uses ... */
3316 /* Recursively scan the operands of this expression. */
3318 const char *fmt
= GET_RTX_FORMAT (code
);
3321 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3325 /* Tail recursive case: save a function call level. */
3331 df_uses_record (collection_rec
, &XEXP (x
, i
), ref_type
,
3332 bb
, insn_info
, flags
);
3334 else if (fmt
[i
] == 'E')
3337 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3338 df_uses_record (collection_rec
,
3339 &XVECEXP (x
, i
, j
), ref_type
,
3340 bb
, insn_info
, flags
);
3349 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3352 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3357 FOR_EACH_VEC_ELT (df_ref
, collection_rec
->def_vec
, ix
, ref
)
3359 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3363 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3364 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3365 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3366 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
);
3367 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3373 /* Get call's extra defs and uses (track caller-saved registers). */
3376 df_get_call_refs (struct df_collection_rec
*collection_rec
,
3378 struct df_insn_info
*insn_info
,
3382 bool is_sibling_call
;
3384 HARD_REG_SET defs_generated
;
3386 CLEAR_HARD_REG_SET (defs_generated
);
3387 df_find_hard_reg_defs (PATTERN (insn_info
->insn
), &defs_generated
);
3388 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3390 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3392 if (i
== STACK_POINTER_REGNUM
)
3393 /* The stack ptr is used (honorarily) by a CALL insn. */
3394 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3395 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3396 DF_REF_CALL_STACK_USAGE
| flags
);
3397 else if (global_regs
[i
])
3399 /* Calls to const functions cannot access any global registers and
3400 calls to pure functions cannot set them. All other calls may
3401 reference any of the global registers, so they are recorded as
3403 if (!RTL_CONST_CALL_P (insn_info
->insn
))
3405 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3406 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
);
3407 if (!RTL_PURE_CALL_P (insn_info
->insn
))
3408 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3409 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
);
3412 else if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
)
3413 /* no clobbers for regs that are the result of the call */
3414 && !TEST_HARD_REG_BIT (defs_generated
, i
)
3415 && (!is_sibling_call
3416 || !bitmap_bit_p (df
->exit_block_uses
, i
)
3417 || refers_to_regno_p (i
, i
+1,
3418 crtl
->return_rtx
, NULL
)))
3419 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3420 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3421 DF_REF_MAY_CLOBBER
| flags
);
3424 /* Record the registers used to pass arguments, and explicitly
3425 noted as clobbered. */
3426 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3427 note
= XEXP (note
, 1))
3429 if (GET_CODE (XEXP (note
, 0)) == USE
)
3430 df_uses_record (collection_rec
, &XEXP (XEXP (note
, 0), 0),
3431 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3432 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3434 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3436 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3437 if (!TEST_HARD_REG_BIT (defs_generated
, regno
))
3438 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3442 df_uses_record (collection_rec
, &XEXP (note
, 0),
3443 DF_REF_REG_USE
, bb
, insn_info
, flags
);
3450 /* Collect all refs in the INSN. This function is free of any
3451 side-effect - it will create and return a lists of df_ref's in the
3452 COLLECTION_REC without putting those refs into existing ref chains
3456 df_insn_refs_collect (struct df_collection_rec
*collection_rec
,
3457 basic_block bb
, struct df_insn_info
*insn_info
)
3460 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3462 /* Clear out the collection record. */
3463 VEC_truncate (df_ref
, collection_rec
->def_vec
, 0);
3464 VEC_truncate (df_ref
, collection_rec
->use_vec
, 0);
3465 VEC_truncate (df_ref
, collection_rec
->eq_use_vec
, 0);
3466 VEC_truncate (df_mw_hardreg_ptr
, collection_rec
->mw_vec
, 0);
3468 /* Process REG_EQUIV/REG_EQUAL notes. */
3469 for (note
= REG_NOTES (insn_info
->insn
); note
;
3470 note
= XEXP (note
, 1))
3472 switch (REG_NOTE_KIND (note
))
3476 df_uses_record (collection_rec
,
3477 &XEXP (note
, 0), DF_REF_REG_USE
,
3478 bb
, insn_info
, DF_REF_IN_NOTE
);
3480 case REG_NON_LOCAL_GOTO
:
3481 /* The frame ptr is used by a non-local goto. */
3482 df_ref_record (DF_REF_BASE
, collection_rec
,
3483 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3484 NULL
, bb
, insn_info
,
3486 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3487 df_ref_record (DF_REF_BASE
, collection_rec
,
3488 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3489 NULL
, bb
, insn_info
,
3498 /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
3499 uses from CALL_INSN_FUNCTION_USAGE. */
3500 if (CALL_P (insn_info
->insn
))
3501 df_get_call_refs (collection_rec
, bb
, insn_info
,
3502 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3504 /* Record other defs. These should be mostly for DF_REF_REGULAR, so
3505 that a qsort on the defs is unnecessary in most cases. */
3506 df_defs_record (collection_rec
,
3507 PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3509 /* Record the register uses. */
3510 df_uses_record (collection_rec
,
3511 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0);
3513 /* DF_REF_CONDITIONAL needs corresponding USES. */
3515 df_get_conditional_uses (collection_rec
);
3517 df_canonize_collection_rec (collection_rec
);
3520 /* Recompute the luids for the insns in BB. */
3523 df_recompute_luids (basic_block bb
)
3528 df_grow_insn_info ();
3530 /* Scan the block an insn at a time from beginning to end. */
3531 FOR_BB_INSNS (bb
, insn
)
3533 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3534 /* Inserting labels does not always trigger the incremental
3538 gcc_assert (!INSN_P (insn
));
3539 insn_info
= df_insn_create_insn_record (insn
);
3542 DF_INSN_INFO_LUID (insn_info
) = luid
;
3549 /* Collect all artificial refs at the block level for BB and add them
3550 to COLLECTION_REC. */
3553 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3555 VEC_truncate (df_ref
, collection_rec
->def_vec
, 0);
3556 VEC_truncate (df_ref
, collection_rec
->use_vec
, 0);
3557 VEC_truncate (df_ref
, collection_rec
->eq_use_vec
, 0);
3558 VEC_truncate (df_mw_hardreg_ptr
, collection_rec
->mw_vec
, 0);
3560 if (bb
->index
== ENTRY_BLOCK
)
3562 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3565 else if (bb
->index
== EXIT_BLOCK
)
3567 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3571 #ifdef EH_RETURN_DATA_REGNO
3572 if (bb_has_eh_pred (bb
))
3575 /* Mark the registers that will contain data for the handler. */
3578 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3579 if (regno
== INVALID_REGNUM
)
3581 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3582 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3587 /* Add the hard_frame_pointer if this block is the target of a
3589 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3590 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3591 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
);
3593 /* Add the artificial uses. */
3594 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3598 bitmap au
= bb_has_eh_pred (bb
)
3599 ? &df
->eh_block_artificial_uses
3600 : &df
->regular_block_artificial_uses
;
3602 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3604 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3605 bb
, NULL
, DF_REF_REG_USE
, 0);
3609 df_canonize_collection_rec (collection_rec
);
3613 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3616 df_bb_refs_record (int bb_index
, bool scan_insns
)
3618 basic_block bb
= BASIC_BLOCK (bb_index
);
3621 struct df_collection_rec collection_rec
;
3626 df_grow_bb_info (df_scan
);
3627 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, 128);
3628 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, 32);
3629 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
3630 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
3633 /* Scan the block an insn at a time from beginning to end. */
3634 FOR_BB_INSNS (bb
, insn
)
3636 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3637 gcc_assert (!insn_info
);
3639 insn_info
= df_insn_create_insn_record (insn
);
3642 /* Record refs within INSN. */
3643 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3644 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3645 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
3647 DF_INSN_INFO_LUID (insn_info
) = luid
;
3650 /* Other block level artificial refs */
3651 df_bb_refs_collect (&collection_rec
, bb
);
3652 df_refs_add_to_chains (&collection_rec
, bb
, NULL
);
3654 VEC_free (df_ref
, stack
, collection_rec
.def_vec
);
3655 VEC_free (df_ref
, stack
, collection_rec
.use_vec
);
3656 VEC_free (df_ref
, stack
, collection_rec
.eq_use_vec
);
3657 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
.mw_vec
);
3659 /* Now that the block has been processed, set the block as dirty so
3660 LR and LIVE will get it processed. */
3661 df_set_bb_dirty (bb
);
3665 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3669 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3675 bitmap_clear (regular_block_artificial_uses
);
3677 if (reload_completed
)
3679 if (frame_pointer_needed
)
3680 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3683 /* Before reload, there are a few registers that must be forced
3684 live everywhere -- which might not already be the case for
3685 blocks within infinite loops. */
3687 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3689 /* Any reference to any pseudo before reload is a potential
3690 reference of the frame pointer. */
3691 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3693 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3694 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3697 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3698 /* Pseudos with argument area equivalences may require
3699 reloading via the argument pointer. */
3700 if (fixed_regs
[ARG_POINTER_REGNUM
])
3701 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3704 /* Any constant, or pseudo with constant equivalences, may
3705 require reloading from memory using the pic register. */
3706 if (picreg
!= INVALID_REGNUM
3707 && fixed_regs
[picreg
])
3708 bitmap_set_bit (regular_block_artificial_uses
, picreg
);
3710 /* The all-important stack pointer must always be live. */
3711 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3714 /* EH_USES registers are used:
3715 1) at all insns that might throw (calls or with -fnon-call-exceptions
3718 3) to support backtraces and/or debugging, anywhere between their
3719 initialization and where they the saved registers are restored
3720 from them, including the cases where we don't reach the epilogue
3721 (noreturn call or infinite loop). */
3722 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3724 bitmap_set_bit (regular_block_artificial_uses
, i
);
3729 /* Get the artificial use set for an eh block. */
3732 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3734 bitmap_clear (eh_block_artificial_uses
);
3736 /* The following code (down through the arg_pointer setting APPEARS
3737 to be necessary because there is nothing that actually
3738 describes what the exception handling code may actually need
3740 if (reload_completed
)
3742 if (frame_pointer_needed
)
3744 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3745 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3746 bitmap_set_bit (eh_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3749 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3750 if (fixed_regs
[ARG_POINTER_REGNUM
])
3751 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3758 /*----------------------------------------------------------------------------
3759 Specialized hard register scanning functions.
3760 ----------------------------------------------------------------------------*/
3763 /* Mark a register in SET. Hard registers in large modes get all
3764 of their component registers set as well. */
3767 df_mark_reg (rtx reg
, void *vset
)
3769 bitmap set
= (bitmap
) vset
;
3770 int regno
= REGNO (reg
);
3772 gcc_assert (GET_MODE (reg
) != BLKmode
);
3774 if (regno
< FIRST_PSEUDO_REGISTER
)
3776 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3777 bitmap_set_range (set
, regno
, n
);
3780 bitmap_set_bit (set
, regno
);
3784 /* Set the bit for regs that are considered being defined at the entry. */
3787 df_get_entry_block_def_set (bitmap entry_block_defs
)
3792 bitmap_clear (entry_block_defs
);
3794 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3795 if (FUNCTION_ARG_REGNO_P (i
))
3796 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3798 /* The always important stack pointer. */
3799 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3801 /* Once the prologue has been generated, all of these registers
3802 should just show up in the first regular block. */
3803 if (HAVE_prologue
&& epilogue_completed
)
3805 /* Defs for the callee saved registers are inserted so that the
3806 pushes have some defining location. */
3807 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3808 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3809 bitmap_set_bit (entry_block_defs
, i
);
3812 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3814 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3816 /* If the function has an incoming STATIC_CHAIN, it has to show up
3817 in the entry def set. */
3818 r
= targetm
.calls
.static_chain (current_function_decl
, true);
3820 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3822 if ((!reload_completed
) || frame_pointer_needed
)
3824 /* Any reference to any pseudo before reload is a potential
3825 reference of the frame pointer. */
3826 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3827 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3828 /* If they are different, also mark the hard frame pointer as live. */
3829 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3830 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3834 /* These registers are live everywhere. */
3835 if (!reload_completed
)
3837 #ifdef PIC_OFFSET_TABLE_REGNUM
3838 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3841 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3842 /* Pseudos with argument area equivalences may require
3843 reloading via the argument pointer. */
3844 if (fixed_regs
[ARG_POINTER_REGNUM
])
3845 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3848 #ifdef PIC_OFFSET_TABLE_REGNUM
3849 /* Any constant, or pseudo with constant equivalences, may
3850 require reloading from memory using the pic register. */
3851 if (picreg
!= INVALID_REGNUM
3852 && fixed_regs
[picreg
])
3853 bitmap_set_bit (entry_block_defs
, picreg
);
3857 #ifdef INCOMING_RETURN_ADDR_RTX
3858 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3859 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3862 targetm
.extra_live_on_entry (entry_block_defs
);
3866 /* Return the (conservative) set of hard registers that are defined on
3867 entry to the function.
3868 It uses df->entry_block_defs to determine which register
3869 reference to include. */
3872 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3873 bitmap entry_block_defs
)
3878 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3880 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3881 ENTRY_BLOCK_PTR
, NULL
, DF_REF_REG_DEF
, 0);
3884 df_canonize_collection_rec (collection_rec
);
3888 /* Record the (conservative) set of hard registers that are defined on
3889 entry to the function. */
3892 df_record_entry_block_defs (bitmap entry_block_defs
)
3894 struct df_collection_rec collection_rec
;
3895 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
3896 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, FIRST_PSEUDO_REGISTER
);
3897 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3899 /* Process bb_refs chain */
3900 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (ENTRY_BLOCK
), NULL
);
3901 VEC_free (df_ref
, stack
, collection_rec
.def_vec
);
3905 /* Update the defs in the entry block. */
3908 df_update_entry_block_defs (void)
3911 bool changed
= false;
3913 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3914 df_get_entry_block_def_set (&refs
);
3915 if (df
->entry_block_defs
)
3917 if (!bitmap_equal_p (df
->entry_block_defs
, &refs
))
3919 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3920 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3921 df_ref_chain_delete (bb_info
->artificial_defs
);
3922 bb_info
->artificial_defs
= NULL
;
3928 struct df_scan_problem_data
*problem_data
3929 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3931 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
3937 df_record_entry_block_defs (&refs
);
3938 bitmap_copy (df
->entry_block_defs
, &refs
);
3939 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
3941 bitmap_clear (&refs
);
3945 /* Set the bit for regs that are considered being used at the exit. */
3948 df_get_exit_block_use_set (bitmap exit_block_uses
)
3951 unsigned int picreg
= PIC_OFFSET_TABLE_REGNUM
;
3953 bitmap_clear (exit_block_uses
);
3955 /* Stack pointer is always live at the exit. */
3956 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
3958 /* Mark the frame pointer if needed at the end of the function.
3959 If we end up eliminating it, it will be removed from the live
3960 list of each basic block by reload. */
3962 if ((!reload_completed
) || frame_pointer_needed
)
3964 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
3965 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3966 /* If they are different, also mark the hard frame pointer as live. */
3967 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3968 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
3972 /* Many architectures have a GP register even without flag_pic.
3973 Assume the pic register is not in use, or will be handled by
3974 other means, if it is not fixed. */
3975 if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
3976 && picreg
!= INVALID_REGNUM
3977 && fixed_regs
[picreg
])
3978 bitmap_set_bit (exit_block_uses
, picreg
);
3980 /* Mark all global registers, and all registers used by the
3981 epilogue as being live at the end of the function since they
3982 may be referenced by our caller. */
3983 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3984 if (global_regs
[i
] || EPILOGUE_USES (i
))
3985 bitmap_set_bit (exit_block_uses
, i
);
3987 if (HAVE_epilogue
&& epilogue_completed
)
3989 /* Mark all call-saved registers that we actually used. */
3990 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3991 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
3992 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3993 bitmap_set_bit (exit_block_uses
, i
);
3996 #ifdef EH_RETURN_DATA_REGNO
3997 /* Mark the registers that will contain data for the handler. */
3998 if (reload_completed
&& crtl
->calls_eh_return
)
4001 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
4002 if (regno
== INVALID_REGNUM
)
4004 bitmap_set_bit (exit_block_uses
, regno
);
4008 #ifdef EH_RETURN_STACKADJ_RTX
4009 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4010 && crtl
->calls_eh_return
)
4012 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
4013 if (tmp
&& REG_P (tmp
))
4014 df_mark_reg (tmp
, exit_block_uses
);
4018 #ifdef EH_RETURN_HANDLER_RTX
4019 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4020 && crtl
->calls_eh_return
)
4022 rtx tmp
= EH_RETURN_HANDLER_RTX
;
4023 if (tmp
&& REG_P (tmp
))
4024 df_mark_reg (tmp
, exit_block_uses
);
4028 /* Mark function return value. */
4029 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
4033 /* Return the refs of hard registers that are used in the exit block.
4034 It uses df->exit_block_uses to determine register to include. */
4037 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
4042 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
4043 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
4044 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0);
4046 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4047 /* It is deliberate that this is not put in the exit block uses but
4048 I do not know why. */
4049 if (reload_completed
4050 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
4051 && bb_has_eh_pred (EXIT_BLOCK_PTR
)
4052 && fixed_regs
[ARG_POINTER_REGNUM
])
4053 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
4054 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0);
4057 df_canonize_collection_rec (collection_rec
);
4061 /* Record the set of hard registers that are used in the exit block.
4062 It uses df->exit_block_uses to determine which bit to include. */
4065 df_record_exit_block_uses (bitmap exit_block_uses
)
4067 struct df_collection_rec collection_rec
;
4068 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4069 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, FIRST_PSEUDO_REGISTER
);
4071 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
4073 /* Process bb_refs chain */
4074 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (EXIT_BLOCK
), NULL
);
4075 VEC_free (df_ref
, stack
, collection_rec
.use_vec
);
4079 /* Update the uses in the exit block. */
4082 df_update_exit_block_uses (void)
4085 bool changed
= false;
4087 bitmap_initialize (&refs
, &df_bitmap_obstack
);
4088 df_get_exit_block_use_set (&refs
);
4089 if (df
->exit_block_uses
)
4091 if (!bitmap_equal_p (df
->exit_block_uses
, &refs
))
4093 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
4094 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
4095 df_ref_chain_delete (bb_info
->artificial_uses
);
4096 bb_info
->artificial_uses
= NULL
;
4102 struct df_scan_problem_data
*problem_data
4103 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
4105 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
4111 df_record_exit_block_uses (&refs
);
4112 bitmap_copy (df
->exit_block_uses
,& refs
);
4113 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
4115 bitmap_clear (&refs
);
4118 static bool initialized
= false;
4121 /* Initialize some platform specific structures. */
4124 df_hard_reg_init (void)
4126 #ifdef ELIMINABLE_REGS
4128 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
4133 /* Record which registers will be eliminated. We use this in
4135 CLEAR_HARD_REG_SET (elim_reg_set
);
4137 #ifdef ELIMINABLE_REGS
4138 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
4139 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
4141 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
4148 /* Recompute the parts of scanning that are based on regs_ever_live
4149 because something changed in that array. */
4152 df_update_entry_exit_and_calls (void)
4156 df_update_entry_block_defs ();
4157 df_update_exit_block_uses ();
4159 /* The call insns need to be rescanned because there may be changes
4160 in the set of registers clobbered across the call. */
4164 FOR_BB_INSNS (bb
, insn
)
4166 if (INSN_P (insn
) && CALL_P (insn
))
4167 df_insn_rescan (insn
);
4173 /* Return true if hard REG is actually used in the some instruction.
4174 There are a fair number of conditions that affect the setting of
4175 this array. See the comment in df.h for df->hard_regs_live_count
4176 for the conditions that this array is set. */
4179 df_hard_reg_used_p (unsigned int reg
)
4181 return df
->hard_regs_live_count
[reg
] != 0;
4185 /* A count of the number of times REG is actually used in the some
4186 instruction. There are a fair number of conditions that affect the
4187 setting of this array. See the comment in df.h for
4188 df->hard_regs_live_count for the conditions that this array is
4193 df_hard_reg_used_count (unsigned int reg
)
4195 return df
->hard_regs_live_count
[reg
];
4199 /* Get the value of regs_ever_live[REGNO]. */
4202 df_regs_ever_live_p (unsigned int regno
)
4204 return regs_ever_live
[regno
];
4208 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
4209 to change, schedule that change for the next update. */
4212 df_set_regs_ever_live (unsigned int regno
, bool value
)
4214 if (regs_ever_live
[regno
] == value
)
4217 regs_ever_live
[regno
] = value
;
4219 df
->redo_entry_and_exit
= true;
4223 /* Compute "regs_ever_live" information from the underlying df
4224 information. Set the vector to all false if RESET. */
4227 df_compute_regs_ever_live (bool reset
)
4230 bool changed
= df
->redo_entry_and_exit
;
4233 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
4235 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4236 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
4238 regs_ever_live
[i
] = true;
4242 df_update_entry_exit_and_calls ();
4243 df
->redo_entry_and_exit
= false;
4247 /*----------------------------------------------------------------------------
4248 Dataflow ref information verification functions.
4250 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4251 df_reg_chain_verify_unmarked (refs)
4252 df_refs_verify (VEC(stack,df_ref)*, ref*, bool)
4253 df_mws_verify (mw*, mw*, bool)
4254 df_insn_refs_verify (collection_rec, bb, insn, bool)
4255 df_bb_refs_verify (bb, refs, bool)
4257 df_exit_block_bitmap_verify (bool)
4258 df_entry_block_bitmap_verify (bool)
4260 ----------------------------------------------------------------------------*/
4263 /* Mark all refs in the reg chain. Verify that all of the registers
4264 are in the correct chain. */
4267 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
4268 bool is_def
, bool is_eq_use
)
4270 unsigned int count
= 0;
4272 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4274 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4276 /* If there are no def-use or use-def chains, make sure that all
4277 of the chains are clear. */
4279 gcc_assert (!DF_REF_CHAIN (ref
));
4281 /* Check to make sure the ref is in the correct chain. */
4282 gcc_assert (DF_REF_REGNO (ref
) == regno
);
4284 gcc_assert (DF_REF_REG_DEF_P (ref
));
4286 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4289 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4291 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4293 if (DF_REF_NEXT_REG (ref
))
4294 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4296 DF_REF_REG_MARK (ref
);
4302 /* Verify that all of the registers in the chain are unmarked. */
4305 df_reg_chain_verify_unmarked (df_ref refs
)
4308 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4309 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4313 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4316 df_refs_verify (VEC(df_ref
,stack
) *new_rec
, df_ref
*old_rec
,
4322 FOR_EACH_VEC_ELT (df_ref
, new_rec
, ix
, new_ref
)
4324 if (*old_rec
== NULL
|| !df_ref_equal_p (new_ref
, *old_rec
))
4332 /* Abort if fail is called from the function level verifier. If
4333 that is the context, mark this reg as being seem. */
4336 gcc_assert (DF_REF_IS_REG_MARKED (*old_rec
));
4337 DF_REF_REG_UNMARK (*old_rec
);
4344 gcc_assert (*old_rec
== NULL
);
4346 return *old_rec
== NULL
;
4351 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4354 df_mws_verify (VEC(df_mw_hardreg_ptr
,stack
) *new_rec
,
4355 struct df_mw_hardreg
**old_rec
,
4359 struct df_mw_hardreg
*new_reg
;
4361 FOR_EACH_VEC_ELT (df_mw_hardreg_ptr
, new_rec
, ix
, new_reg
)
4363 if (*old_rec
== NULL
|| !df_mw_equal_p (new_reg
, *old_rec
))
4374 gcc_assert (*old_rec
== NULL
);
4376 return *old_rec
== NULL
;
4381 /* Return true if the existing insn refs information is complete and
4382 correct. Otherwise (i.e. if there's any missing or extra refs),
4383 return the correct df_ref chain in REFS_RETURN.
4385 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4386 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4387 verification mode instead of the whole function, so unmark
4390 If ABORT_IF_FAIL is set, this function never returns false. */
4393 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4398 bool ret1
, ret2
, ret3
, ret4
;
4399 unsigned int uid
= INSN_UID (insn
);
4400 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4402 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4404 if (!DF_INSN_UID_DEFS (uid
))
4406 /* The insn_rec was created but it was never filled out. */
4413 /* Unfortunately we cannot opt out early if one of these is not
4414 right because the marks will not get cleared. */
4415 ret1
= df_refs_verify (collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4417 ret2
= df_refs_verify (collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4419 ret3
= df_refs_verify (collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4421 ret4
= df_mws_verify (collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4423 return (ret1
&& ret2
&& ret3
&& ret4
);
4427 /* Return true if all refs in the basic block are correct and complete.
4428 Due to df_ref_chain_verify, it will cause all refs
4429 that are verified to have DF_REF_MARK bit set. */
4432 df_bb_verify (basic_block bb
)
4435 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4436 struct df_collection_rec collection_rec
;
4438 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4439 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, 128);
4440 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, 32);
4441 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
4442 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
4444 gcc_assert (bb_info
);
4446 /* Scan the block, one insn at a time, from beginning to end. */
4447 FOR_BB_INSNS_REVERSE (bb
, insn
)
4451 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4452 df_free_collection_rec (&collection_rec
);
4455 /* Do the artificial defs and uses. */
4456 df_bb_refs_collect (&collection_rec
, bb
);
4457 df_refs_verify (collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4458 df_refs_verify (collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4459 df_free_collection_rec (&collection_rec
);
4465 /* Returns true if the entry block has correct and complete df_ref set.
4466 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4469 df_entry_block_bitmap_verify (bool abort_if_fail
)
4471 bitmap_head entry_block_defs
;
4474 bitmap_initialize (&entry_block_defs
, &df_bitmap_obstack
);
4475 df_get_entry_block_def_set (&entry_block_defs
);
4477 is_eq
= bitmap_equal_p (&entry_block_defs
, df
->entry_block_defs
);
4479 if (!is_eq
&& abort_if_fail
)
4481 print_current_pass (stderr
);
4482 fprintf (stderr
, "entry_block_defs = ");
4483 df_print_regset (stderr
, &entry_block_defs
);
4484 fprintf (stderr
, "df->entry_block_defs = ");
4485 df_print_regset (stderr
, df
->entry_block_defs
);
4489 bitmap_clear (&entry_block_defs
);
4495 /* Returns true if the exit block has correct and complete df_ref set.
4496 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4499 df_exit_block_bitmap_verify (bool abort_if_fail
)
4501 bitmap_head exit_block_uses
;
4504 bitmap_initialize (&exit_block_uses
, &df_bitmap_obstack
);
4505 df_get_exit_block_use_set (&exit_block_uses
);
4507 is_eq
= bitmap_equal_p (&exit_block_uses
, df
->exit_block_uses
);
4509 if (!is_eq
&& abort_if_fail
)
4511 print_current_pass (stderr
);
4512 fprintf (stderr
, "exit_block_uses = ");
4513 df_print_regset (stderr
, &exit_block_uses
);
4514 fprintf (stderr
, "df->exit_block_uses = ");
4515 df_print_regset (stderr
, df
->exit_block_uses
);
4519 bitmap_clear (&exit_block_uses
);
4525 /* Return true if df_ref information for all insns in all blocks are
4526 correct and complete. */
4529 df_scan_verify (void)
4533 bitmap_head regular_block_artificial_uses
;
4534 bitmap_head eh_block_artificial_uses
;
4539 /* Verification is a 4 step process. */
4541 /* (1) All of the refs are marked by going through the reg chains. */
4542 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4544 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4545 == DF_REG_DEF_COUNT(i
));
4546 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4547 == DF_REG_USE_COUNT(i
));
4548 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4549 == DF_REG_EQ_USE_COUNT(i
));
4552 /* (2) There are various bitmaps whose value may change over the
4553 course of the compilation. This step recomputes them to make
4554 sure that they have not slipped out of date. */
4555 bitmap_initialize (®ular_block_artificial_uses
, &df_bitmap_obstack
);
4556 bitmap_initialize (&eh_block_artificial_uses
, &df_bitmap_obstack
);
4558 df_get_regular_block_artificial_uses (®ular_block_artificial_uses
);
4559 df_get_eh_block_artificial_uses (&eh_block_artificial_uses
);
4561 bitmap_ior_into (&eh_block_artificial_uses
,
4562 ®ular_block_artificial_uses
);
4564 /* Check artificial_uses bitmaps didn't change. */
4565 gcc_assert (bitmap_equal_p (®ular_block_artificial_uses
,
4566 &df
->regular_block_artificial_uses
));
4567 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses
,
4568 &df
->eh_block_artificial_uses
));
4570 bitmap_clear (®ular_block_artificial_uses
);
4571 bitmap_clear (&eh_block_artificial_uses
);
4573 /* Verify entry block and exit block. These only verify the bitmaps,
4574 the refs are verified in df_bb_verify. */
4575 df_entry_block_bitmap_verify (true);
4576 df_exit_block_bitmap_verify (true);
4578 /* (3) All of the insns in all of the blocks are traversed and the
4579 marks are cleared both in the artificial refs attached to the
4580 blocks and the real refs inside the insns. It is a failure to
4581 clear a mark that has not been set as this means that the ref in
4582 the block or insn was not in the reg chain. */
4587 /* (4) See if all reg chains are traversed a second time. This time
4588 a check is made that the marks are clear. A set mark would be a
4589 from a reg that is not in any insn or basic block. */
4591 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4593 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4594 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4595 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));