Remove the unused parameter const arch_env_t *env from arch_get_frame_entity().
[libfirm] / ir / be / bearch.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  * @brief       Processor architecture specification.
23  * @author      Sebastian Hack
24  * @version     $Id$
25  */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <string.h>
31
32 #include "bearch_t.h"
33 #include "benode_t.h"
34 #include "ircons_t.h"
35 #include "irnode_t.h"
36
37 #include "bitset.h"
38 #include "pset.h"
39 #include "raw_bitset.h"
40
41 #include "irprintf.h"
42
43 /* Initialize the architecture environment struct. */
44 arch_env_t *arch_env_init(const arch_isa_if_t *isa_if, FILE *file_handle, be_main_env_t *main_env)
45 {
46         arch_env_t *arch_env = isa_if->init(file_handle);
47         arch_env->main_env   = main_env;
48         return arch_env;
49 }
50
51 /**
52  * Put all registers in a class into a bitset.
53  * @param cls The class.
54  * @param bs The bitset.
55  * @return The number of registers in the class.
56  */
57 static int arch_register_class_put(const arch_register_class_t *cls, bitset_t *bs)
58 {
59         int i, n = cls->n_regs;
60         for (i = n - 1; i >= 0; --i)
61                 bitset_set(bs, i);
62         return n;
63 }
64
65 /**
66  * Get the isa responsible for a node.
67  * @param irn The node to get the responsible isa for.
68  * @return The irn operations given by the responsible isa.
69  */
70 static INLINE const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
71 {
72         const ir_op          *ops;
73         const arch_irn_ops_t *be_ops;
74
75         if (is_Proj(irn)) {
76                 irn = get_Proj_pred(irn);
77                 assert(!is_Proj(irn));
78         }
79
80         ops    = get_irn_op(irn);
81         be_ops = get_op_ops(ops)->be_ops;
82
83         assert(be_ops);
84         return be_ops;
85 }
86
87 const arch_register_req_t *arch_get_register_req(const ir_node *irn, int pos)
88 {
89         const arch_irn_ops_t *ops = get_irn_ops(irn);
90         return ops->get_irn_reg_req(irn, pos);
91 }
92
93 void arch_set_frame_offset(ir_node *irn, int offset)
94 {
95         const arch_irn_ops_t *ops = get_irn_ops(irn);
96         ops->set_frame_offset(irn, offset);
97 }
98
99 ir_entity *arch_get_frame_entity(const ir_node *irn)
100 {
101         const arch_irn_ops_t *ops = get_irn_ops(irn);
102         return ops->get_frame_entity(irn);
103 }
104
105 void arch_set_frame_entity(const arch_env_t *env, ir_node *irn, ir_entity *ent)
106 {
107         const arch_irn_ops_t *ops = get_irn_ops(irn);
108         (void)env; // TODO remove parameter
109         ops->set_frame_entity(irn, ent);
110 }
111
112 int arch_get_sp_bias(const arch_env_t *env, ir_node *irn)
113 {
114         const arch_irn_ops_t *ops = get_irn_ops(irn);
115         (void)env; // TODO remove parameter
116         return ops->get_sp_bias(irn);
117 }
118
119 arch_inverse_t *arch_get_inverse(const arch_env_t *env, const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack)
120 {
121         const arch_irn_ops_t *ops = get_irn_ops(irn);
122         (void)env; // TODO remove parameter
123
124         if(ops->get_inverse) {
125                 return ops->get_inverse(irn, i, inverse, obstack);
126         } else {
127                 return NULL;
128         }
129 }
130
131 int arch_possible_memory_operand(const arch_env_t *env, const ir_node *irn, unsigned int i) {
132         const arch_irn_ops_t *ops = get_irn_ops(irn);
133         (void)env; // TODO remove parameter
134
135         if(ops->possible_memory_operand) {
136                 return ops->possible_memory_operand(irn, i);
137         } else {
138                 return 0;
139         }
140 }
141
142 void arch_perform_memory_operand(const arch_env_t *env, ir_node *irn, ir_node *spill, unsigned int i) {
143         const arch_irn_ops_t *ops = get_irn_ops(irn);
144         (void)env; // TODO remove parameter
145
146         if(ops->perform_memory_operand) {
147                 ops->perform_memory_operand(irn, spill, i);
148         } else {
149                 return;
150         }
151 }
152
153 int arch_get_op_estimated_cost(const arch_env_t *env, const ir_node *irn)
154 {
155         const arch_irn_ops_t *ops = get_irn_ops(irn);
156         (void)env; // TODO remove parameter
157
158         if(ops->get_op_estimated_cost) {
159                 return ops->get_op_estimated_cost(irn);
160         } else {
161                 return 1;
162         }
163 }
164
165 int arch_is_possible_memory_operand(const arch_env_t *env, const ir_node *irn, int i)
166 {
167         const arch_irn_ops_t *ops = get_irn_ops(irn);
168         (void)env; // TODO remove parameter
169
170         if(ops->possible_memory_operand) {
171                 return ops->possible_memory_operand(irn, i);
172         } else {
173                 return 0;
174         }
175 }
176
177 int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs)
178 {
179         const arch_irn_ops_t *ops = get_irn_ops(irn);
180         const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
181         (void)env; // TODO remove parameter
182
183         if(req->type == arch_register_req_type_none) {
184                 bitset_clear_all(bs);
185                 return 0;
186         }
187
188         if(arch_register_req_is(req, limited)) {
189                 rbitset_copy_to_bitset(req->limited, bs);
190                 return bitset_popcnt(bs);
191         }
192
193         arch_register_class_put(req->cls, bs);
194         return req->cls->n_regs;
195 }
196
197 void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs)
198 {
199         unsigned i;
200
201         for(i = 0; i < cls->n_regs; ++i) {
202                 if(!arch_register_type_is(&cls->regs[i], ignore))
203                         bitset_set(bs, i);
204         }
205 }
206
207 int arch_is_register_operand(const arch_env_t *env,
208     const ir_node *irn, int pos)
209 {
210         const arch_irn_ops_t *ops = get_irn_ops(irn);
211         const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
212         (void)env; // TODO remove parameter
213
214         return req != NULL;
215 }
216
217 int arch_reg_is_allocatable(const arch_env_t *env, const ir_node *irn,
218     int pos, const arch_register_t *reg)
219 {
220         const arch_register_req_t *req = arch_get_register_req(irn, pos);
221         (void)env; // TODO remove parameter
222
223         if(req->type == arch_register_req_type_none)
224                 return 0;
225
226         if(arch_register_req_is(req, limited)) {
227                 assert(arch_register_get_class(reg) == req->cls);
228                 return rbitset_is_set(req->limited, arch_register_get_index(reg));
229         }
230
231         return req->cls == reg->reg_class;
232 }
233
234 const arch_register_class_t *
235 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos)
236 {
237         const arch_irn_ops_t *ops = get_irn_ops(irn);
238         const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
239         (void)env; // TODO remove parameter
240
241         assert(req->type != arch_register_req_type_none || req->cls == NULL);
242
243         return req->cls;
244 }
245
246 extern const arch_register_t *
247 arch_get_irn_register(const arch_env_t *env, const ir_node *irn)
248 {
249         const arch_irn_ops_t *ops = get_irn_ops(irn);
250         (void)env; // TODO remove parameter
251         return ops->get_irn_reg(irn);
252 }
253
254 extern void arch_set_irn_register(const arch_env_t *env,
255     ir_node *irn, const arch_register_t *reg)
256 {
257         const arch_irn_ops_t *ops = get_irn_ops(irn);
258         (void)env; // TODO remove parameter
259         ops->set_irn_reg(irn, reg);
260 }
261
262 extern arch_irn_class_t arch_irn_classify(const arch_env_t *env, const ir_node *irn)
263 {
264         const arch_irn_ops_t *ops = get_irn_ops(irn);
265         (void)env; // TODO remove parameter
266         return ops->classify(irn);
267 }
268
269 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn)
270 {
271         const arch_irn_ops_t *ops = get_irn_ops(irn);
272         (void)env; // TODO remove parameter
273         return ops->get_flags(irn);
274 }
275
276 extern const char *arch_irn_flag_str(arch_irn_flags_t fl)
277 {
278         switch(fl) {
279 #define XXX(x) case arch_irn_flags_ ## x: return #x;
280                 XXX(dont_spill);
281                 XXX(ignore);
282                 XXX(rematerializable);
283                 XXX(modify_sp);
284                 XXX(modify_flags);
285                 XXX(none);
286 #undef XXX
287         }
288         return "n/a";
289 }
290
291 extern char *arch_register_req_format(char *buf, size_t len,
292                                       const arch_register_req_t *req,
293                                       const ir_node *node)
294 {
295         char tmp[128];
296         snprintf(buf, len, "class: %s", req->cls->name);
297
298         if(arch_register_req_is(req, limited)) {
299                 unsigned n_regs = req->cls->n_regs;
300                 unsigned i;
301
302                 strncat(buf, " limited:", len);
303                 for(i = 0; i < n_regs; ++i) {
304                         if(rbitset_is_set(req->limited, i)) {
305                                 const arch_register_t *reg = &req->cls->regs[i];
306                                 strncat(buf, " ", len);
307                                 strncat(buf, reg->name, len);
308                         }
309                 }
310         }
311
312         if(arch_register_req_is(req, should_be_same)) {
313                 const unsigned other = req->other_same;
314                 int i;
315
316                 ir_snprintf(tmp, sizeof(tmp), " same to:");
317                 for (i = 0; 1U << i <= other; ++i) {
318                         if (other & (1U << i)) {
319                                 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
320                                 strncat(buf, tmp, len);
321                         }
322                 }
323         }
324
325         if (arch_register_req_is(req, must_be_different)) {
326                 const unsigned other = req->other_different;
327                 int i;
328
329                 ir_snprintf(tmp, sizeof(tmp), " different from:");
330                 for (i = 0; 1U << i <= other; ++i) {
331                         if (other & (1U << i)) {
332                                 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
333                                 strncat(buf, tmp, len);
334                         }
335                 }
336         }
337
338         return buf;
339 }
340
341 static const arch_register_req_t no_requirement = {
342         arch_register_req_type_none,
343         NULL,
344         NULL,
345         0,
346         0
347 };
348 const arch_register_req_t *arch_no_register_req = &no_requirement;