2 * Copyright (C) 1995-2008 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; /**< base attributes of every be node. */
88 int num_ret_vals; /**< number of return values */
89 unsigned pop; /**< number of bytes that should be popped */
92 /** The be_IncSP attribute type. */
94 be_node_attr_t node_attr; /**< base attributes of every be node. */
95 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
96 int align; /**< wether stack should be aligned after the
100 /** The be_Frame attribute type. */
102 be_node_attr_t node_attr; /**< base attributes of every be node. */
107 /** The be_Call attribute type. */
109 be_node_attr_t node_attr; /**< base attributes of every be node. */
110 ir_entity *ent; /**< The called entity if this is a static call. */
112 ir_type *call_tp; /**< The call type, copied from the original Call node. */
116 be_node_attr_t node_attr; /**< base attributes of every be node. */
117 ir_entity **in_entities;
118 ir_entity **out_entities;
124 ir_op *op_be_MemPerm;
127 ir_op *op_be_CopyKeep;
133 ir_op *op_be_RegParams;
134 ir_op *op_be_FrameAddr;
135 ir_op *op_be_Barrier;
138 static int beo_base = -1;
140 static const ir_op_ops be_node_op_ops;
142 #define N irop_flag_none
143 #define L irop_flag_labeled
144 #define C irop_flag_commutative
145 #define X irop_flag_cfopcode
146 #define I irop_flag_ip_cfopcode
147 #define F irop_flag_fragile
148 #define Y irop_flag_forking
149 #define H irop_flag_highlevel
150 #define c irop_flag_constlike
151 #define K irop_flag_keep
152 #define M irop_flag_uses_memory
156 * Compare two be node attributes.
158 * @return zero if both attributes are identically
160 static int _node_cmp_attr(const be_node_attr_t *a, const be_node_attr_t *b) {
163 if (ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
166 len = ARR_LEN(a->reg_data);
167 for (i = 0; i < len; ++i) {
168 if (a->reg_data[i].reg != b->reg_data[i].reg ||
169 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
170 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
178 * Compare the node attributes of two be_node's.
180 * @return zero if both nodes have identically attributes
182 static int node_cmp_attr(ir_node *a, ir_node *b) {
183 const be_node_attr_t *a_attr = get_irn_attr_const(a);
184 const be_node_attr_t *b_attr = get_irn_attr_const(b);
186 return _node_cmp_attr(a_attr, b_attr);
190 * Compare the attributes of two be_FrameAddr nodes.
192 * @return zero if both nodes have identically attributes
194 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
195 const be_frame_attr_t *a_attr = get_irn_attr_const(a);
196 const be_frame_attr_t *b_attr = get_irn_attr_const(b);
198 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
201 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
205 * Compare the attributes of two be_Return nodes.
207 * @return zero if both nodes have identically attributes
209 static int Return_cmp_attr(ir_node *a, ir_node *b) {
210 const be_return_attr_t *a_attr = get_irn_attr_const(a);
211 const be_return_attr_t *b_attr = get_irn_attr_const(b);
213 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
215 if (a_attr->pop != b_attr->pop)
218 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
222 * Compare the attributes of two be_IncSP nodes.
224 * @return zero if both nodes have identically attributes
226 static int IncSP_cmp_attr(ir_node *a, ir_node *b) {
227 const be_incsp_attr_t *a_attr = get_irn_attr_const(a);
228 const be_incsp_attr_t *b_attr = get_irn_attr_const(b);
230 if (a_attr->offset != b_attr->offset)
233 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
237 * Compare the attributes of two be_Call nodes.
239 * @return zero if both nodes have identically attributes
241 static int Call_cmp_attr(ir_node *a, ir_node *b) {
242 const be_call_attr_t *a_attr = get_irn_attr_const(a);
243 const be_call_attr_t *b_attr = get_irn_attr_const(b);
245 if (a_attr->ent != b_attr->ent ||
246 a_attr->call_tp != b_attr->call_tp)
249 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
252 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
255 const be_node_attr_t *attr;
258 assert(is_be_node(node));
259 attr = get_irn_attr_const(node);
265 assert(idx < get_irn_arity(node));
267 assert(idx < ARR_LEN(attr->reg_data));
268 rd = &attr->reg_data[idx];
270 return pos < 0 ? &rd->req : &rd->in_req;
273 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
275 be_req_t *bereq = get_be_req(node, pos);
279 void be_node_init(void) {
280 static int inited = 0;
287 /* Acquire all needed opcodes. */
288 beo_base = get_next_ir_opcodes(beo_Last);
290 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);
291 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);
292 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);
293 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);
294 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);
295 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);
296 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);
297 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);
298 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);
299 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);
300 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);
301 op_be_IncSP = new_ir_op(beo_base + beo_IncSP, "be_IncSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_incsp_attr_t), &be_node_op_ops);
302 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);
303 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);
304 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);
305 op_be_Unwind = new_ir_op(beo_base + beo_Unwind, "be_Unwind", op_pin_state_pinned, X, oparity_zero, 0, sizeof(be_node_attr_t), &be_node_op_ops);
307 set_op_tag(op_be_Spill, &be_node_tag);
308 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
309 set_op_tag(op_be_Reload, &be_node_tag);
310 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
311 set_op_tag(op_be_Perm, &be_node_tag);
312 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
313 set_op_tag(op_be_MemPerm, &be_node_tag);
314 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
315 set_op_tag(op_be_Copy, &be_node_tag);
316 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
317 set_op_tag(op_be_Keep, &be_node_tag);
318 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
319 set_op_tag(op_be_CopyKeep, &be_node_tag);
320 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
321 set_op_tag(op_be_Call, &be_node_tag);
322 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
323 set_op_tag(op_be_Return, &be_node_tag);
324 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
325 set_op_tag(op_be_AddSP, &be_node_tag);
326 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
327 set_op_tag(op_be_SubSP, &be_node_tag);
328 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
329 set_op_tag(op_be_IncSP, &be_node_tag);
330 op_be_IncSP->ops.node_cmp_attr = IncSP_cmp_attr;
331 set_op_tag(op_be_RegParams, &be_node_tag);
332 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
333 set_op_tag(op_be_FrameAddr, &be_node_tag);
334 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
335 set_op_tag(op_be_Barrier, &be_node_tag);
336 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
337 set_op_tag(op_be_Unwind, &be_node_tag);
338 op_be_Unwind->ops.node_cmp_attr = node_cmp_attr;
342 * Initializes the generic attribute of all be nodes and return ir.
344 static void *init_node_attr(ir_node *node, int max_reg_data)
346 ir_graph *irg = get_irn_irg(node);
347 struct obstack *obst = get_irg_obstack(irg);
348 be_node_attr_t *a = get_irn_attr(node);
350 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
352 if(max_reg_data >= 0) {
353 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
354 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
356 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
362 static void add_register_req(ir_node *node)
364 be_node_attr_t *a = get_irn_attr(node);
365 be_reg_data_t regreq;
366 memset(®req, 0, sizeof(regreq));
367 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
370 int is_be_node(const ir_node *irn)
372 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
375 be_opcode_t be_get_irn_opcode(const ir_node *irn)
377 return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
381 * Skip Proj nodes and return their Proj numbers.
383 * If *node is a Proj or Proj(Proj) node, skip it.
385 * @param node points to the node to be skipped
387 * @return 0 if *node was no Proj node, its Proj number else.
389 static int redir_proj(const ir_node **node)
391 const ir_node *n = *node;
396 *node = irn = get_Proj_pred(n);
398 assert(get_irn_mode(irn) == mode_T);
399 *node = get_Proj_pred(irn);
401 return get_Proj_proj(n);
407 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
409 const be_node_attr_t *attr;
413 pos = get_Proj_proj(node);
414 node = get_Proj_pred(node);
417 assert(is_be_node(node));
418 attr = get_irn_attr_const(node);
419 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
421 return &attr->reg_data[pos];
425 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
427 be_reg_data_t *r = retrieve_reg_data(irn);
432 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
433 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
441 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
442 a = init_node_attr(res, 2);
446 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
447 be_node_set_reg_class(res, be_pos_Spill_val, cls);
451 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
452 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
459 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
461 init_node_attr(res, 2);
462 be_node_set_reg_class(res, -1, cls);
463 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
464 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
468 ir_node *be_get_Reload_mem(const ir_node *irn)
470 assert(be_is_Reload(irn));
471 return get_irn_n(irn, be_pos_Reload_mem);
474 ir_node *be_get_Reload_frame(const ir_node *irn)
476 assert(be_is_Reload(irn));
477 return get_irn_n(irn, be_pos_Reload_frame);
480 ir_node *be_get_Spill_val(const ir_node *irn)
482 assert(be_is_Spill(irn));
483 return get_irn_n(irn, be_pos_Spill_val);
486 ir_node *be_get_Spill_frame(const ir_node *irn)
488 assert(be_is_Spill(irn));
489 return get_irn_n(irn, be_pos_Spill_frame);
492 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
495 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
496 init_node_attr(irn, n);
497 for(i = 0; i < n; ++i) {
498 be_node_set_reg_class(irn, i, cls);
499 be_node_set_reg_class(irn, OUT_POS(i), cls);
505 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
507 ir_graph *irg = get_irn_irg(perm);
508 int arity = get_irn_arity(perm);
509 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
510 be_node_attr_t *attr = get_irn_attr(perm);
511 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
515 assert(be_is_Perm(perm));
516 assert(new_size <= arity);
518 /* save the old register data */
519 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
521 /* compose the new in array and set the new register data directly in place */
522 for (i = 0; i < new_size; ++i) {
524 new_in[i] = get_irn_n(perm, idx);
525 attr->reg_data[i] = old_data[idx];
528 set_irn_in(perm, new_size, new_in);
531 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
534 ir_node *frame = get_irg_frame(irg);
535 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
537 const arch_register_t *sp = arch_env->isa->sp;
538 be_memperm_attr_t *attr;
541 real_in = alloca((n+1) * sizeof(real_in[0]));
543 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
545 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
547 init_node_attr(irn, n + 1);
548 be_node_set_reg_class(irn, 0, sp->reg_class);
549 for (i = 0; i < n; ++i) {
550 be_node_set_reg_class(irn, i + 1, cls_frame);
551 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
554 attr = get_irn_attr(irn);
556 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
557 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
558 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
559 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
565 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
569 arch_register_req_t *req;
572 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
573 init_node_attr(res, 1);
574 be_node_set_reg_class(res, 0, cls);
575 be_node_set_reg_class(res, OUT_POS(0), cls);
577 req = get_req(res, OUT_POS(0));
579 req->type = arch_register_req_type_should_be_same;
580 req->other_same = 1U << 0;
585 ir_node *be_get_Copy_op(const ir_node *cpy) {
586 return get_irn_n(cpy, be_pos_Copy_op);
589 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
590 set_irn_n(cpy, be_pos_Copy_op, op);
593 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
598 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
599 init_node_attr(res, -1);
601 for(i = 0; i < n; ++i) {
602 add_irn_n(res, in[i]);
603 add_register_req(res);
604 be_node_set_reg_class(res, i, cls);
611 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
615 assert(be_is_Keep(keep));
616 n = add_irn_n(keep, node);
617 add_register_req(keep);
618 be_node_set_reg_class(keep, n, cls);
621 /* creates a be_Call */
622 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
623 int n_outs, int n, ir_node *in[], ir_type *call_tp)
626 int real_n = be_pos_Call_first_arg + n;
630 NEW_ARR_A(ir_node *, real_in, real_n);
631 real_in[be_pos_Call_mem] = mem;
632 real_in[be_pos_Call_sp] = sp;
633 real_in[be_pos_Call_ptr] = ptr;
634 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
636 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
637 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
639 a->call_tp = call_tp;
644 /* Gets the call entity or NULL if this is no static call. */
645 ir_entity *be_Call_get_entity(const ir_node *call) {
646 const be_call_attr_t *a = get_irn_attr_const(call);
647 assert(be_is_Call(call));
651 /* Sets the call entity. */
652 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
653 be_call_attr_t *a = get_irn_attr(call);
654 assert(be_is_Call(call));
658 /* Gets the call type. */
659 ir_type *be_Call_get_type(ir_node *call) {
660 const be_call_attr_t *a = get_irn_attr_const(call);
661 assert(be_is_Call(call));
665 /* Sets the call type. */
666 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
667 be_call_attr_t *a = get_irn_attr(call);
668 assert(be_is_Call(call));
669 a->call_tp = call_tp;
672 void be_Call_set_pop(ir_node *call, unsigned pop) {
673 be_call_attr_t *a = get_irn_attr(call);
677 unsigned be_Call_get_pop(const ir_node *call) {
678 const be_call_attr_t *a = get_irn_attr_const(call);
682 /* Construct a new be_Return. */
683 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
684 unsigned pop, int n, ir_node *in[])
690 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
691 init_node_attr(res, -1);
692 for(i = 0; i < n; ++i) {
693 add_irn_n(res, in[i]);
694 add_register_req(res);
697 a = get_irn_attr(res);
698 a->num_ret_vals = n_res;
704 /* Returns the number of real returns values */
705 int be_Return_get_n_rets(const ir_node *ret)
707 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
708 return a->num_ret_vals;
711 unsigned be_Return_get_pop(const ir_node *ret)
713 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
717 int be_Return_append_node(ir_node *ret, ir_node *node)
721 pos = add_irn_n(ret, node);
722 add_register_req(ret);
727 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl,
728 ir_node *old_sp, int offset, int align)
735 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode,
736 sizeof(in) / sizeof(in[0]), in);
737 a = init_node_attr(irn, 1);
741 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
743 /* Set output constraint to stack register. */
744 be_node_set_reg_class(irn, 0, sp->reg_class);
745 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
746 be_node_set_irn_reg(NULL, irn, sp);
751 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
755 ir_node *in[be_pos_AddSP_last];
756 const arch_register_class_t *class;
758 in[be_pos_AddSP_old_sp] = old_sp;
759 in[be_pos_AddSP_size] = sz;
761 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
762 a = init_node_attr(irn, be_pos_AddSP_last);
764 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
765 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
767 /* Set output constraint to stack register. */
768 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
769 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
770 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
771 a->reg_data[pn_be_AddSP_sp].reg = sp;
773 class = arch_register_get_class(sp);
774 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
779 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
783 ir_node *in[be_pos_SubSP_last];
785 in[be_pos_SubSP_old_sp] = old_sp;
786 in[be_pos_SubSP_size] = sz;
788 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
789 a = init_node_attr(irn, be_pos_SubSP_last);
791 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
792 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
794 /* Set output constraint to stack register. */
795 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
796 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
797 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
798 a->reg_data[pn_be_SubSP_sp].reg = sp;
803 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
808 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
809 init_node_attr(res, -1);
810 for(i = 0; i < n_outs; ++i)
811 add_register_req(res);
816 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
817 const arch_env_t *arch_env,
818 const arch_register_t *reg)
820 ir_graph *irg = get_irn_irg(regparams);
821 ir_node *block = get_nodes_block(regparams);
822 be_node_attr_t *attr = get_irn_attr(regparams);
823 const arch_register_class_t *cls = arch_register_get_class(reg);
824 ir_mode *mode = arch_register_class_mode(cls);
825 int n = ARR_LEN(attr->reg_data);
828 assert(be_is_RegParams(regparams));
829 proj = new_r_Proj(irg, block, regparams, mode, n);
830 add_register_req(regparams);
831 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
832 arch_set_irn_register(arch_env, proj, reg);
834 /* TODO decide, whether we need to set ignore/modify sp flags here? */
839 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
846 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
847 a = init_node_attr(irn, 1);
850 be_node_set_reg_class(irn, 0, cls_frame);
851 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
853 return optimize_node(irn);
856 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
857 assert(be_is_FrameAddr(node));
858 return get_irn_n(node, be_pos_FrameAddr_ptr);
861 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
863 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
867 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)
870 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
873 memcpy(&in[1], in_keep, n * sizeof(in[0]));
874 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
875 init_node_attr(irn, n + 1);
876 be_node_set_reg_class(irn, OUT_POS(0), cls);
877 be_node_set_reg_class(irn, 0, cls);
882 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)
884 return be_new_CopyKeep(cls, irg, bl, src, 1, &keep, mode);
887 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
888 return get_irn_n(cpy, be_pos_CopyKeep_op);
891 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
892 set_irn_n(cpy, be_pos_CopyKeep_op, op);
895 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
900 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
901 init_node_attr(res, -1);
902 for(i = 0; i < n; ++i) {
903 add_irn_n(res, in[i]);
904 add_register_req(res);
910 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
912 ir_graph *irg = get_irn_irg(barrier);
913 ir_node *block = get_nodes_block(barrier);
914 ir_mode *mode = get_irn_mode(node);
915 int n = add_irn_n(barrier, node);
917 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
918 add_register_req(barrier);
923 /* Construct a new be_Unwind. */
924 ir_node *be_new_Unwind(dbg_info *dbg, ir_graph *irg, ir_node *block,
925 ir_node *mem, ir_node *sp)
930 in[be_pos_Unwind_mem] = mem;
931 in[be_pos_Unwind_sp] = sp;
932 res = new_ir_node(dbg, irg, block, op_be_Unwind, mode_X, 2, in);
933 init_node_attr(res, -1);
938 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
939 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
940 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
941 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
942 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
943 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
944 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
945 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
946 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
947 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
948 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
949 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
950 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
951 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
952 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
953 int be_is_Unwind (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Unwind ; }
955 int be_has_frame_entity(const ir_node *irn)
957 switch (be_get_irn_opcode(irn)) {
967 ir_entity *be_get_frame_entity(const ir_node *irn)
969 if (be_has_frame_entity(irn)) {
970 const be_frame_attr_t *a = get_irn_attr_const(irn);
976 int be_get_frame_offset(const ir_node *irn)
978 assert(is_be_node(irn));
979 if (be_has_frame_entity(irn)) {
980 const be_frame_attr_t *a = get_irn_attr_const(irn);
986 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
988 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
990 assert(be_is_MemPerm(irn));
991 assert(n < be_get_MemPerm_entity_arity(irn));
993 attr->in_entities[n] = ent;
996 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
998 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
1000 assert(be_is_MemPerm(irn));
1001 assert(n < be_get_MemPerm_entity_arity(irn));
1003 return attr->in_entities[n];
1006 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
1008 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
1010 assert(be_is_MemPerm(irn));
1011 assert(n < be_get_MemPerm_entity_arity(irn));
1013 attr->out_entities[n] = ent;
1016 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
1018 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
1020 assert(be_is_MemPerm(irn));
1021 assert(n < be_get_MemPerm_entity_arity(irn));
1023 return attr->out_entities[n];
1026 int be_get_MemPerm_entity_arity(const ir_node *irn)
1028 return get_irn_arity(irn) - 1;
1031 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
1033 arch_register_req_t *req = get_req(node, pos);
1034 const arch_register_class_t *cls = arch_register_get_class(reg);
1035 ir_graph *irg = get_irn_irg(node);
1036 struct obstack *obst = get_irg_obstack(irg);
1037 unsigned *limited_bitset;
1039 assert(req->cls == NULL || req->cls == cls);
1040 assert(! (req->type & arch_register_req_type_limited));
1041 assert(req->limited == NULL);
1043 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1044 rbitset_set(limited_bitset, arch_register_get_index(reg));
1047 req->type |= arch_register_req_type_limited;
1048 req->limited = limited_bitset;
1051 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1053 ir_graph *irg = get_irn_irg(node);
1054 struct obstack *obst = get_irg_obstack(irg);
1055 arch_register_req_t *r = get_req(node, pos);
1057 assert(arch_register_req_is(req, limited));
1058 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1059 memcpy(r, req, sizeof(r[0]));
1060 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1063 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1065 be_req_t *bereq = get_be_req(irn, pos);
1066 bereq->flags = flags;
1069 void be_node_add_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1071 be_req_t *bereq = get_be_req(irn, pos);
1072 bereq->flags |= flags;
1075 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1077 arch_register_req_t *req = get_req(irn, pos);
1082 req->type = arch_register_req_type_none;
1083 } else if (req->type == arch_register_req_type_none) {
1084 req->type = arch_register_req_type_normal;
1088 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1090 arch_register_req_t *req = get_req(irn, pos);
1094 ir_node *be_get_IncSP_pred(ir_node *irn) {
1095 assert(be_is_IncSP(irn));
1096 return get_irn_n(irn, 0);
1099 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1100 assert(be_is_IncSP(incsp));
1101 set_irn_n(incsp, 0, pred);
1104 void be_set_IncSP_offset(ir_node *irn, int offset)
1106 be_incsp_attr_t *a = get_irn_attr(irn);
1107 assert(be_is_IncSP(irn));
1111 int be_get_IncSP_offset(const ir_node *irn)
1113 const be_incsp_attr_t *a = get_irn_attr_const(irn);
1114 assert(be_is_IncSP(irn));
1118 int be_get_IncSP_align(const ir_node *irn)
1120 const be_incsp_attr_t *a = get_irn_attr_const(irn);
1121 assert(be_is_IncSP(irn));
1125 ir_node *be_spill(const arch_env_t *arch_env, ir_node *block, ir_node *irn)
1127 ir_graph *irg = get_irn_irg(block);
1128 ir_node *frame = get_irg_frame(irg);
1129 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1130 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1133 spill = be_new_Spill(cls, cls_frame, irg, block, frame, irn);
1137 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)
1140 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1141 ir_graph *irg = get_irn_irg(bl);
1142 ir_node *frame = get_irg_frame(irg);
1143 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1145 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1147 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1149 if (is_Block(insert)) {
1150 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1151 sched_add_after(insert, reload);
1153 sched_add_before(insert, reload);
1161 | _ \ ___ __ _ | _ \ ___ __ _ ___
1162 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1163 | _ < __/ (_| | | _ < __/ (_| \__ \
1164 |_| \_\___|\__, | |_| \_\___|\__, |___/
1171 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1173 const be_node_attr_t *a = get_irn_attr_const(irn);
1175 if(out_pos >= ARR_LEN(a->reg_data)) {
1176 return arch_no_register_req;
1179 return &a->reg_data[out_pos].req.req;
1183 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1185 const be_node_attr_t *a = get_irn_attr_const(irn);
1187 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1188 return arch_no_register_req;
1190 return &a->reg_data[pos].in_req.req;
1193 static const arch_register_req_t *
1194 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1200 if (get_irn_mode(irn) == mode_T)
1201 return arch_no_register_req;
1203 out_pos = redir_proj((const ir_node **)&irn);
1204 assert(is_be_node(irn));
1205 return get_out_reg_req(irn, out_pos);
1206 } else if (is_be_node(irn)) {
1208 * For spills and reloads, we return "none" as requirement for frame
1209 * pointer, so every input is ok. Some backends need this (e.g. STA).
1211 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1212 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1213 return arch_no_register_req;
1215 return get_in_reg_req(irn, pos);
1218 return arch_no_register_req;
1221 const arch_register_t *
1222 be_node_get_irn_reg(const void *self, const ir_node *irn)
1227 if (get_irn_mode(irn) == mode_T)
1229 r = retrieve_reg_data(irn);
1233 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1235 redir_proj((const ir_node **) &irn);
1238 switch(be_get_irn_opcode(irn)) {
1239 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1241 XXX(Reload, reload);
1244 XXX(Return, branch);
1247 return arch_irn_class_normal;
1253 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1260 pos = OUT_POS(get_Proj_proj(node));
1261 node = skip_Proj_const(node);
1264 bereq = get_be_req(node, pos);
1266 return bereq->flags;
1269 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1272 return be_get_frame_entity(irn);
1275 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1280 assert(be_has_frame_entity(irn));
1282 a = get_irn_attr(irn);
1286 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1289 if(be_has_frame_entity(irn)) {
1290 be_frame_attr_t *a = get_irn_attr(irn);
1295 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1298 if(be_is_IncSP(irn))
1299 return be_get_IncSP_offset(irn);
1301 return -(int)be_Call_get_pop(irn);
1307 ___ ____ _ _ _ _ _ _
1308 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1309 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1310 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1311 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1315 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1316 be_node_get_irn_reg_req,
1317 be_node_set_irn_reg,
1318 be_node_get_irn_reg,
1321 be_node_get_frame_entity,
1322 be_node_set_frame_entity,
1323 be_node_set_frame_offset,
1324 be_node_get_sp_bias,
1325 NULL, /* get_inverse */
1326 NULL, /* get_op_estimated_cost */
1327 NULL, /* possible_memory_operand */
1328 NULL, /* perform_memory_operand */
1331 static const arch_irn_ops_t be_node_irn_ops = {
1335 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1337 redir_proj((const ir_node **) &irn);
1339 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1342 const arch_irn_handler_t be_node_irn_handler = {
1347 ____ _ _ ___ ____ _ _ _ _ _ _
1348 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1349 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1350 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1351 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1356 const arch_register_t *reg;
1357 arch_register_req_t req;
1358 arch_irn_flags_t flags;
1362 arch_irn_handler_t irn_handler;
1363 arch_irn_ops_t irn_ops;
1364 const arch_env_t *arch_env;
1368 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1369 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1372 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1375 const phi_handler_t *h;
1376 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1379 h = get_phi_handler_from_handler(handler);
1384 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1386 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1388 ir_graph *irg = get_irn_irg(phi);
1389 struct obstack *obst = get_irg_obstack(irg);
1390 attr = obstack_alloc(obst, sizeof(attr[0]));
1391 memset(attr, 0, sizeof(attr[0]));
1392 pmap_insert(handler->phi_attrs, phi, attr);
1399 * Get register class of a Phi.
1402 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1406 int n = get_irn_arity(phi);
1410 if(*visited && pset_find_ptr(*visited, phi))
1413 for(i = 0; i < n; ++i) {
1414 op = get_irn_n(phi, i);
1415 /* Matze: don't we unnecessary constraint our phis with this?
1416 * we only need to take the regclass IMO*/
1418 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1422 * The operands of that Phi were all Phis themselves.
1423 * We have to start a DFS for a non-Phi argument now.
1426 *visited = pset_new_ptr(16);
1428 pset_insert_ptr(*visited, phi);
1430 for(i = 0; i < n; ++i) {
1431 const arch_register_req_t *req;
1432 op = get_irn_n(phi, i);
1433 req = get_Phi_reg_req_recursive(h, op, visited);
1442 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1443 const ir_node *irn, int pos)
1445 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1450 if(!mode_is_datab(get_irn_mode(irn)))
1451 return arch_no_register_req;
1453 attr = get_Phi_attr(phi_handler, irn);
1455 if(attr->req.type == arch_register_req_type_none) {
1456 pset *visited = NULL;
1457 const arch_register_req_t *req;
1458 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1460 memcpy(&attr->req, req, sizeof(req[0]));
1461 assert(attr->req.cls != NULL);
1462 attr->req.type = arch_register_req_type_normal;
1471 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1472 const arch_register_req_t *req)
1474 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1475 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1478 assert(mode_is_datab(get_irn_mode(node)));
1480 attr = get_Phi_attr(handler, node);
1481 memcpy(&attr->req, req, sizeof(req[0]));
1484 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1485 arch_irn_flags_t flags)
1487 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1488 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1491 assert(mode_is_datab(get_irn_mode(node)));
1493 attr = get_Phi_attr(handler, node);
1494 attr->flags = flags;
1498 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1500 phi_handler_t *h = get_phi_handler_from_ops(self);
1501 phi_attr_t *attr = get_Phi_attr(h, irn);
1506 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1508 phi_handler_t *h = get_phi_handler_from_ops(self);
1509 phi_attr_t *attr = get_Phi_attr(h, irn);
1514 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1518 return arch_irn_class_normal;
1522 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1524 phi_handler_t *h = get_phi_handler_from_ops(self);
1525 phi_attr_t *attr = get_Phi_attr(h, irn);
1531 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1539 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1548 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1557 int phi_get_sp_bias(const void* self, const ir_node *irn)
1565 const arch_irn_ops_if_t phi_irn_ops = {
1566 phi_get_irn_reg_req,
1571 phi_get_frame_entity,
1572 phi_set_frame_entity,
1573 phi_set_frame_offset,
1575 NULL, /* get_inverse */
1576 NULL, /* get_op_estimated_cost */
1577 NULL, /* possible_memory_operand */
1578 NULL, /* perform_memory_operand */
1581 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1583 phi_handler_t *h = xmalloc(sizeof(h[0]));
1584 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1585 h->irn_ops.impl = &phi_irn_ops;
1586 h->arch_env = arch_env;
1587 h->phi_attrs = pmap_create();
1588 return (arch_irn_handler_t *) h;
1591 void be_phi_handler_free(arch_irn_handler_t *handler)
1593 phi_handler_t *h = get_phi_handler_from_handler(handler);
1594 pmap_destroy(h->phi_attrs);
1595 h->phi_attrs = NULL;
1599 void be_phi_handler_reset(arch_irn_handler_t *handler)
1601 phi_handler_t *h = get_phi_handler_from_handler(handler);
1603 pmap_destroy(h->phi_attrs);
1604 h->phi_attrs = pmap_create();
1609 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1610 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1611 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1612 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1617 * Dumps a register requirement to a file.
1619 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1620 const ir_node *node)
1622 int did_something = 0;
1624 const char *prefix = buf;
1626 snprintf(buf, sizeof(buf), "#%d ", idx);
1627 buf[sizeof(buf) - 1] = '\0';
1632 arch_register_req_format(tmp, sizeof(tmp), req, node);
1633 fprintf(f, "%s", tmp);
1642 * Dumps node register requirements to a file.
1644 static void dump_node_reqs(FILE *f, ir_node *node)
1647 be_node_attr_t *a = get_irn_attr(node);
1648 int len = ARR_LEN(a->reg_data);
1650 fprintf(f, "registers: \n");
1651 for(i = 0; i < len; ++i) {
1652 be_reg_data_t *rd = &a->reg_data[i];
1654 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1657 fprintf(f, "in requirements:\n");
1658 for(i = 0; i < len; ++i) {
1659 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1662 fprintf(f, "\nout requirements:\n");
1663 for(i = 0; i < len; ++i) {
1664 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1669 * ir_op-Operation: dump a be node to file
1671 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1673 be_node_attr_t *at = get_irn_attr(irn);
1675 assert(is_be_node(irn));
1678 case dump_node_opcode_txt:
1679 fprintf(f, get_op_name(get_irn_op(irn)));
1681 case dump_node_mode_txt:
1682 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1683 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1686 case dump_node_nodeattr_txt:
1687 if(be_is_Call(irn)) {
1688 be_call_attr_t *a = (be_call_attr_t *) at;
1690 fprintf(f, " [%s] ", get_entity_name(a->ent));
1692 if(be_is_IncSP(irn)) {
1693 const be_incsp_attr_t *attr = get_irn_generic_attr_const(irn);
1694 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1695 fprintf(f, " [Setup Stackframe] ");
1696 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1697 fprintf(f, " [Destroy Stackframe] ");
1699 fprintf(f, " [%d] ", attr->offset);
1703 case dump_node_info_txt:
1704 dump_node_reqs(f, irn);
1706 if(be_has_frame_entity(irn)) {
1707 be_frame_attr_t *a = (be_frame_attr_t *) at;
1709 unsigned size = get_type_size_bytes(get_entity_type(a->ent));
1710 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
1711 a->ent, a->offset, a->offset, size, size);
1716 switch(be_get_irn_opcode(irn)) {
1719 be_incsp_attr_t *a = (be_incsp_attr_t *) at;
1720 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1721 fprintf(f, "offset: FRAME_SIZE\n");
1722 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1723 fprintf(f, "offset: -FRAME SIZE\n");
1725 fprintf(f, "offset: %u\n", a->offset);
1730 be_call_attr_t *a = (be_call_attr_t *) at;
1733 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1739 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1740 ir_entity *in, *out;
1741 in = be_get_MemPerm_in_entity(irn, i);
1742 out = be_get_MemPerm_out_entity(irn, i);
1744 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1747 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1763 * Copies the backend specific attributes from old node to new node.
1765 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1767 const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
1768 be_node_attr_t *new_attr = get_irn_attr(new_node);
1769 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1772 assert(is_be_node(old_node));
1773 assert(is_be_node(new_node));
1775 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1776 new_attr->reg_data = NULL;
1778 if(old_attr->reg_data != NULL)
1779 len = ARR_LEN(old_attr->reg_data);
1783 if(get_irn_op(old_node)->opar == oparity_dynamic
1784 || be_is_RegParams(old_node)) {
1785 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1787 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1791 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1792 for(i = 0; i < len; ++i) {
1793 const be_reg_data_t *rd = &old_attr->reg_data[i];
1794 be_reg_data_t *newrd = &new_attr->reg_data[i];
1795 if(arch_register_req_is(&rd->req.req, limited)) {
1796 const arch_register_req_t *req = &rd->req.req;
1797 arch_register_req_t *new_req = &newrd->req.req;
1799 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1801 if(arch_register_req_is(&rd->in_req.req, limited)) {
1802 const arch_register_req_t *req = &rd->in_req.req;
1803 arch_register_req_t *new_req = &newrd->in_req.req;
1805 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1811 static const ir_op_ops be_node_op_ops = {