added copyright headers
[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 "firm_common_t.h"
33 # include "irdom_t.h" /* For size of struct dom_info. */
34 # include "dbginfo.h"
35
36 # include "exc.h"
37
38 /** ir node attributes **/
39
40 /** Block attributes */
41 typedef struct {
42   unsigned long block_visited;  /**< for the walker that walks over all blocks. */
43   /* Attributes private to construction: */
44   bool matured;               /**< if set, all in-nodes of the block are fixed */
45   struct ir_node **graph_arr; /**< array to store all parameters */
46   struct dom_info dom;        /**< Datastructure that holds information about dominators.
47                                  @todo
48            Eventually overlay with graph_arr as only valid
49                                    in different phases.  Eventually inline the whole
50                                    datastructure. */
51   exc_t exc;                  /**< role of this block for exception handling */
52   ir_node *handler_entry;     /**< handler entry block iff this block is part of a region */
53   ir_node ** in_cg;           /**< array with predecessors in
54                                * interprocedural_view, if they differ
55                                * from intraprocedural predecessors */
56   int *backedge;              /**< Field n set to true if pred n is backedge.
57                                  @todo Ev. replace by bitfield! */
58   int *cg_backedge;           /**< Field n set to true if pred n is interprocedural backedge.
59                                  @todo Ev. replace by bitfield! */
60 } block_attr;
61
62 /** Start attributes */
63 typedef struct {
64   ir_graph *irg;
65 } start_attr;
66
67 /** Cond attributes */
68 typedef struct {
69   cond_kind kind;    /**< flavor of Cond */
70   long default_proj; /**< for optimization: biggest Proj number, i.e. the one
71                         used for default. */
72 } cond_attr;
73
74 /** SymConst attributes
75     This union contains the symbolic information represented by the node */
76 typedef union type_or_id {
77   type *typ;
78   ident *ptrinfo;
79 } type_or_id;
80
81 typedef struct {
82   type_or_id tori;
83   symconst_kind num;
84 } symconst_attr;
85
86 /** Sel attributes */
87 typedef struct {
88   entity *ent;          /**< entity to select */
89 } sel_attr;
90
91 typedef struct {
92   type *cld_tp;         /**< type of called procedure */
93 #if PRECISE_EXC_CONTEXT
94   struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
95 #endif
96   entity ** callee_arr; /**< result of callee analysis */
97 } call_attr;
98
99 /** Alloc attributes */
100 typedef struct {
101   type *type;           /**< Type of the allocated object.  */
102   where_alloc where;    /**< stack, heap or other managed part of memory */
103 #if PRECISE_EXC_CONTEXT
104   struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
105 #endif
106 } alloc_attr;
107
108 /** InstOf attributes */
109 typedef struct
110 {
111   type *ent;
112   int dfn;
113 } io_attr;
114
115 /** Filter attributes */
116 typedef struct {
117   long proj;                 /**< contains the result position to project (Proj) */
118   ir_node ** in_cg;          /**< array with interprocedural predecessors (Phi) */
119   int *backedge;              /**< Field n set to true if pred n is backedge.
120                                  @todo Ev. replace by bitfield! */
121 } filter_attr;
122
123 /** EndReg/EndExcept attributes */
124 typedef struct {
125   ir_graph * irg;            /**< ir_graph this node belongs to (for
126                               * navigating in interprocedural graphs) */
127 } end_attr;
128
129 /** CallBegin attributes */
130 typedef struct {
131   ir_graph * irg;            /**< ir_graph this node belongs to (for
132                               * navigating in interprocedural graphs) */
133   ir_node * call;            /**< associated Call-operation */
134 } callbegin_attr;
135
136 /** Cast attributes */
137 typedef struct {
138   type *totype;
139 } cast_attr;
140
141 /** Some irnodes just have one attribute, these are stored here,
142    some have more. Their name is 'irnodename_attr' */
143 typedef union {
144   start_attr     start; /**< For Start */
145   block_attr     block; /**< For Block: Fields needed to construct it */
146   cond_attr      c;     /**< For Cond. */
147   struct tarval *con;   /**< For Const: contains the value of the constant */
148   symconst_attr  i;     /**< For SymConst. */
149   sel_attr       s;     /**< For Sel. */
150   call_attr      call;  /**< For Call: pointer to the type of the method to call */
151   callbegin_attr callbegin; /**< For CallBegin */
152   alloc_attr     a;     /**< For Alloc. */
153   io_attr        io;    /**< For InstOf */
154   type          *f;     /**< For Free. */
155   cast_attr      cast;  /**< For Cast. */
156   int            phi0_pos;  /**< For Phi. Used to remember the value defined by
157                                this Phi node.  Needed when the Phi is completed
158                                to call get_r_internal_value to find the
159                                predecessors. If this attribute is set, the Phi
160                                node takes the role of the obsolete Phi0 node,
161                                therefore the name. */
162   int *phi_backedge;    /**< For Phi after construction.
163                            Field n set to true if pred n is backedge.
164                            @todo Ev. replace by bitfield! */
165   long           proj;  /**< For Proj: contains the result position to project */
166   filter_attr    filter;    /**< For Filter */
167   end_attr       end;       /**< For EndReg, EndExcept */
168 #if PRECISE_EXC_CONTEXT
169   struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions
170                                for nodes Store, Load, Div, Mod, Quot, DivMod. */
171 #endif
172 } attr;
173
174
175 /** common structure of an irnode
176     if the node has some attributes, they are stored in attr */
177 struct ir_node {
178   /* ------- Basics of the representation  ------- */
179   firm_kind kind;          /**< distinguishes this node from others */
180   ir_op *op;               /**< Opcode of this node. */
181   ir_mode *mode;           /**< Mode of this node. */
182   unsigned long visited;   /**< visited counter for walks of the graph */
183   struct ir_node **in;     /**< array with predecessors / operands */
184   void *link;              /**< to attach additional information to the node, e.g.
185                               used while construction to link Phi0 nodes and
186                               during optimization to link to nodes that
187                               shall replace a node. */
188   /* ------- Fields for optimizations / analysis information ------- */
189   struct ir_node **out;    /**< array of out edges */
190   struct dbg_info* dbi;    /**< A pointer to information for debug support. */
191   /* ------- For debugging ------- */
192 #ifdef DEBUG_libfirm
193   int node_nr;             /**< a unique node number for each node to make output
194                               readable. */
195 #endif
196   attr attr;               /**< attribute of this node. Depends on opcode.
197                               Must be last field of struct ir_node. */
198 };
199
200 /** Copies all attributes stored in the old node  to the new node.
201     Assumes both have the same opcode and sufficient size. */
202 void
203 copy_attrs (ir_node *old, ir_node *new);
204
205
206 /** Returns the array with the ins.  The content of the array may not be
207    changed.  */
208 ir_node     **get_irn_in            (const ir_node *node);
209
210 /*@{*/
211 /** access attributes directly */
212 INLINE tarval       *get_irn_const_attr    (ir_node *node);
213 INLINE long          get_irn_proj_attr     (ir_node *node);
214 INLINE alloc_attr    get_irn_alloc_attr    (ir_node *node);
215 INLINE type         *get_irn_free_attr     (ir_node *node);
216 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
217 type         *get_irn_call_attr     (ir_node *node);
218 sel_attr      get_irn_sel_attr      (ir_node *node);
219 int           get_irn_phi_attr      (ir_node *node);
220 block_attr    get_irn_block_attr   (ir_node *node);
221 /*@}*/
222
223 # endif /* _IRNODE_T_H_ */