1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2016 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"
32 #include "insn-config.h"
39 /* Note that turning REG_DEAD_DEBUGGING on will cause
40 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
41 addresses in the dumps. */
42 #define REG_DEAD_DEBUGGING 0
44 #define DF_SPARSE_THRESHOLD 32
46 static bitmap_head seen_in_block
;
47 static bitmap_head seen_in_insn
;
49 /*----------------------------------------------------------------------------
51 ----------------------------------------------------------------------------*/
53 /* Generic versions to get the void* version of the block info. Only
54 used inside the problem instance vectors. */
56 /* Dump a def-use or use-def chain for REF to FILE. */
59 df_chain_dump (struct df_link
*link
, FILE *file
)
62 for (; link
; link
= link
->next
)
64 fprintf (file
, "%c%d(bb %d insn %d) ",
65 DF_REF_REG_DEF_P (link
->ref
)
67 : (DF_REF_FLAGS (link
->ref
) & DF_REF_IN_NOTE
) ? 'e' : 'u',
68 DF_REF_ID (link
->ref
),
69 DF_REF_BBNO (link
->ref
),
70 DF_REF_IS_ARTIFICIAL (link
->ref
)
71 ? -1 : DF_REF_INSN_UID (link
->ref
));
77 /* Print some basic block info as part of df_dump. */
80 df_print_bb_index (basic_block bb
, FILE *file
)
85 fprintf (file
, "\n( ");
86 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
88 basic_block pred
= e
->src
;
89 fprintf (file
, "%d%s ", pred
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
91 fprintf (file
, ")->[%d]->( ", bb
->index
);
92 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
94 basic_block succ
= e
->dest
;
95 fprintf (file
, "%d%s ", succ
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
97 fprintf (file
, ")\n");
101 /*----------------------------------------------------------------------------
104 Find the locations in the function where each definition site for a
105 pseudo reaches. In and out bitvectors are built for each basic
106 block. The id field in the ref is used to index into these sets.
107 See df.h for details.
109 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
110 existing uses are included in the global reaching DEFs set, or in other
111 words only DEFs that are still live. This is a kind of pruned version
112 of the traditional reaching definitions problem that is much less
113 complex to compute and produces enough information to compute UD-chains.
114 In this context, live must be interpreted in the DF_LR sense: Uses that
115 are upward exposed but maybe not initialized on all paths through the
116 CFG. For a USE that is not reached by a DEF on all paths, we still want
117 to make those DEFs that do reach the USE visible, and pruning based on
118 DF_LIVE would make that impossible.
119 ----------------------------------------------------------------------------*/
121 /* This problem plays a large number of games for the sake of
124 1) The order of the bits in the bitvectors. After the scanning
125 phase, all of the defs are sorted. All of the defs for the reg 0
126 are first, followed by all defs for reg 1 and so on.
128 2) There are two kill sets, one if the number of defs is less or
129 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
132 <= : Data is built directly in the kill set.
134 > : One level of indirection is used to keep from generating long
135 strings of 1 bits in the kill sets. Bitvectors that are indexed
136 by the regnum are used to represent that there is a killing def
137 for the register. The confluence and transfer functions use
138 these along with the bitmap_clear_range call to remove ranges of
139 bits without actually generating a knockout vector.
141 The kill and sparse_kill and the dense_invalidated_by_call and
142 sparse_invalidated_by_call both play this game. */
144 /* Private data used to compute the solution for this problem. These
145 data structures are not accessible outside of this module. */
146 struct df_rd_problem_data
148 /* The set of defs to regs invalidated by call. */
149 bitmap_head sparse_invalidated_by_call
;
150 /* The set of defs to regs invalidate by call for rd. */
151 bitmap_head dense_invalidated_by_call
;
152 /* An obstack for the bitmaps we need for this problem. */
153 bitmap_obstack rd_bitmaps
;
157 /* Free basic block info. */
160 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
163 struct df_rd_bb_info
*bb_info
= (struct df_rd_bb_info
*) vbb_info
;
166 bitmap_clear (&bb_info
->kill
);
167 bitmap_clear (&bb_info
->sparse_kill
);
168 bitmap_clear (&bb_info
->gen
);
169 bitmap_clear (&bb_info
->in
);
170 bitmap_clear (&bb_info
->out
);
175 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
176 not touched unless the block is new. */
179 df_rd_alloc (bitmap all_blocks
)
181 unsigned int bb_index
;
183 struct df_rd_problem_data
*problem_data
;
185 if (df_rd
->problem_data
)
187 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
188 bitmap_clear (&problem_data
->sparse_invalidated_by_call
);
189 bitmap_clear (&problem_data
->dense_invalidated_by_call
);
193 problem_data
= XNEW (struct df_rd_problem_data
);
194 df_rd
->problem_data
= problem_data
;
196 bitmap_obstack_initialize (&problem_data
->rd_bitmaps
);
197 bitmap_initialize (&problem_data
->sparse_invalidated_by_call
,
198 &problem_data
->rd_bitmaps
);
199 bitmap_initialize (&problem_data
->dense_invalidated_by_call
,
200 &problem_data
->rd_bitmaps
);
203 df_grow_bb_info (df_rd
);
205 /* Because of the clustering of all use sites for the same pseudo,
206 we have to process all of the blocks before doing the analysis. */
208 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
210 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
212 /* When bitmaps are already initialized, just clear them. */
213 if (bb_info
->kill
.obstack
)
215 bitmap_clear (&bb_info
->kill
);
216 bitmap_clear (&bb_info
->sparse_kill
);
217 bitmap_clear (&bb_info
->gen
);
221 bitmap_initialize (&bb_info
->kill
, &problem_data
->rd_bitmaps
);
222 bitmap_initialize (&bb_info
->sparse_kill
, &problem_data
->rd_bitmaps
);
223 bitmap_initialize (&bb_info
->gen
, &problem_data
->rd_bitmaps
);
224 bitmap_initialize (&bb_info
->in
, &problem_data
->rd_bitmaps
);
225 bitmap_initialize (&bb_info
->out
, &problem_data
->rd_bitmaps
);
228 df_rd
->optional_p
= true;
232 /* Add the effect of the top artificial defs of BB to the reaching definitions
236 df_rd_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_rd
)
238 int bb_index
= bb
->index
;
240 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
241 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
243 unsigned int dregno
= DF_REF_REGNO (def
);
244 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
245 bitmap_clear_range (local_rd
,
246 DF_DEFS_BEGIN (dregno
),
247 DF_DEFS_COUNT (dregno
));
248 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
252 /* Add the effect of the defs of INSN to the reaching definitions bitmap
256 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx_insn
*insn
,
261 FOR_EACH_INSN_DEF (def
, insn
)
263 unsigned int dregno
= DF_REF_REGNO (def
);
264 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
265 || (dregno
>= FIRST_PSEUDO_REGISTER
))
267 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
268 bitmap_clear_range (local_rd
,
269 DF_DEFS_BEGIN (dregno
),
270 DF_DEFS_COUNT (dregno
));
271 if (!(DF_REF_FLAGS (def
)
272 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
273 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
278 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
279 more complicated than just simulating, because we must produce the
280 gen and kill sets and hence deal with the two possible representations
284 df_rd_bb_local_compute_process_def (struct df_rd_bb_info
*bb_info
,
288 for (; def
; def
= DF_REF_NEXT_LOC (def
))
290 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
292 unsigned int regno
= DF_REF_REGNO (def
);
293 unsigned int begin
= DF_DEFS_BEGIN (regno
);
294 unsigned int n_defs
= DF_DEFS_COUNT (regno
);
296 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
297 || (regno
>= FIRST_PSEUDO_REGISTER
))
299 /* Only the last def(s) for a regno in the block has any
301 if (!bitmap_bit_p (&seen_in_block
, regno
))
303 /* The first def for regno in insn gets to knock out the
304 defs from other instructions. */
305 if ((!bitmap_bit_p (&seen_in_insn
, regno
))
306 /* If the def is to only part of the reg, it does
307 not kill the other defs that reach here. */
308 && (!(DF_REF_FLAGS (def
) &
309 (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))))
311 if (n_defs
> DF_SPARSE_THRESHOLD
)
313 bitmap_set_bit (&bb_info
->sparse_kill
, regno
);
314 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
318 bitmap_set_range (&bb_info
->kill
, begin
, n_defs
);
319 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
323 bitmap_set_bit (&seen_in_insn
, regno
);
324 /* All defs for regno in the instruction may be put into
326 if (!(DF_REF_FLAGS (def
)
327 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
328 bitmap_set_bit (&bb_info
->gen
, DF_REF_ID (def
));
335 /* Compute local reaching def info for basic block BB. */
338 df_rd_bb_local_compute (unsigned int bb_index
)
340 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
341 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
344 bitmap_clear (&seen_in_block
);
345 bitmap_clear (&seen_in_insn
);
347 /* Artificials are only hard regs. */
348 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
349 df_rd_bb_local_compute_process_def (bb_info
,
350 df_get_artificial_defs (bb_index
),
353 FOR_BB_INSNS_REVERSE (bb
, insn
)
355 unsigned int uid
= INSN_UID (insn
);
360 df_rd_bb_local_compute_process_def (bb_info
,
361 DF_INSN_UID_DEFS (uid
), 0);
363 /* This complex dance with the two bitmaps is required because
364 instructions can assign twice to the same pseudo. This
365 generally happens with calls that will have one def for the
366 result and another def for the clobber. If only one vector
367 is used and the clobber goes first, the result will be
369 bitmap_ior_into (&seen_in_block
, &seen_in_insn
);
370 bitmap_clear (&seen_in_insn
);
373 /* Process the artificial defs at the top of the block last since we
374 are going backwards through the block and these are logically at
376 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
377 df_rd_bb_local_compute_process_def (bb_info
,
378 df_get_artificial_defs (bb_index
),
383 /* Compute local reaching def info for each basic block within BLOCKS. */
386 df_rd_local_compute (bitmap all_blocks
)
388 unsigned int bb_index
;
391 struct df_rd_problem_data
*problem_data
392 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
393 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
394 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
396 bitmap_initialize (&seen_in_block
, &df_bitmap_obstack
);
397 bitmap_initialize (&seen_in_insn
, &df_bitmap_obstack
);
399 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG
);
401 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
403 df_rd_bb_local_compute (bb_index
);
406 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
407 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset
, 0, regno
, bi
)
409 if (! HARD_REGISTER_NUM_P (regno
)
410 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
412 if (DF_DEFS_COUNT (regno
) > DF_SPARSE_THRESHOLD
)
413 bitmap_set_bit (sparse_invalidated
, regno
);
415 bitmap_set_range (dense_invalidated
,
416 DF_DEFS_BEGIN (regno
),
417 DF_DEFS_COUNT (regno
));
421 bitmap_clear (&seen_in_block
);
422 bitmap_clear (&seen_in_insn
);
426 /* Initialize the solution bit vectors for problem. */
429 df_rd_init_solution (bitmap all_blocks
)
431 unsigned int bb_index
;
434 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
436 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
438 bitmap_copy (&bb_info
->out
, &bb_info
->gen
);
439 bitmap_clear (&bb_info
->in
);
443 /* In of target gets or of out of source. */
446 df_rd_confluence_n (edge e
)
448 bitmap op1
= &df_rd_get_bb_info (e
->dest
->index
)->in
;
449 bitmap op2
= &df_rd_get_bb_info (e
->src
->index
)->out
;
450 bool changed
= false;
452 if (e
->flags
& EDGE_FAKE
)
455 if (e
->flags
& EDGE_EH
)
457 struct df_rd_problem_data
*problem_data
458 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
459 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
460 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
465 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
466 bitmap_and_compl (&tmp
, op2
, dense_invalidated
);
468 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
470 bitmap_clear_range (&tmp
,
471 DF_DEFS_BEGIN (regno
),
472 DF_DEFS_COUNT (regno
));
474 changed
|= bitmap_ior_into (op1
, &tmp
);
479 return bitmap_ior_into (op1
, op2
);
483 /* Transfer function. */
486 df_rd_transfer_function (int bb_index
)
488 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
491 bitmap in
= &bb_info
->in
;
492 bitmap out
= &bb_info
->out
;
493 bitmap gen
= &bb_info
->gen
;
494 bitmap kill
= &bb_info
->kill
;
495 bitmap sparse_kill
= &bb_info
->sparse_kill
;
496 bool changed
= false;
498 if (bitmap_empty_p (sparse_kill
))
499 changed
= bitmap_ior_and_compl (out
, gen
, in
, kill
);
502 struct df_rd_problem_data
*problem_data
;
505 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
506 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
507 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
508 bitmap_initialize (&tmp
, &problem_data
->rd_bitmaps
);
510 bitmap_and_compl (&tmp
, in
, kill
);
511 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
513 bitmap_clear_range (&tmp
,
514 DF_DEFS_BEGIN (regno
),
515 DF_DEFS_COUNT (regno
));
517 bitmap_ior_into (&tmp
, gen
);
518 changed
= !bitmap_equal_p (&tmp
, out
);
520 bitmap_move (out
, &tmp
);
525 if (df
->changeable_flags
& DF_RD_PRUNE_DEAD_DEFS
)
527 /* Create a mask of DEFs for all registers live at the end of this
528 basic block, and mask out DEFs of registers that are not live.
529 Computing the mask looks costly, but the benefit of the pruning
530 outweighs the cost. */
531 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
532 bitmap regs_live_out
= &df_lr_get_bb_info (bb_index
)->out
;
533 bitmap live_defs
= BITMAP_ALLOC (&df_bitmap_obstack
);
537 EXECUTE_IF_SET_IN_BITMAP (regs_live_out
, 0, regno
, bi
)
538 bitmap_set_range (live_defs
,
539 DF_DEFS_BEGIN (regno
),
540 DF_DEFS_COUNT (regno
));
541 changed
|= bitmap_and_into (&bb_info
->out
, live_defs
);
542 BITMAP_FREE (live_defs
);
548 /* Free all storage associated with the problem. */
553 struct df_rd_problem_data
*problem_data
554 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
558 bitmap_obstack_release (&problem_data
->rd_bitmaps
);
560 df_rd
->block_info_size
= 0;
561 free (df_rd
->block_info
);
562 df_rd
->block_info
= NULL
;
563 free (df_rd
->problem_data
);
569 /* Debugging info. */
572 df_rd_start_dump (FILE *file
)
574 struct df_rd_problem_data
*problem_data
575 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
576 unsigned int m
= DF_REG_SIZE (df
);
579 if (!df_rd
->block_info
)
582 fprintf (file
, ";; Reaching defs:\n");
584 fprintf (file
, ";; sparse invalidated \t");
585 dump_bitmap (file
, &problem_data
->sparse_invalidated_by_call
);
586 fprintf (file
, ";; dense invalidated \t");
587 dump_bitmap (file
, &problem_data
->dense_invalidated_by_call
);
589 fprintf (file
, ";; reg->defs[] map:\t");
590 for (regno
= 0; regno
< m
; regno
++)
591 if (DF_DEFS_COUNT (regno
))
592 fprintf (file
, "%d[%d,%d] ", regno
,
593 DF_DEFS_BEGIN (regno
),
594 DF_DEFS_BEGIN (regno
) + DF_DEFS_COUNT (regno
) - 1);
595 fprintf (file
, "\n");
600 df_rd_dump_defs_set (bitmap defs_set
, const char *prefix
, FILE *file
)
604 unsigned int m
= DF_REG_SIZE (df
);
605 bool first_reg
= true;
607 fprintf (file
, "%s\t(%d) ", prefix
, (int) bitmap_count_bits (defs_set
));
609 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
610 for (regno
= 0; regno
< m
; regno
++)
612 if (HARD_REGISTER_NUM_P (regno
)
613 && (df
->changeable_flags
& DF_NO_HARD_REGS
))
615 bitmap_set_range (&tmp
, DF_DEFS_BEGIN (regno
), DF_DEFS_COUNT (regno
));
616 bitmap_and_into (&tmp
, defs_set
);
617 if (! bitmap_empty_p (&tmp
))
621 bool first_def
= true;
627 fprintf (file
, "%u[", regno
);
628 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, ix
, bi
)
630 fprintf (file
, "%s%u", first_def
? "" : ",", ix
);
638 fprintf (file
, "\n");
642 /* Debugging info at top of bb. */
645 df_rd_top_dump (basic_block bb
, FILE *file
)
647 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
651 df_rd_dump_defs_set (&bb_info
->in
, ";; rd in ", file
);
652 df_rd_dump_defs_set (&bb_info
->gen
, ";; rd gen ", file
);
653 df_rd_dump_defs_set (&bb_info
->kill
, ";; rd kill", file
);
657 /* Debugging info at bottom of bb. */
660 df_rd_bottom_dump (basic_block bb
, FILE *file
)
662 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
666 df_rd_dump_defs_set (&bb_info
->out
, ";; rd out ", file
);
669 /* All of the information associated with every instance of the problem. */
671 static const struct df_problem problem_RD
=
673 DF_RD
, /* Problem id. */
674 DF_FORWARD
, /* Direction. */
675 df_rd_alloc
, /* Allocate the problem specific data. */
676 NULL
, /* Reset global information. */
677 df_rd_free_bb_info
, /* Free basic block info. */
678 df_rd_local_compute
, /* Local compute function. */
679 df_rd_init_solution
, /* Init the solution specific data. */
680 df_worklist_dataflow
, /* Worklist solver. */
681 NULL
, /* Confluence operator 0. */
682 df_rd_confluence_n
, /* Confluence operator n. */
683 df_rd_transfer_function
, /* Transfer function. */
684 NULL
, /* Finalize function. */
685 df_rd_free
, /* Free all of the problem information. */
686 df_rd_free
, /* Remove this problem from the stack of dataflow problems. */
687 df_rd_start_dump
, /* Debugging. */
688 df_rd_top_dump
, /* Debugging start block. */
689 df_rd_bottom_dump
, /* Debugging end block. */
690 NULL
, /* Debugging start insn. */
691 NULL
, /* Debugging end insn. */
692 NULL
, /* Incremental solution verify start. */
693 NULL
, /* Incremental solution verify end. */
694 NULL
, /* Dependent problem. */
695 sizeof (struct df_rd_bb_info
),/* Size of entry of block_info array. */
696 TV_DF_RD
, /* Timing variable. */
697 true /* Reset blocks on dropping out of blocks_to_analyze. */
702 /* Create a new RD instance and add it to the existing instance
706 df_rd_add_problem (void)
708 df_add_problem (&problem_RD
);
713 /*----------------------------------------------------------------------------
716 Find the locations in the function where any use of a pseudo can
717 reach in the backwards direction. In and out bitvectors are built
718 for each basic block. The regno is used to index into these sets.
719 See df.h for details.
720 ----------------------------------------------------------------------------*/
722 /* Private data used to verify the solution for this problem. */
723 struct df_lr_problem_data
727 /* An obstack for the bitmaps we need for this problem. */
728 bitmap_obstack lr_bitmaps
;
731 /* Free basic block info. */
734 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
737 struct df_lr_bb_info
*bb_info
= (struct df_lr_bb_info
*) vbb_info
;
740 bitmap_clear (&bb_info
->use
);
741 bitmap_clear (&bb_info
->def
);
742 bitmap_clear (&bb_info
->in
);
743 bitmap_clear (&bb_info
->out
);
748 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
749 not touched unless the block is new. */
752 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
754 unsigned int bb_index
;
756 struct df_lr_problem_data
*problem_data
;
758 df_grow_bb_info (df_lr
);
759 if (df_lr
->problem_data
)
760 problem_data
= (struct df_lr_problem_data
*) df_lr
->problem_data
;
763 problem_data
= XNEW (struct df_lr_problem_data
);
764 df_lr
->problem_data
= problem_data
;
766 problem_data
->out
= NULL
;
767 problem_data
->in
= NULL
;
768 bitmap_obstack_initialize (&problem_data
->lr_bitmaps
);
771 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
773 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
775 /* When bitmaps are already initialized, just clear them. */
776 if (bb_info
->use
.obstack
)
778 bitmap_clear (&bb_info
->def
);
779 bitmap_clear (&bb_info
->use
);
783 bitmap_initialize (&bb_info
->use
, &problem_data
->lr_bitmaps
);
784 bitmap_initialize (&bb_info
->def
, &problem_data
->lr_bitmaps
);
785 bitmap_initialize (&bb_info
->in
, &problem_data
->lr_bitmaps
);
786 bitmap_initialize (&bb_info
->out
, &problem_data
->lr_bitmaps
);
790 df_lr
->optional_p
= false;
794 /* Reset the global solution for recalculation. */
797 df_lr_reset (bitmap all_blocks
)
799 unsigned int bb_index
;
802 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
804 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
805 gcc_assert (bb_info
);
806 bitmap_clear (&bb_info
->in
);
807 bitmap_clear (&bb_info
->out
);
812 /* Compute local live register info for basic block BB. */
815 df_lr_bb_local_compute (unsigned int bb_index
)
817 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
818 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
822 /* Process the registers set in an exception handler. */
823 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
824 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
826 unsigned int dregno
= DF_REF_REGNO (def
);
827 bitmap_set_bit (&bb_info
->def
, dregno
);
828 bitmap_clear_bit (&bb_info
->use
, dregno
);
831 /* Process the hardware registers that are always live. */
832 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
833 /* Add use to set of uses in this BB. */
834 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
835 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
837 FOR_BB_INSNS_REVERSE (bb
, insn
)
839 if (!NONDEBUG_INSN_P (insn
))
842 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
843 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
844 /* If the def is to only part of the reg, it does
845 not kill the other defs that reach here. */
846 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
848 unsigned int dregno
= DF_REF_REGNO (def
);
849 bitmap_set_bit (&bb_info
->def
, dregno
);
850 bitmap_clear_bit (&bb_info
->use
, dregno
);
853 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
854 /* Add use to set of uses in this BB. */
855 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
858 /* Process the registers set in an exception handler or the hard
859 frame pointer if this block is the target of a non local
861 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
862 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
864 unsigned int dregno
= DF_REF_REGNO (def
);
865 bitmap_set_bit (&bb_info
->def
, dregno
);
866 bitmap_clear_bit (&bb_info
->use
, dregno
);
870 /* Process the uses that are live into an exception handler. */
871 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
872 /* Add use to set of uses in this BB. */
873 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
874 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
877 /* If the df_live problem is not defined, such as at -O0 and -O1, we
878 still need to keep the luids up to date. This is normally done
879 in the df_live problem since this problem has a forwards
882 df_recompute_luids (bb
);
886 /* Compute local live register info for each basic block within BLOCKS. */
889 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
891 unsigned int bb_index
, i
;
894 bitmap_clear (&df
->hardware_regs_used
);
896 /* The all-important stack pointer must always be live. */
897 bitmap_set_bit (&df
->hardware_regs_used
, STACK_POINTER_REGNUM
);
899 /* Global regs are always live, too. */
900 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
902 bitmap_set_bit (&df
->hardware_regs_used
, i
);
904 /* Before reload, there are a few registers that must be forced
905 live everywhere -- which might not already be the case for
906 blocks within infinite loops. */
907 if (!reload_completed
)
909 unsigned int pic_offset_table_regnum
= PIC_OFFSET_TABLE_REGNUM
;
910 /* Any reference to any pseudo before reload is a potential
911 reference of the frame pointer. */
912 bitmap_set_bit (&df
->hardware_regs_used
, FRAME_POINTER_REGNUM
);
914 /* Pseudos with argument area equivalences may require
915 reloading via the argument pointer. */
916 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
917 && fixed_regs
[ARG_POINTER_REGNUM
])
918 bitmap_set_bit (&df
->hardware_regs_used
, ARG_POINTER_REGNUM
);
920 /* Any constant, or pseudo with constant equivalences, may
921 require reloading from memory using the pic register. */
922 if (pic_offset_table_regnum
!= INVALID_REGNUM
923 && fixed_regs
[pic_offset_table_regnum
])
924 bitmap_set_bit (&df
->hardware_regs_used
, pic_offset_table_regnum
);
927 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
929 if (bb_index
== EXIT_BLOCK
)
931 /* The exit block is special for this problem and its bits are
932 computed from thin air. */
933 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (EXIT_BLOCK
);
934 bitmap_copy (&bb_info
->use
, df
->exit_block_uses
);
937 df_lr_bb_local_compute (bb_index
);
940 bitmap_clear (df_lr
->out_of_date_transfer_functions
);
944 /* Initialize the solution vectors. */
947 df_lr_init (bitmap all_blocks
)
949 unsigned int bb_index
;
952 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
954 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
955 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
956 bitmap_clear (&bb_info
->out
);
961 /* Confluence function that processes infinite loops. This might be a
962 noreturn function that throws. And even if it isn't, getting the
963 unwind info right helps debugging. */
965 df_lr_confluence_0 (basic_block bb
)
967 bitmap op1
= &df_lr_get_bb_info (bb
->index
)->out
;
968 if (bb
!= EXIT_BLOCK_PTR_FOR_FN (cfun
))
969 bitmap_copy (op1
, &df
->hardware_regs_used
);
973 /* Confluence function that ignores fake edges. */
976 df_lr_confluence_n (edge e
)
978 bitmap op1
= &df_lr_get_bb_info (e
->src
->index
)->out
;
979 bitmap op2
= &df_lr_get_bb_info (e
->dest
->index
)->in
;
980 bool changed
= false;
982 /* Call-clobbered registers die across exception and call edges. */
983 /* ??? Abnormal call edges ignored for the moment, as this gets
984 confused by sibling call edges, which crashes reg-stack. */
985 if (e
->flags
& EDGE_EH
)
986 changed
= bitmap_ior_and_compl_into (op1
, op2
, regs_invalidated_by_call_regset
);
988 changed
= bitmap_ior_into (op1
, op2
);
990 changed
|= bitmap_ior_into (op1
, &df
->hardware_regs_used
);
995 /* Transfer function. */
998 df_lr_transfer_function (int bb_index
)
1000 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
1001 bitmap in
= &bb_info
->in
;
1002 bitmap out
= &bb_info
->out
;
1003 bitmap use
= &bb_info
->use
;
1004 bitmap def
= &bb_info
->def
;
1006 return bitmap_ior_and_compl (in
, use
, out
, def
);
1010 /* Run the fast dce as a side effect of building LR. */
1013 df_lr_finalize (bitmap all_blocks
)
1015 df_lr
->solutions_dirty
= false;
1016 if (df
->changeable_flags
& DF_LR_RUN_DCE
)
1020 /* If dce deletes some instructions, we need to recompute the lr
1021 solution before proceeding further. The problem is that fast
1022 dce is a pessimestic dataflow algorithm. In the case where
1023 it deletes a statement S inside of a loop, the uses inside of
1024 S may not be deleted from the dataflow solution because they
1025 were carried around the loop. While it is conservatively
1026 correct to leave these extra bits, the standards of df
1027 require that we maintain the best possible (least fixed
1028 point) solution. The only way to do that is to redo the
1029 iteration from the beginning. See PR35805 for an
1031 if (df_lr
->solutions_dirty
)
1033 df_clear_flags (DF_LR_RUN_DCE
);
1034 df_lr_alloc (all_blocks
);
1035 df_lr_local_compute (all_blocks
);
1036 df_worklist_dataflow (df_lr
, all_blocks
, df
->postorder
, df
->n_blocks
);
1037 df_lr_finalize (all_blocks
);
1038 df_set_flags (DF_LR_RUN_DCE
);
1044 /* Free all storage associated with the problem. */
1049 struct df_lr_problem_data
*problem_data
1050 = (struct df_lr_problem_data
*) df_lr
->problem_data
;
1051 if (df_lr
->block_info
)
1054 df_lr
->block_info_size
= 0;
1055 free (df_lr
->block_info
);
1056 df_lr
->block_info
= NULL
;
1057 bitmap_obstack_release (&problem_data
->lr_bitmaps
);
1058 free (df_lr
->problem_data
);
1059 df_lr
->problem_data
= NULL
;
1062 BITMAP_FREE (df_lr
->out_of_date_transfer_functions
);
1067 /* Debugging info at top of bb. */
1070 df_lr_top_dump (basic_block bb
, FILE *file
)
1072 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1073 struct df_lr_problem_data
*problem_data
;
1077 fprintf (file
, ";; lr in \t");
1078 df_print_regset (file
, &bb_info
->in
);
1079 if (df_lr
->problem_data
)
1081 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1082 if (problem_data
->in
)
1084 fprintf (file
, ";; old in \t");
1085 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1088 fprintf (file
, ";; lr use \t");
1089 df_print_regset (file
, &bb_info
->use
);
1090 fprintf (file
, ";; lr def \t");
1091 df_print_regset (file
, &bb_info
->def
);
1095 /* Debugging info at bottom of bb. */
1098 df_lr_bottom_dump (basic_block bb
, FILE *file
)
1100 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1101 struct df_lr_problem_data
*problem_data
;
1105 fprintf (file
, ";; lr out \t");
1106 df_print_regset (file
, &bb_info
->out
);
1107 if (df_lr
->problem_data
)
1109 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1110 if (problem_data
->out
)
1112 fprintf (file
, ";; old out \t");
1113 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1119 /* Build the datastructure to verify that the solution to the dataflow
1120 equations is not dirty. */
1123 df_lr_verify_solution_start (void)
1126 struct df_lr_problem_data
*problem_data
;
1127 if (df_lr
->solutions_dirty
)
1130 /* Set it true so that the solution is recomputed. */
1131 df_lr
->solutions_dirty
= true;
1133 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1134 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1135 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1137 FOR_ALL_BB_FN (bb
, cfun
)
1139 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->lr_bitmaps
);
1140 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->lr_bitmaps
);
1141 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
));
1142 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
));
1147 /* Compare the saved datastructure and the new solution to the dataflow
1151 df_lr_verify_solution_end (void)
1153 struct df_lr_problem_data
*problem_data
;
1156 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1158 if (!problem_data
->out
)
1161 if (df_lr
->solutions_dirty
)
1162 /* Do not check if the solution is still dirty. See the comment
1163 in df_lr_finalize for details. */
1164 df_lr
->solutions_dirty
= false;
1166 FOR_ALL_BB_FN (bb
, cfun
)
1168 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
)))
1169 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
))))
1171 /*df_dump (stderr);*/
1176 /* Cannot delete them immediately because you may want to dump them
1177 if the comparison fails. */
1178 FOR_ALL_BB_FN (bb
, cfun
)
1180 bitmap_clear (&problem_data
->in
[bb
->index
]);
1181 bitmap_clear (&problem_data
->out
[bb
->index
]);
1184 free (problem_data
->in
);
1185 free (problem_data
->out
);
1186 problem_data
->in
= NULL
;
1187 problem_data
->out
= NULL
;
1191 /* All of the information associated with every instance of the problem. */
1193 static const struct df_problem problem_LR
=
1195 DF_LR
, /* Problem id. */
1196 DF_BACKWARD
, /* Direction. */
1197 df_lr_alloc
, /* Allocate the problem specific data. */
1198 df_lr_reset
, /* Reset global information. */
1199 df_lr_free_bb_info
, /* Free basic block info. */
1200 df_lr_local_compute
, /* Local compute function. */
1201 df_lr_init
, /* Init the solution specific data. */
1202 df_worklist_dataflow
, /* Worklist solver. */
1203 df_lr_confluence_0
, /* Confluence operator 0. */
1204 df_lr_confluence_n
, /* Confluence operator n. */
1205 df_lr_transfer_function
, /* Transfer function. */
1206 df_lr_finalize
, /* Finalize function. */
1207 df_lr_free
, /* Free all of the problem information. */
1208 NULL
, /* Remove this problem from the stack of dataflow problems. */
1209 NULL
, /* Debugging. */
1210 df_lr_top_dump
, /* Debugging start block. */
1211 df_lr_bottom_dump
, /* Debugging end block. */
1212 NULL
, /* Debugging start insn. */
1213 NULL
, /* Debugging end insn. */
1214 df_lr_verify_solution_start
,/* Incremental solution verify start. */
1215 df_lr_verify_solution_end
, /* Incremental solution verify end. */
1216 NULL
, /* Dependent problem. */
1217 sizeof (struct df_lr_bb_info
),/* Size of entry of block_info array. */
1218 TV_DF_LR
, /* Timing variable. */
1219 false /* Reset blocks on dropping out of blocks_to_analyze. */
1223 /* Create a new DATAFLOW instance and add it to an existing instance
1224 of DF. The returned structure is what is used to get at the
1228 df_lr_add_problem (void)
1230 df_add_problem (&problem_LR
);
1231 /* These will be initialized when df_scan_blocks processes each
1233 df_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1237 /* Verify that all of the lr related info is consistent and
1241 df_lr_verify_transfer_functions (void)
1244 bitmap_head saved_def
;
1245 bitmap_head saved_use
;
1246 bitmap_head all_blocks
;
1251 bitmap_initialize (&saved_def
, &bitmap_default_obstack
);
1252 bitmap_initialize (&saved_use
, &bitmap_default_obstack
);
1253 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1255 FOR_ALL_BB_FN (bb
, cfun
)
1257 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1258 bitmap_set_bit (&all_blocks
, bb
->index
);
1262 /* Make a copy of the transfer functions and then compute
1263 new ones to see if the transfer functions have
1265 if (!bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1268 bitmap_copy (&saved_def
, &bb_info
->def
);
1269 bitmap_copy (&saved_use
, &bb_info
->use
);
1270 bitmap_clear (&bb_info
->def
);
1271 bitmap_clear (&bb_info
->use
);
1273 df_lr_bb_local_compute (bb
->index
);
1274 gcc_assert (bitmap_equal_p (&saved_def
, &bb_info
->def
));
1275 gcc_assert (bitmap_equal_p (&saved_use
, &bb_info
->use
));
1280 /* If we do not have basic block info, the block must be in
1281 the list of dirty blocks or else some one has added a
1282 block behind our backs. */
1283 gcc_assert (bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1286 /* Make sure no one created a block without following
1288 gcc_assert (df_scan_get_bb_info (bb
->index
));
1291 /* Make sure there are no dirty bits in blocks that have been deleted. */
1292 gcc_assert (!bitmap_intersect_compl_p (df_lr
->out_of_date_transfer_functions
,
1295 bitmap_clear (&saved_def
);
1296 bitmap_clear (&saved_use
);
1297 bitmap_clear (&all_blocks
);
1302 /*----------------------------------------------------------------------------
1303 LIVE AND MAY-INITIALIZED REGISTERS.
1305 This problem first computes the IN and OUT bitvectors for the
1306 may-initialized registers problems, which is a forward problem.
1307 It gives the set of registers for which we MAY have an available
1308 definition, i.e. for which there is an available definition on
1309 at least one path from the entry block to the entry/exit of a
1310 basic block. Sets generate a definition, while clobbers kill
1313 In and out bitvectors are built for each basic block and are indexed by
1314 regnum (see df.h for details). In and out bitvectors in struct
1315 df_live_bb_info actually refers to the may-initialized problem;
1317 Then, the in and out sets for the LIVE problem itself are computed.
1318 These are the logical AND of the IN and OUT sets from the LR problem
1319 and the may-initialized problem.
1320 ----------------------------------------------------------------------------*/
1322 /* Private data used to verify the solution for this problem. */
1323 struct df_live_problem_data
1327 /* An obstack for the bitmaps we need for this problem. */
1328 bitmap_obstack live_bitmaps
;
1331 /* Scratch var used by transfer functions. This is used to implement
1332 an optimization to reduce the amount of space used to compute the
1333 combined lr and live analysis. */
1334 static bitmap_head df_live_scratch
;
1337 /* Free basic block info. */
1340 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
1343 struct df_live_bb_info
*bb_info
= (struct df_live_bb_info
*) vbb_info
;
1346 bitmap_clear (&bb_info
->gen
);
1347 bitmap_clear (&bb_info
->kill
);
1348 bitmap_clear (&bb_info
->in
);
1349 bitmap_clear (&bb_info
->out
);
1354 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1355 not touched unless the block is new. */
1358 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
1360 unsigned int bb_index
;
1362 struct df_live_problem_data
*problem_data
;
1364 if (df_live
->problem_data
)
1365 problem_data
= (struct df_live_problem_data
*) df_live
->problem_data
;
1368 problem_data
= XNEW (struct df_live_problem_data
);
1369 df_live
->problem_data
= problem_data
;
1371 problem_data
->out
= NULL
;
1372 problem_data
->in
= NULL
;
1373 bitmap_obstack_initialize (&problem_data
->live_bitmaps
);
1374 bitmap_initialize (&df_live_scratch
, &problem_data
->live_bitmaps
);
1377 df_grow_bb_info (df_live
);
1379 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1381 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1383 /* When bitmaps are already initialized, just clear them. */
1384 if (bb_info
->kill
.obstack
)
1386 bitmap_clear (&bb_info
->kill
);
1387 bitmap_clear (&bb_info
->gen
);
1391 bitmap_initialize (&bb_info
->kill
, &problem_data
->live_bitmaps
);
1392 bitmap_initialize (&bb_info
->gen
, &problem_data
->live_bitmaps
);
1393 bitmap_initialize (&bb_info
->in
, &problem_data
->live_bitmaps
);
1394 bitmap_initialize (&bb_info
->out
, &problem_data
->live_bitmaps
);
1397 df_live
->optional_p
= (optimize
<= 1);
1401 /* Reset the global solution for recalculation. */
1404 df_live_reset (bitmap all_blocks
)
1406 unsigned int bb_index
;
1409 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1411 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1412 gcc_assert (bb_info
);
1413 bitmap_clear (&bb_info
->in
);
1414 bitmap_clear (&bb_info
->out
);
1419 /* Compute local uninitialized register info for basic block BB. */
1422 df_live_bb_local_compute (unsigned int bb_index
)
1424 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1425 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1430 FOR_BB_INSNS (bb
, insn
)
1432 unsigned int uid
= INSN_UID (insn
);
1433 struct df_insn_info
*insn_info
= DF_INSN_UID_GET (uid
);
1435 /* Inserting labels does not always trigger the incremental
1439 gcc_assert (!INSN_P (insn
));
1440 insn_info
= df_insn_create_insn_record (insn
);
1443 DF_INSN_INFO_LUID (insn_info
) = luid
;
1448 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1450 unsigned int regno
= DF_REF_REGNO (def
);
1452 if (DF_REF_FLAGS_IS_SET (def
,
1453 DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
1454 /* All partial or conditional def
1455 seen are included in the gen set. */
1456 bitmap_set_bit (&bb_info
->gen
, regno
);
1457 else if (DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
))
1458 /* Only must clobbers for the entire reg destroy the
1460 bitmap_set_bit (&bb_info
->kill
, regno
);
1461 else if (! DF_REF_FLAGS_IS_SET (def
, DF_REF_MAY_CLOBBER
))
1462 bitmap_set_bit (&bb_info
->gen
, regno
);
1466 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1467 bitmap_set_bit (&bb_info
->gen
, DF_REF_REGNO (def
));
1471 /* Compute local uninitialized register info. */
1474 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
1476 unsigned int bb_index
;
1479 df_grow_insn_info ();
1481 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
,
1484 df_live_bb_local_compute (bb_index
);
1487 bitmap_clear (df_live
->out_of_date_transfer_functions
);
1491 /* Initialize the solution vectors. */
1494 df_live_init (bitmap all_blocks
)
1496 unsigned int bb_index
;
1499 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1501 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1502 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1504 /* No register may reach a location where it is not used. Thus
1505 we trim the rr result to the places where it is used. */
1506 bitmap_and (&bb_info
->out
, &bb_info
->gen
, &bb_lr_info
->out
);
1507 bitmap_clear (&bb_info
->in
);
1511 /* Forward confluence function that ignores fake edges. */
1514 df_live_confluence_n (edge e
)
1516 bitmap op1
= &df_live_get_bb_info (e
->dest
->index
)->in
;
1517 bitmap op2
= &df_live_get_bb_info (e
->src
->index
)->out
;
1519 if (e
->flags
& EDGE_FAKE
)
1522 return bitmap_ior_into (op1
, op2
);
1526 /* Transfer function for the forwards may-initialized problem. */
1529 df_live_transfer_function (int bb_index
)
1531 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1532 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1533 bitmap in
= &bb_info
->in
;
1534 bitmap out
= &bb_info
->out
;
1535 bitmap gen
= &bb_info
->gen
;
1536 bitmap kill
= &bb_info
->kill
;
1538 /* We need to use a scratch set here so that the value returned from this
1539 function invocation properly reflects whether the sets changed in a
1540 significant way; i.e. not just because the lr set was anded in. */
1541 bitmap_and (&df_live_scratch
, gen
, &bb_lr_info
->out
);
1542 /* No register may reach a location where it is not used. Thus
1543 we trim the rr result to the places where it is used. */
1544 bitmap_and_into (in
, &bb_lr_info
->in
);
1546 return bitmap_ior_and_compl (out
, &df_live_scratch
, in
, kill
);
1550 /* And the LR info with the may-initialized registers to produce the LIVE info. */
1553 df_live_finalize (bitmap all_blocks
)
1556 if (df_live
->solutions_dirty
)
1559 unsigned int bb_index
;
1561 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1563 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1564 struct df_live_bb_info
*bb_live_info
= df_live_get_bb_info (bb_index
);
1566 /* No register may reach a location where it is not used. Thus
1567 we trim the rr result to the places where it is used. */
1568 bitmap_and_into (&bb_live_info
->in
, &bb_lr_info
->in
);
1569 bitmap_and_into (&bb_live_info
->out
, &bb_lr_info
->out
);
1572 df_live
->solutions_dirty
= false;
1577 /* Free all storage associated with the problem. */
1582 struct df_live_problem_data
*problem_data
1583 = (struct df_live_problem_data
*) df_live
->problem_data
;
1584 if (df_live
->block_info
)
1586 df_live
->block_info_size
= 0;
1587 free (df_live
->block_info
);
1588 df_live
->block_info
= NULL
;
1589 bitmap_clear (&df_live_scratch
);
1590 bitmap_obstack_release (&problem_data
->live_bitmaps
);
1591 free (problem_data
);
1592 df_live
->problem_data
= NULL
;
1594 BITMAP_FREE (df_live
->out_of_date_transfer_functions
);
1599 /* Debugging info at top of bb. */
1602 df_live_top_dump (basic_block bb
, FILE *file
)
1604 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1605 struct df_live_problem_data
*problem_data
;
1610 fprintf (file
, ";; live in \t");
1611 df_print_regset (file
, &bb_info
->in
);
1612 if (df_live
->problem_data
)
1614 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1615 if (problem_data
->in
)
1617 fprintf (file
, ";; old in \t");
1618 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1621 fprintf (file
, ";; live gen \t");
1622 df_print_regset (file
, &bb_info
->gen
);
1623 fprintf (file
, ";; live kill\t");
1624 df_print_regset (file
, &bb_info
->kill
);
1628 /* Debugging info at bottom of bb. */
1631 df_live_bottom_dump (basic_block bb
, FILE *file
)
1633 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1634 struct df_live_problem_data
*problem_data
;
1639 fprintf (file
, ";; live out \t");
1640 df_print_regset (file
, &bb_info
->out
);
1641 if (df_live
->problem_data
)
1643 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1644 if (problem_data
->out
)
1646 fprintf (file
, ";; old out \t");
1647 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1653 /* Build the datastructure to verify that the solution to the dataflow
1654 equations is not dirty. */
1657 df_live_verify_solution_start (void)
1660 struct df_live_problem_data
*problem_data
;
1661 if (df_live
->solutions_dirty
)
1664 /* Set it true so that the solution is recomputed. */
1665 df_live
->solutions_dirty
= true;
1667 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1668 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1669 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1671 FOR_ALL_BB_FN (bb
, cfun
)
1673 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->live_bitmaps
);
1674 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->live_bitmaps
);
1675 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
));
1676 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
));
1681 /* Compare the saved datastructure and the new solution to the dataflow
1685 df_live_verify_solution_end (void)
1687 struct df_live_problem_data
*problem_data
;
1690 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1691 if (!problem_data
->out
)
1694 FOR_ALL_BB_FN (bb
, cfun
)
1696 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
)))
1697 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
))))
1699 /*df_dump (stderr);*/
1704 /* Cannot delete them immediately because you may want to dump them
1705 if the comparison fails. */
1706 FOR_ALL_BB_FN (bb
, cfun
)
1708 bitmap_clear (&problem_data
->in
[bb
->index
]);
1709 bitmap_clear (&problem_data
->out
[bb
->index
]);
1712 free (problem_data
->in
);
1713 free (problem_data
->out
);
1714 free (problem_data
);
1715 df_live
->problem_data
= NULL
;
1719 /* All of the information associated with every instance of the problem. */
1721 static const struct df_problem problem_LIVE
=
1723 DF_LIVE
, /* Problem id. */
1724 DF_FORWARD
, /* Direction. */
1725 df_live_alloc
, /* Allocate the problem specific data. */
1726 df_live_reset
, /* Reset global information. */
1727 df_live_free_bb_info
, /* Free basic block info. */
1728 df_live_local_compute
, /* Local compute function. */
1729 df_live_init
, /* Init the solution specific data. */
1730 df_worklist_dataflow
, /* Worklist solver. */
1731 NULL
, /* Confluence operator 0. */
1732 df_live_confluence_n
, /* Confluence operator n. */
1733 df_live_transfer_function
, /* Transfer function. */
1734 df_live_finalize
, /* Finalize function. */
1735 df_live_free
, /* Free all of the problem information. */
1736 df_live_free
, /* Remove this problem from the stack of dataflow problems. */
1737 NULL
, /* Debugging. */
1738 df_live_top_dump
, /* Debugging start block. */
1739 df_live_bottom_dump
, /* Debugging end block. */
1740 NULL
, /* Debugging start insn. */
1741 NULL
, /* Debugging end insn. */
1742 df_live_verify_solution_start
,/* Incremental solution verify start. */
1743 df_live_verify_solution_end
, /* Incremental solution verify end. */
1744 &problem_LR
, /* Dependent problem. */
1745 sizeof (struct df_live_bb_info
),/* Size of entry of block_info array. */
1746 TV_DF_LIVE
, /* Timing variable. */
1747 false /* Reset blocks on dropping out of blocks_to_analyze. */
1751 /* Create a new DATAFLOW instance and add it to an existing instance
1752 of DF. The returned structure is what is used to get at the
1756 df_live_add_problem (void)
1758 df_add_problem (&problem_LIVE
);
1759 /* These will be initialized when df_scan_blocks processes each
1761 df_live
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1765 /* Set all of the blocks as dirty. This needs to be done if this
1766 problem is added after all of the insns have been scanned. */
1769 df_live_set_all_dirty (void)
1772 FOR_ALL_BB_FN (bb
, cfun
)
1773 bitmap_set_bit (df_live
->out_of_date_transfer_functions
,
1778 /* Verify that all of the lr related info is consistent and
1782 df_live_verify_transfer_functions (void)
1785 bitmap_head saved_gen
;
1786 bitmap_head saved_kill
;
1787 bitmap_head all_blocks
;
1792 bitmap_initialize (&saved_gen
, &bitmap_default_obstack
);
1793 bitmap_initialize (&saved_kill
, &bitmap_default_obstack
);
1794 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1796 df_grow_insn_info ();
1798 FOR_ALL_BB_FN (bb
, cfun
)
1800 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1801 bitmap_set_bit (&all_blocks
, bb
->index
);
1805 /* Make a copy of the transfer functions and then compute
1806 new ones to see if the transfer functions have
1808 if (!bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1811 bitmap_copy (&saved_gen
, &bb_info
->gen
);
1812 bitmap_copy (&saved_kill
, &bb_info
->kill
);
1813 bitmap_clear (&bb_info
->gen
);
1814 bitmap_clear (&bb_info
->kill
);
1816 df_live_bb_local_compute (bb
->index
);
1817 gcc_assert (bitmap_equal_p (&saved_gen
, &bb_info
->gen
));
1818 gcc_assert (bitmap_equal_p (&saved_kill
, &bb_info
->kill
));
1823 /* If we do not have basic block info, the block must be in
1824 the list of dirty blocks or else some one has added a
1825 block behind our backs. */
1826 gcc_assert (bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1829 /* Make sure no one created a block without following
1831 gcc_assert (df_scan_get_bb_info (bb
->index
));
1834 /* Make sure there are no dirty bits in blocks that have been deleted. */
1835 gcc_assert (!bitmap_intersect_compl_p (df_live
->out_of_date_transfer_functions
,
1837 bitmap_clear (&saved_gen
);
1838 bitmap_clear (&saved_kill
);
1839 bitmap_clear (&all_blocks
);
1842 /*----------------------------------------------------------------------------
1843 MUST-INITIALIZED REGISTERS.
1844 ----------------------------------------------------------------------------*/
1846 /* Private data used to verify the solution for this problem. */
1847 struct df_mir_problem_data
1851 /* An obstack for the bitmaps we need for this problem. */
1852 bitmap_obstack mir_bitmaps
;
1856 /* Free basic block info. */
1859 df_mir_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
1862 struct df_mir_bb_info
*bb_info
= (struct df_mir_bb_info
*) vbb_info
;
1865 bitmap_clear (&bb_info
->gen
);
1866 bitmap_clear (&bb_info
->kill
);
1867 bitmap_clear (&bb_info
->in
);
1868 bitmap_clear (&bb_info
->out
);
1873 /* Allocate or reset bitmaps for DF_MIR blocks. The solution bits are
1874 not touched unless the block is new. */
1877 df_mir_alloc (bitmap all_blocks
)
1879 unsigned int bb_index
;
1881 struct df_mir_problem_data
*problem_data
;
1883 if (df_mir
->problem_data
)
1884 problem_data
= (struct df_mir_problem_data
*) df_mir
->problem_data
;
1887 problem_data
= XNEW (struct df_mir_problem_data
);
1888 df_mir
->problem_data
= problem_data
;
1890 problem_data
->out
= NULL
;
1891 problem_data
->in
= NULL
;
1892 bitmap_obstack_initialize (&problem_data
->mir_bitmaps
);
1895 df_grow_bb_info (df_mir
);
1897 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1899 struct df_mir_bb_info
*bb_info
= df_mir_get_bb_info (bb_index
);
1901 /* When bitmaps are already initialized, just clear them. */
1902 if (bb_info
->kill
.obstack
)
1904 bitmap_clear (&bb_info
->kill
);
1905 bitmap_clear (&bb_info
->gen
);
1909 bitmap_initialize (&bb_info
->kill
, &problem_data
->mir_bitmaps
);
1910 bitmap_initialize (&bb_info
->gen
, &problem_data
->mir_bitmaps
);
1911 bitmap_initialize (&bb_info
->in
, &problem_data
->mir_bitmaps
);
1912 bitmap_initialize (&bb_info
->out
, &problem_data
->mir_bitmaps
);
1913 bitmap_set_range (&bb_info
->in
, 0, DF_REG_SIZE (df
));
1914 bitmap_set_range (&bb_info
->out
, 0, DF_REG_SIZE (df
));
1918 df_mir
->optional_p
= 1;
1922 /* Reset the global solution for recalculation. */
1925 df_mir_reset (bitmap all_blocks
)
1927 unsigned int bb_index
;
1930 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1932 struct df_mir_bb_info
*bb_info
= df_mir_get_bb_info (bb_index
);
1934 gcc_assert (bb_info
);
1936 bitmap_clear (&bb_info
->in
);
1937 bitmap_set_range (&bb_info
->in
, 0, DF_REG_SIZE (df
));
1938 bitmap_clear (&bb_info
->out
);
1939 bitmap_set_range (&bb_info
->out
, 0, DF_REG_SIZE (df
));
1944 /* Compute local uninitialized register info for basic block BB. */
1947 df_mir_bb_local_compute (unsigned int bb_index
)
1949 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1950 struct df_mir_bb_info
*bb_info
= df_mir_get_bb_info (bb_index
);
1954 /* Ignoring artificial defs is intentional: these often pretend that some
1955 registers carry incoming arguments (when they are FUNCTION_ARG_REGNO) even
1956 though they are not used for that. As a result, conservatively assume
1957 they may be uninitialized. */
1959 FOR_BB_INSNS (bb
, insn
)
1961 unsigned int uid
= INSN_UID (insn
);
1962 struct df_insn_info
*insn_info
= DF_INSN_UID_GET (uid
);
1964 /* Inserting labels does not always trigger the incremental
1968 gcc_assert (!INSN_P (insn
));
1969 insn_info
= df_insn_create_insn_record (insn
);
1972 DF_INSN_INFO_LUID (insn_info
) = luid
;
1977 df_mir_simulate_one_insn (bb
, insn
, &bb_info
->kill
, &bb_info
->gen
);
1982 /* Compute local uninitialized register info. */
1985 df_mir_local_compute (bitmap all_blocks
)
1987 unsigned int bb_index
;
1990 df_grow_insn_info ();
1992 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1994 df_mir_bb_local_compute (bb_index
);
1999 /* Initialize the solution vectors. */
2002 df_mir_init (bitmap all_blocks
)
2004 df_mir_reset (all_blocks
);
2008 /* Initialize IN sets for blocks with no predecessors: when landing on such
2009 blocks, assume all registers are uninitialized. */
2012 df_mir_confluence_0 (basic_block bb
)
2014 struct df_mir_bb_info
*bb_info
= df_mir_get_bb_info (bb
->index
);
2016 bitmap_clear (&bb_info
->in
);
2020 /* Forward confluence function that ignores fake edges. */
2023 df_mir_confluence_n (edge e
)
2025 bitmap op1
= &df_mir_get_bb_info (e
->dest
->index
)->in
;
2026 bitmap op2
= &df_mir_get_bb_info (e
->src
->index
)->out
;
2028 if (e
->flags
& EDGE_FAKE
)
2031 /* A register is must-initialized at the entry of a basic block iff it is
2032 must-initialized at the exit of all the predecessors. */
2033 return bitmap_and_into (op1
, op2
);
2037 /* Transfer function for the forwards must-initialized problem. */
2040 df_mir_transfer_function (int bb_index
)
2042 struct df_mir_bb_info
*bb_info
= df_mir_get_bb_info (bb_index
);
2043 bitmap in
= &bb_info
->in
;
2044 bitmap out
= &bb_info
->out
;
2045 bitmap gen
= &bb_info
->gen
;
2046 bitmap kill
= &bb_info
->kill
;
2048 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
2052 /* Free all storage associated with the problem. */
2057 struct df_mir_problem_data
*problem_data
2058 = (struct df_mir_problem_data
*) df_mir
->problem_data
;
2059 if (df_mir
->block_info
)
2061 df_mir
->block_info_size
= 0;
2062 free (df_mir
->block_info
);
2063 df_mir
->block_info
= NULL
;
2064 bitmap_obstack_release (&problem_data
->mir_bitmaps
);
2065 free (problem_data
);
2066 df_mir
->problem_data
= NULL
;
2072 /* Debugging info at top of bb. */
2075 df_mir_top_dump (basic_block bb
, FILE *file
)
2077 struct df_mir_bb_info
*bb_info
= df_mir_get_bb_info (bb
->index
);
2082 fprintf (file
, ";; mir in \t");
2083 df_print_regset (file
, &bb_info
->in
);
2084 fprintf (file
, ";; mir kill\t");
2085 df_print_regset (file
, &bb_info
->kill
);
2086 fprintf (file
, ";; mir gen \t");
2087 df_print_regset (file
, &bb_info
->gen
);
2090 /* Debugging info at bottom of bb. */
2093 df_mir_bottom_dump (basic_block bb
, FILE *file
)
2095 struct df_mir_bb_info
*bb_info
= df_mir_get_bb_info (bb
->index
);
2100 fprintf (file
, ";; mir out \t");
2101 df_print_regset (file
, &bb_info
->out
);
2105 /* Build the datastructure to verify that the solution to the dataflow
2106 equations is not dirty. */
2109 df_mir_verify_solution_start (void)
2112 struct df_mir_problem_data
*problem_data
;
2113 if (df_mir
->solutions_dirty
)
2116 /* Set it true so that the solution is recomputed. */
2117 df_mir
->solutions_dirty
= true;
2119 problem_data
= (struct df_mir_problem_data
*) df_mir
->problem_data
;
2120 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
2121 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
2122 bitmap_obstack_initialize (&problem_data
->mir_bitmaps
);
2124 FOR_ALL_BB_FN (bb
, cfun
)
2126 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->mir_bitmaps
);
2127 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->mir_bitmaps
);
2128 bitmap_copy (&problem_data
->in
[bb
->index
], DF_MIR_IN (bb
));
2129 bitmap_copy (&problem_data
->out
[bb
->index
], DF_MIR_OUT (bb
));
2134 /* Compare the saved datastructure and the new solution to the dataflow
2138 df_mir_verify_solution_end (void)
2140 struct df_mir_problem_data
*problem_data
;
2143 problem_data
= (struct df_mir_problem_data
*) df_mir
->problem_data
;
2144 if (!problem_data
->out
)
2147 FOR_ALL_BB_FN (bb
, cfun
)
2149 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_MIR_IN (bb
)))
2150 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_MIR_OUT (bb
))))
2154 /* Cannot delete them immediately because you may want to dump them
2155 if the comparison fails. */
2156 FOR_ALL_BB_FN (bb
, cfun
)
2158 bitmap_clear (&problem_data
->in
[bb
->index
]);
2159 bitmap_clear (&problem_data
->out
[bb
->index
]);
2162 free (problem_data
->in
);
2163 free (problem_data
->out
);
2164 bitmap_obstack_release (&problem_data
->mir_bitmaps
);
2165 free (problem_data
);
2166 df_mir
->problem_data
= NULL
;
2170 /* All of the information associated with every instance of the problem. */
2172 static const struct df_problem problem_MIR
=
2174 DF_MIR
, /* Problem id. */
2175 DF_FORWARD
, /* Direction. */
2176 df_mir_alloc
, /* Allocate the problem specific data. */
2177 df_mir_reset
, /* Reset global information. */
2178 df_mir_free_bb_info
, /* Free basic block info. */
2179 df_mir_local_compute
, /* Local compute function. */
2180 df_mir_init
, /* Init the solution specific data. */
2181 df_worklist_dataflow
, /* Worklist solver. */
2182 df_mir_confluence_0
, /* Confluence operator 0. */
2183 df_mir_confluence_n
, /* Confluence operator n. */
2184 df_mir_transfer_function
, /* Transfer function. */
2185 NULL
, /* Finalize function. */
2186 df_mir_free
, /* Free all of the problem information. */
2187 df_mir_free
, /* Remove this problem from the stack of dataflow problems. */
2188 NULL
, /* Debugging. */
2189 df_mir_top_dump
, /* Debugging start block. */
2190 df_mir_bottom_dump
, /* Debugging end block. */
2191 NULL
, /* Debugging start insn. */
2192 NULL
, /* Debugging end insn. */
2193 df_mir_verify_solution_start
, /* Incremental solution verify start. */
2194 df_mir_verify_solution_end
, /* Incremental solution verify end. */
2195 NULL
, /* Dependent problem. */
2196 sizeof (struct df_mir_bb_info
),/* Size of entry of block_info array. */
2197 TV_DF_MIR
, /* Timing variable. */
2198 false /* Reset blocks on dropping out of blocks_to_analyze. */
2202 /* Create a new DATAFLOW instance and add it to an existing instance
2206 df_mir_add_problem (void)
2208 df_add_problem (&problem_MIR
);
2209 /* These will be initialized when df_scan_blocks processes each
2211 df_mir
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2215 /* Apply the effects of the gen/kills in INSN to the corresponding bitmaps. */
2218 df_mir_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx_insn
*insn
,
2219 bitmap kill
, bitmap gen
)
2223 FOR_EACH_INSN_DEF (def
, insn
)
2225 unsigned int regno
= DF_REF_REGNO (def
);
2227 /* The order of GENs/KILLs matters, so if this def clobbers a reg, any
2228 previous gen is irrelevant (and reciprocally). Also, claim that a
2229 register is GEN only if it is in all cases. */
2230 if (DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
2232 bitmap_set_bit (kill
, regno
);
2233 bitmap_clear_bit (gen
, regno
);
2235 /* In the worst case, partial and conditional defs can leave bits
2236 uninitialized, so assume they do not change anything. */
2237 else if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
2239 bitmap_set_bit (gen
, regno
);
2240 bitmap_clear_bit (kill
, regno
);
2245 /*----------------------------------------------------------------------------
2246 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
2248 Link either the defs to the uses and / or the uses to the defs.
2250 These problems are set up like the other dataflow problems so that
2251 they nicely fit into the framework. They are much simpler and only
2252 involve a single traversal of instructions and an examination of
2253 the reaching defs information (the dependent problem).
2254 ----------------------------------------------------------------------------*/
2256 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
2258 /* Create a du or ud chain from SRC to DST and link it into SRC. */
2261 df_chain_create (df_ref src
, df_ref dst
)
2263 struct df_link
*head
= DF_REF_CHAIN (src
);
2264 struct df_link
*link
= df_chain
->block_pool
->allocate ();
2266 DF_REF_CHAIN (src
) = link
;
2273 /* Delete any du or ud chains that start at REF and point to
2276 df_chain_unlink_1 (df_ref ref
, df_ref target
)
2278 struct df_link
*chain
= DF_REF_CHAIN (ref
);
2279 struct df_link
*prev
= NULL
;
2283 if (chain
->ref
== target
)
2286 prev
->next
= chain
->next
;
2288 DF_REF_CHAIN (ref
) = chain
->next
;
2289 df_chain
->block_pool
->remove (chain
);
2293 chain
= chain
->next
;
2298 /* Delete a du or ud chain that leave or point to REF. */
2301 df_chain_unlink (df_ref ref
)
2303 struct df_link
*chain
= DF_REF_CHAIN (ref
);
2306 struct df_link
*next
= chain
->next
;
2307 /* Delete the other side if it exists. */
2308 df_chain_unlink_1 (chain
->ref
, ref
);
2309 df_chain
->block_pool
->remove (chain
);
2312 DF_REF_CHAIN (ref
) = NULL
;
2316 /* Copy the du or ud chain starting at FROM_REF and attach it to
2320 df_chain_copy (df_ref to_ref
,
2321 struct df_link
*from_ref
)
2325 df_chain_create (to_ref
, from_ref
->ref
);
2326 from_ref
= from_ref
->next
;
2331 /* Remove this problem from the stack of dataflow problems. */
2334 df_chain_remove_problem (void)
2337 unsigned int bb_index
;
2339 /* Wholesale destruction of the old chains. */
2340 if (df_chain
->block_pool
)
2341 delete df_chain
->block_pool
;
2343 EXECUTE_IF_SET_IN_BITMAP (df_chain
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2347 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2349 if (df_chain_problem_p (DF_DU_CHAIN
))
2350 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
2351 DF_REF_CHAIN (def
) = NULL
;
2352 if (df_chain_problem_p (DF_UD_CHAIN
))
2353 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
2354 DF_REF_CHAIN (use
) = NULL
;
2356 FOR_BB_INSNS (bb
, insn
)
2359 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2360 if (df_chain_problem_p (DF_DU_CHAIN
))
2361 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2362 DF_REF_CHAIN (def
) = NULL
;
2363 if (df_chain_problem_p (DF_UD_CHAIN
))
2365 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2366 DF_REF_CHAIN (use
) = NULL
;
2367 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
2368 DF_REF_CHAIN (use
) = NULL
;
2373 bitmap_clear (df_chain
->out_of_date_transfer_functions
);
2374 df_chain
->block_pool
= NULL
;
2378 /* Remove the chain problem completely. */
2381 df_chain_fully_remove_problem (void)
2383 df_chain_remove_problem ();
2384 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
2389 /* Create def-use or use-def chains. */
2392 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2394 df_chain_remove_problem ();
2395 df_chain
->block_pool
= new object_allocator
<df_link
> ("df_chain_block pool");
2396 df_chain
->optional_p
= true;
2400 /* Reset all of the chains when the set of basic blocks changes. */
2403 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED
)
2405 df_chain_remove_problem ();
2409 /* Create the chains for a list of USEs. */
2412 df_chain_create_bb_process_use (bitmap local_rd
,
2417 unsigned int def_index
;
2419 for (; use
; use
= DF_REF_NEXT_LOC (use
))
2421 unsigned int uregno
= DF_REF_REGNO (use
);
2422 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2423 || (uregno
>= FIRST_PSEUDO_REGISTER
))
2425 /* Do not want to go through this for an uninitialized var. */
2426 int count
= DF_DEFS_COUNT (uregno
);
2429 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2431 unsigned int first_index
= DF_DEFS_BEGIN (uregno
);
2432 unsigned int last_index
= first_index
+ count
- 1;
2434 EXECUTE_IF_SET_IN_BITMAP (local_rd
, first_index
, def_index
, bi
)
2437 if (def_index
> last_index
)
2440 def
= DF_DEFS_GET (def_index
);
2441 if (df_chain_problem_p (DF_DU_CHAIN
))
2442 df_chain_create (def
, use
);
2443 if (df_chain_problem_p (DF_UD_CHAIN
))
2444 df_chain_create (use
, def
);
2453 /* Create chains from reaching defs bitmaps for basic block BB. */
2456 df_chain_create_bb (unsigned int bb_index
)
2458 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2459 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
2463 bitmap_initialize (&cpy
, &bitmap_default_obstack
);
2464 bitmap_copy (&cpy
, &bb_info
->in
);
2465 bitmap_set_bit (df_chain
->out_of_date_transfer_functions
, bb_index
);
2467 /* Since we are going forwards, process the artificial uses first
2468 then the artificial defs second. */
2471 /* Create the chains for the artificial uses from the EH_USES at the
2472 beginning of the block. */
2474 /* Artificials are only hard regs. */
2475 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2476 df_chain_create_bb_process_use (&cpy
,
2477 df_get_artificial_uses (bb
->index
),
2481 df_rd_simulate_artificial_defs_at_top (bb
, &cpy
);
2483 /* Process the regular instructions next. */
2484 FOR_BB_INSNS (bb
, insn
)
2487 unsigned int uid
= INSN_UID (insn
);
2489 /* First scan the uses and link them up with the defs that remain
2490 in the cpy vector. */
2491 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_USES (uid
), 0);
2492 if (df
->changeable_flags
& DF_EQ_NOTES
)
2493 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_EQ_USES (uid
), 0);
2495 /* Since we are going forwards, process the defs second. */
2496 df_rd_simulate_one_insn (bb
, insn
, &cpy
);
2499 /* Create the chains for the artificial uses of the hard registers
2500 at the end of the block. */
2501 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2502 df_chain_create_bb_process_use (&cpy
,
2503 df_get_artificial_uses (bb
->index
),
2506 bitmap_clear (&cpy
);
2509 /* Create def-use chains from reaching use bitmaps for basic blocks
2513 df_chain_finalize (bitmap all_blocks
)
2515 unsigned int bb_index
;
2518 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2520 df_chain_create_bb (bb_index
);
2525 /* Free all storage associated with the problem. */
2528 df_chain_free (void)
2530 delete df_chain
->block_pool
;
2531 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
2536 /* Debugging info. */
2539 df_chain_bb_dump (basic_block bb
, FILE *file
, bool top
)
2541 /* Artificials are only hard regs. */
2542 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
2544 if (df_chain_problem_p (DF_UD_CHAIN
))
2549 ";; UD chains for artificial uses at %s\n",
2550 top
? "top" : "bottom");
2551 FOR_EACH_ARTIFICIAL_USE (use
, bb
->index
)
2552 if ((top
&& (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2553 || (!top
&& !(DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)))
2555 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2556 df_chain_dump (DF_REF_CHAIN (use
), file
);
2557 fprintf (file
, "\n");
2560 if (df_chain_problem_p (DF_DU_CHAIN
))
2565 ";; DU chains for artificial defs at %s\n",
2566 top
? "top" : "bottom");
2567 FOR_EACH_ARTIFICIAL_DEF (def
, bb
->index
)
2568 if ((top
&& (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
2569 || (!top
&& !(DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)))
2571 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2572 df_chain_dump (DF_REF_CHAIN (def
), file
);
2573 fprintf (file
, "\n");
2579 df_chain_top_dump (basic_block bb
, FILE *file
)
2581 df_chain_bb_dump (bb
, file
, /*top=*/true);
2585 df_chain_bottom_dump (basic_block bb
, FILE *file
)
2587 df_chain_bb_dump (bb
, file
, /*top=*/false);
2591 df_chain_insn_top_dump (const rtx_insn
*insn
, FILE *file
)
2593 if (df_chain_problem_p (DF_UD_CHAIN
) && INSN_P (insn
))
2595 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2598 fprintf (file
, ";; UD chains for insn luid %d uid %d\n",
2599 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2600 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2601 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2602 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2604 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2605 if (DF_REF_FLAGS (use
) & DF_REF_READ_WRITE
)
2606 fprintf (file
, "read/write ");
2607 df_chain_dump (DF_REF_CHAIN (use
), file
);
2608 fprintf (file
, "\n");
2610 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
2611 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2612 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2614 fprintf (file
, ";; eq_note reg %d ", DF_REF_REGNO (use
));
2615 df_chain_dump (DF_REF_CHAIN (use
), file
);
2616 fprintf (file
, "\n");
2622 df_chain_insn_bottom_dump (const rtx_insn
*insn
, FILE *file
)
2624 if (df_chain_problem_p (DF_DU_CHAIN
) && INSN_P (insn
))
2626 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2628 fprintf (file
, ";; DU chains for insn luid %d uid %d\n",
2629 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2630 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2631 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def
))
2632 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2634 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2635 if (DF_REF_FLAGS (def
) & DF_REF_READ_WRITE
)
2636 fprintf (file
, "read/write ");
2637 df_chain_dump (DF_REF_CHAIN (def
), file
);
2638 fprintf (file
, "\n");
2640 fprintf (file
, "\n");
2644 static const struct df_problem problem_CHAIN
=
2646 DF_CHAIN
, /* Problem id. */
2647 DF_NONE
, /* Direction. */
2648 df_chain_alloc
, /* Allocate the problem specific data. */
2649 df_chain_reset
, /* Reset global information. */
2650 NULL
, /* Free basic block info. */
2651 NULL
, /* Local compute function. */
2652 NULL
, /* Init the solution specific data. */
2653 NULL
, /* Iterative solver. */
2654 NULL
, /* Confluence operator 0. */
2655 NULL
, /* Confluence operator n. */
2656 NULL
, /* Transfer function. */
2657 df_chain_finalize
, /* Finalize function. */
2658 df_chain_free
, /* Free all of the problem information. */
2659 df_chain_fully_remove_problem
,/* Remove this problem from the stack of dataflow problems. */
2660 NULL
, /* Debugging. */
2661 df_chain_top_dump
, /* Debugging start block. */
2662 df_chain_bottom_dump
, /* Debugging end block. */
2663 df_chain_insn_top_dump
, /* Debugging start insn. */
2664 df_chain_insn_bottom_dump
, /* Debugging end insn. */
2665 NULL
, /* Incremental solution verify start. */
2666 NULL
, /* Incremental solution verify end. */
2667 &problem_RD
, /* Dependent problem. */
2668 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
2669 TV_DF_CHAIN
, /* Timing variable. */
2670 false /* Reset blocks on dropping out of blocks_to_analyze. */
2674 /* Create a new DATAFLOW instance and add it to an existing instance
2675 of DF. The returned structure is what is used to get at the
2679 df_chain_add_problem (unsigned int chain_flags
)
2681 df_add_problem (&problem_CHAIN
);
2682 df_chain
->local_flags
= chain_flags
;
2683 df_chain
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2686 #undef df_chain_problem_p
2689 /*----------------------------------------------------------------------------
2690 WORD LEVEL LIVE REGISTERS
2692 Find the locations in the function where any use of a pseudo can
2693 reach in the backwards direction. In and out bitvectors are built
2694 for each basic block. We only track pseudo registers that have a
2695 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2696 contain two bits corresponding to each of the subwords.
2698 ----------------------------------------------------------------------------*/
2700 /* Private data used to verify the solution for this problem. */
2701 struct df_word_lr_problem_data
2703 /* An obstack for the bitmaps we need for this problem. */
2704 bitmap_obstack word_lr_bitmaps
;
2708 /* Free basic block info. */
2711 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
2714 struct df_word_lr_bb_info
*bb_info
= (struct df_word_lr_bb_info
*) vbb_info
;
2717 bitmap_clear (&bb_info
->use
);
2718 bitmap_clear (&bb_info
->def
);
2719 bitmap_clear (&bb_info
->in
);
2720 bitmap_clear (&bb_info
->out
);
2725 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2726 not touched unless the block is new. */
2729 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2731 unsigned int bb_index
;
2734 struct df_word_lr_problem_data
*problem_data
2735 = XNEW (struct df_word_lr_problem_data
);
2737 df_word_lr
->problem_data
= problem_data
;
2739 df_grow_bb_info (df_word_lr
);
2741 /* Create the mapping from regnos to slots. This does not change
2742 unless the problem is destroyed and recreated. In particular, if
2743 we end up deleting the only insn that used a subreg, we do not
2744 want to redo the mapping because this would invalidate everything
2747 bitmap_obstack_initialize (&problem_data
->word_lr_bitmaps
);
2749 FOR_EACH_BB_FN (bb
, cfun
)
2750 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, bb
->index
);
2752 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, ENTRY_BLOCK
);
2753 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, EXIT_BLOCK
);
2755 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2757 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2759 /* When bitmaps are already initialized, just clear them. */
2760 if (bb_info
->use
.obstack
)
2762 bitmap_clear (&bb_info
->def
);
2763 bitmap_clear (&bb_info
->use
);
2767 bitmap_initialize (&bb_info
->use
, &problem_data
->word_lr_bitmaps
);
2768 bitmap_initialize (&bb_info
->def
, &problem_data
->word_lr_bitmaps
);
2769 bitmap_initialize (&bb_info
->in
, &problem_data
->word_lr_bitmaps
);
2770 bitmap_initialize (&bb_info
->out
, &problem_data
->word_lr_bitmaps
);
2774 df_word_lr
->optional_p
= true;
2778 /* Reset the global solution for recalculation. */
2781 df_word_lr_reset (bitmap all_blocks
)
2783 unsigned int bb_index
;
2786 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2788 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2789 gcc_assert (bb_info
);
2790 bitmap_clear (&bb_info
->in
);
2791 bitmap_clear (&bb_info
->out
);
2795 /* Examine REF, and if it is for a reg we're interested in, set or
2796 clear the bits corresponding to its subwords from the bitmap
2797 according to IS_SET. LIVE is the bitmap we should update. We do
2798 not track hard regs or pseudos of any size other than 2 *
2800 We return true if we changed the bitmap, or if we encountered a register
2801 we're not tracking. */
2804 df_word_lr_mark_ref (df_ref ref
, bool is_set
, regset live
)
2806 rtx orig_reg
= DF_REF_REG (ref
);
2808 machine_mode reg_mode
;
2810 /* Left at -1 for whole accesses. */
2811 int which_subword
= -1;
2812 bool changed
= false;
2814 if (GET_CODE (reg
) == SUBREG
)
2815 reg
= SUBREG_REG (orig_reg
);
2816 regno
= REGNO (reg
);
2817 reg_mode
= GET_MODE (reg
);
2818 if (regno
< FIRST_PSEUDO_REGISTER
2819 || GET_MODE_SIZE (reg_mode
) != 2 * UNITS_PER_WORD
)
2822 if (GET_CODE (orig_reg
) == SUBREG
2823 && df_read_modify_subreg_p (orig_reg
))
2825 gcc_assert (DF_REF_FLAGS_IS_SET (ref
, DF_REF_PARTIAL
));
2826 if (subreg_lowpart_p (orig_reg
))
2833 if (which_subword
!= 1)
2834 changed
|= bitmap_set_bit (live
, regno
* 2);
2835 if (which_subword
!= 0)
2836 changed
|= bitmap_set_bit (live
, regno
* 2 + 1);
2840 if (which_subword
!= 1)
2841 changed
|= bitmap_clear_bit (live
, regno
* 2);
2842 if (which_subword
!= 0)
2843 changed
|= bitmap_clear_bit (live
, regno
* 2 + 1);
2848 /* Compute local live register info for basic block BB. */
2851 df_word_lr_bb_local_compute (unsigned int bb_index
)
2853 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2854 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2858 /* Ensure that artificial refs don't contain references to pseudos. */
2859 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
2860 gcc_assert (DF_REF_REGNO (def
) < FIRST_PSEUDO_REGISTER
);
2862 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
2863 gcc_assert (DF_REF_REGNO (use
) < FIRST_PSEUDO_REGISTER
);
2865 FOR_BB_INSNS_REVERSE (bb
, insn
)
2867 if (!NONDEBUG_INSN_P (insn
))
2870 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2871 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2872 /* If the def is to only part of the reg, it does
2873 not kill the other defs that reach here. */
2874 if (!(DF_REF_FLAGS (def
) & (DF_REF_CONDITIONAL
)))
2876 df_word_lr_mark_ref (def
, true, &bb_info
->def
);
2877 df_word_lr_mark_ref (def
, false, &bb_info
->use
);
2879 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2880 df_word_lr_mark_ref (use
, true, &bb_info
->use
);
2885 /* Compute local live register info for each basic block within BLOCKS. */
2888 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
2890 unsigned int bb_index
;
2893 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2895 if (bb_index
== EXIT_BLOCK
)
2899 EXECUTE_IF_SET_IN_BITMAP (df
->exit_block_uses
, FIRST_PSEUDO_REGISTER
,
2904 df_word_lr_bb_local_compute (bb_index
);
2907 bitmap_clear (df_word_lr
->out_of_date_transfer_functions
);
2911 /* Initialize the solution vectors. */
2914 df_word_lr_init (bitmap all_blocks
)
2916 unsigned int bb_index
;
2919 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2921 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2922 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
2923 bitmap_clear (&bb_info
->out
);
2928 /* Confluence function that ignores fake edges. */
2931 df_word_lr_confluence_n (edge e
)
2933 bitmap op1
= &df_word_lr_get_bb_info (e
->src
->index
)->out
;
2934 bitmap op2
= &df_word_lr_get_bb_info (e
->dest
->index
)->in
;
2936 return bitmap_ior_into (op1
, op2
);
2940 /* Transfer function. */
2943 df_word_lr_transfer_function (int bb_index
)
2945 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2946 bitmap in
= &bb_info
->in
;
2947 bitmap out
= &bb_info
->out
;
2948 bitmap use
= &bb_info
->use
;
2949 bitmap def
= &bb_info
->def
;
2951 return bitmap_ior_and_compl (in
, use
, out
, def
);
2955 /* Free all storage associated with the problem. */
2958 df_word_lr_free (void)
2960 struct df_word_lr_problem_data
*problem_data
2961 = (struct df_word_lr_problem_data
*)df_word_lr
->problem_data
;
2963 if (df_word_lr
->block_info
)
2965 df_word_lr
->block_info_size
= 0;
2966 free (df_word_lr
->block_info
);
2967 df_word_lr
->block_info
= NULL
;
2970 BITMAP_FREE (df_word_lr
->out_of_date_transfer_functions
);
2971 bitmap_obstack_release (&problem_data
->word_lr_bitmaps
);
2972 free (problem_data
);
2977 /* Debugging info at top of bb. */
2980 df_word_lr_top_dump (basic_block bb
, FILE *file
)
2982 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2986 fprintf (file
, ";; blr in \t");
2987 df_print_word_regset (file
, &bb_info
->in
);
2988 fprintf (file
, ";; blr use \t");
2989 df_print_word_regset (file
, &bb_info
->use
);
2990 fprintf (file
, ";; blr def \t");
2991 df_print_word_regset (file
, &bb_info
->def
);
2995 /* Debugging info at bottom of bb. */
2998 df_word_lr_bottom_dump (basic_block bb
, FILE *file
)
3000 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
3004 fprintf (file
, ";; blr out \t");
3005 df_print_word_regset (file
, &bb_info
->out
);
3009 /* All of the information associated with every instance of the problem. */
3011 static const struct df_problem problem_WORD_LR
=
3013 DF_WORD_LR
, /* Problem id. */
3014 DF_BACKWARD
, /* Direction. */
3015 df_word_lr_alloc
, /* Allocate the problem specific data. */
3016 df_word_lr_reset
, /* Reset global information. */
3017 df_word_lr_free_bb_info
, /* Free basic block info. */
3018 df_word_lr_local_compute
, /* Local compute function. */
3019 df_word_lr_init
, /* Init the solution specific data. */
3020 df_worklist_dataflow
, /* Worklist solver. */
3021 NULL
, /* Confluence operator 0. */
3022 df_word_lr_confluence_n
, /* Confluence operator n. */
3023 df_word_lr_transfer_function
, /* Transfer function. */
3024 NULL
, /* Finalize function. */
3025 df_word_lr_free
, /* Free all of the problem information. */
3026 df_word_lr_free
, /* Remove this problem from the stack of dataflow problems. */
3027 NULL
, /* Debugging. */
3028 df_word_lr_top_dump
, /* Debugging start block. */
3029 df_word_lr_bottom_dump
, /* Debugging end block. */
3030 NULL
, /* Debugging start insn. */
3031 NULL
, /* Debugging end insn. */
3032 NULL
, /* Incremental solution verify start. */
3033 NULL
, /* Incremental solution verify end. */
3034 NULL
, /* Dependent problem. */
3035 sizeof (struct df_word_lr_bb_info
),/* Size of entry of block_info array. */
3036 TV_DF_WORD_LR
, /* Timing variable. */
3037 false /* Reset blocks on dropping out of blocks_to_analyze. */
3041 /* Create a new DATAFLOW instance and add it to an existing instance
3042 of DF. The returned structure is what is used to get at the
3046 df_word_lr_add_problem (void)
3048 df_add_problem (&problem_WORD_LR
);
3049 /* These will be initialized when df_scan_blocks processes each
3051 df_word_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
3055 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
3056 any bits, which is used by the caller to determine whether a set is
3057 necessary. We also return true if there are other reasons not to delete
3061 df_word_lr_simulate_defs (rtx_insn
*insn
, bitmap live
)
3063 bool changed
= false;
3066 FOR_EACH_INSN_DEF (def
, insn
)
3067 if (DF_REF_FLAGS (def
) & DF_REF_CONDITIONAL
)
3070 changed
|= df_word_lr_mark_ref (def
, false, live
);
3075 /* Simulate the effects of the uses of INSN on LIVE. */
3078 df_word_lr_simulate_uses (rtx_insn
*insn
, bitmap live
)
3082 FOR_EACH_INSN_USE (use
, insn
)
3083 df_word_lr_mark_ref (use
, true, live
);
3086 /*----------------------------------------------------------------------------
3087 This problem computes REG_DEAD and REG_UNUSED notes.
3088 ----------------------------------------------------------------------------*/
3091 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
3093 df_note
->optional_p
= true;
3096 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
3098 df_print_note (const char *prefix
, rtx_insn
*insn
, rtx note
)
3102 fprintf (dump_file
, "%s %d ", prefix
, INSN_UID (insn
));
3103 print_rtl (dump_file
, note
);
3104 fprintf (dump_file
, "\n");
3109 /* After reg-stack, the x86 floating point stack regs are difficult to
3110 analyze because of all of the pushes, pops and rotations. Thus, we
3111 just leave the notes alone. */
3115 df_ignore_stack_reg (int regno
)
3117 return regstack_completed
3118 && IN_RANGE (regno
, FIRST_STACK_REG
, LAST_STACK_REG
);
3122 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED
)
3129 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
3132 df_remove_dead_and_unused_notes (rtx_insn
*insn
)
3134 rtx
*pprev
= ®_NOTES (insn
);
3139 switch (REG_NOTE_KIND (link
))
3142 /* After reg-stack, we need to ignore any unused notes
3143 for the stack registers. */
3144 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
3146 pprev
= &XEXP (link
, 1);
3151 rtx next
= XEXP (link
, 1);
3152 if (REG_DEAD_DEBUGGING
)
3153 df_print_note ("deleting: ", insn
, link
);
3154 free_EXPR_LIST_node (link
);
3155 *pprev
= link
= next
;
3160 /* After reg-stack, we need to ignore any unused notes
3161 for the stack registers. */
3162 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
3164 pprev
= &XEXP (link
, 1);
3169 rtx next
= XEXP (link
, 1);
3170 if (REG_DEAD_DEBUGGING
)
3171 df_print_note ("deleting: ", insn
, link
);
3172 free_EXPR_LIST_node (link
);
3173 *pprev
= link
= next
;
3178 pprev
= &XEXP (link
, 1);
3185 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
3186 as the bitmap of currently live registers. */
3189 df_remove_dead_eq_notes (rtx_insn
*insn
, bitmap live
)
3191 rtx
*pprev
= ®_NOTES (insn
);
3196 switch (REG_NOTE_KIND (link
))
3201 /* Remove the notes that refer to dead registers. As we have at most
3202 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
3203 so we need to purge the complete EQ_USES vector when removing
3204 the note using df_notes_rescan. */
3206 bool deleted
= false;
3208 FOR_EACH_INSN_EQ_USE (use
, insn
)
3209 if (DF_REF_REGNO (use
) > FIRST_PSEUDO_REGISTER
3211 && (DF_REF_FLAGS (use
) & DF_REF_IN_NOTE
)
3212 && !bitmap_bit_p (live
, DF_REF_REGNO (use
))
3213 && loc_mentioned_in_p (DF_REF_LOC (use
), XEXP (link
, 0)))
3221 if (REG_DEAD_DEBUGGING
)
3222 df_print_note ("deleting: ", insn
, link
);
3223 next
= XEXP (link
, 1);
3224 free_EXPR_LIST_node (link
);
3225 *pprev
= link
= next
;
3226 df_notes_rescan (insn
);
3230 pprev
= &XEXP (link
, 1);
3237 pprev
= &XEXP (link
, 1);
3244 /* Set a NOTE_TYPE note for REG in INSN. */
3247 df_set_note (enum reg_note note_type
, rtx_insn
*insn
, rtx reg
)
3249 gcc_checking_assert (!DEBUG_INSN_P (insn
));
3250 add_reg_note (insn
, note_type
, reg
);
3253 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
3254 arguments. Return true if the register value described by MWS's
3255 mw_reg is known to be completely unused, and if mw_reg can therefore
3256 be used in a REG_UNUSED note. */
3259 df_whole_mw_reg_unused_p (struct df_mw_hardreg
*mws
,
3260 bitmap live
, bitmap artificial_uses
)
3264 /* If MWS describes a partial reference, create REG_UNUSED notes for
3265 individual hard registers. */
3266 if (mws
->flags
& DF_REF_PARTIAL
)
3269 /* Likewise if some part of the register is used. */
3270 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
3271 if (bitmap_bit_p (live
, r
)
3272 || bitmap_bit_p (artificial_uses
, r
))
3275 gcc_assert (REG_P (mws
->mw_reg
));
3280 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
3281 based on the bits in LIVE. Do not generate notes for registers in
3282 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
3283 not generated if the reg is both read and written by the
3288 df_set_unused_notes_for_mw (rtx_insn
*insn
, struct df_mw_hardreg
*mws
,
3289 bitmap live
, bitmap do_not_gen
,
3290 bitmap artificial_uses
,
3291 struct dead_debug_local
*debug
)
3295 if (REG_DEAD_DEBUGGING
&& dump_file
)
3296 fprintf (dump_file
, "mw_set_unused looking at mws[%d..%d]\n",
3297 mws
->start_regno
, mws
->end_regno
);
3299 if (df_whole_mw_reg_unused_p (mws
, live
, artificial_uses
))
3301 unsigned int regno
= mws
->start_regno
;
3302 df_set_note (REG_UNUSED
, insn
, mws
->mw_reg
);
3303 dead_debug_insert_temp (debug
, regno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
3305 if (REG_DEAD_DEBUGGING
)
3306 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
3308 bitmap_set_bit (do_not_gen
, regno
);
3309 /* Only do this if the value is totally dead. */
3312 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
3314 if (!bitmap_bit_p (live
, r
)
3315 && !bitmap_bit_p (artificial_uses
, r
))
3317 df_set_note (REG_UNUSED
, insn
, regno_reg_rtx
[r
]);
3318 dead_debug_insert_temp (debug
, r
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
3319 if (REG_DEAD_DEBUGGING
)
3320 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
3322 bitmap_set_bit (do_not_gen
, r
);
3327 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
3328 arguments. Return true if the register value described by MWS's
3329 mw_reg is known to be completely dead, and if mw_reg can therefore
3330 be used in a REG_DEAD note. */
3333 df_whole_mw_reg_dead_p (struct df_mw_hardreg
*mws
,
3334 bitmap live
, bitmap artificial_uses
,
3339 /* If MWS describes a partial reference, create REG_DEAD notes for
3340 individual hard registers. */
3341 if (mws
->flags
& DF_REF_PARTIAL
)
3344 /* Likewise if some part of the register is not dead. */
3345 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
3346 if (bitmap_bit_p (live
, r
)
3347 || bitmap_bit_p (artificial_uses
, r
)
3348 || bitmap_bit_p (do_not_gen
, r
))
3351 gcc_assert (REG_P (mws
->mw_reg
));
3355 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3356 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3357 from being set if the instruction both reads and writes the
3361 df_set_dead_notes_for_mw (rtx_insn
*insn
, struct df_mw_hardreg
*mws
,
3362 bitmap live
, bitmap do_not_gen
,
3363 bitmap artificial_uses
, bool *added_notes_p
)
3366 bool is_debug
= *added_notes_p
;
3368 *added_notes_p
= false;
3370 if (REG_DEAD_DEBUGGING
&& dump_file
)
3372 fprintf (dump_file
, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3373 mws
->start_regno
, mws
->end_regno
);
3374 df_print_regset (dump_file
, do_not_gen
);
3375 fprintf (dump_file
, " live =");
3376 df_print_regset (dump_file
, live
);
3377 fprintf (dump_file
, " artificial uses =");
3378 df_print_regset (dump_file
, artificial_uses
);
3381 if (df_whole_mw_reg_dead_p (mws
, live
, artificial_uses
, do_not_gen
))
3385 *added_notes_p
= true;
3388 /* Add a dead note for the entire multi word register. */
3389 df_set_note (REG_DEAD
, insn
, mws
->mw_reg
);
3390 if (REG_DEAD_DEBUGGING
)
3391 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
3395 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
3396 if (!bitmap_bit_p (live
, r
)
3397 && !bitmap_bit_p (artificial_uses
, r
)
3398 && !bitmap_bit_p (do_not_gen
, r
))
3402 *added_notes_p
= true;
3405 df_set_note (REG_DEAD
, insn
, regno_reg_rtx
[r
]);
3406 if (REG_DEAD_DEBUGGING
)
3407 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
3414 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3415 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3418 df_create_unused_note (rtx_insn
*insn
, df_ref def
,
3419 bitmap live
, bitmap artificial_uses
,
3420 struct dead_debug_local
*debug
)
3422 unsigned int dregno
= DF_REF_REGNO (def
);
3424 if (REG_DEAD_DEBUGGING
&& dump_file
)
3426 fprintf (dump_file
, " regular looking at def ");
3427 df_ref_debug (def
, dump_file
);
3430 if (!((DF_REF_FLAGS (def
) & DF_REF_MW_HARDREG
)
3431 || bitmap_bit_p (live
, dregno
)
3432 || bitmap_bit_p (artificial_uses
, dregno
)
3433 || df_ignore_stack_reg (dregno
)))
3435 rtx reg
= (DF_REF_LOC (def
))
3436 ? *DF_REF_REAL_LOC (def
): DF_REF_REG (def
);
3437 df_set_note (REG_UNUSED
, insn
, reg
);
3438 dead_debug_insert_temp (debug
, dregno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
3439 if (REG_DEAD_DEBUGGING
)
3440 df_print_note ("adding 3: ", insn
, REG_NOTES (insn
));
3447 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3448 info: lifetime, bb, and number of defs and uses for basic block
3449 BB. The three bitvectors are scratch regs used here. */
3452 df_note_bb_compute (unsigned int bb_index
,
3453 bitmap live
, bitmap do_not_gen
, bitmap artificial_uses
)
3455 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3458 struct dead_debug_local debug
;
3460 dead_debug_local_init (&debug
, NULL
, NULL
);
3462 bitmap_copy (live
, df_get_live_out (bb
));
3463 bitmap_clear (artificial_uses
);
3465 if (REG_DEAD_DEBUGGING
&& dump_file
)
3467 fprintf (dump_file
, "live at bottom ");
3468 df_print_regset (dump_file
, live
);
3471 /* Process the artificial defs and uses at the bottom of the block
3472 to begin processing. */
3473 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3475 if (REG_DEAD_DEBUGGING
&& dump_file
)
3476 fprintf (dump_file
, "artificial def %d\n", DF_REF_REGNO (def
));
3478 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3479 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3482 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3483 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3485 unsigned int regno
= DF_REF_REGNO (use
);
3486 bitmap_set_bit (live
, regno
);
3488 /* Notes are not generated for any of the artificial registers
3489 at the bottom of the block. */
3490 bitmap_set_bit (artificial_uses
, regno
);
3493 if (REG_DEAD_DEBUGGING
&& dump_file
)
3495 fprintf (dump_file
, "live before artificials out ");
3496 df_print_regset (dump_file
, live
);
3499 FOR_BB_INSNS_REVERSE (bb
, insn
)
3504 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3508 debug_insn
= DEBUG_INSN_P (insn
);
3510 bitmap_clear (do_not_gen
);
3511 df_remove_dead_and_unused_notes (insn
);
3513 /* Process the defs. */
3516 if (REG_DEAD_DEBUGGING
&& dump_file
)
3518 fprintf (dump_file
, "processing call %d\n live =",
3520 df_print_regset (dump_file
, live
);
3523 /* We only care about real sets for calls. Clobbers cannot
3524 be depended on to really die. */
3525 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3526 if ((DF_MWS_REG_DEF_P (mw
))
3527 && !df_ignore_stack_reg (mw
->start_regno
))
3528 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3529 artificial_uses
, &debug
);
3531 /* All of the defs except the return value are some sort of
3532 clobber. This code is for the return. */
3533 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3535 unsigned int dregno
= DF_REF_REGNO (def
);
3536 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3538 df_create_unused_note (insn
,
3539 def
, live
, artificial_uses
, &debug
);
3540 bitmap_set_bit (do_not_gen
, dregno
);
3543 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3544 bitmap_clear_bit (live
, dregno
);
3550 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3551 if (DF_MWS_REG_DEF_P (mw
))
3552 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3553 artificial_uses
, &debug
);
3555 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3557 unsigned int dregno
= DF_REF_REGNO (def
);
3558 df_create_unused_note (insn
,
3559 def
, live
, artificial_uses
, &debug
);
3561 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3562 bitmap_set_bit (do_not_gen
, dregno
);
3564 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3565 bitmap_clear_bit (live
, dregno
);
3569 /* Process the uses. */
3570 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3571 if (DF_MWS_REG_USE_P (mw
)
3572 && !df_ignore_stack_reg (mw
->start_regno
))
3574 bool really_add_notes
= debug_insn
!= 0;
3576 df_set_dead_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3580 if (really_add_notes
)
3584 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3586 unsigned int uregno
= DF_REF_REGNO (use
);
3588 if (REG_DEAD_DEBUGGING
&& dump_file
&& !debug_insn
)
3590 fprintf (dump_file
, " regular looking at use ");
3591 df_ref_debug (use
, dump_file
);
3594 if (!bitmap_bit_p (live
, uregno
))
3600 /* We won't add REG_UNUSED or REG_DEAD notes for
3601 these, so we don't have to mess with them in
3602 debug insns either. */
3603 if (!bitmap_bit_p (artificial_uses
, uregno
)
3604 && !df_ignore_stack_reg (uregno
))
3605 dead_debug_add (&debug
, use
, uregno
);
3611 dead_debug_insert_temp (&debug
, uregno
, insn
,
3612 DEBUG_TEMP_BEFORE_WITH_REG
);
3614 if ( (!(DF_REF_FLAGS (use
)
3615 & (DF_REF_MW_HARDREG
| DF_REF_READ_WRITE
)))
3616 && (!bitmap_bit_p (do_not_gen
, uregno
))
3617 && (!bitmap_bit_p (artificial_uses
, uregno
))
3618 && (!df_ignore_stack_reg (uregno
)))
3620 rtx reg
= (DF_REF_LOC (use
))
3621 ? *DF_REF_REAL_LOC (use
) : DF_REF_REG (use
);
3622 df_set_note (REG_DEAD
, insn
, reg
);
3624 if (REG_DEAD_DEBUGGING
)
3625 df_print_note ("adding 4: ", insn
, REG_NOTES (insn
));
3627 /* This register is now live. */
3628 bitmap_set_bit (live
, uregno
);
3632 df_remove_dead_eq_notes (insn
, live
);
3634 if (debug_insn
== -1)
3636 /* ??? We could probably do better here, replacing dead
3637 registers with their definitions. */
3638 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
3639 df_insn_rescan_debug_internal (insn
);
3643 dead_debug_local_finish (&debug
, NULL
);
3647 /* Compute register info: lifetime, bb, and number of defs and uses. */
3649 df_note_compute (bitmap all_blocks
)
3651 unsigned int bb_index
;
3653 bitmap_head live
, do_not_gen
, artificial_uses
;
3655 bitmap_initialize (&live
, &df_bitmap_obstack
);
3656 bitmap_initialize (&do_not_gen
, &df_bitmap_obstack
);
3657 bitmap_initialize (&artificial_uses
, &df_bitmap_obstack
);
3659 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
3661 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3662 pseudos in debug insns because we don't always (re)visit blocks
3663 with death points after visiting dead uses. Even changing this
3664 loop to postorder would still leave room for visiting a death
3665 point before visiting a subsequent debug use. */
3666 df_note_bb_compute (bb_index
, &live
, &do_not_gen
, &artificial_uses
);
3669 bitmap_clear (&live
);
3670 bitmap_clear (&do_not_gen
);
3671 bitmap_clear (&artificial_uses
);
3675 /* Free all storage associated with the problem. */
3684 /* All of the information associated every instance of the problem. */
3686 static const struct df_problem problem_NOTE
=
3688 DF_NOTE
, /* Problem id. */
3689 DF_NONE
, /* Direction. */
3690 df_note_alloc
, /* Allocate the problem specific data. */
3691 NULL
, /* Reset global information. */
3692 NULL
, /* Free basic block info. */
3693 df_note_compute
, /* Local compute function. */
3694 NULL
, /* Init the solution specific data. */
3695 NULL
, /* Iterative solver. */
3696 NULL
, /* Confluence operator 0. */
3697 NULL
, /* Confluence operator n. */
3698 NULL
, /* Transfer function. */
3699 NULL
, /* Finalize function. */
3700 df_note_free
, /* Free all of the problem information. */
3701 df_note_free
, /* Remove this problem from the stack of dataflow problems. */
3702 NULL
, /* Debugging. */
3703 NULL
, /* Debugging start block. */
3704 NULL
, /* Debugging end block. */
3705 NULL
, /* Debugging start insn. */
3706 NULL
, /* Debugging end insn. */
3707 NULL
, /* Incremental solution verify start. */
3708 NULL
, /* Incremental solution verify end. */
3709 &problem_LR
, /* Dependent problem. */
3710 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
3711 TV_DF_NOTE
, /* Timing variable. */
3712 false /* Reset blocks on dropping out of blocks_to_analyze. */
3716 /* Create a new DATAFLOW instance and add it to an existing instance
3717 of DF. The returned structure is what is used to get at the
3721 df_note_add_problem (void)
3723 df_add_problem (&problem_NOTE
);
3729 /*----------------------------------------------------------------------------
3730 Functions for simulating the effects of single insns.
3732 You can either simulate in the forwards direction, starting from
3733 the top of a block or the backwards direction from the end of the
3734 block. If you go backwards, defs are examined first to clear bits,
3735 then uses are examined to set bits. If you go forwards, defs are
3736 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3737 are examined to clear bits. In either case, the result of examining
3738 a def can be undone (respectively by a use or a REG_UNUSED note).
3740 If you start at the top of the block, use one of DF_LIVE_IN or
3741 DF_LR_IN. If you start at the bottom of the block use one of
3742 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3743 THEY WILL BE DESTROYED.
3744 ----------------------------------------------------------------------------*/
3747 /* Find the set of DEFs for INSN. */
3750 df_simulate_find_defs (rtx_insn
*insn
, bitmap defs
)
3754 FOR_EACH_INSN_DEF (def
, insn
)
3755 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3758 /* Find the set of uses for INSN. This includes partial defs. */
3761 df_simulate_find_uses (rtx_insn
*insn
, bitmap uses
)
3764 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3766 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3767 if (DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3768 bitmap_set_bit (uses
, DF_REF_REGNO (def
));
3769 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3770 bitmap_set_bit (uses
, DF_REF_REGNO (use
));
3773 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3776 df_simulate_find_noclobber_defs (rtx_insn
*insn
, bitmap defs
)
3780 FOR_EACH_INSN_DEF (def
, insn
)
3781 if (!(DF_REF_FLAGS (def
) & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
3782 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3786 /* Simulate the effects of the defs of INSN on LIVE. */
3789 df_simulate_defs (rtx_insn
*insn
, bitmap live
)
3793 FOR_EACH_INSN_DEF (def
, insn
)
3795 unsigned int dregno
= DF_REF_REGNO (def
);
3797 /* If the def is to only part of the reg, it does
3798 not kill the other defs that reach here. */
3799 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
3800 bitmap_clear_bit (live
, dregno
);
3805 /* Simulate the effects of the uses of INSN on LIVE. */
3808 df_simulate_uses (rtx_insn
*insn
, bitmap live
)
3812 if (DEBUG_INSN_P (insn
))
3815 FOR_EACH_INSN_USE (use
, insn
)
3816 /* Add use to set of uses in this BB. */
3817 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3821 /* Add back the always live regs in BB to LIVE. */
3824 df_simulate_fixup_sets (basic_block bb
, bitmap live
)
3826 /* These regs are considered always live so if they end up dying
3827 because of some def, we need to bring the back again. */
3828 if (bb_has_eh_pred (bb
))
3829 bitmap_ior_into (live
, &df
->eh_block_artificial_uses
);
3831 bitmap_ior_into (live
, &df
->regular_block_artificial_uses
);
3835 /*----------------------------------------------------------------------------
3836 The following three functions are used only for BACKWARDS scanning:
3837 i.e. they process the defs before the uses.
3839 df_simulate_initialize_backwards should be called first with a
3840 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3841 df_simulate_one_insn_backwards should be called for each insn in
3842 the block, starting with the last one. Finally,
3843 df_simulate_finalize_backwards can be called to get a new value
3844 of the sets at the top of the block (this is rarely used).
3845 ----------------------------------------------------------------------------*/
3847 /* Apply the artificial uses and defs at the end of BB in a backwards
3851 df_simulate_initialize_backwards (basic_block bb
, bitmap live
)
3854 int bb_index
= bb
->index
;
3856 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3857 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3858 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3860 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3861 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3862 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3866 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3869 df_simulate_one_insn_backwards (basic_block bb
, rtx_insn
*insn
, bitmap live
)
3871 if (!NONDEBUG_INSN_P (insn
))
3874 df_simulate_defs (insn
, live
);
3875 df_simulate_uses (insn
, live
);
3876 df_simulate_fixup_sets (bb
, live
);
3880 /* Apply the artificial uses and defs at the top of BB in a backwards
3884 df_simulate_finalize_backwards (basic_block bb
, bitmap live
)
3890 int bb_index
= bb
->index
;
3892 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3893 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3894 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3897 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3898 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
3899 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3902 /*----------------------------------------------------------------------------
3903 The following three functions are used only for FORWARDS scanning:
3904 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3905 Thus it is important to add the DF_NOTES problem to the stack of
3906 problems computed before using these functions.
3908 df_simulate_initialize_forwards should be called first with a
3909 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3910 df_simulate_one_insn_forwards should be called for each insn in
3911 the block, starting with the first one.
3912 ----------------------------------------------------------------------------*/
3914 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3915 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3919 df_simulate_initialize_forwards (basic_block bb
, bitmap live
)
3922 int bb_index
= bb
->index
;
3924 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3925 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3926 bitmap_set_bit (live
, DF_REF_REGNO (def
));
3929 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3932 df_simulate_one_insn_forwards (basic_block bb
, rtx_insn
*insn
, bitmap live
)
3935 if (! INSN_P (insn
))
3938 /* Make sure that DF_NOTE really is an active df problem. */
3939 gcc_assert (df_note
);
3941 /* Note that this is the opposite as how the problem is defined, because
3942 in the LR problem defs _kill_ liveness. However, they do so backwards,
3943 while here the scan is performed forwards! So, first assume that the
3944 def is live, and if this is not true REG_UNUSED notes will rectify the
3946 df_simulate_find_noclobber_defs (insn
, live
);
3948 /* Clear all of the registers that go dead. */
3949 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
3951 switch (REG_NOTE_KIND (link
))
3956 rtx reg
= XEXP (link
, 0);
3957 bitmap_clear_range (live
, REGNO (reg
), REG_NREGS (reg
));
3964 df_simulate_fixup_sets (bb
, live
);
3967 /* Used by the next two functions to encode information about the
3968 memory references we found. */
3969 #define MEMREF_NORMAL 1
3970 #define MEMREF_VOLATILE 2
3972 /* Return an OR of MEMREF_NORMAL or MEMREF_VOLATILE for the MEMs in X. */
3975 find_memory (rtx_insn
*insn
)
3978 subrtx_iterator::array_type array
;
3979 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), NONCONST
)
3981 const_rtx x
= *iter
;
3982 if (GET_CODE (x
) == ASM_OPERANDS
&& MEM_VOLATILE_P (x
))
3983 flags
|= MEMREF_VOLATILE
;
3986 if (MEM_VOLATILE_P (x
))
3987 flags
|= MEMREF_VOLATILE
;
3988 else if (!MEM_READONLY_P (x
))
3989 flags
|= MEMREF_NORMAL
;
3995 /* A subroutine of can_move_insns_across_p called through note_stores.
3996 DATA points to an integer in which we set either the bit for
3997 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
4001 find_memory_stores (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
,
4002 void *data ATTRIBUTE_UNUSED
)
4004 int *pflags
= (int *)data
;
4005 if (GET_CODE (x
) == SUBREG
)
4007 /* Treat stores to SP as stores to memory, this will prevent problems
4008 when there are references to the stack frame. */
4009 if (x
== stack_pointer_rtx
)
4010 *pflags
|= MEMREF_VOLATILE
;
4013 *pflags
|= MEM_VOLATILE_P (x
) ? MEMREF_VOLATILE
: MEMREF_NORMAL
;
4016 /* Scan BB backwards, using df_simulate functions to keep track of
4017 lifetimes, up to insn POINT. The result is stored in LIVE. */
4020 simulate_backwards_to_point (basic_block bb
, regset live
, rtx point
)
4023 bitmap_copy (live
, df_get_live_out (bb
));
4024 df_simulate_initialize_backwards (bb
, live
);
4026 /* Scan and update life information until we reach the point we're
4028 for (insn
= BB_END (bb
); insn
!= point
; insn
= PREV_INSN (insn
))
4029 df_simulate_one_insn_backwards (bb
, insn
, live
);
4032 /* Return true if it is safe to move a group of insns, described by
4033 the range FROM to TO, backwards across another group of insns,
4034 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
4035 are no insns between ACROSS_TO and FROM, but they may be in
4036 different basic blocks; MERGE_BB is the block from which the
4037 insns will be moved. The caller must pass in a regset MERGE_LIVE
4038 which specifies the registers live after TO.
4040 This function may be called in one of two cases: either we try to
4041 move identical instructions from all successor blocks into their
4042 predecessor, or we try to move from only one successor block. If
4043 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
4044 the second case. It should contain a set of registers live at the
4045 end of ACROSS_TO which must not be clobbered by moving the insns.
4046 In that case, we're also more careful about moving memory references
4049 We return false if it is not safe to move the entire group, but it
4050 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
4051 is set to point at the last moveable insn in such a case. */
4054 can_move_insns_across (rtx_insn
*from
, rtx_insn
*to
,
4055 rtx_insn
*across_from
, rtx_insn
*across_to
,
4056 basic_block merge_bb
, regset merge_live
,
4057 regset other_branch_live
, rtx_insn
**pmove_upto
)
4059 rtx_insn
*insn
, *next
, *max_to
;
4060 bitmap merge_set
, merge_use
, local_merge_live
;
4061 bitmap test_set
, test_use
;
4062 unsigned i
, fail
= 0;
4064 int memrefs_in_across
= 0;
4065 int mem_sets_in_across
= 0;
4066 bool trapping_insns_in_across
= false;
4068 if (pmove_upto
!= NULL
)
4071 /* Find real bounds, ignoring debug insns. */
4072 while (!NONDEBUG_INSN_P (from
) && from
!= to
)
4073 from
= NEXT_INSN (from
);
4074 while (!NONDEBUG_INSN_P (to
) && from
!= to
)
4075 to
= PREV_INSN (to
);
4077 for (insn
= across_to
; ; insn
= next
)
4081 if (RTL_CONST_OR_PURE_CALL_P (insn
))
4082 /* Pure functions can read from memory. Const functions can
4083 read from arguments that the ABI has forced onto the stack.
4084 Neither sort of read can be volatile. */
4085 memrefs_in_across
|= MEMREF_NORMAL
;
4088 memrefs_in_across
|= MEMREF_VOLATILE
;
4089 mem_sets_in_across
|= MEMREF_VOLATILE
;
4092 if (NONDEBUG_INSN_P (insn
))
4094 if (volatile_insn_p (PATTERN (insn
)))
4096 memrefs_in_across
|= find_memory (insn
);
4097 note_stores (PATTERN (insn
), find_memory_stores
,
4098 &mem_sets_in_across
);
4099 /* This is used just to find sets of the stack pointer. */
4100 memrefs_in_across
|= mem_sets_in_across
;
4101 trapping_insns_in_across
|= may_trap_p (PATTERN (insn
));
4103 next
= PREV_INSN (insn
);
4104 if (insn
== across_from
)
4109 MERGE_SET = set of registers set in MERGE_BB
4110 MERGE_USE = set of registers used in MERGE_BB and live at its top
4111 MERGE_LIVE = set of registers live at the point inside the MERGE
4112 range that we've reached during scanning
4113 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
4114 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
4115 and live before ACROSS_FROM. */
4117 merge_set
= BITMAP_ALLOC (®_obstack
);
4118 merge_use
= BITMAP_ALLOC (®_obstack
);
4119 local_merge_live
= BITMAP_ALLOC (®_obstack
);
4120 test_set
= BITMAP_ALLOC (®_obstack
);
4121 test_use
= BITMAP_ALLOC (®_obstack
);
4123 /* Compute the set of registers set and used in the ACROSS range. */
4124 if (other_branch_live
!= NULL
)
4125 bitmap_copy (test_use
, other_branch_live
);
4126 df_simulate_initialize_backwards (merge_bb
, test_use
);
4127 for (insn
= across_to
; ; insn
= next
)
4129 if (NONDEBUG_INSN_P (insn
))
4131 df_simulate_find_defs (insn
, test_set
);
4132 df_simulate_defs (insn
, test_use
);
4133 df_simulate_uses (insn
, test_use
);
4135 next
= PREV_INSN (insn
);
4136 if (insn
== across_from
)
4140 /* Compute an upper bound for the amount of insns moved, by finding
4141 the first insn in MERGE that sets a register in TEST_USE, or uses
4142 a register in TEST_SET. We also check for calls, trapping operations,
4143 and memory references. */
4145 for (insn
= from
; ; insn
= next
)
4149 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_EPILOGUE_BEG
)
4151 if (NONDEBUG_INSN_P (insn
))
4153 if (may_trap_or_fault_p (PATTERN (insn
))
4154 && (trapping_insns_in_across
4155 || other_branch_live
!= NULL
4156 || volatile_insn_p (PATTERN (insn
))))
4159 /* We cannot move memory stores past each other, or move memory
4160 reads past stores, at least not without tracking them and
4161 calling true_dependence on every pair.
4163 If there is no other branch and no memory references or
4164 sets in the ACROSS range, we can move memory references
4165 freely, even volatile ones.
4167 Otherwise, the rules are as follows: volatile memory
4168 references and stores can't be moved at all, and any type
4169 of memory reference can't be moved if there are volatile
4170 accesses or stores in the ACROSS range. That leaves
4171 normal reads, which can be moved, as the trapping case is
4172 dealt with elsewhere. */
4173 if (other_branch_live
!= NULL
|| memrefs_in_across
!= 0)
4175 int mem_ref_flags
= 0;
4176 int mem_set_flags
= 0;
4177 note_stores (PATTERN (insn
), find_memory_stores
, &mem_set_flags
);
4178 mem_ref_flags
= find_memory (insn
);
4179 /* Catch sets of the stack pointer. */
4180 mem_ref_flags
|= mem_set_flags
;
4182 if ((mem_ref_flags
| mem_set_flags
) & MEMREF_VOLATILE
)
4184 if ((memrefs_in_across
& MEMREF_VOLATILE
) && mem_ref_flags
!= 0)
4186 if (mem_set_flags
!= 0
4187 || (mem_sets_in_across
!= 0 && mem_ref_flags
!= 0))
4190 df_simulate_find_uses (insn
, merge_use
);
4191 /* We're only interested in uses which use a value live at
4192 the top, not one previously set in this block. */
4193 bitmap_and_compl_into (merge_use
, merge_set
);
4194 df_simulate_find_defs (insn
, merge_set
);
4195 if (bitmap_intersect_p (merge_set
, test_use
)
4196 || bitmap_intersect_p (merge_use
, test_set
))
4198 if (!HAVE_cc0
|| !sets_cc0_p (insn
))
4201 next
= NEXT_INSN (insn
);
4208 if (max_to
== NULL_RTX
|| (fail
&& pmove_upto
== NULL
))
4211 /* Now, lower this upper bound by also taking into account that
4212 a range of insns moved across ACROSS must not leave a register
4213 live at the end that will be clobbered in ACROSS. We need to
4214 find a point where TEST_SET & LIVE == 0.
4216 Insns in the MERGE range that set registers which are also set
4217 in the ACROSS range may still be moved as long as we also move
4218 later insns which use the results of the set, and make the
4219 register dead again. This is verified by the condition stated
4220 above. We only need to test it for registers that are set in
4223 MERGE_LIVE is provided by the caller and holds live registers after
4225 bitmap_copy (local_merge_live
, merge_live
);
4226 for (insn
= to
; insn
!= max_to
; insn
= PREV_INSN (insn
))
4227 df_simulate_one_insn_backwards (merge_bb
, insn
, local_merge_live
);
4229 /* We're not interested in registers that aren't set in the moved
4231 bitmap_and_into (local_merge_live
, merge_set
);
4234 if (NONDEBUG_INSN_P (insn
))
4236 if (!bitmap_intersect_p (test_set
, local_merge_live
)
4237 && (!HAVE_cc0
|| !sets_cc0_p (insn
)))
4243 df_simulate_one_insn_backwards (merge_bb
, insn
,
4251 insn
= PREV_INSN (insn
);
4258 *pmove_upto
= max_to
;
4260 /* For small register class machines, don't lengthen lifetimes of
4261 hard registers before reload. */
4262 if (! reload_completed
4263 && targetm
.small_register_classes_for_mode_p (VOIDmode
))
4265 EXECUTE_IF_SET_IN_BITMAP (merge_set
, 0, i
, bi
)
4267 if (i
< FIRST_PSEUDO_REGISTER
4269 && ! global_regs
[i
])
4278 BITMAP_FREE (merge_set
);
4279 BITMAP_FREE (merge_use
);
4280 BITMAP_FREE (local_merge_live
);
4281 BITMAP_FREE (test_set
);
4282 BITMAP_FREE (test_use
);
4288 /*----------------------------------------------------------------------------
4289 MULTIPLE DEFINITIONS
4291 Find the locations in the function reached by multiple definition sites
4292 for a live pseudo. In and out bitvectors are built for each basic
4293 block. They are restricted for efficiency to live registers.
4295 The gen and kill sets for the problem are obvious. Together they
4296 include all defined registers in a basic block; the gen set includes
4297 registers where a partial or conditional or may-clobber definition is
4298 last in the BB, while the kill set includes registers with a complete
4299 definition coming last. However, the computation of the dataflow
4300 itself is interesting.
4302 The idea behind it comes from SSA form's iterated dominance frontier
4303 criterion for inserting PHI functions. Just like in that case, we can use
4304 the dominance frontier to find places where multiple definitions meet;
4305 a register X defined in a basic block BB1 has multiple definitions in
4306 basic blocks in BB1's dominance frontier.
4308 So, the in-set of a basic block BB2 is not just the union of the
4309 out-sets of BB2's predecessors, but includes some more bits that come
4310 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
4311 the previous paragraph). I called this set the init-set of BB2.
4313 (Note: I actually use the kill-set only to build the init-set.
4314 gen bits are anyway propagated from BB1 to BB2 by dataflow).
4316 For example, if you have
4320 if <...> goto BB2 else goto BB3;
4328 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
4329 init-set of BB3 includes r10 and r12, but not r11. Note that we do
4330 not need to iterate the dominance frontier, because we do not insert
4331 anything like PHI functions there! Instead, dataflow will take care of
4332 propagating the information to BB3's successors.
4333 ---------------------------------------------------------------------------*/
4335 /* Private data used to verify the solution for this problem. */
4336 struct df_md_problem_data
4338 /* An obstack for the bitmaps we need for this problem. */
4339 bitmap_obstack md_bitmaps
;
4342 /* Scratch var used by transfer functions. This is used to do md analysis
4343 only for live registers. */
4344 static bitmap_head df_md_scratch
;
4348 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
4351 struct df_md_bb_info
*bb_info
= (struct df_md_bb_info
*) vbb_info
;
4354 bitmap_clear (&bb_info
->kill
);
4355 bitmap_clear (&bb_info
->gen
);
4356 bitmap_clear (&bb_info
->init
);
4357 bitmap_clear (&bb_info
->in
);
4358 bitmap_clear (&bb_info
->out
);
4363 /* Allocate or reset bitmaps for DF_MD. The solution bits are
4364 not touched unless the block is new. */
4367 df_md_alloc (bitmap all_blocks
)
4369 unsigned int bb_index
;
4371 struct df_md_problem_data
*problem_data
;
4373 df_grow_bb_info (df_md
);
4374 if (df_md
->problem_data
)
4375 problem_data
= (struct df_md_problem_data
*) df_md
->problem_data
;
4378 problem_data
= XNEW (struct df_md_problem_data
);
4379 df_md
->problem_data
= problem_data
;
4380 bitmap_obstack_initialize (&problem_data
->md_bitmaps
);
4382 bitmap_initialize (&df_md_scratch
, &problem_data
->md_bitmaps
);
4384 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4386 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4387 /* When bitmaps are already initialized, just clear them. */
4388 if (bb_info
->init
.obstack
)
4390 bitmap_clear (&bb_info
->init
);
4391 bitmap_clear (&bb_info
->gen
);
4392 bitmap_clear (&bb_info
->kill
);
4393 bitmap_clear (&bb_info
->in
);
4394 bitmap_clear (&bb_info
->out
);
4398 bitmap_initialize (&bb_info
->init
, &problem_data
->md_bitmaps
);
4399 bitmap_initialize (&bb_info
->gen
, &problem_data
->md_bitmaps
);
4400 bitmap_initialize (&bb_info
->kill
, &problem_data
->md_bitmaps
);
4401 bitmap_initialize (&bb_info
->in
, &problem_data
->md_bitmaps
);
4402 bitmap_initialize (&bb_info
->out
, &problem_data
->md_bitmaps
);
4406 df_md
->optional_p
= true;
4409 /* Add the effect of the top artificial defs of BB to the multiple definitions
4413 df_md_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_md
)
4415 int bb_index
= bb
->index
;
4417 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
4418 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
4420 unsigned int dregno
= DF_REF_REGNO (def
);
4421 if (DF_REF_FLAGS (def
)
4422 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4423 bitmap_set_bit (local_md
, dregno
);
4425 bitmap_clear_bit (local_md
, dregno
);
4430 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4434 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx_insn
*insn
,
4439 FOR_EACH_INSN_DEF (def
, insn
)
4441 unsigned int dregno
= DF_REF_REGNO (def
);
4442 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4443 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4445 if (DF_REF_FLAGS (def
)
4446 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4447 bitmap_set_bit (local_md
, DF_REF_ID (def
));
4449 bitmap_clear_bit (local_md
, DF_REF_ID (def
));
4455 df_md_bb_local_compute_process_def (struct df_md_bb_info
*bb_info
,
4459 bitmap_clear (&seen_in_insn
);
4461 for (; def
; def
= DF_REF_NEXT_LOC (def
))
4463 unsigned int dregno
= DF_REF_REGNO (def
);
4464 if (((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4465 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4466 && top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
4468 if (!bitmap_bit_p (&seen_in_insn
, dregno
))
4470 if (DF_REF_FLAGS (def
)
4471 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4473 bitmap_set_bit (&bb_info
->gen
, dregno
);
4474 bitmap_clear_bit (&bb_info
->kill
, dregno
);
4478 /* When we find a clobber and a regular def,
4479 make sure the regular def wins. */
4480 bitmap_set_bit (&seen_in_insn
, dregno
);
4481 bitmap_set_bit (&bb_info
->kill
, dregno
);
4482 bitmap_clear_bit (&bb_info
->gen
, dregno
);
4490 /* Compute local multiple def info for basic block BB. */
4493 df_md_bb_local_compute (unsigned int bb_index
)
4495 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4496 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4499 /* Artificials are only hard regs. */
4500 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4501 df_md_bb_local_compute_process_def (bb_info
,
4502 df_get_artificial_defs (bb_index
),
4505 FOR_BB_INSNS (bb
, insn
)
4507 unsigned int uid
= INSN_UID (insn
);
4511 df_md_bb_local_compute_process_def (bb_info
, DF_INSN_UID_DEFS (uid
), 0);
4514 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4515 df_md_bb_local_compute_process_def (bb_info
,
4516 df_get_artificial_defs (bb_index
),
4520 /* Compute local reaching def info for each basic block within BLOCKS. */
4523 df_md_local_compute (bitmap all_blocks
)
4525 unsigned int bb_index
, df_bb_index
;
4526 bitmap_iterator bi1
, bi2
;
4528 bitmap_head
*frontiers
;
4530 bitmap_initialize (&seen_in_insn
, &bitmap_default_obstack
);
4532 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4534 df_md_bb_local_compute (bb_index
);
4537 bitmap_clear (&seen_in_insn
);
4539 frontiers
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
4540 FOR_ALL_BB_FN (bb
, cfun
)
4541 bitmap_initialize (&frontiers
[bb
->index
], &bitmap_default_obstack
);
4543 compute_dominance_frontiers (frontiers
);
4545 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4546 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4548 bitmap kill
= &df_md_get_bb_info (bb_index
)->kill
;
4549 EXECUTE_IF_SET_IN_BITMAP (&frontiers
[bb_index
], 0, df_bb_index
, bi2
)
4551 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, df_bb_index
);
4552 if (bitmap_bit_p (all_blocks
, df_bb_index
))
4553 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index
)->init
, kill
,
4554 df_get_live_in (bb
));
4558 FOR_ALL_BB_FN (bb
, cfun
)
4559 bitmap_clear (&frontiers
[bb
->index
]);
4564 /* Reset the global solution for recalculation. */
4567 df_md_reset (bitmap all_blocks
)
4569 unsigned int bb_index
;
4572 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4574 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4575 gcc_assert (bb_info
);
4576 bitmap_clear (&bb_info
->in
);
4577 bitmap_clear (&bb_info
->out
);
4582 df_md_transfer_function (int bb_index
)
4584 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4585 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4586 bitmap in
= &bb_info
->in
;
4587 bitmap out
= &bb_info
->out
;
4588 bitmap gen
= &bb_info
->gen
;
4589 bitmap kill
= &bb_info
->kill
;
4591 /* We need to use a scratch set here so that the value returned from this
4592 function invocation properly reflects whether the sets changed in a
4593 significant way; i.e. not just because the live set was anded in. */
4594 bitmap_and (&df_md_scratch
, gen
, df_get_live_out (bb
));
4596 /* Multiple definitions of a register are not relevant if it is not
4597 live. Thus we trim the result to the places where it is live. */
4598 bitmap_and_into (in
, df_get_live_in (bb
));
4600 return bitmap_ior_and_compl (out
, &df_md_scratch
, in
, kill
);
4603 /* Initialize the solution bit vectors for problem. */
4606 df_md_init (bitmap all_blocks
)
4608 unsigned int bb_index
;
4611 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4613 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4615 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4616 df_md_transfer_function (bb_index
);
4621 df_md_confluence_0 (basic_block bb
)
4623 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4624 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4627 /* In of target gets or of out of source. */
4630 df_md_confluence_n (edge e
)
4632 bitmap op1
= &df_md_get_bb_info (e
->dest
->index
)->in
;
4633 bitmap op2
= &df_md_get_bb_info (e
->src
->index
)->out
;
4635 if (e
->flags
& EDGE_FAKE
)
4638 if (e
->flags
& EDGE_EH
)
4639 return bitmap_ior_and_compl_into (op1
, op2
,
4640 regs_invalidated_by_call_regset
);
4642 return bitmap_ior_into (op1
, op2
);
4645 /* Free all storage associated with the problem. */
4650 struct df_md_problem_data
*problem_data
4651 = (struct df_md_problem_data
*) df_md
->problem_data
;
4653 bitmap_obstack_release (&problem_data
->md_bitmaps
);
4654 free (problem_data
);
4655 df_md
->problem_data
= NULL
;
4657 df_md
->block_info_size
= 0;
4658 free (df_md
->block_info
);
4659 df_md
->block_info
= NULL
;
4664 /* Debugging info at top of bb. */
4667 df_md_top_dump (basic_block bb
, FILE *file
)
4669 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4673 fprintf (file
, ";; md in \t");
4674 df_print_regset (file
, &bb_info
->in
);
4675 fprintf (file
, ";; md init \t");
4676 df_print_regset (file
, &bb_info
->init
);
4677 fprintf (file
, ";; md gen \t");
4678 df_print_regset (file
, &bb_info
->gen
);
4679 fprintf (file
, ";; md kill \t");
4680 df_print_regset (file
, &bb_info
->kill
);
4683 /* Debugging info at bottom of bb. */
4686 df_md_bottom_dump (basic_block bb
, FILE *file
)
4688 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4692 fprintf (file
, ";; md out \t");
4693 df_print_regset (file
, &bb_info
->out
);
4696 static const struct df_problem problem_MD
=
4698 DF_MD
, /* Problem id. */
4699 DF_FORWARD
, /* Direction. */
4700 df_md_alloc
, /* Allocate the problem specific data. */
4701 df_md_reset
, /* Reset global information. */
4702 df_md_free_bb_info
, /* Free basic block info. */
4703 df_md_local_compute
, /* Local compute function. */
4704 df_md_init
, /* Init the solution specific data. */
4705 df_worklist_dataflow
, /* Worklist solver. */
4706 df_md_confluence_0
, /* Confluence operator 0. */
4707 df_md_confluence_n
, /* Confluence operator n. */
4708 df_md_transfer_function
, /* Transfer function. */
4709 NULL
, /* Finalize function. */
4710 df_md_free
, /* Free all of the problem information. */
4711 df_md_free
, /* Remove this problem from the stack of dataflow problems. */
4712 NULL
, /* Debugging. */
4713 df_md_top_dump
, /* Debugging start block. */
4714 df_md_bottom_dump
, /* Debugging end block. */
4715 NULL
, /* Debugging start insn. */
4716 NULL
, /* Debugging end insn. */
4717 NULL
, /* Incremental solution verify start. */
4718 NULL
, /* Incremental solution verify end. */
4719 NULL
, /* Dependent problem. */
4720 sizeof (struct df_md_bb_info
),/* Size of entry of block_info array. */
4721 TV_DF_MD
, /* Timing variable. */
4722 false /* Reset blocks on dropping out of blocks_to_analyze. */
4725 /* Create a new MD instance and add it to the existing instance
4729 df_md_add_problem (void)
4731 df_add_problem (&problem_MD
);