3 * File name: ir/be/benode.c
4 * Purpose: Backend node support for generic backend nodes.
5 * Author: Sebastian Hack
6 * Modified by: Michael Beck, Matthias Braun
9 * Copyright: (c) 1998-2007 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 * @author Sebastian Hack
18 * Backend node support for generic backend nodes.
19 * This file provides Perm, Copy, Spill and Reload nodes.
35 #include "bitfiddle.h"
36 #include "raw_bitset.h"
48 #include "besched_t.h"
53 #define OUT_POS(x) (-((x) + 1))
55 /* Sometimes we want to put const nodes into get_irn_generic_attr ... */
56 #define get_irn_attr(irn) get_irn_generic_attr((ir_node *) (irn))
58 static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
61 arch_register_req_t req;
62 arch_irn_flags_t flags;
66 const arch_register_t *reg;
71 /** The generic be nodes attribute type. */
73 be_reg_data_t *reg_data;
76 /** The be_Return nodes attribute type. */
78 be_node_attr_t node_attr;
79 int num_ret_vals; /**< number of return values */
82 /** The be_Stack attribute type. */
84 be_node_attr_t node_attr;
85 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
88 /** The be_Frame attribute type. */
90 be_node_attr_t node_attr;
95 /** The be_Call attribute type. */
97 be_node_attr_t node_attr;
98 ir_entity *ent; /**< The called entity if this is a static call. */
99 ir_type *call_tp; /**< The call type, copied from the original Call node. */
103 be_node_attr_t node_attr;
104 ir_entity **in_entities;
105 ir_entity **out_entities;
111 ir_op *op_be_MemPerm;
114 ir_op *op_be_CopyKeep;
121 ir_op *op_be_RegParams;
122 ir_op *op_be_StackParam;
123 ir_op *op_be_FrameAddr;
124 ir_op *op_be_FrameLoad;
125 ir_op *op_be_FrameStore;
126 ir_op *op_be_Barrier;
128 static int beo_base = -1;
130 static const ir_op_ops be_node_op_ops;
132 #define N irop_flag_none
133 #define L irop_flag_labeled
134 #define C irop_flag_commutative
135 #define X irop_flag_cfopcode
136 #define I irop_flag_ip_cfopcode
137 #define F irop_flag_fragile
138 #define Y irop_flag_forking
139 #define H irop_flag_highlevel
140 #define c irop_flag_constlike
141 #define K irop_flag_keep
142 #define M irop_flag_machine
146 * Compare two node attributes.
148 * @return zero if both attributes are identically
150 static int cmp_node_attr(be_node_attr_t *a, be_node_attr_t *b) {
153 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
156 len = ARR_LEN(a->reg_data);
157 for (i = 0; i < len; ++i) {
158 if (a->reg_data[i].reg != b->reg_data[i].reg ||
159 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
160 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
168 * Compare the attributes of two FrameAddr nodes.
170 * @return zero if both attributes are identically
172 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
173 be_frame_attr_t *a_attr = get_irn_attr(a);
174 be_frame_attr_t *b_attr = get_irn_attr(b);
176 if (a_attr->ent == b_attr->ent && a_attr->offset == b_attr->offset)
177 return cmp_node_attr(&a_attr->node_attr, &b_attr->node_attr);
181 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
184 be_node_attr_t *attr;
187 assert(is_be_node(node));
188 attr = get_irn_attr(node);
194 assert(idx < get_irn_arity(node));
196 assert(idx < ARR_LEN(attr->reg_data));
197 rd = &attr->reg_data[idx];
199 return pos < 0 ? &rd->req : &rd->in_req;
202 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
204 be_req_t *bereq = get_be_req(node, pos);
208 void be_node_init(void) {
209 static int inited = 0;
216 /* Acquire all needed opcodes. */
217 beo_base = get_next_ir_opcodes(beo_Last - 1);
219 op_be_Spill = new_ir_op(beo_base + beo_Spill, "be_Spill", op_pin_state_mem_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
220 op_be_Reload = new_ir_op(beo_base + beo_Reload, "be_Reload", op_pin_state_mem_pinned, N, oparity_zero, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
221 op_be_Perm = new_ir_op(beo_base + beo_Perm, "be_Perm", op_pin_state_pinned, N, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
222 op_be_MemPerm = new_ir_op(beo_base + beo_MemPerm, "be_MemPerm", op_pin_state_mem_pinned, N, oparity_variable, 0, sizeof(be_memperm_attr_t), &be_node_op_ops);
223 op_be_Copy = new_ir_op(beo_base + beo_Copy, "be_Copy", op_pin_state_floats, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
224 op_be_Keep = new_ir_op(beo_base + beo_Keep, "be_Keep", op_pin_state_pinned, K, oparity_dynamic, 0, sizeof(be_node_attr_t), &be_node_op_ops);
225 op_be_CopyKeep = new_ir_op(beo_base + beo_CopyKeep, "be_CopyKeep", op_pin_state_pinned, K, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
226 op_be_Call = new_ir_op(beo_base + beo_Call, "be_Call", op_pin_state_pinned, F, oparity_variable, 0, sizeof(be_call_attr_t), &be_node_op_ops);
227 op_be_Return = new_ir_op(beo_base + beo_Return, "be_Return", op_pin_state_pinned, X, oparity_dynamic, 0, sizeof(be_return_attr_t), &be_node_op_ops);
228 op_be_AddSP = new_ir_op(beo_base + beo_AddSP, "be_AddSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
229 op_be_SubSP = new_ir_op(beo_base + beo_SubSP, "be_SubSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
230 op_be_SetSP = new_ir_op(beo_base + beo_SetSP, "be_SetSP", op_pin_state_pinned, N, oparity_binary, 0, sizeof(be_stack_attr_t), &be_node_op_ops);
231 op_be_IncSP = new_ir_op(beo_base + beo_IncSP, "be_IncSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_stack_attr_t), &be_node_op_ops);
232 op_be_RegParams = new_ir_op(beo_base + beo_RegParams, "be_RegParams", op_pin_state_pinned, N, oparity_zero, 0, sizeof(be_node_attr_t), &be_node_op_ops);
233 op_be_StackParam = new_ir_op(beo_base + beo_StackParam, "be_StackParam", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
234 op_be_FrameAddr = new_ir_op(beo_base + beo_FrameAddr, "be_FrameAddr", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
235 op_be_FrameLoad = new_ir_op(beo_base + beo_FrameLoad, "be_FrameLoad", op_pin_state_pinned, N, oparity_any, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
236 op_be_FrameStore = new_ir_op(beo_base + beo_FrameStore, "be_FrameStore", op_pin_state_pinned, N, oparity_any, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
237 op_be_Barrier = new_ir_op(beo_base + beo_Barrier, "be_Barrier", op_pin_state_pinned, N, oparity_dynamic, 0, sizeof(be_node_attr_t), &be_node_op_ops);
239 set_op_tag(op_be_Spill, &be_node_tag);
240 set_op_tag(op_be_Reload, &be_node_tag);
241 set_op_tag(op_be_Perm, &be_node_tag);
242 set_op_tag(op_be_MemPerm, &be_node_tag);
243 set_op_tag(op_be_Copy, &be_node_tag);
244 set_op_tag(op_be_Keep, &be_node_tag);
245 set_op_tag(op_be_CopyKeep, &be_node_tag);
246 set_op_tag(op_be_Call, &be_node_tag);
247 set_op_tag(op_be_Return, &be_node_tag);
248 set_op_tag(op_be_AddSP, &be_node_tag);
249 set_op_tag(op_be_SubSP, &be_node_tag);
250 set_op_tag(op_be_SetSP, &be_node_tag);
251 set_op_tag(op_be_IncSP, &be_node_tag);
252 set_op_tag(op_be_RegParams, &be_node_tag);
253 set_op_tag(op_be_StackParam, &be_node_tag);
254 set_op_tag(op_be_FrameLoad, &be_node_tag);
255 set_op_tag(op_be_FrameStore, &be_node_tag);
256 set_op_tag(op_be_FrameAddr, &be_node_tag);
257 set_op_tag(op_be_Barrier, &be_node_tag);
259 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
263 * Initializes the generic attribute of all be nodes and return ir.
265 static void *init_node_attr(ir_node *node, int max_reg_data)
267 ir_graph *irg = get_irn_irg(node);
268 struct obstack *obst = get_irg_obstack(irg);
269 be_node_attr_t *a = get_irn_attr(node);
271 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
273 if(max_reg_data >= 0) {
274 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
275 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
277 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
283 static void add_register_req(ir_node *node)
285 be_node_attr_t *a = get_irn_attr(node);
286 be_reg_data_t regreq;
287 memset(®req, 0, sizeof(regreq));
288 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
291 int is_be_node(const ir_node *irn)
293 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
296 be_opcode_t be_get_irn_opcode(const ir_node *irn)
298 return is_be_node(irn) ? get_irn_opcode(irn) - beo_base : beo_NoBeOp;
302 * Skip Proj nodes and return their Proj numbers.
304 * If *node is a Proj or Proj(Proj) node, skip it.
306 * @param node points to the node to be skipped
308 * @return 0 if *node was no Proj node, its Proj number else.
310 static int redir_proj(const ir_node **node)
312 const ir_node *n = *node;
317 *node = irn = get_Proj_pred(n);
319 assert(get_irn_mode(irn) == mode_T);
320 *node = get_Proj_pred(irn);
322 return get_Proj_proj(n);
328 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
330 be_node_attr_t *attr;
334 pos = get_Proj_proj(node);
335 node = get_Proj_pred(node);
338 assert(is_be_node(node));
339 attr = get_irn_attr(node);
340 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
342 return &attr->reg_data[pos];
346 be_node_set_irn_reg(const void *_self, ir_node *irn, const arch_register_t *reg)
348 be_reg_data_t *r = retrieve_reg_data(irn);
352 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
353 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
361 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
362 a = init_node_attr(res, 2);
366 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
367 be_node_set_reg_class(res, be_pos_Spill_val, cls);
371 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
372 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
379 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
381 init_node_attr(res, 2);
382 be_node_set_reg_class(res, -1, cls);
383 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
384 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
388 ir_node *be_get_Reload_mem(const ir_node *irn)
390 assert(be_is_Reload(irn));
391 return get_irn_n(irn, be_pos_Reload_mem);
394 ir_node *be_get_Reload_frame(const ir_node *irn)
396 assert(be_is_Reload(irn));
397 return get_irn_n(irn, be_pos_Reload_frame);
400 ir_node *be_get_Spill_val(const ir_node *irn)
402 assert(be_is_Spill(irn));
403 return get_irn_n(irn, be_pos_Spill_val);
406 ir_node *be_get_Spill_frame(const ir_node *irn)
408 assert(be_is_Spill(irn));
409 return get_irn_n(irn, be_pos_Spill_frame);
412 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
415 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
416 init_node_attr(irn, n);
417 for(i = 0; i < n; ++i) {
418 be_node_set_reg_class(irn, i, cls);
419 be_node_set_reg_class(irn, OUT_POS(i), cls);
425 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
428 ir_node *frame = get_irg_frame(irg);
429 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
431 const arch_register_t *sp = arch_env->isa->sp;
432 be_memperm_attr_t *attr;
435 real_in = alloca((n+1) * sizeof(real_in[0]));
437 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
439 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
441 init_node_attr(irn, n + 1);
442 be_node_set_reg_class(irn, 0, sp->reg_class);
443 for(i = 0; i < n; ++i) {
444 be_node_set_reg_class(irn, i + 1, cls_frame);
445 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
448 attr = get_irn_attr(irn);
450 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
451 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
452 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
453 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
459 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
463 arch_register_req_t *req;
466 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
467 init_node_attr(res, 1);
468 be_node_set_reg_class(res, 0, cls);
469 be_node_set_reg_class(res, OUT_POS(0), cls);
471 req = get_req(res, OUT_POS(0));
473 req->type = arch_register_req_type_should_be_same;
479 ir_node *be_get_Copy_op(const ir_node *cpy) {
480 return get_irn_n(cpy, be_pos_Copy_op);
483 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
484 set_irn_n(cpy, be_pos_Copy_op, op);
487 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
492 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
493 init_node_attr(res, -1);
495 for(i = 0; i < n; ++i) {
496 add_irn_n(res, in[i]);
497 add_register_req(res);
498 be_node_set_reg_class(res, i, cls);
505 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
509 assert(be_is_Keep(keep));
510 n = add_irn_n(keep, node);
511 add_register_req(keep);
512 be_node_set_reg_class(keep, n, cls);
515 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
516 int n_outs, int n, ir_node *in[], ir_type *call_tp)
519 int real_n = be_pos_Call_first_arg + n;
523 NEW_ARR_A(ir_node *, real_in, real_n);
524 real_in[be_pos_Call_mem] = mem;
525 real_in[be_pos_Call_sp] = sp;
526 real_in[be_pos_Call_ptr] = ptr;
527 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
529 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
530 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
532 a->call_tp = call_tp;
536 /* Gets the call entity or NULL if this is no static call. */
537 ir_entity *be_Call_get_entity(const ir_node *call) {
538 be_call_attr_t *a = get_irn_attr(call);
539 assert(be_is_Call(call));
543 /* Sets the call entity. */
544 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
545 be_call_attr_t *a = get_irn_attr(call);
546 assert(be_is_Call(call));
550 /* Gets the call type. */
551 ir_type *be_Call_get_type(ir_node *call) {
552 be_call_attr_t *a = get_irn_attr(call);
553 assert(be_is_Call(call));
557 /* Sets the call type. */
558 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
559 be_call_attr_t *a = get_irn_attr(call);
560 assert(be_is_Call(call));
561 a->call_tp = call_tp;
564 /* Construct a new be_Return. */
565 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
566 int n, ir_node *in[])
572 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
573 init_node_attr(res, -1);
574 for(i = 0; i < n; ++i) {
575 add_irn_n(res, in[i]);
576 add_register_req(res);
579 a = get_irn_attr(res);
580 a->num_ret_vals = n_res;
585 /* Returns the number of real returns values */
586 int be_Return_get_n_rets(ir_node *ret)
588 be_return_attr_t *a = get_irn_attr(ret);
589 return a->num_ret_vals;
592 int be_Return_append_node(ir_node *ret, ir_node *node)
596 pos = add_irn_n(ret, node);
597 add_register_req(ret);
602 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
609 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
610 a = init_node_attr(irn, 1);
613 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
615 /* Set output constraint to stack register. */
616 be_node_set_reg_class(irn, 0, sp->reg_class);
617 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
618 be_node_set_irn_reg(NULL, irn, sp);
623 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
627 ir_node *in[be_pos_AddSP_last];
629 in[be_pos_AddSP_old_sp] = old_sp;
630 in[be_pos_AddSP_size] = sz;
632 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
633 a = init_node_attr(irn, be_pos_AddSP_last);
635 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_res), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
637 /* Set output constraint to stack register. */
638 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
639 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
640 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_res), sp);
641 a->reg_data[pn_be_AddSP_res].reg = sp;
646 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
650 ir_node *in[be_pos_SubSP_last];
652 in[be_pos_SubSP_old_sp] = old_sp;
653 in[be_pos_SubSP_size] = sz;
655 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
656 a = init_node_attr(irn, be_pos_SubSP_last);
658 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_res), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
660 /* Set output constraint to stack register. */
661 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
662 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
663 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_res), sp);
664 a->reg_data[pn_be_SubSP_res].reg = sp;
669 ir_node *be_new_SetSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *op, ir_node *mem)
678 irn = new_ir_node(NULL, irg, bl, op_be_SetSP, get_irn_mode(old_sp), 3, in);
679 a = init_node_attr(irn, 3);
681 be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
683 /* Set output constraint to stack register. */
684 be_set_constr_single_reg(irn, OUT_POS(0), sp);
685 be_node_set_reg_class(irn, be_pos_AddSP_size, sp->reg_class);
686 be_node_set_reg_class(irn, be_pos_AddSP_old_sp, sp->reg_class);
691 ir_node *be_new_StackParam(const arch_register_class_t *cls, const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_mode *mode, ir_node *frame_pointer, ir_entity *ent)
697 in[0] = frame_pointer;
698 irn = new_ir_node(NULL, irg, bl, op_be_StackParam, mode, 1, in);
699 a = init_node_attr(irn, 1);
702 be_node_set_reg_class(irn, 0, cls_frame);
703 be_node_set_reg_class(irn, OUT_POS(0), cls);
707 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
712 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
713 init_node_attr(res, -1);
714 for(i = 0; i < n_outs; ++i)
715 add_register_req(res);
720 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
721 const arch_env_t *arch_env,
722 const arch_register_t *reg)
724 ir_graph *irg = get_irn_irg(regparams);
725 ir_node *block = get_nodes_block(regparams);
726 be_node_attr_t *attr = get_irn_attr(regparams);
727 const arch_register_class_t *cls = arch_register_get_class(reg);
728 ir_mode *mode = arch_register_class_mode(cls);
729 int n = ARR_LEN(attr->reg_data);
732 assert(be_is_RegParams(regparams));
733 proj = new_r_Proj(irg, block, regparams, mode, n);
734 add_register_req(regparams);
735 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
736 arch_set_irn_register(arch_env, proj, reg);
738 /* TODO decide, whether we need to set ignore/modify sp flags here? */
743 ir_node *be_new_FrameLoad(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
744 ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_entity *ent)
752 irn = new_ir_node(NULL, irg, bl, op_be_FrameLoad, mode_T, 2, in);
753 a = init_node_attr(irn, 3);
756 be_node_set_reg_class(irn, 1, cls_frame);
757 be_node_set_reg_class(irn, OUT_POS(pn_Load_res), cls_data);
761 ir_node *be_new_FrameStore(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
762 ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_node *data, ir_entity *ent)
771 irn = new_ir_node(NULL, irg, bl, op_be_FrameStore, mode_T, 3, in);
772 a = init_node_attr(irn, 3);
775 be_node_set_reg_class(irn, 1, cls_frame);
776 be_node_set_reg_class(irn, 2, cls_data);
780 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
787 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
788 a = init_node_attr(irn, 1);
791 be_node_set_reg_class(irn, 0, cls_frame);
792 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
794 return optimize_node(irn);
797 ir_node *be_new_CopyKeep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, int n, ir_node *in_keep[], ir_mode *mode)
800 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
803 memcpy(&in[1], in_keep, n * sizeof(in[0]));
804 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
805 init_node_attr(irn, n + 1);
806 be_node_set_reg_class(irn, OUT_POS(0), cls);
807 be_node_set_reg_class(irn, 0, cls);
812 ir_node *be_new_CopyKeep_single(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, ir_node *keep, ir_mode *mode)
817 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
820 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
821 return get_irn_n(cpy, be_pos_CopyKeep_op);
824 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
825 set_irn_n(cpy, be_pos_CopyKeep_op, op);
828 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
833 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
834 init_node_attr(res, -1);
835 for(i = 0; i < n; ++i) {
836 add_irn_n(res, in[i]);
837 add_register_req(res);
843 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
845 ir_graph *irg = get_irn_irg(barrier);
846 ir_node *block = get_nodes_block(barrier);
847 ir_mode *mode = get_irn_mode(node);
848 int n = add_irn_n(barrier, node);
850 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
851 add_register_req(barrier);
856 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
857 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
858 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
859 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
860 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
861 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
862 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
863 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
864 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
865 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
866 int be_is_SetSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SetSP ; }
867 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
868 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
869 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
870 int be_is_StackParam (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_StackParam ; }
871 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
872 int be_is_FrameLoad (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameLoad ; }
873 int be_is_FrameStore (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameStore ; }
874 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
876 int be_has_frame_entity(const ir_node *irn)
878 switch(be_get_irn_opcode(irn)) {
891 ir_entity *be_get_frame_entity(const ir_node *irn)
893 if (be_has_frame_entity(irn)) {
894 be_frame_attr_t *a = get_irn_attr(irn);
900 int be_get_frame_offset(const ir_node *irn)
902 assert(is_be_node(irn));
903 if (be_has_frame_entity(irn)) {
904 be_frame_attr_t *a = get_irn_attr(irn);
910 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
912 be_memperm_attr_t *attr = get_irn_attr(irn);
914 assert(be_is_MemPerm(irn));
915 assert(n < be_get_MemPerm_entity_arity(irn));
917 attr->in_entities[n] = ent;
920 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
922 be_memperm_attr_t *attr = get_irn_attr(irn);
924 assert(be_is_MemPerm(irn));
925 assert(n < be_get_MemPerm_entity_arity(irn));
927 return attr->in_entities[n];
930 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
932 be_memperm_attr_t *attr = get_irn_attr(irn);
934 assert(be_is_MemPerm(irn));
935 assert(n < be_get_MemPerm_entity_arity(irn));
937 attr->out_entities[n] = ent;
940 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
942 be_memperm_attr_t *attr = get_irn_attr(irn);
944 assert(be_is_MemPerm(irn));
945 assert(n < be_get_MemPerm_entity_arity(irn));
947 return attr->out_entities[n];
950 int be_get_MemPerm_entity_arity(const ir_node *irn)
952 return get_irn_arity(irn) - 1;
955 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
957 arch_register_req_t *req = get_req(node, pos);
958 const arch_register_class_t *cls = arch_register_get_class(reg);
959 ir_graph *irg = get_irn_irg(node);
960 struct obstack *obst = get_irg_obstack(irg);
961 unsigned *limited_bitset;
963 assert(req->cls == NULL || req->cls == cls);
964 assert(! (req->type & arch_register_req_type_limited));
965 assert(req->limited == NULL);
967 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
968 rbitset_set(limited_bitset, arch_register_get_index(reg));
971 req->type |= arch_register_req_type_limited;
972 req->limited = limited_bitset;
975 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
977 ir_graph *irg = get_irn_irg(node);
978 struct obstack *obst = get_irg_obstack(irg);
979 arch_register_req_t *r = get_req(node, pos);
981 assert(arch_register_req_is(req, limited));
982 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
983 memcpy(r, req, sizeof(r[0]));
984 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
987 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
989 be_req_t *bereq = get_be_req(irn, pos);
990 bereq->flags = flags;
993 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
995 arch_register_req_t *req = get_req(irn, pos);
1000 req->type = arch_register_req_type_none;
1001 } else if (req->type == arch_register_req_type_none) {
1002 req->type = arch_register_req_type_normal;
1006 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1008 arch_register_req_t *req = get_req(irn, pos);
1012 ir_node *be_get_IncSP_pred(ir_node *irn) {
1013 assert(be_is_IncSP(irn));
1014 return get_irn_n(irn, 0);
1017 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1018 assert(be_is_IncSP(incsp));
1019 set_irn_n(incsp, 0, pred);
1022 ir_node *be_get_IncSP_mem(ir_node *irn) {
1023 assert(be_is_IncSP(irn));
1024 return get_irn_n(irn, 1);
1027 void be_set_IncSP_offset(ir_node *irn, int offset)
1029 be_stack_attr_t *a = get_irn_attr(irn);
1030 assert(be_is_IncSP(irn));
1034 int be_get_IncSP_offset(const ir_node *irn)
1036 be_stack_attr_t *a = get_irn_attr(irn);
1037 assert(be_is_IncSP(irn));
1041 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
1043 ir_node *bl = get_nodes_block(irn);
1044 ir_graph *irg = get_irn_irg(bl);
1045 ir_node *frame = get_irg_frame(irg);
1046 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1047 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1050 spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
1054 ir_node *be_reload(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_node *insert, ir_mode *mode, ir_node *spill)
1057 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1058 ir_graph *irg = get_irn_irg(bl);
1059 ir_node *frame = get_irg_frame(irg);
1060 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1062 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1064 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1066 if (is_Block(insert)) {
1067 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1068 sched_add_after(insert, reload);
1070 sched_add_before(insert, reload);
1078 | _ \ ___ __ _ | _ \ ___ __ _ ___
1079 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1080 | _ < __/ (_| | | _ < __/ (_| \__ \
1081 |_| \_\___|\__, | |_| \_\___|\__, |___/
1088 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1090 const be_node_attr_t *a = get_irn_attr(irn);
1092 if(out_pos >= ARR_LEN(a->reg_data)) {
1093 return arch_no_register_req;
1096 return &a->reg_data[out_pos].req.req;
1100 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1102 const be_node_attr_t *a = get_irn_attr(irn);
1104 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1105 return arch_no_register_req;
1107 return &a->reg_data[pos].in_req.req;
1110 static const arch_register_req_t *
1111 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1116 if (get_irn_mode(irn) == mode_T)
1117 return arch_no_register_req;
1119 out_pos = redir_proj((const ir_node **)&irn);
1120 assert(is_be_node(irn));
1121 return get_out_reg_req(irn, out_pos);
1122 } else if (is_be_node(irn)) {
1124 * For spills and reloads, we return "none" as requirement for frame
1125 * pointer, so every input is ok. Some backends need this (e.g. STA).
1127 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1128 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1129 return arch_no_register_req;
1131 return get_in_reg_req(irn, pos);
1134 return arch_no_register_req;
1137 const arch_register_t *
1138 be_node_get_irn_reg(const void *_self, const ir_node *irn)
1142 if (get_irn_mode(irn) == mode_T)
1144 r = retrieve_reg_data(irn);
1148 static arch_irn_class_t be_node_classify(const void *_self, const ir_node *irn)
1150 redir_proj((const ir_node **) &irn);
1152 switch(be_get_irn_opcode(irn)) {
1153 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1155 XXX(Reload, reload);
1158 XXX(Return, branch);
1159 XXX(StackParam, stackparam);
1162 return arch_irn_class_normal;
1168 static arch_irn_flags_t be_node_get_flags(const void *_self, const ir_node *node)
1174 pos = OUT_POS(get_Proj_proj(node));
1175 node = skip_Proj_const(node);
1178 bereq = get_be_req(node, pos);
1180 return bereq->flags;
1183 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1185 return be_get_frame_entity(irn);
1188 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1192 assert(be_has_frame_entity(irn));
1194 a = get_irn_attr(irn);
1198 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1200 if(be_has_frame_entity(irn)) {
1201 be_frame_attr_t *a = get_irn_attr(irn);
1206 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1208 return be_is_IncSP(irn) ? be_get_IncSP_offset(irn) : 0;
1212 ___ ____ _ _ _ _ _ _
1213 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1214 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1215 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1216 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1220 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1221 be_node_get_irn_reg_req,
1222 be_node_set_irn_reg,
1223 be_node_get_irn_reg,
1226 be_node_get_frame_entity,
1227 be_node_set_frame_entity,
1228 be_node_set_frame_offset,
1229 be_node_get_sp_bias,
1230 NULL, /* get_inverse */
1231 NULL, /* get_op_estimated_cost */
1232 NULL, /* possible_memory_operand */
1233 NULL, /* perform_memory_operand */
1236 static const arch_irn_ops_t be_node_irn_ops = {
1240 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1242 redir_proj((const ir_node **) &irn);
1243 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1246 const arch_irn_handler_t be_node_irn_handler = {
1251 ____ _ _ ___ ____ _ _ _ _ _ _
1252 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1253 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1254 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1255 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1260 const arch_register_t *reg;
1261 arch_register_req_t req;
1262 arch_irn_flags_t flags;
1266 arch_irn_handler_t irn_handler;
1267 arch_irn_ops_t irn_ops;
1268 const arch_env_t *arch_env;
1272 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1273 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1276 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1279 const phi_handler_t *h;
1280 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1283 h = get_phi_handler_from_handler(handler);
1288 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1290 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1292 ir_graph *irg = get_irn_irg(phi);
1293 struct obstack *obst = get_irg_obstack(irg);
1294 attr = obstack_alloc(obst, sizeof(attr[0]));
1295 memset(attr, 0, sizeof(attr[0]));
1296 pmap_insert(handler->phi_attrs, phi, attr);
1303 * Get register class of a Phi.
1306 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1310 int n = get_irn_arity(phi);
1314 if(*visited && pset_find_ptr(*visited, phi))
1317 for(i = 0; i < n; ++i) {
1318 op = get_irn_n(phi, i);
1319 /* Matze: don't we unnecessary constraint our phis with this?
1320 * we only need to take the regclass IMO*/
1322 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1326 * The operands of that Phi were all Phis themselves.
1327 * We have to start a DFS for a non-Phi argument now.
1330 *visited = pset_new_ptr(16);
1332 pset_insert_ptr(*visited, phi);
1334 for(i = 0; i < n; ++i) {
1335 const arch_register_req_t *req;
1336 op = get_irn_n(phi, i);
1337 req = get_Phi_reg_req_recursive(h, op, visited);
1346 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1347 const ir_node *irn, int pos)
1349 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1352 if(!mode_is_datab(get_irn_mode(irn)))
1353 return arch_no_register_req;
1355 attr = get_Phi_attr(phi_handler, irn);
1357 if(attr->req.type == arch_register_req_type_none) {
1358 pset *visited = NULL;
1359 const arch_register_req_t *req;
1360 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1362 memcpy(&attr->req, req, sizeof(req[0]));
1363 assert(attr->req.cls != NULL);
1364 attr->req.type = arch_register_req_type_normal;
1373 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1374 const arch_register_req_t *req)
1376 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1377 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1380 assert(mode_is_datab(get_irn_mode(node)));
1382 attr = get_Phi_attr(handler, node);
1383 memcpy(&attr->req, req, sizeof(req[0]));
1386 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1387 arch_irn_flags_t flags)
1389 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1390 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1393 assert(mode_is_datab(get_irn_mode(node)));
1395 attr = get_Phi_attr(handler, node);
1396 attr->flags = flags;
1400 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1402 phi_handler_t *h = get_phi_handler_from_ops(self);
1403 phi_attr_t *attr = get_Phi_attr(h, irn);
1408 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1410 phi_handler_t *h = get_phi_handler_from_ops(self);
1411 phi_attr_t *attr = get_Phi_attr(h, irn);
1416 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1418 return arch_irn_class_normal;
1422 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1424 phi_handler_t *h = get_phi_handler_from_ops(self);
1425 phi_attr_t *attr = get_Phi_attr(h, irn);
1430 ir_entity *phi_get_frame_entity(const void *_self, const ir_node *irn)
1436 void phi_set_frame_entity(const void *_self, ir_node *irn, ir_entity *ent)
1442 void phi_set_frame_offset(const void *_self, ir_node *irn, int bias)
1448 int phi_get_sp_bias(const void* self, const ir_node *irn)
1454 const arch_irn_ops_if_t phi_irn_ops = {
1455 phi_get_irn_reg_req,
1460 phi_get_frame_entity,
1461 phi_set_frame_entity,
1462 phi_set_frame_offset,
1464 NULL, /* get_inverse */
1465 NULL, /* get_op_estimated_cost */
1466 NULL, /* possible_memory_operand */
1467 NULL, /* perform_memory_operand */
1470 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1472 phi_handler_t *h = xmalloc(sizeof(h[0]));
1473 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1474 h->irn_ops.impl = &phi_irn_ops;
1475 h->arch_env = arch_env;
1476 h->phi_attrs = pmap_create();
1477 return (arch_irn_handler_t *) h;
1480 void be_phi_handler_free(arch_irn_handler_t *handler)
1482 phi_handler_t *h = (void *) handler;
1483 pmap_destroy(h->phi_attrs);
1487 void be_phi_handler_reset(arch_irn_handler_t *handler)
1489 phi_handler_t *h = get_phi_handler_from_handler(handler);
1491 pmap_destroy(h->phi_attrs);
1492 h->phi_attrs = pmap_create();
1497 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1498 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1499 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1500 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1505 * Dumps a register requirement to a file.
1507 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1508 const ir_node *node)
1510 int did_something = 0;
1512 const char *prefix = buf;
1514 snprintf(buf, sizeof(buf), "#%d ", idx);
1515 buf[sizeof(buf) - 1] = '\0';
1520 arch_register_req_format(tmp, sizeof(tmp), req, node);
1521 fprintf(f, "%s", tmp);
1530 * Dumps node register requirements to a file.
1532 static void dump_node_reqs(FILE *f, ir_node *node)
1535 be_node_attr_t *a = get_irn_attr(node);
1536 int len = ARR_LEN(a->reg_data);
1538 fprintf(f, "registers: \n");
1539 for(i = 0; i < len; ++i) {
1540 be_reg_data_t *rd = &a->reg_data[i];
1542 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1545 fprintf(f, "in requirements:\n");
1546 for(i = 0; i < len; ++i) {
1547 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1550 fprintf(f, "\nout requirements:\n");
1551 for(i = 0; i < len; ++i) {
1552 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1557 * ir_op-Operation: dump a be node to file
1559 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1561 be_node_attr_t *at = get_irn_attr(irn);
1563 assert(is_be_node(irn));
1566 case dump_node_opcode_txt:
1567 fprintf(f, get_op_name(get_irn_op(irn)));
1569 case dump_node_mode_txt:
1570 fprintf(f, get_mode_name(get_irn_mode(irn)));
1572 case dump_node_nodeattr_txt:
1574 case dump_node_info_txt:
1575 dump_node_reqs(f, irn);
1577 if(be_has_frame_entity(irn)) {
1578 be_frame_attr_t *a = (be_frame_attr_t *) at;
1580 int bits = get_type_size_bits(get_entity_type(a->ent));
1581 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1582 a->ent, a->offset, a->offset, bits, bits);
1587 switch(be_get_irn_opcode(irn)) {
1590 be_stack_attr_t *a = (be_stack_attr_t *) at;
1591 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1592 fprintf(f, "offset: FRAME_SIZE\n");
1593 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1594 fprintf(f, "offset: -FRAME SIZE\n");
1596 fprintf(f, "offset: %u\n", a->offset);
1601 be_call_attr_t *a = (be_call_attr_t *) at;
1604 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1610 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1611 ir_entity *in, *out;
1612 in = be_get_MemPerm_in_entity(irn, i);
1613 out = be_get_MemPerm_out_entity(irn, i);
1615 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1618 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1634 * Copies the backend specific attributes from old node to new node.
1636 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1638 be_node_attr_t *old_attr = get_irn_attr(old_node);
1639 be_node_attr_t *new_attr = get_irn_attr(new_node);
1640 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1643 assert(is_be_node(old_node));
1644 assert(is_be_node(new_node));
1646 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1647 new_attr->reg_data = NULL;
1649 if(old_attr->reg_data != NULL)
1650 len = ARR_LEN(old_attr->reg_data);
1654 if(get_irn_op(old_node)->opar == oparity_dynamic
1655 || be_is_RegParams(old_node)) {
1656 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1658 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1662 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1663 for(i = 0; i < len; ++i) {
1664 const be_reg_data_t *rd = &old_attr->reg_data[i];
1665 be_reg_data_t *newrd = &new_attr->reg_data[i];
1666 if(arch_register_req_is(&rd->req.req, limited)) {
1667 const arch_register_req_t *req = &rd->req.req;
1668 arch_register_req_t *new_req = &newrd->req.req;
1670 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1672 if(arch_register_req_is(&rd->in_req.req, limited)) {
1673 const arch_register_req_t *req = &rd->in_req.req;
1674 arch_register_req_t *new_req = &newrd->in_req.req;
1676 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1682 static const ir_op_ops be_node_op_ops = {