common.opt (fshow-column): Don't mark as C ObjC C++ ObjC++.
[official-gcc.git] / gcc / df-problems.c
blob8438c9059b7685571c40a7104cd374aa95f95624
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;
1364 /* An obstack for the bitmaps we need for this problem. */
1365 bitmap_obstack live_bitmaps;
1368 /* Scratch var used by transfer functions. This is used to implement
1369 an optimization to reduce the amount of space used to compute the
1370 combined lr and live analysis. */
1371 static bitmap df_live_scratch;
1373 /* Set basic block info. */
1375 static void
1376 df_live_set_bb_info (unsigned int index,
1377 struct df_live_bb_info *bb_info)
1379 gcc_assert (df_live);
1380 gcc_assert (index < df_live->block_info_size);
1381 df_live->block_info[index] = bb_info;
1385 /* Free basic block info. */
1387 static void
1388 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1389 void *vbb_info)
1391 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
1392 if (bb_info)
1394 bitmap_clear (&bb_info->gen);
1395 bitmap_clear (&bb_info->kill);
1396 bitmap_clear (&bb_info->in);
1397 bitmap_clear (&bb_info->out);
1398 pool_free (df_live->block_pool, bb_info);
1403 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1404 not touched unless the block is new. */
1406 static void
1407 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1409 unsigned int bb_index;
1410 bitmap_iterator bi;
1411 struct df_live_problem_data *problem_data;
1413 if (!df_live->block_pool)
1414 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1415 sizeof (struct df_live_bb_info), 100);
1416 if (df_live->problem_data)
1417 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1418 else
1420 problem_data = XNEW (struct df_live_problem_data);
1421 df_live->problem_data = problem_data;
1423 problem_data->out = NULL;
1424 problem_data->in = NULL;
1425 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1427 if (!df_live_scratch)
1428 df_live_scratch = BITMAP_ALLOC (&problem_data->live_bitmaps);
1430 df_grow_bb_info (df_live);
1432 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1434 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1435 if (bb_info)
1437 bitmap_clear (&bb_info->kill);
1438 bitmap_clear (&bb_info->gen);
1440 else
1442 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1443 df_live_set_bb_info (bb_index, bb_info);
1444 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1445 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1446 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1447 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1450 df_live->optional_p = (optimize <= 1);
1454 /* Reset the global solution for recalculation. */
1456 static void
1457 df_live_reset (bitmap all_blocks)
1459 unsigned int bb_index;
1460 bitmap_iterator bi;
1462 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1464 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1465 gcc_assert (bb_info);
1466 bitmap_clear (&bb_info->in);
1467 bitmap_clear (&bb_info->out);
1472 /* Compute local uninitialized register info for basic block BB. */
1474 static void
1475 df_live_bb_local_compute (unsigned int bb_index)
1477 basic_block bb = BASIC_BLOCK (bb_index);
1478 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1479 rtx insn;
1480 df_ref *def_rec;
1481 int luid = 0;
1483 FOR_BB_INSNS (bb, insn)
1485 unsigned int uid = INSN_UID (insn);
1486 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1488 /* Inserting labels does not always trigger the incremental
1489 rescanning. */
1490 if (!insn_info)
1492 gcc_assert (!INSN_P (insn));
1493 insn_info = df_insn_create_insn_record (insn);
1496 DF_INSN_INFO_LUID (insn_info) = luid;
1497 if (!INSN_P (insn))
1498 continue;
1500 luid++;
1501 for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)
1503 df_ref def = *def_rec;
1504 unsigned int regno = DF_REF_REGNO (def);
1506 if (DF_REF_FLAGS_IS_SET (def,
1507 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1508 /* All partial or conditional def
1509 seen are included in the gen set. */
1510 bitmap_set_bit (&bb_info->gen, regno);
1511 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1512 /* Only must clobbers for the entire reg destroy the
1513 value. */
1514 bitmap_set_bit (&bb_info->kill, regno);
1515 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1516 bitmap_set_bit (&bb_info->gen, regno);
1520 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1522 df_ref def = *def_rec;
1523 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1528 /* Compute local uninitialized register info. */
1530 static void
1531 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1533 unsigned int bb_index;
1534 bitmap_iterator bi;
1536 df_grow_insn_info ();
1538 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1539 0, bb_index, bi)
1541 df_live_bb_local_compute (bb_index);
1544 bitmap_clear (df_live->out_of_date_transfer_functions);
1548 /* Initialize the solution vectors. */
1550 static void
1551 df_live_init (bitmap all_blocks)
1553 unsigned int bb_index;
1554 bitmap_iterator bi;
1556 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1558 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1559 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1561 /* No register may reach a location where it is not used. Thus
1562 we trim the rr result to the places where it is used. */
1563 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1564 bitmap_clear (&bb_info->in);
1568 /* Forward confluence function that ignores fake edges. */
1570 static void
1571 df_live_confluence_n (edge e)
1573 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1574 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1576 if (e->flags & EDGE_FAKE)
1577 return;
1579 bitmap_ior_into (op1, op2);
1583 /* Transfer function for the forwards must-initialized problem. */
1585 static bool
1586 df_live_transfer_function (int bb_index)
1588 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1589 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1590 bitmap in = &bb_info->in;
1591 bitmap out = &bb_info->out;
1592 bitmap gen = &bb_info->gen;
1593 bitmap kill = &bb_info->kill;
1595 /* We need to use a scratch set here so that the value returned from this
1596 function invocation properly reflects whether the sets changed in a
1597 significant way; i.e. not just because the lr set was anded in. */
1598 bitmap_and (df_live_scratch, gen, &bb_lr_info->out);
1599 /* No register may reach a location where it is not used. Thus
1600 we trim the rr result to the places where it is used. */
1601 bitmap_and_into (in, &bb_lr_info->in);
1603 return bitmap_ior_and_compl (out, df_live_scratch, in, kill);
1607 /* And the LR info with the must-initialized registers, to produce the LIVE info. */
1609 static void
1610 df_live_finalize (bitmap all_blocks)
1613 if (df_live->solutions_dirty)
1615 bitmap_iterator bi;
1616 unsigned int bb_index;
1618 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1620 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1621 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1623 /* No register may reach a location where it is not used. Thus
1624 we trim the rr result to the places where it is used. */
1625 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1626 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1629 df_live->solutions_dirty = false;
1634 /* Free all storage associated with the problem. */
1636 static void
1637 df_live_free (void)
1639 struct df_live_problem_data *problem_data
1640 = (struct df_live_problem_data *) df_live->problem_data;
1641 if (df_live->block_info)
1643 free_alloc_pool (df_live->block_pool);
1644 df_live->block_info_size = 0;
1645 free (df_live->block_info);
1646 bitmap_obstack_release (&problem_data->live_bitmaps);
1648 if (df_live_scratch)
1649 BITMAP_FREE (df_live_scratch);
1651 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1652 free (df_live);
1656 /* Debugging info at top of bb. */
1658 static void
1659 df_live_top_dump (basic_block bb, FILE *file)
1661 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1662 struct df_live_problem_data *problem_data;
1664 if (!bb_info)
1665 return;
1667 fprintf (file, ";; live in \t");
1668 df_print_regset (file, &bb_info->in);
1669 if (df_live->problem_data)
1671 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1672 if (problem_data->in)
1674 fprintf (file, ";; old in \t");
1675 df_print_regset (file, &problem_data->in[bb->index]);
1678 fprintf (file, ";; live gen \t");
1679 df_print_regset (file, &bb_info->gen);
1680 fprintf (file, ";; live kill\t");
1681 df_print_regset (file, &bb_info->kill);
1685 /* Debugging info at bottom of bb. */
1687 static void
1688 df_live_bottom_dump (basic_block bb, FILE *file)
1690 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1691 struct df_live_problem_data *problem_data;
1693 if (!bb_info)
1694 return;
1696 fprintf (file, ";; live out \t");
1697 df_print_regset (file, &bb_info->out);
1698 if (df_live->problem_data)
1700 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1701 if (problem_data->out)
1703 fprintf (file, ";; old out \t");
1704 df_print_regset (file, &problem_data->out[bb->index]);
1710 /* Build the datastructure to verify that the solution to the dataflow
1711 equations is not dirty. */
1713 static void
1714 df_live_verify_solution_start (void)
1716 basic_block bb;
1717 struct df_live_problem_data *problem_data;
1718 if (df_live->solutions_dirty)
1719 return;
1721 /* Set it true so that the solution is recomputed. */
1722 df_live->solutions_dirty = true;
1724 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1725 problem_data->in = XNEWVEC (bitmap_head, last_basic_block);
1726 problem_data->out = XNEWVEC (bitmap_head, last_basic_block);
1728 FOR_ALL_BB (bb)
1730 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1731 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1732 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1733 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1738 /* Compare the saved datastructure and the new solution to the dataflow
1739 equations. */
1741 static void
1742 df_live_verify_solution_end (void)
1744 struct df_live_problem_data *problem_data;
1745 basic_block bb;
1747 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1748 if (!problem_data->out)
1749 return;
1751 FOR_ALL_BB (bb)
1753 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1754 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1756 /*df_dump (stderr);*/
1757 gcc_unreachable ();
1761 /* Cannot delete them immediately because you may want to dump them
1762 if the comparison fails. */
1763 FOR_ALL_BB (bb)
1765 bitmap_clear (&problem_data->in[bb->index]);
1766 bitmap_clear (&problem_data->out[bb->index]);
1769 free (problem_data->in);
1770 free (problem_data->out);
1771 free (problem_data);
1772 df_live->problem_data = NULL;
1776 /* All of the information associated with every instance of the problem. */
1778 static struct df_problem problem_LIVE =
1780 DF_LIVE, /* Problem id. */
1781 DF_FORWARD, /* Direction. */
1782 df_live_alloc, /* Allocate the problem specific data. */
1783 df_live_reset, /* Reset global information. */
1784 df_live_free_bb_info, /* Free basic block info. */
1785 df_live_local_compute, /* Local compute function. */
1786 df_live_init, /* Init the solution specific data. */
1787 df_worklist_dataflow, /* Worklist solver. */
1788 NULL, /* Confluence operator 0. */
1789 df_live_confluence_n, /* Confluence operator n. */
1790 df_live_transfer_function, /* Transfer function. */
1791 df_live_finalize, /* Finalize function. */
1792 df_live_free, /* Free all of the problem information. */
1793 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1794 NULL, /* Debugging. */
1795 df_live_top_dump, /* Debugging start block. */
1796 df_live_bottom_dump, /* Debugging end block. */
1797 df_live_verify_solution_start,/* Incremental solution verify start. */
1798 df_live_verify_solution_end, /* Incremental solution verify end. */
1799 &problem_LR, /* Dependent problem. */
1800 TV_DF_LIVE, /* Timing variable. */
1801 false /* Reset blocks on dropping out of blocks_to_analyze. */
1805 /* Create a new DATAFLOW instance and add it to an existing instance
1806 of DF. The returned structure is what is used to get at the
1807 solution. */
1809 void
1810 df_live_add_problem (void)
1812 df_add_problem (&problem_LIVE);
1813 /* These will be initialized when df_scan_blocks processes each
1814 block. */
1815 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1819 /* Set all of the blocks as dirty. This needs to be done if this
1820 problem is added after all of the insns have been scanned. */
1822 void
1823 df_live_set_all_dirty (void)
1825 basic_block bb;
1826 FOR_ALL_BB (bb)
1827 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1828 bb->index);
1832 /* Verify that all of the lr related info is consistent and
1833 correct. */
1835 void
1836 df_live_verify_transfer_functions (void)
1838 basic_block bb;
1839 bitmap_head saved_gen;
1840 bitmap_head saved_kill;
1841 bitmap_head all_blocks;
1843 if (!df)
1844 return;
1846 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1847 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1848 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1850 df_grow_insn_info ();
1852 FOR_ALL_BB (bb)
1854 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1855 bitmap_set_bit (&all_blocks, bb->index);
1857 if (bb_info)
1859 /* Make a copy of the transfer functions and then compute
1860 new ones to see if the transfer functions have
1861 changed. */
1862 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1863 bb->index))
1865 bitmap_copy (&saved_gen, &bb_info->gen);
1866 bitmap_copy (&saved_kill, &bb_info->kill);
1867 bitmap_clear (&bb_info->gen);
1868 bitmap_clear (&bb_info->kill);
1870 df_live_bb_local_compute (bb->index);
1871 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1872 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1875 else
1877 /* If we do not have basic block info, the block must be in
1878 the list of dirty blocks or else some one has added a
1879 block behind our backs. */
1880 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1881 bb->index));
1883 /* Make sure no one created a block without following
1884 procedures. */
1885 gcc_assert (df_scan_get_bb_info (bb->index));
1888 /* Make sure there are no dirty bits in blocks that have been deleted. */
1889 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1890 &all_blocks));
1891 bitmap_clear (&saved_gen);
1892 bitmap_clear (&saved_kill);
1893 bitmap_clear (&all_blocks);
1896 /*----------------------------------------------------------------------------
1897 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1899 Link either the defs to the uses and / or the uses to the defs.
1901 These problems are set up like the other dataflow problems so that
1902 they nicely fit into the framework. They are much simpler and only
1903 involve a single traversal of instructions and an examination of
1904 the reaching defs information (the dependent problem).
1905 ----------------------------------------------------------------------------*/
1907 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
1909 /* Create a du or ud chain from SRC to DST and link it into SRC. */
1911 struct df_link *
1912 df_chain_create (df_ref src, df_ref dst)
1914 struct df_link *head = DF_REF_CHAIN (src);
1915 struct df_link *link = (struct df_link *) pool_alloc (df_chain->block_pool);
1917 DF_REF_CHAIN (src) = link;
1918 link->next = head;
1919 link->ref = dst;
1920 return link;
1924 /* Delete any du or ud chains that start at REF and point to
1925 TARGET. */
1926 static void
1927 df_chain_unlink_1 (df_ref ref, df_ref target)
1929 struct df_link *chain = DF_REF_CHAIN (ref);
1930 struct df_link *prev = NULL;
1932 while (chain)
1934 if (chain->ref == target)
1936 if (prev)
1937 prev->next = chain->next;
1938 else
1939 DF_REF_CHAIN (ref) = chain->next;
1940 pool_free (df_chain->block_pool, chain);
1941 return;
1943 prev = chain;
1944 chain = chain->next;
1949 /* Delete a du or ud chain that leave or point to REF. */
1951 void
1952 df_chain_unlink (df_ref ref)
1954 struct df_link *chain = DF_REF_CHAIN (ref);
1955 while (chain)
1957 struct df_link *next = chain->next;
1958 /* Delete the other side if it exists. */
1959 df_chain_unlink_1 (chain->ref, ref);
1960 pool_free (df_chain->block_pool, chain);
1961 chain = next;
1963 DF_REF_CHAIN (ref) = NULL;
1967 /* Copy the du or ud chain starting at FROM_REF and attach it to
1968 TO_REF. */
1970 void
1971 df_chain_copy (df_ref to_ref,
1972 struct df_link *from_ref)
1974 while (from_ref)
1976 df_chain_create (to_ref, from_ref->ref);
1977 from_ref = from_ref->next;
1982 /* Remove this problem from the stack of dataflow problems. */
1984 static void
1985 df_chain_remove_problem (void)
1987 bitmap_iterator bi;
1988 unsigned int bb_index;
1990 /* Wholesale destruction of the old chains. */
1991 if (df_chain->block_pool)
1992 free_alloc_pool (df_chain->block_pool);
1994 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1996 rtx insn;
1997 df_ref *def_rec;
1998 df_ref *use_rec;
1999 basic_block bb = BASIC_BLOCK (bb_index);
2001 if (df_chain_problem_p (DF_DU_CHAIN))
2002 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
2003 DF_REF_CHAIN (*def_rec) = NULL;
2004 if (df_chain_problem_p (DF_UD_CHAIN))
2005 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
2006 DF_REF_CHAIN (*use_rec) = NULL;
2008 FOR_BB_INSNS (bb, insn)
2010 unsigned int uid = INSN_UID (insn);
2012 if (INSN_P (insn))
2014 if (df_chain_problem_p (DF_DU_CHAIN))
2015 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2016 DF_REF_CHAIN (*def_rec) = NULL;
2017 if (df_chain_problem_p (DF_UD_CHAIN))
2019 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2020 DF_REF_CHAIN (*use_rec) = NULL;
2021 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
2022 DF_REF_CHAIN (*use_rec) = NULL;
2028 bitmap_clear (df_chain->out_of_date_transfer_functions);
2029 df_chain->block_pool = NULL;
2033 /* Remove the chain problem completely. */
2035 static void
2036 df_chain_fully_remove_problem (void)
2038 df_chain_remove_problem ();
2039 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2040 free (df_chain);
2044 /* Create def-use or use-def chains. */
2046 static void
2047 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2049 df_chain_remove_problem ();
2050 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
2051 sizeof (struct df_link), 50);
2052 df_chain->optional_p = true;
2056 /* Reset all of the chains when the set of basic blocks changes. */
2058 static void
2059 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2061 df_chain_remove_problem ();
2065 /* Create the chains for a list of USEs. */
2067 static void
2068 df_chain_create_bb_process_use (bitmap local_rd,
2069 df_ref *use_rec,
2070 int top_flag)
2072 bitmap_iterator bi;
2073 unsigned int def_index;
2075 while (*use_rec)
2077 df_ref use = *use_rec;
2078 unsigned int uregno = DF_REF_REGNO (use);
2079 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2080 || (uregno >= FIRST_PSEUDO_REGISTER))
2082 /* Do not want to go through this for an uninitialized var. */
2083 int count = DF_DEFS_COUNT (uregno);
2084 if (count)
2086 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2088 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2089 unsigned int last_index = first_index + count - 1;
2091 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2093 df_ref def;
2094 if (def_index > last_index)
2095 break;
2097 def = DF_DEFS_GET (def_index);
2098 if (df_chain_problem_p (DF_DU_CHAIN))
2099 df_chain_create (def, use);
2100 if (df_chain_problem_p (DF_UD_CHAIN))
2101 df_chain_create (use, def);
2107 use_rec++;
2112 /* Create chains from reaching defs bitmaps for basic block BB. */
2114 static void
2115 df_chain_create_bb (unsigned int bb_index)
2117 basic_block bb = BASIC_BLOCK (bb_index);
2118 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2119 rtx insn;
2120 bitmap_head cpy;
2122 bitmap_initialize (&cpy, &bitmap_default_obstack);
2123 bitmap_copy (&cpy, &bb_info->in);
2124 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2126 /* Since we are going forwards, process the artificial uses first
2127 then the artificial defs second. */
2129 #ifdef EH_USES
2130 /* Create the chains for the artificial uses from the EH_USES at the
2131 beginning of the block. */
2133 /* Artificials are only hard regs. */
2134 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2135 df_chain_create_bb_process_use (&cpy,
2136 df_get_artificial_uses (bb->index),
2137 DF_REF_AT_TOP);
2138 #endif
2140 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2142 /* Process the regular instructions next. */
2143 FOR_BB_INSNS (bb, insn)
2144 if (INSN_P (insn))
2146 unsigned int uid = INSN_UID (insn);
2148 /* First scan the uses and link them up with the defs that remain
2149 in the cpy vector. */
2150 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2151 if (df->changeable_flags & DF_EQ_NOTES)
2152 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2154 /* Since we are going forwards, process the defs second. */
2155 df_rd_simulate_one_insn (bb, insn, &cpy);
2158 /* Create the chains for the artificial uses of the hard registers
2159 at the end of the block. */
2160 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2161 df_chain_create_bb_process_use (&cpy,
2162 df_get_artificial_uses (bb->index),
2165 bitmap_clear (&cpy);
2168 /* Create def-use chains from reaching use bitmaps for basic blocks
2169 in BLOCKS. */
2171 static void
2172 df_chain_finalize (bitmap all_blocks)
2174 unsigned int bb_index;
2175 bitmap_iterator bi;
2177 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2179 df_chain_create_bb (bb_index);
2184 /* Free all storage associated with the problem. */
2186 static void
2187 df_chain_free (void)
2189 free_alloc_pool (df_chain->block_pool);
2190 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2191 free (df_chain);
2195 /* Debugging info. */
2197 static void
2198 df_chain_top_dump (basic_block bb, FILE *file)
2200 if (df_chain_problem_p (DF_DU_CHAIN))
2202 rtx insn;
2203 df_ref *def_rec = df_get_artificial_defs (bb->index);
2204 if (*def_rec)
2207 fprintf (file, ";; DU chains for artificial defs\n");
2208 while (*def_rec)
2210 df_ref def = *def_rec;
2211 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2212 df_chain_dump (DF_REF_CHAIN (def), file);
2213 fprintf (file, "\n");
2214 def_rec++;
2218 FOR_BB_INSNS (bb, insn)
2220 if (INSN_P (insn))
2222 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2223 def_rec = DF_INSN_INFO_DEFS (insn_info);
2224 if (*def_rec)
2226 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2227 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2229 while (*def_rec)
2231 df_ref def = *def_rec;
2232 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2233 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2234 fprintf (file, "read/write ");
2235 df_chain_dump (DF_REF_CHAIN (def), file);
2236 fprintf (file, "\n");
2237 def_rec++;
2246 static void
2247 df_chain_bottom_dump (basic_block bb, FILE *file)
2249 if (df_chain_problem_p (DF_UD_CHAIN))
2251 rtx insn;
2252 df_ref *use_rec = df_get_artificial_uses (bb->index);
2254 if (*use_rec)
2256 fprintf (file, ";; UD chains for artificial uses\n");
2257 while (*use_rec)
2259 df_ref use = *use_rec;
2260 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2261 df_chain_dump (DF_REF_CHAIN (use), file);
2262 fprintf (file, "\n");
2263 use_rec++;
2267 FOR_BB_INSNS (bb, insn)
2269 if (INSN_P (insn))
2271 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2272 df_ref *eq_use_rec = DF_INSN_INFO_EQ_USES (insn_info);
2273 use_rec = DF_INSN_INFO_USES (insn_info);
2274 if (*use_rec || *eq_use_rec)
2276 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2277 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2279 while (*use_rec)
2281 df_ref use = *use_rec;
2282 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2283 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2284 fprintf (file, "read/write ");
2285 df_chain_dump (DF_REF_CHAIN (use), file);
2286 fprintf (file, "\n");
2287 use_rec++;
2289 while (*eq_use_rec)
2291 df_ref use = *eq_use_rec;
2292 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2293 df_chain_dump (DF_REF_CHAIN (use), file);
2294 fprintf (file, "\n");
2295 eq_use_rec++;
2304 static struct df_problem problem_CHAIN =
2306 DF_CHAIN, /* Problem id. */
2307 DF_NONE, /* Direction. */
2308 df_chain_alloc, /* Allocate the problem specific data. */
2309 df_chain_reset, /* Reset global information. */
2310 NULL, /* Free basic block info. */
2311 NULL, /* Local compute function. */
2312 NULL, /* Init the solution specific data. */
2313 NULL, /* Iterative solver. */
2314 NULL, /* Confluence operator 0. */
2315 NULL, /* Confluence operator n. */
2316 NULL, /* Transfer function. */
2317 df_chain_finalize, /* Finalize function. */
2318 df_chain_free, /* Free all of the problem information. */
2319 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2320 NULL, /* Debugging. */
2321 df_chain_top_dump, /* Debugging start block. */
2322 df_chain_bottom_dump, /* Debugging end block. */
2323 NULL, /* Incremental solution verify start. */
2324 NULL, /* Incremental solution verify end. */
2325 &problem_RD, /* Dependent problem. */
2326 TV_DF_CHAIN, /* Timing variable. */
2327 false /* Reset blocks on dropping out of blocks_to_analyze. */
2331 /* Create a new DATAFLOW instance and add it to an existing instance
2332 of DF. The returned structure is what is used to get at the
2333 solution. */
2335 void
2336 df_chain_add_problem (unsigned int chain_flags)
2338 df_add_problem (&problem_CHAIN);
2339 df_chain->local_flags = chain_flags;
2340 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2343 #undef df_chain_problem_p
2346 /*----------------------------------------------------------------------------
2347 BYTE LEVEL LIVE REGISTERS
2349 Find the locations in the function where any use of a pseudo can
2350 reach in the backwards direction. In and out bitvectors are built
2351 for each basic block. There are two mapping functions,
2352 df_byte_lr_get_regno_start and df_byte_lr_get_regno_len that are
2353 used to map regnos into bit vector positions.
2355 This problem differs from the regular df_lr function in the way
2356 that subregs, *_extracts and strict_low_parts are handled. In lr
2357 these are consider partial kills, here, the exact set of bytes is
2358 modeled. Note that any reg that has none of these operations is
2359 only modeled with a single bit since all operations access the
2360 entire register.
2362 This problem is more brittle that the regular lr. It currently can
2363 be used in dce incrementally, but cannot be used in an environment
2364 where insns are created or modified. The problem is that the
2365 mapping of regnos to bitmap positions is relatively compact, in
2366 that if a pseudo does not do any of the byte wise operations, only
2367 one slot is allocated, rather than a slot for each byte. If insn
2368 are created, where a subreg is used for a reg that had no subregs,
2369 the mapping would be wrong. Likewise, there are no checks to see
2370 that new pseudos have been added. These issues could be addressed
2371 by adding a problem specific flag to not use the compact mapping,
2372 if there was a need to do so.
2374 ----------------------------------------------------------------------------*/
2376 /* Private data used to verify the solution for this problem. */
2377 struct df_byte_lr_problem_data
2379 /* Expanded versions of bitvectors used in lr. */
2380 bitmap_head invalidated_by_call;
2381 bitmap_head hardware_regs_used;
2383 /* Indexed by regno, this is true if there are subregs, extracts or
2384 strict_low_parts for this regno. */
2385 bitmap_head needs_expansion;
2387 /* The start position and len for each regno in the various bit
2388 vectors. */
2389 unsigned int* regno_start;
2390 unsigned int* regno_len;
2391 /* An obstack for the bitmaps we need for this problem. */
2392 bitmap_obstack byte_lr_bitmaps;
2396 /* Get the starting location for REGNO in the df_byte_lr bitmaps. */
2399 df_byte_lr_get_regno_start (unsigned int regno)
2401 struct df_byte_lr_problem_data *problem_data
2402 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;;
2403 return problem_data->regno_start[regno];
2407 /* Get the len for REGNO in the df_byte_lr bitmaps. */
2410 df_byte_lr_get_regno_len (unsigned int regno)
2412 struct df_byte_lr_problem_data *problem_data
2413 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;;
2414 return problem_data->regno_len[regno];
2418 /* Set basic block info. */
2420 static void
2421 df_byte_lr_set_bb_info (unsigned int index,
2422 struct df_byte_lr_bb_info *bb_info)
2424 gcc_assert (df_byte_lr);
2425 gcc_assert (index < df_byte_lr->block_info_size);
2426 df_byte_lr->block_info[index] = bb_info;
2430 /* Free basic block info. */
2432 static void
2433 df_byte_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2434 void *vbb_info)
2436 struct df_byte_lr_bb_info *bb_info = (struct df_byte_lr_bb_info *) vbb_info;
2437 if (bb_info)
2439 bitmap_clear (&bb_info->use);
2440 bitmap_clear (&bb_info->def);
2441 bitmap_clear (&bb_info->in);
2442 bitmap_clear (&bb_info->out);
2443 pool_free (df_byte_lr->block_pool, bb_info);
2448 /* Check all of the refs in REF_REC to see if any of them are
2449 extracts, subregs or strict_low_parts. */
2451 static void
2452 df_byte_lr_check_regs (df_ref *ref_rec)
2454 struct df_byte_lr_problem_data *problem_data
2455 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2457 for (; *ref_rec; ref_rec++)
2459 df_ref ref = *ref_rec;
2460 if (DF_REF_FLAGS_IS_SET (ref, DF_REF_SIGN_EXTRACT
2461 | DF_REF_ZERO_EXTRACT
2462 | DF_REF_STRICT_LOW_PART)
2463 || GET_CODE (DF_REF_REG (ref)) == SUBREG)
2464 bitmap_set_bit (&problem_data->needs_expansion, DF_REF_REGNO (ref));
2469 /* Expand bitmap SRC which is indexed by regno to DEST which is indexed by
2470 regno_start and regno_len. */
2472 static void
2473 df_byte_lr_expand_bitmap (bitmap dest, bitmap src)
2475 struct df_byte_lr_problem_data *problem_data
2476 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2477 bitmap_iterator bi;
2478 unsigned int i;
2480 bitmap_clear (dest);
2481 EXECUTE_IF_SET_IN_BITMAP (src, 0, i, bi)
2483 bitmap_set_range (dest, problem_data->regno_start[i],
2484 problem_data->regno_len[i]);
2489 /* Allocate or reset bitmaps for DF_BYTE_LR blocks. The solution bits are
2490 not touched unless the block is new. */
2492 static void
2493 df_byte_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2495 unsigned int bb_index;
2496 bitmap_iterator bi;
2497 basic_block bb;
2498 unsigned int regno;
2499 unsigned int index = 0;
2500 unsigned int max_reg = max_reg_num();
2501 struct df_byte_lr_problem_data *problem_data
2502 = XNEW (struct df_byte_lr_problem_data);
2504 df_byte_lr->problem_data = problem_data;
2506 if (!df_byte_lr->block_pool)
2507 df_byte_lr->block_pool = create_alloc_pool ("df_byte_lr_block pool",
2508 sizeof (struct df_byte_lr_bb_info), 50);
2510 df_grow_bb_info (df_byte_lr);
2512 /* Create the mapping from regnos to slots. This does not change
2513 unless the problem is destroyed and recreated. In particular, if
2514 we end up deleting the only insn that used a subreg, we do not
2515 want to redo the mapping because this would invalidate everything
2516 else. */
2518 bitmap_obstack_initialize (&problem_data->byte_lr_bitmaps);
2519 problem_data->regno_start = XNEWVEC (unsigned int, max_reg);
2520 problem_data->regno_len = XNEWVEC (unsigned int, max_reg);
2521 bitmap_initialize (&problem_data->hardware_regs_used,
2522 &problem_data->byte_lr_bitmaps);
2523 bitmap_initialize (&problem_data->invalidated_by_call,
2524 &problem_data->byte_lr_bitmaps);
2525 bitmap_initialize (&problem_data->needs_expansion,
2526 &problem_data->byte_lr_bitmaps);
2528 /* Discover which regno's use subregs, extracts or
2529 strict_low_parts. */
2530 FOR_EACH_BB (bb)
2532 rtx insn;
2533 FOR_BB_INSNS (bb, insn)
2535 if (INSN_P (insn))
2537 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2538 df_byte_lr_check_regs (DF_INSN_INFO_DEFS (insn_info));
2539 df_byte_lr_check_regs (DF_INSN_INFO_USES (insn_info));
2542 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, bb->index);
2545 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2546 bitmap_set_bit (df_byte_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2548 /* Allocate the slots for each regno. */
2549 for (regno = 0; regno < max_reg; regno++)
2551 int len;
2552 problem_data->regno_start[regno] = index;
2553 if (bitmap_bit_p (&problem_data->needs_expansion, regno))
2554 len = GET_MODE_SIZE (GET_MODE (regno_reg_rtx[regno]));
2555 else
2556 len = 1;
2558 problem_data->regno_len[regno] = len;
2559 index += len;
2562 df_byte_lr_expand_bitmap (&problem_data->hardware_regs_used,
2563 &df->hardware_regs_used);
2564 df_byte_lr_expand_bitmap (&problem_data->invalidated_by_call,
2565 regs_invalidated_by_call_regset);
2567 EXECUTE_IF_SET_IN_BITMAP (df_byte_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2569 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2570 if (bb_info)
2572 bitmap_clear (&bb_info->def);
2573 bitmap_clear (&bb_info->use);
2575 else
2577 bb_info = (struct df_byte_lr_bb_info *) pool_alloc (df_byte_lr->block_pool);
2578 df_byte_lr_set_bb_info (bb_index, bb_info);
2579 bitmap_initialize (&bb_info->use, &problem_data->byte_lr_bitmaps);
2580 bitmap_initialize (&bb_info->def, &problem_data->byte_lr_bitmaps);
2581 bitmap_initialize (&bb_info->in, &problem_data->byte_lr_bitmaps);
2582 bitmap_initialize (&bb_info->out, &problem_data->byte_lr_bitmaps);
2586 df_byte_lr->optional_p = true;
2590 /* Reset the global solution for recalculation. */
2592 static void
2593 df_byte_lr_reset (bitmap all_blocks)
2595 unsigned int bb_index;
2596 bitmap_iterator bi;
2598 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2600 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2601 gcc_assert (bb_info);
2602 bitmap_clear (&bb_info->in);
2603 bitmap_clear (&bb_info->out);
2608 /* Compute local live register info for basic block BB. */
2610 static void
2611 df_byte_lr_bb_local_compute (unsigned int bb_index)
2613 struct df_byte_lr_problem_data *problem_data
2614 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2615 basic_block bb = BASIC_BLOCK (bb_index);
2616 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2617 rtx insn;
2618 df_ref *def_rec;
2619 df_ref *use_rec;
2621 /* Process the registers set in an exception handler. */
2622 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2624 df_ref def = *def_rec;
2625 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2627 unsigned int dregno = DF_REF_REGNO (def);
2628 unsigned int start = problem_data->regno_start[dregno];
2629 unsigned int len = problem_data->regno_len[dregno];
2630 bitmap_set_range (&bb_info->def, start, len);
2631 bitmap_clear_range (&bb_info->use, start, len);
2635 /* Process the hardware registers that are always live. */
2636 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2638 df_ref use = *use_rec;
2639 /* Add use to set of uses in this BB. */
2640 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2642 unsigned int uregno = DF_REF_REGNO (use);
2643 unsigned int start = problem_data->regno_start[uregno];
2644 unsigned int len = problem_data->regno_len[uregno];
2645 bitmap_set_range (&bb_info->use, start, len);
2649 FOR_BB_INSNS_REVERSE (bb, insn)
2651 unsigned int uid = INSN_UID (insn);
2653 if (!INSN_P (insn))
2654 continue;
2656 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2658 df_ref def = *def_rec;
2659 /* If the def is to only part of the reg, it does
2660 not kill the other defs that reach here. */
2661 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2663 unsigned int dregno = DF_REF_REGNO (def);
2664 unsigned int start = problem_data->regno_start[dregno];
2665 unsigned int len = problem_data->regno_len[dregno];
2666 unsigned int sb;
2667 unsigned int lb;
2668 if (!df_compute_accessed_bytes (def, DF_MM_MUST, &sb, &lb))
2670 start += sb;
2671 len = lb - sb;
2673 if (len)
2675 bitmap_set_range (&bb_info->def, start, len);
2676 bitmap_clear_range (&bb_info->use, start, len);
2681 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2683 df_ref use = *use_rec;
2684 unsigned int uregno = DF_REF_REGNO (use);
2685 unsigned int start = problem_data->regno_start[uregno];
2686 unsigned int len = problem_data->regno_len[uregno];
2687 unsigned int sb;
2688 unsigned int lb;
2689 if (!df_compute_accessed_bytes (use, DF_MM_MAY, &sb, &lb))
2691 start += sb;
2692 len = lb - sb;
2694 /* Add use to set of uses in this BB. */
2695 if (len)
2696 bitmap_set_range (&bb_info->use, start, len);
2700 /* Process the registers set in an exception handler or the hard
2701 frame pointer if this block is the target of a non local
2702 goto. */
2703 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2705 df_ref def = *def_rec;
2706 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2708 unsigned int dregno = DF_REF_REGNO (def);
2709 unsigned int start = problem_data->regno_start[dregno];
2710 unsigned int len = problem_data->regno_len[dregno];
2711 bitmap_set_range (&bb_info->def, start, len);
2712 bitmap_clear_range (&bb_info->use, start, len);
2716 #ifdef EH_USES
2717 /* Process the uses that are live into an exception handler. */
2718 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2720 df_ref use = *use_rec;
2721 /* Add use to set of uses in this BB. */
2722 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
2724 unsigned int uregno = DF_REF_REGNO (use);
2725 unsigned int start = problem_data->regno_start[uregno];
2726 unsigned int len = problem_data->regno_len[uregno];
2727 bitmap_set_range (&bb_info->use, start, len);
2730 #endif
2734 /* Compute local live register info for each basic block within BLOCKS. */
2736 static void
2737 df_byte_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2739 unsigned int bb_index;
2740 bitmap_iterator bi;
2742 EXECUTE_IF_SET_IN_BITMAP (df_byte_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2744 if (bb_index == EXIT_BLOCK)
2746 /* The exit block is special for this problem and its bits are
2747 computed from thin air. */
2748 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (EXIT_BLOCK);
2749 df_byte_lr_expand_bitmap (&bb_info->use, df->exit_block_uses);
2751 else
2752 df_byte_lr_bb_local_compute (bb_index);
2755 bitmap_clear (df_byte_lr->out_of_date_transfer_functions);
2759 /* Initialize the solution vectors. */
2761 static void
2762 df_byte_lr_init (bitmap all_blocks)
2764 unsigned int bb_index;
2765 bitmap_iterator bi;
2767 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2769 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2770 bitmap_copy (&bb_info->in, &bb_info->use);
2771 bitmap_clear (&bb_info->out);
2776 /* Confluence function that processes infinite loops. This might be a
2777 noreturn function that throws. And even if it isn't, getting the
2778 unwind info right helps debugging. */
2779 static void
2780 df_byte_lr_confluence_0 (basic_block bb)
2782 struct df_byte_lr_problem_data *problem_data
2783 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2784 bitmap op1 = &df_byte_lr_get_bb_info (bb->index)->out;
2785 if (bb != EXIT_BLOCK_PTR)
2786 bitmap_copy (op1, &problem_data->hardware_regs_used);
2790 /* Confluence function that ignores fake edges. */
2792 static void
2793 df_byte_lr_confluence_n (edge e)
2795 struct df_byte_lr_problem_data *problem_data
2796 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2797 bitmap op1 = &df_byte_lr_get_bb_info (e->src->index)->out;
2798 bitmap op2 = &df_byte_lr_get_bb_info (e->dest->index)->in;
2800 /* Call-clobbered registers die across exception and call edges. */
2801 /* ??? Abnormal call edges ignored for the moment, as this gets
2802 confused by sibling call edges, which crashes reg-stack. */
2803 if (e->flags & EDGE_EH)
2804 bitmap_ior_and_compl_into (op1, op2, &problem_data->invalidated_by_call);
2805 else
2806 bitmap_ior_into (op1, op2);
2808 bitmap_ior_into (op1, &problem_data->hardware_regs_used);
2812 /* Transfer function. */
2814 static bool
2815 df_byte_lr_transfer_function (int bb_index)
2817 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb_index);
2818 bitmap in = &bb_info->in;
2819 bitmap out = &bb_info->out;
2820 bitmap use = &bb_info->use;
2821 bitmap def = &bb_info->def;
2823 return bitmap_ior_and_compl (in, use, out, def);
2827 /* Free all storage associated with the problem. */
2829 static void
2830 df_byte_lr_free (void)
2832 struct df_byte_lr_problem_data *problem_data
2833 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2836 if (df_byte_lr->block_info)
2838 free_alloc_pool (df_byte_lr->block_pool);
2839 df_byte_lr->block_info_size = 0;
2840 free (df_byte_lr->block_info);
2843 BITMAP_FREE (df_byte_lr->out_of_date_transfer_functions);
2844 bitmap_obstack_release (&problem_data->byte_lr_bitmaps);
2845 free (problem_data->regno_start);
2846 free (problem_data->regno_len);
2847 free (problem_data);
2848 free (df_byte_lr);
2852 /* Debugging info at top of bb. */
2854 static void
2855 df_byte_lr_top_dump (basic_block bb, FILE *file)
2857 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb->index);
2858 if (!bb_info)
2859 return;
2861 fprintf (file, ";; blr in \t");
2862 df_print_byte_regset (file, &bb_info->in);
2863 fprintf (file, ";; blr use \t");
2864 df_print_byte_regset (file, &bb_info->use);
2865 fprintf (file, ";; blr def \t");
2866 df_print_byte_regset (file, &bb_info->def);
2870 /* Debugging info at bottom of bb. */
2872 static void
2873 df_byte_lr_bottom_dump (basic_block bb, FILE *file)
2875 struct df_byte_lr_bb_info *bb_info = df_byte_lr_get_bb_info (bb->index);
2876 if (!bb_info)
2877 return;
2879 fprintf (file, ";; blr out \t");
2880 df_print_byte_regset (file, &bb_info->out);
2884 /* All of the information associated with every instance of the problem. */
2886 static struct df_problem problem_BYTE_LR =
2888 DF_BYTE_LR, /* Problem id. */
2889 DF_BACKWARD, /* Direction. */
2890 df_byte_lr_alloc, /* Allocate the problem specific data. */
2891 df_byte_lr_reset, /* Reset global information. */
2892 df_byte_lr_free_bb_info, /* Free basic block info. */
2893 df_byte_lr_local_compute, /* Local compute function. */
2894 df_byte_lr_init, /* Init the solution specific data. */
2895 df_worklist_dataflow, /* Worklist solver. */
2896 df_byte_lr_confluence_0, /* Confluence operator 0. */
2897 df_byte_lr_confluence_n, /* Confluence operator n. */
2898 df_byte_lr_transfer_function, /* Transfer function. */
2899 NULL, /* Finalize function. */
2900 df_byte_lr_free, /* Free all of the problem information. */
2901 df_byte_lr_free, /* Remove this problem from the stack of dataflow problems. */
2902 NULL, /* Debugging. */
2903 df_byte_lr_top_dump, /* Debugging start block. */
2904 df_byte_lr_bottom_dump, /* Debugging end block. */
2905 NULL, /* Incremental solution verify start. */
2906 NULL, /* Incremental solution verify end. */
2907 NULL, /* Dependent problem. */
2908 TV_DF_BYTE_LR, /* Timing variable. */
2909 false /* Reset blocks on dropping out of blocks_to_analyze. */
2913 /* Create a new DATAFLOW instance and add it to an existing instance
2914 of DF. The returned structure is what is used to get at the
2915 solution. */
2917 void
2918 df_byte_lr_add_problem (void)
2920 df_add_problem (&problem_BYTE_LR);
2921 /* These will be initialized when df_scan_blocks processes each
2922 block. */
2923 df_byte_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2927 /* Simulate the effects of the defs of INSN on LIVE. */
2929 void
2930 df_byte_lr_simulate_defs (rtx insn, bitmap live)
2932 struct df_byte_lr_problem_data *problem_data
2933 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2934 df_ref *def_rec;
2935 unsigned int uid = INSN_UID (insn);
2937 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2939 df_ref def = *def_rec;
2941 /* If the def is to only part of the reg, it does
2942 not kill the other defs that reach here. */
2943 if (!(DF_REF_FLAGS (def) & DF_REF_CONDITIONAL))
2945 unsigned int dregno = DF_REF_REGNO (def);
2946 unsigned int start = problem_data->regno_start[dregno];
2947 unsigned int len = problem_data->regno_len[dregno];
2948 unsigned int sb;
2949 unsigned int lb;
2950 if (!df_compute_accessed_bytes (def, DF_MM_MUST, &sb, &lb))
2952 start += sb;
2953 len = lb - sb;
2956 if (len)
2957 bitmap_clear_range (live, start, len);
2963 /* Simulate the effects of the uses of INSN on LIVE. */
2965 void
2966 df_byte_lr_simulate_uses (rtx insn, bitmap live)
2968 struct df_byte_lr_problem_data *problem_data
2969 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
2970 df_ref *use_rec;
2971 unsigned int uid = INSN_UID (insn);
2973 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
2975 df_ref use = *use_rec;
2976 unsigned int uregno = DF_REF_REGNO (use);
2977 unsigned int start = problem_data->regno_start[uregno];
2978 unsigned int len = problem_data->regno_len[uregno];
2979 unsigned int sb;
2980 unsigned int lb;
2982 if (!df_compute_accessed_bytes (use, DF_MM_MAY, &sb, &lb))
2984 start += sb;
2985 len = lb - sb;
2988 /* Add use to set of uses in this BB. */
2989 if (len)
2990 bitmap_set_range (live, start, len);
2995 /* Apply the artificial uses and defs at the top of BB in a forwards
2996 direction. */
2998 void
2999 df_byte_lr_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
3001 struct df_byte_lr_problem_data *problem_data
3002 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
3003 df_ref *def_rec;
3004 #ifdef EH_USES
3005 df_ref *use_rec;
3006 #endif
3007 int bb_index = bb->index;
3009 #ifdef EH_USES
3010 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3012 df_ref use = *use_rec;
3013 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3015 unsigned int uregno = DF_REF_REGNO (use);
3016 unsigned int start = problem_data->regno_start[uregno];
3017 unsigned int len = problem_data->regno_len[uregno];
3018 bitmap_set_range (live, start, len);
3021 #endif
3023 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3025 df_ref def = *def_rec;
3026 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3028 unsigned int dregno = DF_REF_REGNO (def);
3029 unsigned int start = problem_data->regno_start[dregno];
3030 unsigned int len = problem_data->regno_len[dregno];
3031 bitmap_clear_range (live, start, len);
3037 /* Apply the artificial uses and defs at the end of BB in a backwards
3038 direction. */
3040 void
3041 df_byte_lr_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3043 struct df_byte_lr_problem_data *problem_data
3044 = (struct df_byte_lr_problem_data *)df_byte_lr->problem_data;
3045 df_ref *def_rec;
3046 df_ref *use_rec;
3047 int bb_index = bb->index;
3049 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3051 df_ref def = *def_rec;
3052 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3054 unsigned int dregno = DF_REF_REGNO (def);
3055 unsigned int start = problem_data->regno_start[dregno];
3056 unsigned int len = problem_data->regno_len[dregno];
3057 bitmap_clear_range (live, start, len);
3061 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3063 df_ref use = *use_rec;
3064 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3066 unsigned int uregno = DF_REF_REGNO (use);
3067 unsigned int start = problem_data->regno_start[uregno];
3068 unsigned int len = problem_data->regno_len[uregno];
3069 bitmap_set_range (live, start, len);
3076 /*----------------------------------------------------------------------------
3077 This problem computes REG_DEAD and REG_UNUSED notes.
3078 ----------------------------------------------------------------------------*/
3080 static void
3081 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3083 df_note->optional_p = true;
3086 #ifdef REG_DEAD_DEBUGGING
3087 static void
3088 df_print_note (const char *prefix, rtx insn, rtx note)
3090 if (dump_file)
3092 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
3093 print_rtl (dump_file, note);
3094 fprintf (dump_file, "\n");
3097 #endif
3100 /* After reg-stack, the x86 floating point stack regs are difficult to
3101 analyze because of all of the pushes, pops and rotations. Thus, we
3102 just leave the notes alone. */
3104 #ifdef STACK_REGS
3105 static inline bool
3106 df_ignore_stack_reg (int regno)
3108 return regstack_completed
3109 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
3111 #else
3112 static inline bool
3113 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
3115 return false;
3117 #endif
3120 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
3121 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
3123 static void
3124 df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
3126 rtx *pprev = &REG_NOTES (insn);
3127 rtx link = *pprev;
3128 rtx dead = NULL;
3129 rtx unused = NULL;
3131 while (link)
3133 switch (REG_NOTE_KIND (link))
3135 case REG_DEAD:
3136 /* After reg-stack, we need to ignore any unused notes
3137 for the stack registers. */
3138 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3140 pprev = &XEXP (link, 1);
3141 link = *pprev;
3143 else
3145 rtx next = XEXP (link, 1);
3146 #ifdef REG_DEAD_DEBUGGING
3147 df_print_note ("deleting: ", insn, link);
3148 #endif
3149 XEXP (link, 1) = dead;
3150 dead = link;
3151 *pprev = link = next;
3153 break;
3155 case REG_UNUSED:
3156 /* After reg-stack, we need to ignore any unused notes
3157 for the stack registers. */
3158 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3160 pprev = &XEXP (link, 1);
3161 link = *pprev;
3163 else
3165 rtx next = XEXP (link, 1);
3166 #ifdef REG_DEAD_DEBUGGING
3167 df_print_note ("deleting: ", insn, link);
3168 #endif
3169 XEXP (link, 1) = unused;
3170 unused = link;
3171 *pprev = link = next;
3173 break;
3175 default:
3176 pprev = &XEXP (link, 1);
3177 link = *pprev;
3178 break;
3182 *old_dead_notes = dead;
3183 *old_unused_notes = unused;
3187 /* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
3188 list, otherwise create a new one. */
3190 static inline rtx
3191 df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
3193 rtx curr = old;
3194 rtx prev = NULL;
3196 gcc_assert (!DEBUG_INSN_P (insn));
3198 while (curr)
3199 if (XEXP (curr, 0) == reg)
3201 if (prev)
3202 XEXP (prev, 1) = XEXP (curr, 1);
3203 else
3204 old = XEXP (curr, 1);
3205 XEXP (curr, 1) = REG_NOTES (insn);
3206 REG_NOTES (insn) = curr;
3207 return old;
3209 else
3211 prev = curr;
3212 curr = XEXP (curr, 1);
3215 /* Did not find the note. */
3216 add_reg_note (insn, note_type, reg);
3217 return old;
3220 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
3221 arguments. Return true if the register value described by MWS's
3222 mw_reg is known to be completely unused, and if mw_reg can therefore
3223 be used in a REG_UNUSED note. */
3225 static bool
3226 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
3227 bitmap live, bitmap artificial_uses)
3229 unsigned int r;
3231 /* If MWS describes a partial reference, create REG_UNUSED notes for
3232 individual hard registers. */
3233 if (mws->flags & DF_REF_PARTIAL)
3234 return false;
3236 /* Likewise if some part of the register is used. */
3237 for (r = mws->start_regno; r <= mws->end_regno; r++)
3238 if (bitmap_bit_p (live, r)
3239 || bitmap_bit_p (artificial_uses, r))
3240 return false;
3242 gcc_assert (REG_P (mws->mw_reg));
3243 return true;
3246 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
3247 based on the bits in LIVE. Do not generate notes for registers in
3248 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
3249 not generated if the reg is both read and written by the
3250 instruction.
3253 static rtx
3254 df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3255 bitmap live, bitmap do_not_gen,
3256 bitmap artificial_uses)
3258 unsigned int r;
3260 #ifdef REG_DEAD_DEBUGGING
3261 if (dump_file)
3262 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
3263 mws->start_regno, mws->end_regno);
3264 #endif
3266 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
3268 unsigned int regno = mws->start_regno;
3269 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
3271 #ifdef REG_DEAD_DEBUGGING
3272 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3273 #endif
3274 bitmap_set_bit (do_not_gen, regno);
3275 /* Only do this if the value is totally dead. */
3277 else
3278 for (r = mws->start_regno; r <= mws->end_regno; r++)
3280 if (!bitmap_bit_p (live, r)
3281 && !bitmap_bit_p (artificial_uses, r))
3283 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
3284 #ifdef REG_DEAD_DEBUGGING
3285 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3286 #endif
3288 bitmap_set_bit (do_not_gen, r);
3290 return old;
3294 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
3295 arguments. Return true if the register value described by MWS's
3296 mw_reg is known to be completely dead, and if mw_reg can therefore
3297 be used in a REG_DEAD note. */
3299 static bool
3300 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
3301 bitmap live, bitmap artificial_uses,
3302 bitmap do_not_gen)
3304 unsigned int r;
3306 /* If MWS describes a partial reference, create REG_DEAD notes for
3307 individual hard registers. */
3308 if (mws->flags & DF_REF_PARTIAL)
3309 return false;
3311 /* Likewise if some part of the register is not dead. */
3312 for (r = mws->start_regno; r <= mws->end_regno; r++)
3313 if (bitmap_bit_p (live, r)
3314 || bitmap_bit_p (artificial_uses, r)
3315 || bitmap_bit_p (do_not_gen, r))
3316 return false;
3318 gcc_assert (REG_P (mws->mw_reg));
3319 return true;
3322 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3323 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3324 from being set if the instruction both reads and writes the
3325 register. */
3327 static rtx
3328 df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
3329 bitmap live, bitmap do_not_gen,
3330 bitmap artificial_uses, bool *added_notes_p)
3332 unsigned int r;
3333 bool is_debug = *added_notes_p;
3335 *added_notes_p = false;
3337 #ifdef REG_DEAD_DEBUGGING
3338 if (dump_file)
3340 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3341 mws->start_regno, mws->end_regno);
3342 df_print_regset (dump_file, do_not_gen);
3343 fprintf (dump_file, " live =");
3344 df_print_regset (dump_file, live);
3345 fprintf (dump_file, " artificial uses =");
3346 df_print_regset (dump_file, artificial_uses);
3348 #endif
3350 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
3352 /* Add a dead note for the entire multi word register. */
3353 if (is_debug)
3355 *added_notes_p = true;
3356 return old;
3358 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
3359 #ifdef REG_DEAD_DEBUGGING
3360 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3361 #endif
3363 else
3365 for (r = mws->start_regno; r <= mws->end_regno; r++)
3366 if (!bitmap_bit_p (live, r)
3367 && !bitmap_bit_p (artificial_uses, r)
3368 && !bitmap_bit_p (do_not_gen, r))
3370 if (is_debug)
3372 *added_notes_p = true;
3373 return old;
3375 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
3376 #ifdef REG_DEAD_DEBUGGING
3377 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3378 #endif
3381 return old;
3385 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3386 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3388 static rtx
3389 df_create_unused_note (rtx insn, rtx old, df_ref def,
3390 bitmap live, bitmap artificial_uses)
3392 unsigned int dregno = DF_REF_REGNO (def);
3394 #ifdef REG_DEAD_DEBUGGING
3395 if (dump_file)
3397 fprintf (dump_file, " regular looking at def ");
3398 df_ref_debug (def, dump_file);
3400 #endif
3402 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3403 || bitmap_bit_p (live, dregno)
3404 || bitmap_bit_p (artificial_uses, dregno)
3405 || df_ignore_stack_reg (dregno)))
3407 rtx reg = (DF_REF_LOC (def))
3408 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3409 old = df_set_note (REG_UNUSED, insn, old, reg);
3410 #ifdef REG_DEAD_DEBUGGING
3411 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3412 #endif
3415 return old;
3418 /* Node of a linked list of uses of dead REGs in debug insns. */
3419 struct dead_debug_use
3421 df_ref use;
3422 struct dead_debug_use *next;
3425 /* Linked list of the above, with a bitmap of the REGs in the
3426 list. */
3427 struct dead_debug
3429 struct dead_debug_use *head;
3430 bitmap used;
3431 bitmap to_rescan;
3434 /* Initialize DEBUG to an empty list, and clear USED, if given. */
3435 static inline void
3436 dead_debug_init (struct dead_debug *debug, bitmap used)
3438 debug->head = NULL;
3439 debug->used = used;
3440 debug->to_rescan = NULL;
3441 if (used)
3442 bitmap_clear (used);
3445 /* Reset all debug insns with pending uses. Release the bitmap in it,
3446 unless it is USED. USED must be the same bitmap passed to
3447 dead_debug_init. */
3448 static inline void
3449 dead_debug_finish (struct dead_debug *debug, bitmap used)
3451 struct dead_debug_use *head;
3452 rtx insn = NULL;
3454 if (debug->used != used)
3455 BITMAP_FREE (debug->used);
3457 while ((head = debug->head))
3459 insn = DF_REF_INSN (head->use);
3460 if (!head->next || DF_REF_INSN (head->next->use) != insn)
3462 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3463 df_insn_rescan_debug_internal (insn);
3464 if (debug->to_rescan)
3465 bitmap_clear_bit (debug->to_rescan, INSN_UID (insn));
3467 debug->head = head->next;
3468 XDELETE (head);
3471 if (debug->to_rescan)
3473 bitmap_iterator bi;
3474 unsigned int uid;
3476 EXECUTE_IF_SET_IN_BITMAP (debug->to_rescan, 0, uid, bi)
3478 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
3479 if (insn_info)
3480 df_insn_rescan (insn_info->insn);
3482 BITMAP_FREE (debug->to_rescan);
3486 /* Add USE to DEBUG. It must be a dead reference to UREGNO in a debug
3487 insn. Create a bitmap for DEBUG as needed. */
3488 static inline void
3489 dead_debug_add (struct dead_debug *debug, df_ref use, unsigned int uregno)
3491 struct dead_debug_use *newddu = XNEW (struct dead_debug_use);
3493 newddu->use = use;
3494 newddu->next = debug->head;
3495 debug->head = newddu;
3497 if (!debug->used)
3498 debug->used = BITMAP_ALLOC (NULL);
3500 bitmap_set_bit (debug->used, uregno);
3503 /* If UREGNO is referenced by any entry in DEBUG, emit a debug insn
3504 before INSN that binds the REG to a debug temp, and replace all
3505 uses of UREGNO in DEBUG with uses of the debug temp. INSN must be
3506 the insn where UREGNO dies. */
3507 static inline void
3508 dead_debug_insert_before (struct dead_debug *debug, unsigned int uregno,
3509 rtx insn)
3511 struct dead_debug_use **tailp = &debug->head;
3512 struct dead_debug_use *cur;
3513 struct dead_debug_use *uses = NULL;
3514 struct dead_debug_use **usesp = &uses;
3515 rtx reg = NULL;
3516 rtx dval;
3517 rtx bind;
3519 if (!debug->used || !bitmap_clear_bit (debug->used, uregno))
3520 return;
3522 /* Move all uses of uregno from debug->head to uses, setting mode to
3523 the widest referenced mode. */
3524 while ((cur = *tailp))
3526 if (DF_REF_REGNO (cur->use) == uregno)
3528 *usesp = cur;
3529 usesp = &cur->next;
3530 *tailp = cur->next;
3531 cur->next = NULL;
3532 if (!reg
3533 || (GET_MODE_BITSIZE (GET_MODE (reg))
3534 < GET_MODE_BITSIZE (GET_MODE (*DF_REF_REAL_LOC (cur->use)))))
3535 reg = *DF_REF_REAL_LOC (cur->use);
3537 else
3538 tailp = &(*tailp)->next;
3541 gcc_assert (reg);
3543 /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
3544 dval = make_debug_expr_from_rtl (reg);
3546 /* Emit a debug bind insn before the insn in which reg dies. */
3547 bind = gen_rtx_VAR_LOCATION (GET_MODE (reg),
3548 DEBUG_EXPR_TREE_DECL (dval), reg,
3549 VAR_INIT_STATUS_INITIALIZED);
3551 bind = emit_debug_insn_before (bind, insn);
3552 df_insn_rescan (bind);
3554 /* Adjust all uses. */
3555 while ((cur = uses))
3557 if (GET_MODE (*DF_REF_REAL_LOC (cur->use)) == GET_MODE (reg))
3558 *DF_REF_REAL_LOC (cur->use) = dval;
3559 else
3560 *DF_REF_REAL_LOC (cur->use)
3561 = gen_lowpart_SUBREG (GET_MODE (*DF_REF_REAL_LOC (cur->use)), dval);
3562 /* ??? Should we simplify subreg of subreg? */
3563 if (debug->to_rescan == NULL)
3564 debug->to_rescan = BITMAP_ALLOC (NULL);
3565 bitmap_set_bit (debug->to_rescan, INSN_UID (DF_REF_INSN (cur->use)));
3566 uses = cur->next;
3567 XDELETE (cur);
3571 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3572 info: lifetime, bb, and number of defs and uses for basic block
3573 BB. The three bitvectors are scratch regs used here. */
3575 static void
3576 df_note_bb_compute (unsigned int bb_index,
3577 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3579 basic_block bb = BASIC_BLOCK (bb_index);
3580 rtx insn;
3581 df_ref *def_rec;
3582 df_ref *use_rec;
3583 struct dead_debug debug;
3585 dead_debug_init (&debug, NULL);
3587 bitmap_copy (live, df_get_live_out (bb));
3588 bitmap_clear (artificial_uses);
3590 #ifdef REG_DEAD_DEBUGGING
3591 if (dump_file)
3593 fprintf (dump_file, "live at bottom ");
3594 df_print_regset (dump_file, live);
3596 #endif
3598 /* Process the artificial defs and uses at the bottom of the block
3599 to begin processing. */
3600 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3602 df_ref def = *def_rec;
3603 #ifdef REG_DEAD_DEBUGGING
3604 if (dump_file)
3605 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3606 #endif
3608 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3609 bitmap_clear_bit (live, DF_REF_REGNO (def));
3612 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3614 df_ref use = *use_rec;
3615 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3617 unsigned int regno = DF_REF_REGNO (use);
3618 bitmap_set_bit (live, regno);
3620 /* Notes are not generated for any of the artificial registers
3621 at the bottom of the block. */
3622 bitmap_set_bit (artificial_uses, regno);
3626 #ifdef REG_DEAD_DEBUGGING
3627 if (dump_file)
3629 fprintf (dump_file, "live before artificials out ");
3630 df_print_regset (dump_file, live);
3632 #endif
3634 FOR_BB_INSNS_REVERSE (bb, insn)
3636 unsigned int uid = INSN_UID (insn);
3637 struct df_mw_hardreg **mws_rec;
3638 rtx old_dead_notes;
3639 rtx old_unused_notes;
3640 int debug_insn;
3642 if (!INSN_P (insn))
3643 continue;
3645 debug_insn = DEBUG_INSN_P (insn);
3647 bitmap_clear (do_not_gen);
3648 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
3650 /* Process the defs. */
3651 if (CALL_P (insn))
3653 #ifdef REG_DEAD_DEBUGGING
3654 if (dump_file)
3656 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3657 df_print_regset (dump_file, live);
3659 #endif
3660 /* We only care about real sets for calls. Clobbers cannot
3661 be depended on to really die. */
3662 mws_rec = DF_INSN_UID_MWS (uid);
3663 while (*mws_rec)
3665 struct df_mw_hardreg *mws = *mws_rec;
3666 if ((DF_MWS_REG_DEF_P (mws))
3667 && !df_ignore_stack_reg (mws->start_regno))
3668 old_unused_notes
3669 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3670 mws, live, do_not_gen,
3671 artificial_uses);
3672 mws_rec++;
3675 /* All of the defs except the return value are some sort of
3676 clobber. This code is for the return. */
3677 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3679 df_ref def = *def_rec;
3680 unsigned int dregno = DF_REF_REGNO (def);
3681 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3683 old_unused_notes
3684 = df_create_unused_note (insn, old_unused_notes,
3685 def, live, artificial_uses);
3686 bitmap_set_bit (do_not_gen, dregno);
3689 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3690 bitmap_clear_bit (live, dregno);
3693 else
3695 /* Regular insn. */
3696 mws_rec = DF_INSN_UID_MWS (uid);
3697 while (*mws_rec)
3699 struct df_mw_hardreg *mws = *mws_rec;
3700 if (DF_MWS_REG_DEF_P (mws))
3701 old_unused_notes
3702 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3703 mws, live, do_not_gen,
3704 artificial_uses);
3705 mws_rec++;
3708 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3710 df_ref def = *def_rec;
3711 unsigned int dregno = DF_REF_REGNO (def);
3712 old_unused_notes
3713 = df_create_unused_note (insn, old_unused_notes,
3714 def, live, artificial_uses);
3716 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3717 bitmap_set_bit (do_not_gen, dregno);
3719 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3720 bitmap_clear_bit (live, dregno);
3724 /* Process the uses. */
3725 mws_rec = DF_INSN_UID_MWS (uid);
3726 while (*mws_rec)
3728 struct df_mw_hardreg *mws = *mws_rec;
3729 if ((DF_MWS_REG_DEF_P (mws))
3730 && !df_ignore_stack_reg (mws->start_regno))
3732 bool really_add_notes = debug_insn != 0;
3734 old_dead_notes
3735 = df_set_dead_notes_for_mw (insn, old_dead_notes,
3736 mws, live, do_not_gen,
3737 artificial_uses,
3738 &really_add_notes);
3740 if (really_add_notes)
3741 debug_insn = -1;
3743 mws_rec++;
3746 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3748 df_ref use = *use_rec;
3749 unsigned int uregno = DF_REF_REGNO (use);
3751 #ifdef REG_DEAD_DEBUGGING
3752 if (dump_file && !debug_insn)
3754 fprintf (dump_file, " regular looking at use ");
3755 df_ref_debug (use, dump_file);
3757 #endif
3758 if (!bitmap_bit_p (live, uregno))
3760 if (debug_insn)
3762 if (debug_insn > 0)
3764 dead_debug_add (&debug, use, uregno);
3765 continue;
3767 break;
3769 else
3770 dead_debug_insert_before (&debug, uregno, insn);
3772 if ( (!(DF_REF_FLAGS (use)
3773 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3774 && (!bitmap_bit_p (do_not_gen, uregno))
3775 && (!bitmap_bit_p (artificial_uses, uregno))
3776 && (!df_ignore_stack_reg (uregno)))
3778 rtx reg = (DF_REF_LOC (use))
3779 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3780 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
3782 #ifdef REG_DEAD_DEBUGGING
3783 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3784 #endif
3786 /* This register is now live. */
3787 bitmap_set_bit (live, uregno);
3791 while (old_unused_notes)
3793 rtx next = XEXP (old_unused_notes, 1);
3794 free_EXPR_LIST_node (old_unused_notes);
3795 old_unused_notes = next;
3797 while (old_dead_notes)
3799 rtx next = XEXP (old_dead_notes, 1);
3800 free_EXPR_LIST_node (old_dead_notes);
3801 old_dead_notes = next;
3804 if (debug_insn == -1)
3806 /* ??? We could probably do better here, replacing dead
3807 registers with their definitions. */
3808 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3809 df_insn_rescan_debug_internal (insn);
3813 dead_debug_finish (&debug, NULL);
3817 /* Compute register info: lifetime, bb, and number of defs and uses. */
3818 static void
3819 df_note_compute (bitmap all_blocks)
3821 unsigned int bb_index;
3822 bitmap_iterator bi;
3823 bitmap_head live, do_not_gen, artificial_uses;
3825 bitmap_initialize (&live, &df_bitmap_obstack);
3826 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3827 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3829 #ifdef REG_DEAD_DEBUGGING
3830 if (dump_file)
3831 print_rtl_with_bb (dump_file, get_insns());
3832 #endif
3834 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3836 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3839 bitmap_clear (&live);
3840 bitmap_clear (&do_not_gen);
3841 bitmap_clear (&artificial_uses);
3845 /* Free all storage associated with the problem. */
3847 static void
3848 df_note_free (void)
3850 free (df_note);
3854 /* All of the information associated every instance of the problem. */
3856 static struct df_problem problem_NOTE =
3858 DF_NOTE, /* Problem id. */
3859 DF_NONE, /* Direction. */
3860 df_note_alloc, /* Allocate the problem specific data. */
3861 NULL, /* Reset global information. */
3862 NULL, /* Free basic block info. */
3863 df_note_compute, /* Local compute function. */
3864 NULL, /* Init the solution specific data. */
3865 NULL, /* Iterative solver. */
3866 NULL, /* Confluence operator 0. */
3867 NULL, /* Confluence operator n. */
3868 NULL, /* Transfer function. */
3869 NULL, /* Finalize function. */
3870 df_note_free, /* Free all of the problem information. */
3871 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3872 NULL, /* Debugging. */
3873 NULL, /* Debugging start block. */
3874 NULL, /* Debugging end block. */
3875 NULL, /* Incremental solution verify start. */
3876 NULL, /* Incremental solution verify end. */
3877 &problem_LR, /* Dependent problem. */
3878 TV_DF_NOTE, /* Timing variable. */
3879 false /* Reset blocks on dropping out of blocks_to_analyze. */
3883 /* Create a new DATAFLOW instance and add it to an existing instance
3884 of DF. The returned structure is what is used to get at the
3885 solution. */
3887 void
3888 df_note_add_problem (void)
3890 df_add_problem (&problem_NOTE);
3896 /*----------------------------------------------------------------------------
3897 Functions for simulating the effects of single insns.
3899 You can either simulate in the forwards direction, starting from
3900 the top of a block or the backwards direction from the end of the
3901 block. If you go backwards, defs are examined first to clear bits,
3902 then uses are examined to set bits. If you go forwards, defs are
3903 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3904 are examined to clear bits. In either case, the result of examining
3905 a def can be undone (respectively by a use or a REG_UNUSED note).
3907 If you start at the top of the block, use one of DF_LIVE_IN or
3908 DF_LR_IN. If you start at the bottom of the block use one of
3909 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3910 THEY WILL BE DESTROYED.
3911 ----------------------------------------------------------------------------*/
3914 /* Find the set of DEFs for INSN. */
3916 void
3917 df_simulate_find_defs (rtx insn, bitmap defs)
3919 df_ref *def_rec;
3920 unsigned int uid = INSN_UID (insn);
3922 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3924 df_ref def = *def_rec;
3925 bitmap_set_bit (defs, DF_REF_REGNO (def));
3929 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3931 void
3932 df_simulate_find_noclobber_defs (rtx insn, bitmap defs)
3934 df_ref *def_rec;
3935 unsigned int uid = INSN_UID (insn);
3937 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3939 df_ref def = *def_rec;
3940 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3941 bitmap_set_bit (defs, DF_REF_REGNO (def));
3946 /* Simulate the effects of the defs of INSN on LIVE. */
3948 void
3949 df_simulate_defs (rtx insn, bitmap live)
3951 df_ref *def_rec;
3952 unsigned int uid = INSN_UID (insn);
3954 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3956 df_ref def = *def_rec;
3957 unsigned int dregno = DF_REF_REGNO (def);
3959 /* If the def is to only part of the reg, it does
3960 not kill the other defs that reach here. */
3961 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3962 bitmap_clear_bit (live, dregno);
3967 /* Simulate the effects of the uses of INSN on LIVE. */
3969 void
3970 df_simulate_uses (rtx insn, bitmap live)
3972 df_ref *use_rec;
3973 unsigned int uid = INSN_UID (insn);
3975 if (DEBUG_INSN_P (insn))
3976 return;
3978 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3980 df_ref use = *use_rec;
3981 /* Add use to set of uses in this BB. */
3982 bitmap_set_bit (live, DF_REF_REGNO (use));
3987 /* Add back the always live regs in BB to LIVE. */
3989 static inline void
3990 df_simulate_fixup_sets (basic_block bb, bitmap live)
3992 /* These regs are considered always live so if they end up dying
3993 because of some def, we need to bring the back again. */
3994 if (bb_has_eh_pred (bb))
3995 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3996 else
3997 bitmap_ior_into (live, &df->regular_block_artificial_uses);
4001 /*----------------------------------------------------------------------------
4002 The following three functions are used only for BACKWARDS scanning:
4003 i.e. they process the defs before the uses.
4005 df_simulate_initialize_backwards should be called first with a
4006 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
4007 df_simulate_one_insn_backwards should be called for each insn in
4008 the block, starting with the last one. Finally,
4009 df_simulate_finalize_backwards can be called to get a new value
4010 of the sets at the top of the block (this is rarely used).
4011 ----------------------------------------------------------------------------*/
4013 /* Apply the artificial uses and defs at the end of BB in a backwards
4014 direction. */
4016 void
4017 df_simulate_initialize_backwards (basic_block bb, bitmap live)
4019 df_ref *def_rec;
4020 df_ref *use_rec;
4021 int bb_index = bb->index;
4023 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4025 df_ref def = *def_rec;
4026 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
4027 bitmap_clear_bit (live, DF_REF_REGNO (def));
4030 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4032 df_ref use = *use_rec;
4033 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
4034 bitmap_set_bit (live, DF_REF_REGNO (use));
4039 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
4041 void
4042 df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
4044 if (!NONDEBUG_INSN_P (insn))
4045 return;
4047 df_simulate_defs (insn, live);
4048 df_simulate_uses (insn, live);
4049 df_simulate_fixup_sets (bb, live);
4053 /* Apply the artificial uses and defs at the top of BB in a backwards
4054 direction. */
4056 void
4057 df_simulate_finalize_backwards (basic_block bb, bitmap live)
4059 df_ref *def_rec;
4060 #ifdef EH_USES
4061 df_ref *use_rec;
4062 #endif
4063 int bb_index = bb->index;
4065 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4067 df_ref def = *def_rec;
4068 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4069 bitmap_clear_bit (live, DF_REF_REGNO (def));
4072 #ifdef EH_USES
4073 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4075 df_ref use = *use_rec;
4076 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
4077 bitmap_set_bit (live, DF_REF_REGNO (use));
4079 #endif
4081 /*----------------------------------------------------------------------------
4082 The following three functions are used only for FORWARDS scanning:
4083 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
4084 Thus it is important to add the DF_NOTES problem to the stack of
4085 problems computed before using these functions.
4087 df_simulate_initialize_forwards should be called first with a
4088 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
4089 df_simulate_one_insn_forwards should be called for each insn in
4090 the block, starting with the first one.
4091 ----------------------------------------------------------------------------*/
4093 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
4094 DF_LR_IN for basic block BB, for forward scanning by marking artificial
4095 defs live. */
4097 void
4098 df_simulate_initialize_forwards (basic_block bb, bitmap live)
4100 df_ref *def_rec;
4101 int bb_index = bb->index;
4103 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4105 df_ref def = *def_rec;
4106 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4107 bitmap_set_bit (live, DF_REF_REGNO (def));
4111 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
4113 void
4114 df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
4116 rtx link;
4117 if (! INSN_P (insn))
4118 return;
4120 /* Make sure that DF_NOTE really is an active df problem. */
4121 gcc_assert (df_note);
4123 /* Note that this is the opposite as how the problem is defined, because
4124 in the LR problem defs _kill_ liveness. However, they do so backwards,
4125 while here the scan is performed forwards! So, first assume that the
4126 def is live, and if this is not true REG_UNUSED notes will rectify the
4127 situation. */
4128 df_simulate_find_noclobber_defs (insn, live);
4130 /* Clear all of the registers that go dead. */
4131 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
4133 switch (REG_NOTE_KIND (link))
4135 case REG_DEAD:
4136 case REG_UNUSED:
4138 rtx reg = XEXP (link, 0);
4139 int regno = REGNO (reg);
4140 if (regno < FIRST_PSEUDO_REGISTER)
4142 int n = hard_regno_nregs[regno][GET_MODE (reg)];
4143 while (--n >= 0)
4144 bitmap_clear_bit (live, regno + n);
4146 else
4147 bitmap_clear_bit (live, regno);
4149 break;
4150 default:
4151 break;
4154 df_simulate_fixup_sets (bb, live);
4159 /*----------------------------------------------------------------------------
4160 MULTIPLE DEFINITIONS
4162 Find the locations in the function reached by multiple definition sites
4163 for a live pseudo. In and out bitvectors are built for each basic
4164 block. They are restricted for efficiency to live registers.
4166 The gen and kill sets for the problem are obvious. Together they
4167 include all defined registers in a basic block; the gen set includes
4168 registers where a partial or conditional or may-clobber definition is
4169 last in the BB, while the kill set includes registers with a complete
4170 definition coming last. However, the computation of the dataflow
4171 itself is interesting.
4173 The idea behind it comes from SSA form's iterated dominance frontier
4174 criterion for inserting PHI functions. Just like in that case, we can use
4175 the dominance frontier to find places where multiple definitions meet;
4176 a register X defined in a basic block BB1 has multiple definitions in
4177 basic blocks in BB1's dominance frontier.
4179 So, the in-set of a basic block BB2 is not just the union of the
4180 out-sets of BB2's predecessors, but includes some more bits that come
4181 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
4182 the previous paragraph). I called this set the init-set of BB2.
4184 (Note: I actually use the kill-set only to build the init-set.
4185 gen bits are anyway propagated from BB1 to BB2 by dataflow).
4187 For example, if you have
4189 BB1 : r10 = 0
4190 r11 = 0
4191 if <...> goto BB2 else goto BB3;
4193 BB2 : r10 = 1
4194 r12 = 1
4195 goto BB3;
4197 BB3 :
4199 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
4200 init-set of BB3 includes r10 and r12, but not r11. Note that we do
4201 not need to iterate the dominance frontier, because we do not insert
4202 anything like PHI functions there! Instead, dataflow will take care of
4203 propagating the information to BB3's successors.
4204 ---------------------------------------------------------------------------*/
4206 /* Private data used to verify the solution for this problem. */
4207 struct df_md_problem_data
4209 /* An obstack for the bitmaps we need for this problem. */
4210 bitmap_obstack md_bitmaps;
4213 /* Scratch var used by transfer functions. This is used to do md analysis
4214 only for live registers. */
4215 static bitmap_head df_md_scratch;
4217 /* Set basic block info. */
4219 static void
4220 df_md_set_bb_info (unsigned int index,
4221 struct df_md_bb_info *bb_info)
4223 gcc_assert (df_md);
4224 gcc_assert (index < df_md->block_info_size);
4225 df_md->block_info[index] = bb_info;
4229 static void
4230 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
4231 void *vbb_info)
4233 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
4234 if (bb_info)
4236 bitmap_clear (&bb_info->kill);
4237 bitmap_clear (&bb_info->gen);
4238 bitmap_clear (&bb_info->init);
4239 bitmap_clear (&bb_info->in);
4240 bitmap_clear (&bb_info->out);
4241 pool_free (df_md->block_pool, bb_info);
4246 /* Allocate or reset bitmaps for DF_MD. The solution bits are
4247 not touched unless the block is new. */
4249 static void
4250 df_md_alloc (bitmap all_blocks)
4252 unsigned int bb_index;
4253 bitmap_iterator bi;
4254 struct df_md_problem_data *problem_data;
4256 if (!df_md->block_pool)
4257 df_md->block_pool = create_alloc_pool ("df_md_block pool",
4258 sizeof (struct df_md_bb_info), 50);
4260 df_grow_bb_info (df_md);
4261 if (df_md->problem_data)
4262 problem_data = (struct df_md_problem_data *) df_md->problem_data;
4263 else
4265 problem_data = XNEW (struct df_md_problem_data);
4266 df_md->problem_data = problem_data;
4267 bitmap_obstack_initialize (&problem_data->md_bitmaps);
4269 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
4271 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4273 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4274 if (bb_info)
4276 bitmap_clear (&bb_info->init);
4277 bitmap_clear (&bb_info->gen);
4278 bitmap_clear (&bb_info->kill);
4279 bitmap_clear (&bb_info->in);
4280 bitmap_clear (&bb_info->out);
4282 else
4284 bb_info = (struct df_md_bb_info *) pool_alloc (df_md->block_pool);
4285 df_md_set_bb_info (bb_index, bb_info);
4286 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4287 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4288 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4289 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4290 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
4294 df_md->optional_p = true;
4297 /* Add the effect of the top artificial defs of BB to the multiple definitions
4298 bitmap LOCAL_MD. */
4300 void
4301 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4303 int bb_index = bb->index;
4304 df_ref *def_rec;
4305 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4307 df_ref def = *def_rec;
4308 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4310 unsigned int dregno = DF_REF_REGNO (def);
4311 if (DF_REF_FLAGS (def)
4312 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4313 bitmap_set_bit (local_md, dregno);
4314 else
4315 bitmap_clear_bit (local_md, dregno);
4321 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4322 LOCAL_MD. */
4324 void
4325 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
4326 bitmap local_md)
4328 unsigned uid = INSN_UID (insn);
4329 df_ref *def_rec;
4331 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4333 df_ref def = *def_rec;
4334 unsigned int dregno = DF_REF_REGNO (def);
4335 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4336 || (dregno >= FIRST_PSEUDO_REGISTER))
4338 if (DF_REF_FLAGS (def)
4339 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4340 bitmap_set_bit (local_md, DF_REF_ID (def));
4341 else
4342 bitmap_clear_bit (local_md, DF_REF_ID (def));
4347 static void
4348 df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
4349 df_ref *def_rec,
4350 int top_flag)
4352 df_ref def;
4353 bitmap_clear (&seen_in_insn);
4355 while ((def = *def_rec++) != NULL)
4357 unsigned int dregno = DF_REF_REGNO (def);
4358 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4359 || (dregno >= FIRST_PSEUDO_REGISTER))
4360 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4362 if (!bitmap_bit_p (&seen_in_insn, dregno))
4364 if (DF_REF_FLAGS (def)
4365 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4367 bitmap_set_bit (&bb_info->gen, dregno);
4368 bitmap_clear_bit (&bb_info->kill, dregno);
4370 else
4372 /* When we find a clobber and a regular def,
4373 make sure the regular def wins. */
4374 bitmap_set_bit (&seen_in_insn, dregno);
4375 bitmap_set_bit (&bb_info->kill, dregno);
4376 bitmap_clear_bit (&bb_info->gen, dregno);
4384 /* Compute local multiple def info for basic block BB. */
4386 static void
4387 df_md_bb_local_compute (unsigned int bb_index)
4389 basic_block bb = BASIC_BLOCK (bb_index);
4390 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4391 rtx insn;
4393 /* Artificials are only hard regs. */
4394 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4395 df_md_bb_local_compute_process_def (bb_info,
4396 df_get_artificial_defs (bb_index),
4397 DF_REF_AT_TOP);
4399 FOR_BB_INSNS (bb, insn)
4401 unsigned int uid = INSN_UID (insn);
4402 if (!INSN_P (insn))
4403 continue;
4405 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4408 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4409 df_md_bb_local_compute_process_def (bb_info,
4410 df_get_artificial_defs (bb_index),
4414 /* Compute local reaching def info for each basic block within BLOCKS. */
4416 static void
4417 df_md_local_compute (bitmap all_blocks)
4419 unsigned int bb_index, df_bb_index;
4420 bitmap_iterator bi1, bi2;
4421 basic_block bb;
4422 bitmap_head *frontiers;
4424 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4426 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4428 df_md_bb_local_compute (bb_index);
4431 bitmap_clear (&seen_in_insn);
4433 frontiers = XNEWVEC (bitmap_head, last_basic_block);
4434 FOR_ALL_BB (bb)
4435 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4437 compute_dominance_frontiers (frontiers);
4439 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4440 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4442 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4443 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4445 basic_block bb = BASIC_BLOCK (df_bb_index);
4446 if (bitmap_bit_p (all_blocks, df_bb_index))
4447 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4448 df_get_live_in (bb));
4452 FOR_ALL_BB (bb)
4453 bitmap_clear (&frontiers[bb->index]);
4454 free (frontiers);
4458 /* Reset the global solution for recalculation. */
4460 static void
4461 df_md_reset (bitmap all_blocks)
4463 unsigned int bb_index;
4464 bitmap_iterator bi;
4466 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4468 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4469 gcc_assert (bb_info);
4470 bitmap_clear (&bb_info->in);
4471 bitmap_clear (&bb_info->out);
4475 static bool
4476 df_md_transfer_function (int bb_index)
4478 basic_block bb = BASIC_BLOCK (bb_index);
4479 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4480 bitmap in = &bb_info->in;
4481 bitmap out = &bb_info->out;
4482 bitmap gen = &bb_info->gen;
4483 bitmap kill = &bb_info->kill;
4485 /* We need to use a scratch set here so that the value returned from this
4486 function invocation properly reflects whether the sets changed in a
4487 significant way; i.e. not just because the live set was anded in. */
4488 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4490 /* Multiple definitions of a register are not relevant if it is not
4491 live. Thus we trim the result to the places where it is live. */
4492 bitmap_and_into (in, df_get_live_in (bb));
4494 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4497 /* Initialize the solution bit vectors for problem. */
4499 static void
4500 df_md_init (bitmap all_blocks)
4502 unsigned int bb_index;
4503 bitmap_iterator bi;
4505 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4507 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4509 bitmap_copy (&bb_info->in, &bb_info->init);
4510 df_md_transfer_function (bb_index);
4514 static void
4515 df_md_confluence_0 (basic_block bb)
4517 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4518 bitmap_copy (&bb_info->in, &bb_info->init);
4521 /* In of target gets or of out of source. */
4523 static void
4524 df_md_confluence_n (edge e)
4526 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4527 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4529 if (e->flags & EDGE_FAKE)
4530 return;
4532 if (e->flags & EDGE_EH)
4533 bitmap_ior_and_compl_into (op1, op2, regs_invalidated_by_call_regset);
4534 else
4535 bitmap_ior_into (op1, op2);
4538 /* Free all storage associated with the problem. */
4540 static void
4541 df_md_free (void)
4543 struct df_md_problem_data *problem_data
4544 = (struct df_md_problem_data *) df_md->problem_data;
4546 bitmap_obstack_release (&problem_data->md_bitmaps);
4547 free_alloc_pool (df_md->block_pool);
4549 df_md->block_info_size = 0;
4550 free (df_md->block_info);
4551 free (df_md);
4555 /* Debugging info at top of bb. */
4557 static void
4558 df_md_top_dump (basic_block bb, FILE *file)
4560 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4561 if (!bb_info)
4562 return;
4564 fprintf (file, ";; md in \t");
4565 df_print_regset (file, &bb_info->in);
4566 fprintf (file, ";; md init \t");
4567 df_print_regset (file, &bb_info->init);
4568 fprintf (file, ";; md gen \t");
4569 df_print_regset (file, &bb_info->gen);
4570 fprintf (file, ";; md kill \t");
4571 df_print_regset (file, &bb_info->kill);
4574 /* Debugging info at bottom of bb. */
4576 static void
4577 df_md_bottom_dump (basic_block bb, FILE *file)
4579 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4580 if (!bb_info)
4581 return;
4583 fprintf (file, ";; md out \t");
4584 df_print_regset (file, &bb_info->out);
4587 static struct df_problem problem_MD =
4589 DF_MD, /* Problem id. */
4590 DF_FORWARD, /* Direction. */
4591 df_md_alloc, /* Allocate the problem specific data. */
4592 df_md_reset, /* Reset global information. */
4593 df_md_free_bb_info, /* Free basic block info. */
4594 df_md_local_compute, /* Local compute function. */
4595 df_md_init, /* Init the solution specific data. */
4596 df_worklist_dataflow, /* Worklist solver. */
4597 df_md_confluence_0, /* Confluence operator 0. */
4598 df_md_confluence_n, /* Confluence operator n. */
4599 df_md_transfer_function, /* Transfer function. */
4600 NULL, /* Finalize function. */
4601 df_md_free, /* Free all of the problem information. */
4602 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4603 NULL, /* Debugging. */
4604 df_md_top_dump, /* Debugging start block. */
4605 df_md_bottom_dump, /* Debugging end block. */
4606 NULL, /* Incremental solution verify start. */
4607 NULL, /* Incremental solution verify end. */
4608 NULL, /* Dependent problem. */
4609 TV_DF_MD, /* Timing variable. */
4610 false /* Reset blocks on dropping out of blocks_to_analyze. */
4613 /* Create a new MD instance and add it to the existing instance
4614 of DF. */
4616 void
4617 df_md_add_problem (void)
4619 df_add_problem (&problem_MD);