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