X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fmini-llvm.c;h=ea5072c296548a8b75945c3bbb7408079be73e8d;hb=fd769946c5926f60838f8e78183c8e59275002a4;hp=3398b96d612391fa700679649ee8241f2e67b738;hpb=e03d204d7bfe26bb622039cc2fee3587f26c1d8f;p=mono.git diff --git a/mono/mini/mini-llvm.c b/mono/mini/mini-llvm.c index 3398b96d612..ea5072c2965 100644 --- a/mono/mini/mini-llvm.c +++ b/mono/mini/mini-llvm.c @@ -1,12 +1,14 @@ /* * mini-llvm.c: llvm "Backend" for the mono JIT * - * (C) 2009 Novell, Inc. + * Copyright 2009-2011 Novell Inc (http://www.novell.com) + * Copyright 2011 Xamarin Inc (http://www.xamarin.com) */ #include "mini.h" #include #include +#include #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS @@ -181,7 +183,7 @@ static LLVMRealPredicate fpcond_to_llvm_cond [] = { }; static LLVMExecutionEngineRef ee; -static guint32 current_cfg_tls_id; +static MonoNativeTlsKey current_cfg_tls_id; static MonoLLVMModule jit_module, aot_module; static gboolean jit_module_inited; @@ -349,6 +351,7 @@ type_to_llvm_type (EmitContext *ctx, MonoType *t) if (!ltype) { int i, size; LLVMTypeRef *eltypes; + char *name; size = get_vtype_size (t); @@ -356,8 +359,9 @@ type_to_llvm_type (EmitContext *ctx, MonoType *t) for (i = 0; i < size; ++i) eltypes [i] = LLVMInt8Type (); - /* We couldn't name these types since LLVM uses structural type equality */ - ltype = LLVMStructType (eltypes, size, FALSE); + name = mono_type_full_name (&klass->byval_arg); + ltype = LLVMStructCreateNamed (LLVMGetGlobalContext (), name); + LLVMStructSetBody (ltype, eltypes, size, FALSE); g_hash_table_insert (ctx->lmodule->llvm_types, klass, ltype); g_free (eltypes); } @@ -2467,7 +2471,16 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb) cmp = LLVMBuildICmp (builder, cond_to_llvm_cond [rel], lhs, rhs, ""); if (MONO_IS_COND_BRANCH_OP (ins->next)) { - LLVMBuildCondBr (builder, cmp, get_bb (ctx, ins->next->inst_true_bb), get_bb (ctx, ins->next->inst_false_bb)); + if (ins->next->inst_true_bb == ins->next->inst_false_bb) { + /* + * If the target bb contains PHI instructions, LLVM requires + * two PHI entries for this bblock, while we only generate one. + * So convert this to an unconditional bblock. (bxc #171). + */ + LLVMBuildBr (builder, get_bb (ctx, ins->next->inst_true_bb)); + } else { + LLVMBuildCondBr (builder, cmp, get_bb (ctx, ins->next->inst_true_bb), get_bb (ctx, ins->next->inst_false_bb)); + } has_terminator = TRUE; } else if (MONO_IS_SETCC (ins->next)) { sprintf (dname_buf, "t%d", ins->next->dreg); @@ -4226,7 +4239,7 @@ mono_llvm_emit_method (MonoCompile *cfg) mono_loader_lock (); /* Used to communicate with the callbacks */ - TlsSetValue (current_cfg_tls_id, cfg); + mono_native_tls_set_value (current_cfg_tls_id, cfg); ctx = g_new0 (EmitContext, 1); ctx->cfg = cfg; @@ -4608,7 +4621,7 @@ mono_llvm_emit_method (MonoCompile *cfg) g_free (ctx); - TlsSetValue (current_cfg_tls_id, NULL); + mono_native_tls_set_value (current_cfg_tls_id, NULL); mono_loader_unlock (); } @@ -4686,7 +4699,7 @@ alloc_cb (LLVMValueRef function, int size) { MonoCompile *cfg; - cfg = TlsGetValue (current_cfg_tls_id); + cfg = mono_native_tls_get_value (current_cfg_tls_id); if (cfg) { // FIXME: dynamic @@ -4701,7 +4714,7 @@ emitted_cb (LLVMValueRef function, void *start, void *end) { MonoCompile *cfg; - cfg = TlsGetValue (current_cfg_tls_id); + cfg = mono_native_tls_get_value (current_cfg_tls_id); g_assert (cfg); cfg->code_len = (guint8*)end - (guint8*)start; } @@ -4715,7 +4728,7 @@ exception_cb (void *data) gpointer *type_info; int this_reg, this_offset; - cfg = TlsGetValue (current_cfg_tls_id); + cfg = mono_native_tls_get_value (current_cfg_tls_id); g_assert (cfg); /* @@ -5090,7 +5103,7 @@ add_intrinsics (LLVMModuleRef module) void mono_llvm_init (void) { - current_cfg_tls_id = TlsAlloc (); + mono_native_tls_alloc (¤t_cfg_tls_id, NULL); } static void