Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mono / mini / liveness.c
index ee87dfa082ad509892177d58242c5dc7bf962971..eaa656e059c1b9c3894a321a9a4d6b19b24704e6 100644 (file)
@@ -1,14 +1,17 @@
-/*
- * liveness.c: liveness analysis
+/**
+ * \file
+ * liveness analysis
  *
  * Author:
  *   Dietmar Maurer (dietmar@ximian.com)
  *
  * (C) 2002 Ximian, Inc.
  * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
+#include <mono/utils/mono-compiler.h>
 
 #ifndef DISABLE_JIT
 
@@ -103,8 +106,8 @@ visit_bb (MonoCompile *cfg, MonoBasicBlock *bb, GSList **visited)
                        cfg->varinfo [vi->idx]->flags |= MONO_INST_VOLATILE;
                        if (SIZEOF_REGISTER == 4 && (var->type == STACK_I8 || (var->type == STACK_R8 && COMPILE_SOFT_FLOAT (cfg)))) {
                                /* Make the component vregs volatile as well (#612206) */
-                               get_vreg_to_inst (cfg, var->dreg + 1)->flags |= MONO_INST_VOLATILE;
-                               get_vreg_to_inst (cfg, var->dreg + 2)->flags |= MONO_INST_VOLATILE;
+                               get_vreg_to_inst (cfg, MONO_LVREG_LS (var->dreg))->flags |= MONO_INST_VOLATILE;
+                               get_vreg_to_inst (cfg, MONO_LVREG_MS (var->dreg))->flags |= MONO_INST_VOLATILE;
                        }
                }
                        
@@ -122,8 +125,8 @@ visit_bb (MonoCompile *cfg, MonoBasicBlock *bb, GSList **visited)
                                cfg->varinfo [vi->idx]->flags |= MONO_INST_VOLATILE;
                                if (SIZEOF_REGISTER == 4 && (var->type == STACK_I8 || (var->type == STACK_R8 && COMPILE_SOFT_FLOAT (cfg)))) {
                                        /* Make the component vregs volatile as well (#612206) */
-                                       get_vreg_to_inst (cfg, var->dreg + 1)->flags |= MONO_INST_VOLATILE;
-                                       get_vreg_to_inst (cfg, var->dreg + 2)->flags |= MONO_INST_VOLATILE;
+                                       get_vreg_to_inst (cfg, MONO_LVREG_LS (var->dreg))->flags |= MONO_INST_VOLATILE;
+                                       get_vreg_to_inst (cfg, MONO_LVREG_MS (var->dreg))->flags |= MONO_INST_VOLATILE;
                                }
                        }
                }
@@ -229,8 +232,7 @@ analyze_liveness_bb (MonoCompile *cfg, MonoBasicBlock *bb)
 
 #ifdef DEBUG_LIVENESS
                if (cfg->verbose_level > 1) {
-                       printf ("\t");
-                       mono_print_ins (ins);
+                       mono_print_ins_index (1, ins);
                }
 #endif
 
@@ -850,13 +852,12 @@ update_liveness2 (MonoCompile *cfg, MonoInst *ins, gboolean set_volatile, int in
 static void
 mono_analyze_liveness2 (MonoCompile *cfg)
 {
-       int bnum, idx, i, j, nins, max, max_vars, block_from, block_to, pos, reverse_len;
+       int bnum, idx, i, j, nins, max, max_vars, block_from, block_to, pos;
        gint32 *last_use;
        static guint32 disabled = -1;
-       MonoInst **reverse;
 
        if (disabled == -1)
-               disabled = g_getenv ("DISABLED") != NULL;
+               disabled = g_hasenv ("DISABLED");
 
        if (disabled)
                return;
@@ -888,9 +889,6 @@ mono_analyze_liveness2 (MonoCompile *cfg)
        max_vars = cfg->num_varinfo;
        last_use = g_new0 (gint32, max_vars);
 
-       reverse_len = 1024;
-       reverse = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * reverse_len);
-
        for (idx = 0; idx < max_vars; ++idx) {
                MonoMethodVar *vi = MONO_VARINFO (cfg, idx);
 
@@ -938,25 +936,13 @@ mono_analyze_liveness2 (MonoCompile *cfg)
                if (cfg->ret)
                        last_use [cfg->ret->inst_c0] = block_to;
 
-               for (nins = 0, pos = block_from, ins = bb->code; ins; ins = ins->next, ++nins, ++pos) {
-                       if (nins >= reverse_len) {
-                               int new_reverse_len = reverse_len * 2;
-                               MonoInst **new_reverse = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * new_reverse_len);
-                               memcpy (new_reverse, reverse, sizeof (MonoInst*) * reverse_len);
-                               reverse = new_reverse;
-                               reverse_len = new_reverse_len;
-                       }
-
-                       reverse [nins] = ins;
-               }
+               pos = block_from + 1;
+               MONO_BB_FOR_EACH_INS (bb, ins) pos++;
 
                /* Process instructions backwards */
-               for (i = nins - 1; i >= 0; --i) {
-                       MonoInst *ins = (MonoInst*)reverse [i];
-
-                       update_liveness2 (cfg, ins, FALSE, pos, last_use);
-
-                       pos --;
+               MONO_BB_FOR_EACH_INS_REVERSE (bb, ins) {
+                       update_liveness2 (cfg, ins, FALSE, pos, last_use);
+                       pos--;
                }
 
                for (idx = 0; idx < max_vars; ++idx) {
@@ -1157,4 +1143,8 @@ mono_analyze_liveness_gc (MonoCompile *cfg)
        g_free (vreg_to_varinfo);
 }
 
-#endif /* DISABLE_JIT */
+#else /* !DISABLE_JIT */
+
+MONO_EMPTY_SOURCE_FILE (liveness);
+
+#endif /* !DISABLE_JIT */