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. */
42 /** ir node attributes **/
44 /** Block attributes */
46 /* General attributes */
48 unsigned long block_visited; /**< for the walker that walks over all blocks. */
49 /* Attributes private to construction: */
50 int matured:1; /**< if set, all in-nodes of the block are fixed */
51 int dead:1; /**< if set, the block is dead (and could be replace by a Bad */
52 struct ir_node **graph_arr; /**< array to store all parameters */
53 /* Attributes holding analyses information */
54 struct dom_info dom; /**< Datastructure that holds information about dominators.
56 Eventually overlay with graph_arr as only valid
57 in different phases. Eventually inline the whole
59 /* exc_t exc; */ /**< role of this block for exception handling */
60 /* ir_node *handler_entry; */ /**< handler entry block iff this block is part of a region */
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 bitfield! */
66 int *cg_backedge; /**< Field n set to true if pred n is interprocedural backedge.
67 @@@ @todo Ev. replace by bitfield! */
70 /** Start attributes */
73 /* ir_graph *irg; @@@ now in block */
76 /** Cond attributes */
78 cond_kind kind; /**< flavor of Cond */
79 long default_proj; /**< for optimization: biggest Proj number, i.e. the one
83 /** Const attributes */
85 tarval *tv; /**< the target value */
86 type *tp; /**< the source type, for analyses. default: type_unknown. */
90 symconst_symbol sym; // old tori
92 type *tp; /**< the source type, for analyses. default: type_unknown. */
97 entity *ent; /**< entity to select */
100 /** Exception attributes */
102 op_pin_state pin_state; /**< the pin state for operations that might generate a exception:
103 If it's know that no exception will be generated, could be set to
104 op_pin_state_floats. */
105 #if PRECISE_EXC_CONTEXT
106 struct ir_node **frag_arr; /**< For Phi node construction in case of exception */
111 except_attr exc; /**< the exception attribute. MUST be the first one. */
112 type *cld_tp; /**< type of called procedure */
113 entity ** callee_arr; /**< result of callee analysis */
116 /** Alloc attributes */
118 except_attr exc; /**< the exception attribute. MUST be the first one. */
119 type *type; /**< Type of the allocated object. */
120 where_alloc where; /**< stack, heap or other managed part of memory */
123 /** Free attributes */
125 type *type; /**< Type of the allocated object. */
126 where_alloc where; /**< stack, heap or other managed part of memory */
129 /** InstOf attributes */
136 /** Filter attributes */
138 long proj; /**< contains the result position to project (Proj) */
139 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
140 int *backedge; /**< Field n set to true if pred n is backedge.
141 @todo Ev. replace by bitfield! */
144 /** EndReg/EndExcept attributes */
149 /** CallBegin attributes */
151 ir_node * call; /**< associated Call-operation */
154 /** Cast attributes */
159 /** Load attributes */
161 except_attr exc; /**< the exception attribute. MUST be the first one. */
162 ir_mode *load_mode; /**< the mode of this Load operation */
163 ent_volatility volatility; /**< the volatility of a Load/Store operation */
166 /** Store attributes */
168 except_attr exc; /**< the exception attribute. MUST be the first one. */
169 ent_volatility volatility; /**< the volatility of a Store operation */
172 typedef pn_Cmp confirm_attr; /**< Attribute to hold compare operation */
175 * Edge info to put into an irn.
177 typedef struct _irn_edge_info_t {
178 struct list_head outs_head; /**< The list of all outs */
179 int out_count; /**< number of outs in the list */
183 /** Some irnodes just have one attribute, these are stored here,
184 some have more. Their name is 'irnodename_attr' */
186 start_attr start; /**< For Start */
187 block_attr block; /**< For Block: Fields needed to construct it */
188 cond_attr c; /**< For Cond. */
189 const_attr con; /**< For Const: contains the value of the constant and a type */
190 symconst_attr i; /**< For SymConst. */
191 sel_attr s; /**< For Sel. */
192 call_attr call; /**< For Call: pointer to the type of the method to call */
193 callbegin_attr callbegin; /**< For CallBegin */
194 alloc_attr a; /**< For Alloc. */
195 free_attr f; /**< For Free. */
196 io_attr io; /**< For InstOf */
197 cast_attr cast; /**< For Cast. */
198 load_attr load; /**< For Load. */
199 store_attr store; /**< For Store. */
200 int phi0_pos; /**< For Phi. Used to remember the value defined by
201 this Phi node. Needed when the Phi is completed
202 to call get_r_internal_value to find the
203 predecessors. If this attribute is set, the Phi
204 node takes the role of the obsolete Phi0 node,
205 therefore the name. */
206 int *phi_backedge; /**< For Phi after construction.
207 Field n set to true if pred n is backedge.
208 @todo Ev. replace by bitfield! */
209 long proj; /**< For Proj: contains the result position to project */
210 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
211 filter_attr filter; /**< For Filter */
212 end_attr end; /**< For EndReg, EndExcept */
213 except_attr except; /**< For Phi node construction in case of exceptions */
217 /** common structure of an irnode
218 if the node has some attributes, they are stored in attr */
220 /* ------- Basics of the representation ------- */
221 firm_kind kind; /**< distinguishes this node from others */
222 ir_op *op; /**< Opcode of this node. */
223 ir_mode *mode; /**< Mode of this node. */
224 unsigned long visited; /**< visited counter for walks of the graph */
225 struct ir_node **in; /**< array with predecessors / operands */
226 void *link; /**< to attach additional information to the node, e.g.
227 used while construction to link Phi0 nodes and
228 during optimization to link to nodes that
229 shall replace a node. */
230 /* ------- Fields for optimizations / analysis information ------- */
231 struct ir_node **out; /**< @deprecated array of out edges. */
232 struct dbg_info* dbi; /**< A pointer to information for debug support. */
233 /* ------- For debugging ------- */
236 int node_nr; /**< a unique node number for each node to make output
239 /* ------- For analyses -------- */
240 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
241 #ifdef DO_HEAPANALYSIS
245 #if FIRM_EDGES_INPLACE
246 irn_edge_info_t edge_info; /**< everlasting out edges */
248 /* ------- Opcode depending fields -------- */
249 attr attr; /**< attribute of this node. Depends on opcode.
250 Must be last field of struct ir_node. */
254 /** Returns the array with the ins. The content of the array may not be
256 ir_node **get_irn_in (const ir_node *node);
259 /** access attributes directly */
260 const_attr get_irn_const_attr (ir_node *node);
261 long get_irn_proj_attr (ir_node *node);
262 alloc_attr get_irn_alloc_attr (ir_node *node);
263 free_attr get_irn_free_attr (ir_node *node);
264 symconst_attr get_irn_symconst_attr (ir_node *node);
265 type *get_irn_call_attr (ir_node *node);
266 type *get_irn_funccall_attr (ir_node *node);
267 sel_attr get_irn_sel_attr (ir_node *node);
268 int get_irn_phi_attr (ir_node *node);
269 block_attr get_irn_block_attr (ir_node *node);
270 load_attr get_irn_load_attr (ir_node *node);
271 store_attr get_irn_store_attr (ir_node *node);
272 except_attr get_irn_except_attr (ir_node *node);
276 * The amount of additional space for custom data to be allocated upon creating a new node.
278 extern unsigned firm_add_node_size;
280 /** Set the get_type operation of an ir_op. */
281 ir_op *firm_set_default_get_type(ir_op *op);
283 /*-------------------------------------------------------------------*/
284 /* These function are most used in libfirm. Give them as static */
285 /* functions so they can be inlined. */
286 /*-------------------------------------------------------------------*/
289 * Checks whether a pointer points to a ir node.
290 * Intern version for libFirm.
293 _is_ir_node (const void *thing) {
294 return (get_kind(thing) == k_ir_node);
298 * Gets the op of a node.
299 * Intern version for libFirm.
301 static INLINE ir_op *
302 _get_irn_op (const ir_node *node) {
307 /** Copies all attributes stored in the old node to the new node.
308 Assumes both have the same opcode and sufficient size. */
310 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
311 ir_op *op = _get_irn_op(old_node);
313 /* must always exist */
314 op->copy_attr(old_node, new_node);
318 * Gets the opcode of a node.
319 * Intern version for libFirm.
322 _get_irn_opcode (const ir_node *node) {
323 assert (k_ir_node == get_kind(node));
325 return node->op->code;
329 * Returns the number of predecessors without the block predecessor.
330 * Intern version for libFirm.
333 _get_irn_intra_arity (const ir_node *node) {
335 return ARR_LEN(node->in) - 1;
339 * Returns the number of predecessors without the block predecessor.
340 * Intern version for libFirm.
343 _get_irn_inter_arity (const ir_node *node) {
345 if (_get_irn_opcode(node) == iro_Filter) {
346 assert(node->attr.filter.in_cg);
347 return ARR_LEN(node->attr.filter.in_cg) - 1;
348 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
349 return ARR_LEN(node->attr.block.in_cg) - 1;
351 return _get_irn_intra_arity(node);
355 * Returns the number of predecessors without the block predecessor.
356 * Intern version for libFirm.
358 extern int (*_get_irn_arity)(const ir_node *node);
361 * Intern version for libFirm.
363 static INLINE ir_node *
364 _get_irn_intra_n (const ir_node *node, int n) {
365 assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
367 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
371 * Intern version for libFirm.
373 static INLINE ir_node*
374 _get_irn_inter_n (const ir_node *node, int n) {
375 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
377 /* handle Filter and Block specially */
378 if (_get_irn_opcode(node) == iro_Filter) {
379 assert(node->attr.filter.in_cg);
380 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
381 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
382 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
385 return _get_irn_intra_n (node, n);
389 * Access to the predecessors of a node.
390 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
391 * to iterate including the Block predecessor iterate from i = -1 to
393 * If it is a block, the entry -1 is NULL.
394 * Intern version for libFirm.
396 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
399 * Gets the mode of a node.
400 * Intern version for libFirm.
402 static INLINE ir_mode *
403 _get_irn_mode (const ir_node *node)
410 * Sets the mode of a node.
411 * Intern version of libFirm.
414 _set_irn_mode (ir_node *node, ir_mode *mode)
421 * Gets the visited counter of a node.
422 * Intern version for libFirm.
424 static INLINE unsigned long
425 _get_irn_visited (const ir_node *node)
428 return node->visited;
432 * Sets the visited counter of a node.
433 * Intern version for libFirm.
436 _set_irn_visited (ir_node *node, unsigned long visited)
439 node->visited = visited;
443 * Mark a node as visited in a graph.
444 * Intern version for libFirm.
447 _mark_irn_visited (ir_node *node) {
449 node->visited = current_ir_graph->visited;
453 * Returns non-zero if a node of was visited.
454 * Intern version for libFirm.
457 _irn_visited(const ir_node *node) {
459 return (node->visited >= current_ir_graph->visited);
463 * Returns non-zero if a node of was NOT visited.
464 * Intern version for libFirm.
467 _irn_not_visited(const ir_node *node) {
469 return (node->visited < current_ir_graph->visited);
473 * Sets the link of a node.
474 * Intern version of libFirm.
477 _set_irn_link(ir_node *node, void *link) {
479 /* Link field is used for Phi construction and various optimizations
481 assert(get_irg_phase_state(current_ir_graph) != phase_building);
487 * Returns the link of a node.
488 * Intern version of libFirm.
491 _get_irn_link(const ir_node *node) {
492 assert (node && _is_ir_node(node));
497 * Returns the pinned state of a node.
498 * Intern version of libFirm.
500 static INLINE op_pin_state
501 _get_irn_pinned(const ir_node *node) {
503 assert(node && _is_ir_node(node));
504 state = __get_op_pinned(_get_irn_op(node));
505 if (state >= op_pin_state_exc_pinned)
506 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
511 _is_unop(const ir_node *node) {
512 assert(node && _is_ir_node(node));
513 return (node->op->opar == oparity_unary);
517 _is_binop(const ir_node *node) {
518 assert(node && _is_ir_node(node));
519 return (node->op->opar == oparity_binary);
523 _is_Bad(const ir_node *node) {
525 return (node && _get_irn_op(node) == op_Bad);
529 _is_Const(const ir_node *node) {
531 return (node && _get_irn_op(node) == op_Const);
535 _is_no_Block(const ir_node *node) {
536 assert(node && _is_ir_node(node));
537 return (_get_irn_op(node) != op_Block);
541 _is_Block(const ir_node *node) {
542 assert(node && _is_ir_node(node));
543 return (_get_irn_op(node) == op_Block);
546 static INLINE unsigned long
547 _get_Block_block_visited (ir_node *node) {
548 assert (node->op == op_Block);
549 return node->attr.block.block_visited;
553 _set_Block_block_visited (ir_node *node, unsigned long visit) {
554 assert (node->op == op_Block);
555 node->attr.block.block_visited = visit;
558 /* For this current_ir_graph must be set. */
560 _mark_Block_block_visited (ir_node *node) {
561 assert (node->op == op_Block);
562 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
566 _Block_not_block_visited(ir_node *node) {
567 assert (node->op == op_Block);
568 return (node->attr.block.block_visited < get_irg_block_visited(current_ir_graph));
571 static INLINE ir_node *
572 _set_Block_dead(ir_node *block) {
573 assert(_get_irn_op(block) == op_Block);
574 block->attr.block.dead = 1;
579 _is_Block_dead(const ir_node *block) {
580 ir_op * op = _get_irn_op(block);
585 assert(op == op_Block);
586 return block->attr.block.dead;
590 static INLINE tarval *_get_Const_tarval (ir_node *node) {
591 assert (_get_irn_op(node) == op_Const);
592 return node->attr.con.tv;
595 static INLINE cnst_classify_t _classify_Const(ir_node *node) {
597 assert(_is_ir_node(node));
599 op = _get_irn_op(node);
602 return classify_tarval(_get_Const_tarval(node));
603 else if(op == op_SymConst)
604 return CNST_SYMCONST;
606 return CNST_NO_CONST;
609 static INLINE type *_get_irn_type(ir_node *node) {
610 return _get_irn_op(node)->get_type(node);
613 /* this section MUST contain all inline functions */
614 #define is_ir_node(thing) _is_ir_node(thing)
615 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
616 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
617 #define get_irn_arity(node) _get_irn_arity(node)
618 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
619 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
620 #define get_irn_n(node, n) _get_irn_n(node, n)
621 #define get_irn_mode(node) _get_irn_mode(node)
622 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
623 #define get_irn_op(node) _get_irn_op(node)
624 #define get_irn_opcode(node) _get_irn_opcode(node)
625 #define get_irn_visited(node) _get_irn_visited(node)
626 #define set_irn_visited(node, v) _set_irn_visited(node, v)
627 #define mark_irn_visited(node) _mark_irn_visited(node)
628 #define irn_visited(node) _irn_visited(node)
629 #define irn_not_visited(node) _irn_not_visited(node)
630 #define set_irn_link(node, link) _set_irn_link(node, link)
631 #define get_irn_link(node) _get_irn_link(node)
632 #define is_unop(node) _is_unop(node)
633 #define is_binop(node) _is_binop(node)
634 #define is_Const(node) _is_Const(node)
635 #define is_Bad(node) _is_Bad(node)
636 #define is_no_Block(node) _is_no_Block(node)
637 #define is_Block(node) _is_Block(node)
638 #define get_Block_block_visited(node) _get_Block_block_visited(node)
639 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
640 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
641 #define Block_not_block_visited(node) _Block_not_block_visited(node)
642 #define set_Block_dead(block) _set_Block_dead(block)
643 #define is_Block_dead(block) _is_Block_dead(block)
644 #define get_Const_tarval(node) _get_Const_tarval(node)
645 #define classify_Const(node) _classify_Const(node)
646 #define get_irn_type(node) _get_irn_type(node)
648 # endif /* _IRNODE_T_H_ */