2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Remove critical edges.
23 * @author Christian Schaefer, Goetz Lindenmaier, Sebastian Felis,
35 typedef struct cf_env {
36 char ignore_exc_edges; /**< set if exception edges should be ignored. */
37 char changed; /**< flag indicates that the cf graphs has changed. */
41 * Called by walker of remove_critical_cf_edges().
43 * Place an empty block to an edge between a blocks of multiple
44 * predecessors and a block of multiple successors.
47 * @param env Environment of walker.
49 static void walk_critical_cf_edges(ir_node *n, void *env) {
51 ir_node *pre, *block, *jmp;
53 ir_graph *irg = get_irn_irg(n);
55 /* Block has multiple predecessors */
56 arity = get_irn_arity(n);
58 if (n == get_irg_end_block(irg))
59 return; /* No use to add a block here. */
61 for (i = 0; i < arity; ++i) {
64 pre = get_irn_n(n, i);
65 /* don't count Bad's */
69 cfop = get_irn_op(skip_Proj(pre));
70 if (is_op_fragile(cfop)) {
71 if (cenv->ignore_exc_edges && get_Proj_proj(pre) == pn_Generic_X_except)
75 /* we don't want place nodes in the start block, so handle it like forking */
76 if (is_op_forking(cfop) || cfop == op_Start) {
77 /* Predecessor has multiple successors. Insert new control flow edge edges. */
79 /* set predecessor of new block */
80 block = new_r_Block(irg, 1, &pre);
81 /* insert new jmp node to new block */
82 jmp = new_r_Jmp(irg, block);
83 /* set successor of new block */
86 } /* predecessor has multiple successors */
87 } /* for all predecessors */
88 } /* n is a multi-entry block */
91 void remove_critical_cf_edges_ex(ir_graph *irg, int ignore_exception_edges) {
94 env.ignore_exc_edges = (char)ignore_exception_edges;
97 irg_block_walk_graph(irg, NULL, walk_critical_cf_edges, &env);
99 /* control flow changed */
100 set_irg_outs_inconsistent(irg);
101 set_irg_extblk_inconsistent(irg);
102 set_irg_doms_inconsistent(irg);
103 set_irg_loopinfo_inconsistent(irg);
107 void remove_critical_cf_edges(ir_graph *irg) {
108 remove_critical_cf_edges_ex(irg, 1);