1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2014 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"
30 #include "insn-config.h"
34 #include "alloc-pool.h"
36 #include "hard-reg-set.h"
37 #include "basic-block.h"
48 /* Note that turning REG_DEAD_DEBUGGING on will cause
49 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
50 addresses in the dumps. */
51 #define REG_DEAD_DEBUGGING 0
53 #define DF_SPARSE_THRESHOLD 32
55 static bitmap_head seen_in_block
;
56 static bitmap_head seen_in_insn
;
58 /*----------------------------------------------------------------------------
60 ----------------------------------------------------------------------------*/
62 /* Generic versions to get the void* version of the block info. Only
63 used inside the problem instance vectors. */
65 /* Dump a def-use or use-def chain for REF to FILE. */
68 df_chain_dump (struct df_link
*link
, FILE *file
)
71 for (; link
; link
= link
->next
)
73 fprintf (file
, "%c%d(bb %d insn %d) ",
74 DF_REF_REG_DEF_P (link
->ref
)
76 : (DF_REF_FLAGS (link
->ref
) & DF_REF_IN_NOTE
) ? 'e' : 'u',
77 DF_REF_ID (link
->ref
),
78 DF_REF_BBNO (link
->ref
),
79 DF_REF_IS_ARTIFICIAL (link
->ref
)
80 ? -1 : DF_REF_INSN_UID (link
->ref
));
86 /* Print some basic block info as part of df_dump. */
89 df_print_bb_index (basic_block bb
, FILE *file
)
94 fprintf (file
, "\n( ");
95 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
97 basic_block pred
= e
->src
;
98 fprintf (file
, "%d%s ", pred
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
100 fprintf (file
, ")->[%d]->( ", bb
->index
);
101 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
103 basic_block succ
= e
->dest
;
104 fprintf (file
, "%d%s ", succ
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
106 fprintf (file
, ")\n");
110 /*----------------------------------------------------------------------------
113 Find the locations in the function where each definition site for a
114 pseudo reaches. In and out bitvectors are built for each basic
115 block. The id field in the ref is used to index into these sets.
116 See df.h for details.
118 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
119 existing uses are included in the global reaching DEFs set, or in other
120 words only DEFs that are still live. This is a kind of pruned version
121 of the traditional reaching definitions problem that is much less
122 complex to compute and produces enough information to compute UD-chains.
123 In this context, live must be interpreted in the DF_LR sense: Uses that
124 are upward exposed but maybe not initialized on all paths through the
125 CFG. For a USE that is not reached by a DEF on all paths, we still want
126 to make those DEFs that do reach the USE visible, and pruning based on
127 DF_LIVE would make that impossible.
128 ----------------------------------------------------------------------------*/
130 /* This problem plays a large number of games for the sake of
133 1) The order of the bits in the bitvectors. After the scanning
134 phase, all of the defs are sorted. All of the defs for the reg 0
135 are first, followed by all defs for reg 1 and so on.
137 2) There are two kill sets, one if the number of defs is less or
138 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
141 <= : Data is built directly in the kill set.
143 > : One level of indirection is used to keep from generating long
144 strings of 1 bits in the kill sets. Bitvectors that are indexed
145 by the regnum are used to represent that there is a killing def
146 for the register. The confluence and transfer functions use
147 these along with the bitmap_clear_range call to remove ranges of
148 bits without actually generating a knockout vector.
150 The kill and sparse_kill and the dense_invalidated_by_call and
151 sparse_invalidated_by_call both play this game. */
153 /* Private data used to compute the solution for this problem. These
154 data structures are not accessible outside of this module. */
155 struct df_rd_problem_data
157 /* The set of defs to regs invalidated by call. */
158 bitmap_head sparse_invalidated_by_call
;
159 /* The set of defs to regs invalidate by call for rd. */
160 bitmap_head dense_invalidated_by_call
;
161 /* An obstack for the bitmaps we need for this problem. */
162 bitmap_obstack rd_bitmaps
;
166 /* Free basic block info. */
169 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
172 struct df_rd_bb_info
*bb_info
= (struct df_rd_bb_info
*) vbb_info
;
175 bitmap_clear (&bb_info
->kill
);
176 bitmap_clear (&bb_info
->sparse_kill
);
177 bitmap_clear (&bb_info
->gen
);
178 bitmap_clear (&bb_info
->in
);
179 bitmap_clear (&bb_info
->out
);
184 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
185 not touched unless the block is new. */
188 df_rd_alloc (bitmap all_blocks
)
190 unsigned int bb_index
;
192 struct df_rd_problem_data
*problem_data
;
194 if (df_rd
->problem_data
)
196 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
197 bitmap_clear (&problem_data
->sparse_invalidated_by_call
);
198 bitmap_clear (&problem_data
->dense_invalidated_by_call
);
202 problem_data
= XNEW (struct df_rd_problem_data
);
203 df_rd
->problem_data
= problem_data
;
205 bitmap_obstack_initialize (&problem_data
->rd_bitmaps
);
206 bitmap_initialize (&problem_data
->sparse_invalidated_by_call
,
207 &problem_data
->rd_bitmaps
);
208 bitmap_initialize (&problem_data
->dense_invalidated_by_call
,
209 &problem_data
->rd_bitmaps
);
212 df_grow_bb_info (df_rd
);
214 /* Because of the clustering of all use sites for the same pseudo,
215 we have to process all of the blocks before doing the analysis. */
217 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
219 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
221 /* When bitmaps are already initialized, just clear them. */
222 if (bb_info
->kill
.obstack
)
224 bitmap_clear (&bb_info
->kill
);
225 bitmap_clear (&bb_info
->sparse_kill
);
226 bitmap_clear (&bb_info
->gen
);
230 bitmap_initialize (&bb_info
->kill
, &problem_data
->rd_bitmaps
);
231 bitmap_initialize (&bb_info
->sparse_kill
, &problem_data
->rd_bitmaps
);
232 bitmap_initialize (&bb_info
->gen
, &problem_data
->rd_bitmaps
);
233 bitmap_initialize (&bb_info
->in
, &problem_data
->rd_bitmaps
);
234 bitmap_initialize (&bb_info
->out
, &problem_data
->rd_bitmaps
);
237 df_rd
->optional_p
= true;
241 /* Add the effect of the top artificial defs of BB to the reaching definitions
245 df_rd_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_rd
)
247 int bb_index
= bb
->index
;
249 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
250 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
252 unsigned int dregno
= DF_REF_REGNO (def
);
253 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
254 bitmap_clear_range (local_rd
,
255 DF_DEFS_BEGIN (dregno
),
256 DF_DEFS_COUNT (dregno
));
257 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
261 /* Add the effect of the defs of INSN to the reaching definitions bitmap
265 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx insn
,
270 FOR_EACH_INSN_DEF (def
, insn
)
272 unsigned int dregno
= DF_REF_REGNO (def
);
273 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
274 || (dregno
>= FIRST_PSEUDO_REGISTER
))
276 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
277 bitmap_clear_range (local_rd
,
278 DF_DEFS_BEGIN (dregno
),
279 DF_DEFS_COUNT (dregno
));
280 if (!(DF_REF_FLAGS (def
)
281 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
282 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
287 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
288 more complicated than just simulating, because we must produce the
289 gen and kill sets and hence deal with the two possible representations
293 df_rd_bb_local_compute_process_def (struct df_rd_bb_info
*bb_info
,
297 for (; def
; def
= DF_REF_NEXT_LOC (def
))
299 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
301 unsigned int regno
= DF_REF_REGNO (def
);
302 unsigned int begin
= DF_DEFS_BEGIN (regno
);
303 unsigned int n_defs
= DF_DEFS_COUNT (regno
);
305 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
306 || (regno
>= FIRST_PSEUDO_REGISTER
))
308 /* Only the last def(s) for a regno in the block has any
310 if (!bitmap_bit_p (&seen_in_block
, regno
))
312 /* The first def for regno in insn gets to knock out the
313 defs from other instructions. */
314 if ((!bitmap_bit_p (&seen_in_insn
, regno
))
315 /* If the def is to only part of the reg, it does
316 not kill the other defs that reach here. */
317 && (!(DF_REF_FLAGS (def
) &
318 (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))))
320 if (n_defs
> DF_SPARSE_THRESHOLD
)
322 bitmap_set_bit (&bb_info
->sparse_kill
, regno
);
323 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
327 bitmap_set_range (&bb_info
->kill
, begin
, n_defs
);
328 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
332 bitmap_set_bit (&seen_in_insn
, regno
);
333 /* All defs for regno in the instruction may be put into
335 if (!(DF_REF_FLAGS (def
)
336 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
337 bitmap_set_bit (&bb_info
->gen
, DF_REF_ID (def
));
344 /* Compute local reaching def info for basic block BB. */
347 df_rd_bb_local_compute (unsigned int bb_index
)
349 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
350 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
353 bitmap_clear (&seen_in_block
);
354 bitmap_clear (&seen_in_insn
);
356 /* Artificials are only hard regs. */
357 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
358 df_rd_bb_local_compute_process_def (bb_info
,
359 df_get_artificial_defs (bb_index
),
362 FOR_BB_INSNS_REVERSE (bb
, insn
)
364 unsigned int uid
= INSN_UID (insn
);
369 df_rd_bb_local_compute_process_def (bb_info
,
370 DF_INSN_UID_DEFS (uid
), 0);
372 /* This complex dance with the two bitmaps is required because
373 instructions can assign twice to the same pseudo. This
374 generally happens with calls that will have one def for the
375 result and another def for the clobber. If only one vector
376 is used and the clobber goes first, the result will be
378 bitmap_ior_into (&seen_in_block
, &seen_in_insn
);
379 bitmap_clear (&seen_in_insn
);
382 /* Process the artificial defs at the top of the block last since we
383 are going backwards through the block and these are logically at
385 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
386 df_rd_bb_local_compute_process_def (bb_info
,
387 df_get_artificial_defs (bb_index
),
392 /* Compute local reaching def info for each basic block within BLOCKS. */
395 df_rd_local_compute (bitmap all_blocks
)
397 unsigned int bb_index
;
400 struct df_rd_problem_data
*problem_data
401 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
402 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
403 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
405 bitmap_initialize (&seen_in_block
, &df_bitmap_obstack
);
406 bitmap_initialize (&seen_in_insn
, &df_bitmap_obstack
);
408 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG
);
410 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
412 df_rd_bb_local_compute (bb_index
);
415 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
416 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset
, 0, regno
, bi
)
418 if (! HARD_REGISTER_NUM_P (regno
)
419 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
421 if (DF_DEFS_COUNT (regno
) > DF_SPARSE_THRESHOLD
)
422 bitmap_set_bit (sparse_invalidated
, regno
);
424 bitmap_set_range (dense_invalidated
,
425 DF_DEFS_BEGIN (regno
),
426 DF_DEFS_COUNT (regno
));
430 bitmap_clear (&seen_in_block
);
431 bitmap_clear (&seen_in_insn
);
435 /* Initialize the solution bit vectors for problem. */
438 df_rd_init_solution (bitmap all_blocks
)
440 unsigned int bb_index
;
443 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
445 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
447 bitmap_copy (&bb_info
->out
, &bb_info
->gen
);
448 bitmap_clear (&bb_info
->in
);
452 /* In of target gets or of out of source. */
455 df_rd_confluence_n (edge e
)
457 bitmap op1
= &df_rd_get_bb_info (e
->dest
->index
)->in
;
458 bitmap op2
= &df_rd_get_bb_info (e
->src
->index
)->out
;
459 bool changed
= false;
461 if (e
->flags
& EDGE_FAKE
)
464 if (e
->flags
& EDGE_EH
)
466 struct df_rd_problem_data
*problem_data
467 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
468 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
469 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
474 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
475 bitmap_and_compl (&tmp
, op2
, dense_invalidated
);
477 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
479 bitmap_clear_range (&tmp
,
480 DF_DEFS_BEGIN (regno
),
481 DF_DEFS_COUNT (regno
));
483 changed
|= bitmap_ior_into (op1
, &tmp
);
488 return bitmap_ior_into (op1
, op2
);
492 /* Transfer function. */
495 df_rd_transfer_function (int bb_index
)
497 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
500 bitmap in
= &bb_info
->in
;
501 bitmap out
= &bb_info
->out
;
502 bitmap gen
= &bb_info
->gen
;
503 bitmap kill
= &bb_info
->kill
;
504 bitmap sparse_kill
= &bb_info
->sparse_kill
;
505 bool changed
= false;
507 if (bitmap_empty_p (sparse_kill
))
508 changed
= bitmap_ior_and_compl (out
, gen
, in
, kill
);
511 struct df_rd_problem_data
*problem_data
;
514 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
515 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
516 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
517 bitmap_initialize (&tmp
, &problem_data
->rd_bitmaps
);
519 bitmap_and_compl (&tmp
, in
, kill
);
520 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
522 bitmap_clear_range (&tmp
,
523 DF_DEFS_BEGIN (regno
),
524 DF_DEFS_COUNT (regno
));
526 bitmap_ior_into (&tmp
, gen
);
527 changed
= !bitmap_equal_p (&tmp
, out
);
537 if (df
->changeable_flags
& DF_RD_PRUNE_DEAD_DEFS
)
539 /* Create a mask of DEFs for all registers live at the end of this
540 basic block, and mask out DEFs of registers that are not live.
541 Computing the mask looks costly, but the benefit of the pruning
542 outweighs the cost. */
543 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
544 bitmap regs_live_out
= &df_lr_get_bb_info (bb_index
)->out
;
545 bitmap live_defs
= BITMAP_ALLOC (&df_bitmap_obstack
);
549 EXECUTE_IF_SET_IN_BITMAP (regs_live_out
, 0, regno
, bi
)
550 bitmap_set_range (live_defs
,
551 DF_DEFS_BEGIN (regno
),
552 DF_DEFS_COUNT (regno
));
553 changed
|= bitmap_and_into (&bb_info
->out
, live_defs
);
554 BITMAP_FREE (live_defs
);
560 /* Free all storage associated with the problem. */
565 struct df_rd_problem_data
*problem_data
566 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
570 bitmap_obstack_release (&problem_data
->rd_bitmaps
);
572 df_rd
->block_info_size
= 0;
573 free (df_rd
->block_info
);
574 df_rd
->block_info
= NULL
;
575 free (df_rd
->problem_data
);
581 /* Debugging info. */
584 df_rd_start_dump (FILE *file
)
586 struct df_rd_problem_data
*problem_data
587 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
588 unsigned int m
= DF_REG_SIZE (df
);
591 if (!df_rd
->block_info
)
594 fprintf (file
, ";; Reaching defs:\n");
596 fprintf (file
, ";; sparse invalidated \t");
597 dump_bitmap (file
, &problem_data
->sparse_invalidated_by_call
);
598 fprintf (file
, ";; dense invalidated \t");
599 dump_bitmap (file
, &problem_data
->dense_invalidated_by_call
);
601 fprintf (file
, ";; reg->defs[] map:\t");
602 for (regno
= 0; regno
< m
; regno
++)
603 if (DF_DEFS_COUNT (regno
))
604 fprintf (file
, "%d[%d,%d] ", regno
,
605 DF_DEFS_BEGIN (regno
),
606 DF_DEFS_BEGIN (regno
) + DF_DEFS_COUNT (regno
) - 1);
607 fprintf (file
, "\n");
612 df_rd_dump_defs_set (bitmap defs_set
, const char *prefix
, FILE *file
)
616 unsigned int m
= DF_REG_SIZE (df
);
617 bool first_reg
= true;
619 fprintf (file
, "%s\t(%d) ", prefix
, (int) bitmap_count_bits (defs_set
));
621 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
622 for (regno
= 0; regno
< m
; regno
++)
624 if (HARD_REGISTER_NUM_P (regno
)
625 && (df
->changeable_flags
& DF_NO_HARD_REGS
))
627 bitmap_set_range (&tmp
, DF_DEFS_BEGIN (regno
), DF_DEFS_COUNT (regno
));
628 bitmap_and_into (&tmp
, defs_set
);
629 if (! bitmap_empty_p (&tmp
))
633 bool first_def
= true;
639 fprintf (file
, "%u[", regno
);
640 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, ix
, bi
)
642 fprintf (file
, "%s%u", first_def
? "" : ",", ix
);
650 fprintf (file
, "\n");
654 /* Debugging info at top of bb. */
657 df_rd_top_dump (basic_block bb
, FILE *file
)
659 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
663 df_rd_dump_defs_set (&bb_info
->in
, ";; rd in ", file
);
664 df_rd_dump_defs_set (&bb_info
->gen
, ";; rd gen ", file
);
665 df_rd_dump_defs_set (&bb_info
->kill
, ";; rd kill", file
);
669 /* Debugging info at bottom of bb. */
672 df_rd_bottom_dump (basic_block bb
, FILE *file
)
674 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
678 df_rd_dump_defs_set (&bb_info
->out
, ";; rd out ", file
);
681 /* All of the information associated with every instance of the problem. */
683 static struct df_problem problem_RD
=
685 DF_RD
, /* Problem id. */
686 DF_FORWARD
, /* Direction. */
687 df_rd_alloc
, /* Allocate the problem specific data. */
688 NULL
, /* Reset global information. */
689 df_rd_free_bb_info
, /* Free basic block info. */
690 df_rd_local_compute
, /* Local compute function. */
691 df_rd_init_solution
, /* Init the solution specific data. */
692 df_worklist_dataflow
, /* Worklist solver. */
693 NULL
, /* Confluence operator 0. */
694 df_rd_confluence_n
, /* Confluence operator n. */
695 df_rd_transfer_function
, /* Transfer function. */
696 NULL
, /* Finalize function. */
697 df_rd_free
, /* Free all of the problem information. */
698 df_rd_free
, /* Remove this problem from the stack of dataflow problems. */
699 df_rd_start_dump
, /* Debugging. */
700 df_rd_top_dump
, /* Debugging start block. */
701 df_rd_bottom_dump
, /* Debugging end block. */
702 NULL
, /* Debugging start insn. */
703 NULL
, /* Debugging end insn. */
704 NULL
, /* Incremental solution verify start. */
705 NULL
, /* Incremental solution verify end. */
706 NULL
, /* Dependent problem. */
707 sizeof (struct df_rd_bb_info
),/* Size of entry of block_info array. */
708 TV_DF_RD
, /* Timing variable. */
709 true /* Reset blocks on dropping out of blocks_to_analyze. */
714 /* Create a new RD instance and add it to the existing instance
718 df_rd_add_problem (void)
720 df_add_problem (&problem_RD
);
725 /*----------------------------------------------------------------------------
728 Find the locations in the function where any use of a pseudo can
729 reach in the backwards direction. In and out bitvectors are built
730 for each basic block. The regno is used to index into these sets.
731 See df.h for details.
732 ----------------------------------------------------------------------------*/
734 /* Private data used to verify the solution for this problem. */
735 struct df_lr_problem_data
739 /* An obstack for the bitmaps we need for this problem. */
740 bitmap_obstack lr_bitmaps
;
743 /* Free basic block info. */
746 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
749 struct df_lr_bb_info
*bb_info
= (struct df_lr_bb_info
*) vbb_info
;
752 bitmap_clear (&bb_info
->use
);
753 bitmap_clear (&bb_info
->def
);
754 bitmap_clear (&bb_info
->in
);
755 bitmap_clear (&bb_info
->out
);
760 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
761 not touched unless the block is new. */
764 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
766 unsigned int bb_index
;
768 struct df_lr_problem_data
*problem_data
;
770 df_grow_bb_info (df_lr
);
771 if (df_lr
->problem_data
)
772 problem_data
= (struct df_lr_problem_data
*) df_lr
->problem_data
;
775 problem_data
= XNEW (struct df_lr_problem_data
);
776 df_lr
->problem_data
= problem_data
;
778 problem_data
->out
= NULL
;
779 problem_data
->in
= NULL
;
780 bitmap_obstack_initialize (&problem_data
->lr_bitmaps
);
783 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
785 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
787 /* When bitmaps are already initialized, just clear them. */
788 if (bb_info
->use
.obstack
)
790 bitmap_clear (&bb_info
->def
);
791 bitmap_clear (&bb_info
->use
);
795 bitmap_initialize (&bb_info
->use
, &problem_data
->lr_bitmaps
);
796 bitmap_initialize (&bb_info
->def
, &problem_data
->lr_bitmaps
);
797 bitmap_initialize (&bb_info
->in
, &problem_data
->lr_bitmaps
);
798 bitmap_initialize (&bb_info
->out
, &problem_data
->lr_bitmaps
);
802 df_lr
->optional_p
= false;
806 /* Reset the global solution for recalculation. */
809 df_lr_reset (bitmap all_blocks
)
811 unsigned int bb_index
;
814 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
816 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
817 gcc_assert (bb_info
);
818 bitmap_clear (&bb_info
->in
);
819 bitmap_clear (&bb_info
->out
);
824 /* Compute local live register info for basic block BB. */
827 df_lr_bb_local_compute (unsigned int bb_index
)
829 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
830 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
834 /* Process the registers set in an exception handler. */
835 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
836 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
838 unsigned int dregno
= DF_REF_REGNO (def
);
839 bitmap_set_bit (&bb_info
->def
, dregno
);
840 bitmap_clear_bit (&bb_info
->use
, dregno
);
843 /* Process the hardware registers that are always live. */
844 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
845 /* Add use to set of uses in this BB. */
846 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
847 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
849 FOR_BB_INSNS_REVERSE (bb
, insn
)
851 if (!NONDEBUG_INSN_P (insn
))
854 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
855 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
856 /* If the def is to only part of the reg, it does
857 not kill the other defs that reach here. */
858 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
860 unsigned int dregno
= DF_REF_REGNO (def
);
861 bitmap_set_bit (&bb_info
->def
, dregno
);
862 bitmap_clear_bit (&bb_info
->use
, dregno
);
865 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
866 /* Add use to set of uses in this BB. */
867 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
870 /* Process the registers set in an exception handler or the hard
871 frame pointer if this block is the target of a non local
873 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
874 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
876 unsigned int dregno
= DF_REF_REGNO (def
);
877 bitmap_set_bit (&bb_info
->def
, dregno
);
878 bitmap_clear_bit (&bb_info
->use
, dregno
);
882 /* Process the uses that are live into an exception handler. */
883 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
884 /* Add use to set of uses in this BB. */
885 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
886 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
889 /* If the df_live problem is not defined, such as at -O0 and -O1, we
890 still need to keep the luids up to date. This is normally done
891 in the df_live problem since this problem has a forwards
894 df_recompute_luids (bb
);
898 /* Compute local live register info for each basic block within BLOCKS. */
901 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
903 unsigned int bb_index
, i
;
906 bitmap_clear (&df
->hardware_regs_used
);
908 /* The all-important stack pointer must always be live. */
909 bitmap_set_bit (&df
->hardware_regs_used
, STACK_POINTER_REGNUM
);
911 /* Global regs are always live, too. */
912 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
914 bitmap_set_bit (&df
->hardware_regs_used
, i
);
916 /* Before reload, there are a few registers that must be forced
917 live everywhere -- which might not already be the case for
918 blocks within infinite loops. */
919 if (!reload_completed
)
921 unsigned int pic_offset_table_regnum
= PIC_OFFSET_TABLE_REGNUM
;
922 /* Any reference to any pseudo before reload is a potential
923 reference of the frame pointer. */
924 bitmap_set_bit (&df
->hardware_regs_used
, FRAME_POINTER_REGNUM
);
926 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
927 /* Pseudos with argument area equivalences may require
928 reloading via the argument pointer. */
929 if (fixed_regs
[ARG_POINTER_REGNUM
])
930 bitmap_set_bit (&df
->hardware_regs_used
, ARG_POINTER_REGNUM
);
933 /* Any constant, or pseudo with constant equivalences, may
934 require reloading from memory using the pic register. */
935 if (pic_offset_table_regnum
!= INVALID_REGNUM
936 && fixed_regs
[pic_offset_table_regnum
])
937 bitmap_set_bit (&df
->hardware_regs_used
, pic_offset_table_regnum
);
940 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
942 if (bb_index
== EXIT_BLOCK
)
944 /* The exit block is special for this problem and its bits are
945 computed from thin air. */
946 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (EXIT_BLOCK
);
947 bitmap_copy (&bb_info
->use
, df
->exit_block_uses
);
950 df_lr_bb_local_compute (bb_index
);
953 bitmap_clear (df_lr
->out_of_date_transfer_functions
);
957 /* Initialize the solution vectors. */
960 df_lr_init (bitmap all_blocks
)
962 unsigned int bb_index
;
965 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
967 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
968 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
969 bitmap_clear (&bb_info
->out
);
974 /* Confluence function that processes infinite loops. This might be a
975 noreturn function that throws. And even if it isn't, getting the
976 unwind info right helps debugging. */
978 df_lr_confluence_0 (basic_block bb
)
980 bitmap op1
= &df_lr_get_bb_info (bb
->index
)->out
;
981 if (bb
!= EXIT_BLOCK_PTR_FOR_FN (cfun
))
982 bitmap_copy (op1
, &df
->hardware_regs_used
);
986 /* Confluence function that ignores fake edges. */
989 df_lr_confluence_n (edge e
)
991 bitmap op1
= &df_lr_get_bb_info (e
->src
->index
)->out
;
992 bitmap op2
= &df_lr_get_bb_info (e
->dest
->index
)->in
;
993 bool changed
= false;
995 /* Call-clobbered registers die across exception and call edges. */
996 /* ??? Abnormal call edges ignored for the moment, as this gets
997 confused by sibling call edges, which crashes reg-stack. */
998 if (e
->flags
& EDGE_EH
)
999 changed
= bitmap_ior_and_compl_into (op1
, op2
, regs_invalidated_by_call_regset
);
1001 changed
= bitmap_ior_into (op1
, op2
);
1003 changed
|= bitmap_ior_into (op1
, &df
->hardware_regs_used
);
1008 /* Transfer function. */
1011 df_lr_transfer_function (int bb_index
)
1013 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
1014 bitmap in
= &bb_info
->in
;
1015 bitmap out
= &bb_info
->out
;
1016 bitmap use
= &bb_info
->use
;
1017 bitmap def
= &bb_info
->def
;
1019 return bitmap_ior_and_compl (in
, use
, out
, def
);
1023 /* Run the fast dce as a side effect of building LR. */
1026 df_lr_finalize (bitmap all_blocks
)
1028 df_lr
->solutions_dirty
= false;
1029 if (df
->changeable_flags
& DF_LR_RUN_DCE
)
1033 /* If dce deletes some instructions, we need to recompute the lr
1034 solution before proceeding further. The problem is that fast
1035 dce is a pessimestic dataflow algorithm. In the case where
1036 it deletes a statement S inside of a loop, the uses inside of
1037 S may not be deleted from the dataflow solution because they
1038 were carried around the loop. While it is conservatively
1039 correct to leave these extra bits, the standards of df
1040 require that we maintain the best possible (least fixed
1041 point) solution. The only way to do that is to redo the
1042 iteration from the beginning. See PR35805 for an
1044 if (df_lr
->solutions_dirty
)
1046 df_clear_flags (DF_LR_RUN_DCE
);
1047 df_lr_alloc (all_blocks
);
1048 df_lr_local_compute (all_blocks
);
1049 df_worklist_dataflow (df_lr
, all_blocks
, df
->postorder
, df
->n_blocks
);
1050 df_lr_finalize (all_blocks
);
1051 df_set_flags (DF_LR_RUN_DCE
);
1057 /* Free all storage associated with the problem. */
1062 struct df_lr_problem_data
*problem_data
1063 = (struct df_lr_problem_data
*) df_lr
->problem_data
;
1064 if (df_lr
->block_info
)
1067 df_lr
->block_info_size
= 0;
1068 free (df_lr
->block_info
);
1069 df_lr
->block_info
= NULL
;
1070 bitmap_obstack_release (&problem_data
->lr_bitmaps
);
1071 free (df_lr
->problem_data
);
1072 df_lr
->problem_data
= NULL
;
1075 BITMAP_FREE (df_lr
->out_of_date_transfer_functions
);
1080 /* Debugging info at top of bb. */
1083 df_lr_top_dump (basic_block bb
, FILE *file
)
1085 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1086 struct df_lr_problem_data
*problem_data
;
1090 fprintf (file
, ";; lr in \t");
1091 df_print_regset (file
, &bb_info
->in
);
1092 if (df_lr
->problem_data
)
1094 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1095 if (problem_data
->in
)
1097 fprintf (file
, ";; old in \t");
1098 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1101 fprintf (file
, ";; lr use \t");
1102 df_print_regset (file
, &bb_info
->use
);
1103 fprintf (file
, ";; lr def \t");
1104 df_print_regset (file
, &bb_info
->def
);
1108 /* Debugging info at bottom of bb. */
1111 df_lr_bottom_dump (basic_block bb
, FILE *file
)
1113 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1114 struct df_lr_problem_data
*problem_data
;
1118 fprintf (file
, ";; lr out \t");
1119 df_print_regset (file
, &bb_info
->out
);
1120 if (df_lr
->problem_data
)
1122 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1123 if (problem_data
->out
)
1125 fprintf (file
, ";; old out \t");
1126 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1132 /* Build the datastructure to verify that the solution to the dataflow
1133 equations is not dirty. */
1136 df_lr_verify_solution_start (void)
1139 struct df_lr_problem_data
*problem_data
;
1140 if (df_lr
->solutions_dirty
)
1143 /* Set it true so that the solution is recomputed. */
1144 df_lr
->solutions_dirty
= true;
1146 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1147 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1148 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1150 FOR_ALL_BB_FN (bb
, cfun
)
1152 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->lr_bitmaps
);
1153 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->lr_bitmaps
);
1154 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
));
1155 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
));
1160 /* Compare the saved datastructure and the new solution to the dataflow
1164 df_lr_verify_solution_end (void)
1166 struct df_lr_problem_data
*problem_data
;
1169 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1171 if (!problem_data
->out
)
1174 if (df_lr
->solutions_dirty
)
1175 /* Do not check if the solution is still dirty. See the comment
1176 in df_lr_finalize for details. */
1177 df_lr
->solutions_dirty
= false;
1179 FOR_ALL_BB_FN (bb
, cfun
)
1181 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
)))
1182 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
))))
1184 /*df_dump (stderr);*/
1189 /* Cannot delete them immediately because you may want to dump them
1190 if the comparison fails. */
1191 FOR_ALL_BB_FN (bb
, cfun
)
1193 bitmap_clear (&problem_data
->in
[bb
->index
]);
1194 bitmap_clear (&problem_data
->out
[bb
->index
]);
1197 free (problem_data
->in
);
1198 free (problem_data
->out
);
1199 problem_data
->in
= NULL
;
1200 problem_data
->out
= NULL
;
1204 /* All of the information associated with every instance of the problem. */
1206 static struct df_problem problem_LR
=
1208 DF_LR
, /* Problem id. */
1209 DF_BACKWARD
, /* Direction. */
1210 df_lr_alloc
, /* Allocate the problem specific data. */
1211 df_lr_reset
, /* Reset global information. */
1212 df_lr_free_bb_info
, /* Free basic block info. */
1213 df_lr_local_compute
, /* Local compute function. */
1214 df_lr_init
, /* Init the solution specific data. */
1215 df_worklist_dataflow
, /* Worklist solver. */
1216 df_lr_confluence_0
, /* Confluence operator 0. */
1217 df_lr_confluence_n
, /* Confluence operator n. */
1218 df_lr_transfer_function
, /* Transfer function. */
1219 df_lr_finalize
, /* Finalize function. */
1220 df_lr_free
, /* Free all of the problem information. */
1221 NULL
, /* Remove this problem from the stack of dataflow problems. */
1222 NULL
, /* Debugging. */
1223 df_lr_top_dump
, /* Debugging start block. */
1224 df_lr_bottom_dump
, /* Debugging end block. */
1225 NULL
, /* Debugging start insn. */
1226 NULL
, /* Debugging end insn. */
1227 df_lr_verify_solution_start
,/* Incremental solution verify start. */
1228 df_lr_verify_solution_end
, /* Incremental solution verify end. */
1229 NULL
, /* Dependent problem. */
1230 sizeof (struct df_lr_bb_info
),/* Size of entry of block_info array. */
1231 TV_DF_LR
, /* Timing variable. */
1232 false /* Reset blocks on dropping out of blocks_to_analyze. */
1236 /* Create a new DATAFLOW instance and add it to an existing instance
1237 of DF. The returned structure is what is used to get at the
1241 df_lr_add_problem (void)
1243 df_add_problem (&problem_LR
);
1244 /* These will be initialized when df_scan_blocks processes each
1246 df_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1250 /* Verify that all of the lr related info is consistent and
1254 df_lr_verify_transfer_functions (void)
1257 bitmap_head saved_def
;
1258 bitmap_head saved_use
;
1259 bitmap_head all_blocks
;
1264 bitmap_initialize (&saved_def
, &bitmap_default_obstack
);
1265 bitmap_initialize (&saved_use
, &bitmap_default_obstack
);
1266 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1268 FOR_ALL_BB_FN (bb
, cfun
)
1270 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1271 bitmap_set_bit (&all_blocks
, bb
->index
);
1275 /* Make a copy of the transfer functions and then compute
1276 new ones to see if the transfer functions have
1278 if (!bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1281 bitmap_copy (&saved_def
, &bb_info
->def
);
1282 bitmap_copy (&saved_use
, &bb_info
->use
);
1283 bitmap_clear (&bb_info
->def
);
1284 bitmap_clear (&bb_info
->use
);
1286 df_lr_bb_local_compute (bb
->index
);
1287 gcc_assert (bitmap_equal_p (&saved_def
, &bb_info
->def
));
1288 gcc_assert (bitmap_equal_p (&saved_use
, &bb_info
->use
));
1293 /* If we do not have basic block info, the block must be in
1294 the list of dirty blocks or else some one has added a
1295 block behind our backs. */
1296 gcc_assert (bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1299 /* Make sure no one created a block without following
1301 gcc_assert (df_scan_get_bb_info (bb
->index
));
1304 /* Make sure there are no dirty bits in blocks that have been deleted. */
1305 gcc_assert (!bitmap_intersect_compl_p (df_lr
->out_of_date_transfer_functions
,
1308 bitmap_clear (&saved_def
);
1309 bitmap_clear (&saved_use
);
1310 bitmap_clear (&all_blocks
);
1315 /*----------------------------------------------------------------------------
1316 LIVE AND MUST-INITIALIZED REGISTERS.
1318 This problem first computes the IN and OUT bitvectors for the
1319 must-initialized registers problems, which is a forward problem.
1320 It gives the set of registers for which we MUST have an available
1321 definition on any path from the entry block to the entry/exit of
1322 a basic block. Sets generate a definition, while clobbers kill
1325 In and out bitvectors are built for each basic block and are indexed by
1326 regnum (see df.h for details). In and out bitvectors in struct
1327 df_live_bb_info actually refers to the must-initialized problem;
1329 Then, the in and out sets for the LIVE problem itself are computed.
1330 These are the logical AND of the IN and OUT sets from the LR problem
1331 and the must-initialized problem.
1332 ----------------------------------------------------------------------------*/
1334 /* Private data used to verify the solution for this problem. */
1335 struct df_live_problem_data
1339 /* An obstack for the bitmaps we need for this problem. */
1340 bitmap_obstack live_bitmaps
;
1343 /* Scratch var used by transfer functions. This is used to implement
1344 an optimization to reduce the amount of space used to compute the
1345 combined lr and live analysis. */
1346 static bitmap_head df_live_scratch
;
1349 /* Free basic block info. */
1352 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
1355 struct df_live_bb_info
*bb_info
= (struct df_live_bb_info
*) vbb_info
;
1358 bitmap_clear (&bb_info
->gen
);
1359 bitmap_clear (&bb_info
->kill
);
1360 bitmap_clear (&bb_info
->in
);
1361 bitmap_clear (&bb_info
->out
);
1366 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1367 not touched unless the block is new. */
1370 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
1372 unsigned int bb_index
;
1374 struct df_live_problem_data
*problem_data
;
1376 if (df_live
->problem_data
)
1377 problem_data
= (struct df_live_problem_data
*) df_live
->problem_data
;
1380 problem_data
= XNEW (struct df_live_problem_data
);
1381 df_live
->problem_data
= problem_data
;
1383 problem_data
->out
= NULL
;
1384 problem_data
->in
= NULL
;
1385 bitmap_obstack_initialize (&problem_data
->live_bitmaps
);
1386 bitmap_initialize (&df_live_scratch
, &problem_data
->live_bitmaps
);
1389 df_grow_bb_info (df_live
);
1391 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1393 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1395 /* When bitmaps are already initialized, just clear them. */
1396 if (bb_info
->kill
.obstack
)
1398 bitmap_clear (&bb_info
->kill
);
1399 bitmap_clear (&bb_info
->gen
);
1403 bitmap_initialize (&bb_info
->kill
, &problem_data
->live_bitmaps
);
1404 bitmap_initialize (&bb_info
->gen
, &problem_data
->live_bitmaps
);
1405 bitmap_initialize (&bb_info
->in
, &problem_data
->live_bitmaps
);
1406 bitmap_initialize (&bb_info
->out
, &problem_data
->live_bitmaps
);
1409 df_live
->optional_p
= (optimize
<= 1);
1413 /* Reset the global solution for recalculation. */
1416 df_live_reset (bitmap all_blocks
)
1418 unsigned int bb_index
;
1421 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1423 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1424 gcc_assert (bb_info
);
1425 bitmap_clear (&bb_info
->in
);
1426 bitmap_clear (&bb_info
->out
);
1431 /* Compute local uninitialized register info for basic block BB. */
1434 df_live_bb_local_compute (unsigned int bb_index
)
1436 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1437 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1442 FOR_BB_INSNS (bb
, insn
)
1444 unsigned int uid
= INSN_UID (insn
);
1445 struct df_insn_info
*insn_info
= DF_INSN_UID_GET (uid
);
1447 /* Inserting labels does not always trigger the incremental
1451 gcc_assert (!INSN_P (insn
));
1452 insn_info
= df_insn_create_insn_record (insn
);
1455 DF_INSN_INFO_LUID (insn_info
) = luid
;
1460 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1462 unsigned int regno
= DF_REF_REGNO (def
);
1464 if (DF_REF_FLAGS_IS_SET (def
,
1465 DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
1466 /* All partial or conditional def
1467 seen are included in the gen set. */
1468 bitmap_set_bit (&bb_info
->gen
, regno
);
1469 else if (DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
))
1470 /* Only must clobbers for the entire reg destroy the
1472 bitmap_set_bit (&bb_info
->kill
, regno
);
1473 else if (! DF_REF_FLAGS_IS_SET (def
, DF_REF_MAY_CLOBBER
))
1474 bitmap_set_bit (&bb_info
->gen
, regno
);
1478 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1479 bitmap_set_bit (&bb_info
->gen
, DF_REF_REGNO (def
));
1483 /* Compute local uninitialized register info. */
1486 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
1488 unsigned int bb_index
;
1491 df_grow_insn_info ();
1493 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
,
1496 df_live_bb_local_compute (bb_index
);
1499 bitmap_clear (df_live
->out_of_date_transfer_functions
);
1503 /* Initialize the solution vectors. */
1506 df_live_init (bitmap all_blocks
)
1508 unsigned int bb_index
;
1511 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1513 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1514 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1516 /* No register may reach a location where it is not used. Thus
1517 we trim the rr result to the places where it is used. */
1518 bitmap_and (&bb_info
->out
, &bb_info
->gen
, &bb_lr_info
->out
);
1519 bitmap_clear (&bb_info
->in
);
1523 /* Forward confluence function that ignores fake edges. */
1526 df_live_confluence_n (edge e
)
1528 bitmap op1
= &df_live_get_bb_info (e
->dest
->index
)->in
;
1529 bitmap op2
= &df_live_get_bb_info (e
->src
->index
)->out
;
1531 if (e
->flags
& EDGE_FAKE
)
1534 return bitmap_ior_into (op1
, op2
);
1538 /* Transfer function for the forwards must-initialized problem. */
1541 df_live_transfer_function (int bb_index
)
1543 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1544 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1545 bitmap in
= &bb_info
->in
;
1546 bitmap out
= &bb_info
->out
;
1547 bitmap gen
= &bb_info
->gen
;
1548 bitmap kill
= &bb_info
->kill
;
1550 /* We need to use a scratch set here so that the value returned from this
1551 function invocation properly reflects whether the sets changed in a
1552 significant way; i.e. not just because the lr set was anded in. */
1553 bitmap_and (&df_live_scratch
, gen
, &bb_lr_info
->out
);
1554 /* No register may reach a location where it is not used. Thus
1555 we trim the rr result to the places where it is used. */
1556 bitmap_and_into (in
, &bb_lr_info
->in
);
1558 return bitmap_ior_and_compl (out
, &df_live_scratch
, in
, kill
);
1562 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1565 df_live_finalize (bitmap all_blocks
)
1568 if (df_live
->solutions_dirty
)
1571 unsigned int bb_index
;
1573 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1575 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1576 struct df_live_bb_info
*bb_live_info
= df_live_get_bb_info (bb_index
);
1578 /* No register may reach a location where it is not used. Thus
1579 we trim the rr result to the places where it is used. */
1580 bitmap_and_into (&bb_live_info
->in
, &bb_lr_info
->in
);
1581 bitmap_and_into (&bb_live_info
->out
, &bb_lr_info
->out
);
1584 df_live
->solutions_dirty
= false;
1589 /* Free all storage associated with the problem. */
1594 struct df_live_problem_data
*problem_data
1595 = (struct df_live_problem_data
*) df_live
->problem_data
;
1596 if (df_live
->block_info
)
1598 df_live
->block_info_size
= 0;
1599 free (df_live
->block_info
);
1600 df_live
->block_info
= NULL
;
1601 bitmap_clear (&df_live_scratch
);
1602 bitmap_obstack_release (&problem_data
->live_bitmaps
);
1603 free (problem_data
);
1604 df_live
->problem_data
= NULL
;
1606 BITMAP_FREE (df_live
->out_of_date_transfer_functions
);
1611 /* Debugging info at top of bb. */
1614 df_live_top_dump (basic_block bb
, FILE *file
)
1616 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1617 struct df_live_problem_data
*problem_data
;
1622 fprintf (file
, ";; live in \t");
1623 df_print_regset (file
, &bb_info
->in
);
1624 if (df_live
->problem_data
)
1626 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1627 if (problem_data
->in
)
1629 fprintf (file
, ";; old in \t");
1630 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1633 fprintf (file
, ";; live gen \t");
1634 df_print_regset (file
, &bb_info
->gen
);
1635 fprintf (file
, ";; live kill\t");
1636 df_print_regset (file
, &bb_info
->kill
);
1640 /* Debugging info at bottom of bb. */
1643 df_live_bottom_dump (basic_block bb
, FILE *file
)
1645 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1646 struct df_live_problem_data
*problem_data
;
1651 fprintf (file
, ";; live out \t");
1652 df_print_regset (file
, &bb_info
->out
);
1653 if (df_live
->problem_data
)
1655 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1656 if (problem_data
->out
)
1658 fprintf (file
, ";; old out \t");
1659 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1665 /* Build the datastructure to verify that the solution to the dataflow
1666 equations is not dirty. */
1669 df_live_verify_solution_start (void)
1672 struct df_live_problem_data
*problem_data
;
1673 if (df_live
->solutions_dirty
)
1676 /* Set it true so that the solution is recomputed. */
1677 df_live
->solutions_dirty
= true;
1679 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1680 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1681 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1683 FOR_ALL_BB_FN (bb
, cfun
)
1685 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->live_bitmaps
);
1686 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->live_bitmaps
);
1687 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
));
1688 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
));
1693 /* Compare the saved datastructure and the new solution to the dataflow
1697 df_live_verify_solution_end (void)
1699 struct df_live_problem_data
*problem_data
;
1702 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1703 if (!problem_data
->out
)
1706 FOR_ALL_BB_FN (bb
, cfun
)
1708 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
)))
1709 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
))))
1711 /*df_dump (stderr);*/
1716 /* Cannot delete them immediately because you may want to dump them
1717 if the comparison fails. */
1718 FOR_ALL_BB_FN (bb
, cfun
)
1720 bitmap_clear (&problem_data
->in
[bb
->index
]);
1721 bitmap_clear (&problem_data
->out
[bb
->index
]);
1724 free (problem_data
->in
);
1725 free (problem_data
->out
);
1726 free (problem_data
);
1727 df_live
->problem_data
= NULL
;
1731 /* All of the information associated with every instance of the problem. */
1733 static struct df_problem problem_LIVE
=
1735 DF_LIVE
, /* Problem id. */
1736 DF_FORWARD
, /* Direction. */
1737 df_live_alloc
, /* Allocate the problem specific data. */
1738 df_live_reset
, /* Reset global information. */
1739 df_live_free_bb_info
, /* Free basic block info. */
1740 df_live_local_compute
, /* Local compute function. */
1741 df_live_init
, /* Init the solution specific data. */
1742 df_worklist_dataflow
, /* Worklist solver. */
1743 NULL
, /* Confluence operator 0. */
1744 df_live_confluence_n
, /* Confluence operator n. */
1745 df_live_transfer_function
, /* Transfer function. */
1746 df_live_finalize
, /* Finalize function. */
1747 df_live_free
, /* Free all of the problem information. */
1748 df_live_free
, /* Remove this problem from the stack of dataflow problems. */
1749 NULL
, /* Debugging. */
1750 df_live_top_dump
, /* Debugging start block. */
1751 df_live_bottom_dump
, /* Debugging end block. */
1752 NULL
, /* Debugging start insn. */
1753 NULL
, /* Debugging end insn. */
1754 df_live_verify_solution_start
,/* Incremental solution verify start. */
1755 df_live_verify_solution_end
, /* Incremental solution verify end. */
1756 &problem_LR
, /* Dependent problem. */
1757 sizeof (struct df_live_bb_info
),/* Size of entry of block_info array. */
1758 TV_DF_LIVE
, /* Timing variable. */
1759 false /* Reset blocks on dropping out of blocks_to_analyze. */
1763 /* Create a new DATAFLOW instance and add it to an existing instance
1764 of DF. The returned structure is what is used to get at the
1768 df_live_add_problem (void)
1770 df_add_problem (&problem_LIVE
);
1771 /* These will be initialized when df_scan_blocks processes each
1773 df_live
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1777 /* Set all of the blocks as dirty. This needs to be done if this
1778 problem is added after all of the insns have been scanned. */
1781 df_live_set_all_dirty (void)
1784 FOR_ALL_BB_FN (bb
, cfun
)
1785 bitmap_set_bit (df_live
->out_of_date_transfer_functions
,
1790 /* Verify that all of the lr related info is consistent and
1794 df_live_verify_transfer_functions (void)
1797 bitmap_head saved_gen
;
1798 bitmap_head saved_kill
;
1799 bitmap_head all_blocks
;
1804 bitmap_initialize (&saved_gen
, &bitmap_default_obstack
);
1805 bitmap_initialize (&saved_kill
, &bitmap_default_obstack
);
1806 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1808 df_grow_insn_info ();
1810 FOR_ALL_BB_FN (bb
, cfun
)
1812 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1813 bitmap_set_bit (&all_blocks
, bb
->index
);
1817 /* Make a copy of the transfer functions and then compute
1818 new ones to see if the transfer functions have
1820 if (!bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1823 bitmap_copy (&saved_gen
, &bb_info
->gen
);
1824 bitmap_copy (&saved_kill
, &bb_info
->kill
);
1825 bitmap_clear (&bb_info
->gen
);
1826 bitmap_clear (&bb_info
->kill
);
1828 df_live_bb_local_compute (bb
->index
);
1829 gcc_assert (bitmap_equal_p (&saved_gen
, &bb_info
->gen
));
1830 gcc_assert (bitmap_equal_p (&saved_kill
, &bb_info
->kill
));
1835 /* If we do not have basic block info, the block must be in
1836 the list of dirty blocks or else some one has added a
1837 block behind our backs. */
1838 gcc_assert (bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1841 /* Make sure no one created a block without following
1843 gcc_assert (df_scan_get_bb_info (bb
->index
));
1846 /* Make sure there are no dirty bits in blocks that have been deleted. */
1847 gcc_assert (!bitmap_intersect_compl_p (df_live
->out_of_date_transfer_functions
,
1849 bitmap_clear (&saved_gen
);
1850 bitmap_clear (&saved_kill
);
1851 bitmap_clear (&all_blocks
);
1854 /*----------------------------------------------------------------------------
1855 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1857 Link either the defs to the uses and / or the uses to the defs.
1859 These problems are set up like the other dataflow problems so that
1860 they nicely fit into the framework. They are much simpler and only
1861 involve a single traversal of instructions and an examination of
1862 the reaching defs information (the dependent problem).
1863 ----------------------------------------------------------------------------*/
1865 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1867 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1870 df_chain_create (df_ref src
, df_ref dst
)
1872 struct df_link
*head
= DF_REF_CHAIN (src
);
1873 struct df_link
*link
= (struct df_link
*) pool_alloc (df_chain
->block_pool
);
1875 DF_REF_CHAIN (src
) = link
;
1882 /* Delete any du or ud chains that start at REF and point to
1885 df_chain_unlink_1 (df_ref ref
, df_ref target
)
1887 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1888 struct df_link
*prev
= NULL
;
1892 if (chain
->ref
== target
)
1895 prev
->next
= chain
->next
;
1897 DF_REF_CHAIN (ref
) = chain
->next
;
1898 pool_free (df_chain
->block_pool
, chain
);
1902 chain
= chain
->next
;
1907 /* Delete a du or ud chain that leave or point to REF. */
1910 df_chain_unlink (df_ref ref
)
1912 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1915 struct df_link
*next
= chain
->next
;
1916 /* Delete the other side if it exists. */
1917 df_chain_unlink_1 (chain
->ref
, ref
);
1918 pool_free (df_chain
->block_pool
, chain
);
1921 DF_REF_CHAIN (ref
) = NULL
;
1925 /* Copy the du or ud chain starting at FROM_REF and attach it to
1929 df_chain_copy (df_ref to_ref
,
1930 struct df_link
*from_ref
)
1934 df_chain_create (to_ref
, from_ref
->ref
);
1935 from_ref
= from_ref
->next
;
1940 /* Remove this problem from the stack of dataflow problems. */
1943 df_chain_remove_problem (void)
1946 unsigned int bb_index
;
1948 /* Wholesale destruction of the old chains. */
1949 if (df_chain
->block_pool
)
1950 free_alloc_pool (df_chain
->block_pool
);
1952 EXECUTE_IF_SET_IN_BITMAP (df_chain
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1956 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1958 if (df_chain_problem_p (DF_DU_CHAIN
))
1959 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1960 DF_REF_CHAIN (def
) = NULL
;
1961 if (df_chain_problem_p (DF_UD_CHAIN
))
1962 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1963 DF_REF_CHAIN (use
) = NULL
;
1965 FOR_BB_INSNS (bb
, insn
)
1968 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1969 if (df_chain_problem_p (DF_DU_CHAIN
))
1970 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1971 DF_REF_CHAIN (def
) = NULL
;
1972 if (df_chain_problem_p (DF_UD_CHAIN
))
1974 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1975 DF_REF_CHAIN (use
) = NULL
;
1976 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1977 DF_REF_CHAIN (use
) = NULL
;
1982 bitmap_clear (df_chain
->out_of_date_transfer_functions
);
1983 df_chain
->block_pool
= NULL
;
1987 /* Remove the chain problem completely. */
1990 df_chain_fully_remove_problem (void)
1992 df_chain_remove_problem ();
1993 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
1998 /* Create def-use or use-def chains. */
2001 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2003 df_chain_remove_problem ();
2004 df_chain
->block_pool
= create_alloc_pool ("df_chain_block pool",
2005 sizeof (struct df_link
), 50);
2006 df_chain
->optional_p
= true;
2010 /* Reset all of the chains when the set of basic blocks changes. */
2013 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED
)
2015 df_chain_remove_problem ();
2019 /* Create the chains for a list of USEs. */
2022 df_chain_create_bb_process_use (bitmap local_rd
,
2027 unsigned int def_index
;
2029 for (; use
; use
= DF_REF_NEXT_LOC (use
))
2031 unsigned int uregno
= DF_REF_REGNO (use
);
2032 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2033 || (uregno
>= FIRST_PSEUDO_REGISTER
))
2035 /* Do not want to go through this for an uninitialized var. */
2036 int count
= DF_DEFS_COUNT (uregno
);
2039 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2041 unsigned int first_index
= DF_DEFS_BEGIN (uregno
);
2042 unsigned int last_index
= first_index
+ count
- 1;
2044 EXECUTE_IF_SET_IN_BITMAP (local_rd
, first_index
, def_index
, bi
)
2047 if (def_index
> last_index
)
2050 def
= DF_DEFS_GET (def_index
);
2051 if (df_chain_problem_p (DF_DU_CHAIN
))
2052 df_chain_create (def
, use
);
2053 if (df_chain_problem_p (DF_UD_CHAIN
))
2054 df_chain_create (use
, def
);
2063 /* Create chains from reaching defs bitmaps for basic block BB. */
2066 df_chain_create_bb (unsigned int bb_index
)
2068 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2069 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
2073 bitmap_initialize (&cpy
, &bitmap_default_obstack
);
2074 bitmap_copy (&cpy
, &bb_info
->in
);
2075 bitmap_set_bit (df_chain
->out_of_date_transfer_functions
, bb_index
);
2077 /* Since we are going forwards, process the artificial uses first
2078 then the artificial defs second. */
2081 /* Create the chains for the artificial uses from the EH_USES at the
2082 beginning of the block. */
2084 /* Artificials are only hard regs. */
2085 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2086 df_chain_create_bb_process_use (&cpy
,
2087 df_get_artificial_uses (bb
->index
),
2091 df_rd_simulate_artificial_defs_at_top (bb
, &cpy
);
2093 /* Process the regular instructions next. */
2094 FOR_BB_INSNS (bb
, insn
)
2097 unsigned int uid
= INSN_UID (insn
);
2099 /* First scan the uses and link them up with the defs that remain
2100 in the cpy vector. */
2101 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_USES (uid
), 0);
2102 if (df
->changeable_flags
& DF_EQ_NOTES
)
2103 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_EQ_USES (uid
), 0);
2105 /* Since we are going forwards, process the defs second. */
2106 df_rd_simulate_one_insn (bb
, insn
, &cpy
);
2109 /* Create the chains for the artificial uses of the hard registers
2110 at the end of the block. */
2111 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2112 df_chain_create_bb_process_use (&cpy
,
2113 df_get_artificial_uses (bb
->index
),
2116 bitmap_clear (&cpy
);
2119 /* Create def-use chains from reaching use bitmaps for basic blocks
2123 df_chain_finalize (bitmap all_blocks
)
2125 unsigned int bb_index
;
2128 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2130 df_chain_create_bb (bb_index
);
2135 /* Free all storage associated with the problem. */
2138 df_chain_free (void)
2140 free_alloc_pool (df_chain
->block_pool
);
2141 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
2146 /* Debugging info. */
2149 df_chain_bb_dump (basic_block bb
, FILE *file
, bool top
)
2151 /* Artificials are only hard regs. */
2152 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
2154 if (df_chain_problem_p (DF_UD_CHAIN
))
2159 ";; UD chains for artificial uses at %s\n",
2160 top
? "top" : "bottom");
2161 FOR_EACH_ARTIFICIAL_USE (use
, bb
->index
)
2162 if ((top
&& (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2163 || (!top
&& !(DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)))
2165 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2166 df_chain_dump (DF_REF_CHAIN (use
), file
);
2167 fprintf (file
, "\n");
2170 if (df_chain_problem_p (DF_DU_CHAIN
))
2175 ";; DU chains for artificial defs at %s\n",
2176 top
? "top" : "bottom");
2177 FOR_EACH_ARTIFICIAL_DEF (def
, bb
->index
)
2178 if ((top
&& (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
2179 || (!top
&& !(DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)))
2181 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2182 df_chain_dump (DF_REF_CHAIN (def
), file
);
2183 fprintf (file
, "\n");
2189 df_chain_top_dump (basic_block bb
, FILE *file
)
2191 df_chain_bb_dump (bb
, file
, /*top=*/true);
2195 df_chain_bottom_dump (basic_block bb
, FILE *file
)
2197 df_chain_bb_dump (bb
, file
, /*top=*/false);
2201 df_chain_insn_top_dump (const_rtx insn
, FILE *file
)
2203 if (df_chain_problem_p (DF_UD_CHAIN
) && INSN_P (insn
))
2205 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2208 fprintf (file
, ";; UD chains for insn luid %d uid %d\n",
2209 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2210 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2211 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2212 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2214 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2215 if (DF_REF_FLAGS (use
) & DF_REF_READ_WRITE
)
2216 fprintf (file
, "read/write ");
2217 df_chain_dump (DF_REF_CHAIN (use
), file
);
2218 fprintf (file
, "\n");
2220 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
2221 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2222 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2224 fprintf (file
, ";; eq_note reg %d ", DF_REF_REGNO (use
));
2225 df_chain_dump (DF_REF_CHAIN (use
), file
);
2226 fprintf (file
, "\n");
2232 df_chain_insn_bottom_dump (const_rtx insn
, FILE *file
)
2234 if (df_chain_problem_p (DF_DU_CHAIN
) && INSN_P (insn
))
2236 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2238 fprintf (file
, ";; DU chains for insn luid %d uid %d\n",
2239 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2240 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2241 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def
))
2242 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2244 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2245 if (DF_REF_FLAGS (def
) & DF_REF_READ_WRITE
)
2246 fprintf (file
, "read/write ");
2247 df_chain_dump (DF_REF_CHAIN (def
), file
);
2248 fprintf (file
, "\n");
2250 fprintf (file
, "\n");
2254 static struct df_problem problem_CHAIN
=
2256 DF_CHAIN
, /* Problem id. */
2257 DF_NONE
, /* Direction. */
2258 df_chain_alloc
, /* Allocate the problem specific data. */
2259 df_chain_reset
, /* Reset global information. */
2260 NULL
, /* Free basic block info. */
2261 NULL
, /* Local compute function. */
2262 NULL
, /* Init the solution specific data. */
2263 NULL
, /* Iterative solver. */
2264 NULL
, /* Confluence operator 0. */
2265 NULL
, /* Confluence operator n. */
2266 NULL
, /* Transfer function. */
2267 df_chain_finalize
, /* Finalize function. */
2268 df_chain_free
, /* Free all of the problem information. */
2269 df_chain_fully_remove_problem
,/* Remove this problem from the stack of dataflow problems. */
2270 NULL
, /* Debugging. */
2271 df_chain_top_dump
, /* Debugging start block. */
2272 df_chain_bottom_dump
, /* Debugging end block. */
2273 df_chain_insn_top_dump
, /* Debugging start insn. */
2274 df_chain_insn_bottom_dump
, /* Debugging end insn. */
2275 NULL
, /* Incremental solution verify start. */
2276 NULL
, /* Incremental solution verify end. */
2277 &problem_RD
, /* Dependent problem. */
2278 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
2279 TV_DF_CHAIN
, /* Timing variable. */
2280 false /* Reset blocks on dropping out of blocks_to_analyze. */
2284 /* Create a new DATAFLOW instance and add it to an existing instance
2285 of DF. The returned structure is what is used to get at the
2289 df_chain_add_problem (unsigned int chain_flags
)
2291 df_add_problem (&problem_CHAIN
);
2292 df_chain
->local_flags
= chain_flags
;
2293 df_chain
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2296 #undef df_chain_problem_p
2299 /*----------------------------------------------------------------------------
2300 WORD LEVEL LIVE REGISTERS
2302 Find the locations in the function where any use of a pseudo can
2303 reach in the backwards direction. In and out bitvectors are built
2304 for each basic block. We only track pseudo registers that have a
2305 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2306 contain two bits corresponding to each of the subwords.
2308 ----------------------------------------------------------------------------*/
2310 /* Private data used to verify the solution for this problem. */
2311 struct df_word_lr_problem_data
2313 /* An obstack for the bitmaps we need for this problem. */
2314 bitmap_obstack word_lr_bitmaps
;
2318 /* Free basic block info. */
2321 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
2324 struct df_word_lr_bb_info
*bb_info
= (struct df_word_lr_bb_info
*) vbb_info
;
2327 bitmap_clear (&bb_info
->use
);
2328 bitmap_clear (&bb_info
->def
);
2329 bitmap_clear (&bb_info
->in
);
2330 bitmap_clear (&bb_info
->out
);
2335 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2336 not touched unless the block is new. */
2339 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2341 unsigned int bb_index
;
2344 struct df_word_lr_problem_data
*problem_data
2345 = XNEW (struct df_word_lr_problem_data
);
2347 df_word_lr
->problem_data
= problem_data
;
2349 df_grow_bb_info (df_word_lr
);
2351 /* Create the mapping from regnos to slots. This does not change
2352 unless the problem is destroyed and recreated. In particular, if
2353 we end up deleting the only insn that used a subreg, we do not
2354 want to redo the mapping because this would invalidate everything
2357 bitmap_obstack_initialize (&problem_data
->word_lr_bitmaps
);
2359 FOR_EACH_BB_FN (bb
, cfun
)
2360 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, bb
->index
);
2362 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, ENTRY_BLOCK
);
2363 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, EXIT_BLOCK
);
2365 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2367 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2369 /* When bitmaps are already initialized, just clear them. */
2370 if (bb_info
->use
.obstack
)
2372 bitmap_clear (&bb_info
->def
);
2373 bitmap_clear (&bb_info
->use
);
2377 bitmap_initialize (&bb_info
->use
, &problem_data
->word_lr_bitmaps
);
2378 bitmap_initialize (&bb_info
->def
, &problem_data
->word_lr_bitmaps
);
2379 bitmap_initialize (&bb_info
->in
, &problem_data
->word_lr_bitmaps
);
2380 bitmap_initialize (&bb_info
->out
, &problem_data
->word_lr_bitmaps
);
2384 df_word_lr
->optional_p
= true;
2388 /* Reset the global solution for recalculation. */
2391 df_word_lr_reset (bitmap all_blocks
)
2393 unsigned int bb_index
;
2396 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2398 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2399 gcc_assert (bb_info
);
2400 bitmap_clear (&bb_info
->in
);
2401 bitmap_clear (&bb_info
->out
);
2405 /* Examine REF, and if it is for a reg we're interested in, set or
2406 clear the bits corresponding to its subwords from the bitmap
2407 according to IS_SET. LIVE is the bitmap we should update. We do
2408 not track hard regs or pseudos of any size other than 2 *
2410 We return true if we changed the bitmap, or if we encountered a register
2411 we're not tracking. */
2414 df_word_lr_mark_ref (df_ref ref
, bool is_set
, regset live
)
2416 rtx orig_reg
= DF_REF_REG (ref
);
2418 enum machine_mode reg_mode
;
2420 /* Left at -1 for whole accesses. */
2421 int which_subword
= -1;
2422 bool changed
= false;
2424 if (GET_CODE (reg
) == SUBREG
)
2425 reg
= SUBREG_REG (orig_reg
);
2426 regno
= REGNO (reg
);
2427 reg_mode
= GET_MODE (reg
);
2428 if (regno
< FIRST_PSEUDO_REGISTER
2429 || GET_MODE_SIZE (reg_mode
) != 2 * UNITS_PER_WORD
)
2432 if (GET_CODE (orig_reg
) == SUBREG
2433 && df_read_modify_subreg_p (orig_reg
))
2435 gcc_assert (DF_REF_FLAGS_IS_SET (ref
, DF_REF_PARTIAL
));
2436 if (subreg_lowpart_p (orig_reg
))
2443 if (which_subword
!= 1)
2444 changed
|= bitmap_set_bit (live
, regno
* 2);
2445 if (which_subword
!= 0)
2446 changed
|= bitmap_set_bit (live
, regno
* 2 + 1);
2450 if (which_subword
!= 1)
2451 changed
|= bitmap_clear_bit (live
, regno
* 2);
2452 if (which_subword
!= 0)
2453 changed
|= bitmap_clear_bit (live
, regno
* 2 + 1);
2458 /* Compute local live register info for basic block BB. */
2461 df_word_lr_bb_local_compute (unsigned int bb_index
)
2463 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2464 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2468 /* Ensure that artificial refs don't contain references to pseudos. */
2469 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
2470 gcc_assert (DF_REF_REGNO (def
) < FIRST_PSEUDO_REGISTER
);
2472 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
2473 gcc_assert (DF_REF_REGNO (use
) < FIRST_PSEUDO_REGISTER
);
2475 FOR_BB_INSNS_REVERSE (bb
, insn
)
2477 if (!NONDEBUG_INSN_P (insn
))
2480 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2481 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2482 /* If the def is to only part of the reg, it does
2483 not kill the other defs that reach here. */
2484 if (!(DF_REF_FLAGS (def
) & (DF_REF_CONDITIONAL
)))
2486 df_word_lr_mark_ref (def
, true, &bb_info
->def
);
2487 df_word_lr_mark_ref (def
, false, &bb_info
->use
);
2489 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2490 df_word_lr_mark_ref (use
, true, &bb_info
->use
);
2495 /* Compute local live register info for each basic block within BLOCKS. */
2498 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
2500 unsigned int bb_index
;
2503 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2505 if (bb_index
== EXIT_BLOCK
)
2509 EXECUTE_IF_SET_IN_BITMAP (df
->exit_block_uses
, FIRST_PSEUDO_REGISTER
,
2514 df_word_lr_bb_local_compute (bb_index
);
2517 bitmap_clear (df_word_lr
->out_of_date_transfer_functions
);
2521 /* Initialize the solution vectors. */
2524 df_word_lr_init (bitmap all_blocks
)
2526 unsigned int bb_index
;
2529 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2531 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2532 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
2533 bitmap_clear (&bb_info
->out
);
2538 /* Confluence function that ignores fake edges. */
2541 df_word_lr_confluence_n (edge e
)
2543 bitmap op1
= &df_word_lr_get_bb_info (e
->src
->index
)->out
;
2544 bitmap op2
= &df_word_lr_get_bb_info (e
->dest
->index
)->in
;
2546 return bitmap_ior_into (op1
, op2
);
2550 /* Transfer function. */
2553 df_word_lr_transfer_function (int bb_index
)
2555 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2556 bitmap in
= &bb_info
->in
;
2557 bitmap out
= &bb_info
->out
;
2558 bitmap use
= &bb_info
->use
;
2559 bitmap def
= &bb_info
->def
;
2561 return bitmap_ior_and_compl (in
, use
, out
, def
);
2565 /* Free all storage associated with the problem. */
2568 df_word_lr_free (void)
2570 struct df_word_lr_problem_data
*problem_data
2571 = (struct df_word_lr_problem_data
*)df_word_lr
->problem_data
;
2573 if (df_word_lr
->block_info
)
2575 df_word_lr
->block_info_size
= 0;
2576 free (df_word_lr
->block_info
);
2577 df_word_lr
->block_info
= NULL
;
2580 BITMAP_FREE (df_word_lr
->out_of_date_transfer_functions
);
2581 bitmap_obstack_release (&problem_data
->word_lr_bitmaps
);
2582 free (problem_data
);
2587 /* Debugging info at top of bb. */
2590 df_word_lr_top_dump (basic_block bb
, FILE *file
)
2592 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2596 fprintf (file
, ";; blr in \t");
2597 df_print_word_regset (file
, &bb_info
->in
);
2598 fprintf (file
, ";; blr use \t");
2599 df_print_word_regset (file
, &bb_info
->use
);
2600 fprintf (file
, ";; blr def \t");
2601 df_print_word_regset (file
, &bb_info
->def
);
2605 /* Debugging info at bottom of bb. */
2608 df_word_lr_bottom_dump (basic_block bb
, FILE *file
)
2610 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2614 fprintf (file
, ";; blr out \t");
2615 df_print_word_regset (file
, &bb_info
->out
);
2619 /* All of the information associated with every instance of the problem. */
2621 static struct df_problem problem_WORD_LR
=
2623 DF_WORD_LR
, /* Problem id. */
2624 DF_BACKWARD
, /* Direction. */
2625 df_word_lr_alloc
, /* Allocate the problem specific data. */
2626 df_word_lr_reset
, /* Reset global information. */
2627 df_word_lr_free_bb_info
, /* Free basic block info. */
2628 df_word_lr_local_compute
, /* Local compute function. */
2629 df_word_lr_init
, /* Init the solution specific data. */
2630 df_worklist_dataflow
, /* Worklist solver. */
2631 NULL
, /* Confluence operator 0. */
2632 df_word_lr_confluence_n
, /* Confluence operator n. */
2633 df_word_lr_transfer_function
, /* Transfer function. */
2634 NULL
, /* Finalize function. */
2635 df_word_lr_free
, /* Free all of the problem information. */
2636 df_word_lr_free
, /* Remove this problem from the stack of dataflow problems. */
2637 NULL
, /* Debugging. */
2638 df_word_lr_top_dump
, /* Debugging start block. */
2639 df_word_lr_bottom_dump
, /* Debugging end block. */
2640 NULL
, /* Debugging start insn. */
2641 NULL
, /* Debugging end insn. */
2642 NULL
, /* Incremental solution verify start. */
2643 NULL
, /* Incremental solution verify end. */
2644 NULL
, /* Dependent problem. */
2645 sizeof (struct df_word_lr_bb_info
),/* Size of entry of block_info array. */
2646 TV_DF_WORD_LR
, /* Timing variable. */
2647 false /* Reset blocks on dropping out of blocks_to_analyze. */
2651 /* Create a new DATAFLOW instance and add it to an existing instance
2652 of DF. The returned structure is what is used to get at the
2656 df_word_lr_add_problem (void)
2658 df_add_problem (&problem_WORD_LR
);
2659 /* These will be initialized when df_scan_blocks processes each
2661 df_word_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2665 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2666 any bits, which is used by the caller to determine whether a set is
2667 necessary. We also return true if there are other reasons not to delete
2671 df_word_lr_simulate_defs (rtx insn
, bitmap live
)
2673 bool changed
= false;
2676 FOR_EACH_INSN_DEF (def
, insn
)
2677 if (DF_REF_FLAGS (def
) & DF_REF_CONDITIONAL
)
2680 changed
|= df_word_lr_mark_ref (def
, false, live
);
2685 /* Simulate the effects of the uses of INSN on LIVE. */
2688 df_word_lr_simulate_uses (rtx insn
, bitmap live
)
2692 FOR_EACH_INSN_USE (use
, insn
)
2693 df_word_lr_mark_ref (use
, true, live
);
2696 /*----------------------------------------------------------------------------
2697 This problem computes REG_DEAD and REG_UNUSED notes.
2698 ----------------------------------------------------------------------------*/
2701 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2703 df_note
->optional_p
= true;
2706 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2708 df_print_note (const char *prefix
, rtx insn
, rtx note
)
2712 fprintf (dump_file
, "%s %d ", prefix
, INSN_UID (insn
));
2713 print_rtl (dump_file
, note
);
2714 fprintf (dump_file
, "\n");
2719 /* After reg-stack, the x86 floating point stack regs are difficult to
2720 analyze because of all of the pushes, pops and rotations. Thus, we
2721 just leave the notes alone. */
2725 df_ignore_stack_reg (int regno
)
2727 return regstack_completed
2728 && IN_RANGE (regno
, FIRST_STACK_REG
, LAST_STACK_REG
);
2732 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED
)
2739 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
2742 df_remove_dead_and_unused_notes (rtx insn
)
2744 rtx
*pprev
= ®_NOTES (insn
);
2749 switch (REG_NOTE_KIND (link
))
2752 /* After reg-stack, we need to ignore any unused notes
2753 for the stack registers. */
2754 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2756 pprev
= &XEXP (link
, 1);
2761 rtx next
= XEXP (link
, 1);
2762 if (REG_DEAD_DEBUGGING
)
2763 df_print_note ("deleting: ", insn
, link
);
2764 free_EXPR_LIST_node (link
);
2765 *pprev
= link
= next
;
2770 /* After reg-stack, we need to ignore any unused notes
2771 for the stack registers. */
2772 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2774 pprev
= &XEXP (link
, 1);
2779 rtx next
= XEXP (link
, 1);
2780 if (REG_DEAD_DEBUGGING
)
2781 df_print_note ("deleting: ", insn
, link
);
2782 free_EXPR_LIST_node (link
);
2783 *pprev
= link
= next
;
2788 pprev
= &XEXP (link
, 1);
2795 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2796 as the bitmap of currently live registers. */
2799 df_remove_dead_eq_notes (rtx insn
, bitmap live
)
2801 rtx
*pprev
= ®_NOTES (insn
);
2806 switch (REG_NOTE_KIND (link
))
2811 /* Remove the notes that refer to dead registers. As we have at most
2812 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2813 so we need to purge the complete EQ_USES vector when removing
2814 the note using df_notes_rescan. */
2816 bool deleted
= false;
2818 FOR_EACH_INSN_EQ_USE (use
, insn
)
2819 if (DF_REF_REGNO (use
) > FIRST_PSEUDO_REGISTER
2821 && (DF_REF_FLAGS (use
) & DF_REF_IN_NOTE
)
2822 && !bitmap_bit_p (live
, DF_REF_REGNO (use
))
2823 && loc_mentioned_in_p (DF_REF_LOC (use
), XEXP (link
, 0)))
2831 if (REG_DEAD_DEBUGGING
)
2832 df_print_note ("deleting: ", insn
, link
);
2833 next
= XEXP (link
, 1);
2834 free_EXPR_LIST_node (link
);
2835 *pprev
= link
= next
;
2836 df_notes_rescan (insn
);
2840 pprev
= &XEXP (link
, 1);
2847 pprev
= &XEXP (link
, 1);
2854 /* Set a NOTE_TYPE note for REG in INSN. */
2857 df_set_note (enum reg_note note_type
, rtx insn
, rtx reg
)
2859 gcc_checking_assert (!DEBUG_INSN_P (insn
));
2860 add_reg_note (insn
, note_type
, reg
);
2863 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2864 arguments. Return true if the register value described by MWS's
2865 mw_reg is known to be completely unused, and if mw_reg can therefore
2866 be used in a REG_UNUSED note. */
2869 df_whole_mw_reg_unused_p (struct df_mw_hardreg
*mws
,
2870 bitmap live
, bitmap artificial_uses
)
2874 /* If MWS describes a partial reference, create REG_UNUSED notes for
2875 individual hard registers. */
2876 if (mws
->flags
& DF_REF_PARTIAL
)
2879 /* Likewise if some part of the register is used. */
2880 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2881 if (bitmap_bit_p (live
, r
)
2882 || bitmap_bit_p (artificial_uses
, r
))
2885 gcc_assert (REG_P (mws
->mw_reg
));
2890 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2891 based on the bits in LIVE. Do not generate notes for registers in
2892 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2893 not generated if the reg is both read and written by the
2898 df_set_unused_notes_for_mw (rtx insn
, struct df_mw_hardreg
*mws
,
2899 bitmap live
, bitmap do_not_gen
,
2900 bitmap artificial_uses
,
2901 struct dead_debug_local
*debug
)
2905 if (REG_DEAD_DEBUGGING
&& dump_file
)
2906 fprintf (dump_file
, "mw_set_unused looking at mws[%d..%d]\n",
2907 mws
->start_regno
, mws
->end_regno
);
2909 if (df_whole_mw_reg_unused_p (mws
, live
, artificial_uses
))
2911 unsigned int regno
= mws
->start_regno
;
2912 df_set_note (REG_UNUSED
, insn
, mws
->mw_reg
);
2913 dead_debug_insert_temp (debug
, regno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
2915 if (REG_DEAD_DEBUGGING
)
2916 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
2918 bitmap_set_bit (do_not_gen
, regno
);
2919 /* Only do this if the value is totally dead. */
2922 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2924 if (!bitmap_bit_p (live
, r
)
2925 && !bitmap_bit_p (artificial_uses
, r
))
2927 df_set_note (REG_UNUSED
, insn
, regno_reg_rtx
[r
]);
2928 dead_debug_insert_temp (debug
, r
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
2929 if (REG_DEAD_DEBUGGING
)
2930 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
2932 bitmap_set_bit (do_not_gen
, r
);
2937 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2938 arguments. Return true if the register value described by MWS's
2939 mw_reg is known to be completely dead, and if mw_reg can therefore
2940 be used in a REG_DEAD note. */
2943 df_whole_mw_reg_dead_p (struct df_mw_hardreg
*mws
,
2944 bitmap live
, bitmap artificial_uses
,
2949 /* If MWS describes a partial reference, create REG_DEAD notes for
2950 individual hard registers. */
2951 if (mws
->flags
& DF_REF_PARTIAL
)
2954 /* Likewise if some part of the register is not dead. */
2955 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2956 if (bitmap_bit_p (live
, r
)
2957 || bitmap_bit_p (artificial_uses
, r
)
2958 || bitmap_bit_p (do_not_gen
, r
))
2961 gcc_assert (REG_P (mws
->mw_reg
));
2965 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2966 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2967 from being set if the instruction both reads and writes the
2971 df_set_dead_notes_for_mw (rtx insn
, struct df_mw_hardreg
*mws
,
2972 bitmap live
, bitmap do_not_gen
,
2973 bitmap artificial_uses
, bool *added_notes_p
)
2976 bool is_debug
= *added_notes_p
;
2978 *added_notes_p
= false;
2980 if (REG_DEAD_DEBUGGING
&& dump_file
)
2982 fprintf (dump_file
, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2983 mws
->start_regno
, mws
->end_regno
);
2984 df_print_regset (dump_file
, do_not_gen
);
2985 fprintf (dump_file
, " live =");
2986 df_print_regset (dump_file
, live
);
2987 fprintf (dump_file
, " artificial uses =");
2988 df_print_regset (dump_file
, artificial_uses
);
2991 if (df_whole_mw_reg_dead_p (mws
, live
, artificial_uses
, do_not_gen
))
2995 *added_notes_p
= true;
2998 /* Add a dead note for the entire multi word register. */
2999 df_set_note (REG_DEAD
, insn
, mws
->mw_reg
);
3000 if (REG_DEAD_DEBUGGING
)
3001 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
3005 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
3006 if (!bitmap_bit_p (live
, r
)
3007 && !bitmap_bit_p (artificial_uses
, r
)
3008 && !bitmap_bit_p (do_not_gen
, r
))
3012 *added_notes_p
= true;
3015 df_set_note (REG_DEAD
, insn
, regno_reg_rtx
[r
]);
3016 if (REG_DEAD_DEBUGGING
)
3017 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
3024 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3025 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3028 df_create_unused_note (rtx insn
, df_ref def
,
3029 bitmap live
, bitmap artificial_uses
,
3030 struct dead_debug_local
*debug
)
3032 unsigned int dregno
= DF_REF_REGNO (def
);
3034 if (REG_DEAD_DEBUGGING
&& dump_file
)
3036 fprintf (dump_file
, " regular looking at def ");
3037 df_ref_debug (def
, dump_file
);
3040 if (!((DF_REF_FLAGS (def
) & DF_REF_MW_HARDREG
)
3041 || bitmap_bit_p (live
, dregno
)
3042 || bitmap_bit_p (artificial_uses
, dregno
)
3043 || df_ignore_stack_reg (dregno
)))
3045 rtx reg
= (DF_REF_LOC (def
))
3046 ? *DF_REF_REAL_LOC (def
): DF_REF_REG (def
);
3047 df_set_note (REG_UNUSED
, insn
, reg
);
3048 dead_debug_insert_temp (debug
, dregno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
3049 if (REG_DEAD_DEBUGGING
)
3050 df_print_note ("adding 3: ", insn
, REG_NOTES (insn
));
3057 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3058 info: lifetime, bb, and number of defs and uses for basic block
3059 BB. The three bitvectors are scratch regs used here. */
3062 df_note_bb_compute (unsigned int bb_index
,
3063 bitmap live
, bitmap do_not_gen
, bitmap artificial_uses
)
3065 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3068 struct dead_debug_local debug
;
3070 dead_debug_local_init (&debug
, NULL
, NULL
);
3072 bitmap_copy (live
, df_get_live_out (bb
));
3073 bitmap_clear (artificial_uses
);
3075 if (REG_DEAD_DEBUGGING
&& dump_file
)
3077 fprintf (dump_file
, "live at bottom ");
3078 df_print_regset (dump_file
, live
);
3081 /* Process the artificial defs and uses at the bottom of the block
3082 to begin processing. */
3083 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3085 if (REG_DEAD_DEBUGGING
&& dump_file
)
3086 fprintf (dump_file
, "artificial def %d\n", DF_REF_REGNO (def
));
3088 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3089 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3092 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3093 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3095 unsigned int regno
= DF_REF_REGNO (use
);
3096 bitmap_set_bit (live
, regno
);
3098 /* Notes are not generated for any of the artificial registers
3099 at the bottom of the block. */
3100 bitmap_set_bit (artificial_uses
, regno
);
3103 if (REG_DEAD_DEBUGGING
&& dump_file
)
3105 fprintf (dump_file
, "live before artificials out ");
3106 df_print_regset (dump_file
, live
);
3109 FOR_BB_INSNS_REVERSE (bb
, insn
)
3111 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3118 debug_insn
= DEBUG_INSN_P (insn
);
3120 bitmap_clear (do_not_gen
);
3121 df_remove_dead_and_unused_notes (insn
);
3123 /* Process the defs. */
3126 if (REG_DEAD_DEBUGGING
&& dump_file
)
3128 fprintf (dump_file
, "processing call %d\n live =",
3130 df_print_regset (dump_file
, live
);
3133 /* We only care about real sets for calls. Clobbers cannot
3134 be depended on to really die. */
3135 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3136 if ((DF_MWS_REG_DEF_P (mw
))
3137 && !df_ignore_stack_reg (mw
->start_regno
))
3138 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3139 artificial_uses
, &debug
);
3141 /* All of the defs except the return value are some sort of
3142 clobber. This code is for the return. */
3143 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3145 unsigned int dregno
= DF_REF_REGNO (def
);
3146 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3148 df_create_unused_note (insn
,
3149 def
, live
, artificial_uses
, &debug
);
3150 bitmap_set_bit (do_not_gen
, dregno
);
3153 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3154 bitmap_clear_bit (live
, dregno
);
3160 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3161 if (DF_MWS_REG_DEF_P (mw
))
3162 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3163 artificial_uses
, &debug
);
3165 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3167 unsigned int dregno
= DF_REF_REGNO (def
);
3168 df_create_unused_note (insn
,
3169 def
, live
, artificial_uses
, &debug
);
3171 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3172 bitmap_set_bit (do_not_gen
, dregno
);
3174 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3175 bitmap_clear_bit (live
, dregno
);
3179 /* Process the uses. */
3180 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3181 if (DF_MWS_REG_USE_P (mw
)
3182 && !df_ignore_stack_reg (mw
->start_regno
))
3184 bool really_add_notes
= debug_insn
!= 0;
3186 df_set_dead_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3190 if (really_add_notes
)
3194 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3196 unsigned int uregno
= DF_REF_REGNO (use
);
3198 if (REG_DEAD_DEBUGGING
&& dump_file
&& !debug_insn
)
3200 fprintf (dump_file
, " regular looking at use ");
3201 df_ref_debug (use
, dump_file
);
3204 if (!bitmap_bit_p (live
, uregno
))
3210 /* We won't add REG_UNUSED or REG_DEAD notes for
3211 these, so we don't have to mess with them in
3212 debug insns either. */
3213 if (!bitmap_bit_p (artificial_uses
, uregno
)
3214 && !df_ignore_stack_reg (uregno
))
3215 dead_debug_add (&debug
, use
, uregno
);
3221 dead_debug_insert_temp (&debug
, uregno
, insn
,
3222 DEBUG_TEMP_BEFORE_WITH_REG
);
3224 if ( (!(DF_REF_FLAGS (use
)
3225 & (DF_REF_MW_HARDREG
| DF_REF_READ_WRITE
)))
3226 && (!bitmap_bit_p (do_not_gen
, uregno
))
3227 && (!bitmap_bit_p (artificial_uses
, uregno
))
3228 && (!df_ignore_stack_reg (uregno
)))
3230 rtx reg
= (DF_REF_LOC (use
))
3231 ? *DF_REF_REAL_LOC (use
) : DF_REF_REG (use
);
3232 df_set_note (REG_DEAD
, insn
, reg
);
3234 if (REG_DEAD_DEBUGGING
)
3235 df_print_note ("adding 4: ", insn
, REG_NOTES (insn
));
3237 /* This register is now live. */
3238 bitmap_set_bit (live
, uregno
);
3242 df_remove_dead_eq_notes (insn
, live
);
3244 if (debug_insn
== -1)
3246 /* ??? We could probably do better here, replacing dead
3247 registers with their definitions. */
3248 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
3249 df_insn_rescan_debug_internal (insn
);
3253 dead_debug_local_finish (&debug
, NULL
);
3257 /* Compute register info: lifetime, bb, and number of defs and uses. */
3259 df_note_compute (bitmap all_blocks
)
3261 unsigned int bb_index
;
3263 bitmap_head live
, do_not_gen
, artificial_uses
;
3265 bitmap_initialize (&live
, &df_bitmap_obstack
);
3266 bitmap_initialize (&do_not_gen
, &df_bitmap_obstack
);
3267 bitmap_initialize (&artificial_uses
, &df_bitmap_obstack
);
3269 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
3271 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3272 pseudos in debug insns because we don't always (re)visit blocks
3273 with death points after visiting dead uses. Even changing this
3274 loop to postorder would still leave room for visiting a death
3275 point before visiting a subsequent debug use. */
3276 df_note_bb_compute (bb_index
, &live
, &do_not_gen
, &artificial_uses
);
3279 bitmap_clear (&live
);
3280 bitmap_clear (&do_not_gen
);
3281 bitmap_clear (&artificial_uses
);
3285 /* Free all storage associated with the problem. */
3294 /* All of the information associated every instance of the problem. */
3296 static struct df_problem problem_NOTE
=
3298 DF_NOTE
, /* Problem id. */
3299 DF_NONE
, /* Direction. */
3300 df_note_alloc
, /* Allocate the problem specific data. */
3301 NULL
, /* Reset global information. */
3302 NULL
, /* Free basic block info. */
3303 df_note_compute
, /* Local compute function. */
3304 NULL
, /* Init the solution specific data. */
3305 NULL
, /* Iterative solver. */
3306 NULL
, /* Confluence operator 0. */
3307 NULL
, /* Confluence operator n. */
3308 NULL
, /* Transfer function. */
3309 NULL
, /* Finalize function. */
3310 df_note_free
, /* Free all of the problem information. */
3311 df_note_free
, /* Remove this problem from the stack of dataflow problems. */
3312 NULL
, /* Debugging. */
3313 NULL
, /* Debugging start block. */
3314 NULL
, /* Debugging end block. */
3315 NULL
, /* Debugging start insn. */
3316 NULL
, /* Debugging end insn. */
3317 NULL
, /* Incremental solution verify start. */
3318 NULL
, /* Incremental solution verify end. */
3319 &problem_LR
, /* Dependent problem. */
3320 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
3321 TV_DF_NOTE
, /* Timing variable. */
3322 false /* Reset blocks on dropping out of blocks_to_analyze. */
3326 /* Create a new DATAFLOW instance and add it to an existing instance
3327 of DF. The returned structure is what is used to get at the
3331 df_note_add_problem (void)
3333 df_add_problem (&problem_NOTE
);
3339 /*----------------------------------------------------------------------------
3340 Functions for simulating the effects of single insns.
3342 You can either simulate in the forwards direction, starting from
3343 the top of a block or the backwards direction from the end of the
3344 block. If you go backwards, defs are examined first to clear bits,
3345 then uses are examined to set bits. If you go forwards, defs are
3346 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3347 are examined to clear bits. In either case, the result of examining
3348 a def can be undone (respectively by a use or a REG_UNUSED note).
3350 If you start at the top of the block, use one of DF_LIVE_IN or
3351 DF_LR_IN. If you start at the bottom of the block use one of
3352 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3353 THEY WILL BE DESTROYED.
3354 ----------------------------------------------------------------------------*/
3357 /* Find the set of DEFs for INSN. */
3360 df_simulate_find_defs (rtx insn
, bitmap defs
)
3364 FOR_EACH_INSN_DEF (def
, insn
)
3365 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3368 /* Find the set of uses for INSN. This includes partial defs. */
3371 df_simulate_find_uses (rtx insn
, bitmap uses
)
3374 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3376 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3377 if (DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3378 bitmap_set_bit (uses
, DF_REF_REGNO (def
));
3379 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3380 bitmap_set_bit (uses
, DF_REF_REGNO (use
));
3383 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3386 df_simulate_find_noclobber_defs (rtx insn
, bitmap defs
)
3390 FOR_EACH_INSN_DEF (def
, insn
)
3391 if (!(DF_REF_FLAGS (def
) & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
3392 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3396 /* Simulate the effects of the defs of INSN on LIVE. */
3399 df_simulate_defs (rtx insn
, bitmap live
)
3403 FOR_EACH_INSN_DEF (def
, insn
)
3405 unsigned int dregno
= DF_REF_REGNO (def
);
3407 /* If the def is to only part of the reg, it does
3408 not kill the other defs that reach here. */
3409 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
3410 bitmap_clear_bit (live
, dregno
);
3415 /* Simulate the effects of the uses of INSN on LIVE. */
3418 df_simulate_uses (rtx insn
, bitmap live
)
3422 if (DEBUG_INSN_P (insn
))
3425 FOR_EACH_INSN_USE (use
, insn
)
3426 /* Add use to set of uses in this BB. */
3427 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3431 /* Add back the always live regs in BB to LIVE. */
3434 df_simulate_fixup_sets (basic_block bb
, bitmap live
)
3436 /* These regs are considered always live so if they end up dying
3437 because of some def, we need to bring the back again. */
3438 if (bb_has_eh_pred (bb
))
3439 bitmap_ior_into (live
, &df
->eh_block_artificial_uses
);
3441 bitmap_ior_into (live
, &df
->regular_block_artificial_uses
);
3445 /*----------------------------------------------------------------------------
3446 The following three functions are used only for BACKWARDS scanning:
3447 i.e. they process the defs before the uses.
3449 df_simulate_initialize_backwards should be called first with a
3450 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3451 df_simulate_one_insn_backwards should be called for each insn in
3452 the block, starting with the last one. Finally,
3453 df_simulate_finalize_backwards can be called to get a new value
3454 of the sets at the top of the block (this is rarely used).
3455 ----------------------------------------------------------------------------*/
3457 /* Apply the artificial uses and defs at the end of BB in a backwards
3461 df_simulate_initialize_backwards (basic_block bb
, bitmap live
)
3464 int bb_index
= bb
->index
;
3466 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3467 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3468 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3470 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3471 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3472 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3476 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3479 df_simulate_one_insn_backwards (basic_block bb
, rtx insn
, bitmap live
)
3481 if (!NONDEBUG_INSN_P (insn
))
3484 df_simulate_defs (insn
, live
);
3485 df_simulate_uses (insn
, live
);
3486 df_simulate_fixup_sets (bb
, live
);
3490 /* Apply the artificial uses and defs at the top of BB in a backwards
3494 df_simulate_finalize_backwards (basic_block bb
, bitmap live
)
3500 int bb_index
= bb
->index
;
3502 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3503 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3504 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3507 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3508 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
3509 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3512 /*----------------------------------------------------------------------------
3513 The following three functions are used only for FORWARDS scanning:
3514 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3515 Thus it is important to add the DF_NOTES problem to the stack of
3516 problems computed before using these functions.
3518 df_simulate_initialize_forwards should be called first with a
3519 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3520 df_simulate_one_insn_forwards should be called for each insn in
3521 the block, starting with the first one.
3522 ----------------------------------------------------------------------------*/
3524 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3525 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3529 df_simulate_initialize_forwards (basic_block bb
, bitmap live
)
3532 int bb_index
= bb
->index
;
3534 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3535 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3536 bitmap_set_bit (live
, DF_REF_REGNO (def
));
3539 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3542 df_simulate_one_insn_forwards (basic_block bb
, rtx insn
, bitmap live
)
3545 if (! INSN_P (insn
))
3548 /* Make sure that DF_NOTE really is an active df problem. */
3549 gcc_assert (df_note
);
3551 /* Note that this is the opposite as how the problem is defined, because
3552 in the LR problem defs _kill_ liveness. However, they do so backwards,
3553 while here the scan is performed forwards! So, first assume that the
3554 def is live, and if this is not true REG_UNUSED notes will rectify the
3556 df_simulate_find_noclobber_defs (insn
, live
);
3558 /* Clear all of the registers that go dead. */
3559 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
3561 switch (REG_NOTE_KIND (link
))
3566 rtx reg
= XEXP (link
, 0);
3567 int regno
= REGNO (reg
);
3568 if (HARD_REGISTER_NUM_P (regno
))
3569 bitmap_clear_range (live
, regno
,
3570 hard_regno_nregs
[regno
][GET_MODE (reg
)]);
3572 bitmap_clear_bit (live
, regno
);
3579 df_simulate_fixup_sets (bb
, live
);
3582 /* Used by the next two functions to encode information about the
3583 memory references we found. */
3584 #define MEMREF_NORMAL 1
3585 #define MEMREF_VOLATILE 2
3587 /* A subroutine of can_move_insns_across_p called through for_each_rtx.
3588 Return either MEMREF_NORMAL or MEMREF_VOLATILE if a memory is found. */
3591 find_memory (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
3595 if (GET_CODE (x
) == ASM_OPERANDS
&& MEM_VOLATILE_P (x
))
3596 return MEMREF_VOLATILE
;
3600 if (MEM_VOLATILE_P (x
))
3601 return MEMREF_VOLATILE
;
3602 if (MEM_READONLY_P (x
))
3605 return MEMREF_NORMAL
;
3608 /* A subroutine of can_move_insns_across_p called through note_stores.
3609 DATA points to an integer in which we set either the bit for
3610 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3614 find_memory_stores (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
,
3615 void *data ATTRIBUTE_UNUSED
)
3617 int *pflags
= (int *)data
;
3618 if (GET_CODE (x
) == SUBREG
)
3620 /* Treat stores to SP as stores to memory, this will prevent problems
3621 when there are references to the stack frame. */
3622 if (x
== stack_pointer_rtx
)
3623 *pflags
|= MEMREF_VOLATILE
;
3626 *pflags
|= MEM_VOLATILE_P (x
) ? MEMREF_VOLATILE
: MEMREF_NORMAL
;
3629 /* Scan BB backwards, using df_simulate functions to keep track of
3630 lifetimes, up to insn POINT. The result is stored in LIVE. */
3633 simulate_backwards_to_point (basic_block bb
, regset live
, rtx point
)
3636 bitmap_copy (live
, df_get_live_out (bb
));
3637 df_simulate_initialize_backwards (bb
, live
);
3639 /* Scan and update life information until we reach the point we're
3641 for (insn
= BB_END (bb
); insn
!= point
; insn
= PREV_INSN (insn
))
3642 df_simulate_one_insn_backwards (bb
, insn
, live
);
3645 /* Return true if it is safe to move a group of insns, described by
3646 the range FROM to TO, backwards across another group of insns,
3647 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3648 are no insns between ACROSS_TO and FROM, but they may be in
3649 different basic blocks; MERGE_BB is the block from which the
3650 insns will be moved. The caller must pass in a regset MERGE_LIVE
3651 which specifies the registers live after TO.
3653 This function may be called in one of two cases: either we try to
3654 move identical instructions from all successor blocks into their
3655 predecessor, or we try to move from only one successor block. If
3656 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3657 the second case. It should contain a set of registers live at the
3658 end of ACROSS_TO which must not be clobbered by moving the insns.
3659 In that case, we're also more careful about moving memory references
3662 We return false if it is not safe to move the entire group, but it
3663 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3664 is set to point at the last moveable insn in such a case. */
3667 can_move_insns_across (rtx from
, rtx to
, rtx across_from
, rtx across_to
,
3668 basic_block merge_bb
, regset merge_live
,
3669 regset other_branch_live
, rtx
*pmove_upto
)
3671 rtx insn
, next
, max_to
;
3672 bitmap merge_set
, merge_use
, local_merge_live
;
3673 bitmap test_set
, test_use
;
3674 unsigned i
, fail
= 0;
3676 int memrefs_in_across
= 0;
3677 int mem_sets_in_across
= 0;
3678 bool trapping_insns_in_across
= false;
3680 if (pmove_upto
!= NULL
)
3681 *pmove_upto
= NULL_RTX
;
3683 /* Find real bounds, ignoring debug insns. */
3684 while (!NONDEBUG_INSN_P (from
) && from
!= to
)
3685 from
= NEXT_INSN (from
);
3686 while (!NONDEBUG_INSN_P (to
) && from
!= to
)
3687 to
= PREV_INSN (to
);
3689 for (insn
= across_to
; ; insn
= next
)
3693 if (RTL_CONST_OR_PURE_CALL_P (insn
))
3694 /* Pure functions can read from memory. Const functions can
3695 read from arguments that the ABI has forced onto the stack.
3696 Neither sort of read can be volatile. */
3697 memrefs_in_across
|= MEMREF_NORMAL
;
3700 memrefs_in_across
|= MEMREF_VOLATILE
;
3701 mem_sets_in_across
|= MEMREF_VOLATILE
;
3704 if (NONDEBUG_INSN_P (insn
))
3706 if (volatile_insn_p (PATTERN (insn
)))
3708 memrefs_in_across
|= for_each_rtx (&PATTERN (insn
), find_memory
,
3710 note_stores (PATTERN (insn
), find_memory_stores
,
3711 &mem_sets_in_across
);
3712 /* This is used just to find sets of the stack pointer. */
3713 memrefs_in_across
|= mem_sets_in_across
;
3714 trapping_insns_in_across
|= may_trap_p (PATTERN (insn
));
3716 next
= PREV_INSN (insn
);
3717 if (insn
== across_from
)
3722 MERGE_SET = set of registers set in MERGE_BB
3723 MERGE_USE = set of registers used in MERGE_BB and live at its top
3724 MERGE_LIVE = set of registers live at the point inside the MERGE
3725 range that we've reached during scanning
3726 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3727 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3728 and live before ACROSS_FROM. */
3730 merge_set
= BITMAP_ALLOC (®_obstack
);
3731 merge_use
= BITMAP_ALLOC (®_obstack
);
3732 local_merge_live
= BITMAP_ALLOC (®_obstack
);
3733 test_set
= BITMAP_ALLOC (®_obstack
);
3734 test_use
= BITMAP_ALLOC (®_obstack
);
3736 /* Compute the set of registers set and used in the ACROSS range. */
3737 if (other_branch_live
!= NULL
)
3738 bitmap_copy (test_use
, other_branch_live
);
3739 df_simulate_initialize_backwards (merge_bb
, test_use
);
3740 for (insn
= across_to
; ; insn
= next
)
3742 if (NONDEBUG_INSN_P (insn
))
3744 df_simulate_find_defs (insn
, test_set
);
3745 df_simulate_defs (insn
, test_use
);
3746 df_simulate_uses (insn
, test_use
);
3748 next
= PREV_INSN (insn
);
3749 if (insn
== across_from
)
3753 /* Compute an upper bound for the amount of insns moved, by finding
3754 the first insn in MERGE that sets a register in TEST_USE, or uses
3755 a register in TEST_SET. We also check for calls, trapping operations,
3756 and memory references. */
3758 for (insn
= from
; ; insn
= next
)
3762 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_EPILOGUE_BEG
)
3764 if (NONDEBUG_INSN_P (insn
))
3766 if (may_trap_or_fault_p (PATTERN (insn
))
3767 && (trapping_insns_in_across
3768 || other_branch_live
!= NULL
3769 || volatile_insn_p (PATTERN (insn
))))
3772 /* We cannot move memory stores past each other, or move memory
3773 reads past stores, at least not without tracking them and
3774 calling true_dependence on every pair.
3776 If there is no other branch and no memory references or
3777 sets in the ACROSS range, we can move memory references
3778 freely, even volatile ones.
3780 Otherwise, the rules are as follows: volatile memory
3781 references and stores can't be moved at all, and any type
3782 of memory reference can't be moved if there are volatile
3783 accesses or stores in the ACROSS range. That leaves
3784 normal reads, which can be moved, as the trapping case is
3785 dealt with elsewhere. */
3786 if (other_branch_live
!= NULL
|| memrefs_in_across
!= 0)
3788 int mem_ref_flags
= 0;
3789 int mem_set_flags
= 0;
3790 note_stores (PATTERN (insn
), find_memory_stores
, &mem_set_flags
);
3791 mem_ref_flags
= for_each_rtx (&PATTERN (insn
), find_memory
,
3793 /* Catch sets of the stack pointer. */
3794 mem_ref_flags
|= mem_set_flags
;
3796 if ((mem_ref_flags
| mem_set_flags
) & MEMREF_VOLATILE
)
3798 if ((memrefs_in_across
& MEMREF_VOLATILE
) && mem_ref_flags
!= 0)
3800 if (mem_set_flags
!= 0
3801 || (mem_sets_in_across
!= 0 && mem_ref_flags
!= 0))
3804 df_simulate_find_uses (insn
, merge_use
);
3805 /* We're only interested in uses which use a value live at
3806 the top, not one previously set in this block. */
3807 bitmap_and_compl_into (merge_use
, merge_set
);
3808 df_simulate_find_defs (insn
, merge_set
);
3809 if (bitmap_intersect_p (merge_set
, test_use
)
3810 || bitmap_intersect_p (merge_use
, test_set
))
3813 if (!sets_cc0_p (insn
))
3817 next
= NEXT_INSN (insn
);
3824 if (max_to
== NULL_RTX
|| (fail
&& pmove_upto
== NULL
))
3827 /* Now, lower this upper bound by also taking into account that
3828 a range of insns moved across ACROSS must not leave a register
3829 live at the end that will be clobbered in ACROSS. We need to
3830 find a point where TEST_SET & LIVE == 0.
3832 Insns in the MERGE range that set registers which are also set
3833 in the ACROSS range may still be moved as long as we also move
3834 later insns which use the results of the set, and make the
3835 register dead again. This is verified by the condition stated
3836 above. We only need to test it for registers that are set in
3839 MERGE_LIVE is provided by the caller and holds live registers after
3841 bitmap_copy (local_merge_live
, merge_live
);
3842 for (insn
= to
; insn
!= max_to
; insn
= PREV_INSN (insn
))
3843 df_simulate_one_insn_backwards (merge_bb
, insn
, local_merge_live
);
3845 /* We're not interested in registers that aren't set in the moved
3847 bitmap_and_into (local_merge_live
, merge_set
);
3850 if (NONDEBUG_INSN_P (insn
))
3852 if (!bitmap_intersect_p (test_set
, local_merge_live
)
3854 && !sets_cc0_p (insn
)
3862 df_simulate_one_insn_backwards (merge_bb
, insn
,
3870 insn
= PREV_INSN (insn
);
3877 *pmove_upto
= max_to
;
3879 /* For small register class machines, don't lengthen lifetimes of
3880 hard registers before reload. */
3881 if (! reload_completed
3882 && targetm
.small_register_classes_for_mode_p (VOIDmode
))
3884 EXECUTE_IF_SET_IN_BITMAP (merge_set
, 0, i
, bi
)
3886 if (i
< FIRST_PSEUDO_REGISTER
3888 && ! global_regs
[i
])
3897 BITMAP_FREE (merge_set
);
3898 BITMAP_FREE (merge_use
);
3899 BITMAP_FREE (local_merge_live
);
3900 BITMAP_FREE (test_set
);
3901 BITMAP_FREE (test_use
);
3907 /*----------------------------------------------------------------------------
3908 MULTIPLE DEFINITIONS
3910 Find the locations in the function reached by multiple definition sites
3911 for a live pseudo. In and out bitvectors are built for each basic
3912 block. They are restricted for efficiency to live registers.
3914 The gen and kill sets for the problem are obvious. Together they
3915 include all defined registers in a basic block; the gen set includes
3916 registers where a partial or conditional or may-clobber definition is
3917 last in the BB, while the kill set includes registers with a complete
3918 definition coming last. However, the computation of the dataflow
3919 itself is interesting.
3921 The idea behind it comes from SSA form's iterated dominance frontier
3922 criterion for inserting PHI functions. Just like in that case, we can use
3923 the dominance frontier to find places where multiple definitions meet;
3924 a register X defined in a basic block BB1 has multiple definitions in
3925 basic blocks in BB1's dominance frontier.
3927 So, the in-set of a basic block BB2 is not just the union of the
3928 out-sets of BB2's predecessors, but includes some more bits that come
3929 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3930 the previous paragraph). I called this set the init-set of BB2.
3932 (Note: I actually use the kill-set only to build the init-set.
3933 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3935 For example, if you have
3939 if <...> goto BB2 else goto BB3;
3947 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3948 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3949 not need to iterate the dominance frontier, because we do not insert
3950 anything like PHI functions there! Instead, dataflow will take care of
3951 propagating the information to BB3's successors.
3952 ---------------------------------------------------------------------------*/
3954 /* Private data used to verify the solution for this problem. */
3955 struct df_md_problem_data
3957 /* An obstack for the bitmaps we need for this problem. */
3958 bitmap_obstack md_bitmaps
;
3961 /* Scratch var used by transfer functions. This is used to do md analysis
3962 only for live registers. */
3963 static bitmap_head df_md_scratch
;
3967 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
3970 struct df_md_bb_info
*bb_info
= (struct df_md_bb_info
*) vbb_info
;
3973 bitmap_clear (&bb_info
->kill
);
3974 bitmap_clear (&bb_info
->gen
);
3975 bitmap_clear (&bb_info
->init
);
3976 bitmap_clear (&bb_info
->in
);
3977 bitmap_clear (&bb_info
->out
);
3982 /* Allocate or reset bitmaps for DF_MD. The solution bits are
3983 not touched unless the block is new. */
3986 df_md_alloc (bitmap all_blocks
)
3988 unsigned int bb_index
;
3990 struct df_md_problem_data
*problem_data
;
3992 df_grow_bb_info (df_md
);
3993 if (df_md
->problem_data
)
3994 problem_data
= (struct df_md_problem_data
*) df_md
->problem_data
;
3997 problem_data
= XNEW (struct df_md_problem_data
);
3998 df_md
->problem_data
= problem_data
;
3999 bitmap_obstack_initialize (&problem_data
->md_bitmaps
);
4001 bitmap_initialize (&df_md_scratch
, &problem_data
->md_bitmaps
);
4003 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4005 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4006 /* When bitmaps are already initialized, just clear them. */
4007 if (bb_info
->init
.obstack
)
4009 bitmap_clear (&bb_info
->init
);
4010 bitmap_clear (&bb_info
->gen
);
4011 bitmap_clear (&bb_info
->kill
);
4012 bitmap_clear (&bb_info
->in
);
4013 bitmap_clear (&bb_info
->out
);
4017 bitmap_initialize (&bb_info
->init
, &problem_data
->md_bitmaps
);
4018 bitmap_initialize (&bb_info
->gen
, &problem_data
->md_bitmaps
);
4019 bitmap_initialize (&bb_info
->kill
, &problem_data
->md_bitmaps
);
4020 bitmap_initialize (&bb_info
->in
, &problem_data
->md_bitmaps
);
4021 bitmap_initialize (&bb_info
->out
, &problem_data
->md_bitmaps
);
4025 df_md
->optional_p
= true;
4028 /* Add the effect of the top artificial defs of BB to the multiple definitions
4032 df_md_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_md
)
4034 int bb_index
= bb
->index
;
4036 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
4037 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
4039 unsigned int dregno
= DF_REF_REGNO (def
);
4040 if (DF_REF_FLAGS (def
)
4041 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4042 bitmap_set_bit (local_md
, dregno
);
4044 bitmap_clear_bit (local_md
, dregno
);
4049 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4053 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx insn
,
4058 FOR_EACH_INSN_DEF (def
, insn
)
4060 unsigned int dregno
= DF_REF_REGNO (def
);
4061 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4062 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4064 if (DF_REF_FLAGS (def
)
4065 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4066 bitmap_set_bit (local_md
, DF_REF_ID (def
));
4068 bitmap_clear_bit (local_md
, DF_REF_ID (def
));
4074 df_md_bb_local_compute_process_def (struct df_md_bb_info
*bb_info
,
4078 bitmap_clear (&seen_in_insn
);
4080 for (; def
; def
= DF_REF_NEXT_LOC (def
))
4082 unsigned int dregno
= DF_REF_REGNO (def
);
4083 if (((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4084 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4085 && top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
4087 if (!bitmap_bit_p (&seen_in_insn
, dregno
))
4089 if (DF_REF_FLAGS (def
)
4090 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4092 bitmap_set_bit (&bb_info
->gen
, dregno
);
4093 bitmap_clear_bit (&bb_info
->kill
, dregno
);
4097 /* When we find a clobber and a regular def,
4098 make sure the regular def wins. */
4099 bitmap_set_bit (&seen_in_insn
, dregno
);
4100 bitmap_set_bit (&bb_info
->kill
, dregno
);
4101 bitmap_clear_bit (&bb_info
->gen
, dregno
);
4109 /* Compute local multiple def info for basic block BB. */
4112 df_md_bb_local_compute (unsigned int bb_index
)
4114 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4115 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4118 /* Artificials are only hard regs. */
4119 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4120 df_md_bb_local_compute_process_def (bb_info
,
4121 df_get_artificial_defs (bb_index
),
4124 FOR_BB_INSNS (bb
, insn
)
4126 unsigned int uid
= INSN_UID (insn
);
4130 df_md_bb_local_compute_process_def (bb_info
, DF_INSN_UID_DEFS (uid
), 0);
4133 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4134 df_md_bb_local_compute_process_def (bb_info
,
4135 df_get_artificial_defs (bb_index
),
4139 /* Compute local reaching def info for each basic block within BLOCKS. */
4142 df_md_local_compute (bitmap all_blocks
)
4144 unsigned int bb_index
, df_bb_index
;
4145 bitmap_iterator bi1
, bi2
;
4147 bitmap_head
*frontiers
;
4149 bitmap_initialize (&seen_in_insn
, &bitmap_default_obstack
);
4151 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4153 df_md_bb_local_compute (bb_index
);
4156 bitmap_clear (&seen_in_insn
);
4158 frontiers
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
4159 FOR_ALL_BB_FN (bb
, cfun
)
4160 bitmap_initialize (&frontiers
[bb
->index
], &bitmap_default_obstack
);
4162 compute_dominance_frontiers (frontiers
);
4164 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4165 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4167 bitmap kill
= &df_md_get_bb_info (bb_index
)->kill
;
4168 EXECUTE_IF_SET_IN_BITMAP (&frontiers
[bb_index
], 0, df_bb_index
, bi2
)
4170 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, df_bb_index
);
4171 if (bitmap_bit_p (all_blocks
, df_bb_index
))
4172 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index
)->init
, kill
,
4173 df_get_live_in (bb
));
4177 FOR_ALL_BB_FN (bb
, cfun
)
4178 bitmap_clear (&frontiers
[bb
->index
]);
4183 /* Reset the global solution for recalculation. */
4186 df_md_reset (bitmap all_blocks
)
4188 unsigned int bb_index
;
4191 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4193 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4194 gcc_assert (bb_info
);
4195 bitmap_clear (&bb_info
->in
);
4196 bitmap_clear (&bb_info
->out
);
4201 df_md_transfer_function (int bb_index
)
4203 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4204 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4205 bitmap in
= &bb_info
->in
;
4206 bitmap out
= &bb_info
->out
;
4207 bitmap gen
= &bb_info
->gen
;
4208 bitmap kill
= &bb_info
->kill
;
4210 /* We need to use a scratch set here so that the value returned from this
4211 function invocation properly reflects whether the sets changed in a
4212 significant way; i.e. not just because the live set was anded in. */
4213 bitmap_and (&df_md_scratch
, gen
, df_get_live_out (bb
));
4215 /* Multiple definitions of a register are not relevant if it is not
4216 live. Thus we trim the result to the places where it is live. */
4217 bitmap_and_into (in
, df_get_live_in (bb
));
4219 return bitmap_ior_and_compl (out
, &df_md_scratch
, in
, kill
);
4222 /* Initialize the solution bit vectors for problem. */
4225 df_md_init (bitmap all_blocks
)
4227 unsigned int bb_index
;
4230 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4232 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4234 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4235 df_md_transfer_function (bb_index
);
4240 df_md_confluence_0 (basic_block bb
)
4242 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4243 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4246 /* In of target gets or of out of source. */
4249 df_md_confluence_n (edge e
)
4251 bitmap op1
= &df_md_get_bb_info (e
->dest
->index
)->in
;
4252 bitmap op2
= &df_md_get_bb_info (e
->src
->index
)->out
;
4254 if (e
->flags
& EDGE_FAKE
)
4257 if (e
->flags
& EDGE_EH
)
4258 return bitmap_ior_and_compl_into (op1
, op2
,
4259 regs_invalidated_by_call_regset
);
4261 return bitmap_ior_into (op1
, op2
);
4264 /* Free all storage associated with the problem. */
4269 struct df_md_problem_data
*problem_data
4270 = (struct df_md_problem_data
*) df_md
->problem_data
;
4272 bitmap_obstack_release (&problem_data
->md_bitmaps
);
4273 free (problem_data
);
4274 df_md
->problem_data
= NULL
;
4276 df_md
->block_info_size
= 0;
4277 free (df_md
->block_info
);
4278 df_md
->block_info
= NULL
;
4283 /* Debugging info at top of bb. */
4286 df_md_top_dump (basic_block bb
, FILE *file
)
4288 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4292 fprintf (file
, ";; md in \t");
4293 df_print_regset (file
, &bb_info
->in
);
4294 fprintf (file
, ";; md init \t");
4295 df_print_regset (file
, &bb_info
->init
);
4296 fprintf (file
, ";; md gen \t");
4297 df_print_regset (file
, &bb_info
->gen
);
4298 fprintf (file
, ";; md kill \t");
4299 df_print_regset (file
, &bb_info
->kill
);
4302 /* Debugging info at bottom of bb. */
4305 df_md_bottom_dump (basic_block bb
, FILE *file
)
4307 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4311 fprintf (file
, ";; md out \t");
4312 df_print_regset (file
, &bb_info
->out
);
4315 static struct df_problem problem_MD
=
4317 DF_MD
, /* Problem id. */
4318 DF_FORWARD
, /* Direction. */
4319 df_md_alloc
, /* Allocate the problem specific data. */
4320 df_md_reset
, /* Reset global information. */
4321 df_md_free_bb_info
, /* Free basic block info. */
4322 df_md_local_compute
, /* Local compute function. */
4323 df_md_init
, /* Init the solution specific data. */
4324 df_worklist_dataflow
, /* Worklist solver. */
4325 df_md_confluence_0
, /* Confluence operator 0. */
4326 df_md_confluence_n
, /* Confluence operator n. */
4327 df_md_transfer_function
, /* Transfer function. */
4328 NULL
, /* Finalize function. */
4329 df_md_free
, /* Free all of the problem information. */
4330 df_md_free
, /* Remove this problem from the stack of dataflow problems. */
4331 NULL
, /* Debugging. */
4332 df_md_top_dump
, /* Debugging start block. */
4333 df_md_bottom_dump
, /* Debugging end block. */
4334 NULL
, /* Debugging start insn. */
4335 NULL
, /* Debugging end insn. */
4336 NULL
, /* Incremental solution verify start. */
4337 NULL
, /* Incremental solution verify end. */
4338 NULL
, /* Dependent problem. */
4339 sizeof (struct df_md_bb_info
),/* Size of entry of block_info array. */
4340 TV_DF_MD
, /* Timing variable. */
4341 false /* Reset blocks on dropping out of blocks_to_analyze. */
4344 /* Create a new MD instance and add it to the existing instance
4348 df_md_add_problem (void)
4350 df_add_problem (&problem_MD
);