Use g_assertion_message instead of exit to kill an iOS app.
[mono.git] / mono / mini / liveness.c
index 12f96b3479b40dcff9b8549f2b95179cb134b5a1..aabae662bf7db5e9e42f47eb71972cae26df8b8a 100644 (file)
@@ -5,6 +5,7 @@
  *   Dietmar Maurer (dietmar@ximian.com)
  *
  * (C) 2002 Ximian, Inc.
+ * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
  */
 
 #include "mini.h"
@@ -138,6 +139,39 @@ mono_liveness_handle_exception_clauses (MonoCompile *cfg)
 {
        MonoBasicBlock *bb;
        GSList *visited = NULL;
+       MonoMethodHeader *header = cfg->header;
+       MonoExceptionClause *clause, *clause2;
+       int i, j;
+       gboolean *outer_try;
+
+       /* 
+        * Determine which clauses are outer try clauses, i.e. they are not contained in any
+        * other non-try clause.
+        */
+       outer_try = mono_mempool_alloc0 (cfg->mempool, sizeof (gboolean) * header->num_clauses);
+       for (i = 0; i < header->num_clauses; ++i)
+               outer_try [i] = TRUE;
+       /* Iterate over the clauses backward, so outer clauses come first */
+       /* This avoids doing an O(2) search, since we can determine when inner clauses end */
+       for (i = header->num_clauses - 1; i >= 0; --i) {
+               clause = &header->clauses [i];
+
+               if (clause->flags != 0) {
+                       outer_try [i] = TRUE;
+                       /* Iterate over inner clauses */
+                       for (j = i - 1; j >= 0; --j) {
+                               clause2 = &header->clauses [j];
+
+                               if (clause2->flags == 0 && MONO_OFFSET_IN_HANDLER (clause, clause2->try_offset)) {
+                                       outer_try [j] = FALSE;
+                                       break;
+                               }
+                               if (clause2->try_offset < clause->try_offset)
+                                       /* End of inner clauses */
+                                       break;
+                       }
+               }
+       }
 
        /*
         * Variables in exception handler register cannot be allocated to registers
@@ -149,9 +183,15 @@ mono_liveness_handle_exception_clauses (MonoCompile *cfg)
         */
        for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
 
-               if (bb->region == -1 || MONO_BBLOCK_IS_IN_REGION (bb, MONO_REGION_TRY))
+               if (bb->region == -1)
                        continue;
 
+               if (MONO_BBLOCK_IS_IN_REGION (bb, MONO_REGION_TRY) && outer_try [MONO_REGION_CLAUSE_INDEX (bb->region)])
+                       continue;
+
+               if (cfg->verbose_level > 2)
+                       printf ("pessimize variables in bb %d.\n", bb->block_num);
+
                visit_bb (cfg, bb, &visited);
        }
        g_slist_free (visited);
@@ -446,14 +486,13 @@ mono_analyze_liveness (MonoCompile *cfg)
 
        for (i = 0; i < cfg->num_bblocks; ++i) {
                MonoBasicBlock *bb = cfg->bblocks [i];
-               guint32 rem, max;
+               guint32 max;
                guint32 abs_pos = (bb->dfn << 16);
                MonoMethodVar *vars = cfg->vars;
 
                if (!bb->live_out_set)
                        continue;
 
-               rem = max_vars % BITS_PER_CHUNK;
                max = ((max_vars + (BITS_PER_CHUNK -1)) / BITS_PER_CHUNK);
                for (j = 0; j < max; ++j) {
                        gsize bits_in;
@@ -799,7 +838,7 @@ update_liveness2 (MonoCompile *cfg, MonoInst *ins, gboolean set_volatile, int in
 static void
 mono_analyze_liveness2 (MonoCompile *cfg)
 {
-       int bnum, idx, i, j, nins, rem, max, max_vars, block_from, block_to, pos, reverse_len;
+       int bnum, idx, i, j, nins, max, max_vars, block_from, block_to, pos, reverse_len;
        gint32 *last_use;
        static guint32 disabled = -1;
        MonoInst **reverse;
@@ -850,7 +889,6 @@ mono_analyze_liveness2 (MonoCompile *cfg)
                
                /* For variables in bb->live_out, set last_use to block_to */
 
-               rem = max_vars % BITS_PER_CHUNK;
                max = ((max_vars + (BITS_PER_CHUNK -1)) / BITS_PER_CHUNK);
                for (j = 0; j < max; ++j) {
                        gsize bits_out;
@@ -1001,7 +1039,7 @@ get_vreg_from_var (MonoCompile *cfg, MonoInst *var)
 void
 mono_analyze_liveness_gc (MonoCompile *cfg)
 {
-       int idx, i, j, nins, rem, max, max_vars, block_from, block_to, pos, reverse_len;
+       int idx, i, j, nins, max, max_vars, block_from, block_to, pos, reverse_len;
        gint32 *last_use;
        MonoInst **reverse;
        MonoMethodVar **vreg_to_varinfo = NULL;
@@ -1041,7 +1079,6 @@ mono_analyze_liveness_gc (MonoCompile *cfg)
                
                /* For variables in bb->live_out, set last_use to block_to */
 
-               rem = max_vars % BITS_PER_CHUNK;
                max = ((max_vars + (BITS_PER_CHUNK -1)) / BITS_PER_CHUNK);
                for (j = 0; j < max; ++j) {
                        gsize bits_out;