[llvm] Align aot variables to 8 bytes, parts of the aot code depend on it.
[mono.git] / mono / mini / mini-llvm.c
index 3fb5dfce0117b9e7df33932b2fa3a7de384465fd..f1bec8a2a156f545fceb3457821e42de8aab5310 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * mini-llvm.c: llvm "Backend" for the mono JIT
+/**
+ * \file
+ * llvm "Backend" for the mono JIT
  *
  * Copyright 2009-2011 Novell Inc (http://www.novell.com)
  * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
@@ -483,13 +484,9 @@ type_to_llvm_type (EmitContext *ctx, MonoType *t)
                return LLVMInt16Type ();
        case MONO_TYPE_U4:
                return LLVMInt32Type ();
-       case MONO_TYPE_BOOLEAN:
-               return LLVMInt8Type ();
        case MONO_TYPE_I8:
        case MONO_TYPE_U8:
                return LLVMInt64Type ();
-       case MONO_TYPE_CHAR:
-               return LLVMInt16Type ();
        case MONO_TYPE_R4:
                return LLVMFloatType ();
        case MONO_TYPE_R8:
@@ -498,10 +495,6 @@ type_to_llvm_type (EmitContext *ctx, MonoType *t)
        case MONO_TYPE_U:
                return IntPtrType ();
        case MONO_TYPE_OBJECT:
-       case MONO_TYPE_CLASS:
-       case MONO_TYPE_ARRAY:
-       case MONO_TYPE_SZARRAY:
-       case MONO_TYPE_STRING:
        case MONO_TYPE_PTR:
                return ObjRefType ();
        case MONO_TYPE_VAR:
@@ -4992,6 +4985,8 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
                case OP_X86_LEA: {
                        LLVMValueRef v1, v2;
 
+                       rhs = LLVMBuildSExt (builder, convert (ctx, rhs, LLVMInt32Type ()), LLVMInt64Type (), "");
+
                        v1 = LLVMBuildMul (builder, convert (ctx, rhs, IntPtrType ()), LLVMConstInt (IntPtrType (), (1 << ins->backend.shift_amount), FALSE), "");
                        v2 = LLVMBuildAdd (builder, convert (ctx, lhs, IntPtrType ()), v1, "");
                        values [ins->dreg] = LLVMBuildAdd (builder, v2, LLVMConstInt (IntPtrType (), ins->inst_imm, FALSE), dname);
@@ -6937,13 +6932,16 @@ emit_method_inner (EmitContext *ctx)
                static int count = 0;
                count ++;
 
-               if (g_getenv ("LLVM_COUNT")) {
-                       if (count == atoi (g_getenv ("LLVM_COUNT"))) {
+               char *llvm_count_str = g_getenv ("LLVM_COUNT");
+               if (llvm_count_str) {
+                       int lcount = atoi (llvm_count_str);
+                       g_free (llvm_count_str);
+                       if (count == lcount) {
                                printf ("LAST: %s\n", mono_method_full_name (cfg->method, TRUE));
                                fflush (stdout);
                                last = TRUE;
                        }
-                       if (count > atoi (g_getenv ("LLVM_COUNT"))) {
+                       if (count > lcount) {
                                set_failure (ctx, "count");
                                return;
                        }
@@ -7721,6 +7719,7 @@ decode_llvm_eh_info (EmitContext *ctx, gpointer eh_frame)
        guint32 ei_len, i, nested_len;
        gpointer *type_info;
        gint32 *table;
+       guint8 *unw_info;
 
        /*
         * Decode the one element EH table emitted by the MonoException class
@@ -7753,9 +7752,16 @@ decode_llvm_eh_info (EmitContext *ctx, gpointer eh_frame)
        fde = (guint8*)eh_frame + fde_offset;
        cie = (guint8*)table;
 
-       mono_unwind_decode_llvm_mono_fde (fde, fde_len, cie, cfg->native_code, &info);
+       /* Compute lengths */
+       mono_unwind_decode_llvm_mono_fde (fde, fde_len, cie, cfg->native_code, &info, NULL, NULL, NULL);
+
+       ei = (MonoJitExceptionInfo *)g_malloc0 (info.ex_info_len * sizeof (MonoJitExceptionInfo));
+       type_info = (gpointer *)g_malloc0 (info.ex_info_len * sizeof (gpointer));
+       unw_info = (guint8*)g_malloc0 (info.unw_info_len);
+
+       mono_unwind_decode_llvm_mono_fde (fde, fde_len, cie, cfg->native_code, &info, ei, type_info, unw_info);
 
-       cfg->encoded_unwind_ops = info.unw_info;
+       cfg->encoded_unwind_ops = unw_info;
        cfg->encoded_unwind_ops_len = info.unw_info_len;
        if (cfg->verbose_level > 1)
                mono_print_unwind_info (cfg->encoded_unwind_ops, cfg->encoded_unwind_ops_len);
@@ -7764,9 +7770,7 @@ decode_llvm_eh_info (EmitContext *ctx, gpointer eh_frame)
                cfg->llvm_this_offset = info.this_offset;
        }
 
-       ei = info.ex_info;
        ei_len = info.ex_info_len;
-       type_info = info.type_info;
 
        // Nested clauses are currently disabled
        nested_len = 0;
@@ -8583,6 +8587,7 @@ mono_llvm_emit_aot_data (const char *symbol, guint8 *data, int data_len)
        LLVMSetVisibility (d, LLVMHiddenVisibility);
        LLVMSetLinkage (d, LLVMInternalLinkage);
        LLVMSetInitializer (d, mono_llvm_create_constant_data_array (data, data_len));
+       LLVMSetAlignment (d, 8);
        mono_llvm_set_is_constant (d);
 }
 
@@ -9234,7 +9239,7 @@ default_mono_llvm_unhandled_exception (void)
     The mono JIT uses pointer sized iregs/double fregs, while LLVM uses precisely
     typed registers, so we have to keep track of the precise LLVM type of each vreg.
     This is made easier because the IR is already in SSA form.
-    An additional problem is that our IR is not consistent with types, i.e. i32/ia64 
+    An additional problem is that our IR is not consistent with types, i.e. i32/i64 
        types are frequently used incorrectly.
 */