2 * Copyright (C) 2011 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 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * @brief Convert all unreachable blocks into Bad nodes
18 * @author Andreas Zwinkau
34 static void unreachable_to_bad(ir_node *node, void *env)
36 bool *changed = (bool *)env;
37 ir_graph *irg = get_irn_irg(node);
40 if (get_Block_dom_depth(node) < 0) {
41 exchange(node, new_r_Bad(irg, mode_BB));
44 } else if (is_Bad(node)) {
47 ir_node *block = get_nodes_block(node);
48 if (is_Bad(block) || get_Block_dom_depth(block) < 0) {
49 exchange(node, new_r_Bad(irg, get_irn_mode(node)));
56 * Transforms unreachable blocks and the nodes within into Bad nodes
58 void remove_unreachable_blocks(ir_graph *irg)
64 irg_walk_graph(irg, unreachable_to_bad, NULL, &changed);
67 edges_deactivate(irg);
68 clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_OUTS);
69 clear_irg_state(irg, IR_GRAPH_STATE_NO_BADS);
71 set_irg_state(irg, IR_GRAPH_STATE_NO_UNREACHABLE_CODE);