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 arch_register_req_t const arch_no_requirement = {
43 arch_register_req_type_none,
51 /* Initialize the architecture environment struct. */
52 arch_env_t *arch_env_begin_codegeneration(const arch_isa_if_t *isa_if,
53 be_main_env_t *main_env)
55 arch_env_t *arch_env = isa_if->begin_codegeneration(main_env);
56 arch_env->main_env = main_env;
61 * Get the isa responsible for a node.
62 * @param irn The node to get the responsible isa for.
63 * @return The irn operations given by the responsible isa.
65 static const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
68 irn = get_Proj_pred(irn);
69 assert(!is_Proj(irn));
72 ir_op *ops = get_irn_op(irn);
73 const arch_irn_ops_t *be_ops = get_op_ops(ops)->be_ops;
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 int arch_get_sp_bias(ir_node *irn)
92 const arch_irn_ops_t *ops = get_irn_ops(irn);
93 return ops->get_sp_bias(irn);
96 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
98 const arch_irn_ops_t *ops = get_irn_ops(irn);
100 if (ops->possible_memory_operand) {
101 return ops->possible_memory_operand(irn, i);
107 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
109 const arch_irn_ops_t *ops = get_irn_ops(irn);
111 if (ops->perform_memory_operand) {
112 ops->perform_memory_operand(irn, spill, i);
118 int arch_get_op_estimated_cost(const ir_node *irn)
120 const arch_irn_ops_t *ops = get_irn_ops(irn);
122 if (ops->get_op_estimated_cost) {
123 return ops->get_op_estimated_cost(irn);
129 static reg_out_info_t *get_out_info(const ir_node *node)
132 const backend_info_t *info;
133 assert(get_irn_mode(node) != mode_T);
135 pos = get_Proj_proj(node);
136 node = get_Proj_pred(node);
139 info = be_get_info(node);
140 assert(pos < ARR_LEN(info->out_infos));
141 return &info->out_infos[pos];
144 static reg_out_info_t *get_out_info_n(const ir_node *node, unsigned pos)
146 const backend_info_t *info = be_get_info(node);
147 assert(!is_Proj(node));
148 assert(pos < (unsigned)ARR_LEN(info->out_infos));
149 return &info->out_infos[pos];
153 const arch_register_t *arch_get_irn_register(const ir_node *node)
155 const reg_out_info_t *out = get_out_info(node);
159 const arch_register_t *arch_get_irn_register_out(const ir_node *node,
162 const reg_out_info_t *out = get_out_info_n(node, pos);
166 const arch_register_t *arch_get_irn_register_in(const ir_node *node, int pos)
168 ir_node *op = get_irn_n(node, pos);
169 return arch_get_irn_register(op);
172 void arch_set_irn_register_out(ir_node *node, unsigned pos,
173 const arch_register_t *reg)
175 reg_out_info_t *out = get_out_info_n(node, pos);
179 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
181 reg_out_info_t *out = get_out_info(node);
185 const arch_register_req_t *arch_get_irn_register_req(const ir_node *node)
187 reg_out_info_t *out = get_out_info(node);
191 arch_irn_flags_t arch_get_irn_flags(const ir_node *node)
193 backend_info_t *info;
195 return arch_irn_flags_not_scheduled;
197 info = be_get_info(node);
201 void arch_set_irn_flags(ir_node *node, arch_irn_flags_t flags)
203 backend_info_t *info;
205 /* setting flags is only supported for instructions currently.
206 * (mainly because we found no use for it yet and saved the space for
207 * be_infos for them */
208 assert(!is_Proj(node));
209 info = be_get_info(node);
213 void arch_add_irn_flags(ir_node *node, arch_irn_flags_t flags)
215 backend_info_t *info;
216 assert(!is_Proj(node));
217 info = be_get_info(node);
218 info->flags |= flags;
221 bool arch_reg_is_allocatable(const arch_register_req_t *req,
222 const arch_register_t *reg)
224 assert(req->type != arch_register_req_type_none);
225 if (req->cls != reg->reg_class)
227 if (reg->type & arch_register_type_virtual)
229 if (req->type & arch_register_req_type_limited)
230 return rbitset_is_set(req->limited, reg->index);
234 void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
237 if (req == NULL || req->type == arch_register_req_type_none) {
242 fprintf(F, "%s", req->cls->name);
244 if (arch_register_req_is(req, limited)) {
245 unsigned n_regs = req->cls->n_regs;
248 fprintf(F, " limited to");
249 for (i = 0; i < n_regs; ++i) {
250 if (rbitset_is_set(req->limited, i)) {
251 const arch_register_t *reg = &req->cls->regs[i];
252 fprintf(F, " %s", reg->name);
257 if (arch_register_req_is(req, should_be_same)) {
258 const unsigned other = req->other_same;
261 fprintf(F, " same as");
262 for (i = 0; 1U << i <= other; ++i) {
263 if (other & (1U << i)) {
264 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
269 if (arch_register_req_is(req, must_be_different)) {
270 const unsigned other = req->other_different;
273 fprintf(F, " different from");
274 for (i = 0; 1U << i <= other; ++i) {
275 if (other & (1U << i)) {
276 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
281 if (req->width != 1) {
282 fprintf(F, " width:%d", req->width);
284 if (arch_register_req_is(req, aligned)) {
285 fprintf(F, " aligned");
287 if (arch_register_req_is(req, ignore)) {
288 fprintf(F, " ignore");
290 if (arch_register_req_is(req, produces_sp)) {
291 fprintf(F, " produces_sp");
295 void arch_dump_reqs_and_registers(FILE *F, const ir_node *node)
297 int n_ins = get_irn_arity(node);
298 for (int i = 0; i < n_ins; ++i) {
299 const arch_register_req_t *req = arch_get_irn_register_req_in(node, i);
300 fprintf(F, "inreq #%d = ", i);
301 arch_dump_register_req(F, req, node);
304 unsigned n_outs = arch_get_irn_n_outs(node);
305 for (unsigned o = 0; o < n_outs; ++o) {
306 const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
307 fprintf(F, "outreq #%u = ", o);
308 arch_dump_register_req(F, req, node);
311 for (unsigned o = 0; o < n_outs; ++o) {
312 const arch_register_t *reg = arch_get_irn_register_out(node, o);
313 const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
314 if (req->cls == NULL)
316 fprintf(F, "reg #%u = %s\n", o, reg != NULL ? reg->name : "n/a");
319 fprintf(F, "flags =");
320 arch_irn_flags_t flags = arch_get_irn_flags(node);
321 if (flags == arch_irn_flags_none) {
324 if (flags & arch_irn_flags_dont_spill) {
325 fprintf(F, " unspillable");
327 if (flags & arch_irn_flags_rematerializable) {
328 fprintf(F, " remat");
330 if (flags & arch_irn_flags_modify_flags) {
331 fprintf(F, " modify_flags");
333 if (flags & arch_irn_flags_simple_jump) {
334 fprintf(F, " simple_jump");
336 if (flags & arch_irn_flags_not_scheduled) {
337 fprintf(F, " not_scheduled");
340 fprintf(F, " (0x%x)\n", (unsigned)flags);