[runtime] Use mono_restore_context () to reduce code duplication in the back ends.
[mono.git] / mono / mini / dominators.c
index 6dc67906bfdbfb148e7a009a4aef84cecbf511c1..d4071234f12e0475f79ae9979d0572dcfc19973d 100644 (file)
@@ -6,6 +6,7 @@
  *   Paolo Molaro (lupus@ximian.com)
  *
  * (C) 2003 Ximian, Inc.
+ * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
  */
 #include <string.h>
 #include <mono/metadata/debug-helpers.h>
@@ -34,7 +35,6 @@ static void
 compute_dominators (MonoCompile *cfg)
 {
        int bindex, i, bitsize;
-       char* mem;
        MonoBasicBlock *entry;
        MonoBasicBlock **doms;
        gboolean changed;
@@ -43,8 +43,6 @@ compute_dominators (MonoCompile *cfg)
 
        bitsize = mono_bitset_alloc_size (cfg->num_bblocks, 0);
 
-       mem = mono_mempool_alloc0 (cfg->mempool, bitsize * cfg->num_bblocks);
-
        entry = cfg->bblocks [0];
 
        doms = g_new0 (MonoBasicBlock*, cfg->num_bblocks);
@@ -118,6 +116,9 @@ compute_dominators (MonoCompile *cfg)
                MonoBasicBlock *bb = cfg->bblocks [i];
                MonoBasicBlock *cbb;
                MonoBitSet *dominators;
+               char *mem;
+
+               mem = mono_mempool_alloc0 (cfg->mempool, bitsize);
 
                bb->dominators = dominators = mono_bitset_mem_new (mem, cfg->num_bblocks, 0);
                mem += bitsize;
@@ -143,7 +144,7 @@ compute_dominators (MonoCompile *cfg)
 
 #ifdef DEBUG_DOMINATORS
        printf ("DTREE %s %d\n", mono_method_full_name (cfg->method, TRUE), 
-               mono_method_get_header (cfg->method)->num_clauses);
+               cfg->header->num_clauses);
        for (i = 0; i < cfg->num_bblocks; ++i) {
                MonoBasicBlock *bb = cfg->bblocks [i];
                printf ("BB%d(dfn=%d) (IDOM=BB%d): ", bb->block_num, bb->dfn, bb->idom ? bb->idom->block_num : -1);
@@ -384,6 +385,9 @@ mono_compute_natural_loops (MonoCompile *cfg)
                        /* The loop body start is the first bblock in the order they will be emitted */
                        MonoBasicBlock *h = cfg->bblocks [i];
                        MonoBasicBlock *body_start = h;
+#if defined(__native_client_codegen__)
+                       MonoInst *inst;
+#endif
                        GList *l;
 
                        for (l = h->loop_blocks; l; l = l->next) {
@@ -394,6 +398,12 @@ mono_compute_natural_loops (MonoCompile *cfg)
                                }
                        }
 
+#if defined(__native_client_codegen__)
+                       /* Instrument the loop (GC back branch safe point) */
+                       MONO_INST_NEW (cfg, inst, OP_NACL_GC_SAFE_POINT);
+                       inst->dreg = mono_alloc_dreg (cfg, STACK_I4);
+                       mono_bblock_insert_before_ins (body_start, NULL, inst);
+#endif
                        body_start->loop_body_start = 1;
                }
        }