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
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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* This file contains low level functions to manipulate the CFG and
24 analyze it. All other modules should not transform the data structure
25 directly and use abstraction instead. The file is supposed to be
26 ordered bottom-up and should not contain any code dependent on a
27 particular intermediate language (RTL or trees).
29 Available functionality:
30 - Initialization/deallocation
31 init_flow, clear_edges
32 - Low level basic block manipulation
33 alloc_block, expunge_block
35 make_edge, make_single_succ_edge, cached_make_edge, remove_edge
36 - Low level edge redirection (without updating instruction chain)
37 redirect_edge_succ, redirect_edge_succ_nodup, redirect_edge_pred
38 - Dumping and debugging
39 dump_flow_info, debug_flow_info, dump_edge_info
40 - Allocation of AUX fields for basic blocks
41 alloc_aux_for_blocks, free_aux_for_blocks, alloc_aux_for_block
43 - Consistency checking
45 - Dumping and debugging
46 print_rtl_with_bb, dump_bb, debug_bb, debug_bb_n
51 #include "coretypes.h"
55 #include "hard-reg-set.h"
67 #include "alloc-pool.h"
69 /* The obstack on which the flow graph components are allocated. */
71 struct bitmap_obstack reg_obstack;
73 void debug_flow_info (void);
74 static void free_edge (edge);
76 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
78 /* Called once at initialization time. */
84 cfun->cfg = ggc_alloc_cleared (sizeof (struct control_flow_graph));
86 ENTRY_BLOCK_PTR = ggc_alloc_cleared (sizeof (struct basic_block_def));
87 ENTRY_BLOCK_PTR->index = ENTRY_BLOCK;
88 EXIT_BLOCK_PTR = ggc_alloc_cleared (sizeof (struct basic_block_def));
89 EXIT_BLOCK_PTR->index = EXIT_BLOCK;
90 ENTRY_BLOCK_PTR->next_bb = EXIT_BLOCK_PTR;
91 EXIT_BLOCK_PTR->prev_bb = ENTRY_BLOCK_PTR;
94 /* Helper function for remove_edge and clear_edges. Frees edge structure
95 without actually unlinking it from the pred/succ lists. */
98 free_edge (edge e ATTRIBUTE_UNUSED)
104 /* Free the memory associated with the edge structures. */
115 FOR_EACH_EDGE (e, ei, bb->succs)
117 VEC_truncate (edge, bb->succs, 0);
118 VEC_truncate (edge, bb->preds, 0);
121 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
123 VEC_truncate (edge, EXIT_BLOCK_PTR->preds, 0);
124 VEC_truncate (edge, ENTRY_BLOCK_PTR->succs, 0);
126 gcc_assert (!n_edges);
129 /* Allocate memory for basic_block. */
135 bb = ggc_alloc_cleared (sizeof (*bb));
139 /* Initialize rbi (the structure containing data used by basic block
140 duplication and reordering) for the given basic block. */
143 initialize_bb_rbi (basic_block bb)
145 gcc_assert (!bb->rbi);
146 bb->rbi = ggc_alloc_cleared (sizeof (struct reorder_block_def));
149 /* Link block B to chain after AFTER. */
151 link_block (basic_block b, basic_block after)
153 b->next_bb = after->next_bb;
156 b->next_bb->prev_bb = b;
159 /* Unlink block B from chain. */
161 unlink_block (basic_block b)
163 b->next_bb->prev_bb = b->prev_bb;
164 b->prev_bb->next_bb = b->next_bb;
169 /* Sequentially order blocks and compact the arrays. */
171 compact_blocks (void)
179 BASIC_BLOCK (i) = bb;
184 gcc_assert (i == n_basic_blocks);
186 for (; i < last_basic_block; i++)
187 BASIC_BLOCK (i) = NULL;
189 last_basic_block = n_basic_blocks;
192 /* Remove block B from the basic block array. */
195 expunge_block (basic_block b)
198 BASIC_BLOCK (b->index) = NULL;
200 /* We should be able to ggc_free here, but we are not.
201 The dead SSA_NAMES are left pointing to dead statements that are pointing
202 to dead basic blocks making garbage collector to die.
203 We should be able to release all dead SSA_NAMES and at the same time we should
204 clear out BB pointer of dead statements consistently. */
207 /* Connect E to E->src. */
212 VEC_safe_push (edge, gc, e->src->succs, e);
215 /* Connect E to E->dest. */
218 connect_dest (edge e)
220 basic_block dest = e->dest;
221 VEC_safe_push (edge, gc, dest->preds, e);
222 e->dest_idx = EDGE_COUNT (dest->preds) - 1;
225 /* Disconnect edge E from E->src. */
228 disconnect_src (edge e)
230 basic_block src = e->src;
234 for (ei = ei_start (src->succs); (tmp = ei_safe_edge (ei)); )
238 VEC_unordered_remove (edge, src->succs, ei.index);
248 /* Disconnect edge E from E->dest. */
251 disconnect_dest (edge e)
253 basic_block dest = e->dest;
254 unsigned int dest_idx = e->dest_idx;
256 VEC_unordered_remove (edge, dest->preds, dest_idx);
258 /* If we removed an edge in the middle of the edge vector, we need
259 to update dest_idx of the edge that moved into the "hole". */
260 if (dest_idx < EDGE_COUNT (dest->preds))
261 EDGE_PRED (dest, dest_idx)->dest_idx = dest_idx;
264 /* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
265 created edge. Use this only if you are sure that this edge can't
266 possibly already exist. */
269 unchecked_make_edge (basic_block src, basic_block dst, int flags)
272 e = ggc_alloc_cleared (sizeof (*e));
282 execute_on_growing_pred (e);
287 /* Create an edge connecting SRC and DST with FLAGS optionally using
288 edge cache CACHE. Return the new edge, NULL if already exist. */
291 cached_make_edge (sbitmap edge_cache, basic_block src, basic_block dst, int flags)
293 if (edge_cache == NULL
294 || src == ENTRY_BLOCK_PTR
295 || dst == EXIT_BLOCK_PTR)
296 return make_edge (src, dst, flags);
298 /* Does the requested edge already exist? */
299 if (! TEST_BIT (edge_cache, dst->index))
301 /* The edge does not exist. Create one and update the
303 SET_BIT (edge_cache, dst->index);
304 return unchecked_make_edge (src, dst, flags);
307 /* At this point, we know that the requested edge exists. Adjust
308 flags if necessary. */
311 edge e = find_edge (src, dst);
318 /* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
319 created edge or NULL if already exist. */
322 make_edge (basic_block src, basic_block dest, int flags)
324 edge e = find_edge (src, dest);
326 /* Make sure we don't add duplicate edges. */
333 return unchecked_make_edge (src, dest, flags);
336 /* Create an edge connecting SRC to DEST and set probability by knowing
337 that it is the single edge leaving SRC. */
340 make_single_succ_edge (basic_block src, basic_block dest, int flags)
342 edge e = make_edge (src, dest, flags);
344 e->probability = REG_BR_PROB_BASE;
345 e->count = src->count;
349 /* This function will remove an edge from the flow graph. */
354 remove_predictions_associated_with_edge (e);
355 execute_on_shrinking_pred (e);
363 /* Redirect an edge's successor from one block to another. */
366 redirect_edge_succ (edge e, basic_block new_succ)
368 execute_on_shrinking_pred (e);
374 /* Reconnect the edge to the new successor block. */
377 execute_on_growing_pred (e);
380 /* Like previous but avoid possible duplicate edge. */
383 redirect_edge_succ_nodup (edge e, basic_block new_succ)
387 s = find_edge (e->src, new_succ);
390 s->flags |= e->flags;
391 s->probability += e->probability;
392 if (s->probability > REG_BR_PROB_BASE)
393 s->probability = REG_BR_PROB_BASE;
394 s->count += e->count;
399 redirect_edge_succ (e, new_succ);
404 /* Redirect an edge's predecessor from one block to another. */
407 redirect_edge_pred (edge e, basic_block new_pred)
413 /* Reconnect the edge to the new predecessor block. */
417 /* Clear all basic block flags, with the exception of partitioning. */
419 clear_bb_flags (void)
423 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
424 bb->flags = BB_PARTITION (bb) | (bb->flags & BB_DISABLE_SCHEDULE);
427 /* Check the consistency of profile information. We can't do that
428 in verify_flow_info, as the counts may get invalid for incompletely
429 solved graphs, later eliminating of conditionals or roundoff errors.
430 It is still practical to have them reported for debugging of simple
433 check_bb_profile (basic_block bb, FILE * file)
440 if (profile_status == PROFILE_ABSENT)
443 if (bb != EXIT_BLOCK_PTR)
445 FOR_EACH_EDGE (e, ei, bb->succs)
446 sum += e->probability;
447 if (EDGE_COUNT (bb->succs) && abs (sum - REG_BR_PROB_BASE) > 100)
448 fprintf (file, "Invalid sum of outgoing probabilities %.1f%%\n",
449 sum * 100.0 / REG_BR_PROB_BASE);
451 FOR_EACH_EDGE (e, ei, bb->succs)
453 if (EDGE_COUNT (bb->succs)
454 && (lsum - bb->count > 100 || lsum - bb->count < -100))
455 fprintf (file, "Invalid sum of outgoing counts %i, should be %i\n",
456 (int) lsum, (int) bb->count);
458 if (bb != ENTRY_BLOCK_PTR)
461 FOR_EACH_EDGE (e, ei, bb->preds)
462 sum += EDGE_FREQUENCY (e);
463 if (abs (sum - bb->frequency) > 100)
465 "Invalid sum of incoming frequencies %i, should be %i\n",
468 FOR_EACH_EDGE (e, ei, bb->preds)
470 if (lsum - bb->count > 100 || lsum - bb->count < -100)
471 fprintf (file, "Invalid sum of incoming counts %i, should be %i\n",
472 (int) lsum, (int) bb->count);
477 dump_flow_info (FILE *file)
481 /* There are no pseudo registers after reload. Don't dump them. */
482 if (reg_n_info && !reload_completed)
484 unsigned int i, max = max_reg_num ();
485 fprintf (file, "%d registers.\n", max);
486 for (i = FIRST_PSEUDO_REGISTER; i < max; i++)
489 enum reg_class class, altclass;
491 fprintf (file, "\nRegister %d used %d times across %d insns",
492 i, REG_N_REFS (i), REG_LIVE_LENGTH (i));
493 if (REG_BASIC_BLOCK (i) >= 0)
494 fprintf (file, " in block %d", REG_BASIC_BLOCK (i));
496 fprintf (file, "; set %d time%s", REG_N_SETS (i),
497 (REG_N_SETS (i) == 1) ? "" : "s");
498 if (regno_reg_rtx[i] != NULL && REG_USERVAR_P (regno_reg_rtx[i]))
499 fprintf (file, "; user var");
500 if (REG_N_DEATHS (i) != 1)
501 fprintf (file, "; dies in %d places", REG_N_DEATHS (i));
502 if (REG_N_CALLS_CROSSED (i) == 1)
503 fprintf (file, "; crosses 1 call");
504 else if (REG_N_CALLS_CROSSED (i))
505 fprintf (file, "; crosses %d calls", REG_N_CALLS_CROSSED (i));
506 if (regno_reg_rtx[i] != NULL
507 && PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
508 fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
510 class = reg_preferred_class (i);
511 altclass = reg_alternate_class (i);
512 if (class != GENERAL_REGS || altclass != ALL_REGS)
514 if (altclass == ALL_REGS || class == ALL_REGS)
515 fprintf (file, "; pref %s", reg_class_names[(int) class]);
516 else if (altclass == NO_REGS)
517 fprintf (file, "; %s or none", reg_class_names[(int) class]);
519 fprintf (file, "; pref %s, else %s",
520 reg_class_names[(int) class],
521 reg_class_names[(int) altclass]);
524 if (regno_reg_rtx[i] != NULL && REG_POINTER (regno_reg_rtx[i]))
525 fprintf (file, "; pointer");
526 fprintf (file, ".\n");
530 fprintf (file, "\n%d basic blocks, %d edges.\n", n_basic_blocks, n_edges);
536 fprintf (file, "\nBasic block %d ", bb->index);
537 fprintf (file, "prev %d, next %d, ",
538 bb->prev_bb->index, bb->next_bb->index);
539 fprintf (file, "loop_depth %d, count ", bb->loop_depth);
540 fprintf (file, HOST_WIDEST_INT_PRINT_DEC, bb->count);
541 fprintf (file, ", freq %i", bb->frequency);
542 if (maybe_hot_bb_p (bb))
543 fprintf (file, ", maybe hot");
544 if (probably_never_executed_bb_p (bb))
545 fprintf (file, ", probably never executed");
546 fprintf (file, ".\n");
548 fprintf (file, "Predecessors: ");
549 FOR_EACH_EDGE (e, ei, bb->preds)
550 dump_edge_info (file, e, 0);
552 fprintf (file, "\nSuccessors: ");
553 FOR_EACH_EDGE (e, ei, bb->succs)
554 dump_edge_info (file, e, 1);
556 if (bb->global_live_at_start)
558 fprintf (file, "\nRegisters live at start:");
559 dump_regset (bb->global_live_at_start, file);
562 if (bb->global_live_at_end)
564 fprintf (file, "\nRegisters live at end:");
565 dump_regset (bb->global_live_at_end, file);
569 check_bb_profile (bb, file);
576 debug_flow_info (void)
578 dump_flow_info (stderr);
582 dump_edge_info (FILE *file, edge e, int do_succ)
584 basic_block side = (do_succ ? e->dest : e->src);
586 if (side == ENTRY_BLOCK_PTR)
587 fputs (" ENTRY", file);
588 else if (side == EXIT_BLOCK_PTR)
589 fputs (" EXIT", file);
591 fprintf (file, " %d", side->index);
594 fprintf (file, " [%.1f%%] ", e->probability * 100.0 / REG_BR_PROB_BASE);
598 fprintf (file, " count:");
599 fprintf (file, HOST_WIDEST_INT_PRINT_DEC, e->count);
604 static const char * const bitnames[] = {
605 "fallthru", "ab", "abcall", "eh", "fake", "dfs_back",
606 "can_fallthru", "irreducible", "sibcall", "loop_exit",
607 "true", "false", "exec"
610 int i, flags = e->flags;
613 for (i = 0; flags; i++)
614 if (flags & (1 << i))
620 if (i < (int) ARRAY_SIZE (bitnames))
621 fputs (bitnames[i], file);
623 fprintf (file, "%d", i);
631 /* Simple routines to easily allocate AUX fields of basic blocks. */
633 static struct obstack block_aux_obstack;
634 static void *first_block_aux_obj = 0;
635 static struct obstack edge_aux_obstack;
636 static void *first_edge_aux_obj = 0;
638 /* Allocate a memory block of SIZE as BB->aux. The obstack must
639 be first initialized by alloc_aux_for_blocks. */
642 alloc_aux_for_block (basic_block bb, int size)
644 /* Verify that aux field is clear. */
645 gcc_assert (!bb->aux && first_block_aux_obj);
646 bb->aux = obstack_alloc (&block_aux_obstack, size);
647 memset (bb->aux, 0, size);
650 /* Initialize the block_aux_obstack and if SIZE is nonzero, call
651 alloc_aux_for_block for each basic block. */
654 alloc_aux_for_blocks (int size)
656 static int initialized;
660 gcc_obstack_init (&block_aux_obstack);
664 /* Check whether AUX data are still allocated. */
665 gcc_assert (!first_block_aux_obj);
667 first_block_aux_obj = obstack_alloc (&block_aux_obstack, 0);
672 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
673 alloc_aux_for_block (bb, size);
677 /* Clear AUX pointers of all blocks. */
680 clear_aux_for_blocks (void)
684 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
688 /* Free data allocated in block_aux_obstack and clear AUX pointers
692 free_aux_for_blocks (void)
694 gcc_assert (first_block_aux_obj);
695 obstack_free (&block_aux_obstack, first_block_aux_obj);
696 first_block_aux_obj = NULL;
698 clear_aux_for_blocks ();
701 /* Allocate a memory edge of SIZE as BB->aux. The obstack must
702 be first initialized by alloc_aux_for_edges. */
705 alloc_aux_for_edge (edge e, int size)
707 /* Verify that aux field is clear. */
708 gcc_assert (!e->aux && first_edge_aux_obj);
709 e->aux = obstack_alloc (&edge_aux_obstack, size);
710 memset (e->aux, 0, size);
713 /* Initialize the edge_aux_obstack and if SIZE is nonzero, call
714 alloc_aux_for_edge for each basic edge. */
717 alloc_aux_for_edges (int size)
719 static int initialized;
723 gcc_obstack_init (&edge_aux_obstack);
727 /* Check whether AUX data are still allocated. */
728 gcc_assert (!first_edge_aux_obj);
730 first_edge_aux_obj = obstack_alloc (&edge_aux_obstack, 0);
735 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
740 FOR_EACH_EDGE (e, ei, bb->succs)
741 alloc_aux_for_edge (e, size);
746 /* Clear AUX pointers of all edges. */
749 clear_aux_for_edges (void)
754 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
757 FOR_EACH_EDGE (e, ei, bb->succs)
762 /* Free data allocated in edge_aux_obstack and clear AUX pointers
766 free_aux_for_edges (void)
768 gcc_assert (first_edge_aux_obj);
769 obstack_free (&edge_aux_obstack, first_edge_aux_obj);
770 first_edge_aux_obj = NULL;
772 clear_aux_for_edges ();
776 debug_bb (basic_block bb)
778 dump_bb (bb, stderr, 0);
784 basic_block bb = BASIC_BLOCK (n);
785 dump_bb (bb, stderr, 0);
789 /* Dumps cfg related information about basic block BB to FILE. */
792 dump_cfg_bb_info (FILE *file, basic_block bb)
797 static const char * const bb_bitnames[] =
799 "dirty", "new", "reachable", "visited", "irreducible_loop", "superblock"
801 const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
804 fprintf (file, "Basic block %d", bb->index);
805 for (i = 0; i < n_bitnames; i++)
806 if (bb->flags & (1 << i))
809 fprintf (file, " (");
811 fprintf (file, ", ");
813 fprintf (file, bb_bitnames[i]);
817 fprintf (file, "\n");
819 fprintf (file, "Predecessors: ");
820 FOR_EACH_EDGE (e, ei, bb->preds)
821 dump_edge_info (file, e, 0);
823 fprintf (file, "\nSuccessors: ");
824 FOR_EACH_EDGE (e, ei, bb->succs)
825 dump_edge_info (file, e, 1);
826 fprintf (file, "\n\n");
829 /* Dumps a brief description of cfg to FILE. */
832 brief_dump_cfg (FILE *file)
838 dump_cfg_bb_info (file, bb);
842 /* An edge originally destinating BB of FREQUENCY and COUNT has been proved to
843 leave the block by TAKEN_EDGE. Update profile of BB such that edge E can be
844 redirected to destination of TAKEN_EDGE.
846 This function may leave the profile inconsistent in the case TAKEN_EDGE
847 frequency or count is believed to be lower than FREQUENCY or COUNT
850 update_bb_profile_for_threading (basic_block bb, int edge_frequency,
851 gcov_type count, edge taken_edge)
861 /* Compute the probability of TAKEN_EDGE being reached via threaded edge.
862 Watch for overflows. */
864 prob = edge_frequency * REG_BR_PROB_BASE / bb->frequency;
867 if (prob > taken_edge->probability)
870 fprintf (dump_file, "Jump threading proved probability of edge "
871 "%i->%i too small (it is %i, should be %i).\n",
872 taken_edge->src->index, taken_edge->dest->index,
873 taken_edge->probability, prob);
874 prob = taken_edge->probability;
877 /* Now rescale the probabilities. */
878 taken_edge->probability -= prob;
879 prob = REG_BR_PROB_BASE - prob;
880 bb->frequency -= edge_frequency;
881 if (bb->frequency < 0)
886 fprintf (dump_file, "Edge frequencies of bb %i has been reset, "
887 "frequency of block should end up being 0, it is %i\n",
888 bb->index, bb->frequency);
889 EDGE_SUCC (bb, 0)->probability = REG_BR_PROB_BASE;
890 ei = ei_start (bb->succs);
892 for (; (c = ei_safe_edge (ei)); ei_next (&ei))
895 else if (prob != REG_BR_PROB_BASE)
897 int scale = 65536 * REG_BR_PROB_BASE / prob;
899 FOR_EACH_EDGE (c, ei, bb->succs)
900 c->probability *= scale / 65536;
903 gcc_assert (bb == taken_edge->src);
904 taken_edge->count -= count;
905 if (taken_edge->count < 0)
906 taken_edge->count = 0;
909 /* Multiply all frequencies of basic blocks in array BBS of length NBBS
910 by NUM/DEN, in int arithmetic. May lose some accuracy. */
912 scale_bbs_frequencies_int (basic_block *bbs, int nbbs, int num, int den)
916 for (i = 0; i < nbbs; i++)
919 bbs[i]->frequency = (bbs[i]->frequency * num) / den;
920 bbs[i]->count = RDIV (bbs[i]->count * num, den);
921 FOR_EACH_EDGE (e, ei, bbs[i]->succs)
922 e->count = (e->count * num) /den;
926 /* Multiply all frequencies of basic blocks in array BBS of length NBBS
927 by NUM/DEN, in gcov_type arithmetic. More accurate than previous
928 function but considerably slower. */
930 scale_bbs_frequencies_gcov_type (basic_block *bbs, int nbbs, gcov_type num,
936 for (i = 0; i < nbbs; i++)
939 bbs[i]->frequency = (bbs[i]->frequency * num) / den;
940 bbs[i]->count = RDIV (bbs[i]->count * num, den);
941 FOR_EACH_EDGE (e, ei, bbs[i]->succs)
942 e->count = (e->count * num) /den;
946 /* Datastructures used to maintain mapping between basic blocks and copies. */
947 static htab_t bb_original;
948 static htab_t bb_copy;
949 static alloc_pool original_copy_bb_pool;
951 struct htab_bb_copy_original_entry
953 /* Block we are attaching info to. */
955 /* Index of original or copy (depending on the hashtable) */
960 bb_copy_original_hash (const void *p)
962 struct htab_bb_copy_original_entry *data
963 = ((struct htab_bb_copy_original_entry *)p);
968 bb_copy_original_eq (const void *p, const void *q)
970 struct htab_bb_copy_original_entry *data
971 = ((struct htab_bb_copy_original_entry *)p);
972 struct htab_bb_copy_original_entry *data2
973 = ((struct htab_bb_copy_original_entry *)q);
975 return data->index1 == data2->index1;
978 /* Initialize the datstructures to maintain mapping between blocks and it's copies. */
980 initialize_original_copy_tables (void)
982 gcc_assert (!original_copy_bb_pool);
983 original_copy_bb_pool
984 = create_alloc_pool ("original_copy",
985 sizeof (struct htab_bb_copy_original_entry), 10);
986 bb_original = htab_create (10, bb_copy_original_hash,
987 bb_copy_original_eq, NULL);
988 bb_copy = htab_create (10, bb_copy_original_hash, bb_copy_original_eq, NULL);
991 /* Free the datstructures to maintain mapping between blocks and it's copies. */
993 free_original_copy_tables (void)
995 gcc_assert (original_copy_bb_pool);
996 htab_delete (bb_copy);
997 htab_delete (bb_original);
998 free_alloc_pool (original_copy_bb_pool);
1001 original_copy_bb_pool = NULL;
1004 /* Set original for basic block. Do nothing when datstructures are not
1005 intialized so passes not needing this don't need to care. */
1007 set_bb_original (basic_block bb, basic_block original)
1009 if (original_copy_bb_pool)
1011 struct htab_bb_copy_original_entry **slot;
1012 struct htab_bb_copy_original_entry key;
1014 key.index1 = bb->index;
1016 (struct htab_bb_copy_original_entry **) htab_find_slot (bb_original,
1019 (*slot)->index2 = original->index;
1022 *slot = pool_alloc (original_copy_bb_pool);
1023 (*slot)->index1 = bb->index;
1024 (*slot)->index2 = original->index;
1029 /* Get the original basic block. */
1031 get_bb_original (basic_block bb)
1033 struct htab_bb_copy_original_entry *entry;
1034 struct htab_bb_copy_original_entry key;
1036 gcc_assert (original_copy_bb_pool);
1038 key.index1 = bb->index;
1039 entry = (struct htab_bb_copy_original_entry *) htab_find (bb_original, &key);
1041 return BASIC_BLOCK (entry->index2);
1046 /* Set copy for basic block. Do nothing when datstructures are not
1047 intialized so passes not needing this don't need to care. */
1049 set_bb_copy (basic_block bb, basic_block copy)
1051 if (original_copy_bb_pool)
1053 struct htab_bb_copy_original_entry **slot;
1054 struct htab_bb_copy_original_entry key;
1056 key.index1 = bb->index;
1058 (struct htab_bb_copy_original_entry **) htab_find_slot (bb_copy,
1061 (*slot)->index2 = copy->index;
1064 *slot = pool_alloc (original_copy_bb_pool);
1065 (*slot)->index1 = bb->index;
1066 (*slot)->index2 = copy->index;
1071 /* Get the copy of basic block. */
1073 get_bb_copy (basic_block bb)
1075 struct htab_bb_copy_original_entry *entry;
1076 struct htab_bb_copy_original_entry key;
1078 gcc_assert (original_copy_bb_pool);
1080 key.index1 = bb->index;
1081 entry = (struct htab_bb_copy_original_entry *) htab_find (bb_copy, &key);
1083 return BASIC_BLOCK (entry->index2);