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