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