]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/cfghooks.c
2015-10-29 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / cfghooks.c
1 /* Hooks for cfg representation specific functions.
2 Copyright (C) 2003-2015 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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "cfghooks.h"
28 #include "timevar.h"
29 #include "pretty-print.h"
30 #include "diagnostic-core.h"
31 #include "dumpfile.h"
32 #include "alias.h"
33 #include "cfganal.h"
34 #include "tree-ssa.h"
35 #include "cfgloop.h"
36
37 /* A pointer to one of the hooks containers. */
38 static struct cfg_hooks *cfg_hooks;
39
40 /* Initialization of functions specific to the rtl IR. */
41 void
42 rtl_register_cfg_hooks (void)
43 {
44 cfg_hooks = &rtl_cfg_hooks;
45 }
46
47 /* Initialization of functions specific to the rtl IR. */
48 void
49 cfg_layout_rtl_register_cfg_hooks (void)
50 {
51 cfg_hooks = &cfg_layout_rtl_cfg_hooks;
52 }
53
54 /* Initialization of functions specific to the tree IR. */
55
56 void
57 gimple_register_cfg_hooks (void)
58 {
59 cfg_hooks = &gimple_cfg_hooks;
60 }
61
62 struct cfg_hooks
63 get_cfg_hooks (void)
64 {
65 return *cfg_hooks;
66 }
67
68 void
69 set_cfg_hooks (struct cfg_hooks new_cfg_hooks)
70 {
71 *cfg_hooks = new_cfg_hooks;
72 }
73
74 /* Returns current ir type. */
75
76 enum ir_type
77 current_ir_type (void)
78 {
79 if (cfg_hooks == &gimple_cfg_hooks)
80 return IR_GIMPLE;
81 else if (cfg_hooks == &rtl_cfg_hooks)
82 return IR_RTL_CFGRTL;
83 else if (cfg_hooks == &cfg_layout_rtl_cfg_hooks)
84 return IR_RTL_CFGLAYOUT;
85 else
86 gcc_unreachable ();
87 }
88
89 /* Verify the CFG consistency.
90
91 Currently it does following: checks edge and basic block list correctness
92 and calls into IL dependent checking then. */
93
94 DEBUG_FUNCTION void
95 verify_flow_info (void)
96 {
97 size_t *edge_checksum;
98 int err = 0;
99 basic_block bb, last_bb_seen;
100 basic_block *last_visited;
101
102 timevar_push (TV_CFG_VERIFY);
103 last_visited = XCNEWVEC (basic_block, last_basic_block_for_fn (cfun));
104 edge_checksum = XCNEWVEC (size_t, last_basic_block_for_fn (cfun));
105
106 /* Check bb chain & numbers. */
107 last_bb_seen = ENTRY_BLOCK_PTR_FOR_FN (cfun);
108 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb, NULL, next_bb)
109 {
110 if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
111 && bb != BASIC_BLOCK_FOR_FN (cfun, bb->index))
112 {
113 error ("bb %d on wrong place", bb->index);
114 err = 1;
115 }
116
117 if (bb->prev_bb != last_bb_seen)
118 {
119 error ("prev_bb of %d should be %d, not %d",
120 bb->index, last_bb_seen->index, bb->prev_bb->index);
121 err = 1;
122 }
123
124 last_bb_seen = bb;
125 }
126
127 /* Now check the basic blocks (boundaries etc.) */
128 FOR_EACH_BB_REVERSE_FN (bb, cfun)
129 {
130 int n_fallthru = 0;
131 edge e;
132 edge_iterator ei;
133
134 if (bb->loop_father != NULL && current_loops == NULL)
135 {
136 error ("verify_flow_info: Block %i has loop_father, but there are no loops",
137 bb->index);
138 err = 1;
139 }
140 if (bb->loop_father == NULL && current_loops != NULL)
141 {
142 error ("verify_flow_info: Block %i lacks loop_father", bb->index);
143 err = 1;
144 }
145
146 if (bb->count < 0)
147 {
148 error ("verify_flow_info: Wrong count of block %i %i",
149 bb->index, (int)bb->count);
150 err = 1;
151 }
152 if (bb->frequency < 0)
153 {
154 error ("verify_flow_info: Wrong frequency of block %i %i",
155 bb->index, bb->frequency);
156 err = 1;
157 }
158 FOR_EACH_EDGE (e, ei, bb->succs)
159 {
160 if (last_visited [e->dest->index] == bb)
161 {
162 error ("verify_flow_info: Duplicate edge %i->%i",
163 e->src->index, e->dest->index);
164 err = 1;
165 }
166 if (e->probability < 0 || e->probability > REG_BR_PROB_BASE)
167 {
168 error ("verify_flow_info: Wrong probability of edge %i->%i %i",
169 e->src->index, e->dest->index, e->probability);
170 err = 1;
171 }
172 if (e->count < 0)
173 {
174 error ("verify_flow_info: Wrong count of edge %i->%i %i",
175 e->src->index, e->dest->index, (int)e->count);
176 err = 1;
177 }
178
179 last_visited [e->dest->index] = bb;
180
181 if (e->flags & EDGE_FALLTHRU)
182 n_fallthru++;
183
184 if (e->src != bb)
185 {
186 error ("verify_flow_info: Basic block %d succ edge is corrupted",
187 bb->index);
188 fprintf (stderr, "Predecessor: ");
189 dump_edge_info (stderr, e, TDF_DETAILS, 0);
190 fprintf (stderr, "\nSuccessor: ");
191 dump_edge_info (stderr, e, TDF_DETAILS, 1);
192 fprintf (stderr, "\n");
193 err = 1;
194 }
195
196 edge_checksum[e->dest->index] += (size_t) e;
197 }
198 if (n_fallthru > 1)
199 {
200 error ("wrong amount of branch edges after unconditional jump %i", bb->index);
201 err = 1;
202 }
203
204 FOR_EACH_EDGE (e, ei, bb->preds)
205 {
206 if (e->dest != bb)
207 {
208 error ("basic block %d pred edge is corrupted", bb->index);
209 fputs ("Predecessor: ", stderr);
210 dump_edge_info (stderr, e, TDF_DETAILS, 0);
211 fputs ("\nSuccessor: ", stderr);
212 dump_edge_info (stderr, e, TDF_DETAILS, 1);
213 fputc ('\n', stderr);
214 err = 1;
215 }
216
217 if (ei.index != e->dest_idx)
218 {
219 error ("basic block %d pred edge is corrupted", bb->index);
220 error ("its dest_idx should be %d, not %d",
221 ei.index, e->dest_idx);
222 fputs ("Predecessor: ", stderr);
223 dump_edge_info (stderr, e, TDF_DETAILS, 0);
224 fputs ("\nSuccessor: ", stderr);
225 dump_edge_info (stderr, e, TDF_DETAILS, 1);
226 fputc ('\n', stderr);
227 err = 1;
228 }
229
230 edge_checksum[e->dest->index] -= (size_t) e;
231 }
232 }
233
234 /* Complete edge checksumming for ENTRY and EXIT. */
235 {
236 edge e;
237 edge_iterator ei;
238
239 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs)
240 edge_checksum[e->dest->index] += (size_t) e;
241
242 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
243 edge_checksum[e->dest->index] -= (size_t) e;
244 }
245
246 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
247 if (edge_checksum[bb->index])
248 {
249 error ("basic block %i edge lists are corrupted", bb->index);
250 err = 1;
251 }
252
253 last_bb_seen = ENTRY_BLOCK_PTR_FOR_FN (cfun);
254
255 /* Clean up. */
256 free (last_visited);
257 free (edge_checksum);
258
259 if (cfg_hooks->verify_flow_info)
260 err |= cfg_hooks->verify_flow_info ();
261 if (err)
262 internal_error ("verify_flow_info failed");
263 timevar_pop (TV_CFG_VERIFY);
264 }
265
266 /* Print out one basic block BB to file OUTF. INDENT is printed at the
267 start of each new line. FLAGS are the TDF_* flags in dumpfile.h.
268
269 This function takes care of the purely graph related information.
270 The cfg hook for the active representation should dump
271 representation-specific information. */
272
273 void
274 dump_bb (FILE *outf, basic_block bb, int indent, int flags)
275 {
276 if (flags & TDF_BLOCKS)
277 dump_bb_info (outf, bb, indent, flags, true, false);
278 if (cfg_hooks->dump_bb)
279 cfg_hooks->dump_bb (outf, bb, indent, flags);
280 if (flags & TDF_BLOCKS)
281 dump_bb_info (outf, bb, indent, flags, false, true);
282 fputc ('\n', outf);
283 }
284
285 DEBUG_FUNCTION void
286 debug (basic_block_def &ref)
287 {
288 dump_bb (stderr, &ref, 0, 0);
289 }
290
291 DEBUG_FUNCTION void
292 debug (basic_block_def *ptr)
293 {
294 if (ptr)
295 debug (*ptr);
296 else
297 fprintf (stderr, "<nil>\n");
298 }
299
300
301 /* Dumps basic block BB to pretty-printer PP, for use as a label of
302 a DOT graph record-node. The implementation of this hook is
303 expected to write the label to the stream that is attached to PP.
304 Field separators between instructions are pipe characters printed
305 verbatim. Instructions should be written with some characters
306 escaped, using pp_write_text_as_dot_label_to_stream(). */
307
308 void
309 dump_bb_for_graph (pretty_printer *pp, basic_block bb)
310 {
311 if (!cfg_hooks->dump_bb_for_graph)
312 internal_error ("%s does not support dump_bb_for_graph",
313 cfg_hooks->name);
314 if (bb->count)
315 pp_printf (pp, "COUNT:" "%" PRId64, bb->count);
316 pp_printf (pp, " FREQ:%i |", bb->frequency);
317 pp_write_text_to_stream (pp);
318 if (!(dump_flags & TDF_SLIM))
319 cfg_hooks->dump_bb_for_graph (pp, bb);
320 }
321
322 /* Dump the complete CFG to FILE. FLAGS are the TDF_* flags in dumpfile.h. */
323 void
324 dump_flow_info (FILE *file, int flags)
325 {
326 basic_block bb;
327
328 fprintf (file, "\n%d basic blocks, %d edges.\n", n_basic_blocks_for_fn (cfun),
329 n_edges_for_fn (cfun));
330 FOR_ALL_BB_FN (bb, cfun)
331 dump_bb (file, bb, 0, flags);
332
333 putc ('\n', file);
334 }
335
336 /* Like above, but dump to stderr. To be called from debuggers. */
337 void debug_flow_info (void);
338 DEBUG_FUNCTION void
339 debug_flow_info (void)
340 {
341 dump_flow_info (stderr, TDF_DETAILS);
342 }
343
344 /* Redirect edge E to the given basic block DEST and update underlying program
345 representation. Returns edge representing redirected branch (that may not
346 be equivalent to E in the case of duplicate edges being removed) or NULL
347 if edge is not easily redirectable for whatever reason. */
348
349 edge
350 redirect_edge_and_branch (edge e, basic_block dest)
351 {
352 edge ret;
353
354 if (!cfg_hooks->redirect_edge_and_branch)
355 internal_error ("%s does not support redirect_edge_and_branch",
356 cfg_hooks->name);
357
358 ret = cfg_hooks->redirect_edge_and_branch (e, dest);
359
360 /* If RET != E, then either the redirection failed, or the edge E
361 was removed since RET already lead to the same destination. */
362 if (current_loops != NULL && ret == e)
363 rescan_loop_exit (e, false, false);
364
365 return ret;
366 }
367
368 /* Returns true if it is possible to remove the edge E by redirecting it
369 to the destination of the other edge going from its source. */
370
371 bool
372 can_remove_branch_p (const_edge e)
373 {
374 if (!cfg_hooks->can_remove_branch_p)
375 internal_error ("%s does not support can_remove_branch_p",
376 cfg_hooks->name);
377
378 if (EDGE_COUNT (e->src->succs) != 2)
379 return false;
380
381 return cfg_hooks->can_remove_branch_p (e);
382 }
383
384 /* Removes E, by redirecting it to the destination of the other edge going
385 from its source. Can_remove_branch_p must be true for E, hence this
386 operation cannot fail. */
387
388 void
389 remove_branch (edge e)
390 {
391 edge other;
392 basic_block src = e->src;
393 int irr;
394
395 gcc_assert (EDGE_COUNT (e->src->succs) == 2);
396
397 other = EDGE_SUCC (src, EDGE_SUCC (src, 0) == e);
398 irr = other->flags & EDGE_IRREDUCIBLE_LOOP;
399
400 e = redirect_edge_and_branch (e, other->dest);
401 gcc_assert (e != NULL);
402
403 e->flags &= ~EDGE_IRREDUCIBLE_LOOP;
404 e->flags |= irr;
405 }
406
407 /* Removes edge E from cfg. Unlike remove_branch, it does not update IL. */
408
409 void
410 remove_edge (edge e)
411 {
412 if (current_loops != NULL)
413 rescan_loop_exit (e, false, true);
414
415 /* This is probably not needed, but it doesn't hurt. */
416 /* FIXME: This should be called via a remove_edge hook. */
417 if (current_ir_type () == IR_GIMPLE)
418 redirect_edge_var_map_clear (e);
419
420 remove_edge_raw (e);
421 }
422
423 /* Like redirect_edge_succ but avoid possible duplicate edge. */
424
425 edge
426 redirect_edge_succ_nodup (edge e, basic_block new_succ)
427 {
428 edge s;
429
430 s = find_edge (e->src, new_succ);
431 if (s && s != e)
432 {
433 s->flags |= e->flags;
434 s->probability += e->probability;
435 if (s->probability > REG_BR_PROB_BASE)
436 s->probability = REG_BR_PROB_BASE;
437 s->count += e->count;
438 /* FIXME: This should be called via a hook and only for IR_GIMPLE. */
439 redirect_edge_var_map_dup (s, e);
440 remove_edge (e);
441 e = s;
442 }
443 else
444 redirect_edge_succ (e, new_succ);
445
446 return e;
447 }
448
449 /* Redirect the edge E to basic block DEST even if it requires creating
450 of a new basic block; then it returns the newly created basic block.
451 Aborts when redirection is impossible. */
452
453 basic_block
454 redirect_edge_and_branch_force (edge e, basic_block dest)
455 {
456 basic_block ret, src = e->src;
457
458 if (!cfg_hooks->redirect_edge_and_branch_force)
459 internal_error ("%s does not support redirect_edge_and_branch_force",
460 cfg_hooks->name);
461
462 if (current_loops != NULL)
463 rescan_loop_exit (e, false, true);
464
465 ret = cfg_hooks->redirect_edge_and_branch_force (e, dest);
466
467 if (ret != NULL && dom_info_available_p (CDI_DOMINATORS))
468 set_immediate_dominator (CDI_DOMINATORS, ret, src);
469
470 if (current_loops != NULL)
471 {
472 if (ret != NULL)
473 {
474 struct loop *loop
475 = find_common_loop (single_pred (ret)->loop_father,
476 single_succ (ret)->loop_father);
477 add_bb_to_loop (ret, loop);
478 }
479 else if (find_edge (src, dest) == e)
480 rescan_loop_exit (e, true, false);
481 }
482
483 return ret;
484 }
485
486 /* Splits basic block BB after the specified instruction I (but at least after
487 the labels). If I is NULL, splits just after labels. The newly created edge
488 is returned. The new basic block is created just after the old one. */
489
490 static edge
491 split_block_1 (basic_block bb, void *i)
492 {
493 basic_block new_bb;
494 edge res;
495
496 if (!cfg_hooks->split_block)
497 internal_error ("%s does not support split_block", cfg_hooks->name);
498
499 new_bb = cfg_hooks->split_block (bb, i);
500 if (!new_bb)
501 return NULL;
502
503 new_bb->count = bb->count;
504 new_bb->frequency = bb->frequency;
505 new_bb->discriminator = bb->discriminator;
506
507 if (dom_info_available_p (CDI_DOMINATORS))
508 {
509 redirect_immediate_dominators (CDI_DOMINATORS, bb, new_bb);
510 set_immediate_dominator (CDI_DOMINATORS, new_bb, bb);
511 }
512
513 if (current_loops != NULL)
514 {
515 edge_iterator ei;
516 edge e;
517 add_bb_to_loop (new_bb, bb->loop_father);
518 /* Identify all loops bb may have been the latch of and adjust them. */
519 FOR_EACH_EDGE (e, ei, new_bb->succs)
520 if (e->dest->loop_father->latch == bb)
521 e->dest->loop_father->latch = new_bb;
522 }
523
524 res = make_single_succ_edge (bb, new_bb, EDGE_FALLTHRU);
525
526 if (bb->flags & BB_IRREDUCIBLE_LOOP)
527 {
528 new_bb->flags |= BB_IRREDUCIBLE_LOOP;
529 res->flags |= EDGE_IRREDUCIBLE_LOOP;
530 }
531
532 return res;
533 }
534
535 edge
536 split_block (basic_block bb, gimple *i)
537 {
538 return split_block_1 (bb, i);
539 }
540
541 edge
542 split_block (basic_block bb, rtx i)
543 {
544 return split_block_1 (bb, i);
545 }
546
547 /* Splits block BB just after labels. The newly created edge is returned. */
548
549 edge
550 split_block_after_labels (basic_block bb)
551 {
552 return split_block_1 (bb, NULL);
553 }
554
555 /* Moves block BB immediately after block AFTER. Returns false if the
556 movement was impossible. */
557
558 bool
559 move_block_after (basic_block bb, basic_block after)
560 {
561 bool ret;
562
563 if (!cfg_hooks->move_block_after)
564 internal_error ("%s does not support move_block_after", cfg_hooks->name);
565
566 ret = cfg_hooks->move_block_after (bb, after);
567
568 return ret;
569 }
570
571 /* Deletes the basic block BB. */
572
573 void
574 delete_basic_block (basic_block bb)
575 {
576 if (!cfg_hooks->delete_basic_block)
577 internal_error ("%s does not support delete_basic_block", cfg_hooks->name);
578
579 cfg_hooks->delete_basic_block (bb);
580
581 if (current_loops != NULL)
582 {
583 struct loop *loop = bb->loop_father;
584
585 /* If we remove the header or the latch of a loop, mark the loop for
586 removal. */
587 if (loop->latch == bb
588 || loop->header == bb)
589 mark_loop_for_removal (loop);
590
591 remove_bb_from_loops (bb);
592 }
593
594 /* Remove the edges into and out of this block. Note that there may
595 indeed be edges in, if we are removing an unreachable loop. */
596 while (EDGE_COUNT (bb->preds) != 0)
597 remove_edge (EDGE_PRED (bb, 0));
598 while (EDGE_COUNT (bb->succs) != 0)
599 remove_edge (EDGE_SUCC (bb, 0));
600
601 if (dom_info_available_p (CDI_DOMINATORS))
602 delete_from_dominance_info (CDI_DOMINATORS, bb);
603 if (dom_info_available_p (CDI_POST_DOMINATORS))
604 delete_from_dominance_info (CDI_POST_DOMINATORS, bb);
605
606 /* Remove the basic block from the array. */
607 expunge_block (bb);
608 }
609
610 /* Splits edge E and returns the newly created basic block. */
611
612 basic_block
613 split_edge (edge e)
614 {
615 basic_block ret;
616 gcov_type count = e->count;
617 int freq = EDGE_FREQUENCY (e);
618 edge f;
619 bool irr = (e->flags & EDGE_IRREDUCIBLE_LOOP) != 0;
620 struct loop *loop;
621 basic_block src = e->src, dest = e->dest;
622
623 if (!cfg_hooks->split_edge)
624 internal_error ("%s does not support split_edge", cfg_hooks->name);
625
626 if (current_loops != NULL)
627 rescan_loop_exit (e, false, true);
628
629 ret = cfg_hooks->split_edge (e);
630 ret->count = count;
631 ret->frequency = freq;
632 single_succ_edge (ret)->probability = REG_BR_PROB_BASE;
633 single_succ_edge (ret)->count = count;
634
635 if (irr)
636 {
637 ret->flags |= BB_IRREDUCIBLE_LOOP;
638 single_pred_edge (ret)->flags |= EDGE_IRREDUCIBLE_LOOP;
639 single_succ_edge (ret)->flags |= EDGE_IRREDUCIBLE_LOOP;
640 }
641
642 if (dom_info_available_p (CDI_DOMINATORS))
643 set_immediate_dominator (CDI_DOMINATORS, ret, single_pred (ret));
644
645 if (dom_info_state (CDI_DOMINATORS) >= DOM_NO_FAST_QUERY)
646 {
647 /* There are two cases:
648
649 If the immediate dominator of e->dest is not e->src, it
650 remains unchanged.
651
652 If immediate dominator of e->dest is e->src, it may become
653 ret, provided that all other predecessors of e->dest are
654 dominated by e->dest. */
655
656 if (get_immediate_dominator (CDI_DOMINATORS, single_succ (ret))
657 == single_pred (ret))
658 {
659 edge_iterator ei;
660 FOR_EACH_EDGE (f, ei, single_succ (ret)->preds)
661 {
662 if (f == single_succ_edge (ret))
663 continue;
664
665 if (!dominated_by_p (CDI_DOMINATORS, f->src,
666 single_succ (ret)))
667 break;
668 }
669
670 if (!f)
671 set_immediate_dominator (CDI_DOMINATORS, single_succ (ret), ret);
672 }
673 }
674
675 if (current_loops != NULL)
676 {
677 loop = find_common_loop (src->loop_father, dest->loop_father);
678 add_bb_to_loop (ret, loop);
679
680 /* If we split the latch edge of loop adjust the latch block. */
681 if (loop->latch == src
682 && loop->header == dest)
683 loop->latch = ret;
684 }
685
686 return ret;
687 }
688
689 /* Creates a new basic block just after the basic block AFTER.
690 HEAD and END are the first and the last statement belonging
691 to the block. If both are NULL, an empty block is created. */
692
693 static basic_block
694 create_basic_block_1 (void *head, void *end, basic_block after)
695 {
696 basic_block ret;
697
698 if (!cfg_hooks->create_basic_block)
699 internal_error ("%s does not support create_basic_block", cfg_hooks->name);
700
701 ret = cfg_hooks->create_basic_block (head, end, after);
702
703 if (dom_info_available_p (CDI_DOMINATORS))
704 add_to_dominance_info (CDI_DOMINATORS, ret);
705 if (dom_info_available_p (CDI_POST_DOMINATORS))
706 add_to_dominance_info (CDI_POST_DOMINATORS, ret);
707
708 return ret;
709 }
710
711 basic_block
712 create_basic_block (gimple_seq seq, basic_block after)
713 {
714 return create_basic_block_1 (seq, NULL, after);
715 }
716
717 basic_block
718 create_basic_block (rtx head, rtx end, basic_block after)
719 {
720 return create_basic_block_1 (head, end, after);
721 }
722
723
724 /* Creates an empty basic block just after basic block AFTER. */
725
726 basic_block
727 create_empty_bb (basic_block after)
728 {
729 return create_basic_block_1 (NULL, NULL, after);
730 }
731
732 /* Checks whether we may merge blocks BB1 and BB2. */
733
734 bool
735 can_merge_blocks_p (basic_block bb1, basic_block bb2)
736 {
737 bool ret;
738
739 if (!cfg_hooks->can_merge_blocks_p)
740 internal_error ("%s does not support can_merge_blocks_p", cfg_hooks->name);
741
742 ret = cfg_hooks->can_merge_blocks_p (bb1, bb2);
743
744 return ret;
745 }
746
747 void
748 predict_edge (edge e, enum br_predictor predictor, int probability)
749 {
750 if (!cfg_hooks->predict_edge)
751 internal_error ("%s does not support predict_edge", cfg_hooks->name);
752
753 cfg_hooks->predict_edge (e, predictor, probability);
754 }
755
756 bool
757 predicted_by_p (const_basic_block bb, enum br_predictor predictor)
758 {
759 if (!cfg_hooks->predict_edge)
760 internal_error ("%s does not support predicted_by_p", cfg_hooks->name);
761
762 return cfg_hooks->predicted_by_p (bb, predictor);
763 }
764
765 /* Merges basic block B into basic block A. */
766
767 void
768 merge_blocks (basic_block a, basic_block b)
769 {
770 edge e;
771 edge_iterator ei;
772
773 if (!cfg_hooks->merge_blocks)
774 internal_error ("%s does not support merge_blocks", cfg_hooks->name);
775
776 cfg_hooks->merge_blocks (a, b);
777
778 if (current_loops != NULL)
779 {
780 /* If the block we merge into is a loop header do nothing unless ... */
781 if (a->loop_father->header == a)
782 {
783 /* ... we merge two loop headers, in which case we kill
784 the inner loop. */
785 if (b->loop_father->header == b)
786 mark_loop_for_removal (b->loop_father);
787 }
788 /* If we merge a loop header into its predecessor, update the loop
789 structure. */
790 else if (b->loop_father->header == b)
791 {
792 remove_bb_from_loops (a);
793 add_bb_to_loop (a, b->loop_father);
794 a->loop_father->header = a;
795 }
796 /* If we merge a loop latch into its predecessor, update the loop
797 structure. */
798 if (b->loop_father->latch
799 && b->loop_father->latch == b)
800 b->loop_father->latch = a;
801 remove_bb_from_loops (b);
802 }
803
804 /* Normally there should only be one successor of A and that is B, but
805 partway though the merge of blocks for conditional_execution we'll
806 be merging a TEST block with THEN and ELSE successors. Free the
807 whole lot of them and hope the caller knows what they're doing. */
808
809 while (EDGE_COUNT (a->succs) != 0)
810 remove_edge (EDGE_SUCC (a, 0));
811
812 /* Adjust the edges out of B for the new owner. */
813 FOR_EACH_EDGE (e, ei, b->succs)
814 {
815 e->src = a;
816 if (current_loops != NULL)
817 {
818 /* If b was a latch, a now is. */
819 if (e->dest->loop_father->latch == b)
820 e->dest->loop_father->latch = a;
821 rescan_loop_exit (e, true, false);
822 }
823 }
824 a->succs = b->succs;
825 a->flags |= b->flags;
826
827 /* B hasn't quite yet ceased to exist. Attempt to prevent mishap. */
828 b->preds = b->succs = NULL;
829
830 if (dom_info_available_p (CDI_DOMINATORS))
831 redirect_immediate_dominators (CDI_DOMINATORS, b, a);
832
833 if (dom_info_available_p (CDI_DOMINATORS))
834 delete_from_dominance_info (CDI_DOMINATORS, b);
835 if (dom_info_available_p (CDI_POST_DOMINATORS))
836 delete_from_dominance_info (CDI_POST_DOMINATORS, b);
837
838 expunge_block (b);
839 }
840
841 /* Split BB into entry part and the rest (the rest is the newly created block).
842 Redirect those edges for that REDIRECT_EDGE_P returns true to the entry
843 part. Returns the edge connecting the entry part to the rest. */
844
845 edge
846 make_forwarder_block (basic_block bb, bool (*redirect_edge_p) (edge),
847 void (*new_bb_cbk) (basic_block))
848 {
849 edge e, fallthru;
850 edge_iterator ei;
851 basic_block dummy, jump;
852 struct loop *loop, *ploop, *cloop;
853
854 if (!cfg_hooks->make_forwarder_block)
855 internal_error ("%s does not support make_forwarder_block",
856 cfg_hooks->name);
857
858 fallthru = split_block_after_labels (bb);
859 dummy = fallthru->src;
860 dummy->count = 0;
861 dummy->frequency = 0;
862 fallthru->count = 0;
863 bb = fallthru->dest;
864
865 /* Redirect back edges we want to keep. */
866 for (ei = ei_start (dummy->preds); (e = ei_safe_edge (ei)); )
867 {
868 basic_block e_src;
869
870 if (redirect_edge_p (e))
871 {
872 dummy->frequency += EDGE_FREQUENCY (e);
873 if (dummy->frequency > BB_FREQ_MAX)
874 dummy->frequency = BB_FREQ_MAX;
875
876 dummy->count += e->count;
877 fallthru->count += e->count;
878 ei_next (&ei);
879 continue;
880 }
881
882 e_src = e->src;
883 jump = redirect_edge_and_branch_force (e, bb);
884 if (jump != NULL)
885 {
886 /* If we redirected the loop latch edge, the JUMP block now acts like
887 the new latch of the loop. */
888 if (current_loops != NULL
889 && dummy->loop_father != NULL
890 && dummy->loop_father->header == dummy
891 && dummy->loop_father->latch == e_src)
892 dummy->loop_father->latch = jump;
893
894 if (new_bb_cbk != NULL)
895 new_bb_cbk (jump);
896 }
897 }
898
899 if (dom_info_available_p (CDI_DOMINATORS))
900 {
901 vec<basic_block> doms_to_fix;
902 doms_to_fix.create (2);
903 doms_to_fix.quick_push (dummy);
904 doms_to_fix.quick_push (bb);
905 iterate_fix_dominators (CDI_DOMINATORS, doms_to_fix, false);
906 doms_to_fix.release ();
907 }
908
909 if (current_loops != NULL)
910 {
911 /* If we do not split a loop header, then both blocks belong to the
912 same loop. In case we split loop header and do not redirect the
913 latch edge to DUMMY, then DUMMY belongs to the outer loop, and
914 BB becomes the new header. If latch is not recorded for the loop,
915 we leave this updating on the caller (this may only happen during
916 loop analysis). */
917 loop = dummy->loop_father;
918 if (loop->header == dummy
919 && loop->latch != NULL
920 && find_edge (loop->latch, dummy) == NULL)
921 {
922 remove_bb_from_loops (dummy);
923 loop->header = bb;
924
925 cloop = loop;
926 FOR_EACH_EDGE (e, ei, dummy->preds)
927 {
928 cloop = find_common_loop (cloop, e->src->loop_father);
929 }
930 add_bb_to_loop (dummy, cloop);
931 }
932
933 /* In case we split loop latch, update it. */
934 for (ploop = loop; ploop; ploop = loop_outer (ploop))
935 if (ploop->latch == dummy)
936 ploop->latch = bb;
937 }
938
939 cfg_hooks->make_forwarder_block (fallthru);
940
941 return fallthru;
942 }
943
944 /* Try to make the edge fallthru. */
945
946 void
947 tidy_fallthru_edge (edge e)
948 {
949 if (cfg_hooks->tidy_fallthru_edge)
950 cfg_hooks->tidy_fallthru_edge (e);
951 }
952
953 /* Fix up edges that now fall through, or rather should now fall through
954 but previously required a jump around now deleted blocks. Simplify
955 the search by only examining blocks numerically adjacent, since this
956 is how they were created.
957
958 ??? This routine is currently RTL specific. */
959
960 void
961 tidy_fallthru_edges (void)
962 {
963 basic_block b, c;
964
965 if (!cfg_hooks->tidy_fallthru_edge)
966 return;
967
968 if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
969 return;
970
971 FOR_BB_BETWEEN (b, ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb,
972 EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb, next_bb)
973 {
974 edge s;
975
976 c = b->next_bb;
977
978 /* We care about simple conditional or unconditional jumps with
979 a single successor.
980
981 If we had a conditional branch to the next instruction when
982 CFG was built, then there will only be one out edge for the
983 block which ended with the conditional branch (since we do
984 not create duplicate edges).
985
986 Furthermore, the edge will be marked as a fallthru because we
987 merge the flags for the duplicate edges. So we do not want to
988 check that the edge is not a FALLTHRU edge. */
989
990 if (single_succ_p (b))
991 {
992 s = single_succ_edge (b);
993 if (! (s->flags & EDGE_COMPLEX)
994 && s->dest == c
995 && !(JUMP_P (BB_END (b)) && CROSSING_JUMP_P (BB_END (b))))
996 tidy_fallthru_edge (s);
997 }
998 }
999 }
1000
1001 /* Edge E is assumed to be fallthru edge. Emit needed jump instruction
1002 (and possibly create new basic block) to make edge non-fallthru.
1003 Return newly created BB or NULL if none. */
1004
1005 basic_block
1006 force_nonfallthru (edge e)
1007 {
1008 basic_block ret, src = e->src;
1009
1010 if (!cfg_hooks->force_nonfallthru)
1011 internal_error ("%s does not support force_nonfallthru",
1012 cfg_hooks->name);
1013
1014 ret = cfg_hooks->force_nonfallthru (e);
1015 if (ret != NULL)
1016 {
1017 if (dom_info_available_p (CDI_DOMINATORS))
1018 set_immediate_dominator (CDI_DOMINATORS, ret, src);
1019
1020 if (current_loops != NULL)
1021 {
1022 struct loop *loop
1023 = find_common_loop (single_pred (ret)->loop_father,
1024 single_succ (ret)->loop_father);
1025 rescan_loop_exit (e, false, true);
1026 add_bb_to_loop (ret, loop);
1027 }
1028 }
1029
1030 return ret;
1031 }
1032
1033 /* Returns true if we can duplicate basic block BB. */
1034
1035 bool
1036 can_duplicate_block_p (const_basic_block bb)
1037 {
1038 if (!cfg_hooks->can_duplicate_block_p)
1039 internal_error ("%s does not support can_duplicate_block_p",
1040 cfg_hooks->name);
1041
1042 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1043 return false;
1044
1045 return cfg_hooks->can_duplicate_block_p (bb);
1046 }
1047
1048 /* Duplicates basic block BB and redirects edge E to it. Returns the
1049 new basic block. The new basic block is placed after the basic block
1050 AFTER. */
1051
1052 basic_block
1053 duplicate_block (basic_block bb, edge e, basic_block after)
1054 {
1055 edge s, n;
1056 basic_block new_bb;
1057 gcov_type new_count = e ? e->count : 0;
1058 edge_iterator ei;
1059
1060 if (!cfg_hooks->duplicate_block)
1061 internal_error ("%s does not support duplicate_block",
1062 cfg_hooks->name);
1063
1064 if (bb->count < new_count)
1065 new_count = bb->count;
1066
1067 gcc_checking_assert (can_duplicate_block_p (bb));
1068
1069 new_bb = cfg_hooks->duplicate_block (bb);
1070 if (after)
1071 move_block_after (new_bb, after);
1072
1073 new_bb->flags = bb->flags;
1074 FOR_EACH_EDGE (s, ei, bb->succs)
1075 {
1076 /* Since we are creating edges from a new block to successors
1077 of another block (which therefore are known to be disjoint), there
1078 is no need to actually check for duplicated edges. */
1079 n = unchecked_make_edge (new_bb, s->dest, s->flags);
1080 n->probability = s->probability;
1081 if (e && bb->count)
1082 {
1083 /* Take care for overflows! */
1084 n->count = s->count * (new_count * 10000 / bb->count) / 10000;
1085 s->count -= n->count;
1086 }
1087 else
1088 n->count = s->count;
1089 n->aux = s->aux;
1090 }
1091
1092 if (e)
1093 {
1094 new_bb->count = new_count;
1095 bb->count -= new_count;
1096
1097 new_bb->frequency = EDGE_FREQUENCY (e);
1098 bb->frequency -= EDGE_FREQUENCY (e);
1099
1100 redirect_edge_and_branch_force (e, new_bb);
1101
1102 if (bb->count < 0)
1103 bb->count = 0;
1104 if (bb->frequency < 0)
1105 bb->frequency = 0;
1106 }
1107 else
1108 {
1109 new_bb->count = bb->count;
1110 new_bb->frequency = bb->frequency;
1111 }
1112
1113 set_bb_original (new_bb, bb);
1114 set_bb_copy (bb, new_bb);
1115
1116 /* Add the new block to the copy of the loop of BB, or directly to the loop
1117 of BB if the loop is not being copied. */
1118 if (current_loops != NULL)
1119 {
1120 struct loop *cloop = bb->loop_father;
1121 struct loop *copy = get_loop_copy (cloop);
1122 /* If we copied the loop header block but not the loop
1123 we have created a loop with multiple entries. Ditch the loop,
1124 add the new block to the outer loop and arrange for a fixup. */
1125 if (!copy
1126 && cloop->header == bb)
1127 {
1128 add_bb_to_loop (new_bb, loop_outer (cloop));
1129 mark_loop_for_removal (cloop);
1130 }
1131 else
1132 {
1133 add_bb_to_loop (new_bb, copy ? copy : cloop);
1134 /* If we copied the loop latch block but not the loop, adjust
1135 loop state. */
1136 if (!copy
1137 && cloop->latch == bb)
1138 {
1139 cloop->latch = NULL;
1140 loops_state_set (LOOPS_MAY_HAVE_MULTIPLE_LATCHES);
1141 }
1142 }
1143 }
1144
1145 return new_bb;
1146 }
1147
1148 /* Return 1 if BB ends with a call, possibly followed by some
1149 instructions that must stay with the call, 0 otherwise. */
1150
1151 bool
1152 block_ends_with_call_p (basic_block bb)
1153 {
1154 if (!cfg_hooks->block_ends_with_call_p)
1155 internal_error ("%s does not support block_ends_with_call_p", cfg_hooks->name);
1156
1157 return (cfg_hooks->block_ends_with_call_p) (bb);
1158 }
1159
1160 /* Return 1 if BB ends with a conditional branch, 0 otherwise. */
1161
1162 bool
1163 block_ends_with_condjump_p (const_basic_block bb)
1164 {
1165 if (!cfg_hooks->block_ends_with_condjump_p)
1166 internal_error ("%s does not support block_ends_with_condjump_p",
1167 cfg_hooks->name);
1168
1169 return (cfg_hooks->block_ends_with_condjump_p) (bb);
1170 }
1171
1172 /* Add fake edges to the function exit for any non constant and non noreturn
1173 calls, volatile inline assembly in the bitmap of blocks specified by
1174 BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks
1175 that were split.
1176
1177 The goal is to expose cases in which entering a basic block does not imply
1178 that all subsequent instructions must be executed. */
1179
1180 int
1181 flow_call_edges_add (sbitmap blocks)
1182 {
1183 if (!cfg_hooks->flow_call_edges_add)
1184 internal_error ("%s does not support flow_call_edges_add",
1185 cfg_hooks->name);
1186
1187 return (cfg_hooks->flow_call_edges_add) (blocks);
1188 }
1189
1190 /* This function is called immediately after edge E is added to the
1191 edge vector E->dest->preds. */
1192
1193 void
1194 execute_on_growing_pred (edge e)
1195 {
1196 if (cfg_hooks->execute_on_growing_pred)
1197 cfg_hooks->execute_on_growing_pred (e);
1198 }
1199
1200 /* This function is called immediately before edge E is removed from
1201 the edge vector E->dest->preds. */
1202
1203 void
1204 execute_on_shrinking_pred (edge e)
1205 {
1206 if (cfg_hooks->execute_on_shrinking_pred)
1207 cfg_hooks->execute_on_shrinking_pred (e);
1208 }
1209
1210 /* This is used inside loop versioning when we want to insert
1211 stmts/insns on the edges, which have a different behavior
1212 in tree's and in RTL, so we made a CFG hook. */
1213 void
1214 lv_flush_pending_stmts (edge e)
1215 {
1216 if (cfg_hooks->flush_pending_stmts)
1217 cfg_hooks->flush_pending_stmts (e);
1218 }
1219
1220 /* Loop versioning uses the duplicate_loop_to_header_edge to create
1221 a new version of the loop basic-blocks, the parameters here are
1222 exactly the same as in duplicate_loop_to_header_edge or
1223 tree_duplicate_loop_to_header_edge; while in tree-ssa there is
1224 additional work to maintain ssa information that's why there is
1225 a need to call the tree_duplicate_loop_to_header_edge rather
1226 than duplicate_loop_to_header_edge when we are in tree mode. */
1227 bool
1228 cfg_hook_duplicate_loop_to_header_edge (struct loop *loop, edge e,
1229 unsigned int ndupl,
1230 sbitmap wont_exit, edge orig,
1231 vec<edge> *to_remove,
1232 int flags)
1233 {
1234 gcc_assert (cfg_hooks->cfg_hook_duplicate_loop_to_header_edge);
1235 return cfg_hooks->cfg_hook_duplicate_loop_to_header_edge (loop, e,
1236 ndupl, wont_exit,
1237 orig, to_remove,
1238 flags);
1239 }
1240
1241 /* Conditional jumps are represented differently in trees and RTL,
1242 this hook takes a basic block that is known to have a cond jump
1243 at its end and extracts the taken and not taken edges out of it
1244 and store it in E1 and E2 respectively. */
1245 void
1246 extract_cond_bb_edges (basic_block b, edge *e1, edge *e2)
1247 {
1248 gcc_assert (cfg_hooks->extract_cond_bb_edges);
1249 cfg_hooks->extract_cond_bb_edges (b, e1, e2);
1250 }
1251
1252 /* Responsible for updating the ssa info (PHI nodes) on the
1253 new condition basic block that guards the versioned loop. */
1254 void
1255 lv_adjust_loop_header_phi (basic_block first, basic_block second,
1256 basic_block new_block, edge e)
1257 {
1258 if (cfg_hooks->lv_adjust_loop_header_phi)
1259 cfg_hooks->lv_adjust_loop_header_phi (first, second, new_block, e);
1260 }
1261
1262 /* Conditions in trees and RTL are different so we need
1263 a different handling when we add the condition to the
1264 versioning code. */
1265 void
1266 lv_add_condition_to_bb (basic_block first, basic_block second,
1267 basic_block new_block, void *cond)
1268 {
1269 gcc_assert (cfg_hooks->lv_add_condition_to_bb);
1270 cfg_hooks->lv_add_condition_to_bb (first, second, new_block, cond);
1271 }
1272
1273 /* Checks whether all N blocks in BBS array can be copied. */
1274 bool
1275 can_copy_bbs_p (basic_block *bbs, unsigned n)
1276 {
1277 unsigned i;
1278 edge e;
1279 int ret = true;
1280
1281 for (i = 0; i < n; i++)
1282 bbs[i]->flags |= BB_DUPLICATED;
1283
1284 for (i = 0; i < n; i++)
1285 {
1286 /* In case we should redirect abnormal edge during duplication, fail. */
1287 edge_iterator ei;
1288 FOR_EACH_EDGE (e, ei, bbs[i]->succs)
1289 if ((e->flags & EDGE_ABNORMAL)
1290 && (e->dest->flags & BB_DUPLICATED))
1291 {
1292 ret = false;
1293 goto end;
1294 }
1295
1296 if (!can_duplicate_block_p (bbs[i]))
1297 {
1298 ret = false;
1299 break;
1300 }
1301 }
1302
1303 end:
1304 for (i = 0; i < n; i++)
1305 bbs[i]->flags &= ~BB_DUPLICATED;
1306
1307 return ret;
1308 }
1309
1310 /* Duplicates N basic blocks stored in array BBS. Newly created basic blocks
1311 are placed into array NEW_BBS in the same order. Edges from basic blocks
1312 in BBS are also duplicated and copies of those that lead into BBS are
1313 redirected to appropriate newly created block. The function assigns bbs
1314 into loops (copy of basic block bb is assigned to bb->loop_father->copy
1315 loop, so this must be set up correctly in advance)
1316
1317 If UPDATE_DOMINANCE is true then this function updates dominators locally
1318 (LOOPS structure that contains the information about dominators is passed
1319 to enable this), otherwise it does not update the dominator information
1320 and it assumed that the caller will do this, perhaps by destroying and
1321 recreating it instead of trying to do an incremental update like this
1322 function does when update_dominance is true.
1323
1324 BASE is the superloop to that basic block belongs; if its header or latch
1325 is copied, we do not set the new blocks as header or latch.
1326
1327 Created copies of N_EDGES edges in array EDGES are stored in array NEW_EDGES,
1328 also in the same order.
1329
1330 Newly created basic blocks are put after the basic block AFTER in the
1331 instruction stream, and the order of the blocks in BBS array is preserved. */
1332
1333 void
1334 copy_bbs (basic_block *bbs, unsigned n, basic_block *new_bbs,
1335 edge *edges, unsigned num_edges, edge *new_edges,
1336 struct loop *base, basic_block after, bool update_dominance)
1337 {
1338 unsigned i, j;
1339 basic_block bb, new_bb, dom_bb;
1340 edge e;
1341
1342 /* Duplicate bbs, update dominators, assign bbs to loops. */
1343 for (i = 0; i < n; i++)
1344 {
1345 /* Duplicate. */
1346 bb = bbs[i];
1347 new_bb = new_bbs[i] = duplicate_block (bb, NULL, after);
1348 after = new_bb;
1349 bb->flags |= BB_DUPLICATED;
1350 if (bb->loop_father)
1351 {
1352 /* Possibly set loop header. */
1353 if (bb->loop_father->header == bb && bb->loop_father != base)
1354 new_bb->loop_father->header = new_bb;
1355 /* Or latch. */
1356 if (bb->loop_father->latch == bb && bb->loop_father != base)
1357 new_bb->loop_father->latch = new_bb;
1358 }
1359 }
1360
1361 /* Set dominators. */
1362 if (update_dominance)
1363 {
1364 for (i = 0; i < n; i++)
1365 {
1366 bb = bbs[i];
1367 new_bb = new_bbs[i];
1368
1369 dom_bb = get_immediate_dominator (CDI_DOMINATORS, bb);
1370 if (dom_bb->flags & BB_DUPLICATED)
1371 {
1372 dom_bb = get_bb_copy (dom_bb);
1373 set_immediate_dominator (CDI_DOMINATORS, new_bb, dom_bb);
1374 }
1375 }
1376 }
1377
1378 /* Redirect edges. */
1379 for (j = 0; j < num_edges; j++)
1380 new_edges[j] = NULL;
1381 for (i = 0; i < n; i++)
1382 {
1383 edge_iterator ei;
1384 new_bb = new_bbs[i];
1385 bb = bbs[i];
1386
1387 FOR_EACH_EDGE (e, ei, new_bb->succs)
1388 {
1389 for (j = 0; j < num_edges; j++)
1390 if (edges[j] && edges[j]->src == bb && edges[j]->dest == e->dest)
1391 new_edges[j] = e;
1392
1393 if (!(e->dest->flags & BB_DUPLICATED))
1394 continue;
1395 redirect_edge_and_branch_force (e, get_bb_copy (e->dest));
1396 }
1397 }
1398
1399 /* Clear information about duplicates. */
1400 for (i = 0; i < n; i++)
1401 bbs[i]->flags &= ~BB_DUPLICATED;
1402 }
1403
1404 /* Return true if BB contains only labels or non-executable
1405 instructions */
1406 bool
1407 empty_block_p (basic_block bb)
1408 {
1409 gcc_assert (cfg_hooks->empty_block_p);
1410 return cfg_hooks->empty_block_p (bb);
1411 }
1412
1413 /* Split a basic block if it ends with a conditional branch and if
1414 the other part of the block is not empty. */
1415 basic_block
1416 split_block_before_cond_jump (basic_block bb)
1417 {
1418 gcc_assert (cfg_hooks->split_block_before_cond_jump);
1419 return cfg_hooks->split_block_before_cond_jump (bb);
1420 }
1421
1422 /* Work-horse for passes.c:check_profile_consistency.
1423 Do book-keeping of the CFG for the profile consistency checker.
1424 If AFTER_PASS is 0, do pre-pass accounting, or if AFTER_PASS is 1
1425 then do post-pass accounting. Store the counting in RECORD. */
1426
1427 void
1428 account_profile_record (struct profile_record *record, int after_pass)
1429 {
1430 basic_block bb;
1431 edge_iterator ei;
1432 edge e;
1433 int sum;
1434 gcov_type lsum;
1435
1436 FOR_ALL_BB_FN (bb, cfun)
1437 {
1438 if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
1439 && profile_status_for_fn (cfun) != PROFILE_ABSENT)
1440 {
1441 sum = 0;
1442 FOR_EACH_EDGE (e, ei, bb->succs)
1443 sum += e->probability;
1444 if (EDGE_COUNT (bb->succs) && abs (sum - REG_BR_PROB_BASE) > 100)
1445 record->num_mismatched_freq_out[after_pass]++;
1446 lsum = 0;
1447 FOR_EACH_EDGE (e, ei, bb->succs)
1448 lsum += e->count;
1449 if (EDGE_COUNT (bb->succs)
1450 && (lsum - bb->count > 100 || lsum - bb->count < -100))
1451 record->num_mismatched_count_out[after_pass]++;
1452 }
1453 if (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)
1454 && profile_status_for_fn (cfun) != PROFILE_ABSENT)
1455 {
1456 sum = 0;
1457 FOR_EACH_EDGE (e, ei, bb->preds)
1458 sum += EDGE_FREQUENCY (e);
1459 if (abs (sum - bb->frequency) > 100
1460 || (MAX (sum, bb->frequency) > 10
1461 && abs ((sum - bb->frequency) * 100 / (MAX (sum, bb->frequency) + 1)) > 10))
1462 record->num_mismatched_freq_in[after_pass]++;
1463 lsum = 0;
1464 FOR_EACH_EDGE (e, ei, bb->preds)
1465 lsum += e->count;
1466 if (lsum - bb->count > 100 || lsum - bb->count < -100)
1467 record->num_mismatched_count_in[after_pass]++;
1468 }
1469 if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)
1470 || bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
1471 continue;
1472 gcc_assert (cfg_hooks->account_profile_record);
1473 cfg_hooks->account_profile_record (bb, after_pass, record);
1474 }
1475 }