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