]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/df-problems.c
Mark __dso_handle hidden if assembler supports it.
[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,
f773c2bd 3 2008, 2009, 2010, 2011 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"
35#include "output.h"
36#include "alloc-pool.h"
37#include "flags.h"
38#include "hard-reg-set.h"
39#include "basic-block.h"
40#include "sbitmap.h"
41#include "bitmap.h"
4ec5d4f5 42#include "target.h"
4d779342
DB
43#include "timevar.h"
44#include "df.h"
23249ac4 45#include "except.h"
6fb5fa3c
DB
46#include "dce.h"
47#include "vecprim.h"
23249ac4 48
e44e043c
KZ
49/* Note that turning REG_DEAD_DEBUGGING on will cause
50 gcc.c-torture/unsorted/dump-noaddr.c to fail because it prints
b8698a0f 51 addresses in the dumps. */
23249ac4
DB
52#if 0
53#define REG_DEAD_DEBUGGING
54#endif
4d779342
DB
55
56#define DF_SPARSE_THRESHOLD 32
57
5c72d561
JH
58static bitmap_head seen_in_block;
59static bitmap_head seen_in_insn;
4d779342
DB
60
61\f
62/*----------------------------------------------------------------------------
63 Public functions access functions for the dataflow problems.
64----------------------------------------------------------------------------*/
6fb5fa3c
DB
65/* Get the live at out set for BB no matter what problem happens to be
66 defined. This function is used by the register allocators who
67 choose different dataflow problems depending on the optimization
68 level. */
4d779342 69
6fb5fa3c
DB
70bitmap
71df_get_live_out (basic_block bb)
4d779342 72{
6fb5fa3c 73 gcc_assert (df_lr);
4d779342 74
ba49cb7b 75 if (df_live)
6fb5fa3c 76 return DF_LIVE_OUT (bb);
b8698a0f 77 else
6fb5fa3c 78 return DF_LR_OUT (bb);
4d779342
DB
79}
80
6fb5fa3c
DB
81/* Get the live at in set for BB no matter what problem happens to be
82 defined. This function is used by the register allocators who
83 choose different dataflow problems depending on the optimization
84 level. */
4d779342
DB
85
86bitmap
6fb5fa3c 87df_get_live_in (basic_block bb)
4d779342 88{
6fb5fa3c 89 gcc_assert (df_lr);
4d779342 90
ba49cb7b 91 if (df_live)
6fb5fa3c 92 return DF_LIVE_IN (bb);
b8698a0f 93 else
6fb5fa3c 94 return DF_LR_IN (bb);
4d779342
DB
95}
96
4d779342
DB
97/*----------------------------------------------------------------------------
98 Utility functions.
99----------------------------------------------------------------------------*/
100
101/* Generic versions to get the void* version of the block info. Only
c0220ea4 102 used inside the problem instance vectors. */
4d779342 103
4d779342
DB
104/* Dump a def-use or use-def chain for REF to FILE. */
105
106void
23249ac4 107df_chain_dump (struct df_link *link, FILE *file)
4d779342
DB
108{
109 fprintf (file, "{ ");
110 for (; link; link = link->next)
111 {
112 fprintf (file, "%c%d(bb %d insn %d) ",
885c9b5d
EB
113 DF_REF_REG_DEF_P (link->ref)
114 ? 'd'
115 : (DF_REF_FLAGS (link->ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
4d779342
DB
116 DF_REF_ID (link->ref),
117 DF_REF_BBNO (link->ref),
885c9b5d
EB
118 DF_REF_IS_ARTIFICIAL (link->ref)
119 ? -1 : DF_REF_INSN_UID (link->ref));
4d779342
DB
120 }
121 fprintf (file, "}");
122}
123
124
125/* Print some basic block info as part of df_dump. */
126
b8698a0f 127void
4d779342
DB
128df_print_bb_index (basic_block bb, FILE *file)
129{
130 edge e;
131 edge_iterator ei;
132
6fb5fa3c 133 fprintf (file, "\n( ");
4d779342
DB
134 FOR_EACH_EDGE (e, ei, bb->preds)
135 {
136 basic_block pred = e->src;
6fb5fa3c 137 fprintf (file, "%d%s ", pred->index, e->flags & EDGE_EH ? "(EH)" : "");
b8698a0f 138 }
4d779342
DB
139 fprintf (file, ")->[%d]->( ", bb->index);
140 FOR_EACH_EDGE (e, ei, bb->succs)
141 {
142 basic_block succ = e->dest;
6fb5fa3c 143 fprintf (file, "%d%s ", succ->index, e->flags & EDGE_EH ? "(EH)" : "");
b8698a0f 144 }
4d779342
DB
145 fprintf (file, ")\n");
146}
147
4d779342
DB
148\f
149/*----------------------------------------------------------------------------
150 REACHING DEFINITIONS
151
152 Find the locations in the function where each definition site for a
b11550aa
KZ
153 pseudo reaches. In and out bitvectors are built for each basic
154 block. The id field in the ref is used to index into these sets.
155 See df.h for details.
156 ----------------------------------------------------------------------------*/
157
ba49cb7b 158/* This problem plays a large number of games for the sake of
b8698a0f
L
159 efficiency.
160
ba49cb7b
KZ
161 1) The order of the bits in the bitvectors. After the scanning
162 phase, all of the defs are sorted. All of the defs for the reg 0
163 are first, followed by all defs for reg 1 and so on.
b8698a0f 164
ba49cb7b
KZ
165 2) There are two kill sets, one if the number of defs is less or
166 equal to DF_SPARSE_THRESHOLD and another if the number of defs is
167 greater.
168
169 <= : Data is built directly in the kill set.
170
171 > : One level of indirection is used to keep from generating long
172 strings of 1 bits in the kill sets. Bitvectors that are indexed
173 by the regnum are used to represent that there is a killing def
174 for the register. The confluence and transfer functions use
175 these along with the bitmap_clear_range call to remove ranges of
176 bits without actually generating a knockout vector.
177
178 The kill and sparse_kill and the dense_invalidated_by_call and
179 sparse_invalidated_by_call both play this game. */
4d779342 180
b11550aa 181/* Private data used to compute the solution for this problem. These
6fc0bb99 182 data structures are not accessible outside of this module. */
4d779342
DB
183struct df_rd_problem_data
184{
4d779342 185 /* The set of defs to regs invalidated by call. */
5c72d561 186 bitmap_head sparse_invalidated_by_call;
b8698a0f 187 /* The set of defs to regs invalidate by call for rd. */
5c72d561 188 bitmap_head dense_invalidated_by_call;
6fb5fa3c
DB
189 /* An obstack for the bitmaps we need for this problem. */
190 bitmap_obstack rd_bitmaps;
4d779342
DB
191};
192
4d779342
DB
193
194/* Free basic block info. */
195
196static void
b8698a0f 197df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 198 void *vbb_info)
4d779342
DB
199{
200 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
201 if (bb_info)
202 {
b33a91c9
JH
203 bitmap_clear (&bb_info->kill);
204 bitmap_clear (&bb_info->sparse_kill);
205 bitmap_clear (&bb_info->gen);
206 bitmap_clear (&bb_info->in);
207 bitmap_clear (&bb_info->out);
4d779342
DB
208 }
209}
210
211
6fb5fa3c 212/* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
4d779342
DB
213 not touched unless the block is new. */
214
b8698a0f 215static void
6fb5fa3c 216df_rd_alloc (bitmap all_blocks)
4d779342
DB
217{
218 unsigned int bb_index;
219 bitmap_iterator bi;
6fb5fa3c 220 struct df_rd_problem_data *problem_data;
4d779342 221
6fb5fa3c 222 if (df_rd->problem_data)
4d779342 223 {
6fb5fa3c 224 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
5c72d561
JH
225 bitmap_clear (&problem_data->sparse_invalidated_by_call);
226 bitmap_clear (&problem_data->dense_invalidated_by_call);
4d779342 227 }
b8698a0f 228 else
4d779342 229 {
6fb5fa3c
DB
230 problem_data = XNEW (struct df_rd_problem_data);
231 df_rd->problem_data = problem_data;
232
233 bitmap_obstack_initialize (&problem_data->rd_bitmaps);
5c72d561
JH
234 bitmap_initialize (&problem_data->sparse_invalidated_by_call,
235 &problem_data->rd_bitmaps);
236 bitmap_initialize (&problem_data->dense_invalidated_by_call,
237 &problem_data->rd_bitmaps);
4d779342
DB
238 }
239
6fb5fa3c 240 df_grow_bb_info (df_rd);
4d779342 241
23249ac4 242 /* Because of the clustering of all use sites for the same pseudo,
4d779342
DB
243 we have to process all of the blocks before doing the
244 analysis. */
245
23249ac4 246 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 247 {
6fb5fa3c 248 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
e285df08
JH
249
250 /* When bitmaps are already initialized, just clear them. */
251 if (bb_info->kill.obstack)
b8698a0f 252 {
b33a91c9
JH
253 bitmap_clear (&bb_info->kill);
254 bitmap_clear (&bb_info->sparse_kill);
255 bitmap_clear (&bb_info->gen);
4d779342
DB
256 }
257 else
b8698a0f 258 {
b33a91c9
JH
259 bitmap_initialize (&bb_info->kill, &problem_data->rd_bitmaps);
260 bitmap_initialize (&bb_info->sparse_kill, &problem_data->rd_bitmaps);
261 bitmap_initialize (&bb_info->gen, &problem_data->rd_bitmaps);
262 bitmap_initialize (&bb_info->in, &problem_data->rd_bitmaps);
263 bitmap_initialize (&bb_info->out, &problem_data->rd_bitmaps);
4d779342
DB
264 }
265 }
89a95777 266 df_rd->optional_p = true;
4d779342
DB
267}
268
269
00952e97
PB
270/* Add the effect of the top artificial defs of BB to the reaching definitions
271 bitmap LOCAL_RD. */
272
273void
274df_rd_simulate_artificial_defs_at_top (basic_block bb, bitmap local_rd)
275{
276 int bb_index = bb->index;
277 df_ref *def_rec;
278 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
279 {
280 df_ref def = *def_rec;
281 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
282 {
283 unsigned int dregno = DF_REF_REGNO (def);
284 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
b8698a0f
L
285 bitmap_clear_range (local_rd,
286 DF_DEFS_BEGIN (dregno),
00952e97
PB
287 DF_DEFS_COUNT (dregno));
288 bitmap_set_bit (local_rd, DF_REF_ID (def));
289 }
290 }
291}
292
293/* Add the effect of the defs of INSN to the reaching definitions bitmap
294 LOCAL_RD. */
295
296void
297df_rd_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
298 bitmap local_rd)
299{
300 unsigned uid = INSN_UID (insn);
301 df_ref *def_rec;
302
303 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
304 {
305 df_ref def = *def_rec;
306 unsigned int dregno = DF_REF_REGNO (def);
307 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
308 || (dregno >= FIRST_PSEUDO_REGISTER))
309 {
310 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
b8698a0f
L
311 bitmap_clear_range (local_rd,
312 DF_DEFS_BEGIN (dregno),
00952e97 313 DF_DEFS_COUNT (dregno));
b8698a0f 314 if (!(DF_REF_FLAGS (def)
00952e97
PB
315 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
316 bitmap_set_bit (local_rd, DF_REF_ID (def));
317 }
318 }
319}
320
321/* Process a list of DEFs for df_rd_bb_local_compute. This is a bit
322 more complicated than just simulating, because we must produce the
323 gen and kill sets and hence deal with the two possible representations
324 of kill sets. */
4d779342
DB
325
326static void
b8698a0f 327df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
57512f53 328 df_ref *def_rec,
bbbbb16a 329 int top_flag)
4d779342 330{
963acd6f 331 while (*def_rec)
4d779342 332 {
57512f53 333 df_ref def = *def_rec;
963acd6f 334 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4d779342 335 {
963acd6f 336 unsigned int regno = DF_REF_REGNO (def);
6fb5fa3c
DB
337 unsigned int begin = DF_DEFS_BEGIN (regno);
338 unsigned int n_defs = DF_DEFS_COUNT (regno);
b8698a0f 339
963acd6f
KZ
340 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
341 || (regno >= FIRST_PSEUDO_REGISTER))
342 {
343 /* Only the last def(s) for a regno in the block has any
b8698a0f 344 effect. */
5c72d561 345 if (!bitmap_bit_p (&seen_in_block, regno))
963acd6f
KZ
346 {
347 /* The first def for regno in insn gets to knock out the
348 defs from other instructions. */
5c72d561 349 if ((!bitmap_bit_p (&seen_in_insn, regno))
963acd6f
KZ
350 /* If the def is to only part of the reg, it does
351 not kill the other defs that reach here. */
b8698a0f 352 && (!(DF_REF_FLAGS (def) &
963acd6f
KZ
353 (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
354 {
355 if (n_defs > DF_SPARSE_THRESHOLD)
356 {
b33a91c9
JH
357 bitmap_set_bit (&bb_info->sparse_kill, regno);
358 bitmap_clear_range(&bb_info->gen, begin, n_defs);
963acd6f
KZ
359 }
360 else
361 {
b33a91c9
JH
362 bitmap_set_range (&bb_info->kill, begin, n_defs);
363 bitmap_clear_range (&bb_info->gen, begin, n_defs);
963acd6f
KZ
364 }
365 }
b8698a0f 366
5c72d561 367 bitmap_set_bit (&seen_in_insn, regno);
963acd6f
KZ
368 /* All defs for regno in the instruction may be put into
369 the gen set. */
b8698a0f 370 if (!(DF_REF_FLAGS (def)
963acd6f 371 & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
b33a91c9 372 bitmap_set_bit (&bb_info->gen, DF_REF_ID (def));
963acd6f
KZ
373 }
374 }
4d779342 375 }
963acd6f 376 def_rec++;
4d779342
DB
377 }
378}
379
380/* Compute local reaching def info for basic block BB. */
381
382static void
6fb5fa3c 383df_rd_bb_local_compute (unsigned int bb_index)
4d779342 384{
4d779342 385 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 386 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
387 rtx insn;
388
5c72d561
JH
389 bitmap_clear (&seen_in_block);
390 bitmap_clear (&seen_in_insn);
4d779342 391
6fb5fa3c
DB
392 /* Artificials are only hard regs. */
393 if (!(df->changeable_flags & DF_NO_HARD_REGS))
b8698a0f 394 df_rd_bb_local_compute_process_def (bb_info,
6fb5fa3c
DB
395 df_get_artificial_defs (bb_index),
396 0);
912f2dac 397
4d779342
DB
398 FOR_BB_INSNS_REVERSE (bb, insn)
399 {
400 unsigned int uid = INSN_UID (insn);
401
23249ac4 402 if (!INSN_P (insn))
4d779342
DB
403 continue;
404
b8698a0f 405 df_rd_bb_local_compute_process_def (bb_info,
6fb5fa3c 406 DF_INSN_UID_DEFS (uid), 0);
4d779342
DB
407
408 /* This complex dance with the two bitmaps is required because
409 instructions can assign twice to the same pseudo. This
410 generally happens with calls that will have one def for the
411 result and another def for the clobber. If only one vector
412 is used and the clobber goes first, the result will be
413 lost. */
5c72d561
JH
414 bitmap_ior_into (&seen_in_block, &seen_in_insn);
415 bitmap_clear (&seen_in_insn);
4d779342
DB
416 }
417
912f2dac
DB
418 /* Process the artificial defs at the top of the block last since we
419 are going backwards through the block and these are logically at
420 the start. */
6fb5fa3c 421 if (!(df->changeable_flags & DF_NO_HARD_REGS))
b8698a0f 422 df_rd_bb_local_compute_process_def (bb_info,
6fb5fa3c
DB
423 df_get_artificial_defs (bb_index),
424 DF_REF_AT_TOP);
4d779342
DB
425}
426
427
428/* Compute local reaching def info for each basic block within BLOCKS. */
429
430static void
6fb5fa3c 431df_rd_local_compute (bitmap all_blocks)
4d779342 432{
4d779342
DB
433 unsigned int bb_index;
434 bitmap_iterator bi;
435 unsigned int regno;
23249ac4 436 struct df_rd_problem_data *problem_data
6fb5fa3c 437 = (struct df_rd_problem_data *) df_rd->problem_data;
5c72d561
JH
438 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
439 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
4d779342 440
5c72d561
JH
441 bitmap_initialize (&seen_in_block, &df_bitmap_obstack);
442 bitmap_initialize (&seen_in_insn, &df_bitmap_obstack);
6fb5fa3c
DB
443
444 df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
4d779342
DB
445
446 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
447 {
6fb5fa3c 448 df_rd_bb_local_compute (bb_index);
4d779342 449 }
b8698a0f 450
4d779342 451 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
f2ecb626 452 EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, regno, bi)
4d779342 453 {
6fb5fa3c
DB
454 if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
455 bitmap_set_bit (sparse_invalidated, regno);
4d779342 456 else
b8698a0f
L
457 bitmap_set_range (dense_invalidated,
458 DF_DEFS_BEGIN (regno),
6fb5fa3c 459 DF_DEFS_COUNT (regno));
4d779342 460 }
4c78c26b 461
5c72d561
JH
462 bitmap_clear (&seen_in_block);
463 bitmap_clear (&seen_in_insn);
4d779342
DB
464}
465
466
467/* Initialize the solution bit vectors for problem. */
468
b8698a0f 469static void
6fb5fa3c 470df_rd_init_solution (bitmap all_blocks)
4d779342
DB
471{
472 unsigned int bb_index;
473 bitmap_iterator bi;
474
475 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
476 {
6fb5fa3c 477 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
b8698a0f 478
b33a91c9
JH
479 bitmap_copy (&bb_info->out, &bb_info->gen);
480 bitmap_clear (&bb_info->in);
4d779342
DB
481 }
482}
483
484/* In of target gets or of out of source. */
485
1a0f3fa1 486static bool
6fb5fa3c 487df_rd_confluence_n (edge e)
4d779342 488{
b33a91c9
JH
489 bitmap op1 = &df_rd_get_bb_info (e->dest->index)->in;
490 bitmap op2 = &df_rd_get_bb_info (e->src->index)->out;
1a0f3fa1 491 bool changed = false;
4d779342 492
b8698a0f 493 if (e->flags & EDGE_FAKE)
1a0f3fa1 494 return false;
2b49e1a0 495
963acd6f 496 if (e->flags & EDGE_EH)
4d779342 497 {
23249ac4 498 struct df_rd_problem_data *problem_data
6fb5fa3c 499 = (struct df_rd_problem_data *) df_rd->problem_data;
5c72d561
JH
500 bitmap sparse_invalidated = &problem_data->sparse_invalidated_by_call;
501 bitmap dense_invalidated = &problem_data->dense_invalidated_by_call;
4d779342
DB
502 bitmap_iterator bi;
503 unsigned int regno;
5c72d561 504 bitmap_head tmp;
59c52af4 505
5c72d561
JH
506 bitmap_initialize (&tmp, &df_bitmap_obstack);
507 bitmap_copy (&tmp, op2);
508 bitmap_and_compl_into (&tmp, dense_invalidated);
59c52af4 509
4d779342
DB
510 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
511 {
5c72d561 512 bitmap_clear_range (&tmp,
b8698a0f 513 DF_DEFS_BEGIN (regno),
6fb5fa3c 514 DF_DEFS_COUNT (regno));
4d779342 515 }
1a0f3fa1 516 changed |= bitmap_ior_into (op1, &tmp);
5c72d561 517 bitmap_clear (&tmp);
1a0f3fa1 518 return changed;
4d779342
DB
519 }
520 else
1a0f3fa1 521 return bitmap_ior_into (op1, op2);
4d779342
DB
522}
523
524
525/* Transfer function. */
526
527static bool
6fb5fa3c 528df_rd_transfer_function (int bb_index)
4d779342 529{
6fb5fa3c 530 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
4d779342
DB
531 unsigned int regno;
532 bitmap_iterator bi;
b33a91c9
JH
533 bitmap in = &bb_info->in;
534 bitmap out = &bb_info->out;
535 bitmap gen = &bb_info->gen;
536 bitmap kill = &bb_info->kill;
537 bitmap sparse_kill = &bb_info->sparse_kill;
4d779342 538
963acd6f
KZ
539 if (bitmap_empty_p (sparse_kill))
540 return bitmap_ior_and_compl (out, gen, in, kill);
b8698a0f 541 else
4d779342 542 {
6fb5fa3c 543 struct df_rd_problem_data *problem_data;
963acd6f 544 bool changed = false;
5c72d561 545 bitmap_head tmp;
6fb5fa3c
DB
546
547 /* Note that TMP is _not_ a temporary bitmap if we end up replacing
548 OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
549 problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
5c72d561 550 bitmap_initialize (&tmp, &problem_data->rd_bitmaps);
6fb5fa3c 551
5c72d561 552 bitmap_copy (&tmp, in);
4d779342
DB
553 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
554 {
5c72d561 555 bitmap_clear_range (&tmp,
b8698a0f 556 DF_DEFS_BEGIN (regno),
6fb5fa3c 557 DF_DEFS_COUNT (regno));
4d779342 558 }
5c72d561
JH
559 bitmap_and_compl_into (&tmp, kill);
560 bitmap_ior_into (&tmp, gen);
561 changed = !bitmap_equal_p (&tmp, out);
4d779342
DB
562 if (changed)
563 {
b33a91c9 564 bitmap_clear (out);
5c72d561 565 bb_info->out = tmp;
4d779342 566 }
b8698a0f 567 else
5c72d561 568 bitmap_clear (&tmp);
963acd6f 569 return changed;
4d779342
DB
570 }
571}
572
573
574/* Free all storage associated with the problem. */
575
576static void
6fb5fa3c 577df_rd_free (void)
4d779342 578{
23249ac4 579 struct df_rd_problem_data *problem_data
6fb5fa3c 580 = (struct df_rd_problem_data *) df_rd->problem_data;
4d779342 581
3b8266e2 582 if (problem_data)
4d779342 583 {
6fb5fa3c 584 bitmap_obstack_release (&problem_data->rd_bitmaps);
b8698a0f 585
6fb5fa3c
DB
586 df_rd->block_info_size = 0;
587 free (df_rd->block_info);
e285df08 588 df_rd->block_info = NULL;
6fb5fa3c 589 free (df_rd->problem_data);
4d779342 590 }
6fb5fa3c 591 free (df_rd);
4d779342
DB
592}
593
594
595/* Debugging info. */
596
597static void
6fb5fa3c 598df_rd_start_dump (FILE *file)
4d779342 599{
23249ac4 600 struct df_rd_problem_data *problem_data
6fb5fa3c
DB
601 = (struct df_rd_problem_data *) df_rd->problem_data;
602 unsigned int m = DF_REG_SIZE(df);
4d779342 603 unsigned int regno;
b8698a0f
L
604
605 if (!df_rd->block_info)
23249ac4
DB
606 return;
607
6fb5fa3c 608 fprintf (file, ";; Reaching defs:\n\n");
4d779342
DB
609
610 fprintf (file, " sparse invalidated \t");
5c72d561 611 dump_bitmap (file, &problem_data->sparse_invalidated_by_call);
4d779342 612 fprintf (file, " dense invalidated \t");
5c72d561 613 dump_bitmap (file, &problem_data->dense_invalidated_by_call);
4d779342
DB
614
615 for (regno = 0; regno < m; regno++)
6fb5fa3c 616 if (DF_DEFS_COUNT (regno))
b8698a0f
L
617 fprintf (file, "%d[%d,%d] ", regno,
618 DF_DEFS_BEGIN (regno),
6fb5fa3c 619 DF_DEFS_COUNT (regno));
4d779342
DB
620 fprintf (file, "\n");
621
6fb5fa3c
DB
622}
623
624
625/* Debugging info at top of bb. */
626
627static void
628df_rd_top_dump (basic_block bb, FILE *file)
629{
630 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
b33a91c9 631 if (!bb_info)
6fb5fa3c 632 return;
b8698a0f 633
b33a91c9
JH
634 fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (&bb_info->in));
635 dump_bitmap (file, &bb_info->in);
636 fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (&bb_info->gen));
637 dump_bitmap (file, &bb_info->gen);
638 fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (&bb_info->kill));
639 dump_bitmap (file, &bb_info->kill);
6fb5fa3c
DB
640}
641
642
643/* Debugging info at top of bb. */
644
645static void
646df_rd_bottom_dump (basic_block bb, FILE *file)
647{
648 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
b33a91c9 649 if (!bb_info)
6fb5fa3c 650 return;
b8698a0f 651
b33a91c9
JH
652 fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (&bb_info->out));
653 dump_bitmap (file, &bb_info->out);
4d779342
DB
654}
655
656/* All of the information associated with every instance of the problem. */
657
658static struct df_problem problem_RD =
659{
660 DF_RD, /* Problem id. */
661 DF_FORWARD, /* Direction. */
662 df_rd_alloc, /* Allocate the problem specific data. */
30cb87a0 663 NULL, /* Reset global information. */
4d779342
DB
664 df_rd_free_bb_info, /* Free basic block info. */
665 df_rd_local_compute, /* Local compute function. */
666 df_rd_init_solution, /* Init the solution specific data. */
6fb5fa3c 667 df_worklist_dataflow, /* Worklist solver. */
b8698a0f
L
668 NULL, /* Confluence operator 0. */
669 df_rd_confluence_n, /* Confluence operator n. */
4d779342
DB
670 df_rd_transfer_function, /* Transfer function. */
671 NULL, /* Finalize function. */
672 df_rd_free, /* Free all of the problem information. */
6fb5fa3c
DB
673 df_rd_free, /* Remove this problem from the stack of dataflow problems. */
674 df_rd_start_dump, /* Debugging. */
675 df_rd_top_dump, /* Debugging start block. */
676 df_rd_bottom_dump, /* Debugging end block. */
677 NULL, /* Incremental solution verify start. */
6ed3da00 678 NULL, /* Incremental solution verify end. */
23249ac4 679 NULL, /* Dependent problem. */
e285df08 680 sizeof (struct df_rd_bb_info),/* Size of entry of block_info array. */
b8698a0f 681 TV_DF_RD, /* Timing variable. */
89a95777 682 true /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
683};
684
685
686
c6741572
PB
687/* Create a new RD instance and add it to the existing instance
688 of DF. */
4d779342 689
6fb5fa3c
DB
690void
691df_rd_add_problem (void)
4d779342 692{
6fb5fa3c 693 df_add_problem (&problem_RD);
4d779342
DB
694}
695
696
697\f
698/*----------------------------------------------------------------------------
699 LIVE REGISTERS
700
b11550aa
KZ
701 Find the locations in the function where any use of a pseudo can
702 reach in the backwards direction. In and out bitvectors are built
cc806ac1 703 for each basic block. The regno is used to index into these sets.
b11550aa
KZ
704 See df.h for details.
705 ----------------------------------------------------------------------------*/
4d779342 706
6fb5fa3c
DB
707/* Private data used to verify the solution for this problem. */
708struct df_lr_problem_data
4d779342 709{
b33a91c9
JH
710 bitmap_head *in;
711 bitmap_head *out;
e7f96023
JH
712 /* An obstack for the bitmaps we need for this problem. */
713 bitmap_obstack lr_bitmaps;
6fb5fa3c 714};
4d779342 715
4d779342
DB
716/* Free basic block info. */
717
718static void
b8698a0f 719df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
3b8266e2 720 void *vbb_info)
4d779342
DB
721{
722 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
723 if (bb_info)
724 {
b33a91c9
JH
725 bitmap_clear (&bb_info->use);
726 bitmap_clear (&bb_info->def);
727 bitmap_clear (&bb_info->in);
728 bitmap_clear (&bb_info->out);
4d779342
DB
729 }
730}
731
732
6fb5fa3c 733/* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
4d779342
DB
734 not touched unless the block is new. */
735
b8698a0f 736static void
6fb5fa3c 737df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342
DB
738{
739 unsigned int bb_index;
740 bitmap_iterator bi;
e7f96023 741 struct df_lr_problem_data *problem_data;
4d779342 742
6fb5fa3c 743 df_grow_bb_info (df_lr);
e7f96023
JH
744 if (df_lr->problem_data)
745 problem_data = (struct df_lr_problem_data *) df_lr->problem_data;
746 else
747 {
748 problem_data = XNEW (struct df_lr_problem_data);
749 df_lr->problem_data = problem_data;
750
751 problem_data->out = NULL;
752 problem_data->in = NULL;
753 bitmap_obstack_initialize (&problem_data->lr_bitmaps);
754 }
4d779342 755
6fb5fa3c 756 EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
4d779342 757 {
6fb5fa3c 758 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
e285df08
JH
759
760 /* When bitmaps are already initialized, just clear them. */
761 if (bb_info->use.obstack)
b8698a0f 762 {
b33a91c9
JH
763 bitmap_clear (&bb_info->def);
764 bitmap_clear (&bb_info->use);
4d779342
DB
765 }
766 else
b8698a0f 767 {
e7f96023
JH
768 bitmap_initialize (&bb_info->use, &problem_data->lr_bitmaps);
769 bitmap_initialize (&bb_info->def, &problem_data->lr_bitmaps);
770 bitmap_initialize (&bb_info->in, &problem_data->lr_bitmaps);
771 bitmap_initialize (&bb_info->out, &problem_data->lr_bitmaps);
4d779342
DB
772 }
773 }
89a95777
KZ
774
775 df_lr->optional_p = false;
4d779342
DB
776}
777
778
6fb5fa3c
DB
779/* Reset the global solution for recalculation. */
780
b8698a0f 781static void
6fb5fa3c
DB
782df_lr_reset (bitmap all_blocks)
783{
784 unsigned int bb_index;
785 bitmap_iterator bi;
786
787 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
788 {
789 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
790 gcc_assert (bb_info);
b33a91c9
JH
791 bitmap_clear (&bb_info->in);
792 bitmap_clear (&bb_info->out);
6fb5fa3c
DB
793 }
794}
795
796
4d779342
DB
797/* Compute local live register info for basic block BB. */
798
799static void
6fb5fa3c 800df_lr_bb_local_compute (unsigned int bb_index)
4d779342
DB
801{
802 basic_block bb = BASIC_BLOCK (bb_index);
6fb5fa3c 803 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
4d779342 804 rtx insn;
57512f53
KZ
805 df_ref *def_rec;
806 df_ref *use_rec;
4d779342 807
912f2dac 808 /* Process the registers set in an exception handler. */
6fb5fa3c
DB
809 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
810 {
57512f53 811 df_ref def = *def_rec;
6fb5fa3c
DB
812 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
813 {
814 unsigned int dregno = DF_REF_REGNO (def);
b33a91c9
JH
815 bitmap_set_bit (&bb_info->def, dregno);
816 bitmap_clear_bit (&bb_info->use, dregno);
6fb5fa3c
DB
817 }
818 }
912f2dac 819
4d779342 820 /* Process the hardware registers that are always live. */
6fb5fa3c
DB
821 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
822 {
57512f53 823 df_ref use = *use_rec;
6fb5fa3c
DB
824 /* Add use to set of uses in this BB. */
825 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
b33a91c9 826 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
6fb5fa3c 827 }
4d779342
DB
828
829 FOR_BB_INSNS_REVERSE (bb, insn)
830 {
831 unsigned int uid = INSN_UID (insn);
832
b5b8b0ac 833 if (!NONDEBUG_INSN_P (insn))
b8698a0f 834 continue;
4d779342 835
5d545bf1 836 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4d779342 837 {
57512f53 838 df_ref def = *def_rec;
5d545bf1
SP
839 /* If the def is to only part of the reg, it does
840 not kill the other defs that reach here. */
841 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
4d779342
DB
842 {
843 unsigned int dregno = DF_REF_REGNO (def);
b33a91c9
JH
844 bitmap_set_bit (&bb_info->def, dregno);
845 bitmap_clear_bit (&bb_info->use, dregno);
4d779342
DB
846 }
847 }
848
6fb5fa3c
DB
849 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
850 {
57512f53 851 df_ref use = *use_rec;
6fb5fa3c 852 /* Add use to set of uses in this BB. */
b33a91c9 853 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
6fb5fa3c 854 }
4d779342 855 }
ba49cb7b
KZ
856
857 /* Process the registers set in an exception handler or the hard
858 frame pointer if this block is the target of a non local
859 goto. */
6fb5fa3c
DB
860 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
861 {
57512f53 862 df_ref def = *def_rec;
ba49cb7b 863 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
6fb5fa3c
DB
864 {
865 unsigned int dregno = DF_REF_REGNO (def);
b33a91c9
JH
866 bitmap_set_bit (&bb_info->def, dregno);
867 bitmap_clear_bit (&bb_info->use, dregno);
6fb5fa3c
DB
868 }
869 }
b8698a0f 870
4d779342
DB
871#ifdef EH_USES
872 /* Process the uses that are live into an exception handler. */
6fb5fa3c
DB
873 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
874 {
57512f53 875 df_ref use = *use_rec;
6fb5fa3c
DB
876 /* Add use to set of uses in this BB. */
877 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
c69d3a0e 878 bitmap_set_bit (&bb_info->use, DF_REF_REGNO (use));
6fb5fa3c 879 }
4d779342 880#endif
89a95777
KZ
881
882 /* If the df_live problem is not defined, such as at -O0 and -O1, we
883 still need to keep the luids up to date. This is normally done
884 in the df_live problem since this problem has a forwards
885 scan. */
886 if (!df_live)
887 df_recompute_luids (bb);
4d779342
DB
888}
889
23249ac4 890
4d779342
DB
891/* Compute local live register info for each basic block within BLOCKS. */
892
893static void
6fb5fa3c 894df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
4d779342 895{
4d779342
DB
896 unsigned int bb_index;
897 bitmap_iterator bi;
b8698a0f 898
a7e3698d 899 bitmap_clear (&df->hardware_regs_used);
b8698a0f 900
4d779342 901 /* The all-important stack pointer must always be live. */
a7e3698d 902 bitmap_set_bit (&df->hardware_regs_used, STACK_POINTER_REGNUM);
b8698a0f 903
4d779342
DB
904 /* Before reload, there are a few registers that must be forced
905 live everywhere -- which might not already be the case for
906 blocks within infinite loops. */
23249ac4 907 if (!reload_completed)
4d779342
DB
908 {
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. */
922 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
923 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
a7e3698d 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. */
1231 df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
1232}
1233
1234
1235/* Verify that all of the lr related info is consistent and
1236 correct. */
1237
1238void
1239df_lr_verify_transfer_functions (void)
4d779342 1240{
6fb5fa3c 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. */
1760 df_live->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
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;
6fb5fa3c 2286 df_chain->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
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. */
8d074192 2665 df_word_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
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
23249ac4 2715#ifdef REG_DEAD_DEBUGGING
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
DB
2725}
2726#endif
4d779342 2727
23249ac4
DB
2728
2729/* After reg-stack, the x86 floating point stack regs are difficult to
2730 analyze because of all of the pushes, pops and rotations. Thus, we
2731 just leave the notes alone. */
2732
6fb5fa3c 2733#ifdef STACK_REGS
b8698a0f 2734static inline bool
6fb5fa3c 2735df_ignore_stack_reg (int regno)
23249ac4 2736{
6fb5fa3c
DB
2737 return regstack_completed
2738 && IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG);
2739}
23249ac4 2740#else
b8698a0f 2741static inline bool
6fb5fa3c
DB
2742df_ignore_stack_reg (int regno ATTRIBUTE_UNUSED)
2743{
23249ac4 2744 return false;
23249ac4 2745}
6fb5fa3c 2746#endif
23249ac4
DB
2747
2748
6fb5fa3c
DB
2749/* Remove all of the REG_DEAD or REG_UNUSED notes from INSN and add
2750 them to OLD_DEAD_NOTES and OLD_UNUSED_NOTES. */
23249ac4
DB
2751
2752static void
b144ba9d 2753df_kill_notes (rtx insn)
23249ac4
DB
2754{
2755 rtx *pprev = &REG_NOTES (insn);
2756 rtx link = *pprev;
6fb5fa3c 2757
23249ac4
DB
2758 while (link)
2759 {
2760 switch (REG_NOTE_KIND (link))
2761 {
2762 case REG_DEAD:
b8698a0f 2763 /* After reg-stack, we need to ignore any unused notes
6fb5fa3c
DB
2764 for the stack registers. */
2765 if (df_ignore_stack_reg (REGNO (XEXP (link, 0))))
2766 {
2767 pprev = &XEXP (link, 1);
2768 link = *pprev;
2769 }
2770 else
2771 {
2772 rtx next = XEXP (link, 1);
2773#ifdef REG_DEAD_DEBUGGING
2774 df_print_note ("deleting: ", insn, link);
2775#endif
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);
2792#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2793 df_print_note ("deleting: ", insn, link);
23249ac4 2794#endif
b144ba9d 2795 free_EXPR_LIST_node (link);
23249ac4
DB
2796 *pprev = link = next;
2797 }
2798 break;
b8698a0f 2799
23249ac4
DB
2800 default:
2801 pprev = &XEXP (link, 1);
2802 link = *pprev;
2803 break;
2804 }
2805 }
2806}
2807
2808
b144ba9d 2809/* Set a NOTE_TYPE note for REG in INSN. */
6fb5fa3c 2810
b144ba9d
JH
2811static inline void
2812df_set_note (enum reg_note note_type, rtx insn, rtx reg)
6fb5fa3c 2813{
b144ba9d 2814 gcc_checking_assert (!DEBUG_INSN_P (insn));
65c5f2a6 2815 add_reg_note (insn, note_type, reg);
6fb5fa3c
DB
2816}
2817
6f5c1520
RS
2818/* A subroutine of df_set_unused_notes_for_mw, with a selection of its
2819 arguments. Return true if the register value described by MWS's
2820 mw_reg is known to be completely unused, and if mw_reg can therefore
2821 be used in a REG_UNUSED note. */
2822
2823static bool
2824df_whole_mw_reg_unused_p (struct df_mw_hardreg *mws,
2825 bitmap live, bitmap artificial_uses)
2826{
2827 unsigned int r;
2828
2829 /* If MWS describes a partial reference, create REG_UNUSED notes for
2830 individual hard registers. */
2831 if (mws->flags & DF_REF_PARTIAL)
2832 return false;
2833
2834 /* Likewise if some part of the register is used. */
2835 for (r = mws->start_regno; r <= mws->end_regno; r++)
2836 if (bitmap_bit_p (live, r)
2837 || bitmap_bit_p (artificial_uses, r))
2838 return false;
2839
2840 gcc_assert (REG_P (mws->mw_reg));
2841 return true;
2842}
2843
67c6812f
JJ
2844
2845/* Node of a linked list of uses of dead REGs in debug insns. */
2846struct dead_debug_use
2847{
2848 df_ref use;
2849 struct dead_debug_use *next;
2850};
2851
2852/* Linked list of the above, with a bitmap of the REGs in the
2853 list. */
2854struct dead_debug
2855{
2856 struct dead_debug_use *head;
2857 bitmap used;
2858 bitmap to_rescan;
2859};
2860
2861static void dead_debug_reset (struct dead_debug *, unsigned int);
2862
2863
23249ac4
DB
2864/* Set the REG_UNUSED notes for the multiword hardreg defs in INSN
2865 based on the bits in LIVE. Do not generate notes for registers in
2866 artificial uses. DO_NOT_GEN is updated so that REG_DEAD notes are
2867 not generated if the reg is both read and written by the
2868 instruction.
2869*/
2870
b144ba9d
JH
2871static void
2872df_set_unused_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
b8698a0f 2873 bitmap live, bitmap do_not_gen,
67c6812f
JJ
2874 bitmap artificial_uses,
2875 struct dead_debug *debug)
23249ac4 2876{
6fb5fa3c 2877 unsigned int r;
b8698a0f 2878
23249ac4 2879#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2880 if (dump_file)
b8698a0f 2881 fprintf (dump_file, "mw_set_unused looking at mws[%d..%d]\n",
6fb5fa3c 2882 mws->start_regno, mws->end_regno);
23249ac4 2883#endif
6f5c1520
RS
2884
2885 if (df_whole_mw_reg_unused_p (mws, live, artificial_uses))
23249ac4 2886 {
6fb5fa3c 2887 unsigned int regno = mws->start_regno;
b144ba9d 2888 df_set_note (REG_UNUSED, insn, mws->mw_reg);
67c6812f 2889 dead_debug_reset (debug, regno);
6fb5fa3c 2890
23249ac4 2891#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2892 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
23249ac4
DB
2893#endif
2894 bitmap_set_bit (do_not_gen, regno);
2895 /* Only do this if the value is totally dead. */
23249ac4
DB
2896 }
2897 else
27178277 2898 for (r = mws->start_regno; r <= mws->end_regno; r++)
6fb5fa3c 2899 {
27178277
RS
2900 if (!bitmap_bit_p (live, r)
2901 && !bitmap_bit_p (artificial_uses, r))
6fb5fa3c 2902 {
b144ba9d 2903 df_set_note (REG_UNUSED, insn, regno_reg_rtx[r]);
67c6812f 2904 dead_debug_reset (debug, r);
23249ac4 2905#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2906 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
23249ac4 2907#endif
6fb5fa3c
DB
2908 }
2909 bitmap_set_bit (do_not_gen, r);
2910 }
23249ac4
DB
2911}
2912
2913
6f5c1520
RS
2914/* A subroutine of df_set_dead_notes_for_mw, with a selection of its
2915 arguments. Return true if the register value described by MWS's
2916 mw_reg is known to be completely dead, and if mw_reg can therefore
2917 be used in a REG_DEAD note. */
2918
2919static bool
2920df_whole_mw_reg_dead_p (struct df_mw_hardreg *mws,
2921 bitmap live, bitmap artificial_uses,
2922 bitmap do_not_gen)
2923{
2924 unsigned int r;
2925
2926 /* If MWS describes a partial reference, create REG_DEAD notes for
2927 individual hard registers. */
2928 if (mws->flags & DF_REF_PARTIAL)
2929 return false;
2930
2931 /* Likewise if some part of the register is not dead. */
2932 for (r = mws->start_regno; r <= mws->end_regno; r++)
2933 if (bitmap_bit_p (live, r)
2934 || bitmap_bit_p (artificial_uses, r)
2935 || bitmap_bit_p (do_not_gen, r))
2936 return false;
2937
2938 gcc_assert (REG_P (mws->mw_reg));
2939 return true;
2940}
2941
23249ac4
DB
2942/* Set the REG_DEAD notes for the multiword hardreg use in INSN based
2943 on the bits in LIVE. DO_NOT_GEN is used to keep REG_DEAD notes
2944 from being set if the instruction both reads and writes the
2945 register. */
2946
b144ba9d
JH
2947static void
2948df_set_dead_notes_for_mw (rtx insn, struct df_mw_hardreg *mws,
23249ac4 2949 bitmap live, bitmap do_not_gen,
b5b8b0ac 2950 bitmap artificial_uses, bool *added_notes_p)
23249ac4 2951{
6fb5fa3c 2952 unsigned int r;
b5b8b0ac
AO
2953 bool is_debug = *added_notes_p;
2954
2955 *added_notes_p = false;
b8698a0f 2956
23249ac4 2957#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 2958 if (dump_file)
23249ac4 2959 {
b8698a0f 2960 fprintf (dump_file, "mw_set_dead looking at mws[%d..%d]\n do_not_gen =",
6fb5fa3c
DB
2961 mws->start_regno, mws->end_regno);
2962 df_print_regset (dump_file, do_not_gen);
2963 fprintf (dump_file, " live =");
2964 df_print_regset (dump_file, live);
2965 fprintf (dump_file, " artificial uses =");
2966 df_print_regset (dump_file, artificial_uses);
23249ac4 2967 }
6fb5fa3c
DB
2968#endif
2969
6f5c1520 2970 if (df_whole_mw_reg_dead_p (mws, live, artificial_uses, do_not_gen))
23249ac4 2971 {
6f5c1520 2972 /* Add a dead note for the entire multi word register. */
b5b8b0ac
AO
2973 if (is_debug)
2974 {
2975 *added_notes_p = true;
b144ba9d 2976 return;
b5b8b0ac 2977 }
b144ba9d 2978 df_set_note (REG_DEAD, insn, mws->mw_reg);
23249ac4 2979#ifdef REG_DEAD_DEBUGGING
6f5c1520 2980 df_print_note ("adding 1: ", insn, REG_NOTES (insn));
23249ac4 2981#endif
23249ac4
DB
2982 }
2983 else
2984 {
6fb5fa3c 2985 for (r = mws->start_regno; r <= mws->end_regno; r++)
27178277
RS
2986 if (!bitmap_bit_p (live, r)
2987 && !bitmap_bit_p (artificial_uses, r)
2988 && !bitmap_bit_p (do_not_gen, r))
2989 {
b5b8b0ac
AO
2990 if (is_debug)
2991 {
2992 *added_notes_p = true;
b144ba9d 2993 return;
b5b8b0ac 2994 }
b144ba9d 2995 df_set_note (REG_DEAD, insn, regno_reg_rtx[r]);
23249ac4 2996#ifdef REG_DEAD_DEBUGGING
27178277 2997 df_print_note ("adding 2: ", insn, REG_NOTES (insn));
23249ac4 2998#endif
27178277 2999 }
23249ac4 3000 }
b144ba9d 3001 return;
23249ac4
DB
3002}
3003
3004
e4142b7c
KZ
3005/* Create a REG_UNUSED note if necessary for DEF in INSN updating
3006 LIVE. Do not generate notes for registers in ARTIFICIAL_USES. */
23249ac4 3007
b144ba9d
JH
3008static void
3009df_create_unused_note (rtx insn, df_ref def,
67c6812f
JJ
3010 bitmap live, bitmap artificial_uses,
3011 struct dead_debug *debug)
23249ac4
DB
3012{
3013 unsigned int dregno = DF_REF_REGNO (def);
b8698a0f 3014
23249ac4 3015#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3016 if (dump_file)
23249ac4 3017 {
6fb5fa3c
DB
3018 fprintf (dump_file, " regular looking at def ");
3019 df_ref_debug (def, dump_file);
23249ac4 3020 }
6fb5fa3c
DB
3021#endif
3022
95f4cd58
JH
3023 if (!((DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)
3024 || bitmap_bit_p (live, dregno)
6fb5fa3c
DB
3025 || bitmap_bit_p (artificial_uses, dregno)
3026 || df_ignore_stack_reg (dregno)))
23249ac4 3027 {
b8698a0f 3028 rtx reg = (DF_REF_LOC (def))
6fb5fa3c 3029 ? *DF_REF_REAL_LOC (def): DF_REF_REG (def);
b144ba9d 3030 df_set_note (REG_UNUSED, insn, reg);
67c6812f 3031 dead_debug_reset (debug, dregno);
23249ac4 3032#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3033 df_print_note ("adding 3: ", insn, REG_NOTES (insn));
23249ac4 3034#endif
23249ac4 3035 }
b8698a0f 3036
b144ba9d 3037 return;
4d779342
DB
3038}
3039
e972a1d3
AO
3040
3041/* Initialize DEBUG to an empty list, and clear USED, if given. */
3042static inline void
3043dead_debug_init (struct dead_debug *debug, bitmap used)
3044{
3045 debug->head = NULL;
3046 debug->used = used;
3f592b38 3047 debug->to_rescan = NULL;
e972a1d3
AO
3048 if (used)
3049 bitmap_clear (used);
3050}
3051
3052/* Reset all debug insns with pending uses. Release the bitmap in it,
3053 unless it is USED. USED must be the same bitmap passed to
3054 dead_debug_init. */
3055static inline void
3056dead_debug_finish (struct dead_debug *debug, bitmap used)
3057{
3058 struct dead_debug_use *head;
3059 rtx insn = NULL;
3060
3061 if (debug->used != used)
3062 BITMAP_FREE (debug->used);
3063
3064 while ((head = debug->head))
3065 {
3066 insn = DF_REF_INSN (head->use);
3067 if (!head->next || DF_REF_INSN (head->next->use) != insn)
3068 {
3069 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3070 df_insn_rescan_debug_internal (insn);
3f592b38
JJ
3071 if (debug->to_rescan)
3072 bitmap_clear_bit (debug->to_rescan, INSN_UID (insn));
e972a1d3
AO
3073 }
3074 debug->head = head->next;
3075 XDELETE (head);
3076 }
3f592b38
JJ
3077
3078 if (debug->to_rescan)
3079 {
3080 bitmap_iterator bi;
3081 unsigned int uid;
3082
3083 EXECUTE_IF_SET_IN_BITMAP (debug->to_rescan, 0, uid, bi)
3084 {
3085 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
3086 if (insn_info)
3087 df_insn_rescan (insn_info->insn);
3088 }
3089 BITMAP_FREE (debug->to_rescan);
3090 }
e972a1d3
AO
3091}
3092
67c6812f
JJ
3093/* Reset DEBUG_INSNs with pending uses of DREGNO. */
3094static void
3095dead_debug_reset (struct dead_debug *debug, unsigned int dregno)
3096{
3097 struct dead_debug_use **tailp = &debug->head;
3098 struct dead_debug_use *cur;
3099 rtx insn;
3100
3101 if (!debug->used || !bitmap_clear_bit (debug->used, dregno))
3102 return;
3103
3104 while ((cur = *tailp))
3105 {
3106 if (DF_REF_REGNO (cur->use) == dregno)
3107 {
3108 *tailp = cur->next;
3109 insn = DF_REF_INSN (cur->use);
3110 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3111 if (debug->to_rescan == NULL)
3112 debug->to_rescan = BITMAP_ALLOC (NULL);
3113 bitmap_set_bit (debug->to_rescan, INSN_UID (insn));
3114 XDELETE (cur);
3115 }
3116 else
3117 tailp = &(*tailp)->next;
3118 }
3119}
3120
e972a1d3
AO
3121/* Add USE to DEBUG. It must be a dead reference to UREGNO in a debug
3122 insn. Create a bitmap for DEBUG as needed. */
3123static inline void
3124dead_debug_add (struct dead_debug *debug, df_ref use, unsigned int uregno)
3125{
3126 struct dead_debug_use *newddu = XNEW (struct dead_debug_use);
3127
3128 newddu->use = use;
3129 newddu->next = debug->head;
3130 debug->head = newddu;
3131
3132 if (!debug->used)
3133 debug->used = BITMAP_ALLOC (NULL);
3134
3135 bitmap_set_bit (debug->used, uregno);
3136}
3137
3138/* If UREGNO is referenced by any entry in DEBUG, emit a debug insn
3139 before INSN that binds the REG to a debug temp, and replace all
3140 uses of UREGNO in DEBUG with uses of the debug temp. INSN must be
3141 the insn where UREGNO dies. */
3142static inline void
3143dead_debug_insert_before (struct dead_debug *debug, unsigned int uregno,
3144 rtx insn)
3145{
3146 struct dead_debug_use **tailp = &debug->head;
3147 struct dead_debug_use *cur;
3148 struct dead_debug_use *uses = NULL;
3149 struct dead_debug_use **usesp = &uses;
3150 rtx reg = NULL;
3151 rtx dval;
3152 rtx bind;
3153
3154 if (!debug->used || !bitmap_clear_bit (debug->used, uregno))
3155 return;
3156
3157 /* Move all uses of uregno from debug->head to uses, setting mode to
3158 the widest referenced mode. */
3159 while ((cur = *tailp))
3160 {
3161 if (DF_REF_REGNO (cur->use) == uregno)
3162 {
3163 *usesp = cur;
3164 usesp = &cur->next;
3165 *tailp = cur->next;
3166 cur->next = NULL;
3167 if (!reg
3168 || (GET_MODE_BITSIZE (GET_MODE (reg))
5b8bd3d5
JJ
3169 < GET_MODE_BITSIZE (GET_MODE (*DF_REF_REAL_LOC (cur->use)))))
3170 reg = *DF_REF_REAL_LOC (cur->use);
e972a1d3
AO
3171 }
3172 else
3173 tailp = &(*tailp)->next;
3174 }
3175
3176 gcc_assert (reg);
3177
3178 /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
3179 dval = make_debug_expr_from_rtl (reg);
3180
3181 /* Emit a debug bind insn before the insn in which reg dies. */
3182 bind = gen_rtx_VAR_LOCATION (GET_MODE (reg),
3183 DEBUG_EXPR_TREE_DECL (dval), reg,
3184 VAR_INIT_STATUS_INITIALIZED);
3185
3186 bind = emit_debug_insn_before (bind, insn);
3187 df_insn_rescan (bind);
3188
3189 /* Adjust all uses. */
3190 while ((cur = uses))
3191 {
5b8bd3d5 3192 if (GET_MODE (*DF_REF_REAL_LOC (cur->use)) == GET_MODE (reg))
e972a1d3
AO
3193 *DF_REF_REAL_LOC (cur->use) = dval;
3194 else
3195 *DF_REF_REAL_LOC (cur->use)
5b8bd3d5 3196 = gen_lowpart_SUBREG (GET_MODE (*DF_REF_REAL_LOC (cur->use)), dval);
e972a1d3 3197 /* ??? Should we simplify subreg of subreg? */
3f592b38
JJ
3198 if (debug->to_rescan == NULL)
3199 debug->to_rescan = BITMAP_ALLOC (NULL);
3200 bitmap_set_bit (debug->to_rescan, INSN_UID (DF_REF_INSN (cur->use)));
e972a1d3
AO
3201 uses = cur->next;
3202 XDELETE (cur);
3203 }
3204}
23249ac4
DB
3205
3206/* Recompute the REG_DEAD and REG_UNUSED notes and compute register
3207 info: lifetime, bb, and number of defs and uses for basic block
3208 BB. The three bitvectors are scratch regs used here. */
4d779342
DB
3209
3210static void
b8698a0f 3211df_note_bb_compute (unsigned int bb_index,
e4142b7c 3212 bitmap live, bitmap do_not_gen, bitmap artificial_uses)
4d779342 3213{
4d779342
DB
3214 basic_block bb = BASIC_BLOCK (bb_index);
3215 rtx insn;
57512f53
KZ
3216 df_ref *def_rec;
3217 df_ref *use_rec;
e972a1d3
AO
3218 struct dead_debug debug;
3219
3220 dead_debug_init (&debug, NULL);
23249ac4 3221
6fb5fa3c 3222 bitmap_copy (live, df_get_live_out (bb));
23249ac4
DB
3223 bitmap_clear (artificial_uses);
3224
6fb5fa3c
DB
3225#ifdef REG_DEAD_DEBUGGING
3226 if (dump_file)
23249ac4 3227 {
6fb5fa3c
DB
3228 fprintf (dump_file, "live at bottom ");
3229 df_print_regset (dump_file, live);
23249ac4 3230 }
6fb5fa3c 3231#endif
23249ac4
DB
3232
3233 /* Process the artificial defs and uses at the bottom of the block
3234 to begin processing. */
6fb5fa3c
DB
3235 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3236 {
57512f53 3237 df_ref def = *def_rec;
8b9d606b 3238#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
3239 if (dump_file)
3240 fprintf (dump_file, "artificial def %d\n", DF_REF_REGNO (def));
8b9d606b 3241#endif
4d779342 3242
6fb5fa3c
DB
3243 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
3244 bitmap_clear_bit (live, DF_REF_REGNO (def));
3245 }
4d779342 3246
6fb5fa3c
DB
3247 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3248 {
57512f53 3249 df_ref use = *use_rec;
6fb5fa3c
DB
3250 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3251 {
3252 unsigned int regno = DF_REF_REGNO (use);
3253 bitmap_set_bit (live, regno);
b8698a0f 3254
6fb5fa3c
DB
3255 /* Notes are not generated for any of the artificial registers
3256 at the bottom of the block. */
3257 bitmap_set_bit (artificial_uses, regno);
3258 }
3259 }
b8698a0f 3260
6fb5fa3c
DB
3261#ifdef REG_DEAD_DEBUGGING
3262 if (dump_file)
3263 {
3264 fprintf (dump_file, "live before artificials out ");
3265 df_print_regset (dump_file, live);
3266 }
3267#endif
3268
4d779342
DB
3269 FOR_BB_INSNS_REVERSE (bb, insn)
3270 {
3271 unsigned int uid = INSN_UID (insn);
6fb5fa3c 3272 struct df_mw_hardreg **mws_rec;
b5b8b0ac 3273 int debug_insn;
b8698a0f 3274
23249ac4 3275 if (!INSN_P (insn))
4d779342
DB
3276 continue;
3277
b5b8b0ac
AO
3278 debug_insn = DEBUG_INSN_P (insn);
3279
23249ac4 3280 bitmap_clear (do_not_gen);
b144ba9d 3281 df_kill_notes (insn);
23249ac4
DB
3282
3283 /* Process the defs. */
3284 if (CALL_P (insn))
3285 {
6fb5fa3c
DB
3286#ifdef REG_DEAD_DEBUGGING
3287 if (dump_file)
23249ac4 3288 {
6fb5fa3c
DB
3289 fprintf (dump_file, "processing call %d\n live =", INSN_UID (insn));
3290 df_print_regset (dump_file, live);
23249ac4 3291 }
6fb5fa3c 3292#endif
e44e043c
KZ
3293 /* We only care about real sets for calls. Clobbers cannot
3294 be depended on to really die. */
6fb5fa3c
DB
3295 mws_rec = DF_INSN_UID_MWS (uid);
3296 while (*mws_rec)
23249ac4 3297 {
b8698a0f
L
3298 struct df_mw_hardreg *mws = *mws_rec;
3299 if ((DF_MWS_REG_DEF_P (mws))
23da9ed6 3300 && !df_ignore_stack_reg (mws->start_regno))
b144ba9d
JH
3301 df_set_unused_notes_for_mw (insn,
3302 mws, live, do_not_gen,
67c6812f 3303 artificial_uses, &debug);
6fb5fa3c 3304 mws_rec++;
23249ac4
DB
3305 }
3306
3307 /* All of the defs except the return value are some sort of
3308 clobber. This code is for the return. */
6fb5fa3c
DB
3309 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3310 {
57512f53 3311 df_ref def = *def_rec;
e4142b7c
KZ
3312 unsigned int dregno = DF_REF_REGNO (def);
3313 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3314 {
b144ba9d 3315 df_create_unused_note (insn,
67c6812f 3316 def, live, artificial_uses, &debug);
e4142b7c
KZ
3317 bitmap_set_bit (do_not_gen, dregno);
3318 }
3319
3320 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3321 bitmap_clear_bit (live, dregno);
6fb5fa3c 3322 }
23249ac4
DB
3323 }
3324 else
3325 {
3326 /* Regular insn. */
6fb5fa3c
DB
3327 mws_rec = DF_INSN_UID_MWS (uid);
3328 while (*mws_rec)
23249ac4 3329 {
b8698a0f 3330 struct df_mw_hardreg *mws = *mws_rec;
57512f53 3331 if (DF_MWS_REG_DEF_P (mws))
b144ba9d
JH
3332 df_set_unused_notes_for_mw (insn,
3333 mws, live, do_not_gen,
67c6812f 3334 artificial_uses, &debug);
6fb5fa3c 3335 mws_rec++;
23249ac4
DB
3336 }
3337
6fb5fa3c
DB
3338 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3339 {
57512f53 3340 df_ref def = *def_rec;
e4142b7c 3341 unsigned int dregno = DF_REF_REGNO (def);
b144ba9d 3342 df_create_unused_note (insn,
67c6812f 3343 def, live, artificial_uses, &debug);
e4142b7c
KZ
3344
3345 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))
3346 bitmap_set_bit (do_not_gen, dregno);
3347
3348 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3349 bitmap_clear_bit (live, dregno);
6fb5fa3c 3350 }
23249ac4 3351 }
b8698a0f 3352
23249ac4 3353 /* Process the uses. */
6fb5fa3c
DB
3354 mws_rec = DF_INSN_UID_MWS (uid);
3355 while (*mws_rec)
23249ac4 3356 {
b8698a0f
L
3357 struct df_mw_hardreg *mws = *mws_rec;
3358 if ((DF_MWS_REG_DEF_P (mws))
23da9ed6 3359 && !df_ignore_stack_reg (mws->start_regno))
b5b8b0ac
AO
3360 {
3361 bool really_add_notes = debug_insn != 0;
3362
b144ba9d
JH
3363 df_set_dead_notes_for_mw (insn,
3364 mws, live, do_not_gen,
3365 artificial_uses,
3366 &really_add_notes);
b5b8b0ac
AO
3367
3368 if (really_add_notes)
3369 debug_insn = -1;
3370 }
6fb5fa3c 3371 mws_rec++;
4d779342
DB
3372 }
3373
6fb5fa3c 3374 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
4d779342 3375 {
57512f53 3376 df_ref use = *use_rec;
4d779342
DB
3377 unsigned int uregno = DF_REF_REGNO (use);
3378
6fb5fa3c 3379#ifdef REG_DEAD_DEBUGGING
b5b8b0ac 3380 if (dump_file && !debug_insn)
23249ac4 3381 {
6fb5fa3c
DB
3382 fprintf (dump_file, " regular looking at use ");
3383 df_ref_debug (use, dump_file);
23249ac4 3384 }
23249ac4 3385#endif
912f2dac
DB
3386 if (!bitmap_bit_p (live, uregno))
3387 {
b5b8b0ac
AO
3388 if (debug_insn)
3389 {
e972a1d3 3390 if (debug_insn > 0)
3f592b38
JJ
3391 {
3392 dead_debug_add (&debug, use, uregno);
3393 continue;
3394 }
b5b8b0ac
AO
3395 break;
3396 }
e972a1d3
AO
3397 else
3398 dead_debug_insert_before (&debug, uregno, insn);
b5b8b0ac 3399
95f4cd58
JH
3400 if ( (!(DF_REF_FLAGS (use)
3401 & (DF_REF_MW_HARDREG | DF_REF_READ_WRITE)))
23249ac4
DB
3402 && (!bitmap_bit_p (do_not_gen, uregno))
3403 && (!bitmap_bit_p (artificial_uses, uregno))
23249ac4
DB
3404 && (!df_ignore_stack_reg (uregno)))
3405 {
b8698a0f 3406 rtx reg = (DF_REF_LOC (use))
6fb5fa3c 3407 ? *DF_REF_REAL_LOC (use) : DF_REF_REG (use);
b144ba9d 3408 df_set_note (REG_DEAD, insn, reg);
23249ac4
DB
3409
3410#ifdef REG_DEAD_DEBUGGING
6fb5fa3c 3411 df_print_note ("adding 4: ", insn, REG_NOTES (insn));
23249ac4
DB
3412#endif
3413 }
912f2dac
DB
3414 /* This register is now live. */
3415 bitmap_set_bit (live, uregno);
3416 }
4d779342 3417 }
6fb5fa3c 3418
b5b8b0ac
AO
3419 if (debug_insn == -1)
3420 {
3421 /* ??? We could probably do better here, replacing dead
3422 registers with their definitions. */
3423 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
3424 df_insn_rescan_debug_internal (insn);
3425 }
4d779342 3426 }
e972a1d3
AO
3427
3428 dead_debug_finish (&debug, NULL);
4d779342
DB
3429}
3430
3431
3432/* Compute register info: lifetime, bb, and number of defs and uses. */
3433static void
6fb5fa3c 3434df_note_compute (bitmap all_blocks)
4d779342
DB
3435{
3436 unsigned int bb_index;
3437 bitmap_iterator bi;
5c72d561
JH
3438 bitmap_head live, do_not_gen, artificial_uses;
3439
3440 bitmap_initialize (&live, &df_bitmap_obstack);
3441 bitmap_initialize (&do_not_gen, &df_bitmap_obstack);
3442 bitmap_initialize (&artificial_uses, &df_bitmap_obstack);
23249ac4
DB
3443
3444#ifdef REG_DEAD_DEBUGGING
6fb5fa3c
DB
3445 if (dump_file)
3446 print_rtl_with_bb (dump_file, get_insns());
23249ac4 3447#endif
4d779342 3448
6fb5fa3c 3449 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4d779342 3450 {
5c72d561 3451 df_note_bb_compute (bb_index, &live, &do_not_gen, &artificial_uses);
4d779342
DB
3452 }
3453
5c72d561
JH
3454 bitmap_clear (&live);
3455 bitmap_clear (&do_not_gen);
3456 bitmap_clear (&artificial_uses);
4d779342
DB
3457}
3458
3459
3460/* Free all storage associated with the problem. */
3461
3462static void
6fb5fa3c 3463df_note_free (void)
4d779342 3464{
6fb5fa3c 3465 free (df_note);
4d779342
DB
3466}
3467
3468
4d779342
DB
3469/* All of the information associated every instance of the problem. */
3470
6fb5fa3c 3471static struct df_problem problem_NOTE =
4d779342 3472{
6fb5fa3c 3473 DF_NOTE, /* Problem id. */
4d779342 3474 DF_NONE, /* Direction. */
89a95777 3475 df_note_alloc, /* Allocate the problem specific data. */
30cb87a0 3476 NULL, /* Reset global information. */
4d779342 3477 NULL, /* Free basic block info. */
6fb5fa3c 3478 df_note_compute, /* Local compute function. */
4d779342
DB
3479 NULL, /* Init the solution specific data. */
3480 NULL, /* Iterative solver. */
b8698a0f
L
3481 NULL, /* Confluence operator 0. */
3482 NULL, /* Confluence operator n. */
4d779342
DB
3483 NULL, /* Transfer function. */
3484 NULL, /* Finalize function. */
6fb5fa3c
DB
3485 df_note_free, /* Free all of the problem information. */
3486 df_note_free, /* Remove this problem from the stack of dataflow problems. */
3487 NULL, /* Debugging. */
3488 NULL, /* Debugging start block. */
3489 NULL, /* Debugging end block. */
3490 NULL, /* Incremental solution verify start. */
6ed3da00 3491 NULL, /* Incremental solution verify end. */
6fb5fa3c 3492 &problem_LR, /* Dependent problem. */
e285df08 3493 sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
89a95777
KZ
3494 TV_DF_NOTE, /* Timing variable. */
3495 false /* Reset blocks on dropping out of blocks_to_analyze. */
4d779342
DB
3496};
3497
3498
3499/* Create a new DATAFLOW instance and add it to an existing instance
3500 of DF. The returned structure is what is used to get at the
3501 solution. */
3502
6fb5fa3c
DB
3503void
3504df_note_add_problem (void)
4d779342 3505{
6fb5fa3c 3506 df_add_problem (&problem_NOTE);
4d779342 3507}
6fb5fa3c
DB
3508
3509
3510
3511\f
3512/*----------------------------------------------------------------------------
b8698a0f 3513 Functions for simulating the effects of single insns.
6fb5fa3c
DB
3514
3515 You can either simulate in the forwards direction, starting from
3516 the top of a block or the backwards direction from the end of the
64274683
PB
3517 block. If you go backwards, defs are examined first to clear bits,
3518 then uses are examined to set bits. If you go forwards, defs are
3519 examined first to set bits, then REG_DEAD and REG_UNUSED notes
3520 are examined to clear bits. In either case, the result of examining
3521 a def can be undone (respectively by a use or a REG_UNUSED note).
6fb5fa3c
DB
3522
3523 If you start at the top of the block, use one of DF_LIVE_IN or
3524 DF_LR_IN. If you start at the bottom of the block use one of
3525 DF_LIVE_OUT or DF_LR_OUT. BE SURE TO PASS A COPY OF THESE SETS,
3526 THEY WILL BE DESTROYED.
6fb5fa3c
DB
3527----------------------------------------------------------------------------*/
3528
3529
3530/* Find the set of DEFs for INSN. */
3531
3532void
3533df_simulate_find_defs (rtx insn, bitmap defs)
3534{
57512f53 3535 df_ref *def_rec;
6fb5fa3c
DB
3536 unsigned int uid = INSN_UID (insn);
3537
5d545bf1 3538 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
6fb5fa3c 3539 {
57512f53 3540 df_ref def = *def_rec;
907deb1a
BS
3541 bitmap_set_bit (defs, DF_REF_REGNO (def));
3542 }
3543}
3544
4ec5d4f5
BS
3545/* Find the set of uses for INSN. This includes partial defs. */
3546
3547static void
3548df_simulate_find_uses (rtx insn, bitmap uses)
3549{
3550 df_ref *rec;
3551 unsigned int uid = INSN_UID (insn);
3552
3553 for (rec = DF_INSN_UID_DEFS (uid); *rec; rec++)
3554 {
3555 df_ref def = *rec;
3556 if (DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))
3557 bitmap_set_bit (uses, DF_REF_REGNO (def));
3558 }
3559 for (rec = DF_INSN_UID_USES (uid); *rec; rec++)
3560 {
3561 df_ref use = *rec;
3562 bitmap_set_bit (uses, DF_REF_REGNO (use));
3563 }
3564}
3565
907deb1a
BS
3566/* Find the set of real DEFs, which are not clobbers, for INSN. */
3567
3568void
3569df_simulate_find_noclobber_defs (rtx insn, bitmap defs)
3570{
3571 df_ref *def_rec;
3572 unsigned int uid = INSN_UID (insn);
3573
3574 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
3575 {
3576 df_ref def = *def_rec;
3577 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
5d545bf1 3578 bitmap_set_bit (defs, DF_REF_REGNO (def));
6fb5fa3c
DB
3579 }
3580}
3581
3582
3583/* Simulate the effects of the defs of INSN on LIVE. */
3584
3585void
3586df_simulate_defs (rtx insn, bitmap live)
3587{
57512f53 3588 df_ref *def_rec;
6fb5fa3c
DB
3589 unsigned int uid = INSN_UID (insn);
3590
5d545bf1 3591 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
6fb5fa3c 3592 {
57512f53 3593 df_ref def = *def_rec;
5d545bf1
SP
3594 unsigned int dregno = DF_REF_REGNO (def);
3595
3596 /* If the def is to only part of the reg, it does
3597 not kill the other defs that reach here. */
3598 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
3599 bitmap_clear_bit (live, dregno);
6fb5fa3c 3600 }
b8698a0f 3601}
6fb5fa3c
DB
3602
3603
3604/* Simulate the effects of the uses of INSN on LIVE. */
3605
b8698a0f 3606void
6fb5fa3c
DB
3607df_simulate_uses (rtx insn, bitmap live)
3608{
57512f53 3609 df_ref *use_rec;
6fb5fa3c
DB
3610 unsigned int uid = INSN_UID (insn);
3611
b5b8b0ac
AO
3612 if (DEBUG_INSN_P (insn))
3613 return;
3614
6fb5fa3c
DB
3615 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
3616 {
57512f53 3617 df_ref use = *use_rec;
6fb5fa3c
DB
3618 /* Add use to set of uses in this BB. */
3619 bitmap_set_bit (live, DF_REF_REGNO (use));
3620 }
3621}
3622
3623
3624/* Add back the always live regs in BB to LIVE. */
3625
3626static inline void
3627df_simulate_fixup_sets (basic_block bb, bitmap live)
3628{
3629 /* These regs are considered always live so if they end up dying
3630 because of some def, we need to bring the back again. */
ba49cb7b 3631 if (bb_has_eh_pred (bb))
a7e3698d 3632 bitmap_ior_into (live, &df->eh_block_artificial_uses);
6fb5fa3c 3633 else
a7e3698d 3634 bitmap_ior_into (live, &df->regular_block_artificial_uses);
6fb5fa3c
DB
3635}
3636
3637
07b5bc83
KZ
3638/*----------------------------------------------------------------------------
3639 The following three functions are used only for BACKWARDS scanning:
3640 i.e. they process the defs before the uses.
3641
02b47899 3642 df_simulate_initialize_backwards should be called first with a
07b5bc83 3643 bitvector copyied from the DF_LIVE_OUT or DF_LR_OUT. Then
02b47899 3644 df_simulate_one_insn_backwards should be called for each insn in
64274683 3645 the block, starting with the last one. Finally,
02b47899 3646 df_simulate_finalize_backwards can be called to get a new value
07b5bc83 3647 of the sets at the top of the block (this is rarely used).
02b47899 3648 ----------------------------------------------------------------------------*/
07b5bc83
KZ
3649
3650/* Apply the artificial uses and defs at the end of BB in a backwards
6fb5fa3c
DB
3651 direction. */
3652
b8698a0f 3653void
02b47899 3654df_simulate_initialize_backwards (basic_block bb, bitmap live)
6fb5fa3c 3655{
57512f53
KZ
3656 df_ref *def_rec;
3657 df_ref *use_rec;
6fb5fa3c 3658 int bb_index = bb->index;
b8698a0f 3659
6fb5fa3c
DB
3660 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3661 {
57512f53 3662 df_ref def = *def_rec;
07b5bc83 3663 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
6fb5fa3c
DB
3664 bitmap_clear_bit (live, DF_REF_REGNO (def));
3665 }
07b5bc83
KZ
3666
3667 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3668 {
57512f53 3669 df_ref use = *use_rec;
07b5bc83
KZ
3670 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
3671 bitmap_set_bit (live, DF_REF_REGNO (use));
3672 }
6fb5fa3c
DB
3673}
3674
3675
07b5bc83 3676/* Simulate the backwards effects of INSN on the bitmap LIVE. */
6fb5fa3c 3677
b8698a0f 3678void
02b47899 3679df_simulate_one_insn_backwards (basic_block bb, rtx insn, bitmap live)
6fb5fa3c 3680{
b5b8b0ac 3681 if (!NONDEBUG_INSN_P (insn))
b8698a0f
L
3682 return;
3683
6fb5fa3c 3684 df_simulate_defs (insn, live);
07b5bc83 3685 df_simulate_uses (insn, live);
6fb5fa3c
DB
3686 df_simulate_fixup_sets (bb, live);
3687}
3688
3689
07b5bc83 3690/* Apply the artificial uses and defs at the top of BB in a backwards
6fb5fa3c
DB
3691 direction. */
3692
b8698a0f 3693void
02b47899 3694df_simulate_finalize_backwards (basic_block bb, bitmap live)
6fb5fa3c 3695{
57512f53 3696 df_ref *def_rec;
07b5bc83 3697#ifdef EH_USES
57512f53 3698 df_ref *use_rec;
07b5bc83 3699#endif
6fb5fa3c 3700 int bb_index = bb->index;
b8698a0f 3701
6fb5fa3c
DB
3702 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3703 {
57512f53 3704 df_ref def = *def_rec;
07b5bc83 3705 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
6fb5fa3c
DB
3706 bitmap_clear_bit (live, DF_REF_REGNO (def));
3707 }
3708
07b5bc83 3709#ifdef EH_USES
6fb5fa3c
DB
3710 for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
3711 {
57512f53 3712 df_ref use = *use_rec;
07b5bc83 3713 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
6fb5fa3c
DB
3714 bitmap_set_bit (live, DF_REF_REGNO (use));
3715 }
07b5bc83 3716#endif
6fb5fa3c 3717}
02b47899
KZ
3718/*----------------------------------------------------------------------------
3719 The following three functions are used only for FORWARDS scanning:
3720 i.e. they process the defs and the REG_DEAD and REG_UNUSED notes.
b8698a0f 3721 Thus it is important to add the DF_NOTES problem to the stack of
02b47899
KZ
3722 problems computed before using these functions.
3723
3724 df_simulate_initialize_forwards should be called first with a
3725 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then
3726 df_simulate_one_insn_forwards should be called for each insn in
64274683 3727 the block, starting with the first one.
02b47899
KZ
3728 ----------------------------------------------------------------------------*/
3729
823ff7b4
BS
3730/* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or
3731 DF_LR_IN for basic block BB, for forward scanning by marking artificial
3732 defs live. */
02b47899 3733
b8698a0f 3734void
02b47899
KZ
3735df_simulate_initialize_forwards (basic_block bb, bitmap live)
3736{
3737 df_ref *def_rec;
3738 int bb_index = bb->index;
b8698a0f 3739
02b47899
KZ
3740 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
3741 {
3742 df_ref def = *def_rec;
3743 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
823ff7b4 3744 bitmap_set_bit (live, DF_REF_REGNO (def));
02b47899
KZ
3745 }
3746}
3747
64274683 3748/* Simulate the forwards effects of INSN on the bitmap LIVE. */
02b47899 3749
b8698a0f 3750void
02b47899
KZ
3751df_simulate_one_insn_forwards (basic_block bb, rtx insn, bitmap live)
3752{
3753 rtx link;
3754 if (! INSN_P (insn))
b8698a0f 3755 return;
02b47899 3756
b8698a0f 3757 /* Make sure that DF_NOTE really is an active df problem. */
02b47899
KZ
3758 gcc_assert (df_note);
3759
64274683
PB
3760 /* Note that this is the opposite as how the problem is defined, because
3761 in the LR problem defs _kill_ liveness. However, they do so backwards,
3762 while here the scan is performed forwards! So, first assume that the
3763 def is live, and if this is not true REG_UNUSED notes will rectify the
3764 situation. */
907deb1a 3765 df_simulate_find_noclobber_defs (insn, live);
02b47899
KZ
3766
3767 /* Clear all of the registers that go dead. */
3768 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
3769 {
3770 switch (REG_NOTE_KIND (link))
e1b7793c 3771 {
02b47899
KZ
3772 case REG_DEAD:
3773 case REG_UNUSED:
e1b7793c
ILT
3774 {
3775 rtx reg = XEXP (link, 0);
3776 int regno = REGNO (reg);
f773c2bd
AS
3777 if (HARD_REGISTER_NUM_P (regno))
3778 bitmap_clear_range (live, regno,
3779 hard_regno_nregs[regno][GET_MODE (reg)]);
b8698a0f 3780 else
e1b7793c
ILT
3781 bitmap_clear_bit (live, regno);
3782 }
02b47899
KZ
3783 break;
3784 default:
3785 break;
3786 }
3787 }
3788 df_simulate_fixup_sets (bb, live);
3789}
4ec5d4f5
BS
3790\f
3791/* Used by the next two functions to encode information about the
3792 memory references we found. */
3793#define MEMREF_NORMAL 1
3794#define MEMREF_VOLATILE 2
3795
3796/* A subroutine of can_move_insns_across_p called through for_each_rtx.
3797 Return either MEMREF_NORMAL or MEMREF_VOLATILE if a memory is found. */
3798
3799static int
3800find_memory (rtx *px, void *data ATTRIBUTE_UNUSED)
3801{
3802 rtx x = *px;
3803
3804 if (GET_CODE (x) == ASM_OPERANDS && MEM_VOLATILE_P (x))
3805 return MEMREF_VOLATILE;
3806
3807 if (!MEM_P (x))
3808 return 0;
3809 if (MEM_VOLATILE_P (x))
3810 return MEMREF_VOLATILE;
3811 if (MEM_READONLY_P (x))
3812 return 0;
3813
3814 return MEMREF_NORMAL;
3815}
3816
3817/* A subroutine of can_move_insns_across_p called through note_stores.
3818 DATA points to an integer in which we set either the bit for
3819 MEMREF_NORMAL or the bit for MEMREF_VOLATILE if we find a MEM
3820 of either kind. */
3821
3822static void
3823find_memory_stores (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
3824 void *data ATTRIBUTE_UNUSED)
3825{
3826 int *pflags = (int *)data;
3827 if (GET_CODE (x) == SUBREG)
3828 x = XEXP (x, 0);
3829 /* Treat stores to SP as stores to memory, this will prevent problems
3830 when there are references to the stack frame. */
3831 if (x == stack_pointer_rtx)
3832 *pflags |= MEMREF_VOLATILE;
3833 if (!MEM_P (x))
3834 return;
3835 *pflags |= MEM_VOLATILE_P (x) ? MEMREF_VOLATILE : MEMREF_NORMAL;
3836}
3837
3838/* Scan BB backwards, using df_simulate functions to keep track of
3839 lifetimes, up to insn POINT. The result is stored in LIVE. */
3840
3841void
3842simulate_backwards_to_point (basic_block bb, regset live, rtx point)
3843{
3844 rtx insn;
3845 bitmap_copy (live, df_get_live_out (bb));
3846 df_simulate_initialize_backwards (bb, live);
3847
3848 /* Scan and update life information until we reach the point we're
3849 interested in. */
3850 for (insn = BB_END (bb); insn != point; insn = PREV_INSN (insn))
3851 df_simulate_one_insn_backwards (bb, insn, live);
3852}
3853
3854/* Return true if it is safe to move a group of insns, described by
3855 the range FROM to TO, backwards across another group of insns,
3856 described by ACROSS_FROM to ACROSS_TO. It is assumed that there
3857 are no insns between ACROSS_TO and FROM, but they may be in
3858 different basic blocks; MERGE_BB is the block from which the
3859 insns will be moved. The caller must pass in a regset MERGE_LIVE
3860 which specifies the registers live after TO.
3861
3862 This function may be called in one of two cases: either we try to
3863 move identical instructions from all successor blocks into their
3864 predecessor, or we try to move from only one successor block. If
3865 OTHER_BRANCH_LIVE is nonnull, it indicates that we're dealing with
3866 the second case. It should contain a set of registers live at the
3867 end of ACROSS_TO which must not be clobbered by moving the insns.
3868 In that case, we're also more careful about moving memory references
3869 and trapping insns.
3870
3871 We return false if it is not safe to move the entire group, but it
3872 may still be possible to move a subgroup. PMOVE_UPTO, if nonnull,
3873 is set to point at the last moveable insn in such a case. */
3874
3875bool
3876can_move_insns_across (rtx from, rtx to, rtx across_from, rtx across_to,
3877 basic_block merge_bb, regset merge_live,
3878 regset other_branch_live, rtx *pmove_upto)
3879{
3880 rtx insn, next, max_to;
3881 bitmap merge_set, merge_use, local_merge_live;
3882 bitmap test_set, test_use;
3883 unsigned i, fail = 0;
3884 bitmap_iterator bi;
3885 int memrefs_in_across = 0;
3886 int mem_sets_in_across = 0;
3887 bool trapping_insns_in_across = false;
02b47899 3888
4ec5d4f5
BS
3889 if (pmove_upto != NULL)
3890 *pmove_upto = NULL_RTX;
3891
3892 /* Find real bounds, ignoring debug insns. */
3893 while (!NONDEBUG_INSN_P (from) && from != to)
3894 from = NEXT_INSN (from);
3895 while (!NONDEBUG_INSN_P (to) && from != to)
3896 to = PREV_INSN (to);
3897
3898 for (insn = across_to; ; insn = next)
3899 {
3900 if (NONDEBUG_INSN_P (insn))
3901 {
3902 memrefs_in_across |= for_each_rtx (&PATTERN (insn), find_memory,
3903 NULL);
3904 note_stores (PATTERN (insn), find_memory_stores,
3905 &mem_sets_in_across);
3906 /* This is used just to find sets of the stack pointer. */
3907 memrefs_in_across |= mem_sets_in_across;
3908 trapping_insns_in_across |= may_trap_p (PATTERN (insn));
3909 }
3910 next = PREV_INSN (insn);
3911 if (insn == across_from)
3912 break;
3913 }
3914
3915 /* Collect:
3916 MERGE_SET = set of registers set in MERGE_BB
3917 MERGE_USE = set of registers used in MERGE_BB and live at its top
3918 MERGE_LIVE = set of registers live at the point inside the MERGE
3919 range that we've reached during scanning
3920 TEST_SET = set of registers set between ACROSS_FROM and ACROSS_END.
3921 TEST_USE = set of registers used between ACROSS_FROM and ACROSS_END,
3922 and live before ACROSS_FROM. */
3923
3924 merge_set = BITMAP_ALLOC (&reg_obstack);
3925 merge_use = BITMAP_ALLOC (&reg_obstack);
3926 local_merge_live = BITMAP_ALLOC (&reg_obstack);
3927 test_set = BITMAP_ALLOC (&reg_obstack);
3928 test_use = BITMAP_ALLOC (&reg_obstack);
3929
3930 /* Compute the set of registers set and used in the ACROSS range. */
3931 if (other_branch_live != NULL)
3932 bitmap_copy (test_use, other_branch_live);
3933 df_simulate_initialize_backwards (merge_bb, test_use);
3934 for (insn = across_to; ; insn = next)
3935 {
3936 if (NONDEBUG_INSN_P (insn))
3937 {
3938 df_simulate_find_defs (insn, test_set);
3939 df_simulate_defs (insn, test_use);
3940 df_simulate_uses (insn, test_use);
3941 }
3942 next = PREV_INSN (insn);
3943 if (insn == across_from)
3944 break;
3945 }
3946
3947 /* Compute an upper bound for the amount of insns moved, by finding
3948 the first insn in MERGE that sets a register in TEST_USE, or uses
3949 a register in TEST_SET. We also check for calls, trapping operations,
3950 and memory references. */
3951 max_to = NULL_RTX;
3952 for (insn = from; ; insn = next)
3953 {
3954 if (CALL_P (insn))
3955 break;
3956 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
3957 break;
3958 if (NONDEBUG_INSN_P (insn))
3959 {
f7a60085 3960 if (may_trap_or_fault_p (PATTERN (insn))
4ec5d4f5
BS
3961 && (trapping_insns_in_across || other_branch_live != NULL))
3962 break;
3963
3964 /* We cannot move memory stores past each other, or move memory
3965 reads past stores, at least not without tracking them and
3966 calling true_dependence on every pair.
3967
3968 If there is no other branch and no memory references or
3969 sets in the ACROSS range, we can move memory references
3970 freely, even volatile ones.
3971
3972 Otherwise, the rules are as follows: volatile memory
3973 references and stores can't be moved at all, and any type
3974 of memory reference can't be moved if there are volatile
3975 accesses or stores in the ACROSS range. That leaves
3976 normal reads, which can be moved, as the trapping case is
3977 dealt with elsewhere. */
3978 if (other_branch_live != NULL || memrefs_in_across != 0)
3979 {
3980 int mem_ref_flags = 0;
3981 int mem_set_flags = 0;
3982 note_stores (PATTERN (insn), find_memory_stores, &mem_set_flags);
3983 mem_ref_flags = for_each_rtx (&PATTERN (insn), find_memory,
3984 NULL);
3985 /* Catch sets of the stack pointer. */
3986 mem_ref_flags |= mem_set_flags;
3987
3988 if ((mem_ref_flags | mem_set_flags) & MEMREF_VOLATILE)
3989 break;
3990 if ((memrefs_in_across & MEMREF_VOLATILE) && mem_ref_flags != 0)
3991 break;
3992 if (mem_set_flags != 0
3993 || (mem_sets_in_across != 0 && mem_ref_flags != 0))
3994 break;
3995 }
3996 df_simulate_find_uses (insn, merge_use);
3997 /* We're only interested in uses which use a value live at
3998 the top, not one previously set in this block. */
3999 bitmap_and_compl_into (merge_use, merge_set);
4000 df_simulate_find_defs (insn, merge_set);
4001 if (bitmap_intersect_p (merge_set, test_use)
4002 || bitmap_intersect_p (merge_use, test_set))
4003 break;
0360f70d
BS
4004#ifdef HAVE_cc0
4005 if (!sets_cc0_p (insn))
4006#endif
4007 max_to = insn;
4ec5d4f5
BS
4008 }
4009 next = NEXT_INSN (insn);
4010 if (insn == to)
4011 break;
4012 }
4013 if (max_to != to)
4014 fail = 1;
4015
4016 if (max_to == NULL_RTX || (fail && pmove_upto == NULL))
4017 goto out;
4018
4019 /* Now, lower this upper bound by also taking into account that
4020 a range of insns moved across ACROSS must not leave a register
4021 live at the end that will be clobbered in ACROSS. We need to
4022 find a point where TEST_SET & LIVE == 0.
4023
4024 Insns in the MERGE range that set registers which are also set
4025 in the ACROSS range may still be moved as long as we also move
4026 later insns which use the results of the set, and make the
4027 register dead again. This is verified by the condition stated
4028 above. We only need to test it for registers that are set in
4029 the moved region.
4030
4031 MERGE_LIVE is provided by the caller and holds live registers after
4032 TO. */
4033 bitmap_copy (local_merge_live, merge_live);
4034 for (insn = to; insn != max_to; insn = PREV_INSN (insn))
4035 df_simulate_one_insn_backwards (merge_bb, insn, local_merge_live);
4036
4037 /* We're not interested in registers that aren't set in the moved
4038 region at all. */
4039 bitmap_and_into (local_merge_live, merge_set);
4040 for (;;)
4041 {
4042 if (NONDEBUG_INSN_P (insn))
4043 {
0360f70d
BS
4044 if (!bitmap_intersect_p (test_set, local_merge_live)
4045#ifdef HAVE_cc0
4046 && !sets_cc0_p (insn)
4047#endif
4048 )
4ec5d4f5
BS
4049 {
4050 max_to = insn;
4051 break;
4052 }
4053
4054 df_simulate_one_insn_backwards (merge_bb, insn,
4055 local_merge_live);
4056 }
4057 if (insn == from)
4058 {
4059 fail = 1;
4060 goto out;
4061 }
4062 insn = PREV_INSN (insn);
4063 }
4064
4065 if (max_to != to)
4066 fail = 1;
4067
4068 if (pmove_upto)
4069 *pmove_upto = max_to;
4070
4071 /* For small register class machines, don't lengthen lifetimes of
4072 hard registers before reload. */
4073 if (! reload_completed
4074 && targetm.small_register_classes_for_mode_p (VOIDmode))
4075 {
4076 EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
4077 {
4078 if (i < FIRST_PSEUDO_REGISTER
4079 && ! fixed_regs[i]
4080 && ! global_regs[i])
4081 fail = 1;
4082 }
4083 }
4084
4085 out:
4086 BITMAP_FREE (merge_set);
4087 BITMAP_FREE (merge_use);
4088 BITMAP_FREE (local_merge_live);
4089 BITMAP_FREE (test_set);
4090 BITMAP_FREE (test_use);
4091
4092 return !fail;
4093}
02b47899 4094
c6741572
PB
4095\f
4096/*----------------------------------------------------------------------------
4097 MULTIPLE DEFINITIONS
4098
4099 Find the locations in the function reached by multiple definition sites
f8682ff6
PB
4100 for a live pseudo. In and out bitvectors are built for each basic
4101 block. They are restricted for efficiency to live registers.
c6741572
PB
4102
4103 The gen and kill sets for the problem are obvious. Together they
4104 include all defined registers in a basic block; the gen set includes
4105 registers where a partial or conditional or may-clobber definition is
4106 last in the BB, while the kill set includes registers with a complete
4107 definition coming last. However, the computation of the dataflow
4108 itself is interesting.
4109
4110 The idea behind it comes from SSA form's iterated dominance frontier
4111 criterion for inserting PHI functions. Just like in that case, we can use
4112 the dominance frontier to find places where multiple definitions meet;
4113 a register X defined in a basic block BB1 has multiple definitions in
4114 basic blocks in BB1's dominance frontier.
4115
4116 So, the in-set of a basic block BB2 is not just the union of the
4117 out-sets of BB2's predecessors, but includes some more bits that come
4118 from the basic blocks of whose dominance frontier BB2 is part (BB1 in
4119 the previous paragraph). I called this set the init-set of BB2.
4120
4121 (Note: I actually use the kill-set only to build the init-set.
4122 gen bits are anyway propagated from BB1 to BB2 by dataflow).
4123
4124 For example, if you have
4125
4126 BB1 : r10 = 0
4127 r11 = 0
4128 if <...> goto BB2 else goto BB3;
4129
4130 BB2 : r10 = 1
4131 r12 = 1
4132 goto BB3;
4133
4134 BB3 :
4135
4136 you have BB3 in BB2's dominance frontier but not in BB1's, so that the
4137 init-set of BB3 includes r10 and r12, but not r11. Note that we do
4138 not need to iterate the dominance frontier, because we do not insert
4139 anything like PHI functions there! Instead, dataflow will take care of
b8698a0f 4140 propagating the information to BB3's successors.
c6741572
PB
4141 ---------------------------------------------------------------------------*/
4142
29aba2bb
JH
4143/* Private data used to verify the solution for this problem. */
4144struct df_md_problem_data
4145{
4146 /* An obstack for the bitmaps we need for this problem. */
4147 bitmap_obstack md_bitmaps;
4148};
4149
f8682ff6
PB
4150/* Scratch var used by transfer functions. This is used to do md analysis
4151 only for live registers. */
5c72d561 4152static bitmap_head df_md_scratch;
f8682ff6 4153
c6741572
PB
4154
4155static void
b8698a0f 4156df_md_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
c6741572
PB
4157 void *vbb_info)
4158{
4159 struct df_md_bb_info *bb_info = (struct df_md_bb_info *) vbb_info;
4160 if (bb_info)
4161 {
b33a91c9
JH
4162 bitmap_clear (&bb_info->kill);
4163 bitmap_clear (&bb_info->gen);
4164 bitmap_clear (&bb_info->init);
4165 bitmap_clear (&bb_info->in);
4166 bitmap_clear (&bb_info->out);
c6741572
PB
4167 }
4168}
4169
4170
4171/* Allocate or reset bitmaps for DF_MD. The solution bits are
4172 not touched unless the block is new. */
4173
b8698a0f 4174static void
c6741572
PB
4175df_md_alloc (bitmap all_blocks)
4176{
4177 unsigned int bb_index;
4178 bitmap_iterator bi;
29aba2bb 4179 struct df_md_problem_data *problem_data;
c6741572 4180
c6741572 4181 df_grow_bb_info (df_md);
29aba2bb
JH
4182 if (df_md->problem_data)
4183 problem_data = (struct df_md_problem_data *) df_md->problem_data;
4184 else
4185 {
4186 problem_data = XNEW (struct df_md_problem_data);
4187 df_md->problem_data = problem_data;
4188 bitmap_obstack_initialize (&problem_data->md_bitmaps);
4189 }
4190 bitmap_initialize (&df_md_scratch, &problem_data->md_bitmaps);
c6741572
PB
4191
4192 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4193 {
4194 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
e285df08
JH
4195 /* When bitmaps are already initialized, just clear them. */
4196 if (bb_info->init.obstack)
b8698a0f 4197 {
b33a91c9
JH
4198 bitmap_clear (&bb_info->init);
4199 bitmap_clear (&bb_info->gen);
4200 bitmap_clear (&bb_info->kill);
4201 bitmap_clear (&bb_info->in);
4202 bitmap_clear (&bb_info->out);
c6741572
PB
4203 }
4204 else
b8698a0f 4205 {
29aba2bb
JH
4206 bitmap_initialize (&bb_info->init, &problem_data->md_bitmaps);
4207 bitmap_initialize (&bb_info->gen, &problem_data->md_bitmaps);
4208 bitmap_initialize (&bb_info->kill, &problem_data->md_bitmaps);
4209 bitmap_initialize (&bb_info->in, &problem_data->md_bitmaps);
4210 bitmap_initialize (&bb_info->out, &problem_data->md_bitmaps);
c6741572
PB
4211 }
4212 }
4213
4214 df_md->optional_p = true;
4215}
4216
4217/* Add the effect of the top artificial defs of BB to the multiple definitions
4218 bitmap LOCAL_MD. */
4219
4220void
4221df_md_simulate_artificial_defs_at_top (basic_block bb, bitmap local_md)
4222{
4223 int bb_index = bb->index;
4224 df_ref *def_rec;
4225 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
4226 {
4227 df_ref def = *def_rec;
4228 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
4229 {
4230 unsigned int dregno = DF_REF_REGNO (def);
4231 if (DF_REF_FLAGS (def)
4232 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4233 bitmap_set_bit (local_md, dregno);
4234 else
4235 bitmap_clear_bit (local_md, dregno);
4236 }
4237 }
4238}
4239
4240
4241/* Add the effect of the defs of INSN to the reaching definitions bitmap
4242 LOCAL_MD. */
4243
4244void
4245df_md_simulate_one_insn (basic_block bb ATTRIBUTE_UNUSED, rtx insn,
4246 bitmap local_md)
4247{
4248 unsigned uid = INSN_UID (insn);
4249 df_ref *def_rec;
4250
4251 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
4252 {
4253 df_ref def = *def_rec;
4254 unsigned int dregno = DF_REF_REGNO (def);
4255 if ((!(df->changeable_flags & DF_NO_HARD_REGS))
4256 || (dregno >= FIRST_PSEUDO_REGISTER))
4257 {
4258 if (DF_REF_FLAGS (def)
4259 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4260 bitmap_set_bit (local_md, DF_REF_ID (def));
4261 else
4262 bitmap_clear_bit (local_md, DF_REF_ID (def));
4263 }
4264 }
4265}
4266
4267static void
b8698a0f 4268df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
c6741572
PB
4269 df_ref *def_rec,
4270 int top_flag)
4271{
4272 df_ref def;
5c72d561 4273 bitmap_clear (&seen_in_insn);
c6741572
PB
4274
4275 while ((def = *def_rec++) != NULL)
4276 {
4277 unsigned int dregno = DF_REF_REGNO (def);
4278 if (((!(df->changeable_flags & DF_NO_HARD_REGS))
4279 || (dregno >= FIRST_PSEUDO_REGISTER))
4280 && top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
4281 {
5c72d561 4282 if (!bitmap_bit_p (&seen_in_insn, dregno))
c6741572
PB
4283 {
4284 if (DF_REF_FLAGS (def)
4285 & (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))
4286 {
b33a91c9
JH
4287 bitmap_set_bit (&bb_info->gen, dregno);
4288 bitmap_clear_bit (&bb_info->kill, dregno);
c6741572
PB
4289 }
4290 else
4291 {
4292 /* When we find a clobber and a regular def,
4293 make sure the regular def wins. */
5c72d561 4294 bitmap_set_bit (&seen_in_insn, dregno);
b33a91c9
JH
4295 bitmap_set_bit (&bb_info->kill, dregno);
4296 bitmap_clear_bit (&bb_info->gen, dregno);
c6741572
PB
4297 }
4298 }
4299 }
4300 }
4301}
4302
4303
4304/* Compute local multiple def info for basic block BB. */
4305
4306static void
4307df_md_bb_local_compute (unsigned int bb_index)
4308{
4309 basic_block bb = BASIC_BLOCK (bb_index);
4310 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4311 rtx insn;
4312
4313 /* Artificials are only hard regs. */
4314 if (!(df->changeable_flags & DF_NO_HARD_REGS))
b8698a0f 4315 df_md_bb_local_compute_process_def (bb_info,
c6741572
PB
4316 df_get_artificial_defs (bb_index),
4317 DF_REF_AT_TOP);
4318
4319 FOR_BB_INSNS (bb, insn)
4320 {
4321 unsigned int uid = INSN_UID (insn);
4322 if (!INSN_P (insn))
4323 continue;
4324
4325 df_md_bb_local_compute_process_def (bb_info, DF_INSN_UID_DEFS (uid), 0);
4326 }
4327
4328 if (!(df->changeable_flags & DF_NO_HARD_REGS))
b8698a0f 4329 df_md_bb_local_compute_process_def (bb_info,
c6741572
PB
4330 df_get_artificial_defs (bb_index),
4331 0);
4332}
4333
4334/* Compute local reaching def info for each basic block within BLOCKS. */
4335
4336static void
4337df_md_local_compute (bitmap all_blocks)
4338{
4339 unsigned int bb_index, df_bb_index;
4340 bitmap_iterator bi1, bi2;
4341 basic_block bb;
0fc555fb 4342 bitmap_head *frontiers;
c6741572 4343
5c72d561 4344 bitmap_initialize (&seen_in_insn, &bitmap_default_obstack);
c6741572
PB
4345
4346 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4347 {
4348 df_md_bb_local_compute (bb_index);
4349 }
b8698a0f 4350
5c72d561 4351 bitmap_clear (&seen_in_insn);
c6741572 4352
0fc555fb 4353 frontiers = XNEWVEC (bitmap_head, last_basic_block);
c6741572 4354 FOR_ALL_BB (bb)
0fc555fb 4355 bitmap_initialize (&frontiers[bb->index], &bitmap_default_obstack);
c6741572
PB
4356
4357 compute_dominance_frontiers (frontiers);
4358
4359 /* Add each basic block's kills to the nodes in the frontier of the BB. */
4360 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi1)
4361 {
b33a91c9 4362 bitmap kill = &df_md_get_bb_info (bb_index)->kill;
0fc555fb 4363 EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
c6741572 4364 {
f8682ff6 4365 basic_block bb = BASIC_BLOCK (df_bb_index);
c6741572 4366 if (bitmap_bit_p (all_blocks, df_bb_index))
b33a91c9 4367 bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
f8682ff6 4368 df_get_live_in (bb));
c6741572
PB
4369 }
4370 }
4371
4372 FOR_ALL_BB (bb)
0fc555fb 4373 bitmap_clear (&frontiers[bb->index]);
c6741572
PB
4374 free (frontiers);
4375}
4376
4377
4378/* Reset the global solution for recalculation. */
4379
b8698a0f 4380static void
c6741572
PB
4381df_md_reset (bitmap all_blocks)
4382{
4383 unsigned int bb_index;
4384 bitmap_iterator bi;
4385
4386 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4387 {
4388 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
4389 gcc_assert (bb_info);
b33a91c9
JH
4390 bitmap_clear (&bb_info->in);
4391 bitmap_clear (&bb_info->out);
c6741572
PB
4392 }
4393}
4394
4395static bool
4396df_md_transfer_function (int bb_index)
4397{
f8682ff6 4398 basic_block bb = BASIC_BLOCK (bb_index);
c6741572 4399 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
b33a91c9
JH
4400 bitmap in = &bb_info->in;
4401 bitmap out = &bb_info->out;
4402 bitmap gen = &bb_info->gen;
4403 bitmap kill = &bb_info->kill;
c6741572 4404
f8682ff6
PB
4405 /* We need to use a scratch set here so that the value returned from this
4406 function invocation properly reflects whether the sets changed in a
4407 significant way; i.e. not just because the live set was anded in. */
5c72d561 4408 bitmap_and (&df_md_scratch, gen, df_get_live_out (bb));
f8682ff6
PB
4409
4410 /* Multiple definitions of a register are not relevant if it is not
4411 live. Thus we trim the result to the places where it is live. */
4412 bitmap_and_into (in, df_get_live_in (bb));
4413
5c72d561 4414 return bitmap_ior_and_compl (out, &df_md_scratch, in, kill);
c6741572
PB
4415}
4416
4417/* Initialize the solution bit vectors for problem. */
4418
b8698a0f 4419static void
c6741572
PB
4420df_md_init (bitmap all_blocks)
4421{
4422 unsigned int bb_index;
4423 bitmap_iterator bi;
4424
4425 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
4426 {
4427 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
b8698a0f 4428
b33a91c9 4429 bitmap_copy (&bb_info->in, &bb_info->init);
c6741572
PB
4430 df_md_transfer_function (bb_index);
4431 }
4432}
4433
4434static void
4435df_md_confluence_0 (basic_block bb)
4436{
4437 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
b33a91c9 4438 bitmap_copy (&bb_info->in, &bb_info->init);
b8698a0f 4439}
c6741572
PB
4440
4441/* In of target gets or of out of source. */
4442
1a0f3fa1 4443static bool
c6741572
PB
4444df_md_confluence_n (edge e)
4445{
b33a91c9
JH
4446 bitmap op1 = &df_md_get_bb_info (e->dest->index)->in;
4447 bitmap op2 = &df_md_get_bb_info (e->src->index)->out;
c6741572 4448
b8698a0f 4449 if (e->flags & EDGE_FAKE)
1a0f3fa1 4450 return false;
c6741572
PB
4451
4452 if (e->flags & EDGE_EH)
50b2e859
JH
4453 return bitmap_ior_and_compl_into (op1, op2,
4454 regs_invalidated_by_call_regset);
c6741572 4455 else
1a0f3fa1 4456 return bitmap_ior_into (op1, op2);
c6741572
PB
4457}
4458
4459/* Free all storage associated with the problem. */
4460
4461static void
4462df_md_free (void)
4463{
29aba2bb
JH
4464 struct df_md_problem_data *problem_data
4465 = (struct df_md_problem_data *) df_md->problem_data;
c6741572 4466
29aba2bb 4467 bitmap_obstack_release (&problem_data->md_bitmaps);
d725a1a5
JH
4468 free (problem_data);
4469 df_md->problem_data = NULL;
c6741572
PB
4470
4471 df_md->block_info_size = 0;
4472 free (df_md->block_info);
e285df08 4473 df_md->block_info = NULL;
c6741572
PB
4474 free (df_md);
4475}
4476
4477
4478/* Debugging info at top of bb. */
4479
4480static void
4481df_md_top_dump (basic_block bb, FILE *file)
4482{
4483 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
b33a91c9 4484 if (!bb_info)
c6741572 4485 return;
b8698a0f 4486
c6741572 4487 fprintf (file, ";; md in \t");
b33a91c9 4488 df_print_regset (file, &bb_info->in);
c6741572 4489 fprintf (file, ";; md init \t");
b33a91c9 4490 df_print_regset (file, &bb_info->init);
c6741572 4491 fprintf (file, ";; md gen \t");
b33a91c9 4492 df_print_regset (file, &bb_info->gen);
c6741572 4493 fprintf (file, ";; md kill \t");
b33a91c9 4494 df_print_regset (file, &bb_info->kill);
c6741572
PB
4495}
4496
4497/* Debugging info at bottom of bb. */
4498
4499static void
4500df_md_bottom_dump (basic_block bb, FILE *file)
4501{
4502 struct df_md_bb_info *bb_info = df_md_get_bb_info (bb->index);
b33a91c9 4503 if (!bb_info)
c6741572 4504 return;
b8698a0f 4505
c6741572 4506 fprintf (file, ";; md out \t");
b33a91c9 4507 df_print_regset (file, &bb_info->out);
b8698a0f 4508}
c6741572
PB
4509
4510static struct df_problem problem_MD =
4511{
4512 DF_MD, /* Problem id. */
4513 DF_FORWARD, /* Direction. */
4514 df_md_alloc, /* Allocate the problem specific data. */
4515 df_md_reset, /* Reset global information. */
4516 df_md_free_bb_info, /* Free basic block info. */
4517 df_md_local_compute, /* Local compute function. */
4518 df_md_init, /* Init the solution specific data. */
4519 df_worklist_dataflow, /* Worklist solver. */
b8698a0f
L
4520 df_md_confluence_0, /* Confluence operator 0. */
4521 df_md_confluence_n, /* Confluence operator n. */
c6741572
PB
4522 df_md_transfer_function, /* Transfer function. */
4523 NULL, /* Finalize function. */
4524 df_md_free, /* Free all of the problem information. */
4525 df_md_free, /* Remove this problem from the stack of dataflow problems. */
4526 NULL, /* Debugging. */
4527 df_md_top_dump, /* Debugging start block. */
4528 df_md_bottom_dump, /* Debugging end block. */
4529 NULL, /* Incremental solution verify start. */
4530 NULL, /* Incremental solution verify end. */
4531 NULL, /* Dependent problem. */
e285df08 4532 sizeof (struct df_md_bb_info),/* Size of entry of block_info array. */
b8698a0f 4533 TV_DF_MD, /* Timing variable. */
c6741572
PB
4534 false /* Reset blocks on dropping out of blocks_to_analyze. */
4535};
4536
4537/* Create a new MD instance and add it to the existing instance
4538 of DF. */
4539
4540void
4541df_md_add_problem (void)
4542{
4543 df_add_problem (&problem_MD);
4544}
4545
4546
4547