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
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 * Declarations of an ir node.
19 * @author Martin Trapp, Christian Schaefer
32 # include "irflag_t.h"
33 # include "firm_common_t.h"
34 # include "irdom_t.h" /* For size of struct dom_info. */
41 /** ir node attributes **/
43 /** Block attributes */
45 /* General attributes */
47 unsigned long block_visited; /**< for the walker that walks over all blocks. */
48 /* Attributes private to construction: */
49 bool matured; /**< if set, all in-nodes of the block are fixed */
50 struct ir_node **graph_arr; /**< array to store all parameters */
51 /* Attributes holding analyses information */
52 struct dom_info dom; /**< Datastructure that holds information about dominators.
54 Eventually overlay with graph_arr as only valid
55 in different phases. Eventually inline the whole
57 /* exc_t exc; */ /**< role of this block for exception handling */
58 /* ir_node *handler_entry; */ /**< handler entry block iff this block is part of a region */
59 ir_node ** in_cg; /**< array with predecessors in
60 * interprocedural_view, if they differ
61 * from intraprocedural predecessors */
62 int *backedge; /**< Field n set to true if pred n is backedge.
63 @@@ @todo Ev. replace by bitfield! */
64 int *cg_backedge; /**< Field n set to true if pred n is interprocedural backedge.
65 @@@ @todo Ev. replace by bitfield! */
68 /** Start attributes */
71 /* ir_graph *irg; @@@ now in block */
74 /** Cond attributes */
76 cond_kind kind; /**< flavor of Cond */
77 long default_proj; /**< for optimization: biggest Proj number, i.e. the one
81 /** Const attributes */
83 tarval *tv; /**< the target value */
84 type *tp; /**< the source type, for analyses. default: type_unknown. */
87 /** SymConst attributes
88 This union contains the symbolic information represented by the node */
89 typedef union type_or_id {
101 entity *ent; /**< entity to select */
105 type *cld_tp; /**< type of called procedure */
106 #if PRECISE_EXC_CONTEXT
107 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
109 entity ** callee_arr; /**< result of callee analysis */
112 /** Alloc attributes */
114 type *type; /**< Type of the allocated object. */
115 where_alloc where; /**< stack, heap or other managed part of memory */
116 #if PRECISE_EXC_CONTEXT
117 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
121 /** InstOf attributes */
128 /** Filter attributes */
130 long proj; /**< contains the result position to project (Proj) */
131 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
132 int *backedge; /**< Field n set to true if pred n is backedge.
133 @todo Ev. replace by bitfield! */
136 /** EndReg/EndExcept attributes */
139 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
140 /* * navigating in interprocedural graphs) */
141 /* @@@ now in block */
144 /** CallBegin attributes */
146 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
147 /* * navigating in interprocedural graphs) */
148 /* @@@ now in block */
149 ir_node * call; /**< associated Call-operation */
152 /** Cast attributes */
157 typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */
159 /** Some irnodes just have one attribute, these are stored here,
160 some have more. Their name is 'irnodename_attr' */
162 start_attr start; /**< For Start */
163 block_attr block; /**< For Block: Fields needed to construct it */
164 cond_attr c; /**< For Cond. */
165 const_attr con; /**< For Const: contains the value of the constant and a type */
166 symconst_attr i; /**< For SymConst. */
167 sel_attr s; /**< For Sel. */
168 call_attr call; /**< For Call: pointer to the type of the method to call */
169 callbegin_attr callbegin; /**< For CallBegin */
170 alloc_attr a; /**< For Alloc. */
171 io_attr io; /**< For InstOf */
172 type *f; /**< For Free. */
173 cast_attr cast; /**< For Cast. */
174 int phi0_pos; /**< For Phi. Used to remember the value defined by
175 this Phi node. Needed when the Phi is completed
176 to call get_r_internal_value to find the
177 predecessors. If this attribute is set, the Phi
178 node takes the role of the obsolete Phi0 node,
179 therefore the name. */
180 int *phi_backedge; /**< For Phi after construction.
181 Field n set to true if pred n is backedge.
182 @todo Ev. replace by bitfield! */
183 long proj; /**< For Proj: contains the result position to project */
184 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
185 filter_attr filter; /**< For Filter */
186 end_attr end; /**< For EndReg, EndExcept */
187 #if PRECISE_EXC_CONTEXT
188 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions
189 for nodes Store, Load, Div, Mod, Quot, DivMod. */
194 /** common structure of an irnode
195 if the node has some attributes, they are stored in attr */
197 /* ------- Basics of the representation ------- */
198 firm_kind kind; /**< distinguishes this node from others */
199 ir_op *op; /**< Opcode of this node. */
200 ir_mode *mode; /**< Mode of this node. */
201 unsigned long visited; /**< visited counter for walks of the graph */
202 struct ir_node **in; /**< array with predecessors / operands */
203 void *link; /**< to attach additional information to the node, e.g.
204 used while construction to link Phi0 nodes and
205 during optimization to link to nodes that
206 shall replace a node. */
207 /* ------- Fields for optimizations / analysis information ------- */
208 struct ir_node **out; /**< array of out edges */
209 struct dbg_info* dbi; /**< A pointer to information for debug support. */
210 /* ------- For debugging ------- */
212 int node_nr; /**< a unique node number for each node to make output
215 /* ------- For analyses -------- */
216 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
217 /* ------- Opcode depending fields -------- */
218 attr attr; /**< attribute of this node. Depends on opcode.
219 Must be last field of struct ir_node. */
222 /** Copies all attributes stored in the old node to the new node.
223 Assumes both have the same opcode and sufficient size. */
225 copy_attrs(const ir_node *old_node, ir_node *new_node);
228 /** Returns the array with the ins. The content of the array may not be
230 ir_node **get_irn_in (const ir_node *node);
233 /** access attributes directly */
234 INLINE const_attr get_irn_const_attr (ir_node *node);
235 INLINE long get_irn_proj_attr (ir_node *node);
236 INLINE alloc_attr get_irn_alloc_attr (ir_node *node);
237 INLINE type *get_irn_free_attr (ir_node *node);
238 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
239 type *get_irn_call_attr (ir_node *node);
240 type *get_irn_funccall_attr (ir_node *node);
241 sel_attr get_irn_sel_attr (ir_node *node);
242 int get_irn_phi_attr (ir_node *node);
243 block_attr get_irn_block_attr (ir_node *node);
246 /*********************************************************************/
247 /* These function are most used in libfirm. Give them as static */
248 /* functions so they can be inlined. */
249 /*********************************************************************/
253 /* returns the number of predecessors without the block predecessor. */
255 intern_get_irn_intra_arity (const ir_node *node) {
257 return ARR_LEN(node->in) - 1;
260 /* returns the number of predecessors without the block predecessor. */
262 intern_get_irn_inter_arity (const ir_node *node) {
264 if (get_irn_opcode(node) == iro_Filter) {
265 assert(node->attr.filter.in_cg);
266 return ARR_LEN(node->attr.filter.in_cg) - 1;
267 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
268 return ARR_LEN(node->attr.block.in_cg) - 1;
270 return intern_get_irn_intra_arity(node);
273 /* returns the number of predecessors without the block predecessor. */
275 intern_get_irn_arity (const ir_node *node) {
277 if (interprocedural_view) return intern_get_irn_inter_arity(node);
278 return intern_get_irn_intra_arity(node);
281 static INLINE ir_node *
282 intern_get_irn_intra_n (ir_node *node, int n) {
283 return (node->in[n + 1] = skip_nop(node->in[n + 1]));
286 static INLINE ir_node*
287 intern_get_irn_inter_n (ir_node *node, int n) {
288 /* handle Filter and Block specially */
289 if (get_irn_opcode(node) == iro_Filter) {
290 assert(node->attr.filter.in_cg);
291 return (node->attr.filter.in_cg[n + 1] = skip_nop(node->attr.filter.in_cg[n + 1]));
292 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
293 return (node->attr.block.in_cg[n + 1] = skip_nop(node->attr.block.in_cg[n + 1]));
296 return get_irn_intra_n (node, n);
299 /* to iterate through the predecessors without touching the array */
300 /* To iterate over the operands iterate from 0 to i < get_irn_arity(),
301 to iterate including the Block predecessor iterate from i = -1 to
303 If it is a block, the entry -1 is NULL. */
304 static INLINE ir_node *
305 intern_get_irn_n (ir_node *node, int n) {
306 assert(node); assert(-1 <= n && n < intern_get_irn_arity(node));
307 if (interprocedural_view) return get_irn_inter_n (node, n);
308 return get_irn_intra_n (node, n);
311 static INLINE ir_mode *
312 intern_get_irn_mode (const ir_node *node)
318 static INLINE ir_op *
319 intern_get_irn_op (const ir_node *node)
326 intern_get_irn_opcode (const ir_node *node)
328 assert (k_ir_node == get_kind(node));
330 return node->op->code;
335 # endif /* _IRNODE_T_H_ */