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