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. */
41 #define FIRM_EDGES_INPLACE 1
44 /** ir node attributes **/
46 /** Block attributes */
48 /* General attributes */
50 unsigned long block_visited; /**< for the walker that walks over all blocks. */
51 /* Attributes private to construction: */
52 int matured:1; /**< if set, all in-nodes of the block are fixed */
53 int dead:1; /**< if set, the block is dead (and could be replace by a Bad */
54 struct ir_node **graph_arr; /**< array to store all parameters */
55 /* Attributes holding analyses information */
56 struct dom_info dom; /**< Datastructure that holds information about dominators.
58 Eventually overlay with graph_arr as only valid
59 in different phases. Eventually inline the whole
61 /* exc_t exc; */ /**< role of this block for exception handling */
62 /* ir_node *handler_entry; */ /**< handler entry block iff this block is part of a region */
63 ir_node ** in_cg; /**< array with predecessors in
64 * interprocedural_view, if they differ
65 * from intraprocedural predecessors */
66 int *backedge; /**< Field n set to true if pred n is backedge.
67 @@@ @todo Ev. replace by bitfield! */
68 int *cg_backedge; /**< Field n set to true if pred n is interprocedural backedge.
69 @@@ @todo Ev. replace by bitfield! */
72 /** Start attributes */
75 /* ir_graph *irg; @@@ now in block */
78 /** Cond attributes */
80 cond_kind kind; /**< flavor of Cond */
81 long default_proj; /**< for optimization: biggest Proj number, i.e. the one
85 /** Const attributes */
87 tarval *tv; /**< the target value */
88 type *tp; /**< the source type, for analyses. default: type_unknown. */
92 symconst_symbol sym; // old tori
94 type *tp; /**< the source type, for analyses. default: type_unknown. */
99 entity *ent; /**< entity to select */
102 /** Exception attributes */
104 op_pin_state pin_state; /**< the pin state for operations that might generate a exception:
105 If it's know that no exception will be generated, could be set to
106 op_pin_state_floats. */
107 #if PRECISE_EXC_CONTEXT
108 struct ir_node **frag_arr; /**< For Phi node construction in case of exception */
113 except_attr exc; /**< the exception attribute. MUST be the first one. */
114 type *cld_tp; /**< type of called procedure */
115 entity ** callee_arr; /**< result of callee analysis */
118 /** Alloc attributes */
120 except_attr exc; /**< the exception attribute. MUST be the first one. */
121 type *type; /**< Type of the allocated object. */
122 where_alloc where; /**< stack, heap or other managed part of memory */
125 /** Free attributes */
127 type *type; /**< Type of the allocated object. */
128 where_alloc where; /**< stack, heap or other managed part of memory */
131 /** InstOf attributes */
138 /** Filter attributes */
140 long proj; /**< contains the result position to project (Proj) */
141 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
142 int *backedge; /**< Field n set to true if pred n is backedge.
143 @todo Ev. replace by bitfield! */
146 /** EndReg/EndExcept attributes */
151 /** CallBegin attributes */
153 ir_node * call; /**< associated Call-operation */
156 /** Cast attributes */
161 /** Load attributes */
163 except_attr exc; /**< the exception attribute. MUST be the first one. */
164 ir_mode *load_mode; /**< the mode of this Load operation */
165 ent_volatility volatility; /**< the volatility of a Load/Store operation */
168 /** Store attributes */
170 except_attr exc; /**< the exception attribute. MUST be the first one. */
171 ent_volatility volatility; /**< the volatility of a Store operation */
174 typedef pn_Cmp confirm_attr; /** Attribute to hold compare operation */
177 * Edge info to put into an irn.
179 typedef struct _irn_edge_info_t {
180 struct list_head outs_head;
185 /** Some irnodes just have one attribute, these are stored here,
186 some have more. Their name is 'irnodename_attr' */
188 start_attr start; /**< For Start */
189 block_attr block; /**< For Block: Fields needed to construct it */
190 cond_attr c; /**< For Cond. */
191 const_attr con; /**< For Const: contains the value of the constant and a type */
192 symconst_attr i; /**< For SymConst. */
193 sel_attr s; /**< For Sel. */
194 call_attr call; /**< For Call: pointer to the type of the method to call */
195 callbegin_attr callbegin; /**< For CallBegin */
196 alloc_attr a; /**< For Alloc. */
197 free_attr f; /**< For Free. */
198 io_attr io; /**< For InstOf */
199 cast_attr cast; /**< For Cast. */
200 load_attr load; /**< For Load. */
201 store_attr store; /**< For Store. */
202 int phi0_pos; /**< For Phi. Used to remember the value defined by
203 this Phi node. Needed when the Phi is completed
204 to call get_r_internal_value to find the
205 predecessors. If this attribute is set, the Phi
206 node takes the role of the obsolete Phi0 node,
207 therefore the name. */
208 int *phi_backedge; /**< For Phi after construction.
209 Field n set to true if pred n is backedge.
210 @todo Ev. replace by bitfield! */
211 long proj; /**< For Proj: contains the result position to project */
212 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
213 filter_attr filter; /**< For Filter */
214 end_attr end; /**< For EndReg, EndExcept */
215 except_attr except; /**< For Phi node construction in case of exceptions */
219 /** common structure of an irnode
220 if the node has some attributes, they are stored in attr */
222 /* ------- Basics of the representation ------- */
223 firm_kind kind; /**< distinguishes this node from others */
224 ir_op *op; /**< Opcode of this node. */
225 ir_mode *mode; /**< Mode of this node. */
226 unsigned long visited; /**< visited counter for walks of the graph */
227 struct ir_node **in; /**< array with predecessors / operands */
228 void *link; /**< to attach additional information to the node, e.g.
229 used while construction to link Phi0 nodes and
230 during optimization to link to nodes that
231 shall replace a node. */
232 /* ------- Fields for optimizations / analysis information ------- */
233 struct ir_node **out; /**< @deprecated array of out edges. */
234 struct dbg_info* dbi; /**< A pointer to information for debug support. */
235 /* ------- For debugging ------- */
238 int node_nr; /**< a unique node number for each node to make output
241 /* ------- For analyses -------- */
242 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
243 #ifdef DO_HEAPANALYSIS
247 #ifdef FIRM_EDGES_INPLACE
248 irn_edge_info_t edge_info;
250 /* ------- Opcode depending fields -------- */
251 attr attr; /**< attribute of this node. Depends on opcode.
252 Must be last field of struct ir_node. */
256 /** Returns the array with the ins. The content of the array may not be
258 ir_node **get_irn_in (const ir_node *node);
261 /** access attributes directly */
262 const_attr get_irn_const_attr (ir_node *node);
263 long get_irn_proj_attr (ir_node *node);
264 alloc_attr get_irn_alloc_attr (ir_node *node);
265 free_attr get_irn_free_attr (ir_node *node);
266 symconst_attr get_irn_symconst_attr (ir_node *node);
267 type *get_irn_call_attr (ir_node *node);
268 type *get_irn_funccall_attr (ir_node *node);
269 sel_attr get_irn_sel_attr (ir_node *node);
270 int get_irn_phi_attr (ir_node *node);
271 block_attr get_irn_block_attr (ir_node *node);
272 load_attr get_irn_load_attr (ir_node *node);
273 store_attr get_irn_store_attr (ir_node *node);
274 except_attr get_irn_except_attr (ir_node *node);
278 * The amount of additional space for custom data to be allocated upon creating a new node.
280 extern unsigned firm_add_node_size;
282 /*-------------------------------------------------------------------*/
283 /* These function are most used in libfirm. Give them as static */
284 /* functions so they can be inlined. */
285 /*-------------------------------------------------------------------*/
288 * Checks whether a pointer points to a ir node.
289 * Intern version for libFirm.
292 _is_ir_node (const void *thing) {
293 return (get_kind(thing) == k_ir_node);
297 * Gets the op of a node.
298 * Intern version for libFirm.
300 static INLINE ir_op *
301 _get_irn_op (const ir_node *node) {
306 /** Copies all attributes stored in the old node to the new node.
307 Assumes both have the same opcode and sufficient size. */
309 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
310 ir_op *op = _get_irn_op(old_node);
312 /* must always exist */
313 op->copy_attr(old_node, new_node);
317 * Gets the opcode of a node.
318 * Intern version for libFirm.
321 _get_irn_opcode (const ir_node *node) {
322 assert (k_ir_node == get_kind(node));
324 return node->op->code;
328 * Returns the number of predecessors without the block predecessor.
329 * Intern version for libFirm.
332 _get_irn_intra_arity (const ir_node *node) {
334 return ARR_LEN(node->in) - 1;
338 * Returns the number of predecessors without the block predecessor.
339 * Intern version for libFirm.
342 _get_irn_inter_arity (const ir_node *node) {
344 if (_get_irn_opcode(node) == iro_Filter) {
345 assert(node->attr.filter.in_cg);
346 return ARR_LEN(node->attr.filter.in_cg) - 1;
347 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
348 return ARR_LEN(node->attr.block.in_cg) - 1;
350 return _get_irn_intra_arity(node);
354 * Returns the number of predecessors without the block predecessor.
355 * Intern version for libFirm.
357 extern int (*_get_irn_arity)(const ir_node *node);
360 * Intern version for libFirm.
362 static INLINE ir_node *
363 _get_irn_intra_n (const ir_node *node, int n) {
364 assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
366 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
370 * Intern version for libFirm.
372 static INLINE ir_node*
373 _get_irn_inter_n (const ir_node *node, int n) {
374 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
376 /* handle Filter and Block specially */
377 if (_get_irn_opcode(node) == iro_Filter) {
378 assert(node->attr.filter.in_cg);
379 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
380 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
381 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
384 return _get_irn_intra_n (node, n);
388 * Access to the predecessors of a node.
389 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
390 * to iterate including the Block predecessor iterate from i = -1 to
392 * If it is a block, the entry -1 is NULL.
393 * Intern version for libFirm.
395 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
398 * Gets the mode of a node.
399 * Intern version for libFirm.
401 static INLINE ir_mode *
402 _get_irn_mode (const ir_node *node)
409 * Sets the mode of a node.
410 * Intern version of libFirm.
413 _set_irn_mode (ir_node *node, ir_mode *mode)
420 * Gets the visited counter of a node.
421 * Intern version for libFirm.
423 static INLINE unsigned long
424 _get_irn_visited (const ir_node *node)
427 return node->visited;
431 * Sets the visited counter of a node.
432 * Intern version for libFirm.
435 _set_irn_visited (ir_node *node, unsigned long visited)
438 node->visited = visited;
442 * Mark a node as visited in a graph.
443 * Intern version for libFirm.
446 _mark_irn_visited (ir_node *node) {
448 node->visited = current_ir_graph->visited;
452 * Returns non-zero if a node of was visited.
453 * Intern version for libFirm.
456 _irn_visited(const ir_node *node) {
458 return (node->visited >= current_ir_graph->visited);
462 * Returns non-zero if a node of was NOT visited.
463 * Intern version for libFirm.
466 _irn_not_visited(const ir_node *node) {
468 return (node->visited < current_ir_graph->visited);
472 * Sets the link of a node.
473 * Intern version of libFirm.
476 _set_irn_link(ir_node *node, void *link) {
478 /* Link field is used for Phi construction and various optimizations
480 assert(get_irg_phase_state(current_ir_graph) != phase_building);
486 * Returns the link of a node.
487 * Intern version of libFirm.
490 _get_irn_link(const ir_node *node) {
491 assert (node && _is_ir_node(node));
496 * Returns the pinned state of a node.
497 * Intern version of libFirm.
499 static INLINE op_pin_state
500 _get_irn_pinned(const ir_node *node) {
502 assert(node && _is_ir_node(node));
503 state = __get_op_pinned(_get_irn_op(node));
504 if (state >= op_pin_state_exc_pinned)
505 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
510 _is_unop(const ir_node *node) {
511 assert(node && _is_ir_node(node));
512 return (node->op->opar == oparity_unary);
516 _is_binop(const ir_node *node) {
517 assert(node && _is_ir_node(node));
518 return (node->op->opar == oparity_binary);
522 _is_Bad(const ir_node *node) {
524 return (node && _get_irn_op(node) == op_Bad);
528 _is_no_Block(const ir_node *node) {
529 assert(node && _is_ir_node(node));
530 return (_get_irn_op(node) != op_Block);
534 _is_Block(const ir_node *node) {
535 assert(node && _is_ir_node(node));
536 return (_get_irn_op(node) == op_Block);
539 static INLINE ir_node *
540 _set_Block_dead(ir_node *block) {
541 assert(_get_irn_op(block) == op_Block);
542 block->attr.block.dead = 1;
547 _is_Block_dead(const ir_node *block) {
548 ir_op * op = _get_irn_op(block);
553 assert(op == op_Block);
554 return block->attr.block.dead;
558 static INLINE tarval *_get_Const_tarval (ir_node *node) {
559 assert (node->op == op_Const);
560 return node->attr.con.tv;
564 static INLINE cnst_classify_t _classify_Const(ir_node *node)
567 assert(_is_ir_node(node));
569 op = _get_irn_op(node);
572 return classify_tarval(_get_Const_tarval(node));
573 else if(op == op_SymConst)
574 return CNST_SYMCONST;
576 return CNST_NO_CONST;
580 /* this section MUST contain all inline functions */
581 #define is_ir_node(thing) _is_ir_node(thing)
582 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
583 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
584 #define get_irn_arity(node) _get_irn_arity(node)
585 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
586 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
587 #define get_irn_n(node, n) _get_irn_n(node, n)
588 #define get_irn_mode(node) _get_irn_mode(node)
589 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
590 #define get_irn_op(node) _get_irn_op(node)
591 #define get_irn_opcode(node) _get_irn_opcode(node)
592 #define get_irn_visited(node) _get_irn_visited(node)
593 #define set_irn_visited(node, v) _set_irn_visited(node, v)
594 #define mark_irn_visited(node) _mark_irn_visited(node)
595 #define irn_visited(node) _irn_visited(node)
596 #define irn_not_visited(node) _irn_not_visited(node)
597 #define set_irn_link(node, link) _set_irn_link(node, link)
598 #define get_irn_link(node) _get_irn_link(node)
599 #define is_unop(node) _is_unop(node)
600 #define is_binop(node) _is_binop(node)
601 #define is_Bad(node) _is_Bad(node)
602 #define is_no_Block(node) _is_no_Block(node)
603 #define is_Block(node) _is_Block(node)
604 #define set_Block_dead(block) _set_Block_dead(block)
605 #define is_Block_dead(block) _is_Block_dead(block)
606 #define get_Const_tarval(node) _get_Const_tarval(node)
607 #define classify_Const(node) _classify_Const(node)
609 # endif /* _IRNODE_T_H_ */