Fixed warnings introduced in 97080a1af7b7e8a4969d2fba25e065df417ff074.
[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  */
25 #include "config.h"
26
27 #include "ircons_t.h"
28 #include "irgraph_t.h"
29 #include "irnode_t.h"
30 #include "irgwalk.h"
31
32 /** Note: start and finish must use the same kind of walker */
33 static void (*ssa_cons_walker)(ir_graph *, irg_walk_func *, irg_walk_func *, void *)
34         = irg_block_walk_graph;
35
36 /**
37  * Post-walker: prepare the graph nodes for new SSA construction cycle by
38  * allocation new arrays.
39  */
40 static void prepare_blocks(ir_node *block, void *env)
41 {
42         ir_graph       *const irg   = get_Block_irg(block);
43         unsigned        const n_loc = irg->n_loc;
44         struct obstack *const obst  = irg->obst;
45         (void)env;
46         /* reset mature flag */
47         set_Block_matured(block, 0);
48         block->attr.block.graph_arr = NEW_ARR_D(ir_node *, obst, n_loc);
49         memset(block->attr.block.graph_arr, 0, sizeof(ir_node*) * n_loc);
50         set_Block_phis(block, NULL);
51 }
52
53 void ssa_cons_start(ir_graph *irg, int n_loc)
54 {
55         add_irg_constraints(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION);
56
57         irg_set_nloc(irg, n_loc);
58
59         /*
60          * Note: we could try to reuse existing frag arrays, but it does not
61          * seems worth to do this.  First, we have to check if they really exists and
62          * then clear them.  We do not expect SSA construction is used often.
63          */
64         ssa_cons_walker(irg, NULL, prepare_blocks, NULL);
65 }
66
67 /**
68  * mature all immature Blocks.
69  */
70 static void finish_block(ir_node *block, void *env)
71 {
72         (void)env;
73
74         mature_immBlock(block);
75 }
76
77 void ssa_cons_finish(ir_graph *irg)
78 {
79         ssa_cons_walker(irg, NULL, finish_block, NULL);
80         irg_finalize_cons(irg);
81 }