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"
35 #include "iredges_t.h"
38 * Returns the array with the ins. The content of the array may not be
40 * Note that this function returns the whole in array including the
41 * block predecessor. So, it is NOT symmetric with set_irn_in().
43 ir_node **get_irn_in (const ir_node *node);
46 * The amount of additional space for custom data to be allocated upon creating a new node.
48 extern unsigned firm_add_node_size;
51 * Sets the get_type_attr operation for an ir_op_ops.
53 * @param code the opcode for the default operation
54 * @param ops the operations initialized
59 ir_op_ops *firm_set_default_get_type_attr(unsigned code, ir_op_ops *ops);
62 * Sets the get_entity_attr operation for an ir_op_ops.
64 * @param code the opcode for the default operation
65 * @param ops the operations initialized
70 ir_op_ops *firm_set_default_get_entity_attr(unsigned code, ir_op_ops *ops);
73 * Returns an array with the predecessors of the Block. Depending on
74 * the implementation of the graph data structure this can be a copy of
75 * the internal representation of predecessors as well as the internal
76 * array itself. Therefore writing to this array might obstruct the IR.
78 ir_node **get_Block_cfgpred_arr(ir_node *node);
80 /*-------------------------------------------------------------------*/
81 /* These function are most used in libfirm. Give them as static */
82 /* functions so they can be inlined. */
83 /*-------------------------------------------------------------------*/
86 * Checks whether a pointer points to a ir node.
87 * Intern version for libFirm.
89 static inline int _is_ir_node(const void *thing)
91 return (get_kind(thing) == k_ir_node);
95 * Gets the op of a node.
96 * Intern version for libFirm.
98 static inline ir_op *_get_irn_op(const ir_node *node)
104 static inline void _set_irn_op(ir_node *node, ir_op *op)
110 /** Copies all attributes stored in the old node to the new node.
111 Assumes both have the same opcode and sufficient size. */
112 static inline void _copy_node_attr(ir_graph *irg, const ir_node *old_node,
115 ir_op *op = _get_irn_op(old_node);
117 /* must always exist */
118 op->ops.copy_attr(irg, old_node, new_node);
122 * Gets the opcode of a node.
123 * Intern version for libFirm.
125 static inline unsigned _get_irn_opcode(const ir_node *node)
127 assert(k_ir_node == get_kind(node));
129 return node->op->code;
133 * Returns the number of predecessors without the block predecessor.
134 * Intern version for libFirm.
136 static inline int _get_irn_arity(const ir_node *node)
138 return (int)(ARR_LEN(node->in) - 1);
142 * Intern version for libFirm.
144 static inline ir_node *_get_irn_n(const ir_node *node, int n)
148 assert(-1 <= n && n < _get_irn_arity(node));
150 nn = node->in[n + 1];
151 if (nn->op != op_Id) return nn;
153 return (node->in[n + 1] = skip_Id(nn));
157 * returns a hash value for a node
159 static inline unsigned hash_irn(const ir_node *node)
161 return (unsigned) get_irn_idx(node);
164 static inline int _get_irn_deps(const ir_node *node) {
165 return node->deps ? (int)ARR_LEN(node->deps) : 0;
168 static inline ir_node *_get_irn_dep(const ir_node *node, int pos) {
169 assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
170 assert(pos >= 0 && pos < (int)ARR_LEN(node->deps) && "dependency index out of range");
171 return node->deps[pos];
174 /* forward declaration outside iredges_t.h to avoid circular include problems */
175 void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_edge_kind_t kind, ir_graph *irg);
177 static inline void _set_irn_dep(ir_node *node, int pos, ir_node *dep)
181 assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
182 assert(pos >= 0 && pos < (int)ARR_LEN(node->deps) && "dependency index out of range");
183 old = node->deps[pos];
184 node->deps[pos] = dep;
185 edges_notify_edge_kind(node, pos, dep, old, EDGE_KIND_DEP, get_irn_irg(node));
189 static inline int _get_irn_ins_or_deps(const ir_node *irn)
191 return _get_irn_deps(irn) + _get_irn_arity(irn);
194 static inline ir_node *_get_irn_in_or_dep(const ir_node *irn, int pos)
196 int n_in = get_irn_arity(irn);
197 return pos < n_in ? get_irn_n(irn, pos) : get_irn_dep(irn, pos - n_in);
201 * Gets the mode of a node.
202 * Intern version for libFirm.
204 static inline ir_mode *_get_irn_mode(const ir_node *node)
211 * Sets the mode of a node.
212 * Intern version of libFirm.
214 static inline void _set_irn_mode(ir_node *node, ir_mode *mode)
220 static inline int ir_has_irg_ref(const ir_node *node)
222 return is_Block(node) || is_Bad(node) || is_Anchor(node);
225 static inline ir_graph *_get_irn_irg(const ir_node *node)
228 * Do not use get_nodes_block() here, because this
229 * will check the pinned state.
230 * However even a 'wrong' block is always in the proper irg.
232 if (! is_Block(node))
233 node = get_irn_n(node, -1);
234 assert(ir_has_irg_ref(node));
235 return node->attr.irg.irg;
238 static inline ir_node *_get_nodes_block(const ir_node *node)
240 assert(!is_Block(node));
241 return get_irn_n(node, -1);
245 * Gets the visited counter of a node.
246 * Intern version for libFirm.
248 static inline ir_visited_t _get_irn_visited(const ir_node *node)
251 return node->visited;
255 * Sets the visited counter of a node.
256 * Intern version for libFirm.
258 static inline void _set_irn_visited(ir_node *node, ir_visited_t visited)
261 node->visited = visited;
265 * Mark a node as visited in a graph.
266 * Intern version for libFirm.
268 static inline void _mark_irn_visited(ir_node *node)
270 node->visited = get_irn_irg(node)->visited;
274 * Returns non-zero if a node of was visited.
275 * Intern version for libFirm.
277 static inline int _irn_visited(const ir_node *node)
279 ir_graph *irg = get_irn_irg(node);
280 return node->visited >= irg->visited;
283 static inline int _irn_visited_else_mark(ir_node *node)
285 if (_irn_visited(node))
287 _mark_irn_visited(node);
292 * Sets the link of a node.
293 * Intern version of libFirm.
295 static inline void _set_irn_link(ir_node *node, void *link)
302 * Returns the link of a node.
303 * Intern version of libFirm.
305 static inline void *_get_irn_link(const ir_node *node)
307 assert(node && _is_ir_node(node));
312 * Returns whether the node _always_ must be pinned.
313 * I.e., the node is not floating after global cse.
315 * Intern version of libFirm.
317 static inline op_pin_state _get_irn_pinned(const ir_node *node)
320 assert(node && _is_ir_node(node));
322 state = _get_op_pinned(_get_irn_op(node));
324 if (state >= op_pin_state_exc_pinned)
325 return (op_pin_state)node->attr.except.pin_state;
330 static inline op_pin_state _is_irn_pinned_in_irg(const ir_node *node)
332 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
333 return get_irn_pinned(node);
334 return op_pin_state_pinned;
337 /* include generated code */
338 #include "gen_irnode.h"
340 static inline int _is_unop(const ir_node *node)
342 assert(node && _is_ir_node(node));
343 return (node->op->opar == oparity_unary);
346 static inline int _is_binop(const ir_node *node)
348 assert(node && _is_ir_node(node));
349 return (node->op->opar == oparity_binary);
352 static inline int _is_strictConv(const ir_node *node)
354 return _is_Conv(node) && get_Conv_strict(node);
357 static inline int _is_SymConst_addr_ent(const ir_node *node)
359 return is_SymConst(node) && get_SymConst_kind(node) == symconst_addr_ent;
362 static inline int _get_Block_n_cfgpreds(const ir_node *node)
364 assert(_is_Block(node));
365 return _get_irn_arity(node);
368 static inline ir_node *_get_Block_cfgpred(const ir_node *node, int pos)
370 assert(0 <= pos && pos < get_irn_arity(node));
371 assert(_is_Block(node));
372 return _get_irn_n(node, pos);
375 /* Get the predecessor block.
377 * Returns the block corresponding to the predecessor pos.
379 * There are several ambiguities we resolve with this function:
380 * - The direct predecessor can be a Proj, which is not pinned.
381 * We walk from the predecessor to the next pinned node
382 * (skip_Proj) and return the block that node is in.
383 * - If we encounter the Bad node, this function does not return
384 * the Start block, but the Bad node.
386 static inline ir_node *_get_Block_cfgpred_block(const ir_node *node, int pos)
388 ir_node *res = get_Block_cfgpred(node, pos);
390 /* must return a Bad with mode_BB! */
391 ir_graph *irg = get_irn_irg(node);
392 return new_r_Bad(irg, mode_BB);
394 return get_nodes_block(skip_Proj(res));
398 static inline ir_visited_t _get_Block_block_visited(const ir_node *node)
400 assert(is_Block(node));
401 return node->attr.block.block_visited;
404 static inline void _set_Block_block_visited(ir_node *node, ir_visited_t visit)
406 assert(is_Block(node));
407 node->attr.block.block_visited = visit;
410 static inline void _mark_Block_block_visited(ir_node *node)
412 ir_graph *irg = get_Block_irg(node);
413 node->attr.block.block_visited = get_irg_block_visited(irg);
416 static inline int _Block_block_visited(const ir_node *node)
418 ir_graph *irg = get_Block_irg(node);
419 return node->attr.block.block_visited >= get_irg_block_visited(irg);
422 static inline ir_graph *_get_Block_irg(const ir_node *block)
424 assert(is_Block(block));
425 return block->attr.irg.irg;
428 static inline ir_tarval *_get_Const_tarval(const ir_node *node) {
429 assert(_get_irn_op(node) == op_Const);
430 return node->attr.con.tarval;
433 static inline int _is_Const_null(const ir_node *node) {
434 return tarval_is_null(_get_Const_tarval(node));
437 static inline int _is_Const_one(const ir_node *node) {
438 return tarval_is_one(_get_Const_tarval(node));
441 static inline int _is_Const_all_one(const ir_node *node) {
442 return tarval_is_all_one(_get_Const_tarval(node));
445 static inline int _is_irn_forking(const ir_node *node) {
446 return is_op_forking(_get_irn_op(node));
449 static inline ir_type *_get_irn_type_attr(ir_node *node) {
450 return _get_irn_op(node)->ops.get_type_attr(node);
453 static inline ir_entity *_get_irn_entity_attr(ir_node *node) {
454 return _get_irn_op(node)->ops.get_entity_attr(node);
457 static inline int _is_irn_constlike(const ir_node *node) {
458 return is_op_constlike(_get_irn_op(node));
461 static inline int _is_irn_always_opt(const ir_node *node) {
462 return is_op_always_opt(_get_irn_op(node));
465 static inline int _is_irn_keep(const ir_node *node) {
466 return is_op_keep(_get_irn_op(node));
469 static inline int _is_irn_start_block_placed(const ir_node *node) {
470 return is_op_start_block_placed(_get_irn_op(node));
473 static inline int _is_irn_machine_op(const ir_node *node) {
474 return is_op_machine(_get_irn_op(node));
477 static inline int _is_irn_machine_operand(const ir_node *node) {
478 return is_op_machine_operand(_get_irn_op(node));
481 static inline int _is_irn_machine_user(const ir_node *node, unsigned n) {
482 return is_op_machine_user(_get_irn_op(node), n);
485 static inline int _is_irn_cse_neutral(const ir_node *node) {
486 return is_op_cse_neutral(_get_irn_op(node));
489 static inline cond_jmp_predicate _get_Cond_jmp_pred(const ir_node *node) {
490 assert(_get_irn_op(node) == op_Cond);
491 return node->attr.cond.jmp_pred;
494 static inline void _set_Cond_jmp_pred(ir_node *node, cond_jmp_predicate pred) {
495 assert(_get_irn_op(node) == op_Cond);
496 node->attr.cond.jmp_pred = pred;
499 static inline void *_get_irn_generic_attr(ir_node *node) {
503 static inline const void *_get_irn_generic_attr_const(const ir_node *node) {
507 static inline unsigned _get_irn_idx(const ir_node *node) {
508 return node->node_idx;
511 static inline dbg_info *_get_irn_dbg_info(const ir_node *n) {
515 static inline void _set_irn_dbg_info(ir_node *n, dbg_info *db) {
520 * Sets the Phi list of a block.
522 static inline void _set_Block_phis(ir_node *block, ir_node *phi)
524 assert(_is_Block(block));
525 assert(phi == NULL || _is_Phi(phi));
526 block->attr.block.phis = phi;
530 * Returns the link of a node.
531 * Intern version of libFirm.
533 static inline ir_node *_get_Block_phis(const ir_node *block)
535 assert(_is_Block(block));
536 return block->attr.block.phis;
539 static inline void _set_Phi_next(ir_node *phi, ir_node *next)
541 assert(_is_Phi(phi));
542 phi->attr.phi.next = next;
545 static inline ir_node *_get_Phi_next(const ir_node *phi)
547 assert(_is_Phi(phi));
548 return phi->attr.phi.next;
551 /** Add a Phi node to the list of Block Phi's. */
552 static inline void _add_Block_phi(ir_node *block, ir_node *phi)
554 assert(_is_Block(block));
555 _set_Phi_next(phi, _get_Block_phis(block));
556 _set_Block_phis(block, phi);
559 /** Get the Block mark (single bit). */
560 static inline unsigned _get_Block_mark(const ir_node *block)
562 assert(_is_Block(block));
563 return block->attr.block.marked;
566 /** Set the Block mark (single bit). */
567 static inline void _set_Block_mark(ir_node *block, unsigned mark)
569 assert(_is_Block(block));
570 block->attr.block.marked = mark;
573 /** Returns non-zero if a node is a routine parameter. */
574 static inline int _is_arg_Proj(const ir_node *node)
578 node = get_Proj_pred(node);
581 return pn_Start_T_args == get_Proj_proj(node) && is_Start(get_Proj_pred(node));
584 /** initialize ir_node module */
585 void init_irnode(void);
587 /* this section MUST contain all inline functions */
588 #define is_ir_node(thing) _is_ir_node(thing)
589 #define get_irn_arity(node) _get_irn_arity(node)
590 #define get_irn_n(node, n) _get_irn_n(node, n)
591 #define get_irn_mode(node) _get_irn_mode(node)
592 #define set_irn_mode(node, mode) _set_irn_mode(node, mode)
593 #define get_irn_irg(node) _get_irn_irg(node)
594 #define get_nodes_block(node) _get_nodes_block(node)
595 #define get_irn_op(node) _get_irn_op(node)
596 #define set_irn_op(node, op) _set_irn_op(node, op)
597 #define get_irn_opcode(node) _get_irn_opcode(node)
598 #define get_irn_visited(node) _get_irn_visited(node)
599 #define set_irn_visited(node, v) _set_irn_visited(node, v)
600 #define mark_irn_visited(node) _mark_irn_visited(node)
601 #define irn_visited(node) _irn_visited(node)
602 #define irn_visited_else_mark(node) _irn_visited_else_mark(node)
603 #define set_irn_link(node, link) _set_irn_link(node, link)
604 #define get_irn_link(node) _get_irn_link(node)
605 #define get_irn_pinned(node) _get_irn_pinned(node)
606 #define is_irn_pinned_in_irg(node) _is_irn_pinned_in_irg(node)
607 #define is_unop(node) _is_unop(node)
608 #define is_binop(node) _is_binop(node)
609 #define is_Proj(node) _is_Proj(node)
610 #define is_Phi(node) _is_Phi(node)
611 #define is_strictConv(node) _is_strictConv(node)
612 #define is_SymConst_addr_ent(node) _is_SymConst_addr_ent(node)
613 #define get_Block_n_cfgpreds(node) _get_Block_n_cfgpreds(node)
614 #define get_Block_cfgpred(node, pos) _get_Block_cfgpred(node, pos)
615 #define get_Block_cfgpred_block(node, pos) _get_Block_cfgpred_block(node, pos)
616 #define get_Block_block_visited(node) _get_Block_block_visited(node)
617 #define set_Block_block_visited(node, visit) _set_Block_block_visited(node, visit)
618 #define mark_Block_block_visited(node) _mark_Block_block_visited(node)
619 #define Block_block_visited(node) _Block_block_visited(node)
620 #define get_Block_irg(block) _get_Block_irg(block)
621 #define get_Const_tarval(node) _get_Const_tarval(node)
622 #define is_Const_null(node) _is_Const_null(node)
623 #define is_Const_one(node) _is_Const_one(node)
624 #define is_Const_all_one(node) _is_Const_all_one(node)
625 #define is_irn_forking(node) _is_irn_forking(node)
626 #define copy_node_attr(irg,oldn,newn) _copy_node_attr(irg,oldn,newn)
627 #define get_irn_type(node) _get_irn_type(node)
628 #define get_irn_type_attr(node) _get_irn_type_attr(node)
629 #define get_irn_entity_attr(node) _get_irn_entity_attr(node)
630 #define is_irn_constlike(node) _is_irn_constlike(node)
631 #define is_irn_always_opt(node) _is_irn_always_opt(node)
632 #define is_irn_keep(node) _is_irn_keep(node)
633 #define is_irn_start_block_placed(node) _is_irn_start_block_placed(node)
634 #define is_irn_machine_op(node) _is_irn_machine_op(node)
635 #define is_irn_machine_operand(node) _is_irn_machine_operand(node)
636 #define is_irn_machine_user(node, n) _is_irn_machine_user(node, n)
637 #define is_irn_cse_neutral(node) _is_irn_cse_neutral(node)
638 #define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
639 #define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
640 #define get_irn_generic_attr(node) _get_irn_generic_attr(node)
641 #define get_irn_generic_attr_const(node) _get_irn_generic_attr_const(node)
642 #define get_irn_idx(node) _get_irn_idx(node)
644 #define get_irn_deps(node) _get_irn_deps(node)
645 #define set_irn_dep(node, pos, dep) _set_irn_dep(node, pos, dep)
646 #define get_irn_dep(node, pos) _get_irn_dep(node, pos)
648 #define get_irn_ins_or_deps(node) _get_irn_ins_or_deps(node)
649 #define get_irn_in_or_dep(node, pos) _get_irn_in_or_dep(node, pos)
651 #define get_irn_dbg_info(node) _get_irn_dbg_info(node)
652 #define set_irn_dbg_info(node, db) _set_irn_dbg_info(node, db)
654 #define set_Block_phis(block, phi) _set_Block_phis(block, phi)
655 #define get_Block_phis(block) _get_Block_phis(block)
656 #define add_Block_phi(block, phi) _add_Block_phi(block, phi)
657 #define get_Block_mark(block) _get_Block_mark(block)
658 #define set_Block_mark(block, mark) _set_Block_mark(block, mark)
660 #define set_Phi_next(node, phi) _set_Phi_next(node, phi)
661 #define get_Phi_next(node) _get_Phi_next(node)
663 #define is_arg_Proj(node) _is_arg_Proj(node)