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. */
98 /** The be_Frame attribute type. */
100 be_node_attr_t node_attr; /**< base attributes of every be node. */
105 /** The be_Call attribute type. */
107 be_node_attr_t node_attr; /**< base attributes of every be node. */
108 ir_entity *ent; /**< The called entity if this is a static call. */
110 ir_type *call_tp; /**< The call type, copied from the original Call node. */
114 be_node_attr_t node_attr; /**< base attributes of every be node. */
115 ir_entity **in_entities;
116 ir_entity **out_entities;
122 ir_op *op_be_MemPerm;
125 ir_op *op_be_CopyKeep;
131 ir_op *op_be_RegParams;
132 ir_op *op_be_FrameAddr;
133 ir_op *op_be_Barrier;
136 static int beo_base = -1;
138 static const ir_op_ops be_node_op_ops;
140 #define N irop_flag_none
141 #define L irop_flag_labeled
142 #define C irop_flag_commutative
143 #define X irop_flag_cfopcode
144 #define I irop_flag_ip_cfopcode
145 #define F irop_flag_fragile
146 #define Y irop_flag_forking
147 #define H irop_flag_highlevel
148 #define c irop_flag_constlike
149 #define K irop_flag_keep
150 #define M irop_flag_uses_memory
154 * Compare two be node attributes.
156 * @return zero if both attributes are identically
158 static int _node_cmp_attr(const be_node_attr_t *a, const be_node_attr_t *b) {
161 if (ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
164 len = ARR_LEN(a->reg_data);
165 for (i = 0; i < len; ++i) {
166 if (a->reg_data[i].reg != b->reg_data[i].reg ||
167 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
168 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
176 * Compare the node attributes of two be_node's.
178 * @return zero if both nodes have identically attributes
180 static int node_cmp_attr(ir_node *a, ir_node *b) {
181 const be_node_attr_t *a_attr = get_irn_attr_const(a);
182 const be_node_attr_t *b_attr = get_irn_attr_const(b);
184 return _node_cmp_attr(a_attr, b_attr);
188 * Compare the attributes of two be_FrameAddr nodes.
190 * @return zero if both nodes have identically attributes
192 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
193 const be_frame_attr_t *a_attr = get_irn_attr_const(a);
194 const be_frame_attr_t *b_attr = get_irn_attr_const(b);
196 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
199 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
203 * Compare the attributes of two be_Return nodes.
205 * @return zero if both nodes have identically attributes
207 static int Return_cmp_attr(ir_node *a, ir_node *b) {
208 const be_return_attr_t *a_attr = get_irn_attr_const(a);
209 const be_return_attr_t *b_attr = get_irn_attr_const(b);
211 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
213 if (a_attr->pop != b_attr->pop)
216 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
220 * Compare the attributes of two be_IncSP nodes.
222 * @return zero if both nodes have identically attributes
224 static int IncSP_cmp_attr(ir_node *a, ir_node *b) {
225 const be_incsp_attr_t *a_attr = get_irn_attr_const(a);
226 const be_incsp_attr_t *b_attr = get_irn_attr_const(b);
228 if (a_attr->offset != b_attr->offset)
231 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
235 * Compare the attributes of two be_Call nodes.
237 * @return zero if both nodes have identically attributes
239 static int Call_cmp_attr(ir_node *a, ir_node *b) {
240 const be_call_attr_t *a_attr = get_irn_attr_const(a);
241 const be_call_attr_t *b_attr = get_irn_attr_const(b);
243 if (a_attr->ent != b_attr->ent ||
244 a_attr->call_tp != b_attr->call_tp)
247 return _node_cmp_attr(&a_attr->node_attr, &b_attr->node_attr);
250 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
253 const be_node_attr_t *attr;
256 assert(is_be_node(node));
257 attr = get_irn_attr_const(node);
263 assert(idx < get_irn_arity(node));
265 assert(idx < ARR_LEN(attr->reg_data));
266 rd = &attr->reg_data[idx];
268 return pos < 0 ? &rd->req : &rd->in_req;
271 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
273 be_req_t *bereq = get_be_req(node, pos);
277 void be_node_init(void) {
278 static int inited = 0;
285 /* Acquire all needed opcodes. */
286 beo_base = get_next_ir_opcodes(beo_Last);
288 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);
289 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);
290 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);
291 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);
292 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);
293 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);
294 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);
295 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);
296 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);
297 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);
298 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);
299 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);
300 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);
301 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);
302 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);
303 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);
305 set_op_tag(op_be_Spill, &be_node_tag);
306 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
307 set_op_tag(op_be_Reload, &be_node_tag);
308 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
309 set_op_tag(op_be_Perm, &be_node_tag);
310 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
311 set_op_tag(op_be_MemPerm, &be_node_tag);
312 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
313 set_op_tag(op_be_Copy, &be_node_tag);
314 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
315 set_op_tag(op_be_Keep, &be_node_tag);
316 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
317 set_op_tag(op_be_CopyKeep, &be_node_tag);
318 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
319 set_op_tag(op_be_Call, &be_node_tag);
320 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
321 set_op_tag(op_be_Return, &be_node_tag);
322 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
323 set_op_tag(op_be_AddSP, &be_node_tag);
324 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
325 set_op_tag(op_be_SubSP, &be_node_tag);
326 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
327 set_op_tag(op_be_IncSP, &be_node_tag);
328 op_be_IncSP->ops.node_cmp_attr = IncSP_cmp_attr;
329 set_op_tag(op_be_RegParams, &be_node_tag);
330 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
331 set_op_tag(op_be_FrameAddr, &be_node_tag);
332 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
333 set_op_tag(op_be_Barrier, &be_node_tag);
334 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
335 set_op_tag(op_be_Unwind, &be_node_tag);
336 op_be_Unwind->ops.node_cmp_attr = node_cmp_attr;
340 * Initializes the generic attribute of all be nodes and return ir.
342 static void *init_node_attr(ir_node *node, int max_reg_data)
344 ir_graph *irg = get_irn_irg(node);
345 struct obstack *obst = get_irg_obstack(irg);
346 be_node_attr_t *a = get_irn_attr(node);
348 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
350 if(max_reg_data >= 0) {
351 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
352 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
354 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
360 static void add_register_req(ir_node *node)
362 be_node_attr_t *a = get_irn_attr(node);
363 be_reg_data_t regreq;
364 memset(®req, 0, sizeof(regreq));
365 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
368 int is_be_node(const ir_node *irn)
370 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
373 be_opcode_t be_get_irn_opcode(const ir_node *irn)
375 return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
379 * Skip Proj nodes and return their Proj numbers.
381 * If *node is a Proj or Proj(Proj) node, skip it.
383 * @param node points to the node to be skipped
385 * @return 0 if *node was no Proj node, its Proj number else.
387 static int redir_proj(const ir_node **node)
389 const ir_node *n = *node;
394 *node = irn = get_Proj_pred(n);
396 assert(get_irn_mode(irn) == mode_T);
397 *node = get_Proj_pred(irn);
399 return get_Proj_proj(n);
405 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
407 const be_node_attr_t *attr;
411 pos = get_Proj_proj(node);
412 node = get_Proj_pred(node);
415 assert(is_be_node(node));
416 attr = get_irn_attr_const(node);
417 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
419 return &attr->reg_data[pos];
423 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
425 be_reg_data_t *r = retrieve_reg_data(irn);
430 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
431 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
439 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
440 a = init_node_attr(res, 2);
444 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
445 be_node_set_reg_class(res, be_pos_Spill_val, cls);
449 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
450 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
457 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
459 init_node_attr(res, 2);
460 be_node_set_reg_class(res, -1, cls);
461 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
462 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
466 ir_node *be_get_Reload_mem(const ir_node *irn)
468 assert(be_is_Reload(irn));
469 return get_irn_n(irn, be_pos_Reload_mem);
472 ir_node *be_get_Reload_frame(const ir_node *irn)
474 assert(be_is_Reload(irn));
475 return get_irn_n(irn, be_pos_Reload_frame);
478 ir_node *be_get_Spill_val(const ir_node *irn)
480 assert(be_is_Spill(irn));
481 return get_irn_n(irn, be_pos_Spill_val);
484 ir_node *be_get_Spill_frame(const ir_node *irn)
486 assert(be_is_Spill(irn));
487 return get_irn_n(irn, be_pos_Spill_frame);
490 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
493 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
494 init_node_attr(irn, n);
495 for(i = 0; i < n; ++i) {
496 be_node_set_reg_class(irn, i, cls);
497 be_node_set_reg_class(irn, OUT_POS(i), cls);
503 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
505 ir_graph *irg = get_irn_irg(perm);
506 int arity = get_irn_arity(perm);
507 be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0]));
508 be_node_attr_t *attr = get_irn_attr(perm);
509 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size);
513 assert(be_is_Perm(perm));
514 assert(new_size <= arity);
516 /* save the old register data */
517 memcpy(old_data, attr->reg_data, arity * sizeof(old_data[0]));
519 /* compose the new in array and set the new register data directly in place */
520 for (i = 0; i < new_size; ++i) {
522 new_in[i] = get_irn_n(perm, idx);
523 attr->reg_data[i] = old_data[idx];
526 set_irn_in(perm, new_size, new_in);
529 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
532 ir_node *frame = get_irg_frame(irg);
533 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
535 const arch_register_t *sp = arch_env->isa->sp;
536 be_memperm_attr_t *attr;
539 real_in = alloca((n+1) * sizeof(real_in[0]));
541 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
543 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
545 init_node_attr(irn, n + 1);
546 be_node_set_reg_class(irn, 0, sp->reg_class);
547 for (i = 0; i < n; ++i) {
548 be_node_set_reg_class(irn, i + 1, cls_frame);
549 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
552 attr = get_irn_attr(irn);
554 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
555 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
556 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
557 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
563 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
567 arch_register_req_t *req;
570 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
571 init_node_attr(res, 1);
572 be_node_set_reg_class(res, 0, cls);
573 be_node_set_reg_class(res, OUT_POS(0), cls);
575 req = get_req(res, OUT_POS(0));
577 req->type = arch_register_req_type_should_be_same;
578 req->other_same = 1U << 0;
583 ir_node *be_get_Copy_op(const ir_node *cpy) {
584 return get_irn_n(cpy, be_pos_Copy_op);
587 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
588 set_irn_n(cpy, be_pos_Copy_op, op);
591 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
596 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
597 init_node_attr(res, -1);
599 for(i = 0; i < n; ++i) {
600 add_irn_n(res, in[i]);
601 add_register_req(res);
602 be_node_set_reg_class(res, i, cls);
609 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
613 assert(be_is_Keep(keep));
614 n = add_irn_n(keep, node);
615 add_register_req(keep);
616 be_node_set_reg_class(keep, n, cls);
619 /* creates a be_Call */
620 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
621 int n_outs, int n, ir_node *in[], ir_type *call_tp)
624 int real_n = be_pos_Call_first_arg + n;
628 NEW_ARR_A(ir_node *, real_in, real_n);
629 real_in[be_pos_Call_mem] = mem;
630 real_in[be_pos_Call_sp] = sp;
631 real_in[be_pos_Call_ptr] = ptr;
632 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
634 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
635 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
637 a->call_tp = call_tp;
642 /* Gets the call entity or NULL if this is no static call. */
643 ir_entity *be_Call_get_entity(const ir_node *call) {
644 const be_call_attr_t *a = get_irn_attr_const(call);
645 assert(be_is_Call(call));
649 /* Sets the call entity. */
650 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
651 be_call_attr_t *a = get_irn_attr(call);
652 assert(be_is_Call(call));
656 /* Gets the call type. */
657 ir_type *be_Call_get_type(ir_node *call) {
658 const be_call_attr_t *a = get_irn_attr_const(call);
659 assert(be_is_Call(call));
663 /* Sets the call type. */
664 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
665 be_call_attr_t *a = get_irn_attr(call);
666 assert(be_is_Call(call));
667 a->call_tp = call_tp;
670 void be_Call_set_pop(ir_node *call, unsigned pop) {
671 be_call_attr_t *a = get_irn_attr(call);
675 unsigned be_Call_get_pop(const ir_node *call) {
676 const be_call_attr_t *a = get_irn_attr_const(call);
680 /* Construct a new be_Return. */
681 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
682 unsigned pop, int n, ir_node *in[])
688 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
689 init_node_attr(res, -1);
690 for(i = 0; i < n; ++i) {
691 add_irn_n(res, in[i]);
692 add_register_req(res);
695 a = get_irn_attr(res);
696 a->num_ret_vals = n_res;
702 /* Returns the number of real returns values */
703 int be_Return_get_n_rets(const ir_node *ret)
705 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
706 return a->num_ret_vals;
709 unsigned be_Return_get_pop(const ir_node *ret)
711 const be_return_attr_t *a = get_irn_generic_attr_const(ret);
715 int be_Return_append_node(ir_node *ret, ir_node *node)
719 pos = add_irn_n(ret, node);
720 add_register_req(ret);
725 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
732 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
733 a = init_node_attr(irn, 1);
736 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
738 /* Set output constraint to stack register. */
739 be_node_set_reg_class(irn, 0, sp->reg_class);
740 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
741 be_node_set_irn_reg(NULL, irn, sp);
746 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
750 ir_node *in[be_pos_AddSP_last];
751 const arch_register_class_t *class;
753 in[be_pos_AddSP_old_sp] = old_sp;
754 in[be_pos_AddSP_size] = sz;
756 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
757 a = init_node_attr(irn, be_pos_AddSP_last);
759 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
760 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
762 /* Set output constraint to stack register. */
763 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
764 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
765 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
766 a->reg_data[pn_be_AddSP_sp].reg = sp;
768 class = arch_register_get_class(sp);
769 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
774 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
778 ir_node *in[be_pos_SubSP_last];
780 in[be_pos_SubSP_old_sp] = old_sp;
781 in[be_pos_SubSP_size] = sz;
783 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
784 a = init_node_attr(irn, be_pos_SubSP_last);
786 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
787 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
789 /* Set output constraint to stack register. */
790 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
791 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
792 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
793 a->reg_data[pn_be_SubSP_sp].reg = sp;
798 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
803 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
804 init_node_attr(res, -1);
805 for(i = 0; i < n_outs; ++i)
806 add_register_req(res);
811 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
812 const arch_env_t *arch_env,
813 const arch_register_t *reg)
815 ir_graph *irg = get_irn_irg(regparams);
816 ir_node *block = get_nodes_block(regparams);
817 be_node_attr_t *attr = get_irn_attr(regparams);
818 const arch_register_class_t *cls = arch_register_get_class(reg);
819 ir_mode *mode = arch_register_class_mode(cls);
820 int n = ARR_LEN(attr->reg_data);
823 assert(be_is_RegParams(regparams));
824 proj = new_r_Proj(irg, block, regparams, mode, n);
825 add_register_req(regparams);
826 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
827 arch_set_irn_register(arch_env, proj, reg);
829 /* TODO decide, whether we need to set ignore/modify sp flags here? */
834 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
841 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
842 a = init_node_attr(irn, 1);
845 be_node_set_reg_class(irn, 0, cls_frame);
846 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
848 return optimize_node(irn);
851 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
852 assert(be_is_FrameAddr(node));
853 return get_irn_n(node, be_pos_FrameAddr_ptr);
856 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
858 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
862 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)
865 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
868 memcpy(&in[1], in_keep, n * sizeof(in[0]));
869 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
870 init_node_attr(irn, n + 1);
871 be_node_set_reg_class(irn, OUT_POS(0), cls);
872 be_node_set_reg_class(irn, 0, cls);
877 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)
879 return be_new_CopyKeep(cls, irg, bl, src, 1, &keep, mode);
882 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
883 return get_irn_n(cpy, be_pos_CopyKeep_op);
886 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
887 set_irn_n(cpy, be_pos_CopyKeep_op, op);
890 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
895 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
896 init_node_attr(res, -1);
897 for(i = 0; i < n; ++i) {
898 add_irn_n(res, in[i]);
899 add_register_req(res);
905 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
907 ir_graph *irg = get_irn_irg(barrier);
908 ir_node *block = get_nodes_block(barrier);
909 ir_mode *mode = get_irn_mode(node);
910 int n = add_irn_n(barrier, node);
912 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
913 add_register_req(barrier);
918 /* Construct a new be_Unwind. */
919 ir_node *be_new_Unwind(dbg_info *dbg, ir_graph *irg, ir_node *block,
920 ir_node *mem, ir_node *sp)
925 in[be_pos_Unwind_mem] = mem;
926 in[be_pos_Unwind_sp] = sp;
927 res = new_ir_node(dbg, irg, block, op_be_Unwind, mode_X, 2, in);
928 init_node_attr(res, -1);
933 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
934 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
935 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
936 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
937 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
938 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
939 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
940 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
941 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
942 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
943 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
944 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
945 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
946 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
947 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
948 int be_is_Unwind (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Unwind ; }
950 int be_has_frame_entity(const ir_node *irn)
952 switch (be_get_irn_opcode(irn)) {
962 ir_entity *be_get_frame_entity(const ir_node *irn)
964 if (be_has_frame_entity(irn)) {
965 const be_frame_attr_t *a = get_irn_attr_const(irn);
971 int be_get_frame_offset(const ir_node *irn)
973 assert(is_be_node(irn));
974 if (be_has_frame_entity(irn)) {
975 const be_frame_attr_t *a = get_irn_attr_const(irn);
981 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
983 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
985 assert(be_is_MemPerm(irn));
986 assert(n < be_get_MemPerm_entity_arity(irn));
988 attr->in_entities[n] = ent;
991 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
993 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
995 assert(be_is_MemPerm(irn));
996 assert(n < be_get_MemPerm_entity_arity(irn));
998 return attr->in_entities[n];
1001 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
1003 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
1005 assert(be_is_MemPerm(irn));
1006 assert(n < be_get_MemPerm_entity_arity(irn));
1008 attr->out_entities[n] = ent;
1011 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
1013 const be_memperm_attr_t *attr = get_irn_attr_const(irn);
1015 assert(be_is_MemPerm(irn));
1016 assert(n < be_get_MemPerm_entity_arity(irn));
1018 return attr->out_entities[n];
1021 int be_get_MemPerm_entity_arity(const ir_node *irn)
1023 return get_irn_arity(irn) - 1;
1026 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
1028 arch_register_req_t *req = get_req(node, pos);
1029 const arch_register_class_t *cls = arch_register_get_class(reg);
1030 ir_graph *irg = get_irn_irg(node);
1031 struct obstack *obst = get_irg_obstack(irg);
1032 unsigned *limited_bitset;
1034 assert(req->cls == NULL || req->cls == cls);
1035 assert(! (req->type & arch_register_req_type_limited));
1036 assert(req->limited == NULL);
1038 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1039 rbitset_set(limited_bitset, arch_register_get_index(reg));
1042 req->type |= arch_register_req_type_limited;
1043 req->limited = limited_bitset;
1046 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1048 ir_graph *irg = get_irn_irg(node);
1049 struct obstack *obst = get_irg_obstack(irg);
1050 arch_register_req_t *r = get_req(node, pos);
1052 assert(arch_register_req_is(req, limited));
1053 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1054 memcpy(r, req, sizeof(r[0]));
1055 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1058 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1060 be_req_t *bereq = get_be_req(irn, pos);
1061 bereq->flags = flags;
1064 void be_node_add_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1066 be_req_t *bereq = get_be_req(irn, pos);
1067 bereq->flags |= flags;
1070 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1072 arch_register_req_t *req = get_req(irn, pos);
1077 req->type = arch_register_req_type_none;
1078 } else if (req->type == arch_register_req_type_none) {
1079 req->type = arch_register_req_type_normal;
1083 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1085 arch_register_req_t *req = get_req(irn, pos);
1089 ir_node *be_get_IncSP_pred(ir_node *irn) {
1090 assert(be_is_IncSP(irn));
1091 return get_irn_n(irn, 0);
1094 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1095 assert(be_is_IncSP(incsp));
1096 set_irn_n(incsp, 0, pred);
1099 void be_set_IncSP_offset(ir_node *irn, int offset)
1101 be_incsp_attr_t *a = get_irn_attr(irn);
1102 assert(be_is_IncSP(irn));
1106 int be_get_IncSP_offset(const ir_node *irn)
1108 const be_incsp_attr_t *a = get_irn_attr_const(irn);
1109 assert(be_is_IncSP(irn));
1113 ir_node *be_spill(const arch_env_t *arch_env, ir_node *block, ir_node *irn)
1115 ir_graph *irg = get_irn_irg(block);
1116 ir_node *frame = get_irg_frame(irg);
1117 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1118 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1121 spill = be_new_Spill(cls, cls_frame, irg, block, frame, irn);
1125 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)
1128 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1129 ir_graph *irg = get_irn_irg(bl);
1130 ir_node *frame = get_irg_frame(irg);
1131 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1133 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1135 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1137 if (is_Block(insert)) {
1138 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1139 sched_add_after(insert, reload);
1141 sched_add_before(insert, reload);
1149 | _ \ ___ __ _ | _ \ ___ __ _ ___
1150 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1151 | _ < __/ (_| | | _ < __/ (_| \__ \
1152 |_| \_\___|\__, | |_| \_\___|\__, |___/
1159 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1161 const be_node_attr_t *a = get_irn_attr_const(irn);
1163 if(out_pos >= ARR_LEN(a->reg_data)) {
1164 return arch_no_register_req;
1167 return &a->reg_data[out_pos].req.req;
1171 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1173 const be_node_attr_t *a = get_irn_attr_const(irn);
1175 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1176 return arch_no_register_req;
1178 return &a->reg_data[pos].in_req.req;
1181 static const arch_register_req_t *
1182 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1188 if (get_irn_mode(irn) == mode_T)
1189 return arch_no_register_req;
1191 out_pos = redir_proj((const ir_node **)&irn);
1192 assert(is_be_node(irn));
1193 return get_out_reg_req(irn, out_pos);
1194 } else if (is_be_node(irn)) {
1196 * For spills and reloads, we return "none" as requirement for frame
1197 * pointer, so every input is ok. Some backends need this (e.g. STA).
1199 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1200 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1201 return arch_no_register_req;
1203 return get_in_reg_req(irn, pos);
1206 return arch_no_register_req;
1209 const arch_register_t *
1210 be_node_get_irn_reg(const void *self, const ir_node *irn)
1215 if (get_irn_mode(irn) == mode_T)
1217 r = retrieve_reg_data(irn);
1221 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1223 redir_proj((const ir_node **) &irn);
1226 switch(be_get_irn_opcode(irn)) {
1227 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1229 XXX(Reload, reload);
1232 XXX(Return, branch);
1235 return arch_irn_class_normal;
1241 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1248 pos = OUT_POS(get_Proj_proj(node));
1249 node = skip_Proj_const(node);
1252 bereq = get_be_req(node, pos);
1254 return bereq->flags;
1257 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1260 return be_get_frame_entity(irn);
1263 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1268 assert(be_has_frame_entity(irn));
1270 a = get_irn_attr(irn);
1274 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1277 if(be_has_frame_entity(irn)) {
1278 be_frame_attr_t *a = get_irn_attr(irn);
1283 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1286 if(be_is_IncSP(irn))
1287 return be_get_IncSP_offset(irn);
1289 return -(int)be_Call_get_pop(irn);
1295 ___ ____ _ _ _ _ _ _
1296 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1297 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1298 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1299 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1303 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1304 be_node_get_irn_reg_req,
1305 be_node_set_irn_reg,
1306 be_node_get_irn_reg,
1309 be_node_get_frame_entity,
1310 be_node_set_frame_entity,
1311 be_node_set_frame_offset,
1312 be_node_get_sp_bias,
1313 NULL, /* get_inverse */
1314 NULL, /* get_op_estimated_cost */
1315 NULL, /* possible_memory_operand */
1316 NULL, /* perform_memory_operand */
1319 static const arch_irn_ops_t be_node_irn_ops = {
1323 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1325 redir_proj((const ir_node **) &irn);
1327 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1330 const arch_irn_handler_t be_node_irn_handler = {
1335 ____ _ _ ___ ____ _ _ _ _ _ _
1336 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1337 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1338 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1339 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1344 const arch_register_t *reg;
1345 arch_register_req_t req;
1346 arch_irn_flags_t flags;
1350 arch_irn_handler_t irn_handler;
1351 arch_irn_ops_t irn_ops;
1352 const arch_env_t *arch_env;
1356 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1357 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1360 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1363 const phi_handler_t *h;
1364 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1367 h = get_phi_handler_from_handler(handler);
1372 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1374 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1376 ir_graph *irg = get_irn_irg(phi);
1377 struct obstack *obst = get_irg_obstack(irg);
1378 attr = obstack_alloc(obst, sizeof(attr[0]));
1379 memset(attr, 0, sizeof(attr[0]));
1380 pmap_insert(handler->phi_attrs, phi, attr);
1387 * Get register class of a Phi.
1390 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1394 int n = get_irn_arity(phi);
1398 if(*visited && pset_find_ptr(*visited, phi))
1401 for(i = 0; i < n; ++i) {
1402 op = get_irn_n(phi, i);
1403 /* Matze: don't we unnecessary constraint our phis with this?
1404 * we only need to take the regclass IMO*/
1406 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1410 * The operands of that Phi were all Phis themselves.
1411 * We have to start a DFS for a non-Phi argument now.
1414 *visited = pset_new_ptr(16);
1416 pset_insert_ptr(*visited, phi);
1418 for(i = 0; i < n; ++i) {
1419 const arch_register_req_t *req;
1420 op = get_irn_n(phi, i);
1421 req = get_Phi_reg_req_recursive(h, op, visited);
1430 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1431 const ir_node *irn, int pos)
1433 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1438 if(!mode_is_datab(get_irn_mode(irn)))
1439 return arch_no_register_req;
1441 attr = get_Phi_attr(phi_handler, irn);
1443 if(attr->req.type == arch_register_req_type_none) {
1444 pset *visited = NULL;
1445 const arch_register_req_t *req;
1446 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1448 memcpy(&attr->req, req, sizeof(req[0]));
1449 assert(attr->req.cls != NULL);
1450 attr->req.type = arch_register_req_type_normal;
1459 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1460 const arch_register_req_t *req)
1462 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1463 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1466 assert(mode_is_datab(get_irn_mode(node)));
1468 attr = get_Phi_attr(handler, node);
1469 memcpy(&attr->req, req, sizeof(req[0]));
1472 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1473 arch_irn_flags_t flags)
1475 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1476 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1479 assert(mode_is_datab(get_irn_mode(node)));
1481 attr = get_Phi_attr(handler, node);
1482 attr->flags = flags;
1486 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1488 phi_handler_t *h = get_phi_handler_from_ops(self);
1489 phi_attr_t *attr = get_Phi_attr(h, irn);
1494 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1496 phi_handler_t *h = get_phi_handler_from_ops(self);
1497 phi_attr_t *attr = get_Phi_attr(h, irn);
1502 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1506 return arch_irn_class_normal;
1510 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1512 phi_handler_t *h = get_phi_handler_from_ops(self);
1513 phi_attr_t *attr = get_Phi_attr(h, irn);
1519 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1527 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1536 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1545 int phi_get_sp_bias(const void* self, const ir_node *irn)
1553 const arch_irn_ops_if_t phi_irn_ops = {
1554 phi_get_irn_reg_req,
1559 phi_get_frame_entity,
1560 phi_set_frame_entity,
1561 phi_set_frame_offset,
1563 NULL, /* get_inverse */
1564 NULL, /* get_op_estimated_cost */
1565 NULL, /* possible_memory_operand */
1566 NULL, /* perform_memory_operand */
1569 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1571 phi_handler_t *h = xmalloc(sizeof(h[0]));
1572 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1573 h->irn_ops.impl = &phi_irn_ops;
1574 h->arch_env = arch_env;
1575 h->phi_attrs = pmap_create();
1576 return (arch_irn_handler_t *) h;
1579 void be_phi_handler_free(arch_irn_handler_t *handler)
1581 phi_handler_t *h = get_phi_handler_from_handler(handler);
1582 pmap_destroy(h->phi_attrs);
1583 h->phi_attrs = NULL;
1587 void be_phi_handler_reset(arch_irn_handler_t *handler)
1589 phi_handler_t *h = get_phi_handler_from_handler(handler);
1591 pmap_destroy(h->phi_attrs);
1592 h->phi_attrs = pmap_create();
1597 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1598 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1599 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1600 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1605 * Dumps a register requirement to a file.
1607 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1608 const ir_node *node)
1610 int did_something = 0;
1612 const char *prefix = buf;
1614 snprintf(buf, sizeof(buf), "#%d ", idx);
1615 buf[sizeof(buf) - 1] = '\0';
1620 arch_register_req_format(tmp, sizeof(tmp), req, node);
1621 fprintf(f, "%s", tmp);
1630 * Dumps node register requirements to a file.
1632 static void dump_node_reqs(FILE *f, ir_node *node)
1635 be_node_attr_t *a = get_irn_attr(node);
1636 int len = ARR_LEN(a->reg_data);
1638 fprintf(f, "registers: \n");
1639 for(i = 0; i < len; ++i) {
1640 be_reg_data_t *rd = &a->reg_data[i];
1642 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1645 fprintf(f, "in requirements:\n");
1646 for(i = 0; i < len; ++i) {
1647 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1650 fprintf(f, "\nout requirements:\n");
1651 for(i = 0; i < len; ++i) {
1652 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1657 * ir_op-Operation: dump a be node to file
1659 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1661 be_node_attr_t *at = get_irn_attr(irn);
1663 assert(is_be_node(irn));
1666 case dump_node_opcode_txt:
1667 fprintf(f, get_op_name(get_irn_op(irn)));
1669 case dump_node_mode_txt:
1670 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1671 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1674 case dump_node_nodeattr_txt:
1675 if(be_is_Call(irn)) {
1676 be_call_attr_t *a = (be_call_attr_t *) at;
1678 fprintf(f, " [%s] ", get_entity_name(a->ent));
1680 if(be_is_IncSP(irn)) {
1681 const be_incsp_attr_t *attr = get_irn_generic_attr_const(irn);
1682 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1683 fprintf(f, " [Setup Stackframe] ");
1684 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1685 fprintf(f, " [Destroy Stackframe] ");
1687 fprintf(f, " [%d] ", attr->offset);
1691 case dump_node_info_txt:
1692 dump_node_reqs(f, irn);
1694 if(be_has_frame_entity(irn)) {
1695 be_frame_attr_t *a = (be_frame_attr_t *) at;
1697 unsigned size = get_type_size_bytes(get_entity_type(a->ent));
1698 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
1699 a->ent, a->offset, a->offset, size, size);
1704 switch(be_get_irn_opcode(irn)) {
1707 be_incsp_attr_t *a = (be_incsp_attr_t *) at;
1708 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1709 fprintf(f, "offset: FRAME_SIZE\n");
1710 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1711 fprintf(f, "offset: -FRAME SIZE\n");
1713 fprintf(f, "offset: %u\n", a->offset);
1718 be_call_attr_t *a = (be_call_attr_t *) at;
1721 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1727 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1728 ir_entity *in, *out;
1729 in = be_get_MemPerm_in_entity(irn, i);
1730 out = be_get_MemPerm_out_entity(irn, i);
1732 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1735 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1751 * Copies the backend specific attributes from old node to new node.
1753 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1755 const be_node_attr_t *old_attr = get_irn_attr_const(old_node);
1756 be_node_attr_t *new_attr = get_irn_attr(new_node);
1757 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1760 assert(is_be_node(old_node));
1761 assert(is_be_node(new_node));
1763 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1764 new_attr->reg_data = NULL;
1766 if(old_attr->reg_data != NULL)
1767 len = ARR_LEN(old_attr->reg_data);
1771 if(get_irn_op(old_node)->opar == oparity_dynamic
1772 || be_is_RegParams(old_node)) {
1773 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1775 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1779 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1780 for(i = 0; i < len; ++i) {
1781 const be_reg_data_t *rd = &old_attr->reg_data[i];
1782 be_reg_data_t *newrd = &new_attr->reg_data[i];
1783 if(arch_register_req_is(&rd->req.req, limited)) {
1784 const arch_register_req_t *req = &rd->req.req;
1785 arch_register_req_t *new_req = &newrd->req.req;
1787 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1789 if(arch_register_req_is(&rd->in_req.req, limited)) {
1790 const arch_register_req_t *req = &rd->in_req.req;
1791 arch_register_req_t *new_req = &newrd->in_req.req;
1793 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1799 static const ir_op_ops be_node_op_ops = {