beloopana: Remove duplicate comments.
[libfirm] / ir / ir / irssacons.c
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief   restarting SSA construction for values.
9  * @author  Michael Beck
10  */
11 #include "config.h"
12
13 #include "ircons_t.h"
14 #include "irgraph_t.h"
15 #include "irnode_t.h"
16 #include "irgwalk.h"
17
18 /** Note: start and finish must use the same kind of walker */
19 static void (*ssa_cons_walker)(ir_graph *, irg_walk_func *, irg_walk_func *, void *)
20         = irg_block_walk_graph;
21
22 /**
23  * Post-walker: prepare the graph nodes for new SSA construction cycle by
24  * allocation new arrays.
25  */
26 static void prepare_blocks(ir_node *block, void *env)
27 {
28         ir_graph *const irg   = get_Block_irg(block);
29         unsigned  const n_loc = irg->n_loc;
30         (void)env;
31         /* reset mature flag */
32         set_Block_matured(block, 0);
33         block->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), n_loc);
34         set_Block_phis(block, NULL);
35 }
36
37 void ssa_cons_start(ir_graph *irg, int n_loc)
38 {
39         add_irg_constraints(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION);
40
41         irg_set_nloc(irg, n_loc);
42
43         /*
44          * Note: we could try to reuse existing frag arrays, but it does not
45          * seems worth to do this.  First, we have to check if they really exists and
46          * then clear them.  We do not expect SSA construction is used often.
47          */
48         ssa_cons_walker(irg, NULL, prepare_blocks, NULL);
49 }
50
51 /**
52  * mature all immature Blocks.
53  */
54 static void finish_block(ir_node *block, void *env)
55 {
56         (void)env;
57
58         mature_immBlock(block);
59 }
60
61 void ssa_cons_finish(ir_graph *irg)
62 {
63         ssa_cons_walker(irg, NULL, finish_block, NULL);
64         irg_finalize_cons(irg);
65 }