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