2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Processor architecture specification.
23 * @author Sebastian Hack
39 #include "raw_bitset.h"
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)
46 arch_env_t *arch_env = isa_if->init(file_handle);
47 arch_env->main_env = main_env;
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.
57 static int arch_register_class_put(const arch_register_class_t *cls, bitset_t *bs)
59 int i, n = cls->n_regs;
60 for (i = n - 1; i >= 0; --i)
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.
70 static INLINE const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
73 const arch_irn_ops_t *be_ops;
76 irn = get_Proj_pred(irn);
77 assert(!is_Proj(irn));
80 ops = get_irn_op(irn);
81 be_ops = get_op_ops(ops)->be_ops;
87 const arch_register_req_t *arch_get_register_req(const ir_node *irn, int pos)
89 const arch_irn_ops_t *ops = get_irn_ops(irn);
90 return ops->get_irn_reg_req(irn, pos);
93 void arch_set_frame_offset(ir_node *irn, int offset)
95 const arch_irn_ops_t *ops = get_irn_ops(irn);
96 ops->set_frame_offset(irn, offset);
99 ir_entity *arch_get_frame_entity(const ir_node *irn)
101 const arch_irn_ops_t *ops = get_irn_ops(irn);
102 return ops->get_frame_entity(irn);
105 void arch_set_frame_entity(ir_node *irn, ir_entity *ent)
107 const arch_irn_ops_t *ops = get_irn_ops(irn);
108 ops->set_frame_entity(irn, ent);
111 int arch_get_sp_bias(ir_node *irn)
113 const arch_irn_ops_t *ops = get_irn_ops(irn);
114 return ops->get_sp_bias(irn);
117 arch_inverse_t *arch_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack)
119 const arch_irn_ops_t *ops = get_irn_ops(irn);
121 if(ops->get_inverse) {
122 return ops->get_inverse(irn, i, inverse, obstack);
128 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
130 const arch_irn_ops_t *ops = get_irn_ops(irn);
132 if(ops->possible_memory_operand) {
133 return ops->possible_memory_operand(irn, i);
139 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
141 const arch_irn_ops_t *ops = get_irn_ops(irn);
143 if(ops->perform_memory_operand) {
144 ops->perform_memory_operand(irn, spill, i);
150 int arch_get_op_estimated_cost(const ir_node *irn)
152 const arch_irn_ops_t *ops = get_irn_ops(irn);
154 if(ops->get_op_estimated_cost) {
155 return ops->get_op_estimated_cost(irn);
161 int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs)
163 const arch_irn_ops_t *ops = get_irn_ops(irn);
164 const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
165 (void)env; // TODO remove parameter
167 if(req->type == arch_register_req_type_none) {
168 bitset_clear_all(bs);
172 if(arch_register_req_is(req, limited)) {
173 rbitset_copy_to_bitset(req->limited, bs);
174 return bitset_popcnt(bs);
177 arch_register_class_put(req->cls, bs);
178 return req->cls->n_regs;
181 void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs)
185 for(i = 0; i < cls->n_regs; ++i) {
186 if(!arch_register_type_is(&cls->regs[i], ignore))
191 int arch_is_register_operand(const arch_env_t *env,
192 const ir_node *irn, int pos)
194 const arch_irn_ops_t *ops = get_irn_ops(irn);
195 const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
196 (void)env; // TODO remove parameter
201 int arch_reg_is_allocatable(const arch_env_t *env, const ir_node *irn,
202 int pos, const arch_register_t *reg)
204 const arch_register_req_t *req = arch_get_register_req(irn, pos);
205 (void)env; // TODO remove parameter
207 if(req->type == arch_register_req_type_none)
210 if(arch_register_req_is(req, limited)) {
211 assert(arch_register_get_class(reg) == req->cls);
212 return rbitset_is_set(req->limited, arch_register_get_index(reg));
215 return req->cls == reg->reg_class;
218 const arch_register_class_t *
219 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos)
221 const arch_irn_ops_t *ops = get_irn_ops(irn);
222 const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
223 (void)env; // TODO remove parameter
225 assert(req->type != arch_register_req_type_none || req->cls == NULL);
230 extern const arch_register_t *
231 arch_get_irn_register(const arch_env_t *env, const ir_node *irn)
233 const arch_irn_ops_t *ops = get_irn_ops(irn);
234 (void)env; // TODO remove parameter
235 return ops->get_irn_reg(irn);
238 extern void arch_set_irn_register(const arch_env_t *env,
239 ir_node *irn, const arch_register_t *reg)
241 const arch_irn_ops_t *ops = get_irn_ops(irn);
242 (void)env; // TODO remove parameter
243 ops->set_irn_reg(irn, reg);
246 extern arch_irn_class_t arch_irn_classify(const arch_env_t *env, const ir_node *irn)
248 const arch_irn_ops_t *ops = get_irn_ops(irn);
249 (void)env; // TODO remove parameter
250 return ops->classify(irn);
253 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn)
255 const arch_irn_ops_t *ops = get_irn_ops(irn);
256 (void)env; // TODO remove parameter
257 return ops->get_flags(irn);
260 extern const char *arch_irn_flag_str(arch_irn_flags_t fl)
263 #define XXX(x) case arch_irn_flags_ ## x: return #x;
266 XXX(rematerializable);
275 extern char *arch_register_req_format(char *buf, size_t len,
276 const arch_register_req_t *req,
280 snprintf(buf, len, "class: %s", req->cls->name);
282 if(arch_register_req_is(req, limited)) {
283 unsigned n_regs = req->cls->n_regs;
286 strncat(buf, " limited:", len);
287 for(i = 0; i < n_regs; ++i) {
288 if(rbitset_is_set(req->limited, i)) {
289 const arch_register_t *reg = &req->cls->regs[i];
290 strncat(buf, " ", len);
291 strncat(buf, reg->name, len);
296 if(arch_register_req_is(req, should_be_same)) {
297 const unsigned other = req->other_same;
300 ir_snprintf(tmp, sizeof(tmp), " same to:");
301 for (i = 0; 1U << i <= other; ++i) {
302 if (other & (1U << i)) {
303 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
304 strncat(buf, tmp, len);
309 if (arch_register_req_is(req, must_be_different)) {
310 const unsigned other = req->other_different;
313 ir_snprintf(tmp, sizeof(tmp), " different from:");
314 for (i = 0; 1U << i <= other; ++i) {
315 if (other & (1U << i)) {
316 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
317 strncat(buf, tmp, len);
325 static const arch_register_req_t no_requirement = {
326 arch_register_req_type_none,
332 const arch_register_req_t *arch_no_register_req = &no_requirement;