merge common graph copying code; move dead code elimination into an own file
authorMatthias Braun <matze@braunis.de>
Sun, 7 Mar 2010 22:21:24 +0000 (22:21 +0000)
committerMatthias Braun <matze@braunis.de>
Sun, 7 Mar 2010 22:21:24 +0000 (22:21 +0000)
[r27271]

include/libfirm/irgopt.h
include/libfirm/iroptimize.h
ir/be/beabi.c
ir/be/mips/bearch_mips.c
ir/common/irtools.c
ir/common/irtools.h
ir/ir/irgraph.c
ir/ir/iropt_t.h
ir/opt/dead_code_elimination.c [new file with mode: 0644]
ir/opt/ldstopt.c
ir/opt/opt_inline.c

index 6a17b9c..2bd9050 100644 (file)
@@ -65,122 +65,6 @@ int optimize_graph_df(ir_graph *irg);
  */
 ir_graph_pass_t *optimize_graph_df_pass(const char *name);
 
-/** Performs dead node elimination by copying the ir graph to a new obstack.
- *
- *  The major intention of this pass is to free memory occupied by
- *  dead nodes and outdated analyzes information.  Further this
- *  function removes Bad predecessors from Blocks and the corresponding
- *  inputs to Phi nodes.  This opens optimization potential for other
- *  optimizations.  Further this phase reduces dead Block<->Jmp
- *  self-cycles to Bad nodes.
- *
- *  Dead_node_elimination is only performed if options `optimize' and
- *  `opt_dead_node_elimination' are set.  The graph may
- *  not be in state phase_building.  The outs datasturcture is freed,
- *  the outs state set to outs_none.  Backedge information is conserved.
- *  Removes old attributes of nodes.  Sets link field to NULL.
- *  Callee information must be freed (irg_callee_info_none).
- *
- * @param irg  The graph to be optimized.
- */
-void dead_node_elimination(ir_graph *irg);
-
-/**
- * Creates an ir_graph pass for dead_node_elimination().
- *
- * @param name     the name of this pass or NULL
- *
- * @return  the newly created ir_graph pass
- */
-ir_graph_pass_t *dead_node_elimination_pass(const char *name);
-
-typedef struct _survive_dce_t survive_dce_t;
-
-/**
- * Make a new Survive DCE environment.
- */
-survive_dce_t *new_survive_dce(void);
-
-/**
- * Free a Survive DCE environment.
- */
-void free_survive_dce(survive_dce_t *sd);
-
-/**
- * Register a node pointer to be patched upon DCE.
- * When DCE occurs, the node pointer specified by @p place will be
- * patched to the new address of the node it is pointing to.
- *
- * @param sd    The Survive DCE environment.
- * @param place The address of the node pointer.
- */
-void survive_dce_register_irn(survive_dce_t *sd, ir_node **place);
-
-/** Inlines a method at the given call site.
- *
- *  Removes the call node and splits the basic block the call node
- *  belongs to.  Inserts a copy of the called graph between these nodes.
- *  Assumes that call is a Call node in current_ir_graph and that
- *  the type in the Call nodes type attribute is the same as the
- *  type of the called graph.
- *  Further it assumes that all Phi nodes in a block of current_ir_graph
- *  are assembled in a "link" list in the link field of the corresponding
- *  block nodes.  Further assumes that all Proj nodes are in a "link" list
- *  in the nodes producing the tuple.  (This is only an optical feature
- *  for the graph.)  Conserves this feature for the old
- *  nodes of the graph.  This precondition can be established by a call to
- *  collect_phisprojs(), see irgmod.h.
- *  As dead_node_elimination this function reduces dead Block<->Jmp
- *  self-cycles to Bad nodes.
- *
- *  Called_graph must be unequal to current_ir_graph.   Will not inline
- *  if they are equal.
- *  Sets visited masterflag in current_ir_graph to the max of the flag in
- *  current and called graph.
- *  Assumes that both, the called and the calling graph are in state
- *  "op_pin_state_pinned".
- *  It is recommended to call local_optimize_graph() after inlining as this
- *  function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
- *  combination as control flow operation.
- *
- *  @param call          the call node that should be inlined
- *  @param called_graph  the IR-graph that is called at call
- *
- *  @return zero if method could not be inlined (recursion for instance),
- *          non-zero if all went ok
- */
-int inline_method(ir_node *call, ir_graph *called_graph);
-
-/** Code Placement.
- *
- * Pins all floating nodes to a block where they
- * will be executed only if needed.   Depends on the flag opt_global_cse.
- * Graph may not be in phase_building.  Does not schedule control dead
- * code.  Uses dominator information which it computes if the irg is not
- * in state dom_consistent.  Destroys the out information as it moves nodes
- * to other blocks.  Optimizes Tuples in Control edges.
- * @todo This is not tested!
- *
- * Call remove_critical_cf_edges() before place_code().  This normalizes
- * the control flow graph so that for all operations a basic block exists
- * where they can be optimally placed.
- *
- * @todo A more powerful code placement would move operations past Phi nodes
- * out of loops.
- */
-void place_code(ir_graph *irg);
-
-/**
- * Creates an ir_graph pass for place_code().
- * This pass enables GCSE, runs optimize_graph_df() and finally
- * place_code();
- *
- * @param name     the name of this pass or NULL
- *
- * @return  the newly created ir_graph pass
- */
-ir_graph_pass_t *place_code_pass(const char *name);
-
 /** Places an empty basic block on critical control flow edges thereby
  * removing them.
  *
index cbb3ccd..9c080c8 100644 (file)
@@ -506,7 +506,7 @@ ir_graph_pass_t *remove_phi_cycles_pass(const char *name);
 
 
 /** A default threshold. */
-#define DEFAULT_CLONE_THRESHOLD 300
+#define DEFAULT_CLONE_THRESHOLD 20
 
 /**
  * Do procedure cloning. Evaluate a heuristic weight for every
@@ -978,4 +978,98 @@ void garbage_collect_entities(void);
 /** Pass for garbage_collect_entities */
 ir_prog_pass_t *garbage_collect_entities_pass(const char *name);
 
