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');
69 /** The current phi handler */
70 static const phi_handler_t *curr_phi_handler;
73 arch_register_req_t req;
74 arch_irn_flags_t flags;
78 const arch_register_t *reg;
83 /** The generic be nodes attribute type. */
85 be_reg_data_t *reg_data;
88 /** The be_Return nodes attribute type. */
90 be_node_attr_t node_attr; /**< base attributes of every be node. */
91 int num_ret_vals; /**< number of return values */
92 unsigned pop; /**< number of bytes that should be popped */
93 int emit_pop; /**< if set, emit pop bytes, even if pop = 0 */
96 /** The be_IncSP attribute type. */
98 be_node_attr_t node_attr; /**< base attributes of every be node. */
99 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
100 int align; /**< whether stack should be aligned after the
104 /** The be_Frame attribute type. */
106 be_node_attr_t node_attr; /**< base attributes of every be node. */
111 /** The be_Call attribute type. */
113 be_node_attr_t node_attr; /**< base attributes of every be node. */
114 ir_entity *ent; /**< The called entity if this is a static call. */
116 ir_type *call_tp; /**< The call type, copied from the original Call node. */
120 be_node_attr_t node_attr; /**< base attributes of every be node. */
121 ir_entity **in_entities;
122 ir_entity **out_entities;
128 ir_op *op_be_MemPerm;
131 ir_op *op_be_CopyKeep;
137 ir_op *op_be_RegParams;
138 ir_op *op_be_FrameAddr;
139 ir_op *op_be_Barrier;
142 static const ir_op_ops be_node_op_ops;
144 #define N irop_flag_none
145 #define L irop_flag_labeled
146 #define C irop_flag_commutative
147 #define X irop_flag_cfopcode
148 #define I irop_flag_ip_cfopcode
149 #define F irop_flag_fragile
150 #define Y irop_flag_forking
151 #define H irop_flag_highlevel
152 #define c irop_flag_constlike
153 #define K irop_flag_keep
154 #define M irop_flag_uses_memory
156 static int be_reqs_equal(const be_req_t *req1, const be_req_t *req2)
158 if(!reg_reqs_equal(&req1->req, &req2->req))
160 if(req1->flags != req2->flags)
167 * Compare two be node attributes.
169 * @return zero if both attributes are identically
171 static int _node_cmp_attr(const be_node_attr_t *a, const be_node_attr_t *b) {
174 if (ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
177 len = ARR_LEN(a->reg_data);
178 for (i = 0; i < len; ++i) {
179 if (a->reg_data[i].reg != b->reg_data[i].reg ||
180 !be_reqs_equal(&a->reg_data[i].in_req, &b->reg_data[i].in_req) ||
181 !be_reqs_equal(&a->reg_data[i].req, &b->reg_data[i].req))
189 * Compare the node attributes of two be_node's.
191 * @return zero if both nodes have identically attributes
193 static int node_cmp_attr(ir_node *a, ir_node *b) {
194 const be_node_attr_t *a_attr = get_irn_attr_const(a);
195 const be_node_attr_t *b_attr = get_irn_attr_const(b);
197 return _node_cmp_attr(a_attr, b_attr);
201 * Compare the attributes of two be_FrameAddr nodes.
203 * @return zero if both nodes have identically attributes
205 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
206 const be_frame_attr_t *a_attr = get_irn_attr_const(a);
207 const be_frame_attr_t *b_attr = get_irn_attr_const(b);
209 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
212 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
216 * Compare the attributes of two be_Return nodes.
218 * @return zero if both nodes have identically attributes
220 static int Return_cmp_attr(ir_node *a, ir_node *b) {
221 const be_return_attr_t *a_attr = get_irn_attr_const(a);
222 const be_return_attr_t *b_attr = get_irn_attr_const(b);
224 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
226 if (a_attr->pop != b_attr->pop)
228 if (a_attr->emit_pop != b_attr->emit_pop)
231 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
235 * Compare the attributes of two be_IncSP nodes.
237 * @return zero if both nodes have identically attributes
239 static int IncSP_cmp_attr(ir_node *a, ir_node *b) {
240 const be_incsp_attr_t *a_attr = get_irn_attr_const(a);
241 const be_incsp_attr_t *b_attr = get_irn_attr_const(b);
243 if (a_attr->offset != b_attr->offset)
246 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
250 * Compare the attributes of two be_Call nodes.
252 * @return zero if both nodes have identically attributes
254 static int Call_cmp_attr(ir_node *a, ir_node *b) {
255 const be_call_attr_t *a_attr = get_irn_attr_const(a);
256 const be_call_attr_t *b_attr = get_irn_attr_const(b);
258 if (a_attr->ent != b_attr->ent ||
259 a_attr->call_tp != b_attr->call_tp)
262 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
265 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
268 const be_node_attr_t *attr;
271 assert(is_be_node(node));
272 attr = get_irn_attr_const(node);
278 assert(idx < get_irn_arity(node));
280 assert(idx < ARR_LEN(attr->reg_data));
281 rd = &attr->reg_data[idx];
283 return pos < 0 ? &rd->req : &rd->in_req;
286 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
288 be_req_t *bereq = get_be_req(node, pos);
292 void be_node_init(void) {
293 static int inited = 0;
300 /* Acquire all needed opcodes. */
301 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);
302 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);
303 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);
304 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);
305 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);
306 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);
307 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);
308 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);
309 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);
310 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);
311 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);
312 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);
313 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);
314 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);
315 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);
316 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);
318 set_op_tag(op_be_Spill, &be_node_tag);
319 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
320 set_op_tag(op_be_Reload, &be_node_tag);
321 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
322 set_op_tag(op_be_Perm, &be_node_tag);
323 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
324 set_op_tag(op_be_MemPerm, &be_node_tag);
325 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
326 set_op_tag(op_be_Copy, &be_node_tag);
327 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
328 set_op_tag(op_be_Keep, &be_node_tag);
329 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
330 set_op_tag(op_be_CopyKeep, &be_node_tag);
331 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
332 set_op_tag(op_be_Call, &be_node_tag);
333 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
334 set_op_tag(op_be_Return, &be_node_tag);
335 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
336 set_op_tag(op_be_AddSP, &be_node_tag);
337 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
338 set_op_tag(op_be_SubSP, &be_node_tag);
339 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
340 set_op_tag(op_be_IncSP, &be_node_tag);
341 op_be_IncSP->ops.node_cmp_attr = IncSP_cmp_attr;
342 set_op_tag(op_be_RegParams, &be_node_tag);
343 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
344 set_op_tag(op_be_FrameAddr, &be_node_tag);
345 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
346 set_op_tag(op_be_Barrier, &be_node_tag);
347 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
348 set_op_tag(op_be_Unwind, &be_node_tag);
349 op_be_Unwind->ops.node_cmp_attr = node_cmp_attr;
353 * Initializes the generic attribute of all be nodes and return ir.
355 static void *init_node_attr(ir_node *node, int max_reg_data)
357 ir_graph *irg = get_irn_irg(node);
358 struct obstack *obst = get_irg_obstack(irg);
359 be_node_attr_t *a = get_irn_attr(node);
361 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
363 if(max_reg_data >= 0) {
364 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
365 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
367 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
373 static void add_register_req(ir_node *node)
375 be_node_attr_t *a = get_irn_attr(node);
376 be_reg_data_t regreq;
377 memset(®req, 0, sizeof(regreq));
378 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
381 int is_be_node(const ir_node *irn)
383 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
387 * Skip Proj nodes and return their Proj numbers.
389 * If *node is a Proj or Proj(Proj) node, skip it.
391 * @param node points to the node to be skipped
393 * @return 0 if *node was no Proj node, its Proj number else.
395 static int redir_proj(const ir_node **node)
397 const ir_node *n = *node;
402 *node = irn = get_Proj_pred(n);
404 assert(get_irn_mode(irn) == mode_T);
405 *node = get_Proj_pred(irn);
407 return get_Proj_proj(n);
413 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
415 const be_node_attr_t *attr;
419 pos = get_Proj_proj(node);
420 node = get_Proj_pred(node);
423 assert(is_be_node(node));
424 attr = get_irn_attr_const(node);
425 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
427 return &attr->reg_data[pos];
431 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
433 be_reg_data_t *r = retrieve_reg_data(irn);
438 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
439 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
447 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
448 a = init_node_attr(res, 2);
452 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
453 be_node_set_reg_class(res, be_pos_Spill_val, cls);
457 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
458 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
465 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
467 init_node_attr(res, 2);
468 be_node_set_reg_class(res, -1, cls);
469 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
470 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
474 ir_node *be_get_Reload_mem(const ir_node *irn)
476 assert(be_is_Reload(irn));
477 return get_irn_n(irn, be_pos_Reload_mem);
480 ir_node *be_get_Reload_frame(const ir_node *irn)
482 assert(be_is_Reload(irn));
483 return get_irn_n(irn, be_pos_Reload_frame);
486 ir_node *be_get_Spill_val(const ir_node *irn)
488 assert(be_is_Spill(irn));
489 return get_irn_n(irn, be_pos_Spill_val);
492 ir_node *be_get_Spill_frame(const ir_node *irn)
494 assert(be_is_Spill(irn));
495 return get_irn_n(irn, be_pos_Spill_frame);
498 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
501 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
502 init_node_attr(irn, n);
503 for(i = 0; i < n; ++i) {
504 be_node_set_reg_class(irn, i, cls);
505 be_node_set_reg_class(irn, OUT_POS(i), cls);
511 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
513 ir_graph *irg = get_irn_irg(perm);
514 int arity = get_irn_arity(perm);
515 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
516 be_node_attr_t *attr = get_irn_attr(perm);
517 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
521 assert(be_is_Perm(perm));
522 assert(new_size <= arity);
524 /* save the old register data */
525 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
527 /* compose the new in array and set the new register data directly in place */
528 for (i = 0; i < new_size; ++i) {
530 new_in[i] = get_irn_n(perm, idx);
531 attr->reg_data[i] = old_data[idx];
534 set_irn_in(perm, new_size, new_in);
537 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
540 ir_node *frame = get_irg_frame(irg);
541 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
543 const arch_register_t *sp = arch_env->isa->sp;
544 be_memperm_attr_t *attr;
547 real_in = alloca((n+1) * sizeof(real_in[0]));
549 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
551 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
553 init_node_attr(irn, n + 1);
554 be_node_set_reg_class(irn, 0, sp->reg_class);
555 for (i = 0; i < n; ++i) {
556 be_node_set_reg_class(irn, i + 1, cls_frame);
557 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
560 attr = get_irn_attr(irn);
562 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
563 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
564 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
565 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
571 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
575 arch_register_req_t *req;
578 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
579 init_node_attr(res, 1);
580 be_node_set_reg_class(res, 0, cls);
581 be_node_set_reg_class(res, OUT_POS(0), cls);
583 req = get_req(res, OUT_POS(0));
585 req->type = arch_register_req_type_should_be_same;
586 req->other_same = 1U << 0;
591 ir_node *be_get_Copy_op(const ir_node *cpy) {
592 return get_irn_n(cpy, be_pos_Copy_op);
595 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
596 set_irn_n(cpy, be_pos_Copy_op, op);
599 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
604 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
605 init_node_attr(res, -1);
607 for(i = 0; i < n; ++i) {
608 add_irn_n(res, in[i]);
609 add_register_req(res);
610 be_node_set_reg_class(res, i, cls);
617 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
621 assert(be_is_Keep(keep));
622 n = add_irn_n(keep, node);
623 add_register_req(keep);
624 be_node_set_reg_class(keep, n, cls);
627 /* creates a be_Call */
628 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
629 int n_outs, int n, ir_node *in[], ir_type *call_tp)
632 int real_n = be_pos_Call_first_arg + n;
636 NEW_ARR_A(ir_node *, real_in, real_n);
637 real_in[be_pos_Call_mem] = mem;
638 real_in[be_pos_Call_sp] = sp;
639 real_in[be_pos_Call_ptr] = ptr;
640 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
642 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
643 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
645 a->call_tp = call_tp;
650 /* Gets the call entity or NULL if this is no static call. */
651 ir_entity *be_Call_get_entity(const ir_node *call) {
652 const be_call_attr_t *a = get_irn_attr_const(call);
653 assert(be_is_Call(call));
657 /* Sets the call entity. */
658 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
659 be_call_attr_t *a = get_irn_attr(call);
660 assert(be_is_Call(call));
664 /* Gets the call type. */
665 ir_type *be_Call_get_type(ir_node *call) {
666 const be_call_attr_t *a = get_irn_attr_const(call);
667 assert(be_is_Call(call));
671 /* Sets the call type. */
672 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
673 be_call_attr_t *a = get_irn_attr(call);
674 assert(be_is_Call(call));
675 a->call_tp = call_tp;
678 void be_Call_set_pop(ir_node *call, unsigned pop) {
679 be_call_attr_t *a = get_irn_attr(call);
683 unsigned be_Call_get_pop(const ir_node *call) {
684 const be_call_attr_t *a = get_irn_attr_const(call);
688 /* Construct a new be_Return. */
689 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
690 unsigned pop, int n, ir_node *in[])
696 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
697 init_node_attr(res, -1);
698 for(i = 0; i < n; ++i) {
699 add_irn_n(res, in[i]);
700 add_register_req(res);
703 a = get_irn_attr(res);
704 a->num_ret_vals = n_res;
711 /* Returns the number of real returns values */
712 int be_Return_get_n_rets(const ir_node *ret) {
713 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
714 return a->num_ret_vals;
717 /* return the number of bytes that should be popped from stack when executing the Return. */
718 unsigned be_Return_get_pop(const ir_node *ret) {
719 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
723 /* return non-zero, if number of popped bytes must be always emitted */
724 int be_Return_get_emit_pop(const ir_node *ret) {
725 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
729 /* return non-zero, if number of popped bytes must be always emitted */
730 void be_Return_set_emit_pop(ir_node *ret, int emit_pop) {
731 be_return_attr_t *a = get_irn_generic_attr(ret);
732 a->emit_pop = emit_pop;
735 int be_Return_append_node(ir_node *ret, ir_node *node) {
738 pos = add_irn_n(ret, node);
739 add_register_req(ret);
744 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl,
745 ir_node *old_sp, int offset, int align)
752 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode,
753 sizeof(in) / sizeof(in[0]), in);
754 a = init_node_attr(irn, 1);
758 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
760 /* Set output constraint to stack register. */
761 be_node_set_reg_class(irn, 0, sp->reg_class);
762 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
763 be_node_set_irn_reg(NULL, irn, sp);
768 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
772 ir_node *in[be_pos_AddSP_last];
773 const arch_register_class_t *class;
775 in[be_pos_AddSP_old_sp] = old_sp;
776 in[be_pos_AddSP_size] = sz;
778 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
779 a = init_node_attr(irn, be_pos_AddSP_last);
781 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
782 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
784 /* Set output constraint to stack register. */
785 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
786 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
787 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
788 a->reg_data[pn_be_AddSP_sp].reg = sp;
790 class = arch_register_get_class(sp);
791 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
796 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
800 ir_node *in[be_pos_SubSP_last];
802 in[be_pos_SubSP_old_sp] = old_sp;
803 in[be_pos_SubSP_size] = sz;
805 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
806 a = init_node_attr(irn, be_pos_SubSP_last);
808 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
809 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
811 /* Set output constraint to stack register. */
812 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
813 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
814 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
815 a->reg_data[pn_be_SubSP_sp].reg = sp;
820 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
825 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
826 init_node_attr(res, -1);
827 for(i = 0; i < n_outs; ++i)
828 add_register_req(res);
833 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
834 const arch_env_t *arch_env,
835 const arch_register_t *reg)
837 ir_graph *irg = get_irn_irg(regparams);
838 ir_node *block = get_nodes_block(regparams);
839 be_node_attr_t *attr = get_irn_attr(regparams);
840 const arch_register_class_t *cls = arch_register_get_class(reg);
841 ir_mode *mode = arch_register_class_mode(cls);
842 int n = ARR_LEN(attr->reg_data);
845 assert(be_is_RegParams(regparams));
846 proj = new_r_Proj(irg, block, regparams, mode, n);
847 add_register_req(regparams);
848 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
849 arch_set_irn_register(arch_env, proj, reg);
851 /* TODO decide, whether we need to set ignore/modify sp flags here? */
856 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
863 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
864 a = init_node_attr(irn, 1);
867 be_node_set_reg_class(irn, 0, cls_frame);
868 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
870 return optimize_node(irn);
873 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
874 assert(be_is_FrameAddr(node));
875 return get_irn_n(node, be_pos_FrameAddr_ptr);
878 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
880 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
884 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)
887 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
890 memcpy(&in[1], in_keep, n * sizeof(in[0]));
891 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
892 init_node_attr(irn, n + 1);
893 be_node_set_reg_class(irn, OUT_POS(0), cls);
894 be_node_set_reg_class(irn, 0, cls);
899 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)
901 return be_new_CopyKeep(cls, irg, bl, src, 1, &keep, mode);
904 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
905 return get_irn_n(cpy, be_pos_CopyKeep_op);
908 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
909 set_irn_n(cpy, be_pos_CopyKeep_op, op);
912 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
917 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
918 init_node_attr(res, -1);
919 for(i = 0; i < n; ++i) {
920 add_irn_n(res, in[i]);
921 add_register_req(res);
927 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
929 ir_graph *irg = get_irn_irg(barrier);
930 ir_node *block = get_nodes_block(barrier);
931 ir_mode *mode = get_irn_mode(node);
932 int n = add_irn_n(barrier, node);
934 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
935 add_register_req(barrier);
940 /* Construct a new be_Unwind. */
941 ir_node *be_new_Unwind(dbg_info *dbg, ir_graph *irg, ir_node *block,
942 ir_node *mem, ir_node *sp)
947 in[be_pos_Unwind_mem] = mem;
948 in[be_pos_Unwind_sp] = sp;
949 res = new_ir_node(dbg, irg, block, op_be_Unwind, mode_X, 2, in);
950 init_node_attr(res, -1);
955 int be_has_frame_entity(const ir_node *irn)
957 switch (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)
1238 switch (get_irn_opcode(irn)) {
1239 #define XXX(a,b) case a: return b
1240 XXX(beo_Spill, arch_irn_class_spill);
1241 XXX(beo_Reload, arch_irn_class_reload);
1242 XXX(beo_Perm, arch_irn_class_perm);
1243 XXX(beo_Copy, arch_irn_class_copy);
1244 XXX(beo_Return, arch_irn_class_branch);
1247 irn = get_Proj_pred(irn);
1249 assert(get_irn_mode(irn) == mode_T);
1250 irn = get_Proj_pred(irn);
1255 return arch_irn_class_normal;
1261 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1268 pos = OUT_POS(get_Proj_proj(node));
1269 node = skip_Proj_const(node);
1272 bereq = get_be_req(node, pos);
1274 return bereq->flags;
1277 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1280 return be_get_frame_entity(irn);
1283 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1288 assert(be_has_frame_entity(irn));
1290 a = get_irn_attr(irn);
1294 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1297 if(be_has_frame_entity(irn)) {
1298 be_frame_attr_t *a = get_irn_attr(irn);
1303 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1306 if(be_is_IncSP(irn))
1307 return be_get_IncSP_offset(irn);
1309 return -(int)be_Call_get_pop(irn);
1315 ___ ____ _ _ _ _ _ _
1316 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1317 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1318 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1319 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1323 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1324 be_node_get_irn_reg_req,
1325 be_node_set_irn_reg,
1326 be_node_get_irn_reg,
1329 be_node_get_frame_entity,
1330 be_node_set_frame_entity,
1331 be_node_set_frame_offset,
1332 be_node_get_sp_bias,
1333 NULL, /* get_inverse */
1334 NULL, /* get_op_estimated_cost */
1335 NULL, /* possible_memory_operand */
1336 NULL, /* perform_memory_operand */
1339 static const arch_irn_ops_t be_node_irn_ops = {
1343 const void *be_node_get_irn_ops(const ir_node *irn)
1346 irn = get_Proj_pred(irn);
1348 assert(get_irn_mode(irn) == mode_T);
1349 irn = get_Proj_pred(irn);
1352 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1356 ____ _ _ ___ ____ _ _ _ _ _ _
1357 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1358 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1359 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1360 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1365 const arch_register_t *reg;
1366 arch_register_req_t req;
1367 arch_irn_flags_t flags;
1370 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1371 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1374 const void *phi_get_irn_ops(const ir_node *irn)
1376 if (!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1379 return &curr_phi_handler->irn_ops;
1383 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1385 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1387 ir_graph *irg = get_irn_irg(phi);
1388 struct obstack *obst = get_irg_obstack(irg);
1389 attr = obstack_alloc(obst, sizeof(attr[0]));
1390 memset(attr, 0, sizeof(attr[0]));
1391 pmap_insert(handler->phi_attrs, phi, attr);
1398 * Get register class of a Phi.
1401 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1405 int n = get_irn_arity(phi);
1409 if(*visited && pset_find_ptr(*visited, phi))
1412 for(i = 0; i < n; ++i) {
1413 op = get_irn_n(phi, i);
1414 /* Matze: don't we unnecessary constraint our phis with this?
1415 * we only need to take the regclass IMO*/
1417 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1421 * The operands of that Phi were all Phis themselves.
1422 * We have to start a DFS for a non-Phi argument now.
1425 *visited = pset_new_ptr(16);
1427 pset_insert_ptr(*visited, phi);
1429 for(i = 0; i < n; ++i) {
1430 const arch_register_req_t *req;
1431 op = get_irn_n(phi, i);
1432 req = get_Phi_reg_req_recursive(h, op, visited);
1441 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1442 const ir_node *irn, int pos)
1444 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1449 if(!mode_is_datab(get_irn_mode(irn)))
1450 return arch_no_register_req;
1452 attr = get_Phi_attr(phi_handler, irn);
1454 if(attr->req.type == arch_register_req_type_none) {
1455 pset *visited = NULL;
1456 const arch_register_req_t *req;
1457 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1459 memcpy(&attr->req, req, sizeof(req[0]));
1460 assert(attr->req.cls != NULL);
1461 attr->req.type = arch_register_req_type_normal;
1470 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1471 const arch_register_req_t *req)
1473 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1474 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1477 assert(mode_is_datab(get_irn_mode(node)));
1479 attr = get_Phi_attr(handler, node);
1480 memcpy(&attr->req, req, sizeof(req[0]));
1483 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1484 arch_irn_flags_t flags)
1486 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1487 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1490 assert(mode_is_datab(get_irn_mode(node)));
1492 attr = get_Phi_attr(handler, node);
1493 attr->flags = flags;
1497 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1499 phi_handler_t *h = get_phi_handler_from_ops(self);
1500 phi_attr_t *attr = get_Phi_attr(h, irn);
1505 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1507 phi_handler_t *h = get_phi_handler_from_ops(self);
1508 phi_attr_t *attr = get_Phi_attr(h, irn);
1513 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1517 return arch_irn_class_normal;
1521 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1523 phi_handler_t *h = get_phi_handler_from_ops(self);
1524 phi_attr_t *attr = get_Phi_attr(h, irn);
1530 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1538 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1547 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1556 int phi_get_sp_bias(const void* self, const ir_node *irn)
1564 const arch_irn_ops_if_t phi_irn_ops = {
1565 phi_get_irn_reg_req,
1570 phi_get_frame_entity,
1571 phi_set_frame_entity,
1572 phi_set_frame_offset,
1574 NULL, /* get_inverse */
1575 NULL, /* get_op_estimated_cost */
1576 NULL, /* possible_memory_operand */
1577 NULL, /* perform_memory_operand */
1580 void be_phi_handler_new(be_main_env_t *env)
1582 phi_handler_t *h = &env->phi_handler;
1583 h->get_irn_ops = phi_get_irn_ops;
1584 h->irn_ops.impl = &phi_irn_ops;
1585 h->arch_env = &env->arch_env;
1586 h->phi_attrs = pmap_create();
1587 curr_phi_handler = h;
1590 void be_phi_handler_free(be_main_env_t *env)
1592 phi_handler_t *h = &env->phi_handler;
1593 pmap_destroy(h->phi_attrs);
1594 h->phi_attrs = NULL;
1595 curr_phi_handler = NULL;
1598 void be_phi_handler_reset(be_main_env_t *env)
1600 phi_handler_t *h = &env->phi_handler;
1602 pmap_destroy(h->phi_attrs);
1603 h->phi_attrs = pmap_create();
1608 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1609 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1610 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1611 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1616 * Dumps a register requirement to a file.
1618 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1619 const ir_node *node)
1621 int did_something = 0;
1623 const char *prefix = buf;
1625 snprintf(buf, sizeof(buf), "#%d ", idx);
1626 buf[sizeof(buf) - 1] = '\0';
1631 arch_register_req_format(tmp, sizeof(tmp), req, node);
1632 fprintf(f, "%s", tmp);
1641 * Dumps node register requirements to a file.
1643 static void dump_node_reqs(FILE *f, ir_node *node)
1646 be_node_attr_t *a = get_irn_attr(node);
1647 int len = ARR_LEN(a->reg_data);
1649 fprintf(f, "registers: \n");
1650 for(i = 0; i < len; ++i) {
1651 be_reg_data_t *rd = &a->reg_data[i];
1653 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1656 fprintf(f, "in requirements:\n");
1657 for(i = 0; i < len; ++i) {
1658 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1661 fprintf(f, "\nout requirements:\n");
1662 for(i = 0; i < len; ++i) {
1663 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1668 * ir_op-Operation: dump a be node to file
1670 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1672 be_node_attr_t *at = get_irn_attr(irn);
1674 assert(is_be_node(irn));
1677 case dump_node_opcode_txt:
1678 fprintf(f, get_op_name(get_irn_op(irn)));
1680 case dump_node_mode_txt:
1681 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1682 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1685 case dump_node_nodeattr_txt:
1686 if(be_is_Call(irn)) {
1687 be_call_attr_t *a = (be_call_attr_t *) at;
1689 fprintf(f, " [%s] ", get_entity_name(a->ent));
1691 if(be_is_IncSP(irn)) {
1692 const be_incsp_attr_t *attr = get_irn_generic_attr_const(irn);
1693 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1694 fprintf(f, " [Setup Stackframe] ");
1695 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1696 fprintf(f, " [Destroy Stackframe] ");
1698 fprintf(f, " [%d] ", attr->offset);
1702 case dump_node_info_txt:
1703 dump_node_reqs(f, irn);
1705 if(be_has_frame_entity(irn)) {
1706 be_frame_attr_t *a = (be_frame_attr_t *) at;
1708 unsigned size = get_type_size_bytes(get_entity_type(a->ent));
1709 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
1710 a->ent, a->offset, a->offset, size, size);
1715 switch (get_irn_opcode(irn)) {
1718 be_incsp_attr_t *a = (be_incsp_attr_t *) at;
1719 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1720 fprintf(f, "offset: FRAME_SIZE\n");
1721 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1722 fprintf(f, "offset: -FRAME SIZE\n");
1724 fprintf(f, "offset: %u\n", a->offset);
1729 be_call_attr_t *a = (be_call_attr_t *) at;
1732 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1738 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1739 ir_entity *in, *out;
1740 in = be_get_MemPerm_in_entity(irn, i);
1741 out = be_get_MemPerm_out_entity(irn, i);
1743 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1746 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1762 * Copies the backend specific attributes from old node to new node.
1764 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1766 const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
1767 be_node_attr_t *new_attr = get_irn_attr(new_node);
1768 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1771 assert(is_be_node(old_node));
1772 assert(is_be_node(new_node));
1774 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1775 new_attr->reg_data = NULL;
1777 if(old_attr->reg_data != NULL)
1778 len = ARR_LEN(old_attr->reg_data);
1782 if(get_irn_op(old_node)->opar == oparity_dynamic
1783 || be_is_RegParams(old_node)) {
1784 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1786 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1790 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1791 for(i = 0; i < len; ++i) {
1792 const be_reg_data_t *rd = &old_attr->reg_data[i];
1793 be_reg_data_t *newrd = &new_attr->reg_data[i];
1794 if(arch_register_req_is(&rd->req.req, limited)) {
1795 const arch_register_req_t *req = &rd->req.req;
1796 arch_register_req_t *new_req = &newrd->req.req;
1798 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1800 if(arch_register_req_is(&rd->in_req.req, limited)) {
1801 const arch_register_req_t *req = &rd->in_req.req;
1802 arch_register_req_t *new_req = &newrd->in_req.req;
1804 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1810 static const ir_op_ops be_node_op_ops = {