1 /* Control flow graph manipulation code for GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains low level functions to manipulate the CFG and
23 analyze it. All other modules should not transform the data structure
24 directly and use abstraction instead. The file is supposed to be
25 ordered bottom-up and should not contain any code dependent on a
26 particular intermediate language (RTL or trees).
28 Available functionality:
29 - Initialization/deallocation
30 init_flow, clear_edges
31 - Low level basic block manipulation
32 alloc_block, expunge_block
34 make_edge, make_single_succ_edge, cached_make_edge, remove_edge
35 - Low level edge redirection (without updating instruction chain)
36 redirect_edge_succ, redirect_edge_succ_nodup, redirect_edge_pred
37 - Dumping and debugging
38 dump_flow_info, debug_flow_info, dump_edge_info
39 - Allocation of AUX fields for basic blocks
40 alloc_aux_for_blocks, free_aux_for_blocks, alloc_aux_for_block
42 - Consistency checking
44 - Dumping and debugging
45 print_rtl_with_bb, dump_bb, debug_bb, debug_bb_n
47 TODO: Document these "Available functionality" functions in the files
53 #include "coretypes.h"
57 #include "alloc-pool.h"
58 #include "basic-block.h"
60 #include "cfgloop.h" /* FIXME: For struct loop. */
63 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
65 /* Called once at initialization time. */
68 init_flow (struct function
*the_fun
)
71 the_fun
->cfg
= ggc_alloc_cleared_control_flow_graph ();
72 n_edges_for_function (the_fun
) = 0;
73 ENTRY_BLOCK_PTR_FOR_FUNCTION (the_fun
)
74 = ggc_alloc_cleared_basic_block_def ();
75 ENTRY_BLOCK_PTR_FOR_FUNCTION (the_fun
)->index
= ENTRY_BLOCK
;
76 EXIT_BLOCK_PTR_FOR_FUNCTION (the_fun
)
77 = ggc_alloc_cleared_basic_block_def ();
78 EXIT_BLOCK_PTR_FOR_FUNCTION (the_fun
)->index
= EXIT_BLOCK
;
79 ENTRY_BLOCK_PTR_FOR_FUNCTION (the_fun
)->next_bb
80 = EXIT_BLOCK_PTR_FOR_FUNCTION (the_fun
);
81 EXIT_BLOCK_PTR_FOR_FUNCTION (the_fun
)->prev_bb
82 = ENTRY_BLOCK_PTR_FOR_FUNCTION (the_fun
);
85 /* Helper function for remove_edge and clear_edges. Frees edge structure
86 without actually removing it from the pred/succ arrays. */
95 /* Free the memory associated with the edge structures. */
106 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
108 VEC_truncate (edge
, bb
->succs
, 0);
109 VEC_truncate (edge
, bb
->preds
, 0);
112 FOR_EACH_EDGE (e
, ei
, ENTRY_BLOCK_PTR
->succs
)
114 VEC_truncate (edge
, EXIT_BLOCK_PTR
->preds
, 0);
115 VEC_truncate (edge
, ENTRY_BLOCK_PTR
->succs
, 0);
117 gcc_assert (!n_edges
);
120 /* Allocate memory for basic_block. */
126 bb
= ggc_alloc_cleared_basic_block_def ();
130 /* Link block B to chain after AFTER. */
132 link_block (basic_block b
, basic_block after
)
134 b
->next_bb
= after
->next_bb
;
137 b
->next_bb
->prev_bb
= b
;
140 /* Unlink block B from chain. */
142 unlink_block (basic_block b
)
144 b
->next_bb
->prev_bb
= b
->prev_bb
;
145 b
->prev_bb
->next_bb
= b
->next_bb
;
150 /* Sequentially order blocks and compact the arrays. */
152 compact_blocks (void)
156 SET_BASIC_BLOCK (ENTRY_BLOCK
, ENTRY_BLOCK_PTR
);
157 SET_BASIC_BLOCK (EXIT_BLOCK
, EXIT_BLOCK_PTR
);
160 df_compact_blocks ();
165 i
= NUM_FIXED_BLOCKS
;
168 SET_BASIC_BLOCK (i
, bb
);
172 gcc_assert (i
== n_basic_blocks
);
174 for (; i
< last_basic_block
; i
++)
175 SET_BASIC_BLOCK (i
, NULL
);
177 last_basic_block
= n_basic_blocks
;
180 /* Remove block B from the basic block array. */
183 expunge_block (basic_block b
)
186 SET_BASIC_BLOCK (b
->index
, NULL
);
188 /* We should be able to ggc_free here, but we are not.
189 The dead SSA_NAMES are left pointing to dead statements that are pointing
190 to dead basic blocks making garbage collector to die.
191 We should be able to release all dead SSA_NAMES and at the same time we should
192 clear out BB pointer of dead statements consistently. */
195 /* Connect E to E->src. */
200 VEC_safe_push (edge
, gc
, e
->src
->succs
, e
);
201 df_mark_solutions_dirty ();
204 /* Connect E to E->dest. */
207 connect_dest (edge e
)
209 basic_block dest
= e
->dest
;
210 VEC_safe_push (edge
, gc
, dest
->preds
, e
);
211 e
->dest_idx
= EDGE_COUNT (dest
->preds
) - 1;
212 df_mark_solutions_dirty ();
215 /* Disconnect edge E from E->src. */
218 disconnect_src (edge e
)
220 basic_block src
= e
->src
;
224 for (ei
= ei_start (src
->succs
); (tmp
= ei_safe_edge (ei
)); )
228 VEC_unordered_remove (edge
, src
->succs
, ei
.index
);
229 df_mark_solutions_dirty ();
239 /* Disconnect edge E from E->dest. */
242 disconnect_dest (edge e
)
244 basic_block dest
= e
->dest
;
245 unsigned int dest_idx
= e
->dest_idx
;
247 VEC_unordered_remove (edge
, dest
->preds
, dest_idx
);
249 /* If we removed an edge in the middle of the edge vector, we need
250 to update dest_idx of the edge that moved into the "hole". */
251 if (dest_idx
< EDGE_COUNT (dest
->preds
))
252 EDGE_PRED (dest
, dest_idx
)->dest_idx
= dest_idx
;
253 df_mark_solutions_dirty ();
256 /* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
257 created edge. Use this only if you are sure that this edge can't
258 possibly already exist. */
261 unchecked_make_edge (basic_block src
, basic_block dst
, int flags
)
264 e
= ggc_alloc_cleared_edge_def ();
274 execute_on_growing_pred (e
);
278 /* Create an edge connecting SRC and DST with FLAGS optionally using
279 edge cache CACHE. Return the new edge, NULL if already exist. */
282 cached_make_edge (sbitmap edge_cache
, basic_block src
, basic_block dst
, int flags
)
284 if (edge_cache
== NULL
285 || src
== ENTRY_BLOCK_PTR
286 || dst
== EXIT_BLOCK_PTR
)
287 return make_edge (src
, dst
, flags
);
289 /* Does the requested edge already exist? */
290 if (! TEST_BIT (edge_cache
, dst
->index
))
292 /* The edge does not exist. Create one and update the
294 SET_BIT (edge_cache
, dst
->index
);
295 return unchecked_make_edge (src
, dst
, flags
);
298 /* At this point, we know that the requested edge exists. Adjust
299 flags if necessary. */
302 edge e
= find_edge (src
, dst
);
309 /* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
310 created edge or NULL if already exist. */
313 make_edge (basic_block src
, basic_block dest
, int flags
)
315 edge e
= find_edge (src
, dest
);
317 /* Make sure we don't add duplicate edges. */
324 return unchecked_make_edge (src
, dest
, flags
);
327 /* Create an edge connecting SRC to DEST and set probability by knowing
328 that it is the single edge leaving SRC. */
331 make_single_succ_edge (basic_block src
, basic_block dest
, int flags
)
333 edge e
= make_edge (src
, dest
, flags
);
335 e
->probability
= REG_BR_PROB_BASE
;
336 e
->count
= src
->count
;
340 /* This function will remove an edge from the flow graph. */
343 remove_edge_raw (edge e
)
345 remove_predictions_associated_with_edge (e
);
346 execute_on_shrinking_pred (e
);
354 /* Redirect an edge's successor from one block to another. */
357 redirect_edge_succ (edge e
, basic_block new_succ
)
359 execute_on_shrinking_pred (e
);
365 /* Reconnect the edge to the new successor block. */
368 execute_on_growing_pred (e
);
371 /* Redirect an edge's predecessor from one block to another. */
374 redirect_edge_pred (edge e
, basic_block new_pred
)
380 /* Reconnect the edge to the new predecessor block. */
384 /* Clear all basic block flags, with the exception of partitioning and
387 clear_bb_flags (void)
391 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, NULL
, next_bb
)
392 bb
->flags
= (BB_PARTITION (bb
)
393 | (bb
->flags
& (BB_DISABLE_SCHEDULE
+ BB_RTL
+ BB_NON_LOCAL_GOTO_TARGET
)));
396 /* Check the consistency of profile information. We can't do that
397 in verify_flow_info, as the counts may get invalid for incompletely
398 solved graphs, later eliminating of conditionals or roundoff errors.
399 It is still practical to have them reported for debugging of simple
402 check_bb_profile (basic_block bb
, FILE * file
)
409 if (profile_status
== PROFILE_ABSENT
)
412 if (bb
!= EXIT_BLOCK_PTR
)
414 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
415 sum
+= e
->probability
;
416 if (EDGE_COUNT (bb
->succs
) && abs (sum
- REG_BR_PROB_BASE
) > 100)
417 fprintf (file
, "Invalid sum of outgoing probabilities %.1f%%\n",
418 sum
* 100.0 / REG_BR_PROB_BASE
);
420 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
422 if (EDGE_COUNT (bb
->succs
)
423 && (lsum
- bb
->count
> 100 || lsum
- bb
->count
< -100))
424 fprintf (file
, "Invalid sum of outgoing counts %i, should be %i\n",
425 (int) lsum
, (int) bb
->count
);
427 if (bb
!= ENTRY_BLOCK_PTR
)
430 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
431 sum
+= EDGE_FREQUENCY (e
);
432 if (abs (sum
- bb
->frequency
) > 100)
434 "Invalid sum of incoming frequencies %i, should be %i\n",
437 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
439 if (lsum
- bb
->count
> 100 || lsum
- bb
->count
< -100)
440 fprintf (file
, "Invalid sum of incoming counts %i, should be %i\n",
441 (int) lsum
, (int) bb
->count
);
446 dump_edge_info (FILE *file
, edge e
, int do_succ
)
448 basic_block side
= (do_succ
? e
->dest
: e
->src
);
449 /* ENTRY_BLOCK_PTR/EXIT_BLOCK_PTR depend on cfun.
450 Compare against ENTRY_BLOCK/EXIT_BLOCK to avoid that dependency. */
451 if (side
->index
== ENTRY_BLOCK
)
452 fputs (" ENTRY", file
);
453 else if (side
->index
== EXIT_BLOCK
)
454 fputs (" EXIT", file
);
456 fprintf (file
, " %d", side
->index
);
459 fprintf (file
, " [%.1f%%] ", e
->probability
* 100.0 / REG_BR_PROB_BASE
);
463 fputs (" count:", file
);
464 fprintf (file
, HOST_WIDEST_INT_PRINT_DEC
, e
->count
);
469 static const char * const bitnames
[] = {
470 "fallthru", "ab", "abcall", "eh", "fake", "dfs_back",
471 "can_fallthru", "irreducible", "sibcall", "loop_exit",
472 "true", "false", "exec", "crossing", "preserve"
475 int i
, flags
= e
->flags
;
478 for (i
= 0; flags
; i
++)
479 if (flags
& (1 << i
))
485 if (i
< (int) ARRAY_SIZE (bitnames
))
486 fputs (bitnames
[i
], file
);
488 fprintf (file
, "%d", i
);
496 /* Simple routines to easily allocate AUX fields of basic blocks. */
498 static struct obstack block_aux_obstack
;
499 static void *first_block_aux_obj
= 0;
500 static struct obstack edge_aux_obstack
;
501 static void *first_edge_aux_obj
= 0;
503 /* Allocate a memory block of SIZE as BB->aux. The obstack must
504 be first initialized by alloc_aux_for_blocks. */
507 alloc_aux_for_block (basic_block bb
, int size
)
509 /* Verify that aux field is clear. */
510 gcc_assert (!bb
->aux
&& first_block_aux_obj
);
511 bb
->aux
= obstack_alloc (&block_aux_obstack
, size
);
512 memset (bb
->aux
, 0, size
);
515 /* Initialize the block_aux_obstack and if SIZE is nonzero, call
516 alloc_aux_for_block for each basic block. */
519 alloc_aux_for_blocks (int size
)
521 static int initialized
;
525 gcc_obstack_init (&block_aux_obstack
);
529 /* Check whether AUX data are still allocated. */
530 gcc_assert (!first_block_aux_obj
);
532 first_block_aux_obj
= obstack_alloc (&block_aux_obstack
, 0);
538 alloc_aux_for_block (bb
, size
);
542 /* Clear AUX pointers of all blocks. */
545 clear_aux_for_blocks (void)
553 /* Free data allocated in block_aux_obstack and clear AUX pointers
557 free_aux_for_blocks (void)
559 gcc_assert (first_block_aux_obj
);
560 obstack_free (&block_aux_obstack
, first_block_aux_obj
);
561 first_block_aux_obj
= NULL
;
563 clear_aux_for_blocks ();
566 /* Allocate a memory edge of SIZE as E->aux. The obstack must
567 be first initialized by alloc_aux_for_edges. */
570 alloc_aux_for_edge (edge e
, int size
)
572 /* Verify that aux field is clear. */
573 gcc_assert (!e
->aux
&& first_edge_aux_obj
);
574 e
->aux
= obstack_alloc (&edge_aux_obstack
, size
);
575 memset (e
->aux
, 0, size
);
578 /* Initialize the edge_aux_obstack and if SIZE is nonzero, call
579 alloc_aux_for_edge for each basic edge. */
582 alloc_aux_for_edges (int size
)
584 static int initialized
;
588 gcc_obstack_init (&edge_aux_obstack
);
592 /* Check whether AUX data are still allocated. */
593 gcc_assert (!first_edge_aux_obj
);
595 first_edge_aux_obj
= obstack_alloc (&edge_aux_obstack
, 0);
600 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, EXIT_BLOCK_PTR
, next_bb
)
605 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
606 alloc_aux_for_edge (e
, size
);
611 /* Clear AUX pointers of all edges. */
614 clear_aux_for_edges (void)
619 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, EXIT_BLOCK_PTR
, next_bb
)
622 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
627 /* Free data allocated in edge_aux_obstack and clear AUX pointers
631 free_aux_for_edges (void)
633 gcc_assert (first_edge_aux_obj
);
634 obstack_free (&edge_aux_obstack
, first_edge_aux_obj
);
635 first_edge_aux_obj
= NULL
;
637 clear_aux_for_edges ();
641 debug_bb (basic_block bb
)
643 dump_bb (bb
, stderr
, 0);
646 DEBUG_FUNCTION basic_block
649 basic_block bb
= BASIC_BLOCK (n
);
650 dump_bb (bb
, stderr
, 0);
654 /* Dumps cfg related information about basic block BB to FILE. */
657 dump_cfg_bb_info (FILE *file
, basic_block bb
)
662 static const char * const bb_bitnames
[] =
664 "new", "reachable", "irreducible_loop", "superblock",
665 "nosched", "hot", "cold", "dup", "xlabel", "rtl",
668 const unsigned n_bitnames
= sizeof (bb_bitnames
) / sizeof (char *);
671 fprintf (file
, "Basic block %d", bb
->index
);
672 for (i
= 0; i
< n_bitnames
; i
++)
673 if (bb
->flags
& (1 << i
))
680 fputs (bb_bitnames
[i
], file
);
686 fputs ("Predecessors: ", file
);
687 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
688 dump_edge_info (file
, e
, 0);
690 fprintf (file
, "\nSuccessors: ");
691 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
692 dump_edge_info (file
, e
, 1);
693 fputs ("\n\n", file
);
696 /* Dumps a brief description of cfg to FILE. */
699 brief_dump_cfg (FILE *file
)
705 dump_cfg_bb_info (file
, bb
);
709 /* An edge originally destinating BB of FREQUENCY and COUNT has been proved to
710 leave the block by TAKEN_EDGE. Update profile of BB such that edge E can be
711 redirected to destination of TAKEN_EDGE.
713 This function may leave the profile inconsistent in the case TAKEN_EDGE
714 frequency or count is believed to be lower than FREQUENCY or COUNT
717 update_bb_profile_for_threading (basic_block bb
, int edge_frequency
,
718 gcov_type count
, edge taken_edge
)
728 fprintf (dump_file
, "bb %i count became negative after threading",
733 /* Compute the probability of TAKEN_EDGE being reached via threaded edge.
734 Watch for overflows. */
736 prob
= edge_frequency
* REG_BR_PROB_BASE
/ bb
->frequency
;
739 if (prob
> taken_edge
->probability
)
742 fprintf (dump_file
, "Jump threading proved probability of edge "
743 "%i->%i too small (it is %i, should be %i).\n",
744 taken_edge
->src
->index
, taken_edge
->dest
->index
,
745 taken_edge
->probability
, prob
);
746 prob
= taken_edge
->probability
;
749 /* Now rescale the probabilities. */
750 taken_edge
->probability
-= prob
;
751 prob
= REG_BR_PROB_BASE
- prob
;
752 bb
->frequency
-= edge_frequency
;
753 if (bb
->frequency
< 0)
758 fprintf (dump_file
, "Edge frequencies of bb %i has been reset, "
759 "frequency of block should end up being 0, it is %i\n",
760 bb
->index
, bb
->frequency
);
761 EDGE_SUCC (bb
, 0)->probability
= REG_BR_PROB_BASE
;
762 ei
= ei_start (bb
->succs
);
764 for (; (c
= ei_safe_edge (ei
)); ei_next (&ei
))
767 else if (prob
!= REG_BR_PROB_BASE
)
769 int scale
= RDIV (65536 * REG_BR_PROB_BASE
, prob
);
771 FOR_EACH_EDGE (c
, ei
, bb
->succs
)
773 /* Protect from overflow due to additional scaling. */
774 if (c
->probability
> prob
)
775 c
->probability
= REG_BR_PROB_BASE
;
778 c
->probability
= RDIV (c
->probability
* scale
, 65536);
779 if (c
->probability
> REG_BR_PROB_BASE
)
780 c
->probability
= REG_BR_PROB_BASE
;
785 gcc_assert (bb
== taken_edge
->src
);
786 taken_edge
->count
-= count
;
787 if (taken_edge
->count
< 0)
790 fprintf (dump_file
, "edge %i->%i count became negative after threading",
791 taken_edge
->src
->index
, taken_edge
->dest
->index
);
792 taken_edge
->count
= 0;
796 /* Multiply all frequencies of basic blocks in array BBS of length NBBS
797 by NUM/DEN, in int arithmetic. May lose some accuracy. */
799 scale_bbs_frequencies_int (basic_block
*bbs
, int nbbs
, int num
, int den
)
806 /* Scale NUM and DEN to avoid overflows. Frequencies are in order of
807 10^4, if we make DEN <= 10^3, we can afford to upscale by 100
808 and still safely fit in int during calculations. */
814 num
= RDIV (1000 * num
, den
);
820 for (i
= 0; i
< nbbs
; i
++)
823 bbs
[i
]->frequency
= RDIV (bbs
[i
]->frequency
* num
, den
);
824 /* Make sure the frequencies do not grow over BB_FREQ_MAX. */
825 if (bbs
[i
]->frequency
> BB_FREQ_MAX
)
826 bbs
[i
]->frequency
= BB_FREQ_MAX
;
827 bbs
[i
]->count
= RDIV (bbs
[i
]->count
* num
, den
);
828 FOR_EACH_EDGE (e
, ei
, bbs
[i
]->succs
)
829 e
->count
= RDIV (e
->count
* num
, den
);
833 /* numbers smaller than this value are safe to multiply without getting
835 #define MAX_SAFE_MULTIPLIER (1 << (sizeof (HOST_WIDEST_INT) * 4 - 1))
837 /* Multiply all frequencies of basic blocks in array BBS of length NBBS
838 by NUM/DEN, in gcov_type arithmetic. More accurate than previous
839 function but considerably slower. */
841 scale_bbs_frequencies_gcov_type (basic_block
*bbs
, int nbbs
, gcov_type num
,
846 gcov_type fraction
= RDIV (num
* 65536, den
);
848 gcc_assert (fraction
>= 0);
850 if (num
< MAX_SAFE_MULTIPLIER
)
851 for (i
= 0; i
< nbbs
; i
++)
854 bbs
[i
]->frequency
= RDIV (bbs
[i
]->frequency
* num
, den
);
855 if (bbs
[i
]->count
<= MAX_SAFE_MULTIPLIER
)
856 bbs
[i
]->count
= RDIV (bbs
[i
]->count
* num
, den
);
858 bbs
[i
]->count
= RDIV (bbs
[i
]->count
* fraction
, 65536);
859 FOR_EACH_EDGE (e
, ei
, bbs
[i
]->succs
)
860 if (bbs
[i
]->count
<= MAX_SAFE_MULTIPLIER
)
861 e
->count
= RDIV (e
->count
* num
, den
);
863 e
->count
= RDIV (e
->count
* fraction
, 65536);
866 for (i
= 0; i
< nbbs
; i
++)
869 if (sizeof (gcov_type
) > sizeof (int))
870 bbs
[i
]->frequency
= RDIV (bbs
[i
]->frequency
* num
, den
);
872 bbs
[i
]->frequency
= RDIV (bbs
[i
]->frequency
* fraction
, 65536);
873 bbs
[i
]->count
= RDIV (bbs
[i
]->count
* fraction
, 65536);
874 FOR_EACH_EDGE (e
, ei
, bbs
[i
]->succs
)
875 e
->count
= RDIV (e
->count
* fraction
, 65536);
879 /* Data structures used to maintain mapping between basic blocks and
881 static htab_t bb_original
;
882 static htab_t bb_copy
;
884 /* And between loops and copies. */
885 static htab_t loop_copy
;
886 static alloc_pool original_copy_bb_pool
;
888 struct htab_bb_copy_original_entry
890 /* Block we are attaching info to. */
892 /* Index of original or copy (depending on the hashtable) */
897 bb_copy_original_hash (const void *p
)
899 const struct htab_bb_copy_original_entry
*data
900 = ((const struct htab_bb_copy_original_entry
*)p
);
905 bb_copy_original_eq (const void *p
, const void *q
)
907 const struct htab_bb_copy_original_entry
*data
908 = ((const struct htab_bb_copy_original_entry
*)p
);
909 const struct htab_bb_copy_original_entry
*data2
910 = ((const struct htab_bb_copy_original_entry
*)q
);
912 return data
->index1
== data2
->index1
;
915 /* Initialize the data structures to maintain mapping between blocks
918 initialize_original_copy_tables (void)
920 gcc_assert (!original_copy_bb_pool
);
921 original_copy_bb_pool
922 = create_alloc_pool ("original_copy",
923 sizeof (struct htab_bb_copy_original_entry
), 10);
924 bb_original
= htab_create (10, bb_copy_original_hash
,
925 bb_copy_original_eq
, NULL
);
926 bb_copy
= htab_create (10, bb_copy_original_hash
, bb_copy_original_eq
, NULL
);
927 loop_copy
= htab_create (10, bb_copy_original_hash
, bb_copy_original_eq
, NULL
);
930 /* Free the data structures to maintain mapping between blocks and
933 free_original_copy_tables (void)
935 gcc_assert (original_copy_bb_pool
);
936 htab_delete (bb_copy
);
937 htab_delete (bb_original
);
938 htab_delete (loop_copy
);
939 free_alloc_pool (original_copy_bb_pool
);
943 original_copy_bb_pool
= NULL
;
946 /* Removes the value associated with OBJ from table TAB. */
949 copy_original_table_clear (htab_t tab
, unsigned obj
)
952 struct htab_bb_copy_original_entry key
, *elt
;
954 if (!original_copy_bb_pool
)
958 slot
= htab_find_slot (tab
, &key
, NO_INSERT
);
962 elt
= (struct htab_bb_copy_original_entry
*) *slot
;
963 htab_clear_slot (tab
, slot
);
964 pool_free (original_copy_bb_pool
, elt
);
967 /* Sets the value associated with OBJ in table TAB to VAL.
968 Do nothing when data structures are not initialized. */
971 copy_original_table_set (htab_t tab
, unsigned obj
, unsigned val
)
973 struct htab_bb_copy_original_entry
**slot
;
974 struct htab_bb_copy_original_entry key
;
976 if (!original_copy_bb_pool
)
980 slot
= (struct htab_bb_copy_original_entry
**)
981 htab_find_slot (tab
, &key
, INSERT
);
984 *slot
= (struct htab_bb_copy_original_entry
*)
985 pool_alloc (original_copy_bb_pool
);
986 (*slot
)->index1
= obj
;
988 (*slot
)->index2
= val
;
991 /* Set original for basic block. Do nothing when data structures are not
992 initialized so passes not needing this don't need to care. */
994 set_bb_original (basic_block bb
, basic_block original
)
996 copy_original_table_set (bb_original
, bb
->index
, original
->index
);
999 /* Get the original basic block. */
1001 get_bb_original (basic_block bb
)
1003 struct htab_bb_copy_original_entry
*entry
;
1004 struct htab_bb_copy_original_entry key
;
1006 gcc_assert (original_copy_bb_pool
);
1008 key
.index1
= bb
->index
;
1009 entry
= (struct htab_bb_copy_original_entry
*) htab_find (bb_original
, &key
);
1011 return BASIC_BLOCK (entry
->index2
);
1016 /* Set copy for basic block. Do nothing when data structures are not
1017 initialized so passes not needing this don't need to care. */
1019 set_bb_copy (basic_block bb
, basic_block copy
)
1021 copy_original_table_set (bb_copy
, bb
->index
, copy
->index
);
1024 /* Get the copy of basic block. */
1026 get_bb_copy (basic_block bb
)
1028 struct htab_bb_copy_original_entry
*entry
;
1029 struct htab_bb_copy_original_entry key
;
1031 gcc_assert (original_copy_bb_pool
);
1033 key
.index1
= bb
->index
;
1034 entry
= (struct htab_bb_copy_original_entry
*) htab_find (bb_copy
, &key
);
1036 return BASIC_BLOCK (entry
->index2
);
1041 /* Set copy for LOOP to COPY. Do nothing when data structures are not
1042 initialized so passes not needing this don't need to care. */
1045 set_loop_copy (struct loop
*loop
, struct loop
*copy
)
1048 copy_original_table_clear (loop_copy
, loop
->num
);
1050 copy_original_table_set (loop_copy
, loop
->num
, copy
->num
);
1053 /* Get the copy of LOOP. */
1056 get_loop_copy (struct loop
*loop
)
1058 struct htab_bb_copy_original_entry
*entry
;
1059 struct htab_bb_copy_original_entry key
;
1061 gcc_assert (original_copy_bb_pool
);
1063 key
.index1
= loop
->num
;
1064 entry
= (struct htab_bb_copy_original_entry
*) htab_find (loop_copy
, &key
);
1066 return get_loop (entry
->index2
);