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,
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 const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
59 irn = get_Proj_pred(irn);
60 assert(!is_Proj(irn));
63 ir_op *ops = get_irn_op(irn);
64 const arch_irn_ops_t *be_ops = get_op_ops(ops)->be_ops;
69 void arch_set_frame_offset(ir_node *irn, int offset)
71 const arch_irn_ops_t *ops = get_irn_ops(irn);
72 ops->set_frame_offset(irn, offset);
75 ir_entity *arch_get_frame_entity(const ir_node *irn)
77 const arch_irn_ops_t *ops = get_irn_ops(irn);
78 return ops->get_frame_entity(irn);
81 int arch_get_sp_bias(ir_node *irn)
83 const arch_irn_ops_t *ops = get_irn_ops(irn);
84 return ops->get_sp_bias(irn);
87 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
89 const arch_irn_ops_t *ops = get_irn_ops(irn);
91 if (ops->possible_memory_operand) {
92 return ops->possible_memory_operand(irn, i);
98 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
100 const arch_irn_ops_t *ops = get_irn_ops(irn);
102 if (ops->perform_memory_operand) {
103 ops->perform_memory_operand(irn, spill, i);
109 int arch_get_op_estimated_cost(const ir_node *irn)
111 const arch_irn_ops_t *ops = get_irn_ops(irn);
113 if (ops->get_op_estimated_cost) {
114 return ops->get_op_estimated_cost(irn);
120 static reg_out_info_t *get_out_info_n(const ir_node *node, unsigned pos)
122 const backend_info_t *info = be_get_info(node);
123 assert(pos < (unsigned)ARR_LEN(info->out_infos));
124 return &info->out_infos[pos];
128 const arch_register_t *arch_get_irn_register(const ir_node *node)
130 const reg_out_info_t *out = get_out_info(node);
134 const arch_register_t *arch_get_irn_register_out(const ir_node *node,
137 const reg_out_info_t *out = get_out_info_n(node, pos);
141 const arch_register_t *arch_get_irn_register_in(const ir_node *node, int pos)
143 ir_node *op = get_irn_n(node, pos);
144 return arch_get_irn_register(op);
147 void arch_set_irn_register_out(ir_node *node, unsigned pos,
148 const arch_register_t *reg)
150 reg_out_info_t *out = get_out_info_n(node, pos);
154 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
156 reg_out_info_t *out = get_out_info(node);
160 void arch_set_irn_flags(ir_node *node, arch_irn_flags_t flags)
162 backend_info_t *const info = be_get_info(node);
166 void arch_add_irn_flags(ir_node *node, arch_irn_flags_t flags)
168 backend_info_t *const info = be_get_info(node);
169 info->flags |= flags;
172 bool arch_reg_is_allocatable(const arch_register_req_t *req,
173 const arch_register_t *reg)
175 assert(req->type != arch_register_req_type_none);
176 if (req->cls != reg->reg_class)
178 if (reg->type & arch_register_type_virtual)
180 if (arch_register_req_is(req, limited))
181 return rbitset_is_set(req->limited, reg->index);
186 * Print information about a register requirement in human readable form
187 * @param F output stream/file
188 * @param req The requirements structure to format.
190 static void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
193 if (req == NULL || req->type == arch_register_req_type_none) {
198 fprintf(F, "%s", req->cls->name);
200 if (arch_register_req_is(req, limited)) {
201 unsigned n_regs = req->cls->n_regs;
204 fprintf(F, " limited to");
205 for (i = 0; i < n_regs; ++i) {
206 if (rbitset_is_set(req->limited, i)) {
207 const arch_register_t *reg = &req->cls->regs[i];
208 fprintf(F, " %s", reg->name);
213 if (arch_register_req_is(req, should_be_same)) {
214 const unsigned other = req->other_same;
217 fprintf(F, " same as");
218 for (i = 0; 1U << i <= other; ++i) {
219 if (other & (1U << i)) {
220 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
225 if (arch_register_req_is(req, must_be_different)) {
226 const unsigned other = req->other_different;
229 fprintf(F, " different from");
230 for (i = 0; 1U << i <= other; ++i) {
231 if (other & (1U << i)) {
232 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
237 if (req->width != 1) {
238 fprintf(F, " width:%d", req->width);
240 if (arch_register_req_is(req, aligned)) {
241 fprintf(F, " aligned");
243 if (arch_register_req_is(req, ignore)) {
244 fprintf(F, " ignore");
246 if (arch_register_req_is(req, produces_sp)) {
247 fprintf(F, " produces_sp");
251 void arch_dump_reqs_and_registers(FILE *F, const ir_node *node)
253 backend_info_t *info = be_get_info(node);
254 /* don't fail on invalid graphs */
255 if (info == NULL || info->in_reqs == NULL || info->out_infos == NULL) {
256 fprintf(F, "invalid register requirements!!!\n");
260 int n_ins = get_irn_arity(node);
261 for (int i = 0; i < n_ins; ++i) {
262 const arch_register_req_t *req = arch_get_irn_register_req_in(node, i);
263 fprintf(F, "inreq #%d = ", i);
264 arch_dump_register_req(F, req, node);
267 be_foreach_out(node, o) {
268 const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
269 fprintf(F, "outreq #%u = ", o);
270 arch_dump_register_req(F, req, node);
271 const arch_register_t *reg = arch_get_irn_register_out(node, o);
272 fprintf(F, " [%s]\n", reg != NULL ? reg->name : "n/a");
275 fprintf(F, "flags =");
276 arch_irn_flags_t flags = arch_get_irn_flags(node);
277 if (flags == arch_irn_flags_none) {
280 if (flags & arch_irn_flags_dont_spill) {
281 fprintf(F, " unspillable");
283 if (flags & arch_irn_flags_rematerializable) {
284 fprintf(F, " remat");
286 if (flags & arch_irn_flags_modify_flags) {
287 fprintf(F, " modify_flags");
289 if (flags & arch_irn_flags_simple_jump) {
290 fprintf(F, " simple_jump");
292 if (flags & arch_irn_flags_not_scheduled) {
293 fprintf(F, " not_scheduled");
296 fprintf(F, " (0x%x)\n", (unsigned)flags);