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