make sparc+arm backend completely independent from beabi
[libfirm] / ir / be / benode.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Backend node support for generic backend nodes.
23  * @author      Sebastian Hack
24  * @date        17.05.2005
25  * @version     $Id$
26  *
27  * Backend node support for generic backend nodes.
28  * This file provides Perm, Copy, Spill and Reload nodes.
29  */
30 #include "config.h"
31
32 #include <stdlib.h>
33
34 #include "obst.h"
35 #include "set.h"
36 #include "pmap.h"
37 #include "util.h"
38 #include "debug.h"
39 #include "fourcc.h"
40 #include "bitfiddle.h"
41 #include "raw_bitset.h"
42 #include "error.h"
43 #include "array_t.h"
44
45 #include "irop_t.h"
46 #include "irmode_t.h"
47 #include "irnode_t.h"
48 #include "ircons_t.h"
49 #include "irprintf.h"
50 #include "irgwalk.h"
51 #include "iropt_t.h"
52
53 #include "be_t.h"
54 #include "belive_t.h"
55 #include "besched.h"
56 #include "benode.h"
57 #include "bearch.h"
58
59 #include "beirgmod.h"
60
61 /** The be_Return nodes attribute type. */
62 typedef struct {
63         int            num_ret_vals; /**< number of return values */
64         unsigned       pop;          /**< number of bytes that should be popped */
65         int            emit_pop;     /**< if set, emit pop bytes, even if pop = 0 */
66 } be_return_attr_t;
67
68 /** The be_IncSP attribute type. */
69 typedef struct {
70         int            offset;    /**< The offset by which the stack shall be
71                                        expanded/shrinked. */
72         int            align;     /**< whether stack should be aligned after the
73                                        IncSP */
74 } be_incsp_attr_t;
75
76 /** The be_Frame attribute type. */
77 typedef struct {
78         ir_entity      *ent;
79         int             offset;
80 } be_frame_attr_t;
81
82 /** The be_Call attribute type. */
83 typedef struct {
84         ir_entity      *ent;        /**< called entity if this is a static call. */
85         unsigned        pop;
86         ir_type        *call_tp;    /**< call type, copied from the original Call */
87 } be_call_attr_t;
88
89 typedef struct {
90         ir_entity **in_entities;
91         ir_entity **out_entities;
92 } be_memperm_attr_t;
93
94 ir_op *op_be_Spill;
95 ir_op *op_be_Reload;
96 ir_op *op_be_Perm;
97 ir_op *op_be_MemPerm;
98 ir_op *op_be_Copy;
99 ir_op *op_be_Keep;
100 ir_op *op_be_CopyKeep;
101 ir_op *op_be_Call;
102 ir_op *op_be_Return;
103 ir_op *op_be_IncSP;
104 ir_op *op_be_AddSP;
105 ir_op *op_be_SubSP;
106 ir_op *op_be_Start;
107 ir_op *op_be_FrameAddr;
108 ir_op *op_be_Barrier;
109
110 static const ir_op_ops be_node_op_ops;
111
112 /**
113  * Compare the attributes of two be_FrameAddr nodes.
114  *
115  * @return zero if both nodes have identically attributes
116  */
117 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b)
118 {
119         const be_frame_attr_t *a_attr = get_irn_generic_attr_const(a);
120         const be_frame_attr_t *b_attr = get_irn_generic_attr_const(b);
121
122         if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
123                 return 1;
124
125         return be_nodes_equal(a, b);
126 }
127
128 /**
129  * Compare the attributes of two be_Return nodes.
130  *
131  * @return zero if both nodes have identically attributes
132  */
133 static int Return_cmp_attr(ir_node *a, ir_node *b)
134 {
135         const be_return_attr_t *a_attr = get_irn_generic_attr_const(a);
136         const be_return_attr_t *b_attr = get_irn_generic_attr_const(b);
137
138         if (a_attr->num_ret_vals != b_attr->num_ret_vals)
139                 return 1;
140         if (a_attr->pop != b_attr->pop)
141                 return 1;
142         if (a_attr->emit_pop != b_attr->emit_pop)
143                 return 1;
144
145         return be_nodes_equal(a, b);
146 }
147
148 /**
149  * Compare the attributes of two be_IncSP nodes.
150  *
151  * @return zero if both nodes have identically attributes
152  */
153 static int IncSP_cmp_attr(ir_node *a, ir_node *b)
154 {
155         const be_incsp_attr_t *a_attr = get_irn_generic_attr_const(a);
156         const be_incsp_attr_t *b_attr = get_irn_generic_attr_const(b);
157
158         if (a_attr->offset != b_attr->offset)
159                 return 1;
160
161         return be_nodes_equal(a, b);
162 }
163
164 /**
165  * Compare the attributes of two be_Call nodes.
166  *
167  * @return zero if both nodes have identically attributes
168  */
169 static int Call_cmp_attr(ir_node *a, ir_node *b)
170 {
171         const be_call_attr_t *a_attr = get_irn_generic_attr_const(a);
172         const be_call_attr_t *b_attr = get_irn_generic_attr_const(b);
173
174         if (a_attr->ent != b_attr->ent ||
175                 a_attr->call_tp != b_attr->call_tp)
176                 return 1;
177
178         return be_nodes_equal(a, b);
179 }
180
181 static arch_register_req_t *allocate_reg_req(const ir_node *node)
182 {
183         ir_graph       *irg  = get_irn_irg(node);
184         struct obstack *obst = be_get_be_obst(irg);
185
186         arch_register_req_t *req = obstack_alloc(obst, sizeof(*req));
187         memset(req, 0, sizeof(*req));
188         return req;
189 }
190
191 void be_set_constr_in(ir_node *node, int pos, const arch_register_req_t *req)
192 {
193         backend_info_t *info = be_get_info(node);
194         assert(pos < get_irn_arity(node));
195         info->in_reqs[pos] = req;
196 }
197
198 void be_set_constr_out(ir_node *node, int pos, const arch_register_req_t *req)
199 {
200         backend_info_t *info = be_get_info(node);
201         info->out_infos[pos].req = req;
202 }
203
204 /**
205  * Initializes the generic attribute of all be nodes and return it.
206  */
207 static void *init_node_attr(ir_node *node, int n_inputs, int n_outputs)
208 {
209         ir_graph       *irg  = get_irn_irg(node);
210         struct obstack *obst = be_get_be_obst(irg);
211         backend_info_t *info = be_get_info(node);
212         const arch_register_req_t **in_reqs;
213
214         if (n_inputs >= 0) {
215                 int i;
216                 assert(n_inputs == get_irn_arity(node));
217                 in_reqs = OALLOCN(obst, const arch_register_req_t*, n_inputs);
218                 for (i = 0; i < n_inputs; ++i) {
219                         in_reqs[i] = arch_no_register_req;
220                 }
221         } else {
222                 in_reqs = NEW_ARR_F(const arch_register_req_t*, 0);
223         }
224         info->in_reqs = in_reqs;
225
226         if (n_outputs >= 0) {
227                 int i;
228                 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_outputs);
229                 memset(info->out_infos, 0, n_outputs * sizeof(info->out_infos[0]));
230                 for (i = 0; i < n_outputs; ++i) {
231                         info->out_infos[i].req = arch_no_register_req;
232                 }
233         } else {
234                 info->out_infos = NEW_ARR_F(reg_out_info_t, 0);
235         }
236
237         return get_irn_generic_attr(node);
238 }
239
240 static void add_register_req_out(ir_node *node)
241 {
242         backend_info_t *info = be_get_info(node);
243         reg_out_info_t  out_info;
244         memset(&out_info, 0, sizeof(out_info));
245         out_info.req = arch_no_register_req;
246         ARR_APP1(reg_out_info_t, info->out_infos, out_info);
247 }
248
249 static void add_register_req_in(ir_node *node)
250 {
251         backend_info_t *info = be_get_info(node);
252         ARR_APP1(const arch_register_req_t*, info->in_reqs, arch_no_register_req);
253 }
254
255 ir_node *be_new_Spill(const arch_register_class_t *cls,
256                 const arch_register_class_t *cls_frame, ir_node *bl,
257                 ir_node *frame, ir_node *to_spill)
258 {
259         be_frame_attr_t *a;
260         ir_node         *in[2];
261         ir_node         *res;
262         ir_graph        *irg = get_Block_irg(bl);
263
264         in[0]     = frame;
265         in[1]     = to_spill;
266         res       = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
267         a         = init_node_attr(res, 2, 1);
268         a->ent    = NULL;
269         a->offset = 0;
270
271         be_node_set_reg_class_in(res, be_pos_Spill_frame, cls_frame);
272         be_node_set_reg_class_in(res, be_pos_Spill_val, cls);
273         /*
274          * For spills and reloads, we return "none" as requirement for frame
275          * pointer, so every input is ok. Some backends need this (STA).
276          * Matze: we should investigate if this is really needed, this solution
277          *        looks very hacky to me
278          */
279         be_set_constr_in(res, be_pos_Spill_frame, arch_no_register_req);
280
281         arch_set_out_register_req(res, 0, arch_no_register_req);
282
283         return res;
284 }
285
286 ir_node *be_new_Reload(const arch_register_class_t *cls,
287                 const arch_register_class_t *cls_frame, ir_node *block,
288                 ir_node *frame, ir_node *mem, ir_mode *mode)
289 {
290         ir_node  *in[2];
291         ir_node  *res;
292         ir_graph *irg = get_Block_irg(block);
293
294         in[0] = frame;
295         in[1] = mem;
296         res   = new_ir_node(NULL, irg, block, op_be_Reload, mode, 2, in);
297
298         init_node_attr(res, 2, 1);
299         be_node_set_reg_class_out(res, 0, cls);
300
301         be_node_set_reg_class_in(res, be_pos_Reload_frame, cls_frame);
302         arch_irn_set_flags(res, arch_irn_flags_rematerializable);
303
304         /*
305          * For spills and reloads, we return "none" as requirement for frame
306          * pointer, so every input is ok. Some backends need this (e.g. STA).
307          * Matze: we should investigate if this is really needed, this solution
308          *        looks very hacky to me
309          */
310         be_set_constr_in(res, be_pos_Reload_frame, arch_no_register_req);
311
312         return res;
313 }
314
315 ir_node *be_get_Reload_mem(const ir_node *irn)
316 {
317         assert(be_is_Reload(irn));
318         return get_irn_n(irn, be_pos_Reload_mem);
319 }
320
321 ir_node *be_get_Reload_frame(const ir_node *irn)
322 {
323         assert(be_is_Reload(irn));
324         return get_irn_n(irn, be_pos_Reload_frame);
325 }
326
327 ir_node *be_get_Spill_val(const ir_node *irn)
328 {
329         assert(be_is_Spill(irn));
330         return get_irn_n(irn, be_pos_Spill_val);
331 }
332
333 ir_node *be_get_Spill_frame(const ir_node *irn)
334 {
335         assert(be_is_Spill(irn));
336         return get_irn_n(irn, be_pos_Spill_frame);
337 }
338
339 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_node *block,
340                      int n, ir_node *in[])
341 {
342         int      i;
343         ir_graph *irg = get_Block_irg(block);
344
345         ir_node *irn = new_ir_node(NULL, irg, block, op_be_Perm, mode_T, n, in);
346         init_node_attr(irn, n, n);
347         for (i = 0; i < n; ++i) {
348                 be_node_set_reg_class_in(irn, i, cls);
349                 be_node_set_reg_class_out(irn, i, cls);
350         }
351
352         return irn;
353 }
354
355 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
356 {
357         int             arity      = get_irn_arity(perm);
358         const arch_register_req_t **old_in_reqs
359                 = ALLOCAN(const arch_register_req_t*, arity);
360         reg_out_info_t  *old_infos = ALLOCAN(reg_out_info_t, arity);
361         backend_info_t  *info      = be_get_info(perm);
362         ir_node        **new_in;
363         int              i;
364
365         assert(be_is_Perm(perm));
366         assert(new_size <= arity);
367
368         new_in = alloca(new_size * sizeof(*new_in));
369
370         /* save the old register data */
371         memcpy(old_in_reqs, info->in_reqs, arity * sizeof(old_in_reqs[0]));
372         memcpy(old_infos, info->out_infos, arity * sizeof(old_infos[0]));
373
374         /* compose the new in array and set the new register data directly */
375         for (i = 0; i < new_size; ++i) {
376                 int idx = map[i];
377                 new_in[i]          = get_irn_n(perm, idx);
378                 info->in_reqs[i]   = old_in_reqs[idx];
379                 info->out_infos[i] = old_infos[idx];
380         }
381
382         set_irn_in(perm, new_size, new_in);
383 }
384
385 ir_node *be_new_MemPerm(ir_node *block, int n, ir_node *in[])
386 {
387         ir_graph                     *irg       = get_Block_irg(block);
388         const arch_env_t             *arch_env  = be_get_irg_arch_env(irg);
389         ir_node                      *frame     = get_irg_frame(irg);
390         const arch_register_t        *sp        = arch_env->sp;
391         ir_node                      *irn;
392         be_memperm_attr_t            *attr;
393         ir_node                     **real_in;
394
395         real_in = ALLOCAN(ir_node*, n + 1);
396         real_in[0] = frame;
397         memcpy(&real_in[1], in, n * sizeof(real_in[0]));
398
399         irn = new_ir_node(NULL, irg, block, op_be_MemPerm, mode_T, n+1, real_in);
400
401         init_node_attr(irn, n + 1, n);
402         be_node_set_reg_class_in(irn, 0, sp->reg_class);
403
404         attr               = get_irn_generic_attr(irn);
405         attr->in_entities  = OALLOCNZ(irg->obst, ir_entity*, n);
406         attr->out_entities = OALLOCNZ(irg->obst, ir_entity*, n);
407
408         return irn;
409 }
410
411 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_node *bl, ir_node *op)
412 {
413         ir_node *in[1];
414         ir_node *res;
415         arch_register_req_t *req;
416         ir_graph *irg = get_Block_irg(bl);
417
418         in[0] = op;
419         res   = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
420         init_node_attr(res, 1, 1);
421         be_node_set_reg_class_in(res, 0, cls);
422         be_node_set_reg_class_out(res, 0, cls);
423
424         req = allocate_reg_req(res);
425         req->cls        = cls;
426         req->type       = arch_register_req_type_should_be_same;
427         req->other_same = 1U << 0;
428         req->width      = 1;
429         be_set_constr_out(res, 0, req);
430
431         return res;
432 }
433
434 ir_node *be_get_Copy_op(const ir_node *cpy)
435 {
436         return get_irn_n(cpy, be_pos_Copy_op);
437 }
438
439 void be_set_Copy_op(ir_node *cpy, ir_node *op)
440 {
441         set_irn_n(cpy, be_pos_Copy_op, op);
442 }
443
444 ir_node *be_new_Keep(ir_node *block, int n, ir_node *in[])
445 {
446         int i;
447         ir_node *res;
448         ir_graph *irg = get_Block_irg(block);
449
450         res = new_ir_node(NULL, irg, block, op_be_Keep, mode_ANY, -1, NULL);
451         init_node_attr(res, -1, 1);
452
453         for (i = 0; i < n; ++i) {
454                 add_irn_n(res, in[i]);
455                 add_register_req_in(res);
456         }
457         keep_alive(res);
458
459         return res;
460 }
461
462 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
463 {
464         int n;
465
466         assert(be_is_Keep(keep));
467         n = add_irn_n(keep, node);
468         add_register_req_in(keep);
469         be_node_set_reg_class_in(keep, n, cls);
470 }
471
472 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem,
473                 ir_node *sp, ir_node *ptr, int n_outs, int n, ir_node *in[],
474                 ir_type *call_tp)
475 {
476         be_call_attr_t *a;
477         int real_n = be_pos_Call_first_arg + n;
478         ir_node *irn;
479         ir_node **real_in;
480
481         NEW_ARR_A(ir_node *, real_in, real_n);
482         real_in[be_pos_Call_mem] = mem;
483         real_in[be_pos_Call_sp]  = sp;
484         real_in[be_pos_Call_ptr] = ptr;
485         memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
486
487         irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
488         a = init_node_attr(irn, real_n, n_outs);
489         a->ent     = NULL;
490         a->call_tp = call_tp;
491         a->pop     = 0;
492         return irn;
493 }
494
495 ir_entity *be_Call_get_entity(const ir_node *call)
496 {
497         const be_call_attr_t *a = get_irn_generic_attr_const(call);
498         assert(be_is_Call(call));
499         return a->ent;
500 }
501
502 void be_Call_set_entity(ir_node *call, ir_entity *ent)
503 {
504         be_call_attr_t *a = get_irn_generic_attr(call);
505         assert(be_is_Call(call));
506         a->ent = ent;
507 }
508
509 ir_type *be_Call_get_type(ir_node *call)
510 {
511         const be_call_attr_t *a = get_irn_generic_attr_const(call);
512         assert(be_is_Call(call));
513         return a->call_tp;
514 }
515
516 void be_Call_set_type(ir_node *call, ir_type *call_tp)
517 {
518         be_call_attr_t *a = get_irn_generic_attr(call);
519         assert(be_is_Call(call));
520         a->call_tp = call_tp;
521 }
522
523 void be_Call_set_pop(ir_node *call, unsigned pop)
524 {
525         be_call_attr_t *a = get_irn_generic_attr(call);
526         a->pop = pop;
527 }
528
529 unsigned be_Call_get_pop(const ir_node *call)
530 {
531         const be_call_attr_t *a = get_irn_generic_attr_const(call);
532         return a->pop;
533 }
534
535 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
536                        unsigned pop, int n, ir_node *in[])
537 {
538         be_return_attr_t *a;
539         ir_node *res;
540         int i;
541
542         res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
543         init_node_attr(res, -1, 1);
544         for (i = 0; i < n; ++i) {
545                 add_irn_n(res, in[i]);
546                 add_register_req_in(res);
547         }
548         be_set_constr_out(res, 0, arch_no_register_req);
549
550         a = get_irn_generic_attr(res);
551         a->num_ret_vals = n_res;
552         a->pop          = pop;
553         a->emit_pop     = 0;
554
555         return res;
556 }
557
558 int be_Return_get_n_rets(const ir_node *ret)
559 {
560         const be_return_attr_t *a = get_irn_generic_attr_const(ret);
561         return a->num_ret_vals;
562 }
563
564 unsigned be_Return_get_pop(const ir_node *ret)
565 {
566         const be_return_attr_t *a = get_irn_generic_attr_const(ret);
567         return a->pop;
568 }
569
570 int be_Return_get_emit_pop(const ir_node *ret)
571 {
572         const be_return_attr_t *a = get_irn_generic_attr_const(ret);
573         return a->emit_pop;
574 }
575
576 void be_Return_set_emit_pop(ir_node *ret, int emit_pop)
577 {
578         be_return_attr_t *a = get_irn_generic_attr(ret);
579         a->emit_pop = emit_pop;
580 }
581
582 int be_Return_append_node(ir_node *ret, ir_node *node)
583 {
584         int pos;
585
586         pos = add_irn_n(ret, node);
587         add_register_req_in(ret);
588
589         return pos;
590 }
591
592 ir_node *be_new_IncSP(const arch_register_t *sp, ir_node *bl,
593                       ir_node *old_sp, int offset, int align)
594 {
595         be_incsp_attr_t *a;
596         ir_node *irn;
597         ir_node *in[1];
598         ir_graph *irg = get_Block_irg(bl);
599
600         in[0]     = old_sp;
601         irn       = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode,
602                                 sizeof(in) / sizeof(in[0]), in);
603         a         = init_node_attr(irn, 1, 1);
604         a->offset = offset;
605         a->align  = align;
606
607         /* Set output constraint to stack register. */
608         be_node_set_reg_class_in(irn, 0, sp->reg_class);
609         be_set_constr_single_reg_out(irn, 0, sp, arch_register_req_type_produces_sp);
610
611         return irn;
612 }
613
614 ir_node *be_new_AddSP(const arch_register_t *sp, ir_node *bl, ir_node *old_sp,
615                 ir_node *sz)
616 {
617         ir_node *irn;
618         ir_node *in[be_pos_AddSP_last];
619         const arch_register_class_t *cls;
620         ir_graph *irg;
621
622         in[be_pos_AddSP_old_sp] = old_sp;
623         in[be_pos_AddSP_size]   = sz;
624
625         irg = get_Block_irg(bl);
626         irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
627         init_node_attr(irn, be_pos_AddSP_last, pn_be_AddSP_last);
628
629         /* Set output constraint to stack register. */
630         be_set_constr_single_reg_in(irn, be_pos_AddSP_old_sp, sp, 0);
631         be_node_set_reg_class_in(irn, be_pos_AddSP_size, arch_register_get_class(sp));
632         be_set_constr_single_reg_out(irn, pn_be_AddSP_sp, sp,
633                                      arch_register_req_type_produces_sp);
634
635         cls = arch_register_get_class(sp);
636
637         return irn;
638 }
639
640 ir_node *be_new_SubSP(const arch_register_t *sp, ir_node *bl, ir_node *old_sp, ir_node *sz)
641 {
642         ir_node *irn;
643         ir_node *in[be_pos_SubSP_last];
644         ir_graph *irg;
645
646         in[be_pos_SubSP_old_sp] = old_sp;
647         in[be_pos_SubSP_size]   = sz;
648
649         irg = get_Block_irg(bl);
650         irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
651         init_node_attr(irn, be_pos_SubSP_last, pn_be_SubSP_last);
652
653         /* Set output constraint to stack register. */
654         be_set_constr_single_reg_in(irn, be_pos_SubSP_old_sp, sp, 0);
655         be_node_set_reg_class_in(irn, be_pos_SubSP_size, arch_register_get_class(sp));
656         be_set_constr_single_reg_out(irn, pn_be_SubSP_sp, sp, arch_register_req_type_produces_sp);
657
658         return irn;
659 }
660
661 ir_node *be_new_Start(dbg_info *dbgi, ir_node *bl, int n_outs)
662 {
663         ir_node *res;
664         int i;
665         ir_graph *irg = get_Block_irg(bl);
666
667         res = new_ir_node(dbgi, irg, bl, op_be_Start, mode_T, 0, NULL);
668         init_node_attr(res, 0, -1);
669         for (i = 0; i < n_outs; ++i) {
670                 add_register_req_out(res);
671         }
672
673         return res;
674 }
675
676 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_node *bl, ir_node *frame, ir_entity *ent)
677 {
678         be_frame_attr_t *a;
679         ir_node *irn;
680         ir_node *in[1];
681         ir_graph *irg = get_Block_irg(bl);
682
683         in[0]  = frame;
684         irn    = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
685         a      = init_node_attr(irn, 1, 1);
686         a->ent = ent;
687         a->offset = 0;
688         be_node_set_reg_class_in(irn, 0, cls_frame);
689         be_node_set_reg_class_out(irn, 0, cls_frame);
690
691         return optimize_node(irn);
692 }
693
694 ir_node *be_get_FrameAddr_frame(const ir_node *node)
695 {
696         assert(be_is_FrameAddr(node));
697         return get_irn_n(node, be_pos_FrameAddr_ptr);
698 }
699
700 ir_entity *be_get_FrameAddr_entity(const ir_node *node)
701 {
702         const be_frame_attr_t *attr = get_irn_generic_attr_const(node);
703         return attr->ent;
704 }
705
706 ir_node *be_new_CopyKeep(const arch_register_class_t *cls, ir_node *bl, ir_node *src, int n, ir_node *in_keep[], ir_mode *mode)
707 {
708         ir_node  *irn;
709         ir_node **in = ALLOCAN(ir_node*, n + 1);
710         ir_graph *irg = get_Block_irg(bl);
711
712         in[0] = src;
713         memcpy(&in[1], in_keep, n * sizeof(in[0]));
714         irn   = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
715         init_node_attr(irn, n + 1, 1);
716         be_node_set_reg_class_in(irn, 0, cls);
717         be_node_set_reg_class_out(irn, 0, cls);
718
719         return irn;
720 }
721
722 ir_node *be_new_CopyKeep_single(const arch_register_class_t *cls, ir_node *bl, ir_node *src, ir_node *keep, ir_mode *mode)
723 {
724         return be_new_CopyKeep(cls, bl, src, 1, &keep, mode);
725 }
726
727 ir_node *be_get_CopyKeep_op(const ir_node *cpy)
728 {
729         return get_irn_n(cpy, be_pos_CopyKeep_op);
730 }
731
732 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op)
733 {
734         set_irn_n(cpy, be_pos_CopyKeep_op, op);
735 }
736
737 ir_node *be_new_Barrier(ir_node *bl, int n, ir_node *in[])
738 {
739         ir_node *res;
740         int i;
741         ir_graph *irg = get_Block_irg(bl);
742
743         res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
744         init_node_attr(res, -1, -1);
745         for (i = 0; i < n; ++i) {
746                 add_irn_n(res, in[i]);
747                 add_register_req_in(res);
748                 add_register_req_out(res);
749         }
750
751         return res;
752 }
753
754 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
755 {
756         ir_mode *mode = get_irn_mode(node);
757         int n = add_irn_n(barrier, node);
758
759         ir_node *proj = new_r_Proj(barrier, mode, n);
760         add_register_req_in(barrier);
761         add_register_req_out(barrier);
762
763         return proj;
764 }
765
766 static bool be_has_frame_entity(const ir_node *irn)
767 {
768         switch (get_irn_opcode(irn)) {
769         case beo_Spill:
770         case beo_Reload:
771         case beo_FrameAddr:
772                 return true;
773         default:
774                 return false;
775         }
776 }
777
778 ir_entity *be_get_frame_entity(const ir_node *irn)
779 {
780         if (be_has_frame_entity(irn)) {
781                 const be_frame_attr_t *a = get_irn_generic_attr_const(irn);
782                 return a->ent;
783         }
784         return NULL;
785 }
786
787 int be_get_frame_offset(const ir_node *irn)
788 {
789         assert(is_be_node(irn));
790         if (be_has_frame_entity(irn)) {
791                 const be_frame_attr_t *a = get_irn_generic_attr_const(irn);
792                 return a->offset;
793         }
794         return 0;
795 }
796
797 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
798 {
799         const be_memperm_attr_t *attr = get_irn_generic_attr_const(irn);
800
801         assert(be_is_MemPerm(irn));
802         assert(n < be_get_MemPerm_entity_arity(irn));
803
804         attr->in_entities[n] = ent;
805 }
806
807 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
808 {
809         const be_memperm_attr_t *attr = get_irn_generic_attr_const(irn);
810
811         assert(be_is_MemPerm(irn));
812         assert(n < be_get_MemPerm_entity_arity(irn));
813
814         return attr->in_entities[n];
815 }
816
817 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
818 {
819         const be_memperm_attr_t *attr = get_irn_generic_attr_const(irn);
820
821         assert(be_is_MemPerm(irn));
822         assert(n < be_get_MemPerm_entity_arity(irn));
823
824         attr->out_entities[n] = ent;
825 }
826
827 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
828 {
829         const be_memperm_attr_t *attr = get_irn_generic_attr_const(irn);
830
831         assert(be_is_MemPerm(irn));
832         assert(n < be_get_MemPerm_entity_arity(irn));
833
834         return attr->out_entities[n];
835 }
836
837 int be_get_MemPerm_entity_arity(const ir_node *irn)
838 {
839         return get_irn_arity(irn) - 1;
840 }
841
842 const arch_register_req_t *be_create_reg_req(struct obstack *obst,
843                 const arch_register_t *reg, arch_register_req_type_t additional_types)
844 {
845         arch_register_req_t         *req = obstack_alloc(obst, sizeof(*req));
846         const arch_register_class_t *cls = arch_register_get_class(reg);
847         unsigned                    *limited_bitset;
848
849         limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
850         rbitset_set(limited_bitset, arch_register_get_index(reg));
851
852         req->type    = arch_register_req_type_limited | additional_types;
853         req->cls     = cls;
854         req->limited = limited_bitset;
855         req->width   = 1;
856         return req;
857 }
858
859 void be_set_constr_single_reg_in(ir_node *node, int pos,
860                 const arch_register_t *reg, arch_register_req_type_t additional_types)
861 {
862         const arch_register_req_t *req;
863
864         if (additional_types == 0) {
865                 req = reg->single_req;
866         } else {
867                 ir_graph       *irg  = get_irn_irg(node);
868                 struct obstack *obst = be_get_be_obst(irg);
869                 req = be_create_reg_req(obst, reg, additional_types);
870         }
871         be_set_constr_in(node, pos, req);
872 }
873
874 void be_set_constr_single_reg_out(ir_node *node, int pos,
875                 const arch_register_t *reg, arch_register_req_type_t additional_types)
876 {
877         ir_graph                  *irg  = get_irn_irg(node);
878         be_irg_t                  *birg = be_birg_from_irg(irg);
879         const arch_register_req_t *req;
880
881         /* if we have an ignore register, add ignore flag and just assign it */
882         if (!rbitset_is_set(birg->allocatable_regs, reg->global_index)) {
883                 additional_types |= arch_register_req_type_ignore;
884         }
885
886         if (additional_types == 0) {
887                 req = reg->single_req;
888         } else {
889                 ir_graph       *irg  = get_irn_irg(node);
890                 struct obstack *obst = be_get_be_obst(irg);
891                 req = be_create_reg_req(obst, reg, additional_types);
892         }
893
894         arch_irn_set_register(node, pos, reg);
895         be_set_constr_out(node, pos, req);
896 }
897
898 void be_node_set_reg_class_in(ir_node *irn, int pos,
899                               const arch_register_class_t *cls)
900 {
901         be_set_constr_in(irn, pos, cls->class_req);
902 }
903
904 void be_node_set_reg_class_out(ir_node *irn, int pos,
905                                const arch_register_class_t *cls)
906 {
907         be_set_constr_out(irn, pos, cls->class_req);
908 }
909
910 ir_node *be_get_IncSP_pred(ir_node *irn)
911 {
912         assert(be_is_IncSP(irn));
913         return get_irn_n(irn, 0);
914 }
915
916 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred)
917 {
918         assert(be_is_IncSP(incsp));
919         set_irn_n(incsp, 0, pred);
920 }
921
922 void be_set_IncSP_offset(ir_node *irn, int offset)
923 {
924         be_incsp_attr_t *a = get_irn_generic_attr(irn);
925         assert(be_is_IncSP(irn));
926         a->offset = offset;
927 }
928
929 int be_get_IncSP_offset(const ir_node *irn)
930 {
931         const be_incsp_attr_t *a = get_irn_generic_attr_const(irn);
932         assert(be_is_IncSP(irn));
933         return a->offset;
934 }
935
936 int be_get_IncSP_align(const ir_node *irn)
937 {
938         const be_incsp_attr_t *a = get_irn_generic_attr_const(irn);
939         assert(be_is_IncSP(irn));
940         return a->align;
941 }
942
943 ir_node *be_spill(ir_node *block, ir_node *irn)
944 {
945         ir_graph                    *irg       = get_Block_irg(block);
946         ir_node                     *frame     = get_irg_frame(irg);
947         const arch_register_class_t *cls       = arch_get_irn_reg_class_out(irn);
948         const arch_register_class_t *cls_frame = arch_get_irn_reg_class_out(frame);
949         ir_node                     *spill;
950
951         spill = be_new_Spill(cls, cls_frame, block, frame, irn);
952         return spill;
953 }
954
955 ir_node *be_reload(const arch_register_class_t *cls, ir_node *insert, ir_mode *mode, ir_node *spill)
956 {
957         ir_node  *reload;
958         ir_node  *bl    = is_Block(insert) ? insert : get_nodes_block(insert);
959         ir_graph *irg   = get_Block_irg(bl);
960         ir_node  *frame = get_irg_frame(irg);
961         const arch_register_class_t *cls_frame = arch_get_irn_reg_class_out(frame);
962
963         assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
964
965         reload = be_new_Reload(cls, cls_frame, bl, frame, spill, mode);
966
967         if (is_Block(insert)) {
968                 insert = sched_skip(insert, 0, sched_skip_cf_predicator, NULL);
969                 sched_add_after(insert, reload);
970         } else {
971                 sched_add_before(insert, reload);
972         }
973
974         return reload;
975 }
976
977
978 static arch_irn_class_t be_node_classify(const ir_node *irn)
979 {
980         switch (get_irn_opcode(irn)) {
981                 case beo_Spill:  return arch_irn_class_spill;
982                 case beo_Reload: return arch_irn_class_reload;
983                 case beo_Perm:   return arch_irn_class_perm;
984                 case beo_Copy:   return arch_irn_class_copy;
985                 default:         return 0;
986         }
987 }
988
989 static ir_entity *be_node_get_frame_entity(const ir_node *irn)
990 {
991         return be_get_frame_entity(irn);
992 }
993
994 void be_node_set_frame_entity(ir_node *irn, ir_entity *ent)
995 {
996         be_frame_attr_t *a;
997
998         assert(be_has_frame_entity(irn));
999
1000         a = get_irn_generic_attr(irn);
1001         a->ent = ent;
1002 }
1003
1004 static void be_node_set_frame_offset(ir_node *irn, int offset)
1005 {
1006         be_frame_attr_t *a;
1007
1008         if (!be_has_frame_entity(irn))
1009                 return;
1010
1011         a = get_irn_generic_attr(irn);
1012         a->offset = offset;
1013 }
1014
1015 static int be_node_get_sp_bias(const ir_node *irn)
1016 {
1017         if (be_is_IncSP(irn))
1018                 return be_get_IncSP_offset(irn);
1019         if (be_is_Call(irn))
1020                 return -(int)be_Call_get_pop(irn);
1021
1022         return 0;
1023 }
1024
1025
1026
1027 /* for be nodes */
1028 static const arch_irn_ops_t be_node_irn_ops = {
1029         be_node_classify,
1030         be_node_get_frame_entity,
1031         be_node_set_frame_offset,
1032         be_node_get_sp_bias,
1033         NULL,    /* get_inverse             */
1034         NULL,    /* get_op_estimated_cost   */
1035         NULL,    /* possible_memory_operand */
1036         NULL,    /* perform_memory_operand  */
1037 };
1038
1039 static arch_irn_class_t dummy_classify(const ir_node *node)
1040 {
1041         (void) node;
1042         return 0;
1043 }
1044
1045 static ir_entity* dummy_get_frame_entity(const ir_node *node)
1046 {
1047         (void) node;
1048         return NULL;
1049 }
1050
1051 static void dummy_set_frame_offset(ir_node *node, int bias)
1052 {
1053         (void) node;
1054         (void) bias;
1055         panic("dummy_set_frame_offset() should not be called");
1056 }
1057
1058 static int dummy_get_sp_bias(const ir_node *node)
1059 {
1060         (void) node;
1061         return 0;
1062 }
1063
1064 /* for "middleend" nodes */
1065 static const arch_irn_ops_t dummy_be_irn_ops = {
1066         dummy_classify,
1067         dummy_get_frame_entity,
1068         dummy_set_frame_offset,
1069         dummy_get_sp_bias,
1070         NULL,      /* get_inverse           */
1071         NULL,      /* get_op_estimated_cost */
1072         NULL,      /* possible_memory_operand */
1073         NULL,      /* perform_memory_operand */
1074 };
1075
1076
1077
1078 ir_node *be_new_Phi(ir_node *block, int n_ins, ir_node **ins, ir_mode *mode,
1079                     const arch_register_class_t *cls)
1080 {
1081         const arch_register_req_t *req;
1082         ir_graph       *irg  = get_irn_irg(block);
1083         struct obstack *obst = be_get_be_obst(irg);
1084         backend_info_t *info;
1085         int             i;
1086
1087         ir_node *phi = new_r_Phi(block, n_ins, ins, mode);
1088         info = be_get_info(phi);
1089         info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
1090         memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
1091         info->in_reqs = OALLOCN(obst, const arch_register_req_t*, n_ins);
1092
1093         if (cls == NULL) {
1094                 req = arch_no_register_req;
1095         } else {
1096                 req = cls->class_req;
1097         }
1098         info->out_infos[0].req = req;
1099         for (i = 0; i < n_ins; ++i) {
1100                 info->in_reqs[i] = req;
1101         }
1102
1103         return phi;
1104 }
1105
1106 void be_set_phi_reg_req(ir_node *node, const arch_register_req_t *req)
1107 {
1108         int arity = get_irn_arity(node);
1109         int i;
1110
1111         backend_info_t *info = be_get_info(node);
1112         info->out_infos[0].req = req;
1113         for (i = 0; i < arity; ++i) {
1114                 info->in_reqs[i] = req;
1115         }
1116
1117         assert(mode_is_datab(get_irn_mode(node)));
1118 }
1119
1120 void be_dump_phi_reg_reqs(FILE *F, ir_node *node, dump_reason_t reason)
1121 {
1122         switch (reason) {
1123         case dump_node_opcode_txt:
1124                 fputs(get_op_name(get_irn_op(node)), F);
1125                 break;
1126         case dump_node_mode_txt:
1127                 fprintf(F, "%s", get_mode_name(get_irn_mode(node)));
1128                 break;
1129         case dump_node_nodeattr_txt:
1130                 break;
1131         case dump_node_info_txt:
1132         {
1133                 backend_info_t *info = be_get_info(node);
1134                 if (info != NULL && info->out_infos[0].req != NULL) {
1135                         arch_dump_reqs_and_registers(F, node);
1136                 }
1137                 break;
1138         }
1139
1140         default:
1141                 break;
1142         }
1143 }
1144
1145 static const arch_irn_ops_t phi_irn_ops = {
1146         dummy_classify,
1147         dummy_get_frame_entity,
1148         dummy_set_frame_offset,
1149         dummy_get_sp_bias,
1150         NULL,    /* get_inverse             */
1151         NULL,    /* get_op_estimated_cost   */
1152         NULL,    /* possible_memory_operand */
1153         NULL,    /* perform_memory_operand  */
1154 };
1155
1156
1157
1158 /**
1159  * ir_op-Operation: dump a be node to file
1160  */
1161 static void dump_node(FILE *f, ir_node *irn, dump_reason_t reason)
1162 {
1163         assert(is_be_node(irn));
1164
1165         switch (reason) {
1166                 case dump_node_opcode_txt:
1167                         fputs(get_op_name(get_irn_op(irn)), f);
1168                         break;
1169                 case dump_node_mode_txt:
1170                         if (be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1171                                 fprintf(f, "%s", get_mode_name(get_irn_mode(irn)));
1172                         }
1173                         break;
1174                 case dump_node_nodeattr_txt:
1175                         if (be_is_Call(irn)) {
1176                                 const be_call_attr_t *a = get_irn_generic_attr_const(irn);
1177                                 if (a->ent)
1178                                         fprintf(f, " [%s] ", get_entity_name(a->ent));
1179                         }
1180                         if (be_is_IncSP(irn)) {
1181                                 const be_incsp_attr_t *attr = get_irn_generic_attr_const(irn);
1182                                 if (attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1183                                         fprintf(f, " [Setup Stackframe] ");
1184                                 } else if (attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1185                                         fprintf(f, " [Destroy Stackframe] ");
1186                                 } else {
1187                                         fprintf(f, " [%d] ", attr->offset);
1188                                 }
1189                         }
1190                         break;
1191                 case dump_node_info_txt:
1192                         arch_dump_reqs_and_registers(f, irn);
1193
1194                         if (be_has_frame_entity(irn)) {
1195                                 const be_frame_attr_t *a = get_irn_generic_attr_const(irn);
1196                                 if (a->ent) {
1197                                         unsigned size = get_type_size_bytes(get_entity_type(a->ent));
1198                                         ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
1199                                           a->ent, a->offset, a->offset, size, size);
1200                                 }
1201
1202                         }
1203
1204                         switch (get_irn_opcode(irn)) {
1205                         case beo_IncSP: {
1206                                 const be_incsp_attr_t *a = get_irn_generic_attr_const(irn);
1207                                 fprintf(f, "align: %d\n", a->align);
1208                                 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1209                                         fprintf(f, "offset: FRAME_SIZE\n");
1210                                 else if (a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1211                                         fprintf(f, "offset: -FRAME SIZE\n");
1212                                 else
1213                                         fprintf(f, "offset: %d\n", a->offset);
1214                                 break;
1215                         }
1216                         case beo_Call: {
1217                                 const be_call_attr_t *a = get_irn_generic_attr_const(irn);
1218
1219                                 if (a->ent)
1220                                         fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1221                                 break;
1222                         }
1223                         case beo_MemPerm: {
1224                                 int i;
1225                                 for (i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1226                                         ir_entity *in, *out;
1227                                         in = be_get_MemPerm_in_entity(irn, i);
1228                                         out = be_get_MemPerm_out_entity(irn, i);
1229                                         if (in) {
1230                                                 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1231                                         }
1232                                         if (out) {
1233                                                 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1234                                         }
1235                                 }
1236                                 break;
1237                         }
1238
1239                         default:
1240                                 break;
1241                         }
1242         }
1243 }
1244
1245 /**
1246  * ir_op-Operation:
1247  * Copies the backend specific attributes from old node to new node.
1248  */
1249 static void copy_attr(ir_graph *irg, const ir_node *old_node, ir_node *new_node)
1250 {
1251         const void     *old_attr = get_irn_generic_attr_const(old_node);
1252         void           *new_attr = get_irn_generic_attr(new_node);
1253         struct obstack *obst     = be_get_be_obst(irg);
1254         backend_info_t *old_info = be_get_info(old_node);
1255         backend_info_t *new_info = be_get_info(new_node);
1256
1257         assert(is_be_node(old_node));
1258         assert(is_be_node(new_node));
1259
1260         memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1261
1262         if (old_info->out_infos != NULL) {
1263                 unsigned n_outs = ARR_LEN(old_info->out_infos);
1264                 /* need dyanmic out infos? */
1265                 if (be_is_Barrier(new_node) || be_is_Perm(new_node)) {
1266                         new_info->out_infos = NEW_ARR_F(reg_out_info_t, n_outs);
1267                 } else {
1268                         new_info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_outs);
1269                 }
1270                 memcpy(new_info->out_infos, old_info->out_infos,
1271                            n_outs * sizeof(new_info->out_infos[0]));
1272         } else {
1273                 new_info->out_infos = NULL;
1274         }
1275
1276         /* input infos */
1277         if (old_info->in_reqs != NULL) {
1278                 unsigned n_ins = get_irn_arity(old_node);
1279                 /* need dynamic in infos? */
1280                 if (get_irn_op(old_node)->opar == oparity_dynamic) {
1281                         new_info->in_reqs = NEW_ARR_F(const arch_register_req_t*, n_ins);
1282                 } else {
1283                         new_info->in_reqs = OALLOCN(obst,const arch_register_req_t*, n_ins);
1284                 }
1285                 memcpy(new_info->in_reqs, old_info->in_reqs,
1286                        n_ins * sizeof(new_info->in_reqs[0]));
1287         } else {
1288                 new_info->in_reqs = NULL;
1289         }
1290 }
1291
1292 static const ir_op_ops be_node_op_ops = {
1293         firm_default_hash,
1294         NULL,
1295         NULL,
1296         NULL,
1297         NULL,
1298         NULL,
1299         NULL,
1300         NULL,
1301         NULL,
1302         copy_attr,
1303         NULL,
1304         NULL,
1305         NULL,
1306         NULL,
1307         dump_node,
1308         NULL,
1309         &be_node_irn_ops
1310 };
1311
1312 int is_be_node(const ir_node *irn)
1313 {
1314         return get_op_ops(get_irn_op(irn))->be_ops == &be_node_irn_ops;
1315 }
1316
1317 void be_init_op(void)
1318 {
1319         ir_opcode opc;
1320
1321         /* Acquire all needed opcodes. */
1322         op_be_Spill     = new_ir_op(beo_Spill,     "be_Spill",     op_pin_state_pinned, irop_flag_none,                          oparity_unary,    0, sizeof(be_frame_attr_t),   &be_node_op_ops);
1323         op_be_Reload    = new_ir_op(beo_Reload,    "be_Reload",    op_pin_state_pinned, irop_flag_none,                          oparity_zero,     0, sizeof(be_frame_attr_t),   &be_node_op_ops);
1324         op_be_Perm      = new_ir_op(beo_Perm,      "be_Perm",      op_pin_state_pinned, irop_flag_none,                          oparity_variable, 0, 0,                         &be_node_op_ops);
1325         op_be_MemPerm   = new_ir_op(beo_MemPerm,   "be_MemPerm",   op_pin_state_pinned, irop_flag_none,                          oparity_variable, 0, sizeof(be_memperm_attr_t), &be_node_op_ops);
1326         op_be_Copy      = new_ir_op(beo_Copy,      "be_Copy",      op_pin_state_floats, irop_flag_none,                          oparity_unary,    0, 0,                         &be_node_op_ops);
1327         op_be_Keep      = new_ir_op(beo_Keep,      "be_Keep",      op_pin_state_floats, irop_flag_keep,                          oparity_dynamic,  0, 0,                         &be_node_op_ops);
1328         op_be_CopyKeep  = new_ir_op(beo_CopyKeep,  "be_CopyKeep",  op_pin_state_floats, irop_flag_keep,                          oparity_variable, 0, 0,                         &be_node_op_ops);
1329         op_be_Call      = new_ir_op(beo_Call,      "be_Call",      op_pin_state_pinned, irop_flag_fragile|irop_flag_uses_memory, oparity_variable, 0, sizeof(be_call_attr_t),    &be_node_op_ops);
1330         op_be_Return    = new_ir_op(beo_Return,    "be_Return",    op_pin_state_pinned, irop_flag_cfopcode,                      oparity_dynamic,  0, sizeof(be_return_attr_t),  &be_node_op_ops);
1331         op_be_AddSP     = new_ir_op(beo_AddSP,     "be_AddSP",     op_pin_state_pinned, irop_flag_none,                          oparity_unary,    0, 0,                         &be_node_op_ops);
1332         op_be_SubSP     = new_ir_op(beo_SubSP,     "be_SubSP",     op_pin_state_pinned, irop_flag_none,                          oparity_unary,    0, 0,                         &be_node_op_ops);
1333         op_be_IncSP     = new_ir_op(beo_IncSP,     "be_IncSP",     op_pin_state_pinned, irop_flag_none,                          oparity_unary,    0, sizeof(be_incsp_attr_t),   &be_node_op_ops);
1334         op_be_Start     = new_ir_op(beo_Start,     "be_Start",     op_pin_state_pinned, irop_flag_none,                          oparity_zero,     0, 0,                         &be_node_op_ops);
1335         op_be_FrameAddr = new_ir_op(beo_FrameAddr, "be_FrameAddr", op_pin_state_floats, irop_flag_none,                          oparity_unary,    0, sizeof(be_frame_attr_t),   &be_node_op_ops);
1336         op_be_Barrier   = new_ir_op(beo_Barrier,   "be_Barrier",   op_pin_state_pinned, irop_flag_none,                          oparity_dynamic,  0, 0,                         &be_node_op_ops);
1337
1338         op_be_Spill->ops.node_cmp_attr     = FrameAddr_cmp_attr;
1339         op_be_Reload->ops.node_cmp_attr    = FrameAddr_cmp_attr;
1340         op_be_Perm->ops.node_cmp_attr      = be_nodes_equal;
1341         op_be_MemPerm->ops.node_cmp_attr   = be_nodes_equal;
1342         op_be_Copy->ops.node_cmp_attr      = be_nodes_equal;
1343         op_be_Keep->ops.node_cmp_attr      = be_nodes_equal;
1344         op_be_CopyKeep->ops.node_cmp_attr  = be_nodes_equal;
1345         op_be_Call->ops.node_cmp_attr      = Call_cmp_attr;
1346         op_be_Return->ops.node_cmp_attr    = Return_cmp_attr;
1347         op_be_AddSP->ops.node_cmp_attr     = be_nodes_equal;
1348         op_be_SubSP->ops.node_cmp_attr     = be_nodes_equal;
1349         op_be_IncSP->ops.node_cmp_attr     = IncSP_cmp_attr;
1350         op_be_Start->ops.node_cmp_attr     = be_nodes_equal;
1351         op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
1352         op_be_Barrier->ops.node_cmp_attr   = be_nodes_equal;
1353
1354         /* attach out dummy_ops to middle end nodes */
1355         for (opc = iro_First; opc <= iro_Last; ++opc) {
1356                 ir_op *op = get_irp_opcode(opc);
1357                 assert(op->ops.be_ops == NULL);
1358                 op->ops.be_ops = &dummy_be_irn_ops;
1359         }
1360
1361         op_Phi->ops.be_ops = &phi_irn_ops;
1362 }