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