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.
118 _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 *
127 _get_irn_op(const ir_node *node) {
133 _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. */
141 _copy_node_attr(const ir_node *old_node, ir_node *new_node) {
142 ir_op *op = _get_irn_op(old_node);
144 /* must always exist */
145 op->ops.copy_attr(old_node, new_node);
149 * Gets the opcode of a node.
150 * Intern version for libFirm.
152 static inline unsigned
153 _get_irn_opcode(const ir_node *node) {
154 assert(k_ir_node == get_kind(node));
156 return node->op->code;
160 * Returns the number of predecessors without the block predecessor.
161 * Intern version for libFirm.
164 _get_irn_intra_arity(const ir_node *node) {
166 return ARR_LEN(node->in) - 1;
170 * Returns the number of predecessors without the block predecessor.
171 * Intern version for libFirm.
174 _get_irn_inter_arity(const ir_node *node) {
176 if (_get_irn_op(node) == op_Filter) {
177 assert(node->attr.filter.in_cg);
178 return ARR_LEN(node->attr.filter.in_cg) - 1;
179 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
180 return ARR_LEN(node->attr.block.in_cg) - 1;
182 return _get_irn_intra_arity(node);
185 #ifdef INTERPROCEDURAL_VIEW
187 * Returns the number of predecessors without the block predecessor.
188 * Intern version for libFirm.
190 extern int (*_get_irn_arity)(const ir_node *node);
194 #define _get_irn_arity(n) _get_irn_intra_arity(n)
198 * Intern version for libFirm.
200 static inline ir_node *
201 _get_irn_intra_n(const ir_node *node, int n) {
205 assert(-1 <= n && n < _get_irn_intra_arity(node));
207 nn = node->in[n + 1];
209 /* only block and Anchor inputs are allowed to be NULL */
210 assert((node->op == op_Anchor || n == -1) && "NULL input of a node");
213 if (nn->op != op_Id) return nn;
215 return (node->in[n + 1] = skip_Id(nn));
219 * Intern version for libFirm.
221 static inline ir_node*
222 _get_irn_inter_n(const ir_node *node, int n) {
223 assert(node); assert(-1 <= n && n < _get_irn_inter_arity(node));
225 /* handle Filter and Block specially */
226 if (_get_irn_op(node) == op_Filter) {
227 assert(node->attr.filter.in_cg);
228 return (node->attr.filter.in_cg[n + 1] = skip_Id(node->attr.filter.in_cg[n + 1]));
229 } else if (_get_irn_op(node) == op_Block && node->attr.block.in_cg) {
230 return (node->attr.block.in_cg[n + 1] = skip_Id(node->attr.block.in_cg[n + 1]));
233 return _get_irn_intra_n(node, n);
237 * returns a hash value for a node
239 static inline unsigned hash_irn(const ir_node *node)
241 return (unsigned) get_irn_idx(node);
245 * Access to the predecessors of a node.
246 * To iterate over the operands iterate from 0 to i < get_irn_arity(),
247 * to iterate including the Block predecessor iterate from i = -1 to
249 * If it is a block, the entry -1 is NULL.
250 * Intern version for libFirm.
252 #ifdef INTERPROCEDURAL_VIEW
253 extern ir_node *(*_get_irn_n)(const ir_node *node, int n);
255 #define _get_irn_n(n,i) _get_irn_intra_n(n,i)
258 static inline int _get_irn_deps(const ir_node *node) {
259 return node->deps ? ARR_LEN(node->deps) : 0;
262 static inline ir_node *_get_irn_dep(const ir_node *node, int pos) {
263 assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
264 assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
265 return node->deps[pos];
269 _set_irn_dep(ir_node *node, int pos, ir_node *dep) {
272 assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
273 assert(pos >= 0 && pos < ARR_LEN(node->deps) && "dependency index out of range");
274 old = node->deps[pos];
275 node->deps[pos] = dep;
276 edges_notify_edge_kind(node, pos, dep, old, EDGE_KIND_DEP, get_irn_irg(node));
281 _get_irn_ins_or_deps(const ir_node *irn) {
282 return _get_irn_deps(irn) + _get_irn_arity(irn);
285 static inline ir_node *
286 _get_irn_in_or_dep(const ir_node *irn, int pos) {
287 int n_in = get_irn_arity(irn);
288 return pos < n_in ? get_irn_n(irn, pos) : get_irn_dep(irn, pos - n_in);
292 * Gets the mode of a node.
293 * Intern version for libFirm.
295 static inline ir_mode *
296 _get_irn_mode(const ir_node *node) {
302 * Sets the mode of a node.
303 * Intern version of libFirm.
306 _set_irn_mode(ir_node *node, ir_mode *mode) {
312 * Gets the visited counter of a node.
313 * Intern version for libFirm.
315 static inline ir_visited_t
316 _get_irn_visited(const ir_node *node) {
318 return node->visited;
322 * Sets the visited counter of a node.
323 * Intern version for libFirm.
326 _set_irn_visited(ir_node *node, ir_visited_t visited) {
328 node->visited = visited;
332 * Mark a node as visited in a graph.
333 * Intern version for libFirm.
336 _mark_irn_visited(ir_node *node) {
338 node->visited = current_ir_graph->visited;
342 * Returns non-zero if a node of was visited.
343 * Intern version for libFirm.
346 _irn_visited(const ir_node *node) {
348 return (node->visited >= current_ir_graph->visited);
352 _irn_visited_else_mark(ir_node *node) {
353 if (_irn_visited(node))
355 _mark_irn_visited(node);
360 * Sets the link of a node.
361 * Intern version of libFirm.
364 _set_irn_link(ir_node *node, void *link) {
370 * Returns the link of a node.
371 * Intern version of libFirm.
374 _get_irn_link(const ir_node *node) {
375 assert(node && _is_ir_node(node));
380 * Returns whether the node _always_ must be pinned.
381 * I.e., the node is not floating after global cse.
383 * Intern version of libFirm.
385 static inline op_pin_state
386 _get_irn_pinned(const ir_node *node) {
388 assert(node && _is_ir_node(node));
390 state = _get_op_pinned(_get_irn_op(node));
392 if (state >= op_pin_state_exc_pinned)
393 return get_opt_fragile_ops() ? node->attr.except.pin_state : op_pin_state_pinned;
397 static inline op_pin_state
398 _is_irn_pinned_in_irg(const ir_node *node) {
399 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
400 return get_irn_pinned(node);
401 return op_pin_state_pinned;
404 /* include generated code */
405 #include "gen_irnode.h"
408 _is_unop(const ir_node *node) {
409 assert(node && _is_ir_node(node));
410 return (node->op->opar == oparity_unary);
414 _is_binop(const ir_node *node) {
415 assert(node && _is_ir_node(node));
416 return (node->op->opar == oparity_binary);
420 _is_Phi(const ir_node *node) {
424 op = get_irn_op(node);
425 #ifdef INTERPROCEDURAL_VIEW
426 if (op == op_Filter) return get_interprocedural_view();
428 return (op == op_Phi);
432 _is_Proj(const ir_node *node) {
436 op = _get_irn_op(node);
437 #ifdef INTERPROCEDURAL_VIEW
438 if (op == op_Filter) return !get_interprocedural_view();
440 return (op == op_Proj);
444 _is_strictConv(const ir_node *node) {
445 return _is_Conv(node) && get_Conv_strict(node);
449 _is_SymConst_addr_ent(const ir_node *node) {
450 return is_SymConst(node) && get_SymConst_kind(node) == symconst_addr_ent;
454 _is_no_Block(const ir_node *node) {
455 assert(node && _is_ir_node(node));
456 return (_get_irn_op(node) != op_Block);
460 _get_Block_n_cfgpreds(const ir_node *node) {
461 assert(_is_Block(node));
462 return _get_irn_arity(node);
465 static inline ir_node *
466 _get_Block_cfgpred(const ir_node *node, int pos) {
467 assert(0 <= pos && pos < get_irn_arity(node));
468 assert(_is_Block(node));
469 return _get_irn_n(node, pos);
472 /* Get the predecessor block.
474 * Returns the block corresponding to the predecessor pos.
476 * There are several ambiguities we resolve with this function:
477 * - The direct predecessor can be a Proj, which is not pinned.
478 * We walk from the predecessor to the next pinned node
479 * (skip_Proj) and return the block that node is in.
480 * - If we encounter the Bad node, this function does not return
481 * the Start block, but the Bad node.
483 static inline ir_node *
484 _get_Block_cfgpred_block(const ir_node *node, int pos) {
485 ir_node *res = skip_Proj(get_Block_cfgpred(node, pos));
487 res = get_nodes_block(res);
491 static inline ir_visited_t
492 _get_Block_block_visited(const ir_node *node) {
493 assert(node->op == op_Block);
494 return node->attr.block.block_visited;
498 _set_Block_block_visited(ir_node *node, ir_visited_t visit) {
499 assert(node->op == op_Block);
500 node->attr.block.block_visited = visit;
503 /* For this current_ir_graph must be set. */
505 _mark_Block_block_visited(ir_node *node) {
506 assert(node->op == op_Block);
507 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
511 _Block_block_visited(const ir_node *node) {
512 assert(node->op == op_Block);
513 return (node->attr.block.block_visited >= get_irg_block_visited(current_ir_graph));
516 static inline ir_node *
517 _set_Block_dead(ir_node *block) {
518 assert(_get_irn_op(block) == op_Block);
519 block->attr.block.dom.dom_depth = -1;
520 block->attr.block.is_dead = 1;
525 _is_Block_dead(const ir_node *block) {
526 ir_op *op = _get_irn_op(block);
531 assert(op == op_Block);
532 return block->attr.block.is_dead;
536 static inline ir_graph *
537 _get_Block_irg(const ir_node *block) {
538 assert(is_Block(block) || is_Bad(block));
539 return block->attr.irg.irg;
542 static inline tarval *_get_Const_tarval(const ir_node *node) {
543 assert(_get_irn_op(node) == op_Const);
544 return node->attr.con.tv;
547 static inline int _is_Const_null(const ir_node *node) {
548 return tarval_is_null(_get_Const_tarval(node));
551 static inline int _is_Const_one(const ir_node *node) {
552 return tarval_is_one(_get_Const_tarval(node));
555 static inline int _is_Const_all_one(const ir_node *node) {
556 return tarval_is_all_one(_get_Const_tarval(node));
559 static inline int _is_irn_forking(const ir_node *node) {
560 return is_op_forking(_get_irn_op(node));
563 static inline ir_type *_get_irn_type(ir_node *node) {
564 return _get_irn_op(node)->ops.get_type(node);
567 static inline ir_type *_get_irn_type_attr(ir_node *node) {
568 return _get_irn_op(node)->ops.get_type_attr(node);
571 static inline ir_entity *_get_irn_entity_attr(ir_node *node) {
572 return _get_irn_op(node)->ops.get_entity_attr(node);
575 static inline int _is_irn_constlike(const ir_node *node) {
576 return is_op_constlike(_get_irn_op(node));
579 static inline int _is_irn_always_opt(const ir_node *node) {
580 return is_op_always_opt(_get_irn_op(node));
583 static inline int _is_irn_keep(const ir_node *node) {
584 return is_op_keep(_get_irn_op(node));
587 static inline int _is_irn_start_block_placed(const ir_node *node) {
588 return is_op_start_block_placed(_get_irn_op(node));
591 static inline int _is_irn_machine_op(const ir_node *node) {
592 return is_op_machine(_get_irn_op(node));
595 static inline int _is_irn_machine_operand(const ir_node *node) {
596 return is_op_machine_operand(_get_irn_op(node));
599 static inline int _is_irn_machine_user(const ir_node *node, unsigned n) {
600 return is_op_machine_user(_get_irn_op(node), n);
603 static inline cond_jmp_predicate _get_Cond_jmp_pred(const ir_node *node) {
604 assert(_get_irn_op(node) == op_Cond);
605 return node->attr.cond.jmp_pred;
608 static inline void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
609 assert(_get_irn_op(node) == op_Cond);
610 node->attr.cond.jmp_pred = pred;
613 static inline void *_get_irn_generic_attr(ir_node *node) {
617 static inline const void *_get_irn_generic_attr_const(const ir_node *node) {
621 static inline unsigned _get_irn_idx(const ir_node *node) {
622 return node->node_idx;
625 static inline dbg_info *_get_irn_dbg_info(const ir_node *n) {
627 } /* get_irn_dbg_info */
629 static inline void _set_irn_dbg_info(ir_node *n, dbg_info *db) {
634 * Sets the Phi list of a block.
637 _set_Block_phis(ir_node *block, ir_node *phi) {
638 assert(_is_Block(block));
639 assert(phi == NULL || _is_Phi(phi));
640 block->attr.block.phis = phi;
644 * Returns the link of a node.
645 * Intern version of libFirm.
647 static inline ir_node *
648 _get_Block_phis(const ir_node *block) {
649 assert(_is_Block(block));
650 return block->attr.block.phis;
654 * Sets the next link of a Phi.
657 _set_Phi_next(ir_node *phi, ir_node *next) {
658 assert(_is_Phi(phi));
659 phi->attr.phi.next = next;
663 * Returns the link of a node.
664 * Intern version of libFirm.
666 static inline ir_node *
667 _get_Phi_next(const ir_node *phi) {
668 assert(_is_Phi(phi));
669 return phi->attr.phi.next;
672 /** Add a Phi node to the list of Block Phi's. */
674 _add_Block_phi(ir_node *block, ir_node *phi) {
675 _set_Phi_next(phi, _get_Block_phis(block));
676 _set_Block_phis(block, phi);
679 /** Get the Block mark (single bit). */
680 static inline unsigned
681 _get_Block_mark(const ir_node *block) {
682 assert(_is_Block(block));
683 return block->attr.block.marked;
686 /** Set the Block mark (single bit). */
688 _set_Block_mark(ir_node *block, unsigned mark) {
689 assert(_is_Block(block));
690 block->attr.block.marked = mark;
693 /** Returns non-zero if a node is a routine parameter. */
695 _is_arg_Proj(const ir_node *node) {
698 node = get_Proj_pred(node);
701 return pn_Start_T_args == get_Proj_proj(node) && is_Start(get_Proj_pred(node));
705 /* this section MUST contain all inline functions */
706 #define is_ir_node(thing) _is_ir_node(thing)
707 #define get_irn_intra_arity(node) _get_irn_intra_arity(node)
708 #define get_irn_inter_arity(node) _get_irn_inter_arity(node)
709 #define get_irn_arity(node) _get_irn_arity(node)
710 #define get_irn_intra_n(node, n) _get_irn_intra_n(node, n)
711 #define get_irn_inter_n(node, n) _get_irn_inter_n(node, n)
712 #define get_irn_n(node, n) _get_irn_n(node, n)
713 #define get_irn_mode(node) _get_irn_mode(node)
714 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
715 #define get_irn_op(node) _get_irn_op(node)
716 #define set_irn_op(node, op) _set_irn_op(node, op)
717 #define get_irn_opcode(node) _get_irn_opcode(node)
718 #define get_irn_visited(node) _get_irn_visited(node)
719 #define set_irn_visited(node, v) _set_irn_visited(node, v)
720 #define mark_irn_visited(node) _mark_irn_visited(node)
721 #define irn_visited(node) _irn_visited(node)
722 #define irn_visited_else_mark(node) _irn_visited_else_mark(node)
723 #define set_irn_link(node, link) _set_irn_link(node, link)
724 #define get_irn_link(node) _get_irn_link(node)
725 #define get_irn_pinned(node) _get_irn_pinned(node)
726 #define is_irn_pinned_in_irg(node) _is_irn_pinned_in_irg(node)
727 #define is_unop(node) _is_unop(node)
728 #define is_binop(node) _is_binop(node)
729 #define is_Proj(node) _is_Proj(node)
730 #define is_Phi(node) _is_Phi(node)
731 #define is_strictConv(node) _is_strictConv(node)
732 #define is_SymConst_addr_ent(node) _is_SymConst_addr_ent(node)
733 #define is_no_Block(node) _is_no_Block(node)
734 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
735 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
736 #define get_Block_cfgpred_block(node, pos) _get_Block_cfgpred_block(node, pos)
737 #define get_Block_block_visited(node) _get_Block_block_visited(node)
738 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
739 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
740 #define Block_block_visited(node) _Block_block_visited(node)
741 #define set_Block_dead(block) _set_Block_dead(block)
742 #define is_Block_dead(block) _is_Block_dead(block)
743 #define get_Block_irg(block) _get_Block_irg(block)
744 #define get_Const_tarval(node) _get_Const_tarval(node)
745 #define is_Const_null(node) _is_Const_null(node)
746 #define is_Const_one(node) _is_Const_one(node)
747 #define is_Const_all_one(node) _is_Const_all_one(node)
748 #define is_irn_forking(node) _is_irn_forking(node)
749 #define copy_node_attr(oldn,newn) _copy_node_attr(oldn,newn)
750 #define get_irn_type(node) _get_irn_type(node)
751 #define get_irn_type_attr(node) _get_irn_type_attr(node)
752 #define get_irn_entity_attr(node) _get_irn_entity_attr(node)
753 #define is_irn_constlike(node) _is_irn_constlike(node)
754 #define is_irn_always_opt(node) _is_irn_always_opt(node)
755 #define is_irn_keep(node) _is_irn_keep(node)
756 #define is_irn_start_block_placed(node) _is_irn_start_block_placed(node)
757 #define is_irn_machine_op(node) _is_irn_machine_op(node)
758 #define is_irn_machine_operand(node) _is_irn_machine_operand(node)
759 #define is_irn_machine_user(node, n) _is_irn_machine_user(node, n)
760 #define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
761 #define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
762 #define get_irn_generic_attr(node) _get_irn_generic_attr(node)
763 #define get_irn_generic_attr_const(node) _get_irn_generic_attr_const(node)
764 #define get_irn_idx(node) _get_irn_idx(node)
766 #define get_irn_deps(node) _get_irn_deps(node)
767 #define set_irn_dep(node, pos, dep) _set_irn_dep(node, pos, dep)
768 #define get_irn_dep(node, pos) _get_irn_dep(node, pos)
770 #define get_irn_ins_or_deps(node) _get_irn_ins_or_deps(node)
771 #define get_irn_in_or_dep(node, pos) _get_irn_in_or_dep(node, pos)
773 #define get_irn_dbg_info(node) _get_irn_dbg_info(node)
774 #define set_irn_dbg_info(node, db) _set_irn_dbg_info(node, db)
776 #define set_Block_phis(block, phi) _set_Block_phis(block, phi)
777 #define get_Block_phis(block) _get_Block_phis(block)
778 #define add_Block_phi(block, phi) _add_Block_phi(block, phi)
779 #define get_Block_mark(block) _get_Block_mark(block)
780 #define set_Block_mark(block, mark) _set_Block_mark(block, mark)
782 #define set_Phi_next(node, phi) _set_Phi_next(node, phi)
783 #define get_Phi_next(node) _get_Phi_next(node)
785 #define is_arg_Proj(node) _is_arg_Proj(node)