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.
17 * Declarations of an ir node.
19 * @author Martin Trapp, Christian Schaefer
32 # include "irgraph_t.h"
33 # include "irflag_t.h"
34 # include "firm_common_t.h"
35 # include "irdom_t.h" /* For size of struct dom_info. */
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 /** InstOf attributes */
132 /** Filter attributes */
134 long proj; /**< contains the result position to project (Proj) */
135 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
136 int *backedge; /**< Field n set to true if pred n is backedge.
137 @todo Ev. replace by bitfield! */
140 /** EndReg/EndExcept attributes */
143 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
144 /* * navigating in interprocedural graphs) */
145 /* @@@ now in block */
148 /** CallBegin attributes */
150 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
151 /* * navigating in interprocedural graphs) */
152 /* @@@ now in block */
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 */
176 /** Some irnodes just have one attribute, these are stored here,
177 some have more. Their name is 'irnodename_attr' */
179 start_attr start; /**< For Start */
180 block_attr block; /**< For Block: Fields needed to construct it */
181 cond_attr c; /**< For Cond. */
182 const_attr con; /**< For Const: contains the value of the constant and a type */
183 symconst_attr i; /**< For SymConst. */
184 sel_attr s; /**< For Sel. */
185 call_attr call; /**< For Call: pointer to the type of the method to call */
186 callbegin_attr callbegin; /**< For CallBegin */
187 alloc_attr a; /**< For Alloc. */
188 io_attr io; /**< For InstOf */
189 type *f; /**< For Free. */
190 cast_attr cast; /**< For Cast. */
191 load_attr load; /**< For Load. */
192 store_attr store; /**< For Store. */
193 int phi0_pos; /**< For Phi. Used to remember the value defined by
194 this Phi node. Needed when the Phi is completed
195 to call get_r_internal_value to find the
196 predecessors. If this attribute is set, the Phi
197 node takes the role of the obsolete Phi0 node,
198 therefore the name. */
199 int *phi_backedge; /**< For Phi after construction.
200 Field n set to true if pred n is backedge.
201 @todo Ev. replace by bitfield! */
202 long proj; /**< For Proj: contains the result position to project */
203 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
204 filter_attr filter; /**< For Filter */
205 end_attr end; /**< For EndReg, EndExcept */
206 except_attr except; /**< For Phi node construction in case of exceptions */
210 /** common structure of an irnode
211 if the node has some attributes, they are stored in attr */
213 /* ------- Basics of the representation ------- */
214 firm_kind kind; /**< distinguishes this node from others */
215 ir_op *op; /**< Opcode of this node. */
216 ir_mode *mode; /**< Mode of this node. */
217 unsigned long visited; /**< visited counter for walks of the graph */
218 struct ir_node **in; /**< array with predecessors / operands */
219 void *link; /**< to attach additional information to the node, e.g.
220 used while construction to link Phi0 nodes and
221 during optimization to link to nodes that
222 shall replace a node. */
223 /* ------- Fields for optimizations / analysis information ------- */
224 struct ir_node **out; /**< array of out edges */
225 struct dbg_info* dbi; /**< A pointer to information for debug support. */
226 /* ------- For debugging ------- */
228 int out_valid; /** < indicate that out edges are valid */
229 int node_nr; /**< a unique node number for each node to make output
232 /* ------- For analyses -------- */
233 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
234 #ifdef DO_HEAPANALYSIS
238 /* ------- Opcode depending fields -------- */
239 attr attr; /**< attribute of this node. Depends on opcode.
240 Must be last field of struct ir_node. */
244 /** Copies all attributes stored in the old node to the new node.
245 Assumes both have the same opcode and sufficient size. */
247 copy_attrs(const ir_node *old_node, ir_node *new_node);
250 /** Returns the array with the ins. The content of the array may not be
252 ir_node **get_irn_in (const ir_node *node);
255 /** access attributes directly */
256 INLINE const_attr get_irn_const_attr (ir_node *node);
257 INLINE long get_irn_proj_attr (ir_node *node);
258 INLINE alloc_attr get_irn_alloc_attr (ir_node *node);
259 INLINE type *get_irn_free_attr (ir_node *node);
260 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
261 type *get_irn_call_attr (ir_node *node);
262 type *get_irn_funccall_attr (ir_node *node);
263 sel_attr get_irn_sel_attr (ir_node *node);
264 int get_irn_phi_attr (ir_node *node);
265 block_attr get_irn_block_attr (ir_node *node);
266 load_attr get_irn_load_attr (ir_node *node);
267 store_attr get_irn_store_attr (ir_node *node);
268 except_attr get_irn_except_attr (ir_node *node);
271 /*-------------------------------------------------------------------*/
272 /* These function are most used in libfirm. Give them as static */
273 /* functions so they can be inlined. */
274 /*-------------------------------------------------------------------*/
277 * Checks whether a pointer points to a ir node.
278 * Intern version for libFirm.
281 __is_ir_node (const void *thing) {
282 return (get_kind(thing) == k_ir_node);
286 * Gets the op of a node.
287 * Intern version for libFirm.
289 static INLINE ir_op *
290 __get_irn_op (const ir_node *node) {
296 * Gets the opcode of a node.
297 * Intern version for libFirm.
300 __get_irn_opcode (const ir_node *node) {
301 assert (k_ir_node == get_kind(node));
303 return node->op->code;
307 * Returns the number of predecessors without the block predecessor.
308 * Intern version for libFirm.
311 __get_irn_intra_arity (const ir_node *node) {
313 return ARR_LEN(node->in) - 1;
317 * Returns the number of predecessors without the block predecessor.
318 * Intern version for libFirm.
321 __get_irn_inter_arity (const ir_node *node) {
323 if (__get_irn_opcode(node) == iro_Filter) {
324 assert(node->attr.filter.in_cg);
325 return ARR_LEN(node->attr.filter.in_cg) - 1;
326 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
327 return ARR_LEN(node->attr.block.in_cg) - 1;
329 return __get_irn_intra_arity(node);
333 * Returns the number of predecessors without the block predecessor.
334 * Intern version for libFirm.
336 extern int (*__get_irn_arity)(const ir_node *node);
339 * Intern version for libFirm.
341 static INLINE ir_node *
342 __get_irn_intra_n (ir_node *node, int n) {
343 assert(node); assert(-1 <= n && n < __get_irn_intra_arity(node));
345 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
349 * Intern version for libFirm.
351 static INLINE ir_node*
352 __get_irn_inter_n (ir_node *node, int n) {
353 assert(node); assert(-1 <= n && n < __get_irn_inter_arity(node));
355 /* handle Filter and Block specially */
356 if (__get_irn_opcode(node) == iro_Filter) {
357 assert(node->attr.filter.in_cg);
358 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
359 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
360 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
363 return __get_irn_intra_n (node, n);
367 * Access to the predecessors of a node.
368 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
369 * to iterate including the Block predecessor iterate from i = -1 to
371 * If it is a block, the entry -1 is NULL.
372 * Intern version for libFirm.
374 extern ir_node *(*__get_irn_n)(ir_node *node, int n);
377 * Gets the mode of a node.
378 * Intern version for libFirm.
380 static INLINE ir_mode *
381 __get_irn_mode (const ir_node *node)
388 * Sets the mode of a node.
389 * Intern version of libFirm.
392 __set_irn_mode (ir_node *node, ir_mode *mode)
399 * Gets the visited counter of a node.
400 * Intern version for libFirm.
402 static INLINE unsigned long
403 __get_irn_visited (const ir_node *node)
406 return node->visited;
410 * Sets the visited counter of a node.
411 * Intern version for libFirm.
414 __set_irn_visited (ir_node *node, unsigned long visited)
417 node->visited = visited;
421 * Mark a node as visited in a graph.
422 * Intern version for libFirm.
425 __mark_irn_visited (ir_node *node) {
427 node->visited = current_ir_graph->visited;
431 * Returns non-zero if a node of was visited.
432 * Intern version for libFirm.
435 __irn_visited(const ir_node *node) {
437 return (node->visited >= current_ir_graph->visited);
441 * Returns non-zero if a node of was NOT visited.
442 * Intern version for libFirm.
445 __irn_not_visited(const ir_node *node) {
447 return (node->visited < current_ir_graph->visited);
451 * Sets the link of a node.
452 * Intern version of libFirm.
455 __set_irn_link(ir_node *node, void *link) {
457 /* Link field is used for Phi construction and various optimizations
459 assert(get_irg_phase_state(current_ir_graph) != phase_building);
465 * Returns the link of a node.
466 * Intern version of libFirm.
469 __get_irn_link(const ir_node *node) {
475 * Returns the pinned state of a node.
476 * Intern version of libFirm.
478 static INLINE op_pin_state
479 __get_irn_pinned(const ir_node *node) {
480 op_pin_state state = __get_op_pinned(__get_irn_op(node));
481 if (state >= op_pin_state_exc_pinned)
482 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
487 __is_unop(const ir_node *node) {
488 return (node->op->opar == oparity_unary);
492 __is_binop(const ir_node *node) {
493 return (node->op->opar == oparity_binary);
497 __is_Bad(const ir_node *node) {
499 return (node && __get_irn_op(node) == op_Bad);
503 __is_no_Block(const ir_node *node) {
505 return (__get_irn_op(node) != op_Block);
509 __is_Block(const ir_node *node) {
511 return (__get_irn_op(node) == op_Block);
514 static INLINE ir_node *
515 __set_Block_dead(ir_node *block) {
516 assert(__get_irn_op(block) == op_Block);
517 block->attr.block.dead = 1;
522 __is_Block_dead(const ir_node *block) {
523 ir_op * op = __get_irn_op(block);
528 assert(op == op_Block);
529 return block->attr.block.dead;
533 /* this section MUST contain all inline functions */
534 #define is_ir_node(thing) __is_ir_node(thing)
535 #define get_irn_intra_arity(node) __get_irn_intra_arity(node)
536 #define get_irn_inter_arity(node) __get_irn_inter_arity(node)
537 #define get_irn_arity(node) __get_irn_arity(node)
538 #define get_irn_intra_n(node, n) __get_irn_intra_n(node, n)
539 #define get_irn_inter_n(node, n) __get_irn_inter_n(node, n)
540 #define get_irn_n(node, n) __get_irn_n(node, n)
541 #define get_irn_mode(node) __get_irn_mode(node)
542 #define set_irn_mode(node, mode) __set_irn_mode(node, mode)
543 #define get_irn_op(node) __get_irn_op(node)
544 #define get_irn_opcode(node) __get_irn_opcode(node)
545 #define get_irn_visited(node) __get_irn_visited(node)
546 #define set_irn_visited(node, v) __set_irn_visited(node, v)
547 #define mark_irn_visited(node) __mark_irn_visited(node)
548 #define irn_visited(node) __irn_visited(node)
549 #define irn_not_visited(node) __irn_not_visited(node)
550 #define set_irn_link(node, link) __set_irn_link(node, link)
551 #define get_irn_link(node) __get_irn_link(node)
552 #define is_unop(node) __is_unop(node)
553 #define is_binop(node) __is_binop(node)
554 #define is_Bad(node) __is_Bad(node)
555 #define is_no_Block(node) __is_no_Block(node)
556 #define is_Block(node) __is_Block(node)
557 #define set_Block_dead(block) __set_Block_dead(block)
558 #define is_Block_dead(block) __is_Block_dead(block)
560 # endif /* _IRNODE_T_H_ */