d85b6f61b067c162f348dd038a65306b6c895b87
[libfirm] / ir / be / benode.c
1 /*
2  * Copyright (C) 1995-2007 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 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include <stdlib.h>
35
36 #include "obst.h"
37 #include "set.h"
38 #include "pmap.h"
39 #include "util.h"
40 #include "debug.h"
41 #include "fourcc.h"
42 #include "offset.h"
43 #include "bitfiddle.h"
44 #include "raw_bitset.h"
45
46 #include "irop_t.h"
47 #include "irmode_t.h"
48 #include "irnode_t.h"
49 #include "ircons_t.h"
50 #include "irprintf.h"
51 #include "irgwalk.h"
52 #include "iropt_t.h"
53
54 #include "be_t.h"
55 #include "belive_t.h"
56 #include "besched_t.h"
57 #include "benode_t.h"
58
59 #include "beirgmod.h"
60
61 #define OUT_POS(x) (-((x) + 1))
62
63 /* Sometimes we want to put const nodes into get_irn_generic_attr ... */
64 #define get_irn_attr(irn) get_irn_generic_attr((ir_node *) (irn))
65
66 static unsigned be_node_tag = FOURCC('B', 'E', 'N', 'O');
67
68 typedef struct {
69         arch_register_req_t req;
70         arch_irn_flags_t    flags;
71 } be_req_t;
72
73 typedef struct {
74         const arch_register_t *reg;
75         be_req_t req;
76         be_req_t in_req;
77 } be_reg_data_t;
78
79 /** The generic be nodes attribute type. */
80 typedef struct {
81         be_reg_data_t         *reg_data;
82 } be_node_attr_t;
83
84 /** The be_Return nodes attribute type. */
85 typedef struct {
86         be_node_attr_t node_attr;
87         int            num_ret_vals;  /**< number of return values */
88 } be_return_attr_t;
89
90 /** The be_Stack attribute type. */
91 typedef struct {
92         be_node_attr_t node_attr;
93         int offset;           /**< The offset by which the stack shall be expanded/shrinked. */
94 } be_stack_attr_t;
95
96 /** The be_Frame attribute type. */
97 typedef struct {
98         be_node_attr_t node_attr;
99         ir_entity *ent;
100         int offset;
101 } be_frame_attr_t;
102
103 /** The be_Call attribute type. */
104 typedef struct {
105         be_node_attr_t node_attr;
106         ir_entity *ent;      /**< The called entity if this is a static call. */
107         ir_type *call_tp;    /**< The call type, copied from the original Call node. */
108 } be_call_attr_t;
109
110 typedef struct {
111         be_node_attr_t node_attr;
112         ir_entity **in_entities;
113         ir_entity **out_entities;
114 } be_memperm_attr_t;
115
116 ir_op *op_be_Spill;
117 ir_op *op_be_Reload;
118 ir_op *op_be_Perm;
119 ir_op *op_be_MemPerm;
120 ir_op *op_be_Copy;
121 ir_op *op_be_Keep;
122 ir_op *op_be_CopyKeep;
123 ir_op *op_be_Call;
124 ir_op *op_be_Return;
125 ir_op *op_be_IncSP;
126 ir_op *op_be_AddSP;
127 ir_op *op_be_SubSP;
128 ir_op *op_be_SetSP;
129 ir_op *op_be_RegParams;
130 ir_op *op_be_StackParam;
131 ir_op *op_be_FrameAddr;
132 ir_op *op_be_FrameLoad;
133 ir_op *op_be_FrameStore;
134 ir_op *op_be_Barrier;
135
136 static int beo_base = -1;
137
138 static const ir_op_ops be_node_op_ops;
139
140 #define N   irop_flag_none
141 #define L   irop_flag_labeled
142 #define C   irop_flag_commutative
143 #define X   irop_flag_cfopcode
144 #define I   irop_flag_ip_cfopcode
145 #define F   irop_flag_fragile
146 #define Y   irop_flag_forking
147 #define H   irop_flag_highlevel
148 #define c   irop_flag_constlike
149 #define K   irop_flag_keep
150 #define M   irop_flag_machine
151
152
153 /**
154  * Compare two node attributes.
155  *
156  * @return zero if both attributes are identically
157  */
158 static int _node_cmp_attr(be_node_attr_t *a, be_node_attr_t *b) {
159         int i, len;
160
161         if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
162                 return 1;
163
164         len = ARR_LEN(a->reg_data);
165         for (i = 0; i < len; ++i) {
166                 if (a->reg_data[i].reg != b->reg_data[i].reg ||
167                                 memcmp(&a->reg_data[i].in_req, &b->reg_data[i].in_req, sizeof(b->reg_data[i].in_req)) ||
168                             memcmp(&a->reg_data[i].req,    &b->reg_data[i].req,    sizeof(a->reg_data[i].req)))
169                         return 1;
170         }
171
172         return 0;
173 }
174
175 static int node_cmp_attr(ir_node *a, ir_node *b) {
176         be_node_attr_t *a_attr = get_irn_attr(a);
177         be_node_attr_t *b_attr = get_irn_attr(b);
178
179         return _node_cmp_attr(a_attr, b_attr);
180 }
181
182 /**
183  * Compare the attributes of two FrameAddr nodes.
184  *
185  * @return zero if both attributes are identically
186  */
187 static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
188         be_frame_attr_t *a_attr = get_irn_attr(a);
189         be_frame_attr_t *b_attr = get_irn_attr(b);
190
191         if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
192                 return 1;
193
194         return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
195 }
196
197 static int Return_cmp_attr(ir_node *a, ir_node *b) {
198         be_return_attr_t *a_attr = get_irn_attr(a);
199         be_return_attr_t *b_attr = get_irn_attr(b);
200
201         if (a_attr->num_ret_vals != b_attr->num_ret_vals)
202                 return 1;
203
204         return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
205 }
206
207 static int Stack_cmp_attr(ir_node *a, ir_node *b) {
208         be_stack_attr_t *a_attr = get_irn_attr(a);
209         be_stack_attr_t *b_attr = get_irn_attr(b);
210
211         if (a_attr->offset != b_attr->offset)
212                 return 1;
213
214         return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
215 }
216
217 static int Call_cmp_attr(ir_node *a, ir_node *b) {
218         be_call_attr_t *a_attr = get_irn_attr(a);
219         be_call_attr_t *b_attr = get_irn_attr(b);
220
221         if (a_attr->ent != b_attr->ent ||
222                         a_attr->call_tp != b_attr->call_tp)
223                 return 1;
224
225         return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
226 }
227
228 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
229 {
230         int idx;
231         be_node_attr_t *attr;
232         be_reg_data_t *rd;
233
234         assert(is_be_node(node));
235         attr = get_irn_attr(node);
236
237         if(pos < 0) {
238                 idx = -(pos + 1);
239         } else {
240                 idx = pos;
241                 assert(idx < get_irn_arity(node));
242         }
243         assert(idx < ARR_LEN(attr->reg_data));
244         rd = &attr->reg_data[idx];
245
246         return pos < 0 ? &rd->req : &rd->in_req;
247 }
248
249 static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
250 {
251         be_req_t *bereq = get_be_req(node, pos);
252         return &bereq->req;
253 }
254
255 void be_node_init(void) {
256         static int inited = 0;
257
258         if(inited)
259                 return;
260
261         inited = 1;
262
263         /* Acquire all needed opcodes. */
264         beo_base = get_next_ir_opcodes(beo_Last);
265
266         op_be_Spill      = new_ir_op(beo_base + beo_Spill,      "be_Spill",      op_pin_state_pinned,     N, oparity_unary,    0, sizeof(be_frame_attr_t),   &be_node_op_ops);
267         op_be_Reload     = new_ir_op(beo_base + beo_Reload,     "be_Reload",     op_pin_state_pinned,     N, oparity_zero,     0, sizeof(be_frame_attr_t),   &be_node_op_ops);
268         op_be_Perm       = new_ir_op(beo_base + beo_Perm,       "be_Perm",       op_pin_state_pinned,     N, oparity_variable, 0, sizeof(be_node_attr_t),    &be_node_op_ops);
269         op_be_MemPerm    = new_ir_op(beo_base + beo_MemPerm,    "be_MemPerm",    op_pin_state_pinned,     N, oparity_variable, 0, sizeof(be_memperm_attr_t), &be_node_op_ops);
270         op_be_Copy       = new_ir_op(beo_base + beo_Copy,       "be_Copy",       op_pin_state_floats,     N, oparity_unary,    0, sizeof(be_node_attr_t),    &be_node_op_ops);
271         op_be_Keep       = new_ir_op(beo_base + beo_Keep,       "be_Keep",       op_pin_state_pinned,     K, oparity_dynamic,  0, sizeof(be_node_attr_t),    &be_node_op_ops);
272         op_be_CopyKeep   = new_ir_op(beo_base + beo_CopyKeep,   "be_CopyKeep",   op_pin_state_pinned,     K, oparity_variable, 0, sizeof(be_node_attr_t),    &be_node_op_ops);
273         op_be_Call       = new_ir_op(beo_base + beo_Call,       "be_Call",       op_pin_state_pinned,     F, oparity_variable, 0, sizeof(be_call_attr_t),    &be_node_op_ops);
274         op_be_Return     = new_ir_op(beo_base + beo_Return,     "be_Return",     op_pin_state_pinned,     X, oparity_dynamic,  0, sizeof(be_return_attr_t),  &be_node_op_ops);
275         op_be_AddSP      = new_ir_op(beo_base + beo_AddSP,      "be_AddSP",      op_pin_state_pinned,     N, oparity_unary,    0, sizeof(be_node_attr_t),    &be_node_op_ops);
276         op_be_SubSP      = new_ir_op(beo_base + beo_SubSP,      "be_SubSP",      op_pin_state_pinned,     N, oparity_unary,    0, sizeof(be_node_attr_t),    &be_node_op_ops);
277         op_be_IncSP      = new_ir_op(beo_base + beo_IncSP,      "be_IncSP",      op_pin_state_pinned,     N, oparity_unary,    0, sizeof(be_stack_attr_t),   &be_node_op_ops);
278         op_be_SetSP      = new_ir_op(beo_base + beo_SetSP,      "be_SetSP",      op_pin_state_pinned,     N, oparity_binary,   0, sizeof(be_stack_attr_t),   &be_node_op_ops);
279         op_be_RegParams  = new_ir_op(beo_base + beo_RegParams,  "be_RegParams",  op_pin_state_pinned,     N, oparity_zero,     0, sizeof(be_node_attr_t),    &be_node_op_ops);
280         op_be_StackParam = new_ir_op(beo_base + beo_StackParam, "be_StackParam", op_pin_state_floats,     N, oparity_unary,    0, sizeof(be_frame_attr_t),   &be_node_op_ops);
281         op_be_FrameLoad  = new_ir_op(beo_base + beo_FrameLoad,  "be_FrameLoad",  op_pin_state_floats,     N, oparity_any,      0, sizeof(be_frame_attr_t),   &be_node_op_ops);
282         op_be_FrameStore = new_ir_op(beo_base + beo_FrameStore, "be_FrameStore", op_pin_state_floats,     N, oparity_any,      0, sizeof(be_frame_attr_t),   &be_node_op_ops);
283         op_be_FrameAddr  = new_ir_op(beo_base + beo_FrameAddr,  "be_FrameAddr",  op_pin_state_floats,     N, oparity_unary,    0, sizeof(be_frame_attr_t),   &be_node_op_ops);
284         op_be_Barrier    = new_ir_op(beo_base + beo_Barrier,    "be_Barrier",    op_pin_state_pinned,     N, oparity_dynamic,  0, sizeof(be_node_attr_t),    &be_node_op_ops);
285
286         set_op_tag(op_be_Spill,      &be_node_tag);
287         op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
288         set_op_tag(op_be_Reload,     &be_node_tag);
289         op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
290         set_op_tag(op_be_Perm,       &be_node_tag);
291         op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
292         set_op_tag(op_be_MemPerm,    &be_node_tag);
293         op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
294         set_op_tag(op_be_Copy,       &be_node_tag);
295         op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
296         set_op_tag(op_be_Keep,       &be_node_tag);
297         op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
298         set_op_tag(op_be_CopyKeep,   &be_node_tag);
299         op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
300         set_op_tag(op_be_Call,       &be_node_tag);
301         op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
302         set_op_tag(op_be_Return,     &be_node_tag);
303         op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
304         set_op_tag(op_be_AddSP,      &be_node_tag);
305         op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
306         set_op_tag(op_be_SubSP,      &be_node_tag);
307         op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
308         set_op_tag(op_be_SetSP,      &be_node_tag);
309         op_be_SetSP->ops.node_cmp_attr = Stack_cmp_attr;
310         set_op_tag(op_be_IncSP,      &be_node_tag);
311         op_be_IncSP->ops.node_cmp_attr = Stack_cmp_attr;
312         set_op_tag(op_be_RegParams,  &be_node_tag);
313         op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
314         set_op_tag(op_be_StackParam, &be_node_tag);
315         op_be_StackParam->ops.node_cmp_attr = FrameAddr_cmp_attr;
316         set_op_tag(op_be_FrameLoad,  &be_node_tag);
317         op_be_FrameLoad->ops.node_cmp_attr = FrameAddr_cmp_attr;
318         set_op_tag(op_be_FrameStore, &be_node_tag);
319         op_be_FrameStore->ops.node_cmp_attr = FrameAddr_cmp_attr;
320         set_op_tag(op_be_FrameAddr,  &be_node_tag);
321         op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
322         set_op_tag(op_be_Barrier,    &be_node_tag);
323         op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
324 }
325
326 /**
327  * Initializes the generic attribute of all be nodes and return ir.
328  */
329 static void *init_node_attr(ir_node *node, int max_reg_data)
330 {
331         ir_graph *irg = get_irn_irg(node);
332         struct obstack *obst = get_irg_obstack(irg);
333         be_node_attr_t *a = get_irn_attr(node);
334
335         memset(a, 0, sizeof(get_op_attr_size(get_irn_op(node))));
336
337         if(max_reg_data >= 0) {
338                 a->reg_data = NEW_ARR_D(be_reg_data_t, obst, max_reg_data);
339                 memset(a->reg_data, 0, max_reg_data * sizeof(a->reg_data[0]));
340         } else {
341                 a->reg_data = NEW_ARR_F(be_reg_data_t, 0);
342         }
343
344         return a;
345 }
346
347 static void add_register_req(ir_node *node)
348 {
349         be_node_attr_t *a = get_irn_attr(node);
350         be_reg_data_t regreq;
351         memset(&regreq, 0, sizeof(regreq));
352         ARR_APP1(be_reg_data_t, a->reg_data, regreq);
353 }
354
355 int is_be_node(const ir_node *irn)
356 {
357         return get_op_tag(get_irn_op(irn)) == &be_node_tag;
358 }
359
360 be_opcode_t be_get_irn_opcode(const ir_node *irn)
361 {
362         return is_be_node(irn) ? (be_opcode_t) get_irn_opcode(irn) - beo_base : beo_NoBeOp;
363 }
364
365 /**
366  * Skip Proj nodes and return their Proj numbers.
367  *
368  * If *node is a Proj or Proj(Proj) node, skip it.
369  *
370  * @param node  points to the node to be skipped
371  *
372  * @return 0 if *node was no Proj node, its Proj number else.
373  */
374 static int redir_proj(const ir_node **node)
375 {
376         const ir_node *n = *node;
377
378         if(is_Proj(n)) {
379                 ir_node *irn;
380
381                 *node = irn = get_Proj_pred(n);
382                 if(is_Proj(irn)) {
383                         assert(get_irn_mode(irn) == mode_T);
384                         *node = get_Proj_pred(irn);
385                 }
386                 return get_Proj_proj(n);
387         }
388
389         return 0;
390 }
391
392 static be_reg_data_t *retrieve_reg_data(const ir_node *node)
393 {
394         be_node_attr_t *attr;
395         int pos = 0;
396
397         if(is_Proj(node)) {
398                 pos = get_Proj_proj(node);
399                 node = get_Proj_pred(node);
400         }
401
402         assert(is_be_node(node));
403         attr = get_irn_attr(node);
404         assert(pos >= 0 && pos < ARR_LEN(attr->reg_data) && "illegal proj number");
405
406         return &attr->reg_data[pos];
407 }
408
409 static void
410 be_node_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
411 {
412         be_reg_data_t *r = retrieve_reg_data(irn);
413         (void) self;
414         r->reg = reg;
415 }
416
417 ir_node *be_new_Spill(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
418         ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *to_spill)
419 {
420         be_frame_attr_t *a;
421         ir_node         *in[2];
422         ir_node         *res;
423
424         in[0]     = frame;
425         in[1]     = to_spill;
426         res       = new_ir_node(NULL, irg, bl, op_be_Spill, mode_M, 2, in);
427         a         = init_node_attr(res, 2);
428         a->ent    = NULL;
429         a->offset = 0;
430
431         be_node_set_reg_class(res, be_pos_Spill_frame, cls_frame);
432         be_node_set_reg_class(res, be_pos_Spill_val, cls);
433         return res;
434 }
435
436 ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_class_t *cls_frame,
437         ir_graph *irg, ir_node *bl, ir_node *frame, ir_node *mem, ir_mode *mode)
438 {
439         ir_node *in[2];
440         ir_node *res;
441
442         in[0] = frame;
443         in[1] = mem;
444         res   = new_ir_node(NULL, irg, bl, op_be_Reload, mode, 2, in);
445
446         init_node_attr(res, 2);
447         be_node_set_reg_class(res, -1, cls);
448         be_node_set_reg_class(res, be_pos_Reload_frame, cls_frame);
449         be_node_set_flags(res, -1, arch_irn_flags_rematerializable);
450         return res;
451 }
452
453 ir_node *be_get_Reload_mem(const ir_node *irn)
454 {
455         assert(be_is_Reload(irn));
456         return get_irn_n(irn, be_pos_Reload_mem);
457 }
458
459 ir_node *be_get_Reload_frame(const ir_node *irn)
460 {
461         assert(be_is_Reload(irn));
462         return get_irn_n(irn, be_pos_Reload_frame);
463 }
464
465 ir_node *be_get_Spill_val(const ir_node *irn)
466 {
467         assert(be_is_Spill(irn));
468         return get_irn_n(irn, be_pos_Spill_val);
469 }
470
471 ir_node *be_get_Spill_frame(const ir_node *irn)
472 {
473         assert(be_is_Spill(irn));
474         return get_irn_n(irn, be_pos_Spill_frame);
475 }
476
477 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
478 {
479         int i;
480         ir_node *irn = new_ir_node(NULL, irg, bl, op_be_Perm, mode_T, n, in);
481         init_node_attr(irn, n);
482         for(i = 0; i < n; ++i) {
483                 be_node_set_reg_class(irn, i, cls);
484                 be_node_set_reg_class(irn, OUT_POS(i), cls);
485         }
486
487         return irn;
488 }
489
490 void be_Perm_reduce(ir_node *perm, int new_size, int *map)
491 {
492         ir_graph *irg           = get_irn_irg(perm);
493         int n                   = get_irn_arity(perm);
494         be_reg_data_t *old_data = xmalloc(n * sizeof(old_data[0]));
495         be_node_attr_t *attr    = get_irn_attr(perm);
496         ir_node **new_in        = NEW_ARR_D(ir_node *, irg->obst, new_size + 1);
497
498         int i;
499
500         assert(be_is_Perm(perm));
501         assert(new_size <= n);
502
503         /* save the old register data */
504         memcpy(old_data, attr->reg_data, n * sizeof(old_data[0]));
505
506         /* compose the new in array and set the new register data directly in place */
507         for (i = 0; i < n; ++i) {
508                 int idx = map[i];
509                 if (idx >= 0) {
510                         new_in[idx] = get_irn_n(perm, i);
511                         attr->reg_data[idx] = old_data[i];
512                 }
513         }
514
515         free(old_data);
516         set_irn_in(perm, new_size, new_in);
517 }
518
519 ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
520 {
521         int i;
522         ir_node *frame = get_irg_frame(irg);
523         const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
524         ir_node *irn;
525         const arch_register_t *sp = arch_env->isa->sp;
526         be_memperm_attr_t *attr;
527         ir_node **real_in;
528
529         real_in = alloca((n+1) * sizeof(real_in[0]));
530         real_in[0] = frame;
531         memcpy(&real_in[1], in, n * sizeof(real_in[0]));
532
533         irn =  new_ir_node(NULL, irg, bl, op_be_MemPerm, mode_T, n+1, real_in);
534
535         init_node_attr(irn, n + 1);
536         be_node_set_reg_class(irn, 0, sp->reg_class);
537         for(i = 0; i < n; ++i) {
538                 be_node_set_reg_class(irn, i + 1, cls_frame);
539                 be_node_set_reg_class(irn, OUT_POS(i), cls_frame);
540         }
541
542         attr = get_irn_attr(irn);
543
544         attr->in_entities = obstack_alloc(irg->obst, n * sizeof(attr->in_entities[0]));
545         memset(attr->in_entities, 0, n * sizeof(attr->in_entities[0]));
546         attr->out_entities = obstack_alloc(irg->obst, n*sizeof(attr->out_entities[0]));
547         memset(attr->out_entities, 0, n*sizeof(attr->out_entities[0]));
548
549         return irn;
550 }
551
552
553 ir_node *be_new_Copy(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *op)
554 {
555         ir_node *in[1];
556         ir_node *res;
557         arch_register_req_t *req;
558
559         in[0] = op;
560         res   = new_ir_node(NULL, irg, bl, op_be_Copy, get_irn_mode(op), 1, in);
561         init_node_attr(res, 1);
562         be_node_set_reg_class(res, 0, cls);
563         be_node_set_reg_class(res, OUT_POS(0), cls);
564
565         req = get_req(res, OUT_POS(0));
566         req->cls = cls;
567         req->type = arch_register_req_type_should_be_same;
568         req->other_same = 0;
569
570         return res;
571 }
572
573 ir_node *be_get_Copy_op(const ir_node *cpy) {
574         return get_irn_n(cpy, be_pos_Copy_op);
575 }
576
577 void be_set_Copy_op(ir_node *cpy, ir_node *op) {
578         set_irn_n(cpy, be_pos_Copy_op, op);
579 }
580
581 ir_node *be_new_Keep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
582 {
583         int i;
584         ir_node *res;
585
586         res = new_ir_node(NULL, irg, bl, op_be_Keep, mode_ANY, -1, NULL);
587         init_node_attr(res, -1);
588
589         for(i = 0; i < n; ++i) {
590                 add_irn_n(res, in[i]);
591                 add_register_req(res);
592                 be_node_set_reg_class(res, i, cls);
593         }
594         keep_alive(res);
595
596         return res;
597 }
598
599 void be_Keep_add_node(ir_node *keep, const arch_register_class_t *cls, ir_node *node)
600 {
601         int n;
602
603         assert(be_is_Keep(keep));
604         n = add_irn_n(keep, node);
605         add_register_req(keep);
606         be_node_set_reg_class(keep, n, cls);
607 }
608
609 /* creates a be_Call */
610 ir_node *be_new_Call(dbg_info *dbg, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *sp, ir_node *ptr,
611                      int n_outs, int n, ir_node *in[], ir_type *call_tp)
612 {
613         be_call_attr_t *a;
614         int real_n = be_pos_Call_first_arg + n;
615         ir_node *irn;
616         ir_node **real_in;
617
618         NEW_ARR_A(ir_node *, real_in, real_n);
619         real_in[be_pos_Call_mem] = mem;
620         real_in[be_pos_Call_sp]  = sp;
621         real_in[be_pos_Call_ptr] = ptr;
622         memcpy(&real_in[be_pos_Call_first_arg], in, n * sizeof(in[0]));
623
624         irn = new_ir_node(dbg, irg, bl, op_be_Call, mode_T, real_n, real_in);
625         a = init_node_attr(irn, (n_outs > real_n ? n_outs : real_n));
626         a->ent     = NULL;
627         a->call_tp = call_tp;
628         return irn;
629 }
630
631 /* Gets the call entity or NULL if this is no static call. */
632 ir_entity *be_Call_get_entity(const ir_node *call) {
633         be_call_attr_t *a = get_irn_attr(call);
634         assert(be_is_Call(call));
635         return a->ent;
636 }
637
638 /* Sets the call entity. */
639 void be_Call_set_entity(ir_node *call, ir_entity *ent) {
640         be_call_attr_t *a = get_irn_attr(call);
641         assert(be_is_Call(call));
642         a->ent = ent;
643 }
644
645 /* Gets the call type. */
646 ir_type *be_Call_get_type(ir_node *call) {
647         be_call_attr_t *a = get_irn_attr(call);
648         assert(be_is_Call(call));
649         return a->call_tp;
650 }
651
652 /* Sets the call type. */
653 void be_Call_set_type(ir_node *call, ir_type *call_tp) {
654         be_call_attr_t *a = get_irn_attr(call);
655         assert(be_is_Call(call));
656         a->call_tp = call_tp;
657 }
658
659 /* Construct a new be_Return. */
660 ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
661                        int n, ir_node *in[])
662 {
663         be_return_attr_t *a;
664         ir_node *res;
665         int i;
666
667         res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
668         init_node_attr(res, -1);
669         for(i = 0; i < n; ++i) {
670                 add_irn_n(res, in[i]);
671                 add_register_req(res);
672         }
673
674         a = get_irn_attr(res);
675         a->num_ret_vals = n_res;
676
677         return res;
678 }
679
680 /* Returns the number of real returns values */
681 int be_Return_get_n_rets(ir_node *ret)
682 {
683         be_return_attr_t *a = get_irn_attr(ret);
684         return a->num_ret_vals;
685 }
686
687 int be_Return_append_node(ir_node *ret, ir_node *node)
688 {
689         int pos;
690
691         pos = add_irn_n(ret, node);
692         add_register_req(ret);
693
694         return pos;
695 }
696
697 ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
698 {
699         be_stack_attr_t *a;
700         ir_node *irn;
701         ir_node *in[1];
702
703         in[0]     = old_sp;
704         irn       = new_ir_node(NULL, irg, bl, op_be_IncSP, sp->reg_class->mode, sizeof(in) / sizeof(in[0]), in);
705         a         = init_node_attr(irn, 1);
706         a->offset = offset;
707
708         be_node_set_flags(irn, -1, arch_irn_flags_ignore | arch_irn_flags_modify_sp);
709
710         /* Set output constraint to stack register. */
711         be_node_set_reg_class(irn, 0, sp->reg_class);
712         be_set_constr_single_reg(irn, BE_OUT_POS(0), sp);
713         be_node_set_irn_reg(NULL, irn, sp);
714
715         return irn;
716 }
717
718 ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
719 {
720         be_node_attr_t *a;
721         ir_node *irn;
722         ir_node *in[be_pos_AddSP_last];
723         const arch_register_class_t *class;
724
725         in[be_pos_AddSP_old_sp] = old_sp;
726         in[be_pos_AddSP_size]   = sz;
727
728         irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
729         a   = init_node_attr(irn, be_pos_AddSP_last);
730
731         be_node_set_flags(irn, OUT_POS(pn_be_AddSP_sp),
732                           arch_irn_flags_ignore | arch_irn_flags_modify_sp);
733
734         /* Set output constraint to stack register. */
735         be_set_constr_single_reg(irn, be_pos_AddSP_old_sp, sp);
736         be_node_set_reg_class(irn, be_pos_AddSP_size, arch_register_get_class(sp));
737         be_set_constr_single_reg(irn, OUT_POS(pn_be_AddSP_sp), sp);
738         a->reg_data[pn_be_AddSP_sp].reg = sp;
739
740         class = arch_register_get_class(sp);
741         be_node_set_reg_class(irn, OUT_POS(pn_be_AddSP_res), class);
742
743         return irn;
744 }
745
746 ir_node *be_new_SubSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
747 {
748         be_node_attr_t *a;
749         ir_node *irn;
750         ir_node *in[be_pos_SubSP_last];
751
752         in[be_pos_SubSP_old_sp] = old_sp;
753         in[be_pos_SubSP_size]   = sz;
754
755         irn = new_ir_node(NULL, irg, bl, op_be_SubSP, mode_T, be_pos_SubSP_last, in);
756         a   = init_node_attr(irn, be_pos_SubSP_last);
757
758         be_node_set_flags(irn, OUT_POS(pn_be_SubSP_sp),
759                           arch_irn_flags_ignore | arch_irn_flags_modify_sp);
760
761         /* Set output constraint to stack register. */
762         be_set_constr_single_reg(irn, be_pos_SubSP_old_sp, sp);
763         be_node_set_reg_class(irn, be_pos_SubSP_size, arch_register_get_class(sp));
764         be_set_constr_single_reg(irn, OUT_POS(pn_be_SubSP_sp), sp);
765         a->reg_data[pn_be_SubSP_sp].reg = sp;
766
767         return irn;
768 }
769
770 ir_node *be_new_SetSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl,
771                       ir_node *old_sp, ir_node *op, ir_node *mem)
772 {
773         be_node_attr_t *a;
774         ir_node *irn;
775         ir_node *in[3];
776
777         in[0] = mem;
778         in[1] = old_sp;
779         in[2] = op;
780         irn   = new_ir_node(NULL, irg, bl, op_be_SetSP, get_irn_mode(old_sp), 3, in);
781         a     = init_node_attr(irn, 3);
782
783         be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_ignore | arch_irn_flags_modify_sp);
784
785         /* Set output constraint to stack register. */
786         be_set_constr_single_reg(irn, OUT_POS(0), sp);
787         be_node_set_reg_class(irn, be_pos_AddSP_size, sp->reg_class);
788         be_node_set_reg_class(irn, be_pos_AddSP_old_sp, sp->reg_class);
789
790         return irn;
791 }
792
793 ir_node *be_new_StackParam(const arch_register_class_t *cls, const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_mode *mode, ir_node *frame_pointer, ir_entity *ent)
794 {
795         be_frame_attr_t *a;
796         ir_node *irn;
797         ir_node *in[1];
798
799         in[0] = frame_pointer;
800         irn = new_ir_node(NULL, irg, bl, op_be_StackParam, mode, 1, in);
801         a = init_node_attr(irn, 1);
802         a->ent = ent;
803
804         be_node_set_reg_class(irn, 0, cls_frame);
805         be_node_set_reg_class(irn, OUT_POS(0), cls);
806         be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_rematerializable);
807
808         return irn;
809 }
810
811 ir_node *be_new_RegParams(ir_graph *irg, ir_node *bl, int n_outs)
812 {
813         ir_node *res;
814         int i;
815
816         res = new_ir_node(NULL, irg, bl, op_be_RegParams, mode_T, 0, NULL);
817         init_node_attr(res, -1);
818         for(i = 0; i < n_outs; ++i)
819                 add_register_req(res);
820
821         return res;
822 }
823
824 ir_node *be_RegParams_append_out_reg(ir_node *regparams,
825                                      const arch_env_t *arch_env,
826                                      const arch_register_t *reg)
827 {
828         ir_graph *irg = get_irn_irg(regparams);
829         ir_node *block = get_nodes_block(regparams);
830         be_node_attr_t *attr = get_irn_attr(regparams);
831         const arch_register_class_t *cls = arch_register_get_class(reg);
832         ir_mode *mode = arch_register_class_mode(cls);
833         int n = ARR_LEN(attr->reg_data);
834         ir_node *proj;
835
836         assert(be_is_RegParams(regparams));
837         proj = new_r_Proj(irg, block, regparams, mode, n);
838         add_register_req(regparams);
839         be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
840         arch_set_irn_register(arch_env, proj, reg);
841
842         /* TODO decide, whether we need to set ignore/modify sp flags here? */
843
844         return proj;
845 }
846
847 ir_node *be_new_FrameLoad(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
848                                                   ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_entity *ent)
849 {
850         be_frame_attr_t *a;
851         ir_node *irn;
852         ir_node *in[2];
853
854         in[0]  = mem;
855         in[1]  = frame;
856         irn    = new_ir_node(NULL, irg, bl, op_be_FrameLoad, mode_T, 2, in);
857         a      = init_node_attr(irn, 3);
858         a->ent = ent;
859         a->offset = 0;
860         be_node_set_reg_class(irn, 1, cls_frame);
861         be_node_set_reg_class(irn, OUT_POS(pn_Load_res), cls_data);
862         return irn;
863 }
864
865 ir_node *be_new_FrameStore(const arch_register_class_t *cls_frame, const arch_register_class_t *cls_data,
866                                                    ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *frame, ir_node *data, ir_entity *ent)
867 {
868         be_frame_attr_t *a;
869         ir_node *irn;
870         ir_node *in[3];
871
872         in[0]  = mem;
873         in[1]  = frame;
874         in[2]  = data;
875         irn    = new_ir_node(NULL, irg, bl, op_be_FrameStore, mode_T, 3, in);
876         a      = init_node_attr(irn, 3);
877         a->ent = ent;
878         a->offset = 0;
879         be_node_set_reg_class(irn, 1, cls_frame);
880         be_node_set_reg_class(irn, 2, cls_data);
881         return irn;
882 }
883
884 ir_node *be_new_FrameAddr(const arch_register_class_t *cls_frame, ir_graph *irg, ir_node *bl, ir_node *frame, ir_entity *ent)
885 {
886         be_frame_attr_t *a;
887         ir_node *irn;
888         ir_node *in[1];
889
890         in[0]  = frame;
891         irn    = new_ir_node(NULL, irg, bl, op_be_FrameAddr, get_irn_mode(frame), 1, in);
892         a      = init_node_attr(irn, 1);
893         a->ent = ent;
894         a->offset = 0;
895         be_node_set_reg_class(irn, 0, cls_frame);
896         be_node_set_reg_class(irn, OUT_POS(0), cls_frame);
897
898         return optimize_node(irn);
899 }
900
901 ir_node *be_get_FrameAddr_frame(ir_node *node) {
902         assert(be_is_FrameAddr(node));
903         return get_irn_n(node, be_pos_FrameAddr_ptr);
904 }
905
906 ir_node *be_new_CopyKeep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, int n, ir_node *in_keep[], ir_mode *mode)
907 {
908         ir_node *irn;
909         ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
910
911         in[0] = src;
912         memcpy(&in[1], in_keep, n * sizeof(in[0]));
913         irn   = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
914         init_node_attr(irn, n + 1);
915         be_node_set_reg_class(irn, OUT_POS(0), cls);
916         be_node_set_reg_class(irn, 0, cls);
917
918         return irn;
919 }
920
921 ir_node *be_new_CopyKeep_single(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, ir_node *keep, ir_mode *mode)
922 {
923         ir_node *in[1];
924
925         in[0] = keep;
926         return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
927 }
928
929 ir_node *be_get_CopyKeep_op(const ir_node *cpy) {
930         return get_irn_n(cpy, be_pos_CopyKeep_op);
931 }
932
933 void be_set_CopyKeep_op(ir_node *cpy, ir_node *op) {
934         set_irn_n(cpy, be_pos_CopyKeep_op, op);
935 }
936
937 ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
938 {
939         ir_node *res;
940         int i;
941
942         res = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, -1, NULL);
943         init_node_attr(res, -1);
944         for(i = 0; i < n; ++i) {
945                 add_irn_n(res, in[i]);
946                 add_register_req(res);
947         }
948
949         return res;
950 }
951
952 ir_node *be_Barrier_append_node(ir_node *barrier, ir_node *node)
953 {
954         ir_graph *irg = get_irn_irg(barrier);
955         ir_node *block = get_nodes_block(barrier);
956         ir_mode *mode = get_irn_mode(node);
957         int n = add_irn_n(barrier, node);
958
959         ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
960         add_register_req(barrier);
961
962         return proj;
963 }
964
965 int be_is_Spill         (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill          ; }
966 int be_is_Reload        (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload         ; }
967 int be_is_Copy          (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy           ; }
968 int be_is_CopyKeep      (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_CopyKeep       ; }
969 int be_is_Perm          (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Perm           ; }
970 int be_is_MemPerm       (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_MemPerm        ; }
971 int be_is_Keep          (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Keep           ; }
972 int be_is_Call          (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Call           ; }
973 int be_is_Return        (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return         ; }
974 int be_is_IncSP         (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP          ; }
975 int be_is_SetSP         (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SetSP          ; }
976 int be_is_AddSP         (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP          ; }
977 int be_is_SubSP         (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SubSP          ; }
978 int be_is_RegParams     (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams      ; }
979 int be_is_StackParam    (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_StackParam     ; }
980 int be_is_FrameAddr     (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr      ; }
981 int be_is_FrameLoad     (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameLoad      ; }
982 int be_is_FrameStore    (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameStore     ; }
983 int be_is_Barrier       (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier        ; }
984
985 int be_has_frame_entity(const ir_node *irn)
986 {
987         switch(be_get_irn_opcode(irn)) {
988         case beo_StackParam:
989         case beo_Spill:
990         case beo_Reload:
991         case beo_FrameStore:
992         case beo_FrameLoad:
993         case beo_FrameAddr:
994                 return 1;
995         default:
996                 return 0;
997         }
998 }
999
1000 ir_entity *be_get_frame_entity(const ir_node *irn)
1001 {
1002         if (be_has_frame_entity(irn)) {
1003                 be_frame_attr_t *a = get_irn_attr(irn);
1004                 return a->ent;
1005         }
1006         return NULL;
1007 }
1008
1009 int be_get_frame_offset(const ir_node *irn)
1010 {
1011         assert(is_be_node(irn));
1012         if (be_has_frame_entity(irn)) {
1013                 be_frame_attr_t *a = get_irn_attr(irn);
1014                 return a->offset;
1015         }
1016         return 0;
1017 }
1018
1019 void be_set_MemPerm_in_entity(const ir_node *irn, int n, ir_entity *ent)
1020 {
1021         be_memperm_attr_t *attr = get_irn_attr(irn);
1022
1023         assert(be_is_MemPerm(irn));
1024         assert(n < be_get_MemPerm_entity_arity(irn));
1025
1026         attr->in_entities[n] = ent;
1027 }
1028
1029 ir_entity* be_get_MemPerm_in_entity(const ir_node* irn, int n)
1030 {
1031         be_memperm_attr_t *attr = get_irn_attr(irn);
1032
1033         assert(be_is_MemPerm(irn));
1034         assert(n < be_get_MemPerm_entity_arity(irn));
1035
1036         return attr->in_entities[n];
1037 }
1038
1039 void be_set_MemPerm_out_entity(const ir_node *irn, int n, ir_entity *ent)
1040 {
1041         be_memperm_attr_t *attr = get_irn_attr(irn);
1042
1043         assert(be_is_MemPerm(irn));
1044         assert(n < be_get_MemPerm_entity_arity(irn));
1045
1046         attr->out_entities[n] = ent;
1047 }
1048
1049 ir_entity* be_get_MemPerm_out_entity(const ir_node* irn, int n)
1050 {
1051         be_memperm_attr_t *attr = get_irn_attr(irn);
1052
1053         assert(be_is_MemPerm(irn));
1054         assert(n < be_get_MemPerm_entity_arity(irn));
1055
1056         return attr->out_entities[n];
1057 }
1058
1059 int be_get_MemPerm_entity_arity(const ir_node *irn)
1060 {
1061         return get_irn_arity(irn) - 1;
1062 }
1063
1064 void be_set_constr_single_reg(ir_node *node, int pos, const arch_register_t *reg)
1065 {
1066         arch_register_req_t *req = get_req(node, pos);
1067         const arch_register_class_t *cls = arch_register_get_class(reg);
1068         ir_graph *irg = get_irn_irg(node);
1069         struct obstack *obst = get_irg_obstack(irg);
1070         unsigned *limited_bitset;
1071
1072         assert(req->cls == NULL || req->cls == cls);
1073         assert(! (req->type & arch_register_req_type_limited));
1074         assert(req->limited == NULL);
1075
1076         limited_bitset = rbitset_obstack_alloc(obst, arch_register_class_n_regs(cls));
1077         rbitset_set(limited_bitset, arch_register_get_index(reg));
1078
1079         req->cls = cls;
1080         req->type |= arch_register_req_type_limited;
1081         req->limited = limited_bitset;
1082 }
1083
1084 void be_set_constr_limited(ir_node *node, int pos, const arch_register_req_t *req)
1085 {
1086         ir_graph *irg = get_irn_irg(node);
1087         struct obstack *obst = get_irg_obstack(irg);
1088         arch_register_req_t *r = get_req(node, pos);
1089
1090         assert(arch_register_req_is(req, limited));
1091         assert(! (req->type & (arch_register_req_type_should_be_same | arch_register_req_type_should_be_different)));
1092         memcpy(r, req, sizeof(r[0]));
1093         r->limited = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1094 }
1095
1096 void be_node_set_flags(ir_node *irn, int pos, arch_irn_flags_t flags)
1097 {
1098         be_req_t *bereq = get_be_req(irn, pos);
1099         bereq->flags = flags;
1100 }
1101
1102 void be_node_set_reg_class(ir_node *irn, int pos, const arch_register_class_t *cls)
1103 {
1104         arch_register_req_t *req = get_req(irn, pos);
1105
1106         req->cls = cls;
1107
1108         if (cls == NULL) {
1109                 req->type = arch_register_req_type_none;
1110         } else if (req->type == arch_register_req_type_none) {
1111                 req->type = arch_register_req_type_normal;
1112         }
1113 }
1114
1115 void be_node_set_req_type(ir_node *irn, int pos, arch_register_req_type_t type)
1116 {
1117         arch_register_req_t *req = get_req(irn, pos);
1118         req->type = type;
1119 }
1120
1121 ir_node *be_get_IncSP_pred(ir_node *irn) {
1122         assert(be_is_IncSP(irn));
1123         return get_irn_n(irn, 0);
1124 }
1125
1126 void be_set_IncSP_pred(ir_node *incsp, ir_node *pred) {
1127         assert(be_is_IncSP(incsp));
1128         set_irn_n(incsp, 0, pred);
1129 }
1130
1131 ir_node *be_get_IncSP_mem(ir_node *irn) {
1132         assert(be_is_IncSP(irn));
1133         return get_irn_n(irn, 1);
1134 }
1135
1136 void be_set_IncSP_offset(ir_node *irn, int offset)
1137 {
1138         be_stack_attr_t *a = get_irn_attr(irn);
1139         assert(be_is_IncSP(irn));
1140         a->offset = offset;
1141 }
1142
1143 int be_get_IncSP_offset(const ir_node *irn)
1144 {
1145         be_stack_attr_t *a = get_irn_attr(irn);
1146         assert(be_is_IncSP(irn));
1147         return a->offset;
1148 }
1149
1150 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
1151 {
1152         ir_node                     *bl        = get_nodes_block(irn);
1153         ir_graph                    *irg       = get_irn_irg(bl);
1154         ir_node                     *frame     = get_irg_frame(irg);
1155         const arch_register_class_t *cls       = arch_get_irn_reg_class(arch_env, irn, -1);
1156         const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1157         ir_node                     *spill;
1158
1159         spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
1160         return spill;
1161 }
1162
1163 ir_node *be_reload(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_node *insert, ir_mode *mode, ir_node *spill)
1164 {
1165         ir_node  *reload;
1166         ir_node  *bl    = is_Block(insert) ? insert : get_nodes_block(insert);
1167         ir_graph *irg   = get_irn_irg(bl);
1168         ir_node  *frame = get_irg_frame(irg);
1169         const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
1170
1171         assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
1172
1173         reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
1174
1175         if (is_Block(insert)) {
1176                 insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
1177                 sched_add_after(insert, reload);
1178         } else {
1179                 sched_add_before(insert, reload);
1180         }
1181
1182         return reload;
1183 }
1184
1185 /*
1186   ____              ____
1187  |  _ \ ___  __ _  |  _ \ ___  __ _ ___
1188  | |_) / _ \/ _` | | |_) / _ \/ _` / __|
1189  |  _ <  __/ (_| | |  _ <  __/ (_| \__ \
1190  |_| \_\___|\__, | |_| \_\___|\__, |___/
1191             |___/                |_|
1192
1193 */
1194
1195
1196 static const
1197 arch_register_req_t *get_out_reg_req(const ir_node *irn, int out_pos)
1198 {
1199         const be_node_attr_t *a = get_irn_attr(irn);
1200
1201         if(out_pos >= ARR_LEN(a->reg_data)) {
1202                 return arch_no_register_req;
1203         }
1204
1205         return &a->reg_data[out_pos].req.req;
1206 }
1207
1208 static const
1209 arch_register_req_t *get_in_reg_req(const ir_node *irn, int pos)
1210 {
1211         const be_node_attr_t *a = get_irn_attr(irn);
1212
1213         if(pos >= get_irn_arity(irn) || pos >= ARR_LEN(a->reg_data))
1214                 return arch_no_register_req;
1215
1216         return &a->reg_data[pos].in_req.req;
1217 }
1218
1219 static const arch_register_req_t *
1220 be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
1221 {
1222         int out_pos = pos;
1223
1224         (void) self;
1225         if (pos < 0) {
1226                 if (get_irn_mode(irn) == mode_T)
1227                         return arch_no_register_req;
1228
1229                 out_pos = redir_proj((const ir_node **)&irn);
1230                 assert(is_be_node(irn));
1231                 return get_out_reg_req(irn, out_pos);
1232         } else if (is_be_node(irn)) {
1233                 /*
1234                  * For spills and reloads, we return "none" as requirement for frame
1235                  * pointer, so every input is ok. Some backends need this (e.g. STA).
1236                  */
1237                 if ((be_is_Spill(irn)  && pos == be_pos_Spill_frame) ||
1238                                 (be_is_Reload(irn) && pos == be_pos_Reload_frame))
1239                         return arch_no_register_req;
1240
1241                 return get_in_reg_req(irn, pos);
1242         }
1243
1244         return arch_no_register_req;
1245 }
1246
1247 const arch_register_t *
1248 be_node_get_irn_reg(const void *self, const ir_node *irn)
1249 {
1250         be_reg_data_t *r;
1251
1252         (void) self;
1253         if (get_irn_mode(irn) == mode_T)
1254                 return NULL;
1255         r = retrieve_reg_data(irn);
1256         return r->reg;
1257 }
1258
1259 static arch_irn_class_t be_node_classify(const void *self, const ir_node *irn)
1260 {
1261         redir_proj((const ir_node **) &irn);
1262
1263         (void) self;
1264         switch(be_get_irn_opcode(irn)) {
1265 #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
1266                 XXX(Spill, spill);
1267                 XXX(Reload, reload);
1268                 XXX(Perm, perm);
1269                 XXX(Copy, copy);
1270                 XXX(Return, branch);
1271                 XXX(StackParam, stackparam);
1272 #undef XXX
1273                 default:
1274                 return arch_irn_class_normal;
1275         }
1276
1277         return 0;
1278 }
1279
1280 static arch_irn_flags_t be_node_get_flags(const void *self, const ir_node *node)
1281 {
1282         be_req_t *bereq;
1283         int pos = -1;
1284         (void) self;
1285
1286         if(is_Proj(node)) {
1287                 pos = OUT_POS(get_Proj_proj(node));
1288                 node = skip_Proj_const(node);
1289         }
1290
1291         bereq = get_be_req(node, pos);
1292
1293         return bereq->flags;
1294 }
1295
1296 static ir_entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
1297 {
1298         (void) self;
1299         return be_get_frame_entity(irn);
1300 }
1301
1302 static void be_node_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1303 {
1304         be_frame_attr_t *a;
1305         (void) self;
1306
1307         assert(be_has_frame_entity(irn));
1308
1309         a = get_irn_attr(irn);
1310         a->ent = ent;
1311 }
1312
1313 static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
1314 {
1315         (void) self;
1316         if(be_has_frame_entity(irn)) {
1317                 be_frame_attr_t *a = get_irn_attr(irn);
1318                 a->offset = offset;
1319         }
1320 }
1321
1322 static int be_node_get_sp_bias(const void *self, const ir_node *irn)
1323 {
1324         (void) self;
1325         return be_is_IncSP(irn) ? be_get_IncSP_offset(irn) : 0;
1326 }
1327
1328 /*
1329   ___ ____  _   _   _   _                 _ _
1330  |_ _|  _ \| \ | | | | | | __ _ _ __   __| | | ___ _ __
1331   | || |_) |  \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1332   | ||  _ <| |\  | |  _  | (_| | | | | (_| | |  __/ |
1333  |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1334
1335 */
1336
1337 static const arch_irn_ops_if_t be_node_irn_ops_if = {
1338         be_node_get_irn_reg_req,
1339         be_node_set_irn_reg,
1340         be_node_get_irn_reg,
1341         be_node_classify,
1342         be_node_get_flags,
1343         be_node_get_frame_entity,
1344         be_node_set_frame_entity,
1345         be_node_set_frame_offset,
1346         be_node_get_sp_bias,
1347         NULL,    /* get_inverse             */
1348         NULL,    /* get_op_estimated_cost   */
1349         NULL,    /* possible_memory_operand */
1350         NULL,    /* perform_memory_operand  */
1351 };
1352
1353 static const arch_irn_ops_t be_node_irn_ops = {
1354         &be_node_irn_ops_if
1355 };
1356
1357 const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
1358 {
1359         redir_proj((const ir_node **) &irn);
1360         (void) self;
1361         return is_be_node(irn) ? &be_node_irn_ops : NULL;
1362 }
1363
1364 const arch_irn_handler_t be_node_irn_handler = {
1365         be_node_get_irn_ops
1366 };
1367
1368 /*
1369   ____  _     _   ___ ____  _   _   _   _                 _ _
1370  |  _ \| |__ (_) |_ _|  _ \| \ | | | | | | __ _ _ __   __| | | ___ _ __
1371  | |_) | '_ \| |  | || |_) |  \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
1372  |  __/| | | | |  | ||  _ <| |\  | |  _  | (_| | | | | (_| | |  __/ |
1373  |_|   |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
1374
1375 */
1376
1377 typedef struct {
1378         const arch_register_t *reg;
1379         arch_register_req_t    req;
1380         arch_irn_flags_t       flags;
1381 } phi_attr_t;
1382
1383 typedef struct {
1384         arch_irn_handler_t irn_handler;
1385         arch_irn_ops_t     irn_ops;
1386         const arch_env_t   *arch_env;
1387         pmap               *phi_attrs;
1388 } phi_handler_t;
1389
1390 #define get_phi_handler_from_handler(h)  container_of(h, phi_handler_t, irn_handler)
1391 #define get_phi_handler_from_ops(h)      container_of(h, phi_handler_t, irn_ops)
1392
1393 static
1394 const void *phi_get_irn_ops(const arch_irn_handler_t *handler,
1395                             const ir_node *irn)
1396 {
1397         const phi_handler_t *h;
1398         if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
1399                 return NULL;
1400
1401         h = get_phi_handler_from_handler(handler);
1402         return &h->irn_ops;
1403 }
1404
1405 static INLINE
1406 phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
1407 {
1408         phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
1409         if(attr == NULL) {
1410                 ir_graph *irg = get_irn_irg(phi);
1411                 struct obstack *obst = get_irg_obstack(irg);
1412                 attr = obstack_alloc(obst, sizeof(attr[0]));
1413                 memset(attr, 0, sizeof(attr[0]));
1414                 pmap_insert(handler->phi_attrs, phi, attr);
1415         }
1416
1417         return attr;
1418 }
1419
1420 /**
1421  * Get register class of a Phi.
1422  */
1423 static
1424 const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h,
1425                                                      const ir_node *phi,
1426                                                      pset **visited)
1427 {
1428         int n = get_irn_arity(phi);
1429         ir_node *op;
1430         int i;
1431
1432         if(*visited && pset_find_ptr(*visited, phi))
1433                 return NULL;
1434
1435         for(i = 0; i < n; ++i) {
1436                 op = get_irn_n(phi, i);
1437                 /* Matze: don't we unnecessary constraint our phis with this?
1438                  * we only need to take the regclass IMO*/
1439                 if(!is_Phi(op))
1440                         return arch_get_register_req(h->arch_env, op, BE_OUT_POS(0));
1441         }
1442
1443         /*
1444          * The operands of that Phi were all Phis themselves.
1445          * We have to start a DFS for a non-Phi argument now.
1446          */
1447         if(!*visited)
1448                 *visited = pset_new_ptr(16);
1449
1450         pset_insert_ptr(*visited, phi);
1451
1452         for(i = 0; i < n; ++i) {
1453                 const arch_register_req_t *req;
1454                 op = get_irn_n(phi, i);
1455                 req = get_Phi_reg_req_recursive(h, op, visited);
1456                 if(req != NULL)
1457                         return req;
1458         }
1459
1460         return NULL;
1461 }
1462
1463 static
1464 const arch_register_req_t *phi_get_irn_reg_req(const void *self,
1465                                                const ir_node *irn, int pos)
1466 {
1467         phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
1468         phi_attr_t *attr;
1469         (void) self;
1470         (void) pos;
1471
1472         if(!mode_is_datab(get_irn_mode(irn)))
1473                 return arch_no_register_req;
1474
1475         attr = get_Phi_attr(phi_handler, irn);
1476
1477         if(attr->req.type == arch_register_req_type_none) {
1478                 pset *visited = NULL;
1479                 const arch_register_req_t *req;
1480                 req = get_Phi_reg_req_recursive(phi_handler, irn, &visited);
1481
1482                 memcpy(&attr->req, req, sizeof(req[0]));
1483                 assert(attr->req.cls != NULL);
1484                 attr->req.type = arch_register_req_type_normal;
1485
1486                 if(visited != NULL)
1487                         del_pset(visited);
1488         }
1489
1490         return &attr->req;
1491 }
1492
1493 void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
1494                         const arch_register_req_t *req)
1495 {
1496         const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1497         const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1498         phi_attr_t *attr;
1499
1500         assert(mode_is_datab(get_irn_mode(node)));
1501
1502         attr = get_Phi_attr(handler, node);
1503         memcpy(&attr->req, req, sizeof(req[0]));
1504 }
1505
1506 void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
1507                       arch_irn_flags_t flags)
1508 {
1509         const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
1510         const phi_handler_t *handler = get_phi_handler_from_ops(ops);
1511         phi_attr_t *attr;
1512
1513         assert(mode_is_datab(get_irn_mode(node)));
1514
1515         attr = get_Phi_attr(handler, node);
1516         attr->flags = flags;
1517 }
1518
1519 static
1520 void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
1521 {
1522         phi_handler_t *h = get_phi_handler_from_ops(self);
1523         phi_attr_t *attr = get_Phi_attr(h, irn);
1524         attr->reg = reg;
1525 }
1526
1527 static
1528 const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
1529 {
1530         phi_handler_t *h = get_phi_handler_from_ops(self);
1531         phi_attr_t *attr = get_Phi_attr(h, irn);
1532         return attr->reg;
1533 }
1534
1535 static
1536 arch_irn_class_t phi_classify(const void *self, const ir_node *irn)
1537 {
1538         (void) self;
1539         (void) irn;
1540         return arch_irn_class_normal;
1541 }
1542
1543 static
1544 arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
1545 {
1546         phi_handler_t *h = get_phi_handler_from_ops(self);
1547         phi_attr_t *attr = get_Phi_attr(h, irn);
1548         (void) self;
1549         return attr->flags;
1550 }
1551
1552 static
1553 ir_entity *phi_get_frame_entity(const void *self, const ir_node *irn)
1554 {
1555         (void) self;
1556         (void) irn;
1557         return NULL;
1558 }
1559
1560 static
1561 void phi_set_frame_entity(const void *self, ir_node *irn, ir_entity *ent)
1562 {
1563         (void) self;
1564         (void) irn;
1565         (void) ent;
1566         assert(0);
1567 }
1568
1569 static
1570 void phi_set_frame_offset(const void *self, ir_node *irn, int bias)
1571 {
1572         (void) self;
1573         (void) irn;
1574         (void) bias;
1575         assert(0);
1576 }
1577
1578 static
1579 int phi_get_sp_bias(const void* self, const ir_node *irn)
1580 {
1581         (void) self;
1582         (void) irn;
1583         return 0;
1584 }
1585
1586 static
1587 const arch_irn_ops_if_t phi_irn_ops = {
1588         phi_get_irn_reg_req,
1589         phi_set_irn_reg,
1590         phi_get_irn_reg,
1591         phi_classify,
1592         phi_get_flags,
1593         phi_get_frame_entity,
1594         phi_set_frame_entity,
1595         phi_set_frame_offset,
1596         phi_get_sp_bias,
1597         NULL,    /* get_inverse             */
1598         NULL,    /* get_op_estimated_cost   */
1599         NULL,    /* possible_memory_operand */
1600         NULL,    /* perform_memory_operand  */
1601 };
1602
1603 arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
1604 {
1605         phi_handler_t *h           = xmalloc(sizeof(h[0]));
1606         h->irn_handler.get_irn_ops = phi_get_irn_ops;
1607         h->irn_ops.impl            = &phi_irn_ops;
1608         h->arch_env                = arch_env;
1609         h->phi_attrs               = pmap_create();
1610         return (arch_irn_handler_t *) h;
1611 }
1612
1613 void be_phi_handler_free(arch_irn_handler_t *handler)
1614 {
1615         phi_handler_t *h = get_phi_handler_from_handler(handler);
1616         pmap_destroy(h->phi_attrs);
1617         h->phi_attrs = NULL;
1618         free(handler);
1619 }
1620
1621 void be_phi_handler_reset(arch_irn_handler_t *handler)
1622 {
1623         phi_handler_t *h = get_phi_handler_from_handler(handler);
1624         if(h->phi_attrs)
1625                 pmap_destroy(h->phi_attrs);
1626         h->phi_attrs = pmap_create();
1627 }
1628
1629 /*
1630   _   _           _        ____                        _
1631  | \ | | ___   __| | ___  |  _ \ _   _ _ __ ___  _ __ (_)_ __   __ _
1632  |  \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
1633  | |\  | (_) | (_| |  __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
1634  |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
1635                                                 |_|            |___/
1636 */
1637
1638 /**
1639  * Dumps a register requirement to a file.
1640  */
1641 static void dump_node_req(FILE *f, int idx, const arch_register_req_t *req,
1642                           const ir_node *node)
1643 {
1644         int did_something = 0;
1645         char buf[16];
1646         const char *prefix = buf;
1647
1648         snprintf(buf, sizeof(buf), "#%d ", idx);
1649         buf[sizeof(buf) - 1] = '\0';
1650
1651         if(req->cls != 0) {
1652                 char tmp[256];
1653                 fprintf(f, prefix);
1654                 arch_register_req_format(tmp, sizeof(tmp), req, node);
1655                 fprintf(f, "%s", tmp);
1656                 did_something = 1;
1657         }
1658
1659         if(did_something)
1660                 fprintf(f, "\n");
1661 }
1662
1663 /**
1664  * Dumps node register requirements to a file.
1665  */
1666 static void dump_node_reqs(FILE *f, ir_node *node)
1667 {
1668         int i;
1669         be_node_attr_t *a = get_irn_attr(node);
1670         int len = ARR_LEN(a->reg_data);
1671
1672         fprintf(f, "registers: \n");
1673         for(i = 0; i < len; ++i) {
1674                 be_reg_data_t *rd = &a->reg_data[i];
1675                 if(rd->reg)
1676                         fprintf(f, "#%d: %s\n", i, rd->reg->name);
1677         }
1678
1679         fprintf(f, "in requirements:\n");
1680         for(i = 0; i < len; ++i) {
1681                 dump_node_req(f, i, &a->reg_data[i].in_req.req, node);
1682         }
1683
1684         fprintf(f, "\nout requirements:\n");
1685         for(i = 0; i < len; ++i) {
1686                 dump_node_req(f, i, &a->reg_data[i].req.req, node);
1687         }
1688 }
1689
1690 /**
1691  * ir_op-Operation: dump a be node to file
1692  */
1693 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
1694 {
1695         be_node_attr_t *at = get_irn_attr(irn);
1696
1697         assert(is_be_node(irn));
1698
1699         switch(reason) {
1700                 case dump_node_opcode_txt:
1701                         fprintf(f, get_op_name(get_irn_op(irn)));
1702                         break;
1703                 case dump_node_mode_txt:
1704                         fprintf(f, get_mode_name(get_irn_mode(irn)));
1705                         break;
1706                 case dump_node_nodeattr_txt:
1707                         if(be_is_Call(irn)) {
1708                                 be_call_attr_t *a = (be_call_attr_t *) at;
1709                                 if (a->ent)
1710                                         fprintf(f, " [%s] ", get_entity_name(a->ent));
1711                         }
1712                         break;
1713                 case dump_node_info_txt:
1714                         dump_node_reqs(f, irn);
1715
1716                         if(be_has_frame_entity(irn)) {
1717                                 be_frame_attr_t *a = (be_frame_attr_t *) at;
1718                                 if (a->ent) {
1719                                         int bits = get_type_size_bits(get_entity_type(a->ent));
1720                                         ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
1721                                           a->ent, a->offset, a->offset, bits, bits);
1722                                 }
1723
1724                         }
1725
1726                         switch(be_get_irn_opcode(irn)) {
1727                         case beo_IncSP:
1728                                 {
1729                                         be_stack_attr_t *a = (be_stack_attr_t *) at;
1730                                         if (a->offset == BE_STACK_FRAME_SIZE_EXPAND)
1731                                                 fprintf(f, "offset: FRAME_SIZE\n");
1732                                         else if(a->offset == BE_STACK_FRAME_SIZE_SHRINK)
1733                                                 fprintf(f, "offset: -FRAME SIZE\n");
1734                                         else
1735                                                 fprintf(f, "offset: %u\n", a->offset);
1736                                 }
1737                                 break;
1738                         case beo_Call:
1739                                 {
1740                                         be_call_attr_t *a = (be_call_attr_t *) at;
1741
1742                                         if (a->ent)
1743                                                 fprintf(f, "\ncalling: %s\n", get_entity_name(a->ent));
1744                                 }
1745                                 break;
1746                         case beo_MemPerm:
1747                                 {
1748                                         int i;
1749                                         for(i = 0; i < be_get_MemPerm_entity_arity(irn); ++i) {
1750                                                 ir_entity *in, *out;
1751                                                 in = be_get_MemPerm_in_entity(irn, i);
1752                                                 out = be_get_MemPerm_out_entity(irn, i);
1753                                                 if(in) {
1754                                                         fprintf(f, "\nin[%d]: %s\n", i, get_entity_name(in));
1755                                                 }
1756                                                 if(out) {
1757                                                         fprintf(f, "\nout[%d]: %s\n", i, get_entity_name(out));
1758                                                 }
1759                                         }
1760                                 }
1761                                 break;
1762
1763                         default:
1764                                 break;
1765                         }
1766         }
1767
1768         return 0;
1769 }
1770
1771 /**
1772  * ir_op-Operation:
1773  * Copies the backend specific attributes from old node to new node.
1774  */
1775 static void copy_attr(const ir_node *old_node, ir_node *new_node)
1776 {
1777         be_node_attr_t *old_attr = get_irn_attr(old_node);
1778         be_node_attr_t *new_attr = get_irn_attr(new_node);
1779         struct obstack *obst = get_irg_obstack(get_irn_irg(new_node));
1780         unsigned i, len;
1781
1782         assert(is_be_node(old_node));
1783         assert(is_be_node(new_node));
1784
1785         memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
1786         new_attr->reg_data = NULL;
1787
1788         if(old_attr->reg_data != NULL)
1789                 len = ARR_LEN(old_attr->reg_data);
1790         else
1791                 len = 0;
1792
1793         if(get_irn_op(old_node)->opar == oparity_dynamic
1794                         || be_is_RegParams(old_node)) {
1795                 new_attr->reg_data = NEW_ARR_F(be_reg_data_t, len);
1796         } else {
1797                 new_attr->reg_data = NEW_ARR_D(be_reg_data_t, obst, len);
1798         }
1799
1800         if(len > 0) {
1801                 memcpy(new_attr->reg_data, old_attr->reg_data, len * sizeof(be_reg_data_t));
1802                 for(i = 0; i < len; ++i) {
1803                         const be_reg_data_t *rd = &old_attr->reg_data[i];
1804                         be_reg_data_t *newrd = &new_attr->reg_data[i];
1805                         if(arch_register_req_is(&rd->req.req, limited)) {
1806                                 const arch_register_req_t *req = &rd->req.req;
1807                                 arch_register_req_t *new_req = &newrd->req.req;
1808                                 new_req->limited
1809                                         = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1810                         }
1811                         if(arch_register_req_is(&rd->in_req.req, limited)) {
1812                                 const arch_register_req_t *req = &rd->in_req.req;
1813                                 arch_register_req_t *new_req = &newrd->in_req.req;
1814                                 new_req->limited
1815                                         = rbitset_duplicate_obstack_alloc(obst, req->limited, req->cls->n_regs);
1816                         }
1817                 }
1818         }
1819 }
1820
1821 static const ir_op_ops be_node_op_ops = {
1822         NULL,
1823         NULL,
1824         NULL,
1825         NULL,
1826         NULL,
1827         copy_attr,
1828         NULL,
1829         NULL,
1830         NULL,
1831         NULL,
1832         NULL,
1833         dump_node,
1834         NULL
1835 };