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. */
42 /** ir node attributes **/
44 /** Block attributes */
46 /* General attributes */
48 unsigned long block_visited; /**< for the walker that walks over all blocks. */
49 /* Attributes private to construction: */
50 bool matured; /**< if set, all in-nodes of the block are fixed */
51 struct ir_node **graph_arr; /**< array to store all parameters */
52 /* Attributes holding analyses information */
53 struct dom_info dom; /**< Datastructure that holds information about dominators.
55 Eventually overlay with graph_arr as only valid
56 in different phases. Eventually inline the whole
58 /* exc_t exc; */ /**< role of this block for exception handling */
59 /* ir_node *handler_entry; */ /**< handler entry block iff this block is part of a region */
60 ir_node ** in_cg; /**< array with predecessors in
61 * interprocedural_view, if they differ
62 * from intraprocedural predecessors */
63 int *backedge; /**< Field n set to true if pred n is backedge.
64 @@@ @todo Ev. replace by bitfield! */
65 int *cg_backedge; /**< Field n set to true if pred n is interprocedural backedge.
66 @@@ @todo Ev. replace by bitfield! */
69 /** Start attributes */
72 /* ir_graph *irg; @@@ now in block */
75 /** Cond attributes */
77 cond_kind kind; /**< flavor of Cond */
78 long default_proj; /**< for optimization: biggest Proj number, i.e. the one
82 /** Const attributes */
84 tarval *tv; /**< the target value */
85 type *tp; /**< the source type, for analyses. default: type_unknown. */
88 /** SymConst attributes
89 This union contains the symbolic information represented by the node */
90 typedef union type_or_id {
100 /** Sel attributes */
102 entity *ent; /**< entity to select */
106 type *cld_tp; /**< type of called procedure */
107 #if PRECISE_EXC_CONTEXT
108 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
110 entity ** callee_arr; /**< result of callee analysis */
113 /** Alloc attributes */
115 type *type; /**< Type of the allocated object. */
116 where_alloc where; /**< stack, heap or other managed part of memory */
117 #if PRECISE_EXC_CONTEXT
118 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions */
122 /** InstOf attributes */
129 /** Filter attributes */
131 long proj; /**< contains the result position to project (Proj) */
132 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
133 int *backedge; /**< Field n set to true if pred n is backedge.
134 @todo Ev. replace by bitfield! */
137 /** EndReg/EndExcept attributes */
140 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
141 /* * navigating in interprocedural graphs) */
142 /* @@@ now in block */
145 /** CallBegin attributes */
147 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
148 /* * navigating in interprocedural graphs) */
149 /* @@@ now in block */
150 ir_node * call; /**< associated Call-operation */
153 /** Cast attributes */
158 typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */
160 /** Some irnodes just have one attribute, these are stored here,
161 some have more. Their name is 'irnodename_attr' */
163 start_attr start; /**< For Start */
164 block_attr block; /**< For Block: Fields needed to construct it */
165 cond_attr c; /**< For Cond. */
166 const_attr con; /**< For Const: contains the value of the constant and a type */
167 symconst_attr i; /**< For SymConst. */
168 sel_attr s; /**< For Sel. */
169 call_attr call; /**< For Call: pointer to the type of the method to call */
170 callbegin_attr callbegin; /**< For CallBegin */
171 alloc_attr a; /**< For Alloc. */
172 io_attr io; /**< For InstOf */
173 type *f; /**< For Free. */
174 cast_attr cast; /**< For Cast. */
175 int phi0_pos; /**< For Phi. Used to remember the value defined by
176 this Phi node. Needed when the Phi is completed
177 to call get_r_internal_value to find the
178 predecessors. If this attribute is set, the Phi
179 node takes the role of the obsolete Phi0 node,
180 therefore the name. */
181 int *phi_backedge; /**< For Phi after construction.
182 Field n set to true if pred n is backedge.
183 @todo Ev. replace by bitfield! */
184 long proj; /**< For Proj: contains the result position to project */
185 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
186 filter_attr filter; /**< For Filter */
187 end_attr end; /**< For EndReg, EndExcept */
188 #if PRECISE_EXC_CONTEXT
189 struct ir_node **frag_arr; /**< For Phi node construction in case of exceptions
190 for nodes Store, Load, Div, Mod, Quot, DivMod. */
195 /** common structure of an irnode
196 if the node has some attributes, they are stored in attr */
198 /* ------- Basics of the representation ------- */
199 firm_kind kind; /**< distinguishes this node from others */
200 ir_op *op; /**< Opcode of this node. */
201 ir_mode *mode; /**< Mode of this node. */
202 unsigned long visited; /**< visited counter for walks of the graph */
203 struct ir_node **in; /**< array with predecessors / operands */
204 void *link; /**< to attach additional information to the node, e.g.
205 used while construction to link Phi0 nodes and
206 during optimization to link to nodes that
207 shall replace a node. */
208 /* ------- Fields for optimizations / analysis information ------- */
209 struct ir_node **out; /**< array of out edges */
210 struct dbg_info* dbi; /**< A pointer to information for debug support. */
211 /* ------- For debugging ------- */
213 int out_valid; /** < indicate that out edges are valid */
214 int node_nr; /**< a unique node number for each node to make output
217 /* ------- For analyses -------- */
218 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
219 /* ------- Opcode depending fields -------- */
220 attr attr; /**< attribute of this node. Depends on opcode.
221 Must be last field of struct ir_node. */
224 /** Copies all attributes stored in the old node to the new node.
225 Assumes both have the same opcode and sufficient size. */
227 copy_attrs(const ir_node *old_node, ir_node *new_node);
230 /** Returns the array with the ins. The content of the array may not be
232 ir_node **get_irn_in (const ir_node *node);
235 /** access attributes directly */
236 INLINE const_attr get_irn_const_attr (ir_node *node);
237 INLINE long get_irn_proj_attr (ir_node *node);
238 INLINE alloc_attr get_irn_alloc_attr (ir_node *node);
239 INLINE type *get_irn_free_attr (ir_node *node);
240 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
241 type *get_irn_call_attr (ir_node *node);
242 type *get_irn_funccall_attr (ir_node *node);
243 sel_attr get_irn_sel_attr (ir_node *node);
244 int get_irn_phi_attr (ir_node *node);
245 block_attr get_irn_block_attr (ir_node *node);
248 /*-------------------------------------------------------------------*/
249 /* These function are most used in libfirm. Give them as static */
250 /* functions so they can be inlined. */
251 /*-------------------------------------------------------------------*/
254 * Checks whether a pointer points to a ir node.
255 * Intern version for libFirm.
258 __is_ir_node (const void *thing) {
259 return (get_kind(thing) == k_ir_node);
263 * Gets the op of a node.
264 * Intern version for libFirm.
266 static INLINE ir_op *
267 __get_irn_op (const ir_node *node)
274 * Gets the opcode of a node.
275 * Intern version for libFirm.
278 __get_irn_opcode (const ir_node *node)
280 assert (k_ir_node == get_kind(node));
282 return node->op->code;
286 * Returns the number of predecessors without the block predecessor.
287 * Intern version for libFirm.
290 __get_irn_intra_arity (const ir_node *node) {
292 return ARR_LEN(node->in) - 1;
296 * Returns the number of predecessors without the block predecessor.
297 * Intern version for libFirm.
300 __get_irn_inter_arity (const ir_node *node) {
302 if (__get_irn_opcode(node) == iro_Filter) {
303 assert(node->attr.filter.in_cg);
304 return ARR_LEN(node->attr.filter.in_cg) - 1;
305 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
306 return ARR_LEN(node->attr.block.in_cg) - 1;
308 return __get_irn_intra_arity(node);
312 * Returns the number of predecessors without the block predecessor.
313 * Intern version for libFirm.
316 __get_irn_arity (const ir_node *node) {
318 if (interprocedural_view) return __get_irn_inter_arity(node);
319 return __get_irn_intra_arity(node);
323 * Intern version for libFirm.
325 static INLINE ir_node *
326 __get_irn_intra_n (ir_node *node, int n) {
327 return (node->in[n + 1] = skip_nop(node->in[n + 1]));
331 * Intern version for libFirm.
333 static INLINE ir_node*
334 __get_irn_inter_n (ir_node *node, int n) {
335 /* handle Filter and Block specially */
336 if (__get_irn_opcode(node) == iro_Filter) {
337 assert(node->attr.filter.in_cg);
338 return (node->attr.filter.in_cg[n + 1] = skip_nop(node->attr.filter.in_cg[n + 1]));
339 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
340 return (node->attr.block.in_cg[n + 1] = skip_nop(node->attr.block.in_cg[n + 1]));
343 return __get_irn_intra_n (node, n);
347 * Access to the predecessors of a node.
348 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
349 * to iterate including the Block predecessor iterate from i = -1 to
351 * If it is a block, the entry -1 is NULL.
352 * Intern version for libFirm.
354 static INLINE ir_node *
355 __get_irn_n (ir_node *node, int n) {
356 assert(node); assert(-1 <= n && n < __get_irn_arity(node));
357 if (interprocedural_view) return __get_irn_inter_n (node, n);
358 return __get_irn_intra_n (node, n);
362 * Gets the mode of a node.
363 * Intern version for libFirm.
365 static INLINE ir_mode *
366 __get_irn_mode (const ir_node *node)
373 * Sets the mode of a node.
374 * Intern version of libFirm.
377 __set_irn_mode (ir_node *node, ir_mode *mode)
384 * Gets the visited counter of a node.
385 * Intern version for libFirm.
387 static INLINE unsigned long
388 __get_irn_visited (const ir_node *node)
391 return node->visited;
395 * Sets the visited counter of a node.
396 * Intern version for libFirm.
399 __set_irn_visited (ir_node *node, unsigned long visited)
402 node->visited = visited;
406 * Mark a node as visited in a graph.
407 * Intern version for libFirm.
410 __mark_irn_visited (ir_node *node) {
412 node->visited = current_ir_graph->visited;
416 * Returns non-zero if a node of was visited.
417 * Intern version for libFirm.
420 __irn_visited(const ir_node *node) {
422 return (node->visited >= current_ir_graph->visited);
426 * Returns non-zero if a node of was NOT visited.
427 * Intern version for libFirm.
430 __irn_not_visited(const ir_node *node) {
432 return (node->visited < current_ir_graph->visited);
436 * Sets the link of a node.
437 * Intern version of libFirm.
440 __set_irn_link(ir_node *node, void *link) {
442 /* Link field is used for Phi construction and various optimizations
444 assert(get_irg_phase_state(current_ir_graph) != phase_building);
450 * Returns the link of a node.
451 * Intern version of libFirm.
454 __get_irn_link(const ir_node *node) {
459 /* this section MUST contain all inline functions */
460 #define is_ir_node(thing) __is_ir_node(thing)
461 #define get_irn_intra_arity(node) __get_irn_intra_arity(node)
462 #define get_irn_inter_arity(node) __get_irn_inter_arity(node)
463 #define get_irn_arity(node) __get_irn_arity(node)
464 #define get_irn_intra_n(node, n) __get_irn_intra_n(node, n)
465 #define get_irn_inter_n(node, n) __get_irn_inter_n(node, n)
466 #define get_irn_n(node, n) __get_irn_n(node, n)
467 #define get_irn_mode(node) __get_irn_mode(node)
468 #define set_irn_mode(node, mode) __set_irn_mode(node, mode)
469 #define get_irn_op(node) __get_irn_op(node)
470 #define get_irn_opcode(node) __get_irn_opcode(node)
471 #define get_irn_visited(node) __get_irn_visited(node)
472 #define set_irn_visited(node, v) __set_irn_visited(node, v)
473 #define mark_irn_visited(node) __mark_irn_visited(node)
474 #define irn_visited(node) __irn_visited(node)
475 #define irn_not_visited(node) __irn_not_visited(node)
476 #define set_irn_link(node, link) __set_irn_link(node, link)
477 #define get_irn_link(node) __get_irn_link(node)
479 # endif /* _IRNODE_T_H_ */