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 * File name: ir/be/benode.c
23 * Purpose: Backend node support for generic backend nodes.
24 * Author: Sebastian Hack
25 * Modified by: Michael Beck, Matthias Braun
28 * Copyright: (c) 1998-2007 Universität Karlsruhe
29 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
35 * @author Sebastian Hack
37 * Backend node support for generic backend nodes.
38 * This file provides Perm, Copy, Spill and Reload nodes.
54 #include "bitfiddle.h"
55 #include "raw_bitset.h"
67 #include "besched_t.h"
72 #define OUT_POS(x) (-((x) + 1))
74 /* Sometimes we want to put const nodes into get_irn_generic_attr ... */
75 #define get_irn_attr(irn) get_irn_generic_attr((ir_node *) (irn))
77 static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
80 arch_register_req_t req;
81 arch_irn_flags_t flags;
85 const arch_register_t *reg;
90 /** The generic be nodes attribute type. */
92 be_reg_data_t *reg_data;
95 /** The be_Return nodes attribute type. */
97 be_node_attr_t node_attr;
98 int num_ret_vals; /**< number of return values */
101 /** The be_Stack attribute type. */
103 be_node_attr_t node_attr;
104 int offset; /**< The offset by which the stack shall be expanded/shrinked. */
107 /** The be_Frame attribute type. */
109 be_node_attr_t node_attr;
114 /** The be_Call attribute type. */
116 be_node_attr_t node_attr;
117 ir_entity *ent; /**< The called entity if this is a static call. */
118 ir_type *call_tp; /**< The call type, copied from the original Call node. */
122 be_node_attr_t node_attr;
123 ir_entity **in_entities;
124 ir_entity **out_entities;
130 ir_op *op_be_MemPerm;
133 ir_op *op_be_CopyKeep;
140 ir_op *op_be_RegParams;
141 ir_op *op_be_StackParam;
142 ir_op *op_be_FrameAddr;
143 ir_op *op_be_FrameLoad;
144 ir_op *op_be_FrameStore;
145 ir_op *op_be_Barrier;
147 static int beo_base = -1;
149 static const ir_op_ops be_node_op_ops;
151 #define N irop_flag_none
152 #define L irop_flag_labeled
153 #define C irop_flag_commutative
154 #define X irop_flag_cfopcode
155 #define I irop_flag_ip_cfopcode
156 #define F irop_flag_fragile
157 #define Y irop_flag_forking
158 #define H irop_flag_highlevel
159 #define c irop_flag_constlike
160 #define K irop_flag_keep
161 #define M irop_flag_machine
165 * Compare two node attributes.
167 * @return zero if both attributes are identically
169 static int cmp_node_attr(be_node_attr_t *a, be_node_attr_t *b) {
172 if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
175 len = ARR_LEN(a->reg_data);
176 for (i = 0; i < len; ++i) {
177 if (a->reg_data[i].reg != b->reg_data[i].reg ||
178 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
179 memcmp(&a->reg_data[i].req, &b->reg_data[i].req, sizeof(a->reg_data[i].req)))
187 * Compare the attributes of two FrameAddr nodes.
189 * @return zero if both attributes are identically
191 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
192 be_frame_attr_t *a_attr = get_irn_attr(a);
193 be_frame_attr_t *b_attr = get_irn_attr(b);
195 if (a_attr->ent == b_attr->ent && a_attr->offset == b_attr->offset)
196 return cmp_node_attr(&a_attr->node_attr, &b_attr->node_attr);
200 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
203 be_node_attr_t *attr;
206 assert(is_be_node(node));
207 attr = get_irn_attr(node);
213 assert(idx < get_irn_arity(node));
215 assert(idx < ARR_LEN(attr->reg_data));
216 rd = &attr->reg_data[idx];
218 return pos < 0 ? &rd->req : &rd->in_req;
221 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
223 be_req_t *bereq = get_be_req(node, pos);
227 void be_node_init(void) {
228 static int inited = 0;
235 /* Acquire all needed opcodes. */
236 beo_base = get_next_ir_opcodes(beo_Last - 1);
238 op_be_Spill = new_ir_op(beo_base + beo_Spill, "be_Spill", op_pin_state_mem_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
239 op_be_Reload = new_ir_op(beo_base + beo_Reload, "be_Reload", op_pin_state_mem_pinned, N, oparity_zero, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
240 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);
241 op_be_MemPerm = new_ir_op(beo_base + beo_MemPerm, "be_MemPerm", op_pin_state_mem_pinned, N, oparity_variable, 0, sizeof(be_memperm_attr_t), &be_node_op_ops);
242 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);
243 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);
244 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);
245 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);
246 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);
247 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);
248 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);
249 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);
250 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);
251 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);
252 op_be_StackParam = new_ir_op(beo_base + beo_StackParam, "be_StackParam", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
253 op_be_FrameAddr = new_ir_op(beo_base + beo_FrameAddr, "be_FrameAddr", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
254 op_be_FrameLoad = new_ir_op(beo_base + beo_FrameLoad, "be_FrameLoad", op_pin_state_pinned, N, oparity_any, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
255 op_be_FrameStore = new_ir_op(beo_base + beo_FrameStore, "be_FrameStore", op_pin_state_pinned, N, oparity_any, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
256 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);
258 set_op_tag(op_be_Spill, &be_node_tag);
259 set_op_tag(op_be_Reload, &be_node_tag);
260 set_op_tag(op_be_Perm, &be_node_tag);
261 set_op_tag(op_be_MemPerm, &be_node_tag);
262 set_op_tag(op_be_Copy, &be_node_tag);
263 set_op_tag(op_be_Keep, &be_node_tag);
264 set_op_tag(op_be_CopyKeep, &be_node_tag);
265 set_op_tag(op_be_Call, &be_node_tag);
266 set_op_tag(op_be_Return, &be_node_tag);
267 set_op_tag(op_be_AddSP, &be_node_tag);
268 set_op_tag(op_be_SubSP, &be_node_tag);
269 set_op_tag(op_be_SetSP, &be_node_tag);
270 set_op_tag(op_be_IncSP, &be_node_tag);
271 set_op_tag(op_be_RegParams, &be_node_tag);
272 set_op_tag(op_be_StackParam, &be_node_tag);
273 set_op_tag(op_be_FrameLoad, &be_node_tag);
274 set_op_tag(op_be_FrameStore, &be_node_tag);
275 set_op_tag(op_be_FrameAddr, &be_node_tag);
276 set_op_tag(op_be_Barrier, &be_node_tag);
278 op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
282 * Initializes the generic attribute of all be nodes and return ir.
284 static void *init_node_attr(ir_node *node, int max_reg_data)
286 ir_graph *irg = get_irn_irg(node);
287 struct obstack *obst = get_irg_obstack(irg);
288 be_node_attr_t *a = get_irn_attr(node);
290 memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
292 if(max_reg_data >= 0) {
293 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
294 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
296 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
302 static void add_register_req(ir_node *node)
304 be_node_attr_t *a = get_irn_attr(node);
305 be_reg_data_t regreq;
306 memset(®req, 0, sizeof(regreq));
307 ARR_APP1(be_reg_data_t, a->reg_data, regreq);
310 int is_be_node(const ir_node *irn)
312 return get_op_tag(get_irn_op(irn)) == &be_node_tag;
315 be_opcode_t be_get_irn_opcode(const ir_node *irn)
317 return is_be_node(irn) ? get_irn_opcode(irn) - beo_base : beo_NoBeOp;
321 * Skip Proj nodes and return their Proj numbers.
323 * If *node is a Proj or Proj(Proj) node, skip it.
325 * @param node points to the node to be skipped
327 * @return 0 if *node was no Proj node, its Proj number else.
329 static int redir_proj(const ir_node **node)
331 const ir_node *n = *node;
336 *node = irn = get_Proj_pred(n);
338 assert(get_irn_mode(irn) == mode_T);
339 *node = get_Proj_pred(irn);
341 return get_Proj_proj(n);
347 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
349 be_node_attr_t *attr;
353 pos = get_Proj_proj(node);
354 node = get_Proj_pred(node);
357 assert(is_be_node(node));
358 attr = get_irn_attr(node);
359 assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
361 return &attr->reg_data[pos];
365 be_node_set_irn_reg(const void *_self, ir_node *irn, const arch_register_t *reg)
367 be_reg_data_t *r = retrieve_reg_data(irn);
371 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
372 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
380 res = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
381 a = init_node_attr(res, 2);
385 be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
386 be_node_set_reg_class(res, be_pos_Spill_val, cls);
390 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
391 ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
398 res = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
400 init_node_attr(res, 2);
401 be_node_set_reg_class(res, -1, cls);
402 be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
403 be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
407 ir_node *be_get_Reload_mem(const ir_node *irn)
409 assert(be_is_Reload(irn));
410 return get_irn_n(irn, be_pos_Reload_mem);
413 ir_node *be_get_Reload_frame(const ir_node *irn)
415 assert(be_is_Reload(irn));
416 return get_irn_n(irn, be_pos_Reload_frame);
419 ir_node *be_get_Spill_val(const ir_node *irn)
421 assert(be_is_Spill(irn));
422 return get_irn_n(irn, be_pos_Spill_val);
425 ir_node *be_get_Spill_frame(const ir_node *irn)
427 assert(be_is_Spill(irn));
428 return get_irn_n(irn, be_pos_Spill_frame);
431 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
434 ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
435 init_node_attr(irn, n);
436 for(i = 0; i < n; ++i) {
437 be_node_set_reg_class(irn, i, cls);
438 be_node_set_reg_class(irn, OUT_POS(i), cls);
444 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
447 ir_node *frame = get_irg_frame(irg);
448 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
450 const arch_register_t *sp = arch_env->isa->sp;
451 be_memperm_attr_t *attr;
454 real_in = alloca((n+1) * sizeof(real_in[0]));
456 memcpy(&real_in[1], in, n * sizeof(real_in[0]));
458 irn = new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
460 init_node_attr(irn, n + 1);
461 be_node_set_reg_class(irn, 0, sp->reg_class);
462 for(i = 0; i < n; ++i) {
463 be_node_set_reg_class(irn, i + 1, cls_frame);
464 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
467 attr = get_irn_attr(irn);
469 attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
470 memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
471 attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
472 memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
478 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
482 arch_register_req_t *req;
485 res = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
486 init_node_attr(res, 1);
487 be_node_set_reg_class(res, 0, cls);
488 be_node_set_reg_class(res, OUT_POS(0), cls);
490 req = get_req(res, OUT_POS(0));
492 req->type = arch_register_req_type_should_be_same;
498 ir_node *be_get_Copy_op(const ir_node *cpy) {
499 return get_irn_n(cpy, be_pos_Copy_op);
502 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
503 set_irn_n(cpy, be_pos_Copy_op, op);
506 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
511 res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
512 init_node_attr(res, -1);
514 for(i = 0; i < n; ++i) {
515 add_irn_n(res, in[i]);
516 add_register_req(res);
517 be_node_set_reg_class(res, i, cls);
524 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
528 assert(be_is_Keep(keep));
529 n = add_irn_n(keep, node);
530 add_register_req(keep);
531 be_node_set_reg_class(keep, n, cls);
534 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
535 int n_outs, int n, ir_node *in[], ir_type *call_tp)
538 int real_n = be_pos_Call_first_arg + n;
542 NEW_ARR_A(ir_node *, real_in, real_n);
543 real_in[be_pos_Call_mem] = mem;
544 real_in[be_pos_Call_sp] = sp;
545 real_in[be_pos_Call_ptr] = ptr;
546 memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
548 irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
549 a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
551 a->call_tp = call_tp;
555 /* Gets the call entity or NULL if this is no static call. */
556 ir_entity *be_Call_get_entity(const ir_node *call) {
557 be_call_attr_t *a = get_irn_attr(call);
558 assert(be_is_Call(call));
562 /* Sets the call entity. */
563 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
564 be_call_attr_t *a = get_irn_attr(call);
565 assert(be_is_Call(call));
569 /* Gets the call type. */
570 ir_type *be_Call_get_type(ir_node *call) {
571 be_call_attr_t *a = get_irn_attr(call);
572 assert(be_is_Call(call));
576 /* Sets the call type. */
577 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
578 be_call_attr_t *a = get_irn_attr(call);
579 assert(be_is_Call(call));
580 a->call_tp = call_tp;
583 /* Construct a new be_Return. */
584 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
585 int n, ir_node *in[])
591 res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
592 init_node_attr(res, -1);
593 for(i = 0; i < n; ++i) {
594 add_irn_n(res, in[i]);
595 add_register_req(res);
598 a = get_irn_attr(res);
599 a->num_ret_vals = n_res;
604 /* Returns the number of real returns values */
605 int be_Return_get_n_rets(ir_node *ret)
607 be_return_attr_t *a = get_irn_attr(ret);
608 return a->num_ret_vals;
611 int be_Return_append_node(ir_node *ret, ir_node *node)
615 pos = add_irn_n(ret, node);
616 add_register_req(ret);
621 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
628 irn = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
629 a = init_node_attr(irn, 1);
632 be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
634 /* Set output constraint to stack register. */
635 be_node_set_reg_class(irn, 0, sp->reg_class);
636 be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
637 be_node_set_irn_reg(NULL, irn, sp);
642 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
646 ir_node *in[be_pos_AddSP_last];
648 in[be_pos_AddSP_old_sp] = old_sp;
649 in[be_pos_AddSP_size] = sz;
651 irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
652 a = init_node_attr(irn, be_pos_AddSP_last);
654 be_node_set_flags(irn, OUT_POS(pn_be_AddSP_res), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
656 /* Set output constraint to stack register. */
657 be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
658 be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
659 be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_res), sp);
660 a->reg_data[pn_be_AddSP_res].reg = sp;
665 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
669 ir_node *in[be_pos_SubSP_last];
671 in[be_pos_SubSP_old_sp] = old_sp;
672 in[be_pos_SubSP_size] = sz;
674 irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
675 a = init_node_attr(irn, be_pos_SubSP_last);
677 be_node_set_flags(irn, OUT_POS(pn_be_SubSP_res), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
679 /* Set output constraint to stack register. */
680 be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
681 be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
682 be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_res), sp);
683 a->reg_data[pn_be_SubSP_res].reg = sp;
688 ir_node *be_new_SetSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *op, ir_node *mem)
697 irn = new_ir_node(NULL, irg, bl, op_be_SetSP, get_irn_mode(old_sp), 3, in);
698 a = init_node_attr(irn, 3);
700 be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
702 /* Set output constraint to stack register. */
703 be_set_constr_single_reg(irn, OUT_POS(0), sp);
704 be_node_set_reg_class(irn, be_pos_AddSP_size, sp->reg_class);
705 be_node_set_reg_class(irn, be_pos_AddSP_old_sp, sp->reg_class);
710 ir_node *be_new_StackParam(const arch_register_class_t *cls, const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_mode *mode, ir_node *frame_pointer, ir_entity *ent)
716 in[0] = frame_pointer;
717 irn = new_ir_node(NULL, irg, bl, op_be_StackParam, mode, 1, in);
718 a = init_node_attr(irn, 1);
721 be_node_set_reg_class(irn, 0, cls_frame);
722 be_node_set_reg_class(irn, OUT_POS(0), cls);
726 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
731 res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
732 init_node_attr(res, -1);
733 for(i = 0; i < n_outs; ++i)
734 add_register_req(res);
739 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
740 const arch_env_t *arch_env,
741 const arch_register_t *reg)
743 ir_graph *irg = get_irn_irg(regparams);
744 ir_node *block = get_nodes_block(regparams);
745 be_node_attr_t *attr = get_irn_attr(regparams);
746 const arch_register_class_t *cls = arch_register_get_class(reg);
747 ir_mode *mode = arch_register_class_mode(cls);
748 int n = ARR_LEN(attr->reg_data);
751 assert(be_is_RegParams(regparams));
752 proj = new_r_Proj(irg, block, regparams, mode, n);
753 add_register_req(regparams);
754 be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
755 arch_set_irn_register(arch_env, proj, reg);
757 /* TODO decide, whether we need to set ignore/modify sp flags here? */
762 ir_node *be_new_FrameLoad(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
763 ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_entity *ent)
771 irn = new_ir_node(NULL, irg, bl, op_be_FrameLoad, mode_T, 2, in);
772 a = init_node_attr(irn, 3);
775 be_node_set_reg_class(irn, 1, cls_frame);
776 be_node_set_reg_class(irn, OUT_POS(pn_Load_res), cls_data);
780 ir_node *be_new_FrameStore(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
781 ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_node *data, ir_entity *ent)
790 irn = new_ir_node(NULL, irg, bl, op_be_FrameStore, mode_T, 3, in);
791 a = init_node_attr(irn, 3);
794 be_node_set_reg_class(irn, 1, cls_frame);
795 be_node_set_reg_class(irn, 2, cls_data);
799 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
806 irn = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
807 a = init_node_attr(irn, 1);
810 be_node_set_reg_class(irn, 0, cls_frame);
811 be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
813 return optimize_node(irn);
816 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)
819 ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
822 memcpy(&in[1], in_keep, n * sizeof(in[0]));
823 irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
824 init_node_attr(irn, n + 1);
825 be_node_set_reg_class(irn, OUT_POS(0), cls);
826 be_node_set_reg_class(irn, 0, cls);
831 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)
836 return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
839 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
840 return get_irn_n(cpy, be_pos_CopyKeep_op);
843 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
844 set_irn_n(cpy, be_pos_CopyKeep_op, op);
847 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
852 res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
853 init_node_attr(res, -1);
854 for(i = 0; i < n; ++i) {
855 add_irn_n(res, in[i]);
856 add_register_req(res);
862 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
864 ir_graph *irg = get_irn_irg(barrier);
865 ir_node *block = get_nodes_block(barrier);
866 ir_mode *mode = get_irn_mode(node);
867 int n = add_irn_n(barrier, node);
869 ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
870 add_register_req(barrier);
875 int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
876 int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
877 int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
878 int be_is_CopyKeep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep ; }
879 int be_is_Perm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm ; }
880 int be_is_MemPerm (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm ; }
881 int be_is_Keep (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep ; }
882 int be_is_Call (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call ; }
883 int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
884 int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
885 int be_is_SetSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SetSP ; }
886 int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
887 int be_is_SubSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP ; }
888 int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
889 int be_is_StackParam (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_StackParam ; }
890 int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
891 int be_is_FrameLoad (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameLoad ; }
892 int be_is_FrameStore (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameStore ; }
893 int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
895 int be_has_frame_entity(const ir_node *irn)
897 switch(be_get_irn_opcode(irn)) {
910 ir_entity *be_get_frame_entity(const ir_node *irn)
912 if (be_has_frame_entity(irn)) {
913 be_frame_attr_t *a = get_irn_attr(irn);
919 int be_get_frame_offset(const ir_node *irn)
921 assert(is_be_node(irn));
922 if (be_has_frame_entity(irn)) {
923 be_frame_attr_t *a = get_irn_attr(irn);
929 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
931 be_memperm_attr_t *attr = get_irn_attr(irn);
933 assert(be_is_MemPerm(irn));
934 assert(n < be_get_MemPerm_entity_arity(irn));
936 attr->in_entities[n] = ent;
939 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
941 be_memperm_attr_t *attr = get_irn_attr(irn);
943 assert(be_is_MemPerm(irn));
944 assert(n < be_get_MemPerm_entity_arity(irn));
946 return attr->in_entities[n];
949 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
951 be_memperm_attr_t *attr = get_irn_attr(irn);
953 assert(be_is_MemPerm(irn));
954 assert(n < be_get_MemPerm_entity_arity(irn));
956 attr->out_entities[n] = ent;
959 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
961 be_memperm_attr_t *attr = get_irn_attr(irn);
963 assert(be_is_MemPerm(irn));
964 assert(n < be_get_MemPerm_entity_arity(irn));
966 return attr->out_entities[n];
969 int be_get_MemPerm_entity_arity(const ir_node *irn)
971 return get_irn_arity(irn) - 1;
974 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
976 arch_register_req_t *req = get_req(node, pos);
977 const arch_register_class_t *cls = arch_register_get_class(reg);
978 ir_graph *irg = get_irn_irg(node);
979 struct obstack *obst = get_irg_obstack(irg);
980 unsigned *limited_bitset;
982 assert(req->cls == NULL || req->cls == cls);
983 assert(! (req->type & arch_register_req_type_limited));
984 assert(req->limited == NULL);
986 limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
987 rbitset_set(limited_bitset, arch_register_get_index(reg));
990 req->type |= arch_register_req_type_limited;
991 req->limited = limited_bitset;
994 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
996 ir_graph *irg = get_irn_irg(node);
997 struct obstack *obst = get_irg_obstack(irg);
998 arch_register_req_t *r = get_req(node, pos);
1000 assert(arch_register_req_is(req, limited));
1001 assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1002 memcpy(r, req, sizeof(r[0]));
1003 r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1006 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1008 be_req_t *bereq = get_be_req(irn, pos);
1009 bereq->flags = flags;
1012 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1014 arch_register_req_t *req = get_req(irn, pos);
1019 req->type = arch_register_req_type_none;
1020 } else if (req->type == arch_register_req_type_none) {
1021 req->type = arch_register_req_type_normal;
1025 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1027 arch_register_req_t *req = get_req(irn, pos);
1031 ir_node *be_get_IncSP_pred(ir_node *irn) {
1032 assert(be_is_IncSP(irn));
1033 return get_irn_n(irn, 0);
1036 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1037 assert(be_is_IncSP(incsp));
1038 set_irn_n(incsp, 0, pred);
1041 ir_node *be_get_IncSP_mem(ir_node *irn) {
1042 assert(be_is_IncSP(irn));
1043 return get_irn_n(irn, 1);
1046 void be_set_IncSP_offset(ir_node *irn, int offset)
1048 be_stack_attr_t *a = get_irn_attr(irn);
1049 assert(be_is_IncSP(irn));
1053 int be_get_IncSP_offset(const ir_node *irn)
1055 be_stack_attr_t *a = get_irn_attr(irn);
1056 assert(be_is_IncSP(irn));
1060 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
1062 ir_node *bl = get_nodes_block(irn);
1063 ir_graph *irg = get_irn_irg(bl);
1064 ir_node *frame = get_irg_frame(irg);
1065 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
1066 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1069 spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
1073 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)
1076 ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
1077 ir_graph *irg = get_irn_irg(bl);
1078 ir_node *frame = get_irg_frame(irg);
1079 const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1081 assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1083 reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1085 if (is_Block(insert)) {
1086 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1087 sched_add_after(insert, reload);
1089 sched_add_before(insert, reload);
1097 | _ \ ___ __ _ | _ \ ___ __ _ ___
1098 | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1099 | _ < __/ (_| | | _ < __/ (_| \__ \
1100 |_| \_\___|\__, | |_| \_\___|\__, |___/
1107 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1109 const be_node_attr_t *a = get_irn_attr(irn);
1111 if(out_pos >= ARR_LEN(a->reg_data)) {
1112 return arch_no_register_req;
1115 return &a->reg_data[out_pos].req.req;
1119 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1121 const be_node_attr_t *a = get_irn_attr(irn);
1123 if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1124 return arch_no_register_req;
1126 return &a->reg_data[pos].in_req.req;
1129 static const arch_register_req_t *
1130 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1135 if (get_irn_mode(irn) == mode_T)
1136 return arch_no_register_req;
1138 out_pos = redir_proj((const ir_node **)&irn);
1139 assert(is_be_node(irn));
1140 return get_out_reg_req(irn, out_pos);
1141 } else if (is_be_node(irn)) {
1143 * For spills and reloads, we return "none" as requirement for frame
1144 * pointer, so every input is ok. Some backends need this (e.g. STA).
1146 if ((be_is_Spill(irn) && pos == be_pos_Spill_frame) ||
1147 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1148 return arch_no_register_req;
1150 return get_in_reg_req(irn, pos);
1153 return arch_no_register_req;
1156 const arch_register_t *
1157 be_node_get_irn_reg(const void *_self, const ir_node *irn)
1161 if (get_irn_mode(irn) == mode_T)
1163 r = retrieve_reg_data(irn);
1167 static arch_irn_class_t be_node_classify(const void *_self, const ir_node *irn)
1169 redir_proj((const ir_node **) &irn);
1171 switch(be_get_irn_opcode(irn)) {
1172 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1174 XXX(Reload, reload);
1177 XXX(Return, branch);
1178 XXX(StackParam, stackparam);
1181 return arch_irn_class_normal;
1187 static arch_irn_flags_t be_node_get_flags(const void *_self, const ir_node *node)
1193 pos = OUT_POS(get_Proj_proj(node));
1194 node = skip_Proj_const(node);
1197 bereq = get_be_req(node, pos);
1199 return bereq->flags;
1202 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1204 return be_get_frame_entity(irn);
1207 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1211 assert(be_has_frame_entity(irn));
1213 a = get_irn_attr(irn);
1217 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1219 if(be_has_frame_entity(irn)) {
1220 be_frame_attr_t *a = get_irn_attr(irn);
1225 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1227 return be_is_IncSP(irn) ? be_get_IncSP_offset(irn) : 0;
1231 ___ ____ _ _ _ _ _ _
1232 |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1233 | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1234 | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1235 |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1239 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1240 be_node_get_irn_reg_req,
1241 be_node_set_irn_reg,
1242 be_node_get_irn_reg,
1245 be_node_get_frame_entity,
1246 be_node_set_frame_entity,
1247 be_node_set_frame_offset,
1248 be_node_get_sp_bias,
1249 NULL, /* get_inverse */
1250 NULL, /* get_op_estimated_cost */
1251 NULL, /* possible_memory_operand */
1252 NULL, /* perform_memory_operand */
1255 static const arch_irn_ops_t be_node_irn_ops = {
1259 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1261 redir_proj((const ir_node **) &irn);
1262 return is_be_node(irn) ? &be_node_irn_ops : NULL;
1265 const arch_irn_handler_t be_node_irn_handler = {
1270 ____ _ _ ___ ____ _ _ _ _ _ _
1271 | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
1272 | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1273 | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
1274 |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1279 const arch_register_t *reg;
1280 arch_register_req_t req;
1281 arch_irn_flags_t flags;
1285 arch_irn_handler_t irn_handler;
1286 arch_irn_ops_t irn_ops;
1287 const arch_env_t *arch_env;
1291 #define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
1292 #define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
1295 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1298 const phi_handler_t *h;
1299 if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1302 h = get_phi_handler_from_handler(handler);
1307 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1309 phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1311 ir_graph *irg = get_irn_irg(phi);
1312 struct obstack *obst = get_irg_obstack(irg);
1313 attr = obstack_alloc(obst, sizeof(attr[0]));
1314 memset(attr, 0, sizeof(attr[0]));
1315 pmap_insert(handler->phi_attrs, phi, attr);
1322 * Get register class of a Phi.
1325 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1329 int n = get_irn_arity(phi);
1333 if(*visited && pset_find_ptr(*visited, phi))
1336 for(i = 0; i < n; ++i) {
1337 op = get_irn_n(phi, i);
1338 /* Matze: don't we unnecessary constraint our phis with this?
1339 * we only need to take the regclass IMO*/
1341 return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1345 * The operands of that Phi were all Phis themselves.
1346 * We have to start a DFS for a non-Phi argument now.
1349 *visited = pset_new_ptr(16);
1351 pset_insert_ptr(*visited, phi);
1353 for(i = 0; i < n; ++i) {
1354 const arch_register_req_t *req;
1355 op = get_irn_n(phi, i);
1356 req = get_Phi_reg_req_recursive(h, op, visited);
1365 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1366 const ir_node *irn, int pos)
1368 phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1371 if(!mode_is_datab(get_irn_mode(irn)))
1372 return arch_no_register_req;
1374 attr = get_Phi_attr(phi_handler, irn);
1376 if(attr->req.type == arch_register_req_type_none) {
1377 pset *visited = NULL;
1378 const arch_register_req_t *req;
1379 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1381 memcpy(&attr->req, req, sizeof(req[0]));
1382 assert(attr->req.cls != NULL);
1383 attr->req.type = arch_register_req_type_normal;
1392 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1393 const arch_register_req_t *req)
1395 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1396 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1399 assert(mode_is_datab(get_irn_mode(node)));
1401 attr = get_Phi_attr(handler, node);
1402 memcpy(&attr->req, req, sizeof(req[0]));
1405 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1406 arch_irn_flags_t flags)
1408 const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1409 const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1412 assert(mode_is_datab(get_irn_mode(node)));
1414 attr = get_Phi_attr(handler, node);
1415 attr->flags = flags;
1419 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1421 phi_handler_t *h = get_phi_handler_from_ops(self);
1422 phi_attr_t *attr = get_Phi_attr(h, irn);
1427 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1429 phi_handler_t *h = get_phi_handler_from_ops(self);
1430 phi_attr_t *attr = get_Phi_attr(h, irn);
1435 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1437 return arch_irn_class_normal;
1441 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1443 phi_handler_t *h = get_phi_handler_from_ops(self);
1444 phi_attr_t *attr = get_Phi_attr(h, irn);
1449 ir_entity *phi_get_frame_entity(const void *_self, const ir_node *irn)
1455 void phi_set_frame_entity(const void *_self, ir_node *irn, ir_entity *ent)
1461 void phi_set_frame_offset(const void *_self, ir_node *irn, int bias)
1467 int phi_get_sp_bias(const void* self, const ir_node *irn)
1473 const arch_irn_ops_if_t phi_irn_ops = {
1474 phi_get_irn_reg_req,
1479 phi_get_frame_entity,
1480 phi_set_frame_entity,
1481 phi_set_frame_offset,
1483 NULL, /* get_inverse */
1484 NULL, /* get_op_estimated_cost */
1485 NULL, /* possible_memory_operand */
1486 NULL, /* perform_memory_operand */
1489 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1491 phi_handler_t *h = xmalloc(sizeof(h[0]));
1492 h->irn_handler.get_irn_ops = phi_get_irn_ops;
1493 h->irn_ops.impl = &phi_irn_ops;
1494 h->arch_env = arch_env;
1495 h->phi_attrs = pmap_create();
1496 return (arch_irn_handler_t *) h;
1499 void be_phi_handler_free(arch_irn_handler_t *handler)
1501 phi_handler_t *h = (void *) handler;
1502 pmap_destroy(h->phi_attrs);
1506 void be_phi_handler_reset(arch_irn_handler_t *handler)
1508 phi_handler_t *h = get_phi_handler_from_handler(handler);
1510 pmap_destroy(h->phi_attrs);
1511 h->phi_attrs = pmap_create();
1516 | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
1517 | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1518 | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1519 |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1524 * Dumps a register requirement to a file.
1526 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1527 const ir_node *node)
1529 int did_something = 0;
1531 const char *prefix = buf;
1533 snprintf(buf, sizeof(buf), "#%d ", idx);
1534 buf[sizeof(buf) - 1] = '\0';
1539 arch_register_req_format(tmp, sizeof(tmp), req, node);
1540 fprintf(f, "%s", tmp);
1549 * Dumps node register requirements to a file.
1551 static void dump_node_reqs(FILE *f, ir_node *node)
1554 be_node_attr_t *a = get_irn_attr(node);
1555 int len = ARR_LEN(a->reg_data);
1557 fprintf(f, "registers: \n");
1558 for(i = 0; i < len; ++i) {
1559 be_reg_data_t *rd = &a->reg_data[i];
1561 fprintf(f, "#%d: %s\n", i, rd->reg->name);
1564 fprintf(f, "in requirements:\n");
1565 for(i = 0; i < len; ++i) {
1566 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1569 fprintf(f, "\nout requirements:\n");
1570 for(i = 0; i < len; ++i) {
1571 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1576 * ir_op-Operation: dump a be node to file
1578 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1580 be_node_attr_t *at = get_irn_attr(irn);
1582 assert(is_be_node(irn));
1585 case dump_node_opcode_txt:
1586 fprintf(f, get_op_name(get_irn_op(irn)));
1588 case dump_node_mode_txt:
1589 fprintf(f, get_mode_name(get_irn_mode(irn)));
1591 case dump_node_nodeattr_txt:
1593 case dump_node_info_txt:
1594 dump_node_reqs(f, irn);
1596 if(be_has_frame_entity(irn)) {
1597 be_frame_attr_t *a = (be_frame_attr_t *) at;
1599 int bits = get_type_size_bits(get_entity_type(a->ent));
1600 ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1601 a->ent, a->offset, a->offset, bits, bits);
1606 switch(be_get_irn_opcode(irn)) {
1609 be_stack_attr_t *a = (be_stack_attr_t *) at;
1610 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1611 fprintf(f, "offset: FRAME_SIZE\n");
1612 else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1613 fprintf(f, "offset: -FRAME SIZE\n");
1615 fprintf(f, "offset: %u\n", a->offset);
1620 be_call_attr_t *a = (be_call_attr_t *) at;
1623 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1629 for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1630 ir_entity *in, *out;
1631 in = be_get_MemPerm_in_entity(irn, i);
1632 out = be_get_MemPerm_out_entity(irn, i);
1634 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1637 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1653 * Copies the backend specific attributes from old node to new node.
1655 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1657 be_node_attr_t *old_attr = get_irn_attr(old_node);
1658 be_node_attr_t *new_attr = get_irn_attr(new_node);
1659 struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1662 assert(is_be_node(old_node));
1663 assert(is_be_node(new_node));
1665 memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1666 new_attr->reg_data = NULL;
1668 if(old_attr->reg_data != NULL)
1669 len = ARR_LEN(old_attr->reg_data);
1673 if(get_irn_op(old_node)->opar == oparity_dynamic
1674 || be_is_RegParams(old_node)) {
1675 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1677 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1681 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1682 for(i = 0; i < len; ++i) {
1683 const be_reg_data_t *rd = &old_attr->reg_data[i];
1684 be_reg_data_t *newrd = &new_attr->reg_data[i];
1685 if(arch_register_req_is(&rd->req.req, limited)) {
1686 const arch_register_req_t *req = &rd->req.req;
1687 arch_register_req_t *new_req = &newrd->req.req;
1689 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1691 if(arch_register_req_is(&rd->in_req.req, limited)) {
1692 const arch_register_req_t *req = &rd->in_req.req;
1693 arch_register_req_t *new_req = &newrd->in_req.req;
1695 = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1701 static const ir_op_ops be_node_op_ops = {