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