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
= XNEW (struct df_ru_problem_data
);
389 dflow
->problem_data
= problem_data
;
391 problem_data
->use_sites
= XCNEWVEC (bitmap
, reg_size
);
392 problem_data
->use_sites_size
= reg_size
;
393 problem_data
->sparse_invalidated_by_call
= BITMAP_ALLOC (NULL
);
394 problem_data
->dense_invalidated_by_call
= BITMAP_ALLOC (NULL
);
397 df_grow_bb_info (dflow
);
399 /* Because of the clustering of all def sites for the same pseudo,
400 we have to process all of the blocks before doing the
403 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
405 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
408 bitmap_clear (bb_info
->kill
);
409 bitmap_clear (bb_info
->sparse_kill
);
410 bitmap_clear (bb_info
->gen
);
414 bb_info
= (struct df_ru_bb_info
*) pool_alloc (dflow
->block_pool
);
415 df_ru_set_bb_info (dflow
, bb_index
, bb_info
);
416 bb_info
->kill
= BITMAP_ALLOC (NULL
);
417 bb_info
->sparse_kill
= BITMAP_ALLOC (NULL
);
418 bb_info
->gen
= BITMAP_ALLOC (NULL
);
419 bb_info
->in
= BITMAP_ALLOC (NULL
);
420 bb_info
->out
= BITMAP_ALLOC (NULL
);
426 /* Process a list of DEFs for df_ru_bb_local_compute. */
429 df_ru_bb_local_compute_process_def (struct dataflow
*dflow
,
430 struct df_ru_bb_info
*bb_info
,
432 enum df_ref_flags top_flag
)
434 struct df
*df
= dflow
->df
;
437 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
439 unsigned int regno
= DF_REF_REGNO (def
);
440 unsigned int begin
= DF_REG_USE_GET (df
, regno
)->begin
;
441 unsigned int n_uses
= DF_REG_USE_GET (df
, regno
)->n_refs
;
442 if (!bitmap_bit_p (seen_in_block
, regno
))
444 /* The first def for regno, causes the kill info to be
445 generated and the gen information to cleared. */
446 if (!bitmap_bit_p (seen_in_insn
, regno
))
448 if (n_uses
> DF_SPARSE_THRESHOLD
)
450 bitmap_set_bit (bb_info
->sparse_kill
, regno
);
451 bitmap_clear_range (bb_info
->gen
, begin
, n_uses
);
455 struct df_ru_problem_data
* problem_data
=
456 (struct df_ru_problem_data
*)dflow
->problem_data
;
458 df_ref_bitmap (problem_data
->use_sites
, regno
,
460 bitmap_ior_into (bb_info
->kill
, uses
);
461 bitmap_and_compl_into (bb_info
->gen
, uses
);
464 bitmap_set_bit (seen_in_insn
, regno
);
472 /* Process a list of USEs for df_ru_bb_local_compute. */
475 df_ru_bb_local_compute_process_use (struct df_ru_bb_info
*bb_info
,
477 enum df_ref_flags top_flag
)
481 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
483 /* Add use to set of gens in this BB unless we have seen a
484 def in a previous instruction. */
485 unsigned int regno
= DF_REF_REGNO (use
);
486 if (!bitmap_bit_p (seen_in_block
, regno
))
487 bitmap_set_bit (bb_info
->gen
, DF_REF_ID (use
));
493 /* Compute local reaching use (upward exposed use) info for basic
494 block BB. USE_INFO->REGS[R] caches the set of uses for register R. */
496 df_ru_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
498 struct df
*df
= dflow
->df
;
499 basic_block bb
= BASIC_BLOCK (bb_index
);
500 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
503 /* Set when a def for regno is seen. */
504 bitmap_clear (seen_in_block
);
505 bitmap_clear (seen_in_insn
);
508 /* Variables defined in the prolog that are used by the exception
510 df_ru_bb_local_compute_process_use (bb_info
,
511 df_get_artificial_uses (df
, bb_index
),
514 df_ru_bb_local_compute_process_def (dflow
, bb_info
,
515 df_get_artificial_defs (df
, bb_index
),
518 FOR_BB_INSNS (bb
, insn
)
520 unsigned int uid
= INSN_UID (insn
);
524 df_ru_bb_local_compute_process_def (dflow
, bb_info
,
525 DF_INSN_UID_GET (df
, uid
)->defs
, 0);
527 /* The use processing must happen after the defs processing even
528 though the uses logically happen first since the defs clear
529 the gen set. Otherwise, a use for regno occuring in the same
530 instruction as a def for regno would be cleared. */
531 df_ru_bb_local_compute_process_use (bb_info
,
532 DF_INSN_UID_GET (df
, uid
)->uses
, 0);
534 bitmap_ior_into (seen_in_block
, seen_in_insn
);
535 bitmap_clear (seen_in_insn
);
538 /* Process the hardware registers that are always live. */
539 df_ru_bb_local_compute_process_use (bb_info
,
540 df_get_artificial_uses (df
, bb_index
), 0);
542 df_ru_bb_local_compute_process_def (dflow
, bb_info
,
543 df_get_artificial_defs (df
, bb_index
), 0);
547 /* Compute local reaching use (upward exposed use) info for each basic
548 block within BLOCKS. */
550 df_ru_local_compute (struct dataflow
*dflow
,
552 bitmap rescan_blocks ATTRIBUTE_UNUSED
)
554 struct df
*df
= dflow
->df
;
555 unsigned int bb_index
;
558 struct df_ru_problem_data
*problem_data
=
559 (struct df_ru_problem_data
*) dflow
->problem_data
;
560 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
561 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
565 if (!df
->use_info
.refs_organized
)
566 df_reorganize_refs (&df
->use_info
);
568 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
570 df_ru_bb_local_compute (dflow
, bb_index
);
573 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
574 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call
, 0, regno
, bi
)
576 struct df_reg_info
*reg_info
= DF_REG_USE_GET (df
, regno
);
577 if (reg_info
->n_refs
> DF_SPARSE_THRESHOLD
)
578 bitmap_set_bit (sparse_invalidated
, regno
);
581 bitmap defs
= df_ref_bitmap (problem_data
->use_sites
, regno
,
582 reg_info
->begin
, reg_info
->n_refs
);
583 bitmap_ior_into (dense_invalidated
, defs
);
591 /* Initialize the solution bit vectors for problem. */
594 df_ru_init_solution (struct dataflow
*dflow
, bitmap all_blocks
)
596 unsigned int bb_index
;
599 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
601 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
602 bitmap_copy (bb_info
->in
, bb_info
->gen
);
603 bitmap_clear (bb_info
->out
);
608 /* Out of target gets or of in of source. */
611 df_ru_confluence_n (struct dataflow
*dflow
, edge e
)
613 bitmap op1
= df_ru_get_bb_info (dflow
, e
->src
->index
)->out
;
614 bitmap op2
= df_ru_get_bb_info (dflow
, e
->dest
->index
)->in
;
616 if (e
->flags
& EDGE_EH
)
618 struct df_ru_problem_data
*problem_data
=
619 (struct df_ru_problem_data
*) dflow
->problem_data
;
620 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
621 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
622 struct df
*df
= dflow
->df
;
625 bitmap tmp
= BITMAP_ALLOC (NULL
);
627 bitmap_copy (tmp
, op2
);
628 bitmap_and_compl_into (tmp
, dense_invalidated
);
630 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
632 bitmap_clear_range (tmp
,
633 DF_REG_USE_GET (df
, regno
)->begin
,
634 DF_REG_USE_GET (df
, regno
)->n_refs
);
636 bitmap_ior_into (op1
, tmp
);
640 bitmap_ior_into (op1
, op2
);
644 /* Transfer function. */
647 df_ru_transfer_function (struct dataflow
*dflow
, int bb_index
)
649 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb_index
);
652 bitmap in
= bb_info
->in
;
653 bitmap out
= bb_info
->out
;
654 bitmap gen
= bb_info
->gen
;
655 bitmap kill
= bb_info
->kill
;
656 bitmap sparse_kill
= bb_info
->sparse_kill
;
658 if (bitmap_empty_p (sparse_kill
))
659 return bitmap_ior_and_compl (in
, gen
, out
, kill
);
662 struct df
*df
= dflow
->df
;
663 bool changed
= false;
664 bitmap tmp
= BITMAP_ALLOC (NULL
);
665 bitmap_copy (tmp
, in
);
666 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
668 bitmap_clear_range (tmp
,
669 DF_REG_USE_GET (df
, regno
)->begin
,
670 DF_REG_USE_GET (df
, regno
)->n_refs
);
672 bitmap_and_compl_into (tmp
, kill
);
673 bitmap_ior_into (tmp
, gen
);
674 changed
= !bitmap_equal_p (tmp
, in
);
687 /* Free all storage associated with the problem. */
690 df_ru_free (struct dataflow
*dflow
)
693 struct df_ru_problem_data
*problem_data
=
694 (struct df_ru_problem_data
*) dflow
->problem_data
;
698 for (i
= 0; i
< dflow
->block_info_size
; i
++)
700 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, i
);
703 BITMAP_FREE (bb_info
->kill
);
704 BITMAP_FREE (bb_info
->sparse_kill
);
705 BITMAP_FREE (bb_info
->gen
);
706 BITMAP_FREE (bb_info
->in
);
707 BITMAP_FREE (bb_info
->out
);
711 free_alloc_pool (dflow
->block_pool
);
713 for (i
= 0; i
< problem_data
->use_sites_size
; i
++)
715 bitmap bm
= problem_data
->use_sites
[i
];
720 free (problem_data
->use_sites
);
721 BITMAP_FREE (problem_data
->sparse_invalidated_by_call
);
722 BITMAP_FREE (problem_data
->dense_invalidated_by_call
);
724 dflow
->block_info_size
= 0;
725 free (dflow
->block_info
);
726 free (dflow
->problem_data
);
732 /* Debugging info. */
735 df_ru_dump (struct dataflow
*dflow
, FILE *file
)
738 struct df
*df
= dflow
->df
;
739 struct df_ru_problem_data
*problem_data
=
740 (struct df_ru_problem_data
*) dflow
->problem_data
;
741 unsigned int m
= max_reg_num ();
744 fprintf (file
, "Reaching uses:\n");
746 fprintf (file
, " sparse invalidated \t");
747 dump_bitmap (file
, problem_data
->sparse_invalidated_by_call
);
748 fprintf (file
, " dense invalidated \t");
749 dump_bitmap (file
, problem_data
->dense_invalidated_by_call
);
751 for (regno
= 0; regno
< m
; regno
++)
752 if (DF_REG_USE_GET (df
, regno
)->n_refs
)
753 fprintf (file
, "%d[%d,%d] ", regno
,
754 DF_REG_USE_GET (df
, regno
)->begin
,
755 DF_REG_USE_GET (df
, regno
)->n_refs
);
756 fprintf (file
, "\n");
760 struct df_ru_bb_info
*bb_info
= df_ru_get_bb_info (dflow
, bb
->index
);
761 df_print_bb_index (bb
, file
);
766 fprintf (file
, " in \t");
767 dump_bitmap (file
, bb_info
->in
);
768 fprintf (file
, " gen \t");
769 dump_bitmap (file
, bb_info
->gen
);
770 fprintf (file
, " kill\t");
771 dump_bitmap (file
, bb_info
->kill
);
772 fprintf (file
, " out \t");
773 dump_bitmap (file
, bb_info
->out
);
777 /* All of the information associated with every instance of the problem. */
779 static struct df_problem problem_RU
=
781 DF_RU
, /* Problem id. */
782 DF_BACKWARD
, /* Direction. */
783 df_ru_alloc
, /* Allocate the problem specific data. */
784 NULL
, /* Reset global information. */
785 df_ru_free_bb_info
, /* Free basic block info. */
786 df_ru_local_compute
, /* Local compute function. */
787 df_ru_init_solution
, /* Init the solution specific data. */
788 df_iterative_dataflow
, /* Iterative solver. */
789 NULL
, /* Confluence operator 0. */
790 df_ru_confluence_n
, /* Confluence operator n. */
791 df_ru_transfer_function
, /* Transfer function. */
792 NULL
, /* Finalize function. */
793 df_ru_free
, /* Free all of the problem information. */
794 df_ru_dump
, /* Debugging. */
795 NULL
/* Dependent problem. */
800 /* Create a new DATAFLOW instance and add it to an existing instance
801 of DF. The returned structure is what is used to get at the
805 df_ru_add_problem (struct df
*df
)
807 return df_add_problem (df
, &problem_RU
);
811 /*----------------------------------------------------------------------------
814 Find the locations in the function where each definition site for a
816 ----------------------------------------------------------------------------*/
818 struct df_rd_problem_data
820 bitmap
*def_sites
; /* Bitmap of defs for each pseudo. */
821 unsigned int def_sites_size
; /* Size of def_sites. */
822 /* The set of defs to regs invalidated by call. */
823 bitmap sparse_invalidated_by_call
;
824 /* The set of defs to regs invalidate by call for ru. */
825 bitmap dense_invalidated_by_call
;
828 /* Get basic block info. */
830 struct df_rd_bb_info
*
831 df_rd_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
833 return (struct df_rd_bb_info
*) dflow
->block_info
[index
];
837 /* Set basic block info. */
840 df_rd_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
841 struct df_rd_bb_info
*bb_info
)
843 dflow
->block_info
[index
] = bb_info
;
847 /* Free basic block info. */
850 df_rd_free_bb_info (struct dataflow
*dflow
,
851 basic_block bb ATTRIBUTE_UNUSED
,
854 struct df_rd_bb_info
*bb_info
= (struct df_rd_bb_info
*) vbb_info
;
857 BITMAP_FREE (bb_info
->kill
);
858 BITMAP_FREE (bb_info
->sparse_kill
);
859 BITMAP_FREE (bb_info
->gen
);
860 BITMAP_FREE (bb_info
->in
);
861 BITMAP_FREE (bb_info
->out
);
862 pool_free (dflow
->block_pool
, bb_info
);
867 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
868 not touched unless the block is new. */
871 df_rd_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
873 unsigned int bb_index
;
875 unsigned int reg_size
= max_reg_num ();
877 if (! dflow
->block_pool
)
878 dflow
->block_pool
= create_alloc_pool ("df_rd_block pool",
879 sizeof (struct df_rd_bb_info
), 50);
881 if (dflow
->problem_data
)
884 struct df_rd_problem_data
*problem_data
=
885 (struct df_rd_problem_data
*) dflow
->problem_data
;
887 for (i
= 0; i
< problem_data
->def_sites_size
; i
++)
889 bitmap bm
= problem_data
->def_sites
[i
];
893 problem_data
->def_sites
[i
] = NULL
;
897 if (problem_data
->def_sites_size
< reg_size
)
899 problem_data
->def_sites
900 = xrealloc (problem_data
->def_sites
, reg_size
*sizeof (bitmap
));
901 memset (problem_data
->def_sites
+ problem_data
->def_sites_size
, 0,
902 (reg_size
- problem_data
->def_sites_size
) *sizeof (bitmap
));
903 problem_data
->def_sites_size
= reg_size
;
906 bitmap_clear (problem_data
->sparse_invalidated_by_call
);
907 bitmap_clear (problem_data
->dense_invalidated_by_call
);
911 struct df_rd_problem_data
*problem_data
= XNEW (struct df_rd_problem_data
);
912 dflow
->problem_data
= problem_data
;
914 problem_data
->def_sites
= XCNEWVEC (bitmap
, reg_size
);
915 problem_data
->def_sites_size
= reg_size
;
916 problem_data
->sparse_invalidated_by_call
= BITMAP_ALLOC (NULL
);
917 problem_data
->dense_invalidated_by_call
= BITMAP_ALLOC (NULL
);
920 df_grow_bb_info (dflow
);
922 /* Because of the clustering of all def sites for the same pseudo,
923 we have to process all of the blocks before doing the
926 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
928 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
931 bitmap_clear (bb_info
->kill
);
932 bitmap_clear (bb_info
->sparse_kill
);
933 bitmap_clear (bb_info
->gen
);
937 bb_info
= (struct df_rd_bb_info
*) pool_alloc (dflow
->block_pool
);
938 df_rd_set_bb_info (dflow
, bb_index
, bb_info
);
939 bb_info
->kill
= BITMAP_ALLOC (NULL
);
940 bb_info
->sparse_kill
= BITMAP_ALLOC (NULL
);
941 bb_info
->gen
= BITMAP_ALLOC (NULL
);
942 bb_info
->in
= BITMAP_ALLOC (NULL
);
943 bb_info
->out
= BITMAP_ALLOC (NULL
);
949 /* Process a list of DEFs for df_rd_bb_local_compute. */
952 df_rd_bb_local_compute_process_def (struct dataflow
*dflow
,
953 struct df_rd_bb_info
*bb_info
,
955 enum df_ref_flags top_flag
)
957 struct df
*df
= dflow
->df
;
960 if (top_flag
== (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
))
962 unsigned int regno
= DF_REF_REGNO (def
);
963 unsigned int begin
= DF_REG_DEF_GET (df
, regno
)->begin
;
964 unsigned int n_defs
= DF_REG_DEF_GET (df
, regno
)->n_refs
;
966 /* Only the last def(s) for a regno in the block has any
968 if (!bitmap_bit_p (seen_in_block
, regno
))
970 /* The first def for regno in insn gets to knock out the
971 defs from other instructions. */
972 if (!bitmap_bit_p (seen_in_insn
, regno
))
974 if (n_defs
> DF_SPARSE_THRESHOLD
)
976 bitmap_set_bit (bb_info
->sparse_kill
, regno
);
977 bitmap_clear_range(bb_info
->gen
, begin
, n_defs
);
981 struct df_rd_problem_data
* problem_data
=
982 (struct df_rd_problem_data
*)dflow
->problem_data
;
984 df_ref_bitmap (problem_data
->def_sites
, regno
,
986 bitmap_ior_into (bb_info
->kill
, defs
);
987 bitmap_and_compl_into (bb_info
->gen
, defs
);
991 bitmap_set_bit (seen_in_insn
, regno
);
992 /* All defs for regno in the instruction may be put into
994 if (! (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
))
995 bitmap_set_bit (bb_info
->gen
, DF_REF_ID (def
));
1002 /* Compute local reaching def info for basic block BB. */
1005 df_rd_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
1007 struct df
*df
= dflow
->df
;
1008 basic_block bb
= BASIC_BLOCK (bb_index
);
1009 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
1012 bitmap_clear (seen_in_block
);
1013 bitmap_clear (seen_in_insn
);
1015 df_rd_bb_local_compute_process_def (dflow
, bb_info
,
1016 df_get_artificial_defs (df
, bb_index
), 0);
1018 FOR_BB_INSNS_REVERSE (bb
, insn
)
1020 unsigned int uid
= INSN_UID (insn
);
1022 if (! INSN_P (insn
))
1025 df_rd_bb_local_compute_process_def (dflow
, bb_info
,
1026 DF_INSN_UID_GET (df
, uid
)->defs
, 0);
1028 /* This complex dance with the two bitmaps is required because
1029 instructions can assign twice to the same pseudo. This
1030 generally happens with calls that will have one def for the
1031 result and another def for the clobber. If only one vector
1032 is used and the clobber goes first, the result will be
1034 bitmap_ior_into (seen_in_block
, seen_in_insn
);
1035 bitmap_clear (seen_in_insn
);
1038 /* Process the artificial defs at the top of the block last since we
1039 are going backwards through the block and these are logically at
1041 df_rd_bb_local_compute_process_def (dflow
, bb_info
,
1042 df_get_artificial_defs (df
, bb_index
),
1047 /* Compute local reaching def info for each basic block within BLOCKS. */
1050 df_rd_local_compute (struct dataflow
*dflow
,
1052 bitmap rescan_blocks ATTRIBUTE_UNUSED
)
1054 struct df
*df
= dflow
->df
;
1055 unsigned int bb_index
;
1058 struct df_rd_problem_data
*problem_data
=
1059 (struct df_rd_problem_data
*) dflow
->problem_data
;
1060 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
1061 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
1065 if (!df
->def_info
.refs_organized
)
1066 df_reorganize_refs (&df
->def_info
);
1068 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1070 df_rd_bb_local_compute (dflow
, bb_index
);
1073 /* Set up the knockout bit vectors to be applied across EH_EDGES. */
1074 EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call
, 0, regno
, bi
)
1076 struct df_reg_info
*reg_info
= DF_REG_DEF_GET (df
, regno
);
1077 if (reg_info
->n_refs
> DF_SPARSE_THRESHOLD
)
1079 bitmap_set_bit (sparse_invalidated
, regno
);
1083 bitmap defs
= df_ref_bitmap (problem_data
->def_sites
, regno
,
1084 reg_info
->begin
, reg_info
->n_refs
);
1085 bitmap_ior_into (dense_invalidated
, defs
);
1092 /* Initialize the solution bit vectors for problem. */
1095 df_rd_init_solution (struct dataflow
*dflow
, bitmap all_blocks
)
1097 unsigned int bb_index
;
1100 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1102 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
1104 bitmap_copy (bb_info
->out
, bb_info
->gen
);
1105 bitmap_clear (bb_info
->in
);
1109 /* In of target gets or of out of source. */
1112 df_rd_confluence_n (struct dataflow
*dflow
, edge e
)
1114 bitmap op1
= df_rd_get_bb_info (dflow
, e
->dest
->index
)->in
;
1115 bitmap op2
= df_rd_get_bb_info (dflow
, e
->src
->index
)->out
;
1117 if (e
->flags
& EDGE_EH
)
1119 struct df_rd_problem_data
*problem_data
=
1120 (struct df_rd_problem_data
*) dflow
->problem_data
;
1121 bitmap sparse_invalidated
= problem_data
->sparse_invalidated_by_call
;
1122 bitmap dense_invalidated
= problem_data
->dense_invalidated_by_call
;
1123 struct df
*df
= dflow
->df
;
1126 bitmap tmp
= BITMAP_ALLOC (NULL
);
1128 bitmap_copy (tmp
, op2
);
1129 bitmap_and_compl_into (tmp
, dense_invalidated
);
1131 EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated
, 0, regno
, bi
)
1133 bitmap_clear_range (tmp
,
1134 DF_REG_DEF_GET (df
, regno
)->begin
,
1135 DF_REG_DEF_GET (df
, regno
)->n_refs
);
1137 bitmap_ior_into (op1
, tmp
);
1141 bitmap_ior_into (op1
, op2
);
1145 /* Transfer function. */
1148 df_rd_transfer_function (struct dataflow
*dflow
, int bb_index
)
1150 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb_index
);
1153 bitmap in
= bb_info
->in
;
1154 bitmap out
= bb_info
->out
;
1155 bitmap gen
= bb_info
->gen
;
1156 bitmap kill
= bb_info
->kill
;
1157 bitmap sparse_kill
= bb_info
->sparse_kill
;
1159 if (bitmap_empty_p (sparse_kill
))
1160 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
1163 struct df
*df
= dflow
->df
;
1164 bool changed
= false;
1165 bitmap tmp
= BITMAP_ALLOC (NULL
);
1166 bitmap_copy (tmp
, in
);
1167 EXECUTE_IF_SET_IN_BITMAP (sparse_kill
, 0, regno
, bi
)
1169 bitmap_clear_range (tmp
,
1170 DF_REG_DEF_GET (df
, regno
)->begin
,
1171 DF_REG_DEF_GET (df
, regno
)->n_refs
);
1173 bitmap_and_compl_into (tmp
, kill
);
1174 bitmap_ior_into (tmp
, gen
);
1175 changed
= !bitmap_equal_p (tmp
, out
);
1188 /* Free all storage associated with the problem. */
1191 df_rd_free (struct dataflow
*dflow
)
1194 struct df_rd_problem_data
*problem_data
=
1195 (struct df_rd_problem_data
*) dflow
->problem_data
;
1199 for (i
= 0; i
< dflow
->block_info_size
; i
++)
1201 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, i
);
1204 BITMAP_FREE (bb_info
->kill
);
1205 BITMAP_FREE (bb_info
->sparse_kill
);
1206 BITMAP_FREE (bb_info
->gen
);
1207 BITMAP_FREE (bb_info
->in
);
1208 BITMAP_FREE (bb_info
->out
);
1212 free_alloc_pool (dflow
->block_pool
);
1214 for (i
= 0; i
< problem_data
->def_sites_size
; i
++)
1216 bitmap bm
= problem_data
->def_sites
[i
];
1221 free (problem_data
->def_sites
);
1222 BITMAP_FREE (problem_data
->sparse_invalidated_by_call
);
1223 BITMAP_FREE (problem_data
->dense_invalidated_by_call
);
1225 dflow
->block_info_size
= 0;
1226 free (dflow
->block_info
);
1227 free (dflow
->problem_data
);
1233 /* Debugging info. */
1236 df_rd_dump (struct dataflow
*dflow
, FILE *file
)
1238 struct df
*df
= dflow
->df
;
1240 struct df_rd_problem_data
*problem_data
=
1241 (struct df_rd_problem_data
*) dflow
->problem_data
;
1242 unsigned int m
= max_reg_num ();
1245 fprintf (file
, "Reaching defs:\n\n");
1247 fprintf (file
, " sparse invalidated \t");
1248 dump_bitmap (file
, problem_data
->sparse_invalidated_by_call
);
1249 fprintf (file
, " dense invalidated \t");
1250 dump_bitmap (file
, problem_data
->dense_invalidated_by_call
);
1252 for (regno
= 0; regno
< m
; regno
++)
1253 if (DF_REG_DEF_GET (df
, regno
)->n_refs
)
1254 fprintf (file
, "%d[%d,%d] ", regno
,
1255 DF_REG_DEF_GET (df
, regno
)->begin
,
1256 DF_REG_DEF_GET (df
, regno
)->n_refs
);
1257 fprintf (file
, "\n");
1261 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (dflow
, bb
->index
);
1262 df_print_bb_index (bb
, file
);
1267 fprintf (file
, " in\t(%d)\n", (int) bitmap_count_bits (bb_info
->in
));
1268 dump_bitmap (file
, bb_info
->in
);
1269 fprintf (file
, " gen \t(%d)\n", (int) bitmap_count_bits (bb_info
->gen
));
1270 dump_bitmap (file
, bb_info
->gen
);
1271 fprintf (file
, " kill\t(%d)\n", (int) bitmap_count_bits (bb_info
->kill
));
1272 dump_bitmap (file
, bb_info
->kill
);
1273 fprintf (file
, " out\t(%d)\n", (int) bitmap_count_bits (bb_info
->out
));
1274 dump_bitmap (file
, bb_info
->out
);
1278 /* All of the information associated with every instance of the problem. */
1280 static struct df_problem problem_RD
=
1282 DF_RD
, /* Problem id. */
1283 DF_FORWARD
, /* Direction. */
1284 df_rd_alloc
, /* Allocate the problem specific data. */
1285 NULL
, /* Reset global information. */
1286 df_rd_free_bb_info
, /* Free basic block info. */
1287 df_rd_local_compute
, /* Local compute function. */
1288 df_rd_init_solution
, /* Init the solution specific data. */
1289 df_iterative_dataflow
, /* Iterative solver. */
1290 NULL
, /* Confluence operator 0. */
1291 df_rd_confluence_n
, /* Confluence operator n. */
1292 df_rd_transfer_function
, /* Transfer function. */
1293 NULL
, /* Finalize function. */
1294 df_rd_free
, /* Free all of the problem information. */
1295 df_rd_dump
, /* Debugging. */
1296 NULL
/* Dependent problem. */
1301 /* Create a new DATAFLOW instance and add it to an existing instance
1302 of DF. The returned structure is what is used to get at the
1306 df_rd_add_problem (struct df
*df
)
1308 return df_add_problem (df
, &problem_RD
);
1313 /*----------------------------------------------------------------------------
1316 Find the locations in the function where any use of a pseudo can reach
1317 in the backwards direction.
1318 ----------------------------------------------------------------------------*/
1320 /* Get basic block info. */
1322 struct df_lr_bb_info
*
1323 df_lr_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
1325 return (struct df_lr_bb_info
*) dflow
->block_info
[index
];
1329 /* Set basic block info. */
1332 df_lr_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
1333 struct df_lr_bb_info
*bb_info
)
1335 dflow
->block_info
[index
] = bb_info
;
1339 /* Free basic block info. */
1342 df_lr_free_bb_info (struct dataflow
*dflow
,
1343 basic_block bb ATTRIBUTE_UNUSED
,
1346 struct df_lr_bb_info
*bb_info
= (struct df_lr_bb_info
*) vbb_info
;
1349 BITMAP_FREE (bb_info
->use
);
1350 BITMAP_FREE (bb_info
->def
);
1351 BITMAP_FREE (bb_info
->in
);
1352 BITMAP_FREE (bb_info
->out
);
1353 pool_free (dflow
->block_pool
, bb_info
);
1358 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1359 not touched unless the block is new. */
1362 df_lr_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
1364 unsigned int bb_index
;
1367 if (! dflow
->block_pool
)
1368 dflow
->block_pool
= create_alloc_pool ("df_lr_block pool",
1369 sizeof (struct df_lr_bb_info
), 50);
1371 df_grow_bb_info (dflow
);
1373 /* Because of the clustering of all def sites for the same pseudo,
1374 we have to process all of the blocks before doing the
1377 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
1379 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1382 bitmap_clear (bb_info
->def
);
1383 bitmap_clear (bb_info
->use
);
1387 bb_info
= (struct df_lr_bb_info
*) pool_alloc (dflow
->block_pool
);
1388 df_lr_set_bb_info (dflow
, bb_index
, bb_info
);
1389 bb_info
->use
= BITMAP_ALLOC (NULL
);
1390 bb_info
->def
= BITMAP_ALLOC (NULL
);
1391 bb_info
->in
= BITMAP_ALLOC (NULL
);
1392 bb_info
->out
= BITMAP_ALLOC (NULL
);
1398 /* Compute local live register info for basic block BB. */
1401 df_lr_bb_local_compute (struct dataflow
*dflow
,
1402 struct df
*df
, unsigned int bb_index
)
1404 basic_block bb
= BASIC_BLOCK (bb_index
);
1405 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1410 /* Process the registers set in an exception handler. */
1411 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1412 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
1414 unsigned int dregno
= DF_REF_REGNO (def
);
1415 bitmap_set_bit (bb_info
->def
, dregno
);
1416 bitmap_clear_bit (bb_info
->use
, dregno
);
1419 /* Process the hardware registers that are always live. */
1420 for (use
= df_get_artificial_uses (df
, bb_index
); use
; use
= use
->next_ref
)
1421 /* Add use to set of uses in this BB. */
1422 if ((DF_REF_FLAGS (use
) & DF_REF_AT_TOP
) == 0)
1423 bitmap_set_bit (bb_info
->use
, DF_REF_REGNO (use
));
1425 FOR_BB_INSNS_REVERSE (bb
, insn
)
1427 unsigned int uid
= INSN_UID (insn
);
1429 if (! INSN_P (insn
))
1434 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
1436 unsigned int dregno
= DF_REF_REGNO (def
);
1438 if (dregno
>= FIRST_PSEUDO_REGISTER
1439 || !(SIBLING_CALL_P (insn
)
1440 && bitmap_bit_p (df
->exit_block_uses
, dregno
)
1441 && !refers_to_regno_p (dregno
, dregno
+1,
1442 current_function_return_rtx
,
1445 /* Add def to set of defs in this BB. */
1446 bitmap_set_bit (bb_info
->def
, dregno
);
1447 bitmap_clear_bit (bb_info
->use
, dregno
);
1453 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
1455 unsigned int dregno
= DF_REF_REGNO (def
);
1457 if (DF_INSN_CONTAINS_ASM (df
, insn
)
1458 && dregno
< FIRST_PSEUDO_REGISTER
)
1462 dregno
+ hard_regno_nregs
[dregno
][GET_MODE (DF_REF_REG (def
))] - 1;
1463 for (i
= dregno
; i
<= end
; ++i
)
1464 regs_asm_clobbered
[i
] = 1;
1466 /* Add def to set of defs in this BB. */
1467 bitmap_set_bit (bb_info
->def
, dregno
);
1468 bitmap_clear_bit (bb_info
->use
, dregno
);
1472 for (use
= DF_INSN_UID_GET (df
, uid
)->uses
; use
; use
= use
->next_ref
)
1473 /* Add use to set of uses in this BB. */
1474 bitmap_set_bit (bb_info
->use
, DF_REF_REGNO (use
));
1477 /* Process the registers set in an exception handler. */
1478 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1479 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
1481 unsigned int dregno
= DF_REF_REGNO (def
);
1482 bitmap_set_bit (bb_info
->def
, dregno
);
1483 bitmap_clear_bit (bb_info
->use
, dregno
);
1487 /* Process the uses that are live into an exception handler. */
1488 for (use
= df_get_artificial_uses (df
, bb_index
); use
; use
= use
->next_ref
)
1489 /* Add use to set of uses in this BB. */
1490 if (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
)
1491 bitmap_set_bit (bb_info
->use
, DF_REF_REGNO (use
));
1495 /* Compute local live register info for each basic block within BLOCKS. */
1498 df_lr_local_compute (struct dataflow
*dflow
,
1500 bitmap rescan_blocks
)
1502 struct df
*df
= dflow
->df
;
1503 unsigned int bb_index
;
1506 /* Assume that the stack pointer is unchanging if alloca hasn't
1508 if (bitmap_equal_p (all_blocks
, rescan_blocks
))
1509 memset (regs_asm_clobbered
, 0, sizeof (regs_asm_clobbered
));
1511 bitmap_clear (df
->hardware_regs_used
);
1513 /* The all-important stack pointer must always be live. */
1514 bitmap_set_bit (df
->hardware_regs_used
, STACK_POINTER_REGNUM
);
1516 /* Before reload, there are a few registers that must be forced
1517 live everywhere -- which might not already be the case for
1518 blocks within infinite loops. */
1519 if (! reload_completed
)
1521 /* Any reference to any pseudo before reload is a potential
1522 reference of the frame pointer. */
1523 bitmap_set_bit (df
->hardware_regs_used
, FRAME_POINTER_REGNUM
);
1525 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1526 /* Pseudos with argument area equivalences may require
1527 reloading via the argument pointer. */
1528 if (fixed_regs
[ARG_POINTER_REGNUM
])
1529 bitmap_set_bit (df
->hardware_regs_used
, ARG_POINTER_REGNUM
);
1532 /* Any constant, or pseudo with constant equivalences, may
1533 require reloading from memory using the pic register. */
1534 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
1535 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
1536 bitmap_set_bit (df
->hardware_regs_used
, PIC_OFFSET_TABLE_REGNUM
);
1539 if (bitmap_bit_p (rescan_blocks
, EXIT_BLOCK
))
1541 /* The exit block is special for this problem and its bits are
1542 computed from thin air. */
1543 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, EXIT_BLOCK
);
1544 bitmap_copy (bb_info
->use
, df
->exit_block_uses
);
1547 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks
, 0, bb_index
, bi
)
1549 if (bb_index
== EXIT_BLOCK
)
1551 df_lr_bb_local_compute (dflow
, df
, bb_index
);
1556 /* Initialize the solution vectors. */
1559 df_lr_init (struct dataflow
*dflow
, bitmap all_blocks
)
1561 unsigned int bb_index
;
1564 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1566 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1567 bitmap_copy (bb_info
->in
, bb_info
->use
);
1568 bitmap_clear (bb_info
->out
);
1573 /* Confluence function that processes infinite loops. This might be a
1574 noreturn function that throws. And even if it isn't, getting the
1575 unwind info right helps debugging. */
1577 df_lr_confluence_0 (struct dataflow
*dflow
, basic_block bb
)
1579 struct df
*df
= dflow
->df
;
1581 bitmap op1
= df_lr_get_bb_info (dflow
, bb
->index
)->out
;
1582 if (bb
!= EXIT_BLOCK_PTR
)
1583 bitmap_copy (op1
, df
->hardware_regs_used
);
1587 /* Confluence function that ignores fake edges. */
1589 df_lr_confluence_n (struct dataflow
*dflow
, edge e
)
1591 bitmap op1
= df_lr_get_bb_info (dflow
, e
->src
->index
)->out
;
1592 bitmap op2
= df_lr_get_bb_info (dflow
, e
->dest
->index
)->in
;
1594 /* Call-clobbered registers die across exception and call edges. */
1595 /* ??? Abnormal call edges ignored for the moment, as this gets
1596 confused by sibling call edges, which crashes reg-stack. */
1597 if (e
->flags
& EDGE_EH
)
1598 bitmap_ior_and_compl_into (op1
, op2
, df_invalidated_by_call
);
1600 bitmap_ior_into (op1
, op2
);
1602 bitmap_ior_into (op1
, dflow
->df
->hardware_regs_used
);
1606 /* Transfer function. */
1608 df_lr_transfer_function (struct dataflow
*dflow
, int bb_index
)
1610 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb_index
);
1611 bitmap in
= bb_info
->in
;
1612 bitmap out
= bb_info
->out
;
1613 bitmap use
= bb_info
->use
;
1614 bitmap def
= bb_info
->def
;
1616 return bitmap_ior_and_compl (in
, use
, out
, def
);
1620 /* Free all storage associated with the problem. */
1623 df_lr_free (struct dataflow
*dflow
)
1625 if (dflow
->block_info
)
1628 for (i
= 0; i
< dflow
->block_info_size
; i
++)
1630 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, i
);
1633 BITMAP_FREE (bb_info
->use
);
1634 BITMAP_FREE (bb_info
->def
);
1635 BITMAP_FREE (bb_info
->in
);
1636 BITMAP_FREE (bb_info
->out
);
1639 free_alloc_pool (dflow
->block_pool
);
1641 dflow
->block_info_size
= 0;
1642 free (dflow
->block_info
);
1648 /* Debugging info. */
1651 df_lr_dump (struct dataflow
*dflow
, FILE *file
)
1655 fprintf (file
, "Live Registers:\n");
1658 struct df_lr_bb_info
*bb_info
= df_lr_get_bb_info (dflow
, bb
->index
);
1659 df_print_bb_index (bb
, file
);
1664 fprintf (file
, " in \t");
1665 dump_bitmap (file
, bb_info
->in
);
1666 fprintf (file
, " use \t");
1667 dump_bitmap (file
, bb_info
->use
);
1668 fprintf (file
, " def \t");
1669 dump_bitmap (file
, bb_info
->def
);
1670 fprintf (file
, " out \t");
1671 dump_bitmap (file
, bb_info
->out
);
1675 /* All of the information associated with every instance of the problem. */
1677 static struct df_problem problem_LR
=
1679 DF_LR
, /* Problem id. */
1680 DF_BACKWARD
, /* Direction. */
1681 df_lr_alloc
, /* Allocate the problem specific data. */
1682 NULL
, /* Reset global information. */
1683 df_lr_free_bb_info
, /* Free basic block info. */
1684 df_lr_local_compute
, /* Local compute function. */
1685 df_lr_init
, /* Init the solution specific data. */
1686 df_iterative_dataflow
, /* Iterative solver. */
1687 df_lr_confluence_0
, /* Confluence operator 0. */
1688 df_lr_confluence_n
, /* Confluence operator n. */
1689 df_lr_transfer_function
, /* Transfer function. */
1690 NULL
, /* Finalize function. */
1691 df_lr_free
, /* Free all of the problem information. */
1692 df_lr_dump
, /* Debugging. */
1693 NULL
/* Dependent problem. */
1697 /* Create a new DATAFLOW instance and add it to an existing instance
1698 of DF. The returned structure is what is used to get at the
1702 df_lr_add_problem (struct df
*df
)
1704 return df_add_problem (df
, &problem_LR
);
1709 /*----------------------------------------------------------------------------
1710 UNINITIALIZED REGISTERS
1712 Find the set of uses for registers that are reachable from the entry
1713 block without passing thru a definition.
1714 ----------------------------------------------------------------------------*/
1716 /* Get basic block info. */
1718 struct df_ur_bb_info
*
1719 df_ur_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
1721 return (struct df_ur_bb_info
*) dflow
->block_info
[index
];
1725 /* Set basic block info. */
1728 df_ur_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
1729 struct df_ur_bb_info
*bb_info
)
1731 dflow
->block_info
[index
] = bb_info
;
1735 /* Free basic block info. */
1738 df_ur_free_bb_info (struct dataflow
*dflow
,
1739 basic_block bb ATTRIBUTE_UNUSED
,
1742 struct df_ur_bb_info
*bb_info
= (struct df_ur_bb_info
*) vbb_info
;
1745 BITMAP_FREE (bb_info
->gen
);
1746 BITMAP_FREE (bb_info
->kill
);
1747 BITMAP_FREE (bb_info
->in
);
1748 BITMAP_FREE (bb_info
->out
);
1749 pool_free (dflow
->block_pool
, bb_info
);
1754 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
1755 not touched unless the block is new. */
1758 df_ur_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
1760 unsigned int bb_index
;
1763 if (! dflow
->block_pool
)
1764 dflow
->block_pool
= create_alloc_pool ("df_ur_block pool",
1765 sizeof (struct df_ur_bb_info
), 100);
1767 df_grow_bb_info (dflow
);
1769 /* Because of the clustering of all def sites for the same pseudo,
1770 we have to process all of the blocks before doing the
1773 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
1775 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1778 bitmap_clear (bb_info
->kill
);
1779 bitmap_clear (bb_info
->gen
);
1783 bb_info
= (struct df_ur_bb_info
*) pool_alloc (dflow
->block_pool
);
1784 df_ur_set_bb_info (dflow
, bb_index
, bb_info
);
1785 bb_info
->kill
= BITMAP_ALLOC (NULL
);
1786 bb_info
->gen
= BITMAP_ALLOC (NULL
);
1787 bb_info
->in
= BITMAP_ALLOC (NULL
);
1788 bb_info
->out
= BITMAP_ALLOC (NULL
);
1794 /* Compute local uninitialized register info for basic block BB. */
1797 df_ur_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
1799 struct df
*df
= dflow
->df
;
1800 basic_block bb
= BASIC_BLOCK (bb_index
);
1801 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1805 bitmap_clear (seen_in_block
);
1806 bitmap_clear (seen_in_insn
);
1808 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1809 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
1811 unsigned int regno
= DF_REF_REGNO (def
);
1812 if (!bitmap_bit_p (seen_in_block
, regno
))
1814 bitmap_set_bit (seen_in_block
, regno
);
1815 bitmap_set_bit (bb_info
->gen
, regno
);
1819 FOR_BB_INSNS_REVERSE (bb
, insn
)
1821 unsigned int uid
= INSN_UID (insn
);
1825 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
1827 unsigned int regno
= DF_REF_REGNO (def
);
1828 /* Only the last def counts. */
1829 if (!bitmap_bit_p (seen_in_block
, regno
))
1831 bitmap_set_bit (seen_in_insn
, regno
);
1833 if (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
)
1834 bitmap_set_bit (bb_info
->kill
, regno
);
1836 bitmap_set_bit (bb_info
->gen
, regno
);
1839 bitmap_ior_into (seen_in_block
, seen_in_insn
);
1840 bitmap_clear (seen_in_insn
);
1843 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
1844 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
1846 unsigned int regno
= DF_REF_REGNO (def
);
1847 if (!bitmap_bit_p (seen_in_block
, regno
))
1849 bitmap_set_bit (seen_in_block
, regno
);
1850 bitmap_set_bit (bb_info
->gen
, regno
);
1856 /* Compute local uninitialized register info. */
1859 df_ur_local_compute (struct dataflow
*dflow
,
1860 bitmap all_blocks ATTRIBUTE_UNUSED
,
1861 bitmap rescan_blocks
)
1863 unsigned int bb_index
;
1868 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks
, 0, bb_index
, bi
)
1870 df_ur_bb_local_compute (dflow
, bb_index
);
1877 /* Initialize the solution vectors. */
1880 df_ur_init (struct dataflow
*dflow
, bitmap all_blocks
)
1882 unsigned int bb_index
;
1885 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1887 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1889 bitmap_copy (bb_info
->out
, bb_info
->gen
);
1890 bitmap_clear (bb_info
->in
);
1895 /* Or in the stack regs, hard regs and early clobber regs into the the
1896 ur_in sets of all of the blocks. */
1899 df_ur_local_finalize (struct dataflow
*dflow
, bitmap all_blocks
)
1901 struct df
*df
= dflow
->df
;
1902 struct dataflow
*lr_dflow
= df
->problems_by_index
[DF_LR
];
1903 bitmap tmp
= BITMAP_ALLOC (NULL
);
1905 unsigned int bb_index
;
1907 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
1909 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1910 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (lr_dflow
, bb_index
);
1912 /* No register may reach a location where it is not used. Thus
1913 we trim the rr result to the places where it is used. */
1914 bitmap_and_into (bb_info
->in
, bb_lr_info
->in
);
1915 bitmap_and_into (bb_info
->out
, bb_lr_info
->out
);
1918 /* Hard registers may still stick in the ur_out set, but not
1919 be in the ur_in set, if their only mention was in a call
1920 in this block. This is because a call kills in the lr
1921 problem but does not kill in the ur problem. To clean
1922 this up, we execute the transfer function on the lr_in
1923 set and then use that to knock bits out of ur_out. */
1924 bitmap_ior_and_compl (tmp
, bb_info
->gen
, bb_lr_info
->in
,
1926 bitmap_and_into (bb_info
->out
, tmp
);
1934 /* Confluence function that ignores fake edges. */
1937 df_ur_confluence_n (struct dataflow
*dflow
, edge e
)
1939 bitmap op1
= df_ur_get_bb_info (dflow
, e
->dest
->index
)->in
;
1940 bitmap op2
= df_ur_get_bb_info (dflow
, e
->src
->index
)->out
;
1942 if (e
->flags
& EDGE_FAKE
)
1945 bitmap_ior_into (op1
, op2
);
1949 /* Transfer function. */
1952 df_ur_transfer_function (struct dataflow
*dflow
, int bb_index
)
1954 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
1955 bitmap in
= bb_info
->in
;
1956 bitmap out
= bb_info
->out
;
1957 bitmap gen
= bb_info
->gen
;
1958 bitmap kill
= bb_info
->kill
;
1960 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
1964 /* Free all storage associated with the problem. */
1967 df_ur_free (struct dataflow
*dflow
)
1969 if (dflow
->block_info
)
1973 for (i
= 0; i
< dflow
->block_info_size
; i
++)
1975 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, i
);
1978 BITMAP_FREE (bb_info
->gen
);
1979 BITMAP_FREE (bb_info
->kill
);
1980 BITMAP_FREE (bb_info
->in
);
1981 BITMAP_FREE (bb_info
->out
);
1985 free_alloc_pool (dflow
->block_pool
);
1986 dflow
->block_info_size
= 0;
1987 free (dflow
->block_info
);
1993 /* Debugging info. */
1996 df_ur_dump (struct dataflow
*dflow
, FILE *file
)
2000 fprintf (file
, "Undefined regs:\n");
2004 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb
->index
);
2005 df_print_bb_index (bb
, file
);
2010 fprintf (file
, " in \t");
2011 dump_bitmap (file
, bb_info
->in
);
2012 fprintf (file
, " gen \t");
2013 dump_bitmap (file
, bb_info
->gen
);
2014 fprintf (file
, " kill\t");
2015 dump_bitmap (file
, bb_info
->kill
);
2016 fprintf (file
, " out \t");
2017 dump_bitmap (file
, bb_info
->out
);
2021 /* All of the information associated with every instance of the problem. */
2023 static struct df_problem problem_UR
=
2025 DF_UR
, /* Problem id. */
2026 DF_FORWARD
, /* Direction. */
2027 df_ur_alloc
, /* Allocate the problem specific data. */
2028 NULL
, /* Reset global information. */
2029 df_ur_free_bb_info
, /* Free basic block info. */
2030 df_ur_local_compute
, /* Local compute function. */
2031 df_ur_init
, /* Init the solution specific data. */
2032 df_iterative_dataflow
, /* Iterative solver. */
2033 NULL
, /* Confluence operator 0. */
2034 df_ur_confluence_n
, /* Confluence operator n. */
2035 df_ur_transfer_function
, /* Transfer function. */
2036 df_ur_local_finalize
, /* Finalize function. */
2037 df_ur_free
, /* Free all of the problem information. */
2038 df_ur_dump
, /* Debugging. */
2039 &problem_LR
/* Dependent problem. */
2043 /* Create a new DATAFLOW instance and add it to an existing instance
2044 of DF. The returned structure is what is used to get at the
2048 df_ur_add_problem (struct df
*df
)
2050 return df_add_problem (df
, &problem_UR
);
2055 /*----------------------------------------------------------------------------
2056 UNINITIALIZED REGISTERS WITH EARLYCLOBBER
2058 Find the set of uses for registers that are reachable from the entry
2059 block without passing thru a definition.
2061 This is a variant of the UR problem above that has a lot of special
2062 features just for the register allocation phase.
2063 ----------------------------------------------------------------------------*/
2065 struct df_urec_problem_data
2067 bool earlyclobbers_found
; /* True if any instruction contains an
2070 bitmap stack_regs
; /* Registers that may be allocated to a STACK_REGS. */
2075 /* Get basic block info. */
2077 struct df_urec_bb_info
*
2078 df_urec_get_bb_info (struct dataflow
*dflow
, unsigned int index
)
2080 return (struct df_urec_bb_info
*) dflow
->block_info
[index
];
2084 /* Set basic block info. */
2087 df_urec_set_bb_info (struct dataflow
*dflow
, unsigned int index
,
2088 struct df_urec_bb_info
*bb_info
)
2090 dflow
->block_info
[index
] = bb_info
;
2094 /* Free basic block info. */
2097 df_urec_free_bb_info (struct dataflow
*dflow
,
2098 basic_block bb ATTRIBUTE_UNUSED
,
2101 struct df_urec_bb_info
*bb_info
= (struct df_urec_bb_info
*) vbb_info
;
2104 BITMAP_FREE (bb_info
->gen
);
2105 BITMAP_FREE (bb_info
->kill
);
2106 BITMAP_FREE (bb_info
->in
);
2107 BITMAP_FREE (bb_info
->out
);
2108 BITMAP_FREE (bb_info
->earlyclobber
);
2109 pool_free (dflow
->block_pool
, bb_info
);
2114 /* Allocate or reset bitmaps for DFLOW blocks. The solution bits are
2115 not touched unless the block is new. */
2118 df_urec_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan
)
2120 unsigned int bb_index
;
2122 struct df_urec_problem_data
*problem_data
=
2123 (struct df_urec_problem_data
*) dflow
->problem_data
;
2125 if (! dflow
->block_pool
)
2126 dflow
->block_pool
= create_alloc_pool ("df_urec_block pool",
2127 sizeof (struct df_urec_bb_info
), 50);
2129 if (!dflow
->problem_data
)
2131 problem_data
= XNEW (struct df_urec_problem_data
);
2132 dflow
->problem_data
= problem_data
;
2134 problem_data
->earlyclobbers_found
= false;
2136 df_grow_bb_info (dflow
);
2138 /* Because of the clustering of all def sites for the same pseudo,
2139 we have to process all of the blocks before doing the
2142 EXECUTE_IF_SET_IN_BITMAP (blocks_to_rescan
, 0, bb_index
, bi
)
2144 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2147 bitmap_clear (bb_info
->kill
);
2148 bitmap_clear (bb_info
->gen
);
2149 bitmap_clear (bb_info
->earlyclobber
);
2153 bb_info
= (struct df_urec_bb_info
*) pool_alloc (dflow
->block_pool
);
2154 df_urec_set_bb_info (dflow
, bb_index
, bb_info
);
2155 bb_info
->kill
= BITMAP_ALLOC (NULL
);
2156 bb_info
->gen
= BITMAP_ALLOC (NULL
);
2157 bb_info
->in
= BITMAP_ALLOC (NULL
);
2158 bb_info
->out
= BITMAP_ALLOC (NULL
);
2159 bb_info
->earlyclobber
= BITMAP_ALLOC (NULL
);
2165 /* The function modifies local info for register REG being changed in
2166 SETTER. DATA is used to pass the current basic block info. */
2169 df_urec_mark_reg_change (rtx reg
, rtx setter
, void *data
)
2174 struct df_urec_bb_info
*bb_info
= (struct df_urec_bb_info
*) data
;
2176 if (GET_CODE (reg
) == SUBREG
)
2177 reg
= SUBREG_REG (reg
);
2183 endregno
= regno
= REGNO (reg
);
2184 if (regno
< FIRST_PSEUDO_REGISTER
)
2186 endregno
+=hard_regno_nregs
[regno
][GET_MODE (reg
)];
2188 for (i
= regno
; i
< endregno
; i
++)
2190 bitmap_set_bit (bb_info
->kill
, i
);
2192 if (GET_CODE (setter
) != CLOBBER
)
2193 bitmap_set_bit (bb_info
->gen
, i
);
2195 bitmap_clear_bit (bb_info
->gen
, i
);
2200 bitmap_set_bit (bb_info
->kill
, regno
);
2202 if (GET_CODE (setter
) != CLOBBER
)
2203 bitmap_set_bit (bb_info
->gen
, regno
);
2205 bitmap_clear_bit (bb_info
->gen
, regno
);
2208 /* Classes of registers which could be early clobbered in the current
2212 DEF_VEC_ALLOC_I(int,heap
);
2214 static VEC(int,heap
) *earlyclobber_regclass
;
2216 /* This function finds and stores register classes that could be early
2217 clobbered in INSN. If any earlyclobber classes are found, the function
2218 returns TRUE, in all other cases it returns FALSE. */
2221 df_urec_check_earlyclobber (rtx insn
)
2226 extract_insn (insn
);
2228 VEC_truncate (int, earlyclobber_regclass
, 0);
2229 for (opno
= 0; opno
< recog_data
.n_operands
; opno
++)
2234 enum reg_class
class;
2235 const char *p
= recog_data
.constraints
[opno
];
2244 case '=': case '+': case '?':
2247 case 'm': case '<': case '>': case 'V': case 'o':
2248 case 'E': case 'F': case 'G': case 'H':
2249 case 's': case 'i': case 'n':
2250 case 'I': case 'J': case 'K': case 'L':
2251 case 'M': case 'N': case 'O': case 'P':
2253 case '0': case '1': case '2': case '3': case '4':
2254 case '5': case '6': case '7': case '8': case '9':
2255 /* These don't say anything we care about. */
2263 if (amp_p
&& class != NO_REGS
)
2269 VEC_iterate (int, earlyclobber_regclass
, i
, rc
);
2272 if (rc
== (int) class)
2276 /* We use VEC_quick_push here because
2277 earlyclobber_regclass holds no more than
2278 N_REG_CLASSES elements. */
2279 VEC_quick_push (int, earlyclobber_regclass
, (int) class);
2289 class = GENERAL_REGS
;
2293 class = REG_CLASS_FROM_CONSTRAINT (c
, p
);
2298 p
+= CONSTRAINT_LEN (c
, p
);
2305 /* The function checks that pseudo-register *X has a class
2306 intersecting with the class of pseudo-register could be early
2307 clobbered in the same insn.
2309 This function is a no-op if earlyclobber_regclass is empty.
2311 Reload can assign the same hard register to uninitialized
2312 pseudo-register and early clobbered pseudo-register in an insn if
2313 the pseudo-register is used first time in given BB and not lived at
2314 the BB start. To prevent this we don't change life information for
2315 such pseudo-registers. */
2318 df_urec_mark_reg_use_for_earlyclobber (rtx
*x
, void *data
)
2320 enum reg_class pref_class
, alt_class
;
2322 struct df_urec_bb_info
*bb_info
= (struct df_urec_bb_info
*) data
;
2324 if (REG_P (*x
) && REGNO (*x
) >= FIRST_PSEUDO_REGISTER
)
2329 if (bitmap_bit_p (bb_info
->kill
, regno
)
2330 || bitmap_bit_p (bb_info
->gen
, regno
))
2332 pref_class
= reg_preferred_class (regno
);
2333 alt_class
= reg_alternate_class (regno
);
2334 for (i
= 0; VEC_iterate (int, earlyclobber_regclass
, i
, rc
); i
++)
2336 if (reg_classes_intersect_p (rc
, pref_class
)
2338 && reg_classes_intersect_p (rc
, alt_class
)))
2340 bitmap_set_bit (bb_info
->earlyclobber
, regno
);
2348 /* The function processes all pseudo-registers in *X with the aid of
2349 previous function. */
2352 df_urec_mark_reg_use_for_earlyclobber_1 (rtx
*x
, void *data
)
2354 for_each_rtx (x
, df_urec_mark_reg_use_for_earlyclobber
, data
);
2358 /* Compute local uninitialized register info for basic block BB. */
2361 df_urec_bb_local_compute (struct dataflow
*dflow
, unsigned int bb_index
)
2363 struct df
*df
= dflow
->df
;
2364 basic_block bb
= BASIC_BLOCK (bb_index
);
2365 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2369 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
2370 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
2372 unsigned int regno
= DF_REF_REGNO (def
);
2373 bitmap_set_bit (bb_info
->gen
, regno
);
2376 FOR_BB_INSNS (bb
, insn
)
2380 note_stores (PATTERN (insn
), df_urec_mark_reg_change
, bb_info
);
2381 if (df_state
& (DF_SCAN_GLOBAL
| DF_SCAN_POST_ALLOC
)
2382 && df_urec_check_earlyclobber (insn
))
2384 struct df_urec_problem_data
*problem_data
=
2385 (struct df_urec_problem_data
*) dflow
->problem_data
;
2386 problem_data
->earlyclobbers_found
= true;
2387 note_uses (&PATTERN (insn
),
2388 df_urec_mark_reg_use_for_earlyclobber_1
, bb_info
);
2393 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
2394 if ((DF_REF_FLAGS (def
) & DF_REF_AT_TOP
) == 0)
2396 unsigned int regno
= DF_REF_REGNO (def
);
2397 bitmap_set_bit (bb_info
->gen
, regno
);
2403 /* Compute local uninitialized register info. */
2406 df_urec_local_compute (struct dataflow
*dflow
,
2407 bitmap all_blocks ATTRIBUTE_UNUSED
,
2408 bitmap rescan_blocks
)
2410 unsigned int bb_index
;
2414 HARD_REG_SET zero
, stack_hard_regs
, used
;
2415 struct df_urec_problem_data
*problem_data
=
2416 (struct df_urec_problem_data
*) dflow
->problem_data
;
2418 /* Any register that MAY be allocated to a register stack (like the
2419 387) is treated poorly. Each such register is marked as being
2420 live everywhere. This keeps the register allocator and the
2421 subsequent passes from doing anything useful with these values.
2423 FIXME: This seems like an incredibly poor idea. */
2425 CLEAR_HARD_REG_SET (zero
);
2426 CLEAR_HARD_REG_SET (stack_hard_regs
);
2427 for (i
= FIRST_STACK_REG
; i
<= LAST_STACK_REG
; i
++)
2428 SET_HARD_REG_BIT (stack_hard_regs
, i
);
2429 problem_data
->stack_regs
= BITMAP_ALLOC (NULL
);
2430 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
2432 COPY_HARD_REG_SET (used
, reg_class_contents
[reg_preferred_class (i
)]);
2433 IOR_HARD_REG_SET (used
, reg_class_contents
[reg_alternate_class (i
)]);
2434 AND_HARD_REG_SET (used
, stack_hard_regs
);
2435 GO_IF_HARD_REG_EQUAL (used
, zero
, skip
);
2436 bitmap_set_bit (problem_data
->stack_regs
, i
);
2442 /* We know that earlyclobber_regclass holds no more than
2443 N_REG_CLASSES elements. See df_urec_check_earlyclobber. */
2444 earlyclobber_regclass
= VEC_alloc (int, heap
, N_REG_CLASSES
);
2446 EXECUTE_IF_SET_IN_BITMAP (rescan_blocks
, 0, bb_index
, bi
)
2448 df_urec_bb_local_compute (dflow
, bb_index
);
2451 VEC_free (int, heap
, earlyclobber_regclass
);
2455 /* Initialize the solution vectors. */
2458 df_urec_init (struct dataflow
*dflow
, bitmap all_blocks
)
2460 unsigned int bb_index
;
2463 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2465 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2467 bitmap_copy (bb_info
->out
, bb_info
->gen
);
2468 bitmap_clear (bb_info
->in
);
2473 /* Or in the stack regs, hard regs and early clobber regs into the the
2474 ur_in sets of all of the blocks. */
2477 df_urec_local_finalize (struct dataflow
*dflow
, bitmap all_blocks
)
2479 struct df
*df
= dflow
->df
;
2480 struct dataflow
*lr_dflow
= df
->problems_by_index
[DF_LR
];
2481 bitmap tmp
= BITMAP_ALLOC (NULL
);
2483 unsigned int bb_index
;
2484 struct df_urec_problem_data
*problem_data
=
2485 (struct df_urec_problem_data
*) dflow
->problem_data
;
2487 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2489 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2490 struct df_lr_bb_info
*bb_lr_info
= df_lr_get_bb_info (lr_dflow
, bb_index
);
2492 if (bb_index
!= ENTRY_BLOCK
&& bb_index
!= EXIT_BLOCK
)
2494 if (problem_data
->earlyclobbers_found
)
2495 bitmap_ior_into (bb_info
->in
, bb_info
->earlyclobber
);
2498 /* We can not use the same stack register for uninitialized
2499 pseudo-register and another living pseudo-register
2500 because if the uninitialized pseudo-register dies,
2501 subsequent pass reg-stack will be confused (it will
2502 believe that the other register dies). */
2503 bitmap_ior_into (bb_info
->in
, problem_data
->stack_regs
);
2504 bitmap_ior_into (bb_info
->out
, problem_data
->stack_regs
);
2508 /* No register may reach a location where it is not used. Thus
2509 we trim the rr result to the places where it is used. */
2510 bitmap_and_into (bb_info
->in
, bb_lr_info
->in
);
2511 bitmap_and_into (bb_info
->out
, bb_lr_info
->out
);
2514 /* Hard registers may still stick in the ur_out set, but not
2515 be in the ur_in set, if their only mention was in a call
2516 in this block. This is because a call kills in the lr
2517 problem but does not kill in the rr problem. To clean
2518 this up, we execute the transfer function on the lr_in
2519 set and then use that to knock bits out of ur_out. */
2520 bitmap_ior_and_compl (tmp
, bb_info
->gen
, bb_lr_info
->in
,
2522 bitmap_and_into (bb_info
->out
, tmp
);
2527 BITMAP_FREE (problem_data
->stack_regs
);
2533 /* Confluence function that ignores fake edges. */
2536 df_urec_confluence_n (struct dataflow
*dflow
, edge e
)
2538 bitmap op1
= df_urec_get_bb_info (dflow
, e
->dest
->index
)->in
;
2539 bitmap op2
= df_urec_get_bb_info (dflow
, e
->src
->index
)->out
;
2541 if (e
->flags
& EDGE_FAKE
)
2544 bitmap_ior_into (op1
, op2
);
2548 /* Transfer function. */
2551 df_urec_transfer_function (struct dataflow
*dflow
, int bb_index
)
2553 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb_index
);
2554 bitmap in
= bb_info
->in
;
2555 bitmap out
= bb_info
->out
;
2556 bitmap gen
= bb_info
->gen
;
2557 bitmap kill
= bb_info
->kill
;
2559 return bitmap_ior_and_compl (out
, gen
, in
, kill
);
2563 /* Free all storage associated with the problem. */
2566 df_urec_free (struct dataflow
*dflow
)
2568 if (dflow
->block_info
)
2572 for (i
= 0; i
< dflow
->block_info_size
; i
++)
2574 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, i
);
2577 BITMAP_FREE (bb_info
->gen
);
2578 BITMAP_FREE (bb_info
->kill
);
2579 BITMAP_FREE (bb_info
->in
);
2580 BITMAP_FREE (bb_info
->out
);
2581 BITMAP_FREE (bb_info
->earlyclobber
);
2585 free_alloc_pool (dflow
->block_pool
);
2587 dflow
->block_info_size
= 0;
2588 free (dflow
->block_info
);
2589 free (dflow
->problem_data
);
2595 /* Debugging info. */
2598 df_urec_dump (struct dataflow
*dflow
, FILE *file
)
2602 fprintf (file
, "Undefined regs:\n");
2606 struct df_urec_bb_info
*bb_info
= df_urec_get_bb_info (dflow
, bb
->index
);
2607 df_print_bb_index (bb
, file
);
2612 fprintf (file
, " in \t");
2613 dump_bitmap (file
, bb_info
->in
);
2614 fprintf (file
, " gen \t");
2615 dump_bitmap (file
, bb_info
->gen
);
2616 fprintf (file
, " kill\t");
2617 dump_bitmap (file
, bb_info
->kill
);
2618 fprintf (file
, " ec\t");
2619 dump_bitmap (file
, bb_info
->earlyclobber
);
2620 fprintf (file
, " out \t");
2621 dump_bitmap (file
, bb_info
->out
);
2625 /* All of the information associated with every instance of the problem. */
2627 static struct df_problem problem_UREC
=
2629 DF_UREC
, /* Problem id. */
2630 DF_FORWARD
, /* Direction. */
2631 df_urec_alloc
, /* Allocate the problem specific data. */
2632 NULL
, /* Reset global information. */
2633 df_urec_free_bb_info
, /* Free basic block info. */
2634 df_urec_local_compute
, /* Local compute function. */
2635 df_urec_init
, /* Init the solution specific data. */
2636 df_iterative_dataflow
, /* Iterative solver. */
2637 NULL
, /* Confluence operator 0. */
2638 df_urec_confluence_n
, /* Confluence operator n. */
2639 df_urec_transfer_function
, /* Transfer function. */
2640 df_urec_local_finalize
, /* Finalize function. */
2641 df_urec_free
, /* Free all of the problem information. */
2642 df_urec_dump
, /* Debugging. */
2643 &problem_LR
/* Dependent problem. */
2647 /* Create a new DATAFLOW instance and add it to an existing instance
2648 of DF. The returned structure is what is used to get at the
2652 df_urec_add_problem (struct df
*df
)
2654 return df_add_problem (df
, &problem_UREC
);
2659 /*----------------------------------------------------------------------------
2660 CREATE DEF_USE (DU) and / or USE_DEF (UD) CHAINS
2662 Link either the defs to the uses and / or the uses to the defs.
2664 These problems are set up like the other dataflow problems so that
2665 they nicely fit into the framework. They are much simpler and only
2666 involve a single traversal of instructions and an examination of
2667 the reaching defs information (the dependent problem).
2668 ----------------------------------------------------------------------------*/
2670 struct df_chain_problem_data
2676 /* Create def-use or use-def chains. */
2679 df_chain_alloc (struct dataflow
*dflow
,
2680 bitmap blocks_to_rescan ATTRIBUTE_UNUSED
)
2682 struct df
*df
= dflow
->df
;
2684 struct df_chain_problem_data
*problem_data
=
2685 (struct df_chain_problem_data
*) dflow
->problem_data
;
2687 /* Wholesale destruction of the old chains. */
2688 if (dflow
->block_pool
)
2689 free_alloc_pool (dflow
->block_pool
);
2691 dflow
->block_pool
= create_alloc_pool ("df_chain_chain_block pool",
2692 sizeof (struct df_link
), 100);
2694 if (problem_data
->flags
& DF_DU_CHAIN
)
2696 if (!df
->def_info
.refs_organized
)
2697 df_reorganize_refs (&df
->def_info
);
2699 /* Clear out the pointers from the refs. */
2700 for (i
= 0; i
< DF_DEFS_SIZE (df
); i
++)
2702 struct df_ref
*ref
= df
->def_info
.refs
[i
];
2703 DF_REF_CHAIN (ref
) = NULL
;
2707 if (problem_data
->flags
& DF_UD_CHAIN
)
2709 if (!df
->use_info
.refs_organized
)
2710 df_reorganize_refs (&df
->use_info
);
2711 for (i
= 0; i
< DF_USES_SIZE (df
); i
++)
2713 struct df_ref
*ref
= df
->use_info
.refs
[i
];
2714 DF_REF_CHAIN (ref
) = NULL
;
2720 /* Reset all def_use and use_def chains in INSN. */
2723 df_chain_insn_reset (struct dataflow
*dflow
, rtx insn
)
2725 struct df
*df
= dflow
->df
;
2726 struct df_chain_problem_data
*problem_data
=
2727 (struct df_chain_problem_data
*) dflow
->problem_data
;
2728 unsigned int uid
= INSN_UID (insn
);
2729 struct df_insn_info
*insn_info
= NULL
;
2732 if (uid
< df
->insns_size
)
2733 insn_info
= DF_INSN_UID_GET (df
, uid
);
2737 if (problem_data
->flags
& DF_DU_CHAIN
)
2739 ref
= insn_info
->defs
;
2743 ref
= ref
->next_ref
;
2747 if (problem_data
->flags
& DF_UD_CHAIN
)
2749 ref
= insn_info
->uses
;
2753 ref
= ref
->next_ref
;
2760 /* Reset all def_use and use_def chains in basic block. */
2763 df_chain_bb_reset (struct dataflow
*dflow
, unsigned int bb_index
)
2765 struct df
*df
= dflow
->df
;
2766 struct df_chain_problem_data
*problem_data
=
2767 (struct df_chain_problem_data
*) dflow
->problem_data
;
2769 basic_block bb
= BASIC_BLOCK (bb_index
);
2771 /* Some one deleted the basic block out from under us. */
2775 FOR_BB_INSNS (bb
, insn
)
2779 /* Record defs within INSN. */
2780 df_chain_insn_reset (dflow
, insn
);
2784 /* Get rid of any chains in artifical uses or defs. */
2785 if (problem_data
->flags
& DF_DU_CHAIN
)
2788 def
= df_get_artificial_defs (df
, bb_index
);
2792 def
= def
->next_ref
;
2796 if (problem_data
->flags
& DF_UD_CHAIN
)
2799 use
= df_get_artificial_uses (df
, bb_index
);
2803 use
= use
->next_ref
;
2809 /* Reset all of the chains when the set of basic blocks changes. */
2813 df_chain_reset (struct dataflow
*dflow
, bitmap blocks_to_clear
)
2816 unsigned int bb_index
;
2818 EXECUTE_IF_SET_IN_BITMAP (blocks_to_clear
, 0, bb_index
, bi
)
2820 df_chain_bb_reset (dflow
, bb_index
);
2823 free_alloc_pool (dflow
->block_pool
);
2824 dflow
->block_pool
= NULL
;
2828 /* Create the chains for a list of USEs. */
2831 df_chain_create_bb_process_use (struct dataflow
*dflow
,
2832 struct df_chain_problem_data
*problem_data
,
2835 enum df_ref_flags top_flag
)
2837 struct df
*df
= dflow
->df
;
2839 unsigned int def_index
;
2843 /* Do not want to go through this for an uninitialized var. */
2844 unsigned int uregno
= DF_REF_REGNO (use
);
2845 int count
= DF_REG_DEF_GET (df
, uregno
)->n_refs
;
2848 if (top_flag
== (DF_REF_FLAGS (use
) & DF_REF_AT_TOP
))
2850 unsigned int first_index
= DF_REG_DEF_GET (df
, uregno
)->begin
;
2851 unsigned int last_index
= first_index
+ count
- 1;
2853 EXECUTE_IF_SET_IN_BITMAP (local_rd
, first_index
, def_index
, bi
)
2856 if (def_index
> last_index
)
2859 def
= DF_DEFS_GET (df
, def_index
);
2860 if (problem_data
->flags
& DF_DU_CHAIN
)
2861 df_chain_create (dflow
, def
, use
);
2862 if (problem_data
->flags
& DF_UD_CHAIN
)
2863 df_chain_create (dflow
, use
, def
);
2867 use
= use
->next_ref
;
2871 /* Reset the storage pool that the def-use or use-def chains have been
2872 allocated in. We do not need to re adjust the pointers in the refs,
2873 these have already been clean out.*/
2875 /* Create chains from reaching defs bitmaps for basic block BB. */
2877 df_chain_create_bb (struct dataflow
*dflow
,
2878 struct dataflow
*rd_dflow
,
2879 unsigned int bb_index
)
2881 basic_block bb
= BASIC_BLOCK (bb_index
);
2882 struct df_rd_bb_info
*bb_info
= df_rd_get_bb_info (rd_dflow
, bb_index
);
2884 bitmap cpy
= BITMAP_ALLOC (NULL
);
2885 struct df
*df
= dflow
->df
;
2886 struct df_chain_problem_data
*problem_data
=
2887 (struct df_chain_problem_data
*) dflow
->problem_data
;
2890 bitmap_copy (cpy
, bb_info
->in
);
2892 /* Since we are going forwards, process the artificial uses first
2893 then the artificial defs second. */
2896 /* Create the chains for the artificial uses from the EH_USES at the
2897 beginning of the block. */
2898 df_chain_create_bb_process_use (dflow
, problem_data
, cpy
,
2899 df_get_artificial_uses (df
, bb
->index
),
2903 for (def
= df_get_artificial_defs (df
, bb_index
); def
; def
= def
->next_ref
)
2904 if (DF_REF_FLAGS (def
) & DF_REF_AT_TOP
)
2906 unsigned int dregno
= DF_REF_REGNO (def
);
2907 bitmap_clear_range (cpy
,
2908 DF_REG_DEF_GET (df
, dregno
)->begin
,
2909 DF_REG_DEF_GET (df
, dregno
)->n_refs
);
2910 if (! (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
))
2911 bitmap_set_bit (cpy
, DF_REF_ID (def
));
2914 /* Process the regular instructions next. */
2915 FOR_BB_INSNS (bb
, insn
)
2918 unsigned int uid
= INSN_UID (insn
);
2920 if (! INSN_P (insn
))
2923 /* Now scan the uses and link them up with the defs that remain
2924 in the cpy vector. */
2926 df_chain_create_bb_process_use (dflow
, problem_data
, cpy
,
2927 DF_INSN_UID_GET (df
, uid
)->uses
, 0);
2929 /* Since we are going forwards, process the defs second. This
2930 pass only changes the bits in cpy. */
2931 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
2933 unsigned int dregno
= DF_REF_REGNO (def
);
2934 bitmap_clear_range (cpy
,
2935 DF_REG_DEF_GET (df
, dregno
)->begin
,
2936 DF_REG_DEF_GET (df
, dregno
)->n_refs
);
2937 if (! (DF_REF_FLAGS (def
) & DF_REF_CLOBBER
))
2938 bitmap_set_bit (cpy
, DF_REF_ID (def
));
2942 /* Create the chains for the artificial uses of the hard registers
2943 at the end of the block. */
2944 df_chain_create_bb_process_use (dflow
, problem_data
, cpy
,
2945 df_get_artificial_uses (df
, bb
->index
), 0);
2948 /* Create def-use chains from reaching use bitmaps for basic blocks
2952 df_chain_finalize (struct dataflow
*dflow
, bitmap all_blocks
)
2954 unsigned int bb_index
;
2956 struct df
*df
= dflow
->df
;
2957 struct dataflow
*rd_dflow
= df
->problems_by_index
[DF_RD
];
2959 EXECUTE_IF_SET_IN_BITMAP (all_blocks
, 0, bb_index
, bi
)
2961 df_chain_create_bb (dflow
, rd_dflow
, bb_index
);
2966 /* Free all storage associated with the problem. */
2969 df_chain_free (struct dataflow
*dflow
)
2971 free_alloc_pool (dflow
->block_pool
);
2972 free (dflow
->problem_data
);
2977 /* Debugging info. */
2980 df_chains_dump (struct dataflow
*dflow
, FILE *file
)
2982 struct df
*df
= dflow
->df
;
2984 struct df_chain_problem_data
*problem_data
=
2985 (struct df_chain_problem_data
*) dflow
->problem_data
;
2987 if (problem_data
->flags
& DF_DU_CHAIN
)
2989 fprintf (file
, "Def-use chains:\n");
2990 for (j
= 0; j
< df
->def_info
.bitmap_size
; j
++)
2992 struct df_ref
*def
= DF_DEFS_GET (df
, j
);
2995 fprintf (file
, "d%d bb %d luid %d insn %d reg %d ",
2996 j
, DF_REF_BBNO (def
),
2997 DF_INSN_LUID (df
, DF_REF_INSN (def
)),
2998 DF_REF_INSN (def
) ? DF_REF_INSN_UID (def
) : -1,
2999 DF_REF_REGNO (def
));
3000 if (def
->flags
& DF_REF_READ_WRITE
)
3001 fprintf (file
, "read/write ");
3002 df_chain_dump (df
, DF_REF_CHAIN (def
), file
);
3003 fprintf (file
, "\n");
3008 if (problem_data
->flags
& DF_UD_CHAIN
)
3010 fprintf (file
, "Use-def chains:\n");
3011 for (j
= 0; j
< df
->use_info
.bitmap_size
; j
++)
3013 struct df_ref
*use
= DF_USES_GET (df
, j
);
3016 fprintf (file
, "u%d bb %d luid %d insn %d reg %d ",
3017 j
, DF_REF_BBNO (use
),
3019 DF_INSN_LUID (df
, DF_REF_INSN (use
))
3021 DF_REF_INSN (DF_USES_GET (df
, j
)) ?
3022 DF_REF_INSN_UID (DF_USES_GET (df
,j
))
3024 DF_REF_REGNO (use
));
3025 if (use
->flags
& DF_REF_READ_WRITE
)
3026 fprintf (file
, "read/write ");
3027 if (use
->flags
& DF_REF_STRIPPED
)
3028 fprintf (file
, "stripped ");
3029 if (use
->flags
& DF_REF_IN_NOTE
)
3030 fprintf (file
, "note ");
3031 df_chain_dump (df
, DF_REF_CHAIN (use
), file
);
3032 fprintf (file
, "\n");
3039 static struct df_problem problem_CHAIN
=
3041 DF_CHAIN
, /* Problem id. */
3042 DF_NONE
, /* Direction. */
3043 df_chain_alloc
, /* Allocate the problem specific data. */
3044 df_chain_reset
, /* Reset global information. */
3045 NULL
, /* Free basic block info. */
3046 NULL
, /* Local compute function. */
3047 NULL
, /* Init the solution specific data. */
3048 NULL
, /* Iterative solver. */
3049 NULL
, /* Confluence operator 0. */
3050 NULL
, /* Confluence operator n. */
3051 NULL
, /* Transfer function. */
3052 df_chain_finalize
, /* Finalize function. */
3053 df_chain_free
, /* Free all of the problem information. */
3054 df_chains_dump
, /* Debugging. */
3055 &problem_RD
/* Dependent problem. */
3059 /* Create a new DATAFLOW instance and add it to an existing instance
3060 of DF. The returned structure is what is used to get at the
3064 df_chain_add_problem (struct df
*df
, int flags
)
3066 struct df_chain_problem_data
*problem_data
=
3067 XNEW (struct df_chain_problem_data
);
3068 struct dataflow
*dflow
= df_add_problem (df
, &problem_CHAIN
);
3070 dflow
->problem_data
= problem_data
;
3071 problem_data
->flags
= flags
;
3077 /*----------------------------------------------------------------------------
3078 REGISTER INFORMATION
3080 Currently this consists of only lifetime information. But the plan is
3081 to enhance it so that it produces all of the register information needed
3082 by the register allocators.
3083 ----------------------------------------------------------------------------*/
3086 struct df_ri_problem_data
3092 /* Allocate the lifetime information. */
3095 df_ri_alloc (struct dataflow
*dflow
, bitmap blocks_to_rescan ATTRIBUTE_UNUSED
)
3097 struct df_ri_problem_data
*problem_data
=
3098 (struct df_ri_problem_data
*) dflow
->problem_data
;
3100 if (!dflow
->problem_data
)
3102 struct df_ri_problem_data
*problem_data
= XNEW (struct df_ri_problem_data
);
3103 dflow
->problem_data
= problem_data
;
3106 problem_data
->lifetime
= xrealloc (problem_data
->lifetime
,
3107 max_reg_num () *sizeof (int));
3108 memset (problem_data
->lifetime
, 0, max_reg_num () *sizeof (int));
3111 /* Compute register info: lifetime, bb, and number of defs and uses
3112 for basic block BB. */
3115 df_ri_bb_compute (struct dataflow
*dflow
, unsigned int bb_index
, bitmap live
)
3117 struct df
*df
= dflow
->df
;
3118 struct df_ur_bb_info
*bb_info
= df_ur_get_bb_info (dflow
, bb_index
);
3119 struct df_ri_problem_data
*problem_data
=
3120 (struct df_ri_problem_data
*) dflow
->problem_data
;
3121 basic_block bb
= BASIC_BLOCK (bb_index
);
3124 bitmap_copy (live
, bb_info
->out
);
3126 FOR_BB_INSNS_REVERSE (bb
, insn
)
3128 unsigned int uid
= INSN_UID (insn
);
3134 if (! INSN_P (insn
))
3137 for (def
= DF_INSN_UID_GET (df
, uid
)->defs
; def
; def
= def
->next_ref
)
3139 unsigned int dregno
= DF_REF_REGNO (def
);
3141 /* Kill this register. */
3142 bitmap_clear_bit (live
, dregno
);
3145 for (use
= DF_INSN_UID_GET (df
, uid
)->uses
; use
; use
= use
->next_ref
)
3147 unsigned int uregno
= DF_REF_REGNO (use
);
3149 if (!bitmap_bit_p (live
, uregno
))
3151 use
->flags
|= DF_REF_DIES_AFTER_THIS_USE
;
3152 /* This register is now live. */
3153 bitmap_set_bit (live
, uregno
);
3156 use
->flags
&= ~DF_REF_DIES_AFTER_THIS_USE
;
3159 /* Increment lifetimes of all live registers. */
3160 EXECUTE_IF_SET_IN_BITMAP (live
, 0, regno
, bi
)
3162 problem_data
->lifetime
[regno
]++;
3168 /* Compute register info: lifetime, bb, and number of defs and uses. */
3170 df_ri_compute (struct dataflow
*dflow
, bitmap all_blocks ATTRIBUTE_UNUSED
,
3171 bitmap blocks_to_scan
)
3173 unsigned int bb_index
;
3177 live
= BITMAP_ALLOC (NULL
);
3179 EXECUTE_IF_SET_IN_BITMAP (blocks_to_scan
, 0, bb_index
, bi
)
3181 df_ri_bb_compute (dflow
, bb_index
, live
);
3188 /* Free all storage associated with the problem. */
3191 df_ri_free (struct dataflow
*dflow
)
3193 struct df_ri_problem_data
*problem_data
=
3194 (struct df_ri_problem_data
*) dflow
->problem_data
;
3196 free (problem_data
->lifetime
);
3197 free (dflow
->problem_data
);
3202 /* Debugging info. */
3205 df_ri_dump (struct dataflow
*dflow
, FILE *file
)
3207 struct df_ri_problem_data
*problem_data
=
3208 (struct df_ri_problem_data
*) dflow
->problem_data
;
3211 fprintf (file
, "Register info:\n");
3212 for (j
= 0; j
< max_reg_num (); j
++)
3214 fprintf (file
, "reg %d life %d\n", j
, problem_data
->lifetime
[j
]);
3218 /* All of the information associated every instance of the problem. */
3220 static struct df_problem problem_RI
=
3222 DF_RI
, /* Problem id. */
3223 DF_NONE
, /* Direction. */
3224 df_ri_alloc
, /* Allocate the problem specific data. */
3225 NULL
, /* Reset global information. */
3226 NULL
, /* Free basic block info. */
3227 df_ri_compute
, /* Local compute function. */
3228 NULL
, /* Init the solution specific data. */
3229 NULL
, /* Iterative solver. */
3230 NULL
, /* Confluence operator 0. */
3231 NULL
, /* Confluence operator n. */
3232 NULL
, /* Transfer function. */
3233 NULL
, /* Finalize function. */
3234 df_ri_free
, /* Free all of the problem information. */
3235 df_ri_dump
, /* Debugging. */
3236 &problem_UR
/* Dependent problem. */
3240 /* Create a new DATAFLOW instance and add it to an existing instance
3241 of DF. The returned structure is what is used to get at the
3245 df_ri_add_problem (struct df
*df
)
3247 return df_add_problem (df
, &problem_RI
);
3251 /* Return total lifetime (in insns) of REG. */
3253 df_reg_lifetime (struct df
*df
, rtx reg
)
3255 struct dataflow
*dflow
= df
->problems_by_index
[DF_RI
];
3256 struct df_ri_problem_data
*problem_data
=
3257 (struct df_ri_problem_data
*) dflow
->problem_data
;
3258 return problem_data
->lifetime
[REGNO (reg
)];