PR libstdc++/67078
[official-gcc.git] / gcc / df-problems.c
blobd4b5d76662e8c86e5244421badc78609ba64b138
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "backend.h"
28 #include "rtl.h"
29 #include "df.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "recog.h"
33 #include "regs.h"
34 #include "alloc-pool.h"
35 #include "flags.h"
36 #include "cfganal.h"
37 #include "target.h"
38 #include "timevar.h"
39 #include "except.h"
40 #include "dce.h"
41 #include "valtrack.h"
42 #include "dumpfile.h"
43 #include "rtl-iter.h"
45 /* Note that turning REG_DEAD_DEBUGGING on will cause
46 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
47 addresses in the dumps. */
48 #define REG_DEAD_DEBUGGING 0
50 #define DF_SPARSE_THRESHOLD 32
52 static bitmap_head seen_in_block;
53 static bitmap_head seen_in_insn;
55 /*----------------------------------------------------------------------------
56 Utility functions.
57 ----------------------------------------------------------------------------*/
59 /* Generic versions to get the void* version of the block info. Only
60 used inside the problem instance vectors. */
62 /* Dump a def-use or use-def chain for REF to FILE. */
64 void
65 df_chain_dump (struct df_link *link, FILE *file)
67 fprintf (file, "{ ");
68 for (; link; link = link->next)
70 fprintf (file, "%c%d(bb %d insn %d) ",
71 DF_REF_REG_DEF_P (link->ref)
72 ? 'd'
73 : (DF_REF_FLAGS (link->ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
74 DF_REF_ID (link->ref),
75 DF_REF_BBNO (link->ref),
76 DF_REF_IS_ARTIFICIAL (link->ref)
77 ? -1 : DF_REF_INSN_UID (link->ref));
79 fprintf (file, "}");
83 /* Print some basic block info as part of df_dump. */
85 void
86 df_print_bb_index (basic_block bb, FILE *file)
88 edge e;
89 edge_iterator ei;
91 fprintf (file, "\n( ");
92 FOR_EACH_EDGE (e, ei, bb->preds)
94 basic_block pred = e->src;
95 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
97 fprintf (file, ")->[%d]->( ", bb->index);
98 FOR_EACH_EDGE (e, ei, bb->succs)
100 basic_block succ = e->dest;
101 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
103 fprintf (file, ")\n");
107 /*----------------------------------------------------------------------------
108 REACHING DEFINITIONS
110 Find the locations in the function where each definition site for a
111 pseudo reaches. In and out bitvectors are built for each basic
112 block. The id field in the ref is used to index into these sets.
113 See df.h for details.
115 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
116 existing uses are included in the global reaching DEFs set, or in other
117 words only DEFs that are still live. This is a kind of pruned version
118 of the traditional reaching definitions problem that is much less
119 complex to compute and produces enough information to compute UD-chains.
120 In this context, live must be interpreted in the DF_LR sense: Uses that
121 are upward exposed but maybe not initialized on all paths through the
122 CFG. For a USE that is not reached by a DEF on all paths, we still want
123 to make those DEFs that do reach the USE visible, and pruning based on
124 DF_LIVE would make that impossible.
125 ----------------------------------------------------------------------------*/
127 /* This problem plays a large number of games for the sake of
128 efficiency.
130 1) The order of the bits in the bitvectors. After the scanning
131 phase, all of the defs are sorted. All of the defs for the reg 0
132 are first, followed by all defs for reg 1 and so on.
134 2) There are two kill sets, one if the number of defs is less or
135 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
136 greater.
138 <= : Data is built directly in the kill set.
140 > : One level of indirection is used to keep from generating long
141 strings of 1 bits in the kill sets. Bitvectors that are indexed
142 by the regnum are used to represent that there is a killing def
143 for the register. The confluence and transfer functions use
144 these along with the bitmap_clear_range call to remove ranges of
145 bits without actually generating a knockout vector.
147 The kill and sparse_kill and the dense_invalidated_by_call and
148 sparse_invalidated_by_call both play this game. */
150 /* Private data used to compute the solution for this problem. These
151 data structures are not accessible outside of this module. */
152 struct df_rd_problem_data
154 /* The set of defs to regs invalidated by call. */
155 bitmap_head sparse_invalidated_by_call;
156 /* The set of defs to regs invalidate by call for rd. */
157 bitmap_head dense_invalidated_by_call;
158 /* An obstack for the bitmaps we need for this problem. */
159 bitmap_obstack rd_bitmaps;
163 /* Free basic block info. */
165 static void
166 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
167 void *vbb_info)
169 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
170 if (bb_info)
172 bitmap_clear (&bb_info->kill);
173 bitmap_clear (&bb_info->sparse_kill);
174 bitmap_clear (&bb_info->gen);
175 bitmap_clear (&bb_info->in);
176 bitmap_clear (&bb_info->out);
181 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
182 not touched unless the block is new. */
184 static void
185 df_rd_alloc (bitmap all_blocks)
187 unsigned int bb_index;
188 bitmap_iterator bi;
189 struct df_rd_problem_data *problem_data;
191 if (df_rd->problem_data)
193 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
194 bitmap_clear (&problem_data->sparse_invalidated_by_call);
195 bitmap_clear (&problem_data->dense_invalidated_by_call);
197 else
199 problem_data = XNEW (struct df_rd_problem_data);
200 df_rd->problem_data = problem_data;
202 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
203 bitmap_initialize (&problem_data->sparse_invalidated_by_call,
204 &problem_data->rd_bitmaps);
205 bitmap_initialize (&problem_data->dense_invalidated_by_call,
206 &problem_data->rd_bitmaps);
209 df_grow_bb_info (df_rd);
211 /* Because of the clustering of all use sites for the same pseudo,
212 we have to process all of the blocks before doing the analysis. */
214 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
216 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
218 /* When bitmaps are already initialized, just clear them. */
219 if (bb_info->kill.obstack)
221 bitmap_clear (&bb_info->kill);
222 bitmap_clear (&bb_info->sparse_kill);
223 bitmap_clear (&bb_info->gen);
225 else
227 bitmap_initialize (&bb_info->kill, &problem_data->rd_bitmaps);
228 bitmap_initialize (&bb_info->sparse_kill, &problem_data->rd_bitmaps);
229 bitmap_initialize (&bb_info->gen, &problem_data->rd_bitmaps);
230 bitmap_initialize (&bb_info->in, &problem_data->rd_bitmaps);
231 bitmap_initialize (&bb_info->out, &problem_data->rd_bitmaps);
234 df_rd->optional_p = true;
238 /* Add the effect of the top artificial defs of BB to the reaching definitions
239 bitmap LOCAL_RD. */
241 void
242 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
244 int bb_index = bb->index;
245 df_ref def;
246 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
247 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
249 unsigned int dregno = DF_REF_REGNO (def);
250 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
251 bitmap_clear_range (local_rd,
252 DF_DEFS_BEGIN (dregno),
253 DF_DEFS_COUNT (dregno));
254 bitmap_set_bit (local_rd, DF_REF_ID (def));
258 /* Add the effect of the defs of INSN to the reaching definitions bitmap
259 LOCAL_RD. */
261 void
262 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
263 bitmap local_rd)
265 df_ref def;
267 FOR_EACH_INSN_DEF (def, insn)
269 unsigned int dregno = DF_REF_REGNO (def);
270 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
271 || (dregno >= FIRST_PSEUDO_REGISTER))
273 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
274 bitmap_clear_range (local_rd,
275 DF_DEFS_BEGIN (dregno),
276 DF_DEFS_COUNT (dregno));
277 if (!(DF_REF_FLAGS (def)
278 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
279 bitmap_set_bit (local_rd, DF_REF_ID (def));
284 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
285 more complicated than just simulating, because we must produce the
286 gen and kill sets and hence deal with the two possible representations
287 of kill sets. */
289 static void
290 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
291 df_ref def,
292 int top_flag)
294 for (; def; def = DF_REF_NEXT_LOC (def))
296 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
298 unsigned int regno = DF_REF_REGNO (def);
299 unsigned int begin = DF_DEFS_BEGIN (regno);
300 unsigned int n_defs = DF_DEFS_COUNT (regno);
302 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
303 || (regno >= FIRST_PSEUDO_REGISTER))
305 /* Only the last def(s) for a regno in the block has any
306 effect. */
307 if (!bitmap_bit_p (&seen_in_block, regno))
309 /* The first def for regno in insn gets to knock out the
310 defs from other instructions. */
311 if ((!bitmap_bit_p (&seen_in_insn, regno))
312 /* If the def is to only part of the reg, it does
313 not kill the other defs that reach here. */
314 && (!(DF_REF_FLAGS (def) &
315 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
317 if (n_defs > DF_SPARSE_THRESHOLD)
319 bitmap_set_bit (&bb_info->sparse_kill, regno);
320 bitmap_clear_range (&bb_info->gen, begin, n_defs);
322 else
324 bitmap_set_range (&bb_info->kill, begin, n_defs);
325 bitmap_clear_range (&bb_info->gen, begin, n_defs);
329 bitmap_set_bit (&seen_in_insn, regno);
330 /* All defs for regno in the instruction may be put into
331 the gen set. */
332 if (!(DF_REF_FLAGS (def)
333 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
334 bitmap_set_bit (&bb_info->gen, DF_REF_ID (def));
341 /* Compute local reaching def info for basic block BB. */
343 static void
344 df_rd_bb_local_compute (unsigned int bb_index)
346 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
347 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
348 rtx_insn *insn;
350 bitmap_clear (&seen_in_block);
351 bitmap_clear (&seen_in_insn);
353 /* Artificials are only hard regs. */
354 if (!(df->changeable_flags & DF_NO_HARD_REGS))
355 df_rd_bb_local_compute_process_def (bb_info,
356 df_get_artificial_defs (bb_index),
359 FOR_BB_INSNS_REVERSE (bb, insn)
361 unsigned int uid = INSN_UID (insn);
363 if (!INSN_P (insn))
364 continue;
366 df_rd_bb_local_compute_process_def (bb_info,
367 DF_INSN_UID_DEFS (uid), 0);
369 /* This complex dance with the two bitmaps is required because
370 instructions can assign twice to the same pseudo. This
371 generally happens with calls that will have one def for the
372 result and another def for the clobber. If only one vector
373 is used and the clobber goes first, the result will be
374 lost. */
375 bitmap_ior_into (&seen_in_block, &seen_in_insn);
376 bitmap_clear (&seen_in_insn);
379 /* Process the artificial defs at the top of the block last since we
380 are going backwards through the block and these are logically at
381 the start. */
382 if (!(df->changeable_flags & DF_NO_HARD_REGS))
383 df_rd_bb_local_compute_process_def (bb_info,
384 df_get_artificial_defs (bb_index),
385 DF_REF_AT_TOP);
389 /* Compute local reaching def info for each basic block within BLOCKS. */
391 static void
392 df_rd_local_compute (bitmap all_blocks)
394 unsigned int bb_index;
395 bitmap_iterator bi;
396 unsigned int regno;
397 struct df_rd_problem_data *problem_data
398 = (struct df_rd_problem_data *) df_rd->problem_data;
399 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
400 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
402 bitmap_initialize (&seen_in_block, &df_bitmap_obstack);
403 bitmap_initialize (&seen_in_insn, &df_bitmap_obstack);
405 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
407 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
409 df_rd_bb_local_compute (bb_index);
412 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
413 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, regno, bi)
415 if (! HARD_REGISTER_NUM_P (regno)
416 || !(df->changeable_flags & DF_NO_HARD_REGS))
418 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
419 bitmap_set_bit (sparse_invalidated, regno);
420 else
421 bitmap_set_range (dense_invalidated,
422 DF_DEFS_BEGIN (regno),
423 DF_DEFS_COUNT (regno));
427 bitmap_clear (&seen_in_block);
428 bitmap_clear (&seen_in_insn);
432 /* Initialize the solution bit vectors for problem. */
434 static void
435 df_rd_init_solution (bitmap all_blocks)
437 unsigned int bb_index;
438 bitmap_iterator bi;
440 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
442 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
444 bitmap_copy (&bb_info->out, &bb_info->gen);
445 bitmap_clear (&bb_info->in);
449 /* In of target gets or of out of source. */
451 static bool
452 df_rd_confluence_n (edge e)
454 bitmap op1 = &df_rd_get_bb_info (e->dest->index)->in;
455 bitmap op2 = &df_rd_get_bb_info (e->src->index)->out;
456 bool changed = false;
458 if (e->flags & EDGE_FAKE)
459 return false;
461 if (e->flags & EDGE_EH)
463 struct df_rd_problem_data *problem_data
464 = (struct df_rd_problem_data *) df_rd->problem_data;
465 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
466 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
467 bitmap_iterator bi;
468 unsigned int regno;
469 bitmap_head tmp;
471 bitmap_initialize (&tmp, &df_bitmap_obstack);
472 bitmap_and_compl (&tmp, op2, dense_invalidated);
474 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
476 bitmap_clear_range (&tmp,
477 DF_DEFS_BEGIN (regno),
478 DF_DEFS_COUNT (regno));
480 changed |= bitmap_ior_into (op1, &tmp);
481 bitmap_clear (&tmp);
482 return changed;
484 else
485 return bitmap_ior_into (op1, op2);
489 /* Transfer function. */
491 static bool
492 df_rd_transfer_function (int bb_index)
494 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
495 unsigned int regno;
496 bitmap_iterator bi;
497 bitmap in = &bb_info->in;
498 bitmap out = &bb_info->out;
499 bitmap gen = &bb_info->gen;
500 bitmap kill = &bb_info->kill;
501 bitmap sparse_kill = &bb_info->sparse_kill;
502 bool changed = false;
504 if (bitmap_empty_p (sparse_kill))
505 changed = bitmap_ior_and_compl (out, gen, in, kill);
506 else
508 struct df_rd_problem_data *problem_data;
509 bitmap_head tmp;
511 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
512 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
513 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
514 bitmap_initialize (&tmp, &problem_data->rd_bitmaps);
516 bitmap_and_compl (&tmp, in, kill);
517 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
519 bitmap_clear_range (&tmp,
520 DF_DEFS_BEGIN (regno),
521 DF_DEFS_COUNT (regno));
523 bitmap_ior_into (&tmp, gen);
524 changed = !bitmap_equal_p (&tmp, out);
525 if (changed)
527 bitmap_clear (out);
528 bb_info->out = tmp;
530 else
531 bitmap_clear (&tmp);
534 if (df->changeable_flags & DF_RD_PRUNE_DEAD_DEFS)
536 /* Create a mask of DEFs for all registers live at the end of this
537 basic block, and mask out DEFs of registers that are not live.
538 Computing the mask looks costly, but the benefit of the pruning
539 outweighs the cost. */
540 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
541 bitmap regs_live_out = &df_lr_get_bb_info (bb_index)->out;
542 bitmap live_defs = BITMAP_ALLOC (&df_bitmap_obstack);
543 unsigned int regno;
544 bitmap_iterator bi;
546 EXECUTE_IF_SET_IN_BITMAP (regs_live_out, 0, regno, bi)
547 bitmap_set_range (live_defs,
548 DF_DEFS_BEGIN (regno),
549 DF_DEFS_COUNT (regno));
550 changed |= bitmap_and_into (&bb_info->out, live_defs);
551 BITMAP_FREE (live_defs);
554 return changed;
557 /* Free all storage associated with the problem. */
559 static void
560 df_rd_free (void)
562 struct df_rd_problem_data *problem_data
563 = (struct df_rd_problem_data *) df_rd->problem_data;
565 if (problem_data)
567 bitmap_obstack_release (&problem_data->rd_bitmaps);
569 df_rd->block_info_size = 0;
570 free (df_rd->block_info);
571 df_rd->block_info = NULL;
572 free (df_rd->problem_data);
574 free (df_rd);
578 /* Debugging info. */
580 static void
581 df_rd_start_dump (FILE *file)
583 struct df_rd_problem_data *problem_data
584 = (struct df_rd_problem_data *) df_rd->problem_data;
585 unsigned int m = DF_REG_SIZE (df);
586 unsigned int regno;
588 if (!df_rd->block_info)
589 return;
591 fprintf (file, ";; Reaching defs:\n");
593 fprintf (file, ";; sparse invalidated \t");
594 dump_bitmap (file, &problem_data->sparse_invalidated_by_call);
595 fprintf (file, ";; dense invalidated \t");
596 dump_bitmap (file, &problem_data->dense_invalidated_by_call);
598 fprintf (file, ";; reg->defs[] map:\t");
599 for (regno = 0; regno < m; regno++)
600 if (DF_DEFS_COUNT (regno))
601 fprintf (file, "%d[%d,%d] ", regno,
602 DF_DEFS_BEGIN (regno),
603 DF_DEFS_BEGIN (regno) + DF_DEFS_COUNT (regno) - 1);
604 fprintf (file, "\n");
608 static void
609 df_rd_dump_defs_set (bitmap defs_set, const char *prefix, FILE *file)
611 bitmap_head tmp;
612 unsigned int regno;
613 unsigned int m = DF_REG_SIZE (df);
614 bool first_reg = true;
616 fprintf (file, "%s\t(%d) ", prefix, (int) bitmap_count_bits (defs_set));
618 bitmap_initialize (&tmp, &df_bitmap_obstack);
619 for (regno = 0; regno < m; regno++)
621 if (HARD_REGISTER_NUM_P (regno)
622 && (df->changeable_flags & DF_NO_HARD_REGS))
623 continue;
624 bitmap_set_range (&tmp, DF_DEFS_BEGIN (regno), DF_DEFS_COUNT (regno));
625 bitmap_and_into (&tmp, defs_set);
626 if (! bitmap_empty_p (&tmp))
628 bitmap_iterator bi;
629 unsigned int ix;
630 bool first_def = true;
632 if (! first_reg)
633 fprintf (file, ",");
634 first_reg = false;
636 fprintf (file, "%u[", regno);
637 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, ix, bi)
639 fprintf (file, "%s%u", first_def ? "" : ",", ix);
640 first_def = false;
642 fprintf (file, "]");
644 bitmap_clear (&tmp);
647 fprintf (file, "\n");
648 bitmap_clear (&tmp);
651 /* Debugging info at top of bb. */
653 static void
654 df_rd_top_dump (basic_block bb, FILE *file)
656 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
657 if (!bb_info)
658 return;
660 df_rd_dump_defs_set (&bb_info->in, ";; rd in ", file);
661 df_rd_dump_defs_set (&bb_info->gen, ";; rd gen ", file);
662 df_rd_dump_defs_set (&bb_info->kill, ";; rd kill", file);
666 /* Debugging info at bottom of bb. */
668 static void
669 df_rd_bottom_dump (basic_block bb, FILE *file)
671 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
672 if (!bb_info)
673 return;
675 df_rd_dump_defs_set (&bb_info->out, ";; rd out ", file);
678 /* All of the information associated with every instance of the problem. */
680 static struct df_problem problem_RD =
682 DF_RD, /* Problem id. */
683 DF_FORWARD, /* Direction. */
684 df_rd_alloc, /* Allocate the problem specific data. */
685 NULL, /* Reset global information. */
686 df_rd_free_bb_info, /* Free basic block info. */
687 df_rd_local_compute, /* Local compute function. */
688 df_rd_init_solution, /* Init the solution specific data. */
689 df_worklist_dataflow, /* Worklist solver. */
690 NULL, /* Confluence operator 0. */
691 df_rd_confluence_n, /* Confluence operator n. */
692 df_rd_transfer_function, /* Transfer function. */
693 NULL, /* Finalize function. */
694 df_rd_free, /* Free all of the problem information. */
695 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
696 df_rd_start_dump, /* Debugging. */
697 df_rd_top_dump, /* Debugging start block. */
698 df_rd_bottom_dump, /* Debugging end block. */
699 NULL, /* Debugging start insn. */
700 NULL, /* Debugging end insn. */
701 NULL, /* Incremental solution verify start. */
702 NULL, /* Incremental solution verify end. */
703 NULL, /* Dependent problem. */
704 sizeof (struct df_rd_bb_info),/* Size of entry of block_info array. */
705 TV_DF_RD, /* Timing variable. */
706 true /* Reset blocks on dropping out of blocks_to_analyze. */
711 /* Create a new RD instance and add it to the existing instance
712 of DF. */
714 void
715 df_rd_add_problem (void)
717 df_add_problem (&problem_RD);
722 /*----------------------------------------------------------------------------
723 LIVE REGISTERS
725 Find the locations in the function where any use of a pseudo can
726 reach in the backwards direction. In and out bitvectors are built
727 for each basic block. The regno is used to index into these sets.
728 See df.h for details.
729 ----------------------------------------------------------------------------*/
731 /* Private data used to verify the solution for this problem. */
732 struct df_lr_problem_data
734 bitmap_head *in;
735 bitmap_head *out;
736 /* An obstack for the bitmaps we need for this problem. */
737 bitmap_obstack lr_bitmaps;
740 /* Free basic block info. */
742 static void
743 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
744 void *vbb_info)
746 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
747 if (bb_info)
749 bitmap_clear (&bb_info->use);
750 bitmap_clear (&bb_info->def);
751 bitmap_clear (&bb_info->in);
752 bitmap_clear (&bb_info->out);
757 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
758 not touched unless the block is new. */
760 static void
761 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
763 unsigned int bb_index;
764 bitmap_iterator bi;
765 struct df_lr_problem_data *problem_data;
767 df_grow_bb_info (df_lr);
768 if (df_lr->problem_data)
769 problem_data = (struct df_lr_problem_data *) df_lr->problem_data;
770 else
772 problem_data = XNEW (struct df_lr_problem_data);
773 df_lr->problem_data = problem_data;
775 problem_data->out = NULL;
776 problem_data->in = NULL;
777 bitmap_obstack_initialize (&problem_data->lr_bitmaps);
780 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
782 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
784 /* When bitmaps are already initialized, just clear them. */
785 if (bb_info->use.obstack)
787 bitmap_clear (&bb_info->def);
788 bitmap_clear (&bb_info->use);
790 else
792 bitmap_initialize (&bb_info->use, &problem_data->lr_bitmaps);
793 bitmap_initialize (&bb_info->def, &problem_data->lr_bitmaps);
794 bitmap_initialize (&bb_info->in, &problem_data->lr_bitmaps);
795 bitmap_initialize (&bb_info->out, &problem_data->lr_bitmaps);
799 df_lr->optional_p = false;
803 /* Reset the global solution for recalculation. */
805 static void
806 df_lr_reset (bitmap all_blocks)
808 unsigned int bb_index;
809 bitmap_iterator bi;
811 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
813 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
814 gcc_assert (bb_info);
815 bitmap_clear (&bb_info->in);
816 bitmap_clear (&bb_info->out);
821 /* Compute local live register info for basic block BB. */
823 static void
824 df_lr_bb_local_compute (unsigned int bb_index)
826 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
827 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
828 rtx_insn *insn;
829 df_ref def, use;
831 /* Process the registers set in an exception handler. */
832 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
833 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
835 unsigned int dregno = DF_REF_REGNO (def);
836 bitmap_set_bit (&bb_info->def, dregno);
837 bitmap_clear_bit (&bb_info->use, dregno);
840 /* Process the hardware registers that are always live. */
841 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
842 /* Add use to set of uses in this BB. */
843 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
844 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
846 FOR_BB_INSNS_REVERSE (bb, insn)
848 if (!NONDEBUG_INSN_P (insn))
849 continue;
851 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
852 FOR_EACH_INSN_INFO_DEF (def, insn_info)
853 /* If the def is to only part of the reg, it does
854 not kill the other defs that reach here. */
855 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
857 unsigned int dregno = DF_REF_REGNO (def);
858 bitmap_set_bit (&bb_info->def, dregno);
859 bitmap_clear_bit (&bb_info->use, dregno);
862 FOR_EACH_INSN_INFO_USE (use, insn_info)
863 /* Add use to set of uses in this BB. */
864 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
867 /* Process the registers set in an exception handler or the hard
868 frame pointer if this block is the target of a non local
869 goto. */
870 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
871 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
873 unsigned int dregno = DF_REF_REGNO (def);
874 bitmap_set_bit (&bb_info->def, dregno);
875 bitmap_clear_bit (&bb_info->use, dregno);
878 #ifdef EH_USES
879 /* Process the uses that are live into an exception handler. */
880 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
881 /* Add use to set of uses in this BB. */
882 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
883 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
884 #endif
886 /* If the df_live problem is not defined, such as at -O0 and -O1, we
887 still need to keep the luids up to date. This is normally done
888 in the df_live problem since this problem has a forwards
889 scan. */
890 if (!df_live)
891 df_recompute_luids (bb);
895 /* Compute local live register info for each basic block within BLOCKS. */
897 static void
898 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
900 unsigned int bb_index, i;
901 bitmap_iterator bi;
903 bitmap_clear (&df->hardware_regs_used);
905 /* The all-important stack pointer must always be live. */
906 bitmap_set_bit (&df->hardware_regs_used, STACK_POINTER_REGNUM);
908 /* Global regs are always live, too. */
909 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
910 if (global_regs[i])
911 bitmap_set_bit (&df->hardware_regs_used, i);
913 /* Before reload, there are a few registers that must be forced
914 live everywhere -- which might not already be the case for
915 blocks within infinite loops. */
916 if (!reload_completed)
918 unsigned int pic_offset_table_regnum = PIC_OFFSET_TABLE_REGNUM;
919 /* Any reference to any pseudo before reload is a potential
920 reference of the frame pointer. */
921 bitmap_set_bit (&df->hardware_regs_used, FRAME_POINTER_REGNUM);
923 /* Pseudos with argument area equivalences may require
924 reloading via the argument pointer. */
925 if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
926 && fixed_regs[ARG_POINTER_REGNUM])
927 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
929 /* Any constant, or pseudo with constant equivalences, may
930 require reloading from memory using the pic register. */
931 if (pic_offset_table_regnum != INVALID_REGNUM
932 && fixed_regs[pic_offset_table_regnum])
933 bitmap_set_bit (&df->hardware_regs_used, pic_offset_table_regnum);
936 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
938 if (bb_index == EXIT_BLOCK)
940 /* The exit block is special for this problem and its bits are
941 computed from thin air. */
942 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
943 bitmap_copy (&bb_info->use, df->exit_block_uses);
945 else
946 df_lr_bb_local_compute (bb_index);
949 bitmap_clear (df_lr->out_of_date_transfer_functions);
953 /* Initialize the solution vectors. */
955 static void
956 df_lr_init (bitmap all_blocks)
958 unsigned int bb_index;
959 bitmap_iterator bi;
961 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
963 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
964 bitmap_copy (&bb_info->in, &bb_info->use);
965 bitmap_clear (&bb_info->out);
970 /* Confluence function that processes infinite loops. This might be a
971 noreturn function that throws. And even if it isn't, getting the
972 unwind info right helps debugging. */
973 static void
974 df_lr_confluence_0 (basic_block bb)
976 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
977 if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
978 bitmap_copy (op1, &df->hardware_regs_used);
982 /* Confluence function that ignores fake edges. */
984 static bool
985 df_lr_confluence_n (edge e)
987 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
988 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
989 bool changed = false;
991 /* Call-clobbered registers die across exception and call edges. */
992 /* ??? Abnormal call edges ignored for the moment, as this gets
993 confused by sibling call edges, which crashes reg-stack. */
994 if (e->flags & EDGE_EH)
995 changed = bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
996 else
997 changed = bitmap_ior_into (op1, op2);
999 changed |= bitmap_ior_into (op1, &df->hardware_regs_used);
1000 return changed;
1004 /* Transfer function. */
1006 static bool
1007 df_lr_transfer_function (int bb_index)
1009 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1010 bitmap in = &bb_info->in;
1011 bitmap out = &bb_info->out;
1012 bitmap use = &bb_info->use;
1013 bitmap def = &bb_info->def;
1015 return bitmap_ior_and_compl (in, use, out, def);
1019 /* Run the fast dce as a side effect of building LR. */
1021 static void
1022 df_lr_finalize (bitmap all_blocks)
1024 df_lr->solutions_dirty = false;
1025 if (df->changeable_flags & DF_LR_RUN_DCE)
1027 run_fast_df_dce ();
1029 /* If dce deletes some instructions, we need to recompute the lr
1030 solution before proceeding further. The problem is that fast
1031 dce is a pessimestic dataflow algorithm. In the case where
1032 it deletes a statement S inside of a loop, the uses inside of
1033 S may not be deleted from the dataflow solution because they
1034 were carried around the loop. While it is conservatively
1035 correct to leave these extra bits, the standards of df
1036 require that we maintain the best possible (least fixed
1037 point) solution. The only way to do that is to redo the
1038 iteration from the beginning. See PR35805 for an
1039 example. */
1040 if (df_lr->solutions_dirty)
1042 df_clear_flags (DF_LR_RUN_DCE);
1043 df_lr_alloc (all_blocks);
1044 df_lr_local_compute (all_blocks);
1045 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1046 df_lr_finalize (all_blocks);
1047 df_set_flags (DF_LR_RUN_DCE);
1053 /* Free all storage associated with the problem. */
1055 static void
1056 df_lr_free (void)
1058 struct df_lr_problem_data *problem_data
1059 = (struct df_lr_problem_data *) df_lr->problem_data;
1060 if (df_lr->block_info)
1063 df_lr->block_info_size = 0;
1064 free (df_lr->block_info);
1065 df_lr->block_info = NULL;
1066 bitmap_obstack_release (&problem_data->lr_bitmaps);
1067 free (df_lr->problem_data);
1068 df_lr->problem_data = NULL;
1071 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1072 free (df_lr);
1076 /* Debugging info at top of bb. */
1078 static void
1079 df_lr_top_dump (basic_block bb, FILE *file)
1081 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1082 struct df_lr_problem_data *problem_data;
1083 if (!bb_info)
1084 return;
1086 fprintf (file, ";; lr in \t");
1087 df_print_regset (file, &bb_info->in);
1088 if (df_lr->problem_data)
1090 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1091 if (problem_data->in)
1093 fprintf (file, ";; old in \t");
1094 df_print_regset (file, &problem_data->in[bb->index]);
1097 fprintf (file, ";; lr use \t");
1098 df_print_regset (file, &bb_info->use);
1099 fprintf (file, ";; lr def \t");
1100 df_print_regset (file, &bb_info->def);
1104 /* Debugging info at bottom of bb. */
1106 static void
1107 df_lr_bottom_dump (basic_block bb, FILE *file)
1109 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1110 struct df_lr_problem_data *problem_data;
1111 if (!bb_info)
1112 return;
1114 fprintf (file, ";; lr out \t");
1115 df_print_regset (file, &bb_info->out);
1116 if (df_lr->problem_data)
1118 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1119 if (problem_data->out)
1121 fprintf (file, ";; old out \t");
1122 df_print_regset (file, &problem_data->out[bb->index]);
1128 /* Build the datastructure to verify that the solution to the dataflow
1129 equations is not dirty. */
1131 static void
1132 df_lr_verify_solution_start (void)
1134 basic_block bb;
1135 struct df_lr_problem_data *problem_data;
1136 if (df_lr->solutions_dirty)
1137 return;
1139 /* Set it true so that the solution is recomputed. */
1140 df_lr->solutions_dirty = true;
1142 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1143 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1144 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1146 FOR_ALL_BB_FN (bb, cfun)
1148 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1149 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1150 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1151 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1156 /* Compare the saved datastructure and the new solution to the dataflow
1157 equations. */
1159 static void
1160 df_lr_verify_solution_end (void)
1162 struct df_lr_problem_data *problem_data;
1163 basic_block bb;
1165 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1167 if (!problem_data->out)
1168 return;
1170 if (df_lr->solutions_dirty)
1171 /* Do not check if the solution is still dirty. See the comment
1172 in df_lr_finalize for details. */
1173 df_lr->solutions_dirty = false;
1174 else
1175 FOR_ALL_BB_FN (bb, cfun)
1177 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1178 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1180 /*df_dump (stderr);*/
1181 gcc_unreachable ();
1185 /* Cannot delete them immediately because you may want to dump them
1186 if the comparison fails. */
1187 FOR_ALL_BB_FN (bb, cfun)
1189 bitmap_clear (&problem_data->in[bb->index]);
1190 bitmap_clear (&problem_data->out[bb->index]);
1193 free (problem_data->in);
1194 free (problem_data->out);
1195 problem_data->in = NULL;
1196 problem_data->out = NULL;
1200 /* All of the information associated with every instance of the problem. */
1202 static struct df_problem problem_LR =
1204 DF_LR, /* Problem id. */
1205 DF_BACKWARD, /* Direction. */
1206 df_lr_alloc, /* Allocate the problem specific data. */
1207 df_lr_reset, /* Reset global information. */
1208 df_lr_free_bb_info, /* Free basic block info. */
1209 df_lr_local_compute, /* Local compute function. */
1210 df_lr_init, /* Init the solution specific data. */
1211 df_worklist_dataflow, /* Worklist solver. */
1212 df_lr_confluence_0, /* Confluence operator 0. */
1213 df_lr_confluence_n, /* Confluence operator n. */
1214 df_lr_transfer_function, /* Transfer function. */
1215 df_lr_finalize, /* Finalize function. */
1216 df_lr_free, /* Free all of the problem information. */
1217 NULL, /* Remove this problem from the stack of dataflow problems. */
1218 NULL, /* Debugging. */
1219 df_lr_top_dump, /* Debugging start block. */
1220 df_lr_bottom_dump, /* Debugging end block. */
1221 NULL, /* Debugging start insn. */
1222 NULL, /* Debugging end insn. */
1223 df_lr_verify_solution_start,/* Incremental solution verify start. */
1224 df_lr_verify_solution_end, /* Incremental solution verify end. */
1225 NULL, /* Dependent problem. */
1226 sizeof (struct df_lr_bb_info),/* Size of entry of block_info array. */
1227 TV_DF_LR, /* Timing variable. */
1228 false /* Reset blocks on dropping out of blocks_to_analyze. */
1232 /* Create a new DATAFLOW instance and add it to an existing instance
1233 of DF. The returned structure is what is used to get at the
1234 solution. */
1236 void
1237 df_lr_add_problem (void)
1239 df_add_problem (&problem_LR);
1240 /* These will be initialized when df_scan_blocks processes each
1241 block. */
1242 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1246 /* Verify that all of the lr related info is consistent and
1247 correct. */
1249 void
1250 df_lr_verify_transfer_functions (void)
1252 basic_block bb;
1253 bitmap_head saved_def;
1254 bitmap_head saved_use;
1255 bitmap_head all_blocks;
1257 if (!df)
1258 return;
1260 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1261 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1262 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1264 FOR_ALL_BB_FN (bb, cfun)
1266 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1267 bitmap_set_bit (&all_blocks, bb->index);
1269 if (bb_info)
1271 /* Make a copy of the transfer functions and then compute
1272 new ones to see if the transfer functions have
1273 changed. */
1274 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1275 bb->index))
1277 bitmap_copy (&saved_def, &bb_info->def);
1278 bitmap_copy (&saved_use, &bb_info->use);
1279 bitmap_clear (&bb_info->def);
1280 bitmap_clear (&bb_info->use);
1282 df_lr_bb_local_compute (bb->index);
1283 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1284 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1287 else
1289 /* If we do not have basic block info, the block must be in
1290 the list of dirty blocks or else some one has added a
1291 block behind our backs. */
1292 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1293 bb->index));
1295 /* Make sure no one created a block without following
1296 procedures. */
1297 gcc_assert (df_scan_get_bb_info (bb->index));
1300 /* Make sure there are no dirty bits in blocks that have been deleted. */
1301 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1302 &all_blocks));
1304 bitmap_clear (&saved_def);
1305 bitmap_clear (&saved_use);
1306 bitmap_clear (&all_blocks);
1311 /*----------------------------------------------------------------------------
1312 LIVE AND MUST-INITIALIZED REGISTERS.
1314 This problem first computes the IN and OUT bitvectors for the
1315 must-initialized registers problems, which is a forward problem.
1316 It gives the set of registers for which we MUST have an available
1317 definition on any path from the entry block to the entry/exit of
1318 a basic block. Sets generate a definition, while clobbers kill
1319 a definition.
1321 In and out bitvectors are built for each basic block and are indexed by
1322 regnum (see df.h for details). In and out bitvectors in struct
1323 df_live_bb_info actually refers to the must-initialized problem;
1325 Then, the in and out sets for the LIVE problem itself are computed.
1326 These are the logical AND of the IN and OUT sets from the LR problem
1327 and the must-initialized problem.
1328 ----------------------------------------------------------------------------*/
1330 /* Private data used to verify the solution for this problem. */
1331 struct df_live_problem_data
1333 bitmap_head *in;
1334 bitmap_head *out;
1335 /* An obstack for the bitmaps we need for this problem. */
1336 bitmap_obstack live_bitmaps;
1339 /* Scratch var used by transfer functions. This is used to implement
1340 an optimization to reduce the amount of space used to compute the
1341 combined lr and live analysis. */
1342 static bitmap_head df_live_scratch;
1345 /* Free basic block info. */
1347 static void
1348 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1349 void *vbb_info)
1351 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1352 if (bb_info)
1354 bitmap_clear (&bb_info->gen);
1355 bitmap_clear (&bb_info->kill);
1356 bitmap_clear (&bb_info->in);
1357 bitmap_clear (&bb_info->out);
1362 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1363 not touched unless the block is new. */
1365 static void
1366 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1368 unsigned int bb_index;
1369 bitmap_iterator bi;
1370 struct df_live_problem_data *problem_data;
1372 if (df_live->problem_data)
1373 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1374 else
1376 problem_data = XNEW (struct df_live_problem_data);
1377 df_live->problem_data = problem_data;
1379 problem_data->out = NULL;
1380 problem_data->in = NULL;
1381 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1382 bitmap_initialize (&df_live_scratch, &problem_data->live_bitmaps);
1385 df_grow_bb_info (df_live);
1387 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1389 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1391 /* When bitmaps are already initialized, just clear them. */
1392 if (bb_info->kill.obstack)
1394 bitmap_clear (&bb_info->kill);
1395 bitmap_clear (&bb_info->gen);
1397 else
1399 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1400 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1401 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1402 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1405 df_live->optional_p = (optimize <= 1);
1409 /* Reset the global solution for recalculation. */
1411 static void
1412 df_live_reset (bitmap all_blocks)
1414 unsigned int bb_index;
1415 bitmap_iterator bi;
1417 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1419 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1420 gcc_assert (bb_info);
1421 bitmap_clear (&bb_info->in);
1422 bitmap_clear (&bb_info->out);
1427 /* Compute local uninitialized register info for basic block BB. */
1429 static void
1430 df_live_bb_local_compute (unsigned int bb_index)
1432 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1433 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1434 rtx_insn *insn;
1435 df_ref def;
1436 int luid = 0;
1438 FOR_BB_INSNS (bb, insn)
1440 unsigned int uid = INSN_UID (insn);
1441 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1443 /* Inserting labels does not always trigger the incremental
1444 rescanning. */
1445 if (!insn_info)
1447 gcc_assert (!INSN_P (insn));
1448 insn_info = df_insn_create_insn_record (insn);
1451 DF_INSN_INFO_LUID (insn_info) = luid;
1452 if (!INSN_P (insn))
1453 continue;
1455 luid++;
1456 FOR_EACH_INSN_INFO_DEF (def, insn_info)
1458 unsigned int regno = DF_REF_REGNO (def);
1460 if (DF_REF_FLAGS_IS_SET (def,
1461 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1462 /* All partial or conditional def
1463 seen are included in the gen set. */
1464 bitmap_set_bit (&bb_info->gen, regno);
1465 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1466 /* Only must clobbers for the entire reg destroy the
1467 value. */
1468 bitmap_set_bit (&bb_info->kill, regno);
1469 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1470 bitmap_set_bit (&bb_info->gen, regno);
1474 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
1475 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1479 /* Compute local uninitialized register info. */
1481 static void
1482 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1484 unsigned int bb_index;
1485 bitmap_iterator bi;
1487 df_grow_insn_info ();
1489 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1490 0, bb_index, bi)
1492 df_live_bb_local_compute (bb_index);
1495 bitmap_clear (df_live->out_of_date_transfer_functions);
1499 /* Initialize the solution vectors. */
1501 static void
1502 df_live_init (bitmap all_blocks)
1504 unsigned int bb_index;
1505 bitmap_iterator bi;
1507 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1509 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1510 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1512 /* No register may reach a location where it is not used. Thus
1513 we trim the rr result to the places where it is used. */
1514 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1515 bitmap_clear (&bb_info->in);
1519 /* Forward confluence function that ignores fake edges. */
1521 static bool
1522 df_live_confluence_n (edge e)
1524 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1525 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1527 if (e->flags & EDGE_FAKE)
1528 return false;
1530 return bitmap_ior_into (op1, op2);
1534 /* Transfer function for the forwards must-initialized problem. */
1536 static bool
1537 df_live_transfer_function (int bb_index)
1539 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1540 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1541 bitmap in = &bb_info->in;
1542 bitmap out = &bb_info->out;
1543 bitmap gen = &bb_info->gen;
1544 bitmap kill = &bb_info->kill;
1546 /* We need to use a scratch set here so that the value returned from this
1547 function invocation properly reflects whether the sets changed in a
1548 significant way; i.e. not just because the lr set was anded in. */
1549 bitmap_and (&df_live_scratch, gen, &bb_lr_info->out);
1550 /* No register may reach a location where it is not used. Thus
1551 we trim the rr result to the places where it is used. */
1552 bitmap_and_into (in, &bb_lr_info->in);
1554 return bitmap_ior_and_compl (out, &df_live_scratch, in, kill);
1558 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1560 static void
1561 df_live_finalize (bitmap all_blocks)
1564 if (df_live->solutions_dirty)
1566 bitmap_iterator bi;
1567 unsigned int bb_index;
1569 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1571 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1572 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1574 /* No register may reach a location where it is not used. Thus
1575 we trim the rr result to the places where it is used. */
1576 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1577 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1580 df_live->solutions_dirty = false;
1585 /* Free all storage associated with the problem. */
1587 static void
1588 df_live_free (void)
1590 struct df_live_problem_data *problem_data
1591 = (struct df_live_problem_data *) df_live->problem_data;
1592 if (df_live->block_info)
1594 df_live->block_info_size = 0;
1595 free (df_live->block_info);
1596 df_live->block_info = NULL;
1597 bitmap_clear (&df_live_scratch);
1598 bitmap_obstack_release (&problem_data->live_bitmaps);
1599 free (problem_data);
1600 df_live->problem_data = NULL;
1602 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1603 free (df_live);
1607 /* Debugging info at top of bb. */
1609 static void
1610 df_live_top_dump (basic_block bb, FILE *file)
1612 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1613 struct df_live_problem_data *problem_data;
1615 if (!bb_info)
1616 return;
1618 fprintf (file, ";; live in \t");
1619 df_print_regset (file, &bb_info->in);
1620 if (df_live->problem_data)
1622 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1623 if (problem_data->in)
1625 fprintf (file, ";; old in \t");
1626 df_print_regset (file, &problem_data->in[bb->index]);
1629 fprintf (file, ";; live gen \t");
1630 df_print_regset (file, &bb_info->gen);
1631 fprintf (file, ";; live kill\t");
1632 df_print_regset (file, &bb_info->kill);
1636 /* Debugging info at bottom of bb. */
1638 static void
1639 df_live_bottom_dump (basic_block bb, FILE *file)
1641 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1642 struct df_live_problem_data *problem_data;
1644 if (!bb_info)
1645 return;
1647 fprintf (file, ";; live out \t");
1648 df_print_regset (file, &bb_info->out);
1649 if (df_live->problem_data)
1651 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1652 if (problem_data->out)
1654 fprintf (file, ";; old out \t");
1655 df_print_regset (file, &problem_data->out[bb->index]);
1661 /* Build the datastructure to verify that the solution to the dataflow
1662 equations is not dirty. */
1664 static void
1665 df_live_verify_solution_start (void)
1667 basic_block bb;
1668 struct df_live_problem_data *problem_data;
1669 if (df_live->solutions_dirty)
1670 return;
1672 /* Set it true so that the solution is recomputed. */
1673 df_live->solutions_dirty = true;
1675 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1676 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1677 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1679 FOR_ALL_BB_FN (bb, cfun)
1681 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1682 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1683 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1684 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1689 /* Compare the saved datastructure and the new solution to the dataflow
1690 equations. */
1692 static void
1693 df_live_verify_solution_end (void)
1695 struct df_live_problem_data *problem_data;
1696 basic_block bb;
1698 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1699 if (!problem_data->out)
1700 return;
1702 FOR_ALL_BB_FN (bb, cfun)
1704 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1705 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1707 /*df_dump (stderr);*/
1708 gcc_unreachable ();
1712 /* Cannot delete them immediately because you may want to dump them
1713 if the comparison fails. */
1714 FOR_ALL_BB_FN (bb, cfun)
1716 bitmap_clear (&problem_data->in[bb->index]);
1717 bitmap_clear (&problem_data->out[bb->index]);
1720 free (problem_data->in);
1721 free (problem_data->out);
1722 free (problem_data);
1723 df_live->problem_data = NULL;
1727 /* All of the information associated with every instance of the problem. */
1729 static struct df_problem problem_LIVE =
1731 DF_LIVE, /* Problem id. */
1732 DF_FORWARD, /* Direction. */
1733 df_live_alloc, /* Allocate the problem specific data. */
1734 df_live_reset, /* Reset global information. */
1735 df_live_free_bb_info, /* Free basic block info. */
1736 df_live_local_compute, /* Local compute function. */
1737 df_live_init, /* Init the solution specific data. */
1738 df_worklist_dataflow, /* Worklist solver. */
1739 NULL, /* Confluence operator 0. */
1740 df_live_confluence_n, /* Confluence operator n. */
1741 df_live_transfer_function, /* Transfer function. */
1742 df_live_finalize, /* Finalize function. */
1743 df_live_free, /* Free all of the problem information. */
1744 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1745 NULL, /* Debugging. */
1746 df_live_top_dump, /* Debugging start block. */
1747 df_live_bottom_dump, /* Debugging end block. */
1748 NULL, /* Debugging start insn. */
1749 NULL, /* Debugging end insn. */
1750 df_live_verify_solution_start,/* Incremental solution verify start. */
1751 df_live_verify_solution_end, /* Incremental solution verify end. */
1752 &problem_LR, /* Dependent problem. */
1753 sizeof (struct df_live_bb_info),/* Size of entry of block_info array. */
1754 TV_DF_LIVE, /* Timing variable. */
1755 false /* Reset blocks on dropping out of blocks_to_analyze. */
1759 /* Create a new DATAFLOW instance and add it to an existing instance
1760 of DF. The returned structure is what is used to get at the
1761 solution. */
1763 void
1764 df_live_add_problem (void)
1766 df_add_problem (&problem_LIVE);
1767 /* These will be initialized when df_scan_blocks processes each
1768 block. */
1769 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1773 /* Set all of the blocks as dirty. This needs to be done if this
1774 problem is added after all of the insns have been scanned. */
1776 void
1777 df_live_set_all_dirty (void)
1779 basic_block bb;
1780 FOR_ALL_BB_FN (bb, cfun)
1781 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1782 bb->index);
1786 /* Verify that all of the lr related info is consistent and
1787 correct. */
1789 void
1790 df_live_verify_transfer_functions (void)
1792 basic_block bb;
1793 bitmap_head saved_gen;
1794 bitmap_head saved_kill;
1795 bitmap_head all_blocks;
1797 if (!df)
1798 return;
1800 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1801 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1802 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1804 df_grow_insn_info ();
1806 FOR_ALL_BB_FN (bb, cfun)
1808 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1809 bitmap_set_bit (&all_blocks, bb->index);
1811 if (bb_info)
1813 /* Make a copy of the transfer functions and then compute
1814 new ones to see if the transfer functions have
1815 changed. */
1816 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1817 bb->index))
1819 bitmap_copy (&saved_gen, &bb_info->gen);
1820 bitmap_copy (&saved_kill, &bb_info->kill);
1821 bitmap_clear (&bb_info->gen);
1822 bitmap_clear (&bb_info->kill);
1824 df_live_bb_local_compute (bb->index);
1825 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1826 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1829 else
1831 /* If we do not have basic block info, the block must be in
1832 the list of dirty blocks or else some one has added a
1833 block behind our backs. */
1834 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1835 bb->index));
1837 /* Make sure no one created a block without following
1838 procedures. */
1839 gcc_assert (df_scan_get_bb_info (bb->index));
1842 /* Make sure there are no dirty bits in blocks that have been deleted. */
1843 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1844 &all_blocks));
1845 bitmap_clear (&saved_gen);
1846 bitmap_clear (&saved_kill);
1847 bitmap_clear (&all_blocks);
1850 /*----------------------------------------------------------------------------
1851 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1853 Link either the defs to the uses and / or the uses to the defs.
1855 These problems are set up like the other dataflow problems so that
1856 they nicely fit into the framework. They are much simpler and only
1857 involve a single traversal of instructions and an examination of
1858 the reaching defs information (the dependent problem).
1859 ----------------------------------------------------------------------------*/
1861 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1863 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1865 struct df_link *
1866 df_chain_create (df_ref src, df_ref dst)
1868 struct df_link *head = DF_REF_CHAIN (src);
1869 struct df_link *link = df_chain->block_pool->allocate ();
1871 DF_REF_CHAIN (src) = link;
1872 link->next = head;
1873 link->ref = dst;
1874 return link;
1878 /* Delete any du or ud chains that start at REF and point to
1879 TARGET. */
1880 static void
1881 df_chain_unlink_1 (df_ref ref, df_ref target)
1883 struct df_link *chain = DF_REF_CHAIN (ref);
1884 struct df_link *prev = NULL;
1886 while (chain)
1888 if (chain->ref == target)
1890 if (prev)
1891 prev->next = chain->next;
1892 else
1893 DF_REF_CHAIN (ref) = chain->next;
1894 df_chain->block_pool->remove (chain);
1895 return;
1897 prev = chain;
1898 chain = chain->next;
1903 /* Delete a du or ud chain that leave or point to REF. */
1905 void
1906 df_chain_unlink (df_ref ref)
1908 struct df_link *chain = DF_REF_CHAIN (ref);
1909 while (chain)
1911 struct df_link *next = chain->next;
1912 /* Delete the other side if it exists. */
1913 df_chain_unlink_1 (chain->ref, ref);
1914 df_chain->block_pool->remove (chain);
1915 chain = next;
1917 DF_REF_CHAIN (ref) = NULL;
1921 /* Copy the du or ud chain starting at FROM_REF and attach it to
1922 TO_REF. */
1924 void
1925 df_chain_copy (df_ref to_ref,
1926 struct df_link *from_ref)
1928 while (from_ref)
1930 df_chain_create (to_ref, from_ref->ref);
1931 from_ref = from_ref->next;
1936 /* Remove this problem from the stack of dataflow problems. */
1938 static void
1939 df_chain_remove_problem (void)
1941 bitmap_iterator bi;
1942 unsigned int bb_index;
1944 /* Wholesale destruction of the old chains. */
1945 if (df_chain->block_pool)
1946 delete df_chain->block_pool;
1948 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1950 rtx_insn *insn;
1951 df_ref def, use;
1952 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1954 if (df_chain_problem_p (DF_DU_CHAIN))
1955 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
1956 DF_REF_CHAIN (def) = NULL;
1957 if (df_chain_problem_p (DF_UD_CHAIN))
1958 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
1959 DF_REF_CHAIN (use) = NULL;
1961 FOR_BB_INSNS (bb, insn)
1962 if (INSN_P (insn))
1964 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
1965 if (df_chain_problem_p (DF_DU_CHAIN))
1966 FOR_EACH_INSN_INFO_DEF (def, insn_info)
1967 DF_REF_CHAIN (def) = NULL;
1968 if (df_chain_problem_p (DF_UD_CHAIN))
1970 FOR_EACH_INSN_INFO_USE (use, insn_info)
1971 DF_REF_CHAIN (use) = NULL;
1972 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
1973 DF_REF_CHAIN (use) = NULL;
1978 bitmap_clear (df_chain->out_of_date_transfer_functions);
1979 df_chain->block_pool = NULL;
1983 /* Remove the chain problem completely. */
1985 static void
1986 df_chain_fully_remove_problem (void)
1988 df_chain_remove_problem ();
1989 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
1990 free (df_chain);
1994 /* Create def-use or use-def chains. */
1996 static void
1997 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1999 df_chain_remove_problem ();
2000 df_chain->block_pool = new object_allocator<df_link> ("df_chain_block pool",
2001 50);
2002 df_chain->optional_p = true;
2006 /* Reset all of the chains when the set of basic blocks changes. */
2008 static void
2009 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2011 df_chain_remove_problem ();
2015 /* Create the chains for a list of USEs. */
2017 static void
2018 df_chain_create_bb_process_use (bitmap local_rd,
2019 df_ref use,
2020 int top_flag)
2022 bitmap_iterator bi;
2023 unsigned int def_index;
2025 for (; use; use = DF_REF_NEXT_LOC (use))
2027 unsigned int uregno = DF_REF_REGNO (use);
2028 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2029 || (uregno >= FIRST_PSEUDO_REGISTER))
2031 /* Do not want to go through this for an uninitialized var. */
2032 int count = DF_DEFS_COUNT (uregno);
2033 if (count)
2035 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2037 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2038 unsigned int last_index = first_index + count - 1;
2040 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2042 df_ref def;
2043 if (def_index > last_index)
2044 break;
2046 def = DF_DEFS_GET (def_index);
2047 if (df_chain_problem_p (DF_DU_CHAIN))
2048 df_chain_create (def, use);
2049 if (df_chain_problem_p (DF_UD_CHAIN))
2050 df_chain_create (use, def);
2059 /* Create chains from reaching defs bitmaps for basic block BB. */
2061 static void
2062 df_chain_create_bb (unsigned int bb_index)
2064 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2065 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2066 rtx_insn *insn;
2067 bitmap_head cpy;
2069 bitmap_initialize (&cpy, &bitmap_default_obstack);
2070 bitmap_copy (&cpy, &bb_info->in);
2071 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2073 /* Since we are going forwards, process the artificial uses first
2074 then the artificial defs second. */
2076 #ifdef EH_USES
2077 /* Create the chains for the artificial uses from the EH_USES at the
2078 beginning of the block. */
2080 /* Artificials are only hard regs. */
2081 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2082 df_chain_create_bb_process_use (&cpy,
2083 df_get_artificial_uses (bb->index),
2084 DF_REF_AT_TOP);
2085 #endif
2087 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2089 /* Process the regular instructions next. */
2090 FOR_BB_INSNS (bb, insn)
2091 if (INSN_P (insn))
2093 unsigned int uid = INSN_UID (insn);
2095 /* First scan the uses and link them up with the defs that remain
2096 in the cpy vector. */
2097 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2098 if (df->changeable_flags & DF_EQ_NOTES)
2099 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2101 /* Since we are going forwards, process the defs second. */
2102 df_rd_simulate_one_insn (bb, insn, &cpy);
2105 /* Create the chains for the artificial uses of the hard registers
2106 at the end of the block. */
2107 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2108 df_chain_create_bb_process_use (&cpy,
2109 df_get_artificial_uses (bb->index),
2112 bitmap_clear (&cpy);
2115 /* Create def-use chains from reaching use bitmaps for basic blocks
2116 in BLOCKS. */
2118 static void
2119 df_chain_finalize (bitmap all_blocks)
2121 unsigned int bb_index;
2122 bitmap_iterator bi;
2124 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2126 df_chain_create_bb (bb_index);
2131 /* Free all storage associated with the problem. */
2133 static void
2134 df_chain_free (void)
2136 delete df_chain->block_pool;
2137 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2138 free (df_chain);
2142 /* Debugging info. */
2144 static void
2145 df_chain_bb_dump (basic_block bb, FILE *file, bool top)
2147 /* Artificials are only hard regs. */
2148 if (df->changeable_flags & DF_NO_HARD_REGS)
2149 return;
2150 if (df_chain_problem_p (DF_UD_CHAIN))
2152 df_ref use;
2154 fprintf (file,
2155 ";; UD chains for artificial uses at %s\n",
2156 top ? "top" : "bottom");
2157 FOR_EACH_ARTIFICIAL_USE (use, bb->index)
2158 if ((top && (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2159 || (!top && !(DF_REF_FLAGS (use) & DF_REF_AT_TOP)))
2161 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2162 df_chain_dump (DF_REF_CHAIN (use), file);
2163 fprintf (file, "\n");
2166 if (df_chain_problem_p (DF_DU_CHAIN))
2168 df_ref def;
2170 fprintf (file,
2171 ";; DU chains for artificial defs at %s\n",
2172 top ? "top" : "bottom");
2173 FOR_EACH_ARTIFICIAL_DEF (def, bb->index)
2174 if ((top && (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
2175 || (!top && !(DF_REF_FLAGS (def) & DF_REF_AT_TOP)))
2177 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2178 df_chain_dump (DF_REF_CHAIN (def), file);
2179 fprintf (file, "\n");
2184 static void
2185 df_chain_top_dump (basic_block bb, FILE *file)
2187 df_chain_bb_dump (bb, file, /*top=*/true);
2190 static void
2191 df_chain_bottom_dump (basic_block bb, FILE *file)
2193 df_chain_bb_dump (bb, file, /*top=*/false);
2196 static void
2197 df_chain_insn_top_dump (const rtx_insn *insn, FILE *file)
2199 if (df_chain_problem_p (DF_UD_CHAIN) && INSN_P (insn))
2201 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2202 df_ref use;
2204 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2205 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2206 FOR_EACH_INSN_INFO_USE (use, insn_info)
2207 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2208 || !(df->changeable_flags & DF_NO_HARD_REGS))
2210 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2211 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2212 fprintf (file, "read/write ");
2213 df_chain_dump (DF_REF_CHAIN (use), file);
2214 fprintf (file, "\n");
2216 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
2217 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2218 || !(df->changeable_flags & DF_NO_HARD_REGS))
2220 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2221 df_chain_dump (DF_REF_CHAIN (use), file);
2222 fprintf (file, "\n");
2227 static void
2228 df_chain_insn_bottom_dump (const rtx_insn *insn, FILE *file)
2230 if (df_chain_problem_p (DF_DU_CHAIN) && INSN_P (insn))
2232 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2233 df_ref def;
2234 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2235 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2236 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2237 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def))
2238 || !(df->changeable_flags & DF_NO_HARD_REGS))
2240 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2241 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2242 fprintf (file, "read/write ");
2243 df_chain_dump (DF_REF_CHAIN (def), file);
2244 fprintf (file, "\n");
2246 fprintf (file, "\n");
2250 static struct df_problem problem_CHAIN =
2252 DF_CHAIN, /* Problem id. */
2253 DF_NONE, /* Direction. */
2254 df_chain_alloc, /* Allocate the problem specific data. */
2255 df_chain_reset, /* Reset global information. */
2256 NULL, /* Free basic block info. */
2257 NULL, /* Local compute function. */
2258 NULL, /* Init the solution specific data. */
2259 NULL, /* Iterative solver. */
2260 NULL, /* Confluence operator 0. */
2261 NULL, /* Confluence operator n. */
2262 NULL, /* Transfer function. */
2263 df_chain_finalize, /* Finalize function. */
2264 df_chain_free, /* Free all of the problem information. */
2265 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2266 NULL, /* Debugging. */
2267 df_chain_top_dump, /* Debugging start block. */
2268 df_chain_bottom_dump, /* Debugging end block. */
2269 df_chain_insn_top_dump, /* Debugging start insn. */
2270 df_chain_insn_bottom_dump, /* Debugging end insn. */
2271 NULL, /* Incremental solution verify start. */
2272 NULL, /* Incremental solution verify end. */
2273 &problem_RD, /* Dependent problem. */
2274 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
2275 TV_DF_CHAIN, /* Timing variable. */
2276 false /* Reset blocks on dropping out of blocks_to_analyze. */
2280 /* Create a new DATAFLOW instance and add it to an existing instance
2281 of DF. The returned structure is what is used to get at the
2282 solution. */
2284 void
2285 df_chain_add_problem (unsigned int chain_flags)
2287 df_add_problem (&problem_CHAIN);
2288 df_chain->local_flags = chain_flags;
2289 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2292 #undef df_chain_problem_p
2295 /*----------------------------------------------------------------------------
2296 WORD LEVEL LIVE REGISTERS
2298 Find the locations in the function where any use of a pseudo can
2299 reach in the backwards direction. In and out bitvectors are built
2300 for each basic block. We only track pseudo registers that have a
2301 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2302 contain two bits corresponding to each of the subwords.
2304 ----------------------------------------------------------------------------*/
2306 /* Private data used to verify the solution for this problem. */
2307 struct df_word_lr_problem_data
2309 /* An obstack for the bitmaps we need for this problem. */
2310 bitmap_obstack word_lr_bitmaps;
2314 /* Free basic block info. */
2316 static void
2317 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2318 void *vbb_info)
2320 struct df_word_lr_bb_info *bb_info = (struct df_word_lr_bb_info *) vbb_info;
2321 if (bb_info)
2323 bitmap_clear (&bb_info->use);
2324 bitmap_clear (&bb_info->def);
2325 bitmap_clear (&bb_info->in);
2326 bitmap_clear (&bb_info->out);
2331 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2332 not touched unless the block is new. */
2334 static void
2335 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2337 unsigned int bb_index;
2338 bitmap_iterator bi;
2339 basic_block bb;
2340 struct df_word_lr_problem_data *problem_data
2341 = XNEW (struct df_word_lr_problem_data);
2343 df_word_lr->problem_data = problem_data;
2345 df_grow_bb_info (df_word_lr);
2347 /* Create the mapping from regnos to slots. This does not change
2348 unless the problem is destroyed and recreated. In particular, if
2349 we end up deleting the only insn that used a subreg, we do not
2350 want to redo the mapping because this would invalidate everything
2351 else. */
2353 bitmap_obstack_initialize (&problem_data->word_lr_bitmaps);
2355 FOR_EACH_BB_FN (bb, cfun)
2356 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, bb->index);
2358 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2359 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2361 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2363 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2365 /* When bitmaps are already initialized, just clear them. */
2366 if (bb_info->use.obstack)
2368 bitmap_clear (&bb_info->def);
2369 bitmap_clear (&bb_info->use);
2371 else
2373 bitmap_initialize (&bb_info->use, &problem_data->word_lr_bitmaps);
2374 bitmap_initialize (&bb_info->def, &problem_data->word_lr_bitmaps);
2375 bitmap_initialize (&bb_info->in, &problem_data->word_lr_bitmaps);
2376 bitmap_initialize (&bb_info->out, &problem_data->word_lr_bitmaps);
2380 df_word_lr->optional_p = true;
2384 /* Reset the global solution for recalculation. */
2386 static void
2387 df_word_lr_reset (bitmap all_blocks)
2389 unsigned int bb_index;
2390 bitmap_iterator bi;
2392 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2394 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2395 gcc_assert (bb_info);
2396 bitmap_clear (&bb_info->in);
2397 bitmap_clear (&bb_info->out);
2401 /* Examine REF, and if it is for a reg we're interested in, set or
2402 clear the bits corresponding to its subwords from the bitmap
2403 according to IS_SET. LIVE is the bitmap we should update. We do
2404 not track hard regs or pseudos of any size other than 2 *
2405 UNITS_PER_WORD.
2406 We return true if we changed the bitmap, or if we encountered a register
2407 we're not tracking. */
2409 bool
2410 df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
2412 rtx orig_reg = DF_REF_REG (ref);
2413 rtx reg = orig_reg;
2414 machine_mode reg_mode;
2415 unsigned regno;
2416 /* Left at -1 for whole accesses. */
2417 int which_subword = -1;
2418 bool changed = false;
2420 if (GET_CODE (reg) == SUBREG)
2421 reg = SUBREG_REG (orig_reg);
2422 regno = REGNO (reg);
2423 reg_mode = GET_MODE (reg);
2424 if (regno < FIRST_PSEUDO_REGISTER
2425 || GET_MODE_SIZE (reg_mode) != 2 * UNITS_PER_WORD)
2426 return true;
2428 if (GET_CODE (orig_reg) == SUBREG
2429 && df_read_modify_subreg_p (orig_reg))
2431 gcc_assert (DF_REF_FLAGS_IS_SET (ref, DF_REF_PARTIAL));
2432 if (subreg_lowpart_p (orig_reg))
2433 which_subword = 0;
2434 else
2435 which_subword = 1;
2437 if (is_set)
2439 if (which_subword != 1)
2440 changed |= bitmap_set_bit (live, regno * 2);
2441 if (which_subword != 0)
2442 changed |= bitmap_set_bit (live, regno * 2 + 1);
2444 else
2446 if (which_subword != 1)
2447 changed |= bitmap_clear_bit (live, regno * 2);
2448 if (which_subword != 0)
2449 changed |= bitmap_clear_bit (live, regno * 2 + 1);
2451 return changed;
2454 /* Compute local live register info for basic block BB. */
2456 static void
2457 df_word_lr_bb_local_compute (unsigned int bb_index)
2459 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2460 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2461 rtx_insn *insn;
2462 df_ref def, use;
2464 /* Ensure that artificial refs don't contain references to pseudos. */
2465 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
2466 gcc_assert (DF_REF_REGNO (def) < FIRST_PSEUDO_REGISTER);
2468 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
2469 gcc_assert (DF_REF_REGNO (use) < FIRST_PSEUDO_REGISTER);
2471 FOR_BB_INSNS_REVERSE (bb, insn)
2473 if (!NONDEBUG_INSN_P (insn))
2474 continue;
2476 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2477 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2478 /* If the def is to only part of the reg, it does
2479 not kill the other defs that reach here. */
2480 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2482 df_word_lr_mark_ref (def, true, &bb_info->def);
2483 df_word_lr_mark_ref (def, false, &bb_info->use);
2485 FOR_EACH_INSN_INFO_USE (use, insn_info)
2486 df_word_lr_mark_ref (use, true, &bb_info->use);
2491 /* Compute local live register info for each basic block within BLOCKS. */
2493 static void
2494 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2496 unsigned int bb_index;
2497 bitmap_iterator bi;
2499 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2501 if (bb_index == EXIT_BLOCK)
2503 unsigned regno;
2504 bitmap_iterator bi;
2505 EXECUTE_IF_SET_IN_BITMAP (df->exit_block_uses, FIRST_PSEUDO_REGISTER,
2506 regno, bi)
2507 gcc_unreachable ();
2509 else
2510 df_word_lr_bb_local_compute (bb_index);
2513 bitmap_clear (df_word_lr->out_of_date_transfer_functions);
2517 /* Initialize the solution vectors. */
2519 static void
2520 df_word_lr_init (bitmap all_blocks)
2522 unsigned int bb_index;
2523 bitmap_iterator bi;
2525 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2527 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2528 bitmap_copy (&bb_info->in, &bb_info->use);
2529 bitmap_clear (&bb_info->out);
2534 /* Confluence function that ignores fake edges. */
2536 static bool
2537 df_word_lr_confluence_n (edge e)
2539 bitmap op1 = &df_word_lr_get_bb_info (e->src->index)->out;
2540 bitmap op2 = &df_word_lr_get_bb_info (e->dest->index)->in;
2542 return bitmap_ior_into (op1, op2);
2546 /* Transfer function. */
2548 static bool
2549 df_word_lr_transfer_function (int bb_index)
2551 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2552 bitmap in = &bb_info->in;
2553 bitmap out = &bb_info->out;
2554 bitmap use = &bb_info->use;
2555 bitmap def = &bb_info->def;
2557 return bitmap_ior_and_compl (in, use, out, def);
2561 /* Free all storage associated with the problem. */
2563 static void
2564 df_word_lr_free (void)
2566 struct df_word_lr_problem_data *problem_data
2567 = (struct df_word_lr_problem_data *)df_word_lr->problem_data;
2569 if (df_word_lr->block_info)
2571 df_word_lr->block_info_size = 0;
2572 free (df_word_lr->block_info);
2573 df_word_lr->block_info = NULL;
2576 BITMAP_FREE (df_word_lr->out_of_date_transfer_functions);
2577 bitmap_obstack_release (&problem_data->word_lr_bitmaps);
2578 free (problem_data);
2579 free (df_word_lr);
2583 /* Debugging info at top of bb. */
2585 static void
2586 df_word_lr_top_dump (basic_block bb, FILE *file)
2588 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2589 if (!bb_info)
2590 return;
2592 fprintf (file, ";; blr in \t");
2593 df_print_word_regset (file, &bb_info->in);
2594 fprintf (file, ";; blr use \t");
2595 df_print_word_regset (file, &bb_info->use);
2596 fprintf (file, ";; blr def \t");
2597 df_print_word_regset (file, &bb_info->def);
2601 /* Debugging info at bottom of bb. */
2603 static void
2604 df_word_lr_bottom_dump (basic_block bb, FILE *file)
2606 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2607 if (!bb_info)
2608 return;
2610 fprintf (file, ";; blr out \t");
2611 df_print_word_regset (file, &bb_info->out);
2615 /* All of the information associated with every instance of the problem. */
2617 static struct df_problem problem_WORD_LR =
2619 DF_WORD_LR, /* Problem id. */
2620 DF_BACKWARD, /* Direction. */
2621 df_word_lr_alloc, /* Allocate the problem specific data. */
2622 df_word_lr_reset, /* Reset global information. */
2623 df_word_lr_free_bb_info, /* Free basic block info. */
2624 df_word_lr_local_compute, /* Local compute function. */
2625 df_word_lr_init, /* Init the solution specific data. */
2626 df_worklist_dataflow, /* Worklist solver. */
2627 NULL, /* Confluence operator 0. */
2628 df_word_lr_confluence_n, /* Confluence operator n. */
2629 df_word_lr_transfer_function, /* Transfer function. */
2630 NULL, /* Finalize function. */
2631 df_word_lr_free, /* Free all of the problem information. */
2632 df_word_lr_free, /* Remove this problem from the stack of dataflow problems. */
2633 NULL, /* Debugging. */
2634 df_word_lr_top_dump, /* Debugging start block. */
2635 df_word_lr_bottom_dump, /* Debugging end block. */
2636 NULL, /* Debugging start insn. */
2637 NULL, /* Debugging end insn. */
2638 NULL, /* Incremental solution verify start. */
2639 NULL, /* Incremental solution verify end. */
2640 NULL, /* Dependent problem. */
2641 sizeof (struct df_word_lr_bb_info),/* Size of entry of block_info array. */
2642 TV_DF_WORD_LR, /* Timing variable. */
2643 false /* Reset blocks on dropping out of blocks_to_analyze. */
2647 /* Create a new DATAFLOW instance and add it to an existing instance
2648 of DF. The returned structure is what is used to get at the
2649 solution. */
2651 void
2652 df_word_lr_add_problem (void)
2654 df_add_problem (&problem_WORD_LR);
2655 /* These will be initialized when df_scan_blocks processes each
2656 block. */
2657 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2661 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2662 any bits, which is used by the caller to determine whether a set is
2663 necessary. We also return true if there are other reasons not to delete
2664 an insn. */
2666 bool
2667 df_word_lr_simulate_defs (rtx_insn *insn, bitmap live)
2669 bool changed = false;
2670 df_ref def;
2672 FOR_EACH_INSN_DEF (def, insn)
2673 if (DF_REF_FLAGS (def) & DF_REF_CONDITIONAL)
2674 changed = true;
2675 else
2676 changed |= df_word_lr_mark_ref (def, false, live);
2677 return changed;
2681 /* Simulate the effects of the uses of INSN on LIVE. */
2683 void
2684 df_word_lr_simulate_uses (rtx_insn *insn, bitmap live)
2686 df_ref use;
2688 FOR_EACH_INSN_USE (use, insn)
2689 df_word_lr_mark_ref (use, true, live);
2692 /*----------------------------------------------------------------------------
2693 This problem computes REG_DEAD and REG_UNUSED notes.
2694 ----------------------------------------------------------------------------*/
2696 static void
2697 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2699 df_note->optional_p = true;
2702 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2703 static void
2704 df_print_note (const char *prefix, rtx_insn *insn, rtx note)
2706 if (dump_file)
2708 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2709 print_rtl (dump_file, note);
2710 fprintf (dump_file, "\n");
2715 /* After reg-stack, the x86 floating point stack regs are difficult to
2716 analyze because of all of the pushes, pops and rotations. Thus, we
2717 just leave the notes alone. */
2719 #ifdef STACK_REGS
2720 static inline bool
2721 df_ignore_stack_reg (int regno)
2723 return regstack_completed
2724 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2726 #else
2727 static inline bool
2728 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2730 return false;
2732 #endif
2735 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
2737 static void
2738 df_remove_dead_and_unused_notes (rtx_insn *insn)
2740 rtx *pprev = &REG_NOTES (insn);
2741 rtx link = *pprev;
2743 while (link)
2745 switch (REG_NOTE_KIND (link))
2747 case REG_DEAD:
2748 /* After reg-stack, we need to ignore any unused notes
2749 for the stack registers. */
2750 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2752 pprev = &XEXP (link, 1);
2753 link = *pprev;
2755 else
2757 rtx next = XEXP (link, 1);
2758 if (REG_DEAD_DEBUGGING)
2759 df_print_note ("deleting: ", insn, link);
2760 free_EXPR_LIST_node (link);
2761 *pprev = link = next;
2763 break;
2765 case REG_UNUSED:
2766 /* After reg-stack, we need to ignore any unused notes
2767 for the stack registers. */
2768 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2770 pprev = &XEXP (link, 1);
2771 link = *pprev;
2773 else
2775 rtx next = XEXP (link, 1);
2776 if (REG_DEAD_DEBUGGING)
2777 df_print_note ("deleting: ", insn, link);
2778 free_EXPR_LIST_node (link);
2779 *pprev = link = next;
2781 break;
2783 default:
2784 pprev = &XEXP (link, 1);
2785 link = *pprev;
2786 break;
2791 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2792 as the bitmap of currently live registers. */
2794 static void
2795 df_remove_dead_eq_notes (rtx_insn *insn, bitmap live)
2797 rtx *pprev = &REG_NOTES (insn);
2798 rtx link = *pprev;
2800 while (link)
2802 switch (REG_NOTE_KIND (link))
2804 case REG_EQUAL:
2805 case REG_EQUIV:
2807 /* Remove the notes that refer to dead registers. As we have at most
2808 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2809 so we need to purge the complete EQ_USES vector when removing
2810 the note using df_notes_rescan. */
2811 df_ref use;
2812 bool deleted = false;
2814 FOR_EACH_INSN_EQ_USE (use, insn)
2815 if (DF_REF_REGNO (use) > FIRST_PSEUDO_REGISTER
2816 && DF_REF_LOC (use)
2817 && (DF_REF_FLAGS (use) & DF_REF_IN_NOTE)
2818 && !bitmap_bit_p (live, DF_REF_REGNO (use))
2819 && loc_mentioned_in_p (DF_REF_LOC (use), XEXP (link, 0)))
2821 deleted = true;
2822 break;
2824 if (deleted)
2826 rtx next;
2827 if (REG_DEAD_DEBUGGING)
2828 df_print_note ("deleting: ", insn, link);
2829 next = XEXP (link, 1);
2830 free_EXPR_LIST_node (link);
2831 *pprev = link = next;
2832 df_notes_rescan (insn);
2834 else
2836 pprev = &XEXP (link, 1);
2837 link = *pprev;
2839 break;
2842 default:
2843 pprev = &XEXP (link, 1);
2844 link = *pprev;
2845 break;
2850 /* Set a NOTE_TYPE note for REG in INSN. */
2852 static inline void
2853 df_set_note (enum reg_note note_type, rtx_insn *insn, rtx reg)
2855 gcc_checking_assert (!DEBUG_INSN_P (insn));
2856 add_reg_note (insn, note_type, reg);
2859 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2860 arguments. Return true if the register value described by MWS's
2861 mw_reg is known to be completely unused, and if mw_reg can therefore
2862 be used in a REG_UNUSED note. */
2864 static bool
2865 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2866 bitmap live, bitmap artificial_uses)
2868 unsigned int r;
2870 /* If MWS describes a partial reference, create REG_UNUSED notes for
2871 individual hard registers. */
2872 if (mws->flags & DF_REF_PARTIAL)
2873 return false;
2875 /* Likewise if some part of the register is used. */
2876 for (r = mws->start_regno; r <= mws->end_regno; r++)
2877 if (bitmap_bit_p (live, r)
2878 || bitmap_bit_p (artificial_uses, r))
2879 return false;
2881 gcc_assert (REG_P (mws->mw_reg));
2882 return true;
2886 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2887 based on the bits in LIVE. Do not generate notes for registers in
2888 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2889 not generated if the reg is both read and written by the
2890 instruction.
2893 static void
2894 df_set_unused_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
2895 bitmap live, bitmap do_not_gen,
2896 bitmap artificial_uses,
2897 struct dead_debug_local *debug)
2899 unsigned int r;
2901 if (REG_DEAD_DEBUGGING && dump_file)
2902 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2903 mws->start_regno, mws->end_regno);
2905 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2907 unsigned int regno = mws->start_regno;
2908 df_set_note (REG_UNUSED, insn, mws->mw_reg);
2909 dead_debug_insert_temp (debug, regno, insn, DEBUG_TEMP_AFTER_WITH_REG);
2911 if (REG_DEAD_DEBUGGING)
2912 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2914 bitmap_set_bit (do_not_gen, regno);
2915 /* Only do this if the value is totally dead. */
2917 else
2918 for (r = mws->start_regno; r <= mws->end_regno; r++)
2920 if (!bitmap_bit_p (live, r)
2921 && !bitmap_bit_p (artificial_uses, r))
2923 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
2924 dead_debug_insert_temp (debug, r, insn, DEBUG_TEMP_AFTER_WITH_REG);
2925 if (REG_DEAD_DEBUGGING)
2926 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2928 bitmap_set_bit (do_not_gen, r);
2933 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2934 arguments. Return true if the register value described by MWS's
2935 mw_reg is known to be completely dead, and if mw_reg can therefore
2936 be used in a REG_DEAD note. */
2938 static bool
2939 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2940 bitmap live, bitmap artificial_uses,
2941 bitmap do_not_gen)
2943 unsigned int r;
2945 /* If MWS describes a partial reference, create REG_DEAD notes for
2946 individual hard registers. */
2947 if (mws->flags & DF_REF_PARTIAL)
2948 return false;
2950 /* Likewise if some part of the register is not dead. */
2951 for (r = mws->start_regno; r <= mws->end_regno; r++)
2952 if (bitmap_bit_p (live, r)
2953 || bitmap_bit_p (artificial_uses, r)
2954 || bitmap_bit_p (do_not_gen, r))
2955 return false;
2957 gcc_assert (REG_P (mws->mw_reg));
2958 return true;
2961 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2962 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2963 from being set if the instruction both reads and writes the
2964 register. */
2966 static void
2967 df_set_dead_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
2968 bitmap live, bitmap do_not_gen,
2969 bitmap artificial_uses, bool *added_notes_p)
2971 unsigned int r;
2972 bool is_debug = *added_notes_p;
2974 *added_notes_p = false;
2976 if (REG_DEAD_DEBUGGING && dump_file)
2978 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2979 mws->start_regno, mws->end_regno);
2980 df_print_regset (dump_file, do_not_gen);
2981 fprintf (dump_file, " live =");
2982 df_print_regset (dump_file, live);
2983 fprintf (dump_file, " artificial uses =");
2984 df_print_regset (dump_file, artificial_uses);
2987 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2989 if (is_debug)
2991 *added_notes_p = true;
2992 return;
2994 /* Add a dead note for the entire multi word register. */
2995 df_set_note (REG_DEAD, insn, mws->mw_reg);
2996 if (REG_DEAD_DEBUGGING)
2997 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2999 else
3001 for (r = mws->start_regno; r <= mws->end_regno; r++)
3002 if (!bitmap_bit_p (live, r)
3003 && !bitmap_bit_p (artificial_uses, r)
3004 && !bitmap_bit_p (do_not_gen, r))
3006 if (is_debug)
3008 *added_notes_p = true;
3009 return;
3011 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
3012 if (REG_DEAD_DEBUGGING)
3013 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3016 return;
3020 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3021 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3023 static void
3024 df_create_unused_note (rtx_insn *insn, df_ref def,
3025 bitmap live, bitmap artificial_uses,
3026 struct dead_debug_local *debug)
3028 unsigned int dregno = DF_REF_REGNO (def);
3030 if (REG_DEAD_DEBUGGING && dump_file)
3032 fprintf (dump_file, " regular looking at def ");
3033 df_ref_debug (def, dump_file);
3036 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3037 || bitmap_bit_p (live, dregno)
3038 || bitmap_bit_p (artificial_uses, dregno)
3039 || df_ignore_stack_reg (dregno)))
3041 rtx reg = (DF_REF_LOC (def))
3042 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3043 df_set_note (REG_UNUSED, insn, reg);
3044 dead_debug_insert_temp (debug, dregno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3045 if (REG_DEAD_DEBUGGING)
3046 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3049 return;
3053 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3054 info: lifetime, bb, and number of defs and uses for basic block
3055 BB. The three bitvectors are scratch regs used here. */
3057 static void
3058 df_note_bb_compute (unsigned int bb_index,
3059 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3061 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
3062 rtx_insn *insn;
3063 df_ref def, use;
3064 struct dead_debug_local debug;
3066 dead_debug_local_init (&debug, NULL, NULL);
3068 bitmap_copy (live, df_get_live_out (bb));
3069 bitmap_clear (artificial_uses);
3071 if (REG_DEAD_DEBUGGING && dump_file)
3073 fprintf (dump_file, "live at bottom ");
3074 df_print_regset (dump_file, live);
3077 /* Process the artificial defs and uses at the bottom of the block
3078 to begin processing. */
3079 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3081 if (REG_DEAD_DEBUGGING && dump_file)
3082 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3084 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3085 bitmap_clear_bit (live, DF_REF_REGNO (def));
3088 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3089 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3091 unsigned int regno = DF_REF_REGNO (use);
3092 bitmap_set_bit (live, regno);
3094 /* Notes are not generated for any of the artificial registers
3095 at the bottom of the block. */
3096 bitmap_set_bit (artificial_uses, regno);
3099 if (REG_DEAD_DEBUGGING && dump_file)
3101 fprintf (dump_file, "live before artificials out ");
3102 df_print_regset (dump_file, live);
3105 FOR_BB_INSNS_REVERSE (bb, insn)
3107 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3108 df_mw_hardreg *mw;
3109 int debug_insn;
3111 if (!INSN_P (insn))
3112 continue;
3114 debug_insn = DEBUG_INSN_P (insn);
3116 bitmap_clear (do_not_gen);
3117 df_remove_dead_and_unused_notes (insn);
3119 /* Process the defs. */
3120 if (CALL_P (insn))
3122 if (REG_DEAD_DEBUGGING && dump_file)
3124 fprintf (dump_file, "processing call %d\n live =",
3125 INSN_UID (insn));
3126 df_print_regset (dump_file, live);
3129 /* We only care about real sets for calls. Clobbers cannot
3130 be depended on to really die. */
3131 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3132 if ((DF_MWS_REG_DEF_P (mw))
3133 && !df_ignore_stack_reg (mw->start_regno))
3134 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3135 artificial_uses, &debug);
3137 /* All of the defs except the return value are some sort of
3138 clobber. This code is for the return. */
3139 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3141 unsigned int dregno = DF_REF_REGNO (def);
3142 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3144 df_create_unused_note (insn,
3145 def, live, artificial_uses, &debug);
3146 bitmap_set_bit (do_not_gen, dregno);
3149 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3150 bitmap_clear_bit (live, dregno);
3153 else
3155 /* Regular insn. */
3156 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3157 if (DF_MWS_REG_DEF_P (mw))
3158 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3159 artificial_uses, &debug);
3161 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3163 unsigned int dregno = DF_REF_REGNO (def);
3164 df_create_unused_note (insn,
3165 def, live, artificial_uses, &debug);
3167 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3168 bitmap_set_bit (do_not_gen, dregno);
3170 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3171 bitmap_clear_bit (live, dregno);
3175 /* Process the uses. */
3176 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3177 if (DF_MWS_REG_USE_P (mw)
3178 && !df_ignore_stack_reg (mw->start_regno))
3180 bool really_add_notes = debug_insn != 0;
3182 df_set_dead_notes_for_mw (insn, mw, live, do_not_gen,
3183 artificial_uses,
3184 &really_add_notes);
3186 if (really_add_notes)
3187 debug_insn = -1;
3190 FOR_EACH_INSN_INFO_USE (use, insn_info)
3192 unsigned int uregno = DF_REF_REGNO (use);
3194 if (REG_DEAD_DEBUGGING && dump_file && !debug_insn)
3196 fprintf (dump_file, " regular looking at use ");
3197 df_ref_debug (use, dump_file);
3200 if (!bitmap_bit_p (live, uregno))
3202 if (debug_insn)
3204 if (debug_insn > 0)
3206 /* We won't add REG_UNUSED or REG_DEAD notes for
3207 these, so we don't have to mess with them in
3208 debug insns either. */
3209 if (!bitmap_bit_p (artificial_uses, uregno)
3210 && !df_ignore_stack_reg (uregno))
3211 dead_debug_add (&debug, use, uregno);
3212 continue;
3214 break;
3216 else
3217 dead_debug_insert_temp (&debug, uregno, insn,
3218 DEBUG_TEMP_BEFORE_WITH_REG);
3220 if ( (!(DF_REF_FLAGS (use)
3221 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3222 && (!bitmap_bit_p (do_not_gen, uregno))
3223 && (!bitmap_bit_p (artificial_uses, uregno))
3224 && (!df_ignore_stack_reg (uregno)))
3226 rtx reg = (DF_REF_LOC (use))
3227 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3228 df_set_note (REG_DEAD, insn, reg);
3230 if (REG_DEAD_DEBUGGING)
3231 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3233 /* This register is now live. */
3234 bitmap_set_bit (live, uregno);
3238 df_remove_dead_eq_notes (insn, live);
3240 if (debug_insn == -1)
3242 /* ??? We could probably do better here, replacing dead
3243 registers with their definitions. */
3244 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3245 df_insn_rescan_debug_internal (insn);
3249 dead_debug_local_finish (&debug, NULL);
3253 /* Compute register info: lifetime, bb, and number of defs and uses. */
3254 static void
3255 df_note_compute (bitmap all_blocks)
3257 unsigned int bb_index;
3258 bitmap_iterator bi;
3259 bitmap_head live, do_not_gen, artificial_uses;
3261 bitmap_initialize (&live, &df_bitmap_obstack);
3262 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3263 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3265 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3267 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3268 pseudos in debug insns because we don't always (re)visit blocks
3269 with death points after visiting dead uses. Even changing this
3270 loop to postorder would still leave room for visiting a death
3271 point before visiting a subsequent debug use. */
3272 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3275 bitmap_clear (&live);
3276 bitmap_clear (&do_not_gen);
3277 bitmap_clear (&artificial_uses);
3281 /* Free all storage associated with the problem. */
3283 static void
3284 df_note_free (void)
3286 free (df_note);
3290 /* All of the information associated every instance of the problem. */
3292 static struct df_problem problem_NOTE =
3294 DF_NOTE, /* Problem id. */
3295 DF_NONE, /* Direction. */
3296 df_note_alloc, /* Allocate the problem specific data. */
3297 NULL, /* Reset global information. */
3298 NULL, /* Free basic block info. */
3299 df_note_compute, /* Local compute function. */
3300 NULL, /* Init the solution specific data. */
3301 NULL, /* Iterative solver. */
3302 NULL, /* Confluence operator 0. */
3303 NULL, /* Confluence operator n. */
3304 NULL, /* Transfer function. */
3305 NULL, /* Finalize function. */
3306 df_note_free, /* Free all of the problem information. */
3307 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3308 NULL, /* Debugging. */
3309 NULL, /* Debugging start block. */
3310 NULL, /* Debugging end block. */
3311 NULL, /* Debugging start insn. */
3312 NULL, /* Debugging end insn. */
3313 NULL, /* Incremental solution verify start. */
3314 NULL, /* Incremental solution verify end. */
3315 &problem_LR, /* Dependent problem. */
3316 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
3317 TV_DF_NOTE, /* Timing variable. */
3318 false /* Reset blocks on dropping out of blocks_to_analyze. */
3322 /* Create a new DATAFLOW instance and add it to an existing instance
3323 of DF. The returned structure is what is used to get at the
3324 solution. */
3326 void
3327 df_note_add_problem (void)
3329 df_add_problem (&problem_NOTE);
3335 /*----------------------------------------------------------------------------
3336 Functions for simulating the effects of single insns.
3338 You can either simulate in the forwards direction, starting from
3339 the top of a block or the backwards direction from the end of the
3340 block. If you go backwards, defs are examined first to clear bits,
3341 then uses are examined to set bits. If you go forwards, defs are
3342 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3343 are examined to clear bits. In either case, the result of examining
3344 a def can be undone (respectively by a use or a REG_UNUSED note).
3346 If you start at the top of the block, use one of DF_LIVE_IN or
3347 DF_LR_IN. If you start at the bottom of the block use one of
3348 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3349 THEY WILL BE DESTROYED.
3350 ----------------------------------------------------------------------------*/
3353 /* Find the set of DEFs for INSN. */
3355 void
3356 df_simulate_find_defs (rtx_insn *insn, bitmap defs)
3358 df_ref def;
3360 FOR_EACH_INSN_DEF (def, insn)
3361 bitmap_set_bit (defs, DF_REF_REGNO (def));
3364 /* Find the set of uses for INSN. This includes partial defs. */
3366 static void
3367 df_simulate_find_uses (rtx_insn *insn, bitmap uses)
3369 df_ref def, use;
3370 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3372 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3373 if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3374 bitmap_set_bit (uses, DF_REF_REGNO (def));
3375 FOR_EACH_INSN_INFO_USE (use, insn_info)
3376 bitmap_set_bit (uses, DF_REF_REGNO (use));
3379 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3381 void
3382 df_simulate_find_noclobber_defs (rtx_insn *insn, bitmap defs)
3384 df_ref def;
3386 FOR_EACH_INSN_DEF (def, insn)
3387 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3388 bitmap_set_bit (defs, DF_REF_REGNO (def));
3392 /* Simulate the effects of the defs of INSN on LIVE. */
3394 void
3395 df_simulate_defs (rtx_insn *insn, bitmap live)
3397 df_ref def;
3399 FOR_EACH_INSN_DEF (def, insn)
3401 unsigned int dregno = DF_REF_REGNO (def);
3403 /* If the def is to only part of the reg, it does
3404 not kill the other defs that reach here. */
3405 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3406 bitmap_clear_bit (live, dregno);
3411 /* Simulate the effects of the uses of INSN on LIVE. */
3413 void
3414 df_simulate_uses (rtx_insn *insn, bitmap live)
3416 df_ref use;
3418 if (DEBUG_INSN_P (insn))
3419 return;
3421 FOR_EACH_INSN_USE (use, insn)
3422 /* Add use to set of uses in this BB. */
3423 bitmap_set_bit (live, DF_REF_REGNO (use));
3427 /* Add back the always live regs in BB to LIVE. */
3429 static inline void
3430 df_simulate_fixup_sets (basic_block bb, bitmap live)
3432 /* These regs are considered always live so if they end up dying
3433 because of some def, we need to bring the back again. */
3434 if (bb_has_eh_pred (bb))
3435 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3436 else
3437 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3441 /*----------------------------------------------------------------------------
3442 The following three functions are used only for BACKWARDS scanning:
3443 i.e. they process the defs before the uses.
3445 df_simulate_initialize_backwards should be called first with a
3446 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3447 df_simulate_one_insn_backwards should be called for each insn in
3448 the block, starting with the last one. Finally,
3449 df_simulate_finalize_backwards can be called to get a new value
3450 of the sets at the top of the block (this is rarely used).
3451 ----------------------------------------------------------------------------*/
3453 /* Apply the artificial uses and defs at the end of BB in a backwards
3454 direction. */
3456 void
3457 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3459 df_ref def, use;
3460 int bb_index = bb->index;
3462 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3463 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3464 bitmap_clear_bit (live, DF_REF_REGNO (def));
3466 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3467 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3468 bitmap_set_bit (live, DF_REF_REGNO (use));
3472 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3474 void
3475 df_simulate_one_insn_backwards (basic_block bb, rtx_insn *insn, bitmap live)
3477 if (!NONDEBUG_INSN_P (insn))
3478 return;
3480 df_simulate_defs (insn, live);
3481 df_simulate_uses (insn, live);
3482 df_simulate_fixup_sets (bb, live);
3486 /* Apply the artificial uses and defs at the top of BB in a backwards
3487 direction. */
3489 void
3490 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3492 df_ref def;
3493 #ifdef EH_USES
3494 df_ref use;
3495 #endif
3496 int bb_index = bb->index;
3498 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3499 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3500 bitmap_clear_bit (live, DF_REF_REGNO (def));
3502 #ifdef EH_USES
3503 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3504 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3505 bitmap_set_bit (live, DF_REF_REGNO (use));
3506 #endif
3508 /*----------------------------------------------------------------------------
3509 The following three functions are used only for FORWARDS scanning:
3510 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3511 Thus it is important to add the DF_NOTES problem to the stack of
3512 problems computed before using these functions.
3514 df_simulate_initialize_forwards should be called first with a
3515 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3516 df_simulate_one_insn_forwards should be called for each insn in
3517 the block, starting with the first one.
3518 ----------------------------------------------------------------------------*/
3520 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3521 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3522 defs live. */
3524 void
3525 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3527 df_ref def;
3528 int bb_index = bb->index;
3530 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3531 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3532 bitmap_set_bit (live, DF_REF_REGNO (def));
3535 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3537 void
3538 df_simulate_one_insn_forwards (basic_block bb, rtx_insn *insn, bitmap live)
3540 rtx link;
3541 if (! INSN_P (insn))
3542 return;
3544 /* Make sure that DF_NOTE really is an active df problem. */
3545 gcc_assert (df_note);
3547 /* Note that this is the opposite as how the problem is defined, because
3548 in the LR problem defs _kill_ liveness. However, they do so backwards,
3549 while here the scan is performed forwards! So, first assume that the
3550 def is live, and if this is not true REG_UNUSED notes will rectify the
3551 situation. */
3552 df_simulate_find_noclobber_defs (insn, live);
3554 /* Clear all of the registers that go dead. */
3555 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3557 switch (REG_NOTE_KIND (link))
3559 case REG_DEAD:
3560 case REG_UNUSED:
3562 rtx reg = XEXP (link, 0);
3563 bitmap_clear_range (live, REGNO (reg), REG_NREGS (reg));
3565 break;
3566 default:
3567 break;
3570 df_simulate_fixup_sets (bb, live);
3573 /* Used by the next two functions to encode information about the
3574 memory references we found. */
3575 #define MEMREF_NORMAL 1
3576 #define MEMREF_VOLATILE 2
3578 /* Return an OR of MEMREF_NORMAL or MEMREF_VOLATILE for the MEMs in X. */
3580 static int
3581 find_memory (rtx_insn *insn)
3583 int flags = 0;
3584 subrtx_iterator::array_type array;
3585 FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
3587 const_rtx x = *iter;
3588 if (GET_CODE (x) == ASM_OPERANDS && MEM_VOLATILE_P (x))
3589 flags |= MEMREF_VOLATILE;
3590 else if (MEM_P (x))
3592 if (MEM_VOLATILE_P (x))
3593 flags |= MEMREF_VOLATILE;
3594 else if (!MEM_READONLY_P (x))
3595 flags |= MEMREF_NORMAL;
3598 return flags;
3601 /* A subroutine of can_move_insns_across_p called through note_stores.
3602 DATA points to an integer in which we set either the bit for
3603 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3604 of either kind. */
3606 static void
3607 find_memory_stores (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
3608 void *data ATTRIBUTE_UNUSED)
3610 int *pflags = (int *)data;
3611 if (GET_CODE (x) == SUBREG)
3612 x = XEXP (x, 0);
3613 /* Treat stores to SP as stores to memory, this will prevent problems
3614 when there are references to the stack frame. */
3615 if (x == stack_pointer_rtx)
3616 *pflags |= MEMREF_VOLATILE;
3617 if (!MEM_P (x))
3618 return;
3619 *pflags |= MEM_VOLATILE_P (x) ? MEMREF_VOLATILE : MEMREF_NORMAL;
3622 /* Scan BB backwards, using df_simulate functions to keep track of
3623 lifetimes, up to insn POINT. The result is stored in LIVE. */
3625 void
3626 simulate_backwards_to_point (basic_block bb, regset live, rtx point)
3628 rtx_insn *insn;
3629 bitmap_copy (live, df_get_live_out (bb));
3630 df_simulate_initialize_backwards (bb, live);
3632 /* Scan and update life information until we reach the point we're
3633 interested in. */
3634 for (insn = BB_END (bb); insn != point; insn = PREV_INSN (insn))
3635 df_simulate_one_insn_backwards (bb, insn, live);
3638 /* Return true if it is safe to move a group of insns, described by
3639 the range FROM to TO, backwards across another group of insns,
3640 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3641 are no insns between ACROSS_TO and FROM, but they may be in
3642 different basic blocks; MERGE_BB is the block from which the
3643 insns will be moved. The caller must pass in a regset MERGE_LIVE
3644 which specifies the registers live after TO.
3646 This function may be called in one of two cases: either we try to
3647 move identical instructions from all successor blocks into their
3648 predecessor, or we try to move from only one successor block. If
3649 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3650 the second case. It should contain a set of registers live at the
3651 end of ACROSS_TO which must not be clobbered by moving the insns.
3652 In that case, we're also more careful about moving memory references
3653 and trapping insns.
3655 We return false if it is not safe to move the entire group, but it
3656 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3657 is set to point at the last moveable insn in such a case. */
3659 bool
3660 can_move_insns_across (rtx_insn *from, rtx_insn *to,
3661 rtx_insn *across_from, rtx_insn *across_to,
3662 basic_block merge_bb, regset merge_live,
3663 regset other_branch_live, rtx_insn **pmove_upto)
3665 rtx_insn *insn, *next, *max_to;
3666 bitmap merge_set, merge_use, local_merge_live;
3667 bitmap test_set, test_use;
3668 unsigned i, fail = 0;
3669 bitmap_iterator bi;
3670 int memrefs_in_across = 0;
3671 int mem_sets_in_across = 0;
3672 bool trapping_insns_in_across = false;
3674 if (pmove_upto != NULL)
3675 *pmove_upto = NULL;
3677 /* Find real bounds, ignoring debug insns. */
3678 while (!NONDEBUG_INSN_P (from) && from != to)
3679 from = NEXT_INSN (from);
3680 while (!NONDEBUG_INSN_P (to) && from != to)
3681 to = PREV_INSN (to);
3683 for (insn = across_to; ; insn = next)
3685 if (CALL_P (insn))
3687 if (RTL_CONST_OR_PURE_CALL_P (insn))
3688 /* Pure functions can read from memory. Const functions can
3689 read from arguments that the ABI has forced onto the stack.
3690 Neither sort of read can be volatile. */
3691 memrefs_in_across |= MEMREF_NORMAL;
3692 else
3694 memrefs_in_across |= MEMREF_VOLATILE;
3695 mem_sets_in_across |= MEMREF_VOLATILE;
3698 if (NONDEBUG_INSN_P (insn))
3700 if (volatile_insn_p (PATTERN (insn)))
3701 return false;
3702 memrefs_in_across |= find_memory (insn);
3703 note_stores (PATTERN (insn), find_memory_stores,
3704 &mem_sets_in_across);
3705 /* This is used just to find sets of the stack pointer. */
3706 memrefs_in_across |= mem_sets_in_across;
3707 trapping_insns_in_across |= may_trap_p (PATTERN (insn));
3709 next = PREV_INSN (insn);
3710 if (insn == across_from)
3711 break;
3714 /* Collect:
3715 MERGE_SET = set of registers set in MERGE_BB
3716 MERGE_USE = set of registers used in MERGE_BB and live at its top
3717 MERGE_LIVE = set of registers live at the point inside the MERGE
3718 range that we've reached during scanning
3719 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3720 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3721 and live before ACROSS_FROM. */
3723 merge_set = BITMAP_ALLOC (&reg_obstack);
3724 merge_use = BITMAP_ALLOC (&reg_obstack);
3725 local_merge_live = BITMAP_ALLOC (&reg_obstack);
3726 test_set = BITMAP_ALLOC (&reg_obstack);
3727 test_use = BITMAP_ALLOC (&reg_obstack);
3729 /* Compute the set of registers set and used in the ACROSS range. */
3730 if (other_branch_live != NULL)
3731 bitmap_copy (test_use, other_branch_live);
3732 df_simulate_initialize_backwards (merge_bb, test_use);
3733 for (insn = across_to; ; insn = next)
3735 if (NONDEBUG_INSN_P (insn))
3737 df_simulate_find_defs (insn, test_set);
3738 df_simulate_defs (insn, test_use);
3739 df_simulate_uses (insn, test_use);
3741 next = PREV_INSN (insn);
3742 if (insn == across_from)
3743 break;
3746 /* Compute an upper bound for the amount of insns moved, by finding
3747 the first insn in MERGE that sets a register in TEST_USE, or uses
3748 a register in TEST_SET. We also check for calls, trapping operations,
3749 and memory references. */
3750 max_to = NULL;
3751 for (insn = from; ; insn = next)
3753 if (CALL_P (insn))
3754 break;
3755 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
3756 break;
3757 if (NONDEBUG_INSN_P (insn))
3759 if (may_trap_or_fault_p (PATTERN (insn))
3760 && (trapping_insns_in_across
3761 || other_branch_live != NULL
3762 || volatile_insn_p (PATTERN (insn))))
3763 break;
3765 /* We cannot move memory stores past each other, or move memory
3766 reads past stores, at least not without tracking them and
3767 calling true_dependence on every pair.
3769 If there is no other branch and no memory references or
3770 sets in the ACROSS range, we can move memory references
3771 freely, even volatile ones.
3773 Otherwise, the rules are as follows: volatile memory
3774 references and stores can't be moved at all, and any type
3775 of memory reference can't be moved if there are volatile
3776 accesses or stores in the ACROSS range. That leaves
3777 normal reads, which can be moved, as the trapping case is
3778 dealt with elsewhere. */
3779 if (other_branch_live != NULL || memrefs_in_across != 0)
3781 int mem_ref_flags = 0;
3782 int mem_set_flags = 0;
3783 note_stores (PATTERN (insn), find_memory_stores, &mem_set_flags);
3784 mem_ref_flags = find_memory (insn);
3785 /* Catch sets of the stack pointer. */
3786 mem_ref_flags |= mem_set_flags;
3788 if ((mem_ref_flags | mem_set_flags) & MEMREF_VOLATILE)
3789 break;
3790 if ((memrefs_in_across & MEMREF_VOLATILE) && mem_ref_flags != 0)
3791 break;
3792 if (mem_set_flags != 0
3793 || (mem_sets_in_across != 0 && mem_ref_flags != 0))
3794 break;
3796 df_simulate_find_uses (insn, merge_use);
3797 /* We're only interested in uses which use a value live at
3798 the top, not one previously set in this block. */
3799 bitmap_and_compl_into (merge_use, merge_set);
3800 df_simulate_find_defs (insn, merge_set);
3801 if (bitmap_intersect_p (merge_set, test_use)
3802 || bitmap_intersect_p (merge_use, test_set))
3803 break;
3804 if (!HAVE_cc0 || !sets_cc0_p (insn))
3805 max_to = insn;
3807 next = NEXT_INSN (insn);
3808 if (insn == to)
3809 break;
3811 if (max_to != to)
3812 fail = 1;
3814 if (max_to == NULL_RTX || (fail && pmove_upto == NULL))
3815 goto out;
3817 /* Now, lower this upper bound by also taking into account that
3818 a range of insns moved across ACROSS must not leave a register
3819 live at the end that will be clobbered in ACROSS. We need to
3820 find a point where TEST_SET & LIVE == 0.
3822 Insns in the MERGE range that set registers which are also set
3823 in the ACROSS range may still be moved as long as we also move
3824 later insns which use the results of the set, and make the
3825 register dead again. This is verified by the condition stated
3826 above. We only need to test it for registers that are set in
3827 the moved region.
3829 MERGE_LIVE is provided by the caller and holds live registers after
3830 TO. */
3831 bitmap_copy (local_merge_live, merge_live);
3832 for (insn = to; insn != max_to; insn = PREV_INSN (insn))
3833 df_simulate_one_insn_backwards (merge_bb, insn, local_merge_live);
3835 /* We're not interested in registers that aren't set in the moved
3836 region at all. */
3837 bitmap_and_into (local_merge_live, merge_set);
3838 for (;;)
3840 if (NONDEBUG_INSN_P (insn))
3842 if (!bitmap_intersect_p (test_set, local_merge_live)
3843 && (!HAVE_cc0 || !sets_cc0_p (insn)))
3845 max_to = insn;
3846 break;
3849 df_simulate_one_insn_backwards (merge_bb, insn,
3850 local_merge_live);
3852 if (insn == from)
3854 fail = 1;
3855 goto out;
3857 insn = PREV_INSN (insn);
3860 if (max_to != to)
3861 fail = 1;
3863 if (pmove_upto)
3864 *pmove_upto = max_to;
3866 /* For small register class machines, don't lengthen lifetimes of
3867 hard registers before reload. */
3868 if (! reload_completed
3869 && targetm.small_register_classes_for_mode_p (VOIDmode))
3871 EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
3873 if (i < FIRST_PSEUDO_REGISTER
3874 && ! fixed_regs[i]
3875 && ! global_regs[i])
3877 fail = 1;
3878 break;
3883 out:
3884 BITMAP_FREE (merge_set);
3885 BITMAP_FREE (merge_use);
3886 BITMAP_FREE (local_merge_live);
3887 BITMAP_FREE (test_set);
3888 BITMAP_FREE (test_use);
3890 return !fail;
3894 /*----------------------------------------------------------------------------
3895 MULTIPLE DEFINITIONS
3897 Find the locations in the function reached by multiple definition sites
3898 for a live pseudo. In and out bitvectors are built for each basic
3899 block. They are restricted for efficiency to live registers.
3901 The gen and kill sets for the problem are obvious. Together they
3902 include all defined registers in a basic block; the gen set includes
3903 registers where a partial or conditional or may-clobber definition is
3904 last in the BB, while the kill set includes registers with a complete
3905 definition coming last. However, the computation of the dataflow
3906 itself is interesting.
3908 The idea behind it comes from SSA form's iterated dominance frontier
3909 criterion for inserting PHI functions. Just like in that case, we can use
3910 the dominance frontier to find places where multiple definitions meet;
3911 a register X defined in a basic block BB1 has multiple definitions in
3912 basic blocks in BB1's dominance frontier.
3914 So, the in-set of a basic block BB2 is not just the union of the
3915 out-sets of BB2's predecessors, but includes some more bits that come
3916 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3917 the previous paragraph). I called this set the init-set of BB2.
3919 (Note: I actually use the kill-set only to build the init-set.
3920 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3922 For example, if you have
3924 BB1 : r10 = 0
3925 r11 = 0
3926 if <...> goto BB2 else goto BB3;
3928 BB2 : r10 = 1
3929 r12 = 1
3930 goto BB3;
3932 BB3 :
3934 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3935 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3936 not need to iterate the dominance frontier, because we do not insert
3937 anything like PHI functions there! Instead, dataflow will take care of
3938 propagating the information to BB3's successors.
3939 ---------------------------------------------------------------------------*/
3941 /* Private data used to verify the solution for this problem. */
3942 struct df_md_problem_data
3944 /* An obstack for the bitmaps we need for this problem. */
3945 bitmap_obstack md_bitmaps;
3948 /* Scratch var used by transfer functions. This is used to do md analysis
3949 only for live registers. */
3950 static bitmap_head df_md_scratch;
3953 static void
3954 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3955 void *vbb_info)
3957 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
3958 if (bb_info)
3960 bitmap_clear (&bb_info->kill);
3961 bitmap_clear (&bb_info->gen);
3962 bitmap_clear (&bb_info->init);
3963 bitmap_clear (&bb_info->in);
3964 bitmap_clear (&bb_info->out);
3969 /* Allocate or reset bitmaps for DF_MD. The solution bits are
3970 not touched unless the block is new. */
3972 static void
3973 df_md_alloc (bitmap all_blocks)
3975 unsigned int bb_index;
3976 bitmap_iterator bi;
3977 struct df_md_problem_data *problem_data;
3979 df_grow_bb_info (df_md);
3980 if (df_md->problem_data)
3981 problem_data = (struct df_md_problem_data *) df_md->problem_data;
3982 else
3984 problem_data = XNEW (struct df_md_problem_data);
3985 df_md->problem_data = problem_data;
3986 bitmap_obstack_initialize (&problem_data->md_bitmaps);
3988 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
3990 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3992 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
3993 /* When bitmaps are already initialized, just clear them. */
3994 if (bb_info->init.obstack)
3996 bitmap_clear (&bb_info->init);
3997 bitmap_clear (&bb_info->gen);
3998 bitmap_clear (&bb_info->kill);
3999 bitmap_clear (&bb_info->in);
4000 bitmap_clear (&bb_info->out);
4002 else
4004 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4005 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4006 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4007 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4008 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
4012 df_md->optional_p = true;
4015 /* Add the effect of the top artificial defs of BB to the multiple definitions
4016 bitmap LOCAL_MD. */
4018 void
4019 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4021 int bb_index = bb->index;
4022 df_ref def;
4023 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
4024 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4026 unsigned int dregno = DF_REF_REGNO (def);
4027 if (DF_REF_FLAGS (def)
4028 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4029 bitmap_set_bit (local_md, dregno);
4030 else
4031 bitmap_clear_bit (local_md, dregno);
4036 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4037 LOCAL_MD. */
4039 void
4040 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
4041 bitmap local_md)
4043 df_ref def;
4045 FOR_EACH_INSN_DEF (def, insn)
4047 unsigned int dregno = DF_REF_REGNO (def);
4048 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4049 || (dregno >= FIRST_PSEUDO_REGISTER))
4051 if (DF_REF_FLAGS (def)
4052 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4053 bitmap_set_bit (local_md, DF_REF_ID (def));
4054 else
4055 bitmap_clear_bit (local_md, DF_REF_ID (def));
4060 static void
4061 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
4062 df_ref def,
4063 int top_flag)
4065 bitmap_clear (&seen_in_insn);
4067 for (; def; def = DF_REF_NEXT_LOC (def))
4069 unsigned int dregno = DF_REF_REGNO (def);
4070 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4071 || (dregno >= FIRST_PSEUDO_REGISTER))
4072 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4074 if (!bitmap_bit_p (&seen_in_insn, dregno))
4076 if (DF_REF_FLAGS (def)
4077 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4079 bitmap_set_bit (&bb_info->gen, dregno);
4080 bitmap_clear_bit (&bb_info->kill, dregno);
4082 else
4084 /* When we find a clobber and a regular def,
4085 make sure the regular def wins. */
4086 bitmap_set_bit (&seen_in_insn, dregno);
4087 bitmap_set_bit (&bb_info->kill, dregno);
4088 bitmap_clear_bit (&bb_info->gen, dregno);
4096 /* Compute local multiple def info for basic block BB. */
4098 static void
4099 df_md_bb_local_compute (unsigned int bb_index)
4101 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4102 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4103 rtx_insn *insn;
4105 /* Artificials are only hard regs. */
4106 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4107 df_md_bb_local_compute_process_def (bb_info,
4108 df_get_artificial_defs (bb_index),
4109 DF_REF_AT_TOP);
4111 FOR_BB_INSNS (bb, insn)
4113 unsigned int uid = INSN_UID (insn);
4114 if (!INSN_P (insn))
4115 continue;
4117 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4120 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4121 df_md_bb_local_compute_process_def (bb_info,
4122 df_get_artificial_defs (bb_index),
4126 /* Compute local reaching def info for each basic block within BLOCKS. */
4128 static void
4129 df_md_local_compute (bitmap all_blocks)
4131 unsigned int bb_index, df_bb_index;
4132 bitmap_iterator bi1, bi2;
4133 basic_block bb;
4134 bitmap_head *frontiers;
4136 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4138 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4140 df_md_bb_local_compute (bb_index);
4143 bitmap_clear (&seen_in_insn);
4145 frontiers = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
4146 FOR_ALL_BB_FN (bb, cfun)
4147 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4149 compute_dominance_frontiers (frontiers);
4151 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4152 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4154 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4155 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4157 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, df_bb_index);
4158 if (bitmap_bit_p (all_blocks, df_bb_index))
4159 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4160 df_get_live_in (bb));
4164 FOR_ALL_BB_FN (bb, cfun)
4165 bitmap_clear (&frontiers[bb->index]);
4166 free (frontiers);
4170 /* Reset the global solution for recalculation. */
4172 static void
4173 df_md_reset (bitmap all_blocks)
4175 unsigned int bb_index;
4176 bitmap_iterator bi;
4178 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4180 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4181 gcc_assert (bb_info);
4182 bitmap_clear (&bb_info->in);
4183 bitmap_clear (&bb_info->out);
4187 static bool
4188 df_md_transfer_function (int bb_index)
4190 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4191 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4192 bitmap in = &bb_info->in;
4193 bitmap out = &bb_info->out;
4194 bitmap gen = &bb_info->gen;
4195 bitmap kill = &bb_info->kill;
4197 /* We need to use a scratch set here so that the value returned from this
4198 function invocation properly reflects whether the sets changed in a
4199 significant way; i.e. not just because the live set was anded in. */
4200 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4202 /* Multiple definitions of a register are not relevant if it is not
4203 live. Thus we trim the result to the places where it is live. */
4204 bitmap_and_into (in, df_get_live_in (bb));
4206 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4209 /* Initialize the solution bit vectors for problem. */
4211 static void
4212 df_md_init (bitmap all_blocks)
4214 unsigned int bb_index;
4215 bitmap_iterator bi;
4217 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4219 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4221 bitmap_copy (&bb_info->in, &bb_info->init);
4222 df_md_transfer_function (bb_index);
4226 static void
4227 df_md_confluence_0 (basic_block bb)
4229 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4230 bitmap_copy (&bb_info->in, &bb_info->init);
4233 /* In of target gets or of out of source. */
4235 static bool
4236 df_md_confluence_n (edge e)
4238 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4239 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4241 if (e->flags & EDGE_FAKE)
4242 return false;
4244 if (e->flags & EDGE_EH)
4245 return bitmap_ior_and_compl_into (op1, op2,
4246 regs_invalidated_by_call_regset);
4247 else
4248 return bitmap_ior_into (op1, op2);
4251 /* Free all storage associated with the problem. */
4253 static void
4254 df_md_free (void)
4256 struct df_md_problem_data *problem_data
4257 = (struct df_md_problem_data *) df_md->problem_data;
4259 bitmap_obstack_release (&problem_data->md_bitmaps);
4260 free (problem_data);
4261 df_md->problem_data = NULL;
4263 df_md->block_info_size = 0;
4264 free (df_md->block_info);
4265 df_md->block_info = NULL;
4266 free (df_md);
4270 /* Debugging info at top of bb. */
4272 static void
4273 df_md_top_dump (basic_block bb, FILE *file)
4275 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4276 if (!bb_info)
4277 return;
4279 fprintf (file, ";; md in \t");
4280 df_print_regset (file, &bb_info->in);
4281 fprintf (file, ";; md init \t");
4282 df_print_regset (file, &bb_info->init);
4283 fprintf (file, ";; md gen \t");
4284 df_print_regset (file, &bb_info->gen);
4285 fprintf (file, ";; md kill \t");
4286 df_print_regset (file, &bb_info->kill);
4289 /* Debugging info at bottom of bb. */
4291 static void
4292 df_md_bottom_dump (basic_block bb, FILE *file)
4294 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4295 if (!bb_info)
4296 return;
4298 fprintf (file, ";; md out \t");
4299 df_print_regset (file, &bb_info->out);
4302 static struct df_problem problem_MD =
4304 DF_MD, /* Problem id. */
4305 DF_FORWARD, /* Direction. */
4306 df_md_alloc, /* Allocate the problem specific data. */
4307 df_md_reset, /* Reset global information. */
4308 df_md_free_bb_info, /* Free basic block info. */
4309 df_md_local_compute, /* Local compute function. */
4310 df_md_init, /* Init the solution specific data. */
4311 df_worklist_dataflow, /* Worklist solver. */
4312 df_md_confluence_0, /* Confluence operator 0. */
4313 df_md_confluence_n, /* Confluence operator n. */
4314 df_md_transfer_function, /* Transfer function. */
4315 NULL, /* Finalize function. */
4316 df_md_free, /* Free all of the problem information. */
4317 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4318 NULL, /* Debugging. */
4319 df_md_top_dump, /* Debugging start block. */
4320 df_md_bottom_dump, /* Debugging end block. */
4321 NULL, /* Debugging start insn. */
4322 NULL, /* Debugging end insn. */
4323 NULL, /* Incremental solution verify start. */
4324 NULL, /* Incremental solution verify end. */
4325 NULL, /* Dependent problem. */
4326 sizeof (struct df_md_bb_info),/* Size of entry of block_info array. */
4327 TV_DF_MD, /* Timing variable. */
4328 false /* Reset blocks on dropping out of blocks_to_analyze. */
4331 /* Create a new MD instance and add it to the existing instance
4332 of DF. */
4334 void
4335 df_md_add_problem (void)
4337 df_add_problem (&problem_MD);