ac6f0f509307211f5ca5c9eb21225e79b556d890
[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, phase_irn_data_init_t *data_init)
22 {
23         phase_t *ph;
24
25         assert(growth_factor >= 1.0 && "growth factor must greater or equal to 1.0");
26
27         ph = xmalloc(sizeof(ph[0]));
28
29         obstack_init(&ph->obst);
30
31         ph->name          = name;
32         ph->growth_factor = growth_factor;
33         ph->data_init     = data_init;
34         ph->data_size     = data_size;
35         ph->irg           = irg;
36         ph->n_data_ptr    = 0;
37         ph->data_ptr      = NULL;
38
39         return ph;
40 }
41
42 void phase_free(phase_t *phase)
43 {
44         obstack_free(&phase->obst, NULL);
45         xfree(phase->data_ptr);
46 }
47
48 phase_stat_t *phase_stat(const phase_t *phase, phase_stat_t *stat)
49 {
50         int i, n;
51         memset(stat, 0, sizeof(stat[0]));
52
53         stat->node_map_bytes = phase->n_data_ptr * sizeof(phase->data_ptr[0]);
54         stat->node_slots     = phase->n_data_ptr;
55         for(i = 0, n = phase->n_data_ptr; i < n; ++i) {
56                 if(phase->data_ptr[i] != NULL) {
57                         stat->node_slots_used++;
58                         stat->node_data_bytes += phase->data_size;
59                 }
60         }
61         stat->overall_bytes = stat->node_map_bytes + obstack_memory_used(&phase->obst);
62         return stat;
63 }