removed INLIEN before global functions
[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
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
21 # ifndef _IRNODE_T_H_
22 # define _IRNODE_T_H_
23
24 #include "firm_config.h"
25 #include "irnode.h"
26 #include "irop_t.h"
27 #include "irgraph_t.h"
28 #include "irflag_t.h"
29 #include "firm_common_t.h"
30 #include "irdom_t.h" /* For size of struct dom_info. */
31 #include "dbginfo.h"
32 #include "irloop.h"
33 #include "array.h"
34
35 #include "set.h"
36 #include "entity_t.h"
37 #include "type_t.h"
38
39
40 /** ir node attributes **/
41
42 /** Block attributes */
43 typedef struct {
44   /* General attributes */
45   ir_graph *irg;
46   unsigned long block_visited;  /**< for the walker that walks over all blocks. */
47   /* Attributes private to construction: */
48   int matured:1;                /**< if set, all in-nodes of the block are fixed */
49   int dead:1;                   /**< if set, the block is dead (and could be replace by a Bad */
50   struct ir_node **graph_arr; /**< array to store all parameters */
51   /* Attributes holding analyses information */
52   struct dom_info dom;        /**< Datastructure that holds information about dominators.
53                  @@@ @todo
54                  Eventually overlay with graph_arr as only valid
55                  in different phases.  Eventually inline the whole
56                  datastructure. */
57   /*   exc_t exc;  */            /**< role of this block for exception handling */
58   /*   ir_node *handler_entry; */    /**< handler entry block iff this block is part of a region */
59   ir_node ** in_cg;           /**< array with predecessors in
60                    * interprocedural_view, if they differ
61                    * from intraprocedural predecessors */
62   int *backedge;              /**< Field n set to true if pred n is backedge.
63                      @@@ @todo Ev. replace by bitfield! */
64   int *cg_backedge;           /**< Field n set to true if pred n is interprocedural backedge.
65                      @@@ @todo Ev. replace by bitfield! */
66 } block_attr;
67
68 /** Start attributes */
69 typedef struct {
70   char dummy;
71   /*   ir_graph *irg;   @@@ now in block */
72 } start_attr;
73
74 /** Cond attributes */
75 typedef struct {
76   cond_kind kind;    /**< flavor of Cond */
77   long default_proj; /**< for optimization: biggest Proj number, i.e. the one
78                           used for default. */
79 } cond_attr;
80
81 /** Const attributes */
82 typedef struct {
83   tarval *tv;        /**< the target value */
84   type   *tp;        /**< the source type, for analyses. default: type_unknown. */
85 } const_attr;
86
87 typedef struct {
88   symconst_symbol sym;  // old tori
89   symconst_kind num;
90   type *tp;          /**< the source type, for analyses. default: type_unknown. */
91 } symconst_attr;
92
93 /** Sel attributes */
94 typedef struct {
95   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 typedef struct {
109   except_attr    exc;           /**< the exception attribute. MUST be the first one. */
110   type *cld_tp;                 /**< type of called procedure */
111   entity ** callee_arr;         /**< result of callee analysis */
112 } call_attr;
113
114 /** Alloc attributes */
115 typedef struct {
116   except_attr    exc;           /**< the exception attribute. MUST be the first one. */
117   type *type;                   /**< Type of the allocated object.  */
118   where_alloc where;            /**< stack, heap or other managed part of memory */
119 } alloc_attr;
120
121 /** InstOf attributes */
122 typedef struct
123 {
124   type *ent;
125   int dfn;
126 } io_attr;
127
128 /** Filter attributes */
129 typedef struct {
130   long proj;                 /**< contains the result position to project (Proj) */
131   ir_node ** in_cg;          /**< array with interprocedural predecessors (Phi) */
132   int *backedge;              /**< Field n set to true if pred n is backedge.
133                      @todo Ev. replace by bitfield! */
134 } filter_attr;
135
136 /** EndReg/EndExcept attributes */
137 typedef struct {
138   char dummy;
139   /*   ir_graph * irg; */           /**< ir_graph this node belongs to (for */
140   /*                               * navigating in interprocedural graphs)  */
141   /*                       @@@ now in block */
142 } end_attr;
143
144 /** CallBegin attributes */
145 typedef struct {
146   /*   ir_graph * irg; */           /**< ir_graph this node belongs to (for */
147   /*                   * navigating in interprocedural graphs) */
148   /*                            @@@ now in block */
149   ir_node * call;            /**< associated Call-operation */
150 } callbegin_attr;
151
152 /** Cast attributes */
153 typedef struct {
154   type *totype;
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   ent_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   ent_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 /** Some irnodes just have one attribute, these are stored here,
173    some have more. Their name is 'irnodename_attr' */
174 typedef union {
175   start_attr     start; /**< For Start */
176   block_attr     block; /**< For Block: Fields needed to construct it */
177   cond_attr      c;     /**< For Cond. */
178   const_attr     con;   /**< For Const: contains the value of the constant and a type */
179   symconst_attr  i;     /**< For SymConst. */
180   sel_attr       s;     /**< For Sel. */
181   call_attr      call;  /**< For Call: pointer to the type of the method to call */
182   callbegin_attr callbegin; /**< For CallBegin */
183   alloc_attr     a;     /**< For Alloc. */
184   io_attr        io;    /**< For InstOf */
185   type          *f;     /**< For Free. */
186   cast_attr      cast;  /**< For Cast. */
187   load_attr      load;  /**< For Load. */
188   store_attr     store;  /**< For Store. */
189   int            phi0_pos;  /**< For Phi. Used to remember the value defined by
190                    this Phi node.  Needed when the Phi is completed
191                    to call get_r_internal_value to find the
192                    predecessors. If this attribute is set, the Phi
193                    node takes the role of the obsolete Phi0 node,
194                    therefore the name. */
195   int *phi_backedge;    /**< For Phi after construction.
196                Field n set to true if pred n is backedge.
197                @todo Ev. replace by bitfield! */
198   long           proj;  /**< For Proj: contains the result position to project */
199   confirm_attr   confirm_cmp;   /**< For Confirm: compare operation */
200   filter_attr    filter;    /**< For Filter */
201   end_attr       end;       /**< For EndReg, EndExcept */
202   except_attr    except; /**< For Phi node construction in case of exceptions */
203 } attr;
204
205
206 /** common structure of an irnode
207     if the node has some attributes, they are stored in attr */
208 struct ir_node {
209   /* ------- Basics of the representation  ------- */
210   firm_kind kind;          /**< distinguishes this node from others */
211   ir_op *op;               /**< Opcode of this node. */
212   ir_mode *mode;           /**< Mode of this node. */
213   unsigned long visited;   /**< visited counter for walks of the graph */
214   struct ir_node **in;     /**< array with predecessors / operands */
215   void *link;              /**< to attach additional information to the node, e.g.
216                               used while construction to link Phi0 nodes and
217                               during optimization to link to nodes that
218                               shall replace a node. */
219   /* ------- Fields for optimizations / analysis information ------- */
220   struct ir_node **out;    /**< array of out edges */
221   struct dbg_info* dbi;    /**< A pointer to information for debug support. */
222   /* ------- For debugging ------- */
223 #ifdef DEBUG_libfirm
224   int out_valid;           /** < indicate that out edges are valid */
225   int node_nr;             /**< a unique node number for each node to make output
226                               readable. */
227 #endif
228   /* ------- For analyses -------- */
229   ir_loop *loop;           /**< the loop the node is in. Access routines in irloop.h */
230 #ifdef  DO_HEAPANALYSIS
231   struct abstval *av;
232   struct section *sec;
233 #endif
234   /* ------- Opcode depending fields -------- */
235   attr attr;               /**< attribute of this node. Depends on opcode.
236                               Must be last field of struct ir_node. */
237 };
238
239
240 /** Returns the array with the ins.  The content of the array may not be
241    changed.  */
242 ir_node     **get_irn_in            (const ir_node *node);
243
244 /** @{ */
245 /** access attributes directly */
246 const_attr    get_irn_const_attr    (ir_node *node);
247 long          get_irn_proj_attr     (ir_node *node);
248 alloc_attr    get_irn_alloc_attr    (ir_node *node);
249 type         *get_irn_free_attr     (ir_node *node);
250 symconst_attr get_irn_symconst_attr (ir_node *node);
251 type         *get_irn_call_attr     (ir_node *node);
252 type         *get_irn_funccall_attr (ir_node *node);
253 sel_attr      get_irn_sel_attr      (ir_node *node);
254 int           get_irn_phi_attr      (ir_node *node);
255 block_attr    get_irn_block_attr    (ir_node *node);
256 load_attr     get_irn_load_attr     (ir_node *node);
257 store_attr    get_irn_store_attr    (ir_node *node);
258 except_attr   get_irn_except_attr   (ir_node *node);
259 /** @} */
260
261 /*
262  * The amount of additional space for custom data to be allocated upon creating a new node.
263  */
264 extern unsigned firm_add_node_size;
265
266 /*-------------------------------------------------------------------*/
267 /*  These function are most used in libfirm.  Give them as static    */
268 /*  functions so they can be inlined.                                */
269 /*-------------------------------------------------------------------*/
270
271 /**
272  * Checks whether a pointer points to a ir node.
273  * Intern version for libFirm.
274  */
275 static INLINE int
276 __is_ir_node (const void *thing) {
277   return (get_kind(thing) == k_ir_node);
278 }
279
280 /**
281  * Gets the op of a node.
282  * Intern version for libFirm.
283  */
284 static INLINE ir_op *
285 __get_irn_op (const ir_node *node) {
286   assert (node);
287   return node->op;
288 }
289
290 /** Copies all attributes stored in the old node  to the new node.
291     Assumes both have the same opcode and sufficient size. */
292 static INLINE void
293 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
294   ir_op *op = __get_irn_op(old_node);
295
296   /* must always exist */
297   op->copy_attr(old_node, new_node);
298 }
299
300 /**
301  * Gets the opcode of a node.
302  * Intern version for libFirm.
303  */
304 static INLINE opcode
305 __get_irn_opcode (const ir_node *node) {
306   assert (k_ir_node == get_kind(node));
307   assert (node -> op);
308   return node->op->code;
309 }
310
311 /**
312  * Returns the number of predecessors without the block predecessor.
313  * Intern version for libFirm.
314  */
315 static INLINE int
316 __get_irn_intra_arity (const ir_node *node) {
317   assert(node);
318   return ARR_LEN(node->in) - 1;
319 }
320
321 /**
322  * Returns the number of predecessors without the block predecessor.
323  * Intern version for libFirm.
324  */
325 static INLINE int
326 __get_irn_inter_arity (const ir_node *node) {
327   assert(node);
328   if (__get_irn_opcode(node) == iro_Filter) {
329     assert(node->attr.filter.in_cg);
330     return ARR_LEN(node->attr.filter.in_cg) - 1;
331   } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
332     return ARR_LEN(node->attr.block.in_cg) - 1;
333   }
334   return __get_irn_intra_arity(node);
335 }
336
337 /**
338  * Returns the number of predecessors without the block predecessor.
339  * Intern version for libFirm.
340  */
341 extern int (*__get_irn_arity)(const ir_node *node);
342
343 /**
344  * Intern version for libFirm.
345  */
346 static INLINE ir_node *
347 __get_irn_intra_n (const ir_node *node, int n) {
348   assert(node); assert(-1 <= n && n < __get_irn_intra_arity(node));
349
350   return (node->in[n + 1] = skip_Id(node->in[n + 1]));
351 }
352
353 /**
354  * Intern version for libFirm.
355  */
356 static INLINE ir_node*
357 __get_irn_inter_n (const ir_node *node, int n) {
358   assert(node); assert(-1 <= n && n < __get_irn_inter_arity(node));
359
360   /* handle Filter and Block specially */
361   if (__get_irn_opcode(node) == iro_Filter) {
362     assert(node->attr.filter.in_cg);
363     return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
364   } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
365     return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
366   }
367
368   return __get_irn_intra_n (node, n);
369 }
370
371 /**
372  * Access to the predecessors of a node.
373  * To iterate over the operands iterate from 0 to i < get_irn_arity(),
374  * to iterate including the Block predecessor iterate from i = -1 to
375  * i < get_irn_arity.
376  * If it is a block, the entry -1 is NULL.
377  * Intern version for libFirm.
378  */
379 extern ir_node *(*__get_irn_n)(const ir_node *node, int n);
380
381 /**
382  * Gets the mode of a node.
383  * Intern version for libFirm.
384  */
385 static INLINE ir_mode *
386 __get_irn_mode (const ir_node *node)
387 {
388   assert (node);
389   return node->mode;
390 }
391
392 /**
393  * Sets the mode of a node.
394  * Intern version of libFirm.
395  */
396 static INLINE void
397 __set_irn_mode (ir_node *node, ir_mode *mode)
398 {
399   assert (node);
400   node->mode = mode;
401 }
402
403 /**
404  * Gets the visited counter of a node.
405  * Intern version for libFirm.
406  */
407 static INLINE unsigned long
408 __get_irn_visited (const ir_node *node)
409 {
410   assert (node);
411   return node->visited;
412 }
413
414 /**
415  * Sets the visited counter of a node.
416  * Intern version for libFirm.
417  */
418 static INLINE void
419 __set_irn_visited (ir_node *node, unsigned long visited)
420 {
421   assert (node);
422   node->visited = visited;
423 }
424
425 /**
426  * Mark a node as visited in a graph.
427  * Intern version for libFirm.
428  */
429 static INLINE void
430 __mark_irn_visited (ir_node *node) {
431   assert (node);
432   node->visited = current_ir_graph->visited;
433 }
434
435 /**
436  * Returns non-zero if a node of was visited.
437  * Intern version for libFirm.
438  */
439 static INLINE int
440 __irn_visited(const ir_node *node) {
441   assert (node);
442   return (node->visited >= current_ir_graph->visited);
443 }
444
445 /**
446  * Returns non-zero if a node of was NOT visited.
447  * Intern version for libFirm.
448  */
449 static INLINE int
450 __irn_not_visited(const ir_node *node) {
451   assert (node);
452   return (node->visited < current_ir_graph->visited);
453 }
454
455 /**
456  * Sets the link of a node.
457  * Intern version of libFirm.
458  */
459 static INLINE void
460 __set_irn_link(ir_node *node, void *link) {
461   assert (node);
462   /* Link field is used for Phi construction and various optimizations
463      in iropt. */
464   assert(get_irg_phase_state(current_ir_graph) != phase_building);
465
466   node->link = link;
467 }
468
469 /**
470  * Returns the link of a node.
471  * Intern version of libFirm.
472  */
473 static INLINE void *
474 __get_irn_link(const ir_node *node) {
475   assert (node);
476   return node->link;
477 }
478
479 /**
480  * Returns the pinned state of a node.
481  * Intern version of libFirm.
482  */
483 static INLINE op_pin_state
484 __get_irn_pinned(const ir_node *node) {
485   op_pin_state state = __get_op_pinned(__get_irn_op(node));
486   if (state >= op_pin_state_exc_pinned)
487     return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
488   return state;
489 }
490
491 static INLINE int
492 __is_unop(const ir_node *node) {
493   return (node->op->opar == oparity_unary);
494 }
495
496 static INLINE int
497 __is_binop(const ir_node *node) {
498   return (node->op->opar == oparity_binary);
499 }
500
501 static INLINE int
502 __is_Bad(const ir_node *node) {
503   assert(node);
504   return (node && __get_irn_op(node) == op_Bad);
505 }
506
507 static INLINE int
508 __is_no_Block(const ir_node *node) {
509   assert(node);
510   return (__get_irn_op(node) != op_Block);
511 }
512
513 static INLINE int
514 __is_Block(const ir_node *node) {
515   assert(node);
516   return (__get_irn_op(node) == op_Block);
517 }
518
519 static INLINE ir_node *
520 __set_Block_dead(ir_node *block) {
521   assert(__get_irn_op(block) == op_Block);
522   block->attr.block.dead = 1;
523   return block;
524 }
525
526 static INLINE int
527 __is_Block_dead(const ir_node *block) {
528   ir_op * op = __get_irn_op(block);
529
530   if (op == op_Bad)
531     return 1;
532   else {
533     assert(op == op_Block);
534     return block->attr.block.dead;
535   }
536 }
537
538 /* this section MUST contain all inline functions */
539 #define is_ir_node(thing)          __is_ir_node(thing)
540 #define get_irn_intra_arity(node)  __get_irn_intra_arity(node)
541 #define get_irn_inter_arity(node)  __get_irn_inter_arity(node)
542 #define get_irn_arity(node)        __get_irn_arity(node)
543 #define get_irn_intra_n(node, n)   __get_irn_intra_n(node, n)
544 #define get_irn_inter_n(node, n)   __get_irn_inter_n(node, n)
545 #define get_irn_n(node, n)         __get_irn_n(node, n)
546 #define get_irn_mode(node)         __get_irn_mode(node)
547 #define set_irn_mode(node, mode)   __set_irn_mode(node, mode)
548 #define get_irn_op(node)           __get_irn_op(node)
549 #define get_irn_opcode(node)       __get_irn_opcode(node)
550 #define get_irn_visited(node)      __get_irn_visited(node)
551 #define set_irn_visited(node, v)   __set_irn_visited(node, v)
552 #define mark_irn_visited(node)     __mark_irn_visited(node)
553 #define irn_visited(node)          __irn_visited(node)
554 #define irn_not_visited(node)      __irn_not_visited(node)
555 #define set_irn_link(node, link)   __set_irn_link(node, link)
556 #define get_irn_link(node)         __get_irn_link(node)
557 #define is_unop(node)              __is_unop(node)
558 #define is_binop(node)             __is_binop(node)
559 #define is_Bad(node)               __is_Bad(node)
560 #define is_no_Block(node)          __is_no_Block(node)
561 #define is_Block(node)             __is_Block(node)
562 #define set_Block_dead(block)      __set_Block_dead(block)
563 #define is_Block_dead(block)       __is_Block_dead(block)
564
565 # endif /* _IRNODE_T_H_ */