]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/df-problems.c
sse.md (sse4_2_pcmpestr): Use reg_not_xmm0_operand constraint for operand2.
[thirdparty/gcc.git] / gcc / df-problems.c
CommitLineData
4d779342 1/* Standard problems for dataflow support routines.
6fb5fa3c 2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4d779342
DB
3 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
8
9This file is part of GCC.
10
11GCC is free software; you can redistribute it and/or modify it under
12the terms of the GNU General Public License as published by the Free
9dcd6f09 13Software Foundation; either version 3, or (at your option) any later
4d779342
DB
14version.
15
16GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17WARRANTY; without even the implied warranty of MERCHANTABILITY or
18FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19for more details.
20
21You should have received a copy of the GNU General Public License
9dcd6f09
NC
22along with GCC; see the file COPYING3. If not see
23<http://www.gnu.org/licenses/>. */
4d779342
DB
24
25#include "config.h"
26#include "system.h"
27#include "coretypes.h"
28#include "tm.h"
29#include "rtl.h"
30#include "tm_p.h"
31#include "insn-config.h"
32#include "recog.h"
33#include "function.h"
34#include "regs.h"
35#include "output.h"
36#include "alloc-pool.h"
37#include "flags.h"
38#include "hard-reg-set.h"
39#include "basic-block.h"
40#include "sbitmap.h"
41#include "bitmap.h"
42#include "timevar.h"
43#include "df.h"
23249ac4 44#include "except.h"
6fb5fa3c
DB
45#include "dce.h"
46#include "vecprim.h"
23249ac4 47
e44e043c
KZ
48/* Note that turning REG_DEAD_DEBUGGING on will cause
49 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
50 addresses in the dumps. */
23249ac4
DB
51#if 0
52#define REG_DEAD_DEBUGGING
53#endif
4d779342
DB
54
55#define DF_SPARSE_THRESHOLD 32
56
57static bitmap seen_in_block = NULL;
58static bitmap seen_in_insn = NULL;
59
60\f
61/*----------------------------------------------------------------------------
62 Public functions access functions for the dataflow problems.
63----------------------------------------------------------------------------*/
6fb5fa3c
DB
64/* Get the live at out set for BB no matter what problem happens to be
65 defined. This function is used by the register allocators who
66 choose different dataflow problems depending on the optimization
67 level. */
4d779342 68
6fb5fa3c
DB
69bitmap
70df_get_live_out (basic_block bb)
4d779342 71{
6fb5fa3c 72 gcc_assert (df_lr);
4d779342 73
ba49cb7b 74 if (df_live)
6fb5fa3c
DB
75 return DF_LIVE_OUT (bb);
76 else
77 return DF_LR_OUT (bb);
4d779342
DB
78}
79
6fb5fa3c
DB
80/* Get the live at in set for BB no matter what problem happens to be
81 defined. This function is used by the register allocators who
82 choose different dataflow problems depending on the optimization
83 level. */
4d779342
DB
84
85bitmap
6fb5fa3c 86df_get_live_in (basic_block bb)
4d779342 87{
6fb5fa3c 88 gcc_assert (df_lr);
4d779342 89
ba49cb7b 90 if (df_live)
6fb5fa3c 91 return DF_LIVE_IN (bb);
4d779342 92 else
6fb5fa3c 93 return DF_LR_IN (bb);
4d779342
DB
94}
95
4d779342
DB
96/*----------------------------------------------------------------------------
97 Utility functions.
98----------------------------------------------------------------------------*/
99
100/* Generic versions to get the void* version of the block info. Only
c0220ea4 101 used inside the problem instance vectors. */
4d779342
DB
102
103/* Grow the bb_info array. */
104
105void
106df_grow_bb_info (struct dataflow *dflow)
107{
108 unsigned int new_size = last_basic_block + 1;
109 if (dflow->block_info_size < new_size)
110 {
111 new_size += new_size / 4;
112 dflow->block_info = xrealloc (dflow->block_info,
113 new_size *sizeof (void*));
114 memset (dflow->block_info + dflow->block_info_size, 0,
115 (new_size - dflow->block_info_size) *sizeof (void *));
116 dflow->block_info_size = new_size;
117 }
118}
119
120/* Dump a def-use or use-def chain for REF to FILE. */
121
122void
23249ac4 123df_chain_dump (struct df_link *link, FILE *file)
4d779342
DB
124{
125 fprintf (file, "{ ");
126 for (; link; link = link->next)
127 {
128 fprintf (file, "%c%d(bb %d insn %d) ",
129 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
130 DF_REF_ID (link->ref),
131 DF_REF_BBNO (link->ref),
132 DF_REF_INSN (link->ref) ? DF_REF_INSN_UID (link->ref) : -1);
133 }
134 fprintf (file, "}");
135}
136
137
138/* Print some basic block info as part of df_dump. */
139
140void
141df_print_bb_index (basic_block bb, FILE *file)
142{
143 edge e;
144 edge_iterator ei;
145
6fb5fa3c 146 fprintf (file, "\n( ");
4d779342
DB
147 FOR_EACH_EDGE (e, ei, bb->preds)
148 {
149 basic_block pred = e->src;
6fb5fa3c 150 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
4d779342
DB
151 }
152 fprintf (file, ")->[%d]->( ", bb->index);
153 FOR_EACH_EDGE (e, ei, bb->succs)
154 {
155 basic_block succ = e->dest;
6fb5fa3c 156 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
4d779342
DB
157 }
158 fprintf (file, ")\n");
159}
160
161
4d779342
DB
162
163/* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
164 up correctly. */
165
166static void
167df_set_seen (void)
168{
6fb5fa3c
DB
169 seen_in_block = BITMAP_ALLOC (&df_bitmap_obstack);
170 seen_in_insn = BITMAP_ALLOC (&df_bitmap_obstack);
4d779342
DB
171}
172
173
174static void
175df_unset_seen (void)
176{
177 BITMAP_FREE (seen_in_block);
178 BITMAP_FREE (seen_in_insn);
179}
180
181
4d779342
DB
182\f
183/*----------------------------------------------------------------------------
184 REACHING DEFINITIONS
185
186 Find the locations in the function where each definition site for a
b11550aa
KZ
187 pseudo reaches. In and out bitvectors are built for each basic
188 block. The id field in the ref is used to index into these sets.
189 See df.h for details.
190 ----------------------------------------------------------------------------*/
191
ba49cb7b
KZ
192/* This problem plays a large number of games for the sake of
193 efficiency.
194
195 1) The order of the bits in the bitvectors. After the scanning
196 phase, all of the defs are sorted. All of the defs for the reg 0
197 are first, followed by all defs for reg 1 and so on.
198
199 2) There are two kill sets, one if the number of defs is less or
200 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
201 greater.
202
203 <= : Data is built directly in the kill set.
204
205 > : One level of indirection is used to keep from generating long
206 strings of 1 bits in the kill sets. Bitvectors that are indexed
207 by the regnum are used to represent that there is a killing def
208 for the register. The confluence and transfer functions use
209 these along with the bitmap_clear_range call to remove ranges of
210 bits without actually generating a knockout vector.
211
212 The kill and sparse_kill and the dense_invalidated_by_call and
213 sparse_invalidated_by_call both play this game. */
4d779342 214
b11550aa 215/* Private data used to compute the solution for this problem. These
6fc0bb99 216 data structures are not accessible outside of this module. */
4d779342
DB
217struct df_rd_problem_data
218{
4d779342
DB
219 /* The set of defs to regs invalidated by call. */
220 bitmap sparse_invalidated_by_call;
b11550aa 221 /* The set of defs to regs invalidate by call for rd. */
6fb5fa3c
DB
222 bitmap dense_invalidated_by_call;
223 /* An obstack for the bitmaps we need for this problem. */
224 bitmap_obstack rd_bitmaps;
4d779342
DB
225};
226
4d779342
DB
227/* Set basic block info. */
228
229static void
6fb5fa3c 230df_rd_set_bb_info (unsigned int index,
4d779342
DB
231 struct df_rd_bb_info *bb_info)
232{
6fb5fa3c
DB
233 gcc_assert (df_rd);
234 gcc_assert (index < df_rd->block_info_size);
235 df_rd->block_info[index] = bb_info;
4d779342
DB
236}
237
238
239/* Free basic block info. */
240
241static void
6fb5fa3c 242df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 243 void *vbb_info)
4d779342
DB
244{
245 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
246 if (bb_info)
247 {
248 BITMAP_FREE (bb_info->kill);
249 BITMAP_FREE (bb_info->sparse_kill);
250 BITMAP_FREE (bb_info->gen);
251 BITMAP_FREE (bb_info->in);
252 BITMAP_FREE (bb_info->out);
6fb5fa3c 253 pool_free (df_rd->block_pool, bb_info);
4d779342
DB
254 }
255}
256
257
6fb5fa3c 258/* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
4d779342
DB
259 not touched unless the block is new. */
260
261static void
6fb5fa3c 262df_rd_alloc (bitmap all_blocks)
4d779342
DB
263{
264 unsigned int bb_index;
265 bitmap_iterator bi;
6fb5fa3c 266 struct df_rd_problem_data *problem_data;
4d779342 267
6fb5fa3c
DB
268 if (!df_rd->block_pool)
269 df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
4d779342
DB
270 sizeof (struct df_rd_bb_info), 50);
271
6fb5fa3c 272 if (df_rd->problem_data)
4d779342 273 {
6fb5fa3c 274 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342
DB
275 bitmap_clear (problem_data->sparse_invalidated_by_call);
276 bitmap_clear (problem_data->dense_invalidated_by_call);
277 }
278 else
279 {
6fb5fa3c
DB
280 problem_data = XNEW (struct df_rd_problem_data);
281 df_rd->problem_data = problem_data;
282
283 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
284 problem_data->sparse_invalidated_by_call
285 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
286 problem_data->dense_invalidated_by_call
287 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
4d779342
DB
288 }
289
6fb5fa3c 290 df_grow_bb_info (df_rd);
4d779342 291
23249ac4 292 /* Because of the clustering of all use sites for the same pseudo,
4d779342
DB
293 we have to process all of the blocks before doing the
294 analysis. */
295
23249ac4 296 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 297 {
6fb5fa3c 298 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
299 if (bb_info)
300 {
301 bitmap_clear (bb_info->kill);
302 bitmap_clear (bb_info->sparse_kill);
303 bitmap_clear (bb_info->gen);
304 }
305 else
306 {
6fb5fa3c
DB
307 bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
308 df_rd_set_bb_info (bb_index, bb_info);
309 bb_info->kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
310 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
311 bb_info->gen = BITMAP_ALLOC (&problem_data->rd_bitmaps);
312 bb_info->in = BITMAP_ALLOC (&problem_data->rd_bitmaps);
313 bb_info->out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
4d779342
DB
314 }
315 }
89a95777 316 df_rd->optional_p = true;
4d779342
DB
317}
318
319
320/* Process a list of DEFs for df_rd_bb_local_compute. */
321
322static void
6fb5fa3c
DB
323df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
324 struct df_ref **def_rec,
912f2dac 325 enum df_ref_flags top_flag)
4d779342 326{
6fb5fa3c 327 while (*def_rec)
4d779342 328 {
6fb5fa3c 329 struct df_ref *def = *def_rec;
912f2dac 330 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4d779342 331 {
912f2dac 332 unsigned int regno = DF_REF_REGNO (def);
6fb5fa3c
DB
333 unsigned int begin = DF_DEFS_BEGIN (regno);
334 unsigned int n_defs = DF_DEFS_COUNT (regno);
912f2dac 335
6fb5fa3c
DB
336 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
337 || (regno >= FIRST_PSEUDO_REGISTER))
4d779342 338 {
6fb5fa3c
DB
339 /* Only the last def(s) for a regno in the block has any
340 effect. */
341 if (!bitmap_bit_p (seen_in_block, regno))
4d779342 342 {
6fb5fa3c
DB
343 /* The first def for regno in insn gets to knock out the
344 defs from other instructions. */
345 if ((!bitmap_bit_p (seen_in_insn, regno))
346 /* If the def is to only part of the reg, it does
347 not kill the other defs that reach here. */
348 && (!(DF_REF_FLAGS (def) &
349 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
912f2dac 350 {
6fb5fa3c
DB
351 if (n_defs > DF_SPARSE_THRESHOLD)
352 {
353 bitmap_set_bit (bb_info->sparse_kill, regno);
354 bitmap_clear_range(bb_info->gen, begin, n_defs);
355 }
356 else
357 {
358 bitmap_set_range (bb_info->kill, begin, n_defs);
359 bitmap_clear_range (bb_info->gen, begin, n_defs);
360 }
912f2dac 361 }
6fb5fa3c
DB
362
363 bitmap_set_bit (seen_in_insn, regno);
364 /* All defs for regno in the instruction may be put into
365 the gen set. */
366 if (!(DF_REF_FLAGS (def)
367 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
368 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
4d779342
DB
369 }
370 }
4d779342 371 }
6fb5fa3c 372 def_rec++;
4d779342
DB
373 }
374}
375
376/* Compute local reaching def info for basic block BB. */
377
378static void
6fb5fa3c 379df_rd_bb_local_compute (unsigned int bb_index)
4d779342 380{
4d779342 381 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 382 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
383 rtx insn;
384
385 bitmap_clear (seen_in_block);
386 bitmap_clear (seen_in_insn);
387
6fb5fa3c
DB
388 /* Artificials are only hard regs. */
389 if (!(df->changeable_flags & DF_NO_HARD_REGS))
390 df_rd_bb_local_compute_process_def (bb_info,
391 df_get_artificial_defs (bb_index),
392 0);
912f2dac 393
4d779342
DB
394 FOR_BB_INSNS_REVERSE (bb, insn)
395 {
396 unsigned int uid = INSN_UID (insn);
397
23249ac4 398 if (!INSN_P (insn))
4d779342
DB
399 continue;
400
6fb5fa3c
DB
401 df_rd_bb_local_compute_process_def (bb_info,
402 DF_INSN_UID_DEFS (uid), 0);
4d779342
DB
403
404 /* This complex dance with the two bitmaps is required because
405 instructions can assign twice to the same pseudo. This
406 generally happens with calls that will have one def for the
407 result and another def for the clobber. If only one vector
408 is used and the clobber goes first, the result will be
409 lost. */
410 bitmap_ior_into (seen_in_block, seen_in_insn);
411 bitmap_clear (seen_in_insn);
412 }
413
912f2dac
DB
414 /* Process the artificial defs at the top of the block last since we
415 are going backwards through the block and these are logically at
416 the start. */
6fb5fa3c
DB
417 if (!(df->changeable_flags & DF_NO_HARD_REGS))
418 df_rd_bb_local_compute_process_def (bb_info,
419 df_get_artificial_defs (bb_index),
420 DF_REF_AT_TOP);
4d779342
DB
421}
422
423
424/* Compute local reaching def info for each basic block within BLOCKS. */
425
426static void
6fb5fa3c 427df_rd_local_compute (bitmap all_blocks)
4d779342 428{
4d779342
DB
429 unsigned int bb_index;
430 bitmap_iterator bi;
431 unsigned int regno;
23249ac4 432 struct df_rd_problem_data *problem_data
6fb5fa3c 433 = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342
DB
434 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
435 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
436
437 df_set_seen ();
6fb5fa3c
DB
438
439 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
4d779342
DB
440
441 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
442 {
6fb5fa3c 443 df_rd_bb_local_compute (bb_index);
4d779342
DB
444 }
445
446 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
447 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
448 {
6fb5fa3c
DB
449 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
450 bitmap_set_bit (sparse_invalidated, regno);
4d779342 451 else
6fb5fa3c
DB
452 bitmap_set_range (dense_invalidated,
453 DF_DEFS_BEGIN (regno),
454 DF_DEFS_COUNT (regno));
4d779342
DB
455 }
456 df_unset_seen ();
457}
458
459
460/* Initialize the solution bit vectors for problem. */
461
462static void
6fb5fa3c 463df_rd_init_solution (bitmap all_blocks)
4d779342
DB
464{
465 unsigned int bb_index;
466 bitmap_iterator bi;
467
468 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
469 {
6fb5fa3c 470 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
471
472 bitmap_copy (bb_info->out, bb_info->gen);
473 bitmap_clear (bb_info->in);
474 }
475}
476
477/* In of target gets or of out of source. */
478
479static void
6fb5fa3c 480df_rd_confluence_n (edge e)
4d779342 481{
6fb5fa3c
DB
482 bitmap op1 = df_rd_get_bb_info (e->dest->index)->in;
483 bitmap op2 = df_rd_get_bb_info (e->src->index)->out;
4d779342
DB
484
485 if (e->flags & EDGE_EH)
486 {
23249ac4 487 struct df_rd_problem_data *problem_data
6fb5fa3c 488 = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342
DB
489 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
490 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
4d779342
DB
491 bitmap_iterator bi;
492 unsigned int regno;
6fb5fa3c 493 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
59c52af4
KZ
494
495 bitmap_copy (tmp, op2);
496 bitmap_and_compl_into (tmp, dense_invalidated);
497
4d779342
DB
498 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
499 {
59c52af4 500 bitmap_clear_range (tmp,
6fb5fa3c
DB
501 DF_DEFS_BEGIN (regno),
502 DF_DEFS_COUNT (regno));
4d779342 503 }
59c52af4
KZ
504 bitmap_ior_into (op1, tmp);
505 BITMAP_FREE (tmp);
4d779342
DB
506 }
507 else
508 bitmap_ior_into (op1, op2);
509}
510
511
512/* Transfer function. */
513
514static bool
6fb5fa3c 515df_rd_transfer_function (int bb_index)
4d779342 516{
6fb5fa3c 517 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
518 unsigned int regno;
519 bitmap_iterator bi;
520 bitmap in = bb_info->in;
521 bitmap out = bb_info->out;
522 bitmap gen = bb_info->gen;
523 bitmap kill = bb_info->kill;
524 bitmap sparse_kill = bb_info->sparse_kill;
525
526 if (bitmap_empty_p (sparse_kill))
527 return bitmap_ior_and_compl (out, gen, in, kill);
528 else
529 {
6fb5fa3c 530 struct df_rd_problem_data *problem_data;
4d779342 531 bool changed = false;
6fb5fa3c
DB
532 bitmap tmp;
533
534 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
535 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
536 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
537 tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
538
4d779342
DB
539 bitmap_copy (tmp, in);
540 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
541 {
542 bitmap_clear_range (tmp,
6fb5fa3c
DB
543 DF_DEFS_BEGIN (regno),
544 DF_DEFS_COUNT (regno));
4d779342
DB
545 }
546 bitmap_and_compl_into (tmp, kill);
547 bitmap_ior_into (tmp, gen);
548 changed = !bitmap_equal_p (tmp, out);
549 if (changed)
550 {
551 BITMAP_FREE (out);
552 bb_info->out = tmp;
553 }
554 else
555 BITMAP_FREE (tmp);
556 return changed;
557 }
558}
559
560
561/* Free all storage associated with the problem. */
562
563static void
6fb5fa3c 564df_rd_free (void)
4d779342
DB
565{
566 unsigned int i;
23249ac4 567 struct df_rd_problem_data *problem_data
6fb5fa3c 568 = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342 569
3b8266e2 570 if (problem_data)
4d779342 571 {
6fb5fa3c 572 for (i = 0; i < df_rd->block_info_size; i++)
4d779342 573 {
6fb5fa3c 574 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (i);
3b8266e2
KZ
575 if (bb_info)
576 {
577 BITMAP_FREE (bb_info->kill);
578 BITMAP_FREE (bb_info->sparse_kill);
579 BITMAP_FREE (bb_info->gen);
580 BITMAP_FREE (bb_info->in);
581 BITMAP_FREE (bb_info->out);
582 }
4d779342 583 }
3b8266e2 584
6fb5fa3c 585 free_alloc_pool (df_rd->block_pool);
3b8266e2
KZ
586 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
587 BITMAP_FREE (problem_data->dense_invalidated_by_call);
6fb5fa3c 588 bitmap_obstack_release (&problem_data->rd_bitmaps);
3b8266e2 589
6fb5fa3c
DB
590 df_rd->block_info_size = 0;
591 free (df_rd->block_info);
592 free (df_rd->problem_data);
4d779342 593 }
6fb5fa3c 594 free (df_rd);
4d779342
DB
595}
596
597
598/* Debugging info. */
599
600static void
6fb5fa3c 601df_rd_start_dump (FILE *file)
4d779342 602{
23249ac4 603 struct df_rd_problem_data *problem_data
6fb5fa3c
DB
604 = (struct df_rd_problem_data *) df_rd->problem_data;
605 unsigned int m = DF_REG_SIZE(df);
4d779342
DB
606 unsigned int regno;
607
6fb5fa3c 608 if (!df_rd->block_info)
23249ac4
DB
609 return;
610
6fb5fa3c 611 fprintf (file, ";; Reaching defs:\n\n");
4d779342
DB
612
613 fprintf (file, " sparse invalidated \t");
614 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
615 fprintf (file, " dense invalidated \t");
616 dump_bitmap (file, problem_data->dense_invalidated_by_call);
617
618 for (regno = 0; regno < m; regno++)
6fb5fa3c 619 if (DF_DEFS_COUNT (regno))
4d779342 620 fprintf (file, "%d[%d,%d] ", regno,
6fb5fa3c
DB
621 DF_DEFS_BEGIN (regno),
622 DF_DEFS_COUNT (regno));
4d779342
DB
623 fprintf (file, "\n");
624
6fb5fa3c
DB
625}
626
627
628/* Debugging info at top of bb. */
629
630static void
631df_rd_top_dump (basic_block bb, FILE *file)
632{
633 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
634 if (!bb_info || !bb_info->in)
635 return;
636
637 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
638 dump_bitmap (file, bb_info->in);
639 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
640 dump_bitmap (file, bb_info->gen);
641 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
642 dump_bitmap (file, bb_info->kill);
643}
644
645
646/* Debugging info at top of bb. */
647
648static void
649df_rd_bottom_dump (basic_block bb, FILE *file)
650{
651 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
652 if (!bb_info || !bb_info->out)
653 return;
654
655 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
656 dump_bitmap (file, bb_info->out);
4d779342
DB
657}
658
659/* All of the information associated with every instance of the problem. */
660
661static struct df_problem problem_RD =
662{
663 DF_RD, /* Problem id. */
664 DF_FORWARD, /* Direction. */
665 df_rd_alloc, /* Allocate the problem specific data. */
30cb87a0 666 NULL, /* Reset global information. */
4d779342
DB
667 df_rd_free_bb_info, /* Free basic block info. */
668 df_rd_local_compute, /* Local compute function. */
669 df_rd_init_solution, /* Init the solution specific data. */
6fb5fa3c 670 df_worklist_dataflow, /* Worklist solver. */
4d779342
DB
671 NULL, /* Confluence operator 0. */
672 df_rd_confluence_n, /* Confluence operator n. */
673 df_rd_transfer_function, /* Transfer function. */
674 NULL, /* Finalize function. */
675 df_rd_free, /* Free all of the problem information. */
6fb5fa3c
DB
676 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
677 df_rd_start_dump, /* Debugging. */
678 df_rd_top_dump, /* Debugging start block. */
679 df_rd_bottom_dump, /* Debugging end block. */
680 NULL, /* Incremental solution verify start. */
6ed3da00 681 NULL, /* Incremental solution verify end. */
23249ac4 682 NULL, /* Dependent problem. */
89a95777
KZ
683 TV_DF_RD, /* Timing variable. */
684 true /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
685};
686
687
688
689/* Create a new DATAFLOW instance and add it to an existing instance
690 of DF. The returned structure is what is used to get at the
691 solution. */
692
6fb5fa3c
DB
693void
694df_rd_add_problem (void)
4d779342 695{
6fb5fa3c 696 df_add_problem (&problem_RD);
4d779342
DB
697}
698
699
700\f
701/*----------------------------------------------------------------------------
702 LIVE REGISTERS
703
b11550aa
KZ
704 Find the locations in the function where any use of a pseudo can
705 reach in the backwards direction. In and out bitvectors are built
706 for each basic block. The regnum is used to index into these sets.
707 See df.h for details.
708 ----------------------------------------------------------------------------*/
4d779342 709
6fb5fa3c
DB
710/* Private data used to verify the solution for this problem. */
711struct df_lr_problem_data
4d779342 712{
6fb5fa3c
DB
713 bitmap *in;
714 bitmap *out;
715};
4d779342
DB
716
717
718/* Set basic block info. */
719
720static void
6fb5fa3c 721df_lr_set_bb_info (unsigned int index,
4d779342
DB
722 struct df_lr_bb_info *bb_info)
723{
6fb5fa3c
DB
724 gcc_assert (df_lr);
725 gcc_assert (index < df_lr->block_info_size);
726 df_lr->block_info[index] = bb_info;
4d779342
DB
727}
728
729
730/* Free basic block info. */
731
732static void
6fb5fa3c 733df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 734 void *vbb_info)
4d779342
DB
735{
736 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
737 if (bb_info)
738 {
739 BITMAP_FREE (bb_info->use);
740 BITMAP_FREE (bb_info->def);
741 BITMAP_FREE (bb_info->in);
742 BITMAP_FREE (bb_info->out);
6fb5fa3c 743 pool_free (df_lr->block_pool, bb_info);
4d779342
DB
744 }
745}
746
747
6fb5fa3c 748/* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
4d779342
DB
749 not touched unless the block is new. */
750
751static void
6fb5fa3c 752df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342
DB
753{
754 unsigned int bb_index;
755 bitmap_iterator bi;
756
6fb5fa3c
DB
757 if (!df_lr->block_pool)
758 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
4d779342
DB
759 sizeof (struct df_lr_bb_info), 50);
760
6fb5fa3c 761 df_grow_bb_info (df_lr);
4d779342 762
6fb5fa3c 763 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
4d779342 764 {
6fb5fa3c 765 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342
DB
766 if (bb_info)
767 {
768 bitmap_clear (bb_info->def);
769 bitmap_clear (bb_info->use);
770 }
771 else
772 {
6fb5fa3c
DB
773 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
774 df_lr_set_bb_info (bb_index, bb_info);
4d779342
DB
775 bb_info->use = BITMAP_ALLOC (NULL);
776 bb_info->def = BITMAP_ALLOC (NULL);
777 bb_info->in = BITMAP_ALLOC (NULL);
778 bb_info->out = BITMAP_ALLOC (NULL);
779 }
780 }
89a95777
KZ
781
782 df_lr->optional_p = false;
4d779342
DB
783}
784
785
6fb5fa3c
DB
786/* Reset the global solution for recalculation. */
787
788static void
789df_lr_reset (bitmap all_blocks)
790{
791 unsigned int bb_index;
792 bitmap_iterator bi;
793
794 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
795 {
796 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
797 gcc_assert (bb_info);
798 bitmap_clear (bb_info->in);
799 bitmap_clear (bb_info->out);
6fb5fa3c
DB
800 }
801}
802
803
4d779342
DB
804/* Compute local live register info for basic block BB. */
805
806static void
6fb5fa3c 807df_lr_bb_local_compute (unsigned int bb_index)
4d779342
DB
808{
809 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 810 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342 811 rtx insn;
6fb5fa3c
DB
812 struct df_ref **def_rec;
813 struct df_ref **use_rec;
4d779342 814
912f2dac 815 /* Process the registers set in an exception handler. */
6fb5fa3c
DB
816 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
817 {
818 struct df_ref *def = *def_rec;
819 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
820 {
821 unsigned int dregno = DF_REF_REGNO (def);
822 bitmap_set_bit (bb_info->def, dregno);
823 bitmap_clear_bit (bb_info->use, dregno);
824 }
825 }
912f2dac 826
4d779342 827 /* Process the hardware registers that are always live. */
6fb5fa3c
DB
828 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
829 {
830 struct df_ref *use = *use_rec;
831 /* Add use to set of uses in this BB. */
832 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
833 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
834 }
4d779342
DB
835
836 FOR_BB_INSNS_REVERSE (bb, insn)
837 {
838 unsigned int uid = INSN_UID (insn);
839
23249ac4 840 if (!INSN_P (insn))
4d779342
DB
841 continue;
842
5d545bf1 843 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 844 {
5d545bf1
SP
845 struct df_ref *def = *def_rec;
846 /* If the def is to only part of the reg, it does
847 not kill the other defs that reach here. */
848 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4d779342
DB
849 {
850 unsigned int dregno = DF_REF_REGNO (def);
5d545bf1
SP
851 bitmap_set_bit (bb_info->def, dregno);
852 bitmap_clear_bit (bb_info->use, dregno);
4d779342
DB
853 }
854 }
855
6fb5fa3c
DB
856 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
857 {
858 struct df_ref *use = *use_rec;
859 /* Add use to set of uses in this BB. */
860 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
861 }
4d779342 862 }
ba49cb7b
KZ
863
864 /* Process the registers set in an exception handler or the hard
865 frame pointer if this block is the target of a non local
866 goto. */
6fb5fa3c
DB
867 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
868 {
869 struct df_ref *def = *def_rec;
ba49cb7b 870 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
6fb5fa3c
DB
871 {
872 unsigned int dregno = DF_REF_REGNO (def);
ba49cb7b
KZ
873 bitmap_set_bit (bb_info->def, dregno);
874 bitmap_clear_bit (bb_info->use, dregno);
6fb5fa3c
DB
875 }
876 }
912f2dac 877
4d779342
DB
878#ifdef EH_USES
879 /* Process the uses that are live into an exception handler. */
6fb5fa3c
DB
880 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
881 {
882 struct df_ref *use = *use_rec;
883 /* Add use to set of uses in this BB. */
884 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
ba49cb7b 885 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
6fb5fa3c 886 }
4d779342 887#endif
89a95777
KZ
888
889 /* If the df_live problem is not defined, such as at -O0 and -O1, we
890 still need to keep the luids up to date. This is normally done
891 in the df_live problem since this problem has a forwards
892 scan. */
893 if (!df_live)
894 df_recompute_luids (bb);
4d779342
DB
895}
896
23249ac4 897
4d779342
DB
898/* Compute local live register info for each basic block within BLOCKS. */
899
900static void
6fb5fa3c 901df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342 902{
4d779342
DB
903 unsigned int bb_index;
904 bitmap_iterator bi;
905
4d779342
DB
906 bitmap_clear (df->hardware_regs_used);
907
908 /* The all-important stack pointer must always be live. */
909 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
910
911 /* Before reload, there are a few registers that must be forced
912 live everywhere -- which might not already be the case for
913 blocks within infinite loops. */
23249ac4 914 if (!reload_completed)
4d779342
DB
915 {
916 /* Any reference to any pseudo before reload is a potential
917 reference of the frame pointer. */
918 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
919
920#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
921 /* Pseudos with argument area equivalences may require
922 reloading via the argument pointer. */
923 if (fixed_regs[ARG_POINTER_REGNUM])
924 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
925#endif
926
927 /* Any constant, or pseudo with constant equivalences, may
928 require reloading from memory using the pic register. */
929 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
930 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
931 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
932 }
933
6fb5fa3c 934 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
4d779342
DB
935 {
936 if (bb_index == EXIT_BLOCK)
6fb5fa3c
DB
937 {
938 /* The exit block is special for this problem and its bits are
939 computed from thin air. */
940 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
941 bitmap_copy (bb_info->use, df->exit_block_uses);
942 }
943 else
944 df_lr_bb_local_compute (bb_index);
4d779342 945 }
6fb5fa3c
DB
946
947 bitmap_clear (df_lr->out_of_date_transfer_functions);
4d779342
DB
948}
949
950
951/* Initialize the solution vectors. */
952
953static void
6fb5fa3c 954df_lr_init (bitmap all_blocks)
4d779342
DB
955{
956 unsigned int bb_index;
957 bitmap_iterator bi;
958
959 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
960 {
6fb5fa3c 961 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342
DB
962 bitmap_copy (bb_info->in, bb_info->use);
963 bitmap_clear (bb_info->out);
964 }
965}
966
967
968/* Confluence function that processes infinite loops. This might be a
969 noreturn function that throws. And even if it isn't, getting the
970 unwind info right helps debugging. */
971static void
6fb5fa3c 972df_lr_confluence_0 (basic_block bb)
4d779342 973{
6fb5fa3c 974 bitmap op1 = df_lr_get_bb_info (bb->index)->out;
4d779342
DB
975 if (bb != EXIT_BLOCK_PTR)
976 bitmap_copy (op1, df->hardware_regs_used);
977}
978
979
980/* Confluence function that ignores fake edges. */
23249ac4 981
4d779342 982static void
6fb5fa3c 983df_lr_confluence_n (edge e)
4d779342 984{
6fb5fa3c
DB
985 bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
986 bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
4d779342
DB
987
988 /* Call-clobbered registers die across exception and call edges. */
989 /* ??? Abnormal call edges ignored for the moment, as this gets
990 confused by sibling call edges, which crashes reg-stack. */
991 if (e->flags & EDGE_EH)
992 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
993 else
994 bitmap_ior_into (op1, op2);
995
6fb5fa3c 996 bitmap_ior_into (op1, df->hardware_regs_used);
4d779342
DB
997}
998
999
1000/* Transfer function. */
23249ac4 1001
4d779342 1002static bool
6fb5fa3c 1003df_lr_transfer_function (int bb_index)
4d779342 1004{
6fb5fa3c 1005 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342
DB
1006 bitmap in = bb_info->in;
1007 bitmap out = bb_info->out;
1008 bitmap use = bb_info->use;
1009 bitmap def = bb_info->def;
6fb5fa3c 1010
ba49cb7b 1011 return bitmap_ior_and_compl (in, use, out, def);
6fb5fa3c
DB
1012}
1013
4d779342 1014
6fb5fa3c
DB
1015/* Run the fast dce as a side effect of building LR. */
1016
1017static void
1018df_lr_local_finalize (bitmap all_blocks ATTRIBUTE_UNUSED)
1019{
1020 if (df->changeable_flags & DF_LR_RUN_DCE)
1021 {
1022 run_fast_df_dce ();
1023 if (df_lr->problem_data && df_lr->solutions_dirty)
1024 {
1025 /* If we are here, then it is because we are both verifying
1026 the solution and the dce changed the function. In that case
1027 the verification info built will be wrong. So we leave the
1028 dirty flag true so that the verifier will skip the checking
1029 part and just clean up.*/
1030 df_lr->solutions_dirty = true;
1031 }
1032 else
1033 df_lr->solutions_dirty = false;
1034 }
1035 else
1036 df_lr->solutions_dirty = false;
4d779342
DB
1037}
1038
1039
1040/* Free all storage associated with the problem. */
1041
1042static void
6fb5fa3c 1043df_lr_free (void)
4d779342 1044{
6fb5fa3c 1045 if (df_lr->block_info)
4d779342 1046 {
3b8266e2 1047 unsigned int i;
6fb5fa3c 1048 for (i = 0; i < df_lr->block_info_size; i++)
4d779342 1049 {
6fb5fa3c 1050 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
3b8266e2
KZ
1051 if (bb_info)
1052 {
1053 BITMAP_FREE (bb_info->use);
1054 BITMAP_FREE (bb_info->def);
1055 BITMAP_FREE (bb_info->in);
1056 BITMAP_FREE (bb_info->out);
1057 }
4d779342 1058 }
6fb5fa3c 1059 free_alloc_pool (df_lr->block_pool);
3b8266e2 1060
6fb5fa3c
DB
1061 df_lr->block_info_size = 0;
1062 free (df_lr->block_info);
4d779342 1063 }
23249ac4 1064
6fb5fa3c
DB
1065 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1066 free (df_lr);
4d779342
DB
1067}
1068
1069
6fb5fa3c 1070/* Debugging info at top of bb. */
4d779342
DB
1071
1072static void
6fb5fa3c 1073df_lr_top_dump (basic_block bb, FILE *file)
4d779342 1074{
6fb5fa3c
DB
1075 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1076 struct df_lr_problem_data *problem_data;
1077 if (!bb_info || !bb_info->in)
1078 return;
1079
1080 fprintf (file, ";; lr in \t");
1081 df_print_regset (file, bb_info->in);
1082 if (df_lr->problem_data)
1083 {
1084 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1085 fprintf (file, ";; old in \t");
1086 df_print_regset (file, problem_data->in[bb->index]);
1087 }
1088 fprintf (file, ";; lr use \t");
1089 df_print_regset (file, bb_info->use);
1090 fprintf (file, ";; lr def \t");
1091 df_print_regset (file, bb_info->def);
1092}
1093
1094
1095/* Debugging info at bottom of bb. */
1096
1097static void
1098df_lr_bottom_dump (basic_block bb, FILE *file)
1099{
1100 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1101 struct df_lr_problem_data *problem_data;
1102 if (!bb_info || !bb_info->out)
1103 return;
4d779342 1104
6fb5fa3c
DB
1105 fprintf (file, ";; lr out \t");
1106 df_print_regset (file, bb_info->out);
1107 if (df_lr->problem_data)
1108 {
1109 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1110 fprintf (file, ";; old out \t");
1111 df_print_regset (file, problem_data->out[bb->index]);
1112 }
1113}
1114
1115
1116/* Build the datastructure to verify that the solution to the dataflow
1117 equations is not dirty. */
1118
1119static void
1120df_lr_verify_solution_start (void)
1121{
1122 basic_block bb;
1123 struct df_lr_problem_data *problem_data;
1124 if (df_lr->solutions_dirty)
1125 {
1126 df_lr->problem_data = NULL;
1127 return;
1128 }
1129
1130 /* Set it true so that the solution is recomputed. */
1131 df_lr->solutions_dirty = true;
1132
1133 problem_data = XNEW (struct df_lr_problem_data);
1134 df_lr->problem_data = problem_data;
1135 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1136 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1137
1138 FOR_ALL_BB (bb)
1139 {
1140 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1141 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1142 bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
1143 bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
1144 }
1145}
1146
1147
1148/* Compare the saved datastructure and the new solution to the dataflow
1149 equations. */
1150
1151static void
1152df_lr_verify_solution_end (void)
1153{
1154 struct df_lr_problem_data *problem_data;
1155 basic_block bb;
1156
1157 if (df_lr->problem_data == NULL)
23249ac4
DB
1158 return;
1159
6fb5fa3c
DB
1160 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1161
1162 if (df_lr->solutions_dirty)
1163 /* Do not check if the solution is still dirty. See the comment
1164 in df_lr_local_finalize for details. */
1165 df_lr->solutions_dirty = false;
1166 else
1167 FOR_ALL_BB (bb)
1168 {
1169 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
1170 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
1171 {
1172 /*df_dump (stderr);*/
1173 gcc_unreachable ();
1174 }
1175 }
1176
1177 /* Cannot delete them immediately because you may want to dump them
1178 if the comparison fails. */
4d779342
DB
1179 FOR_ALL_BB (bb)
1180 {
6fb5fa3c
DB
1181 BITMAP_FREE (problem_data->in[bb->index]);
1182 BITMAP_FREE (problem_data->out[bb->index]);
4d779342 1183 }
6fb5fa3c
DB
1184
1185 free (problem_data->in);
1186 free (problem_data->out);
1187 free (problem_data);
1188 df_lr->problem_data = NULL;
4d779342
DB
1189}
1190
6fb5fa3c 1191
4d779342
DB
1192/* All of the information associated with every instance of the problem. */
1193
1194static struct df_problem problem_LR =
1195{
1196 DF_LR, /* Problem id. */
1197 DF_BACKWARD, /* Direction. */
1198 df_lr_alloc, /* Allocate the problem specific data. */
6fb5fa3c 1199 df_lr_reset, /* Reset global information. */
4d779342
DB
1200 df_lr_free_bb_info, /* Free basic block info. */
1201 df_lr_local_compute, /* Local compute function. */
1202 df_lr_init, /* Init the solution specific data. */
6fb5fa3c 1203 df_worklist_dataflow, /* Worklist solver. */
4d779342
DB
1204 df_lr_confluence_0, /* Confluence operator 0. */
1205 df_lr_confluence_n, /* Confluence operator n. */
1206 df_lr_transfer_function, /* Transfer function. */
6fb5fa3c 1207 df_lr_local_finalize, /* Finalize function. */
4d779342 1208 df_lr_free, /* Free all of the problem information. */
6fb5fa3c
DB
1209 NULL, /* Remove this problem from the stack of dataflow problems. */
1210 NULL, /* Debugging. */
1211 df_lr_top_dump, /* Debugging start block. */
1212 df_lr_bottom_dump, /* Debugging end block. */
1213 df_lr_verify_solution_start,/* Incremental solution verify start. */
1214 df_lr_verify_solution_end, /* Incremental solution verify end. */
23249ac4 1215 NULL, /* Dependent problem. */
89a95777
KZ
1216 TV_DF_LR, /* Timing variable. */
1217 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
1218};
1219
1220
1221/* Create a new DATAFLOW instance and add it to an existing instance
1222 of DF. The returned structure is what is used to get at the
1223 solution. */
1224
6fb5fa3c
DB
1225void
1226df_lr_add_problem (void)
1227{
1228 df_add_problem (&problem_LR);
1229 /* These will be initialized when df_scan_blocks processes each
1230 block. */
1231 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1232}
1233
1234
1235/* Verify that all of the lr related info is consistent and
1236 correct. */
1237
1238void
1239df_lr_verify_transfer_functions (void)
4d779342 1240{
6fb5fa3c
DB
1241 basic_block bb;
1242 bitmap saved_def;
1243 bitmap saved_use;
1244 bitmap saved_adef;
1245 bitmap saved_ause;
1246 bitmap all_blocks;
6fb5fa3c
DB
1247
1248 if (!df)
1249 return;
1250
1251 saved_def = BITMAP_ALLOC (NULL);
1252 saved_use = BITMAP_ALLOC (NULL);
1253 saved_adef = BITMAP_ALLOC (NULL);
1254 saved_ause = BITMAP_ALLOC (NULL);
1255 all_blocks = BITMAP_ALLOC (NULL);
1256
1257 FOR_ALL_BB (bb)
1258 {
1259 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1260 bitmap_set_bit (all_blocks, bb->index);
1261
1262 if (bb_info)
1263 {
1264 /* Make a copy of the transfer functions and then compute
1265 new ones to see if the transfer functions have
1266 changed. */
1267 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1268 bb->index))
1269 {
1270 bitmap_copy (saved_def, bb_info->def);
1271 bitmap_copy (saved_use, bb_info->use);
1272 bitmap_clear (bb_info->def);
1273 bitmap_clear (bb_info->use);
1274
6fb5fa3c
DB
1275 df_lr_bb_local_compute (bb->index);
1276 gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
1277 gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
6fb5fa3c
DB
1278 }
1279 }
1280 else
1281 {
1282 /* If we do not have basic block info, the block must be in
1283 the list of dirty blocks or else some one has added a
1284 block behind our backs. */
1285 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1286 bb->index));
1287 }
1288 /* Make sure no one created a block without following
1289 procedures. */
1290 gcc_assert (df_scan_get_bb_info (bb->index));
1291 }
1292
1293 /* Make sure there are no dirty bits in blocks that have been deleted. */
1294 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1295 all_blocks));
1296
1297 BITMAP_FREE (saved_def);
1298 BITMAP_FREE (saved_use);
1299 BITMAP_FREE (saved_adef);
1300 BITMAP_FREE (saved_ause);
1301 BITMAP_FREE (all_blocks);
4d779342
DB
1302}
1303
1304
1305\f
1306/*----------------------------------------------------------------------------
6fb5fa3c 1307 COMBINED LIVE REGISTERS AND UNINITIALIZED REGISTERS.
4d779342 1308
6fb5fa3c
DB
1309 First find the set of uses for registers that are reachable from
1310 the entry block without passing thru a definition. In and out
1311 bitvectors are built for each basic block. The regnum is used to
1312 index into these sets. See df.h for details.
4d779342 1313
6fb5fa3c
DB
1314 Then the in and out sets here are the anded results of the in and
1315 out sets from the lr and ur
1316 problems.
1317----------------------------------------------------------------------------*/
4d779342 1318
6fb5fa3c
DB
1319/* Private data used to verify the solution for this problem. */
1320struct df_live_problem_data
4d779342 1321{
6fb5fa3c
DB
1322 bitmap *in;
1323 bitmap *out;
1324};
4d779342
DB
1325
1326
1327/* Set basic block info. */
1328
1329static void
6fb5fa3c
DB
1330df_live_set_bb_info (unsigned int index,
1331 struct df_live_bb_info *bb_info)
4d779342 1332{
6fb5fa3c
DB
1333 gcc_assert (df_live);
1334 gcc_assert (index < df_live->block_info_size);
1335 df_live->block_info[index] = bb_info;
4d779342
DB
1336}
1337
1338
1339/* Free basic block info. */
1340
1341static void
6fb5fa3c 1342df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 1343 void *vbb_info)
4d779342 1344{
6fb5fa3c 1345 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
4d779342
DB
1346 if (bb_info)
1347 {
1348 BITMAP_FREE (bb_info->gen);
1349 BITMAP_FREE (bb_info->kill);
1350 BITMAP_FREE (bb_info->in);
1351 BITMAP_FREE (bb_info->out);
6fb5fa3c 1352 pool_free (df_live->block_pool, bb_info);
4d779342
DB
1353 }
1354}
1355
1356
6fb5fa3c 1357/* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
4d779342
DB
1358 not touched unless the block is new. */
1359
1360static void
6fb5fa3c 1361df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342
DB
1362{
1363 unsigned int bb_index;
1364 bitmap_iterator bi;
1365
6fb5fa3c
DB
1366 if (!df_live->block_pool)
1367 df_live->block_pool = create_alloc_pool ("df_live_block pool",
1368 sizeof (struct df_live_bb_info), 100);
4d779342 1369
6fb5fa3c 1370 df_grow_bb_info (df_live);
4d779342 1371
6fb5fa3c 1372 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
4d779342 1373 {
6fb5fa3c 1374 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342
DB
1375 if (bb_info)
1376 {
1377 bitmap_clear (bb_info->kill);
1378 bitmap_clear (bb_info->gen);
1379 }
1380 else
1381 {
6fb5fa3c
DB
1382 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
1383 df_live_set_bb_info (bb_index, bb_info);
4d779342
DB
1384 bb_info->kill = BITMAP_ALLOC (NULL);
1385 bb_info->gen = BITMAP_ALLOC (NULL);
1386 bb_info->in = BITMAP_ALLOC (NULL);
1387 bb_info->out = BITMAP_ALLOC (NULL);
1388 }
1389 }
89a95777 1390 df_live->optional_p = (optimize <= 1);
4d779342
DB
1391}
1392
1393
6fb5fa3c
DB
1394/* Reset the global solution for recalculation. */
1395
1396static void
1397df_live_reset (bitmap all_blocks)
1398{
1399 unsigned int bb_index;
1400 bitmap_iterator bi;
1401
1402 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1403 {
1404 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1405 gcc_assert (bb_info);
1406 bitmap_clear (bb_info->in);
1407 bitmap_clear (bb_info->out);
1408 }
1409}
1410
1411
4d779342
DB
1412/* Compute local uninitialized register info for basic block BB. */
1413
1414static void
6fb5fa3c 1415df_live_bb_local_compute (unsigned int bb_index)
4d779342 1416{
4d779342 1417 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 1418 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342 1419 rtx insn;
6fb5fa3c
DB
1420 struct df_ref **def_rec;
1421 int luid = 0;
4d779342 1422
6fb5fa3c
DB
1423 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1424 {
1425 struct df_ref *def = *def_rec;
1426 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
1427 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1428 }
912f2dac 1429
6fb5fa3c 1430 FOR_BB_INSNS (bb, insn)
4d779342
DB
1431 {
1432 unsigned int uid = INSN_UID (insn);
6fb5fa3c
DB
1433 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
1434
1435 /* Inserting labels does not always trigger the incremental
1436 rescanning. */
1437 if (!insn_info)
1438 {
1439 gcc_assert (!INSN_P (insn));
1440 df_insn_create_insn_record (insn);
1441 }
1442
1443 DF_INSN_LUID (insn) = luid;
4d779342
DB
1444 if (!INSN_P (insn))
1445 continue;
1446
6fb5fa3c
DB
1447 luid++;
1448 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 1449 {
6fb5fa3c 1450 struct df_ref *def = *def_rec;
4d779342 1451 unsigned int regno = DF_REF_REGNO (def);
6fb5fa3c
DB
1452
1453 if (DF_REF_FLAGS_IS_SET (def,
1454 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
1455 /* All partial or conditional def
1456 seen are included in the gen set. */
1457 bitmap_set_bit (bb_info->gen, regno);
1458 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
1459 /* Only must clobbers for the entire reg destroy the
1460 value. */
1461 bitmap_set_bit (bb_info->kill, regno);
1462 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1463 bitmap_set_bit (bb_info->gen, regno);
4d779342 1464 }
4d779342
DB
1465 }
1466
6fb5fa3c
DB
1467 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1468 {
1469 struct df_ref *def = *def_rec;
1470 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
1471 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
1472 }
4d779342
DB
1473}
1474
1475
1476/* Compute local uninitialized register info. */
1477
1478static void
6fb5fa3c 1479df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342
DB
1480{
1481 unsigned int bb_index;
1482 bitmap_iterator bi;
1483
6fb5fa3c 1484 df_grow_insn_info ();
4d779342 1485
6fb5fa3c
DB
1486 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
1487 0, bb_index, bi)
4d779342 1488 {
6fb5fa3c 1489 df_live_bb_local_compute (bb_index);
4d779342
DB
1490 }
1491
6fb5fa3c 1492 bitmap_clear (df_live->out_of_date_transfer_functions);
4d779342
DB
1493}
1494
1495
1496/* Initialize the solution vectors. */
1497
1498static void
6fb5fa3c 1499df_live_init (bitmap all_blocks)
4d779342
DB
1500{
1501 unsigned int bb_index;
1502 bitmap_iterator bi;
1503
1504 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1505 {
6fb5fa3c 1506 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342
DB
1507
1508 bitmap_copy (bb_info->out, bb_info->gen);
1509 bitmap_clear (bb_info->in);
1510 }
1511}
1512
4d779342
DB
1513/* Confluence function that ignores fake edges. */
1514
1515static void
6fb5fa3c 1516df_live_confluence_n (edge e)
4d779342 1517{
6fb5fa3c
DB
1518 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
1519 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
4d779342
DB
1520
1521 if (e->flags & EDGE_FAKE)
1522 return;
1523
1524 bitmap_ior_into (op1, op2);
1525}
1526
1527
1528/* Transfer function. */
1529
1530static bool
6fb5fa3c 1531df_live_transfer_function (int bb_index)
4d779342 1532{
6fb5fa3c 1533 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342
DB
1534 bitmap in = bb_info->in;
1535 bitmap out = bb_info->out;
1536 bitmap gen = bb_info->gen;
1537 bitmap kill = bb_info->kill;
1538
1539 return bitmap_ior_and_compl (out, gen, in, kill);
1540}
1541
1542
6fb5fa3c
DB
1543/* And the LR and UR info to produce the LIVE info. */
1544
1545static void
1546df_live_local_finalize (bitmap all_blocks)
1547{
1548
1549 if (df_live->solutions_dirty)
1550 {
1551 bitmap_iterator bi;
1552 unsigned int bb_index;
1553
1554 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1555 {
1556 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
1557 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
ba49cb7b 1558
6fb5fa3c
DB
1559 /* No register may reach a location where it is not used. Thus
1560 we trim the rr result to the places where it is used. */
1561 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
1562 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
1563 }
1564
1565 df_live->solutions_dirty = false;
1566 }
1567}
1568
1569
4d779342
DB
1570/* Free all storage associated with the problem. */
1571
1572static void
6fb5fa3c 1573df_live_free (void)
4d779342 1574{
6fb5fa3c 1575 if (df_live->block_info)
4d779342 1576 {
3b8266e2
KZ
1577 unsigned int i;
1578
6fb5fa3c 1579 for (i = 0; i < df_live->block_info_size; i++)
4d779342 1580 {
6fb5fa3c 1581 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
3b8266e2
KZ
1582 if (bb_info)
1583 {
1584 BITMAP_FREE (bb_info->gen);
1585 BITMAP_FREE (bb_info->kill);
1586 BITMAP_FREE (bb_info->in);
1587 BITMAP_FREE (bb_info->out);
1588 }
4d779342 1589 }
3b8266e2 1590
6fb5fa3c
DB
1591 free_alloc_pool (df_live->block_pool);
1592 df_live->block_info_size = 0;
1593 free (df_live->block_info);
4d779342 1594 }
6fb5fa3c
DB
1595 BITMAP_FREE (df_live->out_of_date_transfer_functions);
1596 free (df_live);
4d779342
DB
1597}
1598
1599
6fb5fa3c 1600/* Debugging info at top of bb. */
4d779342
DB
1601
1602static void
6fb5fa3c 1603df_live_top_dump (basic_block bb, FILE *file)
4d779342 1604{
6fb5fa3c
DB
1605 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1606 struct df_live_problem_data *problem_data;
23249ac4 1607
6fb5fa3c
DB
1608 if (!bb_info || !bb_info->in)
1609 return;
4d779342 1610
6fb5fa3c
DB
1611 fprintf (file, ";; live in \t");
1612 df_print_regset (file, bb_info->in);
1613 if (df_live->problem_data)
1614 {
1615 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1616 fprintf (file, ";; old in \t");
1617 df_print_regset (file, problem_data->in[bb->index]);
4d779342 1618 }
6fb5fa3c
DB
1619 fprintf (file, ";; live gen \t");
1620 df_print_regset (file, bb_info->gen);
1621 fprintf (file, ";; live kill\t");
1622 df_print_regset (file, bb_info->kill);
4d779342
DB
1623}
1624
4d779342 1625
6fb5fa3c
DB
1626/* Debugging info at bottom of bb. */
1627
1628static void
1629df_live_bottom_dump (basic_block bb, FILE *file)
4d779342 1630{
6fb5fa3c
DB
1631 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1632 struct df_live_problem_data *problem_data;
4d779342 1633
6fb5fa3c
DB
1634 if (!bb_info || !bb_info->out)
1635 return;
1636
1637 fprintf (file, ";; live out \t");
1638 df_print_regset (file, bb_info->out);
1639 if (df_live->problem_data)
1640 {
1641 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1642 fprintf (file, ";; old out \t");
1643 df_print_regset (file, problem_data->out[bb->index]);
1644 }
1645}
4d779342 1646
4d779342 1647
6fb5fa3c
DB
1648/* Build the datastructure to verify that the solution to the dataflow
1649 equations is not dirty. */
1650
1651static void
1652df_live_verify_solution_start (void)
4d779342 1653{
6fb5fa3c
DB
1654 basic_block bb;
1655 struct df_live_problem_data *problem_data;
1656 if (df_live->solutions_dirty)
1657 {
1658 df_live->problem_data = NULL;
1659 return;
1660 }
1661
1662 /* Set it true so that the solution is recomputed. */
1663 df_live->solutions_dirty = true;
1664
1665 problem_data = XNEW (struct df_live_problem_data);
1666 df_live->problem_data = problem_data;
1667 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1668 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1669
1670 FOR_ALL_BB (bb)
1671 {
1672 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1673 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1674 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
1675 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
1676 }
4d779342
DB
1677}
1678
1679
6fb5fa3c
DB
1680/* Compare the saved datastructure and the new solution to the dataflow
1681 equations. */
4d779342 1682
6fb5fa3c
DB
1683static void
1684df_live_verify_solution_end (void)
1685{
1686 struct df_live_problem_data *problem_data;
1687 basic_block bb;
1688
1689 if (df_live->problem_data == NULL)
1690 return;
1691
1692 problem_data = (struct df_live_problem_data *)df_live->problem_data;
1693
1694 FOR_ALL_BB (bb)
1695 {
1696 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
1697 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
1698 {
1699 /*df_dump (stderr);*/
1700 gcc_unreachable ();
1701 }
1702 }
1703
1704 /* Cannot delete them immediately because you may want to dump them
1705 if the comparison fails. */
1706 FOR_ALL_BB (bb)
1707 {
1708 BITMAP_FREE (problem_data->in[bb->index]);
1709 BITMAP_FREE (problem_data->out[bb->index]);
1710 }
1711
1712 free (problem_data->in);
1713 free (problem_data->out);
1714 free (problem_data);
1715 df_live->problem_data = NULL;
1716}
1717
1718
1719/* All of the information associated with every instance of the problem. */
1720
1721static struct df_problem problem_LIVE =
1722{
1723 DF_LIVE, /* Problem id. */
1724 DF_FORWARD, /* Direction. */
1725 df_live_alloc, /* Allocate the problem specific data. */
1726 df_live_reset, /* Reset global information. */
1727 df_live_free_bb_info, /* Free basic block info. */
1728 df_live_local_compute, /* Local compute function. */
1729 df_live_init, /* Init the solution specific data. */
1730 df_worklist_dataflow, /* Worklist solver. */
1731 NULL, /* Confluence operator 0. */
1732 df_live_confluence_n, /* Confluence operator n. */
1733 df_live_transfer_function, /* Transfer function. */
1734 df_live_local_finalize, /* Finalize function. */
1735 df_live_free, /* Free all of the problem information. */
1736 df_live_free, /* Remove this problem from the stack of dataflow problems. */
1737 NULL, /* Debugging. */
1738 df_live_top_dump, /* Debugging start block. */
1739 df_live_bottom_dump, /* Debugging end block. */
1740 df_live_verify_solution_start,/* Incremental solution verify start. */
1741 df_live_verify_solution_end, /* Incremental solution verify end. */
1742 &problem_LR, /* Dependent problem. */
89a95777
KZ
1743 TV_DF_LIVE, /* Timing variable. */
1744 false /* Reset blocks on dropping out of blocks_to_analyze. */
6fb5fa3c
DB
1745};
1746
1747
1748/* Create a new DATAFLOW instance and add it to an existing instance
1749 of DF. The returned structure is what is used to get at the
1750 solution. */
1751
1752void
1753df_live_add_problem (void)
1754{
1755 df_add_problem (&problem_LIVE);
1756 /* These will be initialized when df_scan_blocks processes each
1757 block. */
1758 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1759}
1760
1761
89a95777
KZ
1762/* Set all of the blocks as dirty. This needs to be done if this
1763 problem is added after all of the insns have been scanned. */
1764
1765void
1766df_live_set_all_dirty (void)
1767{
1768 basic_block bb;
1769 FOR_ALL_BB (bb)
1770 bitmap_set_bit (df_live->out_of_date_transfer_functions,
1771 bb->index);
1772}
1773
1774
6fb5fa3c
DB
1775/* Verify that all of the lr related info is consistent and
1776 correct. */
1777
1778void
1779df_live_verify_transfer_functions (void)
1780{
1781 basic_block bb;
1782 bitmap saved_gen;
1783 bitmap saved_kill;
1784 bitmap all_blocks;
1785
1786 if (!df)
1787 return;
1788
1789 saved_gen = BITMAP_ALLOC (NULL);
1790 saved_kill = BITMAP_ALLOC (NULL);
1791 all_blocks = BITMAP_ALLOC (NULL);
1792
1793 df_grow_insn_info ();
1794
1795 FOR_ALL_BB (bb)
1796 {
1797 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
1798 bitmap_set_bit (all_blocks, bb->index);
1799
1800 if (bb_info)
1801 {
1802 /* Make a copy of the transfer functions and then compute
1803 new ones to see if the transfer functions have
1804 changed. */
1805 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
1806 bb->index))
1807 {
1808 bitmap_copy (saved_gen, bb_info->gen);
1809 bitmap_copy (saved_kill, bb_info->kill);
1810 bitmap_clear (bb_info->gen);
1811 bitmap_clear (bb_info->kill);
1812
1813 df_live_bb_local_compute (bb->index);
1814 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
1815 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
1816 }
1817 }
1818 else
1819 {
1820 /* If we do not have basic block info, the block must be in
1821 the list of dirty blocks or else some one has added a
1822 block behind our backs. */
1823 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
1824 bb->index));
1825 }
1826 /* Make sure no one created a block without following
1827 procedures. */
1828 gcc_assert (df_scan_get_bb_info (bb->index));
1829 }
1830
1831 /* Make sure there are no dirty bits in blocks that have been deleted. */
1832 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
1833 all_blocks));
1834 BITMAP_FREE (saved_gen);
1835 BITMAP_FREE (saved_kill);
1836 BITMAP_FREE (all_blocks);
1837}
4d779342
DB
1838\f
1839/*----------------------------------------------------------------------------
1840 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
1841
1842 Link either the defs to the uses and / or the uses to the defs.
1843
1844 These problems are set up like the other dataflow problems so that
1845 they nicely fit into the framework. They are much simpler and only
1846 involve a single traversal of instructions and an examination of
1847 the reaching defs information (the dependent problem).
1848----------------------------------------------------------------------------*/
1849
6fb5fa3c 1850#define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
4d779342 1851
6fb5fa3c 1852/* Create a du or ud chain from SRC to DST and link it into SRC. */
23249ac4 1853
6fb5fa3c
DB
1854struct df_link *
1855df_chain_create (struct df_ref *src, struct df_ref *dst)
4d779342 1856{
6fb5fa3c
DB
1857 struct df_link *head = DF_REF_CHAIN (src);
1858 struct df_link *link = pool_alloc (df_chain->block_pool);;
1859
1860 DF_REF_CHAIN (src) = link;
1861 link->next = head;
1862 link->ref = dst;
1863 return link;
1864}
4d779342 1865
4d779342 1866
6fb5fa3c
DB
1867/* Delete any du or ud chains that start at REF and point to
1868 TARGET. */
1869static void
1870df_chain_unlink_1 (struct df_ref *ref, struct df_ref *target)
1871{
1872 struct df_link *chain = DF_REF_CHAIN (ref);
1873 struct df_link *prev = NULL;
4d779342 1874
6fb5fa3c 1875 while (chain)
4d779342 1876 {
6fb5fa3c 1877 if (chain->ref == target)
4d779342 1878 {
6fb5fa3c
DB
1879 if (prev)
1880 prev->next = chain->next;
1881 else
1882 DF_REF_CHAIN (ref) = chain->next;
1883 pool_free (df_chain->block_pool, chain);
1884 return;
4d779342 1885 }
6fb5fa3c
DB
1886 prev = chain;
1887 chain = chain->next;
4d779342 1888 }
6fb5fa3c
DB
1889}
1890
1891
1892/* Delete a du or ud chain that leave or point to REF. */
1893
1894void
1895df_chain_unlink (struct df_ref *ref)
1896{
1897 struct df_link *chain = DF_REF_CHAIN (ref);
1898 while (chain)
4d779342 1899 {
6fb5fa3c
DB
1900 struct df_link *next = chain->next;
1901 /* Delete the other side if it exists. */
1902 df_chain_unlink_1 (chain->ref, ref);
1903 pool_free (df_chain->block_pool, chain);
1904 chain = next;
4d779342 1905 }
6fb5fa3c 1906 DF_REF_CHAIN (ref) = NULL;
4d779342
DB
1907}
1908
1909
6fb5fa3c
DB
1910/* Copy the du or ud chain starting at FROM_REF and attach it to
1911 TO_REF. */
30cb87a0 1912
6fb5fa3c
DB
1913void
1914df_chain_copy (struct df_ref *to_ref,
1915 struct df_link *from_ref)
30cb87a0 1916{
6fb5fa3c
DB
1917 while (from_ref)
1918 {
1919 df_chain_create (to_ref, from_ref->ref);
1920 from_ref = from_ref->next;
1921 }
1922}
30cb87a0 1923
30cb87a0 1924
6fb5fa3c
DB
1925/* Remove this problem from the stack of dataflow problems. */
1926
1927static void
1928df_chain_remove_problem (void)
1929{
1930 bitmap_iterator bi;
1931 unsigned int bb_index;
1932
1933 /* Wholesale destruction of the old chains. */
1934 if (df_chain->block_pool)
1935 free_alloc_pool (df_chain->block_pool);
30cb87a0 1936
6fb5fa3c
DB
1937 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
1938 {
1939 rtx insn;
1940 struct df_ref **def_rec;
1941 struct df_ref **use_rec;
1942 basic_block bb = BASIC_BLOCK (bb_index);
1943
1944 if (df_chain_problem_p (DF_DU_CHAIN))
1945 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
1946 DF_REF_CHAIN (*def_rec) = NULL;
1947 if (df_chain_problem_p (DF_UD_CHAIN))
1948 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
1949 DF_REF_CHAIN (*use_rec) = NULL;
1950
1951 FOR_BB_INSNS (bb, insn)
30cb87a0 1952 {
6fb5fa3c
DB
1953 unsigned int uid = INSN_UID (insn);
1954
1955 if (INSN_P (insn))
30cb87a0 1956 {
6fb5fa3c
DB
1957 if (df_chain_problem_p (DF_DU_CHAIN))
1958 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
1959 DF_REF_CHAIN (*def_rec) = NULL;
1960 if (df_chain_problem_p (DF_UD_CHAIN))
1961 {
1962 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1963 DF_REF_CHAIN (*use_rec) = NULL;
1964 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
1965 DF_REF_CHAIN (*use_rec) = NULL;
1966 }
30cb87a0
KZ
1967 }
1968 }
1969 }
6fb5fa3c
DB
1970
1971 bitmap_clear (df_chain->out_of_date_transfer_functions);
1972 df_chain->block_pool = NULL;
30cb87a0
KZ
1973}
1974
1975
6fb5fa3c 1976/* Remove the chain problem completely. */
30cb87a0 1977
6fb5fa3c
DB
1978static void
1979df_chain_fully_remove_problem (void)
30cb87a0 1980{
6fb5fa3c
DB
1981 df_chain_remove_problem ();
1982 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
1983 free (df_chain);
1984}
30cb87a0 1985
30cb87a0 1986
6fb5fa3c 1987/* Create def-use or use-def chains. */
30cb87a0 1988
6fb5fa3c
DB
1989static void
1990df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
1991{
1992 df_chain_remove_problem ();
1993 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
1994 sizeof (struct df_link), 50);
89a95777 1995 df_chain->optional_p = true;
30cb87a0
KZ
1996}
1997
1998
1999/* Reset all of the chains when the set of basic blocks changes. */
2000
30cb87a0 2001static void
6fb5fa3c 2002df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
30cb87a0 2003{
6fb5fa3c 2004 df_chain_remove_problem ();
30cb87a0
KZ
2005}
2006
2007
4d779342
DB
2008/* Create the chains for a list of USEs. */
2009
2010static void
6fb5fa3c
DB
2011df_chain_create_bb_process_use (bitmap local_rd,
2012 struct df_ref **use_rec,
4d779342
DB
2013 enum df_ref_flags top_flag)
2014{
4d779342
DB
2015 bitmap_iterator bi;
2016 unsigned int def_index;
2017
6fb5fa3c 2018 while (*use_rec)
4d779342 2019 {
6fb5fa3c 2020 struct df_ref *use = *use_rec;
4d779342 2021 unsigned int uregno = DF_REF_REGNO (use);
6fb5fa3c
DB
2022 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2023 || (uregno >= FIRST_PSEUDO_REGISTER))
4d779342 2024 {
6fb5fa3c
DB
2025 /* Do not want to go through this for an uninitialized var. */
2026 int count = DF_DEFS_COUNT (uregno);
2027 if (count)
4d779342 2028 {
6fb5fa3c 2029 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
4d779342 2030 {
6fb5fa3c
DB
2031 unsigned int first_index = DF_DEFS_BEGIN (uregno);
2032 unsigned int last_index = first_index + count - 1;
4d779342 2033
6fb5fa3c
DB
2034 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2035 {
2036 struct df_ref *def;
2037 if (def_index > last_index)
2038 break;
2039
2040 def = DF_DEFS_GET (def_index);
2041 if (df_chain_problem_p (DF_DU_CHAIN))
2042 df_chain_create (def, use);
2043 if (df_chain_problem_p (DF_UD_CHAIN))
2044 df_chain_create (use, def);
2045 }
4d779342
DB
2046 }
2047 }
2048 }
6fb5fa3c
DB
2049
2050 use_rec++;
4d779342
DB
2051 }
2052}
2053
4d779342
DB
2054
2055/* Create chains from reaching defs bitmaps for basic block BB. */
6fb5fa3c 2056
4d779342 2057static void
6fb5fa3c 2058df_chain_create_bb (unsigned int bb_index)
4d779342
DB
2059{
2060 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 2061 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
2062 rtx insn;
2063 bitmap cpy = BITMAP_ALLOC (NULL);
6fb5fa3c 2064 struct df_ref **def_rec;
4d779342
DB
2065
2066 bitmap_copy (cpy, bb_info->in);
6fb5fa3c 2067 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
4d779342
DB
2068
2069 /* Since we are going forwards, process the artificial uses first
2070 then the artificial defs second. */
2071
2072#ifdef EH_USES
2073 /* Create the chains for the artificial uses from the EH_USES at the
2074 beginning of the block. */
6fb5fa3c
DB
2075
2076 /* Artificials are only hard regs. */
2077 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2078 df_chain_create_bb_process_use (cpy,
2079 df_get_artificial_uses (bb->index),
2080 DF_REF_AT_TOP);
4d779342
DB
2081#endif
2082
6fb5fa3c
DB
2083 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2084 {
2085 struct df_ref *def = *def_rec;
2086 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2087 {
2088 unsigned int dregno = DF_REF_REGNO (def);
2089 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2090 bitmap_clear_range (cpy,
2091 DF_DEFS_BEGIN (dregno),
2092 DF_DEFS_COUNT (dregno));
2093 bitmap_set_bit (cpy, DF_REF_ID (def));
2094 }
2095 }
4d779342
DB
2096
2097 /* Process the regular instructions next. */
2098 FOR_BB_INSNS (bb, insn)
2099 {
6fb5fa3c 2100 struct df_ref **def_rec;
4d779342
DB
2101 unsigned int uid = INSN_UID (insn);
2102
23249ac4 2103 if (!INSN_P (insn))
4d779342
DB
2104 continue;
2105
2106 /* Now scan the uses and link them up with the defs that remain
2107 in the cpy vector. */
2108
6fb5fa3c
DB
2109 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
2110
2111 if (df->changeable_flags & DF_EQ_NOTES)
2112 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
2113
4d779342
DB
2114
2115 /* Since we are going forwards, process the defs second. This
2116 pass only changes the bits in cpy. */
6fb5fa3c 2117 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 2118 {
6fb5fa3c 2119 struct df_ref *def = *def_rec;
4d779342 2120 unsigned int dregno = DF_REF_REGNO (def);
6fb5fa3c
DB
2121 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
2122 || (dregno >= FIRST_PSEUDO_REGISTER))
2123 {
2124 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2125 bitmap_clear_range (cpy,
2126 DF_DEFS_BEGIN (dregno),
2127 DF_DEFS_COUNT (dregno));
2128 if (!(DF_REF_FLAGS (def)
2129 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
2130 bitmap_set_bit (cpy, DF_REF_ID (def));
2131 }
4d779342
DB
2132 }
2133 }
2134
2135 /* Create the chains for the artificial uses of the hard registers
2136 at the end of the block. */
6fb5fa3c
DB
2137 if (!(df->changeable_flags & DF_NO_HARD_REGS))
2138 df_chain_create_bb_process_use (cpy,
2139 df_get_artificial_uses (bb->index),
2140 0);
2141
2142 BITMAP_FREE (cpy);
4d779342
DB
2143}
2144
2145/* Create def-use chains from reaching use bitmaps for basic blocks
2146 in BLOCKS. */
2147
2148static void
6fb5fa3c 2149df_chain_finalize (bitmap all_blocks)
4d779342
DB
2150{
2151 unsigned int bb_index;
2152 bitmap_iterator bi;
4d779342
DB
2153
2154 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2155 {
6fb5fa3c 2156 df_chain_create_bb (bb_index);
4d779342
DB
2157 }
2158}
2159
2160
2161/* Free all storage associated with the problem. */
2162
2163static void
6fb5fa3c 2164df_chain_free (void)
4d779342 2165{
6fb5fa3c
DB
2166 free_alloc_pool (df_chain->block_pool);
2167 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
2168 free (df_chain);
4d779342
DB
2169}
2170
2171
2172/* Debugging info. */
2173
2174static void
6fb5fa3c 2175df_chain_top_dump (basic_block bb, FILE *file)
4d779342 2176{
6fb5fa3c 2177 if (df_chain_problem_p (DF_DU_CHAIN))
4d779342 2178 {
6fb5fa3c
DB
2179 rtx insn;
2180 struct df_ref **def_rec = df_get_artificial_defs (bb->index);
2181 if (*def_rec)
4d779342 2182 {
6fb5fa3c
DB
2183
2184 fprintf (file, ";; DU chains for artificial defs\n");
2185 while (*def_rec)
4d779342 2186 {
6fb5fa3c
DB
2187 struct df_ref *def = *def_rec;
2188 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
23249ac4 2189 df_chain_dump (DF_REF_CHAIN (def), file);
4d779342 2190 fprintf (file, "\n");
6fb5fa3c
DB
2191 def_rec++;
2192 }
2193 }
2194
2195 FOR_BB_INSNS (bb, insn)
2196 {
2197 unsigned int uid = INSN_UID (insn);
2198 if (INSN_P (insn))
2199 {
2200 def_rec = DF_INSN_UID_DEFS (uid);
2201 if (*def_rec)
2202 {
2203 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
2204 DF_INSN_LUID (insn), uid);
2205
2206 while (*def_rec)
2207 {
2208 struct df_ref *def = *def_rec;
2209 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
2210 if (def->flags & DF_REF_READ_WRITE)
2211 fprintf (file, "read/write ");
2212 df_chain_dump (DF_REF_CHAIN (def), file);
2213 fprintf (file, "\n");
2214 def_rec++;
2215 }
2216 }
4d779342
DB
2217 }
2218 }
2219 }
6fb5fa3c
DB
2220}
2221
4d779342 2222
6fb5fa3c
DB
2223static void
2224df_chain_bottom_dump (basic_block bb, FILE *file)
2225{
2226 if (df_chain_problem_p (DF_UD_CHAIN))
4d779342 2227 {
6fb5fa3c
DB
2228 rtx insn;
2229 struct df_ref **use_rec = df_get_artificial_uses (bb->index);
2230
2231 if (*use_rec)
4d779342 2232 {
6fb5fa3c
DB
2233 fprintf (file, ";; UD chains for artificial uses\n");
2234 while (*use_rec)
4d779342 2235 {
6fb5fa3c
DB
2236 struct df_ref *use = *use_rec;
2237 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
23249ac4 2238 df_chain_dump (DF_REF_CHAIN (use), file);
4d779342 2239 fprintf (file, "\n");
6fb5fa3c
DB
2240 use_rec++;
2241 }
2242 }
2243
2244 FOR_BB_INSNS (bb, insn)
2245 {
2246 unsigned int uid = INSN_UID (insn);
2247 if (INSN_P (insn))
2248 {
2249 struct df_ref **eq_use_rec = DF_INSN_UID_EQ_USES (uid);
2250 use_rec = DF_INSN_UID_USES (uid);
2251 if (*use_rec || *eq_use_rec)
2252 {
2253 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
2254 DF_INSN_LUID (insn), uid);
2255
2256 while (*use_rec)
2257 {
2258 struct df_ref *use = *use_rec;
2259 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
2260 if (use->flags & DF_REF_READ_WRITE)
2261 fprintf (file, "read/write ");
2262 df_chain_dump (DF_REF_CHAIN (use), file);
2263 fprintf (file, "\n");
2264 use_rec++;
2265 }
2266 while (*eq_use_rec)
2267 {
2268 struct df_ref *use = *eq_use_rec;
2269 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
2270 df_chain_dump (DF_REF_CHAIN (use), file);
2271 fprintf (file, "\n");
2272 eq_use_rec++;
2273 }
2274 }
4d779342
DB
2275 }
2276 }
2277 }
2278}
2279
2280
2281static struct df_problem problem_CHAIN =
2282{
2283 DF_CHAIN, /* Problem id. */
2284 DF_NONE, /* Direction. */
2285 df_chain_alloc, /* Allocate the problem specific data. */
30cb87a0 2286 df_chain_reset, /* Reset global information. */
4d779342
DB
2287 NULL, /* Free basic block info. */
2288 NULL, /* Local compute function. */
2289 NULL, /* Init the solution specific data. */
2290 NULL, /* Iterative solver. */
2291 NULL, /* Confluence operator 0. */
2292 NULL, /* Confluence operator n. */
2293 NULL, /* Transfer function. */
2294 df_chain_finalize, /* Finalize function. */
2295 df_chain_free, /* Free all of the problem information. */
6fb5fa3c
DB
2296 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
2297 NULL, /* Debugging. */
2298 df_chain_top_dump, /* Debugging start block. */
2299 df_chain_bottom_dump, /* Debugging end block. */
2300 NULL, /* Incremental solution verify start. */
6ed3da00 2301 NULL, /* Incremental solution verify end. */
6fb5fa3c 2302 &problem_RD, /* Dependent problem. */
89a95777
KZ
2303 TV_DF_CHAIN, /* Timing variable. */
2304 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
2305};
2306
2307
2308/* Create a new DATAFLOW instance and add it to an existing instance
2309 of DF. The returned structure is what is used to get at the
2310 solution. */
2311
6fb5fa3c
DB
2312void
2313df_chain_add_problem (enum df_chain_flags chain_flags)
4d779342 2314{
6fb5fa3c
DB
2315 df_add_problem (&problem_CHAIN);
2316 df_chain->local_flags = (unsigned int)chain_flags;
2317 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
4d779342
DB
2318}
2319
6fb5fa3c 2320#undef df_chain_problem_p
4d779342 2321
6fb5fa3c 2322\f
4d779342 2323/*----------------------------------------------------------------------------
6fb5fa3c 2324 This pass computes REG_DEAD and REG_UNUSED notes.
23249ac4 2325 ----------------------------------------------------------------------------*/
4d779342 2326
89a95777
KZ
2327static void
2328df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
2329{
2330 df_note->optional_p = true;
2331}
2332
23249ac4
DB
2333#ifdef REG_DEAD_DEBUGGING
2334static void
6fb5fa3c 2335df_print_note (const char *prefix, rtx insn, rtx note)
4d779342 2336{
6fb5fa3c
DB
2337 if (dump_file)
2338 {
2339 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
2340 print_rtl (dump_file, note);
2341 fprintf (dump_file, "\n");
2342 }
23249ac4
DB
2343}
2344#endif
4d779342 2345
23249ac4
DB
2346
2347/* After reg-stack, the x86 floating point stack regs are difficult to
2348 analyze because of all of the pushes, pops and rotations. Thus, we
2349 just leave the notes alone. */
2350
6fb5fa3c 2351#ifdef STACK_REGS
23249ac4 2352static inline bool
6fb5fa3c 2353df_ignore_stack_reg (int regno)
23249ac4 2354{
6fb5fa3c
DB
2355 return regstack_completed
2356 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2357}
23249ac4 2358#else
6fb5fa3c
DB
2359static inline bool
2360df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2361{
23249ac4 2362 return false;
23249ac4 2363}
6fb5fa3c 2364#endif
23249ac4
DB
2365
2366
6fb5fa3c
DB
2367/* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2368 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
23249ac4
DB
2369
2370static void
6fb5fa3c 2371df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
23249ac4
DB
2372{
2373 rtx *pprev = &REG_NOTES (insn);
2374 rtx link = *pprev;
6fb5fa3c
DB
2375 rtx dead = NULL;
2376 rtx unused = NULL;
2377
23249ac4
DB
2378 while (link)
2379 {
2380 switch (REG_NOTE_KIND (link))
2381 {
2382 case REG_DEAD:
6fb5fa3c
DB
2383 /* After reg-stack, we need to ignore any unused notes
2384 for the stack registers. */
2385 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2386 {
2387 pprev = &XEXP (link, 1);
2388 link = *pprev;
2389 }
2390 else
2391 {
2392 rtx next = XEXP (link, 1);
2393#ifdef REG_DEAD_DEBUGGING
2394 df_print_note ("deleting: ", insn, link);
2395#endif
2396 XEXP (link, 1) = dead;
2397 dead = link;
2398 *pprev = link = next;
2399 }
2400 break;
23249ac4 2401
23249ac4 2402 case REG_UNUSED:
6fb5fa3c
DB
2403 /* After reg-stack, we need to ignore any unused notes
2404 for the stack registers. */
2405 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2406 {
2407 pprev = &XEXP (link, 1);
2408 link = *pprev;
2409 }
2410 else
23249ac4
DB
2411 {
2412 rtx next = XEXP (link, 1);
2413#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2414 df_print_note ("deleting: ", insn, link);
23249ac4 2415#endif
6fb5fa3c
DB
2416 XEXP (link, 1) = unused;
2417 unused = link;
23249ac4
DB
2418 *pprev = link = next;
2419 }
2420 break;
2421
2422 default:
2423 pprev = &XEXP (link, 1);
2424 link = *pprev;
2425 break;
2426 }
2427 }
6fb5fa3c
DB
2428
2429 *old_dead_notes = dead;
2430 *old_unused_notes = unused;
23249ac4
DB
2431}
2432
2433
6fb5fa3c
DB
2434/* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
2435 list, otherwise create a new one. */
2436
2437static inline rtx
2438df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
2439{
2440 rtx this = old;
2441 rtx prev = NULL;
2442
2443 while (this)
2444 if (XEXP (this, 0) == reg)
2445 {
2446 if (prev)
2447 XEXP (prev, 1) = XEXP (this, 1);
2448 else
2449 old = XEXP (this, 1);
2450 XEXP (this, 1) = REG_NOTES (insn);
2451 REG_NOTES (insn) = this;
2452 return old;
2453 }
2454 else
2455 {
2456 prev = this;
2457 this = XEXP (this, 1);
2458 }
2459
2460 /* Did not find the note. */
2461 REG_NOTES (insn) = alloc_EXPR_LIST (note_type, reg, REG_NOTES (insn));
2462 return old;
2463}
2464
6f5c1520
RS
2465/* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2466 arguments. Return true if the register value described by MWS's
2467 mw_reg is known to be completely unused, and if mw_reg can therefore
2468 be used in a REG_UNUSED note. */
2469
2470static bool
2471df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2472 bitmap live, bitmap artificial_uses)
2473{
2474 unsigned int r;
2475
2476 /* If MWS describes a partial reference, create REG_UNUSED notes for
2477 individual hard registers. */
2478 if (mws->flags & DF_REF_PARTIAL)
2479 return false;
2480
2481 /* Likewise if some part of the register is used. */
2482 for (r = mws->start_regno; r <= mws->end_regno; r++)
2483 if (bitmap_bit_p (live, r)
2484 || bitmap_bit_p (artificial_uses, r))
2485 return false;
2486
2487 gcc_assert (REG_P (mws->mw_reg));
2488 return true;
2489}
2490
23249ac4
DB
2491/* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2492 based on the bits in LIVE. Do not generate notes for registers in
2493 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2494 not generated if the reg is both read and written by the
2495 instruction.
2496*/
2497
6fb5fa3c
DB
2498static rtx
2499df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
23249ac4 2500 bitmap live, bitmap do_not_gen,
6fb5fa3c 2501 bitmap artificial_uses)
23249ac4 2502{
6fb5fa3c 2503 unsigned int r;
23249ac4
DB
2504
2505#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
2506 if (dump_file)
2507 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
2508 mws->start_regno, mws->end_regno);
23249ac4 2509#endif
6f5c1520
RS
2510
2511 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
23249ac4 2512 {
6fb5fa3c 2513 unsigned int regno = mws->start_regno;
6f5c1520 2514 old = df_set_note (REG_UNUSED, insn, old, mws->mw_reg);
6fb5fa3c 2515
23249ac4 2516#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2517 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
23249ac4
DB
2518#endif
2519 bitmap_set_bit (do_not_gen, regno);
2520 /* Only do this if the value is totally dead. */
23249ac4
DB
2521 }
2522 else
27178277 2523 for (r = mws->start_regno; r <= mws->end_regno; r++)
6fb5fa3c 2524 {
27178277
RS
2525 if (!bitmap_bit_p (live, r)
2526 && !bitmap_bit_p (artificial_uses, r))
6fb5fa3c
DB
2527 {
2528 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
23249ac4 2529#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2530 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
23249ac4 2531#endif
6fb5fa3c
DB
2532 }
2533 bitmap_set_bit (do_not_gen, r);
2534 }
2535 return old;
23249ac4
DB
2536}
2537
2538
6f5c1520
RS
2539/* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2540 arguments. Return true if the register value described by MWS's
2541 mw_reg is known to be completely dead, and if mw_reg can therefore
2542 be used in a REG_DEAD note. */
2543
2544static bool
2545df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2546 bitmap live, bitmap artificial_uses,
2547 bitmap do_not_gen)
2548{
2549 unsigned int r;
2550
2551 /* If MWS describes a partial reference, create REG_DEAD notes for
2552 individual hard registers. */
2553 if (mws->flags & DF_REF_PARTIAL)
2554 return false;
2555
2556 /* Likewise if some part of the register is not dead. */
2557 for (r = mws->start_regno; r <= mws->end_regno; r++)
2558 if (bitmap_bit_p (live, r)
2559 || bitmap_bit_p (artificial_uses, r)
2560 || bitmap_bit_p (do_not_gen, r))
2561 return false;
2562
2563 gcc_assert (REG_P (mws->mw_reg));
2564 return true;
2565}
2566
23249ac4
DB
2567/* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2568 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2569 from being set if the instruction both reads and writes the
2570 register. */
2571
6fb5fa3c
DB
2572static rtx
2573df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
23249ac4 2574 bitmap live, bitmap do_not_gen,
6fb5fa3c 2575 bitmap artificial_uses)
23249ac4 2576{
6fb5fa3c 2577 unsigned int r;
23249ac4
DB
2578
2579#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2580 if (dump_file)
23249ac4 2581 {
6fb5fa3c
DB
2582 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
2583 mws->start_regno, mws->end_regno);
2584 df_print_regset (dump_file, do_not_gen);
2585 fprintf (dump_file, " live =");
2586 df_print_regset (dump_file, live);
2587 fprintf (dump_file, " artificial uses =");
2588 df_print_regset (dump_file, artificial_uses);
23249ac4 2589 }
6fb5fa3c
DB
2590#endif
2591
6f5c1520 2592 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
23249ac4 2593 {
6f5c1520
RS
2594 /* Add a dead note for the entire multi word register. */
2595 old = df_set_note (REG_DEAD, insn, old, mws->mw_reg);
23249ac4 2596#ifdef REG_DEAD_DEBUGGING
6f5c1520 2597 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
23249ac4 2598#endif
23249ac4
DB
2599 }
2600 else
2601 {
6fb5fa3c 2602 for (r = mws->start_regno; r <= mws->end_regno; r++)
27178277
RS
2603 if (!bitmap_bit_p (live, r)
2604 && !bitmap_bit_p (artificial_uses, r)
2605 && !bitmap_bit_p (do_not_gen, r))
2606 {
2607 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
23249ac4 2608#ifdef REG_DEAD_DEBUGGING
27178277 2609 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
23249ac4 2610#endif
27178277 2611 }
23249ac4 2612 }
6fb5fa3c 2613 return old;
23249ac4
DB
2614}
2615
2616
e4142b7c
KZ
2617/* Create a REG_UNUSED note if necessary for DEF in INSN updating
2618 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
23249ac4 2619
6fb5fa3c
DB
2620static rtx
2621df_create_unused_note (rtx insn, rtx old, struct df_ref *def,
e4142b7c 2622 bitmap live, bitmap artificial_uses)
23249ac4
DB
2623{
2624 unsigned int dregno = DF_REF_REGNO (def);
2625
2626#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2627 if (dump_file)
23249ac4 2628 {
6fb5fa3c
DB
2629 fprintf (dump_file, " regular looking at def ");
2630 df_ref_debug (def, dump_file);
23249ac4 2631 }
6fb5fa3c
DB
2632#endif
2633
2634 if (!(bitmap_bit_p (live, dregno)
2635 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
2636 || bitmap_bit_p (artificial_uses, dregno)
2637 || df_ignore_stack_reg (dregno)))
23249ac4 2638 {
6fb5fa3c
DB
2639 rtx reg = (DF_REF_LOC (def))
2640 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
2641 old = df_set_note (REG_UNUSED, insn, old, reg);
23249ac4 2642#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2643 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
23249ac4 2644#endif
23249ac4
DB
2645 }
2646
6fb5fa3c 2647 return old;
4d779342
DB
2648}
2649
23249ac4
DB
2650
2651/* Recompute the REG_DEAD and REG_UNUSED notes and compute register
2652 info: lifetime, bb, and number of defs and uses for basic block
2653 BB. The three bitvectors are scratch regs used here. */
4d779342
DB
2654
2655static void
6fb5fa3c 2656df_note_bb_compute (unsigned int bb_index,
e4142b7c 2657 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
4d779342 2658{
4d779342
DB
2659 basic_block bb = BASIC_BLOCK (bb_index);
2660 rtx insn;
6fb5fa3c
DB
2661 struct df_ref **def_rec;
2662 struct df_ref **use_rec;
23249ac4 2663
6fb5fa3c 2664 bitmap_copy (live, df_get_live_out (bb));
23249ac4
DB
2665 bitmap_clear (artificial_uses);
2666
6fb5fa3c
DB
2667#ifdef REG_DEAD_DEBUGGING
2668 if (dump_file)
23249ac4 2669 {
6fb5fa3c
DB
2670 fprintf (dump_file, "live at bottom ");
2671 df_print_regset (dump_file, live);
23249ac4 2672 }
6fb5fa3c 2673#endif
23249ac4
DB
2674
2675 /* Process the artificial defs and uses at the bottom of the block
2676 to begin processing. */
6fb5fa3c
DB
2677 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2678 {
2679 struct df_ref *def = *def_rec;
8b9d606b 2680#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
2681 if (dump_file)
2682 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
8b9d606b 2683#endif
4d779342 2684
6fb5fa3c
DB
2685 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2686 bitmap_clear_bit (live, DF_REF_REGNO (def));
2687 }
4d779342 2688
6fb5fa3c
DB
2689 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
2690 {
2691 struct df_ref *use = *use_rec;
2692 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
2693 {
2694 unsigned int regno = DF_REF_REGNO (use);
2695 bitmap_set_bit (live, regno);
2696
2697 /* Notes are not generated for any of the artificial registers
2698 at the bottom of the block. */
2699 bitmap_set_bit (artificial_uses, regno);
2700 }
2701 }
23249ac4 2702
6fb5fa3c
DB
2703#ifdef REG_DEAD_DEBUGGING
2704 if (dump_file)
2705 {
2706 fprintf (dump_file, "live before artificials out ");
2707 df_print_regset (dump_file, live);
2708 }
2709#endif
2710
4d779342
DB
2711 FOR_BB_INSNS_REVERSE (bb, insn)
2712 {
2713 unsigned int uid = INSN_UID (insn);
6fb5fa3c
DB
2714 struct df_mw_hardreg **mws_rec;
2715 rtx old_dead_notes;
2716 rtx old_unused_notes;
2717
23249ac4 2718 if (!INSN_P (insn))
4d779342
DB
2719 continue;
2720
23249ac4 2721 bitmap_clear (do_not_gen);
6fb5fa3c 2722 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
23249ac4
DB
2723
2724 /* Process the defs. */
2725 if (CALL_P (insn))
2726 {
6fb5fa3c
DB
2727#ifdef REG_DEAD_DEBUGGING
2728 if (dump_file)
23249ac4 2729 {
6fb5fa3c
DB
2730 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
2731 df_print_regset (dump_file, live);
23249ac4 2732 }
6fb5fa3c 2733#endif
e44e043c
KZ
2734 /* We only care about real sets for calls. Clobbers cannot
2735 be depended on to really die. */
6fb5fa3c
DB
2736 mws_rec = DF_INSN_UID_MWS (uid);
2737 while (*mws_rec)
23249ac4 2738 {
6fb5fa3c 2739 struct df_mw_hardreg *mws = *mws_rec;
23249ac4 2740 if ((mws->type == DF_REF_REG_DEF)
23da9ed6 2741 && !df_ignore_stack_reg (mws->start_regno))
6fb5fa3c
DB
2742 old_unused_notes
2743 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2744 mws, live, do_not_gen,
2745 artificial_uses);
2746 mws_rec++;
23249ac4
DB
2747 }
2748
2749 /* All of the defs except the return value are some sort of
2750 clobber. This code is for the return. */
6fb5fa3c
DB
2751 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2752 {
2753 struct df_ref *def = *def_rec;
e4142b7c
KZ
2754 unsigned int dregno = DF_REF_REGNO (def);
2755 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2756 {
2757 old_unused_notes
2758 = df_create_unused_note (insn, old_unused_notes,
2759 def, live, artificial_uses);
2760 bitmap_set_bit (do_not_gen, dregno);
2761 }
2762
2763 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2764 bitmap_clear_bit (live, dregno);
6fb5fa3c 2765 }
23249ac4
DB
2766 }
2767 else
2768 {
2769 /* Regular insn. */
6fb5fa3c
DB
2770 mws_rec = DF_INSN_UID_MWS (uid);
2771 while (*mws_rec)
23249ac4 2772 {
6fb5fa3c 2773 struct df_mw_hardreg *mws = *mws_rec;
23249ac4 2774 if (mws->type == DF_REF_REG_DEF)
6fb5fa3c
DB
2775 old_unused_notes
2776 = df_set_unused_notes_for_mw (insn, old_unused_notes,
2777 mws, live, do_not_gen,
2778 artificial_uses);
2779 mws_rec++;
23249ac4
DB
2780 }
2781
6fb5fa3c
DB
2782 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
2783 {
2784 struct df_ref *def = *def_rec;
e4142b7c 2785 unsigned int dregno = DF_REF_REGNO (def);
6fb5fa3c
DB
2786 old_unused_notes
2787 = df_create_unused_note (insn, old_unused_notes,
e4142b7c
KZ
2788 def, live, artificial_uses);
2789
2790 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
2791 bitmap_set_bit (do_not_gen, dregno);
2792
2793 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2794 bitmap_clear_bit (live, dregno);
6fb5fa3c 2795 }
23249ac4
DB
2796 }
2797
2798 /* Process the uses. */
6fb5fa3c
DB
2799 mws_rec = DF_INSN_UID_MWS (uid);
2800 while (*mws_rec)
23249ac4 2801 {
6fb5fa3c 2802 struct df_mw_hardreg *mws = *mws_rec;
23249ac4 2803 if ((mws->type != DF_REF_REG_DEF)
23da9ed6 2804 && !df_ignore_stack_reg (mws->start_regno))
6fb5fa3c
DB
2805 old_dead_notes
2806 = df_set_dead_notes_for_mw (insn, old_dead_notes,
2807 mws, live, do_not_gen,
2808 artificial_uses);
2809 mws_rec++;
4d779342
DB
2810 }
2811
6fb5fa3c 2812 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
4d779342 2813 {
6fb5fa3c 2814 struct df_ref *use = *use_rec;
4d779342
DB
2815 unsigned int uregno = DF_REF_REGNO (use);
2816
6fb5fa3c
DB
2817#ifdef REG_DEAD_DEBUGGING
2818 if (dump_file)
23249ac4 2819 {
6fb5fa3c
DB
2820 fprintf (dump_file, " regular looking at use ");
2821 df_ref_debug (use, dump_file);
23249ac4 2822 }
23249ac4 2823#endif
912f2dac
DB
2824 if (!bitmap_bit_p (live, uregno))
2825 {
23249ac4
DB
2826 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
2827 && (!bitmap_bit_p (do_not_gen, uregno))
2828 && (!bitmap_bit_p (artificial_uses, uregno))
2829 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
2830 && (!df_ignore_stack_reg (uregno)))
2831 {
6fb5fa3c
DB
2832 rtx reg = (DF_REF_LOC (use))
2833 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
2834 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
23249ac4
DB
2835
2836#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2837 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
23249ac4
DB
2838#endif
2839 }
912f2dac
DB
2840 /* This register is now live. */
2841 bitmap_set_bit (live, uregno);
2842 }
4d779342 2843 }
6fb5fa3c
DB
2844
2845 while (old_unused_notes)
4d779342 2846 {
6fb5fa3c
DB
2847 rtx next = XEXP (old_unused_notes, 1);
2848 free_EXPR_LIST_node (old_unused_notes);
2849 old_unused_notes = next;
2850 }
2851 while (old_dead_notes)
2852 {
2853 rtx next = XEXP (old_dead_notes, 1);
2854 free_EXPR_LIST_node (old_dead_notes);
2855 old_dead_notes = next;
4d779342
DB
2856 }
2857 }
2858}
2859
2860
2861/* Compute register info: lifetime, bb, and number of defs and uses. */
2862static void
6fb5fa3c 2863df_note_compute (bitmap all_blocks)
4d779342
DB
2864{
2865 unsigned int bb_index;
2866 bitmap_iterator bi;
6fb5fa3c
DB
2867 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
2868 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
2869 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
23249ac4
DB
2870
2871#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
2872 if (dump_file)
2873 print_rtl_with_bb (dump_file, get_insns());
23249ac4 2874#endif
4d779342 2875
6fb5fa3c 2876 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 2877 {
6fb5fa3c 2878 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
4d779342
DB
2879 }
2880
2881 BITMAP_FREE (live);
23249ac4
DB
2882 BITMAP_FREE (do_not_gen);
2883 BITMAP_FREE (artificial_uses);
4d779342
DB
2884}
2885
2886
2887/* Free all storage associated with the problem. */
2888
2889static void
6fb5fa3c 2890df_note_free (void)
4d779342 2891{
6fb5fa3c 2892 free (df_note);
4d779342
DB
2893}
2894
2895
4d779342
DB
2896/* All of the information associated every instance of the problem. */
2897
6fb5fa3c 2898static struct df_problem problem_NOTE =
4d779342 2899{
6fb5fa3c 2900 DF_NOTE, /* Problem id. */
4d779342 2901 DF_NONE, /* Direction. */
89a95777 2902 df_note_alloc, /* Allocate the problem specific data. */
30cb87a0 2903 NULL, /* Reset global information. */
4d779342 2904 NULL, /* Free basic block info. */
6fb5fa3c 2905 df_note_compute, /* Local compute function. */
4d779342
DB
2906 NULL, /* Init the solution specific data. */
2907 NULL, /* Iterative solver. */
2908 NULL, /* Confluence operator 0. */
2909 NULL, /* Confluence operator n. */
2910 NULL, /* Transfer function. */
2911 NULL, /* Finalize function. */
6fb5fa3c
DB
2912 df_note_free, /* Free all of the problem information. */
2913 df_note_free, /* Remove this problem from the stack of dataflow problems. */
2914 NULL, /* Debugging. */
2915 NULL, /* Debugging start block. */
2916 NULL, /* Debugging end block. */
2917 NULL, /* Incremental solution verify start. */
6ed3da00 2918 NULL, /* Incremental solution verify end. */
23249ac4
DB
2919
2920 /* Technically this is only dependent on the live registers problem
6fc0bb99 2921 but it will produce information if built one of uninitialized
23249ac4 2922 register problems (UR, UREC) is also run. */
6fb5fa3c 2923 &problem_LR, /* Dependent problem. */
89a95777
KZ
2924 TV_DF_NOTE, /* Timing variable. */
2925 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
2926};
2927
2928
2929/* Create a new DATAFLOW instance and add it to an existing instance
2930 of DF. The returned structure is what is used to get at the
2931 solution. */
2932
6fb5fa3c
DB
2933void
2934df_note_add_problem (void)
4d779342 2935{
6fb5fa3c 2936 df_add_problem (&problem_NOTE);
4d779342 2937}
6fb5fa3c
DB
2938
2939
2940
2941\f
2942/*----------------------------------------------------------------------------
2943 Functions for simulating the effects of single insns.
2944
2945 You can either simulate in the forwards direction, starting from
2946 the top of a block or the backwards direction from the end of the
2947 block. The main difference is that if you go forwards, the uses
2948 are examined first then the defs, and if you go backwards, the defs
2949 are examined first then the uses.
2950
2951 If you start at the top of the block, use one of DF_LIVE_IN or
2952 DF_LR_IN. If you start at the bottom of the block use one of
2953 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
2954 THEY WILL BE DESTROYED.
2955
2956----------------------------------------------------------------------------*/
2957
2958
2959/* Find the set of DEFs for INSN. */
2960
2961void
2962df_simulate_find_defs (rtx insn, bitmap defs)
2963{
2964 struct df_ref **def_rec;
2965 unsigned int uid = INSN_UID (insn);
2966
5d545bf1 2967 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
6fb5fa3c 2968 {
5d545bf1
SP
2969 struct df_ref *def = *def_rec;
2970 /* If the def is to only part of the reg, it does
2971 not kill the other defs that reach here. */
2972 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2973 bitmap_set_bit (defs, DF_REF_REGNO (def));
6fb5fa3c
DB
2974 }
2975}
2976
2977
2978/* Simulate the effects of the defs of INSN on LIVE. */
2979
2980void
2981df_simulate_defs (rtx insn, bitmap live)
2982{
2983 struct df_ref **def_rec;
2984 unsigned int uid = INSN_UID (insn);
2985
5d545bf1 2986 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
6fb5fa3c 2987 {
5d545bf1
SP
2988 struct df_ref *def = *def_rec;
2989 unsigned int dregno = DF_REF_REGNO (def);
2990
2991 /* If the def is to only part of the reg, it does
2992 not kill the other defs that reach here. */
2993 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
2994 bitmap_clear_bit (live, dregno);
6fb5fa3c
DB
2995 }
2996}
2997
2998
2999/* Simulate the effects of the uses of INSN on LIVE. */
3000
3001void
3002df_simulate_uses (rtx insn, bitmap live)
3003{
3004 struct df_ref **use_rec;
3005 unsigned int uid = INSN_UID (insn);
3006
3007 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3008 {
3009 struct df_ref *use = *use_rec;
3010 /* Add use to set of uses in this BB. */
3011 bitmap_set_bit (live, DF_REF_REGNO (use));
3012 }
3013}
3014
3015
3016/* Add back the always live regs in BB to LIVE. */
3017
3018static inline void
3019df_simulate_fixup_sets (basic_block bb, bitmap live)
3020{
3021 /* These regs are considered always live so if they end up dying
3022 because of some def, we need to bring the back again. */
ba49cb7b 3023 if (bb_has_eh_pred (bb))
6fb5fa3c
DB
3024 bitmap_ior_into (live, df->eh_block_artificial_uses);
3025 else
3026 bitmap_ior_into (live, df->regular_block_artificial_uses);
3027}
3028
3029
0d52bcc1 3030/* Apply the artificial uses and defs at the top of BB in a forwards
6fb5fa3c
DB
3031 direction. */
3032
3033void
3034df_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
3035{
3036 struct df_ref **def_rec;
3037 struct df_ref **use_rec;
3038 int bb_index = bb->index;
3039
3040 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3041 {
3042 struct df_ref *use = *use_rec;
3043 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
3044 bitmap_set_bit (live, DF_REF_REGNO (use));
3045 }
3046
3047 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3048 {
3049 struct df_ref *def = *def_rec;
3050 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3051 bitmap_clear_bit (live, DF_REF_REGNO (def));
3052 }
3053}
3054
3055
3056/* Simulate the forwards effects of INSN on the bitmap LIVE. */
3057
3058void
3059df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3060{
3061 if (! INSN_P (insn))
3062 return;
3063
3064 df_simulate_uses (insn, live);
3065 df_simulate_defs (insn, live);
3066 df_simulate_fixup_sets (bb, live);
3067}
3068
3069
0d52bcc1 3070/* Apply the artificial uses and defs at the end of BB in a backwards
6fb5fa3c
DB
3071 direction. */
3072
3073void
3074df_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
3075{
3076 struct df_ref **def_rec;
3077 struct df_ref **use_rec;
3078 int bb_index = bb->index;
3079
3080 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3081 {
3082 struct df_ref *def = *def_rec;
3083 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3084 bitmap_clear_bit (live, DF_REF_REGNO (def));
3085 }
3086
3087 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3088 {
3089 struct df_ref *use = *use_rec;
3090 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3091 bitmap_set_bit (live, DF_REF_REGNO (use));
3092 }
3093}
3094
3095
3096/* Simulate the backwards effects of INSN on the bitmap LIVE. */
3097
3098void
3099df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
3100{
3101 if (! INSN_P (insn))
3102 return;
3103
3104 df_simulate_defs (insn, live);
3105 df_simulate_uses (insn, live);
3106 df_simulate_fixup_sets (bb, live);
3107}
3108
3109