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_n(const ir_node *node, unsigned pos)
131 const backend_info_t *info = be_get_info(node);
132 assert(pos < (unsigned)ARR_LEN(info->out_infos));
133 return &info->out_infos[pos];
137 const arch_register_t *arch_get_irn_register(const ir_node *node)
139 const reg_out_info_t *out = get_out_info(node);
143 const arch_register_t *arch_get_irn_register_out(const ir_node *node,
146 const reg_out_info_t *out = get_out_info_n(node, pos);
150 const arch_register_t *arch_get_irn_register_in(const ir_node *node, int pos)
152 ir_node *op = get_irn_n(node, pos);
153 return arch_get_irn_register(op);
156 void arch_set_irn_register_out(ir_node *node, unsigned pos,
157 const arch_register_t *reg)
159 reg_out_info_t *out = get_out_info_n(node, pos);
163 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
165 reg_out_info_t *out = get_out_info(node);
169 void arch_set_irn_flags(ir_node *node, arch_irn_flags_t flags)
171 backend_info_t *const info = be_get_info(node);
175 void arch_add_irn_flags(ir_node *node, arch_irn_flags_t flags)
177 backend_info_t *const info = be_get_info(node);
178 info->flags |= flags;
181 bool arch_reg_is_allocatable(const arch_register_req_t *req,
182 const arch_register_t *reg)
184 assert(req->type != arch_register_req_type_none);
185 if (req->cls != reg->reg_class)
187 if (reg->type & arch_register_type_virtual)
189 if (arch_register_req_is(req, limited))
190 return rbitset_is_set(req->limited, reg->index);
195 * Print information about a register requirement in human readable form
196 * @param F output stream/file
197 * @param req The requirements structure to format.
199 static void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
202 if (req == NULL || req->type == arch_register_req_type_none) {
207 fprintf(F, "%s", req->cls->name);
209 if (arch_register_req_is(req, limited)) {
210 unsigned n_regs = req->cls->n_regs;
213 fprintf(F, " limited to");
214 for (i = 0; i < n_regs; ++i) {
215 if (rbitset_is_set(req->limited, i)) {
216 const arch_register_t *reg = &req->cls->regs[i];
217 fprintf(F, " %s", reg->name);
222 if (arch_register_req_is(req, should_be_same)) {
223 const unsigned other = req->other_same;
226 fprintf(F, " same as");
227 for (i = 0; 1U << i <= other; ++i) {
228 if (other & (1U << i)) {
229 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
234 if (arch_register_req_is(req, must_be_different)) {
235 const unsigned other = req->other_different;
238 fprintf(F, " different from");
239 for (i = 0; 1U << i <= other; ++i) {
240 if (other & (1U << i)) {
241 ir_fprintf(F, " %+F", get_irn_n(skip_Proj_const(node), i));
246 if (req->width != 1) {
247 fprintf(F, " width:%d", req->width);
249 if (arch_register_req_is(req, aligned)) {
250 fprintf(F, " aligned");
252 if (arch_register_req_is(req, ignore)) {
253 fprintf(F, " ignore");
255 if (arch_register_req_is(req, produces_sp)) {
256 fprintf(F, " produces_sp");
260 void arch_dump_reqs_and_registers(FILE *F, const ir_node *node)
262 backend_info_t *info = be_get_info(node);
263 /* don't fail on invalid graphs */
264 if (info == NULL || info->in_reqs == NULL || info->out_infos == NULL) {
265 fprintf(F, "invalid register requirements!!!\n");
269 int n_ins = get_irn_arity(node);
270 for (int i = 0; i < n_ins; ++i) {
271 const arch_register_req_t *req = arch_get_irn_register_req_in(node, i);
272 fprintf(F, "inreq #%d = ", i);
273 arch_dump_register_req(F, req, node);
276 unsigned n_outs = arch_get_irn_n_outs(node);
277 for (unsigned o = 0; o < n_outs; ++o) {
278 const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
279 fprintf(F, "outreq #%u = ", o);
280 arch_dump_register_req(F, req, node);
283 for (unsigned o = 0; o < n_outs; ++o) {
284 const arch_register_t *reg = arch_get_irn_register_out(node, o);
285 fprintf(F, "reg #%u = %s\n", o, reg != NULL ? reg->name : "n/a");
288 fprintf(F, "flags =");
289 arch_irn_flags_t flags = arch_get_irn_flags(node);
290 if (flags == arch_irn_flags_none) {
293 if (flags & arch_irn_flags_dont_spill) {
294 fprintf(F, " unspillable");
296 if (flags & arch_irn_flags_rematerializable) {
297 fprintf(F, " remat");
299 if (flags & arch_irn_flags_modify_flags) {
300 fprintf(F, " modify_flags");
302 if (flags & arch_irn_flags_simple_jump) {
303 fprintf(F, " simple_jump");
305 if (flags & arch_irn_flags_not_scheduled) {
306 fprintf(F, " not_scheduled");
309 fprintf(F, " (0x%x)\n", (unsigned)flags);