*/
#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.
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.
CASE(Rot);
CASE(Conv);
CASE(Proj);
+ CASE(Mux);
default:
op->computed_value = NULL;
}
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
CASE(Phi);
CASE(Proj);
CASE(Id);
+ CASE(Mux);
default:
op->equivalent_node = NULL;
}
} 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;
}
} 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;
}
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;
}