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