Fix bootstrap/PR63632
[official-gcc.git] / gcc / df-problems.c
blob389a6491d9930c5fcb468cc73727b8c046e96933
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2014 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tm_p.h"
30 #include "insn-config.h"
31 #include "recog.h"
32 #include "hashtab.h"
33 #include "hash-set.h"
34 #include "vec.h"
35 #include "machmode.h"
36 #include "hard-reg-set.h"
37 #include "input.h"
38 #include "function.h"
39 #include "regs.h"
40 #include "alloc-pool.h"
41 #include "flags.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 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
933 /* Pseudos with argument area equivalences may require
934 reloading via the argument pointer. */
935 if (fixed_regs[ARG_POINTER_REGNUM])
936 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
937 #endif
939 /* Any constant, or pseudo with constant equivalences, may
940 require reloading from memory using the pic register. */
941 if (pic_offset_table_regnum != INVALID_REGNUM
942 && fixed_regs[pic_offset_table_regnum])
943 bitmap_set_bit (&df->hardware_regs_used, pic_offset_table_regnum);
946 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
948 if (bb_index == EXIT_BLOCK)
950 /* The exit block is special for this problem and its bits are
951 computed from thin air. */
952 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
953 bitmap_copy (&bb_info->use, df->exit_block_uses);
955 else
956 df_lr_bb_local_compute (bb_index);
959 bitmap_clear (df_lr->out_of_date_transfer_functions);
963 /* Initialize the solution vectors. */
965 static void
966 df_lr_init (bitmap all_blocks)
968 unsigned int bb_index;
969 bitmap_iterator bi;
971 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
973 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
974 bitmap_copy (&bb_info->in, &bb_info->use);
975 bitmap_clear (&bb_info->out);
980 /* Confluence function that processes infinite loops. This might be a
981 noreturn function that throws. And even if it isn't, getting the
982 unwind info right helps debugging. */
983 static void
984 df_lr_confluence_0 (basic_block bb)
986 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
987 if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
988 bitmap_copy (op1, &df->hardware_regs_used);
992 /* Confluence function that ignores fake edges. */
994 static bool
995 df_lr_confluence_n (edge e)
997 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
998 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
999 bool changed = false;
1001 /* Call-clobbered registers die across exception and call edges. */
1002 /* ??? Abnormal call edges ignored for the moment, as this gets
1003 confused by sibling call edges, which crashes reg-stack. */
1004 if (e->flags & EDGE_EH)
1005 changed = bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
1006 else
1007 changed = bitmap_ior_into (op1, op2);
1009 changed |= bitmap_ior_into (op1, &df->hardware_regs_used);
1010 return changed;
1014 /* Transfer function. */
1016 static bool
1017 df_lr_transfer_function (int bb_index)
1019 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1020 bitmap in = &bb_info->in;
1021 bitmap out = &bb_info->out;
1022 bitmap use = &bb_info->use;
1023 bitmap def = &bb_info->def;
1025 return bitmap_ior_and_compl (in, use, out, def);
1029 /* Run the fast dce as a side effect of building LR. */
1031 static void
1032 df_lr_finalize (bitmap all_blocks)
1034 df_lr->solutions_dirty = false;
1035 if (df->changeable_flags & DF_LR_RUN_DCE)
1037 run_fast_df_dce ();
1039 /* If dce deletes some instructions, we need to recompute the lr
1040 solution before proceeding further. The problem is that fast
1041 dce is a pessimestic dataflow algorithm. In the case where
1042 it deletes a statement S inside of a loop, the uses inside of
1043 S may not be deleted from the dataflow solution because they
1044 were carried around the loop. While it is conservatively
1045 correct to leave these extra bits, the standards of df
1046 require that we maintain the best possible (least fixed
1047 point) solution. The only way to do that is to redo the
1048 iteration from the beginning. See PR35805 for an
1049 example. */
1050 if (df_lr->solutions_dirty)
1052 df_clear_flags (DF_LR_RUN_DCE);
1053 df_lr_alloc (all_blocks);
1054 df_lr_local_compute (all_blocks);
1055 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1056 df_lr_finalize (all_blocks);
1057 df_set_flags (DF_LR_RUN_DCE);
1063 /* Free all storage associated with the problem. */
1065 static void
1066 df_lr_free (void)
1068 struct df_lr_problem_data *problem_data
1069 = (struct df_lr_problem_data *) df_lr->problem_data;
1070 if (df_lr->block_info)
1073 df_lr->block_info_size = 0;
1074 free (df_lr->block_info);
1075 df_lr->block_info = NULL;
1076 bitmap_obstack_release (&problem_data->lr_bitmaps);
1077 free (df_lr->problem_data);
1078 df_lr->problem_data = NULL;
1081 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1082 free (df_lr);
1086 /* Debugging info at top of bb. */
1088 static void
1089 df_lr_top_dump (basic_block bb, FILE *file)
1091 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1092 struct df_lr_problem_data *problem_data;
1093 if (!bb_info)
1094 return;
1096 fprintf (file, ";; lr in \t");
1097 df_print_regset (file, &bb_info->in);
1098 if (df_lr->problem_data)
1100 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1101 if (problem_data->in)
1103 fprintf (file, ";; old in \t");
1104 df_print_regset (file, &problem_data->in[bb->index]);
1107 fprintf (file, ";; lr use \t");
1108 df_print_regset (file, &bb_info->use);
1109 fprintf (file, ";; lr def \t");
1110 df_print_regset (file, &bb_info->def);
1114 /* Debugging info at bottom of bb. */
1116 static void
1117 df_lr_bottom_dump (basic_block bb, FILE *file)
1119 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1120 struct df_lr_problem_data *problem_data;
1121 if (!bb_info)
1122 return;
1124 fprintf (file, ";; lr out \t");
1125 df_print_regset (file, &bb_info->out);
1126 if (df_lr->problem_data)
1128 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1129 if (problem_data->out)
1131 fprintf (file, ";; old out \t");
1132 df_print_regset (file, &problem_data->out[bb->index]);
1138 /* Build the datastructure to verify that the solution to the dataflow
1139 equations is not dirty. */
1141 static void
1142 df_lr_verify_solution_start (void)
1144 basic_block bb;
1145 struct df_lr_problem_data *problem_data;
1146 if (df_lr->solutions_dirty)
1147 return;
1149 /* Set it true so that the solution is recomputed. */
1150 df_lr->solutions_dirty = true;
1152 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1153 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1154 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1156 FOR_ALL_BB_FN (bb, cfun)
1158 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1159 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1160 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1161 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1166 /* Compare the saved datastructure and the new solution to the dataflow
1167 equations. */
1169 static void
1170 df_lr_verify_solution_end (void)
1172 struct df_lr_problem_data *problem_data;
1173 basic_block bb;
1175 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1177 if (!problem_data->out)
1178 return;
1180 if (df_lr->solutions_dirty)
1181 /* Do not check if the solution is still dirty. See the comment
1182 in df_lr_finalize for details. */
1183 df_lr->solutions_dirty = false;
1184 else
1185 FOR_ALL_BB_FN (bb, cfun)
1187 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1188 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1190 /*df_dump (stderr);*/
1191 gcc_unreachable ();
1195 /* Cannot delete them immediately because you may want to dump them
1196 if the comparison fails. */
1197 FOR_ALL_BB_FN (bb, cfun)
1199 bitmap_clear (&problem_data->in[bb->index]);
1200 bitmap_clear (&problem_data->out[bb->index]);
1203 free (problem_data->in);
1204 free (problem_data->out);
1205 problem_data->in = NULL;
1206 problem_data->out = NULL;
1210 /* All of the information associated with every instance of the problem. */
1212 static struct df_problem problem_LR =
1214 DF_LR, /* Problem id. */
1215 DF_BACKWARD, /* Direction. */
1216 df_lr_alloc, /* Allocate the problem specific data. */
1217 df_lr_reset, /* Reset global information. */
1218 df_lr_free_bb_info, /* Free basic block info. */
1219 df_lr_local_compute, /* Local compute function. */
1220 df_lr_init, /* Init the solution specific data. */
1221 df_worklist_dataflow, /* Worklist solver. */
1222 df_lr_confluence_0, /* Confluence operator 0. */
1223 df_lr_confluence_n, /* Confluence operator n. */
1224 df_lr_transfer_function, /* Transfer function. */
1225 df_lr_finalize, /* Finalize function. */
1226 df_lr_free, /* Free all of the problem information. */
1227 NULL, /* Remove this problem from the stack of dataflow problems. */
1228 NULL, /* Debugging. */
1229 df_lr_top_dump, /* Debugging start block. */
1230 df_lr_bottom_dump, /* Debugging end block. */
1231 NULL, /* Debugging start insn. */
1232 NULL, /* Debugging end insn. */
1233 df_lr_verify_solution_start,/* Incremental solution verify start. */
1234 df_lr_verify_solution_end, /* Incremental solution verify end. */
1235 NULL, /* Dependent problem. */
1236 sizeof (struct df_lr_bb_info),/* Size of entry of block_info array. */
1237 TV_DF_LR, /* Timing variable. */
1238 false /* Reset blocks on dropping out of blocks_to_analyze. */
1242 /* Create a new DATAFLOW instance and add it to an existing instance
1243 of DF. The returned structure is what is used to get at the
1244 solution. */
1246 void
1247 df_lr_add_problem (void)
1249 df_add_problem (&problem_LR);
1250 /* These will be initialized when df_scan_blocks processes each
1251 block. */
1252 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1256 /* Verify that all of the lr related info is consistent and
1257 correct. */
1259 void
1260 df_lr_verify_transfer_functions (void)
1262 basic_block bb;
1263 bitmap_head saved_def;
1264 bitmap_head saved_use;
1265 bitmap_head all_blocks;
1267 if (!df)
1268 return;
1270 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1271 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1272 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1274 FOR_ALL_BB_FN (bb, cfun)
1276 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1277 bitmap_set_bit (&all_blocks, bb->index);
1279 if (bb_info)
1281 /* Make a copy of the transfer functions and then compute
1282 new ones to see if the transfer functions have
1283 changed. */
1284 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1285 bb->index))
1287 bitmap_copy (&saved_def, &bb_info->def);
1288 bitmap_copy (&saved_use, &bb_info->use);
1289 bitmap_clear (&bb_info->def);
1290 bitmap_clear (&bb_info->use);
1292 df_lr_bb_local_compute (bb->index);
1293 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1294 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1297 else
1299 /* If we do not have basic block info, the block must be in
1300 the list of dirty blocks or else some one has added a
1301 block behind our backs. */
1302 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1303 bb->index));
1305 /* Make sure no one created a block without following
1306 procedures. */
1307 gcc_assert (df_scan_get_bb_info (bb->index));
1310 /* Make sure there are no dirty bits in blocks that have been deleted. */
1311 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1312 &all_blocks));
1314 bitmap_clear (&saved_def);
1315 bitmap_clear (&saved_use);
1316 bitmap_clear (&all_blocks);
1321 /*----------------------------------------------------------------------------
1322 LIVE AND MUST-INITIALIZED REGISTERS.
1324 This problem first computes the IN and OUT bitvectors for the
1325 must-initialized registers problems, which is a forward problem.
1326 It gives the set of registers for which we MUST have an available
1327 definition on any path from the entry block to the entry/exit of
1328 a basic block. Sets generate a definition, while clobbers kill
1329 a definition.
1331 In and out bitvectors are built for each basic block and are indexed by
1332 regnum (see df.h for details). In and out bitvectors in struct
1333 df_live_bb_info actually refers to the must-initialized problem;
1335 Then, the in and out sets for the LIVE problem itself are computed.
1336 These are the logical AND of the IN and OUT sets from the LR problem
1337 and the must-initialized problem.
1338 ----------------------------------------------------------------------------*/
1340 /* Private data used to verify the solution for this problem. */
1341 struct df_live_problem_data
1343 bitmap_head *in;
1344 bitmap_head *out;
1345 /* An obstack for the bitmaps we need for this problem. */
1346 bitmap_obstack live_bitmaps;
1349 /* Scratch var used by transfer functions. This is used to implement
1350 an optimization to reduce the amount of space used to compute the
1351 combined lr and live analysis. */
1352 static bitmap_head df_live_scratch;
1355 /* Free basic block info. */
1357 static void
1358 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1359 void *vbb_info)
1361 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1362 if (bb_info)
1364 bitmap_clear (&bb_info->gen);
1365 bitmap_clear (&bb_info->kill);
1366 bitmap_clear (&bb_info->in);
1367 bitmap_clear (&bb_info->out);
1372 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1373 not touched unless the block is new. */
1375 static void
1376 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1378 unsigned int bb_index;
1379 bitmap_iterator bi;
1380 struct df_live_problem_data *problem_data;
1382 if (df_live->problem_data)
1383 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1384 else
1386 problem_data = XNEW (struct df_live_problem_data);
1387 df_live->problem_data = problem_data;
1389 problem_data->out = NULL;
1390 problem_data->in = NULL;
1391 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1392 bitmap_initialize (&df_live_scratch, &problem_data->live_bitmaps);
1395 df_grow_bb_info (df_live);
1397 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1399 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1401 /* When bitmaps are already initialized, just clear them. */
1402 if (bb_info->kill.obstack)
1404 bitmap_clear (&bb_info->kill);
1405 bitmap_clear (&bb_info->gen);
1407 else
1409 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1410 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1411 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1412 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1415 df_live->optional_p = (optimize <= 1);
1419 /* Reset the global solution for recalculation. */
1421 static void
1422 df_live_reset (bitmap all_blocks)
1424 unsigned int bb_index;
1425 bitmap_iterator bi;
1427 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1429 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1430 gcc_assert (bb_info);
1431 bitmap_clear (&bb_info->in);
1432 bitmap_clear (&bb_info->out);
1437 /* Compute local uninitialized register info for basic block BB. */
1439 static void
1440 df_live_bb_local_compute (unsigned int bb_index)
1442 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1443 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1444 rtx_insn *insn;
1445 df_ref def;
1446 int luid = 0;
1448 FOR_BB_INSNS (bb, insn)
1450 unsigned int uid = INSN_UID (insn);
1451 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1453 /* Inserting labels does not always trigger the incremental
1454 rescanning. */
1455 if (!insn_info)
1457 gcc_assert (!INSN_P (insn));
1458 insn_info = df_insn_create_insn_record (insn);
1461 DF_INSN_INFO_LUID (insn_info) = luid;
1462 if (!INSN_P (insn))
1463 continue;
1465 luid++;
1466 FOR_EACH_INSN_INFO_DEF (def, insn_info)
1468 unsigned int regno = DF_REF_REGNO (def);
1470 if (DF_REF_FLAGS_IS_SET (def,
1471 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1472 /* All partial or conditional def
1473 seen are included in the gen set. */
1474 bitmap_set_bit (&bb_info->gen, regno);
1475 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1476 /* Only must clobbers for the entire reg destroy the
1477 value. */
1478 bitmap_set_bit (&bb_info->kill, regno);
1479 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1480 bitmap_set_bit (&bb_info->gen, regno);
1484 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
1485 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1489 /* Compute local uninitialized register info. */
1491 static void
1492 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1494 unsigned int bb_index;
1495 bitmap_iterator bi;
1497 df_grow_insn_info ();
1499 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1500 0, bb_index, bi)
1502 df_live_bb_local_compute (bb_index);
1505 bitmap_clear (df_live->out_of_date_transfer_functions);
1509 /* Initialize the solution vectors. */
1511 static void
1512 df_live_init (bitmap all_blocks)
1514 unsigned int bb_index;
1515 bitmap_iterator bi;
1517 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1519 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1520 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1522 /* No register may reach a location where it is not used. Thus
1523 we trim the rr result to the places where it is used. */
1524 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1525 bitmap_clear (&bb_info->in);
1529 /* Forward confluence function that ignores fake edges. */
1531 static bool
1532 df_live_confluence_n (edge e)
1534 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1535 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1537 if (e->flags & EDGE_FAKE)
1538 return false;
1540 return bitmap_ior_into (op1, op2);
1544 /* Transfer function for the forwards must-initialized problem. */
1546 static bool
1547 df_live_transfer_function (int bb_index)
1549 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1550 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1551 bitmap in = &bb_info->in;
1552 bitmap out = &bb_info->out;
1553 bitmap gen = &bb_info->gen;
1554 bitmap kill = &bb_info->kill;
1556 /* We need to use a scratch set here so that the value returned from this
1557 function invocation properly reflects whether the sets changed in a
1558 significant way; i.e. not just because the lr set was anded in. */
1559 bitmap_and (&df_live_scratch, gen, &bb_lr_info->out);
1560 /* No register may reach a location where it is not used. Thus
1561 we trim the rr result to the places where it is used. */
1562 bitmap_and_into (in, &bb_lr_info->in);
1564 return bitmap_ior_and_compl (out, &df_live_scratch, in, kill);
1568 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1570 static void
1571 df_live_finalize (bitmap all_blocks)
1574 if (df_live->solutions_dirty)
1576 bitmap_iterator bi;
1577 unsigned int bb_index;
1579 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1581 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1582 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1584 /* No register may reach a location where it is not used. Thus
1585 we trim the rr result to the places where it is used. */
1586 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1587 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1590 df_live->solutions_dirty = false;
1595 /* Free all storage associated with the problem. */
1597 static void
1598 df_live_free (void)
1600 struct df_live_problem_data *problem_data
1601 = (struct df_live_problem_data *) df_live->problem_data;
1602 if (df_live->block_info)
1604 df_live->block_info_size = 0;
1605 free (df_live->block_info);
1606 df_live->block_info = NULL;
1607 bitmap_clear (&df_live_scratch);
1608 bitmap_obstack_release (&problem_data->live_bitmaps);
1609 free (problem_data);
1610 df_live->problem_data = NULL;
1612 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1613 free (df_live);
1617 /* Debugging info at top of bb. */
1619 static void
1620 df_live_top_dump (basic_block bb, FILE *file)
1622 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1623 struct df_live_problem_data *problem_data;
1625 if (!bb_info)
1626 return;
1628 fprintf (file, ";; live in \t");
1629 df_print_regset (file, &bb_info->in);
1630 if (df_live->problem_data)
1632 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1633 if (problem_data->in)
1635 fprintf (file, ";; old in \t");
1636 df_print_regset (file, &problem_data->in[bb->index]);
1639 fprintf (file, ";; live gen \t");
1640 df_print_regset (file, &bb_info->gen);
1641 fprintf (file, ";; live kill\t");
1642 df_print_regset (file, &bb_info->kill);
1646 /* Debugging info at bottom of bb. */
1648 static void
1649 df_live_bottom_dump (basic_block bb, FILE *file)
1651 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1652 struct df_live_problem_data *problem_data;
1654 if (!bb_info)
1655 return;
1657 fprintf (file, ";; live out \t");
1658 df_print_regset (file, &bb_info->out);
1659 if (df_live->problem_data)
1661 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1662 if (problem_data->out)
1664 fprintf (file, ";; old out \t");
1665 df_print_regset (file, &problem_data->out[bb->index]);
1671 /* Build the datastructure to verify that the solution to the dataflow
1672 equations is not dirty. */
1674 static void
1675 df_live_verify_solution_start (void)
1677 basic_block bb;
1678 struct df_live_problem_data *problem_data;
1679 if (df_live->solutions_dirty)
1680 return;
1682 /* Set it true so that the solution is recomputed. */
1683 df_live->solutions_dirty = true;
1685 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1686 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1687 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1689 FOR_ALL_BB_FN (bb, cfun)
1691 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1692 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1693 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1694 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1699 /* Compare the saved datastructure and the new solution to the dataflow
1700 equations. */
1702 static void
1703 df_live_verify_solution_end (void)
1705 struct df_live_problem_data *problem_data;
1706 basic_block bb;
1708 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1709 if (!problem_data->out)
1710 return;
1712 FOR_ALL_BB_FN (bb, cfun)
1714 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1715 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1717 /*df_dump (stderr);*/
1718 gcc_unreachable ();
1722 /* Cannot delete them immediately because you may want to dump them
1723 if the comparison fails. */
1724 FOR_ALL_BB_FN (bb, cfun)
1726 bitmap_clear (&problem_data->in[bb->index]);
1727 bitmap_clear (&problem_data->out[bb->index]);
1730 free (problem_data->in);
1731 free (problem_data->out);
1732 free (problem_data);
1733 df_live->problem_data = NULL;
1737 /* All of the information associated with every instance of the problem. */
1739 static struct df_problem problem_LIVE =
1741 DF_LIVE, /* Problem id. */
1742 DF_FORWARD, /* Direction. */
1743 df_live_alloc, /* Allocate the problem specific data. */
1744 df_live_reset, /* Reset global information. */
1745 df_live_free_bb_info, /* Free basic block info. */
1746 df_live_local_compute, /* Local compute function. */
1747 df_live_init, /* Init the solution specific data. */
1748 df_worklist_dataflow, /* Worklist solver. */
1749 NULL, /* Confluence operator 0. */
1750 df_live_confluence_n, /* Confluence operator n. */
1751 df_live_transfer_function, /* Transfer function. */
1752 df_live_finalize, /* Finalize function. */
1753 df_live_free, /* Free all of the problem information. */
1754 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1755 NULL, /* Debugging. */
1756 df_live_top_dump, /* Debugging start block. */
1757 df_live_bottom_dump, /* Debugging end block. */
1758 NULL, /* Debugging start insn. */
1759 NULL, /* Debugging end insn. */
1760 df_live_verify_solution_start,/* Incremental solution verify start. */
1761 df_live_verify_solution_end, /* Incremental solution verify end. */
1762 &problem_LR, /* Dependent problem. */
1763 sizeof (struct df_live_bb_info),/* Size of entry of block_info array. */
1764 TV_DF_LIVE, /* Timing variable. */
1765 false /* Reset blocks on dropping out of blocks_to_analyze. */
1769 /* Create a new DATAFLOW instance and add it to an existing instance
1770 of DF. The returned structure is what is used to get at the
1771 solution. */
1773 void
1774 df_live_add_problem (void)
1776 df_add_problem (&problem_LIVE);
1777 /* These will be initialized when df_scan_blocks processes each
1778 block. */
1779 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1783 /* Set all of the blocks as dirty. This needs to be done if this
1784 problem is added after all of the insns have been scanned. */
1786 void
1787 df_live_set_all_dirty (void)
1789 basic_block bb;
1790 FOR_ALL_BB_FN (bb, cfun)
1791 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1792 bb->index);
1796 /* Verify that all of the lr related info is consistent and
1797 correct. */
1799 void
1800 df_live_verify_transfer_functions (void)
1802 basic_block bb;
1803 bitmap_head saved_gen;
1804 bitmap_head saved_kill;
1805 bitmap_head all_blocks;
1807 if (!df)
1808 return;
1810 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1811 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1812 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1814 df_grow_insn_info ();
1816 FOR_ALL_BB_FN (bb, cfun)
1818 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1819 bitmap_set_bit (&all_blocks, bb->index);
1821 if (bb_info)
1823 /* Make a copy of the transfer functions and then compute
1824 new ones to see if the transfer functions have
1825 changed. */
1826 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1827 bb->index))
1829 bitmap_copy (&saved_gen, &bb_info->gen);
1830 bitmap_copy (&saved_kill, &bb_info->kill);
1831 bitmap_clear (&bb_info->gen);
1832 bitmap_clear (&bb_info->kill);
1834 df_live_bb_local_compute (bb->index);
1835 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1836 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1839 else
1841 /* If we do not have basic block info, the block must be in
1842 the list of dirty blocks or else some one has added a
1843 block behind our backs. */
1844 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1845 bb->index));
1847 /* Make sure no one created a block without following
1848 procedures. */
1849 gcc_assert (df_scan_get_bb_info (bb->index));
1852 /* Make sure there are no dirty bits in blocks that have been deleted. */
1853 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1854 &all_blocks));
1855 bitmap_clear (&saved_gen);
1856 bitmap_clear (&saved_kill);
1857 bitmap_clear (&all_blocks);
1860 /*----------------------------------------------------------------------------
1861 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1863 Link either the defs to the uses and / or the uses to the defs.
1865 These problems are set up like the other dataflow problems so that
1866 they nicely fit into the framework. They are much simpler and only
1867 involve a single traversal of instructions and an examination of
1868 the reaching defs information (the dependent problem).
1869 ----------------------------------------------------------------------------*/
1871 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1873 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1875 struct df_link *
1876 df_chain_create (df_ref src, df_ref dst)
1878 struct df_link *head = DF_REF_CHAIN (src);
1879 struct df_link *link = (struct df_link *) pool_alloc (df_chain->block_pool);
1881 DF_REF_CHAIN (src) = link;
1882 link->next = head;
1883 link->ref = dst;
1884 return link;
1888 /* Delete any du or ud chains that start at REF and point to
1889 TARGET. */
1890 static void
1891 df_chain_unlink_1 (df_ref ref, df_ref target)
1893 struct df_link *chain = DF_REF_CHAIN (ref);
1894 struct df_link *prev = NULL;
1896 while (chain)
1898 if (chain->ref == target)
1900 if (prev)
1901 prev->next = chain->next;
1902 else
1903 DF_REF_CHAIN (ref) = chain->next;
1904 pool_free (df_chain->block_pool, chain);
1905 return;
1907 prev = chain;
1908 chain = chain->next;
1913 /* Delete a du or ud chain that leave or point to REF. */
1915 void
1916 df_chain_unlink (df_ref ref)
1918 struct df_link *chain = DF_REF_CHAIN (ref);
1919 while (chain)
1921 struct df_link *next = chain->next;
1922 /* Delete the other side if it exists. */
1923 df_chain_unlink_1 (chain->ref, ref);
1924 pool_free (df_chain->block_pool, chain);
1925 chain = next;
1927 DF_REF_CHAIN (ref) = NULL;
1931 /* Copy the du or ud chain starting at FROM_REF and attach it to
1932 TO_REF. */
1934 void
1935 df_chain_copy (df_ref to_ref,
1936 struct df_link *from_ref)
1938 while (from_ref)
1940 df_chain_create (to_ref, from_ref->ref);
1941 from_ref = from_ref->next;
1946 /* Remove this problem from the stack of dataflow problems. */
1948 static void
1949 df_chain_remove_problem (void)
1951 bitmap_iterator bi;
1952 unsigned int bb_index;
1954 /* Wholesale destruction of the old chains. */
1955 if (df_chain->block_pool)
1956 free_alloc_pool (df_chain->block_pool);
1958 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1960 rtx_insn *insn;
1961 df_ref def, use;
1962 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1964 if (df_chain_problem_p (DF_DU_CHAIN))
1965 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
1966 DF_REF_CHAIN (def) = NULL;
1967 if (df_chain_problem_p (DF_UD_CHAIN))
1968 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
1969 DF_REF_CHAIN (use) = NULL;
1971 FOR_BB_INSNS (bb, insn)
1972 if (INSN_P (insn))
1974 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
1975 if (df_chain_problem_p (DF_DU_CHAIN))
1976 FOR_EACH_INSN_INFO_DEF (def, insn_info)
1977 DF_REF_CHAIN (def) = NULL;
1978 if (df_chain_problem_p (DF_UD_CHAIN))
1980 FOR_EACH_INSN_INFO_USE (use, insn_info)
1981 DF_REF_CHAIN (use) = NULL;
1982 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
1983 DF_REF_CHAIN (use) = NULL;
1988 bitmap_clear (df_chain->out_of_date_transfer_functions);
1989 df_chain->block_pool = NULL;
1993 /* Remove the chain problem completely. */
1995 static void
1996 df_chain_fully_remove_problem (void)
1998 df_chain_remove_problem ();
1999 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2000 free (df_chain);
2004 /* Create def-use or use-def chains. */
2006 static void
2007 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2009 df_chain_remove_problem ();
2010 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2011 sizeof (struct df_link), 50);
2012 df_chain->optional_p = true;
2016 /* Reset all of the chains when the set of basic blocks changes. */
2018 static void
2019 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2021 df_chain_remove_problem ();
2025 /* Create the chains for a list of USEs. */
2027 static void
2028 df_chain_create_bb_process_use (bitmap local_rd,
2029 df_ref use,
2030 int top_flag)
2032 bitmap_iterator bi;
2033 unsigned int def_index;
2035 for (; use; use = DF_REF_NEXT_LOC (use))
2037 unsigned int uregno = DF_REF_REGNO (use);
2038 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2039 || (uregno >= FIRST_PSEUDO_REGISTER))
2041 /* Do not want to go through this for an uninitialized var. */
2042 int count = DF_DEFS_COUNT (uregno);
2043 if (count)
2045 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2047 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2048 unsigned int last_index = first_index + count - 1;
2050 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2052 df_ref def;
2053 if (def_index > last_index)
2054 break;
2056 def = DF_DEFS_GET (def_index);
2057 if (df_chain_problem_p (DF_DU_CHAIN))
2058 df_chain_create (def, use);
2059 if (df_chain_problem_p (DF_UD_CHAIN))
2060 df_chain_create (use, def);
2069 /* Create chains from reaching defs bitmaps for basic block BB. */
2071 static void
2072 df_chain_create_bb (unsigned int bb_index)
2074 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2075 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2076 rtx_insn *insn;
2077 bitmap_head cpy;
2079 bitmap_initialize (&cpy, &bitmap_default_obstack);
2080 bitmap_copy (&cpy, &bb_info->in);
2081 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2083 /* Since we are going forwards, process the artificial uses first
2084 then the artificial defs second. */
2086 #ifdef EH_USES
2087 /* Create the chains for the artificial uses from the EH_USES at the
2088 beginning of the block. */
2090 /* Artificials are only hard regs. */
2091 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2092 df_chain_create_bb_process_use (&cpy,
2093 df_get_artificial_uses (bb->index),
2094 DF_REF_AT_TOP);
2095 #endif
2097 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2099 /* Process the regular instructions next. */
2100 FOR_BB_INSNS (bb, insn)
2101 if (INSN_P (insn))
2103 unsigned int uid = INSN_UID (insn);
2105 /* First scan the uses and link them up with the defs that remain
2106 in the cpy vector. */
2107 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2108 if (df->changeable_flags & DF_EQ_NOTES)
2109 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2111 /* Since we are going forwards, process the defs second. */
2112 df_rd_simulate_one_insn (bb, insn, &cpy);
2115 /* Create the chains for the artificial uses of the hard registers
2116 at the end of the block. */
2117 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2118 df_chain_create_bb_process_use (&cpy,
2119 df_get_artificial_uses (bb->index),
2122 bitmap_clear (&cpy);
2125 /* Create def-use chains from reaching use bitmaps for basic blocks
2126 in BLOCKS. */
2128 static void
2129 df_chain_finalize (bitmap all_blocks)
2131 unsigned int bb_index;
2132 bitmap_iterator bi;
2134 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2136 df_chain_create_bb (bb_index);
2141 /* Free all storage associated with the problem. */
2143 static void
2144 df_chain_free (void)
2146 free_alloc_pool (df_chain->block_pool);
2147 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2148 free (df_chain);
2152 /* Debugging info. */
2154 static void
2155 df_chain_bb_dump (basic_block bb, FILE *file, bool top)
2157 /* Artificials are only hard regs. */
2158 if (df->changeable_flags & DF_NO_HARD_REGS)
2159 return;
2160 if (df_chain_problem_p (DF_UD_CHAIN))
2162 df_ref use;
2164 fprintf (file,
2165 ";; UD chains for artificial uses at %s\n",
2166 top ? "top" : "bottom");
2167 FOR_EACH_ARTIFICIAL_USE (use, bb->index)
2168 if ((top && (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2169 || (!top && !(DF_REF_FLAGS (use) & DF_REF_AT_TOP)))
2171 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2172 df_chain_dump (DF_REF_CHAIN (use), file);
2173 fprintf (file, "\n");
2176 if (df_chain_problem_p (DF_DU_CHAIN))
2178 df_ref def;
2180 fprintf (file,
2181 ";; DU chains for artificial defs at %s\n",
2182 top ? "top" : "bottom");
2183 FOR_EACH_ARTIFICIAL_DEF (def, bb->index)
2184 if ((top && (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
2185 || (!top && !(DF_REF_FLAGS (def) & DF_REF_AT_TOP)))
2187 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2188 df_chain_dump (DF_REF_CHAIN (def), file);
2189 fprintf (file, "\n");
2194 static void
2195 df_chain_top_dump (basic_block bb, FILE *file)
2197 df_chain_bb_dump (bb, file, /*top=*/true);
2200 static void
2201 df_chain_bottom_dump (basic_block bb, FILE *file)
2203 df_chain_bb_dump (bb, file, /*top=*/false);
2206 static void
2207 df_chain_insn_top_dump (const rtx_insn *insn, FILE *file)
2209 if (df_chain_problem_p (DF_UD_CHAIN) && INSN_P (insn))
2211 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2212 df_ref use;
2214 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2215 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2216 FOR_EACH_INSN_INFO_USE (use, insn_info)
2217 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2218 || !(df->changeable_flags & DF_NO_HARD_REGS))
2220 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2221 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2222 fprintf (file, "read/write ");
2223 df_chain_dump (DF_REF_CHAIN (use), file);
2224 fprintf (file, "\n");
2226 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
2227 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2228 || !(df->changeable_flags & DF_NO_HARD_REGS))
2230 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2231 df_chain_dump (DF_REF_CHAIN (use), file);
2232 fprintf (file, "\n");
2237 static void
2238 df_chain_insn_bottom_dump (const rtx_insn *insn, FILE *file)
2240 if (df_chain_problem_p (DF_DU_CHAIN) && INSN_P (insn))
2242 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2243 df_ref def;
2244 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2245 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2246 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2247 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def))
2248 || !(df->changeable_flags & DF_NO_HARD_REGS))
2250 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2251 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2252 fprintf (file, "read/write ");
2253 df_chain_dump (DF_REF_CHAIN (def), file);
2254 fprintf (file, "\n");
2256 fprintf (file, "\n");
2260 static struct df_problem problem_CHAIN =
2262 DF_CHAIN, /* Problem id. */
2263 DF_NONE, /* Direction. */
2264 df_chain_alloc, /* Allocate the problem specific data. */
2265 df_chain_reset, /* Reset global information. */
2266 NULL, /* Free basic block info. */
2267 NULL, /* Local compute function. */
2268 NULL, /* Init the solution specific data. */
2269 NULL, /* Iterative solver. */
2270 NULL, /* Confluence operator 0. */
2271 NULL, /* Confluence operator n. */
2272 NULL, /* Transfer function. */
2273 df_chain_finalize, /* Finalize function. */
2274 df_chain_free, /* Free all of the problem information. */
2275 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2276 NULL, /* Debugging. */
2277 df_chain_top_dump, /* Debugging start block. */
2278 df_chain_bottom_dump, /* Debugging end block. */
2279 df_chain_insn_top_dump, /* Debugging start insn. */
2280 df_chain_insn_bottom_dump, /* Debugging end insn. */
2281 NULL, /* Incremental solution verify start. */
2282 NULL, /* Incremental solution verify end. */
2283 &problem_RD, /* Dependent problem. */
2284 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
2285 TV_DF_CHAIN, /* Timing variable. */
2286 false /* Reset blocks on dropping out of blocks_to_analyze. */
2290 /* Create a new DATAFLOW instance and add it to an existing instance
2291 of DF. The returned structure is what is used to get at the
2292 solution. */
2294 void
2295 df_chain_add_problem (unsigned int chain_flags)
2297 df_add_problem (&problem_CHAIN);
2298 df_chain->local_flags = chain_flags;
2299 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2302 #undef df_chain_problem_p
2305 /*----------------------------------------------------------------------------
2306 WORD LEVEL LIVE REGISTERS
2308 Find the locations in the function where any use of a pseudo can
2309 reach in the backwards direction. In and out bitvectors are built
2310 for each basic block. We only track pseudo registers that have a
2311 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2312 contain two bits corresponding to each of the subwords.
2314 ----------------------------------------------------------------------------*/
2316 /* Private data used to verify the solution for this problem. */
2317 struct df_word_lr_problem_data
2319 /* An obstack for the bitmaps we need for this problem. */
2320 bitmap_obstack word_lr_bitmaps;
2324 /* Free basic block info. */
2326 static void
2327 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2328 void *vbb_info)
2330 struct df_word_lr_bb_info *bb_info = (struct df_word_lr_bb_info *) vbb_info;
2331 if (bb_info)
2333 bitmap_clear (&bb_info->use);
2334 bitmap_clear (&bb_info->def);
2335 bitmap_clear (&bb_info->in);
2336 bitmap_clear (&bb_info->out);
2341 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2342 not touched unless the block is new. */
2344 static void
2345 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2347 unsigned int bb_index;
2348 bitmap_iterator bi;
2349 basic_block bb;
2350 struct df_word_lr_problem_data *problem_data
2351 = XNEW (struct df_word_lr_problem_data);
2353 df_word_lr->problem_data = problem_data;
2355 df_grow_bb_info (df_word_lr);
2357 /* Create the mapping from regnos to slots. This does not change
2358 unless the problem is destroyed and recreated. In particular, if
2359 we end up deleting the only insn that used a subreg, we do not
2360 want to redo the mapping because this would invalidate everything
2361 else. */
2363 bitmap_obstack_initialize (&problem_data->word_lr_bitmaps);
2365 FOR_EACH_BB_FN (bb, cfun)
2366 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, bb->index);
2368 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2369 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2371 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2373 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2375 /* When bitmaps are already initialized, just clear them. */
2376 if (bb_info->use.obstack)
2378 bitmap_clear (&bb_info->def);
2379 bitmap_clear (&bb_info->use);
2381 else
2383 bitmap_initialize (&bb_info->use, &problem_data->word_lr_bitmaps);
2384 bitmap_initialize (&bb_info->def, &problem_data->word_lr_bitmaps);
2385 bitmap_initialize (&bb_info->in, &problem_data->word_lr_bitmaps);
2386 bitmap_initialize (&bb_info->out, &problem_data->word_lr_bitmaps);
2390 df_word_lr->optional_p = true;
2394 /* Reset the global solution for recalculation. */
2396 static void
2397 df_word_lr_reset (bitmap all_blocks)
2399 unsigned int bb_index;
2400 bitmap_iterator bi;
2402 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2404 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2405 gcc_assert (bb_info);
2406 bitmap_clear (&bb_info->in);
2407 bitmap_clear (&bb_info->out);
2411 /* Examine REF, and if it is for a reg we're interested in, set or
2412 clear the bits corresponding to its subwords from the bitmap
2413 according to IS_SET. LIVE is the bitmap we should update. We do
2414 not track hard regs or pseudos of any size other than 2 *
2415 UNITS_PER_WORD.
2416 We return true if we changed the bitmap, or if we encountered a register
2417 we're not tracking. */
2419 bool
2420 df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
2422 rtx orig_reg = DF_REF_REG (ref);
2423 rtx reg = orig_reg;
2424 enum machine_mode reg_mode;
2425 unsigned regno;
2426 /* Left at -1 for whole accesses. */
2427 int which_subword = -1;
2428 bool changed = false;
2430 if (GET_CODE (reg) == SUBREG)
2431 reg = SUBREG_REG (orig_reg);
2432 regno = REGNO (reg);
2433 reg_mode = GET_MODE (reg);
2434 if (regno < FIRST_PSEUDO_REGISTER
2435 || GET_MODE_SIZE (reg_mode) != 2 * UNITS_PER_WORD)
2436 return true;
2438 if (GET_CODE (orig_reg) == SUBREG
2439 && df_read_modify_subreg_p (orig_reg))
2441 gcc_assert (DF_REF_FLAGS_IS_SET (ref, DF_REF_PARTIAL));
2442 if (subreg_lowpart_p (orig_reg))
2443 which_subword = 0;
2444 else
2445 which_subword = 1;
2447 if (is_set)
2449 if (which_subword != 1)
2450 changed |= bitmap_set_bit (live, regno * 2);
2451 if (which_subword != 0)
2452 changed |= bitmap_set_bit (live, regno * 2 + 1);
2454 else
2456 if (which_subword != 1)
2457 changed |= bitmap_clear_bit (live, regno * 2);
2458 if (which_subword != 0)
2459 changed |= bitmap_clear_bit (live, regno * 2 + 1);
2461 return changed;
2464 /* Compute local live register info for basic block BB. */
2466 static void
2467 df_word_lr_bb_local_compute (unsigned int bb_index)
2469 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2470 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2471 rtx_insn *insn;
2472 df_ref def, use;
2474 /* Ensure that artificial refs don't contain references to pseudos. */
2475 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
2476 gcc_assert (DF_REF_REGNO (def) < FIRST_PSEUDO_REGISTER);
2478 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
2479 gcc_assert (DF_REF_REGNO (use) < FIRST_PSEUDO_REGISTER);
2481 FOR_BB_INSNS_REVERSE (bb, insn)
2483 if (!NONDEBUG_INSN_P (insn))
2484 continue;
2486 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2487 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2488 /* If the def is to only part of the reg, it does
2489 not kill the other defs that reach here. */
2490 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2492 df_word_lr_mark_ref (def, true, &bb_info->def);
2493 df_word_lr_mark_ref (def, false, &bb_info->use);
2495 FOR_EACH_INSN_INFO_USE (use, insn_info)
2496 df_word_lr_mark_ref (use, true, &bb_info->use);
2501 /* Compute local live register info for each basic block within BLOCKS. */
2503 static void
2504 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2506 unsigned int bb_index;
2507 bitmap_iterator bi;
2509 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2511 if (bb_index == EXIT_BLOCK)
2513 unsigned regno;
2514 bitmap_iterator bi;
2515 EXECUTE_IF_SET_IN_BITMAP (df->exit_block_uses, FIRST_PSEUDO_REGISTER,
2516 regno, bi)
2517 gcc_unreachable ();
2519 else
2520 df_word_lr_bb_local_compute (bb_index);
2523 bitmap_clear (df_word_lr->out_of_date_transfer_functions);
2527 /* Initialize the solution vectors. */
2529 static void
2530 df_word_lr_init (bitmap all_blocks)
2532 unsigned int bb_index;
2533 bitmap_iterator bi;
2535 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2537 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2538 bitmap_copy (&bb_info->in, &bb_info->use);
2539 bitmap_clear (&bb_info->out);
2544 /* Confluence function that ignores fake edges. */
2546 static bool
2547 df_word_lr_confluence_n (edge e)
2549 bitmap op1 = &df_word_lr_get_bb_info (e->src->index)->out;
2550 bitmap op2 = &df_word_lr_get_bb_info (e->dest->index)->in;
2552 return bitmap_ior_into (op1, op2);
2556 /* Transfer function. */
2558 static bool
2559 df_word_lr_transfer_function (int bb_index)
2561 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2562 bitmap in = &bb_info->in;
2563 bitmap out = &bb_info->out;
2564 bitmap use = &bb_info->use;
2565 bitmap def = &bb_info->def;
2567 return bitmap_ior_and_compl (in, use, out, def);
2571 /* Free all storage associated with the problem. */
2573 static void
2574 df_word_lr_free (void)
2576 struct df_word_lr_problem_data *problem_data
2577 = (struct df_word_lr_problem_data *)df_word_lr->problem_data;
2579 if (df_word_lr->block_info)
2581 df_word_lr->block_info_size = 0;
2582 free (df_word_lr->block_info);
2583 df_word_lr->block_info = NULL;
2586 BITMAP_FREE (df_word_lr->out_of_date_transfer_functions);
2587 bitmap_obstack_release (&problem_data->word_lr_bitmaps);
2588 free (problem_data);
2589 free (df_word_lr);
2593 /* Debugging info at top of bb. */
2595 static void
2596 df_word_lr_top_dump (basic_block bb, FILE *file)
2598 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2599 if (!bb_info)
2600 return;
2602 fprintf (file, ";; blr in \t");
2603 df_print_word_regset (file, &bb_info->in);
2604 fprintf (file, ";; blr use \t");
2605 df_print_word_regset (file, &bb_info->use);
2606 fprintf (file, ";; blr def \t");
2607 df_print_word_regset (file, &bb_info->def);
2611 /* Debugging info at bottom of bb. */
2613 static void
2614 df_word_lr_bottom_dump (basic_block bb, FILE *file)
2616 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2617 if (!bb_info)
2618 return;
2620 fprintf (file, ";; blr out \t");
2621 df_print_word_regset (file, &bb_info->out);
2625 /* All of the information associated with every instance of the problem. */
2627 static struct df_problem problem_WORD_LR =
2629 DF_WORD_LR, /* Problem id. */
2630 DF_BACKWARD, /* Direction. */
2631 df_word_lr_alloc, /* Allocate the problem specific data. */
2632 df_word_lr_reset, /* Reset global information. */
2633 df_word_lr_free_bb_info, /* Free basic block info. */
2634 df_word_lr_local_compute, /* Local compute function. */
2635 df_word_lr_init, /* Init the solution specific data. */
2636 df_worklist_dataflow, /* Worklist solver. */
2637 NULL, /* Confluence operator 0. */
2638 df_word_lr_confluence_n, /* Confluence operator n. */
2639 df_word_lr_transfer_function, /* Transfer function. */
2640 NULL, /* Finalize function. */
2641 df_word_lr_free, /* Free all of the problem information. */
2642 df_word_lr_free, /* Remove this problem from the stack of dataflow problems. */
2643 NULL, /* Debugging. */
2644 df_word_lr_top_dump, /* Debugging start block. */
2645 df_word_lr_bottom_dump, /* Debugging end block. */
2646 NULL, /* Debugging start insn. */
2647 NULL, /* Debugging end insn. */
2648 NULL, /* Incremental solution verify start. */
2649 NULL, /* Incremental solution verify end. */
2650 NULL, /* Dependent problem. */
2651 sizeof (struct df_word_lr_bb_info),/* Size of entry of block_info array. */
2652 TV_DF_WORD_LR, /* Timing variable. */
2653 false /* Reset blocks on dropping out of blocks_to_analyze. */
2657 /* Create a new DATAFLOW instance and add it to an existing instance
2658 of DF. The returned structure is what is used to get at the
2659 solution. */
2661 void
2662 df_word_lr_add_problem (void)
2664 df_add_problem (&problem_WORD_LR);
2665 /* These will be initialized when df_scan_blocks processes each
2666 block. */
2667 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2671 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2672 any bits, which is used by the caller to determine whether a set is
2673 necessary. We also return true if there are other reasons not to delete
2674 an insn. */
2676 bool
2677 df_word_lr_simulate_defs (rtx_insn *insn, bitmap live)
2679 bool changed = false;
2680 df_ref def;
2682 FOR_EACH_INSN_DEF (def, insn)
2683 if (DF_REF_FLAGS (def) & DF_REF_CONDITIONAL)
2684 changed = true;
2685 else
2686 changed |= df_word_lr_mark_ref (def, false, live);
2687 return changed;
2691 /* Simulate the effects of the uses of INSN on LIVE. */
2693 void
2694 df_word_lr_simulate_uses (rtx_insn *insn, bitmap live)
2696 df_ref use;
2698 FOR_EACH_INSN_USE (use, insn)
2699 df_word_lr_mark_ref (use, true, live);
2702 /*----------------------------------------------------------------------------
2703 This problem computes REG_DEAD and REG_UNUSED notes.
2704 ----------------------------------------------------------------------------*/
2706 static void
2707 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2709 df_note->optional_p = true;
2712 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2713 static void
2714 df_print_note (const char *prefix, rtx_insn *insn, rtx note)
2716 if (dump_file)
2718 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2719 print_rtl (dump_file, note);
2720 fprintf (dump_file, "\n");
2725 /* After reg-stack, the x86 floating point stack regs are difficult to
2726 analyze because of all of the pushes, pops and rotations. Thus, we
2727 just leave the notes alone. */
2729 #ifdef STACK_REGS
2730 static inline bool
2731 df_ignore_stack_reg (int regno)
2733 return regstack_completed
2734 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2736 #else
2737 static inline bool
2738 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2740 return false;
2742 #endif
2745 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
2747 static void
2748 df_remove_dead_and_unused_notes (rtx_insn *insn)
2750 rtx *pprev = &REG_NOTES (insn);
2751 rtx link = *pprev;
2753 while (link)
2755 switch (REG_NOTE_KIND (link))
2757 case REG_DEAD:
2758 /* After reg-stack, we need to ignore any unused notes
2759 for the stack registers. */
2760 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2762 pprev = &XEXP (link, 1);
2763 link = *pprev;
2765 else
2767 rtx next = XEXP (link, 1);
2768 if (REG_DEAD_DEBUGGING)
2769 df_print_note ("deleting: ", insn, link);
2770 free_EXPR_LIST_node (link);
2771 *pprev = link = next;
2773 break;
2775 case REG_UNUSED:
2776 /* After reg-stack, we need to ignore any unused notes
2777 for the stack registers. */
2778 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2780 pprev = &XEXP (link, 1);
2781 link = *pprev;
2783 else
2785 rtx next = XEXP (link, 1);
2786 if (REG_DEAD_DEBUGGING)
2787 df_print_note ("deleting: ", insn, link);
2788 free_EXPR_LIST_node (link);
2789 *pprev = link = next;
2791 break;
2793 default:
2794 pprev = &XEXP (link, 1);
2795 link = *pprev;
2796 break;
2801 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2802 as the bitmap of currently live registers. */
2804 static void
2805 df_remove_dead_eq_notes (rtx_insn *insn, bitmap live)
2807 rtx *pprev = &REG_NOTES (insn);
2808 rtx link = *pprev;
2810 while (link)
2812 switch (REG_NOTE_KIND (link))
2814 case REG_EQUAL:
2815 case REG_EQUIV:
2817 /* Remove the notes that refer to dead registers. As we have at most
2818 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2819 so we need to purge the complete EQ_USES vector when removing
2820 the note using df_notes_rescan. */
2821 df_ref use;
2822 bool deleted = false;
2824 FOR_EACH_INSN_EQ_USE (use, insn)
2825 if (DF_REF_REGNO (use) > FIRST_PSEUDO_REGISTER
2826 && DF_REF_LOC (use)
2827 && (DF_REF_FLAGS (use) & DF_REF_IN_NOTE)
2828 && !bitmap_bit_p (live, DF_REF_REGNO (use))
2829 && loc_mentioned_in_p (DF_REF_LOC (use), XEXP (link, 0)))
2831 deleted = true;
2832 break;
2834 if (deleted)
2836 rtx next;
2837 if (REG_DEAD_DEBUGGING)
2838 df_print_note ("deleting: ", insn, link);
2839 next = XEXP (link, 1);
2840 free_EXPR_LIST_node (link);
2841 *pprev = link = next;
2842 df_notes_rescan (insn);
2844 else
2846 pprev = &XEXP (link, 1);
2847 link = *pprev;
2849 break;
2852 default:
2853 pprev = &XEXP (link, 1);
2854 link = *pprev;
2855 break;
2860 /* Set a NOTE_TYPE note for REG in INSN. */
2862 static inline void
2863 df_set_note (enum reg_note note_type, rtx insn, rtx reg)
2865 gcc_checking_assert (!DEBUG_INSN_P (insn));
2866 add_reg_note (insn, note_type, reg);
2869 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2870 arguments. Return true if the register value described by MWS's
2871 mw_reg is known to be completely unused, and if mw_reg can therefore
2872 be used in a REG_UNUSED note. */
2874 static bool
2875 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2876 bitmap live, bitmap artificial_uses)
2878 unsigned int r;
2880 /* If MWS describes a partial reference, create REG_UNUSED notes for
2881 individual hard registers. */
2882 if (mws->flags & DF_REF_PARTIAL)
2883 return false;
2885 /* Likewise if some part of the register is used. */
2886 for (r = mws->start_regno; r <= mws->end_regno; r++)
2887 if (bitmap_bit_p (live, r)
2888 || bitmap_bit_p (artificial_uses, r))
2889 return false;
2891 gcc_assert (REG_P (mws->mw_reg));
2892 return true;
2896 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2897 based on the bits in LIVE. Do not generate notes for registers in
2898 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2899 not generated if the reg is both read and written by the
2900 instruction.
2903 static void
2904 df_set_unused_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
2905 bitmap live, bitmap do_not_gen,
2906 bitmap artificial_uses,
2907 struct dead_debug_local *debug)
2909 unsigned int r;
2911 if (REG_DEAD_DEBUGGING && dump_file)
2912 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2913 mws->start_regno, mws->end_regno);
2915 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2917 unsigned int regno = mws->start_regno;
2918 df_set_note (REG_UNUSED, insn, mws->mw_reg);
2919 dead_debug_insert_temp (debug, regno, insn, DEBUG_TEMP_AFTER_WITH_REG);
2921 if (REG_DEAD_DEBUGGING)
2922 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2924 bitmap_set_bit (do_not_gen, regno);
2925 /* Only do this if the value is totally dead. */
2927 else
2928 for (r = mws->start_regno; r <= mws->end_regno; r++)
2930 if (!bitmap_bit_p (live, r)
2931 && !bitmap_bit_p (artificial_uses, r))
2933 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
2934 dead_debug_insert_temp (debug, r, insn, DEBUG_TEMP_AFTER_WITH_REG);
2935 if (REG_DEAD_DEBUGGING)
2936 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2938 bitmap_set_bit (do_not_gen, r);
2943 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2944 arguments. Return true if the register value described by MWS's
2945 mw_reg is known to be completely dead, and if mw_reg can therefore
2946 be used in a REG_DEAD note. */
2948 static bool
2949 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2950 bitmap live, bitmap artificial_uses,
2951 bitmap do_not_gen)
2953 unsigned int r;
2955 /* If MWS describes a partial reference, create REG_DEAD notes for
2956 individual hard registers. */
2957 if (mws->flags & DF_REF_PARTIAL)
2958 return false;
2960 /* Likewise if some part of the register is not dead. */
2961 for (r = mws->start_regno; r <= mws->end_regno; r++)
2962 if (bitmap_bit_p (live, r)
2963 || bitmap_bit_p (artificial_uses, r)
2964 || bitmap_bit_p (do_not_gen, r))
2965 return false;
2967 gcc_assert (REG_P (mws->mw_reg));
2968 return true;
2971 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2972 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2973 from being set if the instruction both reads and writes the
2974 register. */
2976 static void
2977 df_set_dead_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
2978 bitmap live, bitmap do_not_gen,
2979 bitmap artificial_uses, bool *added_notes_p)
2981 unsigned int r;
2982 bool is_debug = *added_notes_p;
2984 *added_notes_p = false;
2986 if (REG_DEAD_DEBUGGING && dump_file)
2988 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2989 mws->start_regno, mws->end_regno);
2990 df_print_regset (dump_file, do_not_gen);
2991 fprintf (dump_file, " live =");
2992 df_print_regset (dump_file, live);
2993 fprintf (dump_file, " artificial uses =");
2994 df_print_regset (dump_file, artificial_uses);
2997 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2999 if (is_debug)
3001 *added_notes_p = true;
3002 return;
3004 /* Add a dead note for the entire multi word register. */
3005 df_set_note (REG_DEAD, insn, mws->mw_reg);
3006 if (REG_DEAD_DEBUGGING)
3007 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3009 else
3011 for (r = mws->start_regno; r <= mws->end_regno; r++)
3012 if (!bitmap_bit_p (live, r)
3013 && !bitmap_bit_p (artificial_uses, r)
3014 && !bitmap_bit_p (do_not_gen, r))
3016 if (is_debug)
3018 *added_notes_p = true;
3019 return;
3021 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
3022 if (REG_DEAD_DEBUGGING)
3023 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3026 return;
3030 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3031 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3033 static void
3034 df_create_unused_note (rtx_insn *insn, df_ref def,
3035 bitmap live, bitmap artificial_uses,
3036 struct dead_debug_local *debug)
3038 unsigned int dregno = DF_REF_REGNO (def);
3040 if (REG_DEAD_DEBUGGING && dump_file)
3042 fprintf (dump_file, " regular looking at def ");
3043 df_ref_debug (def, dump_file);
3046 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3047 || bitmap_bit_p (live, dregno)
3048 || bitmap_bit_p (artificial_uses, dregno)
3049 || df_ignore_stack_reg (dregno)))
3051 rtx reg = (DF_REF_LOC (def))
3052 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3053 df_set_note (REG_UNUSED, insn, reg);
3054 dead_debug_insert_temp (debug, dregno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3055 if (REG_DEAD_DEBUGGING)
3056 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3059 return;
3063 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3064 info: lifetime, bb, and number of defs and uses for basic block
3065 BB. The three bitvectors are scratch regs used here. */
3067 static void
3068 df_note_bb_compute (unsigned int bb_index,
3069 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3071 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
3072 rtx_insn *insn;
3073 df_ref def, use;
3074 struct dead_debug_local debug;
3076 dead_debug_local_init (&debug, NULL, NULL);
3078 bitmap_copy (live, df_get_live_out (bb));
3079 bitmap_clear (artificial_uses);
3081 if (REG_DEAD_DEBUGGING && dump_file)
3083 fprintf (dump_file, "live at bottom ");
3084 df_print_regset (dump_file, live);
3087 /* Process the artificial defs and uses at the bottom of the block
3088 to begin processing. */
3089 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3091 if (REG_DEAD_DEBUGGING && dump_file)
3092 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3094 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3095 bitmap_clear_bit (live, DF_REF_REGNO (def));
3098 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3099 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3101 unsigned int regno = DF_REF_REGNO (use);
3102 bitmap_set_bit (live, regno);
3104 /* Notes are not generated for any of the artificial registers
3105 at the bottom of the block. */
3106 bitmap_set_bit (artificial_uses, regno);
3109 if (REG_DEAD_DEBUGGING && dump_file)
3111 fprintf (dump_file, "live before artificials out ");
3112 df_print_regset (dump_file, live);
3115 FOR_BB_INSNS_REVERSE (bb, insn)
3117 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3118 df_mw_hardreg *mw;
3119 int debug_insn;
3121 if (!INSN_P (insn))
3122 continue;
3124 debug_insn = DEBUG_INSN_P (insn);
3126 bitmap_clear (do_not_gen);
3127 df_remove_dead_and_unused_notes (insn);
3129 /* Process the defs. */
3130 if (CALL_P (insn))
3132 if (REG_DEAD_DEBUGGING && dump_file)
3134 fprintf (dump_file, "processing call %d\n live =",
3135 INSN_UID (insn));
3136 df_print_regset (dump_file, live);
3139 /* We only care about real sets for calls. Clobbers cannot
3140 be depended on to really die. */
3141 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3142 if ((DF_MWS_REG_DEF_P (mw))
3143 && !df_ignore_stack_reg (mw->start_regno))
3144 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3145 artificial_uses, &debug);
3147 /* All of the defs except the return value are some sort of
3148 clobber. This code is for the return. */
3149 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3151 unsigned int dregno = DF_REF_REGNO (def);
3152 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3154 df_create_unused_note (insn,
3155 def, live, artificial_uses, &debug);
3156 bitmap_set_bit (do_not_gen, dregno);
3159 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3160 bitmap_clear_bit (live, dregno);
3163 else
3165 /* Regular insn. */
3166 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3167 if (DF_MWS_REG_DEF_P (mw))
3168 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3169 artificial_uses, &debug);
3171 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3173 unsigned int dregno = DF_REF_REGNO (def);
3174 df_create_unused_note (insn,
3175 def, live, artificial_uses, &debug);
3177 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3178 bitmap_set_bit (do_not_gen, dregno);
3180 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3181 bitmap_clear_bit (live, dregno);
3185 /* Process the uses. */
3186 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3187 if (DF_MWS_REG_USE_P (mw)
3188 && !df_ignore_stack_reg (mw->start_regno))
3190 bool really_add_notes = debug_insn != 0;
3192 df_set_dead_notes_for_mw (insn, mw, live, do_not_gen,
3193 artificial_uses,
3194 &really_add_notes);
3196 if (really_add_notes)
3197 debug_insn = -1;
3200 FOR_EACH_INSN_INFO_USE (use, insn_info)
3202 unsigned int uregno = DF_REF_REGNO (use);
3204 if (REG_DEAD_DEBUGGING && dump_file && !debug_insn)
3206 fprintf (dump_file, " regular looking at use ");
3207 df_ref_debug (use, dump_file);
3210 if (!bitmap_bit_p (live, uregno))
3212 if (debug_insn)
3214 if (debug_insn > 0)
3216 /* We won't add REG_UNUSED or REG_DEAD notes for
3217 these, so we don't have to mess with them in
3218 debug insns either. */
3219 if (!bitmap_bit_p (artificial_uses, uregno)
3220 && !df_ignore_stack_reg (uregno))
3221 dead_debug_add (&debug, use, uregno);
3222 continue;
3224 break;
3226 else
3227 dead_debug_insert_temp (&debug, uregno, insn,
3228 DEBUG_TEMP_BEFORE_WITH_REG);
3230 if ( (!(DF_REF_FLAGS (use)
3231 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3232 && (!bitmap_bit_p (do_not_gen, uregno))
3233 && (!bitmap_bit_p (artificial_uses, uregno))
3234 && (!df_ignore_stack_reg (uregno)))
3236 rtx reg = (DF_REF_LOC (use))
3237 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3238 df_set_note (REG_DEAD, insn, reg);
3240 if (REG_DEAD_DEBUGGING)
3241 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3243 /* This register is now live. */
3244 bitmap_set_bit (live, uregno);
3248 df_remove_dead_eq_notes (insn, live);
3250 if (debug_insn == -1)
3252 /* ??? We could probably do better here, replacing dead
3253 registers with their definitions. */
3254 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3255 df_insn_rescan_debug_internal (insn);
3259 dead_debug_local_finish (&debug, NULL);
3263 /* Compute register info: lifetime, bb, and number of defs and uses. */
3264 static void
3265 df_note_compute (bitmap all_blocks)
3267 unsigned int bb_index;
3268 bitmap_iterator bi;
3269 bitmap_head live, do_not_gen, artificial_uses;
3271 bitmap_initialize (&live, &df_bitmap_obstack);
3272 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3273 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3275 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3277 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3278 pseudos in debug insns because we don't always (re)visit blocks
3279 with death points after visiting dead uses. Even changing this
3280 loop to postorder would still leave room for visiting a death
3281 point before visiting a subsequent debug use. */
3282 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3285 bitmap_clear (&live);
3286 bitmap_clear (&do_not_gen);
3287 bitmap_clear (&artificial_uses);
3291 /* Free all storage associated with the problem. */
3293 static void
3294 df_note_free (void)
3296 free (df_note);
3300 /* All of the information associated every instance of the problem. */
3302 static struct df_problem problem_NOTE =
3304 DF_NOTE, /* Problem id. */
3305 DF_NONE, /* Direction. */
3306 df_note_alloc, /* Allocate the problem specific data. */
3307 NULL, /* Reset global information. */
3308 NULL, /* Free basic block info. */
3309 df_note_compute, /* Local compute function. */
3310 NULL, /* Init the solution specific data. */
3311 NULL, /* Iterative solver. */
3312 NULL, /* Confluence operator 0. */
3313 NULL, /* Confluence operator n. */
3314 NULL, /* Transfer function. */
3315 NULL, /* Finalize function. */
3316 df_note_free, /* Free all of the problem information. */
3317 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3318 NULL, /* Debugging. */
3319 NULL, /* Debugging start block. */
3320 NULL, /* Debugging end block. */
3321 NULL, /* Debugging start insn. */
3322 NULL, /* Debugging end insn. */
3323 NULL, /* Incremental solution verify start. */
3324 NULL, /* Incremental solution verify end. */
3325 &problem_LR, /* Dependent problem. */
3326 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
3327 TV_DF_NOTE, /* Timing variable. */
3328 false /* Reset blocks on dropping out of blocks_to_analyze. */
3332 /* Create a new DATAFLOW instance and add it to an existing instance
3333 of DF. The returned structure is what is used to get at the
3334 solution. */
3336 void
3337 df_note_add_problem (void)
3339 df_add_problem (&problem_NOTE);
3345 /*----------------------------------------------------------------------------
3346 Functions for simulating the effects of single insns.
3348 You can either simulate in the forwards direction, starting from
3349 the top of a block or the backwards direction from the end of the
3350 block. If you go backwards, defs are examined first to clear bits,
3351 then uses are examined to set bits. If you go forwards, defs are
3352 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3353 are examined to clear bits. In either case, the result of examining
3354 a def can be undone (respectively by a use or a REG_UNUSED note).
3356 If you start at the top of the block, use one of DF_LIVE_IN or
3357 DF_LR_IN. If you start at the bottom of the block use one of
3358 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3359 THEY WILL BE DESTROYED.
3360 ----------------------------------------------------------------------------*/
3363 /* Find the set of DEFs for INSN. */
3365 void
3366 df_simulate_find_defs (rtx_insn *insn, bitmap defs)
3368 df_ref def;
3370 FOR_EACH_INSN_DEF (def, insn)
3371 bitmap_set_bit (defs, DF_REF_REGNO (def));
3374 /* Find the set of uses for INSN. This includes partial defs. */
3376 static void
3377 df_simulate_find_uses (rtx_insn *insn, bitmap uses)
3379 df_ref def, use;
3380 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3382 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3383 if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3384 bitmap_set_bit (uses, DF_REF_REGNO (def));
3385 FOR_EACH_INSN_INFO_USE (use, insn_info)
3386 bitmap_set_bit (uses, DF_REF_REGNO (use));
3389 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3391 void
3392 df_simulate_find_noclobber_defs (rtx_insn *insn, bitmap defs)
3394 df_ref def;
3396 FOR_EACH_INSN_DEF (def, insn)
3397 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3398 bitmap_set_bit (defs, DF_REF_REGNO (def));
3402 /* Simulate the effects of the defs of INSN on LIVE. */
3404 void
3405 df_simulate_defs (rtx_insn *insn, bitmap live)
3407 df_ref def;
3409 FOR_EACH_INSN_DEF (def, insn)
3411 unsigned int dregno = DF_REF_REGNO (def);
3413 /* If the def is to only part of the reg, it does
3414 not kill the other defs that reach here. */
3415 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3416 bitmap_clear_bit (live, dregno);
3421 /* Simulate the effects of the uses of INSN on LIVE. */
3423 void
3424 df_simulate_uses (rtx_insn *insn, bitmap live)
3426 df_ref use;
3428 if (DEBUG_INSN_P (insn))
3429 return;
3431 FOR_EACH_INSN_USE (use, insn)
3432 /* Add use to set of uses in this BB. */
3433 bitmap_set_bit (live, DF_REF_REGNO (use));
3437 /* Add back the always live regs in BB to LIVE. */
3439 static inline void
3440 df_simulate_fixup_sets (basic_block bb, bitmap live)
3442 /* These regs are considered always live so if they end up dying
3443 because of some def, we need to bring the back again. */
3444 if (bb_has_eh_pred (bb))
3445 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3446 else
3447 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3451 /*----------------------------------------------------------------------------
3452 The following three functions are used only for BACKWARDS scanning:
3453 i.e. they process the defs before the uses.
3455 df_simulate_initialize_backwards should be called first with a
3456 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3457 df_simulate_one_insn_backwards should be called for each insn in
3458 the block, starting with the last one. Finally,
3459 df_simulate_finalize_backwards can be called to get a new value
3460 of the sets at the top of the block (this is rarely used).
3461 ----------------------------------------------------------------------------*/
3463 /* Apply the artificial uses and defs at the end of BB in a backwards
3464 direction. */
3466 void
3467 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3469 df_ref def, use;
3470 int bb_index = bb->index;
3472 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3473 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3474 bitmap_clear_bit (live, DF_REF_REGNO (def));
3476 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3477 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3478 bitmap_set_bit (live, DF_REF_REGNO (use));
3482 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3484 void
3485 df_simulate_one_insn_backwards (basic_block bb, rtx_insn *insn, bitmap live)
3487 if (!NONDEBUG_INSN_P (insn))
3488 return;
3490 df_simulate_defs (insn, live);
3491 df_simulate_uses (insn, live);
3492 df_simulate_fixup_sets (bb, live);
3496 /* Apply the artificial uses and defs at the top of BB in a backwards
3497 direction. */
3499 void
3500 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3502 df_ref def;
3503 #ifdef EH_USES
3504 df_ref use;
3505 #endif
3506 int bb_index = bb->index;
3508 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3509 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3510 bitmap_clear_bit (live, DF_REF_REGNO (def));
3512 #ifdef EH_USES
3513 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3514 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3515 bitmap_set_bit (live, DF_REF_REGNO (use));
3516 #endif
3518 /*----------------------------------------------------------------------------
3519 The following three functions are used only for FORWARDS scanning:
3520 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3521 Thus it is important to add the DF_NOTES problem to the stack of
3522 problems computed before using these functions.
3524 df_simulate_initialize_forwards should be called first with a
3525 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3526 df_simulate_one_insn_forwards should be called for each insn in
3527 the block, starting with the first one.
3528 ----------------------------------------------------------------------------*/
3530 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3531 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3532 defs live. */
3534 void
3535 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3537 df_ref def;
3538 int bb_index = bb->index;
3540 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3541 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3542 bitmap_set_bit (live, DF_REF_REGNO (def));
3545 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3547 void
3548 df_simulate_one_insn_forwards (basic_block bb, rtx_insn *insn, bitmap live)
3550 rtx link;
3551 if (! INSN_P (insn))
3552 return;
3554 /* Make sure that DF_NOTE really is an active df problem. */
3555 gcc_assert (df_note);
3557 /* Note that this is the opposite as how the problem is defined, because
3558 in the LR problem defs _kill_ liveness. However, they do so backwards,
3559 while here the scan is performed forwards! So, first assume that the
3560 def is live, and if this is not true REG_UNUSED notes will rectify the
3561 situation. */
3562 df_simulate_find_noclobber_defs (insn, live);
3564 /* Clear all of the registers that go dead. */
3565 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3567 switch (REG_NOTE_KIND (link))
3569 case REG_DEAD:
3570 case REG_UNUSED:
3572 rtx reg = XEXP (link, 0);
3573 int regno = REGNO (reg);
3574 if (HARD_REGISTER_NUM_P (regno))
3575 bitmap_clear_range (live, regno,
3576 hard_regno_nregs[regno][GET_MODE (reg)]);
3577 else
3578 bitmap_clear_bit (live, regno);
3580 break;
3581 default:
3582 break;
3585 df_simulate_fixup_sets (bb, live);
3588 /* Used by the next two functions to encode information about the
3589 memory references we found. */
3590 #define MEMREF_NORMAL 1
3591 #define MEMREF_VOLATILE 2
3593 /* Return an OR of MEMREF_NORMAL or MEMREF_VOLATILE for the MEMs in X. */
3595 static int
3596 find_memory (rtx insn)
3598 int flags = 0;
3599 subrtx_iterator::array_type array;
3600 FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
3602 const_rtx x = *iter;
3603 if (GET_CODE (x) == ASM_OPERANDS && MEM_VOLATILE_P (x))
3604 flags |= MEMREF_VOLATILE;
3605 else if (MEM_P (x))
3607 if (MEM_VOLATILE_P (x))
3608 flags |= MEMREF_VOLATILE;
3609 else if (!MEM_READONLY_P (x))
3610 flags |= MEMREF_NORMAL;
3613 return flags;
3616 /* A subroutine of can_move_insns_across_p called through note_stores.
3617 DATA points to an integer in which we set either the bit for
3618 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3619 of either kind. */
3621 static void
3622 find_memory_stores (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
3623 void *data ATTRIBUTE_UNUSED)
3625 int *pflags = (int *)data;
3626 if (GET_CODE (x) == SUBREG)
3627 x = XEXP (x, 0);
3628 /* Treat stores to SP as stores to memory, this will prevent problems
3629 when there are references to the stack frame. */
3630 if (x == stack_pointer_rtx)
3631 *pflags |= MEMREF_VOLATILE;
3632 if (!MEM_P (x))
3633 return;
3634 *pflags |= MEM_VOLATILE_P (x) ? MEMREF_VOLATILE : MEMREF_NORMAL;
3637 /* Scan BB backwards, using df_simulate functions to keep track of
3638 lifetimes, up to insn POINT. The result is stored in LIVE. */
3640 void
3641 simulate_backwards_to_point (basic_block bb, regset live, rtx point)
3643 rtx_insn *insn;
3644 bitmap_copy (live, df_get_live_out (bb));
3645 df_simulate_initialize_backwards (bb, live);
3647 /* Scan and update life information until we reach the point we're
3648 interested in. */
3649 for (insn = BB_END (bb); insn != point; insn = PREV_INSN (insn))
3650 df_simulate_one_insn_backwards (bb, insn, live);
3653 /* Return true if it is safe to move a group of insns, described by
3654 the range FROM to TO, backwards across another group of insns,
3655 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3656 are no insns between ACROSS_TO and FROM, but they may be in
3657 different basic blocks; MERGE_BB is the block from which the
3658 insns will be moved. The caller must pass in a regset MERGE_LIVE
3659 which specifies the registers live after TO.
3661 This function may be called in one of two cases: either we try to
3662 move identical instructions from all successor blocks into their
3663 predecessor, or we try to move from only one successor block. If
3664 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3665 the second case. It should contain a set of registers live at the
3666 end of ACROSS_TO which must not be clobbered by moving the insns.
3667 In that case, we're also more careful about moving memory references
3668 and trapping insns.
3670 We return false if it is not safe to move the entire group, but it
3671 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3672 is set to point at the last moveable insn in such a case. */
3674 bool
3675 can_move_insns_across (rtx_insn *from, rtx_insn *to,
3676 rtx_insn *across_from, rtx_insn *across_to,
3677 basic_block merge_bb, regset merge_live,
3678 regset other_branch_live, rtx_insn **pmove_upto)
3680 rtx_insn *insn, *next, *max_to;
3681 bitmap merge_set, merge_use, local_merge_live;
3682 bitmap test_set, test_use;
3683 unsigned i, fail = 0;
3684 bitmap_iterator bi;
3685 int memrefs_in_across = 0;
3686 int mem_sets_in_across = 0;
3687 bool trapping_insns_in_across = false;
3689 if (pmove_upto != NULL)
3690 *pmove_upto = NULL;
3692 /* Find real bounds, ignoring debug insns. */
3693 while (!NONDEBUG_INSN_P (from) && from != to)
3694 from = NEXT_INSN (from);
3695 while (!NONDEBUG_INSN_P (to) && from != to)
3696 to = PREV_INSN (to);
3698 for (insn = across_to; ; insn = next)
3700 if (CALL_P (insn))
3702 if (RTL_CONST_OR_PURE_CALL_P (insn))
3703 /* Pure functions can read from memory. Const functions can
3704 read from arguments that the ABI has forced onto the stack.
3705 Neither sort of read can be volatile. */
3706 memrefs_in_across |= MEMREF_NORMAL;
3707 else
3709 memrefs_in_across |= MEMREF_VOLATILE;
3710 mem_sets_in_across |= MEMREF_VOLATILE;
3713 if (NONDEBUG_INSN_P (insn))
3715 if (volatile_insn_p (PATTERN (insn)))
3716 return false;
3717 memrefs_in_across |= find_memory (insn);
3718 note_stores (PATTERN (insn), find_memory_stores,
3719 &mem_sets_in_across);
3720 /* This is used just to find sets of the stack pointer. */
3721 memrefs_in_across |= mem_sets_in_across;
3722 trapping_insns_in_across |= may_trap_p (PATTERN (insn));
3724 next = PREV_INSN (insn);
3725 if (insn == across_from)
3726 break;
3729 /* Collect:
3730 MERGE_SET = set of registers set in MERGE_BB
3731 MERGE_USE = set of registers used in MERGE_BB and live at its top
3732 MERGE_LIVE = set of registers live at the point inside the MERGE
3733 range that we've reached during scanning
3734 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3735 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3736 and live before ACROSS_FROM. */
3738 merge_set = BITMAP_ALLOC (&reg_obstack);
3739 merge_use = BITMAP_ALLOC (&reg_obstack);
3740 local_merge_live = BITMAP_ALLOC (&reg_obstack);
3741 test_set = BITMAP_ALLOC (&reg_obstack);
3742 test_use = BITMAP_ALLOC (&reg_obstack);
3744 /* Compute the set of registers set and used in the ACROSS range. */
3745 if (other_branch_live != NULL)
3746 bitmap_copy (test_use, other_branch_live);
3747 df_simulate_initialize_backwards (merge_bb, test_use);
3748 for (insn = across_to; ; insn = next)
3750 if (NONDEBUG_INSN_P (insn))
3752 df_simulate_find_defs (insn, test_set);
3753 df_simulate_defs (insn, test_use);
3754 df_simulate_uses (insn, test_use);
3756 next = PREV_INSN (insn);
3757 if (insn == across_from)
3758 break;
3761 /* Compute an upper bound for the amount of insns moved, by finding
3762 the first insn in MERGE that sets a register in TEST_USE, or uses
3763 a register in TEST_SET. We also check for calls, trapping operations,
3764 and memory references. */
3765 max_to = NULL;
3766 for (insn = from; ; insn = next)
3768 if (CALL_P (insn))
3769 break;
3770 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
3771 break;
3772 if (NONDEBUG_INSN_P (insn))
3774 if (may_trap_or_fault_p (PATTERN (insn))
3775 && (trapping_insns_in_across
3776 || other_branch_live != NULL
3777 || volatile_insn_p (PATTERN (insn))))
3778 break;
3780 /* We cannot move memory stores past each other, or move memory
3781 reads past stores, at least not without tracking them and
3782 calling true_dependence on every pair.
3784 If there is no other branch and no memory references or
3785 sets in the ACROSS range, we can move memory references
3786 freely, even volatile ones.
3788 Otherwise, the rules are as follows: volatile memory
3789 references and stores can't be moved at all, and any type
3790 of memory reference can't be moved if there are volatile
3791 accesses or stores in the ACROSS range. That leaves
3792 normal reads, which can be moved, as the trapping case is
3793 dealt with elsewhere. */
3794 if (other_branch_live != NULL || memrefs_in_across != 0)
3796 int mem_ref_flags = 0;
3797 int mem_set_flags = 0;
3798 note_stores (PATTERN (insn), find_memory_stores, &mem_set_flags);
3799 mem_ref_flags = find_memory (insn);
3800 /* Catch sets of the stack pointer. */
3801 mem_ref_flags |= mem_set_flags;
3803 if ((mem_ref_flags | mem_set_flags) & MEMREF_VOLATILE)
3804 break;
3805 if ((memrefs_in_across & MEMREF_VOLATILE) && mem_ref_flags != 0)
3806 break;
3807 if (mem_set_flags != 0
3808 || (mem_sets_in_across != 0 && mem_ref_flags != 0))
3809 break;
3811 df_simulate_find_uses (insn, merge_use);
3812 /* We're only interested in uses which use a value live at
3813 the top, not one previously set in this block. */
3814 bitmap_and_compl_into (merge_use, merge_set);
3815 df_simulate_find_defs (insn, merge_set);
3816 if (bitmap_intersect_p (merge_set, test_use)
3817 || bitmap_intersect_p (merge_use, test_set))
3818 break;
3819 #ifdef HAVE_cc0
3820 if (!sets_cc0_p (insn))
3821 #endif
3822 max_to = insn;
3824 next = NEXT_INSN (insn);
3825 if (insn == to)
3826 break;
3828 if (max_to != to)
3829 fail = 1;
3831 if (max_to == NULL_RTX || (fail && pmove_upto == NULL))
3832 goto out;
3834 /* Now, lower this upper bound by also taking into account that
3835 a range of insns moved across ACROSS must not leave a register
3836 live at the end that will be clobbered in ACROSS. We need to
3837 find a point where TEST_SET & LIVE == 0.
3839 Insns in the MERGE range that set registers which are also set
3840 in the ACROSS range may still be moved as long as we also move
3841 later insns which use the results of the set, and make the
3842 register dead again. This is verified by the condition stated
3843 above. We only need to test it for registers that are set in
3844 the moved region.
3846 MERGE_LIVE is provided by the caller and holds live registers after
3847 TO. */
3848 bitmap_copy (local_merge_live, merge_live);
3849 for (insn = to; insn != max_to; insn = PREV_INSN (insn))
3850 df_simulate_one_insn_backwards (merge_bb, insn, local_merge_live);
3852 /* We're not interested in registers that aren't set in the moved
3853 region at all. */
3854 bitmap_and_into (local_merge_live, merge_set);
3855 for (;;)
3857 if (NONDEBUG_INSN_P (insn))
3859 if (!bitmap_intersect_p (test_set, local_merge_live)
3860 #ifdef HAVE_cc0
3861 && !sets_cc0_p (insn)
3862 #endif
3865 max_to = insn;
3866 break;
3869 df_simulate_one_insn_backwards (merge_bb, insn,
3870 local_merge_live);
3872 if (insn == from)
3874 fail = 1;
3875 goto out;
3877 insn = PREV_INSN (insn);
3880 if (max_to != to)
3881 fail = 1;
3883 if (pmove_upto)
3884 *pmove_upto = max_to;
3886 /* For small register class machines, don't lengthen lifetimes of
3887 hard registers before reload. */
3888 if (! reload_completed
3889 && targetm.small_register_classes_for_mode_p (VOIDmode))
3891 EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
3893 if (i < FIRST_PSEUDO_REGISTER
3894 && ! fixed_regs[i]
3895 && ! global_regs[i])
3897 fail = 1;
3898 break;
3903 out:
3904 BITMAP_FREE (merge_set);
3905 BITMAP_FREE (merge_use);
3906 BITMAP_FREE (local_merge_live);
3907 BITMAP_FREE (test_set);
3908 BITMAP_FREE (test_use);
3910 return !fail;
3914 /*----------------------------------------------------------------------------
3915 MULTIPLE DEFINITIONS
3917 Find the locations in the function reached by multiple definition sites
3918 for a live pseudo. In and out bitvectors are built for each basic
3919 block. They are restricted for efficiency to live registers.
3921 The gen and kill sets for the problem are obvious. Together they
3922 include all defined registers in a basic block; the gen set includes
3923 registers where a partial or conditional or may-clobber definition is
3924 last in the BB, while the kill set includes registers with a complete
3925 definition coming last. However, the computation of the dataflow
3926 itself is interesting.
3928 The idea behind it comes from SSA form's iterated dominance frontier
3929 criterion for inserting PHI functions. Just like in that case, we can use
3930 the dominance frontier to find places where multiple definitions meet;
3931 a register X defined in a basic block BB1 has multiple definitions in
3932 basic blocks in BB1's dominance frontier.
3934 So, the in-set of a basic block BB2 is not just the union of the
3935 out-sets of BB2's predecessors, but includes some more bits that come
3936 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
3937 the previous paragraph). I called this set the init-set of BB2.
3939 (Note: I actually use the kill-set only to build the init-set.
3940 gen bits are anyway propagated from BB1 to BB2 by dataflow).
3942 For example, if you have
3944 BB1 : r10 = 0
3945 r11 = 0
3946 if <...> goto BB2 else goto BB3;
3948 BB2 : r10 = 1
3949 r12 = 1
3950 goto BB3;
3952 BB3 :
3954 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
3955 init-set of BB3 includes r10 and r12, but not r11. Note that we do
3956 not need to iterate the dominance frontier, because we do not insert
3957 anything like PHI functions there! Instead, dataflow will take care of
3958 propagating the information to BB3's successors.
3959 ---------------------------------------------------------------------------*/
3961 /* Private data used to verify the solution for this problem. */
3962 struct df_md_problem_data
3964 /* An obstack for the bitmaps we need for this problem. */
3965 bitmap_obstack md_bitmaps;
3968 /* Scratch var used by transfer functions. This is used to do md analysis
3969 only for live registers. */
3970 static bitmap_head df_md_scratch;
3973 static void
3974 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3975 void *vbb_info)
3977 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
3978 if (bb_info)
3980 bitmap_clear (&bb_info->kill);
3981 bitmap_clear (&bb_info->gen);
3982 bitmap_clear (&bb_info->init);
3983 bitmap_clear (&bb_info->in);
3984 bitmap_clear (&bb_info->out);
3989 /* Allocate or reset bitmaps for DF_MD. The solution bits are
3990 not touched unless the block is new. */
3992 static void
3993 df_md_alloc (bitmap all_blocks)
3995 unsigned int bb_index;
3996 bitmap_iterator bi;
3997 struct df_md_problem_data *problem_data;
3999 df_grow_bb_info (df_md);
4000 if (df_md->problem_data)
4001 problem_data = (struct df_md_problem_data *) df_md->problem_data;
4002 else
4004 problem_data = XNEW (struct df_md_problem_data);
4005 df_md->problem_data = problem_data;
4006 bitmap_obstack_initialize (&problem_data->md_bitmaps);
4008 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
4010 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4012 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4013 /* When bitmaps are already initialized, just clear them. */
4014 if (bb_info->init.obstack)
4016 bitmap_clear (&bb_info->init);
4017 bitmap_clear (&bb_info->gen);
4018 bitmap_clear (&bb_info->kill);
4019 bitmap_clear (&bb_info->in);
4020 bitmap_clear (&bb_info->out);
4022 else
4024 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4025 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4026 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4027 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4028 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
4032 df_md->optional_p = true;
4035 /* Add the effect of the top artificial defs of BB to the multiple definitions
4036 bitmap LOCAL_MD. */
4038 void
4039 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4041 int bb_index = bb->index;
4042 df_ref def;
4043 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
4044 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4046 unsigned int dregno = DF_REF_REGNO (def);
4047 if (DF_REF_FLAGS (def)
4048 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4049 bitmap_set_bit (local_md, dregno);
4050 else
4051 bitmap_clear_bit (local_md, dregno);
4056 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4057 LOCAL_MD. */
4059 void
4060 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
4061 bitmap local_md)
4063 df_ref def;
4065 FOR_EACH_INSN_DEF (def, insn)
4067 unsigned int dregno = DF_REF_REGNO (def);
4068 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4069 || (dregno >= FIRST_PSEUDO_REGISTER))
4071 if (DF_REF_FLAGS (def)
4072 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4073 bitmap_set_bit (local_md, DF_REF_ID (def));
4074 else
4075 bitmap_clear_bit (local_md, DF_REF_ID (def));
4080 static void
4081 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
4082 df_ref def,
4083 int top_flag)
4085 bitmap_clear (&seen_in_insn);
4087 for (; def; def = DF_REF_NEXT_LOC (def))
4089 unsigned int dregno = DF_REF_REGNO (def);
4090 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4091 || (dregno >= FIRST_PSEUDO_REGISTER))
4092 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4094 if (!bitmap_bit_p (&seen_in_insn, dregno))
4096 if (DF_REF_FLAGS (def)
4097 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4099 bitmap_set_bit (&bb_info->gen, dregno);
4100 bitmap_clear_bit (&bb_info->kill, dregno);
4102 else
4104 /* When we find a clobber and a regular def,
4105 make sure the regular def wins. */
4106 bitmap_set_bit (&seen_in_insn, dregno);
4107 bitmap_set_bit (&bb_info->kill, dregno);
4108 bitmap_clear_bit (&bb_info->gen, dregno);
4116 /* Compute local multiple def info for basic block BB. */
4118 static void
4119 df_md_bb_local_compute (unsigned int bb_index)
4121 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4122 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4123 rtx_insn *insn;
4125 /* Artificials are only hard regs. */
4126 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4127 df_md_bb_local_compute_process_def (bb_info,
4128 df_get_artificial_defs (bb_index),
4129 DF_REF_AT_TOP);
4131 FOR_BB_INSNS (bb, insn)
4133 unsigned int uid = INSN_UID (insn);
4134 if (!INSN_P (insn))
4135 continue;
4137 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4140 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4141 df_md_bb_local_compute_process_def (bb_info,
4142 df_get_artificial_defs (bb_index),
4146 /* Compute local reaching def info for each basic block within BLOCKS. */
4148 static void
4149 df_md_local_compute (bitmap all_blocks)
4151 unsigned int bb_index, df_bb_index;
4152 bitmap_iterator bi1, bi2;
4153 basic_block bb;
4154 bitmap_head *frontiers;
4156 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4158 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4160 df_md_bb_local_compute (bb_index);
4163 bitmap_clear (&seen_in_insn);
4165 frontiers = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
4166 FOR_ALL_BB_FN (bb, cfun)
4167 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4169 compute_dominance_frontiers (frontiers);
4171 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4172 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4174 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4175 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4177 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, df_bb_index);
4178 if (bitmap_bit_p (all_blocks, df_bb_index))
4179 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4180 df_get_live_in (bb));
4184 FOR_ALL_BB_FN (bb, cfun)
4185 bitmap_clear (&frontiers[bb->index]);
4186 free (frontiers);
4190 /* Reset the global solution for recalculation. */
4192 static void
4193 df_md_reset (bitmap all_blocks)
4195 unsigned int bb_index;
4196 bitmap_iterator bi;
4198 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4200 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4201 gcc_assert (bb_info);
4202 bitmap_clear (&bb_info->in);
4203 bitmap_clear (&bb_info->out);
4207 static bool
4208 df_md_transfer_function (int bb_index)
4210 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4211 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4212 bitmap in = &bb_info->in;
4213 bitmap out = &bb_info->out;
4214 bitmap gen = &bb_info->gen;
4215 bitmap kill = &bb_info->kill;
4217 /* We need to use a scratch set here so that the value returned from this
4218 function invocation properly reflects whether the sets changed in a
4219 significant way; i.e. not just because the live set was anded in. */
4220 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4222 /* Multiple definitions of a register are not relevant if it is not
4223 live. Thus we trim the result to the places where it is live. */
4224 bitmap_and_into (in, df_get_live_in (bb));
4226 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4229 /* Initialize the solution bit vectors for problem. */
4231 static void
4232 df_md_init (bitmap all_blocks)
4234 unsigned int bb_index;
4235 bitmap_iterator bi;
4237 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4239 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4241 bitmap_copy (&bb_info->in, &bb_info->init);
4242 df_md_transfer_function (bb_index);
4246 static void
4247 df_md_confluence_0 (basic_block bb)
4249 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4250 bitmap_copy (&bb_info->in, &bb_info->init);
4253 /* In of target gets or of out of source. */
4255 static bool
4256 df_md_confluence_n (edge e)
4258 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4259 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4261 if (e->flags & EDGE_FAKE)
4262 return false;
4264 if (e->flags & EDGE_EH)
4265 return bitmap_ior_and_compl_into (op1, op2,
4266 regs_invalidated_by_call_regset);
4267 else
4268 return bitmap_ior_into (op1, op2);
4271 /* Free all storage associated with the problem. */
4273 static void
4274 df_md_free (void)
4276 struct df_md_problem_data *problem_data
4277 = (struct df_md_problem_data *) df_md->problem_data;
4279 bitmap_obstack_release (&problem_data->md_bitmaps);
4280 free (problem_data);
4281 df_md->problem_data = NULL;
4283 df_md->block_info_size = 0;
4284 free (df_md->block_info);
4285 df_md->block_info = NULL;
4286 free (df_md);
4290 /* Debugging info at top of bb. */
4292 static void
4293 df_md_top_dump (basic_block bb, FILE *file)
4295 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4296 if (!bb_info)
4297 return;
4299 fprintf (file, ";; md in \t");
4300 df_print_regset (file, &bb_info->in);
4301 fprintf (file, ";; md init \t");
4302 df_print_regset (file, &bb_info->init);
4303 fprintf (file, ";; md gen \t");
4304 df_print_regset (file, &bb_info->gen);
4305 fprintf (file, ";; md kill \t");
4306 df_print_regset (file, &bb_info->kill);
4309 /* Debugging info at bottom of bb. */
4311 static void
4312 df_md_bottom_dump (basic_block bb, FILE *file)
4314 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4315 if (!bb_info)
4316 return;
4318 fprintf (file, ";; md out \t");
4319 df_print_regset (file, &bb_info->out);
4322 static struct df_problem problem_MD =
4324 DF_MD, /* Problem id. */
4325 DF_FORWARD, /* Direction. */
4326 df_md_alloc, /* Allocate the problem specific data. */
4327 df_md_reset, /* Reset global information. */
4328 df_md_free_bb_info, /* Free basic block info. */
4329 df_md_local_compute, /* Local compute function. */
4330 df_md_init, /* Init the solution specific data. */
4331 df_worklist_dataflow, /* Worklist solver. */
4332 df_md_confluence_0, /* Confluence operator 0. */
4333 df_md_confluence_n, /* Confluence operator n. */
4334 df_md_transfer_function, /* Transfer function. */
4335 NULL, /* Finalize function. */
4336 df_md_free, /* Free all of the problem information. */
4337 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4338 NULL, /* Debugging. */
4339 df_md_top_dump, /* Debugging start block. */
4340 df_md_bottom_dump, /* Debugging end block. */
4341 NULL, /* Debugging start insn. */
4342 NULL, /* Debugging end insn. */
4343 NULL, /* Incremental solution verify start. */
4344 NULL, /* Incremental solution verify end. */
4345 NULL, /* Dependent problem. */
4346 sizeof (struct df_md_bb_info),/* Size of entry of block_info array. */
4347 TV_DF_MD, /* Timing variable. */
4348 false /* Reset blocks on dropping out of blocks_to_analyze. */
4351 /* Create a new MD instance and add it to the existing instance
4352 of DF. */
4354 void
4355 df_md_add_problem (void)
4357 df_add_problem (&problem_MD);