Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
[dragonfly.git] / contrib / gcc-3.4 / gcc / cfg.c
blob8042585366604e3d8790748ea0fd1e684ef2f1bb
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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
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
33 - Edge manipulation
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
41 - clear_bb_flags
42 - Consistency checking
43 verify_flow_info
44 - Dumping and debugging
45 print_rtl_with_bb, dump_bb, debug_bb, debug_bb_n
48 #include "config.h"
49 #include "system.h"
50 #include "coretypes.h"
51 #include "tm.h"
52 #include "tree.h"
53 #include "rtl.h"
54 #include "hard-reg-set.h"
55 #include "basic-block.h"
56 #include "regs.h"
57 #include "flags.h"
58 #include "output.h"
59 #include "function.h"
60 #include "except.h"
61 #include "toplev.h"
62 #include "tm_p.h"
63 #include "obstack.h"
64 #include "alloc-pool.h"
66 /* The obstack on which the flow graph components are allocated. */
68 struct obstack flow_obstack;
69 static char *flow_firstobj;
71 /* Basic block object pool. */
73 static alloc_pool bb_pool;
75 /* Edge object pool. */
77 static alloc_pool edge_pool;
79 /* Number of basic blocks in the current function. */
81 int n_basic_blocks;
83 /* First free basic block number. */
85 int last_basic_block;
87 /* Number of edges in the current function. */
89 int n_edges;
91 /* The basic block array. */
93 varray_type basic_block_info;
95 /* The special entry and exit blocks. */
97 struct basic_block_def entry_exit_blocks[2]
98 = {{NULL, /* head */
99 NULL, /* end */
100 NULL, /* head_tree */
101 NULL, /* end_tree */
102 NULL, /* pred */
103 NULL, /* succ */
104 NULL, /* local_set */
105 NULL, /* cond_local_set */
106 NULL, /* global_live_at_start */
107 NULL, /* global_live_at_end */
108 NULL, /* aux */
109 ENTRY_BLOCK, /* index */
110 NULL, /* prev_bb */
111 EXIT_BLOCK_PTR, /* next_bb */
112 0, /* loop_depth */
113 NULL, /* loop_father */
114 { NULL, NULL }, /* dom */
115 0, /* count */
116 0, /* frequency */
117 0, /* flags */
118 NULL /* rbi */
121 NULL, /* head */
122 NULL, /* end */
123 NULL, /* head_tree */
124 NULL, /* end_tree */
125 NULL, /* pred */
126 NULL, /* succ */
127 NULL, /* local_set */
128 NULL, /* cond_local_set */
129 NULL, /* global_live_at_start */
130 NULL, /* global_live_at_end */
131 NULL, /* aux */
132 EXIT_BLOCK, /* index */
133 ENTRY_BLOCK_PTR, /* prev_bb */
134 NULL, /* next_bb */
135 0, /* loop_depth */
136 NULL, /* loop_father */
137 { NULL, NULL }, /* dom */
138 0, /* count */
139 0, /* frequency */
140 0, /* flags */
141 NULL /* rbi */
145 void debug_flow_info (void);
146 static void free_edge (edge);
148 /* Called once at initialization time. */
150 void
151 init_flow (void)
153 static int initialized;
155 n_edges = 0;
157 if (!initialized)
159 gcc_obstack_init (&flow_obstack);
160 flow_firstobj = obstack_alloc (&flow_obstack, 0);
161 initialized = 1;
163 else
165 free_alloc_pool (bb_pool);
166 free_alloc_pool (edge_pool);
167 obstack_free (&flow_obstack, flow_firstobj);
168 flow_firstobj = obstack_alloc (&flow_obstack, 0);
170 bb_pool = create_alloc_pool ("Basic block pool",
171 sizeof (struct basic_block_def), 100);
172 edge_pool = create_alloc_pool ("Edge pool",
173 sizeof (struct edge_def), 100);
176 /* Helper function for remove_edge and clear_edges. Frees edge structure
177 without actually unlinking it from the pred/succ lists. */
179 static void
180 free_edge (edge e)
182 n_edges--;
183 pool_free (edge_pool, e);
186 /* Free the memory associated with the edge structures. */
188 void
189 clear_edges (void)
191 basic_block bb;
192 edge e;
194 FOR_EACH_BB (bb)
196 edge e = bb->succ;
198 while (e)
200 edge next = e->succ_next;
202 free_edge (e);
203 e = next;
206 bb->succ = NULL;
207 bb->pred = NULL;
210 e = ENTRY_BLOCK_PTR->succ;
211 while (e)
213 edge next = e->succ_next;
215 free_edge (e);
216 e = next;
219 EXIT_BLOCK_PTR->pred = NULL;
220 ENTRY_BLOCK_PTR->succ = NULL;
222 if (n_edges)
223 abort ();
226 /* Allocate memory for basic_block. */
228 basic_block
229 alloc_block (void)
231 basic_block bb;
232 bb = pool_alloc (bb_pool);
233 memset (bb, 0, sizeof (*bb));
234 return bb;
237 /* Link block B to chain after AFTER. */
238 void
239 link_block (basic_block b, basic_block after)
241 b->next_bb = after->next_bb;
242 b->prev_bb = after;
243 after->next_bb = b;
244 b->next_bb->prev_bb = b;
247 /* Unlink block B from chain. */
248 void
249 unlink_block (basic_block b)
251 b->next_bb->prev_bb = b->prev_bb;
252 b->prev_bb->next_bb = b->next_bb;
255 /* Sequentially order blocks and compact the arrays. */
256 void
257 compact_blocks (void)
259 int i;
260 basic_block bb;
262 i = 0;
263 FOR_EACH_BB (bb)
265 BASIC_BLOCK (i) = bb;
266 bb->index = i;
267 i++;
270 if (i != n_basic_blocks)
271 abort ();
273 last_basic_block = n_basic_blocks;
276 /* Remove block B from the basic block array. */
278 void
279 expunge_block (basic_block b)
281 unlink_block (b);
282 BASIC_BLOCK (b->index) = NULL;
283 n_basic_blocks--;
284 pool_free (bb_pool, b);
287 /* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
288 created edge. Use this only if you are sure that this edge can't
289 possibly already exist. */
291 edge
292 unchecked_make_edge (basic_block src, basic_block dst, int flags)
294 edge e;
295 e = pool_alloc (edge_pool);
296 memset (e, 0, sizeof (*e));
297 n_edges++;
299 e->succ_next = src->succ;
300 e->pred_next = dst->pred;
301 e->src = src;
302 e->dest = dst;
303 e->flags = flags;
305 src->succ = e;
306 dst->pred = e;
308 return e;
311 /* Create an edge connecting SRC and DST with FLAGS optionally using
312 edge cache CACHE. Return the new edge, NULL if already exist. */
314 edge
315 cached_make_edge (sbitmap *edge_cache, basic_block src, basic_block dst, int flags)
317 int use_edge_cache;
318 edge e;
320 /* Don't bother with edge cache for ENTRY or EXIT, if there aren't that
321 many edges to them, or we didn't allocate memory for it. */
322 use_edge_cache = (edge_cache
323 && src != ENTRY_BLOCK_PTR && dst != EXIT_BLOCK_PTR);
325 /* Make sure we don't add duplicate edges. */
326 switch (use_edge_cache)
328 default:
329 /* Quick test for non-existence of the edge. */
330 if (! TEST_BIT (edge_cache[src->index], dst->index))
331 break;
333 /* The edge exists; early exit if no work to do. */
334 if (flags == 0)
335 return NULL;
337 /* Fall through. */
338 case 0:
339 for (e = src->succ; e; e = e->succ_next)
340 if (e->dest == dst)
342 e->flags |= flags;
343 return NULL;
345 break;
348 e = unchecked_make_edge (src, dst, flags);
350 if (use_edge_cache)
351 SET_BIT (edge_cache[src->index], dst->index);
353 return e;
356 /* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
357 created edge or NULL if already exist. */
359 edge
360 make_edge (basic_block src, basic_block dest, int flags)
362 return cached_make_edge (NULL, src, dest, flags);
365 /* Create an edge connecting SRC to DEST and set probability by knowing
366 that it is the single edge leaving SRC. */
368 edge
369 make_single_succ_edge (basic_block src, basic_block dest, int flags)
371 edge e = make_edge (src, dest, flags);
373 e->probability = REG_BR_PROB_BASE;
374 e->count = src->count;
375 return e;
378 /* This function will remove an edge from the flow graph. */
380 void
381 remove_edge (edge e)
383 edge last_pred = NULL;
384 edge last_succ = NULL;
385 edge tmp;
386 basic_block src, dest;
388 src = e->src;
389 dest = e->dest;
390 for (tmp = src->succ; tmp && tmp != e; tmp = tmp->succ_next)
391 last_succ = tmp;
393 if (!tmp)
394 abort ();
395 if (last_succ)
396 last_succ->succ_next = e->succ_next;
397 else
398 src->succ = e->succ_next;
400 for (tmp = dest->pred; tmp && tmp != e; tmp = tmp->pred_next)
401 last_pred = tmp;
403 if (!tmp)
404 abort ();
405 if (last_pred)
406 last_pred->pred_next = e->pred_next;
407 else
408 dest->pred = e->pred_next;
410 free_edge (e);
413 /* Redirect an edge's successor from one block to another. */
415 void
416 redirect_edge_succ (edge e, basic_block new_succ)
418 edge *pe;
420 /* Disconnect the edge from the old successor block. */
421 for (pe = &e->dest->pred; *pe != e; pe = &(*pe)->pred_next)
422 continue;
423 *pe = (*pe)->pred_next;
425 /* Reconnect the edge to the new successor block. */
426 e->pred_next = new_succ->pred;
427 new_succ->pred = e;
428 e->dest = new_succ;
431 /* Like previous but avoid possible duplicate edge. */
433 edge
434 redirect_edge_succ_nodup (edge e, basic_block new_succ)
436 edge s;
438 /* Check whether the edge is already present. */
439 for (s = e->src->succ; s; s = s->succ_next)
440 if (s->dest == new_succ && s != e)
441 break;
443 if (s)
445 s->flags |= e->flags;
446 s->probability += e->probability;
447 if (s->probability > REG_BR_PROB_BASE)
448 s->probability = REG_BR_PROB_BASE;
449 s->count += e->count;
450 remove_edge (e);
451 e = s;
453 else
454 redirect_edge_succ (e, new_succ);
456 return e;
459 /* Redirect an edge's predecessor from one block to another. */
461 void
462 redirect_edge_pred (edge e, basic_block new_pred)
464 edge *pe;
466 /* Disconnect the edge from the old predecessor block. */
467 for (pe = &e->src->succ; *pe != e; pe = &(*pe)->succ_next)
468 continue;
470 *pe = (*pe)->succ_next;
472 /* Reconnect the edge to the new predecessor block. */
473 e->succ_next = new_pred->succ;
474 new_pred->succ = e;
475 e->src = new_pred;
478 void
479 clear_bb_flags (void)
481 basic_block bb;
483 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
484 bb->flags = 0;
487 void
488 dump_flow_info (FILE *file)
490 int i;
491 int max_regno = max_reg_num ();
492 basic_block bb;
493 static const char * const reg_class_names[] = REG_CLASS_NAMES;
495 fprintf (file, "%d registers.\n", max_regno);
496 if (reg_n_info)
497 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
498 if (REG_N_REFS (i))
500 enum reg_class class, altclass;
502 fprintf (file, "\nRegister %d used %d times across %d insns",
503 i, REG_N_REFS (i), REG_LIVE_LENGTH (i));
504 if (REG_BASIC_BLOCK (i) >= 0)
505 fprintf (file, " in block %d", REG_BASIC_BLOCK (i));
506 if (REG_N_SETS (i))
507 fprintf (file, "; set %d time%s", REG_N_SETS (i),
508 (REG_N_SETS (i) == 1) ? "" : "s");
509 if (regno_reg_rtx[i] != NULL && REG_USERVAR_P (regno_reg_rtx[i]))
510 fprintf (file, "; user var");
511 if (REG_N_DEATHS (i) != 1)
512 fprintf (file, "; dies in %d places", REG_N_DEATHS (i));
513 if (REG_N_CALLS_CROSSED (i) == 1)
514 fprintf (file, "; crosses 1 call");
515 else if (REG_N_CALLS_CROSSED (i))
516 fprintf (file, "; crosses %d calls", REG_N_CALLS_CROSSED (i));
517 if (regno_reg_rtx[i] != NULL
518 && PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
519 fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
521 class = reg_preferred_class (i);
522 altclass = reg_alternate_class (i);
523 if (class != GENERAL_REGS || altclass != ALL_REGS)
525 if (altclass == ALL_REGS || class == ALL_REGS)
526 fprintf (file, "; pref %s", reg_class_names[(int) class]);
527 else if (altclass == NO_REGS)
528 fprintf (file, "; %s or none", reg_class_names[(int) class]);
529 else
530 fprintf (file, "; pref %s, else %s",
531 reg_class_names[(int) class],
532 reg_class_names[(int) altclass]);
535 if (regno_reg_rtx[i] != NULL && REG_POINTER (regno_reg_rtx[i]))
536 fprintf (file, "; pointer");
537 fprintf (file, ".\n");
540 fprintf (file, "\n%d basic blocks, %d edges.\n", n_basic_blocks, n_edges);
541 FOR_EACH_BB (bb)
543 edge e;
544 int sum;
545 gcov_type lsum;
547 fprintf (file, "\nBasic block %d: first insn %d, last %d, ",
548 bb->index, INSN_UID (BB_HEAD (bb)), INSN_UID (BB_END (bb)));
549 fprintf (file, "prev %d, next %d, ",
550 bb->prev_bb->index, bb->next_bb->index);
551 fprintf (file, "loop_depth %d, count ", bb->loop_depth);
552 fprintf (file, HOST_WIDEST_INT_PRINT_DEC, bb->count);
553 fprintf (file, ", freq %i", bb->frequency);
554 if (maybe_hot_bb_p (bb))
555 fprintf (file, ", maybe hot");
556 if (probably_never_executed_bb_p (bb))
557 fprintf (file, ", probably never executed");
558 fprintf (file, ".\n");
560 fprintf (file, "Predecessors: ");
561 for (e = bb->pred; e; e = e->pred_next)
562 dump_edge_info (file, e, 0);
564 fprintf (file, "\nSuccessors: ");
565 for (e = bb->succ; e; e = e->succ_next)
566 dump_edge_info (file, e, 1);
568 fprintf (file, "\nRegisters live at start:");
569 dump_regset (bb->global_live_at_start, file);
571 fprintf (file, "\nRegisters live at end:");
572 dump_regset (bb->global_live_at_end, file);
574 putc ('\n', file);
576 /* Check the consistency of profile information. We can't do that
577 in verify_flow_info, as the counts may get invalid for incompletely
578 solved graphs, later eliminating of conditionals or roundoff errors.
579 It is still practical to have them reported for debugging of simple
580 testcases. */
581 sum = 0;
582 for (e = bb->succ; e; e = e->succ_next)
583 sum += e->probability;
584 if (bb->succ && abs (sum - REG_BR_PROB_BASE) > 100)
585 fprintf (file, "Invalid sum of outgoing probabilities %.1f%%\n",
586 sum * 100.0 / REG_BR_PROB_BASE);
587 sum = 0;
588 for (e = bb->pred; e; e = e->pred_next)
589 sum += EDGE_FREQUENCY (e);
590 if (abs (sum - bb->frequency) > 100)
591 fprintf (file,
592 "Invalid sum of incomming frequencies %i, should be %i\n",
593 sum, bb->frequency);
594 lsum = 0;
595 for (e = bb->pred; e; e = e->pred_next)
596 lsum += e->count;
597 if (lsum - bb->count > 100 || lsum - bb->count < -100)
598 fprintf (file, "Invalid sum of incomming counts %i, should be %i\n",
599 (int)lsum, (int)bb->count);
600 lsum = 0;
601 for (e = bb->succ; e; e = e->succ_next)
602 lsum += e->count;
603 if (bb->succ && (lsum - bb->count > 100 || lsum - bb->count < -100))
604 fprintf (file, "Invalid sum of incomming counts %i, should be %i\n",
605 (int)lsum, (int)bb->count);
608 putc ('\n', file);
611 void
612 debug_flow_info (void)
614 dump_flow_info (stderr);
617 void
618 dump_edge_info (FILE *file, edge e, int do_succ)
620 basic_block side = (do_succ ? e->dest : e->src);
622 if (side == ENTRY_BLOCK_PTR)
623 fputs (" ENTRY", file);
624 else if (side == EXIT_BLOCK_PTR)
625 fputs (" EXIT", file);
626 else
627 fprintf (file, " %d", side->index);
629 if (e->probability)
630 fprintf (file, " [%.1f%%] ", e->probability * 100.0 / REG_BR_PROB_BASE);
632 if (e->count)
634 fprintf (file, " count:");
635 fprintf (file, HOST_WIDEST_INT_PRINT_DEC, e->count);
638 if (e->flags)
640 static const char * const bitnames[] = {
641 "fallthru", "ab", "abcall", "eh", "fake", "dfs_back",
642 "can_fallthru", "irreducible", "sibcall", "loop_exit"
644 int comma = 0;
645 int i, flags = e->flags;
647 fputs (" (", file);
648 for (i = 0; flags; i++)
649 if (flags & (1 << i))
651 flags &= ~(1 << i);
653 if (comma)
654 fputc (',', file);
655 if (i < (int) ARRAY_SIZE (bitnames))
656 fputs (bitnames[i], file);
657 else
658 fprintf (file, "%d", i);
659 comma = 1;
662 fputc (')', file);
666 /* Simple routines to easily allocate AUX fields of basic blocks. */
668 static struct obstack block_aux_obstack;
669 static void *first_block_aux_obj = 0;
670 static struct obstack edge_aux_obstack;
671 static void *first_edge_aux_obj = 0;
673 /* Allocate a memory block of SIZE as BB->aux. The obstack must
674 be first initialized by alloc_aux_for_blocks. */
676 inline void
677 alloc_aux_for_block (basic_block bb, int size)
679 /* Verify that aux field is clear. */
680 if (bb->aux || !first_block_aux_obj)
681 abort ();
682 bb->aux = obstack_alloc (&block_aux_obstack, size);
683 memset (bb->aux, 0, size);
686 /* Initialize the block_aux_obstack and if SIZE is nonzero, call
687 alloc_aux_for_block for each basic block. */
689 void
690 alloc_aux_for_blocks (int size)
692 static int initialized;
694 if (!initialized)
696 gcc_obstack_init (&block_aux_obstack);
697 initialized = 1;
700 /* Check whether AUX data are still allocated. */
701 else if (first_block_aux_obj)
702 abort ();
703 first_block_aux_obj = obstack_alloc (&block_aux_obstack, 0);
704 if (size)
706 basic_block bb;
708 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
709 alloc_aux_for_block (bb, size);
713 /* Clear AUX pointers of all blocks. */
715 void
716 clear_aux_for_blocks (void)
718 basic_block bb;
720 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
721 bb->aux = NULL;
724 /* Free data allocated in block_aux_obstack and clear AUX pointers
725 of all blocks. */
727 void
728 free_aux_for_blocks (void)
730 if (!first_block_aux_obj)
731 abort ();
732 obstack_free (&block_aux_obstack, first_block_aux_obj);
733 first_block_aux_obj = NULL;
735 clear_aux_for_blocks ();
738 /* Allocate a memory edge of SIZE as BB->aux. The obstack must
739 be first initialized by alloc_aux_for_edges. */
741 inline void
742 alloc_aux_for_edge (edge e, int size)
744 /* Verify that aux field is clear. */
745 if (e->aux || !first_edge_aux_obj)
746 abort ();
747 e->aux = obstack_alloc (&edge_aux_obstack, size);
748 memset (e->aux, 0, size);
751 /* Initialize the edge_aux_obstack and if SIZE is nonzero, call
752 alloc_aux_for_edge for each basic edge. */
754 void
755 alloc_aux_for_edges (int size)
757 static int initialized;
759 if (!initialized)
761 gcc_obstack_init (&edge_aux_obstack);
762 initialized = 1;
765 /* Check whether AUX data are still allocated. */
766 else if (first_edge_aux_obj)
767 abort ();
769 first_edge_aux_obj = obstack_alloc (&edge_aux_obstack, 0);
770 if (size)
772 basic_block bb;
774 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
776 edge e;
778 for (e = bb->succ; e; e = e->succ_next)
779 alloc_aux_for_edge (e, size);
784 /* Clear AUX pointers of all edges. */
786 void
787 clear_aux_for_edges (void)
789 basic_block bb;
790 edge e;
792 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
794 for (e = bb->succ; e; e = e->succ_next)
795 e->aux = NULL;
799 /* Free data allocated in edge_aux_obstack and clear AUX pointers
800 of all edges. */
802 void
803 free_aux_for_edges (void)
805 if (!first_edge_aux_obj)
806 abort ();
807 obstack_free (&edge_aux_obstack, first_edge_aux_obj);
808 first_edge_aux_obj = NULL;
810 clear_aux_for_edges ();
813 /* Verify the CFG consistency.
815 Currently it does following checks edge and basic block list correctness
816 and calls into IL dependent checking then. */
817 void
818 verify_flow_info (void)
820 size_t *edge_checksum;
821 int num_bb_notes, err = 0;
822 basic_block bb, last_bb_seen;
823 basic_block *last_visited;
825 last_visited = xcalloc (last_basic_block + 2, sizeof (basic_block));
826 edge_checksum = xcalloc (last_basic_block + 2, sizeof (size_t));
828 /* Check bb chain & numbers. */
829 last_bb_seen = ENTRY_BLOCK_PTR;
830 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR->next_bb, NULL, next_bb)
832 if (bb != EXIT_BLOCK_PTR
833 && bb != BASIC_BLOCK (bb->index))
835 error ("bb %d on wrong place", bb->index);
836 err = 1;
839 if (bb->prev_bb != last_bb_seen)
841 error ("prev_bb of %d should be %d, not %d",
842 bb->index, last_bb_seen->index, bb->prev_bb->index);
843 err = 1;
846 last_bb_seen = bb;
849 /* Now check the basic blocks (boundaries etc.) */
850 FOR_EACH_BB_REVERSE (bb)
852 int n_fallthru = 0;
853 edge e;
855 if (bb->count < 0)
857 error ("verify_flow_info: Wrong count of block %i %i",
858 bb->index, (int)bb->count);
859 err = 1;
861 if (bb->frequency < 0)
863 error ("verify_flow_info: Wrong frequency of block %i %i",
864 bb->index, bb->frequency);
865 err = 1;
867 for (e = bb->succ; e; e = e->succ_next)
869 if (last_visited [e->dest->index + 2] == bb)
871 error ("verify_flow_info: Duplicate edge %i->%i",
872 e->src->index, e->dest->index);
873 err = 1;
875 if (e->probability < 0 || e->probability > REG_BR_PROB_BASE)
877 error ("verify_flow_info: Wrong probability of edge %i->%i %i",
878 e->src->index, e->dest->index, e->probability);
879 err = 1;
881 if (e->count < 0)
883 error ("verify_flow_info: Wrong count of edge %i->%i %i",
884 e->src->index, e->dest->index, (int)e->count);
885 err = 1;
888 last_visited [e->dest->index + 2] = bb;
890 if (e->flags & EDGE_FALLTHRU)
891 n_fallthru++;
893 if (e->src != bb)
895 error ("verify_flow_info: Basic block %d succ edge is corrupted",
896 bb->index);
897 fprintf (stderr, "Predecessor: ");
898 dump_edge_info (stderr, e, 0);
899 fprintf (stderr, "\nSuccessor: ");
900 dump_edge_info (stderr, e, 1);
901 fprintf (stderr, "\n");
902 err = 1;
905 edge_checksum[e->dest->index + 2] += (size_t) e;
907 if (n_fallthru > 1)
909 error ("Wrong amount of branch edges after unconditional jump %i", bb->index);
910 err = 1;
913 for (e = bb->pred; e; e = e->pred_next)
915 if (e->dest != bb)
917 error ("basic block %d pred edge is corrupted", bb->index);
918 fputs ("Predecessor: ", stderr);
919 dump_edge_info (stderr, e, 0);
920 fputs ("\nSuccessor: ", stderr);
921 dump_edge_info (stderr, e, 1);
922 fputc ('\n', stderr);
923 err = 1;
925 edge_checksum[e->dest->index + 2] -= (size_t) e;
929 /* Complete edge checksumming for ENTRY and EXIT. */
931 edge e;
933 for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
934 edge_checksum[e->dest->index + 2] += (size_t) e;
936 for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
937 edge_checksum[e->dest->index + 2] -= (size_t) e;
940 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
941 if (edge_checksum[bb->index + 2])
943 error ("basic block %i edge lists are corrupted", bb->index);
944 err = 1;
947 num_bb_notes = 0;
948 last_bb_seen = ENTRY_BLOCK_PTR;
950 /* Clean up. */
951 free (last_visited);
952 free (edge_checksum);
953 err |= cfg_hooks->cfgh_verify_flow_info ();
954 if (err)
955 internal_error ("verify_flow_info failed");
958 /* Print out one basic block with live information at start and end. */
960 void
961 dump_bb (basic_block bb, FILE *outf)
963 edge e;
965 fprintf (outf, ";; Basic block %d, loop depth %d, count ",
966 bb->index, bb->loop_depth);
967 fprintf (outf, HOST_WIDEST_INT_PRINT_DEC, (HOST_WIDEST_INT) bb->count);
968 putc ('\n', outf);
969 fputs (";; Predecessors: ", outf);
970 for (e = bb->pred; e; e = e->pred_next)
971 dump_edge_info (outf, e, 0);
972 putc ('\n', outf);
974 cfg_hooks->dump_bb (bb, outf);
976 fputs (";; Successors: ", outf);
977 for (e = bb->succ; e; e = e->succ_next)
978 dump_edge_info (outf, e, 1);
979 putc ('\n', outf);
982 void
983 debug_bb (basic_block bb)
985 dump_bb (bb, stderr);
988 basic_block
989 debug_bb_n (int n)
991 basic_block bb = BASIC_BLOCK (n);
992 dump_bb (bb, stderr);
993 return bb;