2008-01-31 Marc Gauthier <marc@tensilica.com>
[official-gcc.git] / gcc / df-problems.c
blob46aa9e03f4c07df2ce0ae5d72b9408eb4e13ae29
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_FAKE)
486 return;
488 if (e->flags & EDGE_EH)
490 struct df_rd_problem_data *problem_data
491 = (struct df_rd_problem_data *) df_rd->problem_data;
492 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
493 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
494 bitmap_iterator bi;
495 unsigned int regno;
496 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
498 bitmap_copy (tmp, op2);
499 bitmap_and_compl_into (tmp, dense_invalidated);
501 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
503 bitmap_clear_range (tmp,
504 DF_DEFS_BEGIN (regno),
505 DF_DEFS_COUNT (regno));
507 bitmap_ior_into (op1, tmp);
508 BITMAP_FREE (tmp);
510 else
511 bitmap_ior_into (op1, op2);
515 /* Transfer function. */
517 static bool
518 df_rd_transfer_function (int bb_index)
520 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
521 unsigned int regno;
522 bitmap_iterator bi;
523 bitmap in = bb_info->in;
524 bitmap out = bb_info->out;
525 bitmap gen = bb_info->gen;
526 bitmap kill = bb_info->kill;
527 bitmap sparse_kill = bb_info->sparse_kill;
529 if (bitmap_empty_p (sparse_kill))
530 return bitmap_ior_and_compl (out, gen, in, kill);
531 else
533 struct df_rd_problem_data *problem_data;
534 bool changed = false;
535 bitmap tmp;
537 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
538 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
539 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
540 tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
542 bitmap_copy (tmp, in);
543 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
545 bitmap_clear_range (tmp,
546 DF_DEFS_BEGIN (regno),
547 DF_DEFS_COUNT (regno));
549 bitmap_and_compl_into (tmp, kill);
550 bitmap_ior_into (tmp, gen);
551 changed = !bitmap_equal_p (tmp, out);
552 if (changed)
554 BITMAP_FREE (out);
555 bb_info->out = tmp;
557 else
558 BITMAP_FREE (tmp);
559 return changed;
564 /* Free all storage associated with the problem. */
566 static void
567 df_rd_free (void)
569 unsigned int i;
570 struct df_rd_problem_data *problem_data
571 = (struct df_rd_problem_data *) df_rd->problem_data;
573 if (problem_data)
575 for (i = 0; i < df_rd->block_info_size; i++)
577 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (i);
578 if (bb_info)
580 BITMAP_FREE (bb_info->kill);
581 BITMAP_FREE (bb_info->sparse_kill);
582 BITMAP_FREE (bb_info->gen);
583 BITMAP_FREE (bb_info->in);
584 BITMAP_FREE (bb_info->out);
588 free_alloc_pool (df_rd->block_pool);
589 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
590 BITMAP_FREE (problem_data->dense_invalidated_by_call);
591 bitmap_obstack_release (&problem_data->rd_bitmaps);
593 df_rd->block_info_size = 0;
594 free (df_rd->block_info);
595 free (df_rd->problem_data);
597 free (df_rd);
601 /* Debugging info. */
603 static void
604 df_rd_start_dump (FILE *file)
606 struct df_rd_problem_data *problem_data
607 = (struct df_rd_problem_data *) df_rd->problem_data;
608 unsigned int m = DF_REG_SIZE(df);
609 unsigned int regno;
611 if (!df_rd->block_info)
612 return;
614 fprintf (file, ";; Reaching defs:\n\n");
616 fprintf (file, " sparse invalidated \t");
617 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
618 fprintf (file, " dense invalidated \t");
619 dump_bitmap (file, problem_data->dense_invalidated_by_call);
621 for (regno = 0; regno < m; regno++)
622 if (DF_DEFS_COUNT (regno))
623 fprintf (file, "%d[%d,%d] ", regno,
624 DF_DEFS_BEGIN (regno),
625 DF_DEFS_COUNT (regno));
626 fprintf (file, "\n");
631 /* Debugging info at top of bb. */
633 static void
634 df_rd_top_dump (basic_block bb, FILE *file)
636 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
637 if (!bb_info || !bb_info->in)
638 return;
640 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
641 dump_bitmap (file, bb_info->in);
642 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
643 dump_bitmap (file, bb_info->gen);
644 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
645 dump_bitmap (file, bb_info->kill);
649 /* Debugging info at top of bb. */
651 static void
652 df_rd_bottom_dump (basic_block bb, FILE *file)
654 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
655 if (!bb_info || !bb_info->out)
656 return;
658 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
659 dump_bitmap (file, bb_info->out);
662 /* All of the information associated with every instance of the problem. */
664 static struct df_problem problem_RD =
666 DF_RD, /* Problem id. */
667 DF_FORWARD, /* Direction. */
668 df_rd_alloc, /* Allocate the problem specific data. */
669 NULL, /* Reset global information. */
670 df_rd_free_bb_info, /* Free basic block info. */
671 df_rd_local_compute, /* Local compute function. */
672 df_rd_init_solution, /* Init the solution specific data. */
673 df_worklist_dataflow, /* Worklist solver. */
674 NULL, /* Confluence operator 0. */
675 df_rd_confluence_n, /* Confluence operator n. */
676 df_rd_transfer_function, /* Transfer function. */
677 NULL, /* Finalize function. */
678 df_rd_free, /* Free all of the problem information. */
679 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
680 df_rd_start_dump, /* Debugging. */
681 df_rd_top_dump, /* Debugging start block. */
682 df_rd_bottom_dump, /* Debugging end block. */
683 NULL, /* Incremental solution verify start. */
684 NULL, /* Incremental solution verify end. */
685 NULL, /* Dependent problem. */
686 TV_DF_RD, /* Timing variable. */
687 true /* Reset blocks on dropping out of blocks_to_analyze. */
692 /* Create a new DATAFLOW instance and add it to an existing instance
693 of DF. The returned structure is what is used to get at the
694 solution. */
696 void
697 df_rd_add_problem (void)
699 df_add_problem (&problem_RD);
704 /*----------------------------------------------------------------------------
705 LIVE REGISTERS
707 Find the locations in the function where any use of a pseudo can
708 reach in the backwards direction. In and out bitvectors are built
709 for each basic block. The regnum is used to index into these sets.
710 See df.h for details.
711 ----------------------------------------------------------------------------*/
713 /* Private data used to verify the solution for this problem. */
714 struct df_lr_problem_data
716 bitmap *in;
717 bitmap *out;
721 /* Set basic block info. */
723 static void
724 df_lr_set_bb_info (unsigned int index,
725 struct df_lr_bb_info *bb_info)
727 gcc_assert (df_lr);
728 gcc_assert (index < df_lr->block_info_size);
729 df_lr->block_info[index] = bb_info;
733 /* Free basic block info. */
735 static void
736 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
737 void *vbb_info)
739 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
740 if (bb_info)
742 BITMAP_FREE (bb_info->use);
743 BITMAP_FREE (bb_info->def);
744 BITMAP_FREE (bb_info->in);
745 BITMAP_FREE (bb_info->out);
746 pool_free (df_lr->block_pool, bb_info);
751 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
752 not touched unless the block is new. */
754 static void
755 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
757 unsigned int bb_index;
758 bitmap_iterator bi;
760 if (!df_lr->block_pool)
761 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
762 sizeof (struct df_lr_bb_info), 50);
764 df_grow_bb_info (df_lr);
766 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
768 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
769 if (bb_info)
771 bitmap_clear (bb_info->def);
772 bitmap_clear (bb_info->use);
774 else
776 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
777 df_lr_set_bb_info (bb_index, bb_info);
778 bb_info->use = BITMAP_ALLOC (NULL);
779 bb_info->def = BITMAP_ALLOC (NULL);
780 bb_info->in = BITMAP_ALLOC (NULL);
781 bb_info->out = BITMAP_ALLOC (NULL);
785 df_lr->optional_p = false;
789 /* Reset the global solution for recalculation. */
791 static void
792 df_lr_reset (bitmap all_blocks)
794 unsigned int bb_index;
795 bitmap_iterator bi;
797 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
799 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
800 gcc_assert (bb_info);
801 bitmap_clear (bb_info->in);
802 bitmap_clear (bb_info->out);
807 /* Compute local live register info for basic block BB. */
809 static void
810 df_lr_bb_local_compute (unsigned int bb_index)
812 basic_block bb = BASIC_BLOCK (bb_index);
813 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
814 rtx insn;
815 struct df_ref **def_rec;
816 struct df_ref **use_rec;
818 /* Process the registers set in an exception handler. */
819 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
821 struct df_ref *def = *def_rec;
822 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
824 unsigned int dregno = DF_REF_REGNO (def);
825 bitmap_set_bit (bb_info->def, dregno);
826 bitmap_clear_bit (bb_info->use, dregno);
830 /* Process the hardware registers that are always live. */
831 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
833 struct df_ref *use = *use_rec;
834 /* Add use to set of uses in this BB. */
835 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
836 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
839 FOR_BB_INSNS_REVERSE (bb, insn)
841 unsigned int uid = INSN_UID (insn);
843 if (!INSN_P (insn))
844 continue;
846 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
848 struct df_ref *def = *def_rec;
849 /* If the def is to only part of the reg, it does
850 not kill the other defs that reach here. */
851 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
853 unsigned int dregno = DF_REF_REGNO (def);
854 bitmap_set_bit (bb_info->def, dregno);
855 bitmap_clear_bit (bb_info->use, dregno);
859 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
861 struct df_ref *use = *use_rec;
862 /* Add use to set of uses in this BB. */
863 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
867 /* Process the registers set in an exception handler or the hard
868 frame pointer if this block is the target of a non local
869 goto. */
870 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
872 struct df_ref *def = *def_rec;
873 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
875 unsigned int dregno = DF_REF_REGNO (def);
876 bitmap_set_bit (bb_info->def, dregno);
877 bitmap_clear_bit (bb_info->use, dregno);
881 #ifdef EH_USES
882 /* Process the uses that are live into an exception handler. */
883 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
885 struct df_ref *use = *use_rec;
886 /* Add use to set of uses in this BB. */
887 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
888 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
890 #endif
892 /* If the df_live problem is not defined, such as at -O0 and -O1, we
893 still need to keep the luids up to date. This is normally done
894 in the df_live problem since this problem has a forwards
895 scan. */
896 if (!df_live)
897 df_recompute_luids (bb);
901 /* Compute local live register info for each basic block within BLOCKS. */
903 static void
904 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
906 unsigned int bb_index;
907 bitmap_iterator bi;
909 bitmap_clear (df->hardware_regs_used);
911 /* The all-important stack pointer must always be live. */
912 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
914 /* Before reload, there are a few registers that must be forced
915 live everywhere -- which might not already be the case for
916 blocks within infinite loops. */
917 if (!reload_completed)
919 /* Any reference to any pseudo before reload is a potential
920 reference of the frame pointer. */
921 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
923 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
924 /* Pseudos with argument area equivalences may require
925 reloading via the argument pointer. */
926 if (fixed_regs[ARG_POINTER_REGNUM])
927 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
928 #endif
930 /* Any constant, or pseudo with constant equivalences, may
931 require reloading from memory using the pic register. */
932 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
933 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
934 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
937 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
939 if (bb_index == EXIT_BLOCK)
941 /* The exit block is special for this problem and its bits are
942 computed from thin air. */
943 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
944 bitmap_copy (bb_info->use, df->exit_block_uses);
946 else
947 df_lr_bb_local_compute (bb_index);
950 bitmap_clear (df_lr->out_of_date_transfer_functions);
954 /* Initialize the solution vectors. */
956 static void
957 df_lr_init (bitmap all_blocks)
959 unsigned int bb_index;
960 bitmap_iterator bi;
962 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
964 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
965 bitmap_copy (bb_info->in, bb_info->use);
966 bitmap_clear (bb_info->out);
971 /* Confluence function that processes infinite loops. This might be a
972 noreturn function that throws. And even if it isn't, getting the
973 unwind info right helps debugging. */
974 static void
975 df_lr_confluence_0 (basic_block bb)
977 bitmap op1 = df_lr_get_bb_info (bb->index)->out;
978 if (bb != EXIT_BLOCK_PTR)
979 bitmap_copy (op1, df->hardware_regs_used);
983 /* Confluence function that ignores fake edges. */
985 static void
986 df_lr_confluence_n (edge e)
988 bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
989 bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
991 /* Call-clobbered registers die across exception and call edges. */
992 /* ??? Abnormal call edges ignored for the moment, as this gets
993 confused by sibling call edges, which crashes reg-stack. */
994 if (e->flags & EDGE_EH)
995 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
996 else
997 bitmap_ior_into (op1, op2);
999 bitmap_ior_into (op1, df->hardware_regs_used);
1003 /* Transfer function. */
1005 static bool
1006 df_lr_transfer_function (int bb_index)
1008 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1009 bitmap in = bb_info->in;
1010 bitmap out = bb_info->out;
1011 bitmap use = bb_info->use;
1012 bitmap def = bb_info->def;
1014 return bitmap_ior_and_compl (in, use, out, def);
1018 /* Run the fast dce as a side effect of building LR. */
1020 static void
1021 df_lr_finalize (bitmap all_blocks ATTRIBUTE_UNUSED)
1023 if (df->changeable_flags & DF_LR_RUN_DCE)
1025 run_fast_df_dce ();
1026 if (df_lr->problem_data && df_lr->solutions_dirty)
1028 /* If we are here, then it is because we are both verifying
1029 the solution and the dce changed the function. In that case
1030 the verification info built will be wrong. So we leave the
1031 dirty flag true so that the verifier will skip the checking
1032 part and just clean up.*/
1033 df_lr->solutions_dirty = true;
1035 else
1036 df_lr->solutions_dirty = false;
1038 else
1039 df_lr->solutions_dirty = false;
1043 /* Free all storage associated with the problem. */
1045 static void
1046 df_lr_free (void)
1048 if (df_lr->block_info)
1050 unsigned int i;
1051 for (i = 0; i < df_lr->block_info_size; i++)
1053 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
1054 if (bb_info)
1056 BITMAP_FREE (bb_info->use);
1057 BITMAP_FREE (bb_info->def);
1058 BITMAP_FREE (bb_info->in);
1059 BITMAP_FREE (bb_info->out);
1062 free_alloc_pool (df_lr->block_pool);
1064 df_lr->block_info_size = 0;
1065 free (df_lr->block_info);
1068 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1069 free (df_lr);
1073 /* Debugging info at top of bb. */
1075 static void
1076 df_lr_top_dump (basic_block bb, FILE *file)
1078 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1079 struct df_lr_problem_data *problem_data;
1080 if (!bb_info || !bb_info->in)
1081 return;
1083 fprintf (file, ";; lr in \t");
1084 df_print_regset (file, bb_info->in);
1085 if (df_lr->problem_data)
1087 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1088 fprintf (file, ";; old in \t");
1089 df_print_regset (file, problem_data->in[bb->index]);
1091 fprintf (file, ";; lr use \t");
1092 df_print_regset (file, bb_info->use);
1093 fprintf (file, ";; lr def \t");
1094 df_print_regset (file, bb_info->def);
1098 /* Debugging info at bottom of bb. */
1100 static void
1101 df_lr_bottom_dump (basic_block bb, FILE *file)
1103 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1104 struct df_lr_problem_data *problem_data;
1105 if (!bb_info || !bb_info->out)
1106 return;
1108 fprintf (file, ";; lr out \t");
1109 df_print_regset (file, bb_info->out);
1110 if (df_lr->problem_data)
1112 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1113 fprintf (file, ";; old out \t");
1114 df_print_regset (file, problem_data->out[bb->index]);
1119 /* Build the datastructure to verify that the solution to the dataflow
1120 equations is not dirty. */
1122 static void
1123 df_lr_verify_solution_start (void)
1125 basic_block bb;
1126 struct df_lr_problem_data *problem_data;
1127 if (df_lr->solutions_dirty)
1129 df_lr->problem_data = NULL;
1130 return;
1133 /* Set it true so that the solution is recomputed. */
1134 df_lr->solutions_dirty = true;
1136 problem_data = XNEW (struct df_lr_problem_data);
1137 df_lr->problem_data = problem_data;
1138 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1139 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1141 FOR_ALL_BB (bb)
1143 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1144 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1145 bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
1146 bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
1151 /* Compare the saved datastructure and the new solution to the dataflow
1152 equations. */
1154 static void
1155 df_lr_verify_solution_end (void)
1157 struct df_lr_problem_data *problem_data;
1158 basic_block bb;
1160 if (df_lr->problem_data == NULL)
1161 return;
1163 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1165 if (df_lr->solutions_dirty)
1166 /* Do not check if the solution is still dirty. See the comment
1167 in df_lr_finalize for details. */
1168 df_lr->solutions_dirty = false;
1169 else
1170 FOR_ALL_BB (bb)
1172 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
1173 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
1175 /*df_dump (stderr);*/
1176 gcc_unreachable ();
1180 /* Cannot delete them immediately because you may want to dump them
1181 if the comparison fails. */
1182 FOR_ALL_BB (bb)
1184 BITMAP_FREE (problem_data->in[bb->index]);
1185 BITMAP_FREE (problem_data->out[bb->index]);
1188 free (problem_data->in);
1189 free (problem_data->out);
1190 free (problem_data);
1191 df_lr->problem_data = NULL;
1195 /* All of the information associated with every instance of the problem. */
1197 static struct df_problem problem_LR =
1199 DF_LR, /* Problem id. */
1200 DF_BACKWARD, /* Direction. */
1201 df_lr_alloc, /* Allocate the problem specific data. */
1202 df_lr_reset, /* Reset global information. */
1203 df_lr_free_bb_info, /* Free basic block info. */
1204 df_lr_local_compute, /* Local compute function. */
1205 df_lr_init, /* Init the solution specific data. */
1206 df_worklist_dataflow, /* Worklist solver. */
1207 df_lr_confluence_0, /* Confluence operator 0. */
1208 df_lr_confluence_n, /* Confluence operator n. */
1209 df_lr_transfer_function, /* Transfer function. */
1210 df_lr_finalize, /* Finalize function. */
1211 df_lr_free, /* Free all of the problem information. */
1212 NULL, /* Remove this problem from the stack of dataflow problems. */
1213 NULL, /* Debugging. */
1214 df_lr_top_dump, /* Debugging start block. */
1215 df_lr_bottom_dump, /* Debugging end block. */
1216 df_lr_verify_solution_start,/* Incremental solution verify start. */
1217 df_lr_verify_solution_end, /* Incremental solution verify end. */
1218 NULL, /* Dependent problem. */
1219 TV_DF_LR, /* Timing variable. */
1220 false /* Reset blocks on dropping out of blocks_to_analyze. */
1224 /* Create a new DATAFLOW instance and add it to an existing instance
1225 of DF. The returned structure is what is used to get at the
1226 solution. */
1228 void
1229 df_lr_add_problem (void)
1231 df_add_problem (&problem_LR);
1232 /* These will be initialized when df_scan_blocks processes each
1233 block. */
1234 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1238 /* Verify that all of the lr related info is consistent and
1239 correct. */
1241 void
1242 df_lr_verify_transfer_functions (void)
1244 basic_block bb;
1245 bitmap saved_def;
1246 bitmap saved_use;
1247 bitmap saved_adef;
1248 bitmap saved_ause;
1249 bitmap all_blocks;
1251 if (!df)
1252 return;
1254 saved_def = BITMAP_ALLOC (NULL);
1255 saved_use = BITMAP_ALLOC (NULL);
1256 saved_adef = BITMAP_ALLOC (NULL);
1257 saved_ause = BITMAP_ALLOC (NULL);
1258 all_blocks = BITMAP_ALLOC (NULL);
1260 FOR_ALL_BB (bb)
1262 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1263 bitmap_set_bit (all_blocks, bb->index);
1265 if (bb_info)
1267 /* Make a copy of the transfer functions and then compute
1268 new ones to see if the transfer functions have
1269 changed. */
1270 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1271 bb->index))
1273 bitmap_copy (saved_def, bb_info->def);
1274 bitmap_copy (saved_use, bb_info->use);
1275 bitmap_clear (bb_info->def);
1276 bitmap_clear (bb_info->use);
1278 df_lr_bb_local_compute (bb->index);
1279 gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
1280 gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
1283 else
1285 /* If we do not have basic block info, the block must be in
1286 the list of dirty blocks or else some one has added a
1287 block behind our backs. */
1288 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1289 bb->index));
1291 /* Make sure no one created a block without following
1292 procedures. */
1293 gcc_assert (df_scan_get_bb_info (bb->index));
1296 /* Make sure there are no dirty bits in blocks that have been deleted. */
1297 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1298 all_blocks));
1300 BITMAP_FREE (saved_def);
1301 BITMAP_FREE (saved_use);
1302 BITMAP_FREE (saved_adef);
1303 BITMAP_FREE (saved_ause);
1304 BITMAP_FREE (all_blocks);
1309 /*----------------------------------------------------------------------------
1310 LIVE AND MUST-INITIALIZED REGISTERS.
1312 This problem first computes the IN and OUT bitvectors for the
1313 must-initialized registers problems, which is a forward problem.
1314 It gives the set of registers for which we MUST have an available
1315 definition on any path from the entry block to the entry/exit of
1316 a basic block. Sets generate a definition, while clobbers kill
1317 a definition.
1319 In and out bitvectors are built for each basic block and are indexed by
1320 regnum (see df.h for details). In and out bitvectors in struct
1321 df_live_bb_info actually refers to the must-initialized problem;
1323 Then, the in and out sets for the LIVE problem itself are computed.
1324 These are the logical AND of the IN and OUT sets from the LR problem
1325 and the must-initialized problem.
1326 ----------------------------------------------------------------------------*/
1328 /* Private data used to verify the solution for this problem. */
1329 struct df_live_problem_data
1331 bitmap *in;
1332 bitmap *out;
1335 /* Scratch var used by transfer functions. This is used to implement
1336 an optimization to reduce the amount of space used to compute the
1337 combined lr and live analysis. */
1338 static bitmap df_live_scratch;
1340 /* Set basic block info. */
1342 static void
1343 df_live_set_bb_info (unsigned int index,
1344 struct df_live_bb_info *bb_info)
1346 gcc_assert (df_live);
1347 gcc_assert (index < df_live->block_info_size);
1348 df_live->block_info[index] = bb_info;
1352 /* Free basic block info. */
1354 static void
1355 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1356 void *vbb_info)
1358 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1359 if (bb_info)
1361 BITMAP_FREE (bb_info->gen);
1362 BITMAP_FREE (bb_info->kill);
1363 BITMAP_FREE (bb_info->in);
1364 BITMAP_FREE (bb_info->out);
1365 pool_free (df_live->block_pool, bb_info);
1370 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1371 not touched unless the block is new. */
1373 static void
1374 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1376 unsigned int bb_index;
1377 bitmap_iterator bi;
1379 if (!df_live->block_pool)
1380 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1381 sizeof (struct df_live_bb_info), 100);
1382 if (!df_live_scratch)
1383 df_live_scratch = BITMAP_ALLOC (NULL);
1385 df_grow_bb_info (df_live);
1387 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1389 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1390 if (bb_info)
1392 bitmap_clear (bb_info->kill);
1393 bitmap_clear (bb_info->gen);
1395 else
1397 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1398 df_live_set_bb_info (bb_index, bb_info);
1399 bb_info->kill = BITMAP_ALLOC (NULL);
1400 bb_info->gen = BITMAP_ALLOC (NULL);
1401 bb_info->in = BITMAP_ALLOC (NULL);
1402 bb_info->out = BITMAP_ALLOC (NULL);
1405 df_live->optional_p = (optimize <= 1);
1409 /* Reset the global solution for recalculation. */
1411 static void
1412 df_live_reset (bitmap all_blocks)
1414 unsigned int bb_index;
1415 bitmap_iterator bi;
1417 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1419 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1420 gcc_assert (bb_info);
1421 bitmap_clear (bb_info->in);
1422 bitmap_clear (bb_info->out);
1427 /* Compute local uninitialized register info for basic block BB. */
1429 static void
1430 df_live_bb_local_compute (unsigned int bb_index)
1432 basic_block bb = BASIC_BLOCK (bb_index);
1433 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1434 rtx insn;
1435 struct df_ref **def_rec;
1436 int luid = 0;
1438 FOR_BB_INSNS (bb, insn)
1440 unsigned int uid = INSN_UID (insn);
1441 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1443 /* Inserting labels does not always trigger the incremental
1444 rescanning. */
1445 if (!insn_info)
1447 gcc_assert (!INSN_P (insn));
1448 df_insn_create_insn_record (insn);
1451 DF_INSN_LUID (insn) = luid;
1452 if (!INSN_P (insn))
1453 continue;
1455 luid++;
1456 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1458 struct df_ref *def = *def_rec;
1459 unsigned int regno = DF_REF_REGNO (def);
1461 if (DF_REF_FLAGS_IS_SET (def,
1462 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1463 /* All partial or conditional def
1464 seen are included in the gen set. */
1465 bitmap_set_bit (bb_info->gen, regno);
1466 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1467 /* Only must clobbers for the entire reg destroy the
1468 value. */
1469 bitmap_set_bit (bb_info->kill, regno);
1470 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1471 bitmap_set_bit (bb_info->gen, regno);
1475 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1477 struct df_ref *def = *def_rec;
1478 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1483 /* Compute local uninitialized register info. */
1485 static void
1486 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1488 unsigned int bb_index;
1489 bitmap_iterator bi;
1491 df_grow_insn_info ();
1493 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1494 0, bb_index, bi)
1496 df_live_bb_local_compute (bb_index);
1499 bitmap_clear (df_live->out_of_date_transfer_functions);
1503 /* Initialize the solution vectors. */
1505 static void
1506 df_live_init (bitmap all_blocks)
1508 unsigned int bb_index;
1509 bitmap_iterator bi;
1511 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1513 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1514 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1516 /* No register may reach a location where it is not used. Thus
1517 we trim the rr result to the places where it is used. */
1518 bitmap_and (bb_info->out, bb_info->gen, bb_lr_info->out);
1519 bitmap_clear (bb_info->in);
1523 /* Forward confluence function that ignores fake edges. */
1525 static void
1526 df_live_confluence_n (edge e)
1528 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
1529 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
1531 if (e->flags & EDGE_FAKE)
1532 return;
1534 bitmap_ior_into (op1, op2);
1538 /* Transfer function for the forwards must-initialized problem. */
1540 static bool
1541 df_live_transfer_function (int bb_index)
1543 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1544 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1545 bitmap in = bb_info->in;
1546 bitmap out = bb_info->out;
1547 bitmap gen = bb_info->gen;
1548 bitmap kill = bb_info->kill;
1550 /* We need to use a scratch set here so that the value returned from
1551 this function invocation properly reflects if the sets changed in
1552 a significant way; i.e. not just because the lr set was anded
1553 in. */
1554 bitmap_and (df_live_scratch, gen, bb_lr_info->out);
1555 /* No register may reach a location where it is not used. Thus
1556 we trim the rr result to the places where it is used. */
1557 bitmap_and_into (in, bb_lr_info->in);
1559 return bitmap_ior_and_compl (out, df_live_scratch, in, kill);
1563 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1565 static void
1566 df_live_finalize (bitmap all_blocks)
1569 if (df_live->solutions_dirty)
1571 bitmap_iterator bi;
1572 unsigned int bb_index;
1574 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1576 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1577 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1579 /* No register may reach a location where it is not used. Thus
1580 we trim the rr result to the places where it is used. */
1581 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
1582 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
1585 df_live->solutions_dirty = false;
1590 /* Free all storage associated with the problem. */
1592 static void
1593 df_live_free (void)
1595 if (df_live->block_info)
1597 unsigned int i;
1599 for (i = 0; i < df_live->block_info_size; i++)
1601 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
1602 if (bb_info)
1604 BITMAP_FREE (bb_info->gen);
1605 BITMAP_FREE (bb_info->kill);
1606 BITMAP_FREE (bb_info->in);
1607 BITMAP_FREE (bb_info->out);
1611 free_alloc_pool (df_live->block_pool);
1612 df_live->block_info_size = 0;
1613 free (df_live->block_info);
1615 if (df_live_scratch)
1616 BITMAP_FREE (df_live_scratch);
1618 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1619 free (df_live);
1623 /* Debugging info at top of bb. */
1625 static void
1626 df_live_top_dump (basic_block bb, FILE *file)
1628 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1629 struct df_live_problem_data *problem_data;
1631 if (!bb_info || !bb_info->in)
1632 return;
1634 fprintf (file, ";; live in \t");
1635 df_print_regset (file, bb_info->in);
1636 if (df_live->problem_data)
1638 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1639 fprintf (file, ";; old in \t");
1640 df_print_regset (file, problem_data->in[bb->index]);
1642 fprintf (file, ";; live gen \t");
1643 df_print_regset (file, bb_info->gen);
1644 fprintf (file, ";; live kill\t");
1645 df_print_regset (file, bb_info->kill);
1649 /* Debugging info at bottom of bb. */
1651 static void
1652 df_live_bottom_dump (basic_block bb, FILE *file)
1654 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1655 struct df_live_problem_data *problem_data;
1657 if (!bb_info || !bb_info->out)
1658 return;
1660 fprintf (file, ";; live out \t");
1661 df_print_regset (file, bb_info->out);
1662 if (df_live->problem_data)
1664 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1665 fprintf (file, ";; old out \t");
1666 df_print_regset (file, problem_data->out[bb->index]);
1671 /* Build the datastructure to verify that the solution to the dataflow
1672 equations is not dirty. */
1674 static void
1675 df_live_verify_solution_start (void)
1677 basic_block bb;
1678 struct df_live_problem_data *problem_data;
1679 if (df_live->solutions_dirty)
1681 df_live->problem_data = NULL;
1682 return;
1685 /* Set it true so that the solution is recomputed. */
1686 df_live->solutions_dirty = true;
1688 problem_data = XNEW (struct df_live_problem_data);
1689 df_live->problem_data = problem_data;
1690 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1691 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1693 FOR_ALL_BB (bb)
1695 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1696 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1697 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
1698 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
1703 /* Compare the saved datastructure and the new solution to the dataflow
1704 equations. */
1706 static void
1707 df_live_verify_solution_end (void)
1709 struct df_live_problem_data *problem_data;
1710 basic_block bb;
1712 if (df_live->problem_data == NULL)
1713 return;
1715 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1717 FOR_ALL_BB (bb)
1719 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
1720 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1722 /*df_dump (stderr);*/
1723 gcc_unreachable ();
1727 /* Cannot delete them immediately because you may want to dump them
1728 if the comparison fails. */
1729 FOR_ALL_BB (bb)
1731 BITMAP_FREE (problem_data->in[bb->index]);
1732 BITMAP_FREE (problem_data->out[bb->index]);
1735 free (problem_data->in);
1736 free (problem_data->out);
1737 free (problem_data);
1738 df_live->problem_data = NULL;
1742 /* All of the information associated with every instance of the problem. */
1744 static struct df_problem problem_LIVE =
1746 DF_LIVE, /* Problem id. */
1747 DF_FORWARD, /* Direction. */
1748 df_live_alloc, /* Allocate the problem specific data. */
1749 df_live_reset, /* Reset global information. */
1750 df_live_free_bb_info, /* Free basic block info. */
1751 df_live_local_compute, /* Local compute function. */
1752 df_live_init, /* Init the solution specific data. */
1753 df_worklist_dataflow, /* Worklist solver. */
1754 NULL, /* Confluence operator 0. */
1755 df_live_confluence_n, /* Confluence operator n. */
1756 df_live_transfer_function, /* Transfer function. */
1757 df_live_finalize, /* Finalize function. */
1758 df_live_free, /* Free all of the problem information. */
1759 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1760 NULL, /* Debugging. */
1761 df_live_top_dump, /* Debugging start block. */
1762 df_live_bottom_dump, /* Debugging end block. */
1763 df_live_verify_solution_start,/* Incremental solution verify start. */
1764 df_live_verify_solution_end, /* Incremental solution verify end. */
1765 &problem_LR, /* Dependent problem. */
1766 TV_DF_LIVE, /* Timing variable. */
1767 false /* Reset blocks on dropping out of blocks_to_analyze. */
1771 /* Create a new DATAFLOW instance and add it to an existing instance
1772 of DF. The returned structure is what is used to get at the
1773 solution. */
1775 void
1776 df_live_add_problem (void)
1778 df_add_problem (&problem_LIVE);
1779 /* These will be initialized when df_scan_blocks processes each
1780 block. */
1781 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1785 /* Set all of the blocks as dirty. This needs to be done if this
1786 problem is added after all of the insns have been scanned. */
1788 void
1789 df_live_set_all_dirty (void)
1791 basic_block bb;
1792 FOR_ALL_BB (bb)
1793 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1794 bb->index);
1798 /* Verify that all of the lr related info is consistent and
1799 correct. */
1801 void
1802 df_live_verify_transfer_functions (void)
1804 basic_block bb;
1805 bitmap saved_gen;
1806 bitmap saved_kill;
1807 bitmap all_blocks;
1809 if (!df)
1810 return;
1812 saved_gen = BITMAP_ALLOC (NULL);
1813 saved_kill = BITMAP_ALLOC (NULL);
1814 all_blocks = BITMAP_ALLOC (NULL);
1816 df_grow_insn_info ();
1818 FOR_ALL_BB (bb)
1820 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1821 bitmap_set_bit (all_blocks, bb->index);
1823 if (bb_info)
1825 /* Make a copy of the transfer functions and then compute
1826 new ones to see if the transfer functions have
1827 changed. */
1828 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1829 bb->index))
1831 bitmap_copy (saved_gen, bb_info->gen);
1832 bitmap_copy (saved_kill, bb_info->kill);
1833 bitmap_clear (bb_info->gen);
1834 bitmap_clear (bb_info->kill);
1836 df_live_bb_local_compute (bb->index);
1837 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
1838 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
1841 else
1843 /* If we do not have basic block info, the block must be in
1844 the list of dirty blocks or else some one has added a
1845 block behind our backs. */
1846 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1847 bb->index));
1849 /* Make sure no one created a block without following
1850 procedures. */
1851 gcc_assert (df_scan_get_bb_info (bb->index));
1854 /* Make sure there are no dirty bits in blocks that have been deleted. */
1855 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1856 all_blocks));
1857 BITMAP_FREE (saved_gen);
1858 BITMAP_FREE (saved_kill);
1859 BITMAP_FREE (all_blocks);
1862 /*----------------------------------------------------------------------------
1863 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1865 Link either the defs to the uses and / or the uses to the defs.
1867 These problems are set up like the other dataflow problems so that
1868 they nicely fit into the framework. They are much simpler and only
1869 involve a single traversal of instructions and an examination of
1870 the reaching defs information (the dependent problem).
1871 ----------------------------------------------------------------------------*/
1873 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1875 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1877 struct df_link *
1878 df_chain_create (struct df_ref *src, struct df_ref *dst)
1880 struct df_link *head = DF_REF_CHAIN (src);
1881 struct df_link *link = pool_alloc (df_chain->block_pool);;
1883 DF_REF_CHAIN (src) = link;
1884 link->next = head;
1885 link->ref = dst;
1886 return link;
1890 /* Delete any du or ud chains that start at REF and point to
1891 TARGET. */
1892 static void
1893 df_chain_unlink_1 (struct df_ref *ref, struct df_ref *target)
1895 struct df_link *chain = DF_REF_CHAIN (ref);
1896 struct df_link *prev = NULL;
1898 while (chain)
1900 if (chain->ref == target)
1902 if (prev)
1903 prev->next = chain->next;
1904 else
1905 DF_REF_CHAIN (ref) = chain->next;
1906 pool_free (df_chain->block_pool, chain);
1907 return;
1909 prev = chain;
1910 chain = chain->next;
1915 /* Delete a du or ud chain that leave or point to REF. */
1917 void
1918 df_chain_unlink (struct df_ref *ref)
1920 struct df_link *chain = DF_REF_CHAIN (ref);
1921 while (chain)
1923 struct df_link *next = chain->next;
1924 /* Delete the other side if it exists. */
1925 df_chain_unlink_1 (chain->ref, ref);
1926 pool_free (df_chain->block_pool, chain);
1927 chain = next;
1929 DF_REF_CHAIN (ref) = NULL;
1933 /* Copy the du or ud chain starting at FROM_REF and attach it to
1934 TO_REF. */
1936 void
1937 df_chain_copy (struct df_ref *to_ref,
1938 struct df_link *from_ref)
1940 while (from_ref)
1942 df_chain_create (to_ref, from_ref->ref);
1943 from_ref = from_ref->next;
1948 /* Remove this problem from the stack of dataflow problems. */
1950 static void
1951 df_chain_remove_problem (void)
1953 bitmap_iterator bi;
1954 unsigned int bb_index;
1956 /* Wholesale destruction of the old chains. */
1957 if (df_chain->block_pool)
1958 free_alloc_pool (df_chain->block_pool);
1960 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1962 rtx insn;
1963 struct df_ref **def_rec;
1964 struct df_ref **use_rec;
1965 basic_block bb = BASIC_BLOCK (bb_index);
1967 if (df_chain_problem_p (DF_DU_CHAIN))
1968 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1969 DF_REF_CHAIN (*def_rec) = NULL;
1970 if (df_chain_problem_p (DF_UD_CHAIN))
1971 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1972 DF_REF_CHAIN (*use_rec) = NULL;
1974 FOR_BB_INSNS (bb, insn)
1976 unsigned int uid = INSN_UID (insn);
1978 if (INSN_P (insn))
1980 if (df_chain_problem_p (DF_DU_CHAIN))
1981 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1982 DF_REF_CHAIN (*def_rec) = NULL;
1983 if (df_chain_problem_p (DF_UD_CHAIN))
1985 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1986 DF_REF_CHAIN (*use_rec) = NULL;
1987 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
1988 DF_REF_CHAIN (*use_rec) = NULL;
1994 bitmap_clear (df_chain->out_of_date_transfer_functions);
1995 df_chain->block_pool = NULL;
1999 /* Remove the chain problem completely. */
2001 static void
2002 df_chain_fully_remove_problem (void)
2004 df_chain_remove_problem ();
2005 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2006 free (df_chain);
2010 /* Create def-use or use-def chains. */
2012 static void
2013 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2015 df_chain_remove_problem ();
2016 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2017 sizeof (struct df_link), 50);
2018 df_chain->optional_p = true;
2022 /* Reset all of the chains when the set of basic blocks changes. */
2024 static void
2025 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2027 df_chain_remove_problem ();
2031 /* Create the chains for a list of USEs. */
2033 static void
2034 df_chain_create_bb_process_use (bitmap local_rd,
2035 struct df_ref **use_rec,
2036 enum df_ref_flags top_flag)
2038 bitmap_iterator bi;
2039 unsigned int def_index;
2041 while (*use_rec)
2043 struct df_ref *use = *use_rec;
2044 unsigned int uregno = DF_REF_REGNO (use);
2045 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2046 || (uregno >= FIRST_PSEUDO_REGISTER))
2048 /* Do not want to go through this for an uninitialized var. */
2049 int count = DF_DEFS_COUNT (uregno);
2050 if (count)
2052 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2054 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2055 unsigned int last_index = first_index + count - 1;
2057 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2059 struct df_ref *def;
2060 if (def_index > last_index)
2061 break;
2063 def = DF_DEFS_GET (def_index);
2064 if (df_chain_problem_p (DF_DU_CHAIN))
2065 df_chain_create (def, use);
2066 if (df_chain_problem_p (DF_UD_CHAIN))
2067 df_chain_create (use, def);
2073 use_rec++;
2078 /* Create chains from reaching defs bitmaps for basic block BB. */
2080 static void
2081 df_chain_create_bb (unsigned int bb_index)
2083 basic_block bb = BASIC_BLOCK (bb_index);
2084 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2085 rtx insn;
2086 bitmap cpy = BITMAP_ALLOC (NULL);
2087 struct df_ref **def_rec;
2089 bitmap_copy (cpy, bb_info->in);
2090 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2092 /* Since we are going forwards, process the artificial uses first
2093 then the artificial defs second. */
2095 #ifdef EH_USES
2096 /* Create the chains for the artificial uses from the EH_USES at the
2097 beginning of the block. */
2099 /* Artificials are only hard regs. */
2100 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2101 df_chain_create_bb_process_use (cpy,
2102 df_get_artificial_uses (bb->index),
2103 DF_REF_AT_TOP);
2104 #endif
2106 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2108 struct df_ref *def = *def_rec;
2109 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2111 unsigned int dregno = DF_REF_REGNO (def);
2112 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2113 bitmap_clear_range (cpy,
2114 DF_DEFS_BEGIN (dregno),
2115 DF_DEFS_COUNT (dregno));
2116 bitmap_set_bit (cpy, DF_REF_ID (def));
2120 /* Process the regular instructions next. */
2121 FOR_BB_INSNS (bb, insn)
2123 struct df_ref **def_rec;
2124 unsigned int uid = INSN_UID (insn);
2126 if (!INSN_P (insn))
2127 continue;
2129 /* Now scan the uses and link them up with the defs that remain
2130 in the cpy vector. */
2132 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
2134 if (df->changeable_flags & DF_EQ_NOTES)
2135 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
2138 /* Since we are going forwards, process the defs second. This
2139 pass only changes the bits in cpy. */
2140 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2142 struct df_ref *def = *def_rec;
2143 unsigned int dregno = DF_REF_REGNO (def);
2144 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2145 || (dregno >= FIRST_PSEUDO_REGISTER))
2147 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2148 bitmap_clear_range (cpy,
2149 DF_DEFS_BEGIN (dregno),
2150 DF_DEFS_COUNT (dregno));
2151 if (!(DF_REF_FLAGS (def)
2152 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
2153 bitmap_set_bit (cpy, DF_REF_ID (def));
2158 /* Create the chains for the artificial uses of the hard registers
2159 at the end of the block. */
2160 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2161 df_chain_create_bb_process_use (cpy,
2162 df_get_artificial_uses (bb->index),
2165 BITMAP_FREE (cpy);
2168 /* Create def-use chains from reaching use bitmaps for basic blocks
2169 in BLOCKS. */
2171 static void
2172 df_chain_finalize (bitmap all_blocks)
2174 unsigned int bb_index;
2175 bitmap_iterator bi;
2177 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2179 df_chain_create_bb (bb_index);
2184 /* Free all storage associated with the problem. */
2186 static void
2187 df_chain_free (void)
2189 free_alloc_pool (df_chain->block_pool);
2190 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2191 free (df_chain);
2195 /* Debugging info. */
2197 static void
2198 df_chain_top_dump (basic_block bb, FILE *file)
2200 if (df_chain_problem_p (DF_DU_CHAIN))
2202 rtx insn;
2203 struct df_ref **def_rec = df_get_artificial_defs (bb->index);
2204 if (*def_rec)
2207 fprintf (file, ";; DU chains for artificial defs\n");
2208 while (*def_rec)
2210 struct df_ref *def = *def_rec;
2211 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2212 df_chain_dump (DF_REF_CHAIN (def), file);
2213 fprintf (file, "\n");
2214 def_rec++;
2218 FOR_BB_INSNS (bb, insn)
2220 unsigned int uid = INSN_UID (insn);
2221 if (INSN_P (insn))
2223 def_rec = DF_INSN_UID_DEFS (uid);
2224 if (*def_rec)
2226 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2227 DF_INSN_LUID (insn), uid);
2229 while (*def_rec)
2231 struct df_ref *def = *def_rec;
2232 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2233 if (def->flags & DF_REF_READ_WRITE)
2234 fprintf (file, "read/write ");
2235 df_chain_dump (DF_REF_CHAIN (def), file);
2236 fprintf (file, "\n");
2237 def_rec++;
2246 static void
2247 df_chain_bottom_dump (basic_block bb, FILE *file)
2249 if (df_chain_problem_p (DF_UD_CHAIN))
2251 rtx insn;
2252 struct df_ref **use_rec = df_get_artificial_uses (bb->index);
2254 if (*use_rec)
2256 fprintf (file, ";; UD chains for artificial uses\n");
2257 while (*use_rec)
2259 struct df_ref *use = *use_rec;
2260 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2261 df_chain_dump (DF_REF_CHAIN (use), file);
2262 fprintf (file, "\n");
2263 use_rec++;
2267 FOR_BB_INSNS (bb, insn)
2269 unsigned int uid = INSN_UID (insn);
2270 if (INSN_P (insn))
2272 struct df_ref **eq_use_rec = DF_INSN_UID_EQ_USES (uid);
2273 use_rec = DF_INSN_UID_USES (uid);
2274 if (*use_rec || *eq_use_rec)
2276 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2277 DF_INSN_LUID (insn), uid);
2279 while (*use_rec)
2281 struct df_ref *use = *use_rec;
2282 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2283 if (use->flags & DF_REF_READ_WRITE)
2284 fprintf (file, "read/write ");
2285 df_chain_dump (DF_REF_CHAIN (use), file);
2286 fprintf (file, "\n");
2287 use_rec++;
2289 while (*eq_use_rec)
2291 struct df_ref *use = *eq_use_rec;
2292 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2293 df_chain_dump (DF_REF_CHAIN (use), file);
2294 fprintf (file, "\n");
2295 eq_use_rec++;
2304 static struct df_problem problem_CHAIN =
2306 DF_CHAIN, /* Problem id. */
2307 DF_NONE, /* Direction. */
2308 df_chain_alloc, /* Allocate the problem specific data. */
2309 df_chain_reset, /* Reset global information. */
2310 NULL, /* Free basic block info. */
2311 NULL, /* Local compute function. */
2312 NULL, /* Init the solution specific data. */
2313 NULL, /* Iterative solver. */
2314 NULL, /* Confluence operator 0. */
2315 NULL, /* Confluence operator n. */
2316 NULL, /* Transfer function. */
2317 df_chain_finalize, /* Finalize function. */
2318 df_chain_free, /* Free all of the problem information. */
2319 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2320 NULL, /* Debugging. */
2321 df_chain_top_dump, /* Debugging start block. */
2322 df_chain_bottom_dump, /* Debugging end block. */
2323 NULL, /* Incremental solution verify start. */
2324 NULL, /* Incremental solution verify end. */
2325 &problem_RD, /* Dependent problem. */
2326 TV_DF_CHAIN, /* Timing variable. */
2327 false /* Reset blocks on dropping out of blocks_to_analyze. */
2331 /* Create a new DATAFLOW instance and add it to an existing instance
2332 of DF. The returned structure is what is used to get at the
2333 solution. */
2335 void
2336 df_chain_add_problem (enum df_chain_flags chain_flags)
2338 df_add_problem (&problem_CHAIN);
2339 df_chain->local_flags = (unsigned int)chain_flags;
2340 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2343 #undef df_chain_problem_p
2346 /*----------------------------------------------------------------------------
2347 This pass computes REG_DEAD and REG_UNUSED notes.
2348 ----------------------------------------------------------------------------*/
2350 static void
2351 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2353 df_note->optional_p = true;
2356 #ifdef REG_DEAD_DEBUGGING
2357 static void
2358 df_print_note (const char *prefix, rtx insn, rtx note)
2360 if (dump_file)
2362 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2363 print_rtl (dump_file, note);
2364 fprintf (dump_file, "\n");
2367 #endif
2370 /* After reg-stack, the x86 floating point stack regs are difficult to
2371 analyze because of all of the pushes, pops and rotations. Thus, we
2372 just leave the notes alone. */
2374 #ifdef STACK_REGS
2375 static inline bool
2376 df_ignore_stack_reg (int regno)
2378 return regstack_completed
2379 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2381 #else
2382 static inline bool
2383 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2385 return false;
2387 #endif
2390 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2391 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
2393 static void
2394 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
2396 rtx *pprev = &REG_NOTES (insn);
2397 rtx link = *pprev;
2398 rtx dead = NULL;
2399 rtx unused = NULL;
2401 while (link)
2403 switch (REG_NOTE_KIND (link))
2405 case REG_DEAD:
2406 /* After reg-stack, we need to ignore any unused notes
2407 for the stack registers. */
2408 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2410 pprev = &XEXP (link, 1);
2411 link = *pprev;
2413 else
2415 rtx next = XEXP (link, 1);
2416 #ifdef REG_DEAD_DEBUGGING
2417 df_print_note ("deleting: ", insn, link);
2418 #endif
2419 XEXP (link, 1) = dead;
2420 dead = link;
2421 *pprev = link = next;
2423 break;
2425 case REG_UNUSED:
2426 /* After reg-stack, we need to ignore any unused notes
2427 for the stack registers. */
2428 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2430 pprev = &XEXP (link, 1);
2431 link = *pprev;
2433 else
2435 rtx next = XEXP (link, 1);
2436 #ifdef REG_DEAD_DEBUGGING
2437 df_print_note ("deleting: ", insn, link);
2438 #endif
2439 XEXP (link, 1) = unused;
2440 unused = link;
2441 *pprev = link = next;
2443 break;
2445 default:
2446 pprev = &XEXP (link, 1);
2447 link = *pprev;
2448 break;
2452 *old_dead_notes = dead;
2453 *old_unused_notes = unused;
2457 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
2458 list, otherwise create a new one. */
2460 static inline rtx
2461 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
2463 rtx this = old;
2464 rtx prev = NULL;
2466 while (this)
2467 if (XEXP (this, 0) == reg)
2469 if (prev)
2470 XEXP (prev, 1) = XEXP (this, 1);
2471 else
2472 old = XEXP (this, 1);
2473 XEXP (this, 1) = REG_NOTES (insn);
2474 REG_NOTES (insn) = this;
2475 return old;
2477 else
2479 prev = this;
2480 this = XEXP (this, 1);
2483 /* Did not find the note. */
2484 REG_NOTES (insn) = alloc_EXPR_LIST (note_type, reg, REG_NOTES (insn));
2485 return old;
2488 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2489 arguments. Return true if the register value described by MWS's
2490 mw_reg is known to be completely unused, and if mw_reg can therefore
2491 be used in a REG_UNUSED note. */
2493 static bool
2494 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2495 bitmap live, bitmap artificial_uses)
2497 unsigned int r;
2499 /* If MWS describes a partial reference, create REG_UNUSED notes for
2500 individual hard registers. */
2501 if (mws->flags & DF_REF_PARTIAL)
2502 return false;
2504 /* Likewise if some part of the register is used. */
2505 for (r = mws->start_regno; r <= mws->end_regno; r++)
2506 if (bitmap_bit_p (live, r)
2507 || bitmap_bit_p (artificial_uses, r))
2508 return false;
2510 gcc_assert (REG_P (mws->mw_reg));
2511 return true;
2514 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2515 based on the bits in LIVE. Do not generate notes for registers in
2516 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2517 not generated if the reg is both read and written by the
2518 instruction.
2521 static rtx
2522 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2523 bitmap live, bitmap do_not_gen,
2524 bitmap artificial_uses)
2526 unsigned int r;
2528 #ifdef REG_DEAD_DEBUGGING
2529 if (dump_file)
2530 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2531 mws->start_regno, mws->end_regno);
2532 #endif
2534 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2536 unsigned int regno = mws->start_regno;
2537 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
2539 #ifdef REG_DEAD_DEBUGGING
2540 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2541 #endif
2542 bitmap_set_bit (do_not_gen, regno);
2543 /* Only do this if the value is totally dead. */
2545 else
2546 for (r = mws->start_regno; r <= mws->end_regno; r++)
2548 if (!bitmap_bit_p (live, r)
2549 && !bitmap_bit_p (artificial_uses, r))
2551 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
2552 #ifdef REG_DEAD_DEBUGGING
2553 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2554 #endif
2556 bitmap_set_bit (do_not_gen, r);
2558 return old;
2562 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2563 arguments. Return true if the register value described by MWS's
2564 mw_reg is known to be completely dead, and if mw_reg can therefore
2565 be used in a REG_DEAD note. */
2567 static bool
2568 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2569 bitmap live, bitmap artificial_uses,
2570 bitmap do_not_gen)
2572 unsigned int r;
2574 /* If MWS describes a partial reference, create REG_DEAD notes for
2575 individual hard registers. */
2576 if (mws->flags & DF_REF_PARTIAL)
2577 return false;
2579 /* Likewise if some part of the register is not dead. */
2580 for (r = mws->start_regno; r <= mws->end_regno; r++)
2581 if (bitmap_bit_p (live, r)
2582 || bitmap_bit_p (artificial_uses, r)
2583 || bitmap_bit_p (do_not_gen, r))
2584 return false;
2586 gcc_assert (REG_P (mws->mw_reg));
2587 return true;
2590 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2591 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2592 from being set if the instruction both reads and writes the
2593 register. */
2595 static rtx
2596 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2597 bitmap live, bitmap do_not_gen,
2598 bitmap artificial_uses)
2600 unsigned int r;
2602 #ifdef REG_DEAD_DEBUGGING
2603 if (dump_file)
2605 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2606 mws->start_regno, mws->end_regno);
2607 df_print_regset (dump_file, do_not_gen);
2608 fprintf (dump_file, " live =");
2609 df_print_regset (dump_file, live);
2610 fprintf (dump_file, " artificial uses =");
2611 df_print_regset (dump_file, artificial_uses);
2613 #endif
2615 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2617 /* Add a dead note for the entire multi word register. */
2618 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
2619 #ifdef REG_DEAD_DEBUGGING
2620 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2621 #endif
2623 else
2625 for (r = mws->start_regno; r <= mws->end_regno; r++)
2626 if (!bitmap_bit_p (live, r)
2627 && !bitmap_bit_p (artificial_uses, r)
2628 && !bitmap_bit_p (do_not_gen, r))
2630 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
2631 #ifdef REG_DEAD_DEBUGGING
2632 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2633 #endif
2636 return old;
2640 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
2641 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
2643 static rtx
2644 df_create_unused_note (rtx insn, rtx old, struct df_ref *def,
2645 bitmap live, bitmap artificial_uses)
2647 unsigned int dregno = DF_REF_REGNO (def);
2649 #ifdef REG_DEAD_DEBUGGING
2650 if (dump_file)
2652 fprintf (dump_file, " regular looking at def ");
2653 df_ref_debug (def, dump_file);
2655 #endif
2657 if (!(bitmap_bit_p (live, dregno)
2658 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
2659 || bitmap_bit_p (artificial_uses, dregno)
2660 || df_ignore_stack_reg (dregno)))
2662 rtx reg = (DF_REF_LOC (def))
2663 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
2664 old = df_set_note (REG_UNUSED, insn, old, reg);
2665 #ifdef REG_DEAD_DEBUGGING
2666 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
2667 #endif
2670 return old;
2674 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
2675 info: lifetime, bb, and number of defs and uses for basic block
2676 BB. The three bitvectors are scratch regs used here. */
2678 static void
2679 df_note_bb_compute (unsigned int bb_index,
2680 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
2682 basic_block bb = BASIC_BLOCK (bb_index);
2683 rtx insn;
2684 struct df_ref **def_rec;
2685 struct df_ref **use_rec;
2687 bitmap_copy (live, df_get_live_out (bb));
2688 bitmap_clear (artificial_uses);
2690 #ifdef REG_DEAD_DEBUGGING
2691 if (dump_file)
2693 fprintf (dump_file, "live at bottom ");
2694 df_print_regset (dump_file, live);
2696 #endif
2698 /* Process the artificial defs and uses at the bottom of the block
2699 to begin processing. */
2700 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2702 struct df_ref *def = *def_rec;
2703 #ifdef REG_DEAD_DEBUGGING
2704 if (dump_file)
2705 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
2706 #endif
2708 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2709 bitmap_clear_bit (live, DF_REF_REGNO (def));
2712 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2714 struct df_ref *use = *use_rec;
2715 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2717 unsigned int regno = DF_REF_REGNO (use);
2718 bitmap_set_bit (live, regno);
2720 /* Notes are not generated for any of the artificial registers
2721 at the bottom of the block. */
2722 bitmap_set_bit (artificial_uses, regno);
2726 #ifdef REG_DEAD_DEBUGGING
2727 if (dump_file)
2729 fprintf (dump_file, "live before artificials out ");
2730 df_print_regset (dump_file, live);
2732 #endif
2734 FOR_BB_INSNS_REVERSE (bb, insn)
2736 unsigned int uid = INSN_UID (insn);
2737 struct df_mw_hardreg **mws_rec;
2738 rtx old_dead_notes;
2739 rtx old_unused_notes;
2741 if (!INSN_P (insn))
2742 continue;
2744 bitmap_clear (do_not_gen);
2745 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
2747 /* Process the defs. */
2748 if (CALL_P (insn))
2750 #ifdef REG_DEAD_DEBUGGING
2751 if (dump_file)
2753 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
2754 df_print_regset (dump_file, live);
2756 #endif
2757 /* We only care about real sets for calls. Clobbers cannot
2758 be depended on to really die. */
2759 mws_rec = DF_INSN_UID_MWS (uid);
2760 while (*mws_rec)
2762 struct df_mw_hardreg *mws = *mws_rec;
2763 if ((mws->type == DF_REF_REG_DEF)
2764 && !df_ignore_stack_reg (mws->start_regno))
2765 old_unused_notes
2766 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2767 mws, live, do_not_gen,
2768 artificial_uses);
2769 mws_rec++;
2772 /* All of the defs except the return value are some sort of
2773 clobber. This code is for the return. */
2774 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2776 struct df_ref *def = *def_rec;
2777 unsigned int dregno = DF_REF_REGNO (def);
2778 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2780 old_unused_notes
2781 = df_create_unused_note (insn, old_unused_notes,
2782 def, live, artificial_uses);
2783 bitmap_set_bit (do_not_gen, dregno);
2786 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2787 bitmap_clear_bit (live, dregno);
2790 else
2792 /* Regular insn. */
2793 mws_rec = DF_INSN_UID_MWS (uid);
2794 while (*mws_rec)
2796 struct df_mw_hardreg *mws = *mws_rec;
2797 if (mws->type == DF_REF_REG_DEF)
2798 old_unused_notes
2799 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2800 mws, live, do_not_gen,
2801 artificial_uses);
2802 mws_rec++;
2805 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2807 struct df_ref *def = *def_rec;
2808 unsigned int dregno = DF_REF_REGNO (def);
2809 old_unused_notes
2810 = df_create_unused_note (insn, old_unused_notes,
2811 def, live, artificial_uses);
2813 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2814 bitmap_set_bit (do_not_gen, dregno);
2816 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2817 bitmap_clear_bit (live, dregno);
2821 /* Process the uses. */
2822 mws_rec = DF_INSN_UID_MWS (uid);
2823 while (*mws_rec)
2825 struct df_mw_hardreg *mws = *mws_rec;
2826 if ((mws->type != DF_REF_REG_DEF)
2827 && !df_ignore_stack_reg (mws->start_regno))
2828 old_dead_notes
2829 = df_set_dead_notes_for_mw (insn, old_dead_notes,
2830 mws, live, do_not_gen,
2831 artificial_uses);
2832 mws_rec++;
2835 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2837 struct df_ref *use = *use_rec;
2838 unsigned int uregno = DF_REF_REGNO (use);
2840 #ifdef REG_DEAD_DEBUGGING
2841 if (dump_file)
2843 fprintf (dump_file, " regular looking at use ");
2844 df_ref_debug (use, dump_file);
2846 #endif
2847 if (!bitmap_bit_p (live, uregno))
2849 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
2850 && (!bitmap_bit_p (do_not_gen, uregno))
2851 && (!bitmap_bit_p (artificial_uses, uregno))
2852 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
2853 && (!df_ignore_stack_reg (uregno)))
2855 rtx reg = (DF_REF_LOC (use))
2856 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
2857 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
2859 #ifdef REG_DEAD_DEBUGGING
2860 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
2861 #endif
2863 /* This register is now live. */
2864 bitmap_set_bit (live, uregno);
2868 while (old_unused_notes)
2870 rtx next = XEXP (old_unused_notes, 1);
2871 free_EXPR_LIST_node (old_unused_notes);
2872 old_unused_notes = next;
2874 while (old_dead_notes)
2876 rtx next = XEXP (old_dead_notes, 1);
2877 free_EXPR_LIST_node (old_dead_notes);
2878 old_dead_notes = next;
2884 /* Compute register info: lifetime, bb, and number of defs and uses. */
2885 static void
2886 df_note_compute (bitmap all_blocks)
2888 unsigned int bb_index;
2889 bitmap_iterator bi;
2890 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
2891 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
2892 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
2894 #ifdef REG_DEAD_DEBUGGING
2895 if (dump_file)
2896 print_rtl_with_bb (dump_file, get_insns());
2897 #endif
2899 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2901 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
2904 BITMAP_FREE (live);
2905 BITMAP_FREE (do_not_gen);
2906 BITMAP_FREE (artificial_uses);
2910 /* Free all storage associated with the problem. */
2912 static void
2913 df_note_free (void)
2915 free (df_note);
2919 /* All of the information associated every instance of the problem. */
2921 static struct df_problem problem_NOTE =
2923 DF_NOTE, /* Problem id. */
2924 DF_NONE, /* Direction. */
2925 df_note_alloc, /* Allocate the problem specific data. */
2926 NULL, /* Reset global information. */
2927 NULL, /* Free basic block info. */
2928 df_note_compute, /* Local compute function. */
2929 NULL, /* Init the solution specific data. */
2930 NULL, /* Iterative solver. */
2931 NULL, /* Confluence operator 0. */
2932 NULL, /* Confluence operator n. */
2933 NULL, /* Transfer function. */
2934 NULL, /* Finalize function. */
2935 df_note_free, /* Free all of the problem information. */
2936 df_note_free, /* Remove this problem from the stack of dataflow problems. */
2937 NULL, /* Debugging. */
2938 NULL, /* Debugging start block. */
2939 NULL, /* Debugging end block. */
2940 NULL, /* Incremental solution verify start. */
2941 NULL, /* Incremental solution verify end. */
2942 &problem_LR, /* Dependent problem. */
2943 TV_DF_NOTE, /* Timing variable. */
2944 false /* Reset blocks on dropping out of blocks_to_analyze. */
2948 /* Create a new DATAFLOW instance and add it to an existing instance
2949 of DF. The returned structure is what is used to get at the
2950 solution. */
2952 void
2953 df_note_add_problem (void)
2955 df_add_problem (&problem_NOTE);
2961 /*----------------------------------------------------------------------------
2962 Functions for simulating the effects of single insns.
2964 You can either simulate in the forwards direction, starting from
2965 the top of a block or the backwards direction from the end of the
2966 block. The main difference is that if you go forwards, the uses
2967 are examined first then the defs, and if you go backwards, the defs
2968 are examined first then the uses.
2970 If you start at the top of the block, use one of DF_LIVE_IN or
2971 DF_LR_IN. If you start at the bottom of the block use one of
2972 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
2973 THEY WILL BE DESTROYED.
2975 ----------------------------------------------------------------------------*/
2978 /* Find the set of DEFs for INSN. */
2980 void
2981 df_simulate_find_defs (rtx insn, bitmap defs)
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 /* If the def is to only part of the reg, it does
2990 not kill the other defs that reach here. */
2991 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2992 bitmap_set_bit (defs, DF_REF_REGNO (def));
2997 /* Simulate the effects of the defs of INSN on LIVE. */
2999 void
3000 df_simulate_defs (rtx insn, bitmap live)
3002 struct df_ref **def_rec;
3003 unsigned int uid = INSN_UID (insn);
3005 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3007 struct df_ref *def = *def_rec;
3008 unsigned int dregno = DF_REF_REGNO (def);
3010 /* If the def is to only part of the reg, it does
3011 not kill the other defs that reach here. */
3012 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3013 bitmap_clear_bit (live, dregno);
3018 /* Simulate the effects of the uses of INSN on LIVE. */
3020 void
3021 df_simulate_uses (rtx insn, bitmap live)
3023 struct df_ref **use_rec;
3024 unsigned int uid = INSN_UID (insn);
3026 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3028 struct df_ref *use = *use_rec;
3029 /* Add use to set of uses in this BB. */
3030 bitmap_set_bit (live, DF_REF_REGNO (use));
3035 /* Add back the always live regs in BB to LIVE. */
3037 static inline void
3038 df_simulate_fixup_sets (basic_block bb, bitmap live)
3040 /* These regs are considered always live so if they end up dying
3041 because of some def, we need to bring the back again. */
3042 if (bb_has_eh_pred (bb))
3043 bitmap_ior_into (live, df->eh_block_artificial_uses);
3044 else
3045 bitmap_ior_into (live, df->regular_block_artificial_uses);
3049 /* Apply the artificial uses and defs at the top of BB in a forwards
3050 direction. */
3052 void
3053 df_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
3055 struct df_ref **def_rec;
3056 struct df_ref **use_rec;
3057 int bb_index = bb->index;
3059 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3061 struct df_ref *use = *use_rec;
3062 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3063 bitmap_set_bit (live, DF_REF_REGNO (use));
3066 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3068 struct df_ref *def = *def_rec;
3069 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3070 bitmap_clear_bit (live, DF_REF_REGNO (def));
3075 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3077 void
3078 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3080 if (! INSN_P (insn))
3081 return;
3083 df_simulate_uses (insn, live);
3084 df_simulate_defs (insn, live);
3085 df_simulate_fixup_sets (bb, live);
3089 /* Apply the artificial uses and defs at the end of BB in a backwards
3090 direction. */
3092 void
3093 df_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3095 struct df_ref **def_rec;
3096 struct df_ref **use_rec;
3097 int bb_index = bb->index;
3099 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3101 struct df_ref *def = *def_rec;
3102 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3103 bitmap_clear_bit (live, DF_REF_REGNO (def));
3106 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3108 struct df_ref *use = *use_rec;
3109 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3110 bitmap_set_bit (live, DF_REF_REGNO (use));
3115 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3117 void
3118 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3120 if (! INSN_P (insn))
3121 return;
3123 df_simulate_defs (insn, live);
3124 df_simulate_uses (insn, live);
3125 df_simulate_fixup_sets (bb, live);