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 "irgraph_t.h"
33 # include "irflag_t.h"
34 # include "firm_common_t.h"
35 # include "irdom_t.h" /* For size of struct dom_info. */
46 /** ir node attributes **/
48 /** Block attributes */
50 /* General attributes */
52 unsigned long block_visited; /**< for the walker that walks over all blocks. */
53 /* Attributes private to construction: */
54 bool matured; /**< if set, all in-nodes of the block are fixed */
55 struct ir_node **graph_arr; /**< array to store all parameters */
56 /* Attributes holding analyses information */
57 struct dom_info dom; /**< Datastructure that holds information about dominators.
59 Eventually overlay with graph_arr as only valid
60 in different phases. Eventually inline the whole
62 /* exc_t exc; */ /**< role of this block for exception handling */
63 /* ir_node *handler_entry; */ /**< handler entry block iff this block is part of a region */
64 ir_node ** in_cg; /**< array with predecessors in
65 * interprocedural_view, if they differ
66 * from intraprocedural predecessors */
67 int *backedge; /**< Field n set to true if pred n is backedge.
68 @@@ @todo Ev. replace by bitfield! */
69 int *cg_backedge; /**< Field n set to true if pred n is interprocedural backedge.
70 @@@ @todo Ev. replace by bitfield! */
73 /** Start attributes */
76 /* ir_graph *irg; @@@ now in block */
79 /** Cond attributes */
81 cond_kind kind; /**< flavor of Cond */
82 long default_proj; /**< for optimization: biggest Proj number, i.e. the one
86 /** Const attributes */
88 tarval *tv; /**< the target value */
89 type *tp; /**< the source type, for analyses. default: type_unknown. */
93 symconst_symbol sym; // old tori
99 entity *ent; /**< entity to select */
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 */
107 entity ** callee_arr; /**< result of callee analysis */
110 /** Alloc attributes */
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 */
119 /** InstOf attributes */
126 /** Filter attributes */
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! */
134 /** EndReg/EndExcept attributes */
137 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
138 /* * navigating in interprocedural graphs) */
139 /* @@@ now in block */
142 /** CallBegin attributes */
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 */
150 /** Cast attributes */
155 typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */
157 /** Some irnodes just have one attribute, these are stored here,
158 some have more. Their name is 'irnodename_attr' */
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. */
192 /** common structure of an irnode
193 if the node has some attributes, they are stored in attr */
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 ------- */
210 int out_valid; /** < indicate that out edges are valid */
211 int node_nr; /**< a unique node number for each node to make output
214 /* ------- For analyses -------- */
215 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
216 /* ------- Opcode depending fields -------- */
217 attr attr; /**< attribute of this node. Depends on opcode.
218 Must be last field of struct ir_node. */
221 /** Copies all attributes stored in the old node to the new node.
222 Assumes both have the same opcode and sufficient size. */
224 copy_attrs(const ir_node *old_node, ir_node *new_node);
227 /** Returns the array with the ins. The content of the array may not be
229 ir_node **get_irn_in (const ir_node *node);
232 /** access attributes directly */
233 INLINE const_attr get_irn_const_attr (ir_node *node);
234 INLINE long get_irn_proj_attr (ir_node *node);
235 INLINE alloc_attr get_irn_alloc_attr (ir_node *node);
236 INLINE type *get_irn_free_attr (ir_node *node);
237 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
238 type *get_irn_call_attr (ir_node *node);
239 type *get_irn_funccall_attr (ir_node *node);
240 sel_attr get_irn_sel_attr (ir_node *node);
241 int get_irn_phi_attr (ir_node *node);
242 block_attr get_irn_block_attr (ir_node *node);
245 /*-------------------------------------------------------------------*/
246 /* These function are most used in libfirm. Give them as static */
247 /* functions so they can be inlined. */
248 /*-------------------------------------------------------------------*/
251 * Checks whether a pointer points to a ir node.
252 * Intern version for libFirm.
255 __is_ir_node (const void *thing) {
256 return (get_kind(thing) == k_ir_node);
260 * Gets the op of a node.
261 * Intern version for libFirm.
263 static INLINE ir_op *
264 __get_irn_op (const ir_node *node)
271 * Gets the opcode of a node.
272 * Intern version for libFirm.
275 __get_irn_opcode (const ir_node *node)
277 assert (k_ir_node == get_kind(node));
279 return node->op->code;
283 * Returns the number of predecessors without the block predecessor.
284 * Intern version for libFirm.
287 __get_irn_intra_arity (const ir_node *node) {
289 return ARR_LEN(node->in) - 1;
293 * Returns the number of predecessors without the block predecessor.
294 * Intern version for libFirm.
297 __get_irn_inter_arity (const ir_node *node) {
299 if (__get_irn_opcode(node) == iro_Filter) {
300 assert(node->attr.filter.in_cg);
301 return ARR_LEN(node->attr.filter.in_cg) - 1;
302 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
303 return ARR_LEN(node->attr.block.in_cg) - 1;
305 return __get_irn_intra_arity(node);
309 * Returns the number of predecessors without the block predecessor.
310 * Intern version for libFirm.
313 __get_irn_arity (const ir_node *node) {
315 if (interprocedural_view) return __get_irn_inter_arity(node);
316 return __get_irn_intra_arity(node);
320 * Intern version for libFirm.
322 static INLINE ir_node *
323 __get_irn_intra_n (ir_node *node, int n) {
324 return (node->in[n + 1] = skip_nop(node->in[n + 1]));
328 * Intern version for libFirm.
330 static INLINE ir_node*
331 __get_irn_inter_n (ir_node *node, int n) {
332 /* handle Filter and Block specially */
333 if (__get_irn_opcode(node) == iro_Filter) {
334 assert(node->attr.filter.in_cg);
335 return (node->attr.filter.in_cg[n + 1] = skip_nop(node->attr.filter.in_cg[n + 1]));
336 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
337 return (node->attr.block.in_cg[n + 1] = skip_nop(node->attr.block.in_cg[n + 1]));
340 return __get_irn_intra_n (node, n);
344 * Access to the predecessors of a node.
345 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
346 * to iterate including the Block predecessor iterate from i = -1 to
348 * If it is a block, the entry -1 is NULL.
349 * Intern version for libFirm.
351 static INLINE ir_node *
352 __get_irn_n (ir_node *node, int n) {
353 assert(node); assert(-1 <= n && n < __get_irn_arity(node));
354 if (interprocedural_view) return __get_irn_inter_n (node, n);
355 return __get_irn_intra_n (node, n);
359 * Gets the mode of a node.
360 * Intern version for libFirm.
362 static INLINE ir_mode *
363 __get_irn_mode (const ir_node *node)
370 * Sets the mode of a node.
371 * Intern version of libFirm.
374 __set_irn_mode (ir_node *node, ir_mode *mode)
381 * Gets the visited counter of a node.
382 * Intern version for libFirm.
384 static INLINE unsigned long
385 __get_irn_visited (const ir_node *node)
388 return node->visited;
392 * Sets the visited counter of a node.
393 * Intern version for libFirm.
396 __set_irn_visited (ir_node *node, unsigned long visited)
399 node->visited = visited;
403 * Mark a node as visited in a graph.
404 * Intern version for libFirm.
407 __mark_irn_visited (ir_node *node) {
409 node->visited = current_ir_graph->visited;
413 * Returns non-zero if a node of was visited.
414 * Intern version for libFirm.
417 __irn_visited(const ir_node *node) {
419 return (node->visited >= current_ir_graph->visited);
423 * Returns non-zero if a node of was NOT visited.
424 * Intern version for libFirm.
427 __irn_not_visited(const ir_node *node) {
429 return (node->visited < current_ir_graph->visited);
433 * Sets the link of a node.
434 * Intern version of libFirm.
437 __set_irn_link(ir_node *node, void *link) {
439 /* Link field is used for Phi construction and various optimizations
441 assert(get_irg_phase_state(current_ir_graph) != phase_building);
447 * Returns the link of a node.
448 * Intern version of libFirm.
451 __get_irn_link(const ir_node *node) {
456 /* this section MUST contain all inline functions */
457 #define is_ir_node(thing) __is_ir_node(thing)
458 #define get_irn_intra_arity(node) __get_irn_intra_arity(node)
459 #define get_irn_inter_arity(node) __get_irn_inter_arity(node)
460 #define get_irn_arity(node) __get_irn_arity(node)
461 #define get_irn_intra_n(node, n) __get_irn_intra_n(node, n)
462 #define get_irn_inter_n(node, n) __get_irn_inter_n(node, n)
463 #define get_irn_n(node, n) __get_irn_n(node, n)
464 #define get_irn_mode(node) __get_irn_mode(node)
465 #define set_irn_mode(node, mode) __set_irn_mode(node, mode)
466 #define get_irn_op(node) __get_irn_op(node)
467 #define get_irn_opcode(node) __get_irn_opcode(node)
468 #define get_irn_visited(node) __get_irn_visited(node)
469 #define set_irn_visited(node, v) __set_irn_visited(node, v)
470 #define mark_irn_visited(node) __mark_irn_visited(node)
471 #define irn_visited(node) __irn_visited(node)
472 #define irn_not_visited(node) __irn_not_visited(node)
473 #define set_irn_link(node, link) __set_irn_link(node, link)
474 #define get_irn_link(node) __get_irn_link(node)
476 # endif /* _IRNODE_T_H_ */