2 * Flow - walk the linearized flowgraph, simplifying it as we
5 * Copyright (C) 2004 Linus Torvalds
16 #include "expression.h"
17 #include "linearize.h"
21 unsigned long bb_generation
;
24 * Dammit, if we have a phi-node followed by a conditional
25 * branch on that phi-node, we should damn well be able to
26 * do something about the source. Maybe.
28 static int rewrite_branch(struct basic_block
*bb
,
29 struct basic_block
**ptr
,
30 struct basic_block
*old
,
31 struct basic_block
*new)
33 if (*ptr
!= old
|| new == old
)
36 /* We might find new if-conversions or non-dominating CSEs */
37 repeat_phase
|= REPEAT_CSE
;
39 replace_bb_in_list(&bb
->children
, old
, new, 1);
40 remove_bb_from_list(&old
->parents
, bb
, 1);
41 add_bb(&new->parents
, bb
);
46 * Return the known truth value of a pseudo, or -1 if
49 static int pseudo_truth_value(pseudo_t pseudo
)
51 switch (pseudo
->type
) {
53 return !!pseudo
->value
;
56 struct instruction
*insn
= pseudo
->def
;
58 /* A symbol address is always considered true.. */
59 if (insn
->opcode
== OP_SYMADDR
&& insn
->target
== pseudo
)
69 * Does a basic block depend on the pseudos that "src" defines?
71 static int bb_depends_on(struct basic_block
*target
, struct basic_block
*src
)
75 FOR_EACH_PTR(src
->defines
, pseudo
) {
76 if (pseudo_in_list(target
->needs
, pseudo
))
78 } END_FOR_EACH_PTR(pseudo
);
83 * Return 1 if 'pseudo' is needed in some parent of 'bb'.
86 static int needed_phisrc(struct instruction
*phi
, struct basic_block
*curr
, unsigned long generation
)
88 pseudo_t target
= phi
->target
;
89 struct basic_block
*bb
;
91 curr
->generation
= generation
;
92 FOR_EACH_PTR(curr
->children
, bb
) {
93 if (bb
->generation
== generation
)
97 if (pseudo_in_list(bb
->defines
, target
)) {
100 if (pseudo_in_list(bb
->needs
, target
))
102 if (needed_phisrc(phi
, bb
, generation
))
105 } END_FOR_EACH_PTR(bb
);
111 * When we reach here, we have:
112 * - a basic block that ends in a conditional branch and
113 * that has no side effects apart from the pseudos it
115 * - the phi-node that the conditional branch depends on
116 * - full pseudo liveness information
118 * We need to check if any of the _sources_ of the phi-node
119 * may be constant, and not actually need this block at all.
121 static int try_to_simplify_bb(struct basic_block
*bb
, struct instruction
*first
, struct instruction
*second
)
126 FOR_EACH_PTR(first
->phi_list
, phi
) {
127 struct instruction
*def
= phi
->def
;
128 struct basic_block
*source
, *target
;
130 struct instruction
*br
;
137 if (!pseudo
|| !source
)
139 br
= last_instruction(source
->insns
);
142 if (br
->opcode
!= OP_CBR
&& br
->opcode
!= OP_BR
)
144 true = pseudo_truth_value(pseudo
);
147 target
= true ? second
->bb_true
: second
->bb_false
;
148 if (bb_depends_on(target
, bb
))
150 changed
|= rewrite_branch(source
, &br
->bb_true
, bb
, target
);
151 changed
|= rewrite_branch(source
, &br
->bb_false
, bb
, target
);
152 if (changed
&& !needed_phisrc(first
, source
, ++bb_generation
))
153 kill_use(THIS_ADDRESS(phi
));
154 } END_FOR_EACH_PTR(phi
);
158 static int bb_has_side_effects(struct basic_block
*bb
)
160 struct instruction
*insn
;
161 FOR_EACH_PTR(bb
->insns
, insn
) {
162 switch (insn
->opcode
) {
164 /* FIXME! This should take "const" etc into account */
172 /* FIXME! This should take "volatile" etc into account */
178 } END_FOR_EACH_PTR(insn
);
182 static int simplify_phi_branch(struct basic_block
*bb
, struct instruction
*br
)
184 pseudo_t cond
= br
->cond
;
185 struct instruction
*def
;
187 if (cond
->type
!= PSEUDO_REG
)
190 if (def
->bb
!= bb
|| def
->opcode
!= OP_PHI
)
192 if (bb_has_side_effects(bb
))
194 return try_to_simplify_bb(bb
, def
, br
);
197 static int simplify_branch_branch(struct basic_block
*bb
, struct instruction
*br
,
198 struct basic_block
**target_p
, int true)
200 struct basic_block
*target
= *target_p
, *final
;
201 struct instruction
*insn
;
206 insn
= last_instruction(target
->insns
);
207 if (!insn
|| insn
->opcode
!= OP_CBR
|| insn
->cond
!= br
->cond
)
210 * Ahhah! We've found a branch to a branch on the same conditional!
211 * Now we just need to see if we can rewrite the branch..
214 final
= true ? insn
->bb_true
: insn
->bb_false
;
215 if (bb_has_side_effects(target
))
216 goto try_to_rewrite_target
;
217 if (bb_depends_on(final
, target
))
218 goto try_to_rewrite_target
;
219 return rewrite_branch(bb
, target_p
, target
, final
);
221 try_to_rewrite_target
:
223 * If we're the only parent, at least we can rewrite the
224 * now-known second branch.
226 if (bb_list_size(target
->parents
) != 1)
228 insert_branch(target
, insn
, final
);
232 static int simplify_one_branch(struct basic_block
*bb
, struct instruction
*br
)
234 if (simplify_phi_branch(bb
, br
))
236 return simplify_branch_branch(bb
, br
, &br
->bb_true
, 1) |
237 simplify_branch_branch(bb
, br
, &br
->bb_false
, 0);
240 static int simplify_branch_nodes(struct entrypoint
*ep
)
243 struct basic_block
*bb
;
245 FOR_EACH_PTR(ep
->bbs
, bb
) {
246 struct instruction
*br
= last_instruction(bb
->insns
);
248 if (!br
|| br
->opcode
!= OP_CBR
)
250 changed
|= simplify_one_branch(bb
, br
);
251 } END_FOR_EACH_PTR(bb
);
256 * This is called late - when we have intra-bb liveness information..
258 int simplify_flow(struct entrypoint
*ep
)
260 return simplify_branch_nodes(ep
);
263 static inline void concat_user_list(struct pseudo_user_list
*src
, struct pseudo_user_list
**dst
)
265 concat_ptr_list((struct ptr_list
*)src
, (struct ptr_list
**)dst
);
268 void convert_instruction_target(struct instruction
*insn
, pseudo_t src
)
271 struct pseudo_user
*pu
;
273 * Go through the "insn->users" list and replace them all..
275 target
= insn
->target
;
278 FOR_EACH_PTR(target
->users
, pu
) {
279 if (*pu
->userp
!= VOID
) {
280 assert(*pu
->userp
== target
);
283 } END_FOR_EACH_PTR(pu
);
284 if (has_use_list(src
))
285 concat_user_list(target
->users
, &src
->users
);
286 target
->users
= NULL
;
289 void convert_load_instruction(struct instruction
*insn
, pseudo_t src
)
291 convert_instruction_target(insn
, src
);
292 /* Turn the load into a no-op */
293 insn
->opcode
= OP_LNOP
;
297 static int overlapping_memop(struct instruction
*a
, struct instruction
*b
)
299 unsigned int a_start
= bytes_to_bits(a
->offset
);
300 unsigned int b_start
= bytes_to_bits(b
->offset
);
301 unsigned int a_size
= a
->size
;
302 unsigned int b_size
= b
->size
;
304 if (a_size
+ a_start
<= b_start
)
306 if (b_size
+ b_start
<= a_start
)
311 static inline int same_memop(struct instruction
*a
, struct instruction
*b
)
313 return a
->offset
== b
->offset
&& a
->size
== b
->size
;
316 static inline int distinct_symbols(pseudo_t a
, pseudo_t b
)
318 if (a
->type
!= PSEUDO_SYM
)
320 if (b
->type
!= PSEUDO_SYM
)
322 return a
->sym
!= b
->sym
;
326 * Return 1 if "dom" dominates the access to "pseudo"
329 * Return 0 if it doesn't, and -1 if you don't know.
331 int dominates(pseudo_t pseudo
, struct instruction
*insn
, struct instruction
*dom
, int local
)
333 int opcode
= dom
->opcode
;
335 if (opcode
== OP_CALL
|| opcode
== OP_ENTRY
)
336 return local
? 0 : -1;
337 if (opcode
!= OP_LOAD
&& opcode
!= OP_STORE
)
339 if (dom
->src
!= pseudo
) {
342 /* We don't think two explicitly different symbols ever alias */
343 if (distinct_symbols(insn
->src
, dom
->src
))
345 /* We could try to do some alias analysis here */
348 if (!same_memop(insn
, dom
)) {
349 if (dom
->opcode
== OP_LOAD
)
351 if (!overlapping_memop(insn
, dom
))
358 static int phisrc_in_bb(struct pseudo_list
*list
, struct basic_block
*bb
)
361 FOR_EACH_PTR(list
, p
) {
362 if (p
->def
->bb
== bb
)
364 } END_FOR_EACH_PTR(p
);
369 static int find_dominating_parents(pseudo_t pseudo
, struct instruction
*insn
,
370 struct basic_block
*bb
, unsigned long generation
, struct pseudo_list
**dominators
,
373 struct basic_block
*parent
;
378 FOR_EACH_PTR(bb
->parents
, parent
) {
379 struct instruction
*one
;
380 struct instruction
*br
;
383 FOR_EACH_PTR_REVERSE(parent
->insns
, one
) {
387 dominance
= dominates(pseudo
, insn
, one
, local
);
389 if (one
->opcode
== OP_LOAD
)
395 goto found_dominator
;
396 } END_FOR_EACH_PTR_REVERSE(one
);
398 if (parent
->generation
== generation
)
400 parent
->generation
= generation
;
402 if (!find_dominating_parents(pseudo
, insn
, parent
, generation
, dominators
, local
))
407 if (dominators
&& phisrc_in_bb(*dominators
, parent
))
409 br
= delete_last_instruction(&parent
->insns
);
410 phi
= alloc_phi(parent
, one
->target
, one
->size
);
411 phi
->ident
= phi
->ident
? : pseudo
->ident
;
412 add_instruction(&parent
->insns
, br
);
413 use_pseudo(insn
, phi
, add_pseudo(dominators
, phi
));
414 } END_FOR_EACH_PTR(parent
);
419 * We should probably sort the phi list just to make it easier to compare
420 * later for equality.
422 void rewrite_load_instruction(struct instruction
*insn
, struct pseudo_list
*dominators
)
427 * Check for somewhat common case of duplicate
430 new = first_pseudo(dominators
)->def
->src1
;
431 FOR_EACH_PTR(dominators
, phi
) {
432 if (new != phi
->def
->src1
)
434 new->ident
= new->ident
? : phi
->ident
;
435 } END_FOR_EACH_PTR(phi
);
438 * All the same pseudo - mark the phi-nodes unused
439 * and convert the load into a LNOP and replace the
442 FOR_EACH_PTR(dominators
, phi
) {
443 kill_instruction(phi
->def
);
444 } END_FOR_EACH_PTR(phi
);
445 convert_load_instruction(insn
, new);
449 /* We leave symbol pseudos with a bogus usage list here */
450 if (insn
->src
->type
!= PSEUDO_SYM
)
451 kill_use(&insn
->src
);
452 insn
->opcode
= OP_PHI
;
453 insn
->phi_list
= dominators
;
456 static int find_dominating_stores(pseudo_t pseudo
, struct instruction
*insn
,
457 unsigned long generation
, int local
)
459 struct basic_block
*bb
= insn
->bb
;
460 struct instruction
*one
, *dom
= NULL
;
461 struct pseudo_list
*dominators
;
464 /* Unreachable load? Undo it */
466 insn
->opcode
= OP_LNOP
;
471 FOR_EACH_PTR(bb
->insns
, one
) {
475 dominance
= dominates(pseudo
, insn
, one
, local
);
477 /* Ignore partial load dominators */
478 if (one
->opcode
== OP_LOAD
)
488 } END_FOR_EACH_PTR(one
);
490 warning(pseudo
->sym
->pos
, "unable to find symbol read");
497 convert_load_instruction(insn
, dom
->target
);
501 /* OK, go find the parents */
502 bb
->generation
= generation
;
505 if (!find_dominating_parents(pseudo
, insn
, bb
, generation
, &dominators
, local
))
508 /* This happens with initial assignments to structures etc.. */
513 convert_load_instruction(insn
, value_pseudo(0));
518 * If we find just one dominating instruction, we
519 * can turn it into a direct thing. Otherwise we'll
520 * have to turn the load into a phi-node of the
523 rewrite_load_instruction(insn
, dominators
);
527 static void kill_store(struct instruction
*insn
)
531 insn
->opcode
= OP_SNOP
;
532 kill_use(&insn
->target
);
536 /* Kill a pseudo that is dead on exit from the bb */
537 static void kill_dead_stores(pseudo_t pseudo
, unsigned long generation
, struct basic_block
*bb
, int local
)
539 struct instruction
*insn
;
540 struct basic_block
*parent
;
542 if (bb
->generation
== generation
)
544 bb
->generation
= generation
;
545 FOR_EACH_PTR_REVERSE(bb
->insns
, insn
) {
546 int opcode
= insn
->opcode
;
548 if (opcode
!= OP_LOAD
&& opcode
!= OP_STORE
) {
551 if (opcode
== OP_CALL
)
555 if (insn
->src
== pseudo
) {
556 if (opcode
== OP_LOAD
)
563 if (insn
->src
->type
!= PSEUDO_SYM
)
565 } END_FOR_EACH_PTR_REVERSE(insn
);
567 FOR_EACH_PTR(bb
->parents
, parent
) {
568 struct basic_block
*child
;
569 FOR_EACH_PTR(parent
->children
, child
) {
570 if (child
&& child
!= bb
)
572 } END_FOR_EACH_PTR(child
);
573 kill_dead_stores(pseudo
, generation
, parent
, local
);
574 } END_FOR_EACH_PTR(parent
);
578 * This should see if the "insn" trivially dominates some previous store, and kill the
579 * store if unnecessary.
581 static void kill_dominated_stores(pseudo_t pseudo
, struct instruction
*insn
,
582 unsigned long generation
, struct basic_block
*bb
, int local
, int found
)
584 struct instruction
*one
;
585 struct basic_block
*parent
;
587 /* Unreachable store? Undo it */
592 if (bb
->generation
== generation
)
594 bb
->generation
= generation
;
595 FOR_EACH_PTR_REVERSE(bb
->insns
, one
) {
603 dominance
= dominates(pseudo
, insn
, one
, local
);
608 if (one
->opcode
== OP_LOAD
)
611 } END_FOR_EACH_PTR_REVERSE(one
);
614 warning(bb
->pos
, "Unable to find instruction");
618 FOR_EACH_PTR(bb
->parents
, parent
) {
619 struct basic_block
*child
;
620 FOR_EACH_PTR(parent
->children
, child
) {
621 if (child
&& child
!= bb
)
623 } END_FOR_EACH_PTR(child
);
624 kill_dominated_stores(pseudo
, insn
, generation
, parent
, local
, found
);
625 } END_FOR_EACH_PTR(parent
);
628 void check_access(struct instruction
*insn
)
630 pseudo_t pseudo
= insn
->src
;
632 if (insn
->bb
&& pseudo
->type
== PSEUDO_SYM
) {
633 int offset
= insn
->offset
, bit
= bytes_to_bits(offset
) + insn
->size
;
634 struct symbol
*sym
= pseudo
->sym
;
636 if (sym
->bit_size
> 0 && (offset
< 0 || bit
> sym
->bit_size
))
637 warning(insn
->pos
, "invalid access %s '%s' (%d %d)",
638 offset
< 0 ? "below" : "past the end of",
639 show_ident(sym
->ident
), offset
,
640 bits_to_bytes(sym
->bit_size
));
644 static void simplify_one_symbol(struct entrypoint
*ep
, struct symbol
*sym
)
646 pseudo_t pseudo
, src
;
647 struct pseudo_user
*pu
;
648 struct instruction
*def
;
650 int all
, stores
, complex;
652 /* Never used as a symbol? */
653 pseudo
= sym
->pseudo
;
657 /* We don't do coverage analysis of volatiles.. */
658 if (sym
->ctype
.modifiers
& MOD_VOLATILE
)
661 /* ..and symbols with external visibility need more care */
662 mod
= sym
->ctype
.modifiers
& (MOD_NONLOCAL
| MOD_STATIC
| MOD_ADDRESSABLE
);
664 goto external_visibility
;
669 FOR_EACH_PTR(pseudo
->users
, pu
) {
670 /* We know that the symbol-pseudo use is the "src" in the instruction */
671 struct instruction
*insn
= pu
->insn
;
673 switch (insn
->opcode
) {
683 mod
|= MOD_ADDRESSABLE
;
684 goto external_visibility
;
691 warning(sym
->pos
, "symbol '%s' pseudo used in unexpected way", show_ident(sym
->ident
));
693 complex |= insn
->offset
;
694 } END_FOR_EACH_PTR(pu
);
702 * Goodie, we have a single store (if even that) in the whole
703 * thing. Replace all loads with moves from the pseudo,
704 * replace the store with a def.
710 FOR_EACH_PTR(pseudo
->users
, pu
) {
711 struct instruction
*insn
= pu
->insn
;
712 if (insn
->opcode
== OP_LOAD
) {
714 convert_load_instruction(insn
, src
);
716 } END_FOR_EACH_PTR(pu
);
718 /* Turn the store into a no-op */
726 FOR_EACH_PTR_REVERSE(pseudo
->users
, pu
) {
727 struct instruction
*insn
= pu
->insn
;
728 if (insn
->opcode
== OP_LOAD
)
729 all
&= find_dominating_stores(pseudo
, insn
, ++bb_generation
, !mod
);
730 } END_FOR_EACH_PTR_REVERSE(pu
);
732 /* If we converted all the loads, remove the stores. They are dead */
734 FOR_EACH_PTR(pseudo
->users
, pu
) {
735 struct instruction
*insn
= pu
->insn
;
736 if (insn
->opcode
== OP_STORE
)
738 } END_FOR_EACH_PTR(pu
);
741 * If we couldn't take the shortcut, see if we can at least kill some
744 FOR_EACH_PTR(pseudo
->users
, pu
) {
745 struct instruction
*insn
= pu
->insn
;
746 if (insn
->opcode
== OP_STORE
)
747 kill_dominated_stores(pseudo
, insn
, ++bb_generation
, insn
->bb
, !mod
, 0);
748 } END_FOR_EACH_PTR(pu
);
750 if (!(mod
& (MOD_NONLOCAL
| MOD_STATIC
))) {
751 struct basic_block
*bb
;
752 FOR_EACH_PTR(ep
->bbs
, bb
) {
754 kill_dead_stores(pseudo
, ++bb_generation
, bb
, !mod
);
755 } END_FOR_EACH_PTR(bb
);
762 void simplify_symbol_usage(struct entrypoint
*ep
)
766 FOR_EACH_PTR(ep
->accesses
, pseudo
) {
767 simplify_one_symbol(ep
, pseudo
->sym
);
768 } END_FOR_EACH_PTR(pseudo
);
771 static void mark_bb_reachable(struct basic_block
*bb
, unsigned long generation
)
773 struct basic_block
*child
;
775 if (bb
->generation
== generation
)
777 bb
->generation
= generation
;
778 FOR_EACH_PTR(bb
->children
, child
) {
779 mark_bb_reachable(child
, generation
);
780 } END_FOR_EACH_PTR(child
);
783 static void kill_defs(struct instruction
*insn
)
785 pseudo_t target
= insn
->target
;
787 if (!has_use_list(target
))
789 if (target
->def
!= insn
)
792 convert_instruction_target(insn
, VOID
);
795 void kill_bb(struct basic_block
*bb
)
797 struct instruction
*insn
;
798 struct basic_block
*child
, *parent
;
800 FOR_EACH_PTR(bb
->insns
, insn
) {
801 kill_instruction_force(insn
);
804 * We kill unreachable instructions even if they
805 * otherwise aren't "killable" (e.g. volatile loads)
807 } END_FOR_EACH_PTR(insn
);
810 FOR_EACH_PTR(bb
->children
, child
) {
811 remove_bb_from_list(&child
->parents
, bb
, 0);
812 } END_FOR_EACH_PTR(child
);
815 FOR_EACH_PTR(bb
->parents
, parent
) {
816 remove_bb_from_list(&parent
->children
, bb
, 0);
817 } END_FOR_EACH_PTR(parent
);
821 void kill_unreachable_bbs(struct entrypoint
*ep
)
823 struct basic_block
*bb
;
824 unsigned long generation
= ++bb_generation
;
826 mark_bb_reachable(ep
->entry
->bb
, generation
);
827 FOR_EACH_PTR(ep
->bbs
, bb
) {
828 if (bb
->generation
== generation
)
830 /* Mark it as being dead */
833 DELETE_CURRENT_PTR(bb
);
834 } END_FOR_EACH_PTR(bb
);
835 PACK_PTR_LIST(&ep
->bbs
);
837 repeat_phase
&= ~REPEAT_CFG_CLEANUP
;
840 static int rewrite_parent_branch(struct basic_block
*bb
, struct basic_block
*old
, struct basic_block
*new)
843 struct instruction
*insn
= last_instruction(bb
->insns
);
848 /* Infinite loops: let's not "optimize" them.. */
852 switch (insn
->opcode
) {
854 changed
|= rewrite_branch(bb
, &insn
->bb_false
, old
, new);
857 changed
|= rewrite_branch(bb
, &insn
->bb_true
, old
, new);
861 struct multijmp
*jmp
;
862 FOR_EACH_PTR(insn
->multijmp_list
, jmp
) {
863 changed
|= rewrite_branch(bb
, &jmp
->target
, old
, new);
864 } END_FOR_EACH_PTR(jmp
);
873 static struct basic_block
* rewrite_branch_bb(struct basic_block
*bb
, struct instruction
*br
)
875 struct basic_block
*parent
;
876 struct basic_block
*target
= br
->bb_true
;
877 struct basic_block
*false = br
->bb_false
;
879 if (br
->opcode
== OP_CBR
) {
880 pseudo_t cond
= br
->cond
;
881 if (cond
->type
!= PSEUDO_VAL
)
883 target
= cond
->value
? target
: false;
887 * We can't do FOR_EACH_PTR() here, because the parent list
888 * may change when we rewrite the parent.
890 while ((parent
= first_basic_block(bb
->parents
)) != NULL
) {
891 if (!rewrite_parent_branch(parent
, bb
, target
))
897 static void vrfy_bb_in_list(struct basic_block
*bb
, struct basic_block_list
*list
)
900 struct basic_block
*tmp
;
901 int no_bb_in_list
= 0;
903 FOR_EACH_PTR(list
, tmp
) {
906 } END_FOR_EACH_PTR(tmp
);
907 assert(no_bb_in_list
);
911 static void vrfy_parents(struct basic_block
*bb
)
913 struct basic_block
*tmp
;
914 FOR_EACH_PTR(bb
->parents
, tmp
) {
915 vrfy_bb_in_list(bb
, tmp
->children
);
916 } END_FOR_EACH_PTR(tmp
);
919 static void vrfy_children(struct basic_block
*bb
)
921 struct basic_block
*tmp
;
922 struct instruction
*br
= last_instruction(bb
->insns
);
925 assert(!bb
->children
);
928 switch (br
->opcode
) {
929 struct multijmp
*jmp
;
931 vrfy_bb_in_list(br
->bb_false
, bb
->children
);
934 vrfy_bb_in_list(br
->bb_true
, bb
->children
);
937 case OP_COMPUTEDGOTO
:
938 FOR_EACH_PTR(br
->multijmp_list
, jmp
) {
939 vrfy_bb_in_list(jmp
->target
, bb
->children
);
940 } END_FOR_EACH_PTR(jmp
);
946 FOR_EACH_PTR(bb
->children
, tmp
) {
947 vrfy_bb_in_list(bb
, tmp
->parents
);
948 } END_FOR_EACH_PTR(tmp
);
951 static void vrfy_bb_flow(struct basic_block
*bb
)
957 void vrfy_flow(struct entrypoint
*ep
)
959 struct basic_block
*bb
;
960 struct basic_block
*entry
= ep
->entry
->bb
;
962 FOR_EACH_PTR(ep
->bbs
, bb
) {
966 } END_FOR_EACH_PTR(bb
);
970 void pack_basic_blocks(struct entrypoint
*ep
)
972 struct basic_block
*bb
;
974 /* See if we can merge a bb into another one.. */
975 FOR_EACH_PTR(ep
->bbs
, bb
) {
976 struct instruction
*first
, *insn
;
977 struct basic_block
*parent
, *child
, *last
;
979 if (!bb_reachable(bb
))
985 FOR_EACH_PTR(bb
->insns
, first
) {
988 switch (first
->opcode
) {
989 case OP_NOP
: case OP_LNOP
: case OP_SNOP
:
993 struct basic_block
*replace
;
994 replace
= rewrite_branch_bb(bb
, first
);
1004 } END_FOR_EACH_PTR(first
);
1008 * See if we only have one parent..
1011 FOR_EACH_PTR(bb
->parents
, parent
) {
1018 } END_FOR_EACH_PTR(parent
);
1021 if (!parent
|| parent
== bb
)
1025 * Goodie. See if the parent can merge..
1027 FOR_EACH_PTR(parent
->children
, child
) {
1030 } END_FOR_EACH_PTR(child
);
1035 repeat_phase
|= REPEAT_CSE
;
1037 parent
->children
= bb
->children
;
1038 bb
->children
= NULL
;
1041 FOR_EACH_PTR(parent
->children
, child
) {
1042 replace_bb_in_list(&child
->parents
, bb
, parent
, 0);
1043 } END_FOR_EACH_PTR(child
);
1045 kill_instruction(delete_last_instruction(&parent
->insns
));
1046 FOR_EACH_PTR(bb
->insns
, insn
) {
1048 assert(insn
->bb
== bb
);
1051 add_instruction(&parent
->insns
, insn
);
1052 } END_FOR_EACH_PTR(insn
);
1056 /* nothing to do */;
1057 } END_FOR_EACH_PTR(bb
);