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 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. */
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
,
328 basic_block bb ATTRIBUTE_UNUSED
,
331 struct df_ru_bb_info
*bb_info
= (struct df_ru_bb_info
*) vbb_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. */
348 df_ru_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
350 unsigned int bb_index
;
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
)
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
];
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
);
388 struct df_ru_problem_data
*problem_data
=
389 xmalloc (sizeof (struct df_ru_problem_data
));
390 dflow
->problem_data
= problem_data
;
392 problem_data
->use_sites
= xcalloc (reg_size
, sizeof (bitmap
));
393 problem_data
->use_sites_size
= reg_size
;
394 problem_data
->sparse_invalidated_by_call
= BITMAP_ALLOC (NULL
);
395 problem_data
->dense_invalidated_by_call
= BITMAP_ALLOC (NULL
);
398 df_grow_bb_info (dflow
);
400 /* Because of the clustering of all def sites for the same pseudo,
401 we have to process all of the blocks before doing the
404 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
406 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
409 bitmap_clear (bb_info
->kill
);
410 bitmap_clear (bb_info
->sparse_kill
);
411 bitmap_clear (bb_info
->gen
);
415 bb_info
= (struct df_ru_bb_info
*) pool_alloc (dflow
->block_pool
);
416 df_ru_set_bb_info (dflow
, bb_index
, bb_info
);
417 bb_info
->kill
= BITMAP_ALLOC (NULL
);
418 bb_info
->sparse_kill
= BITMAP_ALLOC (NULL
);
419 bb_info
->gen
= BITMAP_ALLOC (NULL
);
420 bb_info
->in
= BITMAP_ALLOC (NULL
);
421 bb_info
->out
= BITMAP_ALLOC (NULL
);
427 /* Process a list of DEFs for df_ru_bb_local_compute. */
430 df_ru_bb_local_compute_process_def (struct dataflow
*dflow
,
431 struct df_ru_bb_info
*bb_info
,
433 enum df_ref_flags top_flag
)
435 struct df
*df
= dflow
->df
;
438 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
440 unsigned int regno
= DF_REF_REGNO (def
);
441 unsigned int begin
= DF_REG_USE_GET (df
, regno
)->begin
;
442 unsigned int n_uses
= DF_REG_USE_GET (df
, regno
)->n_refs
;
443 if (!bitmap_bit_p (seen_in_block
, regno
))
445 /* The first def for regno, causes the kill info to be
446 generated and the gen information to cleared. */
447 if (!bitmap_bit_p (seen_in_insn
, regno
))
449 if (n_uses
> DF_SPARSE_THRESHOLD
)
451 bitmap_set_bit (bb_info
->sparse_kill
, regno
);
452 bitmap_clear_range (bb_info
->gen
, begin
, n_uses
);
456 struct df_ru_problem_data
* problem_data
=
457 (struct df_ru_problem_data
*)dflow
->problem_data
;
459 df_ref_bitmap (problem_data
->use_sites
, regno
,
461 bitmap_ior_into (bb_info
->kill
, uses
);
462 bitmap_and_compl_into (bb_info
->gen
, uses
);
465 bitmap_set_bit (seen_in_insn
, regno
);
473 /* Process a list of USEs for df_ru_bb_local_compute. */
476 df_ru_bb_local_compute_process_use (struct df_ru_bb_info
*bb_info
,
478 enum df_ref_flags top_flag
)
482 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
484 /* Add use to set of gens in this BB unless we have seen a
485 def in a previous instruction. */
486 unsigned int regno
= DF_REF_REGNO (use
);
487 if (!bitmap_bit_p (seen_in_block
, regno
))
488 bitmap_set_bit (bb_info
->gen
, DF_REF_ID (use
));
494 /* Compute local reaching use (upward exposed use) info for basic
495 block BB. USE_INFO->REGS[R] caches the set of uses for register R. */
497 df_ru_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
499 struct df
*df
= dflow
->df
;
500 basic_block bb
= BASIC_BLOCK (bb_index
);
501 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
504 /* Set when a def for regno is seen. */
505 bitmap_clear (seen_in_block
);
506 bitmap_clear (seen_in_insn
);
509 /* Variables defined in the prolog that are used by the exception
511 df_ru_bb_local_compute_process_use (bb_info
,
512 df_get_artificial_uses (df
, bb_index
),
515 df_ru_bb_local_compute_process_def (dflow
, bb_info
,
516 df_get_artificial_defs (df
, bb_index
),
519 FOR_BB_INSNS (bb
, insn
)
521 unsigned int uid
= INSN_UID (insn
);
525 df_ru_bb_local_compute_process_def (dflow
, bb_info
,
526 DF_INSN_UID_GET (df
, uid
)->defs
, 0);
528 /* The use processing must happen after the defs processing even
529 though the uses logically happen first since the defs clear
530 the gen set. Otherwise, a use for regno occuring in the same
531 instruction as a def for regno would be cleared. */
532 df_ru_bb_local_compute_process_use (bb_info
,
533 DF_INSN_UID_GET (df
, uid
)->uses
, 0);
535 bitmap_ior_into (seen_in_block
, seen_in_insn
);
536 bitmap_clear (seen_in_insn
);
539 /* Process the hardware registers that are always live. */
540 df_ru_bb_local_compute_process_use (bb_info
,
541 df_get_artificial_uses (df
, bb_index
), 0);
543 df_ru_bb_local_compute_process_def (dflow
, bb_info
,
544 df_get_artificial_defs (df
, bb_index
), 0);
548 /* Compute local reaching use (upward exposed use) info for each basic
549 block within BLOCKS. */
551 df_ru_local_compute (struct dataflow
*dflow
,
553 bitmap rescan_blocks ATTRIBUTE_UNUSED
)
555 struct df
*df
= dflow
->df
;
556 unsigned int bb_index
;
559 struct df_ru_problem_data
*problem_data
=
560 (struct df_ru_problem_data
*) dflow
->problem_data
;
561 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
562 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
566 if (!df
->use_info
.refs_organized
)
567 df_reorganize_refs (&df
->use_info
);
569 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
571 df_ru_bb_local_compute (dflow
, bb_index
);
574 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
575 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call
, 0, regno
, bi
)
577 struct df_reg_info
*reg_info
= DF_REG_USE_GET (df
, regno
);
578 if (reg_info
->n_refs
> DF_SPARSE_THRESHOLD
)
579 bitmap_set_bit (sparse_invalidated
, regno
);
582 bitmap defs
= df_ref_bitmap (problem_data
->use_sites
, regno
,
583 reg_info
->begin
, reg_info
->n_refs
);
584 bitmap_ior_into (dense_invalidated
, defs
);
592 /* Initialize the solution bit vectors for problem. */
595 df_ru_init_solution (struct dataflow
*dflow
, bitmap all_blocks
)
597 unsigned int bb_index
;
600 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
602 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
603 bitmap_copy (bb_info
->in
, bb_info
->gen
);
604 bitmap_clear (bb_info
->out
);
609 /* Out of target gets or of in of source. */
612 df_ru_confluence_n (struct dataflow
*dflow
, edge e
)
614 bitmap op1
= df_ru_get_bb_info (dflow
, e
->src
->index
)->out
;
615 bitmap op2
= df_ru_get_bb_info (dflow
, e
->dest
->index
)->in
;
617 if (e
->flags
& EDGE_EH
)
619 struct df_ru_problem_data
*problem_data
=
620 (struct df_ru_problem_data
*) dflow
->problem_data
;
621 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
622 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
623 struct df
*df
= dflow
->df
;
626 bitmap tmp
= BITMAP_ALLOC (NULL
);
628 bitmap_copy (tmp
, op2
);
629 bitmap_and_compl_into (tmp
, dense_invalidated
);
631 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
633 bitmap_clear_range (tmp
,
634 DF_REG_USE_GET (df
, regno
)->begin
,
635 DF_REG_USE_GET (df
, regno
)->n_refs
);
637 bitmap_ior_into (op1
, tmp
);
641 bitmap_ior_into (op1
, op2
);
645 /* Transfer function. */
648 df_ru_transfer_function (struct dataflow
*dflow
, int bb_index
)
650 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
653 bitmap in
= bb_info
->in
;
654 bitmap out
= bb_info
->out
;
655 bitmap gen
= bb_info
->gen
;
656 bitmap kill
= bb_info
->kill
;
657 bitmap sparse_kill
= bb_info
->sparse_kill
;
659 if (bitmap_empty_p (sparse_kill
))
660 return bitmap_ior_and_compl (in
, gen
, out
, kill
);
663 struct df
*df
= dflow
->df
;
664 bool changed
= false;
665 bitmap tmp
= BITMAP_ALLOC (NULL
);
666 bitmap_copy (tmp
, in
);
667 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
669 bitmap_clear_range (tmp
,
670 DF_REG_USE_GET (df
, regno
)->begin
,
671 DF_REG_USE_GET (df
, regno
)->n_refs
);
673 bitmap_and_compl_into (tmp
, kill
);
674 bitmap_ior_into (tmp
, gen
);
675 changed
= !bitmap_equal_p (tmp
, in
);
688 /* Free all storage associated with the problem. */
691 df_ru_free (struct dataflow
*dflow
)
694 struct df_ru_problem_data
*problem_data
=
695 (struct df_ru_problem_data
*) dflow
->problem_data
;
699 for (i
= 0; i
< dflow
->block_info_size
; i
++)
701 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, i
);
704 BITMAP_FREE (bb_info
->kill
);
705 BITMAP_FREE (bb_info
->sparse_kill
);
706 BITMAP_FREE (bb_info
->gen
);
707 BITMAP_FREE (bb_info
->in
);
708 BITMAP_FREE (bb_info
->out
);
712 free_alloc_pool (dflow
->block_pool
);
714 for (i
= 0; i
< problem_data
->use_sites_size
; i
++)
716 bitmap bm
= problem_data
->use_sites
[i
];
721 free (problem_data
->use_sites
);
722 BITMAP_FREE (problem_data
->sparse_invalidated_by_call
);
723 BITMAP_FREE (problem_data
->dense_invalidated_by_call
);
725 dflow
->block_info_size
= 0;
726 free (dflow
->block_info
);
727 free (dflow
->problem_data
);
733 /* Debugging info. */
736 df_ru_dump (struct dataflow
*dflow
, FILE *file
)
739 struct df
*df
= dflow
->df
;
740 struct df_ru_problem_data
*problem_data
=
741 (struct df_ru_problem_data
*) dflow
->problem_data
;
742 unsigned int m
= max_reg_num ();
745 fprintf (file
, "Reaching uses:\n");
747 fprintf (file
, " sparse invalidated \t");
748 dump_bitmap (file
, problem_data
->sparse_invalidated_by_call
);
749 fprintf (file
, " dense invalidated \t");
750 dump_bitmap (file
, problem_data
->dense_invalidated_by_call
);
752 for (regno
= 0; regno
< m
; regno
++)
753 if (DF_REG_USE_GET (df
, regno
)->n_refs
)
754 fprintf (file
, "%d[%d,%d] ", regno
,
755 DF_REG_USE_GET (df
, regno
)->begin
,
756 DF_REG_USE_GET (df
, regno
)->n_refs
);
757 fprintf (file
, "\n");
761 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb
->index
);
762 df_print_bb_index (bb
, file
);
767 fprintf (file
, " in \t");
768 dump_bitmap (file
, bb_info
->in
);
769 fprintf (file
, " gen \t");
770 dump_bitmap (file
, bb_info
->gen
);
771 fprintf (file
, " kill\t");
772 dump_bitmap (file
, bb_info
->kill
);
773 fprintf (file
, " out \t");
774 dump_bitmap (file
, bb_info
->out
);
778 /* All of the information associated with every instance of the problem. */
780 static struct df_problem problem_RU
=
782 DF_RU
, /* Problem id. */
783 DF_BACKWARD
, /* Direction. */
784 df_ru_alloc
, /* Allocate the problem specific data. */
785 NULL
, /* Reset global information. */
786 df_ru_free_bb_info
, /* Free basic block info. */
787 df_ru_local_compute
, /* Local compute function. */
788 df_ru_init_solution
, /* Init the solution specific data. */
789 df_iterative_dataflow
, /* Iterative solver. */
790 NULL
, /* Confluence operator 0. */
791 df_ru_confluence_n
, /* Confluence operator n. */
792 df_ru_transfer_function
, /* Transfer function. */
793 NULL
, /* Finalize function. */
794 df_ru_free
, /* Free all of the problem information. */
795 df_ru_dump
, /* Debugging. */
796 NULL
/* Dependent problem. */
801 /* Create a new DATAFLOW instance and add it to an existing instance
802 of DF. The returned structure is what is used to get at the
806 df_ru_add_problem (struct df
*df
)
808 return df_add_problem (df
, &problem_RU
);
812 /*----------------------------------------------------------------------------
815 Find the locations in the function where each definition site for a
817 ----------------------------------------------------------------------------*/
819 struct df_rd_problem_data
821 bitmap
*def_sites
; /* Bitmap of defs for each pseudo. */
822 unsigned int def_sites_size
; /* Size of def_sites. */
823 /* The set of defs to regs invalidated by call. */
824 bitmap sparse_invalidated_by_call
;
825 /* The set of defs to regs invalidate by call for ru. */
826 bitmap dense_invalidated_by_call
;
829 /* Get basic block info. */
831 struct df_rd_bb_info
*
832 df_rd_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
834 return (struct df_rd_bb_info
*) dflow
->block_info
[index
];
838 /* Set basic block info. */
841 df_rd_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
842 struct df_rd_bb_info
*bb_info
)
844 dflow
->block_info
[index
] = bb_info
;
848 /* Free basic block info. */
851 df_rd_free_bb_info (struct dataflow
*dflow
,
852 basic_block bb ATTRIBUTE_UNUSED
,
855 struct df_rd_bb_info
*bb_info
= (struct df_rd_bb_info
*) vbb_info
;
858 BITMAP_FREE (bb_info
->kill
);
859 BITMAP_FREE (bb_info
->sparse_kill
);
860 BITMAP_FREE (bb_info
->gen
);
861 BITMAP_FREE (bb_info
->in
);
862 BITMAP_FREE (bb_info
->out
);
863 pool_free (dflow
->block_pool
, bb_info
);
868 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
869 not touched unless the block is new. */
872 df_rd_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
874 unsigned int bb_index
;
876 unsigned int reg_size
= max_reg_num ();
878 if (! dflow
->block_pool
)
879 dflow
->block_pool
= create_alloc_pool ("df_rd_block pool",
880 sizeof (struct df_rd_bb_info
), 50);
882 if (dflow
->problem_data
)
885 struct df_rd_problem_data
*problem_data
=
886 (struct df_rd_problem_data
*) dflow
->problem_data
;
888 for (i
= 0; i
< problem_data
->def_sites_size
; i
++)
890 bitmap bm
= problem_data
->def_sites
[i
];
894 problem_data
->def_sites
[i
] = NULL
;
898 if (problem_data
->def_sites_size
< reg_size
)
900 problem_data
->def_sites
901 = xrealloc (problem_data
->def_sites
, reg_size
*sizeof (bitmap
));
902 memset (problem_data
->def_sites
+ problem_data
->def_sites_size
, 0,
903 (reg_size
- problem_data
->def_sites_size
) *sizeof (bitmap
));
904 problem_data
->def_sites_size
= reg_size
;
907 bitmap_clear (problem_data
->sparse_invalidated_by_call
);
908 bitmap_clear (problem_data
->dense_invalidated_by_call
);
912 struct df_rd_problem_data
*problem_data
=
913 xmalloc (sizeof (struct df_rd_problem_data
));
914 dflow
->problem_data
= problem_data
;
916 problem_data
->def_sites
= xcalloc (reg_size
, sizeof (bitmap
));
917 problem_data
->def_sites_size
= reg_size
;
918 problem_data
->sparse_invalidated_by_call
= BITMAP_ALLOC (NULL
);
919 problem_data
->dense_invalidated_by_call
= BITMAP_ALLOC (NULL
);
922 df_grow_bb_info (dflow
);
924 /* Because of the clustering of all def sites for the same pseudo,
925 we have to process all of the blocks before doing the
928 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
930 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
933 bitmap_clear (bb_info
->kill
);
934 bitmap_clear (bb_info
->sparse_kill
);
935 bitmap_clear (bb_info
->gen
);
939 bb_info
= (struct df_rd_bb_info
*) pool_alloc (dflow
->block_pool
);
940 df_rd_set_bb_info (dflow
, bb_index
, bb_info
);
941 bb_info
->kill
= BITMAP_ALLOC (NULL
);
942 bb_info
->sparse_kill
= BITMAP_ALLOC (NULL
);
943 bb_info
->gen
= BITMAP_ALLOC (NULL
);
944 bb_info
->in
= BITMAP_ALLOC (NULL
);
945 bb_info
->out
= BITMAP_ALLOC (NULL
);
951 /* Process a list of DEFs for df_rd_bb_local_compute. */
954 df_rd_bb_local_compute_process_def (struct dataflow
*dflow
,
955 struct df_rd_bb_info
*bb_info
,
957 enum df_ref_flags top_flag
)
959 struct df
*df
= dflow
->df
;
962 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
964 unsigned int regno
= DF_REF_REGNO (def
);
965 unsigned int begin
= DF_REG_DEF_GET (df
, regno
)->begin
;
966 unsigned int n_defs
= DF_REG_DEF_GET (df
, regno
)->n_refs
;
968 /* Only the last def(s) for a regno in the block has any
970 if (!bitmap_bit_p (seen_in_block
, regno
))
972 /* The first def for regno in insn gets to knock out the
973 defs from other instructions. */
974 if (!bitmap_bit_p (seen_in_insn
, regno
))
976 if (n_defs
> DF_SPARSE_THRESHOLD
)
978 bitmap_set_bit (bb_info
->sparse_kill
, regno
);
979 bitmap_clear_range(bb_info
->gen
, begin
, n_defs
);
983 struct df_rd_problem_data
* problem_data
=
984 (struct df_rd_problem_data
*)dflow
->problem_data
;
986 df_ref_bitmap (problem_data
->def_sites
, regno
,
988 bitmap_ior_into (bb_info
->kill
, defs
);
989 bitmap_and_compl_into (bb_info
->gen
, defs
);
993 bitmap_set_bit (seen_in_insn
, regno
);
994 /* All defs for regno in the instruction may be put into
996 if (! (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
))
997 bitmap_set_bit (bb_info
->gen
, DF_REF_ID (def
));
1000 def
= def
->next_ref
;
1004 /* Compute local reaching def info for basic block BB. */
1007 df_rd_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
1009 struct df
*df
= dflow
->df
;
1010 basic_block bb
= BASIC_BLOCK (bb_index
);
1011 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
1014 bitmap_clear (seen_in_block
);
1015 bitmap_clear (seen_in_insn
);
1017 df_rd_bb_local_compute_process_def (dflow
, bb_info
,
1018 df_get_artificial_defs (df
, bb_index
), 0);
1020 FOR_BB_INSNS_REVERSE (bb
, insn
)
1022 unsigned int uid
= INSN_UID (insn
);
1024 if (! INSN_P (insn
))
1027 df_rd_bb_local_compute_process_def (dflow
, bb_info
,
1028 DF_INSN_UID_GET (df
, uid
)->defs
, 0);
1030 /* This complex dance with the two bitmaps is required because
1031 instructions can assign twice to the same pseudo. This
1032 generally happens with calls that will have one def for the
1033 result and another def for the clobber. If only one vector
1034 is used and the clobber goes first, the result will be
1036 bitmap_ior_into (seen_in_block
, seen_in_insn
);
1037 bitmap_clear (seen_in_insn
);
1040 /* Process the artificial defs at the top of the block last since we
1041 are going backwards through the block and these are logically at
1043 df_rd_bb_local_compute_process_def (dflow
, bb_info
,
1044 df_get_artificial_defs (df
, bb_index
),
1049 /* Compute local reaching def info for each basic block within BLOCKS. */
1052 df_rd_local_compute (struct dataflow
*dflow
,
1054 bitmap rescan_blocks ATTRIBUTE_UNUSED
)
1056 struct df
*df
= dflow
->df
;
1057 unsigned int bb_index
;
1060 struct df_rd_problem_data
*problem_data
=
1061 (struct df_rd_problem_data
*) dflow
->problem_data
;
1062 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
1063 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
1067 if (!df
->def_info
.refs_organized
)
1068 df_reorganize_refs (&df
->def_info
);
1070 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1072 df_rd_bb_local_compute (dflow
, bb_index
);
1075 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
1076 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call
, 0, regno
, bi
)
1078 struct df_reg_info
*reg_info
= DF_REG_DEF_GET (df
, regno
);
1079 if (reg_info
->n_refs
> DF_SPARSE_THRESHOLD
)
1081 bitmap_set_bit (sparse_invalidated
, regno
);
1085 bitmap defs
= df_ref_bitmap (problem_data
->def_sites
, regno
,
1086 reg_info
->begin
, reg_info
->n_refs
);
1087 bitmap_ior_into (dense_invalidated
, defs
);
1094 /* Initialize the solution bit vectors for problem. */
1097 df_rd_init_solution (struct dataflow
*dflow
, bitmap all_blocks
)
1099 unsigned int bb_index
;
1102 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1104 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
1106 bitmap_copy (bb_info
->out
, bb_info
->gen
);
1107 bitmap_clear (bb_info
->in
);
1111 /* In of target gets or of out of source. */
1114 df_rd_confluence_n (struct dataflow
*dflow
, edge e
)
1116 bitmap op1
= df_rd_get_bb_info (dflow
, e
->dest
->index
)->in
;
1117 bitmap op2
= df_rd_get_bb_info (dflow
, e
->src
->index
)->out
;
1119 if (e
->flags
& EDGE_EH
)
1121 struct df_rd_problem_data
*problem_data
=
1122 (struct df_rd_problem_data
*) dflow
->problem_data
;
1123 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
1124 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
1125 struct df
*df
= dflow
->df
;
1128 bitmap tmp
= BITMAP_ALLOC (NULL
);
1130 bitmap_copy (tmp
, op2
);
1131 bitmap_and_compl_into (tmp
, dense_invalidated
);
1133 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
1135 bitmap_clear_range (tmp
,
1136 DF_REG_DEF_GET (df
, regno
)->begin
,
1137 DF_REG_DEF_GET (df
, regno
)->n_refs
);
1139 bitmap_ior_into (op1
, tmp
);
1143 bitmap_ior_into (op1
, op2
);
1147 /* Transfer function. */
1150 df_rd_transfer_function (struct dataflow
*dflow
, int bb_index
)
1152 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
1155 bitmap in
= bb_info
->in
;
1156 bitmap out
= bb_info
->out
;
1157 bitmap gen
= bb_info
->gen
;
1158 bitmap kill
= bb_info
->kill
;
1159 bitmap sparse_kill
= bb_info
->sparse_kill
;
1161 if (bitmap_empty_p (sparse_kill
))
1162 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
1165 struct df
*df
= dflow
->df
;
1166 bool changed
= false;
1167 bitmap tmp
= BITMAP_ALLOC (NULL
);
1168 bitmap_copy (tmp
, in
);
1169 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
1171 bitmap_clear_range (tmp
,
1172 DF_REG_DEF_GET (df
, regno
)->begin
,
1173 DF_REG_DEF_GET (df
, regno
)->n_refs
);
1175 bitmap_and_compl_into (tmp
, kill
);
1176 bitmap_ior_into (tmp
, gen
);
1177 changed
= !bitmap_equal_p (tmp
, out
);
1190 /* Free all storage associated with the problem. */
1193 df_rd_free (struct dataflow
*dflow
)
1196 struct df_rd_problem_data
*problem_data
=
1197 (struct df_rd_problem_data
*) dflow
->problem_data
;
1201 for (i
= 0; i
< dflow
->block_info_size
; i
++)
1203 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, i
);
1206 BITMAP_FREE (bb_info
->kill
);
1207 BITMAP_FREE (bb_info
->sparse_kill
);
1208 BITMAP_FREE (bb_info
->gen
);
1209 BITMAP_FREE (bb_info
->in
);
1210 BITMAP_FREE (bb_info
->out
);
1214 free_alloc_pool (dflow
->block_pool
);
1216 for (i
= 0; i
< problem_data
->def_sites_size
; i
++)
1218 bitmap bm
= problem_data
->def_sites
[i
];
1223 free (problem_data
->def_sites
);
1224 BITMAP_FREE (problem_data
->sparse_invalidated_by_call
);
1225 BITMAP_FREE (problem_data
->dense_invalidated_by_call
);
1227 dflow
->block_info_size
= 0;
1228 free (dflow
->block_info
);
1229 free (dflow
->problem_data
);
1235 /* Debugging info. */
1238 df_rd_dump (struct dataflow
*dflow
, FILE *file
)
1240 struct df
*df
= dflow
->df
;
1242 struct df_rd_problem_data
*problem_data
=
1243 (struct df_rd_problem_data
*) dflow
->problem_data
;
1244 unsigned int m
= max_reg_num ();
1247 fprintf (file
, "Reaching defs:\n\n");
1249 fprintf (file
, " sparse invalidated \t");
1250 dump_bitmap (file
, problem_data
->sparse_invalidated_by_call
);
1251 fprintf (file
, " dense invalidated \t");
1252 dump_bitmap (file
, problem_data
->dense_invalidated_by_call
);
1254 for (regno
= 0; regno
< m
; regno
++)
1255 if (DF_REG_DEF_GET (df
, regno
)->n_refs
)
1256 fprintf (file
, "%d[%d,%d] ", regno
,
1257 DF_REG_DEF_GET (df
, regno
)->begin
,
1258 DF_REG_DEF_GET (df
, regno
)->n_refs
);
1259 fprintf (file
, "\n");
1263 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb
->index
);
1264 df_print_bb_index (bb
, file
);
1269 fprintf (file
, " in\t(%d)\n", (int) bitmap_count_bits (bb_info
->in
));
1270 dump_bitmap (file
, bb_info
->in
);
1271 fprintf (file
, " gen \t(%d)\n", (int) bitmap_count_bits (bb_info
->gen
));
1272 dump_bitmap (file
, bb_info
->gen
);
1273 fprintf (file
, " kill\t(%d)\n", (int) bitmap_count_bits (bb_info
->kill
));
1274 dump_bitmap (file
, bb_info
->kill
);
1275 fprintf (file
, " out\t(%d)\n", (int) bitmap_count_bits (bb_info
->out
));
1276 dump_bitmap (file
, bb_info
->out
);
1280 /* All of the information associated with every instance of the problem. */
1282 static struct df_problem problem_RD
=
1284 DF_RD
, /* Problem id. */
1285 DF_FORWARD
, /* Direction. */
1286 df_rd_alloc
, /* Allocate the problem specific data. */
1287 NULL
, /* Reset global information. */
1288 df_rd_free_bb_info
, /* Free basic block info. */
1289 df_rd_local_compute
, /* Local compute function. */
1290 df_rd_init_solution
, /* Init the solution specific data. */
1291 df_iterative_dataflow
, /* Iterative solver. */
1292 NULL
, /* Confluence operator 0. */
1293 df_rd_confluence_n
, /* Confluence operator n. */
1294 df_rd_transfer_function
, /* Transfer function. */
1295 NULL
, /* Finalize function. */
1296 df_rd_free
, /* Free all of the problem information. */
1297 df_rd_dump
, /* Debugging. */
1298 NULL
/* Dependent problem. */
1303 /* Create a new DATAFLOW instance and add it to an existing instance
1304 of DF. The returned structure is what is used to get at the
1308 df_rd_add_problem (struct df
*df
)
1310 return df_add_problem (df
, &problem_RD
);
1315 /*----------------------------------------------------------------------------
1318 Find the locations in the function where any use of a pseudo can reach
1319 in the backwards direction.
1320 ----------------------------------------------------------------------------*/
1322 /* Get basic block info. */
1324 struct df_lr_bb_info
*
1325 df_lr_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
1327 return (struct df_lr_bb_info
*) dflow
->block_info
[index
];
1331 /* Set basic block info. */
1334 df_lr_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
1335 struct df_lr_bb_info
*bb_info
)
1337 dflow
->block_info
[index
] = bb_info
;
1341 /* Free basic block info. */
1344 df_lr_free_bb_info (struct dataflow
*dflow
,
1345 basic_block bb ATTRIBUTE_UNUSED
,
1348 struct df_lr_bb_info
*bb_info
= (struct df_lr_bb_info
*) vbb_info
;
1351 BITMAP_FREE (bb_info
->use
);
1352 BITMAP_FREE (bb_info
->def
);
1353 BITMAP_FREE (bb_info
->in
);
1354 BITMAP_FREE (bb_info
->out
);
1355 pool_free (dflow
->block_pool
, bb_info
);
1360 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1361 not touched unless the block is new. */
1364 df_lr_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
1366 unsigned int bb_index
;
1369 if (! dflow
->block_pool
)
1370 dflow
->block_pool
= create_alloc_pool ("df_lr_block pool",
1371 sizeof (struct df_lr_bb_info
), 50);
1373 df_grow_bb_info (dflow
);
1375 /* Because of the clustering of all def sites for the same pseudo,
1376 we have to process all of the blocks before doing the
1379 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
1381 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1384 bitmap_clear (bb_info
->def
);
1385 bitmap_clear (bb_info
->use
);
1389 bb_info
= (struct df_lr_bb_info
*) pool_alloc (dflow
->block_pool
);
1390 df_lr_set_bb_info (dflow
, bb_index
, bb_info
);
1391 bb_info
->use
= BITMAP_ALLOC (NULL
);
1392 bb_info
->def
= BITMAP_ALLOC (NULL
);
1393 bb_info
->in
= BITMAP_ALLOC (NULL
);
1394 bb_info
->out
= BITMAP_ALLOC (NULL
);
1400 /* Compute local live register info for basic block BB. */
1403 df_lr_bb_local_compute (struct dataflow
*dflow
,
1404 struct df
*df
, unsigned int bb_index
)
1406 basic_block bb
= BASIC_BLOCK (bb_index
);
1407 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1412 /* Process the registers set in an exception handler. */
1413 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1414 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
1416 unsigned int dregno
= DF_REF_REGNO (def
);
1417 bitmap_set_bit (bb_info
->def
, dregno
);
1418 bitmap_clear_bit (bb_info
->use
, dregno
);
1421 /* Process the hardware registers that are always live. */
1422 for (use
= df_get_artificial_uses (df
, bb_index
); use
; use
= use
->next_ref
)
1423 /* Add use to set of uses in this BB. */
1424 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
1425 bitmap_set_bit (bb_info
->use
, DF_REF_REGNO (use
));
1427 FOR_BB_INSNS_REVERSE (bb
, insn
)
1429 unsigned int uid
= INSN_UID (insn
);
1431 if (! INSN_P (insn
))
1436 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
1438 unsigned int dregno
= DF_REF_REGNO (def
);
1440 if (dregno
>= FIRST_PSEUDO_REGISTER
1441 || !(SIBLING_CALL_P (insn
)
1442 && bitmap_bit_p (df
->exit_block_uses
, dregno
)
1443 && !refers_to_regno_p (dregno
, dregno
+1,
1444 current_function_return_rtx
,
1447 /* Add def to set of defs in this BB. */
1448 bitmap_set_bit (bb_info
->def
, dregno
);
1449 bitmap_clear_bit (bb_info
->use
, dregno
);
1455 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
1457 unsigned int dregno
= DF_REF_REGNO (def
);
1459 if (DF_INSN_CONTAINS_ASM (df
, insn
)
1460 && dregno
< FIRST_PSEUDO_REGISTER
)
1464 dregno
+ hard_regno_nregs
[dregno
][GET_MODE (DF_REF_REG (def
))] - 1;
1465 for (i
= dregno
; i
<= end
; ++i
)
1466 regs_asm_clobbered
[i
] = 1;
1468 /* Add def to set of defs in this BB. */
1469 bitmap_set_bit (bb_info
->def
, dregno
);
1470 bitmap_clear_bit (bb_info
->use
, dregno
);
1474 for (use
= DF_INSN_UID_GET (df
, uid
)->uses
; use
; use
= use
->next_ref
)
1475 /* Add use to set of uses in this BB. */
1476 bitmap_set_bit (bb_info
->use
, DF_REF_REGNO (use
));
1479 /* Process the registers set in an exception handler. */
1480 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1481 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
1483 unsigned int dregno
= DF_REF_REGNO (def
);
1484 bitmap_set_bit (bb_info
->def
, dregno
);
1485 bitmap_clear_bit (bb_info
->use
, dregno
);
1489 /* Process the uses that are live into an exception handler. */
1490 for (use
= df_get_artificial_uses (df
, bb_index
); use
; use
= use
->next_ref
)
1491 /* Add use to set of uses in this BB. */
1492 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
1493 bitmap_set_bit (bb_info
->use
, DF_REF_REGNO (use
));
1497 /* Compute local live register info for each basic block within BLOCKS. */
1500 df_lr_local_compute (struct dataflow
*dflow
,
1502 bitmap rescan_blocks
)
1504 struct df
*df
= dflow
->df
;
1505 unsigned int bb_index
;
1508 /* Assume that the stack pointer is unchanging if alloca hasn't
1510 if (bitmap_equal_p (all_blocks
, rescan_blocks
))
1511 memset (regs_asm_clobbered
, 0, sizeof (regs_asm_clobbered
));
1513 bitmap_clear (df
->hardware_regs_used
);
1515 /* The all-important stack pointer must always be live. */
1516 bitmap_set_bit (df
->hardware_regs_used
, STACK_POINTER_REGNUM
);
1518 /* Before reload, there are a few registers that must be forced
1519 live everywhere -- which might not already be the case for
1520 blocks within infinite loops. */
1521 if (! reload_completed
)
1523 /* Any reference to any pseudo before reload is a potential
1524 reference of the frame pointer. */
1525 bitmap_set_bit (df
->hardware_regs_used
, FRAME_POINTER_REGNUM
);
1527 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1528 /* Pseudos with argument area equivalences may require
1529 reloading via the argument pointer. */
1530 if (fixed_regs
[ARG_POINTER_REGNUM
])
1531 bitmap_set_bit (df
->hardware_regs_used
, ARG_POINTER_REGNUM
);
1534 /* Any constant, or pseudo with constant equivalences, may
1535 require reloading from memory using the pic register. */
1536 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
1537 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
1538 bitmap_set_bit (df
->hardware_regs_used
, PIC_OFFSET_TABLE_REGNUM
);
1541 if (bitmap_bit_p (rescan_blocks
, EXIT_BLOCK
))
1543 /* The exit block is special for this problem and its bits are
1544 computed from thin air. */
1545 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, EXIT_BLOCK
);
1546 bitmap_copy (bb_info
->use
, df
->exit_block_uses
);
1549 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks
, 0, bb_index
, bi
)
1551 if (bb_index
== EXIT_BLOCK
)
1553 df_lr_bb_local_compute (dflow
, df
, bb_index
);
1558 /* Initialize the solution vectors. */
1561 df_lr_init (struct dataflow
*dflow
, bitmap all_blocks
)
1563 unsigned int bb_index
;
1566 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1568 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1569 bitmap_copy (bb_info
->in
, bb_info
->use
);
1570 bitmap_clear (bb_info
->out
);
1575 /* Confluence function that processes infinite loops. This might be a
1576 noreturn function that throws. And even if it isn't, getting the
1577 unwind info right helps debugging. */
1579 df_lr_confluence_0 (struct dataflow
*dflow
, basic_block bb
)
1581 struct df
*df
= dflow
->df
;
1583 bitmap op1
= df_lr_get_bb_info (dflow
, bb
->index
)->out
;
1584 if (bb
!= EXIT_BLOCK_PTR
)
1585 bitmap_copy (op1
, df
->hardware_regs_used
);
1589 /* Confluence function that ignores fake edges. */
1591 df_lr_confluence_n (struct dataflow
*dflow
, edge e
)
1593 bitmap op1
= df_lr_get_bb_info (dflow
, e
->src
->index
)->out
;
1594 bitmap op2
= df_lr_get_bb_info (dflow
, e
->dest
->index
)->in
;
1596 /* Call-clobbered registers die across exception and call edges. */
1597 /* ??? Abnormal call edges ignored for the moment, as this gets
1598 confused by sibling call edges, which crashes reg-stack. */
1599 if (e
->flags
& EDGE_EH
)
1600 bitmap_ior_and_compl_into (op1
, op2
, df_invalidated_by_call
);
1602 bitmap_ior_into (op1
, op2
);
1604 bitmap_ior_into (op1
, dflow
->df
->hardware_regs_used
);
1608 /* Transfer function. */
1610 df_lr_transfer_function (struct dataflow
*dflow
, int bb_index
)
1612 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1613 bitmap in
= bb_info
->in
;
1614 bitmap out
= bb_info
->out
;
1615 bitmap use
= bb_info
->use
;
1616 bitmap def
= bb_info
->def
;
1618 return bitmap_ior_and_compl (in
, use
, out
, def
);
1622 /* Free all storage associated with the problem. */
1625 df_lr_free (struct dataflow
*dflow
)
1627 if (dflow
->block_info
)
1630 for (i
= 0; i
< dflow
->block_info_size
; i
++)
1632 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, i
);
1635 BITMAP_FREE (bb_info
->use
);
1636 BITMAP_FREE (bb_info
->def
);
1637 BITMAP_FREE (bb_info
->in
);
1638 BITMAP_FREE (bb_info
->out
);
1641 free_alloc_pool (dflow
->block_pool
);
1643 dflow
->block_info_size
= 0;
1644 free (dflow
->block_info
);
1650 /* Debugging info. */
1653 df_lr_dump (struct dataflow
*dflow
, FILE *file
)
1657 fprintf (file
, "Live Registers:\n");
1660 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb
->index
);
1661 df_print_bb_index (bb
, file
);
1666 fprintf (file
, " in \t");
1667 dump_bitmap (file
, bb_info
->in
);
1668 fprintf (file
, " use \t");
1669 dump_bitmap (file
, bb_info
->use
);
1670 fprintf (file
, " def \t");
1671 dump_bitmap (file
, bb_info
->def
);
1672 fprintf (file
, " out \t");
1673 dump_bitmap (file
, bb_info
->out
);
1677 /* All of the information associated with every instance of the problem. */
1679 static struct df_problem problem_LR
=
1681 DF_LR
, /* Problem id. */
1682 DF_BACKWARD
, /* Direction. */
1683 df_lr_alloc
, /* Allocate the problem specific data. */
1684 NULL
, /* Reset global information. */
1685 df_lr_free_bb_info
, /* Free basic block info. */
1686 df_lr_local_compute
, /* Local compute function. */
1687 df_lr_init
, /* Init the solution specific data. */
1688 df_iterative_dataflow
, /* Iterative solver. */
1689 df_lr_confluence_0
, /* Confluence operator 0. */
1690 df_lr_confluence_n
, /* Confluence operator n. */
1691 df_lr_transfer_function
, /* Transfer function. */
1692 NULL
, /* Finalize function. */
1693 df_lr_free
, /* Free all of the problem information. */
1694 df_lr_dump
, /* Debugging. */
1695 NULL
/* Dependent problem. */
1699 /* Create a new DATAFLOW instance and add it to an existing instance
1700 of DF. The returned structure is what is used to get at the
1704 df_lr_add_problem (struct df
*df
)
1706 return df_add_problem (df
, &problem_LR
);
1711 /*----------------------------------------------------------------------------
1712 UNINITIALIZED REGISTERS
1714 Find the set of uses for registers that are reachable from the entry
1715 block without passing thru a definition.
1716 ----------------------------------------------------------------------------*/
1718 /* Get basic block info. */
1720 struct df_ur_bb_info
*
1721 df_ur_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
1723 return (struct df_ur_bb_info
*) dflow
->block_info
[index
];
1727 /* Set basic block info. */
1730 df_ur_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
1731 struct df_ur_bb_info
*bb_info
)
1733 dflow
->block_info
[index
] = bb_info
;
1737 /* Free basic block info. */
1740 df_ur_free_bb_info (struct dataflow
*dflow
,
1741 basic_block bb ATTRIBUTE_UNUSED
,
1744 struct df_ur_bb_info
*bb_info
= (struct df_ur_bb_info
*) vbb_info
;
1747 BITMAP_FREE (bb_info
->gen
);
1748 BITMAP_FREE (bb_info
->kill
);
1749 BITMAP_FREE (bb_info
->in
);
1750 BITMAP_FREE (bb_info
->out
);
1751 pool_free (dflow
->block_pool
, bb_info
);
1756 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1757 not touched unless the block is new. */
1760 df_ur_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
1762 unsigned int bb_index
;
1765 if (! dflow
->block_pool
)
1766 dflow
->block_pool
= create_alloc_pool ("df_ur_block pool",
1767 sizeof (struct df_ur_bb_info
), 100);
1769 df_grow_bb_info (dflow
);
1771 /* Because of the clustering of all def sites for the same pseudo,
1772 we have to process all of the blocks before doing the
1775 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
1777 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1780 bitmap_clear (bb_info
->kill
);
1781 bitmap_clear (bb_info
->gen
);
1785 bb_info
= (struct df_ur_bb_info
*) pool_alloc (dflow
->block_pool
);
1786 df_ur_set_bb_info (dflow
, bb_index
, bb_info
);
1787 bb_info
->kill
= BITMAP_ALLOC (NULL
);
1788 bb_info
->gen
= BITMAP_ALLOC (NULL
);
1789 bb_info
->in
= BITMAP_ALLOC (NULL
);
1790 bb_info
->out
= BITMAP_ALLOC (NULL
);
1796 /* Compute local uninitialized register info for basic block BB. */
1799 df_ur_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
1801 struct df
*df
= dflow
->df
;
1802 basic_block bb
= BASIC_BLOCK (bb_index
);
1803 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1807 bitmap_clear (seen_in_block
);
1808 bitmap_clear (seen_in_insn
);
1810 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1811 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
1813 unsigned int regno
= DF_REF_REGNO (def
);
1814 if (!bitmap_bit_p (seen_in_block
, regno
))
1816 bitmap_set_bit (seen_in_block
, regno
);
1817 bitmap_set_bit (bb_info
->gen
, regno
);
1821 FOR_BB_INSNS_REVERSE (bb
, insn
)
1823 unsigned int uid
= INSN_UID (insn
);
1827 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
1829 unsigned int regno
= DF_REF_REGNO (def
);
1830 /* Only the last def counts. */
1831 if (!bitmap_bit_p (seen_in_block
, regno
))
1833 bitmap_set_bit (seen_in_insn
, regno
);
1835 if (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
)
1836 bitmap_set_bit (bb_info
->kill
, regno
);
1838 bitmap_set_bit (bb_info
->gen
, regno
);
1841 bitmap_ior_into (seen_in_block
, seen_in_insn
);
1842 bitmap_clear (seen_in_insn
);
1845 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1846 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
1848 unsigned int regno
= DF_REF_REGNO (def
);
1849 if (!bitmap_bit_p (seen_in_block
, regno
))
1851 bitmap_set_bit (seen_in_block
, regno
);
1852 bitmap_set_bit (bb_info
->gen
, regno
);
1858 /* Compute local uninitialized register info. */
1861 df_ur_local_compute (struct dataflow
*dflow
,
1862 bitmap all_blocks ATTRIBUTE_UNUSED
,
1863 bitmap rescan_blocks
)
1865 unsigned int bb_index
;
1870 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks
, 0, bb_index
, bi
)
1872 df_ur_bb_local_compute (dflow
, bb_index
);
1879 /* Initialize the solution vectors. */
1882 df_ur_init (struct dataflow
*dflow
, bitmap all_blocks
)
1884 unsigned int bb_index
;
1887 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1889 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1891 bitmap_copy (bb_info
->out
, bb_info
->gen
);
1892 bitmap_clear (bb_info
->in
);
1897 /* Or in the stack regs, hard regs and early clobber regs into the the
1898 ur_in sets of all of the blocks. */
1901 df_ur_local_finalize (struct dataflow
*dflow
, bitmap all_blocks
)
1903 struct df
*df
= dflow
->df
;
1904 struct dataflow
*lr_dflow
= df
->problems_by_index
[DF_LR
];
1905 bitmap tmp
= BITMAP_ALLOC (NULL
);
1907 unsigned int bb_index
;
1909 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1911 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1912 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (lr_dflow
, bb_index
);
1914 /* No register may reach a location where it is not used. Thus
1915 we trim the rr result to the places where it is used. */
1916 bitmap_and_into (bb_info
->in
, bb_lr_info
->in
);
1917 bitmap_and_into (bb_info
->out
, bb_lr_info
->out
);
1920 /* Hard registers may still stick in the ur_out set, but not
1921 be in the ur_in set, if their only mention was in a call
1922 in this block. This is because a call kills in the lr
1923 problem but does not kill in the ur problem. To clean
1924 this up, we execute the transfer function on the lr_in
1925 set and then use that to knock bits out of ur_out. */
1926 bitmap_ior_and_compl (tmp
, bb_info
->gen
, bb_lr_info
->in
,
1928 bitmap_and_into (bb_info
->out
, tmp
);
1936 /* Confluence function that ignores fake edges. */
1939 df_ur_confluence_n (struct dataflow
*dflow
, edge e
)
1941 bitmap op1
= df_ur_get_bb_info (dflow
, e
->dest
->index
)->in
;
1942 bitmap op2
= df_ur_get_bb_info (dflow
, e
->src
->index
)->out
;
1944 if (e
->flags
& EDGE_FAKE
)
1947 bitmap_ior_into (op1
, op2
);
1951 /* Transfer function. */
1954 df_ur_transfer_function (struct dataflow
*dflow
, int bb_index
)
1956 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1957 bitmap in
= bb_info
->in
;
1958 bitmap out
= bb_info
->out
;
1959 bitmap gen
= bb_info
->gen
;
1960 bitmap kill
= bb_info
->kill
;
1962 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
1966 /* Free all storage associated with the problem. */
1969 df_ur_free (struct dataflow
*dflow
)
1971 if (dflow
->block_info
)
1975 for (i
= 0; i
< dflow
->block_info_size
; i
++)
1977 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, i
);
1980 BITMAP_FREE (bb_info
->gen
);
1981 BITMAP_FREE (bb_info
->kill
);
1982 BITMAP_FREE (bb_info
->in
);
1983 BITMAP_FREE (bb_info
->out
);
1987 free_alloc_pool (dflow
->block_pool
);
1988 dflow
->block_info_size
= 0;
1989 free (dflow
->block_info
);
1995 /* Debugging info. */
1998 df_ur_dump (struct dataflow
*dflow
, FILE *file
)
2002 fprintf (file
, "Undefined regs:\n");
2006 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb
->index
);
2007 df_print_bb_index (bb
, file
);
2012 fprintf (file
, " in \t");
2013 dump_bitmap (file
, bb_info
->in
);
2014 fprintf (file
, " gen \t");
2015 dump_bitmap (file
, bb_info
->gen
);
2016 fprintf (file
, " kill\t");
2017 dump_bitmap (file
, bb_info
->kill
);
2018 fprintf (file
, " out \t");
2019 dump_bitmap (file
, bb_info
->out
);
2023 /* All of the information associated with every instance of the problem. */
2025 static struct df_problem problem_UR
=
2027 DF_UR
, /* Problem id. */
2028 DF_FORWARD
, /* Direction. */
2029 df_ur_alloc
, /* Allocate the problem specific data. */
2030 NULL
, /* Reset global information. */
2031 df_ur_free_bb_info
, /* Free basic block info. */
2032 df_ur_local_compute
, /* Local compute function. */
2033 df_ur_init
, /* Init the solution specific data. */
2034 df_iterative_dataflow
, /* Iterative solver. */
2035 NULL
, /* Confluence operator 0. */
2036 df_ur_confluence_n
, /* Confluence operator n. */
2037 df_ur_transfer_function
, /* Transfer function. */
2038 df_ur_local_finalize
, /* Finalize function. */
2039 df_ur_free
, /* Free all of the problem information. */
2040 df_ur_dump
, /* Debugging. */
2041 &problem_LR
/* Dependent problem. */
2045 /* Create a new DATAFLOW instance and add it to an existing instance
2046 of DF. The returned structure is what is used to get at the
2050 df_ur_add_problem (struct df
*df
)
2052 return df_add_problem (df
, &problem_UR
);
2057 /*----------------------------------------------------------------------------
2058 UNINITIALIZED REGISTERS WITH EARLYCLOBBER
2060 Find the set of uses for registers that are reachable from the entry
2061 block without passing thru a definition.
2063 This is a variant of the UR problem above that has a lot of special
2064 features just for the register allocation phase.
2065 ----------------------------------------------------------------------------*/
2067 struct df_urec_problem_data
2069 bool earlyclobbers_found
; /* True if any instruction contains an
2072 bitmap stack_regs
; /* Registers that may be allocated to a STACK_REGS. */
2077 /* Get basic block info. */
2079 struct df_urec_bb_info
*
2080 df_urec_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
2082 return (struct df_urec_bb_info
*) dflow
->block_info
[index
];
2086 /* Set basic block info. */
2089 df_urec_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
2090 struct df_urec_bb_info
*bb_info
)
2092 dflow
->block_info
[index
] = bb_info
;
2096 /* Free basic block info. */
2099 df_urec_free_bb_info (struct dataflow
*dflow
,
2100 basic_block bb ATTRIBUTE_UNUSED
,
2103 struct df_urec_bb_info
*bb_info
= (struct df_urec_bb_info
*) vbb_info
;
2106 BITMAP_FREE (bb_info
->gen
);
2107 BITMAP_FREE (bb_info
->kill
);
2108 BITMAP_FREE (bb_info
->in
);
2109 BITMAP_FREE (bb_info
->out
);
2110 BITMAP_FREE (bb_info
->earlyclobber
);
2111 pool_free (dflow
->block_pool
, bb_info
);
2116 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
2117 not touched unless the block is new. */
2120 df_urec_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
2122 unsigned int bb_index
;
2124 struct df_urec_problem_data
*problem_data
=
2125 (struct df_urec_problem_data
*) dflow
->problem_data
;
2127 if (! dflow
->block_pool
)
2128 dflow
->block_pool
= create_alloc_pool ("df_urec_block pool",
2129 sizeof (struct df_urec_bb_info
), 50);
2131 if (!dflow
->problem_data
)
2133 problem_data
= xmalloc (sizeof (struct df_urec_problem_data
));
2134 dflow
->problem_data
= problem_data
;
2136 problem_data
->earlyclobbers_found
= false;
2138 df_grow_bb_info (dflow
);
2140 /* Because of the clustering of all def sites for the same pseudo,
2141 we have to process all of the blocks before doing the
2144 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
2146 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2149 bitmap_clear (bb_info
->kill
);
2150 bitmap_clear (bb_info
->gen
);
2151 bitmap_clear (bb_info
->earlyclobber
);
2155 bb_info
= (struct df_urec_bb_info
*) pool_alloc (dflow
->block_pool
);
2156 df_urec_set_bb_info (dflow
, bb_index
, bb_info
);
2157 bb_info
->kill
= BITMAP_ALLOC (NULL
);
2158 bb_info
->gen
= BITMAP_ALLOC (NULL
);
2159 bb_info
->in
= BITMAP_ALLOC (NULL
);
2160 bb_info
->out
= BITMAP_ALLOC (NULL
);
2161 bb_info
->earlyclobber
= BITMAP_ALLOC (NULL
);
2167 /* The function modifies local info for register REG being changed in
2168 SETTER. DATA is used to pass the current basic block info. */
2171 df_urec_mark_reg_change (rtx reg
, rtx setter
, void *data
)
2176 struct df_urec_bb_info
*bb_info
= (struct df_urec_bb_info
*) data
;
2178 if (GET_CODE (reg
) == SUBREG
)
2179 reg
= SUBREG_REG (reg
);
2185 endregno
= regno
= REGNO (reg
);
2186 if (regno
< FIRST_PSEUDO_REGISTER
)
2188 endregno
+=hard_regno_nregs
[regno
][GET_MODE (reg
)];
2190 for (i
= regno
; i
< endregno
; i
++)
2192 bitmap_set_bit (bb_info
->kill
, i
);
2194 if (GET_CODE (setter
) != CLOBBER
)
2195 bitmap_set_bit (bb_info
->gen
, i
);
2197 bitmap_clear_bit (bb_info
->gen
, i
);
2202 bitmap_set_bit (bb_info
->kill
, regno
);
2204 if (GET_CODE (setter
) != CLOBBER
)
2205 bitmap_set_bit (bb_info
->gen
, regno
);
2207 bitmap_clear_bit (bb_info
->gen
, regno
);
2210 /* Classes of registers which could be early clobbered in the current
2214 DEF_VEC_ALLOC_I(int,heap
);
2216 static VEC(int,heap
) *earlyclobber_regclass
;
2218 /* This function finds and stores register classes that could be early
2219 clobbered in INSN. If any earlyclobber classes are found, the function
2220 returns TRUE, in all other cases it returns FALSE. */
2223 df_urec_check_earlyclobber (rtx insn
)
2228 extract_insn (insn
);
2230 VEC_truncate (int, earlyclobber_regclass
, 0);
2231 for (opno
= 0; opno
< recog_data
.n_operands
; opno
++)
2236 enum reg_class
class;
2237 const char *p
= recog_data
.constraints
[opno
];
2246 case '=': case '+': case '?':
2249 case 'm': case '<': case '>': case 'V': case 'o':
2250 case 'E': case 'F': case 'G': case 'H':
2251 case 's': case 'i': case 'n':
2252 case 'I': case 'J': case 'K': case 'L':
2253 case 'M': case 'N': case 'O': case 'P':
2255 case '0': case '1': case '2': case '3': case '4':
2256 case '5': case '6': case '7': case '8': case '9':
2257 /* These don't say anything we care about. */
2265 if (amp_p
&& class != NO_REGS
)
2271 VEC_iterate (int, earlyclobber_regclass
, i
, rc
);
2274 if (rc
== (int) class)
2278 /* We use VEC_quick_push here because
2279 earlyclobber_regclass holds no more than
2280 N_REG_CLASSES elements. */
2281 VEC_quick_push (int, earlyclobber_regclass
, (int) class);
2291 class = GENERAL_REGS
;
2295 class = REG_CLASS_FROM_CONSTRAINT (c
, p
);
2300 p
+= CONSTRAINT_LEN (c
, p
);
2307 /* The function checks that pseudo-register *X has a class
2308 intersecting with the class of pseudo-register could be early
2309 clobbered in the same insn.
2311 This function is a no-op if earlyclobber_regclass is empty.
2313 Reload can assign the same hard register to uninitialized
2314 pseudo-register and early clobbered pseudo-register in an insn if
2315 the pseudo-register is used first time in given BB and not lived at
2316 the BB start. To prevent this we don't change life information for
2317 such pseudo-registers. */
2320 df_urec_mark_reg_use_for_earlyclobber (rtx
*x
, void *data
)
2322 enum reg_class pref_class
, alt_class
;
2324 struct df_urec_bb_info
*bb_info
= (struct df_urec_bb_info
*) data
;
2326 if (REG_P (*x
) && REGNO (*x
) >= FIRST_PSEUDO_REGISTER
)
2331 if (bitmap_bit_p (bb_info
->kill
, regno
)
2332 || bitmap_bit_p (bb_info
->gen
, regno
))
2334 pref_class
= reg_preferred_class (regno
);
2335 alt_class
= reg_alternate_class (regno
);
2336 for (i
= 0; VEC_iterate (int, earlyclobber_regclass
, i
, rc
); i
++)
2338 if (reg_classes_intersect_p (rc
, pref_class
)
2340 && reg_classes_intersect_p (rc
, alt_class
)))
2342 bitmap_set_bit (bb_info
->earlyclobber
, regno
);
2350 /* The function processes all pseudo-registers in *X with the aid of
2351 previous function. */
2354 df_urec_mark_reg_use_for_earlyclobber_1 (rtx
*x
, void *data
)
2356 for_each_rtx (x
, df_urec_mark_reg_use_for_earlyclobber
, data
);
2360 /* Compute local uninitialized register info for basic block BB. */
2363 df_urec_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
2365 struct df
*df
= dflow
->df
;
2366 basic_block bb
= BASIC_BLOCK (bb_index
);
2367 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2371 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
2372 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
2374 unsigned int regno
= DF_REF_REGNO (def
);
2375 bitmap_set_bit (bb_info
->gen
, regno
);
2378 FOR_BB_INSNS (bb
, insn
)
2382 note_stores (PATTERN (insn
), df_urec_mark_reg_change
, bb_info
);
2383 if (df_state
& (DF_SCAN_GLOBAL
| DF_SCAN_POST_ALLOC
)
2384 && df_urec_check_earlyclobber (insn
))
2386 struct df_urec_problem_data
*problem_data
=
2387 (struct df_urec_problem_data
*) dflow
->problem_data
;
2388 problem_data
->earlyclobbers_found
= true;
2389 note_uses (&PATTERN (insn
),
2390 df_urec_mark_reg_use_for_earlyclobber_1
, bb_info
);
2395 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
2396 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
2398 unsigned int regno
= DF_REF_REGNO (def
);
2399 bitmap_set_bit (bb_info
->gen
, regno
);
2405 /* Compute local uninitialized register info. */
2408 df_urec_local_compute (struct dataflow
*dflow
,
2409 bitmap all_blocks ATTRIBUTE_UNUSED
,
2410 bitmap rescan_blocks
)
2412 unsigned int bb_index
;
2416 HARD_REG_SET zero
, stack_hard_regs
, used
;
2417 struct df_urec_problem_data
*problem_data
=
2418 (struct df_urec_problem_data
*) dflow
->problem_data
;
2420 /* Any register that MAY be allocated to a register stack (like the
2421 387) is treated poorly. Each such register is marked as being
2422 live everywhere. This keeps the register allocator and the
2423 subsequent passes from doing anything useful with these values.
2425 FIXME: This seems like an incredibly poor idea. */
2427 CLEAR_HARD_REG_SET (zero
);
2428 CLEAR_HARD_REG_SET (stack_hard_regs
);
2429 for (i
= FIRST_STACK_REG
; i
<= LAST_STACK_REG
; i
++)
2430 SET_HARD_REG_BIT (stack_hard_regs
, i
);
2431 problem_data
->stack_regs
= BITMAP_ALLOC (NULL
);
2432 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
2434 COPY_HARD_REG_SET (used
, reg_class_contents
[reg_preferred_class (i
)]);
2435 IOR_HARD_REG_SET (used
, reg_class_contents
[reg_alternate_class (i
)]);
2436 AND_HARD_REG_SET (used
, stack_hard_regs
);
2437 GO_IF_HARD_REG_EQUAL (used
, zero
, skip
);
2438 bitmap_set_bit (problem_data
->stack_regs
, i
);
2444 /* We know that earlyclobber_regclass holds no more than
2445 N_REG_CLASSES elements. See df_urec_check_earlyclobber. */
2446 earlyclobber_regclass
= VEC_alloc (int, heap
, N_REG_CLASSES
);
2448 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks
, 0, bb_index
, bi
)
2450 df_urec_bb_local_compute (dflow
, bb_index
);
2453 VEC_free (int, heap
, earlyclobber_regclass
);
2457 /* Initialize the solution vectors. */
2460 df_urec_init (struct dataflow
*dflow
, bitmap all_blocks
)
2462 unsigned int bb_index
;
2465 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2467 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2469 bitmap_copy (bb_info
->out
, bb_info
->gen
);
2470 bitmap_clear (bb_info
->in
);
2475 /* Or in the stack regs, hard regs and early clobber regs into the the
2476 ur_in sets of all of the blocks. */
2479 df_urec_local_finalize (struct dataflow
*dflow
, bitmap all_blocks
)
2481 struct df
*df
= dflow
->df
;
2482 struct dataflow
*lr_dflow
= df
->problems_by_index
[DF_LR
];
2483 bitmap tmp
= BITMAP_ALLOC (NULL
);
2485 unsigned int bb_index
;
2486 struct df_urec_problem_data
*problem_data
=
2487 (struct df_urec_problem_data
*) dflow
->problem_data
;
2489 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2491 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2492 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (lr_dflow
, bb_index
);
2494 if (bb_index
!= ENTRY_BLOCK
&& bb_index
!= EXIT_BLOCK
)
2496 if (problem_data
->earlyclobbers_found
)
2497 bitmap_ior_into (bb_info
->in
, bb_info
->earlyclobber
);
2500 /* We can not use the same stack register for uninitialized
2501 pseudo-register and another living pseudo-register
2502 because if the uninitialized pseudo-register dies,
2503 subsequent pass reg-stack will be confused (it will
2504 believe that the other register dies). */
2505 bitmap_ior_into (bb_info
->in
, problem_data
->stack_regs
);
2506 bitmap_ior_into (bb_info
->out
, problem_data
->stack_regs
);
2510 /* No register may reach a location where it is not used. Thus
2511 we trim the rr result to the places where it is used. */
2512 bitmap_and_into (bb_info
->in
, bb_lr_info
->in
);
2513 bitmap_and_into (bb_info
->out
, bb_lr_info
->out
);
2516 /* Hard registers may still stick in the ur_out set, but not
2517 be in the ur_in set, if their only mention was in a call
2518 in this block. This is because a call kills in the lr
2519 problem but does not kill in the rr problem. To clean
2520 this up, we execute the transfer function on the lr_in
2521 set and then use that to knock bits out of ur_out. */
2522 bitmap_ior_and_compl (tmp
, bb_info
->gen
, bb_lr_info
->in
,
2524 bitmap_and_into (bb_info
->out
, tmp
);
2529 BITMAP_FREE (problem_data
->stack_regs
);
2535 /* Confluence function that ignores fake edges. */
2538 df_urec_confluence_n (struct dataflow
*dflow
, edge e
)
2540 bitmap op1
= df_urec_get_bb_info (dflow
, e
->dest
->index
)->in
;
2541 bitmap op2
= df_urec_get_bb_info (dflow
, e
->src
->index
)->out
;
2543 if (e
->flags
& EDGE_FAKE
)
2546 bitmap_ior_into (op1
, op2
);
2550 /* Transfer function. */
2553 df_urec_transfer_function (struct dataflow
*dflow
, int bb_index
)
2555 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2556 bitmap in
= bb_info
->in
;
2557 bitmap out
= bb_info
->out
;
2558 bitmap gen
= bb_info
->gen
;
2559 bitmap kill
= bb_info
->kill
;
2561 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
2565 /* Free all storage associated with the problem. */
2568 df_urec_free (struct dataflow
*dflow
)
2570 if (dflow
->block_info
)
2574 for (i
= 0; i
< dflow
->block_info_size
; i
++)
2576 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, i
);
2579 BITMAP_FREE (bb_info
->gen
);
2580 BITMAP_FREE (bb_info
->kill
);
2581 BITMAP_FREE (bb_info
->in
);
2582 BITMAP_FREE (bb_info
->out
);
2583 BITMAP_FREE (bb_info
->earlyclobber
);
2587 free_alloc_pool (dflow
->block_pool
);
2589 dflow
->block_info_size
= 0;
2590 free (dflow
->block_info
);
2591 free (dflow
->problem_data
);
2597 /* Debugging info. */
2600 df_urec_dump (struct dataflow
*dflow
, FILE *file
)
2604 fprintf (file
, "Undefined regs:\n");
2608 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb
->index
);
2609 df_print_bb_index (bb
, file
);
2614 fprintf (file
, " in \t");
2615 dump_bitmap (file
, bb_info
->in
);
2616 fprintf (file
, " gen \t");
2617 dump_bitmap (file
, bb_info
->gen
);
2618 fprintf (file
, " kill\t");
2619 dump_bitmap (file
, bb_info
->kill
);
2620 fprintf (file
, " ec\t");
2621 dump_bitmap (file
, bb_info
->earlyclobber
);
2622 fprintf (file
, " out \t");
2623 dump_bitmap (file
, bb_info
->out
);
2627 /* All of the information associated with every instance of the problem. */
2629 static struct df_problem problem_UREC
=
2631 DF_UREC
, /* Problem id. */
2632 DF_FORWARD
, /* Direction. */
2633 df_urec_alloc
, /* Allocate the problem specific data. */
2634 NULL
, /* Reset global information. */
2635 df_urec_free_bb_info
, /* Free basic block info. */
2636 df_urec_local_compute
, /* Local compute function. */
2637 df_urec_init
, /* Init the solution specific data. */
2638 df_iterative_dataflow
, /* Iterative solver. */
2639 NULL
, /* Confluence operator 0. */
2640 df_urec_confluence_n
, /* Confluence operator n. */
2641 df_urec_transfer_function
, /* Transfer function. */
2642 df_urec_local_finalize
, /* Finalize function. */
2643 df_urec_free
, /* Free all of the problem information. */
2644 df_urec_dump
, /* Debugging. */
2645 &problem_LR
/* Dependent problem. */
2649 /* Create a new DATAFLOW instance and add it to an existing instance
2650 of DF. The returned structure is what is used to get at the
2654 df_urec_add_problem (struct df
*df
)
2656 return df_add_problem (df
, &problem_UREC
);
2661 /*----------------------------------------------------------------------------
2662 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
2664 Link either the defs to the uses and / or the uses to the defs.
2666 These problems are set up like the other dataflow problems so that
2667 they nicely fit into the framework. They are much simpler and only
2668 involve a single traversal of instructions and an examination of
2669 the reaching defs information (the dependent problem).
2670 ----------------------------------------------------------------------------*/
2672 struct df_chain_problem_data
2678 /* Create def-use or use-def chains. */
2681 df_chain_alloc (struct dataflow
*dflow
,
2682 bitmap blocks_to_rescan ATTRIBUTE_UNUSED
)
2684 struct df
*df
= dflow
->df
;
2686 struct df_chain_problem_data
*problem_data
=
2687 (struct df_chain_problem_data
*) dflow
->problem_data
;
2689 /* Wholesale destruction of the old chains. */
2690 if (dflow
->block_pool
)
2691 free_alloc_pool (dflow
->block_pool
);
2693 dflow
->block_pool
= create_alloc_pool ("df_chain_chain_block pool",
2694 sizeof (struct df_link
), 100);
2696 if (problem_data
->flags
& DF_DU_CHAIN
)
2698 if (!df
->def_info
.refs_organized
)
2699 df_reorganize_refs (&df
->def_info
);
2701 /* Clear out the pointers from the refs. */
2702 for (i
= 0; i
< DF_DEFS_SIZE (df
); i
++)
2704 struct df_ref
*ref
= df
->def_info
.refs
[i
];
2705 DF_REF_CHAIN (ref
) = NULL
;
2709 if (problem_data
->flags
& DF_UD_CHAIN
)
2711 if (!df
->use_info
.refs_organized
)
2712 df_reorganize_refs (&df
->use_info
);
2713 for (i
= 0; i
< DF_USES_SIZE (df
); i
++)
2715 struct df_ref
*ref
= df
->use_info
.refs
[i
];
2716 DF_REF_CHAIN (ref
) = NULL
;
2722 /* Reset all def_use and use_def chains in INSN. */
2725 df_chain_insn_reset (struct dataflow
*dflow
, rtx insn
)
2727 struct df
*df
= dflow
->df
;
2728 struct df_chain_problem_data
*problem_data
=
2729 (struct df_chain_problem_data
*) dflow
->problem_data
;
2730 unsigned int uid
= INSN_UID (insn
);
2731 struct df_insn_info
*insn_info
= NULL
;
2734 if (uid
< df
->insns_size
)
2735 insn_info
= DF_INSN_UID_GET (df
, uid
);
2739 if (problem_data
->flags
& DF_DU_CHAIN
)
2741 ref
= insn_info
->defs
;
2745 ref
= ref
->next_ref
;
2749 if (problem_data
->flags
& DF_UD_CHAIN
)
2751 ref
= insn_info
->uses
;
2755 ref
= ref
->next_ref
;
2762 /* Reset all def_use and use_def chains in basic block. */
2765 df_chain_bb_reset (struct dataflow
*dflow
, unsigned int bb_index
)
2767 struct df
*df
= dflow
->df
;
2768 struct df_chain_problem_data
*problem_data
=
2769 (struct df_chain_problem_data
*) dflow
->problem_data
;
2771 basic_block bb
= BASIC_BLOCK (bb_index
);
2773 /* Some one deleted the basic block out from under us. */
2777 FOR_BB_INSNS (bb
, insn
)
2781 /* Record defs within INSN. */
2782 df_chain_insn_reset (dflow
, insn
);
2786 /* Get rid of any chains in artifical uses or defs. */
2787 if (problem_data
->flags
& DF_DU_CHAIN
)
2790 def
= df_get_artificial_defs (df
, bb_index
);
2794 def
= def
->next_ref
;
2798 if (problem_data
->flags
& DF_UD_CHAIN
)
2801 use
= df_get_artificial_uses (df
, bb_index
);
2805 use
= use
->next_ref
;
2811 /* Reset all of the chains when the set of basic blocks changes. */
2815 df_chain_reset (struct dataflow
*dflow
, bitmap blocks_to_clear
)
2818 unsigned int bb_index
;
2820 EXECUTE_IF_SET_IN_BITMAP (blocks_to_clear
, 0, bb_index
, bi
)
2822 df_chain_bb_reset (dflow
, bb_index
);
2825 free_alloc_pool (dflow
->block_pool
);
2826 dflow
->block_pool
= NULL
;
2830 /* Create the chains for a list of USEs. */
2833 df_chain_create_bb_process_use (struct dataflow
*dflow
,
2834 struct df_chain_problem_data
*problem_data
,
2837 enum df_ref_flags top_flag
)
2839 struct df
*df
= dflow
->df
;
2841 unsigned int def_index
;
2845 /* Do not want to go through this for an uninitialized var. */
2846 unsigned int uregno
= DF_REF_REGNO (use
);
2847 int count
= DF_REG_DEF_GET (df
, uregno
)->n_refs
;
2850 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2852 unsigned int first_index
= DF_REG_DEF_GET (df
, uregno
)->begin
;
2853 unsigned int last_index
= first_index
+ count
- 1;
2855 EXECUTE_IF_SET_IN_BITMAP (local_rd
, first_index
, def_index
, bi
)
2858 if (def_index
> last_index
)
2861 def
= DF_DEFS_GET (df
, def_index
);
2862 if (problem_data
->flags
& DF_DU_CHAIN
)
2863 df_chain_create (dflow
, def
, use
);
2864 if (problem_data
->flags
& DF_UD_CHAIN
)
2865 df_chain_create (dflow
, use
, def
);
2869 use
= use
->next_ref
;
2873 /* Reset the storage pool that the def-use or use-def chains have been
2874 allocated in. We do not need to re adjust the pointers in the refs,
2875 these have already been clean out.*/
2877 /* Create chains from reaching defs bitmaps for basic block BB. */
2879 df_chain_create_bb (struct dataflow
*dflow
,
2880 struct dataflow
*rd_dflow
,
2881 unsigned int bb_index
)
2883 basic_block bb
= BASIC_BLOCK (bb_index
);
2884 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (rd_dflow
, bb_index
);
2886 bitmap cpy
= BITMAP_ALLOC (NULL
);
2887 struct df
*df
= dflow
->df
;
2888 struct df_chain_problem_data
*problem_data
=
2889 (struct df_chain_problem_data
*) dflow
->problem_data
;
2892 bitmap_copy (cpy
, bb_info
->in
);
2894 /* Since we are going forwards, process the artificial uses first
2895 then the artificial defs second. */
2898 /* Create the chains for the artificial uses from the EH_USES at the
2899 beginning of the block. */
2900 df_chain_create_bb_process_use (dflow
, problem_data
, cpy
,
2901 df_get_artificial_uses (df
, bb
->index
),
2905 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
2906 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
2908 unsigned int dregno
= DF_REF_REGNO (def
);
2909 bitmap_clear_range (cpy
,
2910 DF_REG_DEF_GET (df
, dregno
)->begin
,
2911 DF_REG_DEF_GET (df
, dregno
)->n_refs
);
2912 if (! (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
))
2913 bitmap_set_bit (cpy
, DF_REF_ID (def
));
2916 /* Process the regular instructions next. */
2917 FOR_BB_INSNS (bb
, insn
)
2920 unsigned int uid
= INSN_UID (insn
);
2922 if (! INSN_P (insn
))
2925 /* Now scan the uses and link them up with the defs that remain
2926 in the cpy vector. */
2928 df_chain_create_bb_process_use (dflow
, problem_data
, cpy
,
2929 DF_INSN_UID_GET (df
, uid
)->uses
, 0);
2931 /* Since we are going forwards, process the defs second. This
2932 pass only changes the bits in cpy. */
2933 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
2935 unsigned int dregno
= DF_REF_REGNO (def
);
2936 bitmap_clear_range (cpy
,
2937 DF_REG_DEF_GET (df
, dregno
)->begin
,
2938 DF_REG_DEF_GET (df
, dregno
)->n_refs
);
2939 if (! (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
))
2940 bitmap_set_bit (cpy
, DF_REF_ID (def
));
2944 /* Create the chains for the artificial uses of the hard registers
2945 at the end of the block. */
2946 df_chain_create_bb_process_use (dflow
, problem_data
, cpy
,
2947 df_get_artificial_uses (df
, bb
->index
), 0);
2950 /* Create def-use chains from reaching use bitmaps for basic blocks
2954 df_chain_finalize (struct dataflow
*dflow
, bitmap all_blocks
)
2956 unsigned int bb_index
;
2958 struct df
*df
= dflow
->df
;
2959 struct dataflow
*rd_dflow
= df
->problems_by_index
[DF_RD
];
2961 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2963 df_chain_create_bb (dflow
, rd_dflow
, bb_index
);
2968 /* Free all storage associated with the problem. */
2971 df_chain_free (struct dataflow
*dflow
)
2973 free_alloc_pool (dflow
->block_pool
);
2974 free (dflow
->problem_data
);
2979 /* Debugging info. */
2982 df_chains_dump (struct dataflow
*dflow
, FILE *file
)
2984 struct df
*df
= dflow
->df
;
2986 struct df_chain_problem_data
*problem_data
=
2987 (struct df_chain_problem_data
*) dflow
->problem_data
;
2989 if (problem_data
->flags
& DF_DU_CHAIN
)
2991 fprintf (file
, "Def-use chains:\n");
2992 for (j
= 0; j
< df
->def_info
.bitmap_size
; j
++)
2994 struct df_ref
*def
= DF_DEFS_GET (df
, j
);
2997 fprintf (file
, "d%d bb %d luid %d insn %d reg %d ",
2998 j
, DF_REF_BBNO (def
),
2999 DF_INSN_LUID (df
, DF_REF_INSN (def
)),
3000 DF_REF_INSN (def
) ? DF_REF_INSN_UID (def
) : -1,
3001 DF_REF_REGNO (def
));
3002 if (def
->flags
& DF_REF_READ_WRITE
)
3003 fprintf (file
, "read/write ");
3004 df_chain_dump (df
, DF_REF_CHAIN (def
), file
);
3005 fprintf (file
, "\n");
3010 if (problem_data
->flags
& DF_UD_CHAIN
)
3012 fprintf (file
, "Use-def chains:\n");
3013 for (j
= 0; j
< df
->use_info
.bitmap_size
; j
++)
3015 struct df_ref
*use
= DF_USES_GET (df
, j
);
3018 fprintf (file
, "u%d bb %d luid %d insn %d reg %d ",
3019 j
, DF_REF_BBNO (use
),
3021 DF_INSN_LUID (df
, DF_REF_INSN (use
))
3023 DF_REF_INSN (DF_USES_GET (df
, j
)) ?
3024 DF_REF_INSN_UID (DF_USES_GET (df
,j
))
3026 DF_REF_REGNO (use
));
3027 if (use
->flags
& DF_REF_READ_WRITE
)
3028 fprintf (file
, "read/write ");
3029 if (use
->flags
& DF_REF_STRIPPED
)
3030 fprintf (file
, "stripped ");
3031 if (use
->flags
& DF_REF_IN_NOTE
)
3032 fprintf (file
, "note ");
3033 df_chain_dump (df
, DF_REF_CHAIN (use
), file
);
3034 fprintf (file
, "\n");
3041 static struct df_problem problem_CHAIN
=
3043 DF_CHAIN
, /* Problem id. */
3044 DF_NONE
, /* Direction. */
3045 df_chain_alloc
, /* Allocate the problem specific data. */
3046 df_chain_reset
, /* Reset global information. */
3047 NULL
, /* Free basic block info. */
3048 NULL
, /* Local compute function. */
3049 NULL
, /* Init the solution specific data. */
3050 NULL
, /* Iterative solver. */
3051 NULL
, /* Confluence operator 0. */
3052 NULL
, /* Confluence operator n. */
3053 NULL
, /* Transfer function. */
3054 df_chain_finalize
, /* Finalize function. */
3055 df_chain_free
, /* Free all of the problem information. */
3056 df_chains_dump
, /* Debugging. */
3057 &problem_RD
/* Dependent problem. */
3061 /* Create a new DATAFLOW instance and add it to an existing instance
3062 of DF. The returned structure is what is used to get at the
3066 df_chain_add_problem (struct df
*df
, int flags
)
3068 struct df_chain_problem_data
*problem_data
=
3069 xmalloc (sizeof (struct df_chain_problem_data
));
3070 struct dataflow
*dflow
= df_add_problem (df
, &problem_CHAIN
);
3072 dflow
->problem_data
= problem_data
;
3073 problem_data
->flags
= flags
;
3079 /*----------------------------------------------------------------------------
3080 REGISTER INFORMATION
3082 Currently this consists of only lifetime information. But the plan is
3083 to enhance it so that it produces all of the register information needed
3084 by the register allocators.
3085 ----------------------------------------------------------------------------*/
3088 struct df_ri_problem_data
3094 /* Allocate the lifetime information. */
3097 df_ri_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan ATTRIBUTE_UNUSED
)
3099 struct df_ri_problem_data
*problem_data
=
3100 (struct df_ri_problem_data
*) dflow
->problem_data
;
3102 if (!dflow
->problem_data
)
3104 struct df_ri_problem_data
*problem_data
=
3105 xmalloc (sizeof (struct df_ri_problem_data
));
3106 dflow
->problem_data
= problem_data
;
3109 problem_data
->lifetime
= xrealloc (problem_data
->lifetime
,
3110 max_reg_num () *sizeof (int));
3111 memset (problem_data
->lifetime
, 0, max_reg_num () *sizeof (int));
3114 /* Compute register info: lifetime, bb, and number of defs and uses
3115 for basic block BB. */
3118 df_ri_bb_compute (struct dataflow
*dflow
, unsigned int bb_index
, bitmap live
)
3120 struct df
*df
= dflow
->df
;
3121 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
3122 struct df_ri_problem_data
*problem_data
=
3123 (struct df_ri_problem_data
*) dflow
->problem_data
;
3124 basic_block bb
= BASIC_BLOCK (bb_index
);
3127 bitmap_copy (live
, bb_info
->out
);
3129 FOR_BB_INSNS_REVERSE (bb
, insn
)
3131 unsigned int uid
= INSN_UID (insn
);
3137 if (! INSN_P (insn
))
3140 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
3142 unsigned int dregno
= DF_REF_REGNO (def
);
3144 /* Kill this register. */
3145 bitmap_clear_bit (live
, dregno
);
3148 for (use
= DF_INSN_UID_GET (df
, uid
)->uses
; use
; use
= use
->next_ref
)
3150 unsigned int uregno
= DF_REF_REGNO (use
);
3152 if (!bitmap_bit_p (live
, uregno
))
3154 use
->flags
|= DF_REF_DIES_AFTER_THIS_USE
;
3155 /* This register is now live. */
3156 bitmap_set_bit (live
, uregno
);
3159 use
->flags
&= ~DF_REF_DIES_AFTER_THIS_USE
;
3162 /* Increment lifetimes of all live registers. */
3163 EXECUTE_IF_SET_IN_BITMAP (live
, 0, regno
, bi
)
3165 problem_data
->lifetime
[regno
]++;
3171 /* Compute register info: lifetime, bb, and number of defs and uses. */
3173 df_ri_compute (struct dataflow
*dflow
, bitmap all_blocks ATTRIBUTE_UNUSED
,
3174 bitmap blocks_to_scan
)
3176 unsigned int bb_index
;
3180 live
= BITMAP_ALLOC (NULL
);
3182 EXECUTE_IF_SET_IN_BITMAP (blocks_to_scan
, 0, bb_index
, bi
)
3184 df_ri_bb_compute (dflow
, bb_index
, live
);
3191 /* Free all storage associated with the problem. */
3194 df_ri_free (struct dataflow
*dflow
)
3196 struct df_ri_problem_data
*problem_data
=
3197 (struct df_ri_problem_data
*) dflow
->problem_data
;
3199 free (problem_data
->lifetime
);
3200 free (dflow
->problem_data
);
3205 /* Debugging info. */
3208 df_ri_dump (struct dataflow
*dflow
, FILE *file
)
3210 struct df_ri_problem_data
*problem_data
=
3211 (struct df_ri_problem_data
*) dflow
->problem_data
;
3214 fprintf (file
, "Register info:\n");
3215 for (j
= 0; j
< max_reg_num (); j
++)
3217 fprintf (file
, "reg %d life %d\n", j
, problem_data
->lifetime
[j
]);
3221 /* All of the information associated every instance of the problem. */
3223 static struct df_problem problem_RI
=
3225 DF_RI
, /* Problem id. */
3226 DF_NONE
, /* Direction. */
3227 df_ri_alloc
, /* Allocate the problem specific data. */
3228 NULL
, /* Reset global information. */
3229 NULL
, /* Free basic block info. */
3230 df_ri_compute
, /* Local compute function. */
3231 NULL
, /* Init the solution specific data. */
3232 NULL
, /* Iterative solver. */
3233 NULL
, /* Confluence operator 0. */
3234 NULL
, /* Confluence operator n. */
3235 NULL
, /* Transfer function. */
3236 NULL
, /* Finalize function. */
3237 df_ri_free
, /* Free all of the problem information. */
3238 df_ri_dump
, /* Debugging. */
3239 &problem_UR
/* Dependent problem. */
3243 /* Create a new DATAFLOW instance and add it to an existing instance
3244 of DF. The returned structure is what is used to get at the
3248 df_ri_add_problem (struct df
*df
)
3250 return df_add_problem (df
, &problem_RI
);
3254 /* Return total lifetime (in insns) of REG. */
3256 df_reg_lifetime (struct df
*df
, rtx reg
)
3258 struct dataflow
*dflow
= df
->problems_by_index
[DF_RI
];
3259 struct df_ri_problem_data
*problem_data
=
3260 (struct df_ri_problem_data
*) dflow
->problem_data
;
3261 return problem_data
->lifetime
[REGNO (reg
)];