+/** Performs dead node elimination by copying the ir graph to a new obstack.
+ *
+ *  The major intention of this pass is to free memory occupied by
+ *  dead nodes and outdated analyzes information.  Further this
+ *  function removes Bad predecessors from Blocks and the corresponding
+ *  inputs to Phi nodes.  This opens optimization potential for other
+ *  optimizations.  Further this phase reduces dead Block<->Jmp
+ *  self-cycles to Bad nodes.
+ *
+ *  Dead_node_elimination is only performed if options `optimize' and
+ *  `opt_dead_node_elimination' are set.  The graph may
+ *  not be in state phase_building.  The outs datasturcture is freed,
+ *  the outs state set to outs_none.  Backedge information is conserved.
+ *  Removes old attributes of nodes.  Sets link field to NULL.
+ *  Callee information must be freed (irg_callee_info_none).
+ *
+ * @param irg  The graph to be optimized.
+ */
+void dead_node_elimination(ir_graph *irg);
+
+/**
+ * Creates an ir_graph pass for dead_node_elimination().
+ *
+ * @param name     the name of this pass or NULL
+ *
+ * @return  the newly created ir_graph pass
+ */
+ir_graph_pass_t *dead_node_elimination_pass(const char *name);
+
+/** Inlines a method at the given call site.
+ *
+ *  Removes the call node and splits the basic block the call node
+ *  belongs to.  Inserts a copy of the called graph between these nodes.
+ *  Assumes that call is a Call node in current_ir_graph and that
+ *  the type in the Call nodes type attribute is the same as the
+ *  type of the called graph.
+ *  Further it assumes that all Phi nodes in a block of current_ir_graph
+ *  are assembled in a "link" list in the link field of the corresponding
+ *  block nodes.  Further assumes that all Proj nodes are in a "link" list
+ *  in the nodes producing the tuple.  (This is only an optical feature
+ *  for the graph.)  Conserves this feature for the old
+ *  nodes of the graph.  This precondition can be established by a call to
+ *  collect_phisprojs(), see irgmod.h.
+ *  As dead_node_elimination this function reduces dead Block<->Jmp
+ *  self-cycles to Bad nodes.
+ *
+ *  Called_graph must be unequal to current_ir_graph.   Will not inline
+ *  if they are equal.
+ *  Sets visited masterflag in current_ir_graph to the max of the flag in
+ *  current and called graph.
+ *  Assumes that both, the called and the calling graph are in state
+ *  "op_pin_state_pinned".
+ *  It is recommended to call local_optimize_graph() after inlining as this
+ *  function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
+ *  combination as control flow operation.
+ *
+ *  @param call          the call node that should be inlined
+ *  @param called_graph  the IR-graph that is called at call
+ *
+ *  @return zero if method could not be inlined (recursion for instance),
+ *          non-zero if all went ok
+ */
+int inline_method(ir_node *call, ir_graph *called_graph);
+
+/** Code Placement.
+ *
+ * Pins all floating nodes to a block where they
+ * will be executed only if needed.   Depends on the flag opt_global_cse.
+ * Graph may not be in phase_building.  Does not schedule control dead
+ * code.  Uses dominator information which it computes if the irg is not
+ * in state dom_consistent.  Destroys the out information as it moves nodes
+ * to other blocks.  Optimizes Tuples in Control edges.
+ * @todo This is not tested!
+ *
+ * Call remove_critical_cf_edges() before place_code().  This normalizes
+ * the control flow graph so that for all operations a basic block exists
+ * where they can be optimally placed.
+ *
+ * @todo A more powerful code placement would move operations past Phi nodes
+ * out of loops.
+ */
+void place_code(ir_graph *irg);
+
+/**
+ * Creates an ir_graph pass for place_code().
+ * This pass enables GCSE, runs optimize_graph_df() and finally
+ * place_code();
+ *
+ * @param name     the name of this pass or NULL
+ *
+ * @return  the newly created ir_graph pass
+ */
+ir_graph_pass_t *place_code_pass(const char *name);
+
 #endif
index f4fe80d..e631e02 100644 (file)
@@ -39,6 +39,7 @@
 #include "irprintf_t.h"
 #include "irgopt.h"
 #include "irbitset.h"
+#include "iropt_t.h"
 #include "height.h"
 #include "pdeq.h"
 #include "irtools.h"
index 58529c6..2a0491f 100644 (file)
@@ -30,7 +30,7 @@
 #include "irprog.h"
 #include "irprintf.h"
 #include "ircons.h"
-#include "irgmod.h"
+#include "iroptimize.h"
 #include "irgopt.h"
 #include "irgwalk.h"
 #include "iredges.h"
index 4b17a34..d34c753 100644 (file)
 #include "irtools.h"
 #include "irprintf.h"
 #include "irpass_t.h"
+#include "iropt_t.h"
 
-/* the famous clear_link implementation. */
 void firm_clear_link(ir_node *n, void *env)
 {
        (void) env;
        set_irn_link(n, NULL);
 }
 
-/* the famous clear_node_and_phi_links() implementation. */
 void firm_clear_node_and_phi_links(ir_node *n, void *env)
 {
        (void) env;
@@ -52,14 +51,6 @@ void firm_clear_node_and_phi_links(ir_node *n, void *env)
                set_Phi_next(n, NULL);
 }
 
-/*
- * Copies a node to a new irg. The Ins of the new node point to
- * the predecessors on the old irg.  n->link points to the new node.
- *
- * Does NOT copy standard nodes like Start, End etc that are fixed
- * in an irg. Instead, the corresponding nodes of the new irg are returned.
- * Note further, that the new nodes have no block.
- */
 void copy_irn_to_irg(ir_node *n, ir_graph *irg)
 {
        ir_op *op = get_irn_op(n);
@@ -125,41 +116,93 @@ void copy_irn_to_irg(ir_node *n, ir_graph *irg)
        }
 }
 
