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