- implemented i_mapper_bswap()
[libfirm] / ir / ir / irarch.c
index 1addedd..bc37358 100644 (file)
  */
 #include "config.h"
 
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-
+#include <stdlib.h>
 #include <assert.h>
 
 #include "irnode_t.h"
@@ -506,6 +503,9 @@ static int evaluate_insn(mul_env *env, instruction *inst) {
        case ZERO:
                inst->costs = costs = env->evaluate(inst->kind, NULL);
                return costs;
+       case MUL:
+       case ROOT:
+               break;
        }
        panic("Unsupported instruction kind");
 }
@@ -559,42 +559,50 @@ static ir_node *do_decomposition(ir_node *irn, ir_node *operand, tarval *tv) {
 
 /* Replace Muls with Shifts and Add/Subs. */
 ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn) {
-       ir_node *res = irn;
+       ir_graph *irg;
+       ir_node *res  = irn;
        ir_mode *mode = get_irn_mode(irn);
+       ir_node *left;
+       ir_node *right;
+       ir_node *operand;
+       tarval  *tv;
+
 
        /* If the architecture dependent optimizations were not initialized
           or this optimization was not enabled. */
        if (params == NULL || (opts & arch_dep_mul_to_shift) == 0)
                return irn;
 
-       set_arch_dep_running(1);
-       {
-               if (is_Mul(irn) && mode_is_int(mode)) {
-                       ir_node *left    = get_binop_left(irn);
-                       ir_node *right   = get_binop_right(irn);
-                       tarval *tv       = NULL;
-                       ir_node *operand = NULL;
-
-                       /* Look, if one operand is a constant. */
-                       if (is_Const(left)) {
-                               tv = get_Const_tarval(left);
-                               operand = right;
-                       } else if (is_Const(right)) {
-                               tv = get_Const_tarval(right);
-                               operand = left;
-                       }
+       if (!is_Mul(irn) || !mode_is_int(mode))
+               return res;
+
+       /* we should never do the reverse transformations again
+          (like x+x -> 2*x) */
+       irg = get_irn_irg(irn);
+       set_irg_state(irg, IR_GRAPH_STATE_ARCH_DEP);
+
+       left    = get_binop_left(irn);
+       right   = get_binop_right(irn);
+       tv      = NULL;
+       operand = NULL;
+
+       /* Look, if one operand is a constant. */
+       if (is_Const(left)) {
+               tv = get_Const_tarval(left);
+               operand = right;
+       } else if (is_Const(right)) {
+               tv = get_Const_tarval(right);
+               operand = left;
+       }
 
-                       if (tv != NULL) {
-                               res = do_decomposition(irn, operand, tv);
+       if (tv != NULL) {
+               res = do_decomposition(irn, operand, tv);
 
-                               if (res != irn) {
-                                       hook_arch_dep_replace_mul_with_shifts(irn);
-                                       exchange(irn, res);
-                               }
-                       }
+               if (res != irn) {
+                       hook_arch_dep_replace_mul_with_shifts(irn);
+                       exchange(irn, res);
                }
        }
-       //set_arch_dep_running(0);
 
        return res;
 }
@@ -928,7 +936,7 @@ ir_node *arch_dep_replace_div_by_const(ir_node *irn) {
                                ir_node *curr = left;
 
                                /* create the correction code for signed values only if there might be a remainder */
-                               if (! is_Div_remainderless(irn)) {
+                               if (! get_Div_no_remainder(irn)) {
                                        if (k != 1) {
                                                k_node = new_Const_long(mode_Iu, k - 1);
                                                curr   = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode);