4 * @author Sebastian Hack
6 * Backend node support.
8 * This file provides Perm, Copy, Spill and Reload nodes.
10 * Copyright (C) 2005-2006 Universitaet Karlsruhe
11 * Released under the GPL
26 #include "bitfiddle.h"
27 #include "raw_bitset.h"
39 #include "besched_t.h"
44 #define OUT_POS(x) (-((x) + 1))
46 /* Sometimes we want to put const nodes into get_irn_generic_attr ... */
47 #define get_irn_attr(irn) get_irn_generic_attr((ir_node *) (irn))
49 static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
52 arch_register_req_t req;
53 arch_irn_flags_t flags;
57 const arch_register_t *reg;
62 /** The generic be nodes attribute type. */
64 be_reg_data_t *reg_data;
67 /** The be_Return nodes attribute type. */
69 be_node_attr_t node_attr;
70 int num_ret_vals; /**< number of return values */
73 /** The be_Stack attribute type. */
75 be_node_attr_t node_attr;
76 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
79 /** The be_Frame attribute type. */
81 be_node_attr_t node_attr;
86 /** The be_Call attribute type. */
88 be_node_attr_t node_attr;
89 ir_entity *ent; /**< The called entity if this is a static call. */
90 ir_type *call_tp; /**< The call type, copied from the original Call node. */
94 be_node_attr_t node_attr;
95 ir_entity **in_entities;
96 ir_entity **out_entities;
102 ir_op *op_be_MemPerm;
105 ir_op *op_be_CopyKeep;
112 ir_op *op_be_RegParams;
113 ir_op *op_be_StackParam;
114 ir_op *op_be_FrameAddr;
115 ir_op *op_be_FrameLoad;
116 ir_op *op_be_FrameStore;
117 ir_op *op_be_Barrier;
119 static int beo_base = -1;
121 static const ir_op_ops be_node_op_ops;
123 #define N irop_flag_none
124 #define L irop_flag_labeled
125 #define C irop_flag_commutative
126 #define X irop_flag_cfopcode
127 #define I irop_flag_ip_cfopcode
128 #define F irop_flag_fragile
129 #define Y irop_flag_forking
130 #define H irop_flag_highlevel
131 #define c irop_flag_constlike
132 #define K irop_flag_keep
133 #define M irop_flag_machine
137 * Compare two node attributes.
139 * @return zero if both attributes are identically
141 static int cmp_node_attr(be_node_attr_t *a, be_node_attr_t *b) {
144 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
147 len = ARR_LEN(a->reg_data);
148 for (i = 0; i < len; ++i) {
149 if (a->reg_data[i].reg != b->reg_data[i].reg ||
150 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
151 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
159 * Compare the attributes of two FrameAddr nodes.
161 * @return zero if both attributes are identically
163 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
164 be_frame_attr_t *a_attr = get_irn_attr(a);
165 be_frame_attr_t *b_attr = get_irn_attr(b);
167 if (a_attr->ent == b_attr->ent && a_attr->offset == b_attr->offset)
168 return cmp_node_attr(&a_attr->node_attr, &b_attr->node_attr);
172 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
175 be_node_attr_t *attr;
178 assert(is_be_node(node));
179 attr = get_irn_attr(node);
185 assert(idx < get_irn_arity(node));
187 assert(idx < ARR_LEN(attr->reg_data));
188 rd = &attr->reg_data[idx];
190 return pos < 0 ? &rd->req : &rd->in_req;
193 static inline arch_register_req_t *get_req(const ir_node *node, int pos)
195 be_req_t *bereq = get_be_req(node, pos);
199 void be_node_init(void) {
200 static int inited = 0;
207 /* Acquire all needed opcodes. */
208 beo_base = get_next_ir_opcodes(beo_Last - 1);
210 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);
211 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);
212 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);
213 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);
214 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);
215 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);
216 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);
217 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);
218 op_be_Return = new_ir_op(beo_base + beo_Return, "be_Return", op_pin_state_pinned, X, oparity_variable, 0, sizeof(be_return_attr_t), &be_node_op_ops);
219 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);
220 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);
221 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);
222 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);
223 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);
224 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);
225 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);
226 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);
227 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);
228 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);
230 set_op_tag(op_be_Spill, &be_node_tag);
231 set_op_tag(op_be_Reload, &be_node_tag);
232 set_op_tag(op_be_Perm, &be_node_tag);
233 set_op_tag(op_be_MemPerm, &be_node_tag);
234 set_op_tag(op_be_Copy, &be_node_tag);
235 set_op_tag(op_be_Keep, &be_node_tag);
236 set_op_tag(op_be_CopyKeep, &be_node_tag);
237 set_op_tag(op_be_Call, &be_node_tag);
238 set_op_tag(op_be_Return, &be_node_tag);
239 set_op_tag(op_be_AddSP, &be_node_tag);
240 set_op_tag(op_be_SubSP, &be_node_tag);
241 set_op_tag(op_be_SetSP, &be_node_tag);
242 set_op_tag(op_be_IncSP, &be_node_tag);
243 set_op_tag(op_be_RegParams, &be_node_tag);
244 set_op_tag(op_be_StackParam, &be_node_tag);
245 set_op_tag(op_be_FrameLoad, &be_node_tag);
246 set_op_tag(op_be_FrameStore, &be_node_tag);
247 set_op_tag(op_be_FrameAddr, &be_node_tag);
248 set_op_tag(op_be_Barrier, &be_node_tag);
250 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
254 * Initializes the generic attribute of all be nodes and return ir.
256 static void *init_node_attr(ir_node *node, int max_reg_data)
258 ir_graph *irg = get_irn_irg(node);
259 struct obstack *obst = get_irg_obstack(irg);
260 be_node_attr_t *a = get_irn_attr(node);
262 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
264 if(max_reg_data >= 0) {
265 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
266 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
268 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
274 static void add_register_req(ir_node *node)
276 be_node_attr_t *a = get_irn_attr(node);
277 be_reg_data_t regreq;
278 memset(®req, 0, sizeof(regreq));
279 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
282 int is_be_node(const ir_node *irn)
284 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
287 be_opcode_t be_get_irn_opcode(const ir_node *irn)
289 return is_be_node(irn) ? get_irn_opcode(irn) - beo_base : beo_NoBeOp;
293 * Skip Proj nodes and return their Proj numbers.
295 * If *node is a Proj or Proj(Proj) node, skip it.
297 * @param node points to the node to be skipped
299 * @return 0 if *node was no Proj node, its Proj number else.
301 static int redir_proj(const ir_node **node)
303 const ir_node *n = *node;
308 *node = irn = get_Proj_pred(n);
310 assert(get_irn_mode(irn) == mode_T);
311 *node = get_Proj_pred(irn);
313 return get_Proj_proj(n);
319 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
321 be_node_attr_t *attr;
325 pos = get_Proj_proj(node);
326 node = get_Proj_pred(node);
329 assert(is_be_node(node));
330 attr = get_irn_attr(node);
331 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
333 return &attr->reg_data[pos];
337 be_node_set_irn_reg(const void *_self, ir_node *irn, const arch_register_t *reg)
339 be_reg_data_t *r = retrieve_reg_data(irn);
343 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
344 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
352 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
353 a = init_node_attr(res, 2);
357 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
358 be_node_set_reg_class(res, be_pos_Spill_val, cls);
362 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
363 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
370 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
372 init_node_attr(res, 2);
373 be_node_set_reg_class(res, -1, cls);
374 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
375 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
379 ir_node *be_get_Reload_mem(const ir_node *irn)
381 assert(be_is_Reload(irn));
382 return get_irn_n(irn, be_pos_Reload_mem);
385 ir_node *be_get_Reload_frame(const ir_node *irn)
387 assert(be_is_Reload(irn));
388 return get_irn_n(irn, be_pos_Reload_frame);
391 ir_node *be_get_Spill_val(const ir_node *irn)
393 assert(be_is_Spill(irn));
394 return get_irn_n(irn, be_pos_Spill_val);
397 ir_node *be_get_Spill_frame(const ir_node *irn)
399 assert(be_is_Spill(irn));
400 return get_irn_n(irn, be_pos_Spill_frame);
403 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
406 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
407 init_node_attr(irn, n);
408 for(i = 0; i < n; ++i) {
409 be_node_set_reg_class(irn, i, cls);
410 be_node_set_reg_class(irn, OUT_POS(i), cls);
416 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
419 ir_node *frame = get_irg_frame(irg);
420 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
422 const arch_register_t *sp = arch_env->isa->sp;
423 be_memperm_attr_t *attr;
426 real_in = alloca((n+1) * sizeof(real_in[0]));
428 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
430 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
432 init_node_attr(irn, n + 1);
433 be_node_set_reg_class(irn, 0, sp->reg_class);
434 for(i = 0; i < n; ++i) {
435 be_node_set_reg_class(irn, i + 1, cls_frame);
436 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
439 attr = get_irn_attr(irn);
441 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
442 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
443 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
444 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
450 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
454 arch_register_req_t *req;
457 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
458 init_node_attr(res, 1);
459 be_node_set_reg_class(res, 0, cls);
460 be_node_set_reg_class(res, OUT_POS(0), cls);
462 req = get_req(res, OUT_POS(0));
464 req->type = arch_register_req_type_should_be_same;
470 ir_node *be_get_Copy_op(const ir_node *cpy) {
471 return get_irn_n(cpy, be_pos_Copy_op);
474 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
475 set_irn_n(cpy, be_pos_Copy_op, op);
478 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
483 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
484 init_node_attr(res, -1);
486 for(i = 0; i < n; ++i) {
487 add_irn_n(res, in[i]);
488 add_register_req(res);
489 be_node_set_reg_class(res, i, cls);
496 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
500 assert(be_is_Keep(keep));
501 n = add_irn_n(keep, node);
502 add_register_req(keep);
503 be_node_set_reg_class(keep, n, cls);
506 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
507 int n_outs, int n, ir_node *in[], ir_type *call_tp)
510 int real_n = be_pos_Call_first_arg + n;
514 NEW_ARR_A(ir_node *, real_in, real_n);
515 real_in[be_pos_Call_mem] = mem;
516 real_in[be_pos_Call_sp] = sp;
517 real_in[be_pos_Call_ptr] = ptr;
518 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
520 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
521 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
523 a->call_tp = call_tp;
527 /* Gets the call entity or NULL if this is no static call. */
528 ir_entity *be_Call_get_entity(const ir_node *call) {
529 be_call_attr_t *a = get_irn_attr(call);
530 assert(be_is_Call(call));
534 /* Sets the call entity. */
535 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
536 be_call_attr_t *a = get_irn_attr(call);
537 assert(be_is_Call(call));
541 /* Gets the call type. */
542 ir_type *be_Call_get_type(ir_node *call) {
543 be_call_attr_t *a = get_irn_attr(call);
544 assert(be_is_Call(call));
548 /* Sets the call type. */
549 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
550 be_call_attr_t *a = get_irn_attr(call);
551 assert(be_is_Call(call));
552 a->call_tp = call_tp;
555 /* Construct a new be_Return. */
556 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *bl, int n_res, int n, ir_node *in[])
559 ir_node *irn = new_ir_node(dbg, irg, bl, op_be_Return, mode_X, n, in);
560 init_node_attr(irn, n);
561 a = get_irn_attr(irn);
562 a->num_ret_vals = n_res;
567 /* Returns the number of real returns values */
568 int be_Return_get_n_rets(ir_node *ret)
570 be_return_attr_t *a = get_irn_attr(ret);
571 return a->num_ret_vals;
574 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
581 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
582 a = init_node_attr(irn, 1);
585 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
587 /* Set output constraint to stack register. */
588 be_node_set_reg_class(irn, 0, sp->reg_class);
589 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
590 be_node_set_irn_reg(NULL, irn, sp);
595 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
599 ir_node *in[be_pos_AddSP_last];
601 in[be_pos_AddSP_old_sp] = old_sp;
602 in[be_pos_AddSP_size] = sz;
604 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
605 a = init_node_attr(irn, be_pos_AddSP_last);
607 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_res), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
609 /* Set output constraint to stack register. */
610 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
611 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
612 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_res), sp);
613 a->reg_data[pn_be_AddSP_res].reg = sp;
618 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
622 ir_node *in[be_pos_SubSP_last];
624 in[be_pos_SubSP_old_sp] = old_sp;
625 in[be_pos_SubSP_size] = sz;
627 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
628 a = init_node_attr(irn, be_pos_SubSP_last);
630 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_res), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
632 /* Set output constraint to stack register. */
633 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
634 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
635 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_res), sp);
636 a->reg_data[pn_be_SubSP_res].reg = sp;
641 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)
650 irn = new_ir_node(NULL, irg, bl, op_be_SetSP, get_irn_mode(old_sp), 3, in);
651 a = init_node_attr(irn, 3);
653 be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
655 /* Set output constraint to stack register. */
656 be_set_constr_single_reg(irn, OUT_POS(0), sp);
657 be_node_set_reg_class(irn, be_pos_AddSP_size, sp->reg_class);
658 be_node_set_reg_class(irn, be_pos_AddSP_old_sp, sp->reg_class);
663 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)
669 in[0] = frame_pointer;
670 irn = new_ir_node(NULL, irg, bl, op_be_StackParam, mode, 1, in);
671 a = init_node_attr(irn, 1);
674 be_node_set_reg_class(irn, 0, cls_frame);
675 be_node_set_reg_class(irn, OUT_POS(0), cls);
679 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
684 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
685 init_node_attr(res, -1);
686 for(i = 0; i < n_outs; ++i)
687 add_register_req(res);
692 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
693 const arch_env_t *arch_env,
694 const arch_register_t *reg)
696 ir_graph *irg = get_irn_irg(regparams);
697 ir_node *block = get_nodes_block(regparams);
698 be_node_attr_t *attr = get_irn_attr(regparams);
699 const arch_register_class_t *cls = arch_register_get_class(reg);
700 ir_mode *mode = arch_register_class_mode(cls);
701 int n = ARR_LEN(attr->reg_data);
704 assert(be_is_RegParams(regparams));
705 proj = new_r_Proj(irg, block, regparams, mode, n);
706 add_register_req(regparams);
707 be_set_constr_single_reg(regparams, n, reg);
708 arch_set_irn_register(arch_env, proj, reg);
710 /* TODO decide, whether we need to set ignore/modify sp flags here? */
715 ir_node *be_new_FrameLoad(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
716 ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_entity *ent)
724 irn = new_ir_node(NULL, irg, bl, op_be_FrameLoad, mode_T, 2, in);
725 a = init_node_attr(irn, 3);
728 be_node_set_reg_class(irn, 1, cls_frame);
729 be_node_set_reg_class(irn, OUT_POS(pn_Load_res), cls_data);
733 ir_node *be_new_FrameStore(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
734 ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_node *data, ir_entity *ent)
743 irn = new_ir_node(NULL, irg, bl, op_be_FrameStore, mode_T, 3, in);
744 a = init_node_attr(irn, 3);
747 be_node_set_reg_class(irn, 1, cls_frame);
748 be_node_set_reg_class(irn, 2, cls_data);
752 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
759 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
760 a = init_node_attr(irn, 1);
763 be_node_set_reg_class(irn, 0, cls_frame);
764 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
766 return optimize_node(irn);
769 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)
772 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
775 memcpy(&in[1], in_keep, n * sizeof(in[0]));
776 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
777 init_node_attr(irn, n + 1);
778 be_node_set_reg_class(irn, OUT_POS(0), cls);
779 be_node_set_reg_class(irn, 0, cls);
784 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)
789 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
792 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
793 return get_irn_n(cpy, be_pos_CopyKeep_op);
796 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
797 set_irn_n(cpy, be_pos_CopyKeep_op, op);
800 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
805 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
806 init_node_attr(res, -1);
807 for(i = 0; i < n; ++i) {
808 add_irn_n(res, in[i]);
809 add_register_req(res);
815 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
817 ir_graph *irg = get_irn_irg(barrier);
818 ir_node *block = get_nodes_block(barrier);
819 ir_mode *mode = get_irn_mode(node);
820 int n = add_irn_n(barrier, node);
821 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
822 add_register_req(barrier);
827 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
828 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
829 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
830 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
831 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
832 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
833 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
834 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
835 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
836 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
837 int be_is_SetSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SetSP ; }
838 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
839 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
840 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
841 int be_is_StackParam (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_StackParam ; }
842 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
843 int be_is_FrameLoad (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameLoad ; }
844 int be_is_FrameStore (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameStore ; }
845 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
847 int be_has_frame_entity(const ir_node *irn)
849 switch(be_get_irn_opcode(irn)) {
862 ir_entity *be_get_frame_entity(const ir_node *irn)
864 if (be_has_frame_entity(irn)) {
865 be_frame_attr_t *a = get_irn_attr(irn);
871 int be_get_frame_offset(const ir_node *irn)
873 assert(is_be_node(irn));
874 if (be_has_frame_entity(irn)) {
875 be_frame_attr_t *a = get_irn_attr(irn);
881 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
883 be_memperm_attr_t *attr = get_irn_attr(irn);
885 assert(be_is_MemPerm(irn));
886 assert(n < be_get_MemPerm_entity_arity(irn));
888 attr->in_entities[n] = ent;
891 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
893 be_memperm_attr_t *attr = get_irn_attr(irn);
895 assert(be_is_MemPerm(irn));
896 assert(n < be_get_MemPerm_entity_arity(irn));
898 return attr->in_entities[n];
901 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
903 be_memperm_attr_t *attr = get_irn_attr(irn);
905 assert(be_is_MemPerm(irn));
906 assert(n < be_get_MemPerm_entity_arity(irn));
908 attr->out_entities[n] = ent;
911 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
913 be_memperm_attr_t *attr = get_irn_attr(irn);
915 assert(be_is_MemPerm(irn));
916 assert(n < be_get_MemPerm_entity_arity(irn));
918 return attr->out_entities[n];
921 int be_get_MemPerm_entity_arity(const ir_node *irn)
923 return get_irn_arity(irn) - 1;
926 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
928 arch_register_req_t *req = get_req(node, pos);
929 const arch_register_class_t *cls = arch_register_get_class(reg);
930 ir_graph *irg = get_irn_irg(node);
931 struct obstack *obst = get_irg_obstack(irg);
932 unsigned *limited_bitset;
934 assert(req->cls == NULL || req->cls == cls);
935 assert(! (req->type & arch_register_req_type_limited));
936 assert(req->limited == NULL);
938 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
939 rbitset_set(limited_bitset, arch_register_get_index(reg));
942 req->type |= arch_register_req_type_limited;
943 req->limited = limited_bitset;
946 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
948 ir_graph *irg = get_irn_irg(node);
949 struct obstack *obst = get_irg_obstack(irg);
950 arch_register_req_t *r = get_req(node, pos);
952 assert(arch_register_req_is(req, limited));
953 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
954 memcpy(r, req, sizeof(r[0]));
955 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
958 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
960 be_req_t *bereq = get_be_req(irn, pos);
961 bereq->flags = flags;
964 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
966 arch_register_req_t *req = get_req(irn, pos);
971 req->type = arch_register_req_type_none;
972 } else if (req->type == arch_register_req_type_none) {
973 req->type = arch_register_req_type_normal;
977 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
979 arch_register_req_t *req = get_req(irn, pos);
983 ir_node *be_get_IncSP_pred(ir_node *irn) {
984 assert(be_is_IncSP(irn));
985 return get_irn_n(irn, 0);
988 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
989 assert(be_is_IncSP(incsp));
990 set_irn_n(incsp, 0, pred);
993 ir_node *be_get_IncSP_mem(ir_node *irn) {
994 assert(be_is_IncSP(irn));
995 return get_irn_n(irn, 1);
998 void be_set_IncSP_offset(ir_node *irn, int offset)
1000 be_stack_attr_t *a = get_irn_attr(irn);
1001 assert(be_is_IncSP(irn));
1005 int be_get_IncSP_offset(const ir_node *irn)
1007 be_stack_attr_t *a = get_irn_attr(irn);
1008 assert(be_is_IncSP(irn));
1012 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
1014 ir_node *bl = get_nodes_block(irn);
1015 ir_graph *irg = get_irn_irg(bl);
1016 ir_node *frame = get_irg_frame(irg);
1017 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1018 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1021 spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
1025 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)
1028 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1029 ir_graph *irg = get_irn_irg(bl);
1030 ir_node *frame = get_irg_frame(irg);
1031 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1033 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1035 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1037 if (is_Block(insert)) {
1038 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1039 sched_add_after(insert, reload);
1041 sched_add_before(insert, reload);
1049 | _ \ ___ __ _ | _ \ ___ __ _ ___
1050 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1051 | _ < __/ (_| | | _ < __/ (_| \__ \
1052 |_| \_\___|\__, | |_| \_\___|\__, |___/
1059 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1061 const be_node_attr_t *a = get_irn_attr(irn);
1063 if(out_pos >= ARR_LEN(a->reg_data)) {
1064 return arch_no_register_req;
1067 return &a->reg_data[out_pos].req.req;
1071 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1073 const be_node_attr_t *a = get_irn_attr(irn);
1075 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1076 return arch_no_register_req;
1078 return &a->reg_data[pos].in_req.req;
1081 static const arch_register_req_t *
1082 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1087 if (get_irn_mode(irn) == mode_T)
1088 return arch_no_register_req;
1090 out_pos = redir_proj((const ir_node **)&irn);
1091 assert(is_be_node(irn));
1092 return get_out_reg_req(irn, out_pos);
1093 } else if (is_be_node(irn)) {
1095 * For spills and reloads, we return "none" as requirement for frame
1096 * pointer, so every input is ok. Some backends need this (e.g. STA).
1098 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1099 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1100 return arch_no_register_req;
1102 return get_in_reg_req(irn, pos);
1105 return arch_no_register_req;
1108 const arch_register_t *
1109 be_node_get_irn_reg(const void *_self, const ir_node *irn)
1111 be_reg_data_t *r = retrieve_reg_data(irn);
1115 static arch_irn_class_t be_node_classify(const void *_self, const ir_node *irn)
1117 redir_proj((const ir_node **) &irn);
1119 switch(be_get_irn_opcode(irn)) {
1120 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1122 XXX(Reload, reload);
1125 XXX(Return, branch);
1126 XXX(StackParam, stackparam);
1129 return arch_irn_class_normal;
1135 static arch_irn_flags_t be_node_get_flags(const void *_self, const ir_node *node)
1141 pos = OUT_POS(get_Proj_proj(node));
1142 node = skip_Proj_const(node);
1145 bereq = get_be_req(node, pos);
1147 return bereq->flags;
1150 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1152 return be_get_frame_entity(irn);
1155 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1159 assert(be_has_frame_entity(irn));
1161 a = get_irn_attr(irn);
1165 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1167 if(be_has_frame_entity(irn)) {
1168 be_frame_attr_t *a = get_irn_attr(irn);
1173 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1175 return be_is_IncSP(irn) ? be_get_IncSP_offset(irn) : 0;
1179 ___ ____ _ _ _ _ _ _
1180 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1181 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1182 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1183 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1187 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1188 be_node_get_irn_reg_req,
1189 be_node_set_irn_reg,
1190 be_node_get_irn_reg,
1193 be_node_get_frame_entity,
1194 be_node_set_frame_entity,
1195 be_node_set_frame_offset,
1196 be_node_get_sp_bias,
1197 NULL, /* get_inverse */
1198 NULL, /* get_op_estimated_cost */
1199 NULL, /* possible_memory_operand */
1200 NULL, /* perform_memory_operand */
1203 static const arch_irn_ops_t be_node_irn_ops = {
1207 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1209 redir_proj((const ir_node **) &irn);
1210 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1213 const arch_irn_handler_t be_node_irn_handler = {
1218 ____ _ _ ___ ____ _ _ _ _ _ _
1219 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1220 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1221 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1222 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1227 const arch_register_t *reg;
1228 arch_register_req_t req;
1232 arch_irn_handler_t irn_handler;
1233 arch_irn_ops_t irn_ops;
1234 const arch_env_t *arch_env;
1238 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1239 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1241 static const void *phi_get_irn_ops(const arch_irn_handler_t *handler, const ir_node *irn)
1243 const phi_handler_t *h = get_phi_handler_from_handler(handler);
1244 return is_Phi(irn) && mode_is_datab(get_irn_mode(irn)) ? &h->irn_ops : NULL;
1247 static INLINE phi_attr_t *get_Phi_attr(const phi_handler_t *handler,
1250 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1252 ir_graph *irg = get_irn_irg(phi);
1253 struct obstack *obst = get_irg_obstack(irg);
1254 attr = obstack_alloc(obst, sizeof(attr[0]));
1255 memset(attr, 0, sizeof(attr[0]));
1256 pmap_insert(handler->phi_attrs, phi, attr);
1263 * Get register class of a Phi.
1266 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1270 int n = get_irn_arity(phi);
1274 if(*visited && pset_find_ptr(*visited, phi))
1277 for(i = 0; i < n; ++i) {
1278 op = get_irn_n(phi, i);
1279 /* Matze: don't we unnecessary constraint our phis with this?
1280 * we only need to take the regclass IMO*/
1282 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1286 * The operands of that Phi were all Phis themselves.
1287 * We have to start a DFS for a non-Phi argument now.
1290 *visited = pset_new_ptr(16);
1292 pset_insert_ptr(*visited, phi);
1294 for(i = 0; i < n; ++i) {
1295 const arch_register_req_t *req;
1296 op = get_irn_n(phi, i);
1297 req = get_Phi_reg_req_recursive(h, op, visited);
1306 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1307 const ir_node *irn, int pos)
1309 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1312 if(!mode_is_datab(get_irn_mode(irn)))
1313 return arch_no_register_req;
1315 attr = get_Phi_attr(phi_handler, irn);
1317 if(attr->req.type == arch_register_req_type_none) {
1318 pset *visited = NULL;
1319 const arch_register_req_t *req;
1320 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1322 memcpy(&attr->req, req, sizeof(req[0]));
1323 assert(attr->req.cls != NULL);
1324 attr->req.type = arch_register_req_type_normal;
1333 static void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1335 phi_handler_t *h = get_phi_handler_from_ops(self);
1336 phi_attr_t *attr = get_Phi_attr(h, irn);
1340 static const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1342 phi_handler_t *h = get_phi_handler_from_ops(self);
1343 phi_attr_t *attr = get_Phi_attr(h, irn);
1347 static arch_irn_class_t phi_classify(const void *_self, const ir_node *irn)
1349 return arch_irn_class_normal;
1352 static arch_irn_flags_t phi_get_flags(const void *_self, const ir_node *irn)
1354 return arch_irn_flags_none;
1357 static ir_entity *phi_get_frame_entity(const void *_self, const ir_node *irn)
1362 static void phi_set_frame_entity(const void *_self, ir_node *irn, ir_entity *ent)
1366 static void phi_set_frame_offset(const void *_self, ir_node *irn, int bias)
1370 static int phi_get_sp_bias(const void* self, const ir_node *irn)
1375 static const arch_irn_ops_if_t phi_irn_ops = {
1376 phi_get_irn_reg_req,
1381 phi_get_frame_entity,
1382 phi_set_frame_entity,
1383 phi_set_frame_offset,
1385 NULL, /* get_inverse */
1386 NULL, /* get_op_estimated_cost */
1387 NULL, /* possible_memory_operand */
1388 NULL, /* perform_memory_operand */
1391 static const arch_irn_handler_t phi_irn_handler = {
1395 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1397 phi_handler_t *h = xmalloc(sizeof(h[0]));
1398 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1399 h->irn_ops.impl = &phi_irn_ops;
1400 h->arch_env = arch_env;
1401 h->phi_attrs = pmap_create();
1402 return (arch_irn_handler_t *) h;
1405 void be_phi_handler_free(arch_irn_handler_t *handler)
1407 phi_handler_t *h = (void *) handler;
1408 pmap_destroy(h->phi_attrs);
1412 const void *be_phi_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1414 phi_handler_t *phi_handler = get_phi_handler_from_handler(self);
1415 return is_Phi(irn) ? &phi_handler->irn_ops : NULL;
1418 void be_phi_handler_reset(arch_irn_handler_t *handler)
1420 phi_handler_t *h = get_phi_handler_from_handler(handler);
1422 pmap_destroy(h->phi_attrs);
1423 h->phi_attrs = pmap_create();
1428 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1429 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1430 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1431 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1436 * Dumps a register requirement to a file.
1438 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1439 const ir_node *node)
1441 int did_something = 0;
1443 const char *prefix = buf;
1445 snprintf(buf, sizeof(buf), "#%d ", idx);
1446 buf[sizeof(buf) - 1] = '\0';
1451 arch_register_req_format(tmp, sizeof(tmp), req, node);
1452 fprintf(f, "%s", tmp);
1461 * Dumps node register requirements to a file.
1463 static void dump_node_reqs(FILE *f, ir_node *node)
1466 be_node_attr_t *a = get_irn_attr(node);
1467 int len = ARR_LEN(a->reg_data);
1469 fprintf(f, "registers: \n");
1470 for(i = 0; i < len; ++i) {
1471 be_reg_data_t *rd = &a->reg_data[i];
1473 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1476 fprintf(f, "in requirements:\n");
1477 for(i = 0; i < len; ++i) {
1478 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1481 fprintf(f, "\nout requirements:\n");
1482 for(i = 0; i < len; ++i) {
1483 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1488 * ir_op-Operation: dump a be node to file
1490 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1492 be_node_attr_t *at = get_irn_attr(irn);
1494 assert(is_be_node(irn));
1497 case dump_node_opcode_txt:
1498 fprintf(f, get_op_name(get_irn_op(irn)));
1500 case dump_node_mode_txt:
1501 fprintf(f, get_mode_name(get_irn_mode(irn)));
1503 case dump_node_nodeattr_txt:
1505 case dump_node_info_txt:
1506 dump_node_reqs(f, irn);
1508 if(be_has_frame_entity(irn)) {
1509 be_frame_attr_t *a = (be_frame_attr_t *) at;
1511 int bits = get_type_size_bits(get_entity_type(a->ent));
1512 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1513 a->ent, a->offset, a->offset, bits, bits);
1518 switch(be_get_irn_opcode(irn)) {
1521 be_stack_attr_t *a = (be_stack_attr_t *) at;
1522 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1523 fprintf(f, "offset: FRAME_SIZE\n");
1524 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1525 fprintf(f, "offset: -FRAME SIZE\n");
1527 fprintf(f, "offset: %u\n", a->offset);
1532 be_call_attr_t *a = (be_call_attr_t *) at;
1535 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1541 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1542 ir_entity *in, *out;
1543 in = be_get_MemPerm_in_entity(irn, i);
1544 out = be_get_MemPerm_out_entity(irn, i);
1546 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1549 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1565 * Copies the backend specific attributes from old node to new node.
1567 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1569 be_node_attr_t *old_attr = get_irn_attr(old_node);
1570 be_node_attr_t *new_attr = get_irn_attr(new_node);
1571 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1574 assert(is_be_node(old_node));
1575 assert(is_be_node(new_node));
1577 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1578 new_attr->reg_data = NULL;
1580 if(old_attr->reg_data != NULL)
1581 len = ARR_LEN(old_attr->reg_data);
1585 if(get_irn_op(old_node)->opar == oparity_dynamic
1586 || be_is_RegParams(old_node)) {
1587 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1589 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1593 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1594 for(i = 0; i < len; ++i) {
1595 const be_reg_data_t *rd = &old_attr->reg_data[i];
1596 be_reg_data_t *newrd = &new_attr->reg_data[i];
1597 if(arch_register_req_is(&rd->req.req, limited)) {
1598 const arch_register_req_t *req = &rd->req.req;
1599 arch_register_req_t *new_req = &newrd->req.req;
1601 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1603 if(arch_register_req_is(&rd->in_req.req, limited)) {
1604 const arch_register_req_t *req = &rd->in_req.req;
1605 arch_register_req_t *new_req = &newrd->in_req.req;
1607 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1613 static const ir_op_ops be_node_op_ops = {