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 * Get the isa responsible for a node.
53 * @param irn The node to get the responsible isa for.
54 * @return The irn operations given by the responsible isa.
56 static inline const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
59 const arch_irn_ops_t *be_ops;
62 irn = get_Proj_pred(irn);
63 assert(!is_Proj(irn));
66 ops = get_irn_op(irn);
67 be_ops = get_op_ops(ops)->be_ops;
72 const arch_register_req_t *arch_get_register_req(const ir_node *irn, int pos)
74 const arch_irn_ops_t *ops;
78 pos = -1-get_Proj_proj(irn);
79 irn = get_Proj_pred(irn);
81 ops = get_irn_ops_simple(irn);
83 return ops->get_irn_reg_req_out(irn, -pos-1);
85 return ops->get_irn_reg_req_in(irn, pos);
89 const arch_register_req_t *arch_get_register_req_out(const ir_node *irn)
92 const arch_irn_ops_t *ops;
95 pos = get_Proj_proj(irn);
96 irn = get_Proj_pred(irn);
97 } else if (get_irn_mode(irn) == mode_T) {
98 return arch_no_register_req;
100 ops = get_irn_ops(irn);
101 return ops->get_irn_reg_req_out(irn, pos);
104 void arch_set_frame_offset(ir_node *irn, int offset)
106 const arch_irn_ops_t *ops = get_irn_ops(irn);
107 ops->set_frame_offset(irn, offset);
110 ir_entity *arch_get_frame_entity(const ir_node *irn)
112 const arch_irn_ops_t *ops = get_irn_ops(irn);
113 return ops->get_frame_entity(irn);
116 void arch_set_frame_entity(ir_node *irn, ir_entity *ent)
118 const arch_irn_ops_t *ops = get_irn_ops(irn);
119 ops->set_frame_entity(irn, ent);
122 int arch_get_sp_bias(ir_node *irn)
124 const arch_irn_ops_t *ops = get_irn_ops(irn);
125 return ops->get_sp_bias(irn);
128 arch_inverse_t *arch_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack)
130 const arch_irn_ops_t *ops = get_irn_ops(irn);
132 if(ops->get_inverse) {
133 return ops->get_inverse(irn, i, inverse, obstack);
139 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
141 const arch_irn_ops_t *ops = get_irn_ops(irn);
143 if(ops->possible_memory_operand) {
144 return ops->possible_memory_operand(irn, i);
150 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
152 const arch_irn_ops_t *ops = get_irn_ops(irn);
154 if(ops->perform_memory_operand) {
155 ops->perform_memory_operand(irn, spill, i);
161 int arch_get_op_estimated_cost(const ir_node *irn)
163 const arch_irn_ops_t *ops = get_irn_ops(irn);
165 if(ops->get_op_estimated_cost) {
166 return ops->get_op_estimated_cost(irn);
172 void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs)
176 for(i = 0; i < cls->n_regs; ++i) {
177 if(!arch_register_type_is(&cls->regs[i], ignore))
182 int arch_reg_is_allocatable(const ir_node *irn, int pos, const arch_register_t *reg)
184 const arch_register_req_t *req = arch_get_register_req(irn, pos);
186 if(req->type == arch_register_req_type_none)
189 if(arch_register_req_is(req, limited)) {
190 assert(arch_register_get_class(reg) == req->cls);
191 return rbitset_is_set(req->limited, arch_register_get_index(reg));
194 return req->cls == reg->reg_class;
197 const arch_register_class_t *arch_get_irn_reg_class(const ir_node *irn, int pos)
199 const arch_register_req_t *req = arch_get_register_req(irn, pos);
201 assert(req->type != arch_register_req_type_none || req->cls == NULL);
206 static inline reg_out_info_t *get_out_info(const ir_node *node)
209 const backend_info_t *info;
211 assert(get_irn_mode(node) != mode_T);
213 pos = get_Proj_proj(node);
214 node = get_Proj_pred(node);
217 info = be_get_info(node);
218 assert(pos >= 0 && pos < ARR_LEN(info->out_infos));
219 return &info->out_infos[pos];
223 static inline reg_out_info_t *get_out_info_n(const ir_node *node, int pos)
225 const backend_info_t *info = be_get_info(node);
226 assert(!is_Proj(node));
227 assert(pos >= 0 && pos < ARR_LEN(info->out_infos));
228 return &info->out_infos[pos];
232 const arch_register_t *arch_get_irn_register(const ir_node *node)
234 const reg_out_info_t *out = get_out_info(node);
238 const arch_register_t *arch_irn_get_register(const ir_node *node, int pos)
240 const reg_out_info_t *out = get_out_info_n(node, pos);
244 void arch_irn_set_register(ir_node *node, int pos, const arch_register_t *reg)
246 reg_out_info_t *out = get_out_info_n(node, pos);
250 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
252 reg_out_info_t *out = get_out_info(node);
256 arch_irn_class_t arch_irn_classify(const ir_node *node)
258 const arch_irn_ops_t *ops = get_irn_ops(node);
259 return ops->classify(node);
262 arch_irn_flags_t arch_irn_get_flags(const ir_node *node)
264 backend_info_t *info = be_get_info(node);
268 void arch_irn_set_flags(ir_node *node, arch_irn_flags_t flags)
270 backend_info_t *info = be_get_info(node);
274 void arch_irn_add_flags(ir_node *node, arch_irn_flags_t flags)
276 backend_info_t *info = be_get_info(node);
277 info->flags |= flags;
280 void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
283 if (req == NULL || req->type == arch_register_req_type_none) {
288 fprintf(F, "%s", req->cls->name);
290 if(arch_register_req_is(req, limited)) {
291 unsigned n_regs = req->cls->n_regs;
294 fprintf(F, " limited to");
295 for(i = 0; i < n_regs; ++i) {
296 if(rbitset_is_set(req->limited, i)) {
297 const arch_register_t *reg = &req->cls->regs[i];
298 fprintf(F, " %s", reg->name);
303 if(arch_register_req_is(req, should_be_same)) {
304 const unsigned other = req->other_same;
307 fprintf(F, " same as");
308 for (i = 0; 1U << i <= other; ++i) {
309 if (other & (1U << i)) {
310 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
315 if (arch_register_req_is(req, must_be_different)) {
316 const unsigned other = req->other_different;
319 fprintf(F, " different from");
320 for (i = 0; 1U << i <= other; ++i) {
321 if (other & (1U << i)) {
322 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
327 if (arch_register_req_is(req, ignore)) {
328 fprintf(F, " ignore");
330 if (arch_register_req_is(req, produces_sp)) {
331 fprintf(F, " produces_sp");
335 static const arch_register_req_t no_requirement = {
336 arch_register_req_type_none,
342 const arch_register_req_t *arch_no_register_req = &no_requirement;