* config/rx/rx.c (add_vector_labels): New.
[official-gcc.git] / gcc / df-problems.c
blob77f8c9922b440b5fa7a39234d3aa88ba8b1d1cb2
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2014 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tm_p.h"
30 #include "insn-config.h"
31 #include "recog.h"
32 #include "function.h"
33 #include "regs.h"
34 #include "alloc-pool.h"
35 #include "flags.h"
36 #include "hard-reg-set.h"
37 #include "basic-block.h"
38 #include "sbitmap.h"
39 #include "bitmap.h"
40 #include "target.h"
41 #include "timevar.h"
42 #include "df.h"
43 #include "except.h"
44 #include "dce.h"
45 #include "valtrack.h"
46 #include "dumpfile.h"
48 /* Note that turning REG_DEAD_DEBUGGING on will cause
49 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
50 addresses in the dumps. */
51 #define REG_DEAD_DEBUGGING 0
53 #define DF_SPARSE_THRESHOLD 32
55 static bitmap_head seen_in_block;
56 static bitmap_head seen_in_insn;
58 /*----------------------------------------------------------------------------
59 Utility functions.
60 ----------------------------------------------------------------------------*/
62 /* Generic versions to get the void* version of the block info. Only
63 used inside the problem instance vectors. */
65 /* Dump a def-use or use-def chain for REF to FILE. */
67 void
68 df_chain_dump (struct df_link *link, FILE *file)
70 fprintf (file, "{ ");
71 for (; link; link = link->next)
73 fprintf (file, "%c%d(bb %d insn %d) ",
74 DF_REF_REG_DEF_P (link->ref)
75 ? 'd'
76 : (DF_REF_FLAGS (link->ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
77 DF_REF_ID (link->ref),
78 DF_REF_BBNO (link->ref),
79 DF_REF_IS_ARTIFICIAL (link->ref)
80 ? -1 : DF_REF_INSN_UID (link->ref));
82 fprintf (file, "}");
86 /* Print some basic block info as part of df_dump. */
88 void
89 df_print_bb_index (basic_block bb, FILE *file)
91 edge e;
92 edge_iterator ei;
94 fprintf (file, "\n( ");
95 FOR_EACH_EDGE (e, ei, bb->preds)
97 basic_block pred = e->src;
98 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
100 fprintf (file, ")->[%d]->( ", bb->index);
101 FOR_EACH_EDGE (e, ei, bb->succs)
103 basic_block succ = e->dest;
104 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
106 fprintf (file, ")\n");
110 /*----------------------------------------------------------------------------
111 REACHING DEFINITIONS
113 Find the locations in the function where each definition site for a
114 pseudo reaches. In and out bitvectors are built for each basic
115 block. The id field in the ref is used to index into these sets.
116 See df.h for details.
118 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
119 existing uses are included in the global reaching DEFs set, or in other
120 words only DEFs that are still live. This is a kind of pruned version
121 of the traditional reaching definitions problem that is much less
122 complex to compute and produces enough information to compute UD-chains.
123 In this context, live must be interpreted in the DF_LR sense: Uses that
124 are upward exposed but maybe not initialized on all paths through the
125 CFG. For a USE that is not reached by a DEF on all paths, we still want
126 to make those DEFs that do reach the USE visible, and pruning based on
127 DF_LIVE would make that impossible.
128 ----------------------------------------------------------------------------*/
130 /* This problem plays a large number of games for the sake of
131 efficiency.
133 1) The order of the bits in the bitvectors. After the scanning
134 phase, all of the defs are sorted. All of the defs for the reg 0
135 are first, followed by all defs for reg 1 and so on.
137 2) There are two kill sets, one if the number of defs is less or
138 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
139 greater.
141 <= : Data is built directly in the kill set.
143 > : One level of indirection is used to keep from generating long
144 strings of 1 bits in the kill sets. Bitvectors that are indexed
145 by the regnum are used to represent that there is a killing def
146 for the register. The confluence and transfer functions use
147 these along with the bitmap_clear_range call to remove ranges of
148 bits without actually generating a knockout vector.
150 The kill and sparse_kill and the dense_invalidated_by_call and
151 sparse_invalidated_by_call both play this game. */
153 /* Private data used to compute the solution for this problem. These
154 data structures are not accessible outside of this module. */
155 struct df_rd_problem_data
157 /* The set of defs to regs invalidated by call. */
158 bitmap_head sparse_invalidated_by_call;
159 /* The set of defs to regs invalidate by call for rd. */
160 bitmap_head dense_invalidated_by_call;
161 /* An obstack for the bitmaps we need for this problem. */
162 bitmap_obstack rd_bitmaps;
166 /* Free basic block info. */
168 static void
169 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
170 void *vbb_info)
172 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
173 if (bb_info)
175 bitmap_clear (&bb_info->kill);
176 bitmap_clear (&bb_info->sparse_kill);
177 bitmap_clear (&bb_info->gen);
178 bitmap_clear (&bb_info->in);
179 bitmap_clear (&bb_info->out);
184 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
185 not touched unless the block is new. */
187 static void
188 df_rd_alloc (bitmap all_blocks)
190 unsigned int bb_index;
191 bitmap_iterator bi;
192 struct df_rd_problem_data *problem_data;
194 if (df_rd->problem_data)
196 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
197 bitmap_clear (&problem_data->sparse_invalidated_by_call);
198 bitmap_clear (&problem_data->dense_invalidated_by_call);
200 else
202 problem_data = XNEW (struct df_rd_problem_data);
203 df_rd->problem_data = problem_data;
205 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
206 bitmap_initialize (&problem_data->sparse_invalidated_by_call,
207 &problem_data->rd_bitmaps);
208 bitmap_initialize (&problem_data->dense_invalidated_by_call,
209 &problem_data->rd_bitmaps);
212 df_grow_bb_info (df_rd);
214 /* Because of the clustering of all use sites for the same pseudo,
215 we have to process all of the blocks before doing the analysis. */
217 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
219 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
221 /* When bitmaps are already initialized, just clear them. */
222 if (bb_info->kill.obstack)
224 bitmap_clear (&bb_info->kill);
225 bitmap_clear (&bb_info->sparse_kill);
226 bitmap_clear (&bb_info->gen);
228 else
230 bitmap_initialize (&bb_info->kill, &problem_data->rd_bitmaps);
231 bitmap_initialize (&bb_info->sparse_kill, &problem_data->rd_bitmaps);
232 bitmap_initialize (&bb_info->gen, &problem_data->rd_bitmaps);
233 bitmap_initialize (&bb_info->in, &problem_data->rd_bitmaps);
234 bitmap_initialize (&bb_info->out, &problem_data->rd_bitmaps);
237 df_rd->optional_p = true;
241 /* Add the effect of the top artificial defs of BB to the reaching definitions
242 bitmap LOCAL_RD. */
244 void
245 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
247 int bb_index = bb->index;
248 df_ref *def_rec;
249 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
251 df_ref def = *def_rec;
252 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
254 unsigned int dregno = DF_REF_REGNO (def);
255 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
256 bitmap_clear_range (local_rd,
257 DF_DEFS_BEGIN (dregno),
258 DF_DEFS_COUNT (dregno));
259 bitmap_set_bit (local_rd, DF_REF_ID (def));
264 /* Add the effect of the defs of INSN to the reaching definitions bitmap
265 LOCAL_RD. */
267 void
268 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
269 bitmap local_rd)
271 unsigned uid = INSN_UID (insn);
272 df_ref *def_rec;
274 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
276 df_ref def = *def_rec;
277 unsigned int dregno = DF_REF_REGNO (def);
278 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
279 || (dregno >= FIRST_PSEUDO_REGISTER))
281 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
282 bitmap_clear_range (local_rd,
283 DF_DEFS_BEGIN (dregno),
284 DF_DEFS_COUNT (dregno));
285 if (!(DF_REF_FLAGS (def)
286 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
287 bitmap_set_bit (local_rd, DF_REF_ID (def));
292 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
293 more complicated than just simulating, because we must produce the
294 gen and kill sets and hence deal with the two possible representations
295 of kill sets. */
297 static void
298 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
299 df_ref *def_rec,
300 int top_flag)
302 while (*def_rec)
304 df_ref def = *def_rec;
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));
347 def_rec++;
351 /* Compute local reaching def info for basic block BB. */
353 static void
354 df_rd_bb_local_compute (unsigned int bb_index)
356 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
357 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
358 rtx insn;
360 bitmap_clear (&seen_in_block);
361 bitmap_clear (&seen_in_insn);
363 /* Artificials are only hard regs. */
364 if (!(df->changeable_flags & DF_NO_HARD_REGS))
365 df_rd_bb_local_compute_process_def (bb_info,
366 df_get_artificial_defs (bb_index),
369 FOR_BB_INSNS_REVERSE (bb, insn)
371 unsigned int uid = INSN_UID (insn);
373 if (!INSN_P (insn))
374 continue;
376 df_rd_bb_local_compute_process_def (bb_info,
377 DF_INSN_UID_DEFS (uid), 0);
379 /* This complex dance with the two bitmaps is required because
380 instructions can assign twice to the same pseudo. This
381 generally happens with calls that will have one def for the
382 result and another def for the clobber. If only one vector
383 is used and the clobber goes first, the result will be
384 lost. */
385 bitmap_ior_into (&seen_in_block, &seen_in_insn);
386 bitmap_clear (&seen_in_insn);
389 /* Process the artificial defs at the top of the block last since we
390 are going backwards through the block and these are logically at
391 the start. */
392 if (!(df->changeable_flags & DF_NO_HARD_REGS))
393 df_rd_bb_local_compute_process_def (bb_info,
394 df_get_artificial_defs (bb_index),
395 DF_REF_AT_TOP);
399 /* Compute local reaching def info for each basic block within BLOCKS. */
401 static void
402 df_rd_local_compute (bitmap all_blocks)
404 unsigned int bb_index;
405 bitmap_iterator bi;
406 unsigned int regno;
407 struct df_rd_problem_data *problem_data
408 = (struct df_rd_problem_data *) df_rd->problem_data;
409 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
410 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
412 bitmap_initialize (&seen_in_block, &df_bitmap_obstack);
413 bitmap_initialize (&seen_in_insn, &df_bitmap_obstack);
415 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
417 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
419 df_rd_bb_local_compute (bb_index);
422 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
423 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, regno, bi)
425 if (! HARD_REGISTER_NUM_P (regno)
426 || !(df->changeable_flags & DF_NO_HARD_REGS))
428 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
429 bitmap_set_bit (sparse_invalidated, regno);
430 else
431 bitmap_set_range (dense_invalidated,
432 DF_DEFS_BEGIN (regno),
433 DF_DEFS_COUNT (regno));
437 bitmap_clear (&seen_in_block);
438 bitmap_clear (&seen_in_insn);
442 /* Initialize the solution bit vectors for problem. */
444 static void
445 df_rd_init_solution (bitmap all_blocks)
447 unsigned int bb_index;
448 bitmap_iterator bi;
450 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
452 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
454 bitmap_copy (&bb_info->out, &bb_info->gen);
455 bitmap_clear (&bb_info->in);
459 /* In of target gets or of out of source. */
461 static bool
462 df_rd_confluence_n (edge e)
464 bitmap op1 = &df_rd_get_bb_info (e->dest->index)->in;
465 bitmap op2 = &df_rd_get_bb_info (e->src->index)->out;
466 bool changed = false;
468 if (e->flags & EDGE_FAKE)
469 return false;
471 if (e->flags & EDGE_EH)
473 struct df_rd_problem_data *problem_data
474 = (struct df_rd_problem_data *) df_rd->problem_data;
475 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
476 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
477 bitmap_iterator bi;
478 unsigned int regno;
479 bitmap_head tmp;
481 bitmap_initialize (&tmp, &df_bitmap_obstack);
482 bitmap_and_compl (&tmp, op2, dense_invalidated);
484 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
486 bitmap_clear_range (&tmp,
487 DF_DEFS_BEGIN (regno),
488 DF_DEFS_COUNT (regno));
490 changed |= bitmap_ior_into (op1, &tmp);
491 bitmap_clear (&tmp);
492 return changed;
494 else
495 return bitmap_ior_into (op1, op2);
499 /* Transfer function. */
501 static bool
502 df_rd_transfer_function (int bb_index)
504 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
505 unsigned int regno;
506 bitmap_iterator bi;
507 bitmap in = &bb_info->in;
508 bitmap out = &bb_info->out;
509 bitmap gen = &bb_info->gen;
510 bitmap kill = &bb_info->kill;
511 bitmap sparse_kill = &bb_info->sparse_kill;
512 bool changed = false;
514 if (bitmap_empty_p (sparse_kill))
515 changed = bitmap_ior_and_compl (out, gen, in, kill);
516 else
518 struct df_rd_problem_data *problem_data;
519 bitmap_head tmp;
521 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
522 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
523 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
524 bitmap_initialize (&tmp, &problem_data->rd_bitmaps);
526 bitmap_and_compl (&tmp, in, kill);
527 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
529 bitmap_clear_range (&tmp,
530 DF_DEFS_BEGIN (regno),
531 DF_DEFS_COUNT (regno));
533 bitmap_ior_into (&tmp, gen);
534 changed = !bitmap_equal_p (&tmp, out);
535 if (changed)
537 bitmap_clear (out);
538 bb_info->out = tmp;
540 else
541 bitmap_clear (&tmp);
544 if (df->changeable_flags & DF_RD_PRUNE_DEAD_DEFS)
546 /* Create a mask of DEFs for all registers live at the end of this
547 basic block, and mask out DEFs of registers that are not live.
548 Computing the mask looks costly, but the benefit of the pruning
549 outweighs the cost. */
550 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
551 bitmap regs_live_out = &df_lr_get_bb_info (bb_index)->out;
552 bitmap live_defs = BITMAP_ALLOC (&df_bitmap_obstack);
553 unsigned int regno;
554 bitmap_iterator bi;
556 EXECUTE_IF_SET_IN_BITMAP (regs_live_out, 0, regno, bi)
557 bitmap_set_range (live_defs,
558 DF_DEFS_BEGIN (regno),
559 DF_DEFS_COUNT (regno));
560 changed |= bitmap_and_into (&bb_info->out, live_defs);
561 BITMAP_FREE (live_defs);
564 return changed;
567 /* Free all storage associated with the problem. */
569 static void
570 df_rd_free (void)
572 struct df_rd_problem_data *problem_data
573 = (struct df_rd_problem_data *) df_rd->problem_data;
575 if (problem_data)
577 bitmap_obstack_release (&problem_data->rd_bitmaps);
579 df_rd->block_info_size = 0;
580 free (df_rd->block_info);
581 df_rd->block_info = NULL;
582 free (df_rd->problem_data);
584 free (df_rd);
588 /* Debugging info. */
590 static void
591 df_rd_start_dump (FILE *file)
593 struct df_rd_problem_data *problem_data
594 = (struct df_rd_problem_data *) df_rd->problem_data;
595 unsigned int m = DF_REG_SIZE (df);
596 unsigned int regno;
598 if (!df_rd->block_info)
599 return;
601 fprintf (file, ";; Reaching defs:\n");
603 fprintf (file, ";; sparse invalidated \t");
604 dump_bitmap (file, &problem_data->sparse_invalidated_by_call);
605 fprintf (file, ";; dense invalidated \t");
606 dump_bitmap (file, &problem_data->dense_invalidated_by_call);
608 fprintf (file, ";; reg->defs[] map:\t");
609 for (regno = 0; regno < m; regno++)
610 if (DF_DEFS_COUNT (regno))
611 fprintf (file, "%d[%d,%d] ", regno,
612 DF_DEFS_BEGIN (regno),
613 DF_DEFS_BEGIN (regno) + DF_DEFS_COUNT (regno) - 1);
614 fprintf (file, "\n");
618 static void
619 df_rd_dump_defs_set (bitmap defs_set, const char *prefix, FILE *file)
621 bitmap_head tmp;
622 unsigned int regno;
623 unsigned int m = DF_REG_SIZE (df);
624 bool first_reg = true;
626 fprintf (file, "%s\t(%d) ", prefix, (int) bitmap_count_bits (defs_set));
628 bitmap_initialize (&tmp, &df_bitmap_obstack);
629 for (regno = 0; regno < m; regno++)
631 if (HARD_REGISTER_NUM_P (regno)
632 && (df->changeable_flags & DF_NO_HARD_REGS))
633 continue;
634 bitmap_set_range (&tmp, DF_DEFS_BEGIN (regno), DF_DEFS_COUNT (regno));
635 bitmap_and_into (&tmp, defs_set);
636 if (! bitmap_empty_p (&tmp))
638 bitmap_iterator bi;
639 unsigned int ix;
640 bool first_def = true;
642 if (! first_reg)
643 fprintf (file, ",");
644 first_reg = false;
646 fprintf (file, "%u[", regno);
647 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, ix, bi)
649 fprintf (file, "%s%u", first_def ? "" : ",", ix);
650 first_def = false;
652 fprintf (file, "]");
654 bitmap_clear (&tmp);
657 fprintf (file, "\n");
658 bitmap_clear (&tmp);
661 /* Debugging info at top of bb. */
663 static void
664 df_rd_top_dump (basic_block bb, FILE *file)
666 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
667 if (!bb_info)
668 return;
670 df_rd_dump_defs_set (&bb_info->in, ";; rd in ", file);
671 df_rd_dump_defs_set (&bb_info->gen, ";; rd gen ", file);
672 df_rd_dump_defs_set (&bb_info->kill, ";; rd kill", file);
676 /* Debugging info at bottom of bb. */
678 static void
679 df_rd_bottom_dump (basic_block bb, FILE *file)
681 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
682 if (!bb_info)
683 return;
685 df_rd_dump_defs_set (&bb_info->out, ";; rd out ", file);
688 /* All of the information associated with every instance of the problem. */
690 static struct df_problem problem_RD =
692 DF_RD, /* Problem id. */
693 DF_FORWARD, /* Direction. */
694 df_rd_alloc, /* Allocate the problem specific data. */
695 NULL, /* Reset global information. */
696 df_rd_free_bb_info, /* Free basic block info. */
697 df_rd_local_compute, /* Local compute function. */
698 df_rd_init_solution, /* Init the solution specific data. */
699 df_worklist_dataflow, /* Worklist solver. */
700 NULL, /* Confluence operator 0. */
701 df_rd_confluence_n, /* Confluence operator n. */
702 df_rd_transfer_function, /* Transfer function. */
703 NULL, /* Finalize function. */
704 df_rd_free, /* Free all of the problem information. */
705 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
706 df_rd_start_dump, /* Debugging. */
707 df_rd_top_dump, /* Debugging start block. */
708 df_rd_bottom_dump, /* Debugging end block. */
709 NULL, /* Debugging start insn. */
710 NULL, /* Debugging end insn. */
711 NULL, /* Incremental solution verify start. */
712 NULL, /* Incremental solution verify end. */
713 NULL, /* Dependent problem. */
714 sizeof (struct df_rd_bb_info),/* Size of entry of block_info array. */
715 TV_DF_RD, /* Timing variable. */
716 true /* Reset blocks on dropping out of blocks_to_analyze. */
721 /* Create a new RD instance and add it to the existing instance
722 of DF. */
724 void
725 df_rd_add_problem (void)
727 df_add_problem (&problem_RD);
732 /*----------------------------------------------------------------------------
733 LIVE REGISTERS
735 Find the locations in the function where any use of a pseudo can
736 reach in the backwards direction. In and out bitvectors are built
737 for each basic block. The regno is used to index into these sets.
738 See df.h for details.
739 ----------------------------------------------------------------------------*/
741 /* Private data used to verify the solution for this problem. */
742 struct df_lr_problem_data
744 bitmap_head *in;
745 bitmap_head *out;
746 /* An obstack for the bitmaps we need for this problem. */
747 bitmap_obstack lr_bitmaps;
750 /* Free basic block info. */
752 static void
753 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
754 void *vbb_info)
756 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
757 if (bb_info)
759 bitmap_clear (&bb_info->use);
760 bitmap_clear (&bb_info->def);
761 bitmap_clear (&bb_info->in);
762 bitmap_clear (&bb_info->out);
767 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
768 not touched unless the block is new. */
770 static void
771 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
773 unsigned int bb_index;
774 bitmap_iterator bi;
775 struct df_lr_problem_data *problem_data;
777 df_grow_bb_info (df_lr);
778 if (df_lr->problem_data)
779 problem_data = (struct df_lr_problem_data *) df_lr->problem_data;
780 else
782 problem_data = XNEW (struct df_lr_problem_data);
783 df_lr->problem_data = problem_data;
785 problem_data->out = NULL;
786 problem_data->in = NULL;
787 bitmap_obstack_initialize (&problem_data->lr_bitmaps);
790 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
792 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
794 /* When bitmaps are already initialized, just clear them. */
795 if (bb_info->use.obstack)
797 bitmap_clear (&bb_info->def);
798 bitmap_clear (&bb_info->use);
800 else
802 bitmap_initialize (&bb_info->use, &problem_data->lr_bitmaps);
803 bitmap_initialize (&bb_info->def, &problem_data->lr_bitmaps);
804 bitmap_initialize (&bb_info->in, &problem_data->lr_bitmaps);
805 bitmap_initialize (&bb_info->out, &problem_data->lr_bitmaps);
809 df_lr->optional_p = false;
813 /* Reset the global solution for recalculation. */
815 static void
816 df_lr_reset (bitmap all_blocks)
818 unsigned int bb_index;
819 bitmap_iterator bi;
821 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
823 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
824 gcc_assert (bb_info);
825 bitmap_clear (&bb_info->in);
826 bitmap_clear (&bb_info->out);
831 /* Compute local live register info for basic block BB. */
833 static void
834 df_lr_bb_local_compute (unsigned int bb_index)
836 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
837 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
838 rtx insn;
839 df_ref *def_rec;
840 df_ref *use_rec;
842 /* Process the registers set in an exception handler. */
843 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
845 df_ref def = *def_rec;
846 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
848 unsigned int dregno = DF_REF_REGNO (def);
849 bitmap_set_bit (&bb_info->def, dregno);
850 bitmap_clear_bit (&bb_info->use, dregno);
854 /* Process the hardware registers that are always live. */
855 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
857 df_ref use = *use_rec;
858 /* Add use to set of uses in this BB. */
859 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
860 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
863 FOR_BB_INSNS_REVERSE (bb, insn)
865 unsigned int uid = INSN_UID (insn);
867 if (!NONDEBUG_INSN_P (insn))
868 continue;
870 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
872 df_ref def = *def_rec;
873 /* If the def is to only part of the reg, it does
874 not kill the other defs that reach here. */
875 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
877 unsigned int dregno = DF_REF_REGNO (def);
878 bitmap_set_bit (&bb_info->def, dregno);
879 bitmap_clear_bit (&bb_info->use, dregno);
883 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
885 df_ref use = *use_rec;
886 /* Add use to set of uses in this BB. */
887 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
891 /* Process the registers set in an exception handler or the hard
892 frame pointer if this block is the target of a non local
893 goto. */
894 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
896 df_ref def = *def_rec;
897 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
899 unsigned int dregno = DF_REF_REGNO (def);
900 bitmap_set_bit (&bb_info->def, dregno);
901 bitmap_clear_bit (&bb_info->use, dregno);
905 #ifdef EH_USES
906 /* Process the uses that are live into an exception handler. */
907 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
909 df_ref use = *use_rec;
910 /* Add use to set of uses in this BB. */
911 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
912 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
914 #endif
916 /* If the df_live problem is not defined, such as at -O0 and -O1, we
917 still need to keep the luids up to date. This is normally done
918 in the df_live problem since this problem has a forwards
919 scan. */
920 if (!df_live)
921 df_recompute_luids (bb);
925 /* Compute local live register info for each basic block within BLOCKS. */
927 static void
928 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
930 unsigned int bb_index, i;
931 bitmap_iterator bi;
933 bitmap_clear (&df->hardware_regs_used);
935 /* The all-important stack pointer must always be live. */
936 bitmap_set_bit (&df->hardware_regs_used, STACK_POINTER_REGNUM);
938 /* Global regs are always live, too. */
939 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
940 if (global_regs[i])
941 bitmap_set_bit (&df->hardware_regs_used, i);
943 /* Before reload, there are a few registers that must be forced
944 live everywhere -- which might not already be the case for
945 blocks within infinite loops. */
946 if (!reload_completed)
948 unsigned int pic_offset_table_regnum = PIC_OFFSET_TABLE_REGNUM;
949 /* Any reference to any pseudo before reload is a potential
950 reference of the frame pointer. */
951 bitmap_set_bit (&df->hardware_regs_used, FRAME_POINTER_REGNUM);
953 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
954 /* Pseudos with argument area equivalences may require
955 reloading via the argument pointer. */
956 if (fixed_regs[ARG_POINTER_REGNUM])
957 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
958 #endif
960 /* Any constant, or pseudo with constant equivalences, may
961 require reloading from memory using the pic register. */
962 if (pic_offset_table_regnum != INVALID_REGNUM
963 && fixed_regs[pic_offset_table_regnum])
964 bitmap_set_bit (&df->hardware_regs_used, pic_offset_table_regnum);
967 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
969 if (bb_index == EXIT_BLOCK)
971 /* The exit block is special for this problem and its bits are
972 computed from thin air. */
973 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
974 bitmap_copy (&bb_info->use, df->exit_block_uses);
976 else
977 df_lr_bb_local_compute (bb_index);
980 bitmap_clear (df_lr->out_of_date_transfer_functions);
984 /* Initialize the solution vectors. */
986 static void
987 df_lr_init (bitmap all_blocks)
989 unsigned int bb_index;
990 bitmap_iterator bi;
992 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
994 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
995 bitmap_copy (&bb_info->in, &bb_info->use);
996 bitmap_clear (&bb_info->out);
1001 /* Confluence function that processes infinite loops. This might be a
1002 noreturn function that throws. And even if it isn't, getting the
1003 unwind info right helps debugging. */
1004 static void
1005 df_lr_confluence_0 (basic_block bb)
1007 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
1008 if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
1009 bitmap_copy (op1, &df->hardware_regs_used);
1013 /* Confluence function that ignores fake edges. */
1015 static bool
1016 df_lr_confluence_n (edge e)
1018 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
1019 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
1020 bool changed = false;
1022 /* Call-clobbered registers die across exception and call edges. */
1023 /* ??? Abnormal call edges ignored for the moment, as this gets
1024 confused by sibling call edges, which crashes reg-stack. */
1025 if (e->flags & EDGE_EH)
1026 changed = bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
1027 else
1028 changed = bitmap_ior_into (op1, op2);
1030 changed |= bitmap_ior_into (op1, &df->hardware_regs_used);
1031 return changed;
1035 /* Transfer function. */
1037 static bool
1038 df_lr_transfer_function (int bb_index)
1040 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1041 bitmap in = &bb_info->in;
1042 bitmap out = &bb_info->out;
1043 bitmap use = &bb_info->use;
1044 bitmap def = &bb_info->def;
1046 return bitmap_ior_and_compl (in, use, out, def);
1050 /* Run the fast dce as a side effect of building LR. */
1052 static void
1053 df_lr_finalize (bitmap all_blocks)
1055 df_lr->solutions_dirty = false;
1056 if (df->changeable_flags & DF_LR_RUN_DCE)
1058 run_fast_df_dce ();
1060 /* If dce deletes some instructions, we need to recompute the lr
1061 solution before proceeding further. The problem is that fast
1062 dce is a pessimestic dataflow algorithm. In the case where
1063 it deletes a statement S inside of a loop, the uses inside of
1064 S may not be deleted from the dataflow solution because they
1065 were carried around the loop. While it is conservatively
1066 correct to leave these extra bits, the standards of df
1067 require that we maintain the best possible (least fixed
1068 point) solution. The only way to do that is to redo the
1069 iteration from the beginning. See PR35805 for an
1070 example. */
1071 if (df_lr->solutions_dirty)
1073 df_clear_flags (DF_LR_RUN_DCE);
1074 df_lr_alloc (all_blocks);
1075 df_lr_local_compute (all_blocks);
1076 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1077 df_lr_finalize (all_blocks);
1078 df_set_flags (DF_LR_RUN_DCE);
1084 /* Free all storage associated with the problem. */
1086 static void
1087 df_lr_free (void)
1089 struct df_lr_problem_data *problem_data
1090 = (struct df_lr_problem_data *) df_lr->problem_data;
1091 if (df_lr->block_info)
1094 df_lr->block_info_size = 0;
1095 free (df_lr->block_info);
1096 df_lr->block_info = NULL;
1097 bitmap_obstack_release (&problem_data->lr_bitmaps);
1098 free (df_lr->problem_data);
1099 df_lr->problem_data = NULL;
1102 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1103 free (df_lr);
1107 /* Debugging info at top of bb. */
1109 static void
1110 df_lr_top_dump (basic_block bb, FILE *file)
1112 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1113 struct df_lr_problem_data *problem_data;
1114 if (!bb_info)
1115 return;
1117 fprintf (file, ";; lr in \t");
1118 df_print_regset (file, &bb_info->in);
1119 if (df_lr->problem_data)
1121 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1122 if (problem_data->in)
1124 fprintf (file, ";; old in \t");
1125 df_print_regset (file, &problem_data->in[bb->index]);
1128 fprintf (file, ";; lr use \t");
1129 df_print_regset (file, &bb_info->use);
1130 fprintf (file, ";; lr def \t");
1131 df_print_regset (file, &bb_info->def);
1135 /* Debugging info at bottom of bb. */
1137 static void
1138 df_lr_bottom_dump (basic_block bb, FILE *file)
1140 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1141 struct df_lr_problem_data *problem_data;
1142 if (!bb_info)
1143 return;
1145 fprintf (file, ";; lr out \t");
1146 df_print_regset (file, &bb_info->out);
1147 if (df_lr->problem_data)
1149 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1150 if (problem_data->out)
1152 fprintf (file, ";; old out \t");
1153 df_print_regset (file, &problem_data->out[bb->index]);
1159 /* Build the datastructure to verify that the solution to the dataflow
1160 equations is not dirty. */
1162 static void
1163 df_lr_verify_solution_start (void)
1165 basic_block bb;
1166 struct df_lr_problem_data *problem_data;
1167 if (df_lr->solutions_dirty)
1168 return;
1170 /* Set it true so that the solution is recomputed. */
1171 df_lr->solutions_dirty = true;
1173 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1174 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1175 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1177 FOR_ALL_BB_FN (bb, cfun)
1179 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1180 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1181 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1182 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1187 /* Compare the saved datastructure and the new solution to the dataflow
1188 equations. */
1190 static void
1191 df_lr_verify_solution_end (void)
1193 struct df_lr_problem_data *problem_data;
1194 basic_block bb;
1196 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1198 if (!problem_data->out)
1199 return;
1201 if (df_lr->solutions_dirty)
1202 /* Do not check if the solution is still dirty. See the comment
1203 in df_lr_finalize for details. */
1204 df_lr->solutions_dirty = false;
1205 else
1206 FOR_ALL_BB_FN (bb, cfun)
1208 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1209 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1211 /*df_dump (stderr);*/
1212 gcc_unreachable ();
1216 /* Cannot delete them immediately because you may want to dump them
1217 if the comparison fails. */
1218 FOR_ALL_BB_FN (bb, cfun)
1220 bitmap_clear (&problem_data->in[bb->index]);
1221 bitmap_clear (&problem_data->out[bb->index]);
1224 free (problem_data->in);
1225 free (problem_data->out);
1226 problem_data->in = NULL;
1227 problem_data->out = NULL;
1231 /* All of the information associated with every instance of the problem. */
1233 static struct df_problem problem_LR =
1235 DF_LR, /* Problem id. */
1236 DF_BACKWARD, /* Direction. */
1237 df_lr_alloc, /* Allocate the problem specific data. */
1238 df_lr_reset, /* Reset global information. */
1239 df_lr_free_bb_info, /* Free basic block info. */
1240 df_lr_local_compute, /* Local compute function. */
1241 df_lr_init, /* Init the solution specific data. */
1242 df_worklist_dataflow, /* Worklist solver. */
1243 df_lr_confluence_0, /* Confluence operator 0. */
1244 df_lr_confluence_n, /* Confluence operator n. */
1245 df_lr_transfer_function, /* Transfer function. */
1246 df_lr_finalize, /* Finalize function. */
1247 df_lr_free, /* Free all of the problem information. */
1248 NULL, /* Remove this problem from the stack of dataflow problems. */
1249 NULL, /* Debugging. */
1250 df_lr_top_dump, /* Debugging start block. */
1251 df_lr_bottom_dump, /* Debugging end block. */
1252 NULL, /* Debugging start insn. */
1253 NULL, /* Debugging end insn. */
1254 df_lr_verify_solution_start,/* Incremental solution verify start. */
1255 df_lr_verify_solution_end, /* Incremental solution verify end. */
1256 NULL, /* Dependent problem. */
1257 sizeof (struct df_lr_bb_info),/* Size of entry of block_info array. */
1258 TV_DF_LR, /* Timing variable. */
1259 false /* Reset blocks on dropping out of blocks_to_analyze. */
1263 /* Create a new DATAFLOW instance and add it to an existing instance
1264 of DF. The returned structure is what is used to get at the
1265 solution. */
1267 void
1268 df_lr_add_problem (void)
1270 df_add_problem (&problem_LR);
1271 /* These will be initialized when df_scan_blocks processes each
1272 block. */
1273 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1277 /* Verify that all of the lr related info is consistent and
1278 correct. */
1280 void
1281 df_lr_verify_transfer_functions (void)
1283 basic_block bb;
1284 bitmap_head saved_def;
1285 bitmap_head saved_use;
1286 bitmap_head all_blocks;
1288 if (!df)
1289 return;
1291 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1292 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1293 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1295 FOR_ALL_BB_FN (bb, cfun)
1297 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1298 bitmap_set_bit (&all_blocks, bb->index);
1300 if (bb_info)
1302 /* Make a copy of the transfer functions and then compute
1303 new ones to see if the transfer functions have
1304 changed. */
1305 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1306 bb->index))
1308 bitmap_copy (&saved_def, &bb_info->def);
1309 bitmap_copy (&saved_use, &bb_info->use);
1310 bitmap_clear (&bb_info->def);
1311 bitmap_clear (&bb_info->use);
1313 df_lr_bb_local_compute (bb->index);
1314 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1315 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1318 else
1320 /* If we do not have basic block info, the block must be in
1321 the list of dirty blocks or else some one has added a
1322 block behind our backs. */
1323 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1324 bb->index));
1326 /* Make sure no one created a block without following
1327 procedures. */
1328 gcc_assert (df_scan_get_bb_info (bb->index));
1331 /* Make sure there are no dirty bits in blocks that have been deleted. */
1332 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1333 &all_blocks));
1335 bitmap_clear (&saved_def);
1336 bitmap_clear (&saved_use);
1337 bitmap_clear (&all_blocks);
1342 /*----------------------------------------------------------------------------
1343 LIVE AND MUST-INITIALIZED REGISTERS.
1345 This problem first computes the IN and OUT bitvectors for the
1346 must-initialized registers problems, which is a forward problem.
1347 It gives the set of registers for which we MUST have an available
1348 definition on any path from the entry block to the entry/exit of
1349 a basic block. Sets generate a definition, while clobbers kill
1350 a definition.
1352 In and out bitvectors are built for each basic block and are indexed by
1353 regnum (see df.h for details). In and out bitvectors in struct
1354 df_live_bb_info actually refers to the must-initialized problem;
1356 Then, the in and out sets for the LIVE problem itself are computed.
1357 These are the logical AND of the IN and OUT sets from the LR problem
1358 and the must-initialized problem.
1359 ----------------------------------------------------------------------------*/
1361 /* Private data used to verify the solution for this problem. */
1362 struct df_live_problem_data
1364 bitmap_head *in;
1365 bitmap_head *out;
1366 /* An obstack for the bitmaps we need for this problem. */
1367 bitmap_obstack live_bitmaps;
1370 /* Scratch var used by transfer functions. This is used to implement
1371 an optimization to reduce the amount of space used to compute the
1372 combined lr and live analysis. */
1373 static bitmap_head df_live_scratch;
1376 /* Free basic block info. */
1378 static void
1379 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1380 void *vbb_info)
1382 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1383 if (bb_info)
1385 bitmap_clear (&bb_info->gen);
1386 bitmap_clear (&bb_info->kill);
1387 bitmap_clear (&bb_info->in);
1388 bitmap_clear (&bb_info->out);
1393 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1394 not touched unless the block is new. */
1396 static void
1397 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1399 unsigned int bb_index;
1400 bitmap_iterator bi;
1401 struct df_live_problem_data *problem_data;
1403 if (df_live->problem_data)
1404 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1405 else
1407 problem_data = XNEW (struct df_live_problem_data);
1408 df_live->problem_data = problem_data;
1410 problem_data->out = NULL;
1411 problem_data->in = NULL;
1412 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1413 bitmap_initialize (&df_live_scratch, &problem_data->live_bitmaps);
1416 df_grow_bb_info (df_live);
1418 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1420 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1422 /* When bitmaps are already initialized, just clear them. */
1423 if (bb_info->kill.obstack)
1425 bitmap_clear (&bb_info->kill);
1426 bitmap_clear (&bb_info->gen);
1428 else
1430 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1431 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1432 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1433 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1436 df_live->optional_p = (optimize <= 1);
1440 /* Reset the global solution for recalculation. */
1442 static void
1443 df_live_reset (bitmap all_blocks)
1445 unsigned int bb_index;
1446 bitmap_iterator bi;
1448 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1450 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1451 gcc_assert (bb_info);
1452 bitmap_clear (&bb_info->in);
1453 bitmap_clear (&bb_info->out);
1458 /* Compute local uninitialized register info for basic block BB. */
1460 static void
1461 df_live_bb_local_compute (unsigned int bb_index)
1463 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1464 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1465 rtx insn;
1466 df_ref *def_rec;
1467 int luid = 0;
1469 FOR_BB_INSNS (bb, insn)
1471 unsigned int uid = INSN_UID (insn);
1472 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1474 /* Inserting labels does not always trigger the incremental
1475 rescanning. */
1476 if (!insn_info)
1478 gcc_assert (!INSN_P (insn));
1479 insn_info = df_insn_create_insn_record (insn);
1482 DF_INSN_INFO_LUID (insn_info) = luid;
1483 if (!INSN_P (insn))
1484 continue;
1486 luid++;
1487 for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)
1489 df_ref def = *def_rec;
1490 unsigned int regno = DF_REF_REGNO (def);
1492 if (DF_REF_FLAGS_IS_SET (def,
1493 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1494 /* All partial or conditional def
1495 seen are included in the gen set. */
1496 bitmap_set_bit (&bb_info->gen, regno);
1497 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1498 /* Only must clobbers for the entire reg destroy the
1499 value. */
1500 bitmap_set_bit (&bb_info->kill, regno);
1501 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1502 bitmap_set_bit (&bb_info->gen, regno);
1506 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1508 df_ref def = *def_rec;
1509 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1514 /* Compute local uninitialized register info. */
1516 static void
1517 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1519 unsigned int bb_index;
1520 bitmap_iterator bi;
1522 df_grow_insn_info ();
1524 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1525 0, bb_index, bi)
1527 df_live_bb_local_compute (bb_index);
1530 bitmap_clear (df_live->out_of_date_transfer_functions);
1534 /* Initialize the solution vectors. */
1536 static void
1537 df_live_init (bitmap all_blocks)
1539 unsigned int bb_index;
1540 bitmap_iterator bi;
1542 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1544 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1545 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1547 /* No register may reach a location where it is not used. Thus
1548 we trim the rr result to the places where it is used. */
1549 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1550 bitmap_clear (&bb_info->in);
1554 /* Forward confluence function that ignores fake edges. */
1556 static bool
1557 df_live_confluence_n (edge e)
1559 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1560 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1562 if (e->flags & EDGE_FAKE)
1563 return false;
1565 return bitmap_ior_into (op1, op2);
1569 /* Transfer function for the forwards must-initialized problem. */
1571 static bool
1572 df_live_transfer_function (int bb_index)
1574 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1575 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1576 bitmap in = &bb_info->in;
1577 bitmap out = &bb_info->out;
1578 bitmap gen = &bb_info->gen;
1579 bitmap kill = &bb_info->kill;
1581 /* We need to use a scratch set here so that the value returned from this
1582 function invocation properly reflects whether the sets changed in a
1583 significant way; i.e. not just because the lr set was anded in. */
1584 bitmap_and (&df_live_scratch, gen, &bb_lr_info->out);
1585 /* No register may reach a location where it is not used. Thus
1586 we trim the rr result to the places where it is used. */
1587 bitmap_and_into (in, &bb_lr_info->in);
1589 return bitmap_ior_and_compl (out, &df_live_scratch, in, kill);
1593 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1595 static void
1596 df_live_finalize (bitmap all_blocks)
1599 if (df_live->solutions_dirty)
1601 bitmap_iterator bi;
1602 unsigned int bb_index;
1604 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1606 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1607 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1609 /* No register may reach a location where it is not used. Thus
1610 we trim the rr result to the places where it is used. */
1611 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1612 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1615 df_live->solutions_dirty = false;
1620 /* Free all storage associated with the problem. */
1622 static void
1623 df_live_free (void)
1625 struct df_live_problem_data *problem_data
1626 = (struct df_live_problem_data *) df_live->problem_data;
1627 if (df_live->block_info)
1629 df_live->block_info_size = 0;
1630 free (df_live->block_info);
1631 df_live->block_info = NULL;
1632 bitmap_clear (&df_live_scratch);
1633 bitmap_obstack_release (&problem_data->live_bitmaps);
1634 free (problem_data);
1635 df_live->problem_data = NULL;
1637 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1638 free (df_live);
1642 /* Debugging info at top of bb. */
1644 static void
1645 df_live_top_dump (basic_block bb, FILE *file)
1647 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1648 struct df_live_problem_data *problem_data;
1650 if (!bb_info)
1651 return;
1653 fprintf (file, ";; live in \t");
1654 df_print_regset (file, &bb_info->in);
1655 if (df_live->problem_data)
1657 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1658 if (problem_data->in)
1660 fprintf (file, ";; old in \t");
1661 df_print_regset (file, &problem_data->in[bb->index]);
1664 fprintf (file, ";; live gen \t");
1665 df_print_regset (file, &bb_info->gen);
1666 fprintf (file, ";; live kill\t");
1667 df_print_regset (file, &bb_info->kill);
1671 /* Debugging info at bottom of bb. */
1673 static void
1674 df_live_bottom_dump (basic_block bb, FILE *file)
1676 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1677 struct df_live_problem_data *problem_data;
1679 if (!bb_info)
1680 return;
1682 fprintf (file, ";; live out \t");
1683 df_print_regset (file, &bb_info->out);
1684 if (df_live->problem_data)
1686 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1687 if (problem_data->out)
1689 fprintf (file, ";; old out \t");
1690 df_print_regset (file, &problem_data->out[bb->index]);
1696 /* Build the datastructure to verify that the solution to the dataflow
1697 equations is not dirty. */
1699 static void
1700 df_live_verify_solution_start (void)
1702 basic_block bb;
1703 struct df_live_problem_data *problem_data;
1704 if (df_live->solutions_dirty)
1705 return;
1707 /* Set it true so that the solution is recomputed. */
1708 df_live->solutions_dirty = true;
1710 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1711 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1712 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1714 FOR_ALL_BB_FN (bb, cfun)
1716 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1717 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1718 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1719 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1724 /* Compare the saved datastructure and the new solution to the dataflow
1725 equations. */
1727 static void
1728 df_live_verify_solution_end (void)
1730 struct df_live_problem_data *problem_data;
1731 basic_block bb;
1733 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1734 if (!problem_data->out)
1735 return;
1737 FOR_ALL_BB_FN (bb, cfun)
1739 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1740 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1742 /*df_dump (stderr);*/
1743 gcc_unreachable ();
1747 /* Cannot delete them immediately because you may want to dump them
1748 if the comparison fails. */
1749 FOR_ALL_BB_FN (bb, cfun)
1751 bitmap_clear (&problem_data->in[bb->index]);
1752 bitmap_clear (&problem_data->out[bb->index]);
1755 free (problem_data->in);
1756 free (problem_data->out);
1757 free (problem_data);
1758 df_live->problem_data = NULL;
1762 /* All of the information associated with every instance of the problem. */
1764 static struct df_problem problem_LIVE =
1766 DF_LIVE, /* Problem id. */
1767 DF_FORWARD, /* Direction. */
1768 df_live_alloc, /* Allocate the problem specific data. */
1769 df_live_reset, /* Reset global information. */
1770 df_live_free_bb_info, /* Free basic block info. */
1771 df_live_local_compute, /* Local compute function. */
1772 df_live_init, /* Init the solution specific data. */
1773 df_worklist_dataflow, /* Worklist solver. */
1774 NULL, /* Confluence operator 0. */
1775 df_live_confluence_n, /* Confluence operator n. */
1776 df_live_transfer_function, /* Transfer function. */
1777 df_live_finalize, /* Finalize function. */
1778 df_live_free, /* Free all of the problem information. */
1779 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1780 NULL, /* Debugging. */
1781 df_live_top_dump, /* Debugging start block. */
1782 df_live_bottom_dump, /* Debugging end block. */
1783 NULL, /* Debugging start insn. */
1784 NULL, /* Debugging end insn. */
1785 df_live_verify_solution_start,/* Incremental solution verify start. */
1786 df_live_verify_solution_end, /* Incremental solution verify end. */
1787 &problem_LR, /* Dependent problem. */
1788 sizeof (struct df_live_bb_info),/* Size of entry of block_info array. */
1789 TV_DF_LIVE, /* Timing variable. */
1790 false /* Reset blocks on dropping out of blocks_to_analyze. */
1794 /* Create a new DATAFLOW instance and add it to an existing instance
1795 of DF. The returned structure is what is used to get at the
1796 solution. */
1798 void
1799 df_live_add_problem (void)
1801 df_add_problem (&problem_LIVE);
1802 /* These will be initialized when df_scan_blocks processes each
1803 block. */
1804 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1808 /* Set all of the blocks as dirty. This needs to be done if this
1809 problem is added after all of the insns have been scanned. */
1811 void
1812 df_live_set_all_dirty (void)
1814 basic_block bb;
1815 FOR_ALL_BB_FN (bb, cfun)
1816 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1817 bb->index);
1821 /* Verify that all of the lr related info is consistent and
1822 correct. */
1824 void
1825 df_live_verify_transfer_functions (void)
1827 basic_block bb;
1828 bitmap_head saved_gen;
1829 bitmap_head saved_kill;
1830 bitmap_head all_blocks;
1832 if (!df)
1833 return;
1835 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1836 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1837 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1839 df_grow_insn_info ();
1841 FOR_ALL_BB_FN (bb, cfun)
1843 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1844 bitmap_set_bit (&all_blocks, bb->index);
1846 if (bb_info)
1848 /* Make a copy of the transfer functions and then compute
1849 new ones to see if the transfer functions have
1850 changed. */
1851 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1852 bb->index))
1854 bitmap_copy (&saved_gen, &bb_info->gen);
1855 bitmap_copy (&saved_kill, &bb_info->kill);
1856 bitmap_clear (&bb_info->gen);
1857 bitmap_clear (&bb_info->kill);
1859 df_live_bb_local_compute (bb->index);
1860 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1861 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1864 else
1866 /* If we do not have basic block info, the block must be in
1867 the list of dirty blocks or else some one has added a
1868 block behind our backs. */
1869 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1870 bb->index));
1872 /* Make sure no one created a block without following
1873 procedures. */
1874 gcc_assert (df_scan_get_bb_info (bb->index));
1877 /* Make sure there are no dirty bits in blocks that have been deleted. */
1878 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1879 &all_blocks));
1880 bitmap_clear (&saved_gen);
1881 bitmap_clear (&saved_kill);
1882 bitmap_clear (&all_blocks);
1885 /*----------------------------------------------------------------------------
1886 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1888 Link either the defs to the uses and / or the uses to the defs.
1890 These problems are set up like the other dataflow problems so that
1891 they nicely fit into the framework. They are much simpler and only
1892 involve a single traversal of instructions and an examination of
1893 the reaching defs information (the dependent problem).
1894 ----------------------------------------------------------------------------*/
1896 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1898 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1900 struct df_link *
1901 df_chain_create (df_ref src, df_ref dst)
1903 struct df_link *head = DF_REF_CHAIN (src);
1904 struct df_link *link = (struct df_link *) pool_alloc (df_chain->block_pool);
1906 DF_REF_CHAIN (src) = link;
1907 link->next = head;
1908 link->ref = dst;
1909 return link;
1913 /* Delete any du or ud chains that start at REF and point to
1914 TARGET. */
1915 static void
1916 df_chain_unlink_1 (df_ref ref, df_ref target)
1918 struct df_link *chain = DF_REF_CHAIN (ref);
1919 struct df_link *prev = NULL;
1921 while (chain)
1923 if (chain->ref == target)
1925 if (prev)
1926 prev->next = chain->next;
1927 else
1928 DF_REF_CHAIN (ref) = chain->next;
1929 pool_free (df_chain->block_pool, chain);
1930 return;
1932 prev = chain;
1933 chain = chain->next;
1938 /* Delete a du or ud chain that leave or point to REF. */
1940 void
1941 df_chain_unlink (df_ref ref)
1943 struct df_link *chain = DF_REF_CHAIN (ref);
1944 while (chain)
1946 struct df_link *next = chain->next;
1947 /* Delete the other side if it exists. */
1948 df_chain_unlink_1 (chain->ref, ref);
1949 pool_free (df_chain->block_pool, chain);
1950 chain = next;
1952 DF_REF_CHAIN (ref) = NULL;
1956 /* Copy the du or ud chain starting at FROM_REF and attach it to
1957 TO_REF. */
1959 void
1960 df_chain_copy (df_ref to_ref,
1961 struct df_link *from_ref)
1963 while (from_ref)
1965 df_chain_create (to_ref, from_ref->ref);
1966 from_ref = from_ref->next;
1971 /* Remove this problem from the stack of dataflow problems. */
1973 static void
1974 df_chain_remove_problem (void)
1976 bitmap_iterator bi;
1977 unsigned int bb_index;
1979 /* Wholesale destruction of the old chains. */
1980 if (df_chain->block_pool)
1981 free_alloc_pool (df_chain->block_pool);
1983 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1985 rtx insn;
1986 df_ref *def_rec;
1987 df_ref *use_rec;
1988 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1990 if (df_chain_problem_p (DF_DU_CHAIN))
1991 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1992 DF_REF_CHAIN (*def_rec) = NULL;
1993 if (df_chain_problem_p (DF_UD_CHAIN))
1994 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1995 DF_REF_CHAIN (*use_rec) = NULL;
1997 FOR_BB_INSNS (bb, insn)
1999 unsigned int uid = INSN_UID (insn);
2001 if (INSN_P (insn))
2003 if (df_chain_problem_p (DF_DU_CHAIN))
2004 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2005 DF_REF_CHAIN (*def_rec) = NULL;
2006 if (df_chain_problem_p (DF_UD_CHAIN))
2008 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2009 DF_REF_CHAIN (*use_rec) = NULL;
2010 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
2011 DF_REF_CHAIN (*use_rec) = NULL;
2017 bitmap_clear (df_chain->out_of_date_transfer_functions);
2018 df_chain->block_pool = NULL;
2022 /* Remove the chain problem completely. */
2024 static void
2025 df_chain_fully_remove_problem (void)
2027 df_chain_remove_problem ();
2028 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2029 free (df_chain);
2033 /* Create def-use or use-def chains. */
2035 static void
2036 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2038 df_chain_remove_problem ();
2039 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2040 sizeof (struct df_link), 50);
2041 df_chain->optional_p = true;
2045 /* Reset all of the chains when the set of basic blocks changes. */
2047 static void
2048 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2050 df_chain_remove_problem ();
2054 /* Create the chains for a list of USEs. */
2056 static void
2057 df_chain_create_bb_process_use (bitmap local_rd,
2058 df_ref *use_rec,
2059 int top_flag)
2061 bitmap_iterator bi;
2062 unsigned int def_index;
2064 while (*use_rec)
2066 df_ref use = *use_rec;
2067 unsigned int uregno = DF_REF_REGNO (use);
2068 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2069 || (uregno >= FIRST_PSEUDO_REGISTER))
2071 /* Do not want to go through this for an uninitialized var. */
2072 int count = DF_DEFS_COUNT (uregno);
2073 if (count)
2075 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2077 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2078 unsigned int last_index = first_index + count - 1;
2080 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2082 df_ref def;
2083 if (def_index > last_index)
2084 break;
2086 def = DF_DEFS_GET (def_index);
2087 if (df_chain_problem_p (DF_DU_CHAIN))
2088 df_chain_create (def, use);
2089 if (df_chain_problem_p (DF_UD_CHAIN))
2090 df_chain_create (use, def);
2096 use_rec++;
2101 /* Create chains from reaching defs bitmaps for basic block BB. */
2103 static void
2104 df_chain_create_bb (unsigned int bb_index)
2106 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2107 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2108 rtx insn;
2109 bitmap_head cpy;
2111 bitmap_initialize (&cpy, &bitmap_default_obstack);
2112 bitmap_copy (&cpy, &bb_info->in);
2113 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2115 /* Since we are going forwards, process the artificial uses first
2116 then the artificial defs second. */
2118 #ifdef EH_USES
2119 /* Create the chains for the artificial uses from the EH_USES at the
2120 beginning of the block. */
2122 /* Artificials are only hard regs. */
2123 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2124 df_chain_create_bb_process_use (&cpy,
2125 df_get_artificial_uses (bb->index),
2126 DF_REF_AT_TOP);
2127 #endif
2129 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2131 /* Process the regular instructions next. */
2132 FOR_BB_INSNS (bb, insn)
2133 if (INSN_P (insn))
2135 unsigned int uid = INSN_UID (insn);
2137 /* First scan the uses and link them up with the defs that remain
2138 in the cpy vector. */
2139 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2140 if (df->changeable_flags & DF_EQ_NOTES)
2141 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2143 /* Since we are going forwards, process the defs second. */
2144 df_rd_simulate_one_insn (bb, insn, &cpy);
2147 /* Create the chains for the artificial uses of the hard registers
2148 at the end of the block. */
2149 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2150 df_chain_create_bb_process_use (&cpy,
2151 df_get_artificial_uses (bb->index),
2154 bitmap_clear (&cpy);
2157 /* Create def-use chains from reaching use bitmaps for basic blocks
2158 in BLOCKS. */
2160 static void
2161 df_chain_finalize (bitmap all_blocks)
2163 unsigned int bb_index;
2164 bitmap_iterator bi;
2166 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2168 df_chain_create_bb (bb_index);
2173 /* Free all storage associated with the problem. */
2175 static void
2176 df_chain_free (void)
2178 free_alloc_pool (df_chain->block_pool);
2179 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2180 free (df_chain);
2184 /* Debugging info. */
2186 static void
2187 df_chain_bb_dump (basic_block bb, FILE *file, bool top)
2189 /* Artificials are only hard regs. */
2190 if (df->changeable_flags & DF_NO_HARD_REGS)
2191 return;
2192 if (df_chain_problem_p (DF_UD_CHAIN))
2194 fprintf (file,
2195 ";; UD chains for artificial uses at %s\n",
2196 top ? "top" : "bottom");
2197 df_ref *use_rec = df_get_artificial_uses (bb->index);
2198 if (*use_rec)
2200 while (*use_rec)
2202 df_ref use = *use_rec;
2203 if ((top && (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2204 || (!top && !(DF_REF_FLAGS (use) & DF_REF_AT_TOP)))
2206 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2207 df_chain_dump (DF_REF_CHAIN (use), file);
2208 fprintf (file, "\n");
2210 use_rec++;
2214 if (df_chain_problem_p (DF_DU_CHAIN))
2216 fprintf (file,
2217 ";; DU chains for artificial defs at %s\n",
2218 top ? "top" : "bottom");
2219 df_ref *def_rec = df_get_artificial_defs (bb->index);
2220 if (*def_rec)
2222 while (*def_rec)
2224 df_ref def = *def_rec;
2226 if ((top && (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
2227 || (!top && !(DF_REF_FLAGS (def) & DF_REF_AT_TOP)))
2229 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2230 df_chain_dump (DF_REF_CHAIN (def), file);
2231 fprintf (file, "\n");
2233 def_rec++;
2239 static void
2240 df_chain_top_dump (basic_block bb, FILE *file)
2242 df_chain_bb_dump (bb, file, /*top=*/true);
2245 static void
2246 df_chain_bottom_dump (basic_block bb, FILE *file)
2248 df_chain_bb_dump (bb, file, /*top=*/false);
2251 static void
2252 df_chain_insn_top_dump (const_rtx insn, FILE *file)
2254 if (df_chain_problem_p (DF_UD_CHAIN) && INSN_P (insn))
2256 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2257 df_ref *use_rec = DF_INSN_INFO_USES (insn_info);
2258 df_ref *eq_use_rec = DF_INSN_INFO_EQ_USES (insn_info);
2259 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2260 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2261 if (*use_rec || *eq_use_rec)
2263 while (*use_rec)
2265 df_ref use = *use_rec;
2266 if (! HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2267 || !(df->changeable_flags & DF_NO_HARD_REGS))
2269 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2270 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2271 fprintf (file, "read/write ");
2272 df_chain_dump (DF_REF_CHAIN (use), file);
2273 fprintf (file, "\n");
2275 use_rec++;
2277 while (*eq_use_rec)
2279 df_ref use = *eq_use_rec;
2280 if (! HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2281 || !(df->changeable_flags & DF_NO_HARD_REGS))
2283 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2284 df_chain_dump (DF_REF_CHAIN (use), file);
2285 fprintf (file, "\n");
2287 eq_use_rec++;
2293 static void
2294 df_chain_insn_bottom_dump (const_rtx insn, FILE *file)
2296 if (df_chain_problem_p (DF_DU_CHAIN) && INSN_P (insn))
2298 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2299 df_ref *def_rec = DF_INSN_INFO_DEFS (insn_info);
2300 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2301 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2302 if (*def_rec)
2304 while (*def_rec)
2306 df_ref def = *def_rec;
2307 if (! HARD_REGISTER_NUM_P (DF_REF_REGNO (def))
2308 || !(df->changeable_flags & DF_NO_HARD_REGS))
2310 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2311 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2312 fprintf (file, "read/write ");
2313 df_chain_dump (DF_REF_CHAIN (def), file);
2314 fprintf (file, "\n");
2316 def_rec++;
2319 fprintf (file, "\n");
2323 static struct df_problem problem_CHAIN =
2325 DF_CHAIN, /* Problem id. */
2326 DF_NONE, /* Direction. */
2327 df_chain_alloc, /* Allocate the problem specific data. */
2328 df_chain_reset, /* Reset global information. */
2329 NULL, /* Free basic block info. */
2330 NULL, /* Local compute function. */
2331 NULL, /* Init the solution specific data. */
2332 NULL, /* Iterative solver. */
2333 NULL, /* Confluence operator 0. */
2334 NULL, /* Confluence operator n. */
2335 NULL, /* Transfer function. */
2336 df_chain_finalize, /* Finalize function. */
2337 df_chain_free, /* Free all of the problem information. */
2338 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2339 NULL, /* Debugging. */
2340 df_chain_top_dump, /* Debugging start block. */
2341 df_chain_bottom_dump, /* Debugging end block. */
2342 df_chain_insn_top_dump, /* Debugging start insn. */
2343 df_chain_insn_bottom_dump, /* Debugging end insn. */
2344 NULL, /* Incremental solution verify start. */
2345 NULL, /* Incremental solution verify end. */
2346 &problem_RD, /* Dependent problem. */
2347 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
2348 TV_DF_CHAIN, /* Timing variable. */
2349 false /* Reset blocks on dropping out of blocks_to_analyze. */
2353 /* Create a new DATAFLOW instance and add it to an existing instance
2354 of DF. The returned structure is what is used to get at the
2355 solution. */
2357 void
2358 df_chain_add_problem (unsigned int chain_flags)
2360 df_add_problem (&problem_CHAIN);
2361 df_chain->local_flags = chain_flags;
2362 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2365 #undef df_chain_problem_p
2368 /*----------------------------------------------------------------------------
2369 WORD LEVEL LIVE REGISTERS
2371 Find the locations in the function where any use of a pseudo can
2372 reach in the backwards direction. In and out bitvectors are built
2373 for each basic block. We only track pseudo registers that have a
2374 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2375 contain two bits corresponding to each of the subwords.
2377 ----------------------------------------------------------------------------*/
2379 /* Private data used to verify the solution for this problem. */
2380 struct df_word_lr_problem_data
2382 /* An obstack for the bitmaps we need for this problem. */
2383 bitmap_obstack word_lr_bitmaps;
2387 /* Free basic block info. */
2389 static void
2390 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2391 void *vbb_info)
2393 struct df_word_lr_bb_info *bb_info = (struct df_word_lr_bb_info *) vbb_info;
2394 if (bb_info)
2396 bitmap_clear (&bb_info->use);
2397 bitmap_clear (&bb_info->def);
2398 bitmap_clear (&bb_info->in);
2399 bitmap_clear (&bb_info->out);
2404 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2405 not touched unless the block is new. */
2407 static void
2408 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2410 unsigned int bb_index;
2411 bitmap_iterator bi;
2412 basic_block bb;
2413 struct df_word_lr_problem_data *problem_data
2414 = XNEW (struct df_word_lr_problem_data);
2416 df_word_lr->problem_data = problem_data;
2418 df_grow_bb_info (df_word_lr);
2420 /* Create the mapping from regnos to slots. This does not change
2421 unless the problem is destroyed and recreated. In particular, if
2422 we end up deleting the only insn that used a subreg, we do not
2423 want to redo the mapping because this would invalidate everything
2424 else. */
2426 bitmap_obstack_initialize (&problem_data->word_lr_bitmaps);
2428 FOR_EACH_BB_FN (bb, cfun)
2429 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, bb->index);
2431 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2432 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2434 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2436 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2438 /* When bitmaps are already initialized, just clear them. */
2439 if (bb_info->use.obstack)
2441 bitmap_clear (&bb_info->def);
2442 bitmap_clear (&bb_info->use);
2444 else
2446 bitmap_initialize (&bb_info->use, &problem_data->word_lr_bitmaps);
2447 bitmap_initialize (&bb_info->def, &problem_data->word_lr_bitmaps);
2448 bitmap_initialize (&bb_info->in, &problem_data->word_lr_bitmaps);
2449 bitmap_initialize (&bb_info->out, &problem_data->word_lr_bitmaps);
2453 df_word_lr->optional_p = true;
2457 /* Reset the global solution for recalculation. */
2459 static void
2460 df_word_lr_reset (bitmap all_blocks)
2462 unsigned int bb_index;
2463 bitmap_iterator bi;
2465 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2467 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2468 gcc_assert (bb_info);
2469 bitmap_clear (&bb_info->in);
2470 bitmap_clear (&bb_info->out);
2474 /* Examine REF, and if it is for a reg we're interested in, set or
2475 clear the bits corresponding to its subwords from the bitmap
2476 according to IS_SET. LIVE is the bitmap we should update. We do
2477 not track hard regs or pseudos of any size other than 2 *
2478 UNITS_PER_WORD.
2479 We return true if we changed the bitmap, or if we encountered a register
2480 we're not tracking. */
2482 bool
2483 df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
2485 rtx orig_reg = DF_REF_REG (ref);
2486 rtx reg = orig_reg;
2487 enum machine_mode reg_mode;
2488 unsigned regno;
2489 /* Left at -1 for whole accesses. */
2490 int which_subword = -1;
2491 bool changed = false;
2493 if (GET_CODE (reg) == SUBREG)
2494 reg = SUBREG_REG (orig_reg);
2495 regno = REGNO (reg);
2496 reg_mode = GET_MODE (reg);
2497 if (regno < FIRST_PSEUDO_REGISTER
2498 || GET_MODE_SIZE (reg_mode) != 2 * UNITS_PER_WORD)
2499 return true;
2501 if (GET_CODE (orig_reg) == SUBREG
2502 && df_read_modify_subreg_p (orig_reg))
2504 gcc_assert (DF_REF_FLAGS_IS_SET (ref, DF_REF_PARTIAL));
2505 if (subreg_lowpart_p (orig_reg))
2506 which_subword = 0;
2507 else
2508 which_subword = 1;
2510 if (is_set)
2512 if (which_subword != 1)
2513 changed |= bitmap_set_bit (live, regno * 2);
2514 if (which_subword != 0)
2515 changed |= bitmap_set_bit (live, regno * 2 + 1);
2517 else
2519 if (which_subword != 1)
2520 changed |= bitmap_clear_bit (live, regno * 2);
2521 if (which_subword != 0)
2522 changed |= bitmap_clear_bit (live, regno * 2 + 1);
2524 return changed;
2527 /* Compute local live register info for basic block BB. */
2529 static void
2530 df_word_lr_bb_local_compute (unsigned int bb_index)
2532 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2533 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2534 rtx insn;
2535 df_ref *def_rec;
2536 df_ref *use_rec;
2538 /* Ensure that artificial refs don't contain references to pseudos. */
2539 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2541 df_ref def = *def_rec;
2542 gcc_assert (DF_REF_REGNO (def) < FIRST_PSEUDO_REGISTER);
2545 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2547 df_ref use = *use_rec;
2548 gcc_assert (DF_REF_REGNO (use) < FIRST_PSEUDO_REGISTER);
2551 FOR_BB_INSNS_REVERSE (bb, insn)
2553 unsigned int uid = INSN_UID (insn);
2555 if (!NONDEBUG_INSN_P (insn))
2556 continue;
2557 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2559 df_ref def = *def_rec;
2560 /* If the def is to only part of the reg, it does
2561 not kill the other defs that reach here. */
2562 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2564 df_word_lr_mark_ref (def, true, &bb_info->def);
2565 df_word_lr_mark_ref (def, false, &bb_info->use);
2568 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2570 df_ref use = *use_rec;
2571 df_word_lr_mark_ref (use, true, &bb_info->use);
2577 /* Compute local live register info for each basic block within BLOCKS. */
2579 static void
2580 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2582 unsigned int bb_index;
2583 bitmap_iterator bi;
2585 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2587 if (bb_index == EXIT_BLOCK)
2589 unsigned regno;
2590 bitmap_iterator bi;
2591 EXECUTE_IF_SET_IN_BITMAP (df->exit_block_uses, FIRST_PSEUDO_REGISTER,
2592 regno, bi)
2593 gcc_unreachable ();
2595 else
2596 df_word_lr_bb_local_compute (bb_index);
2599 bitmap_clear (df_word_lr->out_of_date_transfer_functions);
2603 /* Initialize the solution vectors. */
2605 static void
2606 df_word_lr_init (bitmap all_blocks)
2608 unsigned int bb_index;
2609 bitmap_iterator bi;
2611 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2613 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2614 bitmap_copy (&bb_info->in, &bb_info->use);
2615 bitmap_clear (&bb_info->out);
2620 /* Confluence function that ignores fake edges. */
2622 static bool
2623 df_word_lr_confluence_n (edge e)
2625 bitmap op1 = &df_word_lr_get_bb_info (e->src->index)->out;
2626 bitmap op2 = &df_word_lr_get_bb_info (e->dest->index)->in;
2628 return bitmap_ior_into (op1, op2);
2632 /* Transfer function. */
2634 static bool
2635 df_word_lr_transfer_function (int bb_index)
2637 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2638 bitmap in = &bb_info->in;
2639 bitmap out = &bb_info->out;
2640 bitmap use = &bb_info->use;
2641 bitmap def = &bb_info->def;
2643 return bitmap_ior_and_compl (in, use, out, def);
2647 /* Free all storage associated with the problem. */
2649 static void
2650 df_word_lr_free (void)
2652 struct df_word_lr_problem_data *problem_data
2653 = (struct df_word_lr_problem_data *)df_word_lr->problem_data;
2655 if (df_word_lr->block_info)
2657 df_word_lr->block_info_size = 0;
2658 free (df_word_lr->block_info);
2659 df_word_lr->block_info = NULL;
2662 BITMAP_FREE (df_word_lr->out_of_date_transfer_functions);
2663 bitmap_obstack_release (&problem_data->word_lr_bitmaps);
2664 free (problem_data);
2665 free (df_word_lr);
2669 /* Debugging info at top of bb. */
2671 static void
2672 df_word_lr_top_dump (basic_block bb, FILE *file)
2674 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2675 if (!bb_info)
2676 return;
2678 fprintf (file, ";; blr in \t");
2679 df_print_word_regset (file, &bb_info->in);
2680 fprintf (file, ";; blr use \t");
2681 df_print_word_regset (file, &bb_info->use);
2682 fprintf (file, ";; blr def \t");
2683 df_print_word_regset (file, &bb_info->def);
2687 /* Debugging info at bottom of bb. */
2689 static void
2690 df_word_lr_bottom_dump (basic_block bb, FILE *file)
2692 struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2693 if (!bb_info)
2694 return;
2696 fprintf (file, ";; blr out \t");
2697 df_print_word_regset (file, &bb_info->out);
2701 /* All of the information associated with every instance of the problem. */
2703 static struct df_problem problem_WORD_LR =
2705 DF_WORD_LR, /* Problem id. */
2706 DF_BACKWARD, /* Direction. */
2707 df_word_lr_alloc, /* Allocate the problem specific data. */
2708 df_word_lr_reset, /* Reset global information. */
2709 df_word_lr_free_bb_info, /* Free basic block info. */
2710 df_word_lr_local_compute, /* Local compute function. */
2711 df_word_lr_init, /* Init the solution specific data. */
2712 df_worklist_dataflow, /* Worklist solver. */
2713 NULL, /* Confluence operator 0. */
2714 df_word_lr_confluence_n, /* Confluence operator n. */
2715 df_word_lr_transfer_function, /* Transfer function. */
2716 NULL, /* Finalize function. */
2717 df_word_lr_free, /* Free all of the problem information. */
2718 df_word_lr_free, /* Remove this problem from the stack of dataflow problems. */
2719 NULL, /* Debugging. */
2720 df_word_lr_top_dump, /* Debugging start block. */
2721 df_word_lr_bottom_dump, /* Debugging end block. */
2722 NULL, /* Debugging start insn. */
2723 NULL, /* Debugging end insn. */
2724 NULL, /* Incremental solution verify start. */
2725 NULL, /* Incremental solution verify end. */
2726 NULL, /* Dependent problem. */
2727 sizeof (struct df_word_lr_bb_info),/* Size of entry of block_info array. */
2728 TV_DF_WORD_LR, /* Timing variable. */
2729 false /* Reset blocks on dropping out of blocks_to_analyze. */
2733 /* Create a new DATAFLOW instance and add it to an existing instance
2734 of DF. The returned structure is what is used to get at the
2735 solution. */
2737 void
2738 df_word_lr_add_problem (void)
2740 df_add_problem (&problem_WORD_LR);
2741 /* These will be initialized when df_scan_blocks processes each
2742 block. */
2743 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2747 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
2748 any bits, which is used by the caller to determine whether a set is
2749 necessary. We also return true if there are other reasons not to delete
2750 an insn. */
2752 bool
2753 df_word_lr_simulate_defs (rtx insn, bitmap live)
2755 bool changed = false;
2756 df_ref *def_rec;
2757 unsigned int uid = INSN_UID (insn);
2759 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2761 df_ref def = *def_rec;
2762 if (DF_REF_FLAGS (def) & DF_REF_CONDITIONAL)
2763 changed = true;
2764 else
2765 changed |= df_word_lr_mark_ref (*def_rec, false, live);
2767 return changed;
2771 /* Simulate the effects of the uses of INSN on LIVE. */
2773 void
2774 df_word_lr_simulate_uses (rtx insn, bitmap live)
2776 df_ref *use_rec;
2777 unsigned int uid = INSN_UID (insn);
2779 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2780 df_word_lr_mark_ref (*use_rec, true, live);
2783 /*----------------------------------------------------------------------------
2784 This problem computes REG_DEAD and REG_UNUSED notes.
2785 ----------------------------------------------------------------------------*/
2787 static void
2788 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2790 df_note->optional_p = true;
2793 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
2794 static void
2795 df_print_note (const char *prefix, rtx insn, rtx note)
2797 if (dump_file)
2799 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2800 print_rtl (dump_file, note);
2801 fprintf (dump_file, "\n");
2806 /* After reg-stack, the x86 floating point stack regs are difficult to
2807 analyze because of all of the pushes, pops and rotations. Thus, we
2808 just leave the notes alone. */
2810 #ifdef STACK_REGS
2811 static inline bool
2812 df_ignore_stack_reg (int regno)
2814 return regstack_completed
2815 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2817 #else
2818 static inline bool
2819 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2821 return false;
2823 #endif
2826 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
2828 static void
2829 df_remove_dead_and_unused_notes (rtx insn)
2831 rtx *pprev = &REG_NOTES (insn);
2832 rtx link = *pprev;
2834 while (link)
2836 switch (REG_NOTE_KIND (link))
2838 case REG_DEAD:
2839 /* After reg-stack, we need to ignore any unused notes
2840 for the stack registers. */
2841 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2843 pprev = &XEXP (link, 1);
2844 link = *pprev;
2846 else
2848 rtx next = XEXP (link, 1);
2849 if (REG_DEAD_DEBUGGING)
2850 df_print_note ("deleting: ", insn, link);
2851 free_EXPR_LIST_node (link);
2852 *pprev = link = next;
2854 break;
2856 case REG_UNUSED:
2857 /* After reg-stack, we need to ignore any unused notes
2858 for the stack registers. */
2859 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2861 pprev = &XEXP (link, 1);
2862 link = *pprev;
2864 else
2866 rtx next = XEXP (link, 1);
2867 if (REG_DEAD_DEBUGGING)
2868 df_print_note ("deleting: ", insn, link);
2869 free_EXPR_LIST_node (link);
2870 *pprev = link = next;
2872 break;
2874 default:
2875 pprev = &XEXP (link, 1);
2876 link = *pprev;
2877 break;
2882 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
2883 as the bitmap of currently live registers. */
2885 static void
2886 df_remove_dead_eq_notes (rtx insn, bitmap live)
2888 rtx *pprev = &REG_NOTES (insn);
2889 rtx link = *pprev;
2891 while (link)
2893 switch (REG_NOTE_KIND (link))
2895 case REG_EQUAL:
2896 case REG_EQUIV:
2898 /* Remove the notes that refer to dead registers. As we have at most
2899 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
2900 so we need to purge the complete EQ_USES vector when removing
2901 the note using df_notes_rescan. */
2902 df_ref *use_rec;
2903 bool deleted = false;
2905 for (use_rec = DF_INSN_EQ_USES (insn); *use_rec; use_rec++)
2907 df_ref use = *use_rec;
2908 if (DF_REF_REGNO (use) > FIRST_PSEUDO_REGISTER
2909 && DF_REF_LOC (use)
2910 && (DF_REF_FLAGS (use) & DF_REF_IN_NOTE)
2911 && ! bitmap_bit_p (live, DF_REF_REGNO (use))
2912 && loc_mentioned_in_p (DF_REF_LOC (use), XEXP (link, 0)))
2914 deleted = true;
2915 break;
2918 if (deleted)
2920 rtx next;
2921 if (REG_DEAD_DEBUGGING)
2922 df_print_note ("deleting: ", insn, link);
2923 next = XEXP (link, 1);
2924 free_EXPR_LIST_node (link);
2925 *pprev = link = next;
2926 df_notes_rescan (insn);
2928 else
2930 pprev = &XEXP (link, 1);
2931 link = *pprev;
2933 break;
2936 default:
2937 pprev = &XEXP (link, 1);
2938 link = *pprev;
2939 break;
2944 /* Set a NOTE_TYPE note for REG in INSN. */
2946 static inline void
2947 df_set_note (enum reg_note note_type, rtx insn, rtx reg)
2949 gcc_checking_assert (!DEBUG_INSN_P (insn));
2950 add_reg_note (insn, note_type, reg);
2953 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2954 arguments. Return true if the register value described by MWS's
2955 mw_reg is known to be completely unused, and if mw_reg can therefore
2956 be used in a REG_UNUSED note. */
2958 static bool
2959 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2960 bitmap live, bitmap artificial_uses)
2962 unsigned int r;
2964 /* If MWS describes a partial reference, create REG_UNUSED notes for
2965 individual hard registers. */
2966 if (mws->flags & DF_REF_PARTIAL)
2967 return false;
2969 /* Likewise if some part of the register is used. */
2970 for (r = mws->start_regno; r <= mws->end_regno; r++)
2971 if (bitmap_bit_p (live, r)
2972 || bitmap_bit_p (artificial_uses, r))
2973 return false;
2975 gcc_assert (REG_P (mws->mw_reg));
2976 return true;
2980 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2981 based on the bits in LIVE. Do not generate notes for registers in
2982 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2983 not generated if the reg is both read and written by the
2984 instruction.
2987 static void
2988 df_set_unused_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
2989 bitmap live, bitmap do_not_gen,
2990 bitmap artificial_uses,
2991 struct dead_debug_local *debug)
2993 unsigned int r;
2995 if (REG_DEAD_DEBUGGING && dump_file)
2996 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2997 mws->start_regno, mws->end_regno);
2999 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
3001 unsigned int regno = mws->start_regno;
3002 df_set_note (REG_UNUSED, insn, mws->mw_reg);
3003 dead_debug_insert_temp (debug, regno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3005 if (REG_DEAD_DEBUGGING)
3006 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3008 bitmap_set_bit (do_not_gen, regno);
3009 /* Only do this if the value is totally dead. */
3011 else
3012 for (r = mws->start_regno; r <= mws->end_regno; r++)
3014 if (!bitmap_bit_p (live, r)
3015 && !bitmap_bit_p (artificial_uses, r))
3017 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
3018 dead_debug_insert_temp (debug, r, insn, DEBUG_TEMP_AFTER_WITH_REG);
3019 if (REG_DEAD_DEBUGGING)
3020 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3022 bitmap_set_bit (do_not_gen, r);
3027 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
3028 arguments. Return true if the register value described by MWS's
3029 mw_reg is known to be completely dead, and if mw_reg can therefore
3030 be used in a REG_DEAD note. */
3032 static bool
3033 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
3034 bitmap live, bitmap artificial_uses,
3035 bitmap do_not_gen)
3037 unsigned int r;
3039 /* If MWS describes a partial reference, create REG_DEAD notes for
3040 individual hard registers. */
3041 if (mws->flags & DF_REF_PARTIAL)
3042 return false;
3044 /* Likewise if some part of the register is not dead. */
3045 for (r = mws->start_regno; r <= mws->end_regno; r++)
3046 if (bitmap_bit_p (live, r)
3047 || bitmap_bit_p (artificial_uses, r)
3048 || bitmap_bit_p (do_not_gen, r))
3049 return false;
3051 gcc_assert (REG_P (mws->mw_reg));
3052 return true;
3055 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3056 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3057 from being set if the instruction both reads and writes the
3058 register. */
3060 static void
3061 df_set_dead_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
3062 bitmap live, bitmap do_not_gen,
3063 bitmap artificial_uses, bool *added_notes_p)
3065 unsigned int r;
3066 bool is_debug = *added_notes_p;
3068 *added_notes_p = false;
3070 if (REG_DEAD_DEBUGGING && dump_file)
3072 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3073 mws->start_regno, mws->end_regno);
3074 df_print_regset (dump_file, do_not_gen);
3075 fprintf (dump_file, " live =");
3076 df_print_regset (dump_file, live);
3077 fprintf (dump_file, " artificial uses =");
3078 df_print_regset (dump_file, artificial_uses);
3081 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
3083 if (is_debug)
3085 *added_notes_p = true;
3086 return;
3088 /* Add a dead note for the entire multi word register. */
3089 df_set_note (REG_DEAD, insn, mws->mw_reg);
3090 if (REG_DEAD_DEBUGGING)
3091 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3093 else
3095 for (r = mws->start_regno; r <= mws->end_regno; r++)
3096 if (!bitmap_bit_p (live, r)
3097 && !bitmap_bit_p (artificial_uses, r)
3098 && !bitmap_bit_p (do_not_gen, r))
3100 if (is_debug)
3102 *added_notes_p = true;
3103 return;
3105 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
3106 if (REG_DEAD_DEBUGGING)
3107 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3110 return;
3114 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3115 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3117 static void
3118 df_create_unused_note (rtx insn, df_ref def,
3119 bitmap live, bitmap artificial_uses,
3120 struct dead_debug_local *debug)
3122 unsigned int dregno = DF_REF_REGNO (def);
3124 if (REG_DEAD_DEBUGGING && dump_file)
3126 fprintf (dump_file, " regular looking at def ");
3127 df_ref_debug (def, dump_file);
3130 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3131 || bitmap_bit_p (live, dregno)
3132 || bitmap_bit_p (artificial_uses, dregno)
3133 || df_ignore_stack_reg (dregno)))
3135 rtx reg = (DF_REF_LOC (def))
3136 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3137 df_set_note (REG_UNUSED, insn, reg);
3138 dead_debug_insert_temp (debug, dregno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3139 if (REG_DEAD_DEBUGGING)
3140 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3143 return;
3147 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3148 info: lifetime, bb, and number of defs and uses for basic block
3149 BB. The three bitvectors are scratch regs used here. */
3151 static void
3152 df_note_bb_compute (unsigned int bb_index,
3153 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3155 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
3156 rtx insn;
3157 df_ref *def_rec;
3158 df_ref *use_rec;
3159 struct dead_debug_local debug;
3161 dead_debug_local_init (&debug, NULL, NULL);
3163 bitmap_copy (live, df_get_live_out (bb));
3164 bitmap_clear (artificial_uses);
3166 if (REG_DEAD_DEBUGGING && dump_file)
3168 fprintf (dump_file, "live at bottom ");
3169 df_print_regset (dump_file, live);
3172 /* Process the artificial defs and uses at the bottom of the block
3173 to begin processing. */
3174 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3176 df_ref def = *def_rec;
3178 if (REG_DEAD_DEBUGGING && dump_file)
3179 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3181 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3182 bitmap_clear_bit (live, DF_REF_REGNO (def));
3185 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3187 df_ref use = *use_rec;
3188 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3190 unsigned int regno = DF_REF_REGNO (use);
3191 bitmap_set_bit (live, regno);
3193 /* Notes are not generated for any of the artificial registers
3194 at the bottom of the block. */
3195 bitmap_set_bit (artificial_uses, regno);
3199 if (REG_DEAD_DEBUGGING && dump_file)
3201 fprintf (dump_file, "live before artificials out ");
3202 df_print_regset (dump_file, live);
3205 FOR_BB_INSNS_REVERSE (bb, insn)
3207 unsigned int uid = INSN_UID (insn);
3208 struct df_mw_hardreg **mws_rec;
3209 int debug_insn;
3211 if (!INSN_P (insn))
3212 continue;
3214 debug_insn = DEBUG_INSN_P (insn);
3216 bitmap_clear (do_not_gen);
3217 df_remove_dead_and_unused_notes (insn);
3219 /* Process the defs. */
3220 if (CALL_P (insn))
3222 if (REG_DEAD_DEBUGGING && dump_file)
3224 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3225 df_print_regset (dump_file, live);
3228 /* We only care about real sets for calls. Clobbers cannot
3229 be depended on to really die. */
3230 mws_rec = DF_INSN_UID_MWS (uid);
3231 while (*mws_rec)
3233 struct df_mw_hardreg *mws = *mws_rec;
3234 if ((DF_MWS_REG_DEF_P (mws))
3235 && !df_ignore_stack_reg (mws->start_regno))
3236 df_set_unused_notes_for_mw (insn,
3237 mws, live, do_not_gen,
3238 artificial_uses, &debug);
3239 mws_rec++;
3242 /* All of the defs except the return value are some sort of
3243 clobber. This code is for the return. */
3244 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3246 df_ref def = *def_rec;
3247 unsigned int dregno = DF_REF_REGNO (def);
3248 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3250 df_create_unused_note (insn,
3251 def, live, artificial_uses, &debug);
3252 bitmap_set_bit (do_not_gen, dregno);
3255 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3256 bitmap_clear_bit (live, dregno);
3259 else
3261 /* Regular insn. */
3262 mws_rec = DF_INSN_UID_MWS (uid);
3263 while (*mws_rec)
3265 struct df_mw_hardreg *mws = *mws_rec;
3266 if (DF_MWS_REG_DEF_P (mws))
3267 df_set_unused_notes_for_mw (insn,
3268 mws, live, do_not_gen,
3269 artificial_uses, &debug);
3270 mws_rec++;
3273 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3275 df_ref def = *def_rec;
3276 unsigned int dregno = DF_REF_REGNO (def);
3277 df_create_unused_note (insn,
3278 def, live, artificial_uses, &debug);
3280 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3281 bitmap_set_bit (do_not_gen, dregno);
3283 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3284 bitmap_clear_bit (live, dregno);
3288 /* Process the uses. */
3289 mws_rec = DF_INSN_UID_MWS (uid);
3290 while (*mws_rec)
3292 struct df_mw_hardreg *mws = *mws_rec;
3293 if (DF_MWS_REG_USE_P (mws)
3294 && !df_ignore_stack_reg (mws->start_regno))
3296 bool really_add_notes = debug_insn != 0;
3298 df_set_dead_notes_for_mw (insn,
3299 mws, live, do_not_gen,
3300 artificial_uses,
3301 &really_add_notes);
3303 if (really_add_notes)
3304 debug_insn = -1;
3306 mws_rec++;
3309 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3311 df_ref use = *use_rec;
3312 unsigned int uregno = DF_REF_REGNO (use);
3314 if (REG_DEAD_DEBUGGING && dump_file && !debug_insn)
3316 fprintf (dump_file, " regular looking at use ");
3317 df_ref_debug (use, dump_file);
3320 if (!bitmap_bit_p (live, uregno))
3322 if (debug_insn)
3324 if (debug_insn > 0)
3326 /* We won't add REG_UNUSED or REG_DEAD notes for
3327 these, so we don't have to mess with them in
3328 debug insns either. */
3329 if (!bitmap_bit_p (artificial_uses, uregno)
3330 && !df_ignore_stack_reg (uregno))
3331 dead_debug_add (&debug, use, uregno);
3332 continue;
3334 break;
3336 else
3337 dead_debug_insert_temp (&debug, uregno, insn,
3338 DEBUG_TEMP_BEFORE_WITH_REG);
3340 if ( (!(DF_REF_FLAGS (use)
3341 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3342 && (!bitmap_bit_p (do_not_gen, uregno))
3343 && (!bitmap_bit_p (artificial_uses, uregno))
3344 && (!df_ignore_stack_reg (uregno)))
3346 rtx reg = (DF_REF_LOC (use))
3347 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3348 df_set_note (REG_DEAD, insn, reg);
3350 if (REG_DEAD_DEBUGGING)
3351 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3353 /* This register is now live. */
3354 bitmap_set_bit (live, uregno);
3358 df_remove_dead_eq_notes (insn, live);
3360 if (debug_insn == -1)
3362 /* ??? We could probably do better here, replacing dead
3363 registers with their definitions. */
3364 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3365 df_insn_rescan_debug_internal (insn);
3369 dead_debug_local_finish (&debug, NULL);
3373 /* Compute register info: lifetime, bb, and number of defs and uses. */
3374 static void
3375 df_note_compute (bitmap all_blocks)
3377 unsigned int bb_index;
3378 bitmap_iterator bi;
3379 bitmap_head live, do_not_gen, artificial_uses;
3381 bitmap_initialize (&live, &df_bitmap_obstack);
3382 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3383 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3385 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3387 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3388 pseudos in debug insns because we don't always (re)visit blocks
3389 with death points after visiting dead uses. Even changing this
3390 loop to postorder would still leave room for visiting a death
3391 point before visiting a subsequent debug use. */
3392 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3395 bitmap_clear (&live);
3396 bitmap_clear (&do_not_gen);
3397 bitmap_clear (&artificial_uses);
3401 /* Free all storage associated with the problem. */
3403 static void
3404 df_note_free (void)
3406 free (df_note);
3410 /* All of the information associated every instance of the problem. */
3412 static struct df_problem problem_NOTE =
3414 DF_NOTE, /* Problem id. */
3415 DF_NONE, /* Direction. */
3416 df_note_alloc, /* Allocate the problem specific data. */
3417 NULL, /* Reset global information. */
3418 NULL, /* Free basic block info. */
3419 df_note_compute, /* Local compute function. */
3420 NULL, /* Init the solution specific data. */
3421 NULL, /* Iterative solver. */
3422 NULL, /* Confluence operator 0. */
3423 NULL, /* Confluence operator n. */
3424 NULL, /* Transfer function. */
3425 NULL, /* Finalize function. */
3426 df_note_free, /* Free all of the problem information. */
3427 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3428 NULL, /* Debugging. */
3429 NULL, /* Debugging start block. */
3430 NULL, /* Debugging end block. */
3431 NULL, /* Debugging start insn. */
3432 NULL, /* Debugging end insn. */
3433 NULL, /* Incremental solution verify start. */
3434 NULL, /* Incremental solution verify end. */
3435 &problem_LR, /* Dependent problem. */
3436 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
3437 TV_DF_NOTE, /* Timing variable. */
3438 false /* Reset blocks on dropping out of blocks_to_analyze. */
3442 /* Create a new DATAFLOW instance and add it to an existing instance
3443 of DF. The returned structure is what is used to get at the
3444 solution. */
3446 void
3447 df_note_add_problem (void)
3449 df_add_problem (&problem_NOTE);
3455 /*----------------------------------------------------------------------------
3456 Functions for simulating the effects of single insns.
3458 You can either simulate in the forwards direction, starting from
3459 the top of a block or the backwards direction from the end of the
3460 block. If you go backwards, defs are examined first to clear bits,
3461 then uses are examined to set bits. If you go forwards, defs are
3462 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3463 are examined to clear bits. In either case, the result of examining
3464 a def can be undone (respectively by a use or a REG_UNUSED note).
3466 If you start at the top of the block, use one of DF_LIVE_IN or
3467 DF_LR_IN. If you start at the bottom of the block use one of
3468 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3469 THEY WILL BE DESTROYED.
3470 ----------------------------------------------------------------------------*/
3473 /* Find the set of DEFs for INSN. */
3475 void
3476 df_simulate_find_defs (rtx insn, bitmap defs)
3478 df_ref *def_rec;
3479 unsigned int uid = INSN_UID (insn);
3481 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3483 df_ref def = *def_rec;
3484 bitmap_set_bit (defs, DF_REF_REGNO (def));
3488 /* Find the set of uses for INSN. This includes partial defs. */
3490 static void
3491 df_simulate_find_uses (rtx insn, bitmap uses)
3493 df_ref *rec;
3494 unsigned int uid = INSN_UID (insn);
3496 for (rec = DF_INSN_UID_DEFS (uid); *rec; rec++)
3498 df_ref def = *rec;
3499 if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3500 bitmap_set_bit (uses, DF_REF_REGNO (def));
3502 for (rec = DF_INSN_UID_USES (uid); *rec; rec++)
3504 df_ref use = *rec;
3505 bitmap_set_bit (uses, DF_REF_REGNO (use));
3509 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3511 void
3512 df_simulate_find_noclobber_defs (rtx insn, bitmap defs)
3514 df_ref *def_rec;
3515 unsigned int uid = INSN_UID (insn);
3517 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3519 df_ref def = *def_rec;
3520 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3521 bitmap_set_bit (defs, DF_REF_REGNO (def));
3526 /* Simulate the effects of the defs of INSN on LIVE. */
3528 void
3529 df_simulate_defs (rtx insn, bitmap live)
3531 df_ref *def_rec;
3532 unsigned int uid = INSN_UID (insn);
3534 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3536 df_ref def = *def_rec;
3537 unsigned int dregno = DF_REF_REGNO (def);
3539 /* If the def is to only part of the reg, it does
3540 not kill the other defs that reach here. */
3541 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3542 bitmap_clear_bit (live, dregno);
3547 /* Simulate the effects of the uses of INSN on LIVE. */
3549 void
3550 df_simulate_uses (rtx insn, bitmap live)
3552 df_ref *use_rec;
3553 unsigned int uid = INSN_UID (insn);
3555 if (DEBUG_INSN_P (insn))
3556 return;
3558 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3560 df_ref use = *use_rec;
3561 /* Add use to set of uses in this BB. */
3562 bitmap_set_bit (live, DF_REF_REGNO (use));
3567 /* Add back the always live regs in BB to LIVE. */
3569 static inline void
3570 df_simulate_fixup_sets (basic_block bb, bitmap live)
3572 /* These regs are considered always live so if they end up dying
3573 because of some def, we need to bring the back again. */
3574 if (bb_has_eh_pred (bb))
3575 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3576 else
3577 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3581 /*----------------------------------------------------------------------------
3582 The following three functions are used only for BACKWARDS scanning:
3583 i.e. they process the defs before the uses.
3585 df_simulate_initialize_backwards should be called first with a
3586 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3587 df_simulate_one_insn_backwards should be called for each insn in
3588 the block, starting with the last one. Finally,
3589 df_simulate_finalize_backwards can be called to get a new value
3590 of the sets at the top of the block (this is rarely used).
3591 ----------------------------------------------------------------------------*/
3593 /* Apply the artificial uses and defs at the end of BB in a backwards
3594 direction. */
3596 void
3597 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3599 df_ref *def_rec;
3600 df_ref *use_rec;
3601 int bb_index = bb->index;
3603 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3605 df_ref def = *def_rec;
3606 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3607 bitmap_clear_bit (live, DF_REF_REGNO (def));
3610 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3612 df_ref use = *use_rec;
3613 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3614 bitmap_set_bit (live, DF_REF_REGNO (use));
3619 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3621 void
3622 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3624 if (!NONDEBUG_INSN_P (insn))
3625 return;
3627 df_simulate_defs (insn, live);
3628 df_simulate_uses (insn, live);
3629 df_simulate_fixup_sets (bb, live);
3633 /* Apply the artificial uses and defs at the top of BB in a backwards
3634 direction. */
3636 void
3637 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3639 df_ref *def_rec;
3640 #ifdef EH_USES
3641 df_ref *use_rec;
3642 #endif
3643 int bb_index = bb->index;
3645 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3647 df_ref def = *def_rec;
3648 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3649 bitmap_clear_bit (live, DF_REF_REGNO (def));
3652 #ifdef EH_USES
3653 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3655 df_ref use = *use_rec;
3656 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3657 bitmap_set_bit (live, DF_REF_REGNO (use));
3659 #endif
3661 /*----------------------------------------------------------------------------
3662 The following three functions are used only for FORWARDS scanning:
3663 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3664 Thus it is important to add the DF_NOTES problem to the stack of
3665 problems computed before using these functions.
3667 df_simulate_initialize_forwards should be called first with a
3668 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3669 df_simulate_one_insn_forwards should be called for each insn in
3670 the block, starting with the first one.
3671 ----------------------------------------------------------------------------*/
3673 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3674 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3675 defs live. */
3677 void
3678 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3680 df_ref *def_rec;
3681 int bb_index = bb->index;
3683 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3685 df_ref def = *def_rec;
3686 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3687 bitmap_set_bit (live, DF_REF_REGNO (def));
3691 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3693 void
3694 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3696 rtx link;
3697 if (! INSN_P (insn))
3698 return;
3700 /* Make sure that DF_NOTE really is an active df problem. */
3701 gcc_assert (df_note);
3703 /* Note that this is the opposite as how the problem is defined, because
3704 in the LR problem defs _kill_ liveness. However, they do so backwards,
3705 while here the scan is performed forwards! So, first assume that the
3706 def is live, and if this is not true REG_UNUSED notes will rectify the
3707 situation. */
3708 df_simulate_find_noclobber_defs (insn, live);
3710 /* Clear all of the registers that go dead. */
3711 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3713 switch (REG_NOTE_KIND (link))
3715 case REG_DEAD:
3716 case REG_UNUSED:
3718 rtx reg = XEXP (link, 0);
3719 int regno = REGNO (reg);
3720 if (HARD_REGISTER_NUM_P (regno))
3721 bitmap_clear_range (live, regno,
3722 hard_regno_nregs[regno][GET_MODE (reg)]);
3723 else
3724 bitmap_clear_bit (live, regno);
3726 break;
3727 default:
3728 break;
3731 df_simulate_fixup_sets (bb, live);
3734 /* Used by the next two functions to encode information about the
3735 memory references we found. */
3736 #define MEMREF_NORMAL 1
3737 #define MEMREF_VOLATILE 2
3739 /* A subroutine of can_move_insns_across_p called through for_each_rtx.
3740 Return either MEMREF_NORMAL or MEMREF_VOLATILE if a memory is found. */
3742 static int
3743 find_memory (rtx *px, void *data ATTRIBUTE_UNUSED)
3745 rtx x = *px;
3747 if (GET_CODE (x) == ASM_OPERANDS && MEM_VOLATILE_P (x))
3748 return MEMREF_VOLATILE;
3750 if (!MEM_P (x))
3751 return 0;
3752 if (MEM_VOLATILE_P (x))
3753 return MEMREF_VOLATILE;
3754 if (MEM_READONLY_P (x))
3755 return 0;
3757 return MEMREF_NORMAL;
3760 /* A subroutine of can_move_insns_across_p called through note_stores.
3761 DATA points to an integer in which we set either the bit for
3762 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3763 of either kind. */
3765 static void
3766 find_memory_stores (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
3767 void *data ATTRIBUTE_UNUSED)
3769 int *pflags = (int *)data;
3770 if (GET_CODE (x) == SUBREG)
3771 x = XEXP (x, 0);
3772 /* Treat stores to SP as stores to memory, this will prevent problems
3773 when there are references to the stack frame. */
3774 if (x == stack_pointer_rtx)
3775 *pflags |= MEMREF_VOLATILE;
3776 if (!MEM_P (x))
3777 return;
3778 *pflags |= MEM_VOLATILE_P (x) ? MEMREF_VOLATILE : MEMREF_NORMAL;
3781 /* Scan BB backwards, using df_simulate functions to keep track of
3782 lifetimes, up to insn POINT. The result is stored in LIVE. */
3784 void
3785 simulate_backwards_to_point (basic_block bb, regset live, rtx point)
3787 rtx insn;
3788 bitmap_copy (live, df_get_live_out (bb));
3789 df_simulate_initialize_backwards (bb, live);
3791 /* Scan and update life information until we reach the point we're
3792 interested in. */
3793 for (insn = BB_END (bb); insn != point; insn = PREV_INSN (insn))
3794 df_simulate_one_insn_backwards (bb, insn, live);
3797 /* Return true if it is safe to move a group of insns, described by
3798 the range FROM to TO, backwards across another group of insns,
3799 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3800 are no insns between ACROSS_TO and FROM, but they may be in
3801 different basic blocks; MERGE_BB is the block from which the
3802 insns will be moved. The caller must pass in a regset MERGE_LIVE
3803 which specifies the registers live after TO.
3805 This function may be called in one of two cases: either we try to
3806 move identical instructions from all successor blocks into their
3807 predecessor, or we try to move from only one successor block. If
3808 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3809 the second case. It should contain a set of registers live at the
3810 end of ACROSS_TO which must not be clobbered by moving the insns.
3811 In that case, we're also more careful about moving memory references
3812 and trapping insns.
3814 We return false if it is not safe to move the entire group, but it
3815 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3816 is set to point at the last moveable insn in such a case. */
3818 bool
3819 can_move_insns_across (rtx from, rtx to, rtx across_from, rtx across_to,
3820 basic_block merge_bb, regset merge_live,
3821 regset other_branch_live, rtx *pmove_upto)
3823 rtx insn, next, max_to;
3824 bitmap merge_set, merge_use, local_merge_live;
3825 bitmap test_set, test_use;
3826 unsigned i, fail = 0;
3827 bitmap_iterator bi;
3828 int memrefs_in_across = 0;
3829 int mem_sets_in_across = 0;
3830 bool trapping_insns_in_across = false;
3832 if (pmove_upto != NULL)
3833 *pmove_upto = NULL_RTX;
3835 /* Find real bounds, ignoring debug insns. */
3836 while (!NONDEBUG_INSN_P (from) && from != to)
3837 from = NEXT_INSN (from);
3838 while (!NONDEBUG_INSN_P (to) && from != to)
3839 to = PREV_INSN (to);
3841 for (insn = across_to; ; insn = next)
3843 if (CALL_P (insn))
3845 if (RTL_CONST_OR_PURE_CALL_P (insn))
3846 /* Pure functions can read from memory. Const functions can
3847 read from arguments that the ABI has forced onto the stack.
3848 Neither sort of read can be volatile. */
3849 memrefs_in_across |= MEMREF_NORMAL;
3850 else
3852 memrefs_in_across |= MEMREF_VOLATILE;
3853 mem_sets_in_across |= MEMREF_VOLATILE;
3856 if (NONDEBUG_INSN_P (insn))
3858 if (volatile_insn_p (PATTERN (insn)))
3859 return false;
3860 memrefs_in_across |= for_each_rtx (&PATTERN (insn), find_memory,
3861 NULL);
3862 note_stores (PATTERN (insn), find_memory_stores,
3863 &mem_sets_in_across);
3864 /* This is used just to find sets of the stack pointer. */
3865 memrefs_in_across |= mem_sets_in_across;
3866 trapping_insns_in_across |= may_trap_p (PATTERN (insn));
3868 next = PREV_INSN (insn);
3869 if (insn == across_from)
3870 break;
3873 /* Collect:
3874 MERGE_SET = set of registers set in MERGE_BB
3875 MERGE_USE = set of registers used in MERGE_BB and live at its top
3876 MERGE_LIVE = set of registers live at the point inside the MERGE
3877 range that we've reached during scanning
3878 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3879 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3880 and live before ACROSS_FROM. */
3882 merge_set = BITMAP_ALLOC (&reg_obstack);
3883 merge_use = BITMAP_ALLOC (&reg_obstack);
3884 local_merge_live = BITMAP_ALLOC (&reg_obstack);
3885 test_set = BITMAP_ALLOC (&reg_obstack);
3886 test_use = BITMAP_ALLOC (&reg_obstack);
3888 /* Compute the set of registers set and used in the ACROSS range. */
3889 if (other_branch_live != NULL)
3890 bitmap_copy (test_use, other_branch_live);
3891 df_simulate_initialize_backwards (merge_bb, test_use);
3892 for (insn = across_to; ; insn = next)
3894 if (NONDEBUG_INSN_P (insn))
3896 df_simulate_find_defs (insn, test_set);
3897 df_simulate_defs (insn, test_use);
3898 df_simulate_uses (insn, test_use);
3900 next = PREV_INSN (insn);
3901 if (insn == across_from)
3902 break;
3905 /* Compute an upper bound for the amount of insns moved, by finding
3906 the first insn in MERGE that sets a register in TEST_USE, or uses
3907 a register in TEST_SET. We also check for calls, trapping operations,
3908 and memory references. */
3909 max_to = NULL_RTX;
3910 for (insn = from; ; insn = next)
3912 if (CALL_P (insn))
3913 break;
3914 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
3915 break;
3916 if (NONDEBUG_INSN_P (insn))
3918 if (may_trap_or_fault_p (PATTERN (insn))
3919 && (trapping_insns_in_across
3920 || other_branch_live != NULL
3921 || volatile_insn_p (PATTERN (insn))))
3922 break;
3924 /* We cannot move memory stores past each other, or move memory
3925 reads past stores, at least not without tracking them and
3926 calling true_dependence on every pair.
3928 If there is no other branch and no memory references or
3929 sets in the ACROSS range, we can move memory references
3930 freely, even volatile ones.
3932 Otherwise, the rules are as follows: volatile memory
3933 references and stores can't be moved at all, and any type
3934 of memory reference can't be moved if there are volatile
3935 accesses or stores in the ACROSS range. That leaves
3936 normal reads, which can be moved, as the trapping case is
3937 dealt with elsewhere. */
3938 if (other_branch_live != NULL || memrefs_in_across != 0)
3940 int mem_ref_flags = 0;
3941 int mem_set_flags = 0;
3942 note_stores (PATTERN (insn), find_memory_stores, &mem_set_flags);
3943 mem_ref_flags = for_each_rtx (&PATTERN (insn), find_memory,
3944 NULL);
3945 /* Catch sets of the stack pointer. */
3946 mem_ref_flags |= mem_set_flags;
3948 if ((mem_ref_flags | mem_set_flags) & MEMREF_VOLATILE)
3949 break;
3950 if ((memrefs_in_across & MEMREF_VOLATILE) && mem_ref_flags != 0)
3951 break;
3952 if (mem_set_flags != 0
3953 || (mem_sets_in_across != 0 && mem_ref_flags != 0))
3954 break;
3956 df_simulate_find_uses (insn, merge_use);
3957 /* We're only interested in uses which use a value live at
3958 the top, not one previously set in this block. */
3959 bitmap_and_compl_into (merge_use, merge_set);
3960 df_simulate_find_defs (insn, merge_set);
3961 if (bitmap_intersect_p (merge_set, test_use)
3962 || bitmap_intersect_p (merge_use, test_set))
3963 break;
3964 #ifdef HAVE_cc0
3965 if (!sets_cc0_p (insn))
3966 #endif
3967 max_to = insn;
3969 next = NEXT_INSN (insn);
3970 if (insn == to)
3971 break;
3973 if (max_to != to)
3974 fail = 1;
3976 if (max_to == NULL_RTX || (fail && pmove_upto == NULL))
3977 goto out;
3979 /* Now, lower this upper bound by also taking into account that
3980 a range of insns moved across ACROSS must not leave a register
3981 live at the end that will be clobbered in ACROSS. We need to
3982 find a point where TEST_SET & LIVE == 0.
3984 Insns in the MERGE range that set registers which are also set
3985 in the ACROSS range may still be moved as long as we also move
3986 later insns which use the results of the set, and make the
3987 register dead again. This is verified by the condition stated
3988 above. We only need to test it for registers that are set in
3989 the moved region.
3991 MERGE_LIVE is provided by the caller and holds live registers after
3992 TO. */
3993 bitmap_copy (local_merge_live, merge_live);
3994 for (insn = to; insn != max_to; insn = PREV_INSN (insn))
3995 df_simulate_one_insn_backwards (merge_bb, insn, local_merge_live);
3997 /* We're not interested in registers that aren't set in the moved
3998 region at all. */
3999 bitmap_and_into (local_merge_live, merge_set);
4000 for (;;)
4002 if (NONDEBUG_INSN_P (insn))
4004 if (!bitmap_intersect_p (test_set, local_merge_live)
4005 #ifdef HAVE_cc0
4006 && !sets_cc0_p (insn)
4007 #endif
4010 max_to = insn;
4011 break;
4014 df_simulate_one_insn_backwards (merge_bb, insn,
4015 local_merge_live);
4017 if (insn == from)
4019 fail = 1;
4020 goto out;
4022 insn = PREV_INSN (insn);
4025 if (max_to != to)
4026 fail = 1;
4028 if (pmove_upto)
4029 *pmove_upto = max_to;
4031 /* For small register class machines, don't lengthen lifetimes of
4032 hard registers before reload. */
4033 if (! reload_completed
4034 && targetm.small_register_classes_for_mode_p (VOIDmode))
4036 EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
4038 if (i < FIRST_PSEUDO_REGISTER
4039 && ! fixed_regs[i]
4040 && ! global_regs[i])
4042 fail = 1;
4043 break;
4048 out:
4049 BITMAP_FREE (merge_set);
4050 BITMAP_FREE (merge_use);
4051 BITMAP_FREE (local_merge_live);
4052 BITMAP_FREE (test_set);
4053 BITMAP_FREE (test_use);
4055 return !fail;
4059 /*----------------------------------------------------------------------------
4060 MULTIPLE DEFINITIONS
4062 Find the locations in the function reached by multiple definition sites
4063 for a live pseudo. In and out bitvectors are built for each basic
4064 block. They are restricted for efficiency to live registers.
4066 The gen and kill sets for the problem are obvious. Together they
4067 include all defined registers in a basic block; the gen set includes
4068 registers where a partial or conditional or may-clobber definition is
4069 last in the BB, while the kill set includes registers with a complete
4070 definition coming last. However, the computation of the dataflow
4071 itself is interesting.
4073 The idea behind it comes from SSA form's iterated dominance frontier
4074 criterion for inserting PHI functions. Just like in that case, we can use
4075 the dominance frontier to find places where multiple definitions meet;
4076 a register X defined in a basic block BB1 has multiple definitions in
4077 basic blocks in BB1's dominance frontier.
4079 So, the in-set of a basic block BB2 is not just the union of the
4080 out-sets of BB2's predecessors, but includes some more bits that come
4081 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
4082 the previous paragraph). I called this set the init-set of BB2.
4084 (Note: I actually use the kill-set only to build the init-set.
4085 gen bits are anyway propagated from BB1 to BB2 by dataflow).
4087 For example, if you have
4089 BB1 : r10 = 0
4090 r11 = 0
4091 if <...> goto BB2 else goto BB3;
4093 BB2 : r10 = 1
4094 r12 = 1
4095 goto BB3;
4097 BB3 :
4099 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
4100 init-set of BB3 includes r10 and r12, but not r11. Note that we do
4101 not need to iterate the dominance frontier, because we do not insert
4102 anything like PHI functions there! Instead, dataflow will take care of
4103 propagating the information to BB3's successors.
4104 ---------------------------------------------------------------------------*/
4106 /* Private data used to verify the solution for this problem. */
4107 struct df_md_problem_data
4109 /* An obstack for the bitmaps we need for this problem. */
4110 bitmap_obstack md_bitmaps;
4113 /* Scratch var used by transfer functions. This is used to do md analysis
4114 only for live registers. */
4115 static bitmap_head df_md_scratch;
4118 static void
4119 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
4120 void *vbb_info)
4122 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
4123 if (bb_info)
4125 bitmap_clear (&bb_info->kill);
4126 bitmap_clear (&bb_info->gen);
4127 bitmap_clear (&bb_info->init);
4128 bitmap_clear (&bb_info->in);
4129 bitmap_clear (&bb_info->out);
4134 /* Allocate or reset bitmaps for DF_MD. The solution bits are
4135 not touched unless the block is new. */
4137 static void
4138 df_md_alloc (bitmap all_blocks)
4140 unsigned int bb_index;
4141 bitmap_iterator bi;
4142 struct df_md_problem_data *problem_data;
4144 df_grow_bb_info (df_md);
4145 if (df_md->problem_data)
4146 problem_data = (struct df_md_problem_data *) df_md->problem_data;
4147 else
4149 problem_data = XNEW (struct df_md_problem_data);
4150 df_md->problem_data = problem_data;
4151 bitmap_obstack_initialize (&problem_data->md_bitmaps);
4153 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
4155 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4157 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4158 /* When bitmaps are already initialized, just clear them. */
4159 if (bb_info->init.obstack)
4161 bitmap_clear (&bb_info->init);
4162 bitmap_clear (&bb_info->gen);
4163 bitmap_clear (&bb_info->kill);
4164 bitmap_clear (&bb_info->in);
4165 bitmap_clear (&bb_info->out);
4167 else
4169 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4170 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4171 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4172 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4173 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
4177 df_md->optional_p = true;
4180 /* Add the effect of the top artificial defs of BB to the multiple definitions
4181 bitmap LOCAL_MD. */
4183 void
4184 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4186 int bb_index = bb->index;
4187 df_ref *def_rec;
4188 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4190 df_ref def = *def_rec;
4191 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4193 unsigned int dregno = DF_REF_REGNO (def);
4194 if (DF_REF_FLAGS (def)
4195 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4196 bitmap_set_bit (local_md, dregno);
4197 else
4198 bitmap_clear_bit (local_md, dregno);
4204 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4205 LOCAL_MD. */
4207 void
4208 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
4209 bitmap local_md)
4211 unsigned uid = INSN_UID (insn);
4212 df_ref *def_rec;
4214 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4216 df_ref def = *def_rec;
4217 unsigned int dregno = DF_REF_REGNO (def);
4218 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4219 || (dregno >= FIRST_PSEUDO_REGISTER))
4221 if (DF_REF_FLAGS (def)
4222 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4223 bitmap_set_bit (local_md, DF_REF_ID (def));
4224 else
4225 bitmap_clear_bit (local_md, DF_REF_ID (def));
4230 static void
4231 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
4232 df_ref *def_rec,
4233 int top_flag)
4235 df_ref def;
4236 bitmap_clear (&seen_in_insn);
4238 while ((def = *def_rec++) != NULL)
4240 unsigned int dregno = DF_REF_REGNO (def);
4241 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4242 || (dregno >= FIRST_PSEUDO_REGISTER))
4243 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4245 if (!bitmap_bit_p (&seen_in_insn, dregno))
4247 if (DF_REF_FLAGS (def)
4248 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4250 bitmap_set_bit (&bb_info->gen, dregno);
4251 bitmap_clear_bit (&bb_info->kill, dregno);
4253 else
4255 /* When we find a clobber and a regular def,
4256 make sure the regular def wins. */
4257 bitmap_set_bit (&seen_in_insn, dregno);
4258 bitmap_set_bit (&bb_info->kill, dregno);
4259 bitmap_clear_bit (&bb_info->gen, dregno);
4267 /* Compute local multiple def info for basic block BB. */
4269 static void
4270 df_md_bb_local_compute (unsigned int bb_index)
4272 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4273 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4274 rtx insn;
4276 /* Artificials are only hard regs. */
4277 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4278 df_md_bb_local_compute_process_def (bb_info,
4279 df_get_artificial_defs (bb_index),
4280 DF_REF_AT_TOP);
4282 FOR_BB_INSNS (bb, insn)
4284 unsigned int uid = INSN_UID (insn);
4285 if (!INSN_P (insn))
4286 continue;
4288 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4291 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4292 df_md_bb_local_compute_process_def (bb_info,
4293 df_get_artificial_defs (bb_index),
4297 /* Compute local reaching def info for each basic block within BLOCKS. */
4299 static void
4300 df_md_local_compute (bitmap all_blocks)
4302 unsigned int bb_index, df_bb_index;
4303 bitmap_iterator bi1, bi2;
4304 basic_block bb;
4305 bitmap_head *frontiers;
4307 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4309 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4311 df_md_bb_local_compute (bb_index);
4314 bitmap_clear (&seen_in_insn);
4316 frontiers = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
4317 FOR_ALL_BB_FN (bb, cfun)
4318 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4320 compute_dominance_frontiers (frontiers);
4322 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4323 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4325 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4326 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4328 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, df_bb_index);
4329 if (bitmap_bit_p (all_blocks, df_bb_index))
4330 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4331 df_get_live_in (bb));
4335 FOR_ALL_BB_FN (bb, cfun)
4336 bitmap_clear (&frontiers[bb->index]);
4337 free (frontiers);
4341 /* Reset the global solution for recalculation. */
4343 static void
4344 df_md_reset (bitmap all_blocks)
4346 unsigned int bb_index;
4347 bitmap_iterator bi;
4349 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4351 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4352 gcc_assert (bb_info);
4353 bitmap_clear (&bb_info->in);
4354 bitmap_clear (&bb_info->out);
4358 static bool
4359 df_md_transfer_function (int bb_index)
4361 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4362 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4363 bitmap in = &bb_info->in;
4364 bitmap out = &bb_info->out;
4365 bitmap gen = &bb_info->gen;
4366 bitmap kill = &bb_info->kill;
4368 /* We need to use a scratch set here so that the value returned from this
4369 function invocation properly reflects whether the sets changed in a
4370 significant way; i.e. not just because the live set was anded in. */
4371 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4373 /* Multiple definitions of a register are not relevant if it is not
4374 live. Thus we trim the result to the places where it is live. */
4375 bitmap_and_into (in, df_get_live_in (bb));
4377 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4380 /* Initialize the solution bit vectors for problem. */
4382 static void
4383 df_md_init (bitmap all_blocks)
4385 unsigned int bb_index;
4386 bitmap_iterator bi;
4388 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4390 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4392 bitmap_copy (&bb_info->in, &bb_info->init);
4393 df_md_transfer_function (bb_index);
4397 static void
4398 df_md_confluence_0 (basic_block bb)
4400 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4401 bitmap_copy (&bb_info->in, &bb_info->init);
4404 /* In of target gets or of out of source. */
4406 static bool
4407 df_md_confluence_n (edge e)
4409 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4410 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4412 if (e->flags & EDGE_FAKE)
4413 return false;
4415 if (e->flags & EDGE_EH)
4416 return bitmap_ior_and_compl_into (op1, op2,
4417 regs_invalidated_by_call_regset);
4418 else
4419 return bitmap_ior_into (op1, op2);
4422 /* Free all storage associated with the problem. */
4424 static void
4425 df_md_free (void)
4427 struct df_md_problem_data *problem_data
4428 = (struct df_md_problem_data *) df_md->problem_data;
4430 bitmap_obstack_release (&problem_data->md_bitmaps);
4431 free (problem_data);
4432 df_md->problem_data = NULL;
4434 df_md->block_info_size = 0;
4435 free (df_md->block_info);
4436 df_md->block_info = NULL;
4437 free (df_md);
4441 /* Debugging info at top of bb. */
4443 static void
4444 df_md_top_dump (basic_block bb, FILE *file)
4446 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4447 if (!bb_info)
4448 return;
4450 fprintf (file, ";; md in \t");
4451 df_print_regset (file, &bb_info->in);
4452 fprintf (file, ";; md init \t");
4453 df_print_regset (file, &bb_info->init);
4454 fprintf (file, ";; md gen \t");
4455 df_print_regset (file, &bb_info->gen);
4456 fprintf (file, ";; md kill \t");
4457 df_print_regset (file, &bb_info->kill);
4460 /* Debugging info at bottom of bb. */
4462 static void
4463 df_md_bottom_dump (basic_block bb, FILE *file)
4465 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4466 if (!bb_info)
4467 return;
4469 fprintf (file, ";; md out \t");
4470 df_print_regset (file, &bb_info->out);
4473 static struct df_problem problem_MD =
4475 DF_MD, /* Problem id. */
4476 DF_FORWARD, /* Direction. */
4477 df_md_alloc, /* Allocate the problem specific data. */
4478 df_md_reset, /* Reset global information. */
4479 df_md_free_bb_info, /* Free basic block info. */
4480 df_md_local_compute, /* Local compute function. */
4481 df_md_init, /* Init the solution specific data. */
4482 df_worklist_dataflow, /* Worklist solver. */
4483 df_md_confluence_0, /* Confluence operator 0. */
4484 df_md_confluence_n, /* Confluence operator n. */
4485 df_md_transfer_function, /* Transfer function. */
4486 NULL, /* Finalize function. */
4487 df_md_free, /* Free all of the problem information. */
4488 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4489 NULL, /* Debugging. */
4490 df_md_top_dump, /* Debugging start block. */
4491 df_md_bottom_dump, /* Debugging end block. */
4492 NULL, /* Debugging start insn. */
4493 NULL, /* Debugging end insn. */
4494 NULL, /* Incremental solution verify start. */
4495 NULL, /* Incremental solution verify end. */
4496 NULL, /* Dependent problem. */
4497 sizeof (struct df_md_bb_info),/* Size of entry of block_info array. */
4498 TV_DF_MD, /* Timing variable. */
4499 false /* Reset blocks on dropping out of blocks_to_analyze. */
4502 /* Create a new MD instance and add it to the existing instance
4503 of DF. */
4505 void
4506 df_md_add_problem (void)
4508 df_add_problem (&problem_MD);