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
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
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
28 #include "coretypes.h"
32 #include "insn-config.h"
37 #include "alloc-pool.h"
39 #include "hard-reg-set.h"
40 #include "basic-block.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. */
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. */
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;
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. */
90 df_chain_unlink (struct dataflow *dflow, struct df_ref *ref, struct df_link *link)
92 struct df_link *chain = DF_REF_CHAIN (ref);
95 /* Link was the first element in the chain. */
97 DF_REF_CHAIN (ref) = link->next;
100 /* Link is an internal element in the chain. */
101 struct df_link *prev = chain;
106 prev->next = chain->next;
113 pool_free (dflow->block_pool, link);
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
123 struct df_link *next = chain->next;
124 /* Delete the other side if it exists. */
125 df_chain_unlink (dflow, chain->ref, chain);
132 /* Copy the du or ud chain starting at FROM_REF and attach it to
136 df_chain_copy (struct dataflow *dflow,
137 struct df_ref *to_ref,
138 struct df_link *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
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);
161 return DF_UPWARD_LIVE_IN (df, bb);
165 /* Get the live out set for BB no matter what problem happens to be
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);
178 return DF_UPWARD_LIVE_OUT (df, bb);
182 /*----------------------------------------------------------------------------
184 ----------------------------------------------------------------------------*/
186 /* Generic versions to get the void* version of the block info. Only
187 used inside the problem instace vectors. */
189 /* Grow the bb_info array. */
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. */
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);
224 /* Print some basic block info as part of df_dump. */
227 df_print_bb_index (basic_block bb, FILE *file)
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. */
251 df_ref_bitmap (bitmap *maps, unsigned int regno, int start, int count)
253 bitmap ids = maps[regno];
257 unsigned int end = start + count;;
258 ids = BITMAP_ALLOC (NULL);
260 for (i = start; i < end; i++)
261 bitmap_set_bit (ids, i);
267 /* Make sure that the seen_in_insn and seen_in_block sbitmaps are set
273 seen_in_block = BITMAP_ALLOC (NULL);
274 seen_in_insn = BITMAP_ALLOC (NULL);
281 BITMAP_FREE (seen_in_block);
282 BITMAP_FREE (seen_in_insn);
287 /*----------------------------------------------------------------------------
290 Find the locations in the function where each use site for a pseudo
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 invalidate 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. */
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. */
327 df_ru_free_bb_info (struct dataflow *dflow, void *vbb_info)
329 struct df_ru_bb_info *bb_info = (struct df_ru_bb_info *) vbb_info;
332 BITMAP_FREE (bb_info->kill);
333 BITMAP_FREE (bb_info->sparse_kill);
334 BITMAP_FREE (bb_info->gen);
335 BITMAP_FREE (bb_info->in);
336 BITMAP_FREE (bb_info->out);
337 pool_free (dflow->block_pool, bb_info);
342 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
343 not touched unless the block is new. */
346 df_ru_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
348 unsigned int bb_index;
350 unsigned int reg_size = max_reg_num ();
352 if (! dflow->block_pool)
353 dflow->block_pool = create_alloc_pool ("df_ru_block pool",
354 sizeof (struct df_ru_bb_info), 50);
356 if (dflow->problem_data)
359 struct df_ru_problem_data *problem_data =
360 (struct df_ru_problem_data *) dflow->problem_data;
362 for (i = 0; i < problem_data->use_sites_size; i++)
364 bitmap bm = problem_data->use_sites[i];
368 problem_data->use_sites[i] = NULL;
372 if (problem_data->use_sites_size < reg_size)
374 problem_data->use_sites
375 = xrealloc (problem_data->use_sites, reg_size * sizeof (bitmap));
376 memset (problem_data->use_sites + problem_data->use_sites_size, 0,
377 (reg_size - problem_data->use_sites_size) * sizeof (bitmap));
378 problem_data->use_sites_size = reg_size;
381 bitmap_clear (problem_data->sparse_invalidated_by_call);
382 bitmap_clear (problem_data->dense_invalidated_by_call);
386 struct df_ru_problem_data *problem_data =
387 xmalloc (sizeof (struct df_ru_problem_data));
388 dflow->problem_data = problem_data;
390 problem_data->use_sites = xcalloc (reg_size, sizeof (bitmap));
391 problem_data->use_sites_size = reg_size;
392 problem_data->sparse_invalidated_by_call = BITMAP_ALLOC (NULL);
393 problem_data->dense_invalidated_by_call = BITMAP_ALLOC (NULL);
396 df_grow_bb_info (dflow);
398 /* Because of the clustering of all def sites for the same pseudo,
399 we have to process all of the blocks before doing the
402 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
404 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
407 bitmap_clear (bb_info->kill);
408 bitmap_clear (bb_info->sparse_kill);
409 bitmap_clear (bb_info->gen);
413 bb_info = (struct df_ru_bb_info *) pool_alloc (dflow->block_pool);
414 df_ru_set_bb_info (dflow, bb_index, bb_info);
415 bb_info->kill = BITMAP_ALLOC (NULL);
416 bb_info->sparse_kill = BITMAP_ALLOC (NULL);
417 bb_info->gen = BITMAP_ALLOC (NULL);
418 bb_info->in = BITMAP_ALLOC (NULL);
419 bb_info->out = BITMAP_ALLOC (NULL);
425 /* Process a list of DEFs for df_ru_bb_local_compute. */
428 df_ru_bb_local_compute_process_def (struct dataflow *dflow,
429 struct df_ru_bb_info *bb_info,
432 struct df *df = dflow->df;
435 unsigned int regno = DF_REF_REGNO (def);
436 unsigned int begin = DF_REG_USE_GET (df, regno)->begin;
437 unsigned int n_uses = DF_REG_USE_GET (df, regno)->n_refs;
438 if (!bitmap_bit_p (seen_in_block, regno))
440 /* The first def for regno, causes the kill info to be
441 generated and the gen information to cleared. */
442 if (!bitmap_bit_p (seen_in_insn, regno))
444 if (n_uses > DF_SPARSE_THRESHOLD)
446 bitmap_set_bit (bb_info->sparse_kill, regno);
447 bitmap_clear_range (bb_info->gen, begin, n_uses);
451 struct df_ru_problem_data *problem_data =
452 (struct df_ru_problem_data *) dflow->problem_data;
454 df_ref_bitmap (problem_data->use_sites, regno,
456 bitmap_ior_into (bb_info->kill, uses);
457 bitmap_and_compl_into (bb_info->gen, uses);
460 bitmap_set_bit (seen_in_insn, regno);
467 /* Process a list of USEs for df_ru_bb_local_compute. */
470 df_ru_bb_local_compute_process_use (struct df_ru_bb_info *bb_info,
472 enum df_ref_flags top_flag)
476 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
478 /* Add use to set of gens in this BB unless we have seen a
479 def in a previous instruction. */
480 unsigned int regno = DF_REF_REGNO (use);
481 if (!bitmap_bit_p (seen_in_block, regno))
482 bitmap_set_bit (bb_info->gen, DF_REF_ID (use));
488 /* Compute local reaching use (upward exposed use) info for basic
489 block BB. USE_INFO->REGS[R] caches the set of uses for register R. */
491 df_ru_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
493 struct df *df = dflow->df;
494 basic_block bb = BASIC_BLOCK (bb_index);
495 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
498 /* Set when a def for regno is seen. */
499 bitmap_clear (seen_in_block);
500 bitmap_clear (seen_in_insn);
503 /* Variables defined in the prolog that are used by the exception
505 df_ru_bb_local_compute_process_use (bb_info,
506 df_get_artificial_uses (df, bb_index),
510 /* Process the artificial defs first since these are at the top of
512 df_ru_bb_local_compute_process_def (dflow, bb_info,
513 df_get_artificial_defs (df, bb_index));
515 FOR_BB_INSNS (bb, insn)
517 unsigned int uid = INSN_UID (insn);
521 df_ru_bb_local_compute_process_def (dflow, bb_info,
522 DF_INSN_UID_GET (df, uid)->defs);
524 /* The use processing must happen after the defs processing even
525 though the uses logically happen first since the defs clear
526 the gen set. Otherwise, a use for regno occuring in the same
527 instruction as a def for regno would be cleared. */
528 df_ru_bb_local_compute_process_use (bb_info,
529 DF_INSN_UID_GET (df, uid)->uses, 0);
531 bitmap_ior_into (seen_in_block, seen_in_insn);
532 bitmap_clear (seen_in_insn);
535 /* Process the hardware registers that are always live. */
536 df_ru_bb_local_compute_process_use (bb_info,
537 df_get_artificial_uses (df, bb_index), 0);
541 /* Compute local reaching use (upward exposed use) info for each basic
542 block within BLOCKS. */
544 df_ru_local_compute (struct dataflow *dflow,
546 bitmap rescan_blocks ATTRIBUTE_UNUSED)
548 struct df *df = dflow->df;
549 unsigned int bb_index;
552 struct df_ru_problem_data *problem_data =
553 (struct df_ru_problem_data *) dflow->problem_data;
554 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
555 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
559 if (!df->use_info.refs_organized)
560 df_reorganize_refs (&df->use_info);
562 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
564 df_ru_bb_local_compute (dflow, bb_index);
567 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
568 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
570 struct df_reg_info *reg_info = DF_REG_USE_GET (df, regno);
571 if (reg_info->n_refs > DF_SPARSE_THRESHOLD)
572 bitmap_set_bit (sparse_invalidated, regno);
575 bitmap defs = df_ref_bitmap (problem_data->use_sites, regno,
576 reg_info->begin, reg_info->n_refs);
577 bitmap_ior_into (dense_invalidated, defs);
585 /* Initialize the solution bit vectors for problem. */
588 df_ru_init_solution (struct dataflow *dflow, bitmap all_blocks)
590 unsigned int bb_index;
593 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
595 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
596 bitmap_copy (bb_info->in, bb_info->gen);
597 bitmap_clear (bb_info->out);
602 /* Out of target gets or of in of source. */
605 df_ru_confluence_n (struct dataflow *dflow, edge e)
607 bitmap op1 = df_ru_get_bb_info (dflow, e->src->index)->out;
608 bitmap op2 = df_ru_get_bb_info (dflow, e->dest->index)->in;
610 if (e->flags & EDGE_EH)
612 struct df_ru_problem_data *problem_data =
613 (struct df_ru_problem_data *) dflow->problem_data;
614 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
615 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
616 struct df *df = dflow->df;
619 bitmap tmp = BITMAP_ALLOC (NULL);
621 bitmap_copy (tmp, op2);
622 bitmap_and_compl_into (tmp, dense_invalidated);
624 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
626 bitmap_clear_range (tmp,
627 DF_REG_USE_GET (df, regno)->begin,
628 DF_REG_USE_GET (df, regno)->n_refs);
630 bitmap_ior_into (op1, tmp);
634 bitmap_ior_into (op1, op2);
638 /* Transfer function. */
641 df_ru_transfer_function (struct dataflow *dflow, int bb_index)
643 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb_index);
646 bitmap in = bb_info->in;
647 bitmap out = bb_info->out;
648 bitmap gen = bb_info->gen;
649 bitmap kill = bb_info->kill;
650 bitmap sparse_kill = bb_info->sparse_kill;
652 if (bitmap_empty_p (sparse_kill))
653 return bitmap_ior_and_compl (in, gen, out, kill);
656 struct df *df = dflow->df;
657 bool changed = false;
658 bitmap tmp = BITMAP_ALLOC (NULL);
659 bitmap_copy (tmp, in);
660 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
662 bitmap_clear_range (tmp,
663 DF_REG_USE_GET (df, regno)->begin,
664 DF_REG_USE_GET (df, regno)->n_refs);
666 bitmap_and_compl_into (tmp, kill);
667 bitmap_ior_into (tmp, gen);
668 changed = !bitmap_equal_p (tmp, in);
681 /* Free all storage associated with the problem. */
684 df_ru_free (struct dataflow *dflow)
687 struct df_ru_problem_data *problem_data =
688 (struct df_ru_problem_data *) dflow->problem_data;
690 for (i = 0; i < dflow->block_info_size; i++)
692 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, i);
695 BITMAP_FREE (bb_info->kill);
696 BITMAP_FREE (bb_info->sparse_kill);
697 BITMAP_FREE (bb_info->gen);
698 BITMAP_FREE (bb_info->in);
699 BITMAP_FREE (bb_info->out);
703 free_alloc_pool (dflow->block_pool);
705 for (i = 0; i < problem_data->use_sites_size; i++)
707 bitmap bm = problem_data->use_sites[i];
712 free (problem_data->use_sites);
713 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
714 BITMAP_FREE (problem_data->dense_invalidated_by_call);
716 dflow->block_info_size = 0;
717 free (dflow->block_info);
718 free (dflow->problem_data);
723 /* Debugging info. */
726 df_ru_dump (struct dataflow *dflow, FILE *file)
729 struct df *df = dflow->df;
730 struct df_ru_problem_data *problem_data =
731 (struct df_ru_problem_data *) dflow->problem_data;
732 unsigned int m = max_reg_num ();
735 fprintf (file, "Reaching uses:\n");
737 fprintf (file, " sparse invalidated \t");
738 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
739 fprintf (file, " dense invalidated \t");
740 dump_bitmap (file, problem_data->dense_invalidated_by_call);
742 for (regno = 0; regno < m; regno++)
743 if (DF_REG_USE_GET (df, regno)->n_refs)
744 fprintf (file, "%d[%d,%d] ", regno,
745 DF_REG_USE_GET (df, regno)->begin,
746 DF_REG_USE_GET (df, regno)->n_refs);
747 fprintf (file, "\n");
751 struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, bb->index);
752 df_print_bb_index (bb, file);
757 fprintf (file, " in \t");
758 dump_bitmap (file, bb_info->in);
759 fprintf (file, " gen \t");
760 dump_bitmap (file, bb_info->gen);
761 fprintf (file, " kill\t");
762 dump_bitmap (file, bb_info->kill);
763 fprintf (file, " out \t");
764 dump_bitmap (file, bb_info->out);
768 /* All of the information associated with every instance of the problem. */
770 static struct df_problem problem_RU =
772 DF_RU, /* Problem id. */
773 DF_BACKWARD, /* Direction. */
774 df_ru_alloc, /* Allocate the problem specific data. */
775 df_ru_free_bb_info, /* Free basic block info. */
776 df_ru_local_compute, /* Local compute function. */
777 df_ru_init_solution, /* Init the solution specific data. */
778 df_iterative_dataflow, /* Iterative solver. */
779 NULL, /* Confluence operator 0. */
780 df_ru_confluence_n, /* Confluence operator n. */
781 df_ru_transfer_function, /* Transfer function. */
782 NULL, /* Finalize function. */
783 df_ru_free, /* Free all of the problem information. */
784 df_ru_dump, /* Debugging. */
785 NULL /* Dependent problem. */
790 /* Create a new DATAFLOW instance and add it to an existing instance
791 of DF. The returned structure is what is used to get at the
795 df_ru_add_problem (struct df *df)
797 return df_add_problem (df, &problem_RU);
801 /*----------------------------------------------------------------------------
804 Find the locations in the function where each definition site for a
806 ----------------------------------------------------------------------------*/
808 struct df_rd_problem_data
810 bitmap *def_sites; /* Bitmap of defs for each pseudo. */
811 unsigned int def_sites_size; /* Size of def_sites. */
812 /* The set of defs to regs invalidated by call. */
813 bitmap sparse_invalidated_by_call;
814 /* The set of defs to regs invalidate by call for ru. */
815 bitmap dense_invalidated_by_call;
818 /* Get basic block info. */
820 struct df_rd_bb_info *
821 df_rd_get_bb_info (struct dataflow *dflow, unsigned int index)
823 return (struct df_rd_bb_info *) dflow->block_info[index];
827 /* Set basic block info. */
830 df_rd_set_bb_info (struct dataflow *dflow, unsigned int index,
831 struct df_rd_bb_info *bb_info)
833 dflow->block_info[index] = bb_info;
837 /* Free basic block info. */
840 df_rd_free_bb_info (struct dataflow *dflow, void *vbb_info)
842 struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
845 BITMAP_FREE (bb_info->kill);
846 BITMAP_FREE (bb_info->sparse_kill);
847 BITMAP_FREE (bb_info->gen);
848 BITMAP_FREE (bb_info->in);
849 BITMAP_FREE (bb_info->out);
850 pool_free (dflow->block_pool, bb_info);
855 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
856 not touched unless the block is new. */
859 df_rd_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
861 unsigned int bb_index;
863 unsigned int reg_size = max_reg_num ();
865 if (! dflow->block_pool)
866 dflow->block_pool = create_alloc_pool ("df_rd_block pool",
867 sizeof (struct df_rd_bb_info), 50);
869 if (dflow->problem_data)
872 struct df_rd_problem_data *problem_data =
873 (struct df_rd_problem_data *) dflow->problem_data;
875 for (i = 0; i < problem_data->def_sites_size; i++)
877 bitmap bm = problem_data->def_sites[i];
881 problem_data->def_sites[i] = NULL;
885 if (problem_data->def_sites_size < reg_size)
887 problem_data->def_sites
888 = xrealloc (problem_data->def_sites, reg_size *sizeof (bitmap));
889 memset (problem_data->def_sites + problem_data->def_sites_size, 0,
890 (reg_size - problem_data->def_sites_size) *sizeof (bitmap));
891 problem_data->def_sites_size = reg_size;
894 bitmap_clear (problem_data->sparse_invalidated_by_call);
895 bitmap_clear (problem_data->dense_invalidated_by_call);
899 struct df_rd_problem_data *problem_data =
900 xmalloc (sizeof (struct df_rd_problem_data));
901 dflow->problem_data = problem_data;
903 problem_data->def_sites = xcalloc (reg_size, sizeof (bitmap));
904 problem_data->def_sites_size = reg_size;
905 problem_data->sparse_invalidated_by_call = BITMAP_ALLOC (NULL);
906 problem_data->dense_invalidated_by_call = BITMAP_ALLOC (NULL);
909 df_grow_bb_info (dflow);
911 /* Because of the clustering of all def sites for the same pseudo,
912 we have to process all of the blocks before doing the
915 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
917 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
920 bitmap_clear (bb_info->kill);
921 bitmap_clear (bb_info->sparse_kill);
922 bitmap_clear (bb_info->gen);
926 bb_info = (struct df_rd_bb_info *) pool_alloc (dflow->block_pool);
927 df_rd_set_bb_info (dflow, bb_index, bb_info);
928 bb_info->kill = BITMAP_ALLOC (NULL);
929 bb_info->sparse_kill = BITMAP_ALLOC (NULL);
930 bb_info->gen = BITMAP_ALLOC (NULL);
931 bb_info->in = BITMAP_ALLOC (NULL);
932 bb_info->out = BITMAP_ALLOC (NULL);
938 /* Process a list of DEFs for df_rd_bb_local_compute. */
941 df_rd_bb_local_compute_process_def (struct dataflow *dflow,
942 struct df_rd_bb_info *bb_info,
945 struct df *df = dflow->df;
948 unsigned int regno = DF_REF_REGNO (def);
949 unsigned int begin = DF_REG_DEF_GET (df, regno)->begin;
950 unsigned int n_defs = DF_REG_DEF_GET (df, regno)->n_refs;
952 /* Only the last def(s) for a regno in the block has any
954 if (!bitmap_bit_p (seen_in_block, regno))
956 /* The first def for regno in insn gets to knock out the
957 defs from other instructions. */
958 if (!bitmap_bit_p (seen_in_insn, regno))
960 if (n_defs > DF_SPARSE_THRESHOLD)
962 bitmap_set_bit (bb_info->sparse_kill, regno);
963 bitmap_clear_range (bb_info->gen, begin, n_defs);
967 struct df_rd_problem_data *problem_data =
968 (struct df_rd_problem_data *) dflow->problem_data;
970 df_ref_bitmap (problem_data->def_sites, regno,
972 bitmap_ior_into (bb_info->kill, defs);
973 bitmap_and_compl_into (bb_info->gen, defs);
977 bitmap_set_bit (seen_in_insn, regno);
978 /* All defs for regno in the instruction may be put into
980 if (! (DF_REF_FLAGS (def) & DF_REF_CLOBBER))
981 bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
987 /* Compute local reaching def info for basic block BB. */
990 df_rd_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
992 struct df *df = dflow->df;
993 basic_block bb = BASIC_BLOCK (bb_index);
994 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
997 bitmap_clear (seen_in_block);
998 bitmap_clear (seen_in_insn);
1000 FOR_BB_INSNS_REVERSE (bb, insn)
1002 unsigned int uid = INSN_UID (insn);
1004 if (! INSN_P (insn))
1007 df_rd_bb_local_compute_process_def (dflow, bb_info,
1008 DF_INSN_UID_GET (df, uid)->defs);
1010 /* This complex dance with the two bitmaps is required because
1011 instructions can assign twice to the same pseudo. This
1012 generally happens with calls that will have one def for the
1013 result and another def for the clobber. If only one vector
1014 is used and the clobber goes first, the result will be
1016 bitmap_ior_into (seen_in_block, seen_in_insn);
1017 bitmap_clear (seen_in_insn);
1020 /* Process the artificial defs last since we are going backwards
1021 thur the block and these are logically at the start. */
1022 df_rd_bb_local_compute_process_def (dflow, bb_info,
1023 df_get_artificial_defs (df, bb_index));
1027 /* Compute local reaching def info for each basic block within BLOCKS. */
1030 df_rd_local_compute (struct dataflow *dflow,
1032 bitmap rescan_blocks ATTRIBUTE_UNUSED)
1034 struct df *df = dflow->df;
1035 unsigned int bb_index;
1038 struct df_rd_problem_data *problem_data =
1039 (struct df_rd_problem_data *) dflow->problem_data;
1040 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
1041 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
1045 if (!df->def_info.refs_organized)
1046 df_reorganize_refs (&df->def_info);
1048 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1050 df_rd_bb_local_compute (dflow, bb_index);
1053 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
1054 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
1056 struct df_reg_info *reg_info = DF_REG_DEF_GET (df, regno);
1057 if (reg_info->n_refs > DF_SPARSE_THRESHOLD)
1059 bitmap_set_bit (sparse_invalidated, regno);
1063 bitmap defs = df_ref_bitmap (problem_data->def_sites, regno,
1064 reg_info->begin, reg_info->n_refs);
1065 bitmap_ior_into (dense_invalidated, defs);
1072 /* Initialize the solution bit vectors for problem. */
1075 df_rd_init_solution (struct dataflow *dflow, bitmap all_blocks)
1077 unsigned int bb_index;
1080 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1082 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
1084 bitmap_copy (bb_info->out, bb_info->gen);
1085 bitmap_clear (bb_info->in);
1089 /* In of target gets or of out of source. */
1092 df_rd_confluence_n (struct dataflow *dflow, edge e)
1094 bitmap op1 = df_rd_get_bb_info (dflow, e->dest->index)->in;
1095 bitmap op2 = df_rd_get_bb_info (dflow, e->src->index)->out;
1097 if (e->flags & EDGE_EH)
1099 struct df_rd_problem_data *problem_data =
1100 (struct df_rd_problem_data *) dflow->problem_data;
1101 bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
1102 bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
1103 struct df *df = dflow->df;
1106 bitmap tmp = BITMAP_ALLOC (NULL);
1108 bitmap_copy (tmp, op2);
1109 bitmap_and_compl_into (tmp, dense_invalidated);
1111 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
1113 bitmap_clear_range (tmp,
1114 DF_REG_DEF_GET (df, regno)->begin,
1115 DF_REG_DEF_GET (df, regno)->n_refs);
1117 bitmap_ior_into (op1, tmp);
1121 bitmap_ior_into (op1, op2);
1125 /* Transfer function. */
1128 df_rd_transfer_function (struct dataflow *dflow, int bb_index)
1130 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb_index);
1133 bitmap in = bb_info->in;
1134 bitmap out = bb_info->out;
1135 bitmap gen = bb_info->gen;
1136 bitmap kill = bb_info->kill;
1137 bitmap sparse_kill = bb_info->sparse_kill;
1139 if (bitmap_empty_p (sparse_kill))
1140 return bitmap_ior_and_compl (out, gen, in, kill);
1143 struct df *df = dflow->df;
1144 bool changed = false;
1145 bitmap tmp = BITMAP_ALLOC (NULL);
1146 bitmap_copy (tmp, in);
1147 EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
1149 bitmap_clear_range (tmp,
1150 DF_REG_DEF_GET (df, regno)->begin,
1151 DF_REG_DEF_GET (df, regno)->n_refs);
1153 bitmap_and_compl_into (tmp, kill);
1154 bitmap_ior_into (tmp, gen);
1155 changed = !bitmap_equal_p (tmp, out);
1168 /* Free all storage associated with the problem. */
1171 df_rd_free (struct dataflow *dflow)
1174 struct df_rd_problem_data *problem_data =
1175 (struct df_rd_problem_data *) dflow->problem_data;
1177 for (i = 0; i < dflow->block_info_size; i++)
1179 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, i);
1182 BITMAP_FREE (bb_info->kill);
1183 BITMAP_FREE (bb_info->sparse_kill);
1184 BITMAP_FREE (bb_info->gen);
1185 BITMAP_FREE (bb_info->in);
1186 BITMAP_FREE (bb_info->out);
1190 free_alloc_pool (dflow->block_pool);
1192 for (i = 0; i < problem_data->def_sites_size; i++)
1194 bitmap bm = problem_data->def_sites[i];
1199 free (problem_data->def_sites);
1200 BITMAP_FREE (problem_data->sparse_invalidated_by_call);
1201 BITMAP_FREE (problem_data->dense_invalidated_by_call);
1203 dflow->block_info_size = 0;
1204 free (dflow->block_info);
1205 free (dflow->problem_data);
1210 /* Debugging info. */
1213 df_rd_dump (struct dataflow *dflow, FILE *file)
1215 struct df *df = dflow->df;
1217 struct df_rd_problem_data *problem_data =
1218 (struct df_rd_problem_data *) dflow->problem_data;
1219 unsigned int m = max_reg_num ();
1222 fprintf (file, "Reaching defs:\n\n");
1224 fprintf (file, " sparse invalidated \t");
1225 dump_bitmap (file, problem_data->sparse_invalidated_by_call);
1226 fprintf (file, " dense invalidated \t");
1227 dump_bitmap (file, problem_data->dense_invalidated_by_call);
1229 for (regno = 0; regno < m; regno++)
1230 if (DF_REG_DEF_GET (df, regno)->n_refs)
1231 fprintf (file, "%d[%d,%d] ", regno,
1232 DF_REG_DEF_GET (df, regno)->begin,
1233 DF_REG_DEF_GET (df, regno)->n_refs);
1234 fprintf (file, "\n");
1238 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, bb->index);
1239 df_print_bb_index (bb, file);
1244 fprintf (file, " in\t(%d)\n", (int) bitmap_count_bits (bb_info->in));
1245 dump_bitmap (file, bb_info->in);
1246 fprintf (file, " gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
1247 dump_bitmap (file, bb_info->gen);
1248 fprintf (file, " kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
1249 dump_bitmap (file, bb_info->kill);
1250 fprintf (file, " out\t(%d)\n", (int) bitmap_count_bits (bb_info->out));
1251 dump_bitmap (file, bb_info->out);
1255 /* All of the information associated with every instance of the problem. */
1257 static struct df_problem problem_RD =
1259 DF_RD, /* Problem id. */
1260 DF_FORWARD, /* Direction. */
1261 df_rd_alloc, /* Allocate the problem specific data. */
1262 df_rd_free_bb_info, /* Free basic block info. */
1263 df_rd_local_compute, /* Local compute function. */
1264 df_rd_init_solution, /* Init the solution specific data. */
1265 df_iterative_dataflow, /* Iterative solver. */
1266 NULL, /* Confluence operator 0. */
1267 df_rd_confluence_n, /* Confluence operator n. */
1268 df_rd_transfer_function, /* Transfer function. */
1269 NULL, /* Finalize function. */
1270 df_rd_free, /* Free all of the problem information. */
1271 df_rd_dump, /* Debugging. */
1272 NULL /* Dependent problem. */
1277 /* Create a new DATAFLOW instance and add it to an existing instance
1278 of DF. The returned structure is what is used to get at the
1282 df_rd_add_problem (struct df *df)
1284 return df_add_problem (df, &problem_RD);
1289 /*----------------------------------------------------------------------------
1292 Find the locations in the function where any use of a pseudo can reach
1293 in the backwards direction.
1294 ----------------------------------------------------------------------------*/
1296 /* Get basic block info. */
1298 struct df_lr_bb_info *
1299 df_lr_get_bb_info (struct dataflow *dflow, unsigned int index)
1301 return (struct df_lr_bb_info *) dflow->block_info[index];
1305 /* Set basic block info. */
1308 df_lr_set_bb_info (struct dataflow *dflow, unsigned int index,
1309 struct df_lr_bb_info *bb_info)
1311 dflow->block_info[index] = bb_info;
1315 /* Free basic block info. */
1318 df_lr_free_bb_info (struct dataflow *dflow, void *vbb_info)
1320 struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
1323 BITMAP_FREE (bb_info->use);
1324 BITMAP_FREE (bb_info->def);
1325 BITMAP_FREE (bb_info->in);
1326 BITMAP_FREE (bb_info->out);
1327 pool_free (dflow->block_pool, bb_info);
1332 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1333 not touched unless the block is new. */
1336 df_lr_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
1338 unsigned int bb_index;
1341 if (! dflow->block_pool)
1342 dflow->block_pool = create_alloc_pool ("df_lr_block pool",
1343 sizeof (struct df_lr_bb_info), 50);
1345 df_grow_bb_info (dflow);
1347 /* Because of the clustering of all def sites for the same pseudo,
1348 we have to process all of the blocks before doing the
1351 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
1353 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1356 bitmap_clear (bb_info->def);
1357 bitmap_clear (bb_info->use);
1361 bb_info = (struct df_lr_bb_info *) pool_alloc (dflow->block_pool);
1362 df_lr_set_bb_info (dflow, bb_index, bb_info);
1363 bb_info->use = BITMAP_ALLOC (NULL);
1364 bb_info->def = BITMAP_ALLOC (NULL);
1365 bb_info->in = BITMAP_ALLOC (NULL);
1366 bb_info->out = BITMAP_ALLOC (NULL);
1372 /* Compute local live register info for basic block BB. */
1375 df_lr_bb_local_compute (struct dataflow *dflow,
1376 struct df *df, unsigned int bb_index)
1378 basic_block bb = BASIC_BLOCK (bb_index);
1379 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1384 /* Process the hardware registers that are always live. */
1385 for (use = df_get_artificial_uses (df, bb_index); use; use = use->next_ref)
1386 /* Add use to set of uses in this BB. */
1387 if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
1388 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1390 FOR_BB_INSNS_REVERSE (bb, insn)
1392 unsigned int uid = INSN_UID (insn);
1394 if (! INSN_P (insn))
1399 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
1401 unsigned int dregno = DF_REF_REGNO (def);
1403 if (dregno >= FIRST_PSEUDO_REGISTER
1404 || !(SIBLING_CALL_P (insn)
1405 && bitmap_bit_p (df->exit_block_uses, dregno)
1406 && !refers_to_regno_p (dregno, dregno+1,
1407 current_function_return_rtx,
1410 /* Add def to set of defs in this BB. */
1411 bitmap_set_bit (bb_info->def, dregno);
1412 bitmap_clear_bit (bb_info->use, dregno);
1418 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
1420 unsigned int dregno = DF_REF_REGNO (def);
1422 if (DF_INSN_CONTAINS_ASM (df, insn)
1423 && dregno < FIRST_PSEUDO_REGISTER)
1427 dregno + hard_regno_nregs[dregno][GET_MODE (DF_REF_REG (def))] - 1;
1428 for (i = dregno; i <= end; ++i)
1429 regs_asm_clobbered[i] = 1;
1431 /* Add def to set of defs in this BB. */
1432 bitmap_set_bit (bb_info->def, dregno);
1433 bitmap_clear_bit (bb_info->use, dregno);
1437 for (use = DF_INSN_UID_GET (df, uid)->uses; use; use = use->next_ref)
1438 /* Add use to set of uses in this BB. */
1439 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1442 /* Process the registers set in an exception handler. */
1443 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
1445 unsigned int dregno = DF_REF_REGNO (def);
1446 bitmap_set_bit (bb_info->def, dregno);
1447 bitmap_clear_bit (bb_info->use, dregno);
1451 /* Process the uses that are live into an exception handler. */
1452 for (use = df_get_artificial_uses (df, bb_index); use; use = use->next_ref)
1453 /* Add use to set of uses in this BB. */
1454 if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
1455 bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
1459 /* Compute local live register info for each basic block within BLOCKS. */
1462 df_lr_local_compute (struct dataflow *dflow,
1464 bitmap rescan_blocks)
1466 struct df *df = dflow->df;
1467 unsigned int bb_index;
1470 /* Assume that the stack pointer is unchanging if alloca hasn't
1472 if (bitmap_equal_p (all_blocks, rescan_blocks))
1473 memset (regs_asm_clobbered, 0, sizeof (regs_asm_clobbered));
1475 bitmap_clear (df->hardware_regs_used);
1477 /* The all-important stack pointer must always be live. */
1478 bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
1480 /* Before reload, there are a few registers that must be forced
1481 live everywhere -- which might not already be the case for
1482 blocks within infinite loops. */
1483 if (! reload_completed)
1485 /* Any reference to any pseudo before reload is a potential
1486 reference of the frame pointer. */
1487 bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
1489 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1490 /* Pseudos with argument area equivalences may require
1491 reloading via the argument pointer. */
1492 if (fixed_regs[ARG_POINTER_REGNUM])
1493 bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
1496 /* Any constant, or pseudo with constant equivalences, may
1497 require reloading from memory using the pic register. */
1498 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
1499 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
1500 bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
1503 if (bitmap_bit_p (rescan_blocks, EXIT_BLOCK))
1505 /* The exit block is special for this problem and its bits are
1506 computed from thin air. */
1507 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, EXIT_BLOCK);
1508 bitmap_copy (bb_info->use, df->exit_block_uses);
1511 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks, 0, bb_index, bi)
1513 if (bb_index == EXIT_BLOCK)
1515 df_lr_bb_local_compute (dflow, df, bb_index);
1520 /* Initialize the solution vectors. */
1523 df_lr_init (struct dataflow *dflow, bitmap all_blocks)
1525 unsigned int bb_index;
1528 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1530 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1531 bitmap_copy (bb_info->in, bb_info->use);
1532 bitmap_clear (bb_info->out);
1537 /* Confluence function that processes infinite loops. This might be a
1538 noreturn function that throws. And even if it isn't, getting the
1539 unwind info right helps debugging. */
1541 df_lr_confluence_0 (struct dataflow *dflow, basic_block bb)
1543 struct df *df = dflow->df;
1545 bitmap op1 = df_lr_get_bb_info (dflow, bb->index)->out;
1546 if (bb != EXIT_BLOCK_PTR)
1547 bitmap_copy (op1, df->hardware_regs_used);
1551 /* Confluence function that ignores fake edges. */
1553 df_lr_confluence_n (struct dataflow *dflow, edge e)
1555 bitmap op1 = df_lr_get_bb_info (dflow, e->src->index)->out;
1556 bitmap op2 = df_lr_get_bb_info (dflow, e->dest->index)->in;
1558 /* Call-clobbered registers die across exception and call edges. */
1559 /* ??? Abnormal call edges ignored for the moment, as this gets
1560 confused by sibling call edges, which crashes reg-stack. */
1561 if (e->flags & EDGE_EH)
1562 bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
1564 bitmap_ior_into (op1, op2);
1566 bitmap_ior_into (op1, dflow->df->hardware_regs_used);
1570 /* Transfer function. */
1572 df_lr_transfer_function (struct dataflow *dflow, int bb_index)
1574 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb_index);
1575 bitmap in = bb_info->in;
1576 bitmap out = bb_info->out;
1577 bitmap use = bb_info->use;
1578 bitmap def = bb_info->def;
1580 return bitmap_ior_and_compl (in, use, out, def);
1584 /* Free all storage associated with the problem. */
1587 df_lr_free (struct dataflow *dflow)
1590 for (i = 0; i < dflow->block_info_size; i++)
1592 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, i);
1595 BITMAP_FREE (bb_info->use);
1596 BITMAP_FREE (bb_info->def);
1597 BITMAP_FREE (bb_info->in);
1598 BITMAP_FREE (bb_info->out);
1601 free_alloc_pool (dflow->block_pool);
1603 dflow->block_info_size = 0;
1604 free (dflow->block_info);
1609 /* Debugging info. */
1612 df_lr_dump (struct dataflow *dflow, FILE *file)
1616 fprintf (file, "Live Registers:\n");
1619 struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, bb->index);
1620 df_print_bb_index (bb, file);
1625 fprintf (file, " in \t");
1626 dump_bitmap (file, bb_info->in);
1627 fprintf (file, " use \t");
1628 dump_bitmap (file, bb_info->use);
1629 fprintf (file, " def \t");
1630 dump_bitmap (file, bb_info->def);
1631 fprintf (file, " out \t");
1632 dump_bitmap (file, bb_info->out);
1636 /* All of the information associated with every instance of the problem. */
1638 static struct df_problem problem_LR =
1640 DF_LR, /* Problem id. */
1641 DF_BACKWARD, /* Direction. */
1642 df_lr_alloc, /* Allocate the problem specific data. */
1643 df_lr_free_bb_info, /* Free basic block info. */
1644 df_lr_local_compute, /* Local compute function. */
1645 df_lr_init, /* Init the solution specific data. */
1646 df_iterative_dataflow, /* Iterative solver. */
1647 df_lr_confluence_0, /* Confluence operator 0. */
1648 df_lr_confluence_n, /* Confluence operator n. */
1649 df_lr_transfer_function, /* Transfer function. */
1650 NULL, /* Finalize function. */
1651 df_lr_free, /* Free all of the problem information. */
1652 df_lr_dump, /* Debugging. */
1653 NULL /* Dependent problem. */
1657 /* Create a new DATAFLOW instance and add it to an existing instance
1658 of DF. The returned structure is what is used to get at the
1662 df_lr_add_problem (struct df *df)
1664 return df_add_problem (df, &problem_LR);
1669 /*----------------------------------------------------------------------------
1670 UNINITIALIZED REGISTERS
1672 Find the set of uses for registers that are reachable from the entry
1673 block without passing thru a definition.
1674 ----------------------------------------------------------------------------*/
1676 /* Get basic block info. */
1678 struct df_ur_bb_info *
1679 df_ur_get_bb_info (struct dataflow *dflow, unsigned int index)
1681 return (struct df_ur_bb_info *) dflow->block_info[index];
1685 /* Set basic block info. */
1688 df_ur_set_bb_info (struct dataflow *dflow, unsigned int index,
1689 struct df_ur_bb_info *bb_info)
1691 dflow->block_info[index] = bb_info;
1695 /* Free basic block info. */
1698 df_ur_free_bb_info (struct dataflow *dflow, void *vbb_info)
1700 struct df_ur_bb_info *bb_info = (struct df_ur_bb_info *) vbb_info;
1703 BITMAP_FREE (bb_info->gen);
1704 BITMAP_FREE (bb_info->kill);
1705 BITMAP_FREE (bb_info->in);
1706 BITMAP_FREE (bb_info->out);
1707 pool_free (dflow->block_pool, bb_info);
1712 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1713 not touched unless the block is new. */
1716 df_ur_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
1718 unsigned int bb_index;
1721 if (! dflow->block_pool)
1722 dflow->block_pool = create_alloc_pool ("df_ur_block pool",
1723 sizeof (struct df_ur_bb_info), 100);
1725 df_grow_bb_info (dflow);
1727 /* Because of the clustering of all def sites for the same pseudo,
1728 we have to process all of the blocks before doing the
1731 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
1733 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1736 bitmap_clear (bb_info->kill);
1737 bitmap_clear (bb_info->gen);
1741 bb_info = (struct df_ur_bb_info *) pool_alloc (dflow->block_pool);
1742 df_ur_set_bb_info (dflow, bb_index, bb_info);
1743 bb_info->kill = BITMAP_ALLOC (NULL);
1744 bb_info->gen = BITMAP_ALLOC (NULL);
1745 bb_info->in = BITMAP_ALLOC (NULL);
1746 bb_info->out = BITMAP_ALLOC (NULL);
1752 /* Compute local uninitialized register info for basic block BB. */
1755 df_ur_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
1757 struct df *df = dflow->df;
1758 basic_block bb = BASIC_BLOCK (bb_index);
1759 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1763 bitmap_clear (seen_in_block);
1764 bitmap_clear (seen_in_insn);
1766 FOR_BB_INSNS_REVERSE (bb, insn)
1768 unsigned int uid = INSN_UID (insn);
1772 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
1774 unsigned int regno = DF_REF_REGNO (def);
1775 /* Only the last def counts. */
1776 if (!bitmap_bit_p (seen_in_block, regno))
1778 bitmap_set_bit (seen_in_insn, regno);
1780 if (DF_REF_FLAGS (def) & DF_REF_CLOBBER)
1781 bitmap_set_bit (bb_info->kill, regno);
1783 bitmap_set_bit (bb_info->gen, regno);
1786 bitmap_ior_into (seen_in_block, seen_in_insn);
1787 bitmap_clear (seen_in_insn);
1790 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
1792 unsigned int regno = DF_REF_REGNO (def);
1793 if (!bitmap_bit_p (seen_in_block, regno))
1795 bitmap_set_bit (seen_in_block, regno);
1796 bitmap_set_bit (bb_info->gen, regno);
1802 /* Compute local uninitialized register info. */
1805 df_ur_local_compute (struct dataflow *dflow,
1806 bitmap all_blocks ATTRIBUTE_UNUSED,
1807 bitmap rescan_blocks)
1809 unsigned int bb_index;
1814 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks, 0, bb_index, bi)
1816 df_ur_bb_local_compute (dflow, bb_index);
1823 /* Initialize the solution vectors. */
1826 df_ur_init (struct dataflow *dflow, bitmap all_blocks)
1828 unsigned int bb_index;
1831 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1833 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1835 bitmap_copy (bb_info->out, bb_info->gen);
1836 bitmap_clear (bb_info->in);
1841 /* Or in the stack regs, hard regs and early clobber regs into the the
1842 ur_in sets of all of the blocks. */
1845 df_ur_local_finalize (struct dataflow *dflow, bitmap all_blocks)
1847 struct df *df = dflow->df;
1848 struct dataflow *lr_dflow = df->problems_by_index[DF_LR];
1849 bitmap tmp = BITMAP_ALLOC (NULL);
1851 unsigned int bb_index;
1853 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
1855 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1856 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (lr_dflow, bb_index);
1858 bitmap_ior_into (bb_info->in, df_all_hard_regs);
1859 bitmap_ior_into (bb_info->out, df_all_hard_regs);
1861 /* No register may reach a location where it is not used. Thus
1862 we trim the rr result to the places where it is used. */
1863 bitmap_and_into (bb_info->in, bb_lr_info->in);
1864 bitmap_and_into (bb_info->out, bb_lr_info->out);
1867 /* Hard registers may still stick in the ur_out set, but not
1868 be in the ur_in set, if their only mention was in a call
1869 in this block. This is because a call kills in the lr
1870 problem but does not kill in the ur problem. To clean
1871 this up, we execute the transfer function on the lr_in
1872 set and then use that to knock bits out of ur_out. */
1873 bitmap_ior_and_compl (tmp, bb_info->gen, bb_lr_info->in,
1875 bitmap_and_into (bb_info->out, tmp);
1883 /* Confluence function that ignores fake edges. */
1886 df_ur_confluence_n (struct dataflow *dflow, edge e)
1888 bitmap op1 = df_ur_get_bb_info (dflow, e->dest->index)->in;
1889 bitmap op2 = df_ur_get_bb_info (dflow, e->src->index)->out;
1891 if (e->flags & EDGE_FAKE)
1894 bitmap_ior_into (op1, op2);
1898 /* Transfer function. */
1901 df_ur_transfer_function (struct dataflow *dflow, int bb_index)
1903 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
1904 bitmap in = bb_info->in;
1905 bitmap out = bb_info->out;
1906 bitmap gen = bb_info->gen;
1907 bitmap kill = bb_info->kill;
1909 return bitmap_ior_and_compl (out, gen, in, kill);
1913 /* Free all storage associated with the problem. */
1916 df_ur_free (struct dataflow *dflow)
1920 for (i = 0; i < dflow->block_info_size; i++)
1922 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, i);
1925 BITMAP_FREE (bb_info->gen);
1926 BITMAP_FREE (bb_info->kill);
1927 BITMAP_FREE (bb_info->in);
1928 BITMAP_FREE (bb_info->out);
1932 free_alloc_pool (dflow->block_pool);
1933 dflow->block_info_size = 0;
1934 free (dflow->block_info);
1939 /* Debugging info. */
1942 df_ur_dump (struct dataflow *dflow, FILE *file)
1946 fprintf (file, "Undefined regs:\n");
1950 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb->index);
1951 df_print_bb_index (bb, file);
1956 fprintf (file, " in \t");
1957 dump_bitmap (file, bb_info->in);
1958 fprintf (file, " gen \t");
1959 dump_bitmap (file, bb_info->gen);
1960 fprintf (file, " kill\t");
1961 dump_bitmap (file, bb_info->kill);
1962 fprintf (file, " out \t");
1963 dump_bitmap (file, bb_info->out);
1967 /* All of the information associated with every instance of the problem. */
1969 static struct df_problem problem_UR =
1971 DF_UR, /* Problem id. */
1972 DF_FORWARD, /* Direction. */
1973 df_ur_alloc, /* Allocate the problem specific data. */
1974 df_ur_free_bb_info, /* Free basic block info. */
1975 df_ur_local_compute, /* Local compute function. */
1976 df_ur_init, /* Init the solution specific data. */
1977 df_iterative_dataflow, /* Iterative solver. */
1978 NULL, /* Confluence operator 0. */
1979 df_ur_confluence_n, /* Confluence operator n. */
1980 df_ur_transfer_function, /* Transfer function. */
1981 df_ur_local_finalize, /* Finalize function. */
1982 df_ur_free, /* Free all of the problem information. */
1983 df_ur_dump, /* Debugging. */
1984 &problem_LR /* Dependent problem. */
1988 /* Create a new DATAFLOW instance and add it to an existing instance
1989 of DF. The returned structure is what is used to get at the
1993 df_ur_add_problem (struct df *df)
1995 return df_add_problem (df, &problem_UR);
2000 /*----------------------------------------------------------------------------
2001 UNINITIALIZED REGISTERS WITH EARLYCLOBBER
2003 Find the set of uses for registers that are reachable from the entry
2004 block without passing thru a definition.
2006 This is a variant of the UR problem above that has a lot of special
2007 features just for the register allocation phase.
2008 ----------------------------------------------------------------------------*/
2010 struct df_urec_problem_data
2012 bool earlyclobbers_found; /* True if any instruction contains an
2015 bitmap stack_regs; /* Registers that may be allocated to a STACK_REGS. */
2020 /* Get basic block info. */
2022 struct df_urec_bb_info *
2023 df_urec_get_bb_info (struct dataflow *dflow, unsigned int index)
2025 return (struct df_urec_bb_info *) dflow->block_info[index];
2029 /* Set basic block info. */
2032 df_urec_set_bb_info (struct dataflow *dflow, unsigned int index,
2033 struct df_urec_bb_info *bb_info)
2035 dflow->block_info[index] = bb_info;
2039 /* Free basic block info. */
2042 df_urec_free_bb_info (struct dataflow *dflow, void *vbb_info)
2044 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info *) vbb_info;
2047 BITMAP_FREE (bb_info->gen);
2048 BITMAP_FREE (bb_info->kill);
2049 BITMAP_FREE (bb_info->in);
2050 BITMAP_FREE (bb_info->out);
2051 BITMAP_FREE (bb_info->earlyclobber);
2052 pool_free (dflow->block_pool, bb_info);
2057 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
2058 not touched unless the block is new. */
2061 df_urec_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
2063 unsigned int bb_index;
2065 struct df_urec_problem_data *problem_data =
2066 (struct df_urec_problem_data *) dflow->problem_data;
2068 if (! dflow->block_pool)
2069 dflow->block_pool = create_alloc_pool ("df_urec_block pool",
2070 sizeof (struct df_urec_bb_info), 50);
2072 if (!dflow->problem_data)
2074 problem_data = xmalloc (sizeof (struct df_urec_problem_data));
2075 dflow->problem_data = problem_data;
2077 problem_data->earlyclobbers_found = false;
2079 df_grow_bb_info (dflow);
2081 /* Because of the clustering of all def sites for the same pseudo,
2082 we have to process all of the blocks before doing the
2085 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan, 0, bb_index, bi)
2087 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2090 bitmap_clear (bb_info->kill);
2091 bitmap_clear (bb_info->gen);
2092 bitmap_clear (bb_info->earlyclobber);
2096 bb_info = (struct df_urec_bb_info *) pool_alloc (dflow->block_pool);
2097 df_urec_set_bb_info (dflow, bb_index, bb_info);
2098 bb_info->kill = BITMAP_ALLOC (NULL);
2099 bb_info->gen = BITMAP_ALLOC (NULL);
2100 bb_info->in = BITMAP_ALLOC (NULL);
2101 bb_info->out = BITMAP_ALLOC (NULL);
2102 bb_info->earlyclobber = BITMAP_ALLOC (NULL);
2108 /* The function modifies local info for register REG being changed in
2109 SETTER. DATA is used to pass the current basic block info. */
2112 df_urec_mark_reg_change (rtx reg, rtx setter, void *data)
2117 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2119 if (GET_CODE (reg) == SUBREG)
2120 reg = SUBREG_REG (reg);
2126 endregno = regno = REGNO (reg);
2127 if (regno < FIRST_PSEUDO_REGISTER)
2129 endregno +=hard_regno_nregs[regno][GET_MODE (reg)];
2131 for (i = regno; i < endregno; i++)
2133 bitmap_set_bit (bb_info->kill, i);
2135 if (GET_CODE (setter) != CLOBBER)
2136 bitmap_set_bit (bb_info->gen, i);
2138 bitmap_clear_bit (bb_info->gen, i);
2143 bitmap_set_bit (bb_info->kill, regno);
2145 if (GET_CODE (setter) != CLOBBER)
2146 bitmap_set_bit (bb_info->gen, regno);
2148 bitmap_clear_bit (bb_info->gen, regno);
2151 /* Classes of registers which could be early clobbered in the current
2155 DEF_VEC_ALLOC_I(int,heap);
2157 static VEC(int,heap) *earlyclobber_regclass;
2159 /* This function finds and stores register classes that could be early
2160 clobbered in INSN. If any earlyclobber classes are found, the function
2161 returns TRUE, in all other cases it returns FALSE. */
2164 df_urec_check_earlyclobber (rtx insn)
2169 extract_insn (insn);
2171 VEC_truncate (int, earlyclobber_regclass, 0);
2172 for (opno = 0; opno < recog_data.n_operands; opno++)
2177 enum reg_class class;
2178 const char *p = recog_data.constraints[opno];
2187 case '=': case '+': case '?':
2190 case 'm': case '<': case '>': case 'V': case 'o':
2191 case 'E': case 'F': case 'G': case 'H':
2192 case 's': case 'i': case 'n':
2193 case 'I': case 'J': case 'K': case 'L':
2194 case 'M': case 'N': case 'O': case 'P':
2196 case '0': case '1': case '2': case '3': case '4':
2197 case '5': case '6': case '7': case '8': case '9':
2198 /* These don't say anything we care about. */
2206 if (amp_p && class != NO_REGS)
2212 VEC_iterate (int, earlyclobber_regclass, i, rc);
2215 if (rc == (int) class)
2219 /* We use VEC_quick_push here because
2220 earlyclobber_regclass holds no more than
2221 N_REG_CLASSES elements. */
2222 VEC_quick_push (int, earlyclobber_regclass, (int) class);
2232 class = GENERAL_REGS;
2236 class = REG_CLASS_FROM_CONSTRAINT (c, p);
2241 p += CONSTRAINT_LEN (c, p);
2248 /* The function checks that pseudo-register *X has a class
2249 intersecting with the class of pseudo-register could be early
2250 clobbered in the same insn.
2252 This function is a no-op if earlyclobber_regclass is empty.
2254 Reload can assign the same hard register to uninitialized
2255 pseudo-register and early clobbered pseudo-register in an insn if
2256 the pseudo-register is used first time in given BB and not lived at
2257 the BB start. To prevent this we don't change life information for
2258 such pseudo-registers. */
2261 df_urec_mark_reg_use_for_earlyclobber (rtx *x, void *data)
2263 enum reg_class pref_class, alt_class;
2265 struct df_urec_bb_info *bb_info = (struct df_urec_bb_info*) data;
2267 if (REG_P (*x) && REGNO (*x) >= FIRST_PSEUDO_REGISTER)
2272 if (bitmap_bit_p (bb_info->kill, regno)
2273 || bitmap_bit_p (bb_info->gen, regno))
2275 pref_class = reg_preferred_class (regno);
2276 alt_class = reg_alternate_class (regno);
2277 for (i = 0; VEC_iterate (int, earlyclobber_regclass, i, rc); i++)
2279 if (reg_classes_intersect_p (rc, pref_class)
2281 && reg_classes_intersect_p (rc, alt_class)))
2283 bitmap_set_bit (bb_info->earlyclobber, regno);
2291 /* The function processes all pseudo-registers in *X with the aid of
2292 previous function. */
2295 df_urec_mark_reg_use_for_earlyclobber_1 (rtx *x, void *data)
2297 for_each_rtx (x, df_urec_mark_reg_use_for_earlyclobber, data);
2301 /* Compute local uninitialized register info for basic block BB. */
2304 df_urec_bb_local_compute (struct dataflow *dflow, unsigned int bb_index)
2306 struct df *df = dflow->df;
2307 basic_block bb = BASIC_BLOCK (bb_index);
2308 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2312 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
2314 unsigned int regno = DF_REF_REGNO (def);
2315 bitmap_set_bit (bb_info->gen, regno);
2318 FOR_BB_INSNS (bb, insn)
2322 note_stores (PATTERN (insn), df_urec_mark_reg_change, bb_info);
2323 if (df_state & (DF_SCAN_GLOBAL | DF_SCAN_POST_ALLOC)
2324 && df_urec_check_earlyclobber (insn))
2326 struct df_urec_problem_data *problem_data =
2327 (struct df_urec_problem_data *) dflow->problem_data;
2328 problem_data->earlyclobbers_found = true;
2329 note_uses (&PATTERN (insn),
2330 df_urec_mark_reg_use_for_earlyclobber_1, bb_info);
2337 /* Compute local uninitialized register info. */
2340 df_urec_local_compute (struct dataflow *dflow,
2341 bitmap all_blocks ATTRIBUTE_UNUSED,
2342 bitmap rescan_blocks)
2344 unsigned int bb_index;
2348 HARD_REG_SET zero, stack_hard_regs, used;
2349 struct df_urec_problem_data *problem_data =
2350 (struct df_urec_problem_data *) dflow->problem_data;
2352 /* Any register that MAY be allocated to a register stack (like the
2353 387) is treated poorly. Each such register is marked as being
2354 live everywhere. This keeps the register allocator and the
2355 subsequent passes from doing anything useful with these values.
2357 FIXME: This seems like an incredibly poor idea. */
2359 CLEAR_HARD_REG_SET (zero);
2360 CLEAR_HARD_REG_SET (stack_hard_regs);
2361 for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
2362 SET_HARD_REG_BIT (stack_hard_regs, i);
2363 problem_data->stack_regs = BITMAP_ALLOC (NULL);
2364 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
2366 COPY_HARD_REG_SET (used, reg_class_contents[reg_preferred_class (i)]);
2367 IOR_HARD_REG_SET (used, reg_class_contents[reg_alternate_class (i)]);
2368 AND_HARD_REG_SET (used, stack_hard_regs);
2369 GO_IF_HARD_REG_EQUAL (used, zero, skip);
2370 bitmap_set_bit (problem_data->stack_regs, i);
2376 /* We know that earlyclobber_regclass holds no more than
2377 N_REG_CLASSES elements. See df_urec_check_earlyclobber. */
2378 earlyclobber_regclass = VEC_alloc (int, heap, N_REG_CLASSES);
2380 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks, 0, bb_index, bi)
2382 df_urec_bb_local_compute (dflow, bb_index);
2385 VEC_free (int, heap, earlyclobber_regclass);
2389 /* Initialize the solution vectors. */
2392 df_urec_init (struct dataflow *dflow, bitmap all_blocks)
2394 unsigned int bb_index;
2397 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2399 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2401 /* FIXME: This is a hack, it has been copied over from
2402 make_accurate_live_analysis by Vlad. Most likely it is necessary
2403 because the generation of gen and kill information for hardware
2404 registers in ur is a subset of what is really necessary and what
2405 is done for the lr problem. */
2407 /* Inside the register allocator, partial availability is only
2408 allowed for the psuedo registers. To implement this, the rr is
2409 initially iored with a mask ones for the hard registers and zeros
2410 for the pseudos before being iterated. This means that each
2411 hardware register will be live unless explicitly killed by some
2412 statement. Eventually most of these bit will die because the
2413 results of rr are anded with the results of lr before being used.
2414 Outside of register allocation, a more conservative strategy of
2415 completely ignoring the unintialized registers is imployed in the
2416 finalizer function. */
2417 if (df_state & DF_SCAN_GLOBAL)
2419 bitmap_ior (bb_info->out, bb_info->gen, df_all_hard_regs);
2420 bitmap_copy (bb_info->in, df_all_hard_regs);
2424 bitmap_copy (bb_info->out, bb_info->gen);
2425 bitmap_clear (bb_info->in);
2431 /* Or in the stack regs, hard regs and early clobber regs into the the
2432 ur_in sets of all of the blocks. */
2435 df_urec_local_finalize (struct dataflow *dflow, bitmap all_blocks)
2437 struct df *df = dflow->df;
2438 struct dataflow *lr_dflow = df->problems_by_index[DF_LR];
2439 bitmap tmp = BITMAP_ALLOC (NULL);
2441 unsigned int bb_index;
2442 struct df_urec_problem_data *problem_data =
2443 (struct df_urec_problem_data *) dflow->problem_data;
2445 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2447 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2448 struct df_lr_bb_info *bb_lr_info = df_lr_get_bb_info (lr_dflow, bb_index);
2450 if (bb_index != ENTRY_BLOCK && bb_index != EXIT_BLOCK)
2452 if (problem_data->earlyclobbers_found)
2453 bitmap_ior_into (bb_info->in, bb_info->earlyclobber);
2456 /* We can not use the same stack register for uninitialized
2457 pseudo-register and another living pseudo-register
2458 because if the uninitialized pseudo-register dies,
2459 subsequent pass reg-stack will be confused (it will
2460 believe that the other register dies). */
2461 bitmap_ior_into (bb_info->in, problem_data->stack_regs);
2462 bitmap_ior_into (bb_info->out, problem_data->stack_regs);
2466 if (!(df_state & DF_SCAN_GLOBAL))
2468 bitmap_ior_into (bb_info->in, df_all_hard_regs);
2469 bitmap_ior_into (bb_info->out, df_all_hard_regs);
2472 /* No register may reach a location where it is not used. Thus
2473 we trim the rr result to the places where it is used. */
2474 bitmap_and_into (bb_info->in, bb_lr_info->in);
2475 bitmap_and_into (bb_info->out, bb_lr_info->out);
2478 /* Hard registers may still stick in the ur_out set, but not
2479 be in the ur_in set, if their only mention was in a call
2480 in this block. This is because a call kills in the lr
2481 problem but does not kill in the rr problem. To clean
2482 this up, we execute the transfer function on the lr_in
2483 set and then use that to knock bits out of ur_out. */
2484 bitmap_ior_and_compl (tmp, bb_info->gen, bb_lr_info->in,
2486 bitmap_and_into (bb_info->out, tmp);
2491 BITMAP_FREE (problem_data->stack_regs);
2497 /* Confluence function that ignores fake edges. */
2500 df_urec_confluence_n (struct dataflow *dflow, edge e)
2502 bitmap op1 = df_urec_get_bb_info (dflow, e->dest->index)->in;
2503 bitmap op2 = df_urec_get_bb_info (dflow, e->src->index)->out;
2505 if (e->flags & EDGE_FAKE)
2508 bitmap_ior_into (op1, op2);
2512 /* Transfer function. */
2515 df_urec_transfer_function (struct dataflow *dflow, int bb_index)
2517 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb_index);
2518 bitmap in = bb_info->in;
2519 bitmap out = bb_info->out;
2520 bitmap gen = bb_info->gen;
2521 bitmap kill = bb_info->kill;
2523 return bitmap_ior_and_compl (out, gen, in, kill);
2527 /* Free all storage associated with the problem. */
2530 df_urec_free (struct dataflow *dflow)
2534 for (i = 0; i < dflow->block_info_size; i++)
2536 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, i);
2539 BITMAP_FREE (bb_info->gen);
2540 BITMAP_FREE (bb_info->kill);
2541 BITMAP_FREE (bb_info->in);
2542 BITMAP_FREE (bb_info->out);
2543 BITMAP_FREE (bb_info->earlyclobber);
2547 free_alloc_pool (dflow->block_pool);
2549 dflow->block_info_size = 0;
2550 free (dflow->block_info);
2551 free (dflow->problem_data);
2556 /* Debugging info. */
2559 df_urec_dump (struct dataflow *dflow, FILE *file)
2563 fprintf (file, "Undefined regs:\n");
2567 struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, bb->index);
2568 df_print_bb_index (bb, file);
2573 fprintf (file, " in \t");
2574 dump_bitmap (file, bb_info->in);
2575 fprintf (file, " gen \t");
2576 dump_bitmap (file, bb_info->gen);
2577 fprintf (file, " kill\t");
2578 dump_bitmap (file, bb_info->kill);
2579 fprintf (file, " ec\t");
2580 dump_bitmap (file, bb_info->earlyclobber);
2581 fprintf (file, " out \t");
2582 dump_bitmap (file, bb_info->out);
2586 /* All of the information associated with every instance of the problem. */
2588 static struct df_problem problem_UREC =
2590 DF_UREC, /* Problem id. */
2591 DF_FORWARD, /* Direction. */
2592 df_urec_alloc, /* Allocate the problem specific data. */
2593 df_urec_free_bb_info, /* Free basic block info. */
2594 df_urec_local_compute, /* Local compute function. */
2595 df_urec_init, /* Init the solution specific data. */
2596 df_iterative_dataflow, /* Iterative solver. */
2597 NULL, /* Confluence operator 0. */
2598 df_urec_confluence_n, /* Confluence operator n. */
2599 df_urec_transfer_function, /* Transfer function. */
2600 df_urec_local_finalize, /* Finalize function. */
2601 df_urec_free, /* Free all of the problem information. */
2602 df_urec_dump, /* Debugging. */
2603 &problem_LR /* Dependent problem. */
2607 /* Create a new DATAFLOW instance and add it to an existing instance
2608 of DF. The returned structure is what is used to get at the
2612 df_urec_add_problem (struct df *df)
2614 return df_add_problem (df, &problem_UREC);
2619 /*----------------------------------------------------------------------------
2620 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
2622 Link either the defs to the uses and / or the uses to the defs.
2624 These problems are set up like the other dataflow problems so that
2625 they nicely fit into the framework. They are much simpler and only
2626 involve a single traversal of instructions and an examination of
2627 the reaching defs information (the dependent problem).
2628 ----------------------------------------------------------------------------*/
2630 struct df_chain_problem_data
2636 /* Create def-use or use-def chains. */
2639 df_chain_alloc (struct dataflow *dflow,
2640 bitmap blocks_to_rescan ATTRIBUTE_UNUSED)
2642 struct df *df = dflow->df;
2644 struct df_chain_problem_data *problem_data =
2645 (struct df_chain_problem_data *) dflow->problem_data;
2647 /* Wholesale destruction of the old chains. */
2648 if (dflow->block_pool)
2649 free_alloc_pool (dflow->block_pool);
2651 dflow->block_pool = create_alloc_pool ("df_chain_chain_block pool",
2652 sizeof (struct df_link), 100);
2654 if (problem_data->flags & DF_DU_CHAIN)
2656 if (!df->def_info.refs_organized)
2657 df_reorganize_refs (&df->def_info);
2659 /* Clear out the pointers from the refs. */
2660 for (i = 0; i < DF_DEFS_SIZE (df); i++)
2662 struct df_ref *ref = df->def_info.refs[i];
2663 DF_REF_CHAIN (ref) = NULL;
2667 if (problem_data->flags & DF_UD_CHAIN)
2669 if (!df->use_info.refs_organized)
2670 df_reorganize_refs (&df->use_info);
2671 for (i = 0; i < DF_USES_SIZE (df); i++)
2673 struct df_ref *ref = df->use_info.refs[i];
2674 DF_REF_CHAIN (ref) = NULL;
2680 /* Create the chains for a list of USEs. */
2683 df_chain_create_bb_process_use (struct dataflow *dflow,
2684 struct df_chain_problem_data *problem_data,
2687 enum df_ref_flags top_flag)
2689 struct df *df = dflow->df;
2691 unsigned int def_index;
2695 /* Do not want to go thur this for an uninitialized var. */
2696 unsigned int uregno = DF_REF_REGNO (use);
2697 int count = DF_REG_DEF_GET (df, uregno)->n_refs;
2700 if (top_flag == (DF_REF_FLAGS (use) & DF_REF_AT_TOP))
2702 unsigned int first_index = DF_REG_DEF_GET (df, uregno)->begin;
2703 unsigned int last_index = first_index + count - 1;
2705 EXECUTE_IF_SET_IN_BITMAP (local_rd, first_index, def_index, bi)
2708 if (def_index > last_index)
2711 def = DF_DEFS_GET (df, def_index);
2712 if (problem_data->flags & DF_DU_CHAIN)
2713 df_chain_create (dflow, def, use);
2714 if (problem_data->flags & DF_UD_CHAIN)
2715 df_chain_create (dflow, use, def);
2719 use = use->next_ref;
2723 /* Reset the storage pool that the def-use or use-def chains have been
2724 allocated in. We do not need to re adjust the pointers in the refs,
2725 these have already been clean out.*/
2727 /* Create chains from reaching defs bitmaps for basic block BB. */
2729 df_chain_create_bb (struct dataflow *dflow,
2730 struct dataflow *rd_dflow,
2731 unsigned int bb_index)
2733 basic_block bb = BASIC_BLOCK (bb_index);
2734 struct df_rd_bb_info *bb_info = df_rd_get_bb_info (rd_dflow, bb_index);
2736 bitmap cpy = BITMAP_ALLOC (NULL);
2737 struct df *df = dflow->df;
2738 struct df_chain_problem_data *problem_data =
2739 (struct df_chain_problem_data *) dflow->problem_data;
2742 bitmap_copy (cpy, bb_info->in);
2744 /* Since we are going forwards, process the artificial uses first
2745 then the artificial defs second. */
2748 /* Create the chains for the artificial uses from the EH_USES at the
2749 beginning of the block. */
2750 df_chain_create_bb_process_use (dflow, problem_data, cpy,
2751 df_get_artificial_uses (df, bb->index),
2755 for (def = df_get_artificial_defs (df, bb_index); def; def = def->next_ref)
2757 unsigned int dregno = DF_REF_REGNO (def);
2758 bitmap_clear_range (cpy,
2759 DF_REG_DEF_GET (df, dregno)->begin,
2760 DF_REG_DEF_GET (df, dregno)->n_refs);
2761 if (! (DF_REF_FLAGS (def) & DF_REF_CLOBBER))
2762 bitmap_set_bit (cpy, DF_REF_ID (def));
2765 /* Process the regular instructions next. */
2766 FOR_BB_INSNS (bb, insn)
2769 unsigned int uid = INSN_UID (insn);
2771 if (! INSN_P (insn))
2774 /* Now scan the uses and link them up with the defs that remain
2775 in the cpy vector. */
2777 df_chain_create_bb_process_use (dflow, problem_data, cpy,
2778 DF_INSN_UID_GET (df, uid)->uses, 0);
2780 /* Since we are going forwards, process the defs second. This
2781 pass only changes the bits in cpy. */
2782 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
2784 unsigned int dregno = DF_REF_REGNO (def);
2785 bitmap_clear_range (cpy,
2786 DF_REG_DEF_GET (df, dregno)->begin,
2787 DF_REG_DEF_GET (df, dregno)->n_refs);
2788 if (! (DF_REF_FLAGS (def) & DF_REF_CLOBBER))
2789 bitmap_set_bit (cpy, DF_REF_ID (def));
2793 /* Create the chains for the artificial uses of the hard registers
2794 at the end of the block. */
2795 df_chain_create_bb_process_use (dflow, problem_data, cpy,
2796 df_get_artificial_uses (df, bb->index), 0);
2799 /* Create def-use chains from reaching use bitmaps for basic blocks
2803 df_chain_finalize (struct dataflow *dflow, bitmap all_blocks)
2805 unsigned int bb_index;
2807 struct df *df = dflow->df;
2808 struct dataflow *rd_dflow = df->problems_by_index [DF_RD];
2810 EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
2812 df_chain_create_bb (dflow, rd_dflow, bb_index);
2817 /* Free all storage associated with the problem. */
2820 df_chain_free (struct dataflow *dflow)
2822 free_alloc_pool (dflow->block_pool);
2823 free (dflow->problem_data);
2828 /* Debugging info. */
2831 df_chains_dump (struct dataflow *dflow, FILE *file)
2833 struct df *df = dflow->df;
2835 struct df_chain_problem_data *problem_data =
2836 (struct df_chain_problem_data *) dflow->problem_data;
2838 if (problem_data->flags & DF_DU_CHAIN)
2840 fprintf (file, "Def-use chains:\n");
2841 for (j = 0; j < df->def_info.bitmap_size; j++)
2843 struct df_ref *def = DF_DEFS_GET (df, j);
2846 fprintf (file, "d%d bb %d luid %d insn %d reg %d ",
2847 j, DF_REF_BBNO (def),
2848 DF_INSN_LUID (df, DF_REF_INSN (def)),
2849 DF_REF_INSN (def) ? DF_REF_INSN_UID (def) : -1,
2850 DF_REF_REGNO (def));
2851 if (def->flags & DF_REF_READ_WRITE)
2852 fprintf (file, "read/write ");
2853 df_chain_dump (df, DF_REF_CHAIN (def), file);
2854 fprintf (file, "\n");
2859 if (problem_data->flags & DF_UD_CHAIN)
2861 fprintf (file, "Use-def chains:\n");
2862 for (j = 0; j < df->use_info.bitmap_size; j++)
2864 struct df_ref *use = DF_USES_GET (df, j);
2867 fprintf (file, "u%d bb %d luid %d insn %d reg %d ",
2868 j, DF_REF_BBNO (use),
2870 DF_INSN_LUID (df, DF_REF_INSN (use))
2872 DF_REF_INSN (DF_USES_GET (df, j)) ?
2873 DF_REF_INSN_UID (DF_USES_GET (df,j))
2875 DF_REF_REGNO (use));
2876 if (use->flags & DF_REF_READ_WRITE)
2877 fprintf (file, "read/write ");
2878 if (use->flags & DF_REF_STRIPPED)
2879 fprintf (file, "stripped ");
2880 if (use->flags & DF_REF_IN_NOTE)
2881 fprintf (file, "note ");
2882 df_chain_dump (df, DF_REF_CHAIN (use), file);
2883 fprintf (file, "\n");
2890 static struct df_problem problem_CHAIN =
2892 DF_CHAIN, /* Problem id. */
2893 DF_NONE, /* Direction. */
2894 df_chain_alloc, /* Allocate the problem specific data. */
2895 NULL, /* Free basic block info. */
2896 NULL, /* Local compute function. */
2897 NULL, /* Init the solution specific data. */
2898 NULL, /* Iterative solver. */
2899 NULL, /* Confluence operator 0. */
2900 NULL, /* Confluence operator n. */
2901 NULL, /* Transfer function. */
2902 df_chain_finalize, /* Finalize function. */
2903 df_chain_free, /* Free all of the problem information. */
2904 df_chains_dump, /* Debugging. */
2905 &problem_RD /* Dependent problem. */
2909 /* Create a new DATAFLOW instance and add it to an existing instance
2910 of DF. The returned structure is what is used to get at the
2914 df_chain_add_problem (struct df *df, int flags)
2916 struct df_chain_problem_data *problem_data =
2917 xmalloc (sizeof (struct df_chain_problem_data));
2918 struct dataflow *dflow = df_add_problem (df, &problem_CHAIN);
2920 dflow->problem_data = problem_data;
2921 problem_data->flags = flags;
2927 /*----------------------------------------------------------------------------
2928 REGISTER INFORMATION
2930 Currently this consists of only lifetime information. But the plan is
2931 to enhance it so that it produces all of the register information needed
2932 by the register allocators.
2933 ----------------------------------------------------------------------------*/
2936 struct df_ri_problem_data
2942 /* Allocate the lifetime information. */
2945 df_ri_alloc (struct dataflow *dflow, bitmap blocks_to_rescan ATTRIBUTE_UNUSED)
2947 struct df_ri_problem_data *problem_data =
2948 (struct df_ri_problem_data *) dflow->problem_data;
2950 if (!dflow->problem_data)
2952 struct df_ri_problem_data *problem_data =
2953 xmalloc (sizeof (struct df_ri_problem_data));
2954 dflow->problem_data = problem_data;
2957 problem_data->lifetime = xrealloc (problem_data->lifetime,
2958 max_reg_num () *sizeof (int));
2959 memset (problem_data->lifetime, 0, max_reg_num () *sizeof (int));
2962 /* Compute register info: lifetime, bb, and number of defs and uses
2963 for basic block BB. */
2966 df_ri_bb_compute (struct dataflow *dflow, unsigned int bb_index, bitmap live)
2968 struct df *df = dflow->df;
2969 struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, bb_index);
2970 struct df_ri_problem_data *problem_data =
2971 (struct df_ri_problem_data *) dflow->problem_data;
2972 basic_block bb = BASIC_BLOCK (bb_index);
2975 bitmap_copy (live, bb_info->out);
2977 FOR_BB_INSNS_REVERSE (bb, insn)
2979 unsigned int uid = INSN_UID (insn);
2985 if (! INSN_P (insn))
2988 for (def = DF_INSN_UID_GET (df, uid)->defs; def; def = def->next_ref)
2990 unsigned int dregno = DF_REF_REGNO (def);
2992 /* Kill this register. */
2993 bitmap_clear_bit (live, dregno);
2996 for (use = DF_INSN_UID_GET (df, uid)->uses; use; use = use->next_ref)
2998 unsigned int uregno = DF_REF_REGNO (use);
3000 /* This register is now live. */
3001 bitmap_set_bit (live, uregno);
3004 /* Increment lifetimes of all live registers. */
3005 EXECUTE_IF_SET_IN_BITMAP (live, 0, regno, bi)
3007 problem_data->lifetime[regno]++;
3013 /* Compute register info: lifetime, bb, and number of defs and uses. */
3015 df_ri_compute (struct dataflow *dflow, bitmap all_blocks ATTRIBUTE_UNUSED,
3016 bitmap blocks_to_scan)
3018 unsigned int bb_index;
3022 live = BITMAP_ALLOC (NULL);
3024 EXECUTE_IF_SET_IN_BITMAP (blocks_to_scan, 0, bb_index, bi)
3026 df_ri_bb_compute (dflow, bb_index, live);
3033 /* Free all storage associated with the problem. */
3036 df_ri_free (struct dataflow *dflow)
3038 struct df_ri_problem_data *problem_data =
3039 (struct df_ri_problem_data *) dflow->problem_data;
3041 free (problem_data->lifetime);
3042 free (dflow->problem_data);
3047 /* Debugging info. */
3050 df_ri_dump (struct dataflow *dflow, FILE *file)
3052 struct df_ri_problem_data *problem_data =
3053 (struct df_ri_problem_data *) dflow->problem_data;
3056 fprintf (file, "Register info:\n");
3057 for (j = 0; j < max_reg_num (); j++)
3059 fprintf (file, "reg %d life %d\n", j, problem_data->lifetime[j]);
3063 /* All of the information associated every instance of the problem. */
3065 static struct df_problem problem_RI =
3067 DF_RI, /* Problem id. */
3068 DF_NONE, /* Direction. */
3069 df_ri_alloc, /* Allocate the problem specific data. */
3070 NULL, /* Free basic block info. */
3071 df_ri_compute, /* Local compute function. */
3072 NULL, /* Init the solution specific data. */
3073 NULL, /* Iterative solver. */
3074 NULL, /* Confluence operator 0. */
3075 NULL, /* Confluence operator n. */
3076 NULL, /* Transfer function. */
3077 NULL, /* Finalize function. */
3078 df_ri_free, /* Free all of the problem information. */
3079 df_ri_dump, /* Debugging. */
3080 &problem_UR /* Dependent problem. */
3084 /* Create a new DATAFLOW instance and add it to an existing instance
3085 of DF. The returned structure is what is used to get at the
3089 df_ri_add_problem (struct df *df)
3091 return df_add_problem (df, &problem_RI);
3095 /* Return total lifetime (in insns) of REG. */
3097 df_reg_lifetime (struct df *df, rtx reg)
3099 struct dataflow *dflow = df->problems_by_index[DF_RI];
3100 struct df_ri_problem_data *problem_data =
3101 (struct df_ri_problem_data *) dflow->problem_data;
3102 return problem_data->lifetime[REGNO (reg)];