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 */
90 int emit_pop; /**< if set, emit pop bytes, even if pop = 0 */
93 /** The be_IncSP attribute type. */
95 be_node_attr_t node_attr; /**< base attributes of every be node. */
96 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
97 int align; /**< whether stack should be aligned after the
101 /** The be_Frame attribute type. */
103 be_node_attr_t node_attr; /**< base attributes of every be node. */
108 /** The be_Call attribute type. */
110 be_node_attr_t node_attr; /**< base attributes of every be node. */
111 ir_entity *ent; /**< The called entity if this is a static call. */
113 ir_type *call_tp; /**< The call type, copied from the original Call node. */
117 be_node_attr_t node_attr; /**< base attributes of every be node. */
118 ir_entity **in_entities;
119 ir_entity **out_entities;
125 ir_op *op_be_MemPerm;
128 ir_op *op_be_CopyKeep;
134 ir_op *op_be_RegParams;
135 ir_op *op_be_FrameAddr;
136 ir_op *op_be_Barrier;
139 static const ir_op_ops be_node_op_ops;
141 #define N irop_flag_none
142 #define L irop_flag_labeled
143 #define C irop_flag_commutative
144 #define X irop_flag_cfopcode
145 #define I irop_flag_ip_cfopcode
146 #define F irop_flag_fragile
147 #define Y irop_flag_forking
148 #define H irop_flag_highlevel
149 #define c irop_flag_constlike
150 #define K irop_flag_keep
151 #define M irop_flag_uses_memory
153 static int be_reqs_equal(const be_req_t *req1, const be_req_t *req2)
155 if(!reg_reqs_equal(&req1->req, &req2->req))
157 if(req1->flags != req2->flags)
164 * Compare two be node attributes.
166 * @return zero if both attributes are identically
168 static int _node_cmp_attr(const be_node_attr_t *a, const be_node_attr_t *b) {
171 if (ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
174 len = ARR_LEN(a->reg_data);
175 for (i = 0; i < len; ++i) {
176 if (a->reg_data[i].reg != b->reg_data[i].reg ||
177 !be_reqs_equal(&a->reg_data[i].in_req, &b->reg_data[i].in_req) ||
178 !be_reqs_equal(&a->reg_data[i].req, &b->reg_data[i].req))
186 * Compare the node attributes of two be_node's.
188 * @return zero if both nodes have identically attributes
190 static int node_cmp_attr(ir_node *a, ir_node *b) {
191 const be_node_attr_t *a_attr = get_irn_attr_const(a);
192 const be_node_attr_t *b_attr = get_irn_attr_const(b);
194 return _node_cmp_attr(a_attr, b_attr);
198 * Compare the attributes of two be_FrameAddr nodes.
200 * @return zero if both nodes have identically attributes
202 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
203 const be_frame_attr_t *a_attr = get_irn_attr_const(a);
204 const be_frame_attr_t *b_attr = get_irn_attr_const(b);
206 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
209 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
213 * Compare the attributes of two be_Return nodes.
215 * @return zero if both nodes have identically attributes
217 static int Return_cmp_attr(ir_node *a, ir_node *b) {
218 const be_return_attr_t *a_attr = get_irn_attr_const(a);
219 const be_return_attr_t *b_attr = get_irn_attr_const(b);
221 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
223 if (a_attr->pop != b_attr->pop)
225 if (a_attr->emit_pop != b_attr->emit_pop)
228 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
232 * Compare the attributes of two be_IncSP nodes.
234 * @return zero if both nodes have identically attributes
236 static int IncSP_cmp_attr(ir_node *a, ir_node *b) {
237 const be_incsp_attr_t *a_attr = get_irn_attr_const(a);
238 const be_incsp_attr_t *b_attr = get_irn_attr_const(b);
240 if (a_attr->offset != b_attr->offset)
243 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
247 * Compare the attributes of two be_Call nodes.
249 * @return zero if both nodes have identically attributes
251 static int Call_cmp_attr(ir_node *a, ir_node *b) {
252 const be_call_attr_t *a_attr = get_irn_attr_const(a);
253 const be_call_attr_t *b_attr = get_irn_attr_const(b);
255 if (a_attr->ent != b_attr->ent ||
256 a_attr->call_tp != b_attr->call_tp)
259 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
262 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
265 const be_node_attr_t *attr;
268 assert(is_be_node(node));
269 attr = get_irn_attr_const(node);
275 assert(idx < get_irn_arity(node));
277 assert(idx < ARR_LEN(attr->reg_data));
278 rd = &attr->reg_data[idx];
280 return pos < 0 ? &rd->req : &rd->in_req;
283 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
285 be_req_t *bereq = get_be_req(node, pos);
289 void be_node_init(void) {
290 static int inited = 0;
297 /* Acquire all needed opcodes. */
298 op_be_Spill = new_ir_op(beo_Spill, "be_Spill", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
299 op_be_Reload = new_ir_op(beo_Reload, "be_Reload", op_pin_state_pinned, N, oparity_zero, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
300 op_be_Perm = new_ir_op(beo_Perm, "be_Perm", op_pin_state_pinned, N, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
301 op_be_MemPerm = new_ir_op(beo_MemPerm, "be_MemPerm", op_pin_state_pinned, N, oparity_variable, 0, sizeof(be_memperm_attr_t), &be_node_op_ops);
302 op_be_Copy = new_ir_op(beo_Copy, "be_Copy", op_pin_state_floats, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
303 op_be_Keep = new_ir_op(beo_Keep, "be_Keep", op_pin_state_pinned, K, oparity_dynamic, 0, sizeof(be_node_attr_t), &be_node_op_ops);
304 op_be_CopyKeep = new_ir_op(beo_CopyKeep, "be_CopyKeep", op_pin_state_pinned, K, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
305 op_be_Call = new_ir_op(beo_Call, "be_Call", op_pin_state_pinned, F|M, oparity_variable, 0, sizeof(be_call_attr_t), &be_node_op_ops);
306 op_be_Return = new_ir_op(beo_Return, "be_Return", op_pin_state_pinned, X, oparity_dynamic, 0, sizeof(be_return_attr_t), &be_node_op_ops);
307 op_be_AddSP = new_ir_op(beo_AddSP, "be_AddSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
308 op_be_SubSP = new_ir_op(beo_SubSP, "be_SubSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
309 op_be_IncSP = new_ir_op(beo_IncSP, "be_IncSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_incsp_attr_t), &be_node_op_ops);
310 op_be_RegParams = new_ir_op(beo_RegParams, "be_RegParams", op_pin_state_pinned, N, oparity_zero, 0, sizeof(be_node_attr_t), &be_node_op_ops);
311 op_be_FrameAddr = new_ir_op(beo_FrameAddr, "be_FrameAddr", op_pin_state_floats, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
312 op_be_Barrier = new_ir_op(beo_Barrier, "be_Barrier", op_pin_state_pinned, N, oparity_dynamic, 0, sizeof(be_node_attr_t), &be_node_op_ops);
313 op_be_Unwind = new_ir_op(beo_Unwind, "be_Unwind", op_pin_state_pinned, X, oparity_zero, 0, sizeof(be_node_attr_t), &be_node_op_ops);
315 set_op_tag(op_be_Spill, &be_node_tag);
316 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
317 set_op_tag(op_be_Reload, &be_node_tag);
318 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
319 set_op_tag(op_be_Perm, &be_node_tag);
320 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
321 set_op_tag(op_be_MemPerm, &be_node_tag);
322 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
323 set_op_tag(op_be_Copy, &be_node_tag);
324 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
325 set_op_tag(op_be_Keep, &be_node_tag);
326 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
327 set_op_tag(op_be_CopyKeep, &be_node_tag);
328 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
329 set_op_tag(op_be_Call, &be_node_tag);
330 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
331 set_op_tag(op_be_Return, &be_node_tag);
332 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
333 set_op_tag(op_be_AddSP, &be_node_tag);
334 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
335 set_op_tag(op_be_SubSP, &be_node_tag);
336 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
337 set_op_tag(op_be_IncSP, &be_node_tag);
338 op_be_IncSP->ops.node_cmp_attr = IncSP_cmp_attr;
339 set_op_tag(op_be_RegParams, &be_node_tag);
340 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
341 set_op_tag(op_be_FrameAddr, &be_node_tag);
342 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
343 set_op_tag(op_be_Barrier, &be_node_tag);
344 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
345 set_op_tag(op_be_Unwind, &be_node_tag);
346 op_be_Unwind->ops.node_cmp_attr = node_cmp_attr;
350 * Initializes the generic attribute of all be nodes and return ir.
352 static void *init_node_attr(ir_node *node, int max_reg_data)
354 ir_graph *irg = get_irn_irg(node);
355 struct obstack *obst = get_irg_obstack(irg);
356 be_node_attr_t *a = get_irn_attr(node);
358 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
360 if(max_reg_data >= 0) {
361 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
362 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
364 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
370 static void add_register_req(ir_node *node)
372 be_node_attr_t *a = get_irn_attr(node);
373 be_reg_data_t regreq;
374 memset(®req, 0, sizeof(regreq));
375 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
378 int is_be_node(const ir_node *irn)
380 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
384 * Skip Proj nodes and return their Proj numbers.
386 * If *node is a Proj or Proj(Proj) node, skip it.
388 * @param node points to the node to be skipped
390 * @return 0 if *node was no Proj node, its Proj number else.
392 static int redir_proj(const ir_node **node)
394 const ir_node *n = *node;
399 *node = irn = get_Proj_pred(n);
401 assert(get_irn_mode(irn) == mode_T);
402 *node = get_Proj_pred(irn);
404 return get_Proj_proj(n);
410 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
412 const be_node_attr_t *attr;
416 pos = get_Proj_proj(node);
417 node = get_Proj_pred(node);
420 assert(is_be_node(node));
421 attr = get_irn_attr_const(node);
422 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
424 return &attr->reg_data[pos];
428 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
430 be_reg_data_t *r = retrieve_reg_data(irn);
435 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
436 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
444 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
445 a = init_node_attr(res, 2);
449 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
450 be_node_set_reg_class(res, be_pos_Spill_val, cls);
454 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
455 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
462 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
464 init_node_attr(res, 2);
465 be_node_set_reg_class(res, -1, cls);
466 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
467 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
471 ir_node *be_get_Reload_mem(const ir_node *irn)
473 assert(be_is_Reload(irn));
474 return get_irn_n(irn, be_pos_Reload_mem);
477 ir_node *be_get_Reload_frame(const ir_node *irn)
479 assert(be_is_Reload(irn));
480 return get_irn_n(irn, be_pos_Reload_frame);
483 ir_node *be_get_Spill_val(const ir_node *irn)
485 assert(be_is_Spill(irn));
486 return get_irn_n(irn, be_pos_Spill_val);
489 ir_node *be_get_Spill_frame(const ir_node *irn)
491 assert(be_is_Spill(irn));
492 return get_irn_n(irn, be_pos_Spill_frame);
495 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
498 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
499 init_node_attr(irn, n);
500 for(i = 0; i < n; ++i) {
501 be_node_set_reg_class(irn, i, cls);
502 be_node_set_reg_class(irn, OUT_POS(i), cls);
508 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
510 ir_graph *irg = get_irn_irg(perm);
511 int arity = get_irn_arity(perm);
512 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
513 be_node_attr_t *attr = get_irn_attr(perm);
514 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
518 assert(be_is_Perm(perm));
519 assert(new_size <= arity);
521 /* save the old register data */
522 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
524 /* compose the new in array and set the new register data directly in place */
525 for (i = 0; i < new_size; ++i) {
527 new_in[i] = get_irn_n(perm, idx);
528 attr->reg_data[i] = old_data[idx];
531 set_irn_in(perm, new_size, new_in);
534 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
537 ir_node *frame = get_irg_frame(irg);
538 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
540 const arch_register_t *sp = arch_env->isa->sp;
541 be_memperm_attr_t *attr;
544 real_in = alloca((n+1) * sizeof(real_in[0]));
546 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
548 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
550 init_node_attr(irn, n + 1);
551 be_node_set_reg_class(irn, 0, sp->reg_class);
552 for (i = 0; i < n; ++i) {
553 be_node_set_reg_class(irn, i + 1, cls_frame);
554 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
557 attr = get_irn_attr(irn);
559 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
560 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
561 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
562 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
568 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
572 arch_register_req_t *req;
575 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
576 init_node_attr(res, 1);
577 be_node_set_reg_class(res, 0, cls);
578 be_node_set_reg_class(res, OUT_POS(0), cls);
580 req = get_req(res, OUT_POS(0));
582 req->type = arch_register_req_type_should_be_same;
583 req->other_same = 1U << 0;
588 ir_node *be_get_Copy_op(const ir_node *cpy) {
589 return get_irn_n(cpy, be_pos_Copy_op);
592 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
593 set_irn_n(cpy, be_pos_Copy_op, op);
596 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
601 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
602 init_node_attr(res, -1);
604 for(i = 0; i < n; ++i) {
605 add_irn_n(res, in[i]);
606 add_register_req(res);
607 be_node_set_reg_class(res, i, cls);
614 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
618 assert(be_is_Keep(keep));
619 n = add_irn_n(keep, node);
620 add_register_req(keep);
621 be_node_set_reg_class(keep, n, cls);
624 /* creates a be_Call */
625 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
626 int n_outs, int n, ir_node *in[], ir_type *call_tp)
629 int real_n = be_pos_Call_first_arg + n;
633 NEW_ARR_A(ir_node *, real_in, real_n);
634 real_in[be_pos_Call_mem] = mem;
635 real_in[be_pos_Call_sp] = sp;
636 real_in[be_pos_Call_ptr] = ptr;
637 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
639 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
640 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
642 a->call_tp = call_tp;
647 /* Gets the call entity or NULL if this is no static call. */
648 ir_entity *be_Call_get_entity(const ir_node *call) {
649 const be_call_attr_t *a = get_irn_attr_const(call);
650 assert(be_is_Call(call));
654 /* Sets the call entity. */
655 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
656 be_call_attr_t *a = get_irn_attr(call);
657 assert(be_is_Call(call));
661 /* Gets the call type. */
662 ir_type *be_Call_get_type(ir_node *call) {
663 const be_call_attr_t *a = get_irn_attr_const(call);
664 assert(be_is_Call(call));
668 /* Sets the call type. */
669 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
670 be_call_attr_t *a = get_irn_attr(call);
671 assert(be_is_Call(call));
672 a->call_tp = call_tp;
675 void be_Call_set_pop(ir_node *call, unsigned pop) {
676 be_call_attr_t *a = get_irn_attr(call);
680 unsigned be_Call_get_pop(const ir_node *call) {
681 const be_call_attr_t *a = get_irn_attr_const(call);
685 /* Construct a new be_Return. */
686 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
687 unsigned pop, int n, ir_node *in[])
693 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
694 init_node_attr(res, -1);
695 for(i = 0; i < n; ++i) {
696 add_irn_n(res, in[i]);
697 add_register_req(res);
700 a = get_irn_attr(res);
701 a->num_ret_vals = n_res;
708 /* Returns the number of real returns values */
709 int be_Return_get_n_rets(const ir_node *ret) {
710 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
711 return a->num_ret_vals;
714 /* return the number of bytes that should be popped from stack when executing the Return. */
715 unsigned be_Return_get_pop(const ir_node *ret) {
716 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
720 /* return non-zero, if number of popped bytes must be always emitted */
721 int be_Return_get_emit_pop(const ir_node *ret) {
722 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
726 /* return non-zero, if number of popped bytes must be always emitted */
727 void be_Return_set_emit_pop(ir_node *ret, int emit_pop) {
728 be_return_attr_t *a = get_irn_generic_attr(ret);
729 a->emit_pop = emit_pop;
732 int be_Return_append_node(ir_node *ret, ir_node *node) {
735 pos = add_irn_n(ret, node);
736 add_register_req(ret);
741 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl,
742 ir_node *old_sp, int offset, int align)
749 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode,
750 sizeof(in) / sizeof(in[0]), in);
751 a = init_node_attr(irn, 1);
755 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
757 /* Set output constraint to stack register. */
758 be_node_set_reg_class(irn, 0, sp->reg_class);
759 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
760 be_node_set_irn_reg(NULL, irn, sp);
765 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
769 ir_node *in[be_pos_AddSP_last];
770 const arch_register_class_t *class;
772 in[be_pos_AddSP_old_sp] = old_sp;
773 in[be_pos_AddSP_size] = sz;
775 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
776 a = init_node_attr(irn, be_pos_AddSP_last);
778 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
779 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
781 /* Set output constraint to stack register. */
782 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
783 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
784 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
785 a->reg_data[pn_be_AddSP_sp].reg = sp;
787 class = arch_register_get_class(sp);
788 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
793 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
797 ir_node *in[be_pos_SubSP_last];
799 in[be_pos_SubSP_old_sp] = old_sp;
800 in[be_pos_SubSP_size] = sz;
802 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
803 a = init_node_attr(irn, be_pos_SubSP_last);
805 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
806 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
808 /* Set output constraint to stack register. */
809 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
810 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
811 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
812 a->reg_data[pn_be_SubSP_sp].reg = sp;
817 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
822 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
823 init_node_attr(res, -1);
824 for(i = 0; i < n_outs; ++i)
825 add_register_req(res);
830 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
831 const arch_env_t *arch_env,
832 const arch_register_t *reg)
834 ir_graph *irg = get_irn_irg(regparams);
835 ir_node *block = get_nodes_block(regparams);
836 be_node_attr_t *attr = get_irn_attr(regparams);
837 const arch_register_class_t *cls = arch_register_get_class(reg);
838 ir_mode *mode = arch_register_class_mode(cls);
839 int n = ARR_LEN(attr->reg_data);
842 assert(be_is_RegParams(regparams));
843 proj = new_r_Proj(irg, block, regparams, mode, n);
844 add_register_req(regparams);
845 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
846 arch_set_irn_register(arch_env, proj, reg);
848 /* TODO decide, whether we need to set ignore/modify sp flags here? */
853 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
860 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
861 a = init_node_attr(irn, 1);
864 be_node_set_reg_class(irn, 0, cls_frame);
865 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
867 return optimize_node(irn);
870 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
871 assert(be_is_FrameAddr(node));
872 return get_irn_n(node, be_pos_FrameAddr_ptr);
875 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
877 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
881 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)
884 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
887 memcpy(&in[1], in_keep, n * sizeof(in[0]));
888 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
889 init_node_attr(irn, n + 1);
890 be_node_set_reg_class(irn, OUT_POS(0), cls);
891 be_node_set_reg_class(irn, 0, cls);
896 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)
898 return be_new_CopyKeep(cls, irg, bl, src, 1, &keep, mode);
901 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
902 return get_irn_n(cpy, be_pos_CopyKeep_op);
905 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
906 set_irn_n(cpy, be_pos_CopyKeep_op, op);
909 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
914 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
915 init_node_attr(res, -1);
916 for(i = 0; i < n; ++i) {
917 add_irn_n(res, in[i]);
918 add_register_req(res);
924 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
926 ir_graph *irg = get_irn_irg(barrier);
927 ir_node *block = get_nodes_block(barrier);
928 ir_mode *mode = get_irn_mode(node);
929 int n = add_irn_n(barrier, node);
931 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
932 add_register_req(barrier);
937 /* Construct a new be_Unwind. */
938 ir_node *be_new_Unwind(dbg_info *dbg, ir_graph *irg, ir_node *block,
939 ir_node *mem, ir_node *sp)
944 in[be_pos_Unwind_mem] = mem;
945 in[be_pos_Unwind_sp] = sp;
946 res = new_ir_node(dbg, irg, block, op_be_Unwind, mode_X, 2, in);
947 init_node_attr(res, -1);
952 int be_has_frame_entity(const ir_node *irn)
954 switch (get_irn_opcode(irn)) {
964 ir_entity *be_get_frame_entity(const ir_node *irn)
966 if (be_has_frame_entity(irn)) {
967 const be_frame_attr_t *a = get_irn_attr_const(irn);
973 int be_get_frame_offset(const ir_node *irn)
975 assert(is_be_node(irn));
976 if (be_has_frame_entity(irn)) {
977 const be_frame_attr_t *a = get_irn_attr_const(irn);
983 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
985 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
987 assert(be_is_MemPerm(irn));
988 assert(n < be_get_MemPerm_entity_arity(irn));
990 attr->in_entities[n] = ent;
993 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
995 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
997 assert(be_is_MemPerm(irn));
998 assert(n < be_get_MemPerm_entity_arity(irn));
1000 return attr->in_entities[n];
1003 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
1005 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
1007 assert(be_is_MemPerm(irn));
1008 assert(n < be_get_MemPerm_entity_arity(irn));
1010 attr->out_entities[n] = ent;
1013 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
1015 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
1017 assert(be_is_MemPerm(irn));
1018 assert(n < be_get_MemPerm_entity_arity(irn));
1020 return attr->out_entities[n];
1023 int be_get_MemPerm_entity_arity(const ir_node *irn)
1025 return get_irn_arity(irn) - 1;
1028 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
1030 arch_register_req_t *req = get_req(node, pos);
1031 const arch_register_class_t *cls = arch_register_get_class(reg);
1032 ir_graph *irg = get_irn_irg(node);
1033 struct obstack *obst = get_irg_obstack(irg);
1034 unsigned *limited_bitset;
1036 assert(req->cls == NULL || req->cls == cls);
1037 assert(! (req->type & arch_register_req_type_limited));
1038 assert(req->limited == NULL);
1040 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1041 rbitset_set(limited_bitset, arch_register_get_index(reg));
1044 req->type |= arch_register_req_type_limited;
1045 req->limited = limited_bitset;
1048 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1050 ir_graph *irg = get_irn_irg(node);
1051 struct obstack *obst = get_irg_obstack(irg);
1052 arch_register_req_t *r = get_req(node, pos);
1054 assert(arch_register_req_is(req, limited));
1055 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1056 memcpy(r, req, sizeof(r[0]));
1057 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1060 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1062 be_req_t *bereq = get_be_req(irn, pos);
1063 bereq->flags = flags;
1066 void be_node_add_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1068 be_req_t *bereq = get_be_req(irn, pos);
1069 bereq->flags |= flags;
1072 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1074 arch_register_req_t *req = get_req(irn, pos);
1079 req->type = arch_register_req_type_none;
1080 } else if (req->type == arch_register_req_type_none) {
1081 req->type = arch_register_req_type_normal;
1085 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1087 arch_register_req_t *req = get_req(irn, pos);
1091 ir_node *be_get_IncSP_pred(ir_node *irn) {
1092 assert(be_is_IncSP(irn));
1093 return get_irn_n(irn, 0);
1096 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1097 assert(be_is_IncSP(incsp));
1098 set_irn_n(incsp, 0, pred);
1101 void be_set_IncSP_offset(ir_node *irn, int offset)
1103 be_incsp_attr_t *a = get_irn_attr(irn);
1104 assert(be_is_IncSP(irn));
1108 int be_get_IncSP_offset(const ir_node *irn)
1110 const be_incsp_attr_t *a = get_irn_attr_const(irn);
1111 assert(be_is_IncSP(irn));
1115 int be_get_IncSP_align(const ir_node *irn)
1117 const be_incsp_attr_t *a = get_irn_attr_const(irn);
1118 assert(be_is_IncSP(irn));
1122 ir_node *be_spill(const arch_env_t *arch_env, ir_node *block, ir_node *irn)
1124 ir_graph *irg = get_irn_irg(block);
1125 ir_node *frame = get_irg_frame(irg);
1126 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1127 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1130 spill = be_new_Spill(cls, cls_frame, irg, block, frame, irn);
1134 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)
1137 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1138 ir_graph *irg = get_irn_irg(bl);
1139 ir_node *frame = get_irg_frame(irg);
1140 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1142 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1144 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1146 if (is_Block(insert)) {
1147 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1148 sched_add_after(insert, reload);
1150 sched_add_before(insert, reload);
1158 | _ \ ___ __ _ | _ \ ___ __ _ ___
1159 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1160 | _ < __/ (_| | | _ < __/ (_| \__ \
1161 |_| \_\___|\__, | |_| \_\___|\__, |___/
1168 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1170 const be_node_attr_t *a = get_irn_attr_const(irn);
1172 if(out_pos >= ARR_LEN(a->reg_data)) {
1173 return arch_no_register_req;
1176 return &a->reg_data[out_pos].req.req;
1180 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1182 const be_node_attr_t *a = get_irn_attr_const(irn);
1184 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1185 return arch_no_register_req;
1187 return &a->reg_data[pos].in_req.req;
1190 static const arch_register_req_t *
1191 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1197 if (get_irn_mode(irn) == mode_T)
1198 return arch_no_register_req;
1200 out_pos = redir_proj((const ir_node **)&irn);
1201 assert(is_be_node(irn));
1202 return get_out_reg_req(irn, out_pos);
1203 } else if (is_be_node(irn)) {
1205 * For spills and reloads, we return "none" as requirement for frame
1206 * pointer, so every input is ok. Some backends need this (e.g. STA).
1208 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1209 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1210 return arch_no_register_req;
1212 return get_in_reg_req(irn, pos);
1215 return arch_no_register_req;
1218 const arch_register_t *
1219 be_node_get_irn_reg(const void *self, const ir_node *irn)
1224 if (get_irn_mode(irn) == mode_T)
1226 r = retrieve_reg_data(irn);
1230 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1235 switch (get_irn_opcode(irn)) {
1236 #define XXX(a,b) case a: return b
1237 XXX(beo_Spill, arch_irn_class_spill);
1238 XXX(beo_Reload, arch_irn_class_reload);
1239 XXX(beo_Perm, arch_irn_class_perm);
1240 XXX(beo_Copy, arch_irn_class_copy);
1241 XXX(beo_Return, arch_irn_class_branch);
1244 irn = get_Proj_pred(irn);
1246 assert(get_irn_mode(irn) == mode_T);
1247 irn = get_Proj_pred(irn);
1252 return arch_irn_class_normal;
1258 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1265 pos = OUT_POS(get_Proj_proj(node));
1266 node = skip_Proj_const(node);
1269 bereq = get_be_req(node, pos);
1271 return bereq->flags;
1274 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1277 return be_get_frame_entity(irn);
1280 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1285 assert(be_has_frame_entity(irn));
1287 a = get_irn_attr(irn);
1291 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1294 if(be_has_frame_entity(irn)) {
1295 be_frame_attr_t *a = get_irn_attr(irn);
1300 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1303 if(be_is_IncSP(irn))
1304 return be_get_IncSP_offset(irn);
1306 return -(int)be_Call_get_pop(irn);
1312 ___ ____ _ _ _ _ _ _
1313 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1314 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1315 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1316 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1320 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1321 be_node_get_irn_reg_req,
1322 be_node_set_irn_reg,
1323 be_node_get_irn_reg,
1326 be_node_get_frame_entity,
1327 be_node_set_frame_entity,
1328 be_node_set_frame_offset,
1329 be_node_get_sp_bias,
1330 NULL, /* get_inverse */
1331 NULL, /* get_op_estimated_cost */
1332 NULL, /* possible_memory_operand */
1333 NULL, /* perform_memory_operand */
1336 static const arch_irn_ops_t be_node_irn_ops = {
1340 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1343 irn = get_Proj_pred(irn);
1345 assert(get_irn_mode(irn) == mode_T);
1346 irn = get_Proj_pred(irn);
1350 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1353 const arch_irn_handler_t be_node_irn_handler = {
1358 ____ _ _ ___ ____ _ _ _ _ _ _
1359 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1360 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1361 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1362 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1367 const arch_register_t *reg;
1368 arch_register_req_t req;
1369 arch_irn_flags_t flags;
1373 arch_irn_handler_t irn_handler;
1374 arch_irn_ops_t irn_ops;
1375 const arch_env_t *arch_env;
1379 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1380 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1383 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1386 const phi_handler_t *h;
1387 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1390 h = get_phi_handler_from_handler(handler);
1395 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1397 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1399 ir_graph *irg = get_irn_irg(phi);
1400 struct obstack *obst = get_irg_obstack(irg);
1401 attr = obstack_alloc(obst, sizeof(attr[0]));
1402 memset(attr, 0, sizeof(attr[0]));
1403 pmap_insert(handler->phi_attrs, phi, attr);
1410 * Get register class of a Phi.
1413 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1417 int n = get_irn_arity(phi);
1421 if(*visited && pset_find_ptr(*visited, phi))
1424 for(i = 0; i < n; ++i) {
1425 op = get_irn_n(phi, i);
1426 /* Matze: don't we unnecessary constraint our phis with this?
1427 * we only need to take the regclass IMO*/
1429 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1433 * The operands of that Phi were all Phis themselves.
1434 * We have to start a DFS for a non-Phi argument now.
1437 *visited = pset_new_ptr(16);
1439 pset_insert_ptr(*visited, phi);
1441 for(i = 0; i < n; ++i) {
1442 const arch_register_req_t *req;
1443 op = get_irn_n(phi, i);
1444 req = get_Phi_reg_req_recursive(h, op, visited);
1453 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1454 const ir_node *irn, int pos)
1456 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1461 if(!mode_is_datab(get_irn_mode(irn)))
1462 return arch_no_register_req;
1464 attr = get_Phi_attr(phi_handler, irn);
1466 if(attr->req.type == arch_register_req_type_none) {
1467 pset *visited = NULL;
1468 const arch_register_req_t *req;
1469 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1471 memcpy(&attr->req, req, sizeof(req[0]));
1472 assert(attr->req.cls != NULL);
1473 attr->req.type = arch_register_req_type_normal;
1482 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1483 const arch_register_req_t *req)
1485 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1486 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1489 assert(mode_is_datab(get_irn_mode(node)));
1491 attr = get_Phi_attr(handler, node);
1492 memcpy(&attr->req, req, sizeof(req[0]));
1495 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1496 arch_irn_flags_t flags)
1498 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1499 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1502 assert(mode_is_datab(get_irn_mode(node)));
1504 attr = get_Phi_attr(handler, node);
1505 attr->flags = flags;
1509 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1511 phi_handler_t *h = get_phi_handler_from_ops(self);
1512 phi_attr_t *attr = get_Phi_attr(h, irn);
1517 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1519 phi_handler_t *h = get_phi_handler_from_ops(self);
1520 phi_attr_t *attr = get_Phi_attr(h, irn);
1525 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1529 return arch_irn_class_normal;
1533 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1535 phi_handler_t *h = get_phi_handler_from_ops(self);
1536 phi_attr_t *attr = get_Phi_attr(h, irn);
1542 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1550 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1559 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1568 int phi_get_sp_bias(const void* self, const ir_node *irn)
1576 const arch_irn_ops_if_t phi_irn_ops = {
1577 phi_get_irn_reg_req,
1582 phi_get_frame_entity,
1583 phi_set_frame_entity,
1584 phi_set_frame_offset,
1586 NULL, /* get_inverse */
1587 NULL, /* get_op_estimated_cost */
1588 NULL, /* possible_memory_operand */
1589 NULL, /* perform_memory_operand */
1592 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1594 phi_handler_t *h = xmalloc(sizeof(h[0]));
1595 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1596 h->irn_ops.impl = &phi_irn_ops;
1597 h->arch_env = arch_env;
1598 h->phi_attrs = pmap_create();
1599 return (arch_irn_handler_t *) h;
1602 void be_phi_handler_free(arch_irn_handler_t *handler)
1604 phi_handler_t *h = get_phi_handler_from_handler(handler);
1605 pmap_destroy(h->phi_attrs);
1606 h->phi_attrs = NULL;
1610 void be_phi_handler_reset(arch_irn_handler_t *handler)
1612 phi_handler_t *h = get_phi_handler_from_handler(handler);
1614 pmap_destroy(h->phi_attrs);
1615 h->phi_attrs = pmap_create();
1620 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1621 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1622 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1623 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1628 * Dumps a register requirement to a file.
1630 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1631 const ir_node *node)
1633 int did_something = 0;
1635 const char *prefix = buf;
1637 snprintf(buf, sizeof(buf), "#%d ", idx);
1638 buf[sizeof(buf) - 1] = '\0';
1643 arch_register_req_format(tmp, sizeof(tmp), req, node);
1644 fprintf(f, "%s", tmp);
1653 * Dumps node register requirements to a file.
1655 static void dump_node_reqs(FILE *f, ir_node *node)
1658 be_node_attr_t *a = get_irn_attr(node);
1659 int len = ARR_LEN(a->reg_data);
1661 fprintf(f, "registers: \n");
1662 for(i = 0; i < len; ++i) {
1663 be_reg_data_t *rd = &a->reg_data[i];
1665 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1668 fprintf(f, "in requirements:\n");
1669 for(i = 0; i < len; ++i) {
1670 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1673 fprintf(f, "\nout requirements:\n");
1674 for(i = 0; i < len; ++i) {
1675 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1680 * ir_op-Operation: dump a be node to file
1682 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1684 be_node_attr_t *at = get_irn_attr(irn);
1686 assert(is_be_node(irn));
1689 case dump_node_opcode_txt:
1690 fprintf(f, get_op_name(get_irn_op(irn)));
1692 case dump_node_mode_txt:
1693 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1694 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1697 case dump_node_nodeattr_txt:
1698 if(be_is_Call(irn)) {
1699 be_call_attr_t *a = (be_call_attr_t *) at;
1701 fprintf(f, " [%s] ", get_entity_name(a->ent));
1703 if(be_is_IncSP(irn)) {
1704 const be_incsp_attr_t *attr = get_irn_generic_attr_const(irn);
1705 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1706 fprintf(f, " [Setup Stackframe] ");
1707 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1708 fprintf(f, " [Destroy Stackframe] ");
1710 fprintf(f, " [%d] ", attr->offset);
1714 case dump_node_info_txt:
1715 dump_node_reqs(f, irn);
1717 if(be_has_frame_entity(irn)) {
1718 be_frame_attr_t *a = (be_frame_attr_t *) at;
1720 unsigned size = get_type_size_bytes(get_entity_type(a->ent));
1721 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
1722 a->ent, a->offset, a->offset, size, size);
1727 switch (get_irn_opcode(irn)) {
1730 be_incsp_attr_t *a = (be_incsp_attr_t *) at;
1731 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1732 fprintf(f, "offset: FRAME_SIZE\n");
1733 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1734 fprintf(f, "offset: -FRAME SIZE\n");
1736 fprintf(f, "offset: %u\n", a->offset);
1741 be_call_attr_t *a = (be_call_attr_t *) at;
1744 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1750 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1751 ir_entity *in, *out;
1752 in = be_get_MemPerm_in_entity(irn, i);
1753 out = be_get_MemPerm_out_entity(irn, i);
1755 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1758 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1774 * Copies the backend specific attributes from old node to new node.
1776 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1778 const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
1779 be_node_attr_t *new_attr = get_irn_attr(new_node);
1780 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1783 assert(is_be_node(old_node));
1784 assert(is_be_node(new_node));
1786 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1787 new_attr->reg_data = NULL;
1789 if(old_attr->reg_data != NULL)
1790 len = ARR_LEN(old_attr->reg_data);
1794 if(get_irn_op(old_node)->opar == oparity_dynamic
1795 || be_is_RegParams(old_node)) {
1796 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1798 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1802 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1803 for(i = 0; i < len; ++i) {
1804 const be_reg_data_t *rd = &old_attr->reg_data[i];
1805 be_reg_data_t *newrd = &new_attr->reg_data[i];
1806 if(arch_register_req_is(&rd->req.req, limited)) {
1807 const arch_register_req_t *req = &rd->req.req;
1808 arch_register_req_t *new_req = &newrd->req.req;
1810 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1812 if(arch_register_req_is(&rd->in_req.req, limited)) {
1813 const arch_register_req_t *req = &rd->in_req.req;
1814 arch_register_req_t *new_req = &newrd->in_req.req;
1816 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1822 static const ir_op_ops be_node_op_ops = {