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