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