- fixed CSE and Combo for Builtin nodes
[libfirm] / ir / ir / irnode_t.h
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 -- private header.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  * @version $Id$
25  */
26 #ifndef FIRM_IR_IRNODE_T_H
27 #define FIRM_IR_IRNODE_T_H
28
29 #include "irtypes.h"
30 #include "irnode.h"
31 #include "irop_t.h"
32 #include "irgraph_t.h"
33 #include "irflag_t.h"
34 #include "firm_common_t.h"
35 #include "array.h"
36
37 /**
38  * Returns the array with the ins.  The content of the array may not be
39  * changed.
40  * Note that this function returns the whole in array including the
41  * block predecessor. So, it is NOT symmetric with set_irn_in().
42  */
43 ir_node     **get_irn_in            (const ir_node *node);
44
45 /** @{ */
46 /** access attributes directly */
47 const_attr    *get_irn_const_attr    (ir_node *node);
48 long          get_irn_proj_attr      (ir_node *node);
49 alloc_attr    *get_irn_alloc_attr    (ir_node *node);
50 free_attr     *get_irn_free_attr     (ir_node *node);
51 symconst_attr *get_irn_symconst_attr (ir_node *node);
52 ir_type       *get_irn_call_attr     (ir_node *node);
53 ir_type       *get_irn_funccall_attr (ir_node *node);
54 sel_attr      *get_irn_sel_attr      (ir_node *node);
55 phi_attr      *get_irn_phi_attr      (ir_node *node);
56 block_attr    *get_irn_block_attr    (ir_node *node);
57 load_attr     *get_irn_load_attr     (ir_node *node);
58 store_attr    *get_irn_store_attr    (ir_node *node);
59 except_attr   *get_irn_except_attr   (ir_node *node);
60 divmod_attr   *get_irn_divmod_attr   (ir_node *node);
61 builtin_attr  *get_irn_builtin_attr  (ir_node *node);
62 /** @} */
63
64 /**
65  * The amount of additional space for custom data to be allocated upon creating a new node.
66  */
67 extern unsigned firm_add_node_size;
68
69 /**
70  * Sets the get_type operation for an ir_op_ops.
71  *
72  * @param code   the opcode for the default operation
73  * @param ops    the operations initialized
74  *
75  * @return
76  *    The operations.
77  */
78 ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops);
79
80 /**
81  * Sets the get_type_attr operation for an ir_op_ops.
82  *
83  * @param code   the opcode for the default operation
84  * @param ops    the operations initialized
85  *
86  * @return
87  *    The operations.
88  */
89 ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops);
90
91 /**
92  * Sets the get_entity_attr operation for an ir_op_ops.
93  *
94  * @param code   the opcode for the default operation
95  * @param ops    the operations initialized
96  *
97  * @return
98  *    The operations.
99  */
100 ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops);
101
102 /*-------------------------------------------------------------------*/
103 /*  These function are most used in libfirm.  Give them as static    */
104 /*  functions so they can be inlined.                                */
105 /*-------------------------------------------------------------------*/
106
107 /**
108  * Checks whether a pointer points to a ir node.
109  * Intern version for libFirm.
110  */
111 static inline int
112 _is_ir_node(const void *thing) {
113         return (get_kind(thing) == k_ir_node);
114 }
115
116 /**
117  * Gets the op of a node.
118  * Intern version for libFirm.
119  */
120 static inline ir_op *
121 _get_irn_op(const ir_node *node) {
122         assert(node);
123         return node->op;
124 }
125
126 static inline void
127 _set_irn_op(ir_node *node, ir_op *op) {
128         assert(node);
129         node->op = op;
130 }
131
132 /** Copies all attributes stored in the old node  to the new node.
133     Assumes both have the same opcode and sufficient size. */
134 static inline void
135 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
136         ir_op *op = _get_irn_op(old_node);
137
138         /* must always exist */
139         op->ops.copy_attr(old_node, new_node);
140 }
141
142 /**
143  * Gets the opcode of a node.
144  * Intern version for libFirm.
145  */
146 static inline unsigned
147 _get_irn_opcode(const ir_node *node) {
148         assert(k_ir_node == get_kind(node));
149         assert(node->op);
150         return node->op->code;
151 }
152
153 /**
154  * Returns the number of predecessors without the block predecessor.
155  * Intern version for libFirm.
156  */
157 static inline int
158 _get_irn_intra_arity(const ir_node *node) {
159         assert(node);
160         return ARR_LEN(node->in) - 1;
161 }
162
163 /**
164  * Returns the number of predecessors without the block predecessor.
165  * Intern version for libFirm.
166  */
167 static inline int
168 _get_irn_inter_arity(const ir_node *node) {
169         assert(node);
170         if (_get_irn_op(node) == op_Filter) {
171                 assert(node->attr.filter.in_cg);
172                 return ARR_LEN(node->attr.filter.in_cg) - 1;
173         } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
174                 return ARR_LEN(node->attr.block.in_cg) - 1;
175         }
176         return _get_irn_intra_arity(node);
177 }
178
179 #ifdef INTERPROCEDURAL_VIEW
180 /**
181  * Returns the number of predecessors without the block predecessor.
182  * Intern version for libFirm.
183  */
184 extern int (*_get_irn_arity)(const ir_node *node);
185
186 #else
187
188 #define _get_irn_arity(n) _get_irn_intra_arity(n)
189 #endif
190
191 /**
192  * Intern version for libFirm.
193  */
194 static inline ir_node *
195 _get_irn_intra_n(const ir_node *node, int n) {
196         ir_node *nn;
197
198         assert(node);
199         assert(-1 <= n && n < _get_irn_intra_arity(node));
200
201         nn = node->in[n + 1];
202         if (nn == NULL) {
203                 /* only block and Anchor inputs are allowed to be NULL */
204                 assert((node->op == op_Anchor || n == -1) && "NULL input of a node");
205                 return NULL;
206         }
207         if (nn->op != op_Id) return nn;
208
209         return (node->in[n + 1] = skip_Id(nn));
210 }
211
212 /**
213  * Intern version for libFirm.
214  */
215 static inline ir_node*
216 _get_irn_inter_n(const ir_node *node, int n) {
217         assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
218
219         /* handle Filter and Block specially */
220         if (_get_irn_op(node) == op_Filter) {
221                 assert(node->attr.filter.in_cg);
222                 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
223         } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
224                 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
225         }
226
227         return _get_irn_intra_n(node, n);
228 }
229
230 /**
231  * returns a hash value for a node
232  */
233 static inline unsigned hash_irn(const ir_node *node)
234 {
235         return (unsigned) get_irn_idx(node);
236 }
237
238 /**
239  * Access to the predecessors of a node.
240  * To iterate over the operands iterate from 0 to i < get_irn_arity(),
241  * to iterate including the Block predecessor iterate from i = -1 to
242  * i < get_irn_arity.
243  * If it is a block, the entry -1 is NULL.
244  * Intern version for libFirm.
245  */
246 #ifdef INTERPROCEDURAL_VIEW
247 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
248 #else
249 #define _get_irn_n(n,i) _get_irn_intra_n(n,i)
250 #endif
251
252 static inline int _get_irn_deps(const ir_node *node) {
253         return node->deps ? ARR_LEN(node->deps) : 0;
254 }
255
256 static inline ir_node *_get_irn_dep(const ir_node *node, int pos) {
257         assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
258         assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
259         return node->deps[pos];
260 }
261
262 static inline void
263 _set_irn_dep(ir_node *node, int pos, ir_node *dep) {
264         ir_node *old;
265
266         assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
267         assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
268         old = node->deps[pos];
269         node->deps[pos] = dep;
270         edges_notify_edge_kind(node, pos, dep, old, EDGE_KIND_DEP, get_irn_irg(node));
271 }
272
273
274 static inline int
275 _get_irn_ins_or_deps(const ir_node *irn) {
276         return _get_irn_deps(irn) + _get_irn_arity(irn);
277 }
278
279 static inline ir_node *
280 _get_irn_in_or_dep(const ir_node *irn, int pos) {
281         int n_in = get_irn_arity(irn);
282         return pos < n_in ? get_irn_n(irn, pos) : get_irn_dep(irn, pos - n_in);
283 }
284
285 /**
286  * Gets the mode of a node.
287  * Intern version for libFirm.
288  */
289 static inline ir_mode *
290 _get_irn_mode(const ir_node *node) {
291         assert(node);
292         return node->mode;
293 }
294
295 /**
296  * Sets the mode of a node.
297  * Intern version of libFirm.
298  */
299 static inline void
300 _set_irn_mode(ir_node *node, ir_mode *mode) {
301         assert(node);
302         node->mode = mode;
303 }
304
305 /**
306  * Gets the visited counter of a node.
307  * Intern version for libFirm.
308  */
309 static inline ir_visited_t
310 _get_irn_visited(const ir_node *node) {
311         assert(node);
312         return node->visited;
313 }
314
315 /**
316  * Sets the visited counter of a node.
317  * Intern version for libFirm.
318  */
319 static inline void
320 _set_irn_visited(ir_node *node, ir_visited_t visited) {
321         assert(node);
322         node->visited = visited;
323 }
324
325 /**
326  * Mark a node as visited in a graph.
327  * Intern version for libFirm.
328  */
329 static inline void
330 _mark_irn_visited(ir_node *node) {
331         assert(node);
332         node->visited = current_ir_graph->visited;
333 }
334
335 /**
336  * Returns non-zero if a node of was visited.
337  * Intern version for libFirm.
338  */
339 static inline int
340 _irn_visited(const ir_node *node) {
341         assert(node);
342         return (node->visited >= current_ir_graph->visited);
343 }
344
345 static inline int
346 _irn_visited_else_mark(ir_node *node) {
347         if (_irn_visited(node))
348                 return 1;
349         _mark_irn_visited(node);
350         return 0;
351 }
352
353 /**
354  * Sets the link of a node.
355  * Intern version of libFirm.
356  */
357 static inline void
358 _set_irn_link(ir_node *node, void *link) {
359         assert(node);
360         node->link = link;
361 }
362
363 /**
364  * Returns the link of a node.
365  * Intern version of libFirm.
366  */
367 static inline void *
368 _get_irn_link(const ir_node *node) {
369         assert(node && _is_ir_node(node));
370         return node->link;
371 }
372
373 /**
374  * Returns whether the node _always_ must be pinned.
375  * I.e., the node is not floating after global cse.
376  *
377  * Intern version of libFirm.
378  */
379 static inline op_pin_state
380 _get_irn_pinned(const ir_node *node) {
381         op_pin_state state;
382         assert(node && _is_ir_node(node));
383         /* Check opcode */
384         state = _get_op_pinned(_get_irn_op(node));
385
386         if (state >= op_pin_state_exc_pinned)
387                 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
388         return state;
389 }
390
391 static inline op_pin_state
392 _is_irn_pinned_in_irg(const ir_node *node) {
393         if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
394                 return get_irn_pinned(node);
395         return op_pin_state_pinned;
396 }
397
398 static inline int
399 _is_unop(const ir_node *node) {
400         assert(node && _is_ir_node(node));
401         return (node->op->opar == oparity_unary);
402 }
403
404 static inline int
405 _is_binop(const ir_node *node) {
406         assert(node && _is_ir_node(node));
407         return (node->op->opar == oparity_binary);
408 }
409
410 static inline int
411 _is_Phi(const ir_node *node) {
412         ir_op *op;
413         assert(node);
414
415         op = get_irn_op(node);
416 #ifdef INTERPROCEDURAL_VIEW
417         if (op == op_Filter) return get_interprocedural_view();
418 #endif
419         return (op == op_Phi);
420 }
421
422 static inline int
423 _is_Proj(const ir_node *node) {
424         ir_op *op;
425         assert(node);
426
427         op = _get_irn_op(node);
428 #ifdef INTERPROCEDURAL_VIEW
429         if (op == op_Filter) return !get_interprocedural_view();
430 #endif
431         return (op == op_Proj);
432 }
433
434 static inline int
435 _is_Filter(const ir_node *node) {
436         assert(node);
437         return (_get_irn_op(node) == op_Filter);
438 }
439
440 static inline int
441 _is_Bad(const ir_node *node) {
442         assert(node);
443         return (_get_irn_op(node) == op_Bad);
444 }
445
446 static inline int
447 _is_NoMem(const ir_node *node) {
448         assert(node);
449         return (_get_irn_op(node) == op_NoMem);
450 }
451
452 static inline int
453 _is_Minus(const ir_node *node) {
454         assert(node);
455         return (_get_irn_op(node) == op_Minus);
456 }
457
458 static inline int
459 _is_Abs(const ir_node *node) {
460         assert(node);
461         return (_get_irn_op(node) == op_Abs);
462 }
463
464 static inline int
465 _is_Mod(const ir_node *node) {
466         assert(node);
467         return (_get_irn_op(node) == op_Mod);
468 }
469
470 static inline int
471 _is_Div(const ir_node *node) {
472         assert(node);
473         return (_get_irn_op(node) == op_Div);
474 }
475
476 static inline int
477 _is_DivMod(const ir_node *node) {
478         assert(node);
479         return (_get_irn_op(node) == op_DivMod);
480 }
481
482 static inline int
483 _is_Quot(const ir_node *node) {
484         assert(node);
485         return (_get_irn_op(node) == op_Quot);
486 }
487
488 static inline int
489 _is_Add(const ir_node *node) {
490         assert(node);
491         return (_get_irn_op(node) == op_Add);
492 }
493
494 static inline int
495 _is_Carry(const ir_node *node) {
496         assert(node);
497         return (_get_irn_op(node) == op_Carry);
498 }
499
500 static inline int
501 _is_And(const ir_node *node) {
502         assert(node);
503         return (_get_irn_op(node) == op_And);
504 }
505
506 static inline int
507 _is_Or(const ir_node *node) {
508         assert(node);
509         return (_get_irn_op(node) == op_Or);
510 }
511
512 static inline int
513 _is_Eor(const ir_node *node) {
514         assert(node);
515         return (_get_irn_op(node) == op_Eor);
516 }
517
518 static inline int
519 _is_Sub(const ir_node *node) {
520         assert(node);
521         return (_get_irn_op(node) == op_Sub);
522 }
523
524 static inline int
525 _is_Not(const ir_node *node) {
526         assert(node);
527         return (_get_irn_op(node) == op_Not);
528 }
529
530 static inline int
531 _is_Shl(const ir_node *node) {
532         assert(node);
533         return (_get_irn_op(node) == op_Shl);
534 }
535
536 static inline int
537 _is_Shr(const ir_node *node) {
538         assert(node);
539         return (_get_irn_op(node) == op_Shr);
540 }
541
542 static inline int
543 _is_Shrs(const ir_node *node) {
544         assert(node);
545         return (_get_irn_op(node) == op_Shrs);
546 }
547
548 static inline int
549 _is_Rotl(const ir_node *node) {
550         assert(node);
551         return (_get_irn_op(node) == op_Rotl);
552 }
553
554 static inline int
555 _is_Id(const ir_node *node) {
556         assert(node);
557         return (_get_irn_op(node) == op_Id);
558 }
559
560 static inline int
561 _is_Tuple(const ir_node *node) {
562         assert(node);
563         return (_get_irn_op(node) == op_Tuple);
564 }
565
566 static inline int
567 _is_Bound(const ir_node *node) {
568         assert(node);
569         return (_get_irn_op(node) == op_Bound);
570 }
571
572 static inline int
573 _is_Start(const ir_node *node) {
574         assert(node);
575         return (_get_irn_op(node) == op_Start);
576 }
577
578 static inline int
579 _is_End(const ir_node *node) {
580         assert(node);
581         return (_get_irn_op(node) == op_End);
582 }
583
584 static inline int
585 _is_Const(const ir_node *node) {
586         assert(node);
587         return (_get_irn_op(node) == op_Const);
588 }
589
590 static inline int
591 _is_Conv(const ir_node *node) {
592         assert(node);
593         return (_get_irn_op(node) == op_Conv);
594 }
595
596 static inline int
597 _is_strictConv(const ir_node *node) {
598         return _is_Conv(node) && get_Conv_strict(node);
599 }
600
601 static inline int
602 _is_Cast(const ir_node *node) {
603         assert(node);
604         return (_get_irn_op(node) == op_Cast);
605 }
606
607 static inline int
608 _is_CopyB(const ir_node *node) {
609         assert(node);
610         return (_get_irn_op(node) == op_CopyB);
611 }
612
613 static inline int
614 _is_Unknown(const ir_node *node) {
615         assert(node);
616         return (_get_irn_op(node) == op_Unknown);
617 }
618
619 static inline int
620 _is_Return(const ir_node *node) {
621         assert(node);
622         return (_get_irn_op(node) == op_Return);
623 }
624
625 static inline int
626 _is_Call(const ir_node *node) {
627         assert(node);
628         return (_get_irn_op(node) == op_Call);
629 }
630
631 static inline int
632 _is_Builtin(const ir_node *node) {
633         assert(node);
634         return (_get_irn_op(node) == op_Builtin);
635 }
636
637 static inline int
638 _is_CallBegin(const ir_node *node) {
639         assert(node);
640         return (_get_irn_op(node) == op_CallBegin);
641 }
642
643 static inline int
644 _is_Sel(const ir_node *node) {
645         assert(node);
646         return (_get_irn_op(node) == op_Sel);
647 }
648
649 static inline int
650 _is_Mul(const ir_node *node) {
651         assert(node);
652         return (_get_irn_op(node) == op_Mul);
653 }
654
655 static inline int
656 _is_Mulh(const ir_node *node) {
657         assert(node);
658         return (_get_irn_op(node) == op_Mulh);
659 }
660
661 static inline int
662 _is_Mux(const ir_node *node) {
663         assert(node);
664         return (_get_irn_op(node) == op_Mux);
665 }
666
667 static inline int
668 _is_Load(const ir_node *node) {
669         assert(node);
670         return (_get_irn_op(node) == op_Load);
671 }
672
673 static inline int
674 _is_Store(const ir_node *node) {
675         assert(node);
676         return (_get_irn_op(node) == op_Store);
677 }
678
679 static inline int
680 _is_Sync(const ir_node *node) {
681         assert(node);
682         return (_get_irn_op(node) == op_Sync);
683 }
684
685 static inline int
686 _is_Confirm(const ir_node *node) {
687         assert(node);
688         return (_get_irn_op(node) == op_Confirm);
689 }
690
691 static inline int
692 _is_Pin(const ir_node *node) {
693         assert(node);
694         return (_get_irn_op(node) == op_Pin);
695 }
696
697 static inline int
698 _is_SymConst(const ir_node *node) {
699         assert(node);
700         return (_get_irn_op(node) == op_SymConst);
701 }
702
703 static inline int
704 _is_SymConst_addr_ent(const ir_node *node) {
705         return is_SymConst(node) && get_SymConst_kind(node) == symconst_addr_ent;
706 }
707
708 static inline int
709 _is_Cond(const ir_node *node) {
710         assert(node);
711         return (_get_irn_op(node) == op_Cond);
712 }
713
714 static inline int
715 _is_Cmp(const ir_node *node) {
716         assert(node);
717         return (_get_irn_op(node) == op_Cmp);
718 }
719
720 static inline int
721 _is_Alloc(const ir_node *node) {
722         assert(node);
723         return (_get_irn_op(node) == op_Alloc);
724 }
725
726 static inline int
727 _is_Free(const ir_node *node) {
728         assert(node);
729         return (_get_irn_op(node) == op_Free);
730 }
731
732 static inline int
733 _is_Jmp(const ir_node *node) {
734         assert(node);
735         return (_get_irn_op(node) == op_Jmp);
736 }
737
738 static inline int
739 _is_IJmp(const ir_node *node) {
740         assert(node);
741         return (_get_irn_op(node) == op_IJmp);
742 }
743
744 static inline int
745 _is_Raise(const ir_node *node) {
746         assert(node);
747         return (_get_irn_op(node) == op_Raise);
748 }
749
750 static inline int
751 _is_ASM(const ir_node *node) {
752         assert(node);
753         return (_get_irn_op(node) == op_ASM);
754 }
755
756 static inline int
757 _is_Anchor(const ir_node *node) {
758         return (_get_irn_op(node) == op_Anchor);
759 }
760
761 static inline int
762 _is_no_Block(const ir_node *node) {
763         assert(node && _is_ir_node(node));
764         return (_get_irn_op(node) != op_Block);
765 }
766
767 static inline int
768 _is_Block(const ir_node *node) {
769         assert(node && _is_ir_node(node));
770         return (_get_irn_op(node) == op_Block);
771 }
772
773 static inline int
774 _get_Block_n_cfgpreds(const ir_node *node) {
775         assert(_is_Block(node));
776         return _get_irn_arity(node);
777 }
778
779 static inline ir_node *
780 _get_Block_cfgpred(const ir_node *node, int pos) {
781         assert(0 <= pos && pos < get_irn_arity(node));
782         assert(_is_Block(node));
783         return _get_irn_n(node, pos);
784 }
785
786 /* Get the predecessor block.
787  *
788  *  Returns the block corresponding to the predecessor pos.
789  *
790  *  There are several ambiguities we resolve with this function:
791  *  - The direct predecessor can be a Proj, which is not pinned.
792  *    We walk from the predecessor to the next pinned node
793  *    (skip_Proj) and return the block that node is in.
794  *  - If we encounter the Bad node, this function does not return
795  *    Start, but the Bad node.
796  */
797 static inline ir_node  *
798 _get_Block_cfgpred_block(const ir_node *node, int pos) {
799         ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
800         if (!is_Bad(res))
801                 res = get_nodes_block(res);
802         return res;
803 }
804
805 static inline ir_visited_t
806 _get_Block_block_visited(const ir_node *node) {
807         assert(node->op == op_Block);
808         return node->attr.block.block_visited;
809 }
810
811 static inline void
812 _set_Block_block_visited(ir_node *node, ir_visited_t visit) {
813         assert(node->op == op_Block);
814         node->attr.block.block_visited = visit;
815 }
816
817 /* For this current_ir_graph must be set. */
818 static inline void
819 _mark_Block_block_visited(ir_node *node) {
820         assert(node->op == op_Block);
821         node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
822 }
823
824 static inline int
825 _Block_block_visited(const ir_node *node) {
826         assert(node->op == op_Block);
827         return (node->attr.block.block_visited >= get_irg_block_visited(current_ir_graph));
828 }
829
830 static inline ir_node *
831 _set_Block_dead(ir_node *block) {
832         assert(_get_irn_op(block) == op_Block);
833         block->attr.block.dom.dom_depth = -1;
834         block->attr.block.is_dead = 1;
835         return block;
836 }
837
838 static inline int
839 _is_Block_dead(const ir_node *block) {
840         ir_op *op = _get_irn_op(block);
841
842         if (op == op_Bad)
843                 return 1;
844         else {
845                 assert(op == op_Block);
846                 return block->attr.block.is_dead;
847         }
848 }
849
850 static inline tarval *_get_Const_tarval(const ir_node *node) {
851         assert(_get_irn_op(node) == op_Const);
852         return node->attr.con.tv;
853 }
854
855 static inline int _is_Const_null(const ir_node *node) {
856         return tarval_is_null(_get_Const_tarval(node));
857 }
858
859 static inline int _is_Const_one(const ir_node *node) {
860         return tarval_is_one(_get_Const_tarval(node));
861 }
862
863 static inline int _is_Const_all_one(const ir_node *node) {
864         return tarval_is_all_one(_get_Const_tarval(node));
865 }
866
867 static inline int _is_irn_forking(const ir_node *node) {
868         return is_op_forking(_get_irn_op(node));
869 }
870
871 static inline ir_type *_get_irn_type(ir_node *node) {
872         return _get_irn_op(node)->ops.get_type(node);
873 }
874
875 static inline ir_type *_get_irn_type_attr(ir_node *node) {
876         return _get_irn_op(node)->ops.get_type_attr(node);
877 }
878
879 static inline ir_entity *_get_irn_entity_attr(ir_node *node) {
880   return _get_irn_op(node)->ops.get_entity_attr(node);
881 }
882
883 static inline int _is_irn_constlike(const ir_node *node) {
884         return is_op_constlike(_get_irn_op(node));
885 }
886
887 static inline int _is_irn_always_opt(const ir_node *node) {
888         return is_op_always_opt(_get_irn_op(node));
889 }
890
891 static inline int _is_irn_keep(const ir_node *node) {
892         return is_op_keep(_get_irn_op(node));
893 }
894
895 static inline int _is_irn_start_block_placed(const ir_node *node) {
896         return is_op_start_block_placed(_get_irn_op(node));
897 }
898
899 static inline int _is_irn_machine_op(const ir_node *node) {
900         return is_op_machine(_get_irn_op(node));
901 }
902
903 static inline int _is_irn_machine_operand(const ir_node *node) {
904         return is_op_machine_operand(_get_irn_op(node));
905 }
906
907 static inline int _is_irn_machine_user(const ir_node *node, unsigned n) {
908         return is_op_machine_user(_get_irn_op(node), n);
909 }
910
911 static inline cond_jmp_predicate _get_Cond_jmp_pred(const ir_node *node) {
912         assert(_get_irn_op(node) == op_Cond);
913         return node->attr.cond.pred;
914 }
915
916 static inline void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
917         assert(_get_irn_op(node) == op_Cond);
918         node->attr.cond.pred = pred;
919 }
920
921 static inline void *_get_irn_generic_attr(ir_node *node) {
922         return &node->attr;
923 }
924
925 static inline const void *_get_irn_generic_attr_const(const ir_node *node) {
926         return &node->attr;
927 }
928
929 static inline unsigned _get_irn_idx(const ir_node *node) {
930         return node->node_idx;
931 }
932
933 static inline dbg_info *_get_irn_dbg_info(const ir_node *n) {
934         return n->dbi;
935 }  /* get_irn_dbg_info */
936
937 static inline void _set_irn_dbg_info(ir_node *n, dbg_info *db) {
938         n->dbi = db;
939 }
940
941 /**
942  * Sets the Phi list of a block.
943  */
944 static inline void
945 _set_Block_phis(ir_node *block, ir_node *phi) {
946         assert(_is_Block(block));
947         assert(phi == NULL || _is_Phi(phi));
948         block->attr.block.phis = phi;
949 }
950
951 /**
952  * Returns the link of a node.
953  * Intern version of libFirm.
954  */
955 static inline ir_node *
956 _get_Block_phis(const ir_node *block) {
957         assert(_is_Block(block));
958         return block->attr.block.phis;
959 }
960
961 /**
962  * Sets the next link of a Phi.
963  */
964 static inline void
965 _set_Phi_next(ir_node *phi, ir_node *next) {
966         assert(_is_Phi(phi));
967         phi->attr.phi.next = next;
968 }
969
970 /**
971  * Returns the link of a node.
972  * Intern version of libFirm.
973  */
974 static inline ir_node *
975 _get_Phi_next(const ir_node *phi) {
976         assert(_is_Phi(phi));
977         return phi->attr.phi.next;
978 }
979
980 /** Add a Phi node to the list of Block Phi's. */
981 static inline void
982 _add_Block_phi(ir_node *block, ir_node *phi) {
983         _set_Phi_next(phi, _get_Block_phis(block));
984         _set_Block_phis(block, phi);
985 }
986
987 /** Get the Block mark (single bit). */
988 static inline unsigned
989 _get_Block_mark(const ir_node *block) {
990         assert(_is_Block(block));
991         return block->attr.block.marked;
992 }
993
994 /** Set the Block mark (single bit). */
995 static inline void
996 _set_Block_mark(ir_node *block, unsigned mark) {
997         assert(_is_Block(block));
998         block->attr.block.marked = mark;
999 }
1000
1001 /** Returns non-zero if a node is a routine parameter. */
1002 static inline int
1003 _is_arg_Proj(const ir_node *node) {
1004         if (! is_Proj(node))
1005                 return 0;
1006         node = get_Proj_pred(node);
1007         if (! is_Proj(node))
1008                 return 0;
1009         return pn_Start_T_args == get_Proj_proj(node) && is_Start(get_Proj_pred(node));
1010 }
1011
1012
1013 /* this section MUST contain all inline functions */
1014 #define is_ir_node(thing)                     _is_ir_node(thing)
1015 #define get_irn_intra_arity(node)             _get_irn_intra_arity(node)
1016 #define get_irn_inter_arity(node)             _get_irn_inter_arity(node)
1017 #define get_irn_arity(node)                   _get_irn_arity(node)
1018 #define get_irn_intra_n(node, n)              _get_irn_intra_n(node, n)
1019 #define get_irn_inter_n(node, n)              _get_irn_inter_n(node, n)
1020 #define get_irn_n(node, n)                    _get_irn_n(node, n)
1021 #define get_irn_mode(node)                    _get_irn_mode(node)
1022 #define set_irn_mode(node, mode)              _set_irn_mode(node, mode)
1023 #define get_irn_op(node)                      _get_irn_op(node)
1024 #define set_irn_op(node, op)                  _set_irn_op(node, op)
1025 #define get_irn_opcode(node)                  _get_irn_opcode(node)
1026 #define get_irn_visited(node)                 _get_irn_visited(node)
1027 #define set_irn_visited(node, v)              _set_irn_visited(node, v)
1028 #define mark_irn_visited(node)                _mark_irn_visited(node)
1029 #define irn_visited(node)                     _irn_visited(node)
1030 #define irn_visited_else_mark(node)           _irn_visited_else_mark(node)
1031 #define set_irn_link(node, link)              _set_irn_link(node, link)
1032 #define get_irn_link(node)                    _get_irn_link(node)
1033 #define get_irn_pinned(node)                  _get_irn_pinned(node)
1034 #define is_irn_pinned_in_irg(node)            _is_irn_pinned_in_irg(node)
1035 #define is_unop(node)                         _is_unop(node)
1036 #define is_binop(node)                        _is_binop(node)
1037 #define is_Proj(node)                         _is_Proj(node)
1038 #define is_Filter(node)                       _is_Filter(node)
1039 #define is_Phi(node)                          _is_Phi(node)
1040 #define is_Const(node)                        _is_Const(node)
1041 #define is_Conv(node)                         _is_Conv(node)
1042 #define is_strictConv(node)                   _is_strictConv(node)
1043 #define is_Cast(node)                         _is_Cast(node)
1044 #define is_Unknown(node)                      _is_Unknown(node)
1045 #define is_Return(node)                       _is_Return(node)
1046 #define is_Call(node)                         _is_Call(node)
1047 #define is_Builtin(node)                      _is_Builtin(node)
1048 #define is_CallBegin(node)                    _is_CallBegin(node)
1049 #define is_Sel(node)                          _is_Sel(node)
1050 #define is_Mul(node)                          _is_Mul(node)
1051 #define is_Mulh(node)                         _is_Mulh(node)
1052 #define is_Mux(node)                          _is_Mux(node)
1053 #define is_Load(node)                         _is_Load(node)
1054 #define is_Sync(node)                         _is_Sync(node)
1055 #define is_Confirm(node)                      _is_Confirm(node)
1056 #define is_Pin(node)                          _is_Pin(node)
1057 #define is_SymConst(node)                     _is_SymConst(node)
1058 #define is_SymConst_addr_ent(node)            _is_SymConst_addr_ent(node)
1059 #define is_Cond(node)                         _is_Cond(node)
1060 #define is_CopyB(node)                        _is_CopyB(node)
1061 #define is_Cmp(node)                          _is_Cmp(node)
1062 #define is_Alloc(node)                        _is_Alloc(node)
1063 #define is_Free(node)                         _is_Free(node)
1064 #define is_Jmp(node)                          _is_Jmp(node)
1065 #define is_IJmp(node)                         _is_IJmp(node)
1066 #define is_Raise(node)                        _is_Raise(node)
1067 #define is_ASM(node)                          _is_ASM(node)
1068 #define is_Anchor(node)                       _is_Anchor(node)
1069 #define is_Bad(node)                          _is_Bad(node)
1070 #define is_NoMem(node)                        _is_NoMem(node)
1071 #define is_Start(node)                        _is_Start(node)
1072 #define is_End(node)                          _is_End(node)
1073 #define is_Minus(node)                        _is_Minus(node)
1074 #define is_Abs(node)                          _is_Abs(node)
1075 #define is_Mod(node)                          _is_Mod(node)
1076 #define is_Div(node)                          _is_Div(node)
1077 #define is_DivMod(node)                       _is_DivMod(node)
1078 #define is_Quot(node)                         _is_Quot(node)
1079 #define is_Add(node)                          _is_Add(node)
1080 #define is_Carry(node)                        _is_Carry(node)
1081 #define is_And(node)                          _is_And(node)
1082 #define is_Or(node)                           _is_Or(node)
1083 #define is_Eor(node)                          _is_Eor(node)
1084 #define is_Sub(node)                          _is_Sub(node)
1085 #define is_Not(node)                          _is_Not(node)
1086 #define is_Shl(node)                          _is_Shl(node)
1087 #define is_Shr(node)                          _is_Shr(node)
1088 #define is_Shrs(node)                         _is_Shrs(node)
1089 #define is_Rotl(node)                         _is_Rotl(node)
1090 #define is_Id(node)                           _is_Id(node)
1091 #define is_Tuple(node)                        _is_Tuple(node)
1092 #define is_Bound(node)                        _is_Bound(node)
1093 #define is_no_Block(node)                     _is_no_Block(node)
1094 #define is_Block(node)                        _is_Block(node)
1095 #define get_Block_n_cfgpreds(node)            _get_Block_n_cfgpreds(node)
1096 #define get_Block_cfgpred(node, pos)          _get_Block_cfgpred(node, pos)
1097 #define get_Block_cfgpred_block(node, pos)    _get_Block_cfgpred_block(node, pos)
1098 #define get_Block_block_visited(node)         _get_Block_block_visited(node)
1099 #define set_Block_block_visited(node, visit)  _set_Block_block_visited(node, visit)
1100 #define mark_Block_block_visited(node)        _mark_Block_block_visited(node)
1101 #define Block_block_visited(node)             _Block_block_visited(node)
1102 #define set_Block_dead(block)                 _set_Block_dead(block)
1103 #define is_Block_dead(block)                  _is_Block_dead(block)
1104 #define get_Const_tarval(node)                _get_Const_tarval(node)
1105 #define is_Const_null(node)                   _is_Const_null(node)
1106 #define is_Const_one(node)                    _is_Const_one(node)
1107 #define is_Const_all_one(node)                _is_Const_all_one(node)
1108 #define is_irn_forking(node)                  _is_irn_forking(node)
1109 #define get_irn_type(node)                    _get_irn_type(node)
1110 #define get_irn_type_attr(node)               _get_irn_type_attr(node)
1111 #define get_irn_entity_attr(node)             _get_irn_entity_attr(node)
1112 #define is_irn_constlike(node)                _is_irn_constlike(node)
1113 #define is_irn_always_opt(node)               _is_irn_always_opt(node)
1114 #define is_irn_keep(node)                     _is_irn_keep(node)
1115 #define is_irn_start_block_placed(node)       _is_irn_start_block_placed(node)
1116 #define is_irn_machine_op(node)               _is_irn_machine_op(node)
1117 #define is_irn_machine_operand(node)          _is_irn_machine_operand(node)
1118 #define is_irn_machine_user(node, n)          _is_irn_machine_user(node, n)
1119 #define get_Cond_jmp_pred(node)               _get_Cond_jmp_pred(node)
1120 #define set_Cond_jmp_pred(node, pred)         _set_Cond_jmp_pred(node, pred)
1121 #define get_irn_generic_attr(node)            _get_irn_generic_attr(node)
1122 #define get_irn_generic_attr_const(node)      _get_irn_generic_attr_const(node)
1123 #define get_irn_idx(node)                     _get_irn_idx(node)
1124
1125 #define get_irn_deps(node)                    _get_irn_deps(node)
1126 #define set_irn_dep(node, pos, dep)           _set_irn_dep(node, pos, dep)
1127 #define get_irn_dep(node, pos)                _get_irn_dep(node, pos)
1128
1129 #define get_irn_ins_or_deps(node)             _get_irn_ins_or_deps(node)
1130 #define get_irn_in_or_dep(node, pos)          _get_irn_in_or_dep(node, pos)
1131
1132 #define get_irn_dbg_info(node)                _get_irn_dbg_info(node)
1133 #define set_irn_dbg_info(node, db)            _set_irn_dbg_info(node, db)
1134
1135 #define set_Block_phis(block, phi)            _set_Block_phis(block, phi)
1136 #define get_Block_phis(block)                 _get_Block_phis(block)
1137 #define add_Block_phi(block, phi)             _add_Block_phi(block, phi)
1138 #define get_Block_mark(block)                 _get_Block_mark(block)
1139 #define set_Block_mark(block, mark)           _set_Block_mark(block, mark)
1140
1141 #define set_Phi_next(node, phi)               _set_Phi_next(node, phi)
1142 #define get_Phi_next(node)                    _get_Phi_next(node)
1143
1144 #define is_arg_Proj(node)                     _is_arg_Proj(node)
1145
1146 #endif