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"
36 /* the famous clear_link implementation. */
37 void firm_clear_link(ir_node *n, void *env) {
39 set_irn_link(n, NULL);
43 * Copies a node to a new irg. The Ins of the new node point to
44 * the predecessors on the old irg. n->link points to the new node.
46 * Does NOT copy standard nodes like Start, End etc that are fixed
47 * in an irg. Instead, the corresponding nodes of the new irg are returned.
48 * Note further, that the new nodes have no block.
51 copy_irn_to_irg(ir_node *n, ir_graph *irg) {
52 ir_op *op = get_irn_op(n);
56 /* do not copy standard nodes */
58 nn = get_irg_bad(irg);
59 else if (op == op_NoMem)
60 n = get_irg_no_mem(irg);
61 else if (op == op_Block) {
62 old_irg = get_irn_irg(n);
64 if (n == get_irg_start_block(old_irg))
65 nn = get_irg_start_block(irg);
66 else if (n == get_irg_end_block(old_irg))
67 nn = get_irg_end_block(irg);
69 else if (op == op_Start)
70 nn = get_irg_start(irg);
71 else if (op == op_End)
72 nn = get_irg_end(irg);
73 else if (op == op_Proj) {
74 old_irg = get_irn_irg(n);
76 if (n == get_irg_initial_exec(old_irg))
77 nn = get_irg_initial_exec(irg);
78 else if (n == get_irg_frame(old_irg))
79 nn = get_irg_frame(irg);
80 else if (n == get_irg_initial_mem(old_irg))
81 nn = get_irg_initial_mem(irg);
82 else if (n == get_irg_args(old_irg))
83 nn = get_irg_args(irg);
91 nn = new_ir_node(get_irn_dbg_info(n),
93 NULL, /* no block yet, will be set later */
100 /* Copy the attributes. These might point to additional data. If this
101 was allocated on the old obstack the pointers now are dangling. This
102 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
103 copy_node_attr(n, nn);
104 new_backedge_info(nn);
107 /* fix the irg for blocks */
109 nn->attr.block.irg = irg;
111 /* we cannot allow blocks WITHOUT macroblock input */
112 set_Block_MacroBlock(nn, get_Block_MacroBlock(n));
117 * Creates an exact copy of a node.
118 * The copy resides in the same graph in the same block.
120 ir_node *exact_copy(const ir_node *n) {
121 ir_graph *irg = get_irn_irg(n);
122 ir_node *res, *block = NULL;
125 block = get_nodes_block(n);
127 res = new_ir_node(get_irn_dbg_info(n),
136 /* Copy the attributes. These might point to additional data. If this
137 was allocated on the old obstack the pointers now are dangling. This
138 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
139 copy_node_attr(n, res);
140 new_backedge_info(res);
143 set_Block_MacroBlock(res, get_Block_MacroBlock(n));
149 * Dump a pset containing Firm objects.
151 void firm_pset_dump(pset *set) {
154 foreach_pset(set, obj) {
155 ir_fprintf(stderr, "%+F\n", obj);