2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Backend node support for generic backend nodes.
23 * @author Sebastian Hack
27 * Backend node support for generic backend nodes.
28 * This file provides Perm, Copy, Spill and Reload nodes.
43 #include "bitfiddle.h"
44 #include "raw_bitset.h"
56 #include "besched_t.h"
61 #define OUT_POS(x) (-((x) + 1))
63 /* Sometimes we want to put const nodes into get_irn_generic_attr ... */
64 #define get_irn_attr(irn) get_irn_generic_attr((ir_node *) (irn))
66 static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
69 arch_register_req_t req;
70 arch_irn_flags_t flags;
74 const arch_register_t *reg;
79 /** The generic be nodes attribute type. */
81 be_reg_data_t *reg_data;
84 /** The be_Return nodes attribute type. */
86 be_node_attr_t node_attr;
87 int num_ret_vals; /**< number of return values */
90 /** The be_Stack attribute type. */
92 be_node_attr_t node_attr;
93 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
96 /** The be_Frame attribute type. */
98 be_node_attr_t node_attr;
103 /** The be_Call attribute type. */
105 be_node_attr_t node_attr;
106 ir_entity *ent; /**< The called entity if this is a static call. */
107 ir_type *call_tp; /**< The call type, copied from the original Call node. */
111 be_node_attr_t node_attr;
112 ir_entity **in_entities;
113 ir_entity **out_entities;
119 ir_op *op_be_MemPerm;
122 ir_op *op_be_CopyKeep;
128 ir_op *op_be_RegParams;
129 ir_op *op_be_FrameAddr;
130 ir_op *op_be_Barrier;
132 static int beo_base = -1;
134 static const ir_op_ops be_node_op_ops;
136 #define N irop_flag_none
137 #define L irop_flag_labeled
138 #define C irop_flag_commutative
139 #define X irop_flag_cfopcode
140 #define I irop_flag_ip_cfopcode
141 #define F irop_flag_fragile
142 #define Y irop_flag_forking
143 #define H irop_flag_highlevel
144 #define c irop_flag_constlike
145 #define K irop_flag_keep
146 #define M irop_flag_machine
150 * Compare two node attributes.
152 * @return zero if both attributes are identically
154 static int _node_cmp_attr(be_node_attr_t *a, be_node_attr_t *b) {
157 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
160 len = ARR_LEN(a->reg_data);
161 for (i = 0; i < len; ++i) {
162 if (a->reg_data[i].reg != b->reg_data[i].reg ||
163 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
164 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
171 static int node_cmp_attr(ir_node *a, ir_node *b) {
172 be_node_attr_t *a_attr = get_irn_attr(a);
173 be_node_attr_t *b_attr = get_irn_attr(b);
175 return _node_cmp_attr(a_attr, b_attr);
179 * Compare the attributes of two FrameAddr nodes.
181 * @return zero if both attributes are identically
183 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
184 be_frame_attr_t *a_attr = get_irn_attr(a);
185 be_frame_attr_t *b_attr = get_irn_attr(b);
187 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
190 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
193 static int Return_cmp_attr(ir_node *a, ir_node *b) {
194 be_return_attr_t *a_attr = get_irn_attr(a);
195 be_return_attr_t *b_attr = get_irn_attr(b);
197 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
200 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
203 static int Stack_cmp_attr(ir_node *a, ir_node *b) {
204 be_stack_attr_t *a_attr = get_irn_attr(a);
205 be_stack_attr_t *b_attr = get_irn_attr(b);
207 if (a_attr->offset != b_attr->offset)
210 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
213 static int Call_cmp_attr(ir_node *a, ir_node *b) {
214 be_call_attr_t *a_attr = get_irn_attr(a);
215 be_call_attr_t *b_attr = get_irn_attr(b);
217 if (a_attr->ent != b_attr->ent ||
218 a_attr->call_tp != b_attr->call_tp)
221 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
224 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
227 be_node_attr_t *attr;
230 assert(is_be_node(node));
231 attr = get_irn_attr(node);
237 assert(idx < get_irn_arity(node));
239 assert(idx < ARR_LEN(attr->reg_data));
240 rd = &attr->reg_data[idx];
242 return pos < 0 ? &rd->req : &rd->in_req;
245 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
247 be_req_t *bereq = get_be_req(node, pos);
251 void be_node_init(void) {
252 static int inited = 0;
259 /* Acquire all needed opcodes. */
260 beo_base = get_next_ir_opcodes(beo_Last);
262 op_be_Spill = new_ir_op(beo_base + beo_Spill, "be_Spill", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
263 op_be_Reload = new_ir_op(beo_base + beo_Reload, "be_Reload", op_pin_state_pinned, N, oparity_zero, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
264 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);
265 op_be_MemPerm = new_ir_op(beo_base + beo_MemPerm, "be_MemPerm", op_pin_state_pinned, N, oparity_variable, 0, sizeof(be_memperm_attr_t), &be_node_op_ops);
266 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);
267 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);
268 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);
269 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);
270 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);
271 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);
272 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);
273 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);
274 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);
275 op_be_FrameAddr = new_ir_op(beo_base + beo_FrameAddr, "be_FrameAddr", op_pin_state_floats, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
276 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);
278 set_op_tag(op_be_Spill, &be_node_tag);
279 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
280 set_op_tag(op_be_Reload, &be_node_tag);
281 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
282 set_op_tag(op_be_Perm, &be_node_tag);
283 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
284 set_op_tag(op_be_MemPerm, &be_node_tag);
285 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
286 set_op_tag(op_be_Copy, &be_node_tag);
287 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
288 set_op_tag(op_be_Keep, &be_node_tag);
289 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
290 set_op_tag(op_be_CopyKeep, &be_node_tag);
291 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
292 set_op_tag(op_be_Call, &be_node_tag);
293 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
294 set_op_tag(op_be_Return, &be_node_tag);
295 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
296 set_op_tag(op_be_AddSP, &be_node_tag);
297 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
298 set_op_tag(op_be_SubSP, &be_node_tag);
299 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
300 set_op_tag(op_be_IncSP, &be_node_tag);
301 op_be_IncSP->ops.node_cmp_attr = Stack_cmp_attr;
302 set_op_tag(op_be_RegParams, &be_node_tag);
303 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
304 set_op_tag(op_be_FrameAddr, &be_node_tag);
305 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
306 set_op_tag(op_be_Barrier, &be_node_tag);
307 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
311 * Initializes the generic attribute of all be nodes and return ir.
313 static void *init_node_attr(ir_node *node, int max_reg_data)
315 ir_graph *irg = get_irn_irg(node);
316 struct obstack *obst = get_irg_obstack(irg);
317 be_node_attr_t *a = get_irn_attr(node);
319 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
321 if(max_reg_data >= 0) {
322 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
323 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
325 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
331 static void add_register_req(ir_node *node)
333 be_node_attr_t *a = get_irn_attr(node);
334 be_reg_data_t regreq;
335 memset(®req, 0, sizeof(regreq));
336 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
339 int is_be_node(const ir_node *irn)
341 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
344 be_opcode_t be_get_irn_opcode(const ir_node *irn)
346 return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
350 * Skip Proj nodes and return their Proj numbers.
352 * If *node is a Proj or Proj(Proj) node, skip it.
354 * @param node points to the node to be skipped
356 * @return 0 if *node was no Proj node, its Proj number else.
358 static int redir_proj(const ir_node **node)
360 const ir_node *n = *node;
365 *node = irn = get_Proj_pred(n);
367 assert(get_irn_mode(irn) == mode_T);
368 *node = get_Proj_pred(irn);
370 return get_Proj_proj(n);
376 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
378 be_node_attr_t *attr;
382 pos = get_Proj_proj(node);
383 node = get_Proj_pred(node);
386 assert(is_be_node(node));
387 attr = get_irn_attr(node);
388 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
390 return &attr->reg_data[pos];
394 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
396 be_reg_data_t *r = retrieve_reg_data(irn);
401 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
402 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
410 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
411 a = init_node_attr(res, 2);
415 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
416 be_node_set_reg_class(res, be_pos_Spill_val, cls);
420 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
421 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
428 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
430 init_node_attr(res, 2);
431 be_node_set_reg_class(res, -1, cls);
432 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
433 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
437 ir_node *be_get_Reload_mem(const ir_node *irn)
439 assert(be_is_Reload(irn));
440 return get_irn_n(irn, be_pos_Reload_mem);
443 ir_node *be_get_Reload_frame(const ir_node *irn)
445 assert(be_is_Reload(irn));
446 return get_irn_n(irn, be_pos_Reload_frame);
449 ir_node *be_get_Spill_val(const ir_node *irn)
451 assert(be_is_Spill(irn));
452 return get_irn_n(irn, be_pos_Spill_val);
455 ir_node *be_get_Spill_frame(const ir_node *irn)
457 assert(be_is_Spill(irn));
458 return get_irn_n(irn, be_pos_Spill_frame);
461 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
464 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
465 init_node_attr(irn, n);
466 for(i = 0; i < n; ++i) {
467 be_node_set_reg_class(irn, i, cls);
468 be_node_set_reg_class(irn, OUT_POS(i), cls);
474 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
476 ir_graph *irg = get_irn_irg(perm);
477 int arity = get_irn_arity(perm);
478 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
479 be_node_attr_t *attr = get_irn_attr(perm);
480 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
484 assert(be_is_Perm(perm));
485 assert(new_size <= arity);
487 /* save the old register data */
488 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
490 /* compose the new in array and set the new register data directly in place */
491 for (i = 0; i < new_size; ++i) {
493 new_in[i] = get_irn_n(perm, idx);
494 attr->reg_data[i] = old_data[idx];
497 set_irn_in(perm, new_size, new_in);
500 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
503 ir_node *frame = get_irg_frame(irg);
504 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
506 const arch_register_t *sp = arch_env->isa->sp;
507 be_memperm_attr_t *attr;
510 real_in = alloca((n+1) * sizeof(real_in[0]));
512 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
514 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
516 init_node_attr(irn, n + 1);
517 be_node_set_reg_class(irn, 0, sp->reg_class);
518 for(i = 0; i < n; ++i) {
519 be_node_set_reg_class(irn, i + 1, cls_frame);
520 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
523 attr = get_irn_attr(irn);
525 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
526 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
527 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
528 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
534 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
538 arch_register_req_t *req;
541 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
542 init_node_attr(res, 1);
543 be_node_set_reg_class(res, 0, cls);
544 be_node_set_reg_class(res, OUT_POS(0), cls);
546 req = get_req(res, OUT_POS(0));
548 req->type = arch_register_req_type_should_be_same;
554 ir_node *be_get_Copy_op(const ir_node *cpy) {
555 return get_irn_n(cpy, be_pos_Copy_op);
558 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
559 set_irn_n(cpy, be_pos_Copy_op, op);
562 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
567 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
568 init_node_attr(res, -1);
570 for(i = 0; i < n; ++i) {
571 add_irn_n(res, in[i]);
572 add_register_req(res);
573 be_node_set_reg_class(res, i, cls);
580 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
584 assert(be_is_Keep(keep));
585 n = add_irn_n(keep, node);
586 add_register_req(keep);
587 be_node_set_reg_class(keep, n, cls);
590 /* creates a be_Call */
591 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
592 int n_outs, int n, ir_node *in[], ir_type *call_tp)
595 int real_n = be_pos_Call_first_arg + n;
599 NEW_ARR_A(ir_node *, real_in, real_n);
600 real_in[be_pos_Call_mem] = mem;
601 real_in[be_pos_Call_sp] = sp;
602 real_in[be_pos_Call_ptr] = ptr;
603 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
605 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
606 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
608 a->call_tp = call_tp;
612 /* Gets the call entity or NULL if this is no static call. */
613 ir_entity *be_Call_get_entity(const ir_node *call) {
614 be_call_attr_t *a = get_irn_attr(call);
615 assert(be_is_Call(call));
619 /* Sets the call entity. */
620 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
621 be_call_attr_t *a = get_irn_attr(call);
622 assert(be_is_Call(call));
626 /* Gets the call type. */
627 ir_type *be_Call_get_type(ir_node *call) {
628 be_call_attr_t *a = get_irn_attr(call);
629 assert(be_is_Call(call));
633 /* Sets the call type. */
634 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
635 be_call_attr_t *a = get_irn_attr(call);
636 assert(be_is_Call(call));
637 a->call_tp = call_tp;
640 /* Construct a new be_Return. */
641 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
642 int n, ir_node *in[])
648 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
649 init_node_attr(res, -1);
650 for(i = 0; i < n; ++i) {
651 add_irn_n(res, in[i]);
652 add_register_req(res);
655 a = get_irn_attr(res);
656 a->num_ret_vals = n_res;
661 /* Returns the number of real returns values */
662 int be_Return_get_n_rets(ir_node *ret)
664 be_return_attr_t *a = get_irn_attr(ret);
665 return a->num_ret_vals;
668 int be_Return_append_node(ir_node *ret, ir_node *node)
672 pos = add_irn_n(ret, node);
673 add_register_req(ret);
678 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
685 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
686 a = init_node_attr(irn, 1);
689 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
691 /* Set output constraint to stack register. */
692 be_node_set_reg_class(irn, 0, sp->reg_class);
693 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
694 be_node_set_irn_reg(NULL, irn, sp);
699 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
703 ir_node *in[be_pos_AddSP_last];
704 const arch_register_class_t *class;
706 in[be_pos_AddSP_old_sp] = old_sp;
707 in[be_pos_AddSP_size] = sz;
709 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
710 a = init_node_attr(irn, be_pos_AddSP_last);
712 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
713 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
715 /* Set output constraint to stack register. */
716 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
717 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
718 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
719 a->reg_data[pn_be_AddSP_sp].reg = sp;
721 class = arch_register_get_class(sp);
722 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
727 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
731 ir_node *in[be_pos_SubSP_last];
733 in[be_pos_SubSP_old_sp] = old_sp;
734 in[be_pos_SubSP_size] = sz;
736 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
737 a = init_node_attr(irn, be_pos_SubSP_last);
739 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
740 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
742 /* Set output constraint to stack register. */
743 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
744 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
745 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
746 a->reg_data[pn_be_SubSP_sp].reg = sp;
751 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
756 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
757 init_node_attr(res, -1);
758 for(i = 0; i < n_outs; ++i)
759 add_register_req(res);
764 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
765 const arch_env_t *arch_env,
766 const arch_register_t *reg)
768 ir_graph *irg = get_irn_irg(regparams);
769 ir_node *block = get_nodes_block(regparams);
770 be_node_attr_t *attr = get_irn_attr(regparams);
771 const arch_register_class_t *cls = arch_register_get_class(reg);
772 ir_mode *mode = arch_register_class_mode(cls);
773 int n = ARR_LEN(attr->reg_data);
776 assert(be_is_RegParams(regparams));
777 proj = new_r_Proj(irg, block, regparams, mode, n);
778 add_register_req(regparams);
779 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
780 arch_set_irn_register(arch_env, proj, reg);
782 /* TODO decide, whether we need to set ignore/modify sp flags here? */
787 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
794 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
795 a = init_node_attr(irn, 1);
798 be_node_set_reg_class(irn, 0, cls_frame);
799 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
801 return optimize_node(irn);
804 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
805 assert(be_is_FrameAddr(node));
806 return get_irn_n(node, be_pos_FrameAddr_ptr);
809 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
811 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
815 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)
818 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
821 memcpy(&in[1], in_keep, n * sizeof(in[0]));
822 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
823 init_node_attr(irn, n + 1);
824 be_node_set_reg_class(irn, OUT_POS(0), cls);
825 be_node_set_reg_class(irn, 0, cls);
830 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)
835 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
838 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
839 return get_irn_n(cpy, be_pos_CopyKeep_op);
842 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
843 set_irn_n(cpy, be_pos_CopyKeep_op, op);
846 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
851 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
852 init_node_attr(res, -1);
853 for(i = 0; i < n; ++i) {
854 add_irn_n(res, in[i]);
855 add_register_req(res);
861 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
863 ir_graph *irg = get_irn_irg(barrier);
864 ir_node *block = get_nodes_block(barrier);
865 ir_mode *mode = get_irn_mode(node);
866 int n = add_irn_n(barrier, node);
868 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
869 add_register_req(barrier);
874 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
875 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
876 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
877 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
878 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
879 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
880 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
881 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
882 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
883 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
884 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
885 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
886 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
887 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
888 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
890 int be_has_frame_entity(const ir_node *irn)
892 switch(be_get_irn_opcode(irn)) {
902 ir_entity *be_get_frame_entity(const ir_node *irn)
904 if (be_has_frame_entity(irn)) {
905 be_frame_attr_t *a = get_irn_attr(irn);
911 int be_get_frame_offset(const ir_node *irn)
913 assert(is_be_node(irn));
914 if (be_has_frame_entity(irn)) {
915 be_frame_attr_t *a = get_irn_attr(irn);
921 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
923 be_memperm_attr_t *attr = get_irn_attr(irn);
925 assert(be_is_MemPerm(irn));
926 assert(n < be_get_MemPerm_entity_arity(irn));
928 attr->in_entities[n] = ent;
931 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
933 be_memperm_attr_t *attr = get_irn_attr(irn);
935 assert(be_is_MemPerm(irn));
936 assert(n < be_get_MemPerm_entity_arity(irn));
938 return attr->in_entities[n];
941 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
943 be_memperm_attr_t *attr = get_irn_attr(irn);
945 assert(be_is_MemPerm(irn));
946 assert(n < be_get_MemPerm_entity_arity(irn));
948 attr->out_entities[n] = ent;
951 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
953 be_memperm_attr_t *attr = get_irn_attr(irn);
955 assert(be_is_MemPerm(irn));
956 assert(n < be_get_MemPerm_entity_arity(irn));
958 return attr->out_entities[n];
961 int be_get_MemPerm_entity_arity(const ir_node *irn)
963 return get_irn_arity(irn) - 1;
966 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
968 arch_register_req_t *req = get_req(node, pos);
969 const arch_register_class_t *cls = arch_register_get_class(reg);
970 ir_graph *irg = get_irn_irg(node);
971 struct obstack *obst = get_irg_obstack(irg);
972 unsigned *limited_bitset;
974 assert(req->cls == NULL || req->cls == cls);
975 assert(! (req->type & arch_register_req_type_limited));
976 assert(req->limited == NULL);
978 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
979 rbitset_set(limited_bitset, arch_register_get_index(reg));
982 req->type |= arch_register_req_type_limited;
983 req->limited = limited_bitset;
986 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
988 ir_graph *irg = get_irn_irg(node);
989 struct obstack *obst = get_irg_obstack(irg);
990 arch_register_req_t *r = get_req(node, pos);
992 assert(arch_register_req_is(req, limited));
993 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
994 memcpy(r, req, sizeof(r[0]));
995 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
998 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1000 be_req_t *bereq = get_be_req(irn, pos);
1001 bereq->flags = flags;
1004 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1006 arch_register_req_t *req = get_req(irn, pos);
1011 req->type = arch_register_req_type_none;
1012 } else if (req->type == arch_register_req_type_none) {
1013 req->type = arch_register_req_type_normal;
1017 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1019 arch_register_req_t *req = get_req(irn, pos);
1023 ir_node *be_get_IncSP_pred(ir_node *irn) {
1024 assert(be_is_IncSP(irn));
1025 return get_irn_n(irn, 0);
1028 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1029 assert(be_is_IncSP(incsp));
1030 set_irn_n(incsp, 0, pred);
1033 void be_set_IncSP_offset(ir_node *irn, int offset)
1035 be_stack_attr_t *a = get_irn_attr(irn);
1036 assert(be_is_IncSP(irn));
1040 int be_get_IncSP_offset(const ir_node *irn)
1042 be_stack_attr_t *a = get_irn_attr(irn);
1043 assert(be_is_IncSP(irn));
1047 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
1049 ir_node *bl = get_nodes_block(irn);
1050 ir_graph *irg = get_irn_irg(bl);
1051 ir_node *frame = get_irg_frame(irg);
1052 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1053 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1056 spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
1060 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)
1063 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1064 ir_graph *irg = get_irn_irg(bl);
1065 ir_node *frame = get_irg_frame(irg);
1066 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1068 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1070 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1072 if (is_Block(insert)) {
1073 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1074 sched_add_after(insert, reload);
1076 sched_add_before(insert, reload);
1084 | _ \ ___ __ _ | _ \ ___ __ _ ___
1085 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1086 | _ < __/ (_| | | _ < __/ (_| \__ \
1087 |_| \_\___|\__, | |_| \_\___|\__, |___/
1094 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1096 const be_node_attr_t *a = get_irn_attr(irn);
1098 if(out_pos >= ARR_LEN(a->reg_data)) {
1099 return arch_no_register_req;
1102 return &a->reg_data[out_pos].req.req;
1106 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1108 const be_node_attr_t *a = get_irn_attr(irn);
1110 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1111 return arch_no_register_req;
1113 return &a->reg_data[pos].in_req.req;
1116 static const arch_register_req_t *
1117 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1123 if (get_irn_mode(irn) == mode_T)
1124 return arch_no_register_req;
1126 out_pos = redir_proj((const ir_node **)&irn);
1127 assert(is_be_node(irn));
1128 return get_out_reg_req(irn, out_pos);
1129 } else if (is_be_node(irn)) {
1131 * For spills and reloads, we return "none" as requirement for frame
1132 * pointer, so every input is ok. Some backends need this (e.g. STA).
1134 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1135 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1136 return arch_no_register_req;
1138 return get_in_reg_req(irn, pos);
1141 return arch_no_register_req;
1144 const arch_register_t *
1145 be_node_get_irn_reg(const void *self, const ir_node *irn)
1150 if (get_irn_mode(irn) == mode_T)
1152 r = retrieve_reg_data(irn);
1156 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1158 redir_proj((const ir_node **) &irn);
1161 switch(be_get_irn_opcode(irn)) {
1162 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1164 XXX(Reload, reload);
1167 XXX(Return, branch);
1170 return arch_irn_class_normal;
1176 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1183 pos = OUT_POS(get_Proj_proj(node));
1184 node = skip_Proj_const(node);
1187 bereq = get_be_req(node, pos);
1189 return bereq->flags;
1192 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1195 return be_get_frame_entity(irn);
1198 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1203 assert(be_has_frame_entity(irn));
1205 a = get_irn_attr(irn);
1209 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1212 if(be_has_frame_entity(irn)) {
1213 be_frame_attr_t *a = get_irn_attr(irn);
1218 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1221 return be_is_IncSP(irn) ? be_get_IncSP_offset(irn) : 0;
1225 ___ ____ _ _ _ _ _ _
1226 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1227 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1228 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1229 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1233 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1234 be_node_get_irn_reg_req,
1235 be_node_set_irn_reg,
1236 be_node_get_irn_reg,
1239 be_node_get_frame_entity,
1240 be_node_set_frame_entity,
1241 be_node_set_frame_offset,
1242 be_node_get_sp_bias,
1243 NULL, /* get_inverse */
1244 NULL, /* get_op_estimated_cost */
1245 NULL, /* possible_memory_operand */
1246 NULL, /* perform_memory_operand */
1249 static const arch_irn_ops_t be_node_irn_ops = {
1253 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1255 redir_proj((const ir_node **) &irn);
1257 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1260 const arch_irn_handler_t be_node_irn_handler = {
1265 ____ _ _ ___ ____ _ _ _ _ _ _
1266 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1267 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1268 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1269 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1274 const arch_register_t *reg;
1275 arch_register_req_t req;
1276 arch_irn_flags_t flags;
1280 arch_irn_handler_t irn_handler;
1281 arch_irn_ops_t irn_ops;
1282 const arch_env_t *arch_env;
1286 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1287 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1290 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1293 const phi_handler_t *h;
1294 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1297 h = get_phi_handler_from_handler(handler);
1302 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1304 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1306 ir_graph *irg = get_irn_irg(phi);
1307 struct obstack *obst = get_irg_obstack(irg);
1308 attr = obstack_alloc(obst, sizeof(attr[0]));
1309 memset(attr, 0, sizeof(attr[0]));
1310 pmap_insert(handler->phi_attrs, phi, attr);
1317 * Get register class of a Phi.
1320 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1324 int n = get_irn_arity(phi);
1328 if(*visited && pset_find_ptr(*visited, phi))
1331 for(i = 0; i < n; ++i) {
1332 op = get_irn_n(phi, i);
1333 /* Matze: don't we unnecessary constraint our phis with this?
1334 * we only need to take the regclass IMO*/
1336 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1340 * The operands of that Phi were all Phis themselves.
1341 * We have to start a DFS for a non-Phi argument now.
1344 *visited = pset_new_ptr(16);
1346 pset_insert_ptr(*visited, phi);
1348 for(i = 0; i < n; ++i) {
1349 const arch_register_req_t *req;
1350 op = get_irn_n(phi, i);
1351 req = get_Phi_reg_req_recursive(h, op, visited);
1360 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1361 const ir_node *irn, int pos)
1363 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1368 if(!mode_is_datab(get_irn_mode(irn)))
1369 return arch_no_register_req;
1371 attr = get_Phi_attr(phi_handler, irn);
1373 if(attr->req.type == arch_register_req_type_none) {
1374 pset *visited = NULL;
1375 const arch_register_req_t *req;
1376 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1378 memcpy(&attr->req, req, sizeof(req[0]));
1379 assert(attr->req.cls != NULL);
1380 attr->req.type = arch_register_req_type_normal;
1389 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1390 const arch_register_req_t *req)
1392 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1393 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1396 assert(mode_is_datab(get_irn_mode(node)));
1398 attr = get_Phi_attr(handler, node);
1399 memcpy(&attr->req, req, sizeof(req[0]));
1402 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1403 arch_irn_flags_t flags)
1405 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1406 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1409 assert(mode_is_datab(get_irn_mode(node)));
1411 attr = get_Phi_attr(handler, node);
1412 attr->flags = flags;
1416 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1418 phi_handler_t *h = get_phi_handler_from_ops(self);
1419 phi_attr_t *attr = get_Phi_attr(h, irn);
1424 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1426 phi_handler_t *h = get_phi_handler_from_ops(self);
1427 phi_attr_t *attr = get_Phi_attr(h, irn);
1432 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1436 return arch_irn_class_normal;
1440 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1442 phi_handler_t *h = get_phi_handler_from_ops(self);
1443 phi_attr_t *attr = get_Phi_attr(h, irn);
1449 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1457 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1466 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1475 int phi_get_sp_bias(const void* self, const ir_node *irn)
1483 const arch_irn_ops_if_t phi_irn_ops = {
1484 phi_get_irn_reg_req,
1489 phi_get_frame_entity,
1490 phi_set_frame_entity,
1491 phi_set_frame_offset,
1493 NULL, /* get_inverse */
1494 NULL, /* get_op_estimated_cost */
1495 NULL, /* possible_memory_operand */
1496 NULL, /* perform_memory_operand */
1499 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1501 phi_handler_t *h = xmalloc(sizeof(h[0]));
1502 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1503 h->irn_ops.impl = &phi_irn_ops;
1504 h->arch_env = arch_env;
1505 h->phi_attrs = pmap_create();
1506 return (arch_irn_handler_t *) h;
1509 void be_phi_handler_free(arch_irn_handler_t *handler)
1511 phi_handler_t *h = get_phi_handler_from_handler(handler);
1512 pmap_destroy(h->phi_attrs);
1513 h->phi_attrs = NULL;
1517 void be_phi_handler_reset(arch_irn_handler_t *handler)
1519 phi_handler_t *h = get_phi_handler_from_handler(handler);
1521 pmap_destroy(h->phi_attrs);
1522 h->phi_attrs = pmap_create();
1527 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1528 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1529 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1530 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1535 * Dumps a register requirement to a file.
1537 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1538 const ir_node *node)
1540 int did_something = 0;
1542 const char *prefix = buf;
1544 snprintf(buf, sizeof(buf), "#%d ", idx);
1545 buf[sizeof(buf) - 1] = '\0';
1550 arch_register_req_format(tmp, sizeof(tmp), req, node);
1551 fprintf(f, "%s", tmp);
1560 * Dumps node register requirements to a file.
1562 static void dump_node_reqs(FILE *f, ir_node *node)
1565 be_node_attr_t *a = get_irn_attr(node);
1566 int len = ARR_LEN(a->reg_data);
1568 fprintf(f, "registers: \n");
1569 for(i = 0; i < len; ++i) {
1570 be_reg_data_t *rd = &a->reg_data[i];
1572 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1575 fprintf(f, "in requirements:\n");
1576 for(i = 0; i < len; ++i) {
1577 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1580 fprintf(f, "\nout requirements:\n");
1581 for(i = 0; i < len; ++i) {
1582 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1587 * ir_op-Operation: dump a be node to file
1589 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1591 be_node_attr_t *at = get_irn_attr(irn);
1593 assert(is_be_node(irn));
1596 case dump_node_opcode_txt:
1597 fprintf(f, get_op_name(get_irn_op(irn)));
1599 case dump_node_mode_txt:
1600 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1601 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1604 case dump_node_nodeattr_txt:
1605 if(be_is_Call(irn)) {
1606 be_call_attr_t *a = (be_call_attr_t *) at;
1608 fprintf(f, " [%s] ", get_entity_name(a->ent));
1610 if(be_is_IncSP(irn)) {
1611 const be_stack_attr_t *attr = get_irn_generic_attr_const(irn);
1612 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1613 fprintf(f, " [Setup Stackframe] ");
1614 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1615 fprintf(f, " [Destroy Stackframe] ");
1617 fprintf(f, " [%d] ", attr->offset);
1621 case dump_node_info_txt:
1622 dump_node_reqs(f, irn);
1624 if(be_has_frame_entity(irn)) {
1625 be_frame_attr_t *a = (be_frame_attr_t *) at;
1627 int bits = get_type_size_bits(get_entity_type(a->ent));
1628 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1629 a->ent, a->offset, a->offset, bits, bits);
1634 switch(be_get_irn_opcode(irn)) {
1637 be_stack_attr_t *a = (be_stack_attr_t *) at;
1638 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1639 fprintf(f, "offset: FRAME_SIZE\n");
1640 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1641 fprintf(f, "offset: -FRAME SIZE\n");
1643 fprintf(f, "offset: %u\n", a->offset);
1648 be_call_attr_t *a = (be_call_attr_t *) at;
1651 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1657 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1658 ir_entity *in, *out;
1659 in = be_get_MemPerm_in_entity(irn, i);
1660 out = be_get_MemPerm_out_entity(irn, i);
1662 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1665 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1681 * Copies the backend specific attributes from old node to new node.
1683 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1685 be_node_attr_t *old_attr = get_irn_attr(old_node);
1686 be_node_attr_t *new_attr = get_irn_attr(new_node);
1687 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1690 assert(is_be_node(old_node));
1691 assert(is_be_node(new_node));
1693 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1694 new_attr->reg_data = NULL;
1696 if(old_attr->reg_data != NULL)
1697 len = ARR_LEN(old_attr->reg_data);
1701 if(get_irn_op(old_node)->opar == oparity_dynamic
1702 || be_is_RegParams(old_node)) {
1703 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1705 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1709 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1710 for(i = 0; i < len; ++i) {
1711 const be_reg_data_t *rd = &old_attr->reg_data[i];
1712 be_reg_data_t *newrd = &new_attr->reg_data[i];
1713 if(arch_register_req_is(&rd->req.req, limited)) {
1714 const arch_register_req_t *req = &rd->req.req;
1715 arch_register_req_t *new_req = &newrd->req.req;
1717 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1719 if(arch_register_req_is(&rd->in_req.req, limited)) {
1720 const arch_register_req_t *req = &rd->in_req.req;
1721 arch_register_req_t *new_req = &newrd->in_req.req;
1723 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1729 static const ir_op_ops be_node_op_ops = {