becopyilp: Do not advertise the switch to dump the solution, because this is not...
[libfirm] / ir / lower / lower_dw.c
index e8bee5a..78e48d3 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
@@ -111,7 +97,6 @@ typedef struct lower_dw_env_t {
        ir_graph      *irg;
        struct obstack obst;           /**< an obstack holding the temporary data */
        ir_tarval *tv_mode_bytes;      /**< a tarval containing the number of bytes in the lowered modes */
-       ir_tarval *tv_mode_bits;       /**< a tarval containing the number of bits in the lowered modes */
        pdeq      *waitq;              /**< a wait queue of all nodes that must be handled later */
        ir_node  **lowered_phis;       /**< list of lowered phis */
        ir_mode   *high_signed;        /**< doubleword signed type */
@@ -201,14 +186,14 @@ static ir_type *get_conv_type(ir_mode *imode, ir_mode *omode)
  */
 static void add_block_cf_input_nr(ir_node *block, int nr, ir_node *cf)
 {
-       int i, arity = get_irn_arity(block);
+       int i, arity = get_Block_n_cfgpreds(block);
        ir_node **in;
 
        assert(nr < arity);
 
        NEW_ARR_A(ir_node *, in, arity + 1);
        for (i = 0; i < arity; ++i)
-               in[i] = get_irn_n(block, i);
+               in[i] = get_Block_cfgpred(block, i);
        in[i] = cf;
 
        set_irn_in(block, i + 1, in);
@@ -232,11 +217,11 @@ static void add_block_cf_input_nr(ir_node *block, int nr, ir_node *cf)
  */
 static void add_block_cf_input(ir_node *block, ir_node *tmpl, ir_node *cf)
 {
-       int i, arity = get_irn_arity(block);
+       int i, arity = get_Block_n_cfgpreds(block);
        int nr = 0;
 
        for (i = 0; i < arity; ++i) {
-               if (get_irn_n(block, i) == tmpl) {
+               if (get_Block_cfgpred(block, i) == tmpl) {
                        nr = i;
                        break;
                }
@@ -355,7 +340,7 @@ static void lower_Const(ir_node *node, ir_mode *mode)
        ir_tarval *tv       = get_Const_tarval(node);
        ir_tarval *tv_l     = tarval_convert_to(tv, low_mode);
        ir_node   *res_low  = new_rd_Const(dbg, irg, tv_l);
-       ir_tarval *tv_shrs  = tarval_shrs(tv, env->tv_mode_bits);
+       ir_tarval *tv_shrs  = tarval_shrs_unsigned(tv, get_mode_size_bits(low_mode));
        ir_tarval *tv_h     = tarval_convert_to(tv_shrs, mode);
        ir_node   *res_high = new_rd_Const(dbg, irg, tv_h);
 
@@ -1839,9 +1824,6 @@ static ir_type *lower_mtp(ir_type *mtp)
  */
 static void lower_Return(ir_node *node, ir_mode *mode)
 {
-       ir_graph  *irg = get_irn_irg(node);
-       ir_entity *ent = get_irg_entity(irg);
-       ir_type   *mtp = get_entity_type(ent);
        ir_node  **in;
        size_t     i, j, n;
        int        need_conv = 0;
@@ -1858,8 +1840,9 @@ static void lower_Return(ir_node *node, ir_mode *mode)
        if (! need_conv)
                return;
 
-       ent = get_irg_entity(irg);
-       mtp = get_entity_type(ent);
+       ir_graph  *irg = get_irn_irg(node);
+       ir_entity *ent = get_irg_entity(irg);
+       ir_type   *mtp = get_entity_type(ent);
 
        /* create a new in array */
        NEW_ARR_A(ir_node *, in, get_method_n_ress(mtp) + 1);
@@ -2243,11 +2226,10 @@ static void lower_ASM(ir_node *asmn, ir_mode *mode)
        ir_asm_constraint *output_constraints = get_ASM_output_constraints(asmn);
        ir_asm_constraint *input_constraints  = get_ASM_input_constraints(asmn);
        unsigned           n_64bit_outs       = 0;
-       int      i;
 
        (void)mode;
 
-       for (i = get_irn_arity(asmn) - 1; i >= 0; --i) {
+       for (int i = get_irn_arity(asmn) - 1; i >= 0; --i) {
                ir_node *op      = get_irn_n(asmn, i);
                ir_mode *op_mode = get_irn_mode(op);
                if (op_mode == high_signed || op_mode == high_unsigned) {
@@ -2255,8 +2237,8 @@ static void lower_ASM(ir_node *asmn, ir_mode *mode)
                }
        }
 
-       for (i = 0; i < n_outs; ++i) {
-               const ir_asm_constraint *constraint = &output_constraints[i];
+       for (int o = 0; o < n_outs; ++o) {
+               const ir_asm_constraint *constraint = &output_constraints[o];
                if (constraint->mode == high_signed || constraint->mode == high_unsigned) {
                        const char *constr = get_id_str(constraint->constraint);
                        ++n_64bit_outs;
@@ -2271,71 +2253,73 @@ static void lower_ASM(ir_node *asmn, ir_mode *mode)
        if (n_64bit_outs == 0)
                return;
 
-       {
-               dbg_info          *dbgi       = get_irn_dbg_info(asmn);
-               ir_node           *block      = get_nodes_block(asmn);
-               int                arity      = get_irn_arity(asmn);
-               ir_node          **in         = get_irn_in(asmn) + 1;
-               int                new_n_outs = 0;
-               int                n_clobber  = get_ASM_n_clobbers(asmn);
-               long              *proj_map   = ALLOCAN(long, n_outs);
-               ident            **clobbers   = get_ASM_clobbers(asmn);
-               ident             *asm_text   = get_ASM_text(asmn);
-               ir_asm_constraint *new_outputs
-                       = ALLOCAN(ir_asm_constraint, n_outs+n_64bit_outs);
-               ir_node           *new_asm;
-
-               for (i = 0; i < n_outs; ++i) {
-                       const ir_asm_constraint *constraint = &output_constraints[i];
-                       if (constraint->mode == high_signed || constraint->mode == high_unsigned) {
-                               new_outputs[new_n_outs].pos        = constraint->pos;
-                               new_outputs[new_n_outs].constraint = new_id_from_str("=a");
-                               new_outputs[new_n_outs].mode       = env->low_unsigned;
-                               proj_map[i] = new_n_outs;
-                               ++new_n_outs;
-                               new_outputs[new_n_outs].pos        = constraint->pos;
-                               new_outputs[new_n_outs].constraint = new_id_from_str("=d");
-                               if (constraint->mode == high_signed)
-                                       new_outputs[new_n_outs].mode = env->low_signed;
-                               else
-                                       new_outputs[new_n_outs].mode = env->low_unsigned;
-                               ++new_n_outs;
-                       } else {
-                               new_outputs[new_n_outs] = *constraint;
-                               proj_map[i] = new_n_outs;
-                               ++new_n_outs;
-                       }
+       dbg_info          *dbgi       = get_irn_dbg_info(asmn);
+       ir_node           *block      = get_nodes_block(asmn);
+       ir_node           *mem        = get_ASM_mem(asmn);
+       int                new_n_outs = 0;
+       int                n_clobber  = get_ASM_n_clobbers(asmn);
+       long              *proj_map   = ALLOCAN(long, n_outs);
+       ident            **clobbers   = get_ASM_clobbers(asmn);
+       ident             *asm_text   = get_ASM_text(asmn);
+       ir_asm_constraint *new_outputs
+               = ALLOCAN(ir_asm_constraint, n_outs+n_64bit_outs);
+       ir_node           *new_asm;
+
+       for (int o = 0; o < n_outs; ++o) {
+               const ir_asm_constraint *constraint = &output_constraints[o];
+               if (constraint->mode == high_signed || constraint->mode == high_unsigned) {
+                       new_outputs[new_n_outs].pos        = constraint->pos;
+                       new_outputs[new_n_outs].constraint = new_id_from_str("=a");
+                       new_outputs[new_n_outs].mode       = env->low_unsigned;
+                       proj_map[o] = new_n_outs;
+                       ++new_n_outs;
+                       new_outputs[new_n_outs].pos        = constraint->pos;
+                       new_outputs[new_n_outs].constraint = new_id_from_str("=d");
+                       if (constraint->mode == high_signed)
+                               new_outputs[new_n_outs].mode = env->low_signed;
+                       else
+                               new_outputs[new_n_outs].mode = env->low_unsigned;
+                       ++new_n_outs;
+               } else {
+                       new_outputs[new_n_outs] = *constraint;
+                       proj_map[o] = new_n_outs;
+                       ++new_n_outs;
                }
-               assert(new_n_outs == n_outs+(int)n_64bit_outs);
+       }
+       assert(new_n_outs == n_outs+(int)n_64bit_outs);
 
-               new_asm = new_rd_ASM(dbgi, block, arity, in, input_constraints,
-                                    new_n_outs, new_outputs, n_clobber, clobbers,
-                                    asm_text);
+       int       n_inputs = get_ASM_n_inputs(asmn);
+       ir_node **new_ins  = ALLOCAN(ir_node*, n_inputs);
+       for (int i = 0; i < n_inputs; ++i)
+               new_ins[i] = get_ASM_input(asmn, i);
 
-               foreach_out_edge_safe(asmn, edge) {
-                       ir_node *proj      = get_edge_src_irn(edge);
-                       ir_mode *proj_mode = get_irn_mode(proj);
-                       long     pn;
+       new_asm = new_rd_ASM(dbgi, block, mem, n_inputs, new_ins, input_constraints,
+                                                new_n_outs, new_outputs, n_clobber, clobbers,
+                                                asm_text);
 
-                       if (!is_Proj(proj))
-                               continue;
-                       pn = get_Proj_proj(proj);
+       foreach_out_edge_safe(asmn, edge) {
+               ir_node *proj      = get_edge_src_irn(edge);
+               ir_mode *proj_mode = get_irn_mode(proj);
+               long     pn;
 
-                       if (pn < n_outs)
-                               pn = proj_map[pn];
-                       else
-                               pn = new_n_outs + pn - n_outs;
-
-                       if (proj_mode == high_signed || proj_mode == high_unsigned) {
-                               ir_mode *high_mode
-                                       = proj_mode == high_signed ? env->low_signed : env->low_unsigned;
-                               ir_node *np_low  = new_r_Proj(new_asm, env->low_unsigned, pn);
-                               ir_node *np_high = new_r_Proj(new_asm, high_mode, pn+1);
-                               ir_set_dw_lowered(proj, np_low, np_high);
-                       } else {
-                               ir_node *np = new_r_Proj(new_asm, proj_mode, pn);
-                               exchange(proj, np);
-                       }
+               if (!is_Proj(proj))
+                       continue;
+               pn = get_Proj_proj(proj);
+
+               if (pn < n_outs)
+                       pn = proj_map[pn];
+               else
+                       pn = new_n_outs + pn - n_outs;
+
+               if (proj_mode == high_signed || proj_mode == high_unsigned) {
+                       ir_mode *high_mode
+                               = proj_mode == high_signed ? env->low_signed : env->low_unsigned;
+                       ir_node *np_low  = new_r_Proj(new_asm, env->low_unsigned, pn);
+                       ir_node *np_high = new_r_Proj(new_asm, high_mode, pn+1);
+                       ir_set_dw_lowered(proj, np_low, np_high);
+               } else {
+                       ir_node *np = new_r_Proj(new_asm, proj_mode, pn);
+                       exchange(proj, np);
                }
        }
 }
@@ -2649,9 +2633,11 @@ static void lower_reduce_builtin(ir_node *builtin, ir_mode *mode)
                panic("unexpected builtin");
        }
 
-       turn_into_tuple(builtin, 2);
-       set_irn_n(builtin, pn_Builtin_M, mem);
-       set_irn_n(builtin, pn_Builtin_max+1, res);
+       ir_node *const in[] = {
+               [pn_Builtin_M]       = mem,
+               [pn_Builtin_max + 1] = res,
+       };
+       turn_into_tuple(builtin, ARRAY_SIZE(in), in);
        }
 }
 
@@ -2758,6 +2744,7 @@ static bool always_lower(unsigned code)
        case iro_Call:
        case iro_Return:
        case iro_Cond:
+       case iro_Switch:
        case iro_Conv:
        case iro_Sel:
                return true;
@@ -2968,8 +2955,7 @@ static void lower_irg(ir_graph *irg)
        n_idx = get_irg_last_idx(irg);
        n_idx = n_idx + (n_idx >> 2);  /* add 25% */
        env->n_entries = n_idx;
-       env->entries   = NEW_ARR_F(lower64_entry_t*, n_idx);
-       memset(env->entries, 0, sizeof(env->entries[0]) * n_idx);
+       env->entries   = NEW_ARR_FZ(lower64_entry_t*, n_idx);
 
        env->irg            = irg;
        env->flags          = 0;
@@ -3159,7 +3145,6 @@ void ir_lower_dw_ops(void)
        }
 
        lenv.tv_mode_bytes = new_tarval_from_long(param->doubleword_size/(2*8), lenv.low_unsigned);
-       lenv.tv_mode_bits  = new_tarval_from_long(param->doubleword_size/2, lenv.low_unsigned);
        lenv.waitq         = new_pdeq();
        lenv.first_id      = new_id_from_chars(param->little_endian ? ".l" : ".h", 2);
        lenv.next_id       = new_id_from_chars(param->little_endian ? ".h" : ".l", 2);