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