-/*
- * Creates an exact copy of a node.
- * The copy resides in the same graph in the same block.
- */
-ir_node *exact_copy(const ir_node *n)
+ir_node *irn_copy_into_irg(const ir_node *node, ir_graph *irg)
 {
-       ir_graph *irg = get_irn_irg(n);
-       ir_node *res, *block = NULL;
+       ir_node  *block = NULL;
+       ir_op    *op    = get_irn_op(node);
+       int       arity = get_irn_arity(node);
+       dbg_info *dbgi  = get_irn_dbg_info(node);
+       ir_mode  *mode  = get_irn_mode(node);
+       ir_node  *res;
+       int       n_deps;
+       int       i;
+
+       if (op != op_Block)
+               block = get_nodes_block(node);
+
+       if (op->opar == oparity_dynamic) {
+               int i;
+               res = new_ir_node(dbgi, irg, block, op, mode, -1, NULL);
+               for (i = 0; i < arity; ++i) {
+                       ir_node *in = get_irn_n(node, i);
+                       add_irn_n(res, in);
+               }
+       } else {
+               ir_node **ins = get_irn_in(node)+1;
+               res = new_ir_node(dbgi, irg, block, op, mode, arity, ins);
+       }
 
-       if (is_no_Block(n))
-               block = get_nodes_block(n);
+       /* copy the attributes */
+       copy_node_attr(irg, node, res);
+       if (op == op_Block) {
+               set_Block_MacroBlock(res, get_Block_MacroBlock(node));
+       }
 
-       res = new_ir_node(get_irn_dbg_info(n),
-               irg,
-               block,
-               get_irn_op(n),
-               get_irn_mode(n),
-               get_irn_arity(n),
-               get_irn_in(n) + 1);
+       /* duplicate dependency edges */
+       n_deps = get_irn_deps(node);
+       for (i = 0; i < n_deps; ++i) {
+               ir_node *dep = get_irn_dep(node, i);
+               add_irn_dep(res, dep);
+       }
 
+       return res;
+}
 
