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