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
26 #include "firm_config.h"
29 #include "irgraph_t.h"
31 #include "firm_common_t.h"
32 #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 /** InstOf attributes */
130 /** Filter attributes */
132 long proj; /**< contains the result position to project (Proj) */
133 ir_node ** in_cg; /**< array with interprocedural predecessors (Phi) */
134 int *backedge; /**< Field n set to true if pred n is backedge.
135 @todo Ev. replace by bitfield! */
138 /** EndReg/EndExcept attributes */
141 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
142 /* * navigating in interprocedural graphs) */
143 /* @@@ now in block */
146 /** CallBegin attributes */
148 /* ir_graph * irg; */ /**< ir_graph this node belongs to (for */
149 /* * navigating in interprocedural graphs) */
150 /* @@@ now in block */
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 */
174 /** Some irnodes just have one attribute, these are stored here,
175 some have more. Their name is 'irnodename_attr' */
177 start_attr start; /**< For Start */
178 block_attr block; /**< For Block: Fields needed to construct it */
179 cond_attr c; /**< For Cond. */
180 const_attr con; /**< For Const: contains the value of the constant and a type */
181 symconst_attr i; /**< For SymConst. */
182 sel_attr s; /**< For Sel. */
183 call_attr call; /**< For Call: pointer to the type of the method to call */
184 callbegin_attr callbegin; /**< For CallBegin */
185 alloc_attr a; /**< For Alloc. */
186 io_attr io; /**< For InstOf */
187 type *f; /**< For Free. */
188 cast_attr cast; /**< For Cast. */
189 load_attr load; /**< For Load. */
190 store_attr store; /**< For Store. */
191 int phi0_pos; /**< For Phi. Used to remember the value defined by
192 this Phi node. Needed when the Phi is completed
193 to call get_r_internal_value to find the
194 predecessors. If this attribute is set, the Phi
195 node takes the role of the obsolete Phi0 node,
196 therefore the name. */
197 int *phi_backedge; /**< For Phi after construction.
198 Field n set to true if pred n is backedge.
199 @todo Ev. replace by bitfield! */
200 long proj; /**< For Proj: contains the result position to project */
201 confirm_attr confirm_cmp; /**< For Confirm: compare operation */
202 filter_attr filter; /**< For Filter */
203 end_attr end; /**< For EndReg, EndExcept */
204 except_attr except; /**< For Phi node construction in case of exceptions */
208 /** common structure of an irnode
209 if the node has some attributes, they are stored in attr */
211 /* ------- Basics of the representation ------- */
212 firm_kind kind; /**< distinguishes this node from others */
213 ir_op *op; /**< Opcode of this node. */
214 ir_mode *mode; /**< Mode of this node. */
215 unsigned long visited; /**< visited counter for walks of the graph */
216 struct ir_node **in; /**< array with predecessors / operands */
217 void *link; /**< to attach additional information to the node, e.g.
218 used while construction to link Phi0 nodes and
219 during optimization to link to nodes that
220 shall replace a node. */
221 /* ------- Fields for optimizations / analysis information ------- */
222 struct ir_node **out; /**< array of out edges */
223 struct dbg_info* dbi; /**< A pointer to information for debug support. */
224 /* ------- For debugging ------- */
226 int out_valid; /** < indicate that out edges are valid */
227 int node_nr; /**< a unique node number for each node to make output
230 /* ------- For analyses -------- */
231 ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
232 #ifdef DO_HEAPANALYSIS
236 /* ------- Opcode depending fields -------- */
237 attr attr; /**< attribute of this node. Depends on opcode.
238 Must be last field of struct ir_node. */
242 /** Copies all attributes stored in the old node to the new node.
243 Assumes both have the same opcode and sufficient size. */
245 copy_attrs(const ir_node *old_node, ir_node *new_node);
248 /** Returns the array with the ins. The content of the array may not be
250 ir_node **get_irn_in (const ir_node *node);
253 /** access attributes directly */
254 INLINE const_attr get_irn_const_attr (ir_node *node);
255 INLINE long get_irn_proj_attr (ir_node *node);
256 INLINE alloc_attr get_irn_alloc_attr (ir_node *node);
257 INLINE type *get_irn_free_attr (ir_node *node);
258 INLINE symconst_attr get_irn_symconst_attr (ir_node *node);
259 type *get_irn_call_attr (ir_node *node);
260 type *get_irn_funccall_attr (ir_node *node);
261 sel_attr get_irn_sel_attr (ir_node *node);
262 int get_irn_phi_attr (ir_node *node);
263 block_attr get_irn_block_attr (ir_node *node);
264 load_attr get_irn_load_attr (ir_node *node);
265 store_attr get_irn_store_attr (ir_node *node);
266 except_attr get_irn_except_attr (ir_node *node);
269 /*-------------------------------------------------------------------*/
270 /* These function are most used in libfirm. Give them as static */
271 /* functions so they can be inlined. */
272 /*-------------------------------------------------------------------*/
275 * Checks whether a pointer points to a ir node.
276 * Intern version for libFirm.
279 __is_ir_node (const void *thing) {
280 return (get_kind(thing) == k_ir_node);
284 * Gets the op of a node.
285 * Intern version for libFirm.
287 static INLINE ir_op *
288 __get_irn_op (const ir_node *node) {
294 * Gets the opcode of a node.
295 * Intern version for libFirm.
298 __get_irn_opcode (const ir_node *node) {
299 assert (k_ir_node == get_kind(node));
301 return node->op->code;
305 * Returns the number of predecessors without the block predecessor.
306 * Intern version for libFirm.
309 __get_irn_intra_arity (const ir_node *node) {
311 return ARR_LEN(node->in) - 1;
315 * Returns the number of predecessors without the block predecessor.
316 * Intern version for libFirm.
319 __get_irn_inter_arity (const ir_node *node) {
321 if (__get_irn_opcode(node) == iro_Filter) {
322 assert(node->attr.filter.in_cg);
323 return ARR_LEN(node->attr.filter.in_cg) - 1;
324 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
325 return ARR_LEN(node->attr.block.in_cg) - 1;
327 return __get_irn_intra_arity(node);
331 * Returns the number of predecessors without the block predecessor.
332 * Intern version for libFirm.
334 extern int (*__get_irn_arity)(const ir_node *node);
337 * Intern version for libFirm.
339 static INLINE ir_node *
340 __get_irn_intra_n (const ir_node *node, int n) {
341 assert(node); assert(-1 <= n && n < __get_irn_intra_arity(node));
343 return (node->in[n + 1] = skip_Id(node->in[n + 1]));
347 * Intern version for libFirm.
349 static INLINE ir_node*
350 __get_irn_inter_n (const ir_node *node, int n) {
351 assert(node); assert(-1 <= n && n < __get_irn_inter_arity(node));
353 /* handle Filter and Block specially */
354 if (__get_irn_opcode(node) == iro_Filter) {
355 assert(node->attr.filter.in_cg);
356 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
357 } else if (__get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
358 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
361 return __get_irn_intra_n (node, n);
365 * Access to the predecessors of a node.
366 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
367 * to iterate including the Block predecessor iterate from i = -1 to
369 * If it is a block, the entry -1 is NULL.
370 * Intern version for libFirm.
372 extern ir_node *(*__get_irn_n)(const ir_node *node, int n);
375 * Gets the mode of a node.
376 * Intern version for libFirm.
378 static INLINE ir_mode *
379 __get_irn_mode (const ir_node *node)
386 * Sets the mode of a node.
387 * Intern version of libFirm.
390 __set_irn_mode (ir_node *node, ir_mode *mode)
397 * Gets the visited counter of a node.
398 * Intern version for libFirm.
400 static INLINE unsigned long
401 __get_irn_visited (const ir_node *node)
404 return node->visited;
408 * Sets the visited counter of a node.
409 * Intern version for libFirm.
412 __set_irn_visited (ir_node *node, unsigned long visited)
415 node->visited = visited;
419 * Mark a node as visited in a graph.
420 * Intern version for libFirm.
423 __mark_irn_visited (ir_node *node) {
425 node->visited = current_ir_graph->visited;
429 * Returns non-zero if a node of was visited.
430 * Intern version for libFirm.
433 __irn_visited(const ir_node *node) {
435 return (node->visited >= current_ir_graph->visited);
439 * Returns non-zero if a node of was NOT visited.
440 * Intern version for libFirm.
443 __irn_not_visited(const ir_node *node) {
445 return (node->visited < current_ir_graph->visited);
449 * Sets the link of a node.
450 * Intern version of libFirm.
453 __set_irn_link(ir_node *node, void *link) {
455 /* Link field is used for Phi construction and various optimizations
457 assert(get_irg_phase_state(current_ir_graph) != phase_building);
463 * Returns the link of a node.
464 * Intern version of libFirm.
467 __get_irn_link(const ir_node *node) {
473 * Returns the pinned state of a node.
474 * Intern version of libFirm.
476 static INLINE op_pin_state
477 __get_irn_pinned(const ir_node *node) {
478 op_pin_state state = __get_op_pinned(__get_irn_op(node));
479 if (state >= op_pin_state_exc_pinned)
480 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
485 __is_unop(const ir_node *node) {
486 return (node->op->opar == oparity_unary);
490 __is_binop(const ir_node *node) {
491 return (node->op->opar == oparity_binary);
495 __is_Bad(const ir_node *node) {
497 return (node && __get_irn_op(node) == op_Bad);
501 __is_no_Block(const ir_node *node) {
503 return (__get_irn_op(node) != op_Block);
507 __is_Block(const ir_node *node) {
509 return (__get_irn_op(node) == op_Block);
512 static INLINE ir_node *
513 __set_Block_dead(ir_node *block) {
514 assert(__get_irn_op(block) == op_Block);
515 block->attr.block.dead = 1;
520 __is_Block_dead(const ir_node *block) {
521 ir_op * op = __get_irn_op(block);
526 assert(op == op_Block);
527 return block->attr.block.dead;
531 /* this section MUST contain all inline functions */
532 #define is_ir_node(thing) __is_ir_node(thing)
533 #define get_irn_intra_arity(node) __get_irn_intra_arity(node)
534 #define get_irn_inter_arity(node) __get_irn_inter_arity(node)
535 #define get_irn_arity(node) __get_irn_arity(node)
536 #define get_irn_intra_n(node, n) __get_irn_intra_n(node, n)
537 #define get_irn_inter_n(node, n) __get_irn_inter_n(node, n)
538 #define get_irn_n(node, n) __get_irn_n(node, n)
539 #define get_irn_mode(node) __get_irn_mode(node)
540 #define set_irn_mode(node, mode) __set_irn_mode(node, mode)
541 #define get_irn_op(node) __get_irn_op(node)
542 #define get_irn_opcode(node) __get_irn_opcode(node)
543 #define get_irn_visited(node) __get_irn_visited(node)
544 #define set_irn_visited(node, v) __set_irn_visited(node, v)
545 #define mark_irn_visited(node) __mark_irn_visited(node)
546 #define irn_visited(node) __irn_visited(node)
547 #define irn_not_visited(node) __irn_not_visited(node)
548 #define set_irn_link(node, link) __set_irn_link(node, link)
549 #define get_irn_link(node) __get_irn_link(node)
550 #define is_unop(node) __is_unop(node)
551 #define is_binop(node) __is_binop(node)
552 #define is_Bad(node) __is_Bad(node)
553 #define is_no_Block(node) __is_no_Block(node)
554 #define is_Block(node) __is_Block(node)
555 #define set_Block_dead(block) __set_Block_dead(block)
556 #define is_Block_dead(block) __is_Block_dead(block)
558 # endif /* _IRNODE_T_H_ */