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
32 #include "irbackedge_t.h"
37 /* the famous clear_link implementation. */
38 void firm_clear_link(ir_node *n, void *env)
41 set_irn_link(n, NULL);
44 /* the famous clear_node_and_phi_links() implementation. */
45 void firm_clear_node_and_phi_links(ir_node *n, void *env)
48 set_irn_link(n, NULL);
50 set_Block_phis(n, NULL);
52 set_Phi_next(n, NULL);
56 * Copies a node to a new irg. The Ins of the new node point to
57 * the predecessors on the old irg. n->link points to the new node.
59 * Does NOT copy standard nodes like Start, End etc that are fixed
60 * in an irg. Instead, the corresponding nodes of the new irg are returned.
61 * Note further, that the new nodes have no block.
63 void copy_irn_to_irg(ir_node *n, ir_graph *irg)
65 ir_op *op = get_irn_op(n);
69 /* do not copy standard nodes */
71 nn = get_irg_bad(irg);
72 else if (op == op_NoMem)
73 n = get_irg_no_mem(irg);
74 else if (op == op_Block) {
75 old_irg = get_irn_irg(n);
77 if (n == get_irg_start_block(old_irg))
78 nn = get_irg_start_block(irg);
79 else if (n == get_irg_end_block(old_irg))
80 nn = get_irg_end_block(irg);
82 else if (op == op_Start)
83 nn = get_irg_start(irg);
84 else if (op == op_End)
85 nn = get_irg_end(irg);
86 else if (op == op_Proj) {
87 old_irg = get_irn_irg(n);
89 if (n == get_irg_initial_exec(old_irg))
90 nn = get_irg_initial_exec(irg);
91 else if (n == get_irg_frame(old_irg))
92 nn = get_irg_frame(irg);
93 else if (n == get_irg_initial_mem(old_irg))
94 nn = get_irg_initial_mem(irg);
95 else if (n == get_irg_args(old_irg))
96 nn = get_irg_args(irg);
104 nn = new_ir_node(get_irn_dbg_info(n),
106 NULL, /* no block yet, will be set later */
113 /* Copy the attributes. These might point to additional data. If this
114 was allocated on the old obstack the pointers now are dangling. This
115 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
116 copy_node_attr(n, nn);
117 new_backedge_info(nn);
120 /* fix the irg for blocks */
122 nn->attr.block.irg.irg = irg;
124 /* we cannot allow blocks WITHOUT macroblock input */
125 set_Block_MacroBlock(nn, get_Block_MacroBlock(n));
130 * Creates an exact copy of a node.
131 * The copy resides in the same graph in the same block.
133 ir_node *exact_copy(const ir_node *n)
135 ir_graph *irg = get_irn_irg(n);
136 ir_node *res, *block = NULL;
139 block = get_nodes_block(n);
141 res = new_ir_node(get_irn_dbg_info(n),
150 /* Copy the attributes. These might point to additional data. If this
151 was allocated on the old obstack the pointers now are dangling. This
152 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
153 copy_node_attr(n, res);
154 new_backedge_info(res);
157 set_Block_MacroBlock(res, get_Block_MacroBlock(n));
163 * Dump a pset containing Firm objects.
165 void firm_pset_dump(pset *set)
169 foreach_pset(set, obj) {
170 ir_fprintf(stderr, "%+F\n", obj);