]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/df-problems.c
c-common.c (pointer_int_sum): Do the negation in sizetype.
[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
13Software Foundation; either version 2, or (at your option) any later
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
22along with GCC; see the file COPYING. If not, write to the Free
23Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2402110-1301, USA. */
25
26#include "config.h"
27#include "system.h"
28#include "coretypes.h"
29#include "tm.h"
30#include "rtl.h"
31#include "tm_p.h"
32#include "insn-config.h"
33#include "recog.h"
34#include "function.h"
35#include "regs.h"
36#include "output.h"
37#include "alloc-pool.h"
38#include "flags.h"
39#include "hard-reg-set.h"
40#include "basic-block.h"
41#include "sbitmap.h"
42#include "bitmap.h"
43#include "timevar.h"
44#include "df.h"
23249ac4 45#include "except.h"
6fb5fa3c
DB
46#include "dce.h"
47#include "vecprim.h"
23249ac4 48
e44e043c
KZ
49/* Note that turning REG_DEAD_DEBUGGING on will cause
50 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
51 addresses in the dumps. */
23249ac4
DB
52#if 0
53#define REG_DEAD_DEBUGGING
54#endif
4d779342
DB
55
56#define DF_SPARSE_THRESHOLD 32
57
58static bitmap seen_in_block = NULL;
59static bitmap seen_in_insn = NULL;
60
61\f
62/*----------------------------------------------------------------------------
63 Public functions access functions for the dataflow problems.
64----------------------------------------------------------------------------*/
6fb5fa3c
DB
65/* Get the live at out set for BB no matter what problem happens to be
66 defined. This function is used by the register allocators who
67 choose different dataflow problems depending on the optimization
68 level. */
4d779342 69
6fb5fa3c
DB
70bitmap
71df_get_live_out (basic_block bb)
4d779342 72{
6fb5fa3c 73 gcc_assert (df_lr);
4d779342 74
6fb5fa3c
DB
75 if (df_urec)
76 return DF_RA_LIVE_OUT (bb);
77 else if (df_live)
78 return DF_LIVE_OUT (bb);
79 else
80 return DF_LR_OUT (bb);
4d779342
DB
81}
82
6fb5fa3c
DB
83/* Get the live at in set for BB no matter what problem happens to be
84 defined. This function is used by the register allocators who
85 choose different dataflow problems depending on the optimization
86 level. */
4d779342
DB
87
88bitmap
6fb5fa3c 89df_get_live_in (basic_block bb)
4d779342 90{
6fb5fa3c 91 gcc_assert (df_lr);
4d779342 92
6fb5fa3c
DB
93 if (df_urec)
94 return DF_RA_LIVE_IN (bb);
95 else if (df_live)
96 return DF_LIVE_IN (bb);
4d779342 97 else
6fb5fa3c 98 return DF_LR_IN (bb);
4d779342
DB
99}
100
6fb5fa3c
DB
101/* Get the live at top set for BB no matter what problem happens to be
102 defined. This function is used by the register allocators who
103 choose different dataflow problems depending on the optimization
104 level. */
4d779342
DB
105
106bitmap
6fb5fa3c 107df_get_live_top (basic_block bb)
4d779342 108{
6fb5fa3c 109 gcc_assert (df_lr);
4d779342 110
6fb5fa3c
DB
111 if (df_urec)
112 return DF_RA_LIVE_TOP (bb);
4d779342 113 else
6fb5fa3c 114 return DF_LR_TOP (bb);
4d779342
DB
115}
116
117
118/*----------------------------------------------------------------------------
119 Utility functions.
120----------------------------------------------------------------------------*/
121
122/* Generic versions to get the void* version of the block info. Only
c0220ea4 123 used inside the problem instance vectors. */
4d779342
DB
124
125/* Grow the bb_info array. */
126
127void
128df_grow_bb_info (struct dataflow *dflow)
129{
130 unsigned int new_size = last_basic_block + 1;
131 if (dflow->block_info_size < new_size)
132 {
133 new_size += new_size / 4;
134 dflow->block_info = xrealloc (dflow->block_info,
135 new_size *sizeof (void*));
136 memset (dflow->block_info + dflow->block_info_size, 0,
137 (new_size - dflow->block_info_size) *sizeof (void *));
138 dflow->block_info_size = new_size;
139 }
140}
141
142/* Dump a def-use or use-def chain for REF to FILE. */
143
144void
23249ac4 145df_chain_dump (struct df_link *link, FILE *file)
4d779342
DB
146{
147 fprintf (file, "{ ");
148 for (; link; link = link->next)
149 {
150 fprintf (file, "%c%d(bb %d insn %d) ",
151 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
152 DF_REF_ID (link->ref),
153 DF_REF_BBNO (link->ref),
154 DF_REF_INSN (link->ref) ? DF_REF_INSN_UID (link->ref) : -1);
155 }
156 fprintf (file, "}");
157}
158
159
160/* Print some basic block info as part of df_dump. */
161
162void
163df_print_bb_index (basic_block bb, FILE *file)
164{
165 edge e;
166 edge_iterator ei;
167
6fb5fa3c 168 fprintf (file, "\n( ");
4d779342
DB
169 FOR_EACH_EDGE (e, ei, bb->preds)
170 {
171 basic_block pred = e->src;
6fb5fa3c 172 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
4d779342
DB
173 }
174 fprintf (file, ")->[%d]->( ", bb->index);
175 FOR_EACH_EDGE (e, ei, bb->succs)
176 {
177 basic_block succ = e->dest;
6fb5fa3c 178 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
4d779342
DB
179 }
180 fprintf (file, ")\n");
181}
182
183
4d779342
DB
184
185/* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
186 up correctly. */
187
188static void
189df_set_seen (void)
190{
6fb5fa3c
DB
191 seen_in_block = BITMAP_ALLOC (&df_bitmap_obstack);
192 seen_in_insn = BITMAP_ALLOC (&df_bitmap_obstack);
4d779342
DB
193}
194
195
196static void
197df_unset_seen (void)
198{
199 BITMAP_FREE (seen_in_block);
200 BITMAP_FREE (seen_in_insn);
201}
202
203
204\f
205/*----------------------------------------------------------------------------
206 REACHING USES
207
208 Find the locations in the function where each use site for a pseudo
b11550aa
KZ
209 can reach backwards. In and out bitvectors are built for each basic
210 block. The id field in the ref is used to index into these sets.
211 See df.h for details.
4d779342
DB
212
213----------------------------------------------------------------------------*/
214
b11550aa
KZ
215/* This problem plays a large number of games for the sake of
216 efficiency.
217
218 1) The order of the bits in the bitvectors. After the scanning
219 phase, all of the uses are sorted. All of the uses for the reg 0
220 are first, followed by all uses for reg 1 and so on.
221
222 2) There are two kill sets, one if the number of uses is less or
223 equal to DF_SPARSE_THRESHOLD and another if it is greater.
224
6fb5fa3c 225 <= : Data is built directly in the kill set.
b11550aa
KZ
226
227 > : One level of indirection is used to keep from generating long
228 strings of 1 bits in the kill sets. Bitvectors that are indexed
229 by the regnum are used to represent that there is a killing def
230 for the register. The confluence and transfer functions use
231 these along with the bitmap_clear_range call to remove ranges of
232 bits without actually generating a knockout vector.
233
234 The kill and sparse_kill and the dense_invalidated_by_call and
6fb5fa3c 235 sparse_invalidated_by_call both play this game. */
b11550aa
KZ
236
237/* Private data used to compute the solution for this problem. These
6fc0bb99 238 data structures are not accessible outside of this module. */
4d779342
DB
239struct df_ru_problem_data
240{
4d779342
DB
241 /* The set of defs to regs invalidated by call. */
242 bitmap sparse_invalidated_by_call;
912f2dac 243 /* The set of defs to regs invalidated by call for ru. */
6fb5fa3c
DB
244 bitmap dense_invalidated_by_call;
245 /* An obstack for the bitmaps we need for this problem. */
246 bitmap_obstack ru_bitmaps;
4d779342
DB
247};
248
4d779342
DB
249/* Set basic block info. */
250
251static void
6fb5fa3c 252df_ru_set_bb_info (unsigned int index, struct df_ru_bb_info *bb_info)
4d779342 253{
6fb5fa3c
DB
254 gcc_assert (df_ru);
255 gcc_assert (index < df_ru->block_info_size);
256 df_ru->block_info[index] = bb_info;
4d779342
DB
257}
258
259
260/* Free basic block info. */
261
262static void
6fb5fa3c 263df_ru_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 264 void *vbb_info)
4d779342
DB
265{
266 struct df_ru_bb_info *bb_info = (struct df_ru_bb_info *) vbb_info;
267 if (bb_info)
268 {
269 BITMAP_FREE (bb_info->kill);
270 BITMAP_FREE (bb_info->sparse_kill);
271 BITMAP_FREE (bb_info->gen);
272 BITMAP_FREE (bb_info->in);
273 BITMAP_FREE (bb_info->out);
6fb5fa3c 274 pool_free (df_ru->block_pool, bb_info);
4d779342
DB
275 }
276}
277
278
6fb5fa3c 279/* Allocate or reset bitmaps for DF_RU blocks. The solution bits are
4d779342
DB
280 not touched unless the block is new. */
281
282static void
6fb5fa3c 283df_ru_alloc (bitmap all_blocks)
4d779342
DB
284{
285 unsigned int bb_index;
286 bitmap_iterator bi;
6fb5fa3c 287 struct df_ru_problem_data *problem_data;
4d779342 288
6fb5fa3c
DB
289 if (!df_ru->block_pool)
290 df_ru->block_pool = create_alloc_pool ("df_ru_block pool",
4d779342
DB
291 sizeof (struct df_ru_bb_info), 50);
292
6fb5fa3c 293 if (df_ru->problem_data)
4d779342 294 {
6fb5fa3c 295 problem_data = (struct df_ru_problem_data *) df_ru->problem_data;
4d779342
DB
296 bitmap_clear (problem_data->sparse_invalidated_by_call);
297 bitmap_clear (problem_data->dense_invalidated_by_call);
298 }
299 else
300 {
6fb5fa3c
DB
301 problem_data = XNEW (struct df_ru_problem_data);
302 df_ru->problem_data = problem_data;
303
304 bitmap_obstack_initialize (&problem_data->ru_bitmaps);
305 problem_data->sparse_invalidated_by_call
306 = BITMAP_ALLOC (&problem_data->ru_bitmaps);
307 problem_data->dense_invalidated_by_call
308 = BITMAP_ALLOC (&problem_data->ru_bitmaps);
4d779342
DB
309 }
310
6fb5fa3c 311 df_grow_bb_info (df_ru);
4d779342
DB
312
313 /* Because of the clustering of all def sites for the same pseudo,
314 we have to process all of the blocks before doing the
315 analysis. */
316
23249ac4 317 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 318 {
6fb5fa3c 319 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
4d779342
DB
320 if (bb_info)
321 {
322 bitmap_clear (bb_info->kill);
323 bitmap_clear (bb_info->sparse_kill);
324 bitmap_clear (bb_info->gen);
325 }
326 else
327 {
6fb5fa3c
DB
328 bb_info = (struct df_ru_bb_info *) pool_alloc (df_ru->block_pool);
329 df_ru_set_bb_info (bb_index, bb_info);
330 bb_info->kill = BITMAP_ALLOC (&problem_data->ru_bitmaps);
331 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->ru_bitmaps);
332 bb_info->gen = BITMAP_ALLOC (&problem_data->ru_bitmaps);
333 bb_info->in = BITMAP_ALLOC (&problem_data->ru_bitmaps);
334 bb_info->out = BITMAP_ALLOC (&problem_data->ru_bitmaps);
4d779342
DB
335 }
336 }
89a95777 337 df_ru->optional_p = true;
4d779342
DB
338}
339
340
341/* Process a list of DEFs for df_ru_bb_local_compute. */
342
343static void
6fb5fa3c
DB
344df_ru_bb_local_compute_process_def (struct df_ru_bb_info *bb_info,
345 struct df_ref **def_rec,
912f2dac 346 enum df_ref_flags top_flag)
4d779342 347{
6fb5fa3c 348 while (*def_rec)
4d779342 349 {
6fb5fa3c 350 struct df_ref *def = *def_rec;
23249ac4
DB
351 if ((top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
352 /* If the def is to only part of the reg, it is as if it did
353 not happen, since some of the bits may get thru. */
6fb5fa3c 354 && (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))))
4d779342 355 {
912f2dac 356 unsigned int regno = DF_REF_REGNO (def);
6fb5fa3c
DB
357 unsigned int begin = DF_USES_BEGIN (regno);
358 unsigned int n_uses = DF_USES_COUNT (regno);
359
912f2dac 360 if (!bitmap_bit_p (seen_in_block, regno))
4d779342 361 {
1a1a5f4b
KZ
362 /* The first def for regno in the insn, causes the kill
363 info to be generated. Do not modify the gen set
364 because the only values in it are the uses from here
365 to the top of the block and this def does not effect
366 them. */
912f2dac 367 if (!bitmap_bit_p (seen_in_insn, regno))
4d779342 368 {
912f2dac 369 if (n_uses > DF_SPARSE_THRESHOLD)
1a1a5f4b 370 bitmap_set_bit (bb_info->sparse_kill, regno);
912f2dac 371 else
6fb5fa3c 372 bitmap_set_range (bb_info->kill, begin, n_uses);
4d779342 373 }
912f2dac 374 bitmap_set_bit (seen_in_insn, regno);
4d779342 375 }
4d779342 376 }
6fb5fa3c 377 def_rec++;
4d779342
DB
378 }
379}
380
381
382/* Process a list of USEs for df_ru_bb_local_compute. */
383
384static void
385df_ru_bb_local_compute_process_use (struct df_ru_bb_info *bb_info,
6fb5fa3c 386 struct df_ref **use_rec,
4d779342
DB
387 enum df_ref_flags top_flag)
388{
6fb5fa3c 389 while (*use_rec)
4d779342 390 {
6fb5fa3c 391 struct df_ref *use = *use_rec;
4d779342
DB
392 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
393 {
394 /* Add use to set of gens in this BB unless we have seen a
395 def in a previous instruction. */
396 unsigned int regno = DF_REF_REGNO (use);
397 if (!bitmap_bit_p (seen_in_block, regno))
398 bitmap_set_bit (bb_info->gen, DF_REF_ID (use));
399 }
6fb5fa3c 400 use_rec++;
4d779342
DB
401 }
402}
403
404/* Compute local reaching use (upward exposed use) info for basic
405 block BB. USE_INFO->REGS[R] caches the set of uses for register R. */
406static void
6fb5fa3c 407df_ru_bb_local_compute (unsigned int bb_index)
4d779342 408{
4d779342 409 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 410 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
4d779342
DB
411 rtx insn;
412
413 /* Set when a def for regno is seen. */
414 bitmap_clear (seen_in_block);
415 bitmap_clear (seen_in_insn);
416
417#ifdef EH_USES
418 /* Variables defined in the prolog that are used by the exception
419 handler. */
420 df_ru_bb_local_compute_process_use (bb_info,
6fb5fa3c 421 df_get_artificial_uses (bb_index),
4d779342
DB
422 DF_REF_AT_TOP);
423#endif
6fb5fa3c
DB
424 df_ru_bb_local_compute_process_def (bb_info,
425 df_get_artificial_defs (bb_index),
912f2dac 426 DF_REF_AT_TOP);
4d779342
DB
427
428 FOR_BB_INSNS (bb, insn)
429 {
430 unsigned int uid = INSN_UID (insn);
23249ac4 431 if (!INSN_P (insn))
4d779342
DB
432 continue;
433
4d779342 434 df_ru_bb_local_compute_process_use (bb_info,
6fb5fa3c 435 DF_INSN_UID_USES (uid), 0);
4d779342 436
6fb5fa3c
DB
437 if (df->changeable_flags & DF_EQ_NOTES)
438 df_ru_bb_local_compute_process_use (bb_info,
439 DF_INSN_UID_EQ_USES (uid), 0);
440
441 df_ru_bb_local_compute_process_def (bb_info,
442 DF_INSN_UID_DEFS (uid), 0);
1a1a5f4b 443
4d779342
DB
444 bitmap_ior_into (seen_in_block, seen_in_insn);
445 bitmap_clear (seen_in_insn);
446 }
447
448 /* Process the hardware registers that are always live. */
449 df_ru_bb_local_compute_process_use (bb_info,
6fb5fa3c 450 df_get_artificial_uses (bb_index), 0);
912f2dac 451
6fb5fa3c
DB
452 df_ru_bb_local_compute_process_def (bb_info,
453 df_get_artificial_defs (bb_index), 0);
4d779342
DB
454}
455
456
457/* Compute local reaching use (upward exposed use) info for each basic
458 block within BLOCKS. */
459static void
6fb5fa3c 460df_ru_local_compute (bitmap all_blocks)
4d779342 461{
4d779342
DB
462 unsigned int bb_index;
463 bitmap_iterator bi;
464 unsigned int regno;
23249ac4 465 struct df_ru_problem_data *problem_data
6fb5fa3c 466 = (struct df_ru_problem_data *) df_ru->problem_data;
4d779342
DB
467 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
468 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
469
470 df_set_seen ();
6fb5fa3c
DB
471
472 df_maybe_reorganize_use_refs (df->changeable_flags & DF_EQ_NOTES ?
473 DF_REF_ORDER_BY_REG_WITH_NOTES : DF_REF_ORDER_BY_REG);
4d779342
DB
474
475 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
476 {
6fb5fa3c 477 df_ru_bb_local_compute (bb_index);
4d779342
DB
478 }
479
480 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
481 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
482 {
6fb5fa3c 483 if (DF_USES_COUNT (regno) > DF_SPARSE_THRESHOLD)
4d779342
DB
484 bitmap_set_bit (sparse_invalidated, regno);
485 else
6fb5fa3c
DB
486 bitmap_set_range (dense_invalidated,
487 DF_USES_BEGIN (regno),
488 DF_USES_COUNT (regno));
4d779342
DB
489 }
490
491 df_unset_seen ();
492}
493
494
495/* Initialize the solution bit vectors for problem. */
496
497static void
6fb5fa3c 498df_ru_init_solution (bitmap all_blocks)
4d779342
DB
499{
500 unsigned int bb_index;
501 bitmap_iterator bi;
502
503 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
504 {
6fb5fa3c 505 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
4d779342
DB
506 bitmap_copy (bb_info->in, bb_info->gen);
507 bitmap_clear (bb_info->out);
508 }
509}
510
511
512/* Out of target gets or of in of source. */
513
514static void
6fb5fa3c 515df_ru_confluence_n (edge e)
4d779342 516{
6fb5fa3c
DB
517 bitmap op1 = df_ru_get_bb_info (e->src->index)->out;
518 bitmap op2 = df_ru_get_bb_info (e->dest->index)->in;
4d779342
DB
519
520 if (e->flags & EDGE_EH)
521 {
23249ac4 522 struct df_ru_problem_data *problem_data
6fb5fa3c 523 = (struct df_ru_problem_data *) df_ru->problem_data;
4d779342
DB
524 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
525 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
4d779342
DB
526 bitmap_iterator bi;
527 unsigned int regno;
6fb5fa3c 528 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
59c52af4
KZ
529
530 bitmap_copy (tmp, op2);
531 bitmap_and_compl_into (tmp, dense_invalidated);
532
4d779342
DB
533 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
534 {
59c52af4 535 bitmap_clear_range (tmp,
6fb5fa3c
DB
536 DF_USES_BEGIN (regno),
537 DF_USES_COUNT (regno));
4d779342 538 }
59c52af4
KZ
539 bitmap_ior_into (op1, tmp);
540 BITMAP_FREE (tmp);
4d779342
DB
541 }
542 else
543 bitmap_ior_into (op1, op2);
544}
545
546
547/* Transfer function. */
548
549static bool
6fb5fa3c 550df_ru_transfer_function (int bb_index)
4d779342 551{
6fb5fa3c 552 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb_index);
4d779342
DB
553 unsigned int regno;
554 bitmap_iterator bi;
555 bitmap in = bb_info->in;
556 bitmap out = bb_info->out;
557 bitmap gen = bb_info->gen;
558 bitmap kill = bb_info->kill;
559 bitmap sparse_kill = bb_info->sparse_kill;
560
561 if (bitmap_empty_p (sparse_kill))
562 return bitmap_ior_and_compl (in, gen, out, kill);
563 else
564 {
6fb5fa3c
DB
565 struct df_ru_problem_data *problem_data;
566 bitmap tmp;
4d779342 567 bool changed = false;
6fb5fa3c
DB
568
569 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
570 IN with TMP. Therefore, allocate TMP in the RU bitmaps obstack. */
571 problem_data = (struct df_ru_problem_data *) df_ru->problem_data;
572 tmp = BITMAP_ALLOC (&problem_data->ru_bitmaps);
573
b11550aa 574 bitmap_copy (tmp, out);
4d779342
DB
575 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
576 {
577 bitmap_clear_range (tmp,
6fb5fa3c
DB
578 DF_USES_BEGIN (regno),
579 DF_USES_COUNT (regno));
4d779342
DB
580 }
581 bitmap_and_compl_into (tmp, kill);
582 bitmap_ior_into (tmp, gen);
59c52af4 583 changed = !bitmap_equal_p (tmp, in);
4d779342
DB
584 if (changed)
585 {
b11550aa 586 BITMAP_FREE (in);
4d779342
DB
587 bb_info->in = tmp;
588 }
589 else
590 BITMAP_FREE (tmp);
591 return changed;
592 }
593}
594
595
596/* Free all storage associated with the problem. */
597
598static void
6fb5fa3c 599df_ru_free (void)
4d779342
DB
600{
601 unsigned int i;
23249ac4 602 struct df_ru_problem_data *problem_data
6fb5fa3c 603 = (struct df_ru_problem_data *) df_ru->problem_data;
4d779342 604
3b8266e2 605 if (problem_data)
4d779342 606 {
6fb5fa3c 607 for (i = 0; i < df_ru->block_info_size; i++)
4d779342 608 {
6fb5fa3c 609 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (i);
3b8266e2
KZ
610 if (bb_info)
611 {
612 BITMAP_FREE (bb_info->kill);
613 BITMAP_FREE (bb_info->sparse_kill);
614 BITMAP_FREE (bb_info->gen);
615 BITMAP_FREE (bb_info->in);
616 BITMAP_FREE (bb_info->out);
617 }
4d779342 618 }
3b8266e2 619
6fb5fa3c 620 free_alloc_pool (df_ru->block_pool);
3b8266e2
KZ
621 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
622 BITMAP_FREE (problem_data->dense_invalidated_by_call);
6fb5fa3c 623 bitmap_obstack_release (&problem_data->ru_bitmaps);
3b8266e2 624
6fb5fa3c
DB
625 df_ru->block_info_size = 0;
626 free (df_ru->block_info);
627 free (df_ru->problem_data);
4d779342 628 }
6fb5fa3c 629 free (df_ru);
4d779342
DB
630}
631
632
633/* Debugging info. */
634
635static void
6fb5fa3c 636df_ru_start_dump (FILE *file)
4d779342 637{
23249ac4 638 struct df_ru_problem_data *problem_data
6fb5fa3c
DB
639 = (struct df_ru_problem_data *) df_ru->problem_data;
640 unsigned int m = DF_REG_SIZE(df);
4d779342 641 unsigned int regno;
23249ac4 642
6fb5fa3c 643 if (!df_ru->block_info)
23249ac4 644 return;
4d779342 645
6fb5fa3c 646 fprintf (file, ";; Reaching uses:\n");
4d779342 647
6fb5fa3c 648 fprintf (file, ";; sparse invalidated \t");
4d779342 649 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
6fb5fa3c 650 fprintf (file, " dense invalidated \t");
4d779342
DB
651 dump_bitmap (file, problem_data->dense_invalidated_by_call);
652
653 for (regno = 0; regno < m; regno++)
6fb5fa3c 654 if (DF_USES_COUNT (regno))
4d779342 655 fprintf (file, "%d[%d,%d] ", regno,
6fb5fa3c
DB
656 DF_USES_BEGIN (regno),
657 DF_USES_COUNT (regno));
4d779342 658 fprintf (file, "\n");
4d779342
DB
659}
660
6fb5fa3c
DB
661
662/* Debugging info at top of bb. */
663
664static void
665df_ru_top_dump (basic_block bb, FILE *file)
666{
667 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb->index);
668 if (!bb_info || !bb_info->in)
669 return;
670
671 fprintf (file, ";; ru in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
672 dump_bitmap (file, bb_info->in);
673 fprintf (file, ";; ru gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
674 dump_bitmap (file, bb_info->gen);
675 fprintf (file, ";; ru kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
676 dump_bitmap (file, bb_info->kill);
677}
678
679
680/* Debugging info at bottom of bb. */
681
682static void
683df_ru_bottom_dump (basic_block bb, FILE *file)
684{
685 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (bb->index);
686 if (!bb_info || !bb_info->out)
687 return;
688
689 fprintf (file, ";; ru out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
690 dump_bitmap (file, bb_info->out);
691}
692
693
4d779342
DB
694/* All of the information associated with every instance of the problem. */
695
696static struct df_problem problem_RU =
697{
698 DF_RU, /* Problem id. */
699 DF_BACKWARD, /* Direction. */
700 df_ru_alloc, /* Allocate the problem specific data. */
30cb87a0 701 NULL, /* Reset global information. */
4d779342
DB
702 df_ru_free_bb_info, /* Free basic block info. */
703 df_ru_local_compute, /* Local compute function. */
704 df_ru_init_solution, /* Init the solution specific data. */
6fb5fa3c 705 df_worklist_dataflow, /* Worklist solver. */
4d779342
DB
706 NULL, /* Confluence operator 0. */
707 df_ru_confluence_n, /* Confluence operator n. */
708 df_ru_transfer_function, /* Transfer function. */
709 NULL, /* Finalize function. */
710 df_ru_free, /* Free all of the problem information. */
6fb5fa3c
DB
711 df_ru_free, /* Remove this problem from the stack of dataflow problems. */
712 df_ru_start_dump, /* Debugging. */
713 df_ru_top_dump, /* Debugging start block. */
714 df_ru_bottom_dump, /* Debugging end block. */
715 NULL, /* Incremental solution verify start. */
716 NULL, /* Incremental solution verfiy end. */
23249ac4 717 NULL, /* Dependent problem. */
89a95777
KZ
718 TV_DF_RU, /* Timing variable. */
719 true /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
720};
721
722
723
724/* Create a new DATAFLOW instance and add it to an existing instance
725 of DF. The returned structure is what is used to get at the
726 solution. */
727
6fb5fa3c
DB
728void
729df_ru_add_problem (void)
4d779342 730{
6fb5fa3c 731 df_add_problem (&problem_RU);
4d779342
DB
732}
733
734\f
735/*----------------------------------------------------------------------------
736 REACHING DEFINITIONS
737
738 Find the locations in the function where each definition site for a
b11550aa
KZ
739 pseudo reaches. In and out bitvectors are built for each basic
740 block. The id field in the ref is used to index into these sets.
741 See df.h for details.
742 ----------------------------------------------------------------------------*/
743
744/* See the comment at the top of the Reaching Uses problem for how the
745 uses are represented in the kill sets. The same games are played
746 here for the defs. */
4d779342 747
b11550aa 748/* Private data used to compute the solution for this problem. These
6fc0bb99 749 data structures are not accessible outside of this module. */
4d779342
DB
750struct df_rd_problem_data
751{
4d779342
DB
752 /* The set of defs to regs invalidated by call. */
753 bitmap sparse_invalidated_by_call;
b11550aa 754 /* The set of defs to regs invalidate by call for rd. */
6fb5fa3c
DB
755 bitmap dense_invalidated_by_call;
756 /* An obstack for the bitmaps we need for this problem. */
757 bitmap_obstack rd_bitmaps;
4d779342
DB
758};
759
4d779342
DB
760/* Set basic block info. */
761
762static void
6fb5fa3c 763df_rd_set_bb_info (unsigned int index,
4d779342
DB
764 struct df_rd_bb_info *bb_info)
765{
6fb5fa3c
DB
766 gcc_assert (df_rd);
767 gcc_assert (index < df_rd->block_info_size);
768 df_rd->block_info[index] = bb_info;
4d779342
DB
769}
770
771
772/* Free basic block info. */
773
774static void
6fb5fa3c 775df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 776 void *vbb_info)
4d779342
DB
777{
778 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
779 if (bb_info)
780 {
781 BITMAP_FREE (bb_info->kill);
782 BITMAP_FREE (bb_info->sparse_kill);
783 BITMAP_FREE (bb_info->gen);
784 BITMAP_FREE (bb_info->in);
785 BITMAP_FREE (bb_info->out);
6fb5fa3c 786 pool_free (df_rd->block_pool, bb_info);
4d779342
DB
787 }
788}
789
790
6fb5fa3c 791/* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
4d779342
DB
792 not touched unless the block is new. */
793
794static void
6fb5fa3c 795df_rd_alloc (bitmap all_blocks)
4d779342
DB
796{
797 unsigned int bb_index;
798 bitmap_iterator bi;
6fb5fa3c 799 struct df_rd_problem_data *problem_data;
4d779342 800
6fb5fa3c
DB
801 if (!df_rd->block_pool)
802 df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
4d779342
DB
803 sizeof (struct df_rd_bb_info), 50);
804
6fb5fa3c 805 if (df_rd->problem_data)
4d779342 806 {
6fb5fa3c 807 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342
DB
808 bitmap_clear (problem_data->sparse_invalidated_by_call);
809 bitmap_clear (problem_data->dense_invalidated_by_call);
810 }
811 else
812 {
6fb5fa3c
DB
813 problem_data = XNEW (struct df_rd_problem_data);
814 df_rd->problem_data = problem_data;
815
816 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
817 problem_data->sparse_invalidated_by_call
818 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
819 problem_data->dense_invalidated_by_call
820 = BITMAP_ALLOC (&problem_data->rd_bitmaps);
4d779342
DB
821 }
822
6fb5fa3c 823 df_grow_bb_info (df_rd);
4d779342 824
23249ac4 825 /* Because of the clustering of all use sites for the same pseudo,
4d779342
DB
826 we have to process all of the blocks before doing the
827 analysis. */
828
23249ac4 829 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 830 {
6fb5fa3c 831 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
832 if (bb_info)
833 {
834 bitmap_clear (bb_info->kill);
835 bitmap_clear (bb_info->sparse_kill);
836 bitmap_clear (bb_info->gen);
837 }
838 else
839 {
6fb5fa3c
DB
840 bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
841 df_rd_set_bb_info (bb_index, bb_info);
842 bb_info->kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
843 bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
844 bb_info->gen = BITMAP_ALLOC (&problem_data->rd_bitmaps);
845 bb_info->in = BITMAP_ALLOC (&problem_data->rd_bitmaps);
846 bb_info->out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
4d779342
DB
847 }
848 }
89a95777 849 df_rd->optional_p = true;
4d779342
DB
850}
851
852
853/* Process a list of DEFs for df_rd_bb_local_compute. */
854
855static void
6fb5fa3c
DB
856df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
857 struct df_ref **def_rec,
912f2dac 858 enum df_ref_flags top_flag)
4d779342 859{
6fb5fa3c 860 while (*def_rec)
4d779342 861 {
6fb5fa3c 862 struct df_ref *def = *def_rec;
912f2dac 863 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4d779342 864 {
912f2dac 865 unsigned int regno = DF_REF_REGNO (def);
6fb5fa3c
DB
866 unsigned int begin = DF_DEFS_BEGIN (regno);
867 unsigned int n_defs = DF_DEFS_COUNT (regno);
912f2dac 868
6fb5fa3c
DB
869 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
870 || (regno >= FIRST_PSEUDO_REGISTER))
4d779342 871 {
6fb5fa3c
DB
872 /* Only the last def(s) for a regno in the block has any
873 effect. */
874 if (!bitmap_bit_p (seen_in_block, regno))
4d779342 875 {
6fb5fa3c
DB
876 /* The first def for regno in insn gets to knock out the
877 defs from other instructions. */
878 if ((!bitmap_bit_p (seen_in_insn, regno))
879 /* If the def is to only part of the reg, it does
880 not kill the other defs that reach here. */
881 && (!(DF_REF_FLAGS (def) &
882 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
912f2dac 883 {
6fb5fa3c
DB
884 if (n_defs > DF_SPARSE_THRESHOLD)
885 {
886 bitmap_set_bit (bb_info->sparse_kill, regno);
887 bitmap_clear_range(bb_info->gen, begin, n_defs);
888 }
889 else
890 {
891 bitmap_set_range (bb_info->kill, begin, n_defs);
892 bitmap_clear_range (bb_info->gen, begin, n_defs);
893 }
912f2dac 894 }
6fb5fa3c
DB
895
896 bitmap_set_bit (seen_in_insn, regno);
897 /* All defs for regno in the instruction may be put into
898 the gen set. */
899 if (!(DF_REF_FLAGS (def)
900 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
901 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
4d779342
DB
902 }
903 }
4d779342 904 }
6fb5fa3c 905 def_rec++;
4d779342
DB
906 }
907}
908
909/* Compute local reaching def info for basic block BB. */
910
911static void
6fb5fa3c 912df_rd_bb_local_compute (unsigned int bb_index)
4d779342 913{
4d779342 914 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 915 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
916 rtx insn;
917
918 bitmap_clear (seen_in_block);
919 bitmap_clear (seen_in_insn);
920
6fb5fa3c
DB
921 /* Artificials are only hard regs. */
922 if (!(df->changeable_flags & DF_NO_HARD_REGS))
923 df_rd_bb_local_compute_process_def (bb_info,
924 df_get_artificial_defs (bb_index),
925 0);
912f2dac 926
4d779342
DB
927 FOR_BB_INSNS_REVERSE (bb, insn)
928 {
929 unsigned int uid = INSN_UID (insn);
930
23249ac4 931 if (!INSN_P (insn))
4d779342
DB
932 continue;
933
6fb5fa3c
DB
934 df_rd_bb_local_compute_process_def (bb_info,
935 DF_INSN_UID_DEFS (uid), 0);
4d779342
DB
936
937 /* This complex dance with the two bitmaps is required because
938 instructions can assign twice to the same pseudo. This
939 generally happens with calls that will have one def for the
940 result and another def for the clobber. If only one vector
941 is used and the clobber goes first, the result will be
942 lost. */
943 bitmap_ior_into (seen_in_block, seen_in_insn);
944 bitmap_clear (seen_in_insn);
945 }
946
912f2dac
DB
947 /* Process the artificial defs at the top of the block last since we
948 are going backwards through the block and these are logically at
949 the start. */
6fb5fa3c
DB
950 if (!(df->changeable_flags & DF_NO_HARD_REGS))
951 df_rd_bb_local_compute_process_def (bb_info,
952 df_get_artificial_defs (bb_index),
953 DF_REF_AT_TOP);
4d779342
DB
954}
955
956
957/* Compute local reaching def info for each basic block within BLOCKS. */
958
959static void
6fb5fa3c 960df_rd_local_compute (bitmap all_blocks)
4d779342 961{
4d779342
DB
962 unsigned int bb_index;
963 bitmap_iterator bi;
964 unsigned int regno;
23249ac4 965 struct df_rd_problem_data *problem_data
6fb5fa3c 966 = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342
DB
967 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
968 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
969
970 df_set_seen ();
6fb5fa3c
DB
971
972 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
4d779342
DB
973
974 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
975 {
6fb5fa3c 976 df_rd_bb_local_compute (bb_index);
4d779342
DB
977 }
978
979 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
980 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
981 {
6fb5fa3c
DB
982 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
983 bitmap_set_bit (sparse_invalidated, regno);
4d779342 984 else
6fb5fa3c
DB
985 bitmap_set_range (dense_invalidated,
986 DF_DEFS_BEGIN (regno),
987 DF_DEFS_COUNT (regno));
4d779342
DB
988 }
989 df_unset_seen ();
990}
991
992
993/* Initialize the solution bit vectors for problem. */
994
995static void
6fb5fa3c 996df_rd_init_solution (bitmap all_blocks)
4d779342
DB
997{
998 unsigned int bb_index;
999 bitmap_iterator bi;
1000
1001 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1002 {
6fb5fa3c 1003 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
1004
1005 bitmap_copy (bb_info->out, bb_info->gen);
1006 bitmap_clear (bb_info->in);
1007 }
1008}
1009
1010/* In of target gets or of out of source. */
1011
1012static void
6fb5fa3c 1013df_rd_confluence_n (edge e)
4d779342 1014{
6fb5fa3c
DB
1015 bitmap op1 = df_rd_get_bb_info (e->dest->index)->in;
1016 bitmap op2 = df_rd_get_bb_info (e->src->index)->out;
4d779342
DB
1017
1018 if (e->flags & EDGE_EH)
1019 {
23249ac4 1020 struct df_rd_problem_data *problem_data
6fb5fa3c 1021 = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342
DB
1022 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
1023 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
4d779342
DB
1024 bitmap_iterator bi;
1025 unsigned int regno;
6fb5fa3c 1026 bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
59c52af4
KZ
1027
1028 bitmap_copy (tmp, op2);
1029 bitmap_and_compl_into (tmp, dense_invalidated);
1030
4d779342
DB
1031 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
1032 {
59c52af4 1033 bitmap_clear_range (tmp,
6fb5fa3c
DB
1034 DF_DEFS_BEGIN (regno),
1035 DF_DEFS_COUNT (regno));
4d779342 1036 }
59c52af4
KZ
1037 bitmap_ior_into (op1, tmp);
1038 BITMAP_FREE (tmp);
4d779342
DB
1039 }
1040 else
1041 bitmap_ior_into (op1, op2);
1042}
1043
1044
1045/* Transfer function. */
1046
1047static bool
6fb5fa3c 1048df_rd_transfer_function (int bb_index)
4d779342 1049{
6fb5fa3c 1050 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
1051 unsigned int regno;
1052 bitmap_iterator bi;
1053 bitmap in = bb_info->in;
1054 bitmap out = bb_info->out;
1055 bitmap gen = bb_info->gen;
1056 bitmap kill = bb_info->kill;
1057 bitmap sparse_kill = bb_info->sparse_kill;
1058
1059 if (bitmap_empty_p (sparse_kill))
1060 return bitmap_ior_and_compl (out, gen, in, kill);
1061 else
1062 {
6fb5fa3c 1063 struct df_rd_problem_data *problem_data;
4d779342 1064 bool changed = false;
6fb5fa3c
DB
1065 bitmap tmp;
1066
1067 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
1068 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
1069 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
1070 tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
1071
4d779342
DB
1072 bitmap_copy (tmp, in);
1073 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
1074 {
1075 bitmap_clear_range (tmp,
6fb5fa3c
DB
1076 DF_DEFS_BEGIN (regno),
1077 DF_DEFS_COUNT (regno));
4d779342
DB
1078 }
1079 bitmap_and_compl_into (tmp, kill);
1080 bitmap_ior_into (tmp, gen);
1081 changed = !bitmap_equal_p (tmp, out);
1082 if (changed)
1083 {
1084 BITMAP_FREE (out);
1085 bb_info->out = tmp;
1086 }
1087 else
1088 BITMAP_FREE (tmp);
1089 return changed;
1090 }
1091}
1092
1093
1094/* Free all storage associated with the problem. */
1095
1096static void
6fb5fa3c 1097df_rd_free (void)
4d779342
DB
1098{
1099 unsigned int i;
23249ac4 1100 struct df_rd_problem_data *problem_data
6fb5fa3c 1101 = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342 1102
3b8266e2 1103 if (problem_data)
4d779342 1104 {
6fb5fa3c 1105 for (i = 0; i < df_rd->block_info_size; i++)
4d779342 1106 {
6fb5fa3c 1107 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (i);
3b8266e2
KZ
1108 if (bb_info)
1109 {
1110 BITMAP_FREE (bb_info->kill);
1111 BITMAP_FREE (bb_info->sparse_kill);
1112 BITMAP_FREE (bb_info->gen);
1113 BITMAP_FREE (bb_info->in);
1114 BITMAP_FREE (bb_info->out);
1115 }
4d779342 1116 }
3b8266e2 1117
6fb5fa3c 1118 free_alloc_pool (df_rd->block_pool);
3b8266e2
KZ
1119 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
1120 BITMAP_FREE (problem_data->dense_invalidated_by_call);
6fb5fa3c 1121 bitmap_obstack_release (&problem_data->rd_bitmaps);
3b8266e2 1122
6fb5fa3c
DB
1123 df_rd->block_info_size = 0;
1124 free (df_rd->block_info);
1125 free (df_rd->problem_data);
4d779342 1126 }
6fb5fa3c 1127 free (df_rd);
4d779342
DB
1128}
1129
1130
1131/* Debugging info. */
1132
1133static void
6fb5fa3c 1134df_rd_start_dump (FILE *file)
4d779342 1135{
23249ac4 1136 struct df_rd_problem_data *problem_data
6fb5fa3c
DB
1137 = (struct df_rd_problem_data *) df_rd->problem_data;
1138 unsigned int m = DF_REG_SIZE(df);
4d779342
DB
1139 unsigned int regno;
1140
6fb5fa3c 1141 if (!df_rd->block_info)
23249ac4
DB
1142 return;
1143
6fb5fa3c 1144 fprintf (file, ";; Reaching defs:\n\n");
4d779342
DB
1145
1146 fprintf (file, " sparse invalidated \t");
1147 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
1148 fprintf (file, " dense invalidated \t");
1149 dump_bitmap (file, problem_data->dense_invalidated_by_call);
1150
1151 for (regno = 0; regno < m; regno++)
6fb5fa3c 1152 if (DF_DEFS_COUNT (regno))
4d779342 1153 fprintf (file, "%d[%d,%d] ", regno,
6fb5fa3c
DB
1154 DF_DEFS_BEGIN (regno),
1155 DF_DEFS_COUNT (regno));
4d779342
DB
1156 fprintf (file, "\n");
1157
6fb5fa3c
DB
1158}
1159
1160
1161/* Debugging info at top of bb. */
1162
1163static void
1164df_rd_top_dump (basic_block bb, FILE *file)
1165{
1166 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
1167 if (!bb_info || !bb_info->in)
1168 return;
1169
1170 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
1171 dump_bitmap (file, bb_info->in);
1172 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
1173 dump_bitmap (file, bb_info->gen);
1174 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
1175 dump_bitmap (file, bb_info->kill);
1176}
1177
1178
1179/* Debugging info at top of bb. */
1180
1181static void
1182df_rd_bottom_dump (basic_block bb, FILE *file)
1183{
1184 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
1185 if (!bb_info || !bb_info->out)
1186 return;
1187
1188 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
1189 dump_bitmap (file, bb_info->out);
4d779342
DB
1190}
1191
1192/* All of the information associated with every instance of the problem. */
1193
1194static struct df_problem problem_RD =
1195{
1196 DF_RD, /* Problem id. */
1197 DF_FORWARD, /* Direction. */
1198 df_rd_alloc, /* Allocate the problem specific data. */
30cb87a0 1199 NULL, /* Reset global information. */
4d779342
DB
1200 df_rd_free_bb_info, /* Free basic block info. */
1201 df_rd_local_compute, /* Local compute function. */
1202 df_rd_init_solution, /* Init the solution specific data. */
6fb5fa3c 1203 df_worklist_dataflow, /* Worklist solver. */
4d779342
DB
1204 NULL, /* Confluence operator 0. */
1205 df_rd_confluence_n, /* Confluence operator n. */
1206 df_rd_transfer_function, /* Transfer function. */
1207 NULL, /* Finalize function. */
1208 df_rd_free, /* Free all of the problem information. */
6fb5fa3c
DB
1209 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
1210 df_rd_start_dump, /* Debugging. */
1211 df_rd_top_dump, /* Debugging start block. */
1212 df_rd_bottom_dump, /* Debugging end block. */
1213 NULL, /* Incremental solution verify start. */
1214 NULL, /* Incremental solution verfiy end. */
23249ac4 1215 NULL, /* Dependent problem. */
89a95777
KZ
1216 TV_DF_RD, /* Timing variable. */
1217 true /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
1218};
1219
1220
1221
1222/* Create a new DATAFLOW instance and add it to an existing instance
1223 of DF. The returned structure is what is used to get at the
1224 solution. */
1225
6fb5fa3c
DB
1226void
1227df_rd_add_problem (void)
4d779342 1228{
6fb5fa3c 1229 df_add_problem (&problem_RD);
4d779342
DB
1230}
1231
1232
1233\f
1234/*----------------------------------------------------------------------------
1235 LIVE REGISTERS
1236
b11550aa
KZ
1237 Find the locations in the function where any use of a pseudo can
1238 reach in the backwards direction. In and out bitvectors are built
1239 for each basic block. The regnum is used to index into these sets.
1240 See df.h for details.
1241 ----------------------------------------------------------------------------*/
4d779342 1242
6fb5fa3c
DB
1243/* Private data used to verify the solution for this problem. */
1244struct df_lr_problem_data
4d779342 1245{
6fb5fa3c
DB
1246 bitmap *in;
1247 bitmap *out;
1248};
4d779342
DB
1249
1250
1251/* Set basic block info. */
1252
1253static void
6fb5fa3c 1254df_lr_set_bb_info (unsigned int index,
4d779342
DB
1255 struct df_lr_bb_info *bb_info)
1256{
6fb5fa3c
DB
1257 gcc_assert (df_lr);
1258 gcc_assert (index < df_lr->block_info_size);
1259 df_lr->block_info[index] = bb_info;
4d779342
DB
1260}
1261
1262
1263/* Free basic block info. */
1264
1265static void
6fb5fa3c 1266df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 1267 void *vbb_info)
4d779342
DB
1268{
1269 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
1270 if (bb_info)
1271 {
1272 BITMAP_FREE (bb_info->use);
1273 BITMAP_FREE (bb_info->def);
6fb5fa3c
DB
1274 if (bb_info->in == bb_info->top)
1275 bb_info->top = NULL;
1276 else
1277 {
1278 BITMAP_FREE (bb_info->top);
1279 BITMAP_FREE (bb_info->ause);
1280 BITMAP_FREE (bb_info->adef);
1281 }
4d779342
DB
1282 BITMAP_FREE (bb_info->in);
1283 BITMAP_FREE (bb_info->out);
6fb5fa3c 1284 pool_free (df_lr->block_pool, bb_info);
4d779342
DB
1285 }
1286}
1287
1288
6fb5fa3c 1289/* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
4d779342
DB
1290 not touched unless the block is new. */
1291
1292static void
6fb5fa3c 1293df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342
DB
1294{
1295 unsigned int bb_index;
1296 bitmap_iterator bi;
1297
6fb5fa3c
DB
1298 if (!df_lr->block_pool)
1299 df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
4d779342
DB
1300 sizeof (struct df_lr_bb_info), 50);
1301
6fb5fa3c 1302 df_grow_bb_info (df_lr);
4d779342 1303
6fb5fa3c 1304 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
4d779342 1305 {
6fb5fa3c 1306 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342
DB
1307 if (bb_info)
1308 {
1309 bitmap_clear (bb_info->def);
1310 bitmap_clear (bb_info->use);
6fb5fa3c
DB
1311 if (bb_info->adef)
1312 {
1313 bitmap_clear (bb_info->adef);
1314 bitmap_clear (bb_info->ause);
1315 }
4d779342
DB
1316 }
1317 else
1318 {
6fb5fa3c
DB
1319 bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
1320 df_lr_set_bb_info (bb_index, bb_info);
4d779342
DB
1321 bb_info->use = BITMAP_ALLOC (NULL);
1322 bb_info->def = BITMAP_ALLOC (NULL);
1323 bb_info->in = BITMAP_ALLOC (NULL);
1324 bb_info->out = BITMAP_ALLOC (NULL);
6fb5fa3c
DB
1325 bb_info->top = bb_info->in;
1326 bb_info->adef = NULL;
1327 bb_info->ause = NULL;
4d779342
DB
1328 }
1329 }
89a95777
KZ
1330
1331 df_lr->optional_p = false;
4d779342
DB
1332}
1333
1334
6fb5fa3c
DB
1335/* Reset the global solution for recalculation. */
1336
1337static void
1338df_lr_reset (bitmap all_blocks)
1339{
1340 unsigned int bb_index;
1341 bitmap_iterator bi;
1342
1343 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1344 {
1345 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
1346 gcc_assert (bb_info);
1347 bitmap_clear (bb_info->in);
1348 bitmap_clear (bb_info->out);
1349 bitmap_clear (bb_info->top);
1350 }
1351}
1352
1353
4d779342
DB
1354/* Compute local live register info for basic block BB. */
1355
1356static void
6fb5fa3c 1357df_lr_bb_local_compute (unsigned int bb_index)
4d779342
DB
1358{
1359 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 1360 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342 1361 rtx insn;
6fb5fa3c
DB
1362 struct df_ref **def_rec;
1363 struct df_ref **use_rec;
4d779342 1364
912f2dac 1365 /* Process the registers set in an exception handler. */
6fb5fa3c
DB
1366 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1367 {
1368 struct df_ref *def = *def_rec;
1369 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
1370 {
1371 unsigned int dregno = DF_REF_REGNO (def);
1372 bitmap_set_bit (bb_info->def, dregno);
1373 bitmap_clear_bit (bb_info->use, dregno);
1374 }
1375 }
912f2dac 1376
4d779342 1377 /* Process the hardware registers that are always live. */
6fb5fa3c
DB
1378 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
1379 {
1380 struct df_ref *use = *use_rec;
1381 /* Add use to set of uses in this BB. */
1382 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
1383 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1384 }
4d779342
DB
1385
1386 FOR_BB_INSNS_REVERSE (bb, insn)
1387 {
1388 unsigned int uid = INSN_UID (insn);
1389
23249ac4 1390 if (!INSN_P (insn))
4d779342
DB
1391 continue;
1392
1393 if (CALL_P (insn))
1394 {
6fb5fa3c 1395 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 1396 {
6fb5fa3c 1397 struct df_ref *def = *def_rec;
4d779342
DB
1398 unsigned int dregno = DF_REF_REGNO (def);
1399
6fb5fa3c 1400 if (DF_REF_FLAGS (def) & DF_REF_MUST_CLOBBER)
4d779342 1401 {
6fb5fa3c
DB
1402 if (dregno >= FIRST_PSEUDO_REGISTER
1403 || !(SIBLING_CALL_P (insn)
1404 && bitmap_bit_p (df->exit_block_uses, dregno)
1405 && !refers_to_regno_p (dregno, dregno+1,
1406 current_function_return_rtx,
1407 (rtx *)0)))
23249ac4 1408 {
6fb5fa3c
DB
1409 /* If the def is to only part of the reg, it does
1410 not kill the other defs that reach here. */
1411 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
1412 {
1413 bitmap_set_bit (bb_info->def, dregno);
1414 bitmap_clear_bit (bb_info->use, dregno);
1415 }
23249ac4 1416 }
4d779342 1417 }
6fb5fa3c
DB
1418 else
1419 /* This is the return value. */
1420 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
1421 {
1422 bitmap_set_bit (bb_info->def, dregno);
1423 bitmap_clear_bit (bb_info->use, dregno);
1424 }
4d779342
DB
1425 }
1426 }
1427 else
1428 {
6fb5fa3c 1429 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 1430 {
6fb5fa3c 1431 struct df_ref *def = *def_rec;
23249ac4
DB
1432 /* If the def is to only part of the reg, it does
1433 not kill the other defs that reach here. */
6fb5fa3c 1434 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
23249ac4 1435 {
6fb5fa3c 1436 unsigned int dregno = DF_REF_REGNO (def);
23249ac4
DB
1437 bitmap_set_bit (bb_info->def, dregno);
1438 bitmap_clear_bit (bb_info->use, dregno);
1439 }
4d779342
DB
1440 }
1441 }
1442
6fb5fa3c
DB
1443 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
1444 {
1445 struct df_ref *use = *use_rec;
1446 /* Add use to set of uses in this BB. */
1447 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1448 }
4d779342 1449 }
4d779342 1450 /* Process the registers set in an exception handler. */
6fb5fa3c
DB
1451 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
1452 {
1453 struct df_ref *def = *def_rec;
1454 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP)
1455 && (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))))
1456 {
1457 unsigned int dregno = DF_REF_REGNO (def);
1458 if (bb_info->adef == NULL)
1459 {
1460 gcc_assert (bb_info->ause == NULL);
1461 gcc_assert (bb_info->top == bb_info->in);
1462 bb_info->adef = BITMAP_ALLOC (NULL);
1463 bb_info->ause = BITMAP_ALLOC (NULL);
1464 bb_info->top = BITMAP_ALLOC (NULL);
1465 }
1466 bitmap_set_bit (bb_info->adef, dregno);
1467 }
1468 }
912f2dac 1469
4d779342
DB
1470#ifdef EH_USES
1471 /* Process the uses that are live into an exception handler. */
6fb5fa3c
DB
1472 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
1473 {
1474 struct df_ref *use = *use_rec;
1475 /* Add use to set of uses in this BB. */
1476 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
1477 {
1478 if (bb_info->adef == NULL)
1479 {
1480 gcc_assert (bb_info->ause == NULL);
1481 gcc_assert (bb_info->top == bb_info->in);
1482 bb_info->adef = BITMAP_ALLOC (NULL);
1483 bb_info->ause = BITMAP_ALLOC (NULL);
1484 bb_info->top = BITMAP_ALLOC (NULL);
1485 }
1486 bitmap_set_bit (bb_info->ause, DF_REF_REGNO (use));
1487 }
1488 }
4d779342 1489#endif
89a95777
KZ
1490
1491 /* If the df_live problem is not defined, such as at -O0 and -O1, we
1492 still need to keep the luids up to date. This is normally done
1493 in the df_live problem since this problem has a forwards
1494 scan. */
1495 if (!df_live)
1496 df_recompute_luids (bb);
4d779342
DB
1497}
1498
23249ac4 1499
4d779342
DB
1500/* Compute local live register info for each basic block within BLOCKS. */
1501
1502static void
6fb5fa3c 1503df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342 1504{
4d779342
DB
1505 unsigned int bb_index;
1506 bitmap_iterator bi;
1507
4d779342
DB
1508 bitmap_clear (df->hardware_regs_used);
1509
1510 /* The all-important stack pointer must always be live. */
1511 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
1512
1513 /* Before reload, there are a few registers that must be forced
1514 live everywhere -- which might not already be the case for
1515 blocks within infinite loops. */
23249ac4 1516 if (!reload_completed)
4d779342
DB
1517 {
1518 /* Any reference to any pseudo before reload is a potential
1519 reference of the frame pointer. */
1520 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
1521
1522#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1523 /* Pseudos with argument area equivalences may require
1524 reloading via the argument pointer. */
1525 if (fixed_regs[ARG_POINTER_REGNUM])
1526 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
1527#endif
1528
1529 /* Any constant, or pseudo with constant equivalences, may
1530 require reloading from memory using the pic register. */
1531 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
1532 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
1533 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
1534 }
1535
6fb5fa3c 1536 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
4d779342
DB
1537 {
1538 if (bb_index == EXIT_BLOCK)
6fb5fa3c
DB
1539 {
1540 /* The exit block is special for this problem and its bits are
1541 computed from thin air. */
1542 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
1543 bitmap_copy (bb_info->use, df->exit_block_uses);
1544 }
1545 else
1546 df_lr_bb_local_compute (bb_index);
4d779342 1547 }
6fb5fa3c
DB
1548
1549 bitmap_clear (df_lr->out_of_date_transfer_functions);
4d779342
DB
1550}
1551
1552
1553/* Initialize the solution vectors. */
1554
1555static void
6fb5fa3c 1556df_lr_init (bitmap all_blocks)
4d779342
DB
1557{
1558 unsigned int bb_index;
1559 bitmap_iterator bi;
1560
1561 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1562 {
6fb5fa3c 1563 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342
DB
1564 bitmap_copy (bb_info->in, bb_info->use);
1565 bitmap_clear (bb_info->out);
1566 }
1567}
1568
1569
1570/* Confluence function that processes infinite loops. This might be a
1571 noreturn function that throws. And even if it isn't, getting the
1572 unwind info right helps debugging. */
1573static void
6fb5fa3c 1574df_lr_confluence_0 (basic_block bb)
4d779342 1575{
6fb5fa3c 1576 bitmap op1 = df_lr_get_bb_info (bb->index)->out;
4d779342
DB
1577 if (bb != EXIT_BLOCK_PTR)
1578 bitmap_copy (op1, df->hardware_regs_used);
1579}
1580
1581
1582/* Confluence function that ignores fake edges. */
23249ac4 1583
4d779342 1584static void
6fb5fa3c 1585df_lr_confluence_n (edge e)
4d779342 1586{
6fb5fa3c
DB
1587 bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
1588 bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
4d779342
DB
1589
1590 /* Call-clobbered registers die across exception and call edges. */
1591 /* ??? Abnormal call edges ignored for the moment, as this gets
1592 confused by sibling call edges, which crashes reg-stack. */
1593 if (e->flags & EDGE_EH)
1594 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
1595 else
1596 bitmap_ior_into (op1, op2);
1597
6fb5fa3c 1598 bitmap_ior_into (op1, df->hardware_regs_used);
4d779342
DB
1599}
1600
1601
1602/* Transfer function. */
23249ac4 1603
4d779342 1604static bool
6fb5fa3c 1605df_lr_transfer_function (int bb_index)
4d779342 1606{
6fb5fa3c 1607 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342
DB
1608 bitmap in = bb_info->in;
1609 bitmap out = bb_info->out;
1610 bitmap use = bb_info->use;
1611 bitmap def = bb_info->def;
6fb5fa3c
DB
1612 bitmap top = bb_info->top;
1613 bitmap ause = bb_info->ause;
1614 bitmap adef = bb_info->adef;
1615 bool changed;
1616
1617 changed = bitmap_ior_and_compl (top, use, out, def);
1618 if (in != top)
1619 {
1620 gcc_assert (ause && adef);
1621 changed |= bitmap_ior_and_compl (in, ause, top, adef);
1622 }
1623
1624 return changed;
1625}
1626
4d779342 1627
6fb5fa3c
DB
1628/* Run the fast dce as a side effect of building LR. */
1629
1630static void
1631df_lr_local_finalize (bitmap all_blocks ATTRIBUTE_UNUSED)
1632{
1633 if (df->changeable_flags & DF_LR_RUN_DCE)
1634 {
1635 run_fast_df_dce ();
1636 if (df_lr->problem_data && df_lr->solutions_dirty)
1637 {
1638 /* If we are here, then it is because we are both verifying
1639 the solution and the dce changed the function. In that case
1640 the verification info built will be wrong. So we leave the
1641 dirty flag true so that the verifier will skip the checking
1642 part and just clean up.*/
1643 df_lr->solutions_dirty = true;
1644 }
1645 else
1646 df_lr->solutions_dirty = false;
1647 }
1648 else
1649 df_lr->solutions_dirty = false;
4d779342
DB
1650}
1651
1652
1653/* Free all storage associated with the problem. */
1654
1655static void
6fb5fa3c 1656df_lr_free (void)
4d779342 1657{
6fb5fa3c 1658 if (df_lr->block_info)
4d779342 1659 {
3b8266e2 1660 unsigned int i;
6fb5fa3c 1661 for (i = 0; i < df_lr->block_info_size; i++)
4d779342 1662 {
6fb5fa3c 1663 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
3b8266e2
KZ
1664 if (bb_info)
1665 {
1666 BITMAP_FREE (bb_info->use);
1667 BITMAP_FREE (bb_info->def);
6fb5fa3c
DB
1668 if (bb_info->in == bb_info->top)
1669 bb_info->top = NULL;
1670 else
1671 {
1672 BITMAP_FREE (bb_info->top);
1673 BITMAP_FREE (bb_info->ause);
1674 BITMAP_FREE (bb_info->adef);
1675 }
3b8266e2
KZ
1676 BITMAP_FREE (bb_info->in);
1677 BITMAP_FREE (bb_info->out);
1678 }
4d779342 1679 }
6fb5fa3c 1680 free_alloc_pool (df_lr->block_pool);
3b8266e2 1681
6fb5fa3c
DB
1682 df_lr->block_info_size = 0;
1683 free (df_lr->block_info);
4d779342 1684 }
23249ac4 1685
6fb5fa3c
DB
1686 BITMAP_FREE (df_lr->out_of_date_transfer_functions);
1687 free (df_lr);
4d779342
DB
1688}
1689
1690
6fb5fa3c 1691/* Debugging info at top of bb. */
4d779342
DB
1692
1693static void
6fb5fa3c 1694df_lr_top_dump (basic_block bb, FILE *file)
4d779342 1695{
6fb5fa3c
DB
1696 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1697 struct df_lr_problem_data *problem_data;
1698 if (!bb_info || !bb_info->in)
1699 return;
1700
1701 fprintf (file, ";; lr in \t");
1702 df_print_regset (file, bb_info->in);
1703 if (df_lr->problem_data)
1704 {
1705 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1706 fprintf (file, ";; old in \t");
1707 df_print_regset (file, problem_data->in[bb->index]);
1708 }
1709 fprintf (file, ";; lr use \t");
1710 df_print_regset (file, bb_info->use);
1711 fprintf (file, ";; lr def \t");
1712 df_print_regset (file, bb_info->def);
1713}
1714
1715
1716/* Debugging info at bottom of bb. */
1717
1718static void
1719df_lr_bottom_dump (basic_block bb, FILE *file)
1720{
1721 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1722 struct df_lr_problem_data *problem_data;
1723 if (!bb_info || !bb_info->out)
1724 return;
4d779342 1725
6fb5fa3c
DB
1726 fprintf (file, ";; lr out \t");
1727 df_print_regset (file, bb_info->out);
1728 if (df_lr->problem_data)
1729 {
1730 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1731 fprintf (file, ";; old out \t");
1732 df_print_regset (file, problem_data->out[bb->index]);
1733 }
1734}
1735
1736
1737/* Build the datastructure to verify that the solution to the dataflow
1738 equations is not dirty. */
1739
1740static void
1741df_lr_verify_solution_start (void)
1742{
1743 basic_block bb;
1744 struct df_lr_problem_data *problem_data;
1745 if (df_lr->solutions_dirty)
1746 {
1747 df_lr->problem_data = NULL;
1748 return;
1749 }
1750
1751 /* Set it true so that the solution is recomputed. */
1752 df_lr->solutions_dirty = true;
1753
1754 problem_data = XNEW (struct df_lr_problem_data);
1755 df_lr->problem_data = problem_data;
1756 problem_data->in = XNEWVEC (bitmap, last_basic_block);
1757 problem_data->out = XNEWVEC (bitmap, last_basic_block);
1758
1759 FOR_ALL_BB (bb)
1760 {
1761 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
1762 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
1763 bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
1764 bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
1765 }
1766}
1767
1768
1769/* Compare the saved datastructure and the new solution to the dataflow
1770 equations. */
1771
1772static void
1773df_lr_verify_solution_end (void)
1774{
1775 struct df_lr_problem_data *problem_data;
1776 basic_block bb;
1777
1778 if (df_lr->problem_data == NULL)
23249ac4
DB
1779 return;
1780
6fb5fa3c
DB
1781 problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
1782
1783 if (df_lr->solutions_dirty)
1784 /* Do not check if the solution is still dirty. See the comment
1785 in df_lr_local_finalize for details. */
1786 df_lr->solutions_dirty = false;
1787 else
1788 FOR_ALL_BB (bb)
1789 {
1790 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
1791 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
1792 {
1793 /*df_dump (stderr);*/
1794 gcc_unreachable ();
1795 }
1796 }
1797
1798 /* Cannot delete them immediately because you may want to dump them
1799 if the comparison fails. */
4d779342
DB
1800 FOR_ALL_BB (bb)
1801 {
6fb5fa3c
DB
1802 BITMAP_FREE (problem_data->in[bb->index]);
1803 BITMAP_FREE (problem_data->out[bb->index]);
4d779342 1804 }
6fb5fa3c
DB
1805
1806 free (problem_data->in);
1807 free (problem_data->out);
1808 free (problem_data);
1809 df_lr->problem_data = NULL;
4d779342
DB
1810}
1811
6fb5fa3c 1812
4d779342
DB
1813/* All of the information associated with every instance of the problem. */
1814
1815static struct df_problem problem_LR =
1816{
1817 DF_LR, /* Problem id. */
1818 DF_BACKWARD, /* Direction. */
1819 df_lr_alloc, /* Allocate the problem specific data. */
6fb5fa3c 1820 df_lr_reset, /* Reset global information. */
4d779342
DB
1821 df_lr_free_bb_info, /* Free basic block info. */
1822 df_lr_local_compute, /* Local compute function. */
1823 df_lr_init, /* Init the solution specific data. */
6fb5fa3c 1824 df_worklist_dataflow, /* Worklist solver. */
4d779342
DB
1825 df_lr_confluence_0, /* Confluence operator 0. */
1826 df_lr_confluence_n, /* Confluence operator n. */
1827 df_lr_transfer_function, /* Transfer function. */
6fb5fa3c 1828 df_lr_local_finalize, /* Finalize function. */
4d779342 1829 df_lr_free, /* Free all of the problem information. */
6fb5fa3c
DB
1830 NULL, /* Remove this problem from the stack of dataflow problems. */
1831 NULL, /* Debugging. */
1832 df_lr_top_dump, /* Debugging start block. */
1833 df_lr_bottom_dump, /* Debugging end block. */
1834 df_lr_verify_solution_start,/* Incremental solution verify start. */
1835 df_lr_verify_solution_end, /* Incremental solution verify end. */
23249ac4 1836 NULL, /* Dependent problem. */
89a95777
KZ
1837 TV_DF_LR, /* Timing variable. */
1838 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
1839};
1840
1841
1842/* Create a new DATAFLOW instance and add it to an existing instance
1843 of DF. The returned structure is what is used to get at the
1844 solution. */
1845
6fb5fa3c
DB
1846void
1847df_lr_add_problem (void)
1848{
1849 df_add_problem (&problem_LR);
1850 /* These will be initialized when df_scan_blocks processes each
1851 block. */
1852 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1853}
1854
1855
1856/* Verify that all of the lr related info is consistent and
1857 correct. */
1858
1859void
1860df_lr_verify_transfer_functions (void)
4d779342 1861{
6fb5fa3c
DB
1862 basic_block bb;
1863 bitmap saved_def;
1864 bitmap saved_use;
1865 bitmap saved_adef;
1866 bitmap saved_ause;
1867 bitmap all_blocks;
1868 bool need_as;
1869
1870 if (!df)
1871 return;
1872
1873 saved_def = BITMAP_ALLOC (NULL);
1874 saved_use = BITMAP_ALLOC (NULL);
1875 saved_adef = BITMAP_ALLOC (NULL);
1876 saved_ause = BITMAP_ALLOC (NULL);
1877 all_blocks = BITMAP_ALLOC (NULL);
1878
1879 FOR_ALL_BB (bb)
1880 {
1881 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
1882 bitmap_set_bit (all_blocks, bb->index);
1883
1884 if (bb_info)
1885 {
1886 /* Make a copy of the transfer functions and then compute
1887 new ones to see if the transfer functions have
1888 changed. */
1889 if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1890 bb->index))
1891 {
1892 bitmap_copy (saved_def, bb_info->def);
1893 bitmap_copy (saved_use, bb_info->use);
1894 bitmap_clear (bb_info->def);
1895 bitmap_clear (bb_info->use);
1896
1897 if (bb_info->adef)
1898 {
1899 need_as = true;
1900 bitmap_copy (saved_adef, bb_info->adef);
1901 bitmap_copy (saved_ause, bb_info->ause);
1902 bitmap_clear (bb_info->adef);
1903 bitmap_clear (bb_info->ause);
1904 }
1905 else
1906 need_as = false;
1907
1908 df_lr_bb_local_compute (bb->index);
1909 gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
1910 gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
1911
1912 if (need_as)
1913 {
1914 gcc_assert (bb_info->adef);
1915 gcc_assert (bb_info->ause);
1916 gcc_assert (bitmap_equal_p (saved_adef, bb_info->adef));
1917 gcc_assert (bitmap_equal_p (saved_ause, bb_info->ause));
1918 }
1919 else
1920 {
1921 gcc_assert (!bb_info->adef);
1922 gcc_assert (!bb_info->ause);
1923 }
1924 }
1925 }
1926 else
1927 {
1928 /* If we do not have basic block info, the block must be in
1929 the list of dirty blocks or else some one has added a
1930 block behind our backs. */
1931 gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
1932 bb->index));
1933 }
1934 /* Make sure no one created a block without following
1935 procedures. */
1936 gcc_assert (df_scan_get_bb_info (bb->index));
1937 }
1938
1939 /* Make sure there are no dirty bits in blocks that have been deleted. */
1940 gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
1941 all_blocks));
1942
1943 BITMAP_FREE (saved_def);
1944 BITMAP_FREE (saved_use);
1945 BITMAP_FREE (saved_adef);
1946 BITMAP_FREE (saved_ause);
1947 BITMAP_FREE (all_blocks);
4d779342
DB
1948}
1949
1950
1951\f
1952/*----------------------------------------------------------------------------
6fb5fa3c 1953 COMBINED LIVE REGISTERS AND UNINITIALIZED REGISTERS.
4d779342 1954
6fb5fa3c
DB
1955 First find the set of uses for registers that are reachable from
1956 the entry block without passing thru a definition. In and out
1957 bitvectors are built for each basic block. The regnum is used to
1958 index into these sets. See df.h for details.
4d779342 1959
6fb5fa3c
DB
1960 Then the in and out sets here are the anded results of the in and
1961 out sets from the lr and ur
1962 problems.
1963----------------------------------------------------------------------------*/
4d779342 1964
6fb5fa3c
DB
1965/* Private data used to verify the solution for this problem. */
1966struct df_live_problem_data
4d779342 1967{
6fb5fa3c
DB
1968 bitmap *in;
1969 bitmap *out;
1970};
4d779342
DB
1971
1972
1973/* Set basic block info. */
1974
1975static void
6fb5fa3c
DB
1976df_live_set_bb_info (unsigned int index,
1977 struct df_live_bb_info *bb_info)
4d779342 1978{
6fb5fa3c
DB
1979 gcc_assert (df_live);
1980 gcc_assert (index < df_live->block_info_size);
1981 df_live->block_info[index] = bb_info;
4d779342
DB
1982}
1983
1984
1985/* Free basic block info. */
1986
1987static void
6fb5fa3c 1988df_live_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 1989 void *vbb_info)
4d779342 1990{
6fb5fa3c 1991 struct df_live_bb_info *bb_info = (struct df_live_bb_info *) vbb_info;
4d779342
DB
1992 if (bb_info)
1993 {
1994 BITMAP_FREE (bb_info->gen);
1995 BITMAP_FREE (bb_info->kill);
1996 BITMAP_FREE (bb_info->in);
1997 BITMAP_FREE (bb_info->out);
6fb5fa3c 1998 pool_free (df_live->block_pool, bb_info);
4d779342
DB
1999 }
2000}
2001
2002
6fb5fa3c 2003/* Allocate or reset bitmaps for DF_LIVE blocks. The solution bits are
4d779342
DB
2004 not touched unless the block is new. */
2005
2006static void
6fb5fa3c 2007df_live_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342
DB
2008{
2009 unsigned int bb_index;
2010 bitmap_iterator bi;
2011
6fb5fa3c
DB
2012 if (!df_live->block_pool)
2013 df_live->block_pool = create_alloc_pool ("df_live_block pool",
2014 sizeof (struct df_live_bb_info), 100);
4d779342 2015
6fb5fa3c 2016 df_grow_bb_info (df_live);
4d779342 2017
6fb5fa3c 2018 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions, 0, bb_index, bi)
4d779342 2019 {
6fb5fa3c 2020 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342
DB
2021 if (bb_info)
2022 {
2023 bitmap_clear (bb_info->kill);
2024 bitmap_clear (bb_info->gen);
2025 }
2026 else
2027 {
6fb5fa3c
DB
2028 bb_info = (struct df_live_bb_info *) pool_alloc (df_live->block_pool);
2029 df_live_set_bb_info (bb_index, bb_info);
4d779342
DB
2030 bb_info->kill = BITMAP_ALLOC (NULL);
2031 bb_info->gen = BITMAP_ALLOC (NULL);
2032 bb_info->in = BITMAP_ALLOC (NULL);
2033 bb_info->out = BITMAP_ALLOC (NULL);
2034 }
2035 }
89a95777 2036 df_live->optional_p = (optimize <= 1);
4d779342
DB
2037}
2038
2039
6fb5fa3c
DB
2040/* Reset the global solution for recalculation. */
2041
2042static void
2043df_live_reset (bitmap all_blocks)
2044{
2045 unsigned int bb_index;
2046 bitmap_iterator bi;
2047
2048 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2049 {
2050 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
2051 gcc_assert (bb_info);
2052 bitmap_clear (bb_info->in);
2053 bitmap_clear (bb_info->out);
2054 }
2055}
2056
2057
4d779342
DB
2058/* Compute local uninitialized register info for basic block BB. */
2059
2060static void
6fb5fa3c 2061df_live_bb_local_compute (unsigned int bb_index)
4d779342 2062{
4d779342 2063 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 2064 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342 2065 rtx insn;
6fb5fa3c
DB
2066 struct df_ref **def_rec;
2067 int luid = 0;
4d779342 2068
6fb5fa3c
DB
2069 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2070 {
2071 struct df_ref *def = *def_rec;
2072 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2073 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
2074 }
912f2dac 2075
6fb5fa3c 2076 FOR_BB_INSNS (bb, insn)
4d779342
DB
2077 {
2078 unsigned int uid = INSN_UID (insn);
6fb5fa3c
DB
2079 struct df_insn_info *insn_info = DF_INSN_UID_GET (uid);
2080
2081 /* Inserting labels does not always trigger the incremental
2082 rescanning. */
2083 if (!insn_info)
2084 {
2085 gcc_assert (!INSN_P (insn));
2086 df_insn_create_insn_record (insn);
2087 }
2088
2089 DF_INSN_LUID (insn) = luid;
4d779342
DB
2090 if (!INSN_P (insn))
2091 continue;
2092
6fb5fa3c
DB
2093 luid++;
2094 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 2095 {
6fb5fa3c 2096 struct df_ref *def = *def_rec;
4d779342 2097 unsigned int regno = DF_REF_REGNO (def);
6fb5fa3c
DB
2098
2099 if (DF_REF_FLAGS_IS_SET (def,
2100 DF_REF_PARTIAL | DF_REF_CONDITIONAL))
2101 /* All partial or conditional def
2102 seen are included in the gen set. */
2103 bitmap_set_bit (bb_info->gen, regno);
2104 else if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
2105 /* Only must clobbers for the entire reg destroy the
2106 value. */
2107 bitmap_set_bit (bb_info->kill, regno);
2108 else if (! DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
2109 bitmap_set_bit (bb_info->gen, regno);
4d779342 2110 }
4d779342
DB
2111 }
2112
6fb5fa3c
DB
2113 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2114 {
2115 struct df_ref *def = *def_rec;
2116 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2117 bitmap_set_bit (bb_info->gen, DF_REF_REGNO (def));
2118 }
4d779342
DB
2119}
2120
2121
2122/* Compute local uninitialized register info. */
2123
2124static void
6fb5fa3c 2125df_live_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342
DB
2126{
2127 unsigned int bb_index;
2128 bitmap_iterator bi;
2129
6fb5fa3c 2130 df_grow_insn_info ();
4d779342 2131
6fb5fa3c
DB
2132 EXECUTE_IF_SET_IN_BITMAP (df_live->out_of_date_transfer_functions,
2133 0, bb_index, bi)
4d779342 2134 {
6fb5fa3c 2135 df_live_bb_local_compute (bb_index);
4d779342
DB
2136 }
2137
6fb5fa3c 2138 bitmap_clear (df_live->out_of_date_transfer_functions);
4d779342
DB
2139}
2140
2141
2142/* Initialize the solution vectors. */
2143
2144static void
6fb5fa3c 2145df_live_init (bitmap all_blocks)
4d779342
DB
2146{
2147 unsigned int bb_index;
2148 bitmap_iterator bi;
2149
2150 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2151 {
6fb5fa3c 2152 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342
DB
2153
2154 bitmap_copy (bb_info->out, bb_info->gen);
2155 bitmap_clear (bb_info->in);
2156 }
2157}
2158
4d779342
DB
2159/* Confluence function that ignores fake edges. */
2160
2161static void
6fb5fa3c 2162df_live_confluence_n (edge e)
4d779342 2163{
6fb5fa3c
DB
2164 bitmap op1 = df_live_get_bb_info (e->dest->index)->in;
2165 bitmap op2 = df_live_get_bb_info (e->src->index)->out;
4d779342
DB
2166
2167 if (e->flags & EDGE_FAKE)
2168 return;
2169
2170 bitmap_ior_into (op1, op2);
2171}
2172
2173
2174/* Transfer function. */
2175
2176static bool
6fb5fa3c 2177df_live_transfer_function (int bb_index)
4d779342 2178{
6fb5fa3c 2179 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
4d779342
DB
2180 bitmap in = bb_info->in;
2181 bitmap out = bb_info->out;
2182 bitmap gen = bb_info->gen;
2183 bitmap kill = bb_info->kill;
2184
2185 return bitmap_ior_and_compl (out, gen, in, kill);
2186}
2187
2188
6fb5fa3c
DB
2189/* And the LR and UR info to produce the LIVE info. */
2190
2191static void
2192df_live_local_finalize (bitmap all_blocks)
2193{
2194
2195 if (df_live->solutions_dirty)
2196 {
2197 bitmap_iterator bi;
2198 unsigned int bb_index;
2199
2200 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2201 {
2202 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
2203 struct df_live_bb_info *bb_live_info = df_live_get_bb_info (bb_index);
2204
2205 /* No register may reach a location where it is not used. Thus
2206 we trim the rr result to the places where it is used. */
2207 bitmap_and_into (bb_live_info->in, bb_lr_info->in);
2208 bitmap_and_into (bb_live_info->out, bb_lr_info->out);
2209 }
2210
2211 df_live->solutions_dirty = false;
2212 }
2213}
2214
2215
4d779342
DB
2216/* Free all storage associated with the problem. */
2217
2218static void
6fb5fa3c 2219df_live_free (void)
4d779342 2220{
6fb5fa3c 2221 if (df_live->block_info)
4d779342 2222 {
3b8266e2
KZ
2223 unsigned int i;
2224
6fb5fa3c 2225 for (i = 0; i < df_live->block_info_size; i++)
4d779342 2226 {
6fb5fa3c 2227 struct df_live_bb_info *bb_info = df_live_get_bb_info (i);
3b8266e2
KZ
2228 if (bb_info)
2229 {
2230 BITMAP_FREE (bb_info->gen);
2231 BITMAP_FREE (bb_info->kill);
2232 BITMAP_FREE (bb_info->in);
2233 BITMAP_FREE (bb_info->out);
2234 }
4d779342 2235 }
3b8266e2 2236
6fb5fa3c
DB
2237 free_alloc_pool (df_live->block_pool);
2238 df_live->block_info_size = 0;
2239 free (df_live->block_info);
4d779342 2240 }
6fb5fa3c
DB
2241 BITMAP_FREE (df_live->out_of_date_transfer_functions);
2242 free (df_live);
4d779342
DB
2243}
2244
2245
6fb5fa3c 2246/* Debugging info at top of bb. */
4d779342
DB
2247
2248static void
6fb5fa3c 2249df_live_top_dump (basic_block bb, FILE *file)
4d779342 2250{
6fb5fa3c
DB
2251 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
2252 struct df_live_problem_data *problem_data;
23249ac4 2253
6fb5fa3c
DB
2254 if (!bb_info || !bb_info->in)
2255 return;
4d779342 2256
6fb5fa3c
DB
2257 fprintf (file, ";; live in \t");
2258 df_print_regset (file, bb_info->in);
2259 if (df_live->problem_data)
2260 {
2261 problem_data = (struct df_live_problem_data *)df_live->problem_data;
2262 fprintf (file, ";; old in \t");
2263 df_print_regset (file, problem_data->in[bb->index]);
4d779342 2264 }
6fb5fa3c
DB
2265 fprintf (file, ";; live gen \t");
2266 df_print_regset (file, bb_info->gen);
2267 fprintf (file, ";; live kill\t");
2268 df_print_regset (file, bb_info->kill);
4d779342
DB
2269}
2270
4d779342 2271
6fb5fa3c
DB
2272/* Debugging info at bottom of bb. */
2273
2274static void
2275df_live_bottom_dump (basic_block bb, FILE *file)
4d779342 2276{
6fb5fa3c
DB
2277 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
2278 struct df_live_problem_data *problem_data;
4d779342 2279
6fb5fa3c
DB
2280 if (!bb_info || !bb_info->out)
2281 return;
2282
2283 fprintf (file, ";; live out \t");
2284 df_print_regset (file, bb_info->out);
2285 if (df_live->problem_data)
2286 {
2287 problem_data = (struct df_live_problem_data *)df_live->problem_data;
2288 fprintf (file, ";; old out \t");
2289 df_print_regset (file, problem_data->out[bb->index]);
2290 }
2291}
4d779342 2292
4d779342 2293
6fb5fa3c
DB
2294/* Build the datastructure to verify that the solution to the dataflow
2295 equations is not dirty. */
2296
2297static void
2298df_live_verify_solution_start (void)
4d779342 2299{
6fb5fa3c
DB
2300 basic_block bb;
2301 struct df_live_problem_data *problem_data;
2302 if (df_live->solutions_dirty)
2303 {
2304 df_live->problem_data = NULL;
2305 return;
2306 }
2307
2308 /* Set it true so that the solution is recomputed. */
2309 df_live->solutions_dirty = true;
2310
2311 problem_data = XNEW (struct df_live_problem_data);
2312 df_live->problem_data = problem_data;
2313 problem_data->in = XNEWVEC (bitmap, last_basic_block);
2314 problem_data->out = XNEWVEC (bitmap, last_basic_block);
2315
2316 FOR_ALL_BB (bb)
2317 {
2318 problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
2319 problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
2320 bitmap_copy (problem_data->in[bb->index], DF_LIVE_IN (bb));
2321 bitmap_copy (problem_data->out[bb->index], DF_LIVE_OUT (bb));
2322 }
4d779342
DB
2323}
2324
2325
6fb5fa3c
DB
2326/* Compare the saved datastructure and the new solution to the dataflow
2327 equations. */
4d779342 2328
6fb5fa3c
DB
2329static void
2330df_live_verify_solution_end (void)
2331{
2332 struct df_live_problem_data *problem_data;
2333 basic_block bb;
2334
2335 if (df_live->problem_data == NULL)
2336 return;
2337
2338 problem_data = (struct df_live_problem_data *)df_live->problem_data;
2339
2340 FOR_ALL_BB (bb)
2341 {
2342 if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LIVE_IN (bb)))
2343 || (!bitmap_equal_p (problem_data->out[bb->index], DF_LIVE_OUT (bb))))
2344 {
2345 /*df_dump (stderr);*/
2346 gcc_unreachable ();
2347 }
2348 }
2349
2350 /* Cannot delete them immediately because you may want to dump them
2351 if the comparison fails. */
2352 FOR_ALL_BB (bb)
2353 {
2354 BITMAP_FREE (problem_data->in[bb->index]);
2355 BITMAP_FREE (problem_data->out[bb->index]);
2356 }
2357
2358 free (problem_data->in);
2359 free (problem_data->out);
2360 free (problem_data);
2361 df_live->problem_data = NULL;
2362}
2363
2364
2365/* All of the information associated with every instance of the problem. */
2366
2367static struct df_problem problem_LIVE =
2368{
2369 DF_LIVE, /* Problem id. */
2370 DF_FORWARD, /* Direction. */
2371 df_live_alloc, /* Allocate the problem specific data. */
2372 df_live_reset, /* Reset global information. */
2373 df_live_free_bb_info, /* Free basic block info. */
2374 df_live_local_compute, /* Local compute function. */
2375 df_live_init, /* Init the solution specific data. */
2376 df_worklist_dataflow, /* Worklist solver. */
2377 NULL, /* Confluence operator 0. */
2378 df_live_confluence_n, /* Confluence operator n. */
2379 df_live_transfer_function, /* Transfer function. */
2380 df_live_local_finalize, /* Finalize function. */
2381 df_live_free, /* Free all of the problem information. */
2382 df_live_free, /* Remove this problem from the stack of dataflow problems. */
2383 NULL, /* Debugging. */
2384 df_live_top_dump, /* Debugging start block. */
2385 df_live_bottom_dump, /* Debugging end block. */
2386 df_live_verify_solution_start,/* Incremental solution verify start. */
2387 df_live_verify_solution_end, /* Incremental solution verify end. */
2388 &problem_LR, /* Dependent problem. */
89a95777
KZ
2389 TV_DF_LIVE, /* Timing variable. */
2390 false /* Reset blocks on dropping out of blocks_to_analyze. */
6fb5fa3c
DB
2391};
2392
2393
2394/* Create a new DATAFLOW instance and add it to an existing instance
2395 of DF. The returned structure is what is used to get at the
2396 solution. */
2397
2398void
2399df_live_add_problem (void)
2400{
2401 df_add_problem (&problem_LIVE);
2402 /* These will be initialized when df_scan_blocks processes each
2403 block. */
2404 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
2405}
2406
2407
89a95777
KZ
2408/* Set all of the blocks as dirty. This needs to be done if this
2409 problem is added after all of the insns have been scanned. */
2410
2411void
2412df_live_set_all_dirty (void)
2413{
2414 basic_block bb;
2415 FOR_ALL_BB (bb)
2416 bitmap_set_bit (df_live->out_of_date_transfer_functions,
2417 bb->index);
2418}
2419
2420
6fb5fa3c
DB
2421/* Verify that all of the lr related info is consistent and
2422 correct. */
2423
2424void
2425df_live_verify_transfer_functions (void)
2426{
2427 basic_block bb;
2428 bitmap saved_gen;
2429 bitmap saved_kill;
2430 bitmap all_blocks;
2431
2432 if (!df)
2433 return;
2434
2435 saved_gen = BITMAP_ALLOC (NULL);
2436 saved_kill = BITMAP_ALLOC (NULL);
2437 all_blocks = BITMAP_ALLOC (NULL);
2438
2439 df_grow_insn_info ();
2440
2441 FOR_ALL_BB (bb)
2442 {
2443 struct df_live_bb_info *bb_info = df_live_get_bb_info (bb->index);
2444 bitmap_set_bit (all_blocks, bb->index);
2445
2446 if (bb_info)
2447 {
2448 /* Make a copy of the transfer functions and then compute
2449 new ones to see if the transfer functions have
2450 changed. */
2451 if (!bitmap_bit_p (df_live->out_of_date_transfer_functions,
2452 bb->index))
2453 {
2454 bitmap_copy (saved_gen, bb_info->gen);
2455 bitmap_copy (saved_kill, bb_info->kill);
2456 bitmap_clear (bb_info->gen);
2457 bitmap_clear (bb_info->kill);
2458
2459 df_live_bb_local_compute (bb->index);
2460 gcc_assert (bitmap_equal_p (saved_gen, bb_info->gen));
2461 gcc_assert (bitmap_equal_p (saved_kill, bb_info->kill));
2462 }
2463 }
2464 else
2465 {
2466 /* If we do not have basic block info, the block must be in
2467 the list of dirty blocks or else some one has added a
2468 block behind our backs. */
2469 gcc_assert (bitmap_bit_p (df_live->out_of_date_transfer_functions,
2470 bb->index));
2471 }
2472 /* Make sure no one created a block without following
2473 procedures. */
2474 gcc_assert (df_scan_get_bb_info (bb->index));
2475 }
2476
2477 /* Make sure there are no dirty bits in blocks that have been deleted. */
2478 gcc_assert (!bitmap_intersect_compl_p (df_live->out_of_date_transfer_functions,
2479 all_blocks));
2480 BITMAP_FREE (saved_gen);
2481 BITMAP_FREE (saved_kill);
2482 BITMAP_FREE (all_blocks);
2483}
2484
2485
2486\f
2487/*----------------------------------------------------------------------------
2488 UNINITIALIZED REGISTERS WITH EARLYCLOBBER
2489
2490 Find the set of uses for registers that are reachable from the entry
2491 block without passing thru a definition. In and out bitvectors are built
b11550aa
KZ
2492 for each basic block. The regnum is used to index into these sets.
2493 See df.h for details.
4d779342
DB
2494
2495 This is a variant of the UR problem above that has a lot of special
b11550aa 2496 features just for the register allocation phase. This problem
110abdbc 2497 should go away if someone would fix the interference graph.
b11550aa
KZ
2498
2499 ----------------------------------------------------------------------------*/
4d779342 2500
b11550aa 2501/* Private data used to compute the solution for this problem. These
6fc0bb99 2502 data structures are not accessible outside of this module. */
4d779342
DB
2503struct df_urec_problem_data
2504{
2505 bool earlyclobbers_found; /* True if any instruction contains an
2506 earlyclobber. */
2507#ifdef STACK_REGS
2508 bitmap stack_regs; /* Registers that may be allocated to a STACK_REGS. */
2509#endif
2510};
2511
2512
4d779342
DB
2513/* Set basic block info. */
2514
2515static void
6fb5fa3c
DB
2516df_urec_set_bb_info (unsigned int index,
2517 struct df_urec_bb_info *bb_info)
4d779342 2518{
6fb5fa3c
DB
2519 gcc_assert (df_urec);
2520 gcc_assert (index < df_urec->block_info_size);
2521 df_urec->block_info[index] = bb_info;
4d779342
DB
2522}
2523
2524
2525/* Free basic block info. */
2526
2527static void
6fb5fa3c 2528df_urec_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 2529 void *vbb_info)
4d779342
DB
2530{
2531 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info *) vbb_info;
2532 if (bb_info)
2533 {
2534 BITMAP_FREE (bb_info->gen);
2535 BITMAP_FREE (bb_info->kill);
2536 BITMAP_FREE (bb_info->in);
2537 BITMAP_FREE (bb_info->out);
2538 BITMAP_FREE (bb_info->earlyclobber);
6fb5fa3c 2539 pool_free (df_urec->block_pool, bb_info);
4d779342
DB
2540 }
2541}
2542
2543
6fb5fa3c 2544/* Allocate or reset bitmaps for DF_UREC blocks. The solution bits are
4d779342
DB
2545 not touched unless the block is new. */
2546
2547static void
6fb5fa3c 2548df_urec_alloc (bitmap all_blocks)
23249ac4 2549
4d779342
DB
2550{
2551 unsigned int bb_index;
2552 bitmap_iterator bi;
23249ac4 2553 struct df_urec_problem_data *problem_data
6fb5fa3c 2554 = (struct df_urec_problem_data *) df_urec->problem_data;
4d779342 2555
6fb5fa3c
DB
2556 if (!df_urec->block_pool)
2557 df_urec->block_pool = create_alloc_pool ("df_urec_block pool",
4d779342
DB
2558 sizeof (struct df_urec_bb_info), 50);
2559
6fb5fa3c 2560 if (!df_urec->problem_data)
4d779342 2561 {
5ed6ace5 2562 problem_data = XNEW (struct df_urec_problem_data);
6fb5fa3c 2563 df_urec->problem_data = problem_data;
4d779342
DB
2564 }
2565 problem_data->earlyclobbers_found = false;
2566
6fb5fa3c 2567 df_grow_bb_info (df_urec);
4d779342 2568
6fb5fa3c 2569 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 2570 {
6fb5fa3c 2571 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
4d779342
DB
2572 if (bb_info)
2573 {
2574 bitmap_clear (bb_info->kill);
2575 bitmap_clear (bb_info->gen);
2576 bitmap_clear (bb_info->earlyclobber);
2577 }
2578 else
2579 {
6fb5fa3c
DB
2580 bb_info = (struct df_urec_bb_info *) pool_alloc (df_urec->block_pool);
2581 df_urec_set_bb_info (bb_index, bb_info);
4d779342
DB
2582 bb_info->kill = BITMAP_ALLOC (NULL);
2583 bb_info->gen = BITMAP_ALLOC (NULL);
2584 bb_info->in = BITMAP_ALLOC (NULL);
2585 bb_info->out = BITMAP_ALLOC (NULL);
6fb5fa3c 2586 bb_info->top = BITMAP_ALLOC (NULL);
4d779342
DB
2587 bb_info->earlyclobber = BITMAP_ALLOC (NULL);
2588 }
2589 }
89a95777 2590 df_urec->optional_p = true;
4d779342
DB
2591}
2592
2593
2594/* The function modifies local info for register REG being changed in
2595 SETTER. DATA is used to pass the current basic block info. */
2596
2597static void
2598df_urec_mark_reg_change (rtx reg, rtx setter, void *data)
2599{
2600 int regno;
2601 int endregno;
2602 int i;
2603 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2604
2605 if (GET_CODE (reg) == SUBREG)
2606 reg = SUBREG_REG (reg);
2607
2608 if (!REG_P (reg))
2609 return;
2610
09e18274 2611 regno = REGNO (reg);
4d779342
DB
2612 if (regno < FIRST_PSEUDO_REGISTER)
2613 {
09e18274 2614 endregno = END_HARD_REGNO (reg);
4d779342
DB
2615 for (i = regno; i < endregno; i++)
2616 {
2617 bitmap_set_bit (bb_info->kill, i);
2618
2619 if (GET_CODE (setter) != CLOBBER)
2620 bitmap_set_bit (bb_info->gen, i);
2621 else
2622 bitmap_clear_bit (bb_info->gen, i);
2623 }
2624 }
2625 else
2626 {
2627 bitmap_set_bit (bb_info->kill, regno);
2628
2629 if (GET_CODE (setter) != CLOBBER)
2630 bitmap_set_bit (bb_info->gen, regno);
2631 else
2632 bitmap_clear_bit (bb_info->gen, regno);
2633 }
2634}
2635/* Classes of registers which could be early clobbered in the current
2636 insn. */
2637
4d779342
DB
2638static VEC(int,heap) *earlyclobber_regclass;
2639
2640/* This function finds and stores register classes that could be early
2641 clobbered in INSN. If any earlyclobber classes are found, the function
2642 returns TRUE, in all other cases it returns FALSE. */
2643
2644static bool
2645df_urec_check_earlyclobber (rtx insn)
2646{
2647 int opno;
2648 bool found = false;
2649
2650 extract_insn (insn);
2651
2652 VEC_truncate (int, earlyclobber_regclass, 0);
2653 for (opno = 0; opno < recog_data.n_operands; opno++)
2654 {
2655 char c;
2656 bool amp_p;
2657 int i;
2658 enum reg_class class;
2659 const char *p = recog_data.constraints[opno];
2660
2661 class = NO_REGS;
2662 amp_p = false;
2663 for (;;)
2664 {
2665 c = *p;
2666 switch (c)
2667 {
2668 case '=': case '+': case '?':
2669 case '#': case '!':
2670 case '*': case '%':
2671 case 'm': case '<': case '>': case 'V': case 'o':
2672 case 'E': case 'F': case 'G': case 'H':
2673 case 's': case 'i': case 'n':
2674 case 'I': case 'J': case 'K': case 'L':
2675 case 'M': case 'N': case 'O': case 'P':
2676 case 'X':
2677 case '0': case '1': case '2': case '3': case '4':
2678 case '5': case '6': case '7': case '8': case '9':
2679 /* These don't say anything we care about. */
2680 break;
2681
2682 case '&':
2683 amp_p = true;
2684 break;
2685 case '\0':
2686 case ',':
2687 if (amp_p && class != NO_REGS)
2688 {
2689 int rc;
2690
2691 found = true;
2692 for (i = 0;
2693 VEC_iterate (int, earlyclobber_regclass, i, rc);
2694 i++)
2695 {
2696 if (rc == (int) class)
2697 goto found_rc;
2698 }
2699
2700 /* We use VEC_quick_push here because
2701 earlyclobber_regclass holds no more than
2702 N_REG_CLASSES elements. */
2703 VEC_quick_push (int, earlyclobber_regclass, (int) class);
2704 found_rc:
2705 ;
2706 }
2707
2708 amp_p = false;
2709 class = NO_REGS;
2710 break;
2711
2712 case 'r':
2713 class = GENERAL_REGS;
2714 break;
2715
2716 default:
2717 class = REG_CLASS_FROM_CONSTRAINT (c, p);
2718 break;
2719 }
2720 if (c == '\0')
2721 break;
2722 p += CONSTRAINT_LEN (c, p);
2723 }
2724 }
2725
2726 return found;
2727}
2728
2729/* The function checks that pseudo-register *X has a class
2730 intersecting with the class of pseudo-register could be early
2731 clobbered in the same insn.
2732
2733 This function is a no-op if earlyclobber_regclass is empty.
2734
2735 Reload can assign the same hard register to uninitialized
2736 pseudo-register and early clobbered pseudo-register in an insn if
2737 the pseudo-register is used first time in given BB and not lived at
2738 the BB start. To prevent this we don't change life information for
2739 such pseudo-registers. */
2740
2741static int
2742df_urec_mark_reg_use_for_earlyclobber (rtx *x, void *data)
2743{
2744 enum reg_class pref_class, alt_class;
2745 int i, regno;
2746 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2747
2748 if (REG_P (*x) && REGNO (*x) >= FIRST_PSEUDO_REGISTER)
2749 {
2750 int rc;
2751
2752 regno = REGNO (*x);
2753 if (bitmap_bit_p (bb_info->kill, regno)
2754 || bitmap_bit_p (bb_info->gen, regno))
2755 return 0;
2756 pref_class = reg_preferred_class (regno);
2757 alt_class = reg_alternate_class (regno);
2758 for (i = 0; VEC_iterate (int, earlyclobber_regclass, i, rc); i++)
2759 {
2760 if (reg_classes_intersect_p (rc, pref_class)
2761 || (rc != NO_REGS
2762 && reg_classes_intersect_p (rc, alt_class)))
2763 {
2764 bitmap_set_bit (bb_info->earlyclobber, regno);
2765 break;
2766 }
2767 }
2768 }
2769 return 0;
2770}
2771
2772/* The function processes all pseudo-registers in *X with the aid of
2773 previous function. */
2774
2775static void
2776df_urec_mark_reg_use_for_earlyclobber_1 (rtx *x, void *data)
2777{
2778 for_each_rtx (x, df_urec_mark_reg_use_for_earlyclobber, data);
2779}
2780
2781
2782/* Compute local uninitialized register info for basic block BB. */
2783
2784static void
6fb5fa3c 2785df_urec_bb_local_compute (unsigned int bb_index)
4d779342 2786{
4d779342 2787 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 2788 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
4d779342 2789 rtx insn;
6fb5fa3c 2790 struct df_ref **def_rec;
4d779342 2791
6fb5fa3c
DB
2792 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2793 {
2794 struct df_ref *def = *def_rec;
2795 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2796 {
2797 unsigned int regno = DF_REF_REGNO (def);
2798 bitmap_set_bit (bb_info->gen, regno);
2799 }
2800 }
912f2dac 2801
4d779342
DB
2802 FOR_BB_INSNS (bb, insn)
2803 {
2804 if (INSN_P (insn))
2805 {
2806 note_stores (PATTERN (insn), df_urec_mark_reg_change, bb_info);
23249ac4 2807 if (df_urec_check_earlyclobber (insn))
4d779342 2808 {
23249ac4 2809 struct df_urec_problem_data *problem_data
6fb5fa3c 2810 = (struct df_urec_problem_data *) df_urec->problem_data;
4d779342
DB
2811 problem_data->earlyclobbers_found = true;
2812 note_uses (&PATTERN (insn),
2813 df_urec_mark_reg_use_for_earlyclobber_1, bb_info);
2814 }
2815 }
2816 }
912f2dac 2817
6fb5fa3c
DB
2818 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
2819 {
2820 struct df_ref *def = *def_rec;
2821 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2822 {
2823 unsigned int regno = DF_REF_REGNO (def);
2824 bitmap_set_bit (bb_info->gen, regno);
2825 }
2826 }
4d779342
DB
2827}
2828
2829
2830/* Compute local uninitialized register info. */
2831
2832static void
6fb5fa3c 2833df_urec_local_compute (bitmap all_blocks)
4d779342
DB
2834{
2835 unsigned int bb_index;
2836 bitmap_iterator bi;
2837#ifdef STACK_REGS
2838 int i;
56b138ae 2839 HARD_REG_SET stack_hard_regs, used;
23249ac4 2840 struct df_urec_problem_data *problem_data
6fb5fa3c 2841 = (struct df_urec_problem_data *) df_urec->problem_data;
4d779342
DB
2842
2843 /* Any register that MAY be allocated to a register stack (like the
2844 387) is treated poorly. Each such register is marked as being
2845 live everywhere. This keeps the register allocator and the
2846 subsequent passes from doing anything useful with these values.
2847
2848 FIXME: This seems like an incredibly poor idea. */
2849
4d779342
DB
2850 CLEAR_HARD_REG_SET (stack_hard_regs);
2851 for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
2852 SET_HARD_REG_BIT (stack_hard_regs, i);
2853 problem_data->stack_regs = BITMAP_ALLOC (NULL);
2854 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
2855 {
2856 COPY_HARD_REG_SET (used, reg_class_contents[reg_preferred_class (i)]);
2857 IOR_HARD_REG_SET (used, reg_class_contents[reg_alternate_class (i)]);
2858 AND_HARD_REG_SET (used, stack_hard_regs);
56b138ae
RS
2859 if (!hard_reg_set_empty_p (used))
2860 bitmap_set_bit (problem_data->stack_regs, i);
4d779342
DB
2861 }
2862#endif
2863
2864 /* We know that earlyclobber_regclass holds no more than
2865 N_REG_CLASSES elements. See df_urec_check_earlyclobber. */
2866 earlyclobber_regclass = VEC_alloc (int, heap, N_REG_CLASSES);
2867
6fb5fa3c 2868 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 2869 {
6fb5fa3c 2870 df_urec_bb_local_compute (bb_index);
4d779342
DB
2871 }
2872
2873 VEC_free (int, heap, earlyclobber_regclass);
2874}
2875
2876
2877/* Initialize the solution vectors. */
2878
2879static void
6fb5fa3c 2880df_urec_init (bitmap all_blocks)
4d779342
DB
2881{
2882 unsigned int bb_index;
2883 bitmap_iterator bi;
2884
2885 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2886 {
6fb5fa3c 2887 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
4d779342 2888
912f2dac
DB
2889 bitmap_copy (bb_info->out, bb_info->gen);
2890 bitmap_clear (bb_info->in);
4d779342
DB
2891 }
2892}
2893
2894
ea2c620c 2895/* Or in the stack regs, hard regs and early clobber regs into the
6fb5fa3c
DB
2896 urec_in sets of all of the blocks. */
2897
4d779342
DB
2898
2899static void
6fb5fa3c 2900df_urec_local_finalize (bitmap all_blocks)
4d779342 2901{
4d779342
DB
2902 bitmap tmp = BITMAP_ALLOC (NULL);
2903 bitmap_iterator bi;
2904 unsigned int bb_index;
23249ac4 2905 struct df_urec_problem_data *problem_data
6fb5fa3c 2906 = (struct df_urec_problem_data *) df_urec->problem_data;
4d779342
DB
2907
2908 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2909 {
6fb5fa3c
DB
2910 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
2911 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (bb_index);
4d779342
DB
2912
2913 if (bb_index != ENTRY_BLOCK && bb_index != EXIT_BLOCK)
2914 {
2915 if (problem_data->earlyclobbers_found)
2916 bitmap_ior_into (bb_info->in, bb_info->earlyclobber);
2917
2918#ifdef STACK_REGS
2919 /* We can not use the same stack register for uninitialized
2920 pseudo-register and another living pseudo-register
2921 because if the uninitialized pseudo-register dies,
2922 subsequent pass reg-stack will be confused (it will
2923 believe that the other register dies). */
2924 bitmap_ior_into (bb_info->in, problem_data->stack_regs);
2925 bitmap_ior_into (bb_info->out, problem_data->stack_regs);
2926#endif
2927 }
2928
4d779342
DB
2929 /* No register may reach a location where it is not used. Thus
2930 we trim the rr result to the places where it is used. */
2931 bitmap_and_into (bb_info->in, bb_lr_info->in);
2932 bitmap_and_into (bb_info->out, bb_lr_info->out);
6fb5fa3c
DB
2933 bitmap_copy (bb_info->top, bb_info->in);
2934 if (bb_lr_info->adef)
2935 bitmap_ior_into (bb_info->top, bb_lr_info->adef);
2936 bitmap_and_into (bb_info->top, bb_lr_info->top);
2937#if 0
4d779342
DB
2938 /* Hard registers may still stick in the ur_out set, but not
2939 be in the ur_in set, if their only mention was in a call
2940 in this block. This is because a call kills in the lr
2941 problem but does not kill in the rr problem. To clean
2942 this up, we execute the transfer function on the lr_in
2943 set and then use that to knock bits out of ur_out. */
2944 bitmap_ior_and_compl (tmp, bb_info->gen, bb_lr_info->in,
2945 bb_info->kill);
2946 bitmap_and_into (bb_info->out, tmp);
2947#endif
2948 }
2949
2950#ifdef STACK_REGS
2951 BITMAP_FREE (problem_data->stack_regs);
2952#endif
2953 BITMAP_FREE (tmp);
2954}
2955
2956
2957/* Confluence function that ignores fake edges. */
2958
2959static void
6fb5fa3c 2960df_urec_confluence_n (edge e)
4d779342 2961{
6fb5fa3c
DB
2962 bitmap op1 = df_urec_get_bb_info (e->dest->index)->in;
2963 bitmap op2 = df_urec_get_bb_info (e->src->index)->out;
4d779342
DB
2964
2965 if (e->flags & EDGE_FAKE)
2966 return;
2967
2968 bitmap_ior_into (op1, op2);
2969}
2970
2971
2972/* Transfer function. */
2973
2974static bool
6fb5fa3c 2975df_urec_transfer_function (int bb_index)
4d779342 2976{
6fb5fa3c 2977 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb_index);
4d779342
DB
2978 bitmap in = bb_info->in;
2979 bitmap out = bb_info->out;
2980 bitmap gen = bb_info->gen;
2981 bitmap kill = bb_info->kill;
2982
2983 return bitmap_ior_and_compl (out, gen, in, kill);
2984}
2985
2986
2987/* Free all storage associated with the problem. */
2988
2989static void
6fb5fa3c 2990df_urec_free (void)
4d779342 2991{
6fb5fa3c 2992 if (df_urec->block_info)
4d779342 2993 {
3b8266e2
KZ
2994 unsigned int i;
2995
6fb5fa3c 2996 for (i = 0; i < df_urec->block_info_size; i++)
4d779342 2997 {
6fb5fa3c 2998 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (i);
3b8266e2
KZ
2999 if (bb_info)
3000 {
3001 BITMAP_FREE (bb_info->gen);
3002 BITMAP_FREE (bb_info->kill);
3003 BITMAP_FREE (bb_info->in);
3004 BITMAP_FREE (bb_info->out);
3005 BITMAP_FREE (bb_info->earlyclobber);
6fb5fa3c 3006 BITMAP_FREE (bb_info->top);
3b8266e2 3007 }
4d779342 3008 }
3b8266e2 3009
6fb5fa3c 3010 free_alloc_pool (df_urec->block_pool);
3b8266e2 3011
6fb5fa3c
DB
3012 df_urec->block_info_size = 0;
3013 free (df_urec->block_info);
3014 free (df_urec->problem_data);
4d779342 3015 }
6fb5fa3c 3016 free (df_urec);
4d779342
DB
3017}
3018
3019
6fb5fa3c 3020/* Debugging info at top of bb. */
4d779342
DB
3021
3022static void
6fb5fa3c 3023df_urec_top_dump (basic_block bb, FILE *file)
4d779342 3024{
6fb5fa3c
DB
3025 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb->index);
3026 if (!bb_info || !bb_info->in)
23249ac4 3027 return;
4d779342 3028
6fb5fa3c
DB
3029 fprintf (file, ";; urec in \t");
3030 df_print_regset (file, bb_info->in);
3031 fprintf (file, ";; urec gen \t");
3032 df_print_regset (file, bb_info->gen);
3033 fprintf (file, ";; urec kill\t");
3034 df_print_regset (file, bb_info->kill);
3035 fprintf (file, ";; urec ec\t");
3036 df_print_regset (file, bb_info->earlyclobber);
3037}
3038
3039
3040/* Debugging info at bottom of bb. */
3041
3042static void
3043df_urec_bottom_dump (basic_block bb, FILE *file)
3044{
3045 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (bb->index);
3046 if (!bb_info || !bb_info->out)
3047 return;
3048 fprintf (file, ";; urec out \t");
3049 df_print_regset (file, bb_info->out);
4d779342
DB
3050}
3051
6fb5fa3c 3052
4d779342
DB
3053/* All of the information associated with every instance of the problem. */
3054
3055static struct df_problem problem_UREC =
3056{
3057 DF_UREC, /* Problem id. */
3058 DF_FORWARD, /* Direction. */
3059 df_urec_alloc, /* Allocate the problem specific data. */
30cb87a0 3060 NULL, /* Reset global information. */
4d779342
DB
3061 df_urec_free_bb_info, /* Free basic block info. */
3062 df_urec_local_compute, /* Local compute function. */
3063 df_urec_init, /* Init the solution specific data. */
6fb5fa3c 3064 df_worklist_dataflow, /* Worklist solver. */
4d779342
DB
3065 NULL, /* Confluence operator 0. */
3066 df_urec_confluence_n, /* Confluence operator n. */
3067 df_urec_transfer_function, /* Transfer function. */
3068 df_urec_local_finalize, /* Finalize function. */
3069 df_urec_free, /* Free all of the problem information. */
6fb5fa3c
DB
3070 df_urec_free, /* Remove this problem from the stack of dataflow problems. */
3071 NULL, /* Debugging. */
3072 df_urec_top_dump, /* Debugging start block. */
3073 df_urec_bottom_dump, /* Debugging end block. */
3074 NULL, /* Incremental solution verify start. */
3075 NULL, /* Incremental solution verfiy end. */
3076 &problem_LR, /* Dependent problem. */
89a95777
KZ
3077 TV_DF_UREC, /* Timing variable. */
3078 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
3079};
3080
3081
3082/* Create a new DATAFLOW instance and add it to an existing instance
3083 of DF. The returned structure is what is used to get at the
3084 solution. */
3085
6fb5fa3c
DB
3086void
3087df_urec_add_problem (void)
4d779342 3088{
6fb5fa3c 3089 df_add_problem (&problem_UREC);
4d779342
DB
3090}
3091
3092
3093\f
3094/*----------------------------------------------------------------------------
3095 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
3096
3097 Link either the defs to the uses and / or the uses to the defs.
3098
3099 These problems are set up like the other dataflow problems so that
3100 they nicely fit into the framework. They are much simpler and only
3101 involve a single traversal of instructions and an examination of
3102 the reaching defs information (the dependent problem).
3103----------------------------------------------------------------------------*/
3104
6fb5fa3c 3105#define df_chain_problem_p(FLAG) (((enum df_chain_flags)df_chain->local_flags)&(FLAG))
4d779342 3106
6fb5fa3c 3107/* Create a du or ud chain from SRC to DST and link it into SRC. */
23249ac4 3108
6fb5fa3c
DB
3109struct df_link *
3110df_chain_create (struct df_ref *src, struct df_ref *dst)
4d779342 3111{
6fb5fa3c
DB
3112 struct df_link *head = DF_REF_CHAIN (src);
3113 struct df_link *link = pool_alloc (df_chain->block_pool);;
3114
3115 DF_REF_CHAIN (src) = link;
3116 link->next = head;
3117 link->ref = dst;
3118 return link;
3119}
4d779342 3120
4d779342 3121
6fb5fa3c
DB
3122/* Delete any du or ud chains that start at REF and point to
3123 TARGET. */
3124static void
3125df_chain_unlink_1 (struct df_ref *ref, struct df_ref *target)
3126{
3127 struct df_link *chain = DF_REF_CHAIN (ref);
3128 struct df_link *prev = NULL;
4d779342 3129
6fb5fa3c 3130 while (chain)
4d779342 3131 {
6fb5fa3c 3132 if (chain->ref == target)
4d779342 3133 {
6fb5fa3c
DB
3134 if (prev)
3135 prev->next = chain->next;
3136 else
3137 DF_REF_CHAIN (ref) = chain->next;
3138 pool_free (df_chain->block_pool, chain);
3139 return;
4d779342 3140 }
6fb5fa3c
DB
3141 prev = chain;
3142 chain = chain->next;
4d779342 3143 }
6fb5fa3c
DB
3144}
3145
3146
3147/* Delete a du or ud chain that leave or point to REF. */
3148
3149void
3150df_chain_unlink (struct df_ref *ref)
3151{
3152 struct df_link *chain = DF_REF_CHAIN (ref);
3153 while (chain)
4d779342 3154 {
6fb5fa3c
DB
3155 struct df_link *next = chain->next;
3156 /* Delete the other side if it exists. */
3157 df_chain_unlink_1 (chain->ref, ref);
3158 pool_free (df_chain->block_pool, chain);
3159 chain = next;
4d779342 3160 }
6fb5fa3c 3161 DF_REF_CHAIN (ref) = NULL;
4d779342
DB
3162}
3163
3164
6fb5fa3c
DB
3165/* Copy the du or ud chain starting at FROM_REF and attach it to
3166 TO_REF. */
30cb87a0 3167
6fb5fa3c
DB
3168void
3169df_chain_copy (struct df_ref *to_ref,
3170 struct df_link *from_ref)
30cb87a0 3171{
6fb5fa3c
DB
3172 while (from_ref)
3173 {
3174 df_chain_create (to_ref, from_ref->ref);
3175 from_ref = from_ref->next;
3176 }
3177}
30cb87a0 3178
30cb87a0 3179
6fb5fa3c
DB
3180/* Remove this problem from the stack of dataflow problems. */
3181
3182static void
3183df_chain_remove_problem (void)
3184{
3185 bitmap_iterator bi;
3186 unsigned int bb_index;
3187
3188 /* Wholesale destruction of the old chains. */
3189 if (df_chain->block_pool)
3190 free_alloc_pool (df_chain->block_pool);
30cb87a0 3191
6fb5fa3c
DB
3192 EXECUTE_IF_SET_IN_BITMAP (df_chain->out_of_date_transfer_functions, 0, bb_index, bi)
3193 {
3194 rtx insn;
3195 struct df_ref **def_rec;
3196 struct df_ref **use_rec;
3197 basic_block bb = BASIC_BLOCK (bb_index);
3198
3199 if (df_chain_problem_p (DF_DU_CHAIN))
3200 for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
3201 DF_REF_CHAIN (*def_rec) = NULL;
3202 if (df_chain_problem_p (DF_UD_CHAIN))
3203 for (use_rec = df_get_artificial_uses (bb->index); *use_rec; use_rec++)
3204 DF_REF_CHAIN (*use_rec) = NULL;
3205
3206 FOR_BB_INSNS (bb, insn)
30cb87a0 3207 {
6fb5fa3c
DB
3208 unsigned int uid = INSN_UID (insn);
3209
3210 if (INSN_P (insn))
30cb87a0 3211 {
6fb5fa3c
DB
3212 if (df_chain_problem_p (DF_DU_CHAIN))
3213 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3214 DF_REF_CHAIN (*def_rec) = NULL;
3215 if (df_chain_problem_p (DF_UD_CHAIN))
3216 {
3217 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3218 DF_REF_CHAIN (*use_rec) = NULL;
3219 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
3220 DF_REF_CHAIN (*use_rec) = NULL;
3221 }
30cb87a0
KZ
3222 }
3223 }
3224 }
6fb5fa3c
DB
3225
3226 bitmap_clear (df_chain->out_of_date_transfer_functions);
3227 df_chain->block_pool = NULL;
30cb87a0
KZ
3228}
3229
3230
6fb5fa3c 3231/* Remove the chain problem completely. */
30cb87a0 3232
6fb5fa3c
DB
3233static void
3234df_chain_fully_remove_problem (void)
30cb87a0 3235{
6fb5fa3c
DB
3236 df_chain_remove_problem ();
3237 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
3238 free (df_chain);
3239}
30cb87a0 3240
30cb87a0 3241
6fb5fa3c 3242/* Create def-use or use-def chains. */
30cb87a0 3243
6fb5fa3c
DB
3244static void
3245df_chain_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3246{
3247 df_chain_remove_problem ();
3248 df_chain->block_pool = create_alloc_pool ("df_chain_block pool",
3249 sizeof (struct df_link), 50);
89a95777 3250 df_chain->optional_p = true;
30cb87a0
KZ
3251}
3252
3253
3254/* Reset all of the chains when the set of basic blocks changes. */
3255
30cb87a0 3256static void
6fb5fa3c 3257df_chain_reset (bitmap blocks_to_clear ATTRIBUTE_UNUSED)
30cb87a0 3258{
6fb5fa3c 3259 df_chain_remove_problem ();
30cb87a0
KZ
3260}
3261
3262
4d779342
DB
3263/* Create the chains for a list of USEs. */
3264
3265static void
6fb5fa3c
DB
3266df_chain_create_bb_process_use (bitmap local_rd,
3267 struct df_ref **use_rec,
4d779342
DB
3268 enum df_ref_flags top_flag)
3269{
4d779342
DB
3270 bitmap_iterator bi;
3271 unsigned int def_index;
3272
6fb5fa3c 3273 while (*use_rec)
4d779342 3274 {
6fb5fa3c 3275 struct df_ref *use = *use_rec;
4d779342 3276 unsigned int uregno = DF_REF_REGNO (use);
6fb5fa3c
DB
3277 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
3278 || (uregno >= FIRST_PSEUDO_REGISTER))
4d779342 3279 {
6fb5fa3c
DB
3280 /* Do not want to go through this for an uninitialized var. */
3281 int count = DF_DEFS_COUNT (uregno);
3282 if (count)
4d779342 3283 {
6fb5fa3c 3284 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
4d779342 3285 {
6fb5fa3c
DB
3286 unsigned int first_index = DF_DEFS_BEGIN (uregno);
3287 unsigned int last_index = first_index + count - 1;
4d779342 3288
6fb5fa3c
DB
3289 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
3290 {
3291 struct df_ref *def;
3292 if (def_index > last_index)
3293 break;
3294
3295 def = DF_DEFS_GET (def_index);
3296 if (df_chain_problem_p (DF_DU_CHAIN))
3297 df_chain_create (def, use);
3298 if (df_chain_problem_p (DF_UD_CHAIN))
3299 df_chain_create (use, def);
3300 }
4d779342
DB
3301 }
3302 }
3303 }
6fb5fa3c
DB
3304
3305 use_rec++;
4d779342
DB
3306 }
3307}
3308
4d779342
DB
3309
3310/* Create chains from reaching defs bitmaps for basic block BB. */
6fb5fa3c 3311
4d779342 3312static void
6fb5fa3c 3313df_chain_create_bb (unsigned int bb_index)
4d779342
DB
3314{
3315 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 3316 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
3317 rtx insn;
3318 bitmap cpy = BITMAP_ALLOC (NULL);
6fb5fa3c 3319 struct df_ref **def_rec;
4d779342
DB
3320
3321 bitmap_copy (cpy, bb_info->in);
6fb5fa3c 3322 bitmap_set_bit (df_chain->out_of_date_transfer_functions, bb_index);
4d779342
DB
3323
3324 /* Since we are going forwards, process the artificial uses first
3325 then the artificial defs second. */
3326
3327#ifdef EH_USES
3328 /* Create the chains for the artificial uses from the EH_USES at the
3329 beginning of the block. */
6fb5fa3c
DB
3330
3331 /* Artificials are only hard regs. */
3332 if (!(df->changeable_flags & DF_NO_HARD_REGS))
3333 df_chain_create_bb_process_use (cpy,
3334 df_get_artificial_uses (bb->index),
3335 DF_REF_AT_TOP);
4d779342
DB
3336#endif
3337
6fb5fa3c
DB
3338 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3339 {
3340 struct df_ref *def = *def_rec;
3341 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
3342 {
3343 unsigned int dregno = DF_REF_REGNO (def);
3344 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3345 bitmap_clear_range (cpy,
3346 DF_DEFS_BEGIN (dregno),
3347 DF_DEFS_COUNT (dregno));
3348 bitmap_set_bit (cpy, DF_REF_ID (def));
3349 }
3350 }
4d779342
DB
3351
3352 /* Process the regular instructions next. */
3353 FOR_BB_INSNS (bb, insn)
3354 {
6fb5fa3c 3355 struct df_ref **def_rec;
4d779342
DB
3356 unsigned int uid = INSN_UID (insn);
3357
23249ac4 3358 if (!INSN_P (insn))
4d779342
DB
3359 continue;
3360
3361 /* Now scan the uses and link them up with the defs that remain
3362 in the cpy vector. */
3363
6fb5fa3c
DB
3364 df_chain_create_bb_process_use (cpy, DF_INSN_UID_USES (uid), 0);
3365
3366 if (df->changeable_flags & DF_EQ_NOTES)
3367 df_chain_create_bb_process_use (cpy, DF_INSN_UID_EQ_USES (uid), 0);
3368
4d779342
DB
3369
3370 /* Since we are going forwards, process the defs second. This
3371 pass only changes the bits in cpy. */
6fb5fa3c 3372 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 3373 {
6fb5fa3c 3374 struct df_ref *def = *def_rec;
4d779342 3375 unsigned int dregno = DF_REF_REGNO (def);
6fb5fa3c
DB
3376 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
3377 || (dregno >= FIRST_PSEUDO_REGISTER))
3378 {
3379 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3380 bitmap_clear_range (cpy,
3381 DF_DEFS_BEGIN (dregno),
3382 DF_DEFS_COUNT (dregno));
3383 if (!(DF_REF_FLAGS (def)
3384 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3385 bitmap_set_bit (cpy, DF_REF_ID (def));
3386 }
4d779342
DB
3387 }
3388 }
3389
3390 /* Create the chains for the artificial uses of the hard registers
3391 at the end of the block. */
6fb5fa3c
DB
3392 if (!(df->changeable_flags & DF_NO_HARD_REGS))
3393 df_chain_create_bb_process_use (cpy,
3394 df_get_artificial_uses (bb->index),
3395 0);
3396
3397 BITMAP_FREE (cpy);
4d779342
DB
3398}
3399
3400/* Create def-use chains from reaching use bitmaps for basic blocks
3401 in BLOCKS. */
3402
3403static void
6fb5fa3c 3404df_chain_finalize (bitmap all_blocks)
4d779342
DB
3405{
3406 unsigned int bb_index;
3407 bitmap_iterator bi;
4d779342
DB
3408
3409 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
3410 {
6fb5fa3c 3411 df_chain_create_bb (bb_index);
4d779342
DB
3412 }
3413}
3414
3415
3416/* Free all storage associated with the problem. */
3417
3418static void
6fb5fa3c 3419df_chain_free (void)
4d779342 3420{
6fb5fa3c
DB
3421 free_alloc_pool (df_chain->block_pool);
3422 BITMAP_FREE (df_chain->out_of_date_transfer_functions);
3423 free (df_chain);
4d779342
DB
3424}
3425
3426
3427/* Debugging info. */
3428
3429static void
6fb5fa3c 3430df_chain_top_dump (basic_block bb, FILE *file)
4d779342 3431{
6fb5fa3c 3432 if (df_chain_problem_p (DF_DU_CHAIN))
4d779342 3433 {
6fb5fa3c
DB
3434 rtx insn;
3435 struct df_ref **def_rec = df_get_artificial_defs (bb->index);
3436 if (*def_rec)
4d779342 3437 {
6fb5fa3c
DB
3438
3439 fprintf (file, ";; DU chains for artificial defs\n");
3440 while (*def_rec)
4d779342 3441 {
6fb5fa3c
DB
3442 struct df_ref *def = *def_rec;
3443 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
23249ac4 3444 df_chain_dump (DF_REF_CHAIN (def), file);
4d779342 3445 fprintf (file, "\n");
6fb5fa3c
DB
3446 def_rec++;
3447 }
3448 }
3449
3450 FOR_BB_INSNS (bb, insn)
3451 {
3452 unsigned int uid = INSN_UID (insn);
3453 if (INSN_P (insn))
3454 {
3455 def_rec = DF_INSN_UID_DEFS (uid);
3456 if (*def_rec)
3457 {
3458 fprintf (file, ";; DU chains for insn luid %d uid %d\n",
3459 DF_INSN_LUID (insn), uid);
3460
3461 while (*def_rec)
3462 {
3463 struct df_ref *def = *def_rec;
3464 fprintf (file, ";; reg %d ", DF_REF_REGNO (def));
3465 if (def->flags & DF_REF_READ_WRITE)
3466 fprintf (file, "read/write ");
3467 df_chain_dump (DF_REF_CHAIN (def), file);
3468 fprintf (file, "\n");
3469 def_rec++;
3470 }
3471 }
4d779342
DB
3472 }
3473 }
3474 }
6fb5fa3c
DB
3475}
3476
4d779342 3477
6fb5fa3c
DB
3478static void
3479df_chain_bottom_dump (basic_block bb, FILE *file)
3480{
3481 if (df_chain_problem_p (DF_UD_CHAIN))
4d779342 3482 {
6fb5fa3c
DB
3483 rtx insn;
3484 struct df_ref **use_rec = df_get_artificial_uses (bb->index);
3485
3486 if (*use_rec)
4d779342 3487 {
6fb5fa3c
DB
3488 fprintf (file, ";; UD chains for artificial uses\n");
3489 while (*use_rec)
4d779342 3490 {
6fb5fa3c
DB
3491 struct df_ref *use = *use_rec;
3492 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
23249ac4 3493 df_chain_dump (DF_REF_CHAIN (use), file);
4d779342 3494 fprintf (file, "\n");
6fb5fa3c
DB
3495 use_rec++;
3496 }
3497 }
3498
3499 FOR_BB_INSNS (bb, insn)
3500 {
3501 unsigned int uid = INSN_UID (insn);
3502 if (INSN_P (insn))
3503 {
3504 struct df_ref **eq_use_rec = DF_INSN_UID_EQ_USES (uid);
3505 use_rec = DF_INSN_UID_USES (uid);
3506 if (*use_rec || *eq_use_rec)
3507 {
3508 fprintf (file, ";; UD chains for insn luid %d uid %d\n",
3509 DF_INSN_LUID (insn), uid);
3510
3511 while (*use_rec)
3512 {
3513 struct df_ref *use = *use_rec;
3514 fprintf (file, ";; reg %d ", DF_REF_REGNO (use));
3515 if (use->flags & DF_REF_READ_WRITE)
3516 fprintf (file, "read/write ");
3517 df_chain_dump (DF_REF_CHAIN (use), file);
3518 fprintf (file, "\n");
3519 use_rec++;
3520 }
3521 while (*eq_use_rec)
3522 {
3523 struct df_ref *use = *eq_use_rec;
3524 fprintf (file, ";; eq_note reg %d ", DF_REF_REGNO (use));
3525 df_chain_dump (DF_REF_CHAIN (use), file);
3526 fprintf (file, "\n");
3527 eq_use_rec++;
3528 }
3529 }
4d779342
DB
3530 }
3531 }
3532 }
3533}
3534
3535
3536static struct df_problem problem_CHAIN =
3537{
3538 DF_CHAIN, /* Problem id. */
3539 DF_NONE, /* Direction. */
3540 df_chain_alloc, /* Allocate the problem specific data. */
30cb87a0 3541 df_chain_reset, /* Reset global information. */
4d779342
DB
3542 NULL, /* Free basic block info. */
3543 NULL, /* Local compute function. */
3544 NULL, /* Init the solution specific data. */
3545 NULL, /* Iterative solver. */
3546 NULL, /* Confluence operator 0. */
3547 NULL, /* Confluence operator n. */
3548 NULL, /* Transfer function. */
3549 df_chain_finalize, /* Finalize function. */
3550 df_chain_free, /* Free all of the problem information. */
6fb5fa3c
DB
3551 df_chain_fully_remove_problem,/* Remove this problem from the stack of dataflow problems. */
3552 NULL, /* Debugging. */
3553 df_chain_top_dump, /* Debugging start block. */
3554 df_chain_bottom_dump, /* Debugging end block. */
3555 NULL, /* Incremental solution verify start. */
3556 NULL, /* Incremental solution verfiy end. */
3557 &problem_RD, /* Dependent problem. */
89a95777
KZ
3558 TV_DF_CHAIN, /* Timing variable. */
3559 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
3560};
3561
3562
3563/* Create a new DATAFLOW instance and add it to an existing instance
3564 of DF. The returned structure is what is used to get at the
3565 solution. */
3566
6fb5fa3c
DB
3567void
3568df_chain_add_problem (enum df_chain_flags chain_flags)
4d779342 3569{
6fb5fa3c
DB
3570 df_add_problem (&problem_CHAIN);
3571 df_chain->local_flags = (unsigned int)chain_flags;
3572 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
4d779342
DB
3573}
3574
6fb5fa3c 3575#undef df_chain_problem_p
4d779342 3576
6fb5fa3c 3577\f
4d779342 3578/*----------------------------------------------------------------------------
6fb5fa3c 3579 This pass computes REG_DEAD and REG_UNUSED notes.
23249ac4 3580 ----------------------------------------------------------------------------*/
4d779342 3581
89a95777
KZ
3582static void
3583df_note_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
3584{
3585 df_note->optional_p = true;
3586}
3587
23249ac4
DB
3588#ifdef REG_DEAD_DEBUGGING
3589static void
6fb5fa3c 3590df_print_note (const char *prefix, rtx insn, rtx note)
4d779342 3591{
6fb5fa3c
DB
3592 if (dump_file)
3593 {
3594 fprintf (dump_file, "%s %d ", prefix, INSN_UID (insn));
3595 print_rtl (dump_file, note);
3596 fprintf (dump_file, "\n");
3597 }
23249ac4
DB
3598}
3599#endif
4d779342 3600
23249ac4
DB
3601
3602/* After reg-stack, the x86 floating point stack regs are difficult to
3603 analyze because of all of the pushes, pops and rotations. Thus, we
3604 just leave the notes alone. */
3605
6fb5fa3c 3606#ifdef STACK_REGS
23249ac4 3607static inline bool
6fb5fa3c 3608df_ignore_stack_reg (int regno)
23249ac4 3609{
6fb5fa3c
DB
3610 return regstack_completed
3611 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
3612}
23249ac4 3613#else
6fb5fa3c
DB
3614static inline bool
3615df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
3616{
23249ac4 3617 return false;
23249ac4 3618}
6fb5fa3c 3619#endif
23249ac4
DB
3620
3621
6fb5fa3c
DB
3622/* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
3623 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
23249ac4
DB
3624
3625static void
6fb5fa3c 3626df_kill_notes (rtx insn, rtx *old_dead_notes, rtx *old_unused_notes)
23249ac4
DB
3627{
3628 rtx *pprev = &REG_NOTES (insn);
3629 rtx link = *pprev;
6fb5fa3c
DB
3630 rtx dead = NULL;
3631 rtx unused = NULL;
3632
23249ac4
DB
3633 while (link)
3634 {
3635 switch (REG_NOTE_KIND (link))
3636 {
3637 case REG_DEAD:
6fb5fa3c
DB
3638 /* After reg-stack, we need to ignore any unused notes
3639 for the stack registers. */
3640 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3641 {
3642 pprev = &XEXP (link, 1);
3643 link = *pprev;
3644 }
3645 else
3646 {
3647 rtx next = XEXP (link, 1);
3648#ifdef REG_DEAD_DEBUGGING
3649 df_print_note ("deleting: ", insn, link);
3650#endif
3651 XEXP (link, 1) = dead;
3652 dead = link;
3653 *pprev = link = next;
3654 }
3655 break;
23249ac4 3656
23249ac4 3657 case REG_UNUSED:
6fb5fa3c
DB
3658 /* After reg-stack, we need to ignore any unused notes
3659 for the stack registers. */
3660 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
3661 {
3662 pprev = &XEXP (link, 1);
3663 link = *pprev;
3664 }
3665 else
23249ac4
DB
3666 {
3667 rtx next = XEXP (link, 1);
3668#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3669 df_print_note ("deleting: ", insn, link);
23249ac4 3670#endif
6fb5fa3c
DB
3671 XEXP (link, 1) = unused;
3672 unused = link;
23249ac4
DB
3673 *pprev = link = next;
3674 }
3675 break;
3676
3677 default:
3678 pprev = &XEXP (link, 1);
3679 link = *pprev;
3680 break;
3681 }
3682 }
6fb5fa3c
DB
3683
3684 *old_dead_notes = dead;
3685 *old_unused_notes = unused;
23249ac4
DB
3686}
3687
3688
6fb5fa3c
DB
3689/* Set a NOTE_TYPE note for REG in INSN. Try to pull it from the OLD
3690 list, otherwise create a new one. */
3691
3692static inline rtx
3693df_set_note (enum reg_note note_type, rtx insn, rtx old, rtx reg)
3694{
3695 rtx this = old;
3696 rtx prev = NULL;
3697
3698 while (this)
3699 if (XEXP (this, 0) == reg)
3700 {
3701 if (prev)
3702 XEXP (prev, 1) = XEXP (this, 1);
3703 else
3704 old = XEXP (this, 1);
3705 XEXP (this, 1) = REG_NOTES (insn);
3706 REG_NOTES (insn) = this;
3707 return old;
3708 }
3709 else
3710 {
3711 prev = this;
3712 this = XEXP (this, 1);
3713 }
3714
3715 /* Did not find the note. */
3716 REG_NOTES (insn) = alloc_EXPR_LIST (note_type, reg, REG_NOTES (insn));
3717 return old;
3718}
3719
23249ac4
DB
3720/* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
3721 based on the bits in LIVE. Do not generate notes for registers in
3722 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
3723 not generated if the reg is both read and written by the
3724 instruction.
3725*/
3726
6fb5fa3c
DB
3727static rtx
3728df_set_unused_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
23249ac4 3729 bitmap live, bitmap do_not_gen,
6fb5fa3c 3730 bitmap artificial_uses)
23249ac4
DB
3731{
3732 bool all_dead = true;
6fb5fa3c 3733 unsigned int r;
23249ac4
DB
3734
3735#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
3736 if (dump_file)
3737 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
3738 mws->start_regno, mws->end_regno);
23249ac4 3739#endif
6fb5fa3c
DB
3740 for (r=mws->start_regno; r <= mws->end_regno; r++)
3741 if ((bitmap_bit_p (live, r))
3742 || bitmap_bit_p (artificial_uses, r))
3743 {
3744 all_dead = false;
3745 break;
3746 }
23249ac4
DB
3747
3748 if (all_dead)
3749 {
6fb5fa3c
DB
3750 unsigned int regno = mws->start_regno;
3751 old = df_set_note (REG_UNUSED, insn, old, *(mws->loc));
3752
23249ac4 3753#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3754 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
23249ac4
DB
3755#endif
3756 bitmap_set_bit (do_not_gen, regno);
3757 /* Only do this if the value is totally dead. */
23249ac4
DB
3758 }
3759 else
6fb5fa3c
DB
3760 for (r=mws->start_regno; r <= mws->end_regno; r++)
3761 {
3762
3763 if ((!bitmap_bit_p (live, r))
3764 && (!bitmap_bit_p (artificial_uses, r)))
3765 {
3766 old = df_set_note (REG_UNUSED, insn, old, regno_reg_rtx[r]);
23249ac4 3767#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3768 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
23249ac4 3769#endif
6fb5fa3c
DB
3770 }
3771 bitmap_set_bit (do_not_gen, r);
3772 }
3773 return old;
23249ac4
DB
3774}
3775
3776
3777/* Set the REG_DEAD notes for the multiword hardreg use in INSN based
3778 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
3779 from being set if the instruction both reads and writes the
3780 register. */
3781
6fb5fa3c
DB
3782static rtx
3783df_set_dead_notes_for_mw (rtx insn, rtx old, struct df_mw_hardreg *mws,
23249ac4 3784 bitmap live, bitmap do_not_gen,
6fb5fa3c 3785 bitmap artificial_uses)
23249ac4
DB
3786{
3787 bool all_dead = true;
6fb5fa3c 3788 unsigned int r;
23249ac4
DB
3789
3790#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3791 if (dump_file)
23249ac4 3792 {
6fb5fa3c
DB
3793 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
3794 mws->start_regno, mws->end_regno);
3795 df_print_regset (dump_file, do_not_gen);
3796 fprintf (dump_file, " live =");
3797 df_print_regset (dump_file, live);
3798 fprintf (dump_file, " artificial uses =");
3799 df_print_regset (dump_file, artificial_uses);
23249ac4 3800 }
6fb5fa3c
DB
3801#endif
3802
3803 for (r = mws->start_regno; r <= mws->end_regno; r++)
3804 if ((bitmap_bit_p (live, r))
3805 || bitmap_bit_p (artificial_uses, r)
3806 || bitmap_bit_p (do_not_gen, r))
3807 {
3808 all_dead = false;
3809 break;
3810 }
23249ac4
DB
3811
3812 if (all_dead)
3813 {
6fb5fa3c 3814 if (!bitmap_bit_p (do_not_gen, mws->start_regno))
23249ac4
DB
3815 {
3816 /* Add a dead note for the entire multi word register. */
6fb5fa3c 3817 old = df_set_note (REG_DEAD, insn, old, *(mws->loc));
23249ac4 3818#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3819 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
23249ac4 3820#endif
23249ac4
DB
3821 }
3822 }
3823 else
3824 {
6fb5fa3c 3825 for (r = mws->start_regno; r <= mws->end_regno; r++)
23249ac4 3826 {
6fb5fa3c
DB
3827 if ((!bitmap_bit_p (live, r))
3828 && (!bitmap_bit_p (artificial_uses, r))
3829 && (!bitmap_bit_p (do_not_gen, r)))
23249ac4 3830 {
6fb5fa3c 3831 old = df_set_note (REG_DEAD, insn, old, regno_reg_rtx[r]);
23249ac4 3832#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3833 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
23249ac4
DB
3834#endif
3835 }
23249ac4
DB
3836 }
3837 }
6fb5fa3c 3838 return old;
23249ac4
DB
3839}
3840
3841
3842/* Create a REG_UNUSED note if necessary for DEF in INSN updating LIVE
3843 and DO_NOT_GEN. Do not generate notes for registers in artificial
3844 uses. */
3845
6fb5fa3c
DB
3846static rtx
3847df_create_unused_note (rtx insn, rtx old, struct df_ref *def,
3848 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
23249ac4
DB
3849{
3850 unsigned int dregno = DF_REF_REGNO (def);
3851
3852#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3853 if (dump_file)
23249ac4 3854 {
6fb5fa3c
DB
3855 fprintf (dump_file, " regular looking at def ");
3856 df_ref_debug (def, dump_file);
23249ac4 3857 }
6fb5fa3c
DB
3858#endif
3859
3860 if (!(bitmap_bit_p (live, dregno)
3861 || (DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3862 || bitmap_bit_p (artificial_uses, dregno)
3863 || df_ignore_stack_reg (dregno)))
23249ac4 3864 {
6fb5fa3c
DB
3865 rtx reg = (DF_REF_LOC (def))
3866 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
3867 old = df_set_note (REG_UNUSED, insn, old, reg);
23249ac4 3868#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3869 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
23249ac4 3870#endif
23249ac4
DB
3871 }
3872
23249ac4
DB
3873 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER + DF_REF_MAY_CLOBBER)))
3874 bitmap_set_bit (do_not_gen, dregno);
3875
6fb5fa3c
DB
3876 /* Kill this register if it is not a subreg store or conditional store. */
3877 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
23249ac4 3878 bitmap_clear_bit (live, dregno);
6fb5fa3c 3879 return old;
4d779342
DB
3880}
3881
23249ac4
DB
3882
3883/* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3884 info: lifetime, bb, and number of defs and uses for basic block
3885 BB. The three bitvectors are scratch regs used here. */
4d779342
DB
3886
3887static void
6fb5fa3c
DB
3888df_note_bb_compute (unsigned int bb_index,
3889 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
4d779342 3890{
4d779342
DB
3891 basic_block bb = BASIC_BLOCK (bb_index);
3892 rtx insn;
6fb5fa3c
DB
3893 struct df_ref **def_rec;
3894 struct df_ref **use_rec;
23249ac4 3895
6fb5fa3c 3896 bitmap_copy (live, df_get_live_out (bb));
23249ac4
DB
3897 bitmap_clear (artificial_uses);
3898
6fb5fa3c
DB
3899#ifdef REG_DEAD_DEBUGGING
3900 if (dump_file)
23249ac4 3901 {
6fb5fa3c
DB
3902 fprintf (dump_file, "live at bottom ");
3903 df_print_regset (dump_file, live);
23249ac4 3904 }
6fb5fa3c 3905#endif
23249ac4
DB
3906
3907 /* Process the artificial defs and uses at the bottom of the block
3908 to begin processing. */
6fb5fa3c
DB
3909 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3910 {
3911 struct df_ref *def = *def_rec;
8b9d606b 3912#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
3913 if (dump_file)
3914 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
8b9d606b 3915#endif
4d779342 3916
6fb5fa3c
DB
3917 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3918 bitmap_clear_bit (live, DF_REF_REGNO (def));
3919 }
4d779342 3920
6fb5fa3c
DB
3921 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3922 {
3923 struct df_ref *use = *use_rec;
3924 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3925 {
3926 unsigned int regno = DF_REF_REGNO (use);
3927 bitmap_set_bit (live, regno);
3928
3929 /* Notes are not generated for any of the artificial registers
3930 at the bottom of the block. */
3931 bitmap_set_bit (artificial_uses, regno);
3932 }
3933 }
23249ac4 3934
6fb5fa3c
DB
3935#ifdef REG_DEAD_DEBUGGING
3936 if (dump_file)
3937 {
3938 fprintf (dump_file, "live before artificials out ");
3939 df_print_regset (dump_file, live);
3940 }
3941#endif
3942
4d779342
DB
3943 FOR_BB_INSNS_REVERSE (bb, insn)
3944 {
3945 unsigned int uid = INSN_UID (insn);
6fb5fa3c
DB
3946 struct df_mw_hardreg **mws_rec;
3947 rtx old_dead_notes;
3948 rtx old_unused_notes;
3949
23249ac4 3950 if (!INSN_P (insn))
4d779342
DB
3951 continue;
3952
23249ac4 3953 bitmap_clear (do_not_gen);
6fb5fa3c 3954 df_kill_notes (insn, &old_dead_notes, &old_unused_notes);
23249ac4
DB
3955
3956 /* Process the defs. */
3957 if (CALL_P (insn))
3958 {
6fb5fa3c
DB
3959#ifdef REG_DEAD_DEBUGGING
3960 if (dump_file)
23249ac4 3961 {
6fb5fa3c
DB
3962 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3963 df_print_regset (dump_file, live);
23249ac4 3964 }
6fb5fa3c 3965#endif
e44e043c
KZ
3966 /* We only care about real sets for calls. Clobbers cannot
3967 be depended on to really die. */
6fb5fa3c
DB
3968 mws_rec = DF_INSN_UID_MWS (uid);
3969 while (*mws_rec)
23249ac4 3970 {
6fb5fa3c 3971 struct df_mw_hardreg *mws = *mws_rec;
23249ac4
DB
3972 if ((mws->type == DF_REF_REG_DEF)
3973 && !df_ignore_stack_reg (REGNO (mws->mw_reg)))
6fb5fa3c
DB
3974 old_unused_notes
3975 = df_set_unused_notes_for_mw (insn, old_unused_notes,
3976 mws, live, do_not_gen,
3977 artificial_uses);
3978 mws_rec++;
23249ac4
DB
3979 }
3980
3981 /* All of the defs except the return value are some sort of
3982 clobber. This code is for the return. */
6fb5fa3c
DB
3983 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3984 {
3985 struct df_ref *def = *def_rec;
3986 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
3987 old_unused_notes
3988 = df_create_unused_note (insn, old_unused_notes,
3989 def, live, do_not_gen,
3990 artificial_uses);
e44e043c
KZ
3991
3992 /* However a may or must clobber still needs to kill the
3993 reg so that REG_DEAD notes are later placed
3994 appropriately. */
3995 else
3996 bitmap_clear_bit (live, DF_REF_REGNO (def));
6fb5fa3c 3997 }
23249ac4
DB
3998 }
3999 else
4000 {
4001 /* Regular insn. */
6fb5fa3c
DB
4002 mws_rec = DF_INSN_UID_MWS (uid);
4003 while (*mws_rec)
23249ac4 4004 {
6fb5fa3c 4005 struct df_mw_hardreg *mws = *mws_rec;
23249ac4 4006 if (mws->type == DF_REF_REG_DEF)
6fb5fa3c
DB
4007 old_unused_notes
4008 = df_set_unused_notes_for_mw (insn, old_unused_notes,
4009 mws, live, do_not_gen,
4010 artificial_uses);
4011 mws_rec++;
23249ac4
DB
4012 }
4013
6fb5fa3c
DB
4014 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4015 {
4016 struct df_ref *def = *def_rec;
4017 old_unused_notes
4018 = df_create_unused_note (insn, old_unused_notes,
4019 def, live, do_not_gen,
4020 artificial_uses);
4021 }
23249ac4
DB
4022 }
4023
4024 /* Process the uses. */
6fb5fa3c
DB
4025 mws_rec = DF_INSN_UID_MWS (uid);
4026 while (*mws_rec)
23249ac4 4027 {
6fb5fa3c 4028 struct df_mw_hardreg *mws = *mws_rec;
23249ac4
DB
4029 if ((mws->type != DF_REF_REG_DEF)
4030 && !df_ignore_stack_reg (REGNO (mws->mw_reg)))
6fb5fa3c
DB
4031 old_dead_notes
4032 = df_set_dead_notes_for_mw (insn, old_dead_notes,
4033 mws, live, do_not_gen,
4034 artificial_uses);
4035 mws_rec++;
4d779342
DB
4036 }
4037
6fb5fa3c 4038 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
4d779342 4039 {
6fb5fa3c 4040 struct df_ref *use = *use_rec;
4d779342
DB
4041 unsigned int uregno = DF_REF_REGNO (use);
4042
6fb5fa3c
DB
4043#ifdef REG_DEAD_DEBUGGING
4044 if (dump_file)
23249ac4 4045 {
6fb5fa3c
DB
4046 fprintf (dump_file, " regular looking at use ");
4047 df_ref_debug (use, dump_file);
23249ac4 4048 }
23249ac4 4049#endif
912f2dac
DB
4050 if (!bitmap_bit_p (live, uregno))
4051 {
23249ac4
DB
4052 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG))
4053 && (!bitmap_bit_p (do_not_gen, uregno))
4054 && (!bitmap_bit_p (artificial_uses, uregno))
4055 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE))
4056 && (!df_ignore_stack_reg (uregno)))
4057 {
6fb5fa3c
DB
4058 rtx reg = (DF_REF_LOC (use))
4059 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
4060 old_dead_notes = df_set_note (REG_DEAD, insn, old_dead_notes, reg);
23249ac4
DB
4061
4062#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 4063 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
23249ac4
DB
4064#endif
4065 }
912f2dac
DB
4066 /* This register is now live. */
4067 bitmap_set_bit (live, uregno);
4068 }
4d779342 4069 }
6fb5fa3c
DB
4070
4071 while (old_unused_notes)
4d779342 4072 {
6fb5fa3c
DB
4073 rtx next = XEXP (old_unused_notes, 1);
4074 free_EXPR_LIST_node (old_unused_notes);
4075 old_unused_notes = next;
4076 }
4077 while (old_dead_notes)
4078 {
4079 rtx next = XEXP (old_dead_notes, 1);
4080 free_EXPR_LIST_node (old_dead_notes);
4081 old_dead_notes = next;
4d779342
DB
4082 }
4083 }
4084}
4085
4086
4087/* Compute register info: lifetime, bb, and number of defs and uses. */
4088static void
6fb5fa3c 4089df_note_compute (bitmap all_blocks)
4d779342
DB
4090{
4091 unsigned int bb_index;
4092 bitmap_iterator bi;
6fb5fa3c
DB
4093 bitmap live = BITMAP_ALLOC (&df_bitmap_obstack);
4094 bitmap do_not_gen = BITMAP_ALLOC (&df_bitmap_obstack);
4095 bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack);
23249ac4
DB
4096
4097#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
4098 if (dump_file)
4099 print_rtl_with_bb (dump_file, get_insns());
23249ac4 4100#endif
4d779342 4101
6fb5fa3c 4102 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 4103 {
6fb5fa3c 4104 df_note_bb_compute (bb_index, live, do_not_gen, artificial_uses);
4d779342
DB
4105 }
4106
4107 BITMAP_FREE (live);
23249ac4
DB
4108 BITMAP_FREE (do_not_gen);
4109 BITMAP_FREE (artificial_uses);
4d779342
DB
4110}
4111
4112
4113/* Free all storage associated with the problem. */
4114
4115static void
6fb5fa3c 4116df_note_free (void)
4d779342 4117{
6fb5fa3c 4118 free (df_note);
4d779342
DB
4119}
4120
4121
4d779342
DB
4122/* All of the information associated every instance of the problem. */
4123
6fb5fa3c 4124static struct df_problem problem_NOTE =
4d779342 4125{
6fb5fa3c 4126 DF_NOTE, /* Problem id. */
4d779342 4127 DF_NONE, /* Direction. */
89a95777 4128 df_note_alloc, /* Allocate the problem specific data. */
30cb87a0 4129 NULL, /* Reset global information. */
4d779342 4130 NULL, /* Free basic block info. */
6fb5fa3c 4131 df_note_compute, /* Local compute function. */
4d779342
DB
4132 NULL, /* Init the solution specific data. */
4133 NULL, /* Iterative solver. */
4134 NULL, /* Confluence operator 0. */
4135 NULL, /* Confluence operator n. */
4136 NULL, /* Transfer function. */
4137 NULL, /* Finalize function. */
6fb5fa3c
DB
4138 df_note_free, /* Free all of the problem information. */
4139 df_note_free, /* Remove this problem from the stack of dataflow problems. */
4140 NULL, /* Debugging. */
4141 NULL, /* Debugging start block. */
4142 NULL, /* Debugging end block. */
4143 NULL, /* Incremental solution verify start. */
4144 NULL, /* Incremental solution verfiy end. */
23249ac4
DB
4145
4146 /* Technically this is only dependent on the live registers problem
6fc0bb99 4147 but it will produce information if built one of uninitialized
23249ac4 4148 register problems (UR, UREC) is also run. */
6fb5fa3c 4149 &problem_LR, /* Dependent problem. */
89a95777
KZ
4150 TV_DF_NOTE, /* Timing variable. */
4151 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
4152};
4153
4154
4155/* Create a new DATAFLOW instance and add it to an existing instance
4156 of DF. The returned structure is what is used to get at the
4157 solution. */
4158
6fb5fa3c
DB
4159void
4160df_note_add_problem (void)
4d779342 4161{
6fb5fa3c 4162 df_add_problem (&problem_NOTE);
4d779342 4163}
6fb5fa3c
DB
4164
4165
4166
4167\f
4168/*----------------------------------------------------------------------------
4169 Functions for simulating the effects of single insns.
4170
4171 You can either simulate in the forwards direction, starting from
4172 the top of a block or the backwards direction from the end of the
4173 block. The main difference is that if you go forwards, the uses
4174 are examined first then the defs, and if you go backwards, the defs
4175 are examined first then the uses.
4176
4177 If you start at the top of the block, use one of DF_LIVE_IN or
4178 DF_LR_IN. If you start at the bottom of the block use one of
4179 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
4180 THEY WILL BE DESTROYED.
4181
4182----------------------------------------------------------------------------*/
4183
4184
4185/* Find the set of DEFs for INSN. */
4186
4187void
4188df_simulate_find_defs (rtx insn, bitmap defs)
4189{
4190 struct df_ref **def_rec;
4191 unsigned int uid = INSN_UID (insn);
4192
4193 if (CALL_P (insn))
4194 {
4195 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4196 {
4197 struct df_ref *def = *def_rec;
4198 unsigned int dregno = DF_REF_REGNO (def);
4199
4200 if (DF_REF_FLAGS (def) & DF_REF_MUST_CLOBBER)
4201 {
4202 if (dregno >= FIRST_PSEUDO_REGISTER
4203 || !(SIBLING_CALL_P (insn)
4204 && bitmap_bit_p (df->exit_block_uses, dregno)
4205 && !refers_to_regno_p (dregno, dregno+1,
4206 current_function_return_rtx,
4207 (rtx *)0)))
4208 {
4209 /* If the def is to only part of the reg, it does
4210 not kill the other defs that reach here. */
4211 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4212 bitmap_set_bit (defs, dregno);
4213 }
4214 }
4215 else
4216 /* This is the return value. */
4217 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4218 bitmap_set_bit (defs, dregno);
4219 }
4220 }
4221 else
4222 {
4223 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4224 {
4225 struct df_ref *def = *def_rec;
4226 /* If the def is to only part of the reg, it does
4227 not kill the other defs that reach here. */
4228 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4229 bitmap_set_bit (defs, DF_REF_REGNO (def));
4230 }
4231 }
4232}
4233
4234
4235/* Simulate the effects of the defs of INSN on LIVE. */
4236
4237void
4238df_simulate_defs (rtx insn, bitmap live)
4239{
4240 struct df_ref **def_rec;
4241 unsigned int uid = INSN_UID (insn);
4242
4243 if (CALL_P (insn))
4244 {
4245 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4246 {
4247 struct df_ref *def = *def_rec;
4248 unsigned int dregno = DF_REF_REGNO (def);
4249
4250 if (DF_REF_FLAGS (def) & DF_REF_MUST_CLOBBER)
4251 {
4252 if (dregno >= FIRST_PSEUDO_REGISTER
4253 || !(SIBLING_CALL_P (insn)
4254 && bitmap_bit_p (df->exit_block_uses, dregno)
4255 && !refers_to_regno_p (dregno, dregno+1,
4256 current_function_return_rtx,
4257 (rtx *)0)))
4258 {
4259 /* If the def is to only part of the reg, it does
4260 not kill the other defs that reach here. */
4261 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4262 bitmap_clear_bit (live, dregno);
4263 }
4264 }
4265 else
4266 /* This is the return value. */
4267 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4268 bitmap_clear_bit (live, dregno);
4269 }
4270 }
4271 else
4272 {
4273 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4274 {
4275 struct df_ref *def = *def_rec;
4276 unsigned int dregno = DF_REF_REGNO (def);
4277
4278 /* If the def is to only part of the reg, it does
4279 not kill the other defs that reach here. */
4280 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4281 bitmap_clear_bit (live, dregno);
4282 }
4283 }
4284}
4285
4286
4287/* Simulate the effects of the uses of INSN on LIVE. */
4288
4289void
4290df_simulate_uses (rtx insn, bitmap live)
4291{
4292 struct df_ref **use_rec;
4293 unsigned int uid = INSN_UID (insn);
4294
4295 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
4296 {
4297 struct df_ref *use = *use_rec;
4298 /* Add use to set of uses in this BB. */
4299 bitmap_set_bit (live, DF_REF_REGNO (use));
4300 }
4301}
4302
4303
4304/* Add back the always live regs in BB to LIVE. */
4305
4306static inline void
4307df_simulate_fixup_sets (basic_block bb, bitmap live)
4308{
4309 /* These regs are considered always live so if they end up dying
4310 because of some def, we need to bring the back again. */
4311 if (df_has_eh_preds (bb))
4312 bitmap_ior_into (live, df->eh_block_artificial_uses);
4313 else
4314 bitmap_ior_into (live, df->regular_block_artificial_uses);
4315}
4316
4317
0d52bcc1 4318/* Apply the artificial uses and defs at the top of BB in a forwards
6fb5fa3c
DB
4319 direction. */
4320
4321void
4322df_simulate_artificial_refs_at_top (basic_block bb, bitmap live)
4323{
4324 struct df_ref **def_rec;
4325 struct df_ref **use_rec;
4326 int bb_index = bb->index;
4327
4328 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4329 {
4330 struct df_ref *use = *use_rec;
4331 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
4332 bitmap_set_bit (live, DF_REF_REGNO (use));
4333 }
4334
4335 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4336 {
4337 struct df_ref *def = *def_rec;
4338 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4339 bitmap_clear_bit (live, DF_REF_REGNO (def));
4340 }
4341}
4342
4343
4344/* Simulate the forwards effects of INSN on the bitmap LIVE. */
4345
4346void
4347df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
4348{
4349 if (! INSN_P (insn))
4350 return;
4351
4352 df_simulate_uses (insn, live);
4353 df_simulate_defs (insn, live);
4354 df_simulate_fixup_sets (bb, live);
4355}
4356
4357
0d52bcc1 4358/* Apply the artificial uses and defs at the end of BB in a backwards
6fb5fa3c
DB
4359 direction. */
4360
4361void
4362df_simulate_artificial_refs_at_end (basic_block bb, bitmap live)
4363{
4364 struct df_ref **def_rec;
4365 struct df_ref **use_rec;
4366 int bb_index = bb->index;
4367
4368 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4369 {
4370 struct df_ref *def = *def_rec;
4371 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
4372 bitmap_clear_bit (live, DF_REF_REGNO (def));
4373 }
4374
4375 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
4376 {
4377 struct df_ref *use = *use_rec;
4378 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
4379 bitmap_set_bit (live, DF_REF_REGNO (use));
4380 }
4381}
4382
4383
4384/* Simulate the backwards effects of INSN on the bitmap LIVE. */
4385
4386void
4387df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
4388{
4389 if (! INSN_P (insn))
4390 return;
4391
4392 df_simulate_defs (insn, live);
4393 df_simulate_uses (insn, live);
4394 df_simulate_fixup_sets (bb, live);
4395}
4396
4397