1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
31 #include "insn-config.h"
34 #include "alloc-pool.h"
45 /* Note that turning REG_DEAD_DEBUGGING on will cause
46 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
47 addresses in the dumps. */
48 #define REG_DEAD_DEBUGGING 0
50 #define DF_SPARSE_THRESHOLD 32
52 static bitmap_head seen_in_block
;
53 static bitmap_head seen_in_insn
;
55 /*----------------------------------------------------------------------------
57 ----------------------------------------------------------------------------*/
59 /* Generic versions to get the void* version of the block info. Only
60 used inside the problem instance vectors. */
62 /* Dump a def-use or use-def chain for REF to FILE. */
65 df_chain_dump (struct df_link
*link
, FILE *file
)
68 for (; link
; link
= link
->next
)
70 fprintf (file
, "%c%d(bb %d insn %d) ",
71 DF_REF_REG_DEF_P (link
->ref
)
73 : (DF_REF_FLAGS (link
->ref
) & DF_REF_IN_NOTE
) ? 'e' : 'u',
74 DF_REF_ID (link
->ref
),
75 DF_REF_BBNO (link
->ref
),
76 DF_REF_IS_ARTIFICIAL (link
->ref
)
77 ? -1 : DF_REF_INSN_UID (link
->ref
));
83 /* Print some basic block info as part of df_dump. */
86 df_print_bb_index (basic_block bb
, FILE *file
)
91 fprintf (file
, "\n( ");
92 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
94 basic_block pred
= e
->src
;
95 fprintf (file
, "%d%s ", pred
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
97 fprintf (file
, ")->[%d]->( ", bb
->index
);
98 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
100 basic_block succ
= e
->dest
;
101 fprintf (file
, "%d%s ", succ
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
103 fprintf (file
, ")\n");
107 /*----------------------------------------------------------------------------
110 Find the locations in the function where each definition site for a
111 pseudo reaches. In and out bitvectors are built for each basic
112 block. The id field in the ref is used to index into these sets.
113 See df.h for details.
115 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
116 existing uses are included in the global reaching DEFs set, or in other
117 words only DEFs that are still live. This is a kind of pruned version
118 of the traditional reaching definitions problem that is much less
119 complex to compute and produces enough information to compute UD-chains.
120 In this context, live must be interpreted in the DF_LR sense: Uses that
121 are upward exposed but maybe not initialized on all paths through the
122 CFG. For a USE that is not reached by a DEF on all paths, we still want
123 to make those DEFs that do reach the USE visible, and pruning based on
124 DF_LIVE would make that impossible.
125 ----------------------------------------------------------------------------*/
127 /* This problem plays a large number of games for the sake of
130 1) The order of the bits in the bitvectors. After the scanning
131 phase, all of the defs are sorted. All of the defs for the reg 0
132 are first, followed by all defs for reg 1 and so on.
134 2) There are two kill sets, one if the number of defs is less or
135 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
138 <= : Data is built directly in the kill set.
140 > : One level of indirection is used to keep from generating long
141 strings of 1 bits in the kill sets. Bitvectors that are indexed
142 by the regnum are used to represent that there is a killing def
143 for the register. The confluence and transfer functions use
144 these along with the bitmap_clear_range call to remove ranges of
145 bits without actually generating a knockout vector.
147 The kill and sparse_kill and the dense_invalidated_by_call and
148 sparse_invalidated_by_call both play this game. */
150 /* Private data used to compute the solution for this problem. These
151 data structures are not accessible outside of this module. */
152 struct df_rd_problem_data
154 /* The set of defs to regs invalidated by call. */
155 bitmap_head sparse_invalidated_by_call
;
156 /* The set of defs to regs invalidate by call for rd. */
157 bitmap_head dense_invalidated_by_call
;
158 /* An obstack for the bitmaps we need for this problem. */
159 bitmap_obstack rd_bitmaps
;
163 /* Free basic block info. */
166 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
169 struct df_rd_bb_info
*bb_info
= (struct df_rd_bb_info
*) vbb_info
;
172 bitmap_clear (&bb_info
->kill
);
173 bitmap_clear (&bb_info
->sparse_kill
);
174 bitmap_clear (&bb_info
->gen
);
175 bitmap_clear (&bb_info
->in
);
176 bitmap_clear (&bb_info
->out
);
181 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
182 not touched unless the block is new. */
185 df_rd_alloc (bitmap all_blocks
)
187 unsigned int bb_index
;
189 struct df_rd_problem_data
*problem_data
;
191 if (df_rd
->problem_data
)
193 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
194 bitmap_clear (&problem_data
->sparse_invalidated_by_call
);
195 bitmap_clear (&problem_data
->dense_invalidated_by_call
);
199 problem_data
= XNEW (struct df_rd_problem_data
);
200 df_rd
->problem_data
= problem_data
;
202 bitmap_obstack_initialize (&problem_data
->rd_bitmaps
);
203 bitmap_initialize (&problem_data
->sparse_invalidated_by_call
,
204 &problem_data
->rd_bitmaps
);
205 bitmap_initialize (&problem_data
->dense_invalidated_by_call
,
206 &problem_data
->rd_bitmaps
);
209 df_grow_bb_info (df_rd
);
211 /* Because of the clustering of all use sites for the same pseudo,
212 we have to process all of the blocks before doing the analysis. */
214 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
216 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
218 /* When bitmaps are already initialized, just clear them. */
219 if (bb_info
->kill
.obstack
)
221 bitmap_clear (&bb_info
->kill
);
222 bitmap_clear (&bb_info
->sparse_kill
);
223 bitmap_clear (&bb_info
->gen
);
227 bitmap_initialize (&bb_info
->kill
, &problem_data
->rd_bitmaps
);
228 bitmap_initialize (&bb_info
->sparse_kill
, &problem_data
->rd_bitmaps
);
229 bitmap_initialize (&bb_info
->gen
, &problem_data
->rd_bitmaps
);
230 bitmap_initialize (&bb_info
->in
, &problem_data
->rd_bitmaps
);
231 bitmap_initialize (&bb_info
->out
, &problem_data
->rd_bitmaps
);
234 df_rd
->optional_p
= true;
238 /* Add the effect of the top artificial defs of BB to the reaching definitions
242 df_rd_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_rd
)
244 int bb_index
= bb
->index
;
246 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
247 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
249 unsigned int dregno
= DF_REF_REGNO (def
);
250 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
251 bitmap_clear_range (local_rd
,
252 DF_DEFS_BEGIN (dregno
),
253 DF_DEFS_COUNT (dregno
));
254 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
258 /* Add the effect of the defs of INSN to the reaching definitions bitmap
262 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx_insn
*insn
,
267 FOR_EACH_INSN_DEF (def
, insn
)
269 unsigned int dregno
= DF_REF_REGNO (def
);
270 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
271 || (dregno
>= FIRST_PSEUDO_REGISTER
))
273 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
274 bitmap_clear_range (local_rd
,
275 DF_DEFS_BEGIN (dregno
),
276 DF_DEFS_COUNT (dregno
));
277 if (!(DF_REF_FLAGS (def
)
278 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
279 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
284 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
285 more complicated than just simulating, because we must produce the
286 gen and kill sets and hence deal with the two possible representations
290 df_rd_bb_local_compute_process_def (struct df_rd_bb_info
*bb_info
,
294 for (; def
; def
= DF_REF_NEXT_LOC (def
))
296 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
298 unsigned int regno
= DF_REF_REGNO (def
);
299 unsigned int begin
= DF_DEFS_BEGIN (regno
);
300 unsigned int n_defs
= DF_DEFS_COUNT (regno
);
302 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
303 || (regno
>= FIRST_PSEUDO_REGISTER
))
305 /* Only the last def(s) for a regno in the block has any
307 if (!bitmap_bit_p (&seen_in_block
, regno
))
309 /* The first def for regno in insn gets to knock out the
310 defs from other instructions. */
311 if ((!bitmap_bit_p (&seen_in_insn
, regno
))
312 /* If the def is to only part of the reg, it does
313 not kill the other defs that reach here. */
314 && (!(DF_REF_FLAGS (def
) &
315 (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))))
317 if (n_defs
> DF_SPARSE_THRESHOLD
)
319 bitmap_set_bit (&bb_info
->sparse_kill
, regno
);
320 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
324 bitmap_set_range (&bb_info
->kill
, begin
, n_defs
);
325 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
329 bitmap_set_bit (&seen_in_insn
, regno
);
330 /* All defs for regno in the instruction may be put into
332 if (!(DF_REF_FLAGS (def
)
333 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
334 bitmap_set_bit (&bb_info
->gen
, DF_REF_ID (def
));
341 /* Compute local reaching def info for basic block BB. */
344 df_rd_bb_local_compute (unsigned int bb_index
)
346 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
347 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
350 bitmap_clear (&seen_in_block
);
351 bitmap_clear (&seen_in_insn
);
353 /* Artificials are only hard regs. */
354 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
355 df_rd_bb_local_compute_process_def (bb_info
,
356 df_get_artificial_defs (bb_index
),
359 FOR_BB_INSNS_REVERSE (bb
, insn
)
361 unsigned int uid
= INSN_UID (insn
);
366 df_rd_bb_local_compute_process_def (bb_info
,
367 DF_INSN_UID_DEFS (uid
), 0);
369 /* This complex dance with the two bitmaps is required because
370 instructions can assign twice to the same pseudo. This
371 generally happens with calls that will have one def for the
372 result and another def for the clobber. If only one vector
373 is used and the clobber goes first, the result will be
375 bitmap_ior_into (&seen_in_block
, &seen_in_insn
);
376 bitmap_clear (&seen_in_insn
);
379 /* Process the artificial defs at the top of the block last since we
380 are going backwards through the block and these are logically at
382 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
383 df_rd_bb_local_compute_process_def (bb_info
,
384 df_get_artificial_defs (bb_index
),
389 /* Compute local reaching def info for each basic block within BLOCKS. */
392 df_rd_local_compute (bitmap all_blocks
)
394 unsigned int bb_index
;
397 struct df_rd_problem_data
*problem_data
398 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
399 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
400 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
402 bitmap_initialize (&seen_in_block
, &df_bitmap_obstack
);
403 bitmap_initialize (&seen_in_insn
, &df_bitmap_obstack
);
405 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG
);
407 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
409 df_rd_bb_local_compute (bb_index
);
412 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
413 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset
, 0, regno
, bi
)
415 if (! HARD_REGISTER_NUM_P (regno
)
416 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
418 if (DF_DEFS_COUNT (regno
) > DF_SPARSE_THRESHOLD
)
419 bitmap_set_bit (sparse_invalidated
, regno
);
421 bitmap_set_range (dense_invalidated
,
422 DF_DEFS_BEGIN (regno
),
423 DF_DEFS_COUNT (regno
));
427 bitmap_clear (&seen_in_block
);
428 bitmap_clear (&seen_in_insn
);
432 /* Initialize the solution bit vectors for problem. */
435 df_rd_init_solution (bitmap all_blocks
)
437 unsigned int bb_index
;
440 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
442 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
444 bitmap_copy (&bb_info
->out
, &bb_info
->gen
);
445 bitmap_clear (&bb_info
->in
);
449 /* In of target gets or of out of source. */
452 df_rd_confluence_n (edge e
)
454 bitmap op1
= &df_rd_get_bb_info (e
->dest
->index
)->in
;
455 bitmap op2
= &df_rd_get_bb_info (e
->src
->index
)->out
;
456 bool changed
= false;
458 if (e
->flags
& EDGE_FAKE
)
461 if (e
->flags
& EDGE_EH
)
463 struct df_rd_problem_data
*problem_data
464 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
465 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
466 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
471 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
472 bitmap_and_compl (&tmp
, op2
, dense_invalidated
);
474 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
476 bitmap_clear_range (&tmp
,
477 DF_DEFS_BEGIN (regno
),
478 DF_DEFS_COUNT (regno
));
480 changed
|= bitmap_ior_into (op1
, &tmp
);
485 return bitmap_ior_into (op1
, op2
);
489 /* Transfer function. */
492 df_rd_transfer_function (int bb_index
)
494 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
497 bitmap in
= &bb_info
->in
;
498 bitmap out
= &bb_info
->out
;
499 bitmap gen
= &bb_info
->gen
;
500 bitmap kill
= &bb_info
->kill
;
501 bitmap sparse_kill
= &bb_info
->sparse_kill
;
502 bool changed
= false;
504 if (bitmap_empty_p (sparse_kill
))
505 changed
= bitmap_ior_and_compl (out
, gen
, in
, kill
);
508 struct df_rd_problem_data
*problem_data
;
511 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
512 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
513 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
514 bitmap_initialize (&tmp
, &problem_data
->rd_bitmaps
);
516 bitmap_and_compl (&tmp
, in
, kill
);
517 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
519 bitmap_clear_range (&tmp
,
520 DF_DEFS_BEGIN (regno
),
521 DF_DEFS_COUNT (regno
));
523 bitmap_ior_into (&tmp
, gen
);
524 changed
= !bitmap_equal_p (&tmp
, out
);
534 if (df
->changeable_flags
& DF_RD_PRUNE_DEAD_DEFS
)
536 /* Create a mask of DEFs for all registers live at the end of this
537 basic block, and mask out DEFs of registers that are not live.
538 Computing the mask looks costly, but the benefit of the pruning
539 outweighs the cost. */
540 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
541 bitmap regs_live_out
= &df_lr_get_bb_info (bb_index
)->out
;
542 bitmap live_defs
= BITMAP_ALLOC (&df_bitmap_obstack
);
546 EXECUTE_IF_SET_IN_BITMAP (regs_live_out
, 0, regno
, bi
)
547 bitmap_set_range (live_defs
,
548 DF_DEFS_BEGIN (regno
),
549 DF_DEFS_COUNT (regno
));
550 changed
|= bitmap_and_into (&bb_info
->out
, live_defs
);
551 BITMAP_FREE (live_defs
);
557 /* Free all storage associated with the problem. */
562 struct df_rd_problem_data
*problem_data
563 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
567 bitmap_obstack_release (&problem_data
->rd_bitmaps
);
569 df_rd
->block_info_size
= 0;
570 free (df_rd
->block_info
);
571 df_rd
->block_info
= NULL
;
572 free (df_rd
->problem_data
);
578 /* Debugging info. */
581 df_rd_start_dump (FILE *file
)
583 struct df_rd_problem_data
*problem_data
584 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
585 unsigned int m
= DF_REG_SIZE (df
);
588 if (!df_rd
->block_info
)
591 fprintf (file
, ";; Reaching defs:\n");
593 fprintf (file
, ";; sparse invalidated \t");
594 dump_bitmap (file
, &problem_data
->sparse_invalidated_by_call
);
595 fprintf (file
, ";; dense invalidated \t");
596 dump_bitmap (file
, &problem_data
->dense_invalidated_by_call
);
598 fprintf (file
, ";; reg->defs[] map:\t");
599 for (regno
= 0; regno
< m
; regno
++)
600 if (DF_DEFS_COUNT (regno
))
601 fprintf (file
, "%d[%d,%d] ", regno
,
602 DF_DEFS_BEGIN (regno
),
603 DF_DEFS_BEGIN (regno
) + DF_DEFS_COUNT (regno
) - 1);
604 fprintf (file
, "\n");
609 df_rd_dump_defs_set (bitmap defs_set
, const char *prefix
, FILE *file
)
613 unsigned int m
= DF_REG_SIZE (df
);
614 bool first_reg
= true;
616 fprintf (file
, "%s\t(%d) ", prefix
, (int) bitmap_count_bits (defs_set
));
618 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
619 for (regno
= 0; regno
< m
; regno
++)
621 if (HARD_REGISTER_NUM_P (regno
)
622 && (df
->changeable_flags
& DF_NO_HARD_REGS
))
624 bitmap_set_range (&tmp
, DF_DEFS_BEGIN (regno
), DF_DEFS_COUNT (regno
));
625 bitmap_and_into (&tmp
, defs_set
);
626 if (! bitmap_empty_p (&tmp
))
630 bool first_def
= true;
636 fprintf (file
, "%u[", regno
);
637 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, ix
, bi
)
639 fprintf (file
, "%s%u", first_def
? "" : ",", ix
);
647 fprintf (file
, "\n");
651 /* Debugging info at top of bb. */
654 df_rd_top_dump (basic_block bb
, FILE *file
)
656 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
660 df_rd_dump_defs_set (&bb_info
->in
, ";; rd in ", file
);
661 df_rd_dump_defs_set (&bb_info
->gen
, ";; rd gen ", file
);
662 df_rd_dump_defs_set (&bb_info
->kill
, ";; rd kill", file
);
666 /* Debugging info at bottom of bb. */
669 df_rd_bottom_dump (basic_block bb
, FILE *file
)
671 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
675 df_rd_dump_defs_set (&bb_info
->out
, ";; rd out ", file
);
678 /* All of the information associated with every instance of the problem. */
680 static struct df_problem problem_RD
=
682 DF_RD
, /* Problem id. */
683 DF_FORWARD
, /* Direction. */
684 df_rd_alloc
, /* Allocate the problem specific data. */
685 NULL
, /* Reset global information. */
686 df_rd_free_bb_info
, /* Free basic block info. */
687 df_rd_local_compute
, /* Local compute function. */
688 df_rd_init_solution
, /* Init the solution specific data. */
689 df_worklist_dataflow
, /* Worklist solver. */
690 NULL
, /* Confluence operator 0. */
691 df_rd_confluence_n
, /* Confluence operator n. */
692 df_rd_transfer_function
, /* Transfer function. */
693 NULL
, /* Finalize function. */
694 df_rd_free
, /* Free all of the problem information. */
695 df_rd_free
, /* Remove this problem from the stack of dataflow problems. */
696 df_rd_start_dump
, /* Debugging. */
697 df_rd_top_dump
, /* Debugging start block. */
698 df_rd_bottom_dump
, /* Debugging end block. */
699 NULL
, /* Debugging start insn. */
700 NULL
, /* Debugging end insn. */
701 NULL
, /* Incremental solution verify start. */
702 NULL
, /* Incremental solution verify end. */
703 NULL
, /* Dependent problem. */
704 sizeof (struct df_rd_bb_info
),/* Size of entry of block_info array. */
705 TV_DF_RD
, /* Timing variable. */
706 true /* Reset blocks on dropping out of blocks_to_analyze. */
711 /* Create a new RD instance and add it to the existing instance
715 df_rd_add_problem (void)
717 df_add_problem (&problem_RD
);
722 /*----------------------------------------------------------------------------
725 Find the locations in the function where any use of a pseudo can
726 reach in the backwards direction. In and out bitvectors are built
727 for each basic block. The regno is used to index into these sets.
728 See df.h for details.
729 ----------------------------------------------------------------------------*/
731 /* Private data used to verify the solution for this problem. */
732 struct df_lr_problem_data
736 /* An obstack for the bitmaps we need for this problem. */
737 bitmap_obstack lr_bitmaps
;
740 /* Free basic block info. */
743 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
746 struct df_lr_bb_info
*bb_info
= (struct df_lr_bb_info
*) vbb_info
;
749 bitmap_clear (&bb_info
->use
);
750 bitmap_clear (&bb_info
->def
);
751 bitmap_clear (&bb_info
->in
);
752 bitmap_clear (&bb_info
->out
);
757 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
758 not touched unless the block is new. */
761 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
763 unsigned int bb_index
;
765 struct df_lr_problem_data
*problem_data
;
767 df_grow_bb_info (df_lr
);
768 if (df_lr
->problem_data
)
769 problem_data
= (struct df_lr_problem_data
*) df_lr
->problem_data
;
772 problem_data
= XNEW (struct df_lr_problem_data
);
773 df_lr
->problem_data
= problem_data
;
775 problem_data
->out
= NULL
;
776 problem_data
->in
= NULL
;
777 bitmap_obstack_initialize (&problem_data
->lr_bitmaps
);
780 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
782 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
784 /* When bitmaps are already initialized, just clear them. */
785 if (bb_info
->use
.obstack
)
787 bitmap_clear (&bb_info
->def
);
788 bitmap_clear (&bb_info
->use
);
792 bitmap_initialize (&bb_info
->use
, &problem_data
->lr_bitmaps
);
793 bitmap_initialize (&bb_info
->def
, &problem_data
->lr_bitmaps
);
794 bitmap_initialize (&bb_info
->in
, &problem_data
->lr_bitmaps
);
795 bitmap_initialize (&bb_info
->out
, &problem_data
->lr_bitmaps
);
799 df_lr
->optional_p
= false;
803 /* Reset the global solution for recalculation. */
806 df_lr_reset (bitmap all_blocks
)
808 unsigned int bb_index
;
811 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
813 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
814 gcc_assert (bb_info
);
815 bitmap_clear (&bb_info
->in
);
816 bitmap_clear (&bb_info
->out
);
821 /* Compute local live register info for basic block BB. */
824 df_lr_bb_local_compute (unsigned int bb_index
)
826 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
827 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
831 /* Process the registers set in an exception handler. */
832 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
833 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
835 unsigned int dregno
= DF_REF_REGNO (def
);
836 bitmap_set_bit (&bb_info
->def
, dregno
);
837 bitmap_clear_bit (&bb_info
->use
, dregno
);
840 /* Process the hardware registers that are always live. */
841 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
842 /* Add use to set of uses in this BB. */
843 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
844 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
846 FOR_BB_INSNS_REVERSE (bb
, insn
)
848 if (!NONDEBUG_INSN_P (insn
))
851 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
852 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
853 /* If the def is to only part of the reg, it does
854 not kill the other defs that reach here. */
855 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
857 unsigned int dregno
= DF_REF_REGNO (def
);
858 bitmap_set_bit (&bb_info
->def
, dregno
);
859 bitmap_clear_bit (&bb_info
->use
, dregno
);
862 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
863 /* Add use to set of uses in this BB. */
864 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
867 /* Process the registers set in an exception handler or the hard
868 frame pointer if this block is the target of a non local
870 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
871 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
873 unsigned int dregno
= DF_REF_REGNO (def
);
874 bitmap_set_bit (&bb_info
->def
, dregno
);
875 bitmap_clear_bit (&bb_info
->use
, dregno
);
879 /* Process the uses that are live into an exception handler. */
880 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
881 /* Add use to set of uses in this BB. */
882 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
883 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
886 /* If the df_live problem is not defined, such as at -O0 and -O1, we
887 still need to keep the luids up to date. This is normally done
888 in the df_live problem since this problem has a forwards
891 df_recompute_luids (bb
);
895 /* Compute local live register info for each basic block within BLOCKS. */
898 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
900 unsigned int bb_index
, i
;
903 bitmap_clear (&df
->hardware_regs_used
);
905 /* The all-important stack pointer must always be live. */
906 bitmap_set_bit (&df
->hardware_regs_used
, STACK_POINTER_REGNUM
);
908 /* Global regs are always live, too. */
909 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
911 bitmap_set_bit (&df
->hardware_regs_used
, i
);
913 /* Before reload, there are a few registers that must be forced
914 live everywhere -- which might not already be the case for
915 blocks within infinite loops. */
916 if (!reload_completed
)
918 unsigned int pic_offset_table_regnum
= PIC_OFFSET_TABLE_REGNUM
;
919 /* Any reference to any pseudo before reload is a potential
920 reference of the frame pointer. */
921 bitmap_set_bit (&df
->hardware_regs_used
, FRAME_POINTER_REGNUM
);
923 /* Pseudos with argument area equivalences may require
924 reloading via the argument pointer. */
925 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
926 && fixed_regs
[ARG_POINTER_REGNUM
])
927 bitmap_set_bit (&df
->hardware_regs_used
, ARG_POINTER_REGNUM
);
929 /* Any constant, or pseudo with constant equivalences, may
930 require reloading from memory using the pic register. */
931 if (pic_offset_table_regnum
!= INVALID_REGNUM
932 && fixed_regs
[pic_offset_table_regnum
])
933 bitmap_set_bit (&df
->hardware_regs_used
, pic_offset_table_regnum
);
936 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
938 if (bb_index
== EXIT_BLOCK
)
940 /* The exit block is special for this problem and its bits are
941 computed from thin air. */
942 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (EXIT_BLOCK
);
943 bitmap_copy (&bb_info
->use
, df
->exit_block_uses
);
946 df_lr_bb_local_compute (bb_index
);
949 bitmap_clear (df_lr
->out_of_date_transfer_functions
);
953 /* Initialize the solution vectors. */
956 df_lr_init (bitmap all_blocks
)
958 unsigned int bb_index
;
961 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
963 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
964 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
965 bitmap_clear (&bb_info
->out
);
970 /* Confluence function that processes infinite loops. This might be a
971 noreturn function that throws. And even if it isn't, getting the
972 unwind info right helps debugging. */
974 df_lr_confluence_0 (basic_block bb
)
976 bitmap op1
= &df_lr_get_bb_info (bb
->index
)->out
;
977 if (bb
!= EXIT_BLOCK_PTR_FOR_FN (cfun
))
978 bitmap_copy (op1
, &df
->hardware_regs_used
);
982 /* Confluence function that ignores fake edges. */
985 df_lr_confluence_n (edge e
)
987 bitmap op1
= &df_lr_get_bb_info (e
->src
->index
)->out
;
988 bitmap op2
= &df_lr_get_bb_info (e
->dest
->index
)->in
;
989 bool changed
= false;
991 /* Call-clobbered registers die across exception and call edges. */
992 /* ??? Abnormal call edges ignored for the moment, as this gets
993 confused by sibling call edges, which crashes reg-stack. */
994 if (e
->flags
& EDGE_EH
)
995 changed
= bitmap_ior_and_compl_into (op1
, op2
, regs_invalidated_by_call_regset
);
997 changed
= bitmap_ior_into (op1
, op2
);
999 changed
|= bitmap_ior_into (op1
, &df
->hardware_regs_used
);
1004 /* Transfer function. */
1007 df_lr_transfer_function (int bb_index
)
1009 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
1010 bitmap in
= &bb_info
->in
;
1011 bitmap out
= &bb_info
->out
;
1012 bitmap use
= &bb_info
->use
;
1013 bitmap def
= &bb_info
->def
;
1015 return bitmap_ior_and_compl (in
, use
, out
, def
);
1019 /* Run the fast dce as a side effect of building LR. */
1022 df_lr_finalize (bitmap all_blocks
)
1024 df_lr
->solutions_dirty
= false;
1025 if (df
->changeable_flags
& DF_LR_RUN_DCE
)
1029 /* If dce deletes some instructions, we need to recompute the lr
1030 solution before proceeding further. The problem is that fast
1031 dce is a pessimestic dataflow algorithm. In the case where
1032 it deletes a statement S inside of a loop, the uses inside of
1033 S may not be deleted from the dataflow solution because they
1034 were carried around the loop. While it is conservatively
1035 correct to leave these extra bits, the standards of df
1036 require that we maintain the best possible (least fixed
1037 point) solution. The only way to do that is to redo the
1038 iteration from the beginning. See PR35805 for an
1040 if (df_lr
->solutions_dirty
)
1042 df_clear_flags (DF_LR_RUN_DCE
);
1043 df_lr_alloc (all_blocks
);
1044 df_lr_local_compute (all_blocks
);
1045 df_worklist_dataflow (df_lr
, all_blocks
, df
->postorder
, df
->n_blocks
);
1046 df_lr_finalize (all_blocks
);
1047 df_set_flags (DF_LR_RUN_DCE
);
1053 /* Free all storage associated with the problem. */
1058 struct df_lr_problem_data
*problem_data
1059 = (struct df_lr_problem_data
*) df_lr
->problem_data
;
1060 if (df_lr
->block_info
)
1063 df_lr
->block_info_size
= 0;
1064 free (df_lr
->block_info
);
1065 df_lr
->block_info
= NULL
;
1066 bitmap_obstack_release (&problem_data
->lr_bitmaps
);
1067 free (df_lr
->problem_data
);
1068 df_lr
->problem_data
= NULL
;
1071 BITMAP_FREE (df_lr
->out_of_date_transfer_functions
);
1076 /* Debugging info at top of bb. */
1079 df_lr_top_dump (basic_block bb
, FILE *file
)
1081 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1082 struct df_lr_problem_data
*problem_data
;
1086 fprintf (file
, ";; lr in \t");
1087 df_print_regset (file
, &bb_info
->in
);
1088 if (df_lr
->problem_data
)
1090 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1091 if (problem_data
->in
)
1093 fprintf (file
, ";; old in \t");
1094 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1097 fprintf (file
, ";; lr use \t");
1098 df_print_regset (file
, &bb_info
->use
);
1099 fprintf (file
, ";; lr def \t");
1100 df_print_regset (file
, &bb_info
->def
);
1104 /* Debugging info at bottom of bb. */
1107 df_lr_bottom_dump (basic_block bb
, FILE *file
)
1109 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1110 struct df_lr_problem_data
*problem_data
;
1114 fprintf (file
, ";; lr out \t");
1115 df_print_regset (file
, &bb_info
->out
);
1116 if (df_lr
->problem_data
)
1118 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1119 if (problem_data
->out
)
1121 fprintf (file
, ";; old out \t");
1122 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1128 /* Build the datastructure to verify that the solution to the dataflow
1129 equations is not dirty. */
1132 df_lr_verify_solution_start (void)
1135 struct df_lr_problem_data
*problem_data
;
1136 if (df_lr
->solutions_dirty
)
1139 /* Set it true so that the solution is recomputed. */
1140 df_lr
->solutions_dirty
= true;
1142 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1143 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1144 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1146 FOR_ALL_BB_FN (bb
, cfun
)
1148 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->lr_bitmaps
);
1149 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->lr_bitmaps
);
1150 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
));
1151 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
));
1156 /* Compare the saved datastructure and the new solution to the dataflow
1160 df_lr_verify_solution_end (void)
1162 struct df_lr_problem_data
*problem_data
;
1165 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1167 if (!problem_data
->out
)
1170 if (df_lr
->solutions_dirty
)
1171 /* Do not check if the solution is still dirty. See the comment
1172 in df_lr_finalize for details. */
1173 df_lr
->solutions_dirty
= false;
1175 FOR_ALL_BB_FN (bb
, cfun
)
1177 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
)))
1178 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
))))
1180 /*df_dump (stderr);*/
1185 /* Cannot delete them immediately because you may want to dump them
1186 if the comparison fails. */
1187 FOR_ALL_BB_FN (bb
, cfun
)
1189 bitmap_clear (&problem_data
->in
[bb
->index
]);
1190 bitmap_clear (&problem_data
->out
[bb
->index
]);
1193 free (problem_data
->in
);
1194 free (problem_data
->out
);
1195 problem_data
->in
= NULL
;
1196 problem_data
->out
= NULL
;
1200 /* All of the information associated with every instance of the problem. */
1202 static struct df_problem problem_LR
=
1204 DF_LR
, /* Problem id. */
1205 DF_BACKWARD
, /* Direction. */
1206 df_lr_alloc
, /* Allocate the problem specific data. */
1207 df_lr_reset
, /* Reset global information. */
1208 df_lr_free_bb_info
, /* Free basic block info. */
1209 df_lr_local_compute
, /* Local compute function. */
1210 df_lr_init
, /* Init the solution specific data. */
1211 df_worklist_dataflow
, /* Worklist solver. */
1212 df_lr_confluence_0
, /* Confluence operator 0. */
1213 df_lr_confluence_n
, /* Confluence operator n. */
1214 df_lr_transfer_function
, /* Transfer function. */
1215 df_lr_finalize
, /* Finalize function. */
1216 df_lr_free
, /* Free all of the problem information. */
1217 NULL
, /* Remove this problem from the stack of dataflow problems. */
1218 NULL
, /* Debugging. */
1219 df_lr_top_dump
, /* Debugging start block. */
1220 df_lr_bottom_dump
, /* Debugging end block. */
1221 NULL
, /* Debugging start insn. */
1222 NULL
, /* Debugging end insn. */
1223 df_lr_verify_solution_start
,/* Incremental solution verify start. */
1224 df_lr_verify_solution_end
, /* Incremental solution verify end. */
1225 NULL
, /* Dependent problem. */
1226 sizeof (struct df_lr_bb_info
),/* Size of entry of block_info array. */
1227 TV_DF_LR
, /* Timing variable. */
1228 false /* Reset blocks on dropping out of blocks_to_analyze. */
1232 /* Create a new DATAFLOW instance and add it to an existing instance
1233 of DF. The returned structure is what is used to get at the
1237 df_lr_add_problem (void)
1239 df_add_problem (&problem_LR
);
1240 /* These will be initialized when df_scan_blocks processes each
1242 df_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1246 /* Verify that all of the lr related info is consistent and
1250 df_lr_verify_transfer_functions (void)
1253 bitmap_head saved_def
;
1254 bitmap_head saved_use
;
1255 bitmap_head all_blocks
;
1260 bitmap_initialize (&saved_def
, &bitmap_default_obstack
);
1261 bitmap_initialize (&saved_use
, &bitmap_default_obstack
);
1262 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1264 FOR_ALL_BB_FN (bb
, cfun
)
1266 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1267 bitmap_set_bit (&all_blocks
, bb
->index
);
1271 /* Make a copy of the transfer functions and then compute
1272 new ones to see if the transfer functions have
1274 if (!bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1277 bitmap_copy (&saved_def
, &bb_info
->def
);
1278 bitmap_copy (&saved_use
, &bb_info
->use
);
1279 bitmap_clear (&bb_info
->def
);
1280 bitmap_clear (&bb_info
->use
);
1282 df_lr_bb_local_compute (bb
->index
);
1283 gcc_assert (bitmap_equal_p (&saved_def
, &bb_info
->def
));
1284 gcc_assert (bitmap_equal_p (&saved_use
, &bb_info
->use
));
1289 /* If we do not have basic block info, the block must be in
1290 the list of dirty blocks or else some one has added a
1291 block behind our backs. */
1292 gcc_assert (bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1295 /* Make sure no one created a block without following
1297 gcc_assert (df_scan_get_bb_info (bb
->index
));
1300 /* Make sure there are no dirty bits in blocks that have been deleted. */
1301 gcc_assert (!bitmap_intersect_compl_p (df_lr
->out_of_date_transfer_functions
,
1304 bitmap_clear (&saved_def
);
1305 bitmap_clear (&saved_use
);
1306 bitmap_clear (&all_blocks
);
1311 /*----------------------------------------------------------------------------
1312 LIVE AND MUST-INITIALIZED REGISTERS.
1314 This problem first computes the IN and OUT bitvectors for the
1315 must-initialized registers problems, which is a forward problem.
1316 It gives the set of registers for which we MUST have an available
1317 definition on any path from the entry block to the entry/exit of
1318 a basic block. Sets generate a definition, while clobbers kill
1321 In and out bitvectors are built for each basic block and are indexed by
1322 regnum (see df.h for details). In and out bitvectors in struct
1323 df_live_bb_info actually refers to the must-initialized problem;
1325 Then, the in and out sets for the LIVE problem itself are computed.
1326 These are the logical AND of the IN and OUT sets from the LR problem
1327 and the must-initialized problem.
1328 ----------------------------------------------------------------------------*/
1330 /* Private data used to verify the solution for this problem. */
1331 struct df_live_problem_data
1335 /* An obstack for the bitmaps we need for this problem. */
1336 bitmap_obstack live_bitmaps
;
1339 /* Scratch var used by transfer functions. This is used to implement
1340 an optimization to reduce the amount of space used to compute the
1341 combined lr and live analysis. */
1342 static bitmap_head df_live_scratch
;
1345 /* Free basic block info. */
1348 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
1351 struct df_live_bb_info
*bb_info
= (struct df_live_bb_info
*) vbb_info
;
1354 bitmap_clear (&bb_info
->gen
);
1355 bitmap_clear (&bb_info
->kill
);
1356 bitmap_clear (&bb_info
->in
);
1357 bitmap_clear (&bb_info
->out
);
1362 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1363 not touched unless the block is new. */
1366 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
1368 unsigned int bb_index
;
1370 struct df_live_problem_data
*problem_data
;
1372 if (df_live
->problem_data
)
1373 problem_data
= (struct df_live_problem_data
*) df_live
->problem_data
;
1376 problem_data
= XNEW (struct df_live_problem_data
);
1377 df_live
->problem_data
= problem_data
;
1379 problem_data
->out
= NULL
;
1380 problem_data
->in
= NULL
;
1381 bitmap_obstack_initialize (&problem_data
->live_bitmaps
);
1382 bitmap_initialize (&df_live_scratch
, &problem_data
->live_bitmaps
);
1385 df_grow_bb_info (df_live
);
1387 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1389 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1391 /* When bitmaps are already initialized, just clear them. */
1392 if (bb_info
->kill
.obstack
)
1394 bitmap_clear (&bb_info
->kill
);
1395 bitmap_clear (&bb_info
->gen
);
1399 bitmap_initialize (&bb_info
->kill
, &problem_data
->live_bitmaps
);
1400 bitmap_initialize (&bb_info
->gen
, &problem_data
->live_bitmaps
);
1401 bitmap_initialize (&bb_info
->in
, &problem_data
->live_bitmaps
);
1402 bitmap_initialize (&bb_info
->out
, &problem_data
->live_bitmaps
);
1405 df_live
->optional_p
= (optimize
<= 1);
1409 /* Reset the global solution for recalculation. */
1412 df_live_reset (bitmap all_blocks
)
1414 unsigned int bb_index
;
1417 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1419 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1420 gcc_assert (bb_info
);
1421 bitmap_clear (&bb_info
->in
);
1422 bitmap_clear (&bb_info
->out
);
1427 /* Compute local uninitialized register info for basic block BB. */
1430 df_live_bb_local_compute (unsigned int bb_index
)
1432 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1433 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1438 FOR_BB_INSNS (bb
, insn
)
1440 unsigned int uid
= INSN_UID (insn
);
1441 struct df_insn_info
*insn_info
= DF_INSN_UID_GET (uid
);
1443 /* Inserting labels does not always trigger the incremental
1447 gcc_assert (!INSN_P (insn
));
1448 insn_info
= df_insn_create_insn_record (insn
);
1451 DF_INSN_INFO_LUID (insn_info
) = luid
;
1456 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1458 unsigned int regno
= DF_REF_REGNO (def
);
1460 if (DF_REF_FLAGS_IS_SET (def
,
1461 DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
1462 /* All partial or conditional def
1463 seen are included in the gen set. */
1464 bitmap_set_bit (&bb_info
->gen
, regno
);
1465 else if (DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
))
1466 /* Only must clobbers for the entire reg destroy the
1468 bitmap_set_bit (&bb_info
->kill
, regno
);
1469 else if (! DF_REF_FLAGS_IS_SET (def
, DF_REF_MAY_CLOBBER
))
1470 bitmap_set_bit (&bb_info
->gen
, regno
);
1474 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1475 bitmap_set_bit (&bb_info
->gen
, DF_REF_REGNO (def
));
1479 /* Compute local uninitialized register info. */
1482 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
1484 unsigned int bb_index
;
1487 df_grow_insn_info ();
1489 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
,
1492 df_live_bb_local_compute (bb_index
);
1495 bitmap_clear (df_live
->out_of_date_transfer_functions
);
1499 /* Initialize the solution vectors. */
1502 df_live_init (bitmap all_blocks
)
1504 unsigned int bb_index
;
1507 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1509 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1510 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1512 /* No register may reach a location where it is not used. Thus
1513 we trim the rr result to the places where it is used. */
1514 bitmap_and (&bb_info
->out
, &bb_info
->gen
, &bb_lr_info
->out
);
1515 bitmap_clear (&bb_info
->in
);
1519 /* Forward confluence function that ignores fake edges. */
1522 df_live_confluence_n (edge e
)
1524 bitmap op1
= &df_live_get_bb_info (e
->dest
->index
)->in
;
1525 bitmap op2
= &df_live_get_bb_info (e
->src
->index
)->out
;
1527 if (e
->flags
& EDGE_FAKE
)
1530 return bitmap_ior_into (op1
, op2
);
1534 /* Transfer function for the forwards must-initialized problem. */
1537 df_live_transfer_function (int bb_index
)
1539 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1540 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1541 bitmap in
= &bb_info
->in
;
1542 bitmap out
= &bb_info
->out
;
1543 bitmap gen
= &bb_info
->gen
;
1544 bitmap kill
= &bb_info
->kill
;
1546 /* We need to use a scratch set here so that the value returned from this
1547 function invocation properly reflects whether the sets changed in a
1548 significant way; i.e. not just because the lr set was anded in. */
1549 bitmap_and (&df_live_scratch
, gen
, &bb_lr_info
->out
);
1550 /* No register may reach a location where it is not used. Thus
1551 we trim the rr result to the places where it is used. */
1552 bitmap_and_into (in
, &bb_lr_info
->in
);
1554 return bitmap_ior_and_compl (out
, &df_live_scratch
, in
, kill
);
1558 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1561 df_live_finalize (bitmap all_blocks
)
1564 if (df_live
->solutions_dirty
)
1567 unsigned int bb_index
;
1569 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1571 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1572 struct df_live_bb_info
*bb_live_info
= df_live_get_bb_info (bb_index
);
1574 /* No register may reach a location where it is not used. Thus
1575 we trim the rr result to the places where it is used. */
1576 bitmap_and_into (&bb_live_info
->in
, &bb_lr_info
->in
);
1577 bitmap_and_into (&bb_live_info
->out
, &bb_lr_info
->out
);
1580 df_live
->solutions_dirty
= false;
1585 /* Free all storage associated with the problem. */
1590 struct df_live_problem_data
*problem_data
1591 = (struct df_live_problem_data
*) df_live
->problem_data
;
1592 if (df_live
->block_info
)
1594 df_live
->block_info_size
= 0;
1595 free (df_live
->block_info
);
1596 df_live
->block_info
= NULL
;
1597 bitmap_clear (&df_live_scratch
);
1598 bitmap_obstack_release (&problem_data
->live_bitmaps
);
1599 free (problem_data
);
1600 df_live
->problem_data
= NULL
;
1602 BITMAP_FREE (df_live
->out_of_date_transfer_functions
);
1607 /* Debugging info at top of bb. */
1610 df_live_top_dump (basic_block bb
, FILE *file
)
1612 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1613 struct df_live_problem_data
*problem_data
;
1618 fprintf (file
, ";; live in \t");
1619 df_print_regset (file
, &bb_info
->in
);
1620 if (df_live
->problem_data
)
1622 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1623 if (problem_data
->in
)
1625 fprintf (file
, ";; old in \t");
1626 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1629 fprintf (file
, ";; live gen \t");
1630 df_print_regset (file
, &bb_info
->gen
);
1631 fprintf (file
, ";; live kill\t");
1632 df_print_regset (file
, &bb_info
->kill
);
1636 /* Debugging info at bottom of bb. */
1639 df_live_bottom_dump (basic_block bb
, FILE *file
)
1641 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1642 struct df_live_problem_data
*problem_data
;
1647 fprintf (file
, ";; live out \t");
1648 df_print_regset (file
, &bb_info
->out
);
1649 if (df_live
->problem_data
)
1651 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1652 if (problem_data
->out
)
1654 fprintf (file
, ";; old out \t");
1655 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1661 /* Build the datastructure to verify that the solution to the dataflow
1662 equations is not dirty. */
1665 df_live_verify_solution_start (void)
1668 struct df_live_problem_data
*problem_data
;
1669 if (df_live
->solutions_dirty
)
1672 /* Set it true so that the solution is recomputed. */
1673 df_live
->solutions_dirty
= true;
1675 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1676 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1677 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1679 FOR_ALL_BB_FN (bb
, cfun
)
1681 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->live_bitmaps
);
1682 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->live_bitmaps
);
1683 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
));
1684 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
));
1689 /* Compare the saved datastructure and the new solution to the dataflow
1693 df_live_verify_solution_end (void)
1695 struct df_live_problem_data
*problem_data
;
1698 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1699 if (!problem_data
->out
)
1702 FOR_ALL_BB_FN (bb
, cfun
)
1704 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
)))
1705 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
))))
1707 /*df_dump (stderr);*/
1712 /* Cannot delete them immediately because you may want to dump them
1713 if the comparison fails. */
1714 FOR_ALL_BB_FN (bb
, cfun
)
1716 bitmap_clear (&problem_data
->in
[bb
->index
]);
1717 bitmap_clear (&problem_data
->out
[bb
->index
]);
1720 free (problem_data
->in
);
1721 free (problem_data
->out
);
1722 free (problem_data
);
1723 df_live
->problem_data
= NULL
;
1727 /* All of the information associated with every instance of the problem. */
1729 static struct df_problem problem_LIVE
=
1731 DF_LIVE
, /* Problem id. */
1732 DF_FORWARD
, /* Direction. */
1733 df_live_alloc
, /* Allocate the problem specific data. */
1734 df_live_reset
, /* Reset global information. */
1735 df_live_free_bb_info
, /* Free basic block info. */
1736 df_live_local_compute
, /* Local compute function. */
1737 df_live_init
, /* Init the solution specific data. */
1738 df_worklist_dataflow
, /* Worklist solver. */
1739 NULL
, /* Confluence operator 0. */
1740 df_live_confluence_n
, /* Confluence operator n. */
1741 df_live_transfer_function
, /* Transfer function. */
1742 df_live_finalize
, /* Finalize function. */
1743 df_live_free
, /* Free all of the problem information. */
1744 df_live_free
, /* Remove this problem from the stack of dataflow problems. */
1745 NULL
, /* Debugging. */
1746 df_live_top_dump
, /* Debugging start block. */
1747 df_live_bottom_dump
, /* Debugging end block. */
1748 NULL
, /* Debugging start insn. */
1749 NULL
, /* Debugging end insn. */
1750 df_live_verify_solution_start
,/* Incremental solution verify start. */
1751 df_live_verify_solution_end
, /* Incremental solution verify end. */
1752 &problem_LR
, /* Dependent problem. */
1753 sizeof (struct df_live_bb_info
),/* Size of entry of block_info array. */
1754 TV_DF_LIVE
, /* Timing variable. */
1755 false /* Reset blocks on dropping out of blocks_to_analyze. */
1759 /* Create a new DATAFLOW instance and add it to an existing instance
1760 of DF. The returned structure is what is used to get at the
1764 df_live_add_problem (void)
1766 df_add_problem (&problem_LIVE
);
1767 /* These will be initialized when df_scan_blocks processes each
1769 df_live
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1773 /* Set all of the blocks as dirty. This needs to be done if this
1774 problem is added after all of the insns have been scanned. */
1777 df_live_set_all_dirty (void)
1780 FOR_ALL_BB_FN (bb
, cfun
)
1781 bitmap_set_bit (df_live
->out_of_date_transfer_functions
,
1786 /* Verify that all of the lr related info is consistent and
1790 df_live_verify_transfer_functions (void)
1793 bitmap_head saved_gen
;
1794 bitmap_head saved_kill
;
1795 bitmap_head all_blocks
;
1800 bitmap_initialize (&saved_gen
, &bitmap_default_obstack
);
1801 bitmap_initialize (&saved_kill
, &bitmap_default_obstack
);
1802 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1804 df_grow_insn_info ();
1806 FOR_ALL_BB_FN (bb
, cfun
)
1808 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1809 bitmap_set_bit (&all_blocks
, bb
->index
);
1813 /* Make a copy of the transfer functions and then compute
1814 new ones to see if the transfer functions have
1816 if (!bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1819 bitmap_copy (&saved_gen
, &bb_info
->gen
);
1820 bitmap_copy (&saved_kill
, &bb_info
->kill
);
1821 bitmap_clear (&bb_info
->gen
);
1822 bitmap_clear (&bb_info
->kill
);
1824 df_live_bb_local_compute (bb
->index
);
1825 gcc_assert (bitmap_equal_p (&saved_gen
, &bb_info
->gen
));
1826 gcc_assert (bitmap_equal_p (&saved_kill
, &bb_info
->kill
));
1831 /* If we do not have basic block info, the block must be in
1832 the list of dirty blocks or else some one has added a
1833 block behind our backs. */
1834 gcc_assert (bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1837 /* Make sure no one created a block without following
1839 gcc_assert (df_scan_get_bb_info (bb
->index
));
1842 /* Make sure there are no dirty bits in blocks that have been deleted. */
1843 gcc_assert (!bitmap_intersect_compl_p (df_live
->out_of_date_transfer_functions
,
1845 bitmap_clear (&saved_gen
);
1846 bitmap_clear (&saved_kill
);
1847 bitmap_clear (&all_blocks
);
1850 /*----------------------------------------------------------------------------
1851 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1853 Link either the defs to the uses and / or the uses to the defs.
1855 These problems are set up like the other dataflow problems so that
1856 they nicely fit into the framework. They are much simpler and only
1857 involve a single traversal of instructions and an examination of
1858 the reaching defs information (the dependent problem).
1859 ----------------------------------------------------------------------------*/
1861 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1863 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1866 df_chain_create (df_ref src
, df_ref dst
)
1868 struct df_link
*head
= DF_REF_CHAIN (src
);
1869 struct df_link
*link
= df_chain
->block_pool
->allocate ();
1871 DF_REF_CHAIN (src
) = link
;
1878 /* Delete any du or ud chains that start at REF and point to
1881 df_chain_unlink_1 (df_ref ref
, df_ref target
)
1883 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1884 struct df_link
*prev
= NULL
;
1888 if (chain
->ref
== target
)
1891 prev
->next
= chain
->next
;
1893 DF_REF_CHAIN (ref
) = chain
->next
;
1894 df_chain
->block_pool
->remove (chain
);
1898 chain
= chain
->next
;
1903 /* Delete a du or ud chain that leave or point to REF. */
1906 df_chain_unlink (df_ref ref
)
1908 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1911 struct df_link
*next
= chain
->next
;
1912 /* Delete the other side if it exists. */
1913 df_chain_unlink_1 (chain
->ref
, ref
);
1914 df_chain
->block_pool
->remove (chain
);
1917 DF_REF_CHAIN (ref
) = NULL
;
1921 /* Copy the du or ud chain starting at FROM_REF and attach it to
1925 df_chain_copy (df_ref to_ref
,
1926 struct df_link
*from_ref
)
1930 df_chain_create (to_ref
, from_ref
->ref
);
1931 from_ref
= from_ref
->next
;
1936 /* Remove this problem from the stack of dataflow problems. */
1939 df_chain_remove_problem (void)
1942 unsigned int bb_index
;
1944 /* Wholesale destruction of the old chains. */
1945 if (df_chain
->block_pool
)
1946 delete df_chain
->block_pool
;
1948 EXECUTE_IF_SET_IN_BITMAP (df_chain
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1952 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1954 if (df_chain_problem_p (DF_DU_CHAIN
))
1955 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1956 DF_REF_CHAIN (def
) = NULL
;
1957 if (df_chain_problem_p (DF_UD_CHAIN
))
1958 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1959 DF_REF_CHAIN (use
) = NULL
;
1961 FOR_BB_INSNS (bb
, insn
)
1964 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1965 if (df_chain_problem_p (DF_DU_CHAIN
))
1966 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1967 DF_REF_CHAIN (def
) = NULL
;
1968 if (df_chain_problem_p (DF_UD_CHAIN
))
1970 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1971 DF_REF_CHAIN (use
) = NULL
;
1972 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1973 DF_REF_CHAIN (use
) = NULL
;
1978 bitmap_clear (df_chain
->out_of_date_transfer_functions
);
1979 df_chain
->block_pool
= NULL
;
1983 /* Remove the chain problem completely. */
1986 df_chain_fully_remove_problem (void)
1988 df_chain_remove_problem ();
1989 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
1994 /* Create def-use or use-def chains. */
1997 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
1999 df_chain_remove_problem ();
2000 df_chain
->block_pool
= new object_allocator
<df_link
> ("df_chain_block pool",
2002 df_chain
->optional_p
= true;
2006 /* Reset all of the chains when the set of basic blocks changes. */
2009 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED
)
2011 df_chain_remove_problem ();
2015 /* Create the chains for a list of USEs. */
2018 df_chain_create_bb_process_use (bitmap local_rd
,
2023 unsigned int def_index
;
2025 for (; use
; use
= DF_REF_NEXT_LOC (use
))
2027 unsigned int uregno
= DF_REF_REGNO (use
);
2028 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2029 || (uregno
>= FIRST_PSEUDO_REGISTER
))
2031 /* Do not want to go through this for an uninitialized var. */
2032 int count
= DF_DEFS_COUNT (uregno
);
2035 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2037 unsigned int first_index
= DF_DEFS_BEGIN (uregno
);
2038 unsigned int last_index
= first_index
+ count
- 1;
2040 EXECUTE_IF_SET_IN_BITMAP (local_rd
, first_index
, def_index
, bi
)
2043 if (def_index
> last_index
)
2046 def
= DF_DEFS_GET (def_index
);
2047 if (df_chain_problem_p (DF_DU_CHAIN
))
2048 df_chain_create (def
, use
);
2049 if (df_chain_problem_p (DF_UD_CHAIN
))
2050 df_chain_create (use
, def
);
2059 /* Create chains from reaching defs bitmaps for basic block BB. */
2062 df_chain_create_bb (unsigned int bb_index
)
2064 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2065 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
2069 bitmap_initialize (&cpy
, &bitmap_default_obstack
);
2070 bitmap_copy (&cpy
, &bb_info
->in
);
2071 bitmap_set_bit (df_chain
->out_of_date_transfer_functions
, bb_index
);
2073 /* Since we are going forwards, process the artificial uses first
2074 then the artificial defs second. */
2077 /* Create the chains for the artificial uses from the EH_USES at the
2078 beginning of the block. */
2080 /* Artificials are only hard regs. */
2081 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2082 df_chain_create_bb_process_use (&cpy
,
2083 df_get_artificial_uses (bb
->index
),
2087 df_rd_simulate_artificial_defs_at_top (bb
, &cpy
);
2089 /* Process the regular instructions next. */
2090 FOR_BB_INSNS (bb
, insn
)
2093 unsigned int uid
= INSN_UID (insn
);
2095 /* First scan the uses and link them up with the defs that remain
2096 in the cpy vector. */
2097 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_USES (uid
), 0);
2098 if (df
->changeable_flags
& DF_EQ_NOTES
)
2099 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_EQ_USES (uid
), 0);
2101 /* Since we are going forwards, process the defs second. */
2102 df_rd_simulate_one_insn (bb
, insn
, &cpy
);
2105 /* Create the chains for the artificial uses of the hard registers
2106 at the end of the block. */
2107 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2108 df_chain_create_bb_process_use (&cpy
,
2109 df_get_artificial_uses (bb
->index
),
2112 bitmap_clear (&cpy
);
2115 /* Create def-use chains from reaching use bitmaps for basic blocks
2119 df_chain_finalize (bitmap all_blocks
)
2121 unsigned int bb_index
;
2124 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2126 df_chain_create_bb (bb_index
);
2131 /* Free all storage associated with the problem. */
2134 df_chain_free (void)
2136 delete df_chain
->block_pool
;
2137 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
2142 /* Debugging info. */
2145 df_chain_bb_dump (basic_block bb
, FILE *file
, bool top
)
2147 /* Artificials are only hard regs. */
2148 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
2150 if (df_chain_problem_p (DF_UD_CHAIN
))
2155 ";; UD chains for artificial uses at %s\n",
2156 top
? "top" : "bottom");
2157 FOR_EACH_ARTIFICIAL_USE (use
, bb
->index
)
2158 if ((top
&& (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2159 || (!top
&& !(DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)))
2161 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2162 df_chain_dump (DF_REF_CHAIN (use
), file
);
2163 fprintf (file
, "\n");
2166 if (df_chain_problem_p (DF_DU_CHAIN
))
2171 ";; DU chains for artificial defs at %s\n",
2172 top
? "top" : "bottom");
2173 FOR_EACH_ARTIFICIAL_DEF (def
, bb
->index
)
2174 if ((top
&& (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
2175 || (!top
&& !(DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)))
2177 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2178 df_chain_dump (DF_REF_CHAIN (def
), file
);
2179 fprintf (file
, "\n");
2185 df_chain_top_dump (basic_block bb
, FILE *file
)
2187 df_chain_bb_dump (bb
, file
, /*top=*/true);
2191 df_chain_bottom_dump (basic_block bb
, FILE *file
)
2193 df_chain_bb_dump (bb
, file
, /*top=*/false);
2197 df_chain_insn_top_dump (const rtx_insn
*insn
, FILE *file
)
2199 if (df_chain_problem_p (DF_UD_CHAIN
) && INSN_P (insn
))
2201 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2204 fprintf (file
, ";; UD chains for insn luid %d uid %d\n",
2205 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2206 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2207 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2208 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2210 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2211 if (DF_REF_FLAGS (use
) & DF_REF_READ_WRITE
)
2212 fprintf (file
, "read/write ");
2213 df_chain_dump (DF_REF_CHAIN (use
), file
);
2214 fprintf (file
, "\n");
2216 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
2217 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2218 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2220 fprintf (file
, ";; eq_note reg %d ", DF_REF_REGNO (use
));
2221 df_chain_dump (DF_REF_CHAIN (use
), file
);
2222 fprintf (file
, "\n");
2228 df_chain_insn_bottom_dump (const rtx_insn
*insn
, FILE *file
)
2230 if (df_chain_problem_p (DF_DU_CHAIN
) && INSN_P (insn
))
2232 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2234 fprintf (file
, ";; DU chains for insn luid %d uid %d\n",
2235 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2236 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2237 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def
))
2238 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2240 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2241 if (DF_REF_FLAGS (def
) & DF_REF_READ_WRITE
)
2242 fprintf (file
, "read/write ");
2243 df_chain_dump (DF_REF_CHAIN (def
), file
);
2244 fprintf (file
, "\n");
2246 fprintf (file
, "\n");
2250 static struct df_problem problem_CHAIN
=
2252 DF_CHAIN
, /* Problem id. */
2253 DF_NONE
, /* Direction. */
2254 df_chain_alloc
, /* Allocate the problem specific data. */
2255 df_chain_reset
, /* Reset global information. */
2256 NULL
, /* Free basic block info. */
2257 NULL
, /* Local compute function. */
2258 NULL
, /* Init the solution specific data. */
2259 NULL
, /* Iterative solver. */
2260 NULL
, /* Confluence operator 0. */
2261 NULL
, /* Confluence operator n. */
2262 NULL
, /* Transfer function. */
2263 df_chain_finalize
, /* Finalize function. */
2264 df_chain_free
, /* Free all of the problem information. */
2265 df_chain_fully_remove_problem
,/* Remove this problem from the stack of dataflow problems. */
2266 NULL
, /* Debugging. */
2267 df_chain_top_dump
, /* Debugging start block. */
2268 df_chain_bottom_dump
, /* Debugging end block. */
2269 df_chain_insn_top_dump
, /* Debugging start insn. */
2270 df_chain_insn_bottom_dump
, /* Debugging end insn. */
2271 NULL
, /* Incremental solution verify start. */
2272 NULL
, /* Incremental solution verify end. */
2273 &problem_RD
, /* Dependent problem. */
2274 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
2275 TV_DF_CHAIN
, /* Timing variable. */
2276 false /* Reset blocks on dropping out of blocks_to_analyze. */
2280 /* Create a new DATAFLOW instance and add it to an existing instance
2281 of DF. The returned structure is what is used to get at the
2285 df_chain_add_problem (unsigned int chain_flags
)
2287 df_add_problem (&problem_CHAIN
);
2288 df_chain
->local_flags
= chain_flags
;
2289 df_chain
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2292 #undef df_chain_problem_p
2295 /*----------------------------------------------------------------------------
2296 WORD LEVEL LIVE REGISTERS
2298 Find the locations in the function where any use of a pseudo can
2299 reach in the backwards direction. In and out bitvectors are built
2300 for each basic block. We only track pseudo registers that have a
2301 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2302 contain two bits corresponding to each of the subwords.
2304 ----------------------------------------------------------------------------*/
2306 /* Private data used to verify the solution for this problem. */
2307 struct df_word_lr_problem_data
2309 /* An obstack for the bitmaps we need for this problem. */
2310 bitmap_obstack word_lr_bitmaps
;
2314 /* Free basic block info. */
2317 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
2320 struct df_word_lr_bb_info
*bb_info
= (struct df_word_lr_bb_info
*) vbb_info
;
2323 bitmap_clear (&bb_info
->use
);
2324 bitmap_clear (&bb_info
->def
);
2325 bitmap_clear (&bb_info
->in
);
2326 bitmap_clear (&bb_info
->out
);
2331 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2332 not touched unless the block is new. */
2335 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2337 unsigned int bb_index
;
2340 struct df_word_lr_problem_data
*problem_data
2341 = XNEW (struct df_word_lr_problem_data
);
2343 df_word_lr
->problem_data
= problem_data
;
2345 df_grow_bb_info (df_word_lr
);
2347 /* Create the mapping from regnos to slots. This does not change
2348 unless the problem is destroyed and recreated. In particular, if
2349 we end up deleting the only insn that used a subreg, we do not
2350 want to redo the mapping because this would invalidate everything
2353 bitmap_obstack_initialize (&problem_data
->word_lr_bitmaps
);
2355 FOR_EACH_BB_FN (bb
, cfun
)
2356 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, bb
->index
);
2358 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, ENTRY_BLOCK
);
2359 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, EXIT_BLOCK
);
2361 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2363 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2365 /* When bitmaps are already initialized, just clear them. */
2366 if (bb_info
->use
.obstack
)
2368 bitmap_clear (&bb_info
->def
);
2369 bitmap_clear (&bb_info
->use
);
2373 bitmap_initialize (&bb_info
->use
, &problem_data
->word_lr_bitmaps
);
2374 bitmap_initialize (&bb_info
->def
, &problem_data
->word_lr_bitmaps
);
2375 bitmap_initialize (&bb_info
->in
, &problem_data
->word_lr_bitmaps
);
2376 bitmap_initialize (&bb_info
->out
, &problem_data
->word_lr_bitmaps
);
2380 df_word_lr
->optional_p
= true;
2384 /* Reset the global solution for recalculation. */
2387 df_word_lr_reset (bitmap all_blocks
)
2389 unsigned int bb_index
;
2392 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2394 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2395 gcc_assert (bb_info
);
2396 bitmap_clear (&bb_info
->in
);
2397 bitmap_clear (&bb_info
->out
);
2401 /* Examine REF, and if it is for a reg we're interested in, set or
2402 clear the bits corresponding to its subwords from the bitmap
2403 according to IS_SET. LIVE is the bitmap we should update. We do
2404 not track hard regs or pseudos of any size other than 2 *
2406 We return true if we changed the bitmap, or if we encountered a register
2407 we're not tracking. */
2410 df_word_lr_mark_ref (df_ref ref
, bool is_set
, regset live
)
2412 rtx orig_reg
= DF_REF_REG (ref
);
2414 machine_mode reg_mode
;
2416 /* Left at -1 for whole accesses. */
2417 int which_subword
= -1;
2418 bool changed
= false;
2420 if (GET_CODE (reg
) == SUBREG
)
2421 reg
= SUBREG_REG (orig_reg
);
2422 regno
= REGNO (reg
);
2423 reg_mode
= GET_MODE (reg
);
2424 if (regno
< FIRST_PSEUDO_REGISTER
2425 || GET_MODE_SIZE (reg_mode
) != 2 * UNITS_PER_WORD
)
2428 if (GET_CODE (orig_reg
) == SUBREG
2429 && df_read_modify_subreg_p (orig_reg
))
2431 gcc_assert (DF_REF_FLAGS_IS_SET (ref
, DF_REF_PARTIAL
));
2432 if (subreg_lowpart_p (orig_reg
))
2439 if (which_subword
!= 1)
2440 changed
|= bitmap_set_bit (live
, regno
* 2);
2441 if (which_subword
!= 0)
2442 changed
|= bitmap_set_bit (live
, regno
* 2 + 1);
2446 if (which_subword
!= 1)
2447 changed
|= bitmap_clear_bit (live
, regno
* 2);
2448 if (which_subword
!= 0)
2449 changed
|= bitmap_clear_bit (live
, regno
* 2 + 1);
2454 /* Compute local live register info for basic block BB. */
2457 df_word_lr_bb_local_compute (unsigned int bb_index
)
2459 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2460 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2464 /* Ensure that artificial refs don't contain references to pseudos. */
2465 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
2466 gcc_assert (DF_REF_REGNO (def
) < FIRST_PSEUDO_REGISTER
);
2468 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
2469 gcc_assert (DF_REF_REGNO (use
) < FIRST_PSEUDO_REGISTER
);
2471 FOR_BB_INSNS_REVERSE (bb
, insn
)
2473 if (!NONDEBUG_INSN_P (insn
))
2476 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2477 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2478 /* If the def is to only part of the reg, it does
2479 not kill the other defs that reach here. */
2480 if (!(DF_REF_FLAGS (def
) & (DF_REF_CONDITIONAL
)))
2482 df_word_lr_mark_ref (def
, true, &bb_info
->def
);
2483 df_word_lr_mark_ref (def
, false, &bb_info
->use
);
2485 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2486 df_word_lr_mark_ref (use
, true, &bb_info
->use
);
2491 /* Compute local live register info for each basic block within BLOCKS. */
2494 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
2496 unsigned int bb_index
;
2499 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2501 if (bb_index
== EXIT_BLOCK
)
2505 EXECUTE_IF_SET_IN_BITMAP (df
->exit_block_uses
, FIRST_PSEUDO_REGISTER
,
2510 df_word_lr_bb_local_compute (bb_index
);
2513 bitmap_clear (df_word_lr
->out_of_date_transfer_functions
);
2517 /* Initialize the solution vectors. */
2520 df_word_lr_init (bitmap all_blocks
)
2522 unsigned int bb_index
;
2525 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2527 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2528 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
2529 bitmap_clear (&bb_info
->out
);
2534 /* Confluence function that ignores fake edges. */
2537 df_word_lr_confluence_n (edge e
)
2539 bitmap op1
= &df_word_lr_get_bb_info (e
->src
->index
)->out
;
2540 bitmap op2
= &df_word_lr_get_bb_info (e
->dest
->index
)->in
;
2542 return bitmap_ior_into (op1
, op2
);
2546 /* Transfer function. */
2549 df_word_lr_transfer_function (int bb_index
)
2551 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2552 bitmap in
= &bb_info
->in
;
2553 bitmap out
= &bb_info
->out
;
2554 bitmap use
= &bb_info
->use
;
2555 bitmap def
= &bb_info
->def
;
2557 return bitmap_ior_and_compl (in
, use
, out
, def
);
2561 /* Free all storage associated with the problem. */
2564 df_word_lr_free (void)
2566 struct df_word_lr_problem_data
*problem_data
2567 = (struct df_word_lr_problem_data
*)df_word_lr
->problem_data
;
2569 if (df_word_lr
->block_info
)
2571 df_word_lr
->block_info_size
= 0;
2572 free (df_word_lr
->block_info
);
2573 df_word_lr
->block_info
= NULL
;
2576 BITMAP_FREE (df_word_lr
->out_of_date_transfer_functions
);
2577 bitmap_obstack_release (&problem_data
->word_lr_bitmaps
);
2578 free (problem_data
);
2583 /* Debugging info at top of bb. */
2586 df_word_lr_top_dump (basic_block bb
, FILE *file
)
2588 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2592 fprintf (file
, ";; blr in \t");
2593 df_print_word_regset (file
, &bb_info
->in
);
2594 fprintf (file
, ";; blr use \t");
2595 df_print_word_regset (file
, &bb_info
->use
);
2596 fprintf (file
, ";; blr def \t");
2597 df_print_word_regset (file
, &bb_info
->def
);
2601 /* Debugging info at bottom of bb. */
2604 df_word_lr_bottom_dump (basic_block bb
, FILE *file
)
2606 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2610 fprintf (file
, ";; blr out \t");
2611 df_print_word_regset (file
, &bb_info
->out
);
2615 /* All of the information associated with every instance of the problem. */
2617 static struct df_problem problem_WORD_LR
=
2619 DF_WORD_LR
, /* Problem id. */
2620 DF_BACKWARD
, /* Direction. */
2621 df_word_lr_alloc
, /* Allocate the problem specific data. */
2622 df_word_lr_reset
, /* Reset global information. */
2623 df_word_lr_free_bb_info
, /* Free basic block info. */
2624 df_word_lr_local_compute
, /* Local compute function. */
2625 df_word_lr_init
, /* Init the solution specific data. */
2626 df_worklist_dataflow
, /* Worklist solver. */
2627 NULL
, /* Confluence operator 0. */
2628 df_word_lr_confluence_n
, /* Confluence operator n. */
2629 df_word_lr_transfer_function
, /* Transfer function. */
2630 NULL
, /* Finalize function. */
2631 df_word_lr_free
, /* Free all of the problem information. */
2632 df_word_lr_free
, /* Remove this problem from the stack of dataflow problems. */
2633 NULL
, /* Debugging. */
2634 df_word_lr_top_dump
, /* Debugging start block. */
2635 df_word_lr_bottom_dump
, /* Debugging end block. */
2636 NULL
, /* Debugging start insn. */
2637 NULL
, /* Debugging end insn. */
2638 NULL
, /* Incremental solution verify start. */
2639 NULL
, /* Incremental solution verify end. */
2640 NULL
, /* Dependent problem. */
2641 sizeof (struct df_word_lr_bb_info
),/* Size of entry of block_info array. */
2642 TV_DF_WORD_LR
, /* Timing variable. */
2643 false /* Reset blocks on dropping out of blocks_to_analyze. */
2647 /* Create a new DATAFLOW instance and add it to an existing instance
2648 of DF. The returned structure is what is used to get at the
2652 df_word_lr_add_problem (void)
2654 df_add_problem (&problem_WORD_LR
);
2655 /* These will be initialized when df_scan_blocks processes each
2657 df_word_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2661 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2662 any bits, which is used by the caller to determine whether a set is
2663 necessary. We also return true if there are other reasons not to delete
2667 df_word_lr_simulate_defs (rtx_insn
*insn
, bitmap live
)
2669 bool changed
= false;
2672 FOR_EACH_INSN_DEF (def
, insn
)
2673 if (DF_REF_FLAGS (def
) & DF_REF_CONDITIONAL
)
2676 changed
|= df_word_lr_mark_ref (def
, false, live
);
2681 /* Simulate the effects of the uses of INSN on LIVE. */
2684 df_word_lr_simulate_uses (rtx_insn
*insn
, bitmap live
)
2688 FOR_EACH_INSN_USE (use
, insn
)
2689 df_word_lr_mark_ref (use
, true, live
);
2692 /*----------------------------------------------------------------------------
2693 This problem computes REG_DEAD and REG_UNUSED notes.
2694 ----------------------------------------------------------------------------*/
2697 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2699 df_note
->optional_p
= true;
2702 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2704 df_print_note (const char *prefix
, rtx_insn
*insn
, rtx note
)
2708 fprintf (dump_file
, "%s %d ", prefix
, INSN_UID (insn
));
2709 print_rtl (dump_file
, note
);
2710 fprintf (dump_file
, "\n");
2715 /* After reg-stack, the x86 floating point stack regs are difficult to
2716 analyze because of all of the pushes, pops and rotations. Thus, we
2717 just leave the notes alone. */
2721 df_ignore_stack_reg (int regno
)
2723 return regstack_completed
2724 && IN_RANGE (regno
, FIRST_STACK_REG
, LAST_STACK_REG
);
2728 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED
)
2735 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
2738 df_remove_dead_and_unused_notes (rtx_insn
*insn
)
2740 rtx
*pprev
= ®_NOTES (insn
);
2745 switch (REG_NOTE_KIND (link
))
2748 /* After reg-stack, we need to ignore any unused notes
2749 for the stack registers. */
2750 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2752 pprev
= &XEXP (link
, 1);
2757 rtx next
= XEXP (link
, 1);
2758 if (REG_DEAD_DEBUGGING
)
2759 df_print_note ("deleting: ", insn
, link
);
2760 free_EXPR_LIST_node (link
);
2761 *pprev
= link
= next
;
2766 /* After reg-stack, we need to ignore any unused notes
2767 for the stack registers. */
2768 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2770 pprev
= &XEXP (link
, 1);
2775 rtx next
= XEXP (link
, 1);
2776 if (REG_DEAD_DEBUGGING
)
2777 df_print_note ("deleting: ", insn
, link
);
2778 free_EXPR_LIST_node (link
);
2779 *pprev
= link
= next
;
2784 pprev
= &XEXP (link
, 1);
2791 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2792 as the bitmap of currently live registers. */
2795 df_remove_dead_eq_notes (rtx_insn
*insn
, bitmap live
)
2797 rtx
*pprev
= ®_NOTES (insn
);
2802 switch (REG_NOTE_KIND (link
))
2807 /* Remove the notes that refer to dead registers. As we have at most
2808 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2809 so we need to purge the complete EQ_USES vector when removing
2810 the note using df_notes_rescan. */
2812 bool deleted
= false;
2814 FOR_EACH_INSN_EQ_USE (use
, insn
)
2815 if (DF_REF_REGNO (use
) > FIRST_PSEUDO_REGISTER
2817 && (DF_REF_FLAGS (use
) & DF_REF_IN_NOTE
)
2818 && !bitmap_bit_p (live
, DF_REF_REGNO (use
))
2819 && loc_mentioned_in_p (DF_REF_LOC (use
), XEXP (link
, 0)))
2827 if (REG_DEAD_DEBUGGING
)
2828 df_print_note ("deleting: ", insn
, link
);
2829 next
= XEXP (link
, 1);
2830 free_EXPR_LIST_node (link
);
2831 *pprev
= link
= next
;
2832 df_notes_rescan (insn
);
2836 pprev
= &XEXP (link
, 1);
2843 pprev
= &XEXP (link
, 1);
2850 /* Set a NOTE_TYPE note for REG in INSN. */
2853 df_set_note (enum reg_note note_type
, rtx_insn
*insn
, rtx reg
)
2855 gcc_checking_assert (!DEBUG_INSN_P (insn
));
2856 add_reg_note (insn
, note_type
, reg
);
2859 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2860 arguments. Return true if the register value described by MWS's
2861 mw_reg is known to be completely unused, and if mw_reg can therefore
2862 be used in a REG_UNUSED note. */
2865 df_whole_mw_reg_unused_p (struct df_mw_hardreg
*mws
,
2866 bitmap live
, bitmap artificial_uses
)
2870 /* If MWS describes a partial reference, create REG_UNUSED notes for
2871 individual hard registers. */
2872 if (mws
->flags
& DF_REF_PARTIAL
)
2875 /* Likewise if some part of the register is used. */
2876 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2877 if (bitmap_bit_p (live
, r
)
2878 || bitmap_bit_p (artificial_uses
, r
))
2881 gcc_assert (REG_P (mws
->mw_reg
));
2886 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2887 based on the bits in LIVE. Do not generate notes for registers in
2888 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2889 not generated if the reg is both read and written by the
2894 df_set_unused_notes_for_mw (rtx_insn
*insn
, struct df_mw_hardreg
*mws
,
2895 bitmap live
, bitmap do_not_gen
,
2896 bitmap artificial_uses
,
2897 struct dead_debug_local
*debug
)
2901 if (REG_DEAD_DEBUGGING
&& dump_file
)
2902 fprintf (dump_file
, "mw_set_unused looking at mws[%d..%d]\n",
2903 mws
->start_regno
, mws
->end_regno
);
2905 if (df_whole_mw_reg_unused_p (mws
, live
, artificial_uses
))
2907 unsigned int regno
= mws
->start_regno
;
2908 df_set_note (REG_UNUSED
, insn
, mws
->mw_reg
);
2909 dead_debug_insert_temp (debug
, regno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
2911 if (REG_DEAD_DEBUGGING
)
2912 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
2914 bitmap_set_bit (do_not_gen
, regno
);
2915 /* Only do this if the value is totally dead. */
2918 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2920 if (!bitmap_bit_p (live
, r
)
2921 && !bitmap_bit_p (artificial_uses
, r
))
2923 df_set_note (REG_UNUSED
, insn
, regno_reg_rtx
[r
]);
2924 dead_debug_insert_temp (debug
, r
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
2925 if (REG_DEAD_DEBUGGING
)
2926 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
2928 bitmap_set_bit (do_not_gen
, r
);
2933 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2934 arguments. Return true if the register value described by MWS's
2935 mw_reg is known to be completely dead, and if mw_reg can therefore
2936 be used in a REG_DEAD note. */
2939 df_whole_mw_reg_dead_p (struct df_mw_hardreg
*mws
,
2940 bitmap live
, bitmap artificial_uses
,
2945 /* If MWS describes a partial reference, create REG_DEAD notes for
2946 individual hard registers. */
2947 if (mws
->flags
& DF_REF_PARTIAL
)
2950 /* Likewise if some part of the register is not dead. */
2951 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2952 if (bitmap_bit_p (live
, r
)
2953 || bitmap_bit_p (artificial_uses
, r
)
2954 || bitmap_bit_p (do_not_gen
, r
))
2957 gcc_assert (REG_P (mws
->mw_reg
));
2961 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2962 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2963 from being set if the instruction both reads and writes the
2967 df_set_dead_notes_for_mw (rtx_insn
*insn
, struct df_mw_hardreg
*mws
,
2968 bitmap live
, bitmap do_not_gen
,
2969 bitmap artificial_uses
, bool *added_notes_p
)
2972 bool is_debug
= *added_notes_p
;
2974 *added_notes_p
= false;
2976 if (REG_DEAD_DEBUGGING
&& dump_file
)
2978 fprintf (dump_file
, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2979 mws
->start_regno
, mws
->end_regno
);
2980 df_print_regset (dump_file
, do_not_gen
);
2981 fprintf (dump_file
, " live =");
2982 df_print_regset (dump_file
, live
);
2983 fprintf (dump_file
, " artificial uses =");
2984 df_print_regset (dump_file
, artificial_uses
);
2987 if (df_whole_mw_reg_dead_p (mws
, live
, artificial_uses
, do_not_gen
))
2991 *added_notes_p
= true;
2994 /* Add a dead note for the entire multi word register. */
2995 df_set_note (REG_DEAD
, insn
, mws
->mw_reg
);
2996 if (REG_DEAD_DEBUGGING
)
2997 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
3001 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
3002 if (!bitmap_bit_p (live
, r
)
3003 && !bitmap_bit_p (artificial_uses
, r
)
3004 && !bitmap_bit_p (do_not_gen
, r
))
3008 *added_notes_p
= true;
3011 df_set_note (REG_DEAD
, insn
, regno_reg_rtx
[r
]);
3012 if (REG_DEAD_DEBUGGING
)
3013 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
3020 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3021 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3024 df_create_unused_note (rtx_insn
*insn
, df_ref def
,
3025 bitmap live
, bitmap artificial_uses
,
3026 struct dead_debug_local
*debug
)
3028 unsigned int dregno
= DF_REF_REGNO (def
);
3030 if (REG_DEAD_DEBUGGING
&& dump_file
)
3032 fprintf (dump_file
, " regular looking at def ");
3033 df_ref_debug (def
, dump_file
);
3036 if (!((DF_REF_FLAGS (def
) & DF_REF_MW_HARDREG
)
3037 || bitmap_bit_p (live
, dregno
)
3038 || bitmap_bit_p (artificial_uses
, dregno
)
3039 || df_ignore_stack_reg (dregno
)))
3041 rtx reg
= (DF_REF_LOC (def
))
3042 ? *DF_REF_REAL_LOC (def
): DF_REF_REG (def
);
3043 df_set_note (REG_UNUSED
, insn
, reg
);
3044 dead_debug_insert_temp (debug
, dregno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
3045 if (REG_DEAD_DEBUGGING
)
3046 df_print_note ("adding 3: ", insn
, REG_NOTES (insn
));
3053 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3054 info: lifetime, bb, and number of defs and uses for basic block
3055 BB. The three bitvectors are scratch regs used here. */
3058 df_note_bb_compute (unsigned int bb_index
,
3059 bitmap live
, bitmap do_not_gen
, bitmap artificial_uses
)
3061 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3064 struct dead_debug_local debug
;
3066 dead_debug_local_init (&debug
, NULL
, NULL
);
3068 bitmap_copy (live
, df_get_live_out (bb
));
3069 bitmap_clear (artificial_uses
);
3071 if (REG_DEAD_DEBUGGING
&& dump_file
)
3073 fprintf (dump_file
, "live at bottom ");
3074 df_print_regset (dump_file
, live
);
3077 /* Process the artificial defs and uses at the bottom of the block
3078 to begin processing. */
3079 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3081 if (REG_DEAD_DEBUGGING
&& dump_file
)
3082 fprintf (dump_file
, "artificial def %d\n", DF_REF_REGNO (def
));
3084 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3085 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3088 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3089 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3091 unsigned int regno
= DF_REF_REGNO (use
);
3092 bitmap_set_bit (live
, regno
);
3094 /* Notes are not generated for any of the artificial registers
3095 at the bottom of the block. */
3096 bitmap_set_bit (artificial_uses
, regno
);
3099 if (REG_DEAD_DEBUGGING
&& dump_file
)
3101 fprintf (dump_file
, "live before artificials out ");
3102 df_print_regset (dump_file
, live
);
3105 FOR_BB_INSNS_REVERSE (bb
, insn
)
3107 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3114 debug_insn
= DEBUG_INSN_P (insn
);
3116 bitmap_clear (do_not_gen
);
3117 df_remove_dead_and_unused_notes (insn
);
3119 /* Process the defs. */
3122 if (REG_DEAD_DEBUGGING
&& dump_file
)
3124 fprintf (dump_file
, "processing call %d\n live =",
3126 df_print_regset (dump_file
, live
);
3129 /* We only care about real sets for calls. Clobbers cannot
3130 be depended on to really die. */
3131 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3132 if ((DF_MWS_REG_DEF_P (mw
))
3133 && !df_ignore_stack_reg (mw
->start_regno
))
3134 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3135 artificial_uses
, &debug
);
3137 /* All of the defs except the return value are some sort of
3138 clobber. This code is for the return. */
3139 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3141 unsigned int dregno
= DF_REF_REGNO (def
);
3142 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3144 df_create_unused_note (insn
,
3145 def
, live
, artificial_uses
, &debug
);
3146 bitmap_set_bit (do_not_gen
, dregno
);
3149 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3150 bitmap_clear_bit (live
, dregno
);
3156 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3157 if (DF_MWS_REG_DEF_P (mw
))
3158 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3159 artificial_uses
, &debug
);
3161 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3163 unsigned int dregno
= DF_REF_REGNO (def
);
3164 df_create_unused_note (insn
,
3165 def
, live
, artificial_uses
, &debug
);
3167 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3168 bitmap_set_bit (do_not_gen
, dregno
);
3170 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3171 bitmap_clear_bit (live
, dregno
);
3175 /* Process the uses. */
3176 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3177 if (DF_MWS_REG_USE_P (mw
)
3178 && !df_ignore_stack_reg (mw
->start_regno
))
3180 bool really_add_notes
= debug_insn
!= 0;
3182 df_set_dead_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3186 if (really_add_notes
)
3190 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3192 unsigned int uregno
= DF_REF_REGNO (use
);
3194 if (REG_DEAD_DEBUGGING
&& dump_file
&& !debug_insn
)
3196 fprintf (dump_file
, " regular looking at use ");
3197 df_ref_debug (use
, dump_file
);
3200 if (!bitmap_bit_p (live
, uregno
))
3206 /* We won't add REG_UNUSED or REG_DEAD notes for
3207 these, so we don't have to mess with them in
3208 debug insns either. */
3209 if (!bitmap_bit_p (artificial_uses
, uregno
)
3210 && !df_ignore_stack_reg (uregno
))
3211 dead_debug_add (&debug
, use
, uregno
);
3217 dead_debug_insert_temp (&debug
, uregno
, insn
,
3218 DEBUG_TEMP_BEFORE_WITH_REG
);
3220 if ( (!(DF_REF_FLAGS (use
)
3221 & (DF_REF_MW_HARDREG
| DF_REF_READ_WRITE
)))
3222 && (!bitmap_bit_p (do_not_gen
, uregno
))
3223 && (!bitmap_bit_p (artificial_uses
, uregno
))
3224 && (!df_ignore_stack_reg (uregno
)))
3226 rtx reg
= (DF_REF_LOC (use
))
3227 ? *DF_REF_REAL_LOC (use
) : DF_REF_REG (use
);
3228 df_set_note (REG_DEAD
, insn
, reg
);
3230 if (REG_DEAD_DEBUGGING
)
3231 df_print_note ("adding 4: ", insn
, REG_NOTES (insn
));
3233 /* This register is now live. */
3234 bitmap_set_bit (live
, uregno
);
3238 df_remove_dead_eq_notes (insn
, live
);
3240 if (debug_insn
== -1)
3242 /* ??? We could probably do better here, replacing dead
3243 registers with their definitions. */
3244 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
3245 df_insn_rescan_debug_internal (insn
);
3249 dead_debug_local_finish (&debug
, NULL
);
3253 /* Compute register info: lifetime, bb, and number of defs and uses. */
3255 df_note_compute (bitmap all_blocks
)
3257 unsigned int bb_index
;
3259 bitmap_head live
, do_not_gen
, artificial_uses
;
3261 bitmap_initialize (&live
, &df_bitmap_obstack
);
3262 bitmap_initialize (&do_not_gen
, &df_bitmap_obstack
);
3263 bitmap_initialize (&artificial_uses
, &df_bitmap_obstack
);
3265 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
3267 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3268 pseudos in debug insns because we don't always (re)visit blocks
3269 with death points after visiting dead uses. Even changing this
3270 loop to postorder would still leave room for visiting a death
3271 point before visiting a subsequent debug use. */
3272 df_note_bb_compute (bb_index
, &live
, &do_not_gen
, &artificial_uses
);
3275 bitmap_clear (&live
);
3276 bitmap_clear (&do_not_gen
);
3277 bitmap_clear (&artificial_uses
);
3281 /* Free all storage associated with the problem. */
3290 /* All of the information associated every instance of the problem. */
3292 static struct df_problem problem_NOTE
=
3294 DF_NOTE
, /* Problem id. */
3295 DF_NONE
, /* Direction. */
3296 df_note_alloc
, /* Allocate the problem specific data. */
3297 NULL
, /* Reset global information. */
3298 NULL
, /* Free basic block info. */
3299 df_note_compute
, /* Local compute function. */
3300 NULL
, /* Init the solution specific data. */
3301 NULL
, /* Iterative solver. */
3302 NULL
, /* Confluence operator 0. */
3303 NULL
, /* Confluence operator n. */
3304 NULL
, /* Transfer function. */
3305 NULL
, /* Finalize function. */
3306 df_note_free
, /* Free all of the problem information. */
3307 df_note_free
, /* Remove this problem from the stack of dataflow problems. */
3308 NULL
, /* Debugging. */
3309 NULL
, /* Debugging start block. */
3310 NULL
, /* Debugging end block. */
3311 NULL
, /* Debugging start insn. */
3312 NULL
, /* Debugging end insn. */
3313 NULL
, /* Incremental solution verify start. */
3314 NULL
, /* Incremental solution verify end. */
3315 &problem_LR
, /* Dependent problem. */
3316 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
3317 TV_DF_NOTE
, /* Timing variable. */
3318 false /* Reset blocks on dropping out of blocks_to_analyze. */
3322 /* Create a new DATAFLOW instance and add it to an existing instance
3323 of DF. The returned structure is what is used to get at the
3327 df_note_add_problem (void)
3329 df_add_problem (&problem_NOTE
);
3335 /*----------------------------------------------------------------------------
3336 Functions for simulating the effects of single insns.
3338 You can either simulate in the forwards direction, starting from
3339 the top of a block or the backwards direction from the end of the
3340 block. If you go backwards, defs are examined first to clear bits,
3341 then uses are examined to set bits. If you go forwards, defs are
3342 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3343 are examined to clear bits. In either case, the result of examining
3344 a def can be undone (respectively by a use or a REG_UNUSED note).
3346 If you start at the top of the block, use one of DF_LIVE_IN or
3347 DF_LR_IN. If you start at the bottom of the block use one of
3348 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3349 THEY WILL BE DESTROYED.
3350 ----------------------------------------------------------------------------*/
3353 /* Find the set of DEFs for INSN. */
3356 df_simulate_find_defs (rtx_insn
*insn
, bitmap defs
)
3360 FOR_EACH_INSN_DEF (def
, insn
)
3361 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3364 /* Find the set of uses for INSN. This includes partial defs. */
3367 df_simulate_find_uses (rtx_insn
*insn
, bitmap uses
)
3370 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3372 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3373 if (DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3374 bitmap_set_bit (uses
, DF_REF_REGNO (def
));
3375 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3376 bitmap_set_bit (uses
, DF_REF_REGNO (use
));
3379 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3382 df_simulate_find_noclobber_defs (rtx_insn
*insn
, bitmap defs
)
3386 FOR_EACH_INSN_DEF (def
, insn
)
3387 if (!(DF_REF_FLAGS (def
) & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
3388 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3392 /* Simulate the effects of the defs of INSN on LIVE. */
3395 df_simulate_defs (rtx_insn
*insn
, bitmap live
)
3399 FOR_EACH_INSN_DEF (def
, insn
)
3401 unsigned int dregno
= DF_REF_REGNO (def
);
3403 /* If the def is to only part of the reg, it does
3404 not kill the other defs that reach here. */
3405 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
3406 bitmap_clear_bit (live
, dregno
);
3411 /* Simulate the effects of the uses of INSN on LIVE. */
3414 df_simulate_uses (rtx_insn
*insn
, bitmap live
)
3418 if (DEBUG_INSN_P (insn
))
3421 FOR_EACH_INSN_USE (use
, insn
)
3422 /* Add use to set of uses in this BB. */
3423 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3427 /* Add back the always live regs in BB to LIVE. */
3430 df_simulate_fixup_sets (basic_block bb
, bitmap live
)
3432 /* These regs are considered always live so if they end up dying
3433 because of some def, we need to bring the back again. */
3434 if (bb_has_eh_pred (bb
))
3435 bitmap_ior_into (live
, &df
->eh_block_artificial_uses
);
3437 bitmap_ior_into (live
, &df
->regular_block_artificial_uses
);
3441 /*----------------------------------------------------------------------------
3442 The following three functions are used only for BACKWARDS scanning:
3443 i.e. they process the defs before the uses.
3445 df_simulate_initialize_backwards should be called first with a
3446 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3447 df_simulate_one_insn_backwards should be called for each insn in
3448 the block, starting with the last one. Finally,
3449 df_simulate_finalize_backwards can be called to get a new value
3450 of the sets at the top of the block (this is rarely used).
3451 ----------------------------------------------------------------------------*/
3453 /* Apply the artificial uses and defs at the end of BB in a backwards
3457 df_simulate_initialize_backwards (basic_block bb
, bitmap live
)
3460 int bb_index
= bb
->index
;
3462 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3463 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3464 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3466 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3467 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3468 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3472 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3475 df_simulate_one_insn_backwards (basic_block bb
, rtx_insn
*insn
, bitmap live
)
3477 if (!NONDEBUG_INSN_P (insn
))
3480 df_simulate_defs (insn
, live
);
3481 df_simulate_uses (insn
, live
);
3482 df_simulate_fixup_sets (bb
, live
);
3486 /* Apply the artificial uses and defs at the top of BB in a backwards
3490 df_simulate_finalize_backwards (basic_block bb
, bitmap live
)
3496 int bb_index
= bb
->index
;
3498 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3499 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3500 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3503 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3504 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
3505 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3508 /*----------------------------------------------------------------------------
3509 The following three functions are used only for FORWARDS scanning:
3510 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3511 Thus it is important to add the DF_NOTES problem to the stack of
3512 problems computed before using these functions.
3514 df_simulate_initialize_forwards should be called first with a
3515 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3516 df_simulate_one_insn_forwards should be called for each insn in
3517 the block, starting with the first one.
3518 ----------------------------------------------------------------------------*/
3520 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3521 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3525 df_simulate_initialize_forwards (basic_block bb
, bitmap live
)
3528 int bb_index
= bb
->index
;
3530 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3531 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3532 bitmap_set_bit (live
, DF_REF_REGNO (def
));
3535 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3538 df_simulate_one_insn_forwards (basic_block bb
, rtx_insn
*insn
, bitmap live
)
3541 if (! INSN_P (insn
))
3544 /* Make sure that DF_NOTE really is an active df problem. */
3545 gcc_assert (df_note
);
3547 /* Note that this is the opposite as how the problem is defined, because
3548 in the LR problem defs _kill_ liveness. However, they do so backwards,
3549 while here the scan is performed forwards! So, first assume that the
3550 def is live, and if this is not true REG_UNUSED notes will rectify the
3552 df_simulate_find_noclobber_defs (insn
, live
);
3554 /* Clear all of the registers that go dead. */
3555 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
3557 switch (REG_NOTE_KIND (link
))
3562 rtx reg
= XEXP (link
, 0);
3563 bitmap_clear_range (live
, REGNO (reg
), REG_NREGS (reg
));
3570 df_simulate_fixup_sets (bb
, live
);
3573 /* Used by the next two functions to encode information about the
3574 memory references we found. */
3575 #define MEMREF_NORMAL 1
3576 #define MEMREF_VOLATILE 2
3578 /* Return an OR of MEMREF_NORMAL or MEMREF_VOLATILE for the MEMs in X. */
3581 find_memory (rtx_insn
*insn
)
3584 subrtx_iterator::array_type array
;
3585 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), NONCONST
)
3587 const_rtx x
= *iter
;
3588 if (GET_CODE (x
) == ASM_OPERANDS
&& MEM_VOLATILE_P (x
))
3589 flags
|= MEMREF_VOLATILE
;
3592 if (MEM_VOLATILE_P (x
))
3593 flags
|= MEMREF_VOLATILE
;
3594 else if (!MEM_READONLY_P (x
))
3595 flags
|= MEMREF_NORMAL
;
3601 /* A subroutine of can_move_insns_across_p called through note_stores.
3602 DATA points to an integer in which we set either the bit for
3603 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3607 find_memory_stores (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
,
3608 void *data ATTRIBUTE_UNUSED
)
3610 int *pflags
= (int *)data
;
3611 if (GET_CODE (x
) == SUBREG
)
3613 /* Treat stores to SP as stores to memory, this will prevent problems
3614 when there are references to the stack frame. */
3615 if (x
== stack_pointer_rtx
)
3616 *pflags
|= MEMREF_VOLATILE
;
3619 *pflags
|= MEM_VOLATILE_P (x
) ? MEMREF_VOLATILE
: MEMREF_NORMAL
;
3622 /* Scan BB backwards, using df_simulate functions to keep track of
3623 lifetimes, up to insn POINT. The result is stored in LIVE. */
3626 simulate_backwards_to_point (basic_block bb
, regset live
, rtx point
)
3629 bitmap_copy (live
, df_get_live_out (bb
));
3630 df_simulate_initialize_backwards (bb
, live
);
3632 /* Scan and update life information until we reach the point we're
3634 for (insn
= BB_END (bb
); insn
!= point
; insn
= PREV_INSN (insn
))
3635 df_simulate_one_insn_backwards (bb
, insn
, live
);
3638 /* Return true if it is safe to move a group of insns, described by
3639 the range FROM to TO, backwards across another group of insns,
3640 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3641 are no insns between ACROSS_TO and FROM, but they may be in
3642 different basic blocks; MERGE_BB is the block from which the
3643 insns will be moved. The caller must pass in a regset MERGE_LIVE
3644 which specifies the registers live after TO.
3646 This function may be called in one of two cases: either we try to
3647 move identical instructions from all successor blocks into their
3648 predecessor, or we try to move from only one successor block. If
3649 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3650 the second case. It should contain a set of registers live at the
3651 end of ACROSS_TO which must not be clobbered by moving the insns.
3652 In that case, we're also more careful about moving memory references
3655 We return false if it is not safe to move the entire group, but it
3656 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3657 is set to point at the last moveable insn in such a case. */
3660 can_move_insns_across (rtx_insn
*from
, rtx_insn
*to
,
3661 rtx_insn
*across_from
, rtx_insn
*across_to
,
3662 basic_block merge_bb
, regset merge_live
,
3663 regset other_branch_live
, rtx_insn
**pmove_upto
)
3665 rtx_insn
*insn
, *next
, *max_to
;
3666 bitmap merge_set
, merge_use
, local_merge_live
;
3667 bitmap test_set
, test_use
;
3668 unsigned i
, fail
= 0;
3670 int memrefs_in_across
= 0;
3671 int mem_sets_in_across
= 0;
3672 bool trapping_insns_in_across
= false;
3674 if (pmove_upto
!= NULL
)
3677 /* Find real bounds, ignoring debug insns. */
3678 while (!NONDEBUG_INSN_P (from
) && from
!= to
)
3679 from
= NEXT_INSN (from
);
3680 while (!NONDEBUG_INSN_P (to
) && from
!= to
)
3681 to
= PREV_INSN (to
);
3683 for (insn
= across_to
; ; insn
= next
)
3687 if (RTL_CONST_OR_PURE_CALL_P (insn
))
3688 /* Pure functions can read from memory. Const functions can
3689 read from arguments that the ABI has forced onto the stack.
3690 Neither sort of read can be volatile. */
3691 memrefs_in_across
|= MEMREF_NORMAL
;
3694 memrefs_in_across
|= MEMREF_VOLATILE
;
3695 mem_sets_in_across
|= MEMREF_VOLATILE
;
3698 if (NONDEBUG_INSN_P (insn
))
3700 if (volatile_insn_p (PATTERN (insn
)))
3702 memrefs_in_across
|= find_memory (insn
);
3703 note_stores (PATTERN (insn
), find_memory_stores
,
3704 &mem_sets_in_across
);
3705 /* This is used just to find sets of the stack pointer. */
3706 memrefs_in_across
|= mem_sets_in_across
;
3707 trapping_insns_in_across
|= may_trap_p (PATTERN (insn
));
3709 next
= PREV_INSN (insn
);
3710 if (insn
== across_from
)
3715 MERGE_SET = set of registers set in MERGE_BB
3716 MERGE_USE = set of registers used in MERGE_BB and live at its top
3717 MERGE_LIVE = set of registers live at the point inside the MERGE
3718 range that we've reached during scanning
3719 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3720 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3721 and live before ACROSS_FROM. */
3723 merge_set
= BITMAP_ALLOC (®_obstack
);
3724 merge_use
= BITMAP_ALLOC (®_obstack
);
3725 local_merge_live
= BITMAP_ALLOC (®_obstack
);
3726 test_set
= BITMAP_ALLOC (®_obstack
);
3727 test_use
= BITMAP_ALLOC (®_obstack
);
3729 /* Compute the set of registers set and used in the ACROSS range. */
3730 if (other_branch_live
!= NULL
)
3731 bitmap_copy (test_use
, other_branch_live
);
3732 df_simulate_initialize_backwards (merge_bb
, test_use
);
3733 for (insn
= across_to
; ; insn
= next
)
3735 if (NONDEBUG_INSN_P (insn
))
3737 df_simulate_find_defs (insn
, test_set
);
3738 df_simulate_defs (insn
, test_use
);
3739 df_simulate_uses (insn
, test_use
);
3741 next
= PREV_INSN (insn
);
3742 if (insn
== across_from
)
3746 /* Compute an upper bound for the amount of insns moved, by finding
3747 the first insn in MERGE that sets a register in TEST_USE, or uses
3748 a register in TEST_SET. We also check for calls, trapping operations,
3749 and memory references. */
3751 for (insn
= from
; ; insn
= next
)
3755 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_EPILOGUE_BEG
)
3757 if (NONDEBUG_INSN_P (insn
))
3759 if (may_trap_or_fault_p (PATTERN (insn
))
3760 && (trapping_insns_in_across
3761 || other_branch_live
!= NULL
3762 || volatile_insn_p (PATTERN (insn
))))
3765 /* We cannot move memory stores past each other, or move memory
3766 reads past stores, at least not without tracking them and
3767 calling true_dependence on every pair.
3769 If there is no other branch and no memory references or
3770 sets in the ACROSS range, we can move memory references
3771 freely, even volatile ones.
3773 Otherwise, the rules are as follows: volatile memory
3774 references and stores can't be moved at all, and any type
3775 of memory reference can't be moved if there are volatile
3776 accesses or stores in the ACROSS range. That leaves
3777 normal reads, which can be moved, as the trapping case is
3778 dealt with elsewhere. */
3779 if (other_branch_live
!= NULL
|| memrefs_in_across
!= 0)
3781 int mem_ref_flags
= 0;
3782 int mem_set_flags
= 0;
3783 note_stores (PATTERN (insn
), find_memory_stores
, &mem_set_flags
);
3784 mem_ref_flags
= find_memory (insn
);
3785 /* Catch sets of the stack pointer. */
3786 mem_ref_flags
|= mem_set_flags
;
3788 if ((mem_ref_flags
| mem_set_flags
) & MEMREF_VOLATILE
)
3790 if ((memrefs_in_across
& MEMREF_VOLATILE
) && mem_ref_flags
!= 0)
3792 if (mem_set_flags
!= 0
3793 || (mem_sets_in_across
!= 0 && mem_ref_flags
!= 0))
3796 df_simulate_find_uses (insn
, merge_use
);
3797 /* We're only interested in uses which use a value live at
3798 the top, not one previously set in this block. */
3799 bitmap_and_compl_into (merge_use
, merge_set
);
3800 df_simulate_find_defs (insn
, merge_set
);
3801 if (bitmap_intersect_p (merge_set
, test_use
)
3802 || bitmap_intersect_p (merge_use
, test_set
))
3804 if (!HAVE_cc0
|| !sets_cc0_p (insn
))
3807 next
= NEXT_INSN (insn
);
3814 if (max_to
== NULL_RTX
|| (fail
&& pmove_upto
== NULL
))
3817 /* Now, lower this upper bound by also taking into account that
3818 a range of insns moved across ACROSS must not leave a register
3819 live at the end that will be clobbered in ACROSS. We need to
3820 find a point where TEST_SET & LIVE == 0.
3822 Insns in the MERGE range that set registers which are also set
3823 in the ACROSS range may still be moved as long as we also move
3824 later insns which use the results of the set, and make the
3825 register dead again. This is verified by the condition stated
3826 above. We only need to test it for registers that are set in
3829 MERGE_LIVE is provided by the caller and holds live registers after
3831 bitmap_copy (local_merge_live
, merge_live
);
3832 for (insn
= to
; insn
!= max_to
; insn
= PREV_INSN (insn
))
3833 df_simulate_one_insn_backwards (merge_bb
, insn
, local_merge_live
);
3835 /* We're not interested in registers that aren't set in the moved
3837 bitmap_and_into (local_merge_live
, merge_set
);
3840 if (NONDEBUG_INSN_P (insn
))
3842 if (!bitmap_intersect_p (test_set
, local_merge_live
)
3843 && (!HAVE_cc0
|| !sets_cc0_p (insn
)))
3849 df_simulate_one_insn_backwards (merge_bb
, insn
,
3857 insn
= PREV_INSN (insn
);
3864 *pmove_upto
= max_to
;
3866 /* For small register class machines, don't lengthen lifetimes of
3867 hard registers before reload. */
3868 if (! reload_completed
3869 && targetm
.small_register_classes_for_mode_p (VOIDmode
))
3871 EXECUTE_IF_SET_IN_BITMAP (merge_set
, 0, i
, bi
)
3873 if (i
< FIRST_PSEUDO_REGISTER
3875 && ! global_regs
[i
])
3884 BITMAP_FREE (merge_set
);
3885 BITMAP_FREE (merge_use
);
3886 BITMAP_FREE (local_merge_live
);
3887 BITMAP_FREE (test_set
);
3888 BITMAP_FREE (test_use
);
3894 /*----------------------------------------------------------------------------
3895 MULTIPLE DEFINITIONS
3897 Find the locations in the function reached by multiple definition sites
3898 for a live pseudo. In and out bitvectors are built for each basic
3899 block. They are restricted for efficiency to live registers.
3901 The gen and kill sets for the problem are obvious. Together they
3902 include all defined registers in a basic block; the gen set includes
3903 registers where a partial or conditional or may-clobber definition is
3904 last in the BB, while the kill set includes registers with a complete
3905 definition coming last. However, the computation of the dataflow
3906 itself is interesting.
3908 The idea behind it comes from SSA form's iterated dominance frontier
3909 criterion for inserting PHI functions. Just like in that case, we can use
3910 the dominance frontier to find places where multiple definitions meet;
3911 a register X defined in a basic block BB1 has multiple definitions in
3912 basic blocks in BB1's dominance frontier.
3914 So, the in-set of a basic block BB2 is not just the union of the
3915 out-sets of BB2's predecessors, but includes some more bits that come
3916 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3917 the previous paragraph). I called this set the init-set of BB2.
3919 (Note: I actually use the kill-set only to build the init-set.
3920 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3922 For example, if you have
3926 if <...> goto BB2 else goto BB3;
3934 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3935 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3936 not need to iterate the dominance frontier, because we do not insert
3937 anything like PHI functions there! Instead, dataflow will take care of
3938 propagating the information to BB3's successors.
3939 ---------------------------------------------------------------------------*/
3941 /* Private data used to verify the solution for this problem. */
3942 struct df_md_problem_data
3944 /* An obstack for the bitmaps we need for this problem. */
3945 bitmap_obstack md_bitmaps
;
3948 /* Scratch var used by transfer functions. This is used to do md analysis
3949 only for live registers. */
3950 static bitmap_head df_md_scratch
;
3954 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
3957 struct df_md_bb_info
*bb_info
= (struct df_md_bb_info
*) vbb_info
;
3960 bitmap_clear (&bb_info
->kill
);
3961 bitmap_clear (&bb_info
->gen
);
3962 bitmap_clear (&bb_info
->init
);
3963 bitmap_clear (&bb_info
->in
);
3964 bitmap_clear (&bb_info
->out
);
3969 /* Allocate or reset bitmaps for DF_MD. The solution bits are
3970 not touched unless the block is new. */
3973 df_md_alloc (bitmap all_blocks
)
3975 unsigned int bb_index
;
3977 struct df_md_problem_data
*problem_data
;
3979 df_grow_bb_info (df_md
);
3980 if (df_md
->problem_data
)
3981 problem_data
= (struct df_md_problem_data
*) df_md
->problem_data
;
3984 problem_data
= XNEW (struct df_md_problem_data
);
3985 df_md
->problem_data
= problem_data
;
3986 bitmap_obstack_initialize (&problem_data
->md_bitmaps
);
3988 bitmap_initialize (&df_md_scratch
, &problem_data
->md_bitmaps
);
3990 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
3992 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
3993 /* When bitmaps are already initialized, just clear them. */
3994 if (bb_info
->init
.obstack
)
3996 bitmap_clear (&bb_info
->init
);
3997 bitmap_clear (&bb_info
->gen
);
3998 bitmap_clear (&bb_info
->kill
);
3999 bitmap_clear (&bb_info
->in
);
4000 bitmap_clear (&bb_info
->out
);
4004 bitmap_initialize (&bb_info
->init
, &problem_data
->md_bitmaps
);
4005 bitmap_initialize (&bb_info
->gen
, &problem_data
->md_bitmaps
);
4006 bitmap_initialize (&bb_info
->kill
, &problem_data
->md_bitmaps
);
4007 bitmap_initialize (&bb_info
->in
, &problem_data
->md_bitmaps
);
4008 bitmap_initialize (&bb_info
->out
, &problem_data
->md_bitmaps
);
4012 df_md
->optional_p
= true;
4015 /* Add the effect of the top artificial defs of BB to the multiple definitions
4019 df_md_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_md
)
4021 int bb_index
= bb
->index
;
4023 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
4024 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
4026 unsigned int dregno
= DF_REF_REGNO (def
);
4027 if (DF_REF_FLAGS (def
)
4028 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4029 bitmap_set_bit (local_md
, dregno
);
4031 bitmap_clear_bit (local_md
, dregno
);
4036 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4040 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx_insn
*insn
,
4045 FOR_EACH_INSN_DEF (def
, insn
)
4047 unsigned int dregno
= DF_REF_REGNO (def
);
4048 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4049 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4051 if (DF_REF_FLAGS (def
)
4052 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4053 bitmap_set_bit (local_md
, DF_REF_ID (def
));
4055 bitmap_clear_bit (local_md
, DF_REF_ID (def
));
4061 df_md_bb_local_compute_process_def (struct df_md_bb_info
*bb_info
,
4065 bitmap_clear (&seen_in_insn
);
4067 for (; def
; def
= DF_REF_NEXT_LOC (def
))
4069 unsigned int dregno
= DF_REF_REGNO (def
);
4070 if (((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4071 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4072 && top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
4074 if (!bitmap_bit_p (&seen_in_insn
, dregno
))
4076 if (DF_REF_FLAGS (def
)
4077 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4079 bitmap_set_bit (&bb_info
->gen
, dregno
);
4080 bitmap_clear_bit (&bb_info
->kill
, dregno
);
4084 /* When we find a clobber and a regular def,
4085 make sure the regular def wins. */
4086 bitmap_set_bit (&seen_in_insn
, dregno
);
4087 bitmap_set_bit (&bb_info
->kill
, dregno
);
4088 bitmap_clear_bit (&bb_info
->gen
, dregno
);
4096 /* Compute local multiple def info for basic block BB. */
4099 df_md_bb_local_compute (unsigned int bb_index
)
4101 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4102 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4105 /* Artificials are only hard regs. */
4106 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4107 df_md_bb_local_compute_process_def (bb_info
,
4108 df_get_artificial_defs (bb_index
),
4111 FOR_BB_INSNS (bb
, insn
)
4113 unsigned int uid
= INSN_UID (insn
);
4117 df_md_bb_local_compute_process_def (bb_info
, DF_INSN_UID_DEFS (uid
), 0);
4120 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4121 df_md_bb_local_compute_process_def (bb_info
,
4122 df_get_artificial_defs (bb_index
),
4126 /* Compute local reaching def info for each basic block within BLOCKS. */
4129 df_md_local_compute (bitmap all_blocks
)
4131 unsigned int bb_index
, df_bb_index
;
4132 bitmap_iterator bi1
, bi2
;
4134 bitmap_head
*frontiers
;
4136 bitmap_initialize (&seen_in_insn
, &bitmap_default_obstack
);
4138 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4140 df_md_bb_local_compute (bb_index
);
4143 bitmap_clear (&seen_in_insn
);
4145 frontiers
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
4146 FOR_ALL_BB_FN (bb
, cfun
)
4147 bitmap_initialize (&frontiers
[bb
->index
], &bitmap_default_obstack
);
4149 compute_dominance_frontiers (frontiers
);
4151 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4152 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4154 bitmap kill
= &df_md_get_bb_info (bb_index
)->kill
;
4155 EXECUTE_IF_SET_IN_BITMAP (&frontiers
[bb_index
], 0, df_bb_index
, bi2
)
4157 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, df_bb_index
);
4158 if (bitmap_bit_p (all_blocks
, df_bb_index
))
4159 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index
)->init
, kill
,
4160 df_get_live_in (bb
));
4164 FOR_ALL_BB_FN (bb
, cfun
)
4165 bitmap_clear (&frontiers
[bb
->index
]);
4170 /* Reset the global solution for recalculation. */
4173 df_md_reset (bitmap all_blocks
)
4175 unsigned int bb_index
;
4178 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4180 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4181 gcc_assert (bb_info
);
4182 bitmap_clear (&bb_info
->in
);
4183 bitmap_clear (&bb_info
->out
);
4188 df_md_transfer_function (int bb_index
)
4190 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4191 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4192 bitmap in
= &bb_info
->in
;
4193 bitmap out
= &bb_info
->out
;
4194 bitmap gen
= &bb_info
->gen
;
4195 bitmap kill
= &bb_info
->kill
;
4197 /* We need to use a scratch set here so that the value returned from this
4198 function invocation properly reflects whether the sets changed in a
4199 significant way; i.e. not just because the live set was anded in. */
4200 bitmap_and (&df_md_scratch
, gen
, df_get_live_out (bb
));
4202 /* Multiple definitions of a register are not relevant if it is not
4203 live. Thus we trim the result to the places where it is live. */
4204 bitmap_and_into (in
, df_get_live_in (bb
));
4206 return bitmap_ior_and_compl (out
, &df_md_scratch
, in
, kill
);
4209 /* Initialize the solution bit vectors for problem. */
4212 df_md_init (bitmap all_blocks
)
4214 unsigned int bb_index
;
4217 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4219 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4221 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4222 df_md_transfer_function (bb_index
);
4227 df_md_confluence_0 (basic_block bb
)
4229 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4230 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4233 /* In of target gets or of out of source. */
4236 df_md_confluence_n (edge e
)
4238 bitmap op1
= &df_md_get_bb_info (e
->dest
->index
)->in
;
4239 bitmap op2
= &df_md_get_bb_info (e
->src
->index
)->out
;
4241 if (e
->flags
& EDGE_FAKE
)
4244 if (e
->flags
& EDGE_EH
)
4245 return bitmap_ior_and_compl_into (op1
, op2
,
4246 regs_invalidated_by_call_regset
);
4248 return bitmap_ior_into (op1
, op2
);
4251 /* Free all storage associated with the problem. */
4256 struct df_md_problem_data
*problem_data
4257 = (struct df_md_problem_data
*) df_md
->problem_data
;
4259 bitmap_obstack_release (&problem_data
->md_bitmaps
);
4260 free (problem_data
);
4261 df_md
->problem_data
= NULL
;
4263 df_md
->block_info_size
= 0;
4264 free (df_md
->block_info
);
4265 df_md
->block_info
= NULL
;
4270 /* Debugging info at top of bb. */
4273 df_md_top_dump (basic_block bb
, FILE *file
)
4275 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4279 fprintf (file
, ";; md in \t");
4280 df_print_regset (file
, &bb_info
->in
);
4281 fprintf (file
, ";; md init \t");
4282 df_print_regset (file
, &bb_info
->init
);
4283 fprintf (file
, ";; md gen \t");
4284 df_print_regset (file
, &bb_info
->gen
);
4285 fprintf (file
, ";; md kill \t");
4286 df_print_regset (file
, &bb_info
->kill
);
4289 /* Debugging info at bottom of bb. */
4292 df_md_bottom_dump (basic_block bb
, FILE *file
)
4294 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4298 fprintf (file
, ";; md out \t");
4299 df_print_regset (file
, &bb_info
->out
);
4302 static struct df_problem problem_MD
=
4304 DF_MD
, /* Problem id. */
4305 DF_FORWARD
, /* Direction. */
4306 df_md_alloc
, /* Allocate the problem specific data. */
4307 df_md_reset
, /* Reset global information. */
4308 df_md_free_bb_info
, /* Free basic block info. */
4309 df_md_local_compute
, /* Local compute function. */
4310 df_md_init
, /* Init the solution specific data. */
4311 df_worklist_dataflow
, /* Worklist solver. */
4312 df_md_confluence_0
, /* Confluence operator 0. */
4313 df_md_confluence_n
, /* Confluence operator n. */
4314 df_md_transfer_function
, /* Transfer function. */
4315 NULL
, /* Finalize function. */
4316 df_md_free
, /* Free all of the problem information. */
4317 df_md_free
, /* Remove this problem from the stack of dataflow problems. */
4318 NULL
, /* Debugging. */
4319 df_md_top_dump
, /* Debugging start block. */
4320 df_md_bottom_dump
, /* Debugging end block. */
4321 NULL
, /* Debugging start insn. */
4322 NULL
, /* Debugging end insn. */
4323 NULL
, /* Incremental solution verify start. */
4324 NULL
, /* Incremental solution verify end. */
4325 NULL
, /* Dependent problem. */
4326 sizeof (struct df_md_bb_info
),/* Size of entry of block_info array. */
4327 TV_DF_MD
, /* Timing variable. */
4328 false /* Reset blocks on dropping out of blocks_to_analyze. */
4331 /* Create a new MD instance and add it to the existing instance
4335 df_md_add_problem (void)
4337 df_add_problem (&problem_MD
);