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)
54 arch_env_t *arch_env = isa_if->begin_codegeneration();
59 * Get the isa responsible for a node.
60 * @param irn The node to get the responsible isa for.
61 * @return The irn operations given by the responsible isa.
63 static const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
66 irn = get_Proj_pred(irn);
67 assert(!is_Proj(irn));
70 ir_op *ops = get_irn_op(irn);
71 const arch_irn_ops_t *be_ops = get_op_ops(ops)->be_ops;
76 void arch_set_frame_offset(ir_node *irn, int offset)
78 const arch_irn_ops_t *ops = get_irn_ops(irn);
79 ops->set_frame_offset(irn, offset);
82 ir_entity *arch_get_frame_entity(const ir_node *irn)
84 const arch_irn_ops_t *ops = get_irn_ops(irn);
85 return ops->get_frame_entity(irn);
88 int arch_get_sp_bias(ir_node *irn)
90 const arch_irn_ops_t *ops = get_irn_ops(irn);
91 return ops->get_sp_bias(irn);
94 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
96 const arch_irn_ops_t *ops = get_irn_ops(irn);
98 if (ops->possible_memory_operand) {
99 return ops->possible_memory_operand(irn, i);
105 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
107 const arch_irn_ops_t *ops = get_irn_ops(irn);
109 if (ops->perform_memory_operand) {
110 ops->perform_memory_operand(irn, spill, i);
116 int arch_get_op_estimated_cost(const ir_node *irn)
118 const arch_irn_ops_t *ops = get_irn_ops(irn);
120 if (ops->get_op_estimated_cost) {
121 return ops->get_op_estimated_cost(irn);
127 static reg_out_info_t *get_out_info_n(const ir_node *node, unsigned pos)
129 const backend_info_t *info = be_get_info(node);
130 assert(pos < (unsigned)ARR_LEN(info->out_infos));
131 return &info->out_infos[pos];
135 const arch_register_t *arch_get_irn_register(const ir_node *node)
137 const reg_out_info_t *out = get_out_info(node);
141 const arch_register_t *arch_get_irn_register_out(const ir_node *node,
144 const reg_out_info_t *out = get_out_info_n(node, pos);
148 const arch_register_t *arch_get_irn_register_in(const ir_node *node, int pos)
150 ir_node *op = get_irn_n(node, pos);
151 return arch_get_irn_register(op);
154 void arch_set_irn_register_out(ir_node *node, unsigned pos,
155 const arch_register_t *reg)
157 reg_out_info_t *out = get_out_info_n(node, pos);
161 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
163 reg_out_info_t *out = get_out_info(node);
167 void arch_set_irn_flags(ir_node *node, arch_irn_flags_t flags)
169 backend_info_t *const info = be_get_info(node);
173 void arch_add_irn_flags(ir_node *node, arch_irn_flags_t flags)
175 backend_info_t *const info = be_get_info(node);
176 info->flags |= flags;
179 bool arch_reg_is_allocatable(const arch_register_req_t *req,
180 const arch_register_t *reg)
182 assert(req->type != arch_register_req_type_none);
183 if (req->cls != reg->reg_class)
185 if (reg->type & arch_register_type_virtual)
187 if (arch_register_req_is(req, limited))
188 return rbitset_is_set(req->limited, reg->index);
193 * Print information about a register requirement in human readable form
194 * @param F output stream/file
195 * @param req The requirements structure to format.
197 static void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
200 if (req == NULL || req->type == arch_register_req_type_none) {
205 fprintf(F, "%s", req->cls->name);
207 if (arch_register_req_is(req, limited)) {
208 unsigned n_regs = req->cls->n_regs;
211 fprintf(F, " limited to");
212 for (i = 0; i < n_regs; ++i) {
213 if (rbitset_is_set(req->limited, i)) {
214 const arch_register_t *reg = &req->cls->regs[i];
215 fprintf(F, " %s", reg->name);
220 if (arch_register_req_is(req, should_be_same)) {
221 const unsigned other = req->other_same;
224 fprintf(F, " same as");
225 for (i = 0; 1U << i <= other; ++i) {
226 if (other & (1U << i)) {
227 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
232 if (arch_register_req_is(req, must_be_different)) {
233 const unsigned other = req->other_different;
236 fprintf(F, " different from");
237 for (i = 0; 1U << i <= other; ++i) {
238 if (other & (1U << i)) {
239 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
244 if (req->width != 1) {
245 fprintf(F, " width:%d", req->width);
247 if (arch_register_req_is(req, aligned)) {
248 fprintf(F, " aligned");
250 if (arch_register_req_is(req, ignore)) {
251 fprintf(F, " ignore");
253 if (arch_register_req_is(req, produces_sp)) {
254 fprintf(F, " produces_sp");
258 void arch_dump_reqs_and_registers(FILE *F, const ir_node *node)
260 backend_info_t *info = be_get_info(node);
261 /* don't fail on invalid graphs */
262 if (info == NULL || info->in_reqs == NULL || info->out_infos == NULL) {
263 fprintf(F, "invalid register requirements!!!\n");
267 int n_ins = get_irn_arity(node);
268 for (int i = 0; i < n_ins; ++i) {
269 const arch_register_req_t *req = arch_get_irn_register_req_in(node, i);
270 fprintf(F, "inreq #%d = ", i);
271 arch_dump_register_req(F, req, node);
274 be_foreach_out(node, o) {
275 const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
276 fprintf(F, "outreq #%u = ", o);
277 arch_dump_register_req(F, req, node);
278 const arch_register_t *reg = arch_get_irn_register_out(node, o);
279 fprintf(F, " [%s]\n", reg != NULL ? reg->name : "n/a");
282 fprintf(F, "flags =");
283 arch_irn_flags_t flags = arch_get_irn_flags(node);
284 if (flags == arch_irn_flags_none) {
287 if (flags & arch_irn_flags_dont_spill) {
288 fprintf(F, " unspillable");
290 if (flags & arch_irn_flags_rematerializable) {
291 fprintf(F, " remat");
293 if (flags & arch_irn_flags_modify_flags) {
294 fprintf(F, " modify_flags");
296 if (flags & arch_irn_flags_simple_jump) {
297 fprintf(F, " simple_jump");
299 if (flags & arch_irn_flags_not_scheduled) {
300 fprintf(F, " not_scheduled");
303 fprintf(F, " (0x%x)\n", (unsigned)flags);