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