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 */
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 */
185 * Edge info to put into an irn.
187 typedef struct _irn_edge_info_t {
188 struct list_head outs_head; /**< The list of all outs */
189 int out_count; /**< number of outs in the list */
193 /** Some IR-nodes just have one attribute, these are stored here,
194 some have more. Their name is 'irnodename_attr' */
196 start_attr start; /**< For Start */
197 block_attr block; /**< For Block: Fields needed to construct it */
198 cond_attr c; /**< For Cond. */
199 const_attr con; /**< For Const: contains the value of the constant and a type */
200 symconst_attr i; /**< For SymConst. */
201 sel_attr s; /**< For Sel. */
202 call_attr call; /**< For Call: pointer to the type of the method to call */
203 callbegin_attr callbegin; /**< For CallBegin */
204 alloc_attr a; /**< For Alloc. */
205 free_attr f; /**< For Free. */
206 io_attr io; /**< For InstOf */
207 cast_attr cast; /**< For Cast. */
208 load_attr load; /**< For Load. */
209 store_attr store; /**< For Store. */
210 int phi0_pos; /**< For Phi. Used to remember the value defined by
211 this Phi node. Needed when the Phi is completed
212 to call get_r_internal_value to find the
213 predecessors. If this attribute is set, the Phi
214 node takes the role of the obsolete Phi0 node,
215 therefore the name. */
216 int *phi_backedge; /**< For Phi after construction.
217 Field n set to true if pred n is backedge.
218 @todo Ev. replace by bitfield! */
219 long proj; /**< For Proj: contains the result position to project */
220 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
221 filter_attr filter; /**< For Filter */
222 end_attr end; /**< For EndReg, EndExcept */
223 except_attr except; /**< For Phi node construction in case of exceptions */
224 copyb_attr copyb; /**< For CopyB operation */
228 /** common structure of an irnode
229 if the node has some attributes, they are stored in attr */
231 /* ------- Basics of the representation ------- */
232 firm_kind kind; /**< distinguishes this node from others */
233 ir_op *op; /**< Opcode of this node. */
234 ir_mode *mode; /**< Mode of this node. */
235 struct ir_node **in; /**< array with predecessors / operands */
236 unsigned long visited; /**< visited counter for walks of the graph */
237 void *link; /**< to attach additional information to the node, e.g.
238 used while construction to link Phi0 nodes and
239 during optimization to link to nodes that
240 shall replace a node. */
241 /* ------- Fields for optimizations / analysis information ------- */
242 struct ir_node **out; /**< @deprecated array of out edges. */
243 struct dbg_info* dbi; /**< A pointer to information for debug support. */
244 /* ------- For debugging ------- */
247 int node_nr; /**< a unique node number for each node to make output
250 /* ------- For analyses -------- */
251 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
252 #ifdef DO_HEAPANALYSIS
253 struct abstval *av; /**< the abstract value of this node */
256 #if FIRM_EDGES_INPLACE
257 irn_edge_info_t edge_info; /**< everlasting out edges */
259 /* ------- Opcode depending fields -------- */
260 attr attr; /**< attribute of this node. Depends on opcode.
261 Must be last field of struct ir_node. */
265 /** Returns the array with the ins. The content of the array may not be
267 ir_node **get_irn_in (const ir_node *node);
270 /** access attributes directly */
271 const_attr get_irn_const_attr (ir_node *node);
272 long get_irn_proj_attr (ir_node *node);
273 alloc_attr get_irn_alloc_attr (ir_node *node);
274 free_attr get_irn_free_attr (ir_node *node);
275 symconst_attr get_irn_symconst_attr (ir_node *node);
276 ir_type *get_irn_call_attr (ir_node *node);
277 ir_type *get_irn_funccall_attr (ir_node *node);
278 sel_attr get_irn_sel_attr (ir_node *node);
279 int get_irn_phi_attr (ir_node *node);
280 block_attr get_irn_block_attr (ir_node *node);
281 load_attr get_irn_load_attr (ir_node *node);
282 store_attr get_irn_store_attr (ir_node *node);
283 except_attr get_irn_except_attr (ir_node *node);
287 * The amount of additional space for custom data to be allocated upon creating a new node.
289 extern unsigned firm_add_node_size;
292 * Sets the get_type operation for an ir_op_ops.
294 * @param code the opcode for the default operation
295 * @param ops the operations initialized
300 ir_op_ops *firm_set_default_get_type(opcode code, ir_op_ops *ops);
303 * Sets the get_type_attr operation for an ir_op_ops.
305 * @param code the opcode for the default operation
306 * @param ops the operations initialized
311 ir_op_ops *firm_set_default_get_type_attr(opcode code, ir_op_ops *ops);
314 * Sets the get_entity_attr operation for an ir_op_ops.
316 * @param code the opcode for the default operation
317 * @param ops the operations initialized
322 ir_op_ops *firm_set_default_get_entity_attr(opcode code, ir_op_ops *ops);
324 /*-------------------------------------------------------------------*/
325 /* These function are most used in libfirm. Give them as static */
326 /* functions so they can be inlined. */
327 /*-------------------------------------------------------------------*/
330 * Checks whether a pointer points to a ir node.
331 * Intern version for libFirm.
334 _is_ir_node (const void *thing) {
335 return (get_kind(thing) == k_ir_node);
339 * Gets the op of a node.
340 * Intern version for libFirm.
342 static INLINE ir_op *
343 _get_irn_op (const ir_node *node) {
348 /** Copies all attributes stored in the old node to the new node.
349 Assumes both have the same opcode and sufficient size. */
351 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
352 ir_op *op = _get_irn_op(old_node);
354 /* must always exist */
355 op->ops.copy_attr(old_node, new_node);
359 * Gets the opcode of a node.
360 * Intern version for libFirm.
363 _get_irn_opcode (const ir_node *node) {
364 assert (k_ir_node == get_kind(node));
366 return node->op->code;
370 * Returns the number of predecessors without the block predecessor.
371 * Intern version for libFirm.
374 _get_irn_intra_arity (const ir_node *node) {
376 return ARR_LEN(node->in) - 1;
380 * Returns the number of predecessors without the block predecessor.
381 * Intern version for libFirm.
384 _get_irn_inter_arity (const ir_node *node) {
386 if (_get_irn_op(node) == op_Filter) {
387 assert(node->attr.filter.in_cg);
388 return ARR_LEN(node->attr.filter.in_cg) - 1;
389 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
390 return ARR_LEN(node->attr.block.in_cg) - 1;
392 return _get_irn_intra_arity(node);
396 * Returns the number of predecessors without the block predecessor.
397 * Intern version for libFirm.
399 extern int (*_get_irn_arity)(const ir_node *node);
402 * Intern version for libFirm.
404 static INLINE ir_node *
405 _get_irn_intra_n (const ir_node *node, int n) {
408 assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
410 nn = node->in[n + 1];
411 if (!nn || (nn->op != op_Id)) return nn;
413 return (node->in[n + 1] = skip_Id(nn));
417 * Intern version for libFirm.
419 static INLINE ir_node*
420 _get_irn_inter_n (const ir_node *node, int n) {
421 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
423 /* handle Filter and Block specially */
424 if (_get_irn_op(node) == op_Filter) {
425 assert(node->attr.filter.in_cg);
426 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
427 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
428 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
431 return _get_irn_intra_n (node, n);
435 * Access to the predecessors of a node.
436 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
437 * to iterate including the Block predecessor iterate from i = -1 to
439 * If it is a block, the entry -1 is NULL.
440 * Intern version for libFirm.
442 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
445 * Gets the mode of a node.
446 * Intern version for libFirm.
448 static INLINE ir_mode *
449 _get_irn_mode (const ir_node *node)
456 * Sets the mode of a node.
457 * Intern version of libFirm.
460 _set_irn_mode (ir_node *node, ir_mode *mode)
467 * Gets the visited counter of a node.
468 * Intern version for libFirm.
470 static INLINE unsigned long
471 _get_irn_visited (const ir_node *node)
474 return node->visited;
478 * Sets the visited counter of a node.
479 * Intern version for libFirm.
482 _set_irn_visited (ir_node *node, unsigned long visited)
485 node->visited = visited;
489 * Mark a node as visited in a graph.
490 * Intern version for libFirm.
493 _mark_irn_visited (ir_node *node) {
495 node->visited = current_ir_graph->visited;
499 * Returns non-zero if a node of was visited.
500 * Intern version for libFirm.
503 _irn_visited(const ir_node *node) {
505 return (node->visited >= current_ir_graph->visited);
509 * Returns non-zero if a node of was NOT visited.
510 * Intern version for libFirm.
513 _irn_not_visited(const ir_node *node) {
515 return (node->visited < current_ir_graph->visited);
519 * Sets the link of a node.
520 * Intern version of libFirm.
523 _set_irn_link(ir_node *node, void *link) {
525 /* Link field is used for Phi construction and various optimizations
527 assert(get_irg_phase_state(get_irn_irg(node)) != phase_building);
533 * Returns the link of a node.
534 * Intern version of libFirm.
537 _get_irn_link(const ir_node *node) {
538 assert (node && _is_ir_node(node));
543 * Returns whether the node _always_ must be pinned.
544 * I.e., the node is not floating after global cse.
546 * Intern version of libFirm.
548 static INLINE op_pin_state
549 _get_irn_pinned(const ir_node *node) {
551 assert(node && _is_ir_node(node));
553 state = _get_op_pinned(_get_irn_op(node));
555 if (state >= op_pin_state_exc_pinned)
556 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
560 static INLINE op_pin_state
561 _is_irn_pinned_in_irg(const ir_node *node) {
562 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
563 return get_irn_pinned(node);
564 return op_pin_state_pinned;
568 _is_unop(const ir_node *node) {
569 assert(node && _is_ir_node(node));
570 return (node->op->opar == oparity_unary);
574 _is_binop(const ir_node *node) {
575 assert(node && _is_ir_node(node));
576 return (node->op->opar == oparity_binary);
580 _is_Bad(const ir_node *node) {
582 return (node && _get_irn_op(node) == op_Bad);
586 _is_Const(const ir_node *node) {
588 return (node && _get_irn_op(node) == op_Const);
592 _is_Unknown (const ir_node *node) {
594 return (node && _get_irn_op(node) == op_Unknown);
598 _is_no_Block(const ir_node *node) {
599 assert(node && _is_ir_node(node));
600 return (_get_irn_op(node) != op_Block);
604 _is_Block(const ir_node *node) {
605 assert(node && _is_ir_node(node));
606 return (_get_irn_op(node) == op_Block);
610 _get_Block_n_cfgpreds (ir_node *node) {
611 assert(_is_Block(node));
612 return _get_irn_arity(node);
615 static INLINE ir_node *
616 _get_Block_cfgpred (ir_node *node, int pos) {
617 assert(0 <= pos && pos < get_irn_arity(node));
618 assert(_is_Block(node));
619 return _get_irn_n(node, pos);
622 /* Get the predecessor block.
624 * Returns the block corresponding to the predecessor pos.
626 * There are several ambiguities we resolve with this function:
627 * - The direct predecessor can be a Proj, which is not pinned.
628 * We walk from the predecessor to the next pinned node
629 * (skip_Proj) and return the block that node is in.
630 * - If we encounter the Bad node, this function does not return
631 * Start, but the Bad node.
633 static INLINE ir_node *
634 _get_Block_cfgpred_block(ir_node *node, int pos) {
635 ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
637 res = get_nodes_block(res);
641 static INLINE unsigned long
642 _get_Block_block_visited (ir_node *node) {
643 assert (node->op == op_Block);
644 return node->attr.block.block_visited;
648 _set_Block_block_visited (ir_node *node, unsigned long visit) {
649 assert (node->op == op_Block);
650 node->attr.block.block_visited = visit;
653 /* For this current_ir_graph must be set. */
655 _mark_Block_block_visited (ir_node *node) {
656 assert (node->op == op_Block);
657 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
661 _Block_not_block_visited(ir_node *node) {
662 assert (node->op == op_Block);
663 return (node->attr.block.block_visited < get_irg_block_visited(current_ir_graph));
666 static INLINE ir_node *
667 _set_Block_dead(ir_node *block) {
668 assert(_get_irn_op(block) == op_Block);
669 block->attr.block.dead = 1;
674 _is_Block_dead(const ir_node *block) {
675 ir_op * op = _get_irn_op(block);
680 assert(op == op_Block);
681 return block->attr.block.dead;
685 static INLINE tarval *_get_Const_tarval (ir_node *node) {
686 assert (_get_irn_op(node) == op_Const);
687 return node->attr.con.tv;
690 static INLINE cnst_classify_t _classify_Const(ir_node *node) {
692 assert(_is_ir_node(node));
694 op = _get_irn_op(node);
697 return classify_tarval(_get_Const_tarval(node));
698 else if(op == op_SymConst)
699 return CNST_SYMCONST;
701 return CNST_NO_CONST;
704 static INLINE int _is_irn_forking(const ir_node *node) {
705 return is_op_forking(_get_irn_op(node));
708 static INLINE ir_type *_get_irn_type(ir_node *node) {
709 return _get_irn_op(node)->ops.get_type(node);
712 static INLINE ir_type *_get_irn_type_attr(ir_node *node) {
713 return _get_irn_op(node)->ops.get_type_attr(node);
716 static INLINE entity *_get_irn_entity_attr(ir_node *node) {
717 return _get_irn_op(node)->ops.get_entity_attr(node);
720 static INLINE int _is_irn_constlike(const ir_node *node) {
721 return is_op_constlike(_get_irn_op(node));
724 static INLINE cond_jmp_predicate _get_Cond_jmp_pred(ir_node *node) {
725 assert (_get_irn_op(node) == op_Cond);
726 return node->attr.c.pred;
729 static INLINE void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
730 assert (_get_irn_op(node) == op_Cond);
731 node->attr.c.pred = pred;
734 /* this section MUST contain all inline functions */
735 #define is_ir_node(thing) _is_ir_node(thing)
736 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
737 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
738 #define get_irn_arity(node) _get_irn_arity(node)
739 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
740 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
741 #define get_irn_n(node, n) _get_irn_n(node, n)
742 #define get_irn_mode(node) _get_irn_mode(node)
743 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
744 #define get_irn_op(node) _get_irn_op(node)
745 #define get_irn_opcode(node) _get_irn_opcode(node)
746 #define get_irn_visited(node) _get_irn_visited(node)
747 #define set_irn_visited(node, v) _set_irn_visited(node, v)
748 #define mark_irn_visited(node) _mark_irn_visited(node)
749 #define irn_visited(node) _irn_visited(node)
750 #define irn_not_visited(node) _irn_not_visited(node)
751 #define set_irn_link(node, link) _set_irn_link(node, link)
752 #define get_irn_link(node) _get_irn_link(node)
753 #define get_irn_pinned(node) _get_irn_pinned(node)
754 #define is_irn_pinned_in_irg(node) _is_irn_pinned_in_irg(node)
755 #define is_unop(node) _is_unop(node)
756 #define is_binop(node) _is_binop(node)
757 #define is_Const(node) _is_Const(node)
758 #define is_Unknown(node) _is_Unknown(node)
759 #define is_Bad(node) _is_Bad(node)
760 #define is_no_Block(node) _is_no_Block(node)
761 #define is_Block(node) _is_Block(node)
762 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
763 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
764 #define get_Block_cfgpred_block(node, pos) _get_Block_cfgpred_block(node, pos)
765 #define get_Block_block_visited(node) _get_Block_block_visited(node)
766 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
767 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
768 #define Block_not_block_visited(node) _Block_not_block_visited(node)
769 #define set_Block_dead(block) _set_Block_dead(block)
770 #define is_Block_dead(block) _is_Block_dead(block)
771 #define get_Const_tarval(node) _get_Const_tarval(node)
772 #define classify_Const(node) _classify_Const(node)
773 #define is_irn_forking(node) _is_irn_forking(node)
774 #define get_irn_type(node) _get_irn_type(node)
775 #define get_irn_type_attr(node) _get_irn_type_attr(node)
776 #define get_irn_entity_attr(node) _get_irn_entity_attr(node)
777 #define is_irn_constlike(node) _is_irn_constlike(node)
778 #define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
779 #define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
781 # endif /* _IRNODE_T_H_ */