2015-06-11 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / df-problems.c
blob10dc40185143e8a26b3ce8fad1e03eff48174457
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tm_p.h"
30 #include "insn-config.h"
31 #include "recog.h"
32 #include "hard-reg-set.h"
33 #include "input.h"
34 #include "function.h"
35 #include "regs.h"
36 #include "alloc-pool.h"
37 #include "flags.h"
38 #include "predict.h"
39 #include "dominance.h"
40 #include "cfg.h"
41 #include "cfganal.h"
42 #include "basic-block.h"
43 #include "sbitmap.h"
44 #include "bitmap.h"
45 #include "target.h"
46 #include "timevar.h"
47 #include "df.h"
48 #include "except.h"
49 #include "dce.h"
50 #include "valtrack.h"
51 #include "dumpfile.h"
52 #include "rtl-iter.h"
54 /* Note that turning REG_DEAD_DEBUGGING on will cause
55 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
56 addresses in the dumps. */
57 #define REG_DEAD_DEBUGGING 0
59 #define DF_SPARSE_THRESHOLD 32
61 static bitmap_head seen_in_block;
62 static bitmap_head seen_in_insn;
64 /*----------------------------------------------------------------------------
65 Utility functions.
66 ----------------------------------------------------------------------------*/
68 /* Generic versions to get the void* version of the block info. Only
69 used inside the problem instance vectors. */
71 /* Dump a def-use or use-def chain for REF to FILE. */
73 void
74 df_chain_dump (struct df_link *link, FILE *file)
76 fprintf (file, "{ ");
77 for (; link; link = link->next)
79 fprintf (file, "%c%d(bb %d insn %d) ",
80 DF_REF_REG_DEF_P (link->ref)
81 ? 'd'
82 : (DF_REF_FLAGS (link->ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
83 DF_REF_ID (link->ref),
84 DF_REF_BBNO (link->ref),
85 DF_REF_IS_ARTIFICIAL (link->ref)
86 ? -1 : DF_REF_INSN_UID (link->ref));
88 fprintf (file, "}");
92 /* Print some basic block info as part of df_dump. */
94 void
95 df_print_bb_index (basic_block bb, FILE *file)
97 edge e;
98 edge_iterator ei;
100 fprintf (file, "\n( ");
101 FOR_EACH_EDGE (e, ei, bb->preds)
103 basic_block pred = e->src;
104 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
106 fprintf (file, ")->[%d]->( ", bb->index);
107 FOR_EACH_EDGE (e, ei, bb->succs)
109 basic_block succ = e->dest;
110 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
112 fprintf (file, ")\n");
116 /*----------------------------------------------------------------------------
117 REACHING DEFINITIONS
119 Find the locations in the function where each definition site for a
120 pseudo reaches. In and out bitvectors are built for each basic
121 block. The id field in the ref is used to index into these sets.
122 See df.h for details.
124 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
125 existing uses are included in the global reaching DEFs set, or in other
126 words only DEFs that are still live. This is a kind of pruned version
127 of the traditional reaching definitions problem that is much less
128 complex to compute and produces enough information to compute UD-chains.
129 In this context, live must be interpreted in the DF_LR sense: Uses that
130 are upward exposed but maybe not initialized on all paths through the
131 CFG. For a USE that is not reached by a DEF on all paths, we still want
132 to make those DEFs that do reach the USE visible, and pruning based on
133 DF_LIVE would make that impossible.
134 ----------------------------------------------------------------------------*/
136 /* This problem plays a large number of games for the sake of
137 efficiency.
139 1) The order of the bits in the bitvectors. After the scanning
140 phase, all of the defs are sorted. All of the defs for the reg 0
141 are first, followed by all defs for reg 1 and so on.
143 2) There are two kill sets, one if the number of defs is less or
144 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
145 greater.
147 <= : Data is built directly in the kill set.
149 > : One level of indirection is used to keep from generating long
150 strings of 1 bits in the kill sets. Bitvectors that are indexed
151 by the regnum are used to represent that there is a killing def
152 for the register. The confluence and transfer functions use
153 these along with the bitmap_clear_range call to remove ranges of
154 bits without actually generating a knockout vector.
156 The kill and sparse_kill and the dense_invalidated_by_call and
157 sparse_invalidated_by_call both play this game. */
159 /* Private data used to compute the solution for this problem. These
160 data structures are not accessible outside of this module. */
161 struct df_rd_problem_data
163 /* The set of defs to regs invalidated by call. */
164 bitmap_head sparse_invalidated_by_call;
165 /* The set of defs to regs invalidate by call for rd. */
166 bitmap_head dense_invalidated_by_call;
167 /* An obstack for the bitmaps we need for this problem. */
168 bitmap_obstack rd_bitmaps;
172 /* Free basic block info. */
174 static void
175 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
176 void *vbb_info)
178 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
179 if (bb_info)
181 bitmap_clear (&bb_info->kill);
182 bitmap_clear (&bb_info->sparse_kill);
183 bitmap_clear (&bb_info->gen);
184 bitmap_clear (&bb_info->in);
185 bitmap_clear (&bb_info->out);
190 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
191 not touched unless the block is new. */
193 static void
194 df_rd_alloc (bitmap all_blocks)
196 unsigned int bb_index;
197 bitmap_iterator bi;
198 struct df_rd_problem_data *problem_data;
200 if (df_rd->problem_data)
202 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
203 bitmap_clear (&problem_data->sparse_invalidated_by_call);
204 bitmap_clear (&problem_data->dense_invalidated_by_call);
206 else
208 problem_data = XNEW (struct df_rd_problem_data);
209 df_rd->problem_data = problem_data;
211 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
212 bitmap_initialize (&problem_data->sparse_invalidated_by_call,
213 &problem_data->rd_bitmaps);
214 bitmap_initialize (&problem_data->dense_invalidated_by_call,
215 &problem_data->rd_bitmaps);
218 df_grow_bb_info (df_rd);
220 /* Because of the clustering of all use sites for the same pseudo,
221 we have to process all of the blocks before doing the analysis. */
223 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
225 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
227 /* When bitmaps are already initialized, just clear them. */
228 if (bb_info->kill.obstack)
230 bitmap_clear (&bb_info->kill);
231 bitmap_clear (&bb_info->sparse_kill);
232 bitmap_clear (&bb_info->gen);
234 else
236 bitmap_initialize (&bb_info->kill, &problem_data->rd_bitmaps);
237 bitmap_initialize (&bb_info->sparse_kill, &problem_data->rd_bitmaps);
238 bitmap_initialize (&bb_info->gen, &problem_data->rd_bitmaps);
239 bitmap_initialize (&bb_info->in, &problem_data->rd_bitmaps);
240 bitmap_initialize (&bb_info->out, &problem_data->rd_bitmaps);
243 df_rd->optional_p = true;
247 /* Add the effect of the top artificial defs of BB to the reaching definitions
248 bitmap LOCAL_RD. */
250 void
251 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
253 int bb_index = bb->index;
254 df_ref def;
255 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
256 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
258 unsigned int dregno = DF_REF_REGNO (def);
259 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
260 bitmap_clear_range (local_rd,
261 DF_DEFS_BEGIN (dregno),
262 DF_DEFS_COUNT (dregno));
263 bitmap_set_bit (local_rd, DF_REF_ID (def));
267 /* Add the effect of the defs of INSN to the reaching definitions bitmap
268 LOCAL_RD. */
270 void
271 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
272 bitmap local_rd)
274 df_ref def;
276 FOR_EACH_INSN_DEF (def, insn)
278 unsigned int dregno = DF_REF_REGNO (def);
279 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
280 || (dregno >= FIRST_PSEUDO_REGISTER))
282 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
283 bitmap_clear_range (local_rd,
284 DF_DEFS_BEGIN (dregno),
285 DF_DEFS_COUNT (dregno));
286 if (!(DF_REF_FLAGS (def)
287 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
288 bitmap_set_bit (local_rd, DF_REF_ID (def));
293 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
294 more complicated than just simulating, because we must produce the
295 gen and kill sets and hence deal with the two possible representations
296 of kill sets. */
298 static void
299 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
300 df_ref def,
301 int top_flag)
303 for (; def; def = DF_REF_NEXT_LOC (def))
305 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
307 unsigned int regno = DF_REF_REGNO (def);
308 unsigned int begin = DF_DEFS_BEGIN (regno);
309 unsigned int n_defs = DF_DEFS_COUNT (regno);
311 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
312 || (regno >= FIRST_PSEUDO_REGISTER))
314 /* Only the last def(s) for a regno in the block has any
315 effect. */
316 if (!bitmap_bit_p (&seen_in_block, regno))
318 /* The first def for regno in insn gets to knock out the
319 defs from other instructions. */
320 if ((!bitmap_bit_p (&seen_in_insn, regno))
321 /* If the def is to only part of the reg, it does
322 not kill the other defs that reach here. */
323 && (!(DF_REF_FLAGS (def) &
324 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
326 if (n_defs > DF_SPARSE_THRESHOLD)
328 bitmap_set_bit (&bb_info->sparse_kill, regno);
329 bitmap_clear_range (&bb_info->gen, begin, n_defs);
331 else
333 bitmap_set_range (&bb_info->kill, begin, n_defs);
334 bitmap_clear_range (&bb_info->gen, begin, n_defs);
338 bitmap_set_bit (&seen_in_insn, regno);
339 /* All defs for regno in the instruction may be put into
340 the gen set. */
341 if (!(DF_REF_FLAGS (def)
342 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
343 bitmap_set_bit (&bb_info->gen, DF_REF_ID (def));
350 /* Compute local reaching def info for basic block BB. */
352 static void
353 df_rd_bb_local_compute (unsigned int bb_index)
355 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
356 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
357 rtx_insn *insn;
359 bitmap_clear (&seen_in_block);
360 bitmap_clear (&seen_in_insn);
362 /* Artificials are only hard regs. */
363 if (!(df->changeable_flags & DF_NO_HARD_REGS))
364 df_rd_bb_local_compute_process_def (bb_info,
365 df_get_artificial_defs (bb_index),
368 FOR_BB_INSNS_REVERSE (bb, insn)
370 unsigned int uid = INSN_UID (insn);
372 if (!INSN_P (insn))
373 continue;
375 df_rd_bb_local_compute_process_def (bb_info,
376 DF_INSN_UID_DEFS (uid), 0);
378 /* This complex dance with the two bitmaps is required because
379 instructions can assign twice to the same pseudo. This
380 generally happens with calls that will have one def for the
381 result and another def for the clobber. If only one vector
382 is used and the clobber goes first, the result will be
383 lost. */
384 bitmap_ior_into (&seen_in_block, &seen_in_insn);
385 bitmap_clear (&seen_in_insn);
388 /* Process the artificial defs at the top of the block last since we
389 are going backwards through the block and these are logically at
390 the start. */
391 if (!(df->changeable_flags & DF_NO_HARD_REGS))
392 df_rd_bb_local_compute_process_def (bb_info,
393 df_get_artificial_defs (bb_index),
394 DF_REF_AT_TOP);
398 /* Compute local reaching def info for each basic block within BLOCKS. */
400 static void
401 df_rd_local_compute (bitmap all_blocks)
403 unsigned int bb_index;
404 bitmap_iterator bi;
405 unsigned int regno;
406 struct df_rd_problem_data *problem_data
407 = (struct df_rd_problem_data *) df_rd->problem_data;
408 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
409 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
411 bitmap_initialize (&seen_in_block, &df_bitmap_obstack);
412 bitmap_initialize (&seen_in_insn, &df_bitmap_obstack);
414 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
416 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
418 df_rd_bb_local_compute (bb_index);
421 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
422 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, regno, bi)
424 if (! HARD_REGISTER_NUM_P (regno)
425 || !(df->changeable_flags & DF_NO_HARD_REGS))
427 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
428 bitmap_set_bit (sparse_invalidated, regno);
429 else
430 bitmap_set_range (dense_invalidated,
431 DF_DEFS_BEGIN (regno),
432 DF_DEFS_COUNT (regno));
436 bitmap_clear (&seen_in_block);
437 bitmap_clear (&seen_in_insn);
441 /* Initialize the solution bit vectors for problem. */
443 static void
444 df_rd_init_solution (bitmap all_blocks)
446 unsigned int bb_index;
447 bitmap_iterator bi;
449 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
451 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
453 bitmap_copy (&bb_info->out, &bb_info->gen);
454 bitmap_clear (&bb_info->in);
458 /* In of target gets or of out of source. */
460 static bool
461 df_rd_confluence_n (edge e)
463 bitmap op1 = &df_rd_get_bb_info (e->dest->index)->in;
464 bitmap op2 = &df_rd_get_bb_info (e->src->index)->out;
465 bool changed = false;
467 if (e->flags & EDGE_FAKE)
468 return false;
470 if (e->flags & EDGE_EH)
472 struct df_rd_problem_data *problem_data
473 = (struct df_rd_problem_data *) df_rd->problem_data;
474 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
475 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
476 bitmap_iterator bi;
477 unsigned int regno;
478 bitmap_head tmp;
480 bitmap_initialize (&tmp, &df_bitmap_obstack);
481 bitmap_and_compl (&tmp, op2, dense_invalidated);
483 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
485 bitmap_clear_range (&tmp,
486 DF_DEFS_BEGIN (regno),
487 DF_DEFS_COUNT (regno));
489 changed |= bitmap_ior_into (op1, &tmp);
490 bitmap_clear (&tmp);
491 return changed;
493 else
494 return bitmap_ior_into (op1, op2);
498 /* Transfer function. */
500 static bool
501 df_rd_transfer_function (int bb_index)
503 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
504 unsigned int regno;
505 bitmap_iterator bi;
506 bitmap in = &bb_info->in;
507 bitmap out = &bb_info->out;
508 bitmap gen = &bb_info->gen;
509 bitmap kill = &bb_info->kill;
510 bitmap sparse_kill = &bb_info->sparse_kill;
511 bool changed = false;
513 if (bitmap_empty_p (sparse_kill))
514 changed = bitmap_ior_and_compl (out, gen, in, kill);
515 else
517 struct df_rd_problem_data *problem_data;
518 bitmap_head tmp;
520 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
521 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
522 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
523 bitmap_initialize (&tmp, &problem_data->rd_bitmaps);
525 bitmap_and_compl (&tmp, in, kill);
526 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
528 bitmap_clear_range (&tmp,
529 DF_DEFS_BEGIN (regno),
530 DF_DEFS_COUNT (regno));
532 bitmap_ior_into (&tmp, gen);
533 changed = !bitmap_equal_p (&tmp, out);
534 if (changed)
536 bitmap_clear (out);
537 bb_info->out = tmp;
539 else
540 bitmap_clear (&tmp);
543 if (df->changeable_flags & DF_RD_PRUNE_DEAD_DEFS)
545 /* Create a mask of DEFs for all registers live at the end of this
546 basic block, and mask out DEFs of registers that are not live.
547 Computing the mask looks costly, but the benefit of the pruning
548 outweighs the cost. */
549 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
550 bitmap regs_live_out = &df_lr_get_bb_info (bb_index)->out;
551 bitmap live_defs = BITMAP_ALLOC (&df_bitmap_obstack);
552 unsigned int regno;
553 bitmap_iterator bi;
555 EXECUTE_IF_SET_IN_BITMAP (regs_live_out, 0, regno, bi)
556 bitmap_set_range (live_defs,
557 DF_DEFS_BEGIN (regno),
558 DF_DEFS_COUNT (regno));
559 changed |= bitmap_and_into (&bb_info->out, live_defs);
560 BITMAP_FREE (live_defs);
563 return changed;
566 /* Free all storage associated with the problem. */
568 static void
569 df_rd_free (void)
571 struct df_rd_problem_data *problem_data
572 = (struct df_rd_problem_data *) df_rd->problem_data;
574 if (problem_data)
576 bitmap_obstack_release (&problem_data->rd_bitmaps);
578 df_rd->block_info_size = 0;
579 free (df_rd->block_info);
580 df_rd->block_info = NULL;
581 free (df_rd->problem_data);
583 free (df_rd);
587 /* Debugging info. */
589 static void
590 df_rd_start_dump (FILE *file)
592 struct df_rd_problem_data *problem_data
593 = (struct df_rd_problem_data *) df_rd->problem_data;
594 unsigned int m = DF_REG_SIZE (df);
595 unsigned int regno;
597 if (!df_rd->block_info)
598 return;
600 fprintf (file, ";; Reaching defs:\n");
602 fprintf (file, ";; sparse invalidated \t");
603 dump_bitmap (file, &problem_data->sparse_invalidated_by_call);
604 fprintf (file, ";; dense invalidated \t");
605 dump_bitmap (file, &problem_data->dense_invalidated_by_call);
607 fprintf (file, ";; reg->defs[] map:\t");
608 for (regno = 0; regno < m; regno++)
609 if (DF_DEFS_COUNT (regno))
610 fprintf (file, "%d[%d,%d] ", regno,
611 DF_DEFS_BEGIN (regno),
612 DF_DEFS_BEGIN (regno) + DF_DEFS_COUNT (regno) - 1);
613 fprintf (file, "\n");
617 static void
618 df_rd_dump_defs_set (bitmap defs_set, const char *prefix, FILE *file)
620 bitmap_head tmp;
621 unsigned int regno;
622 unsigned int m = DF_REG_SIZE (df);
623 bool first_reg = true;
625 fprintf (file, "%s\t(%d) ", prefix, (int) bitmap_count_bits (defs_set));
627 bitmap_initialize (&tmp, &df_bitmap_obstack);
628 for (regno = 0; regno < m; regno++)
630 if (HARD_REGISTER_NUM_P (regno)
631 && (df->changeable_flags & DF_NO_HARD_REGS))
632 continue;
633 bitmap_set_range (&tmp, DF_DEFS_BEGIN (regno), DF_DEFS_COUNT (regno));
634 bitmap_and_into (&tmp, defs_set);
635 if (! bitmap_empty_p (&tmp))
637 bitmap_iterator bi;
638 unsigned int ix;
639 bool first_def = true;
641 if (! first_reg)
642 fprintf (file, ",");
643 first_reg = false;
645 fprintf (file, "%u[", regno);
646 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, ix, bi)
648 fprintf (file, "%s%u", first_def ? "" : ",", ix);
649 first_def = false;
651 fprintf (file, "]");
653 bitmap_clear (&tmp);
656 fprintf (file, "\n");
657 bitmap_clear (&tmp);
660 /* Debugging info at top of bb. */
662 static void
663 df_rd_top_dump (basic_block bb, FILE *file)
665 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
666 if (!bb_info)
667 return;
669 df_rd_dump_defs_set (&bb_info->in, ";; rd in ", file);
670 df_rd_dump_defs_set (&bb_info->gen, ";; rd gen ", file);
671 df_rd_dump_defs_set (&bb_info->kill, ";; rd kill", file);
675 /* Debugging info at bottom of bb. */
677 static void
678 df_rd_bottom_dump (basic_block bb, FILE *file)
680 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
681 if (!bb_info)
682 return;
684 df_rd_dump_defs_set (&bb_info->out, ";; rd out ", file);
687 /* All of the information associated with every instance of the problem. */
689 static struct df_problem problem_RD =
691 DF_RD, /* Problem id. */
692 DF_FORWARD, /* Direction. */
693 df_rd_alloc, /* Allocate the problem specific data. */
694 NULL, /* Reset global information. */
695 df_rd_free_bb_info, /* Free basic block info. */
696 df_rd_local_compute, /* Local compute function. */
697 df_rd_init_solution, /* Init the solution specific data. */
698 df_worklist_dataflow, /* Worklist solver. */
699 NULL, /* Confluence operator 0. */
700 df_rd_confluence_n, /* Confluence operator n. */
701 df_rd_transfer_function, /* Transfer function. */
702 NULL, /* Finalize function. */
703 df_rd_free, /* Free all of the problem information. */
704 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
705 df_rd_start_dump, /* Debugging. */
706 df_rd_top_dump, /* Debugging start block. */
707 df_rd_bottom_dump, /* Debugging end block. */
708 NULL, /* Debugging start insn. */
709 NULL, /* Debugging end insn. */
710 NULL, /* Incremental solution verify start. */
711 NULL, /* Incremental solution verify end. */
712 NULL, /* Dependent problem. */
713 sizeof (struct df_rd_bb_info),/* Size of entry of block_info array. */
714 TV_DF_RD, /* Timing variable. */
715 true /* Reset blocks on dropping out of blocks_to_analyze. */
720 /* Create a new RD instance and add it to the existing instance
721 of DF. */
723 void
724 df_rd_add_problem (void)
726 df_add_problem (&problem_RD);
731 /*----------------------------------------------------------------------------
732 LIVE REGISTERS
734 Find the locations in the function where any use of a pseudo can
735 reach in the backwards direction. In and out bitvectors are built
736 for each basic block. The regno is used to index into these sets.
737 See df.h for details.
738 ----------------------------------------------------------------------------*/
740 /* Private data used to verify the solution for this problem. */
741 struct df_lr_problem_data
743 bitmap_head *in;
744 bitmap_head *out;
745 /* An obstack for the bitmaps we need for this problem. */
746 bitmap_obstack lr_bitmaps;
749 /* Free basic block info. */
751 static void
752 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
753 void *vbb_info)
755 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
756 if (bb_info)
758 bitmap_clear (&bb_info->use);
759 bitmap_clear (&bb_info->def);
760 bitmap_clear (&bb_info->in);
761 bitmap_clear (&bb_info->out);
766 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
767 not touched unless the block is new. */
769 static void
770 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
772 unsigned int bb_index;
773 bitmap_iterator bi;
774 struct df_lr_problem_data *problem_data;
776 df_grow_bb_info (df_lr);
777 if (df_lr->problem_data)
778 problem_data = (struct df_lr_problem_data *) df_lr->problem_data;
779 else
781 problem_data = XNEW (struct df_lr_problem_data);
782 df_lr->problem_data = problem_data;
784 problem_data->out = NULL;
785 problem_data->in = NULL;
786 bitmap_obstack_initialize (&problem_data->lr_bitmaps);
789 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
791 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
793 /* When bitmaps are already initialized, just clear them. */
794 if (bb_info->use.obstack)
796 bitmap_clear (&bb_info->def);
797 bitmap_clear (&bb_info->use);
799 else
801 bitmap_initialize (&bb_info->use, &problem_data->lr_bitmaps);
802 bitmap_initialize (&bb_info->def, &problem_data->lr_bitmaps);
803 bitmap_initialize (&bb_info->in, &problem_data->lr_bitmaps);
804 bitmap_initialize (&bb_info->out, &problem_data->lr_bitmaps);
808 df_lr->optional_p = false;
812 /* Reset the global solution for recalculation. */
814 static void
815 df_lr_reset (bitmap all_blocks)
817 unsigned int bb_index;
818 bitmap_iterator bi;
820 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
822 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
823 gcc_assert (bb_info);
824 bitmap_clear (&bb_info->in);
825 bitmap_clear (&bb_info->out);
830 /* Compute local live register info for basic block BB. */
832 static void
833 df_lr_bb_local_compute (unsigned int bb_index)
835 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
836 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
837 rtx_insn *insn;
838 df_ref def, use;
840 /* Process the registers set in an exception handler. */
841 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
842 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
844 unsigned int dregno = DF_REF_REGNO (def);
845 bitmap_set_bit (&bb_info->def, dregno);
846 bitmap_clear_bit (&bb_info->use, dregno);
849 /* Process the hardware registers that are always live. */
850 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
851 /* Add use to set of uses in this BB. */
852 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
853 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
855 FOR_BB_INSNS_REVERSE (bb, insn)
857 if (!NONDEBUG_INSN_P (insn))
858 continue;
860 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
861 FOR_EACH_INSN_INFO_DEF (def, insn_info)
862 /* If the def is to only part of the reg, it does
863 not kill the other defs that reach here. */
864 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
866 unsigned int dregno = DF_REF_REGNO (def);
867 bitmap_set_bit (&bb_info->def, dregno);
868 bitmap_clear_bit (&bb_info->use, dregno);
871 FOR_EACH_INSN_INFO_USE (use, insn_info)
872 /* Add use to set of uses in this BB. */
873 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
876 /* Process the registers set in an exception handler or the hard
877 frame pointer if this block is the target of a non local
878 goto. */
879 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
880 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
882 unsigned int dregno = DF_REF_REGNO (def);
883 bitmap_set_bit (&bb_info->def, dregno);
884 bitmap_clear_bit (&bb_info->use, dregno);
887 #ifdef EH_USES
888 /* Process the uses that are live into an exception handler. */
889 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
890 /* Add use to set of uses in this BB. */
891 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
892 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
893 #endif
895 /* If the df_live problem is not defined, such as at -O0 and -O1, we
896 still need to keep the luids up to date. This is normally done
897 in the df_live problem since this problem has a forwards
898 scan. */
899 if (!df_live)
900 df_recompute_luids (bb);
904 /* Compute local live register info for each basic block within BLOCKS. */
906 static void
907 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
909 unsigned int bb_index, i;
910 bitmap_iterator bi;
912 bitmap_clear (&df->hardware_regs_used);
914 /* The all-important stack pointer must always be live. */
915 bitmap_set_bit (&df->hardware_regs_used, STACK_POINTER_REGNUM);
917 /* Global regs are always live, too. */
918 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
919 if (global_regs[i])
920 bitmap_set_bit (&df->hardware_regs_used, i);
922 /* Before reload, there are a few registers that must be forced
923 live everywhere -- which might not already be the case for
924 blocks within infinite loops. */
925 if (!reload_completed)
927 unsigned int pic_offset_table_regnum = PIC_OFFSET_TABLE_REGNUM;
928 /* Any reference to any pseudo before reload is a potential
929 reference of the frame pointer. */
930 bitmap_set_bit (&df->hardware_regs_used, FRAME_POINTER_REGNUM);
932 /* Pseudos with argument area equivalences may require
933 reloading via the argument pointer. */
934 if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
935 && fixed_regs[ARG_POINTER_REGNUM])
936 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
938 /* Any constant, or pseudo with constant equivalences, may
939 require reloading from memory using the pic register. */
940 if (pic_offset_table_regnum != INVALID_REGNUM
941 && fixed_regs[pic_offset_table_regnum])
942 bitmap_set_bit (&df->hardware_regs_used, pic_offset_table_regnum);
945 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
947 if (bb_index == EXIT_BLOCK)
949 /* The exit block is special for this problem and its bits are
950 computed from thin air. */
951 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
952 bitmap_copy (&bb_info->use, df->exit_block_uses);
954 else
955 df_lr_bb_local_compute (bb_index);
958 bitmap_clear (df_lr->out_of_date_transfer_functions);
962 /* Initialize the solution vectors. */
964 static void
965 df_lr_init (bitmap all_blocks)
967 unsigned int bb_index;
968 bitmap_iterator bi;
970 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
972 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
973 bitmap_copy (&bb_info->in, &bb_info->use);
974 bitmap_clear (&bb_info->out);
979 /* Confluence function that processes infinite loops. This might be a
980 noreturn function that throws. And even if it isn't, getting the
981 unwind info right helps debugging. */
982 static void
983 df_lr_confluence_0 (basic_block bb)
985 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
986 if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
987 bitmap_copy (op1, &df->hardware_regs_used);
991 /* Confluence function that ignores fake edges. */
993 static bool
994 df_lr_confluence_n (edge e)
996 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
997 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
998 bool changed = false;
1000 /* Call-clobbered registers die across exception and call edges. */
1001 /* ??? Abnormal call edges ignored for the moment, as this gets
1002 confused by sibling call edges, which crashes reg-stack. */
1003 if (e->flags & EDGE_EH)
1004 changed = bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
1005 else
1006 changed = bitmap_ior_into (op1, op2);
1008 changed |= bitmap_ior_into (op1, &df->hardware_regs_used);
1009 return changed;
1013 /* Transfer function. */
1015 static bool
1016 df_lr_transfer_function (int bb_index)
1018 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1019 bitmap in = &bb_info->in;
1020 bitmap out = &bb_info->out;
1021 bitmap use = &bb_info->use;
1022 bitmap def = &bb_info->def;
1024 return bitmap_ior_and_compl (in, use, out, def);
1028 /* Run the fast dce as a side effect of building LR. */
1030 static void
1031 df_lr_finalize (bitmap all_blocks)
1033 df_lr->solutions_dirty = false;
1034 if (df->changeable_flags & DF_LR_RUN_DCE)
1036 run_fast_df_dce ();
1038 /* If dce deletes some instructions, we need to recompute the lr
1039 solution before proceeding further. The problem is that fast
1040 dce is a pessimestic dataflow algorithm. In the case where
1041 it deletes a statement S inside of a loop, the uses inside of
1042 S may not be deleted from the dataflow solution because they
1043 were carried around the loop. While it is conservatively
1044 correct to leave these extra bits, the standards of df
1045 require that we maintain the best possible (least fixed
1046 point) solution. The only way to do that is to redo the
1047 iteration from the beginning. See PR35805 for an
1048 example. */
1049 if (df_lr->solutions_dirty)
1051 df_clear_flags (DF_LR_RUN_DCE);
1052 df_lr_alloc (all_blocks);
1053 df_lr_local_compute (all_blocks);
1054 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1055 df_lr_finalize (all_blocks);
1056 df_set_flags (DF_LR_RUN_DCE);
1062 /* Free all storage associated with the problem. */
1064 static void
1065 df_lr_free (void)
1067 struct df_lr_problem_data *problem_data
1068 = (struct df_lr_problem_data *) df_lr->problem_data;
1069 if (df_lr->block_info)
1072 df_lr->block_info_size = 0;
1073 free (df_lr->block_info);
1074 df_lr->block_info = NULL;
1075 bitmap_obstack_release (&problem_data->lr_bitmaps);
1076 free (df_lr->problem_data);
1077 df_lr->problem_data = NULL;
1080 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1081 free (df_lr);
1085 /* Debugging info at top of bb. */
1087 static void
1088 df_lr_top_dump (basic_block bb, FILE *file)
1090 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1091 struct df_lr_problem_data *problem_data;
1092 if (!bb_info)
1093 return;
1095 fprintf (file, ";; lr in \t");
1096 df_print_regset (file, &bb_info->in);
1097 if (df_lr->problem_data)
1099 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1100 if (problem_data->in)
1102 fprintf (file, ";; old in \t");
1103 df_print_regset (file, &problem_data->in[bb->index]);
1106 fprintf (file, ";; lr use \t");
1107 df_print_regset (file, &bb_info->use);
1108 fprintf (file, ";; lr def \t");
1109 df_print_regset (file, &bb_info->def);
1113 /* Debugging info at bottom of bb. */
1115 static void
1116 df_lr_bottom_dump (basic_block bb, FILE *file)
1118 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1119 struct df_lr_problem_data *problem_data;
1120 if (!bb_info)
1121 return;
1123 fprintf (file, ";; lr out \t");
1124 df_print_regset (file, &bb_info->out);
1125 if (df_lr->problem_data)
1127 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1128 if (problem_data->out)
1130 fprintf (file, ";; old out \t");
1131 df_print_regset (file, &problem_data->out[bb->index]);
1137 /* Build the datastructure to verify that the solution to the dataflow
1138 equations is not dirty. */
1140 static void
1141 df_lr_verify_solution_start (void)
1143 basic_block bb;
1144 struct df_lr_problem_data *problem_data;
1145 if (df_lr->solutions_dirty)
1146 return;
1148 /* Set it true so that the solution is recomputed. */
1149 df_lr->solutions_dirty = true;
1151 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1152 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1153 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1155 FOR_ALL_BB_FN (bb, cfun)
1157 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1158 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1159 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1160 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1165 /* Compare the saved datastructure and the new solution to the dataflow
1166 equations. */
1168 static void
1169 df_lr_verify_solution_end (void)
1171 struct df_lr_problem_data *problem_data;
1172 basic_block bb;
1174 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1176 if (!problem_data->out)
1177 return;
1179 if (df_lr->solutions_dirty)
1180 /* Do not check if the solution is still dirty. See the comment
1181 in df_lr_finalize for details. */
1182 df_lr->solutions_dirty = false;
1183 else
1184 FOR_ALL_BB_FN (bb, cfun)
1186 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1187 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1189 /*df_dump (stderr);*/
1190 gcc_unreachable ();
1194 /* Cannot delete them immediately because you may want to dump them
1195 if the comparison fails. */
1196 FOR_ALL_BB_FN (bb, cfun)
1198 bitmap_clear (&problem_data->in[bb->index]);
1199 bitmap_clear (&problem_data->out[bb->index]);
1202 free (problem_data->in);
1203 free (problem_data->out);
1204 problem_data->in = NULL;
1205 problem_data->out = NULL;
1209 /* All of the information associated with every instance of the problem. */
1211 static struct df_problem problem_LR =
1213 DF_LR, /* Problem id. */
1214 DF_BACKWARD, /* Direction. */
1215 df_lr_alloc, /* Allocate the problem specific data. */
1216 df_lr_reset, /* Reset global information. */
1217 df_lr_free_bb_info, /* Free basic block info. */
1218 df_lr_local_compute, /* Local compute function. */
1219 df_lr_init, /* Init the solution specific data. */
1220 df_worklist_dataflow, /* Worklist solver. */
1221 df_lr_confluence_0, /* Confluence operator 0. */
1222 df_lr_confluence_n, /* Confluence operator n. */
1223 df_lr_transfer_function, /* Transfer function. */
1224 df_lr_finalize, /* Finalize function. */
1225 df_lr_free, /* Free all of the problem information. */
1226 NULL, /* Remove this problem from the stack of dataflow problems. */
1227 NULL, /* Debugging. */
1228 df_lr_top_dump, /* Debugging start block. */
1229 df_lr_bottom_dump, /* Debugging end block. */
1230 NULL, /* Debugging start insn. */
1231 NULL, /* Debugging end insn. */
1232 df_lr_verify_solution_start,/* Incremental solution verify start. */
1233 df_lr_verify_solution_end, /* Incremental solution verify end. */
1234 NULL, /* Dependent problem. */
1235 sizeof (struct df_lr_bb_info),/* Size of entry of block_info array. */
1236 TV_DF_LR, /* Timing variable. */
1237 false /* Reset blocks on dropping out of blocks_to_analyze. */
1241 /* Create a new DATAFLOW instance and add it to an existing instance
1242 of DF. The returned structure is what is used to get at the
1243 solution. */
1245 void
1246 df_lr_add_problem (void)
1248 df_add_problem (&problem_LR);
1249 /* These will be initialized when df_scan_blocks processes each
1250 block. */
1251 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1255 /* Verify that all of the lr related info is consistent and
1256 correct. */
1258 void
1259 df_lr_verify_transfer_functions (void)
1261 basic_block bb;
1262 bitmap_head saved_def;
1263 bitmap_head saved_use;
1264 bitmap_head all_blocks;
1266 if (!df)
1267 return;
1269 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1270 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1271 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1273 FOR_ALL_BB_FN (bb, cfun)
1275 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1276 bitmap_set_bit (&all_blocks, bb->index);
1278 if (bb_info)
1280 /* Make a copy of the transfer functions and then compute
1281 new ones to see if the transfer functions have
1282 changed. */
1283 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1284 bb->index))
1286 bitmap_copy (&saved_def, &bb_info->def);
1287 bitmap_copy (&saved_use, &bb_info->use);
1288 bitmap_clear (&bb_info->def);
1289 bitmap_clear (&bb_info->use);
1291 df_lr_bb_local_compute (bb->index);
1292 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1293 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1296 else
1298 /* If we do not have basic block info, the block must be in
1299 the list of dirty blocks or else some one has added a
1300 block behind our backs. */
1301 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1302 bb->index));
1304 /* Make sure no one created a block without following
1305 procedures. */
1306 gcc_assert (df_scan_get_bb_info (bb->index));
1309 /* Make sure there are no dirty bits in blocks that have been deleted. */
1310 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1311 &all_blocks));
1313 bitmap_clear (&saved_def);
1314 bitmap_clear (&saved_use);
1315 bitmap_clear (&all_blocks);
1320 /*----------------------------------------------------------------------------
1321 LIVE AND MUST-INITIALIZED REGISTERS.
1323 This problem first computes the IN and OUT bitvectors for the
1324 must-initialized registers problems, which is a forward problem.
1325 It gives the set of registers for which we MUST have an available
1326 definition on any path from the entry block to the entry/exit of
1327 a basic block. Sets generate a definition, while clobbers kill
1328 a definition.
1330 In and out bitvectors are built for each basic block and are indexed by
1331 regnum (see df.h for details). In and out bitvectors in struct
1332 df_live_bb_info actually refers to the must-initialized problem;
1334 Then, the in and out sets for the LIVE problem itself are computed.
1335 These are the logical AND of the IN and OUT sets from the LR problem
1336 and the must-initialized problem.
1337 ----------------------------------------------------------------------------*/
1339 /* Private data used to verify the solution for this problem. */
1340 struct df_live_problem_data
1342 bitmap_head *in;
1343 bitmap_head *out;
1344 /* An obstack for the bitmaps we need for this problem. */
1345 bitmap_obstack live_bitmaps;
1348 /* Scratch var used by transfer functions. This is used to implement
1349 an optimization to reduce the amount of space used to compute the
1350 combined lr and live analysis. */
1351 static bitmap_head df_live_scratch;
1354 /* Free basic block info. */
1356 static void
1357 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1358 void *vbb_info)
1360 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1361 if (bb_info)
1363 bitmap_clear (&bb_info->gen);
1364 bitmap_clear (&bb_info->kill);
1365 bitmap_clear (&bb_info->in);
1366 bitmap_clear (&bb_info->out);
1371 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1372 not touched unless the block is new. */
1374 static void
1375 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1377 unsigned int bb_index;
1378 bitmap_iterator bi;
1379 struct df_live_problem_data *problem_data;
1381 if (df_live->problem_data)
1382 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1383 else
1385 problem_data = XNEW (struct df_live_problem_data);
1386 df_live->problem_data = problem_data;
1388 problem_data->out = NULL;
1389 problem_data->in = NULL;
1390 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1391 bitmap_initialize (&df_live_scratch, &problem_data->live_bitmaps);
1394 df_grow_bb_info (df_live);
1396 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1398 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1400 /* When bitmaps are already initialized, just clear them. */
1401 if (bb_info->kill.obstack)
1403 bitmap_clear (&bb_info->kill);
1404 bitmap_clear (&bb_info->gen);
1406 else
1408 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1409 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1410 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1411 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1414 df_live->optional_p = (optimize <= 1);
1418 /* Reset the global solution for recalculation. */
1420 static void
1421 df_live_reset (bitmap all_blocks)
1423 unsigned int bb_index;
1424 bitmap_iterator bi;
1426 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1428 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1429 gcc_assert (bb_info);
1430 bitmap_clear (&bb_info->in);
1431 bitmap_clear (&bb_info->out);
1436 /* Compute local uninitialized register info for basic block BB. */
1438 static void
1439 df_live_bb_local_compute (unsigned int bb_index)
1441 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1442 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1443 rtx_insn *insn;
1444 df_ref def;
1445 int luid = 0;
1447 FOR_BB_INSNS (bb, insn)
1449 unsigned int uid = INSN_UID (insn);
1450 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1452 /* Inserting labels does not always trigger the incremental
1453 rescanning. */
1454 if (!insn_info)
1456 gcc_assert (!INSN_P (insn));
1457 insn_info = df_insn_create_insn_record (insn);
1460 DF_INSN_INFO_LUID (insn_info) = luid;
1461 if (!INSN_P (insn))
1462 continue;
1464 luid++;
1465 FOR_EACH_INSN_INFO_DEF (def, insn_info)
1467 unsigned int regno = DF_REF_REGNO (def);
1469 if (DF_REF_FLAGS_IS_SET (def,
1470 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1471 /* All partial or conditional def
1472 seen are included in the gen set. */
1473 bitmap_set_bit (&bb_info->gen, regno);
1474 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1475 /* Only must clobbers for the entire reg destroy the
1476 value. */
1477 bitmap_set_bit (&bb_info->kill, regno);
1478 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1479 bitmap_set_bit (&bb_info->gen, regno);
1483 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
1484 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1488 /* Compute local uninitialized register info. */
1490 static void
1491 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1493 unsigned int bb_index;
1494 bitmap_iterator bi;
1496 df_grow_insn_info ();
1498 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1499 0, bb_index, bi)
1501 df_live_bb_local_compute (bb_index);
1504 bitmap_clear (df_live->out_of_date_transfer_functions);
1508 /* Initialize the solution vectors. */
1510 static void
1511 df_live_init (bitmap all_blocks)
1513 unsigned int bb_index;
1514 bitmap_iterator bi;
1516 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1518 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1519 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1521 /* No register may reach a location where it is not used. Thus
1522 we trim the rr result to the places where it is used. */
1523 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1524 bitmap_clear (&bb_info->in);
1528 /* Forward confluence function that ignores fake edges. */
1530 static bool
1531 df_live_confluence_n (edge e)
1533 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1534 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1536 if (e->flags & EDGE_FAKE)
1537 return false;
1539 return bitmap_ior_into (op1, op2);
1543 /* Transfer function for the forwards must-initialized problem. */
1545 static bool
1546 df_live_transfer_function (int bb_index)
1548 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1549 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1550 bitmap in = &bb_info->in;
1551 bitmap out = &bb_info->out;
1552 bitmap gen = &bb_info->gen;
1553 bitmap kill = &bb_info->kill;
1555 /* We need to use a scratch set here so that the value returned from this
1556 function invocation properly reflects whether the sets changed in a
1557 significant way; i.e. not just because the lr set was anded in. */
1558 bitmap_and (&df_live_scratch, gen, &bb_lr_info->out);
1559 /* No register may reach a location where it is not used. Thus
1560 we trim the rr result to the places where it is used. */
1561 bitmap_and_into (in, &bb_lr_info->in);
1563 return bitmap_ior_and_compl (out, &df_live_scratch, in, kill);
1567 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1569 static void
1570 df_live_finalize (bitmap all_blocks)
1573 if (df_live->solutions_dirty)
1575 bitmap_iterator bi;
1576 unsigned int bb_index;
1578 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1580 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1581 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1583 /* No register may reach a location where it is not used. Thus
1584 we trim the rr result to the places where it is used. */
1585 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1586 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1589 df_live->solutions_dirty = false;
1594 /* Free all storage associated with the problem. */
1596 static void
1597 df_live_free (void)
1599 struct df_live_problem_data *problem_data
1600 = (struct df_live_problem_data *) df_live->problem_data;
1601 if (df_live->block_info)
1603 df_live->block_info_size = 0;
1604 free (df_live->block_info);
1605 df_live->block_info = NULL;
1606 bitmap_clear (&df_live_scratch);
1607 bitmap_obstack_release (&problem_data->live_bitmaps);
1608 free (problem_data);
1609 df_live->problem_data = NULL;
1611 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1612 free (df_live);
1616 /* Debugging info at top of bb. */
1618 static void
1619 df_live_top_dump (basic_block bb, FILE *file)
1621 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1622 struct df_live_problem_data *problem_data;
1624 if (!bb_info)
1625 return;
1627 fprintf (file, ";; live in \t");
1628 df_print_regset (file, &bb_info->in);
1629 if (df_live->problem_data)
1631 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1632 if (problem_data->in)
1634 fprintf (file, ";; old in \t");
1635 df_print_regset (file, &problem_data->in[bb->index]);
1638 fprintf (file, ";; live gen \t");
1639 df_print_regset (file, &bb_info->gen);
1640 fprintf (file, ";; live kill\t");
1641 df_print_regset (file, &bb_info->kill);
1645 /* Debugging info at bottom of bb. */
1647 static void
1648 df_live_bottom_dump (basic_block bb, FILE *file)
1650 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1651 struct df_live_problem_data *problem_data;
1653 if (!bb_info)
1654 return;
1656 fprintf (file, ";; live out \t");
1657 df_print_regset (file, &bb_info->out);
1658 if (df_live->problem_data)
1660 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1661 if (problem_data->out)
1663 fprintf (file, ";; old out \t");
1664 df_print_regset (file, &problem_data->out[bb->index]);
1670 /* Build the datastructure to verify that the solution to the dataflow
1671 equations is not dirty. */
1673 static void
1674 df_live_verify_solution_start (void)
1676 basic_block bb;
1677 struct df_live_problem_data *problem_data;
1678 if (df_live->solutions_dirty)
1679 return;
1681 /* Set it true so that the solution is recomputed. */
1682 df_live->solutions_dirty = true;
1684 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1685 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1686 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1688 FOR_ALL_BB_FN (bb, cfun)
1690 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1691 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1692 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1693 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1698 /* Compare the saved datastructure and the new solution to the dataflow
1699 equations. */
1701 static void
1702 df_live_verify_solution_end (void)
1704 struct df_live_problem_data *problem_data;
1705 basic_block bb;
1707 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1708 if (!problem_data->out)
1709 return;
1711 FOR_ALL_BB_FN (bb, cfun)
1713 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1714 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1716 /*df_dump (stderr);*/
1717 gcc_unreachable ();
1721 /* Cannot delete them immediately because you may want to dump them
1722 if the comparison fails. */
1723 FOR_ALL_BB_FN (bb, cfun)
1725 bitmap_clear (&problem_data->in[bb->index]);
1726 bitmap_clear (&problem_data->out[bb->index]);
1729 free (problem_data->in);
1730 free (problem_data->out);
1731 free (problem_data);
1732 df_live->problem_data = NULL;
1736 /* All of the information associated with every instance of the problem. */
1738 static struct df_problem problem_LIVE =
1740 DF_LIVE, /* Problem id. */
1741 DF_FORWARD, /* Direction. */
1742 df_live_alloc, /* Allocate the problem specific data. */
1743 df_live_reset, /* Reset global information. */
1744 df_live_free_bb_info, /* Free basic block info. */
1745 df_live_local_compute, /* Local compute function. */
1746 df_live_init, /* Init the solution specific data. */
1747 df_worklist_dataflow, /* Worklist solver. */
1748 NULL, /* Confluence operator 0. */
1749 df_live_confluence_n, /* Confluence operator n. */
1750 df_live_transfer_function, /* Transfer function. */
1751 df_live_finalize, /* Finalize function. */
1752 df_live_free, /* Free all of the problem information. */
1753 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1754 NULL, /* Debugging. */
1755 df_live_top_dump, /* Debugging start block. */
1756 df_live_bottom_dump, /* Debugging end block. */
1757 NULL, /* Debugging start insn. */
1758 NULL, /* Debugging end insn. */
1759 df_live_verify_solution_start,/* Incremental solution verify start. */
1760 df_live_verify_solution_end, /* Incremental solution verify end. */
1761 &problem_LR, /* Dependent problem. */
1762 sizeof (struct df_live_bb_info),/* Size of entry of block_info array. */
1763 TV_DF_LIVE, /* Timing variable. */
1764 false /* Reset blocks on dropping out of blocks_to_analyze. */
1768 /* Create a new DATAFLOW instance and add it to an existing instance
1769 of DF. The returned structure is what is used to get at the
1770 solution. */
1772 void
1773 df_live_add_problem (void)
1775 df_add_problem (&problem_LIVE);
1776 /* These will be initialized when df_scan_blocks processes each
1777 block. */
1778 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1782 /* Set all of the blocks as dirty. This needs to be done if this
1783 problem is added after all of the insns have been scanned. */
1785 void
1786 df_live_set_all_dirty (void)
1788 basic_block bb;
1789 FOR_ALL_BB_FN (bb, cfun)
1790 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1791 bb->index);
1795 /* Verify that all of the lr related info is consistent and
1796 correct. */
1798 void
1799 df_live_verify_transfer_functions (void)
1801 basic_block bb;
1802 bitmap_head saved_gen;
1803 bitmap_head saved_kill;
1804 bitmap_head all_blocks;
1806 if (!df)
1807 return;
1809 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1810 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1811 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1813 df_grow_insn_info ();
1815 FOR_ALL_BB_FN (bb, cfun)
1817 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1818 bitmap_set_bit (&all_blocks, bb->index);
1820 if (bb_info)
1822 /* Make a copy of the transfer functions and then compute
1823 new ones to see if the transfer functions have
1824 changed. */
1825 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1826 bb->index))
1828 bitmap_copy (&saved_gen, &bb_info->gen);
1829 bitmap_copy (&saved_kill, &bb_info->kill);
1830 bitmap_clear (&bb_info->gen);
1831 bitmap_clear (&bb_info->kill);
1833 df_live_bb_local_compute (bb->index);
1834 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1835 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1838 else
1840 /* If we do not have basic block info, the block must be in
1841 the list of dirty blocks or else some one has added a
1842 block behind our backs. */
1843 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1844 bb->index));
1846 /* Make sure no one created a block without following
1847 procedures. */
1848 gcc_assert (df_scan_get_bb_info (bb->index));
1851 /* Make sure there are no dirty bits in blocks that have been deleted. */
1852 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1853 &all_blocks));
1854 bitmap_clear (&saved_gen);
1855 bitmap_clear (&saved_kill);
1856 bitmap_clear (&all_blocks);
1859 /*----------------------------------------------------------------------------
1860 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1862 Link either the defs to the uses and / or the uses to the defs.
1864 These problems are set up like the other dataflow problems so that
1865 they nicely fit into the framework. They are much simpler and only
1866 involve a single traversal of instructions and an examination of
1867 the reaching defs information (the dependent problem).
1868 ----------------------------------------------------------------------------*/
1870 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1872 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1874 struct df_link *
1875 df_chain_create (df_ref src, df_ref dst)
1877 struct df_link *head = DF_REF_CHAIN (src);
1878 struct df_link *link = df_chain->block_pool->allocate ();
1880 DF_REF_CHAIN (src) = link;
1881 link->next = head;
1882 link->ref = dst;
1883 return link;
1887 /* Delete any du or ud chains that start at REF and point to
1888 TARGET. */
1889 static void
1890 df_chain_unlink_1 (df_ref ref, df_ref target)
1892 struct df_link *chain = DF_REF_CHAIN (ref);
1893 struct df_link *prev = NULL;
1895 while (chain)
1897 if (chain->ref == target)
1899 if (prev)
1900 prev->next = chain->next;
1901 else
1902 DF_REF_CHAIN (ref) = chain->next;
1903 df_chain->block_pool->remove (chain);
1904 return;
1906 prev = chain;
1907 chain = chain->next;
1912 /* Delete a du or ud chain that leave or point to REF. */
1914 void
1915 df_chain_unlink (df_ref ref)
1917 struct df_link *chain = DF_REF_CHAIN (ref);
1918 while (chain)
1920 struct df_link *next = chain->next;
1921 /* Delete the other side if it exists. */
1922 df_chain_unlink_1 (chain->ref, ref);
1923 df_chain->block_pool->remove (chain);
1924 chain = next;
1926 DF_REF_CHAIN (ref) = NULL;
1930 /* Copy the du or ud chain starting at FROM_REF and attach it to
1931 TO_REF. */
1933 void
1934 df_chain_copy (df_ref to_ref,
1935 struct df_link *from_ref)
1937 while (from_ref)
1939 df_chain_create (to_ref, from_ref->ref);
1940 from_ref = from_ref->next;
1945 /* Remove this problem from the stack of dataflow problems. */
1947 static void
1948 df_chain_remove_problem (void)
1950 bitmap_iterator bi;
1951 unsigned int bb_index;
1953 /* Wholesale destruction of the old chains. */
1954 if (df_chain->block_pool)
1955 delete df_chain->block_pool;
1957 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1959 rtx_insn *insn;
1960 df_ref def, use;
1961 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1963 if (df_chain_problem_p (DF_DU_CHAIN))
1964 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
1965 DF_REF_CHAIN (def) = NULL;
1966 if (df_chain_problem_p (DF_UD_CHAIN))
1967 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
1968 DF_REF_CHAIN (use) = NULL;
1970 FOR_BB_INSNS (bb, insn)
1971 if (INSN_P (insn))
1973 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
1974 if (df_chain_problem_p (DF_DU_CHAIN))
1975 FOR_EACH_INSN_INFO_DEF (def, insn_info)
1976 DF_REF_CHAIN (def) = NULL;
1977 if (df_chain_problem_p (DF_UD_CHAIN))
1979 FOR_EACH_INSN_INFO_USE (use, insn_info)
1980 DF_REF_CHAIN (use) = NULL;
1981 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
1982 DF_REF_CHAIN (use) = NULL;
1987 bitmap_clear (df_chain->out_of_date_transfer_functions);
1988 df_chain->block_pool = NULL;
1992 /* Remove the chain problem completely. */
1994 static void
1995 df_chain_fully_remove_problem (void)
1997 df_chain_remove_problem ();
1998 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
1999 free (df_chain);
2003 /* Create def-use or use-def chains. */
2005 static void
2006 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2008 df_chain_remove_problem ();
2009 df_chain->block_pool = new pool_allocator<df_link> ("df_chain_block pool",
2010 50);
2011 df_chain->optional_p = true;
2015 /* Reset all of the chains when the set of basic blocks changes. */
2017 static void
2018 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2020 df_chain_remove_problem ();
2024 /* Create the chains for a list of USEs. */
2026 static void
2027 df_chain_create_bb_process_use (bitmap local_rd,
2028 df_ref use,
2029 int top_flag)
2031 bitmap_iterator bi;
2032 unsigned int def_index;
2034 for (; use; use = DF_REF_NEXT_LOC (use))
2036 unsigned int uregno = DF_REF_REGNO (use);
2037 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2038 || (uregno >= FIRST_PSEUDO_REGISTER))
2040 /* Do not want to go through this for an uninitialized var. */
2041 int count = DF_DEFS_COUNT (uregno);
2042 if (count)
2044 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2046 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2047 unsigned int last_index = first_index + count - 1;
2049 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2051 df_ref def;
2052 if (def_index > last_index)
2053 break;
2055 def = DF_DEFS_GET (def_index);
2056 if (df_chain_problem_p (DF_DU_CHAIN))
2057 df_chain_create (def, use);
2058 if (df_chain_problem_p (DF_UD_CHAIN))
2059 df_chain_create (use, def);
2068 /* Create chains from reaching defs bitmaps for basic block BB. */
2070 static void
2071 df_chain_create_bb (unsigned int bb_index)
2073 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2074 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2075 rtx_insn *insn;
2076 bitmap_head cpy;
2078 bitmap_initialize (&cpy, &bitmap_default_obstack);
2079 bitmap_copy (&cpy, &bb_info->in);
2080 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2082 /* Since we are going forwards, process the artificial uses first
2083 then the artificial defs second. */
2085 #ifdef EH_USES
2086 /* Create the chains for the artificial uses from the EH_USES at the
2087 beginning of the block. */
2089 /* Artificials are only hard regs. */
2090 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2091 df_chain_create_bb_process_use (&cpy,
2092 df_get_artificial_uses (bb->index),
2093 DF_REF_AT_TOP);
2094 #endif
2096 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2098 /* Process the regular instructions next. */
2099 FOR_BB_INSNS (bb, insn)
2100 if (INSN_P (insn))
2102 unsigned int uid = INSN_UID (insn);
2104 /* First scan the uses and link them up with the defs that remain
2105 in the cpy vector. */
2106 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2107 if (df->changeable_flags & DF_EQ_NOTES)
2108 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2110 /* Since we are going forwards, process the defs second. */
2111 df_rd_simulate_one_insn (bb, insn, &cpy);
2114 /* Create the chains for the artificial uses of the hard registers
2115 at the end of the block. */
2116 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2117 df_chain_create_bb_process_use (&cpy,
2118 df_get_artificial_uses (bb->index),
2121 bitmap_clear (&cpy);
2124 /* Create def-use chains from reaching use bitmaps for basic blocks
2125 in BLOCKS. */
2127 static void
2128 df_chain_finalize (bitmap all_blocks)
2130 unsigned int bb_index;
2131 bitmap_iterator bi;
2133 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2135 df_chain_create_bb (bb_index);
2140 /* Free all storage associated with the problem. */
2142 static void
2143 df_chain_free (void)
2145 delete df_chain->block_pool;
2146 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2147 free (df_chain);
2151 /* Debugging info. */
2153 static void
2154 df_chain_bb_dump (basic_block bb, FILE *file, bool top)
2156 /* Artificials are only hard regs. */
2157 if (df->changeable_flags & DF_NO_HARD_REGS)
2158 return;
2159 if (df_chain_problem_p (DF_UD_CHAIN))
2161 df_ref use;
2163 fprintf (file,
2164 ";; UD chains for artificial uses at %s\n",
2165 top ? "top" : "bottom");
2166 FOR_EACH_ARTIFICIAL_USE (use, bb->index)
2167 if ((top && (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2168 || (!top && !(DF_REF_FLAGS (use) & DF_REF_AT_TOP)))
2170 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2171 df_chain_dump (DF_REF_CHAIN (use), file);
2172 fprintf (file, "\n");
2175 if (df_chain_problem_p (DF_DU_CHAIN))
2177 df_ref def;
2179 fprintf (file,
2180 ";; DU chains for artificial defs at %s\n",
2181 top ? "top" : "bottom");
2182 FOR_EACH_ARTIFICIAL_DEF (def, bb->index)
2183 if ((top && (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
2184 || (!top && !(DF_REF_FLAGS (def) & DF_REF_AT_TOP)))
2186 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2187 df_chain_dump (DF_REF_CHAIN (def), file);
2188 fprintf (file, "\n");
2193 static void
2194 df_chain_top_dump (basic_block bb, FILE *file)
2196 df_chain_bb_dump (bb, file, /*top=*/true);
2199 static void
2200 df_chain_bottom_dump (basic_block bb, FILE *file)
2202 df_chain_bb_dump (bb, file, /*top=*/false);
2205 static void
2206 df_chain_insn_top_dump (const rtx_insn *insn, FILE *file)
2208 if (df_chain_problem_p (DF_UD_CHAIN) && INSN_P (insn))
2210 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2211 df_ref use;
2213 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2214 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2215 FOR_EACH_INSN_INFO_USE (use, insn_info)
2216 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2217 || !(df->changeable_flags & DF_NO_HARD_REGS))
2219 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2220 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2221 fprintf (file, "read/write ");
2222 df_chain_dump (DF_REF_CHAIN (use), file);
2223 fprintf (file, "\n");
2225 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
2226 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2227 || !(df->changeable_flags & DF_NO_HARD_REGS))
2229 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2230 df_chain_dump (DF_REF_CHAIN (use), file);
2231 fprintf (file, "\n");
2236 static void
2237 df_chain_insn_bottom_dump (const rtx_insn *insn, FILE *file)
2239 if (df_chain_problem_p (DF_DU_CHAIN) && INSN_P (insn))
2241 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2242 df_ref def;
2243 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2244 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2245 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2246 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def))
2247 || !(df->changeable_flags & DF_NO_HARD_REGS))
2249 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2250 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2251 fprintf (file, "read/write ");
2252 df_chain_dump (DF_REF_CHAIN (def), file);
2253 fprintf (file, "\n");
2255 fprintf (file, "\n");
2259 static struct df_problem problem_CHAIN =
2261 DF_CHAIN, /* Problem id. */
2262 DF_NONE, /* Direction. */
2263 df_chain_alloc, /* Allocate the problem specific data. */
2264 df_chain_reset, /* Reset global information. */
2265 NULL, /* Free basic block info. */
2266 NULL, /* Local compute function. */
2267 NULL, /* Init the solution specific data. */
2268 NULL, /* Iterative solver. */
2269 NULL, /* Confluence operator 0. */
2270 NULL, /* Confluence operator n. */
2271 NULL, /* Transfer function. */
2272 df_chain_finalize, /* Finalize function. */
2273 df_chain_free, /* Free all of the problem information. */
2274 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2275 NULL, /* Debugging. */
2276 df_chain_top_dump, /* Debugging start block. */
2277 df_chain_bottom_dump, /* Debugging end block. */
2278 df_chain_insn_top_dump, /* Debugging start insn. */
2279 df_chain_insn_bottom_dump, /* Debugging end insn. */
2280 NULL, /* Incremental solution verify start. */
2281 NULL, /* Incremental solution verify end. */
2282 &problem_RD, /* Dependent problem. */
2283 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
2284 TV_DF_CHAIN, /* Timing variable. */
2285 false /* Reset blocks on dropping out of blocks_to_analyze. */
2289 /* Create a new DATAFLOW instance and add it to an existing instance
2290 of DF. The returned structure is what is used to get at the
2291 solution. */
2293 void
2294 df_chain_add_problem (unsigned int chain_flags)
2296 df_add_problem (&problem_CHAIN);
2297 df_chain->local_flags = chain_flags;
2298 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2301 #undef df_chain_problem_p
2304 /*----------------------------------------------------------------------------
2305 WORD LEVEL LIVE REGISTERS
2307 Find the locations in the function where any use of a pseudo can
2308 reach in the backwards direction. In and out bitvectors are built
2309 for each basic block. We only track pseudo registers that have a
2310 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2311 contain two bits corresponding to each of the subwords.
2313 ----------------------------------------------------------------------------*/
2315 /* Private data used to verify the solution for this problem. */
2316 struct df_word_lr_problem_data
2318 /* An obstack for the bitmaps we need for this problem. */
2319 bitmap_obstack word_lr_bitmaps;
2323 /* Free basic block info. */
2325 static void
2326 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2327 void *vbb_info)
2329 struct df_word_lr_bb_info *bb_info = (struct df_word_lr_bb_info *) vbb_info;
2330 if (bb_info)
2332 bitmap_clear (&bb_info->use);
2333 bitmap_clear (&bb_info->def);
2334 bitmap_clear (&bb_info->in);
2335 bitmap_clear (&bb_info->out);
2340 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2341 not touched unless the block is new. */
2343 static void
2344 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2346 unsigned int bb_index;
2347 bitmap_iterator bi;
2348 basic_block bb;
2349 struct df_word_lr_problem_data *problem_data
2350 = XNEW (struct df_word_lr_problem_data);
2352 df_word_lr->problem_data = problem_data;
2354 df_grow_bb_info (df_word_lr);
2356 /* Create the mapping from regnos to slots. This does not change
2357 unless the problem is destroyed and recreated. In particular, if
2358 we end up deleting the only insn that used a subreg, we do not
2359 want to redo the mapping because this would invalidate everything
2360 else. */
2362 bitmap_obstack_initialize (&problem_data->word_lr_bitmaps);
2364 FOR_EACH_BB_FN (bb, cfun)
2365 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, bb->index);
2367 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2368 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2370 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2372 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2374 /* When bitmaps are already initialized, just clear them. */
2375 if (bb_info->use.obstack)
2377 bitmap_clear (&bb_info->def);
2378 bitmap_clear (&bb_info->use);
2380 else
2382 bitmap_initialize (&bb_info->use, &problem_data->word_lr_bitmaps);
2383 bitmap_initialize (&bb_info->def, &problem_data->word_lr_bitmaps);
2384 bitmap_initialize (&bb_info->in, &problem_data->word_lr_bitmaps);
2385 bitmap_initialize (&bb_info->out, &problem_data->word_lr_bitmaps);
2389 df_word_lr->optional_p = true;
2393 /* Reset the global solution for recalculation. */
2395 static void
2396 df_word_lr_reset (bitmap all_blocks)
2398 unsigned int bb_index;
2399 bitmap_iterator bi;
2401 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2403 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2404 gcc_assert (bb_info);
2405 bitmap_clear (&bb_info->in);
2406 bitmap_clear (&bb_info->out);
2410 /* Examine REF, and if it is for a reg we're interested in, set or
2411 clear the bits corresponding to its subwords from the bitmap
2412 according to IS_SET. LIVE is the bitmap we should update. We do
2413 not track hard regs or pseudos of any size other than 2 *
2414 UNITS_PER_WORD.
2415 We return true if we changed the bitmap, or if we encountered a register
2416 we're not tracking. */
2418 bool
2419 df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
2421 rtx orig_reg = DF_REF_REG (ref);
2422 rtx reg = orig_reg;
2423 machine_mode reg_mode;
2424 unsigned regno;
2425 /* Left at -1 for whole accesses. */
2426 int which_subword = -1;
2427 bool changed = false;
2429 if (GET_CODE (reg) == SUBREG)
2430 reg = SUBREG_REG (orig_reg);
2431 regno = REGNO (reg);
2432 reg_mode = GET_MODE (reg);
2433 if (regno < FIRST_PSEUDO_REGISTER
2434 || GET_MODE_SIZE (reg_mode) != 2 * UNITS_PER_WORD)
2435 return true;
2437 if (GET_CODE (orig_reg) == SUBREG
2438 && df_read_modify_subreg_p (orig_reg))
2440 gcc_assert (DF_REF_FLAGS_IS_SET (ref, DF_REF_PARTIAL));
2441 if (subreg_lowpart_p (orig_reg))
2442 which_subword = 0;
2443 else
2444 which_subword = 1;
2446 if (is_set)
2448 if (which_subword != 1)
2449 changed |= bitmap_set_bit (live, regno * 2);
2450 if (which_subword != 0)
2451 changed |= bitmap_set_bit (live, regno * 2 + 1);
2453 else
2455 if (which_subword != 1)
2456 changed |= bitmap_clear_bit (live, regno * 2);
2457 if (which_subword != 0)
2458 changed |= bitmap_clear_bit (live, regno * 2 + 1);
2460 return changed;
2463 /* Compute local live register info for basic block BB. */
2465 static void
2466 df_word_lr_bb_local_compute (unsigned int bb_index)
2468 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2469 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2470 rtx_insn *insn;
2471 df_ref def, use;
2473 /* Ensure that artificial refs don't contain references to pseudos. */
2474 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
2475 gcc_assert (DF_REF_REGNO (def) < FIRST_PSEUDO_REGISTER);
2477 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
2478 gcc_assert (DF_REF_REGNO (use) < FIRST_PSEUDO_REGISTER);
2480 FOR_BB_INSNS_REVERSE (bb, insn)
2482 if (!NONDEBUG_INSN_P (insn))
2483 continue;
2485 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2486 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2487 /* If the def is to only part of the reg, it does
2488 not kill the other defs that reach here. */
2489 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2491 df_word_lr_mark_ref (def, true, &bb_info->def);
2492 df_word_lr_mark_ref (def, false, &bb_info->use);
2494 FOR_EACH_INSN_INFO_USE (use, insn_info)
2495 df_word_lr_mark_ref (use, true, &bb_info->use);
2500 /* Compute local live register info for each basic block within BLOCKS. */
2502 static void
2503 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2505 unsigned int bb_index;
2506 bitmap_iterator bi;
2508 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2510 if (bb_index == EXIT_BLOCK)
2512 unsigned regno;
2513 bitmap_iterator bi;
2514 EXECUTE_IF_SET_IN_BITMAP (df->exit_block_uses, FIRST_PSEUDO_REGISTER,
2515 regno, bi)
2516 gcc_unreachable ();
2518 else
2519 df_word_lr_bb_local_compute (bb_index);
2522 bitmap_clear (df_word_lr->out_of_date_transfer_functions);
2526 /* Initialize the solution vectors. */
2528 static void
2529 df_word_lr_init (bitmap all_blocks)
2531 unsigned int bb_index;
2532 bitmap_iterator bi;
2534 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2536 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2537 bitmap_copy (&bb_info->in, &bb_info->use);
2538 bitmap_clear (&bb_info->out);
2543 /* Confluence function that ignores fake edges. */
2545 static bool
2546 df_word_lr_confluence_n (edge e)
2548 bitmap op1 = &df_word_lr_get_bb_info (e->src->index)->out;
2549 bitmap op2 = &df_word_lr_get_bb_info (e->dest->index)->in;
2551 return bitmap_ior_into (op1, op2);
2555 /* Transfer function. */
2557 static bool
2558 df_word_lr_transfer_function (int bb_index)
2560 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2561 bitmap in = &bb_info->in;
2562 bitmap out = &bb_info->out;
2563 bitmap use = &bb_info->use;
2564 bitmap def = &bb_info->def;
2566 return bitmap_ior_and_compl (in, use, out, def);
2570 /* Free all storage associated with the problem. */
2572 static void
2573 df_word_lr_free (void)
2575 struct df_word_lr_problem_data *problem_data
2576 = (struct df_word_lr_problem_data *)df_word_lr->problem_data;
2578 if (df_word_lr->block_info)
2580 df_word_lr->block_info_size = 0;
2581 free (df_word_lr->block_info);
2582 df_word_lr->block_info = NULL;
2585 BITMAP_FREE (df_word_lr->out_of_date_transfer_functions);
2586 bitmap_obstack_release (&problem_data->word_lr_bitmaps);
2587 free (problem_data);
2588 free (df_word_lr);
2592 /* Debugging info at top of bb. */
2594 static void
2595 df_word_lr_top_dump (basic_block bb, FILE *file)
2597 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2598 if (!bb_info)
2599 return;
2601 fprintf (file, ";; blr in \t");
2602 df_print_word_regset (file, &bb_info->in);
2603 fprintf (file, ";; blr use \t");
2604 df_print_word_regset (file, &bb_info->use);
2605 fprintf (file, ";; blr def \t");
2606 df_print_word_regset (file, &bb_info->def);
2610 /* Debugging info at bottom of bb. */
2612 static void
2613 df_word_lr_bottom_dump (basic_block bb, FILE *file)
2615 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2616 if (!bb_info)
2617 return;
2619 fprintf (file, ";; blr out \t");
2620 df_print_word_regset (file, &bb_info->out);
2624 /* All of the information associated with every instance of the problem. */
2626 static struct df_problem problem_WORD_LR =
2628 DF_WORD_LR, /* Problem id. */
2629 DF_BACKWARD, /* Direction. */
2630 df_word_lr_alloc, /* Allocate the problem specific data. */
2631 df_word_lr_reset, /* Reset global information. */
2632 df_word_lr_free_bb_info, /* Free basic block info. */
2633 df_word_lr_local_compute, /* Local compute function. */
2634 df_word_lr_init, /* Init the solution specific data. */
2635 df_worklist_dataflow, /* Worklist solver. */
2636 NULL, /* Confluence operator 0. */
2637 df_word_lr_confluence_n, /* Confluence operator n. */
2638 df_word_lr_transfer_function, /* Transfer function. */
2639 NULL, /* Finalize function. */
2640 df_word_lr_free, /* Free all of the problem information. */
2641 df_word_lr_free, /* Remove this problem from the stack of dataflow problems. */
2642 NULL, /* Debugging. */
2643 df_word_lr_top_dump, /* Debugging start block. */
2644 df_word_lr_bottom_dump, /* Debugging end block. */
2645 NULL, /* Debugging start insn. */
2646 NULL, /* Debugging end insn. */
2647 NULL, /* Incremental solution verify start. */
2648 NULL, /* Incremental solution verify end. */
2649 NULL, /* Dependent problem. */
2650 sizeof (struct df_word_lr_bb_info),/* Size of entry of block_info array. */
2651 TV_DF_WORD_LR, /* Timing variable. */
2652 false /* Reset blocks on dropping out of blocks_to_analyze. */
2656 /* Create a new DATAFLOW instance and add it to an existing instance
2657 of DF. The returned structure is what is used to get at the
2658 solution. */
2660 void
2661 df_word_lr_add_problem (void)
2663 df_add_problem (&problem_WORD_LR);
2664 /* These will be initialized when df_scan_blocks processes each
2665 block. */
2666 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2670 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2671 any bits, which is used by the caller to determine whether a set is
2672 necessary. We also return true if there are other reasons not to delete
2673 an insn. */
2675 bool
2676 df_word_lr_simulate_defs (rtx_insn *insn, bitmap live)
2678 bool changed = false;
2679 df_ref def;
2681 FOR_EACH_INSN_DEF (def, insn)
2682 if (DF_REF_FLAGS (def) & DF_REF_CONDITIONAL)
2683 changed = true;
2684 else
2685 changed |= df_word_lr_mark_ref (def, false, live);
2686 return changed;
2690 /* Simulate the effects of the uses of INSN on LIVE. */
2692 void
2693 df_word_lr_simulate_uses (rtx_insn *insn, bitmap live)
2695 df_ref use;
2697 FOR_EACH_INSN_USE (use, insn)
2698 df_word_lr_mark_ref (use, true, live);
2701 /*----------------------------------------------------------------------------
2702 This problem computes REG_DEAD and REG_UNUSED notes.
2703 ----------------------------------------------------------------------------*/
2705 static void
2706 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2708 df_note->optional_p = true;
2711 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2712 static void
2713 df_print_note (const char *prefix, rtx_insn *insn, rtx note)
2715 if (dump_file)
2717 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2718 print_rtl (dump_file, note);
2719 fprintf (dump_file, "\n");
2724 /* After reg-stack, the x86 floating point stack regs are difficult to
2725 analyze because of all of the pushes, pops and rotations. Thus, we
2726 just leave the notes alone. */
2728 #ifdef STACK_REGS
2729 static inline bool
2730 df_ignore_stack_reg (int regno)
2732 return regstack_completed
2733 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2735 #else
2736 static inline bool
2737 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2739 return false;
2741 #endif
2744 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
2746 static void
2747 df_remove_dead_and_unused_notes (rtx_insn *insn)
2749 rtx *pprev = &REG_NOTES (insn);
2750 rtx link = *pprev;
2752 while (link)
2754 switch (REG_NOTE_KIND (link))
2756 case REG_DEAD:
2757 /* After reg-stack, we need to ignore any unused notes
2758 for the stack registers. */
2759 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2761 pprev = &XEXP (link, 1);
2762 link = *pprev;
2764 else
2766 rtx next = XEXP (link, 1);
2767 if (REG_DEAD_DEBUGGING)
2768 df_print_note ("deleting: ", insn, link);
2769 free_EXPR_LIST_node (link);
2770 *pprev = link = next;
2772 break;
2774 case REG_UNUSED:
2775 /* After reg-stack, we need to ignore any unused notes
2776 for the stack registers. */
2777 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2779 pprev = &XEXP (link, 1);
2780 link = *pprev;
2782 else
2784 rtx next = XEXP (link, 1);
2785 if (REG_DEAD_DEBUGGING)
2786 df_print_note ("deleting: ", insn, link);
2787 free_EXPR_LIST_node (link);
2788 *pprev = link = next;
2790 break;
2792 default:
2793 pprev = &XEXP (link, 1);
2794 link = *pprev;
2795 break;
2800 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2801 as the bitmap of currently live registers. */
2803 static void
2804 df_remove_dead_eq_notes (rtx_insn *insn, bitmap live)
2806 rtx *pprev = &REG_NOTES (insn);
2807 rtx link = *pprev;
2809 while (link)
2811 switch (REG_NOTE_KIND (link))
2813 case REG_EQUAL:
2814 case REG_EQUIV:
2816 /* Remove the notes that refer to dead registers. As we have at most
2817 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2818 so we need to purge the complete EQ_USES vector when removing
2819 the note using df_notes_rescan. */
2820 df_ref use;
2821 bool deleted = false;
2823 FOR_EACH_INSN_EQ_USE (use, insn)
2824 if (DF_REF_REGNO (use) > FIRST_PSEUDO_REGISTER
2825 && DF_REF_LOC (use)
2826 && (DF_REF_FLAGS (use) & DF_REF_IN_NOTE)
2827 && !bitmap_bit_p (live, DF_REF_REGNO (use))
2828 && loc_mentioned_in_p (DF_REF_LOC (use), XEXP (link, 0)))
2830 deleted = true;
2831 break;
2833 if (deleted)
2835 rtx next;
2836 if (REG_DEAD_DEBUGGING)
2837 df_print_note ("deleting: ", insn, link);
2838 next = XEXP (link, 1);
2839 free_EXPR_LIST_node (link);
2840 *pprev = link = next;
2841 df_notes_rescan (insn);
2843 else
2845 pprev = &XEXP (link, 1);
2846 link = *pprev;
2848 break;
2851 default:
2852 pprev = &XEXP (link, 1);
2853 link = *pprev;
2854 break;
2859 /* Set a NOTE_TYPE note for REG in INSN. */
2861 static inline void
2862 df_set_note (enum reg_note note_type, rtx_insn *insn, rtx reg)
2864 gcc_checking_assert (!DEBUG_INSN_P (insn));
2865 add_reg_note (insn, note_type, reg);
2868 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2869 arguments. Return true if the register value described by MWS's
2870 mw_reg is known to be completely unused, and if mw_reg can therefore
2871 be used in a REG_UNUSED note. */
2873 static bool
2874 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2875 bitmap live, bitmap artificial_uses)
2877 unsigned int r;
2879 /* If MWS describes a partial reference, create REG_UNUSED notes for
2880 individual hard registers. */
2881 if (mws->flags & DF_REF_PARTIAL)
2882 return false;
2884 /* Likewise if some part of the register is used. */
2885 for (r = mws->start_regno; r <= mws->end_regno; r++)
2886 if (bitmap_bit_p (live, r)
2887 || bitmap_bit_p (artificial_uses, r))
2888 return false;
2890 gcc_assert (REG_P (mws->mw_reg));
2891 return true;
2895 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2896 based on the bits in LIVE. Do not generate notes for registers in
2897 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2898 not generated if the reg is both read and written by the
2899 instruction.
2902 static void
2903 df_set_unused_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
2904 bitmap live, bitmap do_not_gen,
2905 bitmap artificial_uses,
2906 struct dead_debug_local *debug)
2908 unsigned int r;
2910 if (REG_DEAD_DEBUGGING && dump_file)
2911 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2912 mws->start_regno, mws->end_regno);
2914 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2916 unsigned int regno = mws->start_regno;
2917 df_set_note (REG_UNUSED, insn, mws->mw_reg);
2918 dead_debug_insert_temp (debug, regno, insn, DEBUG_TEMP_AFTER_WITH_REG);
2920 if (REG_DEAD_DEBUGGING)
2921 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2923 bitmap_set_bit (do_not_gen, regno);
2924 /* Only do this if the value is totally dead. */
2926 else
2927 for (r = mws->start_regno; r <= mws->end_regno; r++)
2929 if (!bitmap_bit_p (live, r)
2930 && !bitmap_bit_p (artificial_uses, r))
2932 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
2933 dead_debug_insert_temp (debug, r, insn, DEBUG_TEMP_AFTER_WITH_REG);
2934 if (REG_DEAD_DEBUGGING)
2935 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2937 bitmap_set_bit (do_not_gen, r);
2942 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2943 arguments. Return true if the register value described by MWS's
2944 mw_reg is known to be completely dead, and if mw_reg can therefore
2945 be used in a REG_DEAD note. */
2947 static bool
2948 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2949 bitmap live, bitmap artificial_uses,
2950 bitmap do_not_gen)
2952 unsigned int r;
2954 /* If MWS describes a partial reference, create REG_DEAD notes for
2955 individual hard registers. */
2956 if (mws->flags & DF_REF_PARTIAL)
2957 return false;
2959 /* Likewise if some part of the register is not dead. */
2960 for (r = mws->start_regno; r <= mws->end_regno; r++)
2961 if (bitmap_bit_p (live, r)
2962 || bitmap_bit_p (artificial_uses, r)
2963 || bitmap_bit_p (do_not_gen, r))
2964 return false;
2966 gcc_assert (REG_P (mws->mw_reg));
2967 return true;
2970 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2971 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2972 from being set if the instruction both reads and writes the
2973 register. */
2975 static void
2976 df_set_dead_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
2977 bitmap live, bitmap do_not_gen,
2978 bitmap artificial_uses, bool *added_notes_p)
2980 unsigned int r;
2981 bool is_debug = *added_notes_p;
2983 *added_notes_p = false;
2985 if (REG_DEAD_DEBUGGING && dump_file)
2987 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2988 mws->start_regno, mws->end_regno);
2989 df_print_regset (dump_file, do_not_gen);
2990 fprintf (dump_file, " live =");
2991 df_print_regset (dump_file, live);
2992 fprintf (dump_file, " artificial uses =");
2993 df_print_regset (dump_file, artificial_uses);
2996 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2998 if (is_debug)
3000 *added_notes_p = true;
3001 return;
3003 /* Add a dead note for the entire multi word register. */
3004 df_set_note (REG_DEAD, insn, mws->mw_reg);
3005 if (REG_DEAD_DEBUGGING)
3006 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3008 else
3010 for (r = mws->start_regno; r <= mws->end_regno; r++)
3011 if (!bitmap_bit_p (live, r)
3012 && !bitmap_bit_p (artificial_uses, r)
3013 && !bitmap_bit_p (do_not_gen, r))
3015 if (is_debug)
3017 *added_notes_p = true;
3018 return;
3020 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
3021 if (REG_DEAD_DEBUGGING)
3022 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3025 return;
3029 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3030 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3032 static void
3033 df_create_unused_note (rtx_insn *insn, df_ref def,
3034 bitmap live, bitmap artificial_uses,
3035 struct dead_debug_local *debug)
3037 unsigned int dregno = DF_REF_REGNO (def);
3039 if (REG_DEAD_DEBUGGING && dump_file)
3041 fprintf (dump_file, " regular looking at def ");
3042 df_ref_debug (def, dump_file);
3045 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3046 || bitmap_bit_p (live, dregno)
3047 || bitmap_bit_p (artificial_uses, dregno)
3048 || df_ignore_stack_reg (dregno)))
3050 rtx reg = (DF_REF_LOC (def))
3051 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3052 df_set_note (REG_UNUSED, insn, reg);
3053 dead_debug_insert_temp (debug, dregno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3054 if (REG_DEAD_DEBUGGING)
3055 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3058 return;
3062 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3063 info: lifetime, bb, and number of defs and uses for basic block
3064 BB. The three bitvectors are scratch regs used here. */
3066 static void
3067 df_note_bb_compute (unsigned int bb_index,
3068 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3070 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
3071 rtx_insn *insn;
3072 df_ref def, use;
3073 struct dead_debug_local debug;
3075 dead_debug_local_init (&debug, NULL, NULL);
3077 bitmap_copy (live, df_get_live_out (bb));
3078 bitmap_clear (artificial_uses);
3080 if (REG_DEAD_DEBUGGING && dump_file)
3082 fprintf (dump_file, "live at bottom ");
3083 df_print_regset (dump_file, live);
3086 /* Process the artificial defs and uses at the bottom of the block
3087 to begin processing. */
3088 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3090 if (REG_DEAD_DEBUGGING && dump_file)
3091 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3093 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3094 bitmap_clear_bit (live, DF_REF_REGNO (def));
3097 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3098 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3100 unsigned int regno = DF_REF_REGNO (use);
3101 bitmap_set_bit (live, regno);
3103 /* Notes are not generated for any of the artificial registers
3104 at the bottom of the block. */
3105 bitmap_set_bit (artificial_uses, regno);
3108 if (REG_DEAD_DEBUGGING && dump_file)
3110 fprintf (dump_file, "live before artificials out ");
3111 df_print_regset (dump_file, live);
3114 FOR_BB_INSNS_REVERSE (bb, insn)
3116 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3117 df_mw_hardreg *mw;
3118 int debug_insn;
3120 if (!INSN_P (insn))
3121 continue;
3123 debug_insn = DEBUG_INSN_P (insn);
3125 bitmap_clear (do_not_gen);
3126 df_remove_dead_and_unused_notes (insn);
3128 /* Process the defs. */
3129 if (CALL_P (insn))
3131 if (REG_DEAD_DEBUGGING && dump_file)
3133 fprintf (dump_file, "processing call %d\n live =",
3134 INSN_UID (insn));
3135 df_print_regset (dump_file, live);
3138 /* We only care about real sets for calls. Clobbers cannot
3139 be depended on to really die. */
3140 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3141 if ((DF_MWS_REG_DEF_P (mw))
3142 && !df_ignore_stack_reg (mw->start_regno))
3143 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3144 artificial_uses, &debug);
3146 /* All of the defs except the return value are some sort of
3147 clobber. This code is for the return. */
3148 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3150 unsigned int dregno = DF_REF_REGNO (def);
3151 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3153 df_create_unused_note (insn,
3154 def, live, artificial_uses, &debug);
3155 bitmap_set_bit (do_not_gen, dregno);
3158 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3159 bitmap_clear_bit (live, dregno);
3162 else
3164 /* Regular insn. */
3165 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3166 if (DF_MWS_REG_DEF_P (mw))
3167 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3168 artificial_uses, &debug);
3170 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3172 unsigned int dregno = DF_REF_REGNO (def);
3173 df_create_unused_note (insn,
3174 def, live, artificial_uses, &debug);
3176 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3177 bitmap_set_bit (do_not_gen, dregno);
3179 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3180 bitmap_clear_bit (live, dregno);
3184 /* Process the uses. */
3185 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3186 if (DF_MWS_REG_USE_P (mw)
3187 && !df_ignore_stack_reg (mw->start_regno))
3189 bool really_add_notes = debug_insn != 0;
3191 df_set_dead_notes_for_mw (insn, mw, live, do_not_gen,
3192 artificial_uses,
3193 &really_add_notes);
3195 if (really_add_notes)
3196 debug_insn = -1;
3199 FOR_EACH_INSN_INFO_USE (use, insn_info)
3201 unsigned int uregno = DF_REF_REGNO (use);
3203 if (REG_DEAD_DEBUGGING && dump_file && !debug_insn)
3205 fprintf (dump_file, " regular looking at use ");
3206 df_ref_debug (use, dump_file);
3209 if (!bitmap_bit_p (live, uregno))
3211 if (debug_insn)
3213 if (debug_insn > 0)
3215 /* We won't add REG_UNUSED or REG_DEAD notes for
3216 these, so we don't have to mess with them in
3217 debug insns either. */
3218 if (!bitmap_bit_p (artificial_uses, uregno)
3219 && !df_ignore_stack_reg (uregno))
3220 dead_debug_add (&debug, use, uregno);
3221 continue;
3223 break;
3225 else
3226 dead_debug_insert_temp (&debug, uregno, insn,
3227 DEBUG_TEMP_BEFORE_WITH_REG);
3229 if ( (!(DF_REF_FLAGS (use)
3230 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3231 && (!bitmap_bit_p (do_not_gen, uregno))
3232 && (!bitmap_bit_p (artificial_uses, uregno))
3233 && (!df_ignore_stack_reg (uregno)))
3235 rtx reg = (DF_REF_LOC (use))
3236 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3237 df_set_note (REG_DEAD, insn, reg);
3239 if (REG_DEAD_DEBUGGING)
3240 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3242 /* This register is now live. */
3243 bitmap_set_bit (live, uregno);
3247 df_remove_dead_eq_notes (insn, live);
3249 if (debug_insn == -1)
3251 /* ??? We could probably do better here, replacing dead
3252 registers with their definitions. */
3253 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3254 df_insn_rescan_debug_internal (insn);
3258 dead_debug_local_finish (&debug, NULL);
3262 /* Compute register info: lifetime, bb, and number of defs and uses. */
3263 static void
3264 df_note_compute (bitmap all_blocks)
3266 unsigned int bb_index;
3267 bitmap_iterator bi;
3268 bitmap_head live, do_not_gen, artificial_uses;
3270 bitmap_initialize (&live, &df_bitmap_obstack);
3271 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3272 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3274 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3276 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3277 pseudos in debug insns because we don't always (re)visit blocks
3278 with death points after visiting dead uses. Even changing this
3279 loop to postorder would still leave room for visiting a death
3280 point before visiting a subsequent debug use. */
3281 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3284 bitmap_clear (&live);
3285 bitmap_clear (&do_not_gen);
3286 bitmap_clear (&artificial_uses);
3290 /* Free all storage associated with the problem. */
3292 static void
3293 df_note_free (void)
3295 free (df_note);
3299 /* All of the information associated every instance of the problem. */
3301 static struct df_problem problem_NOTE =
3303 DF_NOTE, /* Problem id. */
3304 DF_NONE, /* Direction. */
3305 df_note_alloc, /* Allocate the problem specific data. */
3306 NULL, /* Reset global information. */
3307 NULL, /* Free basic block info. */
3308 df_note_compute, /* Local compute function. */
3309 NULL, /* Init the solution specific data. */
3310 NULL, /* Iterative solver. */
3311 NULL, /* Confluence operator 0. */
3312 NULL, /* Confluence operator n. */
3313 NULL, /* Transfer function. */
3314 NULL, /* Finalize function. */
3315 df_note_free, /* Free all of the problem information. */
3316 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3317 NULL, /* Debugging. */
3318 NULL, /* Debugging start block. */
3319 NULL, /* Debugging end block. */
3320 NULL, /* Debugging start insn. */
3321 NULL, /* Debugging end insn. */
3322 NULL, /* Incremental solution verify start. */
3323 NULL, /* Incremental solution verify end. */
3324 &problem_LR, /* Dependent problem. */
3325 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
3326 TV_DF_NOTE, /* Timing variable. */
3327 false /* Reset blocks on dropping out of blocks_to_analyze. */
3331 /* Create a new DATAFLOW instance and add it to an existing instance
3332 of DF. The returned structure is what is used to get at the
3333 solution. */
3335 void
3336 df_note_add_problem (void)
3338 df_add_problem (&problem_NOTE);
3344 /*----------------------------------------------------------------------------
3345 Functions for simulating the effects of single insns.
3347 You can either simulate in the forwards direction, starting from
3348 the top of a block or the backwards direction from the end of the
3349 block. If you go backwards, defs are examined first to clear bits,
3350 then uses are examined to set bits. If you go forwards, defs are
3351 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3352 are examined to clear bits. In either case, the result of examining
3353 a def can be undone (respectively by a use or a REG_UNUSED note).
3355 If you start at the top of the block, use one of DF_LIVE_IN or
3356 DF_LR_IN. If you start at the bottom of the block use one of
3357 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3358 THEY WILL BE DESTROYED.
3359 ----------------------------------------------------------------------------*/
3362 /* Find the set of DEFs for INSN. */
3364 void
3365 df_simulate_find_defs (rtx_insn *insn, bitmap defs)
3367 df_ref def;
3369 FOR_EACH_INSN_DEF (def, insn)
3370 bitmap_set_bit (defs, DF_REF_REGNO (def));
3373 /* Find the set of uses for INSN. This includes partial defs. */
3375 static void
3376 df_simulate_find_uses (rtx_insn *insn, bitmap uses)
3378 df_ref def, use;
3379 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3381 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3382 if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3383 bitmap_set_bit (uses, DF_REF_REGNO (def));
3384 FOR_EACH_INSN_INFO_USE (use, insn_info)
3385 bitmap_set_bit (uses, DF_REF_REGNO (use));
3388 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3390 void
3391 df_simulate_find_noclobber_defs (rtx_insn *insn, bitmap defs)
3393 df_ref def;
3395 FOR_EACH_INSN_DEF (def, insn)
3396 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3397 bitmap_set_bit (defs, DF_REF_REGNO (def));
3401 /* Simulate the effects of the defs of INSN on LIVE. */
3403 void
3404 df_simulate_defs (rtx_insn *insn, bitmap live)
3406 df_ref def;
3408 FOR_EACH_INSN_DEF (def, insn)
3410 unsigned int dregno = DF_REF_REGNO (def);
3412 /* If the def is to only part of the reg, it does
3413 not kill the other defs that reach here. */
3414 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3415 bitmap_clear_bit (live, dregno);
3420 /* Simulate the effects of the uses of INSN on LIVE. */
3422 void
3423 df_simulate_uses (rtx_insn *insn, bitmap live)
3425 df_ref use;
3427 if (DEBUG_INSN_P (insn))
3428 return;
3430 FOR_EACH_INSN_USE (use, insn)
3431 /* Add use to set of uses in this BB. */
3432 bitmap_set_bit (live, DF_REF_REGNO (use));
3436 /* Add back the always live regs in BB to LIVE. */
3438 static inline void
3439 df_simulate_fixup_sets (basic_block bb, bitmap live)
3441 /* These regs are considered always live so if they end up dying
3442 because of some def, we need to bring the back again. */
3443 if (bb_has_eh_pred (bb))
3444 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3445 else
3446 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3450 /*----------------------------------------------------------------------------
3451 The following three functions are used only for BACKWARDS scanning:
3452 i.e. they process the defs before the uses.
3454 df_simulate_initialize_backwards should be called first with a
3455 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3456 df_simulate_one_insn_backwards should be called for each insn in
3457 the block, starting with the last one. Finally,
3458 df_simulate_finalize_backwards can be called to get a new value
3459 of the sets at the top of the block (this is rarely used).
3460 ----------------------------------------------------------------------------*/
3462 /* Apply the artificial uses and defs at the end of BB in a backwards
3463 direction. */
3465 void
3466 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3468 df_ref def, use;
3469 int bb_index = bb->index;
3471 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3472 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3473 bitmap_clear_bit (live, DF_REF_REGNO (def));
3475 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3476 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3477 bitmap_set_bit (live, DF_REF_REGNO (use));
3481 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3483 void
3484 df_simulate_one_insn_backwards (basic_block bb, rtx_insn *insn, bitmap live)
3486 if (!NONDEBUG_INSN_P (insn))
3487 return;
3489 df_simulate_defs (insn, live);
3490 df_simulate_uses (insn, live);
3491 df_simulate_fixup_sets (bb, live);
3495 /* Apply the artificial uses and defs at the top of BB in a backwards
3496 direction. */
3498 void
3499 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3501 df_ref def;
3502 #ifdef EH_USES
3503 df_ref use;
3504 #endif
3505 int bb_index = bb->index;
3507 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3508 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3509 bitmap_clear_bit (live, DF_REF_REGNO (def));
3511 #ifdef EH_USES
3512 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3513 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3514 bitmap_set_bit (live, DF_REF_REGNO (use));
3515 #endif
3517 /*----------------------------------------------------------------------------
3518 The following three functions are used only for FORWARDS scanning:
3519 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3520 Thus it is important to add the DF_NOTES problem to the stack of
3521 problems computed before using these functions.
3523 df_simulate_initialize_forwards should be called first with a
3524 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3525 df_simulate_one_insn_forwards should be called for each insn in
3526 the block, starting with the first one.
3527 ----------------------------------------------------------------------------*/
3529 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3530 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3531 defs live. */
3533 void
3534 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3536 df_ref def;
3537 int bb_index = bb->index;
3539 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3540 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3541 bitmap_set_bit (live, DF_REF_REGNO (def));
3544 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3546 void
3547 df_simulate_one_insn_forwards (basic_block bb, rtx_insn *insn, bitmap live)
3549 rtx link;
3550 if (! INSN_P (insn))
3551 return;
3553 /* Make sure that DF_NOTE really is an active df problem. */
3554 gcc_assert (df_note);
3556 /* Note that this is the opposite as how the problem is defined, because
3557 in the LR problem defs _kill_ liveness. However, they do so backwards,
3558 while here the scan is performed forwards! So, first assume that the
3559 def is live, and if this is not true REG_UNUSED notes will rectify the
3560 situation. */
3561 df_simulate_find_noclobber_defs (insn, live);
3563 /* Clear all of the registers that go dead. */
3564 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3566 switch (REG_NOTE_KIND (link))
3568 case REG_DEAD:
3569 case REG_UNUSED:
3571 rtx reg = XEXP (link, 0);
3572 bitmap_clear_range (live, REGNO (reg), REG_NREGS (reg));
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 /* Return an OR of MEMREF_NORMAL or MEMREF_VOLATILE for the MEMs in X. */
3589 static int
3590 find_memory (rtx_insn *insn)
3592 int flags = 0;
3593 subrtx_iterator::array_type array;
3594 FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
3596 const_rtx x = *iter;
3597 if (GET_CODE (x) == ASM_OPERANDS && MEM_VOLATILE_P (x))
3598 flags |= MEMREF_VOLATILE;
3599 else if (MEM_P (x))
3601 if (MEM_VOLATILE_P (x))
3602 flags |= MEMREF_VOLATILE;
3603 else if (!MEM_READONLY_P (x))
3604 flags |= MEMREF_NORMAL;
3607 return flags;
3610 /* A subroutine of can_move_insns_across_p called through note_stores.
3611 DATA points to an integer in which we set either the bit for
3612 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3613 of either kind. */
3615 static void
3616 find_memory_stores (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
3617 void *data ATTRIBUTE_UNUSED)
3619 int *pflags = (int *)data;
3620 if (GET_CODE (x) == SUBREG)
3621 x = XEXP (x, 0);
3622 /* Treat stores to SP as stores to memory, this will prevent problems
3623 when there are references to the stack frame. */
3624 if (x == stack_pointer_rtx)
3625 *pflags |= MEMREF_VOLATILE;
3626 if (!MEM_P (x))
3627 return;
3628 *pflags |= MEM_VOLATILE_P (x) ? MEMREF_VOLATILE : MEMREF_NORMAL;
3631 /* Scan BB backwards, using df_simulate functions to keep track of
3632 lifetimes, up to insn POINT. The result is stored in LIVE. */
3634 void
3635 simulate_backwards_to_point (basic_block bb, regset live, rtx point)
3637 rtx_insn *insn;
3638 bitmap_copy (live, df_get_live_out (bb));
3639 df_simulate_initialize_backwards (bb, live);
3641 /* Scan and update life information until we reach the point we're
3642 interested in. */
3643 for (insn = BB_END (bb); insn != point; insn = PREV_INSN (insn))
3644 df_simulate_one_insn_backwards (bb, insn, live);
3647 /* Return true if it is safe to move a group of insns, described by
3648 the range FROM to TO, backwards across another group of insns,
3649 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3650 are no insns between ACROSS_TO and FROM, but they may be in
3651 different basic blocks; MERGE_BB is the block from which the
3652 insns will be moved. The caller must pass in a regset MERGE_LIVE
3653 which specifies the registers live after TO.
3655 This function may be called in one of two cases: either we try to
3656 move identical instructions from all successor blocks into their
3657 predecessor, or we try to move from only one successor block. If
3658 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3659 the second case. It should contain a set of registers live at the
3660 end of ACROSS_TO which must not be clobbered by moving the insns.
3661 In that case, we're also more careful about moving memory references
3662 and trapping insns.
3664 We return false if it is not safe to move the entire group, but it
3665 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3666 is set to point at the last moveable insn in such a case. */
3668 bool
3669 can_move_insns_across (rtx_insn *from, rtx_insn *to,
3670 rtx_insn *across_from, rtx_insn *across_to,
3671 basic_block merge_bb, regset merge_live,
3672 regset other_branch_live, rtx_insn **pmove_upto)
3674 rtx_insn *insn, *next, *max_to;
3675 bitmap merge_set, merge_use, local_merge_live;
3676 bitmap test_set, test_use;
3677 unsigned i, fail = 0;
3678 bitmap_iterator bi;
3679 int memrefs_in_across = 0;
3680 int mem_sets_in_across = 0;
3681 bool trapping_insns_in_across = false;
3683 if (pmove_upto != NULL)
3684 *pmove_upto = NULL;
3686 /* Find real bounds, ignoring debug insns. */
3687 while (!NONDEBUG_INSN_P (from) && from != to)
3688 from = NEXT_INSN (from);
3689 while (!NONDEBUG_INSN_P (to) && from != to)
3690 to = PREV_INSN (to);
3692 for (insn = across_to; ; insn = next)
3694 if (CALL_P (insn))
3696 if (RTL_CONST_OR_PURE_CALL_P (insn))
3697 /* Pure functions can read from memory. Const functions can
3698 read from arguments that the ABI has forced onto the stack.
3699 Neither sort of read can be volatile. */
3700 memrefs_in_across |= MEMREF_NORMAL;
3701 else
3703 memrefs_in_across |= MEMREF_VOLATILE;
3704 mem_sets_in_across |= MEMREF_VOLATILE;
3707 if (NONDEBUG_INSN_P (insn))
3709 if (volatile_insn_p (PATTERN (insn)))
3710 return false;
3711 memrefs_in_across |= find_memory (insn);
3712 note_stores (PATTERN (insn), find_memory_stores,
3713 &mem_sets_in_across);
3714 /* This is used just to find sets of the stack pointer. */
3715 memrefs_in_across |= mem_sets_in_across;
3716 trapping_insns_in_across |= may_trap_p (PATTERN (insn));
3718 next = PREV_INSN (insn);
3719 if (insn == across_from)
3720 break;
3723 /* Collect:
3724 MERGE_SET = set of registers set in MERGE_BB
3725 MERGE_USE = set of registers used in MERGE_BB and live at its top
3726 MERGE_LIVE = set of registers live at the point inside the MERGE
3727 range that we've reached during scanning
3728 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3729 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3730 and live before ACROSS_FROM. */
3732 merge_set = BITMAP_ALLOC (&reg_obstack);
3733 merge_use = BITMAP_ALLOC (&reg_obstack);
3734 local_merge_live = BITMAP_ALLOC (&reg_obstack);
3735 test_set = BITMAP_ALLOC (&reg_obstack);
3736 test_use = BITMAP_ALLOC (&reg_obstack);
3738 /* Compute the set of registers set and used in the ACROSS range. */
3739 if (other_branch_live != NULL)
3740 bitmap_copy (test_use, other_branch_live);
3741 df_simulate_initialize_backwards (merge_bb, test_use);
3742 for (insn = across_to; ; insn = next)
3744 if (NONDEBUG_INSN_P (insn))
3746 df_simulate_find_defs (insn, test_set);
3747 df_simulate_defs (insn, test_use);
3748 df_simulate_uses (insn, test_use);
3750 next = PREV_INSN (insn);
3751 if (insn == across_from)
3752 break;
3755 /* Compute an upper bound for the amount of insns moved, by finding
3756 the first insn in MERGE that sets a register in TEST_USE, or uses
3757 a register in TEST_SET. We also check for calls, trapping operations,
3758 and memory references. */
3759 max_to = NULL;
3760 for (insn = from; ; insn = next)
3762 if (CALL_P (insn))
3763 break;
3764 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
3765 break;
3766 if (NONDEBUG_INSN_P (insn))
3768 if (may_trap_or_fault_p (PATTERN (insn))
3769 && (trapping_insns_in_across
3770 || other_branch_live != NULL
3771 || volatile_insn_p (PATTERN (insn))))
3772 break;
3774 /* We cannot move memory stores past each other, or move memory
3775 reads past stores, at least not without tracking them and
3776 calling true_dependence on every pair.
3778 If there is no other branch and no memory references or
3779 sets in the ACROSS range, we can move memory references
3780 freely, even volatile ones.
3782 Otherwise, the rules are as follows: volatile memory
3783 references and stores can't be moved at all, and any type
3784 of memory reference can't be moved if there are volatile
3785 accesses or stores in the ACROSS range. That leaves
3786 normal reads, which can be moved, as the trapping case is
3787 dealt with elsewhere. */
3788 if (other_branch_live != NULL || memrefs_in_across != 0)
3790 int mem_ref_flags = 0;
3791 int mem_set_flags = 0;
3792 note_stores (PATTERN (insn), find_memory_stores, &mem_set_flags);
3793 mem_ref_flags = find_memory (insn);
3794 /* Catch sets of the stack pointer. */
3795 mem_ref_flags |= mem_set_flags;
3797 if ((mem_ref_flags | mem_set_flags) & MEMREF_VOLATILE)
3798 break;
3799 if ((memrefs_in_across & MEMREF_VOLATILE) && mem_ref_flags != 0)
3800 break;
3801 if (mem_set_flags != 0
3802 || (mem_sets_in_across != 0 && mem_ref_flags != 0))
3803 break;
3805 df_simulate_find_uses (insn, merge_use);
3806 /* We're only interested in uses which use a value live at
3807 the top, not one previously set in this block. */
3808 bitmap_and_compl_into (merge_use, merge_set);
3809 df_simulate_find_defs (insn, merge_set);
3810 if (bitmap_intersect_p (merge_set, test_use)
3811 || bitmap_intersect_p (merge_use, test_set))
3812 break;
3813 if (!HAVE_cc0 || !sets_cc0_p (insn))
3814 max_to = insn;
3816 next = NEXT_INSN (insn);
3817 if (insn == to)
3818 break;
3820 if (max_to != to)
3821 fail = 1;
3823 if (max_to == NULL_RTX || (fail && pmove_upto == NULL))
3824 goto out;
3826 /* Now, lower this upper bound by also taking into account that
3827 a range of insns moved across ACROSS must not leave a register
3828 live at the end that will be clobbered in ACROSS. We need to
3829 find a point where TEST_SET & LIVE == 0.
3831 Insns in the MERGE range that set registers which are also set
3832 in the ACROSS range may still be moved as long as we also move
3833 later insns which use the results of the set, and make the
3834 register dead again. This is verified by the condition stated
3835 above. We only need to test it for registers that are set in
3836 the moved region.
3838 MERGE_LIVE is provided by the caller and holds live registers after
3839 TO. */
3840 bitmap_copy (local_merge_live, merge_live);
3841 for (insn = to; insn != max_to; insn = PREV_INSN (insn))
3842 df_simulate_one_insn_backwards (merge_bb, insn, local_merge_live);
3844 /* We're not interested in registers that aren't set in the moved
3845 region at all. */
3846 bitmap_and_into (local_merge_live, merge_set);
3847 for (;;)
3849 if (NONDEBUG_INSN_P (insn))
3851 if (!bitmap_intersect_p (test_set, local_merge_live)
3852 && (!HAVE_cc0 || !sets_cc0_p (insn)))
3854 max_to = insn;
3855 break;
3858 df_simulate_one_insn_backwards (merge_bb, insn,
3859 local_merge_live);
3861 if (insn == from)
3863 fail = 1;
3864 goto out;
3866 insn = PREV_INSN (insn);
3869 if (max_to != to)
3870 fail = 1;
3872 if (pmove_upto)
3873 *pmove_upto = max_to;
3875 /* For small register class machines, don't lengthen lifetimes of
3876 hard registers before reload. */
3877 if (! reload_completed
3878 && targetm.small_register_classes_for_mode_p (VOIDmode))
3880 EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
3882 if (i < FIRST_PSEUDO_REGISTER
3883 && ! fixed_regs[i]
3884 && ! global_regs[i])
3886 fail = 1;
3887 break;
3892 out:
3893 BITMAP_FREE (merge_set);
3894 BITMAP_FREE (merge_use);
3895 BITMAP_FREE (local_merge_live);
3896 BITMAP_FREE (test_set);
3897 BITMAP_FREE (test_use);
3899 return !fail;
3903 /*----------------------------------------------------------------------------
3904 MULTIPLE DEFINITIONS
3906 Find the locations in the function reached by multiple definition sites
3907 for a live pseudo. In and out bitvectors are built for each basic
3908 block. They are restricted for efficiency to live registers.
3910 The gen and kill sets for the problem are obvious. Together they
3911 include all defined registers in a basic block; the gen set includes
3912 registers where a partial or conditional or may-clobber definition is
3913 last in the BB, while the kill set includes registers with a complete
3914 definition coming last. However, the computation of the dataflow
3915 itself is interesting.
3917 The idea behind it comes from SSA form's iterated dominance frontier
3918 criterion for inserting PHI functions. Just like in that case, we can use
3919 the dominance frontier to find places where multiple definitions meet;
3920 a register X defined in a basic block BB1 has multiple definitions in
3921 basic blocks in BB1's dominance frontier.
3923 So, the in-set of a basic block BB2 is not just the union of the
3924 out-sets of BB2's predecessors, but includes some more bits that come
3925 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3926 the previous paragraph). I called this set the init-set of BB2.
3928 (Note: I actually use the kill-set only to build the init-set.
3929 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3931 For example, if you have
3933 BB1 : r10 = 0
3934 r11 = 0
3935 if <...> goto BB2 else goto BB3;
3937 BB2 : r10 = 1
3938 r12 = 1
3939 goto BB3;
3941 BB3 :
3943 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3944 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3945 not need to iterate the dominance frontier, because we do not insert
3946 anything like PHI functions there! Instead, dataflow will take care of
3947 propagating the information to BB3's successors.
3948 ---------------------------------------------------------------------------*/
3950 /* Private data used to verify the solution for this problem. */
3951 struct df_md_problem_data
3953 /* An obstack for the bitmaps we need for this problem. */
3954 bitmap_obstack md_bitmaps;
3957 /* Scratch var used by transfer functions. This is used to do md analysis
3958 only for live registers. */
3959 static bitmap_head df_md_scratch;
3962 static void
3963 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3964 void *vbb_info)
3966 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
3967 if (bb_info)
3969 bitmap_clear (&bb_info->kill);
3970 bitmap_clear (&bb_info->gen);
3971 bitmap_clear (&bb_info->init);
3972 bitmap_clear (&bb_info->in);
3973 bitmap_clear (&bb_info->out);
3978 /* Allocate or reset bitmaps for DF_MD. The solution bits are
3979 not touched unless the block is new. */
3981 static void
3982 df_md_alloc (bitmap all_blocks)
3984 unsigned int bb_index;
3985 bitmap_iterator bi;
3986 struct df_md_problem_data *problem_data;
3988 df_grow_bb_info (df_md);
3989 if (df_md->problem_data)
3990 problem_data = (struct df_md_problem_data *) df_md->problem_data;
3991 else
3993 problem_data = XNEW (struct df_md_problem_data);
3994 df_md->problem_data = problem_data;
3995 bitmap_obstack_initialize (&problem_data->md_bitmaps);
3997 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
3999 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4001 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4002 /* When bitmaps are already initialized, just clear them. */
4003 if (bb_info->init.obstack)
4005 bitmap_clear (&bb_info->init);
4006 bitmap_clear (&bb_info->gen);
4007 bitmap_clear (&bb_info->kill);
4008 bitmap_clear (&bb_info->in);
4009 bitmap_clear (&bb_info->out);
4011 else
4013 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4014 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4015 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4016 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4017 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
4021 df_md->optional_p = true;
4024 /* Add the effect of the top artificial defs of BB to the multiple definitions
4025 bitmap LOCAL_MD. */
4027 void
4028 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4030 int bb_index = bb->index;
4031 df_ref def;
4032 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
4033 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4035 unsigned int dregno = DF_REF_REGNO (def);
4036 if (DF_REF_FLAGS (def)
4037 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4038 bitmap_set_bit (local_md, dregno);
4039 else
4040 bitmap_clear_bit (local_md, dregno);
4045 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4046 LOCAL_MD. */
4048 void
4049 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
4050 bitmap local_md)
4052 df_ref def;
4054 FOR_EACH_INSN_DEF (def, insn)
4056 unsigned int dregno = DF_REF_REGNO (def);
4057 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4058 || (dregno >= FIRST_PSEUDO_REGISTER))
4060 if (DF_REF_FLAGS (def)
4061 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4062 bitmap_set_bit (local_md, DF_REF_ID (def));
4063 else
4064 bitmap_clear_bit (local_md, DF_REF_ID (def));
4069 static void
4070 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
4071 df_ref def,
4072 int top_flag)
4074 bitmap_clear (&seen_in_insn);
4076 for (; def; def = DF_REF_NEXT_LOC (def))
4078 unsigned int dregno = DF_REF_REGNO (def);
4079 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4080 || (dregno >= FIRST_PSEUDO_REGISTER))
4081 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4083 if (!bitmap_bit_p (&seen_in_insn, dregno))
4085 if (DF_REF_FLAGS (def)
4086 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4088 bitmap_set_bit (&bb_info->gen, dregno);
4089 bitmap_clear_bit (&bb_info->kill, dregno);
4091 else
4093 /* When we find a clobber and a regular def,
4094 make sure the regular def wins. */
4095 bitmap_set_bit (&seen_in_insn, dregno);
4096 bitmap_set_bit (&bb_info->kill, dregno);
4097 bitmap_clear_bit (&bb_info->gen, dregno);
4105 /* Compute local multiple def info for basic block BB. */
4107 static void
4108 df_md_bb_local_compute (unsigned int bb_index)
4110 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4111 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4112 rtx_insn *insn;
4114 /* Artificials are only hard regs. */
4115 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4116 df_md_bb_local_compute_process_def (bb_info,
4117 df_get_artificial_defs (bb_index),
4118 DF_REF_AT_TOP);
4120 FOR_BB_INSNS (bb, insn)
4122 unsigned int uid = INSN_UID (insn);
4123 if (!INSN_P (insn))
4124 continue;
4126 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4129 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4130 df_md_bb_local_compute_process_def (bb_info,
4131 df_get_artificial_defs (bb_index),
4135 /* Compute local reaching def info for each basic block within BLOCKS. */
4137 static void
4138 df_md_local_compute (bitmap all_blocks)
4140 unsigned int bb_index, df_bb_index;
4141 bitmap_iterator bi1, bi2;
4142 basic_block bb;
4143 bitmap_head *frontiers;
4145 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4147 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4149 df_md_bb_local_compute (bb_index);
4152 bitmap_clear (&seen_in_insn);
4154 frontiers = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
4155 FOR_ALL_BB_FN (bb, cfun)
4156 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4158 compute_dominance_frontiers (frontiers);
4160 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4161 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4163 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4164 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4166 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, df_bb_index);
4167 if (bitmap_bit_p (all_blocks, df_bb_index))
4168 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4169 df_get_live_in (bb));
4173 FOR_ALL_BB_FN (bb, cfun)
4174 bitmap_clear (&frontiers[bb->index]);
4175 free (frontiers);
4179 /* Reset the global solution for recalculation. */
4181 static void
4182 df_md_reset (bitmap all_blocks)
4184 unsigned int bb_index;
4185 bitmap_iterator bi;
4187 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4189 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4190 gcc_assert (bb_info);
4191 bitmap_clear (&bb_info->in);
4192 bitmap_clear (&bb_info->out);
4196 static bool
4197 df_md_transfer_function (int bb_index)
4199 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4200 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4201 bitmap in = &bb_info->in;
4202 bitmap out = &bb_info->out;
4203 bitmap gen = &bb_info->gen;
4204 bitmap kill = &bb_info->kill;
4206 /* We need to use a scratch set here so that the value returned from this
4207 function invocation properly reflects whether the sets changed in a
4208 significant way; i.e. not just because the live set was anded in. */
4209 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4211 /* Multiple definitions of a register are not relevant if it is not
4212 live. Thus we trim the result to the places where it is live. */
4213 bitmap_and_into (in, df_get_live_in (bb));
4215 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4218 /* Initialize the solution bit vectors for problem. */
4220 static void
4221 df_md_init (bitmap all_blocks)
4223 unsigned int bb_index;
4224 bitmap_iterator bi;
4226 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4228 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4230 bitmap_copy (&bb_info->in, &bb_info->init);
4231 df_md_transfer_function (bb_index);
4235 static void
4236 df_md_confluence_0 (basic_block bb)
4238 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4239 bitmap_copy (&bb_info->in, &bb_info->init);
4242 /* In of target gets or of out of source. */
4244 static bool
4245 df_md_confluence_n (edge e)
4247 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4248 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4250 if (e->flags & EDGE_FAKE)
4251 return false;
4253 if (e->flags & EDGE_EH)
4254 return bitmap_ior_and_compl_into (op1, op2,
4255 regs_invalidated_by_call_regset);
4256 else
4257 return bitmap_ior_into (op1, op2);
4260 /* Free all storage associated with the problem. */
4262 static void
4263 df_md_free (void)
4265 struct df_md_problem_data *problem_data
4266 = (struct df_md_problem_data *) df_md->problem_data;
4268 bitmap_obstack_release (&problem_data->md_bitmaps);
4269 free (problem_data);
4270 df_md->problem_data = NULL;
4272 df_md->block_info_size = 0;
4273 free (df_md->block_info);
4274 df_md->block_info = NULL;
4275 free (df_md);
4279 /* Debugging info at top of bb. */
4281 static void
4282 df_md_top_dump (basic_block bb, FILE *file)
4284 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4285 if (!bb_info)
4286 return;
4288 fprintf (file, ";; md in \t");
4289 df_print_regset (file, &bb_info->in);
4290 fprintf (file, ";; md init \t");
4291 df_print_regset (file, &bb_info->init);
4292 fprintf (file, ";; md gen \t");
4293 df_print_regset (file, &bb_info->gen);
4294 fprintf (file, ";; md kill \t");
4295 df_print_regset (file, &bb_info->kill);
4298 /* Debugging info at bottom of bb. */
4300 static void
4301 df_md_bottom_dump (basic_block bb, FILE *file)
4303 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4304 if (!bb_info)
4305 return;
4307 fprintf (file, ";; md out \t");
4308 df_print_regset (file, &bb_info->out);
4311 static struct df_problem problem_MD =
4313 DF_MD, /* Problem id. */
4314 DF_FORWARD, /* Direction. */
4315 df_md_alloc, /* Allocate the problem specific data. */
4316 df_md_reset, /* Reset global information. */
4317 df_md_free_bb_info, /* Free basic block info. */
4318 df_md_local_compute, /* Local compute function. */
4319 df_md_init, /* Init the solution specific data. */
4320 df_worklist_dataflow, /* Worklist solver. */
4321 df_md_confluence_0, /* Confluence operator 0. */
4322 df_md_confluence_n, /* Confluence operator n. */
4323 df_md_transfer_function, /* Transfer function. */
4324 NULL, /* Finalize function. */
4325 df_md_free, /* Free all of the problem information. */
4326 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4327 NULL, /* Debugging. */
4328 df_md_top_dump, /* Debugging start block. */
4329 df_md_bottom_dump, /* Debugging end block. */
4330 NULL, /* Debugging start insn. */
4331 NULL, /* Debugging end insn. */
4332 NULL, /* Incremental solution verify start. */
4333 NULL, /* Incremental solution verify end. */
4334 NULL, /* Dependent problem. */
4335 sizeof (struct df_md_bb_info),/* Size of entry of block_info array. */
4336 TV_DF_MD, /* Timing variable. */
4337 false /* Reset blocks on dropping out of blocks_to_analyze. */
4340 /* Create a new MD instance and add it to the existing instance
4341 of DF. */
4343 void
4344 df_md_add_problem (void)
4346 df_add_problem (&problem_MD);