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
)
425 | (bb
->flags
& BB_RTL
));
428 /* Check the consistency of profile information. We can't do that
429 in verify_flow_info, as the counts may get invalid for incompletely
430 solved graphs, later eliminating of conditionals or roundoff errors.
431 It is still practical to have them reported for debugging of simple
434 check_bb_profile (basic_block bb
, FILE * file
)
441 if (profile_status
== PROFILE_ABSENT
)
444 if (bb
!= EXIT_BLOCK_PTR
)
446 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
447 sum
+= e
->probability
;
448 if (EDGE_COUNT (bb
->succs
) && abs (sum
- REG_BR_PROB_BASE
) > 100)
449 fprintf (file
, "Invalid sum of outgoing probabilities %.1f%%\n",
450 sum
* 100.0 / REG_BR_PROB_BASE
);
452 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
454 if (EDGE_COUNT (bb
->succs
)
455 && (lsum
- bb
->count
> 100 || lsum
- bb
->count
< -100))
456 fprintf (file
, "Invalid sum of outgoing counts %i, should be %i\n",
457 (int) lsum
, (int) bb
->count
);
459 if (bb
!= ENTRY_BLOCK_PTR
)
462 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
463 sum
+= EDGE_FREQUENCY (e
);
464 if (abs (sum
- bb
->frequency
) > 100)
466 "Invalid sum of incoming frequencies %i, should be %i\n",
469 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
471 if (lsum
- bb
->count
> 100 || lsum
- bb
->count
< -100)
472 fprintf (file
, "Invalid sum of incoming counts %i, should be %i\n",
473 (int) lsum
, (int) bb
->count
);
478 dump_flow_info (FILE *file
)
482 /* There are no pseudo registers after reload. Don't dump them. */
483 if (reg_n_info
&& !reload_completed
)
485 unsigned int i
, max
= max_reg_num ();
486 fprintf (file
, "%d registers.\n", max
);
487 for (i
= FIRST_PSEUDO_REGISTER
; i
< max
; i
++)
490 enum reg_class
class, altclass
;
492 fprintf (file
, "\nRegister %d used %d times across %d insns",
493 i
, REG_N_REFS (i
), REG_LIVE_LENGTH (i
));
494 if (REG_BASIC_BLOCK (i
) >= 0)
495 fprintf (file
, " in block %d", REG_BASIC_BLOCK (i
));
497 fprintf (file
, "; set %d time%s", REG_N_SETS (i
),
498 (REG_N_SETS (i
) == 1) ? "" : "s");
499 if (regno_reg_rtx
[i
] != NULL
&& REG_USERVAR_P (regno_reg_rtx
[i
]))
500 fprintf (file
, "; user var");
501 if (REG_N_DEATHS (i
) != 1)
502 fprintf (file
, "; dies in %d places", REG_N_DEATHS (i
));
503 if (REG_N_CALLS_CROSSED (i
) == 1)
504 fprintf (file
, "; crosses 1 call");
505 else if (REG_N_CALLS_CROSSED (i
))
506 fprintf (file
, "; crosses %d calls", REG_N_CALLS_CROSSED (i
));
507 if (regno_reg_rtx
[i
] != NULL
508 && PSEUDO_REGNO_BYTES (i
) != UNITS_PER_WORD
)
509 fprintf (file
, "; %d bytes", PSEUDO_REGNO_BYTES (i
));
511 class = reg_preferred_class (i
);
512 altclass
= reg_alternate_class (i
);
513 if (class != GENERAL_REGS
|| altclass
!= ALL_REGS
)
515 if (altclass
== ALL_REGS
|| class == ALL_REGS
)
516 fprintf (file
, "; pref %s", reg_class_names
[(int) class]);
517 else if (altclass
== NO_REGS
)
518 fprintf (file
, "; %s or none", reg_class_names
[(int) class]);
520 fprintf (file
, "; pref %s, else %s",
521 reg_class_names
[(int) class],
522 reg_class_names
[(int) altclass
]);
525 if (regno_reg_rtx
[i
] != NULL
&& REG_POINTER (regno_reg_rtx
[i
]))
526 fprintf (file
, "; pointer");
527 fprintf (file
, ".\n");
531 fprintf (file
, "\n%d basic blocks, %d edges.\n", n_basic_blocks
, n_edges
);
537 fprintf (file
, "\nBasic block %d ", bb
->index
);
538 fprintf (file
, "prev %d, next %d, ",
539 bb
->prev_bb
->index
, bb
->next_bb
->index
);
540 fprintf (file
, "loop_depth %d, count ", bb
->loop_depth
);
541 fprintf (file
, HOST_WIDEST_INT_PRINT_DEC
, bb
->count
);
542 fprintf (file
, ", freq %i", bb
->frequency
);
543 if (maybe_hot_bb_p (bb
))
544 fprintf (file
, ", maybe hot");
545 if (probably_never_executed_bb_p (bb
))
546 fprintf (file
, ", probably never executed");
547 fprintf (file
, ".\n");
549 fprintf (file
, "Predecessors: ");
550 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
551 dump_edge_info (file
, e
, 0);
553 fprintf (file
, "\nSuccessors: ");
554 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
555 dump_edge_info (file
, e
, 1);
557 if (bb
->flags
& BB_RTL
)
559 if (bb
->il
.rtl
->global_live_at_start
)
561 fprintf (file
, "\nRegisters live at start:");
562 dump_regset (bb
->il
.rtl
->global_live_at_start
, file
);
565 if (bb
->il
.rtl
->global_live_at_end
)
567 fprintf (file
, "\nRegisters live at end:");
568 dump_regset (bb
->il
.rtl
->global_live_at_end
, file
);
573 check_bb_profile (bb
, file
);
580 debug_flow_info (void)
582 dump_flow_info (stderr
);
586 dump_edge_info (FILE *file
, edge e
, int do_succ
)
588 basic_block side
= (do_succ
? e
->dest
: e
->src
);
590 if (side
== ENTRY_BLOCK_PTR
)
591 fputs (" ENTRY", file
);
592 else if (side
== EXIT_BLOCK_PTR
)
593 fputs (" EXIT", file
);
595 fprintf (file
, " %d", side
->index
);
598 fprintf (file
, " [%.1f%%] ", e
->probability
* 100.0 / REG_BR_PROB_BASE
);
602 fprintf (file
, " count:");
603 fprintf (file
, HOST_WIDEST_INT_PRINT_DEC
, e
->count
);
608 static const char * const bitnames
[] = {
609 "fallthru", "ab", "abcall", "eh", "fake", "dfs_back",
610 "can_fallthru", "irreducible", "sibcall", "loop_exit",
611 "true", "false", "exec"
614 int i
, flags
= e
->flags
;
617 for (i
= 0; flags
; i
++)
618 if (flags
& (1 << i
))
624 if (i
< (int) ARRAY_SIZE (bitnames
))
625 fputs (bitnames
[i
], file
);
627 fprintf (file
, "%d", i
);
635 /* Simple routines to easily allocate AUX fields of basic blocks. */
637 static struct obstack block_aux_obstack
;
638 static void *first_block_aux_obj
= 0;
639 static struct obstack edge_aux_obstack
;
640 static void *first_edge_aux_obj
= 0;
642 /* Allocate a memory block of SIZE as BB->aux. The obstack must
643 be first initialized by alloc_aux_for_blocks. */
646 alloc_aux_for_block (basic_block bb
, int size
)
648 /* Verify that aux field is clear. */
649 gcc_assert (!bb
->aux
&& first_block_aux_obj
);
650 bb
->aux
= obstack_alloc (&block_aux_obstack
, size
);
651 memset (bb
->aux
, 0, size
);
654 /* Initialize the block_aux_obstack and if SIZE is nonzero, call
655 alloc_aux_for_block for each basic block. */
658 alloc_aux_for_blocks (int size
)
660 static int initialized
;
664 gcc_obstack_init (&block_aux_obstack
);
668 /* Check whether AUX data are still allocated. */
669 gcc_assert (!first_block_aux_obj
);
671 first_block_aux_obj
= obstack_alloc (&block_aux_obstack
, 0);
676 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, NULL
, next_bb
)
677 alloc_aux_for_block (bb
, size
);
681 /* Clear AUX pointers of all blocks. */
684 clear_aux_for_blocks (void)
688 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, NULL
, next_bb
)
692 /* Free data allocated in block_aux_obstack and clear AUX pointers
696 free_aux_for_blocks (void)
698 gcc_assert (first_block_aux_obj
);
699 obstack_free (&block_aux_obstack
, first_block_aux_obj
);
700 first_block_aux_obj
= NULL
;
702 clear_aux_for_blocks ();
705 /* Allocate a memory edge of SIZE as BB->aux. The obstack must
706 be first initialized by alloc_aux_for_edges. */
709 alloc_aux_for_edge (edge e
, int size
)
711 /* Verify that aux field is clear. */
712 gcc_assert (!e
->aux
&& first_edge_aux_obj
);
713 e
->aux
= obstack_alloc (&edge_aux_obstack
, size
);
714 memset (e
->aux
, 0, size
);
717 /* Initialize the edge_aux_obstack and if SIZE is nonzero, call
718 alloc_aux_for_edge for each basic edge. */
721 alloc_aux_for_edges (int size
)
723 static int initialized
;
727 gcc_obstack_init (&edge_aux_obstack
);
731 /* Check whether AUX data are still allocated. */
732 gcc_assert (!first_edge_aux_obj
);
734 first_edge_aux_obj
= obstack_alloc (&edge_aux_obstack
, 0);
739 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, EXIT_BLOCK_PTR
, next_bb
)
744 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
745 alloc_aux_for_edge (e
, size
);
750 /* Clear AUX pointers of all edges. */
753 clear_aux_for_edges (void)
758 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, EXIT_BLOCK_PTR
, next_bb
)
761 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
766 /* Free data allocated in edge_aux_obstack and clear AUX pointers
770 free_aux_for_edges (void)
772 gcc_assert (first_edge_aux_obj
);
773 obstack_free (&edge_aux_obstack
, first_edge_aux_obj
);
774 first_edge_aux_obj
= NULL
;
776 clear_aux_for_edges ();
780 debug_bb (basic_block bb
)
782 dump_bb (bb
, stderr
, 0);
788 basic_block bb
= BASIC_BLOCK (n
);
789 dump_bb (bb
, stderr
, 0);
793 /* Dumps cfg related information about basic block BB to FILE. */
796 dump_cfg_bb_info (FILE *file
, basic_block bb
)
801 static const char * const bb_bitnames
[] =
803 "dirty", "new", "reachable", "visited", "irreducible_loop", "superblock"
805 const unsigned n_bitnames
= sizeof (bb_bitnames
) / sizeof (char *);
808 fprintf (file
, "Basic block %d", bb
->index
);
809 for (i
= 0; i
< n_bitnames
; i
++)
810 if (bb
->flags
& (1 << i
))
813 fprintf (file
, " (");
815 fprintf (file
, ", ");
817 fprintf (file
, bb_bitnames
[i
]);
821 fprintf (file
, "\n");
823 fprintf (file
, "Predecessors: ");
824 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
825 dump_edge_info (file
, e
, 0);
827 fprintf (file
, "\nSuccessors: ");
828 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
829 dump_edge_info (file
, e
, 1);
830 fprintf (file
, "\n\n");
833 /* Dumps a brief description of cfg to FILE. */
836 brief_dump_cfg (FILE *file
)
842 dump_cfg_bb_info (file
, bb
);
846 /* An edge originally destinating BB of FREQUENCY and COUNT has been proved to
847 leave the block by TAKEN_EDGE. Update profile of BB such that edge E can be
848 redirected to destination of TAKEN_EDGE.
850 This function may leave the profile inconsistent in the case TAKEN_EDGE
851 frequency or count is believed to be lower than FREQUENCY or COUNT
854 update_bb_profile_for_threading (basic_block bb
, int edge_frequency
,
855 gcov_type count
, edge taken_edge
)
865 /* Compute the probability of TAKEN_EDGE being reached via threaded edge.
866 Watch for overflows. */
868 prob
= edge_frequency
* REG_BR_PROB_BASE
/ bb
->frequency
;
871 if (prob
> taken_edge
->probability
)
874 fprintf (dump_file
, "Jump threading proved probability of edge "
875 "%i->%i too small (it is %i, should be %i).\n",
876 taken_edge
->src
->index
, taken_edge
->dest
->index
,
877 taken_edge
->probability
, prob
);
878 prob
= taken_edge
->probability
;
881 /* Now rescale the probabilities. */
882 taken_edge
->probability
-= prob
;
883 prob
= REG_BR_PROB_BASE
- prob
;
884 bb
->frequency
-= edge_frequency
;
885 if (bb
->frequency
< 0)
890 fprintf (dump_file
, "Edge frequencies of bb %i has been reset, "
891 "frequency of block should end up being 0, it is %i\n",
892 bb
->index
, bb
->frequency
);
893 EDGE_SUCC (bb
, 0)->probability
= REG_BR_PROB_BASE
;
894 ei
= ei_start (bb
->succs
);
896 for (; (c
= ei_safe_edge (ei
)); ei_next (&ei
))
899 else if (prob
!= REG_BR_PROB_BASE
)
901 int scale
= 65536 * REG_BR_PROB_BASE
/ prob
;
903 FOR_EACH_EDGE (c
, ei
, bb
->succs
)
904 c
->probability
*= scale
/ 65536;
907 gcc_assert (bb
== taken_edge
->src
);
908 taken_edge
->count
-= count
;
909 if (taken_edge
->count
< 0)
910 taken_edge
->count
= 0;
913 /* Multiply all frequencies of basic blocks in array BBS of length NBBS
914 by NUM/DEN, in int arithmetic. May lose some accuracy. */
916 scale_bbs_frequencies_int (basic_block
*bbs
, int nbbs
, int num
, int den
)
920 for (i
= 0; i
< nbbs
; i
++)
923 bbs
[i
]->frequency
= (bbs
[i
]->frequency
* num
) / den
;
924 bbs
[i
]->count
= RDIV (bbs
[i
]->count
* num
, den
);
925 FOR_EACH_EDGE (e
, ei
, bbs
[i
]->succs
)
926 e
->count
= (e
->count
* num
) /den
;
930 /* Multiply all frequencies of basic blocks in array BBS of length NBBS
931 by NUM/DEN, in gcov_type arithmetic. More accurate than previous
932 function but considerably slower. */
934 scale_bbs_frequencies_gcov_type (basic_block
*bbs
, int nbbs
, gcov_type num
,
940 for (i
= 0; i
< nbbs
; i
++)
943 bbs
[i
]->frequency
= (bbs
[i
]->frequency
* num
) / den
;
944 bbs
[i
]->count
= RDIV (bbs
[i
]->count
* num
, den
);
945 FOR_EACH_EDGE (e
, ei
, bbs
[i
]->succs
)
946 e
->count
= (e
->count
* num
) /den
;
950 /* Datastructures used to maintain mapping between basic blocks and copies. */
951 static htab_t bb_original
;
952 static htab_t bb_copy
;
953 static alloc_pool original_copy_bb_pool
;
955 struct htab_bb_copy_original_entry
957 /* Block we are attaching info to. */
959 /* Index of original or copy (depending on the hashtable) */
964 bb_copy_original_hash (const void *p
)
966 struct htab_bb_copy_original_entry
*data
967 = ((struct htab_bb_copy_original_entry
*)p
);
972 bb_copy_original_eq (const void *p
, const void *q
)
974 struct htab_bb_copy_original_entry
*data
975 = ((struct htab_bb_copy_original_entry
*)p
);
976 struct htab_bb_copy_original_entry
*data2
977 = ((struct htab_bb_copy_original_entry
*)q
);
979 return data
->index1
== data2
->index1
;
982 /* Initialize the datstructures to maintain mapping between blocks and it's copies. */
984 initialize_original_copy_tables (void)
986 gcc_assert (!original_copy_bb_pool
);
987 original_copy_bb_pool
988 = create_alloc_pool ("original_copy",
989 sizeof (struct htab_bb_copy_original_entry
), 10);
990 bb_original
= htab_create (10, bb_copy_original_hash
,
991 bb_copy_original_eq
, NULL
);
992 bb_copy
= htab_create (10, bb_copy_original_hash
, bb_copy_original_eq
, NULL
);
995 /* Free the datstructures to maintain mapping between blocks and it's copies. */
997 free_original_copy_tables (void)
999 gcc_assert (original_copy_bb_pool
);
1000 htab_delete (bb_copy
);
1001 htab_delete (bb_original
);
1002 free_alloc_pool (original_copy_bb_pool
);
1005 original_copy_bb_pool
= NULL
;
1008 /* Set original for basic block. Do nothing when datstructures are not
1009 intialized so passes not needing this don't need to care. */
1011 set_bb_original (basic_block bb
, basic_block original
)
1013 if (original_copy_bb_pool
)
1015 struct htab_bb_copy_original_entry
**slot
;
1016 struct htab_bb_copy_original_entry key
;
1018 key
.index1
= bb
->index
;
1020 (struct htab_bb_copy_original_entry
**) htab_find_slot (bb_original
,
1023 (*slot
)->index2
= original
->index
;
1026 *slot
= pool_alloc (original_copy_bb_pool
);
1027 (*slot
)->index1
= bb
->index
;
1028 (*slot
)->index2
= original
->index
;
1033 /* Get the original basic block. */
1035 get_bb_original (basic_block bb
)
1037 struct htab_bb_copy_original_entry
*entry
;
1038 struct htab_bb_copy_original_entry key
;
1040 gcc_assert (original_copy_bb_pool
);
1042 key
.index1
= bb
->index
;
1043 entry
= (struct htab_bb_copy_original_entry
*) htab_find (bb_original
, &key
);
1045 return BASIC_BLOCK (entry
->index2
);
1050 /* Set copy for basic block. Do nothing when datstructures are not
1051 intialized so passes not needing this don't need to care. */
1053 set_bb_copy (basic_block bb
, basic_block copy
)
1055 if (original_copy_bb_pool
)
1057 struct htab_bb_copy_original_entry
**slot
;
1058 struct htab_bb_copy_original_entry key
;
1060 key
.index1
= bb
->index
;
1062 (struct htab_bb_copy_original_entry
**) htab_find_slot (bb_copy
,
1065 (*slot
)->index2
= copy
->index
;
1068 *slot
= pool_alloc (original_copy_bb_pool
);
1069 (*slot
)->index1
= bb
->index
;
1070 (*slot
)->index2
= copy
->index
;
1075 /* Get the copy of basic block. */
1077 get_bb_copy (basic_block bb
)
1079 struct htab_bb_copy_original_entry
*entry
;
1080 struct htab_bb_copy_original_entry key
;
1082 gcc_assert (original_copy_bb_pool
);
1084 key
.index1
= bb
->index
;
1085 entry
= (struct htab_bb_copy_original_entry
*) htab_find (bb_copy
, &key
);
1087 return BASIC_BLOCK (entry
->index2
);