3 * File name: ir/ir/irtools.c
4 * Purpose: Some often needed tool-functions
9 * Copyright: (c) 1999-2005 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
18 #include "irbackedge_t.h"
21 /* the famous clear_link implementation. */
22 void firm_clear_link(ir_node *n, void *env) {
23 set_irn_link(n, NULL);
27 * Copies a node to a new irg. The Ins of the new node point to
28 * the predecessors on the old irg. n->link points to the new node.
30 * @param n The node to be copied
31 * @param irg the new irg
33 * Does NOT copy standard nodes like Start, End etc that are fixed
34 * in an irg. Instead, the corresponding nodes of the new irg are returned.
35 * Note further, that the new nodes have no block.
38 copy_irn_to_irg(ir_node *n, ir_graph *irg)
40 ir_op *op = get_irn_op(n);
44 /* do not copy standard nodes */
46 nn = get_irg_bad(irg);
47 else if (op == op_NoMem)
48 n = get_irg_no_mem(irg);
49 else if (op == op_Block) {
50 old_irg = get_irn_irg(n);
52 if (n == get_irg_start_block(old_irg))
53 nn = get_irg_start_block(irg);
54 else if (n == get_irg_end_block(old_irg))
55 nn = get_irg_end_block(irg);
57 else if (op == op_Start)
58 nn = get_irg_start(irg);
59 else if (op == op_End)
60 nn = get_irg_end(irg);
61 else if (op == op_Proj) {
62 old_irg = get_irn_irg(n);
64 if (n == get_irg_cstore(old_irg))
65 nn = get_irg_cstore(irg);
66 else if (n == get_irg_frame(old_irg))
67 nn = get_irg_frame(irg);
68 else if (n == get_irg_globals(old_irg))
69 nn = get_irg_globals(irg);
70 else if (n == get_irg_initial_mem(old_irg))
71 nn = get_irg_initial_mem(irg);
72 else if (n == get_irg_args(old_irg))
73 nn = get_irg_args(irg);
81 nn = new_ir_node(get_irn_dbg_info(n),
83 NULL, /* no block yet, will be set later */
90 /* Copy the attributes. These might point to additional data. If this
91 was allocated on the old obstack the pointers now are dangling. This
92 frees e.g. the memory of the graph_arr allocated in new_immBlock. */
93 copy_node_attr(n, nn);
94 new_backedge_info(nn);
97 /* fix the irg for blocks */
99 nn->attr.block.irg = irg;