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)
44 ir_op const *const op = get_irn_op(irn);
45 arch_irn_ops_t const *const be_ops = get_op_ops(op)->be_ops;
50 void arch_set_frame_offset(ir_node *irn, int offset)
52 const arch_irn_ops_t *ops = get_irn_ops(irn);
53 ops->set_frame_offset(irn, offset);
56 ir_entity *arch_get_frame_entity(const ir_node *irn)
58 const arch_irn_ops_t *ops = get_irn_ops(irn);
59 return ops->get_frame_entity(irn);
62 int arch_get_sp_bias(ir_node *irn)
64 const arch_irn_ops_t *ops = get_irn_ops(irn);
65 return ops->get_sp_bias(irn);
68 int arch_possible_memory_operand(const ir_node *irn, unsigned int i)
70 const arch_irn_ops_t *ops = get_irn_ops(irn);
72 if (ops->possible_memory_operand) {
73 return ops->possible_memory_operand(irn, i);
79 void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i)
81 const arch_irn_ops_t *ops = get_irn_ops(irn);
82 ops->perform_memory_operand(irn, spill, i);
85 int arch_get_op_estimated_cost(const ir_node *irn)
87 const arch_irn_ops_t *ops = get_irn_ops(irn);
89 if (ops->get_op_estimated_cost) {
90 return ops->get_op_estimated_cost(irn);
96 static reg_out_info_t *get_out_info_n(const ir_node *node, unsigned pos)
98 const backend_info_t *info = be_get_info(node);
99 assert(pos < (unsigned)ARR_LEN(info->out_infos));
100 return &info->out_infos[pos];
104 const arch_register_t *arch_get_irn_register(const ir_node *node)
106 const reg_out_info_t *out = get_out_info(node);
110 const arch_register_t *arch_get_irn_register_out(const ir_node *node,
113 const reg_out_info_t *out = get_out_info_n(node, pos);
117 const arch_register_t *arch_get_irn_register_in(const ir_node *node, int pos)
119 ir_node *op = get_irn_n(node, pos);
120 return arch_get_irn_register(op);
123 void arch_set_irn_register_out(ir_node *node, unsigned pos,
124 const arch_register_t *reg)
126 reg_out_info_t *out = get_out_info_n(node, pos);
130 void arch_set_irn_register(ir_node *node, const arch_register_t *reg)
132 reg_out_info_t *out = get_out_info(node);
136 void arch_set_irn_flags(ir_node *node, arch_irn_flags_t flags)
138 backend_info_t *const info = be_get_info(node);
142 void arch_add_irn_flags(ir_node *node, arch_irn_flags_t flags)
144 backend_info_t *const info = be_get_info(node);
145 info->flags |= flags;
148 bool arch_reg_is_allocatable(const arch_register_req_t *req,
149 const arch_register_t *reg)
151 assert(req->type != arch_register_req_type_none);
152 if (req->cls != reg->reg_class)
154 if (reg->type & arch_register_type_virtual)
156 if (arch_register_req_is(req, limited))
157 return rbitset_is_set(req->limited, reg->index);
162 * Print information about a register requirement in human readable form
163 * @param F output stream/file
164 * @param req The requirements structure to format.
166 static void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
169 if (req == NULL || req->type == arch_register_req_type_none) {
174 fprintf(F, "%s", req->cls->name);
176 if (arch_register_req_is(req, limited)) {
177 unsigned n_regs = req->cls->n_regs;
180 fprintf(F, " limited to");
181 for (i = 0; i < n_regs; ++i) {
182 if (rbitset_is_set(req->limited, i)) {
183 const arch_register_t *reg = &req->cls->regs[i];
184 fprintf(F, " %s", reg->name);
189 if (arch_register_req_is(req, should_be_same)) {
190 const unsigned other = req->other_same;
193 fprintf(F, " same as");
194 for (i = 0; 1U << i <= other; ++i) {
195 if (other & (1U << i)) {
196 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
201 if (arch_register_req_is(req, must_be_different)) {
202 const unsigned other = req->other_different;
205 fprintf(F, " different from");
206 for (i = 0; 1U << i <= other; ++i) {
207 if (other & (1U << i)) {
208 ir_fprintf(F, " #%d (%+F)", i, get_irn_n(skip_Proj_const(node), i));
213 if (req->width != 1) {
214 fprintf(F, " width:%d", req->width);
216 if (arch_register_req_is(req, aligned)) {
217 fprintf(F, " aligned");
219 if (arch_register_req_is(req, ignore)) {
220 fprintf(F, " ignore");
222 if (arch_register_req_is(req, produces_sp)) {
223 fprintf(F, " produces_sp");
227 void arch_dump_reqs_and_registers(FILE *F, const ir_node *node)
229 backend_info_t *const info = be_get_info(node);
230 int const n_ins = get_irn_arity(node);
231 /* don't fail on invalid graphs */
232 if (!info || (!info->in_reqs && n_ins != 0) || !info->out_infos) {
233 fprintf(F, "invalid register requirements!!!\n");
237 for (int i = 0; i < n_ins; ++i) {
238 const arch_register_req_t *req = arch_get_irn_register_req_in(node, i);
239 fprintf(F, "inreq #%d = ", i);
240 arch_dump_register_req(F, req, node);
243 be_foreach_out(node, o) {
244 const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
245 fprintf(F, "outreq #%u = ", o);
246 arch_dump_register_req(F, req, node);
247 const arch_register_t *reg = arch_get_irn_register_out(node, o);
248 fprintf(F, " [%s]\n", reg != NULL ? reg->name : "n/a");
251 fprintf(F, "flags =");
252 arch_irn_flags_t flags = arch_get_irn_flags(node);
253 if (flags == arch_irn_flags_none) {
256 if (flags & arch_irn_flags_dont_spill) {
257 fprintf(F, " unspillable");
259 if (flags & arch_irn_flags_rematerializable) {
260 fprintf(F, " remat");
262 if (flags & arch_irn_flags_modify_flags) {
263 fprintf(F, " modify_flags");
265 if (flags & arch_irn_flags_simple_jump) {
266 fprintf(F, " simple_jump");
268 if (flags & arch_irn_flags_not_scheduled) {
269 fprintf(F, " not_scheduled");
272 fprintf(F, " (0x%x)\n", (unsigned)flags);