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