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
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
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
24 #include "hard-reg-set.h"
25 #include "basic-block.h"
26 #include "insn-config.h"
30 #include "cfglayout.h"
32 /* The contents of the current function definition are allocated
33 in this obstack, and all are freed at the end of the function.
34 For top-level functions, this is temporary_obstack.
35 Separate obstacks are made for nested functions. */
37 extern struct obstack flow_obstack
;
39 /* Structure to hold information about lexical scopes. */
44 /* The NOTE_INSN_BLOCK_BEG that started this scope. */
47 /* The NOTE_INSN_BLOCK_END that ended this scope. */
50 /* The bb containing note_beg (if any). */
53 /* The bb containing note_end (if any). */
56 /* List of basic blocks contained within this scope. */
59 /* Number of blocks contained within this scope. */
62 /* The outer scope or NULL if outermost scope. */
63 struct scope_def
*outer
;
65 /* The first inner scope or NULL if innermost scope. */
66 struct scope_def
*inner
;
68 /* The last inner scope or NULL if innermost scope. */
69 struct scope_def
*inner_last
;
71 /* Link to the next (sibling) scope. */
72 struct scope_def
*next
;
75 /* Structure to hold information about the scope forest. */
78 /* Number of trees in forest. */
81 /* List of tree roots. */
85 /* Holds the interesting trailing notes for the function. */
86 static rtx function_tail_eff_head
;
88 /* The scope forest of current function. */
89 static scope_forest_info forest
;
91 static rtx skip_insns_after_block
PARAMS ((basic_block
));
92 static void record_effective_endpoints
PARAMS ((void));
93 static rtx label_for_bb
PARAMS ((basic_block
));
94 static void fixup_reorder_chain
PARAMS ((void));
96 static void relate_bbs_with_scopes
PARAMS ((scope
));
97 static scope make_new_scope
PARAMS ((int, rtx
));
98 static void build_scope_forest
PARAMS ((scope_forest_info
*));
99 static void remove_scope_notes
PARAMS ((void));
100 static void insert_intra_1
PARAMS ((scope
, rtx
*, basic_block
));
101 static void insert_intra_bb_scope_notes
PARAMS ((basic_block
));
102 static void insert_inter_bb_scope_notes
PARAMS ((basic_block
, basic_block
));
103 static void rebuild_scope_notes
PARAMS ((scope_forest_info
*));
104 static void free_scope_forest_1
PARAMS ((scope
));
105 static void free_scope_forest
PARAMS ((scope_forest_info
*));
106 void dump_scope_forest
PARAMS ((scope_forest_info
*));
107 static void dump_scope_forest_1
PARAMS ((scope
, int));
109 static rtx get_next_bb_note
PARAMS ((rtx
));
110 static rtx get_prev_bb_note
PARAMS ((rtx
));
112 void verify_insn_chain
PARAMS ((void));
113 static void fixup_fallthru_exit_predecessor
PARAMS ((void));
115 /* Skip over inter-block insns occurring after BB which are typically
116 associated with BB (e.g., barriers). If there are any such insns,
117 we return the last one. Otherwise, we return the end of BB. */
120 skip_insns_after_block (bb
)
123 rtx insn
, last_insn
, next_head
, prev
;
125 next_head
= NULL_RTX
;
126 if (bb
->index
+ 1 != n_basic_blocks
)
127 next_head
= BASIC_BLOCK (bb
->index
+ 1)->head
;
129 for (last_insn
= insn
= bb
->end
; (insn
= NEXT_INSN (insn
)); )
131 if (insn
== next_head
)
134 switch (GET_CODE (insn
))
141 switch (NOTE_LINE_NUMBER (insn
))
143 case NOTE_INSN_LOOP_END
:
144 case NOTE_INSN_BLOCK_END
:
147 case NOTE_INSN_DELETED
:
148 case NOTE_INSN_DELETED_LABEL
:
159 && GET_CODE (NEXT_INSN (insn
)) == JUMP_INSN
160 && (GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_VEC
161 || GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_DIFF_VEC
))
163 insn
= NEXT_INSN (insn
);
175 /* It is possible to hit contradicting sequence. For instance:
181 Where barrier belongs to jump_insn, but the note does not.
182 This can be created by removing the basic block originally
183 following NOTE_INSN_LOOP_BEG.
185 In such case reorder the notes. */
186 for (insn
= last_insn
; insn
!= bb
->end
; insn
= prev
)
188 prev
= PREV_INSN (insn
);
189 if (GET_CODE (insn
) == NOTE
)
190 switch (NOTE_LINE_NUMBER (insn
))
192 case NOTE_INSN_LOOP_END
:
193 case NOTE_INSN_BLOCK_END
:
194 case NOTE_INSN_DELETED
:
195 case NOTE_INSN_DELETED_LABEL
:
198 reorder_insns (insn
, insn
, last_insn
);
205 /* Locate or create a label for a given basic block. */
211 rtx label
= bb
->head
;
213 if (GET_CODE (label
) != CODE_LABEL
)
216 fprintf (rtl_dump_file
, "Emitting label for block %d\n",
219 label
= block_label (bb
);
220 if (bb
->head
== PREV_INSN (RBI (bb
)->eff_head
))
221 RBI (bb
)->eff_head
= label
;
227 /* Locate the effective beginning and end of the insn chain for each
228 block, as defined by skip_insns_after_block above. */
231 record_effective_endpoints ()
233 rtx next_insn
= get_insns ();
236 for (i
= 0; i
< n_basic_blocks
; ++i
)
238 basic_block bb
= BASIC_BLOCK (i
);
241 RBI (bb
)->eff_head
= next_insn
;
242 end
= skip_insns_after_block (bb
);
243 RBI (bb
)->eff_end
= end
;
244 next_insn
= NEXT_INSN (end
);
246 function_tail_eff_head
= next_insn
;
255 if (NOTE_INSN_BASIC_BLOCK_P (x
))
268 if (NOTE_INSN_BASIC_BLOCK_P (x
))
275 /* Determine and record the relationships between basic blocks and
276 scopes in scope tree S. */
279 relate_bbs_with_scopes (s
)
283 int i
, bbi1
, bbi2
, bbs_spanned
;
286 for (p
= s
->inner
; p
; p
= p
->next
)
287 relate_bbs_with_scopes (p
);
292 /* If the begin and end notes are both inside the same basic block,
293 or if they are both outside of basic blocks, then we know immediately
294 how they are related. Otherwise, we need to poke around to make the
296 if (s
->bb_beg
!= s
->bb_end
)
298 if (s
->bb_beg
&& s
->bb_end
)
300 /* Both notes are in different bbs. This implies that all the
301 basic blocks spanned by the pair of notes are contained in
303 bbi1
= s
->bb_beg
->index
;
304 bbi2
= s
->bb_end
->index
;
307 else if (! s
->bb_beg
)
309 /* First note is outside of a bb. If the scope spans more than
310 one basic block, then they all are contained within this
311 scope. Otherwise, this scope is contained within the basic
313 bbnote
= get_next_bb_note (s
->note_beg
);
316 if (NOTE_BASIC_BLOCK (bbnote
) == s
->bb_end
)
319 s
->bb_beg
= NOTE_BASIC_BLOCK (bbnote
);
323 bbi1
= NOTE_BASIC_BLOCK (bbnote
)->index
;
324 bbi2
= s
->bb_end
->index
;
329 else /* ! s->bb_end */
331 /* Second note is outside of a bb. If the scope spans more than
332 one basic block, then they all are contained within this
333 scope. Otherwise, this scope is contained within the basic
335 bbnote
= get_prev_bb_note (s
->note_end
);
338 if (NOTE_BASIC_BLOCK (bbnote
) == s
->bb_beg
)
341 s
->bb_end
= NOTE_BASIC_BLOCK (bbnote
);
345 bbi1
= s
->bb_beg
->index
;
346 bbi2
= NOTE_BASIC_BLOCK (bbnote
)->index
;
355 /* Both notes are in the same bb, which implies the block
356 contains this scope. */
361 /* Both notes are outside of any bbs. This implies that all the
362 basic blocks spanned by the pair of notes are contained in
364 There is a degenerate case to consider. If the notes do not
365 span any basic blocks, then it is an empty scope that can
366 safely be deleted or ignored. Mark these with level = -1. */
368 x1
= get_next_bb_note (s
->note_beg
);
369 x2
= get_prev_bb_note (s
->note_end
);
377 bbi1
= NOTE_BASIC_BLOCK (x1
)->index
;
378 bbi2
= NOTE_BASIC_BLOCK (x2
)->index
;
384 /* If the scope spans one or more basic blocks, we record them. We
385 only record the bbs that are immediately contained within this
386 scope. Note that if a scope is contained within a bb, we can tell
387 by checking that bb_beg = bb_end and that they are non-null. */
393 for (i
= bbi1
; i
<= bbi2
; i
++)
394 if (! RBI (BASIC_BLOCK (i
))->scope
)
397 s
->bbs
= xmalloc (s
->num_bbs
* sizeof (basic_block
));
398 for (i
= bbi1
; i
<= bbi2
; i
++)
400 basic_block curr_bb
= BASIC_BLOCK (i
);
401 if (! RBI (curr_bb
)->scope
)
403 s
->bbs
[j
++] = curr_bb
;
404 RBI (curr_bb
)->scope
= s
;
412 /* Allocate and initialize a new scope structure with scope level LEVEL,
413 and record the NOTE beginning the scope. */
416 make_new_scope (level
, note
)
420 scope new_scope
= xcalloc (1, sizeof (struct scope_def
));
421 new_scope
->level
= level
;
422 new_scope
->note_beg
= note
;
427 /* Build a forest representing the scope structure of the function.
428 Return a pointer to a structure describing the forest. */
431 build_scope_forest (forest
)
432 scope_forest_info
*forest
;
437 scope root
, curr_scope
= 0;
439 forest
->num_trees
= 0;
440 forest
->trees
= NULL
;
445 for (x
= get_insns (); x
; x
= NEXT_INSN (x
))
447 if (bbi
< n_basic_blocks
&& x
== BASIC_BLOCK (bbi
)->head
)
448 curr_bb
= BASIC_BLOCK (bbi
);
450 if (GET_CODE (x
) == NOTE
)
452 if (NOTE_LINE_NUMBER (x
) == NOTE_INSN_BLOCK_BEG
)
460 new_scope
= make_new_scope (level
, x
);
461 new_scope
->outer
= curr_scope
;
462 new_scope
->next
= NULL
;
463 if (! curr_scope
->inner
)
465 curr_scope
->inner
= new_scope
;
466 curr_scope
->inner_last
= new_scope
;
470 curr_scope
->inner_last
->next
= new_scope
;
471 curr_scope
->inner_last
= new_scope
;
473 curr_scope
= curr_scope
->inner_last
;
477 int ntrees
= forest
->num_trees
;
479 curr_scope
= make_new_scope (level
, x
);
481 forest
->trees
= xrealloc (forest
->trees
,
482 sizeof (scope
) * (ntrees
+ 1));
483 forest
->trees
[forest
->num_trees
++] = root
;
485 curr_scope
->bb_beg
= curr_bb
;
487 else if (NOTE_LINE_NUMBER (x
) == NOTE_INSN_BLOCK_END
)
489 curr_scope
->bb_end
= curr_bb
;
490 curr_scope
->note_end
= x
;
492 curr_scope
= curr_scope
->outer
;
498 if (curr_bb
&& curr_bb
->end
== x
)
506 for (i
= 0; i
< forest
->num_trees
; i
++)
507 relate_bbs_with_scopes (forest
->trees
[i
]);
510 /* Remove all the NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes from
514 remove_scope_notes ()
517 basic_block currbb
= NULL
;
519 for (x
= get_insns (); x
; x
= next
)
521 next
= NEXT_INSN (x
);
522 if (NOTE_INSN_BASIC_BLOCK_P (x
))
523 currbb
= NOTE_BASIC_BLOCK (x
);
525 if (GET_CODE (x
) == NOTE
526 && (NOTE_LINE_NUMBER (x
) == NOTE_INSN_BLOCK_BEG
527 || NOTE_LINE_NUMBER (x
) == NOTE_INSN_BLOCK_END
))
529 /* Check if the scope note happens to be the end of a bb. */
530 if (currbb
&& x
== currbb
->end
)
531 currbb
->end
= PREV_INSN (x
);
532 if (currbb
&& x
== currbb
->head
)
537 NEXT_INSN (PREV_INSN (x
)) = next
;
538 PREV_INSN (next
) = PREV_INSN (x
);
540 NEXT_INSN (x
) = NULL
;
541 PREV_INSN (x
) = NULL
;
549 /* Insert scope note pairs for a contained scope tree S after insn IP. */
552 insert_intra_1 (s
, ip
, bb
)
559 if (NOTE_BLOCK (s
->note_beg
))
561 *ip
= emit_note_after (NOTE_INSN_BLOCK_BEG
, *ip
);
562 NOTE_BLOCK (*ip
) = NOTE_BLOCK (s
->note_beg
);
565 for (p
= s
->inner
; p
; p
= p
->next
)
566 insert_intra_1 (p
, ip
, bb
);
568 if (NOTE_BLOCK (s
->note_beg
))
570 *ip
= emit_note_after (NOTE_INSN_BLOCK_END
, *ip
);
571 NOTE_BLOCK (*ip
) = NOTE_BLOCK (s
->note_end
);
576 /* Insert NOTE_INSN_BLOCK_END notes and NOTE_INSN_BLOCK_BEG notes for
577 scopes that are contained within BB. */
580 insert_intra_bb_scope_notes (bb
)
583 scope s
= RBI (bb
)->scope
;
591 if (GET_CODE (ip
) == CODE_LABEL
)
594 for (p
= s
->inner
; p
; p
= p
->next
)
596 if (p
->bb_beg
!= NULL
&& p
->bb_beg
== p
->bb_end
&& p
->bb_beg
== bb
)
597 insert_intra_1 (p
, &ip
, bb
);
602 /* Given two consecutive basic blocks BB1 and BB2 with different scopes,
603 insert NOTE_INSN_BLOCK_END notes after BB1 and NOTE_INSN_BLOCK_BEG
604 notes before BB2 such that the notes are correctly balanced. If BB1 or
605 BB2 is NULL, we are inserting scope notes for the first and last basic
606 blocks, respectively. */
609 insert_inter_bb_scope_notes (bb1
, bb2
)
616 /* It is possible that a basic block is not contained in any scope.
617 In that case, we either open or close a scope but not both. */
620 scope s1
= RBI (bb1
)->scope
;
621 scope s2
= RBI (bb2
)->scope
;
630 /* Find common ancestor scope. */
633 scope s1
= RBI (bb1
)->scope
;
634 scope s2
= RBI (bb2
)->scope
;
639 if (s1
->level
> s2
->level
)
641 else if (s2
->level
> s1
->level
)
659 scope s
= RBI (bb1
)->scope
;
660 ip
= RBI (bb1
)->eff_end
;
663 if (NOTE_BLOCK (s
->note_beg
))
665 ip
= emit_note_after (NOTE_INSN_BLOCK_END
, ip
);
666 NOTE_BLOCK (ip
) = NOTE_BLOCK (s
->note_end
);
670 /* Emitting note may move the end of basic block to unwanted place. */
677 scope s
= RBI (bb2
)->scope
;
681 if (NOTE_BLOCK (s
->note_beg
))
683 ip
= emit_note_before (NOTE_INSN_BLOCK_BEG
, ip
);
684 NOTE_BLOCK (ip
) = NOTE_BLOCK (s
->note_beg
);
692 /* Rebuild all the NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes based
693 on the scope forest and the newly reordered basic blocks. */
696 rebuild_scope_notes (forest
)
697 scope_forest_info
*forest
;
701 if (forest
->num_trees
== 0)
704 /* Start by opening the scopes before the first basic block. */
705 insert_inter_bb_scope_notes (NULL
, BASIC_BLOCK (0));
707 /* Then, open and close scopes as needed between blocks. */
708 for (i
= 0; i
< n_basic_blocks
- 1; i
++)
710 basic_block bb1
= BASIC_BLOCK (i
);
711 basic_block bb2
= BASIC_BLOCK (i
+ 1);
712 if (RBI (bb1
)->scope
!= RBI (bb2
)->scope
)
713 insert_inter_bb_scope_notes (bb1
, bb2
);
714 insert_intra_bb_scope_notes (bb1
);
717 /* Finally, close the scopes after the last basic block. */
718 insert_inter_bb_scope_notes (BASIC_BLOCK (n_basic_blocks
- 1), NULL
);
719 insert_intra_bb_scope_notes (BASIC_BLOCK (n_basic_blocks
- 1));
722 /* Free the storage associated with the scope tree at S. */
725 free_scope_forest_1 (s
)
730 for (p
= s
->inner
; p
; p
= next
)
733 free_scope_forest_1 (p
);
741 /* Free the storage associated with the scope forest. */
744 free_scope_forest (forest
)
745 scope_forest_info
*forest
;
748 for (i
= 0; i
< forest
->num_trees
; i
++)
749 free_scope_forest_1 (forest
->trees
[i
]);
752 /* Visualize the scope forest. */
755 dump_scope_forest (forest
)
756 scope_forest_info
*forest
;
758 if (forest
->num_trees
== 0)
759 fprintf (stderr
, "\n< Empty scope forest >\n");
763 fprintf (stderr
, "\n< Scope forest >\n");
764 for (i
= 0; i
< forest
->num_trees
; i
++)
765 dump_scope_forest_1 (forest
->trees
[i
], 0);
769 /* Recursive portion of dump_scope_forest. */
772 dump_scope_forest_1 (s
, indent
)
779 if (s
->bb_beg
!= NULL
&& s
->bb_beg
== s
->bb_end
780 && RBI (s
->bb_beg
)->scope
781 && RBI (s
->bb_beg
)->scope
->level
+ 1 == s
->level
)
783 fprintf (stderr
, "%*s", indent
, "");
784 fprintf (stderr
, "BB%d:\n", s
->bb_beg
->index
);
787 fprintf (stderr
, "%*s", indent
, "");
788 fprintf (stderr
, "{ level %d (block %p)\n", s
->level
,
789 (PTR
) NOTE_BLOCK (s
->note_beg
));
791 fprintf (stderr
, "%*s%s", indent
, "", "bbs:");
792 for (i
= 0; i
< s
->num_bbs
; i
++)
793 fprintf (stderr
, " %d", s
->bbs
[i
]->index
);
794 fprintf (stderr
, "\n");
796 for (p
= s
->inner
; p
; p
= p
->next
)
797 dump_scope_forest_1 (p
, indent
+ 2);
799 fprintf (stderr
, "%*s", indent
, "");
800 fprintf (stderr
, "}\n");
803 /* Given a reorder chain, rearrange the code to match. */
806 fixup_reorder_chain ()
808 basic_block bb
, last_bb
;
811 int old_n_basic_blocks
= n_basic_blocks
;
813 /* First do the bulk reordering -- rechain the blocks without regard to
814 the needed changes to jumps and labels. */
816 last_bb
= BASIC_BLOCK (0);
817 bb
= RBI (last_bb
)->next
;
821 rtx last_e
= RBI (last_bb
)->eff_end
;
822 rtx curr_h
= RBI (bb
)->eff_head
;
824 NEXT_INSN (last_e
) = curr_h
;
825 PREV_INSN (curr_h
) = last_e
;
832 if (index
!= n_basic_blocks
)
835 insn
= RBI (last_bb
)->eff_end
;
837 NEXT_INSN (insn
) = function_tail_eff_head
;
838 if (function_tail_eff_head
)
839 PREV_INSN (function_tail_eff_head
) = insn
;
841 while (NEXT_INSN (insn
))
842 insn
= NEXT_INSN (insn
);
843 set_last_insn (insn
);
844 #ifdef ENABLE_CHECKING
845 verify_insn_chain ();
848 /* Now add jumps and labels as needed to match the blocks new
851 for (bb
= BASIC_BLOCK (0); bb
; bb
= RBI (bb
)->next
)
853 edge e_fall
, e_taken
, e
;
857 if (bb
->succ
== NULL
)
860 /* Find the old fallthru edge, and another non-EH edge for
862 e_taken
= e_fall
= NULL
;
863 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
864 if (e
->flags
& EDGE_FALLTHRU
)
866 else if (! (e
->flags
& EDGE_EH
))
869 bb_end_insn
= bb
->end
;
870 if (GET_CODE (bb_end_insn
) == JUMP_INSN
)
872 if (any_condjump_p (bb_end_insn
))
874 /* If the old fallthru is still next, nothing to do. */
875 if (RBI (bb
)->next
== e_fall
->dest
877 && e_fall
->dest
== EXIT_BLOCK_PTR
))
880 /* There is one special case: if *neither* block is next,
881 such as happens at the very end of a function, then we'll
882 need to add a new unconditional jump. Choose the taken
883 edge based on known or assumed probability. */
884 if (RBI (bb
)->next
!= e_taken
->dest
)
886 rtx note
= find_reg_note (bb_end_insn
, REG_BR_PROB
, 0);
888 && INTVAL (XEXP (note
, 0)) < REG_BR_PROB_BASE
/ 2
889 && invert_jump (bb_end_insn
,
890 label_for_bb (e_fall
->dest
), 0))
892 e_fall
->flags
&= ~EDGE_FALLTHRU
;
893 e_taken
->flags
|= EDGE_FALLTHRU
;
894 e
= e_fall
, e_fall
= e_taken
, e_taken
= e
;
898 /* Otherwise we can try to invert the jump. This will
899 basically never fail, however, keep up the pretense. */
900 else if (invert_jump (bb_end_insn
,
901 label_for_bb (e_fall
->dest
), 0))
903 e_fall
->flags
&= ~EDGE_FALLTHRU
;
904 e_taken
->flags
|= EDGE_FALLTHRU
;
908 else if (returnjump_p (bb_end_insn
))
912 /* Otherwise we have some switch or computed jump. In the
913 99% case, there should not have been a fallthru edge. */
916 #ifdef CASE_DROPS_THROUGH
917 /* Except for VAX. Since we didn't have predication for the
918 tablejump, the fallthru block should not have moved. */
919 if (RBI (bb
)->next
== e_fall
->dest
)
921 bb_end_insn
= skip_insns_after_block (bb
);
929 /* No fallthru implies a noreturn function with EH edges, or
930 something similarly bizarre. In any case, we don't need to
935 /* If the fallthru block is still next, nothing to do. */
936 if (RBI (bb
)->next
== e_fall
->dest
)
939 /* An fallthru to exit block. */
940 if (!RBI (bb
)->next
&& e_fall
->dest
== EXIT_BLOCK_PTR
)
944 /* We got here if we need to add a new jump insn. */
946 nb
= force_nonfallthru (e_fall
);
950 alloc_aux_for_block (nb
, sizeof (struct reorder_block_def
));
951 RBI (nb
)->eff_head
= nb
->head
;
952 RBI (nb
)->eff_end
= NEXT_INSN (nb
->end
);
953 RBI (nb
)->scope
= RBI (bb
)->scope
;
954 RBI (nb
)->visited
= 1;
955 RBI (nb
)->next
= RBI (bb
)->next
;
957 /* Don't process this new block. */
962 /* Put basic_block_info in the new order. */
963 bb
= BASIC_BLOCK (0);
967 fprintf (rtl_dump_file
, "Reordered sequence:\n");
971 fprintf (rtl_dump_file
, " %i %sbb %i freq %i\n", index
,
972 bb
->index
>= old_n_basic_blocks
? "compensation " : "",
976 BASIC_BLOCK (index
) = bb
;
983 /* Perform sanity checks on the insn chain.
984 1. Check that next/prev pointers are consistent in both the forward and
986 2. Count insns in chain, going both directions, and check if equal.
987 3. Check that get_last_insn () returns the actual end of chain. */
1000 for (x
= get_insns (); x
; x
= NEXT_INSN (x
))
1002 if (PREV_INSN (x
) != prevx
)
1004 fprintf (stderr
, "Forward traversal: insn chain corrupt.\n");
1005 fprintf (stderr
, "previous insn:\n");
1007 fprintf (stderr
, "current insn:\n");
1015 if (prevx
!= get_last_insn ())
1017 fprintf (stderr
, "last_insn corrupt.\n");
1023 for (x
= get_last_insn (); x
; x
= PREV_INSN (x
))
1025 if (NEXT_INSN (x
) != nextx
)
1027 fprintf (stderr
, "Reverse traversal: insn chain corrupt.\n");
1028 fprintf (stderr
, "current insn:\n");
1030 fprintf (stderr
, "next insn:\n");
1038 if (insn_cnt1
!= insn_cnt2
)
1040 fprintf (stderr
, "insn_cnt1 (%d) not equal to insn_cnt2 (%d).\n",
1041 insn_cnt1
, insn_cnt2
);
1046 /* The block falling through to exit must be the last one in the
1047 reordered chain. Ensure that this condition is met. */
1049 fixup_fallthru_exit_predecessor ()
1052 basic_block bb
= NULL
;
1054 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
1055 if (e
->flags
& EDGE_FALLTHRU
)
1057 if (bb
&& RBI (bb
)->next
)
1059 basic_block c
= BASIC_BLOCK (0);
1060 while (RBI (c
)->next
!= bb
)
1062 RBI (c
)->next
= RBI (bb
)->next
;
1063 while (RBI (c
)->next
)
1066 RBI (bb
)->next
= NULL
;
1070 /* Main entry point to this module - initialize the datastructures for
1071 CFG layout changes. */
1074 cfg_layout_initialize ()
1076 alloc_aux_for_blocks (sizeof (struct reorder_block_def
));
1078 build_scope_forest (&forest
);
1079 remove_scope_notes ();
1081 record_effective_endpoints ();
1084 /* Finalize the changes - reorder insn list according to the sequence,
1085 enter compensation code, rebuild scope forest. */
1088 cfg_layout_finalize ()
1090 fixup_fallthru_exit_predecessor ();
1091 fixup_reorder_chain ();
1092 #ifdef ENABLE_CHECKING
1093 verify_insn_chain ();
1096 rebuild_scope_notes (&forest
);
1097 free_scope_forest (&forest
);
1100 free_aux_for_blocks ();
1102 #ifdef ENABLE_CHECKING
1103 verify_flow_info ();