1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
30 #include "insn-config.h"
32 #include "hard-reg-set.h"
35 #include "alloc-pool.h"
38 #include "dominance.h"
41 #include "basic-block.h"
53 /* Note that turning REG_DEAD_DEBUGGING on will cause
54 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
55 addresses in the dumps. */
56 #define REG_DEAD_DEBUGGING 0
58 #define DF_SPARSE_THRESHOLD 32
60 static bitmap_head seen_in_block
;
61 static bitmap_head seen_in_insn
;
63 /*----------------------------------------------------------------------------
65 ----------------------------------------------------------------------------*/
67 /* Generic versions to get the void* version of the block info. Only
68 used inside the problem instance vectors. */
70 /* Dump a def-use or use-def chain for REF to FILE. */
73 df_chain_dump (struct df_link
*link
, FILE *file
)
76 for (; link
; link
= link
->next
)
78 fprintf (file
, "%c%d(bb %d insn %d) ",
79 DF_REF_REG_DEF_P (link
->ref
)
81 : (DF_REF_FLAGS (link
->ref
) & DF_REF_IN_NOTE
) ? 'e' : 'u',
82 DF_REF_ID (link
->ref
),
83 DF_REF_BBNO (link
->ref
),
84 DF_REF_IS_ARTIFICIAL (link
->ref
)
85 ? -1 : DF_REF_INSN_UID (link
->ref
));
91 /* Print some basic block info as part of df_dump. */
94 df_print_bb_index (basic_block bb
, FILE *file
)
99 fprintf (file
, "\n( ");
100 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
102 basic_block pred
= e
->src
;
103 fprintf (file
, "%d%s ", pred
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
105 fprintf (file
, ")->[%d]->( ", bb
->index
);
106 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
108 basic_block succ
= e
->dest
;
109 fprintf (file
, "%d%s ", succ
->index
, e
->flags
& EDGE_EH
? "(EH)" : "");
111 fprintf (file
, ")\n");
115 /*----------------------------------------------------------------------------
118 Find the locations in the function where each definition site for a
119 pseudo reaches. In and out bitvectors are built for each basic
120 block. The id field in the ref is used to index into these sets.
121 See df.h for details.
123 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
124 existing uses are included in the global reaching DEFs set, or in other
125 words only DEFs that are still live. This is a kind of pruned version
126 of the traditional reaching definitions problem that is much less
127 complex to compute and produces enough information to compute UD-chains.
128 In this context, live must be interpreted in the DF_LR sense: Uses that
129 are upward exposed but maybe not initialized on all paths through the
130 CFG. For a USE that is not reached by a DEF on all paths, we still want
131 to make those DEFs that do reach the USE visible, and pruning based on
132 DF_LIVE would make that impossible.
133 ----------------------------------------------------------------------------*/
135 /* This problem plays a large number of games for the sake of
138 1) The order of the bits in the bitvectors. After the scanning
139 phase, all of the defs are sorted. All of the defs for the reg 0
140 are first, followed by all defs for reg 1 and so on.
142 2) There are two kill sets, one if the number of defs is less or
143 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
146 <= : Data is built directly in the kill set.
148 > : One level of indirection is used to keep from generating long
149 strings of 1 bits in the kill sets. Bitvectors that are indexed
150 by the regnum are used to represent that there is a killing def
151 for the register. The confluence and transfer functions use
152 these along with the bitmap_clear_range call to remove ranges of
153 bits without actually generating a knockout vector.
155 The kill and sparse_kill and the dense_invalidated_by_call and
156 sparse_invalidated_by_call both play this game. */
158 /* Private data used to compute the solution for this problem. These
159 data structures are not accessible outside of this module. */
160 struct df_rd_problem_data
162 /* The set of defs to regs invalidated by call. */
163 bitmap_head sparse_invalidated_by_call
;
164 /* The set of defs to regs invalidate by call for rd. */
165 bitmap_head dense_invalidated_by_call
;
166 /* An obstack for the bitmaps we need for this problem. */
167 bitmap_obstack rd_bitmaps
;
171 /* Free basic block info. */
174 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
177 struct df_rd_bb_info
*bb_info
= (struct df_rd_bb_info
*) vbb_info
;
180 bitmap_clear (&bb_info
->kill
);
181 bitmap_clear (&bb_info
->sparse_kill
);
182 bitmap_clear (&bb_info
->gen
);
183 bitmap_clear (&bb_info
->in
);
184 bitmap_clear (&bb_info
->out
);
189 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
190 not touched unless the block is new. */
193 df_rd_alloc (bitmap all_blocks
)
195 unsigned int bb_index
;
197 struct df_rd_problem_data
*problem_data
;
199 if (df_rd
->problem_data
)
201 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
202 bitmap_clear (&problem_data
->sparse_invalidated_by_call
);
203 bitmap_clear (&problem_data
->dense_invalidated_by_call
);
207 problem_data
= XNEW (struct df_rd_problem_data
);
208 df_rd
->problem_data
= problem_data
;
210 bitmap_obstack_initialize (&problem_data
->rd_bitmaps
);
211 bitmap_initialize (&problem_data
->sparse_invalidated_by_call
,
212 &problem_data
->rd_bitmaps
);
213 bitmap_initialize (&problem_data
->dense_invalidated_by_call
,
214 &problem_data
->rd_bitmaps
);
217 df_grow_bb_info (df_rd
);
219 /* Because of the clustering of all use sites for the same pseudo,
220 we have to process all of the blocks before doing the analysis. */
222 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
224 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
226 /* When bitmaps are already initialized, just clear them. */
227 if (bb_info
->kill
.obstack
)
229 bitmap_clear (&bb_info
->kill
);
230 bitmap_clear (&bb_info
->sparse_kill
);
231 bitmap_clear (&bb_info
->gen
);
235 bitmap_initialize (&bb_info
->kill
, &problem_data
->rd_bitmaps
);
236 bitmap_initialize (&bb_info
->sparse_kill
, &problem_data
->rd_bitmaps
);
237 bitmap_initialize (&bb_info
->gen
, &problem_data
->rd_bitmaps
);
238 bitmap_initialize (&bb_info
->in
, &problem_data
->rd_bitmaps
);
239 bitmap_initialize (&bb_info
->out
, &problem_data
->rd_bitmaps
);
242 df_rd
->optional_p
= true;
246 /* Add the effect of the top artificial defs of BB to the reaching definitions
250 df_rd_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_rd
)
252 int bb_index
= bb
->index
;
254 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
255 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
257 unsigned int dregno
= DF_REF_REGNO (def
);
258 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
259 bitmap_clear_range (local_rd
,
260 DF_DEFS_BEGIN (dregno
),
261 DF_DEFS_COUNT (dregno
));
262 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
266 /* Add the effect of the defs of INSN to the reaching definitions bitmap
270 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx_insn
*insn
,
275 FOR_EACH_INSN_DEF (def
, insn
)
277 unsigned int dregno
= DF_REF_REGNO (def
);
278 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
279 || (dregno
>= FIRST_PSEUDO_REGISTER
))
281 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
282 bitmap_clear_range (local_rd
,
283 DF_DEFS_BEGIN (dregno
),
284 DF_DEFS_COUNT (dregno
));
285 if (!(DF_REF_FLAGS (def
)
286 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
287 bitmap_set_bit (local_rd
, DF_REF_ID (def
));
292 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
293 more complicated than just simulating, because we must produce the
294 gen and kill sets and hence deal with the two possible representations
298 df_rd_bb_local_compute_process_def (struct df_rd_bb_info
*bb_info
,
302 for (; def
; def
= DF_REF_NEXT_LOC (def
))
304 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
306 unsigned int regno
= DF_REF_REGNO (def
);
307 unsigned int begin
= DF_DEFS_BEGIN (regno
);
308 unsigned int n_defs
= DF_DEFS_COUNT (regno
);
310 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
311 || (regno
>= FIRST_PSEUDO_REGISTER
))
313 /* Only the last def(s) for a regno in the block has any
315 if (!bitmap_bit_p (&seen_in_block
, regno
))
317 /* The first def for regno in insn gets to knock out the
318 defs from other instructions. */
319 if ((!bitmap_bit_p (&seen_in_insn
, regno
))
320 /* If the def is to only part of the reg, it does
321 not kill the other defs that reach here. */
322 && (!(DF_REF_FLAGS (def
) &
323 (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))))
325 if (n_defs
> DF_SPARSE_THRESHOLD
)
327 bitmap_set_bit (&bb_info
->sparse_kill
, regno
);
328 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
332 bitmap_set_range (&bb_info
->kill
, begin
, n_defs
);
333 bitmap_clear_range (&bb_info
->gen
, begin
, n_defs
);
337 bitmap_set_bit (&seen_in_insn
, regno
);
338 /* All defs for regno in the instruction may be put into
340 if (!(DF_REF_FLAGS (def
)
341 & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
342 bitmap_set_bit (&bb_info
->gen
, DF_REF_ID (def
));
349 /* Compute local reaching def info for basic block BB. */
352 df_rd_bb_local_compute (unsigned int bb_index
)
354 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
355 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
358 bitmap_clear (&seen_in_block
);
359 bitmap_clear (&seen_in_insn
);
361 /* Artificials are only hard regs. */
362 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
363 df_rd_bb_local_compute_process_def (bb_info
,
364 df_get_artificial_defs (bb_index
),
367 FOR_BB_INSNS_REVERSE (bb
, insn
)
369 unsigned int uid
= INSN_UID (insn
);
374 df_rd_bb_local_compute_process_def (bb_info
,
375 DF_INSN_UID_DEFS (uid
), 0);
377 /* This complex dance with the two bitmaps is required because
378 instructions can assign twice to the same pseudo. This
379 generally happens with calls that will have one def for the
380 result and another def for the clobber. If only one vector
381 is used and the clobber goes first, the result will be
383 bitmap_ior_into (&seen_in_block
, &seen_in_insn
);
384 bitmap_clear (&seen_in_insn
);
387 /* Process the artificial defs at the top of the block last since we
388 are going backwards through the block and these are logically at
390 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
391 df_rd_bb_local_compute_process_def (bb_info
,
392 df_get_artificial_defs (bb_index
),
397 /* Compute local reaching def info for each basic block within BLOCKS. */
400 df_rd_local_compute (bitmap all_blocks
)
402 unsigned int bb_index
;
405 struct df_rd_problem_data
*problem_data
406 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
407 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
408 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
410 bitmap_initialize (&seen_in_block
, &df_bitmap_obstack
);
411 bitmap_initialize (&seen_in_insn
, &df_bitmap_obstack
);
413 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG
);
415 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
417 df_rd_bb_local_compute (bb_index
);
420 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
421 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset
, 0, regno
, bi
)
423 if (! HARD_REGISTER_NUM_P (regno
)
424 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
426 if (DF_DEFS_COUNT (regno
) > DF_SPARSE_THRESHOLD
)
427 bitmap_set_bit (sparse_invalidated
, regno
);
429 bitmap_set_range (dense_invalidated
,
430 DF_DEFS_BEGIN (regno
),
431 DF_DEFS_COUNT (regno
));
435 bitmap_clear (&seen_in_block
);
436 bitmap_clear (&seen_in_insn
);
440 /* Initialize the solution bit vectors for problem. */
443 df_rd_init_solution (bitmap all_blocks
)
445 unsigned int bb_index
;
448 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
450 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
452 bitmap_copy (&bb_info
->out
, &bb_info
->gen
);
453 bitmap_clear (&bb_info
->in
);
457 /* In of target gets or of out of source. */
460 df_rd_confluence_n (edge e
)
462 bitmap op1
= &df_rd_get_bb_info (e
->dest
->index
)->in
;
463 bitmap op2
= &df_rd_get_bb_info (e
->src
->index
)->out
;
464 bool changed
= false;
466 if (e
->flags
& EDGE_FAKE
)
469 if (e
->flags
& EDGE_EH
)
471 struct df_rd_problem_data
*problem_data
472 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
473 bitmap sparse_invalidated
= &problem_data
->sparse_invalidated_by_call
;
474 bitmap dense_invalidated
= &problem_data
->dense_invalidated_by_call
;
479 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
480 bitmap_and_compl (&tmp
, op2
, dense_invalidated
);
482 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
484 bitmap_clear_range (&tmp
,
485 DF_DEFS_BEGIN (regno
),
486 DF_DEFS_COUNT (regno
));
488 changed
|= bitmap_ior_into (op1
, &tmp
);
493 return bitmap_ior_into (op1
, op2
);
497 /* Transfer function. */
500 df_rd_transfer_function (int bb_index
)
502 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
505 bitmap in
= &bb_info
->in
;
506 bitmap out
= &bb_info
->out
;
507 bitmap gen
= &bb_info
->gen
;
508 bitmap kill
= &bb_info
->kill
;
509 bitmap sparse_kill
= &bb_info
->sparse_kill
;
510 bool changed
= false;
512 if (bitmap_empty_p (sparse_kill
))
513 changed
= bitmap_ior_and_compl (out
, gen
, in
, kill
);
516 struct df_rd_problem_data
*problem_data
;
519 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
520 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
521 problem_data
= (struct df_rd_problem_data
*) df_rd
->problem_data
;
522 bitmap_initialize (&tmp
, &problem_data
->rd_bitmaps
);
524 bitmap_and_compl (&tmp
, in
, kill
);
525 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
527 bitmap_clear_range (&tmp
,
528 DF_DEFS_BEGIN (regno
),
529 DF_DEFS_COUNT (regno
));
531 bitmap_ior_into (&tmp
, gen
);
532 changed
= !bitmap_equal_p (&tmp
, out
);
542 if (df
->changeable_flags
& DF_RD_PRUNE_DEAD_DEFS
)
544 /* Create a mask of DEFs for all registers live at the end of this
545 basic block, and mask out DEFs of registers that are not live.
546 Computing the mask looks costly, but the benefit of the pruning
547 outweighs the cost. */
548 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
549 bitmap regs_live_out
= &df_lr_get_bb_info (bb_index
)->out
;
550 bitmap live_defs
= BITMAP_ALLOC (&df_bitmap_obstack
);
554 EXECUTE_IF_SET_IN_BITMAP (regs_live_out
, 0, regno
, bi
)
555 bitmap_set_range (live_defs
,
556 DF_DEFS_BEGIN (regno
),
557 DF_DEFS_COUNT (regno
));
558 changed
|= bitmap_and_into (&bb_info
->out
, live_defs
);
559 BITMAP_FREE (live_defs
);
565 /* Free all storage associated with the problem. */
570 struct df_rd_problem_data
*problem_data
571 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
575 bitmap_obstack_release (&problem_data
->rd_bitmaps
);
577 df_rd
->block_info_size
= 0;
578 free (df_rd
->block_info
);
579 df_rd
->block_info
= NULL
;
580 free (df_rd
->problem_data
);
586 /* Debugging info. */
589 df_rd_start_dump (FILE *file
)
591 struct df_rd_problem_data
*problem_data
592 = (struct df_rd_problem_data
*) df_rd
->problem_data
;
593 unsigned int m
= DF_REG_SIZE (df
);
596 if (!df_rd
->block_info
)
599 fprintf (file
, ";; Reaching defs:\n");
601 fprintf (file
, ";; sparse invalidated \t");
602 dump_bitmap (file
, &problem_data
->sparse_invalidated_by_call
);
603 fprintf (file
, ";; dense invalidated \t");
604 dump_bitmap (file
, &problem_data
->dense_invalidated_by_call
);
606 fprintf (file
, ";; reg->defs[] map:\t");
607 for (regno
= 0; regno
< m
; regno
++)
608 if (DF_DEFS_COUNT (regno
))
609 fprintf (file
, "%d[%d,%d] ", regno
,
610 DF_DEFS_BEGIN (regno
),
611 DF_DEFS_BEGIN (regno
) + DF_DEFS_COUNT (regno
) - 1);
612 fprintf (file
, "\n");
617 df_rd_dump_defs_set (bitmap defs_set
, const char *prefix
, FILE *file
)
621 unsigned int m
= DF_REG_SIZE (df
);
622 bool first_reg
= true;
624 fprintf (file
, "%s\t(%d) ", prefix
, (int) bitmap_count_bits (defs_set
));
626 bitmap_initialize (&tmp
, &df_bitmap_obstack
);
627 for (regno
= 0; regno
< m
; regno
++)
629 if (HARD_REGISTER_NUM_P (regno
)
630 && (df
->changeable_flags
& DF_NO_HARD_REGS
))
632 bitmap_set_range (&tmp
, DF_DEFS_BEGIN (regno
), DF_DEFS_COUNT (regno
));
633 bitmap_and_into (&tmp
, defs_set
);
634 if (! bitmap_empty_p (&tmp
))
638 bool first_def
= true;
644 fprintf (file
, "%u[", regno
);
645 EXECUTE_IF_SET_IN_BITMAP (&tmp
, 0, ix
, bi
)
647 fprintf (file
, "%s%u", first_def
? "" : ",", ix
);
655 fprintf (file
, "\n");
659 /* Debugging info at top of bb. */
662 df_rd_top_dump (basic_block bb
, FILE *file
)
664 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
668 df_rd_dump_defs_set (&bb_info
->in
, ";; rd in ", file
);
669 df_rd_dump_defs_set (&bb_info
->gen
, ";; rd gen ", file
);
670 df_rd_dump_defs_set (&bb_info
->kill
, ";; rd kill", file
);
674 /* Debugging info at bottom of bb. */
677 df_rd_bottom_dump (basic_block bb
, FILE *file
)
679 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb
->index
);
683 df_rd_dump_defs_set (&bb_info
->out
, ";; rd out ", file
);
686 /* All of the information associated with every instance of the problem. */
688 static struct df_problem problem_RD
=
690 DF_RD
, /* Problem id. */
691 DF_FORWARD
, /* Direction. */
692 df_rd_alloc
, /* Allocate the problem specific data. */
693 NULL
, /* Reset global information. */
694 df_rd_free_bb_info
, /* Free basic block info. */
695 df_rd_local_compute
, /* Local compute function. */
696 df_rd_init_solution
, /* Init the solution specific data. */
697 df_worklist_dataflow
, /* Worklist solver. */
698 NULL
, /* Confluence operator 0. */
699 df_rd_confluence_n
, /* Confluence operator n. */
700 df_rd_transfer_function
, /* Transfer function. */
701 NULL
, /* Finalize function. */
702 df_rd_free
, /* Free all of the problem information. */
703 df_rd_free
, /* Remove this problem from the stack of dataflow problems. */
704 df_rd_start_dump
, /* Debugging. */
705 df_rd_top_dump
, /* Debugging start block. */
706 df_rd_bottom_dump
, /* Debugging end block. */
707 NULL
, /* Debugging start insn. */
708 NULL
, /* Debugging end insn. */
709 NULL
, /* Incremental solution verify start. */
710 NULL
, /* Incremental solution verify end. */
711 NULL
, /* Dependent problem. */
712 sizeof (struct df_rd_bb_info
),/* Size of entry of block_info array. */
713 TV_DF_RD
, /* Timing variable. */
714 true /* Reset blocks on dropping out of blocks_to_analyze. */
719 /* Create a new RD instance and add it to the existing instance
723 df_rd_add_problem (void)
725 df_add_problem (&problem_RD
);
730 /*----------------------------------------------------------------------------
733 Find the locations in the function where any use of a pseudo can
734 reach in the backwards direction. In and out bitvectors are built
735 for each basic block. The regno is used to index into these sets.
736 See df.h for details.
737 ----------------------------------------------------------------------------*/
739 /* Private data used to verify the solution for this problem. */
740 struct df_lr_problem_data
744 /* An obstack for the bitmaps we need for this problem. */
745 bitmap_obstack lr_bitmaps
;
748 /* Free basic block info. */
751 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
754 struct df_lr_bb_info
*bb_info
= (struct df_lr_bb_info
*) vbb_info
;
757 bitmap_clear (&bb_info
->use
);
758 bitmap_clear (&bb_info
->def
);
759 bitmap_clear (&bb_info
->in
);
760 bitmap_clear (&bb_info
->out
);
765 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
766 not touched unless the block is new. */
769 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
771 unsigned int bb_index
;
773 struct df_lr_problem_data
*problem_data
;
775 df_grow_bb_info (df_lr
);
776 if (df_lr
->problem_data
)
777 problem_data
= (struct df_lr_problem_data
*) df_lr
->problem_data
;
780 problem_data
= XNEW (struct df_lr_problem_data
);
781 df_lr
->problem_data
= problem_data
;
783 problem_data
->out
= NULL
;
784 problem_data
->in
= NULL
;
785 bitmap_obstack_initialize (&problem_data
->lr_bitmaps
);
788 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
790 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
792 /* When bitmaps are already initialized, just clear them. */
793 if (bb_info
->use
.obstack
)
795 bitmap_clear (&bb_info
->def
);
796 bitmap_clear (&bb_info
->use
);
800 bitmap_initialize (&bb_info
->use
, &problem_data
->lr_bitmaps
);
801 bitmap_initialize (&bb_info
->def
, &problem_data
->lr_bitmaps
);
802 bitmap_initialize (&bb_info
->in
, &problem_data
->lr_bitmaps
);
803 bitmap_initialize (&bb_info
->out
, &problem_data
->lr_bitmaps
);
807 df_lr
->optional_p
= false;
811 /* Reset the global solution for recalculation. */
814 df_lr_reset (bitmap all_blocks
)
816 unsigned int bb_index
;
819 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
821 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
822 gcc_assert (bb_info
);
823 bitmap_clear (&bb_info
->in
);
824 bitmap_clear (&bb_info
->out
);
829 /* Compute local live register info for basic block BB. */
832 df_lr_bb_local_compute (unsigned int bb_index
)
834 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
835 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
839 /* Process the registers set in an exception handler. */
840 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
841 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
843 unsigned int dregno
= DF_REF_REGNO (def
);
844 bitmap_set_bit (&bb_info
->def
, dregno
);
845 bitmap_clear_bit (&bb_info
->use
, dregno
);
848 /* Process the hardware registers that are always live. */
849 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
850 /* Add use to set of uses in this BB. */
851 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
852 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
854 FOR_BB_INSNS_REVERSE (bb
, insn
)
856 if (!NONDEBUG_INSN_P (insn
))
859 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
860 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
861 /* If the def is to only part of the reg, it does
862 not kill the other defs that reach here. */
863 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
865 unsigned int dregno
= DF_REF_REGNO (def
);
866 bitmap_set_bit (&bb_info
->def
, dregno
);
867 bitmap_clear_bit (&bb_info
->use
, dregno
);
870 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
871 /* Add use to set of uses in this BB. */
872 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
875 /* Process the registers set in an exception handler or the hard
876 frame pointer if this block is the target of a non local
878 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
879 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
881 unsigned int dregno
= DF_REF_REGNO (def
);
882 bitmap_set_bit (&bb_info
->def
, dregno
);
883 bitmap_clear_bit (&bb_info
->use
, dregno
);
887 /* Process the uses that are live into an exception handler. */
888 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
889 /* Add use to set of uses in this BB. */
890 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
891 bitmap_set_bit (&bb_info
->use
, DF_REF_REGNO (use
));
894 /* If the df_live problem is not defined, such as at -O0 and -O1, we
895 still need to keep the luids up to date. This is normally done
896 in the df_live problem since this problem has a forwards
899 df_recompute_luids (bb
);
903 /* Compute local live register info for each basic block within BLOCKS. */
906 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
908 unsigned int bb_index
, i
;
911 bitmap_clear (&df
->hardware_regs_used
);
913 /* The all-important stack pointer must always be live. */
914 bitmap_set_bit (&df
->hardware_regs_used
, STACK_POINTER_REGNUM
);
916 /* Global regs are always live, too. */
917 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
919 bitmap_set_bit (&df
->hardware_regs_used
, i
);
921 /* Before reload, there are a few registers that must be forced
922 live everywhere -- which might not already be the case for
923 blocks within infinite loops. */
924 if (!reload_completed
)
926 unsigned int pic_offset_table_regnum
= PIC_OFFSET_TABLE_REGNUM
;
927 /* Any reference to any pseudo before reload is a potential
928 reference of the frame pointer. */
929 bitmap_set_bit (&df
->hardware_regs_used
, FRAME_POINTER_REGNUM
);
931 /* Pseudos with argument area equivalences may require
932 reloading via the argument pointer. */
933 if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
934 && fixed_regs
[ARG_POINTER_REGNUM
])
935 bitmap_set_bit (&df
->hardware_regs_used
, ARG_POINTER_REGNUM
);
937 /* Any constant, or pseudo with constant equivalences, may
938 require reloading from memory using the pic register. */
939 if (pic_offset_table_regnum
!= INVALID_REGNUM
940 && fixed_regs
[pic_offset_table_regnum
])
941 bitmap_set_bit (&df
->hardware_regs_used
, pic_offset_table_regnum
);
944 EXECUTE_IF_SET_IN_BITMAP (df_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
946 if (bb_index
== EXIT_BLOCK
)
948 /* The exit block is special for this problem and its bits are
949 computed from thin air. */
950 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (EXIT_BLOCK
);
951 bitmap_copy (&bb_info
->use
, df
->exit_block_uses
);
954 df_lr_bb_local_compute (bb_index
);
957 bitmap_clear (df_lr
->out_of_date_transfer_functions
);
961 /* Initialize the solution vectors. */
964 df_lr_init (bitmap all_blocks
)
966 unsigned int bb_index
;
969 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
971 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
972 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
973 bitmap_clear (&bb_info
->out
);
978 /* Confluence function that processes infinite loops. This might be a
979 noreturn function that throws. And even if it isn't, getting the
980 unwind info right helps debugging. */
982 df_lr_confluence_0 (basic_block bb
)
984 bitmap op1
= &df_lr_get_bb_info (bb
->index
)->out
;
985 if (bb
!= EXIT_BLOCK_PTR_FOR_FN (cfun
))
986 bitmap_copy (op1
, &df
->hardware_regs_used
);
990 /* Confluence function that ignores fake edges. */
993 df_lr_confluence_n (edge e
)
995 bitmap op1
= &df_lr_get_bb_info (e
->src
->index
)->out
;
996 bitmap op2
= &df_lr_get_bb_info (e
->dest
->index
)->in
;
997 bool changed
= false;
999 /* Call-clobbered registers die across exception and call edges. */
1000 /* ??? Abnormal call edges ignored for the moment, as this gets
1001 confused by sibling call edges, which crashes reg-stack. */
1002 if (e
->flags
& EDGE_EH
)
1003 changed
= bitmap_ior_and_compl_into (op1
, op2
, regs_invalidated_by_call_regset
);
1005 changed
= bitmap_ior_into (op1
, op2
);
1007 changed
|= bitmap_ior_into (op1
, &df
->hardware_regs_used
);
1012 /* Transfer function. */
1015 df_lr_transfer_function (int bb_index
)
1017 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb_index
);
1018 bitmap in
= &bb_info
->in
;
1019 bitmap out
= &bb_info
->out
;
1020 bitmap use
= &bb_info
->use
;
1021 bitmap def
= &bb_info
->def
;
1023 return bitmap_ior_and_compl (in
, use
, out
, def
);
1027 /* Run the fast dce as a side effect of building LR. */
1030 df_lr_finalize (bitmap all_blocks
)
1032 df_lr
->solutions_dirty
= false;
1033 if (df
->changeable_flags
& DF_LR_RUN_DCE
)
1037 /* If dce deletes some instructions, we need to recompute the lr
1038 solution before proceeding further. The problem is that fast
1039 dce is a pessimestic dataflow algorithm. In the case where
1040 it deletes a statement S inside of a loop, the uses inside of
1041 S may not be deleted from the dataflow solution because they
1042 were carried around the loop. While it is conservatively
1043 correct to leave these extra bits, the standards of df
1044 require that we maintain the best possible (least fixed
1045 point) solution. The only way to do that is to redo the
1046 iteration from the beginning. See PR35805 for an
1048 if (df_lr
->solutions_dirty
)
1050 df_clear_flags (DF_LR_RUN_DCE
);
1051 df_lr_alloc (all_blocks
);
1052 df_lr_local_compute (all_blocks
);
1053 df_worklist_dataflow (df_lr
, all_blocks
, df
->postorder
, df
->n_blocks
);
1054 df_lr_finalize (all_blocks
);
1055 df_set_flags (DF_LR_RUN_DCE
);
1061 /* Free all storage associated with the problem. */
1066 struct df_lr_problem_data
*problem_data
1067 = (struct df_lr_problem_data
*) df_lr
->problem_data
;
1068 if (df_lr
->block_info
)
1071 df_lr
->block_info_size
= 0;
1072 free (df_lr
->block_info
);
1073 df_lr
->block_info
= NULL
;
1074 bitmap_obstack_release (&problem_data
->lr_bitmaps
);
1075 free (df_lr
->problem_data
);
1076 df_lr
->problem_data
= NULL
;
1079 BITMAP_FREE (df_lr
->out_of_date_transfer_functions
);
1084 /* Debugging info at top of bb. */
1087 df_lr_top_dump (basic_block bb
, FILE *file
)
1089 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1090 struct df_lr_problem_data
*problem_data
;
1094 fprintf (file
, ";; lr in \t");
1095 df_print_regset (file
, &bb_info
->in
);
1096 if (df_lr
->problem_data
)
1098 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1099 if (problem_data
->in
)
1101 fprintf (file
, ";; old in \t");
1102 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1105 fprintf (file
, ";; lr use \t");
1106 df_print_regset (file
, &bb_info
->use
);
1107 fprintf (file
, ";; lr def \t");
1108 df_print_regset (file
, &bb_info
->def
);
1112 /* Debugging info at bottom of bb. */
1115 df_lr_bottom_dump (basic_block bb
, FILE *file
)
1117 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1118 struct df_lr_problem_data
*problem_data
;
1122 fprintf (file
, ";; lr out \t");
1123 df_print_regset (file
, &bb_info
->out
);
1124 if (df_lr
->problem_data
)
1126 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1127 if (problem_data
->out
)
1129 fprintf (file
, ";; old out \t");
1130 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1136 /* Build the datastructure to verify that the solution to the dataflow
1137 equations is not dirty. */
1140 df_lr_verify_solution_start (void)
1143 struct df_lr_problem_data
*problem_data
;
1144 if (df_lr
->solutions_dirty
)
1147 /* Set it true so that the solution is recomputed. */
1148 df_lr
->solutions_dirty
= true;
1150 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1151 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1152 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1154 FOR_ALL_BB_FN (bb
, cfun
)
1156 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->lr_bitmaps
);
1157 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->lr_bitmaps
);
1158 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
));
1159 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
));
1164 /* Compare the saved datastructure and the new solution to the dataflow
1168 df_lr_verify_solution_end (void)
1170 struct df_lr_problem_data
*problem_data
;
1173 problem_data
= (struct df_lr_problem_data
*)df_lr
->problem_data
;
1175 if (!problem_data
->out
)
1178 if (df_lr
->solutions_dirty
)
1179 /* Do not check if the solution is still dirty. See the comment
1180 in df_lr_finalize for details. */
1181 df_lr
->solutions_dirty
= false;
1183 FOR_ALL_BB_FN (bb
, cfun
)
1185 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LR_IN (bb
)))
1186 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LR_OUT (bb
))))
1188 /*df_dump (stderr);*/
1193 /* Cannot delete them immediately because you may want to dump them
1194 if the comparison fails. */
1195 FOR_ALL_BB_FN (bb
, cfun
)
1197 bitmap_clear (&problem_data
->in
[bb
->index
]);
1198 bitmap_clear (&problem_data
->out
[bb
->index
]);
1201 free (problem_data
->in
);
1202 free (problem_data
->out
);
1203 problem_data
->in
= NULL
;
1204 problem_data
->out
= NULL
;
1208 /* All of the information associated with every instance of the problem. */
1210 static struct df_problem problem_LR
=
1212 DF_LR
, /* Problem id. */
1213 DF_BACKWARD
, /* Direction. */
1214 df_lr_alloc
, /* Allocate the problem specific data. */
1215 df_lr_reset
, /* Reset global information. */
1216 df_lr_free_bb_info
, /* Free basic block info. */
1217 df_lr_local_compute
, /* Local compute function. */
1218 df_lr_init
, /* Init the solution specific data. */
1219 df_worklist_dataflow
, /* Worklist solver. */
1220 df_lr_confluence_0
, /* Confluence operator 0. */
1221 df_lr_confluence_n
, /* Confluence operator n. */
1222 df_lr_transfer_function
, /* Transfer function. */
1223 df_lr_finalize
, /* Finalize function. */
1224 df_lr_free
, /* Free all of the problem information. */
1225 NULL
, /* Remove this problem from the stack of dataflow problems. */
1226 NULL
, /* Debugging. */
1227 df_lr_top_dump
, /* Debugging start block. */
1228 df_lr_bottom_dump
, /* Debugging end block. */
1229 NULL
, /* Debugging start insn. */
1230 NULL
, /* Debugging end insn. */
1231 df_lr_verify_solution_start
,/* Incremental solution verify start. */
1232 df_lr_verify_solution_end
, /* Incremental solution verify end. */
1233 NULL
, /* Dependent problem. */
1234 sizeof (struct df_lr_bb_info
),/* Size of entry of block_info array. */
1235 TV_DF_LR
, /* Timing variable. */
1236 false /* Reset blocks on dropping out of blocks_to_analyze. */
1240 /* Create a new DATAFLOW instance and add it to an existing instance
1241 of DF. The returned structure is what is used to get at the
1245 df_lr_add_problem (void)
1247 df_add_problem (&problem_LR
);
1248 /* These will be initialized when df_scan_blocks processes each
1250 df_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1254 /* Verify that all of the lr related info is consistent and
1258 df_lr_verify_transfer_functions (void)
1261 bitmap_head saved_def
;
1262 bitmap_head saved_use
;
1263 bitmap_head all_blocks
;
1268 bitmap_initialize (&saved_def
, &bitmap_default_obstack
);
1269 bitmap_initialize (&saved_use
, &bitmap_default_obstack
);
1270 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1272 FOR_ALL_BB_FN (bb
, cfun
)
1274 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (bb
->index
);
1275 bitmap_set_bit (&all_blocks
, bb
->index
);
1279 /* Make a copy of the transfer functions and then compute
1280 new ones to see if the transfer functions have
1282 if (!bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1285 bitmap_copy (&saved_def
, &bb_info
->def
);
1286 bitmap_copy (&saved_use
, &bb_info
->use
);
1287 bitmap_clear (&bb_info
->def
);
1288 bitmap_clear (&bb_info
->use
);
1290 df_lr_bb_local_compute (bb
->index
);
1291 gcc_assert (bitmap_equal_p (&saved_def
, &bb_info
->def
));
1292 gcc_assert (bitmap_equal_p (&saved_use
, &bb_info
->use
));
1297 /* If we do not have basic block info, the block must be in
1298 the list of dirty blocks or else some one has added a
1299 block behind our backs. */
1300 gcc_assert (bitmap_bit_p (df_lr
->out_of_date_transfer_functions
,
1303 /* Make sure no one created a block without following
1305 gcc_assert (df_scan_get_bb_info (bb
->index
));
1308 /* Make sure there are no dirty bits in blocks that have been deleted. */
1309 gcc_assert (!bitmap_intersect_compl_p (df_lr
->out_of_date_transfer_functions
,
1312 bitmap_clear (&saved_def
);
1313 bitmap_clear (&saved_use
);
1314 bitmap_clear (&all_blocks
);
1319 /*----------------------------------------------------------------------------
1320 LIVE AND MUST-INITIALIZED REGISTERS.
1322 This problem first computes the IN and OUT bitvectors for the
1323 must-initialized registers problems, which is a forward problem.
1324 It gives the set of registers for which we MUST have an available
1325 definition on any path from the entry block to the entry/exit of
1326 a basic block. Sets generate a definition, while clobbers kill
1329 In and out bitvectors are built for each basic block and are indexed by
1330 regnum (see df.h for details). In and out bitvectors in struct
1331 df_live_bb_info actually refers to the must-initialized problem;
1333 Then, the in and out sets for the LIVE problem itself are computed.
1334 These are the logical AND of the IN and OUT sets from the LR problem
1335 and the must-initialized problem.
1336 ----------------------------------------------------------------------------*/
1338 /* Private data used to verify the solution for this problem. */
1339 struct df_live_problem_data
1343 /* An obstack for the bitmaps we need for this problem. */
1344 bitmap_obstack live_bitmaps
;
1347 /* Scratch var used by transfer functions. This is used to implement
1348 an optimization to reduce the amount of space used to compute the
1349 combined lr and live analysis. */
1350 static bitmap_head df_live_scratch
;
1353 /* Free basic block info. */
1356 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
1359 struct df_live_bb_info
*bb_info
= (struct df_live_bb_info
*) vbb_info
;
1362 bitmap_clear (&bb_info
->gen
);
1363 bitmap_clear (&bb_info
->kill
);
1364 bitmap_clear (&bb_info
->in
);
1365 bitmap_clear (&bb_info
->out
);
1370 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1371 not touched unless the block is new. */
1374 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
1376 unsigned int bb_index
;
1378 struct df_live_problem_data
*problem_data
;
1380 if (df_live
->problem_data
)
1381 problem_data
= (struct df_live_problem_data
*) df_live
->problem_data
;
1384 problem_data
= XNEW (struct df_live_problem_data
);
1385 df_live
->problem_data
= problem_data
;
1387 problem_data
->out
= NULL
;
1388 problem_data
->in
= NULL
;
1389 bitmap_obstack_initialize (&problem_data
->live_bitmaps
);
1390 bitmap_initialize (&df_live_scratch
, &problem_data
->live_bitmaps
);
1393 df_grow_bb_info (df_live
);
1395 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1397 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1399 /* When bitmaps are already initialized, just clear them. */
1400 if (bb_info
->kill
.obstack
)
1402 bitmap_clear (&bb_info
->kill
);
1403 bitmap_clear (&bb_info
->gen
);
1407 bitmap_initialize (&bb_info
->kill
, &problem_data
->live_bitmaps
);
1408 bitmap_initialize (&bb_info
->gen
, &problem_data
->live_bitmaps
);
1409 bitmap_initialize (&bb_info
->in
, &problem_data
->live_bitmaps
);
1410 bitmap_initialize (&bb_info
->out
, &problem_data
->live_bitmaps
);
1413 df_live
->optional_p
= (optimize
<= 1);
1417 /* Reset the global solution for recalculation. */
1420 df_live_reset (bitmap all_blocks
)
1422 unsigned int bb_index
;
1425 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1427 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1428 gcc_assert (bb_info
);
1429 bitmap_clear (&bb_info
->in
);
1430 bitmap_clear (&bb_info
->out
);
1435 /* Compute local uninitialized register info for basic block BB. */
1438 df_live_bb_local_compute (unsigned int bb_index
)
1440 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1441 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1446 FOR_BB_INSNS (bb
, insn
)
1448 unsigned int uid
= INSN_UID (insn
);
1449 struct df_insn_info
*insn_info
= DF_INSN_UID_GET (uid
);
1451 /* Inserting labels does not always trigger the incremental
1455 gcc_assert (!INSN_P (insn
));
1456 insn_info
= df_insn_create_insn_record (insn
);
1459 DF_INSN_INFO_LUID (insn_info
) = luid
;
1464 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1466 unsigned int regno
= DF_REF_REGNO (def
);
1468 if (DF_REF_FLAGS_IS_SET (def
,
1469 DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
1470 /* All partial or conditional def
1471 seen are included in the gen set. */
1472 bitmap_set_bit (&bb_info
->gen
, regno
);
1473 else if (DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
))
1474 /* Only must clobbers for the entire reg destroy the
1476 bitmap_set_bit (&bb_info
->kill
, regno
);
1477 else if (! DF_REF_FLAGS_IS_SET (def
, DF_REF_MAY_CLOBBER
))
1478 bitmap_set_bit (&bb_info
->gen
, regno
);
1482 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1483 bitmap_set_bit (&bb_info
->gen
, DF_REF_REGNO (def
));
1487 /* Compute local uninitialized register info. */
1490 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
1492 unsigned int bb_index
;
1495 df_grow_insn_info ();
1497 EXECUTE_IF_SET_IN_BITMAP (df_live
->out_of_date_transfer_functions
,
1500 df_live_bb_local_compute (bb_index
);
1503 bitmap_clear (df_live
->out_of_date_transfer_functions
);
1507 /* Initialize the solution vectors. */
1510 df_live_init (bitmap all_blocks
)
1512 unsigned int bb_index
;
1515 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1517 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1518 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1520 /* No register may reach a location where it is not used. Thus
1521 we trim the rr result to the places where it is used. */
1522 bitmap_and (&bb_info
->out
, &bb_info
->gen
, &bb_lr_info
->out
);
1523 bitmap_clear (&bb_info
->in
);
1527 /* Forward confluence function that ignores fake edges. */
1530 df_live_confluence_n (edge e
)
1532 bitmap op1
= &df_live_get_bb_info (e
->dest
->index
)->in
;
1533 bitmap op2
= &df_live_get_bb_info (e
->src
->index
)->out
;
1535 if (e
->flags
& EDGE_FAKE
)
1538 return bitmap_ior_into (op1
, op2
);
1542 /* Transfer function for the forwards must-initialized problem. */
1545 df_live_transfer_function (int bb_index
)
1547 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb_index
);
1548 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1549 bitmap in
= &bb_info
->in
;
1550 bitmap out
= &bb_info
->out
;
1551 bitmap gen
= &bb_info
->gen
;
1552 bitmap kill
= &bb_info
->kill
;
1554 /* We need to use a scratch set here so that the value returned from this
1555 function invocation properly reflects whether the sets changed in a
1556 significant way; i.e. not just because the lr set was anded in. */
1557 bitmap_and (&df_live_scratch
, gen
, &bb_lr_info
->out
);
1558 /* No register may reach a location where it is not used. Thus
1559 we trim the rr result to the places where it is used. */
1560 bitmap_and_into (in
, &bb_lr_info
->in
);
1562 return bitmap_ior_and_compl (out
, &df_live_scratch
, in
, kill
);
1566 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1569 df_live_finalize (bitmap all_blocks
)
1572 if (df_live
->solutions_dirty
)
1575 unsigned int bb_index
;
1577 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1579 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (bb_index
);
1580 struct df_live_bb_info
*bb_live_info
= df_live_get_bb_info (bb_index
);
1582 /* No register may reach a location where it is not used. Thus
1583 we trim the rr result to the places where it is used. */
1584 bitmap_and_into (&bb_live_info
->in
, &bb_lr_info
->in
);
1585 bitmap_and_into (&bb_live_info
->out
, &bb_lr_info
->out
);
1588 df_live
->solutions_dirty
= false;
1593 /* Free all storage associated with the problem. */
1598 struct df_live_problem_data
*problem_data
1599 = (struct df_live_problem_data
*) df_live
->problem_data
;
1600 if (df_live
->block_info
)
1602 df_live
->block_info_size
= 0;
1603 free (df_live
->block_info
);
1604 df_live
->block_info
= NULL
;
1605 bitmap_clear (&df_live_scratch
);
1606 bitmap_obstack_release (&problem_data
->live_bitmaps
);
1607 free (problem_data
);
1608 df_live
->problem_data
= NULL
;
1610 BITMAP_FREE (df_live
->out_of_date_transfer_functions
);
1615 /* Debugging info at top of bb. */
1618 df_live_top_dump (basic_block bb
, FILE *file
)
1620 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1621 struct df_live_problem_data
*problem_data
;
1626 fprintf (file
, ";; live in \t");
1627 df_print_regset (file
, &bb_info
->in
);
1628 if (df_live
->problem_data
)
1630 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1631 if (problem_data
->in
)
1633 fprintf (file
, ";; old in \t");
1634 df_print_regset (file
, &problem_data
->in
[bb
->index
]);
1637 fprintf (file
, ";; live gen \t");
1638 df_print_regset (file
, &bb_info
->gen
);
1639 fprintf (file
, ";; live kill\t");
1640 df_print_regset (file
, &bb_info
->kill
);
1644 /* Debugging info at bottom of bb. */
1647 df_live_bottom_dump (basic_block bb
, FILE *file
)
1649 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1650 struct df_live_problem_data
*problem_data
;
1655 fprintf (file
, ";; live out \t");
1656 df_print_regset (file
, &bb_info
->out
);
1657 if (df_live
->problem_data
)
1659 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1660 if (problem_data
->out
)
1662 fprintf (file
, ";; old out \t");
1663 df_print_regset (file
, &problem_data
->out
[bb
->index
]);
1669 /* Build the datastructure to verify that the solution to the dataflow
1670 equations is not dirty. */
1673 df_live_verify_solution_start (void)
1676 struct df_live_problem_data
*problem_data
;
1677 if (df_live
->solutions_dirty
)
1680 /* Set it true so that the solution is recomputed. */
1681 df_live
->solutions_dirty
= true;
1683 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1684 problem_data
->in
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1685 problem_data
->out
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
1687 FOR_ALL_BB_FN (bb
, cfun
)
1689 bitmap_initialize (&problem_data
->in
[bb
->index
], &problem_data
->live_bitmaps
);
1690 bitmap_initialize (&problem_data
->out
[bb
->index
], &problem_data
->live_bitmaps
);
1691 bitmap_copy (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
));
1692 bitmap_copy (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
));
1697 /* Compare the saved datastructure and the new solution to the dataflow
1701 df_live_verify_solution_end (void)
1703 struct df_live_problem_data
*problem_data
;
1706 problem_data
= (struct df_live_problem_data
*)df_live
->problem_data
;
1707 if (!problem_data
->out
)
1710 FOR_ALL_BB_FN (bb
, cfun
)
1712 if ((!bitmap_equal_p (&problem_data
->in
[bb
->index
], DF_LIVE_IN (bb
)))
1713 || (!bitmap_equal_p (&problem_data
->out
[bb
->index
], DF_LIVE_OUT (bb
))))
1715 /*df_dump (stderr);*/
1720 /* Cannot delete them immediately because you may want to dump them
1721 if the comparison fails. */
1722 FOR_ALL_BB_FN (bb
, cfun
)
1724 bitmap_clear (&problem_data
->in
[bb
->index
]);
1725 bitmap_clear (&problem_data
->out
[bb
->index
]);
1728 free (problem_data
->in
);
1729 free (problem_data
->out
);
1730 free (problem_data
);
1731 df_live
->problem_data
= NULL
;
1735 /* All of the information associated with every instance of the problem. */
1737 static struct df_problem problem_LIVE
=
1739 DF_LIVE
, /* Problem id. */
1740 DF_FORWARD
, /* Direction. */
1741 df_live_alloc
, /* Allocate the problem specific data. */
1742 df_live_reset
, /* Reset global information. */
1743 df_live_free_bb_info
, /* Free basic block info. */
1744 df_live_local_compute
, /* Local compute function. */
1745 df_live_init
, /* Init the solution specific data. */
1746 df_worklist_dataflow
, /* Worklist solver. */
1747 NULL
, /* Confluence operator 0. */
1748 df_live_confluence_n
, /* Confluence operator n. */
1749 df_live_transfer_function
, /* Transfer function. */
1750 df_live_finalize
, /* Finalize function. */
1751 df_live_free
, /* Free all of the problem information. */
1752 df_live_free
, /* Remove this problem from the stack of dataflow problems. */
1753 NULL
, /* Debugging. */
1754 df_live_top_dump
, /* Debugging start block. */
1755 df_live_bottom_dump
, /* Debugging end block. */
1756 NULL
, /* Debugging start insn. */
1757 NULL
, /* Debugging end insn. */
1758 df_live_verify_solution_start
,/* Incremental solution verify start. */
1759 df_live_verify_solution_end
, /* Incremental solution verify end. */
1760 &problem_LR
, /* Dependent problem. */
1761 sizeof (struct df_live_bb_info
),/* Size of entry of block_info array. */
1762 TV_DF_LIVE
, /* Timing variable. */
1763 false /* Reset blocks on dropping out of blocks_to_analyze. */
1767 /* Create a new DATAFLOW instance and add it to an existing instance
1768 of DF. The returned structure is what is used to get at the
1772 df_live_add_problem (void)
1774 df_add_problem (&problem_LIVE
);
1775 /* These will be initialized when df_scan_blocks processes each
1777 df_live
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
1781 /* Set all of the blocks as dirty. This needs to be done if this
1782 problem is added after all of the insns have been scanned. */
1785 df_live_set_all_dirty (void)
1788 FOR_ALL_BB_FN (bb
, cfun
)
1789 bitmap_set_bit (df_live
->out_of_date_transfer_functions
,
1794 /* Verify that all of the lr related info is consistent and
1798 df_live_verify_transfer_functions (void)
1801 bitmap_head saved_gen
;
1802 bitmap_head saved_kill
;
1803 bitmap_head all_blocks
;
1808 bitmap_initialize (&saved_gen
, &bitmap_default_obstack
);
1809 bitmap_initialize (&saved_kill
, &bitmap_default_obstack
);
1810 bitmap_initialize (&all_blocks
, &bitmap_default_obstack
);
1812 df_grow_insn_info ();
1814 FOR_ALL_BB_FN (bb
, cfun
)
1816 struct df_live_bb_info
*bb_info
= df_live_get_bb_info (bb
->index
);
1817 bitmap_set_bit (&all_blocks
, bb
->index
);
1821 /* Make a copy of the transfer functions and then compute
1822 new ones to see if the transfer functions have
1824 if (!bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1827 bitmap_copy (&saved_gen
, &bb_info
->gen
);
1828 bitmap_copy (&saved_kill
, &bb_info
->kill
);
1829 bitmap_clear (&bb_info
->gen
);
1830 bitmap_clear (&bb_info
->kill
);
1832 df_live_bb_local_compute (bb
->index
);
1833 gcc_assert (bitmap_equal_p (&saved_gen
, &bb_info
->gen
));
1834 gcc_assert (bitmap_equal_p (&saved_kill
, &bb_info
->kill
));
1839 /* If we do not have basic block info, the block must be in
1840 the list of dirty blocks or else some one has added a
1841 block behind our backs. */
1842 gcc_assert (bitmap_bit_p (df_live
->out_of_date_transfer_functions
,
1845 /* Make sure no one created a block without following
1847 gcc_assert (df_scan_get_bb_info (bb
->index
));
1850 /* Make sure there are no dirty bits in blocks that have been deleted. */
1851 gcc_assert (!bitmap_intersect_compl_p (df_live
->out_of_date_transfer_functions
,
1853 bitmap_clear (&saved_gen
);
1854 bitmap_clear (&saved_kill
);
1855 bitmap_clear (&all_blocks
);
1858 /*----------------------------------------------------------------------------
1859 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1861 Link either the defs to the uses and / or the uses to the defs.
1863 These problems are set up like the other dataflow problems so that
1864 they nicely fit into the framework. They are much simpler and only
1865 involve a single traversal of instructions and an examination of
1866 the reaching defs information (the dependent problem).
1867 ----------------------------------------------------------------------------*/
1869 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1871 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1874 df_chain_create (df_ref src
, df_ref dst
)
1876 struct df_link
*head
= DF_REF_CHAIN (src
);
1877 struct df_link
*link
= df_chain
->block_pool
->allocate ();
1879 DF_REF_CHAIN (src
) = link
;
1886 /* Delete any du or ud chains that start at REF and point to
1889 df_chain_unlink_1 (df_ref ref
, df_ref target
)
1891 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1892 struct df_link
*prev
= NULL
;
1896 if (chain
->ref
== target
)
1899 prev
->next
= chain
->next
;
1901 DF_REF_CHAIN (ref
) = chain
->next
;
1902 df_chain
->block_pool
->remove (chain
);
1906 chain
= chain
->next
;
1911 /* Delete a du or ud chain that leave or point to REF. */
1914 df_chain_unlink (df_ref ref
)
1916 struct df_link
*chain
= DF_REF_CHAIN (ref
);
1919 struct df_link
*next
= chain
->next
;
1920 /* Delete the other side if it exists. */
1921 df_chain_unlink_1 (chain
->ref
, ref
);
1922 df_chain
->block_pool
->remove (chain
);
1925 DF_REF_CHAIN (ref
) = NULL
;
1929 /* Copy the du or ud chain starting at FROM_REF and attach it to
1933 df_chain_copy (df_ref to_ref
,
1934 struct df_link
*from_ref
)
1938 df_chain_create (to_ref
, from_ref
->ref
);
1939 from_ref
= from_ref
->next
;
1944 /* Remove this problem from the stack of dataflow problems. */
1947 df_chain_remove_problem (void)
1950 unsigned int bb_index
;
1952 /* Wholesale destruction of the old chains. */
1953 if (df_chain
->block_pool
)
1954 delete df_chain
->block_pool
;
1956 EXECUTE_IF_SET_IN_BITMAP (df_chain
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
1960 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
1962 if (df_chain_problem_p (DF_DU_CHAIN
))
1963 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
1964 DF_REF_CHAIN (def
) = NULL
;
1965 if (df_chain_problem_p (DF_UD_CHAIN
))
1966 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
1967 DF_REF_CHAIN (use
) = NULL
;
1969 FOR_BB_INSNS (bb
, insn
)
1972 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
1973 if (df_chain_problem_p (DF_DU_CHAIN
))
1974 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
1975 DF_REF_CHAIN (def
) = NULL
;
1976 if (df_chain_problem_p (DF_UD_CHAIN
))
1978 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
1979 DF_REF_CHAIN (use
) = NULL
;
1980 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
1981 DF_REF_CHAIN (use
) = NULL
;
1986 bitmap_clear (df_chain
->out_of_date_transfer_functions
);
1987 df_chain
->block_pool
= NULL
;
1991 /* Remove the chain problem completely. */
1994 df_chain_fully_remove_problem (void)
1996 df_chain_remove_problem ();
1997 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
2002 /* Create def-use or use-def chains. */
2005 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2007 df_chain_remove_problem ();
2008 df_chain
->block_pool
= new pool_allocator
<df_link
> ("df_chain_block pool",
2010 df_chain
->optional_p
= true;
2014 /* Reset all of the chains when the set of basic blocks changes. */
2017 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED
)
2019 df_chain_remove_problem ();
2023 /* Create the chains for a list of USEs. */
2026 df_chain_create_bb_process_use (bitmap local_rd
,
2031 unsigned int def_index
;
2033 for (; use
; use
= DF_REF_NEXT_LOC (use
))
2035 unsigned int uregno
= DF_REF_REGNO (use
);
2036 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2037 || (uregno
>= FIRST_PSEUDO_REGISTER
))
2039 /* Do not want to go through this for an uninitialized var. */
2040 int count
= DF_DEFS_COUNT (uregno
);
2043 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2045 unsigned int first_index
= DF_DEFS_BEGIN (uregno
);
2046 unsigned int last_index
= first_index
+ count
- 1;
2048 EXECUTE_IF_SET_IN_BITMAP (local_rd
, first_index
, def_index
, bi
)
2051 if (def_index
> last_index
)
2054 def
= DF_DEFS_GET (def_index
);
2055 if (df_chain_problem_p (DF_DU_CHAIN
))
2056 df_chain_create (def
, use
);
2057 if (df_chain_problem_p (DF_UD_CHAIN
))
2058 df_chain_create (use
, def
);
2067 /* Create chains from reaching defs bitmaps for basic block BB. */
2070 df_chain_create_bb (unsigned int bb_index
)
2072 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2073 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (bb_index
);
2077 bitmap_initialize (&cpy
, &bitmap_default_obstack
);
2078 bitmap_copy (&cpy
, &bb_info
->in
);
2079 bitmap_set_bit (df_chain
->out_of_date_transfer_functions
, bb_index
);
2081 /* Since we are going forwards, process the artificial uses first
2082 then the artificial defs second. */
2085 /* Create the chains for the artificial uses from the EH_USES at the
2086 beginning of the block. */
2088 /* Artificials are only hard regs. */
2089 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2090 df_chain_create_bb_process_use (&cpy
,
2091 df_get_artificial_uses (bb
->index
),
2095 df_rd_simulate_artificial_defs_at_top (bb
, &cpy
);
2097 /* Process the regular instructions next. */
2098 FOR_BB_INSNS (bb
, insn
)
2101 unsigned int uid
= INSN_UID (insn
);
2103 /* First scan the uses and link them up with the defs that remain
2104 in the cpy vector. */
2105 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_USES (uid
), 0);
2106 if (df
->changeable_flags
& DF_EQ_NOTES
)
2107 df_chain_create_bb_process_use (&cpy
, DF_INSN_UID_EQ_USES (uid
), 0);
2109 /* Since we are going forwards, process the defs second. */
2110 df_rd_simulate_one_insn (bb
, insn
, &cpy
);
2113 /* Create the chains for the artificial uses of the hard registers
2114 at the end of the block. */
2115 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
2116 df_chain_create_bb_process_use (&cpy
,
2117 df_get_artificial_uses (bb
->index
),
2120 bitmap_clear (&cpy
);
2123 /* Create def-use chains from reaching use bitmaps for basic blocks
2127 df_chain_finalize (bitmap all_blocks
)
2129 unsigned int bb_index
;
2132 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2134 df_chain_create_bb (bb_index
);
2139 /* Free all storage associated with the problem. */
2142 df_chain_free (void)
2144 delete df_chain
->block_pool
;
2145 BITMAP_FREE (df_chain
->out_of_date_transfer_functions
);
2150 /* Debugging info. */
2153 df_chain_bb_dump (basic_block bb
, FILE *file
, bool top
)
2155 /* Artificials are only hard regs. */
2156 if (df
->changeable_flags
& DF_NO_HARD_REGS
)
2158 if (df_chain_problem_p (DF_UD_CHAIN
))
2163 ";; UD chains for artificial uses at %s\n",
2164 top
? "top" : "bottom");
2165 FOR_EACH_ARTIFICIAL_USE (use
, bb
->index
)
2166 if ((top
&& (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2167 || (!top
&& !(DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)))
2169 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2170 df_chain_dump (DF_REF_CHAIN (use
), file
);
2171 fprintf (file
, "\n");
2174 if (df_chain_problem_p (DF_DU_CHAIN
))
2179 ";; DU chains for artificial defs at %s\n",
2180 top
? "top" : "bottom");
2181 FOR_EACH_ARTIFICIAL_DEF (def
, bb
->index
)
2182 if ((top
&& (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
2183 || (!top
&& !(DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)))
2185 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2186 df_chain_dump (DF_REF_CHAIN (def
), file
);
2187 fprintf (file
, "\n");
2193 df_chain_top_dump (basic_block bb
, FILE *file
)
2195 df_chain_bb_dump (bb
, file
, /*top=*/true);
2199 df_chain_bottom_dump (basic_block bb
, FILE *file
)
2201 df_chain_bb_dump (bb
, file
, /*top=*/false);
2205 df_chain_insn_top_dump (const rtx_insn
*insn
, FILE *file
)
2207 if (df_chain_problem_p (DF_UD_CHAIN
) && INSN_P (insn
))
2209 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2212 fprintf (file
, ";; UD chains for insn luid %d uid %d\n",
2213 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2214 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2215 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2216 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2218 fprintf (file
, ";; reg %d ", DF_REF_REGNO (use
));
2219 if (DF_REF_FLAGS (use
) & DF_REF_READ_WRITE
)
2220 fprintf (file
, "read/write ");
2221 df_chain_dump (DF_REF_CHAIN (use
), file
);
2222 fprintf (file
, "\n");
2224 FOR_EACH_INSN_INFO_EQ_USE (use
, insn_info
)
2225 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use
))
2226 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2228 fprintf (file
, ";; eq_note reg %d ", DF_REF_REGNO (use
));
2229 df_chain_dump (DF_REF_CHAIN (use
), file
);
2230 fprintf (file
, "\n");
2236 df_chain_insn_bottom_dump (const rtx_insn
*insn
, FILE *file
)
2238 if (df_chain_problem_p (DF_DU_CHAIN
) && INSN_P (insn
))
2240 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2242 fprintf (file
, ";; DU chains for insn luid %d uid %d\n",
2243 DF_INSN_INFO_LUID (insn_info
), INSN_UID (insn
));
2244 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2245 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def
))
2246 || !(df
->changeable_flags
& DF_NO_HARD_REGS
))
2248 fprintf (file
, ";; reg %d ", DF_REF_REGNO (def
));
2249 if (DF_REF_FLAGS (def
) & DF_REF_READ_WRITE
)
2250 fprintf (file
, "read/write ");
2251 df_chain_dump (DF_REF_CHAIN (def
), file
);
2252 fprintf (file
, "\n");
2254 fprintf (file
, "\n");
2258 static struct df_problem problem_CHAIN
=
2260 DF_CHAIN
, /* Problem id. */
2261 DF_NONE
, /* Direction. */
2262 df_chain_alloc
, /* Allocate the problem specific data. */
2263 df_chain_reset
, /* Reset global information. */
2264 NULL
, /* Free basic block info. */
2265 NULL
, /* Local compute function. */
2266 NULL
, /* Init the solution specific data. */
2267 NULL
, /* Iterative solver. */
2268 NULL
, /* Confluence operator 0. */
2269 NULL
, /* Confluence operator n. */
2270 NULL
, /* Transfer function. */
2271 df_chain_finalize
, /* Finalize function. */
2272 df_chain_free
, /* Free all of the problem information. */
2273 df_chain_fully_remove_problem
,/* Remove this problem from the stack of dataflow problems. */
2274 NULL
, /* Debugging. */
2275 df_chain_top_dump
, /* Debugging start block. */
2276 df_chain_bottom_dump
, /* Debugging end block. */
2277 df_chain_insn_top_dump
, /* Debugging start insn. */
2278 df_chain_insn_bottom_dump
, /* Debugging end insn. */
2279 NULL
, /* Incremental solution verify start. */
2280 NULL
, /* Incremental solution verify end. */
2281 &problem_RD
, /* Dependent problem. */
2282 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
2283 TV_DF_CHAIN
, /* Timing variable. */
2284 false /* Reset blocks on dropping out of blocks_to_analyze. */
2288 /* Create a new DATAFLOW instance and add it to an existing instance
2289 of DF. The returned structure is what is used to get at the
2293 df_chain_add_problem (unsigned int chain_flags
)
2295 df_add_problem (&problem_CHAIN
);
2296 df_chain
->local_flags
= chain_flags
;
2297 df_chain
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2300 #undef df_chain_problem_p
2303 /*----------------------------------------------------------------------------
2304 WORD LEVEL LIVE REGISTERS
2306 Find the locations in the function where any use of a pseudo can
2307 reach in the backwards direction. In and out bitvectors are built
2308 for each basic block. We only track pseudo registers that have a
2309 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2310 contain two bits corresponding to each of the subwords.
2312 ----------------------------------------------------------------------------*/
2314 /* Private data used to verify the solution for this problem. */
2315 struct df_word_lr_problem_data
2317 /* An obstack for the bitmaps we need for this problem. */
2318 bitmap_obstack word_lr_bitmaps
;
2322 /* Free basic block info. */
2325 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
2328 struct df_word_lr_bb_info
*bb_info
= (struct df_word_lr_bb_info
*) vbb_info
;
2331 bitmap_clear (&bb_info
->use
);
2332 bitmap_clear (&bb_info
->def
);
2333 bitmap_clear (&bb_info
->in
);
2334 bitmap_clear (&bb_info
->out
);
2339 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2340 not touched unless the block is new. */
2343 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2345 unsigned int bb_index
;
2348 struct df_word_lr_problem_data
*problem_data
2349 = XNEW (struct df_word_lr_problem_data
);
2351 df_word_lr
->problem_data
= problem_data
;
2353 df_grow_bb_info (df_word_lr
);
2355 /* Create the mapping from regnos to slots. This does not change
2356 unless the problem is destroyed and recreated. In particular, if
2357 we end up deleting the only insn that used a subreg, we do not
2358 want to redo the mapping because this would invalidate everything
2361 bitmap_obstack_initialize (&problem_data
->word_lr_bitmaps
);
2363 FOR_EACH_BB_FN (bb
, cfun
)
2364 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, bb
->index
);
2366 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, ENTRY_BLOCK
);
2367 bitmap_set_bit (df_word_lr
->out_of_date_transfer_functions
, EXIT_BLOCK
);
2369 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2371 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2373 /* When bitmaps are already initialized, just clear them. */
2374 if (bb_info
->use
.obstack
)
2376 bitmap_clear (&bb_info
->def
);
2377 bitmap_clear (&bb_info
->use
);
2381 bitmap_initialize (&bb_info
->use
, &problem_data
->word_lr_bitmaps
);
2382 bitmap_initialize (&bb_info
->def
, &problem_data
->word_lr_bitmaps
);
2383 bitmap_initialize (&bb_info
->in
, &problem_data
->word_lr_bitmaps
);
2384 bitmap_initialize (&bb_info
->out
, &problem_data
->word_lr_bitmaps
);
2388 df_word_lr
->optional_p
= true;
2392 /* Reset the global solution for recalculation. */
2395 df_word_lr_reset (bitmap all_blocks
)
2397 unsigned int bb_index
;
2400 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2402 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2403 gcc_assert (bb_info
);
2404 bitmap_clear (&bb_info
->in
);
2405 bitmap_clear (&bb_info
->out
);
2409 /* Examine REF, and if it is for a reg we're interested in, set or
2410 clear the bits corresponding to its subwords from the bitmap
2411 according to IS_SET. LIVE is the bitmap we should update. We do
2412 not track hard regs or pseudos of any size other than 2 *
2414 We return true if we changed the bitmap, or if we encountered a register
2415 we're not tracking. */
2418 df_word_lr_mark_ref (df_ref ref
, bool is_set
, regset live
)
2420 rtx orig_reg
= DF_REF_REG (ref
);
2422 machine_mode reg_mode
;
2424 /* Left at -1 for whole accesses. */
2425 int which_subword
= -1;
2426 bool changed
= false;
2428 if (GET_CODE (reg
) == SUBREG
)
2429 reg
= SUBREG_REG (orig_reg
);
2430 regno
= REGNO (reg
);
2431 reg_mode
= GET_MODE (reg
);
2432 if (regno
< FIRST_PSEUDO_REGISTER
2433 || GET_MODE_SIZE (reg_mode
) != 2 * UNITS_PER_WORD
)
2436 if (GET_CODE (orig_reg
) == SUBREG
2437 && df_read_modify_subreg_p (orig_reg
))
2439 gcc_assert (DF_REF_FLAGS_IS_SET (ref
, DF_REF_PARTIAL
));
2440 if (subreg_lowpart_p (orig_reg
))
2447 if (which_subword
!= 1)
2448 changed
|= bitmap_set_bit (live
, regno
* 2);
2449 if (which_subword
!= 0)
2450 changed
|= bitmap_set_bit (live
, regno
* 2 + 1);
2454 if (which_subword
!= 1)
2455 changed
|= bitmap_clear_bit (live
, regno
* 2);
2456 if (which_subword
!= 0)
2457 changed
|= bitmap_clear_bit (live
, regno
* 2 + 1);
2462 /* Compute local live register info for basic block BB. */
2465 df_word_lr_bb_local_compute (unsigned int bb_index
)
2467 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
2468 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2472 /* Ensure that artificial refs don't contain references to pseudos. */
2473 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
2474 gcc_assert (DF_REF_REGNO (def
) < FIRST_PSEUDO_REGISTER
);
2476 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
2477 gcc_assert (DF_REF_REGNO (use
) < FIRST_PSEUDO_REGISTER
);
2479 FOR_BB_INSNS_REVERSE (bb
, insn
)
2481 if (!NONDEBUG_INSN_P (insn
))
2484 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
2485 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
2486 /* If the def is to only part of the reg, it does
2487 not kill the other defs that reach here. */
2488 if (!(DF_REF_FLAGS (def
) & (DF_REF_CONDITIONAL
)))
2490 df_word_lr_mark_ref (def
, true, &bb_info
->def
);
2491 df_word_lr_mark_ref (def
, false, &bb_info
->use
);
2493 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
2494 df_word_lr_mark_ref (use
, true, &bb_info
->use
);
2499 /* Compute local live register info for each basic block within BLOCKS. */
2502 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED
)
2504 unsigned int bb_index
;
2507 EXECUTE_IF_SET_IN_BITMAP (df_word_lr
->out_of_date_transfer_functions
, 0, bb_index
, bi
)
2509 if (bb_index
== EXIT_BLOCK
)
2513 EXECUTE_IF_SET_IN_BITMAP (df
->exit_block_uses
, FIRST_PSEUDO_REGISTER
,
2518 df_word_lr_bb_local_compute (bb_index
);
2521 bitmap_clear (df_word_lr
->out_of_date_transfer_functions
);
2525 /* Initialize the solution vectors. */
2528 df_word_lr_init (bitmap all_blocks
)
2530 unsigned int bb_index
;
2533 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2535 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2536 bitmap_copy (&bb_info
->in
, &bb_info
->use
);
2537 bitmap_clear (&bb_info
->out
);
2542 /* Confluence function that ignores fake edges. */
2545 df_word_lr_confluence_n (edge e
)
2547 bitmap op1
= &df_word_lr_get_bb_info (e
->src
->index
)->out
;
2548 bitmap op2
= &df_word_lr_get_bb_info (e
->dest
->index
)->in
;
2550 return bitmap_ior_into (op1
, op2
);
2554 /* Transfer function. */
2557 df_word_lr_transfer_function (int bb_index
)
2559 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb_index
);
2560 bitmap in
= &bb_info
->in
;
2561 bitmap out
= &bb_info
->out
;
2562 bitmap use
= &bb_info
->use
;
2563 bitmap def
= &bb_info
->def
;
2565 return bitmap_ior_and_compl (in
, use
, out
, def
);
2569 /* Free all storage associated with the problem. */
2572 df_word_lr_free (void)
2574 struct df_word_lr_problem_data
*problem_data
2575 = (struct df_word_lr_problem_data
*)df_word_lr
->problem_data
;
2577 if (df_word_lr
->block_info
)
2579 df_word_lr
->block_info_size
= 0;
2580 free (df_word_lr
->block_info
);
2581 df_word_lr
->block_info
= NULL
;
2584 BITMAP_FREE (df_word_lr
->out_of_date_transfer_functions
);
2585 bitmap_obstack_release (&problem_data
->word_lr_bitmaps
);
2586 free (problem_data
);
2591 /* Debugging info at top of bb. */
2594 df_word_lr_top_dump (basic_block bb
, FILE *file
)
2596 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2600 fprintf (file
, ";; blr in \t");
2601 df_print_word_regset (file
, &bb_info
->in
);
2602 fprintf (file
, ";; blr use \t");
2603 df_print_word_regset (file
, &bb_info
->use
);
2604 fprintf (file
, ";; blr def \t");
2605 df_print_word_regset (file
, &bb_info
->def
);
2609 /* Debugging info at bottom of bb. */
2612 df_word_lr_bottom_dump (basic_block bb
, FILE *file
)
2614 struct df_word_lr_bb_info
*bb_info
= df_word_lr_get_bb_info (bb
->index
);
2618 fprintf (file
, ";; blr out \t");
2619 df_print_word_regset (file
, &bb_info
->out
);
2623 /* All of the information associated with every instance of the problem. */
2625 static struct df_problem problem_WORD_LR
=
2627 DF_WORD_LR
, /* Problem id. */
2628 DF_BACKWARD
, /* Direction. */
2629 df_word_lr_alloc
, /* Allocate the problem specific data. */
2630 df_word_lr_reset
, /* Reset global information. */
2631 df_word_lr_free_bb_info
, /* Free basic block info. */
2632 df_word_lr_local_compute
, /* Local compute function. */
2633 df_word_lr_init
, /* Init the solution specific data. */
2634 df_worklist_dataflow
, /* Worklist solver. */
2635 NULL
, /* Confluence operator 0. */
2636 df_word_lr_confluence_n
, /* Confluence operator n. */
2637 df_word_lr_transfer_function
, /* Transfer function. */
2638 NULL
, /* Finalize function. */
2639 df_word_lr_free
, /* Free all of the problem information. */
2640 df_word_lr_free
, /* Remove this problem from the stack of dataflow problems. */
2641 NULL
, /* Debugging. */
2642 df_word_lr_top_dump
, /* Debugging start block. */
2643 df_word_lr_bottom_dump
, /* Debugging end block. */
2644 NULL
, /* Debugging start insn. */
2645 NULL
, /* Debugging end insn. */
2646 NULL
, /* Incremental solution verify start. */
2647 NULL
, /* Incremental solution verify end. */
2648 NULL
, /* Dependent problem. */
2649 sizeof (struct df_word_lr_bb_info
),/* Size of entry of block_info array. */
2650 TV_DF_WORD_LR
, /* Timing variable. */
2651 false /* Reset blocks on dropping out of blocks_to_analyze. */
2655 /* Create a new DATAFLOW instance and add it to an existing instance
2656 of DF. The returned structure is what is used to get at the
2660 df_word_lr_add_problem (void)
2662 df_add_problem (&problem_WORD_LR
);
2663 /* These will be initialized when df_scan_blocks processes each
2665 df_word_lr
->out_of_date_transfer_functions
= BITMAP_ALLOC (&df_bitmap_obstack
);
2669 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2670 any bits, which is used by the caller to determine whether a set is
2671 necessary. We also return true if there are other reasons not to delete
2675 df_word_lr_simulate_defs (rtx_insn
*insn
, bitmap live
)
2677 bool changed
= false;
2680 FOR_EACH_INSN_DEF (def
, insn
)
2681 if (DF_REF_FLAGS (def
) & DF_REF_CONDITIONAL
)
2684 changed
|= df_word_lr_mark_ref (def
, false, live
);
2689 /* Simulate the effects of the uses of INSN on LIVE. */
2692 df_word_lr_simulate_uses (rtx_insn
*insn
, bitmap live
)
2696 FOR_EACH_INSN_USE (use
, insn
)
2697 df_word_lr_mark_ref (use
, true, live
);
2700 /*----------------------------------------------------------------------------
2701 This problem computes REG_DEAD and REG_UNUSED notes.
2702 ----------------------------------------------------------------------------*/
2705 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED
)
2707 df_note
->optional_p
= true;
2710 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2712 df_print_note (const char *prefix
, rtx_insn
*insn
, rtx note
)
2716 fprintf (dump_file
, "%s %d ", prefix
, INSN_UID (insn
));
2717 print_rtl (dump_file
, note
);
2718 fprintf (dump_file
, "\n");
2723 /* After reg-stack, the x86 floating point stack regs are difficult to
2724 analyze because of all of the pushes, pops and rotations. Thus, we
2725 just leave the notes alone. */
2729 df_ignore_stack_reg (int regno
)
2731 return regstack_completed
2732 && IN_RANGE (regno
, FIRST_STACK_REG
, LAST_STACK_REG
);
2736 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED
)
2743 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
2746 df_remove_dead_and_unused_notes (rtx_insn
*insn
)
2748 rtx
*pprev
= ®_NOTES (insn
);
2753 switch (REG_NOTE_KIND (link
))
2756 /* After reg-stack, we need to ignore any unused notes
2757 for the stack registers. */
2758 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2760 pprev
= &XEXP (link
, 1);
2765 rtx next
= XEXP (link
, 1);
2766 if (REG_DEAD_DEBUGGING
)
2767 df_print_note ("deleting: ", insn
, link
);
2768 free_EXPR_LIST_node (link
);
2769 *pprev
= link
= next
;
2774 /* After reg-stack, we need to ignore any unused notes
2775 for the stack registers. */
2776 if (df_ignore_stack_reg (REGNO (XEXP (link
, 0))))
2778 pprev
= &XEXP (link
, 1);
2783 rtx next
= XEXP (link
, 1);
2784 if (REG_DEAD_DEBUGGING
)
2785 df_print_note ("deleting: ", insn
, link
);
2786 free_EXPR_LIST_node (link
);
2787 *pprev
= link
= next
;
2792 pprev
= &XEXP (link
, 1);
2799 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2800 as the bitmap of currently live registers. */
2803 df_remove_dead_eq_notes (rtx_insn
*insn
, bitmap live
)
2805 rtx
*pprev
= ®_NOTES (insn
);
2810 switch (REG_NOTE_KIND (link
))
2815 /* Remove the notes that refer to dead registers. As we have at most
2816 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2817 so we need to purge the complete EQ_USES vector when removing
2818 the note using df_notes_rescan. */
2820 bool deleted
= false;
2822 FOR_EACH_INSN_EQ_USE (use
, insn
)
2823 if (DF_REF_REGNO (use
) > FIRST_PSEUDO_REGISTER
2825 && (DF_REF_FLAGS (use
) & DF_REF_IN_NOTE
)
2826 && !bitmap_bit_p (live
, DF_REF_REGNO (use
))
2827 && loc_mentioned_in_p (DF_REF_LOC (use
), XEXP (link
, 0)))
2835 if (REG_DEAD_DEBUGGING
)
2836 df_print_note ("deleting: ", insn
, link
);
2837 next
= XEXP (link
, 1);
2838 free_EXPR_LIST_node (link
);
2839 *pprev
= link
= next
;
2840 df_notes_rescan (insn
);
2844 pprev
= &XEXP (link
, 1);
2851 pprev
= &XEXP (link
, 1);
2858 /* Set a NOTE_TYPE note for REG in INSN. */
2861 df_set_note (enum reg_note note_type
, rtx_insn
*insn
, rtx reg
)
2863 gcc_checking_assert (!DEBUG_INSN_P (insn
));
2864 add_reg_note (insn
, note_type
, reg
);
2867 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2868 arguments. Return true if the register value described by MWS's
2869 mw_reg is known to be completely unused, and if mw_reg can therefore
2870 be used in a REG_UNUSED note. */
2873 df_whole_mw_reg_unused_p (struct df_mw_hardreg
*mws
,
2874 bitmap live
, bitmap artificial_uses
)
2878 /* If MWS describes a partial reference, create REG_UNUSED notes for
2879 individual hard registers. */
2880 if (mws
->flags
& DF_REF_PARTIAL
)
2883 /* Likewise if some part of the register is used. */
2884 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2885 if (bitmap_bit_p (live
, r
)
2886 || bitmap_bit_p (artificial_uses
, r
))
2889 gcc_assert (REG_P (mws
->mw_reg
));
2894 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2895 based on the bits in LIVE. Do not generate notes for registers in
2896 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2897 not generated if the reg is both read and written by the
2902 df_set_unused_notes_for_mw (rtx_insn
*insn
, struct df_mw_hardreg
*mws
,
2903 bitmap live
, bitmap do_not_gen
,
2904 bitmap artificial_uses
,
2905 struct dead_debug_local
*debug
)
2909 if (REG_DEAD_DEBUGGING
&& dump_file
)
2910 fprintf (dump_file
, "mw_set_unused looking at mws[%d..%d]\n",
2911 mws
->start_regno
, mws
->end_regno
);
2913 if (df_whole_mw_reg_unused_p (mws
, live
, artificial_uses
))
2915 unsigned int regno
= mws
->start_regno
;
2916 df_set_note (REG_UNUSED
, insn
, mws
->mw_reg
);
2917 dead_debug_insert_temp (debug
, regno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
2919 if (REG_DEAD_DEBUGGING
)
2920 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
2922 bitmap_set_bit (do_not_gen
, regno
);
2923 /* Only do this if the value is totally dead. */
2926 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2928 if (!bitmap_bit_p (live
, r
)
2929 && !bitmap_bit_p (artificial_uses
, r
))
2931 df_set_note (REG_UNUSED
, insn
, regno_reg_rtx
[r
]);
2932 dead_debug_insert_temp (debug
, r
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
2933 if (REG_DEAD_DEBUGGING
)
2934 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
2936 bitmap_set_bit (do_not_gen
, r
);
2941 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2942 arguments. Return true if the register value described by MWS's
2943 mw_reg is known to be completely dead, and if mw_reg can therefore
2944 be used in a REG_DEAD note. */
2947 df_whole_mw_reg_dead_p (struct df_mw_hardreg
*mws
,
2948 bitmap live
, bitmap artificial_uses
,
2953 /* If MWS describes a partial reference, create REG_DEAD notes for
2954 individual hard registers. */
2955 if (mws
->flags
& DF_REF_PARTIAL
)
2958 /* Likewise if some part of the register is not dead. */
2959 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
2960 if (bitmap_bit_p (live
, r
)
2961 || bitmap_bit_p (artificial_uses
, r
)
2962 || bitmap_bit_p (do_not_gen
, r
))
2965 gcc_assert (REG_P (mws
->mw_reg
));
2969 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2970 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2971 from being set if the instruction both reads and writes the
2975 df_set_dead_notes_for_mw (rtx_insn
*insn
, struct df_mw_hardreg
*mws
,
2976 bitmap live
, bitmap do_not_gen
,
2977 bitmap artificial_uses
, bool *added_notes_p
)
2980 bool is_debug
= *added_notes_p
;
2982 *added_notes_p
= false;
2984 if (REG_DEAD_DEBUGGING
&& dump_file
)
2986 fprintf (dump_file
, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2987 mws
->start_regno
, mws
->end_regno
);
2988 df_print_regset (dump_file
, do_not_gen
);
2989 fprintf (dump_file
, " live =");
2990 df_print_regset (dump_file
, live
);
2991 fprintf (dump_file
, " artificial uses =");
2992 df_print_regset (dump_file
, artificial_uses
);
2995 if (df_whole_mw_reg_dead_p (mws
, live
, artificial_uses
, do_not_gen
))
2999 *added_notes_p
= true;
3002 /* Add a dead note for the entire multi word register. */
3003 df_set_note (REG_DEAD
, insn
, mws
->mw_reg
);
3004 if (REG_DEAD_DEBUGGING
)
3005 df_print_note ("adding 1: ", insn
, REG_NOTES (insn
));
3009 for (r
= mws
->start_regno
; r
<= mws
->end_regno
; r
++)
3010 if (!bitmap_bit_p (live
, r
)
3011 && !bitmap_bit_p (artificial_uses
, r
)
3012 && !bitmap_bit_p (do_not_gen
, r
))
3016 *added_notes_p
= true;
3019 df_set_note (REG_DEAD
, insn
, regno_reg_rtx
[r
]);
3020 if (REG_DEAD_DEBUGGING
)
3021 df_print_note ("adding 2: ", insn
, REG_NOTES (insn
));
3028 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3029 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3032 df_create_unused_note (rtx_insn
*insn
, df_ref def
,
3033 bitmap live
, bitmap artificial_uses
,
3034 struct dead_debug_local
*debug
)
3036 unsigned int dregno
= DF_REF_REGNO (def
);
3038 if (REG_DEAD_DEBUGGING
&& dump_file
)
3040 fprintf (dump_file
, " regular looking at def ");
3041 df_ref_debug (def
, dump_file
);
3044 if (!((DF_REF_FLAGS (def
) & DF_REF_MW_HARDREG
)
3045 || bitmap_bit_p (live
, dregno
)
3046 || bitmap_bit_p (artificial_uses
, dregno
)
3047 || df_ignore_stack_reg (dregno
)))
3049 rtx reg
= (DF_REF_LOC (def
))
3050 ? *DF_REF_REAL_LOC (def
): DF_REF_REG (def
);
3051 df_set_note (REG_UNUSED
, insn
, reg
);
3052 dead_debug_insert_temp (debug
, dregno
, insn
, DEBUG_TEMP_AFTER_WITH_REG
);
3053 if (REG_DEAD_DEBUGGING
)
3054 df_print_note ("adding 3: ", insn
, REG_NOTES (insn
));
3061 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3062 info: lifetime, bb, and number of defs and uses for basic block
3063 BB. The three bitvectors are scratch regs used here. */
3066 df_note_bb_compute (unsigned int bb_index
,
3067 bitmap live
, bitmap do_not_gen
, bitmap artificial_uses
)
3069 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
3072 struct dead_debug_local debug
;
3074 dead_debug_local_init (&debug
, NULL
, NULL
);
3076 bitmap_copy (live
, df_get_live_out (bb
));
3077 bitmap_clear (artificial_uses
);
3079 if (REG_DEAD_DEBUGGING
&& dump_file
)
3081 fprintf (dump_file
, "live at bottom ");
3082 df_print_regset (dump_file
, live
);
3085 /* Process the artificial defs and uses at the bottom of the block
3086 to begin processing. */
3087 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3089 if (REG_DEAD_DEBUGGING
&& dump_file
)
3090 fprintf (dump_file
, "artificial def %d\n", DF_REF_REGNO (def
));
3092 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3093 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3096 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3097 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3099 unsigned int regno
= DF_REF_REGNO (use
);
3100 bitmap_set_bit (live
, regno
);
3102 /* Notes are not generated for any of the artificial registers
3103 at the bottom of the block. */
3104 bitmap_set_bit (artificial_uses
, regno
);
3107 if (REG_DEAD_DEBUGGING
&& dump_file
)
3109 fprintf (dump_file
, "live before artificials out ");
3110 df_print_regset (dump_file
, live
);
3113 FOR_BB_INSNS_REVERSE (bb
, insn
)
3115 df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3122 debug_insn
= DEBUG_INSN_P (insn
);
3124 bitmap_clear (do_not_gen
);
3125 df_remove_dead_and_unused_notes (insn
);
3127 /* Process the defs. */
3130 if (REG_DEAD_DEBUGGING
&& dump_file
)
3132 fprintf (dump_file
, "processing call %d\n live =",
3134 df_print_regset (dump_file
, live
);
3137 /* We only care about real sets for calls. Clobbers cannot
3138 be depended on to really die. */
3139 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3140 if ((DF_MWS_REG_DEF_P (mw
))
3141 && !df_ignore_stack_reg (mw
->start_regno
))
3142 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3143 artificial_uses
, &debug
);
3145 /* All of the defs except the return value are some sort of
3146 clobber. This code is for the return. */
3147 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3149 unsigned int dregno
= DF_REF_REGNO (def
);
3150 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3152 df_create_unused_note (insn
,
3153 def
, live
, artificial_uses
, &debug
);
3154 bitmap_set_bit (do_not_gen
, dregno
);
3157 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3158 bitmap_clear_bit (live
, dregno
);
3164 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3165 if (DF_MWS_REG_DEF_P (mw
))
3166 df_set_unused_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3167 artificial_uses
, &debug
);
3169 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3171 unsigned int dregno
= DF_REF_REGNO (def
);
3172 df_create_unused_note (insn
,
3173 def
, live
, artificial_uses
, &debug
);
3175 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
))
3176 bitmap_set_bit (do_not_gen
, dregno
);
3178 if (!DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3179 bitmap_clear_bit (live
, dregno
);
3183 /* Process the uses. */
3184 FOR_EACH_INSN_INFO_MW (mw
, insn_info
)
3185 if (DF_MWS_REG_USE_P (mw
)
3186 && !df_ignore_stack_reg (mw
->start_regno
))
3188 bool really_add_notes
= debug_insn
!= 0;
3190 df_set_dead_notes_for_mw (insn
, mw
, live
, do_not_gen
,
3194 if (really_add_notes
)
3198 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3200 unsigned int uregno
= DF_REF_REGNO (use
);
3202 if (REG_DEAD_DEBUGGING
&& dump_file
&& !debug_insn
)
3204 fprintf (dump_file
, " regular looking at use ");
3205 df_ref_debug (use
, dump_file
);
3208 if (!bitmap_bit_p (live
, uregno
))
3214 /* We won't add REG_UNUSED or REG_DEAD notes for
3215 these, so we don't have to mess with them in
3216 debug insns either. */
3217 if (!bitmap_bit_p (artificial_uses
, uregno
)
3218 && !df_ignore_stack_reg (uregno
))
3219 dead_debug_add (&debug
, use
, uregno
);
3225 dead_debug_insert_temp (&debug
, uregno
, insn
,
3226 DEBUG_TEMP_BEFORE_WITH_REG
);
3228 if ( (!(DF_REF_FLAGS (use
)
3229 & (DF_REF_MW_HARDREG
| DF_REF_READ_WRITE
)))
3230 && (!bitmap_bit_p (do_not_gen
, uregno
))
3231 && (!bitmap_bit_p (artificial_uses
, uregno
))
3232 && (!df_ignore_stack_reg (uregno
)))
3234 rtx reg
= (DF_REF_LOC (use
))
3235 ? *DF_REF_REAL_LOC (use
) : DF_REF_REG (use
);
3236 df_set_note (REG_DEAD
, insn
, reg
);
3238 if (REG_DEAD_DEBUGGING
)
3239 df_print_note ("adding 4: ", insn
, REG_NOTES (insn
));
3241 /* This register is now live. */
3242 bitmap_set_bit (live
, uregno
);
3246 df_remove_dead_eq_notes (insn
, live
);
3248 if (debug_insn
== -1)
3250 /* ??? We could probably do better here, replacing dead
3251 registers with their definitions. */
3252 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
3253 df_insn_rescan_debug_internal (insn
);
3257 dead_debug_local_finish (&debug
, NULL
);
3261 /* Compute register info: lifetime, bb, and number of defs and uses. */
3263 df_note_compute (bitmap all_blocks
)
3265 unsigned int bb_index
;
3267 bitmap_head live
, do_not_gen
, artificial_uses
;
3269 bitmap_initialize (&live
, &df_bitmap_obstack
);
3270 bitmap_initialize (&do_not_gen
, &df_bitmap_obstack
);
3271 bitmap_initialize (&artificial_uses
, &df_bitmap_obstack
);
3273 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
3275 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3276 pseudos in debug insns because we don't always (re)visit blocks
3277 with death points after visiting dead uses. Even changing this
3278 loop to postorder would still leave room for visiting a death
3279 point before visiting a subsequent debug use. */
3280 df_note_bb_compute (bb_index
, &live
, &do_not_gen
, &artificial_uses
);
3283 bitmap_clear (&live
);
3284 bitmap_clear (&do_not_gen
);
3285 bitmap_clear (&artificial_uses
);
3289 /* Free all storage associated with the problem. */
3298 /* All of the information associated every instance of the problem. */
3300 static struct df_problem problem_NOTE
=
3302 DF_NOTE
, /* Problem id. */
3303 DF_NONE
, /* Direction. */
3304 df_note_alloc
, /* Allocate the problem specific data. */
3305 NULL
, /* Reset global information. */
3306 NULL
, /* Free basic block info. */
3307 df_note_compute
, /* Local compute function. */
3308 NULL
, /* Init the solution specific data. */
3309 NULL
, /* Iterative solver. */
3310 NULL
, /* Confluence operator 0. */
3311 NULL
, /* Confluence operator n. */
3312 NULL
, /* Transfer function. */
3313 NULL
, /* Finalize function. */
3314 df_note_free
, /* Free all of the problem information. */
3315 df_note_free
, /* Remove this problem from the stack of dataflow problems. */
3316 NULL
, /* Debugging. */
3317 NULL
, /* Debugging start block. */
3318 NULL
, /* Debugging end block. */
3319 NULL
, /* Debugging start insn. */
3320 NULL
, /* Debugging end insn. */
3321 NULL
, /* Incremental solution verify start. */
3322 NULL
, /* Incremental solution verify end. */
3323 &problem_LR
, /* Dependent problem. */
3324 sizeof (struct df_scan_bb_info
),/* Size of entry of block_info array. */
3325 TV_DF_NOTE
, /* Timing variable. */
3326 false /* Reset blocks on dropping out of blocks_to_analyze. */
3330 /* Create a new DATAFLOW instance and add it to an existing instance
3331 of DF. The returned structure is what is used to get at the
3335 df_note_add_problem (void)
3337 df_add_problem (&problem_NOTE
);
3343 /*----------------------------------------------------------------------------
3344 Functions for simulating the effects of single insns.
3346 You can either simulate in the forwards direction, starting from
3347 the top of a block or the backwards direction from the end of the
3348 block. If you go backwards, defs are examined first to clear bits,
3349 then uses are examined to set bits. If you go forwards, defs are
3350 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3351 are examined to clear bits. In either case, the result of examining
3352 a def can be undone (respectively by a use or a REG_UNUSED note).
3354 If you start at the top of the block, use one of DF_LIVE_IN or
3355 DF_LR_IN. If you start at the bottom of the block use one of
3356 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3357 THEY WILL BE DESTROYED.
3358 ----------------------------------------------------------------------------*/
3361 /* Find the set of DEFs for INSN. */
3364 df_simulate_find_defs (rtx_insn
*insn
, bitmap defs
)
3368 FOR_EACH_INSN_DEF (def
, insn
)
3369 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3372 /* Find the set of uses for INSN. This includes partial defs. */
3375 df_simulate_find_uses (rtx_insn
*insn
, bitmap uses
)
3378 struct df_insn_info
*insn_info
= DF_INSN_INFO_GET (insn
);
3380 FOR_EACH_INSN_INFO_DEF (def
, insn_info
)
3381 if (DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
))
3382 bitmap_set_bit (uses
, DF_REF_REGNO (def
));
3383 FOR_EACH_INSN_INFO_USE (use
, insn_info
)
3384 bitmap_set_bit (uses
, DF_REF_REGNO (use
));
3387 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3390 df_simulate_find_noclobber_defs (rtx_insn
*insn
, bitmap defs
)
3394 FOR_EACH_INSN_DEF (def
, insn
)
3395 if (!(DF_REF_FLAGS (def
) & (DF_REF_MUST_CLOBBER
| DF_REF_MAY_CLOBBER
)))
3396 bitmap_set_bit (defs
, DF_REF_REGNO (def
));
3400 /* Simulate the effects of the defs of INSN on LIVE. */
3403 df_simulate_defs (rtx_insn
*insn
, bitmap live
)
3407 FOR_EACH_INSN_DEF (def
, insn
)
3409 unsigned int dregno
= DF_REF_REGNO (def
);
3411 /* If the def is to only part of the reg, it does
3412 not kill the other defs that reach here. */
3413 if (!(DF_REF_FLAGS (def
) & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
)))
3414 bitmap_clear_bit (live
, dregno
);
3419 /* Simulate the effects of the uses of INSN on LIVE. */
3422 df_simulate_uses (rtx_insn
*insn
, bitmap live
)
3426 if (DEBUG_INSN_P (insn
))
3429 FOR_EACH_INSN_USE (use
, insn
)
3430 /* Add use to set of uses in this BB. */
3431 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3435 /* Add back the always live regs in BB to LIVE. */
3438 df_simulate_fixup_sets (basic_block bb
, bitmap live
)
3440 /* These regs are considered always live so if they end up dying
3441 because of some def, we need to bring the back again. */
3442 if (bb_has_eh_pred (bb
))
3443 bitmap_ior_into (live
, &df
->eh_block_artificial_uses
);
3445 bitmap_ior_into (live
, &df
->regular_block_artificial_uses
);
3449 /*----------------------------------------------------------------------------
3450 The following three functions are used only for BACKWARDS scanning:
3451 i.e. they process the defs before the uses.
3453 df_simulate_initialize_backwards should be called first with a
3454 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3455 df_simulate_one_insn_backwards should be called for each insn in
3456 the block, starting with the last one. Finally,
3457 df_simulate_finalize_backwards can be called to get a new value
3458 of the sets at the top of the block (this is rarely used).
3459 ----------------------------------------------------------------------------*/
3461 /* Apply the artificial uses and defs at the end of BB in a backwards
3465 df_simulate_initialize_backwards (basic_block bb
, bitmap live
)
3468 int bb_index
= bb
->index
;
3470 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3471 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
3472 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3474 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3475 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
3476 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3480 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3483 df_simulate_one_insn_backwards (basic_block bb
, rtx_insn
*insn
, bitmap live
)
3485 if (!NONDEBUG_INSN_P (insn
))
3488 df_simulate_defs (insn
, live
);
3489 df_simulate_uses (insn
, live
);
3490 df_simulate_fixup_sets (bb
, live
);
3494 /* Apply the artificial uses and defs at the top of BB in a backwards
3498 df_simulate_finalize_backwards (basic_block bb
, bitmap live
)
3504 int bb_index
= bb
->index
;
3506 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3507 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3508 bitmap_clear_bit (live
, DF_REF_REGNO (def
));
3511 FOR_EACH_ARTIFICIAL_USE (use
, bb_index
)
3512 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
3513 bitmap_set_bit (live
, DF_REF_REGNO (use
));
3516 /*----------------------------------------------------------------------------
3517 The following three functions are used only for FORWARDS scanning:
3518 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3519 Thus it is important to add the DF_NOTES problem to the stack of
3520 problems computed before using these functions.
3522 df_simulate_initialize_forwards should be called first with a
3523 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3524 df_simulate_one_insn_forwards should be called for each insn in
3525 the block, starting with the first one.
3526 ----------------------------------------------------------------------------*/
3528 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3529 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3533 df_simulate_initialize_forwards (basic_block bb
, bitmap live
)
3536 int bb_index
= bb
->index
;
3538 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
3539 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
3540 bitmap_set_bit (live
, DF_REF_REGNO (def
));
3543 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3546 df_simulate_one_insn_forwards (basic_block bb
, rtx_insn
*insn
, bitmap live
)
3549 if (! INSN_P (insn
))
3552 /* Make sure that DF_NOTE really is an active df problem. */
3553 gcc_assert (df_note
);
3555 /* Note that this is the opposite as how the problem is defined, because
3556 in the LR problem defs _kill_ liveness. However, they do so backwards,
3557 while here the scan is performed forwards! So, first assume that the
3558 def is live, and if this is not true REG_UNUSED notes will rectify the
3560 df_simulate_find_noclobber_defs (insn
, live
);
3562 /* Clear all of the registers that go dead. */
3563 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
3565 switch (REG_NOTE_KIND (link
))
3570 rtx reg
= XEXP (link
, 0);
3571 bitmap_clear_range (live
, REGNO (reg
), REG_NREGS (reg
));
3578 df_simulate_fixup_sets (bb
, live
);
3581 /* Used by the next two functions to encode information about the
3582 memory references we found. */
3583 #define MEMREF_NORMAL 1
3584 #define MEMREF_VOLATILE 2
3586 /* Return an OR of MEMREF_NORMAL or MEMREF_VOLATILE for the MEMs in X. */
3589 find_memory (rtx_insn
*insn
)
3592 subrtx_iterator::array_type array
;
3593 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), NONCONST
)
3595 const_rtx x
= *iter
;
3596 if (GET_CODE (x
) == ASM_OPERANDS
&& MEM_VOLATILE_P (x
))
3597 flags
|= MEMREF_VOLATILE
;
3600 if (MEM_VOLATILE_P (x
))
3601 flags
|= MEMREF_VOLATILE
;
3602 else if (!MEM_READONLY_P (x
))
3603 flags
|= MEMREF_NORMAL
;
3609 /* A subroutine of can_move_insns_across_p called through note_stores.
3610 DATA points to an integer in which we set either the bit for
3611 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3615 find_memory_stores (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
,
3616 void *data ATTRIBUTE_UNUSED
)
3618 int *pflags
= (int *)data
;
3619 if (GET_CODE (x
) == SUBREG
)
3621 /* Treat stores to SP as stores to memory, this will prevent problems
3622 when there are references to the stack frame. */
3623 if (x
== stack_pointer_rtx
)
3624 *pflags
|= MEMREF_VOLATILE
;
3627 *pflags
|= MEM_VOLATILE_P (x
) ? MEMREF_VOLATILE
: MEMREF_NORMAL
;
3630 /* Scan BB backwards, using df_simulate functions to keep track of
3631 lifetimes, up to insn POINT. The result is stored in LIVE. */
3634 simulate_backwards_to_point (basic_block bb
, regset live
, rtx point
)
3637 bitmap_copy (live
, df_get_live_out (bb
));
3638 df_simulate_initialize_backwards (bb
, live
);
3640 /* Scan and update life information until we reach the point we're
3642 for (insn
= BB_END (bb
); insn
!= point
; insn
= PREV_INSN (insn
))
3643 df_simulate_one_insn_backwards (bb
, insn
, live
);
3646 /* Return true if it is safe to move a group of insns, described by
3647 the range FROM to TO, backwards across another group of insns,
3648 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3649 are no insns between ACROSS_TO and FROM, but they may be in
3650 different basic blocks; MERGE_BB is the block from which the
3651 insns will be moved. The caller must pass in a regset MERGE_LIVE
3652 which specifies the registers live after TO.
3654 This function may be called in one of two cases: either we try to
3655 move identical instructions from all successor blocks into their
3656 predecessor, or we try to move from only one successor block. If
3657 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3658 the second case. It should contain a set of registers live at the
3659 end of ACROSS_TO which must not be clobbered by moving the insns.
3660 In that case, we're also more careful about moving memory references
3663 We return false if it is not safe to move the entire group, but it
3664 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3665 is set to point at the last moveable insn in such a case. */
3668 can_move_insns_across (rtx_insn
*from
, rtx_insn
*to
,
3669 rtx_insn
*across_from
, rtx_insn
*across_to
,
3670 basic_block merge_bb
, regset merge_live
,
3671 regset other_branch_live
, rtx_insn
**pmove_upto
)
3673 rtx_insn
*insn
, *next
, *max_to
;
3674 bitmap merge_set
, merge_use
, local_merge_live
;
3675 bitmap test_set
, test_use
;
3676 unsigned i
, fail
= 0;
3678 int memrefs_in_across
= 0;
3679 int mem_sets_in_across
= 0;
3680 bool trapping_insns_in_across
= false;
3682 if (pmove_upto
!= NULL
)
3685 /* Find real bounds, ignoring debug insns. */
3686 while (!NONDEBUG_INSN_P (from
) && from
!= to
)
3687 from
= NEXT_INSN (from
);
3688 while (!NONDEBUG_INSN_P (to
) && from
!= to
)
3689 to
= PREV_INSN (to
);
3691 for (insn
= across_to
; ; insn
= next
)
3695 if (RTL_CONST_OR_PURE_CALL_P (insn
))
3696 /* Pure functions can read from memory. Const functions can
3697 read from arguments that the ABI has forced onto the stack.
3698 Neither sort of read can be volatile. */
3699 memrefs_in_across
|= MEMREF_NORMAL
;
3702 memrefs_in_across
|= MEMREF_VOLATILE
;
3703 mem_sets_in_across
|= MEMREF_VOLATILE
;
3706 if (NONDEBUG_INSN_P (insn
))
3708 if (volatile_insn_p (PATTERN (insn
)))
3710 memrefs_in_across
|= find_memory (insn
);
3711 note_stores (PATTERN (insn
), find_memory_stores
,
3712 &mem_sets_in_across
);
3713 /* This is used just to find sets of the stack pointer. */
3714 memrefs_in_across
|= mem_sets_in_across
;
3715 trapping_insns_in_across
|= may_trap_p (PATTERN (insn
));
3717 next
= PREV_INSN (insn
);
3718 if (insn
== across_from
)
3723 MERGE_SET = set of registers set in MERGE_BB
3724 MERGE_USE = set of registers used in MERGE_BB and live at its top
3725 MERGE_LIVE = set of registers live at the point inside the MERGE
3726 range that we've reached during scanning
3727 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3728 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3729 and live before ACROSS_FROM. */
3731 merge_set
= BITMAP_ALLOC (®_obstack
);
3732 merge_use
= BITMAP_ALLOC (®_obstack
);
3733 local_merge_live
= BITMAP_ALLOC (®_obstack
);
3734 test_set
= BITMAP_ALLOC (®_obstack
);
3735 test_use
= BITMAP_ALLOC (®_obstack
);
3737 /* Compute the set of registers set and used in the ACROSS range. */
3738 if (other_branch_live
!= NULL
)
3739 bitmap_copy (test_use
, other_branch_live
);
3740 df_simulate_initialize_backwards (merge_bb
, test_use
);
3741 for (insn
= across_to
; ; insn
= next
)
3743 if (NONDEBUG_INSN_P (insn
))
3745 df_simulate_find_defs (insn
, test_set
);
3746 df_simulate_defs (insn
, test_use
);
3747 df_simulate_uses (insn
, test_use
);
3749 next
= PREV_INSN (insn
);
3750 if (insn
== across_from
)
3754 /* Compute an upper bound for the amount of insns moved, by finding
3755 the first insn in MERGE that sets a register in TEST_USE, or uses
3756 a register in TEST_SET. We also check for calls, trapping operations,
3757 and memory references. */
3759 for (insn
= from
; ; insn
= next
)
3763 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_EPILOGUE_BEG
)
3765 if (NONDEBUG_INSN_P (insn
))
3767 if (may_trap_or_fault_p (PATTERN (insn
))
3768 && (trapping_insns_in_across
3769 || other_branch_live
!= NULL
3770 || volatile_insn_p (PATTERN (insn
))))
3773 /* We cannot move memory stores past each other, or move memory
3774 reads past stores, at least not without tracking them and
3775 calling true_dependence on every pair.
3777 If there is no other branch and no memory references or
3778 sets in the ACROSS range, we can move memory references
3779 freely, even volatile ones.
3781 Otherwise, the rules are as follows: volatile memory
3782 references and stores can't be moved at all, and any type
3783 of memory reference can't be moved if there are volatile
3784 accesses or stores in the ACROSS range. That leaves
3785 normal reads, which can be moved, as the trapping case is
3786 dealt with elsewhere. */
3787 if (other_branch_live
!= NULL
|| memrefs_in_across
!= 0)
3789 int mem_ref_flags
= 0;
3790 int mem_set_flags
= 0;
3791 note_stores (PATTERN (insn
), find_memory_stores
, &mem_set_flags
);
3792 mem_ref_flags
= find_memory (insn
);
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
))
3812 if (!HAVE_cc0
|| !sets_cc0_p (insn
))
3815 next
= NEXT_INSN (insn
);
3822 if (max_to
== NULL_RTX
|| (fail
&& pmove_upto
== NULL
))
3825 /* Now, lower this upper bound by also taking into account that
3826 a range of insns moved across ACROSS must not leave a register
3827 live at the end that will be clobbered in ACROSS. We need to
3828 find a point where TEST_SET & LIVE == 0.
3830 Insns in the MERGE range that set registers which are also set
3831 in the ACROSS range may still be moved as long as we also move
3832 later insns which use the results of the set, and make the
3833 register dead again. This is verified by the condition stated
3834 above. We only need to test it for registers that are set in
3837 MERGE_LIVE is provided by the caller and holds live registers after
3839 bitmap_copy (local_merge_live
, merge_live
);
3840 for (insn
= to
; insn
!= max_to
; insn
= PREV_INSN (insn
))
3841 df_simulate_one_insn_backwards (merge_bb
, insn
, local_merge_live
);
3843 /* We're not interested in registers that aren't set in the moved
3845 bitmap_and_into (local_merge_live
, merge_set
);
3848 if (NONDEBUG_INSN_P (insn
))
3850 if (!bitmap_intersect_p (test_set
, local_merge_live
)
3851 && (!HAVE_cc0
|| !sets_cc0_p (insn
)))
3857 df_simulate_one_insn_backwards (merge_bb
, insn
,
3865 insn
= PREV_INSN (insn
);
3872 *pmove_upto
= max_to
;
3874 /* For small register class machines, don't lengthen lifetimes of
3875 hard registers before reload. */
3876 if (! reload_completed
3877 && targetm
.small_register_classes_for_mode_p (VOIDmode
))
3879 EXECUTE_IF_SET_IN_BITMAP (merge_set
, 0, i
, bi
)
3881 if (i
< FIRST_PSEUDO_REGISTER
3883 && ! global_regs
[i
])
3892 BITMAP_FREE (merge_set
);
3893 BITMAP_FREE (merge_use
);
3894 BITMAP_FREE (local_merge_live
);
3895 BITMAP_FREE (test_set
);
3896 BITMAP_FREE (test_use
);
3902 /*----------------------------------------------------------------------------
3903 MULTIPLE DEFINITIONS
3905 Find the locations in the function reached by multiple definition sites
3906 for a live pseudo. In and out bitvectors are built for each basic
3907 block. They are restricted for efficiency to live registers.
3909 The gen and kill sets for the problem are obvious. Together they
3910 include all defined registers in a basic block; the gen set includes
3911 registers where a partial or conditional or may-clobber definition is
3912 last in the BB, while the kill set includes registers with a complete
3913 definition coming last. However, the computation of the dataflow
3914 itself is interesting.
3916 The idea behind it comes from SSA form's iterated dominance frontier
3917 criterion for inserting PHI functions. Just like in that case, we can use
3918 the dominance frontier to find places where multiple definitions meet;
3919 a register X defined in a basic block BB1 has multiple definitions in
3920 basic blocks in BB1's dominance frontier.
3922 So, the in-set of a basic block BB2 is not just the union of the
3923 out-sets of BB2's predecessors, but includes some more bits that come
3924 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3925 the previous paragraph). I called this set the init-set of BB2.
3927 (Note: I actually use the kill-set only to build the init-set.
3928 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3930 For example, if you have
3934 if <...> goto BB2 else goto BB3;
3942 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3943 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3944 not need to iterate the dominance frontier, because we do not insert
3945 anything like PHI functions there! Instead, dataflow will take care of
3946 propagating the information to BB3's successors.
3947 ---------------------------------------------------------------------------*/
3949 /* Private data used to verify the solution for this problem. */
3950 struct df_md_problem_data
3952 /* An obstack for the bitmaps we need for this problem. */
3953 bitmap_obstack md_bitmaps
;
3956 /* Scratch var used by transfer functions. This is used to do md analysis
3957 only for live registers. */
3958 static bitmap_head df_md_scratch
;
3962 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED
,
3965 struct df_md_bb_info
*bb_info
= (struct df_md_bb_info
*) vbb_info
;
3968 bitmap_clear (&bb_info
->kill
);
3969 bitmap_clear (&bb_info
->gen
);
3970 bitmap_clear (&bb_info
->init
);
3971 bitmap_clear (&bb_info
->in
);
3972 bitmap_clear (&bb_info
->out
);
3977 /* Allocate or reset bitmaps for DF_MD. The solution bits are
3978 not touched unless the block is new. */
3981 df_md_alloc (bitmap all_blocks
)
3983 unsigned int bb_index
;
3985 struct df_md_problem_data
*problem_data
;
3987 df_grow_bb_info (df_md
);
3988 if (df_md
->problem_data
)
3989 problem_data
= (struct df_md_problem_data
*) df_md
->problem_data
;
3992 problem_data
= XNEW (struct df_md_problem_data
);
3993 df_md
->problem_data
= problem_data
;
3994 bitmap_obstack_initialize (&problem_data
->md_bitmaps
);
3996 bitmap_initialize (&df_md_scratch
, &problem_data
->md_bitmaps
);
3998 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4000 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4001 /* When bitmaps are already initialized, just clear them. */
4002 if (bb_info
->init
.obstack
)
4004 bitmap_clear (&bb_info
->init
);
4005 bitmap_clear (&bb_info
->gen
);
4006 bitmap_clear (&bb_info
->kill
);
4007 bitmap_clear (&bb_info
->in
);
4008 bitmap_clear (&bb_info
->out
);
4012 bitmap_initialize (&bb_info
->init
, &problem_data
->md_bitmaps
);
4013 bitmap_initialize (&bb_info
->gen
, &problem_data
->md_bitmaps
);
4014 bitmap_initialize (&bb_info
->kill
, &problem_data
->md_bitmaps
);
4015 bitmap_initialize (&bb_info
->in
, &problem_data
->md_bitmaps
);
4016 bitmap_initialize (&bb_info
->out
, &problem_data
->md_bitmaps
);
4020 df_md
->optional_p
= true;
4023 /* Add the effect of the top artificial defs of BB to the multiple definitions
4027 df_md_simulate_artificial_defs_at_top (basic_block bb
, bitmap local_md
)
4029 int bb_index
= bb
->index
;
4031 FOR_EACH_ARTIFICIAL_DEF (def
, bb_index
)
4032 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
4034 unsigned int dregno
= DF_REF_REGNO (def
);
4035 if (DF_REF_FLAGS (def
)
4036 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4037 bitmap_set_bit (local_md
, dregno
);
4039 bitmap_clear_bit (local_md
, dregno
);
4044 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4048 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED
, rtx_insn
*insn
,
4053 FOR_EACH_INSN_DEF (def
, insn
)
4055 unsigned int dregno
= DF_REF_REGNO (def
);
4056 if ((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4057 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4059 if (DF_REF_FLAGS (def
)
4060 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4061 bitmap_set_bit (local_md
, DF_REF_ID (def
));
4063 bitmap_clear_bit (local_md
, DF_REF_ID (def
));
4069 df_md_bb_local_compute_process_def (struct df_md_bb_info
*bb_info
,
4073 bitmap_clear (&seen_in_insn
);
4075 for (; def
; def
= DF_REF_NEXT_LOC (def
))
4077 unsigned int dregno
= DF_REF_REGNO (def
);
4078 if (((!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4079 || (dregno
>= FIRST_PSEUDO_REGISTER
))
4080 && top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
4082 if (!bitmap_bit_p (&seen_in_insn
, dregno
))
4084 if (DF_REF_FLAGS (def
)
4085 & (DF_REF_PARTIAL
| DF_REF_CONDITIONAL
| DF_REF_MAY_CLOBBER
))
4087 bitmap_set_bit (&bb_info
->gen
, dregno
);
4088 bitmap_clear_bit (&bb_info
->kill
, dregno
);
4092 /* When we find a clobber and a regular def,
4093 make sure the regular def wins. */
4094 bitmap_set_bit (&seen_in_insn
, dregno
);
4095 bitmap_set_bit (&bb_info
->kill
, dregno
);
4096 bitmap_clear_bit (&bb_info
->gen
, dregno
);
4104 /* Compute local multiple def info for basic block BB. */
4107 df_md_bb_local_compute (unsigned int bb_index
)
4109 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4110 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4113 /* Artificials are only hard regs. */
4114 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4115 df_md_bb_local_compute_process_def (bb_info
,
4116 df_get_artificial_defs (bb_index
),
4119 FOR_BB_INSNS (bb
, insn
)
4121 unsigned int uid
= INSN_UID (insn
);
4125 df_md_bb_local_compute_process_def (bb_info
, DF_INSN_UID_DEFS (uid
), 0);
4128 if (!(df
->changeable_flags
& DF_NO_HARD_REGS
))
4129 df_md_bb_local_compute_process_def (bb_info
,
4130 df_get_artificial_defs (bb_index
),
4134 /* Compute local reaching def info for each basic block within BLOCKS. */
4137 df_md_local_compute (bitmap all_blocks
)
4139 unsigned int bb_index
, df_bb_index
;
4140 bitmap_iterator bi1
, bi2
;
4142 bitmap_head
*frontiers
;
4144 bitmap_initialize (&seen_in_insn
, &bitmap_default_obstack
);
4146 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4148 df_md_bb_local_compute (bb_index
);
4151 bitmap_clear (&seen_in_insn
);
4153 frontiers
= XNEWVEC (bitmap_head
, last_basic_block_for_fn (cfun
));
4154 FOR_ALL_BB_FN (bb
, cfun
)
4155 bitmap_initialize (&frontiers
[bb
->index
], &bitmap_default_obstack
);
4157 compute_dominance_frontiers (frontiers
);
4159 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4160 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi1
)
4162 bitmap kill
= &df_md_get_bb_info (bb_index
)->kill
;
4163 EXECUTE_IF_SET_IN_BITMAP (&frontiers
[bb_index
], 0, df_bb_index
, bi2
)
4165 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, df_bb_index
);
4166 if (bitmap_bit_p (all_blocks
, df_bb_index
))
4167 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index
)->init
, kill
,
4168 df_get_live_in (bb
));
4172 FOR_ALL_BB_FN (bb
, cfun
)
4173 bitmap_clear (&frontiers
[bb
->index
]);
4178 /* Reset the global solution for recalculation. */
4181 df_md_reset (bitmap all_blocks
)
4183 unsigned int bb_index
;
4186 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4188 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4189 gcc_assert (bb_info
);
4190 bitmap_clear (&bb_info
->in
);
4191 bitmap_clear (&bb_info
->out
);
4196 df_md_transfer_function (int bb_index
)
4198 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
4199 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4200 bitmap in
= &bb_info
->in
;
4201 bitmap out
= &bb_info
->out
;
4202 bitmap gen
= &bb_info
->gen
;
4203 bitmap kill
= &bb_info
->kill
;
4205 /* We need to use a scratch set here so that the value returned from this
4206 function invocation properly reflects whether the sets changed in a
4207 significant way; i.e. not just because the live set was anded in. */
4208 bitmap_and (&df_md_scratch
, gen
, df_get_live_out (bb
));
4210 /* Multiple definitions of a register are not relevant if it is not
4211 live. Thus we trim the result to the places where it is live. */
4212 bitmap_and_into (in
, df_get_live_in (bb
));
4214 return bitmap_ior_and_compl (out
, &df_md_scratch
, in
, kill
);
4217 /* Initialize the solution bit vectors for problem. */
4220 df_md_init (bitmap all_blocks
)
4222 unsigned int bb_index
;
4225 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
4227 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb_index
);
4229 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4230 df_md_transfer_function (bb_index
);
4235 df_md_confluence_0 (basic_block bb
)
4237 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4238 bitmap_copy (&bb_info
->in
, &bb_info
->init
);
4241 /* In of target gets or of out of source. */
4244 df_md_confluence_n (edge e
)
4246 bitmap op1
= &df_md_get_bb_info (e
->dest
->index
)->in
;
4247 bitmap op2
= &df_md_get_bb_info (e
->src
->index
)->out
;
4249 if (e
->flags
& EDGE_FAKE
)
4252 if (e
->flags
& EDGE_EH
)
4253 return bitmap_ior_and_compl_into (op1
, op2
,
4254 regs_invalidated_by_call_regset
);
4256 return bitmap_ior_into (op1
, op2
);
4259 /* Free all storage associated with the problem. */
4264 struct df_md_problem_data
*problem_data
4265 = (struct df_md_problem_data
*) df_md
->problem_data
;
4267 bitmap_obstack_release (&problem_data
->md_bitmaps
);
4268 free (problem_data
);
4269 df_md
->problem_data
= NULL
;
4271 df_md
->block_info_size
= 0;
4272 free (df_md
->block_info
);
4273 df_md
->block_info
= NULL
;
4278 /* Debugging info at top of bb. */
4281 df_md_top_dump (basic_block bb
, FILE *file
)
4283 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4287 fprintf (file
, ";; md in \t");
4288 df_print_regset (file
, &bb_info
->in
);
4289 fprintf (file
, ";; md init \t");
4290 df_print_regset (file
, &bb_info
->init
);
4291 fprintf (file
, ";; md gen \t");
4292 df_print_regset (file
, &bb_info
->gen
);
4293 fprintf (file
, ";; md kill \t");
4294 df_print_regset (file
, &bb_info
->kill
);
4297 /* Debugging info at bottom of bb. */
4300 df_md_bottom_dump (basic_block bb
, FILE *file
)
4302 struct df_md_bb_info
*bb_info
= df_md_get_bb_info (bb
->index
);
4306 fprintf (file
, ";; md out \t");
4307 df_print_regset (file
, &bb_info
->out
);
4310 static struct df_problem problem_MD
=
4312 DF_MD
, /* Problem id. */
4313 DF_FORWARD
, /* Direction. */
4314 df_md_alloc
, /* Allocate the problem specific data. */
4315 df_md_reset
, /* Reset global information. */
4316 df_md_free_bb_info
, /* Free basic block info. */
4317 df_md_local_compute
, /* Local compute function. */
4318 df_md_init
, /* Init the solution specific data. */
4319 df_worklist_dataflow
, /* Worklist solver. */
4320 df_md_confluence_0
, /* Confluence operator 0. */
4321 df_md_confluence_n
, /* Confluence operator n. */
4322 df_md_transfer_function
, /* Transfer function. */
4323 NULL
, /* Finalize function. */
4324 df_md_free
, /* Free all of the problem information. */
4325 df_md_free
, /* Remove this problem from the stack of dataflow problems. */
4326 NULL
, /* Debugging. */
4327 df_md_top_dump
, /* Debugging start block. */
4328 df_md_bottom_dump
, /* Debugging end block. */
4329 NULL
, /* Debugging start insn. */
4330 NULL
, /* Debugging end insn. */
4331 NULL
, /* Incremental solution verify start. */
4332 NULL
, /* Incremental solution verify end. */
4333 NULL
, /* Dependent problem. */
4334 sizeof (struct df_md_bb_info
),/* Size of entry of block_info array. */
4335 TV_DF_MD
, /* Timing variable. */
4336 false /* Reset blocks on dropping out of blocks_to_analyze. */
4339 /* Create a new MD instance and add it to the existing instance
4343 df_md_add_problem (void)
4345 df_add_problem (&problem_MD
);