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