pr 33870
[official-gcc.git] / gcc / df-problems.c
blobdd56399be50b144f30c0af809ecd63545d6edef3
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 COMBINED LIVE REGISTERS AND UNINITIALIZED REGISTERS.
1309 First find the set of uses for registers that are reachable from
1310 the entry block without passing thru a definition. In and out
1311 bitvectors are built for each basic block. The regnum is used to
1312 index into these sets. See df.h for details.
1314 Then the in and out sets here are the anded results of the in and
1315 out sets from the lr and ur
1316 problems.
1317 ----------------------------------------------------------------------------*/
1319 /* Private data used to verify the solution for this problem. */
1320 struct df_live_problem_data
1322 bitmap *in;
1323 bitmap *out;
1327 /* Set basic block info. */
1329 static void
1330 df_live_set_bb_info (unsigned int index,
1331 struct df_live_bb_info *bb_info)
1333 gcc_assert (df_live);
1334 gcc_assert (index < df_live->block_info_size);
1335 df_live->block_info[index] = bb_info;
1339 /* Free basic block info. */
1341 static void
1342 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1343 void *vbb_info)
1345 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1346 if (bb_info)
1348 BITMAP_FREE (bb_info->gen);
1349 BITMAP_FREE (bb_info->kill);
1350 BITMAP_FREE (bb_info->in);
1351 BITMAP_FREE (bb_info->out);
1352 pool_free (df_live->block_pool, bb_info);
1357 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1358 not touched unless the block is new. */
1360 static void
1361 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1363 unsigned int bb_index;
1364 bitmap_iterator bi;
1366 if (!df_live->block_pool)
1367 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1368 sizeof (struct df_live_bb_info), 100);
1370 df_grow_bb_info (df_live);
1372 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1374 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1375 if (bb_info)
1377 bitmap_clear (bb_info->kill);
1378 bitmap_clear (bb_info->gen);
1380 else
1382 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1383 df_live_set_bb_info (bb_index, bb_info);
1384 bb_info->kill = BITMAP_ALLOC (NULL);
1385 bb_info->gen = BITMAP_ALLOC (NULL);
1386 bb_info->in = BITMAP_ALLOC (NULL);
1387 bb_info->out = BITMAP_ALLOC (NULL);
1390 df_live->optional_p = (optimize <= 1);
1394 /* Reset the global solution for recalculation. */
1396 static void
1397 df_live_reset (bitmap all_blocks)
1399 unsigned int bb_index;
1400 bitmap_iterator bi;
1402 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1404 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1405 gcc_assert (bb_info);
1406 bitmap_clear (bb_info->in);
1407 bitmap_clear (bb_info->out);
1412 /* Compute local uninitialized register info for basic block BB. */
1414 static void
1415 df_live_bb_local_compute (unsigned int bb_index)
1417 basic_block bb = BASIC_BLOCK (bb_index);
1418 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1419 rtx insn;
1420 struct df_ref **def_rec;
1421 int luid = 0;
1423 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1425 struct df_ref *def = *def_rec;
1426 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
1427 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1430 FOR_BB_INSNS (bb, insn)
1432 unsigned int uid = INSN_UID (insn);
1433 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1435 /* Inserting labels does not always trigger the incremental
1436 rescanning. */
1437 if (!insn_info)
1439 gcc_assert (!INSN_P (insn));
1440 df_insn_create_insn_record (insn);
1443 DF_INSN_LUID (insn) = luid;
1444 if (!INSN_P (insn))
1445 continue;
1447 luid++;
1448 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1450 struct df_ref *def = *def_rec;
1451 unsigned int regno = DF_REF_REGNO (def);
1453 if (DF_REF_FLAGS_IS_SET (def,
1454 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1455 /* All partial or conditional def
1456 seen are included in the gen set. */
1457 bitmap_set_bit (bb_info->gen, regno);
1458 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1459 /* Only must clobbers for the entire reg destroy the
1460 value. */
1461 bitmap_set_bit (bb_info->kill, regno);
1462 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1463 bitmap_set_bit (bb_info->gen, regno);
1467 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1469 struct df_ref *def = *def_rec;
1470 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
1471 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1476 /* Compute local uninitialized register info. */
1478 static void
1479 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1481 unsigned int bb_index;
1482 bitmap_iterator bi;
1484 df_grow_insn_info ();
1486 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1487 0, bb_index, bi)
1489 df_live_bb_local_compute (bb_index);
1492 bitmap_clear (df_live->out_of_date_transfer_functions);
1496 /* Initialize the solution vectors. */
1498 static void
1499 df_live_init (bitmap all_blocks)
1501 unsigned int bb_index;
1502 bitmap_iterator bi;
1504 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1506 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1508 bitmap_copy (bb_info->out, bb_info->gen);
1509 bitmap_clear (bb_info->in);
1513 /* Confluence function that ignores fake edges. */
1515 static void
1516 df_live_confluence_n (edge e)
1518 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
1519 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
1521 if (e->flags & EDGE_FAKE)
1522 return;
1524 bitmap_ior_into (op1, op2);
1528 /* Transfer function. */
1530 static bool
1531 df_live_transfer_function (int bb_index)
1533 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1534 bitmap in = bb_info->in;
1535 bitmap out = bb_info->out;
1536 bitmap gen = bb_info->gen;
1537 bitmap kill = bb_info->kill;
1539 return bitmap_ior_and_compl (out, gen, in, kill);
1543 /* And the LR and UR info to produce the LIVE info. */
1545 static void
1546 df_live_local_finalize (bitmap all_blocks)
1549 if (df_live->solutions_dirty)
1551 bitmap_iterator bi;
1552 unsigned int bb_index;
1554 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1556 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1557 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1559 /* No register may reach a location where it is not used. Thus
1560 we trim the rr result to the places where it is used. */
1561 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
1562 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
1565 df_live->solutions_dirty = false;
1570 /* Free all storage associated with the problem. */
1572 static void
1573 df_live_free (void)
1575 if (df_live->block_info)
1577 unsigned int i;
1579 for (i = 0; i < df_live->block_info_size; i++)
1581 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
1582 if (bb_info)
1584 BITMAP_FREE (bb_info->gen);
1585 BITMAP_FREE (bb_info->kill);
1586 BITMAP_FREE (bb_info->in);
1587 BITMAP_FREE (bb_info->out);
1591 free_alloc_pool (df_live->block_pool);
1592 df_live->block_info_size = 0;
1593 free (df_live->block_info);
1595 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1596 free (df_live);
1600 /* Debugging info at top of bb. */
1602 static void
1603 df_live_top_dump (basic_block bb, FILE *file)
1605 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1606 struct df_live_problem_data *problem_data;
1608 if (!bb_info || !bb_info->in)
1609 return;
1611 fprintf (file, ";; live in \t");
1612 df_print_regset (file, bb_info->in);
1613 if (df_live->problem_data)
1615 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1616 fprintf (file, ";; old in \t");
1617 df_print_regset (file, problem_data->in[bb->index]);
1619 fprintf (file, ";; live gen \t");
1620 df_print_regset (file, bb_info->gen);
1621 fprintf (file, ";; live kill\t");
1622 df_print_regset (file, bb_info->kill);
1626 /* Debugging info at bottom of bb. */
1628 static void
1629 df_live_bottom_dump (basic_block bb, FILE *file)
1631 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1632 struct df_live_problem_data *problem_data;
1634 if (!bb_info || !bb_info->out)
1635 return;
1637 fprintf (file, ";; live out \t");
1638 df_print_regset (file, bb_info->out);
1639 if (df_live->problem_data)
1641 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1642 fprintf (file, ";; old out \t");
1643 df_print_regset (file, problem_data->out[bb->index]);
1648 /* Build the datastructure to verify that the solution to the dataflow
1649 equations is not dirty. */
1651 static void
1652 df_live_verify_solution_start (void)
1654 basic_block bb;
1655 struct df_live_problem_data *problem_data;
1656 if (df_live->solutions_dirty)
1658 df_live->problem_data = NULL;
1659 return;
1662 /* Set it true so that the solution is recomputed. */
1663 df_live->solutions_dirty = true;
1665 problem_data = XNEW (struct df_live_problem_data);
1666 df_live->problem_data = problem_data;
1667 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1668 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1670 FOR_ALL_BB (bb)
1672 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1673 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1674 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
1675 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
1680 /* Compare the saved datastructure and the new solution to the dataflow
1681 equations. */
1683 static void
1684 df_live_verify_solution_end (void)
1686 struct df_live_problem_data *problem_data;
1687 basic_block bb;
1689 if (df_live->problem_data == NULL)
1690 return;
1692 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1694 FOR_ALL_BB (bb)
1696 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
1697 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1699 /*df_dump (stderr);*/
1700 gcc_unreachable ();
1704 /* Cannot delete them immediately because you may want to dump them
1705 if the comparison fails. */
1706 FOR_ALL_BB (bb)
1708 BITMAP_FREE (problem_data->in[bb->index]);
1709 BITMAP_FREE (problem_data->out[bb->index]);
1712 free (problem_data->in);
1713 free (problem_data->out);
1714 free (problem_data);
1715 df_live->problem_data = NULL;
1719 /* All of the information associated with every instance of the problem. */
1721 static struct df_problem problem_LIVE =
1723 DF_LIVE, /* Problem id. */
1724 DF_FORWARD, /* Direction. */
1725 df_live_alloc, /* Allocate the problem specific data. */
1726 df_live_reset, /* Reset global information. */
1727 df_live_free_bb_info, /* Free basic block info. */
1728 df_live_local_compute, /* Local compute function. */
1729 df_live_init, /* Init the solution specific data. */
1730 df_worklist_dataflow, /* Worklist solver. */
1731 NULL, /* Confluence operator 0. */
1732 df_live_confluence_n, /* Confluence operator n. */
1733 df_live_transfer_function, /* Transfer function. */
1734 df_live_local_finalize, /* Finalize function. */
1735 df_live_free, /* Free all of the problem information. */
1736 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1737 NULL, /* Debugging. */
1738 df_live_top_dump, /* Debugging start block. */
1739 df_live_bottom_dump, /* Debugging end block. */
1740 df_live_verify_solution_start,/* Incremental solution verify start. */
1741 df_live_verify_solution_end, /* Incremental solution verify end. */
1742 &problem_LR, /* Dependent problem. */
1743 TV_DF_LIVE, /* Timing variable. */
1744 false /* Reset blocks on dropping out of blocks_to_analyze. */
1748 /* Create a new DATAFLOW instance and add it to an existing instance
1749 of DF. The returned structure is what is used to get at the
1750 solution. */
1752 void
1753 df_live_add_problem (void)
1755 df_add_problem (&problem_LIVE);
1756 /* These will be initialized when df_scan_blocks processes each
1757 block. */
1758 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1762 /* Set all of the blocks as dirty. This needs to be done if this
1763 problem is added after all of the insns have been scanned. */
1765 void
1766 df_live_set_all_dirty (void)
1768 basic_block bb;
1769 FOR_ALL_BB (bb)
1770 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1771 bb->index);
1775 /* Verify that all of the lr related info is consistent and
1776 correct. */
1778 void
1779 df_live_verify_transfer_functions (void)
1781 basic_block bb;
1782 bitmap saved_gen;
1783 bitmap saved_kill;
1784 bitmap all_blocks;
1786 if (!df)
1787 return;
1789 saved_gen = BITMAP_ALLOC (NULL);
1790 saved_kill = BITMAP_ALLOC (NULL);
1791 all_blocks = BITMAP_ALLOC (NULL);
1793 df_grow_insn_info ();
1795 FOR_ALL_BB (bb)
1797 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1798 bitmap_set_bit (all_blocks, bb->index);
1800 if (bb_info)
1802 /* Make a copy of the transfer functions and then compute
1803 new ones to see if the transfer functions have
1804 changed. */
1805 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1806 bb->index))
1808 bitmap_copy (saved_gen, bb_info->gen);
1809 bitmap_copy (saved_kill, bb_info->kill);
1810 bitmap_clear (bb_info->gen);
1811 bitmap_clear (bb_info->kill);
1813 df_live_bb_local_compute (bb->index);
1814 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
1815 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
1818 else
1820 /* If we do not have basic block info, the block must be in
1821 the list of dirty blocks or else some one has added a
1822 block behind our backs. */
1823 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1824 bb->index));
1826 /* Make sure no one created a block without following
1827 procedures. */
1828 gcc_assert (df_scan_get_bb_info (bb->index));
1831 /* Make sure there are no dirty bits in blocks that have been deleted. */
1832 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1833 all_blocks));
1834 BITMAP_FREE (saved_gen);
1835 BITMAP_FREE (saved_kill);
1836 BITMAP_FREE (all_blocks);
1839 /*----------------------------------------------------------------------------
1840 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1842 Link either the defs to the uses and / or the uses to the defs.
1844 These problems are set up like the other dataflow problems so that
1845 they nicely fit into the framework. They are much simpler and only
1846 involve a single traversal of instructions and an examination of
1847 the reaching defs information (the dependent problem).
1848 ----------------------------------------------------------------------------*/
1850 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1852 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1854 struct df_link *
1855 df_chain_create (struct df_ref *src, struct df_ref *dst)
1857 struct df_link *head = DF_REF_CHAIN (src);
1858 struct df_link *link = pool_alloc (df_chain->block_pool);;
1860 DF_REF_CHAIN (src) = link;
1861 link->next = head;
1862 link->ref = dst;
1863 return link;
1867 /* Delete any du or ud chains that start at REF and point to
1868 TARGET. */
1869 static void
1870 df_chain_unlink_1 (struct df_ref *ref, struct df_ref *target)
1872 struct df_link *chain = DF_REF_CHAIN (ref);
1873 struct df_link *prev = NULL;
1875 while (chain)
1877 if (chain->ref == target)
1879 if (prev)
1880 prev->next = chain->next;
1881 else
1882 DF_REF_CHAIN (ref) = chain->next;
1883 pool_free (df_chain->block_pool, chain);
1884 return;
1886 prev = chain;
1887 chain = chain->next;
1892 /* Delete a du or ud chain that leave or point to REF. */
1894 void
1895 df_chain_unlink (struct df_ref *ref)
1897 struct df_link *chain = DF_REF_CHAIN (ref);
1898 while (chain)
1900 struct df_link *next = chain->next;
1901 /* Delete the other side if it exists. */
1902 df_chain_unlink_1 (chain->ref, ref);
1903 pool_free (df_chain->block_pool, chain);
1904 chain = next;
1906 DF_REF_CHAIN (ref) = NULL;
1910 /* Copy the du or ud chain starting at FROM_REF and attach it to
1911 TO_REF. */
1913 void
1914 df_chain_copy (struct df_ref *to_ref,
1915 struct df_link *from_ref)
1917 while (from_ref)
1919 df_chain_create (to_ref, from_ref->ref);
1920 from_ref = from_ref->next;
1925 /* Remove this problem from the stack of dataflow problems. */
1927 static void
1928 df_chain_remove_problem (void)
1930 bitmap_iterator bi;
1931 unsigned int bb_index;
1933 /* Wholesale destruction of the old chains. */
1934 if (df_chain->block_pool)
1935 free_alloc_pool (df_chain->block_pool);
1937 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1939 rtx insn;
1940 struct df_ref **def_rec;
1941 struct df_ref **use_rec;
1942 basic_block bb = BASIC_BLOCK (bb_index);
1944 if (df_chain_problem_p (DF_DU_CHAIN))
1945 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1946 DF_REF_CHAIN (*def_rec) = NULL;
1947 if (df_chain_problem_p (DF_UD_CHAIN))
1948 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1949 DF_REF_CHAIN (*use_rec) = NULL;
1951 FOR_BB_INSNS (bb, insn)
1953 unsigned int uid = INSN_UID (insn);
1955 if (INSN_P (insn))
1957 if (df_chain_problem_p (DF_DU_CHAIN))
1958 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1959 DF_REF_CHAIN (*def_rec) = NULL;
1960 if (df_chain_problem_p (DF_UD_CHAIN))
1962 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1963 DF_REF_CHAIN (*use_rec) = NULL;
1964 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
1965 DF_REF_CHAIN (*use_rec) = NULL;
1971 bitmap_clear (df_chain->out_of_date_transfer_functions);
1972 df_chain->block_pool = NULL;
1976 /* Remove the chain problem completely. */
1978 static void
1979 df_chain_fully_remove_problem (void)
1981 df_chain_remove_problem ();
1982 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
1983 free (df_chain);
1987 /* Create def-use or use-def chains. */
1989 static void
1990 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1992 df_chain_remove_problem ();
1993 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
1994 sizeof (struct df_link), 50);
1995 df_chain->optional_p = true;
1999 /* Reset all of the chains when the set of basic blocks changes. */
2001 static void
2002 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2004 df_chain_remove_problem ();
2008 /* Create the chains for a list of USEs. */
2010 static void
2011 df_chain_create_bb_process_use (bitmap local_rd,
2012 struct df_ref **use_rec,
2013 enum df_ref_flags top_flag)
2015 bitmap_iterator bi;
2016 unsigned int def_index;
2018 while (*use_rec)
2020 struct df_ref *use = *use_rec;
2021 unsigned int uregno = DF_REF_REGNO (use);
2022 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2023 || (uregno >= FIRST_PSEUDO_REGISTER))
2025 /* Do not want to go through this for an uninitialized var. */
2026 int count = DF_DEFS_COUNT (uregno);
2027 if (count)
2029 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2031 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2032 unsigned int last_index = first_index + count - 1;
2034 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2036 struct df_ref *def;
2037 if (def_index > last_index)
2038 break;
2040 def = DF_DEFS_GET (def_index);
2041 if (df_chain_problem_p (DF_DU_CHAIN))
2042 df_chain_create (def, use);
2043 if (df_chain_problem_p (DF_UD_CHAIN))
2044 df_chain_create (use, def);
2050 use_rec++;
2055 /* Create chains from reaching defs bitmaps for basic block BB. */
2057 static void
2058 df_chain_create_bb (unsigned int bb_index)
2060 basic_block bb = BASIC_BLOCK (bb_index);
2061 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2062 rtx insn;
2063 bitmap cpy = BITMAP_ALLOC (NULL);
2064 struct df_ref **def_rec;
2066 bitmap_copy (cpy, bb_info->in);
2067 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2069 /* Since we are going forwards, process the artificial uses first
2070 then the artificial defs second. */
2072 #ifdef EH_USES
2073 /* Create the chains for the artificial uses from the EH_USES at the
2074 beginning of the block. */
2076 /* Artificials are only hard regs. */
2077 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2078 df_chain_create_bb_process_use (cpy,
2079 df_get_artificial_uses (bb->index),
2080 DF_REF_AT_TOP);
2081 #endif
2083 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2085 struct df_ref *def = *def_rec;
2086 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2088 unsigned int dregno = DF_REF_REGNO (def);
2089 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2090 bitmap_clear_range (cpy,
2091 DF_DEFS_BEGIN (dregno),
2092 DF_DEFS_COUNT (dregno));
2093 bitmap_set_bit (cpy, DF_REF_ID (def));
2097 /* Process the regular instructions next. */
2098 FOR_BB_INSNS (bb, insn)
2100 struct df_ref **def_rec;
2101 unsigned int uid = INSN_UID (insn);
2103 if (!INSN_P (insn))
2104 continue;
2106 /* Now scan the uses and link them up with the defs that remain
2107 in the cpy vector. */
2109 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
2111 if (df->changeable_flags & DF_EQ_NOTES)
2112 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
2115 /* Since we are going forwards, process the defs second. This
2116 pass only changes the bits in cpy. */
2117 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2119 struct df_ref *def = *def_rec;
2120 unsigned int dregno = DF_REF_REGNO (def);
2121 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2122 || (dregno >= FIRST_PSEUDO_REGISTER))
2124 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2125 bitmap_clear_range (cpy,
2126 DF_DEFS_BEGIN (dregno),
2127 DF_DEFS_COUNT (dregno));
2128 if (!(DF_REF_FLAGS (def)
2129 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
2130 bitmap_set_bit (cpy, DF_REF_ID (def));
2135 /* Create the chains for the artificial uses of the hard registers
2136 at the end of the block. */
2137 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2138 df_chain_create_bb_process_use (cpy,
2139 df_get_artificial_uses (bb->index),
2142 BITMAP_FREE (cpy);
2145 /* Create def-use chains from reaching use bitmaps for basic blocks
2146 in BLOCKS. */
2148 static void
2149 df_chain_finalize (bitmap all_blocks)
2151 unsigned int bb_index;
2152 bitmap_iterator bi;
2154 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2156 df_chain_create_bb (bb_index);
2161 /* Free all storage associated with the problem. */
2163 static void
2164 df_chain_free (void)
2166 free_alloc_pool (df_chain->block_pool);
2167 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2168 free (df_chain);
2172 /* Debugging info. */
2174 static void
2175 df_chain_top_dump (basic_block bb, FILE *file)
2177 if (df_chain_problem_p (DF_DU_CHAIN))
2179 rtx insn;
2180 struct df_ref **def_rec = df_get_artificial_defs (bb->index);
2181 if (*def_rec)
2184 fprintf (file, ";; DU chains for artificial defs\n");
2185 while (*def_rec)
2187 struct df_ref *def = *def_rec;
2188 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2189 df_chain_dump (DF_REF_CHAIN (def), file);
2190 fprintf (file, "\n");
2191 def_rec++;
2195 FOR_BB_INSNS (bb, insn)
2197 unsigned int uid = INSN_UID (insn);
2198 if (INSN_P (insn))
2200 def_rec = DF_INSN_UID_DEFS (uid);
2201 if (*def_rec)
2203 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2204 DF_INSN_LUID (insn), uid);
2206 while (*def_rec)
2208 struct df_ref *def = *def_rec;
2209 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2210 if (def->flags & DF_REF_READ_WRITE)
2211 fprintf (file, "read/write ");
2212 df_chain_dump (DF_REF_CHAIN (def), file);
2213 fprintf (file, "\n");
2214 def_rec++;
2223 static void
2224 df_chain_bottom_dump (basic_block bb, FILE *file)
2226 if (df_chain_problem_p (DF_UD_CHAIN))
2228 rtx insn;
2229 struct df_ref **use_rec = df_get_artificial_uses (bb->index);
2231 if (*use_rec)
2233 fprintf (file, ";; UD chains for artificial uses\n");
2234 while (*use_rec)
2236 struct df_ref *use = *use_rec;
2237 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2238 df_chain_dump (DF_REF_CHAIN (use), file);
2239 fprintf (file, "\n");
2240 use_rec++;
2244 FOR_BB_INSNS (bb, insn)
2246 unsigned int uid = INSN_UID (insn);
2247 if (INSN_P (insn))
2249 struct df_ref **eq_use_rec = DF_INSN_UID_EQ_USES (uid);
2250 use_rec = DF_INSN_UID_USES (uid);
2251 if (*use_rec || *eq_use_rec)
2253 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2254 DF_INSN_LUID (insn), uid);
2256 while (*use_rec)
2258 struct df_ref *use = *use_rec;
2259 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2260 if (use->flags & DF_REF_READ_WRITE)
2261 fprintf (file, "read/write ");
2262 df_chain_dump (DF_REF_CHAIN (use), file);
2263 fprintf (file, "\n");
2264 use_rec++;
2266 while (*eq_use_rec)
2268 struct df_ref *use = *eq_use_rec;
2269 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2270 df_chain_dump (DF_REF_CHAIN (use), file);
2271 fprintf (file, "\n");
2272 eq_use_rec++;
2281 static struct df_problem problem_CHAIN =
2283 DF_CHAIN, /* Problem id. */
2284 DF_NONE, /* Direction. */
2285 df_chain_alloc, /* Allocate the problem specific data. */
2286 df_chain_reset, /* Reset global information. */
2287 NULL, /* Free basic block info. */
2288 NULL, /* Local compute function. */
2289 NULL, /* Init the solution specific data. */
2290 NULL, /* Iterative solver. */
2291 NULL, /* Confluence operator 0. */
2292 NULL, /* Confluence operator n. */
2293 NULL, /* Transfer function. */
2294 df_chain_finalize, /* Finalize function. */
2295 df_chain_free, /* Free all of the problem information. */
2296 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2297 NULL, /* Debugging. */
2298 df_chain_top_dump, /* Debugging start block. */
2299 df_chain_bottom_dump, /* Debugging end block. */
2300 NULL, /* Incremental solution verify start. */
2301 NULL, /* Incremental solution verify end. */
2302 &problem_RD, /* Dependent problem. */
2303 TV_DF_CHAIN, /* Timing variable. */
2304 false /* Reset blocks on dropping out of blocks_to_analyze. */
2308 /* Create a new DATAFLOW instance and add it to an existing instance
2309 of DF. The returned structure is what is used to get at the
2310 solution. */
2312 void
2313 df_chain_add_problem (enum df_chain_flags chain_flags)
2315 df_add_problem (&problem_CHAIN);
2316 df_chain->local_flags = (unsigned int)chain_flags;
2317 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2320 #undef df_chain_problem_p
2323 /*----------------------------------------------------------------------------
2324 This pass computes REG_DEAD and REG_UNUSED notes.
2325 ----------------------------------------------------------------------------*/
2327 static void
2328 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2330 df_note->optional_p = true;
2333 #ifdef REG_DEAD_DEBUGGING
2334 static void
2335 df_print_note (const char *prefix, rtx insn, rtx note)
2337 if (dump_file)
2339 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2340 print_rtl (dump_file, note);
2341 fprintf (dump_file, "\n");
2344 #endif
2347 /* After reg-stack, the x86 floating point stack regs are difficult to
2348 analyze because of all of the pushes, pops and rotations. Thus, we
2349 just leave the notes alone. */
2351 #ifdef STACK_REGS
2352 static inline bool
2353 df_ignore_stack_reg (int regno)
2355 return regstack_completed
2356 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2358 #else
2359 static inline bool
2360 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2362 return false;
2364 #endif
2367 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2368 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
2370 static void
2371 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
2373 rtx *pprev = &REG_NOTES (insn);
2374 rtx link = *pprev;
2375 rtx dead = NULL;
2376 rtx unused = NULL;
2378 while (link)
2380 switch (REG_NOTE_KIND (link))
2382 case REG_DEAD:
2383 /* After reg-stack, we need to ignore any unused notes
2384 for the stack registers. */
2385 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2387 pprev = &XEXP (link, 1);
2388 link = *pprev;
2390 else
2392 rtx next = XEXP (link, 1);
2393 #ifdef REG_DEAD_DEBUGGING
2394 df_print_note ("deleting: ", insn, link);
2395 #endif
2396 XEXP (link, 1) = dead;
2397 dead = link;
2398 *pprev = link = next;
2400 break;
2402 case REG_UNUSED:
2403 /* After reg-stack, we need to ignore any unused notes
2404 for the stack registers. */
2405 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2407 pprev = &XEXP (link, 1);
2408 link = *pprev;
2410 else
2412 rtx next = XEXP (link, 1);
2413 #ifdef REG_DEAD_DEBUGGING
2414 df_print_note ("deleting: ", insn, link);
2415 #endif
2416 XEXP (link, 1) = unused;
2417 unused = link;
2418 *pprev = link = next;
2420 break;
2422 default:
2423 pprev = &XEXP (link, 1);
2424 link = *pprev;
2425 break;
2429 *old_dead_notes = dead;
2430 *old_unused_notes = unused;
2434 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
2435 list, otherwise create a new one. */
2437 static inline rtx
2438 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
2440 rtx this = old;
2441 rtx prev = NULL;
2443 while (this)
2444 if (XEXP (this, 0) == reg)
2446 if (prev)
2447 XEXP (prev, 1) = XEXP (this, 1);
2448 else
2449 old = XEXP (this, 1);
2450 XEXP (this, 1) = REG_NOTES (insn);
2451 REG_NOTES (insn) = this;
2452 return old;
2454 else
2456 prev = this;
2457 this = XEXP (this, 1);
2460 /* Did not find the note. */
2461 REG_NOTES (insn) = alloc_EXPR_LIST (note_type, reg, REG_NOTES (insn));
2462 return old;
2465 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2466 arguments. Return true if the register value described by MWS's
2467 mw_reg is known to be completely unused, and if mw_reg can therefore
2468 be used in a REG_UNUSED note. */
2470 static bool
2471 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2472 bitmap live, bitmap artificial_uses)
2474 unsigned int r;
2476 /* If MWS describes a partial reference, create REG_UNUSED notes for
2477 individual hard registers. */
2478 if (mws->flags & DF_REF_PARTIAL)
2479 return false;
2481 /* Likewise if some part of the register is used. */
2482 for (r = mws->start_regno; r <= mws->end_regno; r++)
2483 if (bitmap_bit_p (live, r)
2484 || bitmap_bit_p (artificial_uses, r))
2485 return false;
2487 gcc_assert (REG_P (mws->mw_reg));
2488 return true;
2491 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2492 based on the bits in LIVE. Do not generate notes for registers in
2493 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2494 not generated if the reg is both read and written by the
2495 instruction.
2498 static rtx
2499 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2500 bitmap live, bitmap do_not_gen,
2501 bitmap artificial_uses)
2503 unsigned int r;
2505 #ifdef REG_DEAD_DEBUGGING
2506 if (dump_file)
2507 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2508 mws->start_regno, mws->end_regno);
2509 #endif
2511 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2513 unsigned int regno = mws->start_regno;
2514 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
2516 #ifdef REG_DEAD_DEBUGGING
2517 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2518 #endif
2519 bitmap_set_bit (do_not_gen, regno);
2520 /* Only do this if the value is totally dead. */
2522 else
2523 for (r = mws->start_regno; r <= mws->end_regno; r++)
2525 if (!bitmap_bit_p (live, r)
2526 && !bitmap_bit_p (artificial_uses, r))
2528 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
2529 #ifdef REG_DEAD_DEBUGGING
2530 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2531 #endif
2533 bitmap_set_bit (do_not_gen, r);
2535 return old;
2539 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2540 arguments. Return true if the register value described by MWS's
2541 mw_reg is known to be completely dead, and if mw_reg can therefore
2542 be used in a REG_DEAD note. */
2544 static bool
2545 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2546 bitmap live, bitmap artificial_uses,
2547 bitmap do_not_gen)
2549 unsigned int r;
2551 /* If MWS describes a partial reference, create REG_DEAD notes for
2552 individual hard registers. */
2553 if (mws->flags & DF_REF_PARTIAL)
2554 return false;
2556 /* Likewise if some part of the register is not dead. */
2557 for (r = mws->start_regno; r <= mws->end_regno; r++)
2558 if (bitmap_bit_p (live, r)
2559 || bitmap_bit_p (artificial_uses, r)
2560 || bitmap_bit_p (do_not_gen, r))
2561 return false;
2563 gcc_assert (REG_P (mws->mw_reg));
2564 return true;
2567 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2568 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2569 from being set if the instruction both reads and writes the
2570 register. */
2572 static rtx
2573 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2574 bitmap live, bitmap do_not_gen,
2575 bitmap artificial_uses)
2577 unsigned int r;
2579 #ifdef REG_DEAD_DEBUGGING
2580 if (dump_file)
2582 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2583 mws->start_regno, mws->end_regno);
2584 df_print_regset (dump_file, do_not_gen);
2585 fprintf (dump_file, " live =");
2586 df_print_regset (dump_file, live);
2587 fprintf (dump_file, " artificial uses =");
2588 df_print_regset (dump_file, artificial_uses);
2590 #endif
2592 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2594 /* Add a dead note for the entire multi word register. */
2595 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
2596 #ifdef REG_DEAD_DEBUGGING
2597 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2598 #endif
2600 else
2602 for (r = mws->start_regno; r <= mws->end_regno; r++)
2603 if (!bitmap_bit_p (live, r)
2604 && !bitmap_bit_p (artificial_uses, r)
2605 && !bitmap_bit_p (do_not_gen, r))
2607 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
2608 #ifdef REG_DEAD_DEBUGGING
2609 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2610 #endif
2613 return old;
2617 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
2618 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
2620 static rtx
2621 df_create_unused_note (rtx insn, rtx old, struct df_ref *def,
2622 bitmap live, bitmap artificial_uses)
2624 unsigned int dregno = DF_REF_REGNO (def);
2626 #ifdef REG_DEAD_DEBUGGING
2627 if (dump_file)
2629 fprintf (dump_file, " regular looking at def ");
2630 df_ref_debug (def, dump_file);
2632 #endif
2634 if (!(bitmap_bit_p (live, dregno)
2635 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
2636 || bitmap_bit_p (artificial_uses, dregno)
2637 || df_ignore_stack_reg (dregno)))
2639 rtx reg = (DF_REF_LOC (def))
2640 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
2641 old = df_set_note (REG_UNUSED, insn, old, reg);
2642 #ifdef REG_DEAD_DEBUGGING
2643 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
2644 #endif
2647 return old;
2651 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
2652 info: lifetime, bb, and number of defs and uses for basic block
2653 BB. The three bitvectors are scratch regs used here. */
2655 static void
2656 df_note_bb_compute (unsigned int bb_index,
2657 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
2659 basic_block bb = BASIC_BLOCK (bb_index);
2660 rtx insn;
2661 struct df_ref **def_rec;
2662 struct df_ref **use_rec;
2664 bitmap_copy (live, df_get_live_out (bb));
2665 bitmap_clear (artificial_uses);
2667 #ifdef REG_DEAD_DEBUGGING
2668 if (dump_file)
2670 fprintf (dump_file, "live at bottom ");
2671 df_print_regset (dump_file, live);
2673 #endif
2675 /* Process the artificial defs and uses at the bottom of the block
2676 to begin processing. */
2677 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2679 struct df_ref *def = *def_rec;
2680 #ifdef REG_DEAD_DEBUGGING
2681 if (dump_file)
2682 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
2683 #endif
2685 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2686 bitmap_clear_bit (live, DF_REF_REGNO (def));
2689 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2691 struct df_ref *use = *use_rec;
2692 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2694 unsigned int regno = DF_REF_REGNO (use);
2695 bitmap_set_bit (live, regno);
2697 /* Notes are not generated for any of the artificial registers
2698 at the bottom of the block. */
2699 bitmap_set_bit (artificial_uses, regno);
2703 #ifdef REG_DEAD_DEBUGGING
2704 if (dump_file)
2706 fprintf (dump_file, "live before artificials out ");
2707 df_print_regset (dump_file, live);
2709 #endif
2711 FOR_BB_INSNS_REVERSE (bb, insn)
2713 unsigned int uid = INSN_UID (insn);
2714 struct df_mw_hardreg **mws_rec;
2715 rtx old_dead_notes;
2716 rtx old_unused_notes;
2718 if (!INSN_P (insn))
2719 continue;
2721 bitmap_clear (do_not_gen);
2722 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
2724 /* Process the defs. */
2725 if (CALL_P (insn))
2727 #ifdef REG_DEAD_DEBUGGING
2728 if (dump_file)
2730 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
2731 df_print_regset (dump_file, live);
2733 #endif
2734 /* We only care about real sets for calls. Clobbers cannot
2735 be depended on to really die. */
2736 mws_rec = DF_INSN_UID_MWS (uid);
2737 while (*mws_rec)
2739 struct df_mw_hardreg *mws = *mws_rec;
2740 if ((mws->type == DF_REF_REG_DEF)
2741 && !df_ignore_stack_reg (mws->start_regno))
2742 old_unused_notes
2743 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2744 mws, live, do_not_gen,
2745 artificial_uses);
2746 mws_rec++;
2749 /* All of the defs except the return value are some sort of
2750 clobber. This code is for the return. */
2751 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2753 struct df_ref *def = *def_rec;
2754 unsigned int dregno = DF_REF_REGNO (def);
2755 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2757 old_unused_notes
2758 = df_create_unused_note (insn, old_unused_notes,
2759 def, live, artificial_uses);
2760 bitmap_set_bit (do_not_gen, dregno);
2763 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2764 bitmap_clear_bit (live, dregno);
2767 else
2769 /* Regular insn. */
2770 mws_rec = DF_INSN_UID_MWS (uid);
2771 while (*mws_rec)
2773 struct df_mw_hardreg *mws = *mws_rec;
2774 if (mws->type == DF_REF_REG_DEF)
2775 old_unused_notes
2776 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2777 mws, live, do_not_gen,
2778 artificial_uses);
2779 mws_rec++;
2782 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2784 struct df_ref *def = *def_rec;
2785 unsigned int dregno = DF_REF_REGNO (def);
2786 old_unused_notes
2787 = df_create_unused_note (insn, old_unused_notes,
2788 def, live, artificial_uses);
2790 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2791 bitmap_set_bit (do_not_gen, dregno);
2793 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2794 bitmap_clear_bit (live, dregno);
2798 /* Process the uses. */
2799 mws_rec = DF_INSN_UID_MWS (uid);
2800 while (*mws_rec)
2802 struct df_mw_hardreg *mws = *mws_rec;
2803 if ((mws->type != DF_REF_REG_DEF)
2804 && !df_ignore_stack_reg (mws->start_regno))
2805 old_dead_notes
2806 = df_set_dead_notes_for_mw (insn, old_dead_notes,
2807 mws, live, do_not_gen,
2808 artificial_uses);
2809 mws_rec++;
2812 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2814 struct df_ref *use = *use_rec;
2815 unsigned int uregno = DF_REF_REGNO (use);
2817 #ifdef REG_DEAD_DEBUGGING
2818 if (dump_file)
2820 fprintf (dump_file, " regular looking at use ");
2821 df_ref_debug (use, dump_file);
2823 #endif
2824 if (!bitmap_bit_p (live, uregno))
2826 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
2827 && (!bitmap_bit_p (do_not_gen, uregno))
2828 && (!bitmap_bit_p (artificial_uses, uregno))
2829 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
2830 && (!df_ignore_stack_reg (uregno)))
2832 rtx reg = (DF_REF_LOC (use))
2833 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
2834 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
2836 #ifdef REG_DEAD_DEBUGGING
2837 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
2838 #endif
2840 /* This register is now live. */
2841 bitmap_set_bit (live, uregno);
2845 while (old_unused_notes)
2847 rtx next = XEXP (old_unused_notes, 1);
2848 free_EXPR_LIST_node (old_unused_notes);
2849 old_unused_notes = next;
2851 while (old_dead_notes)
2853 rtx next = XEXP (old_dead_notes, 1);
2854 free_EXPR_LIST_node (old_dead_notes);
2855 old_dead_notes = next;
2861 /* Compute register info: lifetime, bb, and number of defs and uses. */
2862 static void
2863 df_note_compute (bitmap all_blocks)
2865 unsigned int bb_index;
2866 bitmap_iterator bi;
2867 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
2868 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
2869 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
2871 #ifdef REG_DEAD_DEBUGGING
2872 if (dump_file)
2873 print_rtl_with_bb (dump_file, get_insns());
2874 #endif
2876 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2878 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
2881 BITMAP_FREE (live);
2882 BITMAP_FREE (do_not_gen);
2883 BITMAP_FREE (artificial_uses);
2887 /* Free all storage associated with the problem. */
2889 static void
2890 df_note_free (void)
2892 free (df_note);
2896 /* All of the information associated every instance of the problem. */
2898 static struct df_problem problem_NOTE =
2900 DF_NOTE, /* Problem id. */
2901 DF_NONE, /* Direction. */
2902 df_note_alloc, /* Allocate the problem specific data. */
2903 NULL, /* Reset global information. */
2904 NULL, /* Free basic block info. */
2905 df_note_compute, /* Local compute function. */
2906 NULL, /* Init the solution specific data. */
2907 NULL, /* Iterative solver. */
2908 NULL, /* Confluence operator 0. */
2909 NULL, /* Confluence operator n. */
2910 NULL, /* Transfer function. */
2911 NULL, /* Finalize function. */
2912 df_note_free, /* Free all of the problem information. */
2913 df_note_free, /* Remove this problem from the stack of dataflow problems. */
2914 NULL, /* Debugging. */
2915 NULL, /* Debugging start block. */
2916 NULL, /* Debugging end block. */
2917 NULL, /* Incremental solution verify start. */
2918 NULL, /* Incremental solution verify end. */
2920 /* Technically this is only dependent on the live registers problem
2921 but it will produce information if built one of uninitialized
2922 register problems (UR, UREC) is also run. */
2923 &problem_LR, /* Dependent problem. */
2924 TV_DF_NOTE, /* Timing variable. */
2925 false /* Reset blocks on dropping out of blocks_to_analyze. */
2929 /* Create a new DATAFLOW instance and add it to an existing instance
2930 of DF. The returned structure is what is used to get at the
2931 solution. */
2933 void
2934 df_note_add_problem (void)
2936 df_add_problem (&problem_NOTE);
2942 /*----------------------------------------------------------------------------
2943 Functions for simulating the effects of single insns.
2945 You can either simulate in the forwards direction, starting from
2946 the top of a block or the backwards direction from the end of the
2947 block. The main difference is that if you go forwards, the uses
2948 are examined first then the defs, and if you go backwards, the defs
2949 are examined first then the uses.
2951 If you start at the top of the block, use one of DF_LIVE_IN or
2952 DF_LR_IN. If you start at the bottom of the block use one of
2953 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
2954 THEY WILL BE DESTROYED.
2956 ----------------------------------------------------------------------------*/
2959 /* Find the set of DEFs for INSN. */
2961 void
2962 df_simulate_find_defs (rtx insn, bitmap defs)
2964 struct df_ref **def_rec;
2965 unsigned int uid = INSN_UID (insn);
2967 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2969 struct df_ref *def = *def_rec;
2970 /* If the def is to only part of the reg, it does
2971 not kill the other defs that reach here. */
2972 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2973 bitmap_set_bit (defs, DF_REF_REGNO (def));
2978 /* Simulate the effects of the defs of INSN on LIVE. */
2980 void
2981 df_simulate_defs (rtx insn, bitmap live)
2983 struct df_ref **def_rec;
2984 unsigned int uid = INSN_UID (insn);
2986 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2988 struct df_ref *def = *def_rec;
2989 unsigned int dregno = DF_REF_REGNO (def);
2991 /* If the def is to only part of the reg, it does
2992 not kill the other defs that reach here. */
2993 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2994 bitmap_clear_bit (live, dregno);
2999 /* Simulate the effects of the uses of INSN on LIVE. */
3001 void
3002 df_simulate_uses (rtx insn, bitmap live)
3004 struct df_ref **use_rec;
3005 unsigned int uid = INSN_UID (insn);
3007 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3009 struct df_ref *use = *use_rec;
3010 /* Add use to set of uses in this BB. */
3011 bitmap_set_bit (live, DF_REF_REGNO (use));
3016 /* Add back the always live regs in BB to LIVE. */
3018 static inline void
3019 df_simulate_fixup_sets (basic_block bb, bitmap live)
3021 /* These regs are considered always live so if they end up dying
3022 because of some def, we need to bring the back again. */
3023 if (bb_has_eh_pred (bb))
3024 bitmap_ior_into (live, df->eh_block_artificial_uses);
3025 else
3026 bitmap_ior_into (live, df->regular_block_artificial_uses);
3030 /* Apply the artificial uses and defs at the top of BB in a forwards
3031 direction. */
3033 void
3034 df_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
3036 struct df_ref **def_rec;
3037 struct df_ref **use_rec;
3038 int bb_index = bb->index;
3040 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3042 struct df_ref *use = *use_rec;
3043 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3044 bitmap_set_bit (live, DF_REF_REGNO (use));
3047 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3049 struct df_ref *def = *def_rec;
3050 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3051 bitmap_clear_bit (live, DF_REF_REGNO (def));
3056 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3058 void
3059 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3061 if (! INSN_P (insn))
3062 return;
3064 df_simulate_uses (insn, live);
3065 df_simulate_defs (insn, live);
3066 df_simulate_fixup_sets (bb, live);
3070 /* Apply the artificial uses and defs at the end of BB in a backwards
3071 direction. */
3073 void
3074 df_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3076 struct df_ref **def_rec;
3077 struct df_ref **use_rec;
3078 int bb_index = bb->index;
3080 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3082 struct df_ref *def = *def_rec;
3083 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3084 bitmap_clear_bit (live, DF_REF_REGNO (def));
3087 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3089 struct df_ref *use = *use_rec;
3090 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3091 bitmap_set_bit (live, DF_REF_REGNO (use));
3096 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3098 void
3099 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3101 if (! INSN_P (insn))
3102 return;
3104 df_simulate_defs (insn, live);
3105 df_simulate_uses (insn, live);
3106 df_simulate_fixup_sets (bb, live);