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 call_attr *get_irn_call_attr (ir_node *node);
52 sel_attr *get_irn_sel_attr (ir_node *node);
53 phi_attr *get_irn_phi_attr (ir_node *node);
54 block_attr *get_irn_block_attr (ir_node *node);
55 load_attr *get_irn_load_attr (ir_node *node);
56 store_attr *get_irn_store_attr (ir_node *node);
57 except_attr *get_irn_except_attr (ir_node *node);
58 divmod_attr *get_irn_divmod_attr (ir_node *node);
59 builtin_attr *get_irn_builtin_attr (ir_node *node);
63 * The amount of additional space for custom data to be allocated upon creating a new node.
65 extern unsigned firm_add_node_size;
68 * Sets the get_type operation for an ir_op_ops.
70 * @param code the opcode for the default operation
71 * @param ops the operations initialized
76 ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops);
79 * Sets the get_type_attr operation for an ir_op_ops.
81 * @param code the opcode for the default operation
82 * @param ops the operations initialized
87 ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops);
90 * Sets the get_entity_attr operation for an ir_op_ops.
92 * @param code the opcode for the default operation
93 * @param ops the operations initialized
98 ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops);
101 * Returns an array with the predecessors of the Block. Depending on
102 * the implementation of the graph data structure this can be a copy of
103 * the internal representation of predecessors as well as the internal
104 * array itself. Therefore writing to this array might obstruct the IR.
106 ir_node **get_Block_cfgpred_arr(ir_node *node);
108 /*-------------------------------------------------------------------*/
109 /* These function are most used in libfirm. Give them as static */
110 /* functions so they can be inlined. */
111 /*-------------------------------------------------------------------*/
114 * Checks whether a pointer points to a ir node.
115 * Intern version for libFirm.
117 static inline int _is_ir_node(const void *thing)
119 return (get_kind(thing) == k_ir_node);
123 * Gets the op of a node.
124 * Intern version for libFirm.
126 static inline ir_op *_get_irn_op(const ir_node *node)
132 static inline void _set_irn_op(ir_node *node, ir_op *op)
138 /** Copies all attributes stored in the old node to the new node.
139 Assumes both have the same opcode and sufficient size. */
140 static inline void _copy_node_attr(ir_graph *irg, const ir_node *old_node,
143 ir_op *op = _get_irn_op(old_node);
145 /* must always exist */
146 op->ops.copy_attr(irg, old_node, new_node);
150 * Gets the opcode of a node.
151 * Intern version for libFirm.
153 static inline unsigned _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.
164 static inline int _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.
174 static inline int _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 *_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 *_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];
269 static inline void _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));
281 static inline int _get_irn_ins_or_deps(const ir_node *irn)
283 return _get_irn_deps(irn) + _get_irn_arity(irn);
286 static inline ir_node *_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 *_get_irn_mode(const ir_node *node)
303 * Sets the mode of a node.
304 * Intern version of libFirm.
306 static inline void _set_irn_mode(ir_node *node, ir_mode *mode)
312 static inline ir_graph *_get_irn_irg(const ir_node *node)
315 * Do not use get_nodes_Block() here, because this
316 * will check the pinned state.
317 * However even a 'wrong' block is always in the proper
320 if (! is_Block(node))
321 node = get_irn_n(node, -1);
322 /* note that get_Block_irg() can handle Bad nodes */
323 return get_Block_irg(node);
327 * Gets the visited counter of a node.
328 * Intern version for libFirm.
330 static inline ir_visited_t _get_irn_visited(const ir_node *node)
333 return node->visited;
337 * Sets the visited counter of a node.
338 * Intern version for libFirm.
340 static inline void _set_irn_visited(ir_node *node, ir_visited_t visited)
343 node->visited = visited;
347 * Mark a node as visited in a graph.
348 * Intern version for libFirm.
350 static inline void _mark_irn_visited(ir_node *node)
352 node->visited = get_irn_irg(node)->visited;
356 * Returns non-zero if a node of was visited.
357 * Intern version for libFirm.
359 static inline int _irn_visited(const ir_node *node)
361 ir_graph *irg = get_irn_irg(node);
362 return node->visited >= irg->visited;
365 static inline int _irn_visited_else_mark(ir_node *node)
367 if (_irn_visited(node))
369 _mark_irn_visited(node);
374 * Sets the link of a node.
375 * Intern version of libFirm.
377 static inline void _set_irn_link(ir_node *node, void *link)
384 * Returns the link of a node.
385 * Intern version of libFirm.
387 static inline void *_get_irn_link(const ir_node *node)
389 assert(node && _is_ir_node(node));
394 * Returns whether the node _always_ must be pinned.
395 * I.e., the node is not floating after global cse.
397 * Intern version of libFirm.
399 static inline op_pin_state _get_irn_pinned(const ir_node *node)
402 assert(node && _is_ir_node(node));
404 state = _get_op_pinned(_get_irn_op(node));
406 if (state >= op_pin_state_exc_pinned)
407 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
411 static inline op_pin_state _is_irn_pinned_in_irg(const ir_node *node)
413 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
414 return get_irn_pinned(node);
415 return op_pin_state_pinned;
418 /* include generated code */
419 #include "gen_irnode.h"
421 static inline int _is_unop(const ir_node *node)
423 assert(node && _is_ir_node(node));
424 return (node->op->opar == oparity_unary);
427 static inline int _is_binop(const ir_node *node)
429 assert(node && _is_ir_node(node));
430 return (node->op->opar == oparity_binary);
433 static inline int _is_Phi(const ir_node *node)
438 op = get_irn_op(node);
439 #ifdef INTERPROCEDURAL_VIEW
440 if (op == op_Filter) return get_interprocedural_view();
442 return (op == op_Phi);
445 static inline int _is_Proj(const ir_node *node)
450 op = _get_irn_op(node);
451 #ifdef INTERPROCEDURAL_VIEW
452 if (op == op_Filter) return !get_interprocedural_view();
454 return (op == op_Proj);
457 static inline int _is_strictConv(const ir_node *node)
459 return _is_Conv(node) && get_Conv_strict(node);
462 static inline int _is_SymConst_addr_ent(const ir_node *node)
464 return is_SymConst(node) && get_SymConst_kind(node) == symconst_addr_ent;
467 static inline int _is_no_Block(const ir_node *node)
469 assert(node && _is_ir_node(node));
470 return (_get_irn_op(node) != op_Block);
473 static inline int _get_Block_n_cfgpreds(const ir_node *node)
475 assert(_is_Block(node));
476 return _get_irn_arity(node);
479 static inline ir_node *_get_Block_cfgpred(const ir_node *node, int pos)
481 assert(0 <= pos && pos < get_irn_arity(node));
482 assert(_is_Block(node));
483 return _get_irn_n(node, pos);
486 /* Get the predecessor block.
488 * Returns the block corresponding to the predecessor pos.
490 * There are several ambiguities we resolve with this function:
491 * - The direct predecessor can be a Proj, which is not pinned.
492 * We walk from the predecessor to the next pinned node
493 * (skip_Proj) and return the block that node is in.
494 * - If we encounter the Bad node, this function does not return
495 * the Start block, but the Bad node.
497 static inline ir_node *_get_Block_cfgpred_block(const ir_node *node, int pos)
499 ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
501 res = get_nodes_block(res);
505 static inline ir_visited_t _get_Block_block_visited(const ir_node *node)
507 assert(node->op == op_Block);
508 return node->attr.block.block_visited;
511 static inline void _set_Block_block_visited(ir_node *node, ir_visited_t visit)
513 assert(node->op == op_Block);
514 node->attr.block.block_visited = visit;
517 /* For this current_ir_graph must be set. */
518 static inline void _mark_Block_block_visited(ir_node *node)
520 ir_graph *irg = get_Block_irg(node);
521 node->attr.block.block_visited = get_irg_block_visited(irg);
524 static inline int _Block_block_visited(const ir_node *node)
526 ir_graph *irg = get_Block_irg(node);
527 return node->attr.block.block_visited >= get_irg_block_visited(irg);
530 static inline ir_node *_set_Block_dead(ir_node *block)
532 assert(_get_irn_op(block) == op_Block);
533 block->attr.block.dom.dom_depth = -1;
534 block->attr.block.is_dead = 1;
538 static inline int _is_Block_dead(const ir_node *block)
540 ir_op *op = _get_irn_op(block);
545 assert(op == op_Block);
546 return block->attr.block.is_dead;
550 static inline ir_graph *_get_Block_irg(const ir_node *block)
552 assert(is_Block(block) || is_Bad(block));
553 return block->attr.irg.irg;
556 static inline tarval *_get_Const_tarval(const ir_node *node) {
557 assert(_get_irn_op(node) == op_Const);
558 return node->attr.con.tv;
561 static inline int _is_Const_null(const ir_node *node) {
562 return tarval_is_null(_get_Const_tarval(node));
565 static inline int _is_Const_one(const ir_node *node) {
566 return tarval_is_one(_get_Const_tarval(node));
569 static inline int _is_Const_all_one(const ir_node *node) {
570 return tarval_is_all_one(_get_Const_tarval(node));
573 static inline int _is_irn_forking(const ir_node *node) {
574 return is_op_forking(_get_irn_op(node));
577 static inline ir_type *_get_irn_type(ir_node *node) {
578 return _get_irn_op(node)->ops.get_type(node);
581 static inline ir_type *_get_irn_type_attr(ir_node *node) {
582 return _get_irn_op(node)->ops.get_type_attr(node);
585 static inline ir_entity *_get_irn_entity_attr(ir_node *node) {
586 return _get_irn_op(node)->ops.get_entity_attr(node);
589 static inline int _is_irn_constlike(const ir_node *node) {
590 return is_op_constlike(_get_irn_op(node));
593 static inline int _is_irn_always_opt(const ir_node *node) {
594 return is_op_always_opt(_get_irn_op(node));
597 static inline int _is_irn_keep(const ir_node *node) {
598 return is_op_keep(_get_irn_op(node));
601 static inline int _is_irn_start_block_placed(const ir_node *node) {
602 return is_op_start_block_placed(_get_irn_op(node));
605 static inline int _is_irn_machine_op(const ir_node *node) {
606 return is_op_machine(_get_irn_op(node));
609 static inline int _is_irn_machine_operand(const ir_node *node) {
610 return is_op_machine_operand(_get_irn_op(node));
613 static inline int _is_irn_machine_user(const ir_node *node, unsigned n) {
614 return is_op_machine_user(_get_irn_op(node), n);
617 static inline int _is_irn_cse_neutral(const ir_node *node) {
618 return is_op_cse_neutral(_get_irn_op(node));
621 static inline cond_jmp_predicate _get_Cond_jmp_pred(const ir_node *node) {
622 assert(_get_irn_op(node) == op_Cond);
623 return node->attr.cond.jmp_pred;
626 static inline void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
627 assert(_get_irn_op(node) == op_Cond);
628 node->attr.cond.jmp_pred = pred;
631 static inline void *_get_irn_generic_attr(ir_node *node) {
635 static inline const void *_get_irn_generic_attr_const(const ir_node *node) {
639 static inline unsigned _get_irn_idx(const ir_node *node) {
640 return node->node_idx;
643 static inline dbg_info *_get_irn_dbg_info(const ir_node *n) {
645 } /* get_irn_dbg_info */
647 static inline void _set_irn_dbg_info(ir_node *n, dbg_info *db) {
652 * Sets the Phi list of a block.
654 static inline void _set_Block_phis(ir_node *block, ir_node *phi)
656 assert(_is_Block(block));
657 assert(phi == NULL || _is_Phi(phi));
658 block->attr.block.phis = phi;
662 * Returns the link of a node.
663 * Intern version of libFirm.
665 static inline ir_node *_get_Block_phis(const ir_node *block)
667 assert(_is_Block(block));
668 return block->attr.block.phis;
672 * Sets the next link of a Phi.
674 static inline void _set_Phi_next(ir_node *phi, ir_node *next)
676 assert(_is_Phi(phi));
677 phi->attr.phi.next = next;
681 * Returns the link of a node.
682 * Intern version of libFirm.
684 static inline ir_node *_get_Phi_next(const ir_node *phi)
686 assert(_is_Phi(phi));
687 return phi->attr.phi.next;
690 /** Add a Phi node to the list of Block Phi's. */
691 static inline void _add_Block_phi(ir_node *block, ir_node *phi)
693 _set_Phi_next(phi, _get_Block_phis(block));
694 _set_Block_phis(block, phi);
697 /** Get the Block mark (single bit). */
698 static inline unsigned _get_Block_mark(const ir_node *block)
700 assert(_is_Block(block));
701 return block->attr.block.marked;
704 /** Set the Block mark (single bit). */
705 static inline void _set_Block_mark(ir_node *block, unsigned mark)
707 assert(_is_Block(block));
708 block->attr.block.marked = mark;
711 /** Returns non-zero if a node is a routine parameter. */
712 static inline int _is_arg_Proj(const ir_node *node)
716 node = get_Proj_pred(node);
719 return pn_Start_T_args == get_Proj_proj(node) && is_Start(get_Proj_pred(node));
723 /* this section MUST contain all inline functions */
724 #define is_ir_node(thing) _is_ir_node(thing)
725 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
726 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
727 #define get_irn_arity(node) _get_irn_arity(node)
728 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
729 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
730 #define get_irn_n(node, n) _get_irn_n(node, n)
731 #define get_irn_mode(node) _get_irn_mode(node)
732 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
733 #define get_irn_irg(node) _get_irn_irg(node)
734 #define get_irn_op(node) _get_irn_op(node)
735 #define set_irn_op(node, op) _set_irn_op(node, op)
736 #define get_irn_opcode(node) _get_irn_opcode(node)
737 #define get_irn_visited(node) _get_irn_visited(node)
738 #define set_irn_visited(node, v) _set_irn_visited(node, v)
739 #define mark_irn_visited(node) _mark_irn_visited(node)
740 #define irn_visited(node) _irn_visited(node)
741 #define irn_visited_else_mark(node) _irn_visited_else_mark(node)
742 #define set_irn_link(node, link) _set_irn_link(node, link)
743 #define get_irn_link(node) _get_irn_link(node)
744 #define get_irn_pinned(node) _get_irn_pinned(node)
745 #define is_irn_pinned_in_irg(node) _is_irn_pinned_in_irg(node)
746 #define is_unop(node) _is_unop(node)
747 #define is_binop(node) _is_binop(node)
748 #define is_Proj(node) _is_Proj(node)
749 #define is_Phi(node) _is_Phi(node)
750 #define is_strictConv(node) _is_strictConv(node)
751 #define is_SymConst_addr_ent(node) _is_SymConst_addr_ent(node)
752 #define is_no_Block(node) _is_no_Block(node)
753 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
754 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
755 #define get_Block_cfgpred_block(node, pos) _get_Block_cfgpred_block(node, pos)
756 #define get_Block_block_visited(node) _get_Block_block_visited(node)
757 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
758 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
759 #define Block_block_visited(node) _Block_block_visited(node)
760 #define set_Block_dead(block) _set_Block_dead(block)
761 #define is_Block_dead(block) _is_Block_dead(block)
762 #define get_Block_irg(block) _get_Block_irg(block)
763 #define get_Const_tarval(node) _get_Const_tarval(node)
764 #define is_Const_null(node) _is_Const_null(node)
765 #define is_Const_one(node) _is_Const_one(node)
766 #define is_Const_all_one(node) _is_Const_all_one(node)
767 #define is_irn_forking(node) _is_irn_forking(node)
768 #define copy_node_attr(irg,oldn,newn) _copy_node_attr(irg,oldn,newn)
769 #define get_irn_type(node) _get_irn_type(node)
770 #define get_irn_type_attr(node) _get_irn_type_attr(node)
771 #define get_irn_entity_attr(node) _get_irn_entity_attr(node)
772 #define is_irn_constlike(node) _is_irn_constlike(node)
773 #define is_irn_always_opt(node) _is_irn_always_opt(node)
774 #define is_irn_keep(node) _is_irn_keep(node)
775 #define is_irn_start_block_placed(node) _is_irn_start_block_placed(node)
776 #define is_irn_machine_op(node) _is_irn_machine_op(node)
777 #define is_irn_machine_operand(node) _is_irn_machine_operand(node)
778 #define is_irn_machine_user(node, n) _is_irn_machine_user(node, n)
779 #define is_irn_cse_neutral(node) _is_irn_cse_neutral(node)
780 #define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
781 #define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
782 #define get_irn_generic_attr(node) _get_irn_generic_attr(node)
783 #define get_irn_generic_attr_const(node) _get_irn_generic_attr_const(node)
784 #define get_irn_idx(node) _get_irn_idx(node)
786 #define get_irn_deps(node) _get_irn_deps(node)
787 #define set_irn_dep(node, pos, dep) _set_irn_dep(node, pos, dep)
788 #define get_irn_dep(node, pos) _get_irn_dep(node, pos)
790 #define get_irn_ins_or_deps(node) _get_irn_ins_or_deps(node)
791 #define get_irn_in_or_dep(node, pos) _get_irn_in_or_dep(node, pos)
793 #define get_irn_dbg_info(node) _get_irn_dbg_info(node)
794 #define set_irn_dbg_info(node, db) _set_irn_dbg_info(node, db)
796 #define set_Block_phis(block, phi) _set_Block_phis(block, phi)
797 #define get_Block_phis(block) _get_Block_phis(block)
798 #define add_Block_phi(block, phi) _add_Block_phi(block, phi)
799 #define get_Block_mark(block) _get_Block_mark(block)
800 #define set_Block_mark(block, mark) _set_Block_mark(block, mark)
802 #define set_Phi_next(node, phi) _set_Phi_next(node, phi)
803 #define get_Phi_next(node) _get_Phi_next(node)
805 #define is_arg_Proj(node) _is_arg_Proj(node)