Fixed misplaced assert
[libfirm] / ir / ir / irnode_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irnode_t.h
4  * Purpose:     Representation of an intermediate operation -- private header.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier, Michael Beck
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file irnode_t.h
15  *
16  * Declarations of an ir node.
17  *
18  * @author Martin Trapp, Christian Schaefer
19  */
20 #ifndef _FIRM_IRNODE_T_H_
21 #define _FIRM_IRNODE_T_H_
22
23 #include "firm_config.h"
24 #include "irnode.h"
25 #include "irop_t.h"
26 #include "irgraph_t.h"
27 #include "irflag_t.h"
28 #include "firm_common_t.h"
29 #include "irdom_t.h" /* For size of struct dom_info. */
30 #include "dbginfo.h"
31 #include "irloop.h"
32 #include "iredgekinds.h"
33 #include "array.h"
34
35 #include "set.h"
36 #include "list.h"
37 #include "entity_t.h"
38 #include "type_t.h"
39 #include "tv_t.h"
40 #include "irextbb_t.h"
41
42
43 /** ir node attributes **/
44
45 /** Block attributes */
46 typedef struct {
47         /* General attributes */
48         ir_graph *irg;              /**< The graph this block belongs to. */
49         unsigned long block_visited; /**< For the walker that walks over all blocks. */
50         /* Attributes private to construction: */
51         unsigned matured:1;         /**< If set, all in-nodes of the block are fixed. */
52         unsigned dead:1;            /**< If set, the block is dead (and could be replace by a Bad. */
53         ir_node **graph_arr;        /**< An array to store all parameters. */
54         /* Attributes holding analyses information */
55         ir_dom_info dom;            /**< Datastructure that holds information about dominators.
56                                          @@@ @todo
57                                          Eventually overlay with graph_arr as only valid
58                                          in different phases.  Eventually inline the whole
59                                          datastructure. */
60         ir_dom_info pdom;           /**< Datastructure that holds information about post-dominators. */
61         ir_node ** in_cg;           /**< array with predecessors in
62                                      * interprocedural_view, if they differ
63                                      * from intraprocedural predecessors */
64         int *backedge;              /**< Field n set to true if pred n is backedge.
65                                          @@@ @todo Ev. replace by bit field! */
66         int *cg_backedge;           /**< Field n set to true if pred n is interprocedural backedge.
67                                          @@@ @todo Ev. replace by bit field! */
68         ir_extblk *extblk;          /**< The extended basic block this block belongs to. */
69         ir_region *region;          /**< The immediate structural region this block belongs to. */
70
71         struct list_head succ_head; /**< A list head for all successor edges of a block. */
72 } block_attr;
73
74 /** Cond attributes. */
75 typedef struct {
76         cond_kind kind;           /**< flavor of Cond */
77         long default_proj;        /**< only for non-binary Conds: biggest Proj number, i.e. the one used for default. */
78         cond_jmp_predicate pred;  /**< only for binary Conds: The jump predication. */
79 } cond_attr;
80
81 /** Const attributes. */
82 typedef struct {
83         tarval  *tv;       /**< the target value */
84         ir_type *tp;       /**< the source type, for analyses. default: type_unknown. */
85 } const_attr;
86
87 /** SymConst attributes. */
88 typedef struct {
89         symconst_symbol sym;  // old tori
90         symconst_kind num;
91         ir_type *tp;       /**< the source type, for analyses. default: type_unknown. */
92 } symconst_attr;
93
94 /** Sel attributes. */
95 typedef struct {
96         ir_entity *ent;    /**< entity to select */
97 } sel_attr;
98
99 /** Exception attributes. */
100 typedef struct {
101         op_pin_state   pin_state;     /**< the pin state for operations that might generate a exception:
102                                                                          If it's know that no exception will be generated, could be set to
103                                                                          op_pin_state_floats. */
104 #if PRECISE_EXC_CONTEXT
105         struct ir_node **frag_arr;    /**< For Phi node construction in case of exception */
106 #endif
107 } except_attr;
108
109 /** Call attributes. */
110 typedef struct {
111         except_attr    exc;           /**< the exception attribute. MUST be the first one. */
112         ir_type *cld_tp;              /**< type of called procedure */
113         ir_entity ** callee_arr;      /**< result of callee analysis */
114 } call_attr;
115
116 /** Alloc attributes. */
117 typedef struct {
118         except_attr    exc;           /**< the exception attribute. MUST be the first one. */
119         ir_type *type;                /**< Type of the allocated object.  */
120         where_alloc where;            /**< stack, heap or other managed part of memory */
121 } alloc_attr;
122
123 /** Free attributes. */
124 typedef struct {
125         ir_type *type;                /**< Type of the allocated object.  */
126         where_alloc where;            /**< stack, heap or other managed part of memory */
127 } free_attr;
128
129 /** InstOf attributes. */
130 typedef struct {
131         except_attr    exc;           /**< the exception attribute. MUST be the first one. */
132         ir_type *type;                /**< the type of which the object pointer must be */
133 } io_attr;
134
135 /** Filter attributes. */
136 typedef struct {
137         long proj;                 /**< contains the result position to project (Proj) */
138         ir_node ** in_cg;          /**< array with interprocedural predecessors (Phi) */
139         int *backedge;             /**< Field n set to true if pred n is backedge.
140                                         @todo Ev. replace by bitfield! */
141 } filter_attr;
142
143 /** EndReg/EndExcept attributes. */
144 typedef struct {
145         char dummy;
146 } end_attr;
147
148 /** CallBegin attributes. */
149 typedef struct {
150         ir_node * call;               /**< Associated Call-operation. */
151 } callbegin_attr;
152
153 /** Cast attributes. */
154 typedef struct {
155         ir_type *totype;              /**< Type of the casted node. */
156 } cast_attr;
157
158 /** Load attributes. */
159 typedef struct {
160         except_attr   exc;            /**< The exception attribute. MUST be the first one. */
161         ir_mode       *load_mode;     /**< The mode of this Load operation. */
162         ir_volatility volatility;     /**< The volatility of a Load/Store operation. */
163 } load_attr;
164
165 /** Store attributes. */
166 typedef struct {
167         except_attr   exc;            /**< the exception attribute. MUST be the first one. */
168         ir_volatility volatility;     /**< the volatility of a Store operation */
169 } store_attr;
170
171 typedef pn_Cmp confirm_attr;    /**< Attribute to hold compare operation */
172
173 /** CopyB attribute. */
174 typedef struct {
175         except_attr    exc;           /**< The exception attribute. MUST be the first one. */
176         ir_type        *data_type;    /**< Type of the copied entity. */
177 } copyb_attr;
178
179 /** Bound attribute. */
180 typedef struct {
181         except_attr exc;              /**< The exception attribute. MUST be the first one. */
182 } bound_attr;
183
184 /** Conv attribute. */
185 typedef struct {
186         char           strict;        /**< If set, this is a strict Conv that cannot be removed. */
187 } conv_attr;
188
189 /** Some IR-nodes just have one attribute, these are stored here,
190    some have more. Their name is 'irnodename_attr' */
191 typedef union {
192         block_attr     block;   /**< For Block: Fields needed to construct it */
193         cond_attr      cond;    /**< For Cond. */
194         const_attr     con;     /**< For Const: contains the value of the constant and a type */
195         symconst_attr  symc;    /**< For SymConst. */
196         sel_attr       sel;     /**< For Sel. */
197         call_attr      call;    /**< For Call: pointer to the type of the method to call */
198         callbegin_attr callbegin; /**< For CallBegin */
199         alloc_attr     alloc;  /**< For Alloc. */
200         free_attr      free;   /**< For Free. */
201         io_attr        instof; /**< For InstOf */
202         cast_attr      cast;   /**< For Cast. */
203         load_attr      load;   /**< For Load. */
204         store_attr     store;  /**< For Store. */
205         int            phi0_pos;  /**< For Phi. Used to remember the value defined by
206                          this Phi node.  Needed when the Phi is completed
207                          to call get_r_internal_value to find the
208                          predecessors. If this attribute is set, the Phi
209                          node takes the role of the obsolete Phi0 node,
210                          therefore the name. */
211         int *phi_backedge;    /**< For Phi after construction.
212                                    Field n set to true if pred n is backedge.
213                                    @todo Ev. replace by bitfield! */
214         long           proj;          /**< For Proj: contains the result position to project */
215         confirm_attr   confirm_cmp;   /**< For Confirm: compare operation */
216         filter_attr    filter;        /**< For Filter */
217         end_attr       end;           /**< For EndReg, EndExcept */
218         except_attr    except;        /**< For Phi node construction in case of exceptions */
219         copyb_attr     copyb;         /**< For CopyB operation */
220         bound_attr     bound;         /**< For Bound operation */
221         conv_attr      conv;          /**< For Conv operation */
222 } attr;
223
224 /**
225 * Edge info to put into an irn.
226 */
227 typedef struct _irn_edge_kind_info_t {
228         struct list_head outs_head;  /**< The list of all outs. */
229         int out_count;               /**< Number of outs in the list. */
230 } irn_edge_info_t;
231
232 typedef irn_edge_info_t irn_edges_info_t[EDGE_KIND_LAST];
233
234 /**
235  * The common structure of an irnode.
236  * If the node has some attributes, they are stored in the attr field.
237  */
238 struct ir_node {
239         /* ------- Basics of the representation  ------- */
240         firm_kind kind;          /**< Distinguishes this node from others. */
241         ir_op *op;               /**< The Opcode of this node. */
242         ir_mode *mode;           /**< The Mode of this node. */
243         struct ir_node **in;     /**< The array of predecessors / operands. */
244         unsigned long visited;   /**< The visited counter for walks of the graph. */
245         unsigned node_idx;       /**< The node index of this node in its graph. */
246         void *link;              /**< To attach additional information to the node, e.g.
247                                       used while construction to link Phi0 nodes and
248                                       during optimization to link to nodes that
249                                       shall replace a node. */
250         /* ------- Fields for optimizations / analysis information ------- */
251         struct ir_node **out;    /**< @deprecated array of out edges. */
252         struct dbg_info *dbi;    /**< A pointer to information for debug support. */
253         /* ------- For debugging ------- */
254 #ifdef DEBUG_libfirm
255         int out_valid;
256         long node_nr;            /**< A unique node number for each node to make output
257                                       readable. */
258 #endif
259         /* ------- For analyses -------- */
260         ir_loop *loop;           /**< the loop the node is in. Access routines in irloop.h */
261 #ifdef DO_HEAPANALYSIS
262         struct abstval *av;      /**< Heapanalysis: The abstract value of this node. */
263         struct section *sec;     /**< Heapanalysis: The section of this node. */
264 #endif
265         struct ir_node **deps;   /**< Additional dependencies induced by state. */
266         irn_edges_info_t edge_info;  /**< Everlasting out edges. */
267         /* ------- Opcode depending fields -------- */
268         attr attr;               /**< The set of attributes of this node. Depends on opcode.
269                                       Must be last field of struct ir_node. */
270 };
271
272
273 /**
274  * Returns the array with the ins.  The content of the array may not be
275  * changed.
276  * Note that this function returns the whole in array including the
277  * block predecessor. So, it is NOT symmetric with set_irn_in().
278  */
279 ir_node     **get_irn_in            (const ir_node *node);
280
281 /** @{ */
282 /** access attributes directly */
283 const_attr    get_irn_const_attr    (ir_node *node);
284 long          get_irn_proj_attr     (ir_node *node);
285 alloc_attr    get_irn_alloc_attr    (ir_node *node);
286 free_attr     get_irn_free_attr     (ir_node *node);
287 symconst_attr get_irn_symconst_attr (ir_node *node);
288 ir_type      *get_irn_call_attr     (ir_node *node);
289 ir_type      *get_irn_funccall_attr (ir_node *node);
290 sel_attr      get_irn_sel_attr      (ir_node *node);
291 int           get_irn_phi_attr      (ir_node *node);
292 block_attr    get_irn_block_attr    (ir_node *node);
293 load_attr     get_irn_load_attr     (ir_node *node);
294 store_attr    get_irn_store_attr    (ir_node *node);
295 except_attr   get_irn_except_attr   (ir_node *node);
296 /** @} */
297
298 /**
299  * The amount of additional space for custom data to be allocated upon creating a new node.
300  */
301 extern unsigned firm_add_node_size;
302
303 /**
304  * Sets the get_type operation for an ir_op_ops.
305  *
306  * @param code   the opcode for the default operation
307  * @param ops    the operations initialized
308  *
309  * @return
310  *    The operations.
311  */
312 ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops);
313
314 /**
315  * Sets the get_type_attr operation for an ir_op_ops.
316  *
317  * @param code   the opcode for the default operation
318  * @param ops    the operations initialized
319  *
320  * @return
321  *    The operations.
322  */
323 ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops);
324
325 /**
326  * Sets the get_entity_attr operation for an ir_op_ops.
327  *
328  * @param code   the opcode for the default operation
329  * @param ops    the operations initialized
330  *
331  * @return
332  *    The operations.
333  */
334 ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops);
335
336 /*-------------------------------------------------------------------*/
337 /*  These function are most used in libfirm.  Give them as static    */
338 /*  functions so they can be inlined.                                */
339 /*-------------------------------------------------------------------*/
340
341 /**
342  * Checks whether a pointer points to a ir node.
343  * Intern version for libFirm.
344  */
345 static INLINE int
346 _is_ir_node(const void *thing) {
347         return (get_kind(thing) == k_ir_node);
348 }
349
350 /**
351  * Gets the op of a node.
352  * Intern version for libFirm.
353  */
354 static INLINE ir_op *
355 _get_irn_op(const ir_node *node) {
356         assert(node);
357         return node->op;
358 }
359
360 static INLINE void
361 _set_irn_op(ir_node *node, ir_op *op) {
362         assert(node);
363         node->op = op;
364 }
365
366 /** Copies all attributes stored in the old node  to the new node.
367     Assumes both have the same opcode and sufficient size. */
368 static INLINE void
369 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
370         ir_op *op = _get_irn_op(old_node);
371
372         /* must always exist */
373         op->ops.copy_attr(old_node, new_node);
374 }
375
376 /**
377  * Gets the opcode of a node.
378  * Intern version for libFirm.
379  */
380 static INLINE ir_opcode
381 _get_irn_opcode(const ir_node *node) {
382         assert(k_ir_node == get_kind(node));
383         assert(node->op);
384         return node->op->code;
385 }
386
387 /**
388  * Returns the number of predecessors without the block predecessor.
389  * Intern version for libFirm.
390  */
391 static INLINE int
392 _get_irn_intra_arity(const ir_node *node) {
393         assert(node);
394         return ARR_LEN(node->in) - 1;
395 }
396
397 /**
398  * Returns the number of predecessors without the block predecessor.
399  * Intern version for libFirm.
400  */
401 static INLINE int
402 _get_irn_inter_arity(const ir_node *node) {
403         assert(node);
404         if (_get_irn_op(node) == op_Filter) {
405                 assert(node->attr.filter.in_cg);
406                 return ARR_LEN(node->attr.filter.in_cg) - 1;
407         } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
408                 return ARR_LEN(node->attr.block.in_cg) - 1;
409         }
410         return _get_irn_intra_arity(node);
411 }
412
413 /**
414  * Returns the number of predecessors without the block predecessor.
415  * Intern version for libFirm.
416  */
417 extern int (*_get_irn_arity)(const ir_node *node);
418
419 /**
420  * Intern version for libFirm.
421  */
422 static INLINE ir_node *
423 _get_irn_intra_n(const ir_node *node, int n) {
424         ir_node *nn;
425
426         assert(node);
427         assert(-1 <= n && n < _get_irn_intra_arity(node));
428
429         nn = node->in[n + 1];
430         if (nn == NULL) {
431                 /* only block inputs are allowed to be NULL */
432                 assert(n == -1 && "NULL input of a node");
433                 return NULL;
434         }
435         if (nn->op != op_Id) return nn;
436
437         return (node->in[n + 1] = skip_Id(nn));
438 }
439
440 /**
441  * Intern version for libFirm.
442  */
443 static INLINE ir_node*
444 _get_irn_inter_n(const ir_node *node, int n) {
445         assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
446
447         /* handle Filter and Block specially */
448         if (_get_irn_op(node) == op_Filter) {
449                 assert(node->attr.filter.in_cg);
450                 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
451         } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
452                 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
453         }
454
455         return _get_irn_intra_n(node, n);
456 }
457
458 /**
459  * Access to the predecessors of a node.
460  * To iterate over the operands iterate from 0 to i < get_irn_arity(),
461  * to iterate including the Block predecessor iterate from i = -1 to
462  * i < get_irn_arity.
463  * If it is a block, the entry -1 is NULL.
464  * Intern version for libFirm.
465  */
466 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
467
468 static INLINE int _get_irn_deps(const ir_node *node) {
469         return node->deps ? ARR_LEN(node->deps) : 0;
470 }
471
472 static INLINE ir_node *_get_irn_dep(const ir_node *node, int pos) {
473         assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
474         assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
475         return node->deps[pos];
476 }
477
478 static INLINE void
479 _set_irn_dep(ir_node *node, int pos, ir_node *dep) {
480         ir_node *old;
481
482         assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
483         assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
484         old = node->deps[pos];
485         node->deps[pos] = dep;
486         edges_notify_edge_kind(node, pos, dep, old, EDGE_KIND_DEP, get_irn_irg(node));
487 }
488
489
490 static INLINE int
491 _get_irn_ins_or_deps(const ir_node *irn) {
492         return _get_irn_deps(irn) + _get_irn_arity(irn);
493 }
494
495 static INLINE ir_node *
496 _get_irn_in_or_dep(const ir_node *irn, int pos) {
497         int n_in = get_irn_arity(irn);
498         return pos < n_in ? get_irn_n(irn, pos) : get_irn_dep(irn, pos - n_in);
499 }
500
501 /**
502  * Gets the mode of a node.
503  * Intern version for libFirm.
504  */
505 static INLINE ir_mode *
506 _get_irn_mode(const ir_node *node) {
507         assert(node);
508         return node->mode;
509 }
510
511 /**
512  * Sets the mode of a node.
513  * Intern version of libFirm.
514  */
515 static INLINE void
516 _set_irn_mode(ir_node *node, ir_mode *mode) {
517         assert(node);
518         node->mode = mode;
519 }
520
521 /**
522  * Gets the visited counter of a node.
523  * Intern version for libFirm.
524  */
525 static INLINE unsigned long
526 _get_irn_visited(const ir_node *node) {
527         assert(node);
528         return node->visited;
529 }
530
531 /**
532  * Sets the visited counter of a node.
533  * Intern version for libFirm.
534  */
535 static INLINE void
536 _set_irn_visited(ir_node *node, unsigned long visited) {
537         assert(node);
538         node->visited = visited;
539 }
540
541 /**
542  * Mark a node as visited in a graph.
543  * Intern version for libFirm.
544  */
545 static INLINE void
546 _mark_irn_visited(ir_node *node) {
547         assert(node);
548         node->visited = current_ir_graph->visited;
549 }
550
551 /**
552  * Returns non-zero if a node of was visited.
553  * Intern version for libFirm.
554  */
555 static INLINE int
556 _irn_visited(const ir_node *node) {
557         assert(node);
558         return (node->visited >= current_ir_graph->visited);
559 }
560
561 /**
562  * Returns non-zero if a node of was NOT visited.
563  * Intern version for libFirm.
564  */
565 static INLINE int
566 _irn_not_visited(const ir_node *node) {
567         assert(node);
568         return (node->visited < current_ir_graph->visited);
569 }
570
571 /**
572  * Sets the link of a node.
573  * Intern version of libFirm.
574  */
575 static INLINE void
576 _set_irn_link(ir_node *node, void *link) {
577   assert(node);
578         /* Link field is used for Phi construction and various optimizations
579            in iropt. */
580         assert(get_irg_phase_state(get_irn_irg(node)) != phase_building);
581
582         node->link = link;
583 }
584
585 /**
586  * Returns the link of a node.
587  * Intern version of libFirm.
588  */
589 static INLINE void *
590 _get_irn_link(const ir_node *node) {
591         assert(node && _is_ir_node(node));
592         return node->link;
593 }
594
595 /**
596  * Returns whether the node _always_ must be pinned.
597  * I.e., the node is not floating after global cse.
598  *
599  * Intern version of libFirm.
600  */
601 static INLINE op_pin_state
602 _get_irn_pinned(const ir_node *node) {
603         op_pin_state state;
604         assert(node && _is_ir_node(node));
605         /* Check opcode */
606         state = _get_op_pinned(_get_irn_op(node));
607
608         if (state >= op_pin_state_exc_pinned)
609                 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
610         return state;
611 }
612
613 static INLINE op_pin_state
614 _is_irn_pinned_in_irg(const ir_node *node) {
615         if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
616                 return get_irn_pinned(node);
617         return op_pin_state_pinned;
618 }
619
620 static INLINE int
621 _is_unop(const ir_node *node) {
622         assert(node && _is_ir_node(node));
623         return (node->op->opar == oparity_unary);
624 }
625
626 static INLINE int
627 _is_binop(const ir_node *node) {
628         assert(node && _is_ir_node(node));
629         return (node->op->opar == oparity_binary);
630 }
631
632 static INLINE int
633 _is_Bad(const ir_node *node) {
634         assert(node);
635         return (_get_irn_op(node) == op_Bad);
636 }
637
638 static INLINE int
639 _is_NoMem(const ir_node *node) {
640         assert(node);
641         return (_get_irn_op(node) == op_NoMem);
642 }
643
644 static INLINE int
645 _is_Mod(const ir_node *node) {
646         assert(node);
647         return (_get_irn_op(node) == op_Mod);
648 }
649
650 static INLINE int
651 _is_Div(const ir_node *node) {
652         assert(node);
653         return (_get_irn_op(node) == op_Div);
654 }
655
656 static INLINE int
657 _is_DivMod(const ir_node *node) {
658         assert(node);
659         return (_get_irn_op(node) == op_DivMod);
660 }
661
662 static INLINE int
663 _is_Quot(const ir_node *node) {
664         assert(node);
665         return (_get_irn_op(node) == op_Quot);
666 }
667
668 static INLINE int
669 _is_Start(const ir_node *node) {
670         assert(node);
671         return (_get_irn_op(node) == op_Start);
672 }
673
674 static INLINE int
675 _is_End(const ir_node *node) {
676         assert(node);
677         return (_get_irn_op(node) == op_End);
678 }
679
680 static INLINE int
681 _is_Const(const ir_node *node) {
682         assert(node);
683         return (_get_irn_op(node) == op_Const);
684 }
685
686 static INLINE int
687 _is_CopyB(const ir_node *node) {
688         assert(node);
689         return (_get_irn_op(node) == op_CopyB);
690 }
691
692 static INLINE int
693 _is_Unknown(const ir_node *node) {
694         assert(node);
695         return (_get_irn_op(node) == op_Unknown);
696 }
697
698 static INLINE int
699 _is_Return(const ir_node *node) {
700         assert(node);
701         return (_get_irn_op(node) == op_Return);
702 }
703
704 static INLINE int
705 _is_Call(const ir_node *node) {
706         assert(node);
707         return (_get_irn_op(node) == op_Call);
708 }
709
710 static INLINE int
711 _is_Sel(const ir_node *node) {
712         assert(node);
713         return (_get_irn_op(node) == op_Sel);
714 }
715
716 static INLINE int
717 _is_Mux(const ir_node *node) {
718         assert(node);
719         if (node) {
720                 ir_op *op = _get_irn_op(node);
721                 return (op == op_Mux || ((op == op_Psi) && _get_irn_arity(node) == 3));
722         }
723         return 0;
724 }
725
726 static INLINE int
727 _is_Load(const ir_node *node) {
728         assert(node);
729         return (_get_irn_op(node) == op_Load);
730 }
731
732 static INLINE int
733 _is_Store(const ir_node *node) {
734         assert(node);
735         return (_get_irn_op(node) == op_Store);
736 }
737
738 static INLINE int
739 _is_Sync(const ir_node *node) {
740         assert(node);
741         return (_get_irn_op(node) == op_Sync);
742 }
743
744 static INLINE int
745 _is_Confirm(const ir_node *node) {
746         assert(node);
747         return (_get_irn_op(node) == op_Confirm);
748 }
749
750 static INLINE int
751 _is_Pin(const ir_node *node) {
752         assert(node);
753         return (_get_irn_op(node) == op_Pin);
754 }
755
756 static INLINE int
757 _is_SymConst(const ir_node *node) {
758         assert(node);
759         return (_get_irn_op(node) == op_SymConst);
760 }
761
762 static INLINE int
763 _is_Cond(const ir_node *node) {
764         assert(node);
765         return (_get_irn_op(node) == op_Cond);
766 }
767
768 static INLINE int
769 _is_Cmp(const ir_node *node) {
770         assert(node);
771         return (_get_irn_op(node) == op_Cmp);
772 }
773
774 static INLINE int
775 _is_Alloc(const ir_node *node) {
776         assert(node);
777         return (_get_irn_op(node) == op_Alloc);
778 }
779
780 static INLINE int
781 _is_Jmp(const ir_node *node) {
782         assert(node);
783         return (_get_irn_op(node) == op_Jmp);
784 }
785
786 static INLINE int
787 _is_Raise(const ir_node *node) {
788         assert(node);
789         return (_get_irn_op(node) == op_Raise);
790 }
791
792 static INLINE int
793 _is_no_Block(const ir_node *node) {
794         assert(node && _is_ir_node(node));
795         return (_get_irn_op(node) != op_Block);
796 }
797
798 static INLINE int
799 _is_Block(const ir_node *node) {
800         assert(node && _is_ir_node(node));
801         return (_get_irn_op(node) == op_Block);
802 }
803
804 static INLINE int
805 _get_Block_n_cfgpreds(const ir_node *node) {
806         assert(_is_Block(node));
807         return _get_irn_arity(node);
808 }
809
810 static INLINE ir_node *
811 _get_Block_cfgpred(ir_node *node, int pos) {
812         assert(0 <= pos && pos < get_irn_arity(node));
813         assert(_is_Block(node));
814         return _get_irn_n(node, pos);
815 }
816
817 /* Get the predecessor block.
818  *
819  *  Returns the block corresponding to the predecessor pos.
820  *
821  *  There are several ambiguities we resolve with this function:
822  *  - The direct predecessor can be a Proj, which is not pinned.
823  *    We walk from the predecessor to the next pinned node
824  *    (skip_Proj) and return the block that node is in.
825  *  - If we encounter the Bad node, this function does not return
826  *    Start, but the Bad node.
827  */
828 static INLINE ir_node  *
829 _get_Block_cfgpred_block(ir_node *node, int pos) {
830         ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
831         if (!is_Bad(res))
832                 res = get_nodes_block(res);
833         return res;
834 }
835
836 static INLINE unsigned long
837 _get_Block_block_visited(const ir_node *node) {
838         assert(node->op == op_Block);
839         return node->attr.block.block_visited;
840 }
841
842 static INLINE void
843 _set_Block_block_visited(ir_node *node, unsigned long visit) {
844         assert(node->op == op_Block);
845         node->attr.block.block_visited = visit;
846 }
847
848 /* For this current_ir_graph must be set. */
849 static INLINE void
850 _mark_Block_block_visited(ir_node *node) {
851         assert(node->op == op_Block);
852         node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
853 }
854
855 static INLINE int
856 _Block_not_block_visited(const ir_node *node) {
857         assert(node->op == op_Block);
858         return (node->attr.block.block_visited < get_irg_block_visited(current_ir_graph));
859 }
860
861 static INLINE int
862 _Block_block_visited(const ir_node *node) {
863         assert(node->op == op_Block);
864         return (node->attr.block.block_visited >= get_irg_block_visited(current_ir_graph));
865 }
866
867 static INLINE ir_node *
868 _set_Block_dead(ir_node *block) {
869         assert(_get_irn_op(block) == op_Block);
870         block->attr.block.dead = 1;
871         return block;
872 }
873
874 static INLINE int
875 _is_Block_dead(const ir_node *block) {
876         ir_op *op = _get_irn_op(block);
877
878         if (op == op_Bad)
879                 return 1;
880         else {
881                 assert(op == op_Block);
882                 return block->attr.block.dead;
883         }
884 }
885
886 static INLINE tarval *_get_Const_tarval(ir_node *node) {
887         assert(_get_irn_op(node) == op_Const);
888         return node->attr.con.tv;
889 }
890
891 static INLINE cnst_classify_t _classify_Const(ir_node *node) {
892         ir_op *op;
893         assert(_is_ir_node(node));
894
895         op = _get_irn_op(node);
896
897         if (op == op_Const)
898                 return classify_tarval(_get_Const_tarval(node));
899         else if(op == op_SymConst)
900                 return CNST_SYMCONST;
901
902         return CNST_NO_CONST;
903 }
904
905 static INLINE int _is_irn_forking(const ir_node *node) {
906         return is_op_forking(_get_irn_op(node));
907 }
908
909 static INLINE ir_type *_get_irn_type(ir_node *node) {
910         return _get_irn_op(node)->ops.get_type(node);
911 }
912
913 static INLINE ir_type *_get_irn_type_attr(ir_node *node) {
914         return _get_irn_op(node)->ops.get_type_attr(node);
915 }
916
917 static INLINE ir_entity *_get_irn_entity_attr(ir_node *node) {
918   return _get_irn_op(node)->ops.get_entity_attr(node);
919 }
920
921 static INLINE int _is_irn_constlike(const ir_node *node) {
922         return is_op_constlike(_get_irn_op(node));
923 }
924
925 static INLINE int _is_irn_always_opt(const ir_node *node) {
926         return is_op_always_opt(_get_irn_op(node));
927 }
928
929 static INLINE int _is_irn_keep(const ir_node *node) {
930         return is_op_keep(_get_irn_op(node));
931 }
932
933 static INLINE int _is_irn_start_block_placed(const ir_node *node) {
934         return is_op_start_block_placed(_get_irn_op(node));
935 }
936
937 static INLINE int _is_irn_machine_op(const ir_node *node) {
938         return is_op_machine(_get_irn_op(node));
939 }
940
941 static INLINE int _is_irn_machine_operand(const ir_node *node) {
942         return is_op_machine_operand(_get_irn_op(node));
943 }
944
945 static INLINE int _is_irn_machine_user(const ir_node *node, unsigned n) {
946         return is_op_machine_user(_get_irn_op(node), n);
947 }
948
949 static INLINE cond_jmp_predicate _get_Cond_jmp_pred(ir_node *node) {
950         assert(_get_irn_op(node) == op_Cond);
951         return node->attr.cond.pred;
952 }
953
954 static INLINE void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
955         assert(_get_irn_op(node) == op_Cond);
956         node->attr.cond.pred = pred;
957 }
958
959 static INLINE int _get_Psi_n_conds(ir_node *node) {
960         assert(_get_irn_op(node) == op_Psi);
961         return _get_irn_arity(node) >> 1;
962 }
963
964 static INLINE unsigned _get_irn_idx(const ir_node *node) {
965         return node->node_idx;
966 }
967
968 /* this section MUST contain all inline functions */
969 #define is_ir_node(thing)                     _is_ir_node(thing)
970 #define get_irn_intra_arity(node)             _get_irn_intra_arity(node)
971 #define get_irn_inter_arity(node)             _get_irn_inter_arity(node)
972 #define get_irn_arity(node)                   _get_irn_arity(node)
973 #define get_irn_intra_n(node, n)              _get_irn_intra_n(node, n)
974 #define get_irn_inter_n(node, n)              _get_irn_inter_n(node, n)
975 #define get_irn_n(node, n)                    _get_irn_n(node, n)
976 #define get_irn_mode(node)                    _get_irn_mode(node)
977 #define set_irn_mode(node, mode)              _set_irn_mode(node, mode)
978 #define get_irn_op(node)                      _get_irn_op(node)
979 #define set_irn_op(node, op)                  _set_irn_op(node, op)
980 #define get_irn_opcode(node)                  _get_irn_opcode(node)
981 #define get_irn_visited(node)                 _get_irn_visited(node)
982 #define set_irn_visited(node, v)              _set_irn_visited(node, v)
983 #define mark_irn_visited(node)                _mark_irn_visited(node)
984 #define irn_visited(node)                     _irn_visited(node)
985 #define irn_not_visited(node)                 _irn_not_visited(node)
986 #define set_irn_link(node, link)              _set_irn_link(node, link)
987 #define get_irn_link(node)                    _get_irn_link(node)
988 #define get_irn_pinned(node)                  _get_irn_pinned(node)
989 #define is_irn_pinned_in_irg(node)            _is_irn_pinned_in_irg(node)
990 #define is_unop(node)                         _is_unop(node)
991 #define is_binop(node)                        _is_binop(node)
992 #define is_Const(node)                        _is_Const(node)
993 #define is_Unknown(node)                      _is_Unknown(node)
994 #define is_Return(node)                       _is_Return(node)
995 #define is_Call(node)                         _is_Call(node)
996 #define is_Sel(node)                          _is_Sel(node)
997 #define is_Mux(node)                          _is_Mux(node)
998 #define is_Load(node)                         _is_Load(node)
999 #define is_Sync(node)                         _is_Sync(node)
1000 #define is_Confirm(node)                      _is_Confirm(node)
1001 #define is_Pin(node)                          _is_Pin(node)
1002 #define is_SymConst(node)                     _is_SymConst(node)
1003 #define is_Cond(node)                         _is_Cond(node)
1004 #define is_CopyB(node)                        _is_CopyB(node)
1005 #define is_Cmp(node)                          _is_Cmp(node)
1006 #define is_Alloc(node)                        _is_Alloc(node)
1007 #define is_Jmp(node)                          _is_Jmp(node)
1008 #define is_Raise(node)                        _is_Raise(node)
1009 #define is_Bad(node)                          _is_Bad(node)
1010 #define is_NoMem(node)                        _is_NoMem(node)
1011 #define is_Start(node)                        _is_Start(node)
1012 #define is_End(node)                          _is_End(node)
1013 #define is_Mod(node)                          _is_Mod(node)
1014 #define is_Div(node)                          _is_Div(node)
1015 #define is_DivMod(node)                       _is_DivMod(node)
1016 #define is_Quot(node)                         _is_Quot(node)
1017 #define is_no_Block(node)                     _is_no_Block(node)
1018 #define is_Block(node)                        _is_Block(node)
1019 #define get_Block_n_cfgpreds(node)            _get_Block_n_cfgpreds(node)
1020 #define get_Block_cfgpred(node, pos)          _get_Block_cfgpred(node, pos)
1021 #define get_Block_cfgpred_block(node, pos)    _get_Block_cfgpred_block(node, pos)
1022 #define get_Block_block_visited(node)         _get_Block_block_visited(node)
1023 #define set_Block_block_visited(node, visit)  _set_Block_block_visited(node, visit)
1024 #define mark_Block_block_visited(node)        _mark_Block_block_visited(node)
1025 #define Block_not_block_visited(node)         _Block_not_block_visited(node)
1026 #define Block_block_visited(node)             _Block_block_visited(node)
1027 #define set_Block_dead(block)                 _set_Block_dead(block)
1028 #define is_Block_dead(block)                  _is_Block_dead(block)
1029 #define get_Const_tarval(node)                _get_Const_tarval(node)
1030 #define classify_Const(node)                  _classify_Const(node)
1031 #define is_irn_forking(node)                  _is_irn_forking(node)
1032 #define get_irn_type(node)                    _get_irn_type(node)
1033 #define get_irn_type_attr(node)               _get_irn_type_attr(node)
1034 #define get_irn_entity_attr(node)             _get_irn_entity_attr(node)
1035 #define is_irn_constlike(node)                _is_irn_constlike(node)
1036 #define is_irn_always_opt(node)               _is_irn_always_opt(node)
1037 #define is_irn_keep(node)                     _is_irn_keep(node)
1038 #define is_irn_start_block_placed(node)       _is_irn_start_block_placed(node)
1039 #define is_irn_machine_op(node)               _is_irn_machine_op(node)
1040 #define is_irn_machine_operand(node)          _is_irn_machine_operand(node)
1041 #define is_irn_machine_user(node, n)          _is_irn_machine_user(node, n)
1042 #define get_Cond_jmp_pred(node)               _get_Cond_jmp_pred(node)
1043 #define set_Cond_jmp_pred(node, pred)         _set_Cond_jmp_pred(node, pred)
1044 #define get_Psi_n_conds(node)                 _get_Psi_n_conds(node)
1045 #define get_irn_idx(node)                     _get_irn_idx(node)
1046
1047 #define get_irn_deps(node)                    _get_irn_deps(node)
1048 #define set_irn_dep(node, pos, dep)           _set_irn_dep(node, pos, dep)
1049 #define get_irn_dep(node, pos)                _get_irn_dep(node, pos)
1050
1051 #define get_irn_ins_or_deps(node)             _get_irn_ins_or_deps(node)
1052 #define get_irn_in_or_dep(node, pos)          _get_irn_in_or_dep(node, pos)
1053
1054 #endif /* _FIRM_IRNODE_T_H_ */