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 /*-------------------------------------------------------------------*/
281 /* These function are most used in libfirm. Give them as static */
282 /* functions so they can be inlined. */
283 /*-------------------------------------------------------------------*/
286 * Checks whether a pointer points to a ir node.
287 * Intern version for libFirm.
290 _is_ir_node (const void *thing) {
291 return (get_kind(thing) == k_ir_node);
295 * Gets the op of a node.
296 * Intern version for libFirm.
298 static INLINE ir_op *
299 _get_irn_op (const ir_node *node) {
304 /** Copies all attributes stored in the old node to the new node.
305 Assumes both have the same opcode and sufficient size. */
307 copy_node_attr(const ir_node *old_node, ir_node *new_node) {
308 ir_op *op = _get_irn_op(old_node);
310 /* must always exist */
311 op->copy_attr(old_node, new_node);
315 * Gets the opcode of a node.
316 * Intern version for libFirm.
319 _get_irn_opcode (const ir_node *node) {
320 assert (k_ir_node == get_kind(node));
322 return node->op->code;
326 * Returns the number of predecessors without the block predecessor.
327 * Intern version for libFirm.
330 _get_irn_intra_arity (const ir_node *node) {
332 return ARR_LEN(node->in) - 1;
336 * Returns the number of predecessors without the block predecessor.
337 * Intern version for libFirm.
340 _get_irn_inter_arity (const ir_node *node) {
342 if (_get_irn_opcode(node) == iro_Filter) {
343 assert(node->attr.filter.in_cg);
344 return ARR_LEN(node->attr.filter.in_cg) - 1;
345 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
346 return ARR_LEN(node->attr.block.in_cg) - 1;
348 return _get_irn_intra_arity(node);
352 * Returns the number of predecessors without the block predecessor.
353 * Intern version for libFirm.
355 extern int (*_get_irn_arity)(const ir_node *node);
358 * Intern version for libFirm.
360 static INLINE ir_node *
361 _get_irn_intra_n (const ir_node *node, int n) {
362 assert(node); assert(-1 <= n && n < _get_irn_intra_arity(node));
364 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
368 * Intern version for libFirm.
370 static INLINE ir_node*
371 _get_irn_inter_n (const ir_node *node, int n) {
372 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
374 /* handle Filter and Block specially */
375 if (_get_irn_opcode(node) == iro_Filter) {
376 assert(node->attr.filter.in_cg);
377 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
378 } else if (_get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
379 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
382 return _get_irn_intra_n (node, n);
386 * Access to the predecessors of a node.
387 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
388 * to iterate including the Block predecessor iterate from i = -1 to
390 * If it is a block, the entry -1 is NULL.
391 * Intern version for libFirm.
393 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
396 * Gets the mode of a node.
397 * Intern version for libFirm.
399 static INLINE ir_mode *
400 _get_irn_mode (const ir_node *node)
407 * Sets the mode of a node.
408 * Intern version of libFirm.
411 _set_irn_mode (ir_node *node, ir_mode *mode)
418 * Gets the visited counter of a node.
419 * Intern version for libFirm.
421 static INLINE unsigned long
422 _get_irn_visited (const ir_node *node)
425 return node->visited;
429 * Sets the visited counter of a node.
430 * Intern version for libFirm.
433 _set_irn_visited (ir_node *node, unsigned long visited)
436 node->visited = visited;
440 * Mark a node as visited in a graph.
441 * Intern version for libFirm.
444 _mark_irn_visited (ir_node *node) {
446 node->visited = current_ir_graph->visited;
450 * Returns non-zero if a node of was visited.
451 * Intern version for libFirm.
454 _irn_visited(const ir_node *node) {
456 return (node->visited >= current_ir_graph->visited);
460 * Returns non-zero if a node of was NOT visited.
461 * Intern version for libFirm.
464 _irn_not_visited(const ir_node *node) {
466 return (node->visited < current_ir_graph->visited);
470 * Sets the link of a node.
471 * Intern version of libFirm.
474 _set_irn_link(ir_node *node, void *link) {
476 /* Link field is used for Phi construction and various optimizations
478 assert(get_irg_phase_state(current_ir_graph) != phase_building);
484 * Returns the link of a node.
485 * Intern version of libFirm.
488 _get_irn_link(const ir_node *node) {
489 assert (node && _is_ir_node(node));
494 * Returns the pinned state of a node.
495 * Intern version of libFirm.
497 static INLINE op_pin_state
498 _get_irn_pinned(const ir_node *node) {
500 assert(node && _is_ir_node(node));
501 state = __get_op_pinned(_get_irn_op(node));
502 if (state >= op_pin_state_exc_pinned)
503 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
508 _is_unop(const ir_node *node) {
509 assert(node && _is_ir_node(node));
510 return (node->op->opar == oparity_unary);
514 _is_binop(const ir_node *node) {
515 assert(node && _is_ir_node(node));
516 return (node->op->opar == oparity_binary);
520 _is_Bad(const ir_node *node) {
522 return (node && _get_irn_op(node) == op_Bad);
526 _is_no_Block(const ir_node *node) {
527 assert(node && _is_ir_node(node));
528 return (_get_irn_op(node) != op_Block);
532 _is_Block(const ir_node *node) {
533 assert(node && _is_ir_node(node));
534 return (_get_irn_op(node) == op_Block);
537 static INLINE ir_node *
538 _set_Block_dead(ir_node *block) {
539 assert(_get_irn_op(block) == op_Block);
540 block->attr.block.dead = 1;
545 _is_Block_dead(const ir_node *block) {
546 ir_op * op = _get_irn_op(block);
551 assert(op == op_Block);
552 return block->attr.block.dead;
556 static INLINE tarval *_get_Const_tarval (ir_node *node) {
557 assert (node->op == op_Const);
558 return node->attr.con.tv;
562 static INLINE cnst_classify_t _classify_Const(ir_node *node)
565 assert(_is_ir_node(node));
567 op = _get_irn_op(node);
570 return classify_tarval(_get_Const_tarval(node));
571 else if(op == op_SymConst)
572 return CNST_SYMCONST;
574 return CNST_NO_CONST;
578 /* this section MUST contain all inline functions */
579 #define is_ir_node(thing) _is_ir_node(thing)
580 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
581 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
582 #define get_irn_arity(node) _get_irn_arity(node)
583 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
584 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
585 #define get_irn_n(node, n) _get_irn_n(node, n)
586 #define get_irn_mode(node) _get_irn_mode(node)
587 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
588 #define get_irn_op(node) _get_irn_op(node)
589 #define get_irn_opcode(node) _get_irn_opcode(node)
590 #define get_irn_visited(node) _get_irn_visited(node)
591 #define set_irn_visited(node, v) _set_irn_visited(node, v)
592 #define mark_irn_visited(node) _mark_irn_visited(node)
593 #define irn_visited(node) _irn_visited(node)
594 #define irn_not_visited(node) _irn_not_visited(node)
595 #define set_irn_link(node, link) _set_irn_link(node, link)
596 #define get_irn_link(node) _get_irn_link(node)
597 #define is_unop(node) _is_unop(node)
598 #define is_binop(node) _is_binop(node)
599 #define is_Bad(node) _is_Bad(node)
600 #define is_no_Block(node) _is_no_Block(node)
601 #define is_Block(node) _is_Block(node)
602 #define set_Block_dead(block) _set_Block_dead(block)
603 #define is_Block_dead(block) _is_Block_dead(block)
604 #define get_Const_tarval(node) _get_Const_tarval(node)
605 #define classify_Const(node) _classify_Const(node)
607 # endif /* _IRNODE_T_H_ */