-       /* Copy the attributes.  These might point to additional data.  If this
-          was allocated on the old obstack the pointers now are dangling.  This
-          frees e.g. the memory of the graph_arr allocated in new_immBlock. */
-       copy_node_attr(irg, n, res);
+ir_node *exact_copy(const ir_node *node)
+{
+       return irn_copy_into_irg(node, get_irn_irg(node));
+}
+
+static ir_node *get_new_node(const ir_node *old_node)
+{
+       return (ir_node*) get_irn_link(old_node);
+}
+
+void irn_rewire_inputs(ir_node *node)
+{
+       ir_graph *new_irg;
+       ir_node  *new_node;
+       int       arity;
+       int       i;
+
+       new_node = get_new_node(node);
+
+       if (is_Block(node)) {
+               /* copy the macro block header */
+               ir_node *mbh = get_Block_MacroBlock(node);
+
+               /* get the macro block header */
+               ir_node *nmbh = get_new_node(mbh);
+               assert(nmbh != NULL);
+               set_Block_MacroBlock(new_node, nmbh);
+       } else {
+               ir_node *block     = get_nodes_block(node);
+               ir_node *new_block = get_new_node(block);
+               set_nodes_block(new_node, new_block);
+       }
 
-       if (is_Block(n)) {
-               set_Block_MacroBlock(res, get_Block_MacroBlock(n));
+       arity = get_irn_arity(new_node);
+       for (i = 0; i < arity; ++i) {
+               ir_node *in     = get_irn_n(node, i);
+               ir_node *new_in = get_new_node(in);
+               set_irn_n(new_node, i, new_in);
        }
-       return res;
+
+       /* Now the new node is complete. We can add it to the hash table for CSE. */
+       new_irg = get_irn_irg(new_node);
+       add_identities(new_irg->value_table, new_node);
 }
 
-/*
- * Dump a pset containing Firm objects.
- */
 void firm_pset_dump(pset *set)
 {
        void *obj;
index ae9ba11..afa6e7f 100644 (file)
@@ -82,6 +82,33 @@ void firm_clear_link(ir_node *n, void *env);
 void firm_clear_node_and_phi_links(ir_node *n, void *env);
 
 /**
+ * Creates an exact copy of a node with same inputs and attributes in the
+ * same block.
+ *
+ * @param node   the node to copy
+ */
+ir_node *exact_copy(const ir_node *node);
+
+/**
+ * Create an exact copy of a node with same inputs and attributes in the same
+ * block but puts the node on a graph which might be different than the graph
+ * of the original node.
+ * Note: You have to fixup the inputs/block later
+ */
+ir_node *irn_copy_into_irg(const ir_node *node, ir_graph *irg);
+
+/**
+ * This is a helper function used by some routines copying irg graphs
+ * This assumes that we have "old" nodes which have been copied to "new"
+ * nodes; The inputs of the new nodes still point to old nodes.
+ *
+ * Given an old(!) node this function rewires the matching new_node
+ * so that all its inputs point to new nodes afterwards.
+ */
+void irn_rewire_inputs(ir_node *node);
+
+/**
+ * @deprecated
  * Copies a node to a new irg. The Ins of the new node point to
  * the predecessors on the old irg.  n->link points to the new node.
  *
@@ -94,15 +121,4 @@ void firm_clear_node_and_phi_links(ir_node *n, void *env);
  */
 void copy_irn_to_irg(ir_node *n, ir_graph *irg);
 
-/**
- * Creates an exact copy of a node.
- * The copy resists on the same graph in the same block.
- *
- * @param n   the node to copy
- *
- * @note If the copy is not changed, the next CSE operation will
- *       replace it by the original, so beware.
- */
-ir_node *exact_copy(const ir_node *n);
-
 #endif
index bc3adf3..67ab88d 100644 (file)
@@ -392,36 +392,17 @@ ir_graph *new_const_code_irg(void)
  * @param n    A node from the original method graph.
  * @param env  The copied graph.
  */
-static void copy_all_nodes(ir_node *n, void *env)
+static void copy_all_nodes(ir_node *node, void *env)
 {
-       ir_graph *irg = env;
-       ir_op    *op  = get_irn_op(n);
-       ir_node  *nn;
+       ir_graph *irg      = env;
+       ir_node  *new_node = irn_copy_into_irg(node, irg);
 
-       nn = new_ir_node(get_irn_dbg_info(n),
-                        irg,
-                        NULL,            /* no block yet, will be set later */
-                        op,
-                        get_irn_mode(n),
-                        get_irn_arity(n),
-                        get_irn_in(n) + 1);
-
-
-       /* Copy the attributes.  These might point to additional data.  If this
-          was allocated on the old obstack the pointers now are dangling.  This
-          frees e.g. the memory of the graph_arr allocated in new_immBlock. */
-       copy_node_attr(irg, n, nn);
-       set_irn_link(n, nn);
-
-       /* fix the irg for Blocks: as Bad nodes are NOT copied, no
-          need t fix them */
-       if (is_Block(nn))
-               nn->attr.block.irg.irg = irg;
+       set_irn_link(node, new_node);
 
        /* fix access to entities on the stack frame */
-       if (is_Sel(nn)) {
-               ir_entity *ent = get_Sel_entity(nn);
-               ir_type   *tp = get_entity_owner(ent);
+       if (is_Sel(new_node)) {
+               ir_entity *ent = get_Sel_entity(new_node);
+               ir_type   *tp  = get_entity_owner(ent);
 
                if (is_frame_type(tp)) {
                        /* replace by the copied entity */
@@ -429,7 +410,7 @@ static void copy_all_nodes(ir_node *n, void *env)
 
                        assert(is_entity(ent));
                        assert(get_entity_owner(ent) == get_irg_frame_type(irg));
-                       set_Sel_entity(nn, ent);
+                       set_Sel_entity(new_node, ent);
                }
        }
 }
@@ -439,32 +420,16 @@ static void copy_all_nodes(ir_node *n, void *env)
  * The copied nodes are set as link of their original nodes. The links of
  * "irn" predecessors are the predecessors of copied node.
  */
-static void set_all_preds(ir_node *irn, void *env)
+static void rewire(ir_node *irn, void *env)
 {
-       int      i;
-       ir_node  *nn, *pred;
        (void) env;
-
-       nn = get_irn_link(irn);
-
-       if (is_Block(irn)) {
-               ir_node *mbh = get_Block_MacroBlock(irn);
-               set_Block_MacroBlock(nn, get_irn_link(mbh));
-               for (i = get_Block_n_cfgpreds(irn) - 1; i >= 0; i--) {
-                       pred = get_Block_cfgpred(irn, i);
-                       set_Block_cfgpred(nn, i, get_irn_link(pred));
-               }
-       } else {
-               /* First we set the block our copy if it is not a block.*/
-               set_nodes_block(nn, get_irn_link(get_nodes_block(irn)));
-               for (i = get_irn_arity(irn) - 1; i >= 0; i--) {
-                       pred = get_irn_n(irn, i);
-                       set_irn_n(nn, i, get_irn_link(pred));
-               }
-       }
+       irn_rewire_inputs(irn);
 }
 
-#define NN(irn)  get_irn_link(irn)
+static ir_node *get_new_node(const ir_node *old_node)
+{
+       return (ir_node*) get_irn_link(old_node);
+}
 
 /*
  * Create a new graph that is a copy of a given one.
@@ -500,25 +465,25 @@ ir_graph *create_irg_copy(ir_graph *irg)
        ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
 
        /* copy all nodes from the graph irg to the new graph res */
-       irg_walk_anchors(irg, copy_all_nodes, set_all_preds, res);
+       irg_walk_anchors(irg, copy_all_nodes, rewire, res);
 
        /* copy the Anchor node */
-       res->anchor = NN(irg->anchor);
+       res->anchor = get_new_node(irg->anchor);
 
        /* -- The end block -- */
-       set_irg_end_block (res, NN(get_irg_end_block(irg)));
-       set_irg_end       (res, NN(get_irg_end(irg)));
-       set_irg_end_reg   (res, NN(get_irg_end_reg(irg)));
-       set_irg_end_except(res, NN(get_irg_end_except(irg)));
+       set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
+       set_irg_end       (res, get_new_node(get_irg_end(irg)));
+       set_irg_end_reg   (res, get_new_node(get_irg_end_reg(irg)));
+       set_irg_end_except(res, get_new_node(get_irg_end_except(irg)));
 
        /* -- The start block -- */
-       set_irg_start_block(res, NN(get_irg_start_block(irg)));
-       set_irg_bad        (res, NN(get_irg_bad(irg)));
-       set_irg_no_mem     (res, NN(get_irg_no_mem(irg)));
-       set_irg_start      (res, NN(get_irg_start(irg)));
+       set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
+       set_irg_bad        (res, get_new_node(get_irg_bad(irg)));
+       set_irg_no_mem     (res, get_new_node(get_irg_no_mem(irg)));
+       set_irg_start      (res, get_new_node(get_irg_start(irg)));
 
        /* Proj results of start node */
-       set_irg_initial_mem(res, NN(get_irg_initial_mem(irg)));
+       set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
 
        /* Copy the node count estimation. Would be strange if this
           is different from the original one. */
@@ -529,8 +494,6 @@ ir_graph *create_irg_copy(ir_graph *irg)
 
        return res;
 }
-#undef NN
-
 
 /* Frees the passed irgraph.
    Deallocates all nodes in this graph and the ir_graph structure.
index 269b250..196454c 100644 (file)
@@ -137,4 +137,31 @@ ir_op_ops *firm_set_default_operations(ir_opcode code, ir_op_ops *ops);
  */
 bool is_negated_value(ir_node *a, ir_node *b);
 
+
+
+/** NOTE: Survive DCE is considered a bad hack - don't use */
+typedef struct _survive_dce_t survive_dce_t;
+
+/**
+ * Make a new Survive DCE environment.
+ * NOTE: Survive DCE is considered a bad hack - don't use
+ */
+survive_dce_t *new_survive_dce(void);
+
+/**
+ * Free a Survive DCE environment.
+ * NOTE: Survive DCE is considered a bad hack - don't use
+ */
+void free_survive_dce(survive_dce_t *sd);
+
+/**
+ * Register a node pointer to be patched upon DCE.
+ * When DCE occurs, the node pointer specified by @p place will be
+ * patched to the new address of the node it is pointing to.
+ *
+ * @param sd    The Survive DCE environment.
+ * @param place The address of the node pointer.
+ */
+void survive_dce_register_irn(survive_dce_t *sd, ir_node **place);
+
 #endif
diff --git a/ir/opt/dead_code_elimination.c b/ir/opt/dead_code_elimination.c
new file mode 100644 (file)
index 0000000..924ff3c
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief    Dead node elimination
+ * @author   Michael Beck, Goetz Lindenmaier
+ * @version  $Id: opt_inline.c 27265 2010-03-07 15:13:00Z matze $
+ *
+ * Strictly speaking dead node elimination is unnecessary in firm - everthying
+ * which is not used can't be found by any walker.
+ * The only drawback is that the nodes still take up memory. This phase fixes
+ * this by copying all (reachable) nodes to a new obstack and throwing away
+ * the old one.
+ */
+#include "config.h"
+
+#include "iroptimize.h"
+#include "irnode_t.h"
+#include "irgraph_t.h"
+#include "irphase_t.h"
+#include "iredges_t.h"
+#include "irhooks.h"
+#include "irtools.h"
+#include "irgwalk.h"
+#include "cgana.h"
+#include "irouts.h"
+#include "trouts.h"
+#include "iropt_t.h"
+#include "irpass.h"
+#include "pmap.h"
+
+/** a pointer to the new phases */
+static ir_phase *new_phases[PHASE_LAST];
+
+/**
+ * Reroute the inputs of a node from nodes in the old graph to copied nodes in
+ * the new graph
+ */
+static void rewire_inputs(ir_node *node, void *env)
+{
+       (void) env;
+       irn_rewire_inputs(node);
+}
+
+static void copy_node_dce(ir_node *node, void *env)
+{
+       int       i;
+       ir_node  *new_node = exact_copy(node);
+       ir_graph *irg      = get_irn_irg(new_node);
+       (void) env;
+
+       /* preserve the node numbers for easier debugging */
+       new_node->node_nr = node->node_nr;
+
+       /* copy phase information for this node */
+       for (i = PHASE_NOT_IRG_MANAGED+1; i < PHASE_LAST; i++) {
+               ir_phase *phase = get_irg_phase(irg, i);
+               if (phase == NULL)
+                       continue;
+               if (!phase_get_irn_data(phase, node))
+                       continue;
+               phase_set_irn_data(new_phases[i], new_node,
+                                  phase_get_irn_data(phase, node));
+       }
+
+       set_irn_link(node, new_node);
+       hook_dead_node_elim_subst(irg, node, new_node);
+}
+
+/**
+ * Copies the graph reachable from current_ir_graph->end to the obstack
+ * in current_ir_graph and fixes the environment.
+ * Then fixes the fields in current_ir_graph containing nodes of the
+ * graph.
+ *
+ * @param copy_node_nr  If non-zero, the node number will be copied
+ */
+static void copy_graph_env(ir_graph *irg)
+{
+       ir_node  *new_anchor;
+       int i;
+
+       /* init the new_phases array */
+       for (i = PHASE_NOT_IRG_MANAGED+1; i < PHASE_LAST; i++) {
+               ir_phase *old_ph = get_irg_phase(irg, i);
+               if (old_ph == NULL) {
+                       new_phases[i] = NULL;
+               } else {
+                       new_phases[i] = xmalloc(sizeof(ir_phase));
+                       phase_init(new_phases[i], "", irg, old_ph->growth_factor,
+                                       old_ph->data_init, old_ph->priv);
+               }
+       }
+
+       /* copy nodes */
+       irg_walk_anchors(irg, copy_node_dce, rewire_inputs, NULL);
+
+       /* fix the anchor */
+       new_anchor = get_irn_link(irg->anchor);
+       assert(new_anchor != NULL);
+       irg->anchor = new_anchor;
+
+       /* copy the new phases into the irg */
+       for (i = PHASE_NOT_IRG_MANAGED+1; i < PHASE_LAST; i++) {
+               ir_phase *old_ph = get_irg_phase(irg, i);
+               if (old_ph == NULL)
+                       continue;
+
+               free_irg_phase(irg, i);
+               irg->phases[i] = new_phases[i];
+       }
+}
+
+/**
+ * Copies all reachable nodes to a new obstack.  Removes bad inputs
+ * from block nodes and the corresponding inputs from Phi nodes.
+ * Merges single exit blocks with single entry blocks and removes
+ * 1-input Phis.
+ * Adds all new nodes to a new hash table for CSE.  Does not
+ * perform CSE, so the hash table might contain common subexpressions.
+ */
+void dead_node_elimination(ir_graph *irg)
+{
+       ir_graph *rem;
+#ifdef INTERPROCEDURAL_VIEW
+       int rem_ipview = get_interprocedural_view();
+#endif
+       struct obstack *graveyard_obst = NULL;
+       struct obstack *rebirth_obst   = NULL;
+
+       edges_deactivate(irg);
+
+       /* inform statistics that we started a dead-node elimination run */
+       hook_dead_node_elim(irg, 1);
+
+       /* Remember external state of current_ir_graph. */
+       rem = current_ir_graph;
+       current_ir_graph = irg;
+#ifdef INTERPROCEDURAL_VIEW
+       set_interprocedural_view(0);
+#endif
+
+       assert(get_irg_phase_state(irg) != phase_building);
+
+       /* Handle graph state */
+       free_callee_info(irg);
+       free_irg_outs(irg);
+       free_trouts();
+       free_loop_information(irg);
+       set_irg_doms_inconsistent(irg);
+
+       /* A quiet place, where the old obstack can rest in peace,
+          until it will be cremated. */
+       graveyard_obst = irg->obst;
+
+       /* A new obstack, where the reachable nodes will be copied to. */
+       rebirth_obst = XMALLOC(struct obstack);
+       irg->obst = rebirth_obst;
+       obstack_init(irg->obst);
+       irg->last_node_idx = 0;
+
+       /* We also need a new value table for CSE */
+       del_identities(irg->value_table);
+       irg->value_table = new_identities();
+
+       /* Copy the graph from the old to the new obstack */
+       copy_graph_env(irg);
+
+       /* Free memory from old unoptimized obstack */
+       obstack_free(graveyard_obst, 0);  /* First empty the obstack ... */
+       xfree(graveyard_obst);            /* ... then free it.           */
+
+       /* inform statistics that the run is over */
+       hook_dead_node_elim(irg, 0);
+
+       current_ir_graph = rem;
+#ifdef INTERPROCEDURAL_VIEW
+       set_interprocedural_view(rem_ipview);
+#endif
+}
+
+ir_graph_pass_t *dead_node_elimination_pass(const char *name)
+{
+       return def_graph_pass(name ? name : "dce", dead_node_elimination);
+}
+
+
+/*
+   __                      _  __ __
+  (_     __    o     _    | \/  |_
+  __)|_| | \_/ | \_/(/_   |_/\__|__
+
+  The following stuff implements a facility that automatically patches
+  registered ir_node pointers to the new node when a dead node elimination occurs.
+
+
+  Warning: This is considered a hack - try hard to avoid this!
+*/
+
+struct _survive_dce_t {
+       struct obstack obst;
+       pmap *places;
+       pmap *new_places;
+       hook_entry_t dead_node_elim;
+       hook_entry_t dead_node_elim_subst;
+};
+
+typedef struct _survive_dce_list_t {
+       struct _survive_dce_list_t *next;
+       ir_node **place;
+} survive_dce_list_t;
+
+static void dead_node_hook(void *context, ir_graph *irg, int start)
+{
+       survive_dce_t *sd = context;
+       (void) irg;
+
+       /* Create a new map before the dead node elimination is performed. */
+       if (start) {
+               sd->new_places = pmap_create_ex(pmap_count(sd->places));
+       } else {
+               /* Patch back all nodes if dead node elimination is over and something is to be done. */
+               pmap_destroy(sd->places);
+               sd->places     = sd->new_places;
+               sd->new_places = NULL;
+       }
+}
+
+/**
+ * Hook called when dead node elimination replaces old by nw.
+ */
+static void dead_node_subst_hook(void *context, ir_graph *irg, ir_node *old, ir_node *nw)
+{
+       survive_dce_t *sd = context;
+       survive_dce_list_t *list = pmap_get(sd->places, old);
+       (void) irg;
+
+       /* If the node is to be patched back, write the new address to all registered locations. */
+       if (list) {
+               survive_dce_list_t *p;
+
+               for (p = list; p; p = p->next)
+                       *(p->place) = nw;
+
+               pmap_insert(sd->new_places, nw, list);
+       }
+}
+
+/**
+ * Make a new Survive DCE environment.
+ */
+survive_dce_t *new_survive_dce(void)
+{
+       survive_dce_t *res = XMALLOC(survive_dce_t);
+       obstack_init(&res->obst);
+       res->places     = pmap_create();
+       res->new_places = NULL;
+
+       res->dead_node_elim.hook._hook_dead_node_elim = dead_node_hook;
+       res->dead_node_elim.context                   = res;
+       res->dead_node_elim.next                      = NULL;
+
+       res->dead_node_elim_subst.hook._hook_dead_node_elim_subst = dead_node_subst_hook;
+       res->dead_node_elim_subst.context = res;
+       res->dead_node_elim_subst.next    = NULL;
+
+       register_hook(hook_dead_node_elim, &res->dead_node_elim);
+       register_hook(hook_dead_node_elim_subst, &res->dead_node_elim_subst);
+       return res;
+}
+
+/**
+ * Free a Survive DCE environment.
+ */
+void free_survive_dce(survive_dce_t *sd)
+{
+       obstack_free(&sd->obst, NULL);
+       pmap_destroy(sd->places);
+       unregister_hook(hook_dead_node_elim, &sd->dead_node_elim);
+       unregister_hook(hook_dead_node_elim_subst, &sd->dead_node_elim_subst);
+       xfree(sd);
+}
+
+/**
+ * Register a node pointer to be patched upon DCE.
+ * When DCE occurs, the node pointer specified by @p place will be
+ * patched to the new address of the node it is pointing to.
+ *
+ * @param sd    The Survive DCE environment.
+ * @param place The address of the node pointer.
+ */
+void survive_dce_register_irn(survive_dce_t *sd, ir_node **place)
+{
+       if (*place != NULL) {
+               ir_node *irn      = *place;
+               survive_dce_list_t *curr = pmap_get(sd->places, irn);
+               survive_dce_list_t *nw   = OALLOC(&sd->obst, survive_dce_list_t);
+
+               nw->next  = curr;
+               nw->place = place;
+
+               pmap_insert(sd->places, irn, nw);
+       }
+}
index 3e2a01e..7ac484a 100644 (file)
@@ -723,19 +723,20 @@ static void handle_load_update(ir_node *load)
  */
 static void reduce_adr_usage(ir_node *ptr)
 {
-       if (is_Proj(ptr)) {
-               if (get_irn_n_edges(ptr) <= 0) {
-                       /* this Proj is dead now */
-                       ir_node *pred = get_Proj_pred(ptr);
+       ir_node *pred;
+       if (!is_Proj(ptr))
+               return;
+       if (get_irn_n_edges(ptr) > 0)
+               return;
 
-                       if (is_Load(pred)) {
-                               ldst_info_t *info = get_irn_link(pred);
-                               info->projs[get_Proj_proj(ptr)] = NULL;
+       /* this Proj is dead now */
+       pred = get_Proj_pred(ptr);
+       if (is_Load(pred)) {
+               ldst_info_t *info = get_irn_link(pred);
+               info->projs[get_Proj_proj(ptr)] = NULL;
 
-                               /* this node lost its result proj, handle that */
-                               handle_load_update(pred);
-                       }
-               }
+               /* this node lost its result proj, handle that */
+               handle_load_update(pred);
        }
 }  /* reduce_adr_usage */
 
@@ -1110,8 +1111,9 @@ static unsigned optimize_load(ir_node *load)
        /* The mem of the Load. Must still be returned after optimization. */
        mem = get_Load_mem(load);
 
-       if (! info->projs[pn_Load_res] && ! info->projs[pn_Load_X_except]) {
-               /* a Load which value is neither used nor exception checked, remove it */
+       if (info->projs[pn_Load_res] == NULL
+                       && info->projs[pn_Load_X_except] == NULL) {
+               /* the value is never used and we don't care about exceptions, remove */
                exchange(info->projs[pn_Load_M], mem);
 
                if (info->projs[pn_Load_X_regular]) {
index 92c2446..6bd787e 100644 (file)
@@ -89,357 +89,6 @@ static inline ir_node *get_new_node(ir_node *old_node)
        return (ir_node*) get_irn_link(old_node);
 }
 
-/** a pointer to the new phases */
-static ir_phase *new_phases[PHASE_LAST];
-
-/**
- * Copies the node to the new obstack. The Ins of the new node point to
- * the predecessors on the old obstack.  For block/phi nodes not all
- * predecessors might be copied.  n->link points to the new node.
- *
- * @param n    The node to be copied
- * @param irg  The irg onto which the node should be copied
- */
-static ir_node *copy_node(ir_node *n, ir_graph *irg)
-{
-       ir_op    *op    = get_irn_op(n);
-       int       arity = get_irn_arity(n);
-       dbg_info *dbgi  = get_irn_dbg_info(n);
-       ir_mode  *mode  = get_irn_mode(n);
-       ir_node  *nn;
-       ir_node  *block;
-       int       i;
-
-       if (op == op_Block) {
-               block = NULL;
-               n->attr.block.graph_arr = NULL;
-       } else {
-               block = get_nodes_block(n);
-       }
-       if (op->opar == oparity_dynamic) {
-               nn = new_ir_node(dbgi, irg, block, op, mode, -1, NULL);
-               for (i = 0; i < arity; ++i) {
-                       ir_node *in = get_irn_n(n, i);
-                       add_irn_n(nn, in);
-               }
-       } else {
-               ir_node **ins = get_irn_in(n)+1;
-               nn = new_ir_node(dbgi, irg, block, op, mode, arity, ins);
-       }
-
-       /* Copy the attributes.  These might point to additional data.  If this
-          was allocated on the old obstack the pointers now are dangling. */
-       copy_node_attr(irg, n, nn);
-       if (op == op_Block) {
-               /* we cannot allow blocks WITHOUT macroblock input */
-               set_Block_MacroBlock(nn, get_Block_MacroBlock(n));
-       }
-
-       /* copy phase information for this node */
-       for (i = PHASE_NOT_IRG_MANAGED+1; i < PHASE_LAST; i++) {
-               ir_graph *old_irg = get_irn_irg(n);
-               ir_phase *old_ph  = get_irg_phase(old_irg, i);
-               if (old_ph == NULL)
-                       continue;
-               if (!phase_get_irn_data(old_ph, n))
-                       continue;
-               phase_set_irn_data(new_phases[i], nn, phase_get_irn_data(old_ph, n));
-       }
-
-       set_new_node(n, nn);
-       hook_dead_node_elim_subst(current_ir_graph, n, nn);
-
-       return nn;
-}
-
-static void copy_node_with_number(ir_node *node, void *env)
-{
-       ir_graph *new_irg  = (ir_graph*) env;
-       ir_node  *new_node = copy_node(node, new_irg);
-
-       /* preserve the node numbers for easier debugging */
-       new_node->node_nr = node->node_nr;
-}
-
-/**
- * Reroute the inputs of a node from nodes in the old graph to copied nodes in
- * the new graph
- */
-static void set_preds(ir_node *node, void *env)
-{
-       ir_graph *new_irg = (ir_graph*) env;
-       ir_node  *new_node;
-       int       arity;
-       int       i;
-
-       new_node = get_new_node(node);
-
-       if (is_Block(node)) {
-               /* copy the macro block header */
-               ir_node *mbh = get_Block_MacroBlock(node);
-
-               /* get the macro block header */
-               ir_node *nmbh = get_new_node(mbh);
-               assert(nmbh != NULL);
-               set_Block_MacroBlock(new_node, nmbh);
-       } else {
-               ir_node *block     = get_nodes_block(node);
-               ir_node *new_block = get_new_node(block);
-               set_nodes_block(new_node, new_block);
-       }
-
-       arity = get_irn_arity(new_node);
-       for (i = 0; i < arity; ++i) {
-               ir_node *in     = get_irn_n(node, i);
-               ir_node *new_in = get_new_node(in);
-               set_irn_n(new_node, i, new_in);
-       }
-
-       /* Now the new node is complete. We can add it to the hash table for CSE. */
-       add_identities(new_irg->value_table, new_node);
-}
-
-/**
- * Copies the graph reachable from current_ir_graph->end to the obstack
- * in current_ir_graph and fixes the environment.
- * Then fixes the fields in current_ir_graph containing nodes of the
- * graph.
- *
- * @param copy_node_nr  If non-zero, the node number will be copied
- */
-static void copy_graph_env(ir_graph *irg)
-{
-       ir_node  *old_end;
-       ir_node  *new_anchor;
-       ir_phase *old_ph;
-       int i;
-
-       /* init the new_phases array */
-       for (i = PHASE_NOT_IRG_MANAGED+1; i < PHASE_LAST; i++) {
-               old_ph = get_irg_phase(irg, i);
-               if (old_ph == NULL) {
-                       new_phases[i] = NULL;
-               } else {
-                       new_phases[i] = xmalloc(sizeof(ir_phase));
-                       phase_init(new_phases[i], "", irg, old_ph->growth_factor,
-                                       old_ph->data_init, old_ph->priv);
-               }
-       }
-
-       /* remove end_except and end_reg nodes */
-       old_end = get_irg_end(irg);
-       set_irg_end_except(irg, old_end);
-       set_irg_end_reg   (irg, old_end);
-
-       /* copy nodes */
-       irg_walk(irg->anchor, copy_node_with_number, set_preds, irg);
-
-       /* fix the anchor */
-       new_anchor = get_new_node(irg->anchor);
-       assert(new_anchor != NULL);
-       irg->anchor = new_anchor;
-
-       /* copy the new phases into the irg */
-       for (i = PHASE_NOT_IRG_MANAGED+1; i < PHASE_LAST; i++) {
-               old_ph = get_irg_phase(irg, i);
-               if (old_ph == NULL)
-                       continue;
-
-               free_irg_phase(irg, i);
-               irg->phases[i] = new_phases[i];
-       }
-
-       free_End(old_end);
-}
-
-/**
- * Copies all reachable nodes to a new obstack.  Removes bad inputs
- * from block nodes and the corresponding inputs from Phi nodes.
- * Merges single exit blocks with single entry blocks and removes
- * 1-input Phis.
- * Adds all new nodes to a new hash table for CSE.  Does not
- * perform CSE, so the hash table might contain common subexpressions.
- */
-void dead_node_elimination(ir_graph *irg)
-{
-       ir_graph *rem;
-#ifdef INTERPROCEDURAL_VIEW
-       int rem_ipview = get_interprocedural_view();
-#endif
-       struct obstack *graveyard_obst = NULL;
-       struct obstack *rebirth_obst   = NULL;
-
-       edges_deactivate(irg);
-
-       /* inform statistics that we started a dead-node elimination run */
-       hook_dead_node_elim(irg, 1);
-
-       /* Remember external state of current_ir_graph. */
-       rem = current_ir_graph;
-       current_ir_graph = irg;
-#ifdef INTERPROCEDURAL_VIEW
-       set_interprocedural_view(0);
-#endif
-
-       assert(get_irg_phase_state(irg) != phase_building);
-
-       /* Handle graph state */
-       free_callee_info(irg);
-       free_irg_outs(irg);
-       free_trouts();
-       free_loop_information(irg);
-       set_irg_doms_inconsistent(irg);
-
-       /* A quiet place, where the old obstack can rest in peace,
-          until it will be cremated. */
-       graveyard_obst = irg->obst;
-
-       /* A new obstack, where the reachable nodes will be copied to. */
-       rebirth_obst = XMALLOC(struct obstack);
-       irg->obst = rebirth_obst;
-       obstack_init(irg->obst);
-       irg->last_node_idx = 0;
-
-       /* We also need a new value table for CSE */
-       del_identities(irg->value_table);
-       irg->value_table = new_identities();
-
-       /* Copy the graph from the old to the new obstack */
-       copy_graph_env(irg);
-
-       /* Free memory from old unoptimized obstack */
-       obstack_free(graveyard_obst, 0);  /* First empty the obstack ... */
-       xfree(graveyard_obst);            /* ... then free it.           */
-
-       /* inform statistics that the run is over */
-       hook_dead_node_elim(irg, 0);
-
-       current_ir_graph = rem;
-#ifdef INTERPROCEDURAL_VIEW
-       set_interprocedural_view(rem_ipview);
-#endif
-}
-
-ir_graph_pass_t *dead_node_elimination_pass(const char *name)
-{
-       return def_graph_pass(name ? name : "dce", dead_node_elimination);
-}
-
-/*
-   __                      _  __ __
-  (_     __    o     _    | \/  |_
-  __)|_| | \_/ | \_/(/_   |_/\__|__
-
-  The following stuff implements a facility that automatically patches
-  registered ir_node pointers to the new node when a dead node elimination occurs.
-*/
-
-struct _survive_dce_t {
-       struct obstack obst;
-       pmap *places;
-       pmap *new_places;
-       hook_entry_t dead_node_elim;
-       hook_entry_t dead_node_elim_subst;
-};
-
-typedef struct _survive_dce_list_t {
-       struct _survive_dce_list_t *next;
-       ir_node **place;
-} survive_dce_list_t;
-
-static void dead_node_hook(void *context, ir_graph *irg, int start)
-{
-       survive_dce_t *sd = context;
-       (void) irg;
-
-       /* Create a new map before the dead node elimination is performed. */
-       if (start) {
-               sd->new_places = pmap_create_ex(pmap_count(sd->places));
-       } else {
-               /* Patch back all nodes if dead node elimination is over and something is to be done. */
-               pmap_destroy(sd->places);
-               sd->places     = sd->new_places;
-               sd->new_places = NULL;
-       }
-}
-
-/**
- * Hook called when dead node elimination replaces old by nw.
- */
-static void dead_node_subst_hook(void *context, ir_graph *irg, ir_node *old, ir_node *nw)
-{
-       survive_dce_t *sd = context;
-       survive_dce_list_t *list = pmap_get(sd->places, old);
-       (void) irg;
-
-       /* If the node is to be patched back, write the new address to all registered locations. */
-       if (list) {
-               survive_dce_list_t *p;
-
-               for (p = list; p; p = p->next)
-                       *(p->place) = nw;
-
-               pmap_insert(sd->new_places, nw, list);
-       }
-}
-
-/**
- * Make a new Survive DCE environment.
- */
-survive_dce_t *new_survive_dce(void)
-{
-       survive_dce_t *res = XMALLOC(survive_dce_t);
-       obstack_init(&res->obst);
-       res->places     = pmap_create();
-       res->new_places = NULL;
-
-       res->dead_node_elim.hook._hook_dead_node_elim = dead_node_hook;
-       res->dead_node_elim.context                   = res;
-       res->dead_node_elim.next                      = NULL;
-
-       res->dead_node_elim_subst.hook._hook_dead_node_elim_subst = dead_node_subst_hook;
-       res->dead_node_elim_subst.context = res;
-       res->dead_node_elim_subst.next    = NULL;
-
-       register_hook(hook_dead_node_elim, &res->dead_node_elim);
-       register_hook(hook_dead_node_elim_subst, &res->dead_node_elim_subst);
-       return res;
-}
-
-/**
- * Free a Survive DCE environment.
- */
-void free_survive_dce(survive_dce_t *sd)
-{
-       obstack_free(&sd->obst, NULL);
-       pmap_destroy(sd->places);
-       unregister_hook(hook_dead_node_elim, &sd->dead_node_elim);
-       unregister_hook(hook_dead_node_elim_subst, &sd->dead_node_elim_subst);
-       xfree(sd);
-}
-
-/**
- * Register a node pointer to be patched upon DCE.
- * When DCE occurs, the node pointer specified by @p place will be
- * patched to the new address of the node it is pointing to.
- *
- * @param sd    The Survive DCE environment.
- * @param place The address of the node pointer.
- */
-void survive_dce_register_irn(survive_dce_t *sd, ir_node **place)
-{
-       if (*place != NULL) {
-               ir_node *irn      = *place;
-               survive_dce_list_t *curr = pmap_get(sd->places, irn);
-               survive_dce_list_t *nw   = OALLOC(&sd->obst, survive_dce_list_t);
-
-               nw->next  = curr;
-               nw->place = place;
-
-               pmap_insert(sd->places, irn, nw);
-       }
-}
-
 /*--------------------------------------------------------------------*/
 /*  Functionality for inlining                                         */
 /*--------------------------------------------------------------------*/
@@ -455,10 +104,11 @@ void survive_dce_register_irn(survive_dce_t *sd, ir_node **place)
  */
 static void copy_node_inline(ir_node *node, void *env)
 {
-       ir_graph *new_irg = (ir_graph*) env;
-       ir_node  *new_node;
+       ir_graph *new_irg  = (ir_graph*) env;
+       ir_node  *new_node = irn_copy_into_irg(node, new_irg);
+
+       set_new_node(node, new_node);
 
-       new_node = copy_node(node, new_irg);
        if (is_Sel(node)) {
                ir_graph  *old_irg        = get_irn_irg(node);
                ir_type   *old_frame_type = get_irg_frame_type(old_irg);
@@ -479,7 +129,7 @@ static void set_preds_inline(ir_node *node, void *env)
 {
        ir_node *new_node;
 
-       set_preds(node, env);
+       irn_rewire_inputs(node);
 
        /* move constants into start block */
        new_node = get_new_node(node);