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)
76 pos = -1-get_Proj_proj(irn);
77 irn = get_Proj_pred(irn);
81 return arch_get_out_register_req(irn, -pos-1);
83 const arch_irn_ops_t *ops = get_irn_ops_simple(irn);
84 return ops->get_irn_reg_req_in(irn, pos);
88 void arch_set_frame_offset(ir_node *irn, int offset)
90 const arch_irn_ops_t *ops = get_irn_ops(irn);
91 ops->set_frame_offset(irn, offset);
94 ir_entity *arch_get_frame_entity(const ir_node *irn)
96 const arch_irn_ops_t *ops = get_irn_ops(irn);
97 return ops->get_frame_entity(irn);
100 void arch_set_frame_entity(ir_node *irn, ir_entity *ent)
102 const arch_irn_ops_t *ops = get_irn_ops(irn);
103 ops->set_frame_entity(irn, ent);
106 int arch_get_sp_bias(ir_node *irn)
108 const arch_irn_ops_t *ops = get_irn_ops(irn);
109 return ops->get_sp_bias(irn);
112 arch_inverse_t *arch_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack)
114 const arch_irn_ops_t *ops = get_irn_ops(irn);
116 if (ops->get_inverse) {
117 return ops->get_inverse(irn, i, inverse, obstack);
123 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
125 const arch_irn_ops_t *ops = get_irn_ops(irn);
127 if (ops->possible_memory_operand) {
128 return ops->possible_memory_operand(irn, i);
134 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
136 const arch_irn_ops_t *ops = get_irn_ops(irn);
138 if (ops->perform_memory_operand) {
139 ops->perform_memory_operand(irn, spill, i);
145 int arch_get_op_estimated_cost(const ir_node *irn)
147 const arch_irn_ops_t *ops = get_irn_ops(irn);
149 if (ops->get_op_estimated_cost) {
150 return ops->get_op_estimated_cost(irn);
156 void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs)
160 for (i = 0; i < cls->n_regs; ++i) {
161 if (!arch_register_type_is(&cls->regs[i], ignore))
166 int arch_reg_is_allocatable(const ir_node *irn, int pos,
167 const arch_register_t *reg)
169 const arch_register_req_t *req = arch_get_register_req(irn, pos);
171 if (req->type == arch_register_req_type_none)
174 if (arch_register_req_is(req, limited)) {
175 if (arch_register_get_class(reg) != req->cls)
177 return rbitset_is_set(req->limited, arch_register_get_index(reg));
180 return req->cls == reg->reg_class;
183 const arch_register_class_t *arch_get_irn_reg_class(const ir_node *irn, int pos)
185 const arch_register_req_t *req = arch_get_register_req(irn, pos);
187 assert(req->type != arch_register_req_type_none || req->cls == NULL);
192 static inline reg_out_info_t *get_out_info(const ir_node *node)
195 const backend_info_t *info;
197 assert(get_irn_mode(node) != mode_T);
199 pos = get_Proj_proj(node);
200 node = get_Proj_pred(node);
203 info = be_get_info(node);
204 assert(pos >= 0 && pos < ARR_LEN(info->out_infos));
205 return &info->out_infos[pos];
209 static inline reg_out_info_t *get_out_info_n(const ir_node *node, int pos)
211 const backend_info_t *info = be_get_info(node);
212 assert(!is_Proj(node));
213 assert(pos >= 0 && pos < ARR_LEN(info->out_infos));
214 return &info->out_infos[pos];
218 const arch_register_t *arch_get_irn_register(const ir_node *node)
220 const reg_out_info_t *out = get_out_info(node);
224 const arch_register_t *arch_irn_get_register(const ir_node *node, int pos)
226 const reg_out_info_t *out = get_out_info_n(node, pos);
230 void arch_irn_set_register(ir_node *node, int pos, const arch_register_t *reg)
232 reg_out_info_t *out = get_out_info_n(node, pos);
236 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
238 reg_out_info_t *out = get_out_info(node);
242 arch_irn_class_t arch_irn_classify(const ir_node *node)
244 const arch_irn_ops_t *ops = get_irn_ops(node);
245 return ops->classify(node);
248 arch_irn_flags_t arch_irn_get_flags(const ir_node *node)
250 backend_info_t *info = be_get_info(node);
254 void arch_irn_set_flags(ir_node *node, arch_irn_flags_t flags)
256 backend_info_t *info = be_get_info(node);
260 void arch_irn_add_flags(ir_node *node, arch_irn_flags_t flags)
262 backend_info_t *info = be_get_info(node);
263 info->flags |= flags;
266 void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
269 if (req == NULL || req->type == arch_register_req_type_none) {
274 fprintf(F, "%s", req->cls->name);
276 if (arch_register_req_is(req, limited)) {
277 unsigned n_regs = req->cls->n_regs;
280 fprintf(F, " limited to");
281 for (i = 0; i < n_regs; ++i) {
282 if (rbitset_is_set(req->limited, i)) {
283 const arch_register_t *reg = &req->cls->regs[i];
284 fprintf(F, " %s", reg->name);
289 if (arch_register_req_is(req, should_be_same)) {
290 const unsigned other = req->other_same;
293 fprintf(F, " same as");
294 for (i = 0; 1U << i <= other; ++i) {
295 if (other & (1U << i)) {
296 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
301 if (arch_register_req_is(req, must_be_different)) {
302 const unsigned other = req->other_different;
305 fprintf(F, " different from");
306 for (i = 0; 1U << i <= other; ++i) {
307 if (other & (1U << i)) {
308 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
313 if (arch_register_req_is(req, ignore)) {
314 fprintf(F, " ignore");
316 if (arch_register_req_is(req, produces_sp)) {
317 fprintf(F, " produces_sp");
321 void arch_dump_reqs_and_registers(FILE *F, const ir_node *node)
323 int n_ins = get_irn_arity(node);
324 int n_outs = arch_irn_get_n_outs(node);
325 arch_irn_flags_t flags = arch_irn_get_flags(node);
328 for (i = 0; i < n_ins; ++i) {
329 const arch_register_req_t *req = arch_get_in_register_req(node, i);
330 fprintf(F, "inreq #%d = ", i);
331 arch_dump_register_req(F, req, node);
334 for (i = 0; i < n_outs; ++i) {
335 const arch_register_req_t *req = arch_get_out_register_req(node, i);
336 fprintf(F, "outreq #%d = ", i);
337 arch_dump_register_req(F, req, node);
340 for (i = 0; i < n_outs; ++i) {
341 const arch_register_t *reg = arch_irn_get_register(node, i);
342 const arch_register_req_t *req = arch_get_out_register_req(node, i);
343 if (req->cls == NULL)
345 fprintf(F, "reg #%d = %s\n", i, reg != NULL ? reg->name : "n/a");
348 fprintf(F, "flags =");
349 if (flags == arch_irn_flags_none) {
352 if (flags & arch_irn_flags_dont_spill) {
353 fprintf(F, " unspillable");
355 if (flags & arch_irn_flags_rematerializable) {
356 fprintf(F, " remat");
358 if (flags & arch_irn_flags_modify_flags) {
359 fprintf(F, " modify_flags");
362 fprintf(F, " (%d)\n", flags);
365 static const arch_register_req_t no_requirement = {
366 arch_register_req_type_none,
372 const arch_register_req_t *arch_no_register_req = &no_requirement;