Add missing ChangeLog entries for revision 160327.
[official-gcc.git] / gcc / df-problems.c
blob05d41b56ed05aefa74e5d462fedb0eb70a2833ca
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "recog.h"
33 #include "function.h"
34 #include "regs.h"
35 #include "output.h"
36 #include "alloc-pool.h"
37 #include "flags.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "sbitmap.h"
41 #include "bitmap.h"
42 #include "timevar.h"
43 #include "df.h"
44 #include "except.h"
45 #include "dce.h"
46 #include "vecprim.h"
48 /* Note that turning REG_DEAD_DEBUGGING on will cause
49 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
50 addresses in the dumps. */
51 #if 0
52 #define REG_DEAD_DEBUGGING
53 #endif
55 #define DF_SPARSE_THRESHOLD 32
57 static bitmap_head seen_in_block;
58 static bitmap_head seen_in_insn;
61 /*----------------------------------------------------------------------------
62 Public functions access functions for the dataflow problems.
63 ----------------------------------------------------------------------------*/
64 /* Get the live at out set for BB no matter what problem happens to be
65 defined. This function is used by the register allocators who
66 choose different dataflow problems depending on the optimization
67 level. */
69 bitmap
70 df_get_live_out (basic_block bb)
72 gcc_assert (df_lr);
74 if (df_live)
75 return DF_LIVE_OUT (bb);
76 else
77 return DF_LR_OUT (bb);
80 /* Get the live at in set for BB no matter what problem happens to be
81 defined. This function is used by the register allocators who
82 choose different dataflow problems depending on the optimization
83 level. */
85 bitmap
86 df_get_live_in (basic_block bb)
88 gcc_assert (df_lr);
90 if (df_live)
91 return DF_LIVE_IN (bb);
92 else
93 return DF_LR_IN (bb);
96 /*----------------------------------------------------------------------------
97 Utility functions.
98 ----------------------------------------------------------------------------*/
100 /* Generic versions to get the void* version of the block info. Only
101 used inside the problem instance vectors. */
103 /* Grow the bb_info array. */
105 void
106 df_grow_bb_info (struct dataflow *dflow)
108 unsigned int new_size = last_basic_block + 1;
109 if (dflow->block_info_size < new_size)
111 new_size += new_size / 4;
112 dflow->block_info = XRESIZEVEC (void *, dflow->block_info, new_size);
113 memset (dflow->block_info + dflow->block_info_size, 0,
114 (new_size - dflow->block_info_size) *sizeof (void *));
115 dflow->block_info_size = new_size;
119 /* Dump a def-use or use-def chain for REF to FILE. */
121 void
122 df_chain_dump (struct df_link *link, FILE *file)
124 fprintf (file, "{ ");
125 for (; link; link = link->next)
127 fprintf (file, "%c%d(bb %d insn %d) ",
128 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
129 DF_REF_ID (link->ref),
130 DF_REF_BBNO (link->ref),
131 DF_REF_IS_ARTIFICIAL (link->ref) ? -1 : DF_REF_INSN_UID (link->ref));
133 fprintf (file, "}");
137 /* Print some basic block info as part of df_dump. */
139 void
140 df_print_bb_index (basic_block bb, FILE *file)
142 edge e;
143 edge_iterator ei;
145 fprintf (file, "\n( ");
146 FOR_EACH_EDGE (e, ei, bb->preds)
148 basic_block pred = e->src;
149 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
151 fprintf (file, ")->[%d]->( ", bb->index);
152 FOR_EACH_EDGE (e, ei, bb->succs)
154 basic_block succ = e->dest;
155 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
157 fprintf (file, ")\n");
161 /*----------------------------------------------------------------------------
162 REACHING DEFINITIONS
164 Find the locations in the function where each definition site for a
165 pseudo reaches. In and out bitvectors are built for each basic
166 block. The id field in the ref is used to index into these sets.
167 See df.h for details.
168 ----------------------------------------------------------------------------*/
170 /* This problem plays a large number of games for the sake of
171 efficiency.
173 1) The order of the bits in the bitvectors. After the scanning
174 phase, all of the defs are sorted. All of the defs for the reg 0
175 are first, followed by all defs for reg 1 and so on.
177 2) There are two kill sets, one if the number of defs is less or
178 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
179 greater.
181 <= : Data is built directly in the kill set.
183 > : One level of indirection is used to keep from generating long
184 strings of 1 bits in the kill sets. Bitvectors that are indexed
185 by the regnum are used to represent that there is a killing def
186 for the register. The confluence and transfer functions use
187 these along with the bitmap_clear_range call to remove ranges of
188 bits without actually generating a knockout vector.
190 The kill and sparse_kill and the dense_invalidated_by_call and
191 sparse_invalidated_by_call both play this game. */
193 /* Private data used to compute the solution for this problem. These
194 data structures are not accessible outside of this module. */
195 struct df_rd_problem_data
197 /* The set of defs to regs invalidated by call. */
198 bitmap_head sparse_invalidated_by_call;
199 /* The set of defs to regs invalidate by call for rd. */
200 bitmap_head dense_invalidated_by_call;
201 /* An obstack for the bitmaps we need for this problem. */
202 bitmap_obstack rd_bitmaps;
205 /* Set basic block info. */
207 static void
208 df_rd_set_bb_info (unsigned int index,
209 struct df_rd_bb_info *bb_info)
211 gcc_assert (df_rd);
212 gcc_assert (index < df_rd->block_info_size);
213 df_rd->block_info[index] = bb_info;
217 /* Free basic block info. */
219 static void
220 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
221 void *vbb_info)
223 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
224 if (bb_info)
226 bitmap_clear (&bb_info->kill);
227 bitmap_clear (&bb_info->sparse_kill);
228 bitmap_clear (&bb_info->gen);
229 bitmap_clear (&bb_info->in);
230 bitmap_clear (&bb_info->out);
231 pool_free (df_rd->block_pool, bb_info);
236 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
237 not touched unless the block is new. */
239 static void
240 df_rd_alloc (bitmap all_blocks)
242 unsigned int bb_index;
243 bitmap_iterator bi;
244 struct df_rd_problem_data *problem_data;
246 if (!df_rd->block_pool)
247 df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
248 sizeof (struct df_rd_bb_info), 50);
250 if (df_rd->problem_data)
252 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
253 bitmap_clear (&problem_data->sparse_invalidated_by_call);
254 bitmap_clear (&problem_data->dense_invalidated_by_call);
256 else
258 problem_data = XNEW (struct df_rd_problem_data);
259 df_rd->problem_data = problem_data;
261 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
262 bitmap_initialize (&problem_data->sparse_invalidated_by_call,
263 &problem_data->rd_bitmaps);
264 bitmap_initialize (&problem_data->dense_invalidated_by_call,
265 &problem_data->rd_bitmaps);
268 df_grow_bb_info (df_rd);
270 /* Because of the clustering of all use sites for the same pseudo,
271 we have to process all of the blocks before doing the
272 analysis. */
274 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
276 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
277 if (bb_info)
279 bitmap_clear (&bb_info->kill);
280 bitmap_clear (&bb_info->sparse_kill);
281 bitmap_clear (&bb_info->gen);
283 else
285 bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
286 df_rd_set_bb_info (bb_index, bb_info);
287 bitmap_initialize (&bb_info->kill, &problem_data->rd_bitmaps);
288 bitmap_initialize (&bb_info->sparse_kill, &problem_data->rd_bitmaps);
289 bitmap_initialize (&bb_info->gen, &problem_data->rd_bitmaps);
290 bitmap_initialize (&bb_info->in, &problem_data->rd_bitmaps);
291 bitmap_initialize (&bb_info->out, &problem_data->rd_bitmaps);
294 df_rd->optional_p = true;
298 /* Add the effect of the top artificial defs of BB to the reaching definitions
299 bitmap LOCAL_RD. */
301 void
302 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
304 int bb_index = bb->index;
305 df_ref *def_rec;
306 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
308 df_ref def = *def_rec;
309 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
311 unsigned int dregno = DF_REF_REGNO (def);
312 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
313 bitmap_clear_range (local_rd,
314 DF_DEFS_BEGIN (dregno),
315 DF_DEFS_COUNT (dregno));
316 bitmap_set_bit (local_rd, DF_REF_ID (def));
321 /* Add the effect of the defs of INSN to the reaching definitions bitmap
322 LOCAL_RD. */
324 void
325 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
326 bitmap local_rd)
328 unsigned uid = INSN_UID (insn);
329 df_ref *def_rec;
331 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
333 df_ref def = *def_rec;
334 unsigned int dregno = DF_REF_REGNO (def);
335 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
336 || (dregno >= FIRST_PSEUDO_REGISTER))
338 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
339 bitmap_clear_range (local_rd,
340 DF_DEFS_BEGIN (dregno),
341 DF_DEFS_COUNT (dregno));
342 if (!(DF_REF_FLAGS (def)
343 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
344 bitmap_set_bit (local_rd, DF_REF_ID (def));
349 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
350 more complicated than just simulating, because we must produce the
351 gen and kill sets and hence deal with the two possible representations
352 of kill sets. */
354 static void
355 df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
356 df_ref *def_rec,
357 int top_flag)
359 while (*def_rec)
361 df_ref def = *def_rec;
362 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
364 unsigned int regno = DF_REF_REGNO (def);
365 unsigned int begin = DF_DEFS_BEGIN (regno);
366 unsigned int n_defs = DF_DEFS_COUNT (regno);
368 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
369 || (regno >= FIRST_PSEUDO_REGISTER))
371 /* Only the last def(s) for a regno in the block has any
372 effect. */
373 if (!bitmap_bit_p (&seen_in_block, regno))
375 /* The first def for regno in insn gets to knock out the
376 defs from other instructions. */
377 if ((!bitmap_bit_p (&seen_in_insn, regno))
378 /* If the def is to only part of the reg, it does
379 not kill the other defs that reach here. */
380 && (!(DF_REF_FLAGS (def) &
381 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
383 if (n_defs > DF_SPARSE_THRESHOLD)
385 bitmap_set_bit (&bb_info->sparse_kill, regno);
386 bitmap_clear_range(&bb_info->gen, begin, n_defs);
388 else
390 bitmap_set_range (&bb_info->kill, begin, n_defs);
391 bitmap_clear_range (&bb_info->gen, begin, n_defs);
395 bitmap_set_bit (&seen_in_insn, regno);
396 /* All defs for regno in the instruction may be put into
397 the gen set. */
398 if (!(DF_REF_FLAGS (def)
399 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
400 bitmap_set_bit (&bb_info->gen, DF_REF_ID (def));
404 def_rec++;
408 /* Compute local reaching def info for basic block BB. */
410 static void
411 df_rd_bb_local_compute (unsigned int bb_index)
413 basic_block bb = BASIC_BLOCK (bb_index);
414 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
415 rtx insn;
417 bitmap_clear (&seen_in_block);
418 bitmap_clear (&seen_in_insn);
420 /* Artificials are only hard regs. */
421 if (!(df->changeable_flags & DF_NO_HARD_REGS))
422 df_rd_bb_local_compute_process_def (bb_info,
423 df_get_artificial_defs (bb_index),
426 FOR_BB_INSNS_REVERSE (bb, insn)
428 unsigned int uid = INSN_UID (insn);
430 if (!INSN_P (insn))
431 continue;
433 df_rd_bb_local_compute_process_def (bb_info,
434 DF_INSN_UID_DEFS (uid), 0);
436 /* This complex dance with the two bitmaps is required because
437 instructions can assign twice to the same pseudo. This
438 generally happens with calls that will have one def for the
439 result and another def for the clobber. If only one vector
440 is used and the clobber goes first, the result will be
441 lost. */
442 bitmap_ior_into (&seen_in_block, &seen_in_insn);
443 bitmap_clear (&seen_in_insn);
446 /* Process the artificial defs at the top of the block last since we
447 are going backwards through the block and these are logically at
448 the start. */
449 if (!(df->changeable_flags & DF_NO_HARD_REGS))
450 df_rd_bb_local_compute_process_def (bb_info,
451 df_get_artificial_defs (bb_index),
452 DF_REF_AT_TOP);
456 /* Compute local reaching def info for each basic block within BLOCKS. */
458 static void
459 df_rd_local_compute (bitmap all_blocks)
461 unsigned int bb_index;
462 bitmap_iterator bi;
463 unsigned int regno;
464 struct df_rd_problem_data *problem_data
465 = (struct df_rd_problem_data *) df_rd->problem_data;
466 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
467 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
469 bitmap_initialize (&seen_in_block, &df_bitmap_obstack);
470 bitmap_initialize (&seen_in_insn, &df_bitmap_obstack);
472 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
474 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
476 df_rd_bb_local_compute (bb_index);
479 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
480 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, regno, bi)
482 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
483 bitmap_set_bit (sparse_invalidated, regno);
484 else
485 bitmap_set_range (dense_invalidated,
486 DF_DEFS_BEGIN (regno),
487 DF_DEFS_COUNT (regno));
490 bitmap_clear (&seen_in_block);
491 bitmap_clear (&seen_in_insn);
495 /* Initialize the solution bit vectors for problem. */
497 static void
498 df_rd_init_solution (bitmap all_blocks)
500 unsigned int bb_index;
501 bitmap_iterator bi;
503 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
505 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
507 bitmap_copy (&bb_info->out, &bb_info->gen);
508 bitmap_clear (&bb_info->in);
512 /* In of target gets or of out of source. */
514 static void
515 df_rd_confluence_n (edge e)
517 bitmap op1 = &df_rd_get_bb_info (e->dest->index)->in;
518 bitmap op2 = &df_rd_get_bb_info (e->src->index)->out;
520 if (e->flags & EDGE_FAKE)
521 return;
523 if (e->flags & EDGE_EH)
525 struct df_rd_problem_data *problem_data
526 = (struct df_rd_problem_data *) df_rd->problem_data;
527 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
528 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
529 bitmap_iterator bi;
530 unsigned int regno;
531 bitmap_head tmp;
533 bitmap_initialize (&tmp, &df_bitmap_obstack);
534 bitmap_copy (&tmp, op2);
535 bitmap_and_compl_into (&tmp, dense_invalidated);
537 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
539 bitmap_clear_range (&tmp,
540 DF_DEFS_BEGIN (regno),
541 DF_DEFS_COUNT (regno));
543 bitmap_ior_into (op1, &tmp);
544 bitmap_clear (&tmp);
546 else
547 bitmap_ior_into (op1, op2);
551 /* Transfer function. */
553 static bool
554 df_rd_transfer_function (int bb_index)
556 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
557 unsigned int regno;
558 bitmap_iterator bi;
559 bitmap in = &bb_info->in;
560 bitmap out = &bb_info->out;
561 bitmap gen = &bb_info->gen;
562 bitmap kill = &bb_info->kill;
563 bitmap sparse_kill = &bb_info->sparse_kill;
565 if (bitmap_empty_p (sparse_kill))
566 return bitmap_ior_and_compl (out, gen, in, kill);
567 else
569 struct df_rd_problem_data *problem_data;
570 bool changed = false;
571 bitmap_head tmp;
573 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
574 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
575 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
576 bitmap_initialize (&tmp, &problem_data->rd_bitmaps);
578 bitmap_copy (&tmp, in);
579 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
581 bitmap_clear_range (&tmp,
582 DF_DEFS_BEGIN (regno),
583 DF_DEFS_COUNT (regno));
585 bitmap_and_compl_into (&tmp, kill);
586 bitmap_ior_into (&tmp, gen);
587 changed = !bitmap_equal_p (&tmp, out);
588 if (changed)
590 bitmap_clear (out);
591 bb_info->out = tmp;
593 else
594 bitmap_clear (&tmp);
595 return changed;
600 /* Free all storage associated with the problem. */
602 static void
603 df_rd_free (void)
605 struct df_rd_problem_data *problem_data
606 = (struct df_rd_problem_data *) df_rd->problem_data;
608 if (problem_data)
610 free_alloc_pool (df_rd->block_pool);
611 bitmap_obstack_release (&problem_data->rd_bitmaps);
613 df_rd->block_info_size = 0;
614 free (df_rd->block_info);
615 free (df_rd->problem_data);
617 free (df_rd);
621 /* Debugging info. */
623 static void
624 df_rd_start_dump (FILE *file)
626 struct df_rd_problem_data *problem_data
627 = (struct df_rd_problem_data *) df_rd->problem_data;
628 unsigned int m = DF_REG_SIZE(df);
629 unsigned int regno;
631 if (!df_rd->block_info)
632 return;
634 fprintf (file, ";; Reaching defs:\n\n");
636 fprintf (file, " sparse invalidated \t");
637 dump_bitmap (file, &problem_data->sparse_invalidated_by_call);
638 fprintf (file, " dense invalidated \t");
639 dump_bitmap (file, &problem_data->dense_invalidated_by_call);
641 for (regno = 0; regno < m; regno++)
642 if (DF_DEFS_COUNT (regno))
643 fprintf (file, "%d[%d,%d] ", regno,
644 DF_DEFS_BEGIN (regno),
645 DF_DEFS_COUNT (regno));
646 fprintf (file, "\n");
651 /* Debugging info at top of bb. */
653 static void
654 df_rd_top_dump (basic_block bb, FILE *file)
656 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
657 if (!bb_info)
658 return;
660 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (&bb_info->in));
661 dump_bitmap (file, &bb_info->in);
662 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (&bb_info->gen));
663 dump_bitmap (file, &bb_info->gen);
664 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (&bb_info->kill));
665 dump_bitmap (file, &bb_info->kill);
669 /* Debugging info at top of bb. */
671 static void
672 df_rd_bottom_dump (basic_block bb, FILE *file)
674 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
675 if (!bb_info)
676 return;
678 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (&bb_info->out));
679 dump_bitmap (file, &bb_info->out);
682 /* All of the information associated with every instance of the problem. */
684 static struct df_problem problem_RD =
686 DF_RD, /* Problem id. */
687 DF_FORWARD, /* Direction. */
688 df_rd_alloc, /* Allocate the problem specific data. */
689 NULL, /* Reset global information. */
690 df_rd_free_bb_info, /* Free basic block info. */
691 df_rd_local_compute, /* Local compute function. */
692 df_rd_init_solution, /* Init the solution specific data. */
693 df_worklist_dataflow, /* Worklist solver. */
694 NULL, /* Confluence operator 0. */
695 df_rd_confluence_n, /* Confluence operator n. */
696 df_rd_transfer_function, /* Transfer function. */
697 NULL, /* Finalize function. */
698 df_rd_free, /* Free all of the problem information. */
699 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
700 df_rd_start_dump, /* Debugging. */
701 df_rd_top_dump, /* Debugging start block. */
702 df_rd_bottom_dump, /* Debugging end block. */
703 NULL, /* Incremental solution verify start. */
704 NULL, /* Incremental solution verify end. */
705 NULL, /* Dependent problem. */
706 TV_DF_RD, /* Timing variable. */
707 true /* Reset blocks on dropping out of blocks_to_analyze. */
712 /* Create a new RD instance and add it to the existing instance
713 of DF. */
715 void
716 df_rd_add_problem (void)
718 df_add_problem (&problem_RD);
723 /*----------------------------------------------------------------------------
724 LIVE REGISTERS
726 Find the locations in the function where any use of a pseudo can
727 reach in the backwards direction. In and out bitvectors are built
728 for each basic block. The regno is used to index into these sets.
729 See df.h for details.
730 ----------------------------------------------------------------------------*/
732 /* Private data used to verify the solution for this problem. */
733 struct df_lr_problem_data
735 bitmap_head *in;
736 bitmap_head *out;
737 /* An obstack for the bitmaps we need for this problem. */
738 bitmap_obstack lr_bitmaps;
742 /* Set basic block info. */
744 static void
745 df_lr_set_bb_info (unsigned int index,
746 struct df_lr_bb_info *bb_info)
748 gcc_assert (df_lr);
749 gcc_assert (index < df_lr->block_info_size);
750 df_lr->block_info[index] = bb_info;
754 /* Free basic block info. */
756 static void
757 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
758 void *vbb_info)
760 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
761 if (bb_info)
763 bitmap_clear (&bb_info->use);
764 bitmap_clear (&bb_info->def);
765 bitmap_clear (&bb_info->in);
766 bitmap_clear (&bb_info->out);
767 pool_free (df_lr->block_pool, bb_info);
772 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
773 not touched unless the block is new. */
775 static void
776 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
778 unsigned int bb_index;
779 bitmap_iterator bi;
780 struct df_lr_problem_data *problem_data;
782 if (!df_lr->block_pool)
783 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
784 sizeof (struct df_lr_bb_info), 50);
786 df_grow_bb_info (df_lr);
787 if (df_lr->problem_data)
788 problem_data = (struct df_lr_problem_data *) df_lr->problem_data;
789 else
791 problem_data = XNEW (struct df_lr_problem_data);
792 df_lr->problem_data = problem_data;
794 problem_data->out = NULL;
795 problem_data->in = NULL;
796 bitmap_obstack_initialize (&problem_data->lr_bitmaps);
799 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
801 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
802 if (bb_info)
804 bitmap_clear (&bb_info->def);
805 bitmap_clear (&bb_info->use);
807 else
809 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
810 df_lr_set_bb_info (bb_index, bb_info);
811 bitmap_initialize (&bb_info->use, &problem_data->lr_bitmaps);
812 bitmap_initialize (&bb_info->def, &problem_data->lr_bitmaps);
813 bitmap_initialize (&bb_info->in, &problem_data->lr_bitmaps);
814 bitmap_initialize (&bb_info->out, &problem_data->lr_bitmaps);
818 df_lr->optional_p = false;
822 /* Reset the global solution for recalculation. */
824 static void
825 df_lr_reset (bitmap all_blocks)
827 unsigned int bb_index;
828 bitmap_iterator bi;
830 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
832 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
833 gcc_assert (bb_info);
834 bitmap_clear (&bb_info->in);
835 bitmap_clear (&bb_info->out);
840 /* Compute local live register info for basic block BB. */
842 static void
843 df_lr_bb_local_compute (unsigned int bb_index)
845 basic_block bb = BASIC_BLOCK (bb_index);
846 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
847 rtx insn;
848 df_ref *def_rec;
849 df_ref *use_rec;
851 /* Process the registers set in an exception handler. */
852 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
854 df_ref def = *def_rec;
855 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
857 unsigned int dregno = DF_REF_REGNO (def);
858 bitmap_set_bit (&bb_info->def, dregno);
859 bitmap_clear_bit (&bb_info->use, dregno);
863 /* Process the hardware registers that are always live. */
864 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
866 df_ref use = *use_rec;
867 /* Add use to set of uses in this BB. */
868 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
869 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
872 FOR_BB_INSNS_REVERSE (bb, insn)
874 unsigned int uid = INSN_UID (insn);
876 if (!NONDEBUG_INSN_P (insn))
877 continue;
879 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
881 df_ref def = *def_rec;
882 /* If the def is to only part of the reg, it does
883 not kill the other defs that reach here. */
884 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
886 unsigned int dregno = DF_REF_REGNO (def);
887 bitmap_set_bit (&bb_info->def, dregno);
888 bitmap_clear_bit (&bb_info->use, dregno);
892 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
894 df_ref use = *use_rec;
895 /* Add use to set of uses in this BB. */
896 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
900 /* Process the registers set in an exception handler or the hard
901 frame pointer if this block is the target of a non local
902 goto. */
903 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
905 df_ref def = *def_rec;
906 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
908 unsigned int dregno = DF_REF_REGNO (def);
909 bitmap_set_bit (&bb_info->def, dregno);
910 bitmap_clear_bit (&bb_info->use, dregno);
914 #ifdef EH_USES
915 /* Process the uses that are live into an exception handler. */
916 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
918 df_ref use = *use_rec;
919 /* Add use to set of uses in this BB. */
920 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
921 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
923 #endif
925 /* If the df_live problem is not defined, such as at -O0 and -O1, we
926 still need to keep the luids up to date. This is normally done
927 in the df_live problem since this problem has a forwards
928 scan. */
929 if (!df_live)
930 df_recompute_luids (bb);
934 /* Compute local live register info for each basic block within BLOCKS. */
936 static void
937 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
939 unsigned int bb_index;
940 bitmap_iterator bi;
942 bitmap_clear (&df->hardware_regs_used);
944 /* The all-important stack pointer must always be live. */
945 bitmap_set_bit (&df->hardware_regs_used, STACK_POINTER_REGNUM);
947 /* Before reload, there are a few registers that must be forced
948 live everywhere -- which might not already be the case for
949 blocks within infinite loops. */
950 if (!reload_completed)
952 /* Any reference to any pseudo before reload is a potential
953 reference of the frame pointer. */
954 bitmap_set_bit (&df->hardware_regs_used, FRAME_POINTER_REGNUM);
956 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
957 /* Pseudos with argument area equivalences may require
958 reloading via the argument pointer. */
959 if (fixed_regs[ARG_POINTER_REGNUM])
960 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
961 #endif
963 /* Any constant, or pseudo with constant equivalences, may
964 require reloading from memory using the pic register. */
965 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
966 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
967 bitmap_set_bit (&df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
970 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
972 if (bb_index == EXIT_BLOCK)
974 /* The exit block is special for this problem and its bits are
975 computed from thin air. */
976 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
977 bitmap_copy (&bb_info->use, df->exit_block_uses);
979 else
980 df_lr_bb_local_compute (bb_index);
983 bitmap_clear (df_lr->out_of_date_transfer_functions);
987 /* Initialize the solution vectors. */
989 static void
990 df_lr_init (bitmap all_blocks)
992 unsigned int bb_index;
993 bitmap_iterator bi;
995 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
997 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
998 bitmap_copy (&bb_info->in, &bb_info->use);
999 bitmap_clear (&bb_info->out);
1004 /* Confluence function that processes infinite loops. This might be a
1005 noreturn function that throws. And even if it isn't, getting the
1006 unwind info right helps debugging. */
1007 static void
1008 df_lr_confluence_0 (basic_block bb)
1010 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
1011 if (bb != EXIT_BLOCK_PTR)
1012 bitmap_copy (op1, &df->hardware_regs_used);
1016 /* Confluence function that ignores fake edges. */
1018 static void
1019 df_lr_confluence_n (edge e)
1021 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
1022 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
1024 /* Call-clobbered registers die across exception and call edges. */
1025 /* ??? Abnormal call edges ignored for the moment, as this gets
1026 confused by sibling call edges, which crashes reg-stack. */
1027 if (e->flags & EDGE_EH)
1028 bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
1029 else
1030 bitmap_ior_into (op1, op2);
1032 bitmap_ior_into (op1, &df->hardware_regs_used);
1036 /* Transfer function. */
1038 static bool
1039 df_lr_transfer_function (int bb_index)
1041 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1042 bitmap in = &bb_info->in;
1043 bitmap out = &bb_info->out;
1044 bitmap use = &bb_info->use;
1045 bitmap def = &bb_info->def;
1047 return bitmap_ior_and_compl (in, use, out, def);
1051 /* Run the fast dce as a side effect of building LR. */
1053 static void
1054 df_lr_finalize (bitmap all_blocks)
1056 df_lr->solutions_dirty = false;
1057 if (df->changeable_flags & DF_LR_RUN_DCE)
1059 run_fast_df_dce ();
1061 /* If dce deletes some instructions, we need to recompute the lr
1062 solution before proceeding further. The problem is that fast
1063 dce is a pessimestic dataflow algorithm. In the case where
1064 it deletes a statement S inside of a loop, the uses inside of
1065 S may not be deleted from the dataflow solution because they
1066 were carried around the loop. While it is conservatively
1067 correct to leave these extra bits, the standards of df
1068 require that we maintain the best possible (least fixed
1069 point) solution. The only way to do that is to redo the
1070 iteration from the beginning. See PR35805 for an
1071 example. */
1072 if (df_lr->solutions_dirty)
1074 df_clear_flags (DF_LR_RUN_DCE);
1075 df_lr_alloc (all_blocks);
1076 df_lr_local_compute (all_blocks);
1077 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1078 df_lr_finalize (all_blocks);
1079 df_set_flags (DF_LR_RUN_DCE);
1085 /* Free all storage associated with the problem. */
1087 static void
1088 df_lr_free (void)
1090 struct df_lr_problem_data *problem_data
1091 = (struct df_lr_problem_data *) df_lr->problem_data;
1092 if (df_lr->block_info)
1094 free_alloc_pool (df_lr->block_pool);
1096 df_lr->block_info_size = 0;
1097 free (df_lr->block_info);
1098 bitmap_obstack_release (&problem_data->lr_bitmaps);
1099 free (df_lr->problem_data);
1100 df_lr->problem_data = NULL;
1103 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1104 free (df_lr);
1108 /* Debugging info at top of bb. */
1110 static void
1111 df_lr_top_dump (basic_block bb, FILE *file)
1113 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1114 struct df_lr_problem_data *problem_data;
1115 if (!bb_info)
1116 return;
1118 fprintf (file, ";; lr in \t");
1119 df_print_regset (file, &bb_info->in);
1120 if (df_lr->problem_data)
1122 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1123 if (problem_data->in)
1125 fprintf (file, ";; old in \t");
1126 df_print_regset (file, &problem_data->in[bb->index]);
1129 fprintf (file, ";; lr use \t");
1130 df_print_regset (file, &bb_info->use);
1131 fprintf (file, ";; lr def \t");
1132 df_print_regset (file, &bb_info->def);
1136 /* Debugging info at bottom of bb. */
1138 static void
1139 df_lr_bottom_dump (basic_block bb, FILE *file)
1141 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1142 struct df_lr_problem_data *problem_data;
1143 if (!bb_info)
1144 return;
1146 fprintf (file, ";; lr out \t");
1147 df_print_regset (file, &bb_info->out);
1148 if (df_lr->problem_data)
1150 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1151 if (problem_data->out)
1153 fprintf (file, ";; old out \t");
1154 df_print_regset (file, &problem_data->out[bb->index]);
1160 /* Build the datastructure to verify that the solution to the dataflow
1161 equations is not dirty. */
1163 static void
1164 df_lr_verify_solution_start (void)
1166 basic_block bb;
1167 struct df_lr_problem_data *problem_data;
1168 if (df_lr->solutions_dirty)
1169 return;
1171 /* Set it true so that the solution is recomputed. */
1172 df_lr->solutions_dirty = true;
1174 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1175 problem_data->in = XNEWVEC (bitmap_head, last_basic_block);
1176 problem_data->out = XNEWVEC (bitmap_head, last_basic_block);
1178 FOR_ALL_BB (bb)
1180 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1181 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1182 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1183 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1188 /* Compare the saved datastructure and the new solution to the dataflow
1189 equations. */
1191 static void
1192 df_lr_verify_solution_end (void)
1194 struct df_lr_problem_data *problem_data;
1195 basic_block bb;
1197 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1199 if (!problem_data->out)
1200 return;
1202 if (df_lr->solutions_dirty)
1203 /* Do not check if the solution is still dirty. See the comment
1204 in df_lr_finalize for details. */
1205 df_lr->solutions_dirty = false;
1206 else
1207 FOR_ALL_BB (bb)
1209 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1210 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1212 /*df_dump (stderr);*/
1213 gcc_unreachable ();
1217 /* Cannot delete them immediately because you may want to dump them
1218 if the comparison fails. */
1219 FOR_ALL_BB (bb)
1221 bitmap_clear (&problem_data->in[bb->index]);
1222 bitmap_clear (&problem_data->out[bb->index]);
1225 free (problem_data->in);
1226 free (problem_data->out);
1227 problem_data->in = NULL;
1228 problem_data->out = NULL;
1232 /* All of the information associated with every instance of the problem. */
1234 static struct df_problem problem_LR =
1236 DF_LR, /* Problem id. */
1237 DF_BACKWARD, /* Direction. */
1238 df_lr_alloc, /* Allocate the problem specific data. */
1239 df_lr_reset, /* Reset global information. */
1240 df_lr_free_bb_info, /* Free basic block info. */
1241 df_lr_local_compute, /* Local compute function. */
1242 df_lr_init, /* Init the solution specific data. */
1243 df_worklist_dataflow, /* Worklist solver. */
1244 df_lr_confluence_0, /* Confluence operator 0. */
1245 df_lr_confluence_n, /* Confluence operator n. */
1246 df_lr_transfer_function, /* Transfer function. */
1247 df_lr_finalize, /* Finalize function. */
1248 df_lr_free, /* Free all of the problem information. */
1249 NULL, /* Remove this problem from the stack of dataflow problems. */
1250 NULL, /* Debugging. */
1251 df_lr_top_dump, /* Debugging start block. */
1252 df_lr_bottom_dump, /* Debugging end block. */
1253 df_lr_verify_solution_start,/* Incremental solution verify start. */
1254 df_lr_verify_solution_end, /* Incremental solution verify end. */
1255 NULL, /* Dependent problem. */
1256 TV_DF_LR, /* Timing variable. */
1257 false /* Reset blocks on dropping out of blocks_to_analyze. */
1261 /* Create a new DATAFLOW instance and add it to an existing instance
1262 of DF. The returned structure is what is used to get at the
1263 solution. */
1265 void
1266 df_lr_add_problem (void)
1268 df_add_problem (&problem_LR);
1269 /* These will be initialized when df_scan_blocks processes each
1270 block. */
1271 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1275 /* Verify that all of the lr related info is consistent and
1276 correct. */
1278 void
1279 df_lr_verify_transfer_functions (void)
1281 basic_block bb;
1282 bitmap_head saved_def;
1283 bitmap_head saved_use;
1284 bitmap_head all_blocks;
1286 if (!df)
1287 return;
1289 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1290 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1291 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1293 FOR_ALL_BB (bb)
1295 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1296 bitmap_set_bit (&all_blocks, bb->index);
1298 if (bb_info)
1300 /* Make a copy of the transfer functions and then compute
1301 new ones to see if the transfer functions have
1302 changed. */
1303 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1304 bb->index))
1306 bitmap_copy (&saved_def, &bb_info->def);
1307 bitmap_copy (&saved_use, &bb_info->use);
1308 bitmap_clear (&bb_info->def);
1309 bitmap_clear (&bb_info->use);
1311 df_lr_bb_local_compute (bb->index);
1312 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1313 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1316 else
1318 /* If we do not have basic block info, the block must be in
1319 the list of dirty blocks or else some one has added a
1320 block behind our backs. */
1321 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1322 bb->index));
1324 /* Make sure no one created a block without following
1325 procedures. */
1326 gcc_assert (df_scan_get_bb_info (bb->index));
1329 /* Make sure there are no dirty bits in blocks that have been deleted. */
1330 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1331 &all_blocks));
1333 bitmap_clear (&saved_def);
1334 bitmap_clear (&saved_use);
1335 bitmap_clear (&all_blocks);
1340 /*----------------------------------------------------------------------------
1341 LIVE AND MUST-INITIALIZED REGISTERS.
1343 This problem first computes the IN and OUT bitvectors for the
1344 must-initialized registers problems, which is a forward problem.
1345 It gives the set of registers for which we MUST have an available
1346 definition on any path from the entry block to the entry/exit of
1347 a basic block. Sets generate a definition, while clobbers kill
1348 a definition.
1350 In and out bitvectors are built for each basic block and are indexed by
1351 regnum (see df.h for details). In and out bitvectors in struct
1352 df_live_bb_info actually refers to the must-initialized problem;
1354 Then, the in and out sets for the LIVE problem itself are computed.
1355 These are the logical AND of the IN and OUT sets from the LR problem
1356 and the must-initialized problem.
1357 ----------------------------------------------------------------------------*/
1359 /* Private data used to verify the solution for this problem. */
1360 struct df_live_problem_data
1362 bitmap_head *in;
1363 bitmap_head *out;
1366 /* Scratch var used by transfer functions. This is used to implement
1367 an optimization to reduce the amount of space used to compute the
1368 combined lr and live analysis. */
1369 static bitmap df_live_scratch;
1371 /* Set basic block info. */
1373 static void
1374 df_live_set_bb_info (unsigned int index,
1375 struct df_live_bb_info *bb_info)
1377 gcc_assert (df_live);
1378 gcc_assert (index < df_live->block_info_size);
1379 df_live->block_info[index] = bb_info;
1383 /* Free basic block info. */
1385 static void
1386 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1387 void *vbb_info)
1389 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1390 if (bb_info)
1392 bitmap_clear (&bb_info->gen);
1393 bitmap_clear (&bb_info->kill);
1394 bitmap_clear (&bb_info->in);
1395 bitmap_clear (&bb_info->out);
1396 pool_free (df_live->block_pool, bb_info);
1401 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1402 not touched unless the block is new. */
1404 static void
1405 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1407 unsigned int bb_index;
1408 bitmap_iterator bi;
1410 if (!df_live->block_pool)
1411 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1412 sizeof (struct df_live_bb_info), 100);
1413 if (!df_live_scratch)
1414 df_live_scratch = BITMAP_ALLOC (NULL);
1416 df_grow_bb_info (df_live);
1418 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1420 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1421 if (bb_info)
1423 bitmap_clear (&bb_info->kill);
1424 bitmap_clear (&bb_info->gen);
1426 else
1428 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1429 df_live_set_bb_info (bb_index, bb_info);
1430 bitmap_initialize (&bb_info->kill, &bitmap_default_obstack);
1431 bitmap_initialize (&bb_info->gen, &bitmap_default_obstack);
1432 bitmap_initialize (&bb_info->in, &bitmap_default_obstack);
1433 bitmap_initialize (&bb_info->out, &bitmap_default_obstack);
1436 df_live->optional_p = (optimize <= 1);
1440 /* Reset the global solution for recalculation. */
1442 static void
1443 df_live_reset (bitmap all_blocks)
1445 unsigned int bb_index;
1446 bitmap_iterator bi;
1448 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1450 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1451 gcc_assert (bb_info);
1452 bitmap_clear (&bb_info->in);
1453 bitmap_clear (&bb_info->out);
1458 /* Compute local uninitialized register info for basic block BB. */
1460 static void
1461 df_live_bb_local_compute (unsigned int bb_index)
1463 basic_block bb = BASIC_BLOCK (bb_index);
1464 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1465 rtx insn;
1466 df_ref *def_rec;
1467 int luid = 0;
1469 FOR_BB_INSNS (bb, insn)
1471 unsigned int uid = INSN_UID (insn);
1472 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1474 /* Inserting labels does not always trigger the incremental
1475 rescanning. */
1476 if (!insn_info)
1478 gcc_assert (!INSN_P (insn));
1479 insn_info = df_insn_create_insn_record (insn);
1482 DF_INSN_INFO_LUID (insn_info) = luid;
1483 if (!INSN_P (insn))
1484 continue;
1486 luid++;
1487 for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)
1489 df_ref def = *def_rec;
1490 unsigned int regno = DF_REF_REGNO (def);
1492 if (DF_REF_FLAGS_IS_SET (def,
1493 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1494 /* All partial or conditional def
1495 seen are included in the gen set. */
1496 bitmap_set_bit (&bb_info->gen, regno);
1497 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1498 /* Only must clobbers for the entire reg destroy the
1499 value. */
1500 bitmap_set_bit (&bb_info->kill, regno);
1501 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1502 bitmap_set_bit (&bb_info->gen, regno);
1506 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1508 df_ref def = *def_rec;
1509 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1514 /* Compute local uninitialized register info. */
1516 static void
1517 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1519 unsigned int bb_index;
1520 bitmap_iterator bi;
1522 df_grow_insn_info ();
1524 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1525 0, bb_index, bi)
1527 df_live_bb_local_compute (bb_index);
1530 bitmap_clear (df_live->out_of_date_transfer_functions);
1534 /* Initialize the solution vectors. */
1536 static void
1537 df_live_init (bitmap all_blocks)
1539 unsigned int bb_index;
1540 bitmap_iterator bi;
1542 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1544 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1545 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1547 /* No register may reach a location where it is not used. Thus
1548 we trim the rr result to the places where it is used. */
1549 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1550 bitmap_clear (&bb_info->in);
1554 /* Forward confluence function that ignores fake edges. */
1556 static void
1557 df_live_confluence_n (edge e)
1559 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1560 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1562 if (e->flags & EDGE_FAKE)
1563 return;
1565 bitmap_ior_into (op1, op2);
1569 /* Transfer function for the forwards must-initialized problem. */
1571 static bool
1572 df_live_transfer_function (int bb_index)
1574 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1575 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1576 bitmap in = &bb_info->in;
1577 bitmap out = &bb_info->out;
1578 bitmap gen = &bb_info->gen;
1579 bitmap kill = &bb_info->kill;
1581 /* We need to use a scratch set here so that the value returned from this
1582 function invocation properly reflects whether the sets changed in a
1583 significant way; i.e. not just because the lr set was anded in. */
1584 bitmap_and (df_live_scratch, gen, &bb_lr_info->out);
1585 /* No register may reach a location where it is not used. Thus
1586 we trim the rr result to the places where it is used. */
1587 bitmap_and_into (in, &bb_lr_info->in);
1589 return bitmap_ior_and_compl (out, df_live_scratch, in, kill);
1593 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1595 static void
1596 df_live_finalize (bitmap all_blocks)
1599 if (df_live->solutions_dirty)
1601 bitmap_iterator bi;
1602 unsigned int bb_index;
1604 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1606 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1607 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1609 /* No register may reach a location where it is not used. Thus
1610 we trim the rr result to the places where it is used. */
1611 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1612 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1615 df_live->solutions_dirty = false;
1620 /* Free all storage associated with the problem. */
1622 static void
1623 df_live_free (void)
1625 if (df_live->block_info)
1627 unsigned int i;
1629 for (i = 0; i < df_live->block_info_size; i++)
1631 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
1632 if (bb_info)
1634 bitmap_clear (&bb_info->gen);
1635 bitmap_clear (&bb_info->kill);
1636 bitmap_clear (&bb_info->in);
1637 bitmap_clear (&bb_info->out);
1641 free_alloc_pool (df_live->block_pool);
1642 df_live->block_info_size = 0;
1643 free (df_live->block_info);
1645 if (df_live_scratch)
1646 BITMAP_FREE (df_live_scratch);
1648 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1649 free (df_live);
1653 /* Debugging info at top of bb. */
1655 static void
1656 df_live_top_dump (basic_block bb, FILE *file)
1658 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1659 struct df_live_problem_data *problem_data;
1661 if (!bb_info)
1662 return;
1664 fprintf (file, ";; live in \t");
1665 df_print_regset (file, &bb_info->in);
1666 if (df_live->problem_data)
1668 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1669 fprintf (file, ";; old in \t");
1670 df_print_regset (file, &problem_data->in[bb->index]);
1672 fprintf (file, ";; live gen \t");
1673 df_print_regset (file, &bb_info->gen);
1674 fprintf (file, ";; live kill\t");
1675 df_print_regset (file, &bb_info->kill);
1679 /* Debugging info at bottom of bb. */
1681 static void
1682 df_live_bottom_dump (basic_block bb, FILE *file)
1684 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1685 struct df_live_problem_data *problem_data;
1687 if (!bb_info)
1688 return;
1690 fprintf (file, ";; live out \t");
1691 df_print_regset (file, &bb_info->out);
1692 if (df_live->problem_data)
1694 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1695 fprintf (file, ";; old out \t");
1696 df_print_regset (file, &problem_data->out[bb->index]);
1701 /* Build the datastructure to verify that the solution to the dataflow
1702 equations is not dirty. */
1704 static void
1705 df_live_verify_solution_start (void)
1707 basic_block bb;
1708 struct df_live_problem_data *problem_data;
1709 if (df_live->solutions_dirty)
1711 df_live->problem_data = NULL;
1712 return;
1715 /* Set it true so that the solution is recomputed. */
1716 df_live->solutions_dirty = true;
1718 problem_data = XNEW (struct df_live_problem_data);
1719 df_live->problem_data = problem_data;
1720 problem_data->in = XNEWVEC (bitmap_head, last_basic_block);
1721 problem_data->out = XNEWVEC (bitmap_head, last_basic_block);
1723 FOR_ALL_BB (bb)
1725 bitmap_initialize (&problem_data->in[bb->index], &bitmap_default_obstack);
1726 bitmap_initialize (&problem_data->out[bb->index], &bitmap_default_obstack);
1727 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1728 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1733 /* Compare the saved datastructure and the new solution to the dataflow
1734 equations. */
1736 static void
1737 df_live_verify_solution_end (void)
1739 struct df_live_problem_data *problem_data;
1740 basic_block bb;
1742 if (df_live->problem_data == NULL)
1743 return;
1745 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1747 FOR_ALL_BB (bb)
1749 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1750 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1752 /*df_dump (stderr);*/
1753 gcc_unreachable ();
1757 /* Cannot delete them immediately because you may want to dump them
1758 if the comparison fails. */
1759 FOR_ALL_BB (bb)
1761 bitmap_clear (&problem_data->in[bb->index]);
1762 bitmap_clear (&problem_data->out[bb->index]);
1765 free (problem_data->in);
1766 free (problem_data->out);
1767 free (problem_data);
1768 df_live->problem_data = NULL;
1772 /* All of the information associated with every instance of the problem. */
1774 static struct df_problem problem_LIVE =
1776 DF_LIVE, /* Problem id. */
1777 DF_FORWARD, /* Direction. */
1778 df_live_alloc, /* Allocate the problem specific data. */
1779 df_live_reset, /* Reset global information. */
1780 df_live_free_bb_info, /* Free basic block info. */
1781 df_live_local_compute, /* Local compute function. */
1782 df_live_init, /* Init the solution specific data. */
1783 df_worklist_dataflow, /* Worklist solver. */
1784 NULL, /* Confluence operator 0. */
1785 df_live_confluence_n, /* Confluence operator n. */
1786 df_live_transfer_function, /* Transfer function. */
1787 df_live_finalize, /* Finalize function. */
1788 df_live_free, /* Free all of the problem information. */
1789 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1790 NULL, /* Debugging. */
1791 df_live_top_dump, /* Debugging start block. */
1792 df_live_bottom_dump, /* Debugging end block. */
1793 df_live_verify_solution_start,/* Incremental solution verify start. */
1794 df_live_verify_solution_end, /* Incremental solution verify end. */
1795 &problem_LR, /* Dependent problem. */
1796 TV_DF_LIVE, /* Timing variable. */
1797 false /* Reset blocks on dropping out of blocks_to_analyze. */
1801 /* Create a new DATAFLOW instance and add it to an existing instance
1802 of DF. The returned structure is what is used to get at the
1803 solution. */
1805 void
1806 df_live_add_problem (void)
1808 df_add_problem (&problem_LIVE);
1809 /* These will be initialized when df_scan_blocks processes each
1810 block. */
1811 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1815 /* Set all of the blocks as dirty. This needs to be done if this
1816 problem is added after all of the insns have been scanned. */
1818 void
1819 df_live_set_all_dirty (void)
1821 basic_block bb;
1822 FOR_ALL_BB (bb)
1823 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1824 bb->index);
1828 /* Verify that all of the lr related info is consistent and
1829 correct. */
1831 void
1832 df_live_verify_transfer_functions (void)
1834 basic_block bb;
1835 bitmap_head saved_gen;
1836 bitmap_head saved_kill;
1837 bitmap_head all_blocks;
1839 if (!df)
1840 return;
1842 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1843 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1844 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1846 df_grow_insn_info ();
1848 FOR_ALL_BB (bb)
1850 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1851 bitmap_set_bit (&all_blocks, bb->index);
1853 if (bb_info)
1855 /* Make a copy of the transfer functions and then compute
1856 new ones to see if the transfer functions have
1857 changed. */
1858 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1859 bb->index))
1861 bitmap_copy (&saved_gen, &bb_info->gen);
1862 bitmap_copy (&saved_kill, &bb_info->kill);
1863 bitmap_clear (&bb_info->gen);
1864 bitmap_clear (&bb_info->kill);
1866 df_live_bb_local_compute (bb->index);
1867 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1868 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1871 else
1873 /* If we do not have basic block info, the block must be in
1874 the list of dirty blocks or else some one has added a
1875 block behind our backs. */
1876 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1877 bb->index));
1879 /* Make sure no one created a block without following
1880 procedures. */
1881 gcc_assert (df_scan_get_bb_info (bb->index));
1884 /* Make sure there are no dirty bits in blocks that have been deleted. */
1885 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1886 &all_blocks));
1887 bitmap_clear (&saved_gen);
1888 bitmap_clear (&saved_kill);
1889 bitmap_clear (&all_blocks);
1892 /*----------------------------------------------------------------------------
1893 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1895 Link either the defs to the uses and / or the uses to the defs.
1897 These problems are set up like the other dataflow problems so that
1898 they nicely fit into the framework. They are much simpler and only
1899 involve a single traversal of instructions and an examination of
1900 the reaching defs information (the dependent problem).
1901 ----------------------------------------------------------------------------*/
1903 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1905 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1907 struct df_link *
1908 df_chain_create (df_ref src, df_ref dst)
1910 struct df_link *head = DF_REF_CHAIN (src);
1911 struct df_link *link = (struct df_link *) pool_alloc (df_chain->block_pool);
1913 DF_REF_CHAIN (src) = link;
1914 link->next = head;
1915 link->ref = dst;
1916 return link;
1920 /* Delete any du or ud chains that start at REF and point to
1921 TARGET. */
1922 static void
1923 df_chain_unlink_1 (df_ref ref, df_ref target)
1925 struct df_link *chain = DF_REF_CHAIN (ref);
1926 struct df_link *prev = NULL;
1928 while (chain)
1930 if (chain->ref == target)
1932 if (prev)
1933 prev->next = chain->next;
1934 else
1935 DF_REF_CHAIN (ref) = chain->next;
1936 pool_free (df_chain->block_pool, chain);
1937 return;
1939 prev = chain;
1940 chain = chain->next;
1945 /* Delete a du or ud chain that leave or point to REF. */
1947 void
1948 df_chain_unlink (df_ref ref)
1950 struct df_link *chain = DF_REF_CHAIN (ref);
1951 while (chain)
1953 struct df_link *next = chain->next;
1954 /* Delete the other side if it exists. */
1955 df_chain_unlink_1 (chain->ref, ref);
1956 pool_free (df_chain->block_pool, chain);
1957 chain = next;
1959 DF_REF_CHAIN (ref) = NULL;
1963 /* Copy the du or ud chain starting at FROM_REF and attach it to
1964 TO_REF. */
1966 void
1967 df_chain_copy (df_ref to_ref,
1968 struct df_link *from_ref)
1970 while (from_ref)
1972 df_chain_create (to_ref, from_ref->ref);
1973 from_ref = from_ref->next;
1978 /* Remove this problem from the stack of dataflow problems. */
1980 static void
1981 df_chain_remove_problem (void)
1983 bitmap_iterator bi;
1984 unsigned int bb_index;
1986 /* Wholesale destruction of the old chains. */
1987 if (df_chain->block_pool)
1988 free_alloc_pool (df_chain->block_pool);
1990 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1992 rtx insn;
1993 df_ref *def_rec;
1994 df_ref *use_rec;
1995 basic_block bb = BASIC_BLOCK (bb_index);
1997 if (df_chain_problem_p (DF_DU_CHAIN))
1998 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1999 DF_REF_CHAIN (*def_rec) = NULL;
2000 if (df_chain_problem_p (DF_UD_CHAIN))
2001 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
2002 DF_REF_CHAIN (*use_rec) = NULL;
2004 FOR_BB_INSNS (bb, insn)
2006 unsigned int uid = INSN_UID (insn);
2008 if (INSN_P (insn))
2010 if (df_chain_problem_p (DF_DU_CHAIN))
2011 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2012 DF_REF_CHAIN (*def_rec) = NULL;
2013 if (df_chain_problem_p (DF_UD_CHAIN))
2015 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2016 DF_REF_CHAIN (*use_rec) = NULL;
2017 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
2018 DF_REF_CHAIN (*use_rec) = NULL;
2024 bitmap_clear (df_chain->out_of_date_transfer_functions);
2025 df_chain->block_pool = NULL;
2029 /* Remove the chain problem completely. */
2031 static void
2032 df_chain_fully_remove_problem (void)
2034 df_chain_remove_problem ();
2035 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2036 free (df_chain);
2040 /* Create def-use or use-def chains. */
2042 static void
2043 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2045 df_chain_remove_problem ();
2046 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2047 sizeof (struct df_link), 50);
2048 df_chain->optional_p = true;
2052 /* Reset all of the chains when the set of basic blocks changes. */
2054 static void
2055 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2057 df_chain_remove_problem ();
2061 /* Create the chains for a list of USEs. */
2063 static void
2064 df_chain_create_bb_process_use (bitmap local_rd,
2065 df_ref *use_rec,
2066 int top_flag)
2068 bitmap_iterator bi;
2069 unsigned int def_index;
2071 while (*use_rec)
2073 df_ref use = *use_rec;
2074 unsigned int uregno = DF_REF_REGNO (use);
2075 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2076 || (uregno >= FIRST_PSEUDO_REGISTER))
2078 /* Do not want to go through this for an uninitialized var. */
2079 int count = DF_DEFS_COUNT (uregno);
2080 if (count)
2082 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2084 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2085 unsigned int last_index = first_index + count - 1;
2087 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2089 df_ref def;
2090 if (def_index > last_index)
2091 break;
2093 def = DF_DEFS_GET (def_index);
2094 if (df_chain_problem_p (DF_DU_CHAIN))
2095 df_chain_create (def, use);
2096 if (df_chain_problem_p (DF_UD_CHAIN))
2097 df_chain_create (use, def);
2103 use_rec++;
2108 /* Create chains from reaching defs bitmaps for basic block BB. */
2110 static void
2111 df_chain_create_bb (unsigned int bb_index)
2113 basic_block bb = BASIC_BLOCK (bb_index);
2114 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2115 rtx insn;
2116 bitmap_head cpy;
2118 bitmap_initialize (&cpy, &bitmap_default_obstack);
2119 bitmap_copy (&cpy, &bb_info->in);
2120 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2122 /* Since we are going forwards, process the artificial uses first
2123 then the artificial defs second. */
2125 #ifdef EH_USES
2126 /* Create the chains for the artificial uses from the EH_USES at the
2127 beginning of the block. */
2129 /* Artificials are only hard regs. */
2130 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2131 df_chain_create_bb_process_use (&cpy,
2132 df_get_artificial_uses (bb->index),
2133 DF_REF_AT_TOP);
2134 #endif
2136 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2138 /* Process the regular instructions next. */
2139 FOR_BB_INSNS (bb, insn)
2140 if (INSN_P (insn))
2142 unsigned int uid = INSN_UID (insn);
2144 /* First scan the uses and link them up with the defs that remain
2145 in the cpy vector. */
2146 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2147 if (df->changeable_flags & DF_EQ_NOTES)
2148 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2150 /* Since we are going forwards, process the defs second. */
2151 df_rd_simulate_one_insn (bb, insn, &cpy);
2154 /* Create the chains for the artificial uses of the hard registers
2155 at the end of the block. */
2156 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2157 df_chain_create_bb_process_use (&cpy,
2158 df_get_artificial_uses (bb->index),
2161 bitmap_clear (&cpy);
2164 /* Create def-use chains from reaching use bitmaps for basic blocks
2165 in BLOCKS. */
2167 static void
2168 df_chain_finalize (bitmap all_blocks)
2170 unsigned int bb_index;
2171 bitmap_iterator bi;
2173 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2175 df_chain_create_bb (bb_index);
2180 /* Free all storage associated with the problem. */
2182 static void
2183 df_chain_free (void)
2185 free_alloc_pool (df_chain->block_pool);
2186 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2187 free (df_chain);
2191 /* Debugging info. */
2193 static void
2194 df_chain_top_dump (basic_block bb, FILE *file)
2196 if (df_chain_problem_p (DF_DU_CHAIN))
2198 rtx insn;
2199 df_ref *def_rec = df_get_artificial_defs (bb->index);
2200 if (*def_rec)
2203 fprintf (file, ";; DU chains for artificial defs\n");
2204 while (*def_rec)
2206 df_ref def = *def_rec;
2207 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2208 df_chain_dump (DF_REF_CHAIN (def), file);
2209 fprintf (file, "\n");
2210 def_rec++;
2214 FOR_BB_INSNS (bb, insn)
2216 if (INSN_P (insn))
2218 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2219 def_rec = DF_INSN_INFO_DEFS (insn_info);
2220 if (*def_rec)
2222 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2223 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2225 while (*def_rec)
2227 df_ref def = *def_rec;
2228 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2229 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2230 fprintf (file, "read/write ");
2231 df_chain_dump (DF_REF_CHAIN (def), file);
2232 fprintf (file, "\n");
2233 def_rec++;
2242 static void
2243 df_chain_bottom_dump (basic_block bb, FILE *file)
2245 if (df_chain_problem_p (DF_UD_CHAIN))
2247 rtx insn;
2248 df_ref *use_rec = df_get_artificial_uses (bb->index);
2250 if (*use_rec)
2252 fprintf (file, ";; UD chains for artificial uses\n");
2253 while (*use_rec)
2255 df_ref use = *use_rec;
2256 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2257 df_chain_dump (DF_REF_CHAIN (use), file);
2258 fprintf (file, "\n");
2259 use_rec++;
2263 FOR_BB_INSNS (bb, insn)
2265 if (INSN_P (insn))
2267 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2268 df_ref *eq_use_rec = DF_INSN_INFO_EQ_USES (insn_info);
2269 use_rec = DF_INSN_INFO_USES (insn_info);
2270 if (*use_rec || *eq_use_rec)
2272 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2273 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2275 while (*use_rec)
2277 df_ref use = *use_rec;
2278 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2279 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2280 fprintf (file, "read/write ");
2281 df_chain_dump (DF_REF_CHAIN (use), file);
2282 fprintf (file, "\n");
2283 use_rec++;
2285 while (*eq_use_rec)
2287 df_ref use = *eq_use_rec;
2288 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2289 df_chain_dump (DF_REF_CHAIN (use), file);
2290 fprintf (file, "\n");
2291 eq_use_rec++;
2300 static struct df_problem problem_CHAIN =
2302 DF_CHAIN, /* Problem id. */
2303 DF_NONE, /* Direction. */
2304 df_chain_alloc, /* Allocate the problem specific data. */
2305 df_chain_reset, /* Reset global information. */
2306 NULL, /* Free basic block info. */
2307 NULL, /* Local compute function. */
2308 NULL, /* Init the solution specific data. */
2309 NULL, /* Iterative solver. */
2310 NULL, /* Confluence operator 0. */
2311 NULL, /* Confluence operator n. */
2312 NULL, /* Transfer function. */
2313 df_chain_finalize, /* Finalize function. */
2314 df_chain_free, /* Free all of the problem information. */
2315 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2316 NULL, /* Debugging. */
2317 df_chain_top_dump, /* Debugging start block. */
2318 df_chain_bottom_dump, /* Debugging end block. */
2319 NULL, /* Incremental solution verify start. */
2320 NULL, /* Incremental solution verify end. */
2321 &problem_RD, /* Dependent problem. */
2322 TV_DF_CHAIN, /* Timing variable. */
2323 false /* Reset blocks on dropping out of blocks_to_analyze. */
2327 /* Create a new DATAFLOW instance and add it to an existing instance
2328 of DF. The returned structure is what is used to get at the
2329 solution. */
2331 void
2332 df_chain_add_problem (unsigned int chain_flags)
2334 df_add_problem (&problem_CHAIN);
2335 df_chain->local_flags = chain_flags;
2336 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2339 #undef df_chain_problem_p
2342 /*----------------------------------------------------------------------------
2343 BYTE LEVEL LIVE REGISTERS
2345 Find the locations in the function where any use of a pseudo can
2346 reach in the backwards direction. In and out bitvectors are built
2347 for each basic block. There are two mapping functions,
2348 df_byte_lr_get_regno_start and df_byte_lr_get_regno_len that are
2349 used to map regnos into bit vector positions.
2351 This problem differs from the regular df_lr function in the way
2352 that subregs, *_extracts and strict_low_parts are handled. In lr
2353 these are consider partial kills, here, the exact set of bytes is
2354 modeled. Note that any reg that has none of these operations is
2355 only modeled with a single bit since all operations access the
2356 entire register.
2358 This problem is more brittle that the regular lr. It currently can
2359 be used in dce incrementally, but cannot be used in an environment
2360 where insns are created or modified. The problem is that the
2361 mapping of regnos to bitmap positions is relatively compact, in
2362 that if a pseudo does not do any of the byte wise operations, only
2363 one slot is allocated, rather than a slot for each byte. If insn
2364 are created, where a subreg is used for a reg that had no subregs,
2365 the mapping would be wrong. Likewise, there are no checks to see
2366 that new pseudos have been added. These issues could be addressed
2367 by adding a problem specific flag to not use the compact mapping,
2368 if there was a need to do so.
2370 ----------------------------------------------------------------------------*/
2372 /* Private data used to verify the solution for this problem. */
2373 struct df_byte_lr_problem_data
2375 /* Expanded versions of bitvectors used in lr. */
2376 bitmap_head invalidated_by_call;
2377 bitmap_head hardware_regs_used;
2379 /* Indexed by regno, this is true if there are subregs, extracts or
2380 strict_low_parts for this regno. */
2381 bitmap_head needs_expansion;
2383 /* The start position and len for each regno in the various bit
2384 vectors. */
2385 unsigned int* regno_start;
2386 unsigned int* regno_len;
2387 /* An obstack for the bitmaps we need for this problem. */
2388 bitmap_obstack byte_lr_bitmaps;
2392 /* Get the starting location for REGNO in the df_byte_lr bitmaps. */
2395 df_byte_lr_get_regno_start (unsigned int regno)
2397 struct df_byte_lr_problem_data *problem_data
2398 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;;
2399 return problem_data->regno_start[regno];
2403 /* Get the len for REGNO in the df_byte_lr bitmaps. */
2406 df_byte_lr_get_regno_len (unsigned int regno)
2408 struct df_byte_lr_problem_data *problem_data
2409 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;;
2410 return problem_data->regno_len[regno];
2414 /* Set basic block info. */
2416 static void
2417 df_byte_lr_set_bb_info (unsigned int index,
2418 struct df_byte_lr_bb_info *bb_info)
2420 gcc_assert (df_byte_lr);
2421 gcc_assert (index < df_byte_lr->block_info_size);
2422 df_byte_lr->block_info[index] = bb_info;
2426 /* Free basic block info. */
2428 static void
2429 df_byte_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2430 void *vbb_info)
2432 struct df_byte_lr_bb_info *bb_info = (struct df_byte_lr_bb_info *) vbb_info;
2433 if (bb_info)
2435 bitmap_clear (&bb_info->use);
2436 bitmap_clear (&bb_info->def);
2437 bitmap_clear (&bb_info->in);
2438 bitmap_clear (&bb_info->out);
2439 pool_free (df_byte_lr->block_pool, bb_info);
2444 /* Check all of the refs in REF_REC to see if any of them are
2445 extracts, subregs or strict_low_parts. */
2447 static void
2448 df_byte_lr_check_regs (df_ref *ref_rec)
2450 struct df_byte_lr_problem_data *problem_data
2451 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2453 for (; *ref_rec; ref_rec++)
2455 df_ref ref = *ref_rec;
2456 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_SIGN_EXTRACT
2457 | DF_REF_ZERO_EXTRACT
2458 | DF_REF_STRICT_LOW_PART)
2459 || GET_CODE (DF_REF_REG (ref)) == SUBREG)
2460 bitmap_set_bit (&problem_data->needs_expansion, DF_REF_REGNO (ref));
2465 /* Expand bitmap SRC which is indexed by regno to DEST which is indexed by
2466 regno_start and regno_len. */
2468 static void
2469 df_byte_lr_expand_bitmap (bitmap dest, bitmap src)
2471 struct df_byte_lr_problem_data *problem_data
2472 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2473 bitmap_iterator bi;
2474 unsigned int i;
2476 bitmap_clear (dest);
2477 EXECUTE_IF_SET_IN_BITMAP (src, 0, i, bi)
2479 bitmap_set_range (dest, problem_data->regno_start[i],
2480 problem_data->regno_len[i]);
2485 /* Allocate or reset bitmaps for DF_BYTE_LR blocks. The solution bits are
2486 not touched unless the block is new. */
2488 static void
2489 df_byte_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2491 unsigned int bb_index;
2492 bitmap_iterator bi;
2493 basic_block bb;
2494 unsigned int regno;
2495 unsigned int index = 0;
2496 unsigned int max_reg = max_reg_num();
2497 struct df_byte_lr_problem_data *problem_data
2498 = XNEW (struct df_byte_lr_problem_data);
2500 df_byte_lr->problem_data = problem_data;
2502 if (!df_byte_lr->block_pool)
2503 df_byte_lr->block_pool = create_alloc_pool ("df_byte_lr_block pool",
2504 sizeof (struct df_byte_lr_bb_info), 50);
2506 df_grow_bb_info (df_byte_lr);
2508 /* Create the mapping from regnos to slots. This does not change
2509 unless the problem is destroyed and recreated. In particular, if
2510 we end up deleting the only insn that used a subreg, we do not
2511 want to redo the mapping because this would invalidate everything
2512 else. */
2514 bitmap_obstack_initialize (&problem_data->byte_lr_bitmaps);
2515 problem_data->regno_start = XNEWVEC (unsigned int, max_reg);
2516 problem_data->regno_len = XNEWVEC (unsigned int, max_reg);
2517 bitmap_initialize (&problem_data->hardware_regs_used,
2518 &problem_data->byte_lr_bitmaps);
2519 bitmap_initialize (&problem_data->invalidated_by_call,
2520 &problem_data->byte_lr_bitmaps);
2521 bitmap_initialize (&problem_data->needs_expansion,
2522 &problem_data->byte_lr_bitmaps);
2524 /* Discover which regno's use subregs, extracts or
2525 strict_low_parts. */
2526 FOR_EACH_BB (bb)
2528 rtx insn;
2529 FOR_BB_INSNS (bb, insn)
2531 if (INSN_P (insn))
2533 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2534 df_byte_lr_check_regs (DF_INSN_INFO_DEFS (insn_info));
2535 df_byte_lr_check_regs (DF_INSN_INFO_USES (insn_info));
2538 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, bb->index);
2541 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2542 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2544 /* Allocate the slots for each regno. */
2545 for (regno = 0; regno < max_reg; regno++)
2547 int len;
2548 problem_data->regno_start[regno] = index;
2549 if (bitmap_bit_p (&problem_data->needs_expansion, regno))
2550 len = GET_MODE_SIZE (GET_MODE (regno_reg_rtx[regno]));
2551 else
2552 len = 1;
2554 problem_data->regno_len[regno] = len;
2555 index += len;
2558 df_byte_lr_expand_bitmap (&problem_data->hardware_regs_used,
2559 &df->hardware_regs_used);
2560 df_byte_lr_expand_bitmap (&problem_data->invalidated_by_call,
2561 regs_invalidated_by_call_regset);
2563 EXECUTE_IF_SET_IN_BITMAP (df_byte_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2565 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2566 if (bb_info)
2568 bitmap_clear (&bb_info->def);
2569 bitmap_clear (&bb_info->use);
2571 else
2573 bb_info = (struct df_byte_lr_bb_info *) pool_alloc (df_byte_lr->block_pool);
2574 df_byte_lr_set_bb_info (bb_index, bb_info);
2575 bitmap_initialize (&bb_info->use, &problem_data->byte_lr_bitmaps);
2576 bitmap_initialize (&bb_info->def, &problem_data->byte_lr_bitmaps);
2577 bitmap_initialize (&bb_info->in, &problem_data->byte_lr_bitmaps);
2578 bitmap_initialize (&bb_info->out, &problem_data->byte_lr_bitmaps);
2582 df_byte_lr->optional_p = true;
2586 /* Reset the global solution for recalculation. */
2588 static void
2589 df_byte_lr_reset (bitmap all_blocks)
2591 unsigned int bb_index;
2592 bitmap_iterator bi;
2594 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2596 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2597 gcc_assert (bb_info);
2598 bitmap_clear (&bb_info->in);
2599 bitmap_clear (&bb_info->out);
2604 /* Compute local live register info for basic block BB. */
2606 static void
2607 df_byte_lr_bb_local_compute (unsigned int bb_index)
2609 struct df_byte_lr_problem_data *problem_data
2610 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2611 basic_block bb = BASIC_BLOCK (bb_index);
2612 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2613 rtx insn;
2614 df_ref *def_rec;
2615 df_ref *use_rec;
2617 /* Process the registers set in an exception handler. */
2618 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2620 df_ref def = *def_rec;
2621 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2623 unsigned int dregno = DF_REF_REGNO (def);
2624 unsigned int start = problem_data->regno_start[dregno];
2625 unsigned int len = problem_data->regno_len[dregno];
2626 bitmap_set_range (&bb_info->def, start, len);
2627 bitmap_clear_range (&bb_info->use, start, len);
2631 /* Process the hardware registers that are always live. */
2632 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2634 df_ref use = *use_rec;
2635 /* Add use to set of uses in this BB. */
2636 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2638 unsigned int uregno = DF_REF_REGNO (use);
2639 unsigned int start = problem_data->regno_start[uregno];
2640 unsigned int len = problem_data->regno_len[uregno];
2641 bitmap_set_range (&bb_info->use, start, len);
2645 FOR_BB_INSNS_REVERSE (bb, insn)
2647 unsigned int uid = INSN_UID (insn);
2649 if (!INSN_P (insn))
2650 continue;
2652 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2654 df_ref def = *def_rec;
2655 /* If the def is to only part of the reg, it does
2656 not kill the other defs that reach here. */
2657 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2659 unsigned int dregno = DF_REF_REGNO (def);
2660 unsigned int start = problem_data->regno_start[dregno];
2661 unsigned int len = problem_data->regno_len[dregno];
2662 unsigned int sb;
2663 unsigned int lb;
2664 if (!df_compute_accessed_bytes (def, DF_MM_MUST, &sb, &lb))
2666 start += sb;
2667 len = lb - sb;
2669 if (len)
2671 bitmap_set_range (&bb_info->def, start, len);
2672 bitmap_clear_range (&bb_info->use, start, len);
2677 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2679 df_ref use = *use_rec;
2680 unsigned int uregno = DF_REF_REGNO (use);
2681 unsigned int start = problem_data->regno_start[uregno];
2682 unsigned int len = problem_data->regno_len[uregno];
2683 unsigned int sb;
2684 unsigned int lb;
2685 if (!df_compute_accessed_bytes (use, DF_MM_MAY, &sb, &lb))
2687 start += sb;
2688 len = lb - sb;
2690 /* Add use to set of uses in this BB. */
2691 if (len)
2692 bitmap_set_range (&bb_info->use, start, len);
2696 /* Process the registers set in an exception handler or the hard
2697 frame pointer if this block is the target of a non local
2698 goto. */
2699 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2701 df_ref def = *def_rec;
2702 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2704 unsigned int dregno = DF_REF_REGNO (def);
2705 unsigned int start = problem_data->regno_start[dregno];
2706 unsigned int len = problem_data->regno_len[dregno];
2707 bitmap_set_range (&bb_info->def, start, len);
2708 bitmap_clear_range (&bb_info->use, start, len);
2712 #ifdef EH_USES
2713 /* Process the uses that are live into an exception handler. */
2714 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2716 df_ref use = *use_rec;
2717 /* Add use to set of uses in this BB. */
2718 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
2720 unsigned int uregno = DF_REF_REGNO (use);
2721 unsigned int start = problem_data->regno_start[uregno];
2722 unsigned int len = problem_data->regno_len[uregno];
2723 bitmap_set_range (&bb_info->use, start, len);
2726 #endif
2730 /* Compute local live register info for each basic block within BLOCKS. */
2732 static void
2733 df_byte_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2735 unsigned int bb_index;
2736 bitmap_iterator bi;
2738 EXECUTE_IF_SET_IN_BITMAP (df_byte_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2740 if (bb_index == EXIT_BLOCK)
2742 /* The exit block is special for this problem and its bits are
2743 computed from thin air. */
2744 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (EXIT_BLOCK);
2745 df_byte_lr_expand_bitmap (&bb_info->use, df->exit_block_uses);
2747 else
2748 df_byte_lr_bb_local_compute (bb_index);
2751 bitmap_clear (df_byte_lr->out_of_date_transfer_functions);
2755 /* Initialize the solution vectors. */
2757 static void
2758 df_byte_lr_init (bitmap all_blocks)
2760 unsigned int bb_index;
2761 bitmap_iterator bi;
2763 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2765 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2766 bitmap_copy (&bb_info->in, &bb_info->use);
2767 bitmap_clear (&bb_info->out);
2772 /* Confluence function that processes infinite loops. This might be a
2773 noreturn function that throws. And even if it isn't, getting the
2774 unwind info right helps debugging. */
2775 static void
2776 df_byte_lr_confluence_0 (basic_block bb)
2778 struct df_byte_lr_problem_data *problem_data
2779 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2780 bitmap op1 = &df_byte_lr_get_bb_info (bb->index)->out;
2781 if (bb != EXIT_BLOCK_PTR)
2782 bitmap_copy (op1, &problem_data->hardware_regs_used);
2786 /* Confluence function that ignores fake edges. */
2788 static void
2789 df_byte_lr_confluence_n (edge e)
2791 struct df_byte_lr_problem_data *problem_data
2792 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2793 bitmap op1 = &df_byte_lr_get_bb_info (e->src->index)->out;
2794 bitmap op2 = &df_byte_lr_get_bb_info (e->dest->index)->in;
2796 /* Call-clobbered registers die across exception and call edges. */
2797 /* ??? Abnormal call edges ignored for the moment, as this gets
2798 confused by sibling call edges, which crashes reg-stack. */
2799 if (e->flags & EDGE_EH)
2800 bitmap_ior_and_compl_into (op1, op2, &problem_data->invalidated_by_call);
2801 else
2802 bitmap_ior_into (op1, op2);
2804 bitmap_ior_into (op1, &problem_data->hardware_regs_used);
2808 /* Transfer function. */
2810 static bool
2811 df_byte_lr_transfer_function (int bb_index)
2813 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2814 bitmap in = &bb_info->in;
2815 bitmap out = &bb_info->out;
2816 bitmap use = &bb_info->use;
2817 bitmap def = &bb_info->def;
2819 return bitmap_ior_and_compl (in, use, out, def);
2823 /* Free all storage associated with the problem. */
2825 static void
2826 df_byte_lr_free (void)
2828 struct df_byte_lr_problem_data *problem_data
2829 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2832 if (df_byte_lr->block_info)
2834 free_alloc_pool (df_byte_lr->block_pool);
2835 df_byte_lr->block_info_size = 0;
2836 free (df_byte_lr->block_info);
2839 BITMAP_FREE (df_byte_lr->out_of_date_transfer_functions);
2840 bitmap_obstack_release (&problem_data->byte_lr_bitmaps);
2841 free (problem_data->regno_start);
2842 free (problem_data->regno_len);
2843 free (problem_data);
2844 free (df_byte_lr);
2848 /* Debugging info at top of bb. */
2850 static void
2851 df_byte_lr_top_dump (basic_block bb, FILE *file)
2853 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb->index);
2854 if (!bb_info)
2855 return;
2857 fprintf (file, ";; blr in \t");
2858 df_print_byte_regset (file, &bb_info->in);
2859 fprintf (file, ";; blr use \t");
2860 df_print_byte_regset (file, &bb_info->use);
2861 fprintf (file, ";; blr def \t");
2862 df_print_byte_regset (file, &bb_info->def);
2866 /* Debugging info at bottom of bb. */
2868 static void
2869 df_byte_lr_bottom_dump (basic_block bb, FILE *file)
2871 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb->index);
2872 if (!bb_info)
2873 return;
2875 fprintf (file, ";; blr out \t");
2876 df_print_byte_regset (file, &bb_info->out);
2880 /* All of the information associated with every instance of the problem. */
2882 static struct df_problem problem_BYTE_LR =
2884 DF_BYTE_LR, /* Problem id. */
2885 DF_BACKWARD, /* Direction. */
2886 df_byte_lr_alloc, /* Allocate the problem specific data. */
2887 df_byte_lr_reset, /* Reset global information. */
2888 df_byte_lr_free_bb_info, /* Free basic block info. */
2889 df_byte_lr_local_compute, /* Local compute function. */
2890 df_byte_lr_init, /* Init the solution specific data. */
2891 df_worklist_dataflow, /* Worklist solver. */
2892 df_byte_lr_confluence_0, /* Confluence operator 0. */
2893 df_byte_lr_confluence_n, /* Confluence operator n. */
2894 df_byte_lr_transfer_function, /* Transfer function. */
2895 NULL, /* Finalize function. */
2896 df_byte_lr_free, /* Free all of the problem information. */
2897 df_byte_lr_free, /* Remove this problem from the stack of dataflow problems. */
2898 NULL, /* Debugging. */
2899 df_byte_lr_top_dump, /* Debugging start block. */
2900 df_byte_lr_bottom_dump, /* Debugging end block. */
2901 NULL, /* Incremental solution verify start. */
2902 NULL, /* Incremental solution verify end. */
2903 NULL, /* Dependent problem. */
2904 TV_DF_BYTE_LR, /* Timing variable. */
2905 false /* Reset blocks on dropping out of blocks_to_analyze. */
2909 /* Create a new DATAFLOW instance and add it to an existing instance
2910 of DF. The returned structure is what is used to get at the
2911 solution. */
2913 void
2914 df_byte_lr_add_problem (void)
2916 df_add_problem (&problem_BYTE_LR);
2917 /* These will be initialized when df_scan_blocks processes each
2918 block. */
2919 df_byte_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2923 /* Simulate the effects of the defs of INSN on LIVE. */
2925 void
2926 df_byte_lr_simulate_defs (rtx insn, bitmap live)
2928 struct df_byte_lr_problem_data *problem_data
2929 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2930 df_ref *def_rec;
2931 unsigned int uid = INSN_UID (insn);
2933 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2935 df_ref def = *def_rec;
2937 /* If the def is to only part of the reg, it does
2938 not kill the other defs that reach here. */
2939 if (!(DF_REF_FLAGS (def) & DF_REF_CONDITIONAL))
2941 unsigned int dregno = DF_REF_REGNO (def);
2942 unsigned int start = problem_data->regno_start[dregno];
2943 unsigned int len = problem_data->regno_len[dregno];
2944 unsigned int sb;
2945 unsigned int lb;
2946 if (!df_compute_accessed_bytes (def, DF_MM_MUST, &sb, &lb))
2948 start += sb;
2949 len = lb - sb;
2952 if (len)
2953 bitmap_clear_range (live, start, len);
2959 /* Simulate the effects of the uses of INSN on LIVE. */
2961 void
2962 df_byte_lr_simulate_uses (rtx insn, bitmap live)
2964 struct df_byte_lr_problem_data *problem_data
2965 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2966 df_ref *use_rec;
2967 unsigned int uid = INSN_UID (insn);
2969 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2971 df_ref use = *use_rec;
2972 unsigned int uregno = DF_REF_REGNO (use);
2973 unsigned int start = problem_data->regno_start[uregno];
2974 unsigned int len = problem_data->regno_len[uregno];
2975 unsigned int sb;
2976 unsigned int lb;
2978 if (!df_compute_accessed_bytes (use, DF_MM_MAY, &sb, &lb))
2980 start += sb;
2981 len = lb - sb;
2984 /* Add use to set of uses in this BB. */
2985 if (len)
2986 bitmap_set_range (live, start, len);
2991 /* Apply the artificial uses and defs at the top of BB in a forwards
2992 direction. */
2994 void
2995 df_byte_lr_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
2997 struct df_byte_lr_problem_data *problem_data
2998 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2999 df_ref *def_rec;
3000 #ifdef EH_USES
3001 df_ref *use_rec;
3002 #endif
3003 int bb_index = bb->index;
3005 #ifdef EH_USES
3006 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3008 df_ref use = *use_rec;
3009 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3011 unsigned int uregno = DF_REF_REGNO (use);
3012 unsigned int start = problem_data->regno_start[uregno];
3013 unsigned int len = problem_data->regno_len[uregno];
3014 bitmap_set_range (live, start, len);
3017 #endif
3019 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3021 df_ref def = *def_rec;
3022 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3024 unsigned int dregno = DF_REF_REGNO (def);
3025 unsigned int start = problem_data->regno_start[dregno];
3026 unsigned int len = problem_data->regno_len[dregno];
3027 bitmap_clear_range (live, start, len);
3033 /* Apply the artificial uses and defs at the end of BB in a backwards
3034 direction. */
3036 void
3037 df_byte_lr_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3039 struct df_byte_lr_problem_data *problem_data
3040 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
3041 df_ref *def_rec;
3042 df_ref *use_rec;
3043 int bb_index = bb->index;
3045 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3047 df_ref def = *def_rec;
3048 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3050 unsigned int dregno = DF_REF_REGNO (def);
3051 unsigned int start = problem_data->regno_start[dregno];
3052 unsigned int len = problem_data->regno_len[dregno];
3053 bitmap_clear_range (live, start, len);
3057 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3059 df_ref use = *use_rec;
3060 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3062 unsigned int uregno = DF_REF_REGNO (use);
3063 unsigned int start = problem_data->regno_start[uregno];
3064 unsigned int len = problem_data->regno_len[uregno];
3065 bitmap_set_range (live, start, len);
3072 /*----------------------------------------------------------------------------
3073 This problem computes REG_DEAD and REG_UNUSED notes.
3074 ----------------------------------------------------------------------------*/
3076 static void
3077 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3079 df_note->optional_p = true;
3082 #ifdef REG_DEAD_DEBUGGING
3083 static void
3084 df_print_note (const char *prefix, rtx insn, rtx note)
3086 if (dump_file)
3088 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
3089 print_rtl (dump_file, note);
3090 fprintf (dump_file, "\n");
3093 #endif
3096 /* After reg-stack, the x86 floating point stack regs are difficult to
3097 analyze because of all of the pushes, pops and rotations. Thus, we
3098 just leave the notes alone. */
3100 #ifdef STACK_REGS
3101 static inline bool
3102 df_ignore_stack_reg (int regno)
3104 return regstack_completed
3105 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
3107 #else
3108 static inline bool
3109 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
3111 return false;
3113 #endif
3116 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
3117 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
3119 static void
3120 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
3122 rtx *pprev = &REG_NOTES (insn);
3123 rtx link = *pprev;
3124 rtx dead = NULL;
3125 rtx unused = NULL;
3127 while (link)
3129 switch (REG_NOTE_KIND (link))
3131 case REG_DEAD:
3132 /* After reg-stack, we need to ignore any unused notes
3133 for the stack registers. */
3134 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3136 pprev = &XEXP (link, 1);
3137 link = *pprev;
3139 else
3141 rtx next = XEXP (link, 1);
3142 #ifdef REG_DEAD_DEBUGGING
3143 df_print_note ("deleting: ", insn, link);
3144 #endif
3145 XEXP (link, 1) = dead;
3146 dead = link;
3147 *pprev = link = next;
3149 break;
3151 case REG_UNUSED:
3152 /* After reg-stack, we need to ignore any unused notes
3153 for the stack registers. */
3154 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3156 pprev = &XEXP (link, 1);
3157 link = *pprev;
3159 else
3161 rtx next = XEXP (link, 1);
3162 #ifdef REG_DEAD_DEBUGGING
3163 df_print_note ("deleting: ", insn, link);
3164 #endif
3165 XEXP (link, 1) = unused;
3166 unused = link;
3167 *pprev = link = next;
3169 break;
3171 default:
3172 pprev = &XEXP (link, 1);
3173 link = *pprev;
3174 break;
3178 *old_dead_notes = dead;
3179 *old_unused_notes = unused;
3183 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
3184 list, otherwise create a new one. */
3186 static inline rtx
3187 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
3189 rtx curr = old;
3190 rtx prev = NULL;
3192 gcc_assert (!DEBUG_INSN_P (insn));
3194 while (curr)
3195 if (XEXP (curr, 0) == reg)
3197 if (prev)
3198 XEXP (prev, 1) = XEXP (curr, 1);
3199 else
3200 old = XEXP (curr, 1);
3201 XEXP (curr, 1) = REG_NOTES (insn);
3202 REG_NOTES (insn) = curr;
3203 return old;
3205 else
3207 prev = curr;
3208 curr = XEXP (curr, 1);
3211 /* Did not find the note. */
3212 add_reg_note (insn, note_type, reg);
3213 return old;
3216 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
3217 arguments. Return true if the register value described by MWS's
3218 mw_reg is known to be completely unused, and if mw_reg can therefore
3219 be used in a REG_UNUSED note. */
3221 static bool
3222 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
3223 bitmap live, bitmap artificial_uses)
3225 unsigned int r;
3227 /* If MWS describes a partial reference, create REG_UNUSED notes for
3228 individual hard registers. */
3229 if (mws->flags & DF_REF_PARTIAL)
3230 return false;
3232 /* Likewise if some part of the register is used. */
3233 for (r = mws->start_regno; r <= mws->end_regno; r++)
3234 if (bitmap_bit_p (live, r)
3235 || bitmap_bit_p (artificial_uses, r))
3236 return false;
3238 gcc_assert (REG_P (mws->mw_reg));
3239 return true;
3242 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
3243 based on the bits in LIVE. Do not generate notes for registers in
3244 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
3245 not generated if the reg is both read and written by the
3246 instruction.
3249 static rtx
3250 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3251 bitmap live, bitmap do_not_gen,
3252 bitmap artificial_uses)
3254 unsigned int r;
3256 #ifdef REG_DEAD_DEBUGGING
3257 if (dump_file)
3258 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
3259 mws->start_regno, mws->end_regno);
3260 #endif
3262 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
3264 unsigned int regno = mws->start_regno;
3265 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
3267 #ifdef REG_DEAD_DEBUGGING
3268 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3269 #endif
3270 bitmap_set_bit (do_not_gen, regno);
3271 /* Only do this if the value is totally dead. */
3273 else
3274 for (r = mws->start_regno; r <= mws->end_regno; r++)
3276 if (!bitmap_bit_p (live, r)
3277 && !bitmap_bit_p (artificial_uses, r))
3279 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
3280 #ifdef REG_DEAD_DEBUGGING
3281 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3282 #endif
3284 bitmap_set_bit (do_not_gen, r);
3286 return old;
3290 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
3291 arguments. Return true if the register value described by MWS's
3292 mw_reg is known to be completely dead, and if mw_reg can therefore
3293 be used in a REG_DEAD note. */
3295 static bool
3296 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
3297 bitmap live, bitmap artificial_uses,
3298 bitmap do_not_gen)
3300 unsigned int r;
3302 /* If MWS describes a partial reference, create REG_DEAD notes for
3303 individual hard registers. */
3304 if (mws->flags & DF_REF_PARTIAL)
3305 return false;
3307 /* Likewise if some part of the register is not dead. */
3308 for (r = mws->start_regno; r <= mws->end_regno; r++)
3309 if (bitmap_bit_p (live, r)
3310 || bitmap_bit_p (artificial_uses, r)
3311 || bitmap_bit_p (do_not_gen, r))
3312 return false;
3314 gcc_assert (REG_P (mws->mw_reg));
3315 return true;
3318 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3319 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3320 from being set if the instruction both reads and writes the
3321 register. */
3323 static rtx
3324 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3325 bitmap live, bitmap do_not_gen,
3326 bitmap artificial_uses, bool *added_notes_p)
3328 unsigned int r;
3329 bool is_debug = *added_notes_p;
3331 *added_notes_p = false;
3333 #ifdef REG_DEAD_DEBUGGING
3334 if (dump_file)
3336 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3337 mws->start_regno, mws->end_regno);
3338 df_print_regset (dump_file, do_not_gen);
3339 fprintf (dump_file, " live =");
3340 df_print_regset (dump_file, live);
3341 fprintf (dump_file, " artificial uses =");
3342 df_print_regset (dump_file, artificial_uses);
3344 #endif
3346 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
3348 /* Add a dead note for the entire multi word register. */
3349 if (is_debug)
3351 *added_notes_p = true;
3352 return old;
3354 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
3355 #ifdef REG_DEAD_DEBUGGING
3356 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3357 #endif
3359 else
3361 for (r = mws->start_regno; r <= mws->end_regno; r++)
3362 if (!bitmap_bit_p (live, r)
3363 && !bitmap_bit_p (artificial_uses, r)
3364 && !bitmap_bit_p (do_not_gen, r))
3366 if (is_debug)
3368 *added_notes_p = true;
3369 return old;
3371 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
3372 #ifdef REG_DEAD_DEBUGGING
3373 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3374 #endif
3377 return old;
3381 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3382 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3384 static rtx
3385 df_create_unused_note (rtx insn, rtx old, df_ref def,
3386 bitmap live, bitmap artificial_uses)
3388 unsigned int dregno = DF_REF_REGNO (def);
3390 #ifdef REG_DEAD_DEBUGGING
3391 if (dump_file)
3393 fprintf (dump_file, " regular looking at def ");
3394 df_ref_debug (def, dump_file);
3396 #endif
3398 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3399 || bitmap_bit_p (live, dregno)
3400 || bitmap_bit_p (artificial_uses, dregno)
3401 || df_ignore_stack_reg (dregno)))
3403 rtx reg = (DF_REF_LOC (def))
3404 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3405 old = df_set_note (REG_UNUSED, insn, old, reg);
3406 #ifdef REG_DEAD_DEBUGGING
3407 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3408 #endif
3411 return old;
3414 /* Node of a linked list of uses of dead REGs in debug insns. */
3415 struct dead_debug_use
3417 df_ref use;
3418 struct dead_debug_use *next;
3421 /* Linked list of the above, with a bitmap of the REGs in the
3422 list. */
3423 struct dead_debug
3425 struct dead_debug_use *head;
3426 bitmap used;
3427 bitmap to_rescan;
3430 /* Initialize DEBUG to an empty list, and clear USED, if given. */
3431 static inline void
3432 dead_debug_init (struct dead_debug *debug, bitmap used)
3434 debug->head = NULL;
3435 debug->used = used;
3436 debug->to_rescan = NULL;
3437 if (used)
3438 bitmap_clear (used);
3441 /* Reset all debug insns with pending uses. Release the bitmap in it,
3442 unless it is USED. USED must be the same bitmap passed to
3443 dead_debug_init. */
3444 static inline void
3445 dead_debug_finish (struct dead_debug *debug, bitmap used)
3447 struct dead_debug_use *head;
3448 rtx insn = NULL;
3450 if (debug->used != used)
3451 BITMAP_FREE (debug->used);
3453 while ((head = debug->head))
3455 insn = DF_REF_INSN (head->use);
3456 if (!head->next || DF_REF_INSN (head->next->use) != insn)
3458 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3459 df_insn_rescan_debug_internal (insn);
3460 if (debug->to_rescan)
3461 bitmap_clear_bit (debug->to_rescan, INSN_UID (insn));
3463 debug->head = head->next;
3464 XDELETE (head);
3467 if (debug->to_rescan)
3469 bitmap_iterator bi;
3470 unsigned int uid;
3472 EXECUTE_IF_SET_IN_BITMAP (debug->to_rescan, 0, uid, bi)
3474 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
3475 if (insn_info)
3476 df_insn_rescan (insn_info->insn);
3478 BITMAP_FREE (debug->to_rescan);
3482 /* Add USE to DEBUG. It must be a dead reference to UREGNO in a debug
3483 insn. Create a bitmap for DEBUG as needed. */
3484 static inline void
3485 dead_debug_add (struct dead_debug *debug, df_ref use, unsigned int uregno)
3487 struct dead_debug_use *newddu = XNEW (struct dead_debug_use);
3489 newddu->use = use;
3490 newddu->next = debug->head;
3491 debug->head = newddu;
3493 if (!debug->used)
3494 debug->used = BITMAP_ALLOC (NULL);
3496 bitmap_set_bit (debug->used, uregno);
3499 /* If UREGNO is referenced by any entry in DEBUG, emit a debug insn
3500 before INSN that binds the REG to a debug temp, and replace all
3501 uses of UREGNO in DEBUG with uses of the debug temp. INSN must be
3502 the insn where UREGNO dies. */
3503 static inline void
3504 dead_debug_insert_before (struct dead_debug *debug, unsigned int uregno,
3505 rtx insn)
3507 struct dead_debug_use **tailp = &debug->head;
3508 struct dead_debug_use *cur;
3509 struct dead_debug_use *uses = NULL;
3510 struct dead_debug_use **usesp = &uses;
3511 rtx reg = NULL;
3512 rtx dval;
3513 rtx bind;
3515 if (!debug->used || !bitmap_clear_bit (debug->used, uregno))
3516 return;
3518 /* Move all uses of uregno from debug->head to uses, setting mode to
3519 the widest referenced mode. */
3520 while ((cur = *tailp))
3522 if (DF_REF_REGNO (cur->use) == uregno)
3524 *usesp = cur;
3525 usesp = &cur->next;
3526 *tailp = cur->next;
3527 cur->next = NULL;
3528 if (!reg
3529 || (GET_MODE_BITSIZE (GET_MODE (reg))
3530 < GET_MODE_BITSIZE (GET_MODE (*DF_REF_REAL_LOC (cur->use)))))
3531 reg = *DF_REF_REAL_LOC (cur->use);
3533 else
3534 tailp = &(*tailp)->next;
3537 gcc_assert (reg);
3539 /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
3540 dval = make_debug_expr_from_rtl (reg);
3542 /* Emit a debug bind insn before the insn in which reg dies. */
3543 bind = gen_rtx_VAR_LOCATION (GET_MODE (reg),
3544 DEBUG_EXPR_TREE_DECL (dval), reg,
3545 VAR_INIT_STATUS_INITIALIZED);
3547 bind = emit_debug_insn_before (bind, insn);
3548 df_insn_rescan (bind);
3550 /* Adjust all uses. */
3551 while ((cur = uses))
3553 if (GET_MODE (*DF_REF_REAL_LOC (cur->use)) == GET_MODE (reg))
3554 *DF_REF_REAL_LOC (cur->use) = dval;
3555 else
3556 *DF_REF_REAL_LOC (cur->use)
3557 = gen_lowpart_SUBREG (GET_MODE (*DF_REF_REAL_LOC (cur->use)), dval);
3558 /* ??? Should we simplify subreg of subreg? */
3559 if (debug->to_rescan == NULL)
3560 debug->to_rescan = BITMAP_ALLOC (NULL);
3561 bitmap_set_bit (debug->to_rescan, INSN_UID (DF_REF_INSN (cur->use)));
3562 uses = cur->next;
3563 XDELETE (cur);
3567 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3568 info: lifetime, bb, and number of defs and uses for basic block
3569 BB. The three bitvectors are scratch regs used here. */
3571 static void
3572 df_note_bb_compute (unsigned int bb_index,
3573 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3575 basic_block bb = BASIC_BLOCK (bb_index);
3576 rtx insn;
3577 df_ref *def_rec;
3578 df_ref *use_rec;
3579 struct dead_debug debug;
3581 dead_debug_init (&debug, NULL);
3583 bitmap_copy (live, df_get_live_out (bb));
3584 bitmap_clear (artificial_uses);
3586 #ifdef REG_DEAD_DEBUGGING
3587 if (dump_file)
3589 fprintf (dump_file, "live at bottom ");
3590 df_print_regset (dump_file, live);
3592 #endif
3594 /* Process the artificial defs and uses at the bottom of the block
3595 to begin processing. */
3596 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3598 df_ref def = *def_rec;
3599 #ifdef REG_DEAD_DEBUGGING
3600 if (dump_file)
3601 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3602 #endif
3604 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3605 bitmap_clear_bit (live, DF_REF_REGNO (def));
3608 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3610 df_ref use = *use_rec;
3611 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3613 unsigned int regno = DF_REF_REGNO (use);
3614 bitmap_set_bit (live, regno);
3616 /* Notes are not generated for any of the artificial registers
3617 at the bottom of the block. */
3618 bitmap_set_bit (artificial_uses, regno);
3622 #ifdef REG_DEAD_DEBUGGING
3623 if (dump_file)
3625 fprintf (dump_file, "live before artificials out ");
3626 df_print_regset (dump_file, live);
3628 #endif
3630 FOR_BB_INSNS_REVERSE (bb, insn)
3632 unsigned int uid = INSN_UID (insn);
3633 struct df_mw_hardreg **mws_rec;
3634 rtx old_dead_notes;
3635 rtx old_unused_notes;
3636 int debug_insn;
3638 if (!INSN_P (insn))
3639 continue;
3641 debug_insn = DEBUG_INSN_P (insn);
3643 bitmap_clear (do_not_gen);
3644 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
3646 /* Process the defs. */
3647 if (CALL_P (insn))
3649 #ifdef REG_DEAD_DEBUGGING
3650 if (dump_file)
3652 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3653 df_print_regset (dump_file, live);
3655 #endif
3656 /* We only care about real sets for calls. Clobbers cannot
3657 be depended on to really die. */
3658 mws_rec = DF_INSN_UID_MWS (uid);
3659 while (*mws_rec)
3661 struct df_mw_hardreg *mws = *mws_rec;
3662 if ((DF_MWS_REG_DEF_P (mws))
3663 && !df_ignore_stack_reg (mws->start_regno))
3664 old_unused_notes
3665 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3666 mws, live, do_not_gen,
3667 artificial_uses);
3668 mws_rec++;
3671 /* All of the defs except the return value are some sort of
3672 clobber. This code is for the return. */
3673 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3675 df_ref def = *def_rec;
3676 unsigned int dregno = DF_REF_REGNO (def);
3677 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3679 old_unused_notes
3680 = df_create_unused_note (insn, old_unused_notes,
3681 def, live, artificial_uses);
3682 bitmap_set_bit (do_not_gen, dregno);
3685 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3686 bitmap_clear_bit (live, dregno);
3689 else
3691 /* Regular insn. */
3692 mws_rec = DF_INSN_UID_MWS (uid);
3693 while (*mws_rec)
3695 struct df_mw_hardreg *mws = *mws_rec;
3696 if (DF_MWS_REG_DEF_P (mws))
3697 old_unused_notes
3698 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3699 mws, live, do_not_gen,
3700 artificial_uses);
3701 mws_rec++;
3704 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3706 df_ref def = *def_rec;
3707 unsigned int dregno = DF_REF_REGNO (def);
3708 old_unused_notes
3709 = df_create_unused_note (insn, old_unused_notes,
3710 def, live, artificial_uses);
3712 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3713 bitmap_set_bit (do_not_gen, dregno);
3715 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3716 bitmap_clear_bit (live, dregno);
3720 /* Process the uses. */
3721 mws_rec = DF_INSN_UID_MWS (uid);
3722 while (*mws_rec)
3724 struct df_mw_hardreg *mws = *mws_rec;
3725 if ((DF_MWS_REG_DEF_P (mws))
3726 && !df_ignore_stack_reg (mws->start_regno))
3728 bool really_add_notes = debug_insn != 0;
3730 old_dead_notes
3731 = df_set_dead_notes_for_mw (insn, old_dead_notes,
3732 mws, live, do_not_gen,
3733 artificial_uses,
3734 &really_add_notes);
3736 if (really_add_notes)
3737 debug_insn = -1;
3739 mws_rec++;
3742 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3744 df_ref use = *use_rec;
3745 unsigned int uregno = DF_REF_REGNO (use);
3747 #ifdef REG_DEAD_DEBUGGING
3748 if (dump_file && !debug_insn)
3750 fprintf (dump_file, " regular looking at use ");
3751 df_ref_debug (use, dump_file);
3753 #endif
3754 if (!bitmap_bit_p (live, uregno))
3756 if (debug_insn)
3758 if (debug_insn > 0)
3760 dead_debug_add (&debug, use, uregno);
3761 continue;
3763 break;
3765 else
3766 dead_debug_insert_before (&debug, uregno, insn);
3768 if ( (!(DF_REF_FLAGS (use)
3769 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3770 && (!bitmap_bit_p (do_not_gen, uregno))
3771 && (!bitmap_bit_p (artificial_uses, uregno))
3772 && (!df_ignore_stack_reg (uregno)))
3774 rtx reg = (DF_REF_LOC (use))
3775 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3776 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
3778 #ifdef REG_DEAD_DEBUGGING
3779 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3780 #endif
3782 /* This register is now live. */
3783 bitmap_set_bit (live, uregno);
3787 while (old_unused_notes)
3789 rtx next = XEXP (old_unused_notes, 1);
3790 free_EXPR_LIST_node (old_unused_notes);
3791 old_unused_notes = next;
3793 while (old_dead_notes)
3795 rtx next = XEXP (old_dead_notes, 1);
3796 free_EXPR_LIST_node (old_dead_notes);
3797 old_dead_notes = next;
3800 if (debug_insn == -1)
3802 /* ??? We could probably do better here, replacing dead
3803 registers with their definitions. */
3804 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3805 df_insn_rescan_debug_internal (insn);
3809 dead_debug_finish (&debug, NULL);
3813 /* Compute register info: lifetime, bb, and number of defs and uses. */
3814 static void
3815 df_note_compute (bitmap all_blocks)
3817 unsigned int bb_index;
3818 bitmap_iterator bi;
3819 bitmap_head live, do_not_gen, artificial_uses;
3821 bitmap_initialize (&live, &df_bitmap_obstack);
3822 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3823 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3825 #ifdef REG_DEAD_DEBUGGING
3826 if (dump_file)
3827 print_rtl_with_bb (dump_file, get_insns());
3828 #endif
3830 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3832 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3835 bitmap_clear (&live);
3836 bitmap_clear (&do_not_gen);
3837 bitmap_clear (&artificial_uses);
3841 /* Free all storage associated with the problem. */
3843 static void
3844 df_note_free (void)
3846 free (df_note);
3850 /* All of the information associated every instance of the problem. */
3852 static struct df_problem problem_NOTE =
3854 DF_NOTE, /* Problem id. */
3855 DF_NONE, /* Direction. */
3856 df_note_alloc, /* Allocate the problem specific data. */
3857 NULL, /* Reset global information. */
3858 NULL, /* Free basic block info. */
3859 df_note_compute, /* Local compute function. */
3860 NULL, /* Init the solution specific data. */
3861 NULL, /* Iterative solver. */
3862 NULL, /* Confluence operator 0. */
3863 NULL, /* Confluence operator n. */
3864 NULL, /* Transfer function. */
3865 NULL, /* Finalize function. */
3866 df_note_free, /* Free all of the problem information. */
3867 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3868 NULL, /* Debugging. */
3869 NULL, /* Debugging start block. */
3870 NULL, /* Debugging end block. */
3871 NULL, /* Incremental solution verify start. */
3872 NULL, /* Incremental solution verify end. */
3873 &problem_LR, /* Dependent problem. */
3874 TV_DF_NOTE, /* Timing variable. */
3875 false /* Reset blocks on dropping out of blocks_to_analyze. */
3879 /* Create a new DATAFLOW instance and add it to an existing instance
3880 of DF. The returned structure is what is used to get at the
3881 solution. */
3883 void
3884 df_note_add_problem (void)
3886 df_add_problem (&problem_NOTE);
3892 /*----------------------------------------------------------------------------
3893 Functions for simulating the effects of single insns.
3895 You can either simulate in the forwards direction, starting from
3896 the top of a block or the backwards direction from the end of the
3897 block. If you go backwards, defs are examined first to clear bits,
3898 then uses are examined to set bits. If you go forwards, defs are
3899 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3900 are examined to clear bits. In either case, the result of examining
3901 a def can be undone (respectively by a use or a REG_UNUSED note).
3903 If you start at the top of the block, use one of DF_LIVE_IN or
3904 DF_LR_IN. If you start at the bottom of the block use one of
3905 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3906 THEY WILL BE DESTROYED.
3907 ----------------------------------------------------------------------------*/
3910 /* Find the set of DEFs for INSN. */
3912 void
3913 df_simulate_find_defs (rtx insn, bitmap defs)
3915 df_ref *def_rec;
3916 unsigned int uid = INSN_UID (insn);
3918 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3920 df_ref def = *def_rec;
3921 bitmap_set_bit (defs, DF_REF_REGNO (def));
3925 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3927 void
3928 df_simulate_find_noclobber_defs (rtx insn, bitmap defs)
3930 df_ref *def_rec;
3931 unsigned int uid = INSN_UID (insn);
3933 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3935 df_ref def = *def_rec;
3936 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3937 bitmap_set_bit (defs, DF_REF_REGNO (def));
3942 /* Simulate the effects of the defs of INSN on LIVE. */
3944 void
3945 df_simulate_defs (rtx insn, bitmap live)
3947 df_ref *def_rec;
3948 unsigned int uid = INSN_UID (insn);
3950 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3952 df_ref def = *def_rec;
3953 unsigned int dregno = DF_REF_REGNO (def);
3955 /* If the def is to only part of the reg, it does
3956 not kill the other defs that reach here. */
3957 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3958 bitmap_clear_bit (live, dregno);
3963 /* Simulate the effects of the uses of INSN on LIVE. */
3965 void
3966 df_simulate_uses (rtx insn, bitmap live)
3968 df_ref *use_rec;
3969 unsigned int uid = INSN_UID (insn);
3971 if (DEBUG_INSN_P (insn))
3972 return;
3974 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3976 df_ref use = *use_rec;
3977 /* Add use to set of uses in this BB. */
3978 bitmap_set_bit (live, DF_REF_REGNO (use));
3983 /* Add back the always live regs in BB to LIVE. */
3985 static inline void
3986 df_simulate_fixup_sets (basic_block bb, bitmap live)
3988 /* These regs are considered always live so if they end up dying
3989 because of some def, we need to bring the back again. */
3990 if (bb_has_eh_pred (bb))
3991 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3992 else
3993 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3997 /*----------------------------------------------------------------------------
3998 The following three functions are used only for BACKWARDS scanning:
3999 i.e. they process the defs before the uses.
4001 df_simulate_initialize_backwards should be called first with a
4002 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
4003 df_simulate_one_insn_backwards should be called for each insn in
4004 the block, starting with the last one. Finally,
4005 df_simulate_finalize_backwards can be called to get a new value
4006 of the sets at the top of the block (this is rarely used).
4007 ----------------------------------------------------------------------------*/
4009 /* Apply the artificial uses and defs at the end of BB in a backwards
4010 direction. */
4012 void
4013 df_simulate_initialize_backwards (basic_block bb, bitmap live)
4015 df_ref *def_rec;
4016 df_ref *use_rec;
4017 int bb_index = bb->index;
4019 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4021 df_ref def = *def_rec;
4022 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
4023 bitmap_clear_bit (live, DF_REF_REGNO (def));
4026 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4028 df_ref use = *use_rec;
4029 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
4030 bitmap_set_bit (live, DF_REF_REGNO (use));
4035 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
4037 void
4038 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
4040 if (!NONDEBUG_INSN_P (insn))
4041 return;
4043 df_simulate_defs (insn, live);
4044 df_simulate_uses (insn, live);
4045 df_simulate_fixup_sets (bb, live);
4049 /* Apply the artificial uses and defs at the top of BB in a backwards
4050 direction. */
4052 void
4053 df_simulate_finalize_backwards (basic_block bb, bitmap live)
4055 df_ref *def_rec;
4056 #ifdef EH_USES
4057 df_ref *use_rec;
4058 #endif
4059 int bb_index = bb->index;
4061 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4063 df_ref def = *def_rec;
4064 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4065 bitmap_clear_bit (live, DF_REF_REGNO (def));
4068 #ifdef EH_USES
4069 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4071 df_ref use = *use_rec;
4072 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
4073 bitmap_set_bit (live, DF_REF_REGNO (use));
4075 #endif
4077 /*----------------------------------------------------------------------------
4078 The following three functions are used only for FORWARDS scanning:
4079 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
4080 Thus it is important to add the DF_NOTES problem to the stack of
4081 problems computed before using these functions.
4083 df_simulate_initialize_forwards should be called first with a
4084 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
4085 df_simulate_one_insn_forwards should be called for each insn in
4086 the block, starting with the first one.
4087 ----------------------------------------------------------------------------*/
4089 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
4090 DF_LR_IN for basic block BB, for forward scanning by marking artificial
4091 defs live. */
4093 void
4094 df_simulate_initialize_forwards (basic_block bb, bitmap live)
4096 df_ref *def_rec;
4097 int bb_index = bb->index;
4099 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4101 df_ref def = *def_rec;
4102 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4103 bitmap_set_bit (live, DF_REF_REGNO (def));
4107 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
4109 void
4110 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
4112 rtx link;
4113 if (! INSN_P (insn))
4114 return;
4116 /* Make sure that DF_NOTE really is an active df problem. */
4117 gcc_assert (df_note);
4119 /* Note that this is the opposite as how the problem is defined, because
4120 in the LR problem defs _kill_ liveness. However, they do so backwards,
4121 while here the scan is performed forwards! So, first assume that the
4122 def is live, and if this is not true REG_UNUSED notes will rectify the
4123 situation. */
4124 df_simulate_find_noclobber_defs (insn, live);
4126 /* Clear all of the registers that go dead. */
4127 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
4129 switch (REG_NOTE_KIND (link))
4131 case REG_DEAD:
4132 case REG_UNUSED:
4134 rtx reg = XEXP (link, 0);
4135 int regno = REGNO (reg);
4136 if (regno < FIRST_PSEUDO_REGISTER)
4138 int n = hard_regno_nregs[regno][GET_MODE (reg)];
4139 while (--n >= 0)
4140 bitmap_clear_bit (live, regno + n);
4142 else
4143 bitmap_clear_bit (live, regno);
4145 break;
4146 default:
4147 break;
4150 df_simulate_fixup_sets (bb, live);
4155 /*----------------------------------------------------------------------------
4156 MULTIPLE DEFINITIONS
4158 Find the locations in the function reached by multiple definition sites
4159 for a live pseudo. In and out bitvectors are built for each basic
4160 block. They are restricted for efficiency to live registers.
4162 The gen and kill sets for the problem are obvious. Together they
4163 include all defined registers in a basic block; the gen set includes
4164 registers where a partial or conditional or may-clobber definition is
4165 last in the BB, while the kill set includes registers with a complete
4166 definition coming last. However, the computation of the dataflow
4167 itself is interesting.
4169 The idea behind it comes from SSA form's iterated dominance frontier
4170 criterion for inserting PHI functions. Just like in that case, we can use
4171 the dominance frontier to find places where multiple definitions meet;
4172 a register X defined in a basic block BB1 has multiple definitions in
4173 basic blocks in BB1's dominance frontier.
4175 So, the in-set of a basic block BB2 is not just the union of the
4176 out-sets of BB2's predecessors, but includes some more bits that come
4177 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
4178 the previous paragraph). I called this set the init-set of BB2.
4180 (Note: I actually use the kill-set only to build the init-set.
4181 gen bits are anyway propagated from BB1 to BB2 by dataflow).
4183 For example, if you have
4185 BB1 : r10 = 0
4186 r11 = 0
4187 if <...> goto BB2 else goto BB3;
4189 BB2 : r10 = 1
4190 r12 = 1
4191 goto BB3;
4193 BB3 :
4195 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
4196 init-set of BB3 includes r10 and r12, but not r11. Note that we do
4197 not need to iterate the dominance frontier, because we do not insert
4198 anything like PHI functions there! Instead, dataflow will take care of
4199 propagating the information to BB3's successors.
4200 ---------------------------------------------------------------------------*/
4202 /* Scratch var used by transfer functions. This is used to do md analysis
4203 only for live registers. */
4204 static bitmap_head df_md_scratch;
4206 /* Set basic block info. */
4208 static void
4209 df_md_set_bb_info (unsigned int index,
4210 struct df_md_bb_info *bb_info)
4212 gcc_assert (df_md);
4213 gcc_assert (index < df_md->block_info_size);
4214 df_md->block_info[index] = bb_info;
4218 static void
4219 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
4220 void *vbb_info)
4222 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
4223 if (bb_info)
4225 bitmap_clear (&bb_info->kill);
4226 bitmap_clear (&bb_info->gen);
4227 bitmap_clear (&bb_info->init);
4228 bitmap_clear (&bb_info->in);
4229 bitmap_clear (&bb_info->out);
4230 pool_free (df_md->block_pool, bb_info);
4235 /* Allocate or reset bitmaps for DF_MD. The solution bits are
4236 not touched unless the block is new. */
4238 static void
4239 df_md_alloc (bitmap all_blocks)
4241 unsigned int bb_index;
4242 bitmap_iterator bi;
4244 if (!df_md->block_pool)
4245 df_md->block_pool = create_alloc_pool ("df_md_block pool",
4246 sizeof (struct df_md_bb_info), 50);
4248 df_grow_bb_info (df_md);
4249 bitmap_initialize (&df_md_scratch, &bitmap_default_obstack);
4251 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4253 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4254 if (bb_info)
4256 bitmap_clear (&bb_info->init);
4257 bitmap_clear (&bb_info->gen);
4258 bitmap_clear (&bb_info->kill);
4259 bitmap_clear (&bb_info->in);
4260 bitmap_clear (&bb_info->out);
4262 else
4264 bb_info = (struct df_md_bb_info *) pool_alloc (df_md->block_pool);
4265 df_md_set_bb_info (bb_index, bb_info);
4266 bitmap_initialize (&bb_info->init, &bitmap_default_obstack);
4267 bitmap_initialize (&bb_info->gen, &bitmap_default_obstack);
4268 bitmap_initialize (&bb_info->kill, &bitmap_default_obstack);
4269 bitmap_initialize (&bb_info->in, &bitmap_default_obstack);
4270 bitmap_initialize (&bb_info->out, &bitmap_default_obstack);
4274 df_md->optional_p = true;
4277 /* Add the effect of the top artificial defs of BB to the multiple definitions
4278 bitmap LOCAL_MD. */
4280 void
4281 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4283 int bb_index = bb->index;
4284 df_ref *def_rec;
4285 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4287 df_ref def = *def_rec;
4288 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4290 unsigned int dregno = DF_REF_REGNO (def);
4291 if (DF_REF_FLAGS (def)
4292 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4293 bitmap_set_bit (local_md, dregno);
4294 else
4295 bitmap_clear_bit (local_md, dregno);
4301 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4302 LOCAL_MD. */
4304 void
4305 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
4306 bitmap local_md)
4308 unsigned uid = INSN_UID (insn);
4309 df_ref *def_rec;
4311 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4313 df_ref def = *def_rec;
4314 unsigned int dregno = DF_REF_REGNO (def);
4315 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4316 || (dregno >= FIRST_PSEUDO_REGISTER))
4318 if (DF_REF_FLAGS (def)
4319 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4320 bitmap_set_bit (local_md, DF_REF_ID (def));
4321 else
4322 bitmap_clear_bit (local_md, DF_REF_ID (def));
4327 static void
4328 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
4329 df_ref *def_rec,
4330 int top_flag)
4332 df_ref def;
4333 bitmap_clear (&seen_in_insn);
4335 while ((def = *def_rec++) != NULL)
4337 unsigned int dregno = DF_REF_REGNO (def);
4338 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4339 || (dregno >= FIRST_PSEUDO_REGISTER))
4340 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4342 if (!bitmap_bit_p (&seen_in_insn, dregno))
4344 if (DF_REF_FLAGS (def)
4345 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4347 bitmap_set_bit (&bb_info->gen, dregno);
4348 bitmap_clear_bit (&bb_info->kill, dregno);
4350 else
4352 /* When we find a clobber and a regular def,
4353 make sure the regular def wins. */
4354 bitmap_set_bit (&seen_in_insn, dregno);
4355 bitmap_set_bit (&bb_info->kill, dregno);
4356 bitmap_clear_bit (&bb_info->gen, dregno);
4364 /* Compute local multiple def info for basic block BB. */
4366 static void
4367 df_md_bb_local_compute (unsigned int bb_index)
4369 basic_block bb = BASIC_BLOCK (bb_index);
4370 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4371 rtx insn;
4373 /* Artificials are only hard regs. */
4374 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4375 df_md_bb_local_compute_process_def (bb_info,
4376 df_get_artificial_defs (bb_index),
4377 DF_REF_AT_TOP);
4379 FOR_BB_INSNS (bb, insn)
4381 unsigned int uid = INSN_UID (insn);
4382 if (!INSN_P (insn))
4383 continue;
4385 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4388 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4389 df_md_bb_local_compute_process_def (bb_info,
4390 df_get_artificial_defs (bb_index),
4394 /* Compute local reaching def info for each basic block within BLOCKS. */
4396 static void
4397 df_md_local_compute (bitmap all_blocks)
4399 unsigned int bb_index, df_bb_index;
4400 bitmap_iterator bi1, bi2;
4401 basic_block bb;
4402 bitmap_head *frontiers;
4404 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4406 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4408 df_md_bb_local_compute (bb_index);
4411 bitmap_clear (&seen_in_insn);
4413 frontiers = XNEWVEC (bitmap_head, last_basic_block);
4414 FOR_ALL_BB (bb)
4415 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4417 compute_dominance_frontiers (frontiers);
4419 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4420 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4422 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4423 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4425 basic_block bb = BASIC_BLOCK (df_bb_index);
4426 if (bitmap_bit_p (all_blocks, df_bb_index))
4427 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4428 df_get_live_in (bb));
4432 FOR_ALL_BB (bb)
4433 bitmap_clear (&frontiers[bb->index]);
4434 free (frontiers);
4438 /* Reset the global solution for recalculation. */
4440 static void
4441 df_md_reset (bitmap all_blocks)
4443 unsigned int bb_index;
4444 bitmap_iterator bi;
4446 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4448 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4449 gcc_assert (bb_info);
4450 bitmap_clear (&bb_info->in);
4451 bitmap_clear (&bb_info->out);
4455 static bool
4456 df_md_transfer_function (int bb_index)
4458 basic_block bb = BASIC_BLOCK (bb_index);
4459 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4460 bitmap in = &bb_info->in;
4461 bitmap out = &bb_info->out;
4462 bitmap gen = &bb_info->gen;
4463 bitmap kill = &bb_info->kill;
4465 /* We need to use a scratch set here so that the value returned from this
4466 function invocation properly reflects whether the sets changed in a
4467 significant way; i.e. not just because the live set was anded in. */
4468 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4470 /* Multiple definitions of a register are not relevant if it is not
4471 live. Thus we trim the result to the places where it is live. */
4472 bitmap_and_into (in, df_get_live_in (bb));
4474 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4477 /* Initialize the solution bit vectors for problem. */
4479 static void
4480 df_md_init (bitmap all_blocks)
4482 unsigned int bb_index;
4483 bitmap_iterator bi;
4485 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4487 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4489 bitmap_copy (&bb_info->in, &bb_info->init);
4490 df_md_transfer_function (bb_index);
4494 static void
4495 df_md_confluence_0 (basic_block bb)
4497 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4498 bitmap_copy (&bb_info->in, &bb_info->init);
4501 /* In of target gets or of out of source. */
4503 static void
4504 df_md_confluence_n (edge e)
4506 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4507 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4509 if (e->flags & EDGE_FAKE)
4510 return;
4512 if (e->flags & EDGE_EH)
4513 bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
4514 else
4515 bitmap_ior_into (op1, op2);
4518 /* Free all storage associated with the problem. */
4520 static void
4521 df_md_free (void)
4523 unsigned int i;
4524 for (i = 0; i < df_md->block_info_size; i++)
4526 struct df_md_bb_info *bb_info = df_md_get_bb_info (i);
4527 if (bb_info)
4529 bitmap_clear (&bb_info->kill);
4530 bitmap_clear (&bb_info->gen);
4531 bitmap_clear (&bb_info->init);
4532 bitmap_clear (&bb_info->in);
4533 bitmap_clear (&bb_info->out);
4537 bitmap_clear (&df_md_scratch);
4538 free_alloc_pool (df_md->block_pool);
4540 df_md->block_info_size = 0;
4541 free (df_md->block_info);
4542 free (df_md);
4546 /* Debugging info at top of bb. */
4548 static void
4549 df_md_top_dump (basic_block bb, FILE *file)
4551 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4552 if (!bb_info)
4553 return;
4555 fprintf (file, ";; md in \t");
4556 df_print_regset (file, &bb_info->in);
4557 fprintf (file, ";; md init \t");
4558 df_print_regset (file, &bb_info->init);
4559 fprintf (file, ";; md gen \t");
4560 df_print_regset (file, &bb_info->gen);
4561 fprintf (file, ";; md kill \t");
4562 df_print_regset (file, &bb_info->kill);
4565 /* Debugging info at bottom of bb. */
4567 static void
4568 df_md_bottom_dump (basic_block bb, FILE *file)
4570 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4571 if (!bb_info)
4572 return;
4574 fprintf (file, ";; md out \t");
4575 df_print_regset (file, &bb_info->out);
4578 static struct df_problem problem_MD =
4580 DF_MD, /* Problem id. */
4581 DF_FORWARD, /* Direction. */
4582 df_md_alloc, /* Allocate the problem specific data. */
4583 df_md_reset, /* Reset global information. */
4584 df_md_free_bb_info, /* Free basic block info. */
4585 df_md_local_compute, /* Local compute function. */
4586 df_md_init, /* Init the solution specific data. */
4587 df_worklist_dataflow, /* Worklist solver. */
4588 df_md_confluence_0, /* Confluence operator 0. */
4589 df_md_confluence_n, /* Confluence operator n. */
4590 df_md_transfer_function, /* Transfer function. */
4591 NULL, /* Finalize function. */
4592 df_md_free, /* Free all of the problem information. */
4593 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4594 NULL, /* Debugging. */
4595 df_md_top_dump, /* Debugging start block. */
4596 df_md_bottom_dump, /* Debugging end block. */
4597 NULL, /* Incremental solution verify start. */
4598 NULL, /* Incremental solution verify end. */
4599 NULL, /* Dependent problem. */
4600 TV_DF_MD, /* Timing variable. */
4601 false /* Reset blocks on dropping out of blocks_to_analyze. */
4604 /* Create a new MD instance and add it to the existing instance
4605 of DF. */
4607 void
4608 df_md_add_problem (void)
4610 df_add_problem (&problem_MD);