OSDN Git Service

* de.po: Update.
[pf3gnuchains/gcc-fork.git] / gcc / cfghooks.c
1 /* Hooks for cfg representation specific functions.
2    Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3    Contributed by Sebastian Pop <s.pop@laposte.net>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
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
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "basic-block.h"
29 #include "tree-flow.h"
30 #include "timevar.h"
31 #include "toplev.h"
32
33 /* A pointer to one of the hooks containers.  */
34 static struct cfg_hooks *cfg_hooks;
35
36 /* Initialization of functions specific to the rtl IR.  */
37 void
38 rtl_register_cfg_hooks (void)
39 {
40   cfg_hooks = &rtl_cfg_hooks;
41 }
42
43 /* Initialization of functions specific to the rtl IR.  */
44 void
45 cfg_layout_rtl_register_cfg_hooks (void)
46 {
47   cfg_hooks = &cfg_layout_rtl_cfg_hooks;
48 }
49
50 /* Initialization of functions specific to the tree IR.  */
51
52 void
53 tree_register_cfg_hooks (void)
54 {
55   cfg_hooks = &tree_cfg_hooks;
56 }
57
58 /* Returns current ir type (rtl = 0, trees = 1).  */
59
60 int
61 ir_type (void)
62 {
63   return cfg_hooks == &tree_cfg_hooks ? 1 : 0;
64 }
65
66 /* Verify the CFG consistency.
67
68    Currently it does following: checks edge and basic block list correctness
69    and calls into IL dependent checking then.  */
70
71 void
72 verify_flow_info (void)
73 {
74   size_t *edge_checksum;
75   int num_bb_notes, err = 0;
76   basic_block bb, last_bb_seen;
77   basic_block *last_visited;
78
79   timevar_push (TV_CFG_VERIFY);
80   last_visited = xcalloc (last_basic_block + 2, sizeof (basic_block));
81   edge_checksum = xcalloc (last_basic_block + 2, sizeof (size_t));
82
83   /* Check bb chain & numbers.  */
84   last_bb_seen = ENTRY_BLOCK_PTR;
85   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR->next_bb, NULL, next_bb)
86     {
87       if (bb != EXIT_BLOCK_PTR
88           && bb != BASIC_BLOCK (bb->index))
89         {
90           error ("bb %d on wrong place", bb->index);
91           err = 1;
92         }
93
94       if (bb->prev_bb != last_bb_seen)
95         {
96           error ("prev_bb of %d should be %d, not %d",
97                  bb->index, last_bb_seen->index, bb->prev_bb->index);
98           err = 1;
99         }
100
101       last_bb_seen = bb;
102     }
103
104   /* Now check the basic blocks (boundaries etc.) */
105   FOR_EACH_BB_REVERSE (bb)
106     {
107       int n_fallthru = 0;
108       edge e;
109       edge_iterator ei;
110
111       if (bb->count < 0)
112         {
113           error ("verify_flow_info: Wrong count of block %i %i",
114                  bb->index, (int)bb->count);
115           err = 1;
116         }
117       if (bb->frequency < 0)
118         {
119           error ("verify_flow_info: Wrong frequency of block %i %i",
120                  bb->index, bb->frequency);
121           err = 1;
122         }
123       FOR_EACH_EDGE (e, ei, bb->succs)
124         {
125           if (last_visited [e->dest->index + 2] == bb)
126             {
127               error ("verify_flow_info: Duplicate edge %i->%i",
128                      e->src->index, e->dest->index);
129               err = 1;
130             }
131           if (e->probability < 0 || e->probability > REG_BR_PROB_BASE)
132             {
133               error ("verify_flow_info: Wrong probability of edge %i->%i %i",
134                      e->src->index, e->dest->index, e->probability);
135               err = 1;
136             }
137           if (e->count < 0)
138             {
139               error ("verify_flow_info: Wrong count of edge %i->%i %i",
140                      e->src->index, e->dest->index, (int)e->count);
141               err = 1;
142             }
143
144           last_visited [e->dest->index + 2] = bb;
145
146           if (e->flags & EDGE_FALLTHRU)
147             n_fallthru++;
148
149           if (e->src != bb)
150             {
151               error ("verify_flow_info: Basic block %d succ edge is corrupted",
152                      bb->index);
153               fprintf (stderr, "Predecessor: ");
154               dump_edge_info (stderr, e, 0);
155               fprintf (stderr, "\nSuccessor: ");
156               dump_edge_info (stderr, e, 1);
157               fprintf (stderr, "\n");
158               err = 1;
159             }
160
161           edge_checksum[e->dest->index + 2] += (size_t) e;
162         }
163       if (n_fallthru > 1)
164         {
165           error ("Wrong amount of branch edges after unconditional jump %i", bb->index);
166           err = 1;
167         }
168
169       FOR_EACH_EDGE (e, ei, bb->preds)
170         {
171           if (e->dest != bb)
172             {
173               error ("basic block %d pred edge is corrupted", bb->index);
174               fputs ("Predecessor: ", stderr);
175               dump_edge_info (stderr, e, 0);
176               fputs ("\nSuccessor: ", stderr);
177               dump_edge_info (stderr, e, 1);
178               fputc ('\n', stderr);
179               err = 1;
180             }
181           edge_checksum[e->dest->index + 2] -= (size_t) e;
182         }
183     }
184
185   /* Complete edge checksumming for ENTRY and EXIT.  */
186   {
187     edge e;
188     edge_iterator ei;
189
190     FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
191       edge_checksum[e->dest->index + 2] += (size_t) e;
192
193     FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
194       edge_checksum[e->dest->index + 2] -= (size_t) e;
195   }
196
197   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
198     if (edge_checksum[bb->index + 2])
199       {
200         error ("basic block %i edge lists are corrupted", bb->index);
201         err = 1;
202       }
203
204   num_bb_notes = 0;
205   last_bb_seen = ENTRY_BLOCK_PTR;
206
207   /* Clean up.  */
208   free (last_visited);
209   free (edge_checksum);
210
211   if (cfg_hooks->verify_flow_info)
212     err |= cfg_hooks->verify_flow_info ();
213   if (err)
214     internal_error ("verify_flow_info failed");
215   timevar_pop (TV_CFG_VERIFY);
216 }
217
218 /* Print out one basic block.  This function takes care of the purely
219    graph related information.  The cfg hook for the active representation
220    should dump representation-specific information.  */
221
222 void
223 dump_bb (basic_block bb, FILE *outf, int indent)
224 {
225   edge e;
226   edge_iterator ei;
227   char *s_indent;
228  
229   s_indent = alloca ((size_t) indent + 1);
230   memset (s_indent, ' ', (size_t) indent);
231   s_indent[indent] = '\0';
232
233   fprintf (outf, ";;%s basic block %d, loop depth %d, count ",
234            s_indent, bb->index, bb->loop_depth);
235   fprintf (outf, HOST_WIDEST_INT_PRINT_DEC, (HOST_WIDEST_INT) bb->count);
236   putc ('\n', outf);
237
238   fprintf (outf, ";;%s prev block ", s_indent);
239   if (bb->prev_bb)
240     fprintf (outf, "%d, ", bb->prev_bb->index);
241   else
242     fprintf (outf, "(nil), ");
243   fprintf (outf, "next block ");
244   if (bb->next_bb)
245     fprintf (outf, "%d", bb->next_bb->index);
246   else
247     fprintf (outf, "(nil)");
248   putc ('\n', outf);
249
250   fprintf (outf, ";;%s pred:      ", s_indent);
251   FOR_EACH_EDGE (e, ei, bb->preds)
252     dump_edge_info (outf, e, 0);
253   putc ('\n', outf);
254
255   fprintf (outf, ";;%s succ:      ", s_indent);
256   FOR_EACH_EDGE (e, ei, bb->succs)
257     dump_edge_info (outf, e, 1);
258   putc ('\n', outf);
259
260   if (cfg_hooks->dump_bb)
261     cfg_hooks->dump_bb (bb, outf, indent);
262 }
263
264 /* Redirect edge E to the given basic block DEST and update underlying program
265    representation.  Returns edge representing redirected branch (that may not
266    be equivalent to E in the case of duplicate edges being removed) or NULL
267    if edge is not easily redirectable for whatever reason.  */
268
269 edge
270 redirect_edge_and_branch (edge e, basic_block dest)
271 {
272   edge ret;
273
274   if (!cfg_hooks->redirect_edge_and_branch)
275     internal_error ("%s does not support redirect_edge_and_branch.",
276                     cfg_hooks->name);
277
278   ret = cfg_hooks->redirect_edge_and_branch (e, dest);
279
280   return ret;
281 }
282
283 /* Redirect the edge E to basic block DEST even if it requires creating
284    of a new basic block; then it returns the newly created basic block.
285    Aborts when redirection is impossible.  */
286
287 basic_block
288 redirect_edge_and_branch_force (edge e, basic_block dest)
289 {
290   basic_block ret;
291
292   if (!cfg_hooks->redirect_edge_and_branch_force)
293     internal_error ("%s does not support redirect_edge_and_branch_force.",
294                     cfg_hooks->name);
295
296   ret = cfg_hooks->redirect_edge_and_branch_force (e, dest);
297
298   return ret;
299 }
300
301 /* Splits basic block BB after the specified instruction I (but at least after
302    the labels).  If I is NULL, splits just after labels.  The newly created edge
303    is returned.  The new basic block is created just after the old one.  */
304
305 edge
306 split_block (basic_block bb, void *i)
307 {
308   basic_block new_bb;
309
310   if (!cfg_hooks->split_block)
311     internal_error ("%s does not support split_block.", cfg_hooks->name);
312
313   new_bb = cfg_hooks->split_block (bb, i);
314   if (!new_bb)
315     return NULL;
316
317   new_bb->count = bb->count;
318   new_bb->frequency = bb->frequency;
319   new_bb->loop_depth = bb->loop_depth;
320
321   if (dom_computed[CDI_DOMINATORS] >= DOM_CONS_OK)
322     {
323       redirect_immediate_dominators (CDI_DOMINATORS, bb, new_bb);
324       set_immediate_dominator (CDI_DOMINATORS, new_bb, bb);
325     }
326
327   return make_single_succ_edge (bb, new_bb, EDGE_FALLTHRU);
328 }
329
330 /* Splits block BB just after labels.  The newly created edge is returned.  */
331
332 edge
333 split_block_after_labels (basic_block bb)
334 {
335   return split_block (bb, NULL);
336 }
337
338 /* Moves block BB immediately after block AFTER.  Returns false if the
339    movement was impossible.  */
340
341 bool
342 move_block_after (basic_block bb, basic_block after)
343 {
344   bool ret;
345
346   if (!cfg_hooks->move_block_after)
347     internal_error ("%s does not support move_block_after.", cfg_hooks->name);
348
349   ret = cfg_hooks->move_block_after (bb, after);
350
351   return ret;
352 }
353
354 /* Deletes the basic block BB.  */
355
356 void
357 delete_basic_block (basic_block bb)
358 {
359   if (!cfg_hooks->delete_basic_block)
360     internal_error ("%s does not support delete_basic_block.", cfg_hooks->name);
361
362   cfg_hooks->delete_basic_block (bb);
363
364   /* Remove the edges into and out of this block.  Note that there may
365      indeed be edges in, if we are removing an unreachable loop.  */
366   while (EDGE_COUNT (bb->preds) != 0)
367     remove_edge (EDGE_PRED (bb, 0));
368   while (EDGE_COUNT (bb->succs) != 0)
369     remove_edge (EDGE_SUCC (bb, 0));
370
371   VEC_truncate (edge, bb->preds, 0);
372   VEC_truncate (edge, bb->succs, 0);
373
374   if (dom_computed[CDI_DOMINATORS])
375     delete_from_dominance_info (CDI_DOMINATORS, bb);
376   if (dom_computed[CDI_POST_DOMINATORS])
377     delete_from_dominance_info (CDI_POST_DOMINATORS, bb);
378
379   /* Remove the basic block from the array.  */
380   expunge_block (bb);
381 }
382
383 /* Splits edge E and returns the newly created basic block.  */
384
385 basic_block
386 split_edge (edge e)
387 {
388   basic_block ret;
389   gcov_type count = e->count;
390   int freq = EDGE_FREQUENCY (e);
391   edge f;
392   bool irr = (e->flags & EDGE_IRREDUCIBLE_LOOP) != 0;
393
394   if (!cfg_hooks->split_edge)
395     internal_error ("%s does not support split_edge.", cfg_hooks->name);
396
397   ret = cfg_hooks->split_edge (e);
398   ret->count = count;
399   ret->frequency = freq;
400   EDGE_SUCC (ret, 0)->probability = REG_BR_PROB_BASE;
401   EDGE_SUCC (ret, 0)->count = count;
402
403   if (irr)
404     {
405       ret->flags |= BB_IRREDUCIBLE_LOOP;
406       EDGE_PRED (ret, 0)->flags |= EDGE_IRREDUCIBLE_LOOP;
407       EDGE_SUCC (ret, 0)->flags |= EDGE_IRREDUCIBLE_LOOP;
408     }
409
410   if (dom_computed[CDI_DOMINATORS])
411     set_immediate_dominator (CDI_DOMINATORS, ret, EDGE_PRED (ret, 0)->src);
412
413   if (dom_computed[CDI_DOMINATORS] >= DOM_NO_FAST_QUERY)
414     {
415       /* There are two cases:
416
417          If the immediate dominator of e->dest is not e->src, it
418          remains unchanged.
419
420          If immediate dominator of e->dest is e->src, it may become
421          ret, provided that all other predecessors of e->dest are
422          dominated by e->dest.  */
423
424       if (get_immediate_dominator (CDI_DOMINATORS, EDGE_SUCC (ret, 0)->dest)
425           == EDGE_PRED (ret, 0)->src)
426         {
427           edge_iterator ei;
428           FOR_EACH_EDGE (f, ei, EDGE_SUCC (ret, 0)->dest->preds)
429             {
430               if (f == EDGE_SUCC (ret, 0))
431                 continue;
432
433               if (!dominated_by_p (CDI_DOMINATORS, f->src,
434                                    EDGE_SUCC (ret, 0)->dest))
435                 break;
436             }
437
438           if (!f)
439             set_immediate_dominator (CDI_DOMINATORS, EDGE_SUCC (ret, 0)->dest, ret);
440         }
441     };
442
443   return ret;
444 }
445
446 /* Creates a new basic block just after the basic block AFTER.
447    HEAD and END are the first and the last statement belonging
448    to the block.  If both are NULL, an empty block is created.  */
449
450 basic_block
451 create_basic_block (void *head, void *end, basic_block after)
452 {
453   basic_block ret;
454
455   if (!cfg_hooks->create_basic_block)
456     internal_error ("%s does not support create_basic_block.", cfg_hooks->name);
457
458   ret = cfg_hooks->create_basic_block (head, end, after);
459
460   if (dom_computed[CDI_DOMINATORS])
461     add_to_dominance_info (CDI_DOMINATORS, ret);
462   if (dom_computed[CDI_POST_DOMINATORS])
463     add_to_dominance_info (CDI_POST_DOMINATORS, ret);
464
465   return ret;
466 }
467
468 /* Creates an empty basic block just after basic block AFTER.  */
469
470 basic_block
471 create_empty_bb (basic_block after)
472 {
473   return create_basic_block (NULL, NULL, after);
474 }
475
476 /* Checks whether we may merge blocks BB1 and BB2.  */
477
478 bool
479 can_merge_blocks_p (basic_block bb1, basic_block bb2)
480 {
481   bool ret;
482
483   if (!cfg_hooks->can_merge_blocks_p)
484     internal_error ("%s does not support can_merge_blocks_p.", cfg_hooks->name);
485
486   ret = cfg_hooks->can_merge_blocks_p (bb1, bb2);
487
488   return ret;
489 }
490
491 void
492 predict_edge (edge e, enum br_predictor predictor, int probability)
493 {
494   if (!cfg_hooks->predict_edge)
495     internal_error ("%s does not support predict_edge.", cfg_hooks->name);
496
497   cfg_hooks->predict_edge (e, predictor, probability);
498 }
499
500 bool
501 predicted_by_p (basic_block bb, enum br_predictor predictor)
502 {
503   if (!cfg_hooks->predict_edge)
504     internal_error ("%s does not support predicted_by_p.", cfg_hooks->name);
505
506   return cfg_hooks->predicted_by_p (bb, predictor);
507 }
508
509 /* Merges basic block B into basic block A.  */
510
511 void
512 merge_blocks (basic_block a, basic_block b)
513 {
514   edge e;
515   edge_iterator ei;
516
517   if (!cfg_hooks->merge_blocks)
518     internal_error ("%s does not support merge_blocks.", cfg_hooks->name);
519
520   cfg_hooks->merge_blocks (a, b);
521
522   /* Normally there should only be one successor of A and that is B, but
523      partway though the merge of blocks for conditional_execution we'll
524      be merging a TEST block with THEN and ELSE successors.  Free the
525      whole lot of them and hope the caller knows what they're doing.  */
526
527   while (EDGE_COUNT (a->succs) != 0)
528    remove_edge (EDGE_SUCC (a, 0));
529
530   /* Adjust the edges out of B for the new owner.  */
531   FOR_EACH_EDGE (e, ei, b->succs)
532     e->src = a;
533   a->succs = b->succs;
534   a->flags |= b->flags;
535
536   /* B hasn't quite yet ceased to exist.  Attempt to prevent mishap.  */
537   b->preds = b->succs = NULL;
538   a->global_live_at_end = b->global_live_at_end;
539
540   if (dom_computed[CDI_DOMINATORS])
541     redirect_immediate_dominators (CDI_DOMINATORS, b, a);
542
543   if (dom_computed[CDI_DOMINATORS])
544     delete_from_dominance_info (CDI_DOMINATORS, b);
545   if (dom_computed[CDI_POST_DOMINATORS])
546     delete_from_dominance_info (CDI_POST_DOMINATORS, b);
547
548   expunge_block (b);
549 }
550
551 /* Split BB into entry part and the rest (the rest is the newly created block).
552    Redirect those edges for that REDIRECT_EDGE_P returns true to the entry
553    part.  Returns the edge connecting the entry part to the rest.  */
554
555 edge
556 make_forwarder_block (basic_block bb, bool (*redirect_edge_p) (edge),
557                       void (*new_bb_cbk) (basic_block))
558 {
559   edge e, fallthru;
560   edge_iterator ei;
561   basic_block dummy, jump;
562
563   if (!cfg_hooks->make_forwarder_block)
564     internal_error ("%s does not support make_forwarder_block.",
565                     cfg_hooks->name);
566
567   fallthru = split_block_after_labels (bb);
568   dummy = fallthru->src;
569   bb = fallthru->dest;
570
571   /* Redirect back edges we want to keep.  */
572   for (ei = ei_start (dummy->preds); (e = ei_safe_edge (ei)); )
573     {
574       if (redirect_edge_p (e))
575         {
576           ei_next (&ei);
577           continue;
578         }
579
580       dummy->frequency -= EDGE_FREQUENCY (e);
581       dummy->count -= e->count;
582       if (dummy->frequency < 0)
583         dummy->frequency = 0;
584       if (dummy->count < 0)
585         dummy->count = 0;
586       fallthru->count -= e->count;
587       if (fallthru->count < 0)
588         fallthru->count = 0;
589
590       jump = redirect_edge_and_branch_force (e, bb);
591       if (jump)
592         new_bb_cbk (jump);
593     }
594
595   if (dom_computed[CDI_DOMINATORS] >= DOM_CONS_OK)
596     {
597       basic_block doms_to_fix[2];
598
599       doms_to_fix[0] = dummy;
600       doms_to_fix[1] = bb;
601       iterate_fix_dominators (CDI_DOMINATORS, doms_to_fix, 2);
602     }
603
604   cfg_hooks->make_forwarder_block (fallthru);
605
606   return fallthru;
607 }
608
609 void
610 tidy_fallthru_edge (edge e)
611 {
612   if (cfg_hooks->tidy_fallthru_edge)
613     cfg_hooks->tidy_fallthru_edge (e);
614 }
615
616 /* Fix up edges that now fall through, or rather should now fall through
617    but previously required a jump around now deleted blocks.  Simplify
618    the search by only examining blocks numerically adjacent, since this
619    is how find_basic_blocks created them.  */
620
621 void
622 tidy_fallthru_edges (void)
623 {
624   basic_block b, c;
625
626   if (!cfg_hooks->tidy_fallthru_edge)
627     return;
628
629   if (ENTRY_BLOCK_PTR->next_bb == EXIT_BLOCK_PTR)
630     return;
631
632   FOR_BB_BETWEEN (b, ENTRY_BLOCK_PTR->next_bb, EXIT_BLOCK_PTR->prev_bb, next_bb)
633     {
634       edge s;
635
636       c = b->next_bb;
637
638       /* We care about simple conditional or unconditional jumps with
639          a single successor.
640
641          If we had a conditional branch to the next instruction when
642          find_basic_blocks was called, then there will only be one
643          out edge for the block which ended with the conditional
644          branch (since we do not create duplicate edges).
645
646          Furthermore, the edge will be marked as a fallthru because we
647          merge the flags for the duplicate edges.  So we do not want to
648          check that the edge is not a FALLTHRU edge.  */
649
650       if (EDGE_COUNT (b->succs) == 1)
651         {
652           s = EDGE_SUCC (b, 0);
653           if (! (s->flags & EDGE_COMPLEX)
654               && s->dest == c
655               && !find_reg_note (BB_END (b), REG_CROSSING_JUMP, NULL_RTX))
656             tidy_fallthru_edge (s);
657         }
658     }
659 }
660
661 /* Returns true if we can duplicate basic block BB.  */
662
663 bool
664 can_duplicate_block_p (basic_block bb)
665 {
666   edge e;
667   edge_iterator ei;
668
669   if (!cfg_hooks->can_duplicate_block_p)
670     internal_error ("%s does not support can_duplicate_block_p.",
671                     cfg_hooks->name);
672
673   if (bb == EXIT_BLOCK_PTR || bb == ENTRY_BLOCK_PTR)
674     return false;
675
676   /* Duplicating fallthru block to exit would require adding a jump
677      and splitting the real last BB.  */
678   FOR_EACH_EDGE (e, ei, bb->succs)
679     if (e->dest == EXIT_BLOCK_PTR && e->flags & EDGE_FALLTHRU)
680        return false;
681
682   return cfg_hooks->can_duplicate_block_p (bb);
683 }
684
685 /* Duplicates basic block BB and redirects edge E to it.  Returns the
686    new basic block.  */
687
688 basic_block
689 duplicate_block (basic_block bb, edge e)
690 {
691   edge s, n;
692   basic_block new_bb;
693   gcov_type new_count = e ? e->count : 0;
694   edge_iterator ei;
695
696   if (!cfg_hooks->duplicate_block)
697     internal_error ("%s does not support duplicate_block.",
698                     cfg_hooks->name);
699
700   if (bb->count < new_count)
701     new_count = bb->count;
702
703 #ifdef ENABLE_CHECKING
704   gcc_assert (can_duplicate_block_p (bb));
705 #endif
706
707   new_bb = cfg_hooks->duplicate_block (bb);
708
709   new_bb->loop_depth = bb->loop_depth;
710   new_bb->flags = bb->flags;
711   FOR_EACH_EDGE (s, ei, bb->succs)
712     {
713       /* Since we are creating edges from a new block to successors
714          of another block (which therefore are known to be disjoint), there
715          is no need to actually check for duplicated edges.  */
716       n = unchecked_make_edge (new_bb, s->dest, s->flags);
717       n->probability = s->probability;
718       if (e && bb->count)
719         {
720           /* Take care for overflows!  */
721           n->count = s->count * (new_count * 10000 / bb->count) / 10000;
722           s->count -= n->count;
723         }
724       else
725         n->count = s->count;
726       n->aux = s->aux;
727     }
728
729   if (e)
730     {
731       new_bb->count = new_count;
732       bb->count -= new_count;
733
734       new_bb->frequency = EDGE_FREQUENCY (e);
735       bb->frequency -= EDGE_FREQUENCY (e);
736
737       redirect_edge_and_branch_force (e, new_bb);
738
739       if (bb->count < 0)
740         bb->count = 0;
741       if (bb->frequency < 0)
742         bb->frequency = 0;
743     }
744   else
745     {
746       new_bb->count = bb->count;
747       new_bb->frequency = bb->frequency;
748     }
749
750   new_bb->rbi->original = bb;
751   bb->rbi->copy = new_bb;
752
753   return new_bb;
754 }
755
756 /* Return 1 if BB ends with a call, possibly followed by some
757    instructions that must stay with the call, 0 otherwise.  */
758
759 bool 
760 block_ends_with_call_p (basic_block bb)
761 {
762   if (!cfg_hooks->block_ends_with_call_p)
763     internal_error ("%s does not support block_ends_with_call_p", cfg_hooks->name);
764
765   return (cfg_hooks->block_ends_with_call_p) (bb);
766 }
767
768 /* Return 1 if BB ends with a conditional branch, 0 otherwise.  */
769
770 bool 
771 block_ends_with_condjump_p (basic_block bb)
772 {
773   if (!cfg_hooks->block_ends_with_condjump_p)
774     internal_error ("%s does not support block_ends_with_condjump_p",
775                     cfg_hooks->name);
776
777   return (cfg_hooks->block_ends_with_condjump_p) (bb);
778 }
779
780 /* Add fake edges to the function exit for any non constant and non noreturn
781    calls, volatile inline assembly in the bitmap of blocks specified by
782    BLOCKS or to the whole CFG if BLOCKS is zero.  Return the number of blocks
783    that were split.
784
785    The goal is to expose cases in which entering a basic block does not imply
786    that all subsequent instructions must be executed.  */
787
788 int
789 flow_call_edges_add (sbitmap blocks)
790 {
791   if (!cfg_hooks->flow_call_edges_add)
792     internal_error ("%s does not support flow_call_edges_add", 
793                     cfg_hooks->name);
794
795   return (cfg_hooks->flow_call_edges_add) (blocks);
796 }