1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
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
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/>. */
27 #include "coretypes.h"
31 #include "insn-config.h"
36 #include "alloc-pool.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.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. */
52 #define REG_DEAD_DEBUGGING
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
70 df_get_live_out (basic_block bb)
75 return DF_LIVE_OUT (bb);
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
86 df_get_live_in (basic_block bb)
91 return DF_LIVE_IN (bb);
96 /*----------------------------------------------------------------------------
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. */
106 df_grow_bb_info (struct dataflow *dflow)
108 unsigned int new_size = last_basic_block + 1;
109 if (dflow->block_info_size < new_size)
111 new_size += new_size / 4;
112 dflow->block_info = xrealloc (dflow->block_info,
113 new_size *sizeof (void*));
114 memset (dflow->block_info + dflow->block_info_size, 0,
115 (new_size - dflow->block_info_size) *sizeof (void *));
116 dflow->block_info_size = new_size;
120 /* Dump a def-use or use-def chain for REF to FILE. */
123 df_chain_dump (struct df_link *link, FILE *file)
125 fprintf (file, "{ ");
126 for (; link; link = link->next)
128 fprintf (file, "%c%d(bb %d insn %d) ",
129 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
130 DF_REF_ID (link->ref),
131 DF_REF_BBNO (link->ref),
132 DF_REF_INSN (link->ref) ? DF_REF_INSN_UID (link->ref) : -1);
138 /* Print some basic block info as part of df_dump. */
141 df_print_bb_index (basic_block bb, FILE *file)
146 fprintf (file, "\n( ");
147 FOR_EACH_EDGE (e, ei, bb->preds)
149 basic_block pred = e->src;
150 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
152 fprintf (file, ")->[%d]->( ", bb->index);
153 FOR_EACH_EDGE (e, ei, bb->succs)
155 basic_block succ = e->dest;
156 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
158 fprintf (file, ")\n");
163 /* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
169 seen_in_block = BITMAP_ALLOC (&df_bitmap_obstack);
170 seen_in_insn = BITMAP_ALLOC (&df_bitmap_obstack);
177 BITMAP_FREE (seen_in_block);
178 BITMAP_FREE (seen_in_insn);
183 /*----------------------------------------------------------------------------
186 Find the locations in the function where each definition site for a
187 pseudo reaches. In and out bitvectors are built for each basic
188 block. The id field in the ref is used to index into these sets.
189 See df.h for details.
190 ----------------------------------------------------------------------------*/
192 /* This problem plays a large number of games for the sake of
195 1) The order of the bits in the bitvectors. After the scanning
196 phase, all of the defs are sorted. All of the defs for the reg 0
197 are first, followed by all defs for reg 1 and so on.
199 2) There are two kill sets, one if the number of defs is less or
200 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
203 <= : Data is built directly in the kill set.
205 > : One level of indirection is used to keep from generating long
206 strings of 1 bits in the kill sets. Bitvectors that are indexed
207 by the regnum are used to represent that there is a killing def
208 for the register. The confluence and transfer functions use
209 these along with the bitmap_clear_range call to remove ranges of
210 bits without actually generating a knockout vector.
212 The kill and sparse_kill and the dense_invalidated_by_call and
213 sparse_invalidated_by_call both play this game. */
215 /* Private data used to compute the solution for this problem. These
216 data structures are not accessible outside of this module. */
217 struct df_rd_problem_data
219 /* The set of defs to regs invalidated by call. */
220 bitmap sparse_invalidated_by_call;
221 /* The set of defs to regs invalidate by call for rd. */
222 bitmap dense_invalidated_by_call;
223 /* An obstack for the bitmaps we need for this problem. */
224 bitmap_obstack rd_bitmaps;
227 /* Set basic block info. */
230 df_rd_set_bb_info (unsigned int index,
231 struct df_rd_bb_info *bb_info)
234 gcc_assert (index < df_rd->block_info_size);
235 df_rd->block_info[index] = bb_info;
239 /* Free basic block info. */
242 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
245 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
248 if (bb_info->expanded_lr_out)
249 BITMAP_FREE (bb_info->expanded_lr_out);
250 BITMAP_FREE (bb_info->kill);
251 BITMAP_FREE (bb_info->sparse_kill);
252 BITMAP_FREE (bb_info->gen);
253 BITMAP_FREE (bb_info->in);
254 BITMAP_FREE (bb_info->out);
255 pool_free (df_rd->block_pool, bb_info);
260 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
261 not touched unless the block is new. */
264 df_rd_alloc (bitmap all_blocks)
266 unsigned int bb_index;
268 struct df_rd_problem_data *problem_data;
270 if (!df_rd->block_pool)
271 df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
272 sizeof (struct df_rd_bb_info), 50);
274 if (df_rd->problem_data)
276 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
277 bitmap_clear (problem_data->sparse_invalidated_by_call);
278 bitmap_clear (problem_data->dense_invalidated_by_call);
282 problem_data = XNEW (struct df_rd_problem_data);
283 df_rd->problem_data = problem_data;
285 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
286 problem_data->sparse_invalidated_by_call
287 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
288 problem_data->dense_invalidated_by_call
289 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
292 df_grow_bb_info (df_rd);
294 /* Because of the clustering of all use sites for the same pseudo,
295 we have to process all of the blocks before doing the
298 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
300 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
303 if (bb_info->expanded_lr_out)
304 bitmap_clear (bb_info->expanded_lr_out);
305 bitmap_clear (bb_info->kill);
306 bitmap_clear (bb_info->sparse_kill);
307 bitmap_clear (bb_info->gen);
311 bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
312 df_rd_set_bb_info (bb_index, bb_info);
313 if (df->changeable_flags & DF_RD_NO_TRIM)
314 bb_info->expanded_lr_out = NULL;
316 bb_info->expanded_lr_out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
317 bb_info->kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
318 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
319 bb_info->gen = BITMAP_ALLOC (&problem_data->rd_bitmaps);
320 bb_info->in = BITMAP_ALLOC (&problem_data->rd_bitmaps);
321 bb_info->out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
324 df_rd->optional_p = true;
328 /* Process a list of DEFs for df_rd_bb_local_compute. */
331 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
332 struct df_ref **def_rec,
333 enum df_ref_flags top_flag)
335 for (; *def_rec; def_rec++)
337 struct df_ref *def = *def_rec;
338 unsigned int regno = DF_REF_REGNO (def);
340 /* This makes sure we do the artificial defs in the right order
341 since they are all in the same list. */
342 if (top_flag != (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
345 /* Skip over the hard regs if we do not care about them. */
346 if ((df->changeable_flags & DF_NO_HARD_REGS) &&
347 (regno < FIRST_PSEUDO_REGISTER))
350 /* Only the last def(s) for a regno in the block has any
352 if (bitmap_bit_p (seen_in_block, regno))
355 /* The first def for regno in insn gets to knock out the
356 defs from other instructions. */
357 if ((!bitmap_bit_p (seen_in_insn, regno))
358 /* If the def is to only part of the reg, it does
359 not kill the other defs that reach here. */
360 && (!(DF_REF_FLAGS (def) &
361 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
363 unsigned int begin = DF_DEFS_BEGIN (regno);
364 unsigned int n_defs = DF_DEFS_COUNT (regno);
365 if (n_defs > DF_SPARSE_THRESHOLD)
366 bitmap_set_bit (bb_info->sparse_kill, regno);
368 bitmap_set_range (bb_info->kill, begin, n_defs);
369 bitmap_clear_range(bb_info->gen, begin, n_defs);
372 bitmap_set_bit (seen_in_insn, regno);
373 /* All defs for regno in the instruction may be put into
375 if (!(DF_REF_FLAGS (def)
376 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
377 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
381 /* Compute local reaching def info for basic block BB. */
384 df_rd_bb_local_compute (unsigned int bb_index)
386 basic_block bb = BASIC_BLOCK (bb_index);
387 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
388 struct df_lr_bb_info *lr_bb_info = df_lr_get_bb_info (bb_index);
391 bitmap_clear (seen_in_block);
392 bitmap_clear (seen_in_insn);
394 if (!(df->changeable_flags & DF_RD_NO_TRIM))
398 int first_reg = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
399 EXECUTE_IF_SET_IN_BITMAP (lr_bb_info->out, first_reg, regno, bi)
401 unsigned int begin = DF_DEFS_BEGIN (regno);
402 unsigned int n_defs = DF_DEFS_COUNT (regno);
403 bitmap_set_range (bb_info->expanded_lr_out, begin, n_defs);
407 /* Artificials are only hard regs. */
408 if (!(df->changeable_flags & DF_NO_HARD_REGS))
409 df_rd_bb_local_compute_process_def (bb_info,
410 df_get_artificial_defs (bb_index),
413 FOR_BB_INSNS_REVERSE (bb, insn)
415 unsigned int uid = INSN_UID (insn);
420 df_rd_bb_local_compute_process_def (bb_info,
421 DF_INSN_UID_DEFS (uid), 0);
423 /* This complex dance with the two bitmaps is required because
424 instructions can assign twice to the same pseudo. This
425 generally happens with calls that will have one def for the
426 result and another def for the clobber. If only one vector
427 is used and the clobber goes first, the result will be
429 bitmap_ior_into (seen_in_block, seen_in_insn);
430 bitmap_clear (seen_in_insn);
433 /* Process the artificial defs at the top of the block last since we
434 are going backwards through the block and these are logically at
436 if (!(df->changeable_flags & DF_NO_HARD_REGS))
437 df_rd_bb_local_compute_process_def (bb_info,
438 df_get_artificial_defs (bb_index),
443 /* Compute local reaching def info for each basic block within BLOCKS. */
446 df_rd_local_compute (bitmap all_blocks)
448 unsigned int bb_index;
451 struct df_rd_problem_data *problem_data
452 = (struct df_rd_problem_data *) df_rd->problem_data;
453 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
454 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
458 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
460 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
462 df_rd_bb_local_compute (bb_index);
465 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
466 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
468 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
469 bitmap_set_bit (sparse_invalidated, regno);
471 bitmap_set_range (dense_invalidated,
472 DF_DEFS_BEGIN (regno),
473 DF_DEFS_COUNT (regno));
479 /* Initialize the solution bit vectors for problem. */
482 df_rd_init_solution (bitmap all_blocks)
484 unsigned int bb_index;
487 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
489 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
491 bitmap_copy (bb_info->out, bb_info->gen);
492 bitmap_clear (bb_info->in);
496 /* In of target gets or of out of source. */
499 df_rd_confluence_n (edge e)
501 bitmap op1 = df_rd_get_bb_info (e->dest->index)->in;
502 bitmap op2 = df_rd_get_bb_info (e->src->index)->out;
504 if (e->flags & EDGE_FAKE)
507 /* If we are trimming the solution, the invalidated_by_call code in
508 the lr problem makes this unnecessary. However, if we do not
509 trim, we must take this into account. */
510 if ((df->changeable_flags & DF_RD_NO_TRIM) && e->flags & EDGE_EH)
512 struct df_rd_problem_data *problem_data
513 = (struct df_rd_problem_data *) df_rd->problem_data;
514 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
515 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
518 bitmap tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
520 bitmap_copy (tmp, op2);
521 bitmap_and_compl_into (tmp, dense_invalidated);
523 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
525 bitmap_clear_range (tmp,
526 DF_DEFS_BEGIN (regno),
527 DF_DEFS_COUNT (regno));
529 bitmap_ior_into (op1, tmp);
533 bitmap_ior_into (op1, op2);
537 /* Transfer function. */
540 df_rd_transfer_function (int bb_index)
542 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
545 bitmap in = bb_info->in;
546 bitmap out = bb_info->out;
547 bitmap gen = bb_info->gen;
548 bitmap kill = bb_info->kill;
549 bitmap sparse_kill = bb_info->sparse_kill;
550 bool changed = false;
552 if ((df->changeable_flags & DF_RD_NO_TRIM) && bitmap_empty_p (sparse_kill))
553 changed = bitmap_ior_and_compl (out, gen, in, kill);
556 struct df_rd_problem_data *problem_data;
559 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
560 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
561 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
562 tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
564 bitmap_copy (tmp, in);
565 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
567 bitmap_clear_range (tmp,
568 DF_DEFS_BEGIN (regno),
569 DF_DEFS_COUNT (regno));
571 bitmap_and_compl_into (tmp, kill);
572 bitmap_ior_into (tmp, gen);
573 if (!(df->changeable_flags & DF_RD_NO_TRIM))
574 bitmap_and_into (tmp, bb_info->expanded_lr_out);
575 changed = !bitmap_equal_p (tmp, out);
589 /* Free all storage associated with the problem. */
595 struct df_rd_problem_data *problem_data
596 = (struct df_rd_problem_data *) df_rd->problem_data;
600 for (i = 0; i < df_rd->block_info_size; i++)
602 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (i);
605 if (bb_info->expanded_lr_out)
606 BITMAP_FREE (bb_info->expanded_lr_out);
607 BITMAP_FREE (bb_info->kill);
608 BITMAP_FREE (bb_info->sparse_kill);
609 BITMAP_FREE (bb_info->gen);
610 BITMAP_FREE (bb_info->in);
611 BITMAP_FREE (bb_info->out);
615 free_alloc_pool (df_rd->block_pool);
616 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
617 BITMAP_FREE (problem_data->dense_invalidated_by_call);
618 bitmap_obstack_release (&problem_data->rd_bitmaps);
620 df_rd->block_info_size = 0;
621 free (df_rd->block_info);
622 free (df_rd->problem_data);
628 /* Debugging info. */
631 df_rd_start_dump (FILE *file)
633 struct df_rd_problem_data *problem_data
634 = (struct df_rd_problem_data *) df_rd->problem_data;
635 unsigned int m = DF_REG_SIZE(df);
638 if (!df_rd->block_info)
641 fprintf (file, ";; Reaching defs:\n\n");
643 fprintf (file, " sparse invalidated \t");
644 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
645 fprintf (file, " dense invalidated \t");
646 dump_bitmap (file, problem_data->dense_invalidated_by_call);
648 for (regno = 0; regno < m; regno++)
649 if (DF_DEFS_COUNT (regno))
650 fprintf (file, "%d[%d,%d] ", regno,
651 DF_DEFS_BEGIN (regno),
652 DF_DEFS_COUNT (regno));
653 fprintf (file, "\n");
658 /* Debugging info at top of bb. */
661 df_rd_top_dump (basic_block bb, FILE *file)
663 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
664 if (!bb_info || !bb_info->in)
667 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
668 dump_bitmap (file, bb_info->in);
669 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
670 dump_bitmap (file, bb_info->gen);
671 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
672 dump_bitmap (file, bb_info->kill);
676 /* Debugging info at top of bb. */
679 df_rd_bottom_dump (basic_block bb, FILE *file)
681 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
682 if (!bb_info || !bb_info->out)
685 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
686 dump_bitmap (file, bb_info->out);
689 /* All of the information associated with every instance of the problem. */
691 static struct df_problem problem_RD =
693 DF_RD, /* Problem id. */
694 DF_FORWARD, /* Direction. */
695 df_rd_alloc, /* Allocate the problem specific data. */
696 NULL, /* Reset global information. */
697 df_rd_free_bb_info, /* Free basic block info. */
698 df_rd_local_compute, /* Local compute function. */
699 df_rd_init_solution, /* Init the solution specific data. */
700 df_worklist_dataflow, /* Worklist solver. */
701 NULL, /* Confluence operator 0. */
702 df_rd_confluence_n, /* Confluence operator n. */
703 df_rd_transfer_function, /* Transfer function. */
704 NULL, /* Finalize function. */
705 df_rd_free, /* Free all of the problem information. */
706 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
707 df_rd_start_dump, /* Debugging. */
708 df_rd_top_dump, /* Debugging start block. */
709 df_rd_bottom_dump, /* Debugging end block. */
710 NULL, /* Incremental solution verify start. */
711 NULL, /* Incremental solution verify end. */
712 NULL, /* Dependent problem. */
713 TV_DF_RD, /* Timing variable. */
714 true /* Reset blocks on dropping out of blocks_to_analyze. */
719 /* Create a new DATAFLOW instance and add it to an existing instance
720 of DF. The returned structure is what is used to get at the
724 df_rd_add_problem (void)
726 df_add_problem (&problem_RD);
731 /*----------------------------------------------------------------------------
734 Find the locations in the function where any use of a pseudo can
735 reach in the backwards direction. In and out bitvectors are built
736 for each basic block. The regnum is used to index into these sets.
737 See df.h for details.
738 ----------------------------------------------------------------------------*/
740 /* Private data used to verify the solution for this problem. */
741 struct df_lr_problem_data
748 /* Set basic block info. */
751 df_lr_set_bb_info (unsigned int index,
752 struct df_lr_bb_info *bb_info)
755 gcc_assert (index < df_lr->block_info_size);
756 df_lr->block_info[index] = bb_info;
760 /* Free basic block info. */
763 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
766 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
769 BITMAP_FREE (bb_info->use);
770 BITMAP_FREE (bb_info->def);
771 BITMAP_FREE (bb_info->in);
772 BITMAP_FREE (bb_info->out);
773 pool_free (df_lr->block_pool, bb_info);
778 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
779 not touched unless the block is new. */
782 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
784 unsigned int bb_index;
787 if (!df_lr->block_pool)
788 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
789 sizeof (struct df_lr_bb_info), 50);
791 df_grow_bb_info (df_lr);
793 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
795 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
798 bitmap_clear (bb_info->def);
799 bitmap_clear (bb_info->use);
803 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
804 df_lr_set_bb_info (bb_index, bb_info);
805 bb_info->use = BITMAP_ALLOC (NULL);
806 bb_info->def = BITMAP_ALLOC (NULL);
807 bb_info->in = BITMAP_ALLOC (NULL);
808 bb_info->out = BITMAP_ALLOC (NULL);
812 df_lr->optional_p = false;
816 /* Reset the global solution for recalculation. */
819 df_lr_reset (bitmap all_blocks)
821 unsigned int bb_index;
824 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
826 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
827 gcc_assert (bb_info);
828 bitmap_clear (bb_info->in);
829 bitmap_clear (bb_info->out);
834 /* Compute local live register info for basic block BB. */
837 df_lr_bb_local_compute (unsigned int bb_index)
839 basic_block bb = BASIC_BLOCK (bb_index);
840 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
842 struct df_ref **def_rec;
843 struct df_ref **use_rec;
845 /* Process the registers set in an exception handler. */
846 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
848 struct df_ref *def = *def_rec;
849 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
851 unsigned int dregno = DF_REF_REGNO (def);
852 bitmap_set_bit (bb_info->def, dregno);
853 bitmap_clear_bit (bb_info->use, dregno);
857 /* Process the hardware registers that are always live. */
858 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
860 struct df_ref *use = *use_rec;
861 /* Add use to set of uses in this BB. */
862 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
863 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
866 FOR_BB_INSNS_REVERSE (bb, insn)
868 unsigned int uid = INSN_UID (insn);
873 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
875 struct df_ref *def = *def_rec;
876 /* If the def is to only part of the reg, it does
877 not kill the other defs that reach here. */
878 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
880 unsigned int dregno = DF_REF_REGNO (def);
881 bitmap_set_bit (bb_info->def, dregno);
882 bitmap_clear_bit (bb_info->use, dregno);
886 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
888 struct df_ref *use = *use_rec;
889 /* Add use to set of uses in this BB. */
890 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
894 /* Process the registers set in an exception handler or the hard
895 frame pointer if this block is the target of a non local
897 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
899 struct df_ref *def = *def_rec;
900 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
902 unsigned int dregno = DF_REF_REGNO (def);
903 bitmap_set_bit (bb_info->def, dregno);
904 bitmap_clear_bit (bb_info->use, dregno);
909 /* Process the uses that are live into an exception handler. */
910 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
912 struct df_ref *use = *use_rec;
913 /* Add use to set of uses in this BB. */
914 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
915 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
919 /* If the df_live problem is not defined, such as at -O0 and -O1, we
920 still need to keep the luids up to date. This is normally done
921 in the df_live problem since this problem has a forwards
924 df_recompute_luids (bb);
928 /* Compute local live register info for each basic block within BLOCKS. */
931 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
933 unsigned int bb_index;
936 bitmap_clear (df->hardware_regs_used);
938 /* The all-important stack pointer must always be live. */
939 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
941 /* Before reload, there are a few registers that must be forced
942 live everywhere -- which might not already be the case for
943 blocks within infinite loops. */
944 if (!reload_completed)
946 /* Any reference to any pseudo before reload is a potential
947 reference of the frame pointer. */
948 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
950 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
951 /* Pseudos with argument area equivalences may require
952 reloading via the argument pointer. */
953 if (fixed_regs[ARG_POINTER_REGNUM])
954 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
957 /* Any constant, or pseudo with constant equivalences, may
958 require reloading from memory using the pic register. */
959 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
960 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
961 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
964 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
966 if (bb_index == EXIT_BLOCK)
968 /* The exit block is special for this problem and its bits are
969 computed from thin air. */
970 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
971 bitmap_copy (bb_info->use, df->exit_block_uses);
974 df_lr_bb_local_compute (bb_index);
977 bitmap_clear (df_lr->out_of_date_transfer_functions);
981 /* Initialize the solution vectors. */
984 df_lr_init (bitmap all_blocks)
986 unsigned int bb_index;
989 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
991 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
992 bitmap_copy (bb_info->in, bb_info->use);
993 bitmap_clear (bb_info->out);
998 /* Confluence function that processes infinite loops. This might be a
999 noreturn function that throws. And even if it isn't, getting the
1000 unwind info right helps debugging. */
1002 df_lr_confluence_0 (basic_block bb)
1004 bitmap op1 = df_lr_get_bb_info (bb->index)->out;
1005 if (bb != EXIT_BLOCK_PTR)
1006 bitmap_copy (op1, df->hardware_regs_used);
1010 /* Confluence function that ignores fake edges. */
1013 df_lr_confluence_n (edge e)
1015 bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
1016 bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
1018 /* Call-clobbered registers die across exception and call edges. */
1019 /* ??? Abnormal call edges ignored for the moment, as this gets
1020 confused by sibling call edges, which crashes reg-stack. */
1021 if (e->flags & EDGE_EH)
1022 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
1024 bitmap_ior_into (op1, op2);
1026 bitmap_ior_into (op1, df->hardware_regs_used);
1030 /* Transfer function. */
1033 df_lr_transfer_function (int bb_index)
1035 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1036 bitmap in = bb_info->in;
1037 bitmap out = bb_info->out;
1038 bitmap use = bb_info->use;
1039 bitmap def = bb_info->def;
1041 return bitmap_ior_and_compl (in, use, out, def);
1045 /* Run the fast dce as a side effect of building LR. */
1048 df_lr_finalize (bitmap all_blocks ATTRIBUTE_UNUSED)
1050 if (df->changeable_flags & DF_LR_RUN_DCE)
1053 if (df_lr->problem_data && df_lr->solutions_dirty)
1055 /* If we are here, then it is because we are both verifying
1056 the solution and the dce changed the function. In that case
1057 the verification info built will be wrong. So we leave the
1058 dirty flag true so that the verifier will skip the checking
1059 part and just clean up.*/
1060 df_lr->solutions_dirty = true;
1063 df_lr->solutions_dirty = false;
1066 df_lr->solutions_dirty = false;
1070 /* Free all storage associated with the problem. */
1075 if (df_lr->block_info)
1078 for (i = 0; i < df_lr->block_info_size; i++)
1080 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
1083 BITMAP_FREE (bb_info->use);
1084 BITMAP_FREE (bb_info->def);
1085 BITMAP_FREE (bb_info->in);
1086 BITMAP_FREE (bb_info->out);
1089 free_alloc_pool (df_lr->block_pool);
1091 df_lr->block_info_size = 0;
1092 free (df_lr->block_info);
1095 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1100 /* Debugging info at top of bb. */
1103 df_lr_top_dump (basic_block bb, FILE *file)
1105 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1106 struct df_lr_problem_data *problem_data;
1107 if (!bb_info || !bb_info->in)
1110 fprintf (file, ";; lr in \t");
1111 df_print_regset (file, bb_info->in);
1112 if (df_lr->problem_data)
1114 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1115 fprintf (file, ";; old in \t");
1116 df_print_regset (file, problem_data->in[bb->index]);
1118 fprintf (file, ";; lr use \t");
1119 df_print_regset (file, bb_info->use);
1120 fprintf (file, ";; lr def \t");
1121 df_print_regset (file, bb_info->def);
1125 /* Debugging info at bottom of bb. */
1128 df_lr_bottom_dump (basic_block bb, FILE *file)
1130 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1131 struct df_lr_problem_data *problem_data;
1132 if (!bb_info || !bb_info->out)
1135 fprintf (file, ";; lr out \t");
1136 df_print_regset (file, bb_info->out);
1137 if (df_lr->problem_data)
1139 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1140 fprintf (file, ";; old out \t");
1141 df_print_regset (file, problem_data->out[bb->index]);
1146 /* Build the datastructure to verify that the solution to the dataflow
1147 equations is not dirty. */
1150 df_lr_verify_solution_start (void)
1153 struct df_lr_problem_data *problem_data;
1154 if (df_lr->solutions_dirty)
1156 df_lr->problem_data = NULL;
1160 /* Set it true so that the solution is recomputed. */
1161 df_lr->solutions_dirty = true;
1163 problem_data = XNEW (struct df_lr_problem_data);
1164 df_lr->problem_data = problem_data;
1165 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1166 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1170 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1171 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1172 bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
1173 bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
1178 /* Compare the saved datastructure and the new solution to the dataflow
1182 df_lr_verify_solution_end (void)
1184 struct df_lr_problem_data *problem_data;
1187 if (df_lr->problem_data == NULL)
1190 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1192 if (df_lr->solutions_dirty)
1193 /* Do not check if the solution is still dirty. See the comment
1194 in df_lr_finalize for details. */
1195 df_lr->solutions_dirty = false;
1199 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
1200 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
1202 /*df_dump (stderr);*/
1207 /* Cannot delete them immediately because you may want to dump them
1208 if the comparison fails. */
1211 BITMAP_FREE (problem_data->in[bb->index]);
1212 BITMAP_FREE (problem_data->out[bb->index]);
1215 free (problem_data->in);
1216 free (problem_data->out);
1217 free (problem_data);
1218 df_lr->problem_data = NULL;
1222 /* All of the information associated with every instance of the problem. */
1224 static struct df_problem problem_LR =
1226 DF_LR, /* Problem id. */
1227 DF_BACKWARD, /* Direction. */
1228 df_lr_alloc, /* Allocate the problem specific data. */
1229 df_lr_reset, /* Reset global information. */
1230 df_lr_free_bb_info, /* Free basic block info. */
1231 df_lr_local_compute, /* Local compute function. */
1232 df_lr_init, /* Init the solution specific data. */
1233 df_worklist_dataflow, /* Worklist solver. */
1234 df_lr_confluence_0, /* Confluence operator 0. */
1235 df_lr_confluence_n, /* Confluence operator n. */
1236 df_lr_transfer_function, /* Transfer function. */
1237 df_lr_finalize, /* Finalize function. */
1238 df_lr_free, /* Free all of the problem information. */
1239 NULL, /* Remove this problem from the stack of dataflow problems. */
1240 NULL, /* Debugging. */
1241 df_lr_top_dump, /* Debugging start block. */
1242 df_lr_bottom_dump, /* Debugging end block. */
1243 df_lr_verify_solution_start,/* Incremental solution verify start. */
1244 df_lr_verify_solution_end, /* Incremental solution verify end. */
1245 NULL, /* Dependent problem. */
1246 TV_DF_LR, /* Timing variable. */
1247 false /* Reset blocks on dropping out of blocks_to_analyze. */
1251 /* Create a new DATAFLOW instance and add it to an existing instance
1252 of DF. The returned structure is what is used to get at the
1256 df_lr_add_problem (void)
1258 df_add_problem (&problem_LR);
1259 /* These will be initialized when df_scan_blocks processes each
1261 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1265 /* Verify that all of the lr related info is consistent and
1269 df_lr_verify_transfer_functions (void)
1281 saved_def = BITMAP_ALLOC (NULL);
1282 saved_use = BITMAP_ALLOC (NULL);
1283 saved_adef = BITMAP_ALLOC (NULL);
1284 saved_ause = BITMAP_ALLOC (NULL);
1285 all_blocks = BITMAP_ALLOC (NULL);
1289 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1290 bitmap_set_bit (all_blocks, bb->index);
1294 /* Make a copy of the transfer functions and then compute
1295 new ones to see if the transfer functions have
1297 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1300 bitmap_copy (saved_def, bb_info->def);
1301 bitmap_copy (saved_use, bb_info->use);
1302 bitmap_clear (bb_info->def);
1303 bitmap_clear (bb_info->use);
1305 df_lr_bb_local_compute (bb->index);
1306 gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
1307 gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
1312 /* If we do not have basic block info, the block must be in
1313 the list of dirty blocks or else some one has added a
1314 block behind our backs. */
1315 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1318 /* Make sure no one created a block without following
1320 gcc_assert (df_scan_get_bb_info (bb->index));
1323 /* Make sure there are no dirty bits in blocks that have been deleted. */
1324 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1327 BITMAP_FREE (saved_def);
1328 BITMAP_FREE (saved_use);
1329 BITMAP_FREE (saved_adef);
1330 BITMAP_FREE (saved_ause);
1331 BITMAP_FREE (all_blocks);
1336 /*----------------------------------------------------------------------------
1337 LIVE AND MUST-INITIALIZED REGISTERS.
1339 This problem first computes the IN and OUT bitvectors for the
1340 must-initialized registers problems, which is a forward problem.
1341 It gives the set of registers for which we MUST have an available
1342 definition on any path from the entry block to the entry/exit of
1343 a basic block. Sets generate a definition, while clobbers kill
1346 In and out bitvectors are built for each basic block and are indexed by
1347 regnum (see df.h for details). In and out bitvectors in struct
1348 df_live_bb_info actually refers to the must-initialized problem;
1350 Then, the in and out sets for the LIVE problem itself are computed.
1351 These are the logical AND of the IN and OUT sets from the LR problem
1352 and the must-initialized problem.
1353 ----------------------------------------------------------------------------*/
1355 /* Private data used to verify the solution for this problem. */
1356 struct df_live_problem_data
1362 /* Scratch var used by transfer functions. This is used to implement
1363 an optimization to reduce the amount of space used to compute the
1364 combined lr and live analysis. */
1365 static bitmap df_live_scratch;
1367 /* Set basic block info. */
1370 df_live_set_bb_info (unsigned int index,
1371 struct df_live_bb_info *bb_info)
1373 gcc_assert (df_live);
1374 gcc_assert (index < df_live->block_info_size);
1375 df_live->block_info[index] = bb_info;
1379 /* Free basic block info. */
1382 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1385 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1388 BITMAP_FREE (bb_info->gen);
1389 BITMAP_FREE (bb_info->kill);
1390 BITMAP_FREE (bb_info->in);
1391 BITMAP_FREE (bb_info->out);
1392 pool_free (df_live->block_pool, bb_info);
1397 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1398 not touched unless the block is new. */
1401 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1403 unsigned int bb_index;
1406 if (!df_live->block_pool)
1407 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1408 sizeof (struct df_live_bb_info), 100);
1409 if (!df_live_scratch)
1410 df_live_scratch = BITMAP_ALLOC (NULL);
1412 df_grow_bb_info (df_live);
1414 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1416 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1419 bitmap_clear (bb_info->kill);
1420 bitmap_clear (bb_info->gen);
1424 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1425 df_live_set_bb_info (bb_index, bb_info);
1426 bb_info->kill = BITMAP_ALLOC (NULL);
1427 bb_info->gen = BITMAP_ALLOC (NULL);
1428 bb_info->in = BITMAP_ALLOC (NULL);
1429 bb_info->out = BITMAP_ALLOC (NULL);
1432 df_live->optional_p = (optimize <= 1);
1436 /* Reset the global solution for recalculation. */
1439 df_live_reset (bitmap all_blocks)
1441 unsigned int bb_index;
1444 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1446 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1447 gcc_assert (bb_info);
1448 bitmap_clear (bb_info->in);
1449 bitmap_clear (bb_info->out);
1454 /* Compute local uninitialized register info for basic block BB. */
1457 df_live_bb_local_compute (unsigned int bb_index)
1459 basic_block bb = BASIC_BLOCK (bb_index);
1460 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1462 struct df_ref **def_rec;
1465 FOR_BB_INSNS (bb, insn)
1467 unsigned int uid = INSN_UID (insn);
1468 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1470 /* Inserting labels does not always trigger the incremental
1474 gcc_assert (!INSN_P (insn));
1475 df_insn_create_insn_record (insn);
1478 DF_INSN_LUID (insn) = luid;
1483 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1485 struct df_ref *def = *def_rec;
1486 unsigned int regno = DF_REF_REGNO (def);
1488 if (DF_REF_FLAGS_IS_SET (def,
1489 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1490 /* All partial or conditional def
1491 seen are included in the gen set. */
1492 bitmap_set_bit (bb_info->gen, regno);
1493 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1494 /* Only must clobbers for the entire reg destroy the
1496 bitmap_set_bit (bb_info->kill, regno);
1497 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1498 bitmap_set_bit (bb_info->gen, regno);
1502 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1504 struct df_ref *def = *def_rec;
1505 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1510 /* Compute local uninitialized register info. */
1513 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1515 unsigned int bb_index;
1518 df_grow_insn_info ();
1520 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1523 df_live_bb_local_compute (bb_index);
1526 bitmap_clear (df_live->out_of_date_transfer_functions);
1530 /* Initialize the solution vectors. */
1533 df_live_init (bitmap all_blocks)
1535 unsigned int bb_index;
1538 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1540 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1541 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1543 /* No register may reach a location where it is not used. Thus
1544 we trim the rr result to the places where it is used. */
1545 bitmap_and (bb_info->out, bb_info->gen, bb_lr_info->out);
1546 bitmap_clear (bb_info->in);
1550 /* Forward confluence function that ignores fake edges. */
1553 df_live_confluence_n (edge e)
1555 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
1556 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
1558 if (e->flags & EDGE_FAKE)
1561 bitmap_ior_into (op1, op2);
1565 /* Transfer function for the forwards must-initialized problem. */
1568 df_live_transfer_function (int bb_index)
1570 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1571 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1572 bitmap in = bb_info->in;
1573 bitmap out = bb_info->out;
1574 bitmap gen = bb_info->gen;
1575 bitmap kill = bb_info->kill;
1577 /* We need to use a scratch set here so that the value returned from
1578 this function invocation properly reflects if the sets changed in
1579 a significant way; i.e. not just because the lr set was anded
1581 bitmap_and (df_live_scratch, gen, bb_lr_info->out);
1582 /* No register may reach a location where it is not used. Thus
1583 we trim the rr result to the places where it is used. */
1584 bitmap_and_into (in, bb_lr_info->in);
1586 return bitmap_ior_and_compl (out, df_live_scratch, in, kill);
1590 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1593 df_live_finalize (bitmap all_blocks)
1596 if (df_live->solutions_dirty)
1599 unsigned int bb_index;
1601 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1603 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1604 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1606 /* No register may reach a location where it is not used. Thus
1607 we trim the rr result to the places where it is used. */
1608 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
1609 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
1612 df_live->solutions_dirty = false;
1617 /* Free all storage associated with the problem. */
1622 if (df_live->block_info)
1626 for (i = 0; i < df_live->block_info_size; i++)
1628 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
1631 BITMAP_FREE (bb_info->gen);
1632 BITMAP_FREE (bb_info->kill);
1633 BITMAP_FREE (bb_info->in);
1634 BITMAP_FREE (bb_info->out);
1638 free_alloc_pool (df_live->block_pool);
1639 df_live->block_info_size = 0;
1640 free (df_live->block_info);
1642 if (df_live_scratch)
1643 BITMAP_FREE (df_live_scratch);
1645 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1650 /* Debugging info at top of bb. */
1653 df_live_top_dump (basic_block bb, FILE *file)
1655 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1656 struct df_live_problem_data *problem_data;
1658 if (!bb_info || !bb_info->in)
1661 fprintf (file, ";; live in \t");
1662 df_print_regset (file, bb_info->in);
1663 if (df_live->problem_data)
1665 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1666 fprintf (file, ";; old in \t");
1667 df_print_regset (file, problem_data->in[bb->index]);
1669 fprintf (file, ";; live gen \t");
1670 df_print_regset (file, bb_info->gen);
1671 fprintf (file, ";; live kill\t");
1672 df_print_regset (file, bb_info->kill);
1676 /* Debugging info at bottom of bb. */
1679 df_live_bottom_dump (basic_block bb, FILE *file)
1681 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1682 struct df_live_problem_data *problem_data;
1684 if (!bb_info || !bb_info->out)
1687 fprintf (file, ";; live out \t");
1688 df_print_regset (file, bb_info->out);
1689 if (df_live->problem_data)
1691 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1692 fprintf (file, ";; old out \t");
1693 df_print_regset (file, problem_data->out[bb->index]);
1698 /* Build the datastructure to verify that the solution to the dataflow
1699 equations is not dirty. */
1702 df_live_verify_solution_start (void)
1705 struct df_live_problem_data *problem_data;
1706 if (df_live->solutions_dirty)
1708 df_live->problem_data = NULL;
1712 /* Set it true so that the solution is recomputed. */
1713 df_live->solutions_dirty = true;
1715 problem_data = XNEW (struct df_live_problem_data);
1716 df_live->problem_data = problem_data;
1717 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1718 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1722 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1723 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1724 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
1725 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
1730 /* Compare the saved datastructure and the new solution to the dataflow
1734 df_live_verify_solution_end (void)
1736 struct df_live_problem_data *problem_data;
1739 if (df_live->problem_data == NULL)
1742 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1746 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
1747 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1749 /*df_dump (stderr);*/
1754 /* Cannot delete them immediately because you may want to dump them
1755 if the comparison fails. */
1758 BITMAP_FREE (problem_data->in[bb->index]);
1759 BITMAP_FREE (problem_data->out[bb->index]);
1762 free (problem_data->in);
1763 free (problem_data->out);
1764 free (problem_data);
1765 df_live->problem_data = NULL;
1769 /* All of the information associated with every instance of the problem. */
1771 static struct df_problem problem_LIVE =
1773 DF_LIVE, /* Problem id. */
1774 DF_FORWARD, /* Direction. */
1775 df_live_alloc, /* Allocate the problem specific data. */
1776 df_live_reset, /* Reset global information. */
1777 df_live_free_bb_info, /* Free basic block info. */
1778 df_live_local_compute, /* Local compute function. */
1779 df_live_init, /* Init the solution specific data. */
1780 df_worklist_dataflow, /* Worklist solver. */
1781 NULL, /* Confluence operator 0. */
1782 df_live_confluence_n, /* Confluence operator n. */
1783 df_live_transfer_function, /* Transfer function. */
1784 df_live_finalize, /* Finalize function. */
1785 df_live_free, /* Free all of the problem information. */
1786 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1787 NULL, /* Debugging. */
1788 df_live_top_dump, /* Debugging start block. */
1789 df_live_bottom_dump, /* Debugging end block. */
1790 df_live_verify_solution_start,/* Incremental solution verify start. */
1791 df_live_verify_solution_end, /* Incremental solution verify end. */
1792 &problem_LR, /* Dependent problem. */
1793 TV_DF_LIVE, /* Timing variable. */
1794 false /* Reset blocks on dropping out of blocks_to_analyze. */
1798 /* Create a new DATAFLOW instance and add it to an existing instance
1799 of DF. The returned structure is what is used to get at the
1803 df_live_add_problem (void)
1805 df_add_problem (&problem_LIVE);
1806 /* These will be initialized when df_scan_blocks processes each
1808 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1812 /* Set all of the blocks as dirty. This needs to be done if this
1813 problem is added after all of the insns have been scanned. */
1816 df_live_set_all_dirty (void)
1820 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1825 /* Verify that all of the lr related info is consistent and
1829 df_live_verify_transfer_functions (void)
1839 saved_gen = BITMAP_ALLOC (NULL);
1840 saved_kill = BITMAP_ALLOC (NULL);
1841 all_blocks = BITMAP_ALLOC (NULL);
1843 df_grow_insn_info ();
1847 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1848 bitmap_set_bit (all_blocks, bb->index);
1852 /* Make a copy of the transfer functions and then compute
1853 new ones to see if the transfer functions have
1855 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1858 bitmap_copy (saved_gen, bb_info->gen);
1859 bitmap_copy (saved_kill, bb_info->kill);
1860 bitmap_clear (bb_info->gen);
1861 bitmap_clear (bb_info->kill);
1863 df_live_bb_local_compute (bb->index);
1864 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
1865 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
1870 /* If we do not have basic block info, the block must be in
1871 the list of dirty blocks or else some one has added a
1872 block behind our backs. */
1873 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1876 /* Make sure no one created a block without following
1878 gcc_assert (df_scan_get_bb_info (bb->index));
1881 /* Make sure there are no dirty bits in blocks that have been deleted. */
1882 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1884 BITMAP_FREE (saved_gen);
1885 BITMAP_FREE (saved_kill);
1886 BITMAP_FREE (all_blocks);
1889 /*----------------------------------------------------------------------------
1890 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1892 Link either the defs to the uses and / or the uses to the defs.
1894 These problems are set up like the other dataflow problems so that
1895 they nicely fit into the framework. They are much simpler and only
1896 involve a single traversal of instructions and an examination of
1897 the reaching defs information (the dependent problem).
1898 ----------------------------------------------------------------------------*/
1900 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1902 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1905 df_chain_create (struct df_ref *src, struct df_ref *dst)
1907 struct df_link *head = DF_REF_CHAIN (src);
1908 struct df_link *link = pool_alloc (df_chain->block_pool);;
1910 DF_REF_CHAIN (src) = link;
1917 /* Delete any du or ud chains that start at REF and point to
1920 df_chain_unlink_1 (struct df_ref *ref, struct df_ref *target)
1922 struct df_link *chain = DF_REF_CHAIN (ref);
1923 struct df_link *prev = NULL;
1927 if (chain->ref == target)
1930 prev->next = chain->next;
1932 DF_REF_CHAIN (ref) = chain->next;
1933 pool_free (df_chain->block_pool, chain);
1937 chain = chain->next;
1942 /* Delete a du or ud chain that leave or point to REF. */
1945 df_chain_unlink (struct df_ref *ref)
1947 struct df_link *chain = DF_REF_CHAIN (ref);
1950 struct df_link *next = chain->next;
1951 /* Delete the other side if it exists. */
1952 df_chain_unlink_1 (chain->ref, ref);
1953 pool_free (df_chain->block_pool, chain);
1956 DF_REF_CHAIN (ref) = NULL;
1960 /* Copy the du or ud chain starting at FROM_REF and attach it to
1964 df_chain_copy (struct df_ref *to_ref,
1965 struct df_link *from_ref)
1969 df_chain_create (to_ref, from_ref->ref);
1970 from_ref = from_ref->next;
1975 /* Remove this problem from the stack of dataflow problems. */
1978 df_chain_remove_problem (void)
1981 unsigned int bb_index;
1983 /* Wholesale destruction of the old chains. */
1984 if (df_chain->block_pool)
1985 free_alloc_pool (df_chain->block_pool);
1987 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1990 struct df_ref **def_rec;
1991 struct df_ref **use_rec;
1992 basic_block bb = BASIC_BLOCK (bb_index);
1994 if (df_chain_problem_p (DF_DU_CHAIN))
1995 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1996 DF_REF_CHAIN (*def_rec) = NULL;
1997 if (df_chain_problem_p (DF_UD_CHAIN))
1998 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1999 DF_REF_CHAIN (*use_rec) = NULL;
2001 FOR_BB_INSNS (bb, insn)
2003 unsigned int uid = INSN_UID (insn);
2007 if (df_chain_problem_p (DF_DU_CHAIN))
2008 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2009 DF_REF_CHAIN (*def_rec) = NULL;
2010 if (df_chain_problem_p (DF_UD_CHAIN))
2012 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2013 DF_REF_CHAIN (*use_rec) = NULL;
2014 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
2015 DF_REF_CHAIN (*use_rec) = NULL;
2021 bitmap_clear (df_chain->out_of_date_transfer_functions);
2022 df_chain->block_pool = NULL;
2026 /* Remove the chain problem completely. */
2029 df_chain_fully_remove_problem (void)
2031 df_chain_remove_problem ();
2032 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2037 /* Create def-use or use-def chains. */
2040 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2042 df_chain_remove_problem ();
2043 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2044 sizeof (struct df_link), 50);
2045 df_chain->optional_p = true;
2049 /* Reset all of the chains when the set of basic blocks changes. */
2052 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2054 df_chain_remove_problem ();
2058 /* Create the chains for a list of USEs. */
2061 df_chain_create_bb_process_use (bitmap local_rd,
2062 struct df_ref **use_rec,
2063 enum df_ref_flags top_flag)
2066 unsigned int def_index;
2070 struct df_ref *use = *use_rec;
2071 unsigned int uregno = DF_REF_REGNO (use);
2072 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2073 || (uregno >= FIRST_PSEUDO_REGISTER))
2075 /* Do not want to go through this for an uninitialized var. */
2076 int count = DF_DEFS_COUNT (uregno);
2079 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2081 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2082 unsigned int last_index = first_index + count - 1;
2084 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2087 if (def_index > last_index)
2090 def = DF_DEFS_GET (def_index);
2091 if (df_chain_problem_p (DF_DU_CHAIN))
2092 df_chain_create (def, use);
2093 if (df_chain_problem_p (DF_UD_CHAIN))
2094 df_chain_create (use, def);
2105 /* Create chains from reaching defs bitmaps for basic block BB. */
2108 df_chain_create_bb (unsigned int bb_index)
2110 basic_block bb = BASIC_BLOCK (bb_index);
2111 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2113 bitmap cpy = BITMAP_ALLOC (NULL);
2114 struct df_ref **def_rec;
2116 bitmap_copy (cpy, bb_info->in);
2117 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2119 /* Since we are going forwards, process the artificial uses first
2120 then the artificial defs second. */
2123 /* Create the chains for the artificial uses from the EH_USES at the
2124 beginning of the block. */
2126 /* Artificials are only hard regs. */
2127 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2128 df_chain_create_bb_process_use (cpy,
2129 df_get_artificial_uses (bb->index),
2133 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2135 struct df_ref *def = *def_rec;
2136 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2138 unsigned int dregno = DF_REF_REGNO (def);
2139 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2140 bitmap_clear_range (cpy,
2141 DF_DEFS_BEGIN (dregno),
2142 DF_DEFS_COUNT (dregno));
2143 bitmap_set_bit (cpy, DF_REF_ID (def));
2147 /* Process the regular instructions next. */
2148 FOR_BB_INSNS (bb, insn)
2150 struct df_ref **def_rec;
2151 unsigned int uid = INSN_UID (insn);
2156 /* Now scan the uses and link them up with the defs that remain
2157 in the cpy vector. */
2159 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
2161 if (df->changeable_flags & DF_EQ_NOTES)
2162 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
2165 /* Since we are going forwards, process the defs second. This
2166 pass only changes the bits in cpy. */
2167 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2169 struct df_ref *def = *def_rec;
2170 unsigned int dregno = DF_REF_REGNO (def);
2171 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2172 || (dregno >= FIRST_PSEUDO_REGISTER))
2174 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2175 bitmap_clear_range (cpy,
2176 DF_DEFS_BEGIN (dregno),
2177 DF_DEFS_COUNT (dregno));
2178 if (!(DF_REF_FLAGS (def)
2179 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
2180 bitmap_set_bit (cpy, DF_REF_ID (def));
2185 /* Create the chains for the artificial uses of the hard registers
2186 at the end of the block. */
2187 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2188 df_chain_create_bb_process_use (cpy,
2189 df_get_artificial_uses (bb->index),
2195 /* Create def-use chains from reaching use bitmaps for basic blocks
2199 df_chain_finalize (bitmap all_blocks)
2201 unsigned int bb_index;
2204 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2206 df_chain_create_bb (bb_index);
2211 /* Free all storage associated with the problem. */
2214 df_chain_free (void)
2216 free_alloc_pool (df_chain->block_pool);
2217 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2222 /* Debugging info. */
2225 df_chain_top_dump (basic_block bb, FILE *file)
2227 if (df_chain_problem_p (DF_DU_CHAIN))
2230 struct df_ref **def_rec = df_get_artificial_defs (bb->index);
2234 fprintf (file, ";; DU chains for artificial defs\n");
2237 struct df_ref *def = *def_rec;
2238 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2239 df_chain_dump (DF_REF_CHAIN (def), file);
2240 fprintf (file, "\n");
2245 FOR_BB_INSNS (bb, insn)
2247 unsigned int uid = INSN_UID (insn);
2250 def_rec = DF_INSN_UID_DEFS (uid);
2253 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2254 DF_INSN_LUID (insn), uid);
2258 struct df_ref *def = *def_rec;
2259 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2260 if (def->flags & DF_REF_READ_WRITE)
2261 fprintf (file, "read/write ");
2262 df_chain_dump (DF_REF_CHAIN (def), file);
2263 fprintf (file, "\n");
2274 df_chain_bottom_dump (basic_block bb, FILE *file)
2276 if (df_chain_problem_p (DF_UD_CHAIN))
2279 struct df_ref **use_rec = df_get_artificial_uses (bb->index);
2283 fprintf (file, ";; UD chains for artificial uses\n");
2286 struct df_ref *use = *use_rec;
2287 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2288 df_chain_dump (DF_REF_CHAIN (use), file);
2289 fprintf (file, "\n");
2294 FOR_BB_INSNS (bb, insn)
2296 unsigned int uid = INSN_UID (insn);
2299 struct df_ref **eq_use_rec = DF_INSN_UID_EQ_USES (uid);
2300 use_rec = DF_INSN_UID_USES (uid);
2301 if (*use_rec || *eq_use_rec)
2303 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2304 DF_INSN_LUID (insn), uid);
2308 struct df_ref *use = *use_rec;
2309 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2310 if (use->flags & DF_REF_READ_WRITE)
2311 fprintf (file, "read/write ");
2312 df_chain_dump (DF_REF_CHAIN (use), file);
2313 fprintf (file, "\n");
2318 struct df_ref *use = *eq_use_rec;
2319 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2320 df_chain_dump (DF_REF_CHAIN (use), file);
2321 fprintf (file, "\n");
2331 static struct df_problem problem_CHAIN =
2333 DF_CHAIN, /* Problem id. */
2334 DF_NONE, /* Direction. */
2335 df_chain_alloc, /* Allocate the problem specific data. */
2336 df_chain_reset, /* Reset global information. */
2337 NULL, /* Free basic block info. */
2338 NULL, /* Local compute function. */
2339 NULL, /* Init the solution specific data. */
2340 NULL, /* Iterative solver. */
2341 NULL, /* Confluence operator 0. */
2342 NULL, /* Confluence operator n. */
2343 NULL, /* Transfer function. */
2344 df_chain_finalize, /* Finalize function. */
2345 df_chain_free, /* Free all of the problem information. */
2346 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2347 NULL, /* Debugging. */
2348 df_chain_top_dump, /* Debugging start block. */
2349 df_chain_bottom_dump, /* Debugging end block. */
2350 NULL, /* Incremental solution verify start. */
2351 NULL, /* Incremental solution verify end. */
2352 &problem_RD, /* Dependent problem. */
2353 TV_DF_CHAIN, /* Timing variable. */
2354 false /* Reset blocks on dropping out of blocks_to_analyze. */
2358 /* Create a new DATAFLOW instance and add it to an existing instance
2359 of DF. The returned structure is what is used to get at the
2363 df_chain_add_problem (enum df_chain_flags chain_flags)
2365 df_add_problem (&problem_CHAIN);
2366 df_chain->local_flags = (unsigned int)chain_flags;
2367 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2370 #undef df_chain_problem_p
2373 /*----------------------------------------------------------------------------
2374 This pass computes REG_DEAD and REG_UNUSED notes.
2375 ----------------------------------------------------------------------------*/
2378 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2380 df_note->optional_p = true;
2383 #ifdef REG_DEAD_DEBUGGING
2385 df_print_note (const char *prefix, rtx insn, rtx note)
2389 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2390 print_rtl (dump_file, note);
2391 fprintf (dump_file, "\n");
2397 /* After reg-stack, the x86 floating point stack regs are difficult to
2398 analyze because of all of the pushes, pops and rotations. Thus, we
2399 just leave the notes alone. */
2403 df_ignore_stack_reg (int regno)
2405 return regstack_completed
2406 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2410 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2417 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2418 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
2421 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
2423 rtx *pprev = ®_NOTES (insn);
2430 switch (REG_NOTE_KIND (link))
2433 /* After reg-stack, we need to ignore any unused notes
2434 for the stack registers. */
2435 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2437 pprev = &XEXP (link, 1);
2442 rtx next = XEXP (link, 1);
2443 #ifdef REG_DEAD_DEBUGGING
2444 df_print_note ("deleting: ", insn, link);
2446 XEXP (link, 1) = dead;
2448 *pprev = link = next;
2453 /* After reg-stack, we need to ignore any unused notes
2454 for the stack registers. */
2455 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2457 pprev = &XEXP (link, 1);
2462 rtx next = XEXP (link, 1);
2463 #ifdef REG_DEAD_DEBUGGING
2464 df_print_note ("deleting: ", insn, link);
2466 XEXP (link, 1) = unused;
2468 *pprev = link = next;
2473 pprev = &XEXP (link, 1);
2479 *old_dead_notes = dead;
2480 *old_unused_notes = unused;
2484 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
2485 list, otherwise create a new one. */
2488 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
2494 if (XEXP (this, 0) == reg)
2497 XEXP (prev, 1) = XEXP (this, 1);
2499 old = XEXP (this, 1);
2500 XEXP (this, 1) = REG_NOTES (insn);
2501 REG_NOTES (insn) = this;
2507 this = XEXP (this, 1);
2510 /* Did not find the note. */
2511 REG_NOTES (insn) = alloc_EXPR_LIST (note_type, reg, REG_NOTES (insn));
2515 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2516 arguments. Return true if the register value described by MWS's
2517 mw_reg is known to be completely unused, and if mw_reg can therefore
2518 be used in a REG_UNUSED note. */
2521 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2522 bitmap live, bitmap artificial_uses)
2526 /* If MWS describes a partial reference, create REG_UNUSED notes for
2527 individual hard registers. */
2528 if (mws->flags & DF_REF_PARTIAL)
2531 /* Likewise if some part of the register is used. */
2532 for (r = mws->start_regno; r <= mws->end_regno; r++)
2533 if (bitmap_bit_p (live, r)
2534 || bitmap_bit_p (artificial_uses, r))
2537 gcc_assert (REG_P (mws->mw_reg));
2541 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2542 based on the bits in LIVE. Do not generate notes for registers in
2543 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2544 not generated if the reg is both read and written by the
2549 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2550 bitmap live, bitmap do_not_gen,
2551 bitmap artificial_uses)
2555 #ifdef REG_DEAD_DEBUGGING
2557 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2558 mws->start_regno, mws->end_regno);
2561 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
2563 unsigned int regno = mws->start_regno;
2564 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
2566 #ifdef REG_DEAD_DEBUGGING
2567 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2569 bitmap_set_bit (do_not_gen, regno);
2570 /* Only do this if the value is totally dead. */
2573 for (r = mws->start_regno; r <= mws->end_regno; r++)
2575 if (!bitmap_bit_p (live, r)
2576 && !bitmap_bit_p (artificial_uses, r))
2578 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
2579 #ifdef REG_DEAD_DEBUGGING
2580 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2583 bitmap_set_bit (do_not_gen, r);
2589 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2590 arguments. Return true if the register value described by MWS's
2591 mw_reg is known to be completely dead, and if mw_reg can therefore
2592 be used in a REG_DEAD note. */
2595 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2596 bitmap live, bitmap artificial_uses,
2601 /* If MWS describes a partial reference, create REG_DEAD notes for
2602 individual hard registers. */
2603 if (mws->flags & DF_REF_PARTIAL)
2606 /* Likewise if some part of the register is not dead. */
2607 for (r = mws->start_regno; r <= mws->end_regno; r++)
2608 if (bitmap_bit_p (live, r)
2609 || bitmap_bit_p (artificial_uses, r)
2610 || bitmap_bit_p (do_not_gen, r))
2613 gcc_assert (REG_P (mws->mw_reg));
2617 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2618 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2619 from being set if the instruction both reads and writes the
2623 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
2624 bitmap live, bitmap do_not_gen,
2625 bitmap artificial_uses)
2629 #ifdef REG_DEAD_DEBUGGING
2632 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2633 mws->start_regno, mws->end_regno);
2634 df_print_regset (dump_file, do_not_gen);
2635 fprintf (dump_file, " live =");
2636 df_print_regset (dump_file, live);
2637 fprintf (dump_file, " artificial uses =");
2638 df_print_regset (dump_file, artificial_uses);
2642 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
2644 /* Add a dead note for the entire multi word register. */
2645 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
2646 #ifdef REG_DEAD_DEBUGGING
2647 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
2652 for (r = mws->start_regno; r <= mws->end_regno; r++)
2653 if (!bitmap_bit_p (live, r)
2654 && !bitmap_bit_p (artificial_uses, r)
2655 && !bitmap_bit_p (do_not_gen, r))
2657 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
2658 #ifdef REG_DEAD_DEBUGGING
2659 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
2667 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
2668 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
2671 df_create_unused_note (rtx insn, rtx old, struct df_ref *def,
2672 bitmap live, bitmap artificial_uses)
2674 unsigned int dregno = DF_REF_REGNO (def);
2676 #ifdef REG_DEAD_DEBUGGING
2679 fprintf (dump_file, " regular looking at def ");
2680 df_ref_debug (def, dump_file);
2684 if (!(bitmap_bit_p (live, dregno)
2685 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
2686 || bitmap_bit_p (artificial_uses, dregno)
2687 || df_ignore_stack_reg (dregno)))
2689 rtx reg = (DF_REF_LOC (def))
2690 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
2691 old = df_set_note (REG_UNUSED, insn, old, reg);
2692 #ifdef REG_DEAD_DEBUGGING
2693 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
2701 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
2702 info: lifetime, bb, and number of defs and uses for basic block
2703 BB. The three bitvectors are scratch regs used here. */
2706 df_note_bb_compute (unsigned int bb_index,
2707 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
2709 basic_block bb = BASIC_BLOCK (bb_index);
2711 struct df_ref **def_rec;
2712 struct df_ref **use_rec;
2714 bitmap_copy (live, df_get_live_out (bb));
2715 bitmap_clear (artificial_uses);
2717 #ifdef REG_DEAD_DEBUGGING
2720 fprintf (dump_file, "live at bottom ");
2721 df_print_regset (dump_file, live);
2725 /* Process the artificial defs and uses at the bottom of the block
2726 to begin processing. */
2727 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2729 struct df_ref *def = *def_rec;
2730 #ifdef REG_DEAD_DEBUGGING
2732 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
2735 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2736 bitmap_clear_bit (live, DF_REF_REGNO (def));
2739 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2741 struct df_ref *use = *use_rec;
2742 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2744 unsigned int regno = DF_REF_REGNO (use);
2745 bitmap_set_bit (live, regno);
2747 /* Notes are not generated for any of the artificial registers
2748 at the bottom of the block. */
2749 bitmap_set_bit (artificial_uses, regno);
2753 #ifdef REG_DEAD_DEBUGGING
2756 fprintf (dump_file, "live before artificials out ");
2757 df_print_regset (dump_file, live);
2761 FOR_BB_INSNS_REVERSE (bb, insn)
2763 unsigned int uid = INSN_UID (insn);
2764 struct df_mw_hardreg **mws_rec;
2766 rtx old_unused_notes;
2771 bitmap_clear (do_not_gen);
2772 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
2774 /* Process the defs. */
2777 #ifdef REG_DEAD_DEBUGGING
2780 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
2781 df_print_regset (dump_file, live);
2784 /* We only care about real sets for calls. Clobbers cannot
2785 be depended on to really die. */
2786 mws_rec = DF_INSN_UID_MWS (uid);
2789 struct df_mw_hardreg *mws = *mws_rec;
2790 if ((mws->type == DF_REF_REG_DEF)
2791 && !df_ignore_stack_reg (mws->start_regno))
2793 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2794 mws, live, do_not_gen,
2799 /* All of the defs except the return value are some sort of
2800 clobber. This code is for the return. */
2801 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2803 struct df_ref *def = *def_rec;
2804 unsigned int dregno = DF_REF_REGNO (def);
2805 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2808 = df_create_unused_note (insn, old_unused_notes,
2809 def, live, artificial_uses);
2810 bitmap_set_bit (do_not_gen, dregno);
2813 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2814 bitmap_clear_bit (live, dregno);
2820 mws_rec = DF_INSN_UID_MWS (uid);
2823 struct df_mw_hardreg *mws = *mws_rec;
2824 if (mws->type == DF_REF_REG_DEF)
2826 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2827 mws, live, do_not_gen,
2832 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2834 struct df_ref *def = *def_rec;
2835 unsigned int dregno = DF_REF_REGNO (def);
2837 = df_create_unused_note (insn, old_unused_notes,
2838 def, live, artificial_uses);
2840 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2841 bitmap_set_bit (do_not_gen, dregno);
2843 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2844 bitmap_clear_bit (live, dregno);
2848 /* Process the uses. */
2849 mws_rec = DF_INSN_UID_MWS (uid);
2852 struct df_mw_hardreg *mws = *mws_rec;
2853 if ((mws->type != DF_REF_REG_DEF)
2854 && !df_ignore_stack_reg (mws->start_regno))
2856 = df_set_dead_notes_for_mw (insn, old_dead_notes,
2857 mws, live, do_not_gen,
2862 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2864 struct df_ref *use = *use_rec;
2865 unsigned int uregno = DF_REF_REGNO (use);
2867 #ifdef REG_DEAD_DEBUGGING
2870 fprintf (dump_file, " regular looking at use ");
2871 df_ref_debug (use, dump_file);
2874 if (!bitmap_bit_p (live, uregno))
2876 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
2877 && (!bitmap_bit_p (do_not_gen, uregno))
2878 && (!bitmap_bit_p (artificial_uses, uregno))
2879 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
2880 && (!df_ignore_stack_reg (uregno)))
2882 rtx reg = (DF_REF_LOC (use))
2883 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
2884 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
2886 #ifdef REG_DEAD_DEBUGGING
2887 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
2890 /* This register is now live. */
2891 bitmap_set_bit (live, uregno);
2895 while (old_unused_notes)
2897 rtx next = XEXP (old_unused_notes, 1);
2898 free_EXPR_LIST_node (old_unused_notes);
2899 old_unused_notes = next;
2901 while (old_dead_notes)
2903 rtx next = XEXP (old_dead_notes, 1);
2904 free_EXPR_LIST_node (old_dead_notes);
2905 old_dead_notes = next;
2911 /* Compute register info: lifetime, bb, and number of defs and uses. */
2913 df_note_compute (bitmap all_blocks)
2915 unsigned int bb_index;
2917 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
2918 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
2919 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
2921 #ifdef REG_DEAD_DEBUGGING
2923 print_rtl_with_bb (dump_file, get_insns());
2926 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2928 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
2932 BITMAP_FREE (do_not_gen);
2933 BITMAP_FREE (artificial_uses);
2937 /* Free all storage associated with the problem. */
2946 /* All of the information associated every instance of the problem. */
2948 static struct df_problem problem_NOTE =
2950 DF_NOTE, /* Problem id. */
2951 DF_NONE, /* Direction. */
2952 df_note_alloc, /* Allocate the problem specific data. */
2953 NULL, /* Reset global information. */
2954 NULL, /* Free basic block info. */
2955 df_note_compute, /* Local compute function. */
2956 NULL, /* Init the solution specific data. */
2957 NULL, /* Iterative solver. */
2958 NULL, /* Confluence operator 0. */
2959 NULL, /* Confluence operator n. */
2960 NULL, /* Transfer function. */
2961 NULL, /* Finalize function. */
2962 df_note_free, /* Free all of the problem information. */
2963 df_note_free, /* Remove this problem from the stack of dataflow problems. */
2964 NULL, /* Debugging. */
2965 NULL, /* Debugging start block. */
2966 NULL, /* Debugging end block. */
2967 NULL, /* Incremental solution verify start. */
2968 NULL, /* Incremental solution verify end. */
2969 &problem_LR, /* Dependent problem. */
2970 TV_DF_NOTE, /* Timing variable. */
2971 false /* Reset blocks on dropping out of blocks_to_analyze. */
2975 /* Create a new DATAFLOW instance and add it to an existing instance
2976 of DF. The returned structure is what is used to get at the
2980 df_note_add_problem (void)
2982 df_add_problem (&problem_NOTE);
2988 /*----------------------------------------------------------------------------
2989 Functions for simulating the effects of single insns.
2991 You can either simulate in the forwards direction, starting from
2992 the top of a block or the backwards direction from the end of the
2993 block. The main difference is that if you go forwards, the uses
2994 are examined first then the defs, and if you go backwards, the defs
2995 are examined first then the uses.
2997 If you start at the top of the block, use one of DF_LIVE_IN or
2998 DF_LR_IN. If you start at the bottom of the block use one of
2999 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3000 THEY WILL BE DESTROYED.
3002 ----------------------------------------------------------------------------*/
3005 /* Find the set of DEFs for INSN. */
3008 df_simulate_find_defs (rtx insn, bitmap defs)
3010 struct df_ref **def_rec;
3011 unsigned int uid = INSN_UID (insn);
3013 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3015 struct df_ref *def = *def_rec;
3016 /* If the def is to only part of the reg, it does
3017 not kill the other defs that reach here. */
3018 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3019 bitmap_set_bit (defs, DF_REF_REGNO (def));
3024 /* Simulate the effects of the defs of INSN on LIVE. */
3027 df_simulate_defs (rtx insn, bitmap live)
3029 struct df_ref **def_rec;
3030 unsigned int uid = INSN_UID (insn);
3032 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3034 struct df_ref *def = *def_rec;
3035 unsigned int dregno = DF_REF_REGNO (def);
3037 /* If the def is to only part of the reg, it does
3038 not kill the other defs that reach here. */
3039 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3040 bitmap_clear_bit (live, dregno);
3045 /* Simulate the effects of the uses of INSN on LIVE. */
3048 df_simulate_uses (rtx insn, bitmap live)
3050 struct df_ref **use_rec;
3051 unsigned int uid = INSN_UID (insn);
3053 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3055 struct df_ref *use = *use_rec;
3056 /* Add use to set of uses in this BB. */
3057 bitmap_set_bit (live, DF_REF_REGNO (use));
3062 /* Add back the always live regs in BB to LIVE. */
3065 df_simulate_fixup_sets (basic_block bb, bitmap live)
3067 /* These regs are considered always live so if they end up dying
3068 because of some def, we need to bring the back again. */
3069 if (bb_has_eh_pred (bb))
3070 bitmap_ior_into (live, df->eh_block_artificial_uses);
3072 bitmap_ior_into (live, df->regular_block_artificial_uses);
3076 /* Apply the artificial uses and defs at the top of BB in a forwards
3080 df_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
3082 struct df_ref **def_rec;
3083 struct df_ref **use_rec;
3084 int bb_index = bb->index;
3086 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3088 struct df_ref *use = *use_rec;
3089 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3090 bitmap_set_bit (live, DF_REF_REGNO (use));
3093 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3095 struct df_ref *def = *def_rec;
3096 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3097 bitmap_clear_bit (live, DF_REF_REGNO (def));
3102 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3105 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3107 if (! INSN_P (insn))
3110 df_simulate_uses (insn, live);
3111 df_simulate_defs (insn, live);
3112 df_simulate_fixup_sets (bb, live);
3116 /* Apply the artificial uses and defs at the end of BB in a backwards
3120 df_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3122 struct df_ref **def_rec;
3123 struct df_ref **use_rec;
3124 int bb_index = bb->index;
3126 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3128 struct df_ref *def = *def_rec;
3129 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3130 bitmap_clear_bit (live, DF_REF_REGNO (def));
3133 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3135 struct df_ref *use = *use_rec;
3136 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3137 bitmap_set_bit (live, DF_REF_REGNO (use));
3142 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3145 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3147 if (! INSN_P (insn))
3150 df_simulate_defs (insn, live);
3151 df_simulate_uses (insn, live);
3152 df_simulate_fixup_sets (bb, live);