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
38 #include "raw_bitset.h"
42 /* Initialize the architecture environment struct. */
43 arch_env_t *arch_env_init(const arch_isa_if_t *isa_if, FILE *file_handle, be_main_env_t *main_env)
45 arch_env_t *arch_env = isa_if->init(file_handle);
46 arch_env->main_env = main_env;
51 * Get the isa responsible for a node.
52 * @param irn The node to get the responsible isa for.
53 * @return The irn operations given by the responsible isa.
55 static inline const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
58 const arch_irn_ops_t *be_ops;
61 irn = get_Proj_pred(irn);
62 assert(!is_Proj(irn));
65 ops = get_irn_op(irn);
66 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 = get_irn_ops(irn);
75 return ops->get_irn_reg_req(irn, pos);
78 void arch_set_frame_offset(ir_node *irn, int offset)
80 const arch_irn_ops_t *ops = get_irn_ops(irn);
81 ops->set_frame_offset(irn, offset);
84 ir_entity *arch_get_frame_entity(const ir_node *irn)
86 const arch_irn_ops_t *ops = get_irn_ops(irn);
87 return ops->get_frame_entity(irn);
90 void arch_set_frame_entity(ir_node *irn, ir_entity *ent)
92 const arch_irn_ops_t *ops = get_irn_ops(irn);
93 ops->set_frame_entity(irn, ent);
96 int arch_get_sp_bias(ir_node *irn)
98 const arch_irn_ops_t *ops = get_irn_ops(irn);
99 return ops->get_sp_bias(irn);
102 arch_inverse_t *arch_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack)
104 const arch_irn_ops_t *ops = get_irn_ops(irn);
106 if(ops->get_inverse) {
107 return ops->get_inverse(irn, i, inverse, obstack);
113 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
115 const arch_irn_ops_t *ops = get_irn_ops(irn);
117 if(ops->possible_memory_operand) {
118 return ops->possible_memory_operand(irn, i);
124 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
126 const arch_irn_ops_t *ops = get_irn_ops(irn);
128 if(ops->perform_memory_operand) {
129 ops->perform_memory_operand(irn, spill, i);
135 int arch_get_op_estimated_cost(const ir_node *irn)
137 const arch_irn_ops_t *ops = get_irn_ops(irn);
139 if(ops->get_op_estimated_cost) {
140 return ops->get_op_estimated_cost(irn);
146 void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs)
150 for(i = 0; i < cls->n_regs; ++i) {
151 if(!arch_register_type_is(&cls->regs[i], ignore))
156 int arch_reg_is_allocatable(const ir_node *irn, int pos, const arch_register_t *reg)
158 const arch_register_req_t *req = arch_get_register_req(irn, pos);
160 if(req->type == arch_register_req_type_none)
163 if(arch_register_req_is(req, limited)) {
164 assert(arch_register_get_class(reg) == req->cls);
165 return rbitset_is_set(req->limited, arch_register_get_index(reg));
168 return req->cls == reg->reg_class;
171 const arch_register_class_t *arch_get_irn_reg_class(const ir_node *irn, int pos)
173 const arch_register_req_t *req = arch_get_register_req(irn, pos);
175 assert(req->type != arch_register_req_type_none || req->cls == NULL);
180 static inline reg_out_info_t *get_out_info(const ir_node *node)
183 const backend_info_t *info;
185 assert(get_irn_mode(node) != mode_T);
187 pos = get_Proj_proj(node);
188 node = get_Proj_pred(node);
191 info = be_get_info(node);
192 assert(pos >= 0 && pos < ARR_LEN(info->out_infos));
193 return &info->out_infos[pos];
197 static inline reg_out_info_t *get_out_info_n(const ir_node *node, int pos)
199 const backend_info_t *info = be_get_info(node);
200 assert(!is_Proj(node));
201 assert(pos >= 0 && pos < ARR_LEN(info->out_infos));
202 return &info->out_infos[pos];
206 const arch_register_t *arch_get_irn_register(const ir_node *node)
208 const reg_out_info_t *out = get_out_info(node);
212 const arch_register_t *arch_irn_get_register(const ir_node *node, int pos)
214 const reg_out_info_t *out = get_out_info_n(node, pos);
218 void arch_irn_set_register(ir_node *node, int pos, const arch_register_t *reg)
220 reg_out_info_t *out = get_out_info_n(node, pos);
224 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
226 reg_out_info_t *out = get_out_info(node);
230 arch_irn_class_t arch_irn_classify(const ir_node *node)
232 const arch_irn_ops_t *ops = get_irn_ops(node);
233 return ops->classify(node);
236 arch_irn_flags_t arch_irn_get_flags(const ir_node *node)
238 backend_info_t *info = be_get_info(node);
242 void arch_irn_set_flags(ir_node *node, arch_irn_flags_t flags)
244 backend_info_t *info = be_get_info(node);
248 void arch_irn_add_flags(ir_node *node, arch_irn_flags_t flags)
250 backend_info_t *info = be_get_info(node);
251 info->flags |= flags;
254 extern char *arch_register_req_format(char *buf, size_t len,
255 const arch_register_req_t *req,
259 snprintf(buf, len, "class: %s", req->cls->name);
261 if(arch_register_req_is(req, limited)) {
262 unsigned n_regs = req->cls->n_regs;
265 strncat(buf, " limited:", len);
266 for(i = 0; i < n_regs; ++i) {
267 if(rbitset_is_set(req->limited, i)) {
268 const arch_register_t *reg = &req->cls->regs[i];
269 strncat(buf, " ", len);
270 strncat(buf, reg->name, len);
275 if(arch_register_req_is(req, should_be_same)) {
276 const unsigned other = req->other_same;
279 ir_snprintf(tmp, sizeof(tmp), " same to:");
280 for (i = 0; 1U << i <= other; ++i) {
281 if (other & (1U << i)) {
282 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
283 strncat(buf, tmp, len);
288 if (arch_register_req_is(req, must_be_different)) {
289 const unsigned other = req->other_different;
292 ir_snprintf(tmp, sizeof(tmp), " different from:");
293 for (i = 0; 1U << i <= other; ++i) {
294 if (other & (1U << i)) {
295 ir_snprintf(tmp, sizeof(tmp), " %+F", get_irn_n(skip_Proj_const(node), i));
296 strncat(buf, tmp, len);
301 if (arch_register_req_is(req, ignore)) {
302 strncat(buf, " ignore", len);
304 if (arch_register_req_is(req, produces_sp)) {
305 strncat(buf, " produces_sp", len);
311 static const arch_register_req_t no_requirement = {
312 arch_register_req_type_none,
318 const arch_register_req_t *arch_no_register_req = &no_requirement;