]>
Commit | Line | Data |
---|---|---|
e011eba9 | 1 | /* Scanning of rtl for dataflow analysis. |
fbd26352 | 2 | Copyright (C) 1999-2019 Free Software Foundation, Inc. |
48e1416a | 3 | Originally contributed by Michael P. Hayes |
e011eba9 | 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 | |
8c4c00c1 | 12 | Software Foundation; either version 3, or (at your option) any later |
e011eba9 | 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 | |
8c4c00c1 | 21 | along with GCC; see the file COPYING3. If not see |
22 | <http://www.gnu.org/licenses/>. */ | |
e011eba9 | 23 | |
24 | #include "config.h" | |
25 | #include "system.h" | |
26 | #include "coretypes.h" | |
9ef16211 | 27 | #include "backend.h" |
7c29e30e | 28 | #include "target.h" |
e011eba9 | 29 | #include "rtl.h" |
7c29e30e | 30 | #include "tree.h" |
9ef16211 | 31 | #include "df.h" |
ad7b10a2 | 32 | #include "memmodel.h" |
e011eba9 | 33 | #include "tm_p.h" |
7c29e30e | 34 | #include "regs.h" |
35 | #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */ | |
b9ed1410 | 36 | #include "dumpfile.h" |
3c56e0c1 | 37 | #include "calls.h" |
e011eba9 | 38 | |
f7f05a07 | 39 | |
e011eba9 | 40 | /* The set of hard registers in eliminables[i].from. */ |
41 | ||
42 | static HARD_REG_SET elim_reg_set; | |
43 | ||
e011eba9 | 44 | /* Initialize ur_in and ur_out as if all hard registers were partially |
45 | available. */ | |
46 | ||
251317e4 | 47 | class df_collection_rec |
3072d30e | 48 | { |
251317e4 | 49 | public: |
4997014d | 50 | auto_vec<df_ref, 128> def_vec; |
51 | auto_vec<df_ref, 32> use_vec; | |
52 | auto_vec<df_ref, 32> eq_use_vec; | |
04009ada | 53 | auto_vec<df_mw_hardreg *, 32> mw_vec; |
3072d30e | 54 | }; |
55 | ||
2e966e2a | 56 | static void df_ref_record (enum df_ref_class, class df_collection_rec *, |
48e1416a | 57 | rtx, rtx *, |
158b6cc9 | 58 | basic_block, struct df_insn_info *, |
c989ecc1 | 59 | enum df_ref_type, int ref_flags); |
2e966e2a | 60 | static void df_def_record_1 (class df_collection_rec *, rtx *, |
158b6cc9 | 61 | basic_block, struct df_insn_info *, |
b9c74b4d | 62 | int ref_flags); |
2e966e2a | 63 | static void df_defs_record (class df_collection_rec *, rtx, |
158b6cc9 | 64 | basic_block, struct df_insn_info *, |
b9c74b4d | 65 | int ref_flags); |
2e966e2a | 66 | static void df_uses_record (class df_collection_rec *, |
3072d30e | 67 | rtx *, enum df_ref_type, |
158b6cc9 | 68 | basic_block, struct df_insn_info *, |
c989ecc1 | 69 | int ref_flags); |
e011eba9 | 70 | |
4ffe0526 | 71 | static void df_install_ref_incremental (df_ref); |
2e966e2a | 72 | static void df_insn_refs_collect (class df_collection_rec*, |
48e1416a | 73 | basic_block, struct df_insn_info *); |
2e966e2a | 74 | static void df_canonize_collection_rec (class df_collection_rec *); |
3072d30e | 75 | |
76 | static void df_get_regular_block_artificial_uses (bitmap); | |
77 | static void df_get_eh_block_artificial_uses (bitmap); | |
78 | ||
79 | static void df_record_entry_block_defs (bitmap); | |
80 | static void df_record_exit_block_uses (bitmap); | |
81 | static void df_get_exit_block_use_set (bitmap); | |
82 | static void df_get_entry_block_def_set (bitmap); | |
e011eba9 | 83 | static void df_grow_ref_info (struct df_ref_info *, unsigned int); |
ddc2d0e3 | 84 | static void df_ref_chain_delete_du_chain (df_ref); |
85 | static void df_ref_chain_delete (df_ref); | |
e011eba9 | 86 | |
2e966e2a | 87 | static void df_refs_add_to_chains (class df_collection_rec *, |
e149ca56 | 88 | basic_block, rtx_insn *, unsigned int); |
3072d30e | 89 | |
2e966e2a | 90 | static bool df_insn_refs_verify (class df_collection_rec *, basic_block, |
e149ca56 | 91 | rtx_insn *, bool); |
2e966e2a | 92 | static void df_entry_block_defs_collect (class df_collection_rec *, bitmap); |
93 | static void df_exit_block_uses_collect (class df_collection_rec *, bitmap); | |
48e1416a | 94 | static void df_install_ref (df_ref, struct df_reg_info *, |
3072d30e | 95 | struct df_ref_info *, bool); |
96 | ||
ddc2d0e3 | 97 | static int df_ref_compare (df_ref, df_ref); |
98 | static int df_ref_ptr_compare (const void *, const void *); | |
99 | static int df_mw_compare (const df_mw_hardreg *, const df_mw_hardreg *); | |
100 | static int df_mw_ptr_compare (const void *, const void *); | |
3072d30e | 101 | |
b983ea33 | 102 | static void df_insn_info_delete (unsigned int); |
103 | ||
3072d30e | 104 | /* Indexed by hardware reg number, is true if that register is ever |
105 | used in the current function. | |
106 | ||
107 | In df-scan.c, this is set up to record the hard regs used | |
108 | explicitly. Reload adds in the hard regs used for holding pseudo | |
109 | regs. Final uses it to generate the code in the function prologue | |
110 | and epilogue to save and restore registers as needed. */ | |
111 | ||
112 | static bool regs_ever_live[FIRST_PSEUDO_REGISTER]; | |
d70aebca | 113 | |
114 | /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */ | |
115 | static const unsigned int copy_defs = 0x1; | |
116 | static const unsigned int copy_uses = 0x2; | |
117 | static const unsigned int copy_eq_uses = 0x4; | |
118 | static const unsigned int copy_mw = 0x8; | |
119 | static const unsigned int copy_all = copy_defs | copy_uses | copy_eq_uses | |
120 | | copy_mw; | |
e011eba9 | 121 | \f |
122 | /*---------------------------------------------------------------------------- | |
123 | SCANNING DATAFLOW PROBLEM | |
124 | ||
125 | There are several ways in which scanning looks just like the other | |
126 | dataflow problems. It shares the all the mechanisms for local info | |
127 | as well as basic block info. Where it differs is when and how often | |
128 | it gets run. It also has no need for the iterative solver. | |
129 | ----------------------------------------------------------------------------*/ | |
130 | ||
131 | /* Problem data for the scanning dataflow function. */ | |
132 | struct df_scan_problem_data | |
133 | { | |
e16712b1 | 134 | object_allocator<df_base_ref> *ref_base_pool; |
135 | object_allocator<df_artificial_ref> *ref_artificial_pool; | |
136 | object_allocator<df_regular_ref> *ref_regular_pool; | |
137 | object_allocator<df_insn_info> *insn_pool; | |
138 | object_allocator<df_reg_info> *reg_pool; | |
139 | object_allocator<df_mw_hardreg> *mw_reg_pool; | |
399ea05d | 140 | |
3072d30e | 141 | bitmap_obstack reg_bitmaps; |
142 | bitmap_obstack insn_bitmaps; | |
e011eba9 | 143 | }; |
144 | ||
ce299759 | 145 | /* Internal function to shut down the scanning problem. */ |
48e1416a | 146 | static void |
3072d30e | 147 | df_scan_free_internal (void) |
e011eba9 | 148 | { |
3e6933a8 | 149 | struct df_scan_problem_data *problem_data |
3072d30e | 150 | = (struct df_scan_problem_data *) df_scan->problem_data; |
e011eba9 | 151 | |
e011eba9 | 152 | free (df->def_info.refs); |
3072d30e | 153 | free (df->def_info.begin); |
154 | free (df->def_info.count); | |
e011eba9 | 155 | memset (&df->def_info, 0, (sizeof (struct df_ref_info))); |
156 | ||
e011eba9 | 157 | free (df->use_info.refs); |
3072d30e | 158 | free (df->use_info.begin); |
159 | free (df->use_info.count); | |
e011eba9 | 160 | memset (&df->use_info, 0, (sizeof (struct df_ref_info))); |
161 | ||
3072d30e | 162 | free (df->def_regs); |
163 | df->def_regs = NULL; | |
164 | free (df->use_regs); | |
165 | df->use_regs = NULL; | |
166 | free (df->eq_use_regs); | |
167 | df->eq_use_regs = NULL; | |
168 | df->regs_size = 0; | |
9af5ce0c | 169 | DF_REG_SIZE (df) = 0; |
3072d30e | 170 | |
e011eba9 | 171 | free (df->insns); |
172 | df->insns = NULL; | |
3072d30e | 173 | DF_INSN_SIZE () = 0; |
e011eba9 | 174 | |
3072d30e | 175 | free (df_scan->block_info); |
176 | df_scan->block_info = NULL; | |
177 | df_scan->block_info_size = 0; | |
e011eba9 | 178 | |
4b5a4301 | 179 | bitmap_clear (&df->hardware_regs_used); |
180 | bitmap_clear (&df->regular_block_artificial_uses); | |
181 | bitmap_clear (&df->eh_block_artificial_uses); | |
fcf2ad9f | 182 | BITMAP_FREE (df->entry_block_defs); |
e011eba9 | 183 | BITMAP_FREE (df->exit_block_uses); |
4b5a4301 | 184 | bitmap_clear (&df->insns_to_delete); |
185 | bitmap_clear (&df->insns_to_rescan); | |
186 | bitmap_clear (&df->insns_to_notes_rescan); | |
e011eba9 | 187 | |
399ea05d | 188 | delete problem_data->ref_base_pool; |
189 | delete problem_data->ref_artificial_pool; | |
190 | delete problem_data->ref_regular_pool; | |
191 | delete problem_data->insn_pool; | |
192 | delete problem_data->reg_pool; | |
193 | delete problem_data->mw_reg_pool; | |
3072d30e | 194 | bitmap_obstack_release (&problem_data->reg_bitmaps); |
195 | bitmap_obstack_release (&problem_data->insn_bitmaps); | |
196 | free (df_scan->problem_data); | |
e011eba9 | 197 | } |
198 | ||
199 | ||
e011eba9 | 200 | /* Free basic block info. */ |
201 | ||
202 | static void | |
3072d30e | 203 | df_scan_free_bb_info (basic_block bb, void *vbb_info) |
e011eba9 | 204 | { |
205 | struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info; | |
3072d30e | 206 | unsigned int bb_index = bb->index; |
7a6a083c | 207 | rtx_insn *insn; |
369ea98d | 208 | |
ddc2d0e3 | 209 | FOR_BB_INSNS (bb, insn) |
210 | if (INSN_P (insn)) | |
211 | df_insn_info_delete (INSN_UID (insn)); | |
212 | ||
213 | if (bb_index < df_scan->block_info_size) | |
214 | bb_info = df_scan_get_bb_info (bb_index); | |
215 | ||
216 | /* Get rid of any artificial uses or defs. */ | |
217 | df_ref_chain_delete_du_chain (bb_info->artificial_defs); | |
218 | df_ref_chain_delete_du_chain (bb_info->artificial_uses); | |
219 | df_ref_chain_delete (bb_info->artificial_defs); | |
220 | df_ref_chain_delete (bb_info->artificial_uses); | |
221 | bb_info->artificial_defs = NULL; | |
222 | bb_info->artificial_uses = NULL; | |
e011eba9 | 223 | } |
224 | ||
225 | ||
226 | /* Allocate the problem data for the scanning problem. This should be | |
227 | called when the problem is created or when the entire function is to | |
228 | be rescanned. */ | |
48e1416a | 229 | void |
3072d30e | 230 | df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED) |
e011eba9 | 231 | { |
e011eba9 | 232 | struct df_scan_problem_data *problem_data; |
3072d30e | 233 | basic_block bb; |
e011eba9 | 234 | |
235 | /* Given the number of pools, this is really faster than tearing | |
236 | everything apart. */ | |
3072d30e | 237 | if (df_scan->problem_data) |
238 | df_scan_free_internal (); | |
e011eba9 | 239 | |
4c36ffe6 | 240 | problem_data = XNEW (struct df_scan_problem_data); |
3072d30e | 241 | df_scan->problem_data = problem_data; |
242 | df_scan->computed = true; | |
e011eba9 | 243 | |
e16712b1 | 244 | problem_data->ref_base_pool = new object_allocator<df_base_ref> |
1dc6c44d | 245 | ("df_scan ref base"); |
e16712b1 | 246 | problem_data->ref_artificial_pool = new object_allocator<df_artificial_ref> |
1dc6c44d | 247 | ("df_scan ref artificial"); |
e16712b1 | 248 | problem_data->ref_regular_pool = new object_allocator<df_regular_ref> |
1dc6c44d | 249 | ("df_scan ref regular"); |
e16712b1 | 250 | problem_data->insn_pool = new object_allocator<df_insn_info> |
1dc6c44d | 251 | ("df_scan insn"); |
e16712b1 | 252 | problem_data->reg_pool = new object_allocator<df_reg_info> |
1dc6c44d | 253 | ("df_scan reg"); |
e16712b1 | 254 | problem_data->mw_reg_pool = new object_allocator<df_mw_hardreg> |
1dc6c44d | 255 | ("df_scan mw_reg"); |
e011eba9 | 256 | |
3072d30e | 257 | bitmap_obstack_initialize (&problem_data->reg_bitmaps); |
258 | bitmap_obstack_initialize (&problem_data->insn_bitmaps); | |
e011eba9 | 259 | |
3072d30e | 260 | df_grow_reg_info (); |
e011eba9 | 261 | |
3072d30e | 262 | df_grow_insn_info (); |
263 | df_grow_bb_info (df_scan); | |
e011eba9 | 264 | |
ed7d889a | 265 | FOR_ALL_BB_FN (bb, cfun) |
e011eba9 | 266 | { |
3072d30e | 267 | unsigned int bb_index = bb->index; |
268 | struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index); | |
e011eba9 | 269 | bb_info->artificial_defs = NULL; |
270 | bb_info->artificial_uses = NULL; | |
271 | } | |
272 | ||
4b5a4301 | 273 | bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps); |
274 | bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps); | |
275 | bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps); | |
3072d30e | 276 | df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps); |
277 | df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps); | |
4b5a4301 | 278 | bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps); |
279 | bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps); | |
280 | bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps); | |
deb2741b | 281 | df_scan->optional_p = false; |
e011eba9 | 282 | } |
283 | ||
284 | ||
285 | /* Free all of the data associated with the scan problem. */ | |
286 | ||
48e1416a | 287 | static void |
3072d30e | 288 | df_scan_free (void) |
e011eba9 | 289 | { |
3072d30e | 290 | if (df_scan->problem_data) |
291 | df_scan_free_internal (); | |
d0802b39 | 292 | |
e011eba9 | 293 | if (df->blocks_to_analyze) |
3072d30e | 294 | { |
295 | BITMAP_FREE (df->blocks_to_analyze); | |
296 | df->blocks_to_analyze = NULL; | |
297 | } | |
e011eba9 | 298 | |
3072d30e | 299 | free (df_scan); |
e011eba9 | 300 | } |
301 | ||
3072d30e | 302 | /* Dump the preamble for DF_SCAN dump. */ |
48e1416a | 303 | static void |
3072d30e | 304 | df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED) |
e011eba9 | 305 | { |
e011eba9 | 306 | int i; |
ed6e85ae | 307 | int dcount = 0; |
308 | int ucount = 0; | |
309 | int ecount = 0; | |
310 | int icount = 0; | |
311 | int ccount = 0; | |
312 | basic_block bb; | |
7a6a083c | 313 | rtx_insn *insn; |
e011eba9 | 314 | |
3072d30e | 315 | fprintf (file, ";; invalidated by call \t"); |
b888113c | 316 | df_print_regset (file, regs_invalidated_by_call_regset); |
3072d30e | 317 | fprintf (file, ";; hardware regs used \t"); |
4b5a4301 | 318 | df_print_regset (file, &df->hardware_regs_used); |
3072d30e | 319 | fprintf (file, ";; regular block artificial uses \t"); |
4b5a4301 | 320 | df_print_regset (file, &df->regular_block_artificial_uses); |
3072d30e | 321 | fprintf (file, ";; eh block artificial uses \t"); |
4b5a4301 | 322 | df_print_regset (file, &df->eh_block_artificial_uses); |
3072d30e | 323 | fprintf (file, ";; entry block defs \t"); |
324 | df_print_regset (file, df->entry_block_defs); | |
325 | fprintf (file, ";; exit block uses \t"); | |
326 | df_print_regset (file, df->exit_block_uses); | |
327 | fprintf (file, ";; regs ever live \t"); | |
e011eba9 | 328 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
3072d30e | 329 | if (df_regs_ever_live_p (i)) |
bff0a500 | 330 | fprintf (file, " %d [%s]", i, reg_names[i]); |
ed6e85ae | 331 | fprintf (file, "\n;; ref usage \t"); |
48e1416a | 332 | |
ed6e85ae | 333 | for (i = 0; i < (int)df->regs_inited; i++) |
334 | if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i)) | |
335 | { | |
336 | const char * sep = ""; | |
337 | ||
338 | fprintf (file, "r%d={", i); | |
339 | if (DF_REG_DEF_COUNT (i)) | |
340 | { | |
341 | fprintf (file, "%dd", DF_REG_DEF_COUNT (i)); | |
342 | sep = ","; | |
343 | dcount += DF_REG_DEF_COUNT (i); | |
344 | } | |
345 | if (DF_REG_USE_COUNT (i)) | |
346 | { | |
347 | fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i)); | |
348 | sep = ","; | |
349 | ucount += DF_REG_USE_COUNT (i); | |
350 | } | |
351 | if (DF_REG_EQ_USE_COUNT (i)) | |
352 | { | |
09669349 | 353 | fprintf (file, "%s%de", sep, DF_REG_EQ_USE_COUNT (i)); |
ed6e85ae | 354 | ecount += DF_REG_EQ_USE_COUNT (i); |
355 | } | |
356 | fprintf (file, "} "); | |
357 | } | |
3072d30e | 358 | |
fc00614f | 359 | FOR_EACH_BB_FN (bb, cfun) |
ed6e85ae | 360 | FOR_BB_INSNS (bb, insn) |
361 | if (INSN_P (insn)) | |
362 | { | |
363 | if (CALL_P (insn)) | |
364 | ccount++; | |
365 | else | |
366 | icount++; | |
367 | } | |
368 | ||
09669349 | 369 | fprintf (file, "\n;; total ref usage %d{%dd,%du,%de}" |
370 | " in %d{%d regular + %d call} insns.\n", | |
371 | dcount + ucount + ecount, dcount, ucount, ecount, | |
372 | icount + ccount, icount, ccount); | |
e011eba9 | 373 | } |
374 | ||
3072d30e | 375 | /* Dump the bb_info for a given basic block. */ |
48e1416a | 376 | static void |
3072d30e | 377 | df_scan_start_block (basic_block bb, FILE *file) |
378 | { | |
379 | struct df_scan_bb_info *bb_info | |
380 | = df_scan_get_bb_info (bb->index); | |
381 | ||
382 | if (bb_info) | |
383 | { | |
384 | fprintf (file, ";; bb %d artificial_defs: ", bb->index); | |
385 | df_refs_chain_dump (bb_info->artificial_defs, true, file); | |
386 | fprintf (file, "\n;; bb %d artificial_uses: ", bb->index); | |
387 | df_refs_chain_dump (bb_info->artificial_uses, true, file); | |
388 | fprintf (file, "\n"); | |
389 | } | |
390 | #if 0 | |
391 | { | |
7a6a083c | 392 | rtx_insn *insn; |
3072d30e | 393 | FOR_BB_INSNS (bb, insn) |
394 | if (INSN_P (insn)) | |
395 | df_insn_debug (insn, false, file); | |
396 | } | |
397 | #endif | |
398 | } | |
399 | ||
d8000c94 | 400 | static const struct df_problem problem_SCAN = |
e011eba9 | 401 | { |
402 | DF_SCAN, /* Problem id. */ | |
403 | DF_NONE, /* Direction. */ | |
404 | df_scan_alloc, /* Allocate the problem specific data. */ | |
f64e6a69 | 405 | NULL, /* Reset global information. */ |
e011eba9 | 406 | df_scan_free_bb_info, /* Free basic block info. */ |
407 | NULL, /* Local compute function. */ | |
408 | NULL, /* Init the solution specific data. */ | |
409 | NULL, /* Iterative solver. */ | |
48e1416a | 410 | NULL, /* Confluence operator 0. */ |
411 | NULL, /* Confluence operator n. */ | |
e011eba9 | 412 | NULL, /* Transfer function. */ |
413 | NULL, /* Finalize function. */ | |
414 | df_scan_free, /* Free all of the problem information. */ | |
3072d30e | 415 | NULL, /* Remove this problem from the stack of dataflow problems. */ |
416 | df_scan_start_dump, /* Debugging. */ | |
417 | df_scan_start_block, /* Debugging start block. */ | |
418 | NULL, /* Debugging end block. */ | |
ea9538fb | 419 | NULL, /* Debugging start insn. */ |
420 | NULL, /* Debugging end insn. */ | |
3072d30e | 421 | NULL, /* Incremental solution verify start. */ |
6dfdc153 | 422 | NULL, /* Incremental solution verify end. */ |
3e6933a8 | 423 | NULL, /* Dependent problem. */ |
369ea98d | 424 | sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */ |
deb2741b | 425 | TV_DF_SCAN, /* Timing variable. */ |
426 | false /* Reset blocks on dropping out of blocks_to_analyze. */ | |
e011eba9 | 427 | }; |
428 | ||
429 | ||
430 | /* Create a new DATAFLOW instance and add it to an existing instance | |
431 | of DF. The returned structure is what is used to get at the | |
432 | solution. */ | |
433 | ||
3072d30e | 434 | void |
435 | df_scan_add_problem (void) | |
e011eba9 | 436 | { |
3072d30e | 437 | df_add_problem (&problem_SCAN); |
e011eba9 | 438 | } |
439 | ||
3072d30e | 440 | \f |
e011eba9 | 441 | /*---------------------------------------------------------------------------- |
442 | Storage Allocation Utilities | |
443 | ----------------------------------------------------------------------------*/ | |
444 | ||
445 | ||
446 | /* First, grow the reg_info information. If the current size is less than | |
f0b5f617 | 447 | the number of pseudos, grow to 25% more than the number of |
48e1416a | 448 | pseudos. |
e011eba9 | 449 | |
450 | Second, assure that all of the slots up to max_reg_num have been | |
451 | filled with reg_info structures. */ | |
452 | ||
48e1416a | 453 | void |
3072d30e | 454 | df_grow_reg_info (void) |
e011eba9 | 455 | { |
456 | unsigned int max_reg = max_reg_num (); | |
457 | unsigned int new_size = max_reg; | |
3e6933a8 | 458 | struct df_scan_problem_data *problem_data |
3072d30e | 459 | = (struct df_scan_problem_data *) df_scan->problem_data; |
e011eba9 | 460 | unsigned int i; |
461 | ||
3072d30e | 462 | if (df->regs_size < new_size) |
e011eba9 | 463 | { |
464 | new_size += new_size / 4; | |
364c0c59 | 465 | df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size); |
466 | df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size); | |
467 | df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs, | |
468 | new_size); | |
469 | df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size); | |
470 | df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size); | |
471 | df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size); | |
472 | df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size); | |
3072d30e | 473 | df->regs_size = new_size; |
e011eba9 | 474 | } |
475 | ||
3072d30e | 476 | for (i = df->regs_inited; i < max_reg; i++) |
e011eba9 | 477 | { |
3072d30e | 478 | struct df_reg_info *reg_info; |
479 | ||
399ea05d | 480 | // TODO |
481 | reg_info = problem_data->reg_pool->allocate (); | |
3072d30e | 482 | memset (reg_info, 0, sizeof (struct df_reg_info)); |
483 | df->def_regs[i] = reg_info; | |
399ea05d | 484 | reg_info = problem_data->reg_pool->allocate (); |
3072d30e | 485 | memset (reg_info, 0, sizeof (struct df_reg_info)); |
486 | df->use_regs[i] = reg_info; | |
399ea05d | 487 | reg_info = problem_data->reg_pool->allocate (); |
e011eba9 | 488 | memset (reg_info, 0, sizeof (struct df_reg_info)); |
3072d30e | 489 | df->eq_use_regs[i] = reg_info; |
490 | df->def_info.begin[i] = 0; | |
491 | df->def_info.count[i] = 0; | |
492 | df->use_info.begin[i] = 0; | |
493 | df->use_info.count[i] = 0; | |
e011eba9 | 494 | } |
48e1416a | 495 | |
3072d30e | 496 | df->regs_inited = max_reg; |
e011eba9 | 497 | } |
498 | ||
499 | ||
500 | /* Grow the ref information. */ | |
501 | ||
48e1416a | 502 | static void |
e011eba9 | 503 | df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size) |
504 | { | |
505 | if (ref_info->refs_size < new_size) | |
506 | { | |
ed6e85ae | 507 | ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size); |
e011eba9 | 508 | memset (ref_info->refs + ref_info->refs_size, 0, |
ed6e85ae | 509 | (new_size - ref_info->refs_size) *sizeof (df_ref)); |
e011eba9 | 510 | ref_info->refs_size = new_size; |
511 | } | |
512 | } | |
513 | ||
514 | ||
3072d30e | 515 | /* Check and grow the ref information if necessary. This routine |
516 | guarantees total_size + BITMAP_ADDEND amount of entries in refs | |
517 | array. It updates ref_info->refs_size only and does not change | |
518 | ref_info->total_size. */ | |
519 | ||
520 | static void | |
48e1416a | 521 | df_check_and_grow_ref_info (struct df_ref_info *ref_info, |
3072d30e | 522 | unsigned bitmap_addend) |
523 | { | |
524 | if (ref_info->refs_size < ref_info->total_size + bitmap_addend) | |
525 | { | |
526 | int new_size = ref_info->total_size + bitmap_addend; | |
527 | new_size += ref_info->total_size / 4; | |
528 | df_grow_ref_info (ref_info, new_size); | |
529 | } | |
530 | } | |
531 | ||
532 | ||
e011eba9 | 533 | /* Grow the ref information. If the current size is less than the |
534 | number of instructions, grow to 25% more than the number of | |
535 | instructions. */ | |
536 | ||
48e1416a | 537 | void |
3072d30e | 538 | df_grow_insn_info (void) |
e011eba9 | 539 | { |
540 | unsigned int new_size = get_max_uid () + 1; | |
3072d30e | 541 | if (DF_INSN_SIZE () < new_size) |
e011eba9 | 542 | { |
543 | new_size += new_size / 4; | |
364c0c59 | 544 | df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size); |
e011eba9 | 545 | memset (df->insns + df->insns_size, 0, |
3072d30e | 546 | (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *)); |
547 | DF_INSN_SIZE () = new_size; | |
e011eba9 | 548 | } |
549 | } | |
550 | ||
551 | ||
552 | ||
553 | \f | |
554 | /*---------------------------------------------------------------------------- | |
555 | PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING. | |
556 | ----------------------------------------------------------------------------*/ | |
557 | ||
3072d30e | 558 | /* Rescan all of the block_to_analyze or all of the blocks in the |
559 | function if df_set_blocks if blocks_to_analyze is NULL; */ | |
e011eba9 | 560 | |
561 | void | |
3072d30e | 562 | df_scan_blocks (void) |
e011eba9 | 563 | { |
e011eba9 | 564 | basic_block bb; |
565 | ||
3072d30e | 566 | df->def_info.ref_order = DF_REF_ORDER_NO_TABLE; |
567 | df->use_info.ref_order = DF_REF_ORDER_NO_TABLE; | |
3e6933a8 | 568 | |
4b5a4301 | 569 | df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses); |
570 | df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses); | |
e011eba9 | 571 | |
4b5a4301 | 572 | bitmap_ior_into (&df->eh_block_artificial_uses, |
573 | &df->regular_block_artificial_uses); | |
f64e6a69 | 574 | |
3072d30e | 575 | /* ENTRY and EXIT blocks have special defs/uses. */ |
576 | df_get_entry_block_def_set (df->entry_block_defs); | |
577 | df_record_entry_block_defs (df->entry_block_defs); | |
578 | df_get_exit_block_use_set (df->exit_block_uses); | |
579 | df_record_exit_block_uses (df->exit_block_uses); | |
f5a6b05f | 580 | df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK)); |
581 | df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK)); | |
e011eba9 | 582 | |
3072d30e | 583 | /* Regular blocks */ |
fc00614f | 584 | FOR_EACH_BB_FN (bb, cfun) |
e011eba9 | 585 | { |
3072d30e | 586 | unsigned int bb_index = bb->index; |
587 | df_bb_refs_record (bb_index, true); | |
e011eba9 | 588 | } |
e011eba9 | 589 | } |
590 | ||
4ffe0526 | 591 | /* Create new refs under address LOC within INSN. This function is |
592 | only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE, | |
593 | depending on whether LOC is inside PATTERN (INSN) or a note. */ | |
594 | ||
595 | void | |
e149ca56 | 596 | df_uses_create (rtx *loc, rtx_insn *insn, int ref_flags) |
4ffe0526 | 597 | { |
598 | gcc_assert (!(ref_flags & ~DF_REF_IN_NOTE)); | |
599 | df_uses_record (NULL, loc, DF_REF_REG_USE, | |
600 | BLOCK_FOR_INSN (insn), | |
601 | DF_INSN_INFO_GET (insn), | |
602 | ref_flags); | |
603 | } | |
3e6933a8 | 604 | |
4ffe0526 | 605 | static void |
606 | df_install_ref_incremental (df_ref ref) | |
607 | { | |
608 | struct df_reg_info **reg_info; | |
609 | struct df_ref_info *ref_info; | |
ddc2d0e3 | 610 | df_ref *ref_ptr; |
4ffe0526 | 611 | bool add_to_table; |
612 | ||
7a6a083c | 613 | rtx_insn *insn = DF_REF_INSN (ref); |
4ffe0526 | 614 | basic_block bb = BLOCK_FOR_INSN (insn); |
e011eba9 | 615 | |
ed6e85ae | 616 | if (DF_REF_REG_DEF_P (ref)) |
3072d30e | 617 | { |
618 | reg_info = df->def_regs; | |
619 | ref_info = &df->def_info; | |
ddc2d0e3 | 620 | ref_ptr = &DF_INSN_DEFS (insn); |
3072d30e | 621 | add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE; |
622 | } | |
623 | else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) | |
624 | { | |
625 | reg_info = df->eq_use_regs; | |
626 | ref_info = &df->use_info; | |
ddc2d0e3 | 627 | ref_ptr = &DF_INSN_EQ_USES (insn); |
3072d30e | 628 | switch (ref_info->ref_order) |
629 | { | |
630 | case DF_REF_ORDER_UNORDERED_WITH_NOTES: | |
631 | case DF_REF_ORDER_BY_REG_WITH_NOTES: | |
632 | case DF_REF_ORDER_BY_INSN_WITH_NOTES: | |
633 | add_to_table = true; | |
634 | break; | |
635 | default: | |
636 | add_to_table = false; | |
637 | break; | |
638 | } | |
639 | } | |
640 | else | |
641 | { | |
642 | reg_info = df->use_regs; | |
643 | ref_info = &df->use_info; | |
ddc2d0e3 | 644 | ref_ptr = &DF_INSN_USES (insn); |
3072d30e | 645 | add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE; |
646 | } | |
e011eba9 | 647 | |
3072d30e | 648 | /* Do not add if ref is not in the right blocks. */ |
649 | if (add_to_table && df->analyze_subset) | |
650 | add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index); | |
e011eba9 | 651 | |
3072d30e | 652 | df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table); |
48e1416a | 653 | |
3072d30e | 654 | if (add_to_table) |
655 | switch (ref_info->ref_order) | |
656 | { | |
657 | case DF_REF_ORDER_UNORDERED_WITH_NOTES: | |
658 | case DF_REF_ORDER_BY_REG_WITH_NOTES: | |
659 | case DF_REF_ORDER_BY_INSN_WITH_NOTES: | |
660 | ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES; | |
661 | break; | |
662 | default: | |
663 | ref_info->ref_order = DF_REF_ORDER_UNORDERED; | |
664 | break; | |
665 | } | |
e011eba9 | 666 | |
ddc2d0e3 | 667 | while (*ref_ptr && df_ref_compare (*ref_ptr, ref) < 0) |
668 | ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr); | |
e011eba9 | 669 | |
ddc2d0e3 | 670 | DF_REF_NEXT_LOC (ref) = *ref_ptr; |
671 | *ref_ptr = ref; | |
e011eba9 | 672 | |
3072d30e | 673 | #if 0 |
674 | if (dump_file) | |
675 | { | |
676 | fprintf (dump_file, "adding ref "); | |
677 | df_ref_debug (ref, dump_file); | |
e011eba9 | 678 | } |
3072d30e | 679 | #endif |
680 | /* By adding the ref directly, df_insn_rescan my not find any | |
681 | differences even though the block will have changed. So we need | |
48e1416a | 682 | to mark the block dirty ourselves. */ |
890dcf62 | 683 | if (!DEBUG_INSN_P (DF_REF_INSN (ref))) |
684 | df_set_bb_dirty (bb); | |
e011eba9 | 685 | } |
686 | ||
687 | ||
3072d30e | 688 | \f |
689 | /*---------------------------------------------------------------------------- | |
690 | UTILITIES TO CREATE AND DESTROY REFS AND CHAINS. | |
691 | ----------------------------------------------------------------------------*/ | |
692 | ||
30de5b55 | 693 | static void |
ed6e85ae | 694 | df_free_ref (df_ref ref) |
30de5b55 | 695 | { |
696 | struct df_scan_problem_data *problem_data | |
697 | = (struct df_scan_problem_data *) df_scan->problem_data; | |
698 | ||
ed6e85ae | 699 | switch (DF_REF_CLASS (ref)) |
700 | { | |
701 | case DF_REF_BASE: | |
399ea05d | 702 | problem_data->ref_base_pool->remove ((df_base_ref *) (ref)); |
ed6e85ae | 703 | break; |
704 | ||
705 | case DF_REF_ARTIFICIAL: | |
399ea05d | 706 | problem_data->ref_artificial_pool->remove |
707 | ((df_artificial_ref *) (ref)); | |
ed6e85ae | 708 | break; |
709 | ||
710 | case DF_REF_REGULAR: | |
399ea05d | 711 | problem_data->ref_regular_pool->remove |
712 | ((df_regular_ref *) (ref)); | |
ed6e85ae | 713 | break; |
ed6e85ae | 714 | } |
30de5b55 | 715 | } |
716 | ||
e011eba9 | 717 | |
3072d30e | 718 | /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain. |
719 | Also delete the def-use or use-def chain if it exists. */ | |
720 | ||
721 | static void | |
48e1416a | 722 | df_reg_chain_unlink (df_ref ref) |
e011eba9 | 723 | { |
48e1416a | 724 | df_ref next = DF_REF_NEXT_REG (ref); |
ed6e85ae | 725 | df_ref prev = DF_REF_PREV_REG (ref); |
3072d30e | 726 | int id = DF_REF_ID (ref); |
e011eba9 | 727 | struct df_reg_info *reg_info; |
ed6e85ae | 728 | df_ref *refs = NULL; |
e011eba9 | 729 | |
ed6e85ae | 730 | if (DF_REF_REG_DEF_P (ref)) |
e011eba9 | 731 | { |
ed6e85ae | 732 | int regno = DF_REF_REGNO (ref); |
733 | reg_info = DF_REG_DEF_GET (regno); | |
3072d30e | 734 | refs = df->def_info.refs; |
e011eba9 | 735 | } |
48e1416a | 736 | else |
e011eba9 | 737 | { |
3072d30e | 738 | if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) |
739 | { | |
740 | reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref)); | |
741 | switch (df->use_info.ref_order) | |
742 | { | |
743 | case DF_REF_ORDER_UNORDERED_WITH_NOTES: | |
744 | case DF_REF_ORDER_BY_REG_WITH_NOTES: | |
745 | case DF_REF_ORDER_BY_INSN_WITH_NOTES: | |
746 | refs = df->use_info.refs; | |
747 | break; | |
748 | default: | |
749 | break; | |
750 | } | |
751 | } | |
752 | else | |
753 | { | |
754 | reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref)); | |
755 | refs = df->use_info.refs; | |
756 | } | |
757 | } | |
758 | ||
759 | if (refs) | |
760 | { | |
761 | if (df->analyze_subset) | |
762 | { | |
ed6e85ae | 763 | if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref))) |
3072d30e | 764 | refs[id] = NULL; |
765 | } | |
766 | else | |
767 | refs[id] = NULL; | |
e011eba9 | 768 | } |
48e1416a | 769 | |
3072d30e | 770 | /* Delete any def-use or use-def chains that start here. It is |
771 | possible that there is trash in this field. This happens for | |
772 | insns that have been deleted when rescanning has been deferred | |
773 | and the chain problem has also been deleted. The chain tear down | |
774 | code skips deleted insns. */ | |
775 | if (df_chain && DF_REF_CHAIN (ref)) | |
776 | df_chain_unlink (ref); | |
48e1416a | 777 | |
e011eba9 | 778 | reg_info->n_refs--; |
3072d30e | 779 | if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE)) |
780 | { | |
781 | gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER); | |
782 | df->hard_regs_live_count[DF_REF_REGNO (ref)]--; | |
783 | } | |
e011eba9 | 784 | |
785 | /* Unlink from the reg chain. If there is no prev, this is the | |
786 | first of the list. If not, just join the next and prev. */ | |
787 | if (prev) | |
3072d30e | 788 | DF_REF_NEXT_REG (prev) = next; |
e011eba9 | 789 | else |
790 | { | |
3072d30e | 791 | gcc_assert (reg_info->reg_chain == ref); |
e011eba9 | 792 | reg_info->reg_chain = next; |
e011eba9 | 793 | } |
3072d30e | 794 | if (next) |
795 | DF_REF_PREV_REG (next) = prev; | |
e011eba9 | 796 | |
30de5b55 | 797 | df_free_ref (ref); |
3072d30e | 798 | } |
799 | ||
7d95e007 | 800 | /* Initialize INSN_INFO to describe INSN. */ |
801 | ||
802 | static void | |
803 | df_insn_info_init_fields (df_insn_info *insn_info, rtx_insn *insn) | |
804 | { | |
805 | memset (insn_info, 0, sizeof (struct df_insn_info)); | |
806 | insn_info->insn = insn; | |
807 | } | |
3072d30e | 808 | |
3072d30e | 809 | /* Create the insn record for INSN. If there was one there, zero it |
810 | out. */ | |
e011eba9 | 811 | |
3072d30e | 812 | struct df_insn_info * |
e149ca56 | 813 | df_insn_create_insn_record (rtx_insn *insn) |
e011eba9 | 814 | { |
3e6933a8 | 815 | struct df_scan_problem_data *problem_data |
3072d30e | 816 | = (struct df_scan_problem_data *) df_scan->problem_data; |
817 | struct df_insn_info *insn_rec; | |
e011eba9 | 818 | |
3072d30e | 819 | df_grow_insn_info (); |
158b6cc9 | 820 | insn_rec = DF_INSN_INFO_GET (insn); |
e011eba9 | 821 | if (!insn_rec) |
822 | { | |
399ea05d | 823 | insn_rec = problem_data->insn_pool->allocate (); |
158b6cc9 | 824 | DF_INSN_INFO_SET (insn, insn_rec); |
e011eba9 | 825 | } |
7d95e007 | 826 | df_insn_info_init_fields (insn_rec, insn); |
e011eba9 | 827 | return insn_rec; |
828 | } | |
829 | ||
d0802b39 | 830 | |
3072d30e | 831 | /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */ |
e011eba9 | 832 | |
3072d30e | 833 | static void |
ddc2d0e3 | 834 | df_ref_chain_delete_du_chain (df_ref ref) |
e011eba9 | 835 | { |
ddc2d0e3 | 836 | for (; ref; ref = DF_REF_NEXT_LOC (ref)) |
837 | /* CHAIN is allocated by DF_CHAIN. So make sure to | |
838 | pass df_scan instance for the problem. */ | |
839 | if (DF_REF_CHAIN (ref)) | |
840 | df_chain_unlink (ref); | |
3072d30e | 841 | } |
3e6933a8 | 842 | |
e011eba9 | 843 | |
3072d30e | 844 | /* Delete all refs in the ref chain. */ |
845 | ||
846 | static void | |
ddc2d0e3 | 847 | df_ref_chain_delete (df_ref ref) |
3072d30e | 848 | { |
ddc2d0e3 | 849 | df_ref next; |
850 | for (; ref; ref = next) | |
3072d30e | 851 | { |
ddc2d0e3 | 852 | next = DF_REF_NEXT_LOC (ref); |
853 | df_reg_chain_unlink (ref); | |
3072d30e | 854 | } |
3072d30e | 855 | } |
856 | ||
857 | ||
858 | /* Delete the hardreg chain. */ | |
859 | ||
860 | static void | |
ddc2d0e3 | 861 | df_mw_hardreg_chain_delete (struct df_mw_hardreg *hardregs) |
3072d30e | 862 | { |
ddc2d0e3 | 863 | struct df_scan_problem_data *problem_data |
864 | = (struct df_scan_problem_data *) df_scan->problem_data; | |
865 | df_mw_hardreg *next; | |
3072d30e | 866 | |
ddc2d0e3 | 867 | for (; hardregs; hardregs = next) |
3072d30e | 868 | { |
ddc2d0e3 | 869 | next = DF_MWS_NEXT (hardregs); |
399ea05d | 870 | problem_data->mw_reg_pool->remove (hardregs); |
3072d30e | 871 | } |
872 | } | |
873 | ||
7d95e007 | 874 | /* Remove the contents of INSN_INFO (but don't free INSN_INFO itself). */ |
875 | ||
876 | static void | |
877 | df_insn_info_free_fields (df_insn_info *insn_info) | |
878 | { | |
879 | /* In general, notes do not have the insn_info fields | |
880 | initialized. However, combine deletes insns by changing them | |
881 | to notes. How clever. So we cannot just check if it is a | |
882 | valid insn before short circuiting this code, we need to see | |
883 | if we actually initialized it. */ | |
884 | df_mw_hardreg_chain_delete (insn_info->mw_hardregs); | |
885 | ||
886 | if (df_chain) | |
887 | { | |
888 | df_ref_chain_delete_du_chain (insn_info->defs); | |
889 | df_ref_chain_delete_du_chain (insn_info->uses); | |
890 | df_ref_chain_delete_du_chain (insn_info->eq_uses); | |
891 | } | |
892 | ||
893 | df_ref_chain_delete (insn_info->defs); | |
894 | df_ref_chain_delete (insn_info->uses); | |
895 | df_ref_chain_delete (insn_info->eq_uses); | |
896 | } | |
3072d30e | 897 | |
b983ea33 | 898 | /* Delete all of the refs information from the insn with UID. |
899 | Internal helper for df_insn_delete, df_insn_rescan, and other | |
900 | df-scan routines that don't have to work in deferred mode | |
901 | and do not have to mark basic blocks for re-processing. */ | |
3072d30e | 902 | |
b983ea33 | 903 | static void |
904 | df_insn_info_delete (unsigned int uid) | |
3072d30e | 905 | { |
b983ea33 | 906 | struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid); |
3072d30e | 907 | |
4b5a4301 | 908 | bitmap_clear_bit (&df->insns_to_delete, uid); |
909 | bitmap_clear_bit (&df->insns_to_rescan, uid); | |
910 | bitmap_clear_bit (&df->insns_to_notes_rescan, uid); | |
3072d30e | 911 | if (insn_info) |
912 | { | |
48e1416a | 913 | struct df_scan_problem_data *problem_data |
3072d30e | 914 | = (struct df_scan_problem_data *) df_scan->problem_data; |
915 | ||
7d95e007 | 916 | df_insn_info_free_fields (insn_info); |
399ea05d | 917 | problem_data->insn_pool->remove (insn_info); |
3072d30e | 918 | DF_INSN_UID_SET (uid, NULL); |
e011eba9 | 919 | } |
920 | } | |
921 | ||
b983ea33 | 922 | /* Delete all of the refs information from INSN, either right now |
923 | or marked for later in deferred mode. */ | |
924 | ||
925 | void | |
e149ca56 | 926 | df_insn_delete (rtx_insn *insn) |
b983ea33 | 927 | { |
928 | unsigned int uid; | |
929 | basic_block bb; | |
930 | ||
931 | gcc_checking_assert (INSN_P (insn)); | |
932 | ||
933 | if (!df) | |
934 | return; | |
935 | ||
936 | uid = INSN_UID (insn); | |
937 | bb = BLOCK_FOR_INSN (insn); | |
938 | ||
939 | /* ??? bb can be NULL after pass_free_cfg. At that point, DF should | |
940 | not exist anymore (as mentioned in df-core.c: "The only requirement | |
941 | [for DF] is that there be a correct control flow graph." Clearly | |
942 | that isn't the case after pass_free_cfg. But DF is freed much later | |
943 | because some back-ends want to use DF info even though the CFG is | |
944 | already gone. It's not clear to me whether that is safe, actually. | |
945 | In any case, we expect BB to be non-NULL at least up to register | |
946 | allocation, so disallow a non-NULL BB up to there. Not perfect | |
947 | but better than nothing... */ | |
d71c7316 | 948 | gcc_checking_assert (bb != NULL || reload_completed); |
b983ea33 | 949 | |
950 | df_grow_bb_info (df_scan); | |
951 | df_grow_reg_info (); | |
952 | ||
953 | /* The block must be marked as dirty now, rather than later as in | |
954 | df_insn_rescan and df_notes_rescan because it may not be there at | |
955 | rescanning time and the mark would blow up. | |
956 | DEBUG_INSNs do not make a block's data flow solution dirty (at | |
957 | worst the LUIDs are no longer contiguous). */ | |
958 | if (bb != NULL && NONDEBUG_INSN_P (insn)) | |
959 | df_set_bb_dirty (bb); | |
960 | ||
961 | /* The client has deferred rescanning. */ | |
962 | if (df->changeable_flags & DF_DEFER_INSN_RESCAN) | |
963 | { | |
964 | struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid); | |
965 | if (insn_info) | |
966 | { | |
967 | bitmap_clear_bit (&df->insns_to_rescan, uid); | |
968 | bitmap_clear_bit (&df->insns_to_notes_rescan, uid); | |
969 | bitmap_set_bit (&df->insns_to_delete, uid); | |
970 | } | |
971 | if (dump_file) | |
972 | fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid); | |
973 | return; | |
974 | } | |
975 | ||
976 | if (dump_file) | |
977 | fprintf (dump_file, "deleting insn with uid = %d.\n", uid); | |
978 | ||
979 | df_insn_info_delete (uid); | |
980 | } | |
981 | ||
e011eba9 | 982 | |
3072d30e | 983 | /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */ |
d0802b39 | 984 | |
3072d30e | 985 | static void |
2e966e2a | 986 | df_free_collection_rec (class df_collection_rec *collection_rec) |
d0802b39 | 987 | { |
f7f05a07 | 988 | unsigned int ix; |
48e1416a | 989 | struct df_scan_problem_data *problem_data |
3072d30e | 990 | = (struct df_scan_problem_data *) df_scan->problem_data; |
f7f05a07 | 991 | df_ref ref; |
992 | struct df_mw_hardreg *mw; | |
993 | ||
f1f41a6c | 994 | FOR_EACH_VEC_ELT (collection_rec->def_vec, ix, ref) |
f7f05a07 | 995 | df_free_ref (ref); |
f1f41a6c | 996 | FOR_EACH_VEC_ELT (collection_rec->use_vec, ix, ref) |
f7f05a07 | 997 | df_free_ref (ref); |
f1f41a6c | 998 | FOR_EACH_VEC_ELT (collection_rec->eq_use_vec, ix, ref) |
f7f05a07 | 999 | df_free_ref (ref); |
f1f41a6c | 1000 | FOR_EACH_VEC_ELT (collection_rec->mw_vec, ix, mw) |
399ea05d | 1001 | problem_data->mw_reg_pool->remove (mw); |
f7f05a07 | 1002 | |
f1f41a6c | 1003 | collection_rec->def_vec.release (); |
1004 | collection_rec->use_vec.release (); | |
1005 | collection_rec->eq_use_vec.release (); | |
1006 | collection_rec->mw_vec.release (); | |
3072d30e | 1007 | } |
d0802b39 | 1008 | |
3072d30e | 1009 | /* Rescan INSN. Return TRUE if the rescanning produced any changes. */ |
1010 | ||
48e1416a | 1011 | bool |
e149ca56 | 1012 | df_insn_rescan (rtx_insn *insn) |
3072d30e | 1013 | { |
1014 | unsigned int uid = INSN_UID (insn); | |
1015 | struct df_insn_info *insn_info = NULL; | |
1016 | basic_block bb = BLOCK_FOR_INSN (insn); | |
2e966e2a | 1017 | class df_collection_rec collection_rec; |
3072d30e | 1018 | |
1019 | if ((!df) || (!INSN_P (insn))) | |
1020 | return false; | |
1021 | ||
1022 | if (!bb) | |
d0802b39 | 1023 | { |
3072d30e | 1024 | if (dump_file) |
1025 | fprintf (dump_file, "no bb for insn with uid = %d.\n", uid); | |
1026 | return false; | |
1027 | } | |
1028 | ||
1029 | /* The client has disabled rescanning and plans to do it itself. */ | |
1030 | if (df->changeable_flags & DF_NO_INSN_RESCAN) | |
1031 | return false; | |
1032 | ||
1033 | df_grow_bb_info (df_scan); | |
1034 | df_grow_reg_info (); | |
1035 | ||
1036 | insn_info = DF_INSN_UID_SAFE_GET (uid); | |
1037 | ||
a3de79f9 | 1038 | /* The client has deferred rescanning. */ |
3072d30e | 1039 | if (df->changeable_flags & DF_DEFER_INSN_RESCAN) |
1040 | { | |
1041 | if (!insn_info) | |
1042 | { | |
1043 | insn_info = df_insn_create_insn_record (insn); | |
ddc2d0e3 | 1044 | insn_info->defs = 0; |
1045 | insn_info->uses = 0; | |
1046 | insn_info->eq_uses = 0; | |
1047 | insn_info->mw_hardregs = 0; | |
3072d30e | 1048 | } |
1049 | if (dump_file) | |
bff9eb26 | 1050 | fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid); |
48e1416a | 1051 | |
4b5a4301 | 1052 | bitmap_clear_bit (&df->insns_to_delete, uid); |
1053 | bitmap_clear_bit (&df->insns_to_notes_rescan, uid); | |
1054 | bitmap_set_bit (&df->insns_to_rescan, INSN_UID (insn)); | |
3072d30e | 1055 | return false; |
1056 | } | |
1057 | ||
4b5a4301 | 1058 | bitmap_clear_bit (&df->insns_to_delete, uid); |
1059 | bitmap_clear_bit (&df->insns_to_rescan, uid); | |
1060 | bitmap_clear_bit (&df->insns_to_notes_rescan, uid); | |
3072d30e | 1061 | if (insn_info) |
1062 | { | |
2e81afe5 | 1063 | int luid; |
3072d30e | 1064 | bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false); |
1065 | /* If there's no change, return false. */ | |
1066 | if (the_same) | |
d0802b39 | 1067 | { |
3072d30e | 1068 | df_free_collection_rec (&collection_rec); |
1069 | if (dump_file) | |
1070 | fprintf (dump_file, "verify found no changes in insn with uid = %d.\n", uid); | |
1071 | return false; | |
d0802b39 | 1072 | } |
3072d30e | 1073 | if (dump_file) |
1074 | fprintf (dump_file, "rescanning insn with uid = %d.\n", uid); | |
1075 | ||
2e81afe5 | 1076 | /* There's change - we need to delete the existing info. |
1077 | Since the insn isn't moved, we can salvage its LUID. */ | |
1078 | luid = DF_INSN_LUID (insn); | |
7d95e007 | 1079 | df_insn_info_free_fields (insn_info); |
1080 | df_insn_info_init_fields (insn_info, insn); | |
2e81afe5 | 1081 | DF_INSN_LUID (insn) = luid; |
3072d30e | 1082 | } |
1083 | else | |
1084 | { | |
158b6cc9 | 1085 | struct df_insn_info *insn_info = df_insn_create_insn_record (insn); |
1086 | df_insn_refs_collect (&collection_rec, bb, insn_info); | |
3072d30e | 1087 | if (dump_file) |
1088 | fprintf (dump_file, "scanning new insn with uid = %d.\n", uid); | |
1089 | } | |
1090 | ||
d70aebca | 1091 | df_refs_add_to_chains (&collection_rec, bb, insn, copy_all); |
0a7642a1 | 1092 | if (!DEBUG_INSN_P (insn)) |
86fc6921 | 1093 | df_set_bb_dirty (bb); |
f7f05a07 | 1094 | |
3072d30e | 1095 | return true; |
1096 | } | |
1097 | ||
9845d120 | 1098 | /* Same as df_insn_rescan, but don't mark the basic block as |
1099 | dirty. */ | |
1100 | ||
1101 | bool | |
e149ca56 | 1102 | df_insn_rescan_debug_internal (rtx_insn *insn) |
9845d120 | 1103 | { |
1104 | unsigned int uid = INSN_UID (insn); | |
1105 | struct df_insn_info *insn_info; | |
1106 | ||
76d2e170 | 1107 | gcc_assert (DEBUG_INSN_P (insn) |
1108 | && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn))); | |
9845d120 | 1109 | |
1110 | if (!df) | |
1111 | return false; | |
1112 | ||
1113 | insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn)); | |
1114 | if (!insn_info) | |
1115 | return false; | |
1116 | ||
1117 | if (dump_file) | |
1118 | fprintf (dump_file, "deleting debug_insn with uid = %d.\n", uid); | |
1119 | ||
4b5a4301 | 1120 | bitmap_clear_bit (&df->insns_to_delete, uid); |
1121 | bitmap_clear_bit (&df->insns_to_rescan, uid); | |
1122 | bitmap_clear_bit (&df->insns_to_notes_rescan, uid); | |
9845d120 | 1123 | |
ddc2d0e3 | 1124 | if (insn_info->defs == 0 |
1125 | && insn_info->uses == 0 | |
1126 | && insn_info->eq_uses == 0 | |
1127 | && insn_info->mw_hardregs == 0) | |
9845d120 | 1128 | return false; |
1129 | ||
1130 | df_mw_hardreg_chain_delete (insn_info->mw_hardregs); | |
1131 | ||
1132 | if (df_chain) | |
1133 | { | |
1134 | df_ref_chain_delete_du_chain (insn_info->defs); | |
1135 | df_ref_chain_delete_du_chain (insn_info->uses); | |
1136 | df_ref_chain_delete_du_chain (insn_info->eq_uses); | |
1137 | } | |
1138 | ||
1139 | df_ref_chain_delete (insn_info->defs); | |
1140 | df_ref_chain_delete (insn_info->uses); | |
1141 | df_ref_chain_delete (insn_info->eq_uses); | |
1142 | ||
ddc2d0e3 | 1143 | insn_info->defs = 0; |
1144 | insn_info->uses = 0; | |
1145 | insn_info->eq_uses = 0; | |
1146 | insn_info->mw_hardregs = 0; | |
9845d120 | 1147 | |
1148 | return true; | |
1149 | } | |
1150 | ||
3072d30e | 1151 | |
1152 | /* Rescan all of the insns in the function. Note that the artificial | |
b983ea33 | 1153 | uses and defs are not touched. This function will destroy def-use |
3072d30e | 1154 | or use-def chains. */ |
1155 | ||
1156 | void | |
1157 | df_insn_rescan_all (void) | |
1158 | { | |
1159 | bool no_insn_rescan = false; | |
1160 | bool defer_insn_rescan = false; | |
1161 | basic_block bb; | |
1162 | bitmap_iterator bi; | |
1163 | unsigned int uid; | |
48e1416a | 1164 | |
3072d30e | 1165 | if (df->changeable_flags & DF_NO_INSN_RESCAN) |
1166 | { | |
1167 | df_clear_flags (DF_NO_INSN_RESCAN); | |
1168 | no_insn_rescan = true; | |
d0802b39 | 1169 | } |
48e1416a | 1170 | |
3072d30e | 1171 | if (df->changeable_flags & DF_DEFER_INSN_RESCAN) |
d0802b39 | 1172 | { |
3072d30e | 1173 | df_clear_flags (DF_DEFER_INSN_RESCAN); |
1174 | defer_insn_rescan = true; | |
1175 | } | |
1176 | ||
f6708c36 | 1177 | auto_bitmap tmp (&df_bitmap_obstack); |
1178 | bitmap_copy (tmp, &df->insns_to_delete); | |
1179 | EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi) | |
3072d30e | 1180 | { |
1181 | struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid); | |
1182 | if (insn_info) | |
b983ea33 | 1183 | df_insn_info_delete (uid); |
d0802b39 | 1184 | } |
3072d30e | 1185 | |
4b5a4301 | 1186 | bitmap_clear (&df->insns_to_delete); |
1187 | bitmap_clear (&df->insns_to_rescan); | |
1188 | bitmap_clear (&df->insns_to_notes_rescan); | |
3072d30e | 1189 | |
fc00614f | 1190 | FOR_EACH_BB_FN (bb, cfun) |
3072d30e | 1191 | { |
7a6a083c | 1192 | rtx_insn *insn; |
3072d30e | 1193 | FOR_BB_INSNS (bb, insn) |
1194 | { | |
1195 | df_insn_rescan (insn); | |
1196 | } | |
1197 | } | |
1198 | ||
1199 | if (no_insn_rescan) | |
1200 | df_set_flags (DF_NO_INSN_RESCAN); | |
1201 | if (defer_insn_rescan) | |
1202 | df_set_flags (DF_DEFER_INSN_RESCAN); | |
d0802b39 | 1203 | } |
1204 | ||
1205 | ||
a3de79f9 | 1206 | /* Process all of the deferred rescans or deletions. */ |
e011eba9 | 1207 | |
3072d30e | 1208 | void |
1209 | df_process_deferred_rescans (void) | |
e011eba9 | 1210 | { |
3072d30e | 1211 | bool no_insn_rescan = false; |
1212 | bool defer_insn_rescan = false; | |
e011eba9 | 1213 | bitmap_iterator bi; |
3072d30e | 1214 | unsigned int uid; |
48e1416a | 1215 | |
3072d30e | 1216 | if (df->changeable_flags & DF_NO_INSN_RESCAN) |
1217 | { | |
1218 | df_clear_flags (DF_NO_INSN_RESCAN); | |
1219 | no_insn_rescan = true; | |
1220 | } | |
48e1416a | 1221 | |
3072d30e | 1222 | if (df->changeable_flags & DF_DEFER_INSN_RESCAN) |
1223 | { | |
1224 | df_clear_flags (DF_DEFER_INSN_RESCAN); | |
1225 | defer_insn_rescan = true; | |
1226 | } | |
1227 | ||
1228 | if (dump_file) | |
a3de79f9 | 1229 | fprintf (dump_file, "starting the processing of deferred insns\n"); |
3072d30e | 1230 | |
f6708c36 | 1231 | auto_bitmap tmp (&df_bitmap_obstack); |
1232 | bitmap_copy (tmp, &df->insns_to_delete); | |
1233 | EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi) | |
3072d30e | 1234 | { |
1235 | struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid); | |
1236 | if (insn_info) | |
b983ea33 | 1237 | df_insn_info_delete (uid); |
3072d30e | 1238 | } |
1239 | ||
f6708c36 | 1240 | bitmap_copy (tmp, &df->insns_to_rescan); |
1241 | EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi) | |
3072d30e | 1242 | { |
1243 | struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid); | |
1244 | if (insn_info) | |
1245 | df_insn_rescan (insn_info->insn); | |
1246 | } | |
1247 | ||
f6708c36 | 1248 | bitmap_copy (tmp, &df->insns_to_notes_rescan); |
1249 | EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi) | |
3072d30e | 1250 | { |
1251 | struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid); | |
1252 | if (insn_info) | |
1253 | df_notes_rescan (insn_info->insn); | |
1254 | } | |
1255 | ||
1256 | if (dump_file) | |
a3de79f9 | 1257 | fprintf (dump_file, "ending the processing of deferred insns\n"); |
3072d30e | 1258 | |
4b5a4301 | 1259 | bitmap_clear (&df->insns_to_delete); |
1260 | bitmap_clear (&df->insns_to_rescan); | |
1261 | bitmap_clear (&df->insns_to_notes_rescan); | |
3072d30e | 1262 | |
1263 | if (no_insn_rescan) | |
1264 | df_set_flags (DF_NO_INSN_RESCAN); | |
1265 | if (defer_insn_rescan) | |
1266 | df_set_flags (DF_DEFER_INSN_RESCAN); | |
1267 | ||
1268 | /* If someone changed regs_ever_live during this pass, fix up the | |
1269 | entry and exit blocks. */ | |
1270 | if (df->redo_entry_and_exit) | |
1271 | { | |
1272 | df_update_entry_exit_and_calls (); | |
1273 | df->redo_entry_and_exit = false; | |
1274 | } | |
1275 | } | |
1276 | ||
e011eba9 | 1277 | |
3072d30e | 1278 | /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include |
1279 | the uses if INCLUDE_USES. Include the eq_uses if | |
1280 | INCLUDE_EQ_USES. */ | |
1281 | ||
1282 | static unsigned int | |
48e1416a | 1283 | df_count_refs (bool include_defs, bool include_uses, |
3072d30e | 1284 | bool include_eq_uses) |
1285 | { | |
1286 | unsigned int regno; | |
1287 | int size = 0; | |
1288 | unsigned int m = df->regs_inited; | |
48e1416a | 1289 | |
3072d30e | 1290 | for (regno = 0; regno < m; regno++) |
e011eba9 | 1291 | { |
3072d30e | 1292 | if (include_defs) |
1293 | size += DF_REG_DEF_COUNT (regno); | |
1294 | if (include_uses) | |
1295 | size += DF_REG_USE_COUNT (regno); | |
1296 | if (include_eq_uses) | |
1297 | size += DF_REG_EQ_USE_COUNT (regno); | |
e011eba9 | 1298 | } |
3072d30e | 1299 | return size; |
e011eba9 | 1300 | } |
1301 | ||
1302 | ||
1303 | /* Take build ref table for either the uses or defs from the reg-use | |
3072d30e | 1304 | or reg-def chains. This version processes the refs in reg order |
1305 | which is likely to be best if processing the whole function. */ | |
e011eba9 | 1306 | |
48e1416a | 1307 | static void |
3072d30e | 1308 | df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info, |
48e1416a | 1309 | bool include_defs, |
1310 | bool include_uses, | |
3072d30e | 1311 | bool include_eq_uses) |
e011eba9 | 1312 | { |
3072d30e | 1313 | unsigned int m = df->regs_inited; |
e011eba9 | 1314 | unsigned int regno; |
1315 | unsigned int offset = 0; | |
3072d30e | 1316 | unsigned int start; |
e011eba9 | 1317 | |
3072d30e | 1318 | if (df->changeable_flags & DF_NO_HARD_REGS) |
1319 | { | |
1320 | start = FIRST_PSEUDO_REGISTER; | |
1321 | memset (ref_info->begin, 0, sizeof (int) * FIRST_PSEUDO_REGISTER); | |
1322 | memset (ref_info->count, 0, sizeof (int) * FIRST_PSEUDO_REGISTER); | |
e011eba9 | 1323 | } |
3072d30e | 1324 | else |
1325 | start = 0; | |
e011eba9 | 1326 | |
48e1416a | 1327 | ref_info->total_size |
3072d30e | 1328 | = df_count_refs (include_defs, include_uses, include_eq_uses); |
1329 | ||
1330 | df_check_and_grow_ref_info (ref_info, 1); | |
1331 | ||
1332 | for (regno = start; regno < m; regno++) | |
e011eba9 | 1333 | { |
e011eba9 | 1334 | int count = 0; |
3072d30e | 1335 | ref_info->begin[regno] = offset; |
1336 | if (include_defs) | |
1337 | { | |
ed6e85ae | 1338 | df_ref ref = DF_REG_DEF_CHAIN (regno); |
48e1416a | 1339 | while (ref) |
3072d30e | 1340 | { |
1341 | ref_info->refs[offset] = ref; | |
1342 | DF_REF_ID (ref) = offset++; | |
1343 | count++; | |
1344 | ref = DF_REF_NEXT_REG (ref); | |
0ea2d350 | 1345 | gcc_checking_assert (offset < ref_info->refs_size); |
3072d30e | 1346 | } |
1347 | } | |
1348 | if (include_uses) | |
e011eba9 | 1349 | { |
ed6e85ae | 1350 | df_ref ref = DF_REG_USE_CHAIN (regno); |
48e1416a | 1351 | while (ref) |
e011eba9 | 1352 | { |
1353 | ref_info->refs[offset] = ref; | |
1354 | DF_REF_ID (ref) = offset++; | |
3072d30e | 1355 | count++; |
e011eba9 | 1356 | ref = DF_REF_NEXT_REG (ref); |
0ea2d350 | 1357 | gcc_checking_assert (offset < ref_info->refs_size); |
3072d30e | 1358 | } |
1359 | } | |
1360 | if (include_eq_uses) | |
1361 | { | |
ed6e85ae | 1362 | df_ref ref = DF_REG_EQ_USE_CHAIN (regno); |
48e1416a | 1363 | while (ref) |
3072d30e | 1364 | { |
1365 | ref_info->refs[offset] = ref; | |
1366 | DF_REF_ID (ref) = offset++; | |
e011eba9 | 1367 | count++; |
3072d30e | 1368 | ref = DF_REF_NEXT_REG (ref); |
0ea2d350 | 1369 | gcc_checking_assert (offset < ref_info->refs_size); |
e011eba9 | 1370 | } |
e011eba9 | 1371 | } |
3072d30e | 1372 | ref_info->count[regno] = count; |
e011eba9 | 1373 | } |
48e1416a | 1374 | |
e011eba9 | 1375 | /* The bitmap size is not decremented when refs are deleted. So |
1376 | reset it now that we have squished out all of the empty | |
1377 | slots. */ | |
3072d30e | 1378 | ref_info->table_size = offset; |
e011eba9 | 1379 | } |
1380 | ||
e011eba9 | 1381 | |
3072d30e | 1382 | /* Take build ref table for either the uses or defs from the reg-use |
1383 | or reg-def chains. This version processes the refs in insn order | |
1384 | which is likely to be best if processing some segment of the | |
1385 | function. */ | |
e011eba9 | 1386 | |
48e1416a | 1387 | static void |
3072d30e | 1388 | df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info, |
48e1416a | 1389 | bool include_defs, |
1390 | bool include_uses, | |
3072d30e | 1391 | bool include_eq_uses) |
e011eba9 | 1392 | { |
3072d30e | 1393 | bitmap_iterator bi; |
1394 | unsigned int bb_index; | |
1395 | unsigned int m = df->regs_inited; | |
1396 | unsigned int offset = 0; | |
1397 | unsigned int r; | |
48e1416a | 1398 | unsigned int start |
3072d30e | 1399 | = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0; |
e011eba9 | 1400 | |
3072d30e | 1401 | memset (ref_info->begin, 0, sizeof (int) * df->regs_inited); |
1402 | memset (ref_info->count, 0, sizeof (int) * df->regs_inited); | |
1403 | ||
1404 | ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses); | |
1405 | df_check_and_grow_ref_info (ref_info, 1); | |
e011eba9 | 1406 | |
3072d30e | 1407 | EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi) |
e011eba9 | 1408 | { |
f5a6b05f | 1409 | basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index); |
7a6a083c | 1410 | rtx_insn *insn; |
be10bb5a | 1411 | df_ref def, use; |
3072d30e | 1412 | |
1413 | if (include_defs) | |
f1c570a6 | 1414 | FOR_EACH_ARTIFICIAL_DEF (def, bb_index) |
3e6933a8 | 1415 | { |
f1c570a6 | 1416 | unsigned int regno = DF_REF_REGNO (def); |
3072d30e | 1417 | ref_info->count[regno]++; |
3e6933a8 | 1418 | } |
3072d30e | 1419 | if (include_uses) |
f1c570a6 | 1420 | FOR_EACH_ARTIFICIAL_USE (use, bb_index) |
3e6933a8 | 1421 | { |
f1c570a6 | 1422 | unsigned int regno = DF_REF_REGNO (use); |
3072d30e | 1423 | ref_info->count[regno]++; |
3e6933a8 | 1424 | } |
e011eba9 | 1425 | |
3072d30e | 1426 | FOR_BB_INSNS (bb, insn) |
1427 | { | |
1428 | if (INSN_P (insn)) | |
1429 | { | |
be10bb5a | 1430 | struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); |
48e1416a | 1431 | |
3072d30e | 1432 | if (include_defs) |
be10bb5a | 1433 | FOR_EACH_INSN_INFO_DEF (def, insn_info) |
3072d30e | 1434 | { |
be10bb5a | 1435 | unsigned int regno = DF_REF_REGNO (def); |
3072d30e | 1436 | ref_info->count[regno]++; |
1437 | } | |
1438 | if (include_uses) | |
be10bb5a | 1439 | FOR_EACH_INSN_INFO_USE (use, insn_info) |
3072d30e | 1440 | { |
be10bb5a | 1441 | unsigned int regno = DF_REF_REGNO (use); |
3072d30e | 1442 | ref_info->count[regno]++; |
1443 | } | |
1444 | if (include_eq_uses) | |
be10bb5a | 1445 | FOR_EACH_INSN_INFO_EQ_USE (use, insn_info) |
3072d30e | 1446 | { |
be10bb5a | 1447 | unsigned int regno = DF_REF_REGNO (use); |
3072d30e | 1448 | ref_info->count[regno]++; |
1449 | } | |
1450 | } | |
1451 | } | |
1452 | } | |
1453 | ||
1454 | for (r = start; r < m; r++) | |
1455 | { | |
1456 | ref_info->begin[r] = offset; | |
1457 | offset += ref_info->count[r]; | |
1458 | ref_info->count[r] = 0; | |
1459 | } | |
48e1416a | 1460 | |
3072d30e | 1461 | EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi) |
1462 | { | |
f5a6b05f | 1463 | basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index); |
7a6a083c | 1464 | rtx_insn *insn; |
be10bb5a | 1465 | df_ref def, use; |
3072d30e | 1466 | |
1467 | if (include_defs) | |
f1c570a6 | 1468 | FOR_EACH_ARTIFICIAL_DEF (def, bb_index) |
3e6933a8 | 1469 | { |
f1c570a6 | 1470 | unsigned int regno = DF_REF_REGNO (def); |
3072d30e | 1471 | if (regno >= start) |
3e6933a8 | 1472 | { |
3072d30e | 1473 | unsigned int id |
1474 | = ref_info->begin[regno] + ref_info->count[regno]++; | |
f1c570a6 | 1475 | DF_REF_ID (def) = id; |
1476 | ref_info->refs[id] = def; | |
3e6933a8 | 1477 | } |
3e6933a8 | 1478 | } |
3072d30e | 1479 | if (include_uses) |
f1c570a6 | 1480 | FOR_EACH_ARTIFICIAL_USE (use, bb_index) |
3e6933a8 | 1481 | { |
f1c570a6 | 1482 | unsigned int regno = DF_REF_REGNO (def); |
3072d30e | 1483 | if (regno >= start) |
1484 | { | |
1485 | unsigned int id | |
1486 | = ref_info->begin[regno] + ref_info->count[regno]++; | |
f1c570a6 | 1487 | DF_REF_ID (use) = id; |
1488 | ref_info->refs[id] = use; | |
3072d30e | 1489 | } |
3e6933a8 | 1490 | } |
3072d30e | 1491 | |
1492 | FOR_BB_INSNS (bb, insn) | |
1493 | { | |
1494 | if (INSN_P (insn)) | |
1495 | { | |
be10bb5a | 1496 | struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); |
48e1416a | 1497 | |
3072d30e | 1498 | if (include_defs) |
be10bb5a | 1499 | FOR_EACH_INSN_INFO_DEF (def, insn_info) |
3072d30e | 1500 | { |
be10bb5a | 1501 | unsigned int regno = DF_REF_REGNO (def); |
3072d30e | 1502 | if (regno >= start) |
1503 | { | |
1504 | unsigned int id | |
1505 | = ref_info->begin[regno] + ref_info->count[regno]++; | |
be10bb5a | 1506 | DF_REF_ID (def) = id; |
1507 | ref_info->refs[id] = def; | |
3072d30e | 1508 | } |
1509 | } | |
1510 | if (include_uses) | |
be10bb5a | 1511 | FOR_EACH_INSN_INFO_USE (use, insn_info) |
3072d30e | 1512 | { |
be10bb5a | 1513 | unsigned int regno = DF_REF_REGNO (use); |
3072d30e | 1514 | if (regno >= start) |
1515 | { | |
1516 | unsigned int id | |
1517 | = ref_info->begin[regno] + ref_info->count[regno]++; | |
be10bb5a | 1518 | DF_REF_ID (use) = id; |
1519 | ref_info->refs[id] = use; | |
3072d30e | 1520 | } |
1521 | } | |
1522 | if (include_eq_uses) | |
be10bb5a | 1523 | FOR_EACH_INSN_INFO_EQ_USE (use, insn_info) |
3072d30e | 1524 | { |
be10bb5a | 1525 | unsigned int regno = DF_REF_REGNO (use); |
3072d30e | 1526 | if (regno >= start) |
1527 | { | |
1528 | unsigned int id | |
1529 | = ref_info->begin[regno] + ref_info->count[regno]++; | |
be10bb5a | 1530 | DF_REF_ID (use) = id; |
1531 | ref_info->refs[id] = use; | |
3072d30e | 1532 | } |
1533 | } | |
1534 | } | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | /* The bitmap size is not decremented when refs are deleted. So | |
1539 | reset it now that we have squished out all of the empty | |
1540 | slots. */ | |
1541 | ||
1542 | ref_info->table_size = offset; | |
1543 | } | |
1544 | ||
1545 | /* Take build ref table for either the uses or defs from the reg-use | |
1546 | or reg-def chains. */ | |
1547 | ||
48e1416a | 1548 | static void |
3072d30e | 1549 | df_reorganize_refs_by_reg (struct df_ref_info *ref_info, |
48e1416a | 1550 | bool include_defs, |
1551 | bool include_uses, | |
3072d30e | 1552 | bool include_eq_uses) |
1553 | { | |
1554 | if (df->analyze_subset) | |
48e1416a | 1555 | df_reorganize_refs_by_reg_by_insn (ref_info, include_defs, |
3072d30e | 1556 | include_uses, include_eq_uses); |
1557 | else | |
48e1416a | 1558 | df_reorganize_refs_by_reg_by_reg (ref_info, include_defs, |
3072d30e | 1559 | include_uses, include_eq_uses); |
1560 | } | |
1561 | ||
1562 | ||
1563 | /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */ | |
48e1416a | 1564 | static unsigned int |
1565 | df_add_refs_to_table (unsigned int offset, | |
1566 | struct df_ref_info *ref_info, | |
ddc2d0e3 | 1567 | df_ref ref) |
3072d30e | 1568 | { |
ddc2d0e3 | 1569 | for (; ref; ref = DF_REF_NEXT_LOC (ref)) |
1570 | if (!(df->changeable_flags & DF_NO_HARD_REGS) | |
1571 | || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER)) | |
1572 | { | |
1573 | ref_info->refs[offset] = ref; | |
1574 | DF_REF_ID (ref) = offset++; | |
1575 | } | |
3072d30e | 1576 | return offset; |
1577 | } | |
1578 | ||
1579 | ||
1580 | /* Count the number of refs in all of the insns of BB. Include the | |
1581 | defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the | |
1582 | eq_uses if INCLUDE_EQ_USES. */ | |
1583 | ||
1584 | static unsigned int | |
48e1416a | 1585 | df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset, |
3072d30e | 1586 | struct df_ref_info *ref_info, |
48e1416a | 1587 | bool include_defs, bool include_uses, |
3072d30e | 1588 | bool include_eq_uses) |
1589 | { | |
7a6a083c | 1590 | rtx_insn *insn; |
3072d30e | 1591 | |
1592 | if (include_defs) | |
48e1416a | 1593 | offset = df_add_refs_to_table (offset, ref_info, |
3072d30e | 1594 | df_get_artificial_defs (bb->index)); |
1595 | if (include_uses) | |
48e1416a | 1596 | offset = df_add_refs_to_table (offset, ref_info, |
3072d30e | 1597 | df_get_artificial_uses (bb->index)); |
1598 | ||
1599 | FOR_BB_INSNS (bb, insn) | |
1600 | if (INSN_P (insn)) | |
1601 | { | |
1602 | unsigned int uid = INSN_UID (insn); | |
1603 | if (include_defs) | |
48e1416a | 1604 | offset = df_add_refs_to_table (offset, ref_info, |
3072d30e | 1605 | DF_INSN_UID_DEFS (uid)); |
1606 | if (include_uses) | |
48e1416a | 1607 | offset = df_add_refs_to_table (offset, ref_info, |
3072d30e | 1608 | DF_INSN_UID_USES (uid)); |
1609 | if (include_eq_uses) | |
48e1416a | 1610 | offset = df_add_refs_to_table (offset, ref_info, |
3072d30e | 1611 | DF_INSN_UID_EQ_USES (uid)); |
3e6933a8 | 1612 | } |
3072d30e | 1613 | return offset; |
1614 | } | |
1615 | ||
1616 | ||
bef304b8 | 1617 | /* Organize the refs by insn into the table in REF_INFO. If |
3072d30e | 1618 | blocks_to_analyze is defined, use that set, otherwise the entire |
1619 | program. Include the defs if INCLUDE_DEFS. Include the uses if | |
1620 | INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */ | |
1621 | ||
1622 | static void | |
1623 | df_reorganize_refs_by_insn (struct df_ref_info *ref_info, | |
48e1416a | 1624 | bool include_defs, bool include_uses, |
3072d30e | 1625 | bool include_eq_uses) |
1626 | { | |
1627 | basic_block bb; | |
1628 | unsigned int offset = 0; | |
1629 | ||
1630 | ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses); | |
1631 | df_check_and_grow_ref_info (ref_info, 1); | |
1632 | if (df->blocks_to_analyze) | |
1633 | { | |
1634 | bitmap_iterator bi; | |
1635 | unsigned int index; | |
1636 | ||
1637 | EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi) | |
1638 | { | |
f5a6b05f | 1639 | offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun, |
1640 | index), | |
1641 | offset, ref_info, | |
48e1416a | 1642 | include_defs, include_uses, |
3072d30e | 1643 | include_eq_uses); |
1644 | } | |
1645 | ||
1646 | ref_info->table_size = offset; | |
1647 | } | |
1648 | else | |
1649 | { | |
ed7d889a | 1650 | FOR_ALL_BB_FN (bb, cfun) |
48e1416a | 1651 | offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info, |
1652 | include_defs, include_uses, | |
3072d30e | 1653 | include_eq_uses); |
1654 | ref_info->table_size = offset; | |
1655 | } | |
1656 | } | |
1657 | ||
1658 | ||
1659 | /* If the use refs in DF are not organized, reorganize them. */ | |
1660 | ||
48e1416a | 1661 | void |
3072d30e | 1662 | df_maybe_reorganize_use_refs (enum df_ref_order order) |
1663 | { | |
1664 | if (order == df->use_info.ref_order) | |
1665 | return; | |
1666 | ||
1667 | switch (order) | |
1668 | { | |
1669 | case DF_REF_ORDER_BY_REG: | |
1670 | df_reorganize_refs_by_reg (&df->use_info, false, true, false); | |
1671 | break; | |
1672 | ||
1673 | case DF_REF_ORDER_BY_REG_WITH_NOTES: | |
1674 | df_reorganize_refs_by_reg (&df->use_info, false, true, true); | |
1675 | break; | |
1676 | ||
1677 | case DF_REF_ORDER_BY_INSN: | |
1678 | df_reorganize_refs_by_insn (&df->use_info, false, true, false); | |
1679 | break; | |
1680 | ||
1681 | case DF_REF_ORDER_BY_INSN_WITH_NOTES: | |
1682 | df_reorganize_refs_by_insn (&df->use_info, false, true, true); | |
1683 | break; | |
1684 | ||
1685 | case DF_REF_ORDER_NO_TABLE: | |
1686 | free (df->use_info.refs); | |
1687 | df->use_info.refs = NULL; | |
1688 | df->use_info.refs_size = 0; | |
1689 | break; | |
1690 | ||
1691 | case DF_REF_ORDER_UNORDERED: | |
1692 | case DF_REF_ORDER_UNORDERED_WITH_NOTES: | |
1693 | gcc_unreachable (); | |
1694 | break; | |
1695 | } | |
48e1416a | 1696 | |
3072d30e | 1697 | df->use_info.ref_order = order; |
1698 | } | |
1699 | ||
1700 | ||
1701 | /* If the def refs in DF are not organized, reorganize them. */ | |
1702 | ||
48e1416a | 1703 | void |
3072d30e | 1704 | df_maybe_reorganize_def_refs (enum df_ref_order order) |
1705 | { | |
1706 | if (order == df->def_info.ref_order) | |
1707 | return; | |
1708 | ||
1709 | switch (order) | |
1710 | { | |
1711 | case DF_REF_ORDER_BY_REG: | |
1712 | df_reorganize_refs_by_reg (&df->def_info, true, false, false); | |
1713 | break; | |
1714 | ||
1715 | case DF_REF_ORDER_BY_INSN: | |
1716 | df_reorganize_refs_by_insn (&df->def_info, true, false, false); | |
1717 | break; | |
1718 | ||
1719 | case DF_REF_ORDER_NO_TABLE: | |
1720 | free (df->def_info.refs); | |
1721 | df->def_info.refs = NULL; | |
1722 | df->def_info.refs_size = 0; | |
1723 | break; | |
1724 | ||
1725 | case DF_REF_ORDER_BY_INSN_WITH_NOTES: | |
1726 | case DF_REF_ORDER_BY_REG_WITH_NOTES: | |
1727 | case DF_REF_ORDER_UNORDERED: | |
1728 | case DF_REF_ORDER_UNORDERED_WITH_NOTES: | |
1729 | gcc_unreachable (); | |
1730 | break; | |
1731 | } | |
48e1416a | 1732 | |
3072d30e | 1733 | df->def_info.ref_order = order; |
1734 | } | |
1735 | ||
1736 | ||
3072d30e | 1737 | /* Change all of the basic block references in INSN to use the insn's |
48e1416a | 1738 | current basic block. This function is called from routines that move |
1739 | instructions from one block to another. */ | |
3072d30e | 1740 | |
1741 | void | |
e149ca56 | 1742 | df_insn_change_bb (rtx_insn *insn, basic_block new_bb) |
3072d30e | 1743 | { |
a2bdd643 | 1744 | basic_block old_bb = BLOCK_FOR_INSN (insn); |
3072d30e | 1745 | struct df_insn_info *insn_info; |
1746 | unsigned int uid = INSN_UID (insn); | |
1747 | ||
a2bdd643 | 1748 | if (old_bb == new_bb) |
1749 | return; | |
1750 | ||
1751 | set_block_for_insn (insn, new_bb); | |
1752 | ||
3072d30e | 1753 | if (!df) |
1754 | return; | |
1755 | ||
1756 | if (dump_file) | |
1757 | fprintf (dump_file, "changing bb of uid %d\n", uid); | |
1758 | ||
1759 | insn_info = DF_INSN_UID_SAFE_GET (uid); | |
1760 | if (insn_info == NULL) | |
1761 | { | |
1762 | if (dump_file) | |
1763 | fprintf (dump_file, " unscanned insn\n"); | |
1764 | df_insn_rescan (insn); | |
1765 | return; | |
1766 | } | |
1767 | ||
1768 | if (!INSN_P (insn)) | |
1769 | return; | |
1770 | ||
3072d30e | 1771 | df_set_bb_dirty (new_bb); |
1772 | if (old_bb) | |
1773 | { | |
1774 | if (dump_file) | |
48e1416a | 1775 | fprintf (dump_file, " from %d to %d\n", |
3072d30e | 1776 | old_bb->index, new_bb->index); |
1777 | df_set_bb_dirty (old_bb); | |
1778 | } | |
1779 | else | |
1780 | if (dump_file) | |
1781 | fprintf (dump_file, " to %d\n", new_bb->index); | |
1782 | } | |
1783 | ||
1784 | ||
1785 | /* Helper function for df_ref_change_reg_with_loc. */ | |
1786 | ||
1787 | static void | |
48e1416a | 1788 | df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df, |
ed6e85ae | 1789 | struct df_reg_info *new_df, |
91f5b5cb | 1790 | unsigned int new_regno, rtx loc) |
3072d30e | 1791 | { |
ed6e85ae | 1792 | df_ref the_ref = old_df->reg_chain; |
3072d30e | 1793 | |
1794 | while (the_ref) | |
1795 | { | |
ed6e85ae | 1796 | if ((!DF_REF_IS_ARTIFICIAL (the_ref)) |
c989ecc1 | 1797 | && DF_REF_LOC (the_ref) |
ed6e85ae | 1798 | && (*DF_REF_LOC (the_ref) == loc)) |
3072d30e | 1799 | { |
ed6e85ae | 1800 | df_ref next_ref = DF_REF_NEXT_REG (the_ref); |
1801 | df_ref prev_ref = DF_REF_PREV_REG (the_ref); | |
ddc2d0e3 | 1802 | df_ref *ref_ptr; |
ed6e85ae | 1803 | struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref); |
3072d30e | 1804 | |
1805 | DF_REF_REGNO (the_ref) = new_regno; | |
1806 | DF_REF_REG (the_ref) = regno_reg_rtx[new_regno]; | |
1807 | ||
1808 | /* Pull the_ref out of the old regno chain. */ | |
1809 | if (prev_ref) | |
ed6e85ae | 1810 | DF_REF_NEXT_REG (prev_ref) = next_ref; |
3072d30e | 1811 | else |
9ce37fa7 | 1812 | old_df->reg_chain = next_ref; |
3072d30e | 1813 | if (next_ref) |
ed6e85ae | 1814 | DF_REF_PREV_REG (next_ref) = prev_ref; |
9ce37fa7 | 1815 | old_df->n_refs--; |
3072d30e | 1816 | |
1817 | /* Put the ref into the new regno chain. */ | |
ed6e85ae | 1818 | DF_REF_PREV_REG (the_ref) = NULL; |
1819 | DF_REF_NEXT_REG (the_ref) = new_df->reg_chain; | |
9ce37fa7 | 1820 | if (new_df->reg_chain) |
ed6e85ae | 1821 | DF_REF_PREV_REG (new_df->reg_chain) = the_ref; |
9ce37fa7 | 1822 | new_df->reg_chain = the_ref; |
1823 | new_df->n_refs++; | |
a43c254c | 1824 | if (DF_REF_BB (the_ref)) |
1825 | df_set_bb_dirty (DF_REF_BB (the_ref)); | |
3072d30e | 1826 | |
ed6e85ae | 1827 | /* Need to sort the record again that the ref was in because |
1828 | the regno is a sorting key. First, find the right | |
1829 | record. */ | |
ddc2d0e3 | 1830 | if (DF_REF_REG_DEF_P (the_ref)) |
1831 | ref_ptr = &insn_info->defs; | |
1832 | else if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE) | |
1833 | ref_ptr = &insn_info->eq_uses; | |
3072d30e | 1834 | else |
ddc2d0e3 | 1835 | ref_ptr = &insn_info->uses; |
ed6e85ae | 1836 | if (dump_file) |
48e1416a | 1837 | fprintf (dump_file, "changing reg in insn %d\n", |
1838 | DF_REF_INSN_UID (the_ref)); | |
1839 | ||
ddc2d0e3 | 1840 | /* Stop if we find the current reference or where the reference |
1841 | needs to be. */ | |
1842 | while (*ref_ptr != the_ref && df_ref_compare (*ref_ptr, the_ref) < 0) | |
1843 | ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr); | |
1844 | if (*ref_ptr != the_ref) | |
3072d30e | 1845 | { |
ddc2d0e3 | 1846 | /* The reference needs to be promoted up the list. */ |
1847 | df_ref next = DF_REF_NEXT_LOC (the_ref); | |
1848 | DF_REF_NEXT_LOC (the_ref) = *ref_ptr; | |
1849 | *ref_ptr = the_ref; | |
1850 | do | |
1851 | ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr); | |
1852 | while (*ref_ptr != the_ref); | |
1853 | *ref_ptr = next; | |
1854 | } | |
1855 | else if (DF_REF_NEXT_LOC (the_ref) | |
1856 | && df_ref_compare (the_ref, DF_REF_NEXT_LOC (the_ref)) > 0) | |
1857 | { | |
1858 | /* The reference needs to be demoted down the list. */ | |
1859 | *ref_ptr = DF_REF_NEXT_LOC (the_ref); | |
1860 | do | |
1861 | ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr); | |
1862 | while (*ref_ptr && df_ref_compare (the_ref, *ref_ptr) > 0); | |
1863 | DF_REF_NEXT_LOC (the_ref) = *ref_ptr; | |
1864 | *ref_ptr = the_ref; | |
3072d30e | 1865 | } |
3072d30e | 1866 | |
1867 | the_ref = next_ref; | |
1868 | } | |
1869 | else | |
ed6e85ae | 1870 | the_ref = DF_REF_NEXT_REG (the_ref); |
3072d30e | 1871 | } |
1872 | } | |
1873 | ||
1874 | ||
91f5b5cb | 1875 | /* Change the regno of register LOC to NEW_REGNO and update the df |
1876 | information accordingly. Refs that do not match LOC are not changed | |
1877 | which means that artificial refs are not changed since they have no loc. | |
1878 | This call is to support the SET_REGNO macro. */ | |
3072d30e | 1879 | |
1880 | void | |
91f5b5cb | 1881 | df_ref_change_reg_with_loc (rtx loc, unsigned int new_regno) |
3072d30e | 1882 | { |
91f5b5cb | 1883 | unsigned int old_regno = REGNO (loc); |
1884 | if (old_regno == new_regno) | |
3072d30e | 1885 | return; |
1886 | ||
91f5b5cb | 1887 | if (df) |
1888 | { | |
1889 | df_grow_reg_info (); | |
1890 | ||
1891 | df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno), | |
1892 | DF_REG_DEF_GET (new_regno), | |
1893 | new_regno, loc); | |
1894 | df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno), | |
1895 | DF_REG_USE_GET (new_regno), | |
1896 | new_regno, loc); | |
1897 | df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno), | |
1898 | DF_REG_EQ_USE_GET (new_regno), | |
1899 | new_regno, loc); | |
1900 | } | |
1c0849e5 | 1901 | set_mode_and_regno (loc, GET_MODE (loc), new_regno); |
3072d30e | 1902 | } |
1903 | ||
1904 | ||
1905 | /* Delete the mw_hardregs that point into the eq_notes. */ | |
1906 | ||
ddc2d0e3 | 1907 | static void |
3072d30e | 1908 | df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info) |
1909 | { | |
ddc2d0e3 | 1910 | struct df_mw_hardreg **mw_ptr = &insn_info->mw_hardregs; |
48e1416a | 1911 | struct df_scan_problem_data *problem_data |
3072d30e | 1912 | = (struct df_scan_problem_data *) df_scan->problem_data; |
1913 | ||
ddc2d0e3 | 1914 | while (*mw_ptr) |
3072d30e | 1915 | { |
ddc2d0e3 | 1916 | df_mw_hardreg *mw = *mw_ptr; |
1917 | if (mw->flags & DF_REF_IN_NOTE) | |
3072d30e | 1918 | { |
ddc2d0e3 | 1919 | *mw_ptr = DF_MWS_NEXT (mw); |
399ea05d | 1920 | problem_data->mw_reg_pool->remove (mw); |
3072d30e | 1921 | } |
1922 | else | |
ddc2d0e3 | 1923 | mw_ptr = &DF_MWS_NEXT (mw); |
3072d30e | 1924 | } |
3072d30e | 1925 | } |
1926 | ||
1927 | ||
1928 | /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */ | |
1929 | ||
1930 | void | |
e149ca56 | 1931 | df_notes_rescan (rtx_insn *insn) |
3072d30e | 1932 | { |
1933 | struct df_insn_info *insn_info; | |
1934 | unsigned int uid = INSN_UID (insn); | |
1935 | ||
1936 | if (!df) | |
1937 | return; | |
1938 | ||
1939 | /* The client has disabled rescanning and plans to do it itself. */ | |
1940 | if (df->changeable_flags & DF_NO_INSN_RESCAN) | |
1941 | return; | |
1942 | ||
3e3659e7 | 1943 | /* Do nothing if the insn hasn't been emitted yet. */ |
1944 | if (!BLOCK_FOR_INSN (insn)) | |
1945 | return; | |
1946 | ||
3072d30e | 1947 | df_grow_bb_info (df_scan); |
1948 | df_grow_reg_info (); | |
1949 | ||
9af5ce0c | 1950 | insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn)); |
3072d30e | 1951 | |
a3de79f9 | 1952 | /* The client has deferred rescanning. */ |
3072d30e | 1953 | if (df->changeable_flags & DF_DEFER_INSN_RESCAN) |
1954 | { | |
1955 | if (!insn_info) | |
1956 | { | |
1957 | insn_info = df_insn_create_insn_record (insn); | |
ddc2d0e3 | 1958 | insn_info->defs = 0; |
1959 | insn_info->uses = 0; | |
1960 | insn_info->eq_uses = 0; | |
1961 | insn_info->mw_hardregs = 0; | |
3072d30e | 1962 | } |
48e1416a | 1963 | |
4b5a4301 | 1964 | bitmap_clear_bit (&df->insns_to_delete, uid); |
3072d30e | 1965 | /* If the insn is set to be rescanned, it does not need to also |
1966 | be notes rescanned. */ | |
4b5a4301 | 1967 | if (!bitmap_bit_p (&df->insns_to_rescan, uid)) |
1968 | bitmap_set_bit (&df->insns_to_notes_rescan, INSN_UID (insn)); | |
3072d30e | 1969 | return; |
1970 | } | |
1971 | ||
4b5a4301 | 1972 | bitmap_clear_bit (&df->insns_to_delete, uid); |
1973 | bitmap_clear_bit (&df->insns_to_notes_rescan, uid); | |
3072d30e | 1974 | |
1975 | if (insn_info) | |
1976 | { | |
1977 | basic_block bb = BLOCK_FOR_INSN (insn); | |
1978 | rtx note; | |
2e966e2a | 1979 | class df_collection_rec collection_rec; |
ddc2d0e3 | 1980 | unsigned int i; |
3072d30e | 1981 | |
ddc2d0e3 | 1982 | df_mw_hardreg_chain_delete_eq_uses (insn_info); |
3072d30e | 1983 | df_ref_chain_delete (insn_info->eq_uses); |
1984 | insn_info->eq_uses = NULL; | |
1985 | ||
1986 | /* Process REG_EQUIV/REG_EQUAL notes */ | |
1987 | for (note = REG_NOTES (insn); note; | |
1988 | note = XEXP (note, 1)) | |
1989 | { | |
1990 | switch (REG_NOTE_KIND (note)) | |
1991 | { | |
1992 | case REG_EQUIV: | |
1993 | case REG_EQUAL: | |
c989ecc1 | 1994 | df_uses_record (&collection_rec, |
3072d30e | 1995 | &XEXP (note, 0), DF_REF_REG_USE, |
c989ecc1 | 1996 | bb, insn_info, DF_REF_IN_NOTE); |
3072d30e | 1997 | default: |
1998 | break; | |
1999 | } | |
2000 | } | |
2001 | ||
2002 | /* Find some place to put any new mw_hardregs. */ | |
2003 | df_canonize_collection_rec (&collection_rec); | |
ddc2d0e3 | 2004 | struct df_mw_hardreg **mw_ptr = &insn_info->mw_hardregs, *mw; |
2005 | FOR_EACH_VEC_ELT (collection_rec.mw_vec, i, mw) | |
3072d30e | 2006 | { |
ddc2d0e3 | 2007 | while (*mw_ptr && df_mw_compare (*mw_ptr, mw) < 0) |
2008 | mw_ptr = &DF_MWS_NEXT (*mw_ptr); | |
2009 | DF_MWS_NEXT (mw) = *mw_ptr; | |
2010 | *mw_ptr = mw; | |
2011 | mw_ptr = &DF_MWS_NEXT (mw); | |
3072d30e | 2012 | } |
d70aebca | 2013 | df_refs_add_to_chains (&collection_rec, bb, insn, copy_eq_uses); |
3072d30e | 2014 | } |
2015 | else | |
2016 | df_insn_rescan (insn); | |
2017 | ||
2018 | } | |
2019 | ||
2020 | \f | |
2021 | /*---------------------------------------------------------------------------- | |
2022 | Hard core instruction scanning code. No external interfaces here, | |
2023 | just a lot of routines that look inside insns. | |
2024 | ----------------------------------------------------------------------------*/ | |
2025 | ||
2026 | ||
48e1416a | 2027 | /* Return true if the contents of two df_ref's are identical. |
3072d30e | 2028 | It ignores DF_REF_MARKER. */ |
2029 | ||
2030 | static bool | |
ed6e85ae | 2031 | df_ref_equal_p (df_ref ref1, df_ref ref2) |
3072d30e | 2032 | { |
2033 | if (!ref2) | |
2034 | return false; | |
48e1416a | 2035 | |
ed6e85ae | 2036 | if (ref1 == ref2) |
2037 | return true; | |
2038 | ||
2039 | if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2) | |
2040 | || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2) | |
2041 | || DF_REF_REG (ref1) != DF_REF_REG (ref2) | |
2042 | || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2) | |
48e1416a | 2043 | || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)) |
ed6e85ae | 2044 | != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))) |
2045 | || DF_REF_BB (ref1) != DF_REF_BB (ref2) | |
2046 | || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2)) | |
2047 | return false; | |
48e1416a | 2048 | |
ed6e85ae | 2049 | switch (DF_REF_CLASS (ref1)) |
2050 | { | |
2051 | case DF_REF_ARTIFICIAL: | |
2052 | case DF_REF_BASE: | |
2053 | return true; | |
30de5b55 | 2054 | |
ed6e85ae | 2055 | case DF_REF_REGULAR: |
2056 | return DF_REF_LOC (ref1) == DF_REF_LOC (ref2); | |
30de5b55 | 2057 | |
ed6e85ae | 2058 | default: |
2059 | gcc_unreachable (); | |
2060 | } | |
2061 | return false; | |
3072d30e | 2062 | } |
2063 | ||
2064 | ||
2065 | /* Compare REF1 and REF2 for sorting. This is only called from places | |
2066 | where all of the refs are of the same type, in the same insn, and | |
2067 | have the same bb. So these fields are not checked. */ | |
2068 | ||
2069 | static int | |
ddc2d0e3 | 2070 | df_ref_compare (df_ref ref1, df_ref ref2) |
3072d30e | 2071 | { |
ed6e85ae | 2072 | if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)) |
2073 | return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2); | |
2074 | ||
3072d30e | 2075 | if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)) |
2076 | return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2); | |
48e1416a | 2077 | |
3072d30e | 2078 | if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)) |
2079 | return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2); | |
2080 | ||
ed6e85ae | 2081 | if (DF_REF_REG (ref1) != DF_REF_REG (ref2)) |
2082 | return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2); | |
2083 | ||
2084 | /* Cannot look at the LOC field on artificial refs. */ | |
2085 | if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL | |
2086 | && DF_REF_LOC (ref1) != DF_REF_LOC (ref2)) | |
3072d30e | 2087 | return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2); |
2088 | ||
2089 | if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2)) | |
2090 | { | |
2091 | /* If two refs are identical except that one of them has is from | |
2092 | a mw and one is not, we need to have the one with the mw | |
2093 | first. */ | |
2094 | if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) == | |
2095 | DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG)) | |
2096 | return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2); | |
2097 | else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG)) | |
2098 | return -1; | |
2099 | else | |
2100 | return 1; | |
2101 | } | |
30de5b55 | 2102 | |
7496f4ad | 2103 | return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2); |
3072d30e | 2104 | } |
2105 | ||
ddc2d0e3 | 2106 | /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2. */ |
2107 | ||
2108 | static int | |
2109 | df_ref_ptr_compare (const void *r1, const void *r2) | |
2110 | { | |
2111 | return df_ref_compare (*(const df_ref *) r1, *(const df_ref *) r2); | |
2112 | } | |
2113 | ||
3072d30e | 2114 | /* Sort and compress a set of refs. */ |
2115 | ||
f7f05a07 | 2116 | static void |
d70aebca | 2117 | df_sort_and_compress_refs (vec<df_ref, va_heap> *ref_vec) |
3072d30e | 2118 | { |
f7f05a07 | 2119 | unsigned int count; |
3072d30e | 2120 | unsigned int i; |
2121 | unsigned int dist = 0; | |
2122 | ||
f1f41a6c | 2123 | count = ref_vec->length (); |
f7f05a07 | 2124 | |
3072d30e | 2125 | /* If there are 1 or 0 elements, there is nothing to do. */ |
2126 | if (count < 2) | |
f7f05a07 | 2127 | return; |
3072d30e | 2128 | else if (count == 2) |
2129 | { | |
f1f41a6c | 2130 | df_ref r0 = (*ref_vec)[0]; |
2131 | df_ref r1 = (*ref_vec)[1]; | |
ddc2d0e3 | 2132 | if (df_ref_compare (r0, r1) > 0) |
a4f59596 | 2133 | std::swap ((*ref_vec)[0], (*ref_vec)[1]); |
3072d30e | 2134 | } |
2135 | else | |
2136 | { | |
2137 | for (i = 0; i < count - 1; i++) | |
f7f05a07 | 2138 | { |
f1f41a6c | 2139 | df_ref r0 = (*ref_vec)[i]; |
2140 | df_ref r1 = (*ref_vec)[i + 1]; | |
ddc2d0e3 | 2141 | if (df_ref_compare (r0, r1) >= 0) |
f7f05a07 | 2142 | break; |
2143 | } | |
3072d30e | 2144 | /* If the array is already strictly ordered, |
2145 | which is the most common case for large COUNT case | |
2146 | (which happens for CALL INSNs), | |
2147 | no need to sort and filter out duplicate. | |
48e1416a | 2148 | Simply return the count. |
3072d30e | 2149 | Make sure DF_GET_ADD_REFS adds refs in the increasing order |
2150 | of DF_REF_COMPARE. */ | |
2151 | if (i == count - 1) | |
f7f05a07 | 2152 | return; |
ddc2d0e3 | 2153 | ref_vec->qsort (df_ref_ptr_compare); |
3072d30e | 2154 | } |
2155 | ||
2156 | for (i=0; i<count-dist; i++) | |
2157 | { | |
2158 | /* Find the next ref that is not equal to the current ref. */ | |
f7f05a07 | 2159 | while (i + dist + 1 < count |
f1f41a6c | 2160 | && df_ref_equal_p ((*ref_vec)[i], |
2161 | (*ref_vec)[i + dist + 1])) | |
3072d30e | 2162 | { |
f1f41a6c | 2163 | df_free_ref ((*ref_vec)[i + dist + 1]); |
3072d30e | 2164 | dist++; |
2165 | } | |
2166 | /* Copy it down to the next position. */ | |
f7f05a07 | 2167 | if (dist && i + dist + 1 < count) |
f1f41a6c | 2168 | (*ref_vec)[i + 1] = (*ref_vec)[i + dist + 1]; |
3072d30e | 2169 | } |
2170 | ||
2171 | count -= dist; | |
f1f41a6c | 2172 | ref_vec->truncate (count); |
3072d30e | 2173 | } |
2174 | ||
2175 | ||
48e1416a | 2176 | /* Return true if the contents of two df_ref's are identical. |
3072d30e | 2177 | It ignores DF_REF_MARKER. */ |
2178 | ||
2179 | static bool | |
2180 | df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2) | |
2181 | { | |
2182 | if (!mw2) | |
2183 | return false; | |
2184 | return (mw1 == mw2) || | |
2185 | (mw1->mw_reg == mw2->mw_reg | |
2186 | && mw1->type == mw2->type | |
2187 | && mw1->flags == mw2->flags | |
2188 | && mw1->start_regno == mw2->start_regno | |
2189 | && mw1->end_regno == mw2->end_regno); | |
2190 | } | |
2191 | ||
2192 | ||
2193 | /* Compare MW1 and MW2 for sorting. */ | |
2194 | ||
2195 | static int | |
ddc2d0e3 | 2196 | df_mw_compare (const df_mw_hardreg *mw1, const df_mw_hardreg *mw2) |
3072d30e | 2197 | { |
3072d30e | 2198 | if (mw1->type != mw2->type) |
2199 | return mw1->type - mw2->type; | |
2200 | ||
2201 | if (mw1->flags != mw2->flags) | |
2202 | return mw1->flags - mw2->flags; | |
2203 | ||
2204 | if (mw1->start_regno != mw2->start_regno) | |
2205 | return mw1->start_regno - mw2->start_regno; | |
2206 | ||
2207 | if (mw1->end_regno != mw2->end_regno) | |
2208 | return mw1->end_regno - mw2->end_regno; | |
2209 | ||
30a05bdc | 2210 | return mw1->mw_order - mw2->mw_order; |
3072d30e | 2211 | } |
2212 | ||
ddc2d0e3 | 2213 | /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2. */ |
2214 | ||
2215 | static int | |
2216 | df_mw_ptr_compare (const void *m1, const void *m2) | |
2217 | { | |
2218 | return df_mw_compare (*(const df_mw_hardreg *const *) m1, | |
2219 | *(const df_mw_hardreg *const *) m2); | |
2220 | } | |
3072d30e | 2221 | |
2222 | /* Sort and compress a set of refs. */ | |
2223 | ||
f7f05a07 | 2224 | static void |
04009ada | 2225 | df_sort_and_compress_mws (vec<df_mw_hardreg *, va_heap> *mw_vec) |
3072d30e | 2226 | { |
f7f05a07 | 2227 | unsigned int count; |
48e1416a | 2228 | struct df_scan_problem_data *problem_data |
3072d30e | 2229 | = (struct df_scan_problem_data *) df_scan->problem_data; |
2230 | unsigned int i; | |
2231 | unsigned int dist = 0; | |
3072d30e | 2232 | |
f1f41a6c | 2233 | count = mw_vec->length (); |
3072d30e | 2234 | if (count < 2) |
f7f05a07 | 2235 | return; |
3072d30e | 2236 | else if (count == 2) |
2237 | { | |
f1f41a6c | 2238 | struct df_mw_hardreg *m0 = (*mw_vec)[0]; |
2239 | struct df_mw_hardreg *m1 = (*mw_vec)[1]; | |
ddc2d0e3 | 2240 | if (df_mw_compare (m0, m1) > 0) |
3072d30e | 2241 | { |
f1f41a6c | 2242 | struct df_mw_hardreg *tmp = (*mw_vec)[0]; |
2243 | (*mw_vec)[0] = (*mw_vec)[1]; | |
2244 | (*mw_vec)[1] = tmp; | |
3072d30e | 2245 | } |
2246 | } | |
2247 | else | |
ddc2d0e3 | 2248 | mw_vec->qsort (df_mw_ptr_compare); |
3072d30e | 2249 | |
2250 | for (i=0; i<count-dist; i++) | |
2251 | { | |
2252 | /* Find the next ref that is not equal to the current ref. */ | |
f7f05a07 | 2253 | while (i + dist + 1 < count |
f1f41a6c | 2254 | && df_mw_equal_p ((*mw_vec)[i], (*mw_vec)[i + dist + 1])) |
3072d30e | 2255 | { |
399ea05d | 2256 | problem_data->mw_reg_pool->remove ((*mw_vec)[i + dist + 1]); |
3072d30e | 2257 | dist++; |
2258 | } | |
2259 | /* Copy it down to the next position. */ | |
f7f05a07 | 2260 | if (dist && i + dist + 1 < count) |
f1f41a6c | 2261 | (*mw_vec)[i + 1] = (*mw_vec)[i + dist + 1]; |
3072d30e | 2262 | } |
2263 | ||
2264 | count -= dist; | |
f1f41a6c | 2265 | mw_vec->truncate (count); |
3072d30e | 2266 | } |
2267 | ||
2268 | ||
2269 | /* Sort and remove duplicates from the COLLECTION_REC. */ | |
2270 | ||
2271 | static void | |
2e966e2a | 2272 | df_canonize_collection_rec (class df_collection_rec *collection_rec) |
3072d30e | 2273 | { |
f7f05a07 | 2274 | df_sort_and_compress_refs (&collection_rec->def_vec); |
2275 | df_sort_and_compress_refs (&collection_rec->use_vec); | |
2276 | df_sort_and_compress_refs (&collection_rec->eq_use_vec); | |
2277 | df_sort_and_compress_mws (&collection_rec->mw_vec); | |
3072d30e | 2278 | } |
2279 | ||
2280 | ||
2281 | /* Add the new df_ref to appropriate reg_info/ref_info chains. */ | |
2282 | ||
2283 | static void | |
48e1416a | 2284 | df_install_ref (df_ref this_ref, |
2285 | struct df_reg_info *reg_info, | |
3072d30e | 2286 | struct df_ref_info *ref_info, |
2287 | bool add_to_table) | |
2288 | { | |
2289 | unsigned int regno = DF_REF_REGNO (this_ref); | |
2290 | /* Add the ref to the reg_{def,use,eq_use} chain. */ | |
ed6e85ae | 2291 | df_ref head = reg_info->reg_chain; |
3072d30e | 2292 | |
2293 | reg_info->reg_chain = this_ref; | |
2294 | reg_info->n_refs++; | |
2295 | ||
2296 | if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE)) | |
2297 | { | |
2298 | gcc_assert (regno < FIRST_PSEUDO_REGISTER); | |
2299 | df->hard_regs_live_count[regno]++; | |
2300 | } | |
2301 | ||
0ea2d350 | 2302 | gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL |
2303 | && DF_REF_PREV_REG (this_ref) == NULL); | |
3072d30e | 2304 | |
2305 | DF_REF_NEXT_REG (this_ref) = head; | |
2306 | ||
2307 | /* We cannot actually link to the head of the chain. */ | |
2308 | DF_REF_PREV_REG (this_ref) = NULL; | |
2309 | ||
2310 | if (head) | |
2311 | DF_REF_PREV_REG (head) = this_ref; | |
48e1416a | 2312 | |
3072d30e | 2313 | if (add_to_table) |
2314 | { | |
2315 | gcc_assert (ref_info->ref_order != DF_REF_ORDER_NO_TABLE); | |
2316 | df_check_and_grow_ref_info (ref_info, 1); | |
2317 | DF_REF_ID (this_ref) = ref_info->table_size; | |
2318 | /* Add the ref to the big array of defs. */ | |
2319 | ref_info->refs[ref_info->table_size] = this_ref; | |
2320 | ref_info->table_size++; | |
48e1416a | 2321 | } |
3072d30e | 2322 | else |
2323 | DF_REF_ID (this_ref) = -1; | |
48e1416a | 2324 | |
3072d30e | 2325 | ref_info->total_size++; |
2326 | } | |
2327 | ||
2328 | ||
2329 | /* This function takes one of the groups of refs (defs, uses or | |
2330 | eq_uses) and installs the entire group into the insn. It also adds | |
2331 | each of these refs into the appropriate chains. */ | |
2332 | ||
ddc2d0e3 | 2333 | static df_ref |
3072d30e | 2334 | df_install_refs (basic_block bb, |
d70aebca | 2335 | const vec<df_ref, va_heap> *old_vec, |
48e1416a | 2336 | struct df_reg_info **reg_info, |
3072d30e | 2337 | struct df_ref_info *ref_info, |
2338 | bool is_notes) | |
2339 | { | |
d70aebca | 2340 | unsigned int count = old_vec->length (); |
3072d30e | 2341 | if (count) |
2342 | { | |
3072d30e | 2343 | bool add_to_table; |
f7f05a07 | 2344 | df_ref this_ref; |
2345 | unsigned int ix; | |
3072d30e | 2346 | |
2347 | switch (ref_info->ref_order) | |
2348 | { | |
2349 | case DF_REF_ORDER_UNORDERED_WITH_NOTES: | |
2350 | case DF_REF_ORDER_BY_REG_WITH_NOTES: | |
2351 | case DF_REF_ORDER_BY_INSN_WITH_NOTES: | |
2352 | ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES; | |
2353 | add_to_table = true; | |
2354 | break; | |
2355 | case DF_REF_ORDER_UNORDERED: | |
2356 | case DF_REF_ORDER_BY_REG: | |
2357 | case DF_REF_ORDER_BY_INSN: | |
2358 | ref_info->ref_order = DF_REF_ORDER_UNORDERED; | |
2359 | add_to_table = !is_notes; | |
2360 | break; | |
2361 | default: | |
2362 | add_to_table = false; | |
2363 | break; | |
2364 | } | |
2365 | ||
2366 | /* Do not add if ref is not in the right blocks. */ | |
2367 | if (add_to_table && df->analyze_subset) | |
2368 | add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index); | |
2369 | ||
d70aebca | 2370 | FOR_EACH_VEC_ELT (*old_vec, ix, this_ref) |
3072d30e | 2371 | { |
ddc2d0e3 | 2372 | DF_REF_NEXT_LOC (this_ref) = (ix + 1 < old_vec->length () |
2373 | ? (*old_vec)[ix + 1] | |
2374 | : NULL); | |
48e1416a | 2375 | df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)], |
3072d30e | 2376 | ref_info, add_to_table); |
2377 | } | |
ddc2d0e3 | 2378 | return (*old_vec)[0]; |
3072d30e | 2379 | } |
2380 | else | |
ddc2d0e3 | 2381 | return 0; |
3072d30e | 2382 | } |
2383 | ||
2384 | ||
2385 | /* This function takes the mws installs the entire group into the | |
2386 | insn. */ | |
2387 | ||
ddc2d0e3 | 2388 | static struct df_mw_hardreg * |
04009ada | 2389 | df_install_mws (const vec<df_mw_hardreg *, va_heap> *old_vec) |
3072d30e | 2390 | { |
d70aebca | 2391 | unsigned int count = old_vec->length (); |
3072d30e | 2392 | if (count) |
2393 | { | |
ddc2d0e3 | 2394 | for (unsigned int i = 0; i < count - 1; i++) |
2395 | DF_MWS_NEXT ((*old_vec)[i]) = (*old_vec)[i + 1]; | |
2396 | DF_MWS_NEXT ((*old_vec)[count - 1]) = 0; | |
2397 | return (*old_vec)[0]; | |
3072d30e | 2398 | } |
2399 | else | |
ddc2d0e3 | 2400 | return 0; |
3072d30e | 2401 | } |
2402 | ||
2403 | ||
2404 | /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info | |
2405 | chains and update other necessary information. */ | |
2406 | ||
2407 | static void | |
2e966e2a | 2408 | df_refs_add_to_chains (class df_collection_rec *collection_rec, |
e149ca56 | 2409 | basic_block bb, rtx_insn *insn, unsigned int flags) |
3072d30e | 2410 | { |
2411 | if (insn) | |
2412 | { | |
158b6cc9 | 2413 | struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn); |
3072d30e | 2414 | /* If there is a vector in the collection rec, add it to the |
2415 | insn. A null rec is a signal that the caller will handle the | |
2416 | chain specially. */ | |
d70aebca | 2417 | if (flags & copy_defs) |
3072d30e | 2418 | { |
ddc2d0e3 | 2419 | gcc_checking_assert (!insn_rec->defs); |
48e1416a | 2420 | insn_rec->defs |
d70aebca | 2421 | = df_install_refs (bb, &collection_rec->def_vec, |
3072d30e | 2422 | df->def_regs, |
2423 | &df->def_info, false); | |
2424 | } | |
d70aebca | 2425 | if (flags & copy_uses) |
3072d30e | 2426 | { |
ddc2d0e3 | 2427 | gcc_checking_assert (!insn_rec->uses); |
48e1416a | 2428 | insn_rec->uses |
d70aebca | 2429 | = df_install_refs (bb, &collection_rec->use_vec, |
3072d30e | 2430 | df->use_regs, |
2431 | &df->use_info, false); | |
2432 | } | |
d70aebca | 2433 | if (flags & copy_eq_uses) |
3072d30e | 2434 | { |
ddc2d0e3 | 2435 | gcc_checking_assert (!insn_rec->eq_uses); |
48e1416a | 2436 | insn_rec->eq_uses |
d70aebca | 2437 | = df_install_refs (bb, &collection_rec->eq_use_vec, |
3072d30e | 2438 | df->eq_use_regs, |
2439 | &df->use_info, true); | |
2440 | } | |
d70aebca | 2441 | if (flags & copy_mw) |
3072d30e | 2442 | { |
ddc2d0e3 | 2443 | gcc_checking_assert (!insn_rec->mw_hardregs); |
48e1416a | 2444 | insn_rec->mw_hardregs |
d70aebca | 2445 | = df_install_mws (&collection_rec->mw_vec); |
3072d30e | 2446 | } |
2447 | } | |
2448 | else | |
2449 | { | |
2450 | struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index); | |
2451 | ||
ddc2d0e3 | 2452 | gcc_checking_assert (!bb_info->artificial_defs); |
48e1416a | 2453 | bb_info->artificial_defs |
d70aebca | 2454 | = df_install_refs (bb, &collection_rec->def_vec, |
3072d30e | 2455 | df->def_regs, |
2456 | &df->def_info, false); | |
ddc2d0e3 | 2457 | gcc_checking_assert (!bb_info->artificial_uses); |
48e1416a | 2458 | bb_info->artificial_uses |
d70aebca | 2459 | = df_install_refs (bb, &collection_rec->use_vec, |
3072d30e | 2460 | df->use_regs, |
2461 | &df->use_info, false); | |
2462 | } | |
2463 | } | |
e011eba9 | 2464 | |
e011eba9 | 2465 | |
c989ecc1 | 2466 | /* Allocate a ref and initialize its fields. */ |
3072d30e | 2467 | |
48e1416a | 2468 | static df_ref |
2469 | df_ref_create_structure (enum df_ref_class cl, | |
2e966e2a | 2470 | class df_collection_rec *collection_rec, |
48e1416a | 2471 | rtx reg, rtx *loc, |
158b6cc9 | 2472 | basic_block bb, struct df_insn_info *info, |
48e1416a | 2473 | enum df_ref_type ref_type, |
c989ecc1 | 2474 | int ref_flags) |
3072d30e | 2475 | { |
ed6e85ae | 2476 | df_ref this_ref = NULL; |
8c90e956 | 2477 | unsigned int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg); |
3072d30e | 2478 | struct df_scan_problem_data *problem_data |
2479 | = (struct df_scan_problem_data *) df_scan->problem_data; | |
2480 | ||
ed6e85ae | 2481 | switch (cl) |
30de5b55 | 2482 | { |
ed6e85ae | 2483 | case DF_REF_BASE: |
399ea05d | 2484 | this_ref = (df_ref) (problem_data->ref_base_pool->allocate ()); |
0ea2d350 | 2485 | gcc_checking_assert (loc == NULL); |
ed6e85ae | 2486 | break; |
2487 | ||
2488 | case DF_REF_ARTIFICIAL: | |
399ea05d | 2489 | this_ref = (df_ref) (problem_data->ref_artificial_pool->allocate ()); |
ed6e85ae | 2490 | this_ref->artificial_ref.bb = bb; |
0ea2d350 | 2491 | gcc_checking_assert (loc == NULL); |
ed6e85ae | 2492 | break; |
2493 | ||
2494 | case DF_REF_REGULAR: | |
399ea05d | 2495 | this_ref = (df_ref) (problem_data->ref_regular_pool->allocate ()); |
ed6e85ae | 2496 | this_ref->regular_ref.loc = loc; |
0ea2d350 | 2497 | gcc_checking_assert (loc); |
ed6e85ae | 2498 | break; |
30de5b55 | 2499 | } |
ed6e85ae | 2500 | |
2501 | DF_REF_CLASS (this_ref) = cl; | |
3072d30e | 2502 | DF_REF_ID (this_ref) = -1; |
2503 | DF_REF_REG (this_ref) = reg; | |
2504 | DF_REF_REGNO (this_ref) = regno; | |
ed6e85ae | 2505 | DF_REF_TYPE (this_ref) = ref_type; |
158b6cc9 | 2506 | DF_REF_INSN_INFO (this_ref) = info; |
3072d30e | 2507 | DF_REF_CHAIN (this_ref) = NULL; |
3072d30e | 2508 | DF_REF_FLAGS (this_ref) = ref_flags; |
3072d30e | 2509 | DF_REF_NEXT_REG (this_ref) = NULL; |
2510 | DF_REF_PREV_REG (this_ref) = NULL; | |
2511 | DF_REF_ORDER (this_ref) = df->ref_order++; | |
2512 | ||
2513 | /* We need to clear this bit because fwprop, and in the future | |
2514 | possibly other optimizations sometimes create new refs using ond | |
2515 | refs as the model. */ | |
2516 | DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE); | |
2517 | ||
2518 | /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */ | |
5df3e7ea | 2519 | if (regno < FIRST_PSEUDO_REGISTER |
2520 | && !DF_REF_IS_ARTIFICIAL (this_ref) | |
2521 | && !DEBUG_INSN_P (DF_REF_INSN (this_ref))) | |
3072d30e | 2522 | { |
ed6e85ae | 2523 | if (DF_REF_REG_DEF_P (this_ref)) |
3072d30e | 2524 | { |
2525 | if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER)) | |
2526 | DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE); | |
2527 | } | |
2528 | else if (!(TEST_HARD_REG_BIT (elim_reg_set, regno) | |
2529 | && (regno == FRAME_POINTER_REGNUM | |
2530 | || regno == ARG_POINTER_REGNUM))) | |
2531 | DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE); | |
2532 | } | |
2533 | ||
2534 | if (collection_rec) | |
2535 | { | |
ed6e85ae | 2536 | if (DF_REF_REG_DEF_P (this_ref)) |
f1f41a6c | 2537 | collection_rec->def_vec.safe_push (this_ref); |
3072d30e | 2538 | else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE) |
f1f41a6c | 2539 | collection_rec->eq_use_vec.safe_push (this_ref); |
3072d30e | 2540 | else |
f1f41a6c | 2541 | collection_rec->use_vec.safe_push (this_ref); |
e011eba9 | 2542 | } |
4ffe0526 | 2543 | else |
2544 | df_install_ref_incremental (this_ref); | |
3072d30e | 2545 | |
e011eba9 | 2546 | return this_ref; |
2547 | } | |
2548 | ||
2549 | ||
2550 | /* Create new references of type DF_REF_TYPE for each part of register REG | |
c989ecc1 | 2551 | at address LOC within INSN of BB. */ |
30de5b55 | 2552 | |
e011eba9 | 2553 | |
2554 | static void | |
48e1416a | 2555 | df_ref_record (enum df_ref_class cl, |
2e966e2a | 2556 | class df_collection_rec *collection_rec, |
48e1416a | 2557 | rtx reg, rtx *loc, |
158b6cc9 | 2558 | basic_block bb, struct df_insn_info *insn_info, |
48e1416a | 2559 | enum df_ref_type ref_type, |
c989ecc1 | 2560 | int ref_flags) |
e011eba9 | 2561 | { |
3e6933a8 | 2562 | unsigned int regno; |
e011eba9 | 2563 | |
0ea2d350 | 2564 | gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG); |
e011eba9 | 2565 | |
e011eba9 | 2566 | regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg); |
2567 | if (regno < FIRST_PSEUDO_REGISTER) | |
2568 | { | |
3e6933a8 | 2569 | struct df_mw_hardreg *hardreg = NULL; |
2570 | struct df_scan_problem_data *problem_data | |
3072d30e | 2571 | = (struct df_scan_problem_data *) df_scan->problem_data; |
2572 | unsigned int i; | |
2573 | unsigned int endregno; | |
ed6e85ae | 2574 | df_ref ref; |
e011eba9 | 2575 | |
e011eba9 | 2576 | if (GET_CODE (reg) == SUBREG) |
fe2ebfc8 | 2577 | { |
2578 | regno += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)), | |
2579 | SUBREG_BYTE (reg), GET_MODE (reg)); | |
a2c6f0b7 | 2580 | endregno = regno + subreg_nregs (reg); |
fe2ebfc8 | 2581 | } |
2582 | else | |
788bed51 | 2583 | endregno = END_REGNO (reg); |
e011eba9 | 2584 | |
3072d30e | 2585 | /* If this is a multiword hardreg, we create some extra |
2586 | datastructures that will enable us to easily build REG_DEAD | |
2587 | and REG_UNUSED notes. */ | |
4ffe0526 | 2588 | if (collection_rec |
2589 | && (endregno != regno + 1) && insn_info) | |
3e6933a8 | 2590 | { |
48e1416a | 2591 | /* Sets to a subreg of a multiword register are partial. |
3e6933a8 | 2592 | Sets to a non-subreg of a multiword register are not. */ |
05beda33 | 2593 | if (GET_CODE (reg) == SUBREG) |
3e6933a8 | 2594 | ref_flags |= DF_REF_PARTIAL; |
2595 | ref_flags |= DF_REF_MW_HARDREG; | |
3072d30e | 2596 | |
399ea05d | 2597 | hardreg = problem_data->mw_reg_pool->allocate (); |
3e6933a8 | 2598 | hardreg->type = ref_type; |
2599 | hardreg->flags = ref_flags; | |
2600 | hardreg->mw_reg = reg; | |
3072d30e | 2601 | hardreg->start_regno = regno; |
2602 | hardreg->end_regno = endregno - 1; | |
2603 | hardreg->mw_order = df->ref_order++; | |
f1f41a6c | 2604 | collection_rec->mw_vec.safe_push (hardreg); |
3e6933a8 | 2605 | } |
2606 | ||
e011eba9 | 2607 | for (i = regno; i < endregno; i++) |
2608 | { | |
48e1416a | 2609 | ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc, |
c989ecc1 | 2610 | bb, insn_info, ref_type, ref_flags); |
3e6933a8 | 2611 | |
3072d30e | 2612 | gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i); |
e011eba9 | 2613 | } |
2614 | } | |
2615 | else | |
2616 | { | |
48e1416a | 2617 | df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info, |
c989ecc1 | 2618 | ref_type, ref_flags); |
e011eba9 | 2619 | } |
2620 | } | |
2621 | ||
2622 | ||
f7583c76 | 2623 | /* Process all the registers defined in the rtx pointed by LOC. |
2624 | Autoincrement/decrement definitions will be picked up by df_uses_record. | |
2625 | Any change here has to be matched in df_find_hard_reg_defs_1. */ | |
e011eba9 | 2626 | |
2627 | static void | |
2e966e2a | 2628 | df_def_record_1 (class df_collection_rec *collection_rec, |
f7583c76 | 2629 | rtx *loc, basic_block bb, struct df_insn_info *insn_info, |
b9c74b4d | 2630 | int flags) |
e011eba9 | 2631 | { |
f7583c76 | 2632 | rtx dst = *loc; |
e011eba9 | 2633 | |
35792caf | 2634 | /* It is legal to have a set destination be a parallel. */ |
2635 | if (GET_CODE (dst) == PARALLEL) | |
e011eba9 | 2636 | { |
2637 | int i; | |
e011eba9 | 2638 | for (i = XVECLEN (dst, 0) - 1; i >= 0; i--) |
2639 | { | |
2640 | rtx temp = XVECEXP (dst, 0, i); | |
f7583c76 | 2641 | gcc_assert (GET_CODE (temp) == EXPR_LIST); |
2642 | df_def_record_1 (collection_rec, &XEXP (temp, 0), | |
2643 | bb, insn_info, flags); | |
e011eba9 | 2644 | } |
2645 | return; | |
2646 | } | |
2647 | ||
30de5b55 | 2648 | if (GET_CODE (dst) == STRICT_LOW_PART) |
e011eba9 | 2649 | { |
30de5b55 | 2650 | flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART; |
2651 | ||
2652 | loc = &XEXP (dst, 0); | |
2653 | dst = *loc; | |
2654 | } | |
2655 | ||
2656 | if (GET_CODE (dst) == ZERO_EXTRACT) | |
2657 | { | |
2658 | flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT; | |
48e1416a | 2659 | |
e011eba9 | 2660 | loc = &XEXP (dst, 0); |
2661 | dst = *loc; | |
e011eba9 | 2662 | } |
2663 | ||
dea7b504 | 2664 | /* At this point if we do not have a reg or a subreg, just return. */ |
2665 | if (REG_P (dst)) | |
2666 | { | |
c989ecc1 | 2667 | df_ref_record (DF_REF_REGULAR, collection_rec, |
2668 | dst, loc, bb, insn_info, DF_REF_REG_DEF, flags); | |
dea7b504 | 2669 | |
2670 | /* We want to keep sp alive everywhere - by making all | |
2671 | writes to sp also use of sp. */ | |
2672 | if (REGNO (dst) == STACK_POINTER_REGNUM) | |
ed6e85ae | 2673 | df_ref_record (DF_REF_BASE, collection_rec, |
c989ecc1 | 2674 | dst, NULL, bb, insn_info, DF_REF_REG_USE, flags); |
dea7b504 | 2675 | } |
2676 | else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst))) | |
2677 | { | |
5a462df3 | 2678 | if (read_modify_subreg_p (dst)) |
dea7b504 | 2679 | flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL; |
c9a4672f | 2680 | |
dea7b504 | 2681 | flags |= DF_REF_SUBREG; |
37ad3318 | 2682 | |
c989ecc1 | 2683 | df_ref_record (DF_REF_REGULAR, collection_rec, |
2684 | dst, loc, bb, insn_info, DF_REF_REG_DEF, flags); | |
dea7b504 | 2685 | } |
e011eba9 | 2686 | } |
2687 | ||
2688 | ||
f7583c76 | 2689 | /* Process all the registers defined in the pattern rtx, X. Any change |
2690 | here has to be matched in df_find_hard_reg_defs. */ | |
e011eba9 | 2691 | |
2692 | static void | |
2e966e2a | 2693 | df_defs_record (class df_collection_rec *collection_rec, |
158b6cc9 | 2694 | rtx x, basic_block bb, struct df_insn_info *insn_info, |
b9c74b4d | 2695 | int flags) |
e011eba9 | 2696 | { |
2697 | RTX_CODE code = GET_CODE (x); | |
f7583c76 | 2698 | int i; |
e011eba9 | 2699 | |
f7583c76 | 2700 | switch (code) |
e011eba9 | 2701 | { |
f7583c76 | 2702 | case SET: |
2703 | df_def_record_1 (collection_rec, &SET_DEST (x), bb, insn_info, flags); | |
2704 | break; | |
2705 | ||
2706 | case CLOBBER: | |
2707 | flags |= DF_REF_MUST_CLOBBER; | |
2708 | df_def_record_1 (collection_rec, &XEXP (x, 0), bb, insn_info, flags); | |
2709 | break; | |
2710 | ||
2711 | case COND_EXEC: | |
48e1416a | 2712 | df_defs_record (collection_rec, COND_EXEC_CODE (x), |
158b6cc9 | 2713 | bb, insn_info, DF_REF_CONDITIONAL); |
f7583c76 | 2714 | break; |
2715 | ||
2716 | case PARALLEL: | |
2717 | for (i = 0; i < XVECLEN (x, 0); i++) | |
2718 | df_defs_record (collection_rec, XVECEXP (x, 0, i), | |
2719 | bb, insn_info, flags); | |
2720 | break; | |
2721 | default: | |
2722 | /* No DEFs to record in other cases */ | |
2723 | break; | |
e011eba9 | 2724 | } |
f7583c76 | 2725 | } |
2726 | ||
2727 | /* Set bits in *DEFS for hard registers found in the rtx DST, which is the | |
2728 | destination of a set or clobber. This has to match the logic in | |
2729 | df_defs_record_1. */ | |
2730 | ||
2731 | static void | |
2732 | df_find_hard_reg_defs_1 (rtx dst, HARD_REG_SET *defs) | |
2733 | { | |
2734 | /* It is legal to have a set destination be a parallel. */ | |
2735 | if (GET_CODE (dst) == PARALLEL) | |
e011eba9 | 2736 | { |
2737 | int i; | |
f7583c76 | 2738 | for (i = XVECLEN (dst, 0) - 1; i >= 0; i--) |
2739 | { | |
2740 | rtx temp = XVECEXP (dst, 0, i); | |
2741 | gcc_assert (GET_CODE (temp) == EXPR_LIST); | |
2742 | df_find_hard_reg_defs_1 (XEXP (temp, 0), defs); | |
2743 | } | |
2744 | return; | |
2745 | } | |
2746 | ||
2747 | if (GET_CODE (dst) == STRICT_LOW_PART) | |
2748 | dst = XEXP (dst, 0); | |
2749 | ||
2750 | if (GET_CODE (dst) == ZERO_EXTRACT) | |
2751 | dst = XEXP (dst, 0); | |
2752 | ||
2753 | /* At this point if we do not have a reg or a subreg, just return. */ | |
2754 | if (REG_P (dst) && HARD_REGISTER_P (dst)) | |
2755 | SET_HARD_REG_BIT (*defs, REGNO (dst)); | |
2756 | else if (GET_CODE (dst) == SUBREG | |
2757 | && REG_P (SUBREG_REG (dst)) && HARD_REGISTER_P (dst)) | |
2758 | SET_HARD_REG_BIT (*defs, REGNO (SUBREG_REG (dst))); | |
2759 | } | |
2760 | ||
2761 | /* Set bits in *DEFS for hard registers defined in the pattern X. This | |
2762 | has to match the logic in df_defs_record. */ | |
e011eba9 | 2763 | |
f7583c76 | 2764 | static void |
2765 | df_find_hard_reg_defs (rtx x, HARD_REG_SET *defs) | |
2766 | { | |
2767 | RTX_CODE code = GET_CODE (x); | |
2768 | int i; | |
2769 | ||
2770 | switch (code) | |
2771 | { | |
2772 | case SET: | |
2773 | df_find_hard_reg_defs_1 (SET_DEST (x), defs); | |
2774 | break; | |
2775 | ||
2776 | case CLOBBER: | |
70bdfe23 | 2777 | case CLOBBER_HIGH: |
f7583c76 | 2778 | df_find_hard_reg_defs_1 (XEXP (x, 0), defs); |
2779 | break; | |
2780 | ||
2781 | case COND_EXEC: | |
2782 | df_find_hard_reg_defs (COND_EXEC_CODE (x), defs); | |
2783 | break; | |
2784 | ||
2785 | case PARALLEL: | |
2786 | for (i = 0; i < XVECLEN (x, 0); i++) | |
2787 | df_find_hard_reg_defs (XVECEXP (x, 0, i), defs); | |
2788 | break; | |
2789 | default: | |
2790 | /* No DEFs to record in other cases */ | |
2791 | break; | |
e011eba9 | 2792 | } |
2793 | } | |
2794 | ||
2795 | ||
c989ecc1 | 2796 | /* Process all the registers used in the rtx at address LOC. */ |
e011eba9 | 2797 | |
2798 | static void | |
2e966e2a | 2799 | df_uses_record (class df_collection_rec *collection_rec, |
3072d30e | 2800 | rtx *loc, enum df_ref_type ref_type, |
158b6cc9 | 2801 | basic_block bb, struct df_insn_info *insn_info, |
c989ecc1 | 2802 | int flags) |
e011eba9 | 2803 | { |
2804 | RTX_CODE code; | |
2805 | rtx x; | |
3072d30e | 2806 | |
e011eba9 | 2807 | retry: |
2808 | x = *loc; | |
2809 | if (!x) | |
2810 | return; | |
2811 | code = GET_CODE (x); | |
2812 | switch (code) | |
2813 | { | |
2814 | case LABEL_REF: | |
2815 | case SYMBOL_REF: | |
e011eba9 | 2816 | case CONST: |
0349edce | 2817 | CASE_CONST_ANY: |
e011eba9 | 2818 | case PC: |
2819 | case CC0: | |
2820 | case ADDR_VEC: | |
2821 | case ADDR_DIFF_VEC: | |
2822 | return; | |
2823 | ||
2824 | case CLOBBER: | |
2825 | /* If we are clobbering a MEM, mark any registers inside the address | |
2826 | as being used. */ | |
2827 | if (MEM_P (XEXP (x, 0))) | |
c989ecc1 | 2828 | df_uses_record (collection_rec, |
3072d30e | 2829 | &XEXP (XEXP (x, 0), 0), |
158b6cc9 | 2830 | DF_REF_REG_MEM_STORE, |
2831 | bb, insn_info, | |
c989ecc1 | 2832 | flags); |
e011eba9 | 2833 | |
2834 | /* If we're clobbering a REG then we have a def so ignore. */ | |
2835 | return; | |
2836 | ||
70bdfe23 | 2837 | case CLOBBER_HIGH: |
2838 | gcc_assert (REG_P (XEXP (x, 0))); | |
2839 | return; | |
2840 | ||
e011eba9 | 2841 | case MEM: |
c989ecc1 | 2842 | df_uses_record (collection_rec, |
48e1416a | 2843 | &XEXP (x, 0), DF_REF_REG_MEM_LOAD, |
c989ecc1 | 2844 | bb, insn_info, flags & DF_REF_IN_NOTE); |
e011eba9 | 2845 | return; |
2846 | ||
2847 | case SUBREG: | |
2848 | /* While we're here, optimize this case. */ | |
3e6933a8 | 2849 | flags |= DF_REF_PARTIAL; |
e011eba9 | 2850 | /* In case the SUBREG is not of a REG, do not optimize. */ |
2851 | if (!REG_P (SUBREG_REG (x))) | |
2852 | { | |
2853 | loc = &SUBREG_REG (x); | |
c989ecc1 | 2854 | df_uses_record (collection_rec, loc, ref_type, bb, insn_info, flags); |
e011eba9 | 2855 | return; |
2856 | } | |
e3533433 | 2857 | /* Fall through */ |
e011eba9 | 2858 | |
2859 | case REG: | |
c989ecc1 | 2860 | df_ref_record (DF_REF_REGULAR, collection_rec, |
158b6cc9 | 2861 | x, loc, bb, insn_info, |
c989ecc1 | 2862 | ref_type, flags); |
e011eba9 | 2863 | return; |
2864 | ||
30de5b55 | 2865 | case SIGN_EXTRACT: |
2866 | case ZERO_EXTRACT: | |
2867 | { | |
c989ecc1 | 2868 | df_uses_record (collection_rec, |
2869 | &XEXP (x, 1), ref_type, bb, insn_info, flags); | |
2870 | df_uses_record (collection_rec, | |
2871 | &XEXP (x, 2), ref_type, bb, insn_info, flags); | |
2872 | ||
2873 | /* If the parameters to the zero or sign extract are | |
2874 | constants, strip them off and recurse, otherwise there is | |
2875 | no information that we can gain from this operation. */ | |
2876 | if (code == ZERO_EXTRACT) | |
2877 | flags |= DF_REF_ZERO_EXTRACT; | |
2878 | else | |
2879 | flags |= DF_REF_SIGN_EXTRACT; | |
2880 | ||
2881 | df_uses_record (collection_rec, | |
2882 | &XEXP (x, 0), ref_type, bb, insn_info, flags); | |
2883 | return; | |
30de5b55 | 2884 | } |
2885 | break; | |
2886 | ||
e011eba9 | 2887 | case SET: |
2888 | { | |
2889 | rtx dst = SET_DEST (x); | |
2890 | gcc_assert (!(flags & DF_REF_IN_NOTE)); | |
c989ecc1 | 2891 | df_uses_record (collection_rec, |
2892 | &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags); | |
e011eba9 | 2893 | |
2894 | switch (GET_CODE (dst)) | |
2895 | { | |
2896 | case SUBREG: | |
5a462df3 | 2897 | if (read_modify_subreg_p (dst)) |
e011eba9 | 2898 | { |
c989ecc1 | 2899 | df_uses_record (collection_rec, &SUBREG_REG (dst), |
48e1416a | 2900 | DF_REF_REG_USE, bb, insn_info, |
c989ecc1 | 2901 | flags | DF_REF_READ_WRITE | DF_REF_SUBREG); |
e011eba9 | 2902 | break; |
2903 | } | |
2904 | /* Fall through. */ | |
2905 | case REG: | |
2906 | case PARALLEL: | |
2907 | case SCRATCH: | |
2908 | case PC: | |
2909 | case CC0: | |
2910 | break; | |
2911 | case MEM: | |
c989ecc1 | 2912 | df_uses_record (collection_rec, &XEXP (dst, 0), |
2913 | DF_REF_REG_MEM_STORE, bb, insn_info, flags); | |
e011eba9 | 2914 | break; |
2915 | case STRICT_LOW_PART: | |
2916 | { | |
2917 | rtx *temp = &XEXP (dst, 0); | |
2918 | /* A strict_low_part uses the whole REG and not just the | |
2919 | SUBREG. */ | |
2920 | dst = XEXP (dst, 0); | |
c989ecc1 | 2921 | df_uses_record (collection_rec, |
48e1416a | 2922 | (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp, |
158b6cc9 | 2923 | DF_REF_REG_USE, bb, insn_info, |
c989ecc1 | 2924 | DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART); |
e011eba9 | 2925 | } |
2926 | break; | |
2927 | case ZERO_EXTRACT: | |
30de5b55 | 2928 | { |
c989ecc1 | 2929 | df_uses_record (collection_rec, &XEXP (dst, 1), |
2930 | DF_REF_REG_USE, bb, insn_info, flags); | |
2931 | df_uses_record (collection_rec, &XEXP (dst, 2), | |
2932 | DF_REF_REG_USE, bb, insn_info, flags); | |
2933 | if (GET_CODE (XEXP (dst,0)) == MEM) | |
2934 | df_uses_record (collection_rec, &XEXP (dst, 0), | |
2935 | DF_REF_REG_USE, bb, insn_info, | |
2936 | flags); | |
2937 | else | |
2938 | df_uses_record (collection_rec, &XEXP (dst, 0), | |
2939 | DF_REF_REG_USE, bb, insn_info, | |
2940 | DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT); | |
30de5b55 | 2941 | } |
e011eba9 | 2942 | break; |
30de5b55 | 2943 | |
e011eba9 | 2944 | default: |
2945 | gcc_unreachable (); | |
2946 | } | |
2947 | return; | |
2948 | } | |
2949 | ||
2950 | case RETURN: | |
9cb2517e | 2951 | case SIMPLE_RETURN: |
e011eba9 | 2952 | break; |
2953 | ||
2954 | case ASM_OPERANDS: | |
2955 | case UNSPEC_VOLATILE: | |
2956 | case TRAP_IF: | |
2957 | case ASM_INPUT: | |
2958 | { | |
2959 | /* Traditional and volatile asm instructions must be | |
2960 | considered to use and clobber all hard registers, all | |
2961 | pseudo-registers and all of memory. So must TRAP_IF and | |
2962 | UNSPEC_VOLATILE operations. | |
2963 | ||
2964 | Consider for instance a volatile asm that changes the fpu | |
2965 | rounding mode. An insn should not be moved across this | |
2966 | even if it only uses pseudo-regs because it might give an | |
2967 | incorrectly rounded result. | |
2968 | ||
2969 | However, flow.c's liveness computation did *not* do this, | |
2970 | giving the reasoning as " ?!? Unfortunately, marking all | |
2971 | hard registers as live causes massive problems for the | |
2972 | register allocator and marking all pseudos as live creates | |
2973 | mountains of uninitialized variable warnings." | |
2974 | ||
2975 | In order to maintain the status quo with regard to liveness | |
2976 | and uses, we do what flow.c did and just mark any regs we | |
3072d30e | 2977 | can find in ASM_OPERANDS as used. In global asm insns are |
2978 | scanned and regs_asm_clobbered is filled out. | |
e011eba9 | 2979 | |
2980 | For all ASM_OPERANDS, we must traverse the vector of input | |
f4d3c071 | 2981 | operands. We cannot just fall through here since then we |
e011eba9 | 2982 | would be confused by the ASM_INPUT rtx inside ASM_OPERANDS, |
2983 | which do not indicate traditional asms unlike their normal | |
2984 | usage. */ | |
2985 | if (code == ASM_OPERANDS) | |
2986 | { | |
2987 | int j; | |
2988 | ||
2989 | for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++) | |
c989ecc1 | 2990 | df_uses_record (collection_rec, &ASM_OPERANDS_INPUT (x, j), |
2991 | DF_REF_REG_USE, bb, insn_info, flags); | |
e011eba9 | 2992 | return; |
2993 | } | |
2994 | break; | |
2995 | } | |
2996 | ||
9845d120 | 2997 | case VAR_LOCATION: |
c989ecc1 | 2998 | df_uses_record (collection_rec, |
9845d120 | 2999 | &PAT_VAR_LOCATION_LOC (x), |
c989ecc1 | 3000 | DF_REF_REG_USE, bb, insn_info, flags); |
9845d120 | 3001 | return; |
3002 | ||
e011eba9 | 3003 | case PRE_DEC: |
3004 | case POST_DEC: | |
3005 | case PRE_INC: | |
3006 | case POST_INC: | |
3007 | case PRE_MODIFY: | |
3008 | case POST_MODIFY: | |
9845d120 | 3009 | gcc_assert (!DEBUG_INSN_P (insn_info->insn)); |
e011eba9 | 3010 | /* Catch the def of the register being modified. */ |
c989ecc1 | 3011 | df_ref_record (DF_REF_REGULAR, collection_rec, XEXP (x, 0), &XEXP (x, 0), |
48e1416a | 3012 | bb, insn_info, |
7577c7f7 | 3013 | DF_REF_REG_DEF, |
c989ecc1 | 3014 | flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY); |
e011eba9 | 3015 | |
3016 | /* ... Fall through to handle uses ... */ | |
3017 | ||
3018 | default: | |
3019 | break; | |
3020 | } | |
3021 | ||
3022 | /* Recursively scan the operands of this expression. */ | |
3023 | { | |
3024 | const char *fmt = GET_RTX_FORMAT (code); | |
3025 | int i; | |
3026 | ||
3027 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
3028 | { | |
3029 | if (fmt[i] == 'e') | |
3030 | { | |
3031 | /* Tail recursive case: save a function call level. */ | |
3032 | if (i == 0) | |
3033 | { | |
3034 | loc = &XEXP (x, 0); | |
3035 | goto retry; | |
3036 | } | |
c989ecc1 | 3037 | df_uses_record (collection_rec, &XEXP (x, i), ref_type, |
3038 | bb, insn_info, flags); | |
e011eba9 | 3039 | } |
3040 | else if (fmt[i] == 'E') | |
3041 | { | |
3042 | int j; | |
3043 | for (j = 0; j < XVECLEN (x, i); j++) | |
c989ecc1 | 3044 | df_uses_record (collection_rec, |
48e1416a | 3045 | &XVECEXP (x, i, j), ref_type, |
c989ecc1 | 3046 | bb, insn_info, flags); |
e011eba9 | 3047 | } |
3048 | } | |
3049 | } | |
e011eba9 | 3050 | |
3072d30e | 3051 | return; |
e011eba9 | 3052 | } |
3053 | ||
3054 | ||
3072d30e | 3055 | /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */ |
e011eba9 | 3056 | |
3072d30e | 3057 | static void |
2e966e2a | 3058 | df_get_conditional_uses (class df_collection_rec *collection_rec) |
e011eba9 | 3059 | { |
f7f05a07 | 3060 | unsigned int ix; |
3061 | df_ref ref; | |
3062 | ||
f1f41a6c | 3063 | FOR_EACH_VEC_ELT (collection_rec->def_vec, ix, ref) |
3072d30e | 3064 | { |
3072d30e | 3065 | if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL)) |
3066 | { | |
ed6e85ae | 3067 | df_ref use; |
30de5b55 | 3068 | |
ed6e85ae | 3069 | use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref), |
30de5b55 | 3070 | DF_REF_LOC (ref), DF_REF_BB (ref), |
158b6cc9 | 3071 | DF_REF_INSN_INFO (ref), DF_REF_REG_USE, |
c989ecc1 | 3072 | DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL); |
3072d30e | 3073 | DF_REF_REGNO (use) = DF_REF_REGNO (ref); |
3074 | } | |
3075 | } | |
e011eba9 | 3076 | } |
3077 | ||
3078 | ||
f7583c76 | 3079 | /* Get call's extra defs and uses (track caller-saved registers). */ |
e011eba9 | 3080 | |
3081 | static void | |
2e966e2a | 3082 | df_get_call_refs (class df_collection_rec *collection_rec, |
48e1416a | 3083 | basic_block bb, |
158b6cc9 | 3084 | struct df_insn_info *insn_info, |
b9c74b4d | 3085 | int flags) |
e011eba9 | 3086 | { |
3072d30e | 3087 | rtx note; |
3072d30e | 3088 | bool is_sibling_call; |
3089 | unsigned int i; | |
f7583c76 | 3090 | HARD_REG_SET defs_generated; |
754158d9 | 3091 | HARD_REG_SET fn_reg_set_usage; |
4b5a4301 | 3092 | |
f7583c76 | 3093 | CLEAR_HARD_REG_SET (defs_generated); |
3094 | df_find_hard_reg_defs (PATTERN (insn_info->insn), &defs_generated); | |
3095 | is_sibling_call = SIBLING_CALL_P (insn_info->insn); | |
754158d9 | 3096 | get_call_reg_set_usage (insn_info->insn, &fn_reg_set_usage, |
3097 | regs_invalidated_by_call); | |
e011eba9 | 3098 | |
f7583c76 | 3099 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
3100 | { | |
3101 | if (i == STACK_POINTER_REGNUM) | |
3102 | /* The stack ptr is used (honorarily) by a CALL insn. */ | |
3103 | df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], | |
3104 | NULL, bb, insn_info, DF_REF_REG_USE, | |
3105 | DF_REF_CALL_STACK_USAGE | flags); | |
3106 | else if (global_regs[i]) | |
3107 | { | |
3108 | /* Calls to const functions cannot access any global registers and | |
3109 | calls to pure functions cannot set them. All other calls may | |
3110 | reference any of the global registers, so they are recorded as | |
3111 | used. */ | |
3112 | if (!RTL_CONST_CALL_P (insn_info->insn)) | |
3113 | { | |
3114 | df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], | |
3115 | NULL, bb, insn_info, DF_REF_REG_USE, flags); | |
3116 | if (!RTL_PURE_CALL_P (insn_info->insn)) | |
3117 | df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], | |
3118 | NULL, bb, insn_info, DF_REF_REG_DEF, flags); | |
3119 | } | |
3120 | } | |
754158d9 | 3121 | else if (TEST_HARD_REG_BIT (fn_reg_set_usage, i) |
f7583c76 | 3122 | /* no clobbers for regs that are the result of the call */ |
3123 | && !TEST_HARD_REG_BIT (defs_generated, i) | |
3124 | && (!is_sibling_call | |
3125 | || !bitmap_bit_p (df->exit_block_uses, i) | |
2ec77a7c | 3126 | || refers_to_regno_p (i, crtl->return_rtx))) |
f7583c76 | 3127 | df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], |
3128 | NULL, bb, insn_info, DF_REF_REG_DEF, | |
3129 | DF_REF_MAY_CLOBBER | flags); | |
3130 | } | |
e011eba9 | 3131 | |
3072d30e | 3132 | /* Record the registers used to pass arguments, and explicitly |
3133 | noted as clobbered. */ | |
158b6cc9 | 3134 | for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note; |
3072d30e | 3135 | note = XEXP (note, 1)) |
3136 | { | |
70bdfe23 | 3137 | gcc_assert (GET_CODE (XEXP (note, 0)) != CLOBBER_HIGH); |
3072d30e | 3138 | if (GET_CODE (XEXP (note, 0)) == USE) |
c989ecc1 | 3139 | df_uses_record (collection_rec, &XEXP (XEXP (note, 0), 0), |
3140 | DF_REF_REG_USE, bb, insn_info, flags); | |
3072d30e | 3141 | else if (GET_CODE (XEXP (note, 0)) == CLOBBER) |
3142 | { | |
5736c998 | 3143 | if (REG_P (XEXP (XEXP (note, 0), 0))) |
3144 | { | |
3145 | unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0)); | |
f7583c76 | 3146 | if (!TEST_HARD_REG_BIT (defs_generated, regno)) |
5736c998 | 3147 | df_defs_record (collection_rec, XEXP (note, 0), bb, |
158b6cc9 | 3148 | insn_info, flags); |
5736c998 | 3149 | } |
3150 | else | |
c989ecc1 | 3151 | df_uses_record (collection_rec, &XEXP (note, 0), |
3152 | DF_REF_REG_USE, bb, insn_info, flags); | |
3072d30e | 3153 | } |
3154 | } | |
e011eba9 | 3155 | |
3072d30e | 3156 | return; |
3157 | } | |
e011eba9 | 3158 | |
3072d30e | 3159 | /* Collect all refs in the INSN. This function is free of any |
3160 | side-effect - it will create and return a lists of df_ref's in the | |
3161 | COLLECTION_REC without putting those refs into existing ref chains | |
3162 | and reg chains. */ | |
e011eba9 | 3163 | |
3072d30e | 3164 | static void |
2e966e2a | 3165 | df_insn_refs_collect (class df_collection_rec *collection_rec, |
48e1416a | 3166 | basic_block bb, struct df_insn_info *insn_info) |
3072d30e | 3167 | { |
3168 | rtx note; | |
158b6cc9 | 3169 | bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC); |
e011eba9 | 3170 | |
3072d30e | 3171 | /* Clear out the collection record. */ |
f1f41a6c | 3172 | collection_rec->def_vec.truncate (0); |
3173 | collection_rec->use_vec.truncate (0); | |
3174 | collection_rec->eq_use_vec.truncate (0); | |
3175 | collection_rec->mw_vec.truncate (0); | |
e011eba9 | 3176 | |
158b6cc9 | 3177 | /* Process REG_EQUIV/REG_EQUAL notes. */ |
3178 | for (note = REG_NOTES (insn_info->insn); note; | |
3072d30e | 3179 | note = XEXP (note, 1)) |
3180 | { | |
3181 | switch (REG_NOTE_KIND (note)) | |
3182 | { | |
3183 | case REG_EQUIV: | |
3184 | case REG_EQUAL: | |
c989ecc1 | 3185 | df_uses_record (collection_rec, |
3072d30e | 3186 | &XEXP (note, 0), DF_REF_REG_USE, |
c989ecc1 | 3187 | bb, insn_info, DF_REF_IN_NOTE); |
3072d30e | 3188 | break; |
3189 | case REG_NON_LOCAL_GOTO: | |
3190 | /* The frame ptr is used by a non-local goto. */ | |
ed6e85ae | 3191 | df_ref_record (DF_REF_BASE, collection_rec, |
3072d30e | 3192 | regno_reg_rtx[FRAME_POINTER_REGNUM], |
158b6cc9 | 3193 | NULL, bb, insn_info, |
c989ecc1 | 3194 | DF_REF_REG_USE, 0); |
f703b3d6 | 3195 | if (!HARD_FRAME_POINTER_IS_FRAME_POINTER) |
3196 | df_ref_record (DF_REF_BASE, collection_rec, | |
3197 | regno_reg_rtx[HARD_FRAME_POINTER_REGNUM], | |
3198 | NULL, bb, insn_info, | |
3199 | DF_REF_REG_USE, 0); | |
3072d30e | 3200 | break; |
3201 | default: | |
3202 | break; | |
3203 | } | |
e011eba9 | 3204 | } |
3072d30e | 3205 | |
69105acc | 3206 | int flags = (is_cond_exec) ? DF_REF_CONDITIONAL : 0; |
f7583c76 | 3207 | /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as |
3208 | uses from CALL_INSN_FUNCTION_USAGE. */ | |
158b6cc9 | 3209 | if (CALL_P (insn_info->insn)) |
69105acc | 3210 | df_get_call_refs (collection_rec, bb, insn_info, flags); |
3211 | ||
f7583c76 | 3212 | /* Record other defs. These should be mostly for DF_REF_REGULAR, so |
3213 | that a qsort on the defs is unnecessary in most cases. */ | |
3214 | df_defs_record (collection_rec, | |
3215 | PATTERN (insn_info->insn), bb, insn_info, 0); | |
3216 | ||
3072d30e | 3217 | /* Record the register uses. */ |
c989ecc1 | 3218 | df_uses_record (collection_rec, |
3219 | &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0); | |
3072d30e | 3220 | |
3221 | /* DF_REF_CONDITIONAL needs corresponding USES. */ | |
3222 | if (is_cond_exec) | |
3223 | df_get_conditional_uses (collection_rec); | |
3224 | ||
3225 | df_canonize_collection_rec (collection_rec); | |
e011eba9 | 3226 | } |
3227 | ||
3072d30e | 3228 | /* Recompute the luids for the insns in BB. */ |
3229 | ||
3230 | void | |
3231 | df_recompute_luids (basic_block bb) | |
e011eba9 | 3232 | { |
7a6a083c | 3233 | rtx_insn *insn; |
e011eba9 | 3234 | int luid = 0; |
3e6933a8 | 3235 | |
3072d30e | 3236 | df_grow_insn_info (); |
e011eba9 | 3237 | |
3238 | /* Scan the block an insn at a time from beginning to end. */ | |
3239 | FOR_BB_INSNS (bb, insn) | |
3240 | { | |
158b6cc9 | 3241 | struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); |
3072d30e | 3242 | /* Inserting labels does not always trigger the incremental |
3243 | rescanning. */ | |
3244 | if (!insn_info) | |
e011eba9 | 3245 | { |
3072d30e | 3246 | gcc_assert (!INSN_P (insn)); |
158b6cc9 | 3247 | insn_info = df_insn_create_insn_record (insn); |
e011eba9 | 3248 | } |
3072d30e | 3249 | |
158b6cc9 | 3250 | DF_INSN_INFO_LUID (insn_info) = luid; |
3072d30e | 3251 | if (INSN_P (insn)) |
3252 | luid++; | |
3253 | } | |
3254 | } | |
3255 | ||
3256 | ||
3072d30e | 3257 | /* Collect all artificial refs at the block level for BB and add them |
3258 | to COLLECTION_REC. */ | |
3259 | ||
3260 | static void | |
2e966e2a | 3261 | df_bb_refs_collect (class df_collection_rec *collection_rec, basic_block bb) |
3072d30e | 3262 | { |
f1f41a6c | 3263 | collection_rec->def_vec.truncate (0); |
3264 | collection_rec->use_vec.truncate (0); | |
3265 | collection_rec->eq_use_vec.truncate (0); | |
3266 | collection_rec->mw_vec.truncate (0); | |
3072d30e | 3267 | |
3268 | if (bb->index == ENTRY_BLOCK) | |
3269 | { | |
3270 | df_entry_block_defs_collect (collection_rec, df->entry_block_defs); | |
3271 | return; | |
3272 | } | |
3273 | else if (bb->index == EXIT_BLOCK) | |
3274 | { | |
3275 | df_exit_block_uses_collect (collection_rec, df->exit_block_uses); | |
3276 | return; | |
e011eba9 | 3277 | } |
3278 | ||
dea7b504 | 3279 | if (bb_has_eh_pred (bb)) |
e011eba9 | 3280 | { |
3281 | unsigned int i; | |
3282 | /* Mark the registers that will contain data for the handler. */ | |
fcf2ad9f | 3283 | for (i = 0; ; ++i) |
3284 | { | |
3285 | unsigned regno = EH_RETURN_DATA_REGNO (i); | |
3286 | if (regno == INVALID_REGNUM) | |
3287 | break; | |
ed6e85ae | 3288 | df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL, |
c989ecc1 | 3289 | bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP); |
fcf2ad9f | 3290 | } |
e011eba9 | 3291 | } |
e011eba9 | 3292 | |
3072d30e | 3293 | /* Add the hard_frame_pointer if this block is the target of a |
3294 | non-local goto. */ | |
3295 | if (bb->flags & BB_NON_LOCAL_GOTO_TARGET) | |
ed6e85ae | 3296 | df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL, |
c989ecc1 | 3297 | bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP); |
48e1416a | 3298 | |
3072d30e | 3299 | /* Add the artificial uses. */ |
3300 | if (bb->index >= NUM_FIXED_BLOCKS) | |
3e6933a8 | 3301 | { |
3302 | bitmap_iterator bi; | |
3303 | unsigned int regno; | |
48e1416a | 3304 | bitmap au = bb_has_eh_pred (bb) |
4b5a4301 | 3305 | ? &df->eh_block_artificial_uses |
3306 | : &df->regular_block_artificial_uses; | |
3e6933a8 | 3307 | |
3072d30e | 3308 | EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi) |
3e6933a8 | 3309 | { |
ed6e85ae | 3310 | df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL, |
c989ecc1 | 3311 | bb, NULL, DF_REF_REG_USE, 0); |
3e6933a8 | 3312 | } |
e011eba9 | 3313 | } |
3072d30e | 3314 | |
3315 | df_canonize_collection_rec (collection_rec); | |
e011eba9 | 3316 | } |
3317 | ||
05268a5f | 3318 | |
3072d30e | 3319 | /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */ |
3320 | ||
3321 | void | |
3322 | df_bb_refs_record (int bb_index, bool scan_insns) | |
05268a5f | 3323 | { |
f5a6b05f | 3324 | basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index); |
7a6a083c | 3325 | rtx_insn *insn; |
3072d30e | 3326 | int luid = 0; |
05268a5f | 3327 | |
3072d30e | 3328 | if (!df) |
05268a5f | 3329 | return; |
3330 | ||
d70aebca | 3331 | df_collection_rec collection_rec; |
369ea98d | 3332 | df_grow_bb_info (df_scan); |
3072d30e | 3333 | if (scan_insns) |
3334 | /* Scan the block an insn at a time from beginning to end. */ | |
3335 | FOR_BB_INSNS (bb, insn) | |
3336 | { | |
158b6cc9 | 3337 | struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); |
3072d30e | 3338 | gcc_assert (!insn_info); |
3339 | ||
158b6cc9 | 3340 | insn_info = df_insn_create_insn_record (insn); |
3072d30e | 3341 | if (INSN_P (insn)) |
3342 | { | |
3343 | /* Record refs within INSN. */ | |
158b6cc9 | 3344 | DF_INSN_INFO_LUID (insn_info) = luid++; |
3345 | df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn)); | |
d70aebca | 3346 | df_refs_add_to_chains (&collection_rec, bb, insn, copy_all); |
3072d30e | 3347 | } |
158b6cc9 | 3348 | DF_INSN_INFO_LUID (insn_info) = luid; |
3072d30e | 3349 | } |
3350 | ||
3351 | /* Other block level artificial refs */ | |
3352 | df_bb_refs_collect (&collection_rec, bb); | |
d70aebca | 3353 | df_refs_add_to_chains (&collection_rec, bb, NULL, copy_all); |
f7f05a07 | 3354 | |
3072d30e | 3355 | /* Now that the block has been processed, set the block as dirty so |
84da8954 | 3356 | LR and LIVE will get it processed. */ |
3072d30e | 3357 | df_set_bb_dirty (bb); |
05268a5f | 3358 | } |
e011eba9 | 3359 | |
3072d30e | 3360 | |
3361 | /* Get the artificial use set for a regular (i.e. non-exit/non-entry) | |
3362 | block. */ | |
e011eba9 | 3363 | |
3364 | static void | |
3072d30e | 3365 | df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses) |
e011eba9 | 3366 | { |
f7039b33 | 3367 | #ifdef EH_USES |
3368 | unsigned int i; | |
3369 | #endif | |
3370 | ||
3072d30e | 3371 | bitmap_clear (regular_block_artificial_uses); |
e011eba9 | 3372 | |
3072d30e | 3373 | if (reload_completed) |
e011eba9 | 3374 | { |
3072d30e | 3375 | if (frame_pointer_needed) |
3376 | bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM); | |
3377 | } | |
3378 | else | |
3379 | /* Before reload, there are a few registers that must be forced | |
3380 | live everywhere -- which might not already be the case for | |
3381 | blocks within infinite loops. */ | |
3382 | { | |
89bc53e2 | 3383 | unsigned int picreg = PIC_OFFSET_TABLE_REGNUM; |
3384 | ||
3072d30e | 3385 | /* Any reference to any pseudo before reload is a potential |
3386 | reference of the frame pointer. */ | |
3387 | bitmap_set_bit (regular_block_artificial_uses, FRAME_POINTER_REGNUM); | |
48e1416a | 3388 | |
f703b3d6 | 3389 | if (!HARD_FRAME_POINTER_IS_FRAME_POINTER) |
3390 | bitmap_set_bit (regular_block_artificial_uses, | |
3391 | HARD_FRAME_POINTER_REGNUM); | |
3072d30e | 3392 | |
3072d30e | 3393 | /* Pseudos with argument area equivalences may require |
3394 | reloading via the argument pointer. */ | |
c6bb296a | 3395 | if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
3396 | && fixed_regs[ARG_POINTER_REGNUM]) | |
3072d30e | 3397 | bitmap_set_bit (regular_block_artificial_uses, ARG_POINTER_REGNUM); |
48e1416a | 3398 | |
3072d30e | 3399 | /* Any constant, or pseudo with constant equivalences, may |
3400 | require reloading from memory using the pic register. */ | |
89bc53e2 | 3401 | if (picreg != INVALID_REGNUM |
3402 | && fixed_regs[picreg]) | |
3403 | bitmap_set_bit (regular_block_artificial_uses, picreg); | |
e011eba9 | 3404 | } |
3072d30e | 3405 | /* The all-important stack pointer must always be live. */ |
3406 | bitmap_set_bit (regular_block_artificial_uses, STACK_POINTER_REGNUM); | |
f7039b33 | 3407 | |
3408 | #ifdef EH_USES | |
3409 | /* EH_USES registers are used: | |
3410 | 1) at all insns that might throw (calls or with -fnon-call-exceptions | |
3411 | trapping insns) | |
3412 | 2) in all EH edges | |
3413 | 3) to support backtraces and/or debugging, anywhere between their | |
3414 | initialization and where they the saved registers are restored | |
3415 | from them, including the cases where we don't reach the epilogue | |
3416 | (noreturn call or infinite loop). */ | |
3417 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
3418 | if (EH_USES (i)) | |
3419 | bitmap_set_bit (regular_block_artificial_uses, i); | |
3420 | #endif | |
3072d30e | 3421 | } |
3422 | ||
e011eba9 | 3423 | |
3072d30e | 3424 | /* Get the artificial use set for an eh block. */ |
fcf2ad9f | 3425 | |
3072d30e | 3426 | static void |
3427 | df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses) | |
3428 | { | |
3429 | bitmap_clear (eh_block_artificial_uses); | |
05268a5f | 3430 | |
9d75589a | 3431 | /* The following code (down through the arg_pointer setting APPEARS |
3072d30e | 3432 | to be necessary because there is nothing that actually |
3433 | describes what the exception handling code may actually need | |
3434 | to keep alive. */ | |
3435 | if (reload_completed) | |
3436 | { | |
3437 | if (frame_pointer_needed) | |
3438 | { | |
3439 | bitmap_set_bit (eh_block_artificial_uses, FRAME_POINTER_REGNUM); | |
f703b3d6 | 3440 | if (!HARD_FRAME_POINTER_IS_FRAME_POINTER) |
3441 | bitmap_set_bit (eh_block_artificial_uses, | |
3442 | HARD_FRAME_POINTER_REGNUM); | |
3072d30e | 3443 | } |
c6bb296a | 3444 | if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
3445 | && fixed_regs[ARG_POINTER_REGNUM]) | |
3072d30e | 3446 | bitmap_set_bit (eh_block_artificial_uses, ARG_POINTER_REGNUM); |
3072d30e | 3447 | } |
e011eba9 | 3448 | } |
3449 | ||
3450 | ||
3072d30e | 3451 | \f |
e011eba9 | 3452 | /*---------------------------------------------------------------------------- |
3453 | Specialized hard register scanning functions. | |
3454 | ----------------------------------------------------------------------------*/ | |
3455 | ||
3072d30e | 3456 | |
e011eba9 | 3457 | /* Mark a register in SET. Hard registers in large modes get all |
3458 | of their component registers set as well. */ | |
3459 | ||
3460 | static void | |
3461 | df_mark_reg (rtx reg, void *vset) | |
3462 | { | |
837d3ea8 | 3463 | bitmap_set_range ((bitmap) vset, REGNO (reg), REG_NREGS (reg)); |
e011eba9 | 3464 | } |
3465 | ||
fcf2ad9f | 3466 | |
3072d30e | 3467 | /* Set the bit for regs that are considered being defined at the entry. */ |
fcf2ad9f | 3468 | |
3469 | static void | |
3072d30e | 3470 | df_get_entry_block_def_set (bitmap entry_block_defs) |
fcf2ad9f | 3471 | { |
fcf2ad9f | 3472 | rtx r; |
3072d30e | 3473 | int i; |
fcf2ad9f | 3474 | |
3072d30e | 3475 | bitmap_clear (entry_block_defs); |
fcf2ad9f | 3476 | |
b06532c2 | 3477 | /* For separate shrink-wrapping we use LIVE to analyze which basic blocks |
3478 | need a prologue for some component to be executed before that block, | |
3479 | and we do not care about any other registers. Hence, we do not want | |
3480 | any register for any component defined in the entry block, and we can | |
3481 | just leave all registers undefined. */ | |
3482 | if (df_scan->local_flags & DF_SCAN_EMPTY_ENTRY_EXIT) | |
3483 | return; | |
3484 | ||
fcf2ad9f | 3485 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
925e8609 | 3486 | { |
3487 | if (global_regs[i]) | |
3488 | bitmap_set_bit (entry_block_defs, i); | |
3489 | if (FUNCTION_ARG_REGNO_P (i)) | |
3490 | bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i)); | |
3491 | } | |
48e1416a | 3492 | |
df4fadd5 | 3493 | /* The always important stack pointer. */ |
3494 | bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM); | |
3495 | ||
fcf2ad9f | 3496 | /* Once the prologue has been generated, all of these registers |
3497 | should just show up in the first regular block. */ | |
cf3a33c8 | 3498 | if (targetm.have_prologue () && epilogue_completed) |
fcf2ad9f | 3499 | { |
3500 | /* Defs for the callee saved registers are inserted so that the | |
3501 | pushes have some defining location. */ | |
3502 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
3072d30e | 3503 | if ((call_used_regs[i] == 0) && (df_regs_ever_live_p (i))) |
3504 | bitmap_set_bit (entry_block_defs, i); | |
fcf2ad9f | 3505 | } |
fcf2ad9f | 3506 | |
652ff291 | 3507 | r = targetm.calls.struct_value_rtx (current_function_decl, true); |
3508 | if (r && REG_P (r)) | |
3509 | bitmap_set_bit (entry_block_defs, REGNO (r)); | |
3510 | ||
82c7907c | 3511 | /* If the function has an incoming STATIC_CHAIN, it has to show up |
3512 | in the entry def set. */ | |
3c56e0c1 | 3513 | r = rtx_for_static_chain (current_function_decl, true); |
82c7907c | 3514 | if (r && REG_P (r)) |
3515 | bitmap_set_bit (entry_block_defs, REGNO (r)); | |
3516 | ||
3e6933a8 | 3517 | if ((!reload_completed) || frame_pointer_needed) |
fcf2ad9f | 3518 | { |
3519 | /* Any reference to any pseudo before reload is a potential | |
3520 | reference of the frame pointer. */ | |
3072d30e | 3521 | bitmap_set_bit (entry_block_defs, FRAME_POINTER_REGNUM); |
f703b3d6 | 3522 | |
3e6933a8 | 3523 | /* If they are different, also mark the hard frame pointer as live. */ |
f703b3d6 | 3524 | if (!HARD_FRAME_POINTER_IS_FRAME_POINTER |
3525 | && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM)) | |
3072d30e | 3526 | bitmap_set_bit (entry_block_defs, HARD_FRAME_POINTER_REGNUM); |
3e6933a8 | 3527 | } |
fcf2ad9f | 3528 | |
3e6933a8 | 3529 | /* These registers are live everywhere. */ |
3530 | if (!reload_completed) | |
3531 | { | |
fcf2ad9f | 3532 | /* Pseudos with argument area equivalences may require |
3533 | reloading via the argument pointer. */ | |
c6bb296a | 3534 | if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
3535 | && fixed_regs[ARG_POINTER_REGNUM]) | |
3072d30e | 3536 | bitmap_set_bit (entry_block_defs, ARG_POINTER_REGNUM); |
48e1416a | 3537 | |
fcf2ad9f | 3538 | /* Any constant, or pseudo with constant equivalences, may |
3539 | require reloading from memory using the pic register. */ | |
099a99b5 | 3540 | unsigned int picreg = PIC_OFFSET_TABLE_REGNUM; |
89bc53e2 | 3541 | if (picreg != INVALID_REGNUM |
3542 | && fixed_regs[picreg]) | |
3543 | bitmap_set_bit (entry_block_defs, picreg); | |
3072d30e | 3544 | } |
3545 | ||
3546 | #ifdef INCOMING_RETURN_ADDR_RTX | |
3547 | if (REG_P (INCOMING_RETURN_ADDR_RTX)) | |
3548 | bitmap_set_bit (entry_block_defs, REGNO (INCOMING_RETURN_ADDR_RTX)); | |
3549 | #endif | |
48e1416a | 3550 | |
202d6e5f | 3551 | targetm.extra_live_on_entry (entry_block_defs); |
3072d30e | 3552 | } |
3553 | ||
3554 | ||
3555 | /* Return the (conservative) set of hard registers that are defined on | |
48e1416a | 3556 | entry to the function. |
3557 | It uses df->entry_block_defs to determine which register | |
3072d30e | 3558 | reference to include. */ |
3559 | ||
3560 | static void | |
2e966e2a | 3561 | df_entry_block_defs_collect (class df_collection_rec *collection_rec, |
3072d30e | 3562 | bitmap entry_block_defs) |
3563 | { | |
48e1416a | 3564 | unsigned int i; |
3072d30e | 3565 | bitmap_iterator bi; |
3566 | ||
3567 | EXECUTE_IF_SET_IN_BITMAP (entry_block_defs, 0, i, bi) | |
3568 | { | |
48e1416a | 3569 | df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL, |
34154e27 | 3570 | ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_DEF, 0); |
3072d30e | 3571 | } |
3572 | ||
3573 | df_canonize_collection_rec (collection_rec); | |
3574 | } | |
3575 | ||
3576 | ||
3577 | /* Record the (conservative) set of hard registers that are defined on | |
3578 | entry to the function. */ | |
3579 | ||
3580 | static void | |
3581 | df_record_entry_block_defs (bitmap entry_block_defs) | |
3582 | { | |
2e966e2a | 3583 | class df_collection_rec collection_rec; |
3072d30e | 3584 | df_entry_block_defs_collect (&collection_rec, entry_block_defs); |
3585 | ||
3586 | /* Process bb_refs chain */ | |
f5a6b05f | 3587 | df_refs_add_to_chains (&collection_rec, |
3588 | BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK), | |
3589 | NULL, | |
d70aebca | 3590 | copy_defs); |
3072d30e | 3591 | } |
3592 | ||
3593 | ||
becfaa62 | 3594 | /* Update the defs in the entry block. */ |
3072d30e | 3595 | |
3596 | void | |
3597 | df_update_entry_block_defs (void) | |
3598 | { | |
3072d30e | 3599 | bool changed = false; |
fcf2ad9f | 3600 | |
f6708c36 | 3601 | auto_bitmap refs (&df_bitmap_obstack); |
3602 | df_get_entry_block_def_set (refs); | |
3a405082 | 3603 | gcc_assert (df->entry_block_defs); |
3604 | if (!bitmap_equal_p (df->entry_block_defs, refs)) | |
3072d30e | 3605 | { |
3a405082 | 3606 | struct df_scan_bb_info *bb_info = df_scan_get_bb_info (ENTRY_BLOCK); |
3607 | df_ref_chain_delete_du_chain (bb_info->artificial_defs); | |
3608 | df_ref_chain_delete (bb_info->artificial_defs); | |
3609 | bb_info->artificial_defs = NULL; | |
3072d30e | 3610 | changed = true; |
3611 | } | |
fcf2ad9f | 3612 | |
3072d30e | 3613 | if (changed) |
fcf2ad9f | 3614 | { |
f6708c36 | 3615 | df_record_entry_block_defs (refs); |
3616 | bitmap_copy (df->entry_block_defs, refs); | |
f5a6b05f | 3617 | df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK)); |
fcf2ad9f | 3618 | } |
3619 | } | |
3620 | ||
3621 | ||
3072d30e | 3622 | /* Set the bit for regs that are considered being used at the exit. */ |
e011eba9 | 3623 | |
3624 | static void | |
3072d30e | 3625 | df_get_exit_block_use_set (bitmap exit_block_uses) |
e011eba9 | 3626 | { |
48e1416a | 3627 | unsigned int i; |
89bc53e2 | 3628 | unsigned int picreg = PIC_OFFSET_TABLE_REGNUM; |
e011eba9 | 3629 | |
3072d30e | 3630 | bitmap_clear (exit_block_uses); |
bff9eb26 | 3631 | |
b06532c2 | 3632 | /* For separate shrink-wrapping we use LIVE to analyze which basic blocks |
3633 | need an epilogue for some component to be executed after that block, | |
3634 | and we do not care about any other registers. Hence, we do not want | |
3635 | any register for any component seen as used in the exit block, and we | |
3636 | can just say no registers at all are used. */ | |
3637 | if (df_scan->local_flags & DF_SCAN_EMPTY_ENTRY_EXIT) | |
3638 | return; | |
3639 | ||
bff9eb26 | 3640 | /* Stack pointer is always live at the exit. */ |
3641 | bitmap_set_bit (exit_block_uses, STACK_POINTER_REGNUM); | |
48e1416a | 3642 | |
e011eba9 | 3643 | /* Mark the frame pointer if needed at the end of the function. |
3644 | If we end up eliminating it, it will be removed from the live | |
3645 | list of each basic block by reload. */ | |
48e1416a | 3646 | |
3e6933a8 | 3647 | if ((!reload_completed) || frame_pointer_needed) |
e011eba9 | 3648 | { |
3072d30e | 3649 | bitmap_set_bit (exit_block_uses, FRAME_POINTER_REGNUM); |
f703b3d6 | 3650 | |
e011eba9 | 3651 | /* If they are different, also mark the hard frame pointer as live. */ |
f703b3d6 | 3652 | if (!HARD_FRAME_POINTER_IS_FRAME_POINTER |
3653 | && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM)) | |
3072d30e | 3654 | bitmap_set_bit (exit_block_uses, HARD_FRAME_POINTER_REGNUM); |
e011eba9 | 3655 | } |
3656 | ||
e011eba9 | 3657 | /* Many architectures have a GP register even without flag_pic. |
3658 | Assume the pic register is not in use, or will be handled by | |
3659 | other means, if it is not fixed. */ | |
260e669e | 3660 | if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED |
89bc53e2 | 3661 | && picreg != INVALID_REGNUM |
3662 | && fixed_regs[picreg]) | |
3663 | bitmap_set_bit (exit_block_uses, picreg); | |
48e1416a | 3664 | |
e011eba9 | 3665 | /* Mark all global registers, and all registers used by the |
3666 | epilogue as being live at the end of the function since they | |
3667 | may be referenced by our caller. */ | |
3668 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
3669 | if (global_regs[i] || EPILOGUE_USES (i)) | |
3072d30e | 3670 | bitmap_set_bit (exit_block_uses, i); |
48e1416a | 3671 | |
cf3a33c8 | 3672 | if (targetm.have_epilogue () && epilogue_completed) |
e011eba9 | 3673 | { |
3674 | /* Mark all call-saved registers that we actually used. */ | |
3675 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
3072d30e | 3676 | if (df_regs_ever_live_p (i) && !LOCAL_REGNO (i) |
3e6933a8 | 3677 | && !TEST_HARD_REG_BIT (regs_invalidated_by_call, i)) |
3072d30e | 3678 | bitmap_set_bit (exit_block_uses, i); |
e011eba9 | 3679 | } |
48e1416a | 3680 | |
e011eba9 | 3681 | /* Mark the registers that will contain data for the handler. */ |
18d50ae6 | 3682 | if (reload_completed && crtl->calls_eh_return) |
e011eba9 | 3683 | for (i = 0; ; ++i) |
3684 | { | |
3685 | unsigned regno = EH_RETURN_DATA_REGNO (i); | |
3686 | if (regno == INVALID_REGNUM) | |
3687 | break; | |
3072d30e | 3688 | bitmap_set_bit (exit_block_uses, regno); |
e011eba9 | 3689 | } |
e011eba9 | 3690 | |
3691 | #ifdef EH_RETURN_STACKADJ_RTX | |
cf3a33c8 | 3692 | if ((!targetm.have_epilogue () || ! epilogue_completed) |
18d50ae6 | 3693 | && crtl->calls_eh_return) |
e011eba9 | 3694 | { |
3695 | rtx tmp = EH_RETURN_STACKADJ_RTX; | |
3696 | if (tmp && REG_P (tmp)) | |
3072d30e | 3697 | df_mark_reg (tmp, exit_block_uses); |
e011eba9 | 3698 | } |
3699 | #endif | |
3700 | ||
cf3a33c8 | 3701 | if ((!targetm.have_epilogue () || ! epilogue_completed) |
18d50ae6 | 3702 | && crtl->calls_eh_return) |
e011eba9 | 3703 | { |
3704 | rtx tmp = EH_RETURN_HANDLER_RTX; | |
3705 | if (tmp && REG_P (tmp)) | |
3072d30e | 3706 | df_mark_reg (tmp, exit_block_uses); |
e011eba9 | 3707 | } |
3072d30e | 3708 | |
e011eba9 | 3709 | /* Mark function return value. */ |
3072d30e | 3710 | diddle_return_value (df_mark_reg, (void*) exit_block_uses); |
3711 | } | |
3712 | ||
3713 | ||
48e1416a | 3714 | /* Return the refs of hard registers that are used in the exit block. |
3072d30e | 3715 | It uses df->exit_block_uses to determine register to include. */ |
3716 | ||
3717 | static void | |
2e966e2a | 3718 | df_exit_block_uses_collect (class df_collection_rec *collection_rec, bitmap exit_block_uses) |
3072d30e | 3719 | { |
48e1416a | 3720 | unsigned int i; |
3072d30e | 3721 | bitmap_iterator bi; |
3722 | ||
3723 | EXECUTE_IF_SET_IN_BITMAP (exit_block_uses, 0, i, bi) | |
ed6e85ae | 3724 | df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL, |
34154e27 | 3725 | EXIT_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_USE, 0); |
e011eba9 | 3726 | |
3072d30e | 3727 | /* It is deliberate that this is not put in the exit block uses but |
3728 | I do not know why. */ | |
c6bb296a | 3729 | if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
3730 | && reload_completed | |
3072d30e | 3731 | && !bitmap_bit_p (exit_block_uses, ARG_POINTER_REGNUM) |
34154e27 | 3732 | && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun)) |
3072d30e | 3733 | && fixed_regs[ARG_POINTER_REGNUM]) |
ed6e85ae | 3734 | df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[ARG_POINTER_REGNUM], NULL, |
34154e27 | 3735 | EXIT_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_USE, 0); |
3072d30e | 3736 | |
3737 | df_canonize_collection_rec (collection_rec); | |
3738 | } | |
3739 | ||
3740 | ||
48e1416a | 3741 | /* Record the set of hard registers that are used in the exit block. |
3072d30e | 3742 | It uses df->exit_block_uses to determine which bit to include. */ |
3743 | ||
3744 | static void | |
3745 | df_record_exit_block_uses (bitmap exit_block_uses) | |
3746 | { | |
2e966e2a | 3747 | class df_collection_rec collection_rec; |
3072d30e | 3748 | df_exit_block_uses_collect (&collection_rec, exit_block_uses); |
3749 | ||
3750 | /* Process bb_refs chain */ | |
f5a6b05f | 3751 | df_refs_add_to_chains (&collection_rec, |
3752 | BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK), | |
3753 | NULL, | |
d70aebca | 3754 | copy_uses); |
3072d30e | 3755 | } |
3756 | ||
3757 | ||
3758 | /* Update the uses in the exit block. */ | |
3759 | ||
3760 | void | |
3761 | df_update_exit_block_uses (void) | |
3762 | { | |
3072d30e | 3763 | bool changed = false; |
3764 | ||
f6708c36 | 3765 | auto_bitmap refs (&df_bitmap_obstack); |
3766 | df_get_exit_block_use_set (refs); | |
3a405082 | 3767 | gcc_assert (df->exit_block_uses); |
3768 | if (!bitmap_equal_p (df->exit_block_uses, refs)) | |
3072d30e | 3769 | { |
3a405082 | 3770 | struct df_scan_bb_info *bb_info = df_scan_get_bb_info (EXIT_BLOCK); |
3771 | df_ref_chain_delete_du_chain (bb_info->artificial_uses); | |
3772 | df_ref_chain_delete (bb_info->artificial_uses); | |
3773 | bb_info->artificial_uses = NULL; | |
3072d30e | 3774 | changed = true; |
3775 | } | |
3776 | ||
3777 | if (changed) | |
3778 | { | |
f6708c36 | 3779 | df_record_exit_block_uses (refs); |
3780 | bitmap_copy (df->exit_block_uses, refs); | |
f5a6b05f | 3781 | df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK)); |
3072d30e | 3782 | } |
e011eba9 | 3783 | } |
3784 | ||
3785 | static bool initialized = false; | |
3786 | ||
3072d30e | 3787 | |
e011eba9 | 3788 | /* Initialize some platform specific structures. */ |
3789 | ||
48e1416a | 3790 | void |
e011eba9 | 3791 | df_hard_reg_init (void) |
3792 | { | |
f9a42947 | 3793 | int i; |
e011eba9 | 3794 | static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS; |
acbc95ac | 3795 | |
e011eba9 | 3796 | if (initialized) |
3797 | return; | |
3798 | ||
e011eba9 | 3799 | /* Record which registers will be eliminated. We use this in |
3800 | mark_used_regs. */ | |
3801 | CLEAR_HARD_REG_SET (elim_reg_set); | |
48e1416a | 3802 | |
e011eba9 | 3803 | for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++) |
3804 | SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from); | |
48e1416a | 3805 | |
e011eba9 | 3806 | initialized = true; |
3807 | } | |
3072d30e | 3808 | |
3809 | ||
3810 | /* Recompute the parts of scanning that are based on regs_ever_live | |
48e1416a | 3811 | because something changed in that array. */ |
3072d30e | 3812 | |
48e1416a | 3813 | void |
3072d30e | 3814 | df_update_entry_exit_and_calls (void) |
3815 | { | |
3816 | basic_block bb; | |
3817 | ||
3818 | df_update_entry_block_defs (); | |
3819 | df_update_exit_block_uses (); | |
3820 | ||
3821 | /* The call insns need to be rescanned because there may be changes | |
3822 | in the set of registers clobbered across the call. */ | |
fc00614f | 3823 | FOR_EACH_BB_FN (bb, cfun) |
3072d30e | 3824 | { |
7a6a083c | 3825 | rtx_insn *insn; |
3072d30e | 3826 | FOR_BB_INSNS (bb, insn) |
3827 | { | |
3828 | if (INSN_P (insn) && CALL_P (insn)) | |
3829 | df_insn_rescan (insn); | |
3830 | } | |
3831 | } | |
3832 | } | |
3833 | ||
3834 | ||
3835 | /* Return true if hard REG is actually used in the some instruction. | |
3836 | There are a fair number of conditions that affect the setting of | |
3837 | this array. See the comment in df.h for df->hard_regs_live_count | |
3838 | for the conditions that this array is set. */ | |
3839 | ||
48e1416a | 3840 | bool |
3072d30e | 3841 | df_hard_reg_used_p (unsigned int reg) |
3842 | { | |
3072d30e | 3843 | return df->hard_regs_live_count[reg] != 0; |
3844 | } | |
3845 | ||
3846 | ||
3847 | /* A count of the number of times REG is actually used in the some | |
3848 | instruction. There are a fair number of conditions that affect the | |
3849 | setting of this array. See the comment in df.h for | |
3850 | df->hard_regs_live_count for the conditions that this array is | |
3851 | set. */ | |
3852 | ||
3853 | ||
3854 | unsigned int | |
3855 | df_hard_reg_used_count (unsigned int reg) | |
3856 | { | |
3072d30e | 3857 | return df->hard_regs_live_count[reg]; |
3858 | } | |
3859 | ||
3860 | ||
3861 | /* Get the value of regs_ever_live[REGNO]. */ | |
3862 | ||
48e1416a | 3863 | bool |
3072d30e | 3864 | df_regs_ever_live_p (unsigned int regno) |
3865 | { | |
3866 | return regs_ever_live[regno]; | |
3867 | } | |
3868 | ||
3869 | ||
3870 | /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live | |
3871 | to change, schedule that change for the next update. */ | |
3872 | ||
48e1416a | 3873 | void |
3072d30e | 3874 | df_set_regs_ever_live (unsigned int regno, bool value) |
3875 | { | |
3876 | if (regs_ever_live[regno] == value) | |
3877 | return; | |
3878 | ||
3879 | regs_ever_live[regno] = value; | |
3880 | if (df) | |
3881 | df->redo_entry_and_exit = true; | |
3882 | } | |
3883 | ||
3884 | ||
3885 | /* Compute "regs_ever_live" information from the underlying df | |
3886 | information. Set the vector to all false if RESET. */ | |
3887 | ||
3888 | void | |
3889 | df_compute_regs_ever_live (bool reset) | |
3890 | { | |
3891 | unsigned int i; | |
3892 | bool changed = df->redo_entry_and_exit; | |
48e1416a | 3893 | |
3072d30e | 3894 | if (reset) |
3895 | memset (regs_ever_live, 0, sizeof (regs_ever_live)); | |
3896 | ||
3897 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
3898 | if ((!regs_ever_live[i]) && df_hard_reg_used_p (i)) | |
3899 | { | |
3900 | regs_ever_live[i] = true; | |
3901 | changed = true; | |
3902 | } | |
3903 | if (changed) | |
3904 | df_update_entry_exit_and_calls (); | |
3905 | df->redo_entry_and_exit = false; | |
3906 | } | |
3907 | ||
3908 | \f | |
3909 | /*---------------------------------------------------------------------------- | |
3910 | Dataflow ref information verification functions. | |
3911 | ||
3912 | df_reg_chain_mark (refs, regno, is_def, is_eq_use) | |
3913 | df_reg_chain_verify_unmarked (refs) | |
f1f41a6c | 3914 | df_refs_verify (vec<stack, va_df_ref>, ref*, bool) |
3072d30e | 3915 | df_mws_verify (mw*, mw*, bool) |
3916 | df_insn_refs_verify (collection_rec, bb, insn, bool) | |
3917 | df_bb_refs_verify (bb, refs, bool) | |
3918 | df_bb_verify (bb) | |
3919 | df_exit_block_bitmap_verify (bool) | |
3920 | df_entry_block_bitmap_verify (bool) | |
3921 | df_scan_verify () | |
3922 | ----------------------------------------------------------------------------*/ | |
3923 | ||
3924 | ||
3925 | /* Mark all refs in the reg chain. Verify that all of the registers | |
48e1416a | 3926 | are in the correct chain. */ |
3072d30e | 3927 | |
3928 | static unsigned int | |
48e1416a | 3929 | df_reg_chain_mark (df_ref refs, unsigned int regno, |
3072d30e | 3930 | bool is_def, bool is_eq_use) |
3931 | { | |
3932 | unsigned int count = 0; | |
ed6e85ae | 3933 | df_ref ref; |
3072d30e | 3934 | for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref)) |
3935 | { | |
3936 | gcc_assert (!DF_REF_IS_REG_MARKED (ref)); | |
3937 | ||
3938 | /* If there are no def-use or use-def chains, make sure that all | |
3939 | of the chains are clear. */ | |
3940 | if (!df_chain) | |
3941 | gcc_assert (!DF_REF_CHAIN (ref)); | |
3942 | ||
3943 | /* Check to make sure the ref is in the correct chain. */ | |
3944 | gcc_assert (DF_REF_REGNO (ref) == regno); | |
3945 | if (is_def) | |
ed6e85ae | 3946 | gcc_assert (DF_REF_REG_DEF_P (ref)); |
3072d30e | 3947 | else |
ed6e85ae | 3948 | gcc_assert (!DF_REF_REG_DEF_P (ref)); |
3072d30e | 3949 | |
3950 | if (is_eq_use) | |
3951 | gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)); | |
3952 | else | |
3953 | gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) == 0); | |
3954 | ||
ed6e85ae | 3955 | if (DF_REF_NEXT_REG (ref)) |
3956 | gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref)) == ref); | |
3072d30e | 3957 | count++; |
3958 | DF_REF_REG_MARK (ref); | |
3959 | } | |
3960 | return count; | |
3961 | } | |
3962 | ||
3963 | ||
48e1416a | 3964 | /* Verify that all of the registers in the chain are unmarked. */ |
3072d30e | 3965 | |
3966 | static void | |
ed6e85ae | 3967 | df_reg_chain_verify_unmarked (df_ref refs) |
3072d30e | 3968 | { |
ed6e85ae | 3969 | df_ref ref; |
3072d30e | 3970 | for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref)) |
3971 | gcc_assert (!DF_REF_IS_REG_MARKED (ref)); | |
3972 | } | |
3973 | ||
3974 | ||
3975 | /* Verify that NEW_REC and OLD_REC have exactly the same members. */ | |
3976 | ||
3977 | static bool | |
ddc2d0e3 | 3978 | df_refs_verify (const vec<df_ref, va_heap> *new_rec, df_ref old_rec, |
3072d30e | 3979 | bool abort_if_fail) |
3980 | { | |
f7f05a07 | 3981 | unsigned int ix; |
3982 | df_ref new_ref; | |
3983 | ||
d70aebca | 3984 | FOR_EACH_VEC_ELT (*new_rec, ix, new_ref) |
3072d30e | 3985 | { |
ddc2d0e3 | 3986 | if (old_rec == NULL || !df_ref_equal_p (new_ref, old_rec)) |
3072d30e | 3987 | { |
3988 | if (abort_if_fail) | |
3989 | gcc_assert (0); | |
3990 | else | |
3991 | return false; | |
3992 | } | |
3993 | ||
3994 | /* Abort if fail is called from the function level verifier. If | |
3995 | that is the context, mark this reg as being seem. */ | |
3996 | if (abort_if_fail) | |
3997 | { | |
ddc2d0e3 | 3998 | gcc_assert (DF_REF_IS_REG_MARKED (old_rec)); |
3999 | DF_REF_REG_UNMARK (old_rec); | |
3072d30e | 4000 | } |
4001 | ||
ddc2d0e3 | 4002 | old_rec = DF_REF_NEXT_LOC (old_rec); |
3072d30e | 4003 | } |
4004 | ||
4005 | if (abort_if_fail) | |
ddc2d0e3 | 4006 | gcc_assert (old_rec == NULL); |
3072d30e | 4007 | else |
ddc2d0e3 | 4008 | return old_rec == NULL; |
3072d30e | 4009 | return false; |
4010 | } | |
4011 | ||
4012 | ||
4013 | /* Verify that NEW_REC and OLD_REC have exactly the same members. */ | |
4014 | ||
4015 | static bool | |
04009ada | 4016 | df_mws_verify (const vec<df_mw_hardreg *, va_heap> *new_rec, |
ddc2d0e3 | 4017 | struct df_mw_hardreg *old_rec, |
3072d30e | 4018 | bool abort_if_fail) |
4019 | { | |
f7f05a07 | 4020 | unsigned int ix; |
4021 | struct df_mw_hardreg *new_reg; | |
4022 | ||
d70aebca | 4023 | FOR_EACH_VEC_ELT (*new_rec, ix, new_reg) |
3072d30e | 4024 | { |
ddc2d0e3 | 4025 | if (old_rec == NULL || !df_mw_equal_p (new_reg, old_rec)) |
3072d30e | 4026 | { |
4027 | if (abort_if_fail) | |
4028 | gcc_assert (0); | |
4029 | else | |
4030 | return false; | |
4031 | } | |
ddc2d0e3 | 4032 | old_rec = DF_MWS_NEXT (old_rec); |
3072d30e | 4033 | } |
4034 | ||
4035 | if (abort_if_fail) | |
ddc2d0e3 | 4036 | gcc_assert (old_rec == NULL); |
3072d30e | 4037 | else |
ddc2d0e3 | 4038 | return old_rec == NULL; |
3072d30e | 4039 | return false; |
4040 | } | |
4041 | ||
4042 | ||
4043 | /* Return true if the existing insn refs information is complete and | |
4044 | correct. Otherwise (i.e. if there's any missing or extra refs), | |
48e1416a | 4045 | return the correct df_ref chain in REFS_RETURN. |
3072d30e | 4046 | |
4047 | If ABORT_IF_FAIL, leave the refs that are verified (already in the | |
4048 | ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn | |
4049 | verification mode instead of the whole function, so unmark | |
4050 | everything. | |
4051 | ||
4052 | If ABORT_IF_FAIL is set, this function never returns false. */ | |
4053 | ||
4054 | static bool | |
2e966e2a | 4055 | df_insn_refs_verify (class df_collection_rec *collection_rec, |
48e1416a | 4056 | basic_block bb, |
e149ca56 | 4057 | rtx_insn *insn, |
3072d30e | 4058 | bool abort_if_fail) |
4059 | { | |
dc54d0c9 | 4060 | bool ret1, ret2, ret3; |
3072d30e | 4061 | unsigned int uid = INSN_UID (insn); |
158b6cc9 | 4062 | struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); |
3072d30e | 4063 | |
158b6cc9 | 4064 | df_insn_refs_collect (collection_rec, bb, insn_info); |
3072d30e | 4065 | |
3072d30e | 4066 | /* Unfortunately we cannot opt out early if one of these is not |
dc54d0c9 | 4067 | right and abort_if_fail is set because the marks will not get cleared. */ |
d70aebca | 4068 | ret1 = df_refs_verify (&collection_rec->def_vec, DF_INSN_UID_DEFS (uid), |
3072d30e | 4069 | abort_if_fail); |
dc54d0c9 | 4070 | if (!ret1 && !abort_if_fail) |
4071 | return false; | |
d70aebca | 4072 | ret2 = df_refs_verify (&collection_rec->use_vec, DF_INSN_UID_USES (uid), |
3072d30e | 4073 | abort_if_fail); |
dc54d0c9 | 4074 | if (!ret2 && !abort_if_fail) |
4075 | return false; | |
d70aebca | 4076 | ret3 = df_refs_verify (&collection_rec->eq_use_vec, DF_INSN_UID_EQ_USES (uid), |
3072d30e | 4077 | abort_if_fail); |
dc54d0c9 | 4078 | if (!ret3 && !abort_if_fail) |
4079 | return false; | |
4080 | if (! df_mws_verify (&collection_rec->mw_vec, DF_INSN_UID_MWS (uid), | |
4081 | abort_if_fail)) | |
4082 | return false; | |
4083 | return (ret1 && ret2 && ret3); | |
3072d30e | 4084 | } |
4085 | ||
4086 | ||
4087 | /* Return true if all refs in the basic block are correct and complete. | |
4088 | Due to df_ref_chain_verify, it will cause all refs | |
4089 | that are verified to have DF_REF_MARK bit set. */ | |
4090 | ||
4091 | static bool | |
4092 | df_bb_verify (basic_block bb) | |
4093 | { | |
7a6a083c | 4094 | rtx_insn *insn; |
3072d30e | 4095 | struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index); |
2e966e2a | 4096 | class df_collection_rec collection_rec; |
48e1416a | 4097 | |
3072d30e | 4098 | gcc_assert (bb_info); |
4099 | ||
ed6e85ae | 4100 | /* Scan the block, one insn at a time, from beginning to end. */ |
3072d30e | 4101 | FOR_BB_INSNS_REVERSE (bb, insn) |
4102 | { | |
4103 | if (!INSN_P (insn)) | |
4104 | continue; | |
4105 | df_insn_refs_verify (&collection_rec, bb, insn, true); | |
25d2985a | 4106 | df_free_collection_rec (&collection_rec); |
3072d30e | 4107 | } |
4108 | ||
4109 | /* Do the artificial defs and uses. */ | |
4110 | df_bb_refs_collect (&collection_rec, bb); | |
d70aebca | 4111 | df_refs_verify (&collection_rec.def_vec, df_get_artificial_defs (bb->index), true); |
4112 | df_refs_verify (&collection_rec.use_vec, df_get_artificial_uses (bb->index), true); | |
3072d30e | 4113 | df_free_collection_rec (&collection_rec); |
48e1416a | 4114 | |
3072d30e | 4115 | return true; |
4116 | } | |
4117 | ||
4118 | ||
48e1416a | 4119 | /* Returns true if the entry block has correct and complete df_ref set. |
3072d30e | 4120 | If not it either aborts if ABORT_IF_FAIL is true or returns false. */ |
4121 | ||
4122 | static bool | |
4123 | df_entry_block_bitmap_verify (bool abort_if_fail) | |
4124 | { | |
3072d30e | 4125 | bool is_eq; |
4126 | ||
f6708c36 | 4127 | auto_bitmap entry_block_defs (&df_bitmap_obstack); |
4128 | df_get_entry_block_def_set (entry_block_defs); | |
3072d30e | 4129 | |
f6708c36 | 4130 | is_eq = bitmap_equal_p (entry_block_defs, df->entry_block_defs); |
3072d30e | 4131 | |
4132 | if (!is_eq && abort_if_fail) | |
4133 | { | |
3072d30e | 4134 | fprintf (stderr, "entry_block_defs = "); |
f6708c36 | 4135 | df_print_regset (stderr, entry_block_defs); |
3072d30e | 4136 | fprintf (stderr, "df->entry_block_defs = "); |
4137 | df_print_regset (stderr, df->entry_block_defs); | |
4138 | gcc_assert (0); | |
4139 | } | |
4140 | ||
3072d30e | 4141 | return is_eq; |
4142 | } | |
4143 | ||
4144 | ||
48e1416a | 4145 | /* Returns true if the exit block has correct and complete df_ref set. |
3072d30e | 4146 | If not it either aborts if ABORT_IF_FAIL is true or returns false. */ |
4147 | ||
4148 | static bool | |
4149 | df_exit_block_bitmap_verify (bool abort_if_fail) | |
4150 | { | |
3072d30e | 4151 | bool is_eq; |
4152 | ||
f6708c36 | 4153 | auto_bitmap exit_block_uses (&df_bitmap_obstack); |
4154 | df_get_exit_block_use_set (exit_block_uses); | |
3072d30e | 4155 | |
f6708c36 | 4156 | is_eq = bitmap_equal_p (exit_block_uses, df->exit_block_uses); |
3072d30e | 4157 | |
4158 | if (!is_eq && abort_if_fail) | |
4159 | { | |
3072d30e | 4160 | fprintf (stderr, "exit_block_uses = "); |
f6708c36 | 4161 | df_print_regset (stderr, exit_block_uses); |
3072d30e | 4162 | fprintf (stderr, "df->exit_block_uses = "); |
4163 | df_print_regset (stderr, df->exit_block_uses); | |
4164 | gcc_assert (0); | |
4165 | } | |
4166 | ||
3072d30e | 4167 | return is_eq; |
4168 | } | |
4169 | ||
4170 | ||
bf1f8fbc | 4171 | /* Return true if df_ref information for all insns in all blocks are |
4172 | correct and complete. */ | |
3072d30e | 4173 | |
4174 | void | |
4175 | df_scan_verify (void) | |
4176 | { | |
4177 | unsigned int i; | |
4178 | basic_block bb; | |
3072d30e | 4179 | |
4180 | if (!df) | |
4181 | return; | |
4182 | ||
3072d30e | 4183 | /* Verification is a 4 step process. */ |
4184 | ||
9d75589a | 4185 | /* (1) All of the refs are marked by going through the reg chains. */ |
3072d30e | 4186 | for (i = 0; i < DF_REG_SIZE (df); i++) |
4187 | { | |
48e1416a | 4188 | gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false) |
9af5ce0c | 4189 | == DF_REG_DEF_COUNT (i)); |
48e1416a | 4190 | gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i), i, false, false) |
9af5ce0c | 4191 | == DF_REG_USE_COUNT (i)); |
48e1416a | 4192 | gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i), i, false, true) |
9af5ce0c | 4193 | == DF_REG_EQ_USE_COUNT (i)); |
3072d30e | 4194 | } |
4195 | ||
4196 | /* (2) There are various bitmaps whose value may change over the | |
4197 | course of the compilation. This step recomputes them to make | |
4198 | sure that they have not slipped out of date. */ | |
f6708c36 | 4199 | auto_bitmap regular_block_artificial_uses (&df_bitmap_obstack); |
4200 | auto_bitmap eh_block_artificial_uses (&df_bitmap_obstack); | |
3072d30e | 4201 | |
f6708c36 | 4202 | df_get_regular_block_artificial_uses (regular_block_artificial_uses); |
4203 | df_get_eh_block_artificial_uses (eh_block_artificial_uses); | |
3072d30e | 4204 | |
f6708c36 | 4205 | bitmap_ior_into (eh_block_artificial_uses, |
4206 | regular_block_artificial_uses); | |
3072d30e | 4207 | |
4208 | /* Check artificial_uses bitmaps didn't change. */ | |
f6708c36 | 4209 | gcc_assert (bitmap_equal_p (regular_block_artificial_uses, |
4b5a4301 | 4210 | &df->regular_block_artificial_uses)); |
f6708c36 | 4211 | gcc_assert (bitmap_equal_p (eh_block_artificial_uses, |
4b5a4301 | 4212 | &df->eh_block_artificial_uses)); |
3072d30e | 4213 | |
3072d30e | 4214 | /* Verify entry block and exit block. These only verify the bitmaps, |
4215 | the refs are verified in df_bb_verify. */ | |
4216 | df_entry_block_bitmap_verify (true); | |
4217 | df_exit_block_bitmap_verify (true); | |
48e1416a | 4218 | |
3072d30e | 4219 | /* (3) All of the insns in all of the blocks are traversed and the |
4220 | marks are cleared both in the artificial refs attached to the | |
4221 | blocks and the real refs inside the insns. It is a failure to | |
4222 | clear a mark that has not been set as this means that the ref in | |
4223 | the block or insn was not in the reg chain. */ | |
4224 | ||
ed7d889a | 4225 | FOR_ALL_BB_FN (bb, cfun) |
3072d30e | 4226 | df_bb_verify (bb); |
4227 | ||
4228 | /* (4) See if all reg chains are traversed a second time. This time | |
4229 | a check is made that the marks are clear. A set mark would be a | |
4230 | from a reg that is not in any insn or basic block. */ | |
4231 | ||
4232 | for (i = 0; i < DF_REG_SIZE (df); i++) | |
4233 | { | |
4234 | df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i)); | |
4235 | df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i)); | |
4236 | df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i)); | |
4237 | } | |
4238 | } |