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 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 */
71 struct list_head succ_head; /**< A list head for all successor edges of a block. */
75 /** Start attributes */
78 /* ir_graph *irg; @@@ now in block */
81 /** Cond attributes */
83 cond_kind kind; /**< flavor of Cond */
84 long default_proj; /**< only for non-binary Conds: biggest Proj number, i.e. the one used for default. */
85 cond_jmp_predicate pred; /**< only for binary Conds: The jump predication. */
88 /** Const attributes */
90 tarval *tv; /**< the target value */
91 type *tp; /**< the source type, for analyses. default: type_unknown. */
95 symconst_symbol sym; // old tori
97 type *tp; /**< the source type, for analyses. default: type_unknown. */
100 /** Sel attributes */
102 entity *ent; /**< entity to select */
105 /** Exception attributes */
107 op_pin_state pin_state; /**< the pin state for operations that might generate a exception:
108 If it's know that no exception will be generated, could be set to
109 op_pin_state_floats. */
110 #if PRECISE_EXC_CONTEXT
111 struct ir_node **frag_arr; /**< For Phi node construction in case of exception */
116 except_attr exc; /**< the exception attribute. MUST be the first one. */
117 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 type *type; /**< Type of the allocated object. */
125 where_alloc where; /**< stack, heap or other managed part of memory */
128 /** Free attributes */
130 type *type; /**< Type of the allocated object. */
131 where_alloc where; /**< stack, heap or other managed part of memory */
134 /** InstOf attributes */
141 /** Filter attributes */
143 long proj; /**< contains the result position to project (Proj) */
144 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
145 int *backedge; /**< Field n set to true if pred n is backedge.
146 @todo Ev. replace by bitfield! */
149 /** EndReg/EndExcept attributes */
154 /** CallBegin attributes */
156 ir_node * call; /**< associated Call-operation */
159 /** Cast attributes */
161 type *totype; /**< type of the casted node */
164 /** Load attributes */
166 except_attr exc; /**< the exception attribute. MUST be the first one. */
167 ir_mode *load_mode; /**< the mode of this Load operation */
168 ent_volatility volatility; /**< the volatility of a Load/Store operation */
171 /** Store attributes */
173 except_attr exc; /**< the exception attribute. MUST be the first one. */
174 ent_volatility volatility; /**< the volatility of a Store operation */
177 typedef pn_Cmp confirm_attr; /**< Attribute to hold compare operation */
180 except_attr exc; /**< the exception attribute. MUST be the first one. */
181 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 unsigned long visited; /**< visited counter for walks of the graph */
236 struct ir_node **in; /**< array with predecessors / operands */
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
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 type *get_irn_call_attr (ir_node *node);
277 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);
302 /*-------------------------------------------------------------------*/
303 /* These function are most used in libfirm. Give them as static */
304 /* functions so they can be inlined. */
305 /*-------------------------------------------------------------------*/
308 * Checks whether a pointer points to a ir node.
309 * Intern version for libFirm.
312 _is_ir_node (const void *thing) {
313 return (get_kind(thing) == k_ir_node);
317 * Gets the op of a node.
318 * Intern version for libFirm.
320 static INLINE ir_op *
321 _get_irn_op (const ir_node *node) {
326 /** Copies all attributes stored in the old node to the new node.
327 Assumes both have the same opcode and sufficient size. */
329 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
330 ir_op *op = _get_irn_op(old_node);
332 /* must always exist */
333 op->ops.copy_attr(old_node, new_node);
337 * Gets the opcode of a node.
338 * Intern version for libFirm.
341 _get_irn_opcode (const ir_node *node) {
342 assert (k_ir_node == get_kind(node));
344 return node->op->code;
348 * Returns the number of predecessors without the block predecessor.
349 * Intern version for libFirm.
352 _get_irn_intra_arity (const ir_node *node) {
354 return ARR_LEN(node->in) - 1;
358 * Returns the number of predecessors without the block predecessor.
359 * Intern version for libFirm.
362 _get_irn_inter_arity (const ir_node *node) {
364 if (_get_irn_opcode(node) == iro_Filter) {
365 assert(node->attr.filter.in_cg);
366 return ARR_LEN(node->attr.filter.in_cg) - 1;
367 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
368 return ARR_LEN(node->attr.block.in_cg) - 1;
370 return _get_irn_intra_arity(node);
374 * Returns the number of predecessors without the block predecessor.
375 * Intern version for libFirm.
377 extern int (*_get_irn_arity)(const ir_node *node);
380 * Intern version for libFirm.
382 static INLINE ir_node *
383 _get_irn_intra_n (const ir_node *node, int n) {
384 assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
386 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
390 * Intern version for libFirm.
392 static INLINE ir_node*
393 _get_irn_inter_n (const ir_node *node, int n) {
394 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
396 /* handle Filter and Block specially */
397 if (_get_irn_op(node) == op_Filter) {
398 assert(node->attr.filter.in_cg);
399 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
400 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
401 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
404 return _get_irn_intra_n (node, n);
408 * Access to the predecessors of a node.
409 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
410 * to iterate including the Block predecessor iterate from i = -1 to
412 * If it is a block, the entry -1 is NULL.
413 * Intern version for libFirm.
415 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
418 * Gets the mode of a node.
419 * Intern version for libFirm.
421 static INLINE ir_mode *
422 _get_irn_mode (const ir_node *node)
429 * Sets the mode of a node.
430 * Intern version of libFirm.
433 _set_irn_mode (ir_node *node, ir_mode *mode)
440 * Gets the visited counter of a node.
441 * Intern version for libFirm.
443 static INLINE unsigned long
444 _get_irn_visited (const ir_node *node)
447 return node->visited;
451 * Sets the visited counter of a node.
452 * Intern version for libFirm.
455 _set_irn_visited (ir_node *node, unsigned long visited)
458 node->visited = visited;
462 * Mark a node as visited in a graph.
463 * Intern version for libFirm.
466 _mark_irn_visited (ir_node *node) {
468 node->visited = current_ir_graph->visited;
472 * Returns non-zero if a node of was visited.
473 * Intern version for libFirm.
476 _irn_visited(const ir_node *node) {
478 return (node->visited >= current_ir_graph->visited);
482 * Returns non-zero if a node of was NOT visited.
483 * Intern version for libFirm.
486 _irn_not_visited(const ir_node *node) {
488 return (node->visited < current_ir_graph->visited);
492 * Sets the link of a node.
493 * Intern version of libFirm.
496 _set_irn_link(ir_node *node, void *link) {
498 /* Link field is used for Phi construction and various optimizations
500 assert(get_irg_phase_state(get_irn_irg(node)) != phase_building);
506 * Returns the link of a node.
507 * Intern version of libFirm.
510 _get_irn_link(const ir_node *node) {
511 assert (node && _is_ir_node(node));
516 * Returns whether the node _always_ must be pinned.
517 * I.e., the node is not floating after global cse.
519 * Intern version of libFirm.
521 static INLINE op_pin_state
522 _get_irn_pinned(const ir_node *node) {
524 assert(node && _is_ir_node(node));
526 state = _get_op_pinned(_get_irn_op(node));
528 if (state >= op_pin_state_exc_pinned)
529 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
533 static INLINE op_pin_state
534 _is_irn_pinned_in_irg(const ir_node *node) {
535 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
536 return get_irn_pinned(node);
537 return op_pin_state_pinned;
541 _is_unop(const ir_node *node) {
542 assert(node && _is_ir_node(node));
543 return (node->op->opar == oparity_unary);
547 _is_binop(const ir_node *node) {
548 assert(node && _is_ir_node(node));
549 return (node->op->opar == oparity_binary);
553 _is_Bad(const ir_node *node) {
555 return (node && _get_irn_op(node) == op_Bad);
559 _is_Const(const ir_node *node) {
561 return (node && _get_irn_op(node) == op_Const);
565 _is_Unknown (const ir_node *node) {
567 return (node && _get_irn_op(node) == op_Unknown);
571 _is_no_Block(const ir_node *node) {
572 assert(node && _is_ir_node(node));
573 return (_get_irn_op(node) != op_Block);
577 _is_Block(const ir_node *node) {
578 assert(node && _is_ir_node(node));
579 return (_get_irn_op(node) == op_Block);
583 _get_Block_n_cfgpreds (ir_node *node) {
584 assert(_is_Block(node));
585 return _get_irn_arity(node);
588 static INLINE ir_node *
589 _get_Block_cfgpred (ir_node *node, int pos) {
590 assert(0 <= pos && pos < get_irn_arity(node));
591 assert(_is_Block(node));
592 return _get_irn_n(node, pos);
595 /* Get the predecessor block.
597 * Returns the block corresponding to the predecessor pos.
599 * There are several ambiguities we resolve with this function:
600 * - The direct predecessor can be a Proj, which is not pinned.
601 * We walk from the predecessor to the next pinned node
602 * (skip_Proj) and return the block that node is in.
603 * - If we encounter the Bad node, this function does not return
604 * Start, but the Bad node.
606 static INLINE ir_node *
607 _get_Block_cfgpred_block(ir_node *node, int pos) {
608 ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
610 res = get_nodes_block(res);
614 static INLINE unsigned long
615 _get_Block_block_visited (ir_node *node) {
616 assert (node->op == op_Block);
617 return node->attr.block.block_visited;
621 _set_Block_block_visited (ir_node *node, unsigned long visit) {
622 assert (node->op == op_Block);
623 node->attr.block.block_visited = visit;
626 /* For this current_ir_graph must be set. */
628 _mark_Block_block_visited (ir_node *node) {
629 assert (node->op == op_Block);
630 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
634 _Block_not_block_visited(ir_node *node) {
635 assert (node->op == op_Block);
636 return (node->attr.block.block_visited < get_irg_block_visited(current_ir_graph));
639 static INLINE ir_node *
640 _set_Block_dead(ir_node *block) {
641 assert(_get_irn_op(block) == op_Block);
642 block->attr.block.dead = 1;
647 _is_Block_dead(const ir_node *block) {
648 ir_op * op = _get_irn_op(block);
653 assert(op == op_Block);
654 return block->attr.block.dead;
658 static INLINE tarval *_get_Const_tarval (ir_node *node) {
659 assert (_get_irn_op(node) == op_Const);
660 return node->attr.con.tv;
663 static INLINE cnst_classify_t _classify_Const(ir_node *node) {
665 assert(_is_ir_node(node));
667 op = _get_irn_op(node);
670 return classify_tarval(_get_Const_tarval(node));
671 else if(op == op_SymConst)
672 return CNST_SYMCONST;
674 return CNST_NO_CONST;
677 static INLINE int _is_irn_forking(const ir_node *node) {
678 return is_op_forking(_get_irn_op(node));
681 static INLINE type *_get_irn_type(ir_node *node) {
682 return _get_irn_op(node)->ops.get_type(node);
685 static INLINE int _is_irn_constlike(const ir_node *node) {
686 return is_op_constlike(_get_irn_op(node));
689 static INLINE cond_jmp_predicate _get_Cond_jmp_pred(ir_node *node) {
690 assert (_get_irn_op(node) == op_Cond);
691 return node->attr.c.pred;
694 static INLINE void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
695 assert (_get_irn_op(node) == op_Cond);
696 node->attr.c.pred = pred;
699 /* this section MUST contain all inline functions */
700 #define is_ir_node(thing) _is_ir_node(thing)
701 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
702 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
703 #define get_irn_arity(node) _get_irn_arity(node)
704 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
705 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
706 #define get_irn_n(node, n) _get_irn_n(node, n)
707 #define get_irn_mode(node) _get_irn_mode(node)
708 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
709 #define get_irn_op(node) _get_irn_op(node)
710 #define get_irn_opcode(node) _get_irn_opcode(node)
711 #define get_irn_visited(node) _get_irn_visited(node)
712 #define set_irn_visited(node, v) _set_irn_visited(node, v)
713 #define mark_irn_visited(node) _mark_irn_visited(node)
714 #define irn_visited(node) _irn_visited(node)
715 #define irn_not_visited(node) _irn_not_visited(node)
716 #define set_irn_link(node, link) _set_irn_link(node, link)
717 #define get_irn_link(node) _get_irn_link(node)
718 #define get_irn_pinned(node) _get_irn_pinned(node)
719 #define is_irn_pinned_in_irg(node) _is_irn_pinned_in_irg(node)
720 #define is_unop(node) _is_unop(node)
721 #define is_binop(node) _is_binop(node)
722 #define is_Const(node) _is_Const(node)
723 #define is_Unknown(node) _is_Unknown(node)
724 #define is_Bad(node) _is_Bad(node)
725 #define is_no_Block(node) _is_no_Block(node)
726 #define is_Block(node) _is_Block(node)
727 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
728 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
729 #define get_Block_cfgpred_block(node, pos) _get_Block_cfgpred_block(node, pos)
730 #define get_Block_block_visited(node) _get_Block_block_visited(node)
731 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
732 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
733 #define Block_not_block_visited(node) _Block_not_block_visited(node)
734 #define set_Block_dead(block) _set_Block_dead(block)
735 #define is_Block_dead(block) _is_Block_dead(block)
736 #define get_Const_tarval(node) _get_Const_tarval(node)
737 #define classify_Const(node) _classify_Const(node)
738 #define is_irn_forking(node) _is_irn_forking(node)
739 #define get_irn_type(node) _get_irn_type(node)
740 #define is_irn_constlike(node) _is_irn_constlike(node)
741 #define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
742 #define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
744 # endif /* _IRNODE_T_H_ */