[llvm] Fix the mixing of LLVM modules in the llvm JIT, use ctx->lmodule instead of...
authorZoltan Varga <vargaz@gmail.com>
Tue, 27 Aug 2019 20:31:18 +0000 (16:31 -0400)
committerZoltan Varga <vargaz@gmail.com>
Tue, 27 Aug 2019 20:31:18 +0000 (16:31 -0400)
Commit migrated from https://github.com/mono/mono/commit/ab1e9be35e78e6a99f5e97cc6e1df514ddbdb8ab

src/mono/mono/mini/mini-llvm.c

index b672119..f4fdc8c 100644 (file)
@@ -384,7 +384,7 @@ static void emit_dbg_info (MonoLLVMModule *module, const char *filename, const c
 static void emit_cond_system_exception (EmitContext *ctx, MonoBasicBlock *bb, const char *exc_type, LLVMValueRef cmp);
 static LLVMValueRef get_intrins_by_name (EmitContext *ctx, const char *name);
 static LLVMValueRef get_intrins (EmitContext *ctx, int id);
-static LLVMValueRef get_intrins_from_module (MonoLLVMModule *module, int id);
+static LLVMValueRef get_intrins_from_module (LLVMModuleRef lmodule, int id);
 static void llvm_jit_finalize_method (EmitContext *ctx);
 static void mono_llvm_nonnull_state_update (EmitContext *ctx, LLVMValueRef lcall, MonoMethod *call_method, LLVMValueRef *args, int num_params);
 static void mono_llvm_propagate_nonnull_final (GHashTable *all_specializable, MonoLLVMModule *module);
@@ -3165,7 +3165,7 @@ emit_gc_safepoint_poll (MonoLLVMModule *module)
        cmp = LLVMBuildICmp (builder, LLVMIntEQ, val, LLVMConstNull (LLVMTypeOf (val)), "");
        args [0] = cmp;
        args [1] = LLVMConstInt (LLVMInt1Type (), 1, FALSE);
-       cmp = LLVMBuildCall (builder, get_intrins_from_module (module, INTRINS_EXPECT_I1), args, 2, "");
+       cmp = LLVMBuildCall (builder, get_intrins_from_module (module->lmodule, INTRINS_EXPECT_I1), args, 2, "");
        LLVMBuildCondBr (builder, cmp, exit_bb, poll_bb);
 
        /* poll: */
@@ -7638,7 +7638,8 @@ mono_llvm_emit_method (MonoCompile *cfg)
                ctx->lmodule = ctx->module->lmodule;
        } else {
                ctx->lmodule = LLVMModuleCreateWithName (g_strdup_printf ("jit-module-%s", cfg->method->name));
-               ctx->module->lmodule = ctx->lmodule;
+               /* Reset this as it contains values from lmodule */
+               memset (ctx->module->intrins_by_id, 0, sizeof (LLVMValueRef) * INTRINS_NUM);
        }
        ctx->llvm_only = ctx->module->llvm_only;
 #ifdef TARGET_WASM
@@ -8839,11 +8840,26 @@ add_intrinsic (LLVMModuleRef module, int id)
 }
 
 static LLVMValueRef
-get_intrins_from_module (MonoLLVMModule *module, int id)
+get_intrins_from_module (LLVMModuleRef lmodule, int id)
 {
+       LLVMValueRef res;
+
        const char *name = (const char*)g_hash_table_lookup (intrins_id_to_name, GINT_TO_POINTER (id));
        g_assert (name);
 
+       res = LLVMGetNamedFunction (lmodule, name);
+       if (!res) {
+               add_intrinsic (lmodule, id);
+               res = LLVMGetNamedFunction (lmodule, name);
+               g_assert (res);
+       }
+       return res;
+}
+
+static LLVMValueRef
+get_intrins (EmitContext *ctx, int id)
+{
+       MonoLLVMModule *module = ctx->module;
        LLVMValueRef res;
 
        /*
@@ -8852,24 +8868,13 @@ get_intrins_from_module (MonoLLVMModule *module, int id)
         */
        res = module->intrins_by_id [id];
        if (!res) {
-               res = LLVMGetNamedFunction (module->lmodule, name);
-               if (!res) {
-                       add_intrinsic (module->lmodule, id);
-                       res = LLVMGetNamedFunction (module->lmodule, name);
-                       g_assert (res);
-               }
+               res = get_intrins_from_module (ctx->lmodule, id);
                module->intrins_by_id [id] = res;
        }
        return res;
 }
 
 static LLVMValueRef
-get_intrins (EmitContext *ctx, int id)
-{
-       return get_intrins_from_module (ctx->module, id);
-}
-
-static LLVMValueRef
 get_intrins_by_name (EmitContext *ctx, const char *name)
 {
        LLVMValueRef res;