*** empty log message ***
[libfirm] / ir / ir / iropt.c
index 68221c9..ec56f83 100644 (file)
@@ -8,9 +8,13 @@
 
 # include "iropt.h"
 # include "ircons.h"
-# include "irgwalk.h"
+# include "irgmod.h"
+# include "irvrfy.h"
 # include "tv.h"
 
+/* Make types visible to allow most efficient access */
+# include "entity_t.h"
+
 /* Trivial inlineable routine for copy propagation.
    Does follow Ids, needed to optimize inlined code. */
 static inline ir_node *
@@ -528,7 +532,6 @@ equivalent_node (ir_node *n)
 } /* end equivalent_node() */
 
 
-#if 0
 /* tries several [inplace] [optimizing] transformations and returns a
    equivalent node.  The difference to equivalent_node is that these
    transformations _do_ generate new nodes, and thus the old node must
@@ -537,16 +540,18 @@ static ir_node *
 transform_node (ir_node *n)
 {
 
-  ir_node *a, *b;
+  ir_node *a = NULL, *b;
   tarval *ta, *tb;
 
   switch (get_irn_opcode(n)) {
   case iro_DivMod: {
+
     int evaluated = 0;
-    ir_mode *mode = get_irn_mode(a);
+    ir_mode *mode;
 
     a = get_DivMod_left(n);
     b = get_DivMod_right(n);
+    mode = get_irn_mode(a);
 
     if (!(   mode_is_int(get_irn_mode(a))
          && mode_is_int(get_irn_mode(b))))
@@ -584,9 +589,10 @@ transform_node (ir_node *n)
       ir_node *mem = get_DivMod_mem(n);
       turn_into_tuple(n, 4);
       set_Tuple_pred(n, 0, mem);
-      set_Tuple_pred(n, 1, new_Bad());
+      set_Tuple_pred(n, 1, new_Bad());  /* no exception */
       set_Tuple_pred(n, 2, a);
       set_Tuple_pred(n, 3, b);
+      assert(get_nodes_Block(n));
     }
   }
   break;
@@ -665,7 +671,7 @@ transform_node (ir_node *n)
     }
   }
   break;
-  case iro_Eor: {
+  case iro_Eor: { /* @@@ not tested as boolean Eor not allowed any more. */
     a = get_Eor_left(n);
     b = get_Eor_right(n);
 
@@ -673,7 +679,7 @@ transform_node (ir_node *n)
        && (get_irn_op(a) == op_Proj)
         && (get_irn_mode(a) == mode_b)
        && (tarval_classify (computed_value (b)) == 1)
-       && (get_irn_op(get_Proj_pred(a)) == iro_Cmp))
+       && (get_irn_op(get_Proj_pred(a)) == op_Cmp))
       /* The Eor negates a Cmp. The Cmp has the negated result anyways! */
       n = new_r_Proj(current_ir_graph, get_nodes_Block(n), get_Proj_pred(a),
                      mode_b, get_negated_pnc(get_Proj_proj(a)));
@@ -684,13 +690,13 @@ transform_node (ir_node *n)
       n = new_r_Not(current_ir_graph, get_nodes_Block(n), a, mode_b);
   }
   break;
-  case iro_Not: {
+  case iro_Not: { /* @@@ not tested as boolean Eor not allowed any more. */
     a = get_Not_op(n);
 
     if (   (get_irn_mode(n) == mode_b)
        && (get_irn_op(a) == op_Proj)
         && (get_irn_mode(a) == mode_b)
-       && (get_irn_op(get_Proj_pred(a)) == iro_Cmp))
+       && (get_irn_op(get_Proj_pred(a)) == op_Cmp))
       /* We negate a Cmp. The Cmp has the negated result anyways! */
       n = new_r_Proj(current_ir_graph, get_nodes_Block(n), get_Proj_pred(a),
                      mode_b, get_negated_pnc(get_Proj_proj(a)));
@@ -698,8 +704,8 @@ transform_node (ir_node *n)
   break;
   default: ;
   }
+  return n;
 }
-#endif
 
 /***************** Common Subexpression Elimination *****************/
 
@@ -885,6 +891,8 @@ optimize (ir_node *n)
   tarval *tv;
   ir_node *old_n = n;
 
+  if ((!get_optimize()) && (get_irn_op(n) != op_Phi)) return n;
+
   /* if not optimize return n */
   if (n == NULL) {
     printf(" attention: empty node!!! \n");
@@ -911,7 +919,7 @@ optimize (ir_node *n)
 
   /** common subexpression elimination **/
   /* Checks whether n is already available. */
-  /* The block input is used to distinguish different subexpressions.  Right
+  /* The block input is used to distinguish different subexpressions. Right
      now all nodes are pinned to blocks, i.e., the cse only finds common
      subexpressions within a block. */
 
@@ -924,16 +932,15 @@ optimize (ir_node *n)
     /* The AmRoq fiasco returns n here.  Martin's version doesn't. */
   }
 
-#if 0
-  /* Some more constant expression evaluation. */
+  /* Some more constant expression evaluation that does not allow to
+     free the node. */
   if (get_opt_constant_folding())
     n = transform_node (n);
-#endif
 
   /* Remove nodes with dead (Bad) input. */
   n = gigo (n);
   /* Now we can verify the node, as it has no dead inputs any more. */
-  ir_vrfy(n);
+  irn_vrfy(n);
 
   /* Now we have a legal, useful node. Enter it in hash table for cse */
   if (get_opt_cse()) {
@@ -948,7 +955,6 @@ optimize (ir_node *n)
     pdeq_putr (current_ir_graph->keep.living, n);
   }
 #endif
-
   return n;
 }
 
@@ -1009,7 +1015,7 @@ optimize_in_place (ir_node *n)
   /* Remove nodes with dead (Bad) input. */
   n = gigo (n);
   /* Now we can verify the node, as it has no dead inputs any more. */
-  ir_vrfy(n);
+  irn_vrfy(n);
 
   /* Now we have a legal, useful node. Enter it in hash table for cse */
   if (get_opt_cse()) {
@@ -1020,30 +1026,3 @@ optimize_in_place (ir_node *n)
 
   return n;
 }
-
-
-void
-optimize_in_place_wrapper (ir_node *n, void *env) {
-  int i;
-  ir_node *optimized;
-
-  /* optimize all sons after recursion, i.e., the sons' sons are
-     optimized already. */
-  for (i = -1; i < get_irn_arity(n); i++) {
-    optimized = optimize_in_place(get_irn_n(n, i));
-    set_irn_n(n, i, optimized);
-  }
-}
-
-
-void
-optimize_graph (ir_graph *irg)
-{
-  ir_graph *rem = current_ir_graph;
-  current_ir_graph = irg;
-
-  /* walk over the graph */
-  irg_walk(irg->end, NULL, optimize_in_place_wrapper, NULL);
-
-  current_ir_graph = rem;
-}