]>
Commit | Line | Data |
---|---|---|
6fb5fa3c | 1 | /* Scanning of rtl for dataflow analysis. |
5624e564 | 2 | Copyright (C) 2007-2015 Free Software Foundation, Inc. |
6fb5fa3c DB |
3 | Contributed by Kenneth Zadeck (zadeck@naturalbridge.com). |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
6fb5fa3c DB |
10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6fb5fa3c DB |
20 | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
c7131fb2 | 25 | #include "backend.h" |
6fb5fa3c | 26 | #include "rtl.h" |
957060b5 | 27 | #include "predict.h" |
c7131fb2 | 28 | #include "df.h" |
6fb5fa3c | 29 | #include "tm_p.h" |
6fb5fa3c | 30 | #include "regs.h" |
957060b5 | 31 | #include "flags.h" |
6fb5fa3c | 32 | #include "except.h" |
6fb5fa3c DB |
33 | |
34 | ||
6fb5fa3c DB |
35 | struct regstat_n_sets_and_refs_t *regstat_n_sets_and_refs; |
36 | ||
37 | /*---------------------------------------------------------------------------- | |
b8698a0f | 38 | REG_N_SETS and REG_N_REFS. |
6fb5fa3c DB |
39 | ----------------------------------------------------------------------------*/ |
40 | ||
dd5a833e | 41 | /* If a pass need to change these values in some magical way or the |
6fb5fa3c DB |
42 | pass needs to have accurate values for these and is not using |
43 | incremental df scanning, then it should use REG_N_SETS and | |
44 | REG_N_USES. If the pass is doing incremental scanning then it | |
45 | should be getting the info from DF_REG_DEF_COUNT and | |
46 | DF_REG_USE_COUNT. */ | |
47 | ||
48 | void | |
49 | regstat_init_n_sets_and_refs (void) | |
50 | { | |
51 | unsigned int i; | |
52 | unsigned int max_regno = max_reg_num (); | |
53 | ||
54 | timevar_push (TV_REG_STATS); | |
55 | df_grow_reg_info (); | |
56 | gcc_assert (!regstat_n_sets_and_refs); | |
57 | ||
1634b18f | 58 | regstat_n_sets_and_refs = XNEWVEC (struct regstat_n_sets_and_refs_t, max_regno); |
6fb5fa3c | 59 | |
b5b8b0ac AO |
60 | if (MAY_HAVE_DEBUG_INSNS) |
61 | for (i = 0; i < max_regno; i++) | |
62 | { | |
63 | int use_count; | |
64 | df_ref use; | |
65 | ||
66 | use_count = DF_REG_USE_COUNT (i); | |
67 | for (use = DF_REG_USE_CHAIN (i); use; use = DF_REF_NEXT_REG (use)) | |
68 | if (DF_REF_INSN_INFO (use) && DEBUG_INSN_P (DF_REF_INSN (use))) | |
69 | use_count--; | |
70 | ||
71 | ||
72 | SET_REG_N_SETS (i, DF_REG_DEF_COUNT (i)); | |
73 | SET_REG_N_REFS (i, use_count + REG_N_SETS (i)); | |
74 | } | |
75 | else | |
76 | for (i = 0; i < max_regno; i++) | |
77 | { | |
78 | SET_REG_N_SETS (i, DF_REG_DEF_COUNT (i)); | |
79 | SET_REG_N_REFS (i, DF_REG_USE_COUNT (i) + REG_N_SETS (i)); | |
80 | } | |
6fb5fa3c DB |
81 | timevar_pop (TV_REG_STATS); |
82 | ||
83 | } | |
84 | ||
85 | ||
86 | /* Free the array that holds the REG_N_SETS and REG_N_REFS. */ | |
87 | ||
88 | void | |
89 | regstat_free_n_sets_and_refs (void) | |
90 | { | |
91 | gcc_assert (regstat_n_sets_and_refs); | |
92 | free (regstat_n_sets_and_refs); | |
93 | regstat_n_sets_and_refs = NULL; | |
94 | } | |
95 | ||
96 | ||
97 | /*---------------------------------------------------------------------------- | |
98 | REGISTER INFORMATION | |
99 | ||
100 | Process REG_N_DEATHS, REG_LIVE_LENGTH, REG_N_CALLS_CROSSED, | |
101 | REG_N_THROWING_CALLS_CROSSED and REG_BASIC_BLOCK. | |
102 | ||
103 | ----------------------------------------------------------------------------*/ | |
104 | ||
105 | static bitmap setjmp_crosses; | |
106 | struct reg_info_t *reg_info_p; | |
107 | ||
108 | /* The number allocated elements of reg_info_p. */ | |
109 | size_t reg_info_p_size; | |
110 | ||
111 | /* Compute register info: lifetime, bb, and number of defs and uses | |
112 | for basic block BB. The three bitvectors are scratch regs used | |
113 | here. */ | |
114 | ||
115 | static void | |
b8698a0f | 116 | regstat_bb_compute_ri (unsigned int bb_index, |
8e6acdb8 SB |
117 | bitmap live, bitmap artificial_uses, |
118 | bitmap local_live, bitmap local_processed, | |
119 | int *local_live_last_luid) | |
6fb5fa3c | 120 | { |
06e28de2 | 121 | basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index); |
7839a073 | 122 | rtx_insn *insn; |
bfac633a | 123 | df_ref def, use; |
6fb5fa3c DB |
124 | int luid = 0; |
125 | bitmap_iterator bi; | |
126 | unsigned int regno; | |
127 | ||
128 | bitmap_copy (live, df_get_live_out (bb)); | |
129 | bitmap_clear (artificial_uses); | |
130 | ||
131 | /* Process the regs live at the end of the block. Mark them as | |
132 | not local to any one basic block. */ | |
133 | EXECUTE_IF_SET_IN_BITMAP (live, 0, regno, bi) | |
134 | REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL; | |
135 | ||
136 | /* Process the artificial defs and uses at the bottom of the block | |
137 | to begin processing. */ | |
292321a5 RS |
138 | FOR_EACH_ARTIFICIAL_DEF (def, bb_index) |
139 | if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0) | |
140 | bitmap_clear_bit (live, DF_REF_REGNO (def)); | |
6fb5fa3c | 141 | |
292321a5 RS |
142 | FOR_EACH_ARTIFICIAL_USE (use, bb_index) |
143 | if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0) | |
144 | { | |
145 | regno = DF_REF_REGNO (use); | |
146 | bitmap_set_bit (live, regno); | |
147 | bitmap_set_bit (artificial_uses, regno); | |
148 | } | |
b8698a0f | 149 | |
6fb5fa3c DB |
150 | FOR_BB_INSNS_REVERSE (bb, insn) |
151 | { | |
bfac633a | 152 | struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); |
6fb5fa3c | 153 | bitmap_iterator bi; |
fc8e9f58 | 154 | df_mw_hardreg *mw; |
6fb5fa3c | 155 | rtx link; |
b8698a0f | 156 | |
b5b8b0ac | 157 | if (!NONDEBUG_INSN_P (insn)) |
6fb5fa3c DB |
158 | continue; |
159 | ||
6fb5fa3c | 160 | luid++; |
b8698a0f | 161 | |
6fb5fa3c DB |
162 | link = REG_NOTES (insn); |
163 | while (link) | |
164 | { | |
165 | if (REG_NOTE_KIND (link) == REG_DEAD) | |
c3284718 | 166 | REG_N_DEATHS (REGNO (XEXP (link, 0)))++; |
6fb5fa3c DB |
167 | link = XEXP (link, 1); |
168 | } | |
169 | ||
170 | /* Process the defs. */ | |
171 | if (CALL_P (insn)) | |
172 | { | |
b8698a0f | 173 | bool can_throw = can_throw_internal (insn); |
6fb5fa3c DB |
174 | bool set_jump = (find_reg_note (insn, REG_SETJMP, NULL) != NULL); |
175 | EXECUTE_IF_SET_IN_BITMAP (live, 0, regno, bi) | |
176 | { | |
177 | REG_N_CALLS_CROSSED (regno)++; | |
a03c6d64 | 178 | REG_FREQ_CALLS_CROSSED (regno) += REG_FREQ_FROM_BB (bb); |
8e6acdb8 SB |
179 | REG_FREQ_CALLS_CROSSED (regno) = |
180 | MIN (REG_FREQ_CALLS_CROSSED (regno), REG_FREQ_MAX); | |
6fb5fa3c DB |
181 | if (can_throw) |
182 | REG_N_THROWING_CALLS_CROSSED (regno)++; | |
b8698a0f | 183 | |
6fb5fa3c DB |
184 | /* We have a problem with any pseudoreg that lives |
185 | across the setjmp. ANSI says that if a user variable | |
186 | does not change in value between the setjmp and the | |
187 | longjmp, then the longjmp preserves it. This | |
188 | includes longjmp from a place where the pseudo | |
189 | appears dead. (In principle, the value still exists | |
190 | if it is in scope.) If the pseudo goes in a hard | |
191 | reg, some other value may occupy that hard reg where | |
192 | this pseudo is dead, thus clobbering the pseudo. | |
193 | Conclusion: such a pseudo must not go in a hard | |
194 | reg. */ | |
195 | if (set_jump) | |
196 | bitmap_set_bit (setjmp_crosses, regno); | |
197 | } | |
198 | } | |
b8698a0f | 199 | |
8e6acdb8 SB |
200 | /* We only care about real sets for calls. Clobbers cannot |
201 | be depended on. | |
202 | Only do this if the value is totally dead. */ | |
fc8e9f58 RS |
203 | FOR_EACH_INSN_INFO_MW (mw, insn_info) |
204 | if (DF_MWS_REG_DEF_P (mw)) | |
205 | { | |
206 | bool all_dead = true; | |
207 | unsigned int r; | |
208 | ||
209 | for (r = mw->start_regno; r <= mw->end_regno; r++) | |
210 | if (bitmap_bit_p (artificial_uses, r) | |
211 | || bitmap_bit_p (live, r)) | |
6fb5fa3c | 212 | { |
fc8e9f58 RS |
213 | all_dead = false; |
214 | break; | |
6fb5fa3c | 215 | } |
fc8e9f58 RS |
216 | |
217 | if (all_dead) | |
218 | { | |
219 | regno = mw->start_regno; | |
220 | REG_LIVE_LENGTH (regno)++; | |
221 | } | |
222 | } | |
b8698a0f | 223 | |
6fb5fa3c DB |
224 | /* All of the defs except the return value are some sort of |
225 | clobber. This code is for the return. */ | |
bfac633a | 226 | FOR_EACH_INSN_INFO_DEF (def, insn_info) |
6fb5fa3c | 227 | { |
6fb5fa3c DB |
228 | if ((!CALL_P (insn)) |
229 | || (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))) | |
230 | { | |
231 | unsigned int dregno = DF_REF_REGNO (def); | |
b8698a0f | 232 | |
6fb5fa3c DB |
233 | if (bitmap_bit_p (live, dregno)) |
234 | { | |
8e6acdb8 SB |
235 | /* If we have seen a use of DREGNO somewhere before (i.e. |
236 | later in this basic block), and DEF is not a subreg | |
237 | store or conditional store, then kill the register | |
238 | here and add the proper length to its REG_LIVE_LENGTH. | |
239 | ||
240 | If we have not seen a use of DREGNO later in this basic | |
241 | block, then we need to add the length from here to the | |
242 | end of the block to the live length. */ | |
243 | if (bitmap_bit_p (local_live, dregno)) | |
6fb5fa3c | 244 | { |
8e6acdb8 SB |
245 | /* Note that LOCAL_LIVE implies LOCAL_PROCESSED, so |
246 | we don't have to set LOCAL_PROCESSED in this clause. */ | |
6fb5fa3c | 247 | if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))) |
8e6acdb8 SB |
248 | { |
249 | REG_LIVE_LENGTH (dregno) += | |
250 | (luid - local_live_last_luid[dregno]); | |
251 | local_live_last_luid[dregno] = luid; | |
252 | bitmap_clear_bit (local_live, dregno); | |
253 | } | |
6fb5fa3c DB |
254 | } |
255 | else | |
256 | { | |
257 | bitmap_set_bit (local_processed, dregno); | |
258 | REG_LIVE_LENGTH (dregno) += luid; | |
8e6acdb8 | 259 | local_live_last_luid[dregno] = luid; |
6fb5fa3c | 260 | } |
8e6acdb8 SB |
261 | |
262 | /* Kill this register if it is not a subreg store or | |
263 | conditional store. | |
264 | ??? This means that any partial store is live from | |
265 | the last use in a basic block to the start of this | |
266 | basic block. This results in poor calculations of | |
267 | REG_LIVE_LENGTH in large basic blocks. */ | |
268 | if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))) | |
269 | bitmap_clear_bit (live, dregno); | |
6fb5fa3c DB |
270 | } |
271 | else if ((!(DF_REF_FLAGS (def) & DF_REF_MW_HARDREG)) | |
272 | && (!bitmap_bit_p (artificial_uses, dregno))) | |
273 | { | |
274 | REG_LIVE_LENGTH (dregno)++; | |
275 | } | |
b8698a0f | 276 | |
6fb5fa3c DB |
277 | if (dregno >= FIRST_PSEUDO_REGISTER) |
278 | { | |
279 | REG_FREQ (dregno) += REG_FREQ_FROM_BB (bb); | |
8e6acdb8 SB |
280 | REG_FREQ (dregno) = |
281 | MIN (REG_FREQ (dregno), REG_FREQ_MAX); | |
282 | ||
6fb5fa3c DB |
283 | if (REG_BASIC_BLOCK (dregno) == REG_BLOCK_UNKNOWN) |
284 | REG_BASIC_BLOCK (dregno) = bb->index; | |
285 | else if (REG_BASIC_BLOCK (dregno) != bb->index) | |
286 | REG_BASIC_BLOCK (dregno) = REG_BLOCK_GLOBAL; | |
287 | } | |
6fb5fa3c DB |
288 | } |
289 | } | |
b8698a0f | 290 | |
bfac633a | 291 | FOR_EACH_INSN_INFO_USE (use, insn_info) |
6fb5fa3c | 292 | { |
6fb5fa3c DB |
293 | unsigned int uregno = DF_REF_REGNO (use); |
294 | ||
295 | if (uregno >= FIRST_PSEUDO_REGISTER) | |
296 | { | |
297 | REG_FREQ (uregno) += REG_FREQ_FROM_BB (bb); | |
8e6acdb8 SB |
298 | REG_FREQ (uregno) = |
299 | MIN (REG_FREQ (uregno), REG_FREQ_MAX); | |
300 | ||
6fb5fa3c DB |
301 | if (REG_BASIC_BLOCK (uregno) == REG_BLOCK_UNKNOWN) |
302 | REG_BASIC_BLOCK (uregno) = bb->index; | |
303 | else if (REG_BASIC_BLOCK (uregno) != bb->index) | |
304 | REG_BASIC_BLOCK (uregno) = REG_BLOCK_GLOBAL; | |
305 | } | |
b8698a0f | 306 | |
fcaa4ca4 | 307 | if (bitmap_set_bit (live, uregno)) |
6fb5fa3c | 308 | { |
8e6acdb8 SB |
309 | /* This register is now live. Begin to process it locally. |
310 | ||
311 | Note that we don't even get here if the variable was live | |
312 | at the end of the block since just a ref inside the block | |
313 | does not effect the calculations. */ | |
6fb5fa3c | 314 | REG_LIVE_LENGTH (uregno) ++; |
8e6acdb8 | 315 | local_live_last_luid[uregno] = luid; |
6fb5fa3c DB |
316 | bitmap_set_bit (local_live, uregno); |
317 | bitmap_set_bit (local_processed, uregno); | |
318 | } | |
319 | } | |
320 | } | |
b8698a0f | 321 | |
8e6acdb8 SB |
322 | /* Add the liveness length to all registers that were used somewhere |
323 | in this bock, but not between that use and the head of this block. */ | |
324 | EXECUTE_IF_SET_IN_BITMAP (local_live, 0, regno, bi) | |
325 | { | |
326 | REG_LIVE_LENGTH (regno) += (luid - local_live_last_luid[regno]); | |
327 | } | |
328 | ||
6fb5fa3c DB |
329 | /* Add the length of the block to all of the registers that were not |
330 | referenced, but still live in this block. */ | |
331 | bitmap_and_compl_into (live, local_processed); | |
332 | EXECUTE_IF_SET_IN_BITMAP (live, 0, regno, bi) | |
333 | REG_LIVE_LENGTH (regno) += luid; | |
334 | ||
335 | bitmap_clear (local_processed); | |
336 | bitmap_clear (local_live); | |
337 | } | |
338 | ||
339 | ||
340 | /* Compute register info: lifetime, bb, and number of defs and uses. */ | |
341 | void | |
342 | regstat_compute_ri (void) | |
343 | { | |
344 | basic_block bb; | |
345 | bitmap live = BITMAP_ALLOC (&df_bitmap_obstack); | |
6fb5fa3c DB |
346 | bitmap artificial_uses = BITMAP_ALLOC (&df_bitmap_obstack); |
347 | bitmap local_live = BITMAP_ALLOC (&df_bitmap_obstack); | |
348 | bitmap local_processed = BITMAP_ALLOC (&df_bitmap_obstack); | |
349 | unsigned int regno; | |
350 | bitmap_iterator bi; | |
8e6acdb8 | 351 | int *local_live_last_luid; |
6fb5fa3c DB |
352 | |
353 | /* Initialize everything. */ | |
354 | ||
355 | gcc_assert (!reg_info_p); | |
356 | ||
357 | timevar_push (TV_REG_STATS); | |
358 | setjmp_crosses = BITMAP_ALLOC (&df_bitmap_obstack); | |
359 | max_regno = max_reg_num (); | |
360 | reg_info_p_size = max_regno; | |
1634b18f | 361 | reg_info_p = XCNEWVEC (struct reg_info_t, max_regno); |
8e6acdb8 | 362 | local_live_last_luid = XNEWVEC (int, max_regno); |
6fb5fa3c | 363 | |
11cd3bed | 364 | FOR_EACH_BB_FN (bb, cfun) |
6fb5fa3c | 365 | { |
8e6acdb8 SB |
366 | regstat_bb_compute_ri (bb->index, live, artificial_uses, |
367 | local_live, local_processed, | |
368 | local_live_last_luid); | |
6fb5fa3c DB |
369 | } |
370 | ||
371 | BITMAP_FREE (live); | |
6fb5fa3c | 372 | BITMAP_FREE (artificial_uses); |
8e6acdb8 SB |
373 | BITMAP_FREE (local_live); |
374 | BITMAP_FREE (local_processed); | |
375 | free (local_live_last_luid); | |
6fb5fa3c | 376 | |
aeb9f7cf | 377 | /* See the setjmp comment in regstat_bb_compute_ri. */ |
6fb5fa3c DB |
378 | EXECUTE_IF_SET_IN_BITMAP (setjmp_crosses, FIRST_PSEUDO_REGISTER, regno, bi) |
379 | { | |
380 | REG_BASIC_BLOCK (regno) = REG_BLOCK_UNKNOWN; | |
381 | REG_LIVE_LENGTH (regno) = -1; | |
b8698a0f L |
382 | } |
383 | ||
6fb5fa3c DB |
384 | timevar_pop (TV_REG_STATS); |
385 | } | |
386 | ||
387 | ||
388 | /* Free all storage associated with the problem. */ | |
389 | ||
390 | void | |
391 | regstat_free_ri (void) | |
392 | { | |
393 | gcc_assert (reg_info_p); | |
394 | reg_info_p_size = 0; | |
b8698a0f | 395 | free (reg_info_p); |
6fb5fa3c DB |
396 | reg_info_p = NULL; |
397 | ||
398 | BITMAP_FREE (setjmp_crosses); | |
399 | } | |
400 | ||
401 | ||
b8698a0f | 402 | /* Return a bitmap containing the set of registers that cross a setjmp. |
6fb5fa3c DB |
403 | The client should not change or delete this bitmap. */ |
404 | ||
405 | bitmap | |
406 | regstat_get_setjmp_crosses (void) | |
407 | { | |
408 | return setjmp_crosses; | |
409 | } | |
410 | ||
411 | /*---------------------------------------------------------------------------- | |
b8698a0f | 412 | Process REG_N_CALLS_CROSSED. |
6fb5fa3c DB |
413 | |
414 | This is used by sched_deps. A good implementation of sched-deps | |
cea618ac | 415 | would really process the blocks directly rather than going through |
6fb5fa3c DB |
416 | lists of insns. If it did this, it could use the exact regs that |
417 | cross an individual call rather than using this info that merges | |
418 | the info for all calls. | |
419 | ||
420 | ----------------------------------------------------------------------------*/ | |
421 | ||
422 | ||
423 | ||
0d52bcc1 | 424 | /* Compute calls crossed for BB. Live is a scratch bitvector. */ |
6fb5fa3c DB |
425 | |
426 | static void | |
427 | regstat_bb_compute_calls_crossed (unsigned int bb_index, bitmap live) | |
428 | { | |
06e28de2 | 429 | basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index); |
7839a073 | 430 | rtx_insn *insn; |
bfac633a | 431 | df_ref def, use; |
6fb5fa3c DB |
432 | |
433 | bitmap_copy (live, df_get_live_out (bb)); | |
434 | ||
435 | /* Process the artificial defs and uses at the bottom of the block | |
436 | to begin processing. */ | |
292321a5 RS |
437 | FOR_EACH_ARTIFICIAL_DEF (def, bb_index) |
438 | if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0) | |
439 | bitmap_clear_bit (live, DF_REF_REGNO (def)); | |
6fb5fa3c | 440 | |
292321a5 RS |
441 | FOR_EACH_ARTIFICIAL_USE (use, bb_index) |
442 | if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0) | |
443 | bitmap_set_bit (live, DF_REF_REGNO (use)); | |
b8698a0f | 444 | |
6fb5fa3c DB |
445 | FOR_BB_INSNS_REVERSE (bb, insn) |
446 | { | |
bfac633a | 447 | struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); |
6fb5fa3c | 448 | unsigned int regno; |
b8698a0f | 449 | |
6fb5fa3c DB |
450 | if (!INSN_P (insn)) |
451 | continue; | |
452 | ||
453 | /* Process the defs. */ | |
454 | if (CALL_P (insn)) | |
455 | { | |
456 | bitmap_iterator bi; | |
457 | EXECUTE_IF_SET_IN_BITMAP (live, 0, regno, bi) | |
a03c6d64 JH |
458 | { |
459 | REG_N_CALLS_CROSSED (regno)++; | |
460 | REG_FREQ_CALLS_CROSSED (regno) += REG_FREQ_FROM_BB (bb); | |
8e6acdb8 SB |
461 | REG_FREQ_CALLS_CROSSED (regno) = |
462 | MIN (REG_FREQ_CALLS_CROSSED (regno), REG_FREQ_MAX); | |
a03c6d64 | 463 | } |
6fb5fa3c | 464 | } |
b8698a0f | 465 | |
6fb5fa3c DB |
466 | /* All of the defs except the return value are some sort of |
467 | clobber. This code is for the return. */ | |
bfac633a | 468 | FOR_EACH_INSN_INFO_DEF (def, insn_info) |
6fb5fa3c | 469 | { |
6fb5fa3c DB |
470 | if ((!CALL_P (insn)) |
471 | || (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))) | |
472 | { | |
473 | /* Kill this register if it is not a subreg store or conditional store. */ | |
474 | if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))) | |
475 | bitmap_clear_bit (live, DF_REF_REGNO (def)); | |
476 | } | |
477 | } | |
b8698a0f | 478 | |
bfac633a RS |
479 | FOR_EACH_INSN_INFO_USE (use, insn_info) |
480 | bitmap_set_bit (live, DF_REF_REGNO (use)); | |
6fb5fa3c DB |
481 | } |
482 | } | |
483 | ||
484 | ||
485 | /* Compute register info: lifetime, bb, and number of defs and uses. */ | |
486 | void | |
487 | regstat_compute_calls_crossed (void) | |
488 | { | |
489 | basic_block bb; | |
490 | bitmap live = BITMAP_ALLOC (&df_bitmap_obstack); | |
491 | ||
492 | /* Initialize everything. */ | |
493 | gcc_assert (!reg_info_p); | |
494 | ||
495 | timevar_push (TV_REG_STATS); | |
496 | max_regno = max_reg_num (); | |
497 | reg_info_p_size = max_regno; | |
1634b18f | 498 | reg_info_p = XCNEWVEC (struct reg_info_t, max_regno); |
6fb5fa3c | 499 | |
11cd3bed | 500 | FOR_EACH_BB_FN (bb, cfun) |
6fb5fa3c DB |
501 | { |
502 | regstat_bb_compute_calls_crossed (bb->index, live); | |
503 | } | |
504 | ||
505 | BITMAP_FREE (live); | |
506 | timevar_pop (TV_REG_STATS); | |
507 | } | |
508 | ||
509 | ||
510 | /* Free all storage associated with the problem. */ | |
511 | ||
512 | void | |
513 | regstat_free_calls_crossed (void) | |
514 | { | |
515 | gcc_assert (reg_info_p); | |
516 | reg_info_p_size = 0; | |
b8698a0f | 517 | free (reg_info_p); |
6fb5fa3c DB |
518 | reg_info_p = NULL; |
519 | } | |
520 | ||
532aafad SB |
521 | /* Dump the register info to FILE. */ |
522 | ||
523 | void | |
524 | dump_reg_info (FILE *file) | |
525 | { | |
526 | unsigned int i, max = max_reg_num (); | |
527 | if (reload_completed) | |
528 | return; | |
529 | ||
530 | if (reg_info_p_size < max) | |
531 | max = reg_info_p_size; | |
532 | ||
533 | fprintf (file, "%d registers.\n", max); | |
534 | for (i = FIRST_PSEUDO_REGISTER; i < max; i++) | |
535 | { | |
536 | enum reg_class rclass, altclass; | |
537 | ||
538 | if (regstat_n_sets_and_refs) | |
539 | fprintf (file, "\nRegister %d used %d times across %d insns", | |
540 | i, REG_N_REFS (i), REG_LIVE_LENGTH (i)); | |
541 | else if (df) | |
542 | fprintf (file, "\nRegister %d used %d times across %d insns", | |
543 | i, DF_REG_USE_COUNT (i) + DF_REG_DEF_COUNT (i), REG_LIVE_LENGTH (i)); | |
544 | ||
545 | if (REG_BASIC_BLOCK (i) >= NUM_FIXED_BLOCKS) | |
546 | fprintf (file, " in block %d", REG_BASIC_BLOCK (i)); | |
547 | if (regstat_n_sets_and_refs) | |
548 | fprintf (file, "; set %d time%s", REG_N_SETS (i), | |
549 | (REG_N_SETS (i) == 1) ? "" : "s"); | |
550 | else if (df) | |
551 | fprintf (file, "; set %d time%s", DF_REG_DEF_COUNT (i), | |
552 | (DF_REG_DEF_COUNT (i) == 1) ? "" : "s"); | |
553 | if (regno_reg_rtx[i] != NULL && REG_USERVAR_P (regno_reg_rtx[i])) | |
554 | fputs ("; user var", file); | |
555 | if (REG_N_DEATHS (i) != 1) | |
556 | fprintf (file, "; dies in %d places", REG_N_DEATHS (i)); | |
557 | if (REG_N_CALLS_CROSSED (i) == 1) | |
558 | fputs ("; crosses 1 call", file); | |
559 | else if (REG_N_CALLS_CROSSED (i)) | |
560 | fprintf (file, "; crosses %d calls", REG_N_CALLS_CROSSED (i)); | |
561 | if (REG_FREQ_CALLS_CROSSED (i)) | |
562 | fprintf (file, "; crosses call with %d frequency", REG_FREQ_CALLS_CROSSED (i)); | |
563 | if (regno_reg_rtx[i] != NULL | |
564 | && PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD) | |
565 | fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i)); | |
566 | ||
567 | rclass = reg_preferred_class (i); | |
568 | altclass = reg_alternate_class (i); | |
569 | if (rclass != GENERAL_REGS || altclass != ALL_REGS) | |
570 | { | |
571 | if (altclass == ALL_REGS || rclass == ALL_REGS) | |
572 | fprintf (file, "; pref %s", reg_class_names[(int) rclass]); | |
573 | else if (altclass == NO_REGS) | |
574 | fprintf (file, "; %s or none", reg_class_names[(int) rclass]); | |
575 | else | |
576 | fprintf (file, "; pref %s, else %s", | |
577 | reg_class_names[(int) rclass], | |
578 | reg_class_names[(int) altclass]); | |
579 | } | |
580 | ||
581 | if (regno_reg_rtx[i] != NULL && REG_POINTER (regno_reg_rtx[i])) | |
582 | fputs ("; pointer", file); | |
583 | fputs (".\n", file); | |
584 | } | |
585 | } | |
586 |