2009-06-12 Andrew Pinski <andrew_pinski@playstation.sony.com>
[official-gcc.git] / gcc / df-problems.c
blobf48da9bc8dc081d7de60b4fee2a7f18221826b56
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009 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 = XRESIZEVEC (void *, dflow->block_info, new_size);
113 memset (dflow->block_info + dflow->block_info_size, 0,
114 (new_size - dflow->block_info_size) *sizeof (void *));
115 dflow->block_info_size = new_size;
119 /* Dump a def-use or use-def chain for REF to FILE. */
121 void
122 df_chain_dump (struct df_link *link, FILE *file)
124 fprintf (file, "{ ");
125 for (; link; link = link->next)
127 fprintf (file, "%c%d(bb %d insn %d) ",
128 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
129 DF_REF_ID (link->ref),
130 DF_REF_BBNO (link->ref),
131 DF_REF_IS_ARTIFICIAL (link->ref) ? -1 : DF_REF_INSN_UID (link->ref));
133 fprintf (file, "}");
137 /* Print some basic block info as part of df_dump. */
139 void
140 df_print_bb_index (basic_block bb, FILE *file)
142 edge e;
143 edge_iterator ei;
145 fprintf (file, "\n( ");
146 FOR_EACH_EDGE (e, ei, bb->preds)
148 basic_block pred = e->src;
149 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
151 fprintf (file, ")->[%d]->( ", bb->index);
152 FOR_EACH_EDGE (e, ei, bb->succs)
154 basic_block succ = e->dest;
155 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
157 fprintf (file, ")\n");
162 /* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
163 up correctly. */
165 static void
166 df_set_seen (void)
168 seen_in_block = BITMAP_ALLOC (&df_bitmap_obstack);
169 seen_in_insn = BITMAP_ALLOC (&df_bitmap_obstack);
173 static void
174 df_unset_seen (void)
176 BITMAP_FREE (seen_in_block);
177 BITMAP_FREE (seen_in_insn);
182 /*----------------------------------------------------------------------------
183 REACHING DEFINITIONS
185 Find the locations in the function where each definition site for a
186 pseudo reaches. In and out bitvectors are built for each basic
187 block. The id field in the ref is used to index into these sets.
188 See df.h for details.
189 ----------------------------------------------------------------------------*/
191 /* This problem plays a large number of games for the sake of
192 efficiency.
194 1) The order of the bits in the bitvectors. After the scanning
195 phase, all of the defs are sorted. All of the defs for the reg 0
196 are first, followed by all defs for reg 1 and so on.
198 2) There are two kill sets, one if the number of defs is less or
199 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
200 greater.
202 <= : Data is built directly in the kill set.
204 > : One level of indirection is used to keep from generating long
205 strings of 1 bits in the kill sets. Bitvectors that are indexed
206 by the regnum are used to represent that there is a killing def
207 for the register. The confluence and transfer functions use
208 these along with the bitmap_clear_range call to remove ranges of
209 bits without actually generating a knockout vector.
211 The kill and sparse_kill and the dense_invalidated_by_call and
212 sparse_invalidated_by_call both play this game. */
214 /* Private data used to compute the solution for this problem. These
215 data structures are not accessible outside of this module. */
216 struct df_rd_problem_data
218 /* The set of defs to regs invalidated by call. */
219 bitmap sparse_invalidated_by_call;
220 /* The set of defs to regs invalidate by call for rd. */
221 bitmap dense_invalidated_by_call;
222 /* An obstack for the bitmaps we need for this problem. */
223 bitmap_obstack rd_bitmaps;
226 /* Set basic block info. */
228 static void
229 df_rd_set_bb_info (unsigned int index,
230 struct df_rd_bb_info *bb_info)
232 gcc_assert (df_rd);
233 gcc_assert (index < df_rd->block_info_size);
234 df_rd->block_info[index] = bb_info;
238 /* Free basic block info. */
240 static void
241 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
242 void *vbb_info)
244 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
245 if (bb_info)
247 BITMAP_FREE (bb_info->kill);
248 BITMAP_FREE (bb_info->sparse_kill);
249 BITMAP_FREE (bb_info->gen);
250 BITMAP_FREE (bb_info->in);
251 BITMAP_FREE (bb_info->out);
252 pool_free (df_rd->block_pool, bb_info);
257 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
258 not touched unless the block is new. */
260 static void
261 df_rd_alloc (bitmap all_blocks)
263 unsigned int bb_index;
264 bitmap_iterator bi;
265 struct df_rd_problem_data *problem_data;
267 if (!df_rd->block_pool)
268 df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
269 sizeof (struct df_rd_bb_info), 50);
271 if (df_rd->problem_data)
273 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
274 bitmap_clear (problem_data->sparse_invalidated_by_call);
275 bitmap_clear (problem_data->dense_invalidated_by_call);
277 else
279 problem_data = XNEW (struct df_rd_problem_data);
280 df_rd->problem_data = problem_data;
282 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
283 problem_data->sparse_invalidated_by_call
284 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
285 problem_data->dense_invalidated_by_call
286 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
289 df_grow_bb_info (df_rd);
291 /* Because of the clustering of all use sites for the same pseudo,
292 we have to process all of the blocks before doing the
293 analysis. */
295 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
297 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
298 if (bb_info)
300 bitmap_clear (bb_info->kill);
301 bitmap_clear (bb_info->sparse_kill);
302 bitmap_clear (bb_info->gen);
304 else
306 bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
307 df_rd_set_bb_info (bb_index, bb_info);
308 bb_info->kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
309 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
310 bb_info->gen = BITMAP_ALLOC (&problem_data->rd_bitmaps);
311 bb_info->in = BITMAP_ALLOC (&problem_data->rd_bitmaps);
312 bb_info->out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
315 df_rd->optional_p = true;
319 /* Add the effect of the top artificial defs of BB to the reaching definitions
320 bitmap LOCAL_RD. */
322 void
323 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
325 int bb_index = bb->index;
326 df_ref *def_rec;
327 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
329 df_ref def = *def_rec;
330 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
332 unsigned int dregno = DF_REF_REGNO (def);
333 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
334 bitmap_clear_range (local_rd,
335 DF_DEFS_BEGIN (dregno),
336 DF_DEFS_COUNT (dregno));
337 bitmap_set_bit (local_rd, DF_REF_ID (def));
342 /* Add the effect of the defs of INSN to the reaching definitions bitmap
343 LOCAL_RD. */
345 void
346 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
347 bitmap local_rd)
349 unsigned uid = INSN_UID (insn);
350 df_ref *def_rec;
352 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
354 df_ref def = *def_rec;
355 unsigned int dregno = DF_REF_REGNO (def);
356 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
357 || (dregno >= FIRST_PSEUDO_REGISTER))
359 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
360 bitmap_clear_range (local_rd,
361 DF_DEFS_BEGIN (dregno),
362 DF_DEFS_COUNT (dregno));
363 if (!(DF_REF_FLAGS (def)
364 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
365 bitmap_set_bit (local_rd, DF_REF_ID (def));
370 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
371 more complicated than just simulating, because we must produce the
372 gen and kill sets and hence deal with the two possible representations
373 of kill sets. */
375 static void
376 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
377 df_ref *def_rec,
378 int top_flag)
380 while (*def_rec)
382 df_ref def = *def_rec;
383 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
385 unsigned int regno = DF_REF_REGNO (def);
386 unsigned int begin = DF_DEFS_BEGIN (regno);
387 unsigned int n_defs = DF_DEFS_COUNT (regno);
389 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
390 || (regno >= FIRST_PSEUDO_REGISTER))
392 /* Only the last def(s) for a regno in the block has any
393 effect. */
394 if (!bitmap_bit_p (seen_in_block, regno))
396 /* The first def for regno in insn gets to knock out the
397 defs from other instructions. */
398 if ((!bitmap_bit_p (seen_in_insn, regno))
399 /* If the def is to only part of the reg, it does
400 not kill the other defs that reach here. */
401 && (!(DF_REF_FLAGS (def) &
402 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
404 if (n_defs > DF_SPARSE_THRESHOLD)
406 bitmap_set_bit (bb_info->sparse_kill, regno);
407 bitmap_clear_range(bb_info->gen, begin, n_defs);
409 else
411 bitmap_set_range (bb_info->kill, begin, n_defs);
412 bitmap_clear_range (bb_info->gen, begin, n_defs);
416 bitmap_set_bit (seen_in_insn, regno);
417 /* All defs for regno in the instruction may be put into
418 the gen set. */
419 if (!(DF_REF_FLAGS (def)
420 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
421 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
425 def_rec++;
429 /* Compute local reaching def info for basic block BB. */
431 static void
432 df_rd_bb_local_compute (unsigned int bb_index)
434 basic_block bb = BASIC_BLOCK (bb_index);
435 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
436 rtx insn;
438 bitmap_clear (seen_in_block);
439 bitmap_clear (seen_in_insn);
441 /* Artificials are only hard regs. */
442 if (!(df->changeable_flags & DF_NO_HARD_REGS))
443 df_rd_bb_local_compute_process_def (bb_info,
444 df_get_artificial_defs (bb_index),
447 FOR_BB_INSNS_REVERSE (bb, insn)
449 unsigned int uid = INSN_UID (insn);
451 if (!INSN_P (insn))
452 continue;
454 df_rd_bb_local_compute_process_def (bb_info,
455 DF_INSN_UID_DEFS (uid), 0);
457 /* This complex dance with the two bitmaps is required because
458 instructions can assign twice to the same pseudo. This
459 generally happens with calls that will have one def for the
460 result and another def for the clobber. If only one vector
461 is used and the clobber goes first, the result will be
462 lost. */
463 bitmap_ior_into (seen_in_block, seen_in_insn);
464 bitmap_clear (seen_in_insn);
467 /* Process the artificial defs at the top of the block last since we
468 are going backwards through the block and these are logically at
469 the start. */
470 if (!(df->changeable_flags & DF_NO_HARD_REGS))
471 df_rd_bb_local_compute_process_def (bb_info,
472 df_get_artificial_defs (bb_index),
473 DF_REF_AT_TOP);
477 /* Compute local reaching def info for each basic block within BLOCKS. */
479 static void
480 df_rd_local_compute (bitmap all_blocks)
482 unsigned int bb_index;
483 bitmap_iterator bi;
484 unsigned int regno;
485 struct df_rd_problem_data *problem_data
486 = (struct df_rd_problem_data *) df_rd->problem_data;
487 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
488 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
490 df_set_seen ();
492 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
494 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
496 df_rd_bb_local_compute (bb_index);
499 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
500 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, regno, bi)
502 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
503 bitmap_set_bit (sparse_invalidated, regno);
504 else
505 bitmap_set_range (dense_invalidated,
506 DF_DEFS_BEGIN (regno),
507 DF_DEFS_COUNT (regno));
509 df_unset_seen ();
513 /* Initialize the solution bit vectors for problem. */
515 static void
516 df_rd_init_solution (bitmap all_blocks)
518 unsigned int bb_index;
519 bitmap_iterator bi;
521 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
523 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
525 bitmap_copy (bb_info->out, bb_info->gen);
526 bitmap_clear (bb_info->in);
530 /* In of target gets or of out of source. */
532 static void
533 df_rd_confluence_n (edge e)
535 bitmap op1 = df_rd_get_bb_info (e->dest->index)->in;
536 bitmap op2 = df_rd_get_bb_info (e->src->index)->out;
538 if (e->flags & EDGE_FAKE)
539 return;
541 if (e->flags & EDGE_EH)
543 struct df_rd_problem_data *problem_data
544 = (struct df_rd_problem_data *) df_rd->problem_data;
545 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
546 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
547 bitmap_iterator bi;
548 unsigned int regno;
549 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
551 bitmap_copy (tmp, op2);
552 bitmap_and_compl_into (tmp, dense_invalidated);
554 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
556 bitmap_clear_range (tmp,
557 DF_DEFS_BEGIN (regno),
558 DF_DEFS_COUNT (regno));
560 bitmap_ior_into (op1, tmp);
561 BITMAP_FREE (tmp);
563 else
564 bitmap_ior_into (op1, op2);
568 /* Transfer function. */
570 static bool
571 df_rd_transfer_function (int bb_index)
573 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
574 unsigned int regno;
575 bitmap_iterator bi;
576 bitmap in = bb_info->in;
577 bitmap out = bb_info->out;
578 bitmap gen = bb_info->gen;
579 bitmap kill = bb_info->kill;
580 bitmap sparse_kill = bb_info->sparse_kill;
582 if (bitmap_empty_p (sparse_kill))
583 return bitmap_ior_and_compl (out, gen, in, kill);
584 else
586 struct df_rd_problem_data *problem_data;
587 bool changed = false;
588 bitmap tmp;
590 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
591 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
592 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
593 tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
595 bitmap_copy (tmp, in);
596 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
598 bitmap_clear_range (tmp,
599 DF_DEFS_BEGIN (regno),
600 DF_DEFS_COUNT (regno));
602 bitmap_and_compl_into (tmp, kill);
603 bitmap_ior_into (tmp, gen);
604 changed = !bitmap_equal_p (tmp, out);
605 if (changed)
607 BITMAP_FREE (out);
608 bb_info->out = tmp;
610 else
611 BITMAP_FREE (tmp);
612 return changed;
617 /* Free all storage associated with the problem. */
619 static void
620 df_rd_free (void)
622 struct df_rd_problem_data *problem_data
623 = (struct df_rd_problem_data *) df_rd->problem_data;
625 if (problem_data)
627 free_alloc_pool (df_rd->block_pool);
628 bitmap_obstack_release (&problem_data->rd_bitmaps);
630 df_rd->block_info_size = 0;
631 free (df_rd->block_info);
632 free (df_rd->problem_data);
634 free (df_rd);
638 /* Debugging info. */
640 static void
641 df_rd_start_dump (FILE *file)
643 struct df_rd_problem_data *problem_data
644 = (struct df_rd_problem_data *) df_rd->problem_data;
645 unsigned int m = DF_REG_SIZE(df);
646 unsigned int regno;
648 if (!df_rd->block_info)
649 return;
651 fprintf (file, ";; Reaching defs:\n\n");
653 fprintf (file, " sparse invalidated \t");
654 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
655 fprintf (file, " dense invalidated \t");
656 dump_bitmap (file, problem_data->dense_invalidated_by_call);
658 for (regno = 0; regno < m; regno++)
659 if (DF_DEFS_COUNT (regno))
660 fprintf (file, "%d[%d,%d] ", regno,
661 DF_DEFS_BEGIN (regno),
662 DF_DEFS_COUNT (regno));
663 fprintf (file, "\n");
668 /* Debugging info at top of bb. */
670 static void
671 df_rd_top_dump (basic_block bb, FILE *file)
673 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
674 if (!bb_info || !bb_info->in)
675 return;
677 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
678 dump_bitmap (file, bb_info->in);
679 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
680 dump_bitmap (file, bb_info->gen);
681 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
682 dump_bitmap (file, bb_info->kill);
686 /* Debugging info at top of bb. */
688 static void
689 df_rd_bottom_dump (basic_block bb, FILE *file)
691 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
692 if (!bb_info || !bb_info->out)
693 return;
695 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
696 dump_bitmap (file, bb_info->out);
699 /* All of the information associated with every instance of the problem. */
701 static struct df_problem problem_RD =
703 DF_RD, /* Problem id. */
704 DF_FORWARD, /* Direction. */
705 df_rd_alloc, /* Allocate the problem specific data. */
706 NULL, /* Reset global information. */
707 df_rd_free_bb_info, /* Free basic block info. */
708 df_rd_local_compute, /* Local compute function. */
709 df_rd_init_solution, /* Init the solution specific data. */
710 df_worklist_dataflow, /* Worklist solver. */
711 NULL, /* Confluence operator 0. */
712 df_rd_confluence_n, /* Confluence operator n. */
713 df_rd_transfer_function, /* Transfer function. */
714 NULL, /* Finalize function. */
715 df_rd_free, /* Free all of the problem information. */
716 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
717 df_rd_start_dump, /* Debugging. */
718 df_rd_top_dump, /* Debugging start block. */
719 df_rd_bottom_dump, /* Debugging end block. */
720 NULL, /* Incremental solution verify start. */
721 NULL, /* Incremental solution verify end. */
722 NULL, /* Dependent problem. */
723 TV_DF_RD, /* Timing variable. */
724 true /* Reset blocks on dropping out of blocks_to_analyze. */
729 /* Create a new DATAFLOW instance and add it to an existing instance
730 of DF. The returned structure is what is used to get at the
731 solution. */
733 void
734 df_rd_add_problem (void)
736 df_add_problem (&problem_RD);
741 /*----------------------------------------------------------------------------
742 LIVE REGISTERS
744 Find the locations in the function where any use of a pseudo can
745 reach in the backwards direction. In and out bitvectors are built
746 for each basic block. The regno is used to index into these sets.
747 See df.h for details.
748 ----------------------------------------------------------------------------*/
750 /* Private data used to verify the solution for this problem. */
751 struct df_lr_problem_data
753 bitmap *in;
754 bitmap *out;
758 /* Set basic block info. */
760 static void
761 df_lr_set_bb_info (unsigned int index,
762 struct df_lr_bb_info *bb_info)
764 gcc_assert (df_lr);
765 gcc_assert (index < df_lr->block_info_size);
766 df_lr->block_info[index] = bb_info;
770 /* Free basic block info. */
772 static void
773 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
774 void *vbb_info)
776 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
777 if (bb_info)
779 BITMAP_FREE (bb_info->use);
780 BITMAP_FREE (bb_info->def);
781 BITMAP_FREE (bb_info->in);
782 BITMAP_FREE (bb_info->out);
783 pool_free (df_lr->block_pool, bb_info);
788 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
789 not touched unless the block is new. */
791 static void
792 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
794 unsigned int bb_index;
795 bitmap_iterator bi;
797 if (!df_lr->block_pool)
798 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
799 sizeof (struct df_lr_bb_info), 50);
801 df_grow_bb_info (df_lr);
803 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
805 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
806 if (bb_info)
808 bitmap_clear (bb_info->def);
809 bitmap_clear (bb_info->use);
811 else
813 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
814 df_lr_set_bb_info (bb_index, bb_info);
815 bb_info->use = BITMAP_ALLOC (NULL);
816 bb_info->def = BITMAP_ALLOC (NULL);
817 bb_info->in = BITMAP_ALLOC (NULL);
818 bb_info->out = BITMAP_ALLOC (NULL);
822 df_lr->optional_p = false;
826 /* Reset the global solution for recalculation. */
828 static void
829 df_lr_reset (bitmap all_blocks)
831 unsigned int bb_index;
832 bitmap_iterator bi;
834 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
836 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
837 gcc_assert (bb_info);
838 bitmap_clear (bb_info->in);
839 bitmap_clear (bb_info->out);
844 /* Compute local live register info for basic block BB. */
846 static void
847 df_lr_bb_local_compute (unsigned int bb_index)
849 basic_block bb = BASIC_BLOCK (bb_index);
850 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
851 rtx insn;
852 df_ref *def_rec;
853 df_ref *use_rec;
855 /* Process the registers set in an exception handler. */
856 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
858 df_ref def = *def_rec;
859 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
861 unsigned int dregno = DF_REF_REGNO (def);
862 bitmap_set_bit (bb_info->def, dregno);
863 bitmap_clear_bit (bb_info->use, dregno);
867 /* Process the hardware registers that are always live. */
868 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
870 df_ref use = *use_rec;
871 /* Add use to set of uses in this BB. */
872 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
873 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
876 FOR_BB_INSNS_REVERSE (bb, insn)
878 unsigned int uid = INSN_UID (insn);
880 if (!INSN_P (insn))
881 continue;
883 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
885 df_ref def = *def_rec;
886 /* If the def is to only part of the reg, it does
887 not kill the other defs that reach here. */
888 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
890 unsigned int dregno = DF_REF_REGNO (def);
891 bitmap_set_bit (bb_info->def, dregno);
892 bitmap_clear_bit (bb_info->use, dregno);
896 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
898 df_ref use = *use_rec;
899 /* Add use to set of uses in this BB. */
900 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
904 /* Process the registers set in an exception handler or the hard
905 frame pointer if this block is the target of a non local
906 goto. */
907 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
909 df_ref def = *def_rec;
910 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
912 unsigned int dregno = DF_REF_REGNO (def);
913 bitmap_set_bit (bb_info->def, dregno);
914 bitmap_clear_bit (bb_info->use, dregno);
918 #ifdef EH_USES
919 /* Process the uses that are live into an exception handler. */
920 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
922 df_ref use = *use_rec;
923 /* Add use to set of uses in this BB. */
924 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
925 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
927 #endif
929 /* If the df_live problem is not defined, such as at -O0 and -O1, we
930 still need to keep the luids up to date. This is normally done
931 in the df_live problem since this problem has a forwards
932 scan. */
933 if (!df_live)
934 df_recompute_luids (bb);
938 /* Compute local live register info for each basic block within BLOCKS. */
940 static void
941 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
943 unsigned int bb_index;
944 bitmap_iterator bi;
946 bitmap_clear (df->hardware_regs_used);
948 /* The all-important stack pointer must always be live. */
949 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
951 /* Before reload, there are a few registers that must be forced
952 live everywhere -- which might not already be the case for
953 blocks within infinite loops. */
954 if (!reload_completed)
956 /* Any reference to any pseudo before reload is a potential
957 reference of the frame pointer. */
958 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
960 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
961 /* Pseudos with argument area equivalences may require
962 reloading via the argument pointer. */
963 if (fixed_regs[ARG_POINTER_REGNUM])
964 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
965 #endif
967 /* Any constant, or pseudo with constant equivalences, may
968 require reloading from memory using the pic register. */
969 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
970 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
971 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
974 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
976 if (bb_index == EXIT_BLOCK)
978 /* The exit block is special for this problem and its bits are
979 computed from thin air. */
980 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
981 bitmap_copy (bb_info->use, df->exit_block_uses);
983 else
984 df_lr_bb_local_compute (bb_index);
987 bitmap_clear (df_lr->out_of_date_transfer_functions);
991 /* Initialize the solution vectors. */
993 static void
994 df_lr_init (bitmap all_blocks)
996 unsigned int bb_index;
997 bitmap_iterator bi;
999 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1001 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1002 bitmap_copy (bb_info->in, bb_info->use);
1003 bitmap_clear (bb_info->out);
1008 /* Confluence function that processes infinite loops. This might be a
1009 noreturn function that throws. And even if it isn't, getting the
1010 unwind info right helps debugging. */
1011 static void
1012 df_lr_confluence_0 (basic_block bb)
1014 bitmap op1 = df_lr_get_bb_info (bb->index)->out;
1015 if (bb != EXIT_BLOCK_PTR)
1016 bitmap_copy (op1, df->hardware_regs_used);
1020 /* Confluence function that ignores fake edges. */
1022 static void
1023 df_lr_confluence_n (edge e)
1025 bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
1026 bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
1028 /* Call-clobbered registers die across exception and call edges. */
1029 /* ??? Abnormal call edges ignored for the moment, as this gets
1030 confused by sibling call edges, which crashes reg-stack. */
1031 if (e->flags & EDGE_EH)
1032 bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
1033 else
1034 bitmap_ior_into (op1, op2);
1036 bitmap_ior_into (op1, df->hardware_regs_used);
1040 /* Transfer function. */
1042 static bool
1043 df_lr_transfer_function (int bb_index)
1045 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1046 bitmap in = bb_info->in;
1047 bitmap out = bb_info->out;
1048 bitmap use = bb_info->use;
1049 bitmap def = bb_info->def;
1051 return bitmap_ior_and_compl (in, use, out, def);
1055 /* Run the fast dce as a side effect of building LR. */
1057 static void
1058 df_lr_finalize (bitmap all_blocks)
1060 df_lr->solutions_dirty = false;
1061 if (df->changeable_flags & DF_LR_RUN_DCE)
1063 run_fast_df_dce ();
1065 /* If dce deletes some instructions, we need to recompute the lr
1066 solution before proceeding further. The problem is that fast
1067 dce is a pessimestic dataflow algorithm. In the case where
1068 it deletes a statement S inside of a loop, the uses inside of
1069 S may not be deleted from the dataflow solution because they
1070 were carried around the loop. While it is conservatively
1071 correct to leave these extra bits, the standards of df
1072 require that we maintain the best possible (least fixed
1073 point) solution. The only way to do that is to redo the
1074 iteration from the beginning. See PR35805 for an
1075 example. */
1076 if (df_lr->solutions_dirty)
1078 df_clear_flags (DF_LR_RUN_DCE);
1079 df_lr_alloc (all_blocks);
1080 df_lr_local_compute (all_blocks);
1081 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1082 df_lr_finalize (all_blocks);
1083 df_set_flags (DF_LR_RUN_DCE);
1089 /* Free all storage associated with the problem. */
1091 static void
1092 df_lr_free (void)
1094 if (df_lr->block_info)
1096 unsigned int i;
1097 for (i = 0; i < df_lr->block_info_size; i++)
1099 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
1100 if (bb_info)
1102 BITMAP_FREE (bb_info->use);
1103 BITMAP_FREE (bb_info->def);
1104 BITMAP_FREE (bb_info->in);
1105 BITMAP_FREE (bb_info->out);
1108 free_alloc_pool (df_lr->block_pool);
1110 df_lr->block_info_size = 0;
1111 free (df_lr->block_info);
1114 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1115 free (df_lr);
1119 /* Debugging info at top of bb. */
1121 static void
1122 df_lr_top_dump (basic_block bb, FILE *file)
1124 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1125 struct df_lr_problem_data *problem_data;
1126 if (!bb_info || !bb_info->in)
1127 return;
1129 fprintf (file, ";; lr in \t");
1130 df_print_regset (file, bb_info->in);
1131 if (df_lr->problem_data)
1133 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1134 fprintf (file, ";; old in \t");
1135 df_print_regset (file, problem_data->in[bb->index]);
1137 fprintf (file, ";; lr use \t");
1138 df_print_regset (file, bb_info->use);
1139 fprintf (file, ";; lr def \t");
1140 df_print_regset (file, bb_info->def);
1144 /* Debugging info at bottom of bb. */
1146 static void
1147 df_lr_bottom_dump (basic_block bb, FILE *file)
1149 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1150 struct df_lr_problem_data *problem_data;
1151 if (!bb_info || !bb_info->out)
1152 return;
1154 fprintf (file, ";; lr out \t");
1155 df_print_regset (file, bb_info->out);
1156 if (df_lr->problem_data)
1158 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1159 fprintf (file, ";; old out \t");
1160 df_print_regset (file, problem_data->out[bb->index]);
1165 /* Build the datastructure to verify that the solution to the dataflow
1166 equations is not dirty. */
1168 static void
1169 df_lr_verify_solution_start (void)
1171 basic_block bb;
1172 struct df_lr_problem_data *problem_data;
1173 if (df_lr->solutions_dirty)
1175 df_lr->problem_data = NULL;
1176 return;
1179 /* Set it true so that the solution is recomputed. */
1180 df_lr->solutions_dirty = true;
1182 problem_data = XNEW (struct df_lr_problem_data);
1183 df_lr->problem_data = problem_data;
1184 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1185 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1187 FOR_ALL_BB (bb)
1189 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1190 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1191 bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
1192 bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
1197 /* Compare the saved datastructure and the new solution to the dataflow
1198 equations. */
1200 static void
1201 df_lr_verify_solution_end (void)
1203 struct df_lr_problem_data *problem_data;
1204 basic_block bb;
1206 if (df_lr->problem_data == NULL)
1207 return;
1209 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1211 if (df_lr->solutions_dirty)
1212 /* Do not check if the solution is still dirty. See the comment
1213 in df_lr_finalize for details. */
1214 df_lr->solutions_dirty = false;
1215 else
1216 FOR_ALL_BB (bb)
1218 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
1219 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
1221 /*df_dump (stderr);*/
1222 gcc_unreachable ();
1226 /* Cannot delete them immediately because you may want to dump them
1227 if the comparison fails. */
1228 FOR_ALL_BB (bb)
1230 BITMAP_FREE (problem_data->in[bb->index]);
1231 BITMAP_FREE (problem_data->out[bb->index]);
1234 free (problem_data->in);
1235 free (problem_data->out);
1236 free (problem_data);
1237 df_lr->problem_data = NULL;
1241 /* All of the information associated with every instance of the problem. */
1243 static struct df_problem problem_LR =
1245 DF_LR, /* Problem id. */
1246 DF_BACKWARD, /* Direction. */
1247 df_lr_alloc, /* Allocate the problem specific data. */
1248 df_lr_reset, /* Reset global information. */
1249 df_lr_free_bb_info, /* Free basic block info. */
1250 df_lr_local_compute, /* Local compute function. */
1251 df_lr_init, /* Init the solution specific data. */
1252 df_worklist_dataflow, /* Worklist solver. */
1253 df_lr_confluence_0, /* Confluence operator 0. */
1254 df_lr_confluence_n, /* Confluence operator n. */
1255 df_lr_transfer_function, /* Transfer function. */
1256 df_lr_finalize, /* Finalize function. */
1257 df_lr_free, /* Free all of the problem information. */
1258 NULL, /* Remove this problem from the stack of dataflow problems. */
1259 NULL, /* Debugging. */
1260 df_lr_top_dump, /* Debugging start block. */
1261 df_lr_bottom_dump, /* Debugging end block. */
1262 df_lr_verify_solution_start,/* Incremental solution verify start. */
1263 df_lr_verify_solution_end, /* Incremental solution verify end. */
1264 NULL, /* Dependent problem. */
1265 TV_DF_LR, /* Timing variable. */
1266 false /* Reset blocks on dropping out of blocks_to_analyze. */
1270 /* Create a new DATAFLOW instance and add it to an existing instance
1271 of DF. The returned structure is what is used to get at the
1272 solution. */
1274 void
1275 df_lr_add_problem (void)
1277 df_add_problem (&problem_LR);
1278 /* These will be initialized when df_scan_blocks processes each
1279 block. */
1280 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1284 /* Verify that all of the lr related info is consistent and
1285 correct. */
1287 void
1288 df_lr_verify_transfer_functions (void)
1290 basic_block bb;
1291 bitmap saved_def;
1292 bitmap saved_use;
1293 bitmap saved_adef;
1294 bitmap saved_ause;
1295 bitmap all_blocks;
1297 if (!df)
1298 return;
1300 saved_def = BITMAP_ALLOC (NULL);
1301 saved_use = BITMAP_ALLOC (NULL);
1302 saved_adef = BITMAP_ALLOC (NULL);
1303 saved_ause = BITMAP_ALLOC (NULL);
1304 all_blocks = BITMAP_ALLOC (NULL);
1306 FOR_ALL_BB (bb)
1308 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1309 bitmap_set_bit (all_blocks, bb->index);
1311 if (bb_info)
1313 /* Make a copy of the transfer functions and then compute
1314 new ones to see if the transfer functions have
1315 changed. */
1316 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1317 bb->index))
1319 bitmap_copy (saved_def, bb_info->def);
1320 bitmap_copy (saved_use, bb_info->use);
1321 bitmap_clear (bb_info->def);
1322 bitmap_clear (bb_info->use);
1324 df_lr_bb_local_compute (bb->index);
1325 gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
1326 gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
1329 else
1331 /* If we do not have basic block info, the block must be in
1332 the list of dirty blocks or else some one has added a
1333 block behind our backs. */
1334 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1335 bb->index));
1337 /* Make sure no one created a block without following
1338 procedures. */
1339 gcc_assert (df_scan_get_bb_info (bb->index));
1342 /* Make sure there are no dirty bits in blocks that have been deleted. */
1343 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1344 all_blocks));
1346 BITMAP_FREE (saved_def);
1347 BITMAP_FREE (saved_use);
1348 BITMAP_FREE (saved_adef);
1349 BITMAP_FREE (saved_ause);
1350 BITMAP_FREE (all_blocks);
1355 /*----------------------------------------------------------------------------
1356 LIVE AND MUST-INITIALIZED REGISTERS.
1358 This problem first computes the IN and OUT bitvectors for the
1359 must-initialized registers problems, which is a forward problem.
1360 It gives the set of registers for which we MUST have an available
1361 definition on any path from the entry block to the entry/exit of
1362 a basic block. Sets generate a definition, while clobbers kill
1363 a definition.
1365 In and out bitvectors are built for each basic block and are indexed by
1366 regnum (see df.h for details). In and out bitvectors in struct
1367 df_live_bb_info actually refers to the must-initialized problem;
1369 Then, the in and out sets for the LIVE problem itself are computed.
1370 These are the logical AND of the IN and OUT sets from the LR problem
1371 and the must-initialized problem.
1372 ----------------------------------------------------------------------------*/
1374 /* Private data used to verify the solution for this problem. */
1375 struct df_live_problem_data
1377 bitmap *in;
1378 bitmap *out;
1381 /* Scratch var used by transfer functions. This is used to implement
1382 an optimization to reduce the amount of space used to compute the
1383 combined lr and live analysis. */
1384 static bitmap df_live_scratch;
1386 /* Set basic block info. */
1388 static void
1389 df_live_set_bb_info (unsigned int index,
1390 struct df_live_bb_info *bb_info)
1392 gcc_assert (df_live);
1393 gcc_assert (index < df_live->block_info_size);
1394 df_live->block_info[index] = bb_info;
1398 /* Free basic block info. */
1400 static void
1401 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1402 void *vbb_info)
1404 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1405 if (bb_info)
1407 BITMAP_FREE (bb_info->gen);
1408 BITMAP_FREE (bb_info->kill);
1409 BITMAP_FREE (bb_info->in);
1410 BITMAP_FREE (bb_info->out);
1411 pool_free (df_live->block_pool, bb_info);
1416 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1417 not touched unless the block is new. */
1419 static void
1420 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1422 unsigned int bb_index;
1423 bitmap_iterator bi;
1425 if (!df_live->block_pool)
1426 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1427 sizeof (struct df_live_bb_info), 100);
1428 if (!df_live_scratch)
1429 df_live_scratch = BITMAP_ALLOC (NULL);
1431 df_grow_bb_info (df_live);
1433 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1435 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1436 if (bb_info)
1438 bitmap_clear (bb_info->kill);
1439 bitmap_clear (bb_info->gen);
1441 else
1443 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1444 df_live_set_bb_info (bb_index, bb_info);
1445 bb_info->kill = BITMAP_ALLOC (NULL);
1446 bb_info->gen = BITMAP_ALLOC (NULL);
1447 bb_info->in = BITMAP_ALLOC (NULL);
1448 bb_info->out = BITMAP_ALLOC (NULL);
1451 df_live->optional_p = (optimize <= 1);
1455 /* Reset the global solution for recalculation. */
1457 static void
1458 df_live_reset (bitmap all_blocks)
1460 unsigned int bb_index;
1461 bitmap_iterator bi;
1463 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1465 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1466 gcc_assert (bb_info);
1467 bitmap_clear (bb_info->in);
1468 bitmap_clear (bb_info->out);
1473 /* Compute local uninitialized register info for basic block BB. */
1475 static void
1476 df_live_bb_local_compute (unsigned int bb_index)
1478 basic_block bb = BASIC_BLOCK (bb_index);
1479 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1480 rtx insn;
1481 df_ref *def_rec;
1482 int luid = 0;
1484 FOR_BB_INSNS (bb, insn)
1486 unsigned int uid = INSN_UID (insn);
1487 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1489 /* Inserting labels does not always trigger the incremental
1490 rescanning. */
1491 if (!insn_info)
1493 gcc_assert (!INSN_P (insn));
1494 insn_info = df_insn_create_insn_record (insn);
1497 DF_INSN_INFO_LUID (insn_info) = luid;
1498 if (!INSN_P (insn))
1499 continue;
1501 luid++;
1502 for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)
1504 df_ref def = *def_rec;
1505 unsigned int regno = DF_REF_REGNO (def);
1507 if (DF_REF_FLAGS_IS_SET (def,
1508 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1509 /* All partial or conditional def
1510 seen are included in the gen set. */
1511 bitmap_set_bit (bb_info->gen, regno);
1512 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1513 /* Only must clobbers for the entire reg destroy the
1514 value. */
1515 bitmap_set_bit (bb_info->kill, regno);
1516 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1517 bitmap_set_bit (bb_info->gen, regno);
1521 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1523 df_ref def = *def_rec;
1524 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1529 /* Compute local uninitialized register info. */
1531 static void
1532 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1534 unsigned int bb_index;
1535 bitmap_iterator bi;
1537 df_grow_insn_info ();
1539 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1540 0, bb_index, bi)
1542 df_live_bb_local_compute (bb_index);
1545 bitmap_clear (df_live->out_of_date_transfer_functions);
1549 /* Initialize the solution vectors. */
1551 static void
1552 df_live_init (bitmap all_blocks)
1554 unsigned int bb_index;
1555 bitmap_iterator bi;
1557 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1559 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1560 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1562 /* No register may reach a location where it is not used. Thus
1563 we trim the rr result to the places where it is used. */
1564 bitmap_and (bb_info->out, bb_info->gen, bb_lr_info->out);
1565 bitmap_clear (bb_info->in);
1569 /* Forward confluence function that ignores fake edges. */
1571 static void
1572 df_live_confluence_n (edge e)
1574 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
1575 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
1577 if (e->flags & EDGE_FAKE)
1578 return;
1580 bitmap_ior_into (op1, op2);
1584 /* Transfer function for the forwards must-initialized problem. */
1586 static bool
1587 df_live_transfer_function (int bb_index)
1589 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1590 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1591 bitmap in = bb_info->in;
1592 bitmap out = bb_info->out;
1593 bitmap gen = bb_info->gen;
1594 bitmap kill = bb_info->kill;
1596 /* We need to use a scratch set here so that the value returned from
1597 this function invocation properly reflects if the sets changed in
1598 a significant way; i.e. not just because the lr set was anded
1599 in. */
1600 bitmap_and (df_live_scratch, gen, bb_lr_info->out);
1601 /* No register may reach a location where it is not used. Thus
1602 we trim the rr result to the places where it is used. */
1603 bitmap_and_into (in, bb_lr_info->in);
1605 return bitmap_ior_and_compl (out, df_live_scratch, in, kill);
1609 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1611 static void
1612 df_live_finalize (bitmap all_blocks)
1615 if (df_live->solutions_dirty)
1617 bitmap_iterator bi;
1618 unsigned int bb_index;
1620 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1622 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1623 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1625 /* No register may reach a location where it is not used. Thus
1626 we trim the rr result to the places where it is used. */
1627 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
1628 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
1631 df_live->solutions_dirty = false;
1636 /* Free all storage associated with the problem. */
1638 static void
1639 df_live_free (void)
1641 if (df_live->block_info)
1643 unsigned int i;
1645 for (i = 0; i < df_live->block_info_size; i++)
1647 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
1648 if (bb_info)
1650 BITMAP_FREE (bb_info->gen);
1651 BITMAP_FREE (bb_info->kill);
1652 BITMAP_FREE (bb_info->in);
1653 BITMAP_FREE (bb_info->out);
1657 free_alloc_pool (df_live->block_pool);
1658 df_live->block_info_size = 0;
1659 free (df_live->block_info);
1661 if (df_live_scratch)
1662 BITMAP_FREE (df_live_scratch);
1664 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1665 free (df_live);
1669 /* Debugging info at top of bb. */
1671 static void
1672 df_live_top_dump (basic_block bb, FILE *file)
1674 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1675 struct df_live_problem_data *problem_data;
1677 if (!bb_info || !bb_info->in)
1678 return;
1680 fprintf (file, ";; live in \t");
1681 df_print_regset (file, bb_info->in);
1682 if (df_live->problem_data)
1684 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1685 fprintf (file, ";; old in \t");
1686 df_print_regset (file, problem_data->in[bb->index]);
1688 fprintf (file, ";; live gen \t");
1689 df_print_regset (file, bb_info->gen);
1690 fprintf (file, ";; live kill\t");
1691 df_print_regset (file, bb_info->kill);
1695 /* Debugging info at bottom of bb. */
1697 static void
1698 df_live_bottom_dump (basic_block bb, FILE *file)
1700 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1701 struct df_live_problem_data *problem_data;
1703 if (!bb_info || !bb_info->out)
1704 return;
1706 fprintf (file, ";; live out \t");
1707 df_print_regset (file, bb_info->out);
1708 if (df_live->problem_data)
1710 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1711 fprintf (file, ";; old out \t");
1712 df_print_regset (file, problem_data->out[bb->index]);
1717 /* Build the datastructure to verify that the solution to the dataflow
1718 equations is not dirty. */
1720 static void
1721 df_live_verify_solution_start (void)
1723 basic_block bb;
1724 struct df_live_problem_data *problem_data;
1725 if (df_live->solutions_dirty)
1727 df_live->problem_data = NULL;
1728 return;
1731 /* Set it true so that the solution is recomputed. */
1732 df_live->solutions_dirty = true;
1734 problem_data = XNEW (struct df_live_problem_data);
1735 df_live->problem_data = problem_data;
1736 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1737 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1739 FOR_ALL_BB (bb)
1741 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1742 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1743 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
1744 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
1749 /* Compare the saved datastructure and the new solution to the dataflow
1750 equations. */
1752 static void
1753 df_live_verify_solution_end (void)
1755 struct df_live_problem_data *problem_data;
1756 basic_block bb;
1758 if (df_live->problem_data == NULL)
1759 return;
1761 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1763 FOR_ALL_BB (bb)
1765 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
1766 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1768 /*df_dump (stderr);*/
1769 gcc_unreachable ();
1773 /* Cannot delete them immediately because you may want to dump them
1774 if the comparison fails. */
1775 FOR_ALL_BB (bb)
1777 BITMAP_FREE (problem_data->in[bb->index]);
1778 BITMAP_FREE (problem_data->out[bb->index]);
1781 free (problem_data->in);
1782 free (problem_data->out);
1783 free (problem_data);
1784 df_live->problem_data = NULL;
1788 /* All of the information associated with every instance of the problem. */
1790 static struct df_problem problem_LIVE =
1792 DF_LIVE, /* Problem id. */
1793 DF_FORWARD, /* Direction. */
1794 df_live_alloc, /* Allocate the problem specific data. */
1795 df_live_reset, /* Reset global information. */
1796 df_live_free_bb_info, /* Free basic block info. */
1797 df_live_local_compute, /* Local compute function. */
1798 df_live_init, /* Init the solution specific data. */
1799 df_worklist_dataflow, /* Worklist solver. */
1800 NULL, /* Confluence operator 0. */
1801 df_live_confluence_n, /* Confluence operator n. */
1802 df_live_transfer_function, /* Transfer function. */
1803 df_live_finalize, /* Finalize function. */
1804 df_live_free, /* Free all of the problem information. */
1805 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1806 NULL, /* Debugging. */
1807 df_live_top_dump, /* Debugging start block. */
1808 df_live_bottom_dump, /* Debugging end block. */
1809 df_live_verify_solution_start,/* Incremental solution verify start. */
1810 df_live_verify_solution_end, /* Incremental solution verify end. */
1811 &problem_LR, /* Dependent problem. */
1812 TV_DF_LIVE, /* Timing variable. */
1813 false /* Reset blocks on dropping out of blocks_to_analyze. */
1817 /* Create a new DATAFLOW instance and add it to an existing instance
1818 of DF. The returned structure is what is used to get at the
1819 solution. */
1821 void
1822 df_live_add_problem (void)
1824 df_add_problem (&problem_LIVE);
1825 /* These will be initialized when df_scan_blocks processes each
1826 block. */
1827 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1831 /* Set all of the blocks as dirty. This needs to be done if this
1832 problem is added after all of the insns have been scanned. */
1834 void
1835 df_live_set_all_dirty (void)
1837 basic_block bb;
1838 FOR_ALL_BB (bb)
1839 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1840 bb->index);
1844 /* Verify that all of the lr related info is consistent and
1845 correct. */
1847 void
1848 df_live_verify_transfer_functions (void)
1850 basic_block bb;
1851 bitmap saved_gen;
1852 bitmap saved_kill;
1853 bitmap all_blocks;
1855 if (!df)
1856 return;
1858 saved_gen = BITMAP_ALLOC (NULL);
1859 saved_kill = BITMAP_ALLOC (NULL);
1860 all_blocks = BITMAP_ALLOC (NULL);
1862 df_grow_insn_info ();
1864 FOR_ALL_BB (bb)
1866 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1867 bitmap_set_bit (all_blocks, bb->index);
1869 if (bb_info)
1871 /* Make a copy of the transfer functions and then compute
1872 new ones to see if the transfer functions have
1873 changed. */
1874 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1875 bb->index))
1877 bitmap_copy (saved_gen, bb_info->gen);
1878 bitmap_copy (saved_kill, bb_info->kill);
1879 bitmap_clear (bb_info->gen);
1880 bitmap_clear (bb_info->kill);
1882 df_live_bb_local_compute (bb->index);
1883 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
1884 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
1887 else
1889 /* If we do not have basic block info, the block must be in
1890 the list of dirty blocks or else some one has added a
1891 block behind our backs. */
1892 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1893 bb->index));
1895 /* Make sure no one created a block without following
1896 procedures. */
1897 gcc_assert (df_scan_get_bb_info (bb->index));
1900 /* Make sure there are no dirty bits in blocks that have been deleted. */
1901 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1902 all_blocks));
1903 BITMAP_FREE (saved_gen);
1904 BITMAP_FREE (saved_kill);
1905 BITMAP_FREE (all_blocks);
1908 /*----------------------------------------------------------------------------
1909 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1911 Link either the defs to the uses and / or the uses to the defs.
1913 These problems are set up like the other dataflow problems so that
1914 they nicely fit into the framework. They are much simpler and only
1915 involve a single traversal of instructions and an examination of
1916 the reaching defs information (the dependent problem).
1917 ----------------------------------------------------------------------------*/
1919 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1921 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1923 struct df_link *
1924 df_chain_create (df_ref src, df_ref dst)
1926 struct df_link *head = DF_REF_CHAIN (src);
1927 struct df_link *link = (struct df_link *) pool_alloc (df_chain->block_pool);
1929 DF_REF_CHAIN (src) = link;
1930 link->next = head;
1931 link->ref = dst;
1932 return link;
1936 /* Delete any du or ud chains that start at REF and point to
1937 TARGET. */
1938 static void
1939 df_chain_unlink_1 (df_ref ref, df_ref target)
1941 struct df_link *chain = DF_REF_CHAIN (ref);
1942 struct df_link *prev = NULL;
1944 while (chain)
1946 if (chain->ref == target)
1948 if (prev)
1949 prev->next = chain->next;
1950 else
1951 DF_REF_CHAIN (ref) = chain->next;
1952 pool_free (df_chain->block_pool, chain);
1953 return;
1955 prev = chain;
1956 chain = chain->next;
1961 /* Delete a du or ud chain that leave or point to REF. */
1963 void
1964 df_chain_unlink (df_ref ref)
1966 struct df_link *chain = DF_REF_CHAIN (ref);
1967 while (chain)
1969 struct df_link *next = chain->next;
1970 /* Delete the other side if it exists. */
1971 df_chain_unlink_1 (chain->ref, ref);
1972 pool_free (df_chain->block_pool, chain);
1973 chain = next;
1975 DF_REF_CHAIN (ref) = NULL;
1979 /* Copy the du or ud chain starting at FROM_REF and attach it to
1980 TO_REF. */
1982 void
1983 df_chain_copy (df_ref to_ref,
1984 struct df_link *from_ref)
1986 while (from_ref)
1988 df_chain_create (to_ref, from_ref->ref);
1989 from_ref = from_ref->next;
1994 /* Remove this problem from the stack of dataflow problems. */
1996 static void
1997 df_chain_remove_problem (void)
1999 bitmap_iterator bi;
2000 unsigned int bb_index;
2002 /* Wholesale destruction of the old chains. */
2003 if (df_chain->block_pool)
2004 free_alloc_pool (df_chain->block_pool);
2006 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
2008 rtx insn;
2009 df_ref *def_rec;
2010 df_ref *use_rec;
2011 basic_block bb = BASIC_BLOCK (bb_index);
2013 if (df_chain_problem_p (DF_DU_CHAIN))
2014 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
2015 DF_REF_CHAIN (*def_rec) = NULL;
2016 if (df_chain_problem_p (DF_UD_CHAIN))
2017 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
2018 DF_REF_CHAIN (*use_rec) = NULL;
2020 FOR_BB_INSNS (bb, insn)
2022 unsigned int uid = INSN_UID (insn);
2024 if (INSN_P (insn))
2026 if (df_chain_problem_p (DF_DU_CHAIN))
2027 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2028 DF_REF_CHAIN (*def_rec) = NULL;
2029 if (df_chain_problem_p (DF_UD_CHAIN))
2031 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2032 DF_REF_CHAIN (*use_rec) = NULL;
2033 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
2034 DF_REF_CHAIN (*use_rec) = NULL;
2040 bitmap_clear (df_chain->out_of_date_transfer_functions);
2041 df_chain->block_pool = NULL;
2045 /* Remove the chain problem completely. */
2047 static void
2048 df_chain_fully_remove_problem (void)
2050 df_chain_remove_problem ();
2051 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2052 free (df_chain);
2056 /* Create def-use or use-def chains. */
2058 static void
2059 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2061 df_chain_remove_problem ();
2062 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2063 sizeof (struct df_link), 50);
2064 df_chain->optional_p = true;
2068 /* Reset all of the chains when the set of basic blocks changes. */
2070 static void
2071 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2073 df_chain_remove_problem ();
2077 /* Create the chains for a list of USEs. */
2079 static void
2080 df_chain_create_bb_process_use (bitmap local_rd,
2081 df_ref *use_rec,
2082 int top_flag)
2084 bitmap_iterator bi;
2085 unsigned int def_index;
2087 while (*use_rec)
2089 df_ref use = *use_rec;
2090 unsigned int uregno = DF_REF_REGNO (use);
2091 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2092 || (uregno >= FIRST_PSEUDO_REGISTER))
2094 /* Do not want to go through this for an uninitialized var. */
2095 int count = DF_DEFS_COUNT (uregno);
2096 if (count)
2098 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2100 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2101 unsigned int last_index = first_index + count - 1;
2103 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2105 df_ref def;
2106 if (def_index > last_index)
2107 break;
2109 def = DF_DEFS_GET (def_index);
2110 if (df_chain_problem_p (DF_DU_CHAIN))
2111 df_chain_create (def, use);
2112 if (df_chain_problem_p (DF_UD_CHAIN))
2113 df_chain_create (use, def);
2119 use_rec++;
2124 /* Create chains from reaching defs bitmaps for basic block BB. */
2126 static void
2127 df_chain_create_bb (unsigned int bb_index)
2129 basic_block bb = BASIC_BLOCK (bb_index);
2130 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2131 rtx insn;
2132 bitmap cpy = BITMAP_ALLOC (NULL);
2134 bitmap_copy (cpy, bb_info->in);
2135 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2137 /* Since we are going forwards, process the artificial uses first
2138 then the artificial defs second. */
2140 #ifdef EH_USES
2141 /* Create the chains for the artificial uses from the EH_USES at the
2142 beginning of the block. */
2144 /* Artificials are only hard regs. */
2145 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2146 df_chain_create_bb_process_use (cpy,
2147 df_get_artificial_uses (bb->index),
2148 DF_REF_AT_TOP);
2149 #endif
2151 df_rd_simulate_artificial_defs_at_top (bb, cpy);
2153 /* Process the regular instructions next. */
2154 FOR_BB_INSNS (bb, insn)
2155 if (INSN_P (insn))
2157 unsigned int uid = INSN_UID (insn);
2159 /* First scan the uses and link them up with the defs that remain
2160 in the cpy vector. */
2161 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
2162 if (df->changeable_flags & DF_EQ_NOTES)
2163 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
2165 /* Since we are going forwards, process the defs second. */
2166 df_rd_simulate_one_insn (bb, insn, cpy);
2169 /* Create the chains for the artificial uses of the hard registers
2170 at the end of the block. */
2171 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2172 df_chain_create_bb_process_use (cpy,
2173 df_get_artificial_uses (bb->index),
2176 BITMAP_FREE (cpy);
2179 /* Create def-use chains from reaching use bitmaps for basic blocks
2180 in BLOCKS. */
2182 static void
2183 df_chain_finalize (bitmap all_blocks)
2185 unsigned int bb_index;
2186 bitmap_iterator bi;
2188 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2190 df_chain_create_bb (bb_index);
2195 /* Free all storage associated with the problem. */
2197 static void
2198 df_chain_free (void)
2200 free_alloc_pool (df_chain->block_pool);
2201 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2202 free (df_chain);
2206 /* Debugging info. */
2208 static void
2209 df_chain_top_dump (basic_block bb, FILE *file)
2211 if (df_chain_problem_p (DF_DU_CHAIN))
2213 rtx insn;
2214 df_ref *def_rec = df_get_artificial_defs (bb->index);
2215 if (*def_rec)
2218 fprintf (file, ";; DU chains for artificial defs\n");
2219 while (*def_rec)
2221 df_ref def = *def_rec;
2222 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2223 df_chain_dump (DF_REF_CHAIN (def), file);
2224 fprintf (file, "\n");
2225 def_rec++;
2229 FOR_BB_INSNS (bb, insn)
2231 if (INSN_P (insn))
2233 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2234 def_rec = DF_INSN_INFO_DEFS (insn_info);
2235 if (*def_rec)
2237 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2238 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2240 while (*def_rec)
2242 df_ref def = *def_rec;
2243 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2244 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2245 fprintf (file, "read/write ");
2246 df_chain_dump (DF_REF_CHAIN (def), file);
2247 fprintf (file, "\n");
2248 def_rec++;
2257 static void
2258 df_chain_bottom_dump (basic_block bb, FILE *file)
2260 if (df_chain_problem_p (DF_UD_CHAIN))
2262 rtx insn;
2263 df_ref *use_rec = df_get_artificial_uses (bb->index);
2265 if (*use_rec)
2267 fprintf (file, ";; UD chains for artificial uses\n");
2268 while (*use_rec)
2270 df_ref use = *use_rec;
2271 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2272 df_chain_dump (DF_REF_CHAIN (use), file);
2273 fprintf (file, "\n");
2274 use_rec++;
2278 FOR_BB_INSNS (bb, insn)
2280 if (INSN_P (insn))
2282 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2283 df_ref *eq_use_rec = DF_INSN_INFO_EQ_USES (insn_info);
2284 use_rec = DF_INSN_INFO_USES (insn_info);
2285 if (*use_rec || *eq_use_rec)
2287 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2288 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2290 while (*use_rec)
2292 df_ref use = *use_rec;
2293 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2294 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2295 fprintf (file, "read/write ");
2296 df_chain_dump (DF_REF_CHAIN (use), file);
2297 fprintf (file, "\n");
2298 use_rec++;
2300 while (*eq_use_rec)
2302 df_ref use = *eq_use_rec;
2303 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2304 df_chain_dump (DF_REF_CHAIN (use), file);
2305 fprintf (file, "\n");
2306 eq_use_rec++;
2315 static struct df_problem problem_CHAIN =
2317 DF_CHAIN, /* Problem id. */
2318 DF_NONE, /* Direction. */
2319 df_chain_alloc, /* Allocate the problem specific data. */
2320 df_chain_reset, /* Reset global information. */
2321 NULL, /* Free basic block info. */
2322 NULL, /* Local compute function. */
2323 NULL, /* Init the solution specific data. */
2324 NULL, /* Iterative solver. */
2325 NULL, /* Confluence operator 0. */
2326 NULL, /* Confluence operator n. */
2327 NULL, /* Transfer function. */
2328 df_chain_finalize, /* Finalize function. */
2329 df_chain_free, /* Free all of the problem information. */
2330 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2331 NULL, /* Debugging. */
2332 df_chain_top_dump, /* Debugging start block. */
2333 df_chain_bottom_dump, /* Debugging end block. */
2334 NULL, /* Incremental solution verify start. */
2335 NULL, /* Incremental solution verify end. */
2336 &problem_RD, /* Dependent problem. */
2337 TV_DF_CHAIN, /* Timing variable. */
2338 false /* Reset blocks on dropping out of blocks_to_analyze. */
2342 /* Create a new DATAFLOW instance and add it to an existing instance
2343 of DF. The returned structure is what is used to get at the
2344 solution. */
2346 void
2347 df_chain_add_problem (unsigned int chain_flags)
2349 df_add_problem (&problem_CHAIN);
2350 df_chain->local_flags = chain_flags;
2351 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2354 #undef df_chain_problem_p
2357 /*----------------------------------------------------------------------------
2358 BYTE LEVEL LIVE REGISTERS
2360 Find the locations in the function where any use of a pseudo can
2361 reach in the backwards direction. In and out bitvectors are built
2362 for each basic block. There are two mapping functions,
2363 df_byte_lr_get_regno_start and df_byte_lr_get_regno_len that are
2364 used to map regnos into bit vector positions.
2366 This problem differs from the regular df_lr function in the way
2367 that subregs, *_extracts and strict_low_parts are handled. In lr
2368 these are consider partial kills, here, the exact set of bytes is
2369 modeled. Note that any reg that has none of these operations is
2370 only modeled with a single bit since all operations access the
2371 entire register.
2373 This problem is more brittle that the regular lr. It currently can
2374 be used in dce incrementally, but cannot be used in an environment
2375 where insns are created or modified. The problem is that the
2376 mapping of regnos to bitmap positions is relatively compact, in
2377 that if a pseudo does not do any of the byte wise operations, only
2378 one slot is allocated, rather than a slot for each byte. If insn
2379 are created, where a subreg is used for a reg that had no subregs,
2380 the mapping would be wrong. Likewise, there are no checks to see
2381 that new pseudos have been added. These issues could be addressed
2382 by adding a problem specific flag to not use the compact mapping,
2383 if there was a need to do so.
2385 ----------------------------------------------------------------------------*/
2387 /* Private data used to verify the solution for this problem. */
2388 struct df_byte_lr_problem_data
2390 /* Expanded versions of bitvectors used in lr. */
2391 bitmap invalidated_by_call;
2392 bitmap hardware_regs_used;
2394 /* Indexed by regno, this is true if there are subregs, extracts or
2395 strict_low_parts for this regno. */
2396 bitmap needs_expansion;
2398 /* The start position and len for each regno in the various bit
2399 vectors. */
2400 unsigned int* regno_start;
2401 unsigned int* regno_len;
2402 /* An obstack for the bitmaps we need for this problem. */
2403 bitmap_obstack byte_lr_bitmaps;
2407 /* Get the starting location for REGNO in the df_byte_lr bitmaps. */
2409 int
2410 df_byte_lr_get_regno_start (unsigned int regno)
2412 struct df_byte_lr_problem_data *problem_data
2413 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;;
2414 return problem_data->regno_start[regno];
2418 /* Get the len for REGNO in the df_byte_lr bitmaps. */
2420 int
2421 df_byte_lr_get_regno_len (unsigned int regno)
2423 struct df_byte_lr_problem_data *problem_data
2424 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;;
2425 return problem_data->regno_len[regno];
2429 /* Set basic block info. */
2431 static void
2432 df_byte_lr_set_bb_info (unsigned int index,
2433 struct df_byte_lr_bb_info *bb_info)
2435 gcc_assert (df_byte_lr);
2436 gcc_assert (index < df_byte_lr->block_info_size);
2437 df_byte_lr->block_info[index] = bb_info;
2441 /* Free basic block info. */
2443 static void
2444 df_byte_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2445 void *vbb_info)
2447 struct df_byte_lr_bb_info *bb_info = (struct df_byte_lr_bb_info *) vbb_info;
2448 if (bb_info)
2450 BITMAP_FREE (bb_info->use);
2451 BITMAP_FREE (bb_info->def);
2452 BITMAP_FREE (bb_info->in);
2453 BITMAP_FREE (bb_info->out);
2454 pool_free (df_byte_lr->block_pool, bb_info);
2459 /* Check all of the refs in REF_REC to see if any of them are
2460 extracts, subregs or strict_low_parts. */
2462 static void
2463 df_byte_lr_check_regs (df_ref *ref_rec)
2465 struct df_byte_lr_problem_data *problem_data
2466 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2468 for (; *ref_rec; ref_rec++)
2470 df_ref ref = *ref_rec;
2471 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_SIGN_EXTRACT
2472 | DF_REF_ZERO_EXTRACT
2473 | DF_REF_STRICT_LOW_PART)
2474 || GET_CODE (DF_REF_REG (ref)) == SUBREG)
2475 bitmap_set_bit (problem_data->needs_expansion, DF_REF_REGNO (ref));
2480 /* Expand bitmap SRC which is indexed by regno to DEST which is indexed by
2481 regno_start and regno_len. */
2483 static void
2484 df_byte_lr_expand_bitmap (bitmap dest, bitmap src)
2486 struct df_byte_lr_problem_data *problem_data
2487 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2488 bitmap_iterator bi;
2489 unsigned int i;
2491 bitmap_clear (dest);
2492 EXECUTE_IF_SET_IN_BITMAP (src, 0, i, bi)
2494 bitmap_set_range (dest, problem_data->regno_start[i],
2495 problem_data->regno_len[i]);
2500 /* Allocate or reset bitmaps for DF_BYTE_LR blocks. The solution bits are
2501 not touched unless the block is new. */
2503 static void
2504 df_byte_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2506 unsigned int bb_index;
2507 bitmap_iterator bi;
2508 basic_block bb;
2509 unsigned int regno;
2510 unsigned int index = 0;
2511 unsigned int max_reg = max_reg_num();
2512 struct df_byte_lr_problem_data *problem_data
2513 = problem_data = XNEW (struct df_byte_lr_problem_data);
2515 df_byte_lr->problem_data = problem_data;
2517 if (!df_byte_lr->block_pool)
2518 df_byte_lr->block_pool = create_alloc_pool ("df_byte_lr_block pool",
2519 sizeof (struct df_byte_lr_bb_info), 50);
2521 df_grow_bb_info (df_byte_lr);
2523 /* Create the mapping from regnos to slots. This does not change
2524 unless the problem is destroyed and recreated. In particular, if
2525 we end up deleting the only insn that used a subreg, we do not
2526 want to redo the mapping because this would invalidate everything
2527 else. */
2529 bitmap_obstack_initialize (&problem_data->byte_lr_bitmaps);
2530 problem_data->regno_start = XNEWVEC (unsigned int, max_reg);
2531 problem_data->regno_len = XNEWVEC (unsigned int, max_reg);
2532 problem_data->hardware_regs_used = BITMAP_ALLOC (&problem_data->byte_lr_bitmaps);
2533 problem_data->invalidated_by_call = BITMAP_ALLOC (&problem_data->byte_lr_bitmaps);
2534 problem_data->needs_expansion = BITMAP_ALLOC (&problem_data->byte_lr_bitmaps);
2536 /* Discover which regno's use subregs, extracts or
2537 strict_low_parts. */
2538 FOR_EACH_BB (bb)
2540 rtx insn;
2541 FOR_BB_INSNS (bb, insn)
2543 if (INSN_P (insn))
2545 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2546 df_byte_lr_check_regs (DF_INSN_INFO_DEFS (insn_info));
2547 df_byte_lr_check_regs (DF_INSN_INFO_USES (insn_info));
2550 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, bb->index);
2553 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2554 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2556 /* Allocate the slots for each regno. */
2557 for (regno = 0; regno < max_reg; regno++)
2559 int len;
2560 problem_data->regno_start[regno] = index;
2561 if (bitmap_bit_p (problem_data->needs_expansion, regno))
2562 len = GET_MODE_SIZE (GET_MODE (regno_reg_rtx[regno]));
2563 else
2564 len = 1;
2566 problem_data->regno_len[regno] = len;
2567 index += len;
2570 df_byte_lr_expand_bitmap (problem_data->hardware_regs_used,
2571 df->hardware_regs_used);
2572 df_byte_lr_expand_bitmap (problem_data->invalidated_by_call,
2573 regs_invalidated_by_call_regset);
2575 EXECUTE_IF_SET_IN_BITMAP (df_byte_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2577 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2578 if (bb_info)
2580 bitmap_clear (bb_info->def);
2581 bitmap_clear (bb_info->use);
2583 else
2585 bb_info = (struct df_byte_lr_bb_info *) pool_alloc (df_byte_lr->block_pool);
2586 df_byte_lr_set_bb_info (bb_index, bb_info);
2587 bb_info->use = BITMAP_ALLOC (&problem_data->byte_lr_bitmaps);
2588 bb_info->def = BITMAP_ALLOC (&problem_data->byte_lr_bitmaps);
2589 bb_info->in = BITMAP_ALLOC (&problem_data->byte_lr_bitmaps);
2590 bb_info->out = BITMAP_ALLOC (&problem_data->byte_lr_bitmaps);
2594 df_byte_lr->optional_p = true;
2598 /* Reset the global solution for recalculation. */
2600 static void
2601 df_byte_lr_reset (bitmap all_blocks)
2603 unsigned int bb_index;
2604 bitmap_iterator bi;
2606 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2608 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2609 gcc_assert (bb_info);
2610 bitmap_clear (bb_info->in);
2611 bitmap_clear (bb_info->out);
2616 /* Compute local live register info for basic block BB. */
2618 static void
2619 df_byte_lr_bb_local_compute (unsigned int bb_index)
2621 struct df_byte_lr_problem_data *problem_data
2622 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2623 basic_block bb = BASIC_BLOCK (bb_index);
2624 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2625 rtx insn;
2626 df_ref *def_rec;
2627 df_ref *use_rec;
2629 /* Process the registers set in an exception handler. */
2630 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2632 df_ref def = *def_rec;
2633 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2635 unsigned int dregno = DF_REF_REGNO (def);
2636 unsigned int start = problem_data->regno_start[dregno];
2637 unsigned int len = problem_data->regno_len[dregno];
2638 bitmap_set_range (bb_info->def, start, len);
2639 bitmap_clear_range (bb_info->use, start, len);
2643 /* Process the hardware registers that are always live. */
2644 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2646 df_ref use = *use_rec;
2647 /* Add use to set of uses in this BB. */
2648 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2650 unsigned int uregno = DF_REF_REGNO (use);
2651 unsigned int start = problem_data->regno_start[uregno];
2652 unsigned int len = problem_data->regno_len[uregno];
2653 bitmap_set_range (bb_info->use, start, len);
2657 FOR_BB_INSNS_REVERSE (bb, insn)
2659 unsigned int uid = INSN_UID (insn);
2661 if (!INSN_P (insn))
2662 continue;
2664 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2666 df_ref def = *def_rec;
2667 /* If the def is to only part of the reg, it does
2668 not kill the other defs that reach here. */
2669 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2671 unsigned int dregno = DF_REF_REGNO (def);
2672 unsigned int start = problem_data->regno_start[dregno];
2673 unsigned int len = problem_data->regno_len[dregno];
2674 unsigned int sb;
2675 unsigned int lb;
2676 if (!df_compute_accessed_bytes (def, DF_MM_MUST, &sb, &lb))
2678 start += sb;
2679 len = lb - sb;
2681 if (len)
2683 bitmap_set_range (bb_info->def, start, len);
2684 bitmap_clear_range (bb_info->use, start, len);
2689 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2691 df_ref use = *use_rec;
2692 unsigned int uregno = DF_REF_REGNO (use);
2693 unsigned int start = problem_data->regno_start[uregno];
2694 unsigned int len = problem_data->regno_len[uregno];
2695 unsigned int sb;
2696 unsigned int lb;
2697 if (!df_compute_accessed_bytes (use, DF_MM_MAY, &sb, &lb))
2699 start += sb;
2700 len = lb - sb;
2702 /* Add use to set of uses in this BB. */
2703 if (len)
2704 bitmap_set_range (bb_info->use, start, len);
2708 /* Process the registers set in an exception handler or the hard
2709 frame pointer if this block is the target of a non local
2710 goto. */
2711 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2713 df_ref def = *def_rec;
2714 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2716 unsigned int dregno = DF_REF_REGNO (def);
2717 unsigned int start = problem_data->regno_start[dregno];
2718 unsigned int len = problem_data->regno_len[dregno];
2719 bitmap_set_range (bb_info->def, start, len);
2720 bitmap_clear_range (bb_info->use, start, len);
2724 #ifdef EH_USES
2725 /* Process the uses that are live into an exception handler. */
2726 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2728 df_ref use = *use_rec;
2729 /* Add use to set of uses in this BB. */
2730 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
2732 unsigned int uregno = DF_REF_REGNO (use);
2733 unsigned int start = problem_data->regno_start[uregno];
2734 unsigned int len = problem_data->regno_len[uregno];
2735 bitmap_set_range (bb_info->use, start, len);
2738 #endif
2742 /* Compute local live register info for each basic block within BLOCKS. */
2744 static void
2745 df_byte_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2747 unsigned int bb_index;
2748 bitmap_iterator bi;
2750 EXECUTE_IF_SET_IN_BITMAP (df_byte_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2752 if (bb_index == EXIT_BLOCK)
2754 /* The exit block is special for this problem and its bits are
2755 computed from thin air. */
2756 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (EXIT_BLOCK);
2757 df_byte_lr_expand_bitmap (bb_info->use, df->exit_block_uses);
2759 else
2760 df_byte_lr_bb_local_compute (bb_index);
2763 bitmap_clear (df_byte_lr->out_of_date_transfer_functions);
2767 /* Initialize the solution vectors. */
2769 static void
2770 df_byte_lr_init (bitmap all_blocks)
2772 unsigned int bb_index;
2773 bitmap_iterator bi;
2775 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2777 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2778 bitmap_copy (bb_info->in, bb_info->use);
2779 bitmap_clear (bb_info->out);
2784 /* Confluence function that processes infinite loops. This might be a
2785 noreturn function that throws. And even if it isn't, getting the
2786 unwind info right helps debugging. */
2787 static void
2788 df_byte_lr_confluence_0 (basic_block bb)
2790 struct df_byte_lr_problem_data *problem_data
2791 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2792 bitmap op1 = df_byte_lr_get_bb_info (bb->index)->out;
2793 if (bb != EXIT_BLOCK_PTR)
2794 bitmap_copy (op1, problem_data->hardware_regs_used);
2798 /* Confluence function that ignores fake edges. */
2800 static void
2801 df_byte_lr_confluence_n (edge e)
2803 struct df_byte_lr_problem_data *problem_data
2804 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2805 bitmap op1 = df_byte_lr_get_bb_info (e->src->index)->out;
2806 bitmap op2 = df_byte_lr_get_bb_info (e->dest->index)->in;
2808 /* Call-clobbered registers die across exception and call edges. */
2809 /* ??? Abnormal call edges ignored for the moment, as this gets
2810 confused by sibling call edges, which crashes reg-stack. */
2811 if (e->flags & EDGE_EH)
2812 bitmap_ior_and_compl_into (op1, op2, problem_data->invalidated_by_call);
2813 else
2814 bitmap_ior_into (op1, op2);
2816 bitmap_ior_into (op1, problem_data->hardware_regs_used);
2820 /* Transfer function. */
2822 static bool
2823 df_byte_lr_transfer_function (int bb_index)
2825 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2826 bitmap in = bb_info->in;
2827 bitmap out = bb_info->out;
2828 bitmap use = bb_info->use;
2829 bitmap def = bb_info->def;
2831 return bitmap_ior_and_compl (in, use, out, def);
2835 /* Free all storage associated with the problem. */
2837 static void
2838 df_byte_lr_free (void)
2840 struct df_byte_lr_problem_data *problem_data
2841 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2844 if (df_byte_lr->block_info)
2846 free_alloc_pool (df_byte_lr->block_pool);
2847 df_byte_lr->block_info_size = 0;
2848 free (df_byte_lr->block_info);
2851 BITMAP_FREE (df_byte_lr->out_of_date_transfer_functions);
2852 bitmap_obstack_release (&problem_data->byte_lr_bitmaps);
2853 free (problem_data->regno_start);
2854 free (problem_data->regno_len);
2855 free (problem_data);
2856 free (df_byte_lr);
2860 /* Debugging info at top of bb. */
2862 static void
2863 df_byte_lr_top_dump (basic_block bb, FILE *file)
2865 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb->index);
2866 if (!bb_info || !bb_info->in)
2867 return;
2869 fprintf (file, ";; blr in \t");
2870 df_print_byte_regset (file, bb_info->in);
2871 fprintf (file, ";; blr use \t");
2872 df_print_byte_regset (file, bb_info->use);
2873 fprintf (file, ";; blr def \t");
2874 df_print_byte_regset (file, bb_info->def);
2878 /* Debugging info at bottom of bb. */
2880 static void
2881 df_byte_lr_bottom_dump (basic_block bb, FILE *file)
2883 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb->index);
2884 if (!bb_info || !bb_info->out)
2885 return;
2887 fprintf (file, ";; blr out \t");
2888 df_print_byte_regset (file, bb_info->out);
2892 /* All of the information associated with every instance of the problem. */
2894 static struct df_problem problem_BYTE_LR =
2896 DF_BYTE_LR, /* Problem id. */
2897 DF_BACKWARD, /* Direction. */
2898 df_byte_lr_alloc, /* Allocate the problem specific data. */
2899 df_byte_lr_reset, /* Reset global information. */
2900 df_byte_lr_free_bb_info, /* Free basic block info. */
2901 df_byte_lr_local_compute, /* Local compute function. */
2902 df_byte_lr_init, /* Init the solution specific data. */
2903 df_worklist_dataflow, /* Worklist solver. */
2904 df_byte_lr_confluence_0, /* Confluence operator 0. */
2905 df_byte_lr_confluence_n, /* Confluence operator n. */
2906 df_byte_lr_transfer_function, /* Transfer function. */
2907 NULL, /* Finalize function. */
2908 df_byte_lr_free, /* Free all of the problem information. */
2909 df_byte_lr_free, /* Remove this problem from the stack of dataflow problems. */
2910 NULL, /* Debugging. */
2911 df_byte_lr_top_dump, /* Debugging start block. */
2912 df_byte_lr_bottom_dump, /* Debugging end block. */
2913 NULL, /* Incremental solution verify start. */
2914 NULL, /* Incremental solution verify end. */
2915 NULL, /* Dependent problem. */
2916 TV_DF_BYTE_LR, /* Timing variable. */
2917 false /* Reset blocks on dropping out of blocks_to_analyze. */
2921 /* Create a new DATAFLOW instance and add it to an existing instance
2922 of DF. The returned structure is what is used to get at the
2923 solution. */
2925 void
2926 df_byte_lr_add_problem (void)
2928 df_add_problem (&problem_BYTE_LR);
2929 /* These will be initialized when df_scan_blocks processes each
2930 block. */
2931 df_byte_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2935 /* Simulate the effects of the defs of INSN on LIVE. */
2937 void
2938 df_byte_lr_simulate_defs (rtx insn, bitmap live)
2940 struct df_byte_lr_problem_data *problem_data
2941 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2942 df_ref *def_rec;
2943 unsigned int uid = INSN_UID (insn);
2945 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2947 df_ref def = *def_rec;
2949 /* If the def is to only part of the reg, it does
2950 not kill the other defs that reach here. */
2951 if (!(DF_REF_FLAGS (def) & DF_REF_CONDITIONAL))
2953 unsigned int dregno = DF_REF_REGNO (def);
2954 unsigned int start = problem_data->regno_start[dregno];
2955 unsigned int len = problem_data->regno_len[dregno];
2956 unsigned int sb;
2957 unsigned int lb;
2958 if (!df_compute_accessed_bytes (def, DF_MM_MUST, &sb, &lb))
2960 start += sb;
2961 len = lb - sb;
2964 if (len)
2965 bitmap_clear_range (live, start, len);
2971 /* Simulate the effects of the uses of INSN on LIVE. */
2973 void
2974 df_byte_lr_simulate_uses (rtx insn, bitmap live)
2976 struct df_byte_lr_problem_data *problem_data
2977 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2978 df_ref *use_rec;
2979 unsigned int uid = INSN_UID (insn);
2981 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2983 df_ref use = *use_rec;
2984 unsigned int uregno = DF_REF_REGNO (use);
2985 unsigned int start = problem_data->regno_start[uregno];
2986 unsigned int len = problem_data->regno_len[uregno];
2987 unsigned int sb;
2988 unsigned int lb;
2990 if (!df_compute_accessed_bytes (use, DF_MM_MAY, &sb, &lb))
2992 start += sb;
2993 len = lb - sb;
2996 /* Add use to set of uses in this BB. */
2997 if (len)
2998 bitmap_set_range (live, start, len);
3003 /* Apply the artificial uses and defs at the top of BB in a forwards
3004 direction. */
3006 void
3007 df_byte_lr_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
3009 struct df_byte_lr_problem_data *problem_data
3010 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
3011 df_ref *def_rec;
3012 #ifdef EH_USES
3013 df_ref *use_rec;
3014 #endif
3015 int bb_index = bb->index;
3017 #ifdef EH_USES
3018 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3020 df_ref use = *use_rec;
3021 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3023 unsigned int uregno = DF_REF_REGNO (use);
3024 unsigned int start = problem_data->regno_start[uregno];
3025 unsigned int len = problem_data->regno_len[uregno];
3026 bitmap_set_range (live, start, len);
3029 #endif
3031 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3033 df_ref def = *def_rec;
3034 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3036 unsigned int dregno = DF_REF_REGNO (def);
3037 unsigned int start = problem_data->regno_start[dregno];
3038 unsigned int len = problem_data->regno_len[dregno];
3039 bitmap_clear_range (live, start, len);
3045 /* Apply the artificial uses and defs at the end of BB in a backwards
3046 direction. */
3048 void
3049 df_byte_lr_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3051 struct df_byte_lr_problem_data *problem_data
3052 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
3053 df_ref *def_rec;
3054 df_ref *use_rec;
3055 int bb_index = bb->index;
3057 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3059 df_ref def = *def_rec;
3060 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3062 unsigned int dregno = DF_REF_REGNO (def);
3063 unsigned int start = problem_data->regno_start[dregno];
3064 unsigned int len = problem_data->regno_len[dregno];
3065 bitmap_clear_range (live, start, len);
3069 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3071 df_ref use = *use_rec;
3072 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3074 unsigned int uregno = DF_REF_REGNO (use);
3075 unsigned int start = problem_data->regno_start[uregno];
3076 unsigned int len = problem_data->regno_len[uregno];
3077 bitmap_set_range (live, start, len);
3084 /*----------------------------------------------------------------------------
3085 This problem computes REG_DEAD and REG_UNUSED notes.
3086 ----------------------------------------------------------------------------*/
3088 static void
3089 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3091 df_note->optional_p = true;
3094 #ifdef REG_DEAD_DEBUGGING
3095 static void
3096 df_print_note (const char *prefix, rtx insn, rtx note)
3098 if (dump_file)
3100 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
3101 print_rtl (dump_file, note);
3102 fprintf (dump_file, "\n");
3105 #endif
3108 /* After reg-stack, the x86 floating point stack regs are difficult to
3109 analyze because of all of the pushes, pops and rotations. Thus, we
3110 just leave the notes alone. */
3112 #ifdef STACK_REGS
3113 static inline bool
3114 df_ignore_stack_reg (int regno)
3116 return regstack_completed
3117 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
3119 #else
3120 static inline bool
3121 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
3123 return false;
3125 #endif
3128 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
3129 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
3131 static void
3132 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
3134 rtx *pprev = &REG_NOTES (insn);
3135 rtx link = *pprev;
3136 rtx dead = NULL;
3137 rtx unused = NULL;
3139 while (link)
3141 switch (REG_NOTE_KIND (link))
3143 case REG_DEAD:
3144 /* After reg-stack, we need to ignore any unused notes
3145 for the stack registers. */
3146 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3148 pprev = &XEXP (link, 1);
3149 link = *pprev;
3151 else
3153 rtx next = XEXP (link, 1);
3154 #ifdef REG_DEAD_DEBUGGING
3155 df_print_note ("deleting: ", insn, link);
3156 #endif
3157 XEXP (link, 1) = dead;
3158 dead = link;
3159 *pprev = link = next;
3161 break;
3163 case REG_UNUSED:
3164 /* After reg-stack, we need to ignore any unused notes
3165 for the stack registers. */
3166 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3168 pprev = &XEXP (link, 1);
3169 link = *pprev;
3171 else
3173 rtx next = XEXP (link, 1);
3174 #ifdef REG_DEAD_DEBUGGING
3175 df_print_note ("deleting: ", insn, link);
3176 #endif
3177 XEXP (link, 1) = unused;
3178 unused = link;
3179 *pprev = link = next;
3181 break;
3183 default:
3184 pprev = &XEXP (link, 1);
3185 link = *pprev;
3186 break;
3190 *old_dead_notes = dead;
3191 *old_unused_notes = unused;
3195 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
3196 list, otherwise create a new one. */
3198 static inline rtx
3199 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
3201 rtx curr = old;
3202 rtx prev = NULL;
3204 while (curr)
3205 if (XEXP (curr, 0) == reg)
3207 if (prev)
3208 XEXP (prev, 1) = XEXP (curr, 1);
3209 else
3210 old = XEXP (curr, 1);
3211 XEXP (curr, 1) = REG_NOTES (insn);
3212 REG_NOTES (insn) = curr;
3213 return old;
3215 else
3217 prev = curr;
3218 curr = XEXP (curr, 1);
3221 /* Did not find the note. */
3222 add_reg_note (insn, note_type, reg);
3223 return old;
3226 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
3227 arguments. Return true if the register value described by MWS's
3228 mw_reg is known to be completely unused, and if mw_reg can therefore
3229 be used in a REG_UNUSED note. */
3231 static bool
3232 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
3233 bitmap live, bitmap artificial_uses)
3235 unsigned int r;
3237 /* If MWS describes a partial reference, create REG_UNUSED notes for
3238 individual hard registers. */
3239 if (mws->flags & DF_REF_PARTIAL)
3240 return false;
3242 /* Likewise if some part of the register is used. */
3243 for (r = mws->start_regno; r <= mws->end_regno; r++)
3244 if (bitmap_bit_p (live, r)
3245 || bitmap_bit_p (artificial_uses, r))
3246 return false;
3248 gcc_assert (REG_P (mws->mw_reg));
3249 return true;
3252 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
3253 based on the bits in LIVE. Do not generate notes for registers in
3254 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
3255 not generated if the reg is both read and written by the
3256 instruction.
3259 static rtx
3260 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3261 bitmap live, bitmap do_not_gen,
3262 bitmap artificial_uses)
3264 unsigned int r;
3266 #ifdef REG_DEAD_DEBUGGING
3267 if (dump_file)
3268 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
3269 mws->start_regno, mws->end_regno);
3270 #endif
3272 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
3274 unsigned int regno = mws->start_regno;
3275 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
3277 #ifdef REG_DEAD_DEBUGGING
3278 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3279 #endif
3280 bitmap_set_bit (do_not_gen, regno);
3281 /* Only do this if the value is totally dead. */
3283 else
3284 for (r = mws->start_regno; r <= mws->end_regno; r++)
3286 if (!bitmap_bit_p (live, r)
3287 && !bitmap_bit_p (artificial_uses, r))
3289 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
3290 #ifdef REG_DEAD_DEBUGGING
3291 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3292 #endif
3294 bitmap_set_bit (do_not_gen, r);
3296 return old;
3300 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
3301 arguments. Return true if the register value described by MWS's
3302 mw_reg is known to be completely dead, and if mw_reg can therefore
3303 be used in a REG_DEAD note. */
3305 static bool
3306 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
3307 bitmap live, bitmap artificial_uses,
3308 bitmap do_not_gen)
3310 unsigned int r;
3312 /* If MWS describes a partial reference, create REG_DEAD notes for
3313 individual hard registers. */
3314 if (mws->flags & DF_REF_PARTIAL)
3315 return false;
3317 /* Likewise if some part of the register is not dead. */
3318 for (r = mws->start_regno; r <= mws->end_regno; r++)
3319 if (bitmap_bit_p (live, r)
3320 || bitmap_bit_p (artificial_uses, r)
3321 || bitmap_bit_p (do_not_gen, r))
3322 return false;
3324 gcc_assert (REG_P (mws->mw_reg));
3325 return true;
3328 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3329 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3330 from being set if the instruction both reads and writes the
3331 register. */
3333 static rtx
3334 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3335 bitmap live, bitmap do_not_gen,
3336 bitmap artificial_uses)
3338 unsigned int r;
3340 #ifdef REG_DEAD_DEBUGGING
3341 if (dump_file)
3343 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3344 mws->start_regno, mws->end_regno);
3345 df_print_regset (dump_file, do_not_gen);
3346 fprintf (dump_file, " live =");
3347 df_print_regset (dump_file, live);
3348 fprintf (dump_file, " artificial uses =");
3349 df_print_regset (dump_file, artificial_uses);
3351 #endif
3353 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
3355 /* Add a dead note for the entire multi word register. */
3356 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
3357 #ifdef REG_DEAD_DEBUGGING
3358 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3359 #endif
3361 else
3363 for (r = mws->start_regno; r <= mws->end_regno; r++)
3364 if (!bitmap_bit_p (live, r)
3365 && !bitmap_bit_p (artificial_uses, r)
3366 && !bitmap_bit_p (do_not_gen, r))
3368 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
3369 #ifdef REG_DEAD_DEBUGGING
3370 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3371 #endif
3374 return old;
3378 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3379 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3381 static rtx
3382 df_create_unused_note (rtx insn, rtx old, df_ref def,
3383 bitmap live, bitmap artificial_uses)
3385 unsigned int dregno = DF_REF_REGNO (def);
3387 #ifdef REG_DEAD_DEBUGGING
3388 if (dump_file)
3390 fprintf (dump_file, " regular looking at def ");
3391 df_ref_debug (def, dump_file);
3393 #endif
3395 if (!(bitmap_bit_p (live, dregno)
3396 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3397 || bitmap_bit_p (artificial_uses, dregno)
3398 || df_ignore_stack_reg (dregno)))
3400 rtx reg = (DF_REF_LOC (def))
3401 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3402 old = df_set_note (REG_UNUSED, insn, old, reg);
3403 #ifdef REG_DEAD_DEBUGGING
3404 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3405 #endif
3408 return old;
3412 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3413 info: lifetime, bb, and number of defs and uses for basic block
3414 BB. The three bitvectors are scratch regs used here. */
3416 static void
3417 df_note_bb_compute (unsigned int bb_index,
3418 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3420 basic_block bb = BASIC_BLOCK (bb_index);
3421 rtx insn;
3422 df_ref *def_rec;
3423 df_ref *use_rec;
3425 bitmap_copy (live, df_get_live_out (bb));
3426 bitmap_clear (artificial_uses);
3428 #ifdef REG_DEAD_DEBUGGING
3429 if (dump_file)
3431 fprintf (dump_file, "live at bottom ");
3432 df_print_regset (dump_file, live);
3434 #endif
3436 /* Process the artificial defs and uses at the bottom of the block
3437 to begin processing. */
3438 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3440 df_ref def = *def_rec;
3441 #ifdef REG_DEAD_DEBUGGING
3442 if (dump_file)
3443 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3444 #endif
3446 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3447 bitmap_clear_bit (live, DF_REF_REGNO (def));
3450 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3452 df_ref use = *use_rec;
3453 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3455 unsigned int regno = DF_REF_REGNO (use);
3456 bitmap_set_bit (live, regno);
3458 /* Notes are not generated for any of the artificial registers
3459 at the bottom of the block. */
3460 bitmap_set_bit (artificial_uses, regno);
3464 #ifdef REG_DEAD_DEBUGGING
3465 if (dump_file)
3467 fprintf (dump_file, "live before artificials out ");
3468 df_print_regset (dump_file, live);
3470 #endif
3472 FOR_BB_INSNS_REVERSE (bb, insn)
3474 unsigned int uid = INSN_UID (insn);
3475 struct df_mw_hardreg **mws_rec;
3476 rtx old_dead_notes;
3477 rtx old_unused_notes;
3479 if (!INSN_P (insn))
3480 continue;
3482 bitmap_clear (do_not_gen);
3483 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
3485 /* Process the defs. */
3486 if (CALL_P (insn))
3488 #ifdef REG_DEAD_DEBUGGING
3489 if (dump_file)
3491 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3492 df_print_regset (dump_file, live);
3494 #endif
3495 /* We only care about real sets for calls. Clobbers cannot
3496 be depended on to really die. */
3497 mws_rec = DF_INSN_UID_MWS (uid);
3498 while (*mws_rec)
3500 struct df_mw_hardreg *mws = *mws_rec;
3501 if ((DF_MWS_REG_DEF_P (mws))
3502 && !df_ignore_stack_reg (mws->start_regno))
3503 old_unused_notes
3504 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3505 mws, live, do_not_gen,
3506 artificial_uses);
3507 mws_rec++;
3510 /* All of the defs except the return value are some sort of
3511 clobber. This code is for the return. */
3512 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3514 df_ref def = *def_rec;
3515 unsigned int dregno = DF_REF_REGNO (def);
3516 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3518 old_unused_notes
3519 = df_create_unused_note (insn, old_unused_notes,
3520 def, live, artificial_uses);
3521 bitmap_set_bit (do_not_gen, dregno);
3524 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3525 bitmap_clear_bit (live, dregno);
3528 else
3530 /* Regular insn. */
3531 mws_rec = DF_INSN_UID_MWS (uid);
3532 while (*mws_rec)
3534 struct df_mw_hardreg *mws = *mws_rec;
3535 if (DF_MWS_REG_DEF_P (mws))
3536 old_unused_notes
3537 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3538 mws, live, do_not_gen,
3539 artificial_uses);
3540 mws_rec++;
3543 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3545 df_ref def = *def_rec;
3546 unsigned int dregno = DF_REF_REGNO (def);
3547 old_unused_notes
3548 = df_create_unused_note (insn, old_unused_notes,
3549 def, live, artificial_uses);
3551 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3552 bitmap_set_bit (do_not_gen, dregno);
3554 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3555 bitmap_clear_bit (live, dregno);
3559 /* Process the uses. */
3560 mws_rec = DF_INSN_UID_MWS (uid);
3561 while (*mws_rec)
3563 struct df_mw_hardreg *mws = *mws_rec;
3564 if ((DF_MWS_REG_DEF_P (mws))
3565 && !df_ignore_stack_reg (mws->start_regno))
3566 old_dead_notes
3567 = df_set_dead_notes_for_mw (insn, old_dead_notes,
3568 mws, live, do_not_gen,
3569 artificial_uses);
3570 mws_rec++;
3573 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3575 df_ref use = *use_rec;
3576 unsigned int uregno = DF_REF_REGNO (use);
3578 #ifdef REG_DEAD_DEBUGGING
3579 if (dump_file)
3581 fprintf (dump_file, " regular looking at use ");
3582 df_ref_debug (use, dump_file);
3584 #endif
3585 if (!bitmap_bit_p (live, uregno))
3587 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
3588 && (!bitmap_bit_p (do_not_gen, uregno))
3589 && (!bitmap_bit_p (artificial_uses, uregno))
3590 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
3591 && (!df_ignore_stack_reg (uregno)))
3593 rtx reg = (DF_REF_LOC (use))
3594 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3595 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
3597 #ifdef REG_DEAD_DEBUGGING
3598 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3599 #endif
3601 /* This register is now live. */
3602 bitmap_set_bit (live, uregno);
3606 while (old_unused_notes)
3608 rtx next = XEXP (old_unused_notes, 1);
3609 free_EXPR_LIST_node (old_unused_notes);
3610 old_unused_notes = next;
3612 while (old_dead_notes)
3614 rtx next = XEXP (old_dead_notes, 1);
3615 free_EXPR_LIST_node (old_dead_notes);
3616 old_dead_notes = next;
3622 /* Compute register info: lifetime, bb, and number of defs and uses. */
3623 static void
3624 df_note_compute (bitmap all_blocks)
3626 unsigned int bb_index;
3627 bitmap_iterator bi;
3628 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
3629 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
3630 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
3632 #ifdef REG_DEAD_DEBUGGING
3633 if (dump_file)
3634 print_rtl_with_bb (dump_file, get_insns());
3635 #endif
3637 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3639 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
3642 BITMAP_FREE (live);
3643 BITMAP_FREE (do_not_gen);
3644 BITMAP_FREE (artificial_uses);
3648 /* Free all storage associated with the problem. */
3650 static void
3651 df_note_free (void)
3653 free (df_note);
3657 /* All of the information associated every instance of the problem. */
3659 static struct df_problem problem_NOTE =
3661 DF_NOTE, /* Problem id. */
3662 DF_NONE, /* Direction. */
3663 df_note_alloc, /* Allocate the problem specific data. */
3664 NULL, /* Reset global information. */
3665 NULL, /* Free basic block info. */
3666 df_note_compute, /* Local compute function. */
3667 NULL, /* Init the solution specific data. */
3668 NULL, /* Iterative solver. */
3669 NULL, /* Confluence operator 0. */
3670 NULL, /* Confluence operator n. */
3671 NULL, /* Transfer function. */
3672 NULL, /* Finalize function. */
3673 df_note_free, /* Free all of the problem information. */
3674 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3675 NULL, /* Debugging. */
3676 NULL, /* Debugging start block. */
3677 NULL, /* Debugging end block. */
3678 NULL, /* Incremental solution verify start. */
3679 NULL, /* Incremental solution verify end. */
3680 &problem_LR, /* Dependent problem. */
3681 TV_DF_NOTE, /* Timing variable. */
3682 false /* Reset blocks on dropping out of blocks_to_analyze. */
3686 /* Create a new DATAFLOW instance and add it to an existing instance
3687 of DF. The returned structure is what is used to get at the
3688 solution. */
3690 void
3691 df_note_add_problem (void)
3693 df_add_problem (&problem_NOTE);
3699 /*----------------------------------------------------------------------------
3700 Functions for simulating the effects of single insns.
3702 You can either simulate in the forwards direction, starting from
3703 the top of a block or the backwards direction from the end of the
3704 block. The main difference is that if you go forwards, the uses
3705 are examined first then the defs, and if you go backwards, the defs
3706 are examined first then the uses.
3708 If you start at the top of the block, use one of DF_LIVE_IN or
3709 DF_LR_IN. If you start at the bottom of the block use one of
3710 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3711 THEY WILL BE DESTROYED.
3712 ----------------------------------------------------------------------------*/
3715 /* Find the set of DEFs for INSN. */
3717 void
3718 df_simulate_find_defs (rtx insn, bitmap defs)
3720 df_ref *def_rec;
3721 unsigned int uid = INSN_UID (insn);
3723 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3725 df_ref def = *def_rec;
3726 /* If the def is to only part of the reg, it does
3727 not kill the other defs that reach here. */
3728 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3729 bitmap_set_bit (defs, DF_REF_REGNO (def));
3734 /* Simulate the effects of the defs of INSN on LIVE. */
3736 void
3737 df_simulate_defs (rtx insn, bitmap live)
3739 df_ref *def_rec;
3740 unsigned int uid = INSN_UID (insn);
3742 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3744 df_ref def = *def_rec;
3745 unsigned int dregno = DF_REF_REGNO (def);
3747 /* If the def is to only part of the reg, it does
3748 not kill the other defs that reach here. */
3749 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3750 bitmap_clear_bit (live, dregno);
3755 /* Simulate the effects of the uses of INSN on LIVE. */
3757 void
3758 df_simulate_uses (rtx insn, bitmap live)
3760 df_ref *use_rec;
3761 unsigned int uid = INSN_UID (insn);
3763 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3765 df_ref use = *use_rec;
3766 /* Add use to set of uses in this BB. */
3767 bitmap_set_bit (live, DF_REF_REGNO (use));
3772 /* Add back the always live regs in BB to LIVE. */
3774 static inline void
3775 df_simulate_fixup_sets (basic_block bb, bitmap live)
3777 /* These regs are considered always live so if they end up dying
3778 because of some def, we need to bring the back again. */
3779 if (bb_has_eh_pred (bb))
3780 bitmap_ior_into (live, df->eh_block_artificial_uses);
3781 else
3782 bitmap_ior_into (live, df->regular_block_artificial_uses);
3786 /*----------------------------------------------------------------------------
3787 The following three functions are used only for BACKWARDS scanning:
3788 i.e. they process the defs before the uses.
3790 df_simulate_initialize_backwards should be called first with a
3791 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3792 df_simulate_one_insn_backwards should be called for each insn in
3793 the block, starting with the last on. Finally,
3794 df_simulate_finalize_backwards can be called to get a new value
3795 of the sets at the top of the block (this is rarely used).
3796 ----------------------------------------------------------------------------*/
3798 /* Apply the artificial uses and defs at the end of BB in a backwards
3799 direction. */
3801 void
3802 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3804 df_ref *def_rec;
3805 df_ref *use_rec;
3806 int bb_index = bb->index;
3808 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3810 df_ref def = *def_rec;
3811 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3812 bitmap_clear_bit (live, DF_REF_REGNO (def));
3815 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3817 df_ref use = *use_rec;
3818 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3819 bitmap_set_bit (live, DF_REF_REGNO (use));
3824 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3826 void
3827 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3829 if (! INSN_P (insn))
3830 return;
3832 df_simulate_defs (insn, live);
3833 df_simulate_uses (insn, live);
3834 df_simulate_fixup_sets (bb, live);
3838 /* Apply the artificial uses and defs at the top of BB in a backwards
3839 direction. */
3841 void
3842 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3844 df_ref *def_rec;
3845 #ifdef EH_USES
3846 df_ref *use_rec;
3847 #endif
3848 int bb_index = bb->index;
3850 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3852 df_ref def = *def_rec;
3853 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3854 bitmap_clear_bit (live, DF_REF_REGNO (def));
3857 #ifdef EH_USES
3858 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3860 df_ref use = *use_rec;
3861 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3862 bitmap_set_bit (live, DF_REF_REGNO (use));
3864 #endif
3866 /*----------------------------------------------------------------------------
3867 The following three functions are used only for FORWARDS scanning:
3868 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3869 Thus it is important to add the DF_NOTES problem to the stack of
3870 problems computed before using these functions.
3872 df_simulate_initialize_forwards should be called first with a
3873 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3874 df_simulate_one_insn_forwards should be called for each insn in
3875 the block, starting with the last on. Finally,
3876 df_simulate_finalize_forwards can be called to get a new value
3877 of the sets at the bottom of the block (this is rarely used).
3878 ----------------------------------------------------------------------------*/
3880 /* Apply the artificial uses and defs at the top of BB in a backwards
3881 direction. */
3883 void
3884 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3886 df_ref *def_rec;
3887 int bb_index = bb->index;
3889 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3891 df_ref def = *def_rec;
3892 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3893 bitmap_clear_bit (live, DF_REF_REGNO (def));
3897 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3899 void
3900 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3902 rtx link;
3903 if (! INSN_P (insn))
3904 return;
3906 /* Make sure that the DF_NOTES really is an active df problem. */
3907 gcc_assert (df_note);
3909 df_simulate_defs (insn, live);
3911 /* Clear all of the registers that go dead. */
3912 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3914 switch (REG_NOTE_KIND (link))
3915 case REG_DEAD:
3916 case REG_UNUSED:
3918 rtx reg = XEXP (link, 0);
3919 int regno = REGNO (reg);
3920 if (regno < FIRST_PSEUDO_REGISTER)
3922 int n = hard_regno_nregs[regno][GET_MODE (reg)];
3923 while (--n >= 0)
3924 bitmap_clear_bit (live, regno + n);
3926 else
3927 bitmap_clear_bit (live, regno);
3928 break;
3929 default:
3930 break;
3933 df_simulate_fixup_sets (bb, live);
3937 /* Apply the artificial uses and defs at the end of BB in a backwards
3938 direction. */
3940 void
3941 df_simulate_finalize_forwards (basic_block bb, bitmap live)
3943 df_ref *def_rec;
3944 int bb_index = bb->index;
3946 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3948 df_ref def = *def_rec;
3949 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3950 bitmap_clear_bit (live, DF_REF_REGNO (def));