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