Fix typo.
[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 /** Note: start and finish must use the same kind of walker */
34 static void (*ssa_cons_walker)(ir_graph *, irg_walk_func *, irg_walk_func *, void *)
35         = irg_block_walk_graph;
36
37 /**
38  * Post-walker: prepare the graph nodes for new SSA construction cycle by
39  * allocation new arrays.
40  */
41 static void prepare_blocks(ir_node *block, void *env)
42 {
43         unsigned        n_loc = current_ir_graph->n_loc;
44         struct obstack *obst  = current_ir_graph->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 /*
54  * Restarts SSA construction on the given graph with n_loc
55  * new values.
56  *
57  * @param irg    the graph on which the SSA construction is restarted
58  * @param n_loc  number of new variables
59  *
60  * After this function is complete, the graph is in phase_building
61  * again and set_value()/get_value() and mature_block() can be used
62  * to construct new values.
63  */
64 void ssa_cons_start(ir_graph *irg, int n_loc)
65 {
66         /* for now we support only phase_high graphs */
67         assert(irg->phase_state == phase_high);
68
69         /* reset the phase to phase building: some optimization might depend on it */
70         set_irg_phase_state(irg, phase_building);
71
72         irg_set_nloc(irg, n_loc);
73
74         /*
75          * Note: we could try to reuse existing frag arrays, but it does not
76          * seems worth to do this.  First, we have to check if they really exists and
77          * then clear them.  We do not expect SSA construction is used often.
78          */
79         ssa_cons_walker(irg, NULL, prepare_blocks, NULL);
80 }
81
82 /**
83  * mature all immature Blocks.
84  */
85 static void finish_block(ir_node *block, void *env)
86 {
87         (void)env;
88
89         if (!get_Block_matured(block))
90                 mature_immBlock(block);
91 }
92
93 /*
94  * Finalize the (restarted) SSA construction. Matures all blocks that are
95  * not matured yet and reset the graph state to phase_high.
96  */
97 void ssa_cons_finish(ir_graph *irg)
98 {
99         ssa_cons_walker(irg, NULL, finish_block, NULL);
100         irg_finalize_cons(irg);
101 }