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