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 Some often needed tool-functions
23 * @author Michael Beck
34 #include "irbackedge_t.h"
38 /* the famous clear_link implementation. */
39 void firm_clear_link(ir_node *n, void *env) {
41 set_irn_link(n, NULL);
45 * Copies a node to a new irg. The Ins of the new node point to
46 * the predecessors on the old irg. n->link points to the new node.
48 * Does NOT copy standard nodes like Start, End etc that are fixed
49 * in an irg. Instead, the corresponding nodes of the new irg are returned.
50 * Note further, that the new nodes have no block.
53 copy_irn_to_irg(ir_node *n, ir_graph *irg)
55 ir_op *op = get_irn_op(n);
59 /* do not copy standard nodes */
61 nn = get_irg_bad(irg);
62 else if (op == op_NoMem)
63 n = get_irg_no_mem(irg);
64 else if (op == op_Block) {
65 old_irg = get_irn_irg(n);
67 if (n == get_irg_start_block(old_irg))
68 nn = get_irg_start_block(irg);
69 else if (n == get_irg_end_block(old_irg))
70 nn = get_irg_end_block(irg);
72 else if (op == op_Start)
73 nn = get_irg_start(irg);
74 else if (op == op_End)
75 nn = get_irg_end(irg);
76 else if (op == op_Proj) {
77 old_irg = get_irn_irg(n);
79 if (n == get_irg_frame(old_irg))
80 nn = get_irg_frame(irg);
81 else if (n == get_irg_globals(old_irg))
82 nn = get_irg_globals(irg);
83 else if (n == get_irg_initial_mem(old_irg))
84 nn = get_irg_initial_mem(irg);
85 else if (n == get_irg_args(old_irg))
86 nn = get_irg_args(irg);
94 nn = new_ir_node(get_irn_dbg_info(n),
96 NULL, /* no block yet, will be set later */
103 /* Copy the attributes. These might point to additional data. If this
104 was allocated on the old obstack the pointers now are dangling. This
105 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
106 copy_node_attr(n, nn);
107 new_backedge_info(nn);
110 /* fix the irg for blocks */
112 nn->attr.block.irg = irg;
116 * Creates an exact copy of a node.
117 * The copy resides in the same graph in the same block.
119 ir_node *exact_copy(const ir_node *n) {
120 ir_graph *irg = get_irn_irg(n);
121 ir_node *res, *block = NULL;
124 block = get_irn_n(n, -1);
126 res = new_ir_node(get_irn_dbg_info(n),
135 /* Copy the attributes. These might point to additional data. If this
136 was allocated on the old obstack the pointers now are dangling. This
137 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
138 copy_node_attr(n, res);
139 new_backedge_info(res);
143 void firm_pset_dump(pset *set)
147 foreach_pset(set, obj) {
148 ir_fprintf(stderr, "%+F\n", obj);