Remove the unused function arch_get_irn_ops().
[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 arch_env_t *env,
88                                                  const ir_node *irn, int pos)
89 {
90         const arch_irn_ops_t *ops = get_irn_ops(irn);
91         (void)env; // TODO remove parameter
92         return ops->get_irn_reg_req(irn, pos);
93 }
94
95 void arch_set_frame_offset(const arch_env_t *env, ir_node *irn, int offset)
96 {
97         const arch_irn_ops_t *ops = get_irn_ops(irn);
98         (void)env; // TODO remove parameter
99         ops->set_frame_offset(irn, offset);
100 }
101
102 ir_entity *arch_get_frame_entity(const arch_env_t *env, const ir_node *irn)
103 {
104         const arch_irn_ops_t *ops = get_irn_ops(irn);
105         (void)env; // TODO remove parameter
106         return ops->get_frame_entity(irn);
107 }
108
109 void arch_set_frame_entity(const arch_env_t *env, ir_node *irn, ir_entity *ent)
110 {
111         const arch_irn_ops_t *ops = get_irn_ops(irn);
112         (void)env; // TODO remove parameter
113         ops->set_frame_entity(irn, ent);
114 }
115
116 int arch_get_sp_bias(const arch_env_t *env, ir_node *irn)
117 {
118         const arch_irn_ops_t *ops = get_irn_ops(irn);
119         (void)env; // TODO remove parameter
120         return ops->get_sp_bias(irn);
121 }
122
123 arch_inverse_t *arch_get_inverse(const arch_env_t *env, const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack)
124 {
125         const arch_irn_ops_t *ops = get_irn_ops(irn);
126         (void)env; // TODO remove parameter
127
128         if(ops->get_inverse) {
129                 return ops->get_inverse(irn, i, inverse, obstack);
130         } else {
131                 return NULL;
132         }
133 }
134
135 int arch_possible_memory_operand(const arch_env_t *env, const ir_node *irn, unsigned int i) {
136         const arch_irn_ops_t *ops = get_irn_ops(irn);
137         (void)env; // TODO remove parameter
138
139         if(ops->possible_memory_operand) {
140                 return ops->possible_memory_operand(irn, i);
141         } else {
142                 return 0;
143         }
144 }
145
146 void arch_perform_memory_operand(const arch_env_t *env, ir_node *irn, ir_node *spill, unsigned int i) {
147         const arch_irn_ops_t *ops = get_irn_ops(irn);
148         (void)env; // TODO remove parameter
149
150         if(ops->perform_memory_operand) {
151                 ops->perform_memory_operand(irn, spill, i);
152         } else {
153                 return;
154         }
155 }
156
157 int arch_get_op_estimated_cost(const arch_env_t *env, const ir_node *irn)
158 {
159         const arch_irn_ops_t *ops = get_irn_ops(irn);
160         (void)env; // TODO remove parameter
161
162         if(ops->get_op_estimated_cost) {
163                 return ops->get_op_estimated_cost(irn);
164         } else {
165                 return 1;
166         }
167 }
168
169 int arch_is_possible_memory_operand(const arch_env_t *env, const ir_node *irn, int i)
170 {
171         const arch_irn_ops_t *ops = get_irn_ops(irn);
172         (void)env; // TODO remove parameter
173
174         if(ops->possible_memory_operand) {
175                 return ops->possible_memory_operand(irn, i);
176         } else {
177                 return 0;
178         }
179 }
180
181 int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs)
182 {
183         const arch_irn_ops_t *ops = get_irn_ops(irn);
184         const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
185         (void)env; // TODO remove parameter
186
187         if(req->type == arch_register_req_type_none) {
188                 bitset_clear_all(bs);
189                 return 0;
190         }
191
192         if(arch_register_req_is(req, limited)) {
193                 rbitset_copy_to_bitset(req->limited, bs);
194                 return bitset_popcnt(bs);
195         }
196
197         arch_register_class_put(req->cls, bs);
198         return req->cls->n_regs;
199 }
200
201 void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs)
202 {
203         unsigned i;
204
205         for(i = 0; i < cls->n_regs; ++i) {
206                 if(!arch_register_type_is(&cls->regs[i], ignore))
207                         bitset_set(bs, i);
208         }
209 }
210
211 int arch_is_register_operand(const arch_env_t *env,
212     const ir_node *irn, int pos)
213 {
214         const arch_irn_ops_t *ops = get_irn_ops(irn);
215         const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
216         (void)env; // TODO remove parameter
217
218         return req != NULL;
219 }
220
221 int arch_reg_is_allocatable(const arch_env_t *env, const ir_node *irn,
222     int pos, const arch_register_t *reg)
223 {
224         const arch_register_req_t *req;
225
226         req = arch_get_register_req(env, irn, pos);
227
228         if(req->type == arch_register_req_type_none)
229                 return 0;
230
231         if(arch_register_req_is(req, limited)) {
232                 assert(arch_register_get_class(reg) == req->cls);
233                 return rbitset_is_set(req->limited, arch_register_get_index(reg));
234         }
235
236         return req->cls == reg->reg_class;
237 }
238
239 const arch_register_class_t *
240 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos)
241 {
242         const arch_irn_ops_t *ops = get_irn_ops(irn);
243         const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
244         (void)env; // TODO remove parameter
245
246         assert(req->type != arch_register_req_type_none || req->cls == NULL);
247
248         return req->cls;
249 }
250
251 extern const arch_register_t *
252 arch_get_irn_register(const arch_env_t *env, const ir_node *irn)
253 {
254         const arch_irn_ops_t *ops = get_irn_ops(irn);
255         (void)env; // TODO remove parameter
256         return ops->get_irn_reg(irn);
257 }
258
259 extern void arch_set_irn_register(const arch_env_t *env,
260     ir_node *irn, const arch_register_t *reg)
261 {
262         const arch_irn_ops_t *ops = get_irn_ops(irn);
263         (void)env; // TODO remove parameter
264         ops->set_irn_reg(irn, reg);
265 }
266
267 extern arch_irn_class_t arch_irn_classify(const arch_env_t *env, const ir_node *irn)
268 {
269         const arch_irn_ops_t *ops = get_irn_ops(irn);
270         (void)env; // TODO remove parameter
271         return ops->classify(irn);
272 }
273
274 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn)
275 {
276         const arch_irn_ops_t *ops = get_irn_ops(irn);
277         (void)env; // TODO remove parameter
278         return ops->get_flags(irn);
279 }
280
281 extern const char *arch_irn_flag_str(arch_irn_flags_t fl)
282 {
283         switch(fl) {
284 #define XXX(x) case arch_irn_flags_ ## x: return #x;
285                 XXX(dont_spill);
286                 XXX(ignore);
287                 XXX(rematerializable);
288                 XXX(modify_sp);
289                 XXX(modify_flags);
290                 XXX(none);
291 #undef XXX
292         }
293         return "n/a";
294 }
295
296 extern char *arch_register_req_format(char *buf, size_t len,
297                                       const arch_register_req_t *req,
298                                       const ir_node *node)
299 {
300         char tmp[128];
301         snprintf(buf, len, "class: %s", req->cls->name);
302
303         if(arch_register_req_is(req, limited)) {
304                 unsigned n_regs = req->cls->n_regs;
305                 unsigned i;
306
307                 strncat(buf, " limited:", len);
308                 for(i = 0; i < n_regs; ++i) {
309                         if(rbitset_is_set(req->limited, i)) {
310                                 const arch_register_t *reg = &req->cls->regs[i];
311                                 strncat(buf, " ", len);
312                                 strncat(buf, reg->name, len);
313                         }
314                 }
315         }
316
317         if(arch_register_req_is(req, should_be_same)) {
318                 const unsigned other = req->other_same;
319                 int i;
320
321                 ir_snprintf(tmp, sizeof(tmp), " same to:");
322                 for (i = 0; 1U << i <= other; ++i) {
323                         if (other & (1U << i)) {
324                                 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
325                                 strncat(buf, tmp, len);
326                         }
327                 }
328         }
329
330         if (arch_register_req_is(req, must_be_different)) {
331                 const unsigned other = req->other_different;
332                 int i;
333
334                 ir_snprintf(tmp, sizeof(tmp), " different from:");
335                 for (i = 0; 1U << i <= other; ++i) {
336                         if (other & (1U << i)) {
337                                 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
338                                 strncat(buf, tmp, len);
339                         }
340                 }
341         }
342
343         return buf;
344 }
345
346 static const arch_register_req_t no_requirement = {
347         arch_register_req_type_none,
348         NULL,
349         NULL,
350         0,
351         0
352 };
353 const arch_register_req_t *arch_no_register_req = &no_requirement;