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