2012-09-04 Janus Weil <janus@gcc.gnu.org>
[official-gcc.git] / gcc / df-problems.c
blobabeb118dd7ea26a8b41c82b1aa7d983a4e965448
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011, 2012 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
14 version.
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
19 for more details.
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/>. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "recog.h"
33 #include "function.h"
34 #include "regs.h"
35 #include "alloc-pool.h"
36 #include "flags.h"
37 #include "hard-reg-set.h"
38 #include "basic-block.h"
39 #include "sbitmap.h"
40 #include "bitmap.h"
41 #include "target.h"
42 #include "timevar.h"
43 #include "df.h"
44 #include "except.h"
45 #include "dce.h"
46 #include "vecprim.h"
47 #include "valtrack.h"
48 #include "dumpfile.h"
50 /* Note that turning REG_DEAD_DEBUGGING on will cause
51 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
52 addresses in the dumps. */
53 #define REG_DEAD_DEBUGGING 0
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
67 level. */
69 bitmap
70 df_get_live_out (basic_block bb)
72 gcc_assert (df_lr);
74 if (df_live)
75 return DF_LIVE_OUT (bb);
76 else
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
83 level. */
85 bitmap
86 df_get_live_in (basic_block bb)
88 gcc_assert (df_lr);
90 if (df_live)
91 return DF_LIVE_IN (bb);
92 else
93 return DF_LR_IN (bb);
96 /*----------------------------------------------------------------------------
97 Utility functions.
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. */
105 void
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)
113 ? 'd'
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));
120 fprintf (file, "}");
124 /* Print some basic block info as part of df_dump. */
126 void
127 df_print_bb_index (basic_block bb, FILE *file)
129 edge e;
130 edge_iterator ei;
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 /*----------------------------------------------------------------------------
149 REACHING DEFINITIONS
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
158 efficiency.
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
166 greater.
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. */
195 static void
196 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
197 void *vbb_info)
199 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
200 if (bb_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. */
214 static void
215 df_rd_alloc (bitmap all_blocks)
217 unsigned int bb_index;
218 bitmap_iterator bi;
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);
227 else
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
243 analysis. */
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);
256 else
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
270 bitmap LOCAL_RD. */
272 void
273 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
275 int bb_index = bb->index;
276 df_ref *def_rec;
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
293 LOCAL_RD. */
295 void
296 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
297 bitmap local_rd)
299 unsigned uid = INSN_UID (insn);
300 df_ref *def_rec;
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
323 of kill sets. */
325 static void
326 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
327 df_ref *def_rec,
328 int top_flag)
330 while (*def_rec)
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
343 effect. */
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);
359 else
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
368 the gen set. */
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));
375 def_rec++;
379 /* Compute local reaching def info for basic block BB. */
381 static void
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);
386 rtx insn;
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);
401 if (!INSN_P (insn))
402 continue;
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
412 lost. */
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
419 the start. */
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),
423 DF_REF_AT_TOP);
427 /* Compute local reaching def info for each basic block within BLOCKS. */
429 static void
430 df_rd_local_compute (bitmap all_blocks)
432 unsigned int bb_index;
433 bitmap_iterator bi;
434 unsigned int regno;
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);
455 else
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. */
468 static void
469 df_rd_init_solution (bitmap all_blocks)
471 unsigned int bb_index;
472 bitmap_iterator bi;
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. */
485 static bool
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)
493 return false;
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;
501 bitmap_iterator bi;
502 unsigned int regno;
503 bitmap_head tmp;
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);
516 bitmap_clear (&tmp);
517 return changed;
519 else
520 return bitmap_ior_into (op1, op2);
524 /* Transfer function. */
526 static bool
527 df_rd_transfer_function (int bb_index)
529 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
530 unsigned int regno;
531 bitmap_iterator bi;
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);
540 else
542 struct df_rd_problem_data *problem_data;
543 bool changed = false;
544 bitmap_head tmp;
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);
561 if (changed)
563 bitmap_clear (out);
564 bb_info->out = tmp;
566 else
567 bitmap_clear (&tmp);
568 return changed;
573 /* Free all storage associated with the problem. */
575 static void
576 df_rd_free (void)
578 struct df_rd_problem_data *problem_data
579 = (struct df_rd_problem_data *) df_rd->problem_data;
581 if (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);
590 free (df_rd);
594 /* Debugging info. */
596 static void
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);
602 unsigned int regno;
604 if (!df_rd->block_info)
605 return;
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. */
626 static void
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);
630 if (!bb_info)
631 return;
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. */
644 static void
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);
648 if (!bb_info)
649 return;
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
687 of DF. */
689 void
690 df_rd_add_problem (void)
692 df_add_problem (&problem_RD);
697 /*----------------------------------------------------------------------------
698 LIVE REGISTERS
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
709 bitmap_head *in;
710 bitmap_head *out;
711 /* An obstack for the bitmaps we need for this problem. */
712 bitmap_obstack lr_bitmaps;
715 /* Free basic block info. */
717 static void
718 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
719 void *vbb_info)
721 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
722 if (bb_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. */
735 static void
736 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
738 unsigned int bb_index;
739 bitmap_iterator bi;
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;
745 else
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);
765 else
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. */
780 static void
781 df_lr_reset (bitmap all_blocks)
783 unsigned int bb_index;
784 bitmap_iterator bi;
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. */
798 static void
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);
803 rtx insn;
804 df_ref *def_rec;
805 df_ref *use_rec;
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))
833 continue;
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
858 goto. */
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);
870 #ifdef EH_USES
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));
879 #endif
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
884 scan. */
885 if (!df_live)
886 df_recompute_luids (bb);
890 /* Compute local live register info for each basic block within BLOCKS. */
892 static void
893 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
895 unsigned int bb_index;
896 bitmap_iterator bi;
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 unsigned int pic_offset_table_regnum = PIC_OFFSET_TABLE_REGNUM;
909 /* Any reference to any pseudo before reload is a potential
910 reference of the frame pointer. */
911 bitmap_set_bit (&df->hardware_regs_used, FRAME_POINTER_REGNUM);
913 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
914 /* Pseudos with argument area equivalences may require
915 reloading via the argument pointer. */
916 if (fixed_regs[ARG_POINTER_REGNUM])
917 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
918 #endif
920 /* Any constant, or pseudo with constant equivalences, may
921 require reloading from memory using the pic register. */
922 if (pic_offset_table_regnum != INVALID_REGNUM
923 && fixed_regs[pic_offset_table_regnum])
924 bitmap_set_bit (&df->hardware_regs_used, pic_offset_table_regnum);
927 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
929 if (bb_index == EXIT_BLOCK)
931 /* The exit block is special for this problem and its bits are
932 computed from thin air. */
933 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
934 bitmap_copy (&bb_info->use, df->exit_block_uses);
936 else
937 df_lr_bb_local_compute (bb_index);
940 bitmap_clear (df_lr->out_of_date_transfer_functions);
944 /* Initialize the solution vectors. */
946 static void
947 df_lr_init (bitmap all_blocks)
949 unsigned int bb_index;
950 bitmap_iterator bi;
952 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
954 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
955 bitmap_copy (&bb_info->in, &bb_info->use);
956 bitmap_clear (&bb_info->out);
961 /* Confluence function that processes infinite loops. This might be a
962 noreturn function that throws. And even if it isn't, getting the
963 unwind info right helps debugging. */
964 static void
965 df_lr_confluence_0 (basic_block bb)
967 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
968 if (bb != EXIT_BLOCK_PTR)
969 bitmap_copy (op1, &df->hardware_regs_used);
973 /* Confluence function that ignores fake edges. */
975 static bool
976 df_lr_confluence_n (edge e)
978 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
979 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
980 bool changed = false;
982 /* Call-clobbered registers die across exception and call edges. */
983 /* ??? Abnormal call edges ignored for the moment, as this gets
984 confused by sibling call edges, which crashes reg-stack. */
985 if (e->flags & EDGE_EH)
986 changed = bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
987 else
988 changed = bitmap_ior_into (op1, op2);
990 changed |= bitmap_ior_into (op1, &df->hardware_regs_used);
991 return changed;
995 /* Transfer function. */
997 static bool
998 df_lr_transfer_function (int bb_index)
1000 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1001 bitmap in = &bb_info->in;
1002 bitmap out = &bb_info->out;
1003 bitmap use = &bb_info->use;
1004 bitmap def = &bb_info->def;
1006 return bitmap_ior_and_compl (in, use, out, def);
1010 /* Run the fast dce as a side effect of building LR. */
1012 static void
1013 df_lr_finalize (bitmap all_blocks)
1015 df_lr->solutions_dirty = false;
1016 if (df->changeable_flags & DF_LR_RUN_DCE)
1018 run_fast_df_dce ();
1020 /* If dce deletes some instructions, we need to recompute the lr
1021 solution before proceeding further. The problem is that fast
1022 dce is a pessimestic dataflow algorithm. In the case where
1023 it deletes a statement S inside of a loop, the uses inside of
1024 S may not be deleted from the dataflow solution because they
1025 were carried around the loop. While it is conservatively
1026 correct to leave these extra bits, the standards of df
1027 require that we maintain the best possible (least fixed
1028 point) solution. The only way to do that is to redo the
1029 iteration from the beginning. See PR35805 for an
1030 example. */
1031 if (df_lr->solutions_dirty)
1033 df_clear_flags (DF_LR_RUN_DCE);
1034 df_lr_alloc (all_blocks);
1035 df_lr_local_compute (all_blocks);
1036 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1037 df_lr_finalize (all_blocks);
1038 df_set_flags (DF_LR_RUN_DCE);
1044 /* Free all storage associated with the problem. */
1046 static void
1047 df_lr_free (void)
1049 struct df_lr_problem_data *problem_data
1050 = (struct df_lr_problem_data *) df_lr->problem_data;
1051 if (df_lr->block_info)
1054 df_lr->block_info_size = 0;
1055 free (df_lr->block_info);
1056 df_lr->block_info = NULL;
1057 bitmap_obstack_release (&problem_data->lr_bitmaps);
1058 free (df_lr->problem_data);
1059 df_lr->problem_data = NULL;
1062 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1063 free (df_lr);
1067 /* Debugging info at top of bb. */
1069 static void
1070 df_lr_top_dump (basic_block bb, FILE *file)
1072 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1073 struct df_lr_problem_data *problem_data;
1074 if (!bb_info)
1075 return;
1077 fprintf (file, ";; lr in \t");
1078 df_print_regset (file, &bb_info->in);
1079 if (df_lr->problem_data)
1081 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1082 if (problem_data->in)
1084 fprintf (file, ";; old in \t");
1085 df_print_regset (file, &problem_data->in[bb->index]);
1088 fprintf (file, ";; lr use \t");
1089 df_print_regset (file, &bb_info->use);
1090 fprintf (file, ";; lr def \t");
1091 df_print_regset (file, &bb_info->def);
1095 /* Debugging info at bottom of bb. */
1097 static void
1098 df_lr_bottom_dump (basic_block bb, FILE *file)
1100 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1101 struct df_lr_problem_data *problem_data;
1102 if (!bb_info)
1103 return;
1105 fprintf (file, ";; lr out \t");
1106 df_print_regset (file, &bb_info->out);
1107 if (df_lr->problem_data)
1109 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1110 if (problem_data->out)
1112 fprintf (file, ";; old out \t");
1113 df_print_regset (file, &problem_data->out[bb->index]);
1119 /* Build the datastructure to verify that the solution to the dataflow
1120 equations is not dirty. */
1122 static void
1123 df_lr_verify_solution_start (void)
1125 basic_block bb;
1126 struct df_lr_problem_data *problem_data;
1127 if (df_lr->solutions_dirty)
1128 return;
1130 /* Set it true so that the solution is recomputed. */
1131 df_lr->solutions_dirty = true;
1133 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1134 problem_data->in = XNEWVEC (bitmap_head, last_basic_block);
1135 problem_data->out = XNEWVEC (bitmap_head, last_basic_block);
1137 FOR_ALL_BB (bb)
1139 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1140 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1141 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1142 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1147 /* Compare the saved datastructure and the new solution to the dataflow
1148 equations. */
1150 static void
1151 df_lr_verify_solution_end (void)
1153 struct df_lr_problem_data *problem_data;
1154 basic_block bb;
1156 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1158 if (!problem_data->out)
1159 return;
1161 if (df_lr->solutions_dirty)
1162 /* Do not check if the solution is still dirty. See the comment
1163 in df_lr_finalize for details. */
1164 df_lr->solutions_dirty = false;
1165 else
1166 FOR_ALL_BB (bb)
1168 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1169 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1171 /*df_dump (stderr);*/
1172 gcc_unreachable ();
1176 /* Cannot delete them immediately because you may want to dump them
1177 if the comparison fails. */
1178 FOR_ALL_BB (bb)
1180 bitmap_clear (&problem_data->in[bb->index]);
1181 bitmap_clear (&problem_data->out[bb->index]);
1184 free (problem_data->in);
1185 free (problem_data->out);
1186 problem_data->in = NULL;
1187 problem_data->out = NULL;
1191 /* All of the information associated with every instance of the problem. */
1193 static struct df_problem problem_LR =
1195 DF_LR, /* Problem id. */
1196 DF_BACKWARD, /* Direction. */
1197 df_lr_alloc, /* Allocate the problem specific data. */
1198 df_lr_reset, /* Reset global information. */
1199 df_lr_free_bb_info, /* Free basic block info. */
1200 df_lr_local_compute, /* Local compute function. */
1201 df_lr_init, /* Init the solution specific data. */
1202 df_worklist_dataflow, /* Worklist solver. */
1203 df_lr_confluence_0, /* Confluence operator 0. */
1204 df_lr_confluence_n, /* Confluence operator n. */
1205 df_lr_transfer_function, /* Transfer function. */
1206 df_lr_finalize, /* Finalize function. */
1207 df_lr_free, /* Free all of the problem information. */
1208 NULL, /* Remove this problem from the stack of dataflow problems. */
1209 NULL, /* Debugging. */
1210 df_lr_top_dump, /* Debugging start block. */
1211 df_lr_bottom_dump, /* Debugging end block. */
1212 df_lr_verify_solution_start,/* Incremental solution verify start. */
1213 df_lr_verify_solution_end, /* Incremental solution verify end. */
1214 NULL, /* Dependent problem. */
1215 sizeof (struct df_lr_bb_info),/* Size of entry of block_info array. */
1216 TV_DF_LR, /* Timing variable. */
1217 false /* Reset blocks on dropping out of blocks_to_analyze. */
1221 /* Create a new DATAFLOW instance and add it to an existing instance
1222 of DF. The returned structure is what is used to get at the
1223 solution. */
1225 void
1226 df_lr_add_problem (void)
1228 df_add_problem (&problem_LR);
1229 /* These will be initialized when df_scan_blocks processes each
1230 block. */
1231 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1235 /* Verify that all of the lr related info is consistent and
1236 correct. */
1238 void
1239 df_lr_verify_transfer_functions (void)
1241 basic_block bb;
1242 bitmap_head saved_def;
1243 bitmap_head saved_use;
1244 bitmap_head all_blocks;
1246 if (!df)
1247 return;
1249 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1250 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1251 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1253 FOR_ALL_BB (bb)
1255 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1256 bitmap_set_bit (&all_blocks, bb->index);
1258 if (bb_info)
1260 /* Make a copy of the transfer functions and then compute
1261 new ones to see if the transfer functions have
1262 changed. */
1263 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1264 bb->index))
1266 bitmap_copy (&saved_def, &bb_info->def);
1267 bitmap_copy (&saved_use, &bb_info->use);
1268 bitmap_clear (&bb_info->def);
1269 bitmap_clear (&bb_info->use);
1271 df_lr_bb_local_compute (bb->index);
1272 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1273 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1276 else
1278 /* If we do not have basic block info, the block must be in
1279 the list of dirty blocks or else some one has added a
1280 block behind our backs. */
1281 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1282 bb->index));
1284 /* Make sure no one created a block without following
1285 procedures. */
1286 gcc_assert (df_scan_get_bb_info (bb->index));
1289 /* Make sure there are no dirty bits in blocks that have been deleted. */
1290 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1291 &all_blocks));
1293 bitmap_clear (&saved_def);
1294 bitmap_clear (&saved_use);
1295 bitmap_clear (&all_blocks);
1300 /*----------------------------------------------------------------------------
1301 LIVE AND MUST-INITIALIZED REGISTERS.
1303 This problem first computes the IN and OUT bitvectors for the
1304 must-initialized registers problems, which is a forward problem.
1305 It gives the set of registers for which we MUST have an available
1306 definition on any path from the entry block to the entry/exit of
1307 a basic block. Sets generate a definition, while clobbers kill
1308 a definition.
1310 In and out bitvectors are built for each basic block and are indexed by
1311 regnum (see df.h for details). In and out bitvectors in struct
1312 df_live_bb_info actually refers to the must-initialized problem;
1314 Then, the in and out sets for the LIVE problem itself are computed.
1315 These are the logical AND of the IN and OUT sets from the LR problem
1316 and the must-initialized problem.
1317 ----------------------------------------------------------------------------*/
1319 /* Private data used to verify the solution for this problem. */
1320 struct df_live_problem_data
1322 bitmap_head *in;
1323 bitmap_head *out;
1324 /* An obstack for the bitmaps we need for this problem. */
1325 bitmap_obstack live_bitmaps;
1328 /* Scratch var used by transfer functions. This is used to implement
1329 an optimization to reduce the amount of space used to compute the
1330 combined lr and live analysis. */
1331 static bitmap_head df_live_scratch;
1334 /* Free basic block info. */
1336 static void
1337 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1338 void *vbb_info)
1340 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1341 if (bb_info)
1343 bitmap_clear (&bb_info->gen);
1344 bitmap_clear (&bb_info->kill);
1345 bitmap_clear (&bb_info->in);
1346 bitmap_clear (&bb_info->out);
1351 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1352 not touched unless the block is new. */
1354 static void
1355 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1357 unsigned int bb_index;
1358 bitmap_iterator bi;
1359 struct df_live_problem_data *problem_data;
1361 if (df_live->problem_data)
1362 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1363 else
1365 problem_data = XNEW (struct df_live_problem_data);
1366 df_live->problem_data = problem_data;
1368 problem_data->out = NULL;
1369 problem_data->in = NULL;
1370 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1371 bitmap_initialize (&df_live_scratch, &problem_data->live_bitmaps);
1374 df_grow_bb_info (df_live);
1376 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1378 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1380 /* When bitmaps are already initialized, just clear them. */
1381 if (bb_info->kill.obstack)
1383 bitmap_clear (&bb_info->kill);
1384 bitmap_clear (&bb_info->gen);
1386 else
1388 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1389 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1390 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1391 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1394 df_live->optional_p = (optimize <= 1);
1398 /* Reset the global solution for recalculation. */
1400 static void
1401 df_live_reset (bitmap all_blocks)
1403 unsigned int bb_index;
1404 bitmap_iterator bi;
1406 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1408 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1409 gcc_assert (bb_info);
1410 bitmap_clear (&bb_info->in);
1411 bitmap_clear (&bb_info->out);
1416 /* Compute local uninitialized register info for basic block BB. */
1418 static void
1419 df_live_bb_local_compute (unsigned int bb_index)
1421 basic_block bb = BASIC_BLOCK (bb_index);
1422 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1423 rtx insn;
1424 df_ref *def_rec;
1425 int luid = 0;
1427 FOR_BB_INSNS (bb, insn)
1429 unsigned int uid = INSN_UID (insn);
1430 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1432 /* Inserting labels does not always trigger the incremental
1433 rescanning. */
1434 if (!insn_info)
1436 gcc_assert (!INSN_P (insn));
1437 insn_info = df_insn_create_insn_record (insn);
1440 DF_INSN_INFO_LUID (insn_info) = luid;
1441 if (!INSN_P (insn))
1442 continue;
1444 luid++;
1445 for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)
1447 df_ref def = *def_rec;
1448 unsigned int regno = DF_REF_REGNO (def);
1450 if (DF_REF_FLAGS_IS_SET (def,
1451 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1452 /* All partial or conditional def
1453 seen are included in the gen set. */
1454 bitmap_set_bit (&bb_info->gen, regno);
1455 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1456 /* Only must clobbers for the entire reg destroy the
1457 value. */
1458 bitmap_set_bit (&bb_info->kill, regno);
1459 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1460 bitmap_set_bit (&bb_info->gen, regno);
1464 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1466 df_ref def = *def_rec;
1467 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1472 /* Compute local uninitialized register info. */
1474 static void
1475 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1477 unsigned int bb_index;
1478 bitmap_iterator bi;
1480 df_grow_insn_info ();
1482 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1483 0, bb_index, bi)
1485 df_live_bb_local_compute (bb_index);
1488 bitmap_clear (df_live->out_of_date_transfer_functions);
1492 /* Initialize the solution vectors. */
1494 static void
1495 df_live_init (bitmap all_blocks)
1497 unsigned int bb_index;
1498 bitmap_iterator bi;
1500 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1502 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1503 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1505 /* No register may reach a location where it is not used. Thus
1506 we trim the rr result to the places where it is used. */
1507 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1508 bitmap_clear (&bb_info->in);
1512 /* Forward confluence function that ignores fake edges. */
1514 static bool
1515 df_live_confluence_n (edge e)
1517 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1518 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1520 if (e->flags & EDGE_FAKE)
1521 return false;
1523 return bitmap_ior_into (op1, op2);
1527 /* Transfer function for the forwards must-initialized problem. */
1529 static bool
1530 df_live_transfer_function (int bb_index)
1532 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1533 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1534 bitmap in = &bb_info->in;
1535 bitmap out = &bb_info->out;
1536 bitmap gen = &bb_info->gen;
1537 bitmap kill = &bb_info->kill;
1539 /* We need to use a scratch set here so that the value returned from this
1540 function invocation properly reflects whether the sets changed in a
1541 significant way; i.e. not just because the lr set was anded in. */
1542 bitmap_and (&df_live_scratch, gen, &bb_lr_info->out);
1543 /* No register may reach a location where it is not used. Thus
1544 we trim the rr result to the places where it is used. */
1545 bitmap_and_into (in, &bb_lr_info->in);
1547 return bitmap_ior_and_compl (out, &df_live_scratch, in, kill);
1551 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1553 static void
1554 df_live_finalize (bitmap all_blocks)
1557 if (df_live->solutions_dirty)
1559 bitmap_iterator bi;
1560 unsigned int bb_index;
1562 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1564 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1565 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1567 /* No register may reach a location where it is not used. Thus
1568 we trim the rr result to the places where it is used. */
1569 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1570 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1573 df_live->solutions_dirty = false;
1578 /* Free all storage associated with the problem. */
1580 static void
1581 df_live_free (void)
1583 struct df_live_problem_data *problem_data
1584 = (struct df_live_problem_data *) df_live->problem_data;
1585 if (df_live->block_info)
1587 df_live->block_info_size = 0;
1588 free (df_live->block_info);
1589 df_live->block_info = NULL;
1590 bitmap_clear (&df_live_scratch);
1591 bitmap_obstack_release (&problem_data->live_bitmaps);
1592 free (problem_data);
1593 df_live->problem_data = NULL;
1595 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1596 free (df_live);
1600 /* Debugging info at top of bb. */
1602 static void
1603 df_live_top_dump (basic_block bb, FILE *file)
1605 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1606 struct df_live_problem_data *problem_data;
1608 if (!bb_info)
1609 return;
1611 fprintf (file, ";; live in \t");
1612 df_print_regset (file, &bb_info->in);
1613 if (df_live->problem_data)
1615 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1616 if (problem_data->in)
1618 fprintf (file, ";; old in \t");
1619 df_print_regset (file, &problem_data->in[bb->index]);
1622 fprintf (file, ";; live gen \t");
1623 df_print_regset (file, &bb_info->gen);
1624 fprintf (file, ";; live kill\t");
1625 df_print_regset (file, &bb_info->kill);
1629 /* Debugging info at bottom of bb. */
1631 static void
1632 df_live_bottom_dump (basic_block bb, FILE *file)
1634 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1635 struct df_live_problem_data *problem_data;
1637 if (!bb_info)
1638 return;
1640 fprintf (file, ";; live out \t");
1641 df_print_regset (file, &bb_info->out);
1642 if (df_live->problem_data)
1644 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1645 if (problem_data->out)
1647 fprintf (file, ";; old out \t");
1648 df_print_regset (file, &problem_data->out[bb->index]);
1654 /* Build the datastructure to verify that the solution to the dataflow
1655 equations is not dirty. */
1657 static void
1658 df_live_verify_solution_start (void)
1660 basic_block bb;
1661 struct df_live_problem_data *problem_data;
1662 if (df_live->solutions_dirty)
1663 return;
1665 /* Set it true so that the solution is recomputed. */
1666 df_live->solutions_dirty = true;
1668 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1669 problem_data->in = XNEWVEC (bitmap_head, last_basic_block);
1670 problem_data->out = XNEWVEC (bitmap_head, last_basic_block);
1672 FOR_ALL_BB (bb)
1674 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1675 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1676 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1677 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1682 /* Compare the saved datastructure and the new solution to the dataflow
1683 equations. */
1685 static void
1686 df_live_verify_solution_end (void)
1688 struct df_live_problem_data *problem_data;
1689 basic_block bb;
1691 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1692 if (!problem_data->out)
1693 return;
1695 FOR_ALL_BB (bb)
1697 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1698 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1700 /*df_dump (stderr);*/
1701 gcc_unreachable ();
1705 /* Cannot delete them immediately because you may want to dump them
1706 if the comparison fails. */
1707 FOR_ALL_BB (bb)
1709 bitmap_clear (&problem_data->in[bb->index]);
1710 bitmap_clear (&problem_data->out[bb->index]);
1713 free (problem_data->in);
1714 free (problem_data->out);
1715 free (problem_data);
1716 df_live->problem_data = NULL;
1720 /* All of the information associated with every instance of the problem. */
1722 static struct df_problem problem_LIVE =
1724 DF_LIVE, /* Problem id. */
1725 DF_FORWARD, /* Direction. */
1726 df_live_alloc, /* Allocate the problem specific data. */
1727 df_live_reset, /* Reset global information. */
1728 df_live_free_bb_info, /* Free basic block info. */
1729 df_live_local_compute, /* Local compute function. */
1730 df_live_init, /* Init the solution specific data. */
1731 df_worklist_dataflow, /* Worklist solver. */
1732 NULL, /* Confluence operator 0. */
1733 df_live_confluence_n, /* Confluence operator n. */
1734 df_live_transfer_function, /* Transfer function. */
1735 df_live_finalize, /* Finalize function. */
1736 df_live_free, /* Free all of the problem information. */
1737 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1738 NULL, /* Debugging. */
1739 df_live_top_dump, /* Debugging start block. */
1740 df_live_bottom_dump, /* Debugging end block. */
1741 df_live_verify_solution_start,/* Incremental solution verify start. */
1742 df_live_verify_solution_end, /* Incremental solution verify end. */
1743 &problem_LR, /* Dependent problem. */
1744 sizeof (struct df_live_bb_info),/* Size of entry of block_info array. */
1745 TV_DF_LIVE, /* Timing variable. */
1746 false /* Reset blocks on dropping out of blocks_to_analyze. */
1750 /* Create a new DATAFLOW instance and add it to an existing instance
1751 of DF. The returned structure is what is used to get at the
1752 solution. */
1754 void
1755 df_live_add_problem (void)
1757 df_add_problem (&problem_LIVE);
1758 /* These will be initialized when df_scan_blocks processes each
1759 block. */
1760 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1764 /* Set all of the blocks as dirty. This needs to be done if this
1765 problem is added after all of the insns have been scanned. */
1767 void
1768 df_live_set_all_dirty (void)
1770 basic_block bb;
1771 FOR_ALL_BB (bb)
1772 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1773 bb->index);
1777 /* Verify that all of the lr related info is consistent and
1778 correct. */
1780 void
1781 df_live_verify_transfer_functions (void)
1783 basic_block bb;
1784 bitmap_head saved_gen;
1785 bitmap_head saved_kill;
1786 bitmap_head all_blocks;
1788 if (!df)
1789 return;
1791 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1792 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1793 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1795 df_grow_insn_info ();
1797 FOR_ALL_BB (bb)
1799 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1800 bitmap_set_bit (&all_blocks, bb->index);
1802 if (bb_info)
1804 /* Make a copy of the transfer functions and then compute
1805 new ones to see if the transfer functions have
1806 changed. */
1807 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1808 bb->index))
1810 bitmap_copy (&saved_gen, &bb_info->gen);
1811 bitmap_copy (&saved_kill, &bb_info->kill);
1812 bitmap_clear (&bb_info->gen);
1813 bitmap_clear (&bb_info->kill);
1815 df_live_bb_local_compute (bb->index);
1816 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1817 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1820 else
1822 /* If we do not have basic block info, the block must be in
1823 the list of dirty blocks or else some one has added a
1824 block behind our backs. */
1825 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1826 bb->index));
1828 /* Make sure no one created a block without following
1829 procedures. */
1830 gcc_assert (df_scan_get_bb_info (bb->index));
1833 /* Make sure there are no dirty bits in blocks that have been deleted. */
1834 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1835 &all_blocks));
1836 bitmap_clear (&saved_gen);
1837 bitmap_clear (&saved_kill);
1838 bitmap_clear (&all_blocks);
1841 /*----------------------------------------------------------------------------
1842 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1844 Link either the defs to the uses and / or the uses to the defs.
1846 These problems are set up like the other dataflow problems so that
1847 they nicely fit into the framework. They are much simpler and only
1848 involve a single traversal of instructions and an examination of
1849 the reaching defs information (the dependent problem).
1850 ----------------------------------------------------------------------------*/
1852 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1854 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1856 struct df_link *
1857 df_chain_create (df_ref src, df_ref dst)
1859 struct df_link *head = DF_REF_CHAIN (src);
1860 struct df_link *link = (struct df_link *) pool_alloc (df_chain->block_pool);
1862 DF_REF_CHAIN (src) = link;
1863 link->next = head;
1864 link->ref = dst;
1865 return link;
1869 /* Delete any du or ud chains that start at REF and point to
1870 TARGET. */
1871 static void
1872 df_chain_unlink_1 (df_ref ref, df_ref target)
1874 struct df_link *chain = DF_REF_CHAIN (ref);
1875 struct df_link *prev = NULL;
1877 while (chain)
1879 if (chain->ref == target)
1881 if (prev)
1882 prev->next = chain->next;
1883 else
1884 DF_REF_CHAIN (ref) = chain->next;
1885 pool_free (df_chain->block_pool, chain);
1886 return;
1888 prev = chain;
1889 chain = chain->next;
1894 /* Delete a du or ud chain that leave or point to REF. */
1896 void
1897 df_chain_unlink (df_ref ref)
1899 struct df_link *chain = DF_REF_CHAIN (ref);
1900 while (chain)
1902 struct df_link *next = chain->next;
1903 /* Delete the other side if it exists. */
1904 df_chain_unlink_1 (chain->ref, ref);
1905 pool_free (df_chain->block_pool, chain);
1906 chain = next;
1908 DF_REF_CHAIN (ref) = NULL;
1912 /* Copy the du or ud chain starting at FROM_REF and attach it to
1913 TO_REF. */
1915 void
1916 df_chain_copy (df_ref to_ref,
1917 struct df_link *from_ref)
1919 while (from_ref)
1921 df_chain_create (to_ref, from_ref->ref);
1922 from_ref = from_ref->next;
1927 /* Remove this problem from the stack of dataflow problems. */
1929 static void
1930 df_chain_remove_problem (void)
1932 bitmap_iterator bi;
1933 unsigned int bb_index;
1935 /* Wholesale destruction of the old chains. */
1936 if (df_chain->block_pool)
1937 free_alloc_pool (df_chain->block_pool);
1939 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1941 rtx insn;
1942 df_ref *def_rec;
1943 df_ref *use_rec;
1944 basic_block bb = BASIC_BLOCK (bb_index);
1946 if (df_chain_problem_p (DF_DU_CHAIN))
1947 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1948 DF_REF_CHAIN (*def_rec) = NULL;
1949 if (df_chain_problem_p (DF_UD_CHAIN))
1950 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1951 DF_REF_CHAIN (*use_rec) = NULL;
1953 FOR_BB_INSNS (bb, insn)
1955 unsigned int uid = INSN_UID (insn);
1957 if (INSN_P (insn))
1959 if (df_chain_problem_p (DF_DU_CHAIN))
1960 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1961 DF_REF_CHAIN (*def_rec) = NULL;
1962 if (df_chain_problem_p (DF_UD_CHAIN))
1964 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1965 DF_REF_CHAIN (*use_rec) = NULL;
1966 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
1967 DF_REF_CHAIN (*use_rec) = NULL;
1973 bitmap_clear (df_chain->out_of_date_transfer_functions);
1974 df_chain->block_pool = NULL;
1978 /* Remove the chain problem completely. */
1980 static void
1981 df_chain_fully_remove_problem (void)
1983 df_chain_remove_problem ();
1984 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
1985 free (df_chain);
1989 /* Create def-use or use-def chains. */
1991 static void
1992 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1994 df_chain_remove_problem ();
1995 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
1996 sizeof (struct df_link), 50);
1997 df_chain->optional_p = true;
2001 /* Reset all of the chains when the set of basic blocks changes. */
2003 static void
2004 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2006 df_chain_remove_problem ();
2010 /* Create the chains for a list of USEs. */
2012 static void
2013 df_chain_create_bb_process_use (bitmap local_rd,
2014 df_ref *use_rec,
2015 int top_flag)
2017 bitmap_iterator bi;
2018 unsigned int def_index;
2020 while (*use_rec)
2022 df_ref use = *use_rec;
2023 unsigned int uregno = DF_REF_REGNO (use);
2024 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2025 || (uregno >= FIRST_PSEUDO_REGISTER))
2027 /* Do not want to go through this for an uninitialized var. */
2028 int count = DF_DEFS_COUNT (uregno);
2029 if (count)
2031 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2033 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2034 unsigned int last_index = first_index + count - 1;
2036 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2038 df_ref def;
2039 if (def_index > last_index)
2040 break;
2042 def = DF_DEFS_GET (def_index);
2043 if (df_chain_problem_p (DF_DU_CHAIN))
2044 df_chain_create (def, use);
2045 if (df_chain_problem_p (DF_UD_CHAIN))
2046 df_chain_create (use, def);
2052 use_rec++;
2057 /* Create chains from reaching defs bitmaps for basic block BB. */
2059 static void
2060 df_chain_create_bb (unsigned int bb_index)
2062 basic_block bb = BASIC_BLOCK (bb_index);
2063 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2064 rtx insn;
2065 bitmap_head cpy;
2067 bitmap_initialize (&cpy, &bitmap_default_obstack);
2068 bitmap_copy (&cpy, &bb_info->in);
2069 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2071 /* Since we are going forwards, process the artificial uses first
2072 then the artificial defs second. */
2074 #ifdef EH_USES
2075 /* Create the chains for the artificial uses from the EH_USES at the
2076 beginning of the block. */
2078 /* Artificials are only hard regs. */
2079 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2080 df_chain_create_bb_process_use (&cpy,
2081 df_get_artificial_uses (bb->index),
2082 DF_REF_AT_TOP);
2083 #endif
2085 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2087 /* Process the regular instructions next. */
2088 FOR_BB_INSNS (bb, insn)
2089 if (INSN_P (insn))
2091 unsigned int uid = INSN_UID (insn);
2093 /* First scan the uses and link them up with the defs that remain
2094 in the cpy vector. */
2095 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2096 if (df->changeable_flags & DF_EQ_NOTES)
2097 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2099 /* Since we are going forwards, process the defs second. */
2100 df_rd_simulate_one_insn (bb, insn, &cpy);
2103 /* Create the chains for the artificial uses of the hard registers
2104 at the end of the block. */
2105 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2106 df_chain_create_bb_process_use (&cpy,
2107 df_get_artificial_uses (bb->index),
2110 bitmap_clear (&cpy);
2113 /* Create def-use chains from reaching use bitmaps for basic blocks
2114 in BLOCKS. */
2116 static void
2117 df_chain_finalize (bitmap all_blocks)
2119 unsigned int bb_index;
2120 bitmap_iterator bi;
2122 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2124 df_chain_create_bb (bb_index);
2129 /* Free all storage associated with the problem. */
2131 static void
2132 df_chain_free (void)
2134 free_alloc_pool (df_chain->block_pool);
2135 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2136 free (df_chain);
2140 /* Debugging info. */
2142 static void
2143 df_chain_top_dump (basic_block bb, FILE *file)
2145 if (df_chain_problem_p (DF_DU_CHAIN))
2147 rtx insn;
2148 df_ref *def_rec = df_get_artificial_defs (bb->index);
2149 if (*def_rec)
2152 fprintf (file, ";; DU chains for artificial defs\n");
2153 while (*def_rec)
2155 df_ref def = *def_rec;
2156 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2157 df_chain_dump (DF_REF_CHAIN (def), file);
2158 fprintf (file, "\n");
2159 def_rec++;
2163 FOR_BB_INSNS (bb, insn)
2165 if (INSN_P (insn))
2167 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2168 def_rec = DF_INSN_INFO_DEFS (insn_info);
2169 if (*def_rec)
2171 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2172 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2174 while (*def_rec)
2176 df_ref def = *def_rec;
2177 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2178 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2179 fprintf (file, "read/write ");
2180 df_chain_dump (DF_REF_CHAIN (def), file);
2181 fprintf (file, "\n");
2182 def_rec++;
2191 static void
2192 df_chain_bottom_dump (basic_block bb, FILE *file)
2194 if (df_chain_problem_p (DF_UD_CHAIN))
2196 rtx insn;
2197 df_ref *use_rec = df_get_artificial_uses (bb->index);
2199 if (*use_rec)
2201 fprintf (file, ";; UD chains for artificial uses\n");
2202 while (*use_rec)
2204 df_ref use = *use_rec;
2205 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2206 df_chain_dump (DF_REF_CHAIN (use), file);
2207 fprintf (file, "\n");
2208 use_rec++;
2212 FOR_BB_INSNS (bb, insn)
2214 if (INSN_P (insn))
2216 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2217 df_ref *eq_use_rec = DF_INSN_INFO_EQ_USES (insn_info);
2218 use_rec = DF_INSN_INFO_USES (insn_info);
2219 if (*use_rec || *eq_use_rec)
2221 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2222 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2224 while (*use_rec)
2226 df_ref use = *use_rec;
2227 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2228 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2229 fprintf (file, "read/write ");
2230 df_chain_dump (DF_REF_CHAIN (use), file);
2231 fprintf (file, "\n");
2232 use_rec++;
2234 while (*eq_use_rec)
2236 df_ref use = *eq_use_rec;
2237 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2238 df_chain_dump (DF_REF_CHAIN (use), file);
2239 fprintf (file, "\n");
2240 eq_use_rec++;
2249 static struct df_problem problem_CHAIN =
2251 DF_CHAIN, /* Problem id. */
2252 DF_NONE, /* Direction. */
2253 df_chain_alloc, /* Allocate the problem specific data. */
2254 df_chain_reset, /* Reset global information. */
2255 NULL, /* Free basic block info. */
2256 NULL, /* Local compute function. */
2257 NULL, /* Init the solution specific data. */
2258 NULL, /* Iterative solver. */
2259 NULL, /* Confluence operator 0. */
2260 NULL, /* Confluence operator n. */
2261 NULL, /* Transfer function. */
2262 df_chain_finalize, /* Finalize function. */
2263 df_chain_free, /* Free all of the problem information. */
2264 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2265 NULL, /* Debugging. */
2266 df_chain_top_dump, /* Debugging start block. */
2267 df_chain_bottom_dump, /* Debugging end block. */
2268 NULL, /* Incremental solution verify start. */
2269 NULL, /* Incremental solution verify end. */
2270 &problem_RD, /* Dependent problem. */
2271 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
2272 TV_DF_CHAIN, /* Timing variable. */
2273 false /* Reset blocks on dropping out of blocks_to_analyze. */
2277 /* Create a new DATAFLOW instance and add it to an existing instance
2278 of DF. The returned structure is what is used to get at the
2279 solution. */
2281 void
2282 df_chain_add_problem (unsigned int chain_flags)
2284 df_add_problem (&problem_CHAIN);
2285 df_chain->local_flags = chain_flags;
2286 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2289 #undef df_chain_problem_p
2292 /*----------------------------------------------------------------------------
2293 WORD LEVEL LIVE REGISTERS
2295 Find the locations in the function where any use of a pseudo can
2296 reach in the backwards direction. In and out bitvectors are built
2297 for each basic block. We only track pseudo registers that have a
2298 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2299 contain two bits corresponding to each of the subwords.
2301 ----------------------------------------------------------------------------*/
2303 /* Private data used to verify the solution for this problem. */
2304 struct df_word_lr_problem_data
2306 /* An obstack for the bitmaps we need for this problem. */
2307 bitmap_obstack word_lr_bitmaps;
2311 /* Free basic block info. */
2313 static void
2314 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2315 void *vbb_info)
2317 struct df_word_lr_bb_info *bb_info = (struct df_word_lr_bb_info *) vbb_info;
2318 if (bb_info)
2320 bitmap_clear (&bb_info->use);
2321 bitmap_clear (&bb_info->def);
2322 bitmap_clear (&bb_info->in);
2323 bitmap_clear (&bb_info->out);
2328 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2329 not touched unless the block is new. */
2331 static void
2332 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2334 unsigned int bb_index;
2335 bitmap_iterator bi;
2336 basic_block bb;
2337 struct df_word_lr_problem_data *problem_data
2338 = XNEW (struct df_word_lr_problem_data);
2340 df_word_lr->problem_data = problem_data;
2342 df_grow_bb_info (df_word_lr);
2344 /* Create the mapping from regnos to slots. This does not change
2345 unless the problem is destroyed and recreated. In particular, if
2346 we end up deleting the only insn that used a subreg, we do not
2347 want to redo the mapping because this would invalidate everything
2348 else. */
2350 bitmap_obstack_initialize (&problem_data->word_lr_bitmaps);
2352 FOR_EACH_BB (bb)
2353 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, bb->index);
2355 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2356 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2358 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2360 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2362 /* When bitmaps are already initialized, just clear them. */
2363 if (bb_info->use.obstack)
2365 bitmap_clear (&bb_info->def);
2366 bitmap_clear (&bb_info->use);
2368 else
2370 bitmap_initialize (&bb_info->use, &problem_data->word_lr_bitmaps);
2371 bitmap_initialize (&bb_info->def, &problem_data->word_lr_bitmaps);
2372 bitmap_initialize (&bb_info->in, &problem_data->word_lr_bitmaps);
2373 bitmap_initialize (&bb_info->out, &problem_data->word_lr_bitmaps);
2377 df_word_lr->optional_p = true;
2381 /* Reset the global solution for recalculation. */
2383 static void
2384 df_word_lr_reset (bitmap all_blocks)
2386 unsigned int bb_index;
2387 bitmap_iterator bi;
2389 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2391 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2392 gcc_assert (bb_info);
2393 bitmap_clear (&bb_info->in);
2394 bitmap_clear (&bb_info->out);
2398 /* Examine REF, and if it is for a reg we're interested in, set or
2399 clear the bits corresponding to its subwords from the bitmap
2400 according to IS_SET. LIVE is the bitmap we should update. We do
2401 not track hard regs or pseudos of any size other than 2 *
2402 UNITS_PER_WORD.
2403 We return true if we changed the bitmap, or if we encountered a register
2404 we're not tracking. */
2406 bool
2407 df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
2409 rtx orig_reg = DF_REF_REG (ref);
2410 rtx reg = orig_reg;
2411 enum machine_mode reg_mode;
2412 unsigned regno;
2413 /* Left at -1 for whole accesses. */
2414 int which_subword = -1;
2415 bool changed = false;
2417 if (GET_CODE (reg) == SUBREG)
2418 reg = SUBREG_REG (orig_reg);
2419 regno = REGNO (reg);
2420 reg_mode = GET_MODE (reg);
2421 if (regno < FIRST_PSEUDO_REGISTER
2422 || GET_MODE_SIZE (reg_mode) != 2 * UNITS_PER_WORD)
2423 return true;
2425 if (GET_CODE (orig_reg) == SUBREG
2426 && df_read_modify_subreg_p (orig_reg))
2428 gcc_assert (DF_REF_FLAGS_IS_SET (ref, DF_REF_PARTIAL));
2429 if (subreg_lowpart_p (orig_reg))
2430 which_subword = 0;
2431 else
2432 which_subword = 1;
2434 if (is_set)
2436 if (which_subword != 1)
2437 changed |= bitmap_set_bit (live, regno * 2);
2438 if (which_subword != 0)
2439 changed |= bitmap_set_bit (live, regno * 2 + 1);
2441 else
2443 if (which_subword != 1)
2444 changed |= bitmap_clear_bit (live, regno * 2);
2445 if (which_subword != 0)
2446 changed |= bitmap_clear_bit (live, regno * 2 + 1);
2448 return changed;
2451 /* Compute local live register info for basic block BB. */
2453 static void
2454 df_word_lr_bb_local_compute (unsigned int bb_index)
2456 basic_block bb = BASIC_BLOCK (bb_index);
2457 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2458 rtx insn;
2459 df_ref *def_rec;
2460 df_ref *use_rec;
2462 /* Ensure that artificial refs don't contain references to pseudos. */
2463 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2465 df_ref def = *def_rec;
2466 gcc_assert (DF_REF_REGNO (def) < FIRST_PSEUDO_REGISTER);
2469 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2471 df_ref use = *use_rec;
2472 gcc_assert (DF_REF_REGNO (use) < FIRST_PSEUDO_REGISTER);
2475 FOR_BB_INSNS_REVERSE (bb, insn)
2477 unsigned int uid = INSN_UID (insn);
2479 if (!NONDEBUG_INSN_P (insn))
2480 continue;
2481 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2483 df_ref def = *def_rec;
2484 /* If the def is to only part of the reg, it does
2485 not kill the other defs that reach here. */
2486 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2488 df_word_lr_mark_ref (def, true, &bb_info->def);
2489 df_word_lr_mark_ref (def, false, &bb_info->use);
2492 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2494 df_ref use = *use_rec;
2495 df_word_lr_mark_ref (use, true, &bb_info->use);
2501 /* Compute local live register info for each basic block within BLOCKS. */
2503 static void
2504 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2506 unsigned int bb_index;
2507 bitmap_iterator bi;
2509 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2511 if (bb_index == EXIT_BLOCK)
2513 unsigned regno;
2514 bitmap_iterator bi;
2515 EXECUTE_IF_SET_IN_BITMAP (df->exit_block_uses, FIRST_PSEUDO_REGISTER,
2516 regno, bi)
2517 gcc_unreachable ();
2519 else
2520 df_word_lr_bb_local_compute (bb_index);
2523 bitmap_clear (df_word_lr->out_of_date_transfer_functions);
2527 /* Initialize the solution vectors. */
2529 static void
2530 df_word_lr_init (bitmap all_blocks)
2532 unsigned int bb_index;
2533 bitmap_iterator bi;
2535 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2537 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2538 bitmap_copy (&bb_info->in, &bb_info->use);
2539 bitmap_clear (&bb_info->out);
2544 /* Confluence function that ignores fake edges. */
2546 static bool
2547 df_word_lr_confluence_n (edge e)
2549 bitmap op1 = &df_word_lr_get_bb_info (e->src->index)->out;
2550 bitmap op2 = &df_word_lr_get_bb_info (e->dest->index)->in;
2552 return bitmap_ior_into (op1, op2);
2556 /* Transfer function. */
2558 static bool
2559 df_word_lr_transfer_function (int bb_index)
2561 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2562 bitmap in = &bb_info->in;
2563 bitmap out = &bb_info->out;
2564 bitmap use = &bb_info->use;
2565 bitmap def = &bb_info->def;
2567 return bitmap_ior_and_compl (in, use, out, def);
2571 /* Free all storage associated with the problem. */
2573 static void
2574 df_word_lr_free (void)
2576 struct df_word_lr_problem_data *problem_data
2577 = (struct df_word_lr_problem_data *)df_word_lr->problem_data;
2579 if (df_word_lr->block_info)
2581 df_word_lr->block_info_size = 0;
2582 free (df_word_lr->block_info);
2583 df_word_lr->block_info = NULL;
2586 BITMAP_FREE (df_word_lr->out_of_date_transfer_functions);
2587 bitmap_obstack_release (&problem_data->word_lr_bitmaps);
2588 free (problem_data);
2589 free (df_word_lr);
2593 /* Debugging info at top of bb. */
2595 static void
2596 df_word_lr_top_dump (basic_block bb, FILE *file)
2598 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2599 if (!bb_info)
2600 return;
2602 fprintf (file, ";; blr in \t");
2603 df_print_word_regset (file, &bb_info->in);
2604 fprintf (file, ";; blr use \t");
2605 df_print_word_regset (file, &bb_info->use);
2606 fprintf (file, ";; blr def \t");
2607 df_print_word_regset (file, &bb_info->def);
2611 /* Debugging info at bottom of bb. */
2613 static void
2614 df_word_lr_bottom_dump (basic_block bb, FILE *file)
2616 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2617 if (!bb_info)
2618 return;
2620 fprintf (file, ";; blr out \t");
2621 df_print_word_regset (file, &bb_info->out);
2625 /* All of the information associated with every instance of the problem. */
2627 static struct df_problem problem_WORD_LR =
2629 DF_WORD_LR, /* Problem id. */
2630 DF_BACKWARD, /* Direction. */
2631 df_word_lr_alloc, /* Allocate the problem specific data. */
2632 df_word_lr_reset, /* Reset global information. */
2633 df_word_lr_free_bb_info, /* Free basic block info. */
2634 df_word_lr_local_compute, /* Local compute function. */
2635 df_word_lr_init, /* Init the solution specific data. */
2636 df_worklist_dataflow, /* Worklist solver. */
2637 NULL, /* Confluence operator 0. */
2638 df_word_lr_confluence_n, /* Confluence operator n. */
2639 df_word_lr_transfer_function, /* Transfer function. */
2640 NULL, /* Finalize function. */
2641 df_word_lr_free, /* Free all of the problem information. */
2642 df_word_lr_free, /* Remove this problem from the stack of dataflow problems. */
2643 NULL, /* Debugging. */
2644 df_word_lr_top_dump, /* Debugging start block. */
2645 df_word_lr_bottom_dump, /* Debugging end block. */
2646 NULL, /* Incremental solution verify start. */
2647 NULL, /* Incremental solution verify end. */
2648 NULL, /* Dependent problem. */
2649 sizeof (struct df_word_lr_bb_info),/* Size of entry of block_info array. */
2650 TV_DF_WORD_LR, /* Timing variable. */
2651 false /* Reset blocks on dropping out of blocks_to_analyze. */
2655 /* Create a new DATAFLOW instance and add it to an existing instance
2656 of DF. The returned structure is what is used to get at the
2657 solution. */
2659 void
2660 df_word_lr_add_problem (void)
2662 df_add_problem (&problem_WORD_LR);
2663 /* These will be initialized when df_scan_blocks processes each
2664 block. */
2665 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2669 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2670 any bits, which is used by the caller to determine whether a set is
2671 necessary. We also return true if there are other reasons not to delete
2672 an insn. */
2674 bool
2675 df_word_lr_simulate_defs (rtx insn, bitmap live)
2677 bool changed = false;
2678 df_ref *def_rec;
2679 unsigned int uid = INSN_UID (insn);
2681 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2683 df_ref def = *def_rec;
2684 if (DF_REF_FLAGS (def) & DF_REF_CONDITIONAL)
2685 changed = true;
2686 else
2687 changed |= df_word_lr_mark_ref (*def_rec, false, live);
2689 return changed;
2693 /* Simulate the effects of the uses of INSN on LIVE. */
2695 void
2696 df_word_lr_simulate_uses (rtx insn, bitmap live)
2698 df_ref *use_rec;
2699 unsigned int uid = INSN_UID (insn);
2701 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2702 df_word_lr_mark_ref (*use_rec, true, live);
2705 /*----------------------------------------------------------------------------
2706 This problem computes REG_DEAD and REG_UNUSED notes.
2707 ----------------------------------------------------------------------------*/
2709 static void
2710 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2712 df_note->optional_p = true;
2715 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2716 static void
2717 df_print_note (const char *prefix, rtx insn, rtx note)
2719 if (dump_file)
2721 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2722 print_rtl (dump_file, note);
2723 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. */
2732 #ifdef STACK_REGS
2733 static inline bool
2734 df_ignore_stack_reg (int regno)
2736 return regstack_completed
2737 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2739 #else
2740 static inline bool
2741 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2743 return false;
2745 #endif
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. Remove also
2750 REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2751 as the bitmap of currently live registers. */
2753 static void
2754 df_kill_notes (rtx insn, bitmap live)
2756 rtx *pprev = &REG_NOTES (insn);
2757 rtx link = *pprev;
2759 while (link)
2761 switch (REG_NOTE_KIND (link))
2763 case REG_DEAD:
2764 /* After reg-stack, we need to ignore any unused notes
2765 for the stack registers. */
2766 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2768 pprev = &XEXP (link, 1);
2769 link = *pprev;
2771 else
2773 rtx next = XEXP (link, 1);
2774 if (REG_DEAD_DEBUGGING)
2775 df_print_note ("deleting: ", insn, link);
2776 free_EXPR_LIST_node (link);
2777 *pprev = link = next;
2779 break;
2781 case REG_UNUSED:
2782 /* After reg-stack, we need to ignore any unused notes
2783 for the stack registers. */
2784 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2786 pprev = &XEXP (link, 1);
2787 link = *pprev;
2789 else
2791 rtx next = XEXP (link, 1);
2792 if (REG_DEAD_DEBUGGING)
2793 df_print_note ("deleting: ", insn, link);
2794 free_EXPR_LIST_node (link);
2795 *pprev = link = next;
2797 break;
2799 case REG_EQUAL:
2800 case REG_EQUIV:
2802 /* Remove the notes that refer to dead registers. As we have at most
2803 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2804 so we need to purge the complete EQ_USES vector when removing
2805 the note using df_notes_rescan. */
2806 df_ref *use_rec;
2807 bool deleted = false;
2809 for (use_rec = DF_INSN_EQ_USES (insn); *use_rec; use_rec++)
2811 df_ref use = *use_rec;
2812 if (DF_REF_REGNO (use) > FIRST_PSEUDO_REGISTER
2813 && DF_REF_LOC (use)
2814 && (DF_REF_FLAGS (use) & DF_REF_IN_NOTE)
2815 && ! bitmap_bit_p (live, DF_REF_REGNO (use))
2816 && loc_mentioned_in_p (DF_REF_LOC (use), XEXP (link, 0)))
2818 deleted = true;
2819 break;
2822 if (deleted)
2824 rtx next;
2825 if (REG_DEAD_DEBUGGING)
2826 df_print_note ("deleting: ", insn, link);
2827 next = XEXP (link, 1);
2828 free_EXPR_LIST_node (link);
2829 *pprev = link = next;
2830 df_notes_rescan (insn);
2832 else
2834 pprev = &XEXP (link, 1);
2835 link = *pprev;
2837 break;
2839 default:
2840 pprev = &XEXP (link, 1);
2841 link = *pprev;
2842 break;
2848 /* Set a NOTE_TYPE note for REG in INSN. */
2850 static inline void
2851 df_set_note (enum reg_note note_type, rtx insn, rtx reg)
2853 gcc_checking_assert (!DEBUG_INSN_P (insn));
2854 add_reg_note (insn, note_type, reg);
2857 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2858 arguments. Return true if the register value described by MWS's
2859 mw_reg is known to be completely unused, and if mw_reg can therefore
2860 be used in a REG_UNUSED note. */
2862 static bool
2863 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2864 bitmap live, bitmap artificial_uses)
2866 unsigned int r;
2868 /* If MWS describes a partial reference, create REG_UNUSED notes for
2869 individual hard registers. */
2870 if (mws->flags & DF_REF_PARTIAL)
2871 return false;
2873 /* Likewise if some part of the register is used. */
2874 for (r = mws->start_regno; r <= mws->end_regno; r++)
2875 if (bitmap_bit_p (live, r)
2876 || bitmap_bit_p (artificial_uses, r))
2877 return false;
2879 gcc_assert (REG_P (mws->mw_reg));
2880 return true;
2884 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2885 based on the bits in LIVE. Do not generate notes for registers in
2886 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2887 not generated if the reg is both read and written by the
2888 instruction.
2891 static void
2892 df_set_unused_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
2893 bitmap live, bitmap do_not_gen,
2894 bitmap artificial_uses,
2895 struct dead_debug *debug)
2897 unsigned int r;
2899 if (REG_DEAD_DEBUGGING && dump_file)
2900 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2901 mws->start_regno, mws->end_regno);
2903 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2905 unsigned int regno = mws->start_regno;
2906 df_set_note (REG_UNUSED, insn, mws->mw_reg);
2907 dead_debug_insert_temp (debug, regno, insn, DEBUG_TEMP_AFTER_WITH_REG);
2909 if (REG_DEAD_DEBUGGING)
2910 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2912 bitmap_set_bit (do_not_gen, regno);
2913 /* Only do this if the value is totally dead. */
2915 else
2916 for (r = mws->start_regno; r <= mws->end_regno; r++)
2918 if (!bitmap_bit_p (live, r)
2919 && !bitmap_bit_p (artificial_uses, r))
2921 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
2922 dead_debug_insert_temp (debug, r, insn, DEBUG_TEMP_AFTER_WITH_REG);
2923 if (REG_DEAD_DEBUGGING)
2924 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2926 bitmap_set_bit (do_not_gen, r);
2931 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2932 arguments. Return true if the register value described by MWS's
2933 mw_reg is known to be completely dead, and if mw_reg can therefore
2934 be used in a REG_DEAD note. */
2936 static bool
2937 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2938 bitmap live, bitmap artificial_uses,
2939 bitmap do_not_gen)
2941 unsigned int r;
2943 /* If MWS describes a partial reference, create REG_DEAD notes for
2944 individual hard registers. */
2945 if (mws->flags & DF_REF_PARTIAL)
2946 return false;
2948 /* Likewise if some part of the register is not dead. */
2949 for (r = mws->start_regno; r <= mws->end_regno; r++)
2950 if (bitmap_bit_p (live, r)
2951 || bitmap_bit_p (artificial_uses, r)
2952 || bitmap_bit_p (do_not_gen, r))
2953 return false;
2955 gcc_assert (REG_P (mws->mw_reg));
2956 return true;
2959 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2960 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2961 from being set if the instruction both reads and writes the
2962 register. */
2964 static void
2965 df_set_dead_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
2966 bitmap live, bitmap do_not_gen,
2967 bitmap artificial_uses, bool *added_notes_p)
2969 unsigned int r;
2970 bool is_debug = *added_notes_p;
2972 *added_notes_p = false;
2974 if (REG_DEAD_DEBUGGING && dump_file)
2976 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2977 mws->start_regno, mws->end_regno);
2978 df_print_regset (dump_file, do_not_gen);
2979 fprintf (dump_file, " live =");
2980 df_print_regset (dump_file, live);
2981 fprintf (dump_file, " artificial uses =");
2982 df_print_regset (dump_file, artificial_uses);
2985 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2987 if (is_debug)
2989 *added_notes_p = true;
2990 return;
2992 /* Add a dead note for the entire multi word register. */
2993 df_set_note (REG_DEAD, insn, mws->mw_reg);
2994 if (REG_DEAD_DEBUGGING)
2995 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2997 else
2999 for (r = mws->start_regno; r <= mws->end_regno; r++)
3000 if (!bitmap_bit_p (live, r)
3001 && !bitmap_bit_p (artificial_uses, r)
3002 && !bitmap_bit_p (do_not_gen, r))
3004 if (is_debug)
3006 *added_notes_p = true;
3007 return;
3009 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
3010 if (REG_DEAD_DEBUGGING)
3011 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3014 return;
3018 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3019 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3021 static void
3022 df_create_unused_note (rtx insn, df_ref def,
3023 bitmap live, bitmap artificial_uses,
3024 struct dead_debug *debug)
3026 unsigned int dregno = DF_REF_REGNO (def);
3028 if (REG_DEAD_DEBUGGING && dump_file)
3030 fprintf (dump_file, " regular looking at def ");
3031 df_ref_debug (def, dump_file);
3034 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3035 || bitmap_bit_p (live, dregno)
3036 || bitmap_bit_p (artificial_uses, dregno)
3037 || df_ignore_stack_reg (dregno)))
3039 rtx reg = (DF_REF_LOC (def))
3040 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3041 df_set_note (REG_UNUSED, insn, reg);
3042 dead_debug_insert_temp (debug, dregno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3043 if (REG_DEAD_DEBUGGING)
3044 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3047 return;
3051 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3052 info: lifetime, bb, and number of defs and uses for basic block
3053 BB. The three bitvectors are scratch regs used here. */
3055 static void
3056 df_note_bb_compute (unsigned int bb_index,
3057 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3059 basic_block bb = BASIC_BLOCK (bb_index);
3060 rtx insn;
3061 df_ref *def_rec;
3062 df_ref *use_rec;
3063 struct dead_debug debug;
3065 dead_debug_init (&debug, NULL);
3067 bitmap_copy (live, df_get_live_out (bb));
3068 bitmap_clear (artificial_uses);
3070 if (REG_DEAD_DEBUGGING && dump_file)
3072 fprintf (dump_file, "live at bottom ");
3073 df_print_regset (dump_file, live);
3076 /* Process the artificial defs and uses at the bottom of the block
3077 to begin processing. */
3078 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3080 df_ref def = *def_rec;
3082 if (REG_DEAD_DEBUGGING && dump_file)
3083 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3085 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3086 bitmap_clear_bit (live, DF_REF_REGNO (def));
3089 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3091 df_ref use = *use_rec;
3092 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3094 unsigned int regno = DF_REF_REGNO (use);
3095 bitmap_set_bit (live, regno);
3097 /* Notes are not generated for any of the artificial registers
3098 at the bottom of the block. */
3099 bitmap_set_bit (artificial_uses, regno);
3103 if (REG_DEAD_DEBUGGING && dump_file)
3105 fprintf (dump_file, "live before artificials out ");
3106 df_print_regset (dump_file, live);
3109 FOR_BB_INSNS_REVERSE (bb, insn)
3111 unsigned int uid = INSN_UID (insn);
3112 struct df_mw_hardreg **mws_rec;
3113 int debug_insn;
3115 if (!INSN_P (insn))
3116 continue;
3118 debug_insn = DEBUG_INSN_P (insn);
3120 bitmap_clear (do_not_gen);
3121 df_kill_notes (insn, live);
3123 /* Process the defs. */
3124 if (CALL_P (insn))
3126 if (REG_DEAD_DEBUGGING && dump_file)
3128 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3129 df_print_regset (dump_file, live);
3132 /* We only care about real sets for calls. Clobbers cannot
3133 be depended on to really die. */
3134 mws_rec = DF_INSN_UID_MWS (uid);
3135 while (*mws_rec)
3137 struct df_mw_hardreg *mws = *mws_rec;
3138 if ((DF_MWS_REG_DEF_P (mws))
3139 && !df_ignore_stack_reg (mws->start_regno))
3140 df_set_unused_notes_for_mw (insn,
3141 mws, live, do_not_gen,
3142 artificial_uses, &debug);
3143 mws_rec++;
3146 /* All of the defs except the return value are some sort of
3147 clobber. This code is for the return. */
3148 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3150 df_ref def = *def_rec;
3151 unsigned int dregno = DF_REF_REGNO (def);
3152 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3154 df_create_unused_note (insn,
3155 def, live, artificial_uses, &debug);
3156 bitmap_set_bit (do_not_gen, dregno);
3159 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3160 bitmap_clear_bit (live, dregno);
3163 else
3165 /* Regular insn. */
3166 mws_rec = DF_INSN_UID_MWS (uid);
3167 while (*mws_rec)
3169 struct df_mw_hardreg *mws = *mws_rec;
3170 if (DF_MWS_REG_DEF_P (mws))
3171 df_set_unused_notes_for_mw (insn,
3172 mws, live, do_not_gen,
3173 artificial_uses, &debug);
3174 mws_rec++;
3177 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3179 df_ref def = *def_rec;
3180 unsigned int dregno = DF_REF_REGNO (def);
3181 df_create_unused_note (insn,
3182 def, live, artificial_uses, &debug);
3184 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3185 bitmap_set_bit (do_not_gen, dregno);
3187 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3188 bitmap_clear_bit (live, dregno);
3192 /* Process the uses. */
3193 mws_rec = DF_INSN_UID_MWS (uid);
3194 while (*mws_rec)
3196 struct df_mw_hardreg *mws = *mws_rec;
3197 if (DF_MWS_REG_USE_P (mws)
3198 && !df_ignore_stack_reg (mws->start_regno))
3200 bool really_add_notes = debug_insn != 0;
3202 df_set_dead_notes_for_mw (insn,
3203 mws, live, do_not_gen,
3204 artificial_uses,
3205 &really_add_notes);
3207 if (really_add_notes)
3208 debug_insn = -1;
3210 mws_rec++;
3213 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3215 df_ref use = *use_rec;
3216 unsigned int uregno = DF_REF_REGNO (use);
3218 if (REG_DEAD_DEBUGGING && dump_file && !debug_insn)
3220 fprintf (dump_file, " regular looking at use ");
3221 df_ref_debug (use, dump_file);
3224 if (!bitmap_bit_p (live, uregno))
3226 if (debug_insn)
3228 if (debug_insn > 0)
3230 /* We won't add REG_UNUSED or REG_DEAD notes for
3231 these, so we don't have to mess with them in
3232 debug insns either. */
3233 if (!bitmap_bit_p (artificial_uses, uregno)
3234 && !df_ignore_stack_reg (uregno))
3235 dead_debug_add (&debug, use, uregno);
3236 continue;
3238 break;
3240 else
3241 dead_debug_insert_temp (&debug, uregno, insn,
3242 DEBUG_TEMP_BEFORE_WITH_REG);
3244 if ( (!(DF_REF_FLAGS (use)
3245 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3246 && (!bitmap_bit_p (do_not_gen, uregno))
3247 && (!bitmap_bit_p (artificial_uses, uregno))
3248 && (!df_ignore_stack_reg (uregno)))
3250 rtx reg = (DF_REF_LOC (use))
3251 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3252 df_set_note (REG_DEAD, insn, reg);
3254 if (REG_DEAD_DEBUGGING)
3255 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3257 /* This register is now live. */
3258 bitmap_set_bit (live, uregno);
3262 if (debug_insn == -1)
3264 /* ??? We could probably do better here, replacing dead
3265 registers with their definitions. */
3266 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3267 df_insn_rescan_debug_internal (insn);
3271 dead_debug_finish (&debug, NULL);
3275 /* Compute register info: lifetime, bb, and number of defs and uses. */
3276 static void
3277 df_note_compute (bitmap all_blocks)
3279 unsigned int bb_index;
3280 bitmap_iterator bi;
3281 bitmap_head live, do_not_gen, artificial_uses;
3283 bitmap_initialize (&live, &df_bitmap_obstack);
3284 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3285 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3287 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3289 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3292 bitmap_clear (&live);
3293 bitmap_clear (&do_not_gen);
3294 bitmap_clear (&artificial_uses);
3298 /* Free all storage associated with the problem. */
3300 static void
3301 df_note_free (void)
3303 free (df_note);
3307 /* All of the information associated every instance of the problem. */
3309 static struct df_problem problem_NOTE =
3311 DF_NOTE, /* Problem id. */
3312 DF_NONE, /* Direction. */
3313 df_note_alloc, /* Allocate the problem specific data. */
3314 NULL, /* Reset global information. */
3315 NULL, /* Free basic block info. */
3316 df_note_compute, /* Local compute function. */
3317 NULL, /* Init the solution specific data. */
3318 NULL, /* Iterative solver. */
3319 NULL, /* Confluence operator 0. */
3320 NULL, /* Confluence operator n. */
3321 NULL, /* Transfer function. */
3322 NULL, /* Finalize function. */
3323 df_note_free, /* Free all of the problem information. */
3324 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3325 NULL, /* Debugging. */
3326 NULL, /* Debugging start block. */
3327 NULL, /* Debugging end block. */
3328 NULL, /* Incremental solution verify start. */
3329 NULL, /* Incremental solution verify end. */
3330 &problem_LR, /* Dependent problem. */
3331 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
3332 TV_DF_NOTE, /* Timing variable. */
3333 false /* Reset blocks on dropping out of blocks_to_analyze. */
3337 /* Create a new DATAFLOW instance and add it to an existing instance
3338 of DF. The returned structure is what is used to get at the
3339 solution. */
3341 void
3342 df_note_add_problem (void)
3344 df_add_problem (&problem_NOTE);
3350 /*----------------------------------------------------------------------------
3351 Functions for simulating the effects of single insns.
3353 You can either simulate in the forwards direction, starting from
3354 the top of a block or the backwards direction from the end of the
3355 block. If you go backwards, defs are examined first to clear bits,
3356 then uses are examined to set bits. If you go forwards, defs are
3357 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3358 are examined to clear bits. In either case, the result of examining
3359 a def can be undone (respectively by a use or a REG_UNUSED note).
3361 If you start at the top of the block, use one of DF_LIVE_IN or
3362 DF_LR_IN. If you start at the bottom of the block use one of
3363 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3364 THEY WILL BE DESTROYED.
3365 ----------------------------------------------------------------------------*/
3368 /* Find the set of DEFs for INSN. */
3370 void
3371 df_simulate_find_defs (rtx insn, bitmap defs)
3373 df_ref *def_rec;
3374 unsigned int uid = INSN_UID (insn);
3376 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3378 df_ref def = *def_rec;
3379 bitmap_set_bit (defs, DF_REF_REGNO (def));
3383 /* Find the set of uses for INSN. This includes partial defs. */
3385 static void
3386 df_simulate_find_uses (rtx insn, bitmap uses)
3388 df_ref *rec;
3389 unsigned int uid = INSN_UID (insn);
3391 for (rec = DF_INSN_UID_DEFS (uid); *rec; rec++)
3393 df_ref def = *rec;
3394 if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3395 bitmap_set_bit (uses, DF_REF_REGNO (def));
3397 for (rec = DF_INSN_UID_USES (uid); *rec; rec++)
3399 df_ref use = *rec;
3400 bitmap_set_bit (uses, DF_REF_REGNO (use));
3404 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3406 void
3407 df_simulate_find_noclobber_defs (rtx insn, bitmap defs)
3409 df_ref *def_rec;
3410 unsigned int uid = INSN_UID (insn);
3412 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3414 df_ref def = *def_rec;
3415 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3416 bitmap_set_bit (defs, DF_REF_REGNO (def));
3421 /* Simulate the effects of the defs of INSN on LIVE. */
3423 void
3424 df_simulate_defs (rtx insn, bitmap live)
3426 df_ref *def_rec;
3427 unsigned int uid = INSN_UID (insn);
3429 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3431 df_ref def = *def_rec;
3432 unsigned int dregno = DF_REF_REGNO (def);
3434 /* If the def is to only part of the reg, it does
3435 not kill the other defs that reach here. */
3436 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3437 bitmap_clear_bit (live, dregno);
3442 /* Simulate the effects of the uses of INSN on LIVE. */
3444 void
3445 df_simulate_uses (rtx insn, bitmap live)
3447 df_ref *use_rec;
3448 unsigned int uid = INSN_UID (insn);
3450 if (DEBUG_INSN_P (insn))
3451 return;
3453 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3455 df_ref use = *use_rec;
3456 /* Add use to set of uses in this BB. */
3457 bitmap_set_bit (live, DF_REF_REGNO (use));
3462 /* Add back the always live regs in BB to LIVE. */
3464 static inline void
3465 df_simulate_fixup_sets (basic_block bb, bitmap live)
3467 /* These regs are considered always live so if they end up dying
3468 because of some def, we need to bring the back again. */
3469 if (bb_has_eh_pred (bb))
3470 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3471 else
3472 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3476 /*----------------------------------------------------------------------------
3477 The following three functions are used only for BACKWARDS scanning:
3478 i.e. they process the defs before the uses.
3480 df_simulate_initialize_backwards should be called first with a
3481 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3482 df_simulate_one_insn_backwards should be called for each insn in
3483 the block, starting with the last one. Finally,
3484 df_simulate_finalize_backwards can be called to get a new value
3485 of the sets at the top of the block (this is rarely used).
3486 ----------------------------------------------------------------------------*/
3488 /* Apply the artificial uses and defs at the end of BB in a backwards
3489 direction. */
3491 void
3492 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3494 df_ref *def_rec;
3495 df_ref *use_rec;
3496 int bb_index = bb->index;
3498 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3500 df_ref def = *def_rec;
3501 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3502 bitmap_clear_bit (live, DF_REF_REGNO (def));
3505 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3507 df_ref use = *use_rec;
3508 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3509 bitmap_set_bit (live, DF_REF_REGNO (use));
3514 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3516 void
3517 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3519 if (!NONDEBUG_INSN_P (insn))
3520 return;
3522 df_simulate_defs (insn, live);
3523 df_simulate_uses (insn, live);
3524 df_simulate_fixup_sets (bb, live);
3528 /* Apply the artificial uses and defs at the top of BB in a backwards
3529 direction. */
3531 void
3532 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3534 df_ref *def_rec;
3535 #ifdef EH_USES
3536 df_ref *use_rec;
3537 #endif
3538 int bb_index = bb->index;
3540 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3542 df_ref def = *def_rec;
3543 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3544 bitmap_clear_bit (live, DF_REF_REGNO (def));
3547 #ifdef EH_USES
3548 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3550 df_ref use = *use_rec;
3551 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3552 bitmap_set_bit (live, DF_REF_REGNO (use));
3554 #endif
3556 /*----------------------------------------------------------------------------
3557 The following three functions are used only for FORWARDS scanning:
3558 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3559 Thus it is important to add the DF_NOTES problem to the stack of
3560 problems computed before using these functions.
3562 df_simulate_initialize_forwards should be called first with a
3563 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3564 df_simulate_one_insn_forwards should be called for each insn in
3565 the block, starting with the first one.
3566 ----------------------------------------------------------------------------*/
3568 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3569 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3570 defs live. */
3572 void
3573 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3575 df_ref *def_rec;
3576 int bb_index = bb->index;
3578 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3580 df_ref def = *def_rec;
3581 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3582 bitmap_set_bit (live, DF_REF_REGNO (def));
3586 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3588 void
3589 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3591 rtx link;
3592 if (! INSN_P (insn))
3593 return;
3595 /* Make sure that DF_NOTE really is an active df problem. */
3596 gcc_assert (df_note);
3598 /* Note that this is the opposite as how the problem is defined, because
3599 in the LR problem defs _kill_ liveness. However, they do so backwards,
3600 while here the scan is performed forwards! So, first assume that the
3601 def is live, and if this is not true REG_UNUSED notes will rectify the
3602 situation. */
3603 df_simulate_find_noclobber_defs (insn, live);
3605 /* Clear all of the registers that go dead. */
3606 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3608 switch (REG_NOTE_KIND (link))
3610 case REG_DEAD:
3611 case REG_UNUSED:
3613 rtx reg = XEXP (link, 0);
3614 int regno = REGNO (reg);
3615 if (HARD_REGISTER_NUM_P (regno))
3616 bitmap_clear_range (live, regno,
3617 hard_regno_nregs[regno][GET_MODE (reg)]);
3618 else
3619 bitmap_clear_bit (live, regno);
3621 break;
3622 default:
3623 break;
3626 df_simulate_fixup_sets (bb, live);
3629 /* Used by the next two functions to encode information about the
3630 memory references we found. */
3631 #define MEMREF_NORMAL 1
3632 #define MEMREF_VOLATILE 2
3634 /* A subroutine of can_move_insns_across_p called through for_each_rtx.
3635 Return either MEMREF_NORMAL or MEMREF_VOLATILE if a memory is found. */
3637 static int
3638 find_memory (rtx *px, void *data ATTRIBUTE_UNUSED)
3640 rtx x = *px;
3642 if (GET_CODE (x) == ASM_OPERANDS && MEM_VOLATILE_P (x))
3643 return MEMREF_VOLATILE;
3645 if (!MEM_P (x))
3646 return 0;
3647 if (MEM_VOLATILE_P (x))
3648 return MEMREF_VOLATILE;
3649 if (MEM_READONLY_P (x))
3650 return 0;
3652 return MEMREF_NORMAL;
3655 /* A subroutine of can_move_insns_across_p called through note_stores.
3656 DATA points to an integer in which we set either the bit for
3657 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3658 of either kind. */
3660 static void
3661 find_memory_stores (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
3662 void *data ATTRIBUTE_UNUSED)
3664 int *pflags = (int *)data;
3665 if (GET_CODE (x) == SUBREG)
3666 x = XEXP (x, 0);
3667 /* Treat stores to SP as stores to memory, this will prevent problems
3668 when there are references to the stack frame. */
3669 if (x == stack_pointer_rtx)
3670 *pflags |= MEMREF_VOLATILE;
3671 if (!MEM_P (x))
3672 return;
3673 *pflags |= MEM_VOLATILE_P (x) ? MEMREF_VOLATILE : MEMREF_NORMAL;
3676 /* Scan BB backwards, using df_simulate functions to keep track of
3677 lifetimes, up to insn POINT. The result is stored in LIVE. */
3679 void
3680 simulate_backwards_to_point (basic_block bb, regset live, rtx point)
3682 rtx insn;
3683 bitmap_copy (live, df_get_live_out (bb));
3684 df_simulate_initialize_backwards (bb, live);
3686 /* Scan and update life information until we reach the point we're
3687 interested in. */
3688 for (insn = BB_END (bb); insn != point; insn = PREV_INSN (insn))
3689 df_simulate_one_insn_backwards (bb, insn, live);
3692 /* Return true if it is safe to move a group of insns, described by
3693 the range FROM to TO, backwards across another group of insns,
3694 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3695 are no insns between ACROSS_TO and FROM, but they may be in
3696 different basic blocks; MERGE_BB is the block from which the
3697 insns will be moved. The caller must pass in a regset MERGE_LIVE
3698 which specifies the registers live after TO.
3700 This function may be called in one of two cases: either we try to
3701 move identical instructions from all successor blocks into their
3702 predecessor, or we try to move from only one successor block. If
3703 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3704 the second case. It should contain a set of registers live at the
3705 end of ACROSS_TO which must not be clobbered by moving the insns.
3706 In that case, we're also more careful about moving memory references
3707 and trapping insns.
3709 We return false if it is not safe to move the entire group, but it
3710 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3711 is set to point at the last moveable insn in such a case. */
3713 bool
3714 can_move_insns_across (rtx from, rtx to, rtx across_from, rtx across_to,
3715 basic_block merge_bb, regset merge_live,
3716 regset other_branch_live, rtx *pmove_upto)
3718 rtx insn, next, max_to;
3719 bitmap merge_set, merge_use, local_merge_live;
3720 bitmap test_set, test_use;
3721 unsigned i, fail = 0;
3722 bitmap_iterator bi;
3723 int memrefs_in_across = 0;
3724 int mem_sets_in_across = 0;
3725 bool trapping_insns_in_across = false;
3727 if (pmove_upto != NULL)
3728 *pmove_upto = NULL_RTX;
3730 /* Find real bounds, ignoring debug insns. */
3731 while (!NONDEBUG_INSN_P (from) && from != to)
3732 from = NEXT_INSN (from);
3733 while (!NONDEBUG_INSN_P (to) && from != to)
3734 to = PREV_INSN (to);
3736 for (insn = across_to; ; insn = next)
3738 if (CALL_P (insn))
3740 if (RTL_CONST_OR_PURE_CALL_P (insn))
3741 /* Pure functions can read from memory. Const functions can
3742 read from arguments that the ABI has forced onto the stack.
3743 Neither sort of read can be volatile. */
3744 memrefs_in_across |= MEMREF_NORMAL;
3745 else
3747 memrefs_in_across |= MEMREF_VOLATILE;
3748 mem_sets_in_across |= MEMREF_VOLATILE;
3751 if (NONDEBUG_INSN_P (insn))
3753 memrefs_in_across |= for_each_rtx (&PATTERN (insn), find_memory,
3754 NULL);
3755 note_stores (PATTERN (insn), find_memory_stores,
3756 &mem_sets_in_across);
3757 /* This is used just to find sets of the stack pointer. */
3758 memrefs_in_across |= mem_sets_in_across;
3759 trapping_insns_in_across |= may_trap_p (PATTERN (insn));
3761 next = PREV_INSN (insn);
3762 if (insn == across_from)
3763 break;
3766 /* Collect:
3767 MERGE_SET = set of registers set in MERGE_BB
3768 MERGE_USE = set of registers used in MERGE_BB and live at its top
3769 MERGE_LIVE = set of registers live at the point inside the MERGE
3770 range that we've reached during scanning
3771 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3772 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3773 and live before ACROSS_FROM. */
3775 merge_set = BITMAP_ALLOC (&reg_obstack);
3776 merge_use = BITMAP_ALLOC (&reg_obstack);
3777 local_merge_live = BITMAP_ALLOC (&reg_obstack);
3778 test_set = BITMAP_ALLOC (&reg_obstack);
3779 test_use = BITMAP_ALLOC (&reg_obstack);
3781 /* Compute the set of registers set and used in the ACROSS range. */
3782 if (other_branch_live != NULL)
3783 bitmap_copy (test_use, other_branch_live);
3784 df_simulate_initialize_backwards (merge_bb, test_use);
3785 for (insn = across_to; ; insn = next)
3787 if (NONDEBUG_INSN_P (insn))
3789 df_simulate_find_defs (insn, test_set);
3790 df_simulate_defs (insn, test_use);
3791 df_simulate_uses (insn, test_use);
3793 next = PREV_INSN (insn);
3794 if (insn == across_from)
3795 break;
3798 /* Compute an upper bound for the amount of insns moved, by finding
3799 the first insn in MERGE that sets a register in TEST_USE, or uses
3800 a register in TEST_SET. We also check for calls, trapping operations,
3801 and memory references. */
3802 max_to = NULL_RTX;
3803 for (insn = from; ; insn = next)
3805 if (CALL_P (insn))
3806 break;
3807 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
3808 break;
3809 if (NONDEBUG_INSN_P (insn))
3811 if (may_trap_or_fault_p (PATTERN (insn))
3812 && (trapping_insns_in_across || other_branch_live != NULL))
3813 break;
3815 /* We cannot move memory stores past each other, or move memory
3816 reads past stores, at least not without tracking them and
3817 calling true_dependence on every pair.
3819 If there is no other branch and no memory references or
3820 sets in the ACROSS range, we can move memory references
3821 freely, even volatile ones.
3823 Otherwise, the rules are as follows: volatile memory
3824 references and stores can't be moved at all, and any type
3825 of memory reference can't be moved if there are volatile
3826 accesses or stores in the ACROSS range. That leaves
3827 normal reads, which can be moved, as the trapping case is
3828 dealt with elsewhere. */
3829 if (other_branch_live != NULL || memrefs_in_across != 0)
3831 int mem_ref_flags = 0;
3832 int mem_set_flags = 0;
3833 note_stores (PATTERN (insn), find_memory_stores, &mem_set_flags);
3834 mem_ref_flags = for_each_rtx (&PATTERN (insn), find_memory,
3835 NULL);
3836 /* Catch sets of the stack pointer. */
3837 mem_ref_flags |= mem_set_flags;
3839 if ((mem_ref_flags | mem_set_flags) & MEMREF_VOLATILE)
3840 break;
3841 if ((memrefs_in_across & MEMREF_VOLATILE) && mem_ref_flags != 0)
3842 break;
3843 if (mem_set_flags != 0
3844 || (mem_sets_in_across != 0 && mem_ref_flags != 0))
3845 break;
3847 df_simulate_find_uses (insn, merge_use);
3848 /* We're only interested in uses which use a value live at
3849 the top, not one previously set in this block. */
3850 bitmap_and_compl_into (merge_use, merge_set);
3851 df_simulate_find_defs (insn, merge_set);
3852 if (bitmap_intersect_p (merge_set, test_use)
3853 || bitmap_intersect_p (merge_use, test_set))
3854 break;
3855 #ifdef HAVE_cc0
3856 if (!sets_cc0_p (insn))
3857 #endif
3858 max_to = insn;
3860 next = NEXT_INSN (insn);
3861 if (insn == to)
3862 break;
3864 if (max_to != to)
3865 fail = 1;
3867 if (max_to == NULL_RTX || (fail && pmove_upto == NULL))
3868 goto out;
3870 /* Now, lower this upper bound by also taking into account that
3871 a range of insns moved across ACROSS must not leave a register
3872 live at the end that will be clobbered in ACROSS. We need to
3873 find a point where TEST_SET & LIVE == 0.
3875 Insns in the MERGE range that set registers which are also set
3876 in the ACROSS range may still be moved as long as we also move
3877 later insns which use the results of the set, and make the
3878 register dead again. This is verified by the condition stated
3879 above. We only need to test it for registers that are set in
3880 the moved region.
3882 MERGE_LIVE is provided by the caller and holds live registers after
3883 TO. */
3884 bitmap_copy (local_merge_live, merge_live);
3885 for (insn = to; insn != max_to; insn = PREV_INSN (insn))
3886 df_simulate_one_insn_backwards (merge_bb, insn, local_merge_live);
3888 /* We're not interested in registers that aren't set in the moved
3889 region at all. */
3890 bitmap_and_into (local_merge_live, merge_set);
3891 for (;;)
3893 if (NONDEBUG_INSN_P (insn))
3895 if (!bitmap_intersect_p (test_set, local_merge_live)
3896 #ifdef HAVE_cc0
3897 && !sets_cc0_p (insn)
3898 #endif
3901 max_to = insn;
3902 break;
3905 df_simulate_one_insn_backwards (merge_bb, insn,
3906 local_merge_live);
3908 if (insn == from)
3910 fail = 1;
3911 goto out;
3913 insn = PREV_INSN (insn);
3916 if (max_to != to)
3917 fail = 1;
3919 if (pmove_upto)
3920 *pmove_upto = max_to;
3922 /* For small register class machines, don't lengthen lifetimes of
3923 hard registers before reload. */
3924 if (! reload_completed
3925 && targetm.small_register_classes_for_mode_p (VOIDmode))
3927 EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
3929 if (i < FIRST_PSEUDO_REGISTER
3930 && ! fixed_regs[i]
3931 && ! global_regs[i])
3932 fail = 1;
3936 out:
3937 BITMAP_FREE (merge_set);
3938 BITMAP_FREE (merge_use);
3939 BITMAP_FREE (local_merge_live);
3940 BITMAP_FREE (test_set);
3941 BITMAP_FREE (test_use);
3943 return !fail;
3947 /*----------------------------------------------------------------------------
3948 MULTIPLE DEFINITIONS
3950 Find the locations in the function reached by multiple definition sites
3951 for a live pseudo. In and out bitvectors are built for each basic
3952 block. They are restricted for efficiency to live registers.
3954 The gen and kill sets for the problem are obvious. Together they
3955 include all defined registers in a basic block; the gen set includes
3956 registers where a partial or conditional or may-clobber definition is
3957 last in the BB, while the kill set includes registers with a complete
3958 definition coming last. However, the computation of the dataflow
3959 itself is interesting.
3961 The idea behind it comes from SSA form's iterated dominance frontier
3962 criterion for inserting PHI functions. Just like in that case, we can use
3963 the dominance frontier to find places where multiple definitions meet;
3964 a register X defined in a basic block BB1 has multiple definitions in
3965 basic blocks in BB1's dominance frontier.
3967 So, the in-set of a basic block BB2 is not just the union of the
3968 out-sets of BB2's predecessors, but includes some more bits that come
3969 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3970 the previous paragraph). I called this set the init-set of BB2.
3972 (Note: I actually use the kill-set only to build the init-set.
3973 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3975 For example, if you have
3977 BB1 : r10 = 0
3978 r11 = 0
3979 if <...> goto BB2 else goto BB3;
3981 BB2 : r10 = 1
3982 r12 = 1
3983 goto BB3;
3985 BB3 :
3987 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3988 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3989 not need to iterate the dominance frontier, because we do not insert
3990 anything like PHI functions there! Instead, dataflow will take care of
3991 propagating the information to BB3's successors.
3992 ---------------------------------------------------------------------------*/
3994 /* Private data used to verify the solution for this problem. */
3995 struct df_md_problem_data
3997 /* An obstack for the bitmaps we need for this problem. */
3998 bitmap_obstack md_bitmaps;
4001 /* Scratch var used by transfer functions. This is used to do md analysis
4002 only for live registers. */
4003 static bitmap_head df_md_scratch;
4006 static void
4007 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
4008 void *vbb_info)
4010 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
4011 if (bb_info)
4013 bitmap_clear (&bb_info->kill);
4014 bitmap_clear (&bb_info->gen);
4015 bitmap_clear (&bb_info->init);
4016 bitmap_clear (&bb_info->in);
4017 bitmap_clear (&bb_info->out);
4022 /* Allocate or reset bitmaps for DF_MD. The solution bits are
4023 not touched unless the block is new. */
4025 static void
4026 df_md_alloc (bitmap all_blocks)
4028 unsigned int bb_index;
4029 bitmap_iterator bi;
4030 struct df_md_problem_data *problem_data;
4032 df_grow_bb_info (df_md);
4033 if (df_md->problem_data)
4034 problem_data = (struct df_md_problem_data *) df_md->problem_data;
4035 else
4037 problem_data = XNEW (struct df_md_problem_data);
4038 df_md->problem_data = problem_data;
4039 bitmap_obstack_initialize (&problem_data->md_bitmaps);
4041 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
4043 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4045 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4046 /* When bitmaps are already initialized, just clear them. */
4047 if (bb_info->init.obstack)
4049 bitmap_clear (&bb_info->init);
4050 bitmap_clear (&bb_info->gen);
4051 bitmap_clear (&bb_info->kill);
4052 bitmap_clear (&bb_info->in);
4053 bitmap_clear (&bb_info->out);
4055 else
4057 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4058 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4059 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4060 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4061 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
4065 df_md->optional_p = true;
4068 /* Add the effect of the top artificial defs of BB to the multiple definitions
4069 bitmap LOCAL_MD. */
4071 void
4072 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4074 int bb_index = bb->index;
4075 df_ref *def_rec;
4076 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4078 df_ref def = *def_rec;
4079 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4081 unsigned int dregno = DF_REF_REGNO (def);
4082 if (DF_REF_FLAGS (def)
4083 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4084 bitmap_set_bit (local_md, dregno);
4085 else
4086 bitmap_clear_bit (local_md, dregno);
4092 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4093 LOCAL_MD. */
4095 void
4096 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
4097 bitmap local_md)
4099 unsigned uid = INSN_UID (insn);
4100 df_ref *def_rec;
4102 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4104 df_ref def = *def_rec;
4105 unsigned int dregno = DF_REF_REGNO (def);
4106 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4107 || (dregno >= FIRST_PSEUDO_REGISTER))
4109 if (DF_REF_FLAGS (def)
4110 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4111 bitmap_set_bit (local_md, DF_REF_ID (def));
4112 else
4113 bitmap_clear_bit (local_md, DF_REF_ID (def));
4118 static void
4119 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
4120 df_ref *def_rec,
4121 int top_flag)
4123 df_ref def;
4124 bitmap_clear (&seen_in_insn);
4126 while ((def = *def_rec++) != NULL)
4128 unsigned int dregno = DF_REF_REGNO (def);
4129 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4130 || (dregno >= FIRST_PSEUDO_REGISTER))
4131 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4133 if (!bitmap_bit_p (&seen_in_insn, dregno))
4135 if (DF_REF_FLAGS (def)
4136 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4138 bitmap_set_bit (&bb_info->gen, dregno);
4139 bitmap_clear_bit (&bb_info->kill, dregno);
4141 else
4143 /* When we find a clobber and a regular def,
4144 make sure the regular def wins. */
4145 bitmap_set_bit (&seen_in_insn, dregno);
4146 bitmap_set_bit (&bb_info->kill, dregno);
4147 bitmap_clear_bit (&bb_info->gen, dregno);
4155 /* Compute local multiple def info for basic block BB. */
4157 static void
4158 df_md_bb_local_compute (unsigned int bb_index)
4160 basic_block bb = BASIC_BLOCK (bb_index);
4161 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4162 rtx insn;
4164 /* Artificials are only hard regs. */
4165 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4166 df_md_bb_local_compute_process_def (bb_info,
4167 df_get_artificial_defs (bb_index),
4168 DF_REF_AT_TOP);
4170 FOR_BB_INSNS (bb, insn)
4172 unsigned int uid = INSN_UID (insn);
4173 if (!INSN_P (insn))
4174 continue;
4176 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4179 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4180 df_md_bb_local_compute_process_def (bb_info,
4181 df_get_artificial_defs (bb_index),
4185 /* Compute local reaching def info for each basic block within BLOCKS. */
4187 static void
4188 df_md_local_compute (bitmap all_blocks)
4190 unsigned int bb_index, df_bb_index;
4191 bitmap_iterator bi1, bi2;
4192 basic_block bb;
4193 bitmap_head *frontiers;
4195 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4197 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4199 df_md_bb_local_compute (bb_index);
4202 bitmap_clear (&seen_in_insn);
4204 frontiers = XNEWVEC (bitmap_head, last_basic_block);
4205 FOR_ALL_BB (bb)
4206 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4208 compute_dominance_frontiers (frontiers);
4210 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4211 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4213 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4214 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4216 basic_block bb = BASIC_BLOCK (df_bb_index);
4217 if (bitmap_bit_p (all_blocks, df_bb_index))
4218 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4219 df_get_live_in (bb));
4223 FOR_ALL_BB (bb)
4224 bitmap_clear (&frontiers[bb->index]);
4225 free (frontiers);
4229 /* Reset the global solution for recalculation. */
4231 static void
4232 df_md_reset (bitmap all_blocks)
4234 unsigned int bb_index;
4235 bitmap_iterator bi;
4237 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4239 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4240 gcc_assert (bb_info);
4241 bitmap_clear (&bb_info->in);
4242 bitmap_clear (&bb_info->out);
4246 static bool
4247 df_md_transfer_function (int bb_index)
4249 basic_block bb = BASIC_BLOCK (bb_index);
4250 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4251 bitmap in = &bb_info->in;
4252 bitmap out = &bb_info->out;
4253 bitmap gen = &bb_info->gen;
4254 bitmap kill = &bb_info->kill;
4256 /* We need to use a scratch set here so that the value returned from this
4257 function invocation properly reflects whether the sets changed in a
4258 significant way; i.e. not just because the live set was anded in. */
4259 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4261 /* Multiple definitions of a register are not relevant if it is not
4262 live. Thus we trim the result to the places where it is live. */
4263 bitmap_and_into (in, df_get_live_in (bb));
4265 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4268 /* Initialize the solution bit vectors for problem. */
4270 static void
4271 df_md_init (bitmap all_blocks)
4273 unsigned int bb_index;
4274 bitmap_iterator bi;
4276 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4278 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4280 bitmap_copy (&bb_info->in, &bb_info->init);
4281 df_md_transfer_function (bb_index);
4285 static void
4286 df_md_confluence_0 (basic_block bb)
4288 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4289 bitmap_copy (&bb_info->in, &bb_info->init);
4292 /* In of target gets or of out of source. */
4294 static bool
4295 df_md_confluence_n (edge e)
4297 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4298 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4300 if (e->flags & EDGE_FAKE)
4301 return false;
4303 if (e->flags & EDGE_EH)
4304 return bitmap_ior_and_compl_into (op1, op2,
4305 regs_invalidated_by_call_regset);
4306 else
4307 return bitmap_ior_into (op1, op2);
4310 /* Free all storage associated with the problem. */
4312 static void
4313 df_md_free (void)
4315 struct df_md_problem_data *problem_data
4316 = (struct df_md_problem_data *) df_md->problem_data;
4318 bitmap_obstack_release (&problem_data->md_bitmaps);
4319 free (problem_data);
4320 df_md->problem_data = NULL;
4322 df_md->block_info_size = 0;
4323 free (df_md->block_info);
4324 df_md->block_info = NULL;
4325 free (df_md);
4329 /* Debugging info at top of bb. */
4331 static void
4332 df_md_top_dump (basic_block bb, FILE *file)
4334 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4335 if (!bb_info)
4336 return;
4338 fprintf (file, ";; md in \t");
4339 df_print_regset (file, &bb_info->in);
4340 fprintf (file, ";; md init \t");
4341 df_print_regset (file, &bb_info->init);
4342 fprintf (file, ";; md gen \t");
4343 df_print_regset (file, &bb_info->gen);
4344 fprintf (file, ";; md kill \t");
4345 df_print_regset (file, &bb_info->kill);
4348 /* Debugging info at bottom of bb. */
4350 static void
4351 df_md_bottom_dump (basic_block bb, FILE *file)
4353 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4354 if (!bb_info)
4355 return;
4357 fprintf (file, ";; md out \t");
4358 df_print_regset (file, &bb_info->out);
4361 static struct df_problem problem_MD =
4363 DF_MD, /* Problem id. */
4364 DF_FORWARD, /* Direction. */
4365 df_md_alloc, /* Allocate the problem specific data. */
4366 df_md_reset, /* Reset global information. */
4367 df_md_free_bb_info, /* Free basic block info. */
4368 df_md_local_compute, /* Local compute function. */
4369 df_md_init, /* Init the solution specific data. */
4370 df_worklist_dataflow, /* Worklist solver. */
4371 df_md_confluence_0, /* Confluence operator 0. */
4372 df_md_confluence_n, /* Confluence operator n. */
4373 df_md_transfer_function, /* Transfer function. */
4374 NULL, /* Finalize function. */
4375 df_md_free, /* Free all of the problem information. */
4376 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4377 NULL, /* Debugging. */
4378 df_md_top_dump, /* Debugging start block. */
4379 df_md_bottom_dump, /* Debugging end block. */
4380 NULL, /* Incremental solution verify start. */
4381 NULL, /* Incremental solution verify end. */
4382 NULL, /* Dependent problem. */
4383 sizeof (struct df_md_bb_info),/* Size of entry of block_info array. */
4384 TV_DF_MD, /* Timing variable. */
4385 false /* Reset blocks on dropping out of blocks_to_analyze. */
4388 /* Create a new MD instance and add it to the existing instance
4389 of DF. */
4391 void
4392 df_md_add_problem (void)
4394 df_add_problem (&problem_MD);