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_machine
150 #define E irop_flag_side_effect
154 * Compare two node attributes.
156 * @return zero if both attributes are identically
158 static int _node_cmp_attr(be_node_attr_t *a, be_node_attr_t *b) {
161 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
164 len = ARR_LEN(a->reg_data);
165 for (i = 0; i < len; ++i) {
166 if (a->reg_data[i].reg != b->reg_data[i].reg ||
167 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
168 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
175 static int node_cmp_attr(ir_node *a, ir_node *b) {
176 be_node_attr_t *a_attr = get_irn_attr(a);
177 be_node_attr_t *b_attr = get_irn_attr(b);
179 return _node_cmp_attr(a_attr, b_attr);
183 * Compare the attributes of two FrameAddr nodes.
185 * @return zero if both attributes are identically
187 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
188 be_frame_attr_t *a_attr = get_irn_attr(a);
189 be_frame_attr_t *b_attr = get_irn_attr(b);
191 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
194 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
197 static int Return_cmp_attr(ir_node *a, ir_node *b) {
198 be_return_attr_t *a_attr = get_irn_attr(a);
199 be_return_attr_t *b_attr = get_irn_attr(b);
201 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
203 if (a_attr->pop != b_attr->pop)
206 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
209 static int Stack_cmp_attr(ir_node *a, ir_node *b) {
210 be_stack_attr_t *a_attr = get_irn_attr(a);
211 be_stack_attr_t *b_attr = get_irn_attr(b);
213 if (a_attr->offset != b_attr->offset)
216 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
219 static int Call_cmp_attr(ir_node *a, ir_node *b) {
220 be_call_attr_t *a_attr = get_irn_attr(a);
221 be_call_attr_t *b_attr = get_irn_attr(b);
223 if (a_attr->ent != b_attr->ent ||
224 a_attr->call_tp != b_attr->call_tp)
227 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
230 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
233 const be_node_attr_t *attr;
236 assert(is_be_node(node));
237 attr = get_irn_attr_const(node);
243 assert(idx < get_irn_arity(node));
245 assert(idx < ARR_LEN(attr->reg_data));
246 rd = &attr->reg_data[idx];
248 return pos < 0 ? &rd->req : &rd->in_req;
251 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
253 be_req_t *bereq = get_be_req(node, pos);
257 void be_node_init(void) {
258 static int inited = 0;
265 /* Acquire all needed opcodes. */
266 beo_base = get_next_ir_opcodes(beo_Last);
268 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);
269 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);
270 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);
271 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);
272 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);
273 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);
274 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);
275 op_be_Call = new_ir_op(beo_base + beo_Call, "be_Call", op_pin_state_pinned, F|E, oparity_variable, 0, sizeof(be_call_attr_t), &be_node_op_ops);
276 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);
277 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);
278 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);
279 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);
280 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);
281 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);
282 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);
284 set_op_tag(op_be_Spill, &be_node_tag);
285 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
286 set_op_tag(op_be_Reload, &be_node_tag);
287 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
288 set_op_tag(op_be_Perm, &be_node_tag);
289 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
290 set_op_tag(op_be_MemPerm, &be_node_tag);
291 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
292 set_op_tag(op_be_Copy, &be_node_tag);
293 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
294 set_op_tag(op_be_Keep, &be_node_tag);
295 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
296 set_op_tag(op_be_CopyKeep, &be_node_tag);
297 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
298 set_op_tag(op_be_Call, &be_node_tag);
299 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
300 set_op_tag(op_be_Return, &be_node_tag);
301 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
302 set_op_tag(op_be_AddSP, &be_node_tag);
303 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
304 set_op_tag(op_be_SubSP, &be_node_tag);
305 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
306 set_op_tag(op_be_IncSP, &be_node_tag);
307 op_be_IncSP->ops.node_cmp_attr = Stack_cmp_attr;
308 set_op_tag(op_be_RegParams, &be_node_tag);
309 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
310 set_op_tag(op_be_FrameAddr, &be_node_tag);
311 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
312 set_op_tag(op_be_Barrier, &be_node_tag);
313 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
317 * Initializes the generic attribute of all be nodes and return ir.
319 static void *init_node_attr(ir_node *node, int max_reg_data)
321 ir_graph *irg = get_irn_irg(node);
322 struct obstack *obst = get_irg_obstack(irg);
323 be_node_attr_t *a = get_irn_attr(node);
325 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
327 if(max_reg_data >= 0) {
328 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
329 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
331 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
337 static void add_register_req(ir_node *node)
339 be_node_attr_t *a = get_irn_attr(node);
340 be_reg_data_t regreq;
341 memset(®req, 0, sizeof(regreq));
342 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
345 int is_be_node(const ir_node *irn)
347 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
350 be_opcode_t be_get_irn_opcode(const ir_node *irn)
352 return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
356 * Skip Proj nodes and return their Proj numbers.
358 * If *node is a Proj or Proj(Proj) node, skip it.
360 * @param node points to the node to be skipped
362 * @return 0 if *node was no Proj node, its Proj number else.
364 static int redir_proj(const ir_node **node)
366 const ir_node *n = *node;
371 *node = irn = get_Proj_pred(n);
373 assert(get_irn_mode(irn) == mode_T);
374 *node = get_Proj_pred(irn);
376 return get_Proj_proj(n);
382 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
384 const be_node_attr_t *attr;
388 pos = get_Proj_proj(node);
389 node = get_Proj_pred(node);
392 assert(is_be_node(node));
393 attr = get_irn_attr_const(node);
394 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
396 return &attr->reg_data[pos];
400 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
402 be_reg_data_t *r = retrieve_reg_data(irn);
407 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
408 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
416 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
417 a = init_node_attr(res, 2);
421 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
422 be_node_set_reg_class(res, be_pos_Spill_val, cls);
426 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
427 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
434 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
436 init_node_attr(res, 2);
437 be_node_set_reg_class(res, -1, cls);
438 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
439 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
443 ir_node *be_get_Reload_mem(const ir_node *irn)
445 assert(be_is_Reload(irn));
446 return get_irn_n(irn, be_pos_Reload_mem);
449 ir_node *be_get_Reload_frame(const ir_node *irn)
451 assert(be_is_Reload(irn));
452 return get_irn_n(irn, be_pos_Reload_frame);
455 ir_node *be_get_Spill_val(const ir_node *irn)
457 assert(be_is_Spill(irn));
458 return get_irn_n(irn, be_pos_Spill_val);
461 ir_node *be_get_Spill_frame(const ir_node *irn)
463 assert(be_is_Spill(irn));
464 return get_irn_n(irn, be_pos_Spill_frame);
467 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
470 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
471 init_node_attr(irn, n);
472 for(i = 0; i < n; ++i) {
473 be_node_set_reg_class(irn, i, cls);
474 be_node_set_reg_class(irn, OUT_POS(i), cls);
480 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
482 ir_graph *irg = get_irn_irg(perm);
483 int arity = get_irn_arity(perm);
484 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
485 be_node_attr_t *attr = get_irn_attr(perm);
486 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
490 assert(be_is_Perm(perm));
491 assert(new_size <= arity);
493 /* save the old register data */
494 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
496 /* compose the new in array and set the new register data directly in place */
497 for (i = 0; i < new_size; ++i) {
499 new_in[i] = get_irn_n(perm, idx);
500 attr->reg_data[i] = old_data[idx];
503 set_irn_in(perm, new_size, new_in);
506 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
509 ir_node *frame = get_irg_frame(irg);
510 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
512 const arch_register_t *sp = arch_env->isa->sp;
513 be_memperm_attr_t *attr;
516 real_in = alloca((n+1) * sizeof(real_in[0]));
518 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
520 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
522 init_node_attr(irn, n + 1);
523 be_node_set_reg_class(irn, 0, sp->reg_class);
524 for(i = 0; i < n; ++i) {
525 be_node_set_reg_class(irn, i + 1, cls_frame);
526 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
529 attr = get_irn_attr(irn);
531 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
532 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
533 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
534 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
540 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
544 arch_register_req_t *req;
547 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
548 init_node_attr(res, 1);
549 be_node_set_reg_class(res, 0, cls);
550 be_node_set_reg_class(res, OUT_POS(0), cls);
552 req = get_req(res, OUT_POS(0));
554 req->type = arch_register_req_type_should_be_same;
555 req->other_same = 1U << 0;
560 ir_node *be_get_Copy_op(const ir_node *cpy) {
561 return get_irn_n(cpy, be_pos_Copy_op);
564 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
565 set_irn_n(cpy, be_pos_Copy_op, op);
568 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
573 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
574 init_node_attr(res, -1);
576 for(i = 0; i < n; ++i) {
577 add_irn_n(res, in[i]);
578 add_register_req(res);
579 be_node_set_reg_class(res, i, cls);
586 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
590 assert(be_is_Keep(keep));
591 n = add_irn_n(keep, node);
592 add_register_req(keep);
593 be_node_set_reg_class(keep, n, cls);
596 /* creates a be_Call */
597 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
598 int n_outs, int n, ir_node *in[], ir_type *call_tp)
601 int real_n = be_pos_Call_first_arg + n;
605 NEW_ARR_A(ir_node *, real_in, real_n);
606 real_in[be_pos_Call_mem] = mem;
607 real_in[be_pos_Call_sp] = sp;
608 real_in[be_pos_Call_ptr] = ptr;
609 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
611 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
612 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
614 a->call_tp = call_tp;
619 /* Gets the call entity or NULL if this is no static call. */
620 ir_entity *be_Call_get_entity(const ir_node *call) {
621 const be_call_attr_t *a = get_irn_attr_const(call);
622 assert(be_is_Call(call));
626 /* Sets the call entity. */
627 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
628 be_call_attr_t *a = get_irn_attr(call);
629 assert(be_is_Call(call));
633 /* Gets the call type. */
634 ir_type *be_Call_get_type(ir_node *call) {
635 const be_call_attr_t *a = get_irn_attr_const(call);
636 assert(be_is_Call(call));
640 /* Sets the call type. */
641 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
642 be_call_attr_t *a = get_irn_attr(call);
643 assert(be_is_Call(call));
644 a->call_tp = call_tp;
647 void be_Call_set_pop(ir_node *call, unsigned pop) {
648 be_call_attr_t *a = get_irn_attr(call);
652 unsigned be_Call_get_pop(const ir_node *call) {
653 const be_call_attr_t *a = get_irn_attr_const(call);
657 /* Construct a new be_Return. */
658 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
659 unsigned pop, int n, ir_node *in[])
665 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
666 init_node_attr(res, -1);
667 for(i = 0; i < n; ++i) {
668 add_irn_n(res, in[i]);
669 add_register_req(res);
672 a = get_irn_attr(res);
673 a->num_ret_vals = n_res;
679 /* Returns the number of real returns values */
680 int be_Return_get_n_rets(const ir_node *ret)
682 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
683 return a->num_ret_vals;
686 unsigned be_Return_get_pop(const ir_node *ret)
688 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
692 int be_Return_append_node(ir_node *ret, ir_node *node)
696 pos = add_irn_n(ret, node);
697 add_register_req(ret);
702 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
709 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
710 a = init_node_attr(irn, 1);
713 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
715 /* Set output constraint to stack register. */
716 be_node_set_reg_class(irn, 0, sp->reg_class);
717 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
718 be_node_set_irn_reg(NULL, irn, sp);
723 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
727 ir_node *in[be_pos_AddSP_last];
728 const arch_register_class_t *class;
730 in[be_pos_AddSP_old_sp] = old_sp;
731 in[be_pos_AddSP_size] = sz;
733 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
734 a = init_node_attr(irn, be_pos_AddSP_last);
736 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
737 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
739 /* Set output constraint to stack register. */
740 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
741 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
742 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
743 a->reg_data[pn_be_AddSP_sp].reg = sp;
745 class = arch_register_get_class(sp);
746 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
751 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
755 ir_node *in[be_pos_SubSP_last];
757 in[be_pos_SubSP_old_sp] = old_sp;
758 in[be_pos_SubSP_size] = sz;
760 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
761 a = init_node_attr(irn, be_pos_SubSP_last);
763 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
764 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
766 /* Set output constraint to stack register. */
767 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
768 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
769 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
770 a->reg_data[pn_be_SubSP_sp].reg = sp;
775 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
780 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
781 init_node_attr(res, -1);
782 for(i = 0; i < n_outs; ++i)
783 add_register_req(res);
788 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
789 const arch_env_t *arch_env,
790 const arch_register_t *reg)
792 ir_graph *irg = get_irn_irg(regparams);
793 ir_node *block = get_nodes_block(regparams);
794 be_node_attr_t *attr = get_irn_attr(regparams);
795 const arch_register_class_t *cls = arch_register_get_class(reg);
796 ir_mode *mode = arch_register_class_mode(cls);
797 int n = ARR_LEN(attr->reg_data);
800 assert(be_is_RegParams(regparams));
801 proj = new_r_Proj(irg, block, regparams, mode, n);
802 add_register_req(regparams);
803 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
804 arch_set_irn_register(arch_env, proj, reg);
806 /* TODO decide, whether we need to set ignore/modify sp flags here? */
811 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
818 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
819 a = init_node_attr(irn, 1);
822 be_node_set_reg_class(irn, 0, cls_frame);
823 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
825 return optimize_node(irn);
828 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
829 assert(be_is_FrameAddr(node));
830 return get_irn_n(node, be_pos_FrameAddr_ptr);
833 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
835 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
839 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)
842 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
845 memcpy(&in[1], in_keep, n * sizeof(in[0]));
846 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
847 init_node_attr(irn, n + 1);
848 be_node_set_reg_class(irn, OUT_POS(0), cls);
849 be_node_set_reg_class(irn, 0, cls);
854 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)
859 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
862 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
863 return get_irn_n(cpy, be_pos_CopyKeep_op);
866 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
867 set_irn_n(cpy, be_pos_CopyKeep_op, op);
870 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
875 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
876 init_node_attr(res, -1);
877 for(i = 0; i < n; ++i) {
878 add_irn_n(res, in[i]);
879 add_register_req(res);
885 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
887 ir_graph *irg = get_irn_irg(barrier);
888 ir_node *block = get_nodes_block(barrier);
889 ir_mode *mode = get_irn_mode(node);
890 int n = add_irn_n(barrier, node);
892 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
893 add_register_req(barrier);
898 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
899 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
900 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
901 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
902 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
903 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
904 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
905 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
906 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
907 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
908 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
909 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
910 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
911 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
912 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
914 int be_has_frame_entity(const ir_node *irn)
916 switch(be_get_irn_opcode(irn)) {
926 ir_entity *be_get_frame_entity(const ir_node *irn)
928 if (be_has_frame_entity(irn)) {
929 const be_frame_attr_t *a = get_irn_attr_const(irn);
935 int be_get_frame_offset(const ir_node *irn)
937 assert(is_be_node(irn));
938 if (be_has_frame_entity(irn)) {
939 const be_frame_attr_t *a = get_irn_attr_const(irn);
945 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
947 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
949 assert(be_is_MemPerm(irn));
950 assert(n < be_get_MemPerm_entity_arity(irn));
952 attr->in_entities[n] = ent;
955 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
957 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
959 assert(be_is_MemPerm(irn));
960 assert(n < be_get_MemPerm_entity_arity(irn));
962 return attr->in_entities[n];
965 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
967 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
969 assert(be_is_MemPerm(irn));
970 assert(n < be_get_MemPerm_entity_arity(irn));
972 attr->out_entities[n] = ent;
975 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
977 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
979 assert(be_is_MemPerm(irn));
980 assert(n < be_get_MemPerm_entity_arity(irn));
982 return attr->out_entities[n];
985 int be_get_MemPerm_entity_arity(const ir_node *irn)
987 return get_irn_arity(irn) - 1;
990 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
992 arch_register_req_t *req = get_req(node, pos);
993 const arch_register_class_t *cls = arch_register_get_class(reg);
994 ir_graph *irg = get_irn_irg(node);
995 struct obstack *obst = get_irg_obstack(irg);
996 unsigned *limited_bitset;
998 assert(req->cls == NULL || req->cls == cls);
999 assert(! (req->type & arch_register_req_type_limited));
1000 assert(req->limited == NULL);
1002 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1003 rbitset_set(limited_bitset, arch_register_get_index(reg));
1006 req->type |= arch_register_req_type_limited;
1007 req->limited = limited_bitset;
1010 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1012 ir_graph *irg = get_irn_irg(node);
1013 struct obstack *obst = get_irg_obstack(irg);
1014 arch_register_req_t *r = get_req(node, pos);
1016 assert(arch_register_req_is(req, limited));
1017 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1018 memcpy(r, req, sizeof(r[0]));
1019 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1022 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1024 be_req_t *bereq = get_be_req(irn, pos);
1025 bereq->flags = flags;
1028 void be_node_add_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1030 be_req_t *bereq = get_be_req(irn, pos);
1031 bereq->flags |= flags;
1034 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1036 arch_register_req_t *req = get_req(irn, pos);
1041 req->type = arch_register_req_type_none;
1042 } else if (req->type == arch_register_req_type_none) {
1043 req->type = arch_register_req_type_normal;
1047 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1049 arch_register_req_t *req = get_req(irn, pos);
1053 ir_node *be_get_IncSP_pred(ir_node *irn) {
1054 assert(be_is_IncSP(irn));
1055 return get_irn_n(irn, 0);
1058 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1059 assert(be_is_IncSP(incsp));
1060 set_irn_n(incsp, 0, pred);
1063 void be_set_IncSP_offset(ir_node *irn, int offset)
1065 be_stack_attr_t *a = get_irn_attr(irn);
1066 assert(be_is_IncSP(irn));
1070 int be_get_IncSP_offset(const ir_node *irn)
1072 const be_stack_attr_t *a = get_irn_attr_const(irn);
1073 assert(be_is_IncSP(irn));
1077 ir_node *be_spill(const arch_env_t *arch_env, ir_node *block, ir_node *irn)
1079 ir_graph *irg = get_irn_irg(block);
1080 ir_node *frame = get_irg_frame(irg);
1081 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1082 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1085 spill = be_new_Spill(cls, cls_frame, irg, block, frame, irn);
1089 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)
1092 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1093 ir_graph *irg = get_irn_irg(bl);
1094 ir_node *frame = get_irg_frame(irg);
1095 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1097 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1099 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1101 if (is_Block(insert)) {
1102 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1103 sched_add_after(insert, reload);
1105 sched_add_before(insert, reload);
1113 | _ \ ___ __ _ | _ \ ___ __ _ ___
1114 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1115 | _ < __/ (_| | | _ < __/ (_| \__ \
1116 |_| \_\___|\__, | |_| \_\___|\__, |___/
1123 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1125 const be_node_attr_t *a = get_irn_attr_const(irn);
1127 if(out_pos >= ARR_LEN(a->reg_data)) {
1128 return arch_no_register_req;
1131 return &a->reg_data[out_pos].req.req;
1135 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1137 const be_node_attr_t *a = get_irn_attr_const(irn);
1139 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1140 return arch_no_register_req;
1142 return &a->reg_data[pos].in_req.req;
1145 static const arch_register_req_t *
1146 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1152 if (get_irn_mode(irn) == mode_T)
1153 return arch_no_register_req;
1155 out_pos = redir_proj((const ir_node **)&irn);
1156 assert(is_be_node(irn));
1157 return get_out_reg_req(irn, out_pos);
1158 } else if (is_be_node(irn)) {
1160 * For spills and reloads, we return "none" as requirement for frame
1161 * pointer, so every input is ok. Some backends need this (e.g. STA).
1163 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1164 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1165 return arch_no_register_req;
1167 return get_in_reg_req(irn, pos);
1170 return arch_no_register_req;
1173 const arch_register_t *
1174 be_node_get_irn_reg(const void *self, const ir_node *irn)
1179 if (get_irn_mode(irn) == mode_T)
1181 r = retrieve_reg_data(irn);
1185 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1187 redir_proj((const ir_node **) &irn);
1190 switch(be_get_irn_opcode(irn)) {
1191 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1193 XXX(Reload, reload);
1196 XXX(Return, branch);
1199 return arch_irn_class_normal;
1205 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1212 pos = OUT_POS(get_Proj_proj(node));
1213 node = skip_Proj_const(node);
1216 bereq = get_be_req(node, pos);
1218 return bereq->flags;
1221 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1224 return be_get_frame_entity(irn);
1227 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1232 assert(be_has_frame_entity(irn));
1234 a = get_irn_attr(irn);
1238 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1241 if(be_has_frame_entity(irn)) {
1242 be_frame_attr_t *a = get_irn_attr(irn);
1247 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1250 if(be_is_IncSP(irn))
1251 return be_get_IncSP_offset(irn);
1253 return -(int)be_Call_get_pop(irn);
1259 ___ ____ _ _ _ _ _ _
1260 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1261 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1262 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1263 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1267 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1268 be_node_get_irn_reg_req,
1269 be_node_set_irn_reg,
1270 be_node_get_irn_reg,
1273 be_node_get_frame_entity,
1274 be_node_set_frame_entity,
1275 be_node_set_frame_offset,
1276 be_node_get_sp_bias,
1277 NULL, /* get_inverse */
1278 NULL, /* get_op_estimated_cost */
1279 NULL, /* possible_memory_operand */
1280 NULL, /* perform_memory_operand */
1283 static const arch_irn_ops_t be_node_irn_ops = {
1287 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1289 redir_proj((const ir_node **) &irn);
1291 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1294 const arch_irn_handler_t be_node_irn_handler = {
1299 ____ _ _ ___ ____ _ _ _ _ _ _
1300 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1301 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1302 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1303 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1308 const arch_register_t *reg;
1309 arch_register_req_t req;
1310 arch_irn_flags_t flags;
1314 arch_irn_handler_t irn_handler;
1315 arch_irn_ops_t irn_ops;
1316 const arch_env_t *arch_env;
1320 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1321 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1324 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1327 const phi_handler_t *h;
1328 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1331 h = get_phi_handler_from_handler(handler);
1336 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1338 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1340 ir_graph *irg = get_irn_irg(phi);
1341 struct obstack *obst = get_irg_obstack(irg);
1342 attr = obstack_alloc(obst, sizeof(attr[0]));
1343 memset(attr, 0, sizeof(attr[0]));
1344 pmap_insert(handler->phi_attrs, phi, attr);
1351 * Get register class of a Phi.
1354 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1358 int n = get_irn_arity(phi);
1362 if(*visited && pset_find_ptr(*visited, phi))
1365 for(i = 0; i < n; ++i) {
1366 op = get_irn_n(phi, i);
1367 /* Matze: don't we unnecessary constraint our phis with this?
1368 * we only need to take the regclass IMO*/
1370 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1374 * The operands of that Phi were all Phis themselves.
1375 * We have to start a DFS for a non-Phi argument now.
1378 *visited = pset_new_ptr(16);
1380 pset_insert_ptr(*visited, phi);
1382 for(i = 0; i < n; ++i) {
1383 const arch_register_req_t *req;
1384 op = get_irn_n(phi, i);
1385 req = get_Phi_reg_req_recursive(h, op, visited);
1394 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1395 const ir_node *irn, int pos)
1397 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1402 if(!mode_is_datab(get_irn_mode(irn)))
1403 return arch_no_register_req;
1405 attr = get_Phi_attr(phi_handler, irn);
1407 if(attr->req.type == arch_register_req_type_none) {
1408 pset *visited = NULL;
1409 const arch_register_req_t *req;
1410 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1412 memcpy(&attr->req, req, sizeof(req[0]));
1413 assert(attr->req.cls != NULL);
1414 attr->req.type = arch_register_req_type_normal;
1423 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1424 const arch_register_req_t *req)
1426 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1427 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1430 assert(mode_is_datab(get_irn_mode(node)));
1432 attr = get_Phi_attr(handler, node);
1433 memcpy(&attr->req, req, sizeof(req[0]));
1436 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1437 arch_irn_flags_t flags)
1439 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1440 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1443 assert(mode_is_datab(get_irn_mode(node)));
1445 attr = get_Phi_attr(handler, node);
1446 attr->flags = flags;
1450 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1452 phi_handler_t *h = get_phi_handler_from_ops(self);
1453 phi_attr_t *attr = get_Phi_attr(h, irn);
1458 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1460 phi_handler_t *h = get_phi_handler_from_ops(self);
1461 phi_attr_t *attr = get_Phi_attr(h, irn);
1466 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1470 return arch_irn_class_normal;
1474 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1476 phi_handler_t *h = get_phi_handler_from_ops(self);
1477 phi_attr_t *attr = get_Phi_attr(h, irn);
1483 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1491 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1500 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1509 int phi_get_sp_bias(const void* self, const ir_node *irn)
1517 const arch_irn_ops_if_t phi_irn_ops = {
1518 phi_get_irn_reg_req,
1523 phi_get_frame_entity,
1524 phi_set_frame_entity,
1525 phi_set_frame_offset,
1527 NULL, /* get_inverse */
1528 NULL, /* get_op_estimated_cost */
1529 NULL, /* possible_memory_operand */
1530 NULL, /* perform_memory_operand */
1533 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1535 phi_handler_t *h = xmalloc(sizeof(h[0]));
1536 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1537 h->irn_ops.impl = &phi_irn_ops;
1538 h->arch_env = arch_env;
1539 h->phi_attrs = pmap_create();
1540 return (arch_irn_handler_t *) h;
1543 void be_phi_handler_free(arch_irn_handler_t *handler)
1545 phi_handler_t *h = get_phi_handler_from_handler(handler);
1546 pmap_destroy(h->phi_attrs);
1547 h->phi_attrs = NULL;
1551 void be_phi_handler_reset(arch_irn_handler_t *handler)
1553 phi_handler_t *h = get_phi_handler_from_handler(handler);
1555 pmap_destroy(h->phi_attrs);
1556 h->phi_attrs = pmap_create();
1561 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1562 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1563 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1564 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1569 * Dumps a register requirement to a file.
1571 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1572 const ir_node *node)
1574 int did_something = 0;
1576 const char *prefix = buf;
1578 snprintf(buf, sizeof(buf), "#%d ", idx);
1579 buf[sizeof(buf) - 1] = '\0';
1584 arch_register_req_format(tmp, sizeof(tmp), req, node);
1585 fprintf(f, "%s", tmp);
1594 * Dumps node register requirements to a file.
1596 static void dump_node_reqs(FILE *f, ir_node *node)
1599 be_node_attr_t *a = get_irn_attr(node);
1600 int len = ARR_LEN(a->reg_data);
1602 fprintf(f, "registers: \n");
1603 for(i = 0; i < len; ++i) {
1604 be_reg_data_t *rd = &a->reg_data[i];
1606 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1609 fprintf(f, "in requirements:\n");
1610 for(i = 0; i < len; ++i) {
1611 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1614 fprintf(f, "\nout requirements:\n");
1615 for(i = 0; i < len; ++i) {
1616 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1621 * ir_op-Operation: dump a be node to file
1623 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1625 be_node_attr_t *at = get_irn_attr(irn);
1627 assert(is_be_node(irn));
1630 case dump_node_opcode_txt:
1631 fprintf(f, get_op_name(get_irn_op(irn)));
1633 case dump_node_mode_txt:
1634 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1635 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1638 case dump_node_nodeattr_txt:
1639 if(be_is_Call(irn)) {
1640 be_call_attr_t *a = (be_call_attr_t *) at;
1642 fprintf(f, " [%s] ", get_entity_name(a->ent));
1644 if(be_is_IncSP(irn)) {
1645 const be_stack_attr_t *attr = get_irn_generic_attr_const(irn);
1646 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1647 fprintf(f, " [Setup Stackframe] ");
1648 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1649 fprintf(f, " [Destroy Stackframe] ");
1651 fprintf(f, " [%d] ", attr->offset);
1655 case dump_node_info_txt:
1656 dump_node_reqs(f, irn);
1658 if(be_has_frame_entity(irn)) {
1659 be_frame_attr_t *a = (be_frame_attr_t *) at;
1661 int bits = get_type_size_bits(get_entity_type(a->ent));
1662 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1663 a->ent, a->offset, a->offset, bits, bits);
1668 switch(be_get_irn_opcode(irn)) {
1671 be_stack_attr_t *a = (be_stack_attr_t *) at;
1672 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1673 fprintf(f, "offset: FRAME_SIZE\n");
1674 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1675 fprintf(f, "offset: -FRAME SIZE\n");
1677 fprintf(f, "offset: %u\n", a->offset);
1682 be_call_attr_t *a = (be_call_attr_t *) at;
1685 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1691 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1692 ir_entity *in, *out;
1693 in = be_get_MemPerm_in_entity(irn, i);
1694 out = be_get_MemPerm_out_entity(irn, i);
1696 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1699 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1715 * Copies the backend specific attributes from old node to new node.
1717 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1719 const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
1720 be_node_attr_t *new_attr = get_irn_attr(new_node);
1721 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1724 assert(is_be_node(old_node));
1725 assert(is_be_node(new_node));
1727 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1728 new_attr->reg_data = NULL;
1730 if(old_attr->reg_data != NULL)
1731 len = ARR_LEN(old_attr->reg_data);
1735 if(get_irn_op(old_node)->opar == oparity_dynamic
1736 || be_is_RegParams(old_node)) {
1737 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1739 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1743 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1744 for(i = 0; i < len; ++i) {
1745 const be_reg_data_t *rd = &old_attr->reg_data[i];
1746 be_reg_data_t *newrd = &new_attr->reg_data[i];
1747 if(arch_register_req_is(&rd->req.req, limited)) {
1748 const arch_register_req_t *req = &rd->req.req;
1749 arch_register_req_t *new_req = &newrd->req.req;
1751 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1753 if(arch_register_req_is(&rd->in_req.req, limited)) {
1754 const arch_register_req_t *req = &rd->in_req.req;
1755 arch_register_req_t *new_req = &newrd->in_req.req;
1757 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1763 static const ir_op_ops be_node_op_ops = {