2 * Copyright (C) 1995-2007 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) {
40 set_irn_link(n, NULL);
44 * Copies a node to a new irg. The Ins of the new node point to
45 * the predecessors on the old irg. n->link points to the new node.
47 * Does NOT copy standard nodes like Start, End etc that are fixed
48 * in an irg. Instead, the corresponding nodes of the new irg are returned.
49 * Note further, that the new nodes have no block.
52 copy_irn_to_irg(ir_node *n, ir_graph *irg)
54 ir_op *op = get_irn_op(n);
58 /* do not copy standard nodes */
60 nn = get_irg_bad(irg);
61 else if (op == op_NoMem)
62 n = get_irg_no_mem(irg);
63 else if (op == op_Block) {
64 old_irg = get_irn_irg(n);
66 if (n == get_irg_start_block(old_irg))
67 nn = get_irg_start_block(irg);
68 else if (n == get_irg_end_block(old_irg))
69 nn = get_irg_end_block(irg);
71 else if (op == op_Start)
72 nn = get_irg_start(irg);
73 else if (op == op_End)
74 nn = get_irg_end(irg);
75 else if (op == op_Proj) {
76 old_irg = get_irn_irg(n);
78 if (n == get_irg_frame(old_irg))
79 nn = get_irg_frame(irg);
80 else if (n == get_irg_globals(old_irg))
81 nn = get_irg_globals(irg);
82 else if (n == get_irg_initial_mem(old_irg))
83 nn = get_irg_initial_mem(irg);
84 else if (n == get_irg_args(old_irg))
85 nn = get_irg_args(irg);
93 nn = new_ir_node(get_irn_dbg_info(n),
95 NULL, /* no block yet, will be set later */
102 /* Copy the attributes. These might point to additional data. If this
103 was allocated on the old obstack the pointers now are dangling. This
104 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
105 copy_node_attr(n, nn);
106 new_backedge_info(nn);
109 /* fix the irg for blocks */
111 nn->attr.block.irg = irg;
115 * Creates an exact copy of a node.
116 * The copy resides in the same graph in the same block.
118 ir_node *exact_copy(const ir_node *n) {
119 ir_graph *irg = get_irn_irg(n);
120 ir_node *res, *block = NULL;
123 block = get_nodes_block(n);
125 res = new_ir_node(get_irn_dbg_info(n),
134 /* Copy the attributes. These might point to additional data. If this
135 was allocated on the old obstack the pointers now are dangling. This
136 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
137 copy_node_attr(n, res);
138 new_backedge_info(res);
142 void firm_pset_dump(pset *set)
146 foreach_pset(set, obj) {
147 ir_fprintf(stderr, "%+F\n", obj);