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