1 /* Hooks for cfg representation specific functions.
2 Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <s.pop@laposte.net>
5 This file is part of GCC.
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)
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.
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, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
24 #include "coretypes.h"
28 #include "basic-block.h"
29 #include "tree-flow.h"
34 /* A pointer to one of the hooks containers. */
35 static struct cfg_hooks
*cfg_hooks
;
37 /* Initialization of functions specific to the rtl IR. */
39 rtl_register_cfg_hooks (void)
41 cfg_hooks
= &rtl_cfg_hooks
;
44 /* Initialization of functions specific to the rtl IR. */
46 cfg_layout_rtl_register_cfg_hooks (void)
48 cfg_hooks
= &cfg_layout_rtl_cfg_hooks
;
51 /* Initialization of functions specific to the tree IR. */
54 tree_register_cfg_hooks (void)
56 cfg_hooks
= &tree_cfg_hooks
;
59 /* Returns current ir type. */
62 current_ir_type (void)
64 if (cfg_hooks
== &tree_cfg_hooks
)
66 else if (cfg_hooks
== &rtl_cfg_hooks
)
68 else if (cfg_hooks
== &cfg_layout_rtl_cfg_hooks
)
69 return IR_RTL_CFGLAYOUT
;
74 /* Verify the CFG consistency.
76 Currently it does following: checks edge and basic block list correctness
77 and calls into IL dependent checking then. */
80 verify_flow_info (void)
82 size_t *edge_checksum
;
84 basic_block bb
, last_bb_seen
;
85 basic_block
*last_visited
;
87 timevar_push (TV_CFG_VERIFY
);
88 last_visited
= XCNEWVEC (basic_block
, last_basic_block
);
89 edge_checksum
= XCNEWVEC (size_t, last_basic_block
);
91 /* Check bb chain & numbers. */
92 last_bb_seen
= ENTRY_BLOCK_PTR
;
93 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
->next_bb
, NULL
, next_bb
)
95 if (bb
!= EXIT_BLOCK_PTR
96 && bb
!= BASIC_BLOCK (bb
->index
))
98 error ("bb %d on wrong place", bb
->index
);
102 if (bb
->prev_bb
!= last_bb_seen
)
104 error ("prev_bb of %d should be %d, not %d",
105 bb
->index
, last_bb_seen
->index
, bb
->prev_bb
->index
);
112 /* Now check the basic blocks (boundaries etc.) */
113 FOR_EACH_BB_REVERSE (bb
)
119 if (bb
->loop_father
!= NULL
&& current_loops
== NULL
)
121 error ("verify_flow_info: Block %i has loop_father, but there are no loops",
125 if (bb
->loop_father
== NULL
&& current_loops
!= NULL
)
127 error ("verify_flow_info: Block %i lacks loop_father", bb
->index
);
133 error ("verify_flow_info: Wrong count of block %i %i",
134 bb
->index
, (int)bb
->count
);
137 if (bb
->frequency
< 0)
139 error ("verify_flow_info: Wrong frequency of block %i %i",
140 bb
->index
, bb
->frequency
);
143 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
145 if (last_visited
[e
->dest
->index
] == bb
)
147 error ("verify_flow_info: Duplicate edge %i->%i",
148 e
->src
->index
, e
->dest
->index
);
151 if (e
->probability
< 0 || e
->probability
> REG_BR_PROB_BASE
)
153 error ("verify_flow_info: Wrong probability of edge %i->%i %i",
154 e
->src
->index
, e
->dest
->index
, e
->probability
);
159 error ("verify_flow_info: Wrong count of edge %i->%i %i",
160 e
->src
->index
, e
->dest
->index
, (int)e
->count
);
164 last_visited
[e
->dest
->index
] = bb
;
166 if (e
->flags
& EDGE_FALLTHRU
)
171 error ("verify_flow_info: Basic block %d succ edge is corrupted",
173 fprintf (stderr
, "Predecessor: ");
174 dump_edge_info (stderr
, e
, 0);
175 fprintf (stderr
, "\nSuccessor: ");
176 dump_edge_info (stderr
, e
, 1);
177 fprintf (stderr
, "\n");
181 edge_checksum
[e
->dest
->index
] += (size_t) e
;
185 error ("wrong amount of branch edges after unconditional jump %i", bb
->index
);
189 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
193 error ("basic block %d pred edge is corrupted", bb
->index
);
194 fputs ("Predecessor: ", stderr
);
195 dump_edge_info (stderr
, e
, 0);
196 fputs ("\nSuccessor: ", stderr
);
197 dump_edge_info (stderr
, e
, 1);
198 fputc ('\n', stderr
);
202 if (ei
.index
!= e
->dest_idx
)
204 error ("basic block %d pred edge is corrupted", bb
->index
);
205 error ("its dest_idx should be %d, not %d",
206 ei
.index
, e
->dest_idx
);
207 fputs ("Predecessor: ", stderr
);
208 dump_edge_info (stderr
, e
, 0);
209 fputs ("\nSuccessor: ", stderr
);
210 dump_edge_info (stderr
, e
, 1);
211 fputc ('\n', stderr
);
215 edge_checksum
[e
->dest
->index
] -= (size_t) e
;
219 /* Complete edge checksumming for ENTRY and EXIT. */
224 FOR_EACH_EDGE (e
, ei
, ENTRY_BLOCK_PTR
->succs
)
225 edge_checksum
[e
->dest
->index
] += (size_t) e
;
227 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR
->preds
)
228 edge_checksum
[e
->dest
->index
] -= (size_t) e
;
231 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, NULL
, next_bb
)
232 if (edge_checksum
[bb
->index
])
234 error ("basic block %i edge lists are corrupted", bb
->index
);
238 last_bb_seen
= ENTRY_BLOCK_PTR
;
242 free (edge_checksum
);
244 if (cfg_hooks
->verify_flow_info
)
245 err
|= cfg_hooks
->verify_flow_info ();
247 internal_error ("verify_flow_info failed");
248 timevar_pop (TV_CFG_VERIFY
);
251 /* Print out one basic block. This function takes care of the purely
252 graph related information. The cfg hook for the active representation
253 should dump representation-specific information. */
256 dump_bb (basic_block bb
, FILE *outf
, int indent
)
262 s_indent
= alloca ((size_t) indent
+ 1);
263 memset (s_indent
, ' ', (size_t) indent
);
264 s_indent
[indent
] = '\0';
266 fprintf (outf
, ";;%s basic block %d, loop depth %d, count ",
267 s_indent
, bb
->index
, bb
->loop_depth
);
268 fprintf (outf
, HOST_WIDEST_INT_PRINT_DEC
, (HOST_WIDEST_INT
) bb
->count
);
271 fprintf (outf
, ";;%s prev block ", s_indent
);
273 fprintf (outf
, "%d, ", bb
->prev_bb
->index
);
275 fprintf (outf
, "(nil), ");
276 fprintf (outf
, "next block ");
278 fprintf (outf
, "%d", bb
->next_bb
->index
);
280 fprintf (outf
, "(nil)");
283 fprintf (outf
, ";;%s pred: ", s_indent
);
284 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
285 dump_edge_info (outf
, e
, 0);
288 fprintf (outf
, ";;%s succ: ", s_indent
);
289 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
290 dump_edge_info (outf
, e
, 1);
293 if (cfg_hooks
->dump_bb
)
294 cfg_hooks
->dump_bb (bb
, outf
, indent
);
297 /* Redirect edge E to the given basic block DEST and update underlying program
298 representation. Returns edge representing redirected branch (that may not
299 be equivalent to E in the case of duplicate edges being removed) or NULL
300 if edge is not easily redirectable for whatever reason. */
303 redirect_edge_and_branch (edge e
, basic_block dest
)
307 if (!cfg_hooks
->redirect_edge_and_branch
)
308 internal_error ("%s does not support redirect_edge_and_branch",
311 ret
= cfg_hooks
->redirect_edge_and_branch (e
, dest
);
316 /* Redirect the edge E to basic block DEST even if it requires creating
317 of a new basic block; then it returns the newly created basic block.
318 Aborts when redirection is impossible. */
321 redirect_edge_and_branch_force (edge e
, basic_block dest
)
326 if (!cfg_hooks
->redirect_edge_and_branch_force
)
327 internal_error ("%s does not support redirect_edge_and_branch_force",
330 ret
= cfg_hooks
->redirect_edge_and_branch_force (e
, dest
);
331 if (current_loops
!= NULL
&& ret
!= NULL
)
333 loop
= find_common_loop (single_pred (ret
)->loop_father
,
334 single_succ (ret
)->loop_father
);
335 add_bb_to_loop (ret
, loop
);
341 /* Splits basic block BB after the specified instruction I (but at least after
342 the labels). If I is NULL, splits just after labels. The newly created edge
343 is returned. The new basic block is created just after the old one. */
346 split_block (basic_block bb
, void *i
)
350 if (!cfg_hooks
->split_block
)
351 internal_error ("%s does not support split_block", cfg_hooks
->name
);
353 new_bb
= cfg_hooks
->split_block (bb
, i
);
357 new_bb
->count
= bb
->count
;
358 new_bb
->frequency
= bb
->frequency
;
359 new_bb
->loop_depth
= bb
->loop_depth
;
361 if (dom_info_available_p (CDI_DOMINATORS
))
363 redirect_immediate_dominators (CDI_DOMINATORS
, bb
, new_bb
);
364 set_immediate_dominator (CDI_DOMINATORS
, new_bb
, bb
);
367 if (current_loops
!= NULL
)
368 add_bb_to_loop (new_bb
, bb
->loop_father
);
370 return make_single_succ_edge (bb
, new_bb
, EDGE_FALLTHRU
);
373 /* Splits block BB just after labels. The newly created edge is returned. */
376 split_block_after_labels (basic_block bb
)
378 return split_block (bb
, NULL
);
381 /* Moves block BB immediately after block AFTER. Returns false if the
382 movement was impossible. */
385 move_block_after (basic_block bb
, basic_block after
)
389 if (!cfg_hooks
->move_block_after
)
390 internal_error ("%s does not support move_block_after", cfg_hooks
->name
);
392 ret
= cfg_hooks
->move_block_after (bb
, after
);
397 /* Deletes the basic block BB. */
400 delete_basic_block (basic_block bb
)
402 if (!cfg_hooks
->delete_basic_block
)
403 internal_error ("%s does not support delete_basic_block", cfg_hooks
->name
);
405 cfg_hooks
->delete_basic_block (bb
);
407 if (current_loops
!= NULL
)
409 struct loop
*loop
= bb
->loop_father
;
411 /* If we remove the header or the latch of a loop, mark the loop for
412 removal by setting its header and latch to NULL. */
413 if (loop
->latch
== bb
414 || loop
->header
== bb
)
420 remove_bb_from_loops (bb
);
423 /* Remove the edges into and out of this block. Note that there may
424 indeed be edges in, if we are removing an unreachable loop. */
425 while (EDGE_COUNT (bb
->preds
) != 0)
426 remove_edge (EDGE_PRED (bb
, 0));
427 while (EDGE_COUNT (bb
->succs
) != 0)
428 remove_edge (EDGE_SUCC (bb
, 0));
430 if (dom_computed
[CDI_DOMINATORS
])
431 delete_from_dominance_info (CDI_DOMINATORS
, bb
);
432 if (dom_computed
[CDI_POST_DOMINATORS
])
433 delete_from_dominance_info (CDI_POST_DOMINATORS
, bb
);
435 /* Remove the basic block from the array. */
439 /* Splits edge E and returns the newly created basic block. */
445 gcov_type count
= e
->count
;
446 int freq
= EDGE_FREQUENCY (e
);
448 bool irr
= (e
->flags
& EDGE_IRREDUCIBLE_LOOP
) != 0;
450 basic_block src
= e
->src
, dest
= e
->dest
;
452 if (!cfg_hooks
->split_edge
)
453 internal_error ("%s does not support split_edge", cfg_hooks
->name
);
455 ret
= cfg_hooks
->split_edge (e
);
457 ret
->frequency
= freq
;
458 single_succ_edge (ret
)->probability
= REG_BR_PROB_BASE
;
459 single_succ_edge (ret
)->count
= count
;
463 ret
->flags
|= BB_IRREDUCIBLE_LOOP
;
464 single_pred_edge (ret
)->flags
|= EDGE_IRREDUCIBLE_LOOP
;
465 single_succ_edge (ret
)->flags
|= EDGE_IRREDUCIBLE_LOOP
;
468 if (dom_computed
[CDI_DOMINATORS
])
469 set_immediate_dominator (CDI_DOMINATORS
, ret
, single_pred (ret
));
471 if (dom_computed
[CDI_DOMINATORS
] >= DOM_NO_FAST_QUERY
)
473 /* There are two cases:
475 If the immediate dominator of e->dest is not e->src, it
478 If immediate dominator of e->dest is e->src, it may become
479 ret, provided that all other predecessors of e->dest are
480 dominated by e->dest. */
482 if (get_immediate_dominator (CDI_DOMINATORS
, single_succ (ret
))
483 == single_pred (ret
))
486 FOR_EACH_EDGE (f
, ei
, single_succ (ret
)->preds
)
488 if (f
== single_succ_edge (ret
))
491 if (!dominated_by_p (CDI_DOMINATORS
, f
->src
,
497 set_immediate_dominator (CDI_DOMINATORS
, single_succ (ret
), ret
);
501 if (current_loops
!= NULL
)
503 loop
= find_common_loop (src
->loop_father
, dest
->loop_father
);
504 add_bb_to_loop (ret
, loop
);
506 if (loop
->latch
== src
)
513 /* Creates a new basic block just after the basic block AFTER.
514 HEAD and END are the first and the last statement belonging
515 to the block. If both are NULL, an empty block is created. */
518 create_basic_block (void *head
, void *end
, basic_block after
)
522 if (!cfg_hooks
->create_basic_block
)
523 internal_error ("%s does not support create_basic_block", cfg_hooks
->name
);
525 ret
= cfg_hooks
->create_basic_block (head
, end
, after
);
527 if (dom_computed
[CDI_DOMINATORS
])
528 add_to_dominance_info (CDI_DOMINATORS
, ret
);
529 if (dom_computed
[CDI_POST_DOMINATORS
])
530 add_to_dominance_info (CDI_POST_DOMINATORS
, ret
);
535 /* Creates an empty basic block just after basic block AFTER. */
538 create_empty_bb (basic_block after
)
540 return create_basic_block (NULL
, NULL
, after
);
543 /* Checks whether we may merge blocks BB1 and BB2. */
546 can_merge_blocks_p (basic_block bb1
, basic_block bb2
)
550 if (!cfg_hooks
->can_merge_blocks_p
)
551 internal_error ("%s does not support can_merge_blocks_p", cfg_hooks
->name
);
553 ret
= cfg_hooks
->can_merge_blocks_p (bb1
, bb2
);
559 predict_edge (edge e
, enum br_predictor predictor
, int probability
)
561 if (!cfg_hooks
->predict_edge
)
562 internal_error ("%s does not support predict_edge", cfg_hooks
->name
);
564 cfg_hooks
->predict_edge (e
, predictor
, probability
);
568 predicted_by_p (basic_block bb
, enum br_predictor predictor
)
570 if (!cfg_hooks
->predict_edge
)
571 internal_error ("%s does not support predicted_by_p", cfg_hooks
->name
);
573 return cfg_hooks
->predicted_by_p (bb
, predictor
);
576 /* Merges basic block B into basic block A. */
579 merge_blocks (basic_block a
, basic_block b
)
584 if (!cfg_hooks
->merge_blocks
)
585 internal_error ("%s does not support merge_blocks", cfg_hooks
->name
);
587 if (current_loops
!= NULL
)
588 remove_bb_from_loops (b
);
590 cfg_hooks
->merge_blocks (a
, b
);
592 /* Normally there should only be one successor of A and that is B, but
593 partway though the merge of blocks for conditional_execution we'll
594 be merging a TEST block with THEN and ELSE successors. Free the
595 whole lot of them and hope the caller knows what they're doing. */
597 while (EDGE_COUNT (a
->succs
) != 0)
598 remove_edge (EDGE_SUCC (a
, 0));
600 /* Adjust the edges out of B for the new owner. */
601 FOR_EACH_EDGE (e
, ei
, b
->succs
)
604 a
->flags
|= b
->flags
;
606 /* B hasn't quite yet ceased to exist. Attempt to prevent mishap. */
607 b
->preds
= b
->succs
= NULL
;
609 if (dom_computed
[CDI_DOMINATORS
])
610 redirect_immediate_dominators (CDI_DOMINATORS
, b
, a
);
612 if (dom_computed
[CDI_DOMINATORS
])
613 delete_from_dominance_info (CDI_DOMINATORS
, b
);
614 if (dom_computed
[CDI_POST_DOMINATORS
])
615 delete_from_dominance_info (CDI_POST_DOMINATORS
, b
);
620 /* Split BB into entry part and the rest (the rest is the newly created block).
621 Redirect those edges for that REDIRECT_EDGE_P returns true to the entry
622 part. Returns the edge connecting the entry part to the rest. */
625 make_forwarder_block (basic_block bb
, bool (*redirect_edge_p
) (edge
),
626 void (*new_bb_cbk
) (basic_block
))
630 basic_block dummy
, jump
;
631 struct loop
*loop
, *ploop
, *cloop
;
633 if (!cfg_hooks
->make_forwarder_block
)
634 internal_error ("%s does not support make_forwarder_block",
637 fallthru
= split_block_after_labels (bb
);
638 dummy
= fallthru
->src
;
641 /* Redirect back edges we want to keep. */
642 for (ei
= ei_start (dummy
->preds
); (e
= ei_safe_edge (ei
)); )
644 if (redirect_edge_p (e
))
650 dummy
->frequency
-= EDGE_FREQUENCY (e
);
651 dummy
->count
-= e
->count
;
652 if (dummy
->frequency
< 0)
653 dummy
->frequency
= 0;
654 if (dummy
->count
< 0)
656 fallthru
->count
-= e
->count
;
657 if (fallthru
->count
< 0)
660 jump
= redirect_edge_and_branch_force (e
, bb
);
665 if (dom_info_available_p (CDI_DOMINATORS
))
667 basic_block doms_to_fix
[2];
669 doms_to_fix
[0] = dummy
;
671 iterate_fix_dominators (CDI_DOMINATORS
, doms_to_fix
, 2);
674 if (current_loops
!= NULL
)
676 /* If we do not split a loop header, then both blocks belong to the
677 same loop. In case we split loop header and do not redirect the
678 latch edge to DUMMY, then DUMMY belongs to the outer loop, and
679 BB becomes the new header. */
680 loop
= dummy
->loop_father
;
681 if (loop
->header
== dummy
682 && find_edge (loop
->latch
, dummy
) == NULL
)
684 remove_bb_from_loops (dummy
);
688 FOR_EACH_EDGE (e
, ei
, dummy
->preds
)
690 cloop
= find_common_loop (cloop
, e
->src
->loop_father
);
692 add_bb_to_loop (dummy
, cloop
);
695 /* In case we split loop latch, update it. */
696 for (ploop
= loop
; ploop
; ploop
= ploop
->outer
)
697 if (ploop
->latch
== dummy
)
701 cfg_hooks
->make_forwarder_block (fallthru
);
707 tidy_fallthru_edge (edge e
)
709 if (cfg_hooks
->tidy_fallthru_edge
)
710 cfg_hooks
->tidy_fallthru_edge (e
);
713 /* Fix up edges that now fall through, or rather should now fall through
714 but previously required a jump around now deleted blocks. Simplify
715 the search by only examining blocks numerically adjacent, since this
716 is how find_basic_blocks created them. */
719 tidy_fallthru_edges (void)
723 if (!cfg_hooks
->tidy_fallthru_edge
)
726 if (ENTRY_BLOCK_PTR
->next_bb
== EXIT_BLOCK_PTR
)
729 FOR_BB_BETWEEN (b
, ENTRY_BLOCK_PTR
->next_bb
, EXIT_BLOCK_PTR
->prev_bb
, next_bb
)
735 /* We care about simple conditional or unconditional jumps with
738 If we had a conditional branch to the next instruction when
739 find_basic_blocks was called, then there will only be one
740 out edge for the block which ended with the conditional
741 branch (since we do not create duplicate edges).
743 Furthermore, the edge will be marked as a fallthru because we
744 merge the flags for the duplicate edges. So we do not want to
745 check that the edge is not a FALLTHRU edge. */
747 if (single_succ_p (b
))
749 s
= single_succ_edge (b
);
750 if (! (s
->flags
& EDGE_COMPLEX
)
752 && !find_reg_note (BB_END (b
), REG_CROSSING_JUMP
, NULL_RTX
))
753 tidy_fallthru_edge (s
);
758 /* Returns true if we can duplicate basic block BB. */
761 can_duplicate_block_p (basic_block bb
)
765 if (!cfg_hooks
->can_duplicate_block_p
)
766 internal_error ("%s does not support can_duplicate_block_p",
769 if (bb
== EXIT_BLOCK_PTR
|| bb
== ENTRY_BLOCK_PTR
)
772 /* Duplicating fallthru block to exit would require adding a jump
773 and splitting the real last BB. */
774 e
= find_edge (bb
, EXIT_BLOCK_PTR
);
775 if (e
&& (e
->flags
& EDGE_FALLTHRU
))
778 return cfg_hooks
->can_duplicate_block_p (bb
);
781 /* Duplicates basic block BB and redirects edge E to it. Returns the
782 new basic block. The new basic block is placed after the basic block
786 duplicate_block (basic_block bb
, edge e
, basic_block after
)
790 gcov_type new_count
= e
? e
->count
: 0;
793 if (!cfg_hooks
->duplicate_block
)
794 internal_error ("%s does not support duplicate_block",
797 if (bb
->count
< new_count
)
798 new_count
= bb
->count
;
800 #ifdef ENABLE_CHECKING
801 gcc_assert (can_duplicate_block_p (bb
));
804 new_bb
= cfg_hooks
->duplicate_block (bb
);
806 move_block_after (new_bb
, after
);
808 new_bb
->loop_depth
= bb
->loop_depth
;
809 new_bb
->flags
= bb
->flags
;
810 FOR_EACH_EDGE (s
, ei
, bb
->succs
)
812 /* Since we are creating edges from a new block to successors
813 of another block (which therefore are known to be disjoint), there
814 is no need to actually check for duplicated edges. */
815 n
= unchecked_make_edge (new_bb
, s
->dest
, s
->flags
);
816 n
->probability
= s
->probability
;
819 /* Take care for overflows! */
820 n
->count
= s
->count
* (new_count
* 10000 / bb
->count
) / 10000;
821 s
->count
-= n
->count
;
830 new_bb
->count
= new_count
;
831 bb
->count
-= new_count
;
833 new_bb
->frequency
= EDGE_FREQUENCY (e
);
834 bb
->frequency
-= EDGE_FREQUENCY (e
);
836 redirect_edge_and_branch_force (e
, new_bb
);
840 if (bb
->frequency
< 0)
845 new_bb
->count
= bb
->count
;
846 new_bb
->frequency
= bb
->frequency
;
849 set_bb_original (new_bb
, bb
);
850 set_bb_copy (bb
, new_bb
);
852 /* Add the new block to the prescribed loop. */
853 if (current_loops
!= NULL
)
854 add_bb_to_loop (new_bb
, bb
->loop_father
->copy
);
859 /* Return 1 if BB ends with a call, possibly followed by some
860 instructions that must stay with the call, 0 otherwise. */
863 block_ends_with_call_p (basic_block bb
)
865 if (!cfg_hooks
->block_ends_with_call_p
)
866 internal_error ("%s does not support block_ends_with_call_p", cfg_hooks
->name
);
868 return (cfg_hooks
->block_ends_with_call_p
) (bb
);
871 /* Return 1 if BB ends with a conditional branch, 0 otherwise. */
874 block_ends_with_condjump_p (basic_block bb
)
876 if (!cfg_hooks
->block_ends_with_condjump_p
)
877 internal_error ("%s does not support block_ends_with_condjump_p",
880 return (cfg_hooks
->block_ends_with_condjump_p
) (bb
);
883 /* Add fake edges to the function exit for any non constant and non noreturn
884 calls, volatile inline assembly in the bitmap of blocks specified by
885 BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks
888 The goal is to expose cases in which entering a basic block does not imply
889 that all subsequent instructions must be executed. */
892 flow_call_edges_add (sbitmap blocks
)
894 if (!cfg_hooks
->flow_call_edges_add
)
895 internal_error ("%s does not support flow_call_edges_add",
898 return (cfg_hooks
->flow_call_edges_add
) (blocks
);
901 /* This function is called immediately after edge E is added to the
902 edge vector E->dest->preds. */
905 execute_on_growing_pred (edge e
)
907 if (cfg_hooks
->execute_on_growing_pred
)
908 cfg_hooks
->execute_on_growing_pred (e
);
911 /* This function is called immediately before edge E is removed from
912 the edge vector E->dest->preds. */
915 execute_on_shrinking_pred (edge e
)
917 if (cfg_hooks
->execute_on_shrinking_pred
)
918 cfg_hooks
->execute_on_shrinking_pred (e
);
921 /* This is used inside loop versioning when we want to insert
922 stmts/insns on the edges, which have a different behavior
923 in tree's and in RTL, so we made a CFG hook. */
925 lv_flush_pending_stmts (edge e
)
927 if (cfg_hooks
->flush_pending_stmts
)
928 cfg_hooks
->flush_pending_stmts (e
);
931 /* Loop versioning uses the duplicate_loop_to_header_edge to create
932 a new version of the loop basic-blocks, the parameters here are
933 exactly the same as in duplicate_loop_to_header_edge or
934 tree_duplicate_loop_to_header_edge; while in tree-ssa there is
935 additional work to maintain ssa information that's why there is
936 a need to call the tree_duplicate_loop_to_header_edge rather
937 than duplicate_loop_to_header_edge when we are in tree mode. */
939 cfg_hook_duplicate_loop_to_header_edge (struct loop
*loop
, edge e
,
941 sbitmap wont_exit
, edge orig
,
942 VEC (edge
, heap
) **to_remove
,
945 gcc_assert (cfg_hooks
->cfg_hook_duplicate_loop_to_header_edge
);
946 return cfg_hooks
->cfg_hook_duplicate_loop_to_header_edge (loop
, e
,
952 /* Conditional jumps are represented differently in trees and RTL,
953 this hook takes a basic block that is known to have a cond jump
954 at its end and extracts the taken and not taken eges out of it
955 and store it in E1 and E2 respectively. */
957 extract_cond_bb_edges (basic_block b
, edge
*e1
, edge
*e2
)
959 gcc_assert (cfg_hooks
->extract_cond_bb_edges
);
960 cfg_hooks
->extract_cond_bb_edges (b
, e1
, e2
);
963 /* Responsible for updating the ssa info (PHI nodes) on the
964 new condition basic block that guards the versioned loop. */
966 lv_adjust_loop_header_phi (basic_block first
, basic_block second
,
967 basic_block
new, edge e
)
969 if (cfg_hooks
->lv_adjust_loop_header_phi
)
970 cfg_hooks
->lv_adjust_loop_header_phi (first
, second
, new, e
);
973 /* Conditions in trees and RTL are different so we need
974 a different handling when we add the condition to the
977 lv_add_condition_to_bb (basic_block first
, basic_block second
,
978 basic_block
new, void *cond
)
980 gcc_assert (cfg_hooks
->lv_add_condition_to_bb
);
981 cfg_hooks
->lv_add_condition_to_bb (first
, second
, new, cond
);