]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/df-problems.c
Fix missed IPA-CP on by-ref argument directly passed through (PR 93429)
[thirdparty/gcc.git] / gcc / df-problems.c
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999-2020 Free Software Foundation, Inc.
3 Originally contributed by Michael P. Hayes
4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
6 and Kenneth Zadeck (zadeck@naturalbridge.com).
7
8 This file is part of GCC.
9
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
14
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "backend.h"
28 #include "target.h"
29 #include "rtl.h"
30 #include "df.h"
31 #include "memmodel.h"
32 #include "tm_p.h"
33 #include "insn-config.h"
34 #include "cfganal.h"
35 #include "dce.h"
36 #include "valtrack.h"
37 #include "dumpfile.h"
38 #include "rtl-iter.h"
39 #include "regs.h"
40 #include "function-abi.h"
41
42 /* Note that turning REG_DEAD_DEBUGGING on will cause
43 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
44 addresses in the dumps. */
45 #define REG_DEAD_DEBUGGING 0
46
47 #define DF_SPARSE_THRESHOLD 32
48
49 static bitmap_head seen_in_block;
50 static bitmap_head seen_in_insn;
51
52 /*----------------------------------------------------------------------------
53 Utility functions.
54 ----------------------------------------------------------------------------*/
55
56 /* Generic versions to get the void* version of the block info. Only
57 used inside the problem instance vectors. */
58
59 /* Dump a def-use or use-def chain for REF to FILE. */
60
61 void
62 df_chain_dump (struct df_link *link, FILE *file)
63 {
64 fprintf (file, "{ ");
65 for (; link; link = link->next)
66 {
67 fprintf (file, "%c%d(bb %d insn %d) ",
68 DF_REF_REG_DEF_P (link->ref)
69 ? 'd'
70 : (DF_REF_FLAGS (link->ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
71 DF_REF_ID (link->ref),
72 DF_REF_BBNO (link->ref),
73 DF_REF_IS_ARTIFICIAL (link->ref)
74 ? -1 : DF_REF_INSN_UID (link->ref));
75 }
76 fprintf (file, "}");
77 }
78
79
80 /* Print some basic block info as part of df_dump. */
81
82 void
83 df_print_bb_index (basic_block bb, FILE *file)
84 {
85 edge e;
86 edge_iterator ei;
87
88 fprintf (file, "\n( ");
89 FOR_EACH_EDGE (e, ei, bb->preds)
90 {
91 basic_block pred = e->src;
92 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
93 }
94 fprintf (file, ")->[%d]->( ", bb->index);
95 FOR_EACH_EDGE (e, ei, bb->succs)
96 {
97 basic_block succ = e->dest;
98 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
99 }
100 fprintf (file, ")\n");
101 }
102
103 \f
104 /*----------------------------------------------------------------------------
105 REACHING DEFINITIONS
106
107 Find the locations in the function where each definition site for a
108 pseudo reaches. In and out bitvectors are built for each basic
109 block. The id field in the ref is used to index into these sets.
110 See df.h for details.
111
112 If the DF_RD_PRUNE_DEAD_DEFS changeable flag is set, only DEFs reaching
113 existing uses are included in the global reaching DEFs set, or in other
114 words only DEFs that are still live. This is a kind of pruned version
115 of the traditional reaching definitions problem that is much less
116 complex to compute and produces enough information to compute UD-chains.
117 In this context, live must be interpreted in the DF_LR sense: Uses that
118 are upward exposed but maybe not initialized on all paths through the
119 CFG. For a USE that is not reached by a DEF on all paths, we still want
120 to make those DEFs that do reach the USE visible, and pruning based on
121 DF_LIVE would make that impossible.
122 ----------------------------------------------------------------------------*/
123
124 /* This problem plays a large number of games for the sake of
125 efficiency.
126
127 1) The order of the bits in the bitvectors. After the scanning
128 phase, all of the defs are sorted. All of the defs for the reg 0
129 are first, followed by all defs for reg 1 and so on.
130
131 2) There are two kill sets, one if the number of defs is less or
132 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
133 greater.
134
135 <= : Data is built directly in the kill set.
136
137 > : One level of indirection is used to keep from generating long
138 strings of 1 bits in the kill sets. Bitvectors that are indexed
139 by the regnum are used to represent that there is a killing def
140 for the register. The confluence and transfer functions use
141 these along with the bitmap_clear_range call to remove ranges of
142 bits without actually generating a knockout vector.
143
144 The kill and sparse_kill and the dense_invalidated_by_eh and
145 sparse_invalidated_by_eh both play this game. */
146
147 /* Private data used to compute the solution for this problem. These
148 data structures are not accessible outside of this module. */
149 class df_rd_problem_data
150 {
151 public:
152 /* The set of defs to regs invalidated by EH edges. */
153 bitmap_head sparse_invalidated_by_eh;
154 bitmap_head dense_invalidated_by_eh;
155 /* An obstack for the bitmaps we need for this problem. */
156 bitmap_obstack rd_bitmaps;
157 };
158
159
160 /* Free basic block info. */
161
162 static void
163 df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
164 void *vbb_info)
165 {
166 class df_rd_bb_info *bb_info = (class df_rd_bb_info *) vbb_info;
167 if (bb_info)
168 {
169 bitmap_clear (&bb_info->kill);
170 bitmap_clear (&bb_info->sparse_kill);
171 bitmap_clear (&bb_info->gen);
172 bitmap_clear (&bb_info->in);
173 bitmap_clear (&bb_info->out);
174 }
175 }
176
177
178 /* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
179 not touched unless the block is new. */
180
181 static void
182 df_rd_alloc (bitmap all_blocks)
183 {
184 unsigned int bb_index;
185 bitmap_iterator bi;
186 class df_rd_problem_data *problem_data;
187
188 if (df_rd->problem_data)
189 {
190 problem_data = (class df_rd_problem_data *) df_rd->problem_data;
191 bitmap_clear (&problem_data->sparse_invalidated_by_eh);
192 bitmap_clear (&problem_data->dense_invalidated_by_eh);
193 }
194 else
195 {
196 problem_data = XNEW (class df_rd_problem_data);
197 df_rd->problem_data = problem_data;
198
199 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
200 bitmap_initialize (&problem_data->sparse_invalidated_by_eh,
201 &problem_data->rd_bitmaps);
202 bitmap_initialize (&problem_data->dense_invalidated_by_eh,
203 &problem_data->rd_bitmaps);
204 }
205
206 df_grow_bb_info (df_rd);
207
208 /* Because of the clustering of all use sites for the same pseudo,
209 we have to process all of the blocks before doing the analysis. */
210
211 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
212 {
213 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
214
215 /* When bitmaps are already initialized, just clear them. */
216 if (bb_info->kill.obstack)
217 {
218 bitmap_clear (&bb_info->kill);
219 bitmap_clear (&bb_info->sparse_kill);
220 bitmap_clear (&bb_info->gen);
221 }
222 else
223 {
224 bitmap_initialize (&bb_info->kill, &problem_data->rd_bitmaps);
225 bitmap_initialize (&bb_info->sparse_kill, &problem_data->rd_bitmaps);
226 bitmap_initialize (&bb_info->gen, &problem_data->rd_bitmaps);
227 bitmap_initialize (&bb_info->in, &problem_data->rd_bitmaps);
228 bitmap_initialize (&bb_info->out, &problem_data->rd_bitmaps);
229 }
230 }
231 df_rd->optional_p = true;
232 }
233
234
235 /* Add the effect of the top artificial defs of BB to the reaching definitions
236 bitmap LOCAL_RD. */
237
238 void
239 df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
240 {
241 int bb_index = bb->index;
242 df_ref def;
243 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
244 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
245 {
246 unsigned int dregno = DF_REF_REGNO (def);
247 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
248 bitmap_clear_range (local_rd,
249 DF_DEFS_BEGIN (dregno),
250 DF_DEFS_COUNT (dregno));
251 bitmap_set_bit (local_rd, DF_REF_ID (def));
252 }
253 }
254
255 /* Add the effect of the defs of INSN to the reaching definitions bitmap
256 LOCAL_RD. */
257
258 void
259 df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
260 bitmap local_rd)
261 {
262 df_ref def;
263
264 FOR_EACH_INSN_DEF (def, insn)
265 {
266 unsigned int dregno = DF_REF_REGNO (def);
267 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
268 || (dregno >= FIRST_PSEUDO_REGISTER))
269 {
270 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
271 bitmap_clear_range (local_rd,
272 DF_DEFS_BEGIN (dregno),
273 DF_DEFS_COUNT (dregno));
274 if (!(DF_REF_FLAGS (def)
275 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
276 bitmap_set_bit (local_rd, DF_REF_ID (def));
277 }
278 }
279 }
280
281 /* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
282 more complicated than just simulating, because we must produce the
283 gen and kill sets and hence deal with the two possible representations
284 of kill sets. */
285
286 static void
287 df_rd_bb_local_compute_process_def (class df_rd_bb_info *bb_info,
288 df_ref def,
289 int top_flag)
290 {
291 for (; def; def = DF_REF_NEXT_LOC (def))
292 {
293 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
294 {
295 unsigned int regno = DF_REF_REGNO (def);
296 unsigned int begin = DF_DEFS_BEGIN (regno);
297 unsigned int n_defs = DF_DEFS_COUNT (regno);
298
299 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
300 || (regno >= FIRST_PSEUDO_REGISTER))
301 {
302 /* Only the last def(s) for a regno in the block has any
303 effect. */
304 if (!bitmap_bit_p (&seen_in_block, regno))
305 {
306 /* The first def for regno in insn gets to knock out the
307 defs from other instructions. */
308 if ((!bitmap_bit_p (&seen_in_insn, regno))
309 /* If the def is to only part of the reg, it does
310 not kill the other defs that reach here. */
311 && (!(DF_REF_FLAGS (def) &
312 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
313 {
314 if (n_defs > DF_SPARSE_THRESHOLD)
315 {
316 bitmap_set_bit (&bb_info->sparse_kill, regno);
317 bitmap_clear_range (&bb_info->gen, begin, n_defs);
318 }
319 else
320 {
321 bitmap_set_range (&bb_info->kill, begin, n_defs);
322 bitmap_clear_range (&bb_info->gen, begin, n_defs);
323 }
324 }
325
326 bitmap_set_bit (&seen_in_insn, regno);
327 /* All defs for regno in the instruction may be put into
328 the gen set. */
329 if (!(DF_REF_FLAGS (def)
330 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
331 bitmap_set_bit (&bb_info->gen, DF_REF_ID (def));
332 }
333 }
334 }
335 }
336 }
337
338 /* Compute local reaching def info for basic block BB. */
339
340 static void
341 df_rd_bb_local_compute (unsigned int bb_index)
342 {
343 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
344 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
345 rtx_insn *insn;
346
347 bitmap_clear (&seen_in_block);
348 bitmap_clear (&seen_in_insn);
349
350 /* Artificials are only hard regs. */
351 if (!(df->changeable_flags & DF_NO_HARD_REGS))
352 df_rd_bb_local_compute_process_def (bb_info,
353 df_get_artificial_defs (bb_index),
354 0);
355
356 FOR_BB_INSNS_REVERSE (bb, insn)
357 {
358 unsigned int uid = INSN_UID (insn);
359
360 if (!INSN_P (insn))
361 continue;
362
363 df_rd_bb_local_compute_process_def (bb_info,
364 DF_INSN_UID_DEFS (uid), 0);
365
366 /* This complex dance with the two bitmaps is required because
367 instructions can assign twice to the same pseudo. This
368 generally happens with calls that will have one def for the
369 result and another def for the clobber. If only one vector
370 is used and the clobber goes first, the result will be
371 lost. */
372 bitmap_ior_into (&seen_in_block, &seen_in_insn);
373 bitmap_clear (&seen_in_insn);
374 }
375
376 /* Process the artificial defs at the top of the block last since we
377 are going backwards through the block and these are logically at
378 the start. */
379 if (!(df->changeable_flags & DF_NO_HARD_REGS))
380 df_rd_bb_local_compute_process_def (bb_info,
381 df_get_artificial_defs (bb_index),
382 DF_REF_AT_TOP);
383 }
384
385
386 /* Compute local reaching def info for each basic block within BLOCKS. */
387
388 static void
389 df_rd_local_compute (bitmap all_blocks)
390 {
391 unsigned int bb_index;
392 bitmap_iterator bi;
393 class df_rd_problem_data *problem_data
394 = (class df_rd_problem_data *) df_rd->problem_data;
395 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_eh;
396 bitmap dense_invalidated = &problem_data->dense_invalidated_by_eh;
397
398 bitmap_initialize (&seen_in_block, &df_bitmap_obstack);
399 bitmap_initialize (&seen_in_insn, &df_bitmap_obstack);
400
401 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
402
403 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
404 {
405 df_rd_bb_local_compute (bb_index);
406 }
407
408 /* Set up the knockout bit vectors to be applied across EH_EDGES.
409 Conservatively treat partially-clobbered registers as surviving
410 across the EH edge, i.e. assume that definitions before the edge
411 is taken *might* reach uses after it has been taken. */
412 if (!(df->changeable_flags & DF_NO_HARD_REGS))
413 for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
414 if (eh_edge_abi.clobbers_full_reg_p (regno))
415 {
416 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
417 bitmap_set_bit (sparse_invalidated, regno);
418 else
419 bitmap_set_range (dense_invalidated,
420 DF_DEFS_BEGIN (regno),
421 DF_DEFS_COUNT (regno));
422 }
423
424 bitmap_release (&seen_in_block);
425 bitmap_release (&seen_in_insn);
426 }
427
428
429 /* Initialize the solution bit vectors for problem. */
430
431 static void
432 df_rd_init_solution (bitmap all_blocks)
433 {
434 unsigned int bb_index;
435 bitmap_iterator bi;
436
437 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
438 {
439 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
440
441 bitmap_copy (&bb_info->out, &bb_info->gen);
442 bitmap_clear (&bb_info->in);
443 }
444 }
445
446 /* In of target gets or of out of source. */
447
448 static bool
449 df_rd_confluence_n (edge e)
450 {
451 bitmap op1 = &df_rd_get_bb_info (e->dest->index)->in;
452 bitmap op2 = &df_rd_get_bb_info (e->src->index)->out;
453 bool changed = false;
454
455 if (e->flags & EDGE_FAKE)
456 return false;
457
458 if (e->flags & EDGE_EH)
459 {
460 class df_rd_problem_data *problem_data
461 = (class df_rd_problem_data *) df_rd->problem_data;
462 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_eh;
463 bitmap dense_invalidated = &problem_data->dense_invalidated_by_eh;
464 bitmap_iterator bi;
465 unsigned int regno;
466
467 auto_bitmap tmp (&df_bitmap_obstack);
468 bitmap_and_compl (tmp, op2, dense_invalidated);
469
470 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
471 {
472 bitmap_clear_range (tmp,
473 DF_DEFS_BEGIN (regno),
474 DF_DEFS_COUNT (regno));
475 }
476 changed |= bitmap_ior_into (op1, tmp);
477 return changed;
478 }
479 else
480 return bitmap_ior_into (op1, op2);
481 }
482
483
484 /* Transfer function. */
485
486 static bool
487 df_rd_transfer_function (int bb_index)
488 {
489 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
490 unsigned int regno;
491 bitmap_iterator bi;
492 bitmap in = &bb_info->in;
493 bitmap out = &bb_info->out;
494 bitmap gen = &bb_info->gen;
495 bitmap kill = &bb_info->kill;
496 bitmap sparse_kill = &bb_info->sparse_kill;
497 bool changed = false;
498
499 if (bitmap_empty_p (sparse_kill))
500 changed = bitmap_ior_and_compl (out, gen, in, kill);
501 else
502 {
503 class df_rd_problem_data *problem_data;
504 bitmap_head tmp;
505
506 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
507 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
508 problem_data = (class df_rd_problem_data *) df_rd->problem_data;
509 bitmap_initialize (&tmp, &problem_data->rd_bitmaps);
510
511 bitmap_and_compl (&tmp, in, kill);
512 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
513 {
514 bitmap_clear_range (&tmp,
515 DF_DEFS_BEGIN (regno),
516 DF_DEFS_COUNT (regno));
517 }
518 bitmap_ior_into (&tmp, gen);
519 changed = !bitmap_equal_p (&tmp, out);
520 if (changed)
521 bitmap_move (out, &tmp);
522 else
523 bitmap_clear (&tmp);
524 }
525
526 if (df->changeable_flags & DF_RD_PRUNE_DEAD_DEFS)
527 {
528 /* Create a mask of DEFs for all registers live at the end of this
529 basic block, and mask out DEFs of registers that are not live.
530 Computing the mask looks costly, but the benefit of the pruning
531 outweighs the cost. */
532 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
533 bitmap regs_live_out = &df_lr_get_bb_info (bb_index)->out;
534 bitmap live_defs = BITMAP_ALLOC (&df_bitmap_obstack);
535 unsigned int regno;
536 bitmap_iterator bi;
537
538 EXECUTE_IF_SET_IN_BITMAP (regs_live_out, 0, regno, bi)
539 bitmap_set_range (live_defs,
540 DF_DEFS_BEGIN (regno),
541 DF_DEFS_COUNT (regno));
542 changed |= bitmap_and_into (&bb_info->out, live_defs);
543 BITMAP_FREE (live_defs);
544 }
545
546 return changed;
547 }
548
549 /* Free all storage associated with the problem. */
550
551 static void
552 df_rd_free (void)
553 {
554 class df_rd_problem_data *problem_data
555 = (class df_rd_problem_data *) df_rd->problem_data;
556
557 if (problem_data)
558 {
559 bitmap_obstack_release (&problem_data->rd_bitmaps);
560
561 df_rd->block_info_size = 0;
562 free (df_rd->block_info);
563 df_rd->block_info = NULL;
564 free (df_rd->problem_data);
565 }
566 free (df_rd);
567 }
568
569
570 /* Debugging info. */
571
572 static void
573 df_rd_start_dump (FILE *file)
574 {
575 class df_rd_problem_data *problem_data
576 = (class df_rd_problem_data *) df_rd->problem_data;
577 unsigned int m = DF_REG_SIZE (df);
578 unsigned int regno;
579
580 if (!df_rd->block_info)
581 return;
582
583 fprintf (file, ";; Reaching defs:\n");
584
585 fprintf (file, ";; sparse invalidated \t");
586 dump_bitmap (file, &problem_data->sparse_invalidated_by_eh);
587 fprintf (file, ";; dense invalidated \t");
588 dump_bitmap (file, &problem_data->dense_invalidated_by_eh);
589
590 fprintf (file, ";; reg->defs[] map:\t");
591 for (regno = 0; regno < m; regno++)
592 if (DF_DEFS_COUNT (regno))
593 fprintf (file, "%d[%d,%d] ", regno,
594 DF_DEFS_BEGIN (regno),
595 DF_DEFS_BEGIN (regno) + DF_DEFS_COUNT (regno) - 1);
596 fprintf (file, "\n");
597 }
598
599
600 static void
601 df_rd_dump_defs_set (bitmap defs_set, const char *prefix, FILE *file)
602 {
603 bitmap_head tmp;
604 unsigned int regno;
605 unsigned int m = DF_REG_SIZE (df);
606 bool first_reg = true;
607
608 fprintf (file, "%s\t(%d) ", prefix, (int) bitmap_count_bits (defs_set));
609
610 bitmap_initialize (&tmp, &df_bitmap_obstack);
611 for (regno = 0; regno < m; regno++)
612 {
613 if (HARD_REGISTER_NUM_P (regno)
614 && (df->changeable_flags & DF_NO_HARD_REGS))
615 continue;
616 bitmap_set_range (&tmp, DF_DEFS_BEGIN (regno), DF_DEFS_COUNT (regno));
617 bitmap_and_into (&tmp, defs_set);
618 if (! bitmap_empty_p (&tmp))
619 {
620 bitmap_iterator bi;
621 unsigned int ix;
622 bool first_def = true;
623
624 if (! first_reg)
625 fprintf (file, ",");
626 first_reg = false;
627
628 fprintf (file, "%u[", regno);
629 EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, ix, bi)
630 {
631 fprintf (file, "%s%u", first_def ? "" : ",", ix);
632 first_def = false;
633 }
634 fprintf (file, "]");
635 }
636 bitmap_clear (&tmp);
637 }
638
639 fprintf (file, "\n");
640 bitmap_clear (&tmp);
641 }
642
643 /* Debugging info at top of bb. */
644
645 static void
646 df_rd_top_dump (basic_block bb, FILE *file)
647 {
648 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
649 if (!bb_info)
650 return;
651
652 df_rd_dump_defs_set (&bb_info->in, ";; rd in ", file);
653 df_rd_dump_defs_set (&bb_info->gen, ";; rd gen ", file);
654 df_rd_dump_defs_set (&bb_info->kill, ";; rd kill", file);
655 }
656
657
658 /* Debugging info at bottom of bb. */
659
660 static void
661 df_rd_bottom_dump (basic_block bb, FILE *file)
662 {
663 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
664 if (!bb_info)
665 return;
666
667 df_rd_dump_defs_set (&bb_info->out, ";; rd out ", file);
668 }
669
670 /* All of the information associated with every instance of the problem. */
671
672 static const struct df_problem problem_RD =
673 {
674 DF_RD, /* Problem id. */
675 DF_FORWARD, /* Direction. */
676 df_rd_alloc, /* Allocate the problem specific data. */
677 NULL, /* Reset global information. */
678 df_rd_free_bb_info, /* Free basic block info. */
679 df_rd_local_compute, /* Local compute function. */
680 df_rd_init_solution, /* Init the solution specific data. */
681 df_worklist_dataflow, /* Worklist solver. */
682 NULL, /* Confluence operator 0. */
683 df_rd_confluence_n, /* Confluence operator n. */
684 df_rd_transfer_function, /* Transfer function. */
685 NULL, /* Finalize function. */
686 df_rd_free, /* Free all of the problem information. */
687 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
688 df_rd_start_dump, /* Debugging. */
689 df_rd_top_dump, /* Debugging start block. */
690 df_rd_bottom_dump, /* Debugging end block. */
691 NULL, /* Debugging start insn. */
692 NULL, /* Debugging end insn. */
693 NULL, /* Incremental solution verify start. */
694 NULL, /* Incremental solution verify end. */
695 NULL, /* Dependent problem. */
696 sizeof (class df_rd_bb_info),/* Size of entry of block_info array. */
697 TV_DF_RD, /* Timing variable. */
698 true /* Reset blocks on dropping out of blocks_to_analyze. */
699 };
700
701
702
703 /* Create a new RD instance and add it to the existing instance
704 of DF. */
705
706 void
707 df_rd_add_problem (void)
708 {
709 df_add_problem (&problem_RD);
710 }
711
712
713 \f
714 /*----------------------------------------------------------------------------
715 LIVE REGISTERS
716
717 Find the locations in the function where any use of a pseudo can
718 reach in the backwards direction. In and out bitvectors are built
719 for each basic block. The regno is used to index into these sets.
720 See df.h for details.
721 ----------------------------------------------------------------------------*/
722
723 /* Private data used to verify the solution for this problem. */
724 struct df_lr_problem_data
725 {
726 bitmap_head *in;
727 bitmap_head *out;
728 /* An obstack for the bitmaps we need for this problem. */
729 bitmap_obstack lr_bitmaps;
730 };
731
732 /* Free basic block info. */
733
734 static void
735 df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
736 void *vbb_info)
737 {
738 class df_lr_bb_info *bb_info = (class df_lr_bb_info *) vbb_info;
739 if (bb_info)
740 {
741 bitmap_clear (&bb_info->use);
742 bitmap_clear (&bb_info->def);
743 bitmap_clear (&bb_info->in);
744 bitmap_clear (&bb_info->out);
745 }
746 }
747
748
749 /* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
750 not touched unless the block is new. */
751
752 static void
753 df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
754 {
755 unsigned int bb_index;
756 bitmap_iterator bi;
757 struct df_lr_problem_data *problem_data;
758
759 df_grow_bb_info (df_lr);
760 if (df_lr->problem_data)
761 problem_data = (struct df_lr_problem_data *) df_lr->problem_data;
762 else
763 {
764 problem_data = XNEW (struct df_lr_problem_data);
765 df_lr->problem_data = problem_data;
766
767 problem_data->out = NULL;
768 problem_data->in = NULL;
769 bitmap_obstack_initialize (&problem_data->lr_bitmaps);
770 }
771
772 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
773 {
774 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
775
776 /* When bitmaps are already initialized, just clear them. */
777 if (bb_info->use.obstack)
778 {
779 bitmap_clear (&bb_info->def);
780 bitmap_clear (&bb_info->use);
781 }
782 else
783 {
784 bitmap_initialize (&bb_info->use, &problem_data->lr_bitmaps);
785 bitmap_initialize (&bb_info->def, &problem_data->lr_bitmaps);
786 bitmap_initialize (&bb_info->in, &problem_data->lr_bitmaps);
787 bitmap_initialize (&bb_info->out, &problem_data->lr_bitmaps);
788 }
789 }
790
791 df_lr->optional_p = false;
792 }
793
794
795 /* Reset the global solution for recalculation. */
796
797 static void
798 df_lr_reset (bitmap all_blocks)
799 {
800 unsigned int bb_index;
801 bitmap_iterator bi;
802
803 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
804 {
805 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
806 gcc_assert (bb_info);
807 bitmap_clear (&bb_info->in);
808 bitmap_clear (&bb_info->out);
809 }
810 }
811
812
813 /* Compute local live register info for basic block BB. */
814
815 static void
816 df_lr_bb_local_compute (unsigned int bb_index)
817 {
818 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
819 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
820 rtx_insn *insn;
821 df_ref def, use;
822
823 /* Process the registers set in an exception handler. */
824 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
825 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
826 {
827 unsigned int dregno = DF_REF_REGNO (def);
828 bitmap_set_bit (&bb_info->def, dregno);
829 bitmap_clear_bit (&bb_info->use, dregno);
830 }
831
832 /* Process the hardware registers that are always live. */
833 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
834 /* Add use to set of uses in this BB. */
835 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
836 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
837
838 FOR_BB_INSNS_REVERSE (bb, insn)
839 {
840 if (!NONDEBUG_INSN_P (insn))
841 continue;
842
843 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
844 FOR_EACH_INSN_INFO_DEF (def, insn_info)
845 /* If the def is to only part of the reg, it does
846 not kill the other defs that reach here. */
847 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
848 {
849 unsigned int dregno = DF_REF_REGNO (def);
850 bitmap_set_bit (&bb_info->def, dregno);
851 bitmap_clear_bit (&bb_info->use, dregno);
852 }
853
854 FOR_EACH_INSN_INFO_USE (use, insn_info)
855 /* Add use to set of uses in this BB. */
856 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
857 }
858
859 /* Process the registers set in an exception handler or the hard
860 frame pointer if this block is the target of a non local
861 goto. */
862 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
863 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
864 {
865 unsigned int dregno = DF_REF_REGNO (def);
866 bitmap_set_bit (&bb_info->def, dregno);
867 bitmap_clear_bit (&bb_info->use, dregno);
868 }
869
870 #ifdef EH_USES
871 /* Process the uses that are live into an exception handler. */
872 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
873 /* Add use to set of uses in this BB. */
874 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
875 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
876 #endif
877
878 /* If the df_live problem is not defined, such as at -O0 and -O1, we
879 still need to keep the luids up to date. This is normally done
880 in the df_live problem since this problem has a forwards
881 scan. */
882 if (!df_live)
883 df_recompute_luids (bb);
884 }
885
886
887 /* Compute local live register info for each basic block within BLOCKS. */
888
889 static void
890 df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
891 {
892 unsigned int bb_index, i;
893 bitmap_iterator bi;
894
895 bitmap_clear (&df->hardware_regs_used);
896
897 /* The all-important stack pointer must always be live. */
898 bitmap_set_bit (&df->hardware_regs_used, STACK_POINTER_REGNUM);
899
900 /* Global regs are always live, too. */
901 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
902 if (global_regs[i])
903 bitmap_set_bit (&df->hardware_regs_used, i);
904
905 /* Before reload, there are a few registers that must be forced
906 live everywhere -- which might not already be the case for
907 blocks within infinite loops. */
908 if (!reload_completed)
909 {
910 unsigned int pic_offset_table_regnum = PIC_OFFSET_TABLE_REGNUM;
911 /* Any reference to any pseudo before reload is a potential
912 reference of the frame pointer. */
913 bitmap_set_bit (&df->hardware_regs_used, FRAME_POINTER_REGNUM);
914
915 /* Pseudos with argument area equivalences may require
916 reloading via the argument pointer. */
917 if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
918 && fixed_regs[ARG_POINTER_REGNUM])
919 bitmap_set_bit (&df->hardware_regs_used, ARG_POINTER_REGNUM);
920
921 /* Any constant, or pseudo with constant equivalences, may
922 require reloading from memory using the pic register. */
923 if (pic_offset_table_regnum != INVALID_REGNUM
924 && fixed_regs[pic_offset_table_regnum])
925 bitmap_set_bit (&df->hardware_regs_used, pic_offset_table_regnum);
926 }
927
928 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
929 {
930 if (bb_index == EXIT_BLOCK)
931 {
932 /* The exit block is special for this problem and its bits are
933 computed from thin air. */
934 class df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
935 bitmap_copy (&bb_info->use, df->exit_block_uses);
936 }
937 else
938 df_lr_bb_local_compute (bb_index);
939 }
940
941 bitmap_clear (df_lr->out_of_date_transfer_functions);
942 }
943
944
945 /* Initialize the solution vectors. */
946
947 static void
948 df_lr_init (bitmap all_blocks)
949 {
950 unsigned int bb_index;
951 bitmap_iterator bi;
952
953 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
954 {
955 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
956 bitmap_copy (&bb_info->in, &bb_info->use);
957 bitmap_clear (&bb_info->out);
958 }
959 }
960
961
962 /* Confluence function that processes infinite loops. This might be a
963 noreturn function that throws. And even if it isn't, getting the
964 unwind info right helps debugging. */
965 static void
966 df_lr_confluence_0 (basic_block bb)
967 {
968 bitmap op1 = &df_lr_get_bb_info (bb->index)->out;
969 if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
970 bitmap_copy (op1, &df->hardware_regs_used);
971 }
972
973
974 /* Confluence function that ignores fake edges. */
975
976 static bool
977 df_lr_confluence_n (edge e)
978 {
979 bitmap op1 = &df_lr_get_bb_info (e->src->index)->out;
980 bitmap op2 = &df_lr_get_bb_info (e->dest->index)->in;
981 bool changed = false;
982
983 /* Call-clobbered registers die across exception and call edges.
984 Conservatively treat partially-clobbered registers as surviving
985 across the edges; they might or might not, depending on what
986 mode they have. */
987 /* ??? Abnormal call edges ignored for the moment, as this gets
988 confused by sibling call edges, which crashes reg-stack. */
989 if (e->flags & EDGE_EH)
990 {
991 bitmap_view<HARD_REG_SET> eh_kills (eh_edge_abi.full_reg_clobbers ());
992 changed = bitmap_ior_and_compl_into (op1, op2, eh_kills);
993 }
994 else
995 changed = bitmap_ior_into (op1, op2);
996
997 changed |= bitmap_ior_into (op1, &df->hardware_regs_used);
998 return changed;
999 }
1000
1001
1002 /* Transfer function. */
1003
1004 static bool
1005 df_lr_transfer_function (int bb_index)
1006 {
1007 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1008 bitmap in = &bb_info->in;
1009 bitmap out = &bb_info->out;
1010 bitmap use = &bb_info->use;
1011 bitmap def = &bb_info->def;
1012
1013 return bitmap_ior_and_compl (in, use, out, def);
1014 }
1015
1016
1017 /* Run the fast dce as a side effect of building LR. */
1018
1019 static void
1020 df_lr_finalize (bitmap all_blocks)
1021 {
1022 df_lr->solutions_dirty = false;
1023 if (df->changeable_flags & DF_LR_RUN_DCE)
1024 {
1025 run_fast_df_dce ();
1026
1027 /* If dce deletes some instructions, we need to recompute the lr
1028 solution before proceeding further. The problem is that fast
1029 dce is a pessimestic dataflow algorithm. In the case where
1030 it deletes a statement S inside of a loop, the uses inside of
1031 S may not be deleted from the dataflow solution because they
1032 were carried around the loop. While it is conservatively
1033 correct to leave these extra bits, the standards of df
1034 require that we maintain the best possible (least fixed
1035 point) solution. The only way to do that is to redo the
1036 iteration from the beginning. See PR35805 for an
1037 example. */
1038 if (df_lr->solutions_dirty)
1039 {
1040 df_clear_flags (DF_LR_RUN_DCE);
1041 df_lr_alloc (all_blocks);
1042 df_lr_local_compute (all_blocks);
1043 df_worklist_dataflow (df_lr, all_blocks, df->postorder, df->n_blocks);
1044 df_lr_finalize (all_blocks);
1045 df_set_flags (DF_LR_RUN_DCE);
1046 }
1047 }
1048 }
1049
1050
1051 /* Free all storage associated with the problem. */
1052
1053 static void
1054 df_lr_free (void)
1055 {
1056 struct df_lr_problem_data *problem_data
1057 = (struct df_lr_problem_data *) df_lr->problem_data;
1058 if (df_lr->block_info)
1059 {
1060
1061 df_lr->block_info_size = 0;
1062 free (df_lr->block_info);
1063 df_lr->block_info = NULL;
1064 bitmap_obstack_release (&problem_data->lr_bitmaps);
1065 free (df_lr->problem_data);
1066 df_lr->problem_data = NULL;
1067 }
1068
1069 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1070 free (df_lr);
1071 }
1072
1073
1074 /* Debugging info at top of bb. */
1075
1076 static void
1077 df_lr_top_dump (basic_block bb, FILE *file)
1078 {
1079 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1080 struct df_lr_problem_data *problem_data;
1081 if (!bb_info)
1082 return;
1083
1084 fprintf (file, ";; lr in \t");
1085 df_print_regset (file, &bb_info->in);
1086 if (df_lr->problem_data)
1087 {
1088 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1089 if (problem_data->in)
1090 {
1091 fprintf (file, ";; old in \t");
1092 df_print_regset (file, &problem_data->in[bb->index]);
1093 }
1094 }
1095 fprintf (file, ";; lr use \t");
1096 df_print_regset (file, &bb_info->use);
1097 fprintf (file, ";; lr def \t");
1098 df_print_regset (file, &bb_info->def);
1099 }
1100
1101
1102 /* Debugging info at bottom of bb. */
1103
1104 static void
1105 df_lr_bottom_dump (basic_block bb, FILE *file)
1106 {
1107 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1108 struct df_lr_problem_data *problem_data;
1109 if (!bb_info)
1110 return;
1111
1112 fprintf (file, ";; lr out \t");
1113 df_print_regset (file, &bb_info->out);
1114 if (df_lr->problem_data)
1115 {
1116 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1117 if (problem_data->out)
1118 {
1119 fprintf (file, ";; old out \t");
1120 df_print_regset (file, &problem_data->out[bb->index]);
1121 }
1122 }
1123 }
1124
1125
1126 /* Build the datastructure to verify that the solution to the dataflow
1127 equations is not dirty. */
1128
1129 static void
1130 df_lr_verify_solution_start (void)
1131 {
1132 basic_block bb;
1133 struct df_lr_problem_data *problem_data;
1134 if (df_lr->solutions_dirty)
1135 return;
1136
1137 /* Set it true so that the solution is recomputed. */
1138 df_lr->solutions_dirty = true;
1139
1140 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1141 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1142 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1143
1144 FOR_ALL_BB_FN (bb, cfun)
1145 {
1146 bitmap_initialize (&problem_data->in[bb->index], &problem_data->lr_bitmaps);
1147 bitmap_initialize (&problem_data->out[bb->index], &problem_data->lr_bitmaps);
1148 bitmap_copy (&problem_data->in[bb->index], DF_LR_IN (bb));
1149 bitmap_copy (&problem_data->out[bb->index], DF_LR_OUT (bb));
1150 }
1151 }
1152
1153
1154 /* Compare the saved datastructure and the new solution to the dataflow
1155 equations. */
1156
1157 static void
1158 df_lr_verify_solution_end (void)
1159 {
1160 struct df_lr_problem_data *problem_data;
1161 basic_block bb;
1162
1163 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1164
1165 if (!problem_data->out)
1166 return;
1167
1168 if (df_lr->solutions_dirty)
1169 /* Do not check if the solution is still dirty. See the comment
1170 in df_lr_finalize for details. */
1171 df_lr->solutions_dirty = false;
1172 else
1173 FOR_ALL_BB_FN (bb, cfun)
1174 {
1175 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LR_IN (bb)))
1176 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LR_OUT (bb))))
1177 {
1178 /*df_dump (stderr);*/
1179 gcc_unreachable ();
1180 }
1181 }
1182
1183 /* Cannot delete them immediately because you may want to dump them
1184 if the comparison fails. */
1185 FOR_ALL_BB_FN (bb, cfun)
1186 {
1187 bitmap_clear (&problem_data->in[bb->index]);
1188 bitmap_clear (&problem_data->out[bb->index]);
1189 }
1190
1191 free (problem_data->in);
1192 free (problem_data->out);
1193 problem_data->in = NULL;
1194 problem_data->out = NULL;
1195 }
1196
1197
1198 /* All of the information associated with every instance of the problem. */
1199
1200 static const struct df_problem problem_LR =
1201 {
1202 DF_LR, /* Problem id. */
1203 DF_BACKWARD, /* Direction. */
1204 df_lr_alloc, /* Allocate the problem specific data. */
1205 df_lr_reset, /* Reset global information. */
1206 df_lr_free_bb_info, /* Free basic block info. */
1207 df_lr_local_compute, /* Local compute function. */
1208 df_lr_init, /* Init the solution specific data. */
1209 df_worklist_dataflow, /* Worklist solver. */
1210 df_lr_confluence_0, /* Confluence operator 0. */
1211 df_lr_confluence_n, /* Confluence operator n. */
1212 df_lr_transfer_function, /* Transfer function. */
1213 df_lr_finalize, /* Finalize function. */
1214 df_lr_free, /* Free all of the problem information. */
1215 NULL, /* Remove this problem from the stack of dataflow problems. */
1216 NULL, /* Debugging. */
1217 df_lr_top_dump, /* Debugging start block. */
1218 df_lr_bottom_dump, /* Debugging end block. */
1219 NULL, /* Debugging start insn. */
1220 NULL, /* Debugging end insn. */
1221 df_lr_verify_solution_start,/* Incremental solution verify start. */
1222 df_lr_verify_solution_end, /* Incremental solution verify end. */
1223 NULL, /* Dependent problem. */
1224 sizeof (class df_lr_bb_info),/* Size of entry of block_info array. */
1225 TV_DF_LR, /* Timing variable. */
1226 false /* Reset blocks on dropping out of blocks_to_analyze. */
1227 };
1228
1229
1230 /* Create a new DATAFLOW instance and add it to an existing instance
1231 of DF. The returned structure is what is used to get at the
1232 solution. */
1233
1234 void
1235 df_lr_add_problem (void)
1236 {
1237 df_add_problem (&problem_LR);
1238 /* These will be initialized when df_scan_blocks processes each
1239 block. */
1240 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1241 }
1242
1243
1244 /* Verify that all of the lr related info is consistent and
1245 correct. */
1246
1247 void
1248 df_lr_verify_transfer_functions (void)
1249 {
1250 basic_block bb;
1251 bitmap_head saved_def;
1252 bitmap_head saved_use;
1253 bitmap_head all_blocks;
1254
1255 if (!df)
1256 return;
1257
1258 bitmap_initialize (&saved_def, &bitmap_default_obstack);
1259 bitmap_initialize (&saved_use, &bitmap_default_obstack);
1260 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1261
1262 FOR_ALL_BB_FN (bb, cfun)
1263 {
1264 class df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1265 bitmap_set_bit (&all_blocks, bb->index);
1266
1267 if (bb_info)
1268 {
1269 /* Make a copy of the transfer functions and then compute
1270 new ones to see if the transfer functions have
1271 changed. */
1272 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1273 bb->index))
1274 {
1275 bitmap_copy (&saved_def, &bb_info->def);
1276 bitmap_copy (&saved_use, &bb_info->use);
1277 bitmap_clear (&bb_info->def);
1278 bitmap_clear (&bb_info->use);
1279
1280 df_lr_bb_local_compute (bb->index);
1281 gcc_assert (bitmap_equal_p (&saved_def, &bb_info->def));
1282 gcc_assert (bitmap_equal_p (&saved_use, &bb_info->use));
1283 }
1284 }
1285 else
1286 {
1287 /* If we do not have basic block info, the block must be in
1288 the list of dirty blocks or else some one has added a
1289 block behind our backs. */
1290 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1291 bb->index));
1292 }
1293 /* Make sure no one created a block without following
1294 procedures. */
1295 gcc_assert (df_scan_get_bb_info (bb->index));
1296 }
1297
1298 /* Make sure there are no dirty bits in blocks that have been deleted. */
1299 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1300 &all_blocks));
1301
1302 bitmap_clear (&saved_def);
1303 bitmap_clear (&saved_use);
1304 bitmap_clear (&all_blocks);
1305 }
1306
1307
1308 \f
1309 /*----------------------------------------------------------------------------
1310 LIVE AND MAY-INITIALIZED REGISTERS.
1311
1312 This problem first computes the IN and OUT bitvectors for the
1313 may-initialized registers problems, which is a forward problem.
1314 It gives the set of registers for which we MAY have an available
1315 definition, i.e. for which there is an available definition on
1316 at least one path from the entry block to the entry/exit of a
1317 basic block. Sets generate a definition, while clobbers kill
1318 a definition.
1319
1320 In and out bitvectors are built for each basic block and are indexed by
1321 regnum (see df.h for details). In and out bitvectors in struct
1322 df_live_bb_info actually refers to the may-initialized problem;
1323
1324 Then, the in and out sets for the LIVE problem itself are computed.
1325 These are the logical AND of the IN and OUT sets from the LR problem
1326 and the may-initialized problem.
1327 ----------------------------------------------------------------------------*/
1328
1329 /* Private data used to verify the solution for this problem. */
1330 struct df_live_problem_data
1331 {
1332 bitmap_head *in;
1333 bitmap_head *out;
1334 /* An obstack for the bitmaps we need for this problem. */
1335 bitmap_obstack live_bitmaps;
1336 };
1337
1338 /* Scratch var used by transfer functions. This is used to implement
1339 an optimization to reduce the amount of space used to compute the
1340 combined lr and live analysis. */
1341 static bitmap_head df_live_scratch;
1342
1343
1344 /* Free basic block info. */
1345
1346 static void
1347 df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1348 void *vbb_info)
1349 {
1350 class df_live_bb_info *bb_info = (class df_live_bb_info *) vbb_info;
1351 if (bb_info)
1352 {
1353 bitmap_clear (&bb_info->gen);
1354 bitmap_clear (&bb_info->kill);
1355 bitmap_clear (&bb_info->in);
1356 bitmap_clear (&bb_info->out);
1357 }
1358 }
1359
1360
1361 /* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
1362 not touched unless the block is new. */
1363
1364 static void
1365 df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1366 {
1367 unsigned int bb_index;
1368 bitmap_iterator bi;
1369 struct df_live_problem_data *problem_data;
1370
1371 if (df_live->problem_data)
1372 problem_data = (struct df_live_problem_data *) df_live->problem_data;
1373 else
1374 {
1375 problem_data = XNEW (struct df_live_problem_data);
1376 df_live->problem_data = problem_data;
1377
1378 problem_data->out = NULL;
1379 problem_data->in = NULL;
1380 bitmap_obstack_initialize (&problem_data->live_bitmaps);
1381 bitmap_initialize (&df_live_scratch, &problem_data->live_bitmaps);
1382 }
1383
1384 df_grow_bb_info (df_live);
1385
1386 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
1387 {
1388 class df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1389
1390 /* When bitmaps are already initialized, just clear them. */
1391 if (bb_info->kill.obstack)
1392 {
1393 bitmap_clear (&bb_info->kill);
1394 bitmap_clear (&bb_info->gen);
1395 }
1396 else
1397 {
1398 bitmap_initialize (&bb_info->kill, &problem_data->live_bitmaps);
1399 bitmap_initialize (&bb_info->gen, &problem_data->live_bitmaps);
1400 bitmap_initialize (&bb_info->in, &problem_data->live_bitmaps);
1401 bitmap_initialize (&bb_info->out, &problem_data->live_bitmaps);
1402 }
1403 }
1404 df_live->optional_p = (optimize <= 1);
1405 }
1406
1407
1408 /* Reset the global solution for recalculation. */
1409
1410 static void
1411 df_live_reset (bitmap all_blocks)
1412 {
1413 unsigned int bb_index;
1414 bitmap_iterator bi;
1415
1416 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1417 {
1418 class df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1419 gcc_assert (bb_info);
1420 bitmap_clear (&bb_info->in);
1421 bitmap_clear (&bb_info->out);
1422 }
1423 }
1424
1425
1426 /* Compute local uninitialized register info for basic block BB. */
1427
1428 static void
1429 df_live_bb_local_compute (unsigned int bb_index)
1430 {
1431 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1432 class df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1433 rtx_insn *insn;
1434 df_ref def;
1435 int luid = 0;
1436
1437 FOR_BB_INSNS (bb, insn)
1438 {
1439 unsigned int uid = INSN_UID (insn);
1440 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1441
1442 /* Inserting labels does not always trigger the incremental
1443 rescanning. */
1444 if (!insn_info)
1445 {
1446 gcc_assert (!INSN_P (insn));
1447 insn_info = df_insn_create_insn_record (insn);
1448 }
1449
1450 DF_INSN_INFO_LUID (insn_info) = luid;
1451 if (!INSN_P (insn))
1452 continue;
1453
1454 luid++;
1455 FOR_EACH_INSN_INFO_DEF (def, insn_info)
1456 {
1457 unsigned int regno = DF_REF_REGNO (def);
1458
1459 if (DF_REF_FLAGS_IS_SET (def,
1460 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1461 /* All partial or conditional def
1462 seen are included in the gen set. */
1463 bitmap_set_bit (&bb_info->gen, regno);
1464 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1465 /* Only must clobbers for the entire reg destroy the
1466 value. */
1467 bitmap_set_bit (&bb_info->kill, regno);
1468 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1469 bitmap_set_bit (&bb_info->gen, regno);
1470 }
1471 }
1472
1473 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
1474 bitmap_set_bit (&bb_info->gen, DF_REF_REGNO (def));
1475 }
1476
1477
1478 /* Compute local uninitialized register info. */
1479
1480 static void
1481 df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
1482 {
1483 unsigned int bb_index;
1484 bitmap_iterator bi;
1485
1486 df_grow_insn_info ();
1487
1488 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1489 0, bb_index, bi)
1490 {
1491 df_live_bb_local_compute (bb_index);
1492 }
1493
1494 bitmap_clear (df_live->out_of_date_transfer_functions);
1495 }
1496
1497
1498 /* Initialize the solution vectors. */
1499
1500 static void
1501 df_live_init (bitmap all_blocks)
1502 {
1503 unsigned int bb_index;
1504 bitmap_iterator bi;
1505
1506 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1507 {
1508 class df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1509 class df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1510
1511 /* No register may reach a location where it is not used. Thus
1512 we trim the rr result to the places where it is used. */
1513 bitmap_and (&bb_info->out, &bb_info->gen, &bb_lr_info->out);
1514 bitmap_clear (&bb_info->in);
1515 }
1516 }
1517
1518 /* Forward confluence function that ignores fake edges. */
1519
1520 static bool
1521 df_live_confluence_n (edge e)
1522 {
1523 bitmap op1 = &df_live_get_bb_info (e->dest->index)->in;
1524 bitmap op2 = &df_live_get_bb_info (e->src->index)->out;
1525
1526 if (e->flags & EDGE_FAKE)
1527 return false;
1528
1529 return bitmap_ior_into (op1, op2);
1530 }
1531
1532
1533 /* Transfer function for the forwards may-initialized problem. */
1534
1535 static bool
1536 df_live_transfer_function (int bb_index)
1537 {
1538 class df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
1539 class df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1540 bitmap in = &bb_info->in;
1541 bitmap out = &bb_info->out;
1542 bitmap gen = &bb_info->gen;
1543 bitmap kill = &bb_info->kill;
1544
1545 /* We need to use a scratch set here so that the value returned from this
1546 function invocation properly reflects whether the sets changed in a
1547 significant way; i.e. not just because the lr set was anded in. */
1548 bitmap_and (&df_live_scratch, gen, &bb_lr_info->out);
1549 /* No register may reach a location where it is not used. Thus
1550 we trim the rr result to the places where it is used. */
1551 bitmap_and_into (in, &bb_lr_info->in);
1552
1553 return bitmap_ior_and_compl (out, &df_live_scratch, in, kill);
1554 }
1555
1556
1557 /* And the LR info with the may-initialized registers to produce the LIVE info. */
1558
1559 static void
1560 df_live_finalize (bitmap all_blocks)
1561 {
1562
1563 if (df_live->solutions_dirty)
1564 {
1565 bitmap_iterator bi;
1566 unsigned int bb_index;
1567
1568 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1569 {
1570 class df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1571 class df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
1572
1573 /* No register may reach a location where it is not used. Thus
1574 we trim the rr result to the places where it is used. */
1575 bitmap_and_into (&bb_live_info->in, &bb_lr_info->in);
1576 bitmap_and_into (&bb_live_info->out, &bb_lr_info->out);
1577 }
1578
1579 df_live->solutions_dirty = false;
1580 }
1581 }
1582
1583
1584 /* Free all storage associated with the problem. */
1585
1586 static void
1587 df_live_free (void)
1588 {
1589 struct df_live_problem_data *problem_data
1590 = (struct df_live_problem_data *) df_live->problem_data;
1591 if (df_live->block_info)
1592 {
1593 df_live->block_info_size = 0;
1594 free (df_live->block_info);
1595 df_live->block_info = NULL;
1596 bitmap_release (&df_live_scratch);
1597 bitmap_obstack_release (&problem_data->live_bitmaps);
1598 free (problem_data);
1599 df_live->problem_data = NULL;
1600 }
1601 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1602 free (df_live);
1603 }
1604
1605
1606 /* Debugging info at top of bb. */
1607
1608 static void
1609 df_live_top_dump (basic_block bb, FILE *file)
1610 {
1611 class df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1612 struct df_live_problem_data *problem_data;
1613
1614 if (!bb_info)
1615 return;
1616
1617 fprintf (file, ";; live in \t");
1618 df_print_regset (file, &bb_info->in);
1619 if (df_live->problem_data)
1620 {
1621 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1622 if (problem_data->in)
1623 {
1624 fprintf (file, ";; old in \t");
1625 df_print_regset (file, &problem_data->in[bb->index]);
1626 }
1627 }
1628 fprintf (file, ";; live gen \t");
1629 df_print_regset (file, &bb_info->gen);
1630 fprintf (file, ";; live kill\t");
1631 df_print_regset (file, &bb_info->kill);
1632 }
1633
1634
1635 /* Debugging info at bottom of bb. */
1636
1637 static void
1638 df_live_bottom_dump (basic_block bb, FILE *file)
1639 {
1640 class df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1641 struct df_live_problem_data *problem_data;
1642
1643 if (!bb_info)
1644 return;
1645
1646 fprintf (file, ";; live out \t");
1647 df_print_regset (file, &bb_info->out);
1648 if (df_live->problem_data)
1649 {
1650 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1651 if (problem_data->out)
1652 {
1653 fprintf (file, ";; old out \t");
1654 df_print_regset (file, &problem_data->out[bb->index]);
1655 }
1656 }
1657 }
1658
1659
1660 /* Build the datastructure to verify that the solution to the dataflow
1661 equations is not dirty. */
1662
1663 static void
1664 df_live_verify_solution_start (void)
1665 {
1666 basic_block bb;
1667 struct df_live_problem_data *problem_data;
1668 if (df_live->solutions_dirty)
1669 return;
1670
1671 /* Set it true so that the solution is recomputed. */
1672 df_live->solutions_dirty = true;
1673
1674 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1675 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1676 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
1677
1678 FOR_ALL_BB_FN (bb, cfun)
1679 {
1680 bitmap_initialize (&problem_data->in[bb->index], &problem_data->live_bitmaps);
1681 bitmap_initialize (&problem_data->out[bb->index], &problem_data->live_bitmaps);
1682 bitmap_copy (&problem_data->in[bb->index], DF_LIVE_IN (bb));
1683 bitmap_copy (&problem_data->out[bb->index], DF_LIVE_OUT (bb));
1684 }
1685 }
1686
1687
1688 /* Compare the saved datastructure and the new solution to the dataflow
1689 equations. */
1690
1691 static void
1692 df_live_verify_solution_end (void)
1693 {
1694 struct df_live_problem_data *problem_data;
1695 basic_block bb;
1696
1697 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1698 if (!problem_data->out)
1699 return;
1700
1701 FOR_ALL_BB_FN (bb, cfun)
1702 {
1703 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_LIVE_IN (bb)))
1704 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1705 {
1706 /*df_dump (stderr);*/
1707 gcc_unreachable ();
1708 }
1709 }
1710
1711 /* Cannot delete them immediately because you may want to dump them
1712 if the comparison fails. */
1713 FOR_ALL_BB_FN (bb, cfun)
1714 {
1715 bitmap_clear (&problem_data->in[bb->index]);
1716 bitmap_clear (&problem_data->out[bb->index]);
1717 }
1718
1719 free (problem_data->in);
1720 free (problem_data->out);
1721 free (problem_data);
1722 df_live->problem_data = NULL;
1723 }
1724
1725
1726 /* All of the information associated with every instance of the problem. */
1727
1728 static const struct df_problem problem_LIVE =
1729 {
1730 DF_LIVE, /* Problem id. */
1731 DF_FORWARD, /* Direction. */
1732 df_live_alloc, /* Allocate the problem specific data. */
1733 df_live_reset, /* Reset global information. */
1734 df_live_free_bb_info, /* Free basic block info. */
1735 df_live_local_compute, /* Local compute function. */
1736 df_live_init, /* Init the solution specific data. */
1737 df_worklist_dataflow, /* Worklist solver. */
1738 NULL, /* Confluence operator 0. */
1739 df_live_confluence_n, /* Confluence operator n. */
1740 df_live_transfer_function, /* Transfer function. */
1741 df_live_finalize, /* Finalize function. */
1742 df_live_free, /* Free all of the problem information. */
1743 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1744 NULL, /* Debugging. */
1745 df_live_top_dump, /* Debugging start block. */
1746 df_live_bottom_dump, /* Debugging end block. */
1747 NULL, /* Debugging start insn. */
1748 NULL, /* Debugging end insn. */
1749 df_live_verify_solution_start,/* Incremental solution verify start. */
1750 df_live_verify_solution_end, /* Incremental solution verify end. */
1751 &problem_LR, /* Dependent problem. */
1752 sizeof (class df_live_bb_info),/* Size of entry of block_info array. */
1753 TV_DF_LIVE, /* Timing variable. */
1754 false /* Reset blocks on dropping out of blocks_to_analyze. */
1755 };
1756
1757
1758 /* Create a new DATAFLOW instance and add it to an existing instance
1759 of DF. The returned structure is what is used to get at the
1760 solution. */
1761
1762 void
1763 df_live_add_problem (void)
1764 {
1765 df_add_problem (&problem_LIVE);
1766 /* These will be initialized when df_scan_blocks processes each
1767 block. */
1768 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
1769 }
1770
1771
1772 /* Set all of the blocks as dirty. This needs to be done if this
1773 problem is added after all of the insns have been scanned. */
1774
1775 void
1776 df_live_set_all_dirty (void)
1777 {
1778 basic_block bb;
1779 FOR_ALL_BB_FN (bb, cfun)
1780 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1781 bb->index);
1782 }
1783
1784
1785 /* Verify that all of the lr related info is consistent and
1786 correct. */
1787
1788 void
1789 df_live_verify_transfer_functions (void)
1790 {
1791 basic_block bb;
1792 bitmap_head saved_gen;
1793 bitmap_head saved_kill;
1794 bitmap_head all_blocks;
1795
1796 if (!df)
1797 return;
1798
1799 bitmap_initialize (&saved_gen, &bitmap_default_obstack);
1800 bitmap_initialize (&saved_kill, &bitmap_default_obstack);
1801 bitmap_initialize (&all_blocks, &bitmap_default_obstack);
1802
1803 df_grow_insn_info ();
1804
1805 FOR_ALL_BB_FN (bb, cfun)
1806 {
1807 class df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1808 bitmap_set_bit (&all_blocks, bb->index);
1809
1810 if (bb_info)
1811 {
1812 /* Make a copy of the transfer functions and then compute
1813 new ones to see if the transfer functions have
1814 changed. */
1815 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1816 bb->index))
1817 {
1818 bitmap_copy (&saved_gen, &bb_info->gen);
1819 bitmap_copy (&saved_kill, &bb_info->kill);
1820 bitmap_clear (&bb_info->gen);
1821 bitmap_clear (&bb_info->kill);
1822
1823 df_live_bb_local_compute (bb->index);
1824 gcc_assert (bitmap_equal_p (&saved_gen, &bb_info->gen));
1825 gcc_assert (bitmap_equal_p (&saved_kill, &bb_info->kill));
1826 }
1827 }
1828 else
1829 {
1830 /* If we do not have basic block info, the block must be in
1831 the list of dirty blocks or else some one has added a
1832 block behind our backs. */
1833 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1834 bb->index));
1835 }
1836 /* Make sure no one created a block without following
1837 procedures. */
1838 gcc_assert (df_scan_get_bb_info (bb->index));
1839 }
1840
1841 /* Make sure there are no dirty bits in blocks that have been deleted. */
1842 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1843 &all_blocks));
1844 bitmap_clear (&saved_gen);
1845 bitmap_clear (&saved_kill);
1846 bitmap_clear (&all_blocks);
1847 }
1848 \f
1849 /*----------------------------------------------------------------------------
1850 MUST-INITIALIZED REGISTERS.
1851 ----------------------------------------------------------------------------*/
1852
1853 /* Private data used to verify the solution for this problem. */
1854 struct df_mir_problem_data
1855 {
1856 bitmap_head *in;
1857 bitmap_head *out;
1858 /* An obstack for the bitmaps we need for this problem. */
1859 bitmap_obstack mir_bitmaps;
1860 };
1861
1862
1863 /* Free basic block info. */
1864
1865 static void
1866 df_mir_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
1867 void *vbb_info)
1868 {
1869 class df_mir_bb_info *bb_info = (class df_mir_bb_info *) vbb_info;
1870 if (bb_info)
1871 {
1872 bitmap_clear (&bb_info->gen);
1873 bitmap_clear (&bb_info->kill);
1874 bitmap_clear (&bb_info->in);
1875 bitmap_clear (&bb_info->out);
1876 }
1877 }
1878
1879
1880 /* Allocate or reset bitmaps for DF_MIR blocks. The solution bits are
1881 not touched unless the block is new. */
1882
1883 static void
1884 df_mir_alloc (bitmap all_blocks)
1885 {
1886 unsigned int bb_index;
1887 bitmap_iterator bi;
1888 struct df_mir_problem_data *problem_data;
1889
1890 if (df_mir->problem_data)
1891 problem_data = (struct df_mir_problem_data *) df_mir->problem_data;
1892 else
1893 {
1894 problem_data = XNEW (struct df_mir_problem_data);
1895 df_mir->problem_data = problem_data;
1896
1897 problem_data->out = NULL;
1898 problem_data->in = NULL;
1899 bitmap_obstack_initialize (&problem_data->mir_bitmaps);
1900 }
1901
1902 df_grow_bb_info (df_mir);
1903
1904 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1905 {
1906 class df_mir_bb_info *bb_info = df_mir_get_bb_info (bb_index);
1907
1908 /* When bitmaps are already initialized, just clear them. */
1909 if (bb_info->kill.obstack)
1910 {
1911 bitmap_clear (&bb_info->kill);
1912 bitmap_clear (&bb_info->gen);
1913 }
1914 else
1915 {
1916 bitmap_initialize (&bb_info->kill, &problem_data->mir_bitmaps);
1917 bitmap_initialize (&bb_info->gen, &problem_data->mir_bitmaps);
1918 bitmap_initialize (&bb_info->in, &problem_data->mir_bitmaps);
1919 bitmap_initialize (&bb_info->out, &problem_data->mir_bitmaps);
1920 bitmap_set_range (&bb_info->in, 0, DF_REG_SIZE (df));
1921 bitmap_set_range (&bb_info->out, 0, DF_REG_SIZE (df));
1922 }
1923 }
1924
1925 df_mir->optional_p = 1;
1926 }
1927
1928
1929 /* Reset the global solution for recalculation. */
1930
1931 static void
1932 df_mir_reset (bitmap all_blocks)
1933 {
1934 unsigned int bb_index;
1935 bitmap_iterator bi;
1936
1937 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1938 {
1939 class df_mir_bb_info *bb_info = df_mir_get_bb_info (bb_index);
1940
1941 gcc_assert (bb_info);
1942
1943 bitmap_clear (&bb_info->in);
1944 bitmap_set_range (&bb_info->in, 0, DF_REG_SIZE (df));
1945 bitmap_clear (&bb_info->out);
1946 bitmap_set_range (&bb_info->out, 0, DF_REG_SIZE (df));
1947 }
1948 }
1949
1950
1951 /* Compute local uninitialized register info for basic block BB. */
1952
1953 static void
1954 df_mir_bb_local_compute (unsigned int bb_index)
1955 {
1956 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1957 class df_mir_bb_info *bb_info = df_mir_get_bb_info (bb_index);
1958 rtx_insn *insn;
1959 int luid = 0;
1960
1961 /* Ignoring artificial defs is intentional: these often pretend that some
1962 registers carry incoming arguments (when they are FUNCTION_ARG_REGNO) even
1963 though they are not used for that. As a result, conservatively assume
1964 they may be uninitialized. */
1965
1966 FOR_BB_INSNS (bb, insn)
1967 {
1968 unsigned int uid = INSN_UID (insn);
1969 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1970
1971 /* Inserting labels does not always trigger the incremental
1972 rescanning. */
1973 if (!insn_info)
1974 {
1975 gcc_assert (!INSN_P (insn));
1976 insn_info = df_insn_create_insn_record (insn);
1977 }
1978
1979 DF_INSN_INFO_LUID (insn_info) = luid;
1980 if (!INSN_P (insn))
1981 continue;
1982
1983 luid++;
1984 df_mir_simulate_one_insn (bb, insn, &bb_info->kill, &bb_info->gen);
1985 }
1986 }
1987
1988
1989 /* Compute local uninitialized register info. */
1990
1991 static void
1992 df_mir_local_compute (bitmap all_blocks)
1993 {
1994 unsigned int bb_index;
1995 bitmap_iterator bi;
1996
1997 df_grow_insn_info ();
1998
1999 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2000 {
2001 df_mir_bb_local_compute (bb_index);
2002 }
2003 }
2004
2005
2006 /* Initialize the solution vectors. */
2007
2008 static void
2009 df_mir_init (bitmap all_blocks)
2010 {
2011 df_mir_reset (all_blocks);
2012 }
2013
2014
2015 /* Initialize IN sets for blocks with no predecessors: when landing on such
2016 blocks, assume all registers are uninitialized. */
2017
2018 static void
2019 df_mir_confluence_0 (basic_block bb)
2020 {
2021 class df_mir_bb_info *bb_info = df_mir_get_bb_info (bb->index);
2022
2023 bitmap_clear (&bb_info->in);
2024 }
2025
2026
2027 /* Forward confluence function that ignores fake edges. */
2028
2029 static bool
2030 df_mir_confluence_n (edge e)
2031 {
2032 bitmap op1 = &df_mir_get_bb_info (e->dest->index)->in;
2033 bitmap op2 = &df_mir_get_bb_info (e->src->index)->out;
2034
2035 if (e->flags & EDGE_FAKE)
2036 return false;
2037
2038 /* A register is must-initialized at the entry of a basic block iff it is
2039 must-initialized at the exit of all the predecessors. */
2040 return bitmap_and_into (op1, op2);
2041 }
2042
2043
2044 /* Transfer function for the forwards must-initialized problem. */
2045
2046 static bool
2047 df_mir_transfer_function (int bb_index)
2048 {
2049 class df_mir_bb_info *bb_info = df_mir_get_bb_info (bb_index);
2050 bitmap in = &bb_info->in;
2051 bitmap out = &bb_info->out;
2052 bitmap gen = &bb_info->gen;
2053 bitmap kill = &bb_info->kill;
2054
2055 return bitmap_ior_and_compl (out, gen, in, kill);
2056 }
2057
2058
2059 /* Free all storage associated with the problem. */
2060
2061 static void
2062 df_mir_free (void)
2063 {
2064 struct df_mir_problem_data *problem_data
2065 = (struct df_mir_problem_data *) df_mir->problem_data;
2066 if (df_mir->block_info)
2067 {
2068 df_mir->block_info_size = 0;
2069 free (df_mir->block_info);
2070 df_mir->block_info = NULL;
2071 bitmap_obstack_release (&problem_data->mir_bitmaps);
2072 free (problem_data);
2073 df_mir->problem_data = NULL;
2074 }
2075 free (df_mir);
2076 }
2077
2078
2079 /* Debugging info at top of bb. */
2080
2081 static void
2082 df_mir_top_dump (basic_block bb, FILE *file)
2083 {
2084 class df_mir_bb_info *bb_info = df_mir_get_bb_info (bb->index);
2085
2086 if (!bb_info)
2087 return;
2088
2089 fprintf (file, ";; mir in \t");
2090 df_print_regset (file, &bb_info->in);
2091 fprintf (file, ";; mir kill\t");
2092 df_print_regset (file, &bb_info->kill);
2093 fprintf (file, ";; mir gen \t");
2094 df_print_regset (file, &bb_info->gen);
2095 }
2096
2097 /* Debugging info at bottom of bb. */
2098
2099 static void
2100 df_mir_bottom_dump (basic_block bb, FILE *file)
2101 {
2102 class df_mir_bb_info *bb_info = df_mir_get_bb_info (bb->index);
2103
2104 if (!bb_info)
2105 return;
2106
2107 fprintf (file, ";; mir out \t");
2108 df_print_regset (file, &bb_info->out);
2109 }
2110
2111
2112 /* Build the datastructure to verify that the solution to the dataflow
2113 equations is not dirty. */
2114
2115 static void
2116 df_mir_verify_solution_start (void)
2117 {
2118 basic_block bb;
2119 struct df_mir_problem_data *problem_data;
2120 if (df_mir->solutions_dirty)
2121 return;
2122
2123 /* Set it true so that the solution is recomputed. */
2124 df_mir->solutions_dirty = true;
2125
2126 problem_data = (struct df_mir_problem_data *) df_mir->problem_data;
2127 problem_data->in = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
2128 problem_data->out = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
2129 bitmap_obstack_initialize (&problem_data->mir_bitmaps);
2130
2131 FOR_ALL_BB_FN (bb, cfun)
2132 {
2133 bitmap_initialize (&problem_data->in[bb->index], &problem_data->mir_bitmaps);
2134 bitmap_initialize (&problem_data->out[bb->index], &problem_data->mir_bitmaps);
2135 bitmap_copy (&problem_data->in[bb->index], DF_MIR_IN (bb));
2136 bitmap_copy (&problem_data->out[bb->index], DF_MIR_OUT (bb));
2137 }
2138 }
2139
2140
2141 /* Compare the saved datastructure and the new solution to the dataflow
2142 equations. */
2143
2144 static void
2145 df_mir_verify_solution_end (void)
2146 {
2147 struct df_mir_problem_data *problem_data;
2148 basic_block bb;
2149
2150 problem_data = (struct df_mir_problem_data *) df_mir->problem_data;
2151 if (!problem_data->out)
2152 return;
2153
2154 FOR_ALL_BB_FN (bb, cfun)
2155 {
2156 if ((!bitmap_equal_p (&problem_data->in[bb->index], DF_MIR_IN (bb)))
2157 || (!bitmap_equal_p (&problem_data->out[bb->index], DF_MIR_OUT (bb))))
2158 gcc_unreachable ();
2159 }
2160
2161 /* Cannot delete them immediately because you may want to dump them
2162 if the comparison fails. */
2163 FOR_ALL_BB_FN (bb, cfun)
2164 {
2165 bitmap_clear (&problem_data->in[bb->index]);
2166 bitmap_clear (&problem_data->out[bb->index]);
2167 }
2168
2169 free (problem_data->in);
2170 free (problem_data->out);
2171 bitmap_obstack_release (&problem_data->mir_bitmaps);
2172 free (problem_data);
2173 df_mir->problem_data = NULL;
2174 }
2175
2176
2177 /* All of the information associated with every instance of the problem. */
2178
2179 static const struct df_problem problem_MIR =
2180 {
2181 DF_MIR, /* Problem id. */
2182 DF_FORWARD, /* Direction. */
2183 df_mir_alloc, /* Allocate the problem specific data. */
2184 df_mir_reset, /* Reset global information. */
2185 df_mir_free_bb_info, /* Free basic block info. */
2186 df_mir_local_compute, /* Local compute function. */
2187 df_mir_init, /* Init the solution specific data. */
2188 df_worklist_dataflow, /* Worklist solver. */
2189 df_mir_confluence_0, /* Confluence operator 0. */
2190 df_mir_confluence_n, /* Confluence operator n. */
2191 df_mir_transfer_function, /* Transfer function. */
2192 NULL, /* Finalize function. */
2193 df_mir_free, /* Free all of the problem information. */
2194 df_mir_free, /* Remove this problem from the stack of dataflow problems. */
2195 NULL, /* Debugging. */
2196 df_mir_top_dump, /* Debugging start block. */
2197 df_mir_bottom_dump, /* Debugging end block. */
2198 NULL, /* Debugging start insn. */
2199 NULL, /* Debugging end insn. */
2200 df_mir_verify_solution_start, /* Incremental solution verify start. */
2201 df_mir_verify_solution_end, /* Incremental solution verify end. */
2202 NULL, /* Dependent problem. */
2203 sizeof (class df_mir_bb_info),/* Size of entry of block_info array. */
2204 TV_DF_MIR, /* Timing variable. */
2205 false /* Reset blocks on dropping out of blocks_to_analyze. */
2206 };
2207
2208
2209 /* Create a new DATAFLOW instance and add it to an existing instance
2210 of DF. */
2211
2212 void
2213 df_mir_add_problem (void)
2214 {
2215 df_add_problem (&problem_MIR);
2216 /* These will be initialized when df_scan_blocks processes each
2217 block. */
2218 df_mir->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2219 }
2220
2221
2222 /* Apply the effects of the gen/kills in INSN to the corresponding bitmaps. */
2223
2224 void
2225 df_mir_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
2226 bitmap kill, bitmap gen)
2227 {
2228 df_ref def;
2229
2230 FOR_EACH_INSN_DEF (def, insn)
2231 {
2232 unsigned int regno = DF_REF_REGNO (def);
2233
2234 /* The order of GENs/KILLs matters, so if this def clobbers a reg, any
2235 previous gen is irrelevant (and reciprocally). Also, claim that a
2236 register is GEN only if it is in all cases. */
2237 if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2238 {
2239 bitmap_set_bit (kill, regno);
2240 bitmap_clear_bit (gen, regno);
2241 }
2242 /* In the worst case, partial and conditional defs can leave bits
2243 uninitialized, so assume they do not change anything. */
2244 else if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2245 {
2246 bitmap_set_bit (gen, regno);
2247 bitmap_clear_bit (kill, regno);
2248 }
2249 }
2250 }
2251 \f
2252 /*----------------------------------------------------------------------------
2253 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
2254
2255 Link either the defs to the uses and / or the uses to the defs.
2256
2257 These problems are set up like the other dataflow problems so that
2258 they nicely fit into the framework. They are much simpler and only
2259 involve a single traversal of instructions and an examination of
2260 the reaching defs information (the dependent problem).
2261 ----------------------------------------------------------------------------*/
2262
2263 #define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
2264
2265 /* Create a du or ud chain from SRC to DST and link it into SRC. */
2266
2267 struct df_link *
2268 df_chain_create (df_ref src, df_ref dst)
2269 {
2270 struct df_link *head = DF_REF_CHAIN (src);
2271 struct df_link *link = df_chain->block_pool->allocate ();
2272
2273 DF_REF_CHAIN (src) = link;
2274 link->next = head;
2275 link->ref = dst;
2276 return link;
2277 }
2278
2279
2280 /* Delete any du or ud chains that start at REF and point to
2281 TARGET. */
2282 static void
2283 df_chain_unlink_1 (df_ref ref, df_ref target)
2284 {
2285 struct df_link *chain = DF_REF_CHAIN (ref);
2286 struct df_link *prev = NULL;
2287
2288 while (chain)
2289 {
2290 if (chain->ref == target)
2291 {
2292 if (prev)
2293 prev->next = chain->next;
2294 else
2295 DF_REF_CHAIN (ref) = chain->next;
2296 df_chain->block_pool->remove (chain);
2297 return;
2298 }
2299 prev = chain;
2300 chain = chain->next;
2301 }
2302 }
2303
2304
2305 /* Delete a du or ud chain that leave or point to REF. */
2306
2307 void
2308 df_chain_unlink (df_ref ref)
2309 {
2310 struct df_link *chain = DF_REF_CHAIN (ref);
2311 while (chain)
2312 {
2313 struct df_link *next = chain->next;
2314 /* Delete the other side if it exists. */
2315 df_chain_unlink_1 (chain->ref, ref);
2316 df_chain->block_pool->remove (chain);
2317 chain = next;
2318 }
2319 DF_REF_CHAIN (ref) = NULL;
2320 }
2321
2322
2323 /* Copy the du or ud chain starting at FROM_REF and attach it to
2324 TO_REF. */
2325
2326 void
2327 df_chain_copy (df_ref to_ref,
2328 struct df_link *from_ref)
2329 {
2330 while (from_ref)
2331 {
2332 df_chain_create (to_ref, from_ref->ref);
2333 from_ref = from_ref->next;
2334 }
2335 }
2336
2337
2338 /* Remove this problem from the stack of dataflow problems. */
2339
2340 static void
2341 df_chain_remove_problem (void)
2342 {
2343 bitmap_iterator bi;
2344 unsigned int bb_index;
2345
2346 /* Wholesale destruction of the old chains. */
2347 if (df_chain->block_pool)
2348 delete df_chain->block_pool;
2349
2350 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
2351 {
2352 rtx_insn *insn;
2353 df_ref def, use;
2354 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2355
2356 if (df_chain_problem_p (DF_DU_CHAIN))
2357 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
2358 DF_REF_CHAIN (def) = NULL;
2359 if (df_chain_problem_p (DF_UD_CHAIN))
2360 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
2361 DF_REF_CHAIN (use) = NULL;
2362
2363 FOR_BB_INSNS (bb, insn)
2364 if (INSN_P (insn))
2365 {
2366 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2367 if (df_chain_problem_p (DF_DU_CHAIN))
2368 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2369 DF_REF_CHAIN (def) = NULL;
2370 if (df_chain_problem_p (DF_UD_CHAIN))
2371 {
2372 FOR_EACH_INSN_INFO_USE (use, insn_info)
2373 DF_REF_CHAIN (use) = NULL;
2374 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
2375 DF_REF_CHAIN (use) = NULL;
2376 }
2377 }
2378 }
2379
2380 bitmap_clear (df_chain->out_of_date_transfer_functions);
2381 df_chain->block_pool = NULL;
2382 }
2383
2384
2385 /* Remove the chain problem completely. */
2386
2387 static void
2388 df_chain_fully_remove_problem (void)
2389 {
2390 df_chain_remove_problem ();
2391 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2392 free (df_chain);
2393 }
2394
2395
2396 /* Create def-use or use-def chains. */
2397
2398 static void
2399 df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2400 {
2401 df_chain_remove_problem ();
2402 df_chain->block_pool = new object_allocator<df_link> ("df_chain_block pool");
2403 df_chain->optional_p = true;
2404 }
2405
2406
2407 /* Reset all of the chains when the set of basic blocks changes. */
2408
2409 static void
2410 df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
2411 {
2412 df_chain_remove_problem ();
2413 }
2414
2415
2416 /* Create the chains for a list of USEs. */
2417
2418 static void
2419 df_chain_create_bb_process_use (bitmap local_rd,
2420 df_ref use,
2421 int top_flag)
2422 {
2423 bitmap_iterator bi;
2424 unsigned int def_index;
2425
2426 for (; use; use = DF_REF_NEXT_LOC (use))
2427 {
2428 unsigned int uregno = DF_REF_REGNO (use);
2429 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2430 || (uregno >= FIRST_PSEUDO_REGISTER))
2431 {
2432 /* Do not want to go through this for an uninitialized var. */
2433 int count = DF_DEFS_COUNT (uregno);
2434 if (count)
2435 {
2436 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2437 {
2438 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2439 unsigned int last_index = first_index + count - 1;
2440
2441 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2442 {
2443 df_ref def;
2444 if (def_index > last_index)
2445 break;
2446
2447 def = DF_DEFS_GET (def_index);
2448 if (df_chain_problem_p (DF_DU_CHAIN))
2449 df_chain_create (def, use);
2450 if (df_chain_problem_p (DF_UD_CHAIN))
2451 df_chain_create (use, def);
2452 }
2453 }
2454 }
2455 }
2456 }
2457 }
2458
2459
2460 /* Create chains from reaching defs bitmaps for basic block BB. */
2461
2462 static void
2463 df_chain_create_bb (unsigned int bb_index)
2464 {
2465 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2466 class df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
2467 rtx_insn *insn;
2468 bitmap_head cpy;
2469
2470 bitmap_initialize (&cpy, &bitmap_default_obstack);
2471 bitmap_copy (&cpy, &bb_info->in);
2472 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
2473
2474 /* Since we are going forwards, process the artificial uses first
2475 then the artificial defs second. */
2476
2477 #ifdef EH_USES
2478 /* Create the chains for the artificial uses from the EH_USES at the
2479 beginning of the block. */
2480
2481 /* Artificials are only hard regs. */
2482 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2483 df_chain_create_bb_process_use (&cpy,
2484 df_get_artificial_uses (bb->index),
2485 DF_REF_AT_TOP);
2486 #endif
2487
2488 df_rd_simulate_artificial_defs_at_top (bb, &cpy);
2489
2490 /* Process the regular instructions next. */
2491 FOR_BB_INSNS (bb, insn)
2492 if (INSN_P (insn))
2493 {
2494 unsigned int uid = INSN_UID (insn);
2495
2496 /* First scan the uses and link them up with the defs that remain
2497 in the cpy vector. */
2498 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_USES (uid), 0);
2499 if (df->changeable_flags & DF_EQ_NOTES)
2500 df_chain_create_bb_process_use (&cpy, DF_INSN_UID_EQ_USES (uid), 0);
2501
2502 /* Since we are going forwards, process the defs second. */
2503 df_rd_simulate_one_insn (bb, insn, &cpy);
2504 }
2505
2506 /* Create the chains for the artificial uses of the hard registers
2507 at the end of the block. */
2508 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2509 df_chain_create_bb_process_use (&cpy,
2510 df_get_artificial_uses (bb->index),
2511 0);
2512
2513 bitmap_clear (&cpy);
2514 }
2515
2516 /* Create def-use chains from reaching use bitmaps for basic blocks
2517 in BLOCKS. */
2518
2519 static void
2520 df_chain_finalize (bitmap all_blocks)
2521 {
2522 unsigned int bb_index;
2523 bitmap_iterator bi;
2524
2525 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2526 {
2527 df_chain_create_bb (bb_index);
2528 }
2529 }
2530
2531
2532 /* Free all storage associated with the problem. */
2533
2534 static void
2535 df_chain_free (void)
2536 {
2537 delete df_chain->block_pool;
2538 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2539 free (df_chain);
2540 }
2541
2542
2543 /* Debugging info. */
2544
2545 static void
2546 df_chain_bb_dump (basic_block bb, FILE *file, bool top)
2547 {
2548 /* Artificials are only hard regs. */
2549 if (df->changeable_flags & DF_NO_HARD_REGS)
2550 return;
2551 if (df_chain_problem_p (DF_UD_CHAIN))
2552 {
2553 df_ref use;
2554
2555 fprintf (file,
2556 ";; UD chains for artificial uses at %s\n",
2557 top ? "top" : "bottom");
2558 FOR_EACH_ARTIFICIAL_USE (use, bb->index)
2559 if ((top && (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2560 || (!top && !(DF_REF_FLAGS (use) & DF_REF_AT_TOP)))
2561 {
2562 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2563 df_chain_dump (DF_REF_CHAIN (use), file);
2564 fprintf (file, "\n");
2565 }
2566 }
2567 if (df_chain_problem_p (DF_DU_CHAIN))
2568 {
2569 df_ref def;
2570
2571 fprintf (file,
2572 ";; DU chains for artificial defs at %s\n",
2573 top ? "top" : "bottom");
2574 FOR_EACH_ARTIFICIAL_DEF (def, bb->index)
2575 if ((top && (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
2576 || (!top && !(DF_REF_FLAGS (def) & DF_REF_AT_TOP)))
2577 {
2578 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2579 df_chain_dump (DF_REF_CHAIN (def), file);
2580 fprintf (file, "\n");
2581 }
2582 }
2583 }
2584
2585 static void
2586 df_chain_top_dump (basic_block bb, FILE *file)
2587 {
2588 df_chain_bb_dump (bb, file, /*top=*/true);
2589 }
2590
2591 static void
2592 df_chain_bottom_dump (basic_block bb, FILE *file)
2593 {
2594 df_chain_bb_dump (bb, file, /*top=*/false);
2595 }
2596
2597 static void
2598 df_chain_insn_top_dump (const rtx_insn *insn, FILE *file)
2599 {
2600 if (df_chain_problem_p (DF_UD_CHAIN) && INSN_P (insn))
2601 {
2602 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2603 df_ref use;
2604
2605 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2606 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2607 FOR_EACH_INSN_INFO_USE (use, insn_info)
2608 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2609 || !(df->changeable_flags & DF_NO_HARD_REGS))
2610 {
2611 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2612 if (DF_REF_FLAGS (use) & DF_REF_READ_WRITE)
2613 fprintf (file, "read/write ");
2614 df_chain_dump (DF_REF_CHAIN (use), file);
2615 fprintf (file, "\n");
2616 }
2617 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
2618 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (use))
2619 || !(df->changeable_flags & DF_NO_HARD_REGS))
2620 {
2621 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2622 df_chain_dump (DF_REF_CHAIN (use), file);
2623 fprintf (file, "\n");
2624 }
2625 }
2626 }
2627
2628 static void
2629 df_chain_insn_bottom_dump (const rtx_insn *insn, FILE *file)
2630 {
2631 if (df_chain_problem_p (DF_DU_CHAIN) && INSN_P (insn))
2632 {
2633 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2634 df_ref def;
2635 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2636 DF_INSN_INFO_LUID (insn_info), INSN_UID (insn));
2637 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2638 if (!HARD_REGISTER_NUM_P (DF_REF_REGNO (def))
2639 || !(df->changeable_flags & DF_NO_HARD_REGS))
2640 {
2641 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2642 if (DF_REF_FLAGS (def) & DF_REF_READ_WRITE)
2643 fprintf (file, "read/write ");
2644 df_chain_dump (DF_REF_CHAIN (def), file);
2645 fprintf (file, "\n");
2646 }
2647 fprintf (file, "\n");
2648 }
2649 }
2650
2651 static const struct df_problem problem_CHAIN =
2652 {
2653 DF_CHAIN, /* Problem id. */
2654 DF_NONE, /* Direction. */
2655 df_chain_alloc, /* Allocate the problem specific data. */
2656 df_chain_reset, /* Reset global information. */
2657 NULL, /* Free basic block info. */
2658 NULL, /* Local compute function. */
2659 NULL, /* Init the solution specific data. */
2660 NULL, /* Iterative solver. */
2661 NULL, /* Confluence operator 0. */
2662 NULL, /* Confluence operator n. */
2663 NULL, /* Transfer function. */
2664 df_chain_finalize, /* Finalize function. */
2665 df_chain_free, /* Free all of the problem information. */
2666 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2667 NULL, /* Debugging. */
2668 df_chain_top_dump, /* Debugging start block. */
2669 df_chain_bottom_dump, /* Debugging end block. */
2670 df_chain_insn_top_dump, /* Debugging start insn. */
2671 df_chain_insn_bottom_dump, /* Debugging end insn. */
2672 NULL, /* Incremental solution verify start. */
2673 NULL, /* Incremental solution verify end. */
2674 &problem_RD, /* Dependent problem. */
2675 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
2676 TV_DF_CHAIN, /* Timing variable. */
2677 false /* Reset blocks on dropping out of blocks_to_analyze. */
2678 };
2679
2680
2681 /* Create a new DATAFLOW instance and add it to an existing instance
2682 of DF. The returned structure is what is used to get at the
2683 solution. */
2684
2685 void
2686 df_chain_add_problem (unsigned int chain_flags)
2687 {
2688 df_add_problem (&problem_CHAIN);
2689 df_chain->local_flags = chain_flags;
2690 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
2691 }
2692
2693 #undef df_chain_problem_p
2694
2695 \f
2696 /*----------------------------------------------------------------------------
2697 WORD LEVEL LIVE REGISTERS
2698
2699 Find the locations in the function where any use of a pseudo can
2700 reach in the backwards direction. In and out bitvectors are built
2701 for each basic block. We only track pseudo registers that have a
2702 size of 2 * UNITS_PER_WORD; bitmaps are indexed by 2 * regno and
2703 contain two bits corresponding to each of the subwords.
2704
2705 ----------------------------------------------------------------------------*/
2706
2707 /* Private data used to verify the solution for this problem. */
2708 struct df_word_lr_problem_data
2709 {
2710 /* An obstack for the bitmaps we need for this problem. */
2711 bitmap_obstack word_lr_bitmaps;
2712 };
2713
2714
2715 /* Free basic block info. */
2716
2717 static void
2718 df_word_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
2719 void *vbb_info)
2720 {
2721 class df_word_lr_bb_info *bb_info = (class df_word_lr_bb_info *) vbb_info;
2722 if (bb_info)
2723 {
2724 bitmap_clear (&bb_info->use);
2725 bitmap_clear (&bb_info->def);
2726 bitmap_clear (&bb_info->in);
2727 bitmap_clear (&bb_info->out);
2728 }
2729 }
2730
2731
2732 /* Allocate or reset bitmaps for DF_WORD_LR blocks. The solution bits are
2733 not touched unless the block is new. */
2734
2735 static void
2736 df_word_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2737 {
2738 unsigned int bb_index;
2739 bitmap_iterator bi;
2740 basic_block bb;
2741 struct df_word_lr_problem_data *problem_data
2742 = XNEW (struct df_word_lr_problem_data);
2743
2744 df_word_lr->problem_data = problem_data;
2745
2746 df_grow_bb_info (df_word_lr);
2747
2748 /* Create the mapping from regnos to slots. This does not change
2749 unless the problem is destroyed and recreated. In particular, if
2750 we end up deleting the only insn that used a subreg, we do not
2751 want to redo the mapping because this would invalidate everything
2752 else. */
2753
2754 bitmap_obstack_initialize (&problem_data->word_lr_bitmaps);
2755
2756 FOR_EACH_BB_FN (bb, cfun)
2757 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, bb->index);
2758
2759 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, ENTRY_BLOCK);
2760 bitmap_set_bit (df_word_lr->out_of_date_transfer_functions, EXIT_BLOCK);
2761
2762 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2763 {
2764 class df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2765
2766 /* When bitmaps are already initialized, just clear them. */
2767 if (bb_info->use.obstack)
2768 {
2769 bitmap_clear (&bb_info->def);
2770 bitmap_clear (&bb_info->use);
2771 }
2772 else
2773 {
2774 bitmap_initialize (&bb_info->use, &problem_data->word_lr_bitmaps);
2775 bitmap_initialize (&bb_info->def, &problem_data->word_lr_bitmaps);
2776 bitmap_initialize (&bb_info->in, &problem_data->word_lr_bitmaps);
2777 bitmap_initialize (&bb_info->out, &problem_data->word_lr_bitmaps);
2778 }
2779 }
2780
2781 df_word_lr->optional_p = true;
2782 }
2783
2784
2785 /* Reset the global solution for recalculation. */
2786
2787 static void
2788 df_word_lr_reset (bitmap all_blocks)
2789 {
2790 unsigned int bb_index;
2791 bitmap_iterator bi;
2792
2793 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2794 {
2795 class df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2796 gcc_assert (bb_info);
2797 bitmap_clear (&bb_info->in);
2798 bitmap_clear (&bb_info->out);
2799 }
2800 }
2801
2802 /* Examine REF, and if it is for a reg we're interested in, set or
2803 clear the bits corresponding to its subwords from the bitmap
2804 according to IS_SET. LIVE is the bitmap we should update. We do
2805 not track hard regs or pseudos of any size other than 2 *
2806 UNITS_PER_WORD.
2807 We return true if we changed the bitmap, or if we encountered a register
2808 we're not tracking. */
2809
2810 bool
2811 df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
2812 {
2813 rtx orig_reg = DF_REF_REG (ref);
2814 rtx reg = orig_reg;
2815 machine_mode reg_mode;
2816 unsigned regno;
2817 /* Left at -1 for whole accesses. */
2818 int which_subword = -1;
2819 bool changed = false;
2820
2821 if (GET_CODE (reg) == SUBREG)
2822 reg = SUBREG_REG (orig_reg);
2823 regno = REGNO (reg);
2824 reg_mode = GET_MODE (reg);
2825 if (regno < FIRST_PSEUDO_REGISTER
2826 || maybe_ne (GET_MODE_SIZE (reg_mode), 2 * UNITS_PER_WORD))
2827 return true;
2828
2829 if (GET_CODE (orig_reg) == SUBREG
2830 && read_modify_subreg_p (orig_reg))
2831 {
2832 gcc_assert (DF_REF_FLAGS_IS_SET (ref, DF_REF_PARTIAL));
2833 if (subreg_lowpart_p (orig_reg))
2834 which_subword = 0;
2835 else
2836 which_subword = 1;
2837 }
2838 if (is_set)
2839 {
2840 if (which_subword != 1)
2841 changed |= bitmap_set_bit (live, regno * 2);
2842 if (which_subword != 0)
2843 changed |= bitmap_set_bit (live, regno * 2 + 1);
2844 }
2845 else
2846 {
2847 if (which_subword != 1)
2848 changed |= bitmap_clear_bit (live, regno * 2);
2849 if (which_subword != 0)
2850 changed |= bitmap_clear_bit (live, regno * 2 + 1);
2851 }
2852 return changed;
2853 }
2854
2855 /* Compute local live register info for basic block BB. */
2856
2857 static void
2858 df_word_lr_bb_local_compute (unsigned int bb_index)
2859 {
2860 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
2861 class df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2862 rtx_insn *insn;
2863 df_ref def, use;
2864
2865 /* Ensure that artificial refs don't contain references to pseudos. */
2866 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
2867 gcc_assert (DF_REF_REGNO (def) < FIRST_PSEUDO_REGISTER);
2868
2869 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
2870 gcc_assert (DF_REF_REGNO (use) < FIRST_PSEUDO_REGISTER);
2871
2872 FOR_BB_INSNS_REVERSE (bb, insn)
2873 {
2874 if (!NONDEBUG_INSN_P (insn))
2875 continue;
2876
2877 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2878 FOR_EACH_INSN_INFO_DEF (def, insn_info)
2879 /* If the def is to only part of the reg, it does
2880 not kill the other defs that reach here. */
2881 if (!(DF_REF_FLAGS (def) & (DF_REF_CONDITIONAL)))
2882 {
2883 df_word_lr_mark_ref (def, true, &bb_info->def);
2884 df_word_lr_mark_ref (def, false, &bb_info->use);
2885 }
2886 FOR_EACH_INSN_INFO_USE (use, insn_info)
2887 df_word_lr_mark_ref (use, true, &bb_info->use);
2888 }
2889 }
2890
2891
2892 /* Compute local live register info for each basic block within BLOCKS. */
2893
2894 static void
2895 df_word_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
2896 {
2897 unsigned int bb_index;
2898 bitmap_iterator bi;
2899
2900 EXECUTE_IF_SET_IN_BITMAP (df_word_lr->out_of_date_transfer_functions, 0, bb_index, bi)
2901 {
2902 if (bb_index == EXIT_BLOCK)
2903 {
2904 unsigned regno;
2905 bitmap_iterator bi;
2906 EXECUTE_IF_SET_IN_BITMAP (df->exit_block_uses, FIRST_PSEUDO_REGISTER,
2907 regno, bi)
2908 gcc_unreachable ();
2909 }
2910 else
2911 df_word_lr_bb_local_compute (bb_index);
2912 }
2913
2914 bitmap_clear (df_word_lr->out_of_date_transfer_functions);
2915 }
2916
2917
2918 /* Initialize the solution vectors. */
2919
2920 static void
2921 df_word_lr_init (bitmap all_blocks)
2922 {
2923 unsigned int bb_index;
2924 bitmap_iterator bi;
2925
2926 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2927 {
2928 class df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2929 bitmap_copy (&bb_info->in, &bb_info->use);
2930 bitmap_clear (&bb_info->out);
2931 }
2932 }
2933
2934
2935 /* Confluence function that ignores fake edges. */
2936
2937 static bool
2938 df_word_lr_confluence_n (edge e)
2939 {
2940 bitmap op1 = &df_word_lr_get_bb_info (e->src->index)->out;
2941 bitmap op2 = &df_word_lr_get_bb_info (e->dest->index)->in;
2942
2943 return bitmap_ior_into (op1, op2);
2944 }
2945
2946
2947 /* Transfer function. */
2948
2949 static bool
2950 df_word_lr_transfer_function (int bb_index)
2951 {
2952 class df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
2953 bitmap in = &bb_info->in;
2954 bitmap out = &bb_info->out;
2955 bitmap use = &bb_info->use;
2956 bitmap def = &bb_info->def;
2957
2958 return bitmap_ior_and_compl (in, use, out, def);
2959 }
2960
2961
2962 /* Free all storage associated with the problem. */
2963
2964 static void
2965 df_word_lr_free (void)
2966 {
2967 struct df_word_lr_problem_data *problem_data
2968 = (struct df_word_lr_problem_data *)df_word_lr->problem_data;
2969
2970 if (df_word_lr->block_info)
2971 {
2972 df_word_lr->block_info_size = 0;
2973 free (df_word_lr->block_info);
2974 df_word_lr->block_info = NULL;
2975 }
2976
2977 BITMAP_FREE (df_word_lr->out_of_date_transfer_functions);
2978 bitmap_obstack_release (&problem_data->word_lr_bitmaps);
2979 free (problem_data);
2980 free (df_word_lr);
2981 }
2982
2983
2984 /* Debugging info at top of bb. */
2985
2986 static void
2987 df_word_lr_top_dump (basic_block bb, FILE *file)
2988 {
2989 class df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
2990 if (!bb_info)
2991 return;
2992
2993 fprintf (file, ";; blr in \t");
2994 df_print_word_regset (file, &bb_info->in);
2995 fprintf (file, ";; blr use \t");
2996 df_print_word_regset (file, &bb_info->use);
2997 fprintf (file, ";; blr def \t");
2998 df_print_word_regset (file, &bb_info->def);
2999 }
3000
3001
3002 /* Debugging info at bottom of bb. */
3003
3004 static void
3005 df_word_lr_bottom_dump (basic_block bb, FILE *file)
3006 {
3007 class df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb->index);
3008 if (!bb_info)
3009 return;
3010
3011 fprintf (file, ";; blr out \t");
3012 df_print_word_regset (file, &bb_info->out);
3013 }
3014
3015
3016 /* All of the information associated with every instance of the problem. */
3017
3018 static const struct df_problem problem_WORD_LR =
3019 {
3020 DF_WORD_LR, /* Problem id. */
3021 DF_BACKWARD, /* Direction. */
3022 df_word_lr_alloc, /* Allocate the problem specific data. */
3023 df_word_lr_reset, /* Reset global information. */
3024 df_word_lr_free_bb_info, /* Free basic block info. */
3025 df_word_lr_local_compute, /* Local compute function. */
3026 df_word_lr_init, /* Init the solution specific data. */
3027 df_worklist_dataflow, /* Worklist solver. */
3028 NULL, /* Confluence operator 0. */
3029 df_word_lr_confluence_n, /* Confluence operator n. */
3030 df_word_lr_transfer_function, /* Transfer function. */
3031 NULL, /* Finalize function. */
3032 df_word_lr_free, /* Free all of the problem information. */
3033 df_word_lr_free, /* Remove this problem from the stack of dataflow problems. */
3034 NULL, /* Debugging. */
3035 df_word_lr_top_dump, /* Debugging start block. */
3036 df_word_lr_bottom_dump, /* Debugging end block. */
3037 NULL, /* Debugging start insn. */
3038 NULL, /* Debugging end insn. */
3039 NULL, /* Incremental solution verify start. */
3040 NULL, /* Incremental solution verify end. */
3041 NULL, /* Dependent problem. */
3042 sizeof (class df_word_lr_bb_info),/* Size of entry of block_info array. */
3043 TV_DF_WORD_LR, /* Timing variable. */
3044 false /* Reset blocks on dropping out of blocks_to_analyze. */
3045 };
3046
3047
3048 /* Create a new DATAFLOW instance and add it to an existing instance
3049 of DF. The returned structure is what is used to get at the
3050 solution. */
3051
3052 void
3053 df_word_lr_add_problem (void)
3054 {
3055 df_add_problem (&problem_WORD_LR);
3056 /* These will be initialized when df_scan_blocks processes each
3057 block. */
3058 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (&df_bitmap_obstack);
3059 }
3060
3061
3062 /* Simulate the effects of the defs of INSN on LIVE. Return true if we changed
3063 any bits, which is used by the caller to determine whether a set is
3064 necessary. We also return true if there are other reasons not to delete
3065 an insn. */
3066
3067 bool
3068 df_word_lr_simulate_defs (rtx_insn *insn, bitmap live)
3069 {
3070 bool changed = false;
3071 df_ref def;
3072
3073 FOR_EACH_INSN_DEF (def, insn)
3074 if (DF_REF_FLAGS (def) & DF_REF_CONDITIONAL)
3075 changed = true;
3076 else
3077 changed |= df_word_lr_mark_ref (def, false, live);
3078 return changed;
3079 }
3080
3081
3082 /* Simulate the effects of the uses of INSN on LIVE. */
3083
3084 void
3085 df_word_lr_simulate_uses (rtx_insn *insn, bitmap live)
3086 {
3087 df_ref use;
3088
3089 FOR_EACH_INSN_USE (use, insn)
3090 df_word_lr_mark_ref (use, true, live);
3091 }
3092 \f
3093 /*----------------------------------------------------------------------------
3094 This problem computes REG_DEAD and REG_UNUSED notes.
3095 ----------------------------------------------------------------------------*/
3096
3097 static void
3098 df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3099 {
3100 df_note->optional_p = true;
3101 }
3102
3103 /* This is only used if REG_DEAD_DEBUGGING is in effect. */
3104 static void
3105 df_print_note (const char *prefix, rtx_insn *insn, rtx note)
3106 {
3107 if (dump_file)
3108 {
3109 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
3110 print_rtl (dump_file, note);
3111 fprintf (dump_file, "\n");
3112 }
3113 }
3114
3115
3116 /* After reg-stack, the x86 floating point stack regs are difficult to
3117 analyze because of all of the pushes, pops and rotations. Thus, we
3118 just leave the notes alone. */
3119
3120 #ifdef STACK_REGS
3121 static inline bool
3122 df_ignore_stack_reg (int regno)
3123 {
3124 return regstack_completed
3125 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
3126 }
3127 #else
3128 static inline bool
3129 df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
3130 {
3131 return false;
3132 }
3133 #endif
3134
3135
3136 /* Remove all of the REG_DEAD or REG_UNUSED notes from INSN. */
3137
3138 static void
3139 df_remove_dead_and_unused_notes (rtx_insn *insn)
3140 {
3141 rtx *pprev = &REG_NOTES (insn);
3142 rtx link = *pprev;
3143
3144 while (link)
3145 {
3146 switch (REG_NOTE_KIND (link))
3147 {
3148 case REG_DEAD:
3149 /* After reg-stack, we need to ignore any unused notes
3150 for the stack registers. */
3151 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3152 {
3153 pprev = &XEXP (link, 1);
3154 link = *pprev;
3155 }
3156 else
3157 {
3158 rtx next = XEXP (link, 1);
3159 if (REG_DEAD_DEBUGGING)
3160 df_print_note ("deleting: ", insn, link);
3161 free_EXPR_LIST_node (link);
3162 *pprev = link = next;
3163 }
3164 break;
3165
3166 case REG_UNUSED:
3167 /* After reg-stack, we need to ignore any unused notes
3168 for the stack registers. */
3169 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3170 {
3171 pprev = &XEXP (link, 1);
3172 link = *pprev;
3173 }
3174 else
3175 {
3176 rtx next = XEXP (link, 1);
3177 if (REG_DEAD_DEBUGGING)
3178 df_print_note ("deleting: ", insn, link);
3179 free_EXPR_LIST_node (link);
3180 *pprev = link = next;
3181 }
3182 break;
3183
3184 default:
3185 pprev = &XEXP (link, 1);
3186 link = *pprev;
3187 break;
3188 }
3189 }
3190 }
3191
3192 /* Remove REG_EQUAL/REG_EQUIV notes referring to dead pseudos using LIVE
3193 as the bitmap of currently live registers. */
3194
3195 static void
3196 df_remove_dead_eq_notes (rtx_insn *insn, bitmap live)
3197 {
3198 rtx *pprev = &REG_NOTES (insn);
3199 rtx link = *pprev;
3200
3201 while (link)
3202 {
3203 switch (REG_NOTE_KIND (link))
3204 {
3205 case REG_EQUAL:
3206 case REG_EQUIV:
3207 {
3208 /* Remove the notes that refer to dead registers. As we have at most
3209 one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
3210 so we need to purge the complete EQ_USES vector when removing
3211 the note using df_notes_rescan. */
3212 df_ref use;
3213 bool deleted = false;
3214
3215 FOR_EACH_INSN_EQ_USE (use, insn)
3216 if (DF_REF_REGNO (use) >= FIRST_PSEUDO_REGISTER
3217 && DF_REF_LOC (use)
3218 && (DF_REF_FLAGS (use) & DF_REF_IN_NOTE)
3219 && !bitmap_bit_p (live, DF_REF_REGNO (use))
3220 && loc_mentioned_in_p (DF_REF_LOC (use), XEXP (link, 0)))
3221 {
3222 deleted = true;
3223 break;
3224 }
3225 if (deleted)
3226 {
3227 rtx next;
3228 if (REG_DEAD_DEBUGGING)
3229 df_print_note ("deleting: ", insn, link);
3230 next = XEXP (link, 1);
3231 free_EXPR_LIST_node (link);
3232 *pprev = link = next;
3233 df_notes_rescan (insn);
3234 }
3235 else
3236 {
3237 pprev = &XEXP (link, 1);
3238 link = *pprev;
3239 }
3240 break;
3241 }
3242
3243 default:
3244 pprev = &XEXP (link, 1);
3245 link = *pprev;
3246 break;
3247 }
3248 }
3249 }
3250
3251 /* Set a NOTE_TYPE note for REG in INSN. */
3252
3253 static inline void
3254 df_set_note (enum reg_note note_type, rtx_insn *insn, rtx reg)
3255 {
3256 gcc_checking_assert (!DEBUG_INSN_P (insn));
3257 add_reg_note (insn, note_type, reg);
3258 }
3259
3260 /* A subroutine of df_set_unused_notes_for_mw, with a selection of its
3261 arguments. Return true if the register value described by MWS's
3262 mw_reg is known to be completely unused, and if mw_reg can therefore
3263 be used in a REG_UNUSED note. */
3264
3265 static bool
3266 df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
3267 bitmap live, bitmap artificial_uses)
3268 {
3269 unsigned int r;
3270
3271 /* If MWS describes a partial reference, create REG_UNUSED notes for
3272 individual hard registers. */
3273 if (mws->flags & DF_REF_PARTIAL)
3274 return false;
3275
3276 /* Likewise if some part of the register is used. */
3277 for (r = mws->start_regno; r <= mws->end_regno; r++)
3278 if (bitmap_bit_p (live, r)
3279 || bitmap_bit_p (artificial_uses, r))
3280 return false;
3281
3282 gcc_assert (REG_P (mws->mw_reg));
3283 return true;
3284 }
3285
3286
3287 /* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
3288 based on the bits in LIVE. Do not generate notes for registers in
3289 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
3290 not generated if the reg is both read and written by the
3291 instruction.
3292 */
3293
3294 static void
3295 df_set_unused_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
3296 bitmap live, bitmap do_not_gen,
3297 bitmap artificial_uses,
3298 struct dead_debug_local *debug)
3299 {
3300 unsigned int r;
3301
3302 if (REG_DEAD_DEBUGGING && dump_file)
3303 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
3304 mws->start_regno, mws->end_regno);
3305
3306 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
3307 {
3308 unsigned int regno = mws->start_regno;
3309 df_set_note (REG_UNUSED, insn, mws->mw_reg);
3310 dead_debug_insert_temp (debug, regno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3311
3312 if (REG_DEAD_DEBUGGING)
3313 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3314
3315 bitmap_set_bit (do_not_gen, regno);
3316 /* Only do this if the value is totally dead. */
3317 }
3318 else
3319 for (r = mws->start_regno; r <= mws->end_regno; r++)
3320 {
3321 if (!bitmap_bit_p (live, r)
3322 && !bitmap_bit_p (artificial_uses, r))
3323 {
3324 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
3325 dead_debug_insert_temp (debug, r, insn, DEBUG_TEMP_AFTER_WITH_REG);
3326 if (REG_DEAD_DEBUGGING)
3327 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3328 }
3329 bitmap_set_bit (do_not_gen, r);
3330 }
3331 }
3332
3333
3334 /* A subroutine of df_set_dead_notes_for_mw, with a selection of its
3335 arguments. Return true if the register value described by MWS's
3336 mw_reg is known to be completely dead, and if mw_reg can therefore
3337 be used in a REG_DEAD note. */
3338
3339 static bool
3340 df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
3341 bitmap live, bitmap artificial_uses,
3342 bitmap do_not_gen)
3343 {
3344 unsigned int r;
3345
3346 /* If MWS describes a partial reference, create REG_DEAD notes for
3347 individual hard registers. */
3348 if (mws->flags & DF_REF_PARTIAL)
3349 return false;
3350
3351 /* Likewise if some part of the register is not dead. */
3352 for (r = mws->start_regno; r <= mws->end_regno; r++)
3353 if (bitmap_bit_p (live, r)
3354 || bitmap_bit_p (artificial_uses, r)
3355 || bitmap_bit_p (do_not_gen, r))
3356 return false;
3357
3358 gcc_assert (REG_P (mws->mw_reg));
3359 return true;
3360 }
3361
3362 /* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3363 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3364 from being set if the instruction both reads and writes the
3365 register. */
3366
3367 static void
3368 df_set_dead_notes_for_mw (rtx_insn *insn, struct df_mw_hardreg *mws,
3369 bitmap live, bitmap do_not_gen,
3370 bitmap artificial_uses, bool *added_notes_p)
3371 {
3372 unsigned int r;
3373 bool is_debug = *added_notes_p;
3374
3375 *added_notes_p = false;
3376
3377 if (REG_DEAD_DEBUGGING && dump_file)
3378 {
3379 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3380 mws->start_regno, mws->end_regno);
3381 df_print_regset (dump_file, do_not_gen);
3382 fprintf (dump_file, " live =");
3383 df_print_regset (dump_file, live);
3384 fprintf (dump_file, " artificial uses =");
3385 df_print_regset (dump_file, artificial_uses);
3386 }
3387
3388 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
3389 {
3390 if (is_debug)
3391 {
3392 *added_notes_p = true;
3393 return;
3394 }
3395 /* Add a dead note for the entire multi word register. */
3396 df_set_note (REG_DEAD, insn, mws->mw_reg);
3397 if (REG_DEAD_DEBUGGING)
3398 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
3399 }
3400 else
3401 {
3402 for (r = mws->start_regno; r <= mws->end_regno; r++)
3403 if (!bitmap_bit_p (live, r)
3404 && !bitmap_bit_p (artificial_uses, r)
3405 && !bitmap_bit_p (do_not_gen, r))
3406 {
3407 if (is_debug)
3408 {
3409 *added_notes_p = true;
3410 return;
3411 }
3412 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
3413 if (REG_DEAD_DEBUGGING)
3414 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
3415 }
3416 }
3417 return;
3418 }
3419
3420
3421 /* Create a REG_UNUSED note if necessary for DEF in INSN updating
3422 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
3423
3424 static void
3425 df_create_unused_note (rtx_insn *insn, df_ref def,
3426 bitmap live, bitmap artificial_uses,
3427 struct dead_debug_local *debug)
3428 {
3429 unsigned int dregno = DF_REF_REGNO (def);
3430
3431 if (REG_DEAD_DEBUGGING && dump_file)
3432 {
3433 fprintf (dump_file, " regular looking at def ");
3434 df_ref_debug (def, dump_file);
3435 }
3436
3437 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3438 || bitmap_bit_p (live, dregno)
3439 || bitmap_bit_p (artificial_uses, dregno)
3440 || df_ignore_stack_reg (dregno)))
3441 {
3442 rtx reg = (DF_REF_LOC (def))
3443 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3444 df_set_note (REG_UNUSED, insn, reg);
3445 dead_debug_insert_temp (debug, dregno, insn, DEBUG_TEMP_AFTER_WITH_REG);
3446 if (REG_DEAD_DEBUGGING)
3447 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
3448 }
3449
3450 return;
3451 }
3452
3453
3454 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3455 info: lifetime, bb, and number of defs and uses for basic block
3456 BB. The three bitvectors are scratch regs used here. */
3457
3458 static void
3459 df_note_bb_compute (unsigned int bb_index,
3460 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
3461 {
3462 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
3463 rtx_insn *insn;
3464 df_ref def, use;
3465 struct dead_debug_local debug;
3466
3467 dead_debug_local_init (&debug, NULL, NULL);
3468
3469 bitmap_copy (live, df_get_live_out (bb));
3470 bitmap_clear (artificial_uses);
3471
3472 if (REG_DEAD_DEBUGGING && dump_file)
3473 {
3474 fprintf (dump_file, "live at bottom ");
3475 df_print_regset (dump_file, live);
3476 }
3477
3478 /* Process the artificial defs and uses at the bottom of the block
3479 to begin processing. */
3480 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3481 {
3482 if (REG_DEAD_DEBUGGING && dump_file)
3483 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
3484
3485 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3486 bitmap_clear_bit (live, DF_REF_REGNO (def));
3487 }
3488
3489 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3490 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3491 {
3492 unsigned int regno = DF_REF_REGNO (use);
3493 bitmap_set_bit (live, regno);
3494
3495 /* Notes are not generated for any of the artificial registers
3496 at the bottom of the block. */
3497 bitmap_set_bit (artificial_uses, regno);
3498 }
3499
3500 if (REG_DEAD_DEBUGGING && dump_file)
3501 {
3502 fprintf (dump_file, "live before artificials out ");
3503 df_print_regset (dump_file, live);
3504 }
3505
3506 FOR_BB_INSNS_REVERSE (bb, insn)
3507 {
3508 if (!INSN_P (insn))
3509 continue;
3510
3511 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3512 df_mw_hardreg *mw;
3513 int debug_insn;
3514
3515 debug_insn = DEBUG_INSN_P (insn);
3516
3517 bitmap_clear (do_not_gen);
3518 df_remove_dead_and_unused_notes (insn);
3519
3520 /* Process the defs. */
3521 if (CALL_P (insn))
3522 {
3523 if (REG_DEAD_DEBUGGING && dump_file)
3524 {
3525 fprintf (dump_file, "processing call %d\n live =",
3526 INSN_UID (insn));
3527 df_print_regset (dump_file, live);
3528 }
3529
3530 /* We only care about real sets for calls. Clobbers cannot
3531 be depended on to really die. */
3532 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3533 if ((DF_MWS_REG_DEF_P (mw))
3534 && !df_ignore_stack_reg (mw->start_regno))
3535 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3536 artificial_uses, &debug);
3537
3538 /* All of the defs except the return value are some sort of
3539 clobber. This code is for the return. */
3540 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3541 {
3542 unsigned int dregno = DF_REF_REGNO (def);
3543 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3544 {
3545 df_create_unused_note (insn,
3546 def, live, artificial_uses, &debug);
3547 bitmap_set_bit (do_not_gen, dregno);
3548 }
3549
3550 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3551 bitmap_clear_bit (live, dregno);
3552 }
3553 }
3554 else
3555 {
3556 /* Regular insn. */
3557 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3558 if (DF_MWS_REG_DEF_P (mw))
3559 df_set_unused_notes_for_mw (insn, mw, live, do_not_gen,
3560 artificial_uses, &debug);
3561
3562 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3563 {
3564 unsigned int dregno = DF_REF_REGNO (def);
3565 df_create_unused_note (insn,
3566 def, live, artificial_uses, &debug);
3567
3568 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3569 bitmap_set_bit (do_not_gen, dregno);
3570
3571 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3572 bitmap_clear_bit (live, dregno);
3573 }
3574 }
3575
3576 /* Process the uses. */
3577 FOR_EACH_INSN_INFO_MW (mw, insn_info)
3578 if (DF_MWS_REG_USE_P (mw)
3579 && !df_ignore_stack_reg (mw->start_regno))
3580 {
3581 bool really_add_notes = debug_insn != 0;
3582
3583 df_set_dead_notes_for_mw (insn, mw, live, do_not_gen,
3584 artificial_uses,
3585 &really_add_notes);
3586
3587 if (really_add_notes)
3588 debug_insn = -1;
3589 }
3590
3591 FOR_EACH_INSN_INFO_USE (use, insn_info)
3592 {
3593 unsigned int uregno = DF_REF_REGNO (use);
3594
3595 if (REG_DEAD_DEBUGGING && dump_file && !debug_insn)
3596 {
3597 fprintf (dump_file, " regular looking at use ");
3598 df_ref_debug (use, dump_file);
3599 }
3600
3601 if (!bitmap_bit_p (live, uregno))
3602 {
3603 if (debug_insn)
3604 {
3605 if (debug_insn > 0)
3606 {
3607 /* We won't add REG_UNUSED or REG_DEAD notes for
3608 these, so we don't have to mess with them in
3609 debug insns either. */
3610 if (!bitmap_bit_p (artificial_uses, uregno)
3611 && !df_ignore_stack_reg (uregno))
3612 dead_debug_add (&debug, use, uregno);
3613 continue;
3614 }
3615 break;
3616 }
3617 else
3618 dead_debug_insert_temp (&debug, uregno, insn,
3619 DEBUG_TEMP_BEFORE_WITH_REG);
3620
3621 if ( (!(DF_REF_FLAGS (use)
3622 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
3623 && (!bitmap_bit_p (do_not_gen, uregno))
3624 && (!bitmap_bit_p (artificial_uses, uregno))
3625 && (!df_ignore_stack_reg (uregno)))
3626 {
3627 rtx reg = (DF_REF_LOC (use))
3628 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
3629 df_set_note (REG_DEAD, insn, reg);
3630
3631 if (REG_DEAD_DEBUGGING)
3632 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
3633 }
3634 /* This register is now live. */
3635 bitmap_set_bit (live, uregno);
3636 }
3637 }
3638
3639 df_remove_dead_eq_notes (insn, live);
3640
3641 if (debug_insn == -1)
3642 {
3643 /* ??? We could probably do better here, replacing dead
3644 registers with their definitions. */
3645 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3646 df_insn_rescan_debug_internal (insn);
3647 }
3648 }
3649
3650 dead_debug_local_finish (&debug, NULL);
3651 }
3652
3653
3654 /* Compute register info: lifetime, bb, and number of defs and uses. */
3655 static void
3656 df_note_compute (bitmap all_blocks)
3657 {
3658 unsigned int bb_index;
3659 bitmap_iterator bi;
3660 bitmap_head live, do_not_gen, artificial_uses;
3661
3662 bitmap_initialize (&live, &df_bitmap_obstack);
3663 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3664 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
3665
3666 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3667 {
3668 /* ??? Unlike fast DCE, we don't use global_debug for uses of dead
3669 pseudos in debug insns because we don't always (re)visit blocks
3670 with death points after visiting dead uses. Even changing this
3671 loop to postorder would still leave room for visiting a death
3672 point before visiting a subsequent debug use. */
3673 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
3674 }
3675
3676 bitmap_clear (&live);
3677 bitmap_clear (&do_not_gen);
3678 bitmap_clear (&artificial_uses);
3679 }
3680
3681
3682 /* Free all storage associated with the problem. */
3683
3684 static void
3685 df_note_free (void)
3686 {
3687 free (df_note);
3688 }
3689
3690
3691 /* All of the information associated every instance of the problem. */
3692
3693 static const struct df_problem problem_NOTE =
3694 {
3695 DF_NOTE, /* Problem id. */
3696 DF_NONE, /* Direction. */
3697 df_note_alloc, /* Allocate the problem specific data. */
3698 NULL, /* Reset global information. */
3699 NULL, /* Free basic block info. */
3700 df_note_compute, /* Local compute function. */
3701 NULL, /* Init the solution specific data. */
3702 NULL, /* Iterative solver. */
3703 NULL, /* Confluence operator 0. */
3704 NULL, /* Confluence operator n. */
3705 NULL, /* Transfer function. */
3706 NULL, /* Finalize function. */
3707 df_note_free, /* Free all of the problem information. */
3708 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3709 NULL, /* Debugging. */
3710 NULL, /* Debugging start block. */
3711 NULL, /* Debugging end block. */
3712 NULL, /* Debugging start insn. */
3713 NULL, /* Debugging end insn. */
3714 NULL, /* Incremental solution verify start. */
3715 NULL, /* Incremental solution verify end. */
3716 &problem_LR, /* Dependent problem. */
3717 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
3718 TV_DF_NOTE, /* Timing variable. */
3719 false /* Reset blocks on dropping out of blocks_to_analyze. */
3720 };
3721
3722
3723 /* Create a new DATAFLOW instance and add it to an existing instance
3724 of DF. The returned structure is what is used to get at the
3725 solution. */
3726
3727 void
3728 df_note_add_problem (void)
3729 {
3730 df_add_problem (&problem_NOTE);
3731 }
3732
3733
3734
3735 \f
3736 /*----------------------------------------------------------------------------
3737 Functions for simulating the effects of single insns.
3738
3739 You can either simulate in the forwards direction, starting from
3740 the top of a block or the backwards direction from the end of the
3741 block. If you go backwards, defs are examined first to clear bits,
3742 then uses are examined to set bits. If you go forwards, defs are
3743 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3744 are examined to clear bits. In either case, the result of examining
3745 a def can be undone (respectively by a use or a REG_UNUSED note).
3746
3747 If you start at the top of the block, use one of DF_LIVE_IN or
3748 DF_LR_IN. If you start at the bottom of the block use one of
3749 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3750 THEY WILL BE DESTROYED.
3751 ----------------------------------------------------------------------------*/
3752
3753
3754 /* Find the set of DEFs for INSN. */
3755
3756 void
3757 df_simulate_find_defs (rtx_insn *insn, bitmap defs)
3758 {
3759 df_ref def;
3760
3761 FOR_EACH_INSN_DEF (def, insn)
3762 bitmap_set_bit (defs, DF_REF_REGNO (def));
3763 }
3764
3765 /* Find the set of uses for INSN. This includes partial defs. */
3766
3767 static void
3768 df_simulate_find_uses (rtx_insn *insn, bitmap uses)
3769 {
3770 df_ref def, use;
3771 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
3772
3773 FOR_EACH_INSN_INFO_DEF (def, insn_info)
3774 if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3775 bitmap_set_bit (uses, DF_REF_REGNO (def));
3776 FOR_EACH_INSN_INFO_USE (use, insn_info)
3777 bitmap_set_bit (uses, DF_REF_REGNO (use));
3778 }
3779
3780 /* Find the set of real DEFs, which are not clobbers, for INSN. */
3781
3782 void
3783 df_simulate_find_noclobber_defs (rtx_insn *insn, bitmap defs)
3784 {
3785 df_ref def;
3786
3787 FOR_EACH_INSN_DEF (def, insn)
3788 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3789 bitmap_set_bit (defs, DF_REF_REGNO (def));
3790 }
3791
3792
3793 /* Simulate the effects of the defs of INSN on LIVE. */
3794
3795 void
3796 df_simulate_defs (rtx_insn *insn, bitmap live)
3797 {
3798 df_ref def;
3799
3800 FOR_EACH_INSN_DEF (def, insn)
3801 {
3802 unsigned int dregno = DF_REF_REGNO (def);
3803
3804 /* If the def is to only part of the reg, it does
3805 not kill the other defs that reach here. */
3806 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3807 bitmap_clear_bit (live, dregno);
3808 }
3809 }
3810
3811
3812 /* Simulate the effects of the uses of INSN on LIVE. */
3813
3814 void
3815 df_simulate_uses (rtx_insn *insn, bitmap live)
3816 {
3817 df_ref use;
3818
3819 if (DEBUG_INSN_P (insn))
3820 return;
3821
3822 FOR_EACH_INSN_USE (use, insn)
3823 /* Add use to set of uses in this BB. */
3824 bitmap_set_bit (live, DF_REF_REGNO (use));
3825 }
3826
3827
3828 /* Add back the always live regs in BB to LIVE. */
3829
3830 static inline void
3831 df_simulate_fixup_sets (basic_block bb, bitmap live)
3832 {
3833 /* These regs are considered always live so if they end up dying
3834 because of some def, we need to bring the back again. */
3835 if (bb_has_eh_pred (bb))
3836 bitmap_ior_into (live, &df->eh_block_artificial_uses);
3837 else
3838 bitmap_ior_into (live, &df->regular_block_artificial_uses);
3839 }
3840
3841
3842 /*----------------------------------------------------------------------------
3843 The following three functions are used only for BACKWARDS scanning:
3844 i.e. they process the defs before the uses.
3845
3846 df_simulate_initialize_backwards should be called first with a
3847 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
3848 df_simulate_one_insn_backwards should be called for each insn in
3849 the block, starting with the last one. Finally,
3850 df_simulate_finalize_backwards can be called to get a new value
3851 of the sets at the top of the block (this is rarely used).
3852 ----------------------------------------------------------------------------*/
3853
3854 /* Apply the artificial uses and defs at the end of BB in a backwards
3855 direction. */
3856
3857 void
3858 df_simulate_initialize_backwards (basic_block bb, bitmap live)
3859 {
3860 df_ref def, use;
3861 int bb_index = bb->index;
3862
3863 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3864 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3865 bitmap_clear_bit (live, DF_REF_REGNO (def));
3866
3867 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3868 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3869 bitmap_set_bit (live, DF_REF_REGNO (use));
3870 }
3871
3872
3873 /* Simulate the backwards effects of INSN on the bitmap LIVE. */
3874
3875 void
3876 df_simulate_one_insn_backwards (basic_block bb, rtx_insn *insn, bitmap live)
3877 {
3878 if (!NONDEBUG_INSN_P (insn))
3879 return;
3880
3881 df_simulate_defs (insn, live);
3882 df_simulate_uses (insn, live);
3883 df_simulate_fixup_sets (bb, live);
3884 }
3885
3886
3887 /* Apply the artificial uses and defs at the top of BB in a backwards
3888 direction. */
3889
3890 void
3891 df_simulate_finalize_backwards (basic_block bb, bitmap live)
3892 {
3893 df_ref def;
3894 #ifdef EH_USES
3895 df_ref use;
3896 #endif
3897 int bb_index = bb->index;
3898
3899 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3900 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3901 bitmap_clear_bit (live, DF_REF_REGNO (def));
3902
3903 #ifdef EH_USES
3904 FOR_EACH_ARTIFICIAL_USE (use, bb_index)
3905 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3906 bitmap_set_bit (live, DF_REF_REGNO (use));
3907 #endif
3908 }
3909 /*----------------------------------------------------------------------------
3910 The following three functions are used only for FORWARDS scanning:
3911 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
3912 Thus it is important to add the DF_NOTES problem to the stack of
3913 problems computed before using these functions.
3914
3915 df_simulate_initialize_forwards should be called first with a
3916 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3917 df_simulate_one_insn_forwards should be called for each insn in
3918 the block, starting with the first one.
3919 ----------------------------------------------------------------------------*/
3920
3921 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3922 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3923 defs live. */
3924
3925 void
3926 df_simulate_initialize_forwards (basic_block bb, bitmap live)
3927 {
3928 df_ref def;
3929 int bb_index = bb->index;
3930
3931 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
3932 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3933 bitmap_set_bit (live, DF_REF_REGNO (def));
3934 }
3935
3936 /* Simulate the forwards effects of INSN on the bitmap LIVE. */
3937
3938 void
3939 df_simulate_one_insn_forwards (basic_block bb, rtx_insn *insn, bitmap live)
3940 {
3941 rtx link;
3942 if (! INSN_P (insn))
3943 return;
3944
3945 /* Make sure that DF_NOTE really is an active df problem. */
3946 gcc_assert (df_note);
3947
3948 /* Note that this is the opposite as how the problem is defined, because
3949 in the LR problem defs _kill_ liveness. However, they do so backwards,
3950 while here the scan is performed forwards! So, first assume that the
3951 def is live, and if this is not true REG_UNUSED notes will rectify the
3952 situation. */
3953 df_simulate_find_noclobber_defs (insn, live);
3954
3955 /* Clear all of the registers that go dead. */
3956 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3957 {
3958 switch (REG_NOTE_KIND (link))
3959 {
3960 case REG_DEAD:
3961 case REG_UNUSED:
3962 {
3963 rtx reg = XEXP (link, 0);
3964 bitmap_clear_range (live, REGNO (reg), REG_NREGS (reg));
3965 }
3966 break;
3967 default:
3968 break;
3969 }
3970 }
3971 df_simulate_fixup_sets (bb, live);
3972 }
3973 \f
3974 /* Used by the next two functions to encode information about the
3975 memory references we found. */
3976 #define MEMREF_NORMAL 1
3977 #define MEMREF_VOLATILE 2
3978
3979 /* Return an OR of MEMREF_NORMAL or MEMREF_VOLATILE for the MEMs in X. */
3980
3981 static int
3982 find_memory (rtx_insn *insn)
3983 {
3984 int flags = 0;
3985 subrtx_iterator::array_type array;
3986 FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
3987 {
3988 const_rtx x = *iter;
3989 if (GET_CODE (x) == ASM_OPERANDS && MEM_VOLATILE_P (x))
3990 flags |= MEMREF_VOLATILE;
3991 else if (MEM_P (x))
3992 {
3993 if (MEM_VOLATILE_P (x))
3994 flags |= MEMREF_VOLATILE;
3995 else if (!MEM_READONLY_P (x))
3996 flags |= MEMREF_NORMAL;
3997 }
3998 }
3999 return flags;
4000 }
4001
4002 /* A subroutine of can_move_insns_across_p called through note_stores.
4003 DATA points to an integer in which we set either the bit for
4004 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
4005 of either kind. */
4006
4007 static void
4008 find_memory_stores (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
4009 void *data ATTRIBUTE_UNUSED)
4010 {
4011 int *pflags = (int *)data;
4012 if (GET_CODE (x) == SUBREG)
4013 x = XEXP (x, 0);
4014 /* Treat stores to SP as stores to memory, this will prevent problems
4015 when there are references to the stack frame. */
4016 if (x == stack_pointer_rtx)
4017 *pflags |= MEMREF_VOLATILE;
4018 if (!MEM_P (x))
4019 return;
4020 *pflags |= MEM_VOLATILE_P (x) ? MEMREF_VOLATILE : MEMREF_NORMAL;
4021 }
4022
4023 /* Scan BB backwards, using df_simulate functions to keep track of
4024 lifetimes, up to insn POINT. The result is stored in LIVE. */
4025
4026 void
4027 simulate_backwards_to_point (basic_block bb, regset live, rtx point)
4028 {
4029 rtx_insn *insn;
4030 bitmap_copy (live, df_get_live_out (bb));
4031 df_simulate_initialize_backwards (bb, live);
4032
4033 /* Scan and update life information until we reach the point we're
4034 interested in. */
4035 for (insn = BB_END (bb); insn != point; insn = PREV_INSN (insn))
4036 df_simulate_one_insn_backwards (bb, insn, live);
4037 }
4038
4039 /* Return true if it is safe to move a group of insns, described by
4040 the range FROM to TO, backwards across another group of insns,
4041 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
4042 are no insns between ACROSS_TO and FROM, but they may be in
4043 different basic blocks; MERGE_BB is the block from which the
4044 insns will be moved. The caller must pass in a regset MERGE_LIVE
4045 which specifies the registers live after TO.
4046
4047 This function may be called in one of two cases: either we try to
4048 move identical instructions from all successor blocks into their
4049 predecessor, or we try to move from only one successor block. If
4050 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
4051 the second case. It should contain a set of registers live at the
4052 end of ACROSS_TO which must not be clobbered by moving the insns.
4053 In that case, we're also more careful about moving memory references
4054 and trapping insns.
4055
4056 We return false if it is not safe to move the entire group, but it
4057 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
4058 is set to point at the last moveable insn in such a case. */
4059
4060 bool
4061 can_move_insns_across (rtx_insn *from, rtx_insn *to,
4062 rtx_insn *across_from, rtx_insn *across_to,
4063 basic_block merge_bb, regset merge_live,
4064 regset other_branch_live, rtx_insn **pmove_upto)
4065 {
4066 rtx_insn *insn, *next, *max_to;
4067 bitmap merge_set, merge_use, local_merge_live;
4068 bitmap test_set, test_use;
4069 unsigned i, fail = 0;
4070 bitmap_iterator bi;
4071 int memrefs_in_across = 0;
4072 int mem_sets_in_across = 0;
4073 bool trapping_insns_in_across = false;
4074
4075 if (pmove_upto != NULL)
4076 *pmove_upto = NULL;
4077
4078 /* Find real bounds, ignoring debug insns. */
4079 while (!NONDEBUG_INSN_P (from) && from != to)
4080 from = NEXT_INSN (from);
4081 while (!NONDEBUG_INSN_P (to) && from != to)
4082 to = PREV_INSN (to);
4083
4084 for (insn = across_to; ; insn = next)
4085 {
4086 if (CALL_P (insn))
4087 {
4088 if (RTL_CONST_OR_PURE_CALL_P (insn))
4089 /* Pure functions can read from memory. Const functions can
4090 read from arguments that the ABI has forced onto the stack.
4091 Neither sort of read can be volatile. */
4092 memrefs_in_across |= MEMREF_NORMAL;
4093 else
4094 {
4095 memrefs_in_across |= MEMREF_VOLATILE;
4096 mem_sets_in_across |= MEMREF_VOLATILE;
4097 }
4098 }
4099 if (NONDEBUG_INSN_P (insn))
4100 {
4101 if (volatile_insn_p (PATTERN (insn)))
4102 return false;
4103 memrefs_in_across |= find_memory (insn);
4104 note_stores (insn, find_memory_stores, &mem_sets_in_across);
4105 /* This is used just to find sets of the stack pointer. */
4106 memrefs_in_across |= mem_sets_in_across;
4107 trapping_insns_in_across |= may_trap_p (PATTERN (insn));
4108 }
4109 next = PREV_INSN (insn);
4110 if (insn == across_from)
4111 break;
4112 }
4113
4114 /* Collect:
4115 MERGE_SET = set of registers set in MERGE_BB
4116 MERGE_USE = set of registers used in MERGE_BB and live at its top
4117 MERGE_LIVE = set of registers live at the point inside the MERGE
4118 range that we've reached during scanning
4119 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
4120 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
4121 and live before ACROSS_FROM. */
4122
4123 merge_set = BITMAP_ALLOC (&reg_obstack);
4124 merge_use = BITMAP_ALLOC (&reg_obstack);
4125 local_merge_live = BITMAP_ALLOC (&reg_obstack);
4126 test_set = BITMAP_ALLOC (&reg_obstack);
4127 test_use = BITMAP_ALLOC (&reg_obstack);
4128
4129 /* Compute the set of registers set and used in the ACROSS range. */
4130 if (other_branch_live != NULL)
4131 bitmap_copy (test_use, other_branch_live);
4132 df_simulate_initialize_backwards (merge_bb, test_use);
4133 for (insn = across_to; ; insn = next)
4134 {
4135 if (NONDEBUG_INSN_P (insn))
4136 {
4137 df_simulate_find_defs (insn, test_set);
4138 df_simulate_defs (insn, test_use);
4139 df_simulate_uses (insn, test_use);
4140 }
4141 next = PREV_INSN (insn);
4142 if (insn == across_from)
4143 break;
4144 }
4145
4146 /* Compute an upper bound for the amount of insns moved, by finding
4147 the first insn in MERGE that sets a register in TEST_USE, or uses
4148 a register in TEST_SET. We also check for calls, trapping operations,
4149 and memory references. */
4150 max_to = NULL;
4151 for (insn = from; ; insn = next)
4152 {
4153 if (CALL_P (insn))
4154 break;
4155 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
4156 break;
4157 if (NONDEBUG_INSN_P (insn))
4158 {
4159 if (may_trap_or_fault_p (PATTERN (insn))
4160 && (trapping_insns_in_across
4161 || other_branch_live != NULL
4162 || volatile_insn_p (PATTERN (insn))))
4163 break;
4164
4165 /* We cannot move memory stores past each other, or move memory
4166 reads past stores, at least not without tracking them and
4167 calling true_dependence on every pair.
4168
4169 If there is no other branch and no memory references or
4170 sets in the ACROSS range, we can move memory references
4171 freely, even volatile ones.
4172
4173 Otherwise, the rules are as follows: volatile memory
4174 references and stores can't be moved at all, and any type
4175 of memory reference can't be moved if there are volatile
4176 accesses or stores in the ACROSS range. That leaves
4177 normal reads, which can be moved, as the trapping case is
4178 dealt with elsewhere. */
4179 if (other_branch_live != NULL || memrefs_in_across != 0)
4180 {
4181 int mem_ref_flags = 0;
4182 int mem_set_flags = 0;
4183 note_stores (insn, find_memory_stores, &mem_set_flags);
4184 mem_ref_flags = find_memory (insn);
4185 /* Catch sets of the stack pointer. */
4186 mem_ref_flags |= mem_set_flags;
4187
4188 if ((mem_ref_flags | mem_set_flags) & MEMREF_VOLATILE)
4189 break;
4190 if ((memrefs_in_across & MEMREF_VOLATILE) && mem_ref_flags != 0)
4191 break;
4192 if (mem_set_flags != 0
4193 || (mem_sets_in_across != 0 && mem_ref_flags != 0))
4194 break;
4195 }
4196 df_simulate_find_uses (insn, merge_use);
4197 /* We're only interested in uses which use a value live at
4198 the top, not one previously set in this block. */
4199 bitmap_and_compl_into (merge_use, merge_set);
4200 df_simulate_find_defs (insn, merge_set);
4201 if (bitmap_intersect_p (merge_set, test_use)
4202 || bitmap_intersect_p (merge_use, test_set))
4203 break;
4204 if (!HAVE_cc0 || !sets_cc0_p (insn))
4205 max_to = insn;
4206 }
4207 next = NEXT_INSN (insn);
4208 if (insn == to)
4209 break;
4210 }
4211 if (max_to != to)
4212 fail = 1;
4213
4214 if (max_to == NULL_RTX || (fail && pmove_upto == NULL))
4215 goto out;
4216
4217 /* Now, lower this upper bound by also taking into account that
4218 a range of insns moved across ACROSS must not leave a register
4219 live at the end that will be clobbered in ACROSS. We need to
4220 find a point where TEST_SET & LIVE == 0.
4221
4222 Insns in the MERGE range that set registers which are also set
4223 in the ACROSS range may still be moved as long as we also move
4224 later insns which use the results of the set, and make the
4225 register dead again. This is verified by the condition stated
4226 above. We only need to test it for registers that are set in
4227 the moved region.
4228
4229 MERGE_LIVE is provided by the caller and holds live registers after
4230 TO. */
4231 bitmap_copy (local_merge_live, merge_live);
4232 for (insn = to; insn != max_to; insn = PREV_INSN (insn))
4233 df_simulate_one_insn_backwards (merge_bb, insn, local_merge_live);
4234
4235 /* We're not interested in registers that aren't set in the moved
4236 region at all. */
4237 bitmap_and_into (local_merge_live, merge_set);
4238 for (;;)
4239 {
4240 if (NONDEBUG_INSN_P (insn))
4241 {
4242 if (!bitmap_intersect_p (test_set, local_merge_live)
4243 && (!HAVE_cc0 || !sets_cc0_p (insn)))
4244 {
4245 max_to = insn;
4246 break;
4247 }
4248
4249 df_simulate_one_insn_backwards (merge_bb, insn,
4250 local_merge_live);
4251 }
4252 if (insn == from)
4253 {
4254 fail = 1;
4255 goto out;
4256 }
4257 insn = PREV_INSN (insn);
4258 }
4259
4260 if (max_to != to)
4261 fail = 1;
4262
4263 if (pmove_upto)
4264 *pmove_upto = max_to;
4265
4266 /* For small register class machines, don't lengthen lifetimes of
4267 hard registers before reload. */
4268 if (! reload_completed
4269 && targetm.small_register_classes_for_mode_p (VOIDmode))
4270 {
4271 EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
4272 {
4273 if (i < FIRST_PSEUDO_REGISTER
4274 && ! fixed_regs[i]
4275 && ! global_regs[i])
4276 {
4277 fail = 1;
4278 break;
4279 }
4280 }
4281 }
4282
4283 out:
4284 BITMAP_FREE (merge_set);
4285 BITMAP_FREE (merge_use);
4286 BITMAP_FREE (local_merge_live);
4287 BITMAP_FREE (test_set);
4288 BITMAP_FREE (test_use);
4289
4290 return !fail;
4291 }
4292
4293 \f
4294 /*----------------------------------------------------------------------------
4295 MULTIPLE DEFINITIONS
4296
4297 Find the locations in the function reached by multiple definition sites
4298 for a live pseudo. In and out bitvectors are built for each basic
4299 block. They are restricted for efficiency to live registers.
4300
4301 The gen and kill sets for the problem are obvious. Together they
4302 include all defined registers in a basic block; the gen set includes
4303 registers where a partial or conditional or may-clobber definition is
4304 last in the BB, while the kill set includes registers with a complete
4305 definition coming last. However, the computation of the dataflow
4306 itself is interesting.
4307
4308 The idea behind it comes from SSA form's iterated dominance frontier
4309 criterion for inserting PHI functions. Just like in that case, we can use
4310 the dominance frontier to find places where multiple definitions meet;
4311 a register X defined in a basic block BB1 has multiple definitions in
4312 basic blocks in BB1's dominance frontier.
4313
4314 So, the in-set of a basic block BB2 is not just the union of the
4315 out-sets of BB2's predecessors, but includes some more bits that come
4316 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
4317 the previous paragraph). I called this set the init-set of BB2.
4318
4319 (Note: I actually use the kill-set only to build the init-set.
4320 gen bits are anyway propagated from BB1 to BB2 by dataflow).
4321
4322 For example, if you have
4323
4324 BB1 : r10 = 0
4325 r11 = 0
4326 if <...> goto BB2 else goto BB3;
4327
4328 BB2 : r10 = 1
4329 r12 = 1
4330 goto BB3;
4331
4332 BB3 :
4333
4334 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
4335 init-set of BB3 includes r10 and r12, but not r11. Note that we do
4336 not need to iterate the dominance frontier, because we do not insert
4337 anything like PHI functions there! Instead, dataflow will take care of
4338 propagating the information to BB3's successors.
4339 ---------------------------------------------------------------------------*/
4340
4341 /* Private data used to verify the solution for this problem. */
4342 struct df_md_problem_data
4343 {
4344 /* An obstack for the bitmaps we need for this problem. */
4345 bitmap_obstack md_bitmaps;
4346 };
4347
4348 /* Scratch var used by transfer functions. This is used to do md analysis
4349 only for live registers. */
4350 static bitmap_head df_md_scratch;
4351
4352
4353 static void
4354 df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
4355 void *vbb_info)
4356 {
4357 class df_md_bb_info *bb_info = (class df_md_bb_info *) vbb_info;
4358 if (bb_info)
4359 {
4360 bitmap_clear (&bb_info->kill);
4361 bitmap_clear (&bb_info->gen);
4362 bitmap_clear (&bb_info->init);
4363 bitmap_clear (&bb_info->in);
4364 bitmap_clear (&bb_info->out);
4365 }
4366 }
4367
4368
4369 /* Allocate or reset bitmaps for DF_MD. The solution bits are
4370 not touched unless the block is new. */
4371
4372 static void
4373 df_md_alloc (bitmap all_blocks)
4374 {
4375 unsigned int bb_index;
4376 bitmap_iterator bi;
4377 struct df_md_problem_data *problem_data;
4378
4379 df_grow_bb_info (df_md);
4380 if (df_md->problem_data)
4381 problem_data = (struct df_md_problem_data *) df_md->problem_data;
4382 else
4383 {
4384 problem_data = XNEW (struct df_md_problem_data);
4385 df_md->problem_data = problem_data;
4386 bitmap_obstack_initialize (&problem_data->md_bitmaps);
4387 }
4388 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
4389
4390 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4391 {
4392 class df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4393 /* When bitmaps are already initialized, just clear them. */
4394 if (bb_info->init.obstack)
4395 {
4396 bitmap_clear (&bb_info->init);
4397 bitmap_clear (&bb_info->gen);
4398 bitmap_clear (&bb_info->kill);
4399 bitmap_clear (&bb_info->in);
4400 bitmap_clear (&bb_info->out);
4401 }
4402 else
4403 {
4404 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4405 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4406 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4407 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4408 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
4409 }
4410 }
4411
4412 df_md->optional_p = true;
4413 }
4414
4415 /* Add the effect of the top artificial defs of BB to the multiple definitions
4416 bitmap LOCAL_MD. */
4417
4418 void
4419 df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4420 {
4421 int bb_index = bb->index;
4422 df_ref def;
4423 FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
4424 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4425 {
4426 unsigned int dregno = DF_REF_REGNO (def);
4427 if (DF_REF_FLAGS (def)
4428 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4429 bitmap_set_bit (local_md, dregno);
4430 else
4431 bitmap_clear_bit (local_md, dregno);
4432 }
4433 }
4434
4435
4436 /* Add the effect of the defs of INSN to the reaching definitions bitmap
4437 LOCAL_MD. */
4438
4439 void
4440 df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx_insn *insn,
4441 bitmap local_md)
4442 {
4443 df_ref def;
4444
4445 FOR_EACH_INSN_DEF (def, insn)
4446 {
4447 unsigned int dregno = DF_REF_REGNO (def);
4448 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4449 || (dregno >= FIRST_PSEUDO_REGISTER))
4450 {
4451 if (DF_REF_FLAGS (def)
4452 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4453 bitmap_set_bit (local_md, DF_REF_ID (def));
4454 else
4455 bitmap_clear_bit (local_md, DF_REF_ID (def));
4456 }
4457 }
4458 }
4459
4460 static void
4461 df_md_bb_local_compute_process_def (class df_md_bb_info *bb_info,
4462 df_ref def,
4463 int top_flag)
4464 {
4465 bitmap_clear (&seen_in_insn);
4466
4467 for (; def; def = DF_REF_NEXT_LOC (def))
4468 {
4469 unsigned int dregno = DF_REF_REGNO (def);
4470 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4471 || (dregno >= FIRST_PSEUDO_REGISTER))
4472 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4473 {
4474 if (!bitmap_bit_p (&seen_in_insn, dregno))
4475 {
4476 if (DF_REF_FLAGS (def)
4477 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4478 {
4479 bitmap_set_bit (&bb_info->gen, dregno);
4480 bitmap_clear_bit (&bb_info->kill, dregno);
4481 }
4482 else
4483 {
4484 /* When we find a clobber and a regular def,
4485 make sure the regular def wins. */
4486 bitmap_set_bit (&seen_in_insn, dregno);
4487 bitmap_set_bit (&bb_info->kill, dregno);
4488 bitmap_clear_bit (&bb_info->gen, dregno);
4489 }
4490 }
4491 }
4492 }
4493 }
4494
4495
4496 /* Compute local multiple def info for basic block BB. */
4497
4498 static void
4499 df_md_bb_local_compute (unsigned int bb_index)
4500 {
4501 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4502 class df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4503 rtx_insn *insn;
4504
4505 /* Artificials are only hard regs. */
4506 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4507 df_md_bb_local_compute_process_def (bb_info,
4508 df_get_artificial_defs (bb_index),
4509 DF_REF_AT_TOP);
4510
4511 FOR_BB_INSNS (bb, insn)
4512 {
4513 unsigned int uid = INSN_UID (insn);
4514 if (!INSN_P (insn))
4515 continue;
4516
4517 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4518 }
4519
4520 if (!(df->changeable_flags & DF_NO_HARD_REGS))
4521 df_md_bb_local_compute_process_def (bb_info,
4522 df_get_artificial_defs (bb_index),
4523 0);
4524 }
4525
4526 /* Compute local reaching def info for each basic block within BLOCKS. */
4527
4528 static void
4529 df_md_local_compute (bitmap all_blocks)
4530 {
4531 unsigned int bb_index, df_bb_index;
4532 bitmap_iterator bi1, bi2;
4533 basic_block bb;
4534 bitmap_head *frontiers;
4535
4536 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
4537
4538 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4539 {
4540 df_md_bb_local_compute (bb_index);
4541 }
4542
4543 bitmap_release (&seen_in_insn);
4544
4545 frontiers = XNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
4546 FOR_ALL_BB_FN (bb, cfun)
4547 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
4548
4549 compute_dominance_frontiers (frontiers);
4550
4551 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4552 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4553 {
4554 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
4555 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
4556 {
4557 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, df_bb_index);
4558 if (bitmap_bit_p (all_blocks, df_bb_index))
4559 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
4560 df_get_live_in (bb));
4561 }
4562 }
4563
4564 FOR_ALL_BB_FN (bb, cfun)
4565 bitmap_clear (&frontiers[bb->index]);
4566 free (frontiers);
4567 }
4568
4569
4570 /* Reset the global solution for recalculation. */
4571
4572 static void
4573 df_md_reset (bitmap all_blocks)
4574 {
4575 unsigned int bb_index;
4576 bitmap_iterator bi;
4577
4578 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4579 {
4580 class df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4581 gcc_assert (bb_info);
4582 bitmap_clear (&bb_info->in);
4583 bitmap_clear (&bb_info->out);
4584 }
4585 }
4586
4587 static bool
4588 df_md_transfer_function (int bb_index)
4589 {
4590 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
4591 class df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4592 bitmap in = &bb_info->in;
4593 bitmap out = &bb_info->out;
4594 bitmap gen = &bb_info->gen;
4595 bitmap kill = &bb_info->kill;
4596
4597 /* We need to use a scratch set here so that the value returned from this
4598 function invocation properly reflects whether the sets changed in a
4599 significant way; i.e. not just because the live set was anded in. */
4600 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
4601
4602 /* Multiple definitions of a register are not relevant if it is not
4603 live. Thus we trim the result to the places where it is live. */
4604 bitmap_and_into (in, df_get_live_in (bb));
4605
4606 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
4607 }
4608
4609 /* Initialize the solution bit vectors for problem. */
4610
4611 static void
4612 df_md_init (bitmap all_blocks)
4613 {
4614 unsigned int bb_index;
4615 bitmap_iterator bi;
4616
4617 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4618 {
4619 class df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4620
4621 bitmap_copy (&bb_info->in, &bb_info->init);
4622 df_md_transfer_function (bb_index);
4623 }
4624 }
4625
4626 static void
4627 df_md_confluence_0 (basic_block bb)
4628 {
4629 class df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4630 bitmap_copy (&bb_info->in, &bb_info->init);
4631 }
4632
4633 /* In of target gets or of out of source. */
4634
4635 static bool
4636 df_md_confluence_n (edge e)
4637 {
4638 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4639 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
4640
4641 if (e->flags & EDGE_FAKE)
4642 return false;
4643
4644 if (e->flags & EDGE_EH)
4645 {
4646 /* Conservatively treat partially-clobbered registers as surviving
4647 across the edge; they might or might not, depending on what mode
4648 they have. */
4649 bitmap_view<HARD_REG_SET> eh_kills (eh_edge_abi.full_reg_clobbers ());
4650 return bitmap_ior_and_compl_into (op1, op2, eh_kills);
4651 }
4652 else
4653 return bitmap_ior_into (op1, op2);
4654 }
4655
4656 /* Free all storage associated with the problem. */
4657
4658 static void
4659 df_md_free (void)
4660 {
4661 struct df_md_problem_data *problem_data
4662 = (struct df_md_problem_data *) df_md->problem_data;
4663
4664 bitmap_release (&df_md_scratch);
4665 bitmap_obstack_release (&problem_data->md_bitmaps);
4666 free (problem_data);
4667 df_md->problem_data = NULL;
4668
4669 df_md->block_info_size = 0;
4670 free (df_md->block_info);
4671 df_md->block_info = NULL;
4672 free (df_md);
4673 }
4674
4675
4676 /* Debugging info at top of bb. */
4677
4678 static void
4679 df_md_top_dump (basic_block bb, FILE *file)
4680 {
4681 class df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4682 if (!bb_info)
4683 return;
4684
4685 fprintf (file, ";; md in \t");
4686 df_print_regset (file, &bb_info->in);
4687 fprintf (file, ";; md init \t");
4688 df_print_regset (file, &bb_info->init);
4689 fprintf (file, ";; md gen \t");
4690 df_print_regset (file, &bb_info->gen);
4691 fprintf (file, ";; md kill \t");
4692 df_print_regset (file, &bb_info->kill);
4693 }
4694
4695 /* Debugging info at bottom of bb. */
4696
4697 static void
4698 df_md_bottom_dump (basic_block bb, FILE *file)
4699 {
4700 class df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
4701 if (!bb_info)
4702 return;
4703
4704 fprintf (file, ";; md out \t");
4705 df_print_regset (file, &bb_info->out);
4706 }
4707
4708 static const struct df_problem problem_MD =
4709 {
4710 DF_MD, /* Problem id. */
4711 DF_FORWARD, /* Direction. */
4712 df_md_alloc, /* Allocate the problem specific data. */
4713 df_md_reset, /* Reset global information. */
4714 df_md_free_bb_info, /* Free basic block info. */
4715 df_md_local_compute, /* Local compute function. */
4716 df_md_init, /* Init the solution specific data. */
4717 df_worklist_dataflow, /* Worklist solver. */
4718 df_md_confluence_0, /* Confluence operator 0. */
4719 df_md_confluence_n, /* Confluence operator n. */
4720 df_md_transfer_function, /* Transfer function. */
4721 NULL, /* Finalize function. */
4722 df_md_free, /* Free all of the problem information. */
4723 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4724 NULL, /* Debugging. */
4725 df_md_top_dump, /* Debugging start block. */
4726 df_md_bottom_dump, /* Debugging end block. */
4727 NULL, /* Debugging start insn. */
4728 NULL, /* Debugging end insn. */
4729 NULL, /* Incremental solution verify start. */
4730 NULL, /* Incremental solution verify end. */
4731 NULL, /* Dependent problem. */
4732 sizeof (class df_md_bb_info),/* Size of entry of block_info array. */
4733 TV_DF_MD, /* Timing variable. */
4734 false /* Reset blocks on dropping out of blocks_to_analyze. */
4735 };
4736
4737 /* Create a new MD instance and add it to the existing instance
4738 of DF. */
4739
4740 void
4741 df_md_add_problem (void)
4742 {
4743 df_add_problem (&problem_MD);
4744 }
4745
4746
4747