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
25 #ifndef FIRM_IR_IRNODE_T_H
26 #define FIRM_IR_IRNODE_T_H
31 #include "irgraph_t.h"
34 #include "iredges_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 * The amount of additional space for custom data to be allocated upon creating a new node.
47 extern unsigned firm_add_node_size;
50 * Returns an array with the predecessors of the Block. Depending on
51 * the implementation of the graph data structure this can be a copy of
52 * the internal representation of predecessors as well as the internal
53 * array itself. Therefore writing to this array might obstruct the IR.
55 ir_node **get_Block_cfgpred_arr(ir_node *node);
57 /*-------------------------------------------------------------------*/
58 /* These function are most used in libfirm. Give them as static */
59 /* functions so they can be inlined. */
60 /*-------------------------------------------------------------------*/
63 * Checks whether a pointer points to a ir node.
64 * Intern version for libFirm.
66 static inline int is_ir_node_(const void *thing)
68 return (get_kind(thing) == k_ir_node);
72 * Gets the op of a node.
73 * Intern version for libFirm.
75 static inline ir_op *get_irn_op_(const ir_node *node)
81 static inline void set_irn_op_(ir_node *node, ir_op *op)
87 /** Copies all attributes stored in the old node to the new node.
88 Assumes both have the same opcode and sufficient size. */
89 static inline void copy_node_attr_(ir_graph *irg, const ir_node *old_node,
92 ir_op *op = get_irn_op_(old_node);
94 /* must always exist */
95 op->ops.copy_attr(irg, old_node, new_node);
99 * Gets the opcode of a node.
100 * Intern version for libFirm.
102 static inline unsigned get_irn_opcode_(const ir_node *node)
104 assert(k_ir_node == get_kind(node));
106 return node->op->code;
110 * Returns the number of predecessors without the block predecessor.
111 * Intern version for libFirm.
113 static inline int get_irn_arity_(const ir_node *node)
115 return (int)(ARR_LEN(node->in) - 1);
119 * Intern version for libFirm.
121 static inline ir_node *get_irn_n_(const ir_node *node, int n)
125 assert(-1 <= n && n < get_irn_arity_(node));
127 nn = node->in[n + 1];
128 if (nn->op != op_Id) return nn;
130 return (node->in[n + 1] = skip_Id(nn));
134 * returns a hash value for a node
136 static inline unsigned hash_irn(const ir_node *node)
138 return (unsigned) get_irn_idx(node);
141 static inline int get_irn_deps_(const ir_node *node)
143 return node->deps ? (int)ARR_LEN(node->deps) : 0;
146 static inline ir_node *get_irn_dep_(const ir_node *node, int pos)
148 assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
149 assert(pos >= 0 && pos < (int)ARR_LEN(node->deps) && "dependency index out of range");
150 return node->deps[pos];
153 /* forward declaration outside iredges_t.h to avoid circular include problems */
154 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);
156 static inline int get_irn_ins_or_deps_(const ir_node *irn)
158 return get_irn_deps_(irn) + get_irn_arity_(irn);
161 static inline ir_node *get_irn_in_or_dep_(const ir_node *irn, int pos)
163 int n_in = get_irn_arity(irn);
164 return pos < n_in ? get_irn_n(irn, pos) : get_irn_dep(irn, pos - n_in);
168 * Gets the mode of a node.
169 * Intern version for libFirm.
171 static inline ir_mode *get_irn_mode_(const ir_node *node)
178 * Sets the mode of a node.
179 * Intern version of libFirm.
181 static inline void set_irn_mode_(ir_node *node, ir_mode *mode)
187 static inline int ir_has_irg_ref(const ir_node *node)
189 return is_Block(node) || is_Bad(node) || is_Anchor(node);
192 static inline ir_graph *get_irn_irg_(const ir_node *node)
194 if (! is_Block(node))
195 node = get_nodes_block(node);
196 assert(ir_has_irg_ref(node));
197 return node->attr.irg.irg;
200 static inline ir_node *get_nodes_block_(const ir_node *node)
202 assert(!is_Block(node));
203 return get_irn_n(node, -1);
207 * Gets the visited counter of a node.
208 * Intern version for libFirm.
210 static inline ir_visited_t get_irn_visited_(const ir_node *node)
213 return node->visited;
217 * Sets the visited counter of a node.
218 * Intern version for libFirm.
220 static inline void set_irn_visited_(ir_node *node, ir_visited_t visited)
223 node->visited = visited;
227 * Mark a node as visited in a graph.
228 * Intern version for libFirm.
230 static inline void mark_irn_visited_(ir_node *node)
232 node->visited = get_irn_irg(node)->visited;
236 * Returns non-zero if a node of was visited.
237 * Intern version for libFirm.
239 static inline int irn_visited_(const ir_node *node)
241 ir_graph *irg = get_irn_irg(node);
242 return node->visited >= irg->visited;
245 static inline int irn_visited_else_mark_(ir_node *node)
247 if (irn_visited_(node))
249 mark_irn_visited_(node);
254 * Sets the link of a node.
255 * Intern version of libFirm.
257 static inline void set_irn_link_(ir_node *node, void *link)
264 * Returns the link of a node.
265 * Intern version of libFirm.
267 static inline void *get_irn_link_(const ir_node *node)
269 assert(node && is_ir_node_(node));
274 * Returns whether the node _always_ must be pinned.
275 * I.e., the node is not floating after global cse.
277 * Intern version of libFirm.
279 static inline op_pin_state get_irn_pinned_(const ir_node *node)
282 assert(node && is_ir_node_(node));
284 state = get_op_pinned_(get_irn_op_(node));
286 if (state >= op_pin_state_exc_pinned)
287 return (op_pin_state)node->attr.except.pin_state;
292 static inline op_pin_state is_irn_pinned_in_irg_(const ir_node *node)
294 if (get_irg_pinned(get_irn_irg(node)) == op_pin_state_floats)
295 return get_irn_pinned(node);
296 return op_pin_state_pinned;
299 /* include generated code */
300 #include "gen_irnode.h"
302 static inline int is_unop_(const ir_node *node)
304 assert(node && is_ir_node_(node));
305 return (node->op->opar == oparity_unary);
308 static inline int is_binop_(const ir_node *node)
310 assert(node && is_ir_node_(node));
311 return (node->op->opar == oparity_binary);
314 static inline int is_strictConv_(const ir_node *node)
316 return is_Conv_(node) && get_Conv_strict(node);
319 static inline int is_SymConst_addr_ent_(const ir_node *node)
321 return is_SymConst(node) && get_SymConst_kind(node) == symconst_addr_ent;
324 static inline int get_Block_n_cfgpreds_(const ir_node *node)
326 assert(is_Block_(node));
327 return get_irn_arity_(node);
330 static inline ir_node *get_Block_cfgpred_(const ir_node *node, int pos)
332 assert(is_Block_(node));
333 return get_irn_n_(node, pos);
336 /* Get the predecessor block.
338 * Returns the block corresponding to the predecessor pos.
340 * There are several ambiguities we resolve with this function:
341 * - The direct predecessor can be a Proj, which is not pinned.
342 * We walk from the predecessor to the next pinned node
343 * (skip_Proj) and return the block that node is in.
344 * - If we encounter the Bad node, this function does not return
345 * the Start block, but the Bad node.
347 static inline ir_node *get_Block_cfgpred_block_(const ir_node *node, int pos)
349 ir_node *res = get_Block_cfgpred(node, pos);
351 /* must return a Bad with mode_BB! */
352 ir_graph *irg = get_irn_irg(node);
353 return new_r_Bad(irg, mode_BB);
355 return get_nodes_block(skip_Proj(res));
359 static inline ir_visited_t get_Block_block_visited_(const ir_node *node)
361 assert(is_Block(node));
362 return node->attr.block.block_visited;
365 static inline void set_Block_block_visited_(ir_node *node, ir_visited_t visit)
367 assert(is_Block(node));
368 node->attr.block.block_visited = visit;
371 static inline void mark_Block_block_visited_(ir_node *node)
373 ir_graph *irg = get_Block_irg(node);
374 node->attr.block.block_visited = get_irg_block_visited(irg);
377 static inline int Block_block_visited_(const ir_node *node)
379 ir_graph *irg = get_Block_irg(node);
380 return node->attr.block.block_visited >= get_irg_block_visited(irg);
383 static inline ir_graph *get_Block_irg_(const ir_node *block)
385 assert(is_Block(block));
386 return block->attr.irg.irg;
389 static inline ir_tarval *get_Const_tarval_(const ir_node *node)
391 assert(get_irn_op_(node) == op_Const);
392 return node->attr.con.tarval;
395 static inline int is_Const_null_(const ir_node *node)
397 return tarval_is_null(get_Const_tarval_(node));
400 static inline int is_Const_one_(const ir_node *node)
402 return tarval_is_one(get_Const_tarval_(node));
405 static inline int is_Const_all_one_(const ir_node *node)
407 return tarval_is_all_one(get_Const_tarval_(node));
410 static inline int is_irn_forking_(const ir_node *node)
412 return is_op_forking(get_irn_op_(node));
415 static inline ir_type *get_irn_type_attr_(ir_node *node)
417 return get_irn_op_(node)->ops.get_type_attr(node);
420 static inline ir_entity *get_irn_entity_attr_(ir_node *node)
422 return get_irn_op_(node)->ops.get_entity_attr(node);
425 static inline int is_irn_constlike_(const ir_node *node)
427 return is_op_constlike(get_irn_op_(node));
430 static inline int is_irn_keep_(const ir_node *node)
432 return is_op_keep(get_irn_op_(node));
435 static inline int is_irn_start_block_placed_(const ir_node *node)
437 return is_op_start_block_placed(get_irn_op_(node));
440 static inline int is_irn_cse_neutral_(const ir_node *node)
442 return is_op_cse_neutral(get_irn_op_(node));
445 static inline cond_jmp_predicate get_Cond_jmp_pred_(const ir_node *node)
447 assert(get_irn_op_(node) == op_Cond);
448 return node->attr.cond.jmp_pred;
451 static inline void set_Cond_jmp_pred_(ir_node *node, cond_jmp_predicate pred)
453 assert(get_irn_op_(node) == op_Cond);
454 node->attr.cond.jmp_pred = pred;
457 static inline void *get_irn_generic_attr_(ir_node *node)
462 static inline const void *get_irn_generic_attr_const_(const ir_node *node)
467 static inline unsigned get_irn_idx_(const ir_node *node)
469 return node->node_idx;
472 static inline dbg_info *get_irn_dbg_info_(const ir_node *n)
477 static inline void set_irn_dbg_info_(ir_node *n, dbg_info *db)
483 * Sets the Phi list of a block.
485 static inline void set_Block_phis_(ir_node *block, ir_node *phi)
487 assert(is_Block_(block));
488 assert(phi == NULL || is_Phi_(phi));
489 block->attr.block.phis = phi;
493 * Returns the link of a node.
494 * Intern version of libFirm.
496 static inline ir_node *get_Block_phis_(const ir_node *block)
498 assert(is_Block_(block));
499 return block->attr.block.phis;
502 static inline void set_Phi_next_(ir_node *phi, ir_node *next)
504 assert(is_Phi_(phi));
505 phi->attr.phi.next = next;
508 static inline ir_node *get_Phi_next_(const ir_node *phi)
510 assert(is_Phi_(phi));
511 return phi->attr.phi.next;
514 /** Add a Phi node to the list of Block Phi's. */
515 static inline void add_Block_phi_(ir_node *block, ir_node *phi)
517 assert(is_Block_(block));
518 set_Phi_next_(phi, get_Block_phis_(block));
519 set_Block_phis_(block, phi);
522 /** Get the Block mark (single bit). */
523 static inline unsigned get_Block_mark_(const ir_node *block)
525 assert(is_Block_(block));
526 return block->attr.block.marked;
529 /** Set the Block mark (single bit). */
530 static inline void set_Block_mark_(ir_node *block, unsigned mark)
532 assert(is_Block_(block));
533 block->attr.block.marked = mark;
536 /** Returns non-zero if a node is a routine parameter. */
537 static inline int is_arg_Proj_(const ir_node *node)
541 node = get_Proj_pred(node);
544 return pn_Start_T_args == get_Proj_proj(node) && is_Start(get_Proj_pred(node));
547 static inline size_t ir_switch_table_get_n_entries_(const ir_switch_table *table)
549 return table->n_entries;
552 static inline ir_switch_table_entry *ir_switch_table_get_entry(
553 ir_switch_table *table, size_t entry)
555 assert(entry < table->n_entries);
556 return &table->entries[entry];
559 static inline const ir_switch_table_entry *ir_switch_table_get_entry_const(
560 const ir_switch_table *table, size_t entry)
562 assert(entry < table->n_entries);
563 return &table->entries[entry];
566 void ir_register_getter_ops(void);
568 /** initialize ir_node module */
569 void init_irnode(void);
571 /* this section MUST contain all inline functions */
572 #define is_ir_node(thing) is_ir_node_(thing)
573 #define get_irn_arity(node) get_irn_arity_(node)
574 #define get_irn_n(node, n) get_irn_n_(node, n)
575 #define get_irn_mode(node) get_irn_mode_(node)
576 #define set_irn_mode(node, mode) set_irn_mode_(node, mode)
577 #define get_irn_irg(node) get_irn_irg_(node)
578 #define get_nodes_block(node) get_nodes_block_(node)
579 #define get_irn_op(node) get_irn_op_(node)
580 #define set_irn_op(node, op) set_irn_op_(node, op)
581 #define get_irn_opcode(node) get_irn_opcode_(node)
582 #define get_irn_visited(node) get_irn_visited_(node)
583 #define set_irn_visited(node, v) set_irn_visited_(node, v)
584 #define mark_irn_visited(node) mark_irn_visited_(node)
585 #define irn_visited(node) irn_visited_(node)
586 #define irn_visited_else_mark(node) irn_visited_else_mark_(node)
587 #define set_irn_link(node, link) set_irn_link_(node, link)
588 #define get_irn_link(node) get_irn_link_(node)
589 #define get_irn_pinned(node) get_irn_pinned_(node)
590 #define is_irn_pinned_in_irg(node) is_irn_pinned_in_irg_(node)
591 #define is_unop(node) is_unop_(node)
592 #define is_binop(node) is_binop_(node)
593 #define is_Proj(node) is_Proj_(node)
594 #define is_Phi(node) is_Phi_(node)
595 #define is_strictConv(node) is_strictConv_(node)
596 #define is_SymConst_addr_ent(node) is_SymConst_addr_ent_(node)
597 #define get_Block_n_cfgpreds(node) get_Block_n_cfgpreds_(node)
598 #define get_Block_cfgpred(node, pos) get_Block_cfgpred_(node, pos)
599 #define get_Block_cfgpred_block(node, pos) get_Block_cfgpred_block_(node, pos)
600 #define get_Block_block_visited(node) get_Block_block_visited_(node)
601 #define set_Block_block_visited(node, visit) set_Block_block_visited_(node, visit)
602 #define mark_Block_block_visited(node) mark_Block_block_visited_(node)
603 #define Block_block_visited(node) Block_block_visited_(node)
604 #define get_Block_irg(block) get_Block_irg_(block)
605 #define get_Const_tarval(node) get_Const_tarval_(node)
606 #define is_Const_null(node) is_Const_null_(node)
607 #define is_Const_one(node) is_Const_one_(node)
608 #define is_Const_all_one(node) is_Const_all_one_(node)
609 #define is_irn_forking(node) is_irn_forking_(node)
610 #define copy_node_attr(irg,oldn,newn) copy_node_attr_(irg,oldn,newn)
611 #define get_irn_type(node) get_irn_type_(node)
612 #define get_irn_type_attr(node) get_irn_type_attr_(node)
613 #define get_irn_entity_attr(node) get_irn_entity_attr_(node)
614 #define is_irn_constlike(node) is_irn_constlike_(node)
615 #define is_irn_keep(node) is_irn_keep_(node)
616 #define is_irn_start_block_placed(node) is_irn_start_block_placed_(node)
617 #define is_irn_cse_neutral(node) is_irn_cse_neutral_(node)
618 #define get_Cond_jmp_pred(node) get_Cond_jmp_pred_(node)
619 #define set_Cond_jmp_pred(node, pred) set_Cond_jmp_pred_(node, pred)
620 #define get_irn_generic_attr(node) get_irn_generic_attr_(node)
621 #define get_irn_generic_attr_const(node) get_irn_generic_attr_const_(node)
622 #define get_irn_idx(node) get_irn_idx_(node)
624 #define get_irn_deps(node) get_irn_deps_(node)
625 #define get_irn_dep(node, pos) get_irn_dep_(node, pos)
627 #define get_irn_ins_or_deps(node) get_irn_ins_or_deps_(node)
628 #define get_irn_in_or_dep(node, pos) get_irn_in_or_dep_(node, pos)
630 #define get_irn_dbg_info(node) get_irn_dbg_info_(node)
631 #define set_irn_dbg_info(node, db) set_irn_dbg_info_(node, db)
633 #define set_Block_phis(block, phi) set_Block_phis_(block, phi)
634 #define get_Block_phis(block) get_Block_phis_(block)
635 #define add_Block_phi(block, phi) add_Block_phi_(block, phi)
636 #define get_Block_mark(block) get_Block_mark_(block)
637 #define set_Block_mark(block, mark) set_Block_mark_(block, mark)
639 #define set_Phi_next(node, phi) set_Phi_next_(node, phi)
640 #define get_Phi_next(node) get_Phi_next_(node)
642 #define is_arg_Proj(node) is_arg_Proj_(node)
643 #define ir_switch_table_get_n_entries(table) ir_switch_table_get_n_entries_(table)