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