2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Processor architecture specification.
9 * @author Sebastian Hack
24 #include "raw_bitset.h"
28 arch_register_req_t const arch_no_requirement = {
29 arch_register_req_type_none,
38 * Get the isa responsible for a node.
39 * @param irn The node to get the responsible isa for.
40 * @return The irn operations given by the responsible isa.
42 static const arch_irn_ops_t *get_irn_ops(const ir_node *irn)
45 irn = get_Proj_pred(irn);
46 assert(!is_Proj(irn));
49 ir_op *ops = get_irn_op(irn);
50 const arch_irn_ops_t *be_ops = get_op_ops(ops)->be_ops;
55 void arch_set_frame_offset(ir_node *irn, int offset)
57 const arch_irn_ops_t *ops = get_irn_ops(irn);
58 ops->set_frame_offset(irn, offset);
61 ir_entity *arch_get_frame_entity(const ir_node *irn)
63 const arch_irn_ops_t *ops = get_irn_ops(irn);
64 return ops->get_frame_entity(irn);
67 int arch_get_sp_bias(ir_node *irn)
69 const arch_irn_ops_t *ops = get_irn_ops(irn);
70 return ops->get_sp_bias(irn);
73 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
75 const arch_irn_ops_t *ops = get_irn_ops(irn);
77 if (ops->possible_memory_operand) {
78 return ops->possible_memory_operand(irn, i);
84 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
86 const arch_irn_ops_t *ops = get_irn_ops(irn);
87 ops->perform_memory_operand(irn, spill, i);
90 int arch_get_op_estimated_cost(const ir_node *irn)
92 const arch_irn_ops_t *ops = get_irn_ops(irn);
94 if (ops->get_op_estimated_cost) {
95 return ops->get_op_estimated_cost(irn);
101 static reg_out_info_t *get_out_info_n(const ir_node *node, unsigned pos)
103 const backend_info_t *info = be_get_info(node);
104 assert(pos < (unsigned)ARR_LEN(info->out_infos));
105 return &info->out_infos[pos];
109 const arch_register_t *arch_get_irn_register(const ir_node *node)
111 const reg_out_info_t *out = get_out_info(node);
115 const arch_register_t *arch_get_irn_register_out(const ir_node *node,
118 const reg_out_info_t *out = get_out_info_n(node, pos);
122 const arch_register_t *arch_get_irn_register_in(const ir_node *node, int pos)
124 ir_node *op = get_irn_n(node, pos);
125 return arch_get_irn_register(op);
128 void arch_set_irn_register_out(ir_node *node, unsigned pos,
129 const arch_register_t *reg)
131 reg_out_info_t *out = get_out_info_n(node, pos);
135 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
137 reg_out_info_t *out = get_out_info(node);
141 void arch_set_irn_flags(ir_node *node, arch_irn_flags_t flags)
143 backend_info_t *const info = be_get_info(node);
147 void arch_add_irn_flags(ir_node *node, arch_irn_flags_t flags)
149 backend_info_t *const info = be_get_info(node);
150 info->flags |= flags;
153 bool arch_reg_is_allocatable(const arch_register_req_t *req,
154 const arch_register_t *reg)
156 assert(req->type != arch_register_req_type_none);
157 if (req->cls != reg->reg_class)
159 if (reg->type & arch_register_type_virtual)
161 if (arch_register_req_is(req, limited))
162 return rbitset_is_set(req->limited, reg->index);
167 * Print information about a register requirement in human readable form
168 * @param F output stream/file
169 * @param req The requirements structure to format.
171 static void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
174 if (req == NULL || req->type == arch_register_req_type_none) {
179 fprintf(F, "%s", req->cls->name);
181 if (arch_register_req_is(req, limited)) {
182 unsigned n_regs = req->cls->n_regs;
185 fprintf(F, " limited to");
186 for (i = 0; i < n_regs; ++i) {
187 if (rbitset_is_set(req->limited, i)) {
188 const arch_register_t *reg = &req->cls->regs[i];
189 fprintf(F, " %s", reg->name);
194 if (arch_register_req_is(req, should_be_same)) {
195 const unsigned other = req->other_same;
198 fprintf(F, " same as");
199 for (i = 0; 1U << i <= other; ++i) {
200 if (other & (1U << i)) {
201 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
206 if (arch_register_req_is(req, must_be_different)) {
207 const unsigned other = req->other_different;
210 fprintf(F, " different from");
211 for (i = 0; 1U << i <= other; ++i) {
212 if (other & (1U << i)) {
213 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
218 if (req->width != 1) {
219 fprintf(F, " width:%d", req->width);
221 if (arch_register_req_is(req, aligned)) {
222 fprintf(F, " aligned");
224 if (arch_register_req_is(req, ignore)) {
225 fprintf(F, " ignore");
227 if (arch_register_req_is(req, produces_sp)) {
228 fprintf(F, " produces_sp");
232 void arch_dump_reqs_and_registers(FILE *F, const ir_node *node)
234 backend_info_t *const info = be_get_info(node);
235 int const n_ins = get_irn_arity(node);
236 /* don't fail on invalid graphs */
237 if (!info || (!info->in_reqs && n_ins != 0) || !info->out_infos) {
238 fprintf(F, "invalid register requirements!!!\n");
242 for (int i = 0; i < n_ins; ++i) {
243 const arch_register_req_t *req = arch_get_irn_register_req_in(node, i);
244 fprintf(F, "inreq #%d = ", i);
245 arch_dump_register_req(F, req, node);
248 be_foreach_out(node, o) {
249 const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
250 fprintf(F, "outreq #%u = ", o);
251 arch_dump_register_req(F, req, node);
252 const arch_register_t *reg = arch_get_irn_register_out(node, o);
253 fprintf(F, " [%s]\n", reg != NULL ? reg->name : "n/a");
256 fprintf(F, "flags =");
257 arch_irn_flags_t flags = arch_get_irn_flags(node);
258 if (flags == arch_irn_flags_none) {
261 if (flags & arch_irn_flags_dont_spill) {
262 fprintf(F, " unspillable");
264 if (flags & arch_irn_flags_rematerializable) {
265 fprintf(F, " remat");
267 if (flags & arch_irn_flags_modify_flags) {
268 fprintf(F, " modify_flags");
270 if (flags & arch_irn_flags_simple_jump) {
271 fprintf(F, " simple_jump");
273 if (flags & arch_irn_flags_not_scheduled) {
274 fprintf(F, " not_scheduled");
277 fprintf(F, " (0x%x)\n", (unsigned)flags);