1 /* Standard problems for dataflow support routines.
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"
49 /* Note that turning REG_DEAD_DEBUGGING on will cause
50 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
51 addresses in the dumps. */
53 #define REG_DEAD_DEBUGGING
56 #define DF_SPARSE_THRESHOLD 32
58 static bitmap_head seen_in_block
;
59 static bitmap_head seen_in_insn
;
62 /*----------------------------------------------------------------------------
63 Public functions access functions for the dataflow problems.
64 ----------------------------------------------------------------------------*/
65 /* Get the live at out set for BB no matter what problem happens to be
66 defined. This function is used by the register allocators who
67 choose different dataflow problems depending on the optimization
71 df_get_live_out (basic_block bb
)
76 return DF_LIVE_OUT (bb
);
78 return DF_LR_OUT (bb
);
81 /* Get the live at in set for BB no matter what problem happens to be
82 defined. This function is used by the register allocators who
83 choose different dataflow problems depending on the optimization
87 df_get_live_in (basic_block bb
)
92 return DF_LIVE_IN (bb
);
97 /*----------------------------------------------------------------------------
99 ----------------------------------------------------------------------------*/
101 /* Generic versions to get the void* version of the block info. Only
102 used inside the problem instance vectors. */
104 /* Dump a def-use or use-def chain for REF to FILE. */
107 df_chain_dump (struct df_link
*link
, FILE *file
)
109 fprintf (file
, "{ ");
110 for (; link
; link
= link
->next
)
112 fprintf (file
, "%c%d(bb %d insn %d) ",
113 DF_REF_REG_DEF_P (link
->ref
) ? 'd' : 'u',
114 DF_REF_ID (link
->ref
),
115 DF_REF_BBNO (link
->ref
),
116 DF_REF_IS_ARTIFICIAL (link
->ref
) ? -1 : DF_REF_INSN_UID (link
->ref
));
122 /* Print some basic block info as part of df_dump. */
125 df_print_bb_index (basic_block bb
, FILE *file
)
130 fprintf (file
, "\n( ");
131 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
133 basic_block pred
= e
->src
;
134 fprintf (file
, "%d%s ", pred
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
136 fprintf (file
, ")->[%d]->( ", bb
->index
);
137 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
139 basic_block succ
= e
->dest
;
140 fprintf (file
, "%d%s ", succ
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
142 fprintf (file
, ")\n");
146 /*----------------------------------------------------------------------------
149 Find the locations in the function where each definition site for a
150 pseudo reaches. In and out bitvectors are built for each basic
151 block. The id field in the ref is used to index into these sets.
152 See df.h for details.
153 ----------------------------------------------------------------------------*/
155 /* This problem plays a large number of games for the sake of
158 1) The order of the bits in the bitvectors. After the scanning
159 phase, all of the defs are sorted. All of the defs for the reg 0
160 are first, followed by all defs for reg 1 and so on.
162 2) There are two kill sets, one if the number of defs is less or
163 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
166 <= : Data is built directly in the kill set.
168 > : One level of indirection is used to keep from generating long
169 strings of 1 bits in the kill sets. Bitvectors that are indexed
170 by the regnum are used to represent that there is a killing def
171 for the register. The confluence and transfer functions use
172 these along with the bitmap_clear_range call to remove ranges of
173 bits without actually generating a knockout vector.
175 The kill and sparse_kill and the dense_invalidated_by_call and
176 sparse_invalidated_by_call both play this game. */
178 /* Private data used to compute the solution for this problem. These
179 data structures are not accessible outside of this module. */
180 struct df_rd_problem_data
182 /* The set of defs to regs invalidated by call. */
183 bitmap_head sparse_invalidated_by_call
;
184 /* The set of defs to regs invalidate by call for rd. */
185 bitmap_head dense_invalidated_by_call
;
186 /* An obstack for the bitmaps we need for this problem. */
187 bitmap_obstack rd_bitmaps
;
191 /* Free basic block info. */
194 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
197 struct df_rd_bb_info
*bb_info
= (struct df_rd_bb_info
*) vbb_info
;
200 bitmap_clear (&bb_info
->kill
);
201 bitmap_clear (&bb_info
->sparse_kill
);
202 bitmap_clear (&bb_info
->gen
);
203 bitmap_clear (&bb_info
->in
);
204 bitmap_clear (&bb_info
->out
);
209 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
210 not touched unless the block is new. */
213 df_rd_alloc (bitmap all_blocks
)
215 unsigned int bb_index
;
217 struct df_rd_problem_data
*problem_data
;
219 if (df_rd
->problem_data
)
221 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
222 bitmap_clear (&problem_data
->sparse_invalidated_by_call
);
223 bitmap_clear (&problem_data
->dense_invalidated_by_call
);
227 problem_data
= XNEW (struct df_rd_problem_data
);
228 df_rd
->problem_data
= problem_data
;
230 bitmap_obstack_initialize (&problem_data
->rd_bitmaps
);
231 bitmap_initialize (&problem_data
->sparse_invalidated_by_call
,
232 &problem_data
->rd_bitmaps
);
233 bitmap_initialize (&problem_data
->dense_invalidated_by_call
,
234 &problem_data
->rd_bitmaps
);
237 df_grow_bb_info (df_rd
);
239 /* Because of the clustering of all use sites for the same pseudo,
240 we have to process all of the blocks before doing the
243 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
245 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
247 /* When bitmaps are already initialized, just clear them. */
248 if (bb_info
->kill
.obstack
)
250 bitmap_clear (&bb_info
->kill
);
251 bitmap_clear (&bb_info
->sparse_kill
);
252 bitmap_clear (&bb_info
->gen
);
256 bitmap_initialize (&bb_info
->kill
, &problem_data
->rd_bitmaps
);
257 bitmap_initialize (&bb_info
->sparse_kill
, &problem_data
->rd_bitmaps
);
258 bitmap_initialize (&bb_info
->gen
, &problem_data
->rd_bitmaps
);
259 bitmap_initialize (&bb_info
->in
, &problem_data
->rd_bitmaps
);
260 bitmap_initialize (&bb_info
->out
, &problem_data
->rd_bitmaps
);
263 df_rd
->optional_p
= true;
267 /* Add the effect of the top artificial defs of BB to the reaching definitions
271 df_rd_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_rd
)
273 int bb_index
= bb
->index
;
275 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
277 df_ref def
= *def_rec
;
278 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
280 unsigned int dregno
= DF_REF_REGNO (def
);
281 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
282 bitmap_clear_range (local_rd
,
283 DF_DEFS_BEGIN (dregno
),
284 DF_DEFS_COUNT (dregno
));
285 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
290 /* Add the effect of the defs of INSN to the reaching definitions bitmap
294 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx insn
,
297 unsigned uid
= INSN_UID (insn
);
300 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
302 df_ref def
= *def_rec
;
303 unsigned int dregno
= DF_REF_REGNO (def
);
304 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
305 || (dregno
>= FIRST_PSEUDO_REGISTER
))
307 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
308 bitmap_clear_range (local_rd
,
309 DF_DEFS_BEGIN (dregno
),
310 DF_DEFS_COUNT (dregno
));
311 if (!(DF_REF_FLAGS (def
)
312 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
313 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
318 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
319 more complicated than just simulating, because we must produce the
320 gen and kill sets and hence deal with the two possible representations
324 df_rd_bb_local_compute_process_def (struct df_rd_bb_info
*bb_info
,
330 df_ref def
= *def_rec
;
331 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
333 unsigned int regno
= DF_REF_REGNO (def
);
334 unsigned int begin
= DF_DEFS_BEGIN (regno
);
335 unsigned int n_defs
= DF_DEFS_COUNT (regno
);
337 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
338 || (regno
>= FIRST_PSEUDO_REGISTER
))
340 /* Only the last def(s) for a regno in the block has any
342 if (!bitmap_bit_p (&seen_in_block
, regno
))
344 /* The first def for regno in insn gets to knock out the
345 defs from other instructions. */
346 if ((!bitmap_bit_p (&seen_in_insn
, regno
))
347 /* If the def is to only part of the reg, it does
348 not kill the other defs that reach here. */
349 && (!(DF_REF_FLAGS (def
) &
350 (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))))
352 if (n_defs
> DF_SPARSE_THRESHOLD
)
354 bitmap_set_bit (&bb_info
->sparse_kill
, regno
);
355 bitmap_clear_range(&bb_info
->gen
, begin
, n_defs
);
359 bitmap_set_range (&bb_info
->kill
, begin
, n_defs
);
360 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
364 bitmap_set_bit (&seen_in_insn
, regno
);
365 /* All defs for regno in the instruction may be put into
367 if (!(DF_REF_FLAGS (def
)
368 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
369 bitmap_set_bit (&bb_info
->gen
, DF_REF_ID (def
));
377 /* Compute local reaching def info for basic block BB. */
380 df_rd_bb_local_compute (unsigned int bb_index
)
382 basic_block bb
= BASIC_BLOCK (bb_index
);
383 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
386 bitmap_clear (&seen_in_block
);
387 bitmap_clear (&seen_in_insn
);
389 /* Artificials are only hard regs. */
390 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
391 df_rd_bb_local_compute_process_def (bb_info
,
392 df_get_artificial_defs (bb_index
),
395 FOR_BB_INSNS_REVERSE (bb
, insn
)
397 unsigned int uid
= INSN_UID (insn
);
402 df_rd_bb_local_compute_process_def (bb_info
,
403 DF_INSN_UID_DEFS (uid
), 0);
405 /* This complex dance with the two bitmaps is required because
406 instructions can assign twice to the same pseudo. This
407 generally happens with calls that will have one def for the
408 result and another def for the clobber. If only one vector
409 is used and the clobber goes first, the result will be
411 bitmap_ior_into (&seen_in_block
, &seen_in_insn
);
412 bitmap_clear (&seen_in_insn
);
415 /* Process the artificial defs at the top of the block last since we
416 are going backwards through the block and these are logically at
418 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
419 df_rd_bb_local_compute_process_def (bb_info
,
420 df_get_artificial_defs (bb_index
),
425 /* Compute local reaching def info for each basic block within BLOCKS. */
428 df_rd_local_compute (bitmap all_blocks
)
430 unsigned int bb_index
;
433 struct df_rd_problem_data
*problem_data
434 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
435 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
436 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
438 bitmap_initialize (&seen_in_block
, &df_bitmap_obstack
);
439 bitmap_initialize (&seen_in_insn
, &df_bitmap_obstack
);
441 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG
);
443 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
445 df_rd_bb_local_compute (bb_index
);
448 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
449 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset
, 0, regno
, bi
)
451 if (DF_DEFS_COUNT (regno
) > DF_SPARSE_THRESHOLD
)
452 bitmap_set_bit (sparse_invalidated
, regno
);
454 bitmap_set_range (dense_invalidated
,
455 DF_DEFS_BEGIN (regno
),
456 DF_DEFS_COUNT (regno
));
459 bitmap_clear (&seen_in_block
);
460 bitmap_clear (&seen_in_insn
);
464 /* Initialize the solution bit vectors for problem. */
467 df_rd_init_solution (bitmap all_blocks
)
469 unsigned int bb_index
;
472 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
474 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
476 bitmap_copy (&bb_info
->out
, &bb_info
->gen
);
477 bitmap_clear (&bb_info
->in
);
481 /* In of target gets or of out of source. */
484 df_rd_confluence_n (edge e
)
486 bitmap op1
= &df_rd_get_bb_info (e
->dest
->index
)->in
;
487 bitmap op2
= &df_rd_get_bb_info (e
->src
->index
)->out
;
488 bool changed
= false;
490 if (e
->flags
& EDGE_FAKE
)
493 if (e
->flags
& EDGE_EH
)
495 struct df_rd_problem_data
*problem_data
496 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
497 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
498 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
503 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
504 bitmap_copy (&tmp
, op2
);
505 bitmap_and_compl_into (&tmp
, dense_invalidated
);
507 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
509 bitmap_clear_range (&tmp
,
510 DF_DEFS_BEGIN (regno
),
511 DF_DEFS_COUNT (regno
));
513 changed
|= bitmap_ior_into (op1
, &tmp
);
518 return bitmap_ior_into (op1
, op2
);
522 /* Transfer function. */
525 df_rd_transfer_function (int bb_index
)
527 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
530 bitmap in
= &bb_info
->in
;
531 bitmap out
= &bb_info
->out
;
532 bitmap gen
= &bb_info
->gen
;
533 bitmap kill
= &bb_info
->kill
;
534 bitmap sparse_kill
= &bb_info
->sparse_kill
;
536 if (bitmap_empty_p (sparse_kill
))
537 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
540 struct df_rd_problem_data
*problem_data
;
541 bool changed
= false;
544 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
545 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
546 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
547 bitmap_initialize (&tmp
, &problem_data
->rd_bitmaps
);
549 bitmap_copy (&tmp
, in
);
550 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
552 bitmap_clear_range (&tmp
,
553 DF_DEFS_BEGIN (regno
),
554 DF_DEFS_COUNT (regno
));
556 bitmap_and_compl_into (&tmp
, kill
);
557 bitmap_ior_into (&tmp
, gen
);
558 changed
= !bitmap_equal_p (&tmp
, out
);
571 /* Free all storage associated with the problem. */
576 struct df_rd_problem_data
*problem_data
577 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
581 bitmap_obstack_release (&problem_data
->rd_bitmaps
);
583 df_rd
->block_info_size
= 0;
584 free (df_rd
->block_info
);
585 df_rd
->block_info
= NULL
;
586 free (df_rd
->problem_data
);
592 /* Debugging info. */
595 df_rd_start_dump (FILE *file
)
597 struct df_rd_problem_data
*problem_data
598 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
599 unsigned int m
= DF_REG_SIZE(df
);
602 if (!df_rd
->block_info
)
605 fprintf (file
, ";; Reaching defs:\n\n");
607 fprintf (file
, " sparse invalidated \t");
608 dump_bitmap (file
, &problem_data
->sparse_invalidated_by_call
);
609 fprintf (file
, " dense invalidated \t");
610 dump_bitmap (file
, &problem_data
->dense_invalidated_by_call
);
612 for (regno
= 0; regno
< m
; regno
++)
613 if (DF_DEFS_COUNT (regno
))
614 fprintf (file
, "%d[%d,%d] ", regno
,
615 DF_DEFS_BEGIN (regno
),
616 DF_DEFS_COUNT (regno
));
617 fprintf (file
, "\n");
622 /* Debugging info at top of bb. */
625 df_rd_top_dump (basic_block bb
, FILE *file
)
627 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
631 fprintf (file
, ";; rd in \t(%d)\n", (int) bitmap_count_bits (&bb_info
->in
));
632 dump_bitmap (file
, &bb_info
->in
);
633 fprintf (file
, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (&bb_info
->gen
));
634 dump_bitmap (file
, &bb_info
->gen
);
635 fprintf (file
, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (&bb_info
->kill
));
636 dump_bitmap (file
, &bb_info
->kill
);
640 /* Debugging info at top of bb. */
643 df_rd_bottom_dump (basic_block bb
, FILE *file
)
645 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
649 fprintf (file
, ";; rd out \t(%d)\n", (int) bitmap_count_bits (&bb_info
->out
));
650 dump_bitmap (file
, &bb_info
->out
);
653 /* All of the information associated with every instance of the problem. */
655 static struct df_problem problem_RD
=
657 DF_RD
, /* Problem id. */
658 DF_FORWARD
, /* Direction. */
659 df_rd_alloc
, /* Allocate the problem specific data. */
660 NULL
, /* Reset global information. */
661 df_rd_free_bb_info
, /* Free basic block info. */
662 df_rd_local_compute
, /* Local compute function. */
663 df_rd_init_solution
, /* Init the solution specific data. */
664 df_worklist_dataflow
, /* Worklist solver. */
665 NULL
, /* Confluence operator 0. */
666 df_rd_confluence_n
, /* Confluence operator n. */
667 df_rd_transfer_function
, /* Transfer function. */
668 NULL
, /* Finalize function. */
669 df_rd_free
, /* Free all of the problem information. */
670 df_rd_free
, /* Remove this problem from the stack of dataflow problems. */
671 df_rd_start_dump
, /* Debugging. */
672 df_rd_top_dump
, /* Debugging start block. */
673 df_rd_bottom_dump
, /* Debugging end block. */
674 NULL
, /* Incremental solution verify start. */
675 NULL
, /* Incremental solution verify end. */
676 NULL
, /* Dependent problem. */
677 sizeof (struct df_rd_bb_info
),/* Size of entry of block_info array. */
678 TV_DF_RD
, /* Timing variable. */
679 true /* Reset blocks on dropping out of blocks_to_analyze. */
684 /* Create a new RD instance and add it to the existing instance
688 df_rd_add_problem (void)
690 df_add_problem (&problem_RD
);
695 /*----------------------------------------------------------------------------
698 Find the locations in the function where any use of a pseudo can
699 reach in the backwards direction. In and out bitvectors are built
700 for each basic block. The regno is used to index into these sets.
701 See df.h for details.
702 ----------------------------------------------------------------------------*/
704 /* Private data used to verify the solution for this problem. */
705 struct df_lr_problem_data
709 /* An obstack for the bitmaps we need for this problem. */
710 bitmap_obstack lr_bitmaps
;
713 /* Free basic block info. */
716 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
719 struct df_lr_bb_info
*bb_info
= (struct df_lr_bb_info
*) vbb_info
;
722 bitmap_clear (&bb_info
->use
);
723 bitmap_clear (&bb_info
->def
);
724 bitmap_clear (&bb_info
->in
);
725 bitmap_clear (&bb_info
->out
);
730 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
731 not touched unless the block is new. */
734 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
736 unsigned int bb_index
;
738 struct df_lr_problem_data
*problem_data
;
740 df_grow_bb_info (df_lr
);
741 if (df_lr
->problem_data
)
742 problem_data
= (struct df_lr_problem_data
*) df_lr
->problem_data
;
745 problem_data
= XNEW (struct df_lr_problem_data
);
746 df_lr
->problem_data
= problem_data
;
748 problem_data
->out
= NULL
;
749 problem_data
->in
= NULL
;
750 bitmap_obstack_initialize (&problem_data
->lr_bitmaps
);
753 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
755 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
757 /* When bitmaps are already initialized, just clear them. */
758 if (bb_info
->use
.obstack
)
760 bitmap_clear (&bb_info
->def
);
761 bitmap_clear (&bb_info
->use
);
765 bitmap_initialize (&bb_info
->use
, &problem_data
->lr_bitmaps
);
766 bitmap_initialize (&bb_info
->def
, &problem_data
->lr_bitmaps
);
767 bitmap_initialize (&bb_info
->in
, &problem_data
->lr_bitmaps
);
768 bitmap_initialize (&bb_info
->out
, &problem_data
->lr_bitmaps
);
772 df_lr
->optional_p
= false;
776 /* Reset the global solution for recalculation. */
779 df_lr_reset (bitmap all_blocks
)
781 unsigned int bb_index
;
784 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
786 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
787 gcc_assert (bb_info
);
788 bitmap_clear (&bb_info
->in
);
789 bitmap_clear (&bb_info
->out
);
794 /* Compute local live register info for basic block BB. */
797 df_lr_bb_local_compute (unsigned int bb_index
)
799 basic_block bb
= BASIC_BLOCK (bb_index
);
800 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
805 /* Process the registers set in an exception handler. */
806 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
808 df_ref def
= *def_rec
;
809 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
811 unsigned int dregno
= DF_REF_REGNO (def
);
812 bitmap_set_bit (&bb_info
->def
, dregno
);
813 bitmap_clear_bit (&bb_info
->use
, dregno
);
817 /* Process the hardware registers that are always live. */
818 for (use_rec
= df_get_artificial_uses (bb_index
); *use_rec
; use_rec
++)
820 df_ref use
= *use_rec
;
821 /* Add use to set of uses in this BB. */
822 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
823 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
826 FOR_BB_INSNS_REVERSE (bb
, insn
)
828 unsigned int uid
= INSN_UID (insn
);
830 if (!NONDEBUG_INSN_P (insn
))
833 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
835 df_ref def
= *def_rec
;
836 /* If the def is to only part of the reg, it does
837 not kill the other defs that reach here. */
838 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
840 unsigned int dregno
= DF_REF_REGNO (def
);
841 bitmap_set_bit (&bb_info
->def
, dregno
);
842 bitmap_clear_bit (&bb_info
->use
, dregno
);
846 for (use_rec
= DF_INSN_UID_USES (uid
); *use_rec
; use_rec
++)
848 df_ref use
= *use_rec
;
849 /* Add use to set of uses in this BB. */
850 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
854 /* Process the registers set in an exception handler or the hard
855 frame pointer if this block is the target of a non local
857 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
859 df_ref def
= *def_rec
;
860 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
862 unsigned int dregno
= DF_REF_REGNO (def
);
863 bitmap_set_bit (&bb_info
->def
, dregno
);
864 bitmap_clear_bit (&bb_info
->use
, dregno
);
869 /* Process the uses that are live into an exception handler. */
870 for (use_rec
= df_get_artificial_uses (bb_index
); *use_rec
; use_rec
++)
872 df_ref use
= *use_rec
;
873 /* Add use to set of uses in this BB. */
874 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
875 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
879 /* If the df_live problem is not defined, such as at -O0 and -O1, we
880 still need to keep the luids up to date. This is normally done
881 in the df_live problem since this problem has a forwards
884 df_recompute_luids (bb
);
888 /* Compute local live register info for each basic block within BLOCKS. */
891 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
893 unsigned int bb_index
;
896 bitmap_clear (&df
->hardware_regs_used
);
898 /* The all-important stack pointer must always be live. */
899 bitmap_set_bit (&df
->hardware_regs_used
, STACK_POINTER_REGNUM
);
901 /* Before reload, there are a few registers that must be forced
902 live everywhere -- which might not already be the case for
903 blocks within infinite loops. */
904 if (!reload_completed
)
906 /* Any reference to any pseudo before reload is a potential
907 reference of the frame pointer. */
908 bitmap_set_bit (&df
->hardware_regs_used
, FRAME_POINTER_REGNUM
);
910 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
911 /* Pseudos with argument area equivalences may require
912 reloading via the argument pointer. */
913 if (fixed_regs
[ARG_POINTER_REGNUM
])
914 bitmap_set_bit (&df
->hardware_regs_used
, ARG_POINTER_REGNUM
);
917 /* Any constant, or pseudo with constant equivalences, may
918 require reloading from memory using the pic register. */
919 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
920 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
921 bitmap_set_bit (&df
->hardware_regs_used
, PIC_OFFSET_TABLE_REGNUM
);
924 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
926 if (bb_index
== EXIT_BLOCK
)
928 /* The exit block is special for this problem and its bits are
929 computed from thin air. */
930 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (EXIT_BLOCK
);
931 bitmap_copy (&bb_info
->use
, df
->exit_block_uses
);
934 df_lr_bb_local_compute (bb_index
);
937 bitmap_clear (df_lr
->out_of_date_transfer_functions
);
941 /* Initialize the solution vectors. */
944 df_lr_init (bitmap all_blocks
)
946 unsigned int bb_index
;
949 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
951 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
952 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
953 bitmap_clear (&bb_info
->out
);
958 /* Confluence function that processes infinite loops. This might be a
959 noreturn function that throws. And even if it isn't, getting the
960 unwind info right helps debugging. */
962 df_lr_confluence_0 (basic_block bb
)
964 bitmap op1
= &df_lr_get_bb_info (bb
->index
)->out
;
965 if (bb
!= EXIT_BLOCK_PTR
)
966 bitmap_copy (op1
, &df
->hardware_regs_used
);
970 /* Confluence function that ignores fake edges. */
973 df_lr_confluence_n (edge e
)
975 bitmap op1
= &df_lr_get_bb_info (e
->src
->index
)->out
;
976 bitmap op2
= &df_lr_get_bb_info (e
->dest
->index
)->in
;
977 bool changed
= false;
979 /* Call-clobbered registers die across exception and call edges. */
980 /* ??? Abnormal call edges ignored for the moment, as this gets
981 confused by sibling call edges, which crashes reg-stack. */
982 if (e
->flags
& EDGE_EH
)
983 changed
= bitmap_ior_and_compl_into (op1
, op2
, regs_invalidated_by_call_regset
);
985 changed
= bitmap_ior_into (op1
, op2
);
987 changed
|= bitmap_ior_into (op1
, &df
->hardware_regs_used
);
992 /* Transfer function. */
995 df_lr_transfer_function (int bb_index
)
997 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
998 bitmap in
= &bb_info
->in
;
999 bitmap out
= &bb_info
->out
;
1000 bitmap use
= &bb_info
->use
;
1001 bitmap def
= &bb_info
->def
;
1003 return bitmap_ior_and_compl (in
, use
, out
, def
);
1007 /* Run the fast dce as a side effect of building LR. */
1010 df_lr_finalize (bitmap all_blocks
)
1012 df_lr
->solutions_dirty
= false;
1013 if (df
->changeable_flags
& DF_LR_RUN_DCE
)
1017 /* If dce deletes some instructions, we need to recompute the lr
1018 solution before proceeding further. The problem is that fast
1019 dce is a pessimestic dataflow algorithm. In the case where
1020 it deletes a statement S inside of a loop, the uses inside of
1021 S may not be deleted from the dataflow solution because they
1022 were carried around the loop. While it is conservatively
1023 correct to leave these extra bits, the standards of df
1024 require that we maintain the best possible (least fixed
1025 point) solution. The only way to do that is to redo the
1026 iteration from the beginning. See PR35805 for an
1028 if (df_lr
->solutions_dirty
)
1030 df_clear_flags (DF_LR_RUN_DCE
);
1031 df_lr_alloc (all_blocks
);
1032 df_lr_local_compute (all_blocks
);
1033 df_worklist_dataflow (df_lr
, all_blocks
, df
->postorder
, df
->n_blocks
);
1034 df_lr_finalize (all_blocks
);
1035 df_set_flags (DF_LR_RUN_DCE
);
1041 /* Free all storage associated with the problem. */
1046 struct df_lr_problem_data
*problem_data
1047 = (struct df_lr_problem_data
*) df_lr
->problem_data
;
1048 if (df_lr
->block_info
)
1051 df_lr
->block_info_size
= 0;
1052 free (df_lr
->block_info
);
1053 df_lr
->block_info
= NULL
;
1054 bitmap_obstack_release (&problem_data
->lr_bitmaps
);
1055 free (df_lr
->problem_data
);
1056 df_lr
->problem_data
= NULL
;
1059 BITMAP_FREE (df_lr
->out_of_date_transfer_functions
);
1064 /* Debugging info at top of bb. */
1067 df_lr_top_dump (basic_block bb
, FILE *file
)
1069 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1070 struct df_lr_problem_data
*problem_data
;
1074 fprintf (file
, ";; lr in \t");
1075 df_print_regset (file
, &bb_info
->in
);
1076 if (df_lr
->problem_data
)
1078 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1079 if (problem_data
->in
)
1081 fprintf (file
, ";; old in \t");
1082 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1085 fprintf (file
, ";; lr use \t");
1086 df_print_regset (file
, &bb_info
->use
);
1087 fprintf (file
, ";; lr def \t");
1088 df_print_regset (file
, &bb_info
->def
);
1092 /* Debugging info at bottom of bb. */
1095 df_lr_bottom_dump (basic_block bb
, FILE *file
)
1097 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1098 struct df_lr_problem_data
*problem_data
;
1102 fprintf (file
, ";; lr out \t");
1103 df_print_regset (file
, &bb_info
->out
);
1104 if (df_lr
->problem_data
)
1106 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1107 if (problem_data
->out
)
1109 fprintf (file
, ";; old out \t");
1110 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1116 /* Build the datastructure to verify that the solution to the dataflow
1117 equations is not dirty. */
1120 df_lr_verify_solution_start (void)
1123 struct df_lr_problem_data
*problem_data
;
1124 if (df_lr
->solutions_dirty
)
1127 /* Set it true so that the solution is recomputed. */
1128 df_lr
->solutions_dirty
= true;
1130 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1131 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block
);
1132 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block
);
1136 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->lr_bitmaps
);
1137 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->lr_bitmaps
);
1138 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
));
1139 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
));
1144 /* Compare the saved datastructure and the new solution to the dataflow
1148 df_lr_verify_solution_end (void)
1150 struct df_lr_problem_data
*problem_data
;
1153 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1155 if (!problem_data
->out
)
1158 if (df_lr
->solutions_dirty
)
1159 /* Do not check if the solution is still dirty. See the comment
1160 in df_lr_finalize for details. */
1161 df_lr
->solutions_dirty
= false;
1165 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
)))
1166 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
))))
1168 /*df_dump (stderr);*/
1173 /* Cannot delete them immediately because you may want to dump them
1174 if the comparison fails. */
1177 bitmap_clear (&problem_data
->in
[bb
->index
]);
1178 bitmap_clear (&problem_data
->out
[bb
->index
]);
1181 free (problem_data
->in
);
1182 free (problem_data
->out
);
1183 problem_data
->in
= NULL
;
1184 problem_data
->out
= NULL
;
1188 /* All of the information associated with every instance of the problem. */
1190 static struct df_problem problem_LR
=
1192 DF_LR
, /* Problem id. */
1193 DF_BACKWARD
, /* Direction. */
1194 df_lr_alloc
, /* Allocate the problem specific data. */
1195 df_lr_reset
, /* Reset global information. */
1196 df_lr_free_bb_info
, /* Free basic block info. */
1197 df_lr_local_compute
, /* Local compute function. */
1198 df_lr_init
, /* Init the solution specific data. */
1199 df_worklist_dataflow
, /* Worklist solver. */
1200 df_lr_confluence_0
, /* Confluence operator 0. */
1201 df_lr_confluence_n
, /* Confluence operator n. */
1202 df_lr_transfer_function
, /* Transfer function. */
1203 df_lr_finalize
, /* Finalize function. */
1204 df_lr_free
, /* Free all of the problem information. */
1205 NULL
, /* Remove this problem from the stack of dataflow problems. */
1206 NULL
, /* Debugging. */
1207 df_lr_top_dump
, /* Debugging start block. */
1208 df_lr_bottom_dump
, /* Debugging end block. */
1209 df_lr_verify_solution_start
,/* Incremental solution verify start. */
1210 df_lr_verify_solution_end
, /* Incremental solution verify end. */
1211 NULL
, /* Dependent problem. */
1212 sizeof (struct df_lr_bb_info
),/* Size of entry of block_info array. */
1213 TV_DF_LR
, /* Timing variable. */
1214 false /* Reset blocks on dropping out of blocks_to_analyze. */
1218 /* Create a new DATAFLOW instance and add it to an existing instance
1219 of DF. The returned structure is what is used to get at the
1223 df_lr_add_problem (void)
1225 df_add_problem (&problem_LR
);
1226 /* These will be initialized when df_scan_blocks processes each
1228 df_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (NULL
);
1232 /* Verify that all of the lr related info is consistent and
1236 df_lr_verify_transfer_functions (void)
1239 bitmap_head saved_def
;
1240 bitmap_head saved_use
;
1241 bitmap_head all_blocks
;
1246 bitmap_initialize (&saved_def
, &bitmap_default_obstack
);
1247 bitmap_initialize (&saved_use
, &bitmap_default_obstack
);
1248 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1252 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1253 bitmap_set_bit (&all_blocks
, bb
->index
);
1257 /* Make a copy of the transfer functions and then compute
1258 new ones to see if the transfer functions have
1260 if (!bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1263 bitmap_copy (&saved_def
, &bb_info
->def
);
1264 bitmap_copy (&saved_use
, &bb_info
->use
);
1265 bitmap_clear (&bb_info
->def
);
1266 bitmap_clear (&bb_info
->use
);
1268 df_lr_bb_local_compute (bb
->index
);
1269 gcc_assert (bitmap_equal_p (&saved_def
, &bb_info
->def
));
1270 gcc_assert (bitmap_equal_p (&saved_use
, &bb_info
->use
));
1275 /* If we do not have basic block info, the block must be in
1276 the list of dirty blocks or else some one has added a
1277 block behind our backs. */
1278 gcc_assert (bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1281 /* Make sure no one created a block without following
1283 gcc_assert (df_scan_get_bb_info (bb
->index
));
1286 /* Make sure there are no dirty bits in blocks that have been deleted. */
1287 gcc_assert (!bitmap_intersect_compl_p (df_lr
->out_of_date_transfer_functions
,
1290 bitmap_clear (&saved_def
);
1291 bitmap_clear (&saved_use
);
1292 bitmap_clear (&all_blocks
);
1297 /*----------------------------------------------------------------------------
1298 LIVE AND MUST-INITIALIZED REGISTERS.
1300 This problem first computes the IN and OUT bitvectors for the
1301 must-initialized registers problems, which is a forward problem.
1302 It gives the set of registers for which we MUST have an available
1303 definition on any path from the entry block to the entry/exit of
1304 a basic block. Sets generate a definition, while clobbers kill
1307 In and out bitvectors are built for each basic block and are indexed by
1308 regnum (see df.h for details). In and out bitvectors in struct
1309 df_live_bb_info actually refers to the must-initialized problem;
1311 Then, the in and out sets for the LIVE problem itself are computed.
1312 These are the logical AND of the IN and OUT sets from the LR problem
1313 and the must-initialized problem.
1314 ----------------------------------------------------------------------------*/
1316 /* Private data used to verify the solution for this problem. */
1317 struct df_live_problem_data
1321 /* An obstack for the bitmaps we need for this problem. */
1322 bitmap_obstack live_bitmaps
;
1325 /* Scratch var used by transfer functions. This is used to implement
1326 an optimization to reduce the amount of space used to compute the
1327 combined lr and live analysis. */
1328 static bitmap_head df_live_scratch
;
1331 /* Free basic block info. */
1334 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
1337 struct df_live_bb_info
*bb_info
= (struct df_live_bb_info
*) vbb_info
;
1340 bitmap_clear (&bb_info
->gen
);
1341 bitmap_clear (&bb_info
->kill
);
1342 bitmap_clear (&bb_info
->in
);
1343 bitmap_clear (&bb_info
->out
);
1348 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1349 not touched unless the block is new. */
1352 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
1354 unsigned int bb_index
;
1356 struct df_live_problem_data
*problem_data
;
1358 if (df_live
->problem_data
)
1359 problem_data
= (struct df_live_problem_data
*) df_live
->problem_data
;
1362 problem_data
= XNEW (struct df_live_problem_data
);
1363 df_live
->problem_data
= problem_data
;
1365 problem_data
->out
= NULL
;
1366 problem_data
->in
= NULL
;
1367 bitmap_obstack_initialize (&problem_data
->live_bitmaps
);
1368 bitmap_initialize (&df_live_scratch
, &problem_data
->live_bitmaps
);
1371 df_grow_bb_info (df_live
);
1373 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1375 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1377 /* When bitmaps are already initialized, just clear them. */
1378 if (bb_info
->kill
.obstack
)
1380 bitmap_clear (&bb_info
->kill
);
1381 bitmap_clear (&bb_info
->gen
);
1385 bitmap_initialize (&bb_info
->kill
, &problem_data
->live_bitmaps
);
1386 bitmap_initialize (&bb_info
->gen
, &problem_data
->live_bitmaps
);
1387 bitmap_initialize (&bb_info
->in
, &problem_data
->live_bitmaps
);
1388 bitmap_initialize (&bb_info
->out
, &problem_data
->live_bitmaps
);
1391 df_live
->optional_p
= (optimize
<= 1);
1395 /* Reset the global solution for recalculation. */
1398 df_live_reset (bitmap all_blocks
)
1400 unsigned int bb_index
;
1403 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1405 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1406 gcc_assert (bb_info
);
1407 bitmap_clear (&bb_info
->in
);
1408 bitmap_clear (&bb_info
->out
);
1413 /* Compute local uninitialized register info for basic block BB. */
1416 df_live_bb_local_compute (unsigned int bb_index
)
1418 basic_block bb
= BASIC_BLOCK (bb_index
);
1419 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1424 FOR_BB_INSNS (bb
, insn
)
1426 unsigned int uid
= INSN_UID (insn
);
1427 struct df_insn_info
*insn_info
= DF_INSN_UID_GET (uid
);
1429 /* Inserting labels does not always trigger the incremental
1433 gcc_assert (!INSN_P (insn
));
1434 insn_info
= df_insn_create_insn_record (insn
);
1437 DF_INSN_INFO_LUID (insn_info
) = luid
;
1442 for (def_rec
= DF_INSN_INFO_DEFS (insn_info
); *def_rec
; def_rec
++)
1444 df_ref def
= *def_rec
;
1445 unsigned int regno
= DF_REF_REGNO (def
);
1447 if (DF_REF_FLAGS_IS_SET (def
,
1448 DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
1449 /* All partial or conditional def
1450 seen are included in the gen set. */
1451 bitmap_set_bit (&bb_info
->gen
, regno
);
1452 else if (DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
))
1453 /* Only must clobbers for the entire reg destroy the
1455 bitmap_set_bit (&bb_info
->kill
, regno
);
1456 else if (! DF_REF_FLAGS_IS_SET (def
, DF_REF_MAY_CLOBBER
))
1457 bitmap_set_bit (&bb_info
->gen
, regno
);
1461 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
1463 df_ref def
= *def_rec
;
1464 bitmap_set_bit (&bb_info
->gen
, DF_REF_REGNO (def
));
1469 /* Compute local uninitialized register info. */
1472 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
1474 unsigned int bb_index
;
1477 df_grow_insn_info ();
1479 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
,
1482 df_live_bb_local_compute (bb_index
);
1485 bitmap_clear (df_live
->out_of_date_transfer_functions
);
1489 /* Initialize the solution vectors. */
1492 df_live_init (bitmap all_blocks
)
1494 unsigned int bb_index
;
1497 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1499 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1500 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1502 /* No register may reach a location where it is not used. Thus
1503 we trim the rr result to the places where it is used. */
1504 bitmap_and (&bb_info
->out
, &bb_info
->gen
, &bb_lr_info
->out
);
1505 bitmap_clear (&bb_info
->in
);
1509 /* Forward confluence function that ignores fake edges. */
1512 df_live_confluence_n (edge e
)
1514 bitmap op1
= &df_live_get_bb_info (e
->dest
->index
)->in
;
1515 bitmap op2
= &df_live_get_bb_info (e
->src
->index
)->out
;
1517 if (e
->flags
& EDGE_FAKE
)
1520 return bitmap_ior_into (op1
, op2
);
1524 /* Transfer function for the forwards must-initialized problem. */
1527 df_live_transfer_function (int bb_index
)
1529 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1530 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1531 bitmap in
= &bb_info
->in
;
1532 bitmap out
= &bb_info
->out
;
1533 bitmap gen
= &bb_info
->gen
;
1534 bitmap kill
= &bb_info
->kill
;
1536 /* We need to use a scratch set here so that the value returned from this
1537 function invocation properly reflects whether the sets changed in a
1538 significant way; i.e. not just because the lr set was anded in. */
1539 bitmap_and (&df_live_scratch
, gen
, &bb_lr_info
->out
);
1540 /* No register may reach a location where it is not used. Thus
1541 we trim the rr result to the places where it is used. */
1542 bitmap_and_into (in
, &bb_lr_info
->in
);
1544 return bitmap_ior_and_compl (out
, &df_live_scratch
, in
, kill
);
1548 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1551 df_live_finalize (bitmap all_blocks
)
1554 if (df_live
->solutions_dirty
)
1557 unsigned int bb_index
;
1559 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1561 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1562 struct df_live_bb_info
*bb_live_info
= df_live_get_bb_info (bb_index
);
1564 /* No register may reach a location where it is not used. Thus
1565 we trim the rr result to the places where it is used. */
1566 bitmap_and_into (&bb_live_info
->in
, &bb_lr_info
->in
);
1567 bitmap_and_into (&bb_live_info
->out
, &bb_lr_info
->out
);
1570 df_live
->solutions_dirty
= false;
1575 /* Free all storage associated with the problem. */
1580 struct df_live_problem_data
*problem_data
1581 = (struct df_live_problem_data
*) df_live
->problem_data
;
1582 if (df_live
->block_info
)
1584 df_live
->block_info_size
= 0;
1585 free (df_live
->block_info
);
1586 df_live
->block_info
= NULL
;
1587 bitmap_clear (&df_live_scratch
);
1588 bitmap_obstack_release (&problem_data
->live_bitmaps
);
1589 free (problem_data
);
1590 df_live
->problem_data
= NULL
;
1592 BITMAP_FREE (df_live
->out_of_date_transfer_functions
);
1597 /* Debugging info at top of bb. */
1600 df_live_top_dump (basic_block bb
, FILE *file
)
1602 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1603 struct df_live_problem_data
*problem_data
;
1608 fprintf (file
, ";; live in \t");
1609 df_print_regset (file
, &bb_info
->in
);
1610 if (df_live
->problem_data
)
1612 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1613 if (problem_data
->in
)
1615 fprintf (file
, ";; old in \t");
1616 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1619 fprintf (file
, ";; live gen \t");
1620 df_print_regset (file
, &bb_info
->gen
);
1621 fprintf (file
, ";; live kill\t");
1622 df_print_regset (file
, &bb_info
->kill
);
1626 /* Debugging info at bottom of bb. */
1629 df_live_bottom_dump (basic_block bb
, FILE *file
)
1631 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1632 struct df_live_problem_data
*problem_data
;
1637 fprintf (file
, ";; live out \t");
1638 df_print_regset (file
, &bb_info
->out
);
1639 if (df_live
->problem_data
)
1641 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1642 if (problem_data
->out
)
1644 fprintf (file
, ";; old out \t");
1645 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1651 /* Build the datastructure to verify that the solution to the dataflow
1652 equations is not dirty. */
1655 df_live_verify_solution_start (void)
1658 struct df_live_problem_data
*problem_data
;
1659 if (df_live
->solutions_dirty
)
1662 /* Set it true so that the solution is recomputed. */
1663 df_live
->solutions_dirty
= true;
1665 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1666 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block
);
1667 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block
);
1671 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->live_bitmaps
);
1672 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->live_bitmaps
);
1673 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
));
1674 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
));
1679 /* Compare the saved datastructure and the new solution to the dataflow
1683 df_live_verify_solution_end (void)
1685 struct df_live_problem_data
*problem_data
;
1688 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1689 if (!problem_data
->out
)
1694 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
)))
1695 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
))))
1697 /*df_dump (stderr);*/
1702 /* Cannot delete them immediately because you may want to dump them
1703 if the comparison fails. */
1706 bitmap_clear (&problem_data
->in
[bb
->index
]);
1707 bitmap_clear (&problem_data
->out
[bb
->index
]);
1710 free (problem_data
->in
);
1711 free (problem_data
->out
);
1712 free (problem_data
);
1713 df_live
->problem_data
= NULL
;
1717 /* All of the information associated with every instance of the problem. */
1719 static struct df_problem problem_LIVE
=
1721 DF_LIVE
, /* Problem id. */
1722 DF_FORWARD
, /* Direction. */
1723 df_live_alloc
, /* Allocate the problem specific data. */
1724 df_live_reset
, /* Reset global information. */
1725 df_live_free_bb_info
, /* Free basic block info. */
1726 df_live_local_compute
, /* Local compute function. */
1727 df_live_init
, /* Init the solution specific data. */
1728 df_worklist_dataflow
, /* Worklist solver. */
1729 NULL
, /* Confluence operator 0. */
1730 df_live_confluence_n
, /* Confluence operator n. */
1731 df_live_transfer_function
, /* Transfer function. */
1732 df_live_finalize
, /* Finalize function. */
1733 df_live_free
, /* Free all of the problem information. */
1734 df_live_free
, /* Remove this problem from the stack of dataflow problems. */
1735 NULL
, /* Debugging. */
1736 df_live_top_dump
, /* Debugging start block. */
1737 df_live_bottom_dump
, /* Debugging end block. */
1738 df_live_verify_solution_start
,/* Incremental solution verify start. */
1739 df_live_verify_solution_end
, /* Incremental solution verify end. */
1740 &problem_LR
, /* Dependent problem. */
1741 sizeof (struct df_live_bb_info
),/* Size of entry of block_info array. */
1742 TV_DF_LIVE
, /* Timing variable. */
1743 false /* Reset blocks on dropping out of blocks_to_analyze. */
1747 /* Create a new DATAFLOW instance and add it to an existing instance
1748 of DF. The returned structure is what is used to get at the
1752 df_live_add_problem (void)
1754 df_add_problem (&problem_LIVE
);
1755 /* These will be initialized when df_scan_blocks processes each
1757 df_live
->out_of_date_transfer_functions
= BITMAP_ALLOC (NULL
);
1761 /* Set all of the blocks as dirty. This needs to be done if this
1762 problem is added after all of the insns have been scanned. */
1765 df_live_set_all_dirty (void)
1769 bitmap_set_bit (df_live
->out_of_date_transfer_functions
,
1774 /* Verify that all of the lr related info is consistent and
1778 df_live_verify_transfer_functions (void)
1781 bitmap_head saved_gen
;
1782 bitmap_head saved_kill
;
1783 bitmap_head all_blocks
;
1788 bitmap_initialize (&saved_gen
, &bitmap_default_obstack
);
1789 bitmap_initialize (&saved_kill
, &bitmap_default_obstack
);
1790 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1792 df_grow_insn_info ();
1796 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1797 bitmap_set_bit (&all_blocks
, bb
->index
);
1801 /* Make a copy of the transfer functions and then compute
1802 new ones to see if the transfer functions have
1804 if (!bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1807 bitmap_copy (&saved_gen
, &bb_info
->gen
);
1808 bitmap_copy (&saved_kill
, &bb_info
->kill
);
1809 bitmap_clear (&bb_info
->gen
);
1810 bitmap_clear (&bb_info
->kill
);
1812 df_live_bb_local_compute (bb
->index
);
1813 gcc_assert (bitmap_equal_p (&saved_gen
, &bb_info
->gen
));
1814 gcc_assert (bitmap_equal_p (&saved_kill
, &bb_info
->kill
));
1819 /* If we do not have basic block info, the block must be in
1820 the list of dirty blocks or else some one has added a
1821 block behind our backs. */
1822 gcc_assert (bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1825 /* Make sure no one created a block without following
1827 gcc_assert (df_scan_get_bb_info (bb
->index
));
1830 /* Make sure there are no dirty bits in blocks that have been deleted. */
1831 gcc_assert (!bitmap_intersect_compl_p (df_live
->out_of_date_transfer_functions
,
1833 bitmap_clear (&saved_gen
);
1834 bitmap_clear (&saved_kill
);
1835 bitmap_clear (&all_blocks
);
1838 /*----------------------------------------------------------------------------
1839 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1841 Link either the defs to the uses and / or the uses to the defs.
1843 These problems are set up like the other dataflow problems so that
1844 they nicely fit into the framework. They are much simpler and only
1845 involve a single traversal of instructions and an examination of
1846 the reaching defs information (the dependent problem).
1847 ----------------------------------------------------------------------------*/
1849 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1851 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1854 df_chain_create (df_ref src
, df_ref dst
)
1856 struct df_link
*head
= DF_REF_CHAIN (src
);
1857 struct df_link
*link
= (struct df_link
*) pool_alloc (df_chain
->block_pool
);
1859 DF_REF_CHAIN (src
) = link
;
1866 /* Delete any du or ud chains that start at REF and point to
1869 df_chain_unlink_1 (df_ref ref
, df_ref target
)
1871 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1872 struct df_link
*prev
= NULL
;
1876 if (chain
->ref
== target
)
1879 prev
->next
= chain
->next
;
1881 DF_REF_CHAIN (ref
) = chain
->next
;
1882 pool_free (df_chain
->block_pool
, chain
);
1886 chain
= chain
->next
;
1891 /* Delete a du or ud chain that leave or point to REF. */
1894 df_chain_unlink (df_ref ref
)
1896 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1899 struct df_link
*next
= chain
->next
;
1900 /* Delete the other side if it exists. */
1901 df_chain_unlink_1 (chain
->ref
, ref
);
1902 pool_free (df_chain
->block_pool
, chain
);
1905 DF_REF_CHAIN (ref
) = NULL
;
1909 /* Copy the du or ud chain starting at FROM_REF and attach it to
1913 df_chain_copy (df_ref to_ref
,
1914 struct df_link
*from_ref
)
1918 df_chain_create (to_ref
, from_ref
->ref
);
1919 from_ref
= from_ref
->next
;
1924 /* Remove this problem from the stack of dataflow problems. */
1927 df_chain_remove_problem (void)
1930 unsigned int bb_index
;
1932 /* Wholesale destruction of the old chains. */
1933 if (df_chain
->block_pool
)
1934 free_alloc_pool (df_chain
->block_pool
);
1936 EXECUTE_IF_SET_IN_BITMAP (df_chain
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1941 basic_block bb
= BASIC_BLOCK (bb_index
);
1943 if (df_chain_problem_p (DF_DU_CHAIN
))
1944 for (def_rec
= df_get_artificial_defs (bb
->index
); *def_rec
; def_rec
++)
1945 DF_REF_CHAIN (*def_rec
) = NULL
;
1946 if (df_chain_problem_p (DF_UD_CHAIN
))
1947 for (use_rec
= df_get_artificial_uses (bb
->index
); *use_rec
; use_rec
++)
1948 DF_REF_CHAIN (*use_rec
) = NULL
;
1950 FOR_BB_INSNS (bb
, insn
)
1952 unsigned int uid
= INSN_UID (insn
);
1956 if (df_chain_problem_p (DF_DU_CHAIN
))
1957 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
1958 DF_REF_CHAIN (*def_rec
) = NULL
;
1959 if (df_chain_problem_p (DF_UD_CHAIN
))
1961 for (use_rec
= DF_INSN_UID_USES (uid
); *use_rec
; use_rec
++)
1962 DF_REF_CHAIN (*use_rec
) = NULL
;
1963 for (use_rec
= DF_INSN_UID_EQ_USES (uid
); *use_rec
; use_rec
++)
1964 DF_REF_CHAIN (*use_rec
) = NULL
;
1970 bitmap_clear (df_chain
->out_of_date_transfer_functions
);
1971 df_chain
->block_pool
= NULL
;
1975 /* Remove the chain problem completely. */
1978 df_chain_fully_remove_problem (void)
1980 df_chain_remove_problem ();
1981 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
1986 /* Create def-use or use-def chains. */
1989 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
1991 df_chain_remove_problem ();
1992 df_chain
->block_pool
= create_alloc_pool ("df_chain_block pool",
1993 sizeof (struct df_link
), 50);
1994 df_chain
->optional_p
= true;
1998 /* Reset all of the chains when the set of basic blocks changes. */
2001 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED
)
2003 df_chain_remove_problem ();
2007 /* Create the chains for a list of USEs. */
2010 df_chain_create_bb_process_use (bitmap local_rd
,
2015 unsigned int def_index
;
2019 df_ref use
= *use_rec
;
2020 unsigned int uregno
= DF_REF_REGNO (use
);
2021 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2022 || (uregno
>= FIRST_PSEUDO_REGISTER
))
2024 /* Do not want to go through this for an uninitialized var. */
2025 int count
= DF_DEFS_COUNT (uregno
);
2028 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2030 unsigned int first_index
= DF_DEFS_BEGIN (uregno
);
2031 unsigned int last_index
= first_index
+ count
- 1;
2033 EXECUTE_IF_SET_IN_BITMAP (local_rd
, first_index
, def_index
, bi
)
2036 if (def_index
> last_index
)
2039 def
= DF_DEFS_GET (def_index
);
2040 if (df_chain_problem_p (DF_DU_CHAIN
))
2041 df_chain_create (def
, use
);
2042 if (df_chain_problem_p (DF_UD_CHAIN
))
2043 df_chain_create (use
, def
);
2054 /* Create chains from reaching defs bitmaps for basic block BB. */
2057 df_chain_create_bb (unsigned int bb_index
)
2059 basic_block bb
= BASIC_BLOCK (bb_index
);
2060 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
2064 bitmap_initialize (&cpy
, &bitmap_default_obstack
);
2065 bitmap_copy (&cpy
, &bb_info
->in
);
2066 bitmap_set_bit (df_chain
->out_of_date_transfer_functions
, bb_index
);
2068 /* Since we are going forwards, process the artificial uses first
2069 then the artificial defs second. */
2072 /* Create the chains for the artificial uses from the EH_USES at the
2073 beginning of the block. */
2075 /* Artificials are only hard regs. */
2076 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2077 df_chain_create_bb_process_use (&cpy
,
2078 df_get_artificial_uses (bb
->index
),
2082 df_rd_simulate_artificial_defs_at_top (bb
, &cpy
);
2084 /* Process the regular instructions next. */
2085 FOR_BB_INSNS (bb
, insn
)
2088 unsigned int uid
= INSN_UID (insn
);
2090 /* First scan the uses and link them up with the defs that remain
2091 in the cpy vector. */
2092 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_USES (uid
), 0);
2093 if (df
->changeable_flags
& DF_EQ_NOTES
)
2094 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_EQ_USES (uid
), 0);
2096 /* Since we are going forwards, process the defs second. */
2097 df_rd_simulate_one_insn (bb
, insn
, &cpy
);
2100 /* Create the chains for the artificial uses of the hard registers
2101 at the end of the block. */
2102 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2103 df_chain_create_bb_process_use (&cpy
,
2104 df_get_artificial_uses (bb
->index
),
2107 bitmap_clear (&cpy
);
2110 /* Create def-use chains from reaching use bitmaps for basic blocks
2114 df_chain_finalize (bitmap all_blocks
)
2116 unsigned int bb_index
;
2119 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2121 df_chain_create_bb (bb_index
);
2126 /* Free all storage associated with the problem. */
2129 df_chain_free (void)
2131 free_alloc_pool (df_chain
->block_pool
);
2132 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
2137 /* Debugging info. */
2140 df_chain_top_dump (basic_block bb
, FILE *file
)
2142 if (df_chain_problem_p (DF_DU_CHAIN
))
2145 df_ref
*def_rec
= df_get_artificial_defs (bb
->index
);
2149 fprintf (file
, ";; DU chains for artificial defs\n");
2152 df_ref def
= *def_rec
;
2153 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2154 df_chain_dump (DF_REF_CHAIN (def
), file
);
2155 fprintf (file
, "\n");
2160 FOR_BB_INSNS (bb
, insn
)
2164 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2165 def_rec
= DF_INSN_INFO_DEFS (insn_info
);
2168 fprintf (file
, ";; DU chains for insn luid %d uid %d\n",
2169 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2173 df_ref def
= *def_rec
;
2174 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2175 if (DF_REF_FLAGS (def
) & DF_REF_READ_WRITE
)
2176 fprintf (file
, "read/write ");
2177 df_chain_dump (DF_REF_CHAIN (def
), file
);
2178 fprintf (file
, "\n");
2189 df_chain_bottom_dump (basic_block bb
, FILE *file
)
2191 if (df_chain_problem_p (DF_UD_CHAIN
))
2194 df_ref
*use_rec
= df_get_artificial_uses (bb
->index
);
2198 fprintf (file
, ";; UD chains for artificial uses\n");
2201 df_ref use
= *use_rec
;
2202 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2203 df_chain_dump (DF_REF_CHAIN (use
), file
);
2204 fprintf (file
, "\n");
2209 FOR_BB_INSNS (bb
, insn
)
2213 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2214 df_ref
*eq_use_rec
= DF_INSN_INFO_EQ_USES (insn_info
);
2215 use_rec
= DF_INSN_INFO_USES (insn_info
);
2216 if (*use_rec
|| *eq_use_rec
)
2218 fprintf (file
, ";; UD chains for insn luid %d uid %d\n",
2219 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2223 df_ref use
= *use_rec
;
2224 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2225 if (DF_REF_FLAGS (use
) & DF_REF_READ_WRITE
)
2226 fprintf (file
, "read/write ");
2227 df_chain_dump (DF_REF_CHAIN (use
), file
);
2228 fprintf (file
, "\n");
2233 df_ref use
= *eq_use_rec
;
2234 fprintf (file
, ";; eq_note reg %d ", DF_REF_REGNO (use
));
2235 df_chain_dump (DF_REF_CHAIN (use
), file
);
2236 fprintf (file
, "\n");
2246 static struct df_problem problem_CHAIN
=
2248 DF_CHAIN
, /* Problem id. */
2249 DF_NONE
, /* Direction. */
2250 df_chain_alloc
, /* Allocate the problem specific data. */
2251 df_chain_reset
, /* Reset global information. */
2252 NULL
, /* Free basic block info. */
2253 NULL
, /* Local compute function. */
2254 NULL
, /* Init the solution specific data. */
2255 NULL
, /* Iterative solver. */
2256 NULL
, /* Confluence operator 0. */
2257 NULL
, /* Confluence operator n. */
2258 NULL
, /* Transfer function. */
2259 df_chain_finalize
, /* Finalize function. */
2260 df_chain_free
, /* Free all of the problem information. */
2261 df_chain_fully_remove_problem
,/* Remove this problem from the stack of dataflow problems. */
2262 NULL
, /* Debugging. */
2263 df_chain_top_dump
, /* Debugging start block. */
2264 df_chain_bottom_dump
, /* Debugging end block. */
2265 NULL
, /* Incremental solution verify start. */
2266 NULL
, /* Incremental solution verify end. */
2267 &problem_RD
, /* Dependent problem. */
2268 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
2269 TV_DF_CHAIN
, /* Timing variable. */
2270 false /* Reset blocks on dropping out of blocks_to_analyze. */
2274 /* Create a new DATAFLOW instance and add it to an existing instance
2275 of DF. The returned structure is what is used to get at the
2279 df_chain_add_problem (unsigned int chain_flags
)
2281 df_add_problem (&problem_CHAIN
);
2282 df_chain
->local_flags
= chain_flags
;
2283 df_chain
->out_of_date_transfer_functions
= BITMAP_ALLOC (NULL
);
2286 #undef df_chain_problem_p
2289 /*----------------------------------------------------------------------------
2290 WORD LEVEL LIVE REGISTERS
2292 Find the locations in the function where any use of a pseudo can
2293 reach in the backwards direction. In and out bitvectors are built
2294 for each basic block. We only track pseudo registers that have a
2295 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2296 contain two bits corresponding to each of the subwords.
2298 ----------------------------------------------------------------------------*/
2300 /* Private data used to verify the solution for this problem. */
2301 struct df_word_lr_problem_data
2303 /* An obstack for the bitmaps we need for this problem. */
2304 bitmap_obstack word_lr_bitmaps
;
2308 /* Free basic block info. */
2311 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
2314 struct df_word_lr_bb_info
*bb_info
= (struct df_word_lr_bb_info
*) vbb_info
;
2317 bitmap_clear (&bb_info
->use
);
2318 bitmap_clear (&bb_info
->def
);
2319 bitmap_clear (&bb_info
->in
);
2320 bitmap_clear (&bb_info
->out
);
2325 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2326 not touched unless the block is new. */
2329 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2331 unsigned int bb_index
;
2334 struct df_word_lr_problem_data
*problem_data
2335 = XNEW (struct df_word_lr_problem_data
);
2337 df_word_lr
->problem_data
= problem_data
;
2339 df_grow_bb_info (df_word_lr
);
2341 /* Create the mapping from regnos to slots. This does not change
2342 unless the problem is destroyed and recreated. In particular, if
2343 we end up deleting the only insn that used a subreg, we do not
2344 want to redo the mapping because this would invalidate everything
2347 bitmap_obstack_initialize (&problem_data
->word_lr_bitmaps
);
2350 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, bb
->index
);
2352 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, ENTRY_BLOCK
);
2353 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, EXIT_BLOCK
);
2355 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2357 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2359 /* When bitmaps are already initialized, just clear them. */
2360 if (bb_info
->use
.obstack
)
2362 bitmap_clear (&bb_info
->def
);
2363 bitmap_clear (&bb_info
->use
);
2367 bitmap_initialize (&bb_info
->use
, &problem_data
->word_lr_bitmaps
);
2368 bitmap_initialize (&bb_info
->def
, &problem_data
->word_lr_bitmaps
);
2369 bitmap_initialize (&bb_info
->in
, &problem_data
->word_lr_bitmaps
);
2370 bitmap_initialize (&bb_info
->out
, &problem_data
->word_lr_bitmaps
);
2374 df_word_lr
->optional_p
= true;
2378 /* Reset the global solution for recalculation. */
2381 df_word_lr_reset (bitmap all_blocks
)
2383 unsigned int bb_index
;
2386 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2388 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2389 gcc_assert (bb_info
);
2390 bitmap_clear (&bb_info
->in
);
2391 bitmap_clear (&bb_info
->out
);
2395 /* Examine REF, and if it is for a reg we're interested in, set or
2396 clear the bits corresponding to its subwords from the bitmap
2397 according to IS_SET. LIVE is the bitmap we should update. We do
2398 not track hard regs or pseudos of any size other than 2 *
2400 We return true if we changed the bitmap, or if we encountered a register
2401 we're not tracking. */
2404 df_word_lr_mark_ref (df_ref ref
, bool is_set
, regset live
)
2406 rtx orig_reg
= DF_REF_REG (ref
);
2408 enum machine_mode reg_mode
;
2410 /* Left at -1 for whole accesses. */
2411 int which_subword
= -1;
2412 bool changed
= false;
2414 if (GET_CODE (reg
) == SUBREG
)
2415 reg
= SUBREG_REG (orig_reg
);
2416 regno
= REGNO (reg
);
2417 reg_mode
= GET_MODE (reg
);
2418 if (regno
< FIRST_PSEUDO_REGISTER
2419 || GET_MODE_SIZE (reg_mode
) != 2 * UNITS_PER_WORD
)
2422 if (GET_CODE (orig_reg
) == SUBREG
2423 && df_read_modify_subreg_p (orig_reg
))
2425 gcc_assert (DF_REF_FLAGS_IS_SET (ref
, DF_REF_PARTIAL
));
2426 if (subreg_lowpart_p (orig_reg
))
2433 if (which_subword
!= 1)
2434 changed
|= bitmap_set_bit (live
, regno
* 2);
2435 if (which_subword
!= 0)
2436 changed
|= bitmap_set_bit (live
, regno
* 2 + 1);
2440 if (which_subword
!= 1)
2441 changed
|= bitmap_clear_bit (live
, regno
* 2);
2442 if (which_subword
!= 0)
2443 changed
|= bitmap_clear_bit (live
, regno
* 2 + 1);
2448 /* Compute local live register info for basic block BB. */
2451 df_word_lr_bb_local_compute (unsigned int bb_index
)
2453 basic_block bb
= BASIC_BLOCK (bb_index
);
2454 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2459 /* Ensure that artificial refs don't contain references to pseudos. */
2460 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
2462 df_ref def
= *def_rec
;
2463 gcc_assert (DF_REF_REGNO (def
) < FIRST_PSEUDO_REGISTER
);
2466 for (use_rec
= df_get_artificial_uses (bb_index
); *use_rec
; use_rec
++)
2468 df_ref use
= *use_rec
;
2469 gcc_assert (DF_REF_REGNO (use
) < FIRST_PSEUDO_REGISTER
);
2472 FOR_BB_INSNS_REVERSE (bb
, insn
)
2474 unsigned int uid
= INSN_UID (insn
);
2476 if (!NONDEBUG_INSN_P (insn
))
2478 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
2480 df_ref def
= *def_rec
;
2481 /* If the def is to only part of the reg, it does
2482 not kill the other defs that reach here. */
2483 if (!(DF_REF_FLAGS (def
) & (DF_REF_CONDITIONAL
)))
2485 df_word_lr_mark_ref (def
, true, &bb_info
->def
);
2486 df_word_lr_mark_ref (def
, false, &bb_info
->use
);
2489 for (use_rec
= DF_INSN_UID_USES (uid
); *use_rec
; use_rec
++)
2491 df_ref use
= *use_rec
;
2492 df_word_lr_mark_ref (use
, true, &bb_info
->use
);
2498 /* Compute local live register info for each basic block within BLOCKS. */
2501 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
2503 unsigned int bb_index
;
2506 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2508 if (bb_index
== EXIT_BLOCK
)
2512 EXECUTE_IF_SET_IN_BITMAP (df
->exit_block_uses
, FIRST_PSEUDO_REGISTER
,
2517 df_word_lr_bb_local_compute (bb_index
);
2520 bitmap_clear (df_word_lr
->out_of_date_transfer_functions
);
2524 /* Initialize the solution vectors. */
2527 df_word_lr_init (bitmap all_blocks
)
2529 unsigned int bb_index
;
2532 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2534 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2535 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
2536 bitmap_clear (&bb_info
->out
);
2541 /* Confluence function that ignores fake edges. */
2544 df_word_lr_confluence_n (edge e
)
2546 bitmap op1
= &df_word_lr_get_bb_info (e
->src
->index
)->out
;
2547 bitmap op2
= &df_word_lr_get_bb_info (e
->dest
->index
)->in
;
2549 return bitmap_ior_into (op1
, op2
);
2553 /* Transfer function. */
2556 df_word_lr_transfer_function (int bb_index
)
2558 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2559 bitmap in
= &bb_info
->in
;
2560 bitmap out
= &bb_info
->out
;
2561 bitmap use
= &bb_info
->use
;
2562 bitmap def
= &bb_info
->def
;
2564 return bitmap_ior_and_compl (in
, use
, out
, def
);
2568 /* Free all storage associated with the problem. */
2571 df_word_lr_free (void)
2573 struct df_word_lr_problem_data
*problem_data
2574 = (struct df_word_lr_problem_data
*)df_word_lr
->problem_data
;
2576 if (df_word_lr
->block_info
)
2578 df_word_lr
->block_info_size
= 0;
2579 free (df_word_lr
->block_info
);
2580 df_word_lr
->block_info
= NULL
;
2583 BITMAP_FREE (df_word_lr
->out_of_date_transfer_functions
);
2584 bitmap_obstack_release (&problem_data
->word_lr_bitmaps
);
2585 free (problem_data
);
2590 /* Debugging info at top of bb. */
2593 df_word_lr_top_dump (basic_block bb
, FILE *file
)
2595 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2599 fprintf (file
, ";; blr in \t");
2600 df_print_word_regset (file
, &bb_info
->in
);
2601 fprintf (file
, ";; blr use \t");
2602 df_print_word_regset (file
, &bb_info
->use
);
2603 fprintf (file
, ";; blr def \t");
2604 df_print_word_regset (file
, &bb_info
->def
);
2608 /* Debugging info at bottom of bb. */
2611 df_word_lr_bottom_dump (basic_block bb
, FILE *file
)
2613 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2617 fprintf (file
, ";; blr out \t");
2618 df_print_word_regset (file
, &bb_info
->out
);
2622 /* All of the information associated with every instance of the problem. */
2624 static struct df_problem problem_WORD_LR
=
2626 DF_WORD_LR
, /* Problem id. */
2627 DF_BACKWARD
, /* Direction. */
2628 df_word_lr_alloc
, /* Allocate the problem specific data. */
2629 df_word_lr_reset
, /* Reset global information. */
2630 df_word_lr_free_bb_info
, /* Free basic block info. */
2631 df_word_lr_local_compute
, /* Local compute function. */
2632 df_word_lr_init
, /* Init the solution specific data. */
2633 df_worklist_dataflow
, /* Worklist solver. */
2634 NULL
, /* Confluence operator 0. */
2635 df_word_lr_confluence_n
, /* Confluence operator n. */
2636 df_word_lr_transfer_function
, /* Transfer function. */
2637 NULL
, /* Finalize function. */
2638 df_word_lr_free
, /* Free all of the problem information. */
2639 df_word_lr_free
, /* Remove this problem from the stack of dataflow problems. */
2640 NULL
, /* Debugging. */
2641 df_word_lr_top_dump
, /* Debugging start block. */
2642 df_word_lr_bottom_dump
, /* Debugging end block. */
2643 NULL
, /* Incremental solution verify start. */
2644 NULL
, /* Incremental solution verify end. */
2645 NULL
, /* Dependent problem. */
2646 sizeof (struct df_word_lr_bb_info
),/* Size of entry of block_info array. */
2647 TV_DF_WORD_LR
, /* Timing variable. */
2648 false /* Reset blocks on dropping out of blocks_to_analyze. */
2652 /* Create a new DATAFLOW instance and add it to an existing instance
2653 of DF. The returned structure is what is used to get at the
2657 df_word_lr_add_problem (void)
2659 df_add_problem (&problem_WORD_LR
);
2660 /* These will be initialized when df_scan_blocks processes each
2662 df_word_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (NULL
);
2666 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2667 any bits, which is used by the caller to determine whether a set is
2668 necessary. We also return true if there are other reasons not to delete
2672 df_word_lr_simulate_defs (rtx insn
, bitmap live
)
2674 bool changed
= false;
2676 unsigned int uid
= INSN_UID (insn
);
2678 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
2680 df_ref def
= *def_rec
;
2681 if (DF_REF_FLAGS (def
) & DF_REF_CONDITIONAL
)
2684 changed
|= df_word_lr_mark_ref (*def_rec
, false, live
);
2690 /* Simulate the effects of the uses of INSN on LIVE. */
2693 df_word_lr_simulate_uses (rtx insn
, bitmap live
)
2696 unsigned int uid
= INSN_UID (insn
);
2698 for (use_rec
= DF_INSN_UID_USES (uid
); *use_rec
; use_rec
++)
2699 df_word_lr_mark_ref (*use_rec
, true, live
);
2702 /*----------------------------------------------------------------------------
2703 This problem computes REG_DEAD and REG_UNUSED notes.
2704 ----------------------------------------------------------------------------*/
2707 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2709 df_note
->optional_p
= true;
2712 #ifdef REG_DEAD_DEBUGGING
2714 df_print_note (const char *prefix
, rtx insn
, rtx note
)
2718 fprintf (dump_file
, "%s %d ", prefix
, INSN_UID (insn
));
2719 print_rtl (dump_file
, note
);
2720 fprintf (dump_file
, "\n");
2726 /* After reg-stack, the x86 floating point stack regs are difficult to
2727 analyze because of all of the pushes, pops and rotations. Thus, we
2728 just leave the notes alone. */
2732 df_ignore_stack_reg (int regno
)
2734 return regstack_completed
2735 && IN_RANGE (regno
, FIRST_STACK_REG
, LAST_STACK_REG
);
2739 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED
)
2746 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2747 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
2750 df_kill_notes (rtx insn
)
2752 rtx
*pprev
= ®_NOTES (insn
);
2757 switch (REG_NOTE_KIND (link
))
2760 /* After reg-stack, we need to ignore any unused notes
2761 for the stack registers. */
2762 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2764 pprev
= &XEXP (link
, 1);
2769 rtx next
= XEXP (link
, 1);
2770 #ifdef REG_DEAD_DEBUGGING
2771 df_print_note ("deleting: ", insn
, link
);
2773 free_EXPR_LIST_node (link
);
2774 *pprev
= link
= next
;
2779 /* After reg-stack, we need to ignore any unused notes
2780 for the stack registers. */
2781 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2783 pprev
= &XEXP (link
, 1);
2788 rtx next
= XEXP (link
, 1);
2789 #ifdef REG_DEAD_DEBUGGING
2790 df_print_note ("deleting: ", insn
, link
);
2792 free_EXPR_LIST_node (link
);
2793 *pprev
= link
= next
;
2798 pprev
= &XEXP (link
, 1);
2806 /* Set a NOTE_TYPE note for REG in INSN. */
2809 df_set_note (enum reg_note note_type
, rtx insn
, rtx reg
)
2811 gcc_checking_assert (!DEBUG_INSN_P (insn
));
2812 add_reg_note (insn
, note_type
, reg
);
2815 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2816 arguments. Return true if the register value described by MWS's
2817 mw_reg is known to be completely unused, and if mw_reg can therefore
2818 be used in a REG_UNUSED note. */
2821 df_whole_mw_reg_unused_p (struct df_mw_hardreg
*mws
,
2822 bitmap live
, bitmap artificial_uses
)
2826 /* If MWS describes a partial reference, create REG_UNUSED notes for
2827 individual hard registers. */
2828 if (mws
->flags
& DF_REF_PARTIAL
)
2831 /* Likewise if some part of the register is used. */
2832 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2833 if (bitmap_bit_p (live
, r
)
2834 || bitmap_bit_p (artificial_uses
, r
))
2837 gcc_assert (REG_P (mws
->mw_reg
));
2841 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2842 based on the bits in LIVE. Do not generate notes for registers in
2843 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2844 not generated if the reg is both read and written by the
2849 df_set_unused_notes_for_mw (rtx insn
, struct df_mw_hardreg
*mws
,
2850 bitmap live
, bitmap do_not_gen
,
2851 bitmap artificial_uses
)
2855 #ifdef REG_DEAD_DEBUGGING
2857 fprintf (dump_file
, "mw_set_unused looking at mws[%d..%d]\n",
2858 mws
->start_regno
, mws
->end_regno
);
2861 if (df_whole_mw_reg_unused_p (mws
, live
, artificial_uses
))
2863 unsigned int regno
= mws
->start_regno
;
2864 df_set_note (REG_UNUSED
, insn
, mws
->mw_reg
);
2866 #ifdef REG_DEAD_DEBUGGING
2867 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
2869 bitmap_set_bit (do_not_gen
, regno
);
2870 /* Only do this if the value is totally dead. */
2873 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2875 if (!bitmap_bit_p (live
, r
)
2876 && !bitmap_bit_p (artificial_uses
, r
))
2878 df_set_note (REG_UNUSED
, insn
, regno_reg_rtx
[r
]);
2879 #ifdef REG_DEAD_DEBUGGING
2880 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
2883 bitmap_set_bit (do_not_gen
, r
);
2888 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2889 arguments. Return true if the register value described by MWS's
2890 mw_reg is known to be completely dead, and if mw_reg can therefore
2891 be used in a REG_DEAD note. */
2894 df_whole_mw_reg_dead_p (struct df_mw_hardreg
*mws
,
2895 bitmap live
, bitmap artificial_uses
,
2900 /* If MWS describes a partial reference, create REG_DEAD notes for
2901 individual hard registers. */
2902 if (mws
->flags
& DF_REF_PARTIAL
)
2905 /* Likewise if some part of the register is not dead. */
2906 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2907 if (bitmap_bit_p (live
, r
)
2908 || bitmap_bit_p (artificial_uses
, r
)
2909 || bitmap_bit_p (do_not_gen
, r
))
2912 gcc_assert (REG_P (mws
->mw_reg
));
2916 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2917 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2918 from being set if the instruction both reads and writes the
2922 df_set_dead_notes_for_mw (rtx insn
, struct df_mw_hardreg
*mws
,
2923 bitmap live
, bitmap do_not_gen
,
2924 bitmap artificial_uses
, bool *added_notes_p
)
2927 bool is_debug
= *added_notes_p
;
2929 *added_notes_p
= false;
2931 #ifdef REG_DEAD_DEBUGGING
2934 fprintf (dump_file
, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2935 mws
->start_regno
, mws
->end_regno
);
2936 df_print_regset (dump_file
, do_not_gen
);
2937 fprintf (dump_file
, " live =");
2938 df_print_regset (dump_file
, live
);
2939 fprintf (dump_file
, " artificial uses =");
2940 df_print_regset (dump_file
, artificial_uses
);
2944 if (df_whole_mw_reg_dead_p (mws
, live
, artificial_uses
, do_not_gen
))
2946 /* Add a dead note for the entire multi word register. */
2949 *added_notes_p
= true;
2952 df_set_note (REG_DEAD
, insn
, mws
->mw_reg
);
2953 #ifdef REG_DEAD_DEBUGGING
2954 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
2959 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2960 if (!bitmap_bit_p (live
, r
)
2961 && !bitmap_bit_p (artificial_uses
, r
)
2962 && !bitmap_bit_p (do_not_gen
, r
))
2966 *added_notes_p
= true;
2969 df_set_note (REG_DEAD
, insn
, regno_reg_rtx
[r
]);
2970 #ifdef REG_DEAD_DEBUGGING
2971 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
2979 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
2980 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
2983 df_create_unused_note (rtx insn
, df_ref def
,
2984 bitmap live
, bitmap artificial_uses
)
2986 unsigned int dregno
= DF_REF_REGNO (def
);
2988 #ifdef REG_DEAD_DEBUGGING
2991 fprintf (dump_file
, " regular looking at def ");
2992 df_ref_debug (def
, dump_file
);
2996 if (!((DF_REF_FLAGS (def
) & DF_REF_MW_HARDREG
)
2997 || bitmap_bit_p (live
, dregno
)
2998 || bitmap_bit_p (artificial_uses
, dregno
)
2999 || df_ignore_stack_reg (dregno
)))
3001 rtx reg
= (DF_REF_LOC (def
))
3002 ? *DF_REF_REAL_LOC (def
): DF_REF_REG (def
);
3003 df_set_note (REG_UNUSED
, insn
, reg
);
3004 #ifdef REG_DEAD_DEBUGGING
3005 df_print_note ("adding 3: ", insn
, REG_NOTES (insn
));
3012 /* Node of a linked list of uses of dead REGs in debug insns. */
3013 struct dead_debug_use
3016 struct dead_debug_use
*next
;
3019 /* Linked list of the above, with a bitmap of the REGs in the
3023 struct dead_debug_use
*head
;
3028 /* Initialize DEBUG to an empty list, and clear USED, if given. */
3030 dead_debug_init (struct dead_debug
*debug
, bitmap used
)
3034 debug
->to_rescan
= NULL
;
3036 bitmap_clear (used
);
3039 /* Reset all debug insns with pending uses. Release the bitmap in it,
3040 unless it is USED. USED must be the same bitmap passed to
3043 dead_debug_finish (struct dead_debug
*debug
, bitmap used
)
3045 struct dead_debug_use
*head
;
3048 if (debug
->used
!= used
)
3049 BITMAP_FREE (debug
->used
);
3051 while ((head
= debug
->head
))
3053 insn
= DF_REF_INSN (head
->use
);
3054 if (!head
->next
|| DF_REF_INSN (head
->next
->use
) != insn
)
3056 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
3057 df_insn_rescan_debug_internal (insn
);
3058 if (debug
->to_rescan
)
3059 bitmap_clear_bit (debug
->to_rescan
, INSN_UID (insn
));
3061 debug
->head
= head
->next
;
3065 if (debug
->to_rescan
)
3070 EXECUTE_IF_SET_IN_BITMAP (debug
->to_rescan
, 0, uid
, bi
)
3072 struct df_insn_info
*insn_info
= DF_INSN_UID_SAFE_GET (uid
);
3074 df_insn_rescan (insn_info
->insn
);
3076 BITMAP_FREE (debug
->to_rescan
);
3080 /* Add USE to DEBUG. It must be a dead reference to UREGNO in a debug
3081 insn. Create a bitmap for DEBUG as needed. */
3083 dead_debug_add (struct dead_debug
*debug
, df_ref use
, unsigned int uregno
)
3085 struct dead_debug_use
*newddu
= XNEW (struct dead_debug_use
);
3088 newddu
->next
= debug
->head
;
3089 debug
->head
= newddu
;
3092 debug
->used
= BITMAP_ALLOC (NULL
);
3094 bitmap_set_bit (debug
->used
, uregno
);
3097 /* If UREGNO is referenced by any entry in DEBUG, emit a debug insn
3098 before INSN that binds the REG to a debug temp, and replace all
3099 uses of UREGNO in DEBUG with uses of the debug temp. INSN must be
3100 the insn where UREGNO dies. */
3102 dead_debug_insert_before (struct dead_debug
*debug
, unsigned int uregno
,
3105 struct dead_debug_use
**tailp
= &debug
->head
;
3106 struct dead_debug_use
*cur
;
3107 struct dead_debug_use
*uses
= NULL
;
3108 struct dead_debug_use
**usesp
= &uses
;
3113 if (!debug
->used
|| !bitmap_clear_bit (debug
->used
, uregno
))
3116 /* Move all uses of uregno from debug->head to uses, setting mode to
3117 the widest referenced mode. */
3118 while ((cur
= *tailp
))
3120 if (DF_REF_REGNO (cur
->use
) == uregno
)
3127 || (GET_MODE_BITSIZE (GET_MODE (reg
))
3128 < GET_MODE_BITSIZE (GET_MODE (*DF_REF_REAL_LOC (cur
->use
)))))
3129 reg
= *DF_REF_REAL_LOC (cur
->use
);
3132 tailp
= &(*tailp
)->next
;
3137 /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
3138 dval
= make_debug_expr_from_rtl (reg
);
3140 /* Emit a debug bind insn before the insn in which reg dies. */
3141 bind
= gen_rtx_VAR_LOCATION (GET_MODE (reg
),
3142 DEBUG_EXPR_TREE_DECL (dval
), reg
,
3143 VAR_INIT_STATUS_INITIALIZED
);
3145 bind
= emit_debug_insn_before (bind
, insn
);
3146 df_insn_rescan (bind
);
3148 /* Adjust all uses. */
3149 while ((cur
= uses
))
3151 if (GET_MODE (*DF_REF_REAL_LOC (cur
->use
)) == GET_MODE (reg
))
3152 *DF_REF_REAL_LOC (cur
->use
) = dval
;
3154 *DF_REF_REAL_LOC (cur
->use
)
3155 = gen_lowpart_SUBREG (GET_MODE (*DF_REF_REAL_LOC (cur
->use
)), dval
);
3156 /* ??? Should we simplify subreg of subreg? */
3157 if (debug
->to_rescan
== NULL
)
3158 debug
->to_rescan
= BITMAP_ALLOC (NULL
);
3159 bitmap_set_bit (debug
->to_rescan
, INSN_UID (DF_REF_INSN (cur
->use
)));
3165 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3166 info: lifetime, bb, and number of defs and uses for basic block
3167 BB. The three bitvectors are scratch regs used here. */
3170 df_note_bb_compute (unsigned int bb_index
,
3171 bitmap live
, bitmap do_not_gen
, bitmap artificial_uses
)
3173 basic_block bb
= BASIC_BLOCK (bb_index
);
3177 struct dead_debug debug
;
3179 dead_debug_init (&debug
, NULL
);
3181 bitmap_copy (live
, df_get_live_out (bb
));
3182 bitmap_clear (artificial_uses
);
3184 #ifdef REG_DEAD_DEBUGGING
3187 fprintf (dump_file
, "live at bottom ");
3188 df_print_regset (dump_file
, live
);
3192 /* Process the artificial defs and uses at the bottom of the block
3193 to begin processing. */
3194 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
3196 df_ref def
= *def_rec
;
3197 #ifdef REG_DEAD_DEBUGGING
3199 fprintf (dump_file
, "artificial def %d\n", DF_REF_REGNO (def
));
3202 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3203 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3206 for (use_rec
= df_get_artificial_uses (bb_index
); *use_rec
; use_rec
++)
3208 df_ref use
= *use_rec
;
3209 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3211 unsigned int regno
= DF_REF_REGNO (use
);
3212 bitmap_set_bit (live
, regno
);
3214 /* Notes are not generated for any of the artificial registers
3215 at the bottom of the block. */
3216 bitmap_set_bit (artificial_uses
, regno
);
3220 #ifdef REG_DEAD_DEBUGGING
3223 fprintf (dump_file
, "live before artificials out ");
3224 df_print_regset (dump_file
, live
);
3228 FOR_BB_INSNS_REVERSE (bb
, insn
)
3230 unsigned int uid
= INSN_UID (insn
);
3231 struct df_mw_hardreg
**mws_rec
;
3237 debug_insn
= DEBUG_INSN_P (insn
);
3239 bitmap_clear (do_not_gen
);
3240 df_kill_notes (insn
);
3242 /* Process the defs. */
3245 #ifdef REG_DEAD_DEBUGGING
3248 fprintf (dump_file
, "processing call %d\n live =", INSN_UID (insn
));
3249 df_print_regset (dump_file
, live
);
3252 /* We only care about real sets for calls. Clobbers cannot
3253 be depended on to really die. */
3254 mws_rec
= DF_INSN_UID_MWS (uid
);
3257 struct df_mw_hardreg
*mws
= *mws_rec
;
3258 if ((DF_MWS_REG_DEF_P (mws
))
3259 && !df_ignore_stack_reg (mws
->start_regno
))
3260 df_set_unused_notes_for_mw (insn
,
3261 mws
, live
, do_not_gen
,
3266 /* All of the defs except the return value are some sort of
3267 clobber. This code is for the return. */
3268 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
3270 df_ref def
= *def_rec
;
3271 unsigned int dregno
= DF_REF_REGNO (def
);
3272 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3274 df_create_unused_note (insn
,
3275 def
, live
, artificial_uses
);
3276 bitmap_set_bit (do_not_gen
, dregno
);
3279 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3280 bitmap_clear_bit (live
, dregno
);
3286 mws_rec
= DF_INSN_UID_MWS (uid
);
3289 struct df_mw_hardreg
*mws
= *mws_rec
;
3290 if (DF_MWS_REG_DEF_P (mws
))
3291 df_set_unused_notes_for_mw (insn
,
3292 mws
, live
, do_not_gen
,
3297 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
3299 df_ref def
= *def_rec
;
3300 unsigned int dregno
= DF_REF_REGNO (def
);
3301 df_create_unused_note (insn
,
3302 def
, live
, artificial_uses
);
3304 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3305 bitmap_set_bit (do_not_gen
, dregno
);
3307 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3308 bitmap_clear_bit (live
, dregno
);
3312 /* Process the uses. */
3313 mws_rec
= DF_INSN_UID_MWS (uid
);
3316 struct df_mw_hardreg
*mws
= *mws_rec
;
3317 if ((DF_MWS_REG_DEF_P (mws
))
3318 && !df_ignore_stack_reg (mws
->start_regno
))
3320 bool really_add_notes
= debug_insn
!= 0;
3322 df_set_dead_notes_for_mw (insn
,
3323 mws
, live
, do_not_gen
,
3327 if (really_add_notes
)
3333 for (use_rec
= DF_INSN_UID_USES (uid
); *use_rec
; use_rec
++)
3335 df_ref use
= *use_rec
;
3336 unsigned int uregno
= DF_REF_REGNO (use
);
3338 #ifdef REG_DEAD_DEBUGGING
3339 if (dump_file
&& !debug_insn
)
3341 fprintf (dump_file
, " regular looking at use ");
3342 df_ref_debug (use
, dump_file
);
3345 if (!bitmap_bit_p (live
, uregno
))
3351 dead_debug_add (&debug
, use
, uregno
);
3357 dead_debug_insert_before (&debug
, uregno
, insn
);
3359 if ( (!(DF_REF_FLAGS (use
)
3360 & (DF_REF_MW_HARDREG
| DF_REF_READ_WRITE
)))
3361 && (!bitmap_bit_p (do_not_gen
, uregno
))
3362 && (!bitmap_bit_p (artificial_uses
, uregno
))
3363 && (!df_ignore_stack_reg (uregno
)))
3365 rtx reg
= (DF_REF_LOC (use
))
3366 ? *DF_REF_REAL_LOC (use
) : DF_REF_REG (use
);
3367 df_set_note (REG_DEAD
, insn
, reg
);
3369 #ifdef REG_DEAD_DEBUGGING
3370 df_print_note ("adding 4: ", insn
, REG_NOTES (insn
));
3373 /* This register is now live. */
3374 bitmap_set_bit (live
, uregno
);
3378 if (debug_insn
== -1)
3380 /* ??? We could probably do better here, replacing dead
3381 registers with their definitions. */
3382 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
3383 df_insn_rescan_debug_internal (insn
);
3387 dead_debug_finish (&debug
, NULL
);
3391 /* Compute register info: lifetime, bb, and number of defs and uses. */
3393 df_note_compute (bitmap all_blocks
)
3395 unsigned int bb_index
;
3397 bitmap_head live
, do_not_gen
, artificial_uses
;
3399 bitmap_initialize (&live
, &df_bitmap_obstack
);
3400 bitmap_initialize (&do_not_gen
, &df_bitmap_obstack
);
3401 bitmap_initialize (&artificial_uses
, &df_bitmap_obstack
);
3403 #ifdef REG_DEAD_DEBUGGING
3405 print_rtl_with_bb (dump_file
, get_insns());
3408 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
3410 df_note_bb_compute (bb_index
, &live
, &do_not_gen
, &artificial_uses
);
3413 bitmap_clear (&live
);
3414 bitmap_clear (&do_not_gen
);
3415 bitmap_clear (&artificial_uses
);
3419 /* Free all storage associated with the problem. */
3428 /* All of the information associated every instance of the problem. */
3430 static struct df_problem problem_NOTE
=
3432 DF_NOTE
, /* Problem id. */
3433 DF_NONE
, /* Direction. */
3434 df_note_alloc
, /* Allocate the problem specific data. */
3435 NULL
, /* Reset global information. */
3436 NULL
, /* Free basic block info. */
3437 df_note_compute
, /* Local compute function. */
3438 NULL
, /* Init the solution specific data. */
3439 NULL
, /* Iterative solver. */
3440 NULL
, /* Confluence operator 0. */
3441 NULL
, /* Confluence operator n. */
3442 NULL
, /* Transfer function. */
3443 NULL
, /* Finalize function. */
3444 df_note_free
, /* Free all of the problem information. */
3445 df_note_free
, /* Remove this problem from the stack of dataflow problems. */
3446 NULL
, /* Debugging. */
3447 NULL
, /* Debugging start block. */
3448 NULL
, /* Debugging end block. */
3449 NULL
, /* Incremental solution verify start. */
3450 NULL
, /* Incremental solution verify end. */
3451 &problem_LR
, /* Dependent problem. */
3452 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
3453 TV_DF_NOTE
, /* Timing variable. */
3454 false /* Reset blocks on dropping out of blocks_to_analyze. */
3458 /* Create a new DATAFLOW instance and add it to an existing instance
3459 of DF. The returned structure is what is used to get at the
3463 df_note_add_problem (void)
3465 df_add_problem (&problem_NOTE
);
3471 /*----------------------------------------------------------------------------
3472 Functions for simulating the effects of single insns.
3474 You can either simulate in the forwards direction, starting from
3475 the top of a block or the backwards direction from the end of the
3476 block. If you go backwards, defs are examined first to clear bits,
3477 then uses are examined to set bits. If you go forwards, defs are
3478 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3479 are examined to clear bits. In either case, the result of examining
3480 a def can be undone (respectively by a use or a REG_UNUSED note).
3482 If you start at the top of the block, use one of DF_LIVE_IN or
3483 DF_LR_IN. If you start at the bottom of the block use one of
3484 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3485 THEY WILL BE DESTROYED.
3486 ----------------------------------------------------------------------------*/
3489 /* Find the set of DEFs for INSN. */
3492 df_simulate_find_defs (rtx insn
, bitmap defs
)
3495 unsigned int uid
= INSN_UID (insn
);
3497 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
3499 df_ref def
= *def_rec
;
3500 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3504 /* Find the set of uses for INSN. This includes partial defs. */
3507 df_simulate_find_uses (rtx insn
, bitmap uses
)
3510 unsigned int uid
= INSN_UID (insn
);
3512 for (rec
= DF_INSN_UID_DEFS (uid
); *rec
; rec
++)
3515 if (DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3516 bitmap_set_bit (uses
, DF_REF_REGNO (def
));
3518 for (rec
= DF_INSN_UID_USES (uid
); *rec
; rec
++)
3521 bitmap_set_bit (uses
, DF_REF_REGNO (use
));
3525 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3528 df_simulate_find_noclobber_defs (rtx insn
, bitmap defs
)
3531 unsigned int uid
= INSN_UID (insn
);
3533 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
3535 df_ref def
= *def_rec
;
3536 if (!(DF_REF_FLAGS (def
) & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
3537 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3542 /* Simulate the effects of the defs of INSN on LIVE. */
3545 df_simulate_defs (rtx insn
, bitmap live
)
3548 unsigned int uid
= INSN_UID (insn
);
3550 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
3552 df_ref def
= *def_rec
;
3553 unsigned int dregno
= DF_REF_REGNO (def
);
3555 /* If the def is to only part of the reg, it does
3556 not kill the other defs that reach here. */
3557 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
3558 bitmap_clear_bit (live
, dregno
);
3563 /* Simulate the effects of the uses of INSN on LIVE. */
3566 df_simulate_uses (rtx insn
, bitmap live
)
3569 unsigned int uid
= INSN_UID (insn
);
3571 if (DEBUG_INSN_P (insn
))
3574 for (use_rec
= DF_INSN_UID_USES (uid
); *use_rec
; use_rec
++)
3576 df_ref use
= *use_rec
;
3577 /* Add use to set of uses in this BB. */
3578 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3583 /* Add back the always live regs in BB to LIVE. */
3586 df_simulate_fixup_sets (basic_block bb
, bitmap live
)
3588 /* These regs are considered always live so if they end up dying
3589 because of some def, we need to bring the back again. */
3590 if (bb_has_eh_pred (bb
))
3591 bitmap_ior_into (live
, &df
->eh_block_artificial_uses
);
3593 bitmap_ior_into (live
, &df
->regular_block_artificial_uses
);
3597 /*----------------------------------------------------------------------------
3598 The following three functions are used only for BACKWARDS scanning:
3599 i.e. they process the defs before the uses.
3601 df_simulate_initialize_backwards should be called first with a
3602 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3603 df_simulate_one_insn_backwards should be called for each insn in
3604 the block, starting with the last one. Finally,
3605 df_simulate_finalize_backwards can be called to get a new value
3606 of the sets at the top of the block (this is rarely used).
3607 ----------------------------------------------------------------------------*/
3609 /* Apply the artificial uses and defs at the end of BB in a backwards
3613 df_simulate_initialize_backwards (basic_block bb
, bitmap live
)
3617 int bb_index
= bb
->index
;
3619 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
3621 df_ref def
= *def_rec
;
3622 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3623 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3626 for (use_rec
= df_get_artificial_uses (bb_index
); *use_rec
; use_rec
++)
3628 df_ref use
= *use_rec
;
3629 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3630 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3635 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3638 df_simulate_one_insn_backwards (basic_block bb
, rtx insn
, bitmap live
)
3640 if (!NONDEBUG_INSN_P (insn
))
3643 df_simulate_defs (insn
, live
);
3644 df_simulate_uses (insn
, live
);
3645 df_simulate_fixup_sets (bb
, live
);
3649 /* Apply the artificial uses and defs at the top of BB in a backwards
3653 df_simulate_finalize_backwards (basic_block bb
, bitmap live
)
3659 int bb_index
= bb
->index
;
3661 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
3663 df_ref def
= *def_rec
;
3664 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3665 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3669 for (use_rec
= df_get_artificial_uses (bb_index
); *use_rec
; use_rec
++)
3671 df_ref use
= *use_rec
;
3672 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
3673 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3677 /*----------------------------------------------------------------------------
3678 The following three functions are used only for FORWARDS scanning:
3679 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3680 Thus it is important to add the DF_NOTES problem to the stack of
3681 problems computed before using these functions.
3683 df_simulate_initialize_forwards should be called first with a
3684 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3685 df_simulate_one_insn_forwards should be called for each insn in
3686 the block, starting with the first one.
3687 ----------------------------------------------------------------------------*/
3689 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3690 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3694 df_simulate_initialize_forwards (basic_block bb
, bitmap live
)
3697 int bb_index
= bb
->index
;
3699 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
3701 df_ref def
= *def_rec
;
3702 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3703 bitmap_set_bit (live
, DF_REF_REGNO (def
));
3707 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3710 df_simulate_one_insn_forwards (basic_block bb
, rtx insn
, bitmap live
)
3713 if (! INSN_P (insn
))
3716 /* Make sure that DF_NOTE really is an active df problem. */
3717 gcc_assert (df_note
);
3719 /* Note that this is the opposite as how the problem is defined, because
3720 in the LR problem defs _kill_ liveness. However, they do so backwards,
3721 while here the scan is performed forwards! So, first assume that the
3722 def is live, and if this is not true REG_UNUSED notes will rectify the
3724 df_simulate_find_noclobber_defs (insn
, live
);
3726 /* Clear all of the registers that go dead. */
3727 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
3729 switch (REG_NOTE_KIND (link
))
3734 rtx reg
= XEXP (link
, 0);
3735 int regno
= REGNO (reg
);
3736 if (regno
< FIRST_PSEUDO_REGISTER
)
3738 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3740 bitmap_clear_bit (live
, regno
+ n
);
3743 bitmap_clear_bit (live
, regno
);
3750 df_simulate_fixup_sets (bb
, live
);
3753 /* Used by the next two functions to encode information about the
3754 memory references we found. */
3755 #define MEMREF_NORMAL 1
3756 #define MEMREF_VOLATILE 2
3758 /* A subroutine of can_move_insns_across_p called through for_each_rtx.
3759 Return either MEMREF_NORMAL or MEMREF_VOLATILE if a memory is found. */
3762 find_memory (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
3766 if (GET_CODE (x
) == ASM_OPERANDS
&& MEM_VOLATILE_P (x
))
3767 return MEMREF_VOLATILE
;
3771 if (MEM_VOLATILE_P (x
))
3772 return MEMREF_VOLATILE
;
3773 if (MEM_READONLY_P (x
))
3776 return MEMREF_NORMAL
;
3779 /* A subroutine of can_move_insns_across_p called through note_stores.
3780 DATA points to an integer in which we set either the bit for
3781 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3785 find_memory_stores (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
,
3786 void *data ATTRIBUTE_UNUSED
)
3788 int *pflags
= (int *)data
;
3789 if (GET_CODE (x
) == SUBREG
)
3791 /* Treat stores to SP as stores to memory, this will prevent problems
3792 when there are references to the stack frame. */
3793 if (x
== stack_pointer_rtx
)
3794 *pflags
|= MEMREF_VOLATILE
;
3797 *pflags
|= MEM_VOLATILE_P (x
) ? MEMREF_VOLATILE
: MEMREF_NORMAL
;
3800 /* Scan BB backwards, using df_simulate functions to keep track of
3801 lifetimes, up to insn POINT. The result is stored in LIVE. */
3804 simulate_backwards_to_point (basic_block bb
, regset live
, rtx point
)
3807 bitmap_copy (live
, df_get_live_out (bb
));
3808 df_simulate_initialize_backwards (bb
, live
);
3810 /* Scan and update life information until we reach the point we're
3812 for (insn
= BB_END (bb
); insn
!= point
; insn
= PREV_INSN (insn
))
3813 df_simulate_one_insn_backwards (bb
, insn
, live
);
3816 /* Return true if it is safe to move a group of insns, described by
3817 the range FROM to TO, backwards across another group of insns,
3818 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3819 are no insns between ACROSS_TO and FROM, but they may be in
3820 different basic blocks; MERGE_BB is the block from which the
3821 insns will be moved. The caller must pass in a regset MERGE_LIVE
3822 which specifies the registers live after TO.
3824 This function may be called in one of two cases: either we try to
3825 move identical instructions from all successor blocks into their
3826 predecessor, or we try to move from only one successor block. If
3827 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3828 the second case. It should contain a set of registers live at the
3829 end of ACROSS_TO which must not be clobbered by moving the insns.
3830 In that case, we're also more careful about moving memory references
3833 We return false if it is not safe to move the entire group, but it
3834 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3835 is set to point at the last moveable insn in such a case. */
3838 can_move_insns_across (rtx from
, rtx to
, rtx across_from
, rtx across_to
,
3839 basic_block merge_bb
, regset merge_live
,
3840 regset other_branch_live
, rtx
*pmove_upto
)
3842 rtx insn
, next
, max_to
;
3843 bitmap merge_set
, merge_use
, local_merge_live
;
3844 bitmap test_set
, test_use
;
3845 unsigned i
, fail
= 0;
3847 int memrefs_in_across
= 0;
3848 int mem_sets_in_across
= 0;
3849 bool trapping_insns_in_across
= false;
3851 if (pmove_upto
!= NULL
)
3852 *pmove_upto
= NULL_RTX
;
3854 /* Find real bounds, ignoring debug insns. */
3855 while (!NONDEBUG_INSN_P (from
) && from
!= to
)
3856 from
= NEXT_INSN (from
);
3857 while (!NONDEBUG_INSN_P (to
) && from
!= to
)
3858 to
= PREV_INSN (to
);
3860 for (insn
= across_to
; ; insn
= next
)
3862 if (NONDEBUG_INSN_P (insn
))
3864 memrefs_in_across
|= for_each_rtx (&PATTERN (insn
), find_memory
,
3866 note_stores (PATTERN (insn
), find_memory_stores
,
3867 &mem_sets_in_across
);
3868 /* This is used just to find sets of the stack pointer. */
3869 memrefs_in_across
|= mem_sets_in_across
;
3870 trapping_insns_in_across
|= may_trap_p (PATTERN (insn
));
3872 next
= PREV_INSN (insn
);
3873 if (insn
== across_from
)
3878 MERGE_SET = set of registers set in MERGE_BB
3879 MERGE_USE = set of registers used in MERGE_BB and live at its top
3880 MERGE_LIVE = set of registers live at the point inside the MERGE
3881 range that we've reached during scanning
3882 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3883 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3884 and live before ACROSS_FROM. */
3886 merge_set
= BITMAP_ALLOC (®_obstack
);
3887 merge_use
= BITMAP_ALLOC (®_obstack
);
3888 local_merge_live
= BITMAP_ALLOC (®_obstack
);
3889 test_set
= BITMAP_ALLOC (®_obstack
);
3890 test_use
= BITMAP_ALLOC (®_obstack
);
3892 /* Compute the set of registers set and used in the ACROSS range. */
3893 if (other_branch_live
!= NULL
)
3894 bitmap_copy (test_use
, other_branch_live
);
3895 df_simulate_initialize_backwards (merge_bb
, test_use
);
3896 for (insn
= across_to
; ; insn
= next
)
3898 if (NONDEBUG_INSN_P (insn
))
3900 df_simulate_find_defs (insn
, test_set
);
3901 df_simulate_defs (insn
, test_use
);
3902 df_simulate_uses (insn
, test_use
);
3904 next
= PREV_INSN (insn
);
3905 if (insn
== across_from
)
3909 /* Compute an upper bound for the amount of insns moved, by finding
3910 the first insn in MERGE that sets a register in TEST_USE, or uses
3911 a register in TEST_SET. We also check for calls, trapping operations,
3912 and memory references. */
3914 for (insn
= from
; ; insn
= next
)
3918 if (NONDEBUG_INSN_P (insn
))
3920 if (may_trap_p (PATTERN (insn
))
3921 && (trapping_insns_in_across
|| other_branch_live
!= NULL
))
3924 /* We cannot move memory stores past each other, or move memory
3925 reads past stores, at least not without tracking them and
3926 calling true_dependence on every pair.
3928 If there is no other branch and no memory references or
3929 sets in the ACROSS range, we can move memory references
3930 freely, even volatile ones.
3932 Otherwise, the rules are as follows: volatile memory
3933 references and stores can't be moved at all, and any type
3934 of memory reference can't be moved if there are volatile
3935 accesses or stores in the ACROSS range. That leaves
3936 normal reads, which can be moved, as the trapping case is
3937 dealt with elsewhere. */
3938 if (other_branch_live
!= NULL
|| memrefs_in_across
!= 0)
3940 int mem_ref_flags
= 0;
3941 int mem_set_flags
= 0;
3942 note_stores (PATTERN (insn
), find_memory_stores
, &mem_set_flags
);
3943 mem_ref_flags
= for_each_rtx (&PATTERN (insn
), find_memory
,
3945 /* Catch sets of the stack pointer. */
3946 mem_ref_flags
|= mem_set_flags
;
3948 if ((mem_ref_flags
| mem_set_flags
) & MEMREF_VOLATILE
)
3950 if ((memrefs_in_across
& MEMREF_VOLATILE
) && mem_ref_flags
!= 0)
3952 if (mem_set_flags
!= 0
3953 || (mem_sets_in_across
!= 0 && mem_ref_flags
!= 0))
3956 df_simulate_find_uses (insn
, merge_use
);
3957 /* We're only interested in uses which use a value live at
3958 the top, not one previously set in this block. */
3959 bitmap_and_compl_into (merge_use
, merge_set
);
3960 df_simulate_find_defs (insn
, merge_set
);
3961 if (bitmap_intersect_p (merge_set
, test_use
)
3962 || bitmap_intersect_p (merge_use
, test_set
))
3966 next
= NEXT_INSN (insn
);
3973 if (max_to
== NULL_RTX
|| (fail
&& pmove_upto
== NULL
))
3976 /* Now, lower this upper bound by also taking into account that
3977 a range of insns moved across ACROSS must not leave a register
3978 live at the end that will be clobbered in ACROSS. We need to
3979 find a point where TEST_SET & LIVE == 0.
3981 Insns in the MERGE range that set registers which are also set
3982 in the ACROSS range may still be moved as long as we also move
3983 later insns which use the results of the set, and make the
3984 register dead again. This is verified by the condition stated
3985 above. We only need to test it for registers that are set in
3988 MERGE_LIVE is provided by the caller and holds live registers after
3990 bitmap_copy (local_merge_live
, merge_live
);
3991 for (insn
= to
; insn
!= max_to
; insn
= PREV_INSN (insn
))
3992 df_simulate_one_insn_backwards (merge_bb
, insn
, local_merge_live
);
3994 /* We're not interested in registers that aren't set in the moved
3996 bitmap_and_into (local_merge_live
, merge_set
);
3999 if (NONDEBUG_INSN_P (insn
))
4001 if (!bitmap_intersect_p (test_set
, local_merge_live
))
4007 df_simulate_one_insn_backwards (merge_bb
, insn
,
4015 insn
= PREV_INSN (insn
);
4022 *pmove_upto
= max_to
;
4024 /* For small register class machines, don't lengthen lifetimes of
4025 hard registers before reload. */
4026 if (! reload_completed
4027 && targetm
.small_register_classes_for_mode_p (VOIDmode
))
4029 EXECUTE_IF_SET_IN_BITMAP (merge_set
, 0, i
, bi
)
4031 if (i
< FIRST_PSEUDO_REGISTER
4033 && ! global_regs
[i
])
4039 BITMAP_FREE (merge_set
);
4040 BITMAP_FREE (merge_use
);
4041 BITMAP_FREE (local_merge_live
);
4042 BITMAP_FREE (test_set
);
4043 BITMAP_FREE (test_use
);
4049 /*----------------------------------------------------------------------------
4050 MULTIPLE DEFINITIONS
4052 Find the locations in the function reached by multiple definition sites
4053 for a live pseudo. In and out bitvectors are built for each basic
4054 block. They are restricted for efficiency to live registers.
4056 The gen and kill sets for the problem are obvious. Together they
4057 include all defined registers in a basic block; the gen set includes
4058 registers where a partial or conditional or may-clobber definition is
4059 last in the BB, while the kill set includes registers with a complete
4060 definition coming last. However, the computation of the dataflow
4061 itself is interesting.
4063 The idea behind it comes from SSA form's iterated dominance frontier
4064 criterion for inserting PHI functions. Just like in that case, we can use
4065 the dominance frontier to find places where multiple definitions meet;
4066 a register X defined in a basic block BB1 has multiple definitions in
4067 basic blocks in BB1's dominance frontier.
4069 So, the in-set of a basic block BB2 is not just the union of the
4070 out-sets of BB2's predecessors, but includes some more bits that come
4071 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
4072 the previous paragraph). I called this set the init-set of BB2.
4074 (Note: I actually use the kill-set only to build the init-set.
4075 gen bits are anyway propagated from BB1 to BB2 by dataflow).
4077 For example, if you have
4081 if <...> goto BB2 else goto BB3;
4089 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
4090 init-set of BB3 includes r10 and r12, but not r11. Note that we do
4091 not need to iterate the dominance frontier, because we do not insert
4092 anything like PHI functions there! Instead, dataflow will take care of
4093 propagating the information to BB3's successors.
4094 ---------------------------------------------------------------------------*/
4096 /* Private data used to verify the solution for this problem. */
4097 struct df_md_problem_data
4099 /* An obstack for the bitmaps we need for this problem. */
4100 bitmap_obstack md_bitmaps
;
4103 /* Scratch var used by transfer functions. This is used to do md analysis
4104 only for live registers. */
4105 static bitmap_head df_md_scratch
;
4109 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
4112 struct df_md_bb_info
*bb_info
= (struct df_md_bb_info
*) vbb_info
;
4115 bitmap_clear (&bb_info
->kill
);
4116 bitmap_clear (&bb_info
->gen
);
4117 bitmap_clear (&bb_info
->init
);
4118 bitmap_clear (&bb_info
->in
);
4119 bitmap_clear (&bb_info
->out
);
4124 /* Allocate or reset bitmaps for DF_MD. The solution bits are
4125 not touched unless the block is new. */
4128 df_md_alloc (bitmap all_blocks
)
4130 unsigned int bb_index
;
4132 struct df_md_problem_data
*problem_data
;
4134 df_grow_bb_info (df_md
);
4135 if (df_md
->problem_data
)
4136 problem_data
= (struct df_md_problem_data
*) df_md
->problem_data
;
4139 problem_data
= XNEW (struct df_md_problem_data
);
4140 df_md
->problem_data
= problem_data
;
4141 bitmap_obstack_initialize (&problem_data
->md_bitmaps
);
4143 bitmap_initialize (&df_md_scratch
, &problem_data
->md_bitmaps
);
4145 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4147 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4148 /* When bitmaps are already initialized, just clear them. */
4149 if (bb_info
->init
.obstack
)
4151 bitmap_clear (&bb_info
->init
);
4152 bitmap_clear (&bb_info
->gen
);
4153 bitmap_clear (&bb_info
->kill
);
4154 bitmap_clear (&bb_info
->in
);
4155 bitmap_clear (&bb_info
->out
);
4159 bitmap_initialize (&bb_info
->init
, &problem_data
->md_bitmaps
);
4160 bitmap_initialize (&bb_info
->gen
, &problem_data
->md_bitmaps
);
4161 bitmap_initialize (&bb_info
->kill
, &problem_data
->md_bitmaps
);
4162 bitmap_initialize (&bb_info
->in
, &problem_data
->md_bitmaps
);
4163 bitmap_initialize (&bb_info
->out
, &problem_data
->md_bitmaps
);
4167 df_md
->optional_p
= true;
4170 /* Add the effect of the top artificial defs of BB to the multiple definitions
4174 df_md_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_md
)
4176 int bb_index
= bb
->index
;
4178 for (def_rec
= df_get_artificial_defs (bb_index
); *def_rec
; def_rec
++)
4180 df_ref def
= *def_rec
;
4181 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
4183 unsigned int dregno
= DF_REF_REGNO (def
);
4184 if (DF_REF_FLAGS (def
)
4185 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4186 bitmap_set_bit (local_md
, dregno
);
4188 bitmap_clear_bit (local_md
, dregno
);
4194 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4198 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx insn
,
4201 unsigned uid
= INSN_UID (insn
);
4204 for (def_rec
= DF_INSN_UID_DEFS (uid
); *def_rec
; def_rec
++)
4206 df_ref def
= *def_rec
;
4207 unsigned int dregno
= DF_REF_REGNO (def
);
4208 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4209 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4211 if (DF_REF_FLAGS (def
)
4212 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4213 bitmap_set_bit (local_md
, DF_REF_ID (def
));
4215 bitmap_clear_bit (local_md
, DF_REF_ID (def
));
4221 df_md_bb_local_compute_process_def (struct df_md_bb_info
*bb_info
,
4226 bitmap_clear (&seen_in_insn
);
4228 while ((def
= *def_rec
++) != NULL
)
4230 unsigned int dregno
= DF_REF_REGNO (def
);
4231 if (((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4232 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4233 && top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
4235 if (!bitmap_bit_p (&seen_in_insn
, dregno
))
4237 if (DF_REF_FLAGS (def
)
4238 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4240 bitmap_set_bit (&bb_info
->gen
, dregno
);
4241 bitmap_clear_bit (&bb_info
->kill
, dregno
);
4245 /* When we find a clobber and a regular def,
4246 make sure the regular def wins. */
4247 bitmap_set_bit (&seen_in_insn
, dregno
);
4248 bitmap_set_bit (&bb_info
->kill
, dregno
);
4249 bitmap_clear_bit (&bb_info
->gen
, dregno
);
4257 /* Compute local multiple def info for basic block BB. */
4260 df_md_bb_local_compute (unsigned int bb_index
)
4262 basic_block bb
= BASIC_BLOCK (bb_index
);
4263 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4266 /* Artificials are only hard regs. */
4267 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4268 df_md_bb_local_compute_process_def (bb_info
,
4269 df_get_artificial_defs (bb_index
),
4272 FOR_BB_INSNS (bb
, insn
)
4274 unsigned int uid
= INSN_UID (insn
);
4278 df_md_bb_local_compute_process_def (bb_info
, DF_INSN_UID_DEFS (uid
), 0);
4281 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4282 df_md_bb_local_compute_process_def (bb_info
,
4283 df_get_artificial_defs (bb_index
),
4287 /* Compute local reaching def info for each basic block within BLOCKS. */
4290 df_md_local_compute (bitmap all_blocks
)
4292 unsigned int bb_index
, df_bb_index
;
4293 bitmap_iterator bi1
, bi2
;
4295 bitmap_head
*frontiers
;
4297 bitmap_initialize (&seen_in_insn
, &bitmap_default_obstack
);
4299 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4301 df_md_bb_local_compute (bb_index
);
4304 bitmap_clear (&seen_in_insn
);
4306 frontiers
= XNEWVEC (bitmap_head
, last_basic_block
);
4308 bitmap_initialize (&frontiers
[bb
->index
], &bitmap_default_obstack
);
4310 compute_dominance_frontiers (frontiers
);
4312 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4313 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4315 bitmap kill
= &df_md_get_bb_info (bb_index
)->kill
;
4316 EXECUTE_IF_SET_IN_BITMAP (&frontiers
[bb_index
], 0, df_bb_index
, bi2
)
4318 basic_block bb
= BASIC_BLOCK (df_bb_index
);
4319 if (bitmap_bit_p (all_blocks
, df_bb_index
))
4320 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index
)->init
, kill
,
4321 df_get_live_in (bb
));
4326 bitmap_clear (&frontiers
[bb
->index
]);
4331 /* Reset the global solution for recalculation. */
4334 df_md_reset (bitmap all_blocks
)
4336 unsigned int bb_index
;
4339 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4341 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4342 gcc_assert (bb_info
);
4343 bitmap_clear (&bb_info
->in
);
4344 bitmap_clear (&bb_info
->out
);
4349 df_md_transfer_function (int bb_index
)
4351 basic_block bb
= BASIC_BLOCK (bb_index
);
4352 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4353 bitmap in
= &bb_info
->in
;
4354 bitmap out
= &bb_info
->out
;
4355 bitmap gen
= &bb_info
->gen
;
4356 bitmap kill
= &bb_info
->kill
;
4358 /* We need to use a scratch set here so that the value returned from this
4359 function invocation properly reflects whether the sets changed in a
4360 significant way; i.e. not just because the live set was anded in. */
4361 bitmap_and (&df_md_scratch
, gen
, df_get_live_out (bb
));
4363 /* Multiple definitions of a register are not relevant if it is not
4364 live. Thus we trim the result to the places where it is live. */
4365 bitmap_and_into (in
, df_get_live_in (bb
));
4367 return bitmap_ior_and_compl (out
, &df_md_scratch
, in
, kill
);
4370 /* Initialize the solution bit vectors for problem. */
4373 df_md_init (bitmap all_blocks
)
4375 unsigned int bb_index
;
4378 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4380 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4382 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4383 df_md_transfer_function (bb_index
);
4388 df_md_confluence_0 (basic_block bb
)
4390 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4391 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4394 /* In of target gets or of out of source. */
4397 df_md_confluence_n (edge e
)
4399 bitmap op1
= &df_md_get_bb_info (e
->dest
->index
)->in
;
4400 bitmap op2
= &df_md_get_bb_info (e
->src
->index
)->out
;
4402 if (e
->flags
& EDGE_FAKE
)
4405 if (e
->flags
& EDGE_EH
)
4406 return bitmap_ior_and_compl_into (op1
, op2
,
4407 regs_invalidated_by_call_regset
);
4409 return bitmap_ior_into (op1
, op2
);
4412 /* Free all storage associated with the problem. */
4417 struct df_md_problem_data
*problem_data
4418 = (struct df_md_problem_data
*) df_md
->problem_data
;
4420 bitmap_obstack_release (&problem_data
->md_bitmaps
);
4421 free (problem_data
);
4422 df_md
->problem_data
= NULL
;
4424 df_md
->block_info_size
= 0;
4425 free (df_md
->block_info
);
4426 df_md
->block_info
= NULL
;
4431 /* Debugging info at top of bb. */
4434 df_md_top_dump (basic_block bb
, FILE *file
)
4436 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4440 fprintf (file
, ";; md in \t");
4441 df_print_regset (file
, &bb_info
->in
);
4442 fprintf (file
, ";; md init \t");
4443 df_print_regset (file
, &bb_info
->init
);
4444 fprintf (file
, ";; md gen \t");
4445 df_print_regset (file
, &bb_info
->gen
);
4446 fprintf (file
, ";; md kill \t");
4447 df_print_regset (file
, &bb_info
->kill
);
4450 /* Debugging info at bottom of bb. */
4453 df_md_bottom_dump (basic_block bb
, FILE *file
)
4455 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4459 fprintf (file
, ";; md out \t");
4460 df_print_regset (file
, &bb_info
->out
);
4463 static struct df_problem problem_MD
=
4465 DF_MD
, /* Problem id. */
4466 DF_FORWARD
, /* Direction. */
4467 df_md_alloc
, /* Allocate the problem specific data. */
4468 df_md_reset
, /* Reset global information. */
4469 df_md_free_bb_info
, /* Free basic block info. */
4470 df_md_local_compute
, /* Local compute function. */
4471 df_md_init
, /* Init the solution specific data. */
4472 df_worklist_dataflow
, /* Worklist solver. */
4473 df_md_confluence_0
, /* Confluence operator 0. */
4474 df_md_confluence_n
, /* Confluence operator n. */
4475 df_md_transfer_function
, /* Transfer function. */
4476 NULL
, /* Finalize function. */
4477 df_md_free
, /* Free all of the problem information. */
4478 df_md_free
, /* Remove this problem from the stack of dataflow problems. */
4479 NULL
, /* Debugging. */
4480 df_md_top_dump
, /* Debugging start block. */
4481 df_md_bottom_dump
, /* Debugging end block. */
4482 NULL
, /* Incremental solution verify start. */
4483 NULL
, /* Incremental solution verify end. */
4484 NULL
, /* Dependent problem. */
4485 sizeof (struct df_md_bb_info
),/* Size of entry of block_info array. */
4486 TV_DF_MD
, /* Timing variable. */
4487 false /* Reset blocks on dropping out of blocks_to_analyze. */
4490 /* Create a new MD instance and add it to the existing instance
4494 df_md_add_problem (void)
4496 df_add_problem (&problem_MD
);