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