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