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