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