4d1ef81eee640b2ba789008c1584a92ba6d56d7f
[libfirm] / ir / ir / irnode.c
1 /*
2  * Copyright (C) 1995-2008 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   Representation of an intermediate operation.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  * @version $Id$
25  */
26 #include "config.h"
27
28 #include <string.h>
29
30 #include "pset_new.h"
31 #include "ident.h"
32 #include "irnode_t.h"
33 #include "irgraph_t.h"
34 #include "irmode_t.h"
35 #include "irbackedge_t.h"
36 #include "irdump.h"
37 #include "irop_t.h"
38 #include "irprog_t.h"
39 #include "iredgekinds.h"
40 #include "iredges_t.h"
41 #include "ircons.h"
42
43 #include "irhooks.h"
44 #include "irtools.h"
45
46 #include "beinfo.h"
47
48 /* some constants fixing the positions of nodes predecessors
49    in the in array */
50 #define CALL_PARAM_OFFSET     2
51 #define BUILDIN_PARAM_OFFSET  1
52 #define SEL_INDEX_OFFSET      2
53 #define RETURN_RESULT_OFFSET  1  /* mem is not a result */
54 #define END_KEEPALIVE_OFFSET  0
55
56 static const char *pnc_name_arr [] = {
57         "pn_Cmp_False", "pn_Cmp_Eq", "pn_Cmp_Lt", "pn_Cmp_Le",
58         "pn_Cmp_Gt", "pn_Cmp_Ge", "pn_Cmp_Lg", "pn_Cmp_Leg",
59         "pn_Cmp_Uo", "pn_Cmp_Ue", "pn_Cmp_Ul", "pn_Cmp_Ule",
60         "pn_Cmp_Ug", "pn_Cmp_Uge", "pn_Cmp_Ne", "pn_Cmp_True"
61 };
62
63 /**
64  * returns the pnc name from an pnc constant
65  */
66 const char *get_pnc_string(int pnc)
67 {
68         assert(pnc >= 0 && pnc <
69                         (int) (sizeof(pnc_name_arr)/sizeof(pnc_name_arr[0])));
70         return pnc_name_arr[pnc];
71 }
72
73 /*
74  * Calculates the negated (Complement(R)) pnc condition.
75  */
76 pn_Cmp get_negated_pnc(long pnc, ir_mode *mode)
77 {
78         pnc ^= pn_Cmp_True;
79
80         /* do NOT add the Uo bit for non-floating point values */
81         if (! mode_is_float(mode))
82                 pnc &= ~pn_Cmp_Uo;
83
84         return (pn_Cmp) pnc;
85 }
86
87 /* Calculates the inversed (R^-1) pnc condition, i.e., "<" --> ">" */
88 pn_Cmp get_inversed_pnc(long pnc)
89 {
90         long code    = pnc & ~(pn_Cmp_Lt|pn_Cmp_Gt);
91         long lesser  = pnc & pn_Cmp_Lt;
92         long greater = pnc & pn_Cmp_Gt;
93
94         code |= (lesser ? pn_Cmp_Gt : 0) | (greater ? pn_Cmp_Lt : 0);
95
96         return (pn_Cmp) code;
97 }
98
99 /**
100  * Indicates, whether additional data can be registered to ir nodes.
101  * If set to 1, this is not possible anymore.
102  */
103 static int forbid_new_data = 0;
104
105 /**
106  * The amount of additional space for custom data to be allocated upon
107  * creating a new node.
108  */
109 unsigned firm_add_node_size = 0;
110
111
112 /* register new space for every node */
113 unsigned firm_register_additional_node_data(unsigned size)
114 {
115         assert(!forbid_new_data && "Too late to register additional node data");
116
117         if (forbid_new_data)
118                 return 0;
119
120         return firm_add_node_size += size;
121 }
122
123
124 void init_irnode(void)
125 {
126         /* Forbid the addition of new data to an ir node. */
127         forbid_new_data = 1;
128 }
129
130 struct struct_align {
131         char c;
132         struct s {
133                 int i;
134                 float f;
135                 double d;
136         } s;
137 };
138
139 /*
140  * irnode constructor.
141  * Create a new irnode in irg, with an op, mode, arity and
142  * some incoming irnodes.
143  * If arity is negative, a node with a dynamic array is created.
144  */
145 ir_node *new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op,
146                      ir_mode *mode, int arity, ir_node **in)
147 {
148         ir_node *res;
149         unsigned align = offsetof(struct struct_align, s) - 1;
150         unsigned add_node_size = (firm_add_node_size + align) & ~align;
151         size_t node_size = offsetof(ir_node, attr) + op->attr_size + add_node_size;
152         char *p;
153         int i;
154
155         assert(irg);
156         assert(op);
157         assert(mode);
158         p = obstack_alloc(irg->obst, node_size);
159         memset(p, 0, node_size);
160         res = (ir_node *)(p + add_node_size);
161
162         res->kind     = k_ir_node;
163         res->op       = op;
164         res->mode     = mode;
165         res->visited  = 0;
166         res->node_idx = irg_register_node_idx(irg, res);
167         res->link     = NULL;
168         res->deps     = NULL;
169
170         if (arity < 0) {
171                 res->in = NEW_ARR_F(ir_node *, 1);  /* 1: space for block */
172         } else {
173                 /* not nice but necessary: End and Sync must always have a flexible array */
174                 if (op == op_End || op == op_Sync)
175                         res->in = NEW_ARR_F(ir_node *, (arity+1));
176                 else
177                         res->in = NEW_ARR_D(ir_node *, irg->obst, (arity+1));
178                 memcpy(&res->in[1], in, sizeof(ir_node *) * arity);
179         }
180
181         res->in[0]   = block;
182         set_irn_dbg_info(res, db);
183         res->out     = NULL;
184         res->node_nr = get_irp_new_node_nr();
185
186         for (i = 0; i < EDGE_KIND_LAST; ++i) {
187                 INIT_LIST_HEAD(&res->edge_info[i].outs_head);
188                 /* edges will be build immediately */
189                 res->edge_info[i].edges_built = 1;
190                 res->edge_info[i].out_count = 0;
191         }
192
193         /* don't put this into the for loop, arity is -1 for some nodes! */
194         edges_notify_edge(res, -1, res->in[0], NULL, irg);
195         for (i = 1; i <= arity; ++i)
196                 edges_notify_edge(res, i - 1, res->in[i], NULL, irg);
197
198         hook_new_node(irg, res);
199         if (get_irg_phase_state(irg) == phase_backend) {
200                 be_info_new_node(res);
201         }
202
203         return res;
204 }
205
206 /*-- getting some parameters from ir_nodes --*/
207
208 int (is_ir_node)(const void *thing)
209 {
210         return _is_ir_node(thing);
211 }
212
213 int (get_irn_intra_arity)(const ir_node *node)
214 {
215         return _get_irn_intra_arity(node);
216 }
217
218 int (get_irn_inter_arity)(const ir_node *node)
219 {
220         return _get_irn_inter_arity(node);
221 }
222
223 int (*_get_irn_arity)(const ir_node *node) = _get_irn_intra_arity;
224
225 int (get_irn_arity)(const ir_node *node)
226 {
227         return _get_irn_arity(node);
228 }
229
230 /* Returns the array with ins. This array is shifted with respect to the
231    array accessed by get_irn_n: The block operand is at position 0 not -1.
232    (@@@ This should be changed.)
233    The order of the predecessors in this array is not guaranteed, except that
234    lists of operands as predecessors of Block or arguments of a Call are
235    consecutive. */
236 ir_node **get_irn_in(const ir_node *node)
237 {
238         assert(node);
239 #ifdef INTERPROCEDURAL_VIEW
240         if (get_interprocedural_view()) { /* handle Filter and Block specially */
241                 if (get_irn_opcode(node) == iro_Filter) {
242                         assert(node->attr.filter.in_cg);
243                         return node->attr.filter.in_cg;
244                 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
245                         return node->attr.block.in_cg;
246                 }
247                 /* else fall through */
248         }
249 #endif /* INTERPROCEDURAL_VIEW */
250         return node->in;
251 }
252
253 void set_irn_in(ir_node *node, int arity, ir_node **in)
254 {
255         int i;
256         ir_node *** pOld_in;
257         ir_graph *irg = get_irn_irg(node);
258
259         assert(node);
260 #ifdef INTERPROCEDURAL_VIEW
261         if (get_interprocedural_view()) { /* handle Filter and Block specially */
262                 ir_opcode code = get_irn_opcode(node);
263                 if (code  == iro_Filter) {
264                         assert(node->attr.filter.in_cg);
265                         pOld_in = &node->attr.filter.in_cg;
266                 } else if (code == iro_Block && node->attr.block.in_cg) {
267                         pOld_in = &node->attr.block.in_cg;
268                 } else {
269                         pOld_in = &node->in;
270                 }
271         } else
272 #endif /* INTERPROCEDURAL_VIEW */
273                 pOld_in = &node->in;
274
275
276         for (i = 0; i < arity; i++) {
277                 if (i < ARR_LEN(*pOld_in)-1)
278                         edges_notify_edge(node, i, in[i], (*pOld_in)[i+1], irg);
279                 else
280                         edges_notify_edge(node, i, in[i], NULL,            irg);
281         }
282         for (;i < ARR_LEN(*pOld_in)-1; i++) {
283                 edges_notify_edge(node, i, NULL, (*pOld_in)[i+1], irg);
284         }
285
286         if (arity != ARR_LEN(*pOld_in) - 1) {
287                 ir_node * block = (*pOld_in)[0];
288                 *pOld_in = NEW_ARR_D(ir_node *, irg->obst, arity + 1);
289                 (*pOld_in)[0] = block;
290         }
291         fix_backedges(irg->obst, node);
292
293         memcpy((*pOld_in) + 1, in, sizeof(ir_node *) * arity);
294 }
295
296 ir_node *(get_irn_intra_n)(const ir_node *node, int n)
297 {
298         return _get_irn_intra_n(node, n);
299 }
300
301 ir_node *(get_irn_inter_n)(const ir_node *node, int n)
302 {
303         return _get_irn_inter_n(node, n);
304 }
305
306 ir_node *(*_get_irn_n)(const ir_node *node, int n) = _get_irn_intra_n;
307
308 ir_node *(get_irn_n)(const ir_node *node, int n)
309 {
310         return _get_irn_n(node, n);
311 }
312
313 void set_irn_n(ir_node *node, int n, ir_node *in)
314 {
315         assert(node && node->kind == k_ir_node);
316         assert(-1 <= n);
317         assert(n < get_irn_arity(node));
318         assert(in && in->kind == k_ir_node);
319
320 #ifdef INTERPROCEDURAL_VIEW
321         if ((n == -1) && (get_irn_opcode(node) == iro_Filter)) {
322                 /* Change block pred in both views! */
323                 node->in[n + 1] = in;
324                 assert(node->attr.filter.in_cg);
325                 node->attr.filter.in_cg[n + 1] = in;
326                 return;
327         }
328         if (get_interprocedural_view()) { /* handle Filter and Block specially */
329                 if (get_irn_opcode(node) == iro_Filter) {
330                         assert(node->attr.filter.in_cg);
331                         node->attr.filter.in_cg[n + 1] = in;
332                         return;
333                 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
334                         node->attr.block.in_cg[n + 1] = in;
335                         return;
336                 }
337                 /* else fall through */
338         }
339 #endif /* INTERPROCEDURAL_VIEW */
340
341         /* Call the hook */
342         hook_set_irn_n(node, n, in, node->in[n + 1]);
343
344         /* Here, we rely on src and tgt being in the current ir graph */
345         edges_notify_edge(node, n, in, node->in[n + 1], current_ir_graph);
346
347         node->in[n + 1] = in;
348 }
349
350 int add_irn_n(ir_node *node, ir_node *in)
351 {
352         int pos;
353         ir_graph *irg = get_irn_irg(node);
354
355         assert(node->op->opar == oparity_dynamic);
356         pos = ARR_LEN(node->in) - 1;
357         ARR_APP1(ir_node *, node->in, in);
358         edges_notify_edge(node, pos, node->in[pos + 1], NULL, irg);
359
360         /* Call the hook */
361         hook_set_irn_n(node, pos, node->in[pos + 1], NULL);
362
363         return pos;
364 }
365
366 void del_Sync_n(ir_node *n, int i)
367 {
368         int      arity     = get_Sync_n_preds(n);
369         ir_node *last_pred = get_Sync_pred(n, arity - 1);
370         set_Sync_pred(n, i, last_pred);
371         edges_notify_edge(n, arity - 1, NULL, last_pred, get_irn_irg(n));
372         ARR_SHRINKLEN(get_irn_in(n), arity);
373 }
374
375 int (get_irn_deps)(const ir_node *node)
376 {
377         return _get_irn_deps(node);
378 }
379
380 ir_node *(get_irn_dep)(const ir_node *node, int pos)
381 {
382         return _get_irn_dep(node, pos);
383 }
384
385 void (set_irn_dep)(ir_node *node, int pos, ir_node *dep)
386 {
387         _set_irn_dep(node, pos, dep);
388 }
389
390 int add_irn_dep(ir_node *node, ir_node *dep)
391 {
392         int res = 0;
393
394         /* DEP edges are only allowed in backend phase */
395         assert(get_irg_phase_state(get_irn_irg(node)) == phase_backend);
396         if (node->deps == NULL) {
397                 node->deps = NEW_ARR_F(ir_node *, 1);
398                 node->deps[0] = dep;
399         } else {
400                 int i, n;
401                 int first_zero = -1;
402
403                 for (i = 0, n = ARR_LEN(node->deps); i < n; ++i) {
404                         if (node->deps[i] == NULL)
405                                 first_zero = i;
406
407                         if (node->deps[i] == dep)
408                                 return i;
409                 }
410
411                 if (first_zero >= 0) {
412                         node->deps[first_zero] = dep;
413                         res = first_zero;
414                 } else {
415                         ARR_APP1(ir_node *, node->deps, dep);
416                         res = n;
417                 }
418         }
419
420         edges_notify_edge_kind(node, res, dep, NULL, EDGE_KIND_DEP, get_irn_irg(node));
421
422         return res;
423 }
424
425 void add_irn_deps(ir_node *tgt, ir_node *src)
426 {
427         int i, n;
428
429         for (i = 0, n = get_irn_deps(src); i < n; ++i)
430                 add_irn_dep(tgt, get_irn_dep(src, i));
431 }
432
433
434 ir_mode *(get_irn_mode)(const ir_node *node)
435 {
436         return _get_irn_mode(node);
437 }
438
439 void (set_irn_mode)(ir_node *node, ir_mode *mode)
440 {
441         _set_irn_mode(node, mode);
442 }
443
444 /** Gets the string representation of the mode .*/
445 const char *get_irn_modename(const ir_node *node)
446 {
447         assert(node);
448         return get_mode_name(node->mode);
449 }
450
451 ident *get_irn_modeident(const ir_node *node)
452 {
453         assert(node);
454         return get_mode_ident(node->mode);
455 }
456
457 ir_op *(get_irn_op)(const ir_node *node)
458 {
459         return _get_irn_op(node);
460 }
461
462 /* should be private to the library: */
463 void (set_irn_op)(ir_node *node, ir_op *op)
464 {
465         _set_irn_op(node, op);
466 }
467
468 unsigned (get_irn_opcode)(const ir_node *node)
469 {
470         return _get_irn_opcode(node);
471 }
472
473 const char *get_irn_opname(const ir_node *node)
474 {
475         assert(node);
476         if (is_Phi0(node)) return "Phi0";
477         return get_id_str(node->op->name);
478 }
479
480 ident *get_irn_opident(const ir_node *node)
481 {
482         assert(node);
483         return node->op->name;
484 }
485
486 ir_visited_t (get_irn_visited)(const ir_node *node)
487 {
488         return _get_irn_visited(node);
489 }
490
491 void (set_irn_visited)(ir_node *node, ir_visited_t visited)
492 {
493         _set_irn_visited(node, visited);
494 }
495
496 void (mark_irn_visited)(ir_node *node)
497 {
498         _mark_irn_visited(node);
499 }
500
501 int (irn_visited)(const ir_node *node)
502 {
503         return _irn_visited(node);
504 }
505
506 int (irn_visited_else_mark)(ir_node *node)
507 {
508         return _irn_visited_else_mark(node);
509 }
510
511 void (set_irn_link)(ir_node *node, void *link)
512 {
513         _set_irn_link(node, link);
514 }
515
516 void *(get_irn_link)(const ir_node *node)
517 {
518         return _get_irn_link(node);
519 }
520
521 op_pin_state (get_irn_pinned)(const ir_node *node)
522 {
523         return _get_irn_pinned(node);
524 }
525
526 op_pin_state (is_irn_pinned_in_irg) (const ir_node *node)
527 {
528         return _is_irn_pinned_in_irg(node);
529 }
530
531 void set_irn_pinned(ir_node *node, op_pin_state state)
532 {
533         /* due to optimization an opt may be turned into a Tuple */
534         if (is_Tuple(node))
535                 return;
536
537         assert(node && get_op_pinned(get_irn_op(node)) >= op_pin_state_exc_pinned);
538         assert(state == op_pin_state_pinned || state == op_pin_state_floats);
539
540         node->attr.except.pin_state = state;
541 }
542
543 /* Outputs a unique number for this node */
544 long get_irn_node_nr(const ir_node *node)
545 {
546         assert(node);
547         return node->node_nr;
548 }
549
550 const_attr *get_irn_const_attr(ir_node *node)
551 {
552         assert(is_Const(node));
553         return &node->attr.con;
554 }
555
556 long get_irn_proj_attr(ir_node *node)
557 {
558         /* BEWARE: check for true Proj node here, no Filter */
559         assert(node->op == op_Proj);
560         return node->attr.proj;
561 }
562
563 alloc_attr *get_irn_alloc_attr(ir_node *node)
564 {
565         assert(is_Alloc(node));
566         return &node->attr.alloc;
567 }
568
569 free_attr *get_irn_free_attr(ir_node *node)
570 {
571         assert(is_Free(node));
572         return &node->attr.free;
573 }
574
575 symconst_attr *get_irn_symconst_attr(ir_node *node)
576 {
577         assert(is_SymConst(node));
578         return &node->attr.symc;
579 }
580
581 call_attr *get_irn_call_attr(ir_node *node)
582 {
583         assert(is_Call(node));
584         return &node->attr.call;
585 }
586
587 sel_attr *get_irn_sel_attr(ir_node *node)
588 {
589         assert(is_Sel(node));
590         return &node->attr.sel;
591 }
592
593 phi_attr *get_irn_phi_attr(ir_node *node)
594 {
595         return &node->attr.phi;
596 }
597
598 block_attr *get_irn_block_attr(ir_node *node)
599 {
600         assert(is_Block(node));
601         return &node->attr.block;
602 }
603
604 load_attr *get_irn_load_attr(ir_node *node)
605 {
606         assert(is_Load(node));
607         return &node->attr.load;
608 }
609
610 store_attr *get_irn_store_attr(ir_node *node)
611 {
612         assert(is_Store(node));
613         return &node->attr.store;
614 }
615
616 except_attr *get_irn_except_attr(ir_node *node)
617 {
618         assert(node->op == op_Div || node->op == op_Quot ||
619                node->op == op_DivMod || node->op == op_Mod || node->op == op_Call || node->op == op_Alloc || node->op == op_Bound);
620         return &node->attr.except;
621 }
622
623 divmod_attr *get_irn_divmod_attr(ir_node *node)
624 {
625         assert(node->op == op_Div || node->op == op_Quot ||
626                node->op == op_DivMod || node->op == op_Mod);
627         return &node->attr.divmod;
628 }
629
630 builtin_attr *get_irn_builtin_attr(ir_node *node)
631 {
632         assert(is_Builtin(node));
633         return &node->attr.builtin;
634 }
635
636 void *(get_irn_generic_attr)(ir_node *node)
637 {
638         assert(is_ir_node(node));
639         return _get_irn_generic_attr(node);
640 }
641
642 const void *(get_irn_generic_attr_const)(const ir_node *node)
643 {
644         assert(is_ir_node(node));
645         return _get_irn_generic_attr_const(node);
646 }
647
648 unsigned (get_irn_idx)(const ir_node *node)
649 {
650         assert(is_ir_node(node));
651         return _get_irn_idx(node);
652 }
653
654 int get_irn_pred_pos(ir_node *node, ir_node *arg)
655 {
656         int i;
657         for (i = get_irn_arity(node) - 1; i >= 0; i--) {
658                 if (get_irn_n(node, i) == arg)
659                         return i;
660         }
661         return -1;
662 }
663
664 /** manipulate fields of individual nodes **/
665
666 /* this works for all except Block */
667 ir_node *get_nodes_block(const ir_node *node)
668 {
669         assert(node->op != op_Block);
670         return get_irn_n(node, -1);
671 }
672
673 void set_nodes_block(ir_node *node, ir_node *block)
674 {
675         assert(node->op != op_Block);
676         set_irn_n(node, -1, block);
677 }
678
679 /* this works for all except Block */
680 ir_node *get_nodes_MacroBlock(const ir_node *node)
681 {
682         assert(node->op != op_Block);
683         return get_Block_MacroBlock(get_irn_n(node, -1));
684 }
685
686 /* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base)
687  * from Start.  If so returns frame type, else Null. */
688 ir_type *is_frame_pointer(const ir_node *n)
689 {
690         if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_frame_base)) {
691                 ir_node *start = get_Proj_pred(n);
692                 if (is_Start(start)) {
693                         return get_irg_frame_type(get_irn_irg(start));
694                 }
695         }
696         return NULL;
697 }
698
699 /* Test whether arbitrary node is tls pointer, i.e. Proj(pn_Start_P_tls)
700  * from Start.  If so returns tls type, else Null. */
701 ir_type *is_tls_pointer(const ir_node *n)
702 {
703         if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_tls)) {
704                 ir_node *start = get_Proj_pred(n);
705                 if (is_Start(start)) {
706                         return get_tls_type();
707                 }
708         }
709         return NULL;
710 }
711
712 ir_node **get_Block_cfgpred_arr(ir_node *node)
713 {
714         assert(is_Block(node));
715         return (ir_node **)&(get_irn_in(node)[1]);
716 }
717
718 int (get_Block_n_cfgpreds)(const ir_node *node)
719 {
720         return _get_Block_n_cfgpreds(node);
721 }
722
723 ir_node *(get_Block_cfgpred)(const ir_node *node, int pos)
724 {
725         return _get_Block_cfgpred(node, pos);
726 }
727
728 void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred)
729 {
730         assert(is_Block(node));
731         set_irn_n(node, pos, pred);
732 }
733
734 int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred)
735 {
736         int i;
737
738         for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
739                 if (get_Block_cfgpred_block(block, i) == pred)
740                         return i;
741         }
742         return -1;
743 }
744
745 ir_node *(get_Block_cfgpred_block)(const ir_node *node, int pos)
746 {
747         return _get_Block_cfgpred_block(node, pos);
748 }
749
750 int get_Block_matured(const ir_node *node)
751 {
752         assert(is_Block(node));
753         return (int)node->attr.block.is_matured;
754 }
755
756 void set_Block_matured(ir_node *node, int matured)
757 {
758         assert(is_Block(node));
759         node->attr.block.is_matured = matured;
760 }
761
762 ir_visited_t (get_Block_block_visited)(const ir_node *node)
763 {
764         return _get_Block_block_visited(node);
765 }
766
767 void (set_Block_block_visited)(ir_node *node, ir_visited_t visit)
768 {
769         _set_Block_block_visited(node, visit);
770 }
771
772 /* For this current_ir_graph must be set. */
773 void (mark_Block_block_visited)(ir_node *node)
774 {
775         _mark_Block_block_visited(node);
776 }
777
778 int (Block_block_visited)(const ir_node *node)
779 {
780         return _Block_block_visited(node);
781 }
782
783 #ifdef INTERPROCEDURAL_VIEW
784 void set_Block_cg_cfgpred_arr(ir_node *node, int arity, ir_node *in[])
785 {
786         assert(is_Block(node));
787         if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) {
788                 node->attr.block.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
789                 node->attr.block.in_cg[0] = NULL;
790                 node->attr.block.cg_backedge = new_backedge_arr(current_ir_graph->obst, arity);
791                 {
792                         /* Fix backedge array.  fix_backedges() operates depending on
793                            interprocedural_view. */
794                         int ipv = get_interprocedural_view();
795                         set_interprocedural_view(1);
796                         fix_backedges(current_ir_graph->obst, node);
797                         set_interprocedural_view(ipv);
798                 }
799         }
800         memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity);
801 }
802
803 void set_Block_cg_cfgpred(ir_node *node, int pos, ir_node *pred)
804 {
805         assert(is_Block(node) && node->attr.block.in_cg &&
806                0 <= pos && pos < ARR_LEN(node->attr.block.in_cg) - 1);
807         node->attr.block.in_cg[pos + 1] = pred;
808 }
809
810 ir_node **get_Block_cg_cfgpred_arr(ir_node *node)
811 {
812         assert(is_Block(node));
813         return node->attr.block.in_cg == NULL ? NULL : node->attr.block.in_cg  + 1;
814 }
815
816 int get_Block_cg_n_cfgpreds(const ir_node *node)
817 {
818         assert(is_Block(node));
819         return node->attr.block.in_cg == NULL ? 0 : ARR_LEN(node->attr.block.in_cg) - 1;
820 }
821
822 ir_node *get_Block_cg_cfgpred(const ir_node *node, int pos)
823 {
824         assert(is_Block(node) && node->attr.block.in_cg);
825         return node->attr.block.in_cg[pos + 1];
826 }
827
828 void remove_Block_cg_cfgpred_arr(ir_node *node)
829 {
830         assert(is_Block(node));
831         node->attr.block.in_cg = NULL;
832 }
833 #endif /* INTERPROCEDURAL_VIEW */
834
835 ir_node *(set_Block_dead)(ir_node *block)
836 {
837         return _set_Block_dead(block);
838 }
839
840 int (is_Block_dead)(const ir_node *block)
841 {
842         return _is_Block_dead(block);
843 }
844
845 ir_extblk *get_Block_extbb(const ir_node *block)
846 {
847         ir_extblk *res;
848         assert(is_Block(block));
849         res = block->attr.block.extblk;
850         assert(res == NULL || is_ir_extbb(res));
851         return res;
852 }
853
854 void set_Block_extbb(ir_node *block, ir_extblk *extblk)
855 {
856         assert(is_Block(block));
857         assert(extblk == NULL || is_ir_extbb(extblk));
858         block->attr.block.extblk = extblk;
859 }
860
861 /* Returns the macro block header of a block.*/
862 ir_node *get_Block_MacroBlock(const ir_node *block)
863 {
864         ir_node *mbh;
865         assert(is_Block(block));
866         mbh = get_irn_n(block, -1);
867         /* once macro block header is respected by all optimizations,
868            this assert can be removed */
869         assert(mbh != NULL);
870         return mbh;
871 }
872
873 /* Sets the macro block header of a block. */
874 void set_Block_MacroBlock(ir_node *block, ir_node *mbh)
875 {
876         assert(is_Block(block));
877         mbh = skip_Id(mbh);
878         assert(is_Block(mbh));
879         set_irn_n(block, -1, mbh);
880 }
881
882 /* returns the macro block header of a node. */
883 ir_node *get_irn_MacroBlock(const ir_node *n)
884 {
885         if (! is_Block(n)) {
886                 n = get_nodes_block(n);
887                 /* if the Block is Bad, do NOT try to get it's MB, it will fail. */
888                 if (is_Bad(n))
889                         return (ir_node *)n;
890         }
891         return get_Block_MacroBlock(n);
892 }
893
894 /* returns the graph of a Block. */
895 ir_graph *(get_Block_irg)(const ir_node *block)
896 {
897         return _get_Block_irg(block);
898 }
899
900 ir_entity *create_Block_entity(ir_node *block)
901 {
902         ir_entity *entity;
903         assert(is_Block(block));
904
905         entity = block->attr.block.entity;
906         if (entity == NULL) {
907                 ir_label_t  nr;
908                 ir_type   *glob;
909
910                 glob = get_glob_type();
911                 entity = new_entity(glob, id_unique("block_%u"), get_code_type());
912                 set_entity_visibility(entity, ir_visibility_local);
913                 set_entity_linkage(entity, IR_LINKAGE_CONSTANT);
914                 nr = get_irp_next_label_nr();
915                 set_entity_label(entity, nr);
916                 set_entity_compiler_generated(entity, 1);
917
918                 block->attr.block.entity = entity;
919         }
920         return entity;
921 }
922
923 ir_entity *get_Block_entity(const ir_node *block)
924 {
925         assert(is_Block(block));
926         return block->attr.block.entity;
927 }
928
929 void set_Block_entity(ir_node *block, ir_entity *entity)
930 {
931         assert(is_Block(block));
932         assert(get_entity_type(entity) == get_code_type());
933         block->attr.block.entity = entity;
934 }
935
936 int has_Block_entity(const ir_node *block)
937 {
938         return block->attr.block.entity != NULL;
939 }
940
941 ir_node *(get_Block_phis)(const ir_node *block)
942 {
943         return _get_Block_phis(block);
944 }
945
946 void (set_Block_phis)(ir_node *block, ir_node *phi)
947 {
948         _set_Block_phis(block, phi);
949 }
950
951 void (add_Block_phi)(ir_node *block, ir_node *phi)
952 {
953         _add_Block_phi(block, phi);
954 }
955
956 /* Get the Block mark (single bit). */
957 unsigned (get_Block_mark)(const ir_node *block)
958 {
959         return _get_Block_mark(block);
960 }
961
962 /* Set the Block mark (single bit). */
963 void (set_Block_mark)(ir_node *block, unsigned mark)
964 {
965         _set_Block_mark(block, mark);
966 }
967
968 int get_End_n_keepalives(const ir_node *end)
969 {
970         assert(is_End(end));
971         return (get_irn_arity(end) - END_KEEPALIVE_OFFSET);
972 }
973
974 ir_node *get_End_keepalive(const ir_node *end, int pos)
975 {
976         assert(is_End(end));
977         return get_irn_n(end, pos + END_KEEPALIVE_OFFSET);
978 }
979
980 void add_End_keepalive(ir_node *end, ir_node *ka)
981 {
982         assert(is_End(end));
983         add_irn_n(end, ka);
984 }
985
986 void set_End_keepalive(ir_node *end, int pos, ir_node *ka)
987 {
988         assert(is_End(end));
989         set_irn_n(end, pos + END_KEEPALIVE_OFFSET, ka);
990 }
991
992 /* Set new keep-alives */
993 void set_End_keepalives(ir_node *end, int n, ir_node *in[])
994 {
995         int i;
996         ir_graph *irg = get_irn_irg(end);
997
998         /* notify that edges are deleted */
999         for (i = END_KEEPALIVE_OFFSET; i < ARR_LEN(end->in) - 1; ++i) {
1000                 edges_notify_edge(end, i, NULL, end->in[i + 1], irg);
1001         }
1002         ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
1003
1004         for (i = 0; i < n; ++i) {
1005                 end->in[1 + END_KEEPALIVE_OFFSET + i] = in[i];
1006                 edges_notify_edge(end, END_KEEPALIVE_OFFSET + i, end->in[1 + END_KEEPALIVE_OFFSET + i], NULL, irg);
1007         }
1008 }
1009
1010 /* Set new keep-alives from old keep-alives, skipping irn */
1011 void remove_End_keepalive(ir_node *end, ir_node *irn)
1012 {
1013         int      n = get_End_n_keepalives(end);
1014         int      i, idx;
1015         ir_graph *irg;
1016
1017         idx = -1;
1018         for (i = n -1; i >= 0; --i) {
1019                 ir_node *old_ka = end->in[1 + END_KEEPALIVE_OFFSET + i];
1020
1021                 /* find irn */
1022                 if (old_ka == irn) {
1023                         idx = i;
1024                         goto found;
1025                 }
1026         }
1027         return;
1028 found:
1029         irg = get_irn_irg(end);
1030
1031         /* remove the edge */
1032         edges_notify_edge(end, idx, NULL, irn, irg);
1033
1034         if (idx != n - 1) {
1035                 /* exchange with the last one */
1036                 ir_node *old = end->in[1 + END_KEEPALIVE_OFFSET + n - 1];
1037                 edges_notify_edge(end, n - 1, NULL, old, irg);
1038                 end->in[1 + END_KEEPALIVE_OFFSET + idx] = old;
1039                 edges_notify_edge(end, idx, old, NULL, irg);
1040         }
1041         /* now n - 1 keeps, 1 block input */
1042         ARR_RESIZE(ir_node *, end->in, (n - 1) + 1 + END_KEEPALIVE_OFFSET);
1043 }
1044
1045 /* remove Bads, NoMems and doublets from the keep-alive set */
1046 void remove_End_Bads_and_doublets(ir_node *end)
1047 {
1048         pset_new_t keeps;
1049         int        idx, n = get_End_n_keepalives(end);
1050         ir_graph   *irg;
1051
1052         if (n <= 0)
1053                 return;
1054
1055         irg = get_irn_irg(end);
1056         pset_new_init(&keeps);
1057
1058         for (idx = n - 1; idx >= 0; --idx) {
1059                 ir_node *ka = get_End_keepalive(end, idx);
1060
1061                 if (is_Bad(ka) || is_NoMem(ka) || pset_new_contains(&keeps, ka)) {
1062                         /* remove the edge */
1063                         edges_notify_edge(end, idx, NULL, ka, irg);
1064
1065                         if (idx != n - 1) {
1066                                 /* exchange with the last one */
1067                                 ir_node *old = end->in[1 + END_KEEPALIVE_OFFSET + n - 1];
1068                                 edges_notify_edge(end, n - 1, NULL, old, irg);
1069                                 end->in[1 + END_KEEPALIVE_OFFSET + idx] = old;
1070                                 edges_notify_edge(end, idx, old, NULL, irg);
1071                         }
1072                         --n;
1073                 } else {
1074                         pset_new_insert(&keeps, ka);
1075                 }
1076         }
1077         /* n keeps, 1 block input */
1078         ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
1079
1080         pset_new_destroy(&keeps);
1081 }
1082
1083 void free_End(ir_node *end)
1084 {
1085         assert(is_End(end));
1086         end->kind = k_BAD;
1087         DEL_ARR_F(end->in);
1088         end->in = NULL;   /* @@@ make sure we get an error if we use the
1089                              in array afterwards ... */
1090 }
1091
1092 /* Return the target address of an IJmp */
1093 ir_node *get_IJmp_target(const ir_node *ijmp)
1094 {
1095         assert(is_IJmp(ijmp));
1096         return get_irn_n(ijmp, 0);
1097 }
1098
1099 /** Sets the target address of an IJmp */
1100 void set_IJmp_target(ir_node *ijmp, ir_node *tgt)
1101 {
1102         assert(is_IJmp(ijmp));
1103         set_irn_n(ijmp, 0, tgt);
1104 }
1105
1106 ir_node *get_Cond_selector(const ir_node *node)
1107 {
1108         assert(is_Cond(node));
1109         return get_irn_n(node, 0);
1110 }
1111
1112 void set_Cond_selector(ir_node *node, ir_node *selector)
1113 {
1114         assert(is_Cond(node));
1115         set_irn_n(node, 0, selector);
1116 }
1117
1118 long get_Cond_default_proj(const ir_node *node)
1119 {
1120         assert(is_Cond(node));
1121         return node->attr.cond.default_proj;
1122 }
1123
1124 void set_Cond_default_proj(ir_node *node, long defproj)
1125 {
1126         assert(is_Cond(node));
1127         node->attr.cond.default_proj = defproj;
1128 }
1129
1130 ir_node *get_Return_mem(const ir_node *node)
1131 {
1132         assert(is_Return(node));
1133         return get_irn_n(node, 0);
1134 }
1135
1136 void set_Return_mem(ir_node *node, ir_node *mem)
1137 {
1138         assert(is_Return(node));
1139         set_irn_n(node, 0, mem);
1140 }
1141
1142 int get_Return_n_ress(const ir_node *node)
1143 {
1144         assert(is_Return(node));
1145         return (get_irn_arity(node) - RETURN_RESULT_OFFSET);
1146 }
1147
1148 ir_node **get_Return_res_arr(ir_node *node)
1149 {
1150         assert(is_Return(node));
1151         if (get_Return_n_ress(node) > 0)
1152                 return (ir_node **)&(get_irn_in(node)[1 + RETURN_RESULT_OFFSET]);
1153         else
1154                 return NULL;
1155 }
1156
1157 /*
1158 void set_Return_n_res(ir_node *node, int results)
1159 {
1160         assert(is_Return(node));
1161 }
1162 */
1163
1164 ir_node *get_Return_res(const ir_node *node, int pos)
1165 {
1166         assert(is_Return(node));
1167         assert(get_Return_n_ress(node) > pos);
1168         return get_irn_n(node, pos + RETURN_RESULT_OFFSET);
1169 }
1170
1171 void set_Return_res(ir_node *node, int pos, ir_node *res)
1172 {
1173         assert(is_Return(node));
1174         set_irn_n(node, pos + RETURN_RESULT_OFFSET, res);
1175 }
1176
1177 tarval *(get_Const_tarval)(const ir_node *node)
1178 {
1179         return _get_Const_tarval(node);
1180 }
1181
1182 void set_Const_tarval(ir_node *node, tarval *con)
1183 {
1184         assert(is_Const(node));
1185         node->attr.con.tv = con;
1186 }
1187
1188 int (is_Const_null)(const ir_node *node)
1189 {
1190         return _is_Const_null(node);
1191 }
1192
1193 int (is_Const_one)(const ir_node *node)
1194 {
1195         return _is_Const_one(node);
1196 }
1197
1198 int (is_Const_all_one)(const ir_node *node)
1199 {
1200         return _is_Const_all_one(node);
1201 }
1202
1203
1204 /* The source language type.  Must be an atomic type.  Mode of type must
1205    be mode of node. For tarvals from entities type must be pointer to
1206    entity type. */
1207 ir_type *get_Const_type(ir_node *node)
1208 {
1209         assert(is_Const(node));
1210         return node->attr.con.tp;
1211 }
1212
1213 void set_Const_type(ir_node *node, ir_type *tp)
1214 {
1215         assert(is_Const(node));
1216         if (tp != firm_unknown_type) {
1217                 assert(is_atomic_type(tp));
1218                 assert(get_type_mode(tp) == get_irn_mode(node));
1219         }
1220         node->attr.con.tp = tp;
1221 }
1222
1223
1224 symconst_kind get_SymConst_kind(const ir_node *node)
1225 {
1226         assert(is_SymConst(node));
1227         return node->attr.symc.kind;
1228 }
1229
1230 void set_SymConst_kind(ir_node *node, symconst_kind kind)
1231 {
1232         assert(is_SymConst(node));
1233         node->attr.symc.kind = kind;
1234 }
1235
1236 ir_type *get_SymConst_type(const ir_node *node)
1237 {
1238         /* the cast here is annoying, but we have to compensate for
1239            the skip_tip() */
1240         ir_node *irn = (ir_node *)node;
1241         assert(is_SymConst(node) &&
1242                (SYMCONST_HAS_TYPE(get_SymConst_kind(node))));
1243         return irn->attr.symc.sym.type_p;
1244 }
1245
1246 void set_SymConst_type(ir_node *node, ir_type *tp)
1247 {
1248         assert(is_SymConst(node) &&
1249                (SYMCONST_HAS_TYPE(get_SymConst_kind(node))));
1250         node->attr.symc.sym.type_p = tp;
1251 }
1252
1253
1254 /* Only to access SymConst of kind symconst_addr_ent.  Else assertion: */
1255 ir_entity *get_SymConst_entity(const ir_node *node)
1256 {
1257         assert(is_SymConst(node) && SYMCONST_HAS_ENT(get_SymConst_kind(node)));
1258         return node->attr.symc.sym.entity_p;
1259 }
1260
1261 void set_SymConst_entity(ir_node *node, ir_entity *ent)
1262 {
1263         assert(is_SymConst(node) && SYMCONST_HAS_ENT(get_SymConst_kind(node)));
1264         node->attr.symc.sym.entity_p  = ent;
1265 }
1266
1267 ir_enum_const *get_SymConst_enum(const ir_node *node)
1268 {
1269         assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
1270         return node->attr.symc.sym.enum_p;
1271 }
1272
1273 void set_SymConst_enum(ir_node *node, ir_enum_const *ec)
1274 {
1275         assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
1276         node->attr.symc.sym.enum_p  = ec;
1277 }
1278
1279 union symconst_symbol
1280 get_SymConst_symbol(const ir_node *node)
1281 {
1282         assert(is_SymConst(node));
1283         return node->attr.symc.sym;
1284 }
1285
1286 void set_SymConst_symbol(ir_node *node, union symconst_symbol sym)
1287 {
1288         assert(is_SymConst(node));
1289         node->attr.symc.sym = sym;
1290 }
1291
1292 ir_type *get_SymConst_value_type(ir_node *node)
1293 {
1294         assert(is_SymConst(node));
1295         return node->attr.symc.tp;
1296 }
1297
1298 void set_SymConst_value_type(ir_node *node, ir_type *tp)
1299 {
1300         assert(is_SymConst(node));
1301         node->attr.symc.tp = tp;
1302 }
1303
1304 ir_node *get_Sel_mem(const ir_node *node)
1305 {
1306         assert(is_Sel(node));
1307         return get_irn_n(node, 0);
1308 }
1309
1310 void set_Sel_mem(ir_node *node, ir_node *mem)
1311 {
1312         assert(is_Sel(node));
1313         set_irn_n(node, 0, mem);
1314 }
1315
1316 ir_node *get_Sel_ptr(const ir_node *node)
1317 {
1318         assert(is_Sel(node));
1319         return get_irn_n(node, 1);
1320 }
1321
1322 void set_Sel_ptr(ir_node *node, ir_node *ptr)
1323 {
1324         assert(is_Sel(node));
1325         set_irn_n(node, 1, ptr);
1326 }
1327
1328 int get_Sel_n_indexs(const ir_node *node)
1329 {
1330         assert(is_Sel(node));
1331         return (get_irn_arity(node) - SEL_INDEX_OFFSET);
1332 }
1333
1334 ir_node **get_Sel_index_arr(ir_node *node)
1335 {
1336         assert(is_Sel(node));
1337         if (get_Sel_n_indexs(node) > 0)
1338                 return (ir_node **)& get_irn_in(node)[SEL_INDEX_OFFSET + 1];
1339         else
1340                 return NULL;
1341 }
1342
1343 ir_node *get_Sel_index(const ir_node *node, int pos)
1344 {
1345         assert(is_Sel(node));
1346         return get_irn_n(node, pos + SEL_INDEX_OFFSET);
1347 }
1348
1349 void set_Sel_index(ir_node *node, int pos, ir_node *index)
1350 {
1351         assert(is_Sel(node));
1352         set_irn_n(node, pos + SEL_INDEX_OFFSET, index);
1353 }
1354
1355 ir_entity *get_Sel_entity(const ir_node *node)
1356 {
1357         assert(is_Sel(node));
1358         return node->attr.sel.entity;
1359 }
1360
1361 /* need a version without const to prevent warning */
1362 static ir_entity *_get_Sel_entity(ir_node *node)
1363 {
1364         return get_Sel_entity(node);
1365 }
1366
1367 void set_Sel_entity(ir_node *node, ir_entity *ent)
1368 {
1369         assert(is_Sel(node));
1370         node->attr.sel.entity = ent;
1371 }
1372
1373
1374 /* For unary and binary arithmetic operations the access to the
1375    operands can be factored out.  Left is the first, right the
1376    second arithmetic value  as listed in tech report 0999-33.
1377    unops are: Minus, Abs, Not, Conv, Cast
1378    binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
1379    Shr, Shrs, Rotate, Cmp */
1380
1381
1382 ir_node *get_Call_mem(const ir_node *node)
1383 {
1384         assert(is_Call(node));
1385         return get_irn_n(node, 0);
1386 }
1387
1388 void set_Call_mem(ir_node *node, ir_node *mem)
1389 {
1390         assert(is_Call(node));
1391         set_irn_n(node, 0, mem);
1392 }
1393
1394 ir_node *get_Call_ptr(const ir_node *node)
1395 {
1396         assert(is_Call(node));
1397         return get_irn_n(node, 1);
1398 }
1399
1400 void set_Call_ptr(ir_node *node, ir_node *ptr)
1401 {
1402         assert(is_Call(node));
1403         set_irn_n(node, 1, ptr);
1404 }
1405
1406 ir_node **get_Call_param_arr(ir_node *node)
1407 {
1408         assert(is_Call(node));
1409         return &get_irn_in(node)[CALL_PARAM_OFFSET + 1];
1410 }
1411
1412 int get_Call_n_params(const ir_node *node)
1413 {
1414         assert(is_Call(node));
1415         return (get_irn_arity(node) - CALL_PARAM_OFFSET);
1416 }
1417
1418 ir_node *get_Call_param(const ir_node *node, int pos)
1419 {
1420         assert(is_Call(node));
1421         return get_irn_n(node, pos + CALL_PARAM_OFFSET);
1422 }
1423
1424 void set_Call_param(ir_node *node, int pos, ir_node *param)
1425 {
1426         assert(is_Call(node));
1427         set_irn_n(node, pos + CALL_PARAM_OFFSET, param);
1428 }
1429
1430 ir_type *get_Call_type(ir_node *node)
1431 {
1432         assert(is_Call(node));
1433         return node->attr.call.type;
1434 }
1435
1436 void set_Call_type(ir_node *node, ir_type *tp)
1437 {
1438         assert(is_Call(node));
1439         assert((get_unknown_type() == tp) || is_Method_type(tp));
1440         node->attr.call.type = tp;
1441 }
1442
1443 unsigned get_Call_tail_call(const ir_node *node)
1444 {
1445         assert(is_Call(node));
1446         return node->attr.call.tail_call;
1447 }
1448
1449 void set_Call_tail_call(ir_node *node, unsigned tail_call)
1450 {
1451         assert(is_Call(node));
1452         node->attr.call.tail_call = tail_call != 0;
1453 }
1454
1455 ir_node *get_Builtin_mem(const ir_node *node)
1456 {
1457         assert(is_Builtin(node));
1458         return get_irn_n(node, 0);
1459 }
1460
1461 void set_Builtin_mem(ir_node *node, ir_node *mem)
1462 {
1463         assert(is_Builtin(node));
1464         set_irn_n(node, 0, mem);
1465 }
1466
1467 ir_builtin_kind get_Builtin_kind(const ir_node *node)
1468 {
1469         assert(is_Builtin(node));
1470         return node->attr.builtin.kind;
1471 }
1472
1473 void set_Builtin_kind(ir_node *node, ir_builtin_kind kind)
1474 {
1475         assert(is_Builtin(node));
1476         node->attr.builtin.kind = kind;
1477 }
1478
1479 ir_node **get_Builtin_param_arr(ir_node *node)
1480 {
1481         assert(is_Builtin(node));
1482         return &get_irn_in(node)[BUILDIN_PARAM_OFFSET + 1];
1483 }
1484
1485 int get_Builtin_n_params(const ir_node *node)
1486 {
1487         assert(is_Builtin(node));
1488         return (get_irn_arity(node) - BUILDIN_PARAM_OFFSET);
1489 }
1490
1491 ir_node *get_Builtin_param(const ir_node *node, int pos)
1492 {
1493         assert(is_Builtin(node));
1494         return get_irn_n(node, pos + BUILDIN_PARAM_OFFSET);
1495 }
1496
1497 void set_Builtin_param(ir_node *node, int pos, ir_node *param)
1498 {
1499         assert(is_Builtin(node));
1500         set_irn_n(node, pos + BUILDIN_PARAM_OFFSET, param);
1501 }
1502
1503 ir_type *get_Builtin_type(ir_node *node)
1504 {
1505         assert(is_Builtin(node));
1506         return node->attr.builtin.type;
1507 }
1508
1509 void set_Builtin_type(ir_node *node, ir_type *tp)
1510 {
1511         assert(is_Builtin(node));
1512         assert((get_unknown_type() == tp) || is_Method_type(tp));
1513         node->attr.builtin.type = tp;
1514 }
1515
1516 /* Returns a human readable string for the ir_builtin_kind. */
1517 const char *get_builtin_kind_name(ir_builtin_kind kind)
1518 {
1519 #define X(a)    case a: return #a;
1520         switch (kind) {
1521                 X(ir_bk_trap);
1522                 X(ir_bk_debugbreak);
1523                 X(ir_bk_return_address);
1524                 X(ir_bk_frame_address);
1525                 X(ir_bk_prefetch);
1526                 X(ir_bk_ffs);
1527                 X(ir_bk_clz);
1528                 X(ir_bk_ctz);
1529                 X(ir_bk_popcount);
1530                 X(ir_bk_parity);
1531                 X(ir_bk_bswap);
1532                 X(ir_bk_inport);
1533                 X(ir_bk_outport);
1534                 X(ir_bk_inner_trampoline);
1535         }
1536         return "<unknown>";
1537 #undef X
1538 }
1539
1540
1541 int Call_has_callees(const ir_node *node)
1542 {
1543         assert(is_Call(node));
1544         return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
1545                 (node->attr.call.callee_arr != NULL));
1546 }
1547
1548 int get_Call_n_callees(const ir_node *node)
1549 {
1550   assert(is_Call(node) && node->attr.call.callee_arr);
1551   return ARR_LEN(node->attr.call.callee_arr);
1552 }
1553
1554 ir_entity *get_Call_callee(const ir_node *node, int pos)
1555 {
1556         assert(pos >= 0 && pos < get_Call_n_callees(node));
1557         return node->attr.call.callee_arr[pos];
1558 }
1559
1560 void set_Call_callee_arr(ir_node *node, const int n, ir_entity ** arr)
1561 {
1562         assert(is_Call(node));
1563         if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
1564                 node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, current_ir_graph->obst, n);
1565         }
1566         memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
1567 }
1568
1569 void remove_Call_callee_arr(ir_node *node)
1570 {
1571         assert(is_Call(node));
1572         node->attr.call.callee_arr = NULL;
1573 }
1574
1575 ir_node *get_CallBegin_ptr(const ir_node *node)
1576 {
1577         assert(is_CallBegin(node));
1578         return get_irn_n(node, 0);
1579 }
1580
1581 void set_CallBegin_ptr(ir_node *node, ir_node *ptr)
1582 {
1583         assert(is_CallBegin(node));
1584         set_irn_n(node, 0, ptr);
1585 }
1586
1587 ir_node *get_CallBegin_call(const ir_node *node)
1588 {
1589         assert(is_CallBegin(node));
1590         return node->attr.callbegin.call;
1591 }
1592
1593 void set_CallBegin_call(ir_node *node, ir_node *call)
1594 {
1595         assert(is_CallBegin(node));
1596         node->attr.callbegin.call = call;
1597 }
1598
1599 /*
1600  * Returns non-zero if a Call is surely a self-recursive Call.
1601  * Beware: if this functions returns 0, the call might be self-recursive!
1602  */
1603 int is_self_recursive_Call(const ir_node *call)
1604 {
1605         const ir_node *callee = get_Call_ptr(call);
1606
1607         if (is_SymConst_addr_ent(callee)) {
1608                 const ir_entity *ent = get_SymConst_entity(callee);
1609                 const ir_graph  *irg = get_entity_irg(ent);
1610                 if (irg == get_irn_irg(call))
1611                         return 1;
1612         }
1613         return 0;
1614 }
1615
1616 #define BINOP(OP)                                      \
1617 ir_node * get_##OP##_left(const ir_node *node) {       \
1618   assert(is_##OP(node));                               \
1619   return get_irn_n(node, node->op->op_index);          \
1620 }                                                      \
1621 void set_##OP##_left(ir_node *node, ir_node *left) {   \
1622   assert(is_##OP(node));                               \
1623   set_irn_n(node, node->op->op_index, left);           \
1624 }                                                      \
1625 ir_node *get_##OP##_right(const ir_node *node) {       \
1626   assert(is_##OP(node));                               \
1627   return get_irn_n(node, node->op->op_index + 1);      \
1628 }                                                      \
1629 void set_##OP##_right(ir_node *node, ir_node *right) { \
1630   assert(is_##OP(node));                               \
1631   set_irn_n(node, node->op->op_index + 1, right);      \
1632 }
1633
1634 #define UNOP(OP)                                  \
1635 ir_node *get_##OP##_op(const ir_node *node) {     \
1636   assert(is_##OP(node));                          \
1637   return get_irn_n(node, node->op->op_index);     \
1638 }                                                 \
1639 void set_##OP##_op(ir_node *node, ir_node *op) {  \
1640   assert(is_##OP(node));                          \
1641   set_irn_n(node, node->op->op_index, op);        \
1642 }
1643
1644 #define BINOP_MEM(OP)                         \
1645 BINOP(OP)                                     \
1646                                               \
1647 ir_node *                                     \
1648 get_##OP##_mem(const ir_node *node) {         \
1649   assert(is_##OP(node));                      \
1650   return get_irn_n(node, 0);                  \
1651 }                                             \
1652                                               \
1653 void                                          \
1654 set_##OP##_mem(ir_node *node, ir_node *mem) { \
1655   assert(is_##OP(node));                      \
1656   set_irn_n(node, 0, mem);                    \
1657 }
1658
1659 #define DIVOP(OP)                                       \
1660 BINOP_MEM(OP)                                           \
1661                                                         \
1662 ir_mode *get_##OP##_resmode(const ir_node *node) {      \
1663   assert(is_##OP(node));                                \
1664   return node->attr.divmod.resmode;                     \
1665 }                                                       \
1666                                                         \
1667 void set_##OP##_resmode(ir_node *node, ir_mode *mode) { \
1668   assert(is_##OP(node));                                \
1669   node->attr.divmod.resmode = mode;                     \
1670 }
1671
1672
1673 BINOP(Add)
1674 BINOP(Borrow)
1675 BINOP(Carry)
1676 BINOP(Sub)
1677 UNOP(Minus)
1678 BINOP(Mul)
1679 BINOP(Mulh)
1680 DIVOP(Quot)
1681 DIVOP(DivMod)
1682 DIVOP(Div)
1683 DIVOP(Mod)
1684 UNOP(Abs)
1685 BINOP(And)
1686 BINOP(Or)
1687 BINOP(Eor)
1688 UNOP(Not)
1689 BINOP(Shl)
1690 BINOP(Shr)
1691 BINOP(Shrs)
1692 BINOP(Rotl)
1693 BINOP(Cmp)
1694 UNOP(Conv)
1695 UNOP(Cast)
1696
1697 int get_Div_no_remainder(const ir_node *node)
1698 {
1699         assert(is_Div(node));
1700         return node->attr.divmod.no_remainder;
1701 }
1702
1703 void set_Div_no_remainder(ir_node *node, int no_remainder)
1704 {
1705         assert(is_Div(node));
1706         node->attr.divmod.no_remainder = no_remainder;
1707 }
1708
1709 int get_Conv_strict(const ir_node *node)
1710 {
1711         assert(is_Conv(node));
1712         return node->attr.conv.strict;
1713 }
1714
1715 void set_Conv_strict(ir_node *node, int strict_flag)
1716 {
1717         assert(is_Conv(node));
1718         node->attr.conv.strict = (char)strict_flag;
1719 }
1720
1721 ir_type *get_Cast_type(ir_node *node)
1722 {
1723         assert(is_Cast(node));
1724         return node->attr.cast.type;
1725 }
1726
1727 void set_Cast_type(ir_node *node, ir_type *to_tp)
1728 {
1729         assert(is_Cast(node));
1730         node->attr.cast.type = to_tp;
1731 }
1732
1733
1734 /* Checks for upcast.
1735  *
1736  * Returns true if the Cast node casts a class type to a super type.
1737  */
1738 int is_Cast_upcast(ir_node *node)
1739 {
1740         ir_type *totype   = get_Cast_type(node);
1741         ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
1742
1743         assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
1744         assert(fromtype);
1745
1746         while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
1747                 totype   = get_pointer_points_to_type(totype);
1748                 fromtype = get_pointer_points_to_type(fromtype);
1749         }
1750
1751         assert(fromtype);
1752
1753         if (!is_Class_type(totype)) return 0;
1754         return is_SubClass_of(fromtype, totype);
1755 }
1756
1757 /* Checks for downcast.
1758  *
1759  * Returns true if the Cast node casts a class type to a sub type.
1760  */
1761 int is_Cast_downcast(ir_node *node)
1762 {
1763         ir_type *totype   = get_Cast_type(node);
1764         ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
1765
1766         assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
1767         assert(fromtype);
1768
1769         while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
1770                 totype   = get_pointer_points_to_type(totype);
1771                 fromtype = get_pointer_points_to_type(fromtype);
1772         }
1773
1774         assert(fromtype);
1775
1776         if (!is_Class_type(totype)) return 0;
1777         return is_SubClass_of(totype, fromtype);
1778 }
1779
1780 int (is_unop)(const ir_node *node)
1781 {
1782         return _is_unop(node);
1783 }
1784
1785 ir_node *get_unop_op(const ir_node *node)
1786 {
1787         if (node->op->opar == oparity_unary)
1788                 return get_irn_n(node, node->op->op_index);
1789
1790         assert(node->op->opar == oparity_unary);
1791         return NULL;
1792 }
1793
1794 void set_unop_op(ir_node *node, ir_node *op)
1795 {
1796         if (node->op->opar == oparity_unary)
1797                 set_irn_n(node, node->op->op_index, op);
1798
1799         assert(node->op->opar == oparity_unary);
1800 }
1801
1802 int (is_binop)(const ir_node *node)
1803 {
1804         return _is_binop(node);
1805 }
1806
1807 ir_node *get_binop_left(const ir_node *node)
1808 {
1809         assert(node->op->opar == oparity_binary);
1810         return get_irn_n(node, node->op->op_index);
1811 }
1812
1813 void set_binop_left(ir_node *node, ir_node *left)
1814 {
1815         assert(node->op->opar == oparity_binary);
1816         set_irn_n(node, node->op->op_index, left);
1817 }
1818
1819 ir_node *get_binop_right(const ir_node *node)
1820 {
1821         assert(node->op->opar == oparity_binary);
1822         return get_irn_n(node, node->op->op_index + 1);
1823 }
1824
1825 void set_binop_right(ir_node *node, ir_node *right)
1826 {
1827         assert(node->op->opar == oparity_binary);
1828         set_irn_n(node, node->op->op_index + 1, right);
1829 }
1830
1831 int is_Phi0(const ir_node *n)
1832 {
1833         assert(n);
1834
1835         return ((get_irn_op(n) == op_Phi) &&
1836                 (get_irn_arity(n) == 0) &&
1837                 (get_irg_phase_state(get_irn_irg(n)) ==  phase_building));
1838 }
1839
1840 ir_node **get_Phi_preds_arr(ir_node *node)
1841 {
1842   assert(node->op == op_Phi);
1843   return (ir_node **)&(get_irn_in(node)[1]);
1844 }
1845
1846 int get_Phi_n_preds(const ir_node *node)
1847 {
1848         assert(is_Phi(node) || is_Phi0(node));
1849         return (get_irn_arity(node));
1850 }
1851
1852 /*
1853 void set_Phi_n_preds(ir_node *node, int n_preds)
1854 {
1855         assert(node->op == op_Phi);
1856 }
1857 */
1858
1859 ir_node *get_Phi_pred(const ir_node *node, int pos)
1860 {
1861         assert(is_Phi(node) || is_Phi0(node));
1862         return get_irn_n(node, pos);
1863 }
1864
1865 void set_Phi_pred(ir_node *node, int pos, ir_node *pred)
1866 {
1867         assert(is_Phi(node) || is_Phi0(node));
1868         set_irn_n(node, pos, pred);
1869 }
1870
1871 ir_node *(get_Phi_next)(const ir_node *phi)
1872 {
1873         return _get_Phi_next(phi);
1874 }
1875
1876 void (set_Phi_next)(ir_node *phi, ir_node *next)
1877 {
1878         _set_Phi_next(phi, next);
1879 }
1880
1881 int is_memop(const ir_node *node)
1882 {
1883         ir_opcode code = get_irn_opcode(node);
1884         return (code == iro_Load || code == iro_Store);
1885 }
1886
1887 ir_node *get_memop_mem(const ir_node *node)
1888 {
1889         assert(is_memop(node));
1890         return get_irn_n(node, 0);
1891 }
1892
1893 void set_memop_mem(ir_node *node, ir_node *mem)
1894 {
1895         assert(is_memop(node));
1896         set_irn_n(node, 0, mem);
1897 }
1898
1899 ir_node *get_memop_ptr(const ir_node *node)
1900 {
1901         assert(is_memop(node));
1902         return get_irn_n(node, 1);
1903 }
1904
1905 void set_memop_ptr(ir_node *node, ir_node *ptr)
1906 {
1907         assert(is_memop(node));
1908         set_irn_n(node, 1, ptr);
1909 }
1910
1911 ir_node *get_Load_mem(const ir_node *node)
1912 {
1913         assert(is_Load(node));
1914         return get_irn_n(node, 0);
1915 }
1916
1917 void set_Load_mem(ir_node *node, ir_node *mem)
1918 {
1919         assert(is_Load(node));
1920         set_irn_n(node, 0, mem);
1921 }
1922
1923 ir_node *get_Load_ptr(const ir_node *node)
1924 {
1925         assert(is_Load(node));
1926         return get_irn_n(node, 1);
1927 }
1928
1929 void set_Load_ptr(ir_node *node, ir_node *ptr)
1930 {
1931         assert(is_Load(node));
1932         set_irn_n(node, 1, ptr);
1933 }
1934
1935 ir_mode *get_Load_mode(const ir_node *node)
1936 {
1937         assert(is_Load(node));
1938         return node->attr.load.mode;
1939 }
1940
1941 void set_Load_mode(ir_node *node, ir_mode *mode)
1942 {
1943         assert(is_Load(node));
1944         node->attr.load.mode = mode;
1945 }
1946
1947 ir_volatility get_Load_volatility(const ir_node *node)
1948 {
1949         assert(is_Load(node));
1950         return node->attr.load.volatility;
1951 }
1952
1953 void set_Load_volatility(ir_node *node, ir_volatility volatility)
1954 {
1955         assert(is_Load(node));
1956         node->attr.load.volatility = volatility;
1957 }
1958
1959 ir_align get_Load_align(const ir_node *node)
1960 {
1961         assert(is_Load(node));
1962         return node->attr.load.aligned;
1963 }
1964
1965 void set_Load_align(ir_node *node, ir_align align)
1966 {
1967         assert(is_Load(node));
1968         node->attr.load.aligned = align;
1969 }
1970
1971
1972 ir_node *get_Store_mem(const ir_node *node)
1973 {
1974         assert(is_Store(node));
1975         return get_irn_n(node, 0);
1976 }
1977
1978 void set_Store_mem(ir_node *node, ir_node *mem)
1979 {
1980         assert(is_Store(node));
1981         set_irn_n(node, 0, mem);
1982 }
1983
1984 ir_node *get_Store_ptr(const ir_node *node)
1985 {
1986         assert(is_Store(node));
1987         return get_irn_n(node, 1);
1988 }
1989
1990 void set_Store_ptr(ir_node *node, ir_node *ptr)
1991 {
1992         assert(is_Store(node));
1993         set_irn_n(node, 1, ptr);
1994 }
1995
1996 ir_node *get_Store_value(const ir_node *node)
1997 {
1998         assert(is_Store(node));
1999         return get_irn_n(node, 2);
2000 }
2001
2002 void set_Store_value(ir_node *node, ir_node *value)
2003 {
2004         assert(is_Store(node));
2005         set_irn_n(node, 2, value);
2006 }
2007
2008 ir_volatility get_Store_volatility(const ir_node *node)
2009 {
2010         assert(is_Store(node));
2011         return node->attr.store.volatility;
2012 }
2013
2014 void set_Store_volatility(ir_node *node, ir_volatility volatility)
2015 {
2016         assert(is_Store(node));
2017         node->attr.store.volatility = volatility;
2018 }
2019
2020 ir_align get_Store_align(const ir_node *node)
2021 {
2022         assert(is_Store(node));
2023         return node->attr.store.aligned;
2024 }
2025
2026 void set_Store_align(ir_node *node, ir_align align)
2027 {
2028         assert(is_Store(node));
2029         node->attr.store.aligned = align;
2030 }
2031
2032
2033 ir_node *get_Alloc_mem(const ir_node *node)
2034 {
2035         assert(is_Alloc(node));
2036         return get_irn_n(node, 0);
2037 }
2038
2039 void set_Alloc_mem(ir_node *node, ir_node *mem)
2040 {
2041         assert(is_Alloc(node));
2042         set_irn_n(node, 0, mem);
2043 }
2044
2045 ir_node *get_Alloc_count(const ir_node *node)
2046 {
2047         assert(is_Alloc(node));
2048         return get_irn_n(node, 1);
2049 }
2050
2051 void set_Alloc_count(ir_node *node, ir_node *count)
2052 {
2053         assert(is_Alloc(node));
2054         set_irn_n(node, 1, count);
2055 }
2056
2057 ir_type *get_Alloc_type(ir_node *node)
2058 {
2059         assert(is_Alloc(node));
2060         return node->attr.alloc.type;
2061 }
2062
2063 void set_Alloc_type(ir_node *node, ir_type *tp)
2064 {
2065         assert(is_Alloc(node));
2066         node->attr.alloc.type = tp;
2067 }
2068
2069 ir_where_alloc get_Alloc_where(const ir_node *node)
2070 {
2071         assert(is_Alloc(node));
2072         return node->attr.alloc.where;
2073 }
2074
2075 void set_Alloc_where(ir_node *node, ir_where_alloc where)
2076 {
2077         assert(is_Alloc(node));
2078         node->attr.alloc.where = where;
2079 }
2080
2081
2082 ir_node *get_Free_mem(const ir_node *node)
2083 {
2084         assert(is_Free(node));
2085         return get_irn_n(node, 0);
2086 }
2087
2088 void set_Free_mem(ir_node *node, ir_node *mem)
2089 {
2090         assert(is_Free(node));
2091         set_irn_n(node, 0, mem);
2092 }
2093
2094 ir_node *get_Free_ptr(const ir_node *node)
2095 {
2096         assert(is_Free(node));
2097         return get_irn_n(node, 1);
2098 }
2099
2100 void set_Free_ptr(ir_node *node, ir_node *ptr)
2101 {
2102         assert(is_Free(node));
2103         set_irn_n(node, 1, ptr);
2104 }
2105
2106 ir_node *get_Free_size(const ir_node *node)
2107 {
2108         assert(is_Free(node));
2109         return get_irn_n(node, 2);
2110 }
2111
2112 void set_Free_size(ir_node *node, ir_node *size)
2113 {
2114         assert(is_Free(node));
2115         set_irn_n(node, 2, size);
2116 }
2117
2118 ir_type *get_Free_type(ir_node *node)
2119 {
2120         assert(is_Free(node));
2121         return node->attr.free.type;
2122 }
2123
2124 void set_Free_type(ir_node *node, ir_type *tp)
2125 {
2126         assert(is_Free(node));
2127         node->attr.free.type = tp;
2128 }
2129
2130 ir_where_alloc get_Free_where(const ir_node *node)
2131 {
2132         assert(is_Free(node));
2133         return node->attr.free.where;
2134 }
2135
2136 void set_Free_where(ir_node *node, ir_where_alloc where)
2137 {
2138         assert(is_Free(node));
2139         node->attr.free.where = where;
2140 }
2141
2142 ir_node **get_Sync_preds_arr(ir_node *node)
2143 {
2144         assert(is_Sync(node));
2145         return (ir_node **)&(get_irn_in(node)[1]);
2146 }
2147
2148 int get_Sync_n_preds(const ir_node *node)
2149 {
2150         assert(is_Sync(node));
2151         return (get_irn_arity(node));
2152 }
2153
2154 /*
2155 void set_Sync_n_preds(ir_node *node, int n_preds)
2156 {
2157         assert(is_Sync(node));
2158 }
2159 */
2160
2161 ir_node *get_Sync_pred(const ir_node *node, int pos)
2162 {
2163         assert(is_Sync(node));
2164         return get_irn_n(node, pos);
2165 }
2166
2167 void set_Sync_pred(ir_node *node, int pos, ir_node *pred)
2168 {
2169         assert(is_Sync(node));
2170         set_irn_n(node, pos, pred);
2171 }
2172
2173 /* Add a new Sync predecessor */
2174 void add_Sync_pred(ir_node *node, ir_node *pred)
2175 {
2176         assert(is_Sync(node));
2177         add_irn_n(node, pred);
2178 }
2179
2180 /* Returns the source language type of a Proj node. */
2181 ir_type *get_Proj_type(ir_node *n)
2182 {
2183         ir_type *tp   = firm_unknown_type;
2184         ir_node *pred = get_Proj_pred(n);
2185
2186         switch (get_irn_opcode(pred)) {
2187         case iro_Proj: {
2188                 ir_node *pred_pred;
2189                 /* Deal with Start / Call here: we need to know the Proj Nr. */
2190                 assert(get_irn_mode(pred) == mode_T);
2191                 pred_pred = get_Proj_pred(pred);
2192
2193                 if (is_Start(pred_pred))  {
2194                         ir_type *mtp = get_entity_type(get_irg_entity(get_irn_irg(pred_pred)));
2195                         tp = get_method_param_type(mtp, get_Proj_proj(n));
2196                 } else if (is_Call(pred_pred)) {
2197                         ir_type *mtp = get_Call_type(pred_pred);
2198                         tp = get_method_res_type(mtp, get_Proj_proj(n));
2199                 }
2200         } break;
2201         case iro_Start: break;
2202         case iro_Call: break;
2203         case iro_Load: {
2204                 ir_node *a = get_Load_ptr(pred);
2205                 if (is_Sel(a))
2206                         tp = get_entity_type(get_Sel_entity(a));
2207         } break;
2208         default:
2209                 break;
2210         }
2211         return tp;
2212 }
2213
2214 ir_node *get_Proj_pred(const ir_node *node)
2215 {
2216         assert(is_Proj(node));
2217         return get_irn_n(node, 0);
2218 }
2219
2220 void set_Proj_pred(ir_node *node, ir_node *pred)
2221 {
2222         assert(is_Proj(node));
2223         set_irn_n(node, 0, pred);
2224 }
2225
2226 long get_Proj_proj(const ir_node *node)
2227 {
2228 #ifdef INTERPROCEDURAL_VIEW
2229         ir_opcode code = get_irn_opcode(node);
2230
2231         if (code == iro_Proj) {
2232                 return node->attr.proj;
2233         }
2234         else {
2235                 assert(code == iro_Filter);
2236                 return node->attr.filter.proj;
2237         }
2238 #else
2239         assert(is_Proj(node));
2240         return node->attr.proj;
2241 #endif /* INTERPROCEDURAL_VIEW */
2242 }
2243
2244 void set_Proj_proj(ir_node *node, long proj)
2245 {
2246 #ifdef INTERPROCEDURAL_VIEW
2247         ir_opcode code = get_irn_opcode(node);
2248
2249         if (code == iro_Proj) {
2250                 node->attr.proj = proj;
2251         }
2252         else {
2253                 assert(code == iro_Filter);
2254                 node->attr.filter.proj = proj;
2255         }
2256 #else
2257         assert(is_Proj(node));
2258         node->attr.proj = proj;
2259 #endif /* INTERPROCEDURAL_VIEW */
2260 }
2261
2262 /* Returns non-zero if a node is a routine parameter. */
2263 int (is_arg_Proj)(const ir_node *node)
2264 {
2265         return _is_arg_Proj(node);
2266 }
2267
2268 ir_node **get_Tuple_preds_arr(ir_node *node)
2269 {
2270         assert(is_Tuple(node));
2271         return (ir_node **)&(get_irn_in(node)[1]);
2272 }
2273
2274 int get_Tuple_n_preds(const ir_node *node)
2275 {
2276         assert(is_Tuple(node));
2277         return get_irn_arity(node);
2278 }
2279
2280 /*
2281 void set_Tuple_n_preds(ir_node *node, int n_preds)
2282 {
2283         assert(is_Tuple(node));
2284 }
2285 */
2286
2287 ir_node *get_Tuple_pred(const ir_node *node, int pos)
2288 {
2289   assert(is_Tuple(node));
2290   return get_irn_n(node, pos);
2291 }
2292
2293 void set_Tuple_pred(ir_node *node, int pos, ir_node *pred)
2294 {
2295         assert(is_Tuple(node));
2296         set_irn_n(node, pos, pred);
2297 }
2298
2299 ir_node *get_Id_pred(const ir_node *node)
2300 {
2301         assert(is_Id(node));
2302         return get_irn_n(node, 0);
2303 }
2304
2305 void set_Id_pred(ir_node *node, ir_node *pred)
2306 {
2307         assert(is_Id(node));
2308         set_irn_n(node, 0, pred);
2309 }
2310
2311 ir_node *get_Confirm_value(const ir_node *node)
2312 {
2313         assert(is_Confirm(node));
2314         return get_irn_n(node, 0);
2315 }
2316
2317 void set_Confirm_value(ir_node *node, ir_node *value)
2318 {
2319         assert(is_Confirm(node));
2320         set_irn_n(node, 0, value);
2321 }
2322
2323 ir_node *get_Confirm_bound(const ir_node *node)
2324 {
2325         assert(is_Confirm(node));
2326         return get_irn_n(node, 1);
2327 }
2328
2329 void set_Confirm_bound(ir_node *node, ir_node *bound)
2330 {
2331         assert(is_Confirm(node));
2332         set_irn_n(node, 0, bound);
2333 }
2334
2335 pn_Cmp get_Confirm_cmp(const ir_node *node)
2336 {
2337         assert(is_Confirm(node));
2338         return node->attr.confirm.cmp;
2339 }
2340
2341 void set_Confirm_cmp(ir_node *node, pn_Cmp cmp)
2342 {
2343         assert(is_Confirm(node));
2344         node->attr.confirm.cmp = cmp;
2345 }
2346
2347 ir_node *get_Filter_pred(ir_node *node)
2348 {
2349         assert(is_Filter(node));
2350         return node->in[1];
2351 }
2352
2353 void set_Filter_pred(ir_node *node, ir_node *pred)
2354 {
2355         assert(is_Filter(node));
2356         node->in[1] = pred;
2357 }
2358
2359 long get_Filter_proj(ir_node *node)
2360 {
2361         assert(is_Filter(node));
2362         return node->attr.filter.proj;
2363 }
2364
2365 void set_Filter_proj(ir_node *node, long proj)
2366 {
2367         assert(is_Filter(node));
2368         node->attr.filter.proj = proj;
2369 }
2370
2371 /* Don't use get_irn_arity, get_irn_n in implementation as access
2372    shall work independent of view!!! */
2373 void set_Filter_cg_pred_arr(ir_node *node, int arity, ir_node ** in)
2374 {
2375         assert(is_Filter(node));
2376         if (node->attr.filter.in_cg == NULL || arity != ARR_LEN(node->attr.filter.in_cg) - 1) {
2377                 ir_graph *irg = get_irn_irg(node);
2378                 node->attr.filter.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
2379                 node->attr.filter.backedge = new_backedge_arr(irg->obst, arity);
2380                 node->attr.filter.in_cg[0] = node->in[0];
2381         }
2382         memcpy(node->attr.filter.in_cg + 1, in, sizeof(ir_node *) * arity);
2383 }
2384
2385 void set_Filter_cg_pred(ir_node * node, int pos, ir_node * pred)
2386 {
2387         assert(is_Filter(node) && node->attr.filter.in_cg &&
2388                0 <= pos && pos < ARR_LEN(node->attr.filter.in_cg) - 1);
2389         node->attr.filter.in_cg[pos + 1] = pred;
2390 }
2391
2392 int get_Filter_n_cg_preds(ir_node *node)
2393 {
2394         assert(is_Filter(node) && node->attr.filter.in_cg);
2395         return (ARR_LEN(node->attr.filter.in_cg) - 1);
2396 }
2397
2398 ir_node *get_Filter_cg_pred(ir_node *node, int pos)
2399 {
2400         int arity;
2401         assert(is_Filter(node) && node->attr.filter.in_cg &&
2402                0 <= pos);
2403         arity = ARR_LEN(node->attr.filter.in_cg);
2404         assert(pos < arity - 1);
2405         return node->attr.filter.in_cg[pos + 1];
2406 }
2407
2408 /* Mux support */
2409 ir_node *get_Mux_sel(const ir_node *node)
2410 {
2411         assert(is_Mux(node));
2412         return node->in[1];
2413 }
2414
2415 void set_Mux_sel(ir_node *node, ir_node *sel)
2416 {
2417         assert(is_Mux(node));
2418         node->in[1] = sel;
2419 }
2420
2421 ir_node *get_Mux_false(const ir_node *node)
2422 {
2423         assert(is_Mux(node));
2424         return node->in[2];
2425 }
2426
2427 void set_Mux_false(ir_node *node, ir_node *ir_false)
2428 {
2429         assert(is_Mux(node));
2430         node->in[2] = ir_false;
2431 }
2432
2433 ir_node *get_Mux_true(const ir_node *node)
2434 {
2435         assert(is_Mux(node));
2436         return node->in[3];
2437 }
2438
2439 void set_Mux_true(ir_node *node, ir_node *ir_true)
2440 {
2441         assert(is_Mux(node));
2442         node->in[3] = ir_true;
2443 }
2444
2445 /* CopyB support */
2446 ir_node *get_CopyB_mem(const ir_node *node)
2447 {
2448         assert(is_CopyB(node));
2449         return get_irn_n(node, 0);
2450 }
2451
2452 void set_CopyB_mem(ir_node *node, ir_node *mem)
2453 {
2454         assert(node->op == op_CopyB);
2455         set_irn_n(node, 0, mem);
2456 }
2457
2458 ir_node *get_CopyB_dst(const ir_node *node)
2459 {
2460         assert(is_CopyB(node));
2461         return get_irn_n(node, 1);
2462 }
2463
2464 void set_CopyB_dst(ir_node *node, ir_node *dst)
2465 {
2466         assert(is_CopyB(node));
2467         set_irn_n(node, 1, dst);
2468 }
2469
2470 ir_node *get_CopyB_src(const ir_node *node)
2471 {
2472   assert(is_CopyB(node));
2473   return get_irn_n(node, 2);
2474 }
2475
2476 void set_CopyB_src(ir_node *node, ir_node *src)
2477 {
2478         assert(is_CopyB(node));
2479         set_irn_n(node, 2, src);
2480 }
2481
2482 ir_type *get_CopyB_type(ir_node *node)
2483 {
2484         assert(is_CopyB(node));
2485         return node->attr.copyb.type;
2486 }
2487
2488 void set_CopyB_type(ir_node *node, ir_type *data_type)
2489 {
2490         assert(is_CopyB(node) && data_type);
2491         node->attr.copyb.type = data_type;
2492 }
2493
2494
2495 ir_type *get_InstOf_type(ir_node *node)
2496 {
2497         assert(node->op == op_InstOf);
2498         return node->attr.instof.type;
2499 }
2500
2501 void set_InstOf_type(ir_node *node, ir_type *type)
2502 {
2503         assert(node->op == op_InstOf);
2504         node->attr.instof.type = type;
2505 }
2506
2507 ir_node *get_InstOf_store(const ir_node *node)
2508 {
2509         assert(node->op == op_InstOf);
2510         return get_irn_n(node, 0);
2511 }
2512
2513 void set_InstOf_store(ir_node *node, ir_node *obj)
2514 {
2515         assert(node->op == op_InstOf);
2516         set_irn_n(node, 0, obj);
2517 }
2518
2519 ir_node *get_InstOf_obj(const ir_node *node)
2520 {
2521         assert(node->op == op_InstOf);
2522         return get_irn_n(node, 1);
2523 }
2524
2525 void set_InstOf_obj(ir_node *node, ir_node *obj)
2526 {
2527         assert(node->op == op_InstOf);
2528         set_irn_n(node, 1, obj);
2529 }
2530
2531 /* Returns the memory input of a Raise operation. */
2532 ir_node *get_Raise_mem(const ir_node *node)
2533 {
2534         assert(is_Raise(node));
2535         return get_irn_n(node, 0);
2536 }
2537
2538 void set_Raise_mem(ir_node *node, ir_node *mem)
2539 {
2540         assert(is_Raise(node));
2541         set_irn_n(node, 0, mem);
2542 }
2543
2544 ir_node *get_Raise_exo_ptr(const ir_node *node)
2545 {
2546         assert(is_Raise(node));
2547         return get_irn_n(node, 1);
2548 }
2549
2550 void set_Raise_exo_ptr(ir_node *node, ir_node *exo_ptr)
2551 {
2552         assert(is_Raise(node));
2553         set_irn_n(node, 1, exo_ptr);
2554 }
2555
2556 /* Bound support */
2557
2558 /* Returns the memory input of a Bound operation. */
2559 ir_node *get_Bound_mem(const ir_node *bound)
2560 {
2561         assert(is_Bound(bound));
2562         return get_irn_n(bound, 0);
2563 }
2564
2565 void set_Bound_mem(ir_node *bound, ir_node *mem)
2566 {
2567         assert(is_Bound(bound));
2568         set_irn_n(bound, 0, mem);
2569 }
2570
2571 /* Returns the index input of a Bound operation. */
2572 ir_node *get_Bound_index(const ir_node *bound)
2573 {
2574         assert(is_Bound(bound));
2575         return get_irn_n(bound, 1);
2576 }
2577
2578 void set_Bound_index(ir_node *bound, ir_node *idx)
2579 {
2580         assert(is_Bound(bound));
2581         set_irn_n(bound, 1, idx);
2582 }
2583
2584 /* Returns the lower bound input of a Bound operation. */
2585 ir_node *get_Bound_lower(const ir_node *bound)
2586 {
2587         assert(is_Bound(bound));
2588         return get_irn_n(bound, 2);
2589 }
2590
2591 void set_Bound_lower(ir_node *bound, ir_node *lower)
2592 {
2593         assert(is_Bound(bound));
2594         set_irn_n(bound, 2, lower);
2595 }
2596
2597 /* Returns the upper bound input of a Bound operation. */
2598 ir_node *get_Bound_upper(const ir_node *bound)
2599 {
2600         assert(is_Bound(bound));
2601         return get_irn_n(bound, 3);
2602 }
2603
2604 void set_Bound_upper(ir_node *bound, ir_node *upper)
2605 {
2606         assert(is_Bound(bound));
2607         set_irn_n(bound, 3, upper);
2608 }
2609
2610 /* Return the operand of a Pin node. */
2611 ir_node *get_Pin_op(const ir_node *pin)
2612 {
2613         assert(is_Pin(pin));
2614         return get_irn_n(pin, 0);
2615 }
2616
2617 void set_Pin_op(ir_node *pin, ir_node *node)
2618 {
2619         assert(is_Pin(pin));
2620         set_irn_n(pin, 0, node);
2621 }
2622
2623 /* Return the assembler text of an ASM pseudo node. */
2624 ident *get_ASM_text(const ir_node *node)
2625 {
2626         assert(is_ASM(node));
2627         return node->attr.assem.asm_text;
2628 }
2629
2630 /* Return the number of input constraints for an ASM node. */
2631 int get_ASM_n_input_constraints(const ir_node *node)
2632 {
2633         assert(is_ASM(node));
2634         return ARR_LEN(node->attr.assem.inputs);
2635 }
2636
2637 /* Return the input constraints for an ASM node. This is a flexible array. */
2638 const ir_asm_constraint *get_ASM_input_constraints(const ir_node *node)
2639 {
2640         assert(is_ASM(node));
2641         return node->attr.assem.inputs;
2642 }
2643
2644 /* Return the number of output constraints for an ASM node.  */
2645 int get_ASM_n_output_constraints(const ir_node *node)
2646 {
2647         assert(is_ASM(node));
2648         return ARR_LEN(node->attr.assem.outputs);
2649 }
2650
2651 /* Return the output constraints for an ASM node. */
2652 const ir_asm_constraint *get_ASM_output_constraints(const ir_node *node)
2653 {
2654         assert(is_ASM(node));
2655         return node->attr.assem.outputs;
2656 }
2657
2658 /* Return the number of clobbered registers for an ASM node.  */
2659 int get_ASM_n_clobbers(const ir_node *node)
2660 {
2661         assert(is_ASM(node));
2662         return ARR_LEN(node->attr.assem.clobber);
2663 }
2664
2665 /* Return the list of clobbered registers for an ASM node. */
2666 ident **get_ASM_clobbers(const ir_node *node)
2667 {
2668         assert(is_ASM(node));
2669         return node->attr.assem.clobber;
2670 }
2671
2672 /* returns the graph of a node */
2673 ir_graph *(get_irn_irg)(const ir_node *node)
2674 {
2675         return _get_irn_irg(node);
2676 }
2677
2678
2679 /*----------------------------------------------------------------*/
2680 /*  Auxiliary routines                                            */
2681 /*----------------------------------------------------------------*/
2682
2683 ir_node *skip_Proj(ir_node *node)
2684 {
2685         /* don't assert node !!! */
2686         if (node == NULL)
2687                 return NULL;
2688
2689         if (is_Proj(node))
2690                 node = get_Proj_pred(node);
2691
2692         return node;
2693 }
2694
2695 const ir_node *
2696 skip_Proj_const(const ir_node *node)
2697 {
2698         /* don't assert node !!! */
2699         if (node == NULL)
2700                 return NULL;
2701
2702         if (is_Proj(node))
2703                 node = get_Proj_pred(node);
2704
2705         return node;
2706 }
2707
2708 ir_node *skip_Tuple(ir_node *node)
2709 {
2710   ir_node *pred;
2711   ir_op   *op;
2712
2713 restart:
2714         if (is_Proj(node)) {
2715             pred = get_Proj_pred(node);
2716             op   = get_irn_op(pred);
2717
2718                 /*
2719                  * Looks strange but calls get_irn_op() only once
2720                  * in most often cases.
2721                  */
2722                 if (op == op_Proj) { /* nested Tuple ? */
2723                     pred = skip_Tuple(pred);
2724
2725                         if (is_Tuple(pred)) {
2726                                 node = get_Tuple_pred(pred, get_Proj_proj(node));
2727                                 goto restart;
2728                         }
2729                 } else if (op == op_Tuple) {
2730                         node = get_Tuple_pred(pred, get_Proj_proj(node));
2731                         goto restart;
2732                 }
2733         }
2734         return node;
2735 }
2736
2737 /* returns operand of node if node is a Cast */
2738 ir_node *skip_Cast(ir_node *node)
2739 {
2740         if (is_Cast(node))
2741                 return get_Cast_op(node);
2742         return node;
2743 }
2744
2745 /* returns operand of node if node is a Cast */
2746 const ir_node *skip_Cast_const(const ir_node *node)
2747 {
2748         if (is_Cast(node))
2749                 return get_Cast_op(node);
2750         return node;
2751 }
2752
2753 /* returns operand of node if node is a Pin */
2754 ir_node *skip_Pin(ir_node *node)
2755 {
2756         if (is_Pin(node))
2757                 return get_Pin_op(node);
2758         return node;
2759 }
2760
2761 /* returns operand of node if node is a Confirm */
2762 ir_node *skip_Confirm(ir_node *node)
2763 {
2764         if (is_Confirm(node))
2765                 return get_Confirm_value(node);
2766         return node;
2767 }
2768
2769 /* skip all high-level ops */
2770 ir_node *skip_HighLevel_ops(ir_node *node)
2771 {
2772         while (is_op_highlevel(get_irn_op(node))) {
2773                 node = get_irn_n(node, 0);
2774         }
2775         return node;
2776 }
2777
2778
2779 /* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity
2780  * than any other approach, as Id chains are resolved and all point to the real node, or
2781  * all id's are self loops.
2782  *
2783  * Note: This function takes 10% of mostly ANY the compiler run, so it's
2784  * a little bit "hand optimized".
2785  *
2786  * Moreover, it CANNOT be switched off using get_opt_normalize() ...
2787  */
2788 ir_node *skip_Id(ir_node *node)
2789 {
2790         ir_node *pred;
2791         /* don't assert node !!! */
2792
2793         if (!node || (node->op != op_Id)) return node;
2794
2795         /* Don't use get_Id_pred():  We get into an endless loop for
2796            self-referencing Ids. */
2797         pred = node->in[0+1];
2798
2799         if (pred->op != op_Id) return pred;
2800
2801         if (node != pred) {  /* not a self referencing Id. Resolve Id chain. */
2802                 ir_node *rem_pred, *res;
2803
2804                 if (pred->op != op_Id) return pred; /* shortcut */
2805                 rem_pred = pred;
2806
2807                 assert(get_irn_arity (node) > 0);
2808
2809                 node->in[0+1] = node;   /* turn us into a self referencing Id:  shorten Id cycles. */
2810                 res = skip_Id(rem_pred);
2811                 if (res->op == op_Id) /* self-loop */ return node;
2812
2813                 node->in[0+1] = res;    /* Turn Id chain into Ids all referencing the chain end. */
2814                 return res;
2815         } else {
2816                 return node;
2817         }
2818 }
2819
2820 int (is_strictConv)(const ir_node *node)
2821 {
2822         return _is_strictConv(node);
2823 }
2824
2825 int (is_no_Block)(const ir_node *node)
2826 {
2827         return _is_no_Block(node);
2828 }
2829
2830 /* Returns true if node is a SymConst node with kind symconst_addr_ent. */
2831 int (is_SymConst_addr_ent)(const ir_node *node)
2832 {
2833         return _is_SymConst_addr_ent(node);
2834 }
2835
2836 /* Returns true if the operation manipulates control flow. */
2837 int is_cfop(const ir_node *node)
2838 {
2839         return is_op_cfopcode(get_irn_op(node));
2840 }
2841
2842 /* Returns true if the operation manipulates interprocedural control flow:
2843    CallBegin, EndReg, EndExcept */
2844 int is_ip_cfop(const ir_node *node)
2845 {
2846         return is_ip_cfopcode(get_irn_op(node));
2847 }
2848
2849 /* Returns true if the operation can change the control flow because
2850    of an exception. */
2851 int is_fragile_op(const ir_node *node)
2852 {
2853         return is_op_fragile(get_irn_op(node));
2854 }
2855
2856 /* Returns the memory operand of fragile operations. */
2857 ir_node *get_fragile_op_mem(ir_node *node)
2858 {
2859         assert(node && is_fragile_op(node));
2860
2861         switch (get_irn_opcode(node)) {
2862         case iro_Call  :
2863         case iro_Quot  :
2864         case iro_DivMod:
2865         case iro_Div   :
2866         case iro_Mod   :
2867         case iro_Load  :
2868         case iro_Store :
2869         case iro_Alloc :
2870         case iro_Bound :
2871         case iro_CopyB :
2872                 return get_irn_n(node, pn_Generic_M);
2873         case iro_Bad   :
2874         case iro_Unknown:
2875                 return node;
2876         default: ;
2877                 assert(0 && "should not be reached");
2878                 return NULL;
2879         }
2880 }
2881
2882 /* Returns the result mode of a Div operation. */
2883 ir_mode *get_divop_resmod(const ir_node *node)
2884 {
2885         switch (get_irn_opcode(node)) {
2886         case iro_Quot  : return get_Quot_resmode(node);
2887         case iro_DivMod: return get_DivMod_resmode(node);
2888         case iro_Div   : return get_Div_resmode(node);
2889         case iro_Mod   : return get_Mod_resmode(node);
2890         default: ;
2891                 assert(0 && "should not be reached");
2892                 return NULL;
2893         }
2894 }
2895
2896 /* Returns true if the operation is a forking control flow operation. */
2897 int (is_irn_forking)(const ir_node *node)
2898 {
2899         return _is_irn_forking(node);
2900 }
2901
2902 void (copy_node_attr)(ir_graph *irg, const ir_node *old_node, ir_node *new_node)
2903 {
2904         _copy_node_attr(irg, old_node, new_node);
2905 }
2906
2907 /* Return the type associated with the value produced by n
2908  * if the node remarks this type as it is the case for
2909  * Cast, Const, SymConst and some Proj nodes. */
2910 ir_type *(get_irn_type)(ir_node *node)
2911 {
2912         return _get_irn_type(node);
2913 }
2914
2915 /* Return the type attribute of a node n (SymConst, Call, Alloc, Free,
2916    Cast) or NULL.*/
2917 ir_type *(get_irn_type_attr)(ir_node *node)
2918 {
2919         return _get_irn_type_attr(node);
2920 }
2921
2922 /* Return the entity attribute of a node n (SymConst, Sel) or NULL. */
2923 ir_entity *(get_irn_entity_attr)(ir_node *node)
2924 {
2925         return _get_irn_entity_attr(node);
2926 }
2927
2928 /* Returns non-zero for constant-like nodes. */
2929 int (is_irn_constlike)(const ir_node *node)
2930 {
2931         return _is_irn_constlike(node);
2932 }
2933
2934 /*
2935  * Returns non-zero for nodes that are allowed to have keep-alives and
2936  * are neither Block nor PhiM.
2937  */
2938 int (is_irn_keep)(const ir_node *node)
2939 {
2940         return _is_irn_keep(node);
2941 }
2942
2943 /*
2944  * Returns non-zero for nodes that are always placed in the start block.
2945  */
2946 int (is_irn_start_block_placed)(const ir_node *node)
2947 {
2948         return _is_irn_start_block_placed(node);
2949 }
2950
2951 /* Returns non-zero for nodes that are machine operations. */
2952 int (is_irn_machine_op)(const ir_node *node)
2953 {
2954         return _is_irn_machine_op(node);
2955 }
2956
2957 /* Returns non-zero for nodes that are machine operands. */
2958 int (is_irn_machine_operand)(const ir_node *node)
2959 {
2960         return _is_irn_machine_operand(node);
2961 }
2962
2963 /* Returns non-zero for nodes that have the n'th user machine flag set. */
2964 int (is_irn_machine_user)(const ir_node *node, unsigned n)
2965 {
2966         return _is_irn_machine_user(node, n);
2967 }
2968
2969 /* Returns non-zero for nodes that are CSE neutral to its users. */
2970 int (is_irn_cse_neutral)(const ir_node *node)
2971 {
2972         return _is_irn_cse_neutral(node);
2973 }
2974
2975 /* Gets the string representation of the jump prediction .*/
2976 const char *get_cond_jmp_predicate_name(cond_jmp_predicate pred)
2977 {
2978 #define X(a)    case a: return #a;
2979         switch (pred) {
2980                 X(COND_JMP_PRED_NONE);
2981                 X(COND_JMP_PRED_TRUE);
2982                 X(COND_JMP_PRED_FALSE);
2983         }
2984         return "<unknown>";
2985 #undef X
2986 }
2987
2988 /* Returns the conditional jump prediction of a Cond node. */
2989 cond_jmp_predicate (get_Cond_jmp_pred)(const ir_node *cond)
2990 {
2991         return _get_Cond_jmp_pred(cond);
2992 }
2993
2994 /* Sets a new conditional jump prediction. */
2995 void (set_Cond_jmp_pred)(ir_node *cond, cond_jmp_predicate pred)
2996 {
2997         _set_Cond_jmp_pred(cond, pred);
2998 }
2999
3000 /** the get_type operation must be always implemented and return a firm type */
3001 static ir_type *get_Default_type(ir_node *n)
3002 {
3003         (void) n;
3004         return get_unknown_type();
3005 }
3006
3007 /* Sets the get_type operation for an ir_op_ops. */
3008 ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops)
3009 {
3010         switch (code) {
3011         case iro_Const:    ops->get_type = get_Const_type; break;
3012         case iro_SymConst: ops->get_type = get_SymConst_value_type; break;
3013         case iro_Cast:     ops->get_type = get_Cast_type; break;
3014         case iro_Proj:     ops->get_type = get_Proj_type; break;
3015         default:
3016                 /* not allowed to be NULL */
3017                 if (! ops->get_type)
3018                         ops->get_type = get_Default_type;
3019                 break;
3020         }
3021         return ops;
3022 }
3023
3024 /** Return the attribute type of a SymConst node if exists */
3025 static ir_type *get_SymConst_attr_type(ir_node *self)
3026 {
3027         symconst_kind kind = get_SymConst_kind(self);
3028         if (SYMCONST_HAS_TYPE(kind))
3029                 return get_SymConst_type(self);
3030         return NULL;
3031 }
3032
3033 /** Return the attribute entity of a SymConst node if exists */
3034 static ir_entity *get_SymConst_attr_entity(ir_node *self)
3035 {
3036         symconst_kind kind = get_SymConst_kind(self);
3037         if (SYMCONST_HAS_ENT(kind))
3038                 return get_SymConst_entity(self);
3039         return NULL;
3040 }
3041
3042 /** the get_type_attr operation must be always implemented */
3043 static ir_type *get_Null_type(ir_node *n)
3044 {
3045         (void) n;
3046         return firm_unknown_type;
3047 }
3048
3049 /* Sets the get_type operation for an ir_op_ops. */
3050 ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops)
3051 {
3052         switch (code) {
3053         case iro_SymConst: ops->get_type_attr = get_SymConst_attr_type; break;
3054         case iro_Call:     ops->get_type_attr = get_Call_type; break;
3055         case iro_Alloc:    ops->get_type_attr = get_Alloc_type; break;
3056         case iro_Free:     ops->get_type_attr = get_Free_type; break;
3057         case iro_Cast:     ops->get_type_attr = get_Cast_type; break;
3058         default:
3059                 /* not allowed to be NULL */
3060                 if (! ops->get_type_attr)
3061                         ops->get_type_attr = get_Null_type;
3062                 break;
3063         }
3064         return ops;
3065 }
3066
3067 /** the get_entity_attr operation must be always implemented */
3068 static ir_entity *get_Null_ent(ir_node *n)
3069 {
3070         (void) n;
3071         return NULL;
3072 }
3073
3074 /* Sets the get_type operation for an ir_op_ops. */
3075 ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops)
3076 {
3077         switch (code) {
3078         case iro_SymConst: ops->get_entity_attr = get_SymConst_attr_entity; break;
3079         case iro_Sel:      ops->get_entity_attr = _get_Sel_entity; break;
3080         default:
3081                 /* not allowed to be NULL */
3082                 if (! ops->get_entity_attr)
3083                         ops->get_entity_attr = get_Null_ent;
3084                 break;
3085         }
3086         return ops;
3087 }
3088
3089 /* Sets the debug information of a node. */
3090 void (set_irn_dbg_info)(ir_node *n, dbg_info *db)
3091 {
3092         _set_irn_dbg_info(n, db);
3093 }
3094
3095 /**
3096  * Returns the debug information of an node.
3097  *
3098  * @param n   The node.
3099  */
3100 dbg_info *(get_irn_dbg_info)(const ir_node *n)
3101 {
3102         return _get_irn_dbg_info(n);
3103 }
3104
3105 /* checks whether a node represents a global address */
3106 int is_Global(const ir_node *node)
3107 {
3108         return is_SymConst_addr_ent(node);
3109 }
3110
3111 /* returns the entity of a global address */
3112 ir_entity *get_Global_entity(const ir_node *node)
3113 {
3114         return get_SymConst_entity(node);
3115 }
3116
3117 /*
3118  * Calculate a hash value of a node.
3119  */
3120 unsigned firm_default_hash(const ir_node *node)
3121 {
3122         unsigned h;
3123         int i, irn_arity;
3124
3125         /* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */
3126         h = irn_arity = get_irn_intra_arity(node);
3127
3128         /* consider all in nodes... except the block if not a control flow. */
3129         for (i = is_cfop(node) ? -1 : 0;  i < irn_arity;  ++i) {
3130                 ir_node *pred = get_irn_intra_n(node, i);
3131                 if (is_irn_cse_neutral(pred))
3132                         h *= 9;
3133                 else
3134                         h = 9*h + HASH_PTR(pred);
3135         }
3136
3137         /* ...mode,... */
3138         h = 9*h + HASH_PTR(get_irn_mode(node));
3139         /* ...and code */
3140         h = 9*h + HASH_PTR(get_irn_op(node));
3141
3142         return h;
3143 }  /* firm_default_hash */
3144
3145 /* include generated code */
3146 #include "gen_irnode.c.inl"