2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Representation of an intermediate operation -- private header.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
26 #ifndef FIRM_IR_IRNODE_T_H
27 #define FIRM_IR_IRNODE_T_H
32 #include "irgraph_t.h"
37 * Returns the array with the ins. The content of the array may not be
39 * Note that this function returns the whole in array including the
40 * block predecessor. So, it is NOT symmetric with set_irn_in().
42 ir_node **get_irn_in (const ir_node *node);
45 /** access attributes directly */
46 const_attr *get_irn_const_attr (ir_node *node);
47 long get_irn_proj_attr (ir_node *node);
48 alloc_attr *get_irn_alloc_attr (ir_node *node);
49 free_attr *get_irn_free_attr (ir_node *node);
50 symconst_attr *get_irn_symconst_attr (ir_node *node);
51 ir_type *get_irn_call_attr (ir_node *node);
52 ir_type *get_irn_funccall_attr (ir_node *node);
53 sel_attr *get_irn_sel_attr (ir_node *node);
54 phi_attr *get_irn_phi_attr (ir_node *node);
55 block_attr *get_irn_block_attr (ir_node *node);
56 load_attr *get_irn_load_attr (ir_node *node);
57 store_attr *get_irn_store_attr (ir_node *node);
58 except_attr *get_irn_except_attr (ir_node *node);
59 divmod_attr *get_irn_divmod_attr (ir_node *node);
60 builtin_attr *get_irn_builtin_attr (ir_node *node);
64 * The amount of additional space for custom data to be allocated upon creating a new node.
66 extern unsigned firm_add_node_size;
69 * Sets the get_type operation for an ir_op_ops.
71 * @param code the opcode for the default operation
72 * @param ops the operations initialized
77 ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops);
80 * Sets the get_type_attr operation for an ir_op_ops.
82 * @param code the opcode for the default operation
83 * @param ops the operations initialized
88 ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops);
91 * Sets the get_entity_attr operation for an ir_op_ops.
93 * @param code the opcode for the default operation
94 * @param ops the operations initialized
99 ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops);
102 * Returns an array with the predecessors of the Block. Depending on
103 * the implementation of the graph data structure this can be a copy of
104 * the internal representation of predecessors as well as the internal
105 * array itself. Therefore writing to this array might obstruct the IR.
107 ir_node **get_Block_cfgpred_arr(ir_node *node);
109 /*-------------------------------------------------------------------*/
110 /* These function are most used in libfirm. Give them as static */
111 /* functions so they can be inlined. */
112 /*-------------------------------------------------------------------*/
115 * Checks whether a pointer points to a ir node.
116 * Intern version for libFirm.
119 _is_ir_node(const void *thing) {
120 return (get_kind(thing) == k_ir_node);
124 * Gets the op of a node.
125 * Intern version for libFirm.
127 static inline ir_op *
128 _get_irn_op(const ir_node *node) {
134 _set_irn_op(ir_node *node, ir_op *op) {
139 /** Copies all attributes stored in the old node to the new node.
140 Assumes both have the same opcode and sufficient size. */
142 _copy_node_attr(const ir_node *old_node, ir_node *new_node) {
143 ir_op *op = _get_irn_op(old_node);
145 /* must always exist */
146 op->ops.copy_attr(old_node, new_node);
150 * Gets the opcode of a node.
151 * Intern version for libFirm.
153 static inline unsigned
154 _get_irn_opcode(const ir_node *node) {
155 assert(k_ir_node == get_kind(node));
157 return node->op->code;
161 * Returns the number of predecessors without the block predecessor.
162 * Intern version for libFirm.
165 _get_irn_intra_arity(const ir_node *node) {
167 return ARR_LEN(node->in) - 1;
171 * Returns the number of predecessors without the block predecessor.
172 * Intern version for libFirm.
175 _get_irn_inter_arity(const ir_node *node) {
177 if (_get_irn_op(node) == op_Filter) {
178 assert(node->attr.filter.in_cg);
179 return ARR_LEN(node->attr.filter.in_cg) - 1;
180 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
181 return ARR_LEN(node->attr.block.in_cg) - 1;
183 return _get_irn_intra_arity(node);
186 #ifdef INTERPROCEDURAL_VIEW
188 * Returns the number of predecessors without the block predecessor.
189 * Intern version for libFirm.
191 extern int (*_get_irn_arity)(const ir_node *node);
195 #define _get_irn_arity(n) _get_irn_intra_arity(n)
199 * Intern version for libFirm.
201 static inline ir_node *
202 _get_irn_intra_n(const ir_node *node, int n) {
206 assert(-1 <= n && n < _get_irn_intra_arity(node));
208 nn = node->in[n + 1];
210 /* only block and Anchor inputs are allowed to be NULL */
211 assert((node->op == op_Anchor || n == -1) && "NULL input of a node");
214 if (nn->op != op_Id) return nn;
216 return (node->in[n + 1] = skip_Id(nn));
220 * Intern version for libFirm.
222 static inline ir_node*
223 _get_irn_inter_n(const ir_node *node, int n) {
224 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
226 /* handle Filter and Block specially */
227 if (_get_irn_op(node) == op_Filter) {
228 assert(node->attr.filter.in_cg);
229 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
230 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
231 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
234 return _get_irn_intra_n(node, n);
238 * returns a hash value for a node
240 static inline unsigned hash_irn(const ir_node *node)
242 return (unsigned) get_irn_idx(node);
246 * Access to the predecessors of a node.
247 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
248 * to iterate including the Block predecessor iterate from i = -1 to
250 * If it is a block, the entry -1 is NULL.
251 * Intern version for libFirm.
253 #ifdef INTERPROCEDURAL_VIEW
254 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
256 #define _get_irn_n(n,i) _get_irn_intra_n(n,i)
259 static inline int _get_irn_deps(const ir_node *node) {
260 return node->deps ? ARR_LEN(node->deps) : 0;
263 static inline ir_node *_get_irn_dep(const ir_node *node, int pos) {
264 assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
265 assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
266 return node->deps[pos];
270 _set_irn_dep(ir_node *node, int pos, ir_node *dep) {
273 assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
274 assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
275 old = node->deps[pos];
276 node->deps[pos] = dep;
277 edges_notify_edge_kind(node, pos, dep, old, EDGE_KIND_DEP, get_irn_irg(node));
282 _get_irn_ins_or_deps(const ir_node *irn) {
283 return _get_irn_deps(irn) + _get_irn_arity(irn);
286 static inline ir_node *
287 _get_irn_in_or_dep(const ir_node *irn, int pos) {
288 int n_in = get_irn_arity(irn);
289 return pos < n_in ? get_irn_n(irn, pos) : get_irn_dep(irn, pos - n_in);
293 * Gets the mode of a node.
294 * Intern version for libFirm.
296 static inline ir_mode *
297 _get_irn_mode(const ir_node *node) {
303 * Sets the mode of a node.
304 * Intern version of libFirm.
307 _set_irn_mode(ir_node *node, ir_mode *mode) {
313 * Gets the visited counter of a node.
314 * Intern version for libFirm.
316 static inline ir_visited_t
317 _get_irn_visited(const ir_node *node) {
319 return node->visited;
323 * Sets the visited counter of a node.
324 * Intern version for libFirm.
327 _set_irn_visited(ir_node *node, ir_visited_t visited) {
329 node->visited = visited;
333 * Mark a node as visited in a graph.
334 * Intern version for libFirm.
337 _mark_irn_visited(ir_node *node) {
339 node->visited = current_ir_graph->visited;
343 * Returns non-zero if a node of was visited.
344 * Intern version for libFirm.
347 _irn_visited(const ir_node *node) {
349 return (node->visited >= current_ir_graph->visited);
353 _irn_visited_else_mark(ir_node *node) {
354 if (_irn_visited(node))
356 _mark_irn_visited(node);
361 * Sets the link of a node.
362 * Intern version of libFirm.
365 _set_irn_link(ir_node *node, void *link) {
371 * Returns the link of a node.
372 * Intern version of libFirm.
375 _get_irn_link(const ir_node *node) {
376 assert(node && _is_ir_node(node));
381 * Returns whether the node _always_ must be pinned.
382 * I.e., the node is not floating after global cse.
384 * Intern version of libFirm.
386 static inline op_pin_state
387 _get_irn_pinned(const ir_node *node) {
389 assert(node && _is_ir_node(node));
391 state = _get_op_pinned(_get_irn_op(node));
393 if (state >= op_pin_state_exc_pinned)
394 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
398 static inline op_pin_state
399 _is_irn_pinned_in_irg(const ir_node *node) {
400 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
401 return get_irn_pinned(node);
402 return op_pin_state_pinned;
405 /* include generated code */
406 #include "gen_irnode.h"
409 _is_unop(const ir_node *node) {
410 assert(node && _is_ir_node(node));
411 return (node->op->opar == oparity_unary);
415 _is_binop(const ir_node *node) {
416 assert(node && _is_ir_node(node));
417 return (node->op->opar == oparity_binary);
421 _is_Phi(const ir_node *node) {
425 op = get_irn_op(node);
426 #ifdef INTERPROCEDURAL_VIEW
427 if (op == op_Filter) return get_interprocedural_view();
429 return (op == op_Phi);
433 _is_Proj(const ir_node *node) {
437 op = _get_irn_op(node);
438 #ifdef INTERPROCEDURAL_VIEW
439 if (op == op_Filter) return !get_interprocedural_view();
441 return (op == op_Proj);
445 _is_strictConv(const ir_node *node) {
446 return _is_Conv(node) && get_Conv_strict(node);
450 _is_SymConst_addr_ent(const ir_node *node) {
451 return is_SymConst(node) && get_SymConst_kind(node) == symconst_addr_ent;
455 _is_no_Block(const ir_node *node) {
456 assert(node && _is_ir_node(node));
457 return (_get_irn_op(node) != op_Block);
461 _get_Block_n_cfgpreds(const ir_node *node) {
462 assert(_is_Block(node));
463 return _get_irn_arity(node);
466 static inline ir_node *
467 _get_Block_cfgpred(const ir_node *node, int pos) {
468 assert(0 <= pos && pos < get_irn_arity(node));
469 assert(_is_Block(node));
470 return _get_irn_n(node, pos);
473 /* Get the predecessor block.
475 * Returns the block corresponding to the predecessor pos.
477 * There are several ambiguities we resolve with this function:
478 * - The direct predecessor can be a Proj, which is not pinned.
479 * We walk from the predecessor to the next pinned node
480 * (skip_Proj) and return the block that node is in.
481 * - If we encounter the Bad node, this function does not return
482 * the Start block, but the Bad node.
484 static inline ir_node *
485 _get_Block_cfgpred_block(const ir_node *node, int pos) {
486 ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
488 res = get_nodes_block(res);
492 static inline ir_visited_t
493 _get_Block_block_visited(const ir_node *node) {
494 assert(node->op == op_Block);
495 return node->attr.block.block_visited;
499 _set_Block_block_visited(ir_node *node, ir_visited_t visit) {
500 assert(node->op == op_Block);
501 node->attr.block.block_visited = visit;
504 /* For this current_ir_graph must be set. */
506 _mark_Block_block_visited(ir_node *node) {
507 assert(node->op == op_Block);
508 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
512 _Block_block_visited(const ir_node *node) {
513 assert(node->op == op_Block);
514 return (node->attr.block.block_visited >= get_irg_block_visited(current_ir_graph));
517 static inline ir_node *
518 _set_Block_dead(ir_node *block) {
519 assert(_get_irn_op(block) == op_Block);
520 block->attr.block.dom.dom_depth = -1;
521 block->attr.block.is_dead = 1;
526 _is_Block_dead(const ir_node *block) {
527 ir_op *op = _get_irn_op(block);
532 assert(op == op_Block);
533 return block->attr.block.is_dead;
537 static inline ir_graph *
538 _get_Block_irg(const ir_node *block) {
539 assert(is_Block(block) || is_Bad(block));
540 return block->attr.irg.irg;
543 static inline tarval *_get_Const_tarval(const ir_node *node) {
544 assert(_get_irn_op(node) == op_Const);
545 return node->attr.con.tv;
548 static inline int _is_Const_null(const ir_node *node) {
549 return tarval_is_null(_get_Const_tarval(node));
552 static inline int _is_Const_one(const ir_node *node) {
553 return tarval_is_one(_get_Const_tarval(node));
556 static inline int _is_Const_all_one(const ir_node *node) {
557 return tarval_is_all_one(_get_Const_tarval(node));
560 static inline int _is_irn_forking(const ir_node *node) {
561 return is_op_forking(_get_irn_op(node));
564 static inline ir_type *_get_irn_type(ir_node *node) {
565 return _get_irn_op(node)->ops.get_type(node);
568 static inline ir_type *_get_irn_type_attr(ir_node *node) {
569 return _get_irn_op(node)->ops.get_type_attr(node);
572 static inline ir_entity *_get_irn_entity_attr(ir_node *node) {
573 return _get_irn_op(node)->ops.get_entity_attr(node);
576 static inline int _is_irn_constlike(const ir_node *node) {
577 return is_op_constlike(_get_irn_op(node));
580 static inline int _is_irn_always_opt(const ir_node *node) {
581 return is_op_always_opt(_get_irn_op(node));
584 static inline int _is_irn_keep(const ir_node *node) {
585 return is_op_keep(_get_irn_op(node));
588 static inline int _is_irn_start_block_placed(const ir_node *node) {
589 return is_op_start_block_placed(_get_irn_op(node));
592 static inline int _is_irn_machine_op(const ir_node *node) {
593 return is_op_machine(_get_irn_op(node));
596 static inline int _is_irn_machine_operand(const ir_node *node) {
597 return is_op_machine_operand(_get_irn_op(node));
600 static inline int _is_irn_machine_user(const ir_node *node, unsigned n) {
601 return is_op_machine_user(_get_irn_op(node), n);
604 static inline cond_jmp_predicate _get_Cond_jmp_pred(const ir_node *node) {
605 assert(_get_irn_op(node) == op_Cond);
606 return node->attr.cond.jmp_pred;
609 static inline void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
610 assert(_get_irn_op(node) == op_Cond);
611 node->attr.cond.jmp_pred = pred;
614 static inline void *_get_irn_generic_attr(ir_node *node) {
618 static inline const void *_get_irn_generic_attr_const(const ir_node *node) {
622 static inline unsigned _get_irn_idx(const ir_node *node) {
623 return node->node_idx;
626 static inline dbg_info *_get_irn_dbg_info(const ir_node *n) {
628 } /* get_irn_dbg_info */
630 static inline void _set_irn_dbg_info(ir_node *n, dbg_info *db) {
635 * Sets the Phi list of a block.
638 _set_Block_phis(ir_node *block, ir_node *phi) {
639 assert(_is_Block(block));
640 assert(phi == NULL || _is_Phi(phi));
641 block->attr.block.phis = phi;
645 * Returns the link of a node.
646 * Intern version of libFirm.
648 static inline ir_node *
649 _get_Block_phis(const ir_node *block) {
650 assert(_is_Block(block));
651 return block->attr.block.phis;
655 * Sets the next link of a Phi.
658 _set_Phi_next(ir_node *phi, ir_node *next) {
659 assert(_is_Phi(phi));
660 phi->attr.phi.next = next;
664 * Returns the link of a node.
665 * Intern version of libFirm.
667 static inline ir_node *
668 _get_Phi_next(const ir_node *phi) {
669 assert(_is_Phi(phi));
670 return phi->attr.phi.next;
673 /** Add a Phi node to the list of Block Phi's. */
675 _add_Block_phi(ir_node *block, ir_node *phi) {
676 _set_Phi_next(phi, _get_Block_phis(block));
677 _set_Block_phis(block, phi);
680 /** Get the Block mark (single bit). */
681 static inline unsigned
682 _get_Block_mark(const ir_node *block) {
683 assert(_is_Block(block));
684 return block->attr.block.marked;
687 /** Set the Block mark (single bit). */
689 _set_Block_mark(ir_node *block, unsigned mark) {
690 assert(_is_Block(block));
691 block->attr.block.marked = mark;
694 /** Returns non-zero if a node is a routine parameter. */
696 _is_arg_Proj(const ir_node *node) {
699 node = get_Proj_pred(node);
702 return pn_Start_T_args == get_Proj_proj(node) && is_Start(get_Proj_pred(node));
706 /* this section MUST contain all inline functions */
707 #define is_ir_node(thing) _is_ir_node(thing)
708 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
709 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
710 #define get_irn_arity(node) _get_irn_arity(node)
711 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
712 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
713 #define get_irn_n(node, n) _get_irn_n(node, n)
714 #define get_irn_mode(node) _get_irn_mode(node)
715 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
716 #define get_irn_op(node) _get_irn_op(node)
717 #define set_irn_op(node, op) _set_irn_op(node, op)
718 #define get_irn_opcode(node) _get_irn_opcode(node)
719 #define get_irn_visited(node) _get_irn_visited(node)
720 #define set_irn_visited(node, v) _set_irn_visited(node, v)
721 #define mark_irn_visited(node) _mark_irn_visited(node)
722 #define irn_visited(node) _irn_visited(node)
723 #define irn_visited_else_mark(node) _irn_visited_else_mark(node)
724 #define set_irn_link(node, link) _set_irn_link(node, link)
725 #define get_irn_link(node) _get_irn_link(node)
726 #define get_irn_pinned(node) _get_irn_pinned(node)
727 #define is_irn_pinned_in_irg(node) _is_irn_pinned_in_irg(node)
728 #define is_unop(node) _is_unop(node)
729 #define is_binop(node) _is_binop(node)
730 #define is_Proj(node) _is_Proj(node)
731 #define is_Phi(node) _is_Phi(node)
732 #define is_strictConv(node) _is_strictConv(node)
733 #define is_SymConst_addr_ent(node) _is_SymConst_addr_ent(node)
734 #define is_no_Block(node) _is_no_Block(node)
735 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
736 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
737 #define get_Block_cfgpred_block(node, pos) _get_Block_cfgpred_block(node, pos)
738 #define get_Block_block_visited(node) _get_Block_block_visited(node)
739 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
740 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
741 #define Block_block_visited(node) _Block_block_visited(node)
742 #define set_Block_dead(block) _set_Block_dead(block)
743 #define is_Block_dead(block) _is_Block_dead(block)
744 #define get_Block_irg(block) _get_Block_irg(block)
745 #define get_Const_tarval(node) _get_Const_tarval(node)
746 #define is_Const_null(node) _is_Const_null(node)
747 #define is_Const_one(node) _is_Const_one(node)
748 #define is_Const_all_one(node) _is_Const_all_one(node)
749 #define is_irn_forking(node) _is_irn_forking(node)
750 #define copy_node_attr(oldn,newn) _copy_node_attr(oldn,newn)
751 #define get_irn_type(node) _get_irn_type(node)
752 #define get_irn_type_attr(node) _get_irn_type_attr(node)
753 #define get_irn_entity_attr(node) _get_irn_entity_attr(node)
754 #define is_irn_constlike(node) _is_irn_constlike(node)
755 #define is_irn_always_opt(node) _is_irn_always_opt(node)
756 #define is_irn_keep(node) _is_irn_keep(node)
757 #define is_irn_start_block_placed(node) _is_irn_start_block_placed(node)
758 #define is_irn_machine_op(node) _is_irn_machine_op(node)
759 #define is_irn_machine_operand(node) _is_irn_machine_operand(node)
760 #define is_irn_machine_user(node, n) _is_irn_machine_user(node, n)
761 #define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
762 #define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
763 #define get_irn_generic_attr(node) _get_irn_generic_attr(node)
764 #define get_irn_generic_attr_const(node) _get_irn_generic_attr_const(node)
765 #define get_irn_idx(node) _get_irn_idx(node)
767 #define get_irn_deps(node) _get_irn_deps(node)
768 #define set_irn_dep(node, pos, dep) _set_irn_dep(node, pos, dep)
769 #define get_irn_dep(node, pos) _get_irn_dep(node, pos)
771 #define get_irn_ins_or_deps(node) _get_irn_ins_or_deps(node)
772 #define get_irn_in_or_dep(node, pos) _get_irn_in_or_dep(node, pos)
774 #define get_irn_dbg_info(node) _get_irn_dbg_info(node)
775 #define set_irn_dbg_info(node, db) _set_irn_dbg_info(node, db)
777 #define set_Block_phis(block, phi) _set_Block_phis(block, phi)
778 #define get_Block_phis(block) _get_Block_phis(block)
779 #define add_Block_phi(block, phi) _add_Block_phi(block, phi)
780 #define get_Block_mark(block) _get_Block_mark(block)
781 #define set_Block_mark(block, mark) _set_Block_mark(block, mark)
783 #define set_Phi_next(node, phi) _set_Phi_next(node, phi)
784 #define get_Phi_next(node) _get_Phi_next(node)
786 #define is_arg_Proj(node) _is_arg_Proj(node)