added conv to keep gcc happy
[libfirm] / ir / ir / irphase.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irphase.c
4  * Purpose:     Phase information handling using node indexes.
5  * Author:      Sebastian Hack
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2006 Universitaet Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifdef _HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16
17 #include "array.h"
18 #include "irnode_t.h"
19 #include "irphase_t.h"
20
21 phase_t *phase_new(const char *name, ir_graph *irg, size_t data_size, unsigned growth_factor,
22                    phase_irn_data_init_t *data_init, void *priv)
23 {
24         phase_t *ph;
25
26         assert(growth_factor >= 1.0 && "growth factor must greater or equal to 1.0");
27
28         ph = xmalloc(sizeof(ph[0]));
29
30         obstack_init(&ph->obst);
31
32         ph->name          = name;
33         ph->growth_factor = growth_factor;
34         ph->data_init     = data_init;
35         ph->data_size     = data_size;
36         ph->irg           = irg;
37         ph->n_data_ptr    = 0;
38         ph->data_ptr      = NULL;
39         ph->priv          = priv;
40
41         return ph;
42 }
43
44 void phase_free(phase_t *phase)
45 {
46         obstack_free(&phase->obst, NULL);
47         xfree(phase->data_ptr);
48 }
49
50 phase_stat_t *phase_stat(const phase_t *phase, phase_stat_t *stat)
51 {
52         int i, n;
53         memset(stat, 0, sizeof(stat[0]));
54
55         stat->node_map_bytes = phase->n_data_ptr * sizeof(phase->data_ptr[0]);
56         stat->node_slots     = phase->n_data_ptr;
57         for(i = 0, n = phase->n_data_ptr; i < n; ++i) {
58                 if(phase->data_ptr[i] != NULL) {
59                         stat->node_slots_used++;
60                         stat->node_data_bytes += phase->data_size;
61                 }
62         }
63         stat->overall_bytes = stat->node_map_bytes + obstack_memory_used(&((phase_t *)phase)->obst);
64         return stat;
65 }