rename NO_BAD_BLOCKS to NO_BADS, remove unnecessary implication from opt_manage
[libfirm] / ir / ir / unreachable.c
1 /*
2  * Copyright (C) 2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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
13  * PURPOSE.
14  */
15
16 /**
17  * @brief    Convert all unreachable blocks into Bad nodes
18  * @author   Andreas Zwinkau
19  */
20 #include "config.h"
21
22 #include <assert.h>
23 #include <stdbool.h>
24
25 #include "irnode_t.h"
26 #include "irgopt.h"
27 #include "irgmod.h"
28 #include "irgwalk.h"
29 #include "irtools.h"
30
31 /**
32  * Block-walker
33  */
34 static void unreachable_to_bad(ir_node *node, void *env)
35 {
36         bool *changed = (bool *)env;
37         ir_graph *irg = get_irn_irg(node);
38
39         if (is_Block(node)) {
40                 if (get_Block_dom_depth(node) < 0) {
41                         exchange(node, new_r_Bad(irg, mode_BB));
42                         *changed = true;
43                 }
44         } else if (is_Bad(node)) {
45                 /* nothing to do */
46         } else {
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)));
50                         *changed = true;
51                 }
52         }
53 }
54
55 /*
56  * Transforms unreachable blocks and the nodes within into Bad nodes
57  */
58 void remove_unreachable_blocks(ir_graph *irg)
59 {
60         bool changed = false;
61
62         assure_doms(irg);
63
64         irg_walk_graph(irg, unreachable_to_bad, NULL, &changed);
65
66         if (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);
70         }
71         set_irg_state(irg, IR_GRAPH_STATE_NO_UNREACHABLE_CODE);
72 }