Cleanup: remove firm_common_t.h (and the PRECISE_EXC_CONTEXT define)
[libfirm] / ir / ir / irssacons.c
1 /*
2  * Copyright (C) 1995-2008 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  * 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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   restarting SSA construction for values.
23  * @author  Michael Beck
24  * @version $Id$
25  */
26 #include "config.h"
27
28 #include "ircons_t.h"
29 #include "irgraph_t.h"
30 #include "irnode_t.h"
31 #include "irgwalk.h"
32
33 /**
34  * Post-walker: prepare the graph nodes for new SSA construction cycle by allocation
35  * new arrays.
36  */
37 static void prepare_nodes(ir_node *irn, void *env) {
38         (void)env;
39
40         switch (get_irn_opcode(irn)) {
41         case iro_Block:
42                 /* reset mature flag */
43                 irn->attr.block.is_matured = 0;
44                 irn->attr.block.graph_arr  = NEW_ARR_D(ir_node *, current_ir_graph->obst,
45                                                        current_ir_graph->n_loc);
46                 memset(irn->attr.block.graph_arr, 0, sizeof(ir_node *) * current_ir_graph->n_loc);
47                 irn->attr.block.phis       = NULL;
48                 break;
49         /* note that the frag array must be cleared first, else firm_alloc_frag_arr()
50            will not allocate new memory. */
51         case iro_Quot:
52                 irn->attr.except.frag_arr = NULL;
53                 firm_alloc_frag_arr(irn, op_Quot, &irn->attr.except.frag_arr);
54                 break;
55         case iro_DivMod:
56                 irn->attr.except.frag_arr = NULL;
57                 firm_alloc_frag_arr(irn, op_DivMod, &irn->attr.except.frag_arr);
58                 break;
59         case iro_Div:
60                 irn->attr.except.frag_arr = NULL;
61                 firm_alloc_frag_arr(irn, op_Div, &irn->attr.except.frag_arr);
62                 break;
63         case iro_Mod:
64                 irn->attr.except.frag_arr = NULL;
65                 firm_alloc_frag_arr(irn, op_Mod, &irn->attr.except.frag_arr);
66                 break;
67         case iro_Call:
68                 irn->attr.call.exc.frag_arr = NULL;
69                 firm_alloc_frag_arr(irn, op_Call, &irn->attr.call.exc.frag_arr);
70                 break;
71         case iro_Load:
72                 irn->attr.load.exc.frag_arr = NULL;
73                 firm_alloc_frag_arr(irn, op_Load, &irn->attr.load.exc.frag_arr);
74                 break;
75         case iro_Store:
76                 irn->attr.store.exc.frag_arr = NULL;
77                 firm_alloc_frag_arr(irn, op_Store, &irn->attr.store.exc.frag_arr);
78                 break;
79         case iro_Alloc:
80                 irn->attr.alloc.exc.frag_arr = NULL;
81                 firm_alloc_frag_arr(irn, op_Alloc, &irn->attr.alloc.exc.frag_arr);
82                 break;
83         case iro_CopyB:
84                 irn->attr.copyb.exc.frag_arr = NULL;
85                 firm_alloc_frag_arr(irn, op_CopyB, &irn->attr.copyb.exc.frag_arr);
86                 break;
87         case iro_Raise:
88                 irn->attr.bound.exc.frag_arr = NULL;
89                 firm_alloc_frag_arr(irn, op_Bound, &irn->attr.bound.exc.frag_arr);
90                 break;
91         default:
92                 ;
93         }
94 }
95
96 /*
97  * Restarts SSA construction on the given graph with n_loc
98  * new values.
99  *
100  * @param irg    the graph on which the SSA construction is restarted
101  * @param n_loc  number of new variables
102  *
103  * After this function is complete, the graph is in phase_building
104  * again and set_value()/get_value() and mature_block() can be used
105  * to construct new values.
106  */
107 void ssa_cons_start(ir_graph *irg, int n_loc) {
108         /* for now we support only phase_high graphs */
109         assert(irg->phase_state == phase_high);
110
111         /* reset the phase to phase building: some optimization might depend on it */
112         set_irg_phase_state(irg, phase_building);
113
114         irg_set_nloc(irg, n_loc);
115
116         /*
117          * Note: we could try to reuse existing frag arrays, but it does not
118          * seems worth to do this.  First, we have to check if they really exists and
119          * then clear them.  We do not expect SSA construction is used often.
120          */
121         irg_walk_graph(irg, NULL, prepare_nodes, NULL);
122 }
123
124 /**
125  * mature all immature Blocks.
126  */
127 static void finish_block(ir_node *block, void *env) {
128         (void)env;
129
130         if (!get_Block_matured(block))
131                 mature_immBlock(block);
132 }
133
134 /*
135  * Finalize the (restarted) SSA construction. Matures all blocks that are
136  * not matured yet and reset the graph state to phase_high.
137  */
138 void ssa_cons_finish(ir_graph *irg) {
139         irg_block_walk_graph(irg, NULL, finish_block, NULL);
140         irg_finalize_cons(irg);
141 }