1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
31 #include "insn-config.h"
36 #include "alloc-pool.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
48 /* Note that turning REG_DEAD_DEBUGGING on will cause
49 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
50 addresses in the dumps. */
52 #define REG_DEAD_DEBUGGING
55 #define DF_SPARSE_THRESHOLD 32
57 static bitmap_head seen_in_block;
58 static bitmap_head seen_in_insn;
61 /*----------------------------------------------------------------------------
62 Public functions access functions for the dataflow problems.
63 ----------------------------------------------------------------------------*/
64 /* Get the live at out set for BB no matter what problem happens to be
65 defined. This function is used by the register allocators who
66 choose different dataflow problems depending on the optimization
70 df_get_live_out (basic_block bb)
75 return DF_LIVE_OUT (bb);
77 return DF_LR_OUT (bb);
80 /* Get the live at in set for BB no matter what problem happens to be
81 defined. This function is used by the register allocators who
82 choose different dataflow problems depending on the optimization
86 df_get_live_in (basic_block bb)
91 return DF_LIVE_IN (bb);
96 /*----------------------------------------------------------------------------
98 ----------------------------------------------------------------------------*/
100 /* Generic versions to get the void* version of the block info. Only
101 used inside the problem instance vectors. */
103 /* Dump a def-use or use-def chain for REF to FILE. */
106 df_chain_dump (struct df_link *link, FILE *file)
108 fprintf (file, "{ ");
109 for (; link; link = link->next)
111 fprintf (file, "%c%d(bb %d insn %d) ",
112 DF_REF_REG_DEF_P (link->ref)
114 : (DF_REF_FLAGS (link->ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
115 DF_REF_ID (link->ref),
116 DF_REF_BBNO (link->ref),
117 DF_REF_IS_ARTIFICIAL (link->ref)
118 ? -1 : DF_REF_INSN_UID (link->ref));
124 /* Print some basic block info as part of df_dump. */
127 df_print_bb_index (basic_block bb, FILE *file)
132 fprintf (file, "\n( ");
133 FOR_EACH_EDGE (e, ei, bb->preds)
135 basic_block pred = e->src;
136 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
138 fprintf (file, ")->[%d]->( ", bb->index);
139 FOR_EACH_EDGE (e, ei, bb->succs)
141 basic_block succ = e->dest;
142 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
144 fprintf (file, ")\n");
148 /*----------------------------------------------------------------------------
151 Find the locations in the function where each definition site for a
152 pseudo reaches. In and out bitvectors are built for each basic
153 block. The id field in the ref is used to index into these sets.
154 See df.h for details.
155 ----------------------------------------------------------------------------*/
157 /* This problem plays a large number of games for the sake of
160 1) The order of the bits in the bitvectors. After the scanning
161 phase, all of the defs are sorted. All of the defs for the reg 0
162 are first, followed by all defs for reg 1 and so on.
164 2) There are two kill sets, one if the number of defs is less or
165 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
168 <= : Data is built directly in the kill set.
170 > : One level of indirection is used to keep from generating long
171 strings of 1 bits in the kill sets. Bitvectors that are indexed
172 by the regnum are used to represent that there is a killing def
173 for the register. The confluence and transfer functions use
174 these along with the bitmap_clear_range call to remove ranges of
175 bits without actually generating a knockout vector.
177 The kill and sparse_kill and the dense_invalidated_by_call and
178 sparse_invalidated_by_call both play this game. */
180 /* Private data used to compute the solution for this problem. These
181 data structures are not accessible outside of this module. */
182 struct df_rd_problem_data
184 /* The set of defs to regs invalidated by call. */
185 bitmap_head sparse_invalidated_by_call;
186 /* The set of defs to regs invalidate by call for rd. */
187 bitmap_head dense_invalidated_by_call;
188 /* An obstack for the bitmaps we need for this problem. */
189 bitmap_obstack rd_bitmaps;
193 /* Free basic block info. */
196 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
199 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
202 bitmap_clear (&bb_info->kill);
203 bitmap_clear (&bb_info->sparse_kill);
204 bitmap_clear (&bb_info->gen);
205 bitmap_clear (&bb_info->in);
206 bitmap_clear (&bb_info->out);
211 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
212 not touched unless the block is new. */
215 df_rd_alloc (bitmap all_blocks)
217 unsigned int bb_index;
219 struct df_rd_problem_data *problem_data;
221 if (df_rd->problem_data)
223 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
224 bitmap_clear (&problem_data->sparse_invalidated_by_call);
225 bitmap_clear (&problem_data->dense_invalidated_by_call);
229 problem_data = XNEW (struct df_rd_problem_data);
230 df_rd->problem_data = problem_data;
232 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
233 bitmap_initialize (&problem_data->sparse_invalidated_by_call,
234 &problem_data->rd_bitmaps);
235 bitmap_initialize (&problem_data->dense_invalidated_by_call,
236 &problem_data->rd_bitmaps);
239 df_grow_bb_info (df_rd);
241 /* Because of the clustering of all use sites for the same pseudo,
242 we have to process all of the blocks before doing the
245 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
247 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
249 /* When bitmaps are already initialized, just clear them. */
250 if (bb_info->kill.obstack)
252 bitmap_clear (&bb_info->kill);
253 bitmap_clear (&bb_info->sparse_kill);
254 bitmap_clear (&bb_info->gen);
258 bitmap_initialize (&bb_info->kill, &problem_data->rd_bitmaps);
259 bitmap_initialize (&bb_info->sparse_kill, &problem_data->rd_bitmaps);
260 bitmap_initialize (&bb_info->gen, &problem_data->rd_bitmaps);
261 bitmap_initialize (&bb_info->in, &problem_data->rd_bitmaps);
262 bitmap_initialize (&bb_info->out, &problem_data->rd_bitmaps);
265 df_rd->optional_p = true;
269 /* Add the effect of the top artificial defs of BB to the reaching definitions
273 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
275 int bb_index = bb->index;
277 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
279 df_ref def = *def_rec;
280 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
282 unsigned int dregno = DF_REF_REGNO (def);
283 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
284 bitmap_clear_range (local_rd,
285 DF_DEFS_BEGIN (dregno),
286 DF_DEFS_COUNT (dregno));
287 bitmap_set_bit (local_rd, DF_REF_ID (def));
292 /* Add the effect of the defs of INSN to the reaching definitions bitmap
296 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
299 unsigned uid = INSN_UID (insn);
302 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
304 df_ref def = *def_rec;
305 unsigned int dregno = DF_REF_REGNO (def);
306 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
307 || (dregno >= FIRST_PSEUDO_REGISTER))
309 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
310 bitmap_clear_range (local_rd,
311 DF_DEFS_BEGIN (dregno),
312 DF_DEFS_COUNT (dregno));
313 if (!(DF_REF_FLAGS (def)
314 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
315 bitmap_set_bit (local_rd, DF_REF_ID (def));
320 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
321 more complicated than just simulating, because we must produce the
322 gen and kill sets and hence deal with the two possible representations
326 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
332 df_ref def = *def_rec;
333 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
335 unsigned int regno = DF_REF_REGNO (def);
336 unsigned int begin = DF_DEFS_BEGIN (regno);
337 unsigned int n_defs = DF_DEFS_COUNT (regno);
339 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
340 || (regno >= FIRST_PSEUDO_REGISTER))
342 /* Only the last def(s) for a regno in the block has any
344 if (!bitmap_bit_p (&seen_in_block, regno))
346 /* The first def for regno in insn gets to knock out the
347 defs from other instructions. */
348 if ((!bitmap_bit_p (&seen_in_insn, regno))
349 /* If the def is to only part of the reg, it does
350 not kill the other defs that reach here. */
351 && (!(DF_REF_FLAGS (def) &
352 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
354 if (n_defs > DF_SPARSE_THRESHOLD)
356 bitmap_set_bit (&bb_info->sparse_kill, regno);
357 bitmap_clear_range(&bb_info->gen, begin, n_defs);
361 bitmap_set_range (&bb_info->kill, begin, n_defs);
362 bitmap_clear_range (&bb_info->gen, begin, n_defs);
366 bitmap_set_bit (&seen_in_insn, regno);
367 /* All defs for regno in the instruction may be put into
369 if (!(DF_REF_FLAGS (def)
370 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
371 bitmap_set_bit (&bb_info->gen, DF_REF_ID (def));
379 /* Compute local reaching def info for basic block BB. */
382 df_rd_bb_local_compute (unsigned int bb_index)
384 basic_block bb = BASIC_BLOCK (bb_index);
385 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
388 bitmap_clear (&seen_in_block);
389 bitmap_clear (&seen_in_insn);
391 /* Artificials are only hard regs. */
392 if (!(df->changeable_flags & DF_NO_HARD_REGS))
393 df_rd_bb_local_compute_process_def (bb_info,
394 df_get_artificial_defs (bb_index),
397 FOR_BB_INSNS_REVERSE (bb, insn)
399 unsigned int uid = INSN_UID (insn);
404 df_rd_bb_local_compute_process_def (bb_info,
405 DF_INSN_UID_DEFS (uid), 0);
407 /* This complex dance with the two bitmaps is required because
408 instructions can assign twice to the same pseudo. This
409 generally happens with calls that will have one def for the
410 result and another def for the clobber. If only one vector
411 is used and the clobber goes first, the result will be
413 bitmap_ior_into (&seen_in_block, &seen_in_insn);
414 bitmap_clear (&seen_in_insn);
417 /* Process the artificial defs at the top of the block last since we
418 are going backwards through the block and these are logically at
420 if (!(df->changeable_flags & DF_NO_HARD_REGS))
421 df_rd_bb_local_compute_process_def (bb_info,
422 df_get_artificial_defs (bb_index),
427 /* Compute local reaching def info for each basic block within BLOCKS. */
430 df_rd_local_compute (bitmap all_blocks)
432 unsigned int bb_index;
435 struct df_rd_problem_data *problem_data
436 = (struct df_rd_problem_data *) df_rd->problem_data;
437 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
438 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
440 bitmap_initialize (&seen_in_block, &df_bitmap_obstack);
441 bitmap_initialize (&seen_in_insn, &df_bitmap_obstack);
443 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
445 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
447 df_rd_bb_local_compute (bb_index);
450 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
451 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, regno, bi)
453 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
454 bitmap_set_bit (sparse_invalidated, regno);
456 bitmap_set_range (dense_invalidated,
457 DF_DEFS_BEGIN (regno),
458 DF_DEFS_COUNT (regno));
461 bitmap_clear (&seen_in_block);
462 bitmap_clear (&seen_in_insn);
466 /* Initialize the solution bit vectors for problem. */
469 df_rd_init_solution (bitmap all_blocks)
471 unsigned int bb_index;
474 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
476 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
478 bitmap_copy (&bb_info->out, &bb_info->gen);
479 bitmap_clear (&bb_info->in);
483 /* In of target gets or of out of source. */
486 df_rd_confluence_n (edge e)
488 bitmap op1 = &df_rd_get_bb_info (e->dest->index)->in;
489 bitmap op2 = &df_rd_get_bb_info (e->src->index)->out;
490 bool changed = false;
492 if (e->flags & EDGE_FAKE)
495 if (e->flags & EDGE_EH)
497 struct df_rd_problem_data *problem_data
498 = (struct df_rd_problem_data *) df_rd->problem_data;
499 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
500 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
505 bitmap_initialize (&tmp, &df_bitmap_obstack);
506 bitmap_copy (&tmp, op2);
507 bitmap_and_compl_into (&tmp, dense_invalidated);
509 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
511 bitmap_clear_range (&tmp,
512 DF_DEFS_BEGIN (regno),
513 DF_DEFS_COUNT (regno));
515 changed |= bitmap_ior_into (op1, &tmp);
520 return bitmap_ior_into (op1, op2);
524 /* Transfer function. */
527 df_rd_transfer_function (int bb_index)
529 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
532 bitmap in = &bb_info->in;
533 bitmap out = &bb_info->out;
534 bitmap gen = &bb_info->gen;
535 bitmap kill = &bb_info->kill;
536 bitmap sparse_kill = &bb_info->sparse_kill;
538 if (bitmap_empty_p (sparse_kill))
539 return bitmap_ior_and_compl (out, gen, in, kill);
542 struct df_rd_problem_data *problem_data;
543 bool changed = false;
546 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
547 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
548 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
549 bitmap_initialize (&tmp, &problem_data->rd_bitmaps);
551 bitmap_copy (&tmp, in);
552 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
554 bitmap_clear_range (&tmp,
555 DF_DEFS_BEGIN (regno),
556 DF_DEFS_COUNT (regno));
558 bitmap_and_compl_into (&tmp, kill);
559 bitmap_ior_into (&tmp, gen);
560 changed = !bitmap_equal_p (&tmp, out);
573 /* Free all storage associated with the problem. */
578 struct df_rd_problem_data *problem_data
579 = (struct df_rd_problem_data *) df_rd->problem_data;
583 bitmap_obstack_release (&problem_data->rd_bitmaps);
585 df_rd->block_info_size = 0;
586 free (df_rd->block_info);
587 df_rd->block_info = NULL;
588 free (df_rd->problem_data);
594 /* Debugging info. */
597 df_rd_start_dump (FILE *file)
599 struct df_rd_problem_data *problem_data
600 = (struct df_rd_problem_data *) df_rd->problem_data;
601 unsigned int m = DF_REG_SIZE(df);
604 if (!df_rd->block_info)
607 fprintf (file, ";; Reaching defs:\n\n");
609 fprintf (file, " sparse invalidated \t");
610 dump_bitmap (file, &problem_data->sparse_invalidated_by_call);
611 fprintf (file, " dense invalidated \t");
612 dump_bitmap (file, &problem_data->dense_invalidated_by_call);
614 for (regno = 0; regno < m; regno++)
615 if (DF_DEFS_COUNT (regno))
616 fprintf (file, "%d[%d,%d] ", regno,
617 DF_DEFS_BEGIN (regno),
618 DF_DEFS_COUNT (regno));
619 fprintf (file, "\n");
624 /* Debugging info at top of bb. */
627 df_rd_top_dump (basic_block bb, FILE *file)
629 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
633 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (&bb_info->in));
634 dump_bitmap (file, &bb_info->in);
635 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (&bb_info->gen));
636 dump_bitmap (file, &bb_info->gen);
637 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (&bb_info->kill));
638 dump_bitmap (file, &bb_info->kill);
642 /* Debugging info at top of bb. */
645 df_rd_bottom_dump (basic_block bb, FILE *file)
647 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
651 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (&bb_info->out));
652 dump_bitmap (file, &bb_info->out);
655 /* All of the information associated with every instance of the problem. */
657 static struct df_problem problem_RD =
659 DF_RD, /* Problem id. */
660 DF_FORWARD, /* Direction. */
661 df_rd_alloc, /* Allocate the problem specific data. */
662 NULL, /* Reset global information. */
663 df_rd_free_bb_info, /* Free basic block info. */
664 df_rd_local_compute, /* Local compute function. */
665 df_rd_init_solution, /* Init the solution specific data. */
666 df_worklist_dataflow, /* Worklist solver. */
667 NULL, /* Confluence operator 0. */
668 df_rd_confluence_n, /* Confluence operator n. */
669 df_rd_transfer_function, /* Transfer function. */
670 NULL, /* Finalize function. */
671 df_rd_free, /* Free all of the problem information. */
672 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
673 df_rd_start_dump, /* Debugging. */
674 df_rd_top_dump, /* Debugging start block. */
675 df_rd_bottom_dump, /* Debugging end block. */
676 NULL, /* Incremental solution verify start. */
677 NULL, /* Incremental solution verify end. */
678 NULL, /* Dependent problem. */
679 sizeof (struct df_rd_bb_info),/* Size of entry of block_info array. */
680 TV_DF_RD, /* Timing variable. */
681 true /* Reset blocks on dropping out of blocks_to_analyze. */
686 /* Create a new RD instance and add it to the existing instance
690 df_rd_add_problem (void)
692 df_add_problem (&problem_RD);
697 /*----------------------------------------------------------------------------
700 Find the locations in the function where any use of a pseudo can
701 reach in the backwards direction. In and out bitvectors are built
702 for each basic block. The regno is used to index into these sets.
703 See df.h for details.
704 ----------------------------------------------------------------------------*/
706 /* Private data used to verify the solution for this problem. */
707 struct df_lr_problem_data
711 /* An obstack for the bitmaps we need for this problem. */
712 bitmap_obstack lr_bitmaps;
715 /* Free basic block info. */
718 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
721 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
724 bitmap_clear (&bb_info->use);
725 bitmap_clear (&bb_info->def);
726 bitmap_clear (&bb_info->in);
727 bitmap_clear (&bb_info->out);
732 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
733 not touched unless the block is new. */
736 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
738 unsigned int bb_index;
740 struct df_lr_problem_data *problem_data;
742 df_grow_bb_info (df_lr);
743 if (df_lr->problem_data)
744 problem_data = (struct df_lr_problem_data *) df_lr->problem_data;
747 problem_data = XNEW (struct df_lr_problem_data);
748 df_lr->problem_data = problem_data;
750 problem_data->out = NULL;
751 problem_data->in = NULL;
752 bitmap_obstack_initialize (&problem_data->lr_bitmaps);
755 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
757 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
759 /* When bitmaps are already initialized, just clear them. */
760 if (bb_info->use.obstack)
762 bitmap_clear (&bb_info->def);
763 bitmap_clear (&bb_info->use);
767 bitmap_initialize (&bb_info->use, &problem_data->lr_bitmaps);
768 bitmap_initialize (&bb_info->def, &problem_data->lr_bitmaps);
769 bitmap_initialize (&bb_info->in, &problem_data->lr_bitmaps);
770 bitmap_initialize (&bb_info->out, &problem_data->lr_bitmaps);
774 df_lr->optional_p = false;
778 /* Reset the global solution for recalculation. */
781 df_lr_reset (bitmap all_blocks)
783 unsigned int bb_index;
786 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
788 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
789 gcc_assert (bb_info);
790 bitmap_clear (&bb_info->in);
791 bitmap_clear (&bb_info->out);
796 /* Compute local live register info for basic block BB. */
799 df_lr_bb_local_compute (unsigned int bb_index)
801 basic_block bb = BASIC_BLOCK (bb_index);
802 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
807 /* Process the registers set in an exception handler. */
808 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
810 df_ref def = *def_rec;
811 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
813 unsigned int dregno = DF_REF_REGNO (def);
814 bitmap_set_bit (&bb_info->def, dregno);
815 bitmap_clear_bit (&bb_info->use, dregno);
819 /* Process the hardware registers that are always live. */
820 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
822 df_ref use = *use_rec;
823 /* Add use to set of uses in this BB. */
824 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
825 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
828 FOR_BB_INSNS_REVERSE (bb, insn)
830 unsigned int uid = INSN_UID (insn);
832 if (!NONDEBUG_INSN_P (insn))
835 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
837 df_ref def = *def_rec;
838 /* If the def is to only part of the reg, it does
839 not kill the other defs that reach here. */
840 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
842 unsigned int dregno = DF_REF_REGNO (def);
843 bitmap_set_bit (&bb_info->def, dregno);
844 bitmap_clear_bit (&bb_info->use, dregno);
848 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
850 df_ref use = *use_rec;
851 /* Add use to set of uses in this BB. */
852 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
856 /* Process the registers set in an exception handler or the hard
857 frame pointer if this block is the target of a non local
859 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
861 df_ref def = *def_rec;
862 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
864 unsigned int dregno = DF_REF_REGNO (def);
865 bitmap_set_bit (&bb_info->def, dregno);
866 bitmap_clear_bit (&bb_info->use, dregno);
871 /* Process the uses that are live into an exception handler. */
872 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
874 df_ref use = *use_rec;
875 /* Add use to set of uses in this BB. */
876 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
877 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
881 /* If the df_live problem is not defined, such as at -O0 and -O1, we
882 still need to keep the luids up to date. This is normally done
883 in the df_live problem since this problem has a forwards
886 df_recompute_luids (bb);
890 /* Compute local live register info for each basic block within BLOCKS. */
893 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
895 unsigned int bb_index;
898 bitmap_clear (&df->hardware_regs_used);
900 /* The all-important stack pointer must always be live. */
901 bitmap_set_bit (&df->hardware_regs_used, STACK_POINTER_REGNUM);
903 /* Before reload, there are a few registers that must be forced
904 live everywhere -- which might not already be the case for
905 blocks within infinite loops. */
906 if (!reload_completed)
908 /* Any reference to any pseudo before reload is a potential
909 reference of the frame pointer. */
910 bitmap_set_bit (&df->hardware_regs_used, FRAME_POINTER_REGNUM);
912 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
913 /* Pseudos with argument area equivalences may require
914 reloading via the argument pointer. */
915 if (fixed_regs[ARG_POINTER_REGNUM])
916 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
919 /* Any constant, or pseudo with constant equivalences, may
920 require reloading from memory using the pic register. */
921 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
922 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
923 bitmap_set_bit (&df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
926 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
928 if (bb_index == EXIT_BLOCK)
930 /* The exit block is special for this problem and its bits are
931 computed from thin air. */
932 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
933 bitmap_copy (&bb_info->use, df->exit_block_uses);
936 df_lr_bb_local_compute (bb_index);
939 bitmap_clear (df_lr->out_of_date_transfer_functions);
943 /* Initialize the solution vectors. */
946 df_lr_init (bitmap all_blocks)
948 unsigned int bb_index;
951 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
953 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
954 bitmap_copy (&bb_info->in, &bb_info->use);
955 bitmap_clear (&bb_info->out);
960 /* Confluence function that processes infinite loops. This might be a
961 noreturn function that throws. And even if it isn't, getting the
962 unwind info right helps debugging. */
964 df_lr_confluence_0 (basic_block bb)
966 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
967 if (bb != EXIT_BLOCK_PTR)
968 bitmap_copy (op1, &df->hardware_regs_used);
972 /* Confluence function that ignores fake edges. */
975 df_lr_confluence_n (edge e)
977 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
978 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
979 bool changed = false;
981 /* Call-clobbered registers die across exception and call edges. */
982 /* ??? Abnormal call edges ignored for the moment, as this gets
983 confused by sibling call edges, which crashes reg-stack. */
984 if (e->flags & EDGE_EH)
985 changed = bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
987 changed = bitmap_ior_into (op1, op2);
989 changed |= bitmap_ior_into (op1, &df->hardware_regs_used);
994 /* Transfer function. */
997 df_lr_transfer_function (int bb_index)
999 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1000 bitmap in = &bb_info->in;
1001 bitmap out = &bb_info->out;
1002 bitmap use = &bb_info->use;
1003 bitmap def = &bb_info->def;
1005 return bitmap_ior_and_compl (in, use, out, def);
1009 /* Run the fast dce as a side effect of building LR. */
1012 df_lr_finalize (bitmap all_blocks)
1014 df_lr->solutions_dirty = false;
1015 if (df->changeable_flags & DF_LR_RUN_DCE)
1019 /* If dce deletes some instructions, we need to recompute the lr
1020 solution before proceeding further. The problem is that fast
1021 dce is a pessimestic dataflow algorithm. In the case where
1022 it deletes a statement S inside of a loop, the uses inside of
1023 S may not be deleted from the dataflow solution because they
1024 were carried around the loop. While it is conservatively
1025 correct to leave these extra bits, the standards of df
1026 require that we maintain the best possible (least fixed
1027 point) solution. The only way to do that is to redo the
1028 iteration from the beginning. See PR35805 for an
1030 if (df_lr->solutions_dirty)
1032 df_clear_flags (DF_LR_RUN_DCE);
1033 df_lr_alloc (all_blocks);
1034 df_lr_local_compute (all_blocks);
1035 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1036 df_lr_finalize (all_blocks);
1037 df_set_flags (DF_LR_RUN_DCE);
1043 /* Free all storage associated with the problem. */
1048 struct df_lr_problem_data *problem_data
1049 = (struct df_lr_problem_data *) df_lr->problem_data;
1050 if (df_lr->block_info)
1053 df_lr->block_info_size = 0;
1054 free (df_lr->block_info);
1055 df_lr->block_info = NULL;
1056 bitmap_obstack_release (&problem_data->lr_bitmaps);
1057 free (df_lr->problem_data);
1058 df_lr->problem_data = NULL;
1061 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1066 /* Debugging info at top of bb. */
1069 df_lr_top_dump (basic_block bb, FILE *file)
1071 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1072 struct df_lr_problem_data *problem_data;
1076 fprintf (file, ";; lr in \t");
1077 df_print_regset (file, &bb_info->in);
1078 if (df_lr->problem_data)
1080 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1081 if (problem_data->in)
1083 fprintf (file, ";; old in \t");
1084 df_print_regset (file, &problem_data->in[bb->index]);
1087 fprintf (file, ";; lr use \t");
1088 df_print_regset (file, &bb_info->use);
1089 fprintf (file, ";; lr def \t");
1090 df_print_regset (file, &bb_info->def);
1094 /* Debugging info at bottom of bb. */
1097 df_lr_bottom_dump (basic_block bb, FILE *file)
1099 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1100 struct df_lr_problem_data *problem_data;
1104 fprintf (file, ";; lr out \t");
1105 df_print_regset (file, &bb_info->out);
1106 if (df_lr->problem_data)
1108 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1109 if (problem_data->out)
1111 fprintf (file, ";; old out \t");
1112 df_print_regset (file, &problem_data->out[bb->index]);
1118 /* Build the datastructure to verify that the solution to the dataflow
1119 equations is not dirty. */
1122 df_lr_verify_solution_start (void)
1125 struct df_lr_problem_data *problem_data;
1126 if (df_lr->solutions_dirty)
1129 /* Set it true so that the solution is recomputed. */
1130 df_lr->solutions_dirty = true;
1132 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1133 problem_data->in = XNEWVEC (bitmap_head, last_basic_block);
1134 problem_data->out = XNEWVEC (bitmap_head, last_basic_block);
1138 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1139 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1140 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1141 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1146 /* Compare the saved datastructure and the new solution to the dataflow
1150 df_lr_verify_solution_end (void)
1152 struct df_lr_problem_data *problem_data;
1155 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1157 if (!problem_data->out)
1160 if (df_lr->solutions_dirty)
1161 /* Do not check if the solution is still dirty. See the comment
1162 in df_lr_finalize for details. */
1163 df_lr->solutions_dirty = false;
1167 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1168 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1170 /*df_dump (stderr);*/
1175 /* Cannot delete them immediately because you may want to dump them
1176 if the comparison fails. */
1179 bitmap_clear (&problem_data->in[bb->index]);
1180 bitmap_clear (&problem_data->out[bb->index]);
1183 free (problem_data->in);
1184 free (problem_data->out);
1185 problem_data->in = NULL;
1186 problem_data->out = NULL;
1190 /* All of the information associated with every instance of the problem. */
1192 static struct df_problem problem_LR =
1194 DF_LR, /* Problem id. */
1195 DF_BACKWARD, /* Direction. */
1196 df_lr_alloc, /* Allocate the problem specific data. */
1197 df_lr_reset, /* Reset global information. */
1198 df_lr_free_bb_info, /* Free basic block info. */
1199 df_lr_local_compute, /* Local compute function. */
1200 df_lr_init, /* Init the solution specific data. */
1201 df_worklist_dataflow, /* Worklist solver. */
1202 df_lr_confluence_0, /* Confluence operator 0. */
1203 df_lr_confluence_n, /* Confluence operator n. */
1204 df_lr_transfer_function, /* Transfer function. */
1205 df_lr_finalize, /* Finalize function. */
1206 df_lr_free, /* Free all of the problem information. */
1207 NULL, /* Remove this problem from the stack of dataflow problems. */
1208 NULL, /* Debugging. */
1209 df_lr_top_dump, /* Debugging start block. */
1210 df_lr_bottom_dump, /* Debugging end block. */
1211 df_lr_verify_solution_start,/* Incremental solution verify start. */
1212 df_lr_verify_solution_end, /* Incremental solution verify end. */
1213 NULL, /* Dependent problem. */
1214 sizeof (struct df_lr_bb_info),/* Size of entry of block_info array. */
1215 TV_DF_LR, /* Timing variable. */
1216 false /* Reset blocks on dropping out of blocks_to_analyze. */
1220 /* Create a new DATAFLOW instance and add it to an existing instance
1221 of DF. The returned structure is what is used to get at the
1225 df_lr_add_problem (void)
1227 df_add_problem (&problem_LR);
1228 /* These will be initialized when df_scan_blocks processes each
1230 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1234 /* Verify that all of the lr related info is consistent and
1238 df_lr_verify_transfer_functions (void)
1241 bitmap_head saved_def;
1242 bitmap_head saved_use;
1243 bitmap_head all_blocks;
1248 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1249 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1250 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1254 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1255 bitmap_set_bit (&all_blocks, bb->index);
1259 /* Make a copy of the transfer functions and then compute
1260 new ones to see if the transfer functions have
1262 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1265 bitmap_copy (&saved_def, &bb_info->def);
1266 bitmap_copy (&saved_use, &bb_info->use);
1267 bitmap_clear (&bb_info->def);
1268 bitmap_clear (&bb_info->use);
1270 df_lr_bb_local_compute (bb->index);
1271 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1272 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1277 /* If we do not have basic block info, the block must be in
1278 the list of dirty blocks or else some one has added a
1279 block behind our backs. */
1280 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1283 /* Make sure no one created a block without following
1285 gcc_assert (df_scan_get_bb_info (bb->index));
1288 /* Make sure there are no dirty bits in blocks that have been deleted. */
1289 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1292 bitmap_clear (&saved_def);
1293 bitmap_clear (&saved_use);
1294 bitmap_clear (&all_blocks);
1299 /*----------------------------------------------------------------------------
1300 LIVE AND MUST-INITIALIZED REGISTERS.
1302 This problem first computes the IN and OUT bitvectors for the
1303 must-initialized registers problems, which is a forward problem.
1304 It gives the set of registers for which we MUST have an available
1305 definition on any path from the entry block to the entry/exit of
1306 a basic block. Sets generate a definition, while clobbers kill
1309 In and out bitvectors are built for each basic block and are indexed by
1310 regnum (see df.h for details). In and out bitvectors in struct
1311 df_live_bb_info actually refers to the must-initialized problem;
1313 Then, the in and out sets for the LIVE problem itself are computed.
1314 These are the logical AND of the IN and OUT sets from the LR problem
1315 and the must-initialized problem.
1316 ----------------------------------------------------------------------------*/
1318 /* Private data used to verify the solution for this problem. */
1319 struct df_live_problem_data
1323 /* An obstack for the bitmaps we need for this problem. */
1324 bitmap_obstack live_bitmaps;
1327 /* Scratch var used by transfer functions. This is used to implement
1328 an optimization to reduce the amount of space used to compute the
1329 combined lr and live analysis. */
1330 static bitmap_head df_live_scratch;
1333 /* Free basic block info. */
1336 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1339 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1342 bitmap_clear (&bb_info->gen);
1343 bitmap_clear (&bb_info->kill);
1344 bitmap_clear (&bb_info->in);
1345 bitmap_clear (&bb_info->out);
1350 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1351 not touched unless the block is new. */
1354 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1356 unsigned int bb_index;
1358 struct df_live_problem_data *problem_data;
1360 if (df_live->problem_data)
1361 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1364 problem_data = XNEW (struct df_live_problem_data);
1365 df_live->problem_data = problem_data;
1367 problem_data->out = NULL;
1368 problem_data->in = NULL;
1369 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1370 bitmap_initialize (&df_live_scratch, &problem_data->live_bitmaps);
1373 df_grow_bb_info (df_live);
1375 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1377 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1379 /* When bitmaps are already initialized, just clear them. */
1380 if (bb_info->kill.obstack)
1382 bitmap_clear (&bb_info->kill);
1383 bitmap_clear (&bb_info->gen);
1387 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1388 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1389 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1390 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1393 df_live->optional_p = (optimize <= 1);
1397 /* Reset the global solution for recalculation. */
1400 df_live_reset (bitmap all_blocks)
1402 unsigned int bb_index;
1405 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1407 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1408 gcc_assert (bb_info);
1409 bitmap_clear (&bb_info->in);
1410 bitmap_clear (&bb_info->out);
1415 /* Compute local uninitialized register info for basic block BB. */
1418 df_live_bb_local_compute (unsigned int bb_index)
1420 basic_block bb = BASIC_BLOCK (bb_index);
1421 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1426 FOR_BB_INSNS (bb, insn)
1428 unsigned int uid = INSN_UID (insn);
1429 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1431 /* Inserting labels does not always trigger the incremental
1435 gcc_assert (!INSN_P (insn));
1436 insn_info = df_insn_create_insn_record (insn);
1439 DF_INSN_INFO_LUID (insn_info) = luid;
1444 for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)
1446 df_ref def = *def_rec;
1447 unsigned int regno = DF_REF_REGNO (def);
1449 if (DF_REF_FLAGS_IS_SET (def,
1450 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1451 /* All partial or conditional def
1452 seen are included in the gen set. */
1453 bitmap_set_bit (&bb_info->gen, regno);
1454 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1455 /* Only must clobbers for the entire reg destroy the
1457 bitmap_set_bit (&bb_info->kill, regno);
1458 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1459 bitmap_set_bit (&bb_info->gen, regno);
1463 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1465 df_ref def = *def_rec;
1466 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1471 /* Compute local uninitialized register info. */
1474 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1476 unsigned int bb_index;
1479 df_grow_insn_info ();
1481 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1484 df_live_bb_local_compute (bb_index);
1487 bitmap_clear (df_live->out_of_date_transfer_functions);
1491 /* Initialize the solution vectors. */
1494 df_live_init (bitmap all_blocks)
1496 unsigned int bb_index;
1499 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1501 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1502 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1504 /* No register may reach a location where it is not used. Thus
1505 we trim the rr result to the places where it is used. */
1506 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1507 bitmap_clear (&bb_info->in);
1511 /* Forward confluence function that ignores fake edges. */
1514 df_live_confluence_n (edge e)
1516 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1517 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1519 if (e->flags & EDGE_FAKE)
1522 return bitmap_ior_into (op1, op2);
1526 /* Transfer function for the forwards must-initialized problem. */
1529 df_live_transfer_function (int bb_index)
1531 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1532 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1533 bitmap in = &bb_info->in;
1534 bitmap out = &bb_info->out;
1535 bitmap gen = &bb_info->gen;
1536 bitmap kill = &bb_info->kill;
1538 /* We need to use a scratch set here so that the value returned from this
1539 function invocation properly reflects whether the sets changed in a
1540 significant way; i.e. not just because the lr set was anded in. */
1541 bitmap_and (&df_live_scratch, gen, &bb_lr_info->out);
1542 /* No register may reach a location where it is not used. Thus
1543 we trim the rr result to the places where it is used. */
1544 bitmap_and_into (in, &bb_lr_info->in);
1546 return bitmap_ior_and_compl (out, &df_live_scratch, in, kill);
1550 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1553 df_live_finalize (bitmap all_blocks)
1556 if (df_live->solutions_dirty)
1559 unsigned int bb_index;
1561 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1563 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1564 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1566 /* No register may reach a location where it is not used. Thus
1567 we trim the rr result to the places where it is used. */
1568 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1569 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1572 df_live->solutions_dirty = false;
1577 /* Free all storage associated with the problem. */
1582 struct df_live_problem_data *problem_data
1583 = (struct df_live_problem_data *) df_live->problem_data;
1584 if (df_live->block_info)
1586 df_live->block_info_size = 0;
1587 free (df_live->block_info);
1588 df_live->block_info = NULL;
1589 bitmap_clear (&df_live_scratch);
1590 bitmap_obstack_release (&problem_data->live_bitmaps);
1591 free (problem_data);
1592 df_live->problem_data = NULL;
1594 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1599 /* Debugging info at top of bb. */
1602 df_live_top_dump (basic_block bb, FILE *file)
1604 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1605 struct df_live_problem_data *problem_data;
1610 fprintf (file, ";; live in \t");
1611 df_print_regset (file, &bb_info->in);
1612 if (df_live->problem_data)
1614 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1615 if (problem_data->in)
1617 fprintf (file, ";; old in \t");
1618 df_print_regset (file, &problem_data->in[bb->index]);
1621 fprintf (file, ";; live gen \t");
1622 df_print_regset (file, &bb_info->gen);
1623 fprintf (file, ";; live kill\t");
1624 df_print_regset (file, &bb_info->kill);
1628 /* Debugging info at bottom of bb. */
1631 df_live_bottom_dump (basic_block bb, FILE *file)
1633 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1634 struct df_live_problem_data *problem_data;
1639 fprintf (file, ";; live out \t");
1640 df_print_regset (file, &bb_info->out);
1641 if (df_live->problem_data)
1643 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1644 if (problem_data->out)
1646 fprintf (file, ";; old out \t");
1647 df_print_regset (file, &problem_data->out[bb->index]);
1653 /* Build the datastructure to verify that the solution to the dataflow
1654 equations is not dirty. */
1657 df_live_verify_solution_start (void)
1660 struct df_live_problem_data *problem_data;
1661 if (df_live->solutions_dirty)
1664 /* Set it true so that the solution is recomputed. */
1665 df_live->solutions_dirty = true;
1667 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1668 problem_data->in = XNEWVEC (bitmap_head, last_basic_block);
1669 problem_data->out = XNEWVEC (bitmap_head, last_basic_block);
1673 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1674 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1675 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1676 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1681 /* Compare the saved datastructure and the new solution to the dataflow
1685 df_live_verify_solution_end (void)
1687 struct df_live_problem_data *problem_data;
1690 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1691 if (!problem_data->out)
1696 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1697 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1699 /*df_dump (stderr);*/
1704 /* Cannot delete them immediately because you may want to dump them
1705 if the comparison fails. */
1708 bitmap_clear (&problem_data->in[bb->index]);
1709 bitmap_clear (&problem_data->out[bb->index]);
1712 free (problem_data->in);
1713 free (problem_data->out);
1714 free (problem_data);
1715 df_live->problem_data = NULL;
1719 /* All of the information associated with every instance of the problem. */
1721 static struct df_problem problem_LIVE =
1723 DF_LIVE, /* Problem id. */
1724 DF_FORWARD, /* Direction. */
1725 df_live_alloc, /* Allocate the problem specific data. */
1726 df_live_reset, /* Reset global information. */
1727 df_live_free_bb_info, /* Free basic block info. */
1728 df_live_local_compute, /* Local compute function. */
1729 df_live_init, /* Init the solution specific data. */
1730 df_worklist_dataflow, /* Worklist solver. */
1731 NULL, /* Confluence operator 0. */
1732 df_live_confluence_n, /* Confluence operator n. */
1733 df_live_transfer_function, /* Transfer function. */
1734 df_live_finalize, /* Finalize function. */
1735 df_live_free, /* Free all of the problem information. */
1736 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1737 NULL, /* Debugging. */
1738 df_live_top_dump, /* Debugging start block. */
1739 df_live_bottom_dump, /* Debugging end block. */
1740 df_live_verify_solution_start,/* Incremental solution verify start. */
1741 df_live_verify_solution_end, /* Incremental solution verify end. */
1742 &problem_LR, /* Dependent problem. */
1743 sizeof (struct df_live_bb_info),/* Size of entry of block_info array. */
1744 TV_DF_LIVE, /* Timing variable. */
1745 false /* Reset blocks on dropping out of blocks_to_analyze. */
1749 /* Create a new DATAFLOW instance and add it to an existing instance
1750 of DF. The returned structure is what is used to get at the
1754 df_live_add_problem (void)
1756 df_add_problem (&problem_LIVE);
1757 /* These will be initialized when df_scan_blocks processes each
1759 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1763 /* Set all of the blocks as dirty. This needs to be done if this
1764 problem is added after all of the insns have been scanned. */
1767 df_live_set_all_dirty (void)
1771 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1776 /* Verify that all of the lr related info is consistent and
1780 df_live_verify_transfer_functions (void)
1783 bitmap_head saved_gen;
1784 bitmap_head saved_kill;
1785 bitmap_head all_blocks;
1790 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1791 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1792 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1794 df_grow_insn_info ();
1798 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1799 bitmap_set_bit (&all_blocks, bb->index);
1803 /* Make a copy of the transfer functions and then compute
1804 new ones to see if the transfer functions have
1806 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1809 bitmap_copy (&saved_gen, &bb_info->gen);
1810 bitmap_copy (&saved_kill, &bb_info->kill);
1811 bitmap_clear (&bb_info->gen);
1812 bitmap_clear (&bb_info->kill);
1814 df_live_bb_local_compute (bb->index);
1815 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1816 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1821 /* If we do not have basic block info, the block must be in
1822 the list of dirty blocks or else some one has added a
1823 block behind our backs. */
1824 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1827 /* Make sure no one created a block without following
1829 gcc_assert (df_scan_get_bb_info (bb->index));
1832 /* Make sure there are no dirty bits in blocks that have been deleted. */
1833 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1835 bitmap_clear (&saved_gen);
1836 bitmap_clear (&saved_kill);
1837 bitmap_clear (&all_blocks);
1840 /*----------------------------------------------------------------------------
1841 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1843 Link either the defs to the uses and / or the uses to the defs.
1845 These problems are set up like the other dataflow problems so that
1846 they nicely fit into the framework. They are much simpler and only
1847 involve a single traversal of instructions and an examination of
1848 the reaching defs information (the dependent problem).
1849 ----------------------------------------------------------------------------*/
1851 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1853 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1856 df_chain_create (df_ref src, df_ref dst)
1858 struct df_link *head = DF_REF_CHAIN (src);
1859 struct df_link *link = (struct df_link *) pool_alloc (df_chain->block_pool);
1861 DF_REF_CHAIN (src) = link;
1868 /* Delete any du or ud chains that start at REF and point to
1871 df_chain_unlink_1 (df_ref ref, df_ref target)
1873 struct df_link *chain = DF_REF_CHAIN (ref);
1874 struct df_link *prev = NULL;
1878 if (chain->ref == target)
1881 prev->next = chain->next;
1883 DF_REF_CHAIN (ref) = chain->next;
1884 pool_free (df_chain->block_pool, chain);
1888 chain = chain->next;
1893 /* Delete a du or ud chain that leave or point to REF. */
1896 df_chain_unlink (df_ref ref)
1898 struct df_link *chain = DF_REF_CHAIN (ref);
1901 struct df_link *next = chain->next;
1902 /* Delete the other side if it exists. */
1903 df_chain_unlink_1 (chain->ref, ref);
1904 pool_free (df_chain->block_pool, chain);
1907 DF_REF_CHAIN (ref) = NULL;
1911 /* Copy the du or ud chain starting at FROM_REF and attach it to
1915 df_chain_copy (df_ref to_ref,
1916 struct df_link *from_ref)
1920 df_chain_create (to_ref, from_ref->ref);
1921 from_ref = from_ref->next;
1926 /* Remove this problem from the stack of dataflow problems. */
1929 df_chain_remove_problem (void)
1932 unsigned int bb_index;
1934 /* Wholesale destruction of the old chains. */
1935 if (df_chain->block_pool)
1936 free_alloc_pool (df_chain->block_pool);
1938 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1943 basic_block bb = BASIC_BLOCK (bb_index);
1945 if (df_chain_problem_p (DF_DU_CHAIN))
1946 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1947 DF_REF_CHAIN (*def_rec) = NULL;
1948 if (df_chain_problem_p (DF_UD_CHAIN))
1949 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1950 DF_REF_CHAIN (*use_rec) = NULL;
1952 FOR_BB_INSNS (bb, insn)
1954 unsigned int uid = INSN_UID (insn);
1958 if (df_chain_problem_p (DF_DU_CHAIN))
1959 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1960 DF_REF_CHAIN (*def_rec) = NULL;
1961 if (df_chain_problem_p (DF_UD_CHAIN))
1963 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1964 DF_REF_CHAIN (*use_rec) = NULL;
1965 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
1966 DF_REF_CHAIN (*use_rec) = NULL;
1972 bitmap_clear (df_chain->out_of_date_transfer_functions);
1973 df_chain->block_pool = NULL;
1977 /* Remove the chain problem completely. */
1980 df_chain_fully_remove_problem (void)
1982 df_chain_remove_problem ();
1983 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
1988 /* Create def-use or use-def chains. */
1991 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1993 df_chain_remove_problem ();
1994 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
1995 sizeof (struct df_link), 50);
1996 df_chain->optional_p = true;
2000 /* Reset all of the chains when the set of basic blocks changes. */
2003 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2005 df_chain_remove_problem ();
2009 /* Create the chains for a list of USEs. */
2012 df_chain_create_bb_process_use (bitmap local_rd,
2017 unsigned int def_index;
2021 df_ref use = *use_rec;
2022 unsigned int uregno = DF_REF_REGNO (use);
2023 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2024 || (uregno >= FIRST_PSEUDO_REGISTER))
2026 /* Do not want to go through this for an uninitialized var. */
2027 int count = DF_DEFS_COUNT (uregno);
2030 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2032 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2033 unsigned int last_index = first_index + count - 1;
2035 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2038 if (def_index > last_index)
2041 def = DF_DEFS_GET (def_index);
2042 if (df_chain_problem_p (DF_DU_CHAIN))
2043 df_chain_create (def, use);
2044 if (df_chain_problem_p (DF_UD_CHAIN))
2045 df_chain_create (use, def);
2056 /* Create chains from reaching defs bitmaps for basic block BB. */
2059 df_chain_create_bb (unsigned int bb_index)
2061 basic_block bb = BASIC_BLOCK (bb_index);
2062 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2066 bitmap_initialize (&cpy, &bitmap_default_obstack);
2067 bitmap_copy (&cpy, &bb_info->in);
2068 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2070 /* Since we are going forwards, process the artificial uses first
2071 then the artificial defs second. */
2074 /* Create the chains for the artificial uses from the EH_USES at the
2075 beginning of the block. */
2077 /* Artificials are only hard regs. */
2078 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2079 df_chain_create_bb_process_use (&cpy,
2080 df_get_artificial_uses (bb->index),
2084 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2086 /* Process the regular instructions next. */
2087 FOR_BB_INSNS (bb, insn)
2090 unsigned int uid = INSN_UID (insn);
2092 /* First scan the uses and link them up with the defs that remain
2093 in the cpy vector. */
2094 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2095 if (df->changeable_flags & DF_EQ_NOTES)
2096 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2098 /* Since we are going forwards, process the defs second. */
2099 df_rd_simulate_one_insn (bb, insn, &cpy);
2102 /* Create the chains for the artificial uses of the hard registers
2103 at the end of the block. */
2104 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2105 df_chain_create_bb_process_use (&cpy,
2106 df_get_artificial_uses (bb->index),
2109 bitmap_clear (&cpy);
2112 /* Create def-use chains from reaching use bitmaps for basic blocks
2116 df_chain_finalize (bitmap all_blocks)
2118 unsigned int bb_index;
2121 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2123 df_chain_create_bb (bb_index);
2128 /* Free all storage associated with the problem. */
2131 df_chain_free (void)
2133 free_alloc_pool (df_chain->block_pool);
2134 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2139 /* Debugging info. */
2142 df_chain_top_dump (basic_block bb, FILE *file)
2144 if (df_chain_problem_p (DF_DU_CHAIN))
2147 df_ref *def_rec = df_get_artificial_defs (bb->index);
2151 fprintf (file, ";; DU chains for artificial defs\n");
2154 df_ref def = *def_rec;
2155 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2156 df_chain_dump (DF_REF_CHAIN (def), file);
2157 fprintf (file, "\n");
2162 FOR_BB_INSNS (bb, insn)
2166 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2167 def_rec = DF_INSN_INFO_DEFS (insn_info);
2170 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2171 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2175 df_ref def = *def_rec;
2176 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2177 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2178 fprintf (file, "read/write ");
2179 df_chain_dump (DF_REF_CHAIN (def), file);
2180 fprintf (file, "\n");
2191 df_chain_bottom_dump (basic_block bb, FILE *file)
2193 if (df_chain_problem_p (DF_UD_CHAIN))
2196 df_ref *use_rec = df_get_artificial_uses (bb->index);
2200 fprintf (file, ";; UD chains for artificial uses\n");
2203 df_ref use = *use_rec;
2204 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2205 df_chain_dump (DF_REF_CHAIN (use), file);
2206 fprintf (file, "\n");
2211 FOR_BB_INSNS (bb, insn)
2215 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2216 df_ref *eq_use_rec = DF_INSN_INFO_EQ_USES (insn_info);
2217 use_rec = DF_INSN_INFO_USES (insn_info);
2218 if (*use_rec || *eq_use_rec)
2220 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2221 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2225 df_ref use = *use_rec;
2226 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2227 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2228 fprintf (file, "read/write ");
2229 df_chain_dump (DF_REF_CHAIN (use), file);
2230 fprintf (file, "\n");
2235 df_ref use = *eq_use_rec;
2236 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2237 df_chain_dump (DF_REF_CHAIN (use), file);
2238 fprintf (file, "\n");
2248 static struct df_problem problem_CHAIN =
2250 DF_CHAIN, /* Problem id. */
2251 DF_NONE, /* Direction. */
2252 df_chain_alloc, /* Allocate the problem specific data. */
2253 df_chain_reset, /* Reset global information. */
2254 NULL, /* Free basic block info. */
2255 NULL, /* Local compute function. */
2256 NULL, /* Init the solution specific data. */
2257 NULL, /* Iterative solver. */
2258 NULL, /* Confluence operator 0. */
2259 NULL, /* Confluence operator n. */
2260 NULL, /* Transfer function. */
2261 df_chain_finalize, /* Finalize function. */
2262 df_chain_free, /* Free all of the problem information. */
2263 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2264 NULL, /* Debugging. */
2265 df_chain_top_dump, /* Debugging start block. */
2266 df_chain_bottom_dump, /* Debugging end block. */
2267 NULL, /* Incremental solution verify start. */
2268 NULL, /* Incremental solution verify end. */
2269 &problem_RD, /* Dependent problem. */
2270 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
2271 TV_DF_CHAIN, /* Timing variable. */
2272 false /* Reset blocks on dropping out of blocks_to_analyze. */
2276 /* Create a new DATAFLOW instance and add it to an existing instance
2277 of DF. The returned structure is what is used to get at the
2281 df_chain_add_problem (unsigned int chain_flags)
2283 df_add_problem (&problem_CHAIN);
2284 df_chain->local_flags = chain_flags;
2285 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2288 #undef df_chain_problem_p
2291 /*----------------------------------------------------------------------------
2292 WORD LEVEL LIVE REGISTERS
2294 Find the locations in the function where any use of a pseudo can
2295 reach in the backwards direction. In and out bitvectors are built
2296 for each basic block. We only track pseudo registers that have a
2297 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2298 contain two bits corresponding to each of the subwords.
2300 ----------------------------------------------------------------------------*/
2302 /* Private data used to verify the solution for this problem. */
2303 struct df_word_lr_problem_data
2305 /* An obstack for the bitmaps we need for this problem. */
2306 bitmap_obstack word_lr_bitmaps;
2310 /* Free basic block info. */
2313 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2316 struct df_word_lr_bb_info *bb_info = (struct df_word_lr_bb_info *) vbb_info;
2319 bitmap_clear (&bb_info->use);
2320 bitmap_clear (&bb_info->def);
2321 bitmap_clear (&bb_info->in);
2322 bitmap_clear (&bb_info->out);
2327 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2328 not touched unless the block is new. */
2331 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2333 unsigned int bb_index;
2336 struct df_word_lr_problem_data *problem_data
2337 = XNEW (struct df_word_lr_problem_data);
2339 df_word_lr->problem_data = problem_data;
2341 df_grow_bb_info (df_word_lr);
2343 /* Create the mapping from regnos to slots. This does not change
2344 unless the problem is destroyed and recreated. In particular, if
2345 we end up deleting the only insn that used a subreg, we do not
2346 want to redo the mapping because this would invalidate everything
2349 bitmap_obstack_initialize (&problem_data->word_lr_bitmaps);
2352 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, bb->index);
2354 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2355 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2357 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2359 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2361 /* When bitmaps are already initialized, just clear them. */
2362 if (bb_info->use.obstack)
2364 bitmap_clear (&bb_info->def);
2365 bitmap_clear (&bb_info->use);
2369 bitmap_initialize (&bb_info->use, &problem_data->word_lr_bitmaps);
2370 bitmap_initialize (&bb_info->def, &problem_data->word_lr_bitmaps);
2371 bitmap_initialize (&bb_info->in, &problem_data->word_lr_bitmaps);
2372 bitmap_initialize (&bb_info->out, &problem_data->word_lr_bitmaps);
2376 df_word_lr->optional_p = true;
2380 /* Reset the global solution for recalculation. */
2383 df_word_lr_reset (bitmap all_blocks)
2385 unsigned int bb_index;
2388 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2390 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2391 gcc_assert (bb_info);
2392 bitmap_clear (&bb_info->in);
2393 bitmap_clear (&bb_info->out);
2397 /* Examine REF, and if it is for a reg we're interested in, set or
2398 clear the bits corresponding to its subwords from the bitmap
2399 according to IS_SET. LIVE is the bitmap we should update. We do
2400 not track hard regs or pseudos of any size other than 2 *
2402 We return true if we changed the bitmap, or if we encountered a register
2403 we're not tracking. */
2406 df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
2408 rtx orig_reg = DF_REF_REG (ref);
2410 enum machine_mode reg_mode;
2412 /* Left at -1 for whole accesses. */
2413 int which_subword = -1;
2414 bool changed = false;
2416 if (GET_CODE (reg) == SUBREG)
2417 reg = SUBREG_REG (orig_reg);
2418 regno = REGNO (reg);
2419 reg_mode = GET_MODE (reg);
2420 if (regno < FIRST_PSEUDO_REGISTER
2421 || GET_MODE_SIZE (reg_mode) != 2 * UNITS_PER_WORD)
2424 if (GET_CODE (orig_reg) == SUBREG
2425 && df_read_modify_subreg_p (orig_reg))
2427 gcc_assert (DF_REF_FLAGS_IS_SET (ref, DF_REF_PARTIAL));
2428 if (subreg_lowpart_p (orig_reg))
2435 if (which_subword != 1)
2436 changed |= bitmap_set_bit (live, regno * 2);
2437 if (which_subword != 0)
2438 changed |= bitmap_set_bit (live, regno * 2 + 1);
2442 if (which_subword != 1)
2443 changed |= bitmap_clear_bit (live, regno * 2);
2444 if (which_subword != 0)
2445 changed |= bitmap_clear_bit (live, regno * 2 + 1);
2450 /* Compute local live register info for basic block BB. */
2453 df_word_lr_bb_local_compute (unsigned int bb_index)
2455 basic_block bb = BASIC_BLOCK (bb_index);
2456 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2461 /* Ensure that artificial refs don't contain references to pseudos. */
2462 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2464 df_ref def = *def_rec;
2465 gcc_assert (DF_REF_REGNO (def) < FIRST_PSEUDO_REGISTER);
2468 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2470 df_ref use = *use_rec;
2471 gcc_assert (DF_REF_REGNO (use) < FIRST_PSEUDO_REGISTER);
2474 FOR_BB_INSNS_REVERSE (bb, insn)
2476 unsigned int uid = INSN_UID (insn);
2478 if (!NONDEBUG_INSN_P (insn))
2480 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2482 df_ref def = *def_rec;
2483 /* If the def is to only part of the reg, it does
2484 not kill the other defs that reach here. */
2485 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2487 df_word_lr_mark_ref (def, true, &bb_info->def);
2488 df_word_lr_mark_ref (def, false, &bb_info->use);
2491 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2493 df_ref use = *use_rec;
2494 df_word_lr_mark_ref (use, true, &bb_info->use);
2500 /* Compute local live register info for each basic block within BLOCKS. */
2503 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2505 unsigned int bb_index;
2508 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2510 if (bb_index == EXIT_BLOCK)
2514 EXECUTE_IF_SET_IN_BITMAP (df->exit_block_uses, FIRST_PSEUDO_REGISTER,
2519 df_word_lr_bb_local_compute (bb_index);
2522 bitmap_clear (df_word_lr->out_of_date_transfer_functions);
2526 /* Initialize the solution vectors. */
2529 df_word_lr_init (bitmap all_blocks)
2531 unsigned int bb_index;
2534 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2536 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2537 bitmap_copy (&bb_info->in, &bb_info->use);
2538 bitmap_clear (&bb_info->out);
2543 /* Confluence function that ignores fake edges. */
2546 df_word_lr_confluence_n (edge e)
2548 bitmap op1 = &df_word_lr_get_bb_info (e->src->index)->out;
2549 bitmap op2 = &df_word_lr_get_bb_info (e->dest->index)->in;
2551 return bitmap_ior_into (op1, op2);
2555 /* Transfer function. */
2558 df_word_lr_transfer_function (int bb_index)
2560 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2561 bitmap in = &bb_info->in;
2562 bitmap out = &bb_info->out;
2563 bitmap use = &bb_info->use;
2564 bitmap def = &bb_info->def;
2566 return bitmap_ior_and_compl (in, use, out, def);
2570 /* Free all storage associated with the problem. */
2573 df_word_lr_free (void)
2575 struct df_word_lr_problem_data *problem_data
2576 = (struct df_word_lr_problem_data *)df_word_lr->problem_data;
2578 if (df_word_lr->block_info)
2580 df_word_lr->block_info_size = 0;
2581 free (df_word_lr->block_info);
2582 df_word_lr->block_info = NULL;
2585 BITMAP_FREE (df_word_lr->out_of_date_transfer_functions);
2586 bitmap_obstack_release (&problem_data->word_lr_bitmaps);
2587 free (problem_data);
2592 /* Debugging info at top of bb. */
2595 df_word_lr_top_dump (basic_block bb, FILE *file)
2597 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2601 fprintf (file, ";; blr in \t");
2602 df_print_word_regset (file, &bb_info->in);
2603 fprintf (file, ";; blr use \t");
2604 df_print_word_regset (file, &bb_info->use);
2605 fprintf (file, ";; blr def \t");
2606 df_print_word_regset (file, &bb_info->def);
2610 /* Debugging info at bottom of bb. */
2613 df_word_lr_bottom_dump (basic_block bb, FILE *file)
2615 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2619 fprintf (file, ";; blr out \t");
2620 df_print_word_regset (file, &bb_info->out);
2624 /* All of the information associated with every instance of the problem. */
2626 static struct df_problem problem_WORD_LR =
2628 DF_WORD_LR, /* Problem id. */
2629 DF_BACKWARD, /* Direction. */
2630 df_word_lr_alloc, /* Allocate the problem specific data. */
2631 df_word_lr_reset, /* Reset global information. */
2632 df_word_lr_free_bb_info, /* Free basic block info. */
2633 df_word_lr_local_compute, /* Local compute function. */
2634 df_word_lr_init, /* Init the solution specific data. */
2635 df_worklist_dataflow, /* Worklist solver. */
2636 NULL, /* Confluence operator 0. */
2637 df_word_lr_confluence_n, /* Confluence operator n. */
2638 df_word_lr_transfer_function, /* Transfer function. */
2639 NULL, /* Finalize function. */
2640 df_word_lr_free, /* Free all of the problem information. */
2641 df_word_lr_free, /* Remove this problem from the stack of dataflow problems. */
2642 NULL, /* Debugging. */
2643 df_word_lr_top_dump, /* Debugging start block. */
2644 df_word_lr_bottom_dump, /* Debugging end block. */
2645 NULL, /* Incremental solution verify start. */
2646 NULL, /* Incremental solution verify end. */
2647 NULL, /* Dependent problem. */
2648 sizeof (struct df_word_lr_bb_info),/* Size of entry of block_info array. */
2649 TV_DF_WORD_LR, /* Timing variable. */
2650 false /* Reset blocks on dropping out of blocks_to_analyze. */
2654 /* Create a new DATAFLOW instance and add it to an existing instance
2655 of DF. The returned structure is what is used to get at the
2659 df_word_lr_add_problem (void)
2661 df_add_problem (&problem_WORD_LR);
2662 /* These will be initialized when df_scan_blocks processes each
2664 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2668 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2669 any bits, which is used by the caller to determine whether a set is
2670 necessary. We also return true if there are other reasons not to delete
2674 df_word_lr_simulate_defs (rtx insn, bitmap live)
2676 bool changed = false;
2678 unsigned int uid = INSN_UID (insn);
2680 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2682 df_ref def = *def_rec;
2683 if (DF_REF_FLAGS (def) & DF_REF_CONDITIONAL)
2686 changed |= df_word_lr_mark_ref (*def_rec, false, live);
2692 /* Simulate the effects of the uses of INSN on LIVE. */
2695 df_word_lr_simulate_uses (rtx insn, bitmap live)
2698 unsigned int uid = INSN_UID (insn);
2700 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2701 df_word_lr_mark_ref (*use_rec, true, live);
2704 /*----------------------------------------------------------------------------
2705 This problem computes REG_DEAD and REG_UNUSED notes.
2706 ----------------------------------------------------------------------------*/
2709 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2711 df_note->optional_p = true;
2714 #ifdef REG_DEAD_DEBUGGING
2716 df_print_note (const char *prefix, rtx insn, rtx note)
2720 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2721 print_rtl (dump_file, note);
2722 fprintf (dump_file, "\n");
2728 /* After reg-stack, the x86 floating point stack regs are difficult to
2729 analyze because of all of the pushes, pops and rotations. Thus, we
2730 just leave the notes alone. */
2734 df_ignore_stack_reg (int regno)
2736 return regstack_completed
2737 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2741 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2748 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2749 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
2752 df_kill_notes (rtx insn)
2754 rtx *pprev = ®_NOTES (insn);
2759 switch (REG_NOTE_KIND (link))
2762 /* After reg-stack, we need to ignore any unused notes
2763 for the stack registers. */
2764 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2766 pprev = &XEXP (link, 1);
2771 rtx next = XEXP (link, 1);
2772 #ifdef REG_DEAD_DEBUGGING
2773 df_print_note ("deleting: ", insn, link);
2775 free_EXPR_LIST_node (link);
2776 *pprev = link = next;
2781 /* After reg-stack, we need to ignore any unused notes
2782 for the stack registers. */
2783 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2785 pprev = &XEXP (link, 1);
2790 rtx next = XEXP (link, 1);
2791 #ifdef REG_DEAD_DEBUGGING
2792 df_print_note ("deleting: ", insn, link);
2794 free_EXPR_LIST_node (link);
2795 *pprev = link = next;
2800 pprev = &XEXP (link, 1);
2808 /* Set a NOTE_TYPE note for REG in INSN. */
2811 df_set_note (enum reg_note note_type, rtx insn, rtx reg)
2813 gcc_checking_assert (!DEBUG_INSN_P (insn));
2814 add_reg_note (insn, note_type, reg);
2817 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2818 arguments. Return true if the register value described by MWS's
2819 mw_reg is known to be completely unused, and if mw_reg can therefore
2820 be used in a REG_UNUSED note. */
2823 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2824 bitmap live, bitmap artificial_uses)
2828 /* If MWS describes a partial reference, create REG_UNUSED notes for
2829 individual hard registers. */
2830 if (mws->flags & DF_REF_PARTIAL)
2833 /* Likewise if some part of the register is used. */
2834 for (r = mws->start_regno; r <= mws->end_regno; r++)
2835 if (bitmap_bit_p (live, r)
2836 || bitmap_bit_p (artificial_uses, r))
2839 gcc_assert (REG_P (mws->mw_reg));
2844 /* Node of a linked list of uses of dead REGs in debug insns. */
2845 struct dead_debug_use
2848 struct dead_debug_use *next;
2851 /* Linked list of the above, with a bitmap of the REGs in the
2855 struct dead_debug_use *head;
2860 static void dead_debug_reset (struct dead_debug *, unsigned int);
2863 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2864 based on the bits in LIVE. Do not generate notes for registers in
2865 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2866 not generated if the reg is both read and written by the
2871 df_set_unused_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
2872 bitmap live, bitmap do_not_gen,
2873 bitmap artificial_uses,
2874 struct dead_debug *debug)
2878 #ifdef REG_DEAD_DEBUGGING
2880 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2881 mws->start_regno, mws->end_regno);
2884 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2886 unsigned int regno = mws->start_regno;
2887 df_set_note (REG_UNUSED, insn, mws->mw_reg);
2888 dead_debug_reset (debug, regno);
2890 #ifdef REG_DEAD_DEBUGGING
2891 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2893 bitmap_set_bit (do_not_gen, regno);
2894 /* Only do this if the value is totally dead. */
2897 for (r = mws->start_regno; r <= mws->end_regno; r++)
2899 if (!bitmap_bit_p (live, r)
2900 && !bitmap_bit_p (artificial_uses, r))
2902 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
2903 dead_debug_reset (debug, r);
2904 #ifdef REG_DEAD_DEBUGGING
2905 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2908 bitmap_set_bit (do_not_gen, r);
2913 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2914 arguments. Return true if the register value described by MWS's
2915 mw_reg is known to be completely dead, and if mw_reg can therefore
2916 be used in a REG_DEAD note. */
2919 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2920 bitmap live, bitmap artificial_uses,
2925 /* If MWS describes a partial reference, create REG_DEAD notes for
2926 individual hard registers. */
2927 if (mws->flags & DF_REF_PARTIAL)
2930 /* Likewise if some part of the register is not dead. */
2931 for (r = mws->start_regno; r <= mws->end_regno; r++)
2932 if (bitmap_bit_p (live, r)
2933 || bitmap_bit_p (artificial_uses, r)
2934 || bitmap_bit_p (do_not_gen, r))
2937 gcc_assert (REG_P (mws->mw_reg));
2941 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2942 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2943 from being set if the instruction both reads and writes the
2947 df_set_dead_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
2948 bitmap live, bitmap do_not_gen,
2949 bitmap artificial_uses, bool *added_notes_p)
2952 bool is_debug = *added_notes_p;
2954 *added_notes_p = false;
2956 #ifdef REG_DEAD_DEBUGGING
2959 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2960 mws->start_regno, mws->end_regno);
2961 df_print_regset (dump_file, do_not_gen);
2962 fprintf (dump_file, " live =");
2963 df_print_regset (dump_file, live);
2964 fprintf (dump_file, " artificial uses =");
2965 df_print_regset (dump_file, artificial_uses);
2969 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2971 /* Add a dead note for the entire multi word register. */
2974 *added_notes_p = true;
2977 df_set_note (REG_DEAD, insn, mws->mw_reg);
2978 #ifdef REG_DEAD_DEBUGGING
2979 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2984 for (r = mws->start_regno; r <= mws->end_regno; r++)
2985 if (!bitmap_bit_p (live, r)
2986 && !bitmap_bit_p (artificial_uses, r)
2987 && !bitmap_bit_p (do_not_gen, r))
2991 *added_notes_p = true;
2994 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
2995 #ifdef REG_DEAD_DEBUGGING
2996 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3004 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3005 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3008 df_create_unused_note (rtx insn, df_ref def,
3009 bitmap live, bitmap artificial_uses,
3010 struct dead_debug *debug)
3012 unsigned int dregno = DF_REF_REGNO (def);
3014 #ifdef REG_DEAD_DEBUGGING
3017 fprintf (dump_file, " regular looking at def ");
3018 df_ref_debug (def, dump_file);
3022 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3023 || bitmap_bit_p (live, dregno)
3024 || bitmap_bit_p (artificial_uses, dregno)
3025 || df_ignore_stack_reg (dregno)))
3027 rtx reg = (DF_REF_LOC (def))
3028 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3029 df_set_note (REG_UNUSED, insn, reg);
3030 dead_debug_reset (debug, dregno);
3031 #ifdef REG_DEAD_DEBUGGING
3032 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3040 /* Initialize DEBUG to an empty list, and clear USED, if given. */
3042 dead_debug_init (struct dead_debug *debug, bitmap used)
3046 debug->to_rescan = NULL;
3048 bitmap_clear (used);
3051 /* Reset all debug insns with pending uses. Release the bitmap in it,
3052 unless it is USED. USED must be the same bitmap passed to
3055 dead_debug_finish (struct dead_debug *debug, bitmap used)
3057 struct dead_debug_use *head;
3060 if (debug->used != used)
3061 BITMAP_FREE (debug->used);
3063 while ((head = debug->head))
3065 insn = DF_REF_INSN (head->use);
3066 if (!head->next || DF_REF_INSN (head->next->use) != insn)
3068 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3069 df_insn_rescan_debug_internal (insn);
3070 if (debug->to_rescan)
3071 bitmap_clear_bit (debug->to_rescan, INSN_UID (insn));
3073 debug->head = head->next;
3077 if (debug->to_rescan)
3082 EXECUTE_IF_SET_IN_BITMAP (debug->to_rescan, 0, uid, bi)
3084 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
3086 df_insn_rescan (insn_info->insn);
3088 BITMAP_FREE (debug->to_rescan);
3092 /* Reset DEBUG_INSNs with pending uses of DREGNO. */
3094 dead_debug_reset (struct dead_debug *debug, unsigned int dregno)
3096 struct dead_debug_use **tailp = &debug->head;
3097 struct dead_debug_use *cur;
3100 if (!debug->used || !bitmap_clear_bit (debug->used, dregno))
3103 while ((cur = *tailp))
3105 if (DF_REF_REGNO (cur->use) == dregno)
3108 insn = DF_REF_INSN (cur->use);
3109 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3110 if (debug->to_rescan == NULL)
3111 debug->to_rescan = BITMAP_ALLOC (NULL);
3112 bitmap_set_bit (debug->to_rescan, INSN_UID (insn));
3116 tailp = &(*tailp)->next;
3120 /* Add USE to DEBUG. It must be a dead reference to UREGNO in a debug
3121 insn. Create a bitmap for DEBUG as needed. */
3123 dead_debug_add (struct dead_debug *debug, df_ref use, unsigned int uregno)
3125 struct dead_debug_use *newddu = XNEW (struct dead_debug_use);
3128 newddu->next = debug->head;
3129 debug->head = newddu;
3132 debug->used = BITMAP_ALLOC (NULL);
3134 bitmap_set_bit (debug->used, uregno);
3137 /* If UREGNO is referenced by any entry in DEBUG, emit a debug insn
3138 before INSN that binds the REG to a debug temp, and replace all
3139 uses of UREGNO in DEBUG with uses of the debug temp. INSN must be
3140 the insn where UREGNO dies. */
3142 dead_debug_insert_before (struct dead_debug *debug, unsigned int uregno,
3145 struct dead_debug_use **tailp = &debug->head;
3146 struct dead_debug_use *cur;
3147 struct dead_debug_use *uses = NULL;
3148 struct dead_debug_use **usesp = &uses;
3153 if (!debug->used || !bitmap_clear_bit (debug->used, uregno))
3156 /* Move all uses of uregno from debug->head to uses, setting mode to
3157 the widest referenced mode. */
3158 while ((cur = *tailp))
3160 if (DF_REF_REGNO (cur->use) == uregno)
3167 || (GET_MODE_BITSIZE (GET_MODE (reg))
3168 < GET_MODE_BITSIZE (GET_MODE (*DF_REF_REAL_LOC (cur->use)))))
3169 reg = *DF_REF_REAL_LOC (cur->use);
3172 tailp = &(*tailp)->next;
3177 /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
3178 dval = make_debug_expr_from_rtl (reg);
3180 /* Emit a debug bind insn before the insn in which reg dies. */
3181 bind = gen_rtx_VAR_LOCATION (GET_MODE (reg),
3182 DEBUG_EXPR_TREE_DECL (dval), reg,
3183 VAR_INIT_STATUS_INITIALIZED);
3185 bind = emit_debug_insn_before (bind, insn);
3186 df_insn_rescan (bind);
3188 /* Adjust all uses. */
3189 while ((cur = uses))
3191 if (GET_MODE (*DF_REF_REAL_LOC (cur->use)) == GET_MODE (reg))
3192 *DF_REF_REAL_LOC (cur->use) = dval;
3194 *DF_REF_REAL_LOC (cur->use)
3195 = gen_lowpart_SUBREG (GET_MODE (*DF_REF_REAL_LOC (cur->use)), dval);
3196 /* ??? Should we simplify subreg of subreg? */
3197 if (debug->to_rescan == NULL)
3198 debug->to_rescan = BITMAP_ALLOC (NULL);
3199 bitmap_set_bit (debug->to_rescan, INSN_UID (DF_REF_INSN (cur->use)));
3205 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3206 info: lifetime, bb, and number of defs and uses for basic block
3207 BB. The three bitvectors are scratch regs used here. */
3210 df_note_bb_compute (unsigned int bb_index,
3211 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3213 basic_block bb = BASIC_BLOCK (bb_index);
3217 struct dead_debug debug;
3219 dead_debug_init (&debug, NULL);
3221 bitmap_copy (live, df_get_live_out (bb));
3222 bitmap_clear (artificial_uses);
3224 #ifdef REG_DEAD_DEBUGGING
3227 fprintf (dump_file, "live at bottom ");
3228 df_print_regset (dump_file, live);
3232 /* Process the artificial defs and uses at the bottom of the block
3233 to begin processing. */
3234 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3236 df_ref def = *def_rec;
3237 #ifdef REG_DEAD_DEBUGGING
3239 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3242 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3243 bitmap_clear_bit (live, DF_REF_REGNO (def));
3246 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3248 df_ref use = *use_rec;
3249 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3251 unsigned int regno = DF_REF_REGNO (use);
3252 bitmap_set_bit (live, regno);
3254 /* Notes are not generated for any of the artificial registers
3255 at the bottom of the block. */
3256 bitmap_set_bit (artificial_uses, regno);
3260 #ifdef REG_DEAD_DEBUGGING
3263 fprintf (dump_file, "live before artificials out ");
3264 df_print_regset (dump_file, live);
3268 FOR_BB_INSNS_REVERSE (bb, insn)
3270 unsigned int uid = INSN_UID (insn);
3271 struct df_mw_hardreg **mws_rec;
3277 debug_insn = DEBUG_INSN_P (insn);
3279 bitmap_clear (do_not_gen);
3280 df_kill_notes (insn);
3282 /* Process the defs. */
3285 #ifdef REG_DEAD_DEBUGGING
3288 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3289 df_print_regset (dump_file, live);
3292 /* We only care about real sets for calls. Clobbers cannot
3293 be depended on to really die. */
3294 mws_rec = DF_INSN_UID_MWS (uid);
3297 struct df_mw_hardreg *mws = *mws_rec;
3298 if ((DF_MWS_REG_DEF_P (mws))
3299 && !df_ignore_stack_reg (mws->start_regno))
3300 df_set_unused_notes_for_mw (insn,
3301 mws, live, do_not_gen,
3302 artificial_uses, &debug);
3306 /* All of the defs except the return value are some sort of
3307 clobber. This code is for the return. */
3308 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3310 df_ref def = *def_rec;
3311 unsigned int dregno = DF_REF_REGNO (def);
3312 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3314 df_create_unused_note (insn,
3315 def, live, artificial_uses, &debug);
3316 bitmap_set_bit (do_not_gen, dregno);
3319 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3320 bitmap_clear_bit (live, dregno);
3326 mws_rec = DF_INSN_UID_MWS (uid);
3329 struct df_mw_hardreg *mws = *mws_rec;
3330 if (DF_MWS_REG_DEF_P (mws))
3331 df_set_unused_notes_for_mw (insn,
3332 mws, live, do_not_gen,
3333 artificial_uses, &debug);
3337 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3339 df_ref def = *def_rec;
3340 unsigned int dregno = DF_REF_REGNO (def);
3341 df_create_unused_note (insn,
3342 def, live, artificial_uses, &debug);
3344 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3345 bitmap_set_bit (do_not_gen, dregno);
3347 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3348 bitmap_clear_bit (live, dregno);
3352 /* Process the uses. */
3353 mws_rec = DF_INSN_UID_MWS (uid);
3356 struct df_mw_hardreg *mws = *mws_rec;
3357 if ((DF_MWS_REG_DEF_P (mws))
3358 && !df_ignore_stack_reg (mws->start_regno))
3360 bool really_add_notes = debug_insn != 0;
3362 df_set_dead_notes_for_mw (insn,
3363 mws, live, do_not_gen,
3367 if (really_add_notes)
3373 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3375 df_ref use = *use_rec;
3376 unsigned int uregno = DF_REF_REGNO (use);
3378 #ifdef REG_DEAD_DEBUGGING
3379 if (dump_file && !debug_insn)
3381 fprintf (dump_file, " regular looking at use ");
3382 df_ref_debug (use, dump_file);
3385 if (!bitmap_bit_p (live, uregno))
3391 dead_debug_add (&debug, use, uregno);
3397 dead_debug_insert_before (&debug, uregno, insn);
3399 if ( (!(DF_REF_FLAGS (use)
3400 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3401 && (!bitmap_bit_p (do_not_gen, uregno))
3402 && (!bitmap_bit_p (artificial_uses, uregno))
3403 && (!df_ignore_stack_reg (uregno)))
3405 rtx reg = (DF_REF_LOC (use))
3406 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3407 df_set_note (REG_DEAD, insn, reg);
3409 #ifdef REG_DEAD_DEBUGGING
3410 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3413 /* This register is now live. */
3414 bitmap_set_bit (live, uregno);
3418 if (debug_insn == -1)
3420 /* ??? We could probably do better here, replacing dead
3421 registers with their definitions. */
3422 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3423 df_insn_rescan_debug_internal (insn);
3427 dead_debug_finish (&debug, NULL);
3431 /* Compute register info: lifetime, bb, and number of defs and uses. */
3433 df_note_compute (bitmap all_blocks)
3435 unsigned int bb_index;
3437 bitmap_head live, do_not_gen, artificial_uses;
3439 bitmap_initialize (&live, &df_bitmap_obstack);
3440 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3441 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3443 #ifdef REG_DEAD_DEBUGGING
3445 print_rtl_with_bb (dump_file, get_insns());
3448 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3450 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3453 bitmap_clear (&live);
3454 bitmap_clear (&do_not_gen);
3455 bitmap_clear (&artificial_uses);
3459 /* Free all storage associated with the problem. */
3468 /* All of the information associated every instance of the problem. */
3470 static struct df_problem problem_NOTE =
3472 DF_NOTE, /* Problem id. */
3473 DF_NONE, /* Direction. */
3474 df_note_alloc, /* Allocate the problem specific data. */
3475 NULL, /* Reset global information. */
3476 NULL, /* Free basic block info. */
3477 df_note_compute, /* Local compute function. */
3478 NULL, /* Init the solution specific data. */
3479 NULL, /* Iterative solver. */
3480 NULL, /* Confluence operator 0. */
3481 NULL, /* Confluence operator n. */
3482 NULL, /* Transfer function. */
3483 NULL, /* Finalize function. */
3484 df_note_free, /* Free all of the problem information. */
3485 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3486 NULL, /* Debugging. */
3487 NULL, /* Debugging start block. */
3488 NULL, /* Debugging end block. */
3489 NULL, /* Incremental solution verify start. */
3490 NULL, /* Incremental solution verify end. */
3491 &problem_LR, /* Dependent problem. */
3492 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
3493 TV_DF_NOTE, /* Timing variable. */
3494 false /* Reset blocks on dropping out of blocks_to_analyze. */
3498 /* Create a new DATAFLOW instance and add it to an existing instance
3499 of DF. The returned structure is what is used to get at the
3503 df_note_add_problem (void)
3505 df_add_problem (&problem_NOTE);
3511 /*----------------------------------------------------------------------------
3512 Functions for simulating the effects of single insns.
3514 You can either simulate in the forwards direction, starting from
3515 the top of a block or the backwards direction from the end of the
3516 block. If you go backwards, defs are examined first to clear bits,
3517 then uses are examined to set bits. If you go forwards, defs are
3518 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3519 are examined to clear bits. In either case, the result of examining
3520 a def can be undone (respectively by a use or a REG_UNUSED note).
3522 If you start at the top of the block, use one of DF_LIVE_IN or
3523 DF_LR_IN. If you start at the bottom of the block use one of
3524 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3525 THEY WILL BE DESTROYED.
3526 ----------------------------------------------------------------------------*/
3529 /* Find the set of DEFs for INSN. */
3532 df_simulate_find_defs (rtx insn, bitmap defs)
3535 unsigned int uid = INSN_UID (insn);
3537 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3539 df_ref def = *def_rec;
3540 bitmap_set_bit (defs, DF_REF_REGNO (def));
3544 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3547 df_simulate_find_noclobber_defs (rtx insn, bitmap defs)
3550 unsigned int uid = INSN_UID (insn);
3552 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3554 df_ref def = *def_rec;
3555 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3556 bitmap_set_bit (defs, DF_REF_REGNO (def));
3561 /* Simulate the effects of the defs of INSN on LIVE. */
3564 df_simulate_defs (rtx insn, bitmap live)
3567 unsigned int uid = INSN_UID (insn);
3569 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3571 df_ref def = *def_rec;
3572 unsigned int dregno = DF_REF_REGNO (def);
3574 /* If the def is to only part of the reg, it does
3575 not kill the other defs that reach here. */
3576 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3577 bitmap_clear_bit (live, dregno);
3582 /* Simulate the effects of the uses of INSN on LIVE. */
3585 df_simulate_uses (rtx insn, bitmap live)
3588 unsigned int uid = INSN_UID (insn);
3590 if (DEBUG_INSN_P (insn))
3593 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3595 df_ref use = *use_rec;
3596 /* Add use to set of uses in this BB. */
3597 bitmap_set_bit (live, DF_REF_REGNO (use));
3602 /* Add back the always live regs in BB to LIVE. */
3605 df_simulate_fixup_sets (basic_block bb, bitmap live)
3607 /* These regs are considered always live so if they end up dying
3608 because of some def, we need to bring the back again. */
3609 if (bb_has_eh_pred (bb))
3610 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3612 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3616 /*----------------------------------------------------------------------------
3617 The following three functions are used only for BACKWARDS scanning:
3618 i.e. they process the defs before the uses.
3620 df_simulate_initialize_backwards should be called first with a
3621 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3622 df_simulate_one_insn_backwards should be called for each insn in
3623 the block, starting with the last one. Finally,
3624 df_simulate_finalize_backwards can be called to get a new value
3625 of the sets at the top of the block (this is rarely used).
3626 ----------------------------------------------------------------------------*/
3628 /* Apply the artificial uses and defs at the end of BB in a backwards
3632 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3636 int bb_index = bb->index;
3638 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3640 df_ref def = *def_rec;
3641 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3642 bitmap_clear_bit (live, DF_REF_REGNO (def));
3645 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3647 df_ref use = *use_rec;
3648 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3649 bitmap_set_bit (live, DF_REF_REGNO (use));
3654 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3657 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3659 if (!NONDEBUG_INSN_P (insn))
3662 df_simulate_defs (insn, live);
3663 df_simulate_uses (insn, live);
3664 df_simulate_fixup_sets (bb, live);
3668 /* Apply the artificial uses and defs at the top of BB in a backwards
3672 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3678 int bb_index = bb->index;
3680 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3682 df_ref def = *def_rec;
3683 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3684 bitmap_clear_bit (live, DF_REF_REGNO (def));
3688 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3690 df_ref use = *use_rec;
3691 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3692 bitmap_set_bit (live, DF_REF_REGNO (use));
3696 /*----------------------------------------------------------------------------
3697 The following three functions are used only for FORWARDS scanning:
3698 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3699 Thus it is important to add the DF_NOTES problem to the stack of
3700 problems computed before using these functions.
3702 df_simulate_initialize_forwards should be called first with a
3703 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3704 df_simulate_one_insn_forwards should be called for each insn in
3705 the block, starting with the first one.
3706 ----------------------------------------------------------------------------*/
3708 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3709 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3713 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3716 int bb_index = bb->index;
3718 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3720 df_ref def = *def_rec;
3721 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3722 bitmap_set_bit (live, DF_REF_REGNO (def));
3726 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3729 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3732 if (! INSN_P (insn))
3735 /* Make sure that DF_NOTE really is an active df problem. */
3736 gcc_assert (df_note);
3738 /* Note that this is the opposite as how the problem is defined, because
3739 in the LR problem defs _kill_ liveness. However, they do so backwards,
3740 while here the scan is performed forwards! So, first assume that the
3741 def is live, and if this is not true REG_UNUSED notes will rectify the
3743 df_simulate_find_noclobber_defs (insn, live);
3745 /* Clear all of the registers that go dead. */
3746 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3748 switch (REG_NOTE_KIND (link))
3753 rtx reg = XEXP (link, 0);
3754 int regno = REGNO (reg);
3755 if (regno < FIRST_PSEUDO_REGISTER)
3757 int n = hard_regno_nregs[regno][GET_MODE (reg)];
3759 bitmap_clear_bit (live, regno + n);
3762 bitmap_clear_bit (live, regno);
3769 df_simulate_fixup_sets (bb, live);
3774 /*----------------------------------------------------------------------------
3775 MULTIPLE DEFINITIONS
3777 Find the locations in the function reached by multiple definition sites
3778 for a live pseudo. In and out bitvectors are built for each basic
3779 block. They are restricted for efficiency to live registers.
3781 The gen and kill sets for the problem are obvious. Together they
3782 include all defined registers in a basic block; the gen set includes
3783 registers where a partial or conditional or may-clobber definition is
3784 last in the BB, while the kill set includes registers with a complete
3785 definition coming last. However, the computation of the dataflow
3786 itself is interesting.
3788 The idea behind it comes from SSA form's iterated dominance frontier
3789 criterion for inserting PHI functions. Just like in that case, we can use
3790 the dominance frontier to find places where multiple definitions meet;
3791 a register X defined in a basic block BB1 has multiple definitions in
3792 basic blocks in BB1's dominance frontier.
3794 So, the in-set of a basic block BB2 is not just the union of the
3795 out-sets of BB2's predecessors, but includes some more bits that come
3796 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3797 the previous paragraph). I called this set the init-set of BB2.
3799 (Note: I actually use the kill-set only to build the init-set.
3800 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3802 For example, if you have
3806 if <...> goto BB2 else goto BB3;
3814 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3815 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3816 not need to iterate the dominance frontier, because we do not insert
3817 anything like PHI functions there! Instead, dataflow will take care of
3818 propagating the information to BB3's successors.
3819 ---------------------------------------------------------------------------*/
3821 /* Private data used to verify the solution for this problem. */
3822 struct df_md_problem_data
3824 /* An obstack for the bitmaps we need for this problem. */
3825 bitmap_obstack md_bitmaps;
3828 /* Scratch var used by transfer functions. This is used to do md analysis
3829 only for live registers. */
3830 static bitmap_head df_md_scratch;
3834 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3837 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
3840 bitmap_clear (&bb_info->kill);
3841 bitmap_clear (&bb_info->gen);
3842 bitmap_clear (&bb_info->init);
3843 bitmap_clear (&bb_info->in);
3844 bitmap_clear (&bb_info->out);
3849 /* Allocate or reset bitmaps for DF_MD. The solution bits are
3850 not touched unless the block is new. */
3853 df_md_alloc (bitmap all_blocks)
3855 unsigned int bb_index;
3857 struct df_md_problem_data *problem_data;
3859 df_grow_bb_info (df_md);
3860 if (df_md->problem_data)
3861 problem_data = (struct df_md_problem_data *) df_md->problem_data;
3864 problem_data = XNEW (struct df_md_problem_data);
3865 df_md->problem_data = problem_data;
3866 bitmap_obstack_initialize (&problem_data->md_bitmaps);
3868 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
3870 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3872 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
3873 /* When bitmaps are already initialized, just clear them. */
3874 if (bb_info->init.obstack)
3876 bitmap_clear (&bb_info->init);
3877 bitmap_clear (&bb_info->gen);
3878 bitmap_clear (&bb_info->kill);
3879 bitmap_clear (&bb_info->in);
3880 bitmap_clear (&bb_info->out);
3884 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
3885 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
3886 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
3887 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
3888 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
3892 df_md->optional_p = true;
3895 /* Add the effect of the top artificial defs of BB to the multiple definitions
3899 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
3901 int bb_index = bb->index;
3903 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3905 df_ref def = *def_rec;
3906 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3908 unsigned int dregno = DF_REF_REGNO (def);
3909 if (DF_REF_FLAGS (def)
3910 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
3911 bitmap_set_bit (local_md, dregno);
3913 bitmap_clear_bit (local_md, dregno);
3919 /* Add the effect of the defs of INSN to the reaching definitions bitmap
3923 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
3926 unsigned uid = INSN_UID (insn);
3929 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3931 df_ref def = *def_rec;
3932 unsigned int dregno = DF_REF_REGNO (def);
3933 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
3934 || (dregno >= FIRST_PSEUDO_REGISTER))
3936 if (DF_REF_FLAGS (def)
3937 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
3938 bitmap_set_bit (local_md, DF_REF_ID (def));
3940 bitmap_clear_bit (local_md, DF_REF_ID (def));
3946 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
3951 bitmap_clear (&seen_in_insn);
3953 while ((def = *def_rec++) != NULL)
3955 unsigned int dregno = DF_REF_REGNO (def);
3956 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
3957 || (dregno >= FIRST_PSEUDO_REGISTER))
3958 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
3960 if (!bitmap_bit_p (&seen_in_insn, dregno))
3962 if (DF_REF_FLAGS (def)
3963 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
3965 bitmap_set_bit (&bb_info->gen, dregno);
3966 bitmap_clear_bit (&bb_info->kill, dregno);
3970 /* When we find a clobber and a regular def,
3971 make sure the regular def wins. */
3972 bitmap_set_bit (&seen_in_insn, dregno);
3973 bitmap_set_bit (&bb_info->kill, dregno);
3974 bitmap_clear_bit (&bb_info->gen, dregno);
3982 /* Compute local multiple def info for basic block BB. */
3985 df_md_bb_local_compute (unsigned int bb_index)
3987 basic_block bb = BASIC_BLOCK (bb_index);
3988 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
3991 /* Artificials are only hard regs. */
3992 if (!(df->changeable_flags & DF_NO_HARD_REGS))
3993 df_md_bb_local_compute_process_def (bb_info,
3994 df_get_artificial_defs (bb_index),
3997 FOR_BB_INSNS (bb, insn)
3999 unsigned int uid = INSN_UID (insn);
4003 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4006 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4007 df_md_bb_local_compute_process_def (bb_info,
4008 df_get_artificial_defs (bb_index),
4012 /* Compute local reaching def info for each basic block within BLOCKS. */
4015 df_md_local_compute (bitmap all_blocks)
4017 unsigned int bb_index, df_bb_index;
4018 bitmap_iterator bi1, bi2;
4020 bitmap_head *frontiers;
4022 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4024 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4026 df_md_bb_local_compute (bb_index);
4029 bitmap_clear (&seen_in_insn);
4031 frontiers = XNEWVEC (bitmap_head, last_basic_block);
4033 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4035 compute_dominance_frontiers (frontiers);
4037 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4038 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4040 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4041 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4043 basic_block bb = BASIC_BLOCK (df_bb_index);
4044 if (bitmap_bit_p (all_blocks, df_bb_index))
4045 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4046 df_get_live_in (bb));
4051 bitmap_clear (&frontiers[bb->index]);
4056 /* Reset the global solution for recalculation. */
4059 df_md_reset (bitmap all_blocks)
4061 unsigned int bb_index;
4064 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4066 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4067 gcc_assert (bb_info);
4068 bitmap_clear (&bb_info->in);
4069 bitmap_clear (&bb_info->out);
4074 df_md_transfer_function (int bb_index)
4076 basic_block bb = BASIC_BLOCK (bb_index);
4077 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4078 bitmap in = &bb_info->in;
4079 bitmap out = &bb_info->out;
4080 bitmap gen = &bb_info->gen;
4081 bitmap kill = &bb_info->kill;
4083 /* We need to use a scratch set here so that the value returned from this
4084 function invocation properly reflects whether the sets changed in a
4085 significant way; i.e. not just because the live set was anded in. */
4086 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4088 /* Multiple definitions of a register are not relevant if it is not
4089 live. Thus we trim the result to the places where it is live. */
4090 bitmap_and_into (in, df_get_live_in (bb));
4092 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4095 /* Initialize the solution bit vectors for problem. */
4098 df_md_init (bitmap all_blocks)
4100 unsigned int bb_index;
4103 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4105 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4107 bitmap_copy (&bb_info->in, &bb_info->init);
4108 df_md_transfer_function (bb_index);
4113 df_md_confluence_0 (basic_block bb)
4115 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4116 bitmap_copy (&bb_info->in, &bb_info->init);
4119 /* In of target gets or of out of source. */
4122 df_md_confluence_n (edge e)
4124 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4125 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4127 if (e->flags & EDGE_FAKE)
4130 if (e->flags & EDGE_EH)
4131 return bitmap_ior_and_compl_into (op1, op2,
4132 regs_invalidated_by_call_regset);
4134 return bitmap_ior_into (op1, op2);
4137 /* Free all storage associated with the problem. */
4142 struct df_md_problem_data *problem_data
4143 = (struct df_md_problem_data *) df_md->problem_data;
4145 bitmap_obstack_release (&problem_data->md_bitmaps);
4146 free (problem_data);
4147 df_md->problem_data = NULL;
4149 df_md->block_info_size = 0;
4150 free (df_md->block_info);
4151 df_md->block_info = NULL;
4156 /* Debugging info at top of bb. */
4159 df_md_top_dump (basic_block bb, FILE *file)
4161 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4165 fprintf (file, ";; md in \t");
4166 df_print_regset (file, &bb_info->in);
4167 fprintf (file, ";; md init \t");
4168 df_print_regset (file, &bb_info->init);
4169 fprintf (file, ";; md gen \t");
4170 df_print_regset (file, &bb_info->gen);
4171 fprintf (file, ";; md kill \t");
4172 df_print_regset (file, &bb_info->kill);
4175 /* Debugging info at bottom of bb. */
4178 df_md_bottom_dump (basic_block bb, FILE *file)
4180 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4184 fprintf (file, ";; md out \t");
4185 df_print_regset (file, &bb_info->out);
4188 static struct df_problem problem_MD =
4190 DF_MD, /* Problem id. */
4191 DF_FORWARD, /* Direction. */
4192 df_md_alloc, /* Allocate the problem specific data. */
4193 df_md_reset, /* Reset global information. */
4194 df_md_free_bb_info, /* Free basic block info. */
4195 df_md_local_compute, /* Local compute function. */
4196 df_md_init, /* Init the solution specific data. */
4197 df_worklist_dataflow, /* Worklist solver. */
4198 df_md_confluence_0, /* Confluence operator 0. */
4199 df_md_confluence_n, /* Confluence operator n. */
4200 df_md_transfer_function, /* Transfer function. */
4201 NULL, /* Finalize function. */
4202 df_md_free, /* Free all of the problem information. */
4203 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4204 NULL, /* Debugging. */
4205 df_md_top_dump, /* Debugging start block. */
4206 df_md_bottom_dump, /* Debugging end block. */
4207 NULL, /* Incremental solution verify start. */
4208 NULL, /* Incremental solution verify end. */
4209 NULL, /* Dependent problem. */
4210 sizeof (struct df_md_bb_info),/* Size of entry of block_info array. */
4211 TV_DF_MD, /* Timing variable. */
4212 false /* Reset blocks on dropping out of blocks_to_analyze. */
4215 /* Create a new MD instance and add it to the existing instance
4219 df_md_add_problem (void)
4221 df_add_problem (&problem_MD);