* doc/install.texi (Prerequisites): Refine some wording on
[official-gcc.git] / gcc / df-problems.c
bloba0422f8307b9d303e19bbadfc5f6dfb0d666966d
1 /* Standard problems for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 2, or (at your option) any later
14 version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING. If not, write to the Free
23 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 02110-1301, USA. */
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "rtl.h"
31 #include "tm_p.h"
32 #include "insn-config.h"
33 #include "recog.h"
34 #include "function.h"
35 #include "regs.h"
36 #include "output.h"
37 #include "alloc-pool.h"
38 #include "flags.h"
39 #include "hard-reg-set.h"
40 #include "basic-block.h"
41 #include "sbitmap.h"
42 #include "bitmap.h"
43 #include "timevar.h"
44 #include "df.h"
46 #define DF_SPARSE_THRESHOLD 32
48 static bitmap seen_in_block = NULL;
49 static bitmap seen_in_insn = NULL;
52 /*----------------------------------------------------------------------------
53 Public functions access functions for the dataflow problems.
54 ----------------------------------------------------------------------------*/
56 /* Get the instance of the problem that DFLOW is dependent on. */
58 struct dataflow *
59 df_get_dependent_problem (struct dataflow *dflow)
61 struct df *df = dflow->df;
62 struct df_problem *dependent_problem = dflow->problem->dependent_problem;
64 gcc_assert (dependent_problem);
65 return df->problems_by_index[dependent_problem->id];
69 /* Create a du or ud chain from SRC to DST and link it into SRC. */
71 struct df_link *
72 df_chain_create (struct dataflow *dflow, struct df_ref *src, struct df_ref *dst)
74 struct df_link *head = DF_REF_CHAIN (src);
75 struct df_link *link = pool_alloc (dflow->block_pool);;
77 DF_REF_CHAIN (src) = link;
78 link->next = head;
79 link->ref = dst;
80 return link;
84 /* Delete a du or ud chain for REF. If LINK is NULL, delete all
85 chains for ref and check to see if the reverse chains can also be
86 deleted. If LINK is not NULL it must be a link off of ref. In
87 this case, the other end is not deleted. */
89 void
90 df_chain_unlink (struct dataflow *dflow, struct df_ref *ref, struct df_link *link)
92 struct df_link *chain = DF_REF_CHAIN (ref);
93 if (link)
95 /* Link was the first element in the chain. */
96 if (chain == link)
97 DF_REF_CHAIN (ref) = link->next;
98 else
100 /* Link is an internal element in the chain. */
101 struct df_link *prev = chain;
102 while (chain)
104 if (chain == link)
106 prev->next = chain->next;
107 break;
109 prev = chain;
110 chain = chain->next;
113 pool_free (dflow->block_pool, link);
115 else
117 /* If chain is NULL here, it was because of a recursive call
118 when the other flavor of chains was not built. Just run thru
119 the entire chain calling the other side and then deleting the
120 link. */
121 while (chain)
123 struct df_link *next = chain->next;
124 /* Delete the other side if it exists. */
125 df_chain_unlink (dflow, chain->ref, chain);
126 chain = next;
132 /* Copy the du or ud chain starting at FROM_REF and attach it to
133 TO_REF. */
135 void
136 df_chain_copy (struct dataflow *dflow,
137 struct df_ref *to_ref,
138 struct df_link *from_ref)
140 while (from_ref)
142 df_chain_create (dflow, to_ref, from_ref->ref);
143 from_ref = from_ref->next;
148 /* Get the live in set for BB no matter what problem happens to be
149 defined. */
151 bitmap
152 df_get_live_in (struct df *df, basic_block bb)
154 gcc_assert (df->problems_by_index[DF_LR]);
156 if (df->problems_by_index[DF_UREC])
157 return DF_RA_LIVE_IN (df, bb);
158 else if (df->problems_by_index[DF_UR])
159 return DF_LIVE_IN (df, bb);
160 else
161 return DF_UPWARD_LIVE_IN (df, bb);
165 /* Get the live out set for BB no matter what problem happens to be
166 defined. */
168 bitmap
169 df_get_live_out (struct df *df, basic_block bb)
171 gcc_assert (df->problems_by_index[DF_LR]);
173 if (df->problems_by_index[DF_UREC])
174 return DF_RA_LIVE_OUT (df, bb);
175 else if (df->problems_by_index[DF_UR])
176 return DF_LIVE_OUT (df, bb);
177 else
178 return DF_UPWARD_LIVE_OUT (df, bb);
182 /*----------------------------------------------------------------------------
183 Utility functions.
184 ----------------------------------------------------------------------------*/
186 /* Generic versions to get the void* version of the block info. Only
187 used inside the problem instance vectors. */
189 /* Grow the bb_info array. */
191 void
192 df_grow_bb_info (struct dataflow *dflow)
194 unsigned int new_size = last_basic_block + 1;
195 if (dflow->block_info_size < new_size)
197 new_size += new_size / 4;
198 dflow->block_info = xrealloc (dflow->block_info,
199 new_size *sizeof (void*));
200 memset (dflow->block_info + dflow->block_info_size, 0,
201 (new_size - dflow->block_info_size) *sizeof (void *));
202 dflow->block_info_size = new_size;
206 /* Dump a def-use or use-def chain for REF to FILE. */
208 void
209 df_chain_dump (struct df *df ATTRIBUTE_UNUSED, struct df_link *link, FILE *file)
211 fprintf (file, "{ ");
212 for (; link; link = link->next)
214 fprintf (file, "%c%d(bb %d insn %d) ",
215 DF_REF_REG_DEF_P (link->ref) ? 'd' : 'u',
216 DF_REF_ID (link->ref),
217 DF_REF_BBNO (link->ref),
218 DF_REF_INSN (link->ref) ? DF_REF_INSN_UID (link->ref) : -1);
220 fprintf (file, "}");
224 /* Print some basic block info as part of df_dump. */
226 void
227 df_print_bb_index (basic_block bb, FILE *file)
229 edge e;
230 edge_iterator ei;
232 fprintf (file, "( ");
233 FOR_EACH_EDGE (e, ei, bb->preds)
235 basic_block pred = e->src;
236 fprintf (file, "%d ", pred->index);
238 fprintf (file, ")->[%d]->( ", bb->index);
239 FOR_EACH_EDGE (e, ei, bb->succs)
241 basic_block succ = e->dest;
242 fprintf (file, "%d ", succ->index);
244 fprintf (file, ")\n");
248 /* Return the set of reference ids in CHAIN, caching the result in *BMAP. */
250 static inline bitmap
251 df_ref_bitmap (bitmap *maps, unsigned int regno, int start, int count)
253 bitmap ids = maps[regno];
254 if (!ids)
256 unsigned int i;
257 unsigned int end = start + count;;
258 ids = BITMAP_ALLOC (NULL);
259 maps[regno] = ids;
260 for (i = start; i < end; i++)
261 bitmap_set_bit (ids, i);
263 return ids;
267 /* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
268 up correctly. */
270 static void
271 df_set_seen (void)
273 seen_in_block = BITMAP_ALLOC (NULL);
274 seen_in_insn = BITMAP_ALLOC (NULL);
278 static void
279 df_unset_seen (void)
281 BITMAP_FREE (seen_in_block);
282 BITMAP_FREE (seen_in_insn);
287 /*----------------------------------------------------------------------------
288 REACHING USES
290 Find the locations in the function where each use site for a pseudo
291 can reach backwards.
293 ----------------------------------------------------------------------------*/
295 struct df_ru_problem_data
297 bitmap *use_sites; /* Bitmap of uses for each pseudo. */
298 unsigned int use_sites_size; /* Size of use_sites. */
299 /* The set of defs to regs invalidated by call. */
300 bitmap sparse_invalidated_by_call;
301 /* The set of defs to regs invalidated by call for ru. */
302 bitmap dense_invalidated_by_call;
305 /* Get basic block info. */
307 struct df_ru_bb_info *
308 df_ru_get_bb_info (struct dataflow *dflow, unsigned int index)
310 return (struct df_ru_bb_info *) dflow->block_info[index];
314 /* Set basic block info. */
316 static void
317 df_ru_set_bb_info (struct dataflow *dflow, unsigned int index,
318 struct df_ru_bb_info *bb_info)
320 dflow->block_info[index] = bb_info;
324 /* Free basic block info. */
326 static void
327 df_ru_free_bb_info (struct dataflow *dflow,
328 basic_block bb ATTRIBUTE_UNUSED,
329 void *vbb_info)
331 struct df_ru_bb_info *bb_info = (struct df_ru_bb_info *) vbb_info;
332 if (bb_info)
334 BITMAP_FREE (bb_info->kill);
335 BITMAP_FREE (bb_info->sparse_kill);
336 BITMAP_FREE (bb_info->gen);
337 BITMAP_FREE (bb_info->in);
338 BITMAP_FREE (bb_info->out);
339 pool_free (dflow->block_pool, bb_info);
344 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
345 not touched unless the block is new. */
347 static void
348 df_ru_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
350 unsigned int bb_index;
351 bitmap_iterator bi;
352 unsigned int reg_size = max_reg_num ();
354 if (! dflow->block_pool)
355 dflow->block_pool = create_alloc_pool ("df_ru_block pool",
356 sizeof (struct df_ru_bb_info), 50);
358 if (dflow->problem_data)
360 unsigned int i;
361 struct df_ru_problem_data *problem_data =
362 (struct df_ru_problem_data *) dflow->problem_data;
364 for (i = 0; i < problem_data->use_sites_size; i++)
366 bitmap bm = problem_data->use_sites[i];
367 if (bm)
369 BITMAP_FREE (bm);
370 problem_data->use_sites[i] = NULL;
374 if (problem_data->use_sites_size < reg_size)
376 problem_data->use_sites
377 = xrealloc (problem_data->use_sites, reg_size * sizeof (bitmap));
378 memset (problem_data->use_sites + problem_data->use_sites_size, 0,
379 (reg_size - problem_data->use_sites_size) * sizeof (bitmap));
380 problem_data->use_sites_size = reg_size;
383 bitmap_clear (problem_data->sparse_invalidated_by_call);
384 bitmap_clear (problem_data->dense_invalidated_by_call);
386 else
388 struct df_ru_problem_data *problem_data = XNEW (struct df_ru_problem_data);
389 dflow->problem_data = problem_data;
391 problem_data->use_sites = XCNEWVEC (bitmap, reg_size);
392 problem_data->use_sites_size = reg_size;
393 problem_data->sparse_invalidated_by_call = BITMAP_ALLOC (NULL);
394 problem_data->dense_invalidated_by_call = BITMAP_ALLOC (NULL);
397 df_grow_bb_info (dflow);
399 /* Because of the clustering of all def sites for the same pseudo,
400 we have to process all of the blocks before doing the
401 analysis. */
403 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
405 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
406 if (bb_info)
408 bitmap_clear (bb_info->kill);
409 bitmap_clear (bb_info->sparse_kill);
410 bitmap_clear (bb_info->gen);
412 else
414 bb_info = (struct df_ru_bb_info *) pool_alloc (dflow->block_pool);
415 df_ru_set_bb_info (dflow, bb_index, bb_info);
416 bb_info->kill = BITMAP_ALLOC (NULL);
417 bb_info->sparse_kill = BITMAP_ALLOC (NULL);
418 bb_info->gen = BITMAP_ALLOC (NULL);
419 bb_info->in = BITMAP_ALLOC (NULL);
420 bb_info->out = BITMAP_ALLOC (NULL);
426 /* Process a list of DEFs for df_ru_bb_local_compute. */
428 static void
429 df_ru_bb_local_compute_process_def (struct dataflow *dflow,
430 struct df_ru_bb_info *bb_info,
431 struct df_ref *def,
432 enum df_ref_flags top_flag)
434 struct df *df = dflow->df;
435 while (def)
437 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
439 unsigned int regno = DF_REF_REGNO (def);
440 unsigned int begin = DF_REG_USE_GET (df, regno)->begin;
441 unsigned int n_uses = DF_REG_USE_GET (df, regno)->n_refs;
442 if (!bitmap_bit_p (seen_in_block, regno))
444 /* The first def for regno, causes the kill info to be
445 generated and the gen information to cleared. */
446 if (!bitmap_bit_p (seen_in_insn, regno))
448 if (n_uses > DF_SPARSE_THRESHOLD)
450 bitmap_set_bit (bb_info->sparse_kill, regno);
451 bitmap_clear_range (bb_info->gen, begin, n_uses);
453 else
455 struct df_ru_problem_data * problem_data =
456 (struct df_ru_problem_data *)dflow->problem_data;
457 bitmap uses =
458 df_ref_bitmap (problem_data->use_sites, regno,
459 begin, n_uses);
460 bitmap_ior_into (bb_info->kill, uses);
461 bitmap_and_compl_into (bb_info->gen, uses);
464 bitmap_set_bit (seen_in_insn, regno);
467 def = def->next_ref;
472 /* Process a list of USEs for df_ru_bb_local_compute. */
474 static void
475 df_ru_bb_local_compute_process_use (struct df_ru_bb_info *bb_info,
476 struct df_ref *use,
477 enum df_ref_flags top_flag)
479 while (use)
481 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
483 /* Add use to set of gens in this BB unless we have seen a
484 def in a previous instruction. */
485 unsigned int regno = DF_REF_REGNO (use);
486 if (!bitmap_bit_p (seen_in_block, regno))
487 bitmap_set_bit (bb_info->gen, DF_REF_ID (use));
489 use = use->next_ref;
493 /* Compute local reaching use (upward exposed use) info for basic
494 block BB. USE_INFO->REGS[R] caches the set of uses for register R. */
495 static void
496 df_ru_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
498 struct df *df = dflow->df;
499 basic_block bb = BASIC_BLOCK (bb_index);
500 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
501 rtx insn;
503 /* Set when a def for regno is seen. */
504 bitmap_clear (seen_in_block);
505 bitmap_clear (seen_in_insn);
507 #ifdef EH_USES
508 /* Variables defined in the prolog that are used by the exception
509 handler. */
510 df_ru_bb_local_compute_process_use (bb_info,
511 df_get_artificial_uses (df, bb_index),
512 DF_REF_AT_TOP);
513 #endif
514 df_ru_bb_local_compute_process_def (dflow, bb_info,
515 df_get_artificial_defs (df, bb_index),
516 DF_REF_AT_TOP);
518 FOR_BB_INSNS (bb, insn)
520 unsigned int uid = INSN_UID (insn);
521 if (! INSN_P (insn))
522 continue;
524 df_ru_bb_local_compute_process_def (dflow, bb_info,
525 DF_INSN_UID_GET (df, uid)->defs, 0);
527 /* The use processing must happen after the defs processing even
528 though the uses logically happen first since the defs clear
529 the gen set. Otherwise, a use for regno occuring in the same
530 instruction as a def for regno would be cleared. */
531 df_ru_bb_local_compute_process_use (bb_info,
532 DF_INSN_UID_GET (df, uid)->uses, 0);
534 bitmap_ior_into (seen_in_block, seen_in_insn);
535 bitmap_clear (seen_in_insn);
538 /* Process the hardware registers that are always live. */
539 df_ru_bb_local_compute_process_use (bb_info,
540 df_get_artificial_uses (df, bb_index), 0);
542 df_ru_bb_local_compute_process_def (dflow, bb_info,
543 df_get_artificial_defs (df, bb_index), 0);
547 /* Compute local reaching use (upward exposed use) info for each basic
548 block within BLOCKS. */
549 static void
550 df_ru_local_compute (struct dataflow *dflow,
551 bitmap all_blocks,
552 bitmap rescan_blocks ATTRIBUTE_UNUSED)
554 struct df *df = dflow->df;
555 unsigned int bb_index;
556 bitmap_iterator bi;
557 unsigned int regno;
558 struct df_ru_problem_data *problem_data =
559 (struct df_ru_problem_data *) dflow->problem_data;
560 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
561 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
563 df_set_seen ();
565 if (!df->use_info.refs_organized)
566 df_reorganize_refs (&df->use_info);
568 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
570 df_ru_bb_local_compute (dflow, bb_index);
573 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
574 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
576 struct df_reg_info *reg_info = DF_REG_USE_GET (df, regno);
577 if (reg_info->n_refs > DF_SPARSE_THRESHOLD)
578 bitmap_set_bit (sparse_invalidated, regno);
579 else
581 bitmap defs = df_ref_bitmap (problem_data->use_sites, regno,
582 reg_info->begin, reg_info->n_refs);
583 bitmap_ior_into (dense_invalidated, defs);
587 df_unset_seen ();
591 /* Initialize the solution bit vectors for problem. */
593 static void
594 df_ru_init_solution (struct dataflow *dflow, bitmap all_blocks)
596 unsigned int bb_index;
597 bitmap_iterator bi;
599 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
601 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
602 bitmap_copy (bb_info->in, bb_info->gen);
603 bitmap_clear (bb_info->out);
608 /* Out of target gets or of in of source. */
610 static void
611 df_ru_confluence_n (struct dataflow *dflow, edge e)
613 bitmap op1 = df_ru_get_bb_info (dflow, e->src->index)->out;
614 bitmap op2 = df_ru_get_bb_info (dflow, e->dest->index)->in;
616 if (e->flags & EDGE_EH)
618 struct df_ru_problem_data *problem_data =
619 (struct df_ru_problem_data *) dflow->problem_data;
620 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
621 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
622 struct df *df = dflow->df;
623 bitmap_iterator bi;
624 unsigned int regno;
625 bitmap tmp = BITMAP_ALLOC (NULL);
627 bitmap_copy (tmp, op2);
628 bitmap_and_compl_into (tmp, dense_invalidated);
630 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
632 bitmap_clear_range (tmp,
633 DF_REG_USE_GET (df, regno)->begin,
634 DF_REG_USE_GET (df, regno)->n_refs);
636 bitmap_ior_into (op1, tmp);
637 BITMAP_FREE (tmp);
639 else
640 bitmap_ior_into (op1, op2);
644 /* Transfer function. */
646 static bool
647 df_ru_transfer_function (struct dataflow *dflow, int bb_index)
649 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
650 unsigned int regno;
651 bitmap_iterator bi;
652 bitmap in = bb_info->in;
653 bitmap out = bb_info->out;
654 bitmap gen = bb_info->gen;
655 bitmap kill = bb_info->kill;
656 bitmap sparse_kill = bb_info->sparse_kill;
658 if (bitmap_empty_p (sparse_kill))
659 return bitmap_ior_and_compl (in, gen, out, kill);
660 else
662 struct df *df = dflow->df;
663 bool changed = false;
664 bitmap tmp = BITMAP_ALLOC (NULL);
665 bitmap_copy (tmp, in);
666 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
668 bitmap_clear_range (tmp,
669 DF_REG_USE_GET (df, regno)->begin,
670 DF_REG_USE_GET (df, regno)->n_refs);
672 bitmap_and_compl_into (tmp, kill);
673 bitmap_ior_into (tmp, gen);
674 changed = !bitmap_equal_p (tmp, in);
675 if (changed)
677 BITMAP_FREE (out);
678 bb_info->in = tmp;
680 else
681 BITMAP_FREE (tmp);
682 return changed;
687 /* Free all storage associated with the problem. */
689 static void
690 df_ru_free (struct dataflow *dflow)
692 unsigned int i;
693 struct df_ru_problem_data *problem_data =
694 (struct df_ru_problem_data *) dflow->problem_data;
696 if (problem_data)
698 for (i = 0; i < dflow->block_info_size; i++)
700 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, i);
701 if (bb_info)
703 BITMAP_FREE (bb_info->kill);
704 BITMAP_FREE (bb_info->sparse_kill);
705 BITMAP_FREE (bb_info->gen);
706 BITMAP_FREE (bb_info->in);
707 BITMAP_FREE (bb_info->out);
711 free_alloc_pool (dflow->block_pool);
713 for (i = 0; i < problem_data->use_sites_size; i++)
715 bitmap bm = problem_data->use_sites[i];
716 if (bm)
717 BITMAP_FREE (bm);
720 free (problem_data->use_sites);
721 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
722 BITMAP_FREE (problem_data->dense_invalidated_by_call);
724 dflow->block_info_size = 0;
725 free (dflow->block_info);
726 free (dflow->problem_data);
728 free (dflow);
732 /* Debugging info. */
734 static void
735 df_ru_dump (struct dataflow *dflow, FILE *file)
737 basic_block bb;
738 struct df *df = dflow->df;
739 struct df_ru_problem_data *problem_data =
740 (struct df_ru_problem_data *) dflow->problem_data;
741 unsigned int m = max_reg_num ();
742 unsigned int regno;
744 fprintf (file, "Reaching uses:\n");
746 fprintf (file, " sparse invalidated \t");
747 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
748 fprintf (file, " dense invalidated \t");
749 dump_bitmap (file, problem_data->dense_invalidated_by_call);
751 for (regno = 0; regno < m; regno++)
752 if (DF_REG_USE_GET (df, regno)->n_refs)
753 fprintf (file, "%d[%d,%d] ", regno,
754 DF_REG_USE_GET (df, regno)->begin,
755 DF_REG_USE_GET (df, regno)->n_refs);
756 fprintf (file, "\n");
758 FOR_ALL_BB (bb)
760 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb->index);
761 df_print_bb_index (bb, file);
763 if (! bb_info->in)
764 continue;
766 fprintf (file, " in \t");
767 dump_bitmap (file, bb_info->in);
768 fprintf (file, " gen \t");
769 dump_bitmap (file, bb_info->gen);
770 fprintf (file, " kill\t");
771 dump_bitmap (file, bb_info->kill);
772 fprintf (file, " out \t");
773 dump_bitmap (file, bb_info->out);
777 /* All of the information associated with every instance of the problem. */
779 static struct df_problem problem_RU =
781 DF_RU, /* Problem id. */
782 DF_BACKWARD, /* Direction. */
783 df_ru_alloc, /* Allocate the problem specific data. */
784 NULL, /* Reset global information. */
785 df_ru_free_bb_info, /* Free basic block info. */
786 df_ru_local_compute, /* Local compute function. */
787 df_ru_init_solution, /* Init the solution specific data. */
788 df_iterative_dataflow, /* Iterative solver. */
789 NULL, /* Confluence operator 0. */
790 df_ru_confluence_n, /* Confluence operator n. */
791 df_ru_transfer_function, /* Transfer function. */
792 NULL, /* Finalize function. */
793 df_ru_free, /* Free all of the problem information. */
794 df_ru_dump, /* Debugging. */
795 NULL /* Dependent problem. */
800 /* Create a new DATAFLOW instance and add it to an existing instance
801 of DF. The returned structure is what is used to get at the
802 solution. */
804 struct dataflow *
805 df_ru_add_problem (struct df *df)
807 return df_add_problem (df, &problem_RU);
811 /*----------------------------------------------------------------------------
812 REACHING DEFINITIONS
814 Find the locations in the function where each definition site for a
815 pseudo reaches.
816 ----------------------------------------------------------------------------*/
818 struct df_rd_problem_data
820 bitmap *def_sites; /* Bitmap of defs for each pseudo. */
821 unsigned int def_sites_size; /* Size of def_sites. */
822 /* The set of defs to regs invalidated by call. */
823 bitmap sparse_invalidated_by_call;
824 /* The set of defs to regs invalidate by call for ru. */
825 bitmap dense_invalidated_by_call;
828 /* Get basic block info. */
830 struct df_rd_bb_info *
831 df_rd_get_bb_info (struct dataflow *dflow, unsigned int index)
833 return (struct df_rd_bb_info *) dflow->block_info[index];
837 /* Set basic block info. */
839 static void
840 df_rd_set_bb_info (struct dataflow *dflow, unsigned int index,
841 struct df_rd_bb_info *bb_info)
843 dflow->block_info[index] = bb_info;
847 /* Free basic block info. */
849 static void
850 df_rd_free_bb_info (struct dataflow *dflow,
851 basic_block bb ATTRIBUTE_UNUSED,
852 void *vbb_info)
854 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
855 if (bb_info)
857 BITMAP_FREE (bb_info->kill);
858 BITMAP_FREE (bb_info->sparse_kill);
859 BITMAP_FREE (bb_info->gen);
860 BITMAP_FREE (bb_info->in);
861 BITMAP_FREE (bb_info->out);
862 pool_free (dflow->block_pool, bb_info);
867 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
868 not touched unless the block is new. */
870 static void
871 df_rd_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
873 unsigned int bb_index;
874 bitmap_iterator bi;
875 unsigned int reg_size = max_reg_num ();
877 if (! dflow->block_pool)
878 dflow->block_pool = create_alloc_pool ("df_rd_block pool",
879 sizeof (struct df_rd_bb_info), 50);
881 if (dflow->problem_data)
883 unsigned int i;
884 struct df_rd_problem_data *problem_data =
885 (struct df_rd_problem_data *) dflow->problem_data;
887 for (i = 0; i < problem_data->def_sites_size; i++)
889 bitmap bm = problem_data->def_sites[i];
890 if (bm)
892 BITMAP_FREE (bm);
893 problem_data->def_sites[i] = NULL;
897 if (problem_data->def_sites_size < reg_size)
899 problem_data->def_sites
900 = xrealloc (problem_data->def_sites, reg_size *sizeof (bitmap));
901 memset (problem_data->def_sites + problem_data->def_sites_size, 0,
902 (reg_size - problem_data->def_sites_size) *sizeof (bitmap));
903 problem_data->def_sites_size = reg_size;
906 bitmap_clear (problem_data->sparse_invalidated_by_call);
907 bitmap_clear (problem_data->dense_invalidated_by_call);
909 else
911 struct df_rd_problem_data *problem_data = XNEW (struct df_rd_problem_data);
912 dflow->problem_data = problem_data;
914 problem_data->def_sites = XCNEWVEC (bitmap, reg_size);
915 problem_data->def_sites_size = reg_size;
916 problem_data->sparse_invalidated_by_call = BITMAP_ALLOC (NULL);
917 problem_data->dense_invalidated_by_call = BITMAP_ALLOC (NULL);
920 df_grow_bb_info (dflow);
922 /* Because of the clustering of all def sites for the same pseudo,
923 we have to process all of the blocks before doing the
924 analysis. */
926 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
928 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
929 if (bb_info)
931 bitmap_clear (bb_info->kill);
932 bitmap_clear (bb_info->sparse_kill);
933 bitmap_clear (bb_info->gen);
935 else
937 bb_info = (struct df_rd_bb_info *) pool_alloc (dflow->block_pool);
938 df_rd_set_bb_info (dflow, bb_index, bb_info);
939 bb_info->kill = BITMAP_ALLOC (NULL);
940 bb_info->sparse_kill = BITMAP_ALLOC (NULL);
941 bb_info->gen = BITMAP_ALLOC (NULL);
942 bb_info->in = BITMAP_ALLOC (NULL);
943 bb_info->out = BITMAP_ALLOC (NULL);
949 /* Process a list of DEFs for df_rd_bb_local_compute. */
951 static void
952 df_rd_bb_local_compute_process_def (struct dataflow *dflow,
953 struct df_rd_bb_info *bb_info,
954 struct df_ref *def,
955 enum df_ref_flags top_flag)
957 struct df *df = dflow->df;
958 while (def)
960 if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
962 unsigned int regno = DF_REF_REGNO (def);
963 unsigned int begin = DF_REG_DEF_GET (df, regno)->begin;
964 unsigned int n_defs = DF_REG_DEF_GET (df, regno)->n_refs;
966 /* Only the last def(s) for a regno in the block has any
967 effect. */
968 if (!bitmap_bit_p (seen_in_block, regno))
970 /* The first def for regno in insn gets to knock out the
971 defs from other instructions. */
972 if (!bitmap_bit_p (seen_in_insn, regno))
974 if (n_defs > DF_SPARSE_THRESHOLD)
976 bitmap_set_bit (bb_info->sparse_kill, regno);
977 bitmap_clear_range(bb_info->gen, begin, n_defs);
979 else
981 struct df_rd_problem_data * problem_data =
982 (struct df_rd_problem_data *)dflow->problem_data;
983 bitmap defs =
984 df_ref_bitmap (problem_data->def_sites, regno,
985 begin, n_defs);
986 bitmap_ior_into (bb_info->kill, defs);
987 bitmap_and_compl_into (bb_info->gen, defs);
991 bitmap_set_bit (seen_in_insn, regno);
992 /* All defs for regno in the instruction may be put into
993 the gen set. */
994 if (! (DF_REF_FLAGS (def) & DF_REF_CLOBBER))
995 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
998 def = def->next_ref;
1002 /* Compute local reaching def info for basic block BB. */
1004 static void
1005 df_rd_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
1007 struct df *df = dflow->df;
1008 basic_block bb = BASIC_BLOCK (bb_index);
1009 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
1010 rtx insn;
1012 bitmap_clear (seen_in_block);
1013 bitmap_clear (seen_in_insn);
1015 df_rd_bb_local_compute_process_def (dflow, bb_info,
1016 df_get_artificial_defs (df, bb_index), 0);
1018 FOR_BB_INSNS_REVERSE (bb, insn)
1020 unsigned int uid = INSN_UID (insn);
1022 if (! INSN_P (insn))
1023 continue;
1025 df_rd_bb_local_compute_process_def (dflow, bb_info,
1026 DF_INSN_UID_GET (df, uid)->defs, 0);
1028 /* This complex dance with the two bitmaps is required because
1029 instructions can assign twice to the same pseudo. This
1030 generally happens with calls that will have one def for the
1031 result and another def for the clobber. If only one vector
1032 is used and the clobber goes first, the result will be
1033 lost. */
1034 bitmap_ior_into (seen_in_block, seen_in_insn);
1035 bitmap_clear (seen_in_insn);
1038 /* Process the artificial defs at the top of the block last since we
1039 are going backwards through the block and these are logically at
1040 the start. */
1041 df_rd_bb_local_compute_process_def (dflow, bb_info,
1042 df_get_artificial_defs (df, bb_index),
1043 DF_REF_AT_TOP);
1047 /* Compute local reaching def info for each basic block within BLOCKS. */
1049 static void
1050 df_rd_local_compute (struct dataflow *dflow,
1051 bitmap all_blocks,
1052 bitmap rescan_blocks ATTRIBUTE_UNUSED)
1054 struct df *df = dflow->df;
1055 unsigned int bb_index;
1056 bitmap_iterator bi;
1057 unsigned int regno;
1058 struct df_rd_problem_data *problem_data =
1059 (struct df_rd_problem_data *) dflow->problem_data;
1060 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
1061 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
1063 df_set_seen ();
1065 if (!df->def_info.refs_organized)
1066 df_reorganize_refs (&df->def_info);
1068 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1070 df_rd_bb_local_compute (dflow, bb_index);
1073 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
1074 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
1076 struct df_reg_info *reg_info = DF_REG_DEF_GET (df, regno);
1077 if (reg_info->n_refs > DF_SPARSE_THRESHOLD)
1079 bitmap_set_bit (sparse_invalidated, regno);
1081 else
1083 bitmap defs = df_ref_bitmap (problem_data->def_sites, regno,
1084 reg_info->begin, reg_info->n_refs);
1085 bitmap_ior_into (dense_invalidated, defs);
1088 df_unset_seen ();
1092 /* Initialize the solution bit vectors for problem. */
1094 static void
1095 df_rd_init_solution (struct dataflow *dflow, bitmap all_blocks)
1097 unsigned int bb_index;
1098 bitmap_iterator bi;
1100 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1102 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
1104 bitmap_copy (bb_info->out, bb_info->gen);
1105 bitmap_clear (bb_info->in);
1109 /* In of target gets or of out of source. */
1111 static void
1112 df_rd_confluence_n (struct dataflow *dflow, edge e)
1114 bitmap op1 = df_rd_get_bb_info (dflow, e->dest->index)->in;
1115 bitmap op2 = df_rd_get_bb_info (dflow, e->src->index)->out;
1117 if (e->flags & EDGE_EH)
1119 struct df_rd_problem_data *problem_data =
1120 (struct df_rd_problem_data *) dflow->problem_data;
1121 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
1122 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
1123 struct df *df = dflow->df;
1124 bitmap_iterator bi;
1125 unsigned int regno;
1126 bitmap tmp = BITMAP_ALLOC (NULL);
1128 bitmap_copy (tmp, op2);
1129 bitmap_and_compl_into (tmp, dense_invalidated);
1131 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
1133 bitmap_clear_range (tmp,
1134 DF_REG_DEF_GET (df, regno)->begin,
1135 DF_REG_DEF_GET (df, regno)->n_refs);
1137 bitmap_ior_into (op1, tmp);
1138 BITMAP_FREE (tmp);
1140 else
1141 bitmap_ior_into (op1, op2);
1145 /* Transfer function. */
1147 static bool
1148 df_rd_transfer_function (struct dataflow *dflow, int bb_index)
1150 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
1151 unsigned int regno;
1152 bitmap_iterator bi;
1153 bitmap in = bb_info->in;
1154 bitmap out = bb_info->out;
1155 bitmap gen = bb_info->gen;
1156 bitmap kill = bb_info->kill;
1157 bitmap sparse_kill = bb_info->sparse_kill;
1159 if (bitmap_empty_p (sparse_kill))
1160 return bitmap_ior_and_compl (out, gen, in, kill);
1161 else
1163 struct df *df = dflow->df;
1164 bool changed = false;
1165 bitmap tmp = BITMAP_ALLOC (NULL);
1166 bitmap_copy (tmp, in);
1167 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
1169 bitmap_clear_range (tmp,
1170 DF_REG_DEF_GET (df, regno)->begin,
1171 DF_REG_DEF_GET (df, regno)->n_refs);
1173 bitmap_and_compl_into (tmp, kill);
1174 bitmap_ior_into (tmp, gen);
1175 changed = !bitmap_equal_p (tmp, out);
1176 if (changed)
1178 BITMAP_FREE (out);
1179 bb_info->out = tmp;
1181 else
1182 BITMAP_FREE (tmp);
1183 return changed;
1188 /* Free all storage associated with the problem. */
1190 static void
1191 df_rd_free (struct dataflow *dflow)
1193 unsigned int i;
1194 struct df_rd_problem_data *problem_data =
1195 (struct df_rd_problem_data *) dflow->problem_data;
1197 if (problem_data)
1199 for (i = 0; i < dflow->block_info_size; i++)
1201 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, i);
1202 if (bb_info)
1204 BITMAP_FREE (bb_info->kill);
1205 BITMAP_FREE (bb_info->sparse_kill);
1206 BITMAP_FREE (bb_info->gen);
1207 BITMAP_FREE (bb_info->in);
1208 BITMAP_FREE (bb_info->out);
1212 free_alloc_pool (dflow->block_pool);
1214 for (i = 0; i < problem_data->def_sites_size; i++)
1216 bitmap bm = problem_data->def_sites[i];
1217 if (bm)
1218 BITMAP_FREE (bm);
1221 free (problem_data->def_sites);
1222 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
1223 BITMAP_FREE (problem_data->dense_invalidated_by_call);
1225 dflow->block_info_size = 0;
1226 free (dflow->block_info);
1227 free (dflow->problem_data);
1229 free (dflow);
1233 /* Debugging info. */
1235 static void
1236 df_rd_dump (struct dataflow *dflow, FILE *file)
1238 struct df *df = dflow->df;
1239 basic_block bb;
1240 struct df_rd_problem_data *problem_data =
1241 (struct df_rd_problem_data *) dflow->problem_data;
1242 unsigned int m = max_reg_num ();
1243 unsigned int regno;
1245 fprintf (file, "Reaching defs:\n\n");
1247 fprintf (file, " sparse invalidated \t");
1248 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
1249 fprintf (file, " dense invalidated \t");
1250 dump_bitmap (file, problem_data->dense_invalidated_by_call);
1252 for (regno = 0; regno < m; regno++)
1253 if (DF_REG_DEF_GET (df, regno)->n_refs)
1254 fprintf (file, "%d[%d,%d] ", regno,
1255 DF_REG_DEF_GET (df, regno)->begin,
1256 DF_REG_DEF_GET (df, regno)->n_refs);
1257 fprintf (file, "\n");
1259 FOR_ALL_BB (bb)
1261 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb->index);
1262 df_print_bb_index (bb, file);
1264 if (! bb_info->in)
1265 continue;
1267 fprintf (file, " in\t(%d)\n", (int) bitmap_count_bits (bb_info->in));
1268 dump_bitmap (file, bb_info->in);
1269 fprintf (file, " gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
1270 dump_bitmap (file, bb_info->gen);
1271 fprintf (file, " kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
1272 dump_bitmap (file, bb_info->kill);
1273 fprintf (file, " out\t(%d)\n", (int) bitmap_count_bits (bb_info->out));
1274 dump_bitmap (file, bb_info->out);
1278 /* All of the information associated with every instance of the problem. */
1280 static struct df_problem problem_RD =
1282 DF_RD, /* Problem id. */
1283 DF_FORWARD, /* Direction. */
1284 df_rd_alloc, /* Allocate the problem specific data. */
1285 NULL, /* Reset global information. */
1286 df_rd_free_bb_info, /* Free basic block info. */
1287 df_rd_local_compute, /* Local compute function. */
1288 df_rd_init_solution, /* Init the solution specific data. */
1289 df_iterative_dataflow, /* Iterative solver. */
1290 NULL, /* Confluence operator 0. */
1291 df_rd_confluence_n, /* Confluence operator n. */
1292 df_rd_transfer_function, /* Transfer function. */
1293 NULL, /* Finalize function. */
1294 df_rd_free, /* Free all of the problem information. */
1295 df_rd_dump, /* Debugging. */
1296 NULL /* Dependent problem. */
1301 /* Create a new DATAFLOW instance and add it to an existing instance
1302 of DF. The returned structure is what is used to get at the
1303 solution. */
1305 struct dataflow *
1306 df_rd_add_problem (struct df *df)
1308 return df_add_problem (df, &problem_RD);
1313 /*----------------------------------------------------------------------------
1314 LIVE REGISTERS
1316 Find the locations in the function where any use of a pseudo can reach
1317 in the backwards direction.
1318 ----------------------------------------------------------------------------*/
1320 /* Get basic block info. */
1322 struct df_lr_bb_info *
1323 df_lr_get_bb_info (struct dataflow *dflow, unsigned int index)
1325 return (struct df_lr_bb_info *) dflow->block_info[index];
1329 /* Set basic block info. */
1331 static void
1332 df_lr_set_bb_info (struct dataflow *dflow, unsigned int index,
1333 struct df_lr_bb_info *bb_info)
1335 dflow->block_info[index] = bb_info;
1339 /* Free basic block info. */
1341 static void
1342 df_lr_free_bb_info (struct dataflow *dflow,
1343 basic_block bb ATTRIBUTE_UNUSED,
1344 void *vbb_info)
1346 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
1347 if (bb_info)
1349 BITMAP_FREE (bb_info->use);
1350 BITMAP_FREE (bb_info->def);
1351 BITMAP_FREE (bb_info->in);
1352 BITMAP_FREE (bb_info->out);
1353 pool_free (dflow->block_pool, bb_info);
1358 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1359 not touched unless the block is new. */
1361 static void
1362 df_lr_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
1364 unsigned int bb_index;
1365 bitmap_iterator bi;
1367 if (! dflow->block_pool)
1368 dflow->block_pool = create_alloc_pool ("df_lr_block pool",
1369 sizeof (struct df_lr_bb_info), 50);
1371 df_grow_bb_info (dflow);
1373 /* Because of the clustering of all def sites for the same pseudo,
1374 we have to process all of the blocks before doing the
1375 analysis. */
1377 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
1379 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1380 if (bb_info)
1382 bitmap_clear (bb_info->def);
1383 bitmap_clear (bb_info->use);
1385 else
1387 bb_info = (struct df_lr_bb_info *) pool_alloc (dflow->block_pool);
1388 df_lr_set_bb_info (dflow, bb_index, bb_info);
1389 bb_info->use = BITMAP_ALLOC (NULL);
1390 bb_info->def = BITMAP_ALLOC (NULL);
1391 bb_info->in = BITMAP_ALLOC (NULL);
1392 bb_info->out = BITMAP_ALLOC (NULL);
1398 /* Compute local live register info for basic block BB. */
1400 static void
1401 df_lr_bb_local_compute (struct dataflow *dflow,
1402 struct df *df, unsigned int bb_index)
1404 basic_block bb = BASIC_BLOCK (bb_index);
1405 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1406 rtx insn;
1407 struct df_ref *def;
1408 struct df_ref *use;
1410 /* Process the registers set in an exception handler. */
1411 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
1412 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
1414 unsigned int dregno = DF_REF_REGNO (def);
1415 bitmap_set_bit (bb_info->def, dregno);
1416 bitmap_clear_bit (bb_info->use, dregno);
1419 /* Process the hardware registers that are always live. */
1420 for (use = df_get_artificial_uses (df, bb_index); use; use = use->next_ref)
1421 /* Add use to set of uses in this BB. */
1422 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
1423 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1425 FOR_BB_INSNS_REVERSE (bb, insn)
1427 unsigned int uid = INSN_UID (insn);
1429 if (! INSN_P (insn))
1430 continue;
1432 if (CALL_P (insn))
1434 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
1436 unsigned int dregno = DF_REF_REGNO (def);
1438 if (dregno >= FIRST_PSEUDO_REGISTER
1439 || !(SIBLING_CALL_P (insn)
1440 && bitmap_bit_p (df->exit_block_uses, dregno)
1441 && !refers_to_regno_p (dregno, dregno+1,
1442 current_function_return_rtx,
1443 (rtx *)0)))
1445 /* Add def to set of defs in this BB. */
1446 bitmap_set_bit (bb_info->def, dregno);
1447 bitmap_clear_bit (bb_info->use, dregno);
1451 else
1453 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
1455 unsigned int dregno = DF_REF_REGNO (def);
1457 if (DF_INSN_CONTAINS_ASM (df, insn)
1458 && dregno < FIRST_PSEUDO_REGISTER)
1460 unsigned int i;
1461 unsigned int end =
1462 dregno + hard_regno_nregs[dregno][GET_MODE (DF_REF_REG (def))] - 1;
1463 for (i = dregno; i <= end; ++i)
1464 regs_asm_clobbered[i] = 1;
1466 /* Add def to set of defs in this BB. */
1467 bitmap_set_bit (bb_info->def, dregno);
1468 bitmap_clear_bit (bb_info->use, dregno);
1472 for (use = DF_INSN_UID_GET (df, uid)->uses; use; use = use->next_ref)
1473 /* Add use to set of uses in this BB. */
1474 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1477 /* Process the registers set in an exception handler. */
1478 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
1479 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
1481 unsigned int dregno = DF_REF_REGNO (def);
1482 bitmap_set_bit (bb_info->def, dregno);
1483 bitmap_clear_bit (bb_info->use, dregno);
1486 #ifdef EH_USES
1487 /* Process the uses that are live into an exception handler. */
1488 for (use = df_get_artificial_uses (df, bb_index); use; use = use->next_ref)
1489 /* Add use to set of uses in this BB. */
1490 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
1491 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1492 #endif
1495 /* Compute local live register info for each basic block within BLOCKS. */
1497 static void
1498 df_lr_local_compute (struct dataflow *dflow,
1499 bitmap all_blocks,
1500 bitmap rescan_blocks)
1502 struct df *df = dflow->df;
1503 unsigned int bb_index;
1504 bitmap_iterator bi;
1506 /* Assume that the stack pointer is unchanging if alloca hasn't
1507 been used. */
1508 if (bitmap_equal_p (all_blocks, rescan_blocks))
1509 memset (regs_asm_clobbered, 0, sizeof (regs_asm_clobbered));
1511 bitmap_clear (df->hardware_regs_used);
1513 /* The all-important stack pointer must always be live. */
1514 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
1516 /* Before reload, there are a few registers that must be forced
1517 live everywhere -- which might not already be the case for
1518 blocks within infinite loops. */
1519 if (! reload_completed)
1521 /* Any reference to any pseudo before reload is a potential
1522 reference of the frame pointer. */
1523 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
1525 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1526 /* Pseudos with argument area equivalences may require
1527 reloading via the argument pointer. */
1528 if (fixed_regs[ARG_POINTER_REGNUM])
1529 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
1530 #endif
1532 /* Any constant, or pseudo with constant equivalences, may
1533 require reloading from memory using the pic register. */
1534 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
1535 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
1536 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
1539 if (bitmap_bit_p (rescan_blocks, EXIT_BLOCK))
1541 /* The exit block is special for this problem and its bits are
1542 computed from thin air. */
1543 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, EXIT_BLOCK);
1544 bitmap_copy (bb_info->use, df->exit_block_uses);
1547 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks, 0, bb_index, bi)
1549 if (bb_index == EXIT_BLOCK)
1550 continue;
1551 df_lr_bb_local_compute (dflow, df, bb_index);
1556 /* Initialize the solution vectors. */
1558 static void
1559 df_lr_init (struct dataflow *dflow, bitmap all_blocks)
1561 unsigned int bb_index;
1562 bitmap_iterator bi;
1564 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1566 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1567 bitmap_copy (bb_info->in, bb_info->use);
1568 bitmap_clear (bb_info->out);
1573 /* Confluence function that processes infinite loops. This might be a
1574 noreturn function that throws. And even if it isn't, getting the
1575 unwind info right helps debugging. */
1576 static void
1577 df_lr_confluence_0 (struct dataflow *dflow, basic_block bb)
1579 struct df *df = dflow->df;
1581 bitmap op1 = df_lr_get_bb_info (dflow, bb->index)->out;
1582 if (bb != EXIT_BLOCK_PTR)
1583 bitmap_copy (op1, df->hardware_regs_used);
1587 /* Confluence function that ignores fake edges. */
1588 static void
1589 df_lr_confluence_n (struct dataflow *dflow, edge e)
1591 bitmap op1 = df_lr_get_bb_info (dflow, e->src->index)->out;
1592 bitmap op2 = df_lr_get_bb_info (dflow, e->dest->index)->in;
1594 /* Call-clobbered registers die across exception and call edges. */
1595 /* ??? Abnormal call edges ignored for the moment, as this gets
1596 confused by sibling call edges, which crashes reg-stack. */
1597 if (e->flags & EDGE_EH)
1598 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
1599 else
1600 bitmap_ior_into (op1, op2);
1602 bitmap_ior_into (op1, dflow->df->hardware_regs_used);
1606 /* Transfer function. */
1607 static bool
1608 df_lr_transfer_function (struct dataflow *dflow, int bb_index)
1610 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1611 bitmap in = bb_info->in;
1612 bitmap out = bb_info->out;
1613 bitmap use = bb_info->use;
1614 bitmap def = bb_info->def;
1616 return bitmap_ior_and_compl (in, use, out, def);
1620 /* Free all storage associated with the problem. */
1622 static void
1623 df_lr_free (struct dataflow *dflow)
1625 if (dflow->block_info)
1627 unsigned int i;
1628 for (i = 0; i < dflow->block_info_size; i++)
1630 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, i);
1631 if (bb_info)
1633 BITMAP_FREE (bb_info->use);
1634 BITMAP_FREE (bb_info->def);
1635 BITMAP_FREE (bb_info->in);
1636 BITMAP_FREE (bb_info->out);
1639 free_alloc_pool (dflow->block_pool);
1641 dflow->block_info_size = 0;
1642 free (dflow->block_info);
1644 free (dflow);
1648 /* Debugging info. */
1650 static void
1651 df_lr_dump (struct dataflow *dflow, FILE *file)
1653 basic_block bb;
1655 fprintf (file, "Live Registers:\n");
1656 FOR_ALL_BB (bb)
1658 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb->index);
1659 df_print_bb_index (bb, file);
1661 if (!bb_info->in)
1662 continue;
1664 fprintf (file, " in \t");
1665 dump_bitmap (file, bb_info->in);
1666 fprintf (file, " use \t");
1667 dump_bitmap (file, bb_info->use);
1668 fprintf (file, " def \t");
1669 dump_bitmap (file, bb_info->def);
1670 fprintf (file, " out \t");
1671 dump_bitmap (file, bb_info->out);
1675 /* All of the information associated with every instance of the problem. */
1677 static struct df_problem problem_LR =
1679 DF_LR, /* Problem id. */
1680 DF_BACKWARD, /* Direction. */
1681 df_lr_alloc, /* Allocate the problem specific data. */
1682 NULL, /* Reset global information. */
1683 df_lr_free_bb_info, /* Free basic block info. */
1684 df_lr_local_compute, /* Local compute function. */
1685 df_lr_init, /* Init the solution specific data. */
1686 df_iterative_dataflow, /* Iterative solver. */
1687 df_lr_confluence_0, /* Confluence operator 0. */
1688 df_lr_confluence_n, /* Confluence operator n. */
1689 df_lr_transfer_function, /* Transfer function. */
1690 NULL, /* Finalize function. */
1691 df_lr_free, /* Free all of the problem information. */
1692 df_lr_dump, /* Debugging. */
1693 NULL /* Dependent problem. */
1697 /* Create a new DATAFLOW instance and add it to an existing instance
1698 of DF. The returned structure is what is used to get at the
1699 solution. */
1701 struct dataflow *
1702 df_lr_add_problem (struct df *df)
1704 return df_add_problem (df, &problem_LR);
1709 /*----------------------------------------------------------------------------
1710 UNINITIALIZED REGISTERS
1712 Find the set of uses for registers that are reachable from the entry
1713 block without passing thru a definition.
1714 ----------------------------------------------------------------------------*/
1716 /* Get basic block info. */
1718 struct df_ur_bb_info *
1719 df_ur_get_bb_info (struct dataflow *dflow, unsigned int index)
1721 return (struct df_ur_bb_info *) dflow->block_info[index];
1725 /* Set basic block info. */
1727 static void
1728 df_ur_set_bb_info (struct dataflow *dflow, unsigned int index,
1729 struct df_ur_bb_info *bb_info)
1731 dflow->block_info[index] = bb_info;
1735 /* Free basic block info. */
1737 static void
1738 df_ur_free_bb_info (struct dataflow *dflow,
1739 basic_block bb ATTRIBUTE_UNUSED,
1740 void *vbb_info)
1742 struct df_ur_bb_info *bb_info = (struct df_ur_bb_info *) vbb_info;
1743 if (bb_info)
1745 BITMAP_FREE (bb_info->gen);
1746 BITMAP_FREE (bb_info->kill);
1747 BITMAP_FREE (bb_info->in);
1748 BITMAP_FREE (bb_info->out);
1749 pool_free (dflow->block_pool, bb_info);
1754 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1755 not touched unless the block is new. */
1757 static void
1758 df_ur_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
1760 unsigned int bb_index;
1761 bitmap_iterator bi;
1763 if (! dflow->block_pool)
1764 dflow->block_pool = create_alloc_pool ("df_ur_block pool",
1765 sizeof (struct df_ur_bb_info), 100);
1767 df_grow_bb_info (dflow);
1769 /* Because of the clustering of all def sites for the same pseudo,
1770 we have to process all of the blocks before doing the
1771 analysis. */
1773 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
1775 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1776 if (bb_info)
1778 bitmap_clear (bb_info->kill);
1779 bitmap_clear (bb_info->gen);
1781 else
1783 bb_info = (struct df_ur_bb_info *) pool_alloc (dflow->block_pool);
1784 df_ur_set_bb_info (dflow, bb_index, bb_info);
1785 bb_info->kill = BITMAP_ALLOC (NULL);
1786 bb_info->gen = BITMAP_ALLOC (NULL);
1787 bb_info->in = BITMAP_ALLOC (NULL);
1788 bb_info->out = BITMAP_ALLOC (NULL);
1794 /* Compute local uninitialized register info for basic block BB. */
1796 static void
1797 df_ur_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
1799 struct df *df = dflow->df;
1800 basic_block bb = BASIC_BLOCK (bb_index);
1801 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1802 rtx insn;
1803 struct df_ref *def;
1805 bitmap_clear (seen_in_block);
1806 bitmap_clear (seen_in_insn);
1808 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
1809 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
1811 unsigned int regno = DF_REF_REGNO (def);
1812 if (!bitmap_bit_p (seen_in_block, regno))
1814 bitmap_set_bit (seen_in_block, regno);
1815 bitmap_set_bit (bb_info->gen, regno);
1819 FOR_BB_INSNS_REVERSE (bb, insn)
1821 unsigned int uid = INSN_UID (insn);
1822 if (!INSN_P (insn))
1823 continue;
1825 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
1827 unsigned int regno = DF_REF_REGNO (def);
1828 /* Only the last def counts. */
1829 if (!bitmap_bit_p (seen_in_block, regno))
1831 bitmap_set_bit (seen_in_insn, regno);
1833 if (DF_REF_FLAGS (def) & DF_REF_CLOBBER)
1834 bitmap_set_bit (bb_info->kill, regno);
1835 else
1836 bitmap_set_bit (bb_info->gen, regno);
1839 bitmap_ior_into (seen_in_block, seen_in_insn);
1840 bitmap_clear (seen_in_insn);
1843 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
1844 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
1846 unsigned int regno = DF_REF_REGNO (def);
1847 if (!bitmap_bit_p (seen_in_block, regno))
1849 bitmap_set_bit (seen_in_block, regno);
1850 bitmap_set_bit (bb_info->gen, regno);
1856 /* Compute local uninitialized register info. */
1858 static void
1859 df_ur_local_compute (struct dataflow *dflow,
1860 bitmap all_blocks ATTRIBUTE_UNUSED,
1861 bitmap rescan_blocks)
1863 unsigned int bb_index;
1864 bitmap_iterator bi;
1866 df_set_seen ();
1868 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks, 0, bb_index, bi)
1870 df_ur_bb_local_compute (dflow, bb_index);
1873 df_unset_seen ();
1877 /* Initialize the solution vectors. */
1879 static void
1880 df_ur_init (struct dataflow *dflow, bitmap all_blocks)
1882 unsigned int bb_index;
1883 bitmap_iterator bi;
1885 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1887 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1889 bitmap_copy (bb_info->out, bb_info->gen);
1890 bitmap_clear (bb_info->in);
1895 /* Or in the stack regs, hard regs and early clobber regs into the the
1896 ur_in sets of all of the blocks. */
1898 static void
1899 df_ur_local_finalize (struct dataflow *dflow, bitmap all_blocks)
1901 struct df *df = dflow->df;
1902 struct dataflow *lr_dflow = df->problems_by_index[DF_LR];
1903 bitmap tmp = BITMAP_ALLOC (NULL);
1904 bitmap_iterator bi;
1905 unsigned int bb_index;
1907 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1909 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1910 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (lr_dflow, bb_index);
1912 /* No register may reach a location where it is not used. Thus
1913 we trim the rr result to the places where it is used. */
1914 bitmap_and_into (bb_info->in, bb_lr_info->in);
1915 bitmap_and_into (bb_info->out, bb_lr_info->out);
1917 #if 1
1918 /* Hard registers may still stick in the ur_out set, but not
1919 be in the ur_in set, if their only mention was in a call
1920 in this block. This is because a call kills in the lr
1921 problem but does not kill in the ur problem. To clean
1922 this up, we execute the transfer function on the lr_in
1923 set and then use that to knock bits out of ur_out. */
1924 bitmap_ior_and_compl (tmp, bb_info->gen, bb_lr_info->in,
1925 bb_info->kill);
1926 bitmap_and_into (bb_info->out, tmp);
1927 #endif
1930 BITMAP_FREE (tmp);
1934 /* Confluence function that ignores fake edges. */
1936 static void
1937 df_ur_confluence_n (struct dataflow *dflow, edge e)
1939 bitmap op1 = df_ur_get_bb_info (dflow, e->dest->index)->in;
1940 bitmap op2 = df_ur_get_bb_info (dflow, e->src->index)->out;
1942 if (e->flags & EDGE_FAKE)
1943 return;
1945 bitmap_ior_into (op1, op2);
1949 /* Transfer function. */
1951 static bool
1952 df_ur_transfer_function (struct dataflow *dflow, int bb_index)
1954 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1955 bitmap in = bb_info->in;
1956 bitmap out = bb_info->out;
1957 bitmap gen = bb_info->gen;
1958 bitmap kill = bb_info->kill;
1960 return bitmap_ior_and_compl (out, gen, in, kill);
1964 /* Free all storage associated with the problem. */
1966 static void
1967 df_ur_free (struct dataflow *dflow)
1969 if (dflow->block_info)
1971 unsigned int i;
1973 for (i = 0; i < dflow->block_info_size; i++)
1975 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, i);
1976 if (bb_info)
1978 BITMAP_FREE (bb_info->gen);
1979 BITMAP_FREE (bb_info->kill);
1980 BITMAP_FREE (bb_info->in);
1981 BITMAP_FREE (bb_info->out);
1985 free_alloc_pool (dflow->block_pool);
1986 dflow->block_info_size = 0;
1987 free (dflow->block_info);
1989 free (dflow);
1993 /* Debugging info. */
1995 static void
1996 df_ur_dump (struct dataflow *dflow, FILE *file)
1998 basic_block bb;
2000 fprintf (file, "Undefined regs:\n");
2002 FOR_ALL_BB (bb)
2004 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb->index);
2005 df_print_bb_index (bb, file);
2007 if (! bb_info->in)
2008 continue;
2010 fprintf (file, " in \t");
2011 dump_bitmap (file, bb_info->in);
2012 fprintf (file, " gen \t");
2013 dump_bitmap (file, bb_info->gen);
2014 fprintf (file, " kill\t");
2015 dump_bitmap (file, bb_info->kill);
2016 fprintf (file, " out \t");
2017 dump_bitmap (file, bb_info->out);
2021 /* All of the information associated with every instance of the problem. */
2023 static struct df_problem problem_UR =
2025 DF_UR, /* Problem id. */
2026 DF_FORWARD, /* Direction. */
2027 df_ur_alloc, /* Allocate the problem specific data. */
2028 NULL, /* Reset global information. */
2029 df_ur_free_bb_info, /* Free basic block info. */
2030 df_ur_local_compute, /* Local compute function. */
2031 df_ur_init, /* Init the solution specific data. */
2032 df_iterative_dataflow, /* Iterative solver. */
2033 NULL, /* Confluence operator 0. */
2034 df_ur_confluence_n, /* Confluence operator n. */
2035 df_ur_transfer_function, /* Transfer function. */
2036 df_ur_local_finalize, /* Finalize function. */
2037 df_ur_free, /* Free all of the problem information. */
2038 df_ur_dump, /* Debugging. */
2039 &problem_LR /* Dependent problem. */
2043 /* Create a new DATAFLOW instance and add it to an existing instance
2044 of DF. The returned structure is what is used to get at the
2045 solution. */
2047 struct dataflow *
2048 df_ur_add_problem (struct df *df)
2050 return df_add_problem (df, &problem_UR);
2055 /*----------------------------------------------------------------------------
2056 UNINITIALIZED REGISTERS WITH EARLYCLOBBER
2058 Find the set of uses for registers that are reachable from the entry
2059 block without passing thru a definition.
2061 This is a variant of the UR problem above that has a lot of special
2062 features just for the register allocation phase.
2063 ----------------------------------------------------------------------------*/
2065 struct df_urec_problem_data
2067 bool earlyclobbers_found; /* True if any instruction contains an
2068 earlyclobber. */
2069 #ifdef STACK_REGS
2070 bitmap stack_regs; /* Registers that may be allocated to a STACK_REGS. */
2071 #endif
2075 /* Get basic block info. */
2077 struct df_urec_bb_info *
2078 df_urec_get_bb_info (struct dataflow *dflow, unsigned int index)
2080 return (struct df_urec_bb_info *) dflow->block_info[index];
2084 /* Set basic block info. */
2086 static void
2087 df_urec_set_bb_info (struct dataflow *dflow, unsigned int index,
2088 struct df_urec_bb_info *bb_info)
2090 dflow->block_info[index] = bb_info;
2094 /* Free basic block info. */
2096 static void
2097 df_urec_free_bb_info (struct dataflow *dflow,
2098 basic_block bb ATTRIBUTE_UNUSED,
2099 void *vbb_info)
2101 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info *) vbb_info;
2102 if (bb_info)
2104 BITMAP_FREE (bb_info->gen);
2105 BITMAP_FREE (bb_info->kill);
2106 BITMAP_FREE (bb_info->in);
2107 BITMAP_FREE (bb_info->out);
2108 BITMAP_FREE (bb_info->earlyclobber);
2109 pool_free (dflow->block_pool, bb_info);
2114 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
2115 not touched unless the block is new. */
2117 static void
2118 df_urec_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
2120 unsigned int bb_index;
2121 bitmap_iterator bi;
2122 struct df_urec_problem_data *problem_data =
2123 (struct df_urec_problem_data *) dflow->problem_data;
2125 if (! dflow->block_pool)
2126 dflow->block_pool = create_alloc_pool ("df_urec_block pool",
2127 sizeof (struct df_urec_bb_info), 50);
2129 if (!dflow->problem_data)
2131 problem_data = XNEW (struct df_urec_problem_data);
2132 dflow->problem_data = problem_data;
2134 problem_data->earlyclobbers_found = false;
2136 df_grow_bb_info (dflow);
2138 /* Because of the clustering of all def sites for the same pseudo,
2139 we have to process all of the blocks before doing the
2140 analysis. */
2142 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
2144 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2145 if (bb_info)
2147 bitmap_clear (bb_info->kill);
2148 bitmap_clear (bb_info->gen);
2149 bitmap_clear (bb_info->earlyclobber);
2151 else
2153 bb_info = (struct df_urec_bb_info *) pool_alloc (dflow->block_pool);
2154 df_urec_set_bb_info (dflow, bb_index, bb_info);
2155 bb_info->kill = BITMAP_ALLOC (NULL);
2156 bb_info->gen = BITMAP_ALLOC (NULL);
2157 bb_info->in = BITMAP_ALLOC (NULL);
2158 bb_info->out = BITMAP_ALLOC (NULL);
2159 bb_info->earlyclobber = BITMAP_ALLOC (NULL);
2165 /* The function modifies local info for register REG being changed in
2166 SETTER. DATA is used to pass the current basic block info. */
2168 static void
2169 df_urec_mark_reg_change (rtx reg, rtx setter, void *data)
2171 int regno;
2172 int endregno;
2173 int i;
2174 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2176 if (GET_CODE (reg) == SUBREG)
2177 reg = SUBREG_REG (reg);
2179 if (!REG_P (reg))
2180 return;
2183 endregno = regno = REGNO (reg);
2184 if (regno < FIRST_PSEUDO_REGISTER)
2186 endregno +=hard_regno_nregs[regno][GET_MODE (reg)];
2188 for (i = regno; i < endregno; i++)
2190 bitmap_set_bit (bb_info->kill, i);
2192 if (GET_CODE (setter) != CLOBBER)
2193 bitmap_set_bit (bb_info->gen, i);
2194 else
2195 bitmap_clear_bit (bb_info->gen, i);
2198 else
2200 bitmap_set_bit (bb_info->kill, regno);
2202 if (GET_CODE (setter) != CLOBBER)
2203 bitmap_set_bit (bb_info->gen, regno);
2204 else
2205 bitmap_clear_bit (bb_info->gen, regno);
2208 /* Classes of registers which could be early clobbered in the current
2209 insn. */
2211 DEF_VEC_I(int);
2212 DEF_VEC_ALLOC_I(int,heap);
2214 static VEC(int,heap) *earlyclobber_regclass;
2216 /* This function finds and stores register classes that could be early
2217 clobbered in INSN. If any earlyclobber classes are found, the function
2218 returns TRUE, in all other cases it returns FALSE. */
2220 static bool
2221 df_urec_check_earlyclobber (rtx insn)
2223 int opno;
2224 bool found = false;
2226 extract_insn (insn);
2228 VEC_truncate (int, earlyclobber_regclass, 0);
2229 for (opno = 0; opno < recog_data.n_operands; opno++)
2231 char c;
2232 bool amp_p;
2233 int i;
2234 enum reg_class class;
2235 const char *p = recog_data.constraints[opno];
2237 class = NO_REGS;
2238 amp_p = false;
2239 for (;;)
2241 c = *p;
2242 switch (c)
2244 case '=': case '+': case '?':
2245 case '#': case '!':
2246 case '*': case '%':
2247 case 'm': case '<': case '>': case 'V': case 'o':
2248 case 'E': case 'F': case 'G': case 'H':
2249 case 's': case 'i': case 'n':
2250 case 'I': case 'J': case 'K': case 'L':
2251 case 'M': case 'N': case 'O': case 'P':
2252 case 'X':
2253 case '0': case '1': case '2': case '3': case '4':
2254 case '5': case '6': case '7': case '8': case '9':
2255 /* These don't say anything we care about. */
2256 break;
2258 case '&':
2259 amp_p = true;
2260 break;
2261 case '\0':
2262 case ',':
2263 if (amp_p && class != NO_REGS)
2265 int rc;
2267 found = true;
2268 for (i = 0;
2269 VEC_iterate (int, earlyclobber_regclass, i, rc);
2270 i++)
2272 if (rc == (int) class)
2273 goto found_rc;
2276 /* We use VEC_quick_push here because
2277 earlyclobber_regclass holds no more than
2278 N_REG_CLASSES elements. */
2279 VEC_quick_push (int, earlyclobber_regclass, (int) class);
2280 found_rc:
2284 amp_p = false;
2285 class = NO_REGS;
2286 break;
2288 case 'r':
2289 class = GENERAL_REGS;
2290 break;
2292 default:
2293 class = REG_CLASS_FROM_CONSTRAINT (c, p);
2294 break;
2296 if (c == '\0')
2297 break;
2298 p += CONSTRAINT_LEN (c, p);
2302 return found;
2305 /* The function checks that pseudo-register *X has a class
2306 intersecting with the class of pseudo-register could be early
2307 clobbered in the same insn.
2309 This function is a no-op if earlyclobber_regclass is empty.
2311 Reload can assign the same hard register to uninitialized
2312 pseudo-register and early clobbered pseudo-register in an insn if
2313 the pseudo-register is used first time in given BB and not lived at
2314 the BB start. To prevent this we don't change life information for
2315 such pseudo-registers. */
2317 static int
2318 df_urec_mark_reg_use_for_earlyclobber (rtx *x, void *data)
2320 enum reg_class pref_class, alt_class;
2321 int i, regno;
2322 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2324 if (REG_P (*x) && REGNO (*x) >= FIRST_PSEUDO_REGISTER)
2326 int rc;
2328 regno = REGNO (*x);
2329 if (bitmap_bit_p (bb_info->kill, regno)
2330 || bitmap_bit_p (bb_info->gen, regno))
2331 return 0;
2332 pref_class = reg_preferred_class (regno);
2333 alt_class = reg_alternate_class (regno);
2334 for (i = 0; VEC_iterate (int, earlyclobber_regclass, i, rc); i++)
2336 if (reg_classes_intersect_p (rc, pref_class)
2337 || (rc != NO_REGS
2338 && reg_classes_intersect_p (rc, alt_class)))
2340 bitmap_set_bit (bb_info->earlyclobber, regno);
2341 break;
2345 return 0;
2348 /* The function processes all pseudo-registers in *X with the aid of
2349 previous function. */
2351 static void
2352 df_urec_mark_reg_use_for_earlyclobber_1 (rtx *x, void *data)
2354 for_each_rtx (x, df_urec_mark_reg_use_for_earlyclobber, data);
2358 /* Compute local uninitialized register info for basic block BB. */
2360 static void
2361 df_urec_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
2363 struct df *df = dflow->df;
2364 basic_block bb = BASIC_BLOCK (bb_index);
2365 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2366 rtx insn;
2367 struct df_ref *def;
2369 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
2370 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2372 unsigned int regno = DF_REF_REGNO (def);
2373 bitmap_set_bit (bb_info->gen, regno);
2376 FOR_BB_INSNS (bb, insn)
2378 if (INSN_P (insn))
2380 note_stores (PATTERN (insn), df_urec_mark_reg_change, bb_info);
2381 if (df_state & (DF_SCAN_GLOBAL | DF_SCAN_POST_ALLOC)
2382 && df_urec_check_earlyclobber (insn))
2384 struct df_urec_problem_data *problem_data =
2385 (struct df_urec_problem_data *) dflow->problem_data;
2386 problem_data->earlyclobbers_found = true;
2387 note_uses (&PATTERN (insn),
2388 df_urec_mark_reg_use_for_earlyclobber_1, bb_info);
2393 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
2394 if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
2396 unsigned int regno = DF_REF_REGNO (def);
2397 bitmap_set_bit (bb_info->gen, regno);
2403 /* Compute local uninitialized register info. */
2405 static void
2406 df_urec_local_compute (struct dataflow *dflow,
2407 bitmap all_blocks ATTRIBUTE_UNUSED,
2408 bitmap rescan_blocks)
2410 unsigned int bb_index;
2411 bitmap_iterator bi;
2412 #ifdef STACK_REGS
2413 int i;
2414 HARD_REG_SET zero, stack_hard_regs, used;
2415 struct df_urec_problem_data *problem_data =
2416 (struct df_urec_problem_data *) dflow->problem_data;
2418 /* Any register that MAY be allocated to a register stack (like the
2419 387) is treated poorly. Each such register is marked as being
2420 live everywhere. This keeps the register allocator and the
2421 subsequent passes from doing anything useful with these values.
2423 FIXME: This seems like an incredibly poor idea. */
2425 CLEAR_HARD_REG_SET (zero);
2426 CLEAR_HARD_REG_SET (stack_hard_regs);
2427 for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
2428 SET_HARD_REG_BIT (stack_hard_regs, i);
2429 problem_data->stack_regs = BITMAP_ALLOC (NULL);
2430 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
2432 COPY_HARD_REG_SET (used, reg_class_contents[reg_preferred_class (i)]);
2433 IOR_HARD_REG_SET (used, reg_class_contents[reg_alternate_class (i)]);
2434 AND_HARD_REG_SET (used, stack_hard_regs);
2435 GO_IF_HARD_REG_EQUAL (used, zero, skip);
2436 bitmap_set_bit (problem_data->stack_regs, i);
2437 skip:
2440 #endif
2442 /* We know that earlyclobber_regclass holds no more than
2443 N_REG_CLASSES elements. See df_urec_check_earlyclobber. */
2444 earlyclobber_regclass = VEC_alloc (int, heap, N_REG_CLASSES);
2446 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks, 0, bb_index, bi)
2448 df_urec_bb_local_compute (dflow, bb_index);
2451 VEC_free (int, heap, earlyclobber_regclass);
2455 /* Initialize the solution vectors. */
2457 static void
2458 df_urec_init (struct dataflow *dflow, bitmap all_blocks)
2460 unsigned int bb_index;
2461 bitmap_iterator bi;
2463 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2465 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2467 bitmap_copy (bb_info->out, bb_info->gen);
2468 bitmap_clear (bb_info->in);
2473 /* Or in the stack regs, hard regs and early clobber regs into the the
2474 ur_in sets of all of the blocks. */
2476 static void
2477 df_urec_local_finalize (struct dataflow *dflow, bitmap all_blocks)
2479 struct df *df = dflow->df;
2480 struct dataflow *lr_dflow = df->problems_by_index[DF_LR];
2481 bitmap tmp = BITMAP_ALLOC (NULL);
2482 bitmap_iterator bi;
2483 unsigned int bb_index;
2484 struct df_urec_problem_data *problem_data =
2485 (struct df_urec_problem_data *) dflow->problem_data;
2487 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2489 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2490 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (lr_dflow, bb_index);
2492 if (bb_index != ENTRY_BLOCK && bb_index != EXIT_BLOCK)
2494 if (problem_data->earlyclobbers_found)
2495 bitmap_ior_into (bb_info->in, bb_info->earlyclobber);
2497 #ifdef STACK_REGS
2498 /* We can not use the same stack register for uninitialized
2499 pseudo-register and another living pseudo-register
2500 because if the uninitialized pseudo-register dies,
2501 subsequent pass reg-stack will be confused (it will
2502 believe that the other register dies). */
2503 bitmap_ior_into (bb_info->in, problem_data->stack_regs);
2504 bitmap_ior_into (bb_info->out, problem_data->stack_regs);
2505 #endif
2508 /* No register may reach a location where it is not used. Thus
2509 we trim the rr result to the places where it is used. */
2510 bitmap_and_into (bb_info->in, bb_lr_info->in);
2511 bitmap_and_into (bb_info->out, bb_lr_info->out);
2513 #if 1
2514 /* Hard registers may still stick in the ur_out set, but not
2515 be in the ur_in set, if their only mention was in a call
2516 in this block. This is because a call kills in the lr
2517 problem but does not kill in the rr problem. To clean
2518 this up, we execute the transfer function on the lr_in
2519 set and then use that to knock bits out of ur_out. */
2520 bitmap_ior_and_compl (tmp, bb_info->gen, bb_lr_info->in,
2521 bb_info->kill);
2522 bitmap_and_into (bb_info->out, tmp);
2523 #endif
2526 #ifdef STACK_REGS
2527 BITMAP_FREE (problem_data->stack_regs);
2528 #endif
2529 BITMAP_FREE (tmp);
2533 /* Confluence function that ignores fake edges. */
2535 static void
2536 df_urec_confluence_n (struct dataflow *dflow, edge e)
2538 bitmap op1 = df_urec_get_bb_info (dflow, e->dest->index)->in;
2539 bitmap op2 = df_urec_get_bb_info (dflow, e->src->index)->out;
2541 if (e->flags & EDGE_FAKE)
2542 return;
2544 bitmap_ior_into (op1, op2);
2548 /* Transfer function. */
2550 static bool
2551 df_urec_transfer_function (struct dataflow *dflow, int bb_index)
2553 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2554 bitmap in = bb_info->in;
2555 bitmap out = bb_info->out;
2556 bitmap gen = bb_info->gen;
2557 bitmap kill = bb_info->kill;
2559 return bitmap_ior_and_compl (out, gen, in, kill);
2563 /* Free all storage associated with the problem. */
2565 static void
2566 df_urec_free (struct dataflow *dflow)
2568 if (dflow->block_info)
2570 unsigned int i;
2572 for (i = 0; i < dflow->block_info_size; i++)
2574 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, i);
2575 if (bb_info)
2577 BITMAP_FREE (bb_info->gen);
2578 BITMAP_FREE (bb_info->kill);
2579 BITMAP_FREE (bb_info->in);
2580 BITMAP_FREE (bb_info->out);
2581 BITMAP_FREE (bb_info->earlyclobber);
2585 free_alloc_pool (dflow->block_pool);
2587 dflow->block_info_size = 0;
2588 free (dflow->block_info);
2589 free (dflow->problem_data);
2591 free (dflow);
2595 /* Debugging info. */
2597 static void
2598 df_urec_dump (struct dataflow *dflow, FILE *file)
2600 basic_block bb;
2602 fprintf (file, "Undefined regs:\n");
2604 FOR_ALL_BB (bb)
2606 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb->index);
2607 df_print_bb_index (bb, file);
2609 if (! bb_info->in)
2610 continue;
2612 fprintf (file, " in \t");
2613 dump_bitmap (file, bb_info->in);
2614 fprintf (file, " gen \t");
2615 dump_bitmap (file, bb_info->gen);
2616 fprintf (file, " kill\t");
2617 dump_bitmap (file, bb_info->kill);
2618 fprintf (file, " ec\t");
2619 dump_bitmap (file, bb_info->earlyclobber);
2620 fprintf (file, " out \t");
2621 dump_bitmap (file, bb_info->out);
2625 /* All of the information associated with every instance of the problem. */
2627 static struct df_problem problem_UREC =
2629 DF_UREC, /* Problem id. */
2630 DF_FORWARD, /* Direction. */
2631 df_urec_alloc, /* Allocate the problem specific data. */
2632 NULL, /* Reset global information. */
2633 df_urec_free_bb_info, /* Free basic block info. */
2634 df_urec_local_compute, /* Local compute function. */
2635 df_urec_init, /* Init the solution specific data. */
2636 df_iterative_dataflow, /* Iterative solver. */
2637 NULL, /* Confluence operator 0. */
2638 df_urec_confluence_n, /* Confluence operator n. */
2639 df_urec_transfer_function, /* Transfer function. */
2640 df_urec_local_finalize, /* Finalize function. */
2641 df_urec_free, /* Free all of the problem information. */
2642 df_urec_dump, /* Debugging. */
2643 &problem_LR /* Dependent problem. */
2647 /* Create a new DATAFLOW instance and add it to an existing instance
2648 of DF. The returned structure is what is used to get at the
2649 solution. */
2651 struct dataflow *
2652 df_urec_add_problem (struct df *df)
2654 return df_add_problem (df, &problem_UREC);
2659 /*----------------------------------------------------------------------------
2660 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
2662 Link either the defs to the uses and / or the uses to the defs.
2664 These problems are set up like the other dataflow problems so that
2665 they nicely fit into the framework. They are much simpler and only
2666 involve a single traversal of instructions and an examination of
2667 the reaching defs information (the dependent problem).
2668 ----------------------------------------------------------------------------*/
2670 struct df_chain_problem_data
2672 int flags;
2676 /* Create def-use or use-def chains. */
2678 static void
2679 df_chain_alloc (struct dataflow *dflow,
2680 bitmap blocks_to_rescan ATTRIBUTE_UNUSED)
2682 struct df *df = dflow->df;
2683 unsigned int i;
2684 struct df_chain_problem_data *problem_data =
2685 (struct df_chain_problem_data *) dflow->problem_data;
2687 /* Wholesale destruction of the old chains. */
2688 if (dflow->block_pool)
2689 free_alloc_pool (dflow->block_pool);
2691 dflow->block_pool = create_alloc_pool ("df_chain_chain_block pool",
2692 sizeof (struct df_link), 100);
2694 if (problem_data->flags & DF_DU_CHAIN)
2696 if (!df->def_info.refs_organized)
2697 df_reorganize_refs (&df->def_info);
2699 /* Clear out the pointers from the refs. */
2700 for (i = 0; i < DF_DEFS_SIZE (df); i++)
2702 struct df_ref *ref = df->def_info.refs[i];
2703 DF_REF_CHAIN (ref) = NULL;
2707 if (problem_data->flags & DF_UD_CHAIN)
2709 if (!df->use_info.refs_organized)
2710 df_reorganize_refs (&df->use_info);
2711 for (i = 0; i < DF_USES_SIZE (df); i++)
2713 struct df_ref *ref = df->use_info.refs[i];
2714 DF_REF_CHAIN (ref) = NULL;
2720 /* Reset all def_use and use_def chains in INSN. */
2722 static void
2723 df_chain_insn_reset (struct dataflow *dflow, rtx insn)
2725 struct df *df = dflow->df;
2726 struct df_chain_problem_data *problem_data =
2727 (struct df_chain_problem_data *) dflow->problem_data;
2728 unsigned int uid = INSN_UID (insn);
2729 struct df_insn_info *insn_info = NULL;
2730 struct df_ref *ref;
2732 if (uid < df->insns_size)
2733 insn_info = DF_INSN_UID_GET (df, uid);
2735 if (insn_info)
2737 if (problem_data->flags & DF_DU_CHAIN)
2739 ref = insn_info->defs;
2740 while (ref)
2742 ref->chain = NULL;
2743 ref = ref->next_ref;
2747 if (problem_data->flags & DF_UD_CHAIN)
2749 ref = insn_info->uses;
2750 while (ref)
2752 ref->chain = NULL;
2753 ref = ref->next_ref;
2760 /* Reset all def_use and use_def chains in basic block. */
2762 static void
2763 df_chain_bb_reset (struct dataflow *dflow, unsigned int bb_index)
2765 struct df *df = dflow->df;
2766 struct df_chain_problem_data *problem_data =
2767 (struct df_chain_problem_data *) dflow->problem_data;
2768 rtx insn;
2769 basic_block bb = BASIC_BLOCK (bb_index);
2771 /* Some one deleted the basic block out from under us. */
2772 if (!bb)
2773 return;
2775 FOR_BB_INSNS (bb, insn)
2777 if (INSN_P (insn))
2779 /* Record defs within INSN. */
2780 df_chain_insn_reset (dflow, insn);
2784 /* Get rid of any chains in artificial uses or defs. */
2785 if (problem_data->flags & DF_DU_CHAIN)
2787 struct df_ref *def;
2788 def = df_get_artificial_defs (df, bb_index);
2789 while (def)
2791 def->chain = NULL;
2792 def = def->next_ref;
2796 if (problem_data->flags & DF_UD_CHAIN)
2798 struct df_ref *use;
2799 use = df_get_artificial_uses (df, bb_index);
2800 while (use)
2802 use->chain = NULL;
2803 use = use->next_ref;
2809 /* Reset all of the chains when the set of basic blocks changes. */
2812 static void
2813 df_chain_reset (struct dataflow *dflow, bitmap blocks_to_clear)
2815 bitmap_iterator bi;
2816 unsigned int bb_index;
2818 EXECUTE_IF_SET_IN_BITMAP (blocks_to_clear, 0, bb_index, bi)
2820 df_chain_bb_reset (dflow, bb_index);
2823 free_alloc_pool (dflow->block_pool);
2824 dflow->block_pool = NULL;
2828 /* Create the chains for a list of USEs. */
2830 static void
2831 df_chain_create_bb_process_use (struct dataflow *dflow,
2832 struct df_chain_problem_data *problem_data,
2833 bitmap local_rd,
2834 struct df_ref *use,
2835 enum df_ref_flags top_flag)
2837 struct df *df = dflow->df;
2838 bitmap_iterator bi;
2839 unsigned int def_index;
2841 while (use)
2843 /* Do not want to go through this for an uninitialized var. */
2844 unsigned int uregno = DF_REF_REGNO (use);
2845 int count = DF_REG_DEF_GET (df, uregno)->n_refs;
2846 if (count)
2848 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2850 unsigned int first_index = DF_REG_DEF_GET (df, uregno)->begin;
2851 unsigned int last_index = first_index + count - 1;
2853 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2855 struct df_ref *def;
2856 if (def_index > last_index)
2857 break;
2859 def = DF_DEFS_GET (df, def_index);
2860 if (problem_data->flags & DF_DU_CHAIN)
2861 df_chain_create (dflow, def, use);
2862 if (problem_data->flags & DF_UD_CHAIN)
2863 df_chain_create (dflow, use, def);
2867 use = use->next_ref;
2871 /* Reset the storage pool that the def-use or use-def chains have been
2872 allocated in. We do not need to re adjust the pointers in the refs,
2873 these have already been clean out.*/
2875 /* Create chains from reaching defs bitmaps for basic block BB. */
2876 static void
2877 df_chain_create_bb (struct dataflow *dflow,
2878 struct dataflow *rd_dflow,
2879 unsigned int bb_index)
2881 basic_block bb = BASIC_BLOCK (bb_index);
2882 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (rd_dflow, bb_index);
2883 rtx insn;
2884 bitmap cpy = BITMAP_ALLOC (NULL);
2885 struct df *df = dflow->df;
2886 struct df_chain_problem_data *problem_data =
2887 (struct df_chain_problem_data *) dflow->problem_data;
2888 struct df_ref *def;
2890 bitmap_copy (cpy, bb_info->in);
2892 /* Since we are going forwards, process the artificial uses first
2893 then the artificial defs second. */
2895 #ifdef EH_USES
2896 /* Create the chains for the artificial uses from the EH_USES at the
2897 beginning of the block. */
2898 df_chain_create_bb_process_use (dflow, problem_data, cpy,
2899 df_get_artificial_uses (df, bb->index),
2900 DF_REF_AT_TOP);
2901 #endif
2903 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
2904 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
2906 unsigned int dregno = DF_REF_REGNO (def);
2907 bitmap_clear_range (cpy,
2908 DF_REG_DEF_GET (df, dregno)->begin,
2909 DF_REG_DEF_GET (df, dregno)->n_refs);
2910 if (! (DF_REF_FLAGS (def) & DF_REF_CLOBBER))
2911 bitmap_set_bit (cpy, DF_REF_ID (def));
2914 /* Process the regular instructions next. */
2915 FOR_BB_INSNS (bb, insn)
2917 struct df_ref *def;
2918 unsigned int uid = INSN_UID (insn);
2920 if (! INSN_P (insn))
2921 continue;
2923 /* Now scan the uses and link them up with the defs that remain
2924 in the cpy vector. */
2926 df_chain_create_bb_process_use (dflow, problem_data, cpy,
2927 DF_INSN_UID_GET (df, uid)->uses, 0);
2929 /* Since we are going forwards, process the defs second. This
2930 pass only changes the bits in cpy. */
2931 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
2933 unsigned int dregno = DF_REF_REGNO (def);
2934 bitmap_clear_range (cpy,
2935 DF_REG_DEF_GET (df, dregno)->begin,
2936 DF_REG_DEF_GET (df, dregno)->n_refs);
2937 if (! (DF_REF_FLAGS (def) & DF_REF_CLOBBER))
2938 bitmap_set_bit (cpy, DF_REF_ID (def));
2942 /* Create the chains for the artificial uses of the hard registers
2943 at the end of the block. */
2944 df_chain_create_bb_process_use (dflow, problem_data, cpy,
2945 df_get_artificial_uses (df, bb->index), 0);
2948 /* Create def-use chains from reaching use bitmaps for basic blocks
2949 in BLOCKS. */
2951 static void
2952 df_chain_finalize (struct dataflow *dflow, bitmap all_blocks)
2954 unsigned int bb_index;
2955 bitmap_iterator bi;
2956 struct df *df = dflow->df;
2957 struct dataflow *rd_dflow = df->problems_by_index [DF_RD];
2959 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2961 df_chain_create_bb (dflow, rd_dflow, bb_index);
2966 /* Free all storage associated with the problem. */
2968 static void
2969 df_chain_free (struct dataflow *dflow)
2971 free_alloc_pool (dflow->block_pool);
2972 free (dflow->problem_data);
2973 free (dflow);
2977 /* Debugging info. */
2979 static void
2980 df_chains_dump (struct dataflow *dflow, FILE *file)
2982 struct df *df = dflow->df;
2983 unsigned int j;
2984 struct df_chain_problem_data *problem_data =
2985 (struct df_chain_problem_data *) dflow->problem_data;
2987 if (problem_data->flags & DF_DU_CHAIN)
2989 fprintf (file, "Def-use chains:\n");
2990 for (j = 0; j < df->def_info.bitmap_size; j++)
2992 struct df_ref *def = DF_DEFS_GET (df, j);
2993 if (def)
2995 fprintf (file, "d%d bb %d luid %d insn %d reg %d ",
2996 j, DF_REF_BBNO (def),
2997 DF_INSN_LUID (df, DF_REF_INSN (def)),
2998 DF_REF_INSN (def) ? DF_REF_INSN_UID (def) : -1,
2999 DF_REF_REGNO (def));
3000 if (def->flags & DF_REF_READ_WRITE)
3001 fprintf (file, "read/write ");
3002 df_chain_dump (df, DF_REF_CHAIN (def), file);
3003 fprintf (file, "\n");
3008 if (problem_data->flags & DF_UD_CHAIN)
3010 fprintf (file, "Use-def chains:\n");
3011 for (j = 0; j < df->use_info.bitmap_size; j++)
3013 struct df_ref *use = DF_USES_GET (df, j);
3014 if (use)
3016 fprintf (file, "u%d bb %d luid %d insn %d reg %d ",
3017 j, DF_REF_BBNO (use),
3018 DF_REF_INSN (use) ?
3019 DF_INSN_LUID (df, DF_REF_INSN (use))
3020 : -1,
3021 DF_REF_INSN (DF_USES_GET (df, j)) ?
3022 DF_REF_INSN_UID (DF_USES_GET (df,j))
3023 : -1,
3024 DF_REF_REGNO (use));
3025 if (use->flags & DF_REF_READ_WRITE)
3026 fprintf (file, "read/write ");
3027 if (use->flags & DF_REF_STRIPPED)
3028 fprintf (file, "stripped ");
3029 if (use->flags & DF_REF_IN_NOTE)
3030 fprintf (file, "note ");
3031 df_chain_dump (df, DF_REF_CHAIN (use), file);
3032 fprintf (file, "\n");
3039 static struct df_problem problem_CHAIN =
3041 DF_CHAIN, /* Problem id. */
3042 DF_NONE, /* Direction. */
3043 df_chain_alloc, /* Allocate the problem specific data. */
3044 df_chain_reset, /* Reset global information. */
3045 NULL, /* Free basic block info. */
3046 NULL, /* Local compute function. */
3047 NULL, /* Init the solution specific data. */
3048 NULL, /* Iterative solver. */
3049 NULL, /* Confluence operator 0. */
3050 NULL, /* Confluence operator n. */
3051 NULL, /* Transfer function. */
3052 df_chain_finalize, /* Finalize function. */
3053 df_chain_free, /* Free all of the problem information. */
3054 df_chains_dump, /* Debugging. */
3055 &problem_RD /* Dependent problem. */
3059 /* Create a new DATAFLOW instance and add it to an existing instance
3060 of DF. The returned structure is what is used to get at the
3061 solution. */
3063 struct dataflow *
3064 df_chain_add_problem (struct df *df, int flags)
3066 struct df_chain_problem_data *problem_data =
3067 XNEW (struct df_chain_problem_data);
3068 struct dataflow *dflow = df_add_problem (df, &problem_CHAIN);
3070 dflow->problem_data = problem_data;
3071 problem_data->flags = flags;
3073 return dflow;
3077 /*----------------------------------------------------------------------------
3078 REGISTER INFORMATION
3080 Currently this consists of only lifetime information. But the plan is
3081 to enhance it so that it produces all of the register information needed
3082 by the register allocators.
3083 ----------------------------------------------------------------------------*/
3086 struct df_ri_problem_data
3088 int *lifetime;
3092 /* Allocate the lifetime information. */
3094 static void
3095 df_ri_alloc (struct dataflow *dflow, bitmap blocks_to_rescan ATTRIBUTE_UNUSED)
3097 struct df_ri_problem_data *problem_data =
3098 (struct df_ri_problem_data *) dflow->problem_data;
3100 if (!dflow->problem_data)
3102 struct df_ri_problem_data *problem_data = XNEW (struct df_ri_problem_data);
3103 dflow->problem_data = problem_data;
3106 problem_data->lifetime = xrealloc (problem_data->lifetime,
3107 max_reg_num () *sizeof (int));
3108 memset (problem_data->lifetime, 0, max_reg_num () *sizeof (int));
3111 /* Compute register info: lifetime, bb, and number of defs and uses
3112 for basic block BB. */
3114 static void
3115 df_ri_bb_compute (struct dataflow *dflow, unsigned int bb_index, bitmap live)
3117 struct df *df = dflow->df;
3118 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
3119 struct df_ri_problem_data *problem_data =
3120 (struct df_ri_problem_data *) dflow->problem_data;
3121 basic_block bb = BASIC_BLOCK (bb_index);
3122 rtx insn;
3124 bitmap_copy (live, bb_info->out);
3126 FOR_BB_INSNS_REVERSE (bb, insn)
3128 unsigned int uid = INSN_UID (insn);
3129 unsigned int regno;
3130 bitmap_iterator bi;
3131 struct df_ref *def;
3132 struct df_ref *use;
3134 if (! INSN_P (insn))
3135 continue;
3137 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
3139 unsigned int dregno = DF_REF_REGNO (def);
3141 /* Kill this register. */
3142 bitmap_clear_bit (live, dregno);
3145 for (use = DF_INSN_UID_GET (df, uid)->uses; use; use = use->next_ref)
3147 unsigned int uregno = DF_REF_REGNO (use);
3149 if (!bitmap_bit_p (live, uregno))
3151 use->flags |= DF_REF_DIES_AFTER_THIS_USE;
3152 /* This register is now live. */
3153 bitmap_set_bit (live, uregno);
3155 else
3156 use->flags &= ~DF_REF_DIES_AFTER_THIS_USE;
3159 /* Increment lifetimes of all live registers. */
3160 EXECUTE_IF_SET_IN_BITMAP (live, 0, regno, bi)
3162 problem_data->lifetime[regno]++;
3168 /* Compute register info: lifetime, bb, and number of defs and uses. */
3169 static void
3170 df_ri_compute (struct dataflow *dflow, bitmap all_blocks ATTRIBUTE_UNUSED,
3171 bitmap blocks_to_scan)
3173 unsigned int bb_index;
3174 bitmap_iterator bi;
3175 bitmap live;
3177 live = BITMAP_ALLOC (NULL);
3179 EXECUTE_IF_SET_IN_BITMAP (blocks_to_scan, 0, bb_index, bi)
3181 df_ri_bb_compute (dflow, bb_index, live);
3184 BITMAP_FREE (live);
3188 /* Free all storage associated with the problem. */
3190 static void
3191 df_ri_free (struct dataflow *dflow)
3193 struct df_ri_problem_data *problem_data =
3194 (struct df_ri_problem_data *) dflow->problem_data;
3196 free (problem_data->lifetime);
3197 free (dflow->problem_data);
3198 free (dflow);
3202 /* Debugging info. */
3204 static void
3205 df_ri_dump (struct dataflow *dflow, FILE *file)
3207 struct df_ri_problem_data *problem_data =
3208 (struct df_ri_problem_data *) dflow->problem_data;
3209 int j;
3211 fprintf (file, "Register info:\n");
3212 for (j = 0; j < max_reg_num (); j++)
3214 fprintf (file, "reg %d life %d\n", j, problem_data->lifetime[j]);
3218 /* All of the information associated every instance of the problem. */
3220 static struct df_problem problem_RI =
3222 DF_RI, /* Problem id. */
3223 DF_NONE, /* Direction. */
3224 df_ri_alloc, /* Allocate the problem specific data. */
3225 NULL, /* Reset global information. */
3226 NULL, /* Free basic block info. */
3227 df_ri_compute, /* Local compute function. */
3228 NULL, /* Init the solution specific data. */
3229 NULL, /* Iterative solver. */
3230 NULL, /* Confluence operator 0. */
3231 NULL, /* Confluence operator n. */
3232 NULL, /* Transfer function. */
3233 NULL, /* Finalize function. */
3234 df_ri_free, /* Free all of the problem information. */
3235 df_ri_dump, /* Debugging. */
3236 &problem_UR /* Dependent problem. */
3240 /* Create a new DATAFLOW instance and add it to an existing instance
3241 of DF. The returned structure is what is used to get at the
3242 solution. */
3244 struct dataflow *
3245 df_ri_add_problem (struct df *df)
3247 return df_add_problem (df, &problem_RI);
3251 /* Return total lifetime (in insns) of REG. */
3253 df_reg_lifetime (struct df *df, rtx reg)
3255 struct dataflow *dflow = df->problems_by_index[DF_RI];
3256 struct df_ri_problem_data *problem_data =
3257 (struct df_ri_problem_data *) dflow->problem_data;
3258 return problem_data->lifetime[REGNO (reg)];