1 /* Basic block reordering routines for the GNU compiler.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "coretypes.h"
27 #include "hard-reg-set.h"
28 #include "basic-block.h"
29 #include "insn-config.h"
33 #include "cfglayout.h"
35 /* The contents of the current function definition are allocated
36 in this obstack, and all are freed at the end of the function. */
37 extern struct obstack flow_obstack
;
39 /* Holds the interesting trailing notes for the function. */
40 static rtx function_footer
;
42 static rtx skip_insns_after_block
PARAMS ((basic_block
));
43 static void record_effective_endpoints
PARAMS ((void));
44 static rtx label_for_bb
PARAMS ((basic_block
));
45 static void fixup_reorder_chain
PARAMS ((void));
47 static void set_block_levels
PARAMS ((tree
, int));
48 static void change_scope
PARAMS ((rtx
, tree
, tree
));
50 void verify_insn_chain
PARAMS ((void));
51 static void cleanup_unconditional_jumps
PARAMS ((void));
52 static void fixup_fallthru_exit_predecessor
PARAMS ((void));
53 static rtx unlink_insn_chain
PARAMS ((rtx
, rtx
));
54 static rtx duplicate_insn_chain
PARAMS ((rtx
, rtx
));
57 unlink_insn_chain (first
, last
)
61 rtx prevfirst
= PREV_INSN (first
);
62 rtx nextlast
= NEXT_INSN (last
);
64 PREV_INSN (first
) = NULL
;
65 NEXT_INSN (last
) = NULL
;
67 NEXT_INSN (prevfirst
) = nextlast
;
69 PREV_INSN (nextlast
) = prevfirst
;
71 set_last_insn (prevfirst
);
73 set_first_insn (nextlast
);
77 /* Skip over inter-block insns occurring after BB which are typically
78 associated with BB (e.g., barriers). If there are any such insns,
79 we return the last one. Otherwise, we return the end of BB. */
82 skip_insns_after_block (bb
)
85 rtx insn
, last_insn
, next_head
, prev
;
88 if (bb
->next_bb
!= EXIT_BLOCK_PTR
)
89 next_head
= bb
->next_bb
->head
;
91 for (last_insn
= insn
= bb
->end
; (insn
= NEXT_INSN (insn
)) != 0; )
93 if (insn
== next_head
)
96 switch (GET_CODE (insn
))
103 switch (NOTE_LINE_NUMBER (insn
))
105 case NOTE_INSN_LOOP_END
:
106 case NOTE_INSN_BLOCK_END
:
109 case NOTE_INSN_DELETED
:
110 case NOTE_INSN_DELETED_LABEL
:
121 && GET_CODE (NEXT_INSN (insn
)) == JUMP_INSN
122 && (GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_VEC
123 || GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_DIFF_VEC
))
125 insn
= NEXT_INSN (insn
);
138 /* It is possible to hit contradictory sequence. For instance:
144 Where barrier belongs to jump_insn, but the note does not. This can be
145 created by removing the basic block originally following
146 NOTE_INSN_LOOP_BEG. In such case reorder the notes. */
148 for (insn
= last_insn
; insn
!= bb
->end
; insn
= prev
)
150 prev
= PREV_INSN (insn
);
151 if (GET_CODE (insn
) == NOTE
)
152 switch (NOTE_LINE_NUMBER (insn
))
154 case NOTE_INSN_LOOP_END
:
155 case NOTE_INSN_BLOCK_END
:
156 case NOTE_INSN_DELETED
:
157 case NOTE_INSN_DELETED_LABEL
:
160 reorder_insns (insn
, insn
, last_insn
);
167 /* Locate or create a label for a given basic block. */
173 rtx label
= bb
->head
;
175 if (GET_CODE (label
) != CODE_LABEL
)
178 fprintf (rtl_dump_file
, "Emitting label for block %d\n", bb
->index
);
180 label
= block_label (bb
);
186 /* Locate the effective beginning and end of the insn chain for each
187 block, as defined by skip_insns_after_block above. */
190 record_effective_endpoints ()
192 rtx next_insn
= get_insns ();
199 if (PREV_INSN (bb
->head
) && next_insn
!= bb
->head
)
200 RBI (bb
)->header
= unlink_insn_chain (next_insn
,
201 PREV_INSN (bb
->head
));
202 end
= skip_insns_after_block (bb
);
203 if (NEXT_INSN (bb
->end
) && bb
->end
!= end
)
204 RBI (bb
)->footer
= unlink_insn_chain (NEXT_INSN (bb
->end
), end
);
205 next_insn
= NEXT_INSN (bb
->end
);
208 function_footer
= next_insn
;
210 function_footer
= unlink_insn_chain (function_footer
, get_last_insn ());
213 /* Build a varray mapping INSN_UID to lexical block. Return it. */
216 scope_to_insns_initialize ()
221 for (insn
= get_insns (); insn
; insn
= next
)
223 next
= NEXT_INSN (insn
);
225 if (active_insn_p (insn
)
226 && GET_CODE (PATTERN (insn
)) != ADDR_VEC
227 && GET_CODE (PATTERN (insn
)) != ADDR_DIFF_VEC
)
228 INSN_SCOPE (insn
) = block
;
229 else if (GET_CODE (insn
) == NOTE
)
231 switch (NOTE_LINE_NUMBER (insn
))
233 case NOTE_INSN_BLOCK_BEG
:
234 block
= NOTE_BLOCK (insn
);
237 case NOTE_INSN_BLOCK_END
:
238 block
= BLOCK_SUPERCONTEXT (block
);
247 /* Tag the blocks with a depth number so that change_scope can find
248 the common parent easily. */
249 set_block_levels (DECL_INITIAL (cfun
->decl
), 0);
252 /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
253 found in the block tree. */
256 set_block_levels (block
, level
)
262 BLOCK_NUMBER (block
) = level
;
263 set_block_levels (BLOCK_SUBBLOCKS (block
), level
+ 1);
264 block
= BLOCK_CHAIN (block
);
268 /* Return sope resulting from combination of S1 and S2. */
270 choose_inner_scope (s1
, s2
)
277 if (BLOCK_NUMBER (s1
) > BLOCK_NUMBER (s2
))
282 /* Emit lexical block notes needed to change scope from S1 to S2. */
285 change_scope (orig_insn
, s1
, s2
)
289 rtx insn
= orig_insn
;
290 tree com
= NULL_TREE
;
291 tree ts1
= s1
, ts2
= s2
;
296 if (ts1
== NULL
|| ts2
== NULL
)
298 if (BLOCK_NUMBER (ts1
) > BLOCK_NUMBER (ts2
))
299 ts1
= BLOCK_SUPERCONTEXT (ts1
);
300 else if (BLOCK_NUMBER (ts1
) < BLOCK_NUMBER (ts2
))
301 ts2
= BLOCK_SUPERCONTEXT (ts2
);
304 ts1
= BLOCK_SUPERCONTEXT (ts1
);
305 ts2
= BLOCK_SUPERCONTEXT (ts2
);
314 rtx note
= emit_note_before (NOTE_INSN_BLOCK_END
, insn
);
315 NOTE_BLOCK (note
) = s
;
316 s
= BLOCK_SUPERCONTEXT (s
);
323 insn
= emit_note_before (NOTE_INSN_BLOCK_BEG
, insn
);
324 NOTE_BLOCK (insn
) = s
;
325 s
= BLOCK_SUPERCONTEXT (s
);
329 /* Rebuild all the NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes based
330 on the scope tree and the newly reordered instructions. */
333 scope_to_insns_finalize ()
335 tree cur_block
= DECL_INITIAL (cfun
->decl
);
339 if (!active_insn_p (insn
))
340 insn
= next_active_insn (insn
);
341 for (; insn
; insn
= next_active_insn (insn
))
345 this_block
= INSN_SCOPE (insn
);
346 /* For sequences compute scope resulting from merging all scopes
347 of instructions nested inside. */
348 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
351 rtx body
= PATTERN (insn
);
354 for (i
= 0; i
< XVECLEN (body
, 0); i
++)
355 this_block
= choose_inner_scope (this_block
,
356 INSN_SCOPE (XVECEXP (body
, 0, i
)));
361 if (this_block
!= cur_block
)
363 change_scope (insn
, cur_block
, this_block
);
364 cur_block
= this_block
;
368 /* change_scope emits before the insn, not after. */
369 note
= emit_note (NULL
, NOTE_INSN_DELETED
);
370 change_scope (note
, cur_block
, DECL_INITIAL (cfun
->decl
));
376 /* Given a reorder chain, rearrange the code to match. */
379 fixup_reorder_chain ()
381 basic_block bb
, prev_bb
;
385 /* First do the bulk reordering -- rechain the blocks without regard to
386 the needed changes to jumps and labels. */
388 for (bb
= ENTRY_BLOCK_PTR
->next_bb
, index
= 0;
390 bb
= RBI (bb
)->next
, index
++)
392 if (RBI (bb
)->header
)
395 NEXT_INSN (insn
) = RBI (bb
)->header
;
397 set_first_insn (RBI (bb
)->header
);
398 PREV_INSN (RBI (bb
)->header
) = insn
;
399 insn
= RBI (bb
)->header
;
400 while (NEXT_INSN (insn
))
401 insn
= NEXT_INSN (insn
);
404 NEXT_INSN (insn
) = bb
->head
;
406 set_first_insn (bb
->head
);
407 PREV_INSN (bb
->head
) = insn
;
409 if (RBI (bb
)->footer
)
411 NEXT_INSN (insn
) = RBI (bb
)->footer
;
412 PREV_INSN (RBI (bb
)->footer
) = insn
;
413 while (NEXT_INSN (insn
))
414 insn
= NEXT_INSN (insn
);
418 if (index
!= n_basic_blocks
)
421 NEXT_INSN (insn
) = function_footer
;
423 PREV_INSN (function_footer
) = insn
;
425 while (NEXT_INSN (insn
))
426 insn
= NEXT_INSN (insn
);
428 set_last_insn (insn
);
429 #ifdef ENABLE_CHECKING
430 verify_insn_chain ();
433 /* Now add jumps and labels as needed to match the blocks new
436 for (bb
= ENTRY_BLOCK_PTR
->next_bb
; bb
; bb
= RBI (bb
)->next
)
438 edge e_fall
, e_taken
, e
;
442 if (bb
->succ
== NULL
)
445 /* Find the old fallthru edge, and another non-EH edge for
447 e_taken
= e_fall
= NULL
;
448 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
449 if (e
->flags
& EDGE_FALLTHRU
)
451 else if (! (e
->flags
& EDGE_EH
))
454 bb_end_insn
= bb
->end
;
455 if (GET_CODE (bb_end_insn
) == JUMP_INSN
)
457 if (any_condjump_p (bb_end_insn
))
459 /* If the old fallthru is still next, nothing to do. */
460 if (RBI (bb
)->next
== e_fall
->dest
462 && e_fall
->dest
== EXIT_BLOCK_PTR
))
465 /* There is one special case: if *neither* block is next,
466 such as happens at the very end of a function, then we'll
467 need to add a new unconditional jump. Choose the taken
468 edge based on known or assumed probability. */
469 if (RBI (bb
)->next
!= e_taken
->dest
)
471 rtx note
= find_reg_note (bb_end_insn
, REG_BR_PROB
, 0);
474 && INTVAL (XEXP (note
, 0)) < REG_BR_PROB_BASE
/ 2
475 && invert_jump (bb_end_insn
,
476 label_for_bb (e_fall
->dest
), 0))
478 e_fall
->flags
&= ~EDGE_FALLTHRU
;
479 e_taken
->flags
|= EDGE_FALLTHRU
;
480 update_br_prob_note (bb
);
481 e
= e_fall
, e_fall
= e_taken
, e_taken
= e
;
485 /* Otherwise we can try to invert the jump. This will
486 basically never fail, however, keep up the pretense. */
487 else if (invert_jump (bb_end_insn
,
488 label_for_bb (e_fall
->dest
), 0))
490 e_fall
->flags
&= ~EDGE_FALLTHRU
;
491 e_taken
->flags
|= EDGE_FALLTHRU
;
492 update_br_prob_note (bb
);
496 else if (returnjump_p (bb_end_insn
))
500 /* Otherwise we have some switch or computed jump. In the
501 99% case, there should not have been a fallthru edge. */
505 #ifdef CASE_DROPS_THROUGH
506 /* Except for VAX. Since we didn't have predication for the
507 tablejump, the fallthru block should not have moved. */
508 if (RBI (bb
)->next
== e_fall
->dest
)
510 bb_end_insn
= skip_insns_after_block (bb
);
518 /* No fallthru implies a noreturn function with EH edges, or
519 something similarly bizarre. In any case, we don't need to
524 /* If the fallthru block is still next, nothing to do. */
525 if (RBI (bb
)->next
== e_fall
->dest
)
528 /* A fallthru to exit block. */
529 if (!RBI (bb
)->next
&& e_fall
->dest
== EXIT_BLOCK_PTR
)
533 /* We got here if we need to add a new jump insn. */
534 nb
= force_nonfallthru (e_fall
);
537 alloc_aux_for_block (nb
, sizeof (struct reorder_block_def
));
538 RBI (nb
)->visited
= 1;
539 RBI (nb
)->next
= RBI (bb
)->next
;
541 /* Don't process this new block. */
546 /* Put basic_block_info in the new order. */
550 fprintf (rtl_dump_file
, "Reordered sequence:\n");
551 for (bb
= ENTRY_BLOCK_PTR
->next_bb
, index
= 0; bb
; bb
= RBI (bb
)->next
, index
++)
553 fprintf (rtl_dump_file
, " %i ", index
);
554 if (RBI (bb
)->original
)
555 fprintf (rtl_dump_file
, "duplicate of %i ",
556 RBI (bb
)->original
->index
);
557 else if (forwarder_block_p (bb
) && GET_CODE (bb
->head
) != CODE_LABEL
)
558 fprintf (rtl_dump_file
, "compensation ");
560 fprintf (rtl_dump_file
, "bb %i ", bb
->index
);
561 fprintf (rtl_dump_file
, " [%i]\n", bb
->frequency
);
565 prev_bb
= ENTRY_BLOCK_PTR
;
566 bb
= ENTRY_BLOCK_PTR
->next_bb
;
569 for (; bb
; prev_bb
= bb
, bb
= RBI (bb
)->next
, index
++)
572 BASIC_BLOCK (index
) = bb
;
574 bb
->prev_bb
= prev_bb
;
575 prev_bb
->next_bb
= bb
;
577 prev_bb
->next_bb
= EXIT_BLOCK_PTR
;
578 EXIT_BLOCK_PTR
->prev_bb
= prev_bb
;
581 /* Perform sanity checks on the insn chain.
582 1. Check that next/prev pointers are consistent in both the forward and
584 2. Count insns in chain, going both directions, and check if equal.
585 3. Check that get_last_insn () returns the actual end of chain. */
591 int insn_cnt1
, insn_cnt2
;
593 for (prevx
= NULL
, insn_cnt1
= 1, x
= get_insns ();
595 prevx
= x
, insn_cnt1
++, x
= NEXT_INSN (x
))
596 if (PREV_INSN (x
) != prevx
)
599 if (prevx
!= get_last_insn ())
602 for (nextx
= NULL
, insn_cnt2
= 1, x
= get_last_insn ();
604 nextx
= x
, insn_cnt2
++, x
= PREV_INSN (x
))
605 if (NEXT_INSN (x
) != nextx
)
608 if (insn_cnt1
!= insn_cnt2
)
612 /* Remove any unconditional jumps and forwarder block creating fallthru
613 edges instead. During BB reordering, fallthru edges are not required
614 to target next basic block in the linear CFG layout, so the unconditional
615 jumps are not needed. */
618 cleanup_unconditional_jumps ()
626 if (bb
->succ
->flags
& EDGE_FALLTHRU
)
628 if (!bb
->succ
->succ_next
)
631 if (GET_CODE (bb
->head
) != CODE_LABEL
&& forwarder_block_p (bb
)
632 && bb
->prev_bb
!= ENTRY_BLOCK_PTR
)
634 basic_block prev
= bb
->prev_bb
;
637 fprintf (rtl_dump_file
, "Removing forwarder BB %i\n",
640 redirect_edge_succ_nodup (bb
->pred
, bb
->succ
->dest
);
641 flow_delete_block (bb
);
644 else if (simplejump_p (bb
->end
))
649 fprintf (rtl_dump_file
, "Removing jump %i in BB %i\n",
650 INSN_UID (jump
), bb
->index
);
652 bb
->succ
->flags
|= EDGE_FALLTHRU
;
657 insn
= NEXT_INSN (bb
->end
);
659 && (GET_CODE (insn
) != NOTE
660 || NOTE_LINE_NUMBER (insn
) != NOTE_INSN_BASIC_BLOCK
))
662 rtx next
= NEXT_INSN (insn
);
664 if (GET_CODE (insn
) == BARRIER
)
665 delete_barrier (insn
);
673 /* The block falling through to exit must be the last one in the
674 reordered chain. Ensure that this condition is met. */
676 fixup_fallthru_exit_predecessor ()
679 basic_block bb
= NULL
;
681 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
682 if (e
->flags
& EDGE_FALLTHRU
)
685 if (bb
&& RBI (bb
)->next
)
687 basic_block c
= ENTRY_BLOCK_PTR
->next_bb
;
689 while (RBI (c
)->next
!= bb
)
692 RBI (c
)->next
= RBI (bb
)->next
;
693 while (RBI (c
)->next
)
697 RBI (bb
)->next
= NULL
;
701 /* Return true in case it is possible to duplicate the basic block BB. */
704 cfg_layout_can_duplicate_bb_p (bb
)
710 if (bb
== EXIT_BLOCK_PTR
|| bb
== ENTRY_BLOCK_PTR
)
713 /* Duplicating fallthru block to exit would require adding a jump
714 and splitting the real last BB. */
715 for (s
= bb
->succ
; s
; s
= s
->succ_next
)
716 if (s
->dest
== EXIT_BLOCK_PTR
&& s
->flags
& EDGE_FALLTHRU
)
719 /* Do not attempt to duplicate tablejumps, as we need to unshare
720 the dispatch table. This is dificult to do, as the instructions
721 computing jump destination may be hoisted outside the basic block. */
722 if (GET_CODE (bb
->end
) == JUMP_INSN
&& JUMP_LABEL (bb
->end
)
723 && (next
= next_nonnote_insn (JUMP_LABEL (bb
->end
)))
724 && GET_CODE (next
) == JUMP_INSN
725 && (GET_CODE (PATTERN (next
)) == ADDR_VEC
726 || GET_CODE (PATTERN (next
)) == ADDR_DIFF_VEC
))
732 duplicate_insn_chain (from
, to
)
737 /* Avoid updating of boundaries of previous basic block. The
738 note will get removed from insn stream in fixup. */
739 last
= emit_note (NULL
, NOTE_INSN_DELETED
);
741 /* Create copy at the end of INSN chain. The chain will
742 be reordered later. */
743 for (insn
= from
; insn
!= NEXT_INSN (to
); insn
= NEXT_INSN (insn
))
745 switch (GET_CODE (insn
))
750 /* Avoid copying of dispatch tables. We never duplicate
751 tablejumps, so this can hit only in case the table got
752 moved far from original jump. */
753 if (GET_CODE (PATTERN (insn
)) == ADDR_VEC
754 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
)
756 emit_copy_of_insn_after (insn
, get_last_insn ());
767 switch (NOTE_LINE_NUMBER (insn
))
769 /* In case prologue is empty and function contain label
770 in first BB, we may want to copy the block. */
771 case NOTE_INSN_PROLOGUE_END
:
773 case NOTE_INSN_LOOP_VTOP
:
774 case NOTE_INSN_LOOP_CONT
:
775 case NOTE_INSN_LOOP_BEG
:
776 case NOTE_INSN_LOOP_END
:
777 /* Strip down the loop notes - we don't really want to keep
778 them consistent in loop copies. */
779 case NOTE_INSN_DELETED
:
780 case NOTE_INSN_DELETED_LABEL
:
781 /* No problem to strip these. */
782 case NOTE_INSN_EPILOGUE_BEG
:
783 case NOTE_INSN_FUNCTION_END
:
784 /* Debug code expect these notes to exist just once.
785 Keep them in the master copy.
786 ??? It probably makes more sense to duplicate them for each
788 case NOTE_INSN_FUNCTION_BEG
:
789 /* There is always just single entry to function. */
790 case NOTE_INSN_BASIC_BLOCK
:
793 /* There is no purpose to duplicate prologue. */
794 case NOTE_INSN_BLOCK_BEG
:
795 case NOTE_INSN_BLOCK_END
:
796 /* The BLOCK_BEG/BLOCK_END notes should be eliminated when BB
797 reordering is in the progress. */
798 case NOTE_INSN_EH_REGION_BEG
:
799 case NOTE_INSN_EH_REGION_END
:
800 /* Should never exist at BB duplication time. */
803 case NOTE_INSN_REPEATED_LINE_NUMBER
:
804 emit_note (NOTE_SOURCE_FILE (insn
), NOTE_LINE_NUMBER (insn
));
808 if (NOTE_LINE_NUMBER (insn
) < 0)
810 /* It is possible that no_line_number is set and the note
812 emit_note (NOTE_SOURCE_FILE (insn
), NOTE_LINE_NUMBER (insn
));
819 insn
= NEXT_INSN (last
);
824 /* Redirect Edge to DEST. */
826 cfg_layout_redirect_edge (e
, dest
)
830 basic_block src
= e
->src
;
831 basic_block old_next_bb
= src
->next_bb
;
833 /* Redirect_edge_and_branch may decide to turn branch into fallthru edge
834 in the case the basic block appears to be in sequence. Avoid this
838 if (e
->flags
& EDGE_FALLTHRU
)
840 /* In case we are redirecting fallthru edge to the branch edge
841 of conditional jump, remove it. */
842 if (src
->succ
->succ_next
843 && !src
->succ
->succ_next
->succ_next
)
845 edge s
= e
->succ_next
? e
->succ_next
: src
->succ
;
847 && any_condjump_p (src
->end
)
848 && onlyjump_p (src
->end
))
849 delete_insn (src
->end
);
851 redirect_edge_succ_nodup (e
, dest
);
854 redirect_edge_and_branch (e
, dest
);
856 /* We don't want simplejumps in the insn stream during cfglayout. */
857 if (simplejump_p (src
->end
))
859 delete_insn (src
->end
);
860 delete_barrier (NEXT_INSN (src
->end
));
861 src
->succ
->flags
|= EDGE_FALLTHRU
;
863 src
->next_bb
= old_next_bb
;
866 /* Create a duplicate of the basic block BB and redirect edge E into it. */
869 cfg_layout_duplicate_bb (bb
, e
)
876 gcov_type new_count
= e
? e
->count
: 0;
878 if (bb
->count
< new_count
)
879 new_count
= bb
->count
;
882 #ifdef ENABLE_CHECKING
883 if (!cfg_layout_can_duplicate_bb_p (bb
))
887 insn
= duplicate_insn_chain (bb
->head
, bb
->end
);
888 new_bb
= create_basic_block (insn
,
889 insn
? get_last_insn () : NULL
,
890 EXIT_BLOCK_PTR
->prev_bb
);
891 alloc_aux_for_block (new_bb
, sizeof (struct reorder_block_def
));
893 if (RBI (bb
)->header
)
895 insn
= RBI (bb
)->header
;
896 while (NEXT_INSN (insn
))
897 insn
= NEXT_INSN (insn
);
898 insn
= duplicate_insn_chain (RBI (bb
)->header
, insn
);
900 RBI (new_bb
)->header
= unlink_insn_chain (insn
, get_last_insn ());
903 if (RBI (bb
)->footer
)
905 insn
= RBI (bb
)->footer
;
906 while (NEXT_INSN (insn
))
907 insn
= NEXT_INSN (insn
);
908 insn
= duplicate_insn_chain (RBI (bb
)->footer
, insn
);
910 RBI (new_bb
)->footer
= unlink_insn_chain (insn
, get_last_insn ());
913 if (bb
->global_live_at_start
)
915 new_bb
->global_live_at_start
= OBSTACK_ALLOC_REG_SET (&flow_obstack
);
916 new_bb
->global_live_at_end
= OBSTACK_ALLOC_REG_SET (&flow_obstack
);
917 COPY_REG_SET (new_bb
->global_live_at_start
, bb
->global_live_at_start
);
918 COPY_REG_SET (new_bb
->global_live_at_end
, bb
->global_live_at_end
);
921 new_bb
->loop_depth
= bb
->loop_depth
;
922 new_bb
->flags
= bb
->flags
;
923 for (s
= bb
->succ
; s
; s
= s
->succ_next
)
925 n
= make_edge (new_bb
, s
->dest
, s
->flags
);
926 n
->probability
= s
->probability
;
928 /* Take care for overflows! */
929 n
->count
= s
->count
* (new_count
* 10000 / bb
->count
) / 10000;
932 s
->count
-= n
->count
;
935 new_bb
->count
= new_count
;
936 bb
->count
-= new_count
;
940 new_bb
->frequency
= EDGE_FREQUENCY (e
);
941 bb
->frequency
-= EDGE_FREQUENCY (e
);
943 cfg_layout_redirect_edge (e
, new_bb
);
948 if (bb
->frequency
< 0)
951 RBI (new_bb
)->original
= bb
;
955 /* Main entry point to this module - initialize the datastructures for
956 CFG layout changes. It keeps LOOPS up-to-date if not null. */
959 cfg_layout_initialize ()
961 /* Our algorithm depends on fact that there are now dead jumptables
963 alloc_aux_for_blocks (sizeof (struct reorder_block_def
));
965 cleanup_unconditional_jumps ();
967 record_effective_endpoints ();
970 /* Finalize the changes: reorder insn list according to the sequence, enter
971 compensation code, rebuild scope forest. */
974 cfg_layout_finalize ()
976 fixup_fallthru_exit_predecessor ();
977 fixup_reorder_chain ();
979 #ifdef ENABLE_CHECKING
980 verify_insn_chain ();
983 free_aux_for_blocks ();
985 #ifdef ENABLE_CHECKING