Add code for bounds check elimination
authorMiguel de Icaza <miguel@gnome.org>
Mon, 9 Dec 2002 18:02:02 +0000 (18:02 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 9 Dec 2002 18:02:02 +0000 (18:02 -0000)
svn path=/trunk/mono/; revision=9487

mono/jit/jit.c
mono/jit/jit.h
mono/jit/mono.c
mono/jit/x86.brg

index 464cc763f14e3906f2b5c4baaeed523b16201e8d..4e7a2fb057beeeb39d33192a0bea302379c0eb38 100644 (file)
@@ -212,6 +212,9 @@ gboolean mono_use_linear_scan = TRUE;
 /* inline code */
 gboolean mono_jit_inline_code = TRUE;
 
+/* generate bound checking */
+gboolean mono_jit_boundcheck = TRUE;
+
 /* inline memcpy */
 gboolean mono_inline_memcpy = TRUE;
 
index 397f3f705209a3ced5158db4066d2f47a8eb7e82..7c79dafc0273af37ecbe1a7959c2891a32ab1262 100644 (file)
@@ -236,6 +236,7 @@ extern gboolean mono_use_fast_iconv;
 extern gboolean mono_break_on_exc;
 extern gboolean mono_inline_memcpy;
 extern guint32  mono_jit_tls_id;
+extern gboolean mono_jit_boundcheck;
 
 extern CRITICAL_SECTION *metadata_section;
 
index 75d159cd5b8afb241c33fc27f9a0736271111439..5a77c7920c1828b4191b087583787984902e144c 100644 (file)
@@ -228,6 +228,8 @@ main (int argc, char *argv [])
                        mono_jit_inline_code = FALSE;
                else if (strcmp (argv [i], "--nointrinsic") == 0)
                        mono_inline_memcpy = FALSE;
+               else if (strcmp (argv [i], "--noboundcheck") == 0)
+                       mono_jit_boundcheck = FALSE;
                else if (strcmp (argv [i], "--nols") == 0)
                        mono_use_linear_scan = FALSE;
                else if (strcmp (argv [i], "--breakonex") == 0)
index 2eec6a53e38bd6e89b49d13844f66918fa51678a..c2b8d51de1f6c4b5180a60d4c00d1b3731e7429d 100644 (file)
@@ -1645,8 +1645,10 @@ reg: LDLEN (reg) {
 reg: LDELEMA (reg, CONST_I4) {
        int ind;
 
-       x86_alu_membase_imm (s->code, X86_CMP, tree->left->reg1, G_STRUCT_OFFSET (MonoArray, max_length), tree->right->data.i);
-       EMIT_COND_SYSTEM_EXCEPTION (X86_CC_GT, FALSE, "IndexOutOfRangeException");
+       if (mono_jit_boundcheck){
+               x86_alu_membase_imm (s->code, X86_CMP, tree->left->reg1, G_STRUCT_OFFSET (MonoArray, max_length), tree->right->data.i);
+               EMIT_COND_SYSTEM_EXCEPTION (X86_CC_GT, FALSE, "IndexOutOfRangeException");
+       }
        
        ind = tree->data.i * tree->right->data.i + G_STRUCT_OFFSET (MonoArray, vector);
        
@@ -1655,8 +1657,10 @@ reg: LDELEMA (reg, CONST_I4) {
 
 reg: LDELEMA (reg, reg) {
 
-       x86_alu_reg_membase (s->code, X86_CMP, tree->right->reg1, tree->left->reg1, G_STRUCT_OFFSET (MonoArray, max_length));
-       EMIT_COND_SYSTEM_EXCEPTION (X86_CC_LT, FALSE, "IndexOutOfRangeException");
+       if (mono_jit_boundcheck){
+               x86_alu_reg_membase (s->code, X86_CMP, tree->right->reg1, tree->left->reg1, G_STRUCT_OFFSET (MonoArray, max_length));
+               EMIT_COND_SYSTEM_EXCEPTION (X86_CC_LT, FALSE, "IndexOutOfRangeException");
+       }
 
        if (tree->data.i == 1 || tree->data.i == 2 || 
            tree->data.i == 4 || tree->data.i == 8) {