Bad and Unknown are pinned instructions yet, speeding up code placement
[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 typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */
157
158 /** Some irnodes just have one attribute, these are stored here,
159    some have more. Their name is 'irnodename_attr' */
160 typedef union {
161   start_attr     start; /**< For Start */
162   block_attr     block; /**< For Block: Fields needed to construct it */
163   cond_attr      c;     /**< For Cond. */
164   const_attr     con;   /**< For Const: contains the value of the constant and a type */
165   symconst_attr  i;     /**< For SymConst. */
166   sel_attr       s;     /**< For Sel. */
167   call_attr      call;  /**< For Call: pointer to the type of the method to call */
168   callbegin_attr callbegin; /**< For CallBegin */
169   alloc_attr     a;     /**< For Alloc. */
170   io_attr        io;    /**< For InstOf */
171   type          *f;     /**< For Free. */
172   cast_attr      cast;  /**< For Cast. */
173   int            phi0_pos;  /**< For Phi. Used to remember the value defined by
174                    this Phi node.  Needed when the Phi is completed
175                    to call get_r_internal_value to find the
176                    predecessors. If this attribute is set, the Phi
177                    node takes the role of the obsolete Phi0 node,
178                    therefore the name. */
179   int *phi_backedge;    /**< For Phi after construction.
180                Field n set to true if pred n is backedge.
181                @todo Ev. replace by bitfield! */
182   long           proj;  /**< For Proj: contains the result position to project */
183   confirm_attr   confirm_cmp;   /**< For Confirm: compare operation */
184   filter_attr    filter;    /**< For Filter */
185   end_attr       end;       /**< For EndReg, EndExcept */
186 #if PRECISE_EXC_CONTEXT
187   struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions
188                 for nodes Store, Load, Div, Mod, Quot, DivMod. */
189 #endif
190 } attr;
191
192
193 /** common structure of an irnode
194     if the node has some attributes, they are stored in attr */
195 struct ir_node {
196   /* ------- Basics of the representation  ------- */
197   firm_kind kind;          /**< distinguishes this node from others */
198   ir_op *op;               /**< Opcode of this node. */
199   ir_mode *mode;           /**< Mode of this node. */
200   unsigned long visited;   /**< visited counter for walks of the graph */
201   struct ir_node **in;     /**< array with predecessors / operands */
202   void *link;              /**< to attach additional information to the node, e.g.
203                               used while construction to link Phi0 nodes and
204                   during optimization to link to nodes that
205                   shall replace a node. */
206   /* ------- Fields for optimizations / analysis information ------- */
207   struct ir_node **out;    /**< array of out edges */
208   struct dbg_info* dbi;    /**< A pointer to information for debug support. */
209   /* ------- For debugging ------- */
210 #ifdef DEBUG_libfirm
211   int out_valid;                /** < indicate that out edges are valid */
212   int node_nr;             /**< a unique node number for each node to make output
213                   readable. */
214 #endif
215   /* ------- For analyses -------- */
216   ir_loop *loop;           /**< the loop the node is in. Access routines in irloop.h */
217 #ifdef  DO_HEAPANALYSIS
218   struct abstval *av;
219   struct section *sec;
220 #endif
221   /* ------- Opcode depending fields -------- */
222   attr attr;               /**< attribute of this node. Depends on opcode.
223                               Must be last field of struct ir_node. */
224 };
225
226 /** Copies all attributes stored in the old node  to the new node.
227     Assumes both have the same opcode and sufficient size. */
228 void
229 copy_attrs(const ir_node *old_node, ir_node *new_node);
230
231
232 /** Returns the array with the ins.  The content of the array may not be
233    changed.  */
234 ir_node     **get_irn_in            (const ir_node *node);
235
236 /** @{ */
237 /** access attributes directly */
238 INLINE const_attr    get_irn_const_attr    (ir_node *node);
239 INLINE long          get_irn_proj_attr     (ir_node *node);
240 INLINE alloc_attr    get_irn_alloc_attr    (ir_node *node);
241 INLINE type         *get_irn_free_attr     (ir_node *node);
242 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
243 type         *get_irn_call_attr     (ir_node *node);
244 type         *get_irn_funccall_attr (ir_node *node);
245 sel_attr      get_irn_sel_attr      (ir_node *node);
246 int           get_irn_phi_attr      (ir_node *node);
247 block_attr    get_irn_block_attr   (ir_node *node);
248 /** @} */
249
250 /*-------------------------------------------------------------------*/
251 /*  These function are most used in libfirm.  Give them as static    */
252 /*  functions so they can be inlined.                                */
253 /*-------------------------------------------------------------------*/
254
255 /**
256  * Checks whether a pointer points to a ir node.
257  * Intern version for libFirm.
258  */
259 static INLINE int
260 __is_ir_node (const void *thing) {
261   return (get_kind(thing) == k_ir_node);
262 }
263
264 /**
265  * Gets the op of a node.
266  * Intern version for libFirm.
267  */
268 static INLINE ir_op *
269 __get_irn_op (const ir_node *node)
270 {
271   assert (node);
272   return node->op;
273 }
274
275 /**
276  * Gets the opcode of a node.
277  * Intern version for libFirm.
278  */
279 static INLINE opcode
280 __get_irn_opcode (const ir_node *node)
281 {
282   assert (k_ir_node == get_kind(node));
283   assert (node -> op);
284   return node->op->code;
285 }
286
287 /**
288  * Returns the number of predecessors without the block predecessor.
289  * Intern version for libFirm.
290  */
291 static INLINE int
292 __get_irn_intra_arity (const ir_node *node) {
293   assert(node);
294   return ARR_LEN(node->in) - 1;
295 }
296
297 /**
298  * Returns the number of predecessors without the block predecessor.
299  * Intern version for libFirm.
300  */
301 static INLINE int
302 __get_irn_inter_arity (const ir_node *node) {
303   assert(node);
304   if (__get_irn_opcode(node) == iro_Filter) {
305     assert(node->attr.filter.in_cg);
306     return ARR_LEN(node->attr.filter.in_cg) - 1;
307   } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
308     return ARR_LEN(node->attr.block.in_cg) - 1;
309   }
310   return __get_irn_intra_arity(node);
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_arity (const ir_node *node) {
319   if (interprocedural_view) return __get_irn_inter_arity(node);
320   return __get_irn_intra_arity(node);
321 }
322
323 /**
324  * Intern version for libFirm.
325  */
326 static INLINE ir_node *
327 __get_irn_intra_n (ir_node *node, int n) {
328   return (node->in[n + 1] = skip_Id(node->in[n + 1]));
329 }
330
331 /**
332  * Intern version for libFirm.
333  */
334 static INLINE ir_node*
335 __get_irn_inter_n (ir_node *node, int n) {
336   /* handle Filter and Block specially */
337   if (__get_irn_opcode(node) == iro_Filter) {
338     assert(node->attr.filter.in_cg);
339     return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
340   } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
341     return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
342   }
343
344   return __get_irn_intra_n (node, n);
345 }
346
347 /**
348  * Access to the predecessors of a node.
349  * To iterate over the operands iterate from 0 to i < get_irn_arity(),
350  * to iterate including the Block predecessor iterate from i = -1 to
351  * i < get_irn_arity.
352  * If it is a block, the entry -1 is NULL.
353  * Intern version for libFirm.
354  */
355 static INLINE ir_node *
356 __get_irn_n (ir_node *node, int n) {
357   assert(node); assert(-1 <= n && n < __get_irn_arity(node));
358   if (interprocedural_view)  return __get_irn_inter_n (node, n);
359   return __get_irn_intra_n (node, n);
360 }
361
362 /**
363  * Gets the mode of a node.
364  * Intern version for libFirm.
365  */
366 static INLINE ir_mode *
367 __get_irn_mode (const ir_node *node)
368 {
369   assert (node);
370   return node->mode;
371 }
372
373 /**
374  * Sets the mode of a node.
375  * Intern version of libFirm.
376  */
377 static INLINE void
378 __set_irn_mode (ir_node *node, ir_mode *mode)
379 {
380   assert (node);
381   node->mode = mode;
382 }
383
384 /**
385  * Gets the visited counter of a node.
386  * Intern version for libFirm.
387  */
388 static INLINE unsigned long
389 __get_irn_visited (const ir_node *node)
390 {
391   assert (node);
392   return node->visited;
393 }
394
395 /**
396  * Sets the visited counter of a node.
397  * Intern version for libFirm.
398  */
399 static INLINE void
400 __set_irn_visited (ir_node *node, unsigned long visited)
401 {
402   assert (node);
403   node->visited = visited;
404 }
405
406 /**
407  * Mark a node as visited in a graph.
408  * Intern version for libFirm.
409  */
410 static INLINE void
411 __mark_irn_visited (ir_node *node) {
412   assert (node);
413   node->visited = current_ir_graph->visited;
414 }
415
416 /**
417  * Returns non-zero if a node of was visited.
418  * Intern version for libFirm.
419  */
420 static INLINE int
421 __irn_visited(const ir_node *node) {
422   assert (node);
423   return (node->visited >= current_ir_graph->visited);
424 }
425
426 /**
427  * Returns non-zero if a node of was NOT visited.
428  * Intern version for libFirm.
429  */
430 static INLINE int
431 __irn_not_visited(const ir_node *node) {
432   assert (node);
433   return (node->visited < current_ir_graph->visited);
434 }
435
436 /**
437  * Sets the link of a node.
438  * Intern version of libFirm.
439  */
440 static INLINE void
441 __set_irn_link(ir_node *node, void *link) {
442   assert (node);
443   /* Link field is used for Phi construction and various optimizations
444      in iropt. */
445   assert(get_irg_phase_state(current_ir_graph) != phase_building);
446
447   node->link = link;
448 }
449
450 /**
451  * Returns the link of a node.
452  * Intern version of libFirm.
453  */
454 static INLINE void *
455 __get_irn_link(const ir_node *node) {
456   assert (node);
457   return node->link;
458 }
459
460 /* this section MUST contain all inline functions */
461 #define is_ir_node(thing)          __is_ir_node(thing)
462 #define get_irn_intra_arity(node)  __get_irn_intra_arity(node)
463 #define get_irn_inter_arity(node)  __get_irn_inter_arity(node)
464 #define get_irn_arity(node)        __get_irn_arity(node)
465 #define get_irn_intra_n(node, n)   __get_irn_intra_n(node, n)
466 #define get_irn_inter_n(node, n)   __get_irn_inter_n(node, n)
467 #define get_irn_n(node, n)         __get_irn_n(node, n)
468 #define get_irn_mode(node)         __get_irn_mode(node)
469 #define set_irn_mode(node, mode)   __set_irn_mode(node, mode)
470 #define get_irn_op(node)           __get_irn_op(node)
471 #define get_irn_opcode(node)       __get_irn_opcode(node)
472 #define get_irn_visited(node)      __get_irn_visited(node)
473 #define set_irn_visited(node, v)   __set_irn_visited(node, v)
474 #define mark_irn_visited(node)     __mark_irn_visited(node)
475 #define irn_visited(node)          __irn_visited(node)
476 #define irn_not_visited(node)      __irn_not_visited(node)
477 #define set_irn_link(node, link)   __set_irn_link(node, link)
478 #define get_irn_link(node)         __get_irn_link(node)
479
480 # endif /* _IRNODE_T_H_ */