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
37 #include "raw_bitset.h"
41 /* Initialize the architecture environment struct. */
42 arch_env_t *arch_env_init(const arch_isa_if_t *isa_if, FILE *file_handle, be_main_env_t *main_env)
44 arch_env_t *arch_env = isa_if->init(file_handle);
45 arch_env->main_env = main_env;
50 * Put all registers in a class into a bitset.
51 * @param cls The class.
52 * @param bs The bitset.
53 * @return The number of registers in the class.
55 static int arch_register_class_put(const arch_register_class_t *cls, bitset_t *bs)
57 int i, n = cls->n_regs;
58 for (i = n - 1; i >= 0; --i)
64 * Get the isa responsible for a node.
65 * @param irn The node to get the responsible isa for.
66 * @return The irn operations given by the responsible isa.
68 static INLINE const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
71 const arch_irn_ops_t *be_ops;
74 irn = get_Proj_pred(irn);
75 assert(!is_Proj(irn));
78 ops = get_irn_op(irn);
79 be_ops = get_op_ops(ops)->be_ops;
85 const arch_register_req_t *arch_get_register_req(const ir_node *irn, int pos)
87 const arch_irn_ops_t *ops = get_irn_ops(irn);
88 return ops->get_irn_reg_req(irn, pos);
91 void arch_set_frame_offset(ir_node *irn, int offset)
93 const arch_irn_ops_t *ops = get_irn_ops(irn);
94 ops->set_frame_offset(irn, offset);
97 ir_entity *arch_get_frame_entity(const ir_node *irn)
99 const arch_irn_ops_t *ops = get_irn_ops(irn);
100 return ops->get_frame_entity(irn);
103 void arch_set_frame_entity(ir_node *irn, ir_entity *ent)
105 const arch_irn_ops_t *ops = get_irn_ops(irn);
106 ops->set_frame_entity(irn, ent);
109 int arch_get_sp_bias(ir_node *irn)
111 const arch_irn_ops_t *ops = get_irn_ops(irn);
112 return ops->get_sp_bias(irn);
115 arch_inverse_t *arch_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack)
117 const arch_irn_ops_t *ops = get_irn_ops(irn);
119 if(ops->get_inverse) {
120 return ops->get_inverse(irn, i, inverse, obstack);
126 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
128 const arch_irn_ops_t *ops = get_irn_ops(irn);
130 if(ops->possible_memory_operand) {
131 return ops->possible_memory_operand(irn, i);
137 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
139 const arch_irn_ops_t *ops = get_irn_ops(irn);
141 if(ops->perform_memory_operand) {
142 ops->perform_memory_operand(irn, spill, i);
148 int arch_get_op_estimated_cost(const ir_node *irn)
150 const arch_irn_ops_t *ops = get_irn_ops(irn);
152 if(ops->get_op_estimated_cost) {
153 return ops->get_op_estimated_cost(irn);
159 int arch_get_allocatable_regs(const ir_node *irn, int pos, bitset_t *bs)
161 const arch_irn_ops_t *ops = get_irn_ops(irn);
162 const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
164 if(req->type == arch_register_req_type_none) {
165 bitset_clear_all(bs);
169 if(arch_register_req_is(req, limited)) {
170 rbitset_copy_to_bitset(req->limited, bs);
171 return bitset_popcnt(bs);
174 arch_register_class_put(req->cls, bs);
175 return req->cls->n_regs;
178 void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs)
182 for(i = 0; i < cls->n_regs; ++i) {
183 if(!arch_register_type_is(&cls->regs[i], ignore))
188 int arch_is_register_operand(const ir_node *irn, int pos)
190 const arch_irn_ops_t *ops = get_irn_ops(irn);
191 const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
196 int arch_reg_is_allocatable(const ir_node *irn, int pos, const arch_register_t *reg)
198 const arch_register_req_t *req = arch_get_register_req(irn, pos);
200 if(req->type == arch_register_req_type_none)
203 if(arch_register_req_is(req, limited)) {
204 assert(arch_register_get_class(reg) == req->cls);
205 return rbitset_is_set(req->limited, arch_register_get_index(reg));
208 return req->cls == reg->reg_class;
211 const arch_register_class_t *arch_get_irn_reg_class(const ir_node *irn, int pos)
213 const arch_irn_ops_t *ops = get_irn_ops(irn);
214 const arch_register_req_t *req = ops->get_irn_reg_req(irn, pos);
216 assert(req->type != arch_register_req_type_none || req->cls == NULL);
221 const arch_register_t *arch_get_irn_register(const ir_node *irn)
223 const arch_irn_ops_t *ops = get_irn_ops(irn);
224 return ops->get_irn_reg(irn);
227 void arch_set_irn_register(ir_node *irn, const arch_register_t *reg)
229 const arch_irn_ops_t *ops = get_irn_ops(irn);
230 ops->set_irn_reg(irn, reg);
233 arch_irn_class_t arch_irn_classify(const ir_node *irn)
235 const arch_irn_ops_t *ops = get_irn_ops(irn);
236 return ops->classify(irn);
239 arch_irn_flags_t arch_irn_get_flags(const ir_node *irn)
241 const arch_irn_ops_t *ops = get_irn_ops(irn);
242 return ops->get_flags(irn);
245 extern const char *arch_irn_flag_str(arch_irn_flags_t fl)
248 #define XXX(x) case arch_irn_flags_ ## x: return #x;
251 XXX(rematerializable);
260 extern char *arch_register_req_format(char *buf, size_t len,
261 const arch_register_req_t *req,
265 snprintf(buf, len, "class: %s", req->cls->name);
267 if(arch_register_req_is(req, limited)) {
268 unsigned n_regs = req->cls->n_regs;
271 strncat(buf, " limited:", len);
272 for(i = 0; i < n_regs; ++i) {
273 if(rbitset_is_set(req->limited, i)) {
274 const arch_register_t *reg = &req->cls->regs[i];
275 strncat(buf, " ", len);
276 strncat(buf, reg->name, len);
281 if(arch_register_req_is(req, should_be_same)) {
282 const unsigned other = req->other_same;
285 ir_snprintf(tmp, sizeof(tmp), " same to:");
286 for (i = 0; 1U << i <= other; ++i) {
287 if (other & (1U << i)) {
288 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
289 strncat(buf, tmp, len);
294 if (arch_register_req_is(req, must_be_different)) {
295 const unsigned other = req->other_different;
298 ir_snprintf(tmp, sizeof(tmp), " different from:");
299 for (i = 0; 1U << i <= other; ++i) {
300 if (other & (1U << i)) {
301 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
302 strncat(buf, tmp, len);
310 static const arch_register_req_t no_requirement = {
311 arch_register_req_type_none,
317 const arch_register_req_t *arch_no_register_req = &no_requirement;