Remove enum tarval_classification_t.
[libfirm] / ir / ir / irgmod.c
index c4ba378..0a06562 100644 (file)
  * PURPOSE.
  */
 
-/*
- * 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
+/**
+ * @file
+ * @brief    Support for ir graph modification.
+ * @author   Martin Trapp, Christian Schaefer, Goetz Lindenmaier
+ * @version  $Id$
  */
-
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -43,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);
        }
 }
 
@@ -72,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);
@@ -85,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);
@@ -96,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;
 
@@ -110,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");
                        }
                }
 
@@ -133,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);
@@ -218,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);
+}