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 #define get_irn_attr(irn) get_irn_generic_attr(irn)
64 #define get_irn_attr_const(irn) get_irn_generic_attr_const(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 */
88 unsigned pop; /**< number of bytes that should be popped */
91 /** The be_Stack attribute type. */
93 be_node_attr_t node_attr;
94 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
97 /** The be_Frame attribute type. */
99 be_node_attr_t node_attr;
104 /** The be_Call attribute type. */
106 be_node_attr_t node_attr;
107 ir_entity *ent; /**< The called entity if this is a static call. */
109 ir_type *call_tp; /**< The call type, copied from the original Call node. */
113 be_node_attr_t node_attr;
114 ir_entity **in_entities;
115 ir_entity **out_entities;
121 ir_op *op_be_MemPerm;
124 ir_op *op_be_CopyKeep;
130 ir_op *op_be_RegParams;
131 ir_op *op_be_FrameAddr;
132 ir_op *op_be_Barrier;
134 static int beo_base = -1;
136 static const ir_op_ops be_node_op_ops;
138 #define N irop_flag_none
139 #define L irop_flag_labeled
140 #define C irop_flag_commutative
141 #define X irop_flag_cfopcode
142 #define I irop_flag_ip_cfopcode
143 #define F irop_flag_fragile
144 #define Y irop_flag_forking
145 #define H irop_flag_highlevel
146 #define c irop_flag_constlike
147 #define K irop_flag_keep
148 #define M irop_flag_machine
152 * Compare two node attributes.
154 * @return zero if both attributes are identically
156 static int _node_cmp_attr(be_node_attr_t *a, be_node_attr_t *b) {
159 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
162 len = ARR_LEN(a->reg_data);
163 for (i = 0; i < len; ++i) {
164 if (a->reg_data[i].reg != b->reg_data[i].reg ||
165 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
166 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
173 static int node_cmp_attr(ir_node *a, ir_node *b) {
174 be_node_attr_t *a_attr = get_irn_attr(a);
175 be_node_attr_t *b_attr = get_irn_attr(b);
177 return _node_cmp_attr(a_attr, b_attr);
181 * Compare the attributes of two FrameAddr nodes.
183 * @return zero if both attributes are identically
185 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
186 be_frame_attr_t *a_attr = get_irn_attr(a);
187 be_frame_attr_t *b_attr = get_irn_attr(b);
189 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
192 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
195 static int Return_cmp_attr(ir_node *a, ir_node *b) {
196 be_return_attr_t *a_attr = get_irn_attr(a);
197 be_return_attr_t *b_attr = get_irn_attr(b);
199 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
201 if (a_attr->pop != b_attr->pop)
204 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
207 static int Stack_cmp_attr(ir_node *a, ir_node *b) {
208 be_stack_attr_t *a_attr = get_irn_attr(a);
209 be_stack_attr_t *b_attr = get_irn_attr(b);
211 if (a_attr->offset != b_attr->offset)
214 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
217 static int Call_cmp_attr(ir_node *a, ir_node *b) {
218 be_call_attr_t *a_attr = get_irn_attr(a);
219 be_call_attr_t *b_attr = get_irn_attr(b);
221 if (a_attr->ent != b_attr->ent ||
222 a_attr->call_tp != b_attr->call_tp)
225 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
228 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
231 const be_node_attr_t *attr;
234 assert(is_be_node(node));
235 attr = get_irn_attr_const(node);
241 assert(idx < get_irn_arity(node));
243 assert(idx < ARR_LEN(attr->reg_data));
244 rd = &attr->reg_data[idx];
246 return pos < 0 ? &rd->req : &rd->in_req;
249 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
251 be_req_t *bereq = get_be_req(node, pos);
255 void be_node_init(void) {
256 static int inited = 0;
263 /* Acquire all needed opcodes. */
264 beo_base = get_next_ir_opcodes(beo_Last);
266 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);
267 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);
268 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);
269 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);
270 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);
271 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);
272 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);
273 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);
274 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);
275 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);
276 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);
277 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);
278 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);
279 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);
280 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);
282 set_op_tag(op_be_Spill, &be_node_tag);
283 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
284 set_op_tag(op_be_Reload, &be_node_tag);
285 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
286 set_op_tag(op_be_Perm, &be_node_tag);
287 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
288 set_op_tag(op_be_MemPerm, &be_node_tag);
289 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
290 set_op_tag(op_be_Copy, &be_node_tag);
291 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
292 set_op_tag(op_be_Keep, &be_node_tag);
293 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
294 set_op_tag(op_be_CopyKeep, &be_node_tag);
295 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
296 set_op_tag(op_be_Call, &be_node_tag);
297 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
298 set_op_tag(op_be_Return, &be_node_tag);
299 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
300 set_op_tag(op_be_AddSP, &be_node_tag);
301 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
302 set_op_tag(op_be_SubSP, &be_node_tag);
303 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
304 set_op_tag(op_be_IncSP, &be_node_tag);
305 op_be_IncSP->ops.node_cmp_attr = Stack_cmp_attr;
306 set_op_tag(op_be_RegParams, &be_node_tag);
307 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
308 set_op_tag(op_be_FrameAddr, &be_node_tag);
309 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
310 set_op_tag(op_be_Barrier, &be_node_tag);
311 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
315 * Initializes the generic attribute of all be nodes and return ir.
317 static void *init_node_attr(ir_node *node, int max_reg_data)
319 ir_graph *irg = get_irn_irg(node);
320 struct obstack *obst = get_irg_obstack(irg);
321 be_node_attr_t *a = get_irn_attr(node);
323 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
325 if(max_reg_data >= 0) {
326 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
327 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
329 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
335 static void add_register_req(ir_node *node)
337 be_node_attr_t *a = get_irn_attr(node);
338 be_reg_data_t regreq;
339 memset(®req, 0, sizeof(regreq));
340 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
343 int is_be_node(const ir_node *irn)
345 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
348 be_opcode_t be_get_irn_opcode(const ir_node *irn)
350 return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
354 * Skip Proj nodes and return their Proj numbers.
356 * If *node is a Proj or Proj(Proj) node, skip it.
358 * @param node points to the node to be skipped
360 * @return 0 if *node was no Proj node, its Proj number else.
362 static int redir_proj(const ir_node **node)
364 const ir_node *n = *node;
369 *node = irn = get_Proj_pred(n);
371 assert(get_irn_mode(irn) == mode_T);
372 *node = get_Proj_pred(irn);
374 return get_Proj_proj(n);
380 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
382 const be_node_attr_t *attr;
386 pos = get_Proj_proj(node);
387 node = get_Proj_pred(node);
390 assert(is_be_node(node));
391 attr = get_irn_attr_const(node);
392 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
394 return &attr->reg_data[pos];
398 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
400 be_reg_data_t *r = retrieve_reg_data(irn);
405 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
406 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
414 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
415 a = init_node_attr(res, 2);
419 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
420 be_node_set_reg_class(res, be_pos_Spill_val, cls);
424 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
425 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
432 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
434 init_node_attr(res, 2);
435 be_node_set_reg_class(res, -1, cls);
436 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
437 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
441 ir_node *be_get_Reload_mem(const ir_node *irn)
443 assert(be_is_Reload(irn));
444 return get_irn_n(irn, be_pos_Reload_mem);
447 ir_node *be_get_Reload_frame(const ir_node *irn)
449 assert(be_is_Reload(irn));
450 return get_irn_n(irn, be_pos_Reload_frame);
453 ir_node *be_get_Spill_val(const ir_node *irn)
455 assert(be_is_Spill(irn));
456 return get_irn_n(irn, be_pos_Spill_val);
459 ir_node *be_get_Spill_frame(const ir_node *irn)
461 assert(be_is_Spill(irn));
462 return get_irn_n(irn, be_pos_Spill_frame);
465 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
468 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
469 init_node_attr(irn, n);
470 for(i = 0; i < n; ++i) {
471 be_node_set_reg_class(irn, i, cls);
472 be_node_set_reg_class(irn, OUT_POS(i), cls);
478 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
480 ir_graph *irg = get_irn_irg(perm);
481 int arity = get_irn_arity(perm);
482 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
483 be_node_attr_t *attr = get_irn_attr(perm);
484 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
488 assert(be_is_Perm(perm));
489 assert(new_size <= arity);
491 /* save the old register data */
492 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
494 /* compose the new in array and set the new register data directly in place */
495 for (i = 0; i < new_size; ++i) {
497 new_in[i] = get_irn_n(perm, idx);
498 attr->reg_data[i] = old_data[idx];
501 set_irn_in(perm, new_size, new_in);
504 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
507 ir_node *frame = get_irg_frame(irg);
508 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
510 const arch_register_t *sp = arch_env->isa->sp;
511 be_memperm_attr_t *attr;
514 real_in = alloca((n+1) * sizeof(real_in[0]));
516 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
518 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
520 init_node_attr(irn, n + 1);
521 be_node_set_reg_class(irn, 0, sp->reg_class);
522 for(i = 0; i < n; ++i) {
523 be_node_set_reg_class(irn, i + 1, cls_frame);
524 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
527 attr = get_irn_attr(irn);
529 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
530 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
531 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
532 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
538 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
542 arch_register_req_t *req;
545 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
546 init_node_attr(res, 1);
547 be_node_set_reg_class(res, 0, cls);
548 be_node_set_reg_class(res, OUT_POS(0), cls);
550 req = get_req(res, OUT_POS(0));
552 req->type = arch_register_req_type_should_be_same;
553 req->other_same = 1U << 0;
558 ir_node *be_get_Copy_op(const ir_node *cpy) {
559 return get_irn_n(cpy, be_pos_Copy_op);
562 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
563 set_irn_n(cpy, be_pos_Copy_op, op);
566 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
571 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
572 init_node_attr(res, -1);
574 for(i = 0; i < n; ++i) {
575 add_irn_n(res, in[i]);
576 add_register_req(res);
577 be_node_set_reg_class(res, i, cls);
584 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
588 assert(be_is_Keep(keep));
589 n = add_irn_n(keep, node);
590 add_register_req(keep);
591 be_node_set_reg_class(keep, n, cls);
594 /* creates a be_Call */
595 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
596 int n_outs, int n, ir_node *in[], ir_type *call_tp)
599 int real_n = be_pos_Call_first_arg + n;
603 NEW_ARR_A(ir_node *, real_in, real_n);
604 real_in[be_pos_Call_mem] = mem;
605 real_in[be_pos_Call_sp] = sp;
606 real_in[be_pos_Call_ptr] = ptr;
607 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
609 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
610 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
612 a->call_tp = call_tp;
617 /* Gets the call entity or NULL if this is no static call. */
618 ir_entity *be_Call_get_entity(const ir_node *call) {
619 const be_call_attr_t *a = get_irn_attr_const(call);
620 assert(be_is_Call(call));
624 /* Sets the call entity. */
625 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
626 be_call_attr_t *a = get_irn_attr(call);
627 assert(be_is_Call(call));
631 /* Gets the call type. */
632 ir_type *be_Call_get_type(ir_node *call) {
633 const be_call_attr_t *a = get_irn_attr_const(call);
634 assert(be_is_Call(call));
638 /* Sets the call type. */
639 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
640 be_call_attr_t *a = get_irn_attr(call);
641 assert(be_is_Call(call));
642 a->call_tp = call_tp;
645 void be_Call_set_pop(ir_node *call, unsigned pop) {
646 be_call_attr_t *a = get_irn_attr(call);
650 unsigned be_Call_get_pop(const ir_node *call) {
651 const be_call_attr_t *a = get_irn_attr_const(call);
655 /* Construct a new be_Return. */
656 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
657 unsigned pop, int n, ir_node *in[])
663 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
664 init_node_attr(res, -1);
665 for(i = 0; i < n; ++i) {
666 add_irn_n(res, in[i]);
667 add_register_req(res);
670 a = get_irn_attr(res);
671 a->num_ret_vals = n_res;
677 /* Returns the number of real returns values */
678 int be_Return_get_n_rets(const ir_node *ret)
680 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
681 return a->num_ret_vals;
684 unsigned be_Return_get_pop(const ir_node *ret)
686 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
690 int be_Return_append_node(ir_node *ret, ir_node *node)
694 pos = add_irn_n(ret, node);
695 add_register_req(ret);
700 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
707 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
708 a = init_node_attr(irn, 1);
711 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
713 /* Set output constraint to stack register. */
714 be_node_set_reg_class(irn, 0, sp->reg_class);
715 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
716 be_node_set_irn_reg(NULL, irn, sp);
721 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
725 ir_node *in[be_pos_AddSP_last];
726 const arch_register_class_t *class;
728 in[be_pos_AddSP_old_sp] = old_sp;
729 in[be_pos_AddSP_size] = sz;
731 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
732 a = init_node_attr(irn, be_pos_AddSP_last);
734 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
735 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
737 /* Set output constraint to stack register. */
738 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
739 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
740 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
741 a->reg_data[pn_be_AddSP_sp].reg = sp;
743 class = arch_register_get_class(sp);
744 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
749 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
753 ir_node *in[be_pos_SubSP_last];
755 in[be_pos_SubSP_old_sp] = old_sp;
756 in[be_pos_SubSP_size] = sz;
758 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
759 a = init_node_attr(irn, be_pos_SubSP_last);
761 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
762 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
764 /* Set output constraint to stack register. */
765 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
766 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
767 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
768 a->reg_data[pn_be_SubSP_sp].reg = sp;
773 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
778 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
779 init_node_attr(res, -1);
780 for(i = 0; i < n_outs; ++i)
781 add_register_req(res);
786 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
787 const arch_env_t *arch_env,
788 const arch_register_t *reg)
790 ir_graph *irg = get_irn_irg(regparams);
791 ir_node *block = get_nodes_block(regparams);
792 be_node_attr_t *attr = get_irn_attr(regparams);
793 const arch_register_class_t *cls = arch_register_get_class(reg);
794 ir_mode *mode = arch_register_class_mode(cls);
795 int n = ARR_LEN(attr->reg_data);
798 assert(be_is_RegParams(regparams));
799 proj = new_r_Proj(irg, block, regparams, mode, n);
800 add_register_req(regparams);
801 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
802 arch_set_irn_register(arch_env, proj, reg);
804 /* TODO decide, whether we need to set ignore/modify sp flags here? */
809 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
816 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
817 a = init_node_attr(irn, 1);
820 be_node_set_reg_class(irn, 0, cls_frame);
821 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
823 return optimize_node(irn);
826 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
827 assert(be_is_FrameAddr(node));
828 return get_irn_n(node, be_pos_FrameAddr_ptr);
831 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
833 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
837 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)
840 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
843 memcpy(&in[1], in_keep, n * sizeof(in[0]));
844 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
845 init_node_attr(irn, n + 1);
846 be_node_set_reg_class(irn, OUT_POS(0), cls);
847 be_node_set_reg_class(irn, 0, cls);
852 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)
857 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
860 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
861 return get_irn_n(cpy, be_pos_CopyKeep_op);
864 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
865 set_irn_n(cpy, be_pos_CopyKeep_op, op);
868 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
873 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
874 init_node_attr(res, -1);
875 for(i = 0; i < n; ++i) {
876 add_irn_n(res, in[i]);
877 add_register_req(res);
883 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
885 ir_graph *irg = get_irn_irg(barrier);
886 ir_node *block = get_nodes_block(barrier);
887 ir_mode *mode = get_irn_mode(node);
888 int n = add_irn_n(barrier, node);
890 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
891 add_register_req(barrier);
896 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
897 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
898 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
899 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
900 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
901 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
902 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
903 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
904 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
905 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
906 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
907 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
908 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
909 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
910 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
912 int be_has_frame_entity(const ir_node *irn)
914 switch(be_get_irn_opcode(irn)) {
924 ir_entity *be_get_frame_entity(const ir_node *irn)
926 if (be_has_frame_entity(irn)) {
927 const be_frame_attr_t *a = get_irn_attr_const(irn);
933 int be_get_frame_offset(const ir_node *irn)
935 assert(is_be_node(irn));
936 if (be_has_frame_entity(irn)) {
937 const be_frame_attr_t *a = get_irn_attr_const(irn);
943 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
945 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
947 assert(be_is_MemPerm(irn));
948 assert(n < be_get_MemPerm_entity_arity(irn));
950 attr->in_entities[n] = ent;
953 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
955 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
957 assert(be_is_MemPerm(irn));
958 assert(n < be_get_MemPerm_entity_arity(irn));
960 return attr->in_entities[n];
963 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
965 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
967 assert(be_is_MemPerm(irn));
968 assert(n < be_get_MemPerm_entity_arity(irn));
970 attr->out_entities[n] = ent;
973 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
975 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
977 assert(be_is_MemPerm(irn));
978 assert(n < be_get_MemPerm_entity_arity(irn));
980 return attr->out_entities[n];
983 int be_get_MemPerm_entity_arity(const ir_node *irn)
985 return get_irn_arity(irn) - 1;
988 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
990 arch_register_req_t *req = get_req(node, pos);
991 const arch_register_class_t *cls = arch_register_get_class(reg);
992 ir_graph *irg = get_irn_irg(node);
993 struct obstack *obst = get_irg_obstack(irg);
994 unsigned *limited_bitset;
996 assert(req->cls == NULL || req->cls == cls);
997 assert(! (req->type & arch_register_req_type_limited));
998 assert(req->limited == NULL);
1000 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1001 rbitset_set(limited_bitset, arch_register_get_index(reg));
1004 req->type |= arch_register_req_type_limited;
1005 req->limited = limited_bitset;
1008 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1010 ir_graph *irg = get_irn_irg(node);
1011 struct obstack *obst = get_irg_obstack(irg);
1012 arch_register_req_t *r = get_req(node, pos);
1014 assert(arch_register_req_is(req, limited));
1015 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1016 memcpy(r, req, sizeof(r[0]));
1017 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1020 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1022 be_req_t *bereq = get_be_req(irn, pos);
1023 bereq->flags = flags;
1026 void be_node_add_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1028 be_req_t *bereq = get_be_req(irn, pos);
1029 bereq->flags |= flags;
1032 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1034 arch_register_req_t *req = get_req(irn, pos);
1039 req->type = arch_register_req_type_none;
1040 } else if (req->type == arch_register_req_type_none) {
1041 req->type = arch_register_req_type_normal;
1045 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1047 arch_register_req_t *req = get_req(irn, pos);
1051 ir_node *be_get_IncSP_pred(ir_node *irn) {
1052 assert(be_is_IncSP(irn));
1053 return get_irn_n(irn, 0);
1056 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1057 assert(be_is_IncSP(incsp));
1058 set_irn_n(incsp, 0, pred);
1061 void be_set_IncSP_offset(ir_node *irn, int offset)
1063 be_stack_attr_t *a = get_irn_attr(irn);
1064 assert(be_is_IncSP(irn));
1068 int be_get_IncSP_offset(const ir_node *irn)
1070 const be_stack_attr_t *a = get_irn_attr_const(irn);
1071 assert(be_is_IncSP(irn));
1075 ir_node *be_spill(const arch_env_t *arch_env, ir_node *block, ir_node *irn)
1077 ir_graph *irg = get_irn_irg(block);
1078 ir_node *frame = get_irg_frame(irg);
1079 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1080 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1083 spill = be_new_Spill(cls, cls_frame, irg, block, frame, irn);
1087 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)
1090 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1091 ir_graph *irg = get_irn_irg(bl);
1092 ir_node *frame = get_irg_frame(irg);
1093 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1095 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1097 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1099 if (is_Block(insert)) {
1100 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1101 sched_add_after(insert, reload);
1103 sched_add_before(insert, reload);
1111 | _ \ ___ __ _ | _ \ ___ __ _ ___
1112 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1113 | _ < __/ (_| | | _ < __/ (_| \__ \
1114 |_| \_\___|\__, | |_| \_\___|\__, |___/
1121 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1123 const be_node_attr_t *a = get_irn_attr_const(irn);
1125 if(out_pos >= ARR_LEN(a->reg_data)) {
1126 return arch_no_register_req;
1129 return &a->reg_data[out_pos].req.req;
1133 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1135 const be_node_attr_t *a = get_irn_attr_const(irn);
1137 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1138 return arch_no_register_req;
1140 return &a->reg_data[pos].in_req.req;
1143 static const arch_register_req_t *
1144 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1150 if (get_irn_mode(irn) == mode_T)
1151 return arch_no_register_req;
1153 out_pos = redir_proj((const ir_node **)&irn);
1154 assert(is_be_node(irn));
1155 return get_out_reg_req(irn, out_pos);
1156 } else if (is_be_node(irn)) {
1158 * For spills and reloads, we return "none" as requirement for frame
1159 * pointer, so every input is ok. Some backends need this (e.g. STA).
1161 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1162 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1163 return arch_no_register_req;
1165 return get_in_reg_req(irn, pos);
1168 return arch_no_register_req;
1171 const arch_register_t *
1172 be_node_get_irn_reg(const void *self, const ir_node *irn)
1177 if (get_irn_mode(irn) == mode_T)
1179 r = retrieve_reg_data(irn);
1183 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1185 redir_proj((const ir_node **) &irn);
1188 switch(be_get_irn_opcode(irn)) {
1189 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1191 XXX(Reload, reload);
1194 XXX(Return, branch);
1197 return arch_irn_class_normal;
1203 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1210 pos = OUT_POS(get_Proj_proj(node));
1211 node = skip_Proj_const(node);
1214 bereq = get_be_req(node, pos);
1216 return bereq->flags;
1219 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1222 return be_get_frame_entity(irn);
1225 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1230 assert(be_has_frame_entity(irn));
1232 a = get_irn_attr(irn);
1236 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1239 if(be_has_frame_entity(irn)) {
1240 be_frame_attr_t *a = get_irn_attr(irn);
1245 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1248 if(be_is_IncSP(irn))
1249 return be_get_IncSP_offset(irn);
1251 return -(int)be_Call_get_pop(irn);
1257 ___ ____ _ _ _ _ _ _
1258 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1259 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1260 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1261 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1265 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1266 be_node_get_irn_reg_req,
1267 be_node_set_irn_reg,
1268 be_node_get_irn_reg,
1271 be_node_get_frame_entity,
1272 be_node_set_frame_entity,
1273 be_node_set_frame_offset,
1274 be_node_get_sp_bias,
1275 NULL, /* get_inverse */
1276 NULL, /* get_op_estimated_cost */
1277 NULL, /* possible_memory_operand */
1278 NULL, /* perform_memory_operand */
1281 static const arch_irn_ops_t be_node_irn_ops = {
1285 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1287 redir_proj((const ir_node **) &irn);
1289 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1292 const arch_irn_handler_t be_node_irn_handler = {
1297 ____ _ _ ___ ____ _ _ _ _ _ _
1298 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1299 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1300 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1301 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1306 const arch_register_t *reg;
1307 arch_register_req_t req;
1308 arch_irn_flags_t flags;
1312 arch_irn_handler_t irn_handler;
1313 arch_irn_ops_t irn_ops;
1314 const arch_env_t *arch_env;
1318 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1319 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1322 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1325 const phi_handler_t *h;
1326 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1329 h = get_phi_handler_from_handler(handler);
1334 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1336 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1338 ir_graph *irg = get_irn_irg(phi);
1339 struct obstack *obst = get_irg_obstack(irg);
1340 attr = obstack_alloc(obst, sizeof(attr[0]));
1341 memset(attr, 0, sizeof(attr[0]));
1342 pmap_insert(handler->phi_attrs, phi, attr);
1349 * Get register class of a Phi.
1352 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1356 int n = get_irn_arity(phi);
1360 if(*visited && pset_find_ptr(*visited, phi))
1363 for(i = 0; i < n; ++i) {
1364 op = get_irn_n(phi, i);
1365 /* Matze: don't we unnecessary constraint our phis with this?
1366 * we only need to take the regclass IMO*/
1368 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1372 * The operands of that Phi were all Phis themselves.
1373 * We have to start a DFS for a non-Phi argument now.
1376 *visited = pset_new_ptr(16);
1378 pset_insert_ptr(*visited, phi);
1380 for(i = 0; i < n; ++i) {
1381 const arch_register_req_t *req;
1382 op = get_irn_n(phi, i);
1383 req = get_Phi_reg_req_recursive(h, op, visited);
1392 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1393 const ir_node *irn, int pos)
1395 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1400 if(!mode_is_datab(get_irn_mode(irn)))
1401 return arch_no_register_req;
1403 attr = get_Phi_attr(phi_handler, irn);
1405 if(attr->req.type == arch_register_req_type_none) {
1406 pset *visited = NULL;
1407 const arch_register_req_t *req;
1408 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1410 memcpy(&attr->req, req, sizeof(req[0]));
1411 assert(attr->req.cls != NULL);
1412 attr->req.type = arch_register_req_type_normal;
1421 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1422 const arch_register_req_t *req)
1424 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1425 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1428 assert(mode_is_datab(get_irn_mode(node)));
1430 attr = get_Phi_attr(handler, node);
1431 memcpy(&attr->req, req, sizeof(req[0]));
1434 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1435 arch_irn_flags_t flags)
1437 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1438 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1441 assert(mode_is_datab(get_irn_mode(node)));
1443 attr = get_Phi_attr(handler, node);
1444 attr->flags = flags;
1448 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1450 phi_handler_t *h = get_phi_handler_from_ops(self);
1451 phi_attr_t *attr = get_Phi_attr(h, irn);
1456 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1458 phi_handler_t *h = get_phi_handler_from_ops(self);
1459 phi_attr_t *attr = get_Phi_attr(h, irn);
1464 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1468 return arch_irn_class_normal;
1472 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1474 phi_handler_t *h = get_phi_handler_from_ops(self);
1475 phi_attr_t *attr = get_Phi_attr(h, irn);
1481 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1489 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1498 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1507 int phi_get_sp_bias(const void* self, const ir_node *irn)
1515 const arch_irn_ops_if_t phi_irn_ops = {
1516 phi_get_irn_reg_req,
1521 phi_get_frame_entity,
1522 phi_set_frame_entity,
1523 phi_set_frame_offset,
1525 NULL, /* get_inverse */
1526 NULL, /* get_op_estimated_cost */
1527 NULL, /* possible_memory_operand */
1528 NULL, /* perform_memory_operand */
1531 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1533 phi_handler_t *h = xmalloc(sizeof(h[0]));
1534 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1535 h->irn_ops.impl = &phi_irn_ops;
1536 h->arch_env = arch_env;
1537 h->phi_attrs = pmap_create();
1538 return (arch_irn_handler_t *) h;
1541 void be_phi_handler_free(arch_irn_handler_t *handler)
1543 phi_handler_t *h = get_phi_handler_from_handler(handler);
1544 pmap_destroy(h->phi_attrs);
1545 h->phi_attrs = NULL;
1549 void be_phi_handler_reset(arch_irn_handler_t *handler)
1551 phi_handler_t *h = get_phi_handler_from_handler(handler);
1553 pmap_destroy(h->phi_attrs);
1554 h->phi_attrs = pmap_create();
1559 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1560 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1561 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1562 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1567 * Dumps a register requirement to a file.
1569 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1570 const ir_node *node)
1572 int did_something = 0;
1574 const char *prefix = buf;
1576 snprintf(buf, sizeof(buf), "#%d ", idx);
1577 buf[sizeof(buf) - 1] = '\0';
1582 arch_register_req_format(tmp, sizeof(tmp), req, node);
1583 fprintf(f, "%s", tmp);
1592 * Dumps node register requirements to a file.
1594 static void dump_node_reqs(FILE *f, ir_node *node)
1597 be_node_attr_t *a = get_irn_attr(node);
1598 int len = ARR_LEN(a->reg_data);
1600 fprintf(f, "registers: \n");
1601 for(i = 0; i < len; ++i) {
1602 be_reg_data_t *rd = &a->reg_data[i];
1604 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1607 fprintf(f, "in requirements:\n");
1608 for(i = 0; i < len; ++i) {
1609 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1612 fprintf(f, "\nout requirements:\n");
1613 for(i = 0; i < len; ++i) {
1614 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1619 * ir_op-Operation: dump a be node to file
1621 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1623 be_node_attr_t *at = get_irn_attr(irn);
1625 assert(is_be_node(irn));
1628 case dump_node_opcode_txt:
1629 fprintf(f, get_op_name(get_irn_op(irn)));
1631 case dump_node_mode_txt:
1632 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1633 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1636 case dump_node_nodeattr_txt:
1637 if(be_is_Call(irn)) {
1638 be_call_attr_t *a = (be_call_attr_t *) at;
1640 fprintf(f, " [%s] ", get_entity_name(a->ent));
1642 if(be_is_IncSP(irn)) {
1643 const be_stack_attr_t *attr = get_irn_generic_attr_const(irn);
1644 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1645 fprintf(f, " [Setup Stackframe] ");
1646 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1647 fprintf(f, " [Destroy Stackframe] ");
1649 fprintf(f, " [%d] ", attr->offset);
1653 case dump_node_info_txt:
1654 dump_node_reqs(f, irn);
1656 if(be_has_frame_entity(irn)) {
1657 be_frame_attr_t *a = (be_frame_attr_t *) at;
1659 int bits = get_type_size_bits(get_entity_type(a->ent));
1660 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1661 a->ent, a->offset, a->offset, bits, bits);
1666 switch(be_get_irn_opcode(irn)) {
1669 be_stack_attr_t *a = (be_stack_attr_t *) at;
1670 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1671 fprintf(f, "offset: FRAME_SIZE\n");
1672 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1673 fprintf(f, "offset: -FRAME SIZE\n");
1675 fprintf(f, "offset: %u\n", a->offset);
1680 be_call_attr_t *a = (be_call_attr_t *) at;
1683 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1689 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1690 ir_entity *in, *out;
1691 in = be_get_MemPerm_in_entity(irn, i);
1692 out = be_get_MemPerm_out_entity(irn, i);
1694 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1697 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1713 * Copies the backend specific attributes from old node to new node.
1715 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1717 const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
1718 be_node_attr_t *new_attr = get_irn_attr(new_node);
1719 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1722 assert(is_be_node(old_node));
1723 assert(is_be_node(new_node));
1725 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1726 new_attr->reg_data = NULL;
1728 if(old_attr->reg_data != NULL)
1729 len = ARR_LEN(old_attr->reg_data);
1733 if(get_irn_op(old_node)->opar == oparity_dynamic
1734 || be_is_RegParams(old_node)) {
1735 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1737 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1741 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1742 for(i = 0; i < len; ++i) {
1743 const be_reg_data_t *rd = &old_attr->reg_data[i];
1744 be_reg_data_t *newrd = &new_attr->reg_data[i];
1745 if(arch_register_req_is(&rd->req.req, limited)) {
1746 const arch_register_req_t *req = &rd->req.req;
1747 arch_register_req_t *new_req = &newrd->req.req;
1749 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1751 if(arch_register_req_is(&rd->in_req.req, limited)) {
1752 const arch_register_req_t *req = &rd->in_req.req;
1753 arch_register_req_t *new_req = &newrd->in_req.req;
1755 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1761 static const ir_op_ops be_node_op_ops = {