backend: put ignore regs into beirg
[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         const arch_register_req_t *req;
878
879         /* if we have an ignore register, add ignore flag and just assign it */
880         if (reg->type & arch_register_type_ignore) {
881                 additional_types |= arch_register_req_type_ignore;
882         }
883
884         if (additional_types == 0) {
885                 req = reg->single_req;
886         } else {
887                 ir_graph       *irg  = get_irn_irg(node);
888                 struct obstack *obst = be_get_be_obst(irg);
889                 req = be_create_reg_req(obst, reg, additional_types);
890         }
891
892         arch_irn_set_register(node, pos, reg);
893         be_set_constr_out(node, pos, req);
894 }
895
896 void be_node_set_reg_class_in(ir_node *irn, int pos,
897                               const arch_register_class_t *cls)
898 {
899         be_set_constr_in(irn, pos, cls->class_req);
900 }
901
902 void be_node_set_reg_class_out(ir_node *irn, int pos,
903                                const arch_register_class_t *cls)
904 {
905         be_set_constr_out(irn, pos, cls->class_req);
906 }
907
908 ir_node *be_get_IncSP_pred(ir_node *irn)
909 {
910         assert(be_is_IncSP(irn));
911         return get_irn_n(irn, 0);
912 }
913
914 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred)
915 {
916         assert(be_is_IncSP(incsp));
917         set_irn_n(incsp, 0, pred);
918 }
919
920 void be_set_IncSP_offset(ir_node *irn, int offset)
921 {
922         be_incsp_attr_t *a = get_irn_generic_attr(irn);
923         assert(be_is_IncSP(irn));
924         a->offset = offset;
925 }
926
927 int be_get_IncSP_offset(const ir_node *irn)
928 {
929         const be_incsp_attr_t *a = get_irn_generic_attr_const(irn);
930         assert(be_is_IncSP(irn));
931         return a->offset;
932 }
933
934 int be_get_IncSP_align(const ir_node *irn)
935 {
936         const be_incsp_attr_t *a = get_irn_generic_attr_const(irn);
937         assert(be_is_IncSP(irn));
938         return a->align;
939 }
940
941 ir_node *be_spill(ir_node *block, ir_node *irn)
942 {
943         ir_graph                    *irg       = get_Block_irg(block);
944         ir_node                     *frame     = get_irg_frame(irg);
945         const arch_register_class_t *cls       = arch_get_irn_reg_class_out(irn);
946         const arch_register_class_t *cls_frame = arch_get_irn_reg_class_out(frame);
947         ir_node                     *spill;
948
949         spill = be_new_Spill(cls, cls_frame, block, frame, irn);
950         return spill;
951 }
952
953 ir_node *be_reload(const arch_register_class_t *cls, ir_node *insert, ir_mode *mode, ir_node *spill)
954 {
955         ir_node  *reload;
956         ir_node  *bl    = is_Block(insert) ? insert : get_nodes_block(insert);
957         ir_graph *irg   = get_Block_irg(bl);
958         ir_node  *frame = get_irg_frame(irg);
959         const arch_register_class_t *cls_frame = arch_get_irn_reg_class_out(frame);
960
961         assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
962
963         reload = be_new_Reload(cls, cls_frame, bl, frame, spill, mode);
964
965         if (is_Block(insert)) {
966                 insert = sched_skip(insert, 0, sched_skip_cf_predicator, NULL);
967                 sched_add_after(insert, reload);
968         } else {
969                 sched_add_before(insert, reload);
970         }
971
972         return reload;
973 }
974
975
976 static arch_irn_class_t be_node_classify(const ir_node *irn)
977 {
978         switch (get_irn_opcode(irn)) {
979                 case beo_Spill:  return arch_irn_class_spill;
980                 case beo_Reload: return arch_irn_class_reload;
981                 case beo_Perm:   return arch_irn_class_perm;
982                 case beo_Copy:   return arch_irn_class_copy;
983                 default:         return 0;
984         }
985 }
986
987 static ir_entity *be_node_get_frame_entity(const ir_node *irn)
988 {
989         return be_get_frame_entity(irn);
990 }
991
992 void be_node_set_frame_entity(ir_node *irn, ir_entity *ent)
993 {
994         be_frame_attr_t *a;
995
996         assert(be_has_frame_entity(irn));
997
998         a = get_irn_generic_attr(irn);
999         a->ent = ent;
1000 }
1001
1002 static void be_node_set_frame_offset(ir_node *irn, int offset)
1003 {
1004         be_frame_attr_t *a;
1005
1006         if (!be_has_frame_entity(irn))
1007                 return;
1008
1009         a = get_irn_generic_attr(irn);
1010         a->offset = offset;
1011 }
1012
1013 static int be_node_get_sp_bias(const ir_node *irn)
1014 {
1015         if (be_is_IncSP(irn))
1016                 return be_get_IncSP_offset(irn);
1017         if (be_is_Call(irn))
1018                 return -(int)be_Call_get_pop(irn);
1019
1020         return 0;
1021 }
1022
1023
1024
1025 /* for be nodes */
1026 static const arch_irn_ops_t be_node_irn_ops = {
1027         be_node_classify,
1028         be_node_get_frame_entity,
1029         be_node_set_frame_offset,
1030         be_node_get_sp_bias,
1031         NULL,    /* get_inverse             */
1032         NULL,    /* get_op_estimated_cost   */
1033         NULL,    /* possible_memory_operand */
1034         NULL,    /* perform_memory_operand  */
1035 };
1036
1037 static arch_irn_class_t dummy_classify(const ir_node *node)
1038 {
1039         (void) node;
1040         return 0;
1041 }
1042
1043 static ir_entity* dummy_get_frame_entity(const ir_node *node)
1044 {
1045         (void) node;
1046         return NULL;
1047 }
1048
1049 static void dummy_set_frame_offset(ir_node *node, int bias)
1050 {
1051         (void) node;
1052         (void) bias;
1053         panic("dummy_set_frame_offset() should not be called");
1054 }
1055
1056 static int dummy_get_sp_bias(const ir_node *node)
1057 {
1058         (void) node;
1059         return 0;
1060 }
1061
1062 /* for "middleend" nodes */
1063 static const arch_irn_ops_t dummy_be_irn_ops = {
1064         dummy_classify,
1065         dummy_get_frame_entity,
1066         dummy_set_frame_offset,
1067         dummy_get_sp_bias,
1068         NULL,      /* get_inverse           */
1069         NULL,      /* get_op_estimated_cost */
1070         NULL,      /* possible_memory_operand */
1071         NULL,      /* perform_memory_operand */
1072 };
1073
1074
1075
1076 ir_node *be_new_Phi(ir_node *block, int n_ins, ir_node **ins, ir_mode *mode,
1077                     const arch_register_class_t *cls)
1078 {
1079         const arch_register_req_t *req;
1080         ir_graph       *irg  = get_irn_irg(block);
1081         struct obstack *obst = be_get_be_obst(irg);
1082         backend_info_t *info;
1083         int             i;
1084
1085         ir_node *phi = new_r_Phi(block, n_ins, ins, mode);
1086         info = be_get_info(phi);
1087         info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
1088         memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
1089         info->in_reqs = OALLOCN(obst, const arch_register_req_t*, n_ins);
1090
1091         if (cls == NULL) {
1092                 req = arch_no_register_req;
1093         } else {
1094                 req = cls->class_req;
1095         }
1096         info->out_infos[0].req = req;
1097         for (i = 0; i < n_ins; ++i) {
1098                 info->in_reqs[i] = req;
1099         }
1100
1101         return phi;
1102 }
1103
1104 void be_set_phi_reg_req(ir_node *node, const arch_register_req_t *req)
1105 {
1106         int arity = get_irn_arity(node);
1107         int i;
1108
1109         backend_info_t *info = be_get_info(node);
1110         info->out_infos[0].req = req;
1111         for (i = 0; i < arity; ++i) {
1112                 info->in_reqs[i] = req;
1113         }
1114
1115         assert(mode_is_datab(get_irn_mode(node)));
1116 }
1117
1118 void be_dump_phi_reg_reqs(FILE *F, ir_node *node, dump_reason_t reason)
1119 {
1120         switch (reason) {
1121         case dump_node_opcode_txt:
1122                 fputs(get_op_name(get_irn_op(node)), F);
1123                 break;
1124         case dump_node_mode_txt:
1125                 fprintf(F, "%s", get_mode_name(get_irn_mode(node)));
1126                 break;
1127         case dump_node_nodeattr_txt:
1128                 break;
1129         case dump_node_info_txt:
1130         {
1131                 backend_info_t *info = be_get_info(node);
1132                 if (info != NULL && info->out_infos[0].req != NULL) {
1133                         arch_dump_reqs_and_registers(F, node);
1134                 }
1135                 break;
1136         }
1137
1138         default:
1139                 break;
1140         }
1141 }
1142
1143 static const arch_irn_ops_t phi_irn_ops = {
1144         dummy_classify,
1145         dummy_get_frame_entity,
1146         dummy_set_frame_offset,
1147         dummy_get_sp_bias,
1148         NULL,    /* get_inverse             */
1149         NULL,    /* get_op_estimated_cost   */
1150         NULL,    /* possible_memory_operand */
1151         NULL,    /* perform_memory_operand  */
1152 };
1153
1154
1155
1156 /**
1157  * ir_op-Operation: dump a be node to file
1158  */
1159 static void dump_node(FILE *f, ir_node *irn, dump_reason_t reason)
1160 {
1161         assert(is_be_node(irn));
1162
1163         switch (reason) {
1164                 case dump_node_opcode_txt:
1165                         fputs(get_op_name(get_irn_op(irn)), f);
1166                         break;
1167                 case dump_node_mode_txt:
1168                         if (be_is_Copy(irn) || be_is_CopyKeep(irn)) {
1169                                 fprintf(f, "%s", get_mode_name(get_irn_mode(irn)));
1170                         }
1171                         break;
1172                 case dump_node_nodeattr_txt:
1173                         if (be_is_Call(irn)) {
1174                                 const be_call_attr_t *a = get_irn_generic_attr_const(irn);
1175                                 if (a->ent)
1176                                         fprintf(f, " [%s] ", get_entity_name(a->ent));
1177                         }
1178                         if (be_is_IncSP(irn)) {
1179                                 const be_incsp_attr_t *attr = get_irn_generic_attr_const(irn);
1180                                 if (attr->offset == BE_STACK_FRAME_SIZE_EXPAND) {
1181                                         fprintf(f, " [Setup Stackframe] ");
1182                                 } else if (attr->offset == BE_STACK_FRAME_SIZE_SHRINK) {
1183                                         fprintf(f, " [Destroy Stackframe] ");
1184                                 } else {
1185                                         fprintf(f, " [%d] ", attr->offset);
1186                                 }
1187                         }
1188                         break;
1189                 case dump_node_info_txt:
1190                         arch_dump_reqs_and_registers(f, irn);
1191
1192                         if (be_has_frame_entity(irn)) {
1193                                 const be_frame_attr_t *a = get_irn_generic_attr_const(irn);
1194                                 if (a->ent) {
1195                                         unsigned size = get_type_size_bytes(get_entity_type(a->ent));
1196                                         ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
1197                                           a->ent, a->offset, a->offset, size, size);
1198                                 }
1199
1200                         }
1201
1202                         switch (get_irn_opcode(irn)) {
1203                         case beo_IncSP: {
1204                                 const be_incsp_attr_t *a = get_irn_generic_attr_const(irn);
1205                                 fprintf(f, "align: %d\n", a->align);
1206                                 if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1207                                         fprintf(f, "offset: FRAME_SIZE\n");
1208                                 else if (a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1209                                         fprintf(f, "offset: -FRAME SIZE\n");
1210                                 else
1211                                         fprintf(f, "offset: %d\n", a->offset);
1212                                 break;
1213                         }
1214                         case beo_Call: {
1215                                 const be_call_attr_t *a = get_irn_generic_attr_const(irn);
1216
1217                                 if (a->ent)
1218                                         fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1219                                 break;
1220                         }
1221                         case beo_MemPerm: {
1222                                 int i;
1223                                 for (i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1224                                         ir_entity *in, *out;
1225                                         in = be_get_MemPerm_in_entity(irn, i);
1226                                         out = be_get_MemPerm_out_entity(irn, i);
1227                                         if (in) {
1228                                                 fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1229                                         }
1230                                         if (out) {
1231                                                 fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1232                                         }
1233                                 }
1234                                 break;
1235                         }
1236
1237                         default:
1238                                 break;
1239                         }
1240         }
1241 }
1242
1243 /**
1244  * ir_op-Operation:
1245  * Copies the backend specific attributes from old node to new node.
1246  */
1247 static void copy_attr(ir_graph *irg, const ir_node *old_node, ir_node *new_node)
1248 {
1249         const void     *old_attr = get_irn_generic_attr_const(old_node);
1250         void           *new_attr = get_irn_generic_attr(new_node);
1251         struct obstack *obst     = be_get_be_obst(irg);
1252         backend_info_t *old_info = be_get_info(old_node);
1253         backend_info_t *new_info = be_get_info(new_node);
1254
1255         assert(is_be_node(old_node));
1256         assert(is_be_node(new_node));
1257
1258         memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1259
1260         if (old_info->out_infos != NULL) {
1261                 unsigned n_outs = ARR_LEN(old_info->out_infos);
1262                 /* need dyanmic out infos? */
1263                 if (be_is_Barrier(new_node) || be_is_Perm(new_node)) {
1264                         new_info->out_infos = NEW_ARR_F(reg_out_info_t, n_outs);
1265                 } else {
1266                         new_info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_outs);
1267                 }
1268                 memcpy(new_info->out_infos, old_info->out_infos,
1269                            n_outs * sizeof(new_info->out_infos[0]));
1270         } else {
1271                 new_info->out_infos = NULL;
1272         }
1273
1274         /* input infos */
1275         if (old_info->in_reqs != NULL) {
1276                 unsigned n_ins = get_irn_arity(old_node);
1277                 /* need dynamic in infos? */
1278                 if (get_irn_op(old_node)->opar == oparity_dynamic) {
1279                         new_info->in_reqs = NEW_ARR_F(const arch_register_req_t*, n_ins);
1280                 } else {
1281                         new_info->in_reqs = OALLOCN(obst,const arch_register_req_t*, n_ins);
1282                 }
1283                 memcpy(new_info->in_reqs, old_info->in_reqs,
1284                        n_ins * sizeof(new_info->in_reqs[0]));
1285         } else {
1286                 new_info->in_reqs = NULL;
1287         }
1288 }
1289
1290 static const ir_op_ops be_node_op_ops = {
1291         firm_default_hash,
1292         NULL,
1293         NULL,
1294         NULL,
1295         NULL,
1296         NULL,
1297         NULL,
1298         NULL,
1299         NULL,
1300         copy_attr,
1301         NULL,
1302         NULL,
1303         NULL,
1304         NULL,
1305         dump_node,
1306         NULL,
1307         &be_node_irn_ops
1308 };
1309
1310 int is_be_node(const ir_node *irn)
1311 {
1312         return get_op_ops(get_irn_op(irn))->be_ops == &be_node_irn_ops;
1313 }
1314
1315 void be_init_op(void)
1316 {
1317         ir_opcode opc;
1318
1319         /* Acquire all needed opcodes. */
1320         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);
1321         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);
1322         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);
1323         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);
1324         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);
1325         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);
1326         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);
1327         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);
1328         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);
1329         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);
1330         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);
1331         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);
1332         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);
1333         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);
1334         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);
1335
1336         op_be_Spill->ops.node_cmp_attr     = FrameAddr_cmp_attr;
1337         op_be_Reload->ops.node_cmp_attr    = FrameAddr_cmp_attr;
1338         op_be_Perm->ops.node_cmp_attr      = be_nodes_equal;
1339         op_be_MemPerm->ops.node_cmp_attr   = be_nodes_equal;
1340         op_be_Copy->ops.node_cmp_attr      = be_nodes_equal;
1341         op_be_Keep->ops.node_cmp_attr      = be_nodes_equal;
1342         op_be_CopyKeep->ops.node_cmp_attr  = be_nodes_equal;
1343         op_be_Call->ops.node_cmp_attr      = Call_cmp_attr;
1344         op_be_Return->ops.node_cmp_attr    = Return_cmp_attr;
1345         op_be_AddSP->ops.node_cmp_attr     = be_nodes_equal;
1346         op_be_SubSP->ops.node_cmp_attr     = be_nodes_equal;
1347         op_be_IncSP->ops.node_cmp_attr     = IncSP_cmp_attr;
1348         op_be_Start->ops.node_cmp_attr     = be_nodes_equal;
1349         op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
1350         op_be_Barrier->ops.node_cmp_attr   = be_nodes_equal;
1351
1352         /* attach out dummy_ops to middle end nodes */
1353         for (opc = iro_First; opc <= iro_Last; ++opc) {
1354                 ir_op *op = get_irp_opcode(opc);
1355                 assert(op->ops.be_ops == NULL);
1356                 op->ops.be_ops = &dummy_be_irn_ops;
1357         }
1358
1359         op_Phi->ops.be_ops = &phi_irn_ops;
1360 }