2008-01-07 Jack Howarth <howarth@bromo.med.uc.edu>
[official-gcc.git] / gcc / df-problems.c
blobed56c7feec51717916ba19dc80280f1353a43d9b
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "recog.h"
33 #include "function.h"
34 #include "regs.h"
35 #include "output.h"
36 #include "alloc-pool.h"
37 #include "flags.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "sbitmap.h"
41 #include "bitmap.h"
42 #include "timevar.h"
43 #include "df.h"
44 #include "except.h"
45 #include "dce.h"
46 #include "vecprim.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 #if 0
52 #define REG_DEAD_DEBUGGING
53 #endif
55 #define DF_SPARSE_THRESHOLD 32
57 static bitmap seen_in_block = NULL;
58 static bitmap seen_in_insn = NULL;
61 /*----------------------------------------------------------------------------
62 Public functions access functions for the dataflow problems.
63 ----------------------------------------------------------------------------*/
64 /* Get the live at out set for BB no matter what problem happens to be
65 defined. This function is used by the register allocators who
66 choose different dataflow problems depending on the optimization
67 level. */
69 bitmap
70 df_get_live_out (basic_block bb)
72 gcc_assert (df_lr);
74 if (df_live)
75 return DF_LIVE_OUT (bb);
76 else
77 return DF_LR_OUT (bb);
80 /* Get the live at in set for BB no matter what problem happens to be
81 defined. This function is used by the register allocators who
82 choose different dataflow problems depending on the optimization
83 level. */
85 bitmap
86 df_get_live_in (basic_block bb)
88 gcc_assert (df_lr);
90 if (df_live)
91 return DF_LIVE_IN (bb);
92 else
93 return DF_LR_IN (bb);
96 /*----------------------------------------------------------------------------
97 Utility functions.
98 ----------------------------------------------------------------------------*/
100 /* Generic versions to get the void* version of the block info. Only
101 used inside the problem instance vectors. */
103 /* Grow the bb_info array. */
105 void
106 df_grow_bb_info (struct dataflow *dflow)
108 unsigned int new_size = last_basic_block + 1;
109 if (dflow->block_info_size < new_size)
111 new_size += new_size / 4;
112 dflow->block_info = xrealloc (dflow->block_info,
113 new_size *sizeof (void*));
114 memset (dflow->block_info + dflow->block_info_size, 0,
115 (new_size - dflow->block_info_size) *sizeof (void *));
116 dflow->block_info_size = new_size;
120 /* Dump a def-use or use-def chain for REF to FILE. */
122 void
123 df_chain_dump (struct df_link *link, FILE *file)
125 fprintf (file, "{ ");
126 for (; link; link = link->next)
128 fprintf (file, "%c%d(bb %d insn %d) ",
129 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
130 DF_REF_ID (link->ref),
131 DF_REF_BBNO (link->ref),
132 DF_REF_INSN (link->ref) ? DF_REF_INSN_UID (link->ref) : -1);
134 fprintf (file, "}");
138 /* Print some basic block info as part of df_dump. */
140 void
141 df_print_bb_index (basic_block bb, FILE *file)
143 edge e;
144 edge_iterator ei;
146 fprintf (file, "\n( ");
147 FOR_EACH_EDGE (e, ei, bb->preds)
149 basic_block pred = e->src;
150 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
152 fprintf (file, ")->[%d]->( ", bb->index);
153 FOR_EACH_EDGE (e, ei, bb->succs)
155 basic_block succ = e->dest;
156 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
158 fprintf (file, ")\n");
163 /* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
164 up correctly. */
166 static void
167 df_set_seen (void)
169 seen_in_block = BITMAP_ALLOC (&df_bitmap_obstack);
170 seen_in_insn = BITMAP_ALLOC (&df_bitmap_obstack);
174 static void
175 df_unset_seen (void)
177 BITMAP_FREE (seen_in_block);
178 BITMAP_FREE (seen_in_insn);
183 /*----------------------------------------------------------------------------
184 REACHING DEFINITIONS
186 Find the locations in the function where each definition site for a
187 pseudo reaches. In and out bitvectors are built for each basic
188 block. The id field in the ref is used to index into these sets.
189 See df.h for details.
190 ----------------------------------------------------------------------------*/
192 /* This problem plays a large number of games for the sake of
193 efficiency.
195 1) The order of the bits in the bitvectors. After the scanning
196 phase, all of the defs are sorted. All of the defs for the reg 0
197 are first, followed by all defs for reg 1 and so on.
199 2) There are two kill sets, one if the number of defs is less or
200 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
201 greater.
203 <= : Data is built directly in the kill set.
205 > : One level of indirection is used to keep from generating long
206 strings of 1 bits in the kill sets. Bitvectors that are indexed
207 by the regnum are used to represent that there is a killing def
208 for the register. The confluence and transfer functions use
209 these along with the bitmap_clear_range call to remove ranges of
210 bits without actually generating a knockout vector.
212 The kill and sparse_kill and the dense_invalidated_by_call and
213 sparse_invalidated_by_call both play this game. */
215 /* Private data used to compute the solution for this problem. These
216 data structures are not accessible outside of this module. */
217 struct df_rd_problem_data
219 /* The set of defs to regs invalidated by call. */
220 bitmap sparse_invalidated_by_call;
221 /* The set of defs to regs invalidate by call for rd. */
222 bitmap dense_invalidated_by_call;
223 /* An obstack for the bitmaps we need for this problem. */
224 bitmap_obstack rd_bitmaps;
227 /* Set basic block info. */
229 static void
230 df_rd_set_bb_info (unsigned int index,
231 struct df_rd_bb_info *bb_info)
233 gcc_assert (df_rd);
234 gcc_assert (index < df_rd->block_info_size);
235 df_rd->block_info[index] = bb_info;
239 /* Free basic block info. */
241 static void
242 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
243 void *vbb_info)
245 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
246 if (bb_info)
248 BITMAP_FREE (bb_info->kill);
249 BITMAP_FREE (bb_info->sparse_kill);
250 BITMAP_FREE (bb_info->gen);
251 BITMAP_FREE (bb_info->in);
252 BITMAP_FREE (bb_info->out);
253 pool_free (df_rd->block_pool, bb_info);
258 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
259 not touched unless the block is new. */
261 static void
262 df_rd_alloc (bitmap all_blocks)
264 unsigned int bb_index;
265 bitmap_iterator bi;
266 struct df_rd_problem_data *problem_data;
268 if (!df_rd->block_pool)
269 df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
270 sizeof (struct df_rd_bb_info), 50);
272 if (df_rd->problem_data)
274 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
275 bitmap_clear (problem_data->sparse_invalidated_by_call);
276 bitmap_clear (problem_data->dense_invalidated_by_call);
278 else
280 problem_data = XNEW (struct df_rd_problem_data);
281 df_rd->problem_data = problem_data;
283 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
284 problem_data->sparse_invalidated_by_call
285 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
286 problem_data->dense_invalidated_by_call
287 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
290 df_grow_bb_info (df_rd);
292 /* Because of the clustering of all use sites for the same pseudo,
293 we have to process all of the blocks before doing the
294 analysis. */
296 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
298 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
299 if (bb_info)
301 bitmap_clear (bb_info->kill);
302 bitmap_clear (bb_info->sparse_kill);
303 bitmap_clear (bb_info->gen);
305 else
307 bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
308 df_rd_set_bb_info (bb_index, bb_info);
309 bb_info->kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
310 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
311 bb_info->gen = BITMAP_ALLOC (&problem_data->rd_bitmaps);
312 bb_info->in = BITMAP_ALLOC (&problem_data->rd_bitmaps);
313 bb_info->out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
316 df_rd->optional_p = true;
320 /* Process a list of DEFs for df_rd_bb_local_compute. */
322 static void
323 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
324 struct df_ref **def_rec,
325 enum df_ref_flags top_flag)
327 while (*def_rec)
329 struct df_ref *def = *def_rec;
330 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
332 unsigned int regno = DF_REF_REGNO (def);
333 unsigned int begin = DF_DEFS_BEGIN (regno);
334 unsigned int n_defs = DF_DEFS_COUNT (regno);
336 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
337 || (regno >= FIRST_PSEUDO_REGISTER))
339 /* Only the last def(s) for a regno in the block has any
340 effect. */
341 if (!bitmap_bit_p (seen_in_block, regno))
343 /* The first def for regno in insn gets to knock out the
344 defs from other instructions. */
345 if ((!bitmap_bit_p (seen_in_insn, regno))
346 /* If the def is to only part of the reg, it does
347 not kill the other defs that reach here. */
348 && (!(DF_REF_FLAGS (def) &
349 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
351 if (n_defs > DF_SPARSE_THRESHOLD)
353 bitmap_set_bit (bb_info->sparse_kill, regno);
354 bitmap_clear_range(bb_info->gen, begin, n_defs);
356 else
358 bitmap_set_range (bb_info->kill, begin, n_defs);
359 bitmap_clear_range (bb_info->gen, begin, n_defs);
363 bitmap_set_bit (seen_in_insn, regno);
364 /* All defs for regno in the instruction may be put into
365 the gen set. */
366 if (!(DF_REF_FLAGS (def)
367 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
368 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
372 def_rec++;
376 /* Compute local reaching def info for basic block BB. */
378 static void
379 df_rd_bb_local_compute (unsigned int bb_index)
381 basic_block bb = BASIC_BLOCK (bb_index);
382 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
383 rtx insn;
385 bitmap_clear (seen_in_block);
386 bitmap_clear (seen_in_insn);
388 /* Artificials are only hard regs. */
389 if (!(df->changeable_flags & DF_NO_HARD_REGS))
390 df_rd_bb_local_compute_process_def (bb_info,
391 df_get_artificial_defs (bb_index),
394 FOR_BB_INSNS_REVERSE (bb, insn)
396 unsigned int uid = INSN_UID (insn);
398 if (!INSN_P (insn))
399 continue;
401 df_rd_bb_local_compute_process_def (bb_info,
402 DF_INSN_UID_DEFS (uid), 0);
404 /* This complex dance with the two bitmaps is required because
405 instructions can assign twice to the same pseudo. This
406 generally happens with calls that will have one def for the
407 result and another def for the clobber. If only one vector
408 is used and the clobber goes first, the result will be
409 lost. */
410 bitmap_ior_into (seen_in_block, seen_in_insn);
411 bitmap_clear (seen_in_insn);
414 /* Process the artificial defs at the top of the block last since we
415 are going backwards through the block and these are logically at
416 the start. */
417 if (!(df->changeable_flags & DF_NO_HARD_REGS))
418 df_rd_bb_local_compute_process_def (bb_info,
419 df_get_artificial_defs (bb_index),
420 DF_REF_AT_TOP);
424 /* Compute local reaching def info for each basic block within BLOCKS. */
426 static void
427 df_rd_local_compute (bitmap all_blocks)
429 unsigned int bb_index;
430 bitmap_iterator bi;
431 unsigned int regno;
432 struct df_rd_problem_data *problem_data
433 = (struct df_rd_problem_data *) df_rd->problem_data;
434 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
435 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
437 df_set_seen ();
439 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
441 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
443 df_rd_bb_local_compute (bb_index);
446 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
447 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
449 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
450 bitmap_set_bit (sparse_invalidated, regno);
451 else
452 bitmap_set_range (dense_invalidated,
453 DF_DEFS_BEGIN (regno),
454 DF_DEFS_COUNT (regno));
456 df_unset_seen ();
460 /* Initialize the solution bit vectors for problem. */
462 static void
463 df_rd_init_solution (bitmap all_blocks)
465 unsigned int bb_index;
466 bitmap_iterator bi;
468 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
470 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
472 bitmap_copy (bb_info->out, bb_info->gen);
473 bitmap_clear (bb_info->in);
477 /* In of target gets or of out of source. */
479 static void
480 df_rd_confluence_n (edge e)
482 bitmap op1 = df_rd_get_bb_info (e->dest->index)->in;
483 bitmap op2 = df_rd_get_bb_info (e->src->index)->out;
485 if (e->flags & EDGE_EH)
487 struct df_rd_problem_data *problem_data
488 = (struct df_rd_problem_data *) df_rd->problem_data;
489 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
490 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
491 bitmap_iterator bi;
492 unsigned int regno;
493 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
495 bitmap_copy (tmp, op2);
496 bitmap_and_compl_into (tmp, dense_invalidated);
498 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
500 bitmap_clear_range (tmp,
501 DF_DEFS_BEGIN (regno),
502 DF_DEFS_COUNT (regno));
504 bitmap_ior_into (op1, tmp);
505 BITMAP_FREE (tmp);
507 else
508 bitmap_ior_into (op1, op2);
512 /* Transfer function. */
514 static bool
515 df_rd_transfer_function (int bb_index)
517 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
518 unsigned int regno;
519 bitmap_iterator bi;
520 bitmap in = bb_info->in;
521 bitmap out = bb_info->out;
522 bitmap gen = bb_info->gen;
523 bitmap kill = bb_info->kill;
524 bitmap sparse_kill = bb_info->sparse_kill;
526 if (bitmap_empty_p (sparse_kill))
527 return bitmap_ior_and_compl (out, gen, in, kill);
528 else
530 struct df_rd_problem_data *problem_data;
531 bool changed = false;
532 bitmap tmp;
534 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
535 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
536 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
537 tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
539 bitmap_copy (tmp, in);
540 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
542 bitmap_clear_range (tmp,
543 DF_DEFS_BEGIN (regno),
544 DF_DEFS_COUNT (regno));
546 bitmap_and_compl_into (tmp, kill);
547 bitmap_ior_into (tmp, gen);
548 changed = !bitmap_equal_p (tmp, out);
549 if (changed)
551 BITMAP_FREE (out);
552 bb_info->out = tmp;
554 else
555 BITMAP_FREE (tmp);
556 return changed;
561 /* Free all storage associated with the problem. */
563 static void
564 df_rd_free (void)
566 unsigned int i;
567 struct df_rd_problem_data *problem_data
568 = (struct df_rd_problem_data *) df_rd->problem_data;
570 if (problem_data)
572 for (i = 0; i < df_rd->block_info_size; i++)
574 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (i);
575 if (bb_info)
577 BITMAP_FREE (bb_info->kill);
578 BITMAP_FREE (bb_info->sparse_kill);
579 BITMAP_FREE (bb_info->gen);
580 BITMAP_FREE (bb_info->in);
581 BITMAP_FREE (bb_info->out);
585 free_alloc_pool (df_rd->block_pool);
586 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
587 BITMAP_FREE (problem_data->dense_invalidated_by_call);
588 bitmap_obstack_release (&problem_data->rd_bitmaps);
590 df_rd->block_info_size = 0;
591 free (df_rd->block_info);
592 free (df_rd->problem_data);
594 free (df_rd);
598 /* Debugging info. */
600 static void
601 df_rd_start_dump (FILE *file)
603 struct df_rd_problem_data *problem_data
604 = (struct df_rd_problem_data *) df_rd->problem_data;
605 unsigned int m = DF_REG_SIZE(df);
606 unsigned int regno;
608 if (!df_rd->block_info)
609 return;
611 fprintf (file, ";; Reaching defs:\n\n");
613 fprintf (file, " sparse invalidated \t");
614 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
615 fprintf (file, " dense invalidated \t");
616 dump_bitmap (file, problem_data->dense_invalidated_by_call);
618 for (regno = 0; regno < m; regno++)
619 if (DF_DEFS_COUNT (regno))
620 fprintf (file, "%d[%d,%d] ", regno,
621 DF_DEFS_BEGIN (regno),
622 DF_DEFS_COUNT (regno));
623 fprintf (file, "\n");
628 /* Debugging info at top of bb. */
630 static void
631 df_rd_top_dump (basic_block bb, FILE *file)
633 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
634 if (!bb_info || !bb_info->in)
635 return;
637 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
638 dump_bitmap (file, bb_info->in);
639 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
640 dump_bitmap (file, bb_info->gen);
641 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
642 dump_bitmap (file, bb_info->kill);
646 /* Debugging info at top of bb. */
648 static void
649 df_rd_bottom_dump (basic_block bb, FILE *file)
651 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
652 if (!bb_info || !bb_info->out)
653 return;
655 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
656 dump_bitmap (file, bb_info->out);
659 /* All of the information associated with every instance of the problem. */
661 static struct df_problem problem_RD =
663 DF_RD, /* Problem id. */
664 DF_FORWARD, /* Direction. */
665 df_rd_alloc, /* Allocate the problem specific data. */
666 NULL, /* Reset global information. */
667 df_rd_free_bb_info, /* Free basic block info. */
668 df_rd_local_compute, /* Local compute function. */
669 df_rd_init_solution, /* Init the solution specific data. */
670 df_worklist_dataflow, /* Worklist solver. */
671 NULL, /* Confluence operator 0. */
672 df_rd_confluence_n, /* Confluence operator n. */
673 df_rd_transfer_function, /* Transfer function. */
674 NULL, /* Finalize function. */
675 df_rd_free, /* Free all of the problem information. */
676 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
677 df_rd_start_dump, /* Debugging. */
678 df_rd_top_dump, /* Debugging start block. */
679 df_rd_bottom_dump, /* Debugging end block. */
680 NULL, /* Incremental solution verify start. */
681 NULL, /* Incremental solution verify end. */
682 NULL, /* Dependent problem. */
683 TV_DF_RD, /* Timing variable. */
684 true /* Reset blocks on dropping out of blocks_to_analyze. */
689 /* Create a new DATAFLOW instance and add it to an existing instance
690 of DF. The returned structure is what is used to get at the
691 solution. */
693 void
694 df_rd_add_problem (void)
696 df_add_problem (&problem_RD);
701 /*----------------------------------------------------------------------------
702 LIVE REGISTERS
704 Find the locations in the function where any use of a pseudo can
705 reach in the backwards direction. In and out bitvectors are built
706 for each basic block. The regnum is used to index into these sets.
707 See df.h for details.
708 ----------------------------------------------------------------------------*/
710 /* Private data used to verify the solution for this problem. */
711 struct df_lr_problem_data
713 bitmap *in;
714 bitmap *out;
718 /* Set basic block info. */
720 static void
721 df_lr_set_bb_info (unsigned int index,
722 struct df_lr_bb_info *bb_info)
724 gcc_assert (df_lr);
725 gcc_assert (index < df_lr->block_info_size);
726 df_lr->block_info[index] = bb_info;
730 /* Free basic block info. */
732 static void
733 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
734 void *vbb_info)
736 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
737 if (bb_info)
739 BITMAP_FREE (bb_info->use);
740 BITMAP_FREE (bb_info->def);
741 BITMAP_FREE (bb_info->in);
742 BITMAP_FREE (bb_info->out);
743 pool_free (df_lr->block_pool, bb_info);
748 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
749 not touched unless the block is new. */
751 static void
752 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
754 unsigned int bb_index;
755 bitmap_iterator bi;
757 if (!df_lr->block_pool)
758 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
759 sizeof (struct df_lr_bb_info), 50);
761 df_grow_bb_info (df_lr);
763 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
765 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
766 if (bb_info)
768 bitmap_clear (bb_info->def);
769 bitmap_clear (bb_info->use);
771 else
773 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
774 df_lr_set_bb_info (bb_index, bb_info);
775 bb_info->use = BITMAP_ALLOC (NULL);
776 bb_info->def = BITMAP_ALLOC (NULL);
777 bb_info->in = BITMAP_ALLOC (NULL);
778 bb_info->out = BITMAP_ALLOC (NULL);
782 df_lr->optional_p = false;
786 /* Reset the global solution for recalculation. */
788 static void
789 df_lr_reset (bitmap all_blocks)
791 unsigned int bb_index;
792 bitmap_iterator bi;
794 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
796 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
797 gcc_assert (bb_info);
798 bitmap_clear (bb_info->in);
799 bitmap_clear (bb_info->out);
804 /* Compute local live register info for basic block BB. */
806 static void
807 df_lr_bb_local_compute (unsigned int bb_index)
809 basic_block bb = BASIC_BLOCK (bb_index);
810 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
811 rtx insn;
812 struct df_ref **def_rec;
813 struct df_ref **use_rec;
815 /* Process the registers set in an exception handler. */
816 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
818 struct df_ref *def = *def_rec;
819 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
821 unsigned int dregno = DF_REF_REGNO (def);
822 bitmap_set_bit (bb_info->def, dregno);
823 bitmap_clear_bit (bb_info->use, dregno);
827 /* Process the hardware registers that are always live. */
828 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
830 struct df_ref *use = *use_rec;
831 /* Add use to set of uses in this BB. */
832 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
833 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
836 FOR_BB_INSNS_REVERSE (bb, insn)
838 unsigned int uid = INSN_UID (insn);
840 if (!INSN_P (insn))
841 continue;
843 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
845 struct df_ref *def = *def_rec;
846 /* If the def is to only part of the reg, it does
847 not kill the other defs that reach here. */
848 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
850 unsigned int dregno = DF_REF_REGNO (def);
851 bitmap_set_bit (bb_info->def, dregno);
852 bitmap_clear_bit (bb_info->use, dregno);
856 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
858 struct df_ref *use = *use_rec;
859 /* Add use to set of uses in this BB. */
860 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
864 /* Process the registers set in an exception handler or the hard
865 frame pointer if this block is the target of a non local
866 goto. */
867 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
869 struct df_ref *def = *def_rec;
870 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
872 unsigned int dregno = DF_REF_REGNO (def);
873 bitmap_set_bit (bb_info->def, dregno);
874 bitmap_clear_bit (bb_info->use, dregno);
878 #ifdef EH_USES
879 /* Process the uses that are live into an exception handler. */
880 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
882 struct df_ref *use = *use_rec;
883 /* Add use to set of uses in this BB. */
884 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
885 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
887 #endif
889 /* If the df_live problem is not defined, such as at -O0 and -O1, we
890 still need to keep the luids up to date. This is normally done
891 in the df_live problem since this problem has a forwards
892 scan. */
893 if (!df_live)
894 df_recompute_luids (bb);
898 /* Compute local live register info for each basic block within BLOCKS. */
900 static void
901 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
903 unsigned int bb_index;
904 bitmap_iterator bi;
906 bitmap_clear (df->hardware_regs_used);
908 /* The all-important stack pointer must always be live. */
909 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
911 /* Before reload, there are a few registers that must be forced
912 live everywhere -- which might not already be the case for
913 blocks within infinite loops. */
914 if (!reload_completed)
916 /* Any reference to any pseudo before reload is a potential
917 reference of the frame pointer. */
918 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
920 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
921 /* Pseudos with argument area equivalences may require
922 reloading via the argument pointer. */
923 if (fixed_regs[ARG_POINTER_REGNUM])
924 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
925 #endif
927 /* Any constant, or pseudo with constant equivalences, may
928 require reloading from memory using the pic register. */
929 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
930 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
931 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
934 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
936 if (bb_index == EXIT_BLOCK)
938 /* The exit block is special for this problem and its bits are
939 computed from thin air. */
940 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
941 bitmap_copy (bb_info->use, df->exit_block_uses);
943 else
944 df_lr_bb_local_compute (bb_index);
947 bitmap_clear (df_lr->out_of_date_transfer_functions);
951 /* Initialize the solution vectors. */
953 static void
954 df_lr_init (bitmap all_blocks)
956 unsigned int bb_index;
957 bitmap_iterator bi;
959 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
961 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
962 bitmap_copy (bb_info->in, bb_info->use);
963 bitmap_clear (bb_info->out);
968 /* Confluence function that processes infinite loops. This might be a
969 noreturn function that throws. And even if it isn't, getting the
970 unwind info right helps debugging. */
971 static void
972 df_lr_confluence_0 (basic_block bb)
974 bitmap op1 = df_lr_get_bb_info (bb->index)->out;
975 if (bb != EXIT_BLOCK_PTR)
976 bitmap_copy (op1, df->hardware_regs_used);
980 /* Confluence function that ignores fake edges. */
982 static void
983 df_lr_confluence_n (edge e)
985 bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
986 bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
988 /* Call-clobbered registers die across exception and call edges. */
989 /* ??? Abnormal call edges ignored for the moment, as this gets
990 confused by sibling call edges, which crashes reg-stack. */
991 if (e->flags & EDGE_EH)
992 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
993 else
994 bitmap_ior_into (op1, op2);
996 bitmap_ior_into (op1, df->hardware_regs_used);
1000 /* Transfer function. */
1002 static bool
1003 df_lr_transfer_function (int bb_index)
1005 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1006 bitmap in = bb_info->in;
1007 bitmap out = bb_info->out;
1008 bitmap use = bb_info->use;
1009 bitmap def = bb_info->def;
1011 return bitmap_ior_and_compl (in, use, out, def);
1015 /* Run the fast dce as a side effect of building LR. */
1017 static void
1018 df_lr_local_finalize (bitmap all_blocks ATTRIBUTE_UNUSED)
1020 if (df->changeable_flags & DF_LR_RUN_DCE)
1022 run_fast_df_dce ();
1023 if (df_lr->problem_data && df_lr->solutions_dirty)
1025 /* If we are here, then it is because we are both verifying
1026 the solution and the dce changed the function. In that case
1027 the verification info built will be wrong. So we leave the
1028 dirty flag true so that the verifier will skip the checking
1029 part and just clean up.*/
1030 df_lr->solutions_dirty = true;
1032 else
1033 df_lr->solutions_dirty = false;
1035 else
1036 df_lr->solutions_dirty = false;
1040 /* Free all storage associated with the problem. */
1042 static void
1043 df_lr_free (void)
1045 if (df_lr->block_info)
1047 unsigned int i;
1048 for (i = 0; i < df_lr->block_info_size; i++)
1050 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
1051 if (bb_info)
1053 BITMAP_FREE (bb_info->use);
1054 BITMAP_FREE (bb_info->def);
1055 BITMAP_FREE (bb_info->in);
1056 BITMAP_FREE (bb_info->out);
1059 free_alloc_pool (df_lr->block_pool);
1061 df_lr->block_info_size = 0;
1062 free (df_lr->block_info);
1065 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1066 free (df_lr);
1070 /* Debugging info at top of bb. */
1072 static void
1073 df_lr_top_dump (basic_block bb, FILE *file)
1075 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1076 struct df_lr_problem_data *problem_data;
1077 if (!bb_info || !bb_info->in)
1078 return;
1080 fprintf (file, ";; lr in \t");
1081 df_print_regset (file, bb_info->in);
1082 if (df_lr->problem_data)
1084 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1085 fprintf (file, ";; old in \t");
1086 df_print_regset (file, problem_data->in[bb->index]);
1088 fprintf (file, ";; lr use \t");
1089 df_print_regset (file, bb_info->use);
1090 fprintf (file, ";; lr def \t");
1091 df_print_regset (file, bb_info->def);
1095 /* Debugging info at bottom of bb. */
1097 static void
1098 df_lr_bottom_dump (basic_block bb, FILE *file)
1100 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1101 struct df_lr_problem_data *problem_data;
1102 if (!bb_info || !bb_info->out)
1103 return;
1105 fprintf (file, ";; lr out \t");
1106 df_print_regset (file, bb_info->out);
1107 if (df_lr->problem_data)
1109 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1110 fprintf (file, ";; old out \t");
1111 df_print_regset (file, problem_data->out[bb->index]);
1116 /* Build the datastructure to verify that the solution to the dataflow
1117 equations is not dirty. */
1119 static void
1120 df_lr_verify_solution_start (void)
1122 basic_block bb;
1123 struct df_lr_problem_data *problem_data;
1124 if (df_lr->solutions_dirty)
1126 df_lr->problem_data = NULL;
1127 return;
1130 /* Set it true so that the solution is recomputed. */
1131 df_lr->solutions_dirty = true;
1133 problem_data = XNEW (struct df_lr_problem_data);
1134 df_lr->problem_data = problem_data;
1135 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1136 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1138 FOR_ALL_BB (bb)
1140 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1141 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1142 bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
1143 bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
1148 /* Compare the saved datastructure and the new solution to the dataflow
1149 equations. */
1151 static void
1152 df_lr_verify_solution_end (void)
1154 struct df_lr_problem_data *problem_data;
1155 basic_block bb;
1157 if (df_lr->problem_data == NULL)
1158 return;
1160 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1162 if (df_lr->solutions_dirty)
1163 /* Do not check if the solution is still dirty. See the comment
1164 in df_lr_local_finalize for details. */
1165 df_lr->solutions_dirty = false;
1166 else
1167 FOR_ALL_BB (bb)
1169 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
1170 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
1172 /*df_dump (stderr);*/
1173 gcc_unreachable ();
1177 /* Cannot delete them immediately because you may want to dump them
1178 if the comparison fails. */
1179 FOR_ALL_BB (bb)
1181 BITMAP_FREE (problem_data->in[bb->index]);
1182 BITMAP_FREE (problem_data->out[bb->index]);
1185 free (problem_data->in);
1186 free (problem_data->out);
1187 free (problem_data);
1188 df_lr->problem_data = NULL;
1192 /* All of the information associated with every instance of the problem. */
1194 static struct df_problem problem_LR =
1196 DF_LR, /* Problem id. */
1197 DF_BACKWARD, /* Direction. */
1198 df_lr_alloc, /* Allocate the problem specific data. */
1199 df_lr_reset, /* Reset global information. */
1200 df_lr_free_bb_info, /* Free basic block info. */
1201 df_lr_local_compute, /* Local compute function. */
1202 df_lr_init, /* Init the solution specific data. */
1203 df_worklist_dataflow, /* Worklist solver. */
1204 df_lr_confluence_0, /* Confluence operator 0. */
1205 df_lr_confluence_n, /* Confluence operator n. */
1206 df_lr_transfer_function, /* Transfer function. */
1207 df_lr_local_finalize, /* Finalize function. */
1208 df_lr_free, /* Free all of the problem information. */
1209 NULL, /* Remove this problem from the stack of dataflow problems. */
1210 NULL, /* Debugging. */
1211 df_lr_top_dump, /* Debugging start block. */
1212 df_lr_bottom_dump, /* Debugging end block. */
1213 df_lr_verify_solution_start,/* Incremental solution verify start. */
1214 df_lr_verify_solution_end, /* Incremental solution verify end. */
1215 NULL, /* Dependent problem. */
1216 TV_DF_LR, /* Timing variable. */
1217 false /* Reset blocks on dropping out of blocks_to_analyze. */
1221 /* Create a new DATAFLOW instance and add it to an existing instance
1222 of DF. The returned structure is what is used to get at the
1223 solution. */
1225 void
1226 df_lr_add_problem (void)
1228 df_add_problem (&problem_LR);
1229 /* These will be initialized when df_scan_blocks processes each
1230 block. */
1231 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1235 /* Verify that all of the lr related info is consistent and
1236 correct. */
1238 void
1239 df_lr_verify_transfer_functions (void)
1241 basic_block bb;
1242 bitmap saved_def;
1243 bitmap saved_use;
1244 bitmap saved_adef;
1245 bitmap saved_ause;
1246 bitmap all_blocks;
1248 if (!df)
1249 return;
1251 saved_def = BITMAP_ALLOC (NULL);
1252 saved_use = BITMAP_ALLOC (NULL);
1253 saved_adef = BITMAP_ALLOC (NULL);
1254 saved_ause = BITMAP_ALLOC (NULL);
1255 all_blocks = BITMAP_ALLOC (NULL);
1257 FOR_ALL_BB (bb)
1259 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1260 bitmap_set_bit (all_blocks, bb->index);
1262 if (bb_info)
1264 /* Make a copy of the transfer functions and then compute
1265 new ones to see if the transfer functions have
1266 changed. */
1267 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1268 bb->index))
1270 bitmap_copy (saved_def, bb_info->def);
1271 bitmap_copy (saved_use, bb_info->use);
1272 bitmap_clear (bb_info->def);
1273 bitmap_clear (bb_info->use);
1275 df_lr_bb_local_compute (bb->index);
1276 gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
1277 gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
1280 else
1282 /* If we do not have basic block info, the block must be in
1283 the list of dirty blocks or else some one has added a
1284 block behind our backs. */
1285 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1286 bb->index));
1288 /* Make sure no one created a block without following
1289 procedures. */
1290 gcc_assert (df_scan_get_bb_info (bb->index));
1293 /* Make sure there are no dirty bits in blocks that have been deleted. */
1294 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1295 all_blocks));
1297 BITMAP_FREE (saved_def);
1298 BITMAP_FREE (saved_use);
1299 BITMAP_FREE (saved_adef);
1300 BITMAP_FREE (saved_ause);
1301 BITMAP_FREE (all_blocks);
1306 /*----------------------------------------------------------------------------
1307 LIVE AND MUST-INITIALIZED REGISTERS.
1309 This problem first computes the IN and OUT bitvectors for the
1310 must-initialized registers problems, which is a forward problem.
1311 It gives the set of registers for which we MUST have an available
1312 definition on any path from the entry block to the entry/exit of
1313 a basic block. Sets generate a definition, while clobbers kill
1314 a definition.
1316 In and out bitvectors are built for each basic block and are indexed by
1317 regnum (see df.h for details). In and out bitvectors in struct
1318 df_live_bb_info actually refers to the must-initialized problem;
1320 Then, the in and out sets for the LIVE problem itself are computed.
1321 These are the logical AND of the IN and OUT sets from the LR problem
1322 and the must-initialized problem.
1323 ----------------------------------------------------------------------------*/
1325 /* Private data used to verify the solution for this problem. */
1326 struct df_live_problem_data
1328 bitmap *in;
1329 bitmap *out;
1333 /* Set basic block info. */
1335 static void
1336 df_live_set_bb_info (unsigned int index,
1337 struct df_live_bb_info *bb_info)
1339 gcc_assert (df_live);
1340 gcc_assert (index < df_live->block_info_size);
1341 df_live->block_info[index] = bb_info;
1345 /* Free basic block info. */
1347 static void
1348 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1349 void *vbb_info)
1351 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1352 if (bb_info)
1354 BITMAP_FREE (bb_info->gen);
1355 BITMAP_FREE (bb_info->kill);
1356 BITMAP_FREE (bb_info->in);
1357 BITMAP_FREE (bb_info->out);
1358 pool_free (df_live->block_pool, bb_info);
1363 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1364 not touched unless the block is new. */
1366 static void
1367 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1369 unsigned int bb_index;
1370 bitmap_iterator bi;
1372 if (!df_live->block_pool)
1373 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1374 sizeof (struct df_live_bb_info), 100);
1376 df_grow_bb_info (df_live);
1378 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1380 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1381 if (bb_info)
1383 bitmap_clear (bb_info->kill);
1384 bitmap_clear (bb_info->gen);
1386 else
1388 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1389 df_live_set_bb_info (bb_index, bb_info);
1390 bb_info->kill = BITMAP_ALLOC (NULL);
1391 bb_info->gen = BITMAP_ALLOC (NULL);
1392 bb_info->in = BITMAP_ALLOC (NULL);
1393 bb_info->out = BITMAP_ALLOC (NULL);
1396 df_live->optional_p = (optimize <= 1);
1400 /* Reset the global solution for recalculation. */
1402 static void
1403 df_live_reset (bitmap all_blocks)
1405 unsigned int bb_index;
1406 bitmap_iterator bi;
1408 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1410 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1411 gcc_assert (bb_info);
1412 bitmap_clear (bb_info->in);
1413 bitmap_clear (bb_info->out);
1418 /* Compute local uninitialized register info for basic block BB. */
1420 static void
1421 df_live_bb_local_compute (unsigned int bb_index)
1423 basic_block bb = BASIC_BLOCK (bb_index);
1424 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1425 rtx insn;
1426 struct df_ref **def_rec;
1427 int luid = 0;
1429 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1431 struct df_ref *def = *def_rec;
1432 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
1433 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1436 FOR_BB_INSNS (bb, insn)
1438 unsigned int uid = INSN_UID (insn);
1439 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1441 /* Inserting labels does not always trigger the incremental
1442 rescanning. */
1443 if (!insn_info)
1445 gcc_assert (!INSN_P (insn));
1446 df_insn_create_insn_record (insn);
1449 DF_INSN_LUID (insn) = luid;
1450 if (!INSN_P (insn))
1451 continue;
1453 luid++;
1454 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1456 struct df_ref *def = *def_rec;
1457 unsigned int regno = DF_REF_REGNO (def);
1459 if (DF_REF_FLAGS_IS_SET (def,
1460 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1461 /* All partial or conditional def
1462 seen are included in the gen set. */
1463 bitmap_set_bit (bb_info->gen, regno);
1464 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1465 /* Only must clobbers for the entire reg destroy the
1466 value. */
1467 bitmap_set_bit (bb_info->kill, regno);
1468 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1469 bitmap_set_bit (bb_info->gen, regno);
1473 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1475 struct df_ref *def = *def_rec;
1476 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
1477 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1482 /* Compute local uninitialized register info. */
1484 static void
1485 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1487 unsigned int bb_index;
1488 bitmap_iterator bi;
1490 df_grow_insn_info ();
1492 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1493 0, bb_index, bi)
1495 df_live_bb_local_compute (bb_index);
1498 bitmap_clear (df_live->out_of_date_transfer_functions);
1502 /* Initialize the solution vectors. */
1504 static void
1505 df_live_init (bitmap all_blocks)
1507 unsigned int bb_index;
1508 bitmap_iterator bi;
1510 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1512 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1514 bitmap_copy (bb_info->out, bb_info->gen);
1515 bitmap_clear (bb_info->in);
1519 /* Forward confluence function that ignores fake edges. */
1521 static void
1522 df_live_confluence_n (edge e)
1524 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
1525 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
1527 if (e->flags & EDGE_FAKE)
1528 return;
1530 bitmap_ior_into (op1, op2);
1534 /* Transfer function for the forwards must-initialized problem. */
1536 static bool
1537 df_live_transfer_function (int bb_index)
1539 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1540 bitmap in = bb_info->in;
1541 bitmap out = bb_info->out;
1542 bitmap gen = bb_info->gen;
1543 bitmap kill = bb_info->kill;
1545 return bitmap_ior_and_compl (out, gen, in, kill);
1549 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1551 static void
1552 df_live_local_finalize (bitmap all_blocks)
1555 if (df_live->solutions_dirty)
1557 bitmap_iterator bi;
1558 unsigned int bb_index;
1560 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1562 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1563 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1565 /* No register may reach a location where it is not used. Thus
1566 we trim the rr result to the places where it is used. */
1567 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
1568 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
1571 df_live->solutions_dirty = false;
1576 /* Free all storage associated with the problem. */
1578 static void
1579 df_live_free (void)
1581 if (df_live->block_info)
1583 unsigned int i;
1585 for (i = 0; i < df_live->block_info_size; i++)
1587 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
1588 if (bb_info)
1590 BITMAP_FREE (bb_info->gen);
1591 BITMAP_FREE (bb_info->kill);
1592 BITMAP_FREE (bb_info->in);
1593 BITMAP_FREE (bb_info->out);
1597 free_alloc_pool (df_live->block_pool);
1598 df_live->block_info_size = 0;
1599 free (df_live->block_info);
1601 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1602 free (df_live);
1606 /* Debugging info at top of bb. */
1608 static void
1609 df_live_top_dump (basic_block bb, FILE *file)
1611 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1612 struct df_live_problem_data *problem_data;
1614 if (!bb_info || !bb_info->in)
1615 return;
1617 fprintf (file, ";; live in \t");
1618 df_print_regset (file, bb_info->in);
1619 if (df_live->problem_data)
1621 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1622 fprintf (file, ";; old in \t");
1623 df_print_regset (file, problem_data->in[bb->index]);
1625 fprintf (file, ";; live gen \t");
1626 df_print_regset (file, bb_info->gen);
1627 fprintf (file, ";; live kill\t");
1628 df_print_regset (file, bb_info->kill);
1632 /* Debugging info at bottom of bb. */
1634 static void
1635 df_live_bottom_dump (basic_block bb, FILE *file)
1637 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1638 struct df_live_problem_data *problem_data;
1640 if (!bb_info || !bb_info->out)
1641 return;
1643 fprintf (file, ";; live out \t");
1644 df_print_regset (file, bb_info->out);
1645 if (df_live->problem_data)
1647 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1648 fprintf (file, ";; old out \t");
1649 df_print_regset (file, problem_data->out[bb->index]);
1654 /* Build the datastructure to verify that the solution to the dataflow
1655 equations is not dirty. */
1657 static void
1658 df_live_verify_solution_start (void)
1660 basic_block bb;
1661 struct df_live_problem_data *problem_data;
1662 if (df_live->solutions_dirty)
1664 df_live->problem_data = NULL;
1665 return;
1668 /* Set it true so that the solution is recomputed. */
1669 df_live->solutions_dirty = true;
1671 problem_data = XNEW (struct df_live_problem_data);
1672 df_live->problem_data = problem_data;
1673 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1674 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1676 FOR_ALL_BB (bb)
1678 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1679 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1680 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
1681 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
1686 /* Compare the saved datastructure and the new solution to the dataflow
1687 equations. */
1689 static void
1690 df_live_verify_solution_end (void)
1692 struct df_live_problem_data *problem_data;
1693 basic_block bb;
1695 if (df_live->problem_data == NULL)
1696 return;
1698 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1700 FOR_ALL_BB (bb)
1702 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
1703 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1705 /*df_dump (stderr);*/
1706 gcc_unreachable ();
1710 /* Cannot delete them immediately because you may want to dump them
1711 if the comparison fails. */
1712 FOR_ALL_BB (bb)
1714 BITMAP_FREE (problem_data->in[bb->index]);
1715 BITMAP_FREE (problem_data->out[bb->index]);
1718 free (problem_data->in);
1719 free (problem_data->out);
1720 free (problem_data);
1721 df_live->problem_data = NULL;
1725 /* All of the information associated with every instance of the problem. */
1727 static struct df_problem problem_LIVE =
1729 DF_LIVE, /* Problem id. */
1730 DF_FORWARD, /* Direction. */
1731 df_live_alloc, /* Allocate the problem specific data. */
1732 df_live_reset, /* Reset global information. */
1733 df_live_free_bb_info, /* Free basic block info. */
1734 df_live_local_compute, /* Local compute function. */
1735 df_live_init, /* Init the solution specific data. */
1736 df_worklist_dataflow, /* Worklist solver. */
1737 NULL, /* Confluence operator 0. */
1738 df_live_confluence_n, /* Confluence operator n. */
1739 df_live_transfer_function, /* Transfer function. */
1740 df_live_local_finalize, /* Finalize function. */
1741 df_live_free, /* Free all of the problem information. */
1742 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1743 NULL, /* Debugging. */
1744 df_live_top_dump, /* Debugging start block. */
1745 df_live_bottom_dump, /* Debugging end block. */
1746 df_live_verify_solution_start,/* Incremental solution verify start. */
1747 df_live_verify_solution_end, /* Incremental solution verify end. */
1748 &problem_LR, /* Dependent problem. */
1749 TV_DF_LIVE, /* Timing variable. */
1750 false /* Reset blocks on dropping out of blocks_to_analyze. */
1754 /* Create a new DATAFLOW instance and add it to an existing instance
1755 of DF. The returned structure is what is used to get at the
1756 solution. */
1758 void
1759 df_live_add_problem (void)
1761 df_add_problem (&problem_LIVE);
1762 /* These will be initialized when df_scan_blocks processes each
1763 block. */
1764 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1768 /* Set all of the blocks as dirty. This needs to be done if this
1769 problem is added after all of the insns have been scanned. */
1771 void
1772 df_live_set_all_dirty (void)
1774 basic_block bb;
1775 FOR_ALL_BB (bb)
1776 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1777 bb->index);
1781 /* Verify that all of the lr related info is consistent and
1782 correct. */
1784 void
1785 df_live_verify_transfer_functions (void)
1787 basic_block bb;
1788 bitmap saved_gen;
1789 bitmap saved_kill;
1790 bitmap all_blocks;
1792 if (!df)
1793 return;
1795 saved_gen = BITMAP_ALLOC (NULL);
1796 saved_kill = BITMAP_ALLOC (NULL);
1797 all_blocks = BITMAP_ALLOC (NULL);
1799 df_grow_insn_info ();
1801 FOR_ALL_BB (bb)
1803 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1804 bitmap_set_bit (all_blocks, bb->index);
1806 if (bb_info)
1808 /* Make a copy of the transfer functions and then compute
1809 new ones to see if the transfer functions have
1810 changed. */
1811 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1812 bb->index))
1814 bitmap_copy (saved_gen, bb_info->gen);
1815 bitmap_copy (saved_kill, bb_info->kill);
1816 bitmap_clear (bb_info->gen);
1817 bitmap_clear (bb_info->kill);
1819 df_live_bb_local_compute (bb->index);
1820 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
1821 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
1824 else
1826 /* If we do not have basic block info, the block must be in
1827 the list of dirty blocks or else some one has added a
1828 block behind our backs. */
1829 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1830 bb->index));
1832 /* Make sure no one created a block without following
1833 procedures. */
1834 gcc_assert (df_scan_get_bb_info (bb->index));
1837 /* Make sure there are no dirty bits in blocks that have been deleted. */
1838 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1839 all_blocks));
1840 BITMAP_FREE (saved_gen);
1841 BITMAP_FREE (saved_kill);
1842 BITMAP_FREE (all_blocks);
1845 /*----------------------------------------------------------------------------
1846 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1848 Link either the defs to the uses and / or the uses to the defs.
1850 These problems are set up like the other dataflow problems so that
1851 they nicely fit into the framework. They are much simpler and only
1852 involve a single traversal of instructions and an examination of
1853 the reaching defs information (the dependent problem).
1854 ----------------------------------------------------------------------------*/
1856 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1858 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1860 struct df_link *
1861 df_chain_create (struct df_ref *src, struct df_ref *dst)
1863 struct df_link *head = DF_REF_CHAIN (src);
1864 struct df_link *link = pool_alloc (df_chain->block_pool);;
1866 DF_REF_CHAIN (src) = link;
1867 link->next = head;
1868 link->ref = dst;
1869 return link;
1873 /* Delete any du or ud chains that start at REF and point to
1874 TARGET. */
1875 static void
1876 df_chain_unlink_1 (struct df_ref *ref, struct df_ref *target)
1878 struct df_link *chain = DF_REF_CHAIN (ref);
1879 struct df_link *prev = NULL;
1881 while (chain)
1883 if (chain->ref == target)
1885 if (prev)
1886 prev->next = chain->next;
1887 else
1888 DF_REF_CHAIN (ref) = chain->next;
1889 pool_free (df_chain->block_pool, chain);
1890 return;
1892 prev = chain;
1893 chain = chain->next;
1898 /* Delete a du or ud chain that leave or point to REF. */
1900 void
1901 df_chain_unlink (struct df_ref *ref)
1903 struct df_link *chain = DF_REF_CHAIN (ref);
1904 while (chain)
1906 struct df_link *next = chain->next;
1907 /* Delete the other side if it exists. */
1908 df_chain_unlink_1 (chain->ref, ref);
1909 pool_free (df_chain->block_pool, chain);
1910 chain = next;
1912 DF_REF_CHAIN (ref) = NULL;
1916 /* Copy the du or ud chain starting at FROM_REF and attach it to
1917 TO_REF. */
1919 void
1920 df_chain_copy (struct df_ref *to_ref,
1921 struct df_link *from_ref)
1923 while (from_ref)
1925 df_chain_create (to_ref, from_ref->ref);
1926 from_ref = from_ref->next;
1931 /* Remove this problem from the stack of dataflow problems. */
1933 static void
1934 df_chain_remove_problem (void)
1936 bitmap_iterator bi;
1937 unsigned int bb_index;
1939 /* Wholesale destruction of the old chains. */
1940 if (df_chain->block_pool)
1941 free_alloc_pool (df_chain->block_pool);
1943 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1945 rtx insn;
1946 struct df_ref **def_rec;
1947 struct df_ref **use_rec;
1948 basic_block bb = BASIC_BLOCK (bb_index);
1950 if (df_chain_problem_p (DF_DU_CHAIN))
1951 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1952 DF_REF_CHAIN (*def_rec) = NULL;
1953 if (df_chain_problem_p (DF_UD_CHAIN))
1954 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1955 DF_REF_CHAIN (*use_rec) = NULL;
1957 FOR_BB_INSNS (bb, insn)
1959 unsigned int uid = INSN_UID (insn);
1961 if (INSN_P (insn))
1963 if (df_chain_problem_p (DF_DU_CHAIN))
1964 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1965 DF_REF_CHAIN (*def_rec) = NULL;
1966 if (df_chain_problem_p (DF_UD_CHAIN))
1968 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1969 DF_REF_CHAIN (*use_rec) = NULL;
1970 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
1971 DF_REF_CHAIN (*use_rec) = NULL;
1977 bitmap_clear (df_chain->out_of_date_transfer_functions);
1978 df_chain->block_pool = NULL;
1982 /* Remove the chain problem completely. */
1984 static void
1985 df_chain_fully_remove_problem (void)
1987 df_chain_remove_problem ();
1988 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
1989 free (df_chain);
1993 /* Create def-use or use-def chains. */
1995 static void
1996 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1998 df_chain_remove_problem ();
1999 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2000 sizeof (struct df_link), 50);
2001 df_chain->optional_p = true;
2005 /* Reset all of the chains when the set of basic blocks changes. */
2007 static void
2008 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2010 df_chain_remove_problem ();
2014 /* Create the chains for a list of USEs. */
2016 static void
2017 df_chain_create_bb_process_use (bitmap local_rd,
2018 struct df_ref **use_rec,
2019 enum df_ref_flags top_flag)
2021 bitmap_iterator bi;
2022 unsigned int def_index;
2024 while (*use_rec)
2026 struct df_ref *use = *use_rec;
2027 unsigned int uregno = DF_REF_REGNO (use);
2028 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2029 || (uregno >= FIRST_PSEUDO_REGISTER))
2031 /* Do not want to go through this for an uninitialized var. */
2032 int count = DF_DEFS_COUNT (uregno);
2033 if (count)
2035 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2037 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2038 unsigned int last_index = first_index + count - 1;
2040 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2042 struct df_ref *def;
2043 if (def_index > last_index)
2044 break;
2046 def = DF_DEFS_GET (def_index);
2047 if (df_chain_problem_p (DF_DU_CHAIN))
2048 df_chain_create (def, use);
2049 if (df_chain_problem_p (DF_UD_CHAIN))
2050 df_chain_create (use, def);
2056 use_rec++;
2061 /* Create chains from reaching defs bitmaps for basic block BB. */
2063 static void
2064 df_chain_create_bb (unsigned int bb_index)
2066 basic_block bb = BASIC_BLOCK (bb_index);
2067 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2068 rtx insn;
2069 bitmap cpy = BITMAP_ALLOC (NULL);
2070 struct df_ref **def_rec;
2072 bitmap_copy (cpy, bb_info->in);
2073 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2075 /* Since we are going forwards, process the artificial uses first
2076 then the artificial defs second. */
2078 #ifdef EH_USES
2079 /* Create the chains for the artificial uses from the EH_USES at the
2080 beginning of the block. */
2082 /* Artificials are only hard regs. */
2083 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2084 df_chain_create_bb_process_use (cpy,
2085 df_get_artificial_uses (bb->index),
2086 DF_REF_AT_TOP);
2087 #endif
2089 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2091 struct df_ref *def = *def_rec;
2092 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2094 unsigned int dregno = DF_REF_REGNO (def);
2095 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2096 bitmap_clear_range (cpy,
2097 DF_DEFS_BEGIN (dregno),
2098 DF_DEFS_COUNT (dregno));
2099 bitmap_set_bit (cpy, DF_REF_ID (def));
2103 /* Process the regular instructions next. */
2104 FOR_BB_INSNS (bb, insn)
2106 struct df_ref **def_rec;
2107 unsigned int uid = INSN_UID (insn);
2109 if (!INSN_P (insn))
2110 continue;
2112 /* Now scan the uses and link them up with the defs that remain
2113 in the cpy vector. */
2115 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
2117 if (df->changeable_flags & DF_EQ_NOTES)
2118 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
2121 /* Since we are going forwards, process the defs second. This
2122 pass only changes the bits in cpy. */
2123 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2125 struct df_ref *def = *def_rec;
2126 unsigned int dregno = DF_REF_REGNO (def);
2127 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2128 || (dregno >= FIRST_PSEUDO_REGISTER))
2130 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2131 bitmap_clear_range (cpy,
2132 DF_DEFS_BEGIN (dregno),
2133 DF_DEFS_COUNT (dregno));
2134 if (!(DF_REF_FLAGS (def)
2135 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
2136 bitmap_set_bit (cpy, DF_REF_ID (def));
2141 /* Create the chains for the artificial uses of the hard registers
2142 at the end of the block. */
2143 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2144 df_chain_create_bb_process_use (cpy,
2145 df_get_artificial_uses (bb->index),
2148 BITMAP_FREE (cpy);
2151 /* Create def-use chains from reaching use bitmaps for basic blocks
2152 in BLOCKS. */
2154 static void
2155 df_chain_finalize (bitmap all_blocks)
2157 unsigned int bb_index;
2158 bitmap_iterator bi;
2160 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2162 df_chain_create_bb (bb_index);
2167 /* Free all storage associated with the problem. */
2169 static void
2170 df_chain_free (void)
2172 free_alloc_pool (df_chain->block_pool);
2173 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2174 free (df_chain);
2178 /* Debugging info. */
2180 static void
2181 df_chain_top_dump (basic_block bb, FILE *file)
2183 if (df_chain_problem_p (DF_DU_CHAIN))
2185 rtx insn;
2186 struct df_ref **def_rec = df_get_artificial_defs (bb->index);
2187 if (*def_rec)
2190 fprintf (file, ";; DU chains for artificial defs\n");
2191 while (*def_rec)
2193 struct df_ref *def = *def_rec;
2194 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2195 df_chain_dump (DF_REF_CHAIN (def), file);
2196 fprintf (file, "\n");
2197 def_rec++;
2201 FOR_BB_INSNS (bb, insn)
2203 unsigned int uid = INSN_UID (insn);
2204 if (INSN_P (insn))
2206 def_rec = DF_INSN_UID_DEFS (uid);
2207 if (*def_rec)
2209 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2210 DF_INSN_LUID (insn), uid);
2212 while (*def_rec)
2214 struct df_ref *def = *def_rec;
2215 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2216 if (def->flags & DF_REF_READ_WRITE)
2217 fprintf (file, "read/write ");
2218 df_chain_dump (DF_REF_CHAIN (def), file);
2219 fprintf (file, "\n");
2220 def_rec++;
2229 static void
2230 df_chain_bottom_dump (basic_block bb, FILE *file)
2232 if (df_chain_problem_p (DF_UD_CHAIN))
2234 rtx insn;
2235 struct df_ref **use_rec = df_get_artificial_uses (bb->index);
2237 if (*use_rec)
2239 fprintf (file, ";; UD chains for artificial uses\n");
2240 while (*use_rec)
2242 struct df_ref *use = *use_rec;
2243 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2244 df_chain_dump (DF_REF_CHAIN (use), file);
2245 fprintf (file, "\n");
2246 use_rec++;
2250 FOR_BB_INSNS (bb, insn)
2252 unsigned int uid = INSN_UID (insn);
2253 if (INSN_P (insn))
2255 struct df_ref **eq_use_rec = DF_INSN_UID_EQ_USES (uid);
2256 use_rec = DF_INSN_UID_USES (uid);
2257 if (*use_rec || *eq_use_rec)
2259 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2260 DF_INSN_LUID (insn), uid);
2262 while (*use_rec)
2264 struct df_ref *use = *use_rec;
2265 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2266 if (use->flags & DF_REF_READ_WRITE)
2267 fprintf (file, "read/write ");
2268 df_chain_dump (DF_REF_CHAIN (use), file);
2269 fprintf (file, "\n");
2270 use_rec++;
2272 while (*eq_use_rec)
2274 struct df_ref *use = *eq_use_rec;
2275 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2276 df_chain_dump (DF_REF_CHAIN (use), file);
2277 fprintf (file, "\n");
2278 eq_use_rec++;
2287 static struct df_problem problem_CHAIN =
2289 DF_CHAIN, /* Problem id. */
2290 DF_NONE, /* Direction. */
2291 df_chain_alloc, /* Allocate the problem specific data. */
2292 df_chain_reset, /* Reset global information. */
2293 NULL, /* Free basic block info. */
2294 NULL, /* Local compute function. */
2295 NULL, /* Init the solution specific data. */
2296 NULL, /* Iterative solver. */
2297 NULL, /* Confluence operator 0. */
2298 NULL, /* Confluence operator n. */
2299 NULL, /* Transfer function. */
2300 df_chain_finalize, /* Finalize function. */
2301 df_chain_free, /* Free all of the problem information. */
2302 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2303 NULL, /* Debugging. */
2304 df_chain_top_dump, /* Debugging start block. */
2305 df_chain_bottom_dump, /* Debugging end block. */
2306 NULL, /* Incremental solution verify start. */
2307 NULL, /* Incremental solution verify end. */
2308 &problem_RD, /* Dependent problem. */
2309 TV_DF_CHAIN, /* Timing variable. */
2310 false /* Reset blocks on dropping out of blocks_to_analyze. */
2314 /* Create a new DATAFLOW instance and add it to an existing instance
2315 of DF. The returned structure is what is used to get at the
2316 solution. */
2318 void
2319 df_chain_add_problem (enum df_chain_flags chain_flags)
2321 df_add_problem (&problem_CHAIN);
2322 df_chain->local_flags = (unsigned int)chain_flags;
2323 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2326 #undef df_chain_problem_p
2329 /*----------------------------------------------------------------------------
2330 This pass computes REG_DEAD and REG_UNUSED notes.
2331 ----------------------------------------------------------------------------*/
2333 static void
2334 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2336 df_note->optional_p = true;
2339 #ifdef REG_DEAD_DEBUGGING
2340 static void
2341 df_print_note (const char *prefix, rtx insn, rtx note)
2343 if (dump_file)
2345 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2346 print_rtl (dump_file, note);
2347 fprintf (dump_file, "\n");
2350 #endif
2353 /* After reg-stack, the x86 floating point stack regs are difficult to
2354 analyze because of all of the pushes, pops and rotations. Thus, we
2355 just leave the notes alone. */
2357 #ifdef STACK_REGS
2358 static inline bool
2359 df_ignore_stack_reg (int regno)
2361 return regstack_completed
2362 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2364 #else
2365 static inline bool
2366 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2368 return false;
2370 #endif
2373 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2374 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
2376 static void
2377 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
2379 rtx *pprev = &REG_NOTES (insn);
2380 rtx link = *pprev;
2381 rtx dead = NULL;
2382 rtx unused = NULL;
2384 while (link)
2386 switch (REG_NOTE_KIND (link))
2388 case REG_DEAD:
2389 /* After reg-stack, we need to ignore any unused notes
2390 for the stack registers. */
2391 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2393 pprev = &XEXP (link, 1);
2394 link = *pprev;
2396 else
2398 rtx next = XEXP (link, 1);
2399 #ifdef REG_DEAD_DEBUGGING
2400 df_print_note ("deleting: ", insn, link);
2401 #endif
2402 XEXP (link, 1) = dead;
2403 dead = link;
2404 *pprev = link = next;
2406 break;
2408 case REG_UNUSED:
2409 /* After reg-stack, we need to ignore any unused notes
2410 for the stack registers. */
2411 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2413 pprev = &XEXP (link, 1);
2414 link = *pprev;
2416 else
2418 rtx next = XEXP (link, 1);
2419 #ifdef REG_DEAD_DEBUGGING
2420 df_print_note ("deleting: ", insn, link);
2421 #endif
2422 XEXP (link, 1) = unused;
2423 unused = link;
2424 *pprev = link = next;
2426 break;
2428 default:
2429 pprev = &XEXP (link, 1);
2430 link = *pprev;
2431 break;
2435 *old_dead_notes = dead;
2436 *old_unused_notes = unused;
2440 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
2441 list, otherwise create a new one. */
2443 static inline rtx
2444 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
2446 rtx this = old;
2447 rtx prev = NULL;
2449 while (this)
2450 if (XEXP (this, 0) == reg)
2452 if (prev)
2453 XEXP (prev, 1) = XEXP (this, 1);
2454 else
2455 old = XEXP (this, 1);
2456 XEXP (this, 1) = REG_NOTES (insn);
2457 REG_NOTES (insn) = this;
2458 return old;
2460 else
2462 prev = this;
2463 this = XEXP (this, 1);
2466 /* Did not find the note. */
2467 REG_NOTES (insn) = alloc_EXPR_LIST (note_type, reg, REG_NOTES (insn));
2468 return old;
2471 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2472 arguments. Return true if the register value described by MWS's
2473 mw_reg is known to be completely unused, and if mw_reg can therefore
2474 be used in a REG_UNUSED note. */
2476 static bool
2477 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2478 bitmap live, bitmap artificial_uses)
2480 unsigned int r;
2482 /* If MWS describes a partial reference, create REG_UNUSED notes for
2483 individual hard registers. */
2484 if (mws->flags & DF_REF_PARTIAL)
2485 return false;
2487 /* Likewise if some part of the register is used. */
2488 for (r = mws->start_regno; r <= mws->end_regno; r++)
2489 if (bitmap_bit_p (live, r)
2490 || bitmap_bit_p (artificial_uses, r))
2491 return false;
2493 gcc_assert (REG_P (mws->mw_reg));
2494 return true;
2497 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2498 based on the bits in LIVE. Do not generate notes for registers in
2499 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2500 not generated if the reg is both read and written by the
2501 instruction.
2504 static rtx
2505 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2506 bitmap live, bitmap do_not_gen,
2507 bitmap artificial_uses)
2509 unsigned int r;
2511 #ifdef REG_DEAD_DEBUGGING
2512 if (dump_file)
2513 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2514 mws->start_regno, mws->end_regno);
2515 #endif
2517 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2519 unsigned int regno = mws->start_regno;
2520 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
2522 #ifdef REG_DEAD_DEBUGGING
2523 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2524 #endif
2525 bitmap_set_bit (do_not_gen, regno);
2526 /* Only do this if the value is totally dead. */
2528 else
2529 for (r = mws->start_regno; r <= mws->end_regno; r++)
2531 if (!bitmap_bit_p (live, r)
2532 && !bitmap_bit_p (artificial_uses, r))
2534 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
2535 #ifdef REG_DEAD_DEBUGGING
2536 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2537 #endif
2539 bitmap_set_bit (do_not_gen, r);
2541 return old;
2545 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2546 arguments. Return true if the register value described by MWS's
2547 mw_reg is known to be completely dead, and if mw_reg can therefore
2548 be used in a REG_DEAD note. */
2550 static bool
2551 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2552 bitmap live, bitmap artificial_uses,
2553 bitmap do_not_gen)
2555 unsigned int r;
2557 /* If MWS describes a partial reference, create REG_DEAD notes for
2558 individual hard registers. */
2559 if (mws->flags & DF_REF_PARTIAL)
2560 return false;
2562 /* Likewise if some part of the register is not dead. */
2563 for (r = mws->start_regno; r <= mws->end_regno; r++)
2564 if (bitmap_bit_p (live, r)
2565 || bitmap_bit_p (artificial_uses, r)
2566 || bitmap_bit_p (do_not_gen, r))
2567 return false;
2569 gcc_assert (REG_P (mws->mw_reg));
2570 return true;
2573 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2574 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2575 from being set if the instruction both reads and writes the
2576 register. */
2578 static rtx
2579 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2580 bitmap live, bitmap do_not_gen,
2581 bitmap artificial_uses)
2583 unsigned int r;
2585 #ifdef REG_DEAD_DEBUGGING
2586 if (dump_file)
2588 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2589 mws->start_regno, mws->end_regno);
2590 df_print_regset (dump_file, do_not_gen);
2591 fprintf (dump_file, " live =");
2592 df_print_regset (dump_file, live);
2593 fprintf (dump_file, " artificial uses =");
2594 df_print_regset (dump_file, artificial_uses);
2596 #endif
2598 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2600 /* Add a dead note for the entire multi word register. */
2601 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
2602 #ifdef REG_DEAD_DEBUGGING
2603 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2604 #endif
2606 else
2608 for (r = mws->start_regno; r <= mws->end_regno; r++)
2609 if (!bitmap_bit_p (live, r)
2610 && !bitmap_bit_p (artificial_uses, r)
2611 && !bitmap_bit_p (do_not_gen, r))
2613 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
2614 #ifdef REG_DEAD_DEBUGGING
2615 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2616 #endif
2619 return old;
2623 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
2624 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
2626 static rtx
2627 df_create_unused_note (rtx insn, rtx old, struct df_ref *def,
2628 bitmap live, bitmap artificial_uses)
2630 unsigned int dregno = DF_REF_REGNO (def);
2632 #ifdef REG_DEAD_DEBUGGING
2633 if (dump_file)
2635 fprintf (dump_file, " regular looking at def ");
2636 df_ref_debug (def, dump_file);
2638 #endif
2640 if (!(bitmap_bit_p (live, dregno)
2641 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
2642 || bitmap_bit_p (artificial_uses, dregno)
2643 || df_ignore_stack_reg (dregno)))
2645 rtx reg = (DF_REF_LOC (def))
2646 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
2647 old = df_set_note (REG_UNUSED, insn, old, reg);
2648 #ifdef REG_DEAD_DEBUGGING
2649 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
2650 #endif
2653 return old;
2657 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
2658 info: lifetime, bb, and number of defs and uses for basic block
2659 BB. The three bitvectors are scratch regs used here. */
2661 static void
2662 df_note_bb_compute (unsigned int bb_index,
2663 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
2665 basic_block bb = BASIC_BLOCK (bb_index);
2666 rtx insn;
2667 struct df_ref **def_rec;
2668 struct df_ref **use_rec;
2670 bitmap_copy (live, df_get_live_out (bb));
2671 bitmap_clear (artificial_uses);
2673 #ifdef REG_DEAD_DEBUGGING
2674 if (dump_file)
2676 fprintf (dump_file, "live at bottom ");
2677 df_print_regset (dump_file, live);
2679 #endif
2681 /* Process the artificial defs and uses at the bottom of the block
2682 to begin processing. */
2683 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2685 struct df_ref *def = *def_rec;
2686 #ifdef REG_DEAD_DEBUGGING
2687 if (dump_file)
2688 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
2689 #endif
2691 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2692 bitmap_clear_bit (live, DF_REF_REGNO (def));
2695 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2697 struct df_ref *use = *use_rec;
2698 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2700 unsigned int regno = DF_REF_REGNO (use);
2701 bitmap_set_bit (live, regno);
2703 /* Notes are not generated for any of the artificial registers
2704 at the bottom of the block. */
2705 bitmap_set_bit (artificial_uses, regno);
2709 #ifdef REG_DEAD_DEBUGGING
2710 if (dump_file)
2712 fprintf (dump_file, "live before artificials out ");
2713 df_print_regset (dump_file, live);
2715 #endif
2717 FOR_BB_INSNS_REVERSE (bb, insn)
2719 unsigned int uid = INSN_UID (insn);
2720 struct df_mw_hardreg **mws_rec;
2721 rtx old_dead_notes;
2722 rtx old_unused_notes;
2724 if (!INSN_P (insn))
2725 continue;
2727 bitmap_clear (do_not_gen);
2728 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
2730 /* Process the defs. */
2731 if (CALL_P (insn))
2733 #ifdef REG_DEAD_DEBUGGING
2734 if (dump_file)
2736 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
2737 df_print_regset (dump_file, live);
2739 #endif
2740 /* We only care about real sets for calls. Clobbers cannot
2741 be depended on to really die. */
2742 mws_rec = DF_INSN_UID_MWS (uid);
2743 while (*mws_rec)
2745 struct df_mw_hardreg *mws = *mws_rec;
2746 if ((mws->type == DF_REF_REG_DEF)
2747 && !df_ignore_stack_reg (mws->start_regno))
2748 old_unused_notes
2749 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2750 mws, live, do_not_gen,
2751 artificial_uses);
2752 mws_rec++;
2755 /* All of the defs except the return value are some sort of
2756 clobber. This code is for the return. */
2757 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2759 struct df_ref *def = *def_rec;
2760 unsigned int dregno = DF_REF_REGNO (def);
2761 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2763 old_unused_notes
2764 = df_create_unused_note (insn, old_unused_notes,
2765 def, live, artificial_uses);
2766 bitmap_set_bit (do_not_gen, dregno);
2769 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2770 bitmap_clear_bit (live, dregno);
2773 else
2775 /* Regular insn. */
2776 mws_rec = DF_INSN_UID_MWS (uid);
2777 while (*mws_rec)
2779 struct df_mw_hardreg *mws = *mws_rec;
2780 if (mws->type == DF_REF_REG_DEF)
2781 old_unused_notes
2782 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2783 mws, live, do_not_gen,
2784 artificial_uses);
2785 mws_rec++;
2788 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2790 struct df_ref *def = *def_rec;
2791 unsigned int dregno = DF_REF_REGNO (def);
2792 old_unused_notes
2793 = df_create_unused_note (insn, old_unused_notes,
2794 def, live, artificial_uses);
2796 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2797 bitmap_set_bit (do_not_gen, dregno);
2799 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2800 bitmap_clear_bit (live, dregno);
2804 /* Process the uses. */
2805 mws_rec = DF_INSN_UID_MWS (uid);
2806 while (*mws_rec)
2808 struct df_mw_hardreg *mws = *mws_rec;
2809 if ((mws->type != DF_REF_REG_DEF)
2810 && !df_ignore_stack_reg (mws->start_regno))
2811 old_dead_notes
2812 = df_set_dead_notes_for_mw (insn, old_dead_notes,
2813 mws, live, do_not_gen,
2814 artificial_uses);
2815 mws_rec++;
2818 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2820 struct df_ref *use = *use_rec;
2821 unsigned int uregno = DF_REF_REGNO (use);
2823 #ifdef REG_DEAD_DEBUGGING
2824 if (dump_file)
2826 fprintf (dump_file, " regular looking at use ");
2827 df_ref_debug (use, dump_file);
2829 #endif
2830 if (!bitmap_bit_p (live, uregno))
2832 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
2833 && (!bitmap_bit_p (do_not_gen, uregno))
2834 && (!bitmap_bit_p (artificial_uses, uregno))
2835 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
2836 && (!df_ignore_stack_reg (uregno)))
2838 rtx reg = (DF_REF_LOC (use))
2839 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
2840 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
2842 #ifdef REG_DEAD_DEBUGGING
2843 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
2844 #endif
2846 /* This register is now live. */
2847 bitmap_set_bit (live, uregno);
2851 while (old_unused_notes)
2853 rtx next = XEXP (old_unused_notes, 1);
2854 free_EXPR_LIST_node (old_unused_notes);
2855 old_unused_notes = next;
2857 while (old_dead_notes)
2859 rtx next = XEXP (old_dead_notes, 1);
2860 free_EXPR_LIST_node (old_dead_notes);
2861 old_dead_notes = next;
2867 /* Compute register info: lifetime, bb, and number of defs and uses. */
2868 static void
2869 df_note_compute (bitmap all_blocks)
2871 unsigned int bb_index;
2872 bitmap_iterator bi;
2873 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
2874 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
2875 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
2877 #ifdef REG_DEAD_DEBUGGING
2878 if (dump_file)
2879 print_rtl_with_bb (dump_file, get_insns());
2880 #endif
2882 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2884 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
2887 BITMAP_FREE (live);
2888 BITMAP_FREE (do_not_gen);
2889 BITMAP_FREE (artificial_uses);
2893 /* Free all storage associated with the problem. */
2895 static void
2896 df_note_free (void)
2898 free (df_note);
2902 /* All of the information associated every instance of the problem. */
2904 static struct df_problem problem_NOTE =
2906 DF_NOTE, /* Problem id. */
2907 DF_NONE, /* Direction. */
2908 df_note_alloc, /* Allocate the problem specific data. */
2909 NULL, /* Reset global information. */
2910 NULL, /* Free basic block info. */
2911 df_note_compute, /* Local compute function. */
2912 NULL, /* Init the solution specific data. */
2913 NULL, /* Iterative solver. */
2914 NULL, /* Confluence operator 0. */
2915 NULL, /* Confluence operator n. */
2916 NULL, /* Transfer function. */
2917 NULL, /* Finalize function. */
2918 df_note_free, /* Free all of the problem information. */
2919 df_note_free, /* Remove this problem from the stack of dataflow problems. */
2920 NULL, /* Debugging. */
2921 NULL, /* Debugging start block. */
2922 NULL, /* Debugging end block. */
2923 NULL, /* Incremental solution verify start. */
2924 NULL, /* Incremental solution verify end. */
2925 &problem_LR, /* Dependent problem. */
2926 TV_DF_NOTE, /* Timing variable. */
2927 false /* Reset blocks on dropping out of blocks_to_analyze. */
2931 /* Create a new DATAFLOW instance and add it to an existing instance
2932 of DF. The returned structure is what is used to get at the
2933 solution. */
2935 void
2936 df_note_add_problem (void)
2938 df_add_problem (&problem_NOTE);
2944 /*----------------------------------------------------------------------------
2945 Functions for simulating the effects of single insns.
2947 You can either simulate in the forwards direction, starting from
2948 the top of a block or the backwards direction from the end of the
2949 block. The main difference is that if you go forwards, the uses
2950 are examined first then the defs, and if you go backwards, the defs
2951 are examined first then the uses.
2953 If you start at the top of the block, use one of DF_LIVE_IN or
2954 DF_LR_IN. If you start at the bottom of the block use one of
2955 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
2956 THEY WILL BE DESTROYED.
2958 ----------------------------------------------------------------------------*/
2961 /* Find the set of DEFs for INSN. */
2963 void
2964 df_simulate_find_defs (rtx insn, bitmap defs)
2966 struct df_ref **def_rec;
2967 unsigned int uid = INSN_UID (insn);
2969 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2971 struct df_ref *def = *def_rec;
2972 /* If the def is to only part of the reg, it does
2973 not kill the other defs that reach here. */
2974 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2975 bitmap_set_bit (defs, DF_REF_REGNO (def));
2980 /* Simulate the effects of the defs of INSN on LIVE. */
2982 void
2983 df_simulate_defs (rtx insn, bitmap live)
2985 struct df_ref **def_rec;
2986 unsigned int uid = INSN_UID (insn);
2988 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2990 struct df_ref *def = *def_rec;
2991 unsigned int dregno = DF_REF_REGNO (def);
2993 /* If the def is to only part of the reg, it does
2994 not kill the other defs that reach here. */
2995 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2996 bitmap_clear_bit (live, dregno);
3001 /* Simulate the effects of the uses of INSN on LIVE. */
3003 void
3004 df_simulate_uses (rtx insn, bitmap live)
3006 struct df_ref **use_rec;
3007 unsigned int uid = INSN_UID (insn);
3009 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3011 struct df_ref *use = *use_rec;
3012 /* Add use to set of uses in this BB. */
3013 bitmap_set_bit (live, DF_REF_REGNO (use));
3018 /* Add back the always live regs in BB to LIVE. */
3020 static inline void
3021 df_simulate_fixup_sets (basic_block bb, bitmap live)
3023 /* These regs are considered always live so if they end up dying
3024 because of some def, we need to bring the back again. */
3025 if (bb_has_eh_pred (bb))
3026 bitmap_ior_into (live, df->eh_block_artificial_uses);
3027 else
3028 bitmap_ior_into (live, df->regular_block_artificial_uses);
3032 /* Apply the artificial uses and defs at the top of BB in a forwards
3033 direction. */
3035 void
3036 df_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
3038 struct df_ref **def_rec;
3039 struct df_ref **use_rec;
3040 int bb_index = bb->index;
3042 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3044 struct df_ref *use = *use_rec;
3045 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3046 bitmap_set_bit (live, DF_REF_REGNO (use));
3049 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3051 struct df_ref *def = *def_rec;
3052 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3053 bitmap_clear_bit (live, DF_REF_REGNO (def));
3058 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3060 void
3061 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3063 if (! INSN_P (insn))
3064 return;
3066 df_simulate_uses (insn, live);
3067 df_simulate_defs (insn, live);
3068 df_simulate_fixup_sets (bb, live);
3072 /* Apply the artificial uses and defs at the end of BB in a backwards
3073 direction. */
3075 void
3076 df_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3078 struct df_ref **def_rec;
3079 struct df_ref **use_rec;
3080 int bb_index = bb->index;
3082 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3084 struct df_ref *def = *def_rec;
3085 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3086 bitmap_clear_bit (live, DF_REF_REGNO (def));
3089 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3091 struct df_ref *use = *use_rec;
3092 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3093 bitmap_set_bit (live, DF_REF_REGNO (use));
3098 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3100 void
3101 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3103 if (! INSN_P (insn))
3104 return;
3106 df_simulate_defs (insn, live);
3107 df_simulate_uses (insn, live);
3108 df_simulate_fixup_sets (bb, live);