renamed register_additional_node_data() to firm_register_additional_node_data()
[libfirm] / ir / ir / irgmod.c
index 953610b..0a06562 100644 (file)
@@ -1,15 +1,28 @@
 /*
- * Project:     libFIRM
- * File name:   ir/ir/irgmod.c
- * Purpose:     Support for ir graph modification.
- * Author:      Martin Trapp, Christian Schaefer
- * Modified by: Goetz Lindenmaier
- * Created:
- * CVS-ID:      $Id$
- * Copyright:   (c) 1998-2003 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 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    Support for ir graph modification.
+ * @author   Martin Trapp, Christian Schaefer, Goetz Lindenmaier
+ * @version  $Id$
+ */
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -25,6 +38,7 @@
 #include "irhooks.h"
 #include "iredges_t.h"
 #include "irtools.h"
+#include "error.h"
 
 /**
  * Turns a node into a "useless" Tuple.  The Tuple just forms a tuple
  * This is useful if a node returning a tuple is removed, but the Projs
  * extracting values from the tuple are not available.
  */
-void turn_into_tuple (ir_node *node, int arity)
-{
+void turn_into_tuple(ir_node *node, int arity) {
        assert(node);
        set_irn_op(node, op_Tuple);
        if (get_irn_arity(node) == arity) {
                /* keep old array */
        } else {
+               /* don't use get_nodes_block here, we allow turn_into_tuple for unpinned nodes */
+               ir_node *block = get_irn_n(node, -1);
                /* Allocate new array, don't free old in_array, it's on the obstack. */
-               ir_node *block = get_nodes_block(node);
                edges_node_deleted(node, current_ir_graph);
                node->in = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity+1);
                /* clear the new in array, else edge_notify tries to delete garbage */
                memset(node->in, 0, (arity+1) * sizeof(node->in[0]));
-               set_nodes_block(node, block);
+               set_irn_n(node, -1, block);
        }
 }
 
@@ -54,8 +68,7 @@ void turn_into_tuple (ir_node *node, int arity)
  * Since `new' may be bigger than `old' replace `old'
  * by an op_Id which is smaller than everything.
  */
-void exchange(ir_node *old, ir_node *nw)
-{
+void exchange(ir_node *old, ir_node *nw) {
        ir_graph *irg;
 
        assert(old && nw);
@@ -67,9 +80,9 @@ void exchange(ir_node *old, ir_node *nw)
        hook_replace(old, nw);
 
        /*
-       * If new outs are on, we can skip the id node creation and reroute
-       * the edges from the old node to the new directly.
-       */
+        * If new outs are on, we can skip the id node creation and reroute
+        * the edges from the old node to the new directly.
+        */
        if (edges_activated(irg)) {
                /* copy all dependencies from old to new */
                add_irn_deps(nw, old);
@@ -78,8 +91,7 @@ void exchange(ir_node *old, ir_node *nw)
                edges_reroute_kind(old, nw, EDGE_KIND_DEP, irg);
                edges_node_deleted(old, irg);
                old->op = op_Bad;
-       }
-       else {
+       } else {
                /* Else, do it the old-fashioned way. */
                ir_node *block;
 
@@ -92,9 +104,7 @@ void exchange(ir_node *old, ir_node *nw)
                        block = is_Block(nw) ? nw : get_nodes_block(nw);
 
                        if (! block) {
-                               DDMN(old);
-                               DDMN(nw);
-                               assert(0 && "cannot find legal block for id");
+                               panic("cannot find legal block for id");
                        }
                }
 
@@ -115,12 +125,12 @@ void exchange(ir_node *old, ir_node *nw)
  */
 static void collect(ir_node *n, void *env) {
        ir_node *pred;
+       (void) env;
 
        if (is_Phi(n)) {
                set_irn_link(n, get_irn_link(get_nodes_block(n)));
                set_irn_link(get_nodes_block(n), n);
-       }
-       else if (is_Proj(n)) {
+       } else if (is_Proj(n)) {
                pred = n;
                do {
                        pred = get_Proj_pred(pred);
@@ -200,12 +210,21 @@ void part_block(ir_node *node) {
        set_irn_link(new_block, phi);
        set_irn_link(old_block, NULL);
        while (phi) {
-               if(get_nodes_block(phi) == old_block);   /* @@@ inlinening chokes on phis that don't
-                                                                                                obey this condition.  How do they get into
-                                                                                                the list??? Example: InterfaceIII */
                set_nodes_block(phi, new_block);
                phi = get_irn_link(phi);
        }
 
        set_optimize(rem_opt);
 }
+
+/* kill a node by setting its predecessors to Bad and finally exchange the node by Bad itself. */
+void kill_node(ir_node *node) {
+       ir_graph *irg = get_irn_irg(node);
+       ir_node *bad = get_irg_bad(irg);
+       int i;
+
+       for (i = get_irn_arity(node) - 1; i >= -1; --i) {
+               set_irn_n(node, i, bad);
+       }
+       exchange(node, bad);
+}