2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Phase information handling using node indexes.
23 * @author Sebastian Hack
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.
34 #include "irgraph_t.h"
35 #include "irphase_t.h"
37 void *phase_irn_init_default(ir_phase *ph, const ir_node *irn)
44 void phase_init(ir_phase *phase, ir_graph *irg, phase_irn_init *data_init)
46 memset(phase, 0, sizeof(*phase));
48 obstack_init(&phase->obst);
49 phase->data_init = data_init;
51 phase->n_data_ptr = 0;
52 phase->data_ptr = NULL;
55 ir_phase *new_phase(ir_graph *irg, phase_irn_init *data_init)
57 ir_phase *phase = xmalloc(sizeof(*phase));
58 phase_init(phase, irg, data_init);
62 void phase_deinit(ir_phase *phase)
64 obstack_free(&phase->obst, NULL);
66 xfree(phase->data_ptr);
69 void phase_free(ir_phase *phase)
75 phase_stat_t *phase_stat(const ir_phase *phase, phase_stat_t *stat)
78 memset(stat, 0, sizeof(stat[0]));
80 stat->node_map_bytes = phase->n_data_ptr * sizeof(phase->data_ptr[0]);
81 stat->node_slots = phase->n_data_ptr;
82 for (i = 0, n = phase->n_data_ptr; i < n; ++i) {
83 if (phase->data_ptr[i] != NULL) {
84 stat->node_slots_used++;
87 stat->overall_bytes = stat->node_map_bytes + obstack_memory_used(&((ir_phase *)phase)->obst);
91 void phase_reinit_irn_data(ir_phase *phase, phase_irn_reinit *data_reinit)
96 if (! phase->data_init)
100 for (i = 0, n = phase->n_data_ptr; i < n; ++i) {
101 if (phase->data_ptr[i]) {
102 ir_node *node = get_idx_irn(irg, i);
103 phase->data_ptr[i] = data_reinit(phase, node, phase->data_ptr[i]);
108 ir_node *phase_get_first_node(const ir_phase *phase)
112 for (i = 0; i < phase->n_data_ptr; ++i)
113 if (phase->data_ptr[i])
114 return get_idx_irn(phase->irg, i);
119 ir_node *phase_get_next_node(const ir_phase *phase, ir_node *start)
123 for (i = get_irn_idx(start) + 1; i < phase->n_data_ptr; ++i)
124 if (phase->data_ptr[i])
125 return get_idx_irn(phase->irg, i);