2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Backend node support for generic backend nodes.
23 * @author Sebastian Hack
27 * Backend node support for generic backend nodes.
28 * This file provides Perm, Copy, Spill and Reload nodes.
43 #include "bitfiddle.h"
44 #include "raw_bitset.h"
56 #include "besched_t.h"
61 #define OUT_POS(x) (-((x) + 1))
63 /* Sometimes we want to put const nodes into get_irn_generic_attr ... */
64 #define get_irn_attr(irn) get_irn_generic_attr((ir_node *) (irn))
66 static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
69 arch_register_req_t req;
70 arch_irn_flags_t flags;
74 const arch_register_t *reg;
79 /** The generic be nodes attribute type. */
81 be_reg_data_t *reg_data;
84 /** The be_Return nodes attribute type. */
86 be_node_attr_t node_attr;
87 int num_ret_vals; /**< number of return values */
90 /** The be_Stack attribute type. */
92 be_node_attr_t node_attr;
93 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
96 /** The be_Frame attribute type. */
98 be_node_attr_t node_attr;
103 /** The be_Call attribute type. */
105 be_node_attr_t node_attr;
106 ir_entity *ent; /**< The called entity if this is a static call. */
107 ir_type *call_tp; /**< The call type, copied from the original Call node. */
111 be_node_attr_t node_attr;
112 ir_entity **in_entities;
113 ir_entity **out_entities;
119 ir_op *op_be_MemPerm;
122 ir_op *op_be_CopyKeep;
129 ir_op *op_be_RegParams;
130 ir_op *op_be_FrameAddr;
131 ir_op *op_be_Barrier;
133 static int beo_base = -1;
135 static const ir_op_ops be_node_op_ops;
137 #define N irop_flag_none
138 #define L irop_flag_labeled
139 #define C irop_flag_commutative
140 #define X irop_flag_cfopcode
141 #define I irop_flag_ip_cfopcode
142 #define F irop_flag_fragile
143 #define Y irop_flag_forking
144 #define H irop_flag_highlevel
145 #define c irop_flag_constlike
146 #define K irop_flag_keep
147 #define M irop_flag_machine
151 * Compare two node attributes.
153 * @return zero if both attributes are identically
155 static int _node_cmp_attr(be_node_attr_t *a, be_node_attr_t *b) {
158 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
161 len = ARR_LEN(a->reg_data);
162 for (i = 0; i < len; ++i) {
163 if (a->reg_data[i].reg != b->reg_data[i].reg ||
164 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
165 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
172 static int node_cmp_attr(ir_node *a, ir_node *b) {
173 be_node_attr_t *a_attr = get_irn_attr(a);
174 be_node_attr_t *b_attr = get_irn_attr(b);
176 return _node_cmp_attr(a_attr, b_attr);
180 * Compare the attributes of two FrameAddr nodes.
182 * @return zero if both attributes are identically
184 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
185 be_frame_attr_t *a_attr = get_irn_attr(a);
186 be_frame_attr_t *b_attr = get_irn_attr(b);
188 if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
191 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
194 static int Return_cmp_attr(ir_node *a, ir_node *b) {
195 be_return_attr_t *a_attr = get_irn_attr(a);
196 be_return_attr_t *b_attr = get_irn_attr(b);
198 if (a_attr->num_ret_vals != b_attr->num_ret_vals)
201 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
204 static int Stack_cmp_attr(ir_node *a, ir_node *b) {
205 be_stack_attr_t *a_attr = get_irn_attr(a);
206 be_stack_attr_t *b_attr = get_irn_attr(b);
208 if (a_attr->offset != b_attr->offset)
211 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
214 static int Call_cmp_attr(ir_node *a, ir_node *b) {
215 be_call_attr_t *a_attr = get_irn_attr(a);
216 be_call_attr_t *b_attr = get_irn_attr(b);
218 if (a_attr->ent != b_attr->ent ||
219 a_attr->call_tp != b_attr->call_tp)
222 return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
225 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
228 be_node_attr_t *attr;
231 assert(is_be_node(node));
232 attr = get_irn_attr(node);
238 assert(idx < get_irn_arity(node));
240 assert(idx < ARR_LEN(attr->reg_data));
241 rd = &attr->reg_data[idx];
243 return pos < 0 ? &rd->req : &rd->in_req;
246 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
248 be_req_t *bereq = get_be_req(node, pos);
252 void be_node_init(void) {
253 static int inited = 0;
260 /* Acquire all needed opcodes. */
261 beo_base = get_next_ir_opcodes(beo_Last);
263 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);
264 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);
265 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);
266 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);
267 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);
268 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);
269 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);
270 op_be_Call = new_ir_op(beo_base + beo_Call, "be_Call", op_pin_state_pinned, F, oparity_variable, 0, sizeof(be_call_attr_t), &be_node_op_ops);
271 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);
272 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);
273 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);
274 op_be_IncSP = new_ir_op(beo_base + beo_IncSP, "be_IncSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_stack_attr_t), &be_node_op_ops);
275 op_be_SetSP = new_ir_op(beo_base + beo_SetSP, "be_SetSP", op_pin_state_pinned, N, oparity_binary, 0, sizeof(be_stack_attr_t), &be_node_op_ops);
276 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);
277 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);
278 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);
280 set_op_tag(op_be_Spill, &be_node_tag);
281 op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
282 set_op_tag(op_be_Reload, &be_node_tag);
283 op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
284 set_op_tag(op_be_Perm, &be_node_tag);
285 op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
286 set_op_tag(op_be_MemPerm, &be_node_tag);
287 op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
288 set_op_tag(op_be_Copy, &be_node_tag);
289 op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
290 set_op_tag(op_be_Keep, &be_node_tag);
291 op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
292 set_op_tag(op_be_CopyKeep, &be_node_tag);
293 op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
294 set_op_tag(op_be_Call, &be_node_tag);
295 op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
296 set_op_tag(op_be_Return, &be_node_tag);
297 op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
298 set_op_tag(op_be_AddSP, &be_node_tag);
299 op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
300 set_op_tag(op_be_SubSP, &be_node_tag);
301 op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
302 set_op_tag(op_be_SetSP, &be_node_tag);
303 op_be_SetSP->ops.node_cmp_attr = Stack_cmp_attr;
304 set_op_tag(op_be_IncSP, &be_node_tag);
305 op_be_IncSP->ops.node_cmp_attr = Stack_cmp_attr;
306 set_op_tag(op_be_RegParams, &be_node_tag);
307 op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
308 set_op_tag(op_be_FrameAddr, &be_node_tag);
309 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
310 set_op_tag(op_be_Barrier, &be_node_tag);
311 op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
315 * Initializes the generic attribute of all be nodes and return ir.
317 static void *init_node_attr(ir_node *node, int max_reg_data)
319 ir_graph *irg = get_irn_irg(node);
320 struct obstack *obst = get_irg_obstack(irg);
321 be_node_attr_t *a = get_irn_attr(node);
323 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
325 if(max_reg_data >= 0) {
326 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
327 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
329 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
335 static void add_register_req(ir_node *node)
337 be_node_attr_t *a = get_irn_attr(node);
338 be_reg_data_t regreq;
339 memset(®req, 0, sizeof(regreq));
340 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
343 int is_be_node(const ir_node *irn)
345 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
348 be_opcode_t be_get_irn_opcode(const ir_node *irn)
350 return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
354 * Skip Proj nodes and return their Proj numbers.
356 * If *node is a Proj or Proj(Proj) node, skip it.
358 * @param node points to the node to be skipped
360 * @return 0 if *node was no Proj node, its Proj number else.
362 static int redir_proj(const ir_node **node)
364 const ir_node *n = *node;
369 *node = irn = get_Proj_pred(n);
371 assert(get_irn_mode(irn) == mode_T);
372 *node = get_Proj_pred(irn);
374 return get_Proj_proj(n);
380 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
382 be_node_attr_t *attr;
386 pos = get_Proj_proj(node);
387 node = get_Proj_pred(node);
390 assert(is_be_node(node));
391 attr = get_irn_attr(node);
392 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
394 return &attr->reg_data[pos];
398 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
400 be_reg_data_t *r = retrieve_reg_data(irn);
405 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
406 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
414 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
415 a = init_node_attr(res, 2);
419 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
420 be_node_set_reg_class(res, be_pos_Spill_val, cls);
424 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
425 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
432 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
434 init_node_attr(res, 2);
435 be_node_set_reg_class(res, -1, cls);
436 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
437 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
441 ir_node *be_get_Reload_mem(const ir_node *irn)
443 assert(be_is_Reload(irn));
444 return get_irn_n(irn, be_pos_Reload_mem);
447 ir_node *be_get_Reload_frame(const ir_node *irn)
449 assert(be_is_Reload(irn));
450 return get_irn_n(irn, be_pos_Reload_frame);
453 ir_node *be_get_Spill_val(const ir_node *irn)
455 assert(be_is_Spill(irn));
456 return get_irn_n(irn, be_pos_Spill_val);
459 ir_node *be_get_Spill_frame(const ir_node *irn)
461 assert(be_is_Spill(irn));
462 return get_irn_n(irn, be_pos_Spill_frame);
465 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
468 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
469 init_node_attr(irn, n);
470 for(i = 0; i < n; ++i) {
471 be_node_set_reg_class(irn, i, cls);
472 be_node_set_reg_class(irn, OUT_POS(i), cls);
478 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
480 ir_graph *irg = get_irn_irg(perm);
481 int n = get_irn_arity(perm);
482 be_reg_data_t *old_data = xmalloc(n * sizeof(old_data[0]));
483 be_node_attr_t *attr = get_irn_attr(perm);
484 ir_node **new_in = NEW_ARR_D(ir_node *, irg->obst, new_size + 1);
488 assert(be_is_Perm(perm));
489 assert(new_size <= n);
491 /* save the old register data */
492 memcpy(old_data, attr->reg_data, n * sizeof(old_data[0]));
494 /* compose the new in array and set the new register data directly in place */
495 for (i = 0; i < n; ++i) {
498 new_in[idx] = get_irn_n(perm, i);
499 attr->reg_data[idx] = old_data[i];
504 set_irn_in(perm, new_size, new_in);
507 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
510 ir_node *frame = get_irg_frame(irg);
511 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
513 const arch_register_t *sp = arch_env->isa->sp;
514 be_memperm_attr_t *attr;
517 real_in = alloca((n+1) * sizeof(real_in[0]));
519 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
521 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
523 init_node_attr(irn, n + 1);
524 be_node_set_reg_class(irn, 0, sp->reg_class);
525 for(i = 0; i < n; ++i) {
526 be_node_set_reg_class(irn, i + 1, cls_frame);
527 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
530 attr = get_irn_attr(irn);
532 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
533 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
534 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
535 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
541 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
545 arch_register_req_t *req;
548 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
549 init_node_attr(res, 1);
550 be_node_set_reg_class(res, 0, cls);
551 be_node_set_reg_class(res, OUT_POS(0), cls);
553 req = get_req(res, OUT_POS(0));
555 req->type = arch_register_req_type_should_be_same;
561 ir_node *be_get_Copy_op(const ir_node *cpy) {
562 return get_irn_n(cpy, be_pos_Copy_op);
565 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
566 set_irn_n(cpy, be_pos_Copy_op, op);
569 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
574 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
575 init_node_attr(res, -1);
577 for(i = 0; i < n; ++i) {
578 add_irn_n(res, in[i]);
579 add_register_req(res);
580 be_node_set_reg_class(res, i, cls);
587 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
591 assert(be_is_Keep(keep));
592 n = add_irn_n(keep, node);
593 add_register_req(keep);
594 be_node_set_reg_class(keep, n, cls);
597 /* creates a be_Call */
598 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
599 int n_outs, int n, ir_node *in[], ir_type *call_tp)
602 int real_n = be_pos_Call_first_arg + n;
606 NEW_ARR_A(ir_node *, real_in, real_n);
607 real_in[be_pos_Call_mem] = mem;
608 real_in[be_pos_Call_sp] = sp;
609 real_in[be_pos_Call_ptr] = ptr;
610 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
612 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
613 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
615 a->call_tp = call_tp;
619 /* Gets the call entity or NULL if this is no static call. */
620 ir_entity *be_Call_get_entity(const ir_node *call) {
621 be_call_attr_t *a = get_irn_attr(call);
622 assert(be_is_Call(call));
626 /* Sets the call entity. */
627 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
628 be_call_attr_t *a = get_irn_attr(call);
629 assert(be_is_Call(call));
633 /* Gets the call type. */
634 ir_type *be_Call_get_type(ir_node *call) {
635 be_call_attr_t *a = get_irn_attr(call);
636 assert(be_is_Call(call));
640 /* Sets the call type. */
641 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
642 be_call_attr_t *a = get_irn_attr(call);
643 assert(be_is_Call(call));
644 a->call_tp = call_tp;
647 /* Construct a new be_Return. */
648 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
649 int n, ir_node *in[])
655 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
656 init_node_attr(res, -1);
657 for(i = 0; i < n; ++i) {
658 add_irn_n(res, in[i]);
659 add_register_req(res);
662 a = get_irn_attr(res);
663 a->num_ret_vals = n_res;
668 /* Returns the number of real returns values */
669 int be_Return_get_n_rets(ir_node *ret)
671 be_return_attr_t *a = get_irn_attr(ret);
672 return a->num_ret_vals;
675 int be_Return_append_node(ir_node *ret, ir_node *node)
679 pos = add_irn_n(ret, node);
680 add_register_req(ret);
685 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
692 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
693 a = init_node_attr(irn, 1);
696 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
698 /* Set output constraint to stack register. */
699 be_node_set_reg_class(irn, 0, sp->reg_class);
700 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
701 be_node_set_irn_reg(NULL, irn, sp);
706 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
710 ir_node *in[be_pos_AddSP_last];
711 const arch_register_class_t *class;
713 in[be_pos_AddSP_old_sp] = old_sp;
714 in[be_pos_AddSP_size] = sz;
716 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
717 a = init_node_attr(irn, be_pos_AddSP_last);
719 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
720 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
722 /* Set output constraint to stack register. */
723 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
724 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
725 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
726 a->reg_data[pn_be_AddSP_sp].reg = sp;
728 class = arch_register_get_class(sp);
729 be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
734 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
738 ir_node *in[be_pos_SubSP_last];
740 in[be_pos_SubSP_old_sp] = old_sp;
741 in[be_pos_SubSP_size] = sz;
743 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
744 a = init_node_attr(irn, be_pos_SubSP_last);
746 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
747 arch_irn_flags_ignore | arch_irn_flags_modify_sp);
749 /* Set output constraint to stack register. */
750 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
751 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
752 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
753 a->reg_data[pn_be_SubSP_sp].reg = sp;
758 ir_node *be_new_SetSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl,
759 ir_node *old_sp, ir_node *op, ir_node *mem)
768 irn = new_ir_node(NULL, irg, bl, op_be_SetSP, get_irn_mode(old_sp), 3, in);
769 a = init_node_attr(irn, 3);
771 be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
773 /* Set output constraint to stack register. */
774 be_set_constr_single_reg(irn, OUT_POS(0), sp);
775 be_node_set_reg_class(irn, be_pos_AddSP_size, sp->reg_class);
776 be_node_set_reg_class(irn, be_pos_AddSP_old_sp, sp->reg_class);
781 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
786 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
787 init_node_attr(res, -1);
788 for(i = 0; i < n_outs; ++i)
789 add_register_req(res);
794 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
795 const arch_env_t *arch_env,
796 const arch_register_t *reg)
798 ir_graph *irg = get_irn_irg(regparams);
799 ir_node *block = get_nodes_block(regparams);
800 be_node_attr_t *attr = get_irn_attr(regparams);
801 const arch_register_class_t *cls = arch_register_get_class(reg);
802 ir_mode *mode = arch_register_class_mode(cls);
803 int n = ARR_LEN(attr->reg_data);
806 assert(be_is_RegParams(regparams));
807 proj = new_r_Proj(irg, block, regparams, mode, n);
808 add_register_req(regparams);
809 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
810 arch_set_irn_register(arch_env, proj, reg);
812 /* TODO decide, whether we need to set ignore/modify sp flags here? */
817 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
824 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
825 a = init_node_attr(irn, 1);
828 be_node_set_reg_class(irn, 0, cls_frame);
829 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
831 return optimize_node(irn);
834 ir_node *be_get_FrameAddr_frame(const ir_node *node) {
835 assert(be_is_FrameAddr(node));
836 return get_irn_n(node, be_pos_FrameAddr_ptr);
839 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
841 const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
845 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)
848 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
851 memcpy(&in[1], in_keep, n * sizeof(in[0]));
852 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
853 init_node_attr(irn, n + 1);
854 be_node_set_reg_class(irn, OUT_POS(0), cls);
855 be_node_set_reg_class(irn, 0, cls);
860 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)
865 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
868 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
869 return get_irn_n(cpy, be_pos_CopyKeep_op);
872 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
873 set_irn_n(cpy, be_pos_CopyKeep_op, op);
876 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
881 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
882 init_node_attr(res, -1);
883 for(i = 0; i < n; ++i) {
884 add_irn_n(res, in[i]);
885 add_register_req(res);
891 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
893 ir_graph *irg = get_irn_irg(barrier);
894 ir_node *block = get_nodes_block(barrier);
895 ir_mode *mode = get_irn_mode(node);
896 int n = add_irn_n(barrier, node);
898 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
899 add_register_req(barrier);
904 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
905 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
906 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
907 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
908 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
909 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
910 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
911 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
912 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
913 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
914 int be_is_SetSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SetSP ; }
915 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
916 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
917 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
918 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
919 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
921 int be_has_frame_entity(const ir_node *irn)
923 switch(be_get_irn_opcode(irn)) {
933 ir_entity *be_get_frame_entity(const ir_node *irn)
935 if (be_has_frame_entity(irn)) {
936 be_frame_attr_t *a = get_irn_attr(irn);
942 int be_get_frame_offset(const ir_node *irn)
944 assert(is_be_node(irn));
945 if (be_has_frame_entity(irn)) {
946 be_frame_attr_t *a = get_irn_attr(irn);
952 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
954 be_memperm_attr_t *attr = get_irn_attr(irn);
956 assert(be_is_MemPerm(irn));
957 assert(n < be_get_MemPerm_entity_arity(irn));
959 attr->in_entities[n] = ent;
962 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
964 be_memperm_attr_t *attr = get_irn_attr(irn);
966 assert(be_is_MemPerm(irn));
967 assert(n < be_get_MemPerm_entity_arity(irn));
969 return attr->in_entities[n];
972 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
974 be_memperm_attr_t *attr = get_irn_attr(irn);
976 assert(be_is_MemPerm(irn));
977 assert(n < be_get_MemPerm_entity_arity(irn));
979 attr->out_entities[n] = ent;
982 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
984 be_memperm_attr_t *attr = get_irn_attr(irn);
986 assert(be_is_MemPerm(irn));
987 assert(n < be_get_MemPerm_entity_arity(irn));
989 return attr->out_entities[n];
992 int be_get_MemPerm_entity_arity(const ir_node *irn)
994 return get_irn_arity(irn) - 1;
997 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
999 arch_register_req_t *req = get_req(node, pos);
1000 const arch_register_class_t *cls = arch_register_get_class(reg);
1001 ir_graph *irg = get_irn_irg(node);
1002 struct obstack *obst = get_irg_obstack(irg);
1003 unsigned *limited_bitset;
1005 assert(req->cls == NULL || req->cls == cls);
1006 assert(! (req->type & arch_register_req_type_limited));
1007 assert(req->limited == NULL);
1009 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1010 rbitset_set(limited_bitset, arch_register_get_index(reg));
1013 req->type |= arch_register_req_type_limited;
1014 req->limited = limited_bitset;
1017 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1019 ir_graph *irg = get_irn_irg(node);
1020 struct obstack *obst = get_irg_obstack(irg);
1021 arch_register_req_t *r = get_req(node, pos);
1023 assert(arch_register_req_is(req, limited));
1024 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1025 memcpy(r, req, sizeof(r[0]));
1026 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1029 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1031 be_req_t *bereq = get_be_req(irn, pos);
1032 bereq->flags = flags;
1035 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1037 arch_register_req_t *req = get_req(irn, pos);
1042 req->type = arch_register_req_type_none;
1043 } else if (req->type == arch_register_req_type_none) {
1044 req->type = arch_register_req_type_normal;
1048 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1050 arch_register_req_t *req = get_req(irn, pos);
1054 ir_node *be_get_IncSP_pred(ir_node *irn) {
1055 assert(be_is_IncSP(irn));
1056 return get_irn_n(irn, 0);
1059 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1060 assert(be_is_IncSP(incsp));
1061 set_irn_n(incsp, 0, pred);
1064 void be_set_IncSP_offset(ir_node *irn, int offset)
1066 be_stack_attr_t *a = get_irn_attr(irn);
1067 assert(be_is_IncSP(irn));
1071 int be_get_IncSP_offset(const ir_node *irn)
1073 be_stack_attr_t *a = get_irn_attr(irn);
1074 assert(be_is_IncSP(irn));
1078 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
1080 ir_node *bl = get_nodes_block(irn);
1081 ir_graph *irg = get_irn_irg(bl);
1082 ir_node *frame = get_irg_frame(irg);
1083 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1084 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1087 spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
1091 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)
1094 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1095 ir_graph *irg = get_irn_irg(bl);
1096 ir_node *frame = get_irg_frame(irg);
1097 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1099 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1101 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1103 if (is_Block(insert)) {
1104 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1105 sched_add_after(insert, reload);
1107 sched_add_before(insert, reload);
1115 | _ \ ___ __ _ | _ \ ___ __ _ ___
1116 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1117 | _ < __/ (_| | | _ < __/ (_| \__ \
1118 |_| \_\___|\__, | |_| \_\___|\__, |___/
1125 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1127 const be_node_attr_t *a = get_irn_attr(irn);
1129 if(out_pos >= ARR_LEN(a->reg_data)) {
1130 return arch_no_register_req;
1133 return &a->reg_data[out_pos].req.req;
1137 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1139 const be_node_attr_t *a = get_irn_attr(irn);
1141 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1142 return arch_no_register_req;
1144 return &a->reg_data[pos].in_req.req;
1147 static const arch_register_req_t *
1148 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1154 if (get_irn_mode(irn) == mode_T)
1155 return arch_no_register_req;
1157 out_pos = redir_proj((const ir_node **)&irn);
1158 assert(is_be_node(irn));
1159 return get_out_reg_req(irn, out_pos);
1160 } else if (is_be_node(irn)) {
1162 * For spills and reloads, we return "none" as requirement for frame
1163 * pointer, so every input is ok. Some backends need this (e.g. STA).
1165 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1166 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1167 return arch_no_register_req;
1169 return get_in_reg_req(irn, pos);
1172 return arch_no_register_req;
1175 const arch_register_t *
1176 be_node_get_irn_reg(const void *self, const ir_node *irn)
1181 if (get_irn_mode(irn) == mode_T)
1183 r = retrieve_reg_data(irn);
1187 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1189 redir_proj((const ir_node **) &irn);
1192 switch(be_get_irn_opcode(irn)) {
1193 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1195 XXX(Reload, reload);
1198 XXX(Return, branch);
1201 return arch_irn_class_normal;
1207 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1214 pos = OUT_POS(get_Proj_proj(node));
1215 node = skip_Proj_const(node);
1218 bereq = get_be_req(node, pos);
1220 return bereq->flags;
1223 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1226 return be_get_frame_entity(irn);
1229 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1234 assert(be_has_frame_entity(irn));
1236 a = get_irn_attr(irn);
1240 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1243 if(be_has_frame_entity(irn)) {
1244 be_frame_attr_t *a = get_irn_attr(irn);
1249 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1252 return be_is_IncSP(irn) ? be_get_IncSP_offset(irn) : 0;
1256 ___ ____ _ _ _ _ _ _
1257 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1258 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1259 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1260 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1264 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1265 be_node_get_irn_reg_req,
1266 be_node_set_irn_reg,
1267 be_node_get_irn_reg,
1270 be_node_get_frame_entity,
1271 be_node_set_frame_entity,
1272 be_node_set_frame_offset,
1273 be_node_get_sp_bias,
1274 NULL, /* get_inverse */
1275 NULL, /* get_op_estimated_cost */
1276 NULL, /* possible_memory_operand */
1277 NULL, /* perform_memory_operand */
1280 static const arch_irn_ops_t be_node_irn_ops = {
1284 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1286 redir_proj((const ir_node **) &irn);
1288 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1291 const arch_irn_handler_t be_node_irn_handler = {
1296 ____ _ _ ___ ____ _ _ _ _ _ _
1297 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1298 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1299 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1300 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1305 const arch_register_t *reg;
1306 arch_register_req_t req;
1307 arch_irn_flags_t flags;
1311 arch_irn_handler_t irn_handler;
1312 arch_irn_ops_t irn_ops;
1313 const arch_env_t *arch_env;
1317 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1318 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1321 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1324 const phi_handler_t *h;
1325 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1328 h = get_phi_handler_from_handler(handler);
1333 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1335 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1337 ir_graph *irg = get_irn_irg(phi);
1338 struct obstack *obst = get_irg_obstack(irg);
1339 attr = obstack_alloc(obst, sizeof(attr[0]));
1340 memset(attr, 0, sizeof(attr[0]));
1341 pmap_insert(handler->phi_attrs, phi, attr);
1348 * Get register class of a Phi.
1351 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1355 int n = get_irn_arity(phi);
1359 if(*visited && pset_find_ptr(*visited, phi))
1362 for(i = 0; i < n; ++i) {
1363 op = get_irn_n(phi, i);
1364 /* Matze: don't we unnecessary constraint our phis with this?
1365 * we only need to take the regclass IMO*/
1367 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1371 * The operands of that Phi were all Phis themselves.
1372 * We have to start a DFS for a non-Phi argument now.
1375 *visited = pset_new_ptr(16);
1377 pset_insert_ptr(*visited, phi);
1379 for(i = 0; i < n; ++i) {
1380 const arch_register_req_t *req;
1381 op = get_irn_n(phi, i);
1382 req = get_Phi_reg_req_recursive(h, op, visited);
1391 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1392 const ir_node *irn, int pos)
1394 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1399 if(!mode_is_datab(get_irn_mode(irn)))
1400 return arch_no_register_req;
1402 attr = get_Phi_attr(phi_handler, irn);
1404 if(attr->req.type == arch_register_req_type_none) {
1405 pset *visited = NULL;
1406 const arch_register_req_t *req;
1407 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1409 memcpy(&attr->req, req, sizeof(req[0]));
1410 assert(attr->req.cls != NULL);
1411 attr->req.type = arch_register_req_type_normal;
1420 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1421 const arch_register_req_t *req)
1423 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1424 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1427 assert(mode_is_datab(get_irn_mode(node)));
1429 attr = get_Phi_attr(handler, node);
1430 memcpy(&attr->req, req, sizeof(req[0]));
1433 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1434 arch_irn_flags_t flags)
1436 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1437 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1440 assert(mode_is_datab(get_irn_mode(node)));
1442 attr = get_Phi_attr(handler, node);
1443 attr->flags = flags;
1447 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1449 phi_handler_t *h = get_phi_handler_from_ops(self);
1450 phi_attr_t *attr = get_Phi_attr(h, irn);
1455 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1457 phi_handler_t *h = get_phi_handler_from_ops(self);
1458 phi_attr_t *attr = get_Phi_attr(h, irn);
1463 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1467 return arch_irn_class_normal;
1471 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1473 phi_handler_t *h = get_phi_handler_from_ops(self);
1474 phi_attr_t *attr = get_Phi_attr(h, irn);
1480 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1488 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1497 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1506 int phi_get_sp_bias(const void* self, const ir_node *irn)
1514 const arch_irn_ops_if_t phi_irn_ops = {
1515 phi_get_irn_reg_req,
1520 phi_get_frame_entity,
1521 phi_set_frame_entity,
1522 phi_set_frame_offset,
1524 NULL, /* get_inverse */
1525 NULL, /* get_op_estimated_cost */
1526 NULL, /* possible_memory_operand */
1527 NULL, /* perform_memory_operand */
1530 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1532 phi_handler_t *h = xmalloc(sizeof(h[0]));
1533 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1534 h->irn_ops.impl = &phi_irn_ops;
1535 h->arch_env = arch_env;
1536 h->phi_attrs = pmap_create();
1537 return (arch_irn_handler_t *) h;
1540 void be_phi_handler_free(arch_irn_handler_t *handler)
1542 phi_handler_t *h = get_phi_handler_from_handler(handler);
1543 pmap_destroy(h->phi_attrs);
1544 h->phi_attrs = NULL;
1548 void be_phi_handler_reset(arch_irn_handler_t *handler)
1550 phi_handler_t *h = get_phi_handler_from_handler(handler);
1552 pmap_destroy(h->phi_attrs);
1553 h->phi_attrs = pmap_create();
1558 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1559 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1560 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1561 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1566 * Dumps a register requirement to a file.
1568 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1569 const ir_node *node)
1571 int did_something = 0;
1573 const char *prefix = buf;
1575 snprintf(buf, sizeof(buf), "#%d ", idx);
1576 buf[sizeof(buf) - 1] = '\0';
1581 arch_register_req_format(tmp, sizeof(tmp), req, node);
1582 fprintf(f, "%s", tmp);
1591 * Dumps node register requirements to a file.
1593 static void dump_node_reqs(FILE *f, ir_node *node)
1596 be_node_attr_t *a = get_irn_attr(node);
1597 int len = ARR_LEN(a->reg_data);
1599 fprintf(f, "registers: \n");
1600 for(i = 0; i < len; ++i) {
1601 be_reg_data_t *rd = &a->reg_data[i];
1603 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1606 fprintf(f, "in requirements:\n");
1607 for(i = 0; i < len; ++i) {
1608 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1611 fprintf(f, "\nout requirements:\n");
1612 for(i = 0; i < len; ++i) {
1613 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1618 * ir_op-Operation: dump a be node to file
1620 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1622 be_node_attr_t *at = get_irn_attr(irn);
1624 assert(is_be_node(irn));
1627 case dump_node_opcode_txt:
1628 fprintf(f, get_op_name(get_irn_op(irn)));
1630 case dump_node_mode_txt:
1631 if(be_is_Perm(irn) || be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1632 fprintf(f, " %s", get_mode_name(get_irn_mode(irn)));
1635 case dump_node_nodeattr_txt:
1636 if(be_is_Call(irn)) {
1637 be_call_attr_t *a = (be_call_attr_t *) at;
1639 fprintf(f, " [%s] ", get_entity_name(a->ent));
1641 if(be_is_IncSP(irn)) {
1642 const be_stack_attr_t *attr = get_irn_generic_attr_const(irn);
1643 if(attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1644 fprintf(f, " [Setup Stackframe] ");
1645 } else if(attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1646 fprintf(f, " [Destroy Stackframe] ");
1648 fprintf(f, " [%d] ", attr->offset);
1652 case dump_node_info_txt:
1653 dump_node_reqs(f, irn);
1655 if(be_has_frame_entity(irn)) {
1656 be_frame_attr_t *a = (be_frame_attr_t *) at;
1658 int bits = get_type_size_bits(get_entity_type(a->ent));
1659 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1660 a->ent, a->offset, a->offset, bits, bits);
1665 switch(be_get_irn_opcode(irn)) {
1668 be_stack_attr_t *a = (be_stack_attr_t *) at;
1669 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1670 fprintf(f, "offset: FRAME_SIZE\n");
1671 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1672 fprintf(f, "offset: -FRAME SIZE\n");
1674 fprintf(f, "offset: %u\n", a->offset);
1679 be_call_attr_t *a = (be_call_attr_t *) at;
1682 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1688 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1689 ir_entity *in, *out;
1690 in = be_get_MemPerm_in_entity(irn, i);
1691 out = be_get_MemPerm_out_entity(irn, i);
1693 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1696 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1712 * Copies the backend specific attributes from old node to new node.
1714 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1716 be_node_attr_t *old_attr = get_irn_attr(old_node);
1717 be_node_attr_t *new_attr = get_irn_attr(new_node);
1718 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1721 assert(is_be_node(old_node));
1722 assert(is_be_node(new_node));
1724 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1725 new_attr->reg_data = NULL;
1727 if(old_attr->reg_data != NULL)
1728 len = ARR_LEN(old_attr->reg_data);
1732 if(get_irn_op(old_node)->opar == oparity_dynamic
1733 || be_is_RegParams(old_node)) {
1734 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1736 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1740 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1741 for(i = 0; i < len; ++i) {
1742 const be_reg_data_t *rd = &old_attr->reg_data[i];
1743 be_reg_data_t *newrd = &new_attr->reg_data[i];
1744 if(arch_register_req_is(&rd->req.req, limited)) {
1745 const arch_register_req_t *req = &rd->req.req;
1746 arch_register_req_t *new_req = &newrd->req.req;
1748 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1750 if(arch_register_req_is(&rd->in_req.req, limited)) {
1751 const arch_register_req_t *req = &rd->in_req.req;
1752 arch_register_req_t *new_req = &newrd->in_req.req;
1754 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1760 static const ir_op_ops be_node_op_ops = {