1 /* Scanning of rtl for dataflow analysis.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
31 #include "insn-config.h"
36 #include "alloc-pool.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
45 #include "target-def.h"
47 #include "tree-pass.h"
48 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
51 DEF_VEC_ALLOC_P_STACK(df_ref
);
53 #define VEC_df_ref_stack_alloc(alloc) VEC_stack_alloc (df_ref, alloc)
55 typedef struct df_mw_hardreg
*df_mw_hardreg_ptr
;
57 DEF_VEC_P(df_mw_hardreg_ptr
);
58 DEF_VEC_ALLOC_P_STACK(df_mw_hardreg_ptr
);
60 #define VEC_df_mw_hardreg_ptr_stack_alloc(alloc) \
61 VEC_stack_alloc (df_mw_hardreg_ptr, alloc)
64 #define HAVE_epilogue 0
67 #define HAVE_prologue 0
69 #ifndef HAVE_sibcall_epilogue
70 #define HAVE_sibcall_epilogue 0
74 #define EPILOGUE_USES(REGNO) 0
77 /* The following two macros free the vecs that hold either the refs or
78 the mw refs. They are a little tricky because the vec has 0
79 elements is special and is not to be freed. */
80 #define df_scan_free_ref_vec(V) \
86 #define df_scan_free_mws_vec(V) \
92 /* The set of hard registers in eliminables[i].from. */
94 static HARD_REG_SET elim_reg_set
;
96 /* Initialize ur_in and ur_out as if all hard registers were partially
99 struct df_collection_rec
101 VEC(df_ref
,stack
) *def_vec
;
102 VEC(df_ref
,stack
) *use_vec
;
103 VEC(df_ref
,stack
) *eq_use_vec
;
104 VEC(df_mw_hardreg_ptr
,stack
) *mw_vec
;
107 static df_ref df_null_ref_rec
[1];
108 static struct df_mw_hardreg
* df_null_mw_rec
[1];
110 static void df_ref_record (enum df_ref_class
, struct df_collection_rec
*,
112 basic_block
, struct df_insn_info
*,
113 enum df_ref_type
, int ref_flags
,
114 int, int, enum machine_mode
);
115 static void df_def_record_1 (struct df_collection_rec
*, rtx
,
116 basic_block
, struct df_insn_info
*,
118 static void df_defs_record (struct df_collection_rec
*, rtx
,
119 basic_block
, struct df_insn_info
*,
121 static void df_uses_record (enum df_ref_class
, struct df_collection_rec
*,
122 rtx
*, enum df_ref_type
,
123 basic_block
, struct df_insn_info
*,
125 int, int, enum machine_mode
);
127 static df_ref
df_ref_create_structure (enum df_ref_class
,
128 struct df_collection_rec
*, rtx
, rtx
*,
129 basic_block
, struct df_insn_info
*,
130 enum df_ref_type
, int ref_flags
,
131 int, int, enum machine_mode
);
133 static void df_insn_refs_collect (struct df_collection_rec
*,
134 basic_block
, struct df_insn_info
*);
135 static void df_canonize_collection_rec (struct df_collection_rec
*);
137 static void df_get_regular_block_artificial_uses (bitmap
);
138 static void df_get_eh_block_artificial_uses (bitmap
);
140 static void df_record_entry_block_defs (bitmap
);
141 static void df_record_exit_block_uses (bitmap
);
142 static void df_get_exit_block_use_set (bitmap
);
143 static void df_get_entry_block_def_set (bitmap
);
144 static void df_grow_ref_info (struct df_ref_info
*, unsigned int);
145 static void df_ref_chain_delete_du_chain (df_ref
*);
146 static void df_ref_chain_delete (df_ref
*);
148 static void df_refs_add_to_chains (struct df_collection_rec
*,
151 static bool df_insn_refs_verify (struct df_collection_rec
*, basic_block
, rtx
, bool);
152 static void df_entry_block_defs_collect (struct df_collection_rec
*, bitmap
);
153 static void df_exit_block_uses_collect (struct df_collection_rec
*, bitmap
);
154 static void df_install_ref (df_ref
, struct df_reg_info
*,
155 struct df_ref_info
*, bool);
157 static int df_ref_compare (const void *, const void *);
158 static int df_mw_compare (const void *, const void *);
160 /* Indexed by hardware reg number, is true if that register is ever
161 used in the current function.
163 In df-scan.c, this is set up to record the hard regs used
164 explicitly. Reload adds in the hard regs used for holding pseudo
165 regs. Final uses it to generate the code in the function prologue
166 and epilogue to save and restore registers as needed. */
168 static bool regs_ever_live
[FIRST_PSEUDO_REGISTER
];
170 /*----------------------------------------------------------------------------
171 SCANNING DATAFLOW PROBLEM
173 There are several ways in which scanning looks just like the other
174 dataflow problems. It shares the all the mechanisms for local info
175 as well as basic block info. Where it differs is when and how often
176 it gets run. It also has no need for the iterative solver.
177 ----------------------------------------------------------------------------*/
179 /* Problem data for the scanning dataflow function. */
180 struct df_scan_problem_data
182 alloc_pool ref_base_pool
;
183 alloc_pool ref_artificial_pool
;
184 alloc_pool ref_regular_pool
;
185 alloc_pool ref_extract_pool
;
186 alloc_pool insn_pool
;
188 alloc_pool mw_reg_pool
;
189 bitmap_obstack reg_bitmaps
;
190 bitmap_obstack insn_bitmaps
;
193 typedef struct df_scan_bb_info
*df_scan_bb_info_t
;
196 /* Internal function to shut down the scanning problem. */
198 df_scan_free_internal (void)
200 struct df_scan_problem_data
*problem_data
201 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
205 /* The vectors that hold the refs are not pool allocated because
206 they come in many sizes. This makes them impossible to delete
208 for (i
= 0; i
< DF_INSN_SIZE(); i
++)
210 struct df_insn_info
*insn_info
= DF_INSN_UID_GET(i
);
211 /* Skip the insns that have no insn_info or have been
215 df_scan_free_ref_vec (insn_info
->defs
);
216 df_scan_free_ref_vec (insn_info
->uses
);
217 df_scan_free_ref_vec (insn_info
->eq_uses
);
218 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
224 unsigned int bb_index
= bb
->index
;
225 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
228 df_scan_free_ref_vec (bb_info
->artificial_defs
);
229 df_scan_free_ref_vec (bb_info
->artificial_uses
);
233 free (df
->def_info
.refs
);
234 free (df
->def_info
.begin
);
235 free (df
->def_info
.count
);
236 memset (&df
->def_info
, 0, (sizeof (struct df_ref_info
)));
238 free (df
->use_info
.refs
);
239 free (df
->use_info
.begin
);
240 free (df
->use_info
.count
);
241 memset (&df
->use_info
, 0, (sizeof (struct df_ref_info
)));
247 free (df
->eq_use_regs
);
248 df
->eq_use_regs
= NULL
;
256 free (df_scan
->block_info
);
257 df_scan
->block_info
= NULL
;
258 df_scan
->block_info_size
= 0;
260 bitmap_clear (&df
->hardware_regs_used
);
261 bitmap_clear (&df
->regular_block_artificial_uses
);
262 bitmap_clear (&df
->eh_block_artificial_uses
);
263 BITMAP_FREE (df
->entry_block_defs
);
264 BITMAP_FREE (df
->exit_block_uses
);
265 bitmap_clear (&df
->insns_to_delete
);
266 bitmap_clear (&df
->insns_to_rescan
);
267 bitmap_clear (&df
->insns_to_notes_rescan
);
269 free_alloc_pool (problem_data
->ref_base_pool
);
270 free_alloc_pool (problem_data
->ref_artificial_pool
);
271 free_alloc_pool (problem_data
->ref_regular_pool
);
272 free_alloc_pool (problem_data
->ref_extract_pool
);
273 free_alloc_pool (problem_data
->insn_pool
);
274 free_alloc_pool (problem_data
->reg_pool
);
275 free_alloc_pool (problem_data
->mw_reg_pool
);
276 bitmap_obstack_release (&problem_data
->reg_bitmaps
);
277 bitmap_obstack_release (&problem_data
->insn_bitmaps
);
278 free (df_scan
->problem_data
);
282 /* Free basic block info. */
285 df_scan_free_bb_info (basic_block bb
, void *vbb_info
)
287 struct df_scan_bb_info
*bb_info
= (struct df_scan_bb_info
*) vbb_info
;
288 unsigned int bb_index
= bb
->index
;
290 /* See if bb_info is initialized. */
291 if (bb_info
->artificial_defs
)
294 FOR_BB_INSNS (bb
, insn
)
297 /* Record defs within INSN. */
298 df_insn_delete (bb
, INSN_UID (insn
));
301 if (bb_index
< df_scan
->block_info_size
)
302 bb_info
= df_scan_get_bb_info (bb_index
);
304 /* Get rid of any artificial uses or defs. */
305 if (bb_info
->artificial_defs
)
307 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
308 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
309 df_ref_chain_delete (bb_info
->artificial_defs
);
310 df_ref_chain_delete (bb_info
->artificial_uses
);
311 bb_info
->artificial_defs
= NULL
;
312 bb_info
->artificial_uses
= NULL
;
318 /* Allocate the problem data for the scanning problem. This should be
319 called when the problem is created or when the entire function is to
322 df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
324 struct df_scan_problem_data
*problem_data
;
325 unsigned int insn_num
= get_max_uid () + 1;
326 unsigned int block_size
= 400;
329 /* Given the number of pools, this is really faster than tearing
331 if (df_scan
->problem_data
)
332 df_scan_free_internal ();
334 problem_data
= XNEW (struct df_scan_problem_data
);
335 df_scan
->problem_data
= problem_data
;
336 df_scan
->computed
= true;
338 problem_data
->ref_base_pool
339 = create_alloc_pool ("df_scan ref base",
340 sizeof (struct df_base_ref
), block_size
);
341 problem_data
->ref_artificial_pool
342 = create_alloc_pool ("df_scan ref artificial",
343 sizeof (struct df_artificial_ref
), block_size
);
344 problem_data
->ref_regular_pool
345 = create_alloc_pool ("df_scan ref regular",
346 sizeof (struct df_regular_ref
), block_size
);
347 problem_data
->ref_extract_pool
348 = create_alloc_pool ("df_scan ref extract",
349 sizeof (struct df_extract_ref
), block_size
);
350 problem_data
->insn_pool
351 = create_alloc_pool ("df_scan insn",
352 sizeof (struct df_insn_info
), block_size
);
353 problem_data
->reg_pool
354 = create_alloc_pool ("df_scan reg",
355 sizeof (struct df_reg_info
), block_size
);
356 problem_data
->mw_reg_pool
357 = create_alloc_pool ("df_scan mw_reg",
358 sizeof (struct df_mw_hardreg
), block_size
);
360 bitmap_obstack_initialize (&problem_data
->reg_bitmaps
);
361 bitmap_obstack_initialize (&problem_data
->insn_bitmaps
);
363 insn_num
+= insn_num
/ 4;
366 df_grow_insn_info ();
367 df_grow_bb_info (df_scan
);
371 unsigned int bb_index
= bb
->index
;
372 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb_index
);
373 bb_info
->artificial_defs
= NULL
;
374 bb_info
->artificial_uses
= NULL
;
377 bitmap_initialize (&df
->hardware_regs_used
, &problem_data
->reg_bitmaps
);
378 bitmap_initialize (&df
->regular_block_artificial_uses
, &problem_data
->reg_bitmaps
);
379 bitmap_initialize (&df
->eh_block_artificial_uses
, &problem_data
->reg_bitmaps
);
380 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
381 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
382 bitmap_initialize (&df
->insns_to_delete
, &problem_data
->insn_bitmaps
);
383 bitmap_initialize (&df
->insns_to_rescan
, &problem_data
->insn_bitmaps
);
384 bitmap_initialize (&df
->insns_to_notes_rescan
, &problem_data
->insn_bitmaps
);
385 df_scan
->optional_p
= false;
389 /* Free all of the data associated with the scan problem. */
394 if (df_scan
->problem_data
)
395 df_scan_free_internal ();
397 if (df
->blocks_to_analyze
)
399 BITMAP_FREE (df
->blocks_to_analyze
);
400 df
->blocks_to_analyze
= NULL
;
406 /* Dump the preamble for DF_SCAN dump. */
408 df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED
)
419 fprintf (file
, ";; invalidated by call \t");
420 df_print_regset (file
, regs_invalidated_by_call_regset
);
421 fprintf (file
, ";; hardware regs used \t");
422 df_print_regset (file
, &df
->hardware_regs_used
);
423 fprintf (file
, ";; regular block artificial uses \t");
424 df_print_regset (file
, &df
->regular_block_artificial_uses
);
425 fprintf (file
, ";; eh block artificial uses \t");
426 df_print_regset (file
, &df
->eh_block_artificial_uses
);
427 fprintf (file
, ";; entry block defs \t");
428 df_print_regset (file
, df
->entry_block_defs
);
429 fprintf (file
, ";; exit block uses \t");
430 df_print_regset (file
, df
->exit_block_uses
);
431 fprintf (file
, ";; regs ever live \t");
432 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
433 if (df_regs_ever_live_p (i
))
434 fprintf (file
, " %d[%s]", i
, reg_names
[i
]);
435 fprintf (file
, "\n;; ref usage \t");
437 for (i
= 0; i
< (int)df
->regs_inited
; i
++)
438 if (DF_REG_DEF_COUNT (i
) || DF_REG_USE_COUNT (i
) || DF_REG_EQ_USE_COUNT (i
))
440 const char * sep
= "";
442 fprintf (file
, "r%d={", i
);
443 if (DF_REG_DEF_COUNT (i
))
445 fprintf (file
, "%dd", DF_REG_DEF_COUNT (i
));
447 dcount
+= DF_REG_DEF_COUNT (i
);
449 if (DF_REG_USE_COUNT (i
))
451 fprintf (file
, "%s%du", sep
, DF_REG_USE_COUNT (i
));
453 ucount
+= DF_REG_USE_COUNT (i
);
455 if (DF_REG_EQ_USE_COUNT (i
))
457 fprintf (file
, "%s%dd", sep
, DF_REG_EQ_USE_COUNT (i
));
458 ecount
+= DF_REG_EQ_USE_COUNT (i
);
460 fprintf (file
, "} ");
464 FOR_BB_INSNS (bb
, insn
)
473 fprintf (file
, "\n;; total ref usage %d{%dd,%du,%de} in %d{%d regular + %d call} insns.\n",
474 dcount
+ ucount
+ ecount
, dcount
, ucount
, ecount
, icount
+ ccount
, icount
, ccount
);
477 /* Dump the bb_info for a given basic block. */
479 df_scan_start_block (basic_block bb
, FILE *file
)
481 struct df_scan_bb_info
*bb_info
482 = df_scan_get_bb_info (bb
->index
);
486 fprintf (file
, ";; bb %d artificial_defs: ", bb
->index
);
487 df_refs_chain_dump (bb_info
->artificial_defs
, true, file
);
488 fprintf (file
, "\n;; bb %d artificial_uses: ", bb
->index
);
489 df_refs_chain_dump (bb_info
->artificial_uses
, true, file
);
490 fprintf (file
, "\n");
495 FOR_BB_INSNS (bb
, insn
)
497 df_insn_debug (insn
, false, file
);
502 static struct df_problem problem_SCAN
=
504 DF_SCAN
, /* Problem id. */
505 DF_NONE
, /* Direction. */
506 df_scan_alloc
, /* Allocate the problem specific data. */
507 NULL
, /* Reset global information. */
508 df_scan_free_bb_info
, /* Free basic block info. */
509 NULL
, /* Local compute function. */
510 NULL
, /* Init the solution specific data. */
511 NULL
, /* Iterative solver. */
512 NULL
, /* Confluence operator 0. */
513 NULL
, /* Confluence operator n. */
514 NULL
, /* Transfer function. */
515 NULL
, /* Finalize function. */
516 df_scan_free
, /* Free all of the problem information. */
517 NULL
, /* Remove this problem from the stack of dataflow problems. */
518 df_scan_start_dump
, /* Debugging. */
519 df_scan_start_block
, /* Debugging start block. */
520 NULL
, /* Debugging end block. */
521 NULL
, /* Incremental solution verify start. */
522 NULL
, /* Incremental solution verify end. */
523 NULL
, /* Dependent problem. */
524 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
525 TV_DF_SCAN
, /* Timing variable. */
526 false /* Reset blocks on dropping out of blocks_to_analyze. */
530 /* Create a new DATAFLOW instance and add it to an existing instance
531 of DF. The returned structure is what is used to get at the
535 df_scan_add_problem (void)
537 df_add_problem (&problem_SCAN
);
541 /*----------------------------------------------------------------------------
542 Storage Allocation Utilities
543 ----------------------------------------------------------------------------*/
546 /* First, grow the reg_info information. If the current size is less than
547 the number of pseudos, grow to 25% more than the number of
550 Second, assure that all of the slots up to max_reg_num have been
551 filled with reg_info structures. */
554 df_grow_reg_info (void)
556 unsigned int max_reg
= max_reg_num ();
557 unsigned int new_size
= max_reg
;
558 struct df_scan_problem_data
*problem_data
559 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
562 if (df
->regs_size
< new_size
)
564 new_size
+= new_size
/ 4;
565 df
->def_regs
= XRESIZEVEC (struct df_reg_info
*, df
->def_regs
, new_size
);
566 df
->use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->use_regs
, new_size
);
567 df
->eq_use_regs
= XRESIZEVEC (struct df_reg_info
*, df
->eq_use_regs
,
569 df
->def_info
.begin
= XRESIZEVEC (unsigned, df
->def_info
.begin
, new_size
);
570 df
->def_info
.count
= XRESIZEVEC (unsigned, df
->def_info
.count
, new_size
);
571 df
->use_info
.begin
= XRESIZEVEC (unsigned, df
->use_info
.begin
, new_size
);
572 df
->use_info
.count
= XRESIZEVEC (unsigned, df
->use_info
.count
, new_size
);
573 df
->regs_size
= new_size
;
576 for (i
= df
->regs_inited
; i
< max_reg
; i
++)
578 struct df_reg_info
*reg_info
;
580 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
581 memset (reg_info
, 0, sizeof (struct df_reg_info
));
582 df
->def_regs
[i
] = reg_info
;
583 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
584 memset (reg_info
, 0, sizeof (struct df_reg_info
));
585 df
->use_regs
[i
] = reg_info
;
586 reg_info
= (struct df_reg_info
*) pool_alloc (problem_data
->reg_pool
);
587 memset (reg_info
, 0, sizeof (struct df_reg_info
));
588 df
->eq_use_regs
[i
] = reg_info
;
589 df
->def_info
.begin
[i
] = 0;
590 df
->def_info
.count
[i
] = 0;
591 df
->use_info
.begin
[i
] = 0;
592 df
->use_info
.count
[i
] = 0;
595 df
->regs_inited
= max_reg
;
599 /* Grow the ref information. */
602 df_grow_ref_info (struct df_ref_info
*ref_info
, unsigned int new_size
)
604 if (ref_info
->refs_size
< new_size
)
606 ref_info
->refs
= XRESIZEVEC (df_ref
, ref_info
->refs
, new_size
);
607 memset (ref_info
->refs
+ ref_info
->refs_size
, 0,
608 (new_size
- ref_info
->refs_size
) *sizeof (df_ref
));
609 ref_info
->refs_size
= new_size
;
614 /* Check and grow the ref information if necessary. This routine
615 guarantees total_size + BITMAP_ADDEND amount of entries in refs
616 array. It updates ref_info->refs_size only and does not change
617 ref_info->total_size. */
620 df_check_and_grow_ref_info (struct df_ref_info
*ref_info
,
621 unsigned bitmap_addend
)
623 if (ref_info
->refs_size
< ref_info
->total_size
+ bitmap_addend
)
625 int new_size
= ref_info
->total_size
+ bitmap_addend
;
626 new_size
+= ref_info
->total_size
/ 4;
627 df_grow_ref_info (ref_info
, new_size
);
632 /* Grow the ref information. If the current size is less than the
633 number of instructions, grow to 25% more than the number of
637 df_grow_insn_info (void)
639 unsigned int new_size
= get_max_uid () + 1;
640 if (DF_INSN_SIZE () < new_size
)
642 new_size
+= new_size
/ 4;
643 df
->insns
= XRESIZEVEC (struct df_insn_info
*, df
->insns
, new_size
);
644 memset (df
->insns
+ df
->insns_size
, 0,
645 (new_size
- DF_INSN_SIZE ()) *sizeof (struct df_insn_info
*));
646 DF_INSN_SIZE () = new_size
;
653 /*----------------------------------------------------------------------------
654 PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
655 ----------------------------------------------------------------------------*/
657 /* Rescan all of the block_to_analyze or all of the blocks in the
658 function if df_set_blocks if blocks_to_analyze is NULL; */
661 df_scan_blocks (void)
665 df
->def_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
666 df
->use_info
.ref_order
= DF_REF_ORDER_NO_TABLE
;
668 df_get_regular_block_artificial_uses (&df
->regular_block_artificial_uses
);
669 df_get_eh_block_artificial_uses (&df
->eh_block_artificial_uses
);
671 bitmap_ior_into (&df
->eh_block_artificial_uses
,
672 &df
->regular_block_artificial_uses
);
674 /* ENTRY and EXIT blocks have special defs/uses. */
675 df_get_entry_block_def_set (df
->entry_block_defs
);
676 df_record_entry_block_defs (df
->entry_block_defs
);
677 df_get_exit_block_use_set (df
->exit_block_uses
);
678 df_record_exit_block_uses (df
->exit_block_uses
);
679 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
680 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
685 unsigned int bb_index
= bb
->index
;
686 df_bb_refs_record (bb_index
, true);
691 /* Create a new ref of type DF_REF_TYPE for register REG at address
692 LOC within INSN of BB. This function is only used externally.
694 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
695 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
696 fields if they were constants. Otherwise they should be -1 if
697 those flags were set. */
700 df_ref_create (rtx reg
, rtx
*loc
, rtx insn
,
702 enum df_ref_type ref_type
,
704 int width
, int offset
, enum machine_mode mode
)
707 struct df_reg_info
**reg_info
;
708 struct df_ref_info
*ref_info
;
710 df_ref
**ref_rec_ptr
;
711 unsigned int count
= 0;
713 enum df_ref_class cl
;
717 /* You cannot hack artificial refs. */
720 if (width
!= -1 || offset
!= -1)
726 ref
= df_ref_create_structure (cl
, NULL
, reg
, loc
, bb
, DF_INSN_INFO_GET (insn
),
728 width
, offset
, mode
);
730 if (DF_REF_REG_DEF_P (ref
))
732 reg_info
= df
->def_regs
;
733 ref_info
= &df
->def_info
;
734 ref_rec_ptr
= &DF_INSN_DEFS (insn
);
735 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
737 else if (DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
)
739 reg_info
= df
->eq_use_regs
;
740 ref_info
= &df
->use_info
;
741 ref_rec_ptr
= &DF_INSN_EQ_USES (insn
);
742 switch (ref_info
->ref_order
)
744 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
745 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
746 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
750 add_to_table
= false;
756 reg_info
= df
->use_regs
;
757 ref_info
= &df
->use_info
;
758 ref_rec_ptr
= &DF_INSN_USES (insn
);
759 add_to_table
= ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
;
762 /* Do not add if ref is not in the right blocks. */
763 if (add_to_table
&& df
->analyze_subset
)
764 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
766 df_install_ref (ref
, reg_info
[DF_REF_REGNO (ref
)], ref_info
, add_to_table
);
769 switch (ref_info
->ref_order
)
771 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
772 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
773 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
774 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
777 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
781 ref_rec
= *ref_rec_ptr
;
788 ref_rec
= *ref_rec_ptr
;
791 ref_rec
= XRESIZEVEC (df_ref
, ref_rec
, count
+2);
792 *ref_rec_ptr
= ref_rec
;
793 ref_rec
[count
] = ref
;
794 ref_rec
[count
+1] = NULL
;
795 qsort (ref_rec
, count
+ 1, sizeof (df_ref
), df_ref_compare
);
799 df_ref
*ref_rec
= XNEWVEC (df_ref
, 2);
802 *ref_rec_ptr
= ref_rec
;
808 fprintf (dump_file
, "adding ref ");
809 df_ref_debug (ref
, dump_file
);
812 /* By adding the ref directly, df_insn_rescan my not find any
813 differences even though the block will have changed. So we need
814 to mark the block dirty ourselves. */
815 if (!DEBUG_INSN_P (DF_REF_INSN (ref
)))
816 df_set_bb_dirty (bb
);
823 /*----------------------------------------------------------------------------
824 UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
825 ----------------------------------------------------------------------------*/
828 df_free_ref (df_ref ref
)
830 struct df_scan_problem_data
*problem_data
831 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
833 switch (DF_REF_CLASS (ref
))
836 pool_free (problem_data
->ref_base_pool
, ref
);
839 case DF_REF_ARTIFICIAL
:
840 pool_free (problem_data
->ref_artificial_pool
, ref
);
844 pool_free (problem_data
->ref_regular_pool
, ref
);
848 pool_free (problem_data
->ref_extract_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 (ix
= 0; VEC_iterate (df_ref
, collection_rec
->def_vec
, ix
, ref
); ++ix
)
1185 for (ix
= 0; VEC_iterate (df_ref
, collection_rec
->use_vec
, ix
, ref
); ++ix
)
1187 for (ix
= 0; VEC_iterate (df_ref
, collection_rec
->eq_use_vec
, ix
, ref
); ++ix
)
1190 VEC_iterate (df_mw_hardreg_ptr
, collection_rec
->mw_vec
, ix
, mw
);
1192 pool_free (problem_data
->mw_reg_pool
, mw
);
1194 VEC_free (df_ref
, stack
, collection_rec
->def_vec
);
1195 VEC_free (df_ref
, stack
, collection_rec
->use_vec
);
1196 VEC_free (df_ref
, stack
, collection_rec
->eq_use_vec
);
1197 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
->mw_vec
);
1200 /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
1203 df_insn_rescan (rtx insn
)
1205 unsigned int uid
= INSN_UID (insn
);
1206 struct df_insn_info
*insn_info
= NULL
;
1207 basic_block bb
= BLOCK_FOR_INSN (insn
);
1208 struct df_collection_rec collection_rec
;
1210 if ((!df
) || (!INSN_P (insn
)))
1216 fprintf (dump_file
, "no bb for insn with uid = %d.\n", uid
);
1220 /* The client has disabled rescanning and plans to do it itself. */
1221 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1224 df_grow_bb_info (df_scan
);
1225 df_grow_reg_info ();
1227 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1229 /* The client has deferred rescanning. */
1230 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1234 insn_info
= df_insn_create_insn_record (insn
);
1235 insn_info
->defs
= df_null_ref_rec
;
1236 insn_info
->uses
= df_null_ref_rec
;
1237 insn_info
->eq_uses
= df_null_ref_rec
;
1238 insn_info
->mw_hardregs
= df_null_mw_rec
;
1241 fprintf (dump_file
, "deferring rescan insn with uid = %d.\n", uid
);
1243 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1244 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1245 bitmap_set_bit (&df
->insns_to_rescan
, INSN_UID (insn
));
1249 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, 128);
1250 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, 32);
1251 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
1252 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
1254 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1255 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1256 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1260 bool the_same
= df_insn_refs_verify (&collection_rec
, bb
, insn
, false);
1261 /* If there's no change, return false. */
1264 df_free_collection_rec (&collection_rec
);
1266 fprintf (dump_file
, "verify found no changes in insn with uid = %d.\n", uid
);
1270 fprintf (dump_file
, "rescanning insn with uid = %d.\n", uid
);
1272 /* There's change - we need to delete the existing info.
1273 Since the insn isn't moved, we can salvage its LUID. */
1274 luid
= DF_INSN_LUID (insn
);
1275 df_insn_delete (NULL
, uid
);
1276 df_insn_create_insn_record (insn
);
1277 DF_INSN_LUID (insn
) = luid
;
1281 struct df_insn_info
*insn_info
= df_insn_create_insn_record (insn
);
1282 df_insn_refs_collect (&collection_rec
, bb
, insn_info
);
1284 fprintf (dump_file
, "scanning new insn with uid = %d.\n", uid
);
1287 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
1288 if (DEBUG_INSN_P (insn
))
1289 df_set_bb_dirty_nonlr (bb
);
1291 df_set_bb_dirty (bb
);
1293 VEC_free (df_ref
, stack
, collection_rec
.def_vec
);
1294 VEC_free (df_ref
, stack
, collection_rec
.use_vec
);
1295 VEC_free (df_ref
, stack
, collection_rec
.eq_use_vec
);
1296 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
.mw_vec
);
1301 /* Same as df_insn_rescan, but don't mark the basic block as
1305 df_insn_rescan_debug_internal (rtx insn
)
1307 unsigned int uid
= INSN_UID (insn
);
1308 struct df_insn_info
*insn_info
;
1310 gcc_assert (DEBUG_INSN_P (insn
)
1311 && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn
)));
1316 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID (insn
));
1321 fprintf (dump_file
, "deleting debug_insn with uid = %d.\n", uid
);
1323 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
1324 bitmap_clear_bit (&df
->insns_to_rescan
, uid
);
1325 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
1327 if (!insn_info
->defs
)
1330 if (insn_info
->defs
== df_null_ref_rec
1331 && insn_info
->uses
== df_null_ref_rec
1332 && insn_info
->eq_uses
== df_null_ref_rec
1333 && insn_info
->mw_hardregs
== df_null_mw_rec
)
1336 df_mw_hardreg_chain_delete (insn_info
->mw_hardregs
);
1340 df_ref_chain_delete_du_chain (insn_info
->defs
);
1341 df_ref_chain_delete_du_chain (insn_info
->uses
);
1342 df_ref_chain_delete_du_chain (insn_info
->eq_uses
);
1345 df_ref_chain_delete (insn_info
->defs
);
1346 df_ref_chain_delete (insn_info
->uses
);
1347 df_ref_chain_delete (insn_info
->eq_uses
);
1349 insn_info
->defs
= df_null_ref_rec
;
1350 insn_info
->uses
= df_null_ref_rec
;
1351 insn_info
->eq_uses
= df_null_ref_rec
;
1352 insn_info
->mw_hardregs
= df_null_mw_rec
;
1358 /* Rescan all of the insns in the function. Note that the artificial
1359 uses and defs are not touched. This function will destroy def-se
1360 or use-def chains. */
1363 df_insn_rescan_all (void)
1365 bool no_insn_rescan
= false;
1366 bool defer_insn_rescan
= false;
1372 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1374 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1376 df_clear_flags (DF_NO_INSN_RESCAN
);
1377 no_insn_rescan
= true;
1380 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1382 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1383 defer_insn_rescan
= true;
1386 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1387 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1389 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1391 df_insn_delete (NULL
, uid
);
1394 bitmap_clear (&tmp
);
1395 bitmap_clear (&df
->insns_to_delete
);
1396 bitmap_clear (&df
->insns_to_rescan
);
1397 bitmap_clear (&df
->insns_to_notes_rescan
);
1402 FOR_BB_INSNS (bb
, insn
)
1404 df_insn_rescan (insn
);
1409 df_set_flags (DF_NO_INSN_RESCAN
);
1410 if (defer_insn_rescan
)
1411 df_set_flags (DF_DEFER_INSN_RESCAN
);
1415 /* Process all of the deferred rescans or deletions. */
1418 df_process_deferred_rescans (void)
1420 bool no_insn_rescan
= false;
1421 bool defer_insn_rescan
= false;
1426 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
1428 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
1430 df_clear_flags (DF_NO_INSN_RESCAN
);
1431 no_insn_rescan
= true;
1434 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
1436 df_clear_flags (DF_DEFER_INSN_RESCAN
);
1437 defer_insn_rescan
= true;
1441 fprintf (dump_file
, "starting the processing of deferred insns\n");
1443 bitmap_copy (&tmp
, &df
->insns_to_delete
);
1444 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1446 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1448 df_insn_delete (NULL
, uid
);
1451 bitmap_copy (&tmp
, &df
->insns_to_rescan
);
1452 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1454 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1456 df_insn_rescan (insn_info
->insn
);
1459 bitmap_copy (&tmp
, &df
->insns_to_notes_rescan
);
1460 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, uid
, bi
)
1462 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1464 df_notes_rescan (insn_info
->insn
);
1468 fprintf (dump_file
, "ending the processing of deferred insns\n");
1470 bitmap_clear (&tmp
);
1471 bitmap_clear (&df
->insns_to_delete
);
1472 bitmap_clear (&df
->insns_to_rescan
);
1473 bitmap_clear (&df
->insns_to_notes_rescan
);
1476 df_set_flags (DF_NO_INSN_RESCAN
);
1477 if (defer_insn_rescan
)
1478 df_set_flags (DF_DEFER_INSN_RESCAN
);
1480 /* If someone changed regs_ever_live during this pass, fix up the
1481 entry and exit blocks. */
1482 if (df
->redo_entry_and_exit
)
1484 df_update_entry_exit_and_calls ();
1485 df
->redo_entry_and_exit
= false;
1490 /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
1491 the uses if INCLUDE_USES. Include the eq_uses if
1495 df_count_refs (bool include_defs
, bool include_uses
,
1496 bool include_eq_uses
)
1500 unsigned int m
= df
->regs_inited
;
1502 for (regno
= 0; regno
< m
; regno
++)
1505 size
+= DF_REG_DEF_COUNT (regno
);
1507 size
+= DF_REG_USE_COUNT (regno
);
1508 if (include_eq_uses
)
1509 size
+= DF_REG_EQ_USE_COUNT (regno
);
1515 /* Take build ref table for either the uses or defs from the reg-use
1516 or reg-def chains. This version processes the refs in reg order
1517 which is likely to be best if processing the whole function. */
1520 df_reorganize_refs_by_reg_by_reg (struct df_ref_info
*ref_info
,
1523 bool include_eq_uses
)
1525 unsigned int m
= df
->regs_inited
;
1527 unsigned int offset
= 0;
1530 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
1532 start
= FIRST_PSEUDO_REGISTER
;
1533 memset (ref_info
->begin
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1534 memset (ref_info
->count
, 0, sizeof (int) * FIRST_PSEUDO_REGISTER
);
1539 ref_info
->total_size
1540 = df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1542 df_check_and_grow_ref_info (ref_info
, 1);
1544 for (regno
= start
; regno
< m
; regno
++)
1547 ref_info
->begin
[regno
] = offset
;
1550 df_ref ref
= DF_REG_DEF_CHAIN (regno
);
1553 ref_info
->refs
[offset
] = ref
;
1554 DF_REF_ID (ref
) = offset
++;
1556 ref
= DF_REF_NEXT_REG (ref
);
1557 gcc_checking_assert (offset
< ref_info
->refs_size
);
1562 df_ref ref
= DF_REG_USE_CHAIN (regno
);
1565 ref_info
->refs
[offset
] = ref
;
1566 DF_REF_ID (ref
) = offset
++;
1568 ref
= DF_REF_NEXT_REG (ref
);
1569 gcc_checking_assert (offset
< ref_info
->refs_size
);
1572 if (include_eq_uses
)
1574 df_ref ref
= DF_REG_EQ_USE_CHAIN (regno
);
1577 ref_info
->refs
[offset
] = ref
;
1578 DF_REF_ID (ref
) = offset
++;
1580 ref
= DF_REF_NEXT_REG (ref
);
1581 gcc_checking_assert (offset
< ref_info
->refs_size
);
1584 ref_info
->count
[regno
] = count
;
1587 /* The bitmap size is not decremented when refs are deleted. So
1588 reset it now that we have squished out all of the empty
1590 ref_info
->table_size
= offset
;
1594 /* Take build ref table for either the uses or defs from the reg-use
1595 or reg-def chains. This version processes the refs in insn order
1596 which is likely to be best if processing some segment of the
1600 df_reorganize_refs_by_reg_by_insn (struct df_ref_info
*ref_info
,
1603 bool include_eq_uses
)
1606 unsigned int bb_index
;
1607 unsigned int m
= df
->regs_inited
;
1608 unsigned int offset
= 0;
1611 = (df
->changeable_flags
& DF_NO_HARD_REGS
) ? FIRST_PSEUDO_REGISTER
: 0;
1613 memset (ref_info
->begin
, 0, sizeof (int) * df
->regs_inited
);
1614 memset (ref_info
->count
, 0, sizeof (int) * df
->regs_inited
);
1616 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1617 df_check_and_grow_ref_info (ref_info
, 1);
1619 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1621 basic_block bb
= BASIC_BLOCK (bb_index
);
1626 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1628 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1629 ref_info
->count
[regno
]++;
1632 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1634 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1635 ref_info
->count
[regno
]++;
1638 FOR_BB_INSNS (bb
, insn
)
1642 unsigned int uid
= INSN_UID (insn
);
1645 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1647 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1648 ref_info
->count
[regno
]++;
1651 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1653 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1654 ref_info
->count
[regno
]++;
1656 if (include_eq_uses
)
1657 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1659 unsigned int regno
= DF_REF_REGNO (*ref_rec
);
1660 ref_info
->count
[regno
]++;
1666 for (r
= start
; r
< m
; r
++)
1668 ref_info
->begin
[r
] = offset
;
1669 offset
+= ref_info
->count
[r
];
1670 ref_info
->count
[r
] = 0;
1673 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, bb_index
, bi
)
1675 basic_block bb
= BASIC_BLOCK (bb_index
);
1680 for (ref_rec
= df_get_artificial_defs (bb_index
); *ref_rec
; ref_rec
++)
1682 df_ref ref
= *ref_rec
;
1683 unsigned int regno
= DF_REF_REGNO (ref
);
1687 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1688 DF_REF_ID (ref
) = id
;
1689 ref_info
->refs
[id
] = ref
;
1693 for (ref_rec
= df_get_artificial_uses (bb_index
); *ref_rec
; ref_rec
++)
1695 df_ref ref
= *ref_rec
;
1696 unsigned int regno
= DF_REF_REGNO (ref
);
1700 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1701 DF_REF_ID (ref
) = id
;
1702 ref_info
->refs
[id
] = ref
;
1706 FOR_BB_INSNS (bb
, insn
)
1710 unsigned int uid
= INSN_UID (insn
);
1713 for (ref_rec
= DF_INSN_UID_DEFS (uid
); *ref_rec
; ref_rec
++)
1715 df_ref ref
= *ref_rec
;
1716 unsigned int regno
= DF_REF_REGNO (ref
);
1720 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1721 DF_REF_ID (ref
) = id
;
1722 ref_info
->refs
[id
] = ref
;
1726 for (ref_rec
= DF_INSN_UID_USES (uid
); *ref_rec
; ref_rec
++)
1728 df_ref ref
= *ref_rec
;
1729 unsigned int regno
= DF_REF_REGNO (ref
);
1733 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1734 DF_REF_ID (ref
) = id
;
1735 ref_info
->refs
[id
] = ref
;
1738 if (include_eq_uses
)
1739 for (ref_rec
= DF_INSN_UID_EQ_USES (uid
); *ref_rec
; ref_rec
++)
1741 df_ref ref
= *ref_rec
;
1742 unsigned int regno
= DF_REF_REGNO (ref
);
1746 = ref_info
->begin
[regno
] + ref_info
->count
[regno
]++;
1747 DF_REF_ID (ref
) = id
;
1748 ref_info
->refs
[id
] = ref
;
1755 /* The bitmap size is not decremented when refs are deleted. So
1756 reset it now that we have squished out all of the empty
1759 ref_info
->table_size
= offset
;
1762 /* Take build ref table for either the uses or defs from the reg-use
1763 or reg-def chains. */
1766 df_reorganize_refs_by_reg (struct df_ref_info
*ref_info
,
1769 bool include_eq_uses
)
1771 if (df
->analyze_subset
)
1772 df_reorganize_refs_by_reg_by_insn (ref_info
, include_defs
,
1773 include_uses
, include_eq_uses
);
1775 df_reorganize_refs_by_reg_by_reg (ref_info
, include_defs
,
1776 include_uses
, include_eq_uses
);
1780 /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
1782 df_add_refs_to_table (unsigned int offset
,
1783 struct df_ref_info
*ref_info
,
1788 df_ref ref
= *ref_vec
;
1789 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
1790 || (DF_REF_REGNO (ref
) >= FIRST_PSEUDO_REGISTER
))
1792 ref_info
->refs
[offset
] = ref
;
1793 DF_REF_ID (*ref_vec
) = offset
++;
1801 /* Count the number of refs in all of the insns of BB. Include the
1802 defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
1803 eq_uses if INCLUDE_EQ_USES. */
1806 df_reorganize_refs_by_insn_bb (basic_block bb
, unsigned int offset
,
1807 struct df_ref_info
*ref_info
,
1808 bool include_defs
, bool include_uses
,
1809 bool include_eq_uses
)
1814 offset
= df_add_refs_to_table (offset
, ref_info
,
1815 df_get_artificial_defs (bb
->index
));
1817 offset
= df_add_refs_to_table (offset
, ref_info
,
1818 df_get_artificial_uses (bb
->index
));
1820 FOR_BB_INSNS (bb
, insn
)
1823 unsigned int uid
= INSN_UID (insn
);
1825 offset
= df_add_refs_to_table (offset
, ref_info
,
1826 DF_INSN_UID_DEFS (uid
));
1828 offset
= df_add_refs_to_table (offset
, ref_info
,
1829 DF_INSN_UID_USES (uid
));
1830 if (include_eq_uses
)
1831 offset
= df_add_refs_to_table (offset
, ref_info
,
1832 DF_INSN_UID_EQ_USES (uid
));
1838 /* Organize the refs by insn into the table in REF_INFO. If
1839 blocks_to_analyze is defined, use that set, otherwise the entire
1840 program. Include the defs if INCLUDE_DEFS. Include the uses if
1841 INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
1844 df_reorganize_refs_by_insn (struct df_ref_info
*ref_info
,
1845 bool include_defs
, bool include_uses
,
1846 bool include_eq_uses
)
1849 unsigned int offset
= 0;
1851 ref_info
->total_size
= df_count_refs (include_defs
, include_uses
, include_eq_uses
);
1852 df_check_and_grow_ref_info (ref_info
, 1);
1853 if (df
->blocks_to_analyze
)
1858 EXECUTE_IF_SET_IN_BITMAP (df
->blocks_to_analyze
, 0, index
, bi
)
1860 offset
= df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index
), offset
, ref_info
,
1861 include_defs
, include_uses
,
1865 ref_info
->table_size
= offset
;
1870 offset
= df_reorganize_refs_by_insn_bb (bb
, offset
, ref_info
,
1871 include_defs
, include_uses
,
1873 ref_info
->table_size
= offset
;
1878 /* If the use refs in DF are not organized, reorganize them. */
1881 df_maybe_reorganize_use_refs (enum df_ref_order order
)
1883 if (order
== df
->use_info
.ref_order
)
1888 case DF_REF_ORDER_BY_REG
:
1889 df_reorganize_refs_by_reg (&df
->use_info
, false, true, false);
1892 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1893 df_reorganize_refs_by_reg (&df
->use_info
, false, true, true);
1896 case DF_REF_ORDER_BY_INSN
:
1897 df_reorganize_refs_by_insn (&df
->use_info
, false, true, false);
1900 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1901 df_reorganize_refs_by_insn (&df
->use_info
, false, true, true);
1904 case DF_REF_ORDER_NO_TABLE
:
1905 free (df
->use_info
.refs
);
1906 df
->use_info
.refs
= NULL
;
1907 df
->use_info
.refs_size
= 0;
1910 case DF_REF_ORDER_UNORDERED
:
1911 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1916 df
->use_info
.ref_order
= order
;
1920 /* If the def refs in DF are not organized, reorganize them. */
1923 df_maybe_reorganize_def_refs (enum df_ref_order order
)
1925 if (order
== df
->def_info
.ref_order
)
1930 case DF_REF_ORDER_BY_REG
:
1931 df_reorganize_refs_by_reg (&df
->def_info
, true, false, false);
1934 case DF_REF_ORDER_BY_INSN
:
1935 df_reorganize_refs_by_insn (&df
->def_info
, true, false, false);
1938 case DF_REF_ORDER_NO_TABLE
:
1939 free (df
->def_info
.refs
);
1940 df
->def_info
.refs
= NULL
;
1941 df
->def_info
.refs_size
= 0;
1944 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
1945 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
1946 case DF_REF_ORDER_UNORDERED
:
1947 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
1952 df
->def_info
.ref_order
= order
;
1956 /* Change all of the basic block references in INSN to use the insn's
1957 current basic block. This function is called from routines that move
1958 instructions from one block to another. */
1961 df_insn_change_bb (rtx insn
, basic_block new_bb
)
1963 basic_block old_bb
= BLOCK_FOR_INSN (insn
);
1964 struct df_insn_info
*insn_info
;
1965 unsigned int uid
= INSN_UID (insn
);
1967 if (old_bb
== new_bb
)
1970 set_block_for_insn (insn
, new_bb
);
1976 fprintf (dump_file
, "changing bb of uid %d\n", uid
);
1978 insn_info
= DF_INSN_UID_SAFE_GET (uid
);
1979 if (insn_info
== NULL
)
1982 fprintf (dump_file
, " unscanned insn\n");
1983 df_insn_rescan (insn
);
1990 df_set_bb_dirty (new_bb
);
1994 fprintf (dump_file
, " from %d to %d\n",
1995 old_bb
->index
, new_bb
->index
);
1996 df_set_bb_dirty (old_bb
);
2000 fprintf (dump_file
, " to %d\n", new_bb
->index
);
2004 /* Helper function for df_ref_change_reg_with_loc. */
2007 df_ref_change_reg_with_loc_1 (struct df_reg_info
*old_df
,
2008 struct df_reg_info
*new_df
,
2009 int new_regno
, rtx loc
)
2011 df_ref the_ref
= old_df
->reg_chain
;
2015 if ((!DF_REF_IS_ARTIFICIAL (the_ref
))
2016 && (DF_REF_LOC (the_ref
))
2017 && (*DF_REF_LOC (the_ref
) == loc
))
2019 df_ref next_ref
= DF_REF_NEXT_REG (the_ref
);
2020 df_ref prev_ref
= DF_REF_PREV_REG (the_ref
);
2021 df_ref
*ref_vec
, *ref_vec_t
;
2022 struct df_insn_info
*insn_info
= DF_REF_INSN_INFO (the_ref
);
2023 unsigned int count
= 0;
2025 DF_REF_REGNO (the_ref
) = new_regno
;
2026 DF_REF_REG (the_ref
) = regno_reg_rtx
[new_regno
];
2028 /* Pull the_ref out of the old regno chain. */
2030 DF_REF_NEXT_REG (prev_ref
) = next_ref
;
2032 old_df
->reg_chain
= next_ref
;
2034 DF_REF_PREV_REG (next_ref
) = prev_ref
;
2037 /* Put the ref into the new regno chain. */
2038 DF_REF_PREV_REG (the_ref
) = NULL
;
2039 DF_REF_NEXT_REG (the_ref
) = new_df
->reg_chain
;
2040 if (new_df
->reg_chain
)
2041 DF_REF_PREV_REG (new_df
->reg_chain
) = the_ref
;
2042 new_df
->reg_chain
= the_ref
;
2044 if (DF_REF_BB (the_ref
))
2045 df_set_bb_dirty (DF_REF_BB (the_ref
));
2047 /* Need to sort the record again that the ref was in because
2048 the regno is a sorting key. First, find the right
2050 if (DF_REF_FLAGS (the_ref
) & DF_REF_IN_NOTE
)
2051 ref_vec
= insn_info
->eq_uses
;
2053 ref_vec
= insn_info
->uses
;
2055 fprintf (dump_file
, "changing reg in insn %d\n",
2056 DF_REF_INSN_UID (the_ref
));
2058 ref_vec_t
= ref_vec
;
2060 /* Find the length. */
2066 qsort (ref_vec
, count
, sizeof (df_ref
), df_ref_compare
);
2071 the_ref
= DF_REF_NEXT_REG (the_ref
);
2076 /* Change the regno of all refs that contained LOC from OLD_REGNO to
2077 NEW_REGNO. Refs that do not match LOC are not changed which means
2078 that artificial refs are not changed since they have no loc. This
2079 call is to support the SET_REGNO macro. */
2082 df_ref_change_reg_with_loc (int old_regno
, int new_regno
, rtx loc
)
2084 if ((!df
) || (old_regno
== -1) || (old_regno
== new_regno
))
2087 df_grow_reg_info ();
2089 df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno
),
2090 DF_REG_DEF_GET (new_regno
), new_regno
, loc
);
2091 df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno
),
2092 DF_REG_USE_GET (new_regno
), new_regno
, loc
);
2093 df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno
),
2094 DF_REG_EQ_USE_GET (new_regno
), new_regno
, loc
);
2098 /* Delete the mw_hardregs that point into the eq_notes. */
2101 df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info
*insn_info
)
2103 struct df_mw_hardreg
**mw_vec
= insn_info
->mw_hardregs
;
2104 unsigned int deleted
= 0;
2105 unsigned int count
= 0;
2106 struct df_scan_problem_data
*problem_data
2107 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2114 if ((*mw_vec
)->flags
& DF_REF_IN_NOTE
)
2116 struct df_mw_hardreg
**temp_vec
= mw_vec
;
2118 pool_free (problem_data
->mw_reg_pool
, *mw_vec
);
2120 /* Shove the remaining ones down one to fill the gap. While
2121 this looks n**2, it is highly unusual to have any mw regs
2122 in eq_notes and the chances of more than one are almost
2126 *temp_vec
= *(temp_vec
+ 1);
2140 df_scan_free_mws_vec (insn_info
->mw_hardregs
);
2141 insn_info
->mw_hardregs
= df_null_mw_rec
;
2148 /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
2151 df_notes_rescan (rtx insn
)
2153 struct df_insn_info
*insn_info
;
2154 unsigned int uid
= INSN_UID (insn
);
2159 /* The client has disabled rescanning and plans to do it itself. */
2160 if (df
->changeable_flags
& DF_NO_INSN_RESCAN
)
2163 /* Do nothing if the insn hasn't been emitted yet. */
2164 if (!BLOCK_FOR_INSN (insn
))
2167 df_grow_bb_info (df_scan
);
2168 df_grow_reg_info ();
2170 insn_info
= DF_INSN_UID_SAFE_GET (INSN_UID(insn
));
2172 /* The client has deferred rescanning. */
2173 if (df
->changeable_flags
& DF_DEFER_INSN_RESCAN
)
2177 insn_info
= df_insn_create_insn_record (insn
);
2178 insn_info
->defs
= df_null_ref_rec
;
2179 insn_info
->uses
= df_null_ref_rec
;
2180 insn_info
->eq_uses
= df_null_ref_rec
;
2181 insn_info
->mw_hardregs
= df_null_mw_rec
;
2184 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
2185 /* If the insn is set to be rescanned, it does not need to also
2186 be notes rescanned. */
2187 if (!bitmap_bit_p (&df
->insns_to_rescan
, uid
))
2188 bitmap_set_bit (&df
->insns_to_notes_rescan
, INSN_UID (insn
));
2192 bitmap_clear_bit (&df
->insns_to_delete
, uid
);
2193 bitmap_clear_bit (&df
->insns_to_notes_rescan
, uid
);
2197 basic_block bb
= BLOCK_FOR_INSN (insn
);
2199 struct df_collection_rec collection_rec
;
2200 unsigned int num_deleted
;
2201 unsigned int mw_len
;
2203 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
2204 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
2205 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
2207 num_deleted
= df_mw_hardreg_chain_delete_eq_uses (insn_info
);
2208 df_ref_chain_delete (insn_info
->eq_uses
);
2209 insn_info
->eq_uses
= NULL
;
2211 /* Process REG_EQUIV/REG_EQUAL notes */
2212 for (note
= REG_NOTES (insn
); note
;
2213 note
= XEXP (note
, 1))
2215 switch (REG_NOTE_KIND (note
))
2219 df_uses_record (DF_REF_REGULAR
, &collection_rec
,
2220 &XEXP (note
, 0), DF_REF_REG_USE
,
2221 bb
, insn_info
, DF_REF_IN_NOTE
, -1, -1, VOIDmode
);
2227 /* Find some place to put any new mw_hardregs. */
2228 df_canonize_collection_rec (&collection_rec
);
2229 mw_len
= VEC_length (df_mw_hardreg_ptr
, collection_rec
.mw_vec
);
2232 unsigned int count
= 0;
2233 struct df_mw_hardreg
**mw_rec
= insn_info
->mw_hardregs
;
2242 /* Append to the end of the existing record after
2243 expanding it if necessary. */
2244 if (mw_len
> num_deleted
)
2246 insn_info
->mw_hardregs
=
2247 XRESIZEVEC (struct df_mw_hardreg
*,
2248 insn_info
->mw_hardregs
,
2249 count
+ 1 + mw_len
);
2251 memcpy (&insn_info
->mw_hardregs
[count
],
2252 VEC_address (df_mw_hardreg_ptr
, collection_rec
.mw_vec
),
2253 mw_len
* sizeof (struct df_mw_hardreg
*));
2254 insn_info
->mw_hardregs
[count
+ mw_len
] = NULL
;
2255 qsort (insn_info
->mw_hardregs
, count
+ mw_len
,
2256 sizeof (struct df_mw_hardreg
*), df_mw_compare
);
2260 /* No vector there. */
2261 insn_info
->mw_hardregs
2262 = XNEWVEC (struct df_mw_hardreg
*, 1 + mw_len
);
2263 memcpy (insn_info
->mw_hardregs
,
2264 VEC_address (df_mw_hardreg_ptr
, collection_rec
.mw_vec
),
2265 mw_len
* sizeof (struct df_mw_hardreg
*));
2266 insn_info
->mw_hardregs
[mw_len
] = NULL
;
2269 /* Get rid of the mw_rec so that df_refs_add_to_chains will
2271 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
.mw_vec
);
2272 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
2273 VEC_free (df_ref
, stack
, collection_rec
.eq_use_vec
);
2276 df_insn_rescan (insn
);
2281 /*----------------------------------------------------------------------------
2282 Hard core instruction scanning code. No external interfaces here,
2283 just a lot of routines that look inside insns.
2284 ----------------------------------------------------------------------------*/
2287 /* Return true if the contents of two df_ref's are identical.
2288 It ignores DF_REF_MARKER. */
2291 df_ref_equal_p (df_ref ref1
, df_ref ref2
)
2299 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
)
2300 || DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
)
2301 || DF_REF_REG (ref1
) != DF_REF_REG (ref2
)
2302 || DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
)
2303 || ((DF_REF_FLAGS (ref1
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
))
2304 != (DF_REF_FLAGS (ref2
) & ~(DF_REF_REG_MARKER
+ DF_REF_MW_HARDREG
)))
2305 || DF_REF_BB (ref1
) != DF_REF_BB (ref2
)
2306 || DF_REF_INSN_INFO (ref1
) != DF_REF_INSN_INFO (ref2
))
2309 switch (DF_REF_CLASS (ref1
))
2311 case DF_REF_ARTIFICIAL
:
2315 case DF_REF_EXTRACT
:
2316 if ((DF_REF_EXTRACT_OFFSET (ref1
) != DF_REF_EXTRACT_OFFSET (ref2
))
2317 || (DF_REF_EXTRACT_WIDTH (ref1
) != DF_REF_EXTRACT_WIDTH (ref2
))
2318 || (DF_REF_EXTRACT_MODE (ref1
) != DF_REF_EXTRACT_MODE (ref2
)))
2322 case DF_REF_REGULAR
:
2323 return DF_REF_LOC (ref1
) == DF_REF_LOC (ref2
);
2332 /* Compare REF1 and REF2 for sorting. This is only called from places
2333 where all of the refs are of the same type, in the same insn, and
2334 have the same bb. So these fields are not checked. */
2337 df_ref_compare (const void *r1
, const void *r2
)
2339 const df_ref ref1
= *(const df_ref
*)r1
;
2340 const df_ref ref2
= *(const df_ref
*)r2
;
2345 if (DF_REF_CLASS (ref1
) != DF_REF_CLASS (ref2
))
2346 return (int)DF_REF_CLASS (ref1
) - (int)DF_REF_CLASS (ref2
);
2348 if (DF_REF_REGNO (ref1
) != DF_REF_REGNO (ref2
))
2349 return (int)DF_REF_REGNO (ref1
) - (int)DF_REF_REGNO (ref2
);
2351 if (DF_REF_TYPE (ref1
) != DF_REF_TYPE (ref2
))
2352 return (int)DF_REF_TYPE (ref1
) - (int)DF_REF_TYPE (ref2
);
2354 if (DF_REF_REG (ref1
) != DF_REF_REG (ref2
))
2355 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2357 /* Cannot look at the LOC field on artificial refs. */
2358 if (DF_REF_CLASS (ref1
) != DF_REF_ARTIFICIAL
2359 && DF_REF_LOC (ref1
) != DF_REF_LOC (ref2
))
2360 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2362 if (DF_REF_FLAGS (ref1
) != DF_REF_FLAGS (ref2
))
2364 /* If two refs are identical except that one of them has is from
2365 a mw and one is not, we need to have the one with the mw
2367 if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
) ==
2368 DF_REF_FLAGS_IS_SET (ref2
, DF_REF_MW_HARDREG
))
2369 return DF_REF_FLAGS (ref1
) - DF_REF_FLAGS (ref2
);
2370 else if (DF_REF_FLAGS_IS_SET (ref1
, DF_REF_MW_HARDREG
))
2376 /* The classes are the same at this point so it is safe to only look
2378 if (DF_REF_CLASS (ref1
) == DF_REF_EXTRACT
)
2380 if (DF_REF_EXTRACT_OFFSET (ref1
) != DF_REF_EXTRACT_OFFSET (ref2
))
2381 return DF_REF_EXTRACT_OFFSET (ref1
) - DF_REF_EXTRACT_OFFSET (ref2
);
2382 if (DF_REF_EXTRACT_WIDTH (ref1
) != DF_REF_EXTRACT_WIDTH (ref2
))
2383 return DF_REF_EXTRACT_WIDTH (ref1
) - DF_REF_EXTRACT_WIDTH (ref2
);
2384 if (DF_REF_EXTRACT_MODE (ref1
) != DF_REF_EXTRACT_MODE (ref2
))
2385 return DF_REF_EXTRACT_MODE (ref1
) - DF_REF_EXTRACT_MODE (ref2
);
2387 return (int)DF_REF_ORDER (ref1
) - (int)DF_REF_ORDER (ref2
);
2391 df_swap_refs (VEC(df_ref
,stack
) **ref_vec
, int i
, int j
)
2393 df_ref tmp
= VEC_index (df_ref
, *ref_vec
, i
);
2394 VEC_replace (df_ref
, *ref_vec
, i
, VEC_index (df_ref
, *ref_vec
, j
));
2395 VEC_replace (df_ref
, *ref_vec
, j
, tmp
);
2398 /* Sort and compress a set of refs. */
2401 df_sort_and_compress_refs (VEC(df_ref
,stack
) **ref_vec
)
2405 unsigned int dist
= 0;
2407 count
= VEC_length (df_ref
, *ref_vec
);
2409 /* If there are 1 or 0 elements, there is nothing to do. */
2412 else if (count
== 2)
2414 df_ref r0
= VEC_index (df_ref
, *ref_vec
, 0);
2415 df_ref r1
= VEC_index (df_ref
, *ref_vec
, 1);
2416 if (df_ref_compare (&r0
, &r1
) > 0)
2417 df_swap_refs (ref_vec
, 0, 1);
2421 for (i
= 0; i
< count
- 1; i
++)
2423 df_ref r0
= VEC_index (df_ref
, *ref_vec
, i
);
2424 df_ref r1
= VEC_index (df_ref
, *ref_vec
, i
+ 1);
2425 if (df_ref_compare (&r0
, &r1
) >= 0)
2428 /* If the array is already strictly ordered,
2429 which is the most common case for large COUNT case
2430 (which happens for CALL INSNs),
2431 no need to sort and filter out duplicate.
2432 Simply return the count.
2433 Make sure DF_GET_ADD_REFS adds refs in the increasing order
2434 of DF_REF_COMPARE. */
2437 qsort (VEC_address (df_ref
, *ref_vec
), count
, sizeof (df_ref
),
2441 for (i
=0; i
<count
-dist
; i
++)
2443 /* Find the next ref that is not equal to the current ref. */
2444 while (i
+ dist
+ 1 < count
2445 && df_ref_equal_p (VEC_index (df_ref
, *ref_vec
, i
),
2446 VEC_index (df_ref
, *ref_vec
, i
+ dist
+ 1)))
2448 df_free_ref (VEC_index (df_ref
, *ref_vec
, i
+ dist
+ 1));
2451 /* Copy it down to the next position. */
2452 if (dist
&& i
+ dist
+ 1 < count
)
2453 VEC_replace (df_ref
, *ref_vec
, i
+ 1,
2454 VEC_index (df_ref
, *ref_vec
, i
+ dist
+ 1));
2458 VEC_truncate (df_ref
, *ref_vec
, count
);
2462 /* Return true if the contents of two df_ref's are identical.
2463 It ignores DF_REF_MARKER. */
2466 df_mw_equal_p (struct df_mw_hardreg
*mw1
, struct df_mw_hardreg
*mw2
)
2470 return (mw1
== mw2
) ||
2471 (mw1
->mw_reg
== mw2
->mw_reg
2472 && mw1
->type
== mw2
->type
2473 && mw1
->flags
== mw2
->flags
2474 && mw1
->start_regno
== mw2
->start_regno
2475 && mw1
->end_regno
== mw2
->end_regno
);
2479 /* Compare MW1 and MW2 for sorting. */
2482 df_mw_compare (const void *m1
, const void *m2
)
2484 const struct df_mw_hardreg
*const mw1
= *(const struct df_mw_hardreg
*const*)m1
;
2485 const struct df_mw_hardreg
*const mw2
= *(const struct df_mw_hardreg
*const*)m2
;
2490 if (mw1
->type
!= mw2
->type
)
2491 return mw1
->type
- mw2
->type
;
2493 if (mw1
->flags
!= mw2
->flags
)
2494 return mw1
->flags
- mw2
->flags
;
2496 if (mw1
->start_regno
!= mw2
->start_regno
)
2497 return mw1
->start_regno
- mw2
->start_regno
;
2499 if (mw1
->end_regno
!= mw2
->end_regno
)
2500 return mw1
->end_regno
- mw2
->end_regno
;
2502 if (mw1
->mw_reg
!= mw2
->mw_reg
)
2503 return mw1
->mw_order
- mw2
->mw_order
;
2509 /* Sort and compress a set of refs. */
2512 df_sort_and_compress_mws (VEC(df_mw_hardreg_ptr
,stack
) **mw_vec
)
2515 struct df_scan_problem_data
*problem_data
2516 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2518 unsigned int dist
= 0;
2520 count
= VEC_length (df_mw_hardreg_ptr
, *mw_vec
);
2523 else if (count
== 2)
2525 struct df_mw_hardreg
*m0
= VEC_index (df_mw_hardreg_ptr
, *mw_vec
, 0);
2526 struct df_mw_hardreg
*m1
= VEC_index (df_mw_hardreg_ptr
, *mw_vec
, 1);
2527 if (df_mw_compare (&m0
, &m1
) > 0)
2529 struct df_mw_hardreg
*tmp
= VEC_index (df_mw_hardreg_ptr
,
2531 VEC_replace (df_mw_hardreg_ptr
, *mw_vec
, 0,
2532 VEC_index (df_mw_hardreg_ptr
, *mw_vec
, 1));
2533 VEC_replace (df_mw_hardreg_ptr
, *mw_vec
, 1, tmp
);
2537 qsort (VEC_address (df_mw_hardreg_ptr
, *mw_vec
), count
,
2538 sizeof (struct df_mw_hardreg
*), df_mw_compare
);
2540 for (i
=0; i
<count
-dist
; i
++)
2542 /* Find the next ref that is not equal to the current ref. */
2543 while (i
+ dist
+ 1 < count
2544 && df_mw_equal_p (VEC_index (df_mw_hardreg_ptr
, *mw_vec
, i
),
2545 VEC_index (df_mw_hardreg_ptr
, *mw_vec
,
2548 pool_free (problem_data
->mw_reg_pool
,
2549 VEC_index (df_mw_hardreg_ptr
, *mw_vec
, i
+ dist
+ 1));
2552 /* Copy it down to the next position. */
2553 if (dist
&& i
+ dist
+ 1 < count
)
2554 VEC_replace (df_mw_hardreg_ptr
, *mw_vec
, i
+ 1,
2555 VEC_index (df_mw_hardreg_ptr
, *mw_vec
, i
+ dist
+ 1));
2559 VEC_truncate (df_mw_hardreg_ptr
, *mw_vec
, count
);
2563 /* Sort and remove duplicates from the COLLECTION_REC. */
2566 df_canonize_collection_rec (struct df_collection_rec
*collection_rec
)
2568 df_sort_and_compress_refs (&collection_rec
->def_vec
);
2569 df_sort_and_compress_refs (&collection_rec
->use_vec
);
2570 df_sort_and_compress_refs (&collection_rec
->eq_use_vec
);
2571 df_sort_and_compress_mws (&collection_rec
->mw_vec
);
2575 /* Add the new df_ref to appropriate reg_info/ref_info chains. */
2578 df_install_ref (df_ref this_ref
,
2579 struct df_reg_info
*reg_info
,
2580 struct df_ref_info
*ref_info
,
2583 unsigned int regno
= DF_REF_REGNO (this_ref
);
2584 /* Add the ref to the reg_{def,use,eq_use} chain. */
2585 df_ref head
= reg_info
->reg_chain
;
2587 reg_info
->reg_chain
= this_ref
;
2590 if (DF_REF_FLAGS_IS_SET (this_ref
, DF_HARD_REG_LIVE
))
2592 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2593 df
->hard_regs_live_count
[regno
]++;
2596 gcc_checking_assert (DF_REF_NEXT_REG (this_ref
) == NULL
2597 && DF_REF_PREV_REG (this_ref
) == NULL
);
2599 DF_REF_NEXT_REG (this_ref
) = head
;
2601 /* We cannot actually link to the head of the chain. */
2602 DF_REF_PREV_REG (this_ref
) = NULL
;
2605 DF_REF_PREV_REG (head
) = this_ref
;
2609 gcc_assert (ref_info
->ref_order
!= DF_REF_ORDER_NO_TABLE
);
2610 df_check_and_grow_ref_info (ref_info
, 1);
2611 DF_REF_ID (this_ref
) = ref_info
->table_size
;
2612 /* Add the ref to the big array of defs. */
2613 ref_info
->refs
[ref_info
->table_size
] = this_ref
;
2614 ref_info
->table_size
++;
2617 DF_REF_ID (this_ref
) = -1;
2619 ref_info
->total_size
++;
2623 /* This function takes one of the groups of refs (defs, uses or
2624 eq_uses) and installs the entire group into the insn. It also adds
2625 each of these refs into the appropriate chains. */
2628 df_install_refs (basic_block bb
,
2629 VEC(df_ref
,stack
)* old_vec
,
2630 struct df_reg_info
**reg_info
,
2631 struct df_ref_info
*ref_info
,
2636 count
= VEC_length (df_ref
, old_vec
);
2639 df_ref
*new_vec
= XNEWVEC (df_ref
, count
+ 1);
2644 switch (ref_info
->ref_order
)
2646 case DF_REF_ORDER_UNORDERED_WITH_NOTES
:
2647 case DF_REF_ORDER_BY_REG_WITH_NOTES
:
2648 case DF_REF_ORDER_BY_INSN_WITH_NOTES
:
2649 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED_WITH_NOTES
;
2650 add_to_table
= true;
2652 case DF_REF_ORDER_UNORDERED
:
2653 case DF_REF_ORDER_BY_REG
:
2654 case DF_REF_ORDER_BY_INSN
:
2655 ref_info
->ref_order
= DF_REF_ORDER_UNORDERED
;
2656 add_to_table
= !is_notes
;
2659 add_to_table
= false;
2663 /* Do not add if ref is not in the right blocks. */
2664 if (add_to_table
&& df
->analyze_subset
)
2665 add_to_table
= bitmap_bit_p (df
->blocks_to_analyze
, bb
->index
);
2667 for (ix
= 0; VEC_iterate (df_ref
, old_vec
, ix
, this_ref
); ++ix
)
2669 new_vec
[ix
] = this_ref
;
2670 df_install_ref (this_ref
, reg_info
[DF_REF_REGNO (this_ref
)],
2671 ref_info
, add_to_table
);
2674 new_vec
[count
] = NULL
;
2678 return df_null_ref_rec
;
2682 /* This function takes the mws installs the entire group into the
2685 static struct df_mw_hardreg
**
2686 df_install_mws (VEC(df_mw_hardreg_ptr
,stack
) *old_vec
)
2690 count
= VEC_length (df_mw_hardreg_ptr
, old_vec
);
2693 struct df_mw_hardreg
**new_vec
2694 = XNEWVEC (struct df_mw_hardreg
*, count
+ 1);
2695 memcpy (new_vec
, VEC_address (df_mw_hardreg_ptr
, old_vec
),
2696 sizeof (struct df_mw_hardreg
*) * count
);
2697 new_vec
[count
] = NULL
;
2701 return df_null_mw_rec
;
2705 /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
2706 chains and update other necessary information. */
2709 df_refs_add_to_chains (struct df_collection_rec
*collection_rec
,
2710 basic_block bb
, rtx insn
)
2714 struct df_insn_info
*insn_rec
= DF_INSN_INFO_GET (insn
);
2715 /* If there is a vector in the collection rec, add it to the
2716 insn. A null rec is a signal that the caller will handle the
2718 if (collection_rec
->def_vec
)
2720 df_scan_free_ref_vec (insn_rec
->defs
);
2722 = df_install_refs (bb
, collection_rec
->def_vec
,
2724 &df
->def_info
, false);
2726 if (collection_rec
->use_vec
)
2728 df_scan_free_ref_vec (insn_rec
->uses
);
2730 = df_install_refs (bb
, collection_rec
->use_vec
,
2732 &df
->use_info
, false);
2734 if (collection_rec
->eq_use_vec
)
2736 df_scan_free_ref_vec (insn_rec
->eq_uses
);
2738 = df_install_refs (bb
, collection_rec
->eq_use_vec
,
2740 &df
->use_info
, true);
2742 if (collection_rec
->mw_vec
)
2744 df_scan_free_mws_vec (insn_rec
->mw_hardregs
);
2745 insn_rec
->mw_hardregs
2746 = df_install_mws (collection_rec
->mw_vec
);
2751 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
2753 df_scan_free_ref_vec (bb_info
->artificial_defs
);
2754 bb_info
->artificial_defs
2755 = df_install_refs (bb
, collection_rec
->def_vec
,
2757 &df
->def_info
, false);
2758 df_scan_free_ref_vec (bb_info
->artificial_uses
);
2759 bb_info
->artificial_uses
2760 = df_install_refs (bb
, collection_rec
->use_vec
,
2762 &df
->use_info
, false);
2767 /* Allocate a ref and initialize its fields.
2769 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2770 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the fields
2771 if they were constants. Otherwise they should be -1 if those flags
2775 df_ref_create_structure (enum df_ref_class cl
,
2776 struct df_collection_rec
*collection_rec
,
2778 basic_block bb
, struct df_insn_info
*info
,
2779 enum df_ref_type ref_type
,
2781 int width
, int offset
, enum machine_mode mode
)
2783 df_ref this_ref
= NULL
;
2784 int regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2785 struct df_scan_problem_data
*problem_data
2786 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2791 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_base_pool
);
2792 gcc_checking_assert (loc
== NULL
);
2795 case DF_REF_ARTIFICIAL
:
2796 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_artificial_pool
);
2797 this_ref
->artificial_ref
.bb
= bb
;
2798 gcc_checking_assert (loc
== NULL
);
2801 case DF_REF_REGULAR
:
2802 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_regular_pool
);
2803 this_ref
->regular_ref
.loc
= loc
;
2804 gcc_checking_assert (loc
);
2807 case DF_REF_EXTRACT
:
2808 this_ref
= (df_ref
) pool_alloc (problem_data
->ref_extract_pool
);
2809 DF_REF_EXTRACT_WIDTH (this_ref
) = width
;
2810 DF_REF_EXTRACT_OFFSET (this_ref
) = offset
;
2811 DF_REF_EXTRACT_MODE (this_ref
) = mode
;
2812 this_ref
->regular_ref
.loc
= loc
;
2813 gcc_checking_assert (loc
);
2817 DF_REF_CLASS (this_ref
) = cl
;
2818 DF_REF_ID (this_ref
) = -1;
2819 DF_REF_REG (this_ref
) = reg
;
2820 DF_REF_REGNO (this_ref
) = regno
;
2821 DF_REF_TYPE (this_ref
) = ref_type
;
2822 DF_REF_INSN_INFO (this_ref
) = info
;
2823 DF_REF_CHAIN (this_ref
) = NULL
;
2824 DF_REF_FLAGS (this_ref
) = ref_flags
;
2825 DF_REF_NEXT_REG (this_ref
) = NULL
;
2826 DF_REF_PREV_REG (this_ref
) = NULL
;
2827 DF_REF_ORDER (this_ref
) = df
->ref_order
++;
2829 /* We need to clear this bit because fwprop, and in the future
2830 possibly other optimizations sometimes create new refs using ond
2831 refs as the model. */
2832 DF_REF_FLAGS_CLEAR (this_ref
, DF_HARD_REG_LIVE
);
2834 /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
2835 if ((regno
< FIRST_PSEUDO_REGISTER
)
2836 && (!DF_REF_IS_ARTIFICIAL (this_ref
)))
2838 if (DF_REF_REG_DEF_P (this_ref
))
2840 if (!DF_REF_FLAGS_IS_SET (this_ref
, DF_REF_MAY_CLOBBER
))
2841 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2843 else if (!(TEST_HARD_REG_BIT (elim_reg_set
, regno
)
2844 && (regno
== FRAME_POINTER_REGNUM
2845 || regno
== ARG_POINTER_REGNUM
)))
2846 DF_REF_FLAGS_SET (this_ref
, DF_HARD_REG_LIVE
);
2851 if (DF_REF_REG_DEF_P (this_ref
))
2852 VEC_safe_push (df_ref
, stack
, collection_rec
->def_vec
, this_ref
);
2853 else if (DF_REF_FLAGS (this_ref
) & DF_REF_IN_NOTE
)
2854 VEC_safe_push (df_ref
, stack
, collection_rec
->eq_use_vec
, this_ref
);
2856 VEC_safe_push (df_ref
, stack
, collection_rec
->use_vec
, this_ref
);
2863 /* Create new references of type DF_REF_TYPE for each part of register REG
2864 at address LOC within INSN of BB.
2866 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
2867 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
2868 fields if they were constants. Otherwise they should be -1 if
2869 those flags were set. */
2873 df_ref_record (enum df_ref_class cl
,
2874 struct df_collection_rec
*collection_rec
,
2876 basic_block bb
, struct df_insn_info
*insn_info
,
2877 enum df_ref_type ref_type
,
2879 int width
, int offset
, enum machine_mode mode
)
2883 gcc_checking_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
2885 regno
= REGNO (GET_CODE (reg
) == SUBREG
? SUBREG_REG (reg
) : reg
);
2886 if (regno
< FIRST_PSEUDO_REGISTER
)
2888 struct df_mw_hardreg
*hardreg
= NULL
;
2889 struct df_scan_problem_data
*problem_data
2890 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
2892 unsigned int endregno
;
2895 if (GET_CODE (reg
) == SUBREG
)
2897 regno
+= subreg_regno_offset (regno
, GET_MODE (SUBREG_REG (reg
)),
2898 SUBREG_BYTE (reg
), GET_MODE (reg
));
2899 endregno
= regno
+ subreg_nregs (reg
);
2902 endregno
= END_HARD_REGNO (reg
);
2904 /* If this is a multiword hardreg, we create some extra
2905 datastructures that will enable us to easily build REG_DEAD
2906 and REG_UNUSED notes. */
2907 if ((endregno
!= regno
+ 1) && insn_info
)
2909 /* Sets to a subreg of a multiword register are partial.
2910 Sets to a non-subreg of a multiword register are not. */
2911 if (GET_CODE (reg
) == SUBREG
)
2912 ref_flags
|= DF_REF_PARTIAL
;
2913 ref_flags
|= DF_REF_MW_HARDREG
;
2915 hardreg
= (struct df_mw_hardreg
*) pool_alloc (problem_data
->mw_reg_pool
);
2916 hardreg
->type
= ref_type
;
2917 hardreg
->flags
= ref_flags
;
2918 hardreg
->mw_reg
= reg
;
2919 hardreg
->start_regno
= regno
;
2920 hardreg
->end_regno
= endregno
- 1;
2921 hardreg
->mw_order
= df
->ref_order
++;
2922 VEC_safe_push (df_mw_hardreg_ptr
, stack
, collection_rec
->mw_vec
,
2926 for (i
= regno
; i
< endregno
; i
++)
2928 ref
= df_ref_create_structure (cl
, collection_rec
, regno_reg_rtx
[i
], loc
,
2929 bb
, insn_info
, ref_type
, ref_flags
,
2930 width
, offset
, mode
);
2932 gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref
)) == i
);
2937 df_ref_create_structure (cl
, collection_rec
, reg
, loc
, bb
, insn_info
,
2938 ref_type
, ref_flags
, width
, offset
, mode
);
2943 /* A set to a non-paradoxical SUBREG for which the number of word_mode units
2944 covered by the outer mode is smaller than that covered by the inner mode,
2945 is a read-modify-write operation.
2946 This function returns true iff the SUBREG X is such a SUBREG. */
2949 df_read_modify_subreg_p (rtx x
)
2951 unsigned int isize
, osize
;
2952 if (GET_CODE (x
) != SUBREG
)
2954 isize
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)));
2955 osize
= GET_MODE_SIZE (GET_MODE (x
));
2956 return isize
> osize
2957 && isize
> REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x
)));
2961 /* Process all the registers defined in the rtx, X.
2962 Autoincrement/decrement definitions will be picked up by
2966 df_def_record_1 (struct df_collection_rec
*collection_rec
,
2967 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
2974 enum machine_mode mode
= VOIDmode
;
2975 enum df_ref_class cl
= DF_REF_REGULAR
;
2977 /* We may recursively call ourselves on EXPR_LIST when dealing with PARALLEL
2979 if (GET_CODE (x
) == EXPR_LIST
|| GET_CODE (x
) == CLOBBER
)
2982 loc
= &SET_DEST (x
);
2985 /* It is legal to have a set destination be a parallel. */
2986 if (GET_CODE (dst
) == PARALLEL
)
2990 for (i
= XVECLEN (dst
, 0) - 1; i
>= 0; i
--)
2992 rtx temp
= XVECEXP (dst
, 0, i
);
2993 if (GET_CODE (temp
) == EXPR_LIST
|| GET_CODE (temp
) == CLOBBER
2994 || GET_CODE (temp
) == SET
)
2995 df_def_record_1 (collection_rec
,
2996 temp
, bb
, insn_info
,
2997 GET_CODE (temp
) == CLOBBER
2998 ? flags
| DF_REF_MUST_CLOBBER
: flags
);
3003 if (GET_CODE (dst
) == STRICT_LOW_PART
)
3005 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_STRICT_LOW_PART
;
3007 loc
= &XEXP (dst
, 0);
3011 if (GET_CODE (dst
) == ZERO_EXTRACT
)
3013 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
| DF_REF_ZERO_EXTRACT
;
3015 if (CONST_INT_P (XEXP (dst
, 1))
3016 && CONST_INT_P (XEXP (dst
, 2)))
3018 width
= INTVAL (XEXP (dst
, 1));
3019 offset
= INTVAL (XEXP (dst
, 2));
3020 mode
= GET_MODE (dst
);
3021 cl
= DF_REF_EXTRACT
;
3024 loc
= &XEXP (dst
, 0);
3028 /* At this point if we do not have a reg or a subreg, just return. */
3031 df_ref_record (cl
, collection_rec
,
3032 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
,
3033 width
, offset
, mode
);
3035 /* We want to keep sp alive everywhere - by making all
3036 writes to sp also use of sp. */
3037 if (REGNO (dst
) == STACK_POINTER_REGNUM
)
3038 df_ref_record (DF_REF_BASE
, collection_rec
,
3039 dst
, NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
,
3040 width
, offset
, mode
);
3042 else if (GET_CODE (dst
) == SUBREG
&& REG_P (SUBREG_REG (dst
)))
3044 if (df_read_modify_subreg_p (dst
))
3045 flags
|= DF_REF_READ_WRITE
| DF_REF_PARTIAL
;
3047 flags
|= DF_REF_SUBREG
;
3049 df_ref_record (cl
, collection_rec
,
3050 dst
, loc
, bb
, insn_info
, DF_REF_REG_DEF
, flags
,
3051 width
, offset
, mode
);
3056 /* Process all the registers defined in the pattern rtx, X. */
3059 df_defs_record (struct df_collection_rec
*collection_rec
,
3060 rtx x
, basic_block bb
, struct df_insn_info
*insn_info
,
3063 RTX_CODE code
= GET_CODE (x
);
3065 if (code
== SET
|| code
== CLOBBER
)
3067 /* Mark the single def within the pattern. */
3068 int clobber_flags
= flags
;
3069 clobber_flags
|= (code
== CLOBBER
) ? DF_REF_MUST_CLOBBER
: 0;
3070 df_def_record_1 (collection_rec
, x
, bb
, insn_info
, clobber_flags
);
3072 else if (code
== COND_EXEC
)
3074 df_defs_record (collection_rec
, COND_EXEC_CODE (x
),
3075 bb
, insn_info
, DF_REF_CONDITIONAL
);
3077 else if (code
== PARALLEL
)
3081 /* Mark the multiple defs within the pattern. */
3082 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
3083 df_defs_record (collection_rec
, XVECEXP (x
, 0, i
), bb
, insn_info
, flags
);
3088 /* Process all the registers used in the rtx at address LOC.
3090 If the REF_FLAGS field contain DF_REF_SIGN_EXTRACT or
3091 DF_REF_ZERO_EXTRACT. WIDTH, OFFSET and MODE are used to access the
3092 fields if they were constants. Otherwise they should be -1 if
3093 those flags were set. */
3096 df_uses_record (enum df_ref_class cl
, struct df_collection_rec
*collection_rec
,
3097 rtx
*loc
, enum df_ref_type ref_type
,
3098 basic_block bb
, struct df_insn_info
*insn_info
,
3100 int width
, int offset
, enum machine_mode mode
)
3109 code
= GET_CODE (x
);
3126 /* If we are clobbering a MEM, mark any registers inside the address
3128 if (MEM_P (XEXP (x
, 0)))
3129 df_uses_record (cl
, collection_rec
,
3130 &XEXP (XEXP (x
, 0), 0),
3131 DF_REF_REG_MEM_STORE
,
3133 flags
, width
, offset
, mode
);
3135 /* If we're clobbering a REG then we have a def so ignore. */
3139 df_uses_record (cl
, collection_rec
,
3140 &XEXP (x
, 0), DF_REF_REG_MEM_LOAD
,
3141 bb
, insn_info
, flags
& DF_REF_IN_NOTE
,
3142 width
, offset
, mode
);
3146 /* While we're here, optimize this case. */
3147 flags
|= DF_REF_PARTIAL
;
3148 /* In case the SUBREG is not of a REG, do not optimize. */
3149 if (!REG_P (SUBREG_REG (x
)))
3151 loc
= &SUBREG_REG (x
);
3152 df_uses_record (cl
, collection_rec
, loc
, ref_type
, bb
, insn_info
, flags
,
3153 width
, offset
, mode
);
3156 /* ... Fall through ... */
3159 df_ref_record (cl
, collection_rec
,
3160 x
, loc
, bb
, insn_info
,
3162 width
, offset
, mode
);
3168 /* If the parameters to the zero or sign extract are
3169 constants, strip them off and recurse, otherwise there is
3170 no information that we can gain from this operation. */
3171 if (CONST_INT_P (XEXP (x
, 1))
3172 && CONST_INT_P (XEXP (x
, 2)))
3174 width
= INTVAL (XEXP (x
, 1));
3175 offset
= INTVAL (XEXP (x
, 2));
3176 mode
= GET_MODE (x
);
3178 if (code
== ZERO_EXTRACT
)
3179 flags
|= DF_REF_ZERO_EXTRACT
;
3181 flags
|= DF_REF_SIGN_EXTRACT
;
3183 df_uses_record (DF_REF_EXTRACT
, collection_rec
,
3184 &XEXP (x
, 0), ref_type
, bb
, insn_info
, flags
,
3185 width
, offset
, mode
);
3193 rtx dst
= SET_DEST (x
);
3194 gcc_assert (!(flags
& DF_REF_IN_NOTE
));
3195 df_uses_record (cl
, collection_rec
,
3196 &SET_SRC (x
), DF_REF_REG_USE
, bb
, insn_info
, flags
,
3197 width
, offset
, mode
);
3199 switch (GET_CODE (dst
))
3202 if (df_read_modify_subreg_p (dst
))
3204 df_uses_record (cl
, collection_rec
, &SUBREG_REG (dst
),
3205 DF_REF_REG_USE
, bb
, insn_info
,
3206 flags
| DF_REF_READ_WRITE
| DF_REF_SUBREG
,
3207 width
, offset
, mode
);
3218 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 0),
3219 DF_REF_REG_MEM_STORE
, bb
, insn_info
, flags
,
3220 width
, offset
, mode
);
3222 case STRICT_LOW_PART
:
3224 rtx
*temp
= &XEXP (dst
, 0);
3225 /* A strict_low_part uses the whole REG and not just the
3227 dst
= XEXP (dst
, 0);
3228 df_uses_record (cl
, collection_rec
,
3229 (GET_CODE (dst
) == SUBREG
) ? &SUBREG_REG (dst
) : temp
,
3230 DF_REF_REG_USE
, bb
, insn_info
,
3231 DF_REF_READ_WRITE
| DF_REF_STRICT_LOW_PART
,
3232 width
, offset
, mode
);
3237 if (CONST_INT_P (XEXP (dst
, 1))
3238 && CONST_INT_P (XEXP (dst
, 2)))
3240 width
= INTVAL (XEXP (dst
, 1));
3241 offset
= INTVAL (XEXP (dst
, 2));
3242 mode
= GET_MODE (dst
);
3243 if (GET_CODE (XEXP (dst
,0)) == MEM
)
3245 /* Handle the case of zero_extract(mem(...)) in the set dest.
3246 This special case is allowed only if the mem is a single byte and
3247 is useful to set a bitfield in memory. */
3248 df_uses_record (DF_REF_EXTRACT
, collection_rec
, &XEXP (XEXP (dst
,0), 0),
3249 DF_REF_REG_MEM_STORE
, bb
, insn_info
,
3250 DF_REF_ZERO_EXTRACT
,
3251 width
, offset
, mode
);
3255 df_uses_record (DF_REF_EXTRACT
, collection_rec
, &XEXP (dst
, 0),
3256 DF_REF_REG_USE
, bb
, insn_info
,
3257 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
,
3258 width
, offset
, mode
);
3263 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 1),
3264 DF_REF_REG_USE
, bb
, insn_info
, flags
,
3265 width
, offset
, mode
);
3266 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 2),
3267 DF_REF_REG_USE
, bb
, insn_info
, flags
,
3268 width
, offset
, mode
);
3269 df_uses_record (cl
, collection_rec
, &XEXP (dst
, 0),
3270 DF_REF_REG_USE
, bb
, insn_info
,
3271 DF_REF_READ_WRITE
| DF_REF_ZERO_EXTRACT
,
3272 width
, offset
, mode
);
3288 case UNSPEC_VOLATILE
:
3292 /* Traditional and volatile asm instructions must be
3293 considered to use and clobber all hard registers, all
3294 pseudo-registers and all of memory. So must TRAP_IF and
3295 UNSPEC_VOLATILE operations.
3297 Consider for instance a volatile asm that changes the fpu
3298 rounding mode. An insn should not be moved across this
3299 even if it only uses pseudo-regs because it might give an
3300 incorrectly rounded result.
3302 However, flow.c's liveness computation did *not* do this,
3303 giving the reasoning as " ?!? Unfortunately, marking all
3304 hard registers as live causes massive problems for the
3305 register allocator and marking all pseudos as live creates
3306 mountains of uninitialized variable warnings."
3308 In order to maintain the status quo with regard to liveness
3309 and uses, we do what flow.c did and just mark any regs we
3310 can find in ASM_OPERANDS as used. In global asm insns are
3311 scanned and regs_asm_clobbered is filled out.
3313 For all ASM_OPERANDS, we must traverse the vector of input
3314 operands. We can not just fall through here since then we
3315 would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
3316 which do not indicate traditional asms unlike their normal
3318 if (code
== ASM_OPERANDS
)
3322 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
3323 df_uses_record (cl
, collection_rec
, &ASM_OPERANDS_INPUT (x
, j
),
3324 DF_REF_REG_USE
, bb
, insn_info
, flags
,
3325 width
, offset
, mode
);
3332 df_uses_record (cl
, collection_rec
,
3333 &PAT_VAR_LOCATION_LOC (x
),
3334 DF_REF_REG_USE
, bb
, insn_info
,
3335 flags
, width
, offset
, mode
);
3344 gcc_assert (!DEBUG_INSN_P (insn_info
->insn
));
3345 /* Catch the def of the register being modified. */
3346 df_ref_record (cl
, collection_rec
, XEXP (x
, 0), &XEXP (x
, 0),
3349 flags
| DF_REF_READ_WRITE
| DF_REF_PRE_POST_MODIFY
,
3350 width
, offset
, mode
);
3352 /* ... Fall through to handle uses ... */
3358 /* Recursively scan the operands of this expression. */
3360 const char *fmt
= GET_RTX_FORMAT (code
);
3363 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3367 /* Tail recursive case: save a function call level. */
3373 df_uses_record (cl
, collection_rec
, &XEXP (x
, i
), ref_type
,
3374 bb
, insn_info
, flags
,
3375 width
, offset
, mode
);
3377 else if (fmt
[i
] == 'E')
3380 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3381 df_uses_record (cl
, collection_rec
,
3382 &XVECEXP (x
, i
, j
), ref_type
,
3383 bb
, insn_info
, flags
,
3384 width
, offset
, mode
);
3393 /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
3396 df_get_conditional_uses (struct df_collection_rec
*collection_rec
)
3401 for (ix
= 0; VEC_iterate (df_ref
, collection_rec
->def_vec
, ix
, ref
); ++ix
)
3403 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_CONDITIONAL
))
3407 enum machine_mode mode
= VOIDmode
;
3410 if (DF_REF_FLAGS_IS_SET (ref
, DF_REF_SIGN_EXTRACT
| DF_REF_ZERO_EXTRACT
))
3412 width
= DF_REF_EXTRACT_WIDTH (ref
);
3413 offset
= DF_REF_EXTRACT_OFFSET (ref
);
3414 mode
= DF_REF_EXTRACT_MODE (ref
);
3417 use
= df_ref_create_structure (DF_REF_CLASS (ref
), collection_rec
, DF_REF_REG (ref
),
3418 DF_REF_LOC (ref
), DF_REF_BB (ref
),
3419 DF_REF_INSN_INFO (ref
), DF_REF_REG_USE
,
3420 DF_REF_FLAGS (ref
) & ~DF_REF_CONDITIONAL
,
3421 width
, offset
, mode
);
3422 DF_REF_REGNO (use
) = DF_REF_REGNO (ref
);
3428 /* Get call's extra defs and uses. */
3431 df_get_call_refs (struct df_collection_rec
* collection_rec
,
3433 struct df_insn_info
*insn_info
,
3439 bool is_sibling_call
;
3442 bitmap_head defs_generated
;
3444 bitmap_initialize (&defs_generated
, &df_bitmap_obstack
);
3446 /* Do not generate clobbers for registers that are the result of the
3447 call. This causes ordering problems in the chain building code
3448 depending on which def is seen first. */
3449 for (i
= 0; VEC_iterate (df_ref
, collection_rec
->def_vec
, i
, def
); ++i
)
3450 bitmap_set_bit (&defs_generated
, DF_REF_REGNO (def
));
3452 /* Record the registers used to pass arguments, and explicitly
3453 noted as clobbered. */
3454 for (note
= CALL_INSN_FUNCTION_USAGE (insn_info
->insn
); note
;
3455 note
= XEXP (note
, 1))
3457 if (GET_CODE (XEXP (note
, 0)) == USE
)
3458 df_uses_record (DF_REF_REGULAR
, collection_rec
, &XEXP (XEXP (note
, 0), 0),
3459 DF_REF_REG_USE
, bb
, insn_info
, flags
, -1, -1,
3461 else if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
3463 if (REG_P (XEXP (XEXP (note
, 0), 0)))
3465 unsigned int regno
= REGNO (XEXP (XEXP (note
, 0), 0));
3466 if (!bitmap_bit_p (&defs_generated
, regno
))
3467 df_defs_record (collection_rec
, XEXP (note
, 0), bb
,
3471 df_uses_record (DF_REF_REGULAR
, collection_rec
, &XEXP (note
, 0),
3472 DF_REF_REG_USE
, bb
, insn_info
, flags
, -1, -1,
3477 /* The stack ptr is used (honorarily) by a CALL insn. */
3478 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[STACK_POINTER_REGNUM
],
3479 NULL
, bb
, insn_info
, DF_REF_REG_USE
,
3480 DF_REF_CALL_STACK_USAGE
| flags
,
3483 /* Calls may also reference any of the global registers,
3484 so they are recorded as used. */
3485 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3488 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3489 NULL
, bb
, insn_info
, DF_REF_REG_USE
, flags
, -1, -1,
3491 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[i
],
3492 NULL
, bb
, insn_info
, DF_REF_REG_DEF
, flags
, -1, -1,
3496 is_sibling_call
= SIBLING_CALL_P (insn_info
->insn
);
3497 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset
, 0, ui
, bi
)
3499 if (!global_regs
[ui
]
3500 && (!bitmap_bit_p (&defs_generated
, ui
))
3501 && (!is_sibling_call
3502 || !bitmap_bit_p (df
->exit_block_uses
, ui
)
3503 || refers_to_regno_p (ui
, ui
+1,
3504 crtl
->return_rtx
, NULL
)))
3505 df_ref_record (DF_REF_BASE
, collection_rec
, regno_reg_rtx
[ui
],
3506 NULL
, bb
, insn_info
, DF_REF_REG_DEF
,
3507 DF_REF_MAY_CLOBBER
| flags
,
3511 bitmap_clear (&defs_generated
);
3515 /* Collect all refs in the INSN. This function is free of any
3516 side-effect - it will create and return a lists of df_ref's in the
3517 COLLECTION_REC without putting those refs into existing ref chains
3521 df_insn_refs_collect (struct df_collection_rec
* collection_rec
,
3522 basic_block bb
, struct df_insn_info
*insn_info
)
3525 bool is_cond_exec
= (GET_CODE (PATTERN (insn_info
->insn
)) == COND_EXEC
);
3527 /* Clear out the collection record. */
3528 VEC_truncate (df_ref
, collection_rec
->def_vec
, 0);
3529 VEC_truncate (df_ref
, collection_rec
->use_vec
, 0);
3530 VEC_truncate (df_ref
, collection_rec
->eq_use_vec
, 0);
3531 VEC_truncate (df_mw_hardreg_ptr
, collection_rec
->mw_vec
, 0);
3533 /* Record register defs. */
3534 df_defs_record (collection_rec
, PATTERN (insn_info
->insn
), bb
, insn_info
, 0);
3536 /* Process REG_EQUIV/REG_EQUAL notes. */
3537 for (note
= REG_NOTES (insn_info
->insn
); note
;
3538 note
= XEXP (note
, 1))
3540 switch (REG_NOTE_KIND (note
))
3544 df_uses_record (DF_REF_REGULAR
, collection_rec
,
3545 &XEXP (note
, 0), DF_REF_REG_USE
,
3546 bb
, insn_info
, DF_REF_IN_NOTE
, -1, -1, VOIDmode
);
3548 case REG_NON_LOCAL_GOTO
:
3549 /* The frame ptr is used by a non-local goto. */
3550 df_ref_record (DF_REF_BASE
, collection_rec
,
3551 regno_reg_rtx
[FRAME_POINTER_REGNUM
],
3552 NULL
, bb
, insn_info
,
3553 DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
3554 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3555 df_ref_record (DF_REF_BASE
, collection_rec
,
3556 regno_reg_rtx
[HARD_FRAME_POINTER_REGNUM
],
3557 NULL
, bb
, insn_info
,
3558 DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
3566 if (CALL_P (insn_info
->insn
))
3567 df_get_call_refs (collection_rec
, bb
, insn_info
,
3568 (is_cond_exec
) ? DF_REF_CONDITIONAL
: 0);
3570 /* Record the register uses. */
3571 df_uses_record (DF_REF_REGULAR
, collection_rec
,
3572 &PATTERN (insn_info
->insn
), DF_REF_REG_USE
, bb
, insn_info
, 0,
3575 /* DF_REF_CONDITIONAL needs corresponding USES. */
3577 df_get_conditional_uses (collection_rec
);
3579 df_canonize_collection_rec (collection_rec
);
3582 /* Recompute the luids for the insns in BB. */
3585 df_recompute_luids (basic_block bb
)
3590 df_grow_insn_info ();
3592 /* Scan the block an insn at a time from beginning to end. */
3593 FOR_BB_INSNS (bb
, insn
)
3595 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3596 /* Inserting labels does not always trigger the incremental
3600 gcc_assert (!INSN_P (insn
));
3601 insn_info
= df_insn_create_insn_record (insn
);
3604 DF_INSN_INFO_LUID (insn_info
) = luid
;
3611 /* Collect all artificial refs at the block level for BB and add them
3612 to COLLECTION_REC. */
3615 df_bb_refs_collect (struct df_collection_rec
*collection_rec
, basic_block bb
)
3617 VEC_truncate (df_ref
, collection_rec
->def_vec
, 0);
3618 VEC_truncate (df_ref
, collection_rec
->use_vec
, 0);
3619 VEC_truncate (df_ref
, collection_rec
->eq_use_vec
, 0);
3620 VEC_truncate (df_mw_hardreg_ptr
, collection_rec
->mw_vec
, 0);
3622 if (bb
->index
== ENTRY_BLOCK
)
3624 df_entry_block_defs_collect (collection_rec
, df
->entry_block_defs
);
3627 else if (bb
->index
== EXIT_BLOCK
)
3629 df_exit_block_uses_collect (collection_rec
, df
->exit_block_uses
);
3633 #ifdef EH_RETURN_DATA_REGNO
3634 if (bb_has_eh_pred (bb
))
3637 /* Mark the registers that will contain data for the handler. */
3640 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
3641 if (regno
== INVALID_REGNUM
)
3643 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3644 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
, -1, -1,
3650 /* Add the hard_frame_pointer if this block is the target of a
3652 if (bb
->flags
& BB_NON_LOCAL_GOTO_TARGET
)
3653 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, hard_frame_pointer_rtx
, NULL
,
3654 bb
, NULL
, DF_REF_REG_DEF
, DF_REF_AT_TOP
, -1, -1, VOIDmode
);
3656 /* Add the artificial uses. */
3657 if (bb
->index
>= NUM_FIXED_BLOCKS
)
3661 bitmap au
= bb_has_eh_pred (bb
)
3662 ? &df
->eh_block_artificial_uses
3663 : &df
->regular_block_artificial_uses
;
3665 EXECUTE_IF_SET_IN_BITMAP (au
, 0, regno
, bi
)
3667 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[regno
], NULL
,
3668 bb
, NULL
, DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
3672 df_canonize_collection_rec (collection_rec
);
3676 /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
3679 df_bb_refs_record (int bb_index
, bool scan_insns
)
3681 basic_block bb
= BASIC_BLOCK (bb_index
);
3684 struct df_collection_rec collection_rec
;
3689 df_grow_bb_info (df_scan
);
3690 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, 128);
3691 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, 32);
3692 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
3693 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
3696 /* Scan the block an insn at a time from beginning to end. */
3697 FOR_BB_INSNS (bb
, insn
)
3699 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3700 gcc_assert (!insn_info
);
3702 insn_info
= df_insn_create_insn_record (insn
);
3705 /* Record refs within INSN. */
3706 DF_INSN_INFO_LUID (insn_info
) = luid
++;
3707 df_insn_refs_collect (&collection_rec
, bb
, DF_INSN_INFO_GET (insn
));
3708 df_refs_add_to_chains (&collection_rec
, bb
, insn
);
3710 DF_INSN_INFO_LUID (insn_info
) = luid
;
3713 /* Other block level artificial refs */
3714 df_bb_refs_collect (&collection_rec
, bb
);
3715 df_refs_add_to_chains (&collection_rec
, bb
, NULL
);
3717 VEC_free (df_ref
, stack
, collection_rec
.def_vec
);
3718 VEC_free (df_ref
, stack
, collection_rec
.use_vec
);
3719 VEC_free (df_ref
, stack
, collection_rec
.eq_use_vec
);
3720 VEC_free (df_mw_hardreg_ptr
, stack
, collection_rec
.mw_vec
);
3722 /* Now that the block has been processed, set the block as dirty so
3723 LR and LIVE will get it processed. */
3724 df_set_bb_dirty (bb
);
3728 /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
3732 df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses
)
3738 bitmap_clear (regular_block_artificial_uses
);
3740 if (reload_completed
)
3742 if (frame_pointer_needed
)
3743 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3746 /* Before reload, there are a few registers that must be forced
3747 live everywhere -- which might not already be the case for
3748 blocks within infinite loops. */
3750 /* Any reference to any pseudo before reload is a potential
3751 reference of the frame pointer. */
3752 bitmap_set_bit (regular_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3754 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3755 bitmap_set_bit (regular_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3758 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3759 /* Pseudos with argument area equivalences may require
3760 reloading via the argument pointer. */
3761 if (fixed_regs
[ARG_POINTER_REGNUM
])
3762 bitmap_set_bit (regular_block_artificial_uses
, ARG_POINTER_REGNUM
);
3765 /* Any constant, or pseudo with constant equivalences, may
3766 require reloading from memory using the pic register. */
3767 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
3768 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
3769 bitmap_set_bit (regular_block_artificial_uses
, PIC_OFFSET_TABLE_REGNUM
);
3771 /* The all-important stack pointer must always be live. */
3772 bitmap_set_bit (regular_block_artificial_uses
, STACK_POINTER_REGNUM
);
3775 /* EH_USES registers are used:
3776 1) at all insns that might throw (calls or with -fnon-call-exceptions
3779 3) to support backtraces and/or debugging, anywhere between their
3780 initialization and where they the saved registers are restored
3781 from them, including the cases where we don't reach the epilogue
3782 (noreturn call or infinite loop). */
3783 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3785 bitmap_set_bit (regular_block_artificial_uses
, i
);
3790 /* Get the artificial use set for an eh block. */
3793 df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses
)
3795 bitmap_clear (eh_block_artificial_uses
);
3797 /* The following code (down thru the arg_pointer setting APPEARS
3798 to be necessary because there is nothing that actually
3799 describes what the exception handling code may actually need
3801 if (reload_completed
)
3803 if (frame_pointer_needed
)
3805 bitmap_set_bit (eh_block_artificial_uses
, FRAME_POINTER_REGNUM
);
3806 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3807 bitmap_set_bit (eh_block_artificial_uses
, HARD_FRAME_POINTER_REGNUM
);
3810 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3811 if (fixed_regs
[ARG_POINTER_REGNUM
])
3812 bitmap_set_bit (eh_block_artificial_uses
, ARG_POINTER_REGNUM
);
3819 /*----------------------------------------------------------------------------
3820 Specialized hard register scanning functions.
3821 ----------------------------------------------------------------------------*/
3824 /* Mark a register in SET. Hard registers in large modes get all
3825 of their component registers set as well. */
3828 df_mark_reg (rtx reg
, void *vset
)
3830 bitmap set
= (bitmap
) vset
;
3831 int regno
= REGNO (reg
);
3833 gcc_assert (GET_MODE (reg
) != BLKmode
);
3835 if (regno
< FIRST_PSEUDO_REGISTER
)
3837 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3838 bitmap_set_range (set
, regno
, n
);
3841 bitmap_set_bit (set
, regno
);
3845 /* Set the bit for regs that are considered being defined at the entry. */
3848 df_get_entry_block_def_set (bitmap entry_block_defs
)
3853 bitmap_clear (entry_block_defs
);
3855 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3857 if (FUNCTION_ARG_REGNO_P (i
))
3858 #ifdef INCOMING_REGNO
3859 bitmap_set_bit (entry_block_defs
, INCOMING_REGNO (i
));
3861 bitmap_set_bit (entry_block_defs
, i
);
3865 /* The always important stack pointer. */
3866 bitmap_set_bit (entry_block_defs
, STACK_POINTER_REGNUM
);
3868 /* Once the prologue has been generated, all of these registers
3869 should just show up in the first regular block. */
3870 if (HAVE_prologue
&& epilogue_completed
)
3872 /* Defs for the callee saved registers are inserted so that the
3873 pushes have some defining location. */
3874 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3875 if ((call_used_regs
[i
] == 0) && (df_regs_ever_live_p (i
)))
3876 bitmap_set_bit (entry_block_defs
, i
);
3879 r
= targetm
.calls
.struct_value_rtx (current_function_decl
, true);
3881 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3883 /* If the function has an incoming STATIC_CHAIN, it has to show up
3884 in the entry def set. */
3885 r
= targetm
.calls
.static_chain (current_function_decl
, true);
3887 bitmap_set_bit (entry_block_defs
, REGNO (r
));
3889 if ((!reload_completed
) || frame_pointer_needed
)
3891 /* Any reference to any pseudo before reload is a potential
3892 reference of the frame pointer. */
3893 bitmap_set_bit (entry_block_defs
, FRAME_POINTER_REGNUM
);
3894 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3895 /* If they are different, also mark the hard frame pointer as live. */
3896 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
3897 bitmap_set_bit (entry_block_defs
, HARD_FRAME_POINTER_REGNUM
);
3901 /* These registers are live everywhere. */
3902 if (!reload_completed
)
3904 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3905 /* Pseudos with argument area equivalences may require
3906 reloading via the argument pointer. */
3907 if (fixed_regs
[ARG_POINTER_REGNUM
])
3908 bitmap_set_bit (entry_block_defs
, ARG_POINTER_REGNUM
);
3911 #ifdef PIC_OFFSET_TABLE_REGNUM
3912 /* Any constant, or pseudo with constant equivalences, may
3913 require reloading from memory using the pic register. */
3914 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
3915 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
3916 bitmap_set_bit (entry_block_defs
, PIC_OFFSET_TABLE_REGNUM
);
3920 #ifdef INCOMING_RETURN_ADDR_RTX
3921 if (REG_P (INCOMING_RETURN_ADDR_RTX
))
3922 bitmap_set_bit (entry_block_defs
, REGNO (INCOMING_RETURN_ADDR_RTX
));
3925 targetm
.extra_live_on_entry (entry_block_defs
);
3929 /* Return the (conservative) set of hard registers that are defined on
3930 entry to the function.
3931 It uses df->entry_block_defs to determine which register
3932 reference to include. */
3935 df_entry_block_defs_collect (struct df_collection_rec
*collection_rec
,
3936 bitmap entry_block_defs
)
3941 EXECUTE_IF_SET_IN_BITMAP (entry_block_defs
, 0, i
, bi
)
3943 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
3944 ENTRY_BLOCK_PTR
, NULL
, DF_REF_REG_DEF
, 0, -1, -1,
3948 df_canonize_collection_rec (collection_rec
);
3952 /* Record the (conservative) set of hard registers that are defined on
3953 entry to the function. */
3956 df_record_entry_block_defs (bitmap entry_block_defs
)
3958 struct df_collection_rec collection_rec
;
3959 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
3960 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, FIRST_PSEUDO_REGISTER
);
3961 df_entry_block_defs_collect (&collection_rec
, entry_block_defs
);
3963 /* Process bb_refs chain */
3964 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (ENTRY_BLOCK
), NULL
);
3965 VEC_free (df_ref
, stack
, collection_rec
.def_vec
);
3969 /* Update the defs in the entry block. */
3972 df_update_entry_block_defs (void)
3975 bool changed
= false;
3977 bitmap_initialize (&refs
, &df_bitmap_obstack
);
3978 df_get_entry_block_def_set (&refs
);
3979 if (df
->entry_block_defs
)
3981 if (!bitmap_equal_p (df
->entry_block_defs
, &refs
))
3983 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (ENTRY_BLOCK
);
3984 df_ref_chain_delete_du_chain (bb_info
->artificial_defs
);
3985 df_ref_chain_delete (bb_info
->artificial_defs
);
3986 bb_info
->artificial_defs
= NULL
;
3992 struct df_scan_problem_data
*problem_data
3993 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
3995 df
->entry_block_defs
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
4001 df_record_entry_block_defs (&refs
);
4002 bitmap_copy (df
->entry_block_defs
, &refs
);
4003 df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK
));
4005 bitmap_clear (&refs
);
4009 /* Set the bit for regs that are considered being used at the exit. */
4012 df_get_exit_block_use_set (bitmap exit_block_uses
)
4016 bitmap_clear (exit_block_uses
);
4018 /* Stack pointer is always live at the exit. */
4019 bitmap_set_bit (exit_block_uses
, STACK_POINTER_REGNUM
);
4021 /* Mark the frame pointer if needed at the end of the function.
4022 If we end up eliminating it, it will be removed from the live
4023 list of each basic block by reload. */
4025 if ((!reload_completed
) || frame_pointer_needed
)
4027 bitmap_set_bit (exit_block_uses
, FRAME_POINTER_REGNUM
);
4028 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4029 /* If they are different, also mark the hard frame pointer as live. */
4030 if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
4031 bitmap_set_bit (exit_block_uses
, HARD_FRAME_POINTER_REGNUM
);
4035 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
4036 /* Many architectures have a GP register even without flag_pic.
4037 Assume the pic register is not in use, or will be handled by
4038 other means, if it is not fixed. */
4039 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
4040 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
4041 bitmap_set_bit (exit_block_uses
, PIC_OFFSET_TABLE_REGNUM
);
4044 /* Mark all global registers, and all registers used by the
4045 epilogue as being live at the end of the function since they
4046 may be referenced by our caller. */
4047 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4048 if (global_regs
[i
] || EPILOGUE_USES (i
))
4049 bitmap_set_bit (exit_block_uses
, i
);
4051 if (HAVE_epilogue
&& epilogue_completed
)
4053 /* Mark all call-saved registers that we actually used. */
4054 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4055 if (df_regs_ever_live_p (i
) && !LOCAL_REGNO (i
)
4056 && !TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
4057 bitmap_set_bit (exit_block_uses
, i
);
4060 #ifdef EH_RETURN_DATA_REGNO
4061 /* Mark the registers that will contain data for the handler. */
4062 if (reload_completed
&& crtl
->calls_eh_return
)
4065 unsigned regno
= EH_RETURN_DATA_REGNO (i
);
4066 if (regno
== INVALID_REGNUM
)
4068 bitmap_set_bit (exit_block_uses
, regno
);
4072 #ifdef EH_RETURN_STACKADJ_RTX
4073 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4074 && crtl
->calls_eh_return
)
4076 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
4077 if (tmp
&& REG_P (tmp
))
4078 df_mark_reg (tmp
, exit_block_uses
);
4082 #ifdef EH_RETURN_HANDLER_RTX
4083 if ((!HAVE_epilogue
|| ! epilogue_completed
)
4084 && crtl
->calls_eh_return
)
4086 rtx tmp
= EH_RETURN_HANDLER_RTX
;
4087 if (tmp
&& REG_P (tmp
))
4088 df_mark_reg (tmp
, exit_block_uses
);
4092 /* Mark function return value. */
4093 diddle_return_value (df_mark_reg
, (void*) exit_block_uses
);
4097 /* Return the refs of hard registers that are used in the exit block.
4098 It uses df->exit_block_uses to determine register to include. */
4101 df_exit_block_uses_collect (struct df_collection_rec
*collection_rec
, bitmap exit_block_uses
)
4106 EXECUTE_IF_SET_IN_BITMAP (exit_block_uses
, 0, i
, bi
)
4107 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[i
], NULL
,
4108 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
4110 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4111 /* It is deliberate that this is not put in the exit block uses but
4112 I do not know why. */
4113 if (reload_completed
4114 && !bitmap_bit_p (exit_block_uses
, ARG_POINTER_REGNUM
)
4115 && bb_has_eh_pred (EXIT_BLOCK_PTR
)
4116 && fixed_regs
[ARG_POINTER_REGNUM
])
4117 df_ref_record (DF_REF_ARTIFICIAL
, collection_rec
, regno_reg_rtx
[ARG_POINTER_REGNUM
], NULL
,
4118 EXIT_BLOCK_PTR
, NULL
, DF_REF_REG_USE
, 0, -1, -1, VOIDmode
);
4121 df_canonize_collection_rec (collection_rec
);
4125 /* Record the set of hard registers that are used in the exit block.
4126 It uses df->exit_block_uses to determine which bit to include. */
4129 df_record_exit_block_uses (bitmap exit_block_uses
)
4131 struct df_collection_rec collection_rec
;
4132 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4133 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, FIRST_PSEUDO_REGISTER
);
4135 df_exit_block_uses_collect (&collection_rec
, exit_block_uses
);
4137 /* Process bb_refs chain */
4138 df_refs_add_to_chains (&collection_rec
, BASIC_BLOCK (EXIT_BLOCK
), NULL
);
4139 VEC_free (df_ref
, stack
, collection_rec
.use_vec
);
4143 /* Update the uses in the exit block. */
4146 df_update_exit_block_uses (void)
4149 bool changed
= false;
4151 bitmap_initialize (&refs
, &df_bitmap_obstack
);
4152 df_get_exit_block_use_set (&refs
);
4153 if (df
->exit_block_uses
)
4155 if (!bitmap_equal_p (df
->exit_block_uses
, &refs
))
4157 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (EXIT_BLOCK
);
4158 df_ref_chain_delete_du_chain (bb_info
->artificial_uses
);
4159 df_ref_chain_delete (bb_info
->artificial_uses
);
4160 bb_info
->artificial_uses
= NULL
;
4166 struct df_scan_problem_data
*problem_data
4167 = (struct df_scan_problem_data
*) df_scan
->problem_data
;
4169 df
->exit_block_uses
= BITMAP_ALLOC (&problem_data
->reg_bitmaps
);
4175 df_record_exit_block_uses (&refs
);
4176 bitmap_copy (df
->exit_block_uses
,& refs
);
4177 df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK
));
4179 bitmap_clear (&refs
);
4182 static bool initialized
= false;
4185 /* Initialize some platform specific structures. */
4188 df_hard_reg_init (void)
4190 #ifdef ELIMINABLE_REGS
4192 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
4197 /* Record which registers will be eliminated. We use this in
4199 CLEAR_HARD_REG_SET (elim_reg_set
);
4201 #ifdef ELIMINABLE_REGS
4202 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
4203 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
4205 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
4212 /* Recompute the parts of scanning that are based on regs_ever_live
4213 because something changed in that array. */
4216 df_update_entry_exit_and_calls (void)
4220 df_update_entry_block_defs ();
4221 df_update_exit_block_uses ();
4223 /* The call insns need to be rescanned because there may be changes
4224 in the set of registers clobbered across the call. */
4228 FOR_BB_INSNS (bb
, insn
)
4230 if (INSN_P (insn
) && CALL_P (insn
))
4231 df_insn_rescan (insn
);
4237 /* Return true if hard REG is actually used in the some instruction.
4238 There are a fair number of conditions that affect the setting of
4239 this array. See the comment in df.h for df->hard_regs_live_count
4240 for the conditions that this array is set. */
4243 df_hard_reg_used_p (unsigned int reg
)
4245 return df
->hard_regs_live_count
[reg
] != 0;
4249 /* A count of the number of times REG is actually used in the some
4250 instruction. There are a fair number of conditions that affect the
4251 setting of this array. See the comment in df.h for
4252 df->hard_regs_live_count for the conditions that this array is
4257 df_hard_reg_used_count (unsigned int reg
)
4259 return df
->hard_regs_live_count
[reg
];
4263 /* Get the value of regs_ever_live[REGNO]. */
4266 df_regs_ever_live_p (unsigned int regno
)
4268 return regs_ever_live
[regno
];
4272 /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
4273 to change, schedule that change for the next update. */
4276 df_set_regs_ever_live (unsigned int regno
, bool value
)
4278 if (regs_ever_live
[regno
] == value
)
4281 regs_ever_live
[regno
] = value
;
4283 df
->redo_entry_and_exit
= true;
4287 /* Compute "regs_ever_live" information from the underlying df
4288 information. Set the vector to all false if RESET. */
4291 df_compute_regs_ever_live (bool reset
)
4294 bool changed
= df
->redo_entry_and_exit
;
4297 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
4299 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4300 if ((!regs_ever_live
[i
]) && df_hard_reg_used_p (i
))
4302 regs_ever_live
[i
] = true;
4306 df_update_entry_exit_and_calls ();
4307 df
->redo_entry_and_exit
= false;
4311 /*----------------------------------------------------------------------------
4312 Dataflow ref information verification functions.
4314 df_reg_chain_mark (refs, regno, is_def, is_eq_use)
4315 df_reg_chain_verify_unmarked (refs)
4316 df_refs_verify (VEC(stack,df_ref)*, ref*, bool)
4317 df_mws_verify (mw*, mw*, bool)
4318 df_insn_refs_verify (collection_rec, bb, insn, bool)
4319 df_bb_refs_verify (bb, refs, bool)
4321 df_exit_block_bitmap_verify (bool)
4322 df_entry_block_bitmap_verify (bool)
4324 ----------------------------------------------------------------------------*/
4327 /* Mark all refs in the reg chain. Verify that all of the registers
4328 are in the correct chain. */
4331 df_reg_chain_mark (df_ref refs
, unsigned int regno
,
4332 bool is_def
, bool is_eq_use
)
4334 unsigned int count
= 0;
4336 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4338 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4340 /* If there are no def-use or use-def chains, make sure that all
4341 of the chains are clear. */
4343 gcc_assert (!DF_REF_CHAIN (ref
));
4345 /* Check to make sure the ref is in the correct chain. */
4346 gcc_assert (DF_REF_REGNO (ref
) == regno
);
4348 gcc_assert (DF_REF_REG_DEF_P (ref
));
4350 gcc_assert (!DF_REF_REG_DEF_P (ref
));
4353 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
));
4355 gcc_assert ((DF_REF_FLAGS (ref
) & DF_REF_IN_NOTE
) == 0);
4357 if (DF_REF_NEXT_REG (ref
))
4358 gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref
)) == ref
);
4360 DF_REF_REG_MARK (ref
);
4366 /* Verify that all of the registers in the chain are unmarked. */
4369 df_reg_chain_verify_unmarked (df_ref refs
)
4372 for (ref
= refs
; ref
; ref
= DF_REF_NEXT_REG (ref
))
4373 gcc_assert (!DF_REF_IS_REG_MARKED (ref
));
4377 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4380 df_refs_verify (VEC(df_ref
,stack
) *new_rec
, df_ref
*old_rec
,
4386 for (ix
= 0; VEC_iterate (df_ref
, new_rec
, ix
, new_ref
); ++ix
)
4388 if (*old_rec
== NULL
|| !df_ref_equal_p (new_ref
, *old_rec
))
4396 /* Abort if fail is called from the function level verifier. If
4397 that is the context, mark this reg as being seem. */
4400 gcc_assert (DF_REF_IS_REG_MARKED (*old_rec
));
4401 DF_REF_REG_UNMARK (*old_rec
);
4408 gcc_assert (*old_rec
== NULL
);
4410 return *old_rec
== NULL
;
4415 /* Verify that NEW_REC and OLD_REC have exactly the same members. */
4418 df_mws_verify (VEC(df_mw_hardreg_ptr
,stack
) *new_rec
,
4419 struct df_mw_hardreg
**old_rec
,
4423 struct df_mw_hardreg
*new_reg
;
4425 for (ix
= 0; VEC_iterate (df_mw_hardreg_ptr
, new_rec
, ix
, new_reg
); ++ix
)
4427 if (*old_rec
== NULL
|| !df_mw_equal_p (new_reg
, *old_rec
))
4438 gcc_assert (*old_rec
== NULL
);
4440 return *old_rec
== NULL
;
4445 /* Return true if the existing insn refs information is complete and
4446 correct. Otherwise (i.e. if there's any missing or extra refs),
4447 return the correct df_ref chain in REFS_RETURN.
4449 If ABORT_IF_FAIL, leave the refs that are verified (already in the
4450 ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
4451 verification mode instead of the whole function, so unmark
4454 If ABORT_IF_FAIL is set, this function never returns false. */
4457 df_insn_refs_verify (struct df_collection_rec
*collection_rec
,
4462 bool ret1
, ret2
, ret3
, ret4
;
4463 unsigned int uid
= INSN_UID (insn
);
4464 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
4466 df_insn_refs_collect (collection_rec
, bb
, insn_info
);
4468 if (!DF_INSN_UID_DEFS (uid
))
4470 /* The insn_rec was created but it was never filled out. */
4477 /* Unfortunately we cannot opt out early if one of these is not
4478 right because the marks will not get cleared. */
4479 ret1
= df_refs_verify (collection_rec
->def_vec
, DF_INSN_UID_DEFS (uid
),
4481 ret2
= df_refs_verify (collection_rec
->use_vec
, DF_INSN_UID_USES (uid
),
4483 ret3
= df_refs_verify (collection_rec
->eq_use_vec
, DF_INSN_UID_EQ_USES (uid
),
4485 ret4
= df_mws_verify (collection_rec
->mw_vec
, DF_INSN_UID_MWS (uid
),
4487 return (ret1
&& ret2
&& ret3
&& ret4
);
4491 /* Return true if all refs in the basic block are correct and complete.
4492 Due to df_ref_chain_verify, it will cause all refs
4493 that are verified to have DF_REF_MARK bit set. */
4496 df_bb_verify (basic_block bb
)
4499 struct df_scan_bb_info
*bb_info
= df_scan_get_bb_info (bb
->index
);
4500 struct df_collection_rec collection_rec
;
4502 memset (&collection_rec
, 0, sizeof (struct df_collection_rec
));
4503 collection_rec
.def_vec
= VEC_alloc (df_ref
, stack
, 128);
4504 collection_rec
.use_vec
= VEC_alloc (df_ref
, stack
, 32);
4505 collection_rec
.eq_use_vec
= VEC_alloc (df_ref
, stack
, 32);
4506 collection_rec
.mw_vec
= VEC_alloc (df_mw_hardreg_ptr
, stack
, 32);
4508 gcc_assert (bb_info
);
4510 /* Scan the block, one insn at a time, from beginning to end. */
4511 FOR_BB_INSNS_REVERSE (bb
, insn
)
4515 df_insn_refs_verify (&collection_rec
, bb
, insn
, true);
4516 df_free_collection_rec (&collection_rec
);
4519 /* Do the artificial defs and uses. */
4520 df_bb_refs_collect (&collection_rec
, bb
);
4521 df_refs_verify (collection_rec
.def_vec
, df_get_artificial_defs (bb
->index
), true);
4522 df_refs_verify (collection_rec
.use_vec
, df_get_artificial_uses (bb
->index
), true);
4523 df_free_collection_rec (&collection_rec
);
4529 /* Returns true if the entry block has correct and complete df_ref set.
4530 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4533 df_entry_block_bitmap_verify (bool abort_if_fail
)
4535 bitmap_head entry_block_defs
;
4538 bitmap_initialize (&entry_block_defs
, &df_bitmap_obstack
);
4539 df_get_entry_block_def_set (&entry_block_defs
);
4541 is_eq
= bitmap_equal_p (&entry_block_defs
, df
->entry_block_defs
);
4543 if (!is_eq
&& abort_if_fail
)
4545 print_current_pass (stderr
);
4546 fprintf (stderr
, "entry_block_defs = ");
4547 df_print_regset (stderr
, &entry_block_defs
);
4548 fprintf (stderr
, "df->entry_block_defs = ");
4549 df_print_regset (stderr
, df
->entry_block_defs
);
4553 bitmap_clear (&entry_block_defs
);
4559 /* Returns true if the exit block has correct and complete df_ref set.
4560 If not it either aborts if ABORT_IF_FAIL is true or returns false. */
4563 df_exit_block_bitmap_verify (bool abort_if_fail
)
4565 bitmap_head exit_block_uses
;
4568 bitmap_initialize (&exit_block_uses
, &df_bitmap_obstack
);
4569 df_get_exit_block_use_set (&exit_block_uses
);
4571 is_eq
= bitmap_equal_p (&exit_block_uses
, df
->exit_block_uses
);
4573 if (!is_eq
&& abort_if_fail
)
4575 print_current_pass (stderr
);
4576 fprintf (stderr
, "exit_block_uses = ");
4577 df_print_regset (stderr
, &exit_block_uses
);
4578 fprintf (stderr
, "df->exit_block_uses = ");
4579 df_print_regset (stderr
, df
->exit_block_uses
);
4583 bitmap_clear (&exit_block_uses
);
4589 /* Return true if df_ref information for all insns in all blocks are
4590 correct and complete. */
4593 df_scan_verify (void)
4597 bitmap_head regular_block_artificial_uses
;
4598 bitmap_head eh_block_artificial_uses
;
4603 /* Verification is a 4 step process. */
4605 /* (1) All of the refs are marked by going thru the reg chains. */
4606 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4608 gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i
), i
, true, false)
4609 == DF_REG_DEF_COUNT(i
));
4610 gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i
), i
, false, false)
4611 == DF_REG_USE_COUNT(i
));
4612 gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i
), i
, false, true)
4613 == DF_REG_EQ_USE_COUNT(i
));
4616 /* (2) There are various bitmaps whose value may change over the
4617 course of the compilation. This step recomputes them to make
4618 sure that they have not slipped out of date. */
4619 bitmap_initialize (®ular_block_artificial_uses
, &df_bitmap_obstack
);
4620 bitmap_initialize (&eh_block_artificial_uses
, &df_bitmap_obstack
);
4622 df_get_regular_block_artificial_uses (®ular_block_artificial_uses
);
4623 df_get_eh_block_artificial_uses (&eh_block_artificial_uses
);
4625 bitmap_ior_into (&eh_block_artificial_uses
,
4626 ®ular_block_artificial_uses
);
4628 /* Check artificial_uses bitmaps didn't change. */
4629 gcc_assert (bitmap_equal_p (®ular_block_artificial_uses
,
4630 &df
->regular_block_artificial_uses
));
4631 gcc_assert (bitmap_equal_p (&eh_block_artificial_uses
,
4632 &df
->eh_block_artificial_uses
));
4634 bitmap_clear (®ular_block_artificial_uses
);
4635 bitmap_clear (&eh_block_artificial_uses
);
4637 /* Verify entry block and exit block. These only verify the bitmaps,
4638 the refs are verified in df_bb_verify. */
4639 df_entry_block_bitmap_verify (true);
4640 df_exit_block_bitmap_verify (true);
4642 /* (3) All of the insns in all of the blocks are traversed and the
4643 marks are cleared both in the artificial refs attached to the
4644 blocks and the real refs inside the insns. It is a failure to
4645 clear a mark that has not been set as this means that the ref in
4646 the block or insn was not in the reg chain. */
4651 /* (4) See if all reg chains are traversed a second time. This time
4652 a check is made that the marks are clear. A set mark would be a
4653 from a reg that is not in any insn or basic block. */
4655 for (i
= 0; i
< DF_REG_SIZE (df
); i
++)
4657 df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i
));
4658 df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i
));
4659 df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i
));