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