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;
549 req->other_same[0] = 0;
550 req->other_same[1] = -1;
555 ir_node *be_get_Copy_op(const ir_node *cpy) {
556 return get_irn_n(cpy, be_pos_Copy_op);
559 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
560 set_irn_n(cpy, be_pos_Copy_op, op);
563 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
568 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
569 init_node_attr(res, -1);
571 for(i = 0; i < n; ++i) {
572 add_irn_n(res, in[i]);
573 add_register_req(res);
574 be_node_set_reg_class(res, i, cls);
581 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
585 assert(be_is_Keep(keep));
586 n = add_irn_n(keep, node);
587 add_register_req(keep);
588 be_node_set_reg_class(keep, n, cls);
591 /* creates a be_Call */
592 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
593 int n_outs, int n, ir_node *in[], ir_type *call_tp)
596 int real_n = be_pos_Call_first_arg + n;
600 NEW_ARR_A(ir_node *, real_in, real_n);
601 real_in[be_pos_Call_mem] = mem;
602 real_in[be_pos_Call_sp] = sp;
603 real_in[be_pos_Call_ptr] = ptr;
604 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
606 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
607 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
609 a->call_tp = call_tp;
613 /* Gets the call entity or NULL if this is no static call. */
614 ir_entity *be_Call_get_entity(const ir_node *call) {
615 be_call_attr_t *a = get_irn_attr(call);
616 assert(be_is_Call(call));
620 /* Sets the call entity. */
621 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
622 be_call_attr_t *a = get_irn_attr(call);
623 assert(be_is_Call(call));
627 /* Gets the call type. */
628 ir_type *be_Call_get_type(ir_node *call) {
629 be_call_attr_t *a = get_irn_attr(call);
630 assert(be_is_Call(call));
634 /* Sets the call type. */
635 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
636 be_call_attr_t *a = get_irn_attr(call);
637 assert(be_is_Call(call));
638 a->call_tp = call_tp;
641 /* Construct a new be_Return. */
642 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
643 int n, ir_node *in[])
649 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
650 init_node_attr(res, -1);
651 for(i = 0; i < n; ++i) {
652 add_irn_n(res, in[i]);
653 add_register_req(res);
656 a = get_irn_attr(res);
657 a->num_ret_vals = n_res;
662 /* Returns the number of real returns values */
663 int be_Return_get_n_rets(ir_node *ret)
665 be_return_attr_t *a = get_irn_attr(ret);
666 return a->num_ret_vals;
669 int be_Return_append_node(ir_node *ret, ir_node *node)
673 pos = add_irn_n(ret, node);
674 add_register_req(ret);
679 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
686 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
687 a = init_node_attr(irn, 1);
690 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
692 /* Set output constraint to stack register. */
693 be_node_set_reg_class(irn, 0, sp->reg_class);
694 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
695 be_node_set_irn_reg(NULL, irn, sp);
700 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
704 ir_node *in[be_pos_AddSP_last];
705 const arch_register_class_t *class;
707 in[be_pos_AddSP_old_sp] = old_sp;
708 in[be_pos_AddSP_size] = sz;
710 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
711 a = init_node_attr(irn, be_pos_AddSP_last);
713 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
714 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
716 /* Set output constraint to stack register. */
717 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
718 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
719 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
720 a->reg_data[pn_be_AddSP_sp].reg = sp;
722 class = arch_register_get_class(sp);
723 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
728 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
732 ir_node *in[be_pos_SubSP_last];
734 in[be_pos_SubSP_old_sp] = old_sp;
735 in[be_pos_SubSP_size] = sz;
737 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
738 a = init_node_attr(irn, be_pos_SubSP_last);
740 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
741 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
743 /* Set output constraint to stack register. */
744 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
745 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
746 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
747 a->reg_data[pn_be_SubSP_sp].reg = sp;
752 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
757 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
758 init_node_attr(res, -1);
759 for(i = 0; i < n_outs; ++i)
760 add_register_req(res);
765 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
766 const arch_env_t *arch_env,
767 const arch_register_t *reg)
769 ir_graph *irg = get_irn_irg(regparams);
770 ir_node *block = get_nodes_block(regparams);
771 be_node_attr_t *attr = get_irn_attr(regparams);
772 const arch_register_class_t *cls = arch_register_get_class(reg);
773 ir_mode *mode = arch_register_class_mode(cls);
774 int n = ARR_LEN(attr->reg_data);
777 assert(be_is_RegParams(regparams));
778 proj = new_r_Proj(irg, block, regparams, mode, n);
779 add_register_req(regparams);
780 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
781 arch_set_irn_register(arch_env, proj, reg);
783 /* TODO decide, whether we need to set ignore/modify sp flags here? */
788 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
795 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
796 a = init_node_attr(irn, 1);
799 be_node_set_reg_class(irn, 0, cls_frame);
800 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
802 return optimize_node(irn);
805 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
806 assert(be_is_FrameAddr(node));
807 return get_irn_n(node, be_pos_FrameAddr_ptr);
810 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
812 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
816 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)
819 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
822 memcpy(&in[1], in_keep, n * sizeof(in[0]));
823 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
824 init_node_attr(irn, n + 1);
825 be_node_set_reg_class(irn, OUT_POS(0), cls);
826 be_node_set_reg_class(irn, 0, cls);
831 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)
836 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
839 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
840 return get_irn_n(cpy, be_pos_CopyKeep_op);
843 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
844 set_irn_n(cpy, be_pos_CopyKeep_op, op);
847 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
852 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
853 init_node_attr(res, -1);
854 for(i = 0; i < n; ++i) {
855 add_irn_n(res, in[i]);
856 add_register_req(res);
862 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
864 ir_graph *irg = get_irn_irg(barrier);
865 ir_node *block = get_nodes_block(barrier);
866 ir_mode *mode = get_irn_mode(node);
867 int n = add_irn_n(barrier, node);
869 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
870 add_register_req(barrier);
875 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
876 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
877 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
878 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
879 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
880 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
881 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
882 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
883 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
884 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
885 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
886 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
887 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
888 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
889 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
891 int be_has_frame_entity(const ir_node *irn)
893 switch(be_get_irn_opcode(irn)) {
903 ir_entity *be_get_frame_entity(const ir_node *irn)
905 if (be_has_frame_entity(irn)) {
906 be_frame_attr_t *a = get_irn_attr(irn);
912 int be_get_frame_offset(const ir_node *irn)
914 assert(is_be_node(irn));
915 if (be_has_frame_entity(irn)) {
916 be_frame_attr_t *a = get_irn_attr(irn);
922 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
924 be_memperm_attr_t *attr = get_irn_attr(irn);
926 assert(be_is_MemPerm(irn));
927 assert(n < be_get_MemPerm_entity_arity(irn));
929 attr->in_entities[n] = ent;
932 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
934 be_memperm_attr_t *attr = get_irn_attr(irn);
936 assert(be_is_MemPerm(irn));
937 assert(n < be_get_MemPerm_entity_arity(irn));
939 return attr->in_entities[n];
942 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
944 be_memperm_attr_t *attr = get_irn_attr(irn);
946 assert(be_is_MemPerm(irn));
947 assert(n < be_get_MemPerm_entity_arity(irn));
949 attr->out_entities[n] = ent;
952 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
954 be_memperm_attr_t *attr = get_irn_attr(irn);
956 assert(be_is_MemPerm(irn));
957 assert(n < be_get_MemPerm_entity_arity(irn));
959 return attr->out_entities[n];
962 int be_get_MemPerm_entity_arity(const ir_node *irn)
964 return get_irn_arity(irn) - 1;
967 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
969 arch_register_req_t *req = get_req(node, pos);
970 const arch_register_class_t *cls = arch_register_get_class(reg);
971 ir_graph *irg = get_irn_irg(node);
972 struct obstack *obst = get_irg_obstack(irg);
973 unsigned *limited_bitset;
975 assert(req->cls == NULL || req->cls == cls);
976 assert(! (req->type & arch_register_req_type_limited));
977 assert(req->limited == NULL);
979 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
980 rbitset_set(limited_bitset, arch_register_get_index(reg));
983 req->type |= arch_register_req_type_limited;
984 req->limited = limited_bitset;
987 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
989 ir_graph *irg = get_irn_irg(node);
990 struct obstack *obst = get_irg_obstack(irg);
991 arch_register_req_t *r = get_req(node, pos);
993 assert(arch_register_req_is(req, limited));
994 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
995 memcpy(r, req, sizeof(r[0]));
996 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
999 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1001 be_req_t *bereq = get_be_req(irn, pos);
1002 bereq->flags = flags;
1005 void be_node_add_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1007 be_req_t *bereq = get_be_req(irn, pos);
1008 bereq->flags |= flags;
1011 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1013 arch_register_req_t *req = get_req(irn, pos);
1018 req->type = arch_register_req_type_none;
1019 } else if (req->type == arch_register_req_type_none) {
1020 req->type = arch_register_req_type_normal;
1024 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1026 arch_register_req_t *req = get_req(irn, pos);
1030 ir_node *be_get_IncSP_pred(ir_node *irn) {
1031 assert(be_is_IncSP(irn));
1032 return get_irn_n(irn, 0);
1035 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1036 assert(be_is_IncSP(incsp));
1037 set_irn_n(incsp, 0, pred);
1040 void be_set_IncSP_offset(ir_node *irn, int offset)
1042 be_stack_attr_t *a = get_irn_attr(irn);
1043 assert(be_is_IncSP(irn));
1047 int be_get_IncSP_offset(const ir_node *irn)
1049 be_stack_attr_t *a = get_irn_attr(irn);
1050 assert(be_is_IncSP(irn));
1054 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
1056 ir_node *bl = get_nodes_block(irn);
1057 ir_graph *irg = get_irn_irg(bl);
1058 ir_node *frame = get_irg_frame(irg);
1059 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1060 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1063 spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
1067 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)
1070 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1071 ir_graph *irg = get_irn_irg(bl);
1072 ir_node *frame = get_irg_frame(irg);
1073 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1075 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1077 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1079 if (is_Block(insert)) {
1080 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1081 sched_add_after(insert, reload);
1083 sched_add_before(insert, reload);
1091 | _ \ ___ __ _ | _ \ ___ __ _ ___
1092 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1093 | _ < __/ (_| | | _ < __/ (_| \__ \
1094 |_| \_\___|\__, | |_| \_\___|\__, |___/
1101 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1103 const be_node_attr_t *a = get_irn_attr(irn);
1105 if(out_pos >= ARR_LEN(a->reg_data)) {
1106 return arch_no_register_req;
1109 return &a->reg_data[out_pos].req.req;
1113 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1115 const be_node_attr_t *a = get_irn_attr(irn);
1117 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1118 return arch_no_register_req;
1120 return &a->reg_data[pos].in_req.req;
1123 static const arch_register_req_t *
1124 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1130 if (get_irn_mode(irn) == mode_T)
1131 return arch_no_register_req;
1133 out_pos = redir_proj((const ir_node **)&irn);
1134 assert(is_be_node(irn));
1135 return get_out_reg_req(irn, out_pos);
1136 } else if (is_be_node(irn)) {
1138 * For spills and reloads, we return "none" as requirement for frame
1139 * pointer, so every input is ok. Some backends need this (e.g. STA).
1141 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1142 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1143 return arch_no_register_req;
1145 return get_in_reg_req(irn, pos);
1148 return arch_no_register_req;
1151 const arch_register_t *
1152 be_node_get_irn_reg(const void *self, const ir_node *irn)
1157 if (get_irn_mode(irn) == mode_T)
1159 r = retrieve_reg_data(irn);
1163 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1165 redir_proj((const ir_node **) &irn);
1168 switch(be_get_irn_opcode(irn)) {
1169 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1171 XXX(Reload, reload);
1174 XXX(Return, branch);
1177 return arch_irn_class_normal;
1183 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1190 pos = OUT_POS(get_Proj_proj(node));
1191 node = skip_Proj_const(node);
1194 bereq = get_be_req(node, pos);
1196 return bereq->flags;
1199 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1202 return be_get_frame_entity(irn);
1205 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1210 assert(be_has_frame_entity(irn));
1212 a = get_irn_attr(irn);
1216 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1219 if(be_has_frame_entity(irn)) {
1220 be_frame_attr_t *a = get_irn_attr(irn);
1225 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1228 return be_is_IncSP(irn) ? be_get_IncSP_offset(irn) : 0;
1232 ___ ____ _ _ _ _ _ _
1233 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1234 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1235 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1236 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1240 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1241 be_node_get_irn_reg_req,
1242 be_node_set_irn_reg,
1243 be_node_get_irn_reg,
1246 be_node_get_frame_entity,
1247 be_node_set_frame_entity,
1248 be_node_set_frame_offset,
1249 be_node_get_sp_bias,
1250 NULL, /* get_inverse */
1251 NULL, /* get_op_estimated_cost */
1252 NULL, /* possible_memory_operand */
1253 NULL, /* perform_memory_operand */
1256 static const arch_irn_ops_t be_node_irn_ops = {
1260 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1262 redir_proj((const ir_node **) &irn);
1264 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1267 const arch_irn_handler_t be_node_irn_handler = {
1272 ____ _ _ ___ ____ _ _ _ _ _ _
1273 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1274 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1275 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1276 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1281 const arch_register_t *reg;
1282 arch_register_req_t req;
1283 arch_irn_flags_t flags;
1287 arch_irn_handler_t irn_handler;
1288 arch_irn_ops_t irn_ops;
1289 const arch_env_t *arch_env;
1293 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1294 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1297 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1300 const phi_handler_t *h;
1301 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1304 h = get_phi_handler_from_handler(handler);
1309 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1311 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1313 ir_graph *irg = get_irn_irg(phi);
1314 struct obstack *obst = get_irg_obstack(irg);
1315 attr = obstack_alloc(obst, sizeof(attr[0]));
1316 memset(attr, 0, sizeof(attr[0]));
1317 pmap_insert(handler->phi_attrs, phi, attr);
1324 * Get register class of a Phi.
1327 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1331 int n = get_irn_arity(phi);
1335 if(*visited && pset_find_ptr(*visited, phi))
1338 for(i = 0; i < n; ++i) {
1339 op = get_irn_n(phi, i);
1340 /* Matze: don't we unnecessary constraint our phis with this?
1341 * we only need to take the regclass IMO*/
1343 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1347 * The operands of that Phi were all Phis themselves.
1348 * We have to start a DFS for a non-Phi argument now.
1351 *visited = pset_new_ptr(16);
1353 pset_insert_ptr(*visited, phi);
1355 for(i = 0; i < n; ++i) {
1356 const arch_register_req_t *req;
1357 op = get_irn_n(phi, i);
1358 req = get_Phi_reg_req_recursive(h, op, visited);
1367 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1368 const ir_node *irn, int pos)
1370 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1375 if(!mode_is_datab(get_irn_mode(irn)))
1376 return arch_no_register_req;
1378 attr = get_Phi_attr(phi_handler, irn);
1380 if(attr->req.type == arch_register_req_type_none) {
1381 pset *visited = NULL;
1382 const arch_register_req_t *req;
1383 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1385 memcpy(&attr->req, req, sizeof(req[0]));
1386 assert(attr->req.cls != NULL);
1387 attr->req.type = arch_register_req_type_normal;
1396 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1397 const arch_register_req_t *req)
1399 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1400 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1403 assert(mode_is_datab(get_irn_mode(node)));
1405 attr = get_Phi_attr(handler, node);
1406 memcpy(&attr->req, req, sizeof(req[0]));
1409 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1410 arch_irn_flags_t flags)
1412 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1413 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1416 assert(mode_is_datab(get_irn_mode(node)));
1418 attr = get_Phi_attr(handler, node);
1419 attr->flags = flags;
1423 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1425 phi_handler_t *h = get_phi_handler_from_ops(self);
1426 phi_attr_t *attr = get_Phi_attr(h, irn);
1431 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1433 phi_handler_t *h = get_phi_handler_from_ops(self);
1434 phi_attr_t *attr = get_Phi_attr(h, irn);
1439 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1443 return arch_irn_class_normal;
1447 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1449 phi_handler_t *h = get_phi_handler_from_ops(self);
1450 phi_attr_t *attr = get_Phi_attr(h, irn);
1456 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1464 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1473 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1482 int phi_get_sp_bias(const void* self, const ir_node *irn)
1490 const arch_irn_ops_if_t phi_irn_ops = {
1491 phi_get_irn_reg_req,
1496 phi_get_frame_entity,
1497 phi_set_frame_entity,
1498 phi_set_frame_offset,
1500 NULL, /* get_inverse */
1501 NULL, /* get_op_estimated_cost */
1502 NULL, /* possible_memory_operand */
1503 NULL, /* perform_memory_operand */
1506 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1508 phi_handler_t *h = xmalloc(sizeof(h[0]));
1509 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1510 h->irn_ops.impl = &phi_irn_ops;
1511 h->arch_env = arch_env;
1512 h->phi_attrs = pmap_create();
1513 return (arch_irn_handler_t *) h;
1516 void be_phi_handler_free(arch_irn_handler_t *handler)
1518 phi_handler_t *h = get_phi_handler_from_handler(handler);
1519 pmap_destroy(h->phi_attrs);
1520 h->phi_attrs = NULL;
1524 void be_phi_handler_reset(arch_irn_handler_t *handler)
1526 phi_handler_t *h = get_phi_handler_from_handler(handler);
1528 pmap_destroy(h->phi_attrs);
1529 h->phi_attrs = pmap_create();
1534 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1535 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1536 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1537 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1542 * Dumps a register requirement to a file.
1544 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1545 const ir_node *node)
1547 int did_something = 0;
1549 const char *prefix = buf;
1551 snprintf(buf, sizeof(buf), "#%d ", idx);
1552 buf[sizeof(buf) - 1] = '\0';
1557 arch_register_req_format(tmp, sizeof(tmp), req, node);
1558 fprintf(f, "%s", tmp);
1567 * Dumps node register requirements to a file.
1569 static void dump_node_reqs(FILE *f, ir_node *node)
1572 be_node_attr_t *a = get_irn_attr(node);
1573 int len = ARR_LEN(a->reg_data);
1575 fprintf(f, "registers: \n");
1576 for(i = 0; i < len; ++i) {
1577 be_reg_data_t *rd = &a->reg_data[i];
1579 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1582 fprintf(f, "in requirements:\n");
1583 for(i = 0; i < len; ++i) {
1584 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1587 fprintf(f, "\nout requirements:\n");
1588 for(i = 0; i < len; ++i) {
1589 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1594 * ir_op-Operation: dump a be node to file
1596 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1598 be_node_attr_t *at = get_irn_attr(irn);
1600 assert(is_be_node(irn));
1603 case dump_node_opcode_txt:
1604 fprintf(f, get_op_name(get_irn_op(irn)));
1606 case dump_node_mode_txt:
1607 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1608 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1611 case dump_node_nodeattr_txt:
1612 if(be_is_Call(irn)) {
1613 be_call_attr_t *a = (be_call_attr_t *) at;
1615 fprintf(f, " [%s] ", get_entity_name(a->ent));
1617 if(be_is_IncSP(irn)) {
1618 const be_stack_attr_t *attr = get_irn_generic_attr_const(irn);
1619 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1620 fprintf(f, " [Setup Stackframe] ");
1621 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1622 fprintf(f, " [Destroy Stackframe] ");
1624 fprintf(f, " [%d] ", attr->offset);
1628 case dump_node_info_txt:
1629 dump_node_reqs(f, irn);
1631 if(be_has_frame_entity(irn)) {
1632 be_frame_attr_t *a = (be_frame_attr_t *) at;
1634 int bits = get_type_size_bits(get_entity_type(a->ent));
1635 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1636 a->ent, a->offset, a->offset, bits, bits);
1641 switch(be_get_irn_opcode(irn)) {
1644 be_stack_attr_t *a = (be_stack_attr_t *) at;
1645 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1646 fprintf(f, "offset: FRAME_SIZE\n");
1647 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1648 fprintf(f, "offset: -FRAME SIZE\n");
1650 fprintf(f, "offset: %u\n", a->offset);
1655 be_call_attr_t *a = (be_call_attr_t *) at;
1658 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1664 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1665 ir_entity *in, *out;
1666 in = be_get_MemPerm_in_entity(irn, i);
1667 out = be_get_MemPerm_out_entity(irn, i);
1669 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1672 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1688 * Copies the backend specific attributes from old node to new node.
1690 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1692 be_node_attr_t *old_attr = get_irn_attr(old_node);
1693 be_node_attr_t *new_attr = get_irn_attr(new_node);
1694 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1697 assert(is_be_node(old_node));
1698 assert(is_be_node(new_node));
1700 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1701 new_attr->reg_data = NULL;
1703 if(old_attr->reg_data != NULL)
1704 len = ARR_LEN(old_attr->reg_data);
1708 if(get_irn_op(old_node)->opar == oparity_dynamic
1709 || be_is_RegParams(old_node)) {
1710 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1712 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1716 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1717 for(i = 0; i < len; ++i) {
1718 const be_reg_data_t *rd = &old_attr->reg_data[i];
1719 be_reg_data_t *newrd = &new_attr->reg_data[i];
1720 if(arch_register_req_is(&rd->req.req, limited)) {
1721 const arch_register_req_t *req = &rd->req.req;
1722 arch_register_req_t *new_req = &newrd->req.req;
1724 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1726 if(arch_register_req_is(&rd->in_req.req, limited)) {
1727 const arch_register_req_t *req = &rd->in_req.req;
1728 arch_register_req_t *new_req = &newrd->in_req.req;
1730 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1736 static const ir_op_ops be_node_op_ops = {