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) {
40 set_irn_link(n, NULL);
43 /* the famous clear_node_and_phi_links() implementation. */
44 void firm_clear_node_and_phi_links(ir_node *n, void *env) {
46 set_irn_link(n, NULL);
48 set_Block_phis(n, NULL);
50 set_Phi_next(n, NULL);
54 * Copies a node to a new irg. The Ins of the new node point to
55 * the predecessors on the old irg. n->link points to the new node.
57 * Does NOT copy standard nodes like Start, End etc that are fixed
58 * in an irg. Instead, the corresponding nodes of the new irg are returned.
59 * Note further, that the new nodes have no block.
62 copy_irn_to_irg(ir_node *n, ir_graph *irg) {
63 ir_op *op = get_irn_op(n);
67 /* do not copy standard nodes */
69 nn = get_irg_bad(irg);
70 else if (op == op_NoMem)
71 n = get_irg_no_mem(irg);
72 else if (op == op_Block) {
73 old_irg = get_irn_irg(n);
75 if (n == get_irg_start_block(old_irg))
76 nn = get_irg_start_block(irg);
77 else if (n == get_irg_end_block(old_irg))
78 nn = get_irg_end_block(irg);
80 else if (op == op_Start)
81 nn = get_irg_start(irg);
82 else if (op == op_End)
83 nn = get_irg_end(irg);
84 else if (op == op_Proj) {
85 old_irg = get_irn_irg(n);
87 if (n == get_irg_initial_exec(old_irg))
88 nn = get_irg_initial_exec(irg);
89 else if (n == get_irg_frame(old_irg))
90 nn = get_irg_frame(irg);
91 else if (n == get_irg_initial_mem(old_irg))
92 nn = get_irg_initial_mem(irg);
93 else if (n == get_irg_args(old_irg))
94 nn = get_irg_args(irg);
102 nn = new_ir_node(get_irn_dbg_info(n),
104 NULL, /* no block yet, will be set later */
111 /* Copy the attributes. These might point to additional data. If this
112 was allocated on the old obstack the pointers now are dangling. This
113 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
114 copy_node_attr(n, nn);
115 new_backedge_info(nn);
118 /* fix the irg for blocks */
120 nn->attr.block.irg.irg = irg;
122 /* we cannot allow blocks WITHOUT macroblock input */
123 set_Block_MacroBlock(nn, get_Block_MacroBlock(n));
128 * Creates an exact copy of a node.
129 * The copy resides in the same graph in the same block.
131 ir_node *exact_copy(const ir_node *n) {
132 ir_graph *irg = get_irn_irg(n);
133 ir_node *res, *block = NULL;
136 block = get_nodes_block(n);
138 res = new_ir_node(get_irn_dbg_info(n),
147 /* Copy the attributes. These might point to additional data. If this
148 was allocated on the old obstack the pointers now are dangling. This
149 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
150 copy_node_attr(n, res);
151 new_backedge_info(res);
154 set_Block_MacroBlock(res, get_Block_MacroBlock(n));
160 * Dump a pset containing Firm objects.
162 void firm_pset_dump(pset *set) {
165 foreach_pset(set, obj) {
166 ir_fprintf(stderr, "%+F\n", obj);