removed INLIEN before global functions
[libfirm] / ir / ir / iropt.c
index 2a8df25..dbcbe6c 100644 (file)
  */
 
 #ifdef HAVE_CONFIG_H
-# include <config.h>
+# include "config.h"
+#endif
+
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
 #endif
 
 # include "irnode_t.h"
 /* Make types visible to allow most efficient access */
 # include "entity_t.h"
 
-# ifdef DO_HEAPANALYSIS
-/* heapanal can't cope with NoMems */
-# else /* if defined DO_HEAPANALYSIS */
-#  define USE_NOMEM
-# endif /* defined DO_HEAPANALYSIS */
-
 /**
  * Trivial INLINEable routine for copy propagation.
  * Does follow Ids, needed to optimize INLINEd code.
@@ -503,6 +507,26 @@ static tarval *computed_value_Proj(ir_node *n)
   return tarval_bad;
 }
 
+/**
+ * calculate the value of a Mux: can be evaluated, if the
+ * sel and the right input are known
+ */
+static tarval *computed_value_Mux(ir_node *n)
+{
+  ir_node *sel = get_Mux_sel(n);
+  tarval *ts = value_of(sel);
+
+  if (ts == get_tarval_b_true()) {
+    ir_node *v = get_Mux_true(n);
+    return value_of(v);
+  }
+  else if (ts == get_tarval_b_false()) {
+    ir_node *v = get_Mux_false(n);
+    return value_of(v);
+  }
+  return tarval_bad;
+}
+
 /**
  * If the parameter n can be computed, return its value, else tarval_bad.
  * Performs constant folding.
@@ -547,6 +571,7 @@ static ir_op *firm_set_default_computed_value(ir_op *op)
   CASE(Rot);
   CASE(Conv);
   CASE(Proj);
+  CASE(Mux);
   default:
     op->computed_value  = NULL;
   }
@@ -1052,6 +1077,22 @@ static ir_node *equivalent_node_Id(ir_node *n)
   return n;
 }
 
+/**
+ * optimize a Mux
+ */
+static ir_node *equivalent_node_Mux(ir_node *n)
+{
+  ir_node *sel = get_Mux_sel(n);
+  tarval *ts = value_of(sel);
+
+  if (ts == get_tarval_b_true())
+    return get_Mux_true(n);
+  else if (ts == get_tarval_b_false())
+    return get_Mux_false(n);
+
+  return n;
+}
+
 /**
  * equivalent_node() returns a node equivalent to input n. It skips all nodes that
  * perform no actual computation, as, e.g., the Id nodes.  It does not create
@@ -1100,6 +1141,7 @@ static ir_op *firm_set_default_equivalent_node(ir_op *op)
   CASE(Phi);
   CASE(Proj);
   CASE(Id);
+  CASE(Mux);
   default:
     op->equivalent_node  = NULL;
   }
@@ -1456,9 +1498,7 @@ static ir_node *transform_node_Proj(ir_node *proj)
       } else {
         /* the memory Proj can be removed */
         ir_node *res = get_Div_mem(n);
-# ifdef USE_NOMEM
         set_Div_mem(n, get_irg_no_mem(current_ir_graph));
-# endif /* defined USE_NOMEM */
         if (proj_nr == pn_Div_M)
           return res;
       }
@@ -1480,9 +1520,7 @@ static ir_node *transform_node_Proj(ir_node *proj)
       } else {
         /* the memory Proj can be removed */
         ir_node *res = get_Mod_mem(n);
-# ifdef USE_NOMEM
         set_Mod_mem(n, get_irg_no_mem(current_ir_graph));
-# endif /* defined USE_NOMEM */
         if (proj_nr == pn_Mod_M)
           return res;
       }
@@ -1505,9 +1543,7 @@ static ir_node *transform_node_Proj(ir_node *proj)
       else {
         /* the memory Proj can be removed */
         ir_node *res = get_DivMod_mem(n);
-# ifdef USE_NOMEM
         set_DivMod_mem(n, get_irg_no_mem(current_ir_graph));
-# endif /* defined USE_NOMEM */
         if (proj_nr == pn_DivMod_M)
           return res;
       }