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