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"
62 #define OUT_POS(x) (-((x) + 1))
64 #define get_irn_attr(irn) get_irn_generic_attr(irn)
65 #define get_irn_attr_const(irn) get_irn_generic_attr_const(irn)
67 static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
70 arch_register_req_t req;
71 arch_irn_flags_t flags;
75 const arch_register_t *reg;
80 /** The generic be nodes attribute type. */
82 be_reg_data_t *reg_data;
85 /** The be_Return nodes attribute type. */
87 be_node_attr_t node_attr;
88 int num_ret_vals; /**< number of return values */
89 unsigned pop; /**< number of bytes that should be popped */
92 /** The be_Stack attribute type. */
94 be_node_attr_t node_attr;
95 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
98 /** The be_Frame attribute type. */
100 be_node_attr_t node_attr;
105 /** The be_Call attribute type. */
107 be_node_attr_t node_attr;
108 ir_entity *ent; /**< The called entity if this is a static call. */
110 ir_type *call_tp; /**< The call type, copied from the original Call node. */
114 be_node_attr_t node_attr;
115 ir_entity **in_entities;
116 ir_entity **out_entities;
122 ir_op *op_be_MemPerm;
125 ir_op *op_be_CopyKeep;
131 ir_op *op_be_RegParams;
132 ir_op *op_be_FrameAddr;
133 ir_op *op_be_Barrier;
135 static int beo_base = -1;
137 static const ir_op_ops be_node_op_ops;
139 #define N irop_flag_none
140 #define L irop_flag_labeled
141 #define C irop_flag_commutative
142 #define X irop_flag_cfopcode
143 #define I irop_flag_ip_cfopcode
144 #define F irop_flag_fragile
145 #define Y irop_flag_forking
146 #define H irop_flag_highlevel
147 #define c irop_flag_constlike
148 #define K irop_flag_keep
149 #define M irop_flag_uses_memory
153 * Compare two node attributes.
155 * @return zero if both attributes are identically
157 static int _node_cmp_attr(be_node_attr_t *a, be_node_attr_t *b) {
160 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
163 len = ARR_LEN(a->reg_data);
164 for (i = 0; i < len; ++i) {
165 if (a->reg_data[i].reg != b->reg_data[i].reg ||
166 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
167 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
174 static int node_cmp_attr(ir_node *a, ir_node *b) {
175 be_node_attr_t *a_attr = get_irn_attr(a);
176 be_node_attr_t *b_attr = get_irn_attr(b);
178 return _node_cmp_attr(a_attr, b_attr);
182 * Compare the attributes of two FrameAddr nodes.
184 * @return zero if both attributes are identically
186 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
187 be_frame_attr_t *a_attr = get_irn_attr(a);
188 be_frame_attr_t *b_attr = get_irn_attr(b);
190 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
193 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
196 static int Return_cmp_attr(ir_node *a, ir_node *b) {
197 be_return_attr_t *a_attr = get_irn_attr(a);
198 be_return_attr_t *b_attr = get_irn_attr(b);
200 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
202 if (a_attr->pop != b_attr->pop)
205 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
208 static int Stack_cmp_attr(ir_node *a, ir_node *b) {
209 be_stack_attr_t *a_attr = get_irn_attr(a);
210 be_stack_attr_t *b_attr = get_irn_attr(b);
212 if (a_attr->offset != b_attr->offset)
215 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
218 static int Call_cmp_attr(ir_node *a, ir_node *b) {
219 be_call_attr_t *a_attr = get_irn_attr(a);
220 be_call_attr_t *b_attr = get_irn_attr(b);
222 if (a_attr->ent != b_attr->ent ||
223 a_attr->call_tp != b_attr->call_tp)
226 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
229 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
232 const be_node_attr_t *attr;
235 assert(is_be_node(node));
236 attr = get_irn_attr_const(node);
242 assert(idx < get_irn_arity(node));
244 assert(idx < ARR_LEN(attr->reg_data));
245 rd = &attr->reg_data[idx];
247 return pos < 0 ? &rd->req : &rd->in_req;
250 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
252 be_req_t *bereq = get_be_req(node, pos);
256 void be_node_init(void) {
257 static int inited = 0;
264 /* Acquire all needed opcodes. */
265 beo_base = get_next_ir_opcodes(beo_Last);
267 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);
268 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);
269 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);
270 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);
271 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);
272 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);
273 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);
274 op_be_Call = new_ir_op(beo_base + beo_Call, "be_Call", op_pin_state_pinned, F|M, oparity_variable, 0, sizeof(be_call_attr_t), &be_node_op_ops);
275 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);
276 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);
277 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);
278 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);
279 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);
280 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);
281 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);
283 set_op_tag(op_be_Spill, &be_node_tag);
284 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
285 set_op_tag(op_be_Reload, &be_node_tag);
286 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
287 set_op_tag(op_be_Perm, &be_node_tag);
288 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
289 set_op_tag(op_be_MemPerm, &be_node_tag);
290 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
291 set_op_tag(op_be_Copy, &be_node_tag);
292 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
293 set_op_tag(op_be_Keep, &be_node_tag);
294 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
295 set_op_tag(op_be_CopyKeep, &be_node_tag);
296 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
297 set_op_tag(op_be_Call, &be_node_tag);
298 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
299 set_op_tag(op_be_Return, &be_node_tag);
300 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
301 set_op_tag(op_be_AddSP, &be_node_tag);
302 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
303 set_op_tag(op_be_SubSP, &be_node_tag);
304 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
305 set_op_tag(op_be_IncSP, &be_node_tag);
306 op_be_IncSP->ops.node_cmp_attr = Stack_cmp_attr;
307 set_op_tag(op_be_RegParams, &be_node_tag);
308 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
309 set_op_tag(op_be_FrameAddr, &be_node_tag);
310 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
311 set_op_tag(op_be_Barrier, &be_node_tag);
312 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
316 * Initializes the generic attribute of all be nodes and return ir.
318 static void *init_node_attr(ir_node *node, int max_reg_data)
320 ir_graph *irg = get_irn_irg(node);
321 struct obstack *obst = get_irg_obstack(irg);
322 be_node_attr_t *a = get_irn_attr(node);
324 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
326 if(max_reg_data >= 0) {
327 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
328 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
330 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
336 static void add_register_req(ir_node *node)
338 be_node_attr_t *a = get_irn_attr(node);
339 be_reg_data_t regreq;
340 memset(®req, 0, sizeof(regreq));
341 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
344 int is_be_node(const ir_node *irn)
346 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
349 be_opcode_t be_get_irn_opcode(const ir_node *irn)
351 return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
355 * Skip Proj nodes and return their Proj numbers.
357 * If *node is a Proj or Proj(Proj) node, skip it.
359 * @param node points to the node to be skipped
361 * @return 0 if *node was no Proj node, its Proj number else.
363 static int redir_proj(const ir_node **node)
365 const ir_node *n = *node;
370 *node = irn = get_Proj_pred(n);
372 assert(get_irn_mode(irn) == mode_T);
373 *node = get_Proj_pred(irn);
375 return get_Proj_proj(n);
381 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
383 const be_node_attr_t *attr;
387 pos = get_Proj_proj(node);
388 node = get_Proj_pred(node);
391 assert(is_be_node(node));
392 attr = get_irn_attr_const(node);
393 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
395 return &attr->reg_data[pos];
399 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
401 be_reg_data_t *r = retrieve_reg_data(irn);
406 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
407 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
415 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
416 a = init_node_attr(res, 2);
420 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
421 be_node_set_reg_class(res, be_pos_Spill_val, cls);
425 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
426 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
433 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
435 init_node_attr(res, 2);
436 be_node_set_reg_class(res, -1, cls);
437 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
438 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
442 ir_node *be_get_Reload_mem(const ir_node *irn)
444 assert(be_is_Reload(irn));
445 return get_irn_n(irn, be_pos_Reload_mem);
448 ir_node *be_get_Reload_frame(const ir_node *irn)
450 assert(be_is_Reload(irn));
451 return get_irn_n(irn, be_pos_Reload_frame);
454 ir_node *be_get_Spill_val(const ir_node *irn)
456 assert(be_is_Spill(irn));
457 return get_irn_n(irn, be_pos_Spill_val);
460 ir_node *be_get_Spill_frame(const ir_node *irn)
462 assert(be_is_Spill(irn));
463 return get_irn_n(irn, be_pos_Spill_frame);
466 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
469 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
470 init_node_attr(irn, n);
471 for(i = 0; i < n; ++i) {
472 be_node_set_reg_class(irn, i, cls);
473 be_node_set_reg_class(irn, OUT_POS(i), cls);
479 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
481 ir_graph *irg = get_irn_irg(perm);
482 int arity = get_irn_arity(perm);
483 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
484 be_node_attr_t *attr = get_irn_attr(perm);
485 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
489 assert(be_is_Perm(perm));
490 assert(new_size <= arity);
492 /* save the old register data */
493 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
495 /* compose the new in array and set the new register data directly in place */
496 for (i = 0; i < new_size; ++i) {
498 new_in[i] = get_irn_n(perm, idx);
499 attr->reg_data[i] = old_data[idx];
502 set_irn_in(perm, new_size, new_in);
505 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
508 ir_node *frame = get_irg_frame(irg);
509 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
511 const arch_register_t *sp = arch_env->isa->sp;
512 be_memperm_attr_t *attr;
515 real_in = alloca((n+1) * sizeof(real_in[0]));
517 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
519 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
521 init_node_attr(irn, n + 1);
522 be_node_set_reg_class(irn, 0, sp->reg_class);
523 for(i = 0; i < n; ++i) {
524 be_node_set_reg_class(irn, i + 1, cls_frame);
525 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
528 attr = get_irn_attr(irn);
530 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
531 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
532 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
533 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
539 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
543 arch_register_req_t *req;
546 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
547 init_node_attr(res, 1);
548 be_node_set_reg_class(res, 0, cls);
549 be_node_set_reg_class(res, OUT_POS(0), cls);
551 req = get_req(res, OUT_POS(0));
553 req->type = arch_register_req_type_should_be_same;
554 req->other_same = 1U << 0;
559 ir_node *be_get_Copy_op(const ir_node *cpy) {
560 return get_irn_n(cpy, be_pos_Copy_op);
563 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
564 set_irn_n(cpy, be_pos_Copy_op, op);
567 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
572 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
573 init_node_attr(res, -1);
575 for(i = 0; i < n; ++i) {
576 add_irn_n(res, in[i]);
577 add_register_req(res);
578 be_node_set_reg_class(res, i, cls);
585 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
589 assert(be_is_Keep(keep));
590 n = add_irn_n(keep, node);
591 add_register_req(keep);
592 be_node_set_reg_class(keep, n, cls);
595 /* creates a be_Call */
596 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
597 int n_outs, int n, ir_node *in[], ir_type *call_tp)
600 int real_n = be_pos_Call_first_arg + n;
604 NEW_ARR_A(ir_node *, real_in, real_n);
605 real_in[be_pos_Call_mem] = mem;
606 real_in[be_pos_Call_sp] = sp;
607 real_in[be_pos_Call_ptr] = ptr;
608 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
610 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
611 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
613 a->call_tp = call_tp;
618 /* Gets the call entity or NULL if this is no static call. */
619 ir_entity *be_Call_get_entity(const ir_node *call) {
620 const be_call_attr_t *a = get_irn_attr_const(call);
621 assert(be_is_Call(call));
625 /* Sets the call entity. */
626 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
627 be_call_attr_t *a = get_irn_attr(call);
628 assert(be_is_Call(call));
632 /* Gets the call type. */
633 ir_type *be_Call_get_type(ir_node *call) {
634 const be_call_attr_t *a = get_irn_attr_const(call);
635 assert(be_is_Call(call));
639 /* Sets the call type. */
640 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
641 be_call_attr_t *a = get_irn_attr(call);
642 assert(be_is_Call(call));
643 a->call_tp = call_tp;
646 void be_Call_set_pop(ir_node *call, unsigned pop) {
647 be_call_attr_t *a = get_irn_attr(call);
651 unsigned be_Call_get_pop(const ir_node *call) {
652 const be_call_attr_t *a = get_irn_attr_const(call);
656 /* Construct a new be_Return. */
657 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
658 unsigned pop, int n, ir_node *in[])
664 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
665 init_node_attr(res, -1);
666 for(i = 0; i < n; ++i) {
667 add_irn_n(res, in[i]);
668 add_register_req(res);
671 a = get_irn_attr(res);
672 a->num_ret_vals = n_res;
678 /* Returns the number of real returns values */
679 int be_Return_get_n_rets(const ir_node *ret)
681 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
682 return a->num_ret_vals;
685 unsigned be_Return_get_pop(const ir_node *ret)
687 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
691 int be_Return_append_node(ir_node *ret, ir_node *node)
695 pos = add_irn_n(ret, node);
696 add_register_req(ret);
701 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
708 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
709 a = init_node_attr(irn, 1);
712 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
714 /* Set output constraint to stack register. */
715 be_node_set_reg_class(irn, 0, sp->reg_class);
716 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
717 be_node_set_irn_reg(NULL, irn, sp);
722 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
726 ir_node *in[be_pos_AddSP_last];
727 const arch_register_class_t *class;
729 in[be_pos_AddSP_old_sp] = old_sp;
730 in[be_pos_AddSP_size] = sz;
732 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
733 a = init_node_attr(irn, be_pos_AddSP_last);
735 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
736 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
738 /* Set output constraint to stack register. */
739 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
740 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
741 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
742 a->reg_data[pn_be_AddSP_sp].reg = sp;
744 class = arch_register_get_class(sp);
745 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
750 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
754 ir_node *in[be_pos_SubSP_last];
756 in[be_pos_SubSP_old_sp] = old_sp;
757 in[be_pos_SubSP_size] = sz;
759 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
760 a = init_node_attr(irn, be_pos_SubSP_last);
762 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
763 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
765 /* Set output constraint to stack register. */
766 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
767 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
768 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
769 a->reg_data[pn_be_SubSP_sp].reg = sp;
774 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
779 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
780 init_node_attr(res, -1);
781 for(i = 0; i < n_outs; ++i)
782 add_register_req(res);
787 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
788 const arch_env_t *arch_env,
789 const arch_register_t *reg)
791 ir_graph *irg = get_irn_irg(regparams);
792 ir_node *block = get_nodes_block(regparams);
793 be_node_attr_t *attr = get_irn_attr(regparams);
794 const arch_register_class_t *cls = arch_register_get_class(reg);
795 ir_mode *mode = arch_register_class_mode(cls);
796 int n = ARR_LEN(attr->reg_data);
799 assert(be_is_RegParams(regparams));
800 proj = new_r_Proj(irg, block, regparams, mode, n);
801 add_register_req(regparams);
802 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
803 arch_set_irn_register(arch_env, proj, reg);
805 /* TODO decide, whether we need to set ignore/modify sp flags here? */
810 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
817 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
818 a = init_node_attr(irn, 1);
821 be_node_set_reg_class(irn, 0, cls_frame);
822 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
824 return optimize_node(irn);
827 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
828 assert(be_is_FrameAddr(node));
829 return get_irn_n(node, be_pos_FrameAddr_ptr);
832 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
834 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
838 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)
841 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
844 memcpy(&in[1], in_keep, n * sizeof(in[0]));
845 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
846 init_node_attr(irn, n + 1);
847 be_node_set_reg_class(irn, OUT_POS(0), cls);
848 be_node_set_reg_class(irn, 0, cls);
853 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)
858 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
861 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
862 return get_irn_n(cpy, be_pos_CopyKeep_op);
865 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
866 set_irn_n(cpy, be_pos_CopyKeep_op, op);
869 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
874 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
875 init_node_attr(res, -1);
876 for(i = 0; i < n; ++i) {
877 add_irn_n(res, in[i]);
878 add_register_req(res);
884 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
886 ir_graph *irg = get_irn_irg(barrier);
887 ir_node *block = get_nodes_block(barrier);
888 ir_mode *mode = get_irn_mode(node);
889 int n = add_irn_n(barrier, node);
891 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
892 add_register_req(barrier);
897 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
898 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
899 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
900 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
901 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
902 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
903 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
904 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
905 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
906 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
907 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
908 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
909 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
910 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
911 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
913 int be_has_frame_entity(const ir_node *irn)
915 switch(be_get_irn_opcode(irn)) {
925 ir_entity *be_get_frame_entity(const ir_node *irn)
927 if (be_has_frame_entity(irn)) {
928 const be_frame_attr_t *a = get_irn_attr_const(irn);
934 int be_get_frame_offset(const ir_node *irn)
936 assert(is_be_node(irn));
937 if (be_has_frame_entity(irn)) {
938 const be_frame_attr_t *a = get_irn_attr_const(irn);
944 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
946 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
948 assert(be_is_MemPerm(irn));
949 assert(n < be_get_MemPerm_entity_arity(irn));
951 attr->in_entities[n] = ent;
954 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
956 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
958 assert(be_is_MemPerm(irn));
959 assert(n < be_get_MemPerm_entity_arity(irn));
961 return attr->in_entities[n];
964 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
966 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
968 assert(be_is_MemPerm(irn));
969 assert(n < be_get_MemPerm_entity_arity(irn));
971 attr->out_entities[n] = ent;
974 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
976 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
978 assert(be_is_MemPerm(irn));
979 assert(n < be_get_MemPerm_entity_arity(irn));
981 return attr->out_entities[n];
984 int be_get_MemPerm_entity_arity(const ir_node *irn)
986 return get_irn_arity(irn) - 1;
989 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
991 arch_register_req_t *req = get_req(node, pos);
992 const arch_register_class_t *cls = arch_register_get_class(reg);
993 ir_graph *irg = get_irn_irg(node);
994 struct obstack *obst = get_irg_obstack(irg);
995 unsigned *limited_bitset;
997 assert(req->cls == NULL || req->cls == cls);
998 assert(! (req->type & arch_register_req_type_limited));
999 assert(req->limited == NULL);
1001 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1002 rbitset_set(limited_bitset, arch_register_get_index(reg));
1005 req->type |= arch_register_req_type_limited;
1006 req->limited = limited_bitset;
1009 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1011 ir_graph *irg = get_irn_irg(node);
1012 struct obstack *obst = get_irg_obstack(irg);
1013 arch_register_req_t *r = get_req(node, pos);
1015 assert(arch_register_req_is(req, limited));
1016 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1017 memcpy(r, req, sizeof(r[0]));
1018 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1021 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1023 be_req_t *bereq = get_be_req(irn, pos);
1024 bereq->flags = flags;
1027 void be_node_add_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1029 be_req_t *bereq = get_be_req(irn, pos);
1030 bereq->flags |= flags;
1033 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1035 arch_register_req_t *req = get_req(irn, pos);
1040 req->type = arch_register_req_type_none;
1041 } else if (req->type == arch_register_req_type_none) {
1042 req->type = arch_register_req_type_normal;
1046 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1048 arch_register_req_t *req = get_req(irn, pos);
1052 ir_node *be_get_IncSP_pred(ir_node *irn) {
1053 assert(be_is_IncSP(irn));
1054 return get_irn_n(irn, 0);
1057 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1058 assert(be_is_IncSP(incsp));
1059 set_irn_n(incsp, 0, pred);
1062 void be_set_IncSP_offset(ir_node *irn, int offset)
1064 be_stack_attr_t *a = get_irn_attr(irn);
1065 assert(be_is_IncSP(irn));
1069 int be_get_IncSP_offset(const ir_node *irn)
1071 const be_stack_attr_t *a = get_irn_attr_const(irn);
1072 assert(be_is_IncSP(irn));
1076 ir_node *be_spill(const arch_env_t *arch_env, ir_node *block, ir_node *irn)
1078 ir_graph *irg = get_irn_irg(block);
1079 ir_node *frame = get_irg_frame(irg);
1080 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1081 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1084 spill = be_new_Spill(cls, cls_frame, irg, block, frame, irn);
1088 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)
1091 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1092 ir_graph *irg = get_irn_irg(bl);
1093 ir_node *frame = get_irg_frame(irg);
1094 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1096 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1098 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1100 if (is_Block(insert)) {
1101 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1102 sched_add_after(insert, reload);
1104 sched_add_before(insert, reload);
1112 | _ \ ___ __ _ | _ \ ___ __ _ ___
1113 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1114 | _ < __/ (_| | | _ < __/ (_| \__ \
1115 |_| \_\___|\__, | |_| \_\___|\__, |___/
1122 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1124 const be_node_attr_t *a = get_irn_attr_const(irn);
1126 if(out_pos >= ARR_LEN(a->reg_data)) {
1127 return arch_no_register_req;
1130 return &a->reg_data[out_pos].req.req;
1134 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1136 const be_node_attr_t *a = get_irn_attr_const(irn);
1138 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1139 return arch_no_register_req;
1141 return &a->reg_data[pos].in_req.req;
1144 static const arch_register_req_t *
1145 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1151 if (get_irn_mode(irn) == mode_T)
1152 return arch_no_register_req;
1154 out_pos = redir_proj((const ir_node **)&irn);
1155 assert(is_be_node(irn));
1156 return get_out_reg_req(irn, out_pos);
1157 } else if (is_be_node(irn)) {
1159 * For spills and reloads, we return "none" as requirement for frame
1160 * pointer, so every input is ok. Some backends need this (e.g. STA).
1162 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1163 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1164 return arch_no_register_req;
1166 return get_in_reg_req(irn, pos);
1169 return arch_no_register_req;
1172 const arch_register_t *
1173 be_node_get_irn_reg(const void *self, const ir_node *irn)
1178 if (get_irn_mode(irn) == mode_T)
1180 r = retrieve_reg_data(irn);
1184 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1186 redir_proj((const ir_node **) &irn);
1189 switch(be_get_irn_opcode(irn)) {
1190 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1192 XXX(Reload, reload);
1195 XXX(Return, branch);
1198 return arch_irn_class_normal;
1204 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1211 pos = OUT_POS(get_Proj_proj(node));
1212 node = skip_Proj_const(node);
1215 bereq = get_be_req(node, pos);
1217 return bereq->flags;
1220 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1223 return be_get_frame_entity(irn);
1226 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1231 assert(be_has_frame_entity(irn));
1233 a = get_irn_attr(irn);
1237 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1240 if(be_has_frame_entity(irn)) {
1241 be_frame_attr_t *a = get_irn_attr(irn);
1246 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1249 if(be_is_IncSP(irn))
1250 return be_get_IncSP_offset(irn);
1252 return -(int)be_Call_get_pop(irn);
1258 ___ ____ _ _ _ _ _ _
1259 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1260 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1261 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1262 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1266 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1267 be_node_get_irn_reg_req,
1268 be_node_set_irn_reg,
1269 be_node_get_irn_reg,
1272 be_node_get_frame_entity,
1273 be_node_set_frame_entity,
1274 be_node_set_frame_offset,
1275 be_node_get_sp_bias,
1276 NULL, /* get_inverse */
1277 NULL, /* get_op_estimated_cost */
1278 NULL, /* possible_memory_operand */
1279 NULL, /* perform_memory_operand */
1282 static const arch_irn_ops_t be_node_irn_ops = {
1286 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1288 redir_proj((const ir_node **) &irn);
1290 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1293 const arch_irn_handler_t be_node_irn_handler = {
1298 ____ _ _ ___ ____ _ _ _ _ _ _
1299 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1300 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1301 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1302 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1307 const arch_register_t *reg;
1308 arch_register_req_t req;
1309 arch_irn_flags_t flags;
1313 arch_irn_handler_t irn_handler;
1314 arch_irn_ops_t irn_ops;
1315 const arch_env_t *arch_env;
1319 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1320 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1323 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1326 const phi_handler_t *h;
1327 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1330 h = get_phi_handler_from_handler(handler);
1335 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1337 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1339 ir_graph *irg = get_irn_irg(phi);
1340 struct obstack *obst = get_irg_obstack(irg);
1341 attr = obstack_alloc(obst, sizeof(attr[0]));
1342 memset(attr, 0, sizeof(attr[0]));
1343 pmap_insert(handler->phi_attrs, phi, attr);
1350 * Get register class of a Phi.
1353 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1357 int n = get_irn_arity(phi);
1361 if(*visited && pset_find_ptr(*visited, phi))
1364 for(i = 0; i < n; ++i) {
1365 op = get_irn_n(phi, i);
1366 /* Matze: don't we unnecessary constraint our phis with this?
1367 * we only need to take the regclass IMO*/
1369 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1373 * The operands of that Phi were all Phis themselves.
1374 * We have to start a DFS for a non-Phi argument now.
1377 *visited = pset_new_ptr(16);
1379 pset_insert_ptr(*visited, phi);
1381 for(i = 0; i < n; ++i) {
1382 const arch_register_req_t *req;
1383 op = get_irn_n(phi, i);
1384 req = get_Phi_reg_req_recursive(h, op, visited);
1393 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1394 const ir_node *irn, int pos)
1396 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1401 if(!mode_is_datab(get_irn_mode(irn)))
1402 return arch_no_register_req;
1404 attr = get_Phi_attr(phi_handler, irn);
1406 if(attr->req.type == arch_register_req_type_none) {
1407 pset *visited = NULL;
1408 const arch_register_req_t *req;
1409 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1411 memcpy(&attr->req, req, sizeof(req[0]));
1412 assert(attr->req.cls != NULL);
1413 attr->req.type = arch_register_req_type_normal;
1422 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1423 const arch_register_req_t *req)
1425 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1426 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1429 assert(mode_is_datab(get_irn_mode(node)));
1431 attr = get_Phi_attr(handler, node);
1432 memcpy(&attr->req, req, sizeof(req[0]));
1435 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1436 arch_irn_flags_t flags)
1438 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1439 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1442 assert(mode_is_datab(get_irn_mode(node)));
1444 attr = get_Phi_attr(handler, node);
1445 attr->flags = flags;
1449 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1451 phi_handler_t *h = get_phi_handler_from_ops(self);
1452 phi_attr_t *attr = get_Phi_attr(h, irn);
1457 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1459 phi_handler_t *h = get_phi_handler_from_ops(self);
1460 phi_attr_t *attr = get_Phi_attr(h, irn);
1465 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1469 return arch_irn_class_normal;
1473 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1475 phi_handler_t *h = get_phi_handler_from_ops(self);
1476 phi_attr_t *attr = get_Phi_attr(h, irn);
1482 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1490 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1499 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1508 int phi_get_sp_bias(const void* self, const ir_node *irn)
1516 const arch_irn_ops_if_t phi_irn_ops = {
1517 phi_get_irn_reg_req,
1522 phi_get_frame_entity,
1523 phi_set_frame_entity,
1524 phi_set_frame_offset,
1526 NULL, /* get_inverse */
1527 NULL, /* get_op_estimated_cost */
1528 NULL, /* possible_memory_operand */
1529 NULL, /* perform_memory_operand */
1532 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1534 phi_handler_t *h = xmalloc(sizeof(h[0]));
1535 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1536 h->irn_ops.impl = &phi_irn_ops;
1537 h->arch_env = arch_env;
1538 h->phi_attrs = pmap_create();
1539 return (arch_irn_handler_t *) h;
1542 void be_phi_handler_free(arch_irn_handler_t *handler)
1544 phi_handler_t *h = get_phi_handler_from_handler(handler);
1545 pmap_destroy(h->phi_attrs);
1546 h->phi_attrs = NULL;
1550 void be_phi_handler_reset(arch_irn_handler_t *handler)
1552 phi_handler_t *h = get_phi_handler_from_handler(handler);
1554 pmap_destroy(h->phi_attrs);
1555 h->phi_attrs = pmap_create();
1560 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1561 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1562 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1563 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1568 * Dumps a register requirement to a file.
1570 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1571 const ir_node *node)
1573 int did_something = 0;
1575 const char *prefix = buf;
1577 snprintf(buf, sizeof(buf), "#%d ", idx);
1578 buf[sizeof(buf) - 1] = '\0';
1583 arch_register_req_format(tmp, sizeof(tmp), req, node);
1584 fprintf(f, "%s", tmp);
1593 * Dumps node register requirements to a file.
1595 static void dump_node_reqs(FILE *f, ir_node *node)
1598 be_node_attr_t *a = get_irn_attr(node);
1599 int len = ARR_LEN(a->reg_data);
1601 fprintf(f, "registers: \n");
1602 for(i = 0; i < len; ++i) {
1603 be_reg_data_t *rd = &a->reg_data[i];
1605 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1608 fprintf(f, "in requirements:\n");
1609 for(i = 0; i < len; ++i) {
1610 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1613 fprintf(f, "\nout requirements:\n");
1614 for(i = 0; i < len; ++i) {
1615 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1620 * ir_op-Operation: dump a be node to file
1622 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1624 be_node_attr_t *at = get_irn_attr(irn);
1626 assert(is_be_node(irn));
1629 case dump_node_opcode_txt:
1630 fprintf(f, get_op_name(get_irn_op(irn)));
1632 case dump_node_mode_txt:
1633 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1634 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1637 case dump_node_nodeattr_txt:
1638 if(be_is_Call(irn)) {
1639 be_call_attr_t *a = (be_call_attr_t *) at;
1641 fprintf(f, " [%s] ", get_entity_name(a->ent));
1643 if(be_is_IncSP(irn)) {
1644 const be_stack_attr_t *attr = get_irn_generic_attr_const(irn);
1645 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1646 fprintf(f, " [Setup Stackframe] ");
1647 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1648 fprintf(f, " [Destroy Stackframe] ");
1650 fprintf(f, " [%d] ", attr->offset);
1654 case dump_node_info_txt:
1655 dump_node_reqs(f, irn);
1657 if(be_has_frame_entity(irn)) {
1658 be_frame_attr_t *a = (be_frame_attr_t *) at;
1660 unsigned size = get_type_size_bytes(get_entity_type(a->ent));
1661 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
1662 a->ent, a->offset, a->offset, size, size);
1667 switch(be_get_irn_opcode(irn)) {
1670 be_stack_attr_t *a = (be_stack_attr_t *) at;
1671 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1672 fprintf(f, "offset: FRAME_SIZE\n");
1673 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1674 fprintf(f, "offset: -FRAME SIZE\n");
1676 fprintf(f, "offset: %u\n", a->offset);
1681 be_call_attr_t *a = (be_call_attr_t *) at;
1684 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1690 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1691 ir_entity *in, *out;
1692 in = be_get_MemPerm_in_entity(irn, i);
1693 out = be_get_MemPerm_out_entity(irn, i);
1695 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1698 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1714 * Copies the backend specific attributes from old node to new node.
1716 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1718 const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
1719 be_node_attr_t *new_attr = get_irn_attr(new_node);
1720 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1723 assert(is_be_node(old_node));
1724 assert(is_be_node(new_node));
1726 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1727 new_attr->reg_data = NULL;
1729 if(old_attr->reg_data != NULL)
1730 len = ARR_LEN(old_attr->reg_data);
1734 if(get_irn_op(old_node)->opar == oparity_dynamic
1735 || be_is_RegParams(old_node)) {
1736 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1738 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1742 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1743 for(i = 0; i < len; ++i) {
1744 const be_reg_data_t *rd = &old_attr->reg_data[i];
1745 be_reg_data_t *newrd = &new_attr->reg_data[i];
1746 if(arch_register_req_is(&rd->req.req, limited)) {
1747 const arch_register_req_t *req = &rd->req.req;
1748 arch_register_req_t *new_req = &newrd->req.req;
1750 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1752 if(arch_register_req_is(&rd->in_req.req, limited)) {
1753 const arch_register_req_t *req = &rd->in_req.req;
1754 arch_register_req_t *new_req = &newrd->in_req.req;
1756 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1762 static const ir_op_ops be_node_op_ops = {