Merge remote branch 'upstream/master'
[mono.git] / mono / mini / ssa.c
index 32edf7bccbab7148bf6259b0c65ccd02e064648b..96a90ca65d8e094e5e947999c435cd3af59113f3 100644 (file)
@@ -268,7 +268,7 @@ mono_ssa_rename_vars (MonoCompile *cfg, int max_vars, MonoBasicBlock *bb, gboole
                        }
                        else if (G_UNLIKELY (!var && lvreg_defined [ins->dreg] && (ins->dreg >= MONO_MAX_IREGS))) {
                                /* Perform renaming for local vregs */
-                               lvreg_stack [ins->dreg] = mono_alloc_preg (cfg);
+                               lvreg_stack [ins->dreg] = vreg_is_ref (cfg, ins->dreg) ? mono_alloc_ireg_ref (cfg) : mono_alloc_preg (cfg);
                                ins->dreg = lvreg_stack [ins->dreg];
                        }
                        else
@@ -340,8 +340,6 @@ mono_ssa_compute (MonoCompile *cfg)
 
        g_assert (!(cfg->comp_done & MONO_COMP_SSA));
 
-       /* we dont support methods containing exception clauses */
-       g_assert (mono_method_get_header (cfg->method)->num_clauses == 0);
        g_assert (!cfg->disable_ssa);
 
        if (cfg->verbose_level >= 4)
@@ -383,7 +381,7 @@ mono_ssa_compute (MonoCompile *cfg)
                MonoInst *var = cfg->varinfo [i];
 
 #if SIZEOF_REGISTER == 4
-               if (var->type == STACK_I8)
+               if (var->type == STACK_I8 && !COMPILE_LLVM (cfg))
                        continue;
 #endif
                if (var->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT))
@@ -485,7 +483,7 @@ void
 mono_ssa_remove (MonoCompile *cfg)
 {
        MonoInst *ins, *var, *move;
-       int i, j, first;
+       int bbindex, i, j, first;
 
        g_assert (cfg->comp_done & MONO_COMP_SSA);
 
@@ -553,12 +551,12 @@ mono_ssa_remove (MonoCompile *cfg)
         * can coalesce them into the original variable.
         */
 
-       for (i = 0; i < cfg->num_bblocks; ++i) {
-               MonoBasicBlock *bb = cfg->bblocks [i];
+       for (bbindex = 0; bbindex < cfg->num_bblocks; ++bbindex) {
+               MonoBasicBlock *bb = cfg->bblocks [bbindex];
 
                for (ins = bb->code; ins; ins = ins->next) {
                        const char *spec = INS_INFO (ins->opcode);
-                       int num_sregs, j;
+                       int num_sregs;
                        int sregs [MONO_MAX_SRC_REGS];
 
                        if (ins->opcode == OP_NOP)
@@ -582,7 +580,7 @@ mono_ssa_remove (MonoCompile *cfg)
                        }
 
                        num_sregs = mono_inst_get_src_registers (ins, sregs);
-                       for (j = 0; j < num_sregs; ++j) {
+                       for (i = 0; i < num_sregs; ++i) {
                                MonoInst *var = get_vreg_to_inst (cfg, sregs [i]);
 
                                if (var) {
@@ -1168,6 +1166,15 @@ mono_ssa_cprop (MonoCompile *cfg)
                        info->cpstate = 2;
        }
 
+       for (bb = cfg->bb_entry->next_bb; bb; bb = bb->next_bb) {
+               /*
+                * FIXME: This should be bb->flags & BB_FLAG_EXCEPTION_HANDLER, but
+                * that would still allow unreachable try's to be removed.
+                */
+               if (bb->region)
+                       add_cprop_bb (cfg, bb, &bblock_list);
+       }
+
        cvars = NULL;
 
        while (bblock_list) {
@@ -1179,11 +1186,13 @@ mono_ssa_cprop (MonoCompile *cfg)
 
                g_assert (bb->flags &  BB_REACHABLE);
 
-               if (bb->out_count == 1) {
-                       if (!(bb->out_bb [0]->flags &  BB_REACHABLE)) {
-                               bb->out_bb [0]->flags |= BB_REACHABLE;
-                               bblock_list = g_list_prepend (bblock_list, bb->out_bb [0]);
-                       }
+               /* 
+                * Some bblocks are linked to 2 others even through they fall through to the
+                * next bblock.
+                */
+               if (!(bb->last_ins && MONO_IS_BRANCH_OP (bb->last_ins))) {
+                       for (i = 0; i < bb->out_count; ++i)
+                               add_cprop_bb (cfg, bb->out_bb [i], &bblock_list);
                }
 
                if (cfg->verbose_level > 1)