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 2, 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 COPYING. If not, write to the Free
23 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "coretypes.h"
32 #include "insn-config.h"
37 #include "alloc-pool.h"
39 #include "hard-reg-set.h"
40 #include "basic-block.h"
50 #define REG_DEAD_DEBUGGING
53 #define DF_SPARSE_THRESHOLD 32
55 static bitmap seen_in_block = NULL;
56 static bitmap seen_in_insn = NULL;
59 /*----------------------------------------------------------------------------
60 Public functions access functions for the dataflow problems.
61 ----------------------------------------------------------------------------*/
62 /* Get the live at out set for BB no matter what problem happens to be
63 defined. This function is used by the register allocators who
64 choose different dataflow problems depending on the optimization
68 df_get_live_out (basic_block bb)
73 return DF_RA_LIVE_OUT (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_RA_LIVE_IN (bb);
93 return DF_LIVE_IN (bb);
98 /* Get the live at top set for BB no matter what problem happens to be
99 defined. This function is used by the register allocators who
100 choose different dataflow problems depending on the optimization
104 df_get_live_top (basic_block bb)
109 return DF_RA_LIVE_TOP (bb);
111 return DF_LR_TOP (bb);
115 /*----------------------------------------------------------------------------
117 ----------------------------------------------------------------------------*/
119 /* Generic versions to get the void* version of the block info. Only
120 used inside the problem instance vectors. */
122 /* Grow the bb_info array. */
125 df_grow_bb_info (struct dataflow *dflow)
127 unsigned int new_size = last_basic_block + 1;
128 if (dflow->block_info_size < new_size)
130 new_size += new_size / 4;
131 dflow->block_info = xrealloc (dflow->block_info,
132 new_size *sizeof (void*));
133 memset (dflow->block_info + dflow->block_info_size, 0,
134 (new_size - dflow->block_info_size) *sizeof (void *));
135 dflow->block_info_size = new_size;
139 /* Dump a def-use or use-def chain for REF to FILE. */
142 df_chain_dump (struct df_link *link, FILE *file)
144 fprintf (file, "{ ");
145 for (; link; link = link->next)
147 fprintf (file, "%c%d(bb %d insn %d) ",
148 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
149 DF_REF_ID (link->ref),
150 DF_REF_BBNO (link->ref),
151 DF_REF_INSN (link->ref) ? DF_REF_INSN_UID (link->ref) : -1);
157 /* Print some basic block info as part of df_dump. */
160 df_print_bb_index (basic_block bb, FILE *file)
165 fprintf (file, "\n( ");
166 FOR_EACH_EDGE (e, ei, bb->preds)
168 basic_block pred = e->src;
169 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
171 fprintf (file, ")->[%d]->( ", bb->index);
172 FOR_EACH_EDGE (e, ei, bb->succs)
174 basic_block succ = e->dest;
175 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
177 fprintf (file, ")\n");
182 /* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
188 seen_in_block = BITMAP_ALLOC (&df_bitmap_obstack);
189 seen_in_insn = BITMAP_ALLOC (&df_bitmap_obstack);
196 BITMAP_FREE (seen_in_block);
197 BITMAP_FREE (seen_in_insn);
202 /*----------------------------------------------------------------------------
205 Find the locations in the function where each use site for a pseudo
206 can reach backwards. In and out bitvectors are built for each basic
207 block. The id field in the ref is used to index into these sets.
208 See df.h for details.
210 ----------------------------------------------------------------------------*/
212 /* This problem plays a large number of games for the sake of
215 1) The order of the bits in the bitvectors. After the scanning
216 phase, all of the uses are sorted. All of the uses for the reg 0
217 are first, followed by all uses for reg 1 and so on.
219 2) There are two kill sets, one if the number of uses is less or
220 equal to DF_SPARSE_THRESHOLD and another if it is greater.
222 <= : Data is built directly in the kill set.
224 > : One level of indirection is used to keep from generating long
225 strings of 1 bits in the kill sets. Bitvectors that are indexed
226 by the regnum are used to represent that there is a killing def
227 for the register. The confluence and transfer functions use
228 these along with the bitmap_clear_range call to remove ranges of
229 bits without actually generating a knockout vector.
231 The kill and sparse_kill and the dense_invalidated_by_call and
232 sparse_invalidated_by_call both play this game. */
234 /* Private data used to compute the solution for this problem. These
235 data structures are not accessible outside of this module. */
236 struct df_ru_problem_data
238 /* The set of defs to regs invalidated by call. */
239 bitmap sparse_invalidated_by_call;
240 /* The set of defs to regs invalidated by call for ru. */
241 bitmap dense_invalidated_by_call;
242 /* An obstack for the bitmaps we need for this problem. */
243 bitmap_obstack ru_bitmaps;
246 /* Set basic block info. */
249 df_ru_set_bb_info (unsigned int index, struct df_ru_bb_info *bb_info)
252 gcc_assert (index < df_ru->block_info_size);
253 df_ru->block_info[index] = bb_info;
257 /* Free basic block info. */
260 df_ru_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
263 struct df_ru_bb_info *bb_info = (struct df_ru_bb_info *) vbb_info;
266 BITMAP_FREE (bb_info->kill);
267 BITMAP_FREE (bb_info->sparse_kill);
268 BITMAP_FREE (bb_info->gen);
269 BITMAP_FREE (bb_info->in);
270 BITMAP_FREE (bb_info->out);
271 pool_free (df_ru->block_pool, bb_info);
276 /* Allocate or reset bitmaps for DF_RU blocks. The solution bits are
277 not touched unless the block is new. */
280 df_ru_alloc (bitmap all_blocks)
282 unsigned int bb_index;
284 struct df_ru_problem_data *problem_data;
286 if (!df_ru->block_pool)
287 df_ru->block_pool = create_alloc_pool ("df_ru_block pool",
288 sizeof (struct df_ru_bb_info), 50);
290 if (df_ru->problem_data)
292 problem_data = (struct df_ru_problem_data *) df_ru->problem_data;
293 bitmap_clear (problem_data->sparse_invalidated_by_call);
294 bitmap_clear (problem_data->dense_invalidated_by_call);
298 problem_data = XNEW (struct df_ru_problem_data);
299 df_ru->problem_data = problem_data;
301 bitmap_obstack_initialize (&problem_data->ru_bitmaps);
302 problem_data->sparse_invalidated_by_call
303 = BITMAP_ALLOC (&problem_data->ru_bitmaps);
304 problem_data->dense_invalidated_by_call
305 = BITMAP_ALLOC (&problem_data->ru_bitmaps);
308 df_grow_bb_info (df_ru);
310 /* Because of the clustering of all def sites for the same pseudo,
311 we have to process all of the blocks before doing the
314 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
316 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
319 bitmap_clear (bb_info->kill);
320 bitmap_clear (bb_info->sparse_kill);
321 bitmap_clear (bb_info->gen);
325 bb_info = (struct df_ru_bb_info *) pool_alloc (df_ru->block_pool);
326 df_ru_set_bb_info (bb_index, bb_info);
327 bb_info->kill = BITMAP_ALLOC (&problem_data->ru_bitmaps);
328 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->ru_bitmaps);
329 bb_info->gen = BITMAP_ALLOC (&problem_data->ru_bitmaps);
330 bb_info->in = BITMAP_ALLOC (&problem_data->ru_bitmaps);
331 bb_info->out = BITMAP_ALLOC (&problem_data->ru_bitmaps);
334 df_ru->optional_p = true;
338 /* Process a list of DEFs for df_ru_bb_local_compute. */
341 df_ru_bb_local_compute_process_def (struct df_ru_bb_info *bb_info,
342 struct df_ref **def_rec,
343 enum df_ref_flags top_flag)
347 struct df_ref *def = *def_rec;
348 if ((top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
349 /* If the def is to only part of the reg, it is as if it did
350 not happen, since some of the bits may get thru. */
351 && (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))))
353 unsigned int regno = DF_REF_REGNO (def);
354 unsigned int begin = DF_USES_BEGIN (regno);
355 unsigned int n_uses = DF_USES_COUNT (regno);
357 if (!bitmap_bit_p (seen_in_block, regno))
359 /* The first def for regno in the insn, causes the kill
360 info to be generated. Do not modify the gen set
361 because the only values in it are the uses from here
362 to the top of the block and this def does not effect
364 if (!bitmap_bit_p (seen_in_insn, regno))
366 if (n_uses > DF_SPARSE_THRESHOLD)
367 bitmap_set_bit (bb_info->sparse_kill, regno);
369 bitmap_set_range (bb_info->kill, begin, n_uses);
371 bitmap_set_bit (seen_in_insn, regno);
379 /* Process a list of USEs for df_ru_bb_local_compute. */
382 df_ru_bb_local_compute_process_use (struct df_ru_bb_info *bb_info,
383 struct df_ref **use_rec,
384 enum df_ref_flags top_flag)
388 struct df_ref *use = *use_rec;
389 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
391 /* Add use to set of gens in this BB unless we have seen a
392 def in a previous instruction. */
393 unsigned int regno = DF_REF_REGNO (use);
394 if (!bitmap_bit_p (seen_in_block, regno))
395 bitmap_set_bit (bb_info->gen, DF_REF_ID (use));
401 /* Compute local reaching use (upward exposed use) info for basic
402 block BB. USE_INFO->REGS[R] caches the set of uses for register R. */
404 df_ru_bb_local_compute (unsigned int bb_index)
406 basic_block bb = BASIC_BLOCK (bb_index);
407 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
410 /* Set when a def for regno is seen. */
411 bitmap_clear (seen_in_block);
412 bitmap_clear (seen_in_insn);
415 /* Variables defined in the prolog that are used by the exception
417 df_ru_bb_local_compute_process_use (bb_info,
418 df_get_artificial_uses (bb_index),
421 df_ru_bb_local_compute_process_def (bb_info,
422 df_get_artificial_defs (bb_index),
425 FOR_BB_INSNS (bb, insn)
427 unsigned int uid = INSN_UID (insn);
431 df_ru_bb_local_compute_process_use (bb_info,
432 DF_INSN_UID_USES (uid), 0);
434 if (df->changeable_flags & DF_EQ_NOTES)
435 df_ru_bb_local_compute_process_use (bb_info,
436 DF_INSN_UID_EQ_USES (uid), 0);
438 df_ru_bb_local_compute_process_def (bb_info,
439 DF_INSN_UID_DEFS (uid), 0);
441 bitmap_ior_into (seen_in_block, seen_in_insn);
442 bitmap_clear (seen_in_insn);
445 /* Process the hardware registers that are always live. */
446 df_ru_bb_local_compute_process_use (bb_info,
447 df_get_artificial_uses (bb_index), 0);
449 df_ru_bb_local_compute_process_def (bb_info,
450 df_get_artificial_defs (bb_index), 0);
454 /* Compute local reaching use (upward exposed use) info for each basic
455 block within BLOCKS. */
457 df_ru_local_compute (bitmap all_blocks)
459 unsigned int bb_index;
462 struct df_ru_problem_data *problem_data
463 = (struct df_ru_problem_data *) df_ru->problem_data;
464 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
465 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
469 df_maybe_reorganize_use_refs (df->changeable_flags & DF_EQ_NOTES ?
470 DF_REF_ORDER_BY_REG_WITH_NOTES : DF_REF_ORDER_BY_REG);
472 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
474 df_ru_bb_local_compute (bb_index);
477 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
478 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
480 if (DF_USES_COUNT (regno) > DF_SPARSE_THRESHOLD)
481 bitmap_set_bit (sparse_invalidated, regno);
483 bitmap_set_range (dense_invalidated,
484 DF_USES_BEGIN (regno),
485 DF_USES_COUNT (regno));
492 /* Initialize the solution bit vectors for problem. */
495 df_ru_init_solution (bitmap all_blocks)
497 unsigned int bb_index;
500 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
502 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
503 bitmap_copy (bb_info->in, bb_info->gen);
504 bitmap_clear (bb_info->out);
509 /* Out of target gets or of in of source. */
512 df_ru_confluence_n (edge e)
514 bitmap op1 = df_ru_get_bb_info (e->src->index)->out;
515 bitmap op2 = df_ru_get_bb_info (e->dest->index)->in;
517 if (e->flags & EDGE_EH)
519 struct df_ru_problem_data *problem_data
520 = (struct df_ru_problem_data *) df_ru->problem_data;
521 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
522 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
525 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
527 bitmap_copy (tmp, op2);
528 bitmap_and_compl_into (tmp, dense_invalidated);
530 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
532 bitmap_clear_range (tmp,
533 DF_USES_BEGIN (regno),
534 DF_USES_COUNT (regno));
536 bitmap_ior_into (op1, tmp);
540 bitmap_ior_into (op1, op2);
544 /* Transfer function. */
547 df_ru_transfer_function (int bb_index)
549 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
552 bitmap in = bb_info->in;
553 bitmap out = bb_info->out;
554 bitmap gen = bb_info->gen;
555 bitmap kill = bb_info->kill;
556 bitmap sparse_kill = bb_info->sparse_kill;
558 if (bitmap_empty_p (sparse_kill))
559 return bitmap_ior_and_compl (in, gen, out, kill);
562 struct df_ru_problem_data *problem_data;
564 bool changed = false;
566 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
567 IN with TMP. Therefore, allocate TMP in the RU bitmaps obstack. */
568 problem_data = (struct df_ru_problem_data *) df_ru->problem_data;
569 tmp = BITMAP_ALLOC (&problem_data->ru_bitmaps);
571 bitmap_copy (tmp, out);
572 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
574 bitmap_clear_range (tmp,
575 DF_USES_BEGIN (regno),
576 DF_USES_COUNT (regno));
578 bitmap_and_compl_into (tmp, kill);
579 bitmap_ior_into (tmp, gen);
580 changed = !bitmap_equal_p (tmp, in);
593 /* Free all storage associated with the problem. */
599 struct df_ru_problem_data *problem_data
600 = (struct df_ru_problem_data *) df_ru->problem_data;
604 for (i = 0; i < df_ru->block_info_size; i++)
606 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (i);
609 BITMAP_FREE (bb_info->kill);
610 BITMAP_FREE (bb_info->sparse_kill);
611 BITMAP_FREE (bb_info->gen);
612 BITMAP_FREE (bb_info->in);
613 BITMAP_FREE (bb_info->out);
617 free_alloc_pool (df_ru->block_pool);
618 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
619 BITMAP_FREE (problem_data->dense_invalidated_by_call);
620 bitmap_obstack_release (&problem_data->ru_bitmaps);
622 df_ru->block_info_size = 0;
623 free (df_ru->block_info);
624 free (df_ru->problem_data);
630 /* Debugging info. */
633 df_ru_start_dump (FILE *file)
635 struct df_ru_problem_data *problem_data
636 = (struct df_ru_problem_data *) df_ru->problem_data;
637 unsigned int m = DF_REG_SIZE(df);
640 if (!df_ru->block_info)
643 fprintf (file, ";; Reaching uses:\n");
645 fprintf (file, ";; sparse invalidated \t");
646 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
647 fprintf (file, " dense invalidated \t");
648 dump_bitmap (file, problem_data->dense_invalidated_by_call);
650 for (regno = 0; regno < m; regno++)
651 if (DF_USES_COUNT (regno))
652 fprintf (file, "%d[%d,%d] ", regno,
653 DF_USES_BEGIN (regno),
654 DF_USES_COUNT (regno));
655 fprintf (file, "\n");
659 /* Debugging info at top of bb. */
662 df_ru_top_dump (basic_block bb, FILE *file)
664 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb->index);
665 if (!bb_info || !bb_info->in)
668 fprintf (file, ";; ru in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
669 dump_bitmap (file, bb_info->in);
670 fprintf (file, ";; ru gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
671 dump_bitmap (file, bb_info->gen);
672 fprintf (file, ";; ru kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
673 dump_bitmap (file, bb_info->kill);
677 /* Debugging info at bottom of bb. */
680 df_ru_bottom_dump (basic_block bb, FILE *file)
682 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb->index);
683 if (!bb_info || !bb_info->out)
686 fprintf (file, ";; ru out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
687 dump_bitmap (file, bb_info->out);
691 /* All of the information associated with every instance of the problem. */
693 static struct df_problem problem_RU =
695 DF_RU, /* Problem id. */
696 DF_BACKWARD, /* Direction. */
697 df_ru_alloc, /* Allocate the problem specific data. */
698 NULL, /* Reset global information. */
699 df_ru_free_bb_info, /* Free basic block info. */
700 df_ru_local_compute, /* Local compute function. */
701 df_ru_init_solution, /* Init the solution specific data. */
702 df_worklist_dataflow, /* Worklist solver. */
703 NULL, /* Confluence operator 0. */
704 df_ru_confluence_n, /* Confluence operator n. */
705 df_ru_transfer_function, /* Transfer function. */
706 NULL, /* Finalize function. */
707 df_ru_free, /* Free all of the problem information. */
708 df_ru_free, /* Remove this problem from the stack of dataflow problems. */
709 df_ru_start_dump, /* Debugging. */
710 df_ru_top_dump, /* Debugging start block. */
711 df_ru_bottom_dump, /* Debugging end block. */
712 NULL, /* Incremental solution verify start. */
713 NULL, /* Incremental solution verfiy end. */
714 NULL, /* Dependent problem. */
715 TV_DF_RU, /* Timing variable. */
716 true /* Reset blocks on dropping out of blocks_to_analyze. */
721 /* Create a new DATAFLOW instance and add it to an existing instance
722 of DF. The returned structure is what is used to get at the
726 df_ru_add_problem (void)
728 df_add_problem (&problem_RU);
732 /*----------------------------------------------------------------------------
735 Find the locations in the function where each definition site for a
736 pseudo reaches. In and out bitvectors are built for each basic
737 block. The id field in the ref is used to index into these sets.
738 See df.h for details.
739 ----------------------------------------------------------------------------*/
741 /* See the comment at the top of the Reaching Uses problem for how the
742 uses are represented in the kill sets. The same games are played
743 here for the defs. */
745 /* Private data used to compute the solution for this problem. These
746 data structures are not accessible outside of this module. */
747 struct df_rd_problem_data
749 /* The set of defs to regs invalidated by call. */
750 bitmap sparse_invalidated_by_call;
751 /* The set of defs to regs invalidate by call for rd. */
752 bitmap dense_invalidated_by_call;
753 /* An obstack for the bitmaps we need for this problem. */
754 bitmap_obstack rd_bitmaps;
757 /* Set basic block info. */
760 df_rd_set_bb_info (unsigned int index,
761 struct df_rd_bb_info *bb_info)
764 gcc_assert (index < df_rd->block_info_size);
765 df_rd->block_info[index] = bb_info;
769 /* Free basic block info. */
772 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
775 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
778 BITMAP_FREE (bb_info->kill);
779 BITMAP_FREE (bb_info->sparse_kill);
780 BITMAP_FREE (bb_info->gen);
781 BITMAP_FREE (bb_info->in);
782 BITMAP_FREE (bb_info->out);
783 pool_free (df_rd->block_pool, bb_info);
788 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
789 not touched unless the block is new. */
792 df_rd_alloc (bitmap all_blocks)
794 unsigned int bb_index;
796 struct df_rd_problem_data *problem_data;
798 if (!df_rd->block_pool)
799 df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
800 sizeof (struct df_rd_bb_info), 50);
802 if (df_rd->problem_data)
804 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
805 bitmap_clear (problem_data->sparse_invalidated_by_call);
806 bitmap_clear (problem_data->dense_invalidated_by_call);
810 problem_data = XNEW (struct df_rd_problem_data);
811 df_rd->problem_data = problem_data;
813 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
814 problem_data->sparse_invalidated_by_call
815 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
816 problem_data->dense_invalidated_by_call
817 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
820 df_grow_bb_info (df_rd);
822 /* Because of the clustering of all use sites for the same pseudo,
823 we have to process all of the blocks before doing the
826 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
828 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
831 bitmap_clear (bb_info->kill);
832 bitmap_clear (bb_info->sparse_kill);
833 bitmap_clear (bb_info->gen);
837 bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
838 df_rd_set_bb_info (bb_index, bb_info);
839 bb_info->kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
840 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
841 bb_info->gen = BITMAP_ALLOC (&problem_data->rd_bitmaps);
842 bb_info->in = BITMAP_ALLOC (&problem_data->rd_bitmaps);
843 bb_info->out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
846 df_rd->optional_p = true;
850 /* Process a list of DEFs for df_rd_bb_local_compute. */
853 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
854 struct df_ref **def_rec,
855 enum df_ref_flags top_flag)
859 struct df_ref *def = *def_rec;
860 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
862 unsigned int regno = DF_REF_REGNO (def);
863 unsigned int begin = DF_DEFS_BEGIN (regno);
864 unsigned int n_defs = DF_DEFS_COUNT (regno);
866 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
867 || (regno >= FIRST_PSEUDO_REGISTER))
869 /* Only the last def(s) for a regno in the block has any
871 if (!bitmap_bit_p (seen_in_block, regno))
873 /* The first def for regno in insn gets to knock out the
874 defs from other instructions. */
875 if ((!bitmap_bit_p (seen_in_insn, regno))
876 /* If the def is to only part of the reg, it does
877 not kill the other defs that reach here. */
878 && (!(DF_REF_FLAGS (def) &
879 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
881 if (n_defs > DF_SPARSE_THRESHOLD)
883 bitmap_set_bit (bb_info->sparse_kill, regno);
884 bitmap_clear_range(bb_info->gen, begin, n_defs);
888 bitmap_set_range (bb_info->kill, begin, n_defs);
889 bitmap_clear_range (bb_info->gen, begin, n_defs);
893 bitmap_set_bit (seen_in_insn, regno);
894 /* All defs for regno in the instruction may be put into
896 if (!(DF_REF_FLAGS (def)
897 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
898 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
906 /* Compute local reaching def info for basic block BB. */
909 df_rd_bb_local_compute (unsigned int bb_index)
911 basic_block bb = BASIC_BLOCK (bb_index);
912 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
915 bitmap_clear (seen_in_block);
916 bitmap_clear (seen_in_insn);
918 /* Artificials are only hard regs. */
919 if (!(df->changeable_flags & DF_NO_HARD_REGS))
920 df_rd_bb_local_compute_process_def (bb_info,
921 df_get_artificial_defs (bb_index),
924 FOR_BB_INSNS_REVERSE (bb, insn)
926 unsigned int uid = INSN_UID (insn);
931 df_rd_bb_local_compute_process_def (bb_info,
932 DF_INSN_UID_DEFS (uid), 0);
934 /* This complex dance with the two bitmaps is required because
935 instructions can assign twice to the same pseudo. This
936 generally happens with calls that will have one def for the
937 result and another def for the clobber. If only one vector
938 is used and the clobber goes first, the result will be
940 bitmap_ior_into (seen_in_block, seen_in_insn);
941 bitmap_clear (seen_in_insn);
944 /* Process the artificial defs at the top of the block last since we
945 are going backwards through the block and these are logically at
947 if (!(df->changeable_flags & DF_NO_HARD_REGS))
948 df_rd_bb_local_compute_process_def (bb_info,
949 df_get_artificial_defs (bb_index),
954 /* Compute local reaching def info for each basic block within BLOCKS. */
957 df_rd_local_compute (bitmap all_blocks)
959 unsigned int bb_index;
962 struct df_rd_problem_data *problem_data
963 = (struct df_rd_problem_data *) df_rd->problem_data;
964 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
965 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
969 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
971 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
973 df_rd_bb_local_compute (bb_index);
976 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
977 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
979 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
980 bitmap_set_bit (sparse_invalidated, regno);
982 bitmap_set_range (dense_invalidated,
983 DF_DEFS_BEGIN (regno),
984 DF_DEFS_COUNT (regno));
990 /* Initialize the solution bit vectors for problem. */
993 df_rd_init_solution (bitmap all_blocks)
995 unsigned int bb_index;
998 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1000 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
1002 bitmap_copy (bb_info->out, bb_info->gen);
1003 bitmap_clear (bb_info->in);
1007 /* In of target gets or of out of source. */
1010 df_rd_confluence_n (edge e)
1012 bitmap op1 = df_rd_get_bb_info (e->dest->index)->in;
1013 bitmap op2 = df_rd_get_bb_info (e->src->index)->out;
1015 if (e->flags & EDGE_EH)
1017 struct df_rd_problem_data *problem_data
1018 = (struct df_rd_problem_data *) df_rd->problem_data;
1019 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
1020 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
1023 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
1025 bitmap_copy (tmp, op2);
1026 bitmap_and_compl_into (tmp, dense_invalidated);
1028 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
1030 bitmap_clear_range (tmp,
1031 DF_DEFS_BEGIN (regno),
1032 DF_DEFS_COUNT (regno));
1034 bitmap_ior_into (op1, tmp);
1038 bitmap_ior_into (op1, op2);
1042 /* Transfer function. */
1045 df_rd_transfer_function (int bb_index)
1047 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
1050 bitmap in = bb_info->in;
1051 bitmap out = bb_info->out;
1052 bitmap gen = bb_info->gen;
1053 bitmap kill = bb_info->kill;
1054 bitmap sparse_kill = bb_info->sparse_kill;
1056 if (bitmap_empty_p (sparse_kill))
1057 return bitmap_ior_and_compl (out, gen, in, kill);
1060 struct df_rd_problem_data *problem_data;
1061 bool changed = false;
1064 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
1065 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
1066 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
1067 tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
1069 bitmap_copy (tmp, in);
1070 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
1072 bitmap_clear_range (tmp,
1073 DF_DEFS_BEGIN (regno),
1074 DF_DEFS_COUNT (regno));
1076 bitmap_and_compl_into (tmp, kill);
1077 bitmap_ior_into (tmp, gen);
1078 changed = !bitmap_equal_p (tmp, out);
1091 /* Free all storage associated with the problem. */
1097 struct df_rd_problem_data *problem_data
1098 = (struct df_rd_problem_data *) df_rd->problem_data;
1102 for (i = 0; i < df_rd->block_info_size; i++)
1104 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (i);
1107 BITMAP_FREE (bb_info->kill);
1108 BITMAP_FREE (bb_info->sparse_kill);
1109 BITMAP_FREE (bb_info->gen);
1110 BITMAP_FREE (bb_info->in);
1111 BITMAP_FREE (bb_info->out);
1115 free_alloc_pool (df_rd->block_pool);
1116 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
1117 BITMAP_FREE (problem_data->dense_invalidated_by_call);
1118 bitmap_obstack_release (&problem_data->rd_bitmaps);
1120 df_rd->block_info_size = 0;
1121 free (df_rd->block_info);
1122 free (df_rd->problem_data);
1128 /* Debugging info. */
1131 df_rd_start_dump (FILE *file)
1133 struct df_rd_problem_data *problem_data
1134 = (struct df_rd_problem_data *) df_rd->problem_data;
1135 unsigned int m = DF_REG_SIZE(df);
1138 if (!df_rd->block_info)
1141 fprintf (file, ";; Reaching defs:\n\n");
1143 fprintf (file, " sparse invalidated \t");
1144 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
1145 fprintf (file, " dense invalidated \t");
1146 dump_bitmap (file, problem_data->dense_invalidated_by_call);
1148 for (regno = 0; regno < m; regno++)
1149 if (DF_DEFS_COUNT (regno))
1150 fprintf (file, "%d[%d,%d] ", regno,
1151 DF_DEFS_BEGIN (regno),
1152 DF_DEFS_COUNT (regno));
1153 fprintf (file, "\n");
1158 /* Debugging info at top of bb. */
1161 df_rd_top_dump (basic_block bb, FILE *file)
1163 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
1164 if (!bb_info || !bb_info->in)
1167 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
1168 dump_bitmap (file, bb_info->in);
1169 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
1170 dump_bitmap (file, bb_info->gen);
1171 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
1172 dump_bitmap (file, bb_info->kill);
1176 /* Debugging info at top of bb. */
1179 df_rd_bottom_dump (basic_block bb, FILE *file)
1181 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
1182 if (!bb_info || !bb_info->out)
1185 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
1186 dump_bitmap (file, bb_info->out);
1189 /* All of the information associated with every instance of the problem. */
1191 static struct df_problem problem_RD =
1193 DF_RD, /* Problem id. */
1194 DF_FORWARD, /* Direction. */
1195 df_rd_alloc, /* Allocate the problem specific data. */
1196 NULL, /* Reset global information. */
1197 df_rd_free_bb_info, /* Free basic block info. */
1198 df_rd_local_compute, /* Local compute function. */
1199 df_rd_init_solution, /* Init the solution specific data. */
1200 df_worklist_dataflow, /* Worklist solver. */
1201 NULL, /* Confluence operator 0. */
1202 df_rd_confluence_n, /* Confluence operator n. */
1203 df_rd_transfer_function, /* Transfer function. */
1204 NULL, /* Finalize function. */
1205 df_rd_free, /* Free all of the problem information. */
1206 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
1207 df_rd_start_dump, /* Debugging. */
1208 df_rd_top_dump, /* Debugging start block. */
1209 df_rd_bottom_dump, /* Debugging end block. */
1210 NULL, /* Incremental solution verify start. */
1211 NULL, /* Incremental solution verfiy end. */
1212 NULL, /* Dependent problem. */
1213 TV_DF_RD, /* Timing variable. */
1214 true /* Reset blocks on dropping out of blocks_to_analyze. */
1219 /* Create a new DATAFLOW instance and add it to an existing instance
1220 of DF. The returned structure is what is used to get at the
1224 df_rd_add_problem (void)
1226 df_add_problem (&problem_RD);
1231 /*----------------------------------------------------------------------------
1234 Find the locations in the function where any use of a pseudo can
1235 reach in the backwards direction. In and out bitvectors are built
1236 for each basic block. The regnum is used to index into these sets.
1237 See df.h for details.
1238 ----------------------------------------------------------------------------*/
1240 /* Private data used to verify the solution for this problem. */
1241 struct df_lr_problem_data
1248 /* Set basic block info. */
1251 df_lr_set_bb_info (unsigned int index,
1252 struct df_lr_bb_info *bb_info)
1255 gcc_assert (index < df_lr->block_info_size);
1256 df_lr->block_info[index] = bb_info;
1260 /* Free basic block info. */
1263 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1266 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
1269 BITMAP_FREE (bb_info->use);
1270 BITMAP_FREE (bb_info->def);
1271 if (bb_info->in == bb_info->top)
1272 bb_info->top = NULL;
1275 BITMAP_FREE (bb_info->top);
1276 BITMAP_FREE (bb_info->ause);
1277 BITMAP_FREE (bb_info->adef);
1279 BITMAP_FREE (bb_info->in);
1280 BITMAP_FREE (bb_info->out);
1281 pool_free (df_lr->block_pool, bb_info);
1286 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
1287 not touched unless the block is new. */
1290 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1292 unsigned int bb_index;
1295 if (!df_lr->block_pool)
1296 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
1297 sizeof (struct df_lr_bb_info), 50);
1299 df_grow_bb_info (df_lr);
1301 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
1303 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1306 bitmap_clear (bb_info->def);
1307 bitmap_clear (bb_info->use);
1310 bitmap_clear (bb_info->adef);
1311 bitmap_clear (bb_info->ause);
1316 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
1317 df_lr_set_bb_info (bb_index, bb_info);
1318 bb_info->use = BITMAP_ALLOC (NULL);
1319 bb_info->def = BITMAP_ALLOC (NULL);
1320 bb_info->in = BITMAP_ALLOC (NULL);
1321 bb_info->out = BITMAP_ALLOC (NULL);
1322 bb_info->top = bb_info->in;
1323 bb_info->adef = NULL;
1324 bb_info->ause = NULL;
1328 df_lr->optional_p = false;
1332 /* Reset the global solution for recalculation. */
1335 df_lr_reset (bitmap all_blocks)
1337 unsigned int bb_index;
1340 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1342 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1343 gcc_assert (bb_info);
1344 bitmap_clear (bb_info->in);
1345 bitmap_clear (bb_info->out);
1346 bitmap_clear (bb_info->top);
1351 /* Compute local live register info for basic block BB. */
1354 df_lr_bb_local_compute (unsigned int bb_index)
1356 basic_block bb = BASIC_BLOCK (bb_index);
1357 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1359 struct df_ref **def_rec;
1360 struct df_ref **use_rec;
1362 /* Process the registers set in an exception handler. */
1363 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1365 struct df_ref *def = *def_rec;
1366 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
1368 unsigned int dregno = DF_REF_REGNO (def);
1369 bitmap_set_bit (bb_info->def, dregno);
1370 bitmap_clear_bit (bb_info->use, dregno);
1374 /* Process the hardware registers that are always live. */
1375 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
1377 struct df_ref *use = *use_rec;
1378 /* Add use to set of uses in this BB. */
1379 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
1380 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1383 FOR_BB_INSNS_REVERSE (bb, insn)
1385 unsigned int uid = INSN_UID (insn);
1392 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1394 struct df_ref *def = *def_rec;
1395 unsigned int dregno = DF_REF_REGNO (def);
1397 if (DF_REF_FLAGS (def) & DF_REF_MUST_CLOBBER)
1399 if (dregno >= FIRST_PSEUDO_REGISTER
1400 || !(SIBLING_CALL_P (insn)
1401 && bitmap_bit_p (df->exit_block_uses, dregno)
1402 && !refers_to_regno_p (dregno, dregno+1,
1403 current_function_return_rtx,
1406 /* If the def is to only part of the reg, it does
1407 not kill the other defs that reach here. */
1408 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
1410 bitmap_set_bit (bb_info->def, dregno);
1411 bitmap_clear_bit (bb_info->use, dregno);
1416 /* This is the return value. */
1417 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
1419 bitmap_set_bit (bb_info->def, dregno);
1420 bitmap_clear_bit (bb_info->use, dregno);
1426 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1428 struct df_ref *def = *def_rec;
1429 /* If the def is to only part of the reg, it does
1430 not kill the other defs that reach here. */
1431 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
1433 unsigned int dregno = DF_REF_REGNO (def);
1434 bitmap_set_bit (bb_info->def, dregno);
1435 bitmap_clear_bit (bb_info->use, dregno);
1440 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1442 struct df_ref *use = *use_rec;
1443 /* Add use to set of uses in this BB. */
1444 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1447 /* Process the registers set in an exception handler. */
1448 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1450 struct df_ref *def = *def_rec;
1451 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP)
1452 && (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))))
1454 unsigned int dregno = DF_REF_REGNO (def);
1455 if (bb_info->adef == NULL)
1457 gcc_assert (bb_info->ause == NULL);
1458 gcc_assert (bb_info->top == bb_info->in);
1459 bb_info->adef = BITMAP_ALLOC (NULL);
1460 bb_info->ause = BITMAP_ALLOC (NULL);
1461 bb_info->top = BITMAP_ALLOC (NULL);
1463 bitmap_set_bit (bb_info->adef, dregno);
1468 /* Process the uses that are live into an exception handler. */
1469 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
1471 struct df_ref *use = *use_rec;
1472 /* Add use to set of uses in this BB. */
1473 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
1475 if (bb_info->adef == NULL)
1477 gcc_assert (bb_info->ause == NULL);
1478 gcc_assert (bb_info->top == bb_info->in);
1479 bb_info->adef = BITMAP_ALLOC (NULL);
1480 bb_info->ause = BITMAP_ALLOC (NULL);
1481 bb_info->top = BITMAP_ALLOC (NULL);
1483 bitmap_set_bit (bb_info->ause, DF_REF_REGNO (use));
1488 /* If the df_live problem is not defined, such as at -O0 and -O1, we
1489 still need to keep the luids up to date. This is normally done
1490 in the df_live problem since this problem has a forwards
1493 df_recompute_luids (bb);
1497 /* Compute local live register info for each basic block within BLOCKS. */
1500 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1502 unsigned int bb_index;
1505 bitmap_clear (df->hardware_regs_used);
1507 /* The all-important stack pointer must always be live. */
1508 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
1510 /* Before reload, there are a few registers that must be forced
1511 live everywhere -- which might not already be the case for
1512 blocks within infinite loops. */
1513 if (!reload_completed)
1515 /* Any reference to any pseudo before reload is a potential
1516 reference of the frame pointer. */
1517 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
1519 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1520 /* Pseudos with argument area equivalences may require
1521 reloading via the argument pointer. */
1522 if (fixed_regs[ARG_POINTER_REGNUM])
1523 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
1526 /* Any constant, or pseudo with constant equivalences, may
1527 require reloading from memory using the pic register. */
1528 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
1529 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
1530 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
1533 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
1535 if (bb_index == EXIT_BLOCK)
1537 /* The exit block is special for this problem and its bits are
1538 computed from thin air. */
1539 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
1540 bitmap_copy (bb_info->use, df->exit_block_uses);
1543 df_lr_bb_local_compute (bb_index);
1546 bitmap_clear (df_lr->out_of_date_transfer_functions);
1550 /* Initialize the solution vectors. */
1553 df_lr_init (bitmap all_blocks)
1555 unsigned int bb_index;
1558 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1560 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1561 bitmap_copy (bb_info->in, bb_info->use);
1562 bitmap_clear (bb_info->out);
1567 /* Confluence function that processes infinite loops. This might be a
1568 noreturn function that throws. And even if it isn't, getting the
1569 unwind info right helps debugging. */
1571 df_lr_confluence_0 (basic_block bb)
1573 bitmap op1 = df_lr_get_bb_info (bb->index)->out;
1574 if (bb != EXIT_BLOCK_PTR)
1575 bitmap_copy (op1, df->hardware_regs_used);
1579 /* Confluence function that ignores fake edges. */
1582 df_lr_confluence_n (edge e)
1584 bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
1585 bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
1587 /* Call-clobbered registers die across exception and call edges. */
1588 /* ??? Abnormal call edges ignored for the moment, as this gets
1589 confused by sibling call edges, which crashes reg-stack. */
1590 if (e->flags & EDGE_EH)
1591 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
1593 bitmap_ior_into (op1, op2);
1595 bitmap_ior_into (op1, df->hardware_regs_used);
1599 /* Transfer function. */
1602 df_lr_transfer_function (int bb_index)
1604 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1605 bitmap in = bb_info->in;
1606 bitmap out = bb_info->out;
1607 bitmap use = bb_info->use;
1608 bitmap def = bb_info->def;
1609 bitmap top = bb_info->top;
1610 bitmap ause = bb_info->ause;
1611 bitmap adef = bb_info->adef;
1614 changed = bitmap_ior_and_compl (top, use, out, def);
1617 gcc_assert (ause && adef);
1618 changed |= bitmap_ior_and_compl (in, ause, top, adef);
1625 /* Run the fast dce as a side effect of building LR. */
1628 df_lr_local_finalize (bitmap all_blocks ATTRIBUTE_UNUSED)
1630 if (df->changeable_flags & DF_LR_RUN_DCE)
1633 if (df_lr->problem_data && df_lr->solutions_dirty)
1635 /* If we are here, then it is because we are both verifying
1636 the solution and the dce changed the function. In that case
1637 the verification info built will be wrong. So we leave the
1638 dirty flag true so that the verifier will skip the checking
1639 part and just clean up.*/
1640 df_lr->solutions_dirty = true;
1643 df_lr->solutions_dirty = false;
1646 df_lr->solutions_dirty = false;
1650 /* Free all storage associated with the problem. */
1655 if (df_lr->block_info)
1658 for (i = 0; i < df_lr->block_info_size; i++)
1660 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
1663 BITMAP_FREE (bb_info->use);
1664 BITMAP_FREE (bb_info->def);
1665 if (bb_info->in == bb_info->top)
1666 bb_info->top = NULL;
1669 BITMAP_FREE (bb_info->top);
1670 BITMAP_FREE (bb_info->ause);
1671 BITMAP_FREE (bb_info->adef);
1673 BITMAP_FREE (bb_info->in);
1674 BITMAP_FREE (bb_info->out);
1677 free_alloc_pool (df_lr->block_pool);
1679 df_lr->block_info_size = 0;
1680 free (df_lr->block_info);
1683 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1688 /* Debugging info at top of bb. */
1691 df_lr_top_dump (basic_block bb, FILE *file)
1693 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1694 struct df_lr_problem_data *problem_data;
1695 if (!bb_info || !bb_info->in)
1698 fprintf (file, ";; lr in \t");
1699 df_print_regset (file, bb_info->in);
1700 if (df_lr->problem_data)
1702 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1703 fprintf (file, ";; old in \t");
1704 df_print_regset (file, problem_data->in[bb->index]);
1706 fprintf (file, ";; lr use \t");
1707 df_print_regset (file, bb_info->use);
1708 fprintf (file, ";; lr def \t");
1709 df_print_regset (file, bb_info->def);
1713 /* Debugging info at bottom of bb. */
1716 df_lr_bottom_dump (basic_block bb, FILE *file)
1718 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1719 struct df_lr_problem_data *problem_data;
1720 if (!bb_info || !bb_info->out)
1723 fprintf (file, ";; lr out \t");
1724 df_print_regset (file, bb_info->out);
1725 if (df_lr->problem_data)
1727 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1728 fprintf (file, ";; old out \t");
1729 df_print_regset (file, problem_data->out[bb->index]);
1734 /* Build the datastructure to verify that the solution to the dataflow
1735 equations is not dirty. */
1738 df_lr_verify_solution_start (void)
1741 struct df_lr_problem_data *problem_data;
1742 if (df_lr->solutions_dirty)
1744 df_lr->problem_data = NULL;
1748 /* Set it true so that the solution is recomputed. */
1749 df_lr->solutions_dirty = true;
1751 problem_data = XNEW (struct df_lr_problem_data);
1752 df_lr->problem_data = problem_data;
1753 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1754 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1758 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1759 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1760 bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
1761 bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
1766 /* Compare the saved datastructure and the new solution to the dataflow
1770 df_lr_verify_solution_end (void)
1772 struct df_lr_problem_data *problem_data;
1775 if (df_lr->problem_data == NULL)
1778 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1780 if (df_lr->solutions_dirty)
1781 /* Do not check if the solution is still dirty. See the comment
1782 in df_lr_local_finalize for details. */
1783 df_lr->solutions_dirty = false;
1787 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
1788 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
1790 /*df_dump (stderr);*/
1795 /* Cannot delete them immediately because you may want to dump them
1796 if the comparison fails. */
1799 BITMAP_FREE (problem_data->in[bb->index]);
1800 BITMAP_FREE (problem_data->out[bb->index]);
1803 free (problem_data->in);
1804 free (problem_data->out);
1805 free (problem_data);
1806 df_lr->problem_data = NULL;
1810 /* All of the information associated with every instance of the problem. */
1812 static struct df_problem problem_LR =
1814 DF_LR, /* Problem id. */
1815 DF_BACKWARD, /* Direction. */
1816 df_lr_alloc, /* Allocate the problem specific data. */
1817 df_lr_reset, /* Reset global information. */
1818 df_lr_free_bb_info, /* Free basic block info. */
1819 df_lr_local_compute, /* Local compute function. */
1820 df_lr_init, /* Init the solution specific data. */
1821 df_worklist_dataflow, /* Worklist solver. */
1822 df_lr_confluence_0, /* Confluence operator 0. */
1823 df_lr_confluence_n, /* Confluence operator n. */
1824 df_lr_transfer_function, /* Transfer function. */
1825 df_lr_local_finalize, /* Finalize function. */
1826 df_lr_free, /* Free all of the problem information. */
1827 NULL, /* Remove this problem from the stack of dataflow problems. */
1828 NULL, /* Debugging. */
1829 df_lr_top_dump, /* Debugging start block. */
1830 df_lr_bottom_dump, /* Debugging end block. */
1831 df_lr_verify_solution_start,/* Incremental solution verify start. */
1832 df_lr_verify_solution_end, /* Incremental solution verify end. */
1833 NULL, /* Dependent problem. */
1834 TV_DF_LR, /* Timing variable. */
1835 false /* Reset blocks on dropping out of blocks_to_analyze. */
1839 /* Create a new DATAFLOW instance and add it to an existing instance
1840 of DF. The returned structure is what is used to get at the
1844 df_lr_add_problem (void)
1846 df_add_problem (&problem_LR);
1847 /* These will be initialized when df_scan_blocks processes each
1849 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1853 /* Verify that all of the lr related info is consistent and
1857 df_lr_verify_transfer_functions (void)
1870 saved_def = BITMAP_ALLOC (NULL);
1871 saved_use = BITMAP_ALLOC (NULL);
1872 saved_adef = BITMAP_ALLOC (NULL);
1873 saved_ause = BITMAP_ALLOC (NULL);
1874 all_blocks = BITMAP_ALLOC (NULL);
1878 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1879 bitmap_set_bit (all_blocks, bb->index);
1883 /* Make a copy of the transfer functions and then compute
1884 new ones to see if the transfer functions have
1886 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1889 bitmap_copy (saved_def, bb_info->def);
1890 bitmap_copy (saved_use, bb_info->use);
1891 bitmap_clear (bb_info->def);
1892 bitmap_clear (bb_info->use);
1897 bitmap_copy (saved_adef, bb_info->adef);
1898 bitmap_copy (saved_ause, bb_info->ause);
1899 bitmap_clear (bb_info->adef);
1900 bitmap_clear (bb_info->ause);
1905 df_lr_bb_local_compute (bb->index);
1906 gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
1907 gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
1911 gcc_assert (bb_info->adef);
1912 gcc_assert (bb_info->ause);
1913 gcc_assert (bitmap_equal_p (saved_adef, bb_info->adef));
1914 gcc_assert (bitmap_equal_p (saved_ause, bb_info->ause));
1918 gcc_assert (!bb_info->adef);
1919 gcc_assert (!bb_info->ause);
1925 /* If we do not have basic block info, the block must be in
1926 the list of dirty blocks or else some one has added a
1927 block behind our backs. */
1928 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1931 /* Make sure no one created a block without following
1933 gcc_assert (df_scan_get_bb_info (bb->index));
1936 /* Make sure there are no dirty bits in blocks that have been deleted. */
1937 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1940 BITMAP_FREE (saved_def);
1941 BITMAP_FREE (saved_use);
1942 BITMAP_FREE (saved_adef);
1943 BITMAP_FREE (saved_ause);
1944 BITMAP_FREE (all_blocks);
1949 /*----------------------------------------------------------------------------
1950 COMBINED LIVE REGISTERS AND UNINITIALIZED REGISTERS.
1952 First find the set of uses for registers that are reachable from
1953 the entry block without passing thru a definition. In and out
1954 bitvectors are built for each basic block. The regnum is used to
1955 index into these sets. See df.h for details.
1957 Then the in and out sets here are the anded results of the in and
1958 out sets from the lr and ur
1960 ----------------------------------------------------------------------------*/
1962 /* Private data used to verify the solution for this problem. */
1963 struct df_live_problem_data
1970 /* Set basic block info. */
1973 df_live_set_bb_info (unsigned int index,
1974 struct df_live_bb_info *bb_info)
1976 gcc_assert (df_live);
1977 gcc_assert (index < df_live->block_info_size);
1978 df_live->block_info[index] = bb_info;
1982 /* Free basic block info. */
1985 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1988 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1991 BITMAP_FREE (bb_info->gen);
1992 BITMAP_FREE (bb_info->kill);
1993 BITMAP_FREE (bb_info->in);
1994 BITMAP_FREE (bb_info->out);
1995 pool_free (df_live->block_pool, bb_info);
2000 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
2001 not touched unless the block is new. */
2004 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2006 unsigned int bb_index;
2009 if (!df_live->block_pool)
2010 df_live->block_pool = create_alloc_pool ("df_live_block pool",
2011 sizeof (struct df_live_bb_info), 100);
2013 df_grow_bb_info (df_live);
2015 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
2017 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
2020 bitmap_clear (bb_info->kill);
2021 bitmap_clear (bb_info->gen);
2025 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
2026 df_live_set_bb_info (bb_index, bb_info);
2027 bb_info->kill = BITMAP_ALLOC (NULL);
2028 bb_info->gen = BITMAP_ALLOC (NULL);
2029 bb_info->in = BITMAP_ALLOC (NULL);
2030 bb_info->out = BITMAP_ALLOC (NULL);
2033 df_live->optional_p = (optimize <= 1);
2037 /* Reset the global solution for recalculation. */
2040 df_live_reset (bitmap all_blocks)
2042 unsigned int bb_index;
2045 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2047 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
2048 gcc_assert (bb_info);
2049 bitmap_clear (bb_info->in);
2050 bitmap_clear (bb_info->out);
2055 /* Compute local uninitialized register info for basic block BB. */
2058 df_live_bb_local_compute (unsigned int bb_index)
2060 basic_block bb = BASIC_BLOCK (bb_index);
2061 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
2063 struct df_ref **def_rec;
2066 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2068 struct df_ref *def = *def_rec;
2069 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2070 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
2073 FOR_BB_INSNS (bb, insn)
2075 unsigned int uid = INSN_UID (insn);
2076 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
2078 /* Inserting labels does not always trigger the incremental
2082 gcc_assert (!INSN_P (insn));
2083 df_insn_create_insn_record (insn);
2086 DF_INSN_LUID (insn) = luid;
2091 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2093 struct df_ref *def = *def_rec;
2094 unsigned int regno = DF_REF_REGNO (def);
2096 if (DF_REF_FLAGS_IS_SET (def,
2097 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2098 /* All partial or conditional def
2099 seen are included in the gen set. */
2100 bitmap_set_bit (bb_info->gen, regno);
2101 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
2102 /* Only must clobbers for the entire reg destroy the
2104 bitmap_set_bit (bb_info->kill, regno);
2105 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
2106 bitmap_set_bit (bb_info->gen, regno);
2110 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2112 struct df_ref *def = *def_rec;
2113 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2114 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
2119 /* Compute local uninitialized register info. */
2122 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2124 unsigned int bb_index;
2127 df_grow_insn_info ();
2129 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
2132 df_live_bb_local_compute (bb_index);
2135 bitmap_clear (df_live->out_of_date_transfer_functions);
2139 /* Initialize the solution vectors. */
2142 df_live_init (bitmap all_blocks)
2144 unsigned int bb_index;
2147 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2149 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
2151 bitmap_copy (bb_info->out, bb_info->gen);
2152 bitmap_clear (bb_info->in);
2156 /* Confluence function that ignores fake edges. */
2159 df_live_confluence_n (edge e)
2161 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
2162 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
2164 if (e->flags & EDGE_FAKE)
2167 bitmap_ior_into (op1, op2);
2171 /* Transfer function. */
2174 df_live_transfer_function (int bb_index)
2176 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
2177 bitmap in = bb_info->in;
2178 bitmap out = bb_info->out;
2179 bitmap gen = bb_info->gen;
2180 bitmap kill = bb_info->kill;
2182 return bitmap_ior_and_compl (out, gen, in, kill);
2186 /* And the LR and UR info to produce the LIVE info. */
2189 df_live_local_finalize (bitmap all_blocks)
2192 if (df_live->solutions_dirty)
2195 unsigned int bb_index;
2197 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2199 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
2200 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
2202 /* No register may reach a location where it is not used. Thus
2203 we trim the rr result to the places where it is used. */
2204 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
2205 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
2208 df_live->solutions_dirty = false;
2213 /* Free all storage associated with the problem. */
2218 if (df_live->block_info)
2222 for (i = 0; i < df_live->block_info_size; i++)
2224 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
2227 BITMAP_FREE (bb_info->gen);
2228 BITMAP_FREE (bb_info->kill);
2229 BITMAP_FREE (bb_info->in);
2230 BITMAP_FREE (bb_info->out);
2234 free_alloc_pool (df_live->block_pool);
2235 df_live->block_info_size = 0;
2236 free (df_live->block_info);
2238 BITMAP_FREE (df_live->out_of_date_transfer_functions);
2243 /* Debugging info at top of bb. */
2246 df_live_top_dump (basic_block bb, FILE *file)
2248 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
2249 struct df_live_problem_data *problem_data;
2251 if (!bb_info || !bb_info->in)
2254 fprintf (file, ";; live in \t");
2255 df_print_regset (file, bb_info->in);
2256 if (df_live->problem_data)
2258 problem_data = (struct df_live_problem_data *)df_live->problem_data;
2259 fprintf (file, ";; old in \t");
2260 df_print_regset (file, problem_data->in[bb->index]);
2262 fprintf (file, ";; live gen \t");
2263 df_print_regset (file, bb_info->gen);
2264 fprintf (file, ";; live kill\t");
2265 df_print_regset (file, bb_info->kill);
2269 /* Debugging info at bottom of bb. */
2272 df_live_bottom_dump (basic_block bb, FILE *file)
2274 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
2275 struct df_live_problem_data *problem_data;
2277 if (!bb_info || !bb_info->out)
2280 fprintf (file, ";; live out \t");
2281 df_print_regset (file, bb_info->out);
2282 if (df_live->problem_data)
2284 problem_data = (struct df_live_problem_data *)df_live->problem_data;
2285 fprintf (file, ";; old out \t");
2286 df_print_regset (file, problem_data->out[bb->index]);
2291 /* Build the datastructure to verify that the solution to the dataflow
2292 equations is not dirty. */
2295 df_live_verify_solution_start (void)
2298 struct df_live_problem_data *problem_data;
2299 if (df_live->solutions_dirty)
2301 df_live->problem_data = NULL;
2305 /* Set it true so that the solution is recomputed. */
2306 df_live->solutions_dirty = true;
2308 problem_data = XNEW (struct df_live_problem_data);
2309 df_live->problem_data = problem_data;
2310 problem_data->in = XNEWVEC (bitmap, last_basic_block);
2311 problem_data->out = XNEWVEC (bitmap, last_basic_block);
2315 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
2316 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
2317 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
2318 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
2323 /* Compare the saved datastructure and the new solution to the dataflow
2327 df_live_verify_solution_end (void)
2329 struct df_live_problem_data *problem_data;
2332 if (df_live->problem_data == NULL)
2335 problem_data = (struct df_live_problem_data *)df_live->problem_data;
2339 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
2340 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
2342 /*df_dump (stderr);*/
2347 /* Cannot delete them immediately because you may want to dump them
2348 if the comparison fails. */
2351 BITMAP_FREE (problem_data->in[bb->index]);
2352 BITMAP_FREE (problem_data->out[bb->index]);
2355 free (problem_data->in);
2356 free (problem_data->out);
2357 free (problem_data);
2358 df_live->problem_data = NULL;
2362 /* All of the information associated with every instance of the problem. */
2364 static struct df_problem problem_LIVE =
2366 DF_LIVE, /* Problem id. */
2367 DF_FORWARD, /* Direction. */
2368 df_live_alloc, /* Allocate the problem specific data. */
2369 df_live_reset, /* Reset global information. */
2370 df_live_free_bb_info, /* Free basic block info. */
2371 df_live_local_compute, /* Local compute function. */
2372 df_live_init, /* Init the solution specific data. */
2373 df_worklist_dataflow, /* Worklist solver. */
2374 NULL, /* Confluence operator 0. */
2375 df_live_confluence_n, /* Confluence operator n. */
2376 df_live_transfer_function, /* Transfer function. */
2377 df_live_local_finalize, /* Finalize function. */
2378 df_live_free, /* Free all of the problem information. */
2379 df_live_free, /* Remove this problem from the stack of dataflow problems. */
2380 NULL, /* Debugging. */
2381 df_live_top_dump, /* Debugging start block. */
2382 df_live_bottom_dump, /* Debugging end block. */
2383 df_live_verify_solution_start,/* Incremental solution verify start. */
2384 df_live_verify_solution_end, /* Incremental solution verify end. */
2385 &problem_LR, /* Dependent problem. */
2386 TV_DF_LIVE, /* Timing variable. */
2387 false /* Reset blocks on dropping out of blocks_to_analyze. */
2391 /* Create a new DATAFLOW instance and add it to an existing instance
2392 of DF. The returned structure is what is used to get at the
2396 df_live_add_problem (void)
2398 df_add_problem (&problem_LIVE);
2399 /* These will be initialized when df_scan_blocks processes each
2401 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2405 /* Set all of the blocks as dirty. This needs to be done if this
2406 problem is added after all of the insns have been scanned. */
2409 df_live_set_all_dirty (void)
2413 bitmap_set_bit (df_live->out_of_date_transfer_functions,
2418 /* Verify that all of the lr related info is consistent and
2422 df_live_verify_transfer_functions (void)
2432 saved_gen = BITMAP_ALLOC (NULL);
2433 saved_kill = BITMAP_ALLOC (NULL);
2434 all_blocks = BITMAP_ALLOC (NULL);
2436 df_grow_insn_info ();
2440 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
2441 bitmap_set_bit (all_blocks, bb->index);
2445 /* Make a copy of the transfer functions and then compute
2446 new ones to see if the transfer functions have
2448 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
2451 bitmap_copy (saved_gen, bb_info->gen);
2452 bitmap_copy (saved_kill, bb_info->kill);
2453 bitmap_clear (bb_info->gen);
2454 bitmap_clear (bb_info->kill);
2456 df_live_bb_local_compute (bb->index);
2457 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
2458 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
2463 /* If we do not have basic block info, the block must be in
2464 the list of dirty blocks or else some one has added a
2465 block behind our backs. */
2466 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
2469 /* Make sure no one created a block without following
2471 gcc_assert (df_scan_get_bb_info (bb->index));
2474 /* Make sure there are no dirty bits in blocks that have been deleted. */
2475 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
2477 BITMAP_FREE (saved_gen);
2478 BITMAP_FREE (saved_kill);
2479 BITMAP_FREE (all_blocks);
2484 /*----------------------------------------------------------------------------
2485 UNINITIALIZED REGISTERS WITH EARLYCLOBBER
2487 Find the set of uses for registers that are reachable from the entry
2488 block without passing thru a definition. In and out bitvectors are built
2489 for each basic block. The regnum is used to index into these sets.
2490 See df.h for details.
2492 This is a variant of the UR problem above that has a lot of special
2493 features just for the register allocation phase. This problem
2494 should go away if someone would fix the interference graph.
2496 ----------------------------------------------------------------------------*/
2498 /* Private data used to compute the solution for this problem. These
2499 data structures are not accessible outside of this module. */
2500 struct df_urec_problem_data
2502 bool earlyclobbers_found; /* True if any instruction contains an
2505 bitmap stack_regs; /* Registers that may be allocated to a STACK_REGS. */
2510 /* Set basic block info. */
2513 df_urec_set_bb_info (unsigned int index,
2514 struct df_urec_bb_info *bb_info)
2516 gcc_assert (df_urec);
2517 gcc_assert (index < df_urec->block_info_size);
2518 df_urec->block_info[index] = bb_info;
2522 /* Free basic block info. */
2525 df_urec_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2528 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info *) vbb_info;
2531 BITMAP_FREE (bb_info->gen);
2532 BITMAP_FREE (bb_info->kill);
2533 BITMAP_FREE (bb_info->in);
2534 BITMAP_FREE (bb_info->out);
2535 BITMAP_FREE (bb_info->earlyclobber);
2536 pool_free (df_urec->block_pool, bb_info);
2541 /* Allocate or reset bitmaps for DF_UREC blocks. The solution bits are
2542 not touched unless the block is new. */
2545 df_urec_alloc (bitmap all_blocks)
2548 unsigned int bb_index;
2550 struct df_urec_problem_data *problem_data
2551 = (struct df_urec_problem_data *) df_urec->problem_data;
2553 if (!df_urec->block_pool)
2554 df_urec->block_pool = create_alloc_pool ("df_urec_block pool",
2555 sizeof (struct df_urec_bb_info), 50);
2557 if (!df_urec->problem_data)
2559 problem_data = XNEW (struct df_urec_problem_data);
2560 df_urec->problem_data = problem_data;
2562 problem_data->earlyclobbers_found = false;
2564 df_grow_bb_info (df_urec);
2566 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2568 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
2571 bitmap_clear (bb_info->kill);
2572 bitmap_clear (bb_info->gen);
2573 bitmap_clear (bb_info->earlyclobber);
2577 bb_info = (struct df_urec_bb_info *) pool_alloc (df_urec->block_pool);
2578 df_urec_set_bb_info (bb_index, bb_info);
2579 bb_info->kill = BITMAP_ALLOC (NULL);
2580 bb_info->gen = BITMAP_ALLOC (NULL);
2581 bb_info->in = BITMAP_ALLOC (NULL);
2582 bb_info->out = BITMAP_ALLOC (NULL);
2583 bb_info->top = BITMAP_ALLOC (NULL);
2584 bb_info->earlyclobber = BITMAP_ALLOC (NULL);
2587 df_urec->optional_p = true;
2591 /* The function modifies local info for register REG being changed in
2592 SETTER. DATA is used to pass the current basic block info. */
2595 df_urec_mark_reg_change (rtx reg, rtx setter, void *data)
2600 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2602 if (GET_CODE (reg) == SUBREG)
2603 reg = SUBREG_REG (reg);
2608 regno = REGNO (reg);
2609 if (regno < FIRST_PSEUDO_REGISTER)
2611 endregno = END_HARD_REGNO (reg);
2612 for (i = regno; i < endregno; i++)
2614 bitmap_set_bit (bb_info->kill, i);
2616 if (GET_CODE (setter) != CLOBBER)
2617 bitmap_set_bit (bb_info->gen, i);
2619 bitmap_clear_bit (bb_info->gen, i);
2624 bitmap_set_bit (bb_info->kill, regno);
2626 if (GET_CODE (setter) != CLOBBER)
2627 bitmap_set_bit (bb_info->gen, regno);
2629 bitmap_clear_bit (bb_info->gen, regno);
2632 /* Classes of registers which could be early clobbered in the current
2635 static VEC(int,heap) *earlyclobber_regclass;
2637 /* This function finds and stores register classes that could be early
2638 clobbered in INSN. If any earlyclobber classes are found, the function
2639 returns TRUE, in all other cases it returns FALSE. */
2642 df_urec_check_earlyclobber (rtx insn)
2647 extract_insn (insn);
2649 VEC_truncate (int, earlyclobber_regclass, 0);
2650 for (opno = 0; opno < recog_data.n_operands; opno++)
2655 enum reg_class class;
2656 const char *p = recog_data.constraints[opno];
2665 case '=': case '+': case '?':
2668 case 'm': case '<': case '>': case 'V': case 'o':
2669 case 'E': case 'F': case 'G': case 'H':
2670 case 's': case 'i': case 'n':
2671 case 'I': case 'J': case 'K': case 'L':
2672 case 'M': case 'N': case 'O': case 'P':
2674 case '0': case '1': case '2': case '3': case '4':
2675 case '5': case '6': case '7': case '8': case '9':
2676 /* These don't say anything we care about. */
2684 if (amp_p && class != NO_REGS)
2690 VEC_iterate (int, earlyclobber_regclass, i, rc);
2693 if (rc == (int) class)
2697 /* We use VEC_quick_push here because
2698 earlyclobber_regclass holds no more than
2699 N_REG_CLASSES elements. */
2700 VEC_quick_push (int, earlyclobber_regclass, (int) class);
2710 class = GENERAL_REGS;
2714 class = REG_CLASS_FROM_CONSTRAINT (c, p);
2719 p += CONSTRAINT_LEN (c, p);
2726 /* The function checks that pseudo-register *X has a class
2727 intersecting with the class of pseudo-register could be early
2728 clobbered in the same insn.
2730 This function is a no-op if earlyclobber_regclass is empty.
2732 Reload can assign the same hard register to uninitialized
2733 pseudo-register and early clobbered pseudo-register in an insn if
2734 the pseudo-register is used first time in given BB and not lived at
2735 the BB start. To prevent this we don't change life information for
2736 such pseudo-registers. */
2739 df_urec_mark_reg_use_for_earlyclobber (rtx *x, void *data)
2741 enum reg_class pref_class, alt_class;
2743 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2745 if (REG_P (*x) && REGNO (*x) >= FIRST_PSEUDO_REGISTER)
2750 if (bitmap_bit_p (bb_info->kill, regno)
2751 || bitmap_bit_p (bb_info->gen, regno))
2753 pref_class = reg_preferred_class (regno);
2754 alt_class = reg_alternate_class (regno);
2755 for (i = 0; VEC_iterate (int, earlyclobber_regclass, i, rc); i++)
2757 if (reg_classes_intersect_p (rc, pref_class)
2759 && reg_classes_intersect_p (rc, alt_class)))
2761 bitmap_set_bit (bb_info->earlyclobber, regno);
2769 /* The function processes all pseudo-registers in *X with the aid of
2770 previous function. */
2773 df_urec_mark_reg_use_for_earlyclobber_1 (rtx *x, void *data)
2775 for_each_rtx (x, df_urec_mark_reg_use_for_earlyclobber, data);
2779 /* Compute local uninitialized register info for basic block BB. */
2782 df_urec_bb_local_compute (unsigned int bb_index)
2784 basic_block bb = BASIC_BLOCK (bb_index);
2785 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
2787 struct df_ref **def_rec;
2789 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2791 struct df_ref *def = *def_rec;
2792 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2794 unsigned int regno = DF_REF_REGNO (def);
2795 bitmap_set_bit (bb_info->gen, regno);
2799 FOR_BB_INSNS (bb, insn)
2803 note_stores (PATTERN (insn), df_urec_mark_reg_change, bb_info);
2804 if (df_urec_check_earlyclobber (insn))
2806 struct df_urec_problem_data *problem_data
2807 = (struct df_urec_problem_data *) df_urec->problem_data;
2808 problem_data->earlyclobbers_found = true;
2809 note_uses (&PATTERN (insn),
2810 df_urec_mark_reg_use_for_earlyclobber_1, bb_info);
2815 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2817 struct df_ref *def = *def_rec;
2818 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2820 unsigned int regno = DF_REF_REGNO (def);
2821 bitmap_set_bit (bb_info->gen, regno);
2827 /* Compute local uninitialized register info. */
2830 df_urec_local_compute (bitmap all_blocks)
2832 unsigned int bb_index;
2836 HARD_REG_SET stack_hard_regs, used;
2837 struct df_urec_problem_data *problem_data
2838 = (struct df_urec_problem_data *) df_urec->problem_data;
2840 /* Any register that MAY be allocated to a register stack (like the
2841 387) is treated poorly. Each such register is marked as being
2842 live everywhere. This keeps the register allocator and the
2843 subsequent passes from doing anything useful with these values.
2845 FIXME: This seems like an incredibly poor idea. */
2847 CLEAR_HARD_REG_SET (stack_hard_regs);
2848 for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
2849 SET_HARD_REG_BIT (stack_hard_regs, i);
2850 problem_data->stack_regs = BITMAP_ALLOC (NULL);
2851 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
2853 COPY_HARD_REG_SET (used, reg_class_contents[reg_preferred_class (i)]);
2854 IOR_HARD_REG_SET (used, reg_class_contents[reg_alternate_class (i)]);
2855 AND_HARD_REG_SET (used, stack_hard_regs);
2856 if (!hard_reg_set_empty_p (used))
2857 bitmap_set_bit (problem_data->stack_regs, i);
2861 /* We know that earlyclobber_regclass holds no more than
2862 N_REG_CLASSES elements. See df_urec_check_earlyclobber. */
2863 earlyclobber_regclass = VEC_alloc (int, heap, N_REG_CLASSES);
2865 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2867 df_urec_bb_local_compute (bb_index);
2870 VEC_free (int, heap, earlyclobber_regclass);
2874 /* Initialize the solution vectors. */
2877 df_urec_init (bitmap all_blocks)
2879 unsigned int bb_index;
2882 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2884 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
2886 bitmap_copy (bb_info->out, bb_info->gen);
2887 bitmap_clear (bb_info->in);
2892 /* Or in the stack regs, hard regs and early clobber regs into the
2893 urec_in sets of all of the blocks. */
2897 df_urec_local_finalize (bitmap all_blocks)
2899 bitmap tmp = BITMAP_ALLOC (NULL);
2901 unsigned int bb_index;
2902 struct df_urec_problem_data *problem_data
2903 = (struct df_urec_problem_data *) df_urec->problem_data;
2905 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2907 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
2908 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
2910 if (bb_index != ENTRY_BLOCK && bb_index != EXIT_BLOCK)
2912 if (problem_data->earlyclobbers_found)
2913 bitmap_ior_into (bb_info->in, bb_info->earlyclobber);
2916 /* We can not use the same stack register for uninitialized
2917 pseudo-register and another living pseudo-register
2918 because if the uninitialized pseudo-register dies,
2919 subsequent pass reg-stack will be confused (it will
2920 believe that the other register dies). */
2921 bitmap_ior_into (bb_info->in, problem_data->stack_regs);
2922 bitmap_ior_into (bb_info->out, problem_data->stack_regs);
2926 /* No register may reach a location where it is not used. Thus
2927 we trim the rr result to the places where it is used. */
2928 bitmap_and_into (bb_info->in, bb_lr_info->in);
2929 bitmap_and_into (bb_info->out, bb_lr_info->out);
2930 bitmap_copy (bb_info->top, bb_info->in);
2931 if (bb_lr_info->adef)
2932 bitmap_ior_into (bb_info->top, bb_lr_info->adef);
2933 bitmap_and_into (bb_info->top, bb_lr_info->top);
2935 /* Hard registers may still stick in the ur_out set, but not
2936 be in the ur_in set, if their only mention was in a call
2937 in this block. This is because a call kills in the lr
2938 problem but does not kill in the rr problem. To clean
2939 this up, we execute the transfer function on the lr_in
2940 set and then use that to knock bits out of ur_out. */
2941 bitmap_ior_and_compl (tmp, bb_info->gen, bb_lr_info->in,
2943 bitmap_and_into (bb_info->out, tmp);
2948 BITMAP_FREE (problem_data->stack_regs);
2954 /* Confluence function that ignores fake edges. */
2957 df_urec_confluence_n (edge e)
2959 bitmap op1 = df_urec_get_bb_info (e->dest->index)->in;
2960 bitmap op2 = df_urec_get_bb_info (e->src->index)->out;
2962 if (e->flags & EDGE_FAKE)
2965 bitmap_ior_into (op1, op2);
2969 /* Transfer function. */
2972 df_urec_transfer_function (int bb_index)
2974 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
2975 bitmap in = bb_info->in;
2976 bitmap out = bb_info->out;
2977 bitmap gen = bb_info->gen;
2978 bitmap kill = bb_info->kill;
2980 return bitmap_ior_and_compl (out, gen, in, kill);
2984 /* Free all storage associated with the problem. */
2989 if (df_urec->block_info)
2993 for (i = 0; i < df_urec->block_info_size; i++)
2995 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (i);
2998 BITMAP_FREE (bb_info->gen);
2999 BITMAP_FREE (bb_info->kill);
3000 BITMAP_FREE (bb_info->in);
3001 BITMAP_FREE (bb_info->out);
3002 BITMAP_FREE (bb_info->earlyclobber);
3003 BITMAP_FREE (bb_info->top);
3007 free_alloc_pool (df_urec->block_pool);
3009 df_urec->block_info_size = 0;
3010 free (df_urec->block_info);
3011 free (df_urec->problem_data);
3017 /* Debugging info at top of bb. */
3020 df_urec_top_dump (basic_block bb, FILE *file)
3022 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb->index);
3023 if (!bb_info || !bb_info->in)
3026 fprintf (file, ";; urec in \t");
3027 df_print_regset (file, bb_info->in);
3028 fprintf (file, ";; urec gen \t");
3029 df_print_regset (file, bb_info->gen);
3030 fprintf (file, ";; urec kill\t");
3031 df_print_regset (file, bb_info->kill);
3032 fprintf (file, ";; urec ec\t");
3033 df_print_regset (file, bb_info->earlyclobber);
3037 /* Debugging info at bottom of bb. */
3040 df_urec_bottom_dump (basic_block bb, FILE *file)
3042 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb->index);
3043 if (!bb_info || !bb_info->out)
3045 fprintf (file, ";; urec out \t");
3046 df_print_regset (file, bb_info->out);
3050 /* All of the information associated with every instance of the problem. */
3052 static struct df_problem problem_UREC =
3054 DF_UREC, /* Problem id. */
3055 DF_FORWARD, /* Direction. */
3056 df_urec_alloc, /* Allocate the problem specific data. */
3057 NULL, /* Reset global information. */
3058 df_urec_free_bb_info, /* Free basic block info. */
3059 df_urec_local_compute, /* Local compute function. */
3060 df_urec_init, /* Init the solution specific data. */
3061 df_worklist_dataflow, /* Worklist solver. */
3062 NULL, /* Confluence operator 0. */
3063 df_urec_confluence_n, /* Confluence operator n. */
3064 df_urec_transfer_function, /* Transfer function. */
3065 df_urec_local_finalize, /* Finalize function. */
3066 df_urec_free, /* Free all of the problem information. */
3067 df_urec_free, /* Remove this problem from the stack of dataflow problems. */
3068 NULL, /* Debugging. */
3069 df_urec_top_dump, /* Debugging start block. */
3070 df_urec_bottom_dump, /* Debugging end block. */
3071 NULL, /* Incremental solution verify start. */
3072 NULL, /* Incremental solution verfiy end. */
3073 &problem_LR, /* Dependent problem. */
3074 TV_DF_UREC, /* Timing variable. */
3075 false /* Reset blocks on dropping out of blocks_to_analyze. */
3079 /* Create a new DATAFLOW instance and add it to an existing instance
3080 of DF. The returned structure is what is used to get at the
3084 df_urec_add_problem (void)
3086 df_add_problem (&problem_UREC);
3091 /*----------------------------------------------------------------------------
3092 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
3094 Link either the defs to the uses and / or the uses to the defs.
3096 These problems are set up like the other dataflow problems so that
3097 they nicely fit into the framework. They are much simpler and only
3098 involve a single traversal of instructions and an examination of
3099 the reaching defs information (the dependent problem).
3100 ----------------------------------------------------------------------------*/
3102 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
3104 /* Create a du or ud chain from SRC to DST and link it into SRC. */
3107 df_chain_create (struct df_ref *src, struct df_ref *dst)
3109 struct df_link *head = DF_REF_CHAIN (src);
3110 struct df_link *link = pool_alloc (df_chain->block_pool);;
3112 DF_REF_CHAIN (src) = link;
3119 /* Delete any du or ud chains that start at REF and point to
3122 df_chain_unlink_1 (struct df_ref *ref, struct df_ref *target)
3124 struct df_link *chain = DF_REF_CHAIN (ref);
3125 struct df_link *prev = NULL;
3129 if (chain->ref == target)
3132 prev->next = chain->next;
3134 DF_REF_CHAIN (ref) = chain->next;
3135 pool_free (df_chain->block_pool, chain);
3139 chain = chain->next;
3144 /* Delete a du or ud chain that leave or point to REF. */
3147 df_chain_unlink (struct df_ref *ref)
3149 struct df_link *chain = DF_REF_CHAIN (ref);
3152 struct df_link *next = chain->next;
3153 /* Delete the other side if it exists. */
3154 df_chain_unlink_1 (chain->ref, ref);
3155 pool_free (df_chain->block_pool, chain);
3158 DF_REF_CHAIN (ref) = NULL;
3162 /* Copy the du or ud chain starting at FROM_REF and attach it to
3166 df_chain_copy (struct df_ref *to_ref,
3167 struct df_link *from_ref)
3171 df_chain_create (to_ref, from_ref->ref);
3172 from_ref = from_ref->next;
3177 /* Remove this problem from the stack of dataflow problems. */
3180 df_chain_remove_problem (void)
3183 unsigned int bb_index;
3185 /* Wholesale destruction of the old chains. */
3186 if (df_chain->block_pool)
3187 free_alloc_pool (df_chain->block_pool);
3189 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
3192 struct df_ref **def_rec;
3193 struct df_ref **use_rec;
3194 basic_block bb = BASIC_BLOCK (bb_index);
3196 if (df_chain_problem_p (DF_DU_CHAIN))
3197 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
3198 DF_REF_CHAIN (*def_rec) = NULL;
3199 if (df_chain_problem_p (DF_UD_CHAIN))
3200 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
3201 DF_REF_CHAIN (*use_rec) = NULL;
3203 FOR_BB_INSNS (bb, insn)
3205 unsigned int uid = INSN_UID (insn);
3209 if (df_chain_problem_p (DF_DU_CHAIN))
3210 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3211 DF_REF_CHAIN (*def_rec) = NULL;
3212 if (df_chain_problem_p (DF_UD_CHAIN))
3214 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3215 DF_REF_CHAIN (*use_rec) = NULL;
3216 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
3217 DF_REF_CHAIN (*use_rec) = NULL;
3223 bitmap_clear (df_chain->out_of_date_transfer_functions);
3224 df_chain->block_pool = NULL;
3228 /* Remove the chain problem completely. */
3231 df_chain_fully_remove_problem (void)
3233 df_chain_remove_problem ();
3234 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
3239 /* Create def-use or use-def chains. */
3242 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3244 df_chain_remove_problem ();
3245 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
3246 sizeof (struct df_link), 50);
3247 df_chain->optional_p = true;
3251 /* Reset all of the chains when the set of basic blocks changes. */
3254 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
3256 df_chain_remove_problem ();
3260 /* Create the chains for a list of USEs. */
3263 df_chain_create_bb_process_use (bitmap local_rd,
3264 struct df_ref **use_rec,
3265 enum df_ref_flags top_flag)
3268 unsigned int def_index;
3272 struct df_ref *use = *use_rec;
3273 unsigned int uregno = DF_REF_REGNO (use);
3274 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
3275 || (uregno >= FIRST_PSEUDO_REGISTER))
3277 /* Do not want to go through this for an uninitialized var. */
3278 int count = DF_DEFS_COUNT (uregno);
3281 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
3283 unsigned int first_index = DF_DEFS_BEGIN (uregno);
3284 unsigned int last_index = first_index + count - 1;
3286 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
3289 if (def_index > last_index)
3292 def = DF_DEFS_GET (def_index);
3293 if (df_chain_problem_p (DF_DU_CHAIN))
3294 df_chain_create (def, use);
3295 if (df_chain_problem_p (DF_UD_CHAIN))
3296 df_chain_create (use, def);
3307 /* Create chains from reaching defs bitmaps for basic block BB. */
3310 df_chain_create_bb (unsigned int bb_index)
3312 basic_block bb = BASIC_BLOCK (bb_index);
3313 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
3315 bitmap cpy = BITMAP_ALLOC (NULL);
3316 struct df_ref **def_rec;
3318 bitmap_copy (cpy, bb_info->in);
3319 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
3321 /* Since we are going forwards, process the artificial uses first
3322 then the artificial defs second. */
3325 /* Create the chains for the artificial uses from the EH_USES at the
3326 beginning of the block. */
3328 /* Artificials are only hard regs. */
3329 if (!(df->changeable_flags & DF_NO_HARD_REGS))
3330 df_chain_create_bb_process_use (cpy,
3331 df_get_artificial_uses (bb->index),
3335 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3337 struct df_ref *def = *def_rec;
3338 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3340 unsigned int dregno = DF_REF_REGNO (def);
3341 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3342 bitmap_clear_range (cpy,
3343 DF_DEFS_BEGIN (dregno),
3344 DF_DEFS_COUNT (dregno));
3345 bitmap_set_bit (cpy, DF_REF_ID (def));
3349 /* Process the regular instructions next. */
3350 FOR_BB_INSNS (bb, insn)
3352 struct df_ref **def_rec;
3353 unsigned int uid = INSN_UID (insn);
3358 /* Now scan the uses and link them up with the defs that remain
3359 in the cpy vector. */
3361 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
3363 if (df->changeable_flags & DF_EQ_NOTES)
3364 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
3367 /* Since we are going forwards, process the defs second. This
3368 pass only changes the bits in cpy. */
3369 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3371 struct df_ref *def = *def_rec;
3372 unsigned int dregno = DF_REF_REGNO (def);
3373 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
3374 || (dregno >= FIRST_PSEUDO_REGISTER))
3376 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3377 bitmap_clear_range (cpy,
3378 DF_DEFS_BEGIN (dregno),
3379 DF_DEFS_COUNT (dregno));
3380 if (!(DF_REF_FLAGS (def)
3381 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3382 bitmap_set_bit (cpy, DF_REF_ID (def));
3387 /* Create the chains for the artificial uses of the hard registers
3388 at the end of the block. */
3389 if (!(df->changeable_flags & DF_NO_HARD_REGS))
3390 df_chain_create_bb_process_use (cpy,
3391 df_get_artificial_uses (bb->index),
3397 /* Create def-use chains from reaching use bitmaps for basic blocks
3401 df_chain_finalize (bitmap all_blocks)
3403 unsigned int bb_index;
3406 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3408 df_chain_create_bb (bb_index);
3413 /* Free all storage associated with the problem. */
3416 df_chain_free (void)
3418 free_alloc_pool (df_chain->block_pool);
3419 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
3424 /* Debugging info. */
3427 df_chain_top_dump (basic_block bb, FILE *file)
3429 if (df_chain_problem_p (DF_DU_CHAIN))
3432 struct df_ref **def_rec = df_get_artificial_defs (bb->index);
3436 fprintf (file, ";; DU chains for artificial defs\n");
3439 struct df_ref *def = *def_rec;
3440 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
3441 df_chain_dump (DF_REF_CHAIN (def), file);
3442 fprintf (file, "\n");
3447 FOR_BB_INSNS (bb, insn)
3449 unsigned int uid = INSN_UID (insn);
3452 def_rec = DF_INSN_UID_DEFS (uid);
3455 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
3456 DF_INSN_LUID (insn), uid);
3460 struct df_ref *def = *def_rec;
3461 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
3462 if (def->flags & DF_REF_READ_WRITE)
3463 fprintf (file, "read/write ");
3464 df_chain_dump (DF_REF_CHAIN (def), file);
3465 fprintf (file, "\n");
3476 df_chain_bottom_dump (basic_block bb, FILE *file)
3478 if (df_chain_problem_p (DF_UD_CHAIN))
3481 struct df_ref **use_rec = df_get_artificial_uses (bb->index);
3485 fprintf (file, ";; UD chains for artificial uses\n");
3488 struct df_ref *use = *use_rec;
3489 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
3490 df_chain_dump (DF_REF_CHAIN (use), file);
3491 fprintf (file, "\n");
3496 FOR_BB_INSNS (bb, insn)
3498 unsigned int uid = INSN_UID (insn);
3501 struct df_ref **eq_use_rec = DF_INSN_UID_EQ_USES (uid);
3502 use_rec = DF_INSN_UID_USES (uid);
3503 if (*use_rec || *eq_use_rec)
3505 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
3506 DF_INSN_LUID (insn), uid);
3510 struct df_ref *use = *use_rec;
3511 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
3512 if (use->flags & DF_REF_READ_WRITE)
3513 fprintf (file, "read/write ");
3514 df_chain_dump (DF_REF_CHAIN (use), file);
3515 fprintf (file, "\n");
3520 struct df_ref *use = *eq_use_rec;
3521 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
3522 df_chain_dump (DF_REF_CHAIN (use), file);
3523 fprintf (file, "\n");
3533 static struct df_problem problem_CHAIN =
3535 DF_CHAIN, /* Problem id. */
3536 DF_NONE, /* Direction. */
3537 df_chain_alloc, /* Allocate the problem specific data. */
3538 df_chain_reset, /* Reset global information. */
3539 NULL, /* Free basic block info. */
3540 NULL, /* Local compute function. */
3541 NULL, /* Init the solution specific data. */
3542 NULL, /* Iterative solver. */
3543 NULL, /* Confluence operator 0. */
3544 NULL, /* Confluence operator n. */
3545 NULL, /* Transfer function. */
3546 df_chain_finalize, /* Finalize function. */
3547 df_chain_free, /* Free all of the problem information. */
3548 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
3549 NULL, /* Debugging. */
3550 df_chain_top_dump, /* Debugging start block. */
3551 df_chain_bottom_dump, /* Debugging end block. */
3552 NULL, /* Incremental solution verify start. */
3553 NULL, /* Incremental solution verfiy end. */
3554 &problem_RD, /* Dependent problem. */
3555 TV_DF_CHAIN, /* Timing variable. */
3556 false /* Reset blocks on dropping out of blocks_to_analyze. */
3560 /* Create a new DATAFLOW instance and add it to an existing instance
3561 of DF. The returned structure is what is used to get at the
3565 df_chain_add_problem (enum df_chain_flags chain_flags)
3567 df_add_problem (&problem_CHAIN);
3568 df_chain->local_flags = (unsigned int)chain_flags;
3569 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
3572 #undef df_chain_problem_p
3575 /*----------------------------------------------------------------------------
3576 This pass computes REG_DEAD and REG_UNUSED notes.
3577 ----------------------------------------------------------------------------*/
3580 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3582 df_note->optional_p = true;
3585 #ifdef REG_DEAD_DEBUGGING
3587 df_print_note (const char *prefix, rtx insn, rtx note)
3591 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
3592 print_rtl (dump_file, note);
3593 fprintf (dump_file, "\n");
3599 /* After reg-stack, the x86 floating point stack regs are difficult to
3600 analyze because of all of the pushes, pops and rotations. Thus, we
3601 just leave the notes alone. */
3605 df_ignore_stack_reg (int regno)
3607 return regstack_completed
3608 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
3612 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
3619 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
3620 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
3623 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
3625 rtx *pprev = ®_NOTES (insn);
3632 switch (REG_NOTE_KIND (link))
3635 /* After reg-stack, we need to ignore any unused notes
3636 for the stack registers. */
3637 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3639 pprev = &XEXP (link, 1);
3644 rtx next = XEXP (link, 1);
3645 #ifdef REG_DEAD_DEBUGGING
3646 df_print_note ("deleting: ", insn, link);
3648 XEXP (link, 1) = dead;
3650 *pprev = link = next;
3655 /* After reg-stack, we need to ignore any unused notes
3656 for the stack registers. */
3657 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3659 pprev = &XEXP (link, 1);
3664 rtx next = XEXP (link, 1);
3665 #ifdef REG_DEAD_DEBUGGING
3666 df_print_note ("deleting: ", insn, link);
3668 XEXP (link, 1) = unused;
3670 *pprev = link = next;
3675 pprev = &XEXP (link, 1);
3681 *old_dead_notes = dead;
3682 *old_unused_notes = unused;
3686 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
3687 list, otherwise create a new one. */
3690 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
3696 if (XEXP (this, 0) == reg)
3699 XEXP (prev, 1) = XEXP (this, 1);
3701 old = XEXP (this, 1);
3702 XEXP (this, 1) = REG_NOTES (insn);
3703 REG_NOTES (insn) = this;
3709 this = XEXP (this, 1);
3712 /* Did not find the note. */
3713 REG_NOTES (insn) = alloc_EXPR_LIST (note_type, reg, REG_NOTES (insn));
3717 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
3718 based on the bits in LIVE. Do not generate notes for registers in
3719 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
3720 not generated if the reg is both read and written by the
3725 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3726 bitmap live, bitmap do_not_gen,
3727 bitmap artificial_uses)
3729 bool all_dead = true;
3732 #ifdef REG_DEAD_DEBUGGING
3734 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
3735 mws->start_regno, mws->end_regno);
3737 for (r=mws->start_regno; r <= mws->end_regno; r++)
3738 if ((bitmap_bit_p (live, r))
3739 || bitmap_bit_p (artificial_uses, r))
3747 unsigned int regno = mws->start_regno;
3748 old = df_set_note (REG_UNUSED, insn, old, *(mws->loc));
3750 #ifdef REG_DEAD_DEBUGGING
3751 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3753 bitmap_set_bit (do_not_gen, regno);
3754 /* Only do this if the value is totally dead. */
3757 for (r=mws->start_regno; r <= mws->end_regno; r++)
3760 if ((!bitmap_bit_p (live, r))
3761 && (!bitmap_bit_p (artificial_uses, r)))
3763 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
3764 #ifdef REG_DEAD_DEBUGGING
3765 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3768 bitmap_set_bit (do_not_gen, r);
3774 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3775 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3776 from being set if the instruction both reads and writes the
3780 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3781 bitmap live, bitmap do_not_gen,
3782 bitmap artificial_uses)
3784 bool all_dead = true;
3787 #ifdef REG_DEAD_DEBUGGING
3790 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3791 mws->start_regno, mws->end_regno);
3792 df_print_regset (dump_file, do_not_gen);
3793 fprintf (dump_file, " live =");
3794 df_print_regset (dump_file, live);
3795 fprintf (dump_file, " artificial uses =");
3796 df_print_regset (dump_file, artificial_uses);
3800 for (r = mws->start_regno; r <= mws->end_regno; r++)
3801 if ((bitmap_bit_p (live, r))
3802 || bitmap_bit_p (artificial_uses, r)
3803 || bitmap_bit_p (do_not_gen, r))
3811 if (!bitmap_bit_p (do_not_gen, mws->start_regno))
3813 /* Add a dead note for the entire multi word register. */
3814 old = df_set_note (REG_DEAD, insn, old, *(mws->loc));
3815 #ifdef REG_DEAD_DEBUGGING
3816 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3822 for (r = mws->start_regno; r <= mws->end_regno; r++)
3824 if ((!bitmap_bit_p (live, r))
3825 && (!bitmap_bit_p (artificial_uses, r))
3826 && (!bitmap_bit_p (do_not_gen, r)))
3828 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
3829 #ifdef REG_DEAD_DEBUGGING
3830 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3839 /* Create a REG_UNUSED note if necessary for DEF in INSN updating LIVE
3840 and DO_NOT_GEN. Do not generate notes for registers in artificial
3844 df_create_unused_note (rtx insn, rtx old, struct df_ref *def,
3845 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3847 unsigned int dregno = DF_REF_REGNO (def);
3849 #ifdef REG_DEAD_DEBUGGING
3852 fprintf (dump_file, " regular looking at def ");
3853 df_ref_debug (def, dump_file);
3857 if (!(bitmap_bit_p (live, dregno)
3858 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3859 || bitmap_bit_p (artificial_uses, dregno)
3860 || df_ignore_stack_reg (dregno)))
3862 rtx reg = (DF_REF_LOC (def))
3863 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3864 old = df_set_note (REG_UNUSED, insn, old, reg);
3865 #ifdef REG_DEAD_DEBUGGING
3866 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3870 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER + DF_REF_MAY_CLOBBER)))
3871 bitmap_set_bit (do_not_gen, dregno);
3873 /* Kill this register if it is not a subreg store or conditional store. */
3874 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3875 bitmap_clear_bit (live, dregno);
3880 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3881 info: lifetime, bb, and number of defs and uses for basic block
3882 BB. The three bitvectors are scratch regs used here. */
3885 df_note_bb_compute (unsigned int bb_index,
3886 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3888 basic_block bb = BASIC_BLOCK (bb_index);
3890 struct df_ref **def_rec;
3891 struct df_ref **use_rec;
3893 bitmap_copy (live, df_get_live_out (bb));
3894 bitmap_clear (artificial_uses);
3896 #ifdef REG_DEAD_DEBUGGING
3899 fprintf (dump_file, "live at bottom ");
3900 df_print_regset (dump_file, live);
3904 /* Process the artificial defs and uses at the bottom of the block
3905 to begin processing. */
3906 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3908 struct df_ref *def = *def_rec;
3909 #ifdef REG_DEAD_DEBUGGING
3911 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3914 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3915 bitmap_clear_bit (live, DF_REF_REGNO (def));
3918 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3920 struct df_ref *use = *use_rec;
3921 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3923 unsigned int regno = DF_REF_REGNO (use);
3924 bitmap_set_bit (live, regno);
3926 /* Notes are not generated for any of the artificial registers
3927 at the bottom of the block. */
3928 bitmap_set_bit (artificial_uses, regno);
3932 #ifdef REG_DEAD_DEBUGGING
3935 fprintf (dump_file, "live before artificials out ");
3936 df_print_regset (dump_file, live);
3940 FOR_BB_INSNS_REVERSE (bb, insn)
3942 unsigned int uid = INSN_UID (insn);
3943 struct df_mw_hardreg **mws_rec;
3945 rtx old_unused_notes;
3950 bitmap_clear (do_not_gen);
3951 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
3953 /* Process the defs. */
3956 #ifdef REG_DEAD_DEBUGGING
3959 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3960 df_print_regset (dump_file, live);
3963 /* We only care about real sets for calls. Clobbers only
3964 may clobbers cannot be depended on. */
3965 mws_rec = DF_INSN_UID_MWS (uid);
3968 struct df_mw_hardreg *mws = *mws_rec;
3969 if ((mws->type == DF_REF_REG_DEF)
3970 && !df_ignore_stack_reg (REGNO (mws->mw_reg)))
3972 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3973 mws, live, do_not_gen,
3978 /* All of the defs except the return value are some sort of
3979 clobber. This code is for the return. */
3980 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3982 struct df_ref *def = *def_rec;
3983 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3985 = df_create_unused_note (insn, old_unused_notes,
3986 def, live, do_not_gen,
3993 mws_rec = DF_INSN_UID_MWS (uid);
3996 struct df_mw_hardreg *mws = *mws_rec;
3997 if (mws->type == DF_REF_REG_DEF)
3999 = df_set_unused_notes_for_mw (insn, old_unused_notes,
4000 mws, live, do_not_gen,
4005 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4007 struct df_ref *def = *def_rec;
4009 = df_create_unused_note (insn, old_unused_notes,
4010 def, live, do_not_gen,
4015 /* Process the uses. */
4016 mws_rec = DF_INSN_UID_MWS (uid);
4019 struct df_mw_hardreg *mws = *mws_rec;
4020 if ((mws->type != DF_REF_REG_DEF)
4021 && !df_ignore_stack_reg (REGNO (mws->mw_reg)))
4023 = df_set_dead_notes_for_mw (insn, old_dead_notes,
4024 mws, live, do_not_gen,
4029 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
4031 struct df_ref *use = *use_rec;
4032 unsigned int uregno = DF_REF_REGNO (use);
4034 #ifdef REG_DEAD_DEBUGGING
4037 fprintf (dump_file, " regular looking at use ");
4038 df_ref_debug (use, dump_file);
4041 if (!bitmap_bit_p (live, uregno))
4043 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
4044 && (!bitmap_bit_p (do_not_gen, uregno))
4045 && (!bitmap_bit_p (artificial_uses, uregno))
4046 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
4047 && (!df_ignore_stack_reg (uregno)))
4049 rtx reg = (DF_REF_LOC (use))
4050 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
4051 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
4053 #ifdef REG_DEAD_DEBUGGING
4054 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
4057 /* This register is now live. */
4058 bitmap_set_bit (live, uregno);
4062 while (old_unused_notes)
4064 rtx next = XEXP (old_unused_notes, 1);
4065 free_EXPR_LIST_node (old_unused_notes);
4066 old_unused_notes = next;
4068 while (old_dead_notes)
4070 rtx next = XEXP (old_dead_notes, 1);
4071 free_EXPR_LIST_node (old_dead_notes);
4072 old_dead_notes = next;
4078 /* Compute register info: lifetime, bb, and number of defs and uses. */
4080 df_note_compute (bitmap all_blocks)
4082 unsigned int bb_index;
4084 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
4085 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
4086 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
4088 #ifdef REG_DEAD_DEBUGGING
4090 print_rtl_with_bb (dump_file, get_insns());
4093 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4095 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
4099 BITMAP_FREE (do_not_gen);
4100 BITMAP_FREE (artificial_uses);
4104 /* Free all storage associated with the problem. */
4113 /* All of the information associated every instance of the problem. */
4115 static struct df_problem problem_NOTE =
4117 DF_NOTE, /* Problem id. */
4118 DF_NONE, /* Direction. */
4119 df_note_alloc, /* Allocate the problem specific data. */
4120 NULL, /* Reset global information. */
4121 NULL, /* Free basic block info. */
4122 df_note_compute, /* Local compute function. */
4123 NULL, /* Init the solution specific data. */
4124 NULL, /* Iterative solver. */
4125 NULL, /* Confluence operator 0. */
4126 NULL, /* Confluence operator n. */
4127 NULL, /* Transfer function. */
4128 NULL, /* Finalize function. */
4129 df_note_free, /* Free all of the problem information. */
4130 df_note_free, /* Remove this problem from the stack of dataflow problems. */
4131 NULL, /* Debugging. */
4132 NULL, /* Debugging start block. */
4133 NULL, /* Debugging end block. */
4134 NULL, /* Incremental solution verify start. */
4135 NULL, /* Incremental solution verfiy end. */
4137 /* Technically this is only dependent on the live registers problem
4138 but it will produce information if built one of uninitialized
4139 register problems (UR, UREC) is also run. */
4140 &problem_LR, /* Dependent problem. */
4141 TV_DF_NOTE, /* Timing variable. */
4142 false /* Reset blocks on dropping out of blocks_to_analyze. */
4146 /* Create a new DATAFLOW instance and add it to an existing instance
4147 of DF. The returned structure is what is used to get at the
4151 df_note_add_problem (void)
4153 df_add_problem (&problem_NOTE);
4159 /*----------------------------------------------------------------------------
4160 Functions for simulating the effects of single insns.
4162 You can either simulate in the forwards direction, starting from
4163 the top of a block or the backwards direction from the end of the
4164 block. The main difference is that if you go forwards, the uses
4165 are examined first then the defs, and if you go backwards, the defs
4166 are examined first then the uses.
4168 If you start at the top of the block, use one of DF_LIVE_IN or
4169 DF_LR_IN. If you start at the bottom of the block use one of
4170 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
4171 THEY WILL BE DESTROYED.
4173 ----------------------------------------------------------------------------*/
4176 /* Find the set of DEFs for INSN. */
4179 df_simulate_find_defs (rtx insn, bitmap defs)
4181 struct df_ref **def_rec;
4182 unsigned int uid = INSN_UID (insn);
4186 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4188 struct df_ref *def = *def_rec;
4189 unsigned int dregno = DF_REF_REGNO (def);
4191 if (DF_REF_FLAGS (def) & DF_REF_MUST_CLOBBER)
4193 if (dregno >= FIRST_PSEUDO_REGISTER
4194 || !(SIBLING_CALL_P (insn)
4195 && bitmap_bit_p (df->exit_block_uses, dregno)
4196 && !refers_to_regno_p (dregno, dregno+1,
4197 current_function_return_rtx,
4200 /* If the def is to only part of the reg, it does
4201 not kill the other defs that reach here. */
4202 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4203 bitmap_set_bit (defs, dregno);
4207 /* This is the return value. */
4208 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4209 bitmap_set_bit (defs, dregno);
4214 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4216 struct df_ref *def = *def_rec;
4217 /* If the def is to only part of the reg, it does
4218 not kill the other defs that reach here. */
4219 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4220 bitmap_set_bit (defs, DF_REF_REGNO (def));
4226 /* Simulate the effects of the defs of INSN on LIVE. */
4229 df_simulate_defs (rtx insn, bitmap live)
4231 struct df_ref **def_rec;
4232 unsigned int uid = INSN_UID (insn);
4236 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4238 struct df_ref *def = *def_rec;
4239 unsigned int dregno = DF_REF_REGNO (def);
4241 if (DF_REF_FLAGS (def) & DF_REF_MUST_CLOBBER)
4243 if (dregno >= FIRST_PSEUDO_REGISTER
4244 || !(SIBLING_CALL_P (insn)
4245 && bitmap_bit_p (df->exit_block_uses, dregno)
4246 && !refers_to_regno_p (dregno, dregno+1,
4247 current_function_return_rtx,
4250 /* If the def is to only part of the reg, it does
4251 not kill the other defs that reach here. */
4252 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4253 bitmap_clear_bit (live, dregno);
4257 /* This is the return value. */
4258 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4259 bitmap_clear_bit (live, dregno);
4264 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4266 struct df_ref *def = *def_rec;
4267 unsigned int dregno = DF_REF_REGNO (def);
4269 /* If the def is to only part of the reg, it does
4270 not kill the other defs that reach here. */
4271 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4272 bitmap_clear_bit (live, dregno);
4278 /* Simulate the effects of the uses of INSN on LIVE. */
4281 df_simulate_uses (rtx insn, bitmap live)
4283 struct df_ref **use_rec;
4284 unsigned int uid = INSN_UID (insn);
4286 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
4288 struct df_ref *use = *use_rec;
4289 /* Add use to set of uses in this BB. */
4290 bitmap_set_bit (live, DF_REF_REGNO (use));
4295 /* Add back the always live regs in BB to LIVE. */
4298 df_simulate_fixup_sets (basic_block bb, bitmap live)
4300 /* These regs are considered always live so if they end up dying
4301 because of some def, we need to bring the back again. */
4302 if (df_has_eh_preds (bb))
4303 bitmap_ior_into (live, df->eh_block_artificial_uses);
4305 bitmap_ior_into (live, df->regular_block_artificial_uses);
4309 /* Apply the artificial uses and defs at the top of BB in a forwards
4313 df_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
4315 struct df_ref **def_rec;
4316 struct df_ref **use_rec;
4317 int bb_index = bb->index;
4319 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4321 struct df_ref *use = *use_rec;
4322 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
4323 bitmap_set_bit (live, DF_REF_REGNO (use));
4326 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4328 struct df_ref *def = *def_rec;
4329 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4330 bitmap_clear_bit (live, DF_REF_REGNO (def));
4335 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
4338 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
4340 if (! INSN_P (insn))
4343 df_simulate_uses (insn, live);
4344 df_simulate_defs (insn, live);
4345 df_simulate_fixup_sets (bb, live);
4349 /* Apply the artificial uses and defs at the end of BB in a backwards
4353 df_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
4355 struct df_ref **def_rec;
4356 struct df_ref **use_rec;
4357 int bb_index = bb->index;
4359 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4361 struct df_ref *def = *def_rec;
4362 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
4363 bitmap_clear_bit (live, DF_REF_REGNO (def));
4366 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4368 struct df_ref *use = *use_rec;
4369 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
4370 bitmap_set_bit (live, DF_REF_REGNO (use));
4375 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
4378 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
4380 if (! INSN_P (insn))
4383 df_simulate_defs (insn, live);
4384 df_simulate_uses (insn, live);
4385 df_simulate_fixup_sets (bb, live);