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