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
95 type *tp; /**< the source type, for analyses. default: type_unknown. */
100 entity *ent; /**< entity to select */
104 type *cld_tp; /**< type of called procedure */
105 #if PRECISE_EXC_CONTEXT
106 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
108 entity ** callee_arr; /**< result of callee analysis */
111 /** Alloc attributes */
113 type *type; /**< Type of the allocated object. */
114 where_alloc where; /**< stack, heap or other managed part of memory */
115 #if PRECISE_EXC_CONTEXT
116 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
120 /** InstOf attributes */
127 /** Filter attributes */
129 long proj; /**< contains the result position to project (Proj) */
130 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
131 int *backedge; /**< Field n set to true if pred n is backedge.
132 @todo Ev. replace by bitfield! */
135 /** EndReg/EndExcept attributes */
138 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
139 /* * navigating in interprocedural graphs) */
140 /* @@@ now in block */
143 /** CallBegin attributes */
145 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
146 /* * navigating in interprocedural graphs) */
147 /* @@@ now in block */
148 ir_node * call; /**< associated Call-operation */
151 /** Cast attributes */
156 typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */
158 /** Some irnodes just have one attribute, these are stored here,
159 some have more. Their name is 'irnodename_attr' */
161 start_attr start; /**< For Start */
162 block_attr block; /**< For Block: Fields needed to construct it */
163 cond_attr c; /**< For Cond. */
164 const_attr con; /**< For Const: contains the value of the constant and a type */
165 symconst_attr i; /**< For SymConst. */
166 sel_attr s; /**< For Sel. */
167 call_attr call; /**< For Call: pointer to the type of the method to call */
168 callbegin_attr callbegin; /**< For CallBegin */
169 alloc_attr a; /**< For Alloc. */
170 io_attr io; /**< For InstOf */
171 type *f; /**< For Free. */
172 cast_attr cast; /**< For Cast. */
173 int phi0_pos; /**< For Phi. Used to remember the value defined by
174 this Phi node. Needed when the Phi is completed
175 to call get_r_internal_value to find the
176 predecessors. If this attribute is set, the Phi
177 node takes the role of the obsolete Phi0 node,
178 therefore the name. */
179 int *phi_backedge; /**< For Phi after construction.
180 Field n set to true if pred n is backedge.
181 @todo Ev. replace by bitfield! */
182 long proj; /**< For Proj: contains the result position to project */
183 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
184 filter_attr filter; /**< For Filter */
185 end_attr end; /**< For EndReg, EndExcept */
186 #if PRECISE_EXC_CONTEXT
187 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions
188 for nodes Store, Load, Div, Mod, Quot, DivMod. */
193 /** common structure of an irnode
194 if the node has some attributes, they are stored in attr */
196 /* ------- Basics of the representation ------- */
197 firm_kind kind; /**< distinguishes this node from others */
198 ir_op *op; /**< Opcode of this node. */
199 ir_mode *mode; /**< Mode of this node. */
200 unsigned long visited; /**< visited counter for walks of the graph */
201 struct ir_node **in; /**< array with predecessors / operands */
202 void *link; /**< to attach additional information to the node, e.g.
203 used while construction to link Phi0 nodes and
204 during optimization to link to nodes that
205 shall replace a node. */
206 /* ------- Fields for optimizations / analysis information ------- */
207 struct ir_node **out; /**< array of out edges */
208 struct dbg_info* dbi; /**< A pointer to information for debug support. */
209 /* ------- For debugging ------- */
211 int out_valid; /** < indicate that out edges are valid */
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 /*-------------------------------------------------------------------*/
252 * Checks whether a pointer points to a ir node.
253 * Intern version for libFirm.
256 __is_ir_node (const void *thing) {
257 return (get_kind(thing) == k_ir_node);
261 * Gets the op of a node.
262 * Intern version for libFirm.
264 static INLINE ir_op *
265 __get_irn_op (const ir_node *node)
272 * Gets the opcode of a node.
273 * Intern version for libFirm.
276 __get_irn_opcode (const ir_node *node)
278 assert (k_ir_node == get_kind(node));
280 return node->op->code;
284 * Returns the number of predecessors without the block predecessor.
285 * Intern version for libFirm.
288 __get_irn_intra_arity (const ir_node *node) {
290 return ARR_LEN(node->in) - 1;
294 * Returns the number of predecessors without the block predecessor.
295 * Intern version for libFirm.
298 __get_irn_inter_arity (const ir_node *node) {
300 if (__get_irn_opcode(node) == iro_Filter) {
301 assert(node->attr.filter.in_cg);
302 return ARR_LEN(node->attr.filter.in_cg) - 1;
303 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
304 return ARR_LEN(node->attr.block.in_cg) - 1;
306 return __get_irn_intra_arity(node);
310 * Returns the number of predecessors without the block predecessor.
311 * Intern version for libFirm.
314 __get_irn_arity (const ir_node *node) {
316 if (interprocedural_view) return __get_irn_inter_arity(node);
317 return __get_irn_intra_arity(node);
321 * Intern version for libFirm.
323 static INLINE ir_node *
324 __get_irn_intra_n (ir_node *node, int n) {
325 return (node->in[n + 1] = skip_nop(node->in[n + 1]));
329 * Intern version for libFirm.
331 static INLINE ir_node*
332 __get_irn_inter_n (ir_node *node, int n) {
333 /* handle Filter and Block specially */
334 if (__get_irn_opcode(node) == iro_Filter) {
335 assert(node->attr.filter.in_cg);
336 return (node->attr.filter.in_cg[n + 1] = skip_nop(node->attr.filter.in_cg[n + 1]));
337 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
338 return (node->attr.block.in_cg[n + 1] = skip_nop(node->attr.block.in_cg[n + 1]));
341 return __get_irn_intra_n (node, n);
345 * Access to the predecessors of a node.
346 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
347 * to iterate including the Block predecessor iterate from i = -1 to
349 * If it is a block, the entry -1 is NULL.
350 * Intern version for libFirm.
352 static INLINE ir_node *
353 __get_irn_n (ir_node *node, int n) {
354 assert(node); assert(-1 <= n && n < __get_irn_arity(node));
355 if (interprocedural_view) return __get_irn_inter_n (node, n);
356 return __get_irn_intra_n (node, n);
360 * Gets the mode of a node.
361 * Intern version for libFirm.
363 static INLINE ir_mode *
364 __get_irn_mode (const ir_node *node)
371 * Sets the mode of a node.
372 * Intern version of libFirm.
375 __set_irn_mode (ir_node *node, ir_mode *mode)
382 * Gets the visited counter of a node.
383 * Intern version for libFirm.
385 static INLINE unsigned long
386 __get_irn_visited (const ir_node *node)
389 return node->visited;
393 * Sets the visited counter of a node.
394 * Intern version for libFirm.
397 __set_irn_visited (ir_node *node, unsigned long visited)
400 node->visited = visited;
404 * Mark a node as visited in a graph.
405 * Intern version for libFirm.
408 __mark_irn_visited (ir_node *node) {
410 node->visited = current_ir_graph->visited;
414 * Returns non-zero if a node of was visited.
415 * Intern version for libFirm.
418 __irn_visited(const ir_node *node) {
420 return (node->visited >= current_ir_graph->visited);
424 * Returns non-zero if a node of was NOT visited.
425 * Intern version for libFirm.
428 __irn_not_visited(const ir_node *node) {
430 return (node->visited < current_ir_graph->visited);
434 * Sets the link of a node.
435 * Intern version of libFirm.
438 __set_irn_link(ir_node *node, void *link) {
440 /* Link field is used for Phi construction and various optimizations
442 assert(get_irg_phase_state(current_ir_graph) != phase_building);
448 * Returns the link of a node.
449 * Intern version of libFirm.
452 __get_irn_link(const ir_node *node) {
457 /* this section MUST contain all inline functions */
458 #define is_ir_node(thing) __is_ir_node(thing)
459 #define get_irn_intra_arity(node) __get_irn_intra_arity(node)
460 #define get_irn_inter_arity(node) __get_irn_inter_arity(node)
461 #define get_irn_arity(node) __get_irn_arity(node)
462 #define get_irn_intra_n(node, n) __get_irn_intra_n(node, n)
463 #define get_irn_inter_n(node, n) __get_irn_inter_n(node, n)
464 #define get_irn_n(node, n) __get_irn_n(node, n)
465 #define get_irn_mode(node) __get_irn_mode(node)
466 #define set_irn_mode(node, mode) __set_irn_mode(node, mode)
467 #define get_irn_op(node) __get_irn_op(node)
468 #define get_irn_opcode(node) __get_irn_opcode(node)
469 #define get_irn_visited(node) __get_irn_visited(node)
470 #define set_irn_visited(node, v) __set_irn_visited(node, v)
471 #define mark_irn_visited(node) __mark_irn_visited(node)
472 #define irn_visited(node) __irn_visited(node)
473 #define irn_not_visited(node) __irn_not_visited(node)
474 #define set_irn_link(node, link) __set_irn_link(node, link)
475 #define get_irn_link(node) __get_irn_link(node)
477 # endif /* _IRNODE_T_H_ */