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