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