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