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