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