cleaned up doxygen comments
[libfirm] / ir / ir / irphase.c
1 /*
2  * Copyright (C) 1995-2007 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    Phase information handling using node indexes.
23  * @author   Sebastian Hack
24  * @version  $Id$
25  * @summary
26  *  A phase contains a link to private data for each node in an ir graph.
27  *  A phase is independent from the globally visible link field of ir nodes.
28  */
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "array.h"
34 #include "irnode_t.h"
35 #include "irphase_t.h"
36
37 ir_phase *phase_init(ir_phase *ph, const char *name, ir_graph *irg, unsigned growth_factor, phase_irn_data_init_t *data_init, void *priv)
38 {
39         assert(growth_factor >= 256 && "growth factor must greater or equal to 256/256");
40         assert(data_init && "You must provide a data constructor");
41
42         obstack_init(&ph->obst);
43
44         ph->name          = name;
45         ph->growth_factor = growth_factor;
46         ph->data_init     = data_init;
47         ph->irg           = irg;
48         ph->n_data_ptr    = 0;
49         ph->data_ptr      = NULL;
50         ph->priv          = priv;
51
52         return ph;
53 }
54
55 void phase_free(ir_phase *phase)
56 {
57         obstack_free(&phase->obst, NULL);
58         if(phase->data_ptr)
59                 xfree(phase->data_ptr);
60 }
61
62 phase_stat_t *phase_stat(const ir_phase *phase, phase_stat_t *stat)
63 {
64         int i, n;
65         memset(stat, 0, sizeof(stat[0]));
66
67         stat->node_map_bytes = phase->n_data_ptr * sizeof(phase->data_ptr[0]);
68         stat->node_slots     = phase->n_data_ptr;
69         for(i = 0, n = phase->n_data_ptr; i < n; ++i) {
70                 if(phase->data_ptr[i] != NULL) {
71                         stat->node_slots_used++;
72                 }
73         }
74         stat->overall_bytes = stat->node_map_bytes + obstack_memory_used(&((ir_phase *)phase)->obst);
75         return stat;
76 }
77
78 void phase_reinit_irn_data(ir_phase *phase)
79 {
80         int i, n;
81
82         if (! phase->data_init)
83                 return;
84
85         for (i = 0, n = phase->n_data_ptr; i < n; ++i) {
86                 if (phase->data_ptr[i])
87                         phase->data_init(phase, get_idx_irn(phase->irg, i), phase->data_ptr[i]);
88         }
89 }
90
91 void phase_reinit_block_irn_data(ir_phase *phase, ir_node *block)
92 {
93         int i, n;
94
95         if (! phase->data_init)
96                 return;
97
98         for (i = 0, n = phase->n_data_ptr; i < n; ++i) {
99                 if (phase->data_ptr[i]) {
100                         ir_node *irn = get_idx_irn(phase->irg, i);
101                         if (! is_Block(irn) && get_nodes_block(irn) == block)
102                                 phase->data_init(phase, irn, phase->data_ptr[i]);
103                 }
104         }
105 }
106
107 ir_node *phase_get_first_node(ir_phase *phase) {
108         unsigned i;
109
110         for (i = 0; i < phase->n_data_ptr;  ++i)
111                 if (phase->data_ptr[i])
112                         return get_idx_irn(phase->irg, i);
113
114         return NULL;
115 }
116
117 ir_node *phase_get_next_node(ir_phase *phase, ir_node *start) {
118         unsigned i;
119
120         for (i = get_irn_idx(start) + 1; i < phase->n_data_ptr; ++i)
121                 if (phase->data_ptr[i])
122                         return get_idx_irn(phase->irg, i);
123
124         return NULL;
125 }