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