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.
16 * Declarations of an ir node.
18 * @author Martin Trapp, Christian Schaefer
24 #include "firm_config.h"
27 #include "irgraph_t.h"
29 #include "firm_common_t.h"
30 #include "irdom_t.h" /* For size of struct dom_info. */
40 /** ir node attributes **/
42 /** Block attributes */
44 /* General attributes */
46 unsigned long block_visited; /**< for the walker that walks over all blocks. */
47 /* Attributes private to construction: */
48 int matured:1; /**< if set, all in-nodes of the block are fixed */
49 int dead:1; /**< if set, the block is dead (and could be replace by a Bad */
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. */
88 symconst_symbol sym; // old tori
90 type *tp; /**< the source type, for analyses. default: type_unknown. */
95 entity *ent; /**< entity to select */
98 /** Exception attributes */
100 op_pin_state pin_state; /**< the pin state for operations that might generate a exception:
101 If it's know that no exception will be generated, could be set to
102 op_pin_state_floats. */
103 #if PRECISE_EXC_CONTEXT
104 struct ir_node **frag_arr; /**< For Phi node construction in case of exception */
109 except_attr exc; /**< the exception attribute. MUST be the first one. */
110 type *cld_tp; /**< type of called procedure */
111 entity ** callee_arr; /**< result of callee analysis */
114 /** Alloc attributes */
116 except_attr exc; /**< the exception attribute. MUST be the first one. */
117 type *type; /**< Type of the allocated object. */
118 where_alloc where; /**< stack, heap or other managed part of memory */
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 */
141 /** CallBegin attributes */
143 ir_node * call; /**< associated Call-operation */
146 /** Cast attributes */
151 /** Load attributes */
153 except_attr exc; /**< the exception attribute. MUST be the first one. */
154 ir_mode *load_mode; /**< the mode of this Load operation */
155 ent_volatility volatility; /**< the volatility of a Load/Store operation */
158 /** Store attributes */
160 except_attr exc; /**< the exception attribute. MUST be the first one. */
161 ent_volatility volatility; /**< the volatility of a Store operation */
164 typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */
166 /** Some irnodes just have one attribute, these are stored here,
167 some have more. Their name is 'irnodename_attr' */
169 start_attr start; /**< For Start */
170 block_attr block; /**< For Block: Fields needed to construct it */
171 cond_attr c; /**< For Cond. */
172 const_attr con; /**< For Const: contains the value of the constant and a type */
173 symconst_attr i; /**< For SymConst. */
174 sel_attr s; /**< For Sel. */
175 call_attr call; /**< For Call: pointer to the type of the method to call */
176 callbegin_attr callbegin; /**< For CallBegin */
177 alloc_attr a; /**< For Alloc. */
178 io_attr io; /**< For InstOf */
179 type *f; /**< For Free. */
180 cast_attr cast; /**< For Cast. */
181 load_attr load; /**< For Load. */
182 store_attr store; /**< For Store. */
183 int phi0_pos; /**< For Phi. Used to remember the value defined by
184 this Phi node. Needed when the Phi is completed
185 to call get_r_internal_value to find the
186 predecessors. If this attribute is set, the Phi
187 node takes the role of the obsolete Phi0 node,
188 therefore the name. */
189 int *phi_backedge; /**< For Phi after construction.
190 Field n set to true if pred n is backedge.
191 @todo Ev. replace by bitfield! */
192 long proj; /**< For Proj: contains the result position to project */
193 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
194 filter_attr filter; /**< For Filter */
195 end_attr end; /**< For EndReg, EndExcept */
196 except_attr except; /**< For Phi node construction in case of exceptions */
200 /** common structure of an irnode
201 if the node has some attributes, they are stored in attr */
203 /* ------- Basics of the representation ------- */
204 firm_kind kind; /**< distinguishes this node from others */
205 ir_op *op; /**< Opcode of this node. */
206 ir_mode *mode; /**< Mode of this node. */
207 unsigned long visited; /**< visited counter for walks of the graph */
208 struct ir_node **in; /**< array with predecessors / operands */
209 void *link; /**< to attach additional information to the node, e.g.
210 used while construction to link Phi0 nodes and
211 during optimization to link to nodes that
212 shall replace a node. */
213 /* ------- Fields for optimizations / analysis information ------- */
214 struct ir_node **out; /**< array of out edges */
215 struct dbg_info* dbi; /**< A pointer to information for debug support. */
216 /* ------- For debugging ------- */
218 int out_valid; /** < indicate that out edges are valid */
219 int node_nr; /**< a unique node number for each node to make output
222 /* ------- For analyses -------- */
223 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
224 #ifdef DO_HEAPANALYSIS
228 /* ------- Opcode depending fields -------- */
229 attr attr; /**< attribute of this node. Depends on opcode.
230 Must be last field of struct ir_node. */
234 /** Returns the array with the ins. The content of the array may not be
236 ir_node **get_irn_in (const ir_node *node);
239 /** access attributes directly */
240 const_attr get_irn_const_attr (ir_node *node);
241 long get_irn_proj_attr (ir_node *node);
242 alloc_attr get_irn_alloc_attr (ir_node *node);
243 type *get_irn_free_attr (ir_node *node);
244 symconst_attr get_irn_symconst_attr (ir_node *node);
245 type *get_irn_call_attr (ir_node *node);
246 type *get_irn_funccall_attr (ir_node *node);
247 sel_attr get_irn_sel_attr (ir_node *node);
248 int get_irn_phi_attr (ir_node *node);
249 block_attr get_irn_block_attr (ir_node *node);
250 load_attr get_irn_load_attr (ir_node *node);
251 store_attr get_irn_store_attr (ir_node *node);
252 except_attr get_irn_except_attr (ir_node *node);
256 * The amount of additional space for custom data to be allocated upon creating a new node.
258 extern unsigned firm_add_node_size;
260 /*-------------------------------------------------------------------*/
261 /* These function are most used in libfirm. Give them as static */
262 /* functions so they can be inlined. */
263 /*-------------------------------------------------------------------*/
266 * Checks whether a pointer points to a ir node.
267 * Intern version for libFirm.
270 __is_ir_node (const void *thing) {
271 return (get_kind(thing) == k_ir_node);
275 * Gets the op of a node.
276 * Intern version for libFirm.
278 static INLINE ir_op *
279 __get_irn_op (const ir_node *node) {
284 /** Copies all attributes stored in the old node to the new node.
285 Assumes both have the same opcode and sufficient size. */
287 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
288 ir_op *op = __get_irn_op(old_node);
290 /* must always exist */
291 op->copy_attr(old_node, new_node);
295 * Gets the opcode of a node.
296 * Intern version for libFirm.
299 __get_irn_opcode (const ir_node *node) {
300 assert (k_ir_node == get_kind(node));
302 return node->op->code;
306 * Returns the number of predecessors without the block predecessor.
307 * Intern version for libFirm.
310 __get_irn_intra_arity (const ir_node *node) {
312 return ARR_LEN(node->in) - 1;
316 * Returns the number of predecessors without the block predecessor.
317 * Intern version for libFirm.
320 __get_irn_inter_arity (const ir_node *node) {
322 if (__get_irn_opcode(node) == iro_Filter) {
323 assert(node->attr.filter.in_cg);
324 return ARR_LEN(node->attr.filter.in_cg) - 1;
325 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
326 return ARR_LEN(node->attr.block.in_cg) - 1;
328 return __get_irn_intra_arity(node);
332 * Returns the number of predecessors without the block predecessor.
333 * Intern version for libFirm.
335 extern int (*__get_irn_arity)(const ir_node *node);
338 * Intern version for libFirm.
340 static INLINE ir_node *
341 __get_irn_intra_n (const ir_node *node, int n) {
342 assert(node); assert(-1 <= n && n < __get_irn_intra_arity(node));
344 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
348 * Intern version for libFirm.
350 static INLINE ir_node*
351 __get_irn_inter_n (const ir_node *node, int n) {
352 assert(node); assert(-1 <= n && n < __get_irn_inter_arity(node));
354 /* handle Filter and Block specially */
355 if (__get_irn_opcode(node) == iro_Filter) {
356 assert(node->attr.filter.in_cg);
357 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
358 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
359 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
362 return __get_irn_intra_n (node, n);
366 * Access to the predecessors of a node.
367 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
368 * to iterate including the Block predecessor iterate from i = -1 to
370 * If it is a block, the entry -1 is NULL.
371 * Intern version for libFirm.
373 extern ir_node *(*__get_irn_n)(const ir_node *node, int n);
376 * Gets the mode of a node.
377 * Intern version for libFirm.
379 static INLINE ir_mode *
380 __get_irn_mode (const ir_node *node)
387 * Sets the mode of a node.
388 * Intern version of libFirm.
391 __set_irn_mode (ir_node *node, ir_mode *mode)
398 * Gets the visited counter of a node.
399 * Intern version for libFirm.
401 static INLINE unsigned long
402 __get_irn_visited (const ir_node *node)
405 return node->visited;
409 * Sets the visited counter of a node.
410 * Intern version for libFirm.
413 __set_irn_visited (ir_node *node, unsigned long visited)
416 node->visited = visited;
420 * Mark a node as visited in a graph.
421 * Intern version for libFirm.
424 __mark_irn_visited (ir_node *node) {
426 node->visited = current_ir_graph->visited;
430 * Returns non-zero if a node of was visited.
431 * Intern version for libFirm.
434 __irn_visited(const ir_node *node) {
436 return (node->visited >= current_ir_graph->visited);
440 * Returns non-zero if a node of was NOT visited.
441 * Intern version for libFirm.
444 __irn_not_visited(const ir_node *node) {
446 return (node->visited < current_ir_graph->visited);
450 * Sets the link of a node.
451 * Intern version of libFirm.
454 __set_irn_link(ir_node *node, void *link) {
456 /* Link field is used for Phi construction and various optimizations
458 assert(get_irg_phase_state(current_ir_graph) != phase_building);
464 * Returns the link of a node.
465 * Intern version of libFirm.
468 __get_irn_link(const ir_node *node) {
469 assert (node && is_ir_node(node));
474 * Returns the pinned state of a node.
475 * Intern version of libFirm.
477 static INLINE op_pin_state
478 __get_irn_pinned(const ir_node *node) {
479 assert(node && is_ir_node(node));
480 op_pin_state state = __get_op_pinned(__get_irn_op(node));
481 if (state >= op_pin_state_exc_pinned)
482 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
487 __is_unop(const ir_node *node) {
488 assert(node && is_ir_node(node));
489 return (node->op->opar == oparity_unary);
493 __is_binop(const ir_node *node) {
494 assert(node && is_ir_node(node));
495 return (node->op->opar == oparity_binary);
499 __is_Bad(const ir_node *node) {
501 return (node && __get_irn_op(node) == op_Bad);
505 __is_no_Block(const ir_node *node) {
506 assert(node && is_ir_node(node));
507 return (__get_irn_op(node) != op_Block);
511 __is_Block(const ir_node *node) {
512 assert(node && is_ir_node(node));
513 return (__get_irn_op(node) == op_Block);
516 static INLINE ir_node *
517 __set_Block_dead(ir_node *block) {
518 assert(__get_irn_op(block) == op_Block);
519 block->attr.block.dead = 1;
524 __is_Block_dead(const ir_node *block) {
525 ir_op * op = __get_irn_op(block);
530 assert(op == op_Block);
531 return block->attr.block.dead;
535 /* this section MUST contain all inline functions */
536 #define is_ir_node(thing) __is_ir_node(thing)
537 #define get_irn_intra_arity(node) __get_irn_intra_arity(node)
538 #define get_irn_inter_arity(node) __get_irn_inter_arity(node)
539 #define get_irn_arity(node) __get_irn_arity(node)
540 #define get_irn_intra_n(node, n) __get_irn_intra_n(node, n)
541 #define get_irn_inter_n(node, n) __get_irn_inter_n(node, n)
542 #define get_irn_n(node, n) __get_irn_n(node, n)
543 #define get_irn_mode(node) __get_irn_mode(node)
544 #define set_irn_mode(node, mode) __set_irn_mode(node, mode)
545 #define get_irn_op(node) __get_irn_op(node)
546 #define get_irn_opcode(node) __get_irn_opcode(node)
547 #define get_irn_visited(node) __get_irn_visited(node)
548 #define set_irn_visited(node, v) __set_irn_visited(node, v)
549 #define mark_irn_visited(node) __mark_irn_visited(node)
550 #define irn_visited(node) __irn_visited(node)
551 #define irn_not_visited(node) __irn_not_visited(node)
552 #define set_irn_link(node, link) __set_irn_link(node, link)
553 #define get_irn_link(node) __get_irn_link(node)
554 #define is_unop(node) __is_unop(node)
555 #define is_binop(node) __is_binop(node)
556 #define is_Bad(node) __is_Bad(node)
557 #define is_no_Block(node) __is_no_Block(node)
558 #define is_Block(node) __is_Block(node)
559 #define set_Block_dead(block) __set_Block_dead(block)
560 #define is_Block_dead(block) __is_Block_dead(block)
562 # endif /* _IRNODE_T_H_ */