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