Remove address name SymConsts.
[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 <stdbool.h>
28
29 #include "beinfo.h"
30 #include "bearch.h"
31 #include "benode.h"
32 #include "irgwalk.h"
33 #include "irnode_t.h"
34 #include "error.h"
35
36 static copy_attr_func  old_phi_copy_attr;
37
38 void be_info_new_node(ir_node *node)
39 {
40         struct obstack *obst;
41         backend_info_t *info;
42
43         /* Projs need no be info, their tuple holds all information */
44         if (is_Proj(node))
45                 return;
46
47         obst = be_get_birg_obst(current_ir_graph);
48         info = OALLOCZ(obst, backend_info_t);
49
50         assert(node->backend_info == NULL);
51         node->backend_info = info;
52
53         /* Hack! We still have middle end nodes in the backend (which was probably
54            a bad decision back then), which have no register constraints.
55            Set some none_requirements here.
56          */
57         if (get_irn_mode(node) != mode_T
58                         && get_irn_opcode(node) <= iro_Last) {
59                 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
60                 memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
61                 info->out_infos[0].req = arch_no_register_req;
62         }
63 }
64
65 static void new_Phi_copy_attr(const ir_node *old_node, ir_node *new_node)
66 {
67         backend_info_t *old_info = be_get_info(old_node);
68         backend_info_t *new_info = be_get_info(new_node);
69
70         *new_info = *old_info;
71
72         old_phi_copy_attr(old_node, new_node);
73 }
74
75 int be_infos_equal(const backend_info_t *info1, const backend_info_t *info2)
76 {
77         int             len   = ARR_LEN(info1->out_infos);
78         int             i;
79
80         if (ARR_LEN(info2->out_infos) != len)
81                 return false;
82
83         for (i = 0; i < len; ++i) {
84                 const reg_out_info_t *out1 = &info1->out_infos[i];
85                 const reg_out_info_t *out2 = &info2->out_infos[i];
86                 if (out1->reg != out2->reg)
87                         return false;
88                 if (!reg_reqs_equal(out1->req, out2->req))
89                         return false;
90         }
91
92         return true;
93 }
94
95 int be_nodes_equal(const ir_node *node1, const ir_node *node2)
96 {
97         backend_info_t *info1 = be_get_info(node1);
98         backend_info_t *info2 = be_get_info(node2);
99         return be_infos_equal(info1, info2);
100 }
101
102 static void init_walker(ir_node *node, void *data)
103 {
104         (void) data;
105         be_info_new_node(node);
106 }
107
108 static bool initialized = false;
109
110 void be_info_init(void)
111 {
112         if (initialized)
113                 panic("double initialization of be_info");
114
115         old_phi_copy_attr = op_Phi->ops.copy_attr;
116         op_Phi->ops.copy_attr = new_Phi_copy_attr;
117         initialized = true;
118
119         /* phis have register and register requirements now which we want to dump */
120         assert(op_Phi->ops.dump_node == NULL);
121         op_Phi->ops.dump_node = be_dump_phi_reg_reqs;
122 }
123
124 void be_info_init_irg(ir_graph *irg)
125 {
126         irg_walk_anchors(irg, init_walker, NULL, NULL);
127 }
128
129 void be_info_free(void)
130 {
131         if (!initialized)
132                 panic("be_info_free called without prior init");
133
134         assert(op_Phi->ops.copy_attr == new_Phi_copy_attr);
135         op_Phi->ops.copy_attr = old_phi_copy_attr;
136         initialized = false;
137
138         assert(op_Phi->ops.dump_node == be_dump_phi_reg_reqs);
139         op_Phi->ops.dump_node = NULL;
140 }
141
142 int be_info_initialized(const ir_graph *irg)
143 {
144         (void) irg;
145         return initialized;
146 }