- C99 features removed
[libfirm] / ir / be / beinfo.c
1 /*
2  * Copyright (C) 1995-2008 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  * @author      Matthias Braun
23  * @version     $Id$
24  */
25 #include "config.h"
26
27 #include "beinfo.h"
28 #include "bearch_t.h"
29 #include "irgwalk.h"
30 #include "irnode_t.h"
31 #include "error.h"
32
33 static copy_attr_func  old_phi_copy_attr;
34
35 void be_info_new_node(ir_node *node)
36 {
37         struct obstack *obst;
38         backend_info_t *info;
39         sched_info_t   *sinfo;
40
41         if (is_Anchor(node))
42                 return;
43
44         obst  = get_irg_obstack(current_ir_graph);
45         info  = obstack_alloc(obst, sizeof(*info));
46         sinfo = &info->sched_info;
47
48         memset(info, 0, sizeof(*info));
49
50         sinfo->idx = get_irn_idx(node);
51         INIT_LIST_HEAD(&sinfo->list);
52
53         if (is_Phi(node)) {
54                 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
55                 memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
56         }
57         assert(node->backend_info == NULL);
58         node->backend_info = info;
59 }
60
61 static void new_Phi_copy_attr(const ir_node *old_node, ir_node *new_node)
62 {
63         struct obstack *obst  = get_irg_obstack(get_irn_irg(new_node));
64         backend_info_t *old_info = be_get_info(old_node);
65         backend_info_t *new_info = be_get_info(new_node);
66
67         old_phi_copy_attr(old_node, new_node);
68         new_info->out_infos = DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
69 }
70
71 int be_info_equal(const ir_node *node1, const ir_node *node2)
72 {
73         backend_info_t *info1 = be_get_info(node1);
74         backend_info_t *info2 = be_get_info(node2);
75         int             len   = ARR_LEN(info1->out_infos);
76         int             i;
77
78         if (ARR_LEN(info2->out_infos) != len)
79                 return 0;
80
81         for (i = 0; i < len; ++i) {
82                 const reg_out_info_t *out1 = &info1->out_infos[i];
83                 const reg_out_info_t *out2 = &info2->out_infos[i];
84                 if (out1->reg != out2->reg)
85                         return 0;
86                 if (!reg_reqs_equal(out1->req, out2->req))
87                         return 0;
88         }
89
90         /* TODO: in reqs */
91
92         return 1;
93 }
94
95 static void init_walker(ir_node *node, void *data)
96 {
97         (void) data;
98         be_info_new_node(node);
99 }
100
101 static int initialized = 0;
102
103 void be_info_init(void)
104 {
105         if (initialized == 1)
106                 panic("double initialization of be_info");
107
108         old_phi_copy_attr = op_Phi->ops.copy_attr;
109         op_Phi->ops.copy_attr = new_Phi_copy_attr;
110         initialized = 1;
111 }
112
113 void be_info_init_irg(ir_graph *irg)
114 {
115         irg_walk_anchors(irg, init_walker, NULL, NULL);
116 }
117
118 void be_info_free(void)
119 {
120         if (!initialized)
121                 panic("be_info_free called without prior init");
122
123         assert(op_Phi->ops.copy_attr == new_Phi_copy_attr);
124         op_Phi->ops.copy_attr = old_phi_copy_attr;
125         initialized = 0;
126 }
127
128 int be_info_initialized(const ir_graph *irg)
129 {
130         (void) irg;
131         return initialized;
132 }