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 #include "irextbb_t.h"
43 /** ir node attributes **/
45 /** Block attributes */
47 /* General attributes */
49 unsigned long block_visited; /**< for the walker that walks over all blocks. */
50 /* Attributes private to construction: */
51 int matured:1; /**< if set, all in-nodes of the block are fixed */
52 int dead:1; /**< if set, the block is dead (and could be replace by a Bad */
53 struct ir_node **graph_arr; /**< array to store all parameters */
54 /* Attributes holding analyses information */
55 struct dom_info dom; /**< Datastructure that holds information about dominators.
57 Eventually overlay with graph_arr as only valid
58 in different phases. Eventually inline the whole
60 /* exc_t exc; */ /**< role of this block for exception handling */
61 /* ir_node *handler_entry; */ /**< handler entry block iff this block is part of a region */
62 ir_node ** in_cg; /**< array with predecessors in
63 * interprocedural_view, if they differ
64 * from intraprocedural predecessors */
65 int *backedge; /**< Field n set to true if pred n is backedge.
66 @@@ @todo Ev. replace by bitfield! */
67 int *cg_backedge; /**< Field n set to true if pred n is interprocedural backedge.
68 @@@ @todo Ev. replace by bitfield! */
69 ir_extblk *extblk; /**< the extended basic block this block belongs to */
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 */
103 /** Exception attributes */
105 op_pin_state pin_state; /**< the pin state for operations that might generate a exception:
106 If it's know that no exception will be generated, could be set to
107 op_pin_state_floats. */
108 #if PRECISE_EXC_CONTEXT
109 struct ir_node **frag_arr; /**< For Phi node construction in case of exception */
114 except_attr exc; /**< the exception attribute. MUST be the first one. */
115 type *cld_tp; /**< type of called procedure */
116 entity ** callee_arr; /**< result of callee analysis */
119 /** Alloc attributes */
121 except_attr exc; /**< the exception attribute. MUST be the first one. */
122 type *type; /**< Type of the allocated object. */
123 where_alloc where; /**< stack, heap or other managed part of memory */
126 /** Free attributes */
128 type *type; /**< Type of the allocated object. */
129 where_alloc where; /**< stack, heap or other managed part of memory */
132 /** InstOf attributes */
139 /** Filter attributes */
141 long proj; /**< contains the result position to project (Proj) */
142 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
143 int *backedge; /**< Field n set to true if pred n is backedge.
144 @todo Ev. replace by bitfield! */
147 /** EndReg/EndExcept attributes */
152 /** CallBegin attributes */
154 ir_node * call; /**< associated Call-operation */
157 /** Cast attributes */
162 /** Load attributes */
164 except_attr exc; /**< the exception attribute. MUST be the first one. */
165 ir_mode *load_mode; /**< the mode of this Load operation */
166 ent_volatility volatility; /**< the volatility of a Load/Store operation */
169 /** Store attributes */
171 except_attr exc; /**< the exception attribute. MUST be the first one. */
172 ent_volatility volatility; /**< the volatility of a Store operation */
175 typedef pn_Cmp confirm_attr; /**< Attribute to hold compare operation */
178 * Edge info to put into an irn.
180 typedef struct _irn_edge_info_t {
181 struct list_head outs_head; /**< The list of all outs */
182 int out_count; /**< number of outs in the list */
186 /** Some irnodes just have one attribute, these are stored here,
187 some have more. Their name is 'irnodename_attr' */
189 start_attr start; /**< For Start */
190 block_attr block; /**< For Block: Fields needed to construct it */
191 cond_attr c; /**< For Cond. */
192 const_attr con; /**< For Const: contains the value of the constant and a type */
193 symconst_attr i; /**< For SymConst. */
194 sel_attr s; /**< For Sel. */
195 call_attr call; /**< For Call: pointer to the type of the method to call */
196 callbegin_attr callbegin; /**< For CallBegin */
197 alloc_attr a; /**< For Alloc. */
198 free_attr f; /**< For Free. */
199 io_attr io; /**< For InstOf */
200 cast_attr cast; /**< For Cast. */
201 load_attr load; /**< For Load. */
202 store_attr store; /**< For Store. */
203 int phi0_pos; /**< For Phi. Used to remember the value defined by
204 this Phi node. Needed when the Phi is completed
205 to call get_r_internal_value to find the
206 predecessors. If this attribute is set, the Phi
207 node takes the role of the obsolete Phi0 node,
208 therefore the name. */
209 int *phi_backedge; /**< For Phi after construction.
210 Field n set to true if pred n is backedge.
211 @todo Ev. replace by bitfield! */
212 long proj; /**< For Proj: contains the result position to project */
213 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
214 filter_attr filter; /**< For Filter */
215 end_attr end; /**< For EndReg, EndExcept */
216 except_attr except; /**< For Phi node construction in case of exceptions */
220 /** common structure of an irnode
221 if the node has some attributes, they are stored in attr */
223 /* ------- Basics of the representation ------- */
224 firm_kind kind; /**< distinguishes this node from others */
225 ir_op *op; /**< Opcode of this node. */
226 ir_mode *mode; /**< Mode of this node. */
227 unsigned long visited; /**< visited counter for walks of the graph */
228 struct ir_node **in; /**< array with predecessors / operands */
229 void *link; /**< to attach additional information to the node, e.g.
230 used while construction to link Phi0 nodes and
231 during optimization to link to nodes that
232 shall replace a node. */
233 /* ------- Fields for optimizations / analysis information ------- */
234 struct ir_node **out; /**< @deprecated array of out edges. */
235 struct dbg_info* dbi; /**< A pointer to information for debug support. */
236 /* ------- For debugging ------- */
239 int node_nr; /**< a unique node number for each node to make output
242 /* ------- For analyses -------- */
243 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
244 #ifdef DO_HEAPANALYSIS
248 #if FIRM_EDGES_INPLACE
249 irn_edge_info_t edge_info; /**< everlasting out edges */
251 /* ------- Opcode depending fields -------- */
252 attr attr; /**< attribute of this node. Depends on opcode.
253 Must be last field of struct ir_node. */
257 /** Returns the array with the ins. The content of the array may not be
259 ir_node **get_irn_in (const ir_node *node);
262 /** access attributes directly */
263 const_attr get_irn_const_attr (ir_node *node);
264 long get_irn_proj_attr (ir_node *node);
265 alloc_attr get_irn_alloc_attr (ir_node *node);
266 free_attr get_irn_free_attr (ir_node *node);
267 symconst_attr get_irn_symconst_attr (ir_node *node);
268 type *get_irn_call_attr (ir_node *node);
269 type *get_irn_funccall_attr (ir_node *node);
270 sel_attr get_irn_sel_attr (ir_node *node);
271 int get_irn_phi_attr (ir_node *node);
272 block_attr get_irn_block_attr (ir_node *node);
273 load_attr get_irn_load_attr (ir_node *node);
274 store_attr get_irn_store_attr (ir_node *node);
275 except_attr get_irn_except_attr (ir_node *node);
279 * The amount of additional space for custom data to be allocated upon creating a new node.
281 extern unsigned firm_add_node_size;
283 /** Set the get_type operation of an ir_op. */
284 ir_op *firm_set_default_get_type(ir_op *op);
286 /*-------------------------------------------------------------------*/
287 /* These function are most used in libfirm. Give them as static */
288 /* functions so they can be inlined. */
289 /*-------------------------------------------------------------------*/
292 * Checks whether a pointer points to a ir node.
293 * Intern version for libFirm.
296 _is_ir_node (const void *thing) {
297 return (get_kind(thing) == k_ir_node);
301 * Gets the op of a node.
302 * Intern version for libFirm.
304 static INLINE ir_op *
305 _get_irn_op (const ir_node *node) {
310 /** Copies all attributes stored in the old node to the new node.
311 Assumes both have the same opcode and sufficient size. */
313 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
314 ir_op *op = _get_irn_op(old_node);
316 /* must always exist */
317 op->copy_attr(old_node, new_node);
321 * Gets the opcode of a node.
322 * Intern version for libFirm.
325 _get_irn_opcode (const ir_node *node) {
326 assert (k_ir_node == get_kind(node));
328 return node->op->code;
332 * Returns the number of predecessors without the block predecessor.
333 * Intern version for libFirm.
336 _get_irn_intra_arity (const ir_node *node) {
338 return ARR_LEN(node->in) - 1;
342 * Returns the number of predecessors without the block predecessor.
343 * Intern version for libFirm.
346 _get_irn_inter_arity (const ir_node *node) {
348 if (_get_irn_opcode(node) == iro_Filter) {
349 assert(node->attr.filter.in_cg);
350 return ARR_LEN(node->attr.filter.in_cg) - 1;
351 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
352 return ARR_LEN(node->attr.block.in_cg) - 1;
354 return _get_irn_intra_arity(node);
358 * Returns the number of predecessors without the block predecessor.
359 * Intern version for libFirm.
361 extern int (*_get_irn_arity)(const ir_node *node);
364 * Intern version for libFirm.
366 static INLINE ir_node *
367 _get_irn_intra_n (const ir_node *node, int n) {
368 assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
370 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
374 * Intern version for libFirm.
376 static INLINE ir_node*
377 _get_irn_inter_n (const ir_node *node, int n) {
378 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
380 /* handle Filter and Block specially */
381 if (_get_irn_op(node) == op_Filter) {
382 assert(node->attr.filter.in_cg);
383 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
384 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
385 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
388 return _get_irn_intra_n (node, n);
392 * Access to the predecessors of a node.
393 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
394 * to iterate including the Block predecessor iterate from i = -1 to
396 * If it is a block, the entry -1 is NULL.
397 * Intern version for libFirm.
399 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
402 * Gets the mode of a node.
403 * Intern version for libFirm.
405 static INLINE ir_mode *
406 _get_irn_mode (const ir_node *node)
413 * Sets the mode of a node.
414 * Intern version of libFirm.
417 _set_irn_mode (ir_node *node, ir_mode *mode)
424 * Gets the visited counter of a node.
425 * Intern version for libFirm.
427 static INLINE unsigned long
428 _get_irn_visited (const ir_node *node)
431 return node->visited;
435 * Sets the visited counter of a node.
436 * Intern version for libFirm.
439 _set_irn_visited (ir_node *node, unsigned long visited)
442 node->visited = visited;
446 * Mark a node as visited in a graph.
447 * Intern version for libFirm.
450 _mark_irn_visited (ir_node *node) {
452 node->visited = current_ir_graph->visited;
456 * Returns non-zero if a node of was visited.
457 * Intern version for libFirm.
460 _irn_visited(const ir_node *node) {
462 return (node->visited >= current_ir_graph->visited);
466 * Returns non-zero if a node of was NOT visited.
467 * Intern version for libFirm.
470 _irn_not_visited(const ir_node *node) {
472 return (node->visited < current_ir_graph->visited);
476 * Sets the link of a node.
477 * Intern version of libFirm.
480 _set_irn_link(ir_node *node, void *link) {
482 /* Link field is used for Phi construction and various optimizations
484 assert(get_irg_phase_state(current_ir_graph) != phase_building);
490 * Returns the link of a node.
491 * Intern version of libFirm.
494 _get_irn_link(const ir_node *node) {
495 assert (node && _is_ir_node(node));
500 * Returns the pinned state of a node.
501 * Intern version of libFirm.
503 static INLINE op_pin_state
504 _get_irn_pinned(const ir_node *node) {
506 assert(node && _is_ir_node(node));
507 state = _get_op_pinned(_get_irn_op(node));
508 if (state >= op_pin_state_exc_pinned)
509 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
514 _is_unop(const ir_node *node) {
515 assert(node && _is_ir_node(node));
516 return (node->op->opar == oparity_unary);
520 _is_binop(const ir_node *node) {
521 assert(node && _is_ir_node(node));
522 return (node->op->opar == oparity_binary);
526 _is_Bad(const ir_node *node) {
528 return (node && _get_irn_op(node) == op_Bad);
532 _is_Const(const ir_node *node) {
534 return (node && _get_irn_op(node) == op_Const);
538 _is_Unknown (const ir_node *node) {
540 return (node && _get_irn_op(node) == op_Unknown);
544 _is_no_Block(const ir_node *node) {
545 assert(node && _is_ir_node(node));
546 return (_get_irn_op(node) != op_Block);
550 _is_Block(const ir_node *node) {
551 assert(node && _is_ir_node(node));
552 return (_get_irn_op(node) == op_Block);
556 _get_Block_n_cfgpreds (ir_node *node) {
557 assert(_is_Block(node));
558 return _get_irn_arity(node);
561 static INLINE ir_node *
562 _get_Block_cfgpred (ir_node *node, int pos) {
563 assert(0 <= pos && pos < get_irn_arity(node));
564 assert(_is_Block(node));
565 return _get_irn_n(node, pos);
568 static INLINE unsigned long
569 _get_Block_block_visited (ir_node *node) {
570 assert (node->op == op_Block);
571 return node->attr.block.block_visited;
575 _set_Block_block_visited (ir_node *node, unsigned long visit) {
576 assert (node->op == op_Block);
577 node->attr.block.block_visited = visit;
580 /* For this current_ir_graph must be set. */
582 _mark_Block_block_visited (ir_node *node) {
583 assert (node->op == op_Block);
584 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
588 _Block_not_block_visited(ir_node *node) {
589 assert (node->op == op_Block);
590 return (node->attr.block.block_visited < get_irg_block_visited(current_ir_graph));
593 static INLINE ir_node *
594 _set_Block_dead(ir_node *block) {
595 assert(_get_irn_op(block) == op_Block);
596 block->attr.block.dead = 1;
601 _is_Block_dead(const ir_node *block) {
602 ir_op * op = _get_irn_op(block);
607 assert(op == op_Block);
608 return block->attr.block.dead;
612 static INLINE tarval *_get_Const_tarval (ir_node *node) {
613 assert (_get_irn_op(node) == op_Const);
614 return node->attr.con.tv;
617 static INLINE cnst_classify_t _classify_Const(ir_node *node) {
619 assert(_is_ir_node(node));
621 op = _get_irn_op(node);
624 return classify_tarval(_get_Const_tarval(node));
625 else if(op == op_SymConst)
626 return CNST_SYMCONST;
628 return CNST_NO_CONST;
631 static INLINE type *_get_irn_type(ir_node *node) {
632 return _get_irn_op(node)->get_type(node);
635 /* this section MUST contain all inline functions */
636 #define is_ir_node(thing) _is_ir_node(thing)
637 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
638 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
639 #define get_irn_arity(node) _get_irn_arity(node)
640 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
641 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
642 #define get_irn_n(node, n) _get_irn_n(node, n)
643 #define get_irn_mode(node) _get_irn_mode(node)
644 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
645 #define get_irn_op(node) _get_irn_op(node)
646 #define get_irn_opcode(node) _get_irn_opcode(node)
647 #define get_irn_visited(node) _get_irn_visited(node)
648 #define set_irn_visited(node, v) _set_irn_visited(node, v)
649 #define mark_irn_visited(node) _mark_irn_visited(node)
650 #define irn_visited(node) _irn_visited(node)
651 #define irn_not_visited(node) _irn_not_visited(node)
652 #define set_irn_link(node, link) _set_irn_link(node, link)
653 #define get_irn_link(node) _get_irn_link(node)
654 #define is_unop(node) _is_unop(node)
655 #define is_binop(node) _is_binop(node)
656 #define is_Const(node) _is_Const(node)
657 #define is_Unknown(node) _is_Unknown(node)
658 #define is_Bad(node) _is_Bad(node)
659 #define is_no_Block(node) _is_no_Block(node)
660 #define is_Block(node) _is_Block(node)
661 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
662 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
663 #define get_Block_block_visited(node) _get_Block_block_visited(node)
664 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
665 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
666 #define Block_not_block_visited(node) _Block_not_block_visited(node)
667 #define set_Block_dead(block) _set_Block_dead(block)
668 #define is_Block_dead(block) _is_Block_dead(block)
669 #define get_Const_tarval(node) _get_Const_tarval(node)
670 #define classify_Const(node) _classify_Const(node)
671 #define get_irn_type(node) _get_irn_type(node)
673 # endif /* _IRNODE_T_H_ */