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 unsigned matured:1; /**< if set, all in-nodes of the block are fixed */
52 unsigned dead:1; /**< if set, the block is dead (and could be replace by a Bad */
53 ir_node **graph_arr; /**< array to store all parameters */
54 /* Attributes holding analyses information */
55 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 dom_info pdom; /**< Datastructure that holds information about post-dominators. */
61 ir_node ** in_cg; /**< array with predecessors in
62 * interprocedural_view, if they differ
63 * from intraprocedural predecessors */
64 int *backedge; /**< Field n set to true if pred n is backedge.
65 @@@ @todo Ev. replace by bit field! */
66 int *cg_backedge; /**< Field n set to true if pred n is interprocedural backedge.
67 @@@ @todo Ev. replace by bit field! */
68 ir_extblk *extblk; /**< the extended basic block this block belongs to */
70 struct list_head succ_head; /**< A list head for all successor edges of a block. */
74 /** Start attributes */
77 /* ir_graph *irg; @@@ now in block */
80 /** Cond attributes */
82 cond_kind kind; /**< flavor of Cond */
83 long default_proj; /**< only for non-binary Conds: biggest Proj number, i.e. the one used for default. */
84 cond_jmp_predicate pred; /**< only for binary Conds: The jump predication. */
87 /** Const attributes */
89 tarval *tv; /**< the target value */
90 ir_type *tp; /**< the source type, for analyses. default: type_unknown. */
94 symconst_symbol sym; // old tori
96 ir_type *tp; /**< the source type, for analyses. default: type_unknown. */
101 entity *ent; /**< entity to select */
104 /** Exception attributes */
106 op_pin_state pin_state; /**< the pin state for operations that might generate a exception:
107 If it's know that no exception will be generated, could be set to
108 op_pin_state_floats. */
109 #if PRECISE_EXC_CONTEXT
110 struct ir_node **frag_arr; /**< For Phi node construction in case of exception */
114 /** Call attributes */
116 except_attr exc; /**< the exception attribute. MUST be the first one. */
117 ir_type *cld_tp; /**< type of called procedure */
118 entity ** callee_arr; /**< result of callee analysis */
121 /** Alloc attributes */
123 except_attr exc; /**< the exception attribute. MUST be the first one. */
124 ir_type *type; /**< Type of the allocated object. */
125 where_alloc where; /**< stack, heap or other managed part of memory */
128 /** Free attributes */
130 ir_type *type; /**< Type of the allocated object. */
131 where_alloc where; /**< stack, heap or other managed part of memory */
134 /** InstOf attributes */
136 except_attr exc; /**< the exception attribute. MUST be the first one. */
137 ir_type *type; /**< the type of which the object pointer must be */
140 /** Filter attributes */
142 long proj; /**< contains the result position to project (Proj) */
143 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
144 int *backedge; /**< Field n set to true if pred n is backedge.
145 @todo Ev. replace by bitfield! */
148 /** EndReg/EndExcept attributes */
153 /** CallBegin attributes */
155 ir_node * call; /**< Associated Call-operation. */
158 /** Cast attributes */
160 ir_type *totype; /**< Type of the casted node. */
163 /** Load attributes */
165 except_attr exc; /**< The exception attribute. MUST be the first one. */
166 ir_mode *load_mode; /**< The mode of this Load operation. */
167 ent_volatility volatility; /**< The volatility of a Load/Store operation. */
170 /** Store attributes */
172 except_attr exc; /**< the exception attribute. MUST be the first one. */
173 ent_volatility volatility; /**< the volatility of a Store operation */
176 typedef pn_Cmp confirm_attr; /**< Attribute to hold compare operation */
178 /** CopyB attribute */
180 except_attr exc; /**< The exception attribute. MUST be the first one. */
181 ir_type *data_type; /**< Type of the copied entity. */
184 /** Bound attribute */
186 except_attr exc; /**< The exception attribute. MUST be the first one. */
190 * Edge info to put into an irn.
192 typedef struct _irn_edge_info_t {
193 struct list_head outs_head; /**< The list of all outs. */
194 int out_count; /**< Number of outs in the list. */
198 /** Some IR-nodes just have one attribute, these are stored here,
199 some have more. Their name is 'irnodename_attr' */
201 start_attr start; /**< For Start */
202 block_attr block; /**< For Block: Fields needed to construct it */
203 cond_attr c; /**< For Cond. */
204 const_attr con; /**< For Const: contains the value of the constant and a type */
205 symconst_attr i; /**< For SymConst. */
206 sel_attr s; /**< For Sel. */
207 call_attr call; /**< For Call: pointer to the type of the method to call */
208 callbegin_attr callbegin; /**< For CallBegin */
209 alloc_attr a; /**< For Alloc. */
210 free_attr f; /**< For Free. */
211 io_attr io; /**< For InstOf */
212 cast_attr cast; /**< For Cast. */
213 load_attr load; /**< For Load. */
214 store_attr store; /**< For Store. */
215 int phi0_pos; /**< For Phi. Used to remember the value defined by
216 this Phi node. Needed when the Phi is completed
217 to call get_r_internal_value to find the
218 predecessors. If this attribute is set, the Phi
219 node takes the role of the obsolete Phi0 node,
220 therefore the name. */
221 int *phi_backedge; /**< For Phi after construction.
222 Field n set to true if pred n is backedge.
223 @todo Ev. replace by bitfield! */
224 long proj; /**< For Proj: contains the result position to project */
225 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
226 filter_attr filter; /**< For Filter */
227 end_attr end; /**< For EndReg, EndExcept */
228 except_attr except; /**< For Phi node construction in case of exceptions */
229 copyb_attr copyb; /**< For CopyB operation */
230 bound_attr bound; /**< For Bound operation */
234 /** common structure of an irnode
235 if the node has some attributes, they are stored in attr */
237 /* ------- Basics of the representation ------- */
238 firm_kind kind; /**< distinguishes this node from others */
239 ir_op *op; /**< Opcode of this node. */
240 ir_mode *mode; /**< Mode of this node. */
241 struct ir_node **in; /**< array with predecessors / operands */
242 unsigned long visited; /**< visited counter for walks of the graph */
243 void *link; /**< to attach additional information to the node, e.g.
244 used while construction to link Phi0 nodes and
245 during optimization to link to nodes that
246 shall replace a node. */
247 /* ------- Fields for optimizations / analysis information ------- */
248 struct ir_node **out; /**< @deprecated array of out edges. */
249 struct dbg_info* dbi; /**< A pointer to information for debug support. */
250 /* ------- For debugging ------- */
253 long node_nr; /**< a unique node number for each node to make output
256 /* ------- For analyses -------- */
257 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
258 #ifdef DO_HEAPANALYSIS
259 struct abstval *av; /**< the abstract value of this node */
262 #if FIRM_EDGES_INPLACE
263 irn_edge_info_t edge_info; /**< everlasting out edges */
265 /* ------- Opcode depending fields -------- */
266 attr attr; /**< attribute of this node. Depends on opcode.
267 Must be last field of struct ir_node. */
271 /** Returns the array with the ins. The content of the array may not be
273 ir_node **get_irn_in (const ir_node *node);
276 /** access attributes directly */
277 const_attr get_irn_const_attr (ir_node *node);
278 long get_irn_proj_attr (ir_node *node);
279 alloc_attr get_irn_alloc_attr (ir_node *node);
280 free_attr get_irn_free_attr (ir_node *node);
281 symconst_attr get_irn_symconst_attr (ir_node *node);
282 ir_type *get_irn_call_attr (ir_node *node);
283 ir_type *get_irn_funccall_attr (ir_node *node);
284 sel_attr get_irn_sel_attr (ir_node *node);
285 int get_irn_phi_attr (ir_node *node);
286 block_attr get_irn_block_attr (ir_node *node);
287 load_attr get_irn_load_attr (ir_node *node);
288 store_attr get_irn_store_attr (ir_node *node);
289 except_attr get_irn_except_attr (ir_node *node);
293 * The amount of additional space for custom data to be allocated upon creating a new node.
295 extern unsigned firm_add_node_size;
298 * Sets the get_type operation for an ir_op_ops.
300 * @param code the opcode for the default operation
301 * @param ops the operations initialized
306 ir_op_ops *firm_set_default_get_type(opcode code, ir_op_ops *ops);
309 * Sets the get_type_attr operation for an ir_op_ops.
311 * @param code the opcode for the default operation
312 * @param ops the operations initialized
317 ir_op_ops *firm_set_default_get_type_attr(opcode code, ir_op_ops *ops);
320 * Sets the get_entity_attr operation for an ir_op_ops.
322 * @param code the opcode for the default operation
323 * @param ops the operations initialized
328 ir_op_ops *firm_set_default_get_entity_attr(opcode code, ir_op_ops *ops);
330 /*-------------------------------------------------------------------*/
331 /* These function are most used in libfirm. Give them as static */
332 /* functions so they can be inlined. */
333 /*-------------------------------------------------------------------*/
336 * Checks whether a pointer points to a ir node.
337 * Intern version for libFirm.
340 _is_ir_node (const void *thing) {
341 return (get_kind(thing) == k_ir_node);
345 * Gets the op of a node.
346 * Intern version for libFirm.
348 static INLINE ir_op *
349 _get_irn_op (const ir_node *node) {
354 /** Copies all attributes stored in the old node to the new node.
355 Assumes both have the same opcode and sufficient size. */
357 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
358 ir_op *op = _get_irn_op(old_node);
360 /* must always exist */
361 op->ops.copy_attr(old_node, new_node);
365 * Gets the opcode of a node.
366 * Intern version for libFirm.
369 _get_irn_opcode (const ir_node *node) {
370 assert (k_ir_node == get_kind(node));
372 return node->op->code;
376 * Returns the number of predecessors without the block predecessor.
377 * Intern version for libFirm.
380 _get_irn_intra_arity (const ir_node *node) {
382 return ARR_LEN(node->in) - 1;
386 * Returns the number of predecessors without the block predecessor.
387 * Intern version for libFirm.
390 _get_irn_inter_arity (const ir_node *node) {
392 if (_get_irn_op(node) == op_Filter) {
393 assert(node->attr.filter.in_cg);
394 return ARR_LEN(node->attr.filter.in_cg) - 1;
395 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
396 return ARR_LEN(node->attr.block.in_cg) - 1;
398 return _get_irn_intra_arity(node);
402 * Returns the number of predecessors without the block predecessor.
403 * Intern version for libFirm.
405 extern int (*_get_irn_arity)(const ir_node *node);
408 * Intern version for libFirm.
410 static INLINE ir_node *
411 _get_irn_intra_n (const ir_node *node, int n) {
414 assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
416 nn = node->in[n + 1];
417 if (!nn || (nn->op != op_Id)) return nn;
419 return (node->in[n + 1] = skip_Id(nn));
423 * Intern version for libFirm.
425 static INLINE ir_node*
426 _get_irn_inter_n (const ir_node *node, int n) {
427 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
429 /* handle Filter and Block specially */
430 if (_get_irn_op(node) == op_Filter) {
431 assert(node->attr.filter.in_cg);
432 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
433 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
434 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
437 return _get_irn_intra_n (node, n);
441 * Access to the predecessors of a node.
442 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
443 * to iterate including the Block predecessor iterate from i = -1 to
445 * If it is a block, the entry -1 is NULL.
446 * Intern version for libFirm.
448 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
451 * Gets the mode of a node.
452 * Intern version for libFirm.
454 static INLINE ir_mode *
455 _get_irn_mode (const ir_node *node)
462 * Sets the mode of a node.
463 * Intern version of libFirm.
466 _set_irn_mode (ir_node *node, ir_mode *mode)
473 * Gets the visited counter of a node.
474 * Intern version for libFirm.
476 static INLINE unsigned long
477 _get_irn_visited (const ir_node *node)
480 return node->visited;
484 * Sets the visited counter of a node.
485 * Intern version for libFirm.
488 _set_irn_visited (ir_node *node, unsigned long visited)
491 node->visited = visited;
495 * Mark a node as visited in a graph.
496 * Intern version for libFirm.
499 _mark_irn_visited (ir_node *node) {
501 node->visited = current_ir_graph->visited;
505 * Returns non-zero if a node of was visited.
506 * Intern version for libFirm.
509 _irn_visited(const ir_node *node) {
511 return (node->visited >= current_ir_graph->visited);
515 * Returns non-zero if a node of was NOT visited.
516 * Intern version for libFirm.
519 _irn_not_visited(const ir_node *node) {
521 return (node->visited < current_ir_graph->visited);
525 * Sets the link of a node.
526 * Intern version of libFirm.
529 _set_irn_link(ir_node *node, void *link) {
531 /* Link field is used for Phi construction and various optimizations
533 assert(get_irg_phase_state(get_irn_irg(node)) != phase_building);
539 * Returns the link of a node.
540 * Intern version of libFirm.
543 _get_irn_link(const ir_node *node) {
544 assert (node && _is_ir_node(node));
549 * Returns whether the node _always_ must be pinned.
550 * I.e., the node is not floating after global cse.
552 * Intern version of libFirm.
554 static INLINE op_pin_state
555 _get_irn_pinned(const ir_node *node) {
557 assert(node && _is_ir_node(node));
559 state = _get_op_pinned(_get_irn_op(node));
561 if (state >= op_pin_state_exc_pinned)
562 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
566 static INLINE op_pin_state
567 _is_irn_pinned_in_irg(const ir_node *node) {
568 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
569 return get_irn_pinned(node);
570 return op_pin_state_pinned;
574 _is_unop(const ir_node *node) {
575 assert(node && _is_ir_node(node));
576 return (node->op->opar == oparity_unary);
580 _is_binop(const ir_node *node) {
581 assert(node && _is_ir_node(node));
582 return (node->op->opar == oparity_binary);
586 _is_Bad(const ir_node *node) {
588 return (node && _get_irn_op(node) == op_Bad);
592 _is_Const(const ir_node *node) {
594 return (node && _get_irn_op(node) == op_Const);
598 _is_Unknown (const ir_node *node) {
600 return (node && _get_irn_op(node) == op_Unknown);
604 _is_no_Block(const ir_node *node) {
605 assert(node && _is_ir_node(node));
606 return (_get_irn_op(node) != op_Block);
610 _is_Block(const ir_node *node) {
611 assert(node && _is_ir_node(node));
612 return (_get_irn_op(node) == op_Block);
616 _get_Block_n_cfgpreds (ir_node *node) {
617 assert(_is_Block(node));
618 return _get_irn_arity(node);
621 static INLINE ir_node *
622 _get_Block_cfgpred (ir_node *node, int pos) {
623 assert(0 <= pos && pos < get_irn_arity(node));
624 assert(_is_Block(node));
625 return _get_irn_n(node, pos);
628 /* Get the predecessor block.
630 * Returns the block corresponding to the predecessor pos.
632 * There are several ambiguities we resolve with this function:
633 * - The direct predecessor can be a Proj, which is not pinned.
634 * We walk from the predecessor to the next pinned node
635 * (skip_Proj) and return the block that node is in.
636 * - If we encounter the Bad node, this function does not return
637 * Start, but the Bad node.
639 static INLINE ir_node *
640 _get_Block_cfgpred_block(ir_node *node, int pos) {
641 ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
643 res = get_nodes_block(res);
647 static INLINE unsigned long
648 _get_Block_block_visited (ir_node *node) {
649 assert (node->op == op_Block);
650 return node->attr.block.block_visited;
654 _set_Block_block_visited (ir_node *node, unsigned long visit) {
655 assert (node->op == op_Block);
656 node->attr.block.block_visited = visit;
659 /* For this current_ir_graph must be set. */
661 _mark_Block_block_visited (ir_node *node) {
662 assert (node->op == op_Block);
663 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
667 _Block_not_block_visited(ir_node *node) {
668 assert (node->op == op_Block);
669 return (node->attr.block.block_visited < get_irg_block_visited(current_ir_graph));
672 static INLINE ir_node *
673 _set_Block_dead(ir_node *block) {
674 assert(_get_irn_op(block) == op_Block);
675 block->attr.block.dead = 1;
680 _is_Block_dead(const ir_node *block) {
681 ir_op * op = _get_irn_op(block);
686 assert(op == op_Block);
687 return block->attr.block.dead;
691 static INLINE tarval *_get_Const_tarval (ir_node *node) {
692 assert (_get_irn_op(node) == op_Const);
693 return node->attr.con.tv;
696 static INLINE cnst_classify_t _classify_Const(ir_node *node) {
698 assert(_is_ir_node(node));
700 op = _get_irn_op(node);
703 return classify_tarval(_get_Const_tarval(node));
704 else if(op == op_SymConst)
705 return CNST_SYMCONST;
707 return CNST_NO_CONST;
710 static INLINE int _is_irn_forking(const ir_node *node) {
711 return is_op_forking(_get_irn_op(node));
714 static INLINE ir_type *_get_irn_type(ir_node *node) {
715 return _get_irn_op(node)->ops.get_type(node);
718 static INLINE ir_type *_get_irn_type_attr(ir_node *node) {
719 return _get_irn_op(node)->ops.get_type_attr(node);
722 static INLINE entity *_get_irn_entity_attr(ir_node *node) {
723 return _get_irn_op(node)->ops.get_entity_attr(node);
726 static INLINE int _is_irn_constlike(const ir_node *node) {
727 return is_op_constlike(_get_irn_op(node));
730 static INLINE int _is_irn_keep(const ir_node *node) {
731 return is_op_keep(_get_irn_op(node));
734 static INLINE cond_jmp_predicate _get_Cond_jmp_pred(ir_node *node) {
735 assert (_get_irn_op(node) == op_Cond);
736 return node->attr.c.pred;
739 static INLINE void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
740 assert (_get_irn_op(node) == op_Cond);
741 node->attr.c.pred = pred;
744 /* this section MUST contain all inline functions */
745 #define is_ir_node(thing) _is_ir_node(thing)
746 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
747 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
748 #define get_irn_arity(node) _get_irn_arity(node)
749 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
750 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
751 #define get_irn_n(node, n) _get_irn_n(node, n)
752 #define get_irn_mode(node) _get_irn_mode(node)
753 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
754 #define get_irn_op(node) _get_irn_op(node)
755 #define get_irn_opcode(node) _get_irn_opcode(node)
756 #define get_irn_visited(node) _get_irn_visited(node)
757 #define set_irn_visited(node, v) _set_irn_visited(node, v)
758 #define mark_irn_visited(node) _mark_irn_visited(node)
759 #define irn_visited(node) _irn_visited(node)
760 #define irn_not_visited(node) _irn_not_visited(node)
761 #define set_irn_link(node, link) _set_irn_link(node, link)
762 #define get_irn_link(node) _get_irn_link(node)
763 #define get_irn_pinned(node) _get_irn_pinned(node)
764 #define is_irn_pinned_in_irg(node) _is_irn_pinned_in_irg(node)
765 #define is_unop(node) _is_unop(node)
766 #define is_binop(node) _is_binop(node)
767 #define is_Const(node) _is_Const(node)
768 #define is_Unknown(node) _is_Unknown(node)
769 #define is_Bad(node) _is_Bad(node)
770 #define is_no_Block(node) _is_no_Block(node)
771 #define is_Block(node) _is_Block(node)
772 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
773 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
774 #define get_Block_cfgpred_block(node, pos) _get_Block_cfgpred_block(node, pos)
775 #define get_Block_block_visited(node) _get_Block_block_visited(node)
776 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
777 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
778 #define Block_not_block_visited(node) _Block_not_block_visited(node)
779 #define set_Block_dead(block) _set_Block_dead(block)
780 #define is_Block_dead(block) _is_Block_dead(block)
781 #define get_Const_tarval(node) _get_Const_tarval(node)
782 #define classify_Const(node) _classify_Const(node)
783 #define is_irn_forking(node) _is_irn_forking(node)
784 #define get_irn_type(node) _get_irn_type(node)
785 #define get_irn_type_attr(node) _get_irn_type_attr(node)
786 #define get_irn_entity_attr(node) _get_irn_entity_attr(node)
787 #define is_irn_constlike(node) _is_irn_constlike(node)
788 #define is_irn_keep(node) _is_irn_keep(node)
789 #define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
790 #define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
792 # endif /* _IRNODE_T_H